[ Index ]

PHP Cross Reference of MyBB 1.8.29

title

Body

[close]

/admin/modules/tools/ -> maillogs.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_email_log, "index.php?module=tools-maillogs");
  18  
  19  $plugins->run_hooks("admin_tools_maillogs_begin");
  20  
  21  if($mybb->input['action'] == "prune" && $mybb->request_method == "post")
  22  {
  23      $plugins->run_hooks("admin_tools_maillogs_prune");
  24  
  25      if($mybb->input['delete_all'])
  26      {
  27          $db->delete_query("maillogs");
  28          $num_deleted = $db->affected_rows();
  29  
  30          $plugins->run_hooks("admin_tools_maillogs_prune_delete_all_commit");
  31  
  32          // Log admin action
  33          log_admin_action($num_deleted);
  34  
  35          flash_message($lang->all_logs_deleted, 'success');
  36          admin_redirect("index.php?module=tools-maillogs");
  37      }
  38      else if(is_array($mybb->input['log']))
  39      {
  40          $log_ids = implode(",", array_map("intval", $mybb->input['log']));
  41          if($log_ids)
  42          {
  43              $db->delete_query("maillogs", "mid IN ({$log_ids})");
  44              $num_deleted = $db->affected_rows();
  45          }
  46  
  47          // Log admin action
  48          log_admin_action($num_deleted);
  49      }
  50  
  51      $plugins->run_hooks("admin_tools_maillogs_prune_commit");
  52  
  53      flash_message($lang->selected_logs_deleted, 'success');
  54      admin_redirect("index.php?module=tools-maillogs");
  55  }
  56  
  57  if($mybb->input['action'] == "view")
  58  {
  59      $query = $db->simple_select("maillogs", "*", "mid='".$mybb->get_input('mid', MyBB::INPUT_INT)."'");
  60      $log = $db->fetch_array($query);
  61  
  62      if(!$log['mid'])
  63      {
  64          exit;
  65      }
  66  
  67      $plugins->run_hooks("admin_tools_maillogs_view");
  68  
  69      $log['toemail'] = htmlspecialchars_uni($log['toemail']);
  70      $log['fromemail'] = htmlspecialchars_uni($log['fromemail']);
  71      $log['subject'] = htmlspecialchars_uni($log['subject']);
  72      $log['dateline'] = my_date('relative', $log['dateline']);
  73      if($mybb->settings['mail_logging'] == 1)
  74      {
  75          $log['message'] = $lang->na;
  76      }
  77      else
  78      {
  79          $log['message'] = nl2br(htmlspecialchars_uni($log['message']));
  80      }
  81  
  82      ?>
  83      <div class="modal">
  84      <div style="overflow-y: auto; max-height: 400px;">
  85  
  86      <?php
  87      $table = new Table();
  88  
  89      $table->construct_cell($lang->to.":");
  90      $table->construct_cell("<a href=\"mailto:{$log['toemail']}\">{$log['toemail']}</a>");
  91      $table->construct_row();
  92  
  93      $table->construct_cell($lang->from.":");
  94      $table->construct_cell("<a href=\"mailto:{$log['fromemail']}\">{$log['fromemail']}</a>");
  95      $table->construct_row();
  96  
  97      $table->construct_cell($lang->ip_address.":");
  98      $table->construct_cell(my_inet_ntop($db->unescape_binary($log['ipaddress'])));
  99      $table->construct_row();
 100  
 101      $table->construct_cell($lang->subject.":");
 102      $table->construct_cell($log['subject']);
 103      $table->construct_row();
 104  
 105      $table->construct_cell($lang->date.":");
 106      $table->construct_cell($log['dateline']);
 107      $table->construct_row();
 108  
 109      $table->construct_cell($log['message'], array("colspan" => 2));
 110      $table->construct_row();
 111  
 112      $table->output($lang->user_email_log_viewer);
 113  
 114      ?>
 115  </div>
 116  </div>
 117      <?php
 118  }
 119  
 120  if(!$mybb->input['action'])
 121  {
 122      $query = $db->simple_select("maillogs l", "COUNT(l.mid) as logs");
 123      $total_rows = $db->fetch_field($query, "logs");
 124  
 125      if(!$mybb->settings['threadsperpage'] || (int)$mybb->settings['threadsperpage'] < 1)
 126      {
 127          $mybb->settings['threadsperpage'] = 20;
 128      }
 129  
 130      $per_page = $mybb->settings['threadsperpage'];
 131  
 132      if(!$per_page)
 133      {
 134          $per_page = 20;
 135      }
 136  
 137      if(!empty($mybb->input['page']) && $mybb->input['page'] > 1)
 138      {
 139          $mybb->input['page'] = $mybb->get_input('page', MyBB::INPUT_INT);
 140          $start = ($mybb->input['page']*$per_page)-$per_page;
 141          $pages = ceil($total_rows / $per_page);
 142          if($mybb->input['page'] > $pages)
 143          {
 144              $mybb->input['page'] = 1;
 145              $start = 0;
 146          }
 147      }
 148      else
 149      {
 150          $mybb->input['page'] = 1;
 151          $start = 0;
 152      }
 153  
 154      $additional_criteria = array();
 155  
 156      $plugins->run_hooks("admin_tools_maillogs_start");
 157  
 158      // Filter form was submitted - play around with the values
 159      if($mybb->request_method == "post")
 160      {
 161          if($mybb->input['from_type'] == "user")
 162          {
 163              $mybb->input['fromname'] = $mybb->input['from_value'];
 164          }
 165          else if($mybb->input['from_type'] == "email")
 166          {
 167              $mybb->input['fromemail'] = $mybb->input['from_value'];
 168          }
 169  
 170          if($mybb->input['to_type'] == "user")
 171          {
 172              $mybb->input['toname'] = $mybb->input['to_value'];
 173          }
 174          else if($mybb->input['to_type'] == "email")
 175          {
 176              $mybb->input['toemail'] = $mybb->input['to_value'];
 177          }
 178      }
 179  
 180      $touid = $mybb->get_input('touid', MyBB::INPUT_INT);
 181      $toname = $db->escape_string($mybb->get_input('toname'));
 182      $toemail = $db->escape_string_like($mybb->get_input('toemail'));
 183  
 184      $fromuid = $mybb->get_input('fromuid', MyBB::INPUT_INT);
 185      $fromemail = $db->escape_string_like($mybb->get_input('fromemail'));
 186  
 187      $subject = $db->escape_string_like($mybb->get_input('subject'));
 188  
 189      // Begin criteria filtering
 190      $additional_sql_criteria = '';
 191      if(!empty($mybb->input['subject']))
 192      {
 193          $additional_sql_criteria .= " AND l.subject LIKE '%{$subject}%'";
 194          $additional_criteria[] = "subject=".urlencode($mybb->input['subject']);
 195      }
 196  
 197      $from_filter = '';
 198      if(!empty($mybb->input['fromuid']))
 199      {
 200          $query = $db->simple_select("users", "uid, username", "uid = '{$fromuid}'");
 201          $user = $db->fetch_array($query);
 202          $from_filter = $user['username'];
 203  
 204          $additional_sql_criteria .= " AND l.fromuid = '{$fromuid}'";
 205          $additional_criteria[] = "fromuid={$fromuid}";
 206      }
 207      else if(!empty($mybb->input['fromname']))
 208      {
 209          $user = get_user_by_username($mybb->input['fromname'], array('fields' => 'uid, username'));
 210          $from_filter = $user['username'];
 211  
 212          if(!$user['uid'])
 213          {
 214              flash_message($lang->error_invalid_user, 'error');
 215              admin_redirect("index.php?module=tools-maillogs");
 216          }
 217  
 218          $additional_sql_criteria .= "AND l.fromuid = '{$user['uid']}'";
 219          $additional_criteria[] = "fromuid={$user['uid']}";
 220      }
 221      else if(!empty($mybb->input['fromemail']))
 222      {
 223          $additional_sql_criteria .= " AND l.fromemail LIKE '%{$fromemail}%'";
 224          $additional_criteria[] = "fromemail=".urlencode($mybb->input['fromemail']);
 225          $from_filter = $mybb->input['fromemail'];
 226      }
 227  
 228      $to_filter = '';
 229      if(!empty($mybb->input['touid']))
 230      {
 231          $query = $db->simple_select("users", "uid, username", "uid = '{$touid}'");
 232          $user = $db->fetch_array($query);
 233          $to_filter = $user['username'];
 234  
 235          $additional_sql_criteria .= " AND l.touid = '{$touid}'";
 236          $additional_criteria[] = "touid={$touid}";
 237      }
 238      else if(!empty($mybb->input['toname']))
 239      {
 240          $user = get_user_by_username($toname, array('fields' => 'username'));
 241          $to_filter = $user['username'];
 242  
 243          if(!$user['uid'])
 244          {
 245              flash_message($lang->error_invalid_user, 'error');
 246              admin_redirect("index.php?module=tools-maillogs");
 247          }
 248  
 249          $additional_sql_criteria .= "AND l.touid='{$user['uid']}'";
 250          $additional_criteria[] = "touid={$user['uid']}";
 251      }
 252      else if(!empty($mybb->input['toemail']))
 253      {
 254          $additional_sql_criteria .= " AND l.toemail LIKE '%{$toemail}%'";
 255          $additional_criteria[] = "toemail=".urlencode($mybb->input['toemail']);
 256          $to_filter = $mybb->input['toemail'];
 257      }
 258  
 259      if(!empty($additional_criteria))
 260      {
 261          $additional_criteria = "&amp;".implode("&amp;", $additional_criteria);
 262      }
 263      else
 264      {
 265          $additional_criteria = '';
 266      }
 267  
 268      $page->output_header($lang->user_email_log);
 269  
 270      $sub_tabs['maillogs'] = array(
 271          'title' => $lang->user_email_log,
 272          'link' => "index.php?module=tools-maillogs",
 273          'description' => $lang->user_email_log_desc
 274      );
 275  
 276      $page->output_nav_tabs($sub_tabs, 'maillogs');
 277  
 278      $form = new Form("index.php?module=tools-maillogs&amp;action=prune", "post");
 279  
 280      $table = new Table;
 281      $table->construct_header($form->generate_check_box("allbox", 1, '', array('class' => 'checkall')));
 282      $table->construct_header($lang->subject, array("colspan" => 2));
 283      $table->construct_header($lang->from, array("class" => "align_center", "width" => "20%"));
 284      $table->construct_header($lang->to, array("class" => "align_center", "width" => "20%"));
 285      $table->construct_header($lang->date_sent, array("class" => "align_center", "width" => "20%"));
 286      $table->construct_header($lang->ip_address, array("class" => "align_center", 'width' => '10%'));
 287  
 288      $query = $db->query("
 289          SELECT l.*, r.username AS to_username, f.username AS from_username, t.subject AS thread_subject
 290          FROM ".TABLE_PREFIX."maillogs l
 291          LEFT JOIN ".TABLE_PREFIX."users r ON (r.uid=l.touid)
 292          LEFT JOIN ".TABLE_PREFIX."users f ON (f.uid=l.fromuid)
 293          LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=l.tid)
 294          WHERE 1=1 {$additional_sql_criteria}
 295          ORDER BY l.dateline DESC
 296          LIMIT {$start}, {$per_page}
 297      ");
 298      while($log = $db->fetch_array($query))
 299      {
 300          $table->construct_cell($form->generate_check_box("log[{$log['mid']}]", $log['mid'], ''), array("width" => 1));
 301          $log['subject'] = htmlspecialchars_uni($log['subject']);
 302          $log['dateline'] = my_date('relative', $log['dateline']);
 303  
 304          $plugins->run_hooks("admin_tools_maillogs_log");
 305  
 306          if($log['type'] == 1)
 307          {
 308              $table->construct_cell("<img src=\"styles/{$page->style}/images/icons/maillogs_user.png\" title=\"{$lang->email_sent_to_user}\" alt=\"\" />", array("width" => 1));
 309              $table->construct_cell("<a href=\"javascript:MyBB.popupWindow('index.php?module=tools-maillogs&amp;action=view&amp;mid={$log['mid']}', null, true);\">{$log['subject']}</a>");
 310          }
 311          elseif($log['type'] == 2)
 312          {
 313              if($log['thread_subject'])
 314              {
 315                  $log['thread_subject'] = htmlspecialchars_uni($log['thread_subject']);
 316                  $thread_link = "<a href=\"../".get_thread_link($log['tid'])."\">".$log['thread_subject']."</a>";
 317              }
 318              else
 319              {
 320                  $thread_link = $lang->deleted;
 321              }
 322              $table->construct_cell("<img src=\"styles/{$page->style}/images/icons/maillogs_thread.png\" title=\"{$lang->sent_using_send_thread_feature}\" alt=\"\" />", array("width" => 1));
 323              $table->construct_cell("<a href=\"javascript:MyBB.popupWindow('index.php?module=tools-maillogs&amp;action=view&amp;mid={$log['mid']}', null, true);\">{$log['subject']}</a><br /><small>{$lang->thread} {$thread_link}</small>");
 324          }
 325          elseif($log['type'] == 3)
 326          {
 327              $table->construct_cell("<img src=\"styles/{$page->style}/images/icons/maillogs_contact.png\" title=\"{$lang->email_sent_using_contact_form}\" alt=\"\" />", array("width" => 1));
 328              $table->construct_cell("<a href=\"javascript:MyBB.popupWindow('index.php?module=tools-maillogs&amp;action=view&amp;mid={$log['mid']}', null, true);\">{$log['subject']}</a>");
 329          }
 330          else
 331          {
 332              $table->construct_cell("<img src=\"styles/{$page->style}/images/icons/default.png\" title=\"{$lang->email}\" alt=\"\" />", array("width" => 1));
 333              $table->construct_cell("<a href=\"javascript:MyBB.popupWindow('index.php?module=tools-maillogs&amp;action=view&amp;mid={$log['mid']}', null, true);\">{$log['subject']}</a>");
 334          }
 335  
 336          if($log['fromuid'] > 0)
 337          {
 338              $log['find_from'] = "<div class=\"float_right\"><a href=\"index.php?module=tools-maillogs&amp;fromuid={$log['fromuid']}\"><img src=\"styles/{$page->style}/images/icons/find.png\" title=\"{$lang->find_emails_by_user}\" alt=\"{$lang->find}\" /></a></div>";
 339          }
 340          else
 341          {
 342              $log['find_from'] = '';
 343          }
 344  
 345          if(!$log['from_username'] && $log['fromuid'] > 0)
 346          {
 347              $table->construct_cell("{$log['find_from']}<div>{$lang->deleted_user}</div>");
 348          }
 349          elseif($log['fromuid'] == 0)
 350          {
 351              $log['fromemail'] = htmlspecialchars_uni($log['fromemail']);
 352              $table->construct_cell("{$log['find_from']}<div>{$log['fromemail']}</div>");
 353          }
 354          else
 355          {
 356              $table->construct_cell("{$log['find_from']}<div><a href=\"../".get_profile_link($log['fromuid'])."\">{$log['from_username']}</a></div>");
 357          }
 358  
 359          if($log['touid'] > 0)
 360          {
 361              $log['find_to'] = "<div class=\"float_right\"><a href=\"index.php?module=tools-maillogs&amp;touid={$log['touid']}\"><img src=\"styles/{$page->style}/images/icons/find.png\" title=\"{$lang->find_emails_to_user}\" alt=\"{$lang->find}\" /></a></div>";
 362          }
 363          else
 364          {
 365              $log['find_to'] = '';
 366          }
 367  
 368          if(!$log['to_username'] && $log['touid'] > 0)
 369          {
 370              $table->construct_cell("{$log['find_to']}<div>{$lang->deleted_user}</div>");
 371          }
 372          elseif($log['touid'] == 0)
 373          {
 374              $log['toemail'] = htmlspecialchars_uni($log['toemail']);
 375              $table->construct_cell("{$log['find_to']}<div>{$log['toemail']}</div>");
 376          }
 377          else
 378          {
 379              $table->construct_cell("{$log['find_to']}<div><a href=\"../".get_profile_link($log['touid'])."\">{$log['to_username']}</a></div>");
 380          }
 381  
 382          $table->construct_cell($log['dateline'], array("class" => "align_center"));
 383          $table->construct_cell(my_inet_ntop($db->unescape_binary($log['ipaddress'])), array("class" => "align_center"));
 384          $table->construct_row();
 385      }
 386  
 387      if($table->num_rows() == 0)
 388      {
 389          $table->construct_cell($lang->no_logs, array("colspan" => "7"));
 390          $table->construct_row();
 391          $table->output($lang->user_email_log);
 392      }
 393      else
 394      {
 395          $table->output($lang->user_email_log);
 396          $buttons[] = $form->generate_submit_button($lang->delete_selected, array('onclick' => "return confirm('{$lang->confirm_delete_logs}');"));
 397          $buttons[] = $form->generate_submit_button($lang->delete_all, array('name' => 'delete_all', 'onclick' => "return confirm('{$lang->confirm_delete_all_logs}');"));
 398          $form->output_submit_wrapper($buttons);
 399      }
 400  
 401      $form->end();
 402  
 403      echo "<br />".draw_admin_pagination($mybb->get_input('page'), $per_page, $total_rows, "index.php?module=tools-maillogs&amp;page={page}{$additional_criteria}");
 404  
 405      $form = new Form("index.php?module=tools-maillogs", "post");
 406      $form_container = new FormContainer($lang->filter_user_email_log);
 407      $user_email = array(
 408          "user" => $lang->username_is,
 409          "email" => $lang->email_contains
 410      );
 411      $form_container->output_row($lang->subject_contains, "", $form->generate_text_box('subject', $mybb->get_input('subject'), array('id' => 'subject')), 'subject');
 412      $from_type = '';
 413      if($mybb->get_input('fromname'))
 414      {
 415          $from_type = "user";
 416      }
 417      else if($mybb->get_input('fromemail'))
 418      {
 419          $from_type = "email";
 420      }
 421      $form_container->output_row($lang->from, "", $form->generate_select_box('from_type', $user_email, $from_type)." ".$form->generate_text_box('from_value', htmlspecialchars_uni($from_filter), array('id' => 'from_value')), 'from_value');
 422      $to_type = '';
 423      if($mybb->get_input('toname'))
 424      {
 425          $to_type = "user";
 426      }
 427      else if($mybb->get_input('toemail'))
 428      {
 429          $to_type = "email";
 430      }
 431      $form_container->output_row($lang->to, "", $form->generate_select_box('to_type', $user_email, $to_type)." ".$form->generate_text_box('to_value', htmlspecialchars_uni($to_filter), array('id' => 'to_value')), 'to_value');
 432      $form_container->end();
 433      $buttons = array();
 434      $buttons[] = $form->generate_submit_button($lang->filter_user_email_log);
 435      $form->output_submit_wrapper($buttons);
 436      $form->end();
 437  
 438      $page->output_footer();
 439  }


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