Location: PHPKode > projects > phpMyPrepaid > phpmyprepaid/www/include/users/managelocation.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.
  */
if ($buttonID=="add_user_loc" and !isset($_GET['su'])) {
	$idloc=$_POST['aul_loc_id'];
	$iduser=$_POST['aul_user_id'];
	$idstatus=$_POST['aul_status_id'];
	$q1="INSERT INTO user_location(userid,locationid,statusid) VALUES('$iduser','$idloc','$idstatus')";
	$oreon->database->database->query ($q1) or die("Query database error !");
	$msg="<p class=\"information\"> Successfull add user location</p>";
}

if ($buttonID=="del_user_loc" and !isset($_GET['su'])) {
	$idloc=$_POST['dul_loc_id'];
	$iduser=$_POST['dul_user_id'];
if (!is_last_location($iduser)) {
	$q1="DELETE From user_location Where userid='". $iduser ."' AND locationid='".$idloc."'";
	$oreon->database->database->query ($q1) or die("Query database error !");
	$msg="<p class=\"information\"> Successfull del user location</p>";
}else
	$msg="<p class=\"error\"> Only one location left for this user !</p>";


}

if ($buttonID=="mod_user_loc" and !isset($_GET['su'])) {
	$result1=get_user_by_location($oreon->user);

	if (!$result1) {
		$_SESSION['error']='Invalid request : ' . "Query database error !";
		echo "<script Language=\"JavaScript\"> window.location.href='".$_SERVER['HTTP_REFERER']."';</script>";
		return;
	}
	
	$numrows=$oreon->database->database->result_num_rows($result1);
	if ($numrows == 0) 
	{
		$_SESSION['error']=" No user found, please create one  !";
		echo "<script Language=\"JavaScript\"> window.location.href='".$_SERVER['HTTP_REFERER']."';</script>";
		return;
	}
	
	echo '<table border="2">';
	echo"<tr>";
	
	echo "<td class=\"bpcell\" width=180>";
	echo "<b>Alias</b>";
	echo "</td>";
	echo "<td class=\"bpcell\" width=180>";
	echo "<b>Fistname</b>";
	echo "</td>";
	echo "<td class=\"bpcell\" width=180>";
	echo "<b>Lastname</b>";
	echo "</td>";
	echo "</tr>";
	
	printf('<form  name="center"  action="phpmyprepaid.php" method="post">');
	
	while ($row = $oreon->database->database->fetch_object($result1)) {
		if(!isset($shade)) { $shade = 2;}
		$array[] = $row;
		
		$user=$oreon->database->getUser($row->userid);
		$Id= $user['user_id'];
		$alias= $user['user_alias'];
		$lastname=$user['user_lastname'];
		$firstname=$user['user_firstname'];
		echo("<tr>");
		
		if($shade == 1) { echo('<td STYLE="background-color: #F2F7FB">'); }
		else{ echo('<td STYLE="background-color: #cde5f4">'); }
		printf('<input type="radio" name="modUserLoc" value="%s" %s/> %s<br />',
			$Id,
			(isset($_REQUEST['modUser']) and $_REQUEST['modUser'] == $alias) ? 'checked="checked" ' : '',
			$alias);
		echo("</td>");
		if($shade == 1) { echo('<td STYLE="background-color: #F2F7FB">'); }
		else{ echo('<td STYLE="background-color: #cde5f4">'); }
		echo $lastname;
		echo("</td>");
		if($shade == 1) { echo('<td STYLE="background-color: #F2F7FB">'); }
		else{ echo('<td STYLE="background-color: #cde5f4">'); }
		echo $firstname;
		echo("</td></tr>");
		$count++ ; // <--- adds 0ne to the page number
		if($shade == 1) { $shade = 2;}else{ $shade = 1; }
	}
	
	echo "</table>";
	
	echo('<input type="hidden" name="buttonID" value="mod_user_loc_form">');
	echo "<br>";
	echo ('<td align="right"><tr>');
	echo ("<input type=\"submit\" name=\"submit\" class=\"smallButton\" value=\"Manage user location \"/>");
	echo ('</td></tr>');
	echo '</form>';
	
	echo "<br>";
}
else {
	printf('<form  name="center"  action="phpmyprepaid.php" method="post">');
	echo '<script type="text/javascript">  
		function changeLocation(formulaire) { 
			document.location.href="phpmyprepaid.php?su="+formulaire.aul_loc_id.value+"&&ui="+formulaire.user_id.value;
	}  
    </script>';
	if (isset($_POST['modUserLoc']) or isset($_POST['aul_user_id']) or isset($_GET['su'])) {
		if (isset($_POST['modUserLoc']))
			$user=$oreon->users[$_POST['modUserLoc']];
		else if (isset($_POST['aul_user_id']))
			$user=$oreon->users[$_POST['aul_user_id']];
		else 
			$user=$oreon->users[$_GET['ui']];


		if (isset($_GET['su'])) 
			$loc=$_GET['su'];
		else
			$loc=getLocationUser($user->get_id());
	
		$result = getLocationName($user);
		$status=get_user_status_location($user,$loc);
		
		echo "<p class=\"information\"><small>All location available for user ".$user->get_alias()." ";
		echo('<select id="aul_loc_id" name="aul_loc_id" onchange="changeLocation(this.form)">');
		
		while ($row = $oreon->database->database->fetch_object($result))
			if ($loc==$row->ID) 
				echo ("<option id=\"aul_loc_id\" selected=\"selected\" value=\"".$row->ID."\">".$row->LocationName."</option>");
			else
				echo ("<option id=\"aul_loc_id\" value=\"".$row->ID."\">".$row->LocationName."</option>");

		
		echo('</select>');
		echo " as ";
		$su=$status;
		if ($su=='1')
			echo "User";
		if ($su=='2')
			echo "Administrator";
		if ($su=='3')
			echo "Super Administrator";
		
		echo("<input type=\"hidden\" name=\"user_id\" value=\"".$user->get_id()."\">");
		echo '<hr><br></form>';

		//ADD USER LOCATION AND STATUS
		printf('<form  name="center"  action="phpmyprepaid.php" method="post">');

		
		echo '
			
			<table style="text-align: left; width: 100%;" border="0"
			cellpadding="2" cellspacing="2">
			<tbody>
			<tr>
			<td style="width: 198px;">Add location<br>
			</td>
			<td>';
		$result = get_location_exclude($oreon->user,$user);
		$loc=getLocationUser($user->get_id());
		
		$numrows=$oreon->database->database->result_num_rows($result);
		echo('<select name="aul_loc_id">');
		while ($row = $oreon->database->database->fetch_object($result)){
			if ($loc==$row->ID) 
				echo ("<option selected=\"selected\" value=\"".$row->ID."\">".$row->LocationName."</option>");
			else
				echo ("<option  value=\"".$row->ID."\">".$row->LocationName."</option>");
		}
		echo '</select>
			</td>
			<td style="width: 167px;">
			<select name="aul_status_id">';
      if ($oreon->user->get_status()>='1')
      echo "<option value='1'>".$lang['u_user']."</option>";
      if ($oreon->user->get_status()>='2')
      echo "<option value='2'>".$lang['u_administrator']."</option>";
      if ($oreon->user->get_status()>='3')
      echo "<option value='3'>".$lang['u_sadministrator']."</option>";
      echo '</select></td>';
      
      echo "<td>";
      echo("<input type=\"hidden\" name=\"aul_user_id\" value=\"".$user->get_id()."\">");
      echo("<input type=\"hidden\" name=\"buttonID\" value=\"add_user_loc\">");
      printf('<input type="image" value="submit" class="image" name="submit" alt="Add location to this user" title="Add location to this user" src="images/insert.png">');
      printf('</form>');

      // DELETE USER LOCATION
      printf('<form  name="center"  action="phpmyprepaid.php" method="post" onsubmit="return confirmDelete();">');
		echo "</td>";
      echo '<tr>
			<td style="width: 198px;"></td>
			<td></td>
			<td style="width: 167px;"></td>
			<td style="width: 334px;"></td>
			</tr>
			<tr><hr>
			<td style="width: 198px;">Remove user location</td>
			<td>';
		$result = getLocationName($user);
		$loc=getLocationUser($user->get_id());
		echo('<select name="dul_loc_id">');
		while ($row = $oreon->database->database->fetch_object($result))
			if ($loc==$row->ID) 
				echo ("<option selected=\"selected\" value=\"".$row->ID."\">".$row->LocationName."</option>");
			else
				echo ("<option  value=\"".$row->ID."\">".$row->LocationName."</option>");
		
		echo('</select>');
		echo '</td>';
		
		echo '<td><script type="text/javascript">  
			function confirmDelete() { 
	        if(confirm("Are you sure, you want to delete this location for this user ?" )) document.location.href = phpmyprepaid.php;
		return false; //pour ne pas revenir au début de la page
	}  
    </script>';
	printf("<input type=\"hidden\" name=\"buttonID\" value=\"del_user_loc\">");
        printf("<input type=\"hidden\" name=\"dul_user_id\" value=\"".$user->get_id()."\">");
	printf('<input type="image" value="submit" class="image" name="submit" alt="Delete location" title="Delete user location" src="images/delete.png">');
	printf('</form>');
	echo "</td>";
	echo '</tr>
		</tbody>
		</table>';
	}
}
?>
Return current item: phpMyPrepaid