X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Add New Module through Admin back-end (https://forum.x-cart.com/showthread.php?t=8787)

pmstudios 08-04-2004 11:14 PM

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...

sstillwell@aerostich.com 08-06-2004 07:30 AM

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)) {

pmstudios 08-06-2004 01:19 PM

Oops, thanks for the corrections. Fixed the original post :>

Jon 08-06-2004 01:48 PM

Nice mod. I'm sure it will now appear in x-cart 4.1 :D


All times are GMT -8. The time now is 02:43 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.