[ Index ]

PHP Cross Reference of MyBB 1.8.38

title

Body

[close]

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

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


2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref