/web/1/000/076/129/313906/htdocs/styroporzuschnitte24_shop/admin/gm/classes/GMModulesManager.php (13.34 KB)
<?php
/* --------------------------------------------------------------
GMModuleManager.php 2010-10-04 mb
Gambio GmbH
http://www.gambio.de
Copyright (c) 2010 Gambio GmbH
Released under the GNU General Public License (Version 2)
[http://www.gnu.org/licenses/gpl-2.0.html]
--------------------------------------------------------------
*/
?><?php
class GMModuleManager
{
var $v_module_type = '';
var $v_modules_directory = '';
var $v_modules_lang_directory = '';
var $v_module_link = '';
var $v_show_installed_modules_menu = false;
var $v_display_installed_modules = false;
var $v_show_missing_modules_menu = true;
var $v_display_missing_modules = true;
function GMModuleManager($p_module_type, $p_show_installed_modules_menu = false, $p_display_installed_modules = false, $p_show_missing_modules_menu = true, $p_display_missing_modules = true, $p_ignore_files_array = array())
{
$this->v_module_type = basename($p_module_type);
if($p_module_type == 'ordertotal')
{
$this->v_module_type = 'order_total';
}
$this->v_modules_directory = DIR_FS_CATALOG_MODULES . $this->v_module_type . '/';
$this->v_modules_lang_directory = DIR_FS_LANGUAGES . $_SESSION['language'] . '/modules/' . $this->v_module_type . '/';
$this->v_module_link = FILENAME_MODULES . '?set=' . $this->v_module_type . '&module=';
$this->v_show_installed_modules_menu = $p_show_installed_modules_menu;
$this->v_display_installed_modules = $p_display_installed_modules;
$this->v_show_missing_modules_menu = $p_show_missing_modules_menu;
$this->v_display_missing_modules = $p_display_missing_modules;
$this->v_ignore_files_array = $p_ignore_files_array;
}
function get_modules_installed()
{
$t_modules_installed = array();
$t_get_modules_installed = xtc_db_query("SELECT configuration_value
FROM " . TABLE_CONFIGURATION . "
WHERE configuration_key = 'MODULE_" . strtoupper($this->v_module_type) . "_INSTALLED'
LIMIT 1");
if(xtc_db_num_rows($t_get_modules_installed) == 1)
{
$t_modules_installed_result = xtc_db_fetch_array($t_get_modules_installed);
$t_modules_installed_result['configuration_value'] = str_replace('.php', '', $t_modules_installed_result['configuration_value']);
$t_modules_installed = explode(';', $t_modules_installed_result['configuration_value']);
}
return $t_modules_installed;
}
function get_missing_modules($p_structure_array)
{
$t_missing_modules = array();
if($t_dir = opendir($this->v_modules_directory))
{
while($t_file = readdir($t_dir))
{
if(substr($t_file, -4) == '.php')
{
if(strpos(serialize($p_structure_array), '"' . substr($t_file, 0, -4) . '"') === false && !in_array($t_file, $this->v_ignore_files_array))
{
$t_missing_modules[] = substr($t_file, 0, -4);
}
}
}
sort($t_missing_modules);
closedir($t_dir);
}
return $t_missing_modules;
}
function repair()
{
$t_modules_installed_array = $this->get_modules_installed();
if($t_dir = opendir($this->v_modules_directory))
{
while($t_file = readdir($t_dir))
{
if(substr($t_file, -4) == '.php')
{
include_once($this->v_modules_lang_directory . $t_file);
include_once($this->v_modules_directory . $t_file);
$t_module_name = substr($t_file, 0, -4);
if(xtc_class_exists($t_module_name))
{
$coo_module = new $t_module_name();
if($coo_module->check() && !in_array($coo_module->code, $t_modules_installed_array))
{
$t_modules_installed_array[] = $coo_module->code;
foreach($t_modules_installed_array AS $t_key => $t_value)
{
if(substr($t_value, -4) != '.php')
{
$t_modules_installed_array[$t_key] .= '.php';
}
if($t_modules_installed_array[$t_key] == '.php')
{
unset($t_modules_installed_array[$t_key]);
}
}
$t_modules_installed_array = array_unique($this->sort_modules($t_modules_installed_array));
xtc_db_query("UPDATE " . TABLE_CONFIGURATION . "
SET configuration_value = '" . xtc_db_input(implode(';', $t_modules_installed_array)) . "'
WHERE configuration_key = 'MODULE_" . strtoupper($this->v_module_type) . "_INSTALLED'");
}
elseif(!$coo_module->check() && in_array($coo_module->code, $t_modules_installed_array))
{
foreach($t_modules_installed_array AS $t_key => $t_value)
{
if($t_value == $coo_module->code)
{
unset($t_modules_installed_array[$t_key]);
}
if(substr($t_value, -4) != '.php')
{
$t_modules_installed_array[$t_key] .= '.php';
}
if($t_modules_installed_array[$t_key] == '.php')
{
unset($t_modules_installed_array[$t_key]);
}
}
$t_modules_installed_array = array_unique($this->sort_modules($t_modules_installed_array));
xtc_db_query("UPDATE " . TABLE_CONFIGURATION . "
SET configuration_value = '" . xtc_db_input(implode(';', $t_modules_installed_array)) . "'
WHERE configuration_key = 'MODULE_" . strtoupper($this->v_module_type) . "_INSTALLED'");
}
}
}
}
closedir($t_dir);
}
}
function sort_modules($p_modules_array)
{
$t_sorted_modules_array = array();
$t_modules_files_array = array();
$t_modules_sort_number_array = array();
foreach($p_modules_array AS $t_key => $t_file)
{
if(substr($t_file, -4) != '.php')
{
$t_file .= '.php';
}
if(is_file($this->v_modules_lang_directory . $t_file) && is_file($this->v_modules_directory . $t_file))
{
include_once($this->v_modules_lang_directory . $t_file);
include_once($this->v_modules_directory . $t_file);
$t_module_name = substr($t_file, 0, -4);
if(xtc_class_exists($t_module_name))
{
$coo_module = new $t_module_name();
if($coo_module->check())
{
if(isset($_POST['configuration']['MODULE_' . strtoupper($this->v_module_type) . '_' . strtoupper($t_module_name) . '_SORT_ORDER']))
{
$t_modules_sort_number_array[] = $_POST['configuration']['MODULE_' . strtoupper($this->v_module_type) . '_' . strtoupper($t_module_name) . '_SORT_ORDER'];
}
else
{
$t_modules_sort_number_array[] = $coo_module->sort_order;
}
$t_modules_files_array[] = $t_file;
}
}
}
}
asort($t_modules_sort_number_array);
reset($t_modules_sort_number_array);
foreach($t_modules_sort_number_array AS $t_key => $t_value)
{
$t_sorted_modules_array[] = $t_modules_files_array[$t_key];
}
return $t_sorted_modules_array;
}
function save_sort_order($p_modules_array)
{
$t_modules_array = array_unique($this->sort_modules($p_modules_array));
xtc_db_query("UPDATE " . TABLE_CONFIGURATION . "
SET configuration_value = '" . xtc_db_input(implode(';', $t_modules_array)) . "'
WHERE configuration_key = 'MODULE_" . strtoupper($this->v_module_type) . "_INSTALLED'");
}
function get_module_data_by_name($p_module_name)
{
$t_module_data = array();
if(file_exists($this->v_modules_lang_directory . basename($p_module_name) . '.php')
&&
file_exists($this->v_modules_directory . basename($p_module_name) . '.php'))
{
include_once($this->v_modules_lang_directory . basename($p_module_name) . '.php');
include_once($this->v_modules_directory . basename($p_module_name) . '.php');
if(xtc_class_exists($p_module_name))
{
$coo_module = new $p_module_name();
$t_module_keys_array = array();
$t_keys_array = $coo_module->keys();
for($i = 0; $i < count($t_keys_array); $i++)
{
$t_get_key_data = xtc_db_query("SELECT
configuration_key,
configuration_value,
use_function,
set_function
FROM " . TABLE_CONFIGURATION . "
WHERE
configuration_key = '" . $t_keys_array[$i] . "'
LIMIT 1");
if(xtc_db_num_rows($t_get_key_data) == 1)
{
$t_key_data = xtc_db_fetch_array($t_get_key_data);
$t_module_keys_array[$t_keys_array[$i]]['title'] = constant(strtoupper($t_keys_array[$i] . '_TITLE'));
$t_module_keys_array[$t_keys_array[$i]]['value'] = $t_key_data['configuration_value'];
$t_module_keys_array[$t_keys_array[$i]]['description'] = constant(strtoupper($t_keys_array[$i] . '_DESC'));
$t_module_keys_array[$t_keys_array[$i]]['use_function'] = $t_key_data['use_function'];
$t_module_keys_array[$t_keys_array[$i]]['set_function'] = $t_key_data['set_function'];
}
}
$t_module_data = array('code' => $coo_module->code,
'title' => $coo_module->title,
'description' => $coo_module->description,
'show_install' => $coo_module->show_install,
'sort_order' => ($coo_module->check() && is_numeric($coo_module->sort_order)) ? $coo_module->sort_order : '',
'arrow' => ($_GET['module'] != $coo_module->code) ? '<a href="' . $this->v_module_link . $coo_module->code . '" id="gm_module_arrow_inactive_' . $coo_module->code . '"><img src="' . DIR_WS_IMAGES . 'icon_info.gif" title="' . htmlspecialchars($coo_module->title) . '" /></a>' : '<img src="' . DIR_WS_IMAGES . 'icon_arrow_right.gif" title="' . htmlspecialchars($coo_module->title) . '" id="gm_module_arrow_active_' . $coo_module->code . '" />',
'status' => $coo_module->check(),
'keys' => $t_module_keys_array
);
}
}
return $t_module_data;
}
function show_modules($p_structure_array)
{
$t_structure_array = $p_structure_array;
if($this->v_show_missing_modules_menu)
{
$t_missing_modules_array = array(
array(
'TITLE' => GM_MODULES_MISSING_TITLE,
'MODULES' => $this->get_missing_modules($t_structure_array),
'DISPLAY' => $this->v_display_missing_modules
)
);
if(!empty($t_missing_modules_array[0]['MODULES'][0]))
{
$t_structure_array = array_merge($t_structure_array, $t_missing_modules_array);
}
}
if($this->v_show_installed_modules_menu)
{
$t_modules_installed_structure_array = array(
array('TITLE' => GM_MODULES_INSTALLED_TITLE,
'MODULES' => $this->get_modules_installed(),
'DISPLAY' => $this->v_display_installed_modules
)
);
if(!empty($t_modules_installed_structure_array[0]['MODULES'][0]))
{
$t_structure_array = array_merge($t_modules_installed_structure_array, $t_structure_array);
}
}
if(isset($_GET['module']))
{
foreach($t_structure_array AS $t_key => $t_value)
{
$t_structure_array[$t_key] = $this->expand_menu($t_value, $_GET['module']);
}
}
$this->draw_output($t_structure_array);
}
function expand_menu($p_structure_array, $p_module)
{
if(isset($p_structure_array['MODULES']) && is_array($p_structure_array['MODULES']))
{
foreach($p_structure_array['MODULES'] AS $t_index => $t_module)
{
if($t_module == $p_module)
{
$p_structure_array['DISPLAY'] = 1;
return $p_structure_array;
}
elseif(is_array($t_module))
{
$t_result = $this->expand_menu($t_module, $p_module);
if(is_array($t_result))
{
$p_structure_array['MODULES'][$t_index] = $t_result;
$p_structure_array['DISPLAY'] = 1;
}
}
}
}
return $p_structure_array;
}
function draw_output($p_structure, $p_depth = ' ')
{
foreach($p_structure AS $t_key => $t_value)
{
if(!is_array($t_value))
{
$t_module_data = $this->get_module_data_by_name($t_value);
if(!empty($t_module_data))
{
$t_active = '';
if($_GET['module'] == $t_module_data['code'])
{
$t_active = '_active';
}
echo '<div class="gm_modules' . $t_active . '" id="gm_modules_' . $t_module_data['code'] . '"><div style="float: left;">' . $p_depth . '</div><div style="float: left;">' . $t_module_data['title'] . ' (' . $t_module_data['code'] . ') </div><div style="float: right; margin-right: 10px; text-align:right;"><div class="gm_modules_arrow">' . $t_module_data['arrow'] . '</div>' . $t_module_data['sort_order'] . '</div></div>';
}
}
else
{
if(isset($t_value['TITLE']))
{
if(isset($t_value['DISPLAY']) && !$t_value['DISPLAY'])
{
$t_style = ' style="display: none;"';
$t_prefix = '<img src="gm/images/gm_modules_icon_plus.gif" width="9" height="9" border="0" /> ';
}
else
{
$t_style = '';
$t_prefix = '<img src="gm/images/gm_modules_icon_minus.gif" width="9" height="9" border="0" /> ';
}
echo '<div class="gm_modules_heading"><div class="gm_modules_title">' . $p_depth . $t_prefix . $t_value['TITLE'] . '</div><div class="gm_modules_block"' . $t_style . '>';
}
if(isset($t_value['MODULES']))
{
$this->draw_output($t_value['MODULES'], $p_depth . ' ');
}
if(isset($t_value['TITLE']))
{
echo '</div></div>';
}
}
}
}
}
?>