<?php
################################################################################
## -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =- #
## --------------------------------------------------------------------------- #
## ApPHP AdminPanel Pro #
## Developed by: ApPHP <hide@address.com> #
## License: GNU LGPL v.3 #
## Site: http://www.apphp.com/php-adminpanel/ #
## Copyright: ApPHP AdminPanel (c) 2006-2011. All rights reserved. #
## #
################################################################################
// Initialize the session.
session_start();
require_once("../inc/classes/session.class.php");
require_once("../inc/checkAdminPagePermissions.php");
require_once("../inc/config.inc.php");
require_once("../inc/settings.inc.php");
require_once("../inc/functions.inc.php");
require_once("../inc/languages/".$SETTINGS['site_language'].".php");
if(!page_access_allowed($_SERVER['SCRIPT_NAME'])) redirect_to("access_denied.php");
$unique_prefix = "mod_"; /* prevent overlays - must be started with a letter */
$mode = isset($_REQUEST[$unique_prefix.'mode']) ? $_REQUEST[$unique_prefix.'mode'] : "";
$rid = isset($_REQUEST[$unique_prefix.'rid']) ? $_REQUEST[$unique_prefix.'rid'] : "";
$module_installed = isset($_POST['styis_installed']) ? $_POST['styis_installed'] : "";
$module_name = isset($_POST['rtyname']) ? $_POST['rtyname'] : "";
$parent_menu_id = isset($_POST['riyparent_menu_id']) ? $_POST['riyparent_menu_id'] : "0";
$module_menu_id = isset($_POST['stymenu_id']) ? $_POST['stymenu_id'] : "0";
$module_icon_file = isset($_POST['styicon_file']) ? $_POST['styicon_file'] : "";
$module_file = isset($_POST['rtymodule_file']) ? $_POST['rtymodule_file'] : "";
$truncate_tables = isset($_POST['_truncate_tables']) ? $_POST['_truncate_tables'] : "";
unset($_POST['_truncate_tables']);
$is_module_installed = "";
$related_tables = "";
if($mode == "add") $readonly_module_file = false;
else $readonly_module_file = true;
// collect info about module
$sql = "SELECT is_installed, related_tables FROM ".TABLE_MODULES." WHERE id = ".(int)$rid;
$db->Query($sql);
if($row = $db->FetchArray()){
$is_module_installed = $row['is_installed'];
$related_tables = $row['related_tables'];
}
## +---------------------------------------------------------------------------+
## | 1. Creating & Calling: |
## +---------------------------------------------------------------------------+
## *** define a relative (virtual) path to datagrid.class.php file (relatively to the current file)
## *** RELATIVE PATH ONLY ***
## Ex.: "datagrid/datagrid.class.php" or "datagrid.class.php" etc.
define ("DATAGRID_DIR", "../modules/datagrid/"); /* Ex.: "datagrid/" */
define ("PEAR_DIR", "../modules/datagrid/pear/"); /* Ex.: "datagrid/pear/" */
require_once(DATAGRID_DIR.'datagrid.class.php');
require_once(PEAR_DIR.'PEAR.php');
require_once(PEAR_DIR.'DB.php');
## *** creating variables that we need for database connection
$config = new Config();
$DB_USER = $config->getUser();
$DB_PASS = $config->getPassword();
$DB_HOST = $config->getHost();
$DB_NAME = $config->getDatabase();
$DB_TYPE = $config->getDatabaseType();
ob_start();
$db_conn = DB::factory($DB_TYPE); /* don't forget to change on appropriate db type */
$result_conn = $db_conn->connect(DB::parseDSN($DB_TYPE.'://'.$DB_USER.':'.$DB_PASS.'@'.$DB_HOST.'/'.$DB_NAME));
if(DB::isError($result_conn)){ die($result_conn->getDebugInfo()); }
## *** write down the primary key in the first place (MUST BE AUTO-INCREMENT NUMERIC!)
$sql = "SELECT
".TABLE_MODULES.".id,
".TABLE_MODULES.".name,
".TABLE_MODULES.".icon_file,
".TABLE_MODULES.".module_file,
".TABLE_MENU.".name as menu_name,
IF(".TABLE_MODULES.".is_installed = 1, '<span class=yes>".lang("installed")."</span>', '<span class=no>".lang("not_installed")."</span>') as is_installed
FROM ".TABLE_MODULES."
LEFT OUTER JOIN ".TABLE_MENU." ON ".TABLE_MODULES.".parent_menu_id = ".TABLE_MENU.".id ";
## *** set needed options and create a new class instance
$debug_mode = false; /* display SQL statements while processing */
$messaging = true; /* display system messages on a screen */
$dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix, DATAGRID_DIR);
if(strtolower(_SITE_MODE) == "demo") $dgrid->isDemo = true;
## *** set encoding and collation (default: utf8/utf8_unicode_ci)
/// $dg_encoding = "utf8";
/// $dg_collation = "utf8_unicode_ci";
/// $dgrid->SetEncoding($dg_encoding, $dg_collation);
## *** set data source with needed options
$default_order_field = TABLE_MODULES.".priority_order";
$default_order_type = "ASC";
$dgrid->DataSource($db_conn, $sql, $default_order_field, $default_order_type);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title><?php echo $SETTINGS['site_name']; ?> :: <?php echo lang('admin_panel'); ?> :: <?php echo lang('modules_manager'); ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="../styles/<?php echo $SETTINGS['css_style'];?>/style.css" type="text/css" rel="stylesheet">
<?php
## call of this method between HTML <HEAD> tags
//$dgrid->WriteCssClass();
?>
</head>
<body dir="<?php echo $SETTINGS['language_dir'];?>">
<?php echo page_breadcrumbs(); ?>
<br />
<?php
## +---------------------------------------------------------------------------+
## | 2. General Settings: |
## +---------------------------------------------------------------------------+
## *** set interface language (default - English)
$dg_language = $SETTINGS['site_language'];
$dgrid->setInterfaceLang($dg_language);
## *** set direction: "ltr" or "rtr" (default - "ltr")
$direction = $SETTINGS['language_dir'];
$dgrid->SetDirection($direction);
## *** set layouts: "0" - tabular(horizontal) - default, "1" - columnar(vertical), "2" - customized
## *** use "view"=>"0" and "edit"=>"0" only if you work on the same tables
$layouts = array("view"=>"2", "edit"=>"1", "details"=>"1", "filter"=>"1");
$dgrid->SetLayouts($layouts);
$view_mode_template = array("header"=>"", "body"=>"", "footer"=>"");
$view_mode_template['body'] = "<table align='left' cellpadding='3' onmouseover='this.style.borderColor=\"#ababab\"' onmouseout='this.style.borderColor=\"#dedede\"' style='border:1px solid #dedede;margin:3px;' width='130px'><tr><td align='center'><b>{name}</b> <br>{icon_file}<br>{is_installed}</td></tr><tr><td align='center'>[[EDIT]]</td></tr></table>";
$dgrid->SetTemplates($view_mode_template,"","");
## *** set modes for operations ("type" => "link|button|image")
## *** "view" - view mode | "edit" - add/edit/details modes
## *** "byFieldValue"=>"fieldName" - make the field to be a link to edit mode page
$modes = array(
"add" =>array("view"=>false, "edit"=>false, "type"=>"link", "show_add_button"=>"inside|outside"),
"edit" =>array("view"=>true, "edit"=>true, "type"=>"link", "byFieldValue"=>""),
"cancel" =>array("view"=>true, "edit"=>true, "type"=>"link"),
"details" =>array("view"=>false, "edit"=>false, "type"=>"link"),
"delete" =>array("view"=>false, "edit"=>false, "type"=>"image")
);
$dgrid->SetModes($modes);
## *** allow scrolling on datagrid
/// $scrolling_option = false;
/// $dgrid->AllowScrollingSettings($scrolling_option);
## *** set scrolling settings (optional)
/// $scrolling_width = "90%";
/// $scrolling_height = "100%";
/// $dgrid->setScrollingSettings($scrolling_width, $scrolling_height);
## *** allow multirow operations
/// $multirow_option = true;
/// $dgrid->AllowMultirowOperations($multirow_option);
/// $multirow_operations = array(
/// "delete" => array("view"=>true),
/// "details" => array("view"=>true),
/// "my_operation_name" => array("view"=>true, "flag_name"=>"my_flag_name", "flag_value"=>"my_flag_value", "tooltip"=>"Do something with selected", "image"=>"image.gif")
/// );
/// $dgrid->SetMultirowOperations($multirow_operations);
## *** set CSS class for datagrid
## *** "default", "blue", "x-blue", "gray", "green" or "pink" or your own css file
$css_class = $SETTINGS['datagrid_css_style'];
$dgrid->SetCssClass($css_class);
## *** set variables that used to get access to the page (like: my_page.php?act=34&id=56 etc.)
/// $http_get_vars = array("act", "id");
/// $dgrid->SetHttpGetVars($http_get_vars);
## *** set other datagrid/s unique prefixes (if you use few datagrids on one page)
## *** format (in which mode to allow processing of another datagrids)
## *** array("unique_prefix"=>array("view"=>true|false, "edit"=>true|false, "details"=>true|false));
/// $anotherDatagrids = array("abcd_"=>array("view"=>true, "edit"=>true, "details"=>true));
/// $dgrid->SetAnotherDatagrids($anotherDatagrids);
## *** set DataGrid caption
$dg_caption = lang('modules_manager');
$dgrid->SetCaption($dg_caption);
## +---------------------------------------------------------------------------+
## | 3. Printing & Exporting Settings: |
## +---------------------------------------------------------------------------+
## *** set printing option: true(default) or false
$printing_option = false;
$dgrid->AllowPrinting($printing_option);
## *** set exporting option: true(default) or false and relative (virtual) path
## *** to export directory (relatively to datagrid.class.php file).
## *** Add 744 access permissions for this folder. Ex.: "" - if we use current datagrid folder
## *** Change $file_path = "../../".$dir.$file; in scripts/download.php on appropriate path relatively to download.php
/// $exporting_option = true;
/// $exporting_directory = "";
/// $export_all = false;
/// $dgrid->AllowExporting($exporting_option, $exporting_directory, $export_all);
/// $exporting_types = array("excel"=>"true", "pdf"=>"true", "xml"=>"true");
/// $dgrid->AllowExportingTypes($exporting_types);
## +---------------------------------------------------------------------------+
## | 4. Sorting & Paging Settings: |
## +---------------------------------------------------------------------------+
## *** set sorting option: true(default) or false
/// $sorting_option = true;
/// $dgrid->AllowSorting($sorting_option);
## *** set paging option: true(default) or false
$paging_option = false;
$rows_numeration = false;
$numeration_sign = "N #";
$dgrid->AllowPaging($paging_option, $rows_numeration, $numeration_sign);
## *** set paging settings
$bottom_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
$top_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
$pages_array = array("10"=>"10", "25"=>"25", "50"=>"50", "100"=>"100", "250"=>"250", "500"=>"500", "1000"=>"1000");
$default_page_size = 25;
$paging_arrows = array("first"=>"|<<", "previous"=>"<<", "next"=>">>", "last"=>">>|");
$dgrid->SetPagingSettings($bottom_paging, $top_paging, $pages_array, $default_page_size, $paging_arrows);
## +---------------------------------------------------------------------------+
## | 5. Filter Settings: |
## +---------------------------------------------------------------------------+
## *** set filtering option: true or false(default)
/// $filtering_option = true;
/// $show_search_type = true;
/// $dgrid->AllowFiltering($filtering_option, $show_search_type);
## *** set additional filtering settings
## *** tips: use "," (comma) if you want to make search by some words, for ex.: hello, bye, hi
## *** "field_type" may be "from" or "to"
## *** "date_format" may be "date", "datedmy" or "datetime"
## *** "default_operator" may be =|<|>|like|%like|like%|%like%|not like
/// $fill_from_array = array("0"=>"No", "1"=>"Yes"); /* as "value"=>"option" */
/// $filtering_fields = array(
/// "Caption_1"=>array("type"=>"textbox", "table"=>"tableName_1", "field"=>"fieldName_1|,fieldName_2", "filter_condition"=>"", "show_operator"=>"false", "default_operator"=>"=", "case_sensitive"=>"false", "comparison_type"=>"string|numeric|binary", "width"=>"", "on_js_event"=>""),
/// "Caption_2"=>array("type"=>"textbox", "autocomplete"=>"false", "handler"=>"modules/autosuggest/test.php", "maxresults"=>"12", "shownoresults"=>"false", "table"=>"tableName_1", "field"=>"fieldName_1|,fieldName_2", "filter_condition"=>"", "show_operator"=>"false", "default_operator"=>"=", "case_sensitive"=>"false", "comparison_type"=>"string|numeric|binary", "width"=>"", "on_js_event"=>""),
/// "Caption_3"=>array("type"=>"dropdownlist", "table"=>"tableName_2", "field"=>"fieldName_2", "filter_condition"=>"", "order"=>"ASC|DESC", "source"=>"self"|$fill_from_array, "show"=>"", "condition"=>"", "show_operator"=>"false", "default_operator"=>"=", "case_sensitive"=>"false", "comparison_type"=>"string|numeric|binary", "width"=>"", "multiple"=>"false", "multiple_size"=>"4", "on_js_event"=>""),
/// "Caption_4"=>array("type"=>"calendar", "calendar_type"=>"popup|floating", "date_format"=>"date", "table"=>"tableName_3", "field"=>"fieldName_3", "filter_condition"=>"", "field_type"=>"", "show_operator"=>"false", "default_operator"=>"=", "case_sensitive"=>"false", "comparison_type"=>"string|numeric|binary", "width"=>"", "on_js_event"=>""),
/// );
/// $dgrid->SetFieldsFiltering($filtering_fields);
## +---------------------------------------------------------------------------+
## | 6. View Mode Settings: |
## +---------------------------------------------------------------------------+
## *** set view mode table properties
/// $vm_table_properties = array("width"=>"60%");
/// $dgrid->SetViewModeTableProperties($vm_table_properties);
## *** set columns in view mode
/// $fill_from_array = array("0"=>"Banned", "1"=>"Active", "2"=>"Closed", "3"=>"Removed"); /* as "value"=>"option" */
$vm_colimns = array(
"icon_file" =>array("header"=>lang("icon"), "type"=>"image", "align"=>"center", "width"=>"100px", "wrap"=>"wrap|nowrap", "text_length"=>"-1", "case"=>"normal|upper|lower|camel", "summarize"=>"false", "sort_type"=>"string|numeric", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "target_path"=>"../images/module_icons/", "default"=>"default_image.ext", "image_width"=>"50px", "image_height"=>"50px", "linkto"=>"", "magnify"=>"false", "magnify_type"=>"popup|lightbox", "magnify_power"=>"2"),
"name" =>array("header"=>lang("module_name"), "type"=>"label", "align"=>"left", "width"=>"", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>true|false, "tooltip_type"=>"floating|simple", "case"=>"normal", "summarize"=>"false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "pre_addition"=>" "),
"menu_name" =>array("header"=>lang("show_in"), "type"=>"label", "align"=>"center", "width"=>"", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>true|false, "tooltip_type"=>"floating|simple", "case"=>"normal", "summarize"=>"false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
"is_installed" =>array("header"=>lang("installed"), "type"=>"label", "align"=>"center", "width"=>"", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>true|false, "tooltip_type"=>"floating|simple", "case"=>"normal", "summarize"=>"false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
);
$dgrid->SetColumnsInViewMode($vm_colimns);
## *** set auto-generated columns in view mode
// $auto_column_in_view_mode = false;
// $dgrid->SetAutoColumnsInViewMode($auto_column_in_view_mode);
## +---------------------------------------------------------------------------+
## | 7. Add/Edit/Details Mode Settings: |
## +---------------------------------------------------------------------------+
## *** set add/edit mode table properties
$em_table_properties = array("width"=>"600px");
$dgrid->SetEditModeTableProperties($em_table_properties);
## *** set details mode table properties
/// $dm_table_properties = array("width"=>"70%");
/// $dgrid->SetDetailsModeTableProperties($dm_table_properties);
## *** set settings for add/edit/details modes
$table_name = TABLE_MODULES;
$primary_key = "id";
// for ex.: "table_name.field = ".$_REQUEST['abc_rid'];
$condition = "";
$dgrid->SetTableEdit($table_name, $primary_key, $condition);
## *** set columns in edit mode
$fill_from_array_insstalled = array("0"=>"No", "1"=>"Yes");
$em_columns = array(
"name" =>array("header"=>lang("module_name"), "type"=>"textbox", "req_type"=>"rt", "width"=>"210px", "title"=>"", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "unique"=>true, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
"icon_file" =>array("header"=>lang("icon"), "type"=>"image", "req_type"=>"st", "width"=>"220px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "target_path"=>"../images/module_icons/", "max_file_size"=>"100K", "image_width"=>"96px", "image_height"=>"96px", "magnify"=>"false", "file_name"=>"module_thumb_".((isset($_REQUEST['meno_mode']) && ($_REQUEST['meno_mode'] == "add")) ? $dgrid->GetRandomString("10") : $dgrid->GetCurrentId()), "host"=>"local", "magnify_type"=>"lightbox"),
"module_file" =>array("header"=>lang("module_file"), "type"=>"textbox", "req_type"=>"rt", "width"=>"210px", "title"=>"", "readonly"=>$readonly_module_file, "maxlength"=>"-1", "default"=>"", "unique"=>true, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
"menu_id" =>array("header"=>"", "type"=>"hidden", "req_type"=>"st", "default"=>"", "value"=>"", "unique"=>"false", "visible"=>"true"),
"parent_menu_id" =>array("header"=>lang("menu_category"), "type"=>"foreign_key","req_type"=>"ri", "width"=>"210px", "title"=>"", "readonly"=>"false", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true"),
"priority_order" =>array("header"=>lang("priority_order"),"type"=>"textbox", "req_type"=>"ri", "width"=>"40px", "title"=>"", "readonly"=>false, "maxlength"=>"2", "default"=>"", "unique"=>true, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
"is_installed" =>array("header"=>lang("installed"), "type"=>"enum", "req_type"=>"st", "width"=>"210px", "title"=>"", "readonly"=>false, "maxlength"=>"-1", "default"=>"admin", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "source"=>$fill_from_array_insstalled, "view_type"=>"dropdownlist", "radiobuttons_alignment"=>"horizontal|vertical", "multiple"=>false, "multiple_size"=>"4"),
);
if($is_module_installed == "1") $em_columns["delimiter_1"] = array("inner_html"=>"<div style='float:left'><input type='checkbox' name='_truncate_tables' value='1' /> ".lang("msg_m_truncate_all_tables")."</div>");
$dgrid->SetColumnsInEditMode($em_columns);
## *** set auto-generated columns in edit mode
// $auto_column_in_edit_mode = false;
// $dgrid->SetAutoColumnsInEditMode($auto_column_in_edit_mode);
## *** set foreign keys for add/edit/details modes (if there are linked tables)
$foreign_keys = array(
"parent_menu_id"=>array("table"=>TABLE_MENU, "field_key"=>"id", "field_name"=>"name", "view_type"=>"dropdownlist", "radiobuttons_alignment"=>"horizontal|vertical", "condition"=>"is_menu_group = 1", "order_by_field"=>"order_index", "order_type"=>"ASC", "on_js_event"=>""),
);
$dgrid->SetForeignKeysEdit($foreign_keys);
################################################################################
## +---------------------------------------------------------------------------+
## | 8. Bind the DataGrid: |
## +---------------------------------------------------------------------------+
## *** bind the DataGrid and draw it on the screen
echo "<table align='center'><tr><td align='center'>";
$dgrid->Bind();
echo "</td></tr></table>";
ob_end_flush();
################################################################################
//--------------------------------------------------------------------------
// module was updated - update menu
//--------------------------------------------------------------------------
if($mode == "update" && $dgrid->IsOperationCompleted())
{
if($module_installed == "1"){
$sql = "SELECT COUNT(*) as cnt FROM ".TABLE_MENU." WHERE LCASE(name = '".strtolower($module_name)."') AND file_type_id = 0";
$db->Query($sql);
if($row = $db->FetchArray()){
if($row['cnt'] > 0){
// module installed
$sql = "UPDATE ".TABLE_MENU."
SET name = '".$module_name."', parent_id = ".(int)$parent_menu_id.", icon = '".$module_icon_file."'
WHERE id = ".(int)$module_menu_id."";
$db->Exec($sql);
}else{
// module not installed
$sql = "INSERT INTO ".TABLE_MENU." (id, name, page_name, is_menu_group, is_removable, is_hidden, parent_id, order_index, icon, is_dashboard_icon, is_menu_item, is_create_file, file_type_id)
VALUES (NULL, '".$module_name."', '".$module_file."', 0, 0, 0, ".(int)$parent_menu_id.", 0, '".$module_icon_file."', 1, 1, 1, 0)";
$db->Exec($sql);
$insert_id = $db->InsertID();
$sql = "UPDATE ".TABLE_MODULES." SET parent_menu_id = '".(int)$parent_menu_id."', menu_id = ".(int)$insert_id." WHERE id = ".(int)$rid;
$db->Exec($sql);
}
// delete icon from menu icons directory (if exists)
$sql = "SELECT icon FROM ".TABLE_MENU." WHERE id = ".(int)$module_menu_id." AND file_type_id = 0";
$db->Query($sql);
if($row = $db->FetchArray()){
@unlink("../images/icons/".$row['icon']);
}
// copy icon to menu icons directory
@copy("../images/module_icons/".$module_icon_file, "../images/icons/".$module_icon_file);
}
}else{
// un-install module
$sql = "UPDATE ".TABLE_MODULES." SET menu_id = 0, parent_menu_id = 0 WHERE id = ".(int)$rid;
$db->Exec($sql);
$sql = "DELETE FROM ".TABLE_MENU." WHERE id = ".(int)$module_menu_id." AND file_type_id = 0";
$db->Exec($sql);
if($truncate_tables == "1"){
$related_tables_parts = explode(",", $related_tables);
foreach($related_tables_parts as $table){
$db->Query("TRUNCATE TABLE "._DB_PREFIX.$table);
}
}
}
// refresh menu
if(strtolower(_SITE_MODE) != "demo"){
echo "<script type='text/javascript'>setTimeout('parent.location.reload()', 500);</script>";
}
}
?>
<br />
</body>
</html>