Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Add New Module through Admin back-end

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 08-04-2004, 11:14 PM
 
pmstudios pmstudios is offline
 

Senior Member
  
Join Date: May 2004
Posts: 133
 

Default Add New Module through Admin back-end

I've been creating a few custom features as modules and have quite a few more on my ToDo list, so I wrote this to make adding modules to the database a bit easier. This will add an "Add Module" dialog below the modules list in the admin back-end.

In admin/modules.php, find:
Code:
if ($REQUEST_METHOD=="POST") { require $xcart_dir."/include/safe_mode.php"; # # Disable all module files, then enable certain # db_query("update $sql_tbl[modules] set active='N'"); foreach ($HTTP_POST_VARS as $module_name => $val) { if ($val=="on") db_query("update $sql_tbl[modules] set active='Y' where module_name='$module_name'"); } func_header_location("modules.php"); }

And replace it with the following:
Code:
if ($REQUEST_METHOD=="POST") { require $xcart_dir."/include/safe_mode.php"; # # Disable all module files, then enable certain # if ($mode == "update") { db_query("update $sql_tbl[modules] set active='N'"); foreach ($HTTP_POST_VARS as $module_name => $val) { if ($val=="on") db_query("update $sql_tbl[modules] set active='Y' where module_name='$module_name'"); } } # # Add new module # if ($mode == "add") { $module_name = str_replace(" ", "_", $HTTP_POST_VARS['module_name']); $existing_mod = func_query("SELECT $sql_tbl[modules].moduleid FROM $sql_tbl[modules] WHERE $sql_tbl[modules].module_name='$module_name'"); if (empty($existing_mod)) { if ($active=="on") $active = "Y"; db_query("INSERT INTO $sql_tbl[modules] (module_name,module_descr,active) VALUES ('$module_name','$module_descr','$active')"); } } func_header_location("modules.php"); }


Then add the following at the bottom of skin1/admin/modules.tpl:
Code:
{capture name=dialog} <FORM action="modules.php?mode=add" method="post" name="myform2"> <TABLE cellpadding="5"> <TR> <TD>{$lng.lbl_module_name}</TD> <TD>{$lng.lbl_module_active}</TD> <TD>{$lng.lbl_module_descr}</TD> </TR> <TD><INPUT type="text" name="module_name" size="26"></TD> <TD><INPUT type="checkbox" name="active"></TD> <TD><INPUT type="text" name="module_descr" size="35"> <INPUT type="submit" value="{$lng.lbl_add_module}"></TD> </TR> </TABLE> </FORM> {/capture} {include file="dialog.tpl" title=$lng.lbl_add_module content=$smarty.capture.dialog extra="width=100%"}

Then add the following labels:
lbl_add_module
lbl_module_name
lbl_module_descr
lbl_module_active

I have this implemented in 4.0.1, but it should work with earlier versions. Just don't forget to backup your files first

Hope someone finds this useful...
__________________
X-Cart 4.0.5
MySQL: 3.23.58
PHP 4.3.2
Reply With Quote
  #2  
Old 08-06-2004, 07:30 AM
 
sstillwell@aerostich.com sstillwell@aerostich.com is offline
 

eXpert
  
Join Date: Jun 2004
Location: Duluth, MN
Posts: 242
 

Default

Cool post but just two typos.

1)
lbl_modue_descr

should be

lbl_module_descr

2)
if (empy($existing_mod)) {

should be

if (empty($existing_mod)) {
__________________
No longer using Xcart, was good while it lasted.
Reply With Quote
  #3  
Old 08-06-2004, 01:19 PM
 
pmstudios pmstudios is offline
 

Senior Member
  
Join Date: May 2004
Posts: 133
 

Default

Oops, thanks for the corrections. Fixed the original post :>
__________________
X-Cart 4.0.5
MySQL: 3.23.58
PHP 4.3.2
Reply With Quote
  #4  
Old 08-06-2004, 01:48 PM
  Jon's Avatar 
Jon Jon is offline
 

X-Guru
  
Join Date: Oct 2002
Location: Vancouver, Canada
Posts: 4,200
 

Default

Nice mod. I'm sure it will now appear in x-cart 4.1
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 03:18 PM.

   

 
X-Cart forums © 2001-2020