[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

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

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


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