[ Index ]
osCommerce Docs :: PHP Cross Reference For osCommerce 2.2 MS2
Provided By OSCdox.com

/admin/ -> modules.php (source)

[Summary view]

   1  <?php
   2  /*
   3    $Id: modules.php,v 1.47 2003/06/29 22:50:52 hpdl Exp $
   4  
   5    osCommerce, Open Source E-Commerce Solutions
   6    http://www.oscommerce.com
   7  
   8    Copyright (c) 2003 osCommerce
   9  
  10    Released under the GNU General Public License
  11  */
  12  
  13    require ('includes/application_top.php');
  14  
  15    $set = (isset($HTTP_GET_VARS['set']) ? $HTTP_GET_VARS['set'] : '');
  16  
  17    if (tep_not_null($set)) {
  18      switch ($set) {
  19        case 'shipping':
  20          $module_type = 'shipping';
  21          $module_directory = DIR_FS_CATALOG_MODULES . 'shipping/';
  22          $module_key = 'MODULE_SHIPPING_INSTALLED';
  23          define('HEADING_TITLE', HEADING_TITLE_MODULES_SHIPPING);
  24          break;
  25        case 'ordertotal':
  26          $module_type = 'order_total';
  27          $module_directory = DIR_FS_CATALOG_MODULES . 'order_total/';
  28          $module_key = 'MODULE_ORDER_TOTAL_INSTALLED';
  29          define('HEADING_TITLE', HEADING_TITLE_MODULES_ORDER_TOTAL);
  30          break;
  31        case 'payment':
  32        default:
  33          $module_type = 'payment';
  34          $module_directory = DIR_FS_CATALOG_MODULES . 'payment/';
  35          $module_key = 'MODULE_PAYMENT_INSTALLED';
  36          define('HEADING_TITLE', HEADING_TITLE_MODULES_PAYMENT);
  37          break;
  38      }
  39    }
  40  
  41    $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');
  42  
  43    if (tep_not_null($action)) {
  44      switch ($action) {
  45        case 'save':
  46          while (list($key, $value) = each($HTTP_POST_VARS['configuration'])) {
  47            tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $value . "' where configuration_key = '" . $key . "'");
  48          }
  49          tep_redirect(tep_href_link(FILENAME_MODULES, 'set=' . $set . '&module=' . $HTTP_GET_VARS['module']));
  50          break;
  51        case 'install':
  52        case 'remove':
  53          $file_extension = substr($PHP_SELF, strrpos($PHP_SELF, '.'));
  54          $class = basename($HTTP_GET_VARS['module']);
  55          if (file_exists($module_directory . $class . $file_extension)) {
  56            include($module_directory . $class . $file_extension);
  57            $module = new $class;
  58            if ($action == 'install') {
  59              $module->install();
  60            } elseif ($action == 'remove') {
  61              $module->remove();
  62            }
  63          }
  64          tep_redirect(tep_href_link(FILENAME_MODULES, 'set=' . $set . '&module=' . $class));
  65          break;
  66      }
  67    }
  68  ?>
  69  <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
  70  <html <?php echo HTML_PARAMS; ?>>
  71  <head>
  72  <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
  73  <title><?php echo TITLE; ?></title>
  74  <link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
  75  <script language="javascript" src="includes/general.js"></script>
  76  </head>
  77  <body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
  78  <!-- header //-->
  79  <?php require (DIR_WS_INCLUDES . 'header.php'); ?>
  80  <!-- header_eof //-->
  81  
  82  <!-- body //-->
  83  <table border="0" width="100%" cellspacing="2" cellpadding="2">
  84    <tr>
  85      <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
  86  <!-- left_navigation //-->
  87  <?php require (DIR_WS_INCLUDES . 'column_left.php'); ?>
  88  <!-- left_navigation_eof //-->
  89      </table></td>
  90  <!-- body_text //-->
  91      <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
  92        <tr>
  93          <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
  94            <tr>
  95              <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
  96              <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
  97            </tr>
  98          </table></td>
  99        </tr>
 100        <tr>
 101          <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
 102            <tr>
 103              <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
 104                <tr class="dataTableHeadingRow">
 105                  <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_MODULES; ?></td>
 106                  <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_SORT_ORDER; ?></td>
 107                  <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
 108                </tr>
 109  <?php
 110    $file_extension = substr($PHP_SELF, strrpos($PHP_SELF, '.'));
 111    $directory_array = array();
 112    if ($dir = @dir($module_directory)) {
 113      while ($file = $dir->read()) {
 114        if (!is_dir($module_directory . $file)) {
 115          if (substr($file, strrpos($file, '.')) == $file_extension) {
 116            $directory_array[] = $file;
 117          }
 118        }
 119      }
 120      sort($directory_array);
 121      $dir->close();
 122    }
 123  
 124    $installed_modules = array();
 125    for ($i=0, $n=sizeof($directory_array); $i<$n; $i++) {
 126      $file = $directory_array[$i];
 127  
 128      include(DIR_FS_CATALOG_LANGUAGES . $language . '/modules/' . $module_type . '/' . $file);
 129      include($module_directory . $file);
 130  
 131      $class = substr($file, 0, strrpos($file, '.'));
 132      if (tep_class_exists($class)) {
 133        $module = new $class;
 134        if ($module->check() > 0) {
 135          if ($module->sort_order > 0) {
 136            $installed_modules[$module->sort_order] = $file;
 137          } else {
 138            $installed_modules[] = $file;
 139          }
 140        }
 141  
 142        if ((!isset($HTTP_GET_VARS['module']) || (isset($HTTP_GET_VARS['module']) && ($HTTP_GET_VARS['module'] == $class))) && !isset($mInfo)) {
 143          $module_info = array('code' => $module->code,
 144                               'title' => $module->title,
 145                               'description' => $module->description,
 146                               'status' => $module->check());
 147  
 148          $module_keys = $module->keys();
 149  
 150          $keys_extra = array();
 151          for ($j=0, $k=sizeof($module_keys); $j<$k; $j++) {
 152            $key_value_query = tep_db_query("select configuration_title, configuration_value, configuration_description, use_function, set_function from " . TABLE_CONFIGURATION . " where configuration_key = '" . $module_keys[$j] . "'");
 153            $key_value = tep_db_fetch_array($key_value_query);
 154  
 155            $keys_extra[$module_keys[$j]]['title'] = $key_value['configuration_title'];
 156            $keys_extra[$module_keys[$j]]['value'] = $key_value['configuration_value'];
 157            $keys_extra[$module_keys[$j]]['description'] = $key_value['configuration_description'];
 158            $keys_extra[$module_keys[$j]]['use_function'] = $key_value['use_function'];
 159            $keys_extra[$module_keys[$j]]['set_function'] = $key_value['set_function'];
 160          }
 161  
 162          $module_info['keys'] = $keys_extra;
 163  
 164          $mInfo = new objectInfo($module_info);
 165        }
 166  
 167        if (isset($mInfo) && is_object($mInfo) && ($class == $mInfo->code) ) {
 168          if ($module->check() > 0) {
 169            echo '              <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_MODULES, 'set=' . $set . '&module=' . $class . '&action=edit') . '\'">' . "\n";
 170          } else {
 171            echo '              <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)">' . "\n";
 172          }
 173        } else {
 174          echo '              <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_MODULES, 'set=' . $set . '&module=' . $class) . '\'">' . "\n";
 175        }
 176  ?>
 177                  <td class="dataTableContent"><?php echo $module->title; ?></td>
 178                  <td class="dataTableContent" align="right"><?php if (is_numeric($module->sort_order)) echo $module->sort_order; ?></td>
 179                  <td class="dataTableContent" align="right"><?php if (isset($mInfo) && is_object($mInfo) && ($class == $mInfo->code) ) { echo tep_image(DIR_WS_IMAGES . 'icon_arrow_right.gif'); } else { echo '<a href="' . tep_href_link(FILENAME_MODULES, 'set=' . $set . '&module=' . $class) . '">' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
 180                </tr>
 181  <?php
 182      }
 183    }
 184  
 185    ksort($installed_modules);
 186    $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = '" . $module_key . "'");
 187    if (tep_db_num_rows($check_query)) {
 188      $check = tep_db_fetch_array($check_query);
 189      if ($check['configuration_value'] != implode(';', $installed_modules)) {
 190        tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . implode(';', $installed_modules) . "', last_modified = now() where configuration_key = '" . $module_key . "'");
 191      }
 192    } else {
 193      tep_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) . "', 'This is automatically updated. No need to edit.', '6', '0', now())");
 194    }
 195  ?>
 196                <tr>
 197                  <td colspan="3" class="smallText"><?php echo TEXT_MODULE_DIRECTORY . ' ' . $module_directory; ?></td>
 198                </tr>
 199              </table></td>
 200  <?php
 201    $heading = array();
 202    $contents = array();
 203  
 204    switch ($action) {
 205      case 'edit':
 206        $keys = '';
 207        reset($mInfo->keys);
 208        while (list($key, $value) = each($mInfo->keys)) {
 209          $keys .= '<b>' . $value['title'] . '</b><br>' . $value['description'] . '<br>';
 210  
 211          if ($value['set_function']) {
 212            eval('$keys .= ' . $value['set_function'] . "'" . $value['value'] . "', '" . $key . "');");
 213          } else {
 214            $keys .= tep_draw_input_field('configuration[' . $key . ']', $value['value']);
 215          }
 216          $keys .= '<br><br>';
 217        }
 218        $keys = substr($keys, 0, strrpos($keys, '<br><br>'));
 219  
 220        $heading[] = array('text' => '<b>' . $mInfo->title . '</b>');
 221  
 222        $contents = array('form' => tep_draw_form('modules', FILENAME_MODULES, 'set=' . $set . '&module=' . $HTTP_GET_VARS['module'] . '&action=save'));
 223        $contents[] = array('text' => $keys);
 224        $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_update.gif', IMAGE_UPDATE) . ' <a href="' . tep_href_link(FILENAME_MODULES, 'set=' . $set . '&module=' . $HTTP_GET_VARS['module']) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
 225        break;
 226      default:
 227        $heading[] = array('text' => '<b>' . $mInfo->title . '</b>');
 228  
 229        if ($mInfo->status == '1') {
 230          $keys = '';
 231          reset($mInfo->keys);
 232          while (list(, $value) = each($mInfo->keys)) {
 233            $keys .= '<b>' . $value['title'] . '</b><br>';
 234            if ($value['use_function']) {
 235              $use_function = $value['use_function'];
 236              if (ereg('->', $use_function)) {
 237                $class_method = explode('->', $use_function);
 238                if (!is_object(${$class_method[0]})) {
 239                  include(DIR_WS_CLASSES . $class_method[0] . '.php');
 240                  ${$class_method[0]} = new $class_method[0]();
 241                }
 242                $keys .= tep_call_function($class_method[1], $value['value'], ${$class_method[0]});
 243              } else {
 244                $keys .= tep_call_function($use_function, $value['value']);
 245              }
 246            } else {
 247              $keys .= $value['value'];
 248            }
 249            $keys .= '<br><br>';
 250          }
 251          $keys = substr($keys, 0, strrpos($keys, '<br><br>'));
 252  
 253          $contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link(FILENAME_MODULES, 'set=' . $set . '&module=' . $mInfo->code . '&action=remove') . '">' . tep_image_button('button_module_remove.gif', IMAGE_MODULE_REMOVE) . '</a> <a href="' . tep_href_link(FILENAME_MODULES, 'set=' . $set . (isset($HTTP_GET_VARS['module']) ? '&module=' . $HTTP_GET_VARS['module'] : '') . '&action=edit') . '">' . tep_image_button('button_edit.gif', IMAGE_EDIT) . '</a>');
 254          $contents[] = array('text' => '<br>' . $mInfo->description);
 255          $contents[] = array('text' => '<br>' . $keys);
 256        } else {
 257          $contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link(FILENAME_MODULES, 'set=' . $set . '&module=' . $mInfo->code . '&action=install') . '">' . tep_image_button('button_module_install.gif', IMAGE_MODULE_INSTALL) . '</a>');
 258          $contents[] = array('text' => '<br>' . $mInfo->description);
 259        }
 260        break;
 261    }
 262  
 263    if ( (tep_not_null($heading)) && (tep_not_null($contents)) ) {
 264      echo '            <td width="25%" valign="top">' . "\n";
 265  
 266      $box = new box;
 267      echo $box->infoBox($heading, $contents);
 268  
 269      echo '            </td>' . "\n";
 270    }
 271  ?>
 272            </tr>
 273          </table></td>
 274        </tr>
 275      </table></td>
 276  <!-- body_text_eof //-->
 277    </tr>
 278  </table>
 279  <!-- body_eof //-->
 280  
 281  <!-- footer //-->
 282  <?php require (DIR_WS_INCLUDES . 'footer.php'); ?>
 283  <!-- footer_eof //-->
 284  <br>
 285  </body>
 286  </html>
 287  <?php require (DIR_WS_INCLUDES . 'application_bottom.php'); ?>


Generated: Tue Nov 4 23:53:39 2003
Hosted By :: AABox.com
Cross-referenced by PHPXref 0.4