PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/oscommerce-2.2rc2/admin/modules.php

http://myopensources.googlecode.com/
PHP | 306 lines | 263 code | 31 blank | 12 comment | 61 complexity | 49f6e0ed5c43b1f510c48afea4e13c9b MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /*
  3. $Id: modules.php 1802 2008-01-11 16:59:17Z hpdl $
  4. osCommerce, Open Source E-Commerce Solutions
  5. http://www.oscommerce.com
  6. Copyright (c) 2008 osCommerce
  7. Released under the GNU General Public License
  8. */
  9. require('includes/application_top.php');
  10. $set = (isset($HTTP_GET_VARS['set']) ? $HTTP_GET_VARS['set'] : '');
  11. if (tep_not_null($set)) {
  12. switch ($set) {
  13. // START STS 4.1
  14. case 'sts':
  15. $module_type = 'sts';
  16. $module_directory = DIR_FS_CATALOG_MODULES . 'sts/';
  17. $module_key = 'MODULE_STS_INSTALLED';
  18. define('HEADING_TITLE', HEADING_TITLE_MODULES_STS);
  19. break;
  20. // END STS 4.1
  21. case 'shipping':
  22. $module_type = 'shipping';
  23. $module_directory = DIR_FS_CATALOG_MODULES . 'shipping/';
  24. $module_key = 'MODULE_SHIPPING_INSTALLED';
  25. define('HEADING_TITLE', HEADING_TITLE_MODULES_SHIPPING);
  26. break;
  27. case 'ordertotal':
  28. $module_type = 'order_total';
  29. $module_directory = DIR_FS_CATALOG_MODULES . 'order_total/';
  30. $module_key = 'MODULE_ORDER_TOTAL_INSTALLED';
  31. define('HEADING_TITLE', HEADING_TITLE_MODULES_ORDER_TOTAL);
  32. break;
  33. case 'payment':
  34. default:
  35. $module_type = 'payment';
  36. $module_directory = DIR_FS_CATALOG_MODULES . 'payment/';
  37. $module_key = 'MODULE_PAYMENT_INSTALLED';
  38. define('HEADING_TITLE', HEADING_TITLE_MODULES_PAYMENT);
  39. break;
  40. }
  41. }
  42. $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');
  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. <!-- body //-->
  82. <table border="0" width="100%" cellspacing="2" cellpadding="2">
  83. <tr>
  84. <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
  85. <!-- left_navigation //-->
  86. <?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
  87. <!-- left_navigation_eof //-->
  88. </table></td>
  89. <!-- body_text //-->
  90. <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
  91. <tr>
  92. <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
  93. <tr>
  94. <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
  95. <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
  96. </tr>
  97. </table></td>
  98. </tr>
  99. <tr>
  100. <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
  101. <tr>
  102. <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
  103. <tr class="dataTableHeadingRow">
  104. <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_MODULES; ?></td>
  105. <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_SORT_ORDER; ?></td>
  106. <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
  107. </tr>
  108. <?php
  109. $file_extension = substr($PHP_SELF, strrpos($PHP_SELF, '.'));
  110. $directory_array = array();
  111. if ($dir = @dir($module_directory)) {
  112. while ($file = $dir->read()) {
  113. if (!is_dir($module_directory . $file)) {
  114. if (substr($file, strrpos($file, '.')) == $file_extension) {
  115. $directory_array[] = $file;
  116. }
  117. }
  118. }
  119. sort($directory_array);
  120. $dir->close();
  121. }
  122. $installed_modules = array();
  123. for ($i=0, $n=sizeof($directory_array); $i<$n; $i++) {
  124. $file = $directory_array[$i];
  125. include(DIR_FS_CATALOG_LANGUAGES . $language . '/modules/' . $module_type . '/' . $file);
  126. include($module_directory . $file);
  127. $class = substr($file, 0, strrpos($file, '.'));
  128. if (tep_class_exists($class)) {
  129. $module = new $class;
  130. if ($module->check() > 0) {
  131. if ($module->sort_order > 0) {
  132. $installed_modules[$module->sort_order] = $file;
  133. } else {
  134. $installed_modules[] = $file;
  135. }
  136. }
  137. if ((!isset($HTTP_GET_VARS['module']) || (isset($HTTP_GET_VARS['module']) && ($HTTP_GET_VARS['module'] == $class))) && !isset($mInfo)) {
  138. $module_info = array('code' => $module->code,
  139. 'title' => $module->title,
  140. 'description' => $module->description,
  141. 'status' => $module->check(),
  142. 'signature' => (isset($module->signature) ? $module->signature : null));
  143. $module_keys = $module->keys();
  144. $keys_extra = array();
  145. for ($j=0, $k=sizeof($module_keys); $j<$k; $j++) {
  146. $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] . "'");
  147. $key_value = tep_db_fetch_array($key_value_query);
  148. $keys_extra[$module_keys[$j]]['title'] = $key_value['configuration_title'];
  149. $keys_extra[$module_keys[$j]]['value'] = $key_value['configuration_value'];
  150. $keys_extra[$module_keys[$j]]['description'] = $key_value['configuration_description'];
  151. $keys_extra[$module_keys[$j]]['use_function'] = $key_value['use_function'];
  152. $keys_extra[$module_keys[$j]]['set_function'] = $key_value['set_function'];
  153. }
  154. $module_info['keys'] = $keys_extra;
  155. $mInfo = new objectInfo($module_info);
  156. }
  157. if (isset($mInfo) && is_object($mInfo) && ($class == $mInfo->code) ) {
  158. if ($module->check() > 0) {
  159. 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";
  160. } else {
  161. echo ' <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)">' . "\n";
  162. }
  163. } else {
  164. echo ' <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_MODULES, 'set=' . $set . '&module=' . $class) . '\'">' . "\n";
  165. }
  166. ?>
  167. <td class="dataTableContent"><?php echo $module->title; ?></td>
  168. <td class="dataTableContent" align="right"><?php if (is_numeric($module->sort_order)) echo $module->sort_order; ?></td>
  169. <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>
  170. </tr>
  171. <?php
  172. }
  173. }
  174. ksort($installed_modules);
  175. $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = '" . $module_key . "'");
  176. if (tep_db_num_rows($check_query)) {
  177. $check = tep_db_fetch_array($check_query);
  178. if ($check['configuration_value'] != implode(';', $installed_modules)) {
  179. tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . implode(';', $installed_modules) . "', last_modified = now() where configuration_key = '" . $module_key . "'");
  180. }
  181. } else {
  182. 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())");
  183. }
  184. ?>
  185. <tr>
  186. <td colspan="3" class="smallText"><?php echo TEXT_MODULE_DIRECTORY . ' ' . $module_directory; ?></td>
  187. </tr>
  188. </table></td>
  189. <?php
  190. $heading = array();
  191. $contents = array();
  192. switch ($action) {
  193. case 'edit':
  194. $keys = '';
  195. reset($mInfo->keys);
  196. while (list($key, $value) = each($mInfo->keys)) {
  197. $keys .= '<b>' . $value['title'] . '</b><br>' . $value['description'] . '<br>';
  198. if ($value['set_function']) {
  199. eval('$keys .= ' . $value['set_function'] . "'" . $value['value'] . "', '" . $key . "');");
  200. } else {
  201. $keys .= tep_draw_input_field('configuration[' . $key . ']', $value['value']);
  202. }
  203. $keys .= '<br><br>';
  204. }
  205. $keys = substr($keys, 0, strrpos($keys, '<br><br>'));
  206. $heading[] = array('text' => '<b>' . $mInfo->title . '</b>');
  207. $contents = array('form' => tep_draw_form('modules', FILENAME_MODULES, 'set=' . $set . '&module=' . $HTTP_GET_VARS['module'] . '&action=save'));
  208. $contents[] = array('text' => $keys);
  209. $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>');
  210. break;
  211. default:
  212. $heading[] = array('text' => '<b>' . $mInfo->title . '</b>');
  213. if ($mInfo->status == '1') {
  214. $keys = '';
  215. reset($mInfo->keys);
  216. while (list(, $value) = each($mInfo->keys)) {
  217. $keys .= '<b>' . $value['title'] . '</b><br>';
  218. if ($value['use_function']) {
  219. $use_function = $value['use_function'];
  220. if (ereg('->', $use_function)) {
  221. $class_method = explode('->', $use_function);
  222. if (!is_object(${$class_method[0]})) {
  223. include(DIR_WS_CLASSES . $class_method[0] . '.php');
  224. ${$class_method[0]} = new $class_method[0]();
  225. }
  226. $keys .= tep_call_function($class_method[1], $value['value'], ${$class_method[0]});
  227. } else {
  228. $keys .= tep_call_function($use_function, $value['value']);
  229. }
  230. } else {
  231. $keys .= $value['value'];
  232. }
  233. $keys .= '<br><br>';
  234. }
  235. $keys = substr($keys, 0, strrpos($keys, '<br><br>'));
  236. $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>');
  237. if (isset($mInfo->signature) && (list($scode, $smodule, $sversion, $soscversion) = explode('|', $mInfo->signature))) {
  238. $contents[] = array('text' => '<br>' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '&nbsp;<b>' . TEXT_INFO_VERSION . '</b> ' . $sversion . ' (<a href="http://sig.oscommerce.com/' . $mInfo->signature . '" target="_blank">' . TEXT_INFO_ONLINE_STATUS . '</a>)');
  239. }
  240. $contents[] = array('text' => '<br>' . $mInfo->description);
  241. $contents[] = array('text' => '<br>' . $keys);
  242. } else {
  243. $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>');
  244. if (isset($mInfo->signature) && (list($scode, $smodule, $sversion, $soscversion) = explode('|', $mInfo->signature))) {
  245. $contents[] = array('text' => '<br>' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '&nbsp;<b>' . TEXT_INFO_VERSION . '</b> ' . $sversion . ' (<a href="http://sig.oscommerce.com/' . $mInfo->signature . '" target="_blank">' . TEXT_INFO_ONLINE_STATUS . '</a>)');
  246. }
  247. $contents[] = array('text' => '<br>' . $mInfo->description);
  248. }
  249. break;
  250. }
  251. if ( (tep_not_null($heading)) && (tep_not_null($contents)) ) {
  252. echo ' <td width="25%" valign="top">' . "\n";
  253. $box = new box;
  254. echo $box->infoBox($heading, $contents);
  255. echo ' </td>' . "\n";
  256. }
  257. ?>
  258. </tr>
  259. </table></td>
  260. </tr>
  261. </table></td>
  262. <!-- body_text_eof //-->
  263. </tr>
  264. </table>
  265. <!-- body_eof //-->
  266. <!-- footer //-->
  267. <?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
  268. <!-- footer_eof //-->
  269. <br>
  270. </body>
  271. </html>
  272. <?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>