/upload/admin/admin_cron.php

http://torrentpier2.googlecode.com/ · PHP · 235 lines · 204 code · 28 blank · 3 comment · 39 complexity · a2849c18fdc34ad7a20035e106f61d52 MD5 · raw file

  1. <?php
  2. // ACP Header - START
  3. if (!empty($setmodules))
  4. {
  5. if (IS_SUPER_ADMIN)
  6. {
  7. $module['TorrentPier']['Cron'] = basename(__FILE__) . '?mode=list';
  8. }
  9. return;
  10. }
  11. $mode = isset($_GET['mode']) ? $_GET['mode'] : '';
  12. $job_id = isset($_GET['id']) ? (int) $_GET['id'] : '';
  13. $submit = isset($_POST['submit']);
  14. $jobs = isset($_POST['select']) ? implode(',', $_POST['select']) : '';
  15. $cron_action = isset($_POST['cron_action']) ? $_POST['cron_action'] : '';
  16. if ($mode == 'run' && !$job_id)
  17. {
  18. define('BB_ROOT', './../');
  19. require(BB_ROOT.'common.php');
  20. $user->session_start();
  21. redirect('admin/'.basename(__FILE__) . '?mode=list');
  22. }
  23. else require('./pagestart.php');
  24. // ACP Header - END
  25. if (!IS_SUPER_ADMIN) bb_die($lang['NOT_ADMIN']);
  26. require(INC_DIR .'functions_admin_torrent.php');
  27. require(INC_DIR .'functions_admin_cron.php');
  28. $sql = DB()->fetch_rowset("SELECT * FROM ". BB_CONFIG ." WHERE config_name = 'cron_enabled' OR config_name = 'cron_check_interval'");
  29. foreach ($sql as $row)
  30. {
  31. $config_name = $row['config_name'];
  32. $config_value = $row['config_value'];
  33. $default_config[$config_name] = $config_value;
  34. $new[$config_name] = isset($_POST[$config_name]) ? $_POST[$config_name] : $default_config[$config_name];
  35. if (isset($_POST['submit']) && $row['config_value'] != $new[$config_name])
  36. {
  37. bb_update_config(array($config_name => $new[$config_name]));
  38. }
  39. }
  40. $template->assign_vars(array(
  41. 'CRON_ENABLED' => ($new['cron_enabled']) ? true : false,
  42. 'CRON_CHECK_INTERVAL' => $new['cron_check_interval'],
  43. ));
  44. switch($mode)
  45. {
  46. case 'list':
  47. $sql = DB()->fetch_rowset("SELECT * FROM ". BB_CRON ." ORDER BY cron_id");
  48. foreach ($sql as $i => $row)
  49. {
  50. $template->assign_block_vars('list', array(
  51. 'ROW_CLASS' => !($i % 2) ? 'row2' : 'row1',
  52. 'JOB_ID' => $i + 1,
  53. 'CRON_ID' => $row['cron_id'],
  54. 'CRON_ACTIVE' => $row['cron_active'] ? '<img src="../images/icon_run.gif" alt="'. $lang['YES'] .'" />' : '<img src="../images/icon_delete.gif" alt="'. $lang['NO'] .'" />',
  55. 'CRON_TITLE' => $row['cron_title'],
  56. 'CRON_SCRIPT' => $row['cron_script'],
  57. 'SCHEDULE' => $row['schedule'] ? $lang['SCHEDULE'][$row['schedule']] : '<b class="leech">'. $lang['NOSELECT'] .'</b>',
  58. 'RUN_DAY' => $row['run_day'],
  59. 'LAST_RUN' => $row['last_run'],
  60. 'NEXT_RUN' => $row['next_run'],
  61. 'RUN_COUNT' => $row['run_counter'],
  62. ));
  63. }
  64. $template->assign_vars(array(
  65. 'TPL_CRON_LIST' => true,
  66. 'S_CRON_ACTION' => 'admin_cron.php',
  67. 'S_MODE' => 'list',
  68. ));
  69. //detect cron status
  70. if (@file_exists('../triggers/cron_running'))
  71. {
  72. $template->assign_vars(array(
  73. 'CRON_RUNNING' => true,
  74. ));
  75. }
  76. break;
  77. case 'repair':
  78. if (@file_exists('../triggers/cron_running'))
  79. {
  80. rename("../triggers/cron_running", "../triggers/cron_allowed");
  81. }
  82. redirect('admin/'.basename(__FILE__) . '?mode=list');
  83. break;
  84. case 'run':
  85. run_jobs($job_id);
  86. redirect('admin/'.basename(__FILE__) . '?mode=list');
  87. break;
  88. case 'edit':
  89. $sql = DB()->fetch_rowset("SELECT * FROM ". BB_CRON ." WHERE cron_id = $job_id");
  90. foreach ($sql as $row)
  91. {
  92. $template->assign_vars(array(
  93. 'CRON_ID' => $row['cron_id'],
  94. 'CRON_ACTIVE' => $row['cron_active'],
  95. 'CRON_TITLE' => $row['cron_title'],
  96. 'CRON_SCRIPT' => $row['cron_script'],
  97. 'SCHEDULE' => $row['schedule'] ? $lang['SCHEDULE'][$row['schedule']] : '',
  98. 'RUN_DAY' => $row['run_day'],
  99. 'RUN_TIME' => $row['run_time'],
  100. 'RUN_ORDER' => $row['run_order'],
  101. 'LAST_RUN' => $row['last_run'],
  102. 'NEXT_RUN' => $row['next_run'],
  103. 'RUN_INTERVAL' => $row['run_interval'],
  104. 'LOG_ENABLED' => $row['log_enabled'],
  105. 'LOG_FILE' => $row['log_file'],
  106. 'LOG_SQL_QUERIES' => $row['log_sql_queries'],
  107. 'DISABLE_BOARD' => $row['disable_board'],
  108. 'RUN_COUNTER' => $row['run_counter'],
  109. ));
  110. }
  111. $run_day = array($lang['DELTA_TIME']['INTERVALS']['mday'][0] => 0);
  112. for ($i = 1; $i <= 28; $i++)
  113. {
  114. $run_day[$i] = $i;
  115. }
  116. $schedule = array($lang['SCHEDULE']['select'] => 0);
  117. foreach ($lang['SCHEDULE'] as $type => $key)
  118. {
  119. $schedule[$key] = $type;
  120. }
  121. $template->assign_vars(array(
  122. 'TPL_CRON_EDIT' => true,
  123. 'S_CRON_ACTION' => 'admin_cron.php',
  124. 'S_MODE' => 'edit',
  125. 'SCHEDULE' => build_select('schedule', $schedule, $row['schedule']),
  126. 'RUN_DAY' => build_select('run_day', $run_day, $row['run_day']),
  127. 'L_CRON_EDIT_HEAD' => $lang['CRON_EDIT_HEAD_EDIT'],
  128. ));
  129. break;
  130. case 'add':
  131. $run_day = array($lang['DELTA_TIME']['INTERVALS']['mday'][0] => 0);
  132. for ($i = 1; $i <= 28; $i++)
  133. {
  134. $run_day[$i] = $i;
  135. }
  136. $schedule = array();
  137. foreach ($lang['SCHEDULE'] as $type => $key)
  138. {
  139. $schedule[$key] = $type;
  140. }
  141. $template->assign_vars(array(
  142. 'TPL_CRON_EDIT' => true,
  143. 'S_CRON_ACTION' => 'admin_cron.php',
  144. 'S_MODE' => 'add',
  145. 'SCHEDULE' => build_select('schedule', $schedule, 'select', null, null),
  146. 'RUN_DAY' => build_select('run_day', $run_day, 0, null, null),
  147. 'L_CRON_EDIT_HEAD' => $lang['CRON_EDIT_HEAD_ADD'],
  148. 'CRON_ID' => 'none',
  149. 'CRON_ACTIVE' => 1,
  150. 'CRON_TITLE' => '',
  151. 'CRON_SCRIPT' => '',
  152. 'RUN_TIME' => '',
  153. 'RUN_ORDER' => 255,
  154. 'LAST_RUN' => '0000-00-00 00:00:00',
  155. 'NEXT_RUN' => '0000-00-00 00:00:00',
  156. 'RUN_INTERVAL' => '',
  157. 'LOG_ENABLED' => 0,
  158. 'LOG_FILE' => '',
  159. 'LOG_SQL_QUERIES' => 0,
  160. 'DISABLE_BOARD' => 0,
  161. 'RUN_COUNTER' => 0,
  162. ));
  163. break;
  164. case 'delete':
  165. delete_jobs($job_id);
  166. $message = $lang['JOB_REMOVED'] . '<br /><br />' . sprintf($lang['CLICK_RETURN_JOBS'], '<a href="admin_cron.php?mode=list">', '</a>') . '<br /><br />' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '<a href="index.php?pane=right">', '</a>');
  167. message_die(GENERAL_MESSAGE, $message);
  168. break;
  169. }
  170. if ($submit)
  171. {
  172. if ($_POST['mode'] == 'list')
  173. {
  174. if ($cron_action == 'run' && $jobs)
  175. {
  176. run_jobs($jobs);
  177. }
  178. else if ($cron_action == 'delete' && $jobs)
  179. {
  180. delete_jobs($jobs);
  181. }
  182. else if (($cron_action == 'disable' || $cron_action == 'enable') && $jobs)
  183. {
  184. toggle_active($jobs, $cron_action);
  185. }
  186. redirect('admin/'.basename(__FILE__) . '?mode=list');
  187. }
  188. else if (validate_cron_post($_POST) == 1)
  189. {
  190. if($_POST['mode'] == 'edit')
  191. {
  192. update_cron_job($_POST);
  193. }
  194. else if ($_POST['mode'] == 'add')
  195. {
  196. insert_cron_job($_POST);
  197. }
  198. else bb_die();
  199. redirect('admin/'.basename(__FILE__) . '?mode=list');
  200. }
  201. else
  202. {
  203. $message = validate_cron_post($_POST);
  204. message_die(GENERAL_MESSAGE, $message);
  205. }
  206. }
  207. print_page('admin_cron.tpl', 'admin');