Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.51 KB | None | 0 0
  1. <?php
  2.  
  3. function array_sort($array, $on, $order=SORT_ASC)
  4. {
  5.     $new_array = array();
  6.     $sortable_array = array();
  7.  
  8.     if (count($array) > 0) {
  9.         foreach ($array as $k => $v) {
  10.             if (is_array($v)) {
  11.                 foreach ($v as $k2 => $v2) {
  12.                     if ($k2 == $on) {
  13.                         $sortable_array[$k] = $v2;
  14.                     }
  15.                 }
  16.             } else {
  17.                 $sortable_array[$k] = $v;
  18.             }
  19.         }
  20.  
  21.         switch ($order) {
  22.             case SORT_ASC:
  23.                 asort($sortable_array);
  24.             break;
  25.             case SORT_DESC:
  26.                 arsort($sortable_array);
  27.             break;
  28.         }
  29.  
  30.         foreach ($sortable_array as $k => $v) {
  31.             $new_array[$k] = $array[$k];
  32.         }
  33.     }
  34.  
  35.     return $new_array;
  36. }
  37.  
  38. $link = mysql_connect("localhost", "USER", "PASSWORD");
  39. mysql_select_db("agent", $link);
  40.  
  41. $result = mysql_query("SELECT * FROM teacher JOIN (site) ON teacher.site_id = site.id ORDER BY site.name, teacher.last_name", $link);
  42. $i = 0;
  43. while($row = mysql_fetch_array($result)){
  44.  
  45. $teacher_pull = "SELECT teacher.first_name, teacher.last_name, site.passkey, site.name, logon_history.logon_time, COUNT(logon_history.logon_time) FROM teacher JOIN (site, logon_history) ON ( teacher.site_id = site.id AND teacher.id = logon_history.teacher_id ) WHERE teacher_id = " . $row[0];
  46.  
  47. $logon_history_pull = "SELECT logon_time FROM logon_history WHERE teacher_id=" . $row[0] . " ORDER BY logon_time DESC LIMIT 1";
  48.  
  49.  
  50.         $teacher_results = mysql_query($teacher_pull, $link);
  51.  
  52.                 $logon_history_results = mysql_query($logon_history_pull, $link);
  53.  
  54.         $teacher[$i]['name'] = mysql_result($teacher_results,0,"teacher.last_name");
  55.         $teacher[$i]['name'] .= ", " . mysql_result($teacher_results,0,"teacher.first_name");
  56.  
  57.  
  58.                 $last_logon = mysql_fetch_assoc($logon_history_results);
  59.  
  60.                 //print_r($last_logon);
  61.                 $teacher[$i]['last_logon'] = $last_logon['logon_time'];
  62.  
  63.                 //print_r($logon_history_results);
  64.  
  65.                 //$last_logon = mysql_result($logon_history_results,0,"logon_time");
  66.  
  67.                 $teacher[$i]['site'] = mysql_result($teacher_results,0,"site.name");
  68.         $teacher[$i]['passkey'] = mysql_result($teacher_results,0,"site.passkey");
  69.         $teacher[$i]['date'] = mysql_result($teacher_results,0,"logon_history.logon_time");
  70.         $teacher[$i]['numlogins'] = mysql_result($teacher_results,0,5);
  71.  
  72. $i = $i + 1;
  73. }
  74. //print_r($teacher);
  75. //echo "<br />
  76. //<br />";
  77.  
  78. //print_r(array_sort($teacher, 'last_logon', SORT_DESC));
  79. //echo "<br />
  80. //<br />";
  81.  
  82. $teacher = array_sort($teacher, 'last_logon', SORT_DESC);
  83. //print_r($teacher);
  84.  
  85.  
  86. $date = date("m/d/Y");
  87.  
  88. $report = "<H1>Stuff</H1><table width='800'><tr><td><H2>Stuff</H2></td><td align='right'><H2>" . $date . "</H2></td></tr><tr><td></td><td align='right'>user logins as of 7/13</td></tr></table>";
  89.  
  90.  
  91. $report .= "<table width='800' border='1' cellpadding='3'><tr><td><strong>Site Name</strong></td><td><strong>Teacher</strong></td><td><strong>Keycode</strong></td>";
  92.  
  93. $report .= "<td align=center><strong>Date Registered</strong></td><td><strong>#of Logins</strong></td><td align=center><strong>Last Logon</strong></td></tr>";
  94.  
  95. foreach($teacher as $v){
  96.  
  97.  
  98.         $report .= "<tr><td>";
  99.         $report .= $v['site'];
  100.         $report .= "</td><td>";
  101.         $report .= $v['name'];
  102.         $report .= "</td><td>";
  103.         $report .= $v['passkey'];
  104.         $report .= "</td><td>";
  105.         $report .= $v['date'];
  106.         $report .= "</td><td>";
  107.                 $report .= $v['numlogins'];
  108.                 $report .= "</td><td>";
  109.                 $report .= $v['last_logon'];
  110.         $report .= "</td></tr>";
  111.  
  112.  
  113. }
  114. $report .= "</table>";
  115.  
  116.  
  117.  require_once "Mail.php";
  118.  
  119.  $from = "EMAIL";
  120.  $to = "EMAIL";
  121.  $subject = "Daily Report";
  122.  $body = $report;
  123.  
  124.  $host = "MAILSERVER";
  125.  $username = "EMAIL";
  126.  $password = "PASSWORD";
  127.  
  128.  $headers = array ('From' => $from,
  129.    'To' => $to,
  130.    'Subject' => $subject,
  131.    'MIME-Version' => '1.0',
  132.    'Content-Type' => 'text/html',
  133.    'Charset' => 'ISO-8859-1');
  134.  
  135.  $smtp = Mail::factory('smtp',
  136.    array ('host' => $host,
  137.      'auth' => true,
  138.      'username' => $username,
  139.      'password' => $password));
  140.  
  141.  $mail = $smtp->send($to, $headers, $body);
  142.  
  143.  if (PEAR::isError($mail)) {
  144.    echo("<p>" . $mail->getMessage() . "</p>");
  145.   } else {
  146.    echo("<p>Message successfully sent!</p>");
  147.   }
  148.  
  149.  
  150.  
  151. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement