<?php require_once('../Connections/oprmConn.php'); ?>
<?php $msg = ""; if(isset($_REQUEST['msg'])) $msg = $_REQUEST['msg']; ?>
<?php include('check-admin-session.php'); ?>
<?php

if(isset($_POST['new_password'])) {
mysql_select_db($database_oprmConn, $oprmConn);
$query_Recordset1 = "SELECT * FROM weby_users WHERE weby_users.user_id = '$_SESSION[user_id]'";
$Recordset1 = mysql_query($query_Recordset1, $oprmConn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

$olp = md5($_REQUEST['current_password']);
if($olp == $row_Recordset1['password']) {
mysql_select_db($database_oprmConn, $oprmConn);
$np = md5($_REQUEST['new_password']);
$query_Recordset1 = "update weby_users set password = '$np' WHERE weby_users.user_id = '$_SESSION[user_id]'";
$Recordset1 = mysql_query($query_Recordset1, $oprmConn) or die(mysql_error());
$msg = "Password changed successfully";
} else {
$msg = "Old Password is wrong. Please try one more time.";
}
} else {
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']);
}
$dob = date("Y-m-d",strtotime($_POST['date_of_birth']));
$pd = date("Y-m-d",strtotime($_POST['passport_edate']));
$vd = date("Y-m-d",strtotime($_POST['visa_edate']));
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "edit_profile")) {
  $updateSQL = sprintf("UPDATE weby_profiles SET full_name=%s, job_title=%s, profile_pic=%s, created_by=%s WHERE profile_id=%s",
                       GetSQLValueString($_POST['full_name'], "text"),
                       GetSQLValueString($_POST['job_title'], "text"),      
                       GetSQLValueString($_POST['profile_pic1'], "text"),
                       GetSQLValueString($_POST['created_by'], "int"),
                       GetSQLValueString($_POST['profile_id'], "int"));

  mysql_select_db($database_oprmConn, $oprmConn);
  $Result1 = mysql_query($updateSQL, $oprmConn) or die(mysql_error());
  
  mysql_select_db($database_oprmConn, $oprmConn);
	$query_Recordset111 = "update weby_users set email_address = '$_POST[email_address]' WHERE weby_users.user_id = '$_SESSION[user_id]'";
	$Recordset111 = mysql_query($query_Recordset111, $oprmConn) or die(mysql_error());

  $updateGoTo = "profile.php?msg=Profile Updated";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

}
$sd = date("Y-m-d",strtotime($_POST['start_date']));
$ed = date("Y-m-d",strtotime($_POST['end_date']));
mysql_select_db($database_oprmConn, $oprmConn);
$query_getProfile = "SELECT p.*, weby_users.email_address, weby_users.user_role FROM weby_profiles p, weby_users WHERE p.user_id = '$_SESSION[user_id]' AND weby_users.user_id = p.user_id";
$getProfile = mysql_query($query_getProfile, $oprmConn) or die(mysql_error());
$row_getProfile = mysql_fetch_assoc($getProfile);
$totalRows_getProfile = mysql_num_rows($getProfile);

mysql_select_db($database_oprmConn, $oprmConn);
$query_getDoclist = "SELECT d.*, weby_profiles.profile_id, weby_profiles.user_id, weby_users.user_id FROM weby_otherdoc d, weby_profiles, weby_users WHERE d.profile_id = weby_profiles.profile_id AND weby_profiles.user_id = '$_SESSION[user_id]' AND d.status = 'A' group by d.doc_id";
$getDoclist = mysql_query($query_getDoclist, $oprmConn) or die(mysql_error());
$row_getDoclist = mysql_fetch_assoc($getDoclist);
$totalRows_getDoclist = mysql_num_rows($getDoclist);
?>
<!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" />
<title>SS WEB TECHNOLOGIES - Tool Resource Projects</title>
<link rel="stylesheet" href="../css/style.css" type="text/css">
<!-- IE Fix for HTML5 Tags -->
<!--[if IE]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> 
	<![endif]-->
<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">
<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 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 checkP(){
if(document.getElementById("new_password").value != document.getElementById("confirm_password").value) {
alert("New password and Confirm password should be same");
document.getElementById("new_password").focus();
return false;
}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
</script>
<script>
$(function() {
    $("#date_of_birth" ).datepicker({ dateFormat:'dd-mm-yy',   changeMonth: true,  changeYear: true ,
    
      
    });
   $( "#passport_edate" ).datepicker({ dateFormat:'dd-mm-yy',   changeMonth: true,  changeYear: true ,
    
      
    });
	$( "#visa_edate" ).datepicker( {dateFormat:'dd-mm-yy',   changeMonth: true,  changeYear: true,  
    
      
    });
	
  
});

</script>
</head>

<body>

<!-- Wrapper Starts -->

<div class="wrapper">

    <?php  require_once('../includes/header.php'); ?>
    
<?php  require_once('../includes/tools-menu.php'); ?>
  <!-- Content Goes here -->
  <article class="inside_wrapper clear_fix"> 
    
    <!-- Main Content Goes here -->
    <section class="main_content">
      <h1>My Profile</h1>
      <?php if(isset($_REQUEST['msg']) ){ ?>
      <font color="#FF0000"><?php echo $msg; ?><a href="profile.php"><img src="/RM/images/cross.png" width="12" height="12" alt="delete"></a></font>
      <?php } ?>
      <!--<div class="welcome_box">
        <div class="timesheet_type">
          <div class="welcome_txt arrow">Welcome <?php echo $row_getProfile['full_name']; ?>
            <ul> <li><a href="index.php">Dashboard</a></li>
                <li><a href="timesheet-all.php">Time sheet</a></li>
                <li><a href="project-list.php">Projects</a></li>
            	<li><a href="resources-list.php">Resources</a></li>
            	<li><a href="profile.php">Profile</a></li>
                <li><a href="leave-list.php">Leave Manager</a></li>
                 <li><a href="reports.php">Records</a></li>
            	<li><a href="logout.php">Logout</a></li>
            </ul>
          </div>
        </div>
      </div>-->
      <article class="resource_profile">
        <div class="current_profile"> 
          <!-- <h3>Hr Rate: &pound;<?php echo $row_getProfile['hr_rate']; ?></h3> -->
          <p><b>Current Profile Pic</b></p>
          <p><img src="/RM/images/<?php if(!empty($row_getProfile['profile_pic']))echo $row_getProfile['profile_pic']; else echo "black-img.jpg"; ?>" width="68" />&nbsp;<a href="profile-delete.php?prid=<?php echo $row_getProfile['profile_id']; ?>&cn=profile_pic"><img src="/RM/images/cross.png" width="12" height="12" alt="delete"></a></p>
          <?php /*?><p><b>Current CV:</b><br/>
            <?php if($row_getProfile['cv_file'] != NULL) { ?>
            <a href="/RM/images/<?php echo $row_getProfile['cv_file']; ?>" target="_blank"><?php echo $row_getProfile['cv_file']; ?></a>&nbsp;<a href="profile-delete.php?prid=<?php echo $row_getProfile['profile_id']; ?>&cn=cv_file"><img src="/RM/images/cross.png" width="12" height="12" alt="delete"></a>
            <?php } else { echo "Not Uploaded"; } ?>
          </p>
          <p><b>Passport Copy:</b><br/>
            <?php if($row_getProfile['passport_file'] != NULL) { ?>
            <a href="/RM/images/<?php echo $row_getProfile['passport_file']; ?>" target="_blank"><?php echo $row_getProfile['passport_file']; ?></a>&nbsp;<a href="profile-delete.php?prid=<?php echo $row_getProfile['profile_id']; ?>&cn=passport_file"><img src="/RM/images/cross.png" width="12" height="12" alt="delete"></a>
            <?php } else { echo "Not Uploaded"; } ?>
          </p>
          <p><b>Visa Copy:</b><br/>
            <?php if($row_getProfile['visa_file'] != NULL) { ?>
            <a href="/RM/images/<?php echo $row_getProfile['visa_file']; ?>" target="_blank"><?php echo $row_getProfile['visa_file']; ?></a>&nbsp;<a href="profile-delete.php?prid=<?php echo $row_getProfile['profile_id']; ?>&cn=visa_file"><img src="/RM/images/cross.png" width="12" height="12" alt="delete"></a>
            <?php } else { echo "Not Uploaded"; } ?>
          </p>
          <p><b>Holdiay Sheet:</b><br/>
            <?php if($row_getProfile['holiday_sheet'] != NULL) { ?>
            <a href="/RM/images/<?php echo $row_getProfile['holiday_sheet']; ?>" target="_blank"><?php echo $row_getProfile['holiday_sheet']; ?></a>&nbsp;<a href="profile-delete.php?prid=<?php echo $row_getProfile['profile_id']; ?>&cn=holiday_sheet"><img src="/RM/images/cross.png" width="12" height="12" alt="delete"></a>
            <?php } else { echo "Not Uploaded"; } ?>
          </p>
          <p><b>Other/Academic Certificates:</b><br/>
          
          <ol>
            <?php  if($row_getDoclist['other_docs'] != NULL) {?>
            <?php do {?>
            <li> <a href="/RM/images/<?php echo $row_getDoclist['other_docs']; ?>" target="_blank"><?php echo $row_getDoclist['other_docs']; ?></a>&nbsp;<a href="doc-delete.php?prid=<?php echo $row_getDoclist['profile_id']; ?>&oid=<?php echo $row_getDoclist['doc_id']; ?>"><img src="/RM/images/cross.png" width="12" height="12" alt="delete"></a></li>
            <?php } while ($row_getDoclist = mysql_fetch_assoc($getDoclist)); } else {echo "Not uploaded";} ?>
          </ol><?php */?>
        </div>
        <div class="edit_profile">
          <div class="edit_profile">
            <form name="edit_profile" method="POST" action="<?php echo $editFormAction; ?>" id="edit_profile">
              <div class="field_item">
                <label>Full Name:</label>
                <input name="full_name" type="text" id="full_name" value="<?php echo $row_getProfile['full_name']; ?>" />
              </div>
              <div class="field_item">
                <label>Job title:</label>
                <input name="job_title" type="text" id="job_title" value="<?php echo $row_getProfile['job_title']; ?>" />
              </div>
              <div class="field_item">
                <label>Email Address:</label>
                <input type="email" name="email_address" id="email_address" value="<?php echo $row_getProfile['email_address']; ?>" /> 
                <input type="hidden" id="created_by" name="created_by" value="<?php echo $row_getProfile['created_by']; ?>" />
                <input name="profile_id" type="hidden" id="profile_id" value="<?php echo $row_getProfile['profile_id']; ?>" />
              </div>
              <!--<div class="field_item">
                <label>Skillset:</label>
                <textarea name="skill_set" id="skill_set" rows="4" />
                <?php echo $row_getProfile['skill_set']; ?>
                </textarea>
               
              </div>-->
              <div class="field_item">
                <p>Supports JPG, PNG, GIF</p>
                <label>Profile Picture:
                  <input name="profile_pic1" type="hidden" id="profile_pic1" value="<?php echo $row_getProfile['profile_pic']; ?>" />
                </label>
                <input type="button" onclick="MM_openBrWindow('upload.php?uptype=1','UPLOAD','width=500,height=220')" value="Upload Profile Picture" />
              </div>
             <!-- <div class="field_item">
                <p>Supports PDF, doc, docx</p>
                <label>Upload CV:
                  <input name="cv_file1" type="hidden" id="cv_file1" value="<?php echo $row_getProfile['cv_file']; ?>" />
                </label>
                <input type="button" onclick="MM_openBrWindow('upload.php?uptype=2','UPLOAD','width=500,height=220')" value="Upload CV" />
              </div>
              <div class="field_item">
                <p>Supports PDF, DOC, DOCX, JPG, PNG, GIF</p>
                <label>
                  <input name="passport_file1" type="hidden" id="passport_file1" value="<?php echo $row_getProfile['passport_file']; ?>" />
                  Passport Copy:</label>
                <input type="button" onclick="MM_openBrWindow('upload.php?uptype=3','UPLOAD','width=500,height=220')" value="Upload Passport" />
              </div>
              <div class="field_item">
                <p>Supports PDF, DOC, DOCX, JPG, PNG, GIF</p>
                <label>
                  <input name="visa_file1" type="hidden" id="visa_file1" value="<?php echo $row_getProfile['visa_file']; ?>" />
                  Visa Copy:</label>
                <input type="button" onclick="MM_openBrWindow('upload.php?uptype=6','UPLOAD','width=500,height=220')" value="Upload Visa" />
              </div>
              <div class="field_item">
                <p>Supports PDF, xls, xlsx</p>
                <label>Holiday Sheet:
                  <input name="holiday_sheet1" type="hidden" id="holiday_sheet1" value="<?php echo $row_getProfile['holiday_sheet']; ?>" />
                </label>
                <input type="button" onclick="MM_openBrWindow('upload.php?uptype=4','UPLOAD','width=500,height=220')" value="Upload Holiday Sheet" />
              </div>
              <div class="field_item">
                <p>Supports PDF, doc, docx,xls,xlsx</p>
                <label>Other/Academic Certificates:
                  <input name="other_docs1" type="hidden" id="other_docs1" value="<?php echo $row_getProfile['other_docs']; ?>" />
                </label>
                <input type="button" onclick="MM_openBrWindow('upload_other.php?prid=<?php echo $row_getProfile['profile_id']; ?>&uptype=1','UPLOAD','width=500,height=220')" value="Upload Other documents" />
              </div>
              <div class="field_item">
                <label>Other Info:</label>
                <textarea name="other_info" id="other_info" rows="4" />
                <?php echo $row_getProfile['other_info']; ?>
                </textarea>
                </textarea>
              </div>
              <h3>Bank Details</h3>
              <div class="field_item">
                <label>Account No.:</label>
                <input name="bank_account" type="text" id="bank_account" value="<?php echo $row_getProfile['bank_account']; ?>" />
              </div>
              <div class="field_item">
                <label>Sort Code:</label>
                <input name="bank_sortcode" type="text" id="bank_sortcode" value="<?php echo $row_getProfile['bank_sortcode']; ?>" />
              </div>
              <div class="field_item">
                <label>Bank Name and Address:</label>
                <textarea name="bank_address" id="bank_address" rows="4" />
                <?php echo $row_getProfile['bank_address']; ?>
                </textarea>
              </div>
              <h3>Personal Details</h3>
               <div class="field_item">(DD-MM-YYYY)<br />
                  <label>Date Of Birth</label>
                <input  name="date_of_birth" type="text" id="date_of_birth" value="<?php if($row_getProfile['date_of_birth'] != NULL) { echo date('d-m-Y',strtotime($row_getProfile['date_of_birth'])); } if($row_getProfile['date_of_birth'] == NULL) { echo date('d-m-Y'); } ?>" readonly="readonly" />
              </div>
              <div class="field_item">
                <label>Passport Number</label>
                <input  name="passport_number" type="text" id="passport_number" value="<?php echo $row_getProfile['passport_number']; ?>"  />
              </div>
              <div class="field_item">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(DD-MM-YYYY)<br />
                <label>Passport Expiry Date</label>
                <input  name="passport_edate" type="text" id="passport_edate" value="<?php if($row_getProfile['passport_edate'] != NULL) { echo date('d-m-Y',strtotime($row_getProfile['passport_edate'])); } if($row_getProfile['passport_edate'] == NULL) { echo date('d-m-Y'); } ?>" readonly="readonly" />
              </div>
              <div class="field_item">
                <label>Visa Number</label>
                <input  name="visa_number" type="text" id="visa_number" value="<?php echo$row_getProfile['visa_number']; ?>"  />
              </div>
              <div class="field_item">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(DD-MM-YYYY)<br />
                <label>Visa Expiry Date</label>
                <input  name="visa_edate" type="text" id="visa_edate" value="<?php if($row_getProfile['visa_edate'] != NULL) { echo  date('d-m-Y',strtotime($row_getProfile['visa_edate'])); } if($row_getProfile['visa_edate'] == NULL) { echo date('d-m-Y'); } ?>" readonly="readonly" />
              </div>
              <div class="field_item">
                <label>NI Number:</label>
                <input name="ni_number" type="text" id="ni_number" value="<?php echo $row_getProfile['ni_number']; ?>" />
              </div>
              <div class="field_item">
                <label>Citizen of</label>
                <input  name="citizen_of" type="text" id="citizen_of" value="<?php echo $row_getProfile['citizen_of']; ?>"  />
              </div>
              <div class="field_item">
                <label>Contact Phone</label>
                <input  name="contact_phone" type="text" id="contact_phone" value="<?php echo $row_getProfile['contact_phone']; ?>"  />
              </div>
              <div class="field_item">
                <label>Contact Address</label>
                <textarea name="contact_address" id="contact_address" rows="4" />
                <?php echo $row_getProfile['contact_address']; ?>
                </textarea>
                </textarea>
              </div>-->
              <div class="action_items">
                <input name="submit2" type="submit" class="save_btn" onclick="MM_validateForm('full_name','','R','job_title','','R','bank_account','','R','contact_phone','','R','skill_set','','R');return document.MM_returnValue" value="Save">
                <!-- <input type="reset" value="Cancel" class="reset_btn">--> 
              </div>
              <input type="hidden" name="MM_update" value="edit_profile" />
            </form>
          </div>
        </div>
        <div class="clear-fix">&nbsp;</div>
      </article>
    </section>
    
    <!-- Sidebar Goes here -->
    <aside class="sidebar">
    <div class="featured">
      <h2 class="white_txt">Change Password</h2>
      <form method="post" action="#" id="change_password" onsubmit="return checkP()">
        <div class="field_item">
          <label>Current Password:</label>
          <input type="password" name="current_password" id="current_password" >
        </div>
        <div class="field_item">
          <label>New Password:</label>
          <input type="password" name="new_password" id="new_password" >
        </div>
        <div class="field_item">
          <label>Confirm Password:</label>
          <input type="password" name="confirm_password" id="confirm_password" >
        </div>
        <div class="action_items">
          <input name="submit" type="submit" class="save_btn" onclick="MM_validateForm('current_password','','R','new_password','','R','confirm_password','','R');return document.MM_returnValue" value="Save">
          <input type="reset" value="Cancel" class="reset_btn">
        </div>
      </form>
      <div class="clear-fix">&nbsp;</div>
    </div>
    <div class="clear-fix">&nbsp;</div>
  </article>
  <div class="clear-fix">&nbsp;</div>
  <!-- Footer Goes here -->

     <?php  require_once('../includes/footer.php'); ?>
</div>
</body>
</html>
