<?php
session_start();
include './veriflog.php';
include './core.php';
$pageSequence = $_SESSION['sequence'];
$toDiv = "contentZone" . $pageSequence;
$resultZoneDiv = "resultZone" . $pageSequence;
$tableZone = "#tableZone" . $pageSequence;
$_SESSION['sequence']++;
//echo  dirname(__FILE__);  
//echo $_SERVER['DOCUMENT_ROOT'] . "   ".dirname(__FILE__)."  ".str_replace($_SERVER['DOCUMENT_ROOT'],"",dirname(__FILE__)) ;

//$toDiv = $_REQUEST['toDiv'];
//$rPage = $_REQUEST['rPage'];

$rPage = $_REQUEST['rPage'];
$id = $_REQUEST['userId'];
$res = $dba->getSystemUsers($id, true, 0,$_SESSION['cfg']['max.elements']) ;
?>


<style type="text/css">

    /* Style the form */
    #regForm {
        background-color: #ffffff;
        margin: 5px auto;
        padding: 40px;
        width: 80%;
        min-width: 300px;
    }

    /* Style the input fields */
    input {
        padding: 10px;
        width: 50%;
        font-size: 17px;
        font-family: Raleway;
        border: 1px solid #aaaaaa;
    }

    textarea {
        padding: 10px;
        width: 50%;
        font-size: 17px;
        font-family: Raleway;
        border: 1px solid #aaaaaa;
    }

    /* Mark input boxes that gets an error on validation: */
    input.invalid {
        background-color: #ffdddd;
    }

    /* Hide all steps by default: */
    .tab {
        display: none;
    }

    /* Make circles that indicate the steps of the form: */
    .step {
        height: 15px;
        width: 15px;
        margin: 0 2px;
        background-color: #bbbbbb;
        border: none;
        border-radius: 50%;
        display: inline-block;
        opacity: 0.5;
    }

    /* Mark the active step: */
    .step.active {
        opacity: 1;
    }

    /* Mark the steps that are finished and valid: */
    .step.finish {
        background-color: #04AA6D;
    }

    .moduleId323 { background-color:#E9F2FE }


</style>
<section class="content" >
    <div class="row">
        <div class="col-sm-12">
            <div class="panel panel-bd lobidrag">
                <div class="panel-heading">
                    <div class="btn-group" id="buttonexport">
                        <a href="#">
                            <h4>Réinitialisation du  mot de passe</h4>
                        </a>
                    </div>
                </div>
                <div class="panel-body">

                    <form id="regForm" action="exec_reset_user_password.php"  method="post" onsubmit="return false;">

                        <div class="form-group">
                            <label><em> <h3> Utilisateur - <b style="color:RED"> <?php echo $res[0]['user_name_v']; ?> </b></h3> </em> </label>
                        </div>

                        <!-- One "tab" for each step in the form: -->
                        <div class="tab">
<!--
                          <div class="form-group">
                        <input type="text" name="login" id="login"  size="50" readonly="readonly" value="<?php echo $res[0]['user_name_v'] ; ?>" />
                    </div>
                    
                    <?php 
					
					   if($_SESSION['right'] != 1 ) {
					
					?>
                    
                      <div class="form-group">
                     <input type="password" name="oldPassword" id="oldPassword"  size="50" required="required" placeholder="**************"  />
                     
                    </div>
                    
                    
                    <?php } ?>
                    -->
                     <div class="form-group">
                     <input type="password" name="newPassword" id="newPassword"  size="50" required   placeholder="**************"  />
                     <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="password" name="confPassword" id="confPassword"  size="50" required="required"   placeholder="**************"  />
                     
                    </div>





                            </div>

                        


                            <div style="overflow:auto;">
                                <div style="float:right;">
                                    <button type="button" id="cancelBtn" onclick="getPage('<?php echo $rPage; ?>', 'content-wrapper');">Annuler</button>
                                    <button type="button" id="prevBtn" onclick="prev(-1)">Précédent</button>
                                    <button type="button" id="nextBtn" onclick="nextPrev(1)">Suivant</button>
                                </div>
                            </div>

                            <!-- Circles which indicates the steps of the form: -->
                            <div style="text-align:center;margin-top:40px;">
                                <span class="step"></span>
                                <span class="step"></span>

                            </div>

                        </form>

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


    </section>





    <script type="text/javascript">




        $(document).ready(function () {
           

        $('form').on("submit", function (event) {

            var toDiv = $("form").attr('toDiv');
            var rpage = $("form").attr('returnPage');

            $.post($(this).attr("action"), $(this).serialize(), function (data) {

                var obj = jQuery.parseJSON(data);

                if (obj.errorCode == 0) {

                    //alert( obj.errorMessage );

                    //    $.alert( obj.errorMessage );

                    $.confirm({
                        icon: 'glyphicon glyphicon-ok',
                        title: 'RESULTAT',
                        content: obj.errorMessage,
                        type: 'green',
                        typeAnimated: true,
                        buttons: {
                            confirm: {
                                text: 'OK',
                                action: function () {
                                    $("#content-wrapper").load("<?php echo $rPage; ?>");
                                }

                            }


                        }

                    });
                    //  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(); */
        });



    });


//process add data








    var currentTab = 0; // Current tab is set to be the first tab (0)
    showTab(currentTab); // Display the current tab

    function showTab(n) {
        // This function will display the specified tab of the form ...
        var x = document.getElementsByClassName("tab");
        x[n].style.display = "block";
        // ... and fix the Previous/Next buttons:
        if (n == 0) {
            document.getElementById("prevBtn").style.display = "none";
        } else {
            document.getElementById("prevBtn").style.display = "inline";
        }
        if (n == (x.length - 1)) {
            document.getElementById("nextBtn").innerHTML = "Soumettre";
        } else {
            document.getElementById("nextBtn").innerHTML = "Suivant";
        }
        // ... and run a function that displays the correct step indicator:
        fixStepIndicator(n)
    }

    function nextPrev(n) {

        if (document.getElementById("nextBtn").innerHTML == "Soumettre") {


            $("#regForm").submit();



        } else {


            var x = document.getElementsByClassName("tab");
            // Exit the function if any field in the current tab is invalid:
            if (n == 1 && !validateForm())
                return false;
            // Hide the current tab:
            x[currentTab].style.display = "none";
            // Increase or decrease the current tab by 1:
            currentTab = currentTab + n;
            // if you have reached the end of the form... :
            if (currentTab >= x.length) {
                //...the form gets submitted:
                alert("the form gets submitted");
                document.getElementById("regForm").submit();
                return false;
            }
            // Otherwise, display the correct tab:
            showTab(currentTab);

        }


        // This function will figure out which tab to display

    }


    function prev(n) {

        var x = document.getElementsByClassName("tab");
        // Exit the function if any field in the current tab is invalid:
        if (n == 1 && !validateForm())
            return false;
        // Hide the current tab:
        x[currentTab].style.display = "none";
        // Increase or decrease the current tab by 1:
        currentTab = currentTab + n;
        // if you have reached the end of the form... :
        if (currentTab >= x.length) {
            //...the form gets submitted:
            alert("the form gets submitted");
            document.getElementById("regForm").submit();
            return false;
        }
        // Otherwise, display the correct tab:
        showTab(currentTab);


        // This function will figure out which tab to display

    }


    function validateForm() {
        // This function deals with validation of the form fields
        var x, y, i, valid = true;
        x = document.getElementsByClassName("tab");
        y = x[currentTab].getElementsByTagName("input");
        // A loop that checks every input field in the current tab:
        for (i = 0; i < y.length; i++) {
            // If a field is empty...
            if (y[i].value == "") {
                // add an "invalid" class to the field:
                y[i].className += " invalid";
                // and set the current valid status to false:
                valid = false;
            }
        }
        // If the valid status is true, mark the step as finished and valid:
        if (valid) {
            document.getElementsByClassName("step")[currentTab].className += " Terminer";
        }
        return valid; // return the valid status
    }

    function fixStepIndicator(n) {
        // This function removes the "active" class of all steps...
        var i, x = document.getElementsByClassName("step");
        for (i = 0; i < x.length; i++) {
            x[i].className = x[i].className.replace(" active", "");
        }
        //... and adds the "active" class to the current step:
        x[n].className += " active";
    }


</script>

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