Location: PHPKode > projects > RepMan > repman/inc/report.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <title>HTML Report</title>
  <link rel="stylesheet" href="sc/style.css" type="text/css">
</head>
<body>
<br>
<div id="menu">
<?
  require ('inc/menu.php');
?>
</div>
<h1>HTML Report</h1>
<?
  ConnectIt();

  $user_in = 0;
  if ($usdata = Query("SELECT name FROM user ORDER BY name;")) {
    if (isset($_GET["name"])) {
      foreach ($usdata as $uslist) {
      	if ($uslist[0] == $_GET["name"]) {
          $_SESSION["username"] = $_GET["name"];
          $user_in = 1;
        } 
      }
    } elseif (isset($_POST["us"])) {
      if ($_POST["us"]!="0") {
        foreach ($usdata as $uslist) {
        	if ($uslist[0] == $_POST["us"]) {
            $_SESSION["username"] = $_POST["us"];
            $user_in = 1;
          }
        }     
      } else {
        $_SESSION["username"] = "";
        $user_in = 0;
      }
    } elseif (isset($_SESSION["username"]) && $_SESSION["username"]!="") {
          $user_in = 1;      
    }
  } else { 
    if (isLoggedIn()) {
      echo "<div class=\"info\"><p><u>Couldn't find users</u><br>Disabling user filter.<br>\nIf you want to use user filter, <a href=\"users.php?new=1\">add users</a> and configure mailing list.</p></div>\n";
    } else {
      echo "<div class=\"info\"><p><u>Couldn't find users</u><br>Disabling user filter.<br>\nIf you want to use user filter, add users and configure mailing list.<br>\n To do that, you must <a href=\"?admin=1\" title=\"Log in as administrator\">log in as Repman's administrator</a></p></div>\n";
    }
    logerr("Nemuzu nacist jmena uzivatelu.");
  }

  if (isset($_GET["date"]) && $_GET["date"] != 0 ) {     // zmena data diferenci (pomoci odkazu v RepManovi)
    $d = $_GET["date"]+0;     // ulozit si diferenci
    $d_strtt = strtotime("$d day");   // ulozit microtime reprezentaci 
    if ($d_strtt < $GLOBALS["first_may"]) {     // kontrola 1st May 2008
      logdebug("MAY: ".date("Ymd",$d_strtt)." is less than 1st May!");
      $d = strtotime("now")-$GLOBALS["first_may"];    // vypocitat rozdil dnesniho dne a 1st May k ulozeni nove diference
      $d /= 86400;    // prevod na pocet dnu
      $d = floor($d);  // zaokrouhleni na jednotky dolu
      $d *= -1;  // prevedeni do casove osy na dny
    }
    $t = strtotime("$d day");
    $date = date("Ymd", $t);	

  } elseif (isset($_GET["group"])) {      // zmena data skupinou (odkaz z e-mailu)
    $sgroup = $_GET["group"]+0;     // ulozeni skupiny
    $g_strtt = strtotime($sgroup);      // prevest na microtime
    if ($g_strtt >= $GLOBALS["first_may"]) {
      $td = strtotime(date("Ymd"));  // prevest cislo dnesni skupiny na microtime
      $d = ($g_strtt - $td)/86400;      // vypocet diference na dny
      $d = floor($d);     // zaokrouhleni na jednotky dolu
    } else {
      logdebug("MAY: ".date("Ymd",$d_strtt)." is less than 1st May!");
      $d = strtotime("now")-$GLOBALS["first_may"];    // vypocitat rozdil dnesniho dne a 1st May k ulozeni nove diference
      $d /= 86400;    // prevod na pocet dnu
      $d = floor($d);  // zaokrouhleni na jednotky dolu
      $d *= -1;  // prevedeni do casove osy na dny
    }
    $t = strtotime("$d day");
    $date = date("Ymd",$t);

  } else {      // plati pro dnesni den
    $date = date("Ymd",strtotime("now"));
  }
  
  /*if (isset($_GET["group"]) && strlen($_GET["group"]+0) == 8) {
    $sgroup = $_GET["group"]+0;
    if (!$sgdata = Query("SELECT * FROM sess WHERE processed='$sgroup';")) {
      echo "<div class=\"info\"><p>Group $sgroup doesn't exist.</p></div>\n";
    }
  } else {
    echo "<div class=\"info\"><p>Group ".$_GET["group"]." doesn't exist.</p></div>\n";
  }*/

  if(Query("SELECT * FROM sess where processed=$date;")) {
    $sess_exists = true;
  } else {
    $sess_exists = false;
  }

  require ('inc/config.php');
  
  if ($usdata) {
?>

<form action="index.php<? if (isset($date)) { echo "?date=$d"; } ?>" method="post" accept="text/html" title="User filter">
  <label for="us">Filter for user:</label>
  <select name="us" size="1">
<?
    if ($usna = ifAsUser()) {
      echo "    <option value=\"0\"></option>\n";      	
      foreach ($usdata as $uslist) {
        if ($uslist[0]==$_SESSION["username"]) {
        	echo "    <option value=\"".$uslist[0]."\" selected>".$uslist[0]."</option>\n";
      	} else {
        	echo "    <option value=\"".$uslist[0]."\">".$uslist[0]."</option>\n";
        }
      }    
    } else {
      echo "    <option value=\"0\" selected></option>\n";
      foreach ($usdata as $uslist) {
      	echo "    <option value=\"".$uslist[0]."\">".$uslist[0]."</option>\n";
      }    
    }
?>
  </select> 
  <input type="submit" value="Apply ->">
</form>
<?
  }  
?>

<h2>Session group <?
                      if (isset($d)) {
                        $dminus1 = $d-1;
                        $dplus1 = $d+1;
                      } else {
                        $dminus1 = -1;
                        $dplus1 = 1;
                      }
                      if (strtotime($date) != $GLOBALS["first_may"]) {      // pokud nejsme na pocatku RepManova kalendare (prvni maj 2008)
                        echo "<a href=\"index.php?date=$dminus1\" title=\"$date minus 1\">&lsaquo;</a>";   // zobraz odkaz pro snizeni data, ktere se zobrazi
                      }
                      if (isset($d)and($d>0)) {
                        echo "<a href=\"index.php?date=0\" title=\"today\">&circ;</a>";                        
                      }
                      echo $date;
                      if (isset($d)and($d<0)) {
                        echo "<a href=\"index.php?date=0\" title=\"today\">&circ;</a>";                        
                        echo "<a href=\"index.php?date=$dplus1\" title=\"$date plus 1\">&rsaquo;</a>";
                      }
                  ?></h2>

<?
  if($sess_exists && $user_in == 0):
?>
  <small>Processed sessions</small>
  <ul class="no_dec">
  <?  
    $list = Query("SELECT client.name,job.job,finished,status FROM sess LEFT JOIN (client,job) ON (client.id=sess.client_id AND job.id=sess.job_id) WHERE processed=$date;");
    echo "<li><u>Client</u>".str_repeat("&nbsp;", 10)."<u>Job</u>".str_repeat("&nbsp;", 15)."<u>Finish time</u>".str_repeat("&nbsp;", 9)."<u>Status</u></li>\n";
    foreach ($list as $sess) {
      echo "<li>$sess[0]".str_repeat("&nbsp;", 16-strlen($sess[0])).$sess[1].str_repeat("&nbsp;", 18-strlen($sess[1])).$sess[2]." ".ELevel($sess[3])."</li>\n";
    }
  ?>  
  </ul>

<?
  elseif($sess_exists && $user_in == 1):
    /*if ($list = Query("SELECT client.id,job.id,client.name,job.job,finished,status FROM sess LEFT JOIN (client,job) ON (client.id=sess.client_id AND job.id=sess.job_id) WHERE processed=$date;")) {
      if ($mlist = Query("SELECT cl_id,jo_id FROM mailing LEFT JOIN(client,job,user) ON(client.id=mailing.cl_id AND job.id=mailing.jo_id AND user.id=mailing.us_id) WHERE user.name='".$_SESSION["username"]."';")) {
        $ussess = array ();
        $c = 0;
        foreach ($list as $sslist) {
        	foreach ($mlist as $mss) {
            if ($sslist[0]==$mss[0] && $sslist[1]==$mss[1]) {
              $ussess[$c++] = $mss;
            }
          }
        }
      } else {
        echo "Chyba selektovani mailing pro sessions. User: ".$_SESSION["username"]."<br>\n";
        logerr("Chyba selektovani mailing pro sessions.");
      }
    } */  
    /*if ($list = Query("SELECT sess.client_id,sess.job_id,sess.finished,sess.status,mailing.cl_id,mailing.jo_id,mailing.us_id FROM sess,mailing LEFT JOIN (user) ON(user.id=mailing.us_id)  WHERE sess.processed='20080604' AND (sess.client_id=mailing.cl_id OR sess.job_id=mailing.jo_id) AND user.name='".$_SESSION["username"]."';")) {*/
    /*if ($list = Query("SELECT client.name,job.job,sess.finished,sess.status,mailing.cl_id,mailing.jo_id,mailing.us_id,user.name,sess.client_id,sess.job_id FROM sess LEFT JOIN (client,job) ON (client.id=sess.client_id AND job.id=sess.job_id),mailing LEFT JOIN(user) ON (user.id=mailing.us_id)  WHERE sess.processed='$date' AND (sess.client_id=mailing.cl_id OR sess.job_id=mailing.jo_id) AND user.name='".$_SESSION["username"]."';")) {*/
    if ($list = Query("SELECT client.name,job.job,sess.finished,sess.status,mailing.cl_id,mailing.jo_id,mailing.us_id,user.name,sess.client_id,sess.job_id FROM sess LEFT JOIN (client,job) ON (client.id=sess.client_id AND job.id=sess.job_id),mailing LEFT JOIN(user) ON (user.id=mailing.us_id)  WHERE sess.processed='$date' AND ((sess.client_id=mailing.cl_id AND sess.job_id=mailing.jo_id) OR (mailing.cl_id=0 AND sess.job_id=mailing.jo_id) OR (sess.client_id=mailing.cl_id AND mailing.jo_id=0)) AND user.name='".$_SESSION["username"]."';")) {
?>
      <small>Processed sessions for <? echo "'".$_SESSION["username"]."'"; ?></small>
      <ul class="no_dec">
<?
      echo "<li><u>Client</u>".str_repeat("&nbsp;", 10)."<u>Job</u>".str_repeat("&nbsp;", 15)."<u>Finish time</u>".str_repeat("&nbsp;", 9)."<u>Status</u></li>\n";
      foreach ($list as $sess) {
        echo "<li>$sess[0]".str_repeat("&nbsp;", 16-strlen($sess[0])).$sess[1].str_repeat("&nbsp;", 18-strlen($sess[1])).$sess[2]." ".ELevel($sess[3])."</li>\n";
      }      
    } else {
      echo "<small>No processed session (for this user) @$date</small><br>\n";
    }
?>
    </ul>
<?
  else: 
?>
  <small>
    No processed session @<?echo $date; ?>.<br><br>
  </small>
<?
  endif;
  if (isset($_GET["processed"])&&(!$_GET["processed"])):
    echo "<h2>Unprocessed sessions</h2>\n";
    echo "<ul class=\"no_dec\">\n";
    if ($list = Query("SELECT client.name,job.job,finished,status FROM sess LEFT JOIN (client,job) ON (client.id=sess.client_id AND job.id=sess.job_id) WHERE processed=0 AND sess.client_id<>".$GLOBALS["test_client_id"]." AND sess.job_id<>".$GLOBALS["test_job_id"].";")) {
      echo "<li><u>Client</u>".str_repeat("&nbsp;", 10)."<u>Job</u>".str_repeat("&nbsp;", 15)."<u>Finish time</u>".str_repeat("&nbsp;", 9)."<u>Status</u></li>\n";
      foreach ($list as $sess) {
        echo "<li>$sess[0]".str_repeat("&nbsp;", 16-strlen($sess[0])).$sess[1].str_repeat("&nbsp;", 18-strlen($sess[1])).$sess[2]." ".ELevel($sess[3])."</li>\n";
      }
    } else {
      echo "<small>No unprocessed session</small><br>\n";
    }
    echo "</ul>";
?>

  <small><a href="?processed=1<?
                                if (isset($_GET["testy"])) {
                                  echo "&testy=".$_GET["testy"];
                                }
                                if(isset($d)) {
                                  echo "&date=$d";
                                }
                              ?>">Hide unprocessed sessions</a></small><br>

<?
  else:
?>

  <small><a href="?processed=0<?
                                if (isset($_GET["testy"])) {
                                  echo "&testy=".$_GET["testy"];
                                }
                                if(isset($d)) {
                                  echo "&date=$d";
                                }
                              ?>">Show unprocessed sessions</a></small><br>
  
<?
  endif;
  if (isset($_GET["testy"])&&$_GET["testy"]==1):
    echo "<h2>Test sessions</h2>\n";
    echo "<ul class=\"no_dec\">\n";
    if ($list = Query("SELECT client.name,job.job,finished,status FROM sess LEFT JOIN (client,job) ON (client.id=sess.client_id AND job.id=sess.job_id) WHERE processed=0 AND sess.client_id=".$GLOBALS["test_client_id"]." AND sess.job_id=".$GLOBALS["test_job_id"].";")) {
      echo "<li><u>Client</u>".str_repeat("&nbsp;", 10)."<u>Job</u>".str_repeat("&nbsp;", 15)."<u>Finish time</u>".str_repeat("&nbsp;", 9)."<u>Status</u></li>\n";
      foreach ($list as $sess) {
        echo "<li>$sess[0]".str_repeat("&nbsp;", 16-strlen($sess[0])).$sess[1].str_repeat("&nbsp;", 18-strlen($sess[1])).$sess[2]." ".ELevel($sess[3])."</li>\n";
      }
    } else {
      echo "<small>No test session</small><br>\n";      
    }
    echo "</ul>";
?>

  <small><a href="?testy=0<?
                            if (isset($_GET["processed"])) {
                              echo "&processed=".$_GET["processed"];
                            }
                            if(isset($d)) {
                              echo "&date=$d";
                            }
                          ?>"><? echo sayifadmin("Hide test sessions",0) ?></a></small><br>

<?
  else:
?>

  <small><a href="?testy=1<?
                            if (isset($_GET["processed"])) {
                              echo "&processed=".$_GET["processed"];
                            }
                            if(isset($d)) {
                            echo "&date=$d";
                            }
                          ?>"><? echo sayifadmin("Show test sessions",0) ?></a></small><br>

<?
  endif;
?>

</body>
</html>
Return current item: RepMan