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