<?php session_start();
$pageSequence = $_SESSION['sequence'];
$toDiv = "contentZone" . $pageSequence;
$resultZoneDiv = "resultZone" . $pageSequence;
$_SESSION['sequence']++;
//echo  dirname(__FILE__);  
//echo $_SERVER['DOCUMENT_ROOT'] . "   ".dirname(__FILE__)."  ".str_replace($_SERVER['DOCUMENT_ROOT'],"",dirname(__FILE__)) . " SELF :" .$_SERVER['PHP_SELF']  ;
$toDiv = $_REQUEST['toDiv'];
$rpage = $_REQUEST['rpage'];

$currentBaseDir = dirname($_SERVER['PHP_SELF']);
include($_SESSION['basedir']."core.php");
$profileList = $dba->getProfileListByRight($_SESSION['right']);
$id = $_REQUEST['item'];
$res = $dba->getUserDetailByRight($_SESSION['right'],$id ,1 ,false, 0,0);
$agencyres = $dba->getSCCAgencies( 0 );

?>

<form action="<?php echo $currentBaseDir; ?>/exec_modify_user.php" method="post" enctype="multipart/form-data"  id="campaignFrm"  toDiv="<?php echo $_REQUEST['toDiv']; ?>"  returnPage="<?php echo $_REQUEST['rpage']; ?>" onsubmit="return false;">
                    <div class="form-group">
                      <select name="profileId" id="profileId" required>
                                                        <option value="-1"  > - </option>
                                                        <?php
                                                        //$cfgCount = count($ruleCfg);

                                                       for ($i = 0; $i < count($profileList); $i++) {
                                                            ?>

                                                            <option value="<?php echo $profileList[$i]['profile_id_n']; ?>" <?php if($profileList[$i]['profile_id_n'] == $res[0]['profile_id_n']){ ?> selected="selected" <?php } ?> > <?php echo $profileList[$i]['profile_name_v']; ?></option>

                                                            <?php
                                                        }
                                                        ?>

                                                    </select>
                    </div>
                    <div class="form-group">
                        <input type="text" name="login" id="login"  size="50" readonly="readonly" value="<?php echo $res[0]['user_name_v'] ; ?>" />
                    </div>
                     <div class="form-group">
                     <input type="text" name="lastName" id="lastName"  size="50" required  value="<?php echo $res[0]['last_name_v'] ; ?>" />
                     <input type="hidden" name="sccUserId" value="<?php echo $res[0]['user_id_n'] ;  ?>" />
                     <input type="hidden" name="accountName" value="<?php echo $res[0]['mobile_phone_v'] ; ?>" />
                    </div>
                    
                     <div class="form-group">
                     <input type="text" name="firstName" id="firstName"  size="50" required="required" value="<?php echo $res[0]['first_name_v'] ; ?>"  />
                     
                    </div>
                    
                    <div class="form-group">
                    <input name="msisdn" id="msisdn"  size="30"  type="text"  maxlength ="21" required  value="<?php echo $res[0]['mobile_phone_v'] ; ?>"/>
                     
                    </div>
                    
                    <div class="form-group">
                    <input type="text" name="email" id="email"  size="50" required value="<?php echo $res[0]['email_v'] ; ?>"/>
                     
                    </div>
                    <!--
                    <div class="form-group">
                    <input name="password" id="password"  size="30"  type="password"  required placeholder="Mot de passe"/>
                     
                    </div>
                    
                    <div class="form-group">
                   <input name="confPasswd" id="confPasswd"  size="30"  type="password"  required placeholder="Confirmer le mot de passe"/>
                     
                    </div>
                    -->
                    <div class="form-group">
                      <select name="agencyId" id="agencyId" required>
                                                        <option value="-1" selected="selected"> - Agence - </option>
                                                        <?php
                                                        //$cfgCount = count($ruleCfg);

                                                       for ($i = 0; $i < count($agencyres); $i++) {
                                                            ?>

 <option value="<?php echo $agencyres[$i]['agency_id_n']; ?>" <?php if($agencyres[$i]['agency_id_n'] == $res[0]['agency_id_n']){ ?> selected="selected" <?php } ?> > <?php echo $agencyres[$i]['agency_name_v']; ?></option>
 
                                                       

                                                            <?php
                                                        }
                                                        ?>

                                                    </select>
                    </div>
                     <button  type="submit" class="btn addition">Modifier</button>  <button type="button" class="btn close-btn" data-dismiss="modal" data-href="">Fermer</button>
                </form>
                



<script type="text/javascript">

$('form').on("submit", function(event) {
	
	 $.post($(this).attr("action"), $(this).serialize(), function(data) {
 
		   var obj = jQuery.parseJSON( data);
		   
		   if(obj.errorCode == 0 ) {
			   
			   //alert( obj.errorMessage );
			 
			 //    $.alert( obj.errorMessage );
			 
			 $.alert({
				 icon: 'glyphicon glyphicon-ok',
				 title: 'RESULTAT',
                 content: obj.errorMessage,
                 type: 'green',
                 typeAnimated: true

				});
			    //  alert(data);
      
		   }
		   else {
			   
			   $.alert({
				     icon: 'glyphicon glyphicon-warning-sign',
					 title: 'RESULTAT',
                     content: obj.errorMessage,
                     type: 'red',
                     typeAnimated: true
				});
			   
			  // $.alert( obj.errorMessage );
		   }
         
        });
       // return false; // prevent normal submit
   
	
  event.preventDefault();
	
	/*
        var postData = $(this).serializeArray();
        var formURL = $(this).attr("action");
		
        $.ajax({
            url: formURL,
            type: "POST",
            data: postData,
            success: function(data, textStatus, jqXHR) {
              
			  alert("Processing the form...");
			
            },
            error: function(jqXHR, status, error) {
                console.log(status + ": " + error);
            }
        });
        event.preventDefault(); */
    });


$(".close-btn").on('click', function(){
  // create the backdrop and wait for next modal to be triggered
 // $('body').modalmanager('loading');
   $('#loader').loading({
		  message : "Chargement...",
		  theme : 'dark'
		  
		});
		
		   $("#<?php echo $toDiv; ?>").load("<?php echo $rpage; ?>");
           $('#loader').loading('stop'); 
		
});


</script>
 
<link rel="stylesheet" href="css/jquery-confirm.min.css">
<script src="js/jquery-confirm.min.js"></script>