[ Index ]

PHP Cross Reference of MyBB 1.8.38

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)
  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      $mybb->input['page'] = $mybb->get_input('page', MyBB::INPUT_INT);
 138      if($mybb->input['page'] > 1)
 139      {
 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  
 211          if(!$user)
 212          {
 213              flash_message($lang->error_invalid_user, 'error');
 214              admin_redirect("index.php?module=tools-maillogs");
 215          }
 216  
 217          $from_filter = $user['username'];
 218  
 219          $additional_sql_criteria .= "AND l.fromuid = '{$user['uid']}'";
 220          $additional_criteria[] = "fromuid={$user['uid']}";
 221      }
 222      else if(!empty($mybb->input['fromemail']))
 223      {
 224          $additional_sql_criteria .= " AND l.fromemail LIKE '%{$fromemail}%'";
 225          $additional_criteria[] = "fromemail=".urlencode($mybb->input['fromemail']);
 226          $from_filter = $mybb->input['fromemail'];
 227      }
 228  
 229      $to_filter = '';
 230      if(!empty($mybb->input['touid']))
 231      {
 232          $query = $db->simple_select("users", "uid, username", "uid = '{$touid}'");
 233          $user = $db->fetch_array($query);
 234          $to_filter = $user['username'];
 235  
 236          $additional_sql_criteria .= " AND l.touid = '{$touid}'";
 237          $additional_criteria[] = "touid={$touid}";
 238      }
 239      else if(!empty($mybb->input['toname']))
 240      {
 241          $user = get_user_by_username($toname, array('fields' => 'username'));
 242  
 243          if(!$user)
 244          {
 245              flash_message($lang->error_invalid_user, 'error');
 246              admin_redirect("index.php?module=tools-maillogs");
 247          }
 248  
 249          $to_filter = $user['username'];
 250  
 251          $additional_sql_criteria .= "AND l.touid='{$user['uid']}'";
 252          $additional_criteria[] = "touid={$user['uid']}";
 253      }
 254      else if(!empty($mybb->input['toemail']))
 255      {
 256          $additional_sql_criteria .= " AND l.toemail LIKE '%{$toemail}%'";
 257          $additional_criteria[] = "toemail=".urlencode($mybb->input['toemail']);
 258          $to_filter = $mybb->input['toemail'];
 259      }
 260  
 261      if(!empty($additional_criteria))
 262      {
 263          $additional_criteria = "&amp;".implode("&amp;", $additional_criteria);
 264      }
 265      else
 266      {
 267          $additional_criteria = '';
 268      }
 269  
 270      $page->output_header($lang->user_email_log);
 271  
 272      $sub_tabs['maillogs'] = array(
 273          'title' => $lang->user_email_log,
 274          'link' => "index.php?module=tools-maillogs",
 275          'description' => $lang->user_email_log_desc
 276      );
 277  
 278      $page->output_nav_tabs($sub_tabs, 'maillogs');
 279  
 280      $form = new Form("index.php?module=tools-maillogs&amp;action=prune", "post");
 281  
 282      $table = new Table;
 283      $table->construct_header($form->generate_check_box("allbox", 1, '', array('class' => 'checkall')));
 284      $table->construct_header($lang->subject, array("colspan" => 2));
 285      $table->construct_header($lang->from, array("class" => "align_center", "width" => "20%"));
 286      $table->construct_header($lang->to, array("class" => "align_center", "width" => "20%"));
 287      $table->construct_header($lang->date_sent, array("class" => "align_center", "width" => "20%"));
 288      $table->construct_header($lang->ip_address, array("class" => "align_center", 'width' => '10%'));
 289  
 290      $query = $db->query("
 291          SELECT l.*, r.username AS to_username, f.username AS from_username, t.subject AS thread_subject
 292          FROM ".TABLE_PREFIX."maillogs l
 293          LEFT JOIN ".TABLE_PREFIX."users r ON (r.uid=l.touid)
 294          LEFT JOIN ".TABLE_PREFIX."users f ON (f.uid=l.fromuid)
 295          LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=l.tid)
 296          WHERE 1=1 {$additional_sql_criteria}
 297          ORDER BY l.dateline DESC
 298          LIMIT {$start}, {$per_page}
 299      ");
 300      while($log = $db->fetch_array($query))
 301      {
 302          $table->construct_cell($form->generate_check_box("log[{$log['mid']}]", $log['mid'], ''), array("width" => 1));
 303          $log['subject'] = htmlspecialchars_uni($log['subject']);
 304          $log['dateline'] = my_date('relative', $log['dateline']);
 305  
 306          $plugins->run_hooks("admin_tools_maillogs_log");
 307  
 308          if($log['type'] == 1)
 309          {
 310              $table->construct_cell("<img src=\"styles/{$page->style}/images/icons/maillogs_user.png\" title=\"{$lang->email_sent_to_user}\" alt=\"\" />", array("width" => 1));
 311              $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>");
 312          }
 313          elseif($log['type'] == 2)
 314          {
 315              if($log['thread_subject'])
 316              {
 317                  $log['thread_subject'] = htmlspecialchars_uni($log['thread_subject']);
 318                  $thread_link = "<a href=\"../".get_thread_link($log['tid'])."\">".$log['thread_subject']."</a>";
 319              }
 320              else
 321              {
 322                  $thread_link = $lang->deleted;
 323              }
 324              $table->construct_cell("<img src=\"styles/{$page->style}/images/icons/maillogs_thread.png\" title=\"{$lang->sent_using_send_thread_feature}\" alt=\"\" />", array("width" => 1));
 325              $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>");
 326          }
 327          elseif($log['type'] == 3)
 328          {
 329              $table->construct_cell("<img src=\"styles/{$page->style}/images/icons/maillogs_contact.png\" title=\"{$lang->email_sent_using_contact_form}\" alt=\"\" />", array("width" => 1));
 330              $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>");
 331          }
 332          else
 333          {
 334              $table->construct_cell("<img src=\"styles/{$page->style}/images/icons/default.png\" title=\"{$lang->email}\" alt=\"\" />", array("width" => 1));
 335              $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>");
 336          }
 337  
 338          if($log['fromuid'] > 0)
 339          {
 340              $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>";
 341          }
 342          else
 343          {
 344              $log['find_from'] = '';
 345          }
 346  
 347          if(!$log['from_username'] && $log['fromuid'] > 0)
 348          {
 349              $table->construct_cell("{$log['find_from']}<div>{$lang->deleted_user}</div>");
 350          }
 351          elseif($log['fromuid'] == 0)
 352          {
 353              $log['fromemail'] = htmlspecialchars_uni($log['fromemail']);
 354              $table->construct_cell("{$log['find_from']}<div>{$log['fromemail']}</div>");
 355          }
 356          else
 357          {
 358              $table->construct_cell("{$log['find_from']}<div><a href=\"../".get_profile_link($log['fromuid'])."\">{$log['from_username']}</a></div>");
 359          }
 360  
 361          if($log['touid'] > 0)
 362          {
 363              $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>";
 364          }
 365          else
 366          {
 367              $log['find_to'] = '';
 368          }
 369  
 370          if(!$log['to_username'] && $log['touid'] > 0)
 371          {
 372              $table->construct_cell("{$log['find_to']}<div>{$lang->deleted_user}</div>");
 373          }
 374          elseif($log['touid'] == 0)
 375          {
 376              $log['toemail'] = htmlspecialchars_uni($log['toemail']);
 377              $table->construct_cell("{$log['find_to']}<div>{$log['toemail']}</div>");
 378          }
 379          else
 380          {
 381              $table->construct_cell("{$log['find_to']}<div><a href=\"../".get_profile_link($log['touid'])."\">{$log['to_username']}</a></div>");
 382          }
 383  
 384          $table->construct_cell($log['dateline'], array("class" => "align_center"));
 385          $table->construct_cell(my_inet_ntop($db->unescape_binary($log['ipaddress'])), array("class" => "align_center"));
 386          $table->construct_row();
 387      }
 388  
 389      if($table->num_rows() == 0)
 390      {
 391          $table->construct_cell($lang->no_logs, array("colspan" => "7"));
 392          $table->construct_row();
 393          $table->output($lang->user_email_log);
 394      }
 395      else
 396      {
 397          $table->output($lang->user_email_log);
 398          $buttons[] = $form->generate_submit_button($lang->delete_selected, array('onclick' => "return confirm('{$lang->confirm_delete_logs}');"));
 399          $buttons[] = $form->generate_submit_button($lang->delete_all, array('name' => 'delete_all', 'onclick' => "return confirm('{$lang->confirm_delete_all_logs}');"));
 400          $form->output_submit_wrapper($buttons);
 401      }
 402  
 403      $form->end();
 404  
 405      echo "<br />".draw_admin_pagination($mybb->input['page'], $per_page, $total_rows, "index.php?module=tools-maillogs&amp;page={page}{$additional_criteria}");
 406  
 407      $form = new Form("index.php?module=tools-maillogs", "post");
 408      $form_container = new FormContainer($lang->filter_user_email_log);
 409      $user_email = array(
 410          "user" => $lang->username_is,
 411          "email" => $lang->email_contains
 412      );
 413      $form_container->output_row($lang->subject_contains, "", $form->generate_text_box('subject', $mybb->get_input('subject'), array('id' => 'subject')), 'subject');
 414      $from_type = '';
 415      if($mybb->get_input('fromname'))
 416      {
 417          $from_type = "user";
 418      }
 419      else if($mybb->get_input('fromemail'))
 420      {
 421          $from_type = "email";
 422      }
 423      $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');
 424      $to_type = '';
 425      if($mybb->get_input('toname'))
 426      {
 427          $to_type = "user";
 428      }
 429      else if($mybb->get_input('toemail'))
 430      {
 431          $to_type = "email";
 432      }
 433      $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');
 434      $form_container->end();
 435      $buttons = array();
 436      $buttons[] = $form->generate_submit_button($lang->filter_user_email_log);
 437      $form->output_submit_wrapper($buttons);
 438      $form->end();
 439  
 440      $page->output_footer();
 441  }


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