<script>
    $.noConflict();
    function documentID(el) {
        return document.getElementById(el);
    }
</script>
<?php
$person_id = $this->session->userdata('person_id');
?>
<div class="col-sm-10 " >
    <div class="col-sm-12 gray_ttc " >
        <div class="col-sm-12 h3 text-center">
            Update Course Category
            <hr>
            <br>
        </div>
        <?php
        echo validation_errors();
        $url = 'super-admin/edit-course-category/' . $category_value->url;
        echo form_open($url, 'class="cmxform" id="formID3" name="edit_course_category"');
        ?>
        <div class="form-group col-sm-12">
            <div class="form-group col-sm-5">
                <div class="input-group">
                    <input type="text" 
                           data-errormessage-value-missing="Category Name is required!"  placeholder="Please type Course category Name"
                           class="form-control validate[required, custom[categoryNameExists]] text-input"
                           oninput="checkCategoryNameExists(this.value)"
                           data-errormessage-value-missing="Please type Category name"
                           id="course_category_name" 
                           name="course_category_name"
                           value="<?php
                           if (set_value('course_category_name')) {
                               echo set_value('course_category_name');
                           } else {
                               echo $category_value->course_category_name;
                           }
                           ?>" >
                    <span class="input-group-addon" id="basic-addon1" title="Please type Category Name"><i class="fa fa-book"></i></span>
                    <input type="hidden" name="old_course_category_name" id="old_course_category_name" value="<?php echo $category_value->course_category_name; ?>">
                    <input type="hidden" id="category_name_exists" value="">
                    <input type="hidden" name="person_id" value="<?php echo $category_value->person_id; ?>">
                </div>
            </div>

            <script>
                function checkCategoryNameExists(input) {
                    var old_course_category_name = documentID('old_course_category_name').value;
                    if (old_course_category_name == input) {
                        documentID('category_name_exists').value = '';
                    } else {
                        var xmlhttp = false;
                        try {
                            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                        } catch (e) {
                            try {
                                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                            } catch (E) {
                                xmlhttp = false;
                            }
                        }
                        if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
                            xmlhttp = new XMLHttpRequest();
                        }

                        var category_name = input.replace(/  +/g, ' ');

                        serverPage = '<?php echo base_url() ?>super-admin/category-name-existance/' + category_name;
                        xmlhttp.open("GET", serverPage);
                        xmlhttp.onreadystatechange = function ()
                        {
                            if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                            {
                                documentID('category_name_exists').value = xmlhttp.responseText;
                            }
                        }
                        xmlhttp.send(null);
                        makeManuUrl(input);
                    }
                }

                function makeManuUrl(profileID) {
                    if (profileID == '') {
                        documentID('menu_url').value = '';
                    } else {
                        for (i = 0; profileID.length > i; i++) {
                            if (profileID.charAt(i) === ' ') {
                                profileID = profileID.replace(/ +/g, '-');
                            }
                            if (profileID.charAt(i) === '.') {
                                profileID = profileID.replace(/\./g, '');
                            }
                            if (profileID.charAt(i) === '-') {
                                profileID = profileID.replace(/--/g, '-');
                            }

                        }
                        if (profileID.charAt(profileID.length - 1) === '-') {
                            profileID = setCharAt(profileID, profileID.length - 1, '');
                        }
                        profileID = profileID.toLowerCase();

                        documentID('course_category_url').value = profileID;
                        checkProfileUrl(profileID);
                    }
                }
            </script>

            <div class="form-group col-sm-5">
                <div class="input-group">
                    <input  type="text" 
                            data-errormessage-value-missing="Category URl is required!"
                            class="form-control validate[required], custom[urlSpecialCaracter], custom[spaceFunction], custom[urlExistence], custom[noCapital]] text-input" 
                            id="course_category_url" 
                            name="course_category_url"
                            oninput="checkProfileUrl(this.value)"
                            placeholder="Give a category URL"  
                            value="<?php
                            if (set_value('course_category_url')) {
                                echo set_value('course_category_url');
                            } else {
                                echo $category_value->url;
                            }
                            ?>" >
                    <input type="hidden" name="old_course_category_url" id="old_course_category_url" value="<?php echo $category_value->url; ?>">
                    <input type="hidden" name="old_url_id" id="old_url_id" value="<?php echo $category_value->url_id; ?>">
                    <input type="hidden" name="url_exist" id="url_exist" value="">
                    <span class="input-group-addon" id="basic-addon1" title="Please type Category URl "><i class="fa fa-link"></i></span>
                </div>
            </div>
            <script>
                function checkProfileUrl(given_text) {
                    var old_url = documentID('old_course_category_url').value;
                    if (old_url == given_text) {
                        documentID('url_exist').value = '';
                    } else {
                        var xmlhttp2 = false;
                        try {
                            xmlhttp2 = new ActiveXObject("Msxml2.XMLHTTP");
                        } catch (e) {
                            try {
                                xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
                            } catch (E) {
                                xmlhttp2 = false;
                            }
                        }
                        if (!xmlhttp2 && typeof XMLHttpRequest != 'undefined') {
                            xmlhttp2 = new XMLHttpRequest();
                        }

                        if (given_text != '') {
                            serverPage = '<?php echo base_url(); ?>super_admin/check_profile_id_existance/' + given_text;
                            xmlhttp2.open("GET", serverPage);
                            xmlhttp2.onreadystatechange = function ()
                            {
                                if (xmlhttp2.readyState == 4 && xmlhttp2.status == 200)
                                {
                                    if (xmlhttp2.responseText == 1)
                                    {
                                        documentID('url_exist').value = '1';
                                    } else if (xmlhttp2.responseText == 2)
                                    {
                                        documentID('url_exist').value = '';
                                    }
                                }
                            }
                            xmlhttp2.send(null);
                        } else if (given_text == '') {
                        }
                    }
                }
            </script>
        </div>
        <div class="form-group col-sm-12">
            <div class="form-group col-sm-5">
                <div class="input-group ">
                    <input type="text"
                           data-errormessage-value-missing="Please type Course Category Author" 
                           class="form-control" 
                           name="course_category_author" 
                           id="course_category_author"
                           value="<?php
                           if (set_value('course_category_author')) {
                               echo set_value('course_category_author');
                           } else {
                               echo $category_value->course_category_author;
                           }
                           ?>" 
                           placeholder="Please type Course Category Author"> 
                    <span class="input-group-addon" id="basic-addon1" title="Please type Course Category Author"><i class="fa fa-user"></i></span>
                </div>
            </div>
            <?php
//                           echo '<pre>';
//                           print_r($all_course_category);

            if ($all_course_category) {
                ?>
                <div class="form-group col-sm-5">
                    <div class="input-group ">
                        <select data-errormessage-value-missing="Course Category is required!"  
                                class="form-control" 
                                name="course_category_id" 
                                id="course_category_id"  >
                            <option value=" ">Select Parent Category</option>
                            <?php
                            foreach ($all_course_category as $category_value1) {
                                echo '<option value="' . $category_value1->course_category_id . '">' . $category_value1->course_category_name . '</option>';
                            }
                            ?>
                        </select>
                        <span class="input-group-addon" id="basic-addon1" title="Please Select "><i class="fa fa-list"></i></span>
                    </div>
                    <script>
                        document.forms['edit_course_category'].elements['course_category_id'].value = '<?php
                        if (set_value('course_category_id')) {
                            echo set_value('course_category_id');
                        } else {
                            echo $category_value1->course_category_parent_id;
                        }
                        ?>';
                    </script>
                </div>
            <?php } ?>
        </div>
        <div class="form-group col-sm-12">
            <div class="form-group col-sm-10">
                <div class="input-group col-sm-12">
                    <input class="col-sm-12"
                           type="hidden" name="to_address" id="to_address" value="" >
                    <div class="col-sm-12 padding-zero">
                        <select name="course_category_meta_keywords[]"  id="course_category_meta_keywords" 
                                data-errormessage-value-missing="Interest Field is is Required!"
                                class="tokenize-sample validate[]"
                                title="" 
                                multiple="multiple" style="margin: 0px; padding: 0px; border: 0px; display: none;">
                                    <?php
                                    if (set_value('to_address')) {
                                        $keyword_string = set_value('to_address');
                                        $keywords = explode(",", $keyword_string);
                                        for ($i = 0; $i < (count($keywords) - 1); $i++) {
                                            ?>
                                    <option value="<?php echo $keywords[$i]; ?>" selected><?php echo $keywords[$i]; ?></option>
                                    <?php
                                }
                            } else {
                                $keyword_string = $category_value->course_category_meta_keywords;
                                $keywords = explode(",", $keyword_string);
                                for ($i = 0; $i < count($keywords); $i++) {
                                    ?>
                                    <option value="<?php echo $keywords[$i]; ?>" selected><?php echo $keywords[$i]; ?></option>
                                    <?php
                                }
                            }
                            ?>
                        </select>
                    </div>
                    <script type="text/javascript">
                        $('select#course_category_meta_keywords').tokenize({placeholder: "Please Type Meta Keyword"});
                    </script>
                </div>
            </div>
        </div>
        <?php
//        
//        echo "<script type=\"text/javascript\">";
//echo "document.write(Hello World!)";
//echo "</script>";
//        echo "<script type=\"text/javascript\">";
//        echo '<script language="javascript">';
//echo 'message successfully sent';
//echo '</script>';
//                            echo '<pre>';
//        echo '<script type="text/javascript">    
//  <!--      // spam protected email     
//  emailE=("enquiries@" + "example.co.uk")     
//  document.write(\'<a title="E-mail Example" href="mailto:3232">32323</a>\')      
//  //-->     
//  </script>     
//  <noscript>         
//  <span class="spam-protected">Email address protected by JavaScript. Please enable JavaScript.</span>     
//  </noscript>'; 
        ?>

        <div class="form-group col-sm-12">
            <div class="form-group col-sm-10">
                <div class="input-group text-left" id="screen1280" >
                    <label>Category Meta Description</label>
                    <textarea   class="form-control resoulation1280" 
                                name="course_category_meta_description[]"
                                rows="4"><?php
        if (set_value('course_category_meta_description')) {
            echo set_value('course_category_meta_description');
        } else {
            echo $category_value->course_category_meta_description;
        }
        ?></textarea>
                </div>

                <div class="input-group text-left" id="screen1024" >
                    <label>Category Meta Description</label>
                    <textarea   class="form-control  resoulation1024" 
                                name="course_category_meta_description[]"
                                rows="4"><?php
                                    if (set_value('course_category_meta_description')) {
                                        echo set_value('course_category_meta_description');
                                    } else {
                                        echo $category_value->course_category_meta_description;
                                    }
        ?></textarea>
                </div>
                <div class="input-group text-left" id="screenMobile" >
                    <label>Category Meta Description</label>
                    <textarea   class="form-control  resoulationMobile" 
                                name="course_category_meta_description[]"
                                rows="4"><?php
                                    if (set_value('course_category_meta_description')) {
                                        echo set_value('course_category_meta_description');
                                    } else {
                                        echo $category_value->course_category_meta_description;
                                    }
        ?></textarea>
                </div>
                <div class="input-group text-left" id="screenMobile_max499" >
                    <label>Category Meta Description</label>
                    <textarea   class="form-control  resoulationMobile_max499" 
                                name="course_category_meta_description[]"
                                rows="4"><?php
                                    if (set_value('course_category_meta_description')) {
                                        echo set_value('course_category_meta_description');
                                    } else {
                                        echo $category_value->course_category_meta_description;
                                    }
        ?></textarea>
                </div>
            </div>
        </div>

        <div class="form-group col-sm-12">
            <div class="form-group col-sm-10">
                <div class="input-group text-left" id="screen1280" >
                    <label>Course Category Description</label>
                    <textarea class="form-control  resoulation1280"
                              name="course_category_description[]"
                              rows="4"><?php
                                    if (set_value('course_category_description')) {
                                        echo set_value('course_category_description');
                                    } else {
                                        echo $category_value->course_category_description;
                                    }
        ?></textarea>
                </div>
                <div class="input-group text-left" id="screen1024" >
                    <label>Course Category Description</label>
                    <textarea class="form-control resoulation1024"
                              name="course_category_description[]"
                              rows="4"><?php
                                  if (set_value('course_category_description')) {
                                      echo set_value('course_category_description');
                                  } else {
                                      echo $category_value->course_category_description;
                                  }
        ?></textarea>
                </div>
                <div class="input-group text-left" id="screenMobile" >
                    <label>Course Category Description</label>
                    <textarea   class="form-control  resoulationMobile "
                                name="course_category_description[]"
                                rows="4"><?php
                                  if (set_value('course_category_description')) {
                                      echo set_value('course_category_description');
                                  } else {
                                      echo $category_value->course_category_description;
                                  }
        ?></textarea>
                </div>
                <div class="input-group text-left" id="screenMobile_max499" >
                    <label>Course Category Description</label>
                    <textarea class="form-control  resoulationMobile_max499" 
                              name="course_category_description[]"
                              rows="4"><?php
                                    if (set_value('course_category_description')) {
                                        echo set_value('course_category_description');
                                    } else {
                                        echo $category_value->course_category_description;
                                    }
        ?></textarea>
                </div>
            </div>
        </div>

        <div class="form-group col-sm-12">
            <div class="form-group col-sm-5">
                <div class="input-group ">
                    <select data-errormessage-value-missing="Please Select Course Category Access Level" 
                            class="form-control validate[required]" 
                            name="course_category_access_level" 
                            id="course_category_access_level">
                        <option value="">Select Access Level</option>
                        <option value="1">Public</option>
                        <option value="2">TalhaTraining User</option>
                    </select>
                    <span class="input-group-addon" id="basic-addon1" title="Please Select Course Category Access Level"><i class="fa fa-user"></i></span>
                </div>
            </div>
        </div>



        <div class="form-group col-sm-12">
            <div class="form-group col-sm-10">
                <label class="col-sm-1 text-left padding-zero" for="person_status"> Status : &nbsp;</label>
                <div class="radio radio-success col-sm-11 margin-zero" >
                    <input type="radio" 
                           class="validate[required]"
                           name="course_category_status" 
                           id="published" value="1">
                    <label for="published">Active</label>
                    <span style="margin-right: 30px"></span>
                    <input type="radio"
                           class="validate[required]"
                           name="course_category_status" 
                           id="unpublished" value="2">
                    <label for="unpublishded">Inactive</label>
                    <span style="margin-right: 30px"></span>
                    <input type="radio"
                           class="validate[required]"
                           name="course_category_status" 
                           id="archived" value="3">
                    <label for="archived">Archived</label>
                    <span style="margin-right: 30px"></span>
                    <input type="radio" 
                           class="validate[required]"
                           name="course_category_status" 
                           id="pending" value="4">
                    <label for="pending">Pending</label>
                    <span style="margin-right: 30px"></span>
                    <input type="radio" 
                           class="validate[required]"
                           name="course_category_status" 
                           id="approved" value="5">
                    <label for="approved">Approved</label>
                </div>
            </div>
        </div>
        <div class="form-group col-sm-12">
            <div class="form-group col-sm-8">
                <div class="checkbox checkbox-success">
                    <input id="checkbox1" 
                           name="course_category_home_page_view" 
                           class="styled" type="checkbox"
                           value="2">
                    <label for="course_category_home_page_view">View in Home Page ?
                    </label>
                </div>
            </div>
            <div class="form-group col-sm-8">
                <div id="submit_status"></div>
                <div class="checkbox col-sm-12">
                    <center> 
                        <button type="submit" id="submit" class="btn btn-default" >Submit</button>
                    </center>
                </div>
            </div>
        </div>
        <?php echo form_close(); ?>
    </div>
</div>
<script>
    document.forms['edit_course_category'].elements['course_category_access_level'].value = '<?php
        if (set_value('course_category_access_level')) {
            echo set_value('course_category_access_level');
        } else {
            echo $category_value->course_category_access_level;
        }
        ?>';
    document.forms['edit_course_category'].elements['course_category_status'].value = '<?php
        if (set_value('course_category_status')) {
            echo set_value('course_category_status');
        } else {
            echo $category_value->course_category_status;
        }
        ?>';

    '<?php if (set_value('course_category_home_page_view')) { ?>'
        document.forms['edit_course_category'].elements['course_category_home_page_view'].checked = true;
        '<?php } else if ($category_value->course_category_home_page_view) { ?>'
        document.forms['edit_course_category'].elements['course_category_home_page_view'].checked = true;
        '<?php } ?>'

</script>

