Location: PHPKode > projects > phpMyPrepaid > phpmyprepaid/www/include/ap/show_users.php
<?php
/*     This file is used to display all cards that have been created
	It is expected that in production, this feature will be rather
	useless because of the number of accounts that will build up
	over time.  Some sort of method for clearing old accounts will
	need to be implemented.  For now, AllCards is the first step
	in building a reporting system.

	This file C. Carl H. Peterson 2004 and released under the GPL.
	If you didn't get a copy of the GPL with this, do a search for
	GPL and find it your self.  Remember, I copyrighted this so if
	you are using it you better have a license to use it.  GPl 
	works for me.
*/
//////////////////////////////////////////////////////////
//	THIS SCRIPT DISPLAYS ACCOUNTS FOR A LOCATION	//
//	First we pull the session location ID and then	//
//	use it to pull the correct cards.  		//
//	we use the button ID to figure out which type	//
//	of cards we want to pull			//
//////////////////////////////////////////////////////////
if(isset($msg)){ unset($msg);}

if(isset($_SESSION['locID'])){
  $loc = $_SESSION['locID'];
}
$LocName = $_SESSION['LocName'];
$div=1;
if(!isset($buttonID)) {
  $msg= "$msg <p class=\"error\">No button ID was sent</p>"; // this shouldn't happen
}

if(!isset($msg)){  // no errors? ...  hit it.  Need to reset button id

 if (isset($_POST['userdeleteap']))

 
	if(isset($_GET['s'])) { $s=$_GET['s']; }
	if(isset($_GET['so'])) { $so = $_GET['so']; }

	// Default to sorting by UserName else set to previous
	if(!isset($so)) { $sort = "UserName"; } else { $sort=$so; }

	// Change the sort order if the user selected a column heading
	if(isset($_POST['FirstName'])) { $sort = 'FirstName';}
	if(isset($_POST['LastName']))  { $sort = 'LastName';}
	if(isset($_POST['used']))      { $sort = 'TotalSessionTime';}
	if(isset($_POST['CrDate']))    { $sort = 'CrDate'; }
	if(isset($_POST['Type']))    { $sort = 'Type'; }
	if(isset($_POST['UserName']))  { $sort = 'UserName'; } // all this needs to be fixed

	// Update current sort order
	$so = $sort;


  if (!isset($_POST['actionf'])) $actionf="";
  else
    $actionf=$_POST['actionf'];
	
  if ($actionf =="find_account")				
    $username=$_POST['findAccountName'];
   
  echo "<hr>All Accounts listed for nas $dnsname<br><br> ";
  echo('<form action="phpmyprepaid.php" name="allcards" method="post">');
  echo ('<table>');		
  echo('<tr>');
  echo ('<td class="fieldcell" style="text-align: left">');
if (isset($username))
	echo "<input type=text size=17 class=text value=\"$username\" name=\"findAccountName\">";
else
  echo "<input type=text size=17 class=text value=\"\" name=\"findAccountName\">";
  echo ('</td>');
 echo (' <td style="height: 33px; width: 33px;"><input class="image" name="FindAccount"
    alt="Find account" title="Find account"
     src="images/search.png" value="" height="25"
      type="image" width="25"></td>');
  echo("<input type=\"hidden\" name=\"buttonID\" value='$buttonID'>");
	echo("<input type=\"hidden\" name=\"APID\" value=\"$apid\">");
	echo('<input type="hidden" name="LocationID" value='.$locid.'>');
  echo("<input type=\"hidden\" name=\"actionf\" value=\"find_account\"></tr>");
  echo "</table>";
  echo '</form><br>';
			
  if(!isset($so)) { $sort = "UserName"; }
  if(isset($_POST['UserName'])) { $sort = 'UserName';}            // all this needs to be fixed
  if(isset($_POST['BillingPlan'])) { $sort = 'BillingPlan';}
  if(isset($_POST['SessionTime'])) { $sort = 'AcctSessionTime';}
  if(isset($_POST['CrDate'])) { $sort = 'CrDate';}
  if(isset($_POST['activeDate'])) { $sort = 'activeDate';}
  if(isset($_POST['Type'])) { $sort = 'Type';}
  if(isset($_POST['TotalSessionTime'])) { $sort = 'TotalSessionTime';}
  //	if(!isset($so)) { $sort = "UserName"; }
  $order = 'ORDER by ';
  $groupby=' GROUP BY userinfo.UserName';	
  if(isset($_POST['limit'])) { $limit = $_POST['limit']; }else{ $limit = 10; } // <-- Hook for later feature

  //	if(isset($addcr)) { $cr = ', CrDate'; }else{ $cr = NULL; }

 
  if (isset($username) and $username!='')
    $q1 = "SELECT userinfo.ID,userinfo.UserName,Type, BillingPlan, LastName, CrDate,activeDate FROM userinfo,radcheck WHERE userinfo.UserName=radcheck.UserName AND Attribute='NAS-Identifier' AND Value='$nasval' AND LocationID='$loc' AND userinfo.Username REGEXP ('$username')   $groupby ORDER BY $sort "; // get all
  else
	  $q1 = "SELECT userinfo.ID,userinfo.UserName,Type, BillingPlan, LastName, CrDate,activeDate FROM userinfo 
	  userinfo,radcheck WHERE userinfo.UserName=radcheck.UserName AND Attribute='NAS-Identifier' AND Value='$nasval' AND LocationID='$loc'  $groupby ORDER BY $sort "; // get all
   
if ($debug) echo " DISPLAY ".$q1;
  if (empty($s)) {  // <---- Requires the weird non functional echo above FIXME
    $s=0;             // <---- I think an if(!isset($s) might work if we pull the GET
  }

  $result1 = $oreon->database->database->query($q1) or die("Query database error !");
  $numrows=$oreon->database->database->result_num_rows($result1);
  $q1 .= " LIMIT $s,$limit";

  echo "<table border=\"1\" width=\"680\" >";
  echo"<tr>";
  
  echo "<td>";

  printf('<form action="phpmyprepaid.php "method="post">');
  printf("<input type=\"hidden\" name=\"buttonID\" value=\"$buttonID\">");
  printf("<input type=\"hidden\" name=\"so\" value=\"$so\">");
  printf("<input type=\"hidden\" name=\"s\" value=\"$s\">");
  echo("<input type=\"hidden\" name=\"APID\" value=\"$apid\">");
  echo('<input type="hidden" name="LocationID" value='.$locid.'>');
  printf('<input type="submit" name="UserName" class="smallButton" value=" Username "/>');
  printf('</form>');
  echo "</td>";
  echo "<td width=\"40\">";
  printf('<form action="phpmyprepaid.php "method="post">');
  printf("<input type=\"hidden\" name=\"buttonID\" value=\"$buttonID\">");
  printf("<input type=\"hidden\" name=\"so\" value=\"$so\">");
  printf("<input type=\"hidden\" name=\"s\" value=\"$s\">");
  echo("<input type=\"hidden\" name=\"APID\" value=\"$apid\">");
  echo('<input type="hidden" name="LocationID" value='.$locid.'>');
  printf('<input type="submit" name="BillingPlan" class="smallButton" value="Billing Plan"/>');
  printf('</form>');
  echo "</td>";
 // echo "<td width=40>";
  //REMOVED NOT USEFUL
 // printf('<form action="phpmyprepaid.php "method="post">');
 // printf("<input type=\"hidden\" name=\"buttonID\" value=\"$buttonID\">");
 // printf("<input type=\"hidden\" name=\"so\" value=\"$so\">");
 // printf("<input type=\"hidden\" name=\"s\" value=\"$s\">");
 // printf('<input type="submit" name="LastName" class="button" value="Last Name"/>');
 // printf('</form>');
 // echo "</td>";
 
  echo "<td width=\"150\">";
  printf('<form action="phpmyprepaid.php "method="post">');
  printf("<input type=\"hidden\" name=\"buttonID\" value=\"$buttonID\">");
  printf("<input type=\"hidden\" name=\"so\" value=\"Type\">");
  printf("<input type=\"hidden\" name=\"s\" value=\"$s\">");
  echo("<input type=\"hidden\" name=\"APID\" value=\"$apid\">");
  echo('<input type="hidden" name="LocationID" value='.$locid.'>');
  printf('<input type="submit" name="Value" class="smallButton" value="Type"/>');
  printf('</form>');
  echo "</td>";
	
  echo "<td width=\"150\">";
  //printf('<form action="phpmyprepaid.php "method="post">');
  printf("<input type=\"hidden\" name=\"buttonID\" value=\"$buttonID\">");
  printf("<input type=\"hidden\" name=\"so\" value=\"TotalSessionTime\">");
  echo("<input type=\"hidden\" name=\"APID\" value=\"$apid\">");
  echo('<input type="hidden" name="LocationID" value='.$locid.'>');
  printf("<input type=\"hidden\" name=\"s\" value=\"$s\">");
  printf('<input type="submit" name="TotalSessionTime" class="smallButton" value="Used"/>');
  //printf('</form>');
  echo "</td>";
		
  echo "<td width=\"40\">";
  printf('<form action="phpmyprepaid.php "method="post">');
  printf("<input type=\"hidden\" name=\"buttonID\" value=\"$buttonID\">");
  printf("<input type=\"hidden\" name=\"so\" value=\"activateDate\">");
  echo("<input type=\"hidden\" name=\"APID\" value=\"$apid\">");
  echo('<input type="hidden" name="LocationID" value='.$locid.'>');
  printf("<input type=\"hidden\" name=\"s\" value=\"$s\">");
  printf('<input type="submit" name="activeDate" class="smallButton" value="Activate Date    "/>');
  printf('</form>');
  echo "</td>";
 echo "<td width=\"5\"></td>";
  echo "</tr>";

  $result1 = $oreon->database->database->query($q1) or die("Query database error !");
  $count = 1 + $s; // <-- sets the page number
  if(isset($_POST['ID'])) { $pullUser=$_POST['ID'];
  unset($_POST['ID']);}

  while ($row = $oreon->database->database->fetch_object($result1)) {
    if(!isset($shade)) { $shade = 2;}
    $array[] = $row; 
    $ID = ($row->ID);
    
    $usernametmp = ($row->UserName);
   $type=$row->Type;	     
    $BillingPlan=get_plan_name(($row->BillingPlan));
    //$LastName=($row->LastName);
    $CrDate=($row->CrDate);
    $Value=round(($row->Value));
    $activeDate=($row->activeDate);
    //	$sec = $row->Value;
    //	$min = ($sec /60);
    //	if($addcr == 1) { $date = ($row->CrDate); } // <--See conf file
    echo("<tr>");
    	
    $q2 = "SELECT SUM(AcctSessionTime) as TotalSessionTime,SUM($acctoutputoctetsattr) AS sum_output FROM radacct WHERE UserName='$usernametmp'"; 
    $numresults2=$oreon->database->database->query($q2);  // <------ FIGURE OUT HOW MANY RESULTS WE ARE PULLING
    $numrows2=$oreon->database->database->result_num_rows($numresults2);
    $res2 = $oreon->database->database->query($q2) or die("Query database error !");
    $r2 = $oreon->database->database->fetch_object($res2);
    
    if ($type=="Octets" or $type=="Subscription Octets")
    $used = round($r2->sum_output);
    else
    $used = round($r2->TotalSessionTime);

    if ($used=='') $used='0';

    if($shade == 1) { echo('<td STYLE="background-color: #F2F7FB">'); }
    else{ echo('<td STYLE="background-color: #cde5f4">'); }
     printf("<form  action=\"include/divers/sexyTabs.php\" target=\"_blank\" method=\"post\" >");

    echo("<input type=\"hidden\" name=\"ID\" value=\"$usernametmp\">");
    echo("<input type=\"hidden\" name=\"phpmyprepaid\" value=\"".session_id()."\">");
			
    echo("<input type=\"submit\" class=\"smallButton\" name=\"UserSelected\" value=\"$usernametmp\">");
    echo('</form>');
    echo("</td><small>");
							 
			
    if($shade == 1) { echo('<td STYLE="background-color: #F2F7FB"><small>'); }
    else{ echo('<td STYLE="background-color: #cde5f4"><small>'); }
    echo($BillingPlan);
    echo("</td>");

    //if($shade == 1) { echo('<td STYLE="background-color: #F2F7FB"><small>'); }
    //else{ echo('<td STYLE="background-color: #cde5f4"><small>'); }
    //echo($LastName);
   //echo("</td>");
    
    if ($type=="Subscription Expiration") {
      $Value=date_from_attribute($row->Value,$dateFormat);
      if($shade == 1) { echo('<td STYLE="background-color: #F2F7FB"><small>'); }
      else{ echo('<td STYLE="background-color: #cde5f4"><small>'); }
    }
    else {
      if($shade == 1) { echo('<td STYLE="background-color: #F2F7FB"><small>'); }
       else{ echo('<td STYLE="background-color: #cde5f4" ><small>'); }
      }
    echo $type;
    if($shade == 1) { echo('<td STYLE="background-color: #F2F7FB"><small>'); }
    else{ echo('<td STYLE="background-color: #cde5f4" ><small>'); }
    if ($type=="Hourly" or $type=="Subscription Time") 
        $used=time2str($used);
    else if ($type=="Octets" or $type=="Subscription Octets")
       $used=octets2str($used);
    else 
       $used=time2str($used);
    echo "<small>";
    echo($used);
    echo "</small>";
    echo("</td>");


    if($shade == 1) { echo('<td STYLE="background-color: #F2F7FB"><small>'); }
    else{ echo('<td STYLE="background-color: #cde5f4"><small>'); }
    //echo($activeDate);
    echo "<small>";
    echo date_from_attribute($activeDate,$dateFormat);
    echo "</small>";
    echo("</td>");

    echo "<td >";
    echo '<script type="text/javascript">  
			function confirmDelete() { 
	        if(confirm("Are you sure, you want to delete this user ?" )) document.location.href = phpmyprepaid.php;
	          return false; //pour ne pas revenir au début de la page
          	}  
    </script>
    <form action="phpmyprepaid.php" onsubmit="return confirmDelete();" method="post">';  
    printf("<input type=\"hidden\" name=\"buttonID\" value=\"$buttonID\">");
    printf("<input type=\"hidden\" name=\"userdelete\" value=\"$usernametmp\">");
    printf('<input class="image" type="image" class="tdimage" value="submit" name="delete" alt="Delete user" title="Delete user" src="images/delete.png" >');
    printf('</form>');
    echo "</td>";


  
    echo("</tr>");
    if(isset($pullUser)&&$pullUser==$usernametmp){
      //	pullUser($pulluser);
      include('include/divers/pullUser.php');
      include('include/divers/include/divers/sexyTabs.php');
      echo('<tr>');
      echo('<td colspan = 5>');
      echo('</td>');
      echo('</tr>');
      unset($pullUser);
    }
    $count++ ; // <--- adds 0ne to the page number
    if($shade == 2) { $shade = 1; }else{ $shade = 2;}

  
  }
  $currPage = (($s/$limit) + 1);
  
  echo "</table><br>";
  
  //////////////////////////////////////////////////////////////////
  //      SET UP THE REST OF THE RESULTS PAGES                    //
  //   Some of this code once came from an online tutorial        //
  //   I used when I was building a website.  I will find         //
  //   The author later or re-write.  CP                          //
  //////////////////////////////////////////////////////////////////
  if ($s>=1) { // <---- Don't need a back button if this is the first page
    $prevs=($s-$limit);
    print "&nbsp;<a href=\"phpmyprepaid.php?&so=$sort&s=$prevs&buttonID=$buttonID&actionf=$actionf&username=$username\"><img src=\"images/leftarrow.png\" title=\"Previous $limit\"></a>";
    
  }
  
    $pages=intval($numrows/$limit); // <--This figures out how many pages we have
    // $pages now contains int of pages needed unless there is a remainder from division
    if ($numrows%$limit) {
      // has remainder so add one page
      $pages++;
    }
    // check to see if last page
    if ( ($pages!=0) && !((($s+$limit)/$limit)==$pages) && $pages!=1) {
      
      // not last page so give NEXT link
      $next=$s+$limit;
      
      echo "&nbsp;<a href=\"phpmyprepaid.php?&so=$sort&s=$next&buttonID=$buttonID&actionf=$actionf&username=$username\"><img src=\"images/rightarrow.png\" title=\"Next $limit\"></a>";
    }
    
    $a = $s + ($limit) ;
    if ($a > $numrows) { $a = $numrows ; }
    if ($numrows ==0){
      $b=0;
      echo "<p> No result to display.</p>";
      }
      else
      {
       $b = $s + 1 ;
       echo "<p>Showing results $b to $a of $numrows</p>";
      } 
}else{
  echo($msg);
}

?>		















		     
Return current item: phpMyPrepaid