<?php require_once('../Connections/oprmConn.php'); 

if(!isset($_SESSION['user_id']))

{

	header("location: ../index.php");

}

?>
<?php $msg = ""; if(isset($_REQUEST['msg'])) $msg = $_REQUEST['msg']; ?>
<?php $msg1 = ""; if(isset($_REQUEST['msg1'])) $msg1 = $_REQUEST['msg1']; ?>
<?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, skill_set=%s, profile_pic=%s, cv_file=%s, passport_file=%s, visa_file=%s, ni_number=%s, holiday_sheet=%s, other_docs=%s, other_info=%s, bank_account=%s, bank_sortcode=%s, bank_address=%s,date_of_birth=%s, passport_number=%s, visa_number=%s, passport_edate=%s, visa_edate=%s, citizen_of=%s, contact_phone=%s, contact_address=%s, created_by=%s WHERE profile_id=%s",

                       GetSQLValueString($_POST['full_name'], "text"),

                       GetSQLValueString($_POST['job_title'], "text"),

                       GetSQLValueString($_POST['skill_set'], "text"),

                       GetSQLValueString($_POST['profile_pic1'], "text"),

                       GetSQLValueString($_POST['cv_file1'], "text"),

                       GetSQLValueString($_POST['passport_file1'], "text"),

					   GetSQLValueString($_POST['visa_file1'], "text"),
					   
					   GetSQLValueString($_POST['ni_number'], "text"),
					   
                       GetSQLValueString($_POST['holiday_sheet1'], "text"),

                       GetSQLValueString($_POST['other_docs1'], "text"),

                       GetSQLValueString($_POST['other_info'], "text"),

                       GetSQLValueString($_POST['bank_account'], "text"),

                       GetSQLValueString($_POST['bank_sortcode'], "text"),

                       GetSQLValueString($_POST['bank_address'], "text"),
                       
                         GetSQLValueString($dob, "text"),
                     

                       GetSQLValueString($_POST['passport_number'], "text"),

					   GetSQLValueString($_POST['visa_number'], "text"),

					   GetSQLValueString($pd, "text"),

					   GetSQLValueString($vd, "text"),

                       GetSQLValueString($_POST['citizen_of'], "text"),

                       GetSQLValueString($_POST['contact_phone'], "text"),

                       GetSQLValueString($_POST['contact_address'], "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?msg1=Profile Updated";

  if (isset($_SERVER['QUERY_STRING'])) {

    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";

    $updateGoTo .= $_SERVER['QUERY_STRING'];

  }

  header(sprintf("Location: %s", $updateGoTo));

}



}



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";



//"SELECT distinct d.doc_id, d.profile_id, d.other_docs, profiles.profile_id, profiles.user_id, weby_users.user_id FROM otherdoc d, profiles, weby_users WHERE profiles.user_id = $_REQUEST[user_id] AND (d.profile_id = profiles.profile_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">
<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>

<!-- IE Fix for HTML5 Tags -->

<!--[if IE]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> 

	<![endif]-->

<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'); ?>
    <!-- Banner Goes here --> 
    
  <!-- 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 } ?>
      <?php if(isset($_REQUEST['msg1']) ){ ?>
      <font color="#00FF00"><?php echo $msg1; ?><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']; ?>

                <?php $pweek = date('W');

		  $pyear = date('Y'); ?>

            <ul> <li><a href="index.php">Dashboard</a></li>

               <li><a href="timesheet.php">Timesheet</a></li> <li><a href="manage-leave.php">Manage Leaves</a></li>

            	<li><a href="logout.php">Logout</a></li>

            	</ul>	

                </div>

                </div>