<? 
require_once "include/application.php"; 
require_once "include/paginator.php";
require_once "include/paginator_html.php";
require_once "include/function.php";
require_once "include/newvalue_lib.php";

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="sddm.css" >
<script src="include/validation.js" type="text/javascript"></script>
<title><? echo TITLE?></title>
</head>
<body>

<table width="1024" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#f1efd8">
  <tr>
    <td  colspan="2" align="center"><? require_once "include/header.php"; ?></td>
  </tr>
  <tr>
    <td colspan="2" align="center">&nbsp;</td>
  </tr>
  <tr>
    <td width="185" valign="top" bgcolor="e6f3f9">
	
<? require_once "include/columnLeft.php"; ?>	</td>
    <td width="834" valign="top">
	<form name="form" method="post" action="<?=$PHP_SELF ?>" >
	  <table width="810" border="0" align="center" cellpadding="0" cellspacing="0">
      
      <tr>

        <td valign="top"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="100%" height="30" class="TitleH3">Person Search </td>
          </tr>
          <tr>
            <td height="1" bgcolor="#B8ED83"></td>
          </tr>
          <tr>
            <td ><? echo "<div class='Msg'>$action_msg</div>" ?>&nbsp;
              <input name="ty" type="hidden" id="ty" value="<? echo $ty ?>" /></td>
          </tr>

        </table>
          <table border="0" cellpadding="1" width="100%" cellspacing="2" class="small">
            <tr>
              <td height="7" colspan="9" class="text12"><span class="TextH1">
                <select name="sType" id="sType">
                  <option value="Name">Name</option>
                  <option value="Job">Job Title</option>
                </select>
                <input name="sReferral" type="text" id="sReferral" value="<? echo $sReferral ?>" />
                Role
                <select name="role" id="role" >
                  <option value=""></option>
                  <?
			 
			 	$sql="select * from newvalue where nv_type='Role' order by nv_id";
				$result=mysql_query($sql) or die(mysql_error());				
				while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC)){
					echo "<option value='".$myrow["nv_id"]."' ";
					if($role==$myrow["nv_id"])echo "selected";
					echo ">".$myrow["nv_name"]." </option>";
				}
			
?>
                </select>
                <? stayfocus("form","sType",$sType) ?>
                Type
                <select name="type" id="type" >
                  <option value=""></option>
                  <?
						 for($i=0;$i<count($tl); $i++)
						 {
							echo "<option value='".$tl[$i]."' ";
							if($type==$tl[$i])echo "selected";
							echo ">".$nv[$tl[$i]]." </option>";
						 }
			
?>
                </select>
              </span></td>
            </tr>
            <tr>
              <td height="7" colspan="9" class="TextH1">Source
                <select name="source" id="source">
                        <option value=""></option>
                   <?
			 
			 	$sql="select * from newvalue where nv_type='Source' order by nv_id";
				$result=mysql_query($sql) or die(mysql_error());				
				while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC)){
					echo "<option value='".$myrow["nv_id"]."' ";
					if($source==$myrow["nv_id"])echo "selected";
					echo ">".$myrow["nv_name"]." </option>";
				}
			
?>
                 </select>
                 
				 Country 
				 <select name="country" id="country">
						<option value=""></option>
						                <? require "country.inc"; ?>
					</select>
										                <? stayfocus("form","country",$country) ?> 

					User
	                <select name="user" id="user" >
                    <?
						 if(count($ugrp) > 1)
							echo "<option value='all'>All</option>";

						 
						 for($i=0;$i<count($ugrp); $i++)
						 {
						 
							echo "<option value='".$ugrp[$i]."' ";
							if($user==$ugrp[$i])echo "selected";
							echo ">".$ugrp[$i]." </option>";
						 }

?>														
                    </select>
	                <span class="text12">
                 <input name="btnSearch" type="submit" class="btn" id="btnSearch" value="Search"/>
                 </span></td>
            </tr>
            <tr>
              <td height="17" colspan="9" class="text12"><input type="button" name="btnAdd" value="Add New Person" class="btn150" onclick="location.href='ppl_newPerson.php'"/>
			<? if($pm){ ?>
				<img src="images/trash_can.png" alt="Remove pin from menu" width="30" height="30" onclick="removepinmenu('<? echo $pm ?>')"/>
			<? }else{ ?>	
				<img src="images/pin.png" alt="Pin to menu" width="30" height="30" onclick="pintomenu('person')"/>
			<? } ?>	
                <input name="pm" type="hidden" id="pm" value="<? echo $pm ?>" />				</td>
            </tr>
            <tr>
              <td width="255" height="23" background="images/tab-btns.gif" class="TextH1"><div align="center">Name</div></td>
              <td width="161" background="images/tab-btns.gif" class="TextH1"><div align="center">Type</div></td>
              <td width="151" background="images/tab-btns.gif" class="TextH1"><div align="center">Source</div></td>
              <td width="71" background="images/tab-btns.gif" class="TextH1"><div align="center">Active</div></td>
              <td width="70" background="images/tab-btns.gif" class="TextH1"><div align="center">User</div></td>
              <td width="49" background="images/tab-btns.gif">&nbsp;</td>
            </tr>
            <?
	if(!$user){
		if(count($ugrp) > 1)$user="all";
		else $user=$_SESSION["egoUser"];		
	}	

	$sql="select p_id,p_name,p_user,p_type,p_dob,p_source,p_active from person where ";
	if($user=="all")$sql.="p_user IN ('".implode("','",$ugrp)."') ";
	else $sql.="p_user='$user' ";
		

	if($sReferral){
		if($sType=="Name")$sql.=" and p_name like '%$sReferral%'";			
		else if($sType=="Job")$sql.=" and p_job like '%$sReferral%'";				
	}	
	if($role)$sql.=" and p_role='$role'";
	if($type)$sql.=" and FIND_IN_SET('$type',p_type)<>'0'";
	if($source)$sql.=" and p_source='$source'";
	if($country)$sql.=" and p_country='$country'";
//	if($user)$sql.=" and p_user='$user'";
	$result=mysql_query($sql);
	$num_rows=mysql_num_rows($result);
	
	$pass="so=1&sReferral=$sReferral&sType=$sType&role=$role&type=$type&source=$source&country=$country&user=$user";
    $a =& new Paginator_html($_GET['page'],$num_rows,$pass);	
	$a->set_Limit(15);
	$a->set_Links(10);  	
	$limit1 = $a->getRange1();  
	$limit2 = $a->getRange2();  
	$sql.=" order by p_name limit $limit1,$limit2 ";	
	$result=mysql_query($sql) or die(mysql_error());

	while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC))
	{
		echo "<tr bgcolor='#ffffff' class='TextH1'>"; 
		$id=$myrow["p_id"];
	    echo "<td height='20' align='center' class='text12'>".$myrow["p_name"]."</td>";	  				

		$ty=split(",",$myrow["p_type"]);
		$str="";
		for($i=0;$i<count($ty);$i++){
			if(!$str)$str=$nv[$ty[$i]];
			else $str.=", ".$nv[$ty[$i]];
		}

	    echo "<td align='center' class='text12'>$str</td>";	  
	    echo "<td height='20' align='center' class='text12'>".$nv[$myrow["p_source"]]."</td>";	  						
		if($myrow["p_active"]=="Yes")echo "<td align='center' class='text12'>Yes</td>";	  
		else echo "<td align='center' class='text12'>No</td>";	  
	    echo "<td align='center' class='text12'>".$myrow["p_user"]."</td>";	  
		echo "<td align='center' class='text12'><a href='ppl_newPersonEdit.php?id=$id'><img src='images/view.jpg' border='0'></a>";
		echo "</td>";	  								
		echo "</tr>";

	}

?>
            <tr>
              <td colspan="9" class="TextH2"><? echo "Total Record :[".$num_rows."] "; if($num_rows)$a->previousNext();?></td>
            </tr>
          </table></td>

      </tr>
 
    </table>
	  <br />
	</form>	</td>
  </tr>
  <tr>
    <td colspan="2" bgcolor="#333333"><div align="center"><span class="Footer">
      <br />
      <? require_once "footer.php"; ?>
    </span></div></td>
  </tr>
</table>
</body>
</html>
<?
if(array_search("People",$menulist)==false)
		print("<script type='text/javascript'>location.href='index.php'</script>");
?>