<script>

    function readURL(input, objID) {
        var node = document.createElement("img");
        var parentDIV = document.getElementById("image");
        parentDIV.appendChild(node);
        document.getElementById("image").appendChild(node);
        node.setAttribute("id", objID);
        node.setAttribute("src", "");

        if (input.files && input.files[0]) {
            var reader = new FileReader();
            reader.onload = function (e) {
                $('#' + objID)
                        .attr('src', e.target.result)
                        .width(50)
                        .height(50);
            };
            reader.readAsDataURL(input.files[0]);
        }
    }

    //Create a boolean variable to check for a valid Internet Explorer instance.
    var xmlhttp = false;
//Check if we are using IE.
    try {
        //If the Javascript version is greater than 5.
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

        //alert ("You are using Microsoft Internet Explorer.");
    } catch (e) {

        //If not, then use the older active x object.
        try {
            //If we are using Internet Explorer.
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            //alert ("You are using Microsoft Internet Explorer");
        } catch (E) {
            //Else we must be using a non-IE browser.
            xmlhttp = false;
        }
    }
//If we are using a non-IE browser, create a javascript instance of the object.
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        xmlhttp = new XMLHttpRequest();
        //alert ("You are not using Microsoft Internet Explorer");
    }
</script>

<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
    <div class="">
        <a href="<?php echo base_url(); ?>super_admin">Dashboard</a>->>
        <span>Add <?php // echo $user_role;        ?> Edit User</span>
    </div>
    <hr>
    <h3 class="page-header">Edit <?php
        if ($student_info) {
            echo $student_info->last_name;
        }
        ?>'s Information</h3>
    <p>
        <?php
        $message = $this->session->userdata('message');
        $this->session->unset_userdata('message');
        if ($message) {
            echo $message;
        }
        ?>
    </p>

    <div class="table-responsive col-sm-12">
        <?php echo validation_errors(); ?>
        <form action="<?php echo base_url(); ?>smis/edit_student_information/<?php echo $student_info->student_id; ?>" method="post" name="studentForm" enctype="multipart/form-data" >
            <div class="form-group col-sm-12">
                <div class="form-group col-sm-4">
                    <label for="email">Email:</label><span class="required"> * </span>
                    <input type="hidden" name="person_id" id="email_status_value" value="<?php
                    if ($student_info) {
                        echo $student_info->person_id;
                    }
                    ?>"/>
                    <input type="email" class="form-control" id="user_email" name="email" placeholder="Enter email"  value="<?php
                    if ($student_info) {
                        echo $student_info->email;
                    } echo set_value('email');
                    ?>" onblur="checkUserEmail(this.value, 'email_status')"autofocus >
                </div>
                <div class="form-group col-sm-8" id=""></div>
                <div class="form-group col-sm-4" id="email_status"></div>
                <div class="form-group col-sm-4"><?php echo form_error('user_email'); ?></div>                
            </div>

            <div class="form-group col-sm-10">
                <div class="form-group col-sm-4">
                    <label for="first_name">First Name</label><span class="required"> * </span>
                    <input type="text" class="form-control" id="first_name" name="first_name" value="<?php
                    if ($student_info) {
                        echo $student_info->first_name;
                    } echo set_value('first_name');
                    ?>" placeholder="Enter First Name" >
                </div>
                <div class="form-group col-sm-4">
                    <label for="last_name">Last Name</label>
                    <input type="text" class="form-control" id="last_name" name="last_name" placeholder="Enter Last Name" value="<?php
                    if ($student_info) {
                        echo $student_info->last_name;
                    }echo set_value('last_name');
                    ?>">
                </div>
                <div class="form-group col-sm-7"><?php echo form_error('first_name'); ?></div>
            </div>

            <div class="form-group col-sm-10">
                <div class="form-group col-sm-4">
                    <label for="password">Password</label><span class="required"> * <?php echo form_error('password'); ?></span>
                    <input type="password" class="form-control" id="user_password" name="password" onblur="noticeField(this.value, 'password_status');" placeholder="Password" >
                </div>

                <div class="form-group col-sm-10" id="password_status">

                </div>
                <div class="form-group col-sm-4 danger"><?php echo form_error('password'); ?></div>
            </div>

            <div class="form-group col-sm-12">
                <div class="form-group col-sm-4">
                    <label for="country">Country</label><span class="required"> * </span>
                    <select class="form-control" name="country" >
                        <option value="">--Select Country--</option>
                        <?php foreach ($all_country as $v_country) { ?>
                            <option value="<?php echo $v_country->country_id; ?>"> <?php echo $v_country->country_name ?></option>
                        <?php } ?>
                    </select>
                </div>
                <div class="form-group col-sm-4">
                    <label for="city">City</label>
                    <select class="form-control" name="city">
                        <option value="">--Select City--</option>
                        <?php foreach ($all_city as $v_city) { ?>
                            <option value="<?php echo $v_city->city_id; ?>"> <?php echo $v_city->city_name ?></option>
                        <?php } ?>
                    </select>
                </div>

                <div class="form-group col-sm-12 danger"><?php echo form_error('country'); ?></div>

                <div class="form-group col-sm-6">
                    <label for="address">Address</label>
                    <textarea name="address" class="form-control" ><?php
                        if ($student_info) {
                            echo $student_info->address;
                        } echo set_value('address');
                        ?></textarea>
                </div>

                <div class="form-group col-sm-2">
                    <label for="zip">Zip/Postal Code</label>
                    <input type="text" name="zip" maxlength="5" class="form-control" value="<?php
                    if ($student_info) {
                        echo $student_info->zip;
                    } else {
                        echo set_value('zip');
                    };
                    ?>" >
                </div>

                <div class="form-group col-sm-10">
                    <div class="form-group col-sm-4">
                        <label for="contact_number">Contact Number</label>
                        <input type="text" maxlength="11" class="form-control" name="contact_number" id="contact_number" placeholder="Contact Number" value="<?php
                        if ($student_info) {
                            echo $student_info->contact_number;
                        } echo set_value('contact_number');
                        ?>">
                    </div>
                    <div class="form-group col-sm-7"><?php echo form_error('contact_number'); ?></div>
                </div>
                <div class="form-group col-sm-8">
                    <label for="user_image" >Image</label>
                    <input type="hidden" id="user_image" name="image" value="<?php echo $student_info->person_image; ?>">
                    <input type="hidden" id="user_image_thumb" name="image_thumb" required value="<?php echo $student_info->person_image_thumb; ?>">
                    <input type="file" id="user_image" name="new_image" onchange="readURL(this, 'photo_0')" >
                    <div id="image" style="float: right;" ></div>
                    <img width="100" height="100" src="<?php echo base_url() . $student_info->person_image; ?>" />
                </div>

            </div>

            <div class="form-group col-sm-8">
                <div class="form-group col-sm-8">
                    <label for="status">Status</label><span class="required"> * <?php echo form_error('status'); ?></span>
                    <input type="radio" name="status" id="status" value="1"  />Active
                    <input type="radio" name="status" id="status" value="2" />Inactive
                </div>

                <div class="checkbox col-sm-6" >
                    <button type="submit" id="submit" class="btn btn-default">Submit</button>
                    <button type="reset" class="btn btn-default">Reset</button>
                </div>
            </div>

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


<script type="text/javascript">

    document.forms['studentForm'].elements['country'].value = '<?php
                               if ($student_info) {
                                   echo $student_info->country_id;
                               } echo set_value('country');
                        ?>';
    document.forms['studentForm'].elements['city'].value = '<?php
                               if ($student_info) {
                                   echo $student_info->city_id;
                               }echo set_value('city');
                        ?>';
    document.forms['studentForm'].elements['type_id'].value = '<?php
                               if ($student_info) {
                                   echo $student_info->type_id;
                               } echo set_value('type_id');
                        ?>';
    document.forms['studentForm'].elements['status'].value = '<?php
                               if ($student_info) {
                                   echo $student_info->status;
                               }echo set_value('status');
                        ?>';

</script>