modules.php

来自「全新且完善的强大网上商店系统」· PHP 代码 · 共 277 行

PHP
277
字号
<?php
/*
  [SOOBIC!] admin/modules.php 

	Version: 1.5
	Author: soolan (soolan@qq.com)
	Copyright: soolan (www.soobic.com)
	Last Modified: 2005/4/16 10:00

*/

if(!defined('IN_SOOBIC')) {
        exit('Access Denied');
}

cpheader();

include ("admin/languages/".$language."/modules.php");

if(!$allowsetmodules){
    cpmsg("对不起,您的管理权限受限,不能进行此操作。");
}

$action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : (isset($HTTP_POST_VARS['action']) ? $HTTP_POST_VARS['action'] : ''));

$set = (isset($HTTP_GET_VARS['set']) ? $HTTP_GET_VARS['set'] : '');
if (isset($set)) {
    switch ($set) {
      case 'shipping':
        $module_type = 'shipping';
        $module_directory = 'modules/shipping/';
        $module_key = 'MODULE_SHIPPING_INSTALLED';
        define('HEADING_TITLE', HEADING_TITLE_MODULES_SHIPPING);
        break;
      case 'ordertotal':
        $module_type = 'order_total';
        $module_directory = 'modules/order_total/';
        $module_key = 'MODULE_ORDER_TOTAL_INSTALLED';
        define('HEADING_TITLE', HEADING_TITLE_MODULES_ORDER_TOTAL);
        break;
      case 'payment':
      default:
        $module_type = 'payment';
        $module_directory = 'modules/payment/';
        $module_key = 'MODULE_PAYMENT_INSTALLED';
        define('HEADING_TITLE', HEADING_TITLE_MODULES_PAYMENT);
        break;
    }
}
if ($action) {
    switch ($action) {
       case 'save':
          while (list($key, $value) = each($HTTP_POST_VARS['configuration'])) {
             $db->query("update $table_configuration set configuration_value = '" . $value . "' where configuration_key = '" . $key . "'");
          }
          updatecache('settings');
					cpmsg("操作成功!", tep_href_link('admincp.php', 'act=modules&set=' . $set . '&module=' . $HTTP_GET_VARS['module']));
		  break;
      case 'install':
      case 'remove':
          $file_extension = substr($PHP_SELF, strrpos($PHP_SELF, '.'));
          $class = basename($HTTP_GET_VARS['module']);
          if (file_exists($module_directory . $class . $file_extension)) {
              include($module_directory . $class . $file_extension);
              $module = new $class;
              if ($action == 'install') {
                  $module->install();
              } elseif ($action == 'remove') {
                  $module->remove();
              }
          }
          updatecache('settings');
          cpmsg("操作成功!", tep_href_link('admincp.php', 'act=modules&set=' . $set . '&module=' . $class));
		   break;
    }
}elseif($type){
		if (isset($HTTP_GET_VARS['module']) ) {
          $file_extension = substr($PHP_SELF, strrpos($PHP_SELF, '.'));
          $class = basename($HTTP_GET_VARS['module']);
				  include('languages/'. $language . '/modules/' . $module_type. '/' . $class . $file_extension);
				  if (file_exists($module_directory . $class . $file_extension)) {
              include($module_directory . $class . $file_extension);
              $module = new $class;
              if ($action == 'install') {
                  $module->install();
              } elseif ($action == 'remove') {
                  $module->remove();
              }
          }
				  $module_info = array('code' => $module->code,
                             'title' => $module->title,
                             'description' => $module->description,
                             'status' => $module->check());
          $module_keys = $module->keys();
         	$keys_extra = array();
          for ($j=0, $k=sizeof($module_keys); $j<$k; $j++) {
               $query = $db->query("select configuration_title, configuration_value, configuration_description, use_function, set_function from $table_configuration where configuration_key = '" . $module_keys[$j] . "'");
               $key_value = $db->fetch_array($query);
               $keys_extra[$module_keys[$j]]['title'] = $key_value['configuration_title'];
               $keys_extra[$module_keys[$j]]['value'] = $key_value['configuration_value'];
               $keys_extra[$module_keys[$j]]['description'] = $key_value['configuration_description'];
               $keys_extra[$module_keys[$j]]['use_function'] = $key_value['use_function'];
               $keys_extra[$module_keys[$j]]['set_function'] = $key_value['set_function'];
          }
          $module_info['keys'] = $keys_extra;
          @extract($module_info);
    }
    switch ($type) {
       case 'edit':
           reset($keys);
           $key='';
					 foreach($keys as $key1=>$value){
               $key .= '<tr><td bgcolor="'.ALTBG1.'" width="60%"><b>' . $value['title'] . '</b><br>' . $value['description'] . '</td>';
               $key.='<td bgcolor="'.ALTBG2.'">';
							 if ($value['set_function']) {
									 eval('$key .= '. $value['set_function'] . "'" . $value['value'] . "', '" . $key1 . "');");
							 } else {
                   $key .= tep_draw_input_field('configuration[' . $key1 . ']', $value['value']);
               }
               $key .= '</td></tr>';
           }
           $form='<form name="modules" action="'.tep_href_link('admincp.php', 'act=modules&set='.$set.'&module='.$HTTP_GET_VARS['module'] . '&action=save', 'NONSSL') . '"  method="post">';
					 $link5=tep_image_submit('button_update.gif',IMAGE_UPDATE); 
					 $link2='<a href="'. tep_href_link('admincp.php', 'act=modules&set=' . $set . '&type=more&module=' . $HTTP_GET_VARS['module']).'">'.tep_image_button('button_cancel.gif',IMAGE_CANCEL).'</a>';
       break;
       default:           
					 if ($status == '1') {
               reset($keys);
							 $key='';
							 foreach($keys as $value){
                   $key .= '<tr><td bgcolor="'.ALTBG1.'">' . $value['title'] . '</td>';
                   if ($value['use_function']) {
                        $use_function = $value['use_function'];
                        if (ereg('->', $use_function)) {
                              $class_method = explode('->', $use_function);
                              if (!is_object(${$class_method[0]})) {
                                   include('admin/includes/class/' . $class_method[0] . '.php');
                                   ${$class_method[0]} = new $class_method[0]();
                              }
                              $key .= '<td bgcolor="'.ALTBG1.'">' . tep_call_function($class_method[1], $value['value'], ${$class_method[0]}). '</td></tr>';
                        } else {
                              $key .= '<td bgcolor="'.ALTBG1.'">' . tep_call_function($use_function, $value['value']). '</td></tr>';
                        }
                  } else {
                        $key .= '<td bgcolor="'.ALTBG1.'">' . $value['value']. '</td></tr>';
                  }
              }
              $link1='<a href="' . tep_href_link('admincp.php', 'act=modules&set=' . $set . '&module=' . $code . '&action=remove') . '" class="bold">'.IMAGE_MODULE_REMOVE.'</a>';
              $link2='<a href="' . tep_href_link('admincp.php', 'act=modules&set=' . $set . (isset($HTTP_GET_VARS['module']) ? '&module=' . $HTTP_GET_VARS['module'] : '') . '&type=edit') . '" class="bold">'.IMAGE_EDIT.'</a>';
              $link3='<a href="' . tep_href_link('admincp.php','act=modules&&set=' . $set . '&module=' . $code).'" class="bold">'.IMAGE_BACK.'</a>';
					 } else {
              $link1='<a href="' . tep_href_link('admincp.php', 'act=modules&set=' . $set . '&module=' . $code . '&action=install') . '" class="bold">'.IMAGE_MODULE_INSTALL.'</a>';
           }
        break;
    }
    
?> 
<br>
<table cellspacing="0" cellpadding="0" border="0" width="95%" align="center">
<tr><td bgcolor="<?=BORDERCOLOR?>">
<table border="0" cellspacing="<?=BORDERWIDTH?>" cellpadding="<?=TABLESPACE?>" width="100%">
<tr class="header"><td>特别提示</td></tr>
<tr bgcolor="<?=ALTBG1?>"><td><table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr><td><ul><li><b><?=$title;?>&nbsp;&nbsp;&nbsp;显示给顾客的信息如下:</b></ul><ul><?=$description; ?></ul></td>
<td align="right"><?php echo $link3.'<br><br>'.$link2.'<br><br>'.$link1; ?></td>
</tr></table></td></tr></table></td></tr></table>
<br>
<?=$form;?>
<table cellspacing="0" cellpadding="0" border="0" width="95%" align="center" style="word-break:break-all;"> 
<tr><td bgcolor="<?=BORDERCOLOR?>"> 
<table border="0" cellspacing="<?=BORDERWIDTH?>" cellpadding="<?=TABLESPACE?>" width="100%" style="word-break:break-all;"> 
<tr class="header" >
<td align="left"><?=TEXT_CONFIGURATION; ?></td>
<td align="left"><?=TEXT_CONFIGURATION_VALUE; ?></td>
</tr>
<?=$key; ?>
</table></td></tr></table>
<br><center><?=$warning?>
<?php echo '<br>'.$link5.'&nbsp;&nbsp;&nbsp;'.$link2.'&nbsp;&nbsp;&nbsp;'.$link3;?>
</center><? echo $form ?  '</form>' : '';?><br><br>
<?

}else{
     
    function tep_class_exists($class_name) {
        if (function_exists('class_exists')) {
            return class_exists($class_name);
        } else {
            return true;
        }
    }
?>


<br>
<table cellspacing="0" cellpadding="0" border="0" width="95%" align="center">
<tr><td bgcolor="<?=BORDERCOLOR?>">
<table border="0" cellspacing="<?=BORDERWIDTH?>" cellpadding="<?=TABLESPACE?>" width="100%">
<tr class="header"><td>特别提示</td></tr>
<tr bgcolor="<?=ALTBG1?>"><td><table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr><td><?=TEXT_MODULE_TIP;?></td>
</tr></table></td></tr></table></td></tr></table>
<br>

<table cellspacing="0" cellpadding="0" border="0" width="95%" align="center" style="word-break:break-all;"> 
<tr><td bgcolor="<?=BORDERCOLOR?>"> 
<table border="0" cellspacing="<?=BORDERWIDTH?>" cellpadding="<?=TABLESPACE?>" width="100%" style="word-break:break-all;"> 
<tr class="header" align="left">
<td bgcolor="<?=ALTBG1?>"><?=TABLE_HEADING_MODULES; ?></td>
<td bgcolor="<?=ALTBG1?>" align="center"><?=TABLE_HEADING_SORT_ORDER; ?></td>
<td bgcolor="<?=ALTBG1?>" align="center"><?=TEXT_HEADING_STATUS; ?></td>
<td bgcolor="<?=ALTBG1?>" align="center"><?=TABLE_HEADING_ACTION; ?></td>
</tr>


<?php
    $file_extension = substr($PHP_SELF, strrpos($PHP_SELF, '.'));
    $directory_array = array();
    if ($dir = @dir($module_directory)) {
        while ($file = $dir->read()) {
            if (!is_dir($module_directory . $file)) {
               if (substr($file, strrpos($file, '.')) == $file_extension) {
                   $directory_array[] = $file;
               }
            }
        }
        sort($directory_array);
        $dir->close();
    }

    $installed_modules = array();
    for ($i=0, $n=sizeof($directory_array); $i<$n; $i++) {
          $file = $directory_array[$i];

          include('languages/'. $language . '/modules/' . $module_type . '/' . $file);
          include($module_directory . $file);

          $class = substr($file, 0, strrpos($file, '.'));
          if (tep_class_exists($class)) {
							$module = new $class;
              if ($module->check() > 0) {
                   if ($module->sort_order > 0) {
                       $installed_modules[$module->sort_order] = $file;
                   } else {
                       $installed_modules[] = $file;
                   }
              }
?>
              <tr>  
								<td bgcolor="<?=ALTBG1?>"><?php echo $module->title; ?></td>
                <td bgcolor="<?=ALTBG1?>" align="center" width="15%"><?php if (is_numeric($module->sort_order)) echo $module->sort_order; ?></td>
                <td bgcolor="<?=ALTBG1?>" align="center" width="15%"><?php echo ( $module->enabled== 1 || $module->enabled =='True' ) ? TEXT_STATUS_ON : TEXT_STATUS_OFF; ?></td>
                <td bgcolor="<?=ALTBG1?>" align="center" width="15%"><?php echo '<a href="' . tep_href_link('admincp.php', 'act=modules&set=' . $set . '&type=more&module=' . $class) . '">详情</a>';?>&nbsp;</td>
              </tr>
<?php
          }
    }
    ksort($installed_modules);
    $check_query = $db->query("select configuration_value from $table_configuration where configuration_key = '" . $module_key . "'");
    if ($db->num_rows($check_query)) {
         $check = $db->fetch_array($check_query);
         if ($check['configuration_value'] != implode(';', $installed_modules)) {
              $db->query("update $table_configuration set configuration_value = '" . implode(';', $installed_modules) . "', last_modified = now() where configuration_key = '" . $module_key . "'");
         }
    } else {
         $db->query("insert into $table_configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Installed Modules', '" . $module_key . "', '" . implode(';', $installed_modules) . "', '系统自动更新,不需要手动更改.', '6', '0', now())");
    }
?>
              <tr>
                <td colspan="4" bgcolor="<?=ALTBG1?>"><?php echo TEXT_MODULE_DIRECTORY . ' ' . $module_directory; ?></td>
              </tr>
      </table></td></tr></table>

<?
}
?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?