[ Index ]

PHP Cross Reference of MyBB 1.6.5

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: maillogs.php 5297 2010-12-28 22:01:14Z Tomm $
  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 = 20;
 136  
 137      if($mybb->input['page'] && $mybb->input['page'] > 1)
 138      {
 139          $mybb->input['page'] = intval($mybb->input['page']);
 140          $start = ($mybb->input['page']*$per_page)-$per_page;
 141      }
 142      else
 143      {
 144          $mybb->input['page'] = 1;
 145          $start = 0;
 146      }
 147  
 148      $additional_criteria = array();
 149  
 150      // Filter form was submitted - play around with the values
 151      if($mybb->request_method == "post")
 152      {
 153          if($mybb->input['from_type'] == "user")
 154          {
 155              $mybb->input['fromname'] = $mybb->input['from_value'];
 156          }
 157          else if($mybb->input['from_type'] == "email")
 158          {
 159              $mybb->input['fromemail'] = $mybb->input['from_value'];
 160          }
 161  
 162          if($mybb->input['to_type'] == "user")
 163          {
 164              $mybb->input['toname'] = $mybb->input['to_value'];
 165          }
 166          else if($mybb->input['to_type'] == "email")
 167          {
 168              $mybb->input['toemail'] = $mybb->input['to_value'];
 169          }
 170      }
 171  
 172      // Begin criteria filtering
 173      if($mybb->input['subject'])
 174      {
 175          $additional_sql_criteria .= " AND l.subject LIKE '%".$db->escape_string($mybb->input['subject'])."%'";
 176          $additional_criteria[] = "subject='".htmlspecialchars_uni($mybb->input['subject'])."'";
 177      }
 178  
 179      if($mybb->input['fromuid'])
 180      {
 181          $query = $db->simple_select("users", "uid, username", "uid='".intval($mybb->input['fromuid'])."'");
 182          $user = $db->fetch_array($query);
 183          $from_filter = $user['username'];
 184          $additional_sql_criteria .= " AND l.fromuid='".intval($mybb->input['fromuid'])."'";
 185          $additional_criteria[] = "fromuid='".intval($mybb->input['fromuid'])."'";
 186      }
 187      else if($mybb->input['fromname'])
 188      {
 189          $query = $db->simple_select("users", "uid, username", "LOWER(username)='".my_strtolower($mybb->input['fromname'])."'");
 190          $user = $db->fetch_array($query);
 191          $from_filter = $user['username'];
 192  
 193          if(!$user['uid'])
 194          {
 195              flash_message($lang->error_invalid_user, 'error');
 196              admin_redirect("index.php?module=tools-maillogs");
 197          }
 198          $additional_sql_criteria .= "AND l.fromuid='{$user['uid']}'";
 199          $additional_criteria = "fromuid={$user['uid']}";
 200      }
 201  
 202      if($mybb->input['fromemail'])
 203      {
 204          $additional_sql_criteria .= " AND l.fromemail LIKE '%".$db->escape_string($mybb->input['fromemail'])."%'";
 205          $additional_criteria[] = "fromemail=".urlencode($mybb->input['fromemail']);
 206          $from_filter = $mybb->input['fromemail'];
 207      }
 208  
 209      if($mybb->input['touid'])
 210      {
 211          $query = $db->simple_select("users", "uid, username", "uid='".intval($mybb->input['touid'])."'");
 212          $user = $db->fetch_array($query);
 213          $to_filter = $user['username'];
 214          $additional_sql_criteria .= " AND l.touid='".intval($mybb->input['touid'])."'";
 215          $additional_criteria[] = "touid='".intval($mybb->input['touid'])."'";
 216      }
 217      else if($mybb->input['toname'])
 218      {
 219          $query = $db->simple_select("users", "uid, username", "LOWER(username)='".my_strtolower($mybb->input['toname'])."'");
 220          $user = $db->fetch_array($query);
 221          $to_filter = $user['username'];
 222  
 223          if(!$user['uid'])
 224          {
 225              flash_message($lang->error_invalid_user, 'error');
 226              admin_redirect("index.php?module=tools-maillogs");
 227          }
 228          $additional_sql_criteria .= "AND l.touid='{$user['uid']}'";
 229          $additional_criteria = "touid='{$user['uid']}'";
 230      }
 231  
 232      if($mybb->input['toemail'])
 233      {
 234          $additional_sql_criteria .= " AND l.toemail LIKE '%".$db->escape_string($mybb->input['toemail'])."%'";
 235          $additional_criteria[] = "toemail='".urlencode($mybb->input['toemail'])."'";
 236          $to_filter = $mybb->input['toemail'];
 237      }
 238  
 239      if($additional_criteria)
 240      {
 241          $additional_criteria = "&amp;".implode("&amp;", $additional_criteria);
 242      }
 243  
 244      $page->output_header($lang->user_email_log);
 245      
 246      $sub_tabs['maillogs'] = array(
 247          'title' => $lang->user_email_log,
 248          'link' => "index.php?module=tools-maillogs",
 249          'description' => $lang->user_email_log_desc
 250      );
 251  
 252      $page->output_nav_tabs($sub_tabs, 'maillogs');
 253      
 254      $form = new Form("index.php?module=tools-maillogs&amp;action=prune", "post");
 255  
 256      $table = new Table;
 257      $table->construct_header($form->generate_check_box("checkall", 1, '', array('class' => 'checkall')));
 258      $table->construct_header($lang->subject, array("colspan" => 2));
 259      $table->construct_header($lang->from, array("class" => "align_center", "width" => "20%"));
 260      $table->construct_header($lang->to, array("class" => "align_center", "width" => "20%"));
 261      $table->construct_header($lang->date_sent, array("class" => "align_center", "width" => "20%"));
 262  
 263      $query = $db->query("
 264          SELECT l.*, r.username AS to_username, f.username AS from_username, t.subject AS thread_subject
 265          FROM ".TABLE_PREFIX."maillogs l
 266          LEFT JOIN ".TABLE_PREFIX."users r ON (r.uid=l.touid)
 267          LEFT JOIN ".TABLE_PREFIX."users f ON (f.uid=l.fromuid)
 268          LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=l.tid)
 269          WHERE 1=1 {$additional_sql_criteria}
 270          ORDER BY l.dateline DESC
 271          LIMIT {$start}, {$per_page}
 272      ");
 273      while($log = $db->fetch_array($query))
 274      {
 275          $table->construct_cell($form->generate_check_box("log[{$log['mid']}]", $log['mid'], ''));
 276          $log['subject'] = htmlspecialchars_uni($log['subject']);
 277          $log['dateline'] = date($mybb->settings['dateformat'], $log['dateline']).", ".date($mybb->settings['timeformat'], $log['dateline']);
 278          if($log['tid'] > 0)
 279          {
 280              if($log['thread_subject'])
 281              {
 282                  $log['thread_subject'] = htmlspecialchars_uni($log['thread_subject']);
 283                  $thread_link = "<a href=\"../".get_thread_link($log['tid'])."\">".$log['thread_subject']."</a>";
 284              }
 285              else
 286              {
 287                  $thread_link = $lang->deleted;
 288              }
 289              $table->construct_cell("<img src=\"styles/{$page->style}/images/icons/maillogs_thread.gif\" title=\"{$lang->sent_using_send_thread_feature}\" alt=\"\" />", array("width" => 1));
 290              $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>");
 291              $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>";
 292              if(!$log['from_username'])
 293              {
 294                  $table->construct_cell("{$find_from}<div>{$lang->deleted_user}</div>");
 295              }
 296              else
 297              {
 298                  $table->construct_cell("{$find_from}<div><a href=\"../".get_profile_link($log['fromuid'])."\">{$log['from_username']}</a></div>");
 299              }
 300              $log['toemail'] = htmlspecialchars_uni($log['toemail']);
 301              $table->construct_cell($log['toemail']);
 302              $table->construct_cell($log['dateline'], array("class" => "align_center"));
 303          }
 304          else
 305          {
 306              $table->construct_cell("<img src=\"styles/{$page->style}/images/icons/maillogs_user.gif\" title=\"{$lang->email_sent_to_user}\" alt=\"\" />", array("width" => 1));
 307              $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>");
 308              $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>";
 309              if(!$log['from_username'])
 310              {
 311                  $table->construct_cell("{$find_from}<div>{$lang->deleted_user}</div>");
 312              }
 313              else
 314              {
 315                  $table->construct_cell("{$find_from}<div><a href=\"../".get_profile_link($log['fromuid'])."\">{$log['from_username']}</a></div>");
 316              }
 317              $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>"; 
 318              if(!$log['to_username'])
 319              {
 320                  $table->construct_cell("{$find_to}<div>{$lang->deleted_user}</div>");
 321              }
 322              else
 323              {
 324                  $table->construct_cell("{$find_to}<div><a href=\"../".get_profile_link($log['touid'])."\">{$log['to_username']}</a></div>");
 325              }
 326              $table->construct_cell($log['dateline'], array("class" => "align_center"));
 327          }
 328          $table->construct_row();
 329      }
 330      
 331      if($table->num_rows() == 0)
 332      {
 333          $table->construct_cell($lang->no_logs, array("colspan" => "6"));
 334          $table->construct_row();
 335          $table->output($lang->user_email_log);
 336      }
 337      else
 338      {
 339          $table->output($lang->user_email_log);
 340          $buttons[] = $form->generate_submit_button($lang->delete_selected, array('onclick' => "return confirm('{$lang->confirm_delete_logs}');"));
 341          $buttons[] = $form->generate_submit_button($lang->delete_all, array('name' => 'delete_all', 'onclick' => "return confirm('{$lang->confirm_delete_all_logs}');"));
 342          $form->output_submit_wrapper($buttons);
 343      }
 344      
 345      $form->end();
 346      
 347      $query = $db->simple_select("maillogs l", "COUNT(l.mid) as logs", "1=1 {$additional_sql_criteria}");
 348      $total_rows = $db->fetch_field($query, "logs");
 349  
 350      echo "<br />".draw_admin_pagination($mybb->input['page'], $per_page, $total_rows, "index.php?module=tools-maillogs&amp;page={page}{$additional_criteria}");
 351      
 352      $form = new Form("index.php?module=tools-maillogs", "post");
 353      $form_container = new FormContainer($lang->filter_user_email_log);
 354      $user_email = array(
 355          "user" => $lang->username_is,
 356          "email" => $lang->email_contains
 357      );
 358      $form_container->output_row($lang->subject_contains, "", $form->generate_text_box('subject', $mybb->input['subject'], array('id' => 'subject')), 'subject');    
 359      if($from_username)
 360      {
 361          $from_type = "user";
 362      }
 363      else if($mybb->input['fromemail'])
 364      {
 365          $from_type = "email";
 366      }
 367      $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');
 368      if($to_username)
 369      {
 370          $to_type = "user";
 371      }
 372      else if($mybb->input['toemail'])
 373      {
 374          $to_type = "email";
 375      }
 376      $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');
 377      $form_container->end();
 378      $buttons[] = $form->generate_submit_button($lang->filter_user_email_log);
 379      $form->output_submit_wrapper($buttons);
 380      $form->end();
 381  
 382      $page->output_footer();
 383  }
 384  ?>


Generated: Sun Dec 11 14:16:27 2011 Cross-referenced by PHPXref 0.7.1