[ Index ]

PHP Cross Reference of MyBB 1.8.38

title

Body

[close]

/admin/modules/user/ -> group_promotions.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  $page->add_breadcrumb_item($lang->user_group_promotions, "index.php?module=user-group_promotions");
  18  
  19  $sub_tabs['usergroup_promotions'] = array(
  20      'title' => $lang->user_group_promotions,
  21      'link' => "index.php?module=user-group_promotions",
  22      'description' => $lang->user_group_promotions_desc
  23  );
  24  
  25  $sub_tabs['add_promotion'] = array(
  26      'title' => $lang->add_new_promotion,
  27      'link' => "index.php?module=user-group_promotions&amp;action=add",
  28      'description' => $lang->add_new_promotion_desc
  29  );
  30  
  31  $sub_tabs['promotion_logs'] = array(
  32      'title' => $lang->view_promotion_logs,
  33      'link' => "index.php?module=user-group_promotions&amp;action=logs",
  34      'description' => $lang->view_promotion_logs_desc
  35  );
  36  
  37  $plugins->run_hooks("admin_user_group_promotions_begin");
  38  
  39  if($mybb->input['action'] == "disable")
  40  {
  41      if($mybb->get_input('no'))
  42      {
  43          admin_redirect("index.php?module=user-group_promotions");
  44      }
  45  
  46      if(!trim($mybb->input['pid']))
  47      {
  48          flash_message($lang->error_no_promo_id, 'error');
  49          admin_redirect("index.php?module=user-group_promotions");
  50      }
  51  
  52      $query = $db->simple_select("promotions", "*", "pid='".$mybb->get_input('pid', MyBB::INPUT_INT)."'");
  53      $promotion = $db->fetch_array($query);
  54  
  55      if(!$promotion)
  56      {
  57          flash_message($lang->error_invalid_promo_id, 'error');
  58          admin_redirect("index.php?module=user-group_promotions");
  59      }
  60  
  61      $plugins->run_hooks("admin_user_group_promotions_disable");
  62  
  63      if($mybb->request_method == "post")
  64      {
  65          $update_promotion = array(
  66              "enabled" => 0
  67          );
  68  
  69          $plugins->run_hooks("admin_user_group_promotions_disable_commit");
  70  
  71          $db->update_query("promotions", $update_promotion, "pid = '{$promotion['pid']}'");
  72  
  73          // Log admin action
  74          log_admin_action($promotion['pid'], $promotion['title']);
  75  
  76          flash_message($lang->success_promo_disabled, 'success');
  77          admin_redirect("index.php?module=user-group_promotions");
  78      }
  79      else
  80      {
  81          $page->output_confirm_action("index.php?module=user-group_promotions&amp;action=disable&amp;pid={$promotion['pid']}", $lang->confirm_promo_disable);
  82      }
  83  }
  84  
  85  if($mybb->input['action'] == "delete")
  86  {
  87      if($mybb->get_input('no'))
  88      {
  89          admin_redirect("index.php?module=user-group_promotions");
  90      }
  91  
  92      if(!trim($mybb->input['pid']))
  93      {
  94          flash_message($lang->error_no_promo_id, 'error');
  95          admin_redirect("index.php?module=user-group_promotions");
  96      }
  97  
  98      $query = $db->simple_select("promotions", "*", "pid='".$mybb->get_input('pid', MyBB::INPUT_INT)."'");
  99      $promotion = $db->fetch_array($query);
 100  
 101      if(!$promotion)
 102      {
 103          flash_message($lang->error_invalid_promo_id, 'error');
 104          admin_redirect("index.php?module=user-group_promotions");
 105      }
 106  
 107      $plugins->run_hooks("admin_user_group_promotions_delete");
 108  
 109      if($mybb->request_method == "post")
 110      {
 111          $db->delete_query("promotions", "pid = '{$promotion['pid']}'");
 112  
 113          $plugins->run_hooks("admin_user_group_promotions_delete_commit");
 114  
 115          // Log admin action
 116          log_admin_action($promotion['pid'], $promotion['title']);
 117  
 118          flash_message($lang->success_promo_deleted, 'success');
 119          admin_redirect("index.php?module=user-group_promotions");
 120      }
 121      else
 122      {
 123          $page->output_confirm_action("index.php?module=user-group_promotions&amp;action=delete&amp;pid={$mybb->input['pid']}", $lang->confirm_promo_deletion);
 124      }
 125  }
 126  
 127  if($mybb->input['action'] == "enable")
 128  {
 129      if(!verify_post_check($mybb->get_input('my_post_key')))
 130      {
 131          flash_message($lang->invalid_post_verify_key2, 'error');
 132          admin_redirect("index.php?module=user-group_promotions");
 133      }
 134  
 135      if(!trim($mybb->input['pid']))
 136      {
 137          flash_message($lang->error_no_promo_id, 'error');
 138          admin_redirect("index.php?module=user-group_promotions");
 139      }
 140  
 141      $query = $db->simple_select("promotions", "*", "pid='".$mybb->get_input('pid', MyBB::INPUT_INT)."'");
 142      $promotion = $db->fetch_array($query);
 143  
 144      if(!$promotion)
 145      {
 146          flash_message($lang->error_invalid_promo_id, 'error');
 147          admin_redirect("index.php?module=user-group_promotions");
 148      }
 149  
 150      $plugins->run_hooks("admin_user_group_promotions_enable");
 151  
 152      $update_promotion = array(
 153          "enabled" => 1
 154      );
 155  
 156      $plugins->run_hooks("admin_user_group_promotions_enable_commit");
 157  
 158      $db->update_query("promotions", $update_promotion, "pid = '{$promotion['pid']}'");
 159  
 160      // Log admin action
 161      log_admin_action($promotion['pid'], $promotion['title']);
 162  
 163      flash_message($lang->success_promo_enabled, 'success');
 164      admin_redirect("index.php?module=user-group_promotions");
 165  }
 166  
 167  if($mybb->input['action'] == "edit")
 168  {
 169      if(!trim($mybb->input['pid']))
 170      {
 171          flash_message($lang->error_no_promo_id, 'error');
 172          admin_redirect("index.php?module=user-group_promotions");
 173      }
 174  
 175      $query = $db->simple_select("promotions", "*", "pid='".$mybb->get_input('pid', MyBB::INPUT_INT)."'");
 176      $promotion = $db->fetch_array($query);
 177  
 178      if(!$promotion)
 179      {
 180          flash_message($lang->error_invalid_promo_id, 'error');
 181          admin_redirect("index.php?module=user-group_promotions");
 182      }
 183  
 184      $plugins->run_hooks("admin_user_group_promotions_edit");
 185  
 186      if($mybb->request_method == "post")
 187      {
 188          if(!trim($mybb->input['title']))
 189          {
 190              $errors[] = $lang->error_no_title;
 191          }
 192  
 193          if(!trim($mybb->input['description']))
 194          {
 195              $errors[] = $lang->error_no_desc;
 196          }
 197  
 198          if(empty($mybb->input['requirements']))
 199          {
 200              $errors[] = $lang->error_no_requirements;
 201          }
 202  
 203          if(empty($mybb->input['originalusergroup']))
 204          {
 205              $errors[] = $lang->error_no_orig_usergroup;
 206          }
 207  
 208          if(!trim($mybb->input['newusergroup']))
 209          {
 210              $errors[] = $lang->error_no_new_usergroup;
 211          }
 212  
 213          if(!trim($mybb->input['usergroupchangetype']))
 214          {
 215              $errors[] = $lang->error_no_usergroup_change_type;
 216          }
 217  
 218          if(!$errors)
 219          {
 220              if(in_array('*', $mybb->input['originalusergroup']))
 221              {
 222                  $mybb->input['originalusergroup'] = '*';
 223              }
 224              else
 225              {
 226                  $mybb->input['originalusergroup'] = implode(',', array_map('intval', $mybb->input['originalusergroup']));
 227              }
 228  
 229              $allowed_operators = array('>', '>=', '=', '<=', '<');
 230              $operator_fields = array('posttype', 'threadtype', 'reputationtype', 'referralstype', 'warningstype');
 231  
 232              foreach($operator_fields as $field)
 233              {
 234                  if(!in_array($mybb->get_input($field), $allowed_operators))
 235                  {
 236                      $mybb->input[$field] = '=';
 237                  }
 238              }
 239  
 240              $allowed_times = array('hours', 'days', 'weeks', 'months', 'years');
 241              $time_fields = array('timeregisteredtype', 'timeonlinetype');
 242  
 243              foreach($time_fields as $field)
 244              {
 245                  if(!in_array($mybb->get_input($field), $allowed_times))
 246                  {
 247                      $mybb->input[$field] = 'days';
 248                  }
 249              }
 250  
 251              $update_promotion = array(
 252                  "title" => $db->escape_string($mybb->input['title']),
 253                  "description" => $db->escape_string($mybb->input['description']),
 254                  "posts" => $mybb->get_input('postcount', MyBB::INPUT_INT),
 255                  "posttype" => $db->escape_string($mybb->input['posttype']),
 256                  "threads" => $mybb->get_input('threadcount', MyBB::INPUT_INT),
 257                  "threadtype" => $db->escape_string($mybb->input['threadtype']),
 258                  "registered" => $mybb->get_input('timeregistered', MyBB::INPUT_INT),
 259                  "registeredtype" => $db->escape_string($mybb->input['timeregisteredtype']),
 260                  "online" => $mybb->get_input('timeonline', MyBB::INPUT_INT),
 261                  "onlinetype" => $db->escape_string($mybb->input['timeonlinetype']),
 262                  "reputations" => $mybb->get_input('reputationcount', MyBB::INPUT_INT),
 263                  "reputationtype" => $db->escape_string($mybb->input['reputationtype']),
 264                  "referrals" => $mybb->get_input('referrals', MyBB::INPUT_INT),
 265                  "referralstype" => $db->escape_string($mybb->input['referralstype']),
 266                  "warnings" => $mybb->get_input('warnings', MyBB::INPUT_INT),
 267                  "warningstype" => $db->escape_string($mybb->input['warningstype']),
 268                  "requirements" => $db->escape_string(implode(",", $mybb->input['requirements'])),
 269                  "originalusergroup" => $db->escape_string($mybb->input['originalusergroup']),
 270                  "newusergroup" => $mybb->get_input('newusergroup', MyBB::INPUT_INT),
 271                  "usergrouptype" => $db->escape_string($mybb->input['usergroupchangetype']),
 272                  "enabled" => $mybb->get_input('enabled', MyBB::INPUT_INT),
 273                  "logging" => $mybb->get_input('logging', MyBB::INPUT_INT)
 274              );
 275  
 276              $plugins->run_hooks("admin_user_group_promotions_edit_commit");
 277  
 278              $db->update_query("promotions", $update_promotion, "pid = '{$promotion['pid']}'");
 279  
 280              // Log admin action
 281              log_admin_action($promotion['pid'], $mybb->input['title']);
 282  
 283              flash_message($lang->success_promo_updated, 'success');
 284              admin_redirect("index.php?module=user-group_promotions");
 285          }
 286      }
 287  
 288      $page->add_breadcrumb_item($lang->edit_promotion);
 289      $page->output_header($lang->user_group_promotions." - ".$lang->edit_promotion);
 290  
 291      $sub_tabs = array();
 292      $sub_tabs['edit_promotion'] = array(
 293          'title' => $lang->edit_promotion,
 294          'link' => "index.php?module=user-group_promotions&amp;action=edit",
 295          'description' => $lang->edit_promotion_desc
 296      );
 297  
 298      $page->output_nav_tabs($sub_tabs, 'edit_promotion');
 299      $form = new Form("index.php?module=user-group_promotions&amp;action=edit", "post", "edit");
 300      echo $form->generate_hidden_field("pid", $promotion['pid']);
 301      if($errors)
 302      {
 303          $page->output_inline_error($errors);
 304      }
 305      else
 306      {
 307          $mybb->input['title'] = $promotion['title'];
 308          $mybb->input['description'] = $promotion['description'];
 309          $mybb->input['requirements'] = explode(',', $promotion['requirements']);
 310          $mybb->input['reputationcount'] = $promotion['reputations'];
 311          $mybb->input['reputationtype'] = $promotion['reputationtype'];
 312          $mybb->input['postcount'] = $promotion['posts'];
 313          $mybb->input['posttype'] = $promotion['posttype'];
 314          $mybb->input['threadcount'] = $promotion['threads'];
 315          $mybb->input['threadtype'] = $promotion['threadtype'];
 316          $mybb->input['referrals'] = $promotion['referrals'];
 317          $mybb->input['referralstype'] = $promotion['referralstype'];
 318          $mybb->input['warnings'] = $promotion['warnings'];
 319          $mybb->input['warningstype'] = $promotion['warningstype'];
 320          $mybb->input['timeregistered'] = $promotion['registered'];
 321          $mybb->input['timeregisteredtype'] = $promotion['registeredtype'];
 322          $mybb->input['timeonline'] = $promotion['online'];
 323          $mybb->input['timeonlinetype'] = $promotion['onlinetype'];
 324          $mybb->input['originalusergroup'] = explode(',', $promotion['originalusergroup']);
 325          $mybb->input['usergroupchangetype'] = $promotion['usergrouptype'];
 326          $mybb->input['newusergroup'] = $promotion['newusergroup'];
 327          $mybb->input['enabled'] = $promotion['enabled'];
 328          $mybb->input['logging'] = $promotion['logging'];
 329      }
 330  
 331      $form_container = new FormContainer($lang->edit_promotion);
 332      $form_container->output_row($lang->title." <em>*</em>", "", $form->generate_text_box('title', $mybb->input['title'], array('id' => 'title')), 'title');
 333      $form_container->output_row($lang->short_desc." <em>*</em>", "", $form->generate_text_box('description', $mybb->input['description'], array('id' => 'description')), 'description');
 334  
 335      $options = array(
 336          "postcount" => $lang->post_count,
 337          "threadcount" => $lang->thread_count,
 338          "reputation" => $lang->reputation,
 339          "referrals" => $lang->referrals,
 340          "warnings" => $lang->warning_points,
 341          "timeregistered" => $lang->time_registered,
 342          "timeonline" => $lang->time_online
 343      );
 344  
 345      $form_container->output_row($lang->promo_requirements." <em>*</em>", $lang->promo_requirements_desc, $form->generate_select_box('requirements[]', $options, $mybb->input['requirements'], array('id' => 'requirements', 'multiple' => true, 'size' => 5)), 'requirements');
 346  
 347      $options_type = array(
 348          ">" => $lang->greater_than,
 349          ">=" => $lang->greater_than_or_equal_to,
 350          "=" => $lang->equal_to,
 351          "<=" => $lang->less_than_or_equal_to,
 352          "<" => $lang->less_than
 353      );
 354  
 355      $form_container->output_row($lang->post_count, $lang->post_count_desc, $form->generate_numeric_field('postcount', $mybb->input['postcount'], array('id' => 'postcount', 'min' => 0))." ".$form->generate_select_box("posttype", $options_type, $mybb->input['posttype'], array('id' => 'posttype')), 'postcount');
 356  
 357      $form_container->output_row($lang->thread_count, $lang->thread_count_desc, $form->generate_numeric_field('threadcount', $mybb->input['threadcount'], array('id' => 'threadcount', 'min' => 0))." ".$form->generate_select_box("threadtype", $options_type, $mybb->input['threadtype'], array('id' => 'threadtype')), 'threadcount');
 358  
 359      $form_container->output_row($lang->reputation_count, $lang->reputation_count_desc, $form->generate_numeric_field('reputationcount', $mybb->input['reputationcount'], array('id' => 'reputationcount', 'min' => 0))." ".$form->generate_select_box("reputationtype", $options_type, $mybb->input['reputationtype'], array('id' => 'reputationtype')), 'reputationcount');
 360  
 361      $options = array(
 362          "hours" => $lang->hours,
 363          "days" => $lang->days,
 364          "weeks" => $lang->weeks,
 365          "months" => $lang->months,
 366          "years" => $lang->years
 367      );
 368  
 369      $form_container->output_row($lang->referral_count, $lang->referral_count_desc, $form->generate_numeric_field('referrals', $mybb->input['referrals'], array('id' => 'referrals', 'min' => 0))." ".$form->generate_select_box("referralstype", $options_type, $mybb->input['referralstype'], array('id' => 'referralstype')), 'referrals');
 370  
 371      $form_container->output_row($lang->warning_points, $lang->warning_points_desc, $form->generate_numeric_field('warnings', $mybb->input['warnings'], array('id' => 'warnings', 'min' => 0))." ".$form->generate_select_box("warningstype", $options_type, $mybb->input['warningstype'], array('id' => 'warningstype')), 'warnings');
 372  
 373      $form_container->output_row($lang->time_registered, $lang->time_registered_desc, $form->generate_numeric_field('timeregistered', $mybb->input['timeregistered'], array('id' => 'timeregistered', 'min' => 0))." ".$form->generate_select_box("timeregisteredtype", $options, $mybb->input['timeregisteredtype'], array('id' => 'timeregisteredtype')), 'timeregistered');
 374  
 375      $form_container->output_row($lang->time_online, $lang->time_online_desc, $form->generate_numeric_field('timeonline', $mybb->input['timeonline'], array('id' => 'timeonline', 'min' => 0))." ".$form->generate_select_box("timeonlinetype", $options, $mybb->input['timeonlinetype'], array('id' => 'timeonlinetype')), 'timeonline');
 376  
 377      $options = array();
 378  
 379      $query = $db->simple_select("usergroups", "gid, title", "gid != '1'", array('order_by' => 'title'));
 380      while($usergroup = $db->fetch_array($query))
 381      {
 382          $options[(int)$usergroup['gid']] = htmlspecialchars_uni($usergroup['title']);
 383      }
 384  
 385      $form_container->output_row($lang->orig_user_group." <em>*</em>", $lang->orig_user_group_desc, $form->generate_select_box('originalusergroup[]', $options, $mybb->input['originalusergroup'], array('id' => 'originalusergroup', 'multiple' => true, 'size' => 5)), 'originalusergroup');
 386  
 387      unset($options['*']); // Remove the all usergroups option
 388      $form_container->output_row($lang->new_user_group." <em>*</em>", $lang->new_user_group_desc, $form->generate_select_box('newusergroup', $options, $mybb->input['newusergroup'], array('id' => 'newusergroup')), 'newusergroup');
 389  
 390      $options = array(
 391          'primary' => $lang->primary_user_group,
 392          'secondary' => $lang->secondary_user_group
 393      );
 394  
 395      $form_container->output_row($lang->user_group_change_type." <em>*</em>", $lang->user_group_change_type_desc, $form->generate_select_box('usergroupchangetype', $options, $mybb->input['usergroupchangetype'], array('id' => 'usergroupchangetype')), 'usergroupchangetype');
 396  
 397      $form_container->output_row($lang->enabled." <em>*</em>", "", $form->generate_yes_no_radio("enabled", $mybb->input['enabled'], true));
 398  
 399      $form_container->output_row($lang->enable_logging." <em>*</em>", "", $form->generate_yes_no_radio("logging", $mybb->input['logging'], true));
 400      $form_container->end();
 401  
 402      $buttons[] = $form->generate_submit_button($lang->update_promotion);
 403  
 404      $form->output_submit_wrapper($buttons);
 405      $form->end();
 406  
 407      $page->output_footer();
 408  }
 409  
 410  if($mybb->input['action'] == "add")
 411  {
 412      $plugins->run_hooks("admin_user_group_promotions_add");
 413  
 414      if($mybb->request_method == "post")
 415      {
 416          if(!trim($mybb->input['title']))
 417          {
 418              $errors[] = $lang->error_no_title;
 419          }
 420  
 421          if(!trim($mybb->input['description']))
 422          {
 423              $errors[] = $lang->error_no_desc;
 424          }
 425  
 426          if(empty($mybb->input['requirements']))
 427          {
 428              $errors[] = $lang->error_no_requirements;
 429          }
 430  
 431          if(empty($mybb->input['originalusergroup']))
 432          {
 433              $errors[] = $lang->error_no_orig_usergroup;
 434          }
 435  
 436          if(!trim($mybb->input['newusergroup']))
 437          {
 438              $errors[] = $lang->error_no_new_usergroup;
 439          }
 440  
 441          if(!trim($mybb->input['usergroupchangetype']))
 442          {
 443              $errors[] = $lang->error_no_usergroup_change_type;
 444          }
 445  
 446          if(!$errors)
 447          {
 448              if(in_array('*', $mybb->input['originalusergroup']))
 449              {
 450                  $mybb->input['originalusergroup'] = '*';
 451              }
 452              else
 453              {
 454                  $mybb->input['originalusergroup'] = implode(',', array_map('intval', $mybb->input['originalusergroup']));
 455              }
 456  
 457              $allowed_operators = array('>', '>=', '=', '<=', '<');
 458              $operator_fields = array('posttype', 'threadtype', 'reputationtype', 'referralstype', 'warningstype');
 459  
 460              foreach($operator_fields as $field)
 461              {
 462                  if(!in_array($mybb->get_input($field), $allowed_operators))
 463                  {
 464                      $mybb->input[$field] = '=';
 465                  }
 466              }
 467  
 468              $allowed_times = array('hours', 'days', 'weeks', 'months', 'years');
 469              $time_fields = array('timeregisteredtype', 'timeonlinetype');
 470  
 471              foreach($time_fields as $field)
 472              {
 473                  if(!in_array($mybb->get_input($field), $allowed_times))
 474                  {
 475                      $mybb->input[$field] = 'days';
 476                  }
 477              }
 478  
 479              $new_promotion = array(
 480                  "title" => $db->escape_string($mybb->input['title']),
 481                  "description" => $db->escape_string($mybb->input['description']),
 482                  "posts" => $mybb->get_input('postcount', MyBB::INPUT_INT),
 483                  "posttype" => $db->escape_string($mybb->input['posttype']),
 484                  "threads" => $mybb->get_input('threadcount', MyBB::INPUT_INT),
 485                  "threadtype" => $db->escape_string($mybb->input['threadtype']),
 486                  "registered" => $mybb->get_input('timeregistered', MyBB::INPUT_INT),
 487                  "registeredtype" => $db->escape_string($mybb->input['timeregisteredtype']),
 488                  "online" => $mybb->get_input('timeonline', MyBB::INPUT_INT),
 489                  "onlinetype" => $db->escape_string($mybb->input['timeonlinetype']),
 490                  "reputations" => $mybb->get_input('reputationcount', MyBB::INPUT_INT),
 491                  "reputationtype" => $db->escape_string($mybb->input['reputationtype']),
 492                  "referrals" => $mybb->get_input('referrals', MyBB::INPUT_INT),
 493                  "referralstype" => $db->escape_string($mybb->input['referralstype']),
 494                  "warnings" => $mybb->get_input('warnings', MyBB::INPUT_INT),
 495                  "warningstype" => $db->escape_string($mybb->input['warningstype']),
 496                  "requirements" => $db->escape_string(implode(",", $mybb->input['requirements'])),
 497                  "originalusergroup" => $db->escape_string($mybb->input['originalusergroup']),
 498                  "usergrouptype" => $db->escape_string($mybb->input['usergroupchangetype']),
 499                  "newusergroup" => $mybb->get_input('newusergroup', MyBB::INPUT_INT),
 500                  "enabled" => $mybb->get_input('enabled', MyBB::INPUT_INT),
 501                  "logging" => $mybb->get_input('logging', MyBB::INPUT_INT)
 502              );
 503  
 504              $pid = $db->insert_query("promotions", $new_promotion);
 505  
 506              $plugins->run_hooks("admin_user_group_promotions_add_commit");
 507  
 508              // Log admin action
 509              log_admin_action($pid, $mybb->input['title']);
 510  
 511              flash_message($lang->success_promo_added, 'success');
 512              admin_redirect("index.php?module=user-group_promotions");
 513          }
 514      }
 515      $page->add_breadcrumb_item($lang->add_new_promotion);
 516      $page->output_header($lang->user_group_promotions." - ".$lang->add_new_promotion);
 517  
 518      $sub_tabs['usergroup_promotions'] = array(
 519          'title' => $lang->user_group_promotions,
 520          'link' => "index.php?module=user-group_promotions"
 521      );
 522  
 523      $sub_tabs['add_promotion'] = array(
 524          'title' => $lang->add_new_promotion,
 525          'link' => "index.php?module=user-group_promotions&amp;action=add",
 526          'description' => $lang->add_new_promotion_desc
 527      );
 528  
 529      $sub_tabs['promotion_logs'] = array(
 530          'title' => $lang->view_promotion_logs,
 531          'link' => "index.php?module=user-group_promotions&amp;action=logs"
 532      );
 533  
 534      $page->output_nav_tabs($sub_tabs, 'add_promotion');
 535      $form = new Form("index.php?module=user-group_promotions&amp;action=add", "post", "add");
 536      if($errors)
 537      {
 538          $page->output_inline_error($errors);
 539      }
 540      else
 541      {
 542          $mybb->input['reputationcount'] = '0';
 543          $mybb->input['referrals'] = '0';
 544          $mybb->input['warnings'] = '0';
 545          $mybb->input['postcount'] = '0';
 546          $mybb->input['threadcount'] = '0';
 547          $mybb->input['timeregistered'] = '0';
 548          $mybb->input['timeregisteredtype'] = 'days';
 549          $mybb->input['timeonline'] = '0';
 550          $mybb->input['timeonlinetype'] = 'days';
 551          $mybb->input['originalusergroup'] = '*';
 552          $mybb->input['newusergroup'] = '2';
 553          $mybb->input['enabled'] = '1';
 554          $mybb->input['logging'] = '1';
 555      }
 556      $form_container = new FormContainer($lang->add_new_promotion);
 557      $form_container->output_row($lang->title." <em>*</em>", "", $form->generate_text_box('title', $mybb->get_input('title'), array('id' => 'title')), 'title');
 558      $form_container->output_row($lang->short_desc." <em>*</em>", "", $form->generate_text_box('description', $mybb->get_input('description'), array('id' => 'description')), 'description');
 559  
 560      $options = array(
 561          "postcount" => $lang->post_count,
 562          "threadcount" => $lang->thread_count,
 563          "reputation" => $lang->reputation,
 564          "referrals" => $lang->referrals,
 565          "warnings" => $lang->warning_points,
 566          "timeregistered" => $lang->time_registered,
 567          "timeonline" => $lang->time_online
 568      );
 569  
 570      $form_container->output_row($lang->promo_requirements." <em>*</em>", $lang->promo_requirements_desc, $form->generate_select_box('requirements[]', $options, $mybb->get_input('requirements', MyBB::INPUT_ARRAY), array('id' => 'requirements', 'multiple' => true, 'size' => 5)), 'requirements');
 571  
 572      $options_type = array(
 573          ">" => $lang->greater_than,
 574          ">=" => $lang->greater_than_or_equal_to,
 575          "=" => $lang->equal_to,
 576          "<=" => $lang->less_than_or_equal_to,
 577          "<" => $lang->less_than
 578      );
 579  
 580      $form_container->output_row($lang->post_count, $lang->post_count_desc, $form->generate_numeric_field('postcount', $mybb->get_input('postcount'), array('id' => 'postcount', 'min' => 0))." ".$form->generate_select_box("posttype", $options_type, $mybb->get_input('posttype'), array('id' => 'posttype')), 'postcount');
 581  
 582      $form_container->output_row($lang->thread_count, $lang->thread_count_desc, $form->generate_numeric_field('threadcount', $mybb->get_input('threadcount'), array('id' => 'threadcount', 'min' => 0))." ".$form->generate_select_box("threadtype", $options_type, $mybb->get_input('threadtype'), array('id' => 'threadtype')), 'threadcount');
 583  
 584      $form_container->output_row($lang->reputation_count, $lang->reputation_count_desc, $form->generate_numeric_field('reputationcount', $mybb->get_input('reputationcount'), array('id' => 'reputationcount', 'min' => 0))." ".$form->generate_select_box("reputationtype", $options_type, $mybb->get_input('reputationtype'), array('id' => 'reputationtype')), 'reputationcount');
 585  
 586      $options = array(
 587          "hours" => $lang->hours,
 588          "days" => $lang->days,
 589          "weeks" => $lang->weeks,
 590          "months" => $lang->months,
 591          "years" => $lang->years
 592      );
 593  
 594      $form_container->output_row($lang->referral_count, $lang->referral_count_desc, $form->generate_numeric_field('referrals', $mybb->get_input('referrals'), array('id' => 'referrals', 'min' => 0))." ".$form->generate_select_box("referralstype", $options_type, $mybb->get_input('referralstype'), array('id' => 'referralstype')), 'referrals');
 595  
 596      $form_container->output_row($lang->warning_points, $lang->warning_points_desc, $form->generate_numeric_field('warnings', $mybb->get_input('warnings'), array('id' => 'warnings', 'min' => 0))." ".$form->generate_select_box("warningstype", $options_type, $mybb->get_input('warningstype'), array('id' => 'warningstype')), 'warnings');
 597  
 598      $form_container->output_row($lang->time_registered, $lang->time_registered_desc, $form->generate_numeric_field('timeregistered', $mybb->get_input('timeregistered'), array('id' => 'timeregistered', 'min' => 0))." ".$form->generate_select_box("timeregisteredtype", $options, $mybb->get_input('timeregisteredtype'), array('id' => 'timeregisteredtype')), 'timeregistered');
 599  
 600      $form_container->output_row($lang->time_online, $lang->time_online_desc, $form->generate_numeric_field('timeonline', $mybb->get_input('timeonline'), array('id' => 'timeonline', 'min' => 0))." ".$form->generate_select_box("timeonlinetype", $options, $mybb->get_input('timeonlinetype'), array('id' => 'timeonlinetype')), 'timeonline');
 601      $options = array();
 602  
 603      $query = $db->simple_select("usergroups", "gid, title", "gid != '1'", array('order_by' => 'title'));
 604      while($usergroup = $db->fetch_array($query))
 605      {
 606          $options[(int)$usergroup['gid']] = htmlspecialchars_uni($usergroup['title']);
 607      }
 608  
 609      $form_container->output_row($lang->orig_user_group." <em>*</em>", $lang->orig_user_group_desc, $form->generate_select_box('originalusergroup[]', $options, $mybb->get_input('originalusergroup', MyBB::INPUT_ARRAY), array('id' => 'originalusergroup', 'multiple' => true, 'size' => 5)), 'originalusergroup');
 610  
 611      unset($options['*']);
 612      $form_container->output_row($lang->new_user_group." <em>*</em>", $lang->new_user_group_desc, $form->generate_select_box('newusergroup', $options, $mybb->get_input('newusergroup'), array('id' => 'newusergroup')), 'newusergroup');
 613  
 614      $options = array(
 615          'primary' => $lang->primary_user_group,
 616          'secondary' => $lang->secondary_user_group
 617      );
 618  
 619      $form_container->output_row($lang->user_group_change_type." <em>*</em>", $lang->user_group_change_type_desc, $form->generate_select_box('usergroupchangetype', $options, $mybb->get_input('usergroupchangetype'), array('id' => 'usergroupchangetype')), 'usergroupchangetype');
 620  
 621      $form_container->output_row($lang->enabled." <em>*</em>", "", $form->generate_yes_no_radio("enabled", $mybb->get_input('enabled'), true));
 622  
 623      $form_container->output_row($lang->enable_logging." <em>*</em>", "", $form->generate_yes_no_radio("logging", $mybb->get_input('logging'), true));
 624      $form_container->end();
 625  
 626      $buttons[] = $form->generate_submit_button($lang->update_promotion);
 627  
 628      $form->output_submit_wrapper($buttons);
 629      $form->end();
 630  
 631      $page->output_footer();
 632  }
 633  
 634  if($mybb->input['action'] == "logs")
 635  {
 636      $plugins->run_hooks("admin_user_group_promotions_logs");
 637  
 638      $query = $db->simple_select("promotionlogs", "COUNT(plid) as promotionlogs");
 639      $total_rows = $db->fetch_field($query, "promotionlogs");
 640  
 641      if($mybb->get_input('page', MyBB::INPUT_INT) > 1)
 642      {
 643          $mybb->input['page'] = $mybb->get_input('page', MyBB::INPUT_INT);
 644          $start = ($mybb->input['page']*20)-20;
 645          $pages = ceil($total_rows / 20);
 646          if($mybb->input['page'] > $pages)
 647          {
 648              $mybb->input['page'] = 1;
 649              $start = 0;
 650          }
 651      }
 652      else
 653      {
 654          $mybb->input['page'] = 1;
 655          $start = 0;
 656      }
 657  
 658      $page->add_breadcrumb_item($lang->promotion_logs);
 659      $page->output_header($lang->user_group_promotions." - ".$lang->promotion_logs);
 660  
 661      $page->output_nav_tabs($sub_tabs, 'promotion_logs');
 662  
 663      $table = new Table;
 664      $table->construct_header($lang->promoted_user, array("class" => "align_center", "width" => '20%'));
 665      $table->construct_header($lang->user_group_change_type, array("class" => "align_center", "width" => '20%'));
 666      $table->construct_header($lang->orig_user_group, array("class" => "align_center", "width" => '20%'));
 667      $table->construct_header($lang->new_user_group, array("class" => "align_center", "width" => '20%'));
 668      $table->construct_header($lang->time_promoted, array("class" => "align_center", "width" => '20%'));
 669  
 670      $query = $db->query("
 671          SELECT pl.*,u.username
 672          FROM ".TABLE_PREFIX."promotionlogs pl
 673          LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=pl.uid)
 674          ORDER BY dateline DESC
 675          LIMIT {$start}, 20
 676      ");
 677      while($log = $db->fetch_array($query))
 678      {
 679          $log['username'] = "<a href=\"index.php?module=user-view&amp;action=edit&amp;uid={$log['uid']}\">".htmlspecialchars_uni($log['username'])."</a>";
 680  
 681          if($log['type'] == "secondary" || (!empty($log['oldusergroup']) && strstr(",", $log['oldusergroup'])))
 682          {
 683              $log['oldusergroup'] = "<i>".$lang->multiple_usergroups."</i>";
 684              $log['newusergroup'] = htmlspecialchars_uni($groupscache[$log['newusergroup']]['title']);
 685          }
 686          else
 687          {
 688              $log['oldusergroup'] = htmlspecialchars_uni($groupscache[$log['oldusergroup']]['title']);
 689              $log['newusergroup'] = htmlspecialchars_uni($groupscache[$log['newusergroup']]['title']);
 690          }
 691  
 692          if($log['type'] == "secondary")
 693          {
 694              $log['type'] = $lang->secondary;
 695          }
 696          else
 697          {
 698              $log['type'] = $lang->primary;
 699          }
 700  
 701          $log['dateline'] = my_date('relative', $log['dateline']);
 702          $table->construct_cell($log['username']);
 703          $table->construct_cell($log['type'], array('style' => 'text-align: center;'));
 704          $table->construct_cell($log['oldusergroup'], array('style' => 'text-align: center;'));
 705          $table->construct_cell($log['newusergroup'], array('style' => 'text-align: center;'));
 706          $table->construct_cell($log['dateline'], array('style' => 'text-align: center;'));
 707          $table->construct_row();
 708      }
 709  
 710      if($table->num_rows() == 0)
 711      {
 712          $table->construct_cell($lang->no_promotion_logs, array("colspan" => "5"));
 713          $table->construct_row();
 714      }
 715  
 716      $table->output($lang->promotion_logs);
 717  
 718      echo "<br />".draw_admin_pagination($mybb->input['page'], "20", $total_rows, "index.php?module=user-group_promotions&amp;action=logs&amp;page={page}");
 719  
 720      $page->output_footer();
 721  }
 722  
 723  if(!$mybb->input['action'])
 724  {
 725      $plugins->run_hooks("admin_user_group_promotions_start");
 726  
 727      $page->output_header($lang->promotion_manager);
 728  
 729      $page->output_nav_tabs($sub_tabs, 'usergroup_promotions');
 730  
 731      $table = new Table;
 732      $table->construct_header($lang->promotion);
 733      $table->construct_header($lang->controls, array("class" => "align_center", "width" => 150));
 734  
 735      $query = $db->simple_select("promotions", "*", "", array("order_by" => "title", "order_dir" => "asc"));
 736      while($promotion = $db->fetch_array($query))
 737      {
 738          $promotion['title'] = htmlspecialchars_uni($promotion['title']);
 739          $promotion['description'] = htmlspecialchars_uni($promotion['description']);
 740          if($promotion['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  
 749          $table->construct_cell("<div>{$icon}<strong><a href=\"index.php?module=user-group_promotions&amp;action=edit&amp;pid={$promotion['pid']}\">{$promotion['title']}</a></strong><br /><small>{$promotion['description']}</small></div>");
 750  
 751          $popup = new PopupMenu("promotion_{$promotion['pid']}", $lang->options);
 752          $popup->add_item($lang->edit_promotion, "index.php?module=user-group_promotions&amp;action=edit&amp;pid={$promotion['pid']}");
 753          if($promotion['enabled'] == 1)
 754          {
 755              $popup->add_item($lang->disable_promotion, "index.php?module=user-group_promotions&amp;action=disable&amp;pid={$promotion['pid']}&amp;my_post_key={$mybb->post_code}", "return AdminCP.deleteConfirmation(this, '{$lang->confirm_promo_disable}')");
 756          }
 757          else
 758          {
 759              $popup->add_item($lang->enable_promotion, "index.php?module=user-group_promotions&amp;action=enable&amp;pid={$promotion['pid']}&amp;my_post_key={$mybb->post_code}");
 760          }
 761          $popup->add_item($lang->delete_promotion, "index.php?module=user-group_promotions&amp;action=delete&amp;pid={$promotion['pid']}&amp;my_post_key={$mybb->post_code}", "return AdminCP.deleteConfirmation(this, '{$lang->confirm_promo_deletion}')");
 762          $table->construct_cell($popup->fetch(), array("class" => "align_center"));
 763          $table->construct_row();
 764      }
 765  
 766      if($table->num_rows() == 0)
 767      {
 768          $table->construct_cell($lang->no_promotions_set, array("colspan" => "2"));
 769          $table->construct_row();
 770      }
 771  
 772      $table->output($lang->user_group_promotions);
 773  
 774      $page->output_footer();
 775  }


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