<?
include getenv("DOCUMENT_ROOT")."/include/session_include.php";
@include getenv("DOCUMENT_ROOT")."/config/config_shopInfo.php";

//$func->checkAdmin("index.php");

//$GUID = trim($_POST["guid"]);

//echo "guid = $GUID";

//if ($GUID == "") $mode = "create";
//else $mode = "modify";

if ($mode == "") $mode = "update";

if ($mode == "create") {
	$btnName = "CREATE";
}
else if ($mode == "update") {
	$btnName = "UPDATE";
	$admTag = "DISABLED";
}

if ($_SESSION["ss_AID"] != "") {
		// Get Information
		$query = "SELECT * FROM tbl_admusers WHERE adm_userid = '".$_SESSION['ss_AID']."' ";
		$result=$jdb->fQuery($query, "fetch query error");
		//	echo"$query";

		for($i=0; $i<sizeof($result); $i++)
		{
			list($key, $value) = each($result);
			$$key = $value;
		}

		$adm_fnameSTR = str_replace("\\", "", $adm_fname);
		$adm_lnameSTR = str_replace("\\", "", $adm_lname);
}

?>

<script>
$(document).ready(function(){
	
	  $("#admininfo").validate({
	    // Specify validation rules
	    ignore: ".ignore",
	    rules: {
	      adm_password: {
	        required: true,
	        minlength: 6,
	      },
	      passwordcheck: {
	        required: true,
	        minlength: 6,
	        equalTo : '[name="adm_password"]'
	      },
	      adm_fname: {
	        required: true,
	      },
	      adm_lname: {
	        required: true,
	      },       
	    },
	    messages: {
					adm_password: {
							required: "Please input password (Minimum of 6 characters)",
							minlength: "Minimum of 6 characters.",
					},
					passwordcheck: {
							required: "Password and confirm password don't match",
							minlength: "Minimum of 6 characters.",
							equalTo : "Password and confirm password don't match",
					},  
					adm_fname: {
							required: "Please input First name",
					},				
					adm_lname: {
							required: "Please input Last name",
					},	
	    },
	    
	    errorElement : 'div',


		  submitHandler: function(form) {
		  	
		 							//e.preventDefault();
				         	var amodeid = $('#amodeid').val();
				         	//var aactionStrid = $('#actionStrid').val();
				         	//var aactionPageid = $('#actionPageid').val();
				         	
									var aadm_id = $('#adm_idid').val();
									var aadm_passwordid = $('#adm_passwordid').val();
									var aadm_fnameid = $('#adm_fnameid').val();
									var aadm_lnameid = $('#adm_lnameid').val();
									var aadm_phoneid = $('#adm_phoneid').val();
				         	//alert(amodeid);

					        $.ajax({  
					             url:"doc/personal_lib_process.php",  
					             method:"POST",  
					             data:{amode:amodeid, adm_id:aadm_id, adm_password:aadm_passwordid,
					             				adm_fname:aadm_fnameid, adm_lname:aadm_lnameid, adm_phone:aadm_phoneid	},
					             //beforeSend:function(){  
					             //     $('#submitid').val("Updating");  
					             //},  
					             success:function(response){  
					                  //$('#addcartformid')[0].reset();  
					                  //For debugging
					                  //$('.rt_debugging').html(response);
					                  
					                  if (response) {
																$('.myModalPopup-body').html("Successfully Updated");
																$('.myModalPopup-body').css('background-color', '#F43700');
																
							                  $('#myModalPopup').modal('show'); 
														    setTimeout(function () {
														        $('#myModalPopup').modal('hide'); 
														        $('#myModalAdminInfo').modal('hide');
														    }, 1500);                  
					                  }
					                  
					                  //$('#myModalAdminInfo').modal('hide');
					                  //$('.cart-item-no').html(response);  

					             }  
					        });  

			}		



	});
  
});
</script>


<style>
.error{
	color: red;
	font-weight: 200;
	margin-left: 1em;
}		
</style>

<div class="rt_debugging"></div>

        <div class="modal-header-2">
        	<h4 class="modal-title" id="myModalAdminInfoLabel">Update Information</h4>
          <button type="button" class="close" data-dismiss="modal">&times;</button>
        </div>
        <div class="modal-body-message">
           <p style="font-size:18px; padding:0.1em 0.5em;">

        <FORM name=admininfo id=admininfo method="post">
          <input type=hidden name=mode id="amodeid" value="<?=$mode?>">
        	<!--input type=hidden name=actionStr id="actionStrid" value="ADMINFO"-->
        	<!--input type=hidden name=actionPage id="actionPageid" value="ADMINADMINFO"-->
          <input type=hidden name=adm_id id="adm_idid" value="<?=$adm_id?>">
          
			          <div class="form-group">
					        <label class="lb-creation">User ID</label>
					        <input class="input-box" TYPE='text' NAME='adm_userid' id="adm_useridid" required='required' option='email' VALUE='<?=$adm_userid?>' <?=$admTag?> maxlength=60 >
					        <label class="lb-creation">Password</label>
					        <input  class="input-box" TYPE='password' NAME='adm_password' id="adm_passwordid" required='required' VALUE='' minlength="6" maxlength=20>
					        <label class="lb-creation">Re-Password</label>
					        <input  class="input-box" TYPE='password' NAME='passwordcheck' id="passwordcheckid" required='required' VALUE='' minlength="6" maxlength=20>
					        <label class="lb-creation">First Name</label>
					        <input class="input-box" TYPE='text' NAME='adm_fname' id="adm_fnameid" required='required' VALUE='<?=htmlspecialchars($adm_fnameSTR, ENT_QUOTES)?>' maxlength=50 >
					        <label class="lb-creation">Last Name</label>
					        <input class="input-box" TYPE='text' NAME='adm_lname' id="adm_lnameid" required='required' VALUE='<?=htmlspecialchars($adm_lnameSTR, ENT_QUOTES)?>' maxlength=50 >
					        <label class="lb-creation">Phone</label>
					        <input class="input-box" TYPE='text' NAME='adm_phone' id="adm_phoneid" required='required' VALUE='<?=$adm_phone?>' maxlength=20 >	        					        					        					        
			          </div>
          </p>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            <button type="submit" id="submitid" class="btn btn-create" >Update</button>
        </div>

				</FORM>             
				</div>
				

<div class="modal fade" id="myModalPopup" tabindex="-1" role="dialog" aria-labelledby="myModalPopup"  style="opacity: 0.5; padding-right: 0px !important;">
  <div class="modal-dialog modal-dialog-centered modal-xl" role="document">
      <div class="modal-content" style="background-color:#F43700 !important; max-width:260px; margin: 0 auto;">
        <div class="myModalPopup-body" style="text-align: center; border-radius: 5px; max-height:60px;	font-size:18px; background-color:#F43700; color: #FFFFFF; font-weight: bold;padding:0.5em 1em; ">

        </div>     	
      </div>
  </div>
</div>