<?php require_once('../Connections/oprmConn.php'); ?><?php require_once('../Connections/oprmConn.php'); $msg = ""; if(isset($_REQUEST['msg'])) $msg = $_REQUEST['msg']; ?>
<?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']);
}

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, holiday_sheet=%s, other_docs=%s, other_info=%s, bank_account=%s, bank_sortcode=%s, bank_address=%s,passport_number=%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['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($_POST['passport_number'], "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?msg=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);
if(isset($_REQUEST['pid'])) {
$query_getProfile = "SELECT p.*, weby_users.email_address, weby_users.user_role FROM weby_profiles p, weby_users WHERE p.user_id = '$_REQUEST[pid]' AND weby_users.user_id = p.user_id";
} else {
$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);
?><!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]-->
    <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);
}
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
</script>
</head>

<body>
<!-- Wrapper Starts -->

<div class="wrapper">

    <?php  require_once('../includes/header.php'); ?>
    
<?php  require_once('../includes/tools-menu.php'); ?>
  <!-- Content Goes here -->
    <!-- Content Goes here -->
    <article class="inside_wrapper">
    
    	<!-- Main Content Goes here -->
      <section class="main_content">
    		 <h1><?php if(isset($_REQUEST['pid'])) echo "User ".$row_getProfile['full_name']; else echo "My"; ?> Profile</h1>
             <font color="#FF0000"><?php echo $msg; ?></font>
              
            <article class="resource_profile">
              <div class="current_profile">
                <h3>Hr Rate: &pound;<?php echo $row_getProfile['hr_rate']; ?></h3> 
                <p>Current Profile Pic</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" height="78" /></p>
                <p>Current CV:<br/>
                  <a href="/RM/images/<?php echo $row_getProfile['cv_file']; ?>"><?php echo $row_getProfile['cv_file']; ?></a></p>
                <p>Passport Copy:<br/>
                  <a href="/RM/images/<?php echo $row_getProfile['passport_file']; ?>"><?php echo $row_getProfile['passport_file']; ?></a></p>
                <p>Holiday Sheet:<br/>
                  <a href="/RM/images/<?php echo $row_getProfile['holiday_sheet']; ?>"><?php echo $row_getProfile['holiday_sheet']; ?></a></p>
                <p>Other Documents:<br/>
                  <a href="/RM/images/<?php echo $row_getProfile['other_docs']; ?>"><?php echo $row_getProfile['other_docs']; ?></a></p>
              </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']; ?>" />
                      </div>
                      <div class="field_item">
                        <label>Skillet:</label>
                        <textarea name="skill_set" id="skill_set" rows="4" /><?php echo $row_getProfile['skill_set']; ?> </textarea>
                        </textarea>
                         <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>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&user_id=<?php echo $_REQUEST['pid']; ?>','UPLOAD','width=500,height=220')" value="Upload Profile Picture" />
                        <p>Supports JPG, PNG, GIF</p>
                      </div>
                      <div class="field_item">
                        <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&user_id=<?php echo $_REQUEST['pid']; ?>','UPLOAD','width=500,height=220')" value="Upload CV" />
                        <p>Supports PDF, doc, docx</p>
                      </div>
                      <div class="field_item">
                        <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&user_id=<?php echo $_REQUEST['pid']; ?>','UPLOAD','width=500,height=220')" value="Upload Passport" />
                        <p>Supports PDF, DOC, DOCX</p>
                      </div>
                      <div class="field_item">
                        <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&user_id=<?php echo $_REQUEST['pid']; ?>','UPLOAD','width=500,height=220')" value="Upload Holiday Sheet" />
                        <p>Supports PDF, xls, xlsx</p>
                      </div>
                      <div class="field_item">
                        <label>Other Documents:
                        <input name="other_docs1" type="hidden" id="other_docs1" value="<?php echo $row_getProfile['other_docs']; ?>" />
                        </label>
                        <input type="button" onclick="MM_openBrWindow('upload.php?uptype=5&user_id=<?php echo $_REQUEST['pid']; ?>','UPLOAD','width=500,height=220')" value="Upload Other documents" />
                        <p>Supports PDF, doc, docx,xls,xlsx</p>
                      </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">
                        <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">
                        <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">
                       <?php if(!isset($_REQUEST['pid'])) { ?> <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" class="reset_btn" onclick="MM_goToURL('parent','index.php');return document.MM_returnValue" value="Cancel"> 
                        <?php } ?>
                      </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>
     	 
     	 </aside>
    
    	 
    
     	<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>
