<?php require_once('../Connections/oprmConn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "create_client_form")) {
  $updateSQL = sprintf("UPDATE weby_clients SET client_name=%s, client_contact_name=%s, client_mail=%s, client_phone=%s, client_address=%s, status=%s, updated_by=%s WHERE client_id=%s",
                       GetSQLValueString($_POST['client_name'], "text"),
					    GetSQLValueString($_POST['client_contact_name'], "text"),
						 GetSQLValueString($_POST['client_mail'], "text"),
						  GetSQLValueString($_POST['client_phone'], "text"),
                       GetSQLValueString($_POST['client_address'], "text"),
                       GetSQLValueString($_POST['status'], "text"),
                       GetSQLValueString($_POST['created_by'], "int"),
                       GetSQLValueString($_POST['client_id'], "int"));

  mysql_select_db($database_oprmConn, $oprmConn);
  $Result1 = mysql_query($updateSQL, $oprmConn) or die(mysql_error());

  $updateGoTo = "client-list.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s&msg2", $updateGoTo));
}

$maxRows_getRes = 2;
$pageNum_getRes = 0;
if (isset($_GET['pageNum_getRes'])) {
  $pageNum_getRes = $_GET['pageNum_getRes'];
}
$startRow_getRes = $pageNum_getRes * $maxRows_getRes;

mysql_select_db($database_oprmConn, $oprmConn);
$query_getRes = "SELECT weby_users.user_id, weby_users.email_address, weby_users.caeated_date, weby_profiles.profile_id, weby_profiles.full_name, weby_profiles.job_title, weby_profiles.skill_set, weby_profiles.profile_pic FROM weby_users, weby_profiles WHERE weby_users.status = 'P' AND weby_profiles.user_id = weby_users.user_id";
$query_limit_getRes = sprintf("%s LIMIT %d, %d", $query_getRes, $startRow_getRes, $maxRows_getRes);
$getRes = mysql_query($query_limit_getRes, $oprmConn) or die(mysql_error());
$row_getRes = mysql_fetch_assoc($getRes);

if (isset($_GET['totalRows_getRes'])) {
  $totalRows_getRes = $_GET['totalRows_getRes'];
} else {
  $all_getRes = mysql_query($query_getRes);
  $totalRows_getRes = mysql_num_rows($all_getRes);
}
$totalPages_getRes = ceil($totalRows_getRes/$maxRows_getRes)-1;

$maxRows_getRes1 = 2;
$pageNum_getRes1 = 0;
if (isset($_GET['pageNum_getRes1'])) {
  $pageNum_getRes1 = $_GET['pageNum_getRes1'];
}
$startRow_getRes1 = $pageNum_getRes1 * $maxRows_getRes1;

mysql_select_db($database_oprmConn, $oprmConn);
//$query_getRes1 = "SELECT weby_users.user_id, weby_users.email_address, weby_users.caeated_date, profiles.profile_id, profiles.full_name, profiles.job_title, profiles.skill_set, profiles.profile_pic FROM weby_users, profiles WHERE weby_users.status = 'A' AND profiles.user_id = weby_users.user_id";
$query_getRes1 = "SELECT weby_users.user_id, weby_users.email_address, weby_users.caeated_date, weby_profiles.profile_id, weby_profiles.full_name, weby_profiles.job_title, weby_profiles.skill_set, weby_profiles.profile_pic FROM weby_users, weby_profiles WHERE weby_profiles.status = 'A' AND weby_users.status = 'A' AND weby_users.user_role <> 1 AND weby_profiles.user_id = weby_users.user_id order by weby_profiles.profile_id desc" ;
$query_limit_getRes1 = sprintf("%s LIMIT %d, %d", $query_getRes1, $startRow_getRes1, $maxRows_getRes1);
$getRes1 = mysql_query($query_limit_getRes1, $oprmConn) or die(mysql_error());
$row_getRes1 = mysql_fetch_assoc($getRes1);

if (isset($_GET['totalRows_getRes1'])) {
  $totalRows_getRes1 = $_GET['totalRows_getRes1'];
} else {
  $all_getRes1 = mysql_query($query_getRes1);
  $totalRows_getRes1 = mysql_num_rows($all_getRes1);
}
$totalPages_getRes1 = ceil($totalRows_getRes1/$maxRows_getRes1)-1;

mysql_select_db($database_oprmConn, $oprmConn);
$query_getProjDe = "SELECT * FROM weby_clients WHERE weby_clients.client_id = '$_REQUEST[clientid]'";
$getProjDe = mysql_query($query_getProjDe, $oprmConn) or die(mysql_error());
$row_getProjDe = mysql_fetch_assoc($getProjDe);
$totalRows_getProjDe = mysql_num_rows($getProjDe);


?>
<!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=utf-8" />
<link rel="stylesheet" href="../css/style.css" type="text/css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<!-- IE Fix for HTML5 Tags -->
<!--[if IE]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> 
<![endif]-->
<title>SS WEB TECHNOLOGIES- Admin Dash board</title>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<script src="../../js/jquery.flexslider.js"></script>
<script language="JavaScript">
function setVisibility(id, visibility) {
document.getElementById(id).style.display = visibility;
}
</script>
<style>
.act_client { background: #373938;
  color: #fff;}
  </style>
<script type="text/javascript">
<!--
//function MM_validateForm() { //v4.0
//  if (document.getElementById){
//    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
//    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
//      if (val) { nm=val.name; if ((val=val.value)!="") {
//        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
//          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
//        } else if (test!='R') { num = parseFloat(val);
//          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
//          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
//            min=test.substring(8,p); max=test.substring(p+1);
//            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
//      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
//    } if (errors) alert('The following error(s) occurred:\n'+errors);
//    document.MM_returnValue = (errors == '');
//} }
//-->


function validateForm() {

	
 

	var name = document.getElementById('client_name');
	if (name.value == "") {
        //message = message+"Name be filled out\n";
        alert("Client Name be filled out")
		return false
    }
	
	var cname = document.getElementById('client_contact_name');
	if (cname.value == "") {
        //message = message+"Name be filled out\n";
        alert("Client Manager Name be filled out")
		return false
    }
	var emailID=document.getElementById('clint_mail');
	
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}

var mobileno = document.getElementById('clint_phone');


var mob = /^[1-9]{1}[0-9]{9}$/;
	
	
	if (mobileno.value == "") {
  alert("You didn't enter a Mobile number.")
   mobileno.focus()
  return false
 }
  else if (isNaN(mobileno.value)) {
  alert("The Mobile number contains illegal characters.")
  mobileno.focus()
  return false
 }
 else if (!(mobileno.value.length == 10)) {
  alert("The Mobile number is the wrong length. \nPlease enter 10 digit mobile no.")
  mobileno.focus()
  return false
 }
 if (mob.test(mobileno.value) == false) {
        alert("Please enter valid mobile number.")
        mobileno.focus()
        return false
    }
   
var address = document.getElementById('clint_address').value;
	if (address == "") {
        //message = message+"Address be filled out\n";
		alert("Address be filled out")
       return false
    }	
}
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}
    </script>
    <script>
function cancel() {
  location.href = "client-list.php";
}
</script>
<style>
.act_client {
	background: #373938 !important;
	color: #fff !important;
}
</style>
</head>

<body>
<div id="wrapper">

    <?php  require_once('../includes/header.php'); ?>
    
<?php  require_once('../includes/tools-menu.php'); ?>
    <article class="project_edit_inside_wrapper clear_fix">
    <aside class="side_bar">
    	 
<?php /*?>   <div class="featured clear_fix">



            	<h2 class="white_txt">PENDING RESOURCES</h2>



                <?php if($totalRows_getRes>0) { do { ?>



                <div class="profile_box">



                    <a href="resources-view.php?user_id=<?php echo $row_getRes['user_id']; ?>"><img src="/RM/images/<?php if(!empty($row_getRes['profile_pic'])) echo $row_getRes['profile_pic']; else echo "black-img.jpg";?>" width="68" /></a>



                    <p class="profile_title"><a href="resources-view.php?user_id=<?php echo $row_getRes['user_id']; ?>"><?php echo $row_getRes['full_name']; ?></a><span class="desig"><br />



                    <?php echo $row_getRes['job_title']; ?></span></p>



                <p class="profile_desc"><?php echo $row_getRes['skill_set']; ?></p>



                  <div class="clear-fix">&nbsp;</div>



            </div>



          <?php } while ($row_getRes = mysql_fetch_assoc($getRes)); } else { echo "<div class='no-rows'>No Pending Resources</div>";}?></div>

<?php */?>

       	  <h2>ACTIVE RESOURCES</h2>



         <form action="resources-list.php" method="post" id="act_resource_search" class="act_resource_search">



         <input name="search" class="search" type="text" size="30" />



         <input name="submit" type="submit" class="search-sub" value="Search" />



         </form>



         



         



                <?php if($totalRows_getRes1>0) { do { ?>



                  <div class="profile_box">



                    <a href="resources-view.php?user_id=<?php echo $row_getRes1['user_id']; ?><?php ?>"><img src="/RM/images/<?php if(!empty($row_getRes1['profile_pic'])) echo $row_getRes1['profile_pic']; else echo "black-img.jpg";?>" width="68" /></a>



                    <p class="profile_title"><a href="resources-view.php?user_id=<?php echo $row_getRes1['user_id']; ?>"><?php echo $row_getRes1['full_name']; ?></a><span class="desig"><br />



                    <?php echo $row_getRes1['job_title']; ?></span></p>



                  <p class="profile_desc"><?php echo $row_getRes1['skill_set']; ?></p>



                    <div class="clear-fix">&nbsp;</div>



                        </div>



                  <?php } while ($row_getRes1 = mysql_fetch_assoc($getRes1)); } else { echo "<div>No Active Resources</div>";} ?>



                  



                  <!-- <div class="profile_box"> <a href="resources-view.php?user_id=1234"><img src="/RM/images/black-img.jpg" /></a>



                    <p class="profile_title"><a href="resources-view.php?user_id=1234">David Masciana</a><span class="desig"><br />



				  IT Business Analyst</span></p>



                    <p class="profile_desc">Cisco IP knowledge is preferred to Cisco CCNA/Juniper JNCIA and similar level 		



                    ....</p>



                <div class="clear-fix">&nbsp;</div>



          </div> -->



          



          <p><a href="resources-list.php">View all >></a></p>

    </aside>
    <section class="main_content">
    	<h1>Create Client / Edit Client</h1>
      <div class="admin_container"> 
             	<form action="<?php echo $editFormAction; ?>" name="create_client_form" method="POST" id="create_client_form" onsubmit="return validateForm()">
                    <div class="field_item">
					<label for="project_name">Client Name:</label>
                	<input name="client_name" type="text" class="required" id="client_name" value="<?php echo $row_getProjDe['client_name']; ?>"/>
                    </div>
                      <div class="field_item">
					<label for="client_name">Contact Manager Name:</label>
                	<input type="text" name="client_contact_name" id="client_contact_name"  value="<?php echo $row_getProjDe['client_contact_name']; ?>"/>
                    </div>
                    
                      <div class="field_item">
					<label for="project_name">Contact Mail:</label>
                	<input type="text" name="client_mail" id="client_mail"  value="<?php echo $row_getProjDe['client_mail']; ?>"/>
                    </div>
                    <div class="field_item">
					<label for="project_name">Contact Phone No:</label>
                	<input type="text" name="client_phone" id="client_phone"  value="<?php echo $row_getProjDe['client_phone']; ?>"/>
                    </div>
                    <div class="field_item">
					<label for="project_desc">Description:</label>
        			<textarea rows="8" cols="36" name="client_address" id="client_address" class="required"><?php echo $row_getProjDe['client_address']; ?></textarea>
            		</div>
                     <div class="field_item">
					<label for="status">Status:</label>
        			<select name="status" id="status">
                    <option value="A" <?php if (!(strcmp("A", $row_getProjDe['status']))) {echo "selected=\"selected\"";} ?>>Active</option>
                    <option value="P" <?php if (!(strcmp("P", $row_getProjDe['status']))) {echo "selected=\"selected\"";} ?>>Pending</option>
                    <option value="C" <?php if (!(strcmp("C", $row_getProjDe['status']))) {echo "selected=\"selected\"";} ?>>Closed</option>
                    </select>
            		<input name="client_id" type="hidden" id="client_id" value="<?php echo $row_getProjDe['client_id']; ?>" />
            		<input type="hidden" name="created_by" id="created_by" value="<?php echo $_SESSION['user_id']; ?>" />
            		<input type="hidden" name="created_date" id="created_date" value="<?php echo date('Y-m-d'); ?>" />
                    </div>
                    <div class="action_items">
                    	<input name="submit" type="submit" class="save_btn" onclick="MM_validateForm('client_name','','R','client_contact_name','','R','client_mail','','R','client_phone','','R','client_address','','R');return document.MM_returnValue" value="Save">
                        <input type="reset" value="Cancel" class="reset_btn" onclick="cancel()">
                    </div>
                    <div class="clear-fix">&nbsp;</div>
                    
           	        <input type="hidden" name="MM_update" value="create_client_form" />
           	   </form>
        </div>
    </section>
    <div class="clear-fix"></div>
    </article>
  	<!--<article class="arrow-bar">
    </article>-->
    <?php  require_once('../includes/footer.php'); ?> 
    
    </div>

</body>
</html>