[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/admin/modules/tools/ -> tasks.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.6
   4   * Copyright 2010 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://mybb.com
   7   * License: http://mybb.com/about/license
   8   *
   9   * $Id: tasks.php 5828 2012-05-08 16:06:16Z Tomm $
  10   */
  11  
  12  // Disallow direct access to this file for security reasons
  13  if(!defined("IN_MYBB"))
  14  {
  15      die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
  16  }
  17  
  18  require_once  MYBB_ROOT."/inc/functions_task.php";
  19  
  20  $page->add_breadcrumb_item($lang->task_manager, "index.php?module=tools-tasks");
  21  
  22  $plugins->run_hooks("admin_tools_tasks_begin");
  23  
  24  /**
  25   * Validates a string or array of values
  26   * 
  27   * @param mixed Comma-separated list or array of values
  28   * @param int Minimum value
  29   * @param int Maximum value
  30   * @param string Set "string" to return in a comma-separated list, or "array" to return in an array
  31   * @return mixed String or array of valid values OR false if string/array is invalid
  32   */
  33  function check_time_values($value, $min, $max, $return_type)
  34  {
  35      // If the values aren't in an array form, make them into an array
  36      if(!is_array($value))
  37      {
  38          // Empty value == *
  39          if($value === '')
  40          {
  41              return ($return_type == 'string') ? '*' : array('*');
  42          }
  43          $implode = 1;
  44          $value = explode(',', $value);
  45      }
  46      // If * is in the array, always return with * because it overrides all
  47      if(in_array('*', $value))
  48      {
  49          return ($return_type == 'string') ? '*' : array('*');
  50      }
  51      // Validate each value in array
  52      foreach($value as $time)
  53      {
  54          if($time < $min || $time > $max)
  55          {
  56              return false;
  57          }
  58      }
  59      // Return based on return type
  60      if($return_type == 'string')
  61      {
  62          $value = implode(',', $value);
  63      }
  64      return $value;
  65  }
  66  
  67  if($mybb->input['action'] == "add")
  68  {
  69      $plugins->run_hooks("admin_tools_tasks_add");
  70      
  71      if($mybb->request_method == "post")
  72      {
  73          if(!trim($mybb->input['title']))
  74          {
  75              $errors[] = $lang->error_missing_title;
  76          }
  77  
  78          if(!trim($mybb->input['description']))
  79          {
  80              $errors[] = $lang->error_missing_description;
  81          }
  82  
  83          if(!file_exists(MYBB_ROOT."inc/tasks/".$mybb->input['file'].".php"))
  84          {
  85              $errors[] = $lang->error_invalid_task_file;
  86          }
  87  
  88          $mybb->input['minute'] = check_time_values($mybb->input['minute'], 0, 59, 'string');
  89          if($mybb->input['minute'] === false)
  90          {
  91              $errors[] = $lang->error_invalid_minute;
  92          }
  93  
  94          $mybb->input['hour'] = check_time_values($mybb->input['hour'], 0, 59, 'string');
  95          if($mybb->input['hour'] === false)
  96          {
  97              $errors[] = $lang->error_invalid_hour;
  98          }
  99  
 100          if($mybb->input['day'] != "*" && $mybb->input['day'] != '')
 101          {
 102              $mybb->input['day'] = check_time_values($mybb->input['day'], 1, 31, 'string');
 103              if($mybb->input['day'] === false)
 104              {
 105                  $errors[] = $lang->error_invalid_day;
 106              }
 107              $mybb->input['weekday'] = array('*');
 108          }
 109          else
 110          {
 111              $mybb->input['weekday'] = check_time_values($mybb->input['weekday'], 0, 6, 'array');
 112              if($mybb->input['weekday'] === false)
 113              {
 114                  $errors[] = $lang->error_invalid_weekday;
 115              }
 116              $mybb->input['day'] = '*';
 117          }
 118  
 119          $mybb->input['month'] = check_time_values($mybb->input['month'], 1, 12, 'array');
 120          if($mybb->input['month'] === false)
 121          {
 122              $errors[] = $lang->error_invalid_month;
 123          }
 124  
 125          if(!$errors)
 126          {
 127              $new_task = array(
 128                  "title" => $db->escape_string($mybb->input['title']),
 129                  "description" => $db->escape_string($mybb->input['description']),
 130                  "file" => $db->escape_string($mybb->input['file']),
 131                  "minute" => $db->escape_string($mybb->input['minute']),
 132                  "hour" => $db->escape_string($mybb->input['hour']),
 133                  "day" => $db->escape_string($mybb->input['day']),
 134                  "month" => $db->escape_string(implode(',', $mybb->input['month'])),
 135                  "weekday" => $db->escape_string(implode(',', $mybb->input['weekday'])),
 136                  "enabled" => intval($mybb->input['enabled']),
 137                  "logging" => intval($mybb->input['logging'])
 138              );
 139  
 140              $new_task['nextrun'] = fetch_next_run($new_task);
 141              $tid = $db->insert_query("tasks", $new_task);
 142              $cache->update_tasks();
 143              
 144              $plugins->run_hooks("admin_tools_tasks_add_commit");
 145  
 146              // Log admin action
 147              log_admin_action($tid, $mybb->input['title']);
 148  
 149              flash_message($lang->success_task_created, 'success');
 150              admin_redirect("index.php?module=tools-tasks");
 151          }
 152      }
 153      $page->add_breadcrumb_item($lang->add_new_task);
 154      $page->output_header($lang->scheduled_tasks." - ".$lang->add_new_task);
 155  
 156  
 157      $sub_tabs['scheduled_tasks'] = array(
 158          'title' => $lang->scheduled_tasks,
 159          'link' => "index.php?module=tools-tasks"
 160      );
 161  
 162      $sub_tabs['add_task'] = array(
 163          'title' => $lang->add_new_task,
 164          'link' => "index.php?module=tools-tasks&amp;action=add",
 165          'description' => $lang->add_new_task_desc
 166      );
 167  
 168      $sub_tabs['task_logs'] = array(
 169          'title' => $lang->view_task_logs,
 170          'link' => "index.php?module=tools-tasks&amp;action=logs"
 171      );    
 172  
 173      $page->output_nav_tabs($sub_tabs, 'add_task');
 174      $form = new Form("index.php?module=tools-tasks&amp;action=add", "post", "add");
 175      if($errors)
 176      {
 177          $page->output_inline_error($errors);
 178      }
 179      else
 180      {
 181          $mybb->input['minute'] = '*';
 182          $mybb->input['hour'] = '*';
 183          $mybb->input['day'] = '*';
 184          $mybb->input['weekday'] = '*';
 185          $mybb->input['month'] = '*';
 186      }
 187      $form_container = new FormContainer($lang->add_new_task);
 188      $form_container->output_row($lang->title." <em>*</em>", "", $form->generate_text_box('title', $mybb->input['title'], array('id' => 'title')), 'title');
 189      $form_container->output_row($lang->short_description." <em>*</em>", "", $form->generate_text_box('description', $mybb->input['description'], array('id' => 'description')), 'description');
 190  
 191      $task_list = array();
 192      $task_files = scandir(MYBB_ROOT."inc/tasks/");
 193      foreach($task_files as $task_file)
 194      {
 195          if(is_file(MYBB_ROOT."inc/tasks/{$task_file}") && get_extension($task_file) == "php")
 196          {
 197              $file_id = preg_replace("#\.".get_extension($task_file)."$#i", "$1", $task_file);
 198              $task_list[$file_id] = $task_file;
 199          }
 200      }
 201      $form_container->output_row($lang->task_file." <em>*</em>", $lang->task_file_desc, $form->generate_select_box("file", $task_list, $mybb->input['file'], array('id' => 'file')), 'file');
 202      $form_container->output_row($lang->time_minutes, $lang->time_minutes_desc, $form->generate_text_box('minute', $mybb->input['minute'], array('id' => 'minute')), 'minute');
 203      $form_container->output_row($lang->time_hours, $lang->time_hours_desc, $form->generate_text_box('hour', $mybb->input['hour'], array('id' => 'hour')), 'hour');
 204      $form_container->output_row($lang->time_days_of_month, $lang->time_days_of_month_desc, $form->generate_text_box('day', $mybb->input['day'], array('id' => 'day')), 'day');
 205  
 206      $options = array(
 207          "*" => $lang->every_weekday,
 208          "0" => $lang->sunday,
 209          "1" => $lang->monday,
 210          "2" => $lang->tuesday,
 211          "3" => $lang->wednesday,
 212          "4" => $lang->thursday,
 213          "5" => $lang->friday,
 214          "6" => $lang->saturday
 215      );
 216      $form_container->output_row($lang->time_weekdays, $lang->time_weekdays_desc, $form->generate_select_box('weekday[]', $options, $mybb->input['weekday'], array('id' => 'weekday', 'multiple' => true, 'size' => 8)), 'weekday');
 217  
 218      $options = array(
 219          "*" => $lang->every_month,
 220          "1" => $lang->january,
 221          "2" => $lang->february,
 222          "3" => $lang->march,
 223          "4" => $lang->april,
 224          "5" => $lang->may,
 225          "6" => $lang->june,
 226          "7" => $lang->july,
 227          "8" => $lang->august,
 228          "9" => $lang->september,
 229          "10" => $lang->october,
 230          "11" => $lang->november,
 231          "12" => $lang->december
 232      );
 233      $form_container->output_row($lang->time_months, $lang->time_months_desc, $form->generate_select_box('month[]', $options, $mybb->input['month'], array('id' => 'month', 'multiple' => true, 'size' => 13)), 'month');
 234  
 235      $form_container->output_row($lang->enable_logging." <em>*</em>", "", $form->generate_yes_no_radio("logging", $mybb->input['logging'], true));
 236      
 237      $form_container->output_row($lang->enabled." <em>*</em>", "", $form->generate_yes_no_radio("enabled", $mybb->input['enabled'], true));
 238      $form_container->end();
 239  
 240      $buttons[] = $form->generate_submit_button($lang->save_task);
 241  
 242      $form->output_submit_wrapper($buttons);
 243      $form->end();
 244  
 245      $page->output_footer();
 246  }
 247  
 248  if($mybb->input['action'] == "edit")
 249  {
 250      $plugins->run_hooks("admin_tools_tasks_edit");
 251      
 252      $query = $db->simple_select("tasks", "*", "tid='".intval($mybb->input['tid'])."'");
 253      $task = $db->fetch_array($query);
 254  
 255      // Does the task not exist?
 256      if(!$task['tid'])
 257      {
 258          flash_message($lang->error_invalid_task, 'error');
 259          admin_redirect("index.php?module=tools-tasks");
 260      }
 261  
 262      if($mybb->request_method == "post")
 263      {
 264          if(!trim($mybb->input['title']))
 265          {
 266              $errors[] = $lang->error_missing_title;
 267          }
 268  
 269          if(!trim($mybb->input['description']))
 270          {
 271              $errors[] = $lang->error_missing_description;
 272          }
 273  
 274          if(!file_exists(MYBB_ROOT."inc/tasks/".$mybb->input['file'].".php"))
 275          {
 276              $errors[] = $lang->error_invalid_task_file;
 277          }
 278  
 279          $mybb->input['minute'] = check_time_values($mybb->input['minute'], 0, 59, 'string');
 280          if($mybb->input['minute'] === false)
 281          {
 282              $errors[] = $lang->error_invalid_minute;
 283          }
 284  
 285          $mybb->input['hour'] = check_time_values($mybb->input['hour'], 0, 59, 'string');
 286          if($mybb->input['hour'] === false)
 287          {
 288              $errors[] = $lang->error_invalid_hour;
 289          }
 290  
 291          if($mybb->input['day'] != "*" && $mybb->input['day'] != '')
 292          {
 293              $mybb->input['day'] = check_time_values($mybb->input['day'], 1, 31, 'string');
 294              if($mybb->input['day'] === false)
 295              {
 296                  $errors[] = $lang->error_invalid_day;
 297              }
 298              $mybb->input['weekday'] = array('*');
 299          }
 300          else
 301          {
 302              $mybb->input['weekday'] = check_time_values($mybb->input['weekday'], 0, 6, 'array');
 303              if($mybb->input['weekday'] === false)
 304              {
 305                  $errors[] = $lang->error_invalid_weekday;
 306              }
 307              $mybb->input['day'] = '*';
 308          }
 309  
 310          $mybb->input['month'] = check_time_values($mybb->input['month'], 1, 12, 'array');
 311          if($mybb->input['month'] === false)
 312          {
 313              $errors[] = $lang->error_invalid_month;
 314          }
 315          
 316          if(!$errors)
 317          {
 318              $enable_confirmation = false;
 319              // Check if we need to ask the user to confirm turning on the task
 320              if(($task['file'] == "backupdb" || $task['file'] == "checktables") && $task['enabled'] == 0 && $mybb->input['enabled'] == 1)
 321              {
 322                  $mybb->input['enabled'] = 0;
 323                  $enable_confirmation = true;
 324              }
 325              
 326              $updated_task = array(
 327                  "title" => $db->escape_string($mybb->input['title']),
 328                  "description" => $db->escape_string($mybb->input['description']),
 329                  "file" => $db->escape_string($mybb->input['file']),
 330                  "minute" => $db->escape_string($mybb->input['minute']),
 331                  "hour" => $db->escape_string($mybb->input['hour']),
 332                  "day" => $db->escape_string($mybb->input['day']),
 333                  "month" => $db->escape_string(implode(',', $mybb->input['month'])),
 334                  "weekday" => $db->escape_string(implode(',', $mybb->input['weekday'])),
 335                  "enabled" => intval($mybb->input['enabled']),
 336                  "logging" => intval($mybb->input['logging'])
 337              );
 338  
 339              $updated_task['nextrun'] = fetch_next_run($updated_task);
 340              $db->update_query("tasks", $updated_task, "tid='{$task['tid']}'");
 341              $cache->update_tasks();
 342              
 343              $plugins->run_hooks("admin_tools_tasks_edit_commit");
 344  
 345              // Log admin action
 346              log_admin_action($task['tid'], $mybb->input['title']);
 347  
 348              flash_message($lang->success_task_updated, 'success');
 349              
 350              if($enable_confirmation == true)
 351              {
 352                  admin_redirect("index.php?module=tools-tasks&amp;action=enable&amp;tid={$task['tid']}&amp;my_post_key={$mybb->post_code}");
 353              }
 354              else
 355              {
 356                  admin_redirect("index.php?module=tools-tasks");
 357              }
 358          }
 359      }
 360  
 361      $page->add_breadcrumb_item($lang->edit_task);
 362      $page->output_header($lang->scheduled_tasks." - ".$lang->edit_task);
 363      
 364      $sub_tabs['edit_task'] = array(
 365          'title' => $lang->edit_task,
 366          'description' => $lang->edit_task_desc,
 367          'link' => "index.php?module=tools-tasks&amp;action=edit&amp;tid={$task['tid']}"
 368      );
 369  
 370      $page->output_nav_tabs($sub_tabs, 'edit_task');
 371  
 372      $form = new Form("index.php?module=tools-tasks&amp;action=edit", "post");
 373  
 374      if($errors)
 375      {
 376          $page->output_inline_error($errors);
 377          $task_data = $mybb->input;
 378      }
 379      else
 380      {
 381          $task_data = $task;
 382          $task_data['weekday'] = explode(',', $task['weekday']);
 383          $task_data['month'] = explode(',', $task['month']);
 384      }
 385  
 386      $form_container = new FormContainer($lang->edit_task);
 387      echo $form->generate_hidden_field("tid", $task['tid']);
 388      $form_container->output_row($lang->title." <em>*</em>", "", $form->generate_text_box('title', $task_data['title'], array('id' => 'title')), 'title');
 389      $form_container->output_row($lang->short_description, "", $form->generate_text_box('description', $task_data['description'], array('id' => 'description')), 'description');
 390  
 391      $task_list = array();
 392      $task_files = scandir(MYBB_ROOT."inc/tasks/");
 393      foreach($task_files as $task_file)
 394      {
 395          if(is_file(MYBB_ROOT."inc/tasks/{$task_file}") && get_extension($task_file) == "php")
 396          {
 397              $file_id = preg_replace("#\.".get_extension($task_file)."$#i", "$1", $task_file);
 398              $task_list[$file_id] = $task_file;
 399          }
 400      }
 401      $form_container->output_row($lang->task." <em>*</em>", $lang->task_file_desc, $form->generate_select_box("file", $task_list, $task_data['file'], array('id' => 'file')), 'file');
 402      $form_container->output_row($lang->time_minutes, $lang->time_minutes_desc, $form->generate_text_box('minute', $task_data['minute'], array('id' => 'minute')), 'minute');
 403      $form_container->output_row($lang->time_hours, $lang->time_hours_desc, $form->generate_text_box('hour', $task_data['hour'], array('id' => 'hour')), 'hour');
 404      $form_container->output_row($lang->time_days_of_month, $lang->time_days_of_month_desc, $form->generate_text_box('day', $task_data['day'], array('id' => 'day')), 'day');
 405  
 406      $options = array(
 407          "*" => $lang->every_weekday,
 408          "0" => $lang->sunday,
 409          "1" => $lang->monday,
 410          "2" => $lang->tuesday,
 411          "3" => $lang->wednesday,
 412          "4" => $lang->thursday,
 413          "5" => $lang->friday,
 414          "6" => $lang->saturday
 415      );
 416      $form_container->output_row($lang->time_weekdays, $lang->time_weekdays_desc, $form->generate_select_box('weekday[]', $options, $task_data['weekday'], array('id' => 'weekday', 'multiple' => true)), 'weekday');
 417  
 418      $options = array(
 419          "*" => $lang->every_month,
 420          "1" => $lang->january,
 421          "2" => $lang->february,
 422          "3" => $lang->march,
 423          "4" => $lang->april,
 424          "5" => $lang->may,
 425          "6" => $lang->june,
 426          "7" => $lang->july,
 427          "8" => $lang->august,
 428          "9" => $lang->september,
 429          "10" => $lang->october,
 430          "11" => $lang->november,
 431          "12" => $lang->december
 432      );
 433      $form_container->output_row($lang->time_months, $lang->time_months_desc, $form->generate_select_box('month[]', $options, $task_data['month'], array('id' => 'month', 'multiple' => true)), 'month');
 434  
 435      $form_container->output_row($lang->enable_logging." <em>*</em>", "", $form->generate_yes_no_radio("logging", $task_data['logging'], true));
 436      
 437      $form_container->output_row($lang->enabled." <em>*</em>", "", $form->generate_yes_no_radio("enabled", $task_data['enabled'], true));
 438      $form_container->end();
 439  
 440      $buttons[] = $form->generate_submit_button($lang->save_task);
 441  
 442      $form->output_submit_wrapper($buttons);
 443      $form->end();
 444  
 445      $page->output_footer();
 446  }
 447  
 448  if($mybb->input['action'] == "delete")
 449  {
 450      $plugins->run_hooks("admin_tools_tasks_delete");
 451      
 452      $query = $db->simple_select("tasks", "*", "tid='".intval($mybb->input['tid'])."'");
 453      $task = $db->fetch_array($query);
 454  
 455      // Does the task not exist?
 456      if(!$task['tid'])
 457      {
 458          flash_message($lang->error_invalid_task, 'error');
 459          admin_redirect("index.php?module=tools-tasks");
 460      }
 461      
 462      // User clicked no
 463      if($mybb->input['no'])
 464      {
 465          admin_redirect("index.php?module=tools-tasks");
 466      }
 467  
 468      if($mybb->request_method == "post")
 469      {
 470          // Delete the task & any associated task log entries
 471          $db->delete_query("tasks", "tid='{$task['tid']}'");
 472          $db->delete_query("tasklog", "tid='{$task['tid']}'");
 473  
 474          // Fetch next task run
 475          $cache->update_tasks();
 476          
 477          $plugins->run_hooks("admin_tools_tasks_delete_commit");
 478  
 479          // Log admin action
 480          log_admin_action($task['tid'], $task['title']);
 481  
 482          flash_message($lang->success_task_deleted, 'success');
 483          admin_redirect("index.php?module=tools-tasks");
 484      }
 485      else
 486      {
 487          $page->output_confirm_action("index.php?module=tools-tasks&amp;action=delete&amp;tid={$task['tid']}", $lang->confirm_task_deletion);
 488      }
 489  }
 490  
 491  if($mybb->input['action'] == "enable" || $mybb->input['action'] == "disable")
 492  {
 493      if(!verify_post_check($mybb->input['my_post_key']))
 494      {
 495          flash_message($lang->invalid_post_verify_key2, 'error');
 496          admin_redirect("index.php?module=tools-tasks");
 497      }
 498      
 499      if($mybb->input['action'] == "enable")
 500      {
 501          $plugins->run_hooks("admin_tools_tasks_enable");
 502      }
 503      else
 504      {
 505          $plugins->run_hooks("admin_tools_tasks_disable");
 506      }
 507      
 508      $query = $db->simple_select("tasks", "*", "tid='".intval($mybb->input['tid'])."'");
 509      $task = $db->fetch_array($query);
 510  
 511      // Does the task not exist?
 512      if(!$task['tid'])
 513      {
 514          flash_message($lang->error_invalid_task, 'error');
 515          admin_redirect("index.php?module=tools-tasks");
 516      }
 517  
 518      if($mybb->input['action'] == "enable")
 519      {    
 520          if($task['file'] == "backupdb" || $task['file'] == "checktables")
 521          {
 522              // User clicked no
 523              if($mybb->input['no'])
 524              {
 525                  admin_redirect("index.php?module=tools-tasks");
 526              }
 527          
 528              if($mybb->request_method == "post")
 529              {
 530                  $nextrun = fetch_next_run($task);
 531                  $db->update_query("tasks", array("nextrun" => $nextrun, "enabled" => 1), "tid='{$task['tid']}'");
 532                  $cache->update_tasks();
 533                  
 534                  $plugins->run_hooks("admin_tools_tasks_enable_commit");
 535                  
 536                  // Log admin action
 537                  log_admin_action($task['tid'], $task['title'], $mybb->input['action']);
 538                  
 539                  flash_message($lang->success_task_enabled, 'success');
 540                  admin_redirect("index.php?module=tools-tasks");
 541              }
 542              else
 543              {
 544                  $page->output_confirm_action("index.php?module=tools-tasks&amp;action=enable&amp;tid={$task['tid']}", $lang->confirm_task_enable);
 545              }
 546          }
 547          else
 548          {
 549              $nextrun = fetch_next_run($task);
 550              $db->update_query("tasks", array("nextrun" => $nextrun, "enabled" => 1), "tid='{$task['tid']}'");
 551              $cache->update_tasks();
 552              
 553              $plugins->run_hooks("admin_tools_tasks_enable_commit");
 554              
 555              // Log admin action
 556              log_admin_action($task['tid'], $task['title'], $mybb->input['action']);
 557              
 558              flash_message($lang->success_task_enabled, 'success');
 559              admin_redirect("index.php?module=tools-tasks");
 560          }
 561      }
 562      else
 563      {
 564          $db->update_query("tasks", array("enabled" => 0), "tid='{$task['tid']}'");
 565          $cache->update_tasks();
 566          
 567          $plugins->run_hooks("admin_tools_tasks_disable_commit");
 568          
 569          // Log admin action
 570          log_admin_action($task['tid'], $task['title'], $mybb->input['action']);
 571          
 572          flash_message($lang->success_task_disabled, 'success');
 573          admin_redirect("index.php?module=tools-tasks");
 574      }
 575  }
 576  
 577  if($mybb->input['action'] == "run")
 578  {
 579      if(!verify_post_check($mybb->input['my_post_key']))
 580      {
 581          flash_message($lang->invalid_post_verify_key2, 'error');
 582          admin_redirect("index.php?module=tools-tasks");
 583      }
 584      
 585      ignore_user_abort(true);
 586      @set_time_limit(0);
 587      $plugins->run_hooks("admin_tools_tasks_run");
 588      
 589      $query = $db->simple_select("tasks", "*", "tid='".intval($mybb->input['tid'])."'");
 590      $task = $db->fetch_array($query);
 591  
 592      // Does the task not exist?
 593      if(!$task['tid'])
 594      {
 595          flash_message($lang->error_invalid_task, 'error');
 596          admin_redirect("index.php?module=tools-tasks");
 597      }
 598      
 599      run_task($task['tid']);
 600  
 601      $plugins->run_hooks("admin_tools_tasks_run_commit");
 602  
 603      // Log admin action
 604      log_admin_action($task['tid'], $task['title']);
 605  
 606      flash_message($lang->success_task_run, 'success');
 607      admin_redirect("index.php?module=tools-tasks");
 608  }
 609  
 610  if($mybb->input['action'] == "logs")
 611  {
 612      $plugins->run_hooks("admin_tools_tasks_logs");
 613      
 614      $page->output_header($lang->task_logs);
 615  
 616      $sub_tabs['scheduled_tasks'] = array(
 617          'title' => $lang->scheduled_tasks,
 618          'link' => "index.php?module=tools-tasks"
 619      );
 620  
 621      $sub_tabs['add_task'] = array(
 622          'title' => $lang->add_new_task,
 623          'link' => "index.php?module=tools-tasks&amp;action=add"
 624      );
 625      
 626      $sub_tabs['task_logs'] = array(
 627          'title' => $lang->view_task_logs,
 628          'link' => "index.php?module=tools-tasks&amp;action=logs",
 629          'description' => $lang->view_task_logs_desc
 630      );
 631  
 632      $page->output_nav_tabs($sub_tabs, 'task_logs');
 633  
 634      $table = new Table;
 635      $table->construct_header($lang->task);
 636      $table->construct_header($lang->date, array("class" => "align_center", "width" => 200));
 637      $table->construct_header($lang->data, array("width" => "60%"));
 638  
 639      $query = $db->simple_select("tasklog", "COUNT(*) AS log_count");
 640      $log_count = $db->fetch_field($query, "log_count");
 641  
 642      $per_page = 50;
 643  
 644      if($mybb->input['page'] > 0)
 645      {
 646          $current_page = intval($mybb->input['page']);
 647          $start = ($current_page-1)*$per_page;
 648          $pages = $log_count / $per_page;
 649          $pages = ceil($pages);
 650          if($current_page > $pages)
 651          {
 652              $start = 0;
 653              $current_page = 1;
 654          }
 655      }
 656      else
 657      {
 658          $start = 0;
 659          $current_page = 1;
 660      }
 661  
 662      $pagination = draw_admin_pagination($current_page, $per_page, $log_count, "index.php?module=tools-tasks&amp;action=logs&amp;page={page}");
 663  
 664      $query = $db->query("
 665          SELECT l.*, t.title
 666          FROM ".TABLE_PREFIX."tasklog l
 667          LEFT JOIN ".TABLE_PREFIX."tasks t ON (t.tid=l.tid)
 668          ORDER BY l.dateline DESC
 669          LIMIT {$start}, {$per_page}
 670      ");
 671      while($log_entry = $db->fetch_array($query))
 672      {
 673          $log_entry['title'] = htmlspecialchars_uni($log_entry['title']);
 674          $log_entry['data'] = htmlspecialchars_uni($log_entry['data']);
 675          $date = my_date($mybb->settings['dateformat'], $log_entry['dateline']).", ".my_date($mybb->settings['timeformat'], $log_entry['dateline']);
 676          $table->construct_cell("<a href=\"index.php?module=tools-tasks&amp;action=edit&amp;tid={$log_entry['tid']}\">{$log_entry['title']}</a>");
 677          $table->construct_cell($date, array("class" => "align_center"));
 678          $table->construct_cell($log_entry['data']);
 679          $table->construct_row();
 680      }
 681  
 682      if($table->num_rows() == 0)
 683      {
 684          $table->construct_cell($lang->no_task_logs, array("colspan" => "3"));
 685          $table->construct_row();
 686      }
 687      $table->output($lang->task_logs);
 688      echo $pagination;
 689  
 690      $page->output_footer();
 691  }
 692  
 693  if(!$mybb->input['action'])
 694  {
 695      $plugins->run_hooks("admin_tools_tasks_start");
 696      
 697      $page->output_header($lang->task_manager);
 698  
 699      $sub_tabs['scheduled_tasks'] = array(
 700          'title' => $lang->scheduled_tasks,
 701          'link' => "index.php?module=tools-tasks",
 702          'description' => $lang->scheduled_tasks_desc
 703      );
 704  
 705      $sub_tabs['add_task'] = array(
 706          'title' => $lang->add_new_task,
 707          'link' => "index.php?module=tools-tasks&amp;action=add"
 708      );
 709  
 710      $sub_tabs['task_logs'] = array(
 711          'title' => $lang->view_task_logs,
 712          'link' => "index.php?module=tools-tasks&amp;action=logs"
 713      );
 714  
 715      $page->output_nav_tabs($sub_tabs, 'scheduled_tasks');
 716  
 717      $table = new Table;
 718      $table->construct_header($lang->task);
 719      $table->construct_header($lang->next_run, array("class" => "align_center", "width" => 200));
 720      $table->construct_header($lang->controls, array("class" => "align_center", "width" => 150));
 721  
 722      $query = $db->simple_select("tasks", "*", "", array("order_by" => "title", "order_dir" => "asc"));
 723      while($task = $db->fetch_array($query))
 724      {
 725          $task['title'] = htmlspecialchars_uni($task['title']);
 726          $task['description'] = htmlspecialchars_uni($task['description']);
 727          $next_run = date($mybb->settings['dateformat'], $task['nextrun']).", ".date($mybb->settings['timeformat'], $task['nextrun']);
 728          if($task['enabled'] == 1)
 729          {
 730              $icon = "<img src=\"styles/{$page->style}/images/icons/bullet_on.gif\" alt=\"({$lang->alt_enabled})\" title=\"{$lang->alt_enabled}\"  style=\"vertical-align: middle;\" /> ";
 731          }
 732          else
 733          {
 734              $icon = "<img src=\"styles/{$page->style}/images/icons/bullet_off.gif\" alt=\"({$lang->alt_disabled})\" title=\"{$lang->alt_disabled}\"  style=\"vertical-align: middle;\" /> ";
 735          }
 736          $table->construct_cell("<div class=\"float_right\"><a href=\"index.php?module=tools-tasks&amp;action=run&amp;tid={$task['tid']}&amp;my_post_key={$mybb->post_code}\"><img src=\"styles/{$page->style}/images/icons/run_task.gif\" title=\"{$lang->run_task_now}\" alt=\"{$lang->run_task}\" /></a></div><div>{$icon}<strong><a href=\"index.php?module=tools-tasks&amp;action=edit&amp;tid={$task['tid']}\">{$task['title']}</a></strong><br /><small>{$task['description']}</small></div>");
 737          $table->construct_cell($next_run, array("class" => "align_center"));
 738  
 739          $popup = new PopupMenu("task_{$task['tid']}", $lang->options);
 740          $popup->add_item($lang->edit_task, "index.php?module=tools-tasks&amp;action=edit&amp;tid={$task['tid']}");
 741          if($task['enabled'] == 1)
 742          {
 743              $popup->add_item($lang->disable_task, "index.php?module=tools-tasks&amp;action=disable&amp;tid={$task['tid']}&amp;my_post_key={$mybb->post_code}");
 744          }
 745          else
 746          {
 747              $popup->add_item($lang->enable_task, "index.php?module=tools-tasks&amp;action=enable&amp;tid={$task['tid']}&amp;my_post_key={$mybb->post_code}");
 748          }
 749          $popup->add_item($lang->delete_task, "index.php?module=tools-tasks&amp;action=delete&amp;tid={$task['tid']}&amp;my_post_key={$mybb->post_code}", "return AdminCP.deleteConfirmation(this, '{$lang->confirm_task_deletion}')");
 750          $table->construct_cell($popup->fetch(), array("class" => "align_center"));
 751          $table->construct_row();
 752      }
 753      $table->output($lang->scheduled_tasks);
 754  
 755      $page->output_footer();
 756  }
 757  ?>


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1