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

/modules/shipping/pages/admin/pre_process.php

http://phreedom.googlecode.com/
PHP | 183 lines | 154 code | 0 blank | 29 comment | 22 complexity | 105cfcb3f6fdb773ae6f0d9cb0e5ce61 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0
  1. <?php
  2. // +-----------------------------------------------------------------+
  3. // | PhreeBooks Open Source ERP |
  4. // +-----------------------------------------------------------------+
  5. // | Copyright (c) 2007-2008 PhreeSoft, LLC |
  6. // | http://www.PhreeSoft.com |
  7. // +-----------------------------------------------------------------+
  8. // | This program is free software: you can redistribute it and/or |
  9. // | modify it under the terms of the GNU General Public License as |
  10. // | published by the Free Software Foundation, either version 3 of |
  11. // | the License, or any later version. |
  12. // | |
  13. // | This program is distributed in the hope that it will be useful, |
  14. // | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  15. // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  16. // | GNU General Public License for more details. |
  17. // +-----------------------------------------------------------------+
  18. // Path: /modules/shipping/pages/admin/pre_process.php
  19. //
  20. $security_level = validate_user(SECURITY_ID_CONFIGURATION);
  21. /************** include page specific files *********************/
  22. gen_pull_language($module, 'admin');
  23. gen_pull_language('phreedom', 'admin');
  24. gen_pull_language('contacts');
  25. require_once(DIR_FS_WORKING . 'defaults.php');
  26. require_once(DIR_FS_WORKING . 'functions/shipping.php');
  27. require_once(DIR_FS_MODULES . 'phreedom/classes/backup.php');
  28. require_once(DIR_FS_WORKING . 'classes/install.php');
  29. /************** page specific initialization *************************/
  30. $error = false;
  31. $method_dir = DIR_FS_WORKING . 'methods/';
  32. $action = isset($_GET['action']) ? $_GET['action'] : $_POST['todo'];
  33. $install = new shipping_admin();
  34. // see if installing or removing a method
  35. if (substr($action, 0, 8) == 'install_') {
  36. $method = substr($action, 8);
  37. $action = 'install';
  38. } elseif (substr($action, 0, 7) == 'remove_') {
  39. $method = substr($action, 7);
  40. $action = 'remove';
  41. } elseif (substr($action, 0, 7) == 'signup_') {
  42. $method = substr($action, 7);
  43. $action = 'signup';
  44. }
  45. // load the available methods
  46. $methods = array();
  47. $contents = scandir($method_dir);
  48. foreach ($contents as $choice) {
  49. if ($choice <> '.' && $choice <> '..') {
  50. load_method_language($method_dir, $choice);
  51. $methods[] = $choice;
  52. }
  53. }
  54. /*************** Act on the action request *************************/
  55. switch ($action) {
  56. case 'install':
  57. validate_security($security_level, 4);
  58. require_once($method_dir . $method . '/' . $method . '.php');
  59. $properties = new $method();
  60. write_configure('MODULE_SHIPPING_' . strtoupper($method) . '_STATUS', '1');
  61. foreach ($properties->keys() as $key) write_configure($key['key'], $key['default']);
  62. if (method_exists($properties, 'install')) $properties->install(); // handle special case install, db, files, etc
  63. gen_redirect(html_href_link(FILENAME_DEFAULT, gen_get_all_get_params(array('action')), 'SSL'));
  64. break;
  65. case 'remove';
  66. validate_security($security_level, 4);
  67. require_once($method_dir . $method . '/' . $method . '.php');
  68. $properties = new $method();
  69. if (method_exists($properties, 'remove')) $properties->remove(); // handle special case removal, db, files, etc
  70. foreach ($properties->keys() as $key) { // remove all of the keys from the configuration table
  71. $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key = '" . $key['key'] . "'");
  72. }
  73. remove_configure('MODULE_SHIPPING_' . strtoupper($method) . '_STATUS');
  74. gen_redirect(html_href_link(FILENAME_DEFAULT, gen_get_all_get_params(array('action')), 'SSL'));
  75. break;
  76. case 'save':
  77. validate_security($security_level, 3);
  78. // foreach method if enabled, save info
  79. if (sizeof($methods) > 0) foreach ($methods as $shipper) {
  80. if (defined('MODULE_SHIPPING_' . strtoupper($shipper) . '_STATUS')) {
  81. require_once($method_dir . $shipper . '/' . $shipper . '.php');
  82. $properties = new $shipper;
  83. $properties->update();
  84. }
  85. }
  86. // save general tab
  87. foreach ($install->keys as $key => $default) {
  88. $field = strtolower($key);
  89. if (isset($_POST[$field])) write_configure($key, $_POST[$field]);
  90. }
  91. gen_redirect(html_href_link(FILENAME_DEFAULT, gen_get_all_get_params(array('action')), 'SSL'));
  92. break;
  93. case 'signup':
  94. validate_security($security_level, 4);
  95. require_once($method_dir . $method.'/'.$method.'.php');
  96. $properties = new $method();
  97. if (method_exists($properties, 'signup')) $properties->signup();
  98. // gen_redirect(html_href_link(FILENAME_DEFAULT, gen_get_all_get_params(array('action')), 'SSL'));
  99. break;
  100. case 'backup':
  101. $carrier = db_prepare_input($_POST['carrier']);
  102. $fy_month = db_prepare_input($_POST['fy_month']);
  103. $fy_year = db_prepare_input($_POST['fy_year']);
  104. $conv_type = db_prepare_input($_POST['conv_type']);
  105. // set execution time limit to a large number to allow extra time
  106. if (ini_get('max_execution_time') < 20000) set_time_limit(20000);
  107. $backup = new backup;
  108. $backup->source_dir = DIR_FS_MY_FILES . $_SESSION['company'].'/shipping/labels/'.$carrier.'/'.$fy_year.'/'.$fy_month.'/';
  109. $backup->dest_dir = DIR_FS_MY_FILES . 'backups/';
  110. switch ($conv_type) {
  111. case 'bz2':
  112. $backup->dest_file = 'ship_' . $carrier . '_' . $fy_year . $fy_month . '.tar.bz2';
  113. if ($backup->make_bz2('dir')) $error = true;
  114. break;
  115. default:
  116. case 'zip':
  117. $backup->dest_file = 'ship_' . $carrier . '_' . $fy_year . $fy_month . '.zip';
  118. if ($backup->make_zip('dir')) $error = true;
  119. break;
  120. }
  121. if (!$error) {
  122. gen_add_audit_log(GEN_DB_DATA_BACKUP, TABLE_AUDIT_LOG);
  123. $backup->download($backup->dest_dir, $backup->dest_file); // will not return if successful
  124. }
  125. $default_tab_id = 'tools';
  126. break;
  127. case 'clean':
  128. $carrier = db_prepare_input($_POST['carrier']);
  129. $fy_month = db_prepare_input($_POST['fy_month']);
  130. $fy_year = db_prepare_input($_POST['fy_year']);
  131. $conv_type = db_prepare_input($_POST['conv_type']);
  132. $backup = new backup;
  133. $backup->source_dir = DIR_FS_MY_FILES . $_SESSION['company'] . '/shipping/labels/' . $carrier . '/' . $fy_year . '/' . $fy_month . '/';
  134. if ($backup->delete_dir($backup->source_dir, $recursive = true)) $error = true;
  135. if (!$error) gen_add_audit_log(GEN_FILE_DATA_CLEAN);
  136. $default_tab_id = 'tools';
  137. break;
  138. default:
  139. }
  140. /***************** prepare to display templates *************************/
  141. // build some general pull down arrays
  142. $sel_yes_no = array(
  143. array('id' => '0', 'text' => TEXT_NO),
  144. array('id' => '1', 'text' => TEXT_YES),
  145. );
  146. $sel_checked = array(
  147. array('id' => '0', 'text' => TEXT_UNCHECKED),
  148. array('id' => '1', 'text' => TEXT_CHECKED),
  149. );
  150. $sel_show = array(
  151. array('id' => '0', 'text' => TEXT_HIDE),
  152. array('id' => '1', 'text' => TEXT_SHOW),
  153. );
  154. $sel_fy_month = array(
  155. array('id' => '01', 'text'=> TEXT_JAN),
  156. array('id' => '02', 'text'=> TEXT_FEB),
  157. array('id' => '03', 'text'=> TEXT_MAR),
  158. array('id' => '04', 'text'=> TEXT_APR),
  159. array('id' => '05', 'text'=> TEXT_MAY),
  160. array('id' => '06', 'text'=> TEXT_JUN),
  161. array('id' => '07', 'text'=> TEXT_JUL),
  162. array('id' => '08', 'text'=> TEXT_AUG),
  163. array('id' => '09', 'text'=> TEXT_SEP),
  164. array('id' => '10', 'text'=> TEXT_OCT),
  165. array('id' => '11', 'text'=> TEXT_NOV),
  166. array('id' => '12', 'text'=> TEXT_DEC),
  167. );
  168. $sel_fy_year = array();
  169. for ($i = 0; $i < 8; $i++) {
  170. $sel_fy_year[] = array('id' => date('Y')-$i, 'text' => date('Y')-$i);
  171. }
  172. $sel_method = array();
  173. $sel_method[] = array('id' => '', 'text' => GEN_HEADING_PLEASE_SELECT);
  174. foreach ($methods as $value) {
  175. if (defined('MODULE_SHIPPING_' . strtoupper($value) . '_STATUS')) {
  176. $sel_method[] = array('id' => $value, 'text' => constant('MODULE_SHIPPING_' . strtoupper($value) . '_TEXT_TITLE'));
  177. }
  178. }
  179. $include_header = true;
  180. $include_footer = true;
  181. $include_template = 'template_main.php';
  182. define('PAGE_TITLE', MODULE_SHIPPING_TITLE);
  183. ?>