<script>
    var urlValue = '';
    var sat='1';
</script>
<div class="col-sm-10">


    <div class="row ">
        <div class="col-sm-12 ">
            <div class="col-sm-12 gray ">
                <div class="col-sm-12">
                    <h3 class="text-center">Update Group </h3>  
                    <hr>


                </div>

                <div class="col-sm-12"><br></div>
                <!--<div class="col-md-12" style="border: 1px solid green"></div>-->
                <div class="col-sm-12"><br></div>
                <div class="col-sm-12">


                           <?php
                 $url = 'update-group-value';
                 echo form_open_multipart($url, 'class="cmxform" id="formID3" name="edit_group" onsubmit="return submitGroup()"');
                  ?>           

                    <div class="col-sm-10 ">
                        <!--<form action="#"  method="post"  enctype="multipart/form-data">-->
                            <div class="form-group col-sm-12">
                                <input type="hidden" name="group_id" id="group_id" value=" <?php echo  $edit_group->group_id;?> ">
                                <div class="input-group">
                                    <input name="group_name" id="group_name" type="text" class="form-control validate[required]" 
                                           oninput="checkgroupUrlValue('',this.value,urlValue)"
                                            value="<?php echo $edit_group->group_name; ?>"
                                           placeholder="Please Type Group Name.."   >
                                    <span class="input-group-addon"  title="Please Type Group Name"><i class="fa fa-group"></i></span>
                                   
                                </div>
                                <div class="col-sm-12" id="video_course_title_error" style="color: red"><?php echo form_error('group_name'); ?></div>
                                
                            </div>   
                        <div class="form-group col-sm-12"></div>
                            <div class="form-group col-sm-6">
                                     <?php //$type_name=$group_type->group_type_name;?>
                                <select name="group_type_id" class="form-control validate[required]" id="account-type" onchange="otherCategory(this.value)">
                                    <option value=""> -Select Group Type- </option>
                                    <?php foreach($group_type_all as $val) {?>
                                    <?php if($val->group_type_id==$edit_group->group_type_id){ ?>
                                       
                                    <option selected value="<?php echo $val->group_type_id; ?>"><?php echo $val->group_type_name; ?>
                                   
                                    </option>
                                    <?php } else{ ?>
                                   
                                    <option value="<?php echo $val->group_type_id; ?>"><?php echo $val->group_type_name; ?>
                                   
                                    </option>
                                    
                                    <?php } }?>
                                    
                                </select>
                               
                            </div>
                          <div class="col-sm-12" id="video_course_title_error" style="color: red"><?php echo form_error('group_type_id'); ?></div>
                            

                            <div class="form-group col-sm-12"></div>
                            <div class="form-group col-sm-6">

                                <div class="input-group">
                                    <input name="invitation_code" oninput="invitecode(this.value)" type="text"  class="form-control validate[required, custom[spaceFunction]] text-input" placeholder="Please Type  Invitation Code.." value="<?php echo $edit_group->group_public_id; ?>"   >
                                    <span class="input-group-addon"  title="Please Type  Invitation Code"><i class="fa fa-newspaper-o"></i></span>
                               
                                </div>
                                  
                                <div class="col-sm-12" id="video_course_title_error" style="color: red"><?php echo form_error('group_type_id'); ?></div>
                                <div class="col-sm-12"  id="incode" style="color: red"></div>
                               <input type="hidden" name="incode_status" id="incode_status" value="0">
                             

                            </div>    
                            
                            <div class="form-group col-sm-6">
                                <div class="input-group">
                                    <input name="group_url" id="group_url" type="text" 
                                           class="form-control validate[required, custom[urlSpecialCaracter], custom[spaceFunction], custom[urlExistence], custom[noCapital], custom[checkUrlHypen], custom[checkUrlHypenLast]]" 
                                           oninput="checkgroupUrlValue(event,group_name.value,this.value)"
                                          value="<?php echo $url_info ;?>"
                                           placeholder="Please Type Group URL.."   >
                                    <span class="input-group-addon"  title="Please Type Group URL"><i class="fa fa-link"></i></span>
                                    
                                </div>
                                <div class="col-sm-12" id="video_course_title_error" style="color: red"><?php echo form_error('group_url'); ?></div>
                            </div>
                            <div class="form-group col-sm-6" id="url_check" style="color: red"></div>
                            </div>
                    
                             <input type="hidden" id="url_exist" value="">
                             <input type="hidden" id="url_stat" value="0">
                        
                             <input type="hidden" id="url_id" name="url_id" value="<?php echo $url_id->url_id;?>">

                        <div class="form-group col-sm-12"></div>
                          <script>
                                        function checkgroupUrlValue(event,videoCourseTitle, urlInput) {
                                           // url_id(urlInput);
                                            if (event !== '') {
                                             sat = '2';
                                             } 
                                        if (sat === '1') {
                                                makegroupUrl(videoCourseTitle);
                                            } else if(sat === '2') {
                                             // checkgroupURLExists(urlInput, '');
                                             url_id_exists( urlInput);
                                            }
                                    }
                                    </script>


                            <div class="form-group col-sm-12" >
                                <div class="input-group text-left" id="screen1280" >
                                    <label>Group Description</label>
                                    <textarea name="group_description[]"  class="form-control  resoulation1280 " rows="4"  placeholder="Video Training Objective" ><?php echo $edit_group->group_description; ?></textarea>
                                
                                </div>

                                <div class="input-group" id="screen1024" >
                                    <label>Group Description</label>
                                    <textarea name="group_description[]"    class="form-control  resoulation1024 " rows="4"   placeholder="Video Training Objective"  ><?php echo $edit_group->group_description; ?></textarea>
                                </div>
                                <div class="input-group" id="screenMobile" >
                                    <label>Group Description</label>
                                    <textarea name="group_description[]"    class="form-control  resoulationMobile " rows="4"   placeholder="Video Training Objective"  ><?php echo $edit_group->group_description; ?></textarea>
                                </div>

                                <div class="input-group " id="screenMobile_max499" >
                                    <label>Group Description</label>
                                    <textarea  name="group_description[]"   class="form-control  resoulationMobile_max499 " rows="4"   placeholder="Video Training Objective"><?php echo $edit_group->group_description; ?></textarea>
                                </div>
                            </div>
                           <div class="form-group col-sm-12"></div>
                            <div class="form-group col-sm-6">
                                <select name="user_permission" class="form-control validate[required]">
                                    <option value=""> -Select User Permission - </option>
                                   <?php if($edit_group->group_permission ==1){?>
                                    <option value="1"  selected>Public</option>
                                    <option value="4" >Only group Member</option>
                                   <?php } else if($edit_group->group_permission ==4){?>
                                    <option value="4" selected >Only group Member</option>
                                    <option value="1" >Public</option>
                                   <?php }?>
                                </select>
                                  <div class="col-sm-12" id="video_course_title_error" style="color: red"><?php echo form_error('user_permission'); ?></div>
                               
                            </div>
                    <div class="form-group col-sm-12"></div>
                            <div class="form-group col-sm-10">

                                    <label class="col-sm-2 text-left padding-zero" for="person_status"> Status : &nbsp;</label>
                                    <div class="radio radio-success col-sm-10 margin-zero" >
                                      <?php if ( $edit_group->group_status ==0 ){?>  
                                        <input  class="  validate[required]"  type="radio" name="group_status" id="unpublished" value="0" checked>
                                      <label for="Unpublishded">Unpublishded</label>
                                     <span style="margin-right: 30px"></span>
                                      <input  class=" validate[required]"  type="radio" name="group_status" id="published" value="1" >
                                       <label for="Published">Published</label>
                                       <span style="margin-right: 30px"></span>
                                       <input type="radio" class=" validate[required]" name="group_status"  id="archived" value="2" >
                                        <label for="archived">Archived</label>
                                        <span style="margin-right: 30px"></span>
                                    
                                      <?php } else if($edit_group->group_status==1){?>
                                         
                                    <input  class="  validate[required]"  type="radio" name="group_status" id="unpublished" value="0">
                                      <label for="Unpublishded">Unpublishded</label>
                                     <span style="margin-right: 30px"></span>
                                      <input  class=" validate[required]"  type="radio" name="group_status" id="published" value="1" checked>
                                       <label for="Published">Published</label>
                                       <span style="margin-right: 30px"></span>
                                       <input type="radio" class=" validate[required]" name="group_status"  id="archived" value="2" >
                                        <label for="archived">Archived</label>
                                        <span style="margin-right: 30px"></span>
                                    
                                      <?php } else if($edit_group->group_status==2){?>
                                        
                                    <input  class="  validate[required]"  type="radio" name="group_status" id="unpublished" value="0">
                                      <label for="Unpublishded">Unpublishded</label>
                                     <span style="margin-right: 30px"></span>
                                      <input  class=" validate[required]"  type="radio" name="group_status" id="published" value="1" >
                                       <label for="Published">Published</label>
                                       <span style="margin-right: 30px"></span>
                                       <input type="radio" class=" validate[required]" name="group_status"  id="archived" value="2" checked>
                                        <label for="archived">Archived</label>
                                        <span style="margin-right: 30px"></span>
                                    
                                      <?php } ?>
                                    </div>
                                     <div class="col-sm-12" id="video_course_title_error" style="color: red"><?php echo form_error('group_status'); ?></div>
                               

                            </div>






                            <div class="col-sm-12"><br><br></div>

                            <div class="form-group col-sm-4 col-sm-offset-4">

                                <input type="submit" class="green-btn btn btn-default" value="Update Group !"><br/><br/>
                            </div>
                            <div class="col-sm-4"></div>

                        <!--</form>-->
 <?php echo form_close(); ?>

                    </div>

                </div>
             

            </div>
        </div>

    </div>
    <br>
    <div class="row gray">

        <div class="col-sm-12 ">

            <div class="col-sm-12 text-left">
                <label><a href="<?php echo base_url() ?>super_admin()">Dashboard </a>->><a href="<?php echo base_url() ?>super_admin()"> Manage Group </a>Create Group</label>
            </div>    
        </div>
    </div>

    <div class="col-sm-12"><br><br></div>


</div>


<!--java script function-->
<script type="text/javascript" src="<?php echo base_url(); ?>back_end_resource/group/group.js">
</script>
<script>
    checkgroupURLExistsURL = '<?php echo base_url() . 'group-url-exists' ?>';
</script>
<script>
    function otherCategory(givenText) {

        if (givenText == 'Other') {
            var Othercategory = document.getElementById('Ocategory');
            Othercategory.setAttribute("style", 'display:block; ');
        } else {
            var Othercategory = document.getElementById('Ocategory');
            Othercategory.setAttribute("style", 'display:none; ');
        }
    }
     function  submitGroup(){
           var inco_stat= document.getElementById('incode_status').value;
           var url_stat= document.getElementById('url_stat').value;
           if(inco_stat=='1' || url_stat=='1'){
               return false;
           }else{

           }
       }
    
   
</script>
<script>
    function invitecode(inco){
        var xmlhttp4 = false;
        try {
            xmlhttp4 = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp4 = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                xmlhttp4 = false;
            }
        }
        if (!xmlhttp4 && typeof XMLHttpRequest != 'undefined') {
            xmlhttp4 = new XMLHttpRequest();
        }
        var url='<?php echo base_url(); ?>' +'check-edit-invite-code';
     //alert(inco);
     var group_id = document.getElementById('group_id').value;
            var formdata = new FormData();
            formdata.append("group_public_id", inco);
            formdata.append("group_id", group_id);
         xmlhttp4.addEventListener("load", function () {
            // alert(xmlhttp4.responseText);
        if( xmlhttp4.responseText ==1){
            
            document.getElementById('incode').innerHTML="This Invitation code has already been exsist.Please try another one"
              document.getElementById('incode_status').value=1;
        }
        else{
            document.getElementById('incode').innerHTML="";
              document.getElementById('incode_status').value=0;
        }
          
     
            }, false);
            xmlhttp4.addEventListener("error", function () {
                alert("not upload");
            }, false);
            xmlhttp4.addEventListener("abort", function () {
                alert("Aborted");
            }, false);

            xmlhttp4.open("POST", url);
            xmlhttp4.send(formdata);

    }
      function url_id_exists(url_name){
        //  alert(url_id);
          
        var xmlhttp5 = false;
        try {
            xmlhttp5 = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp5 = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                xmlhttp5 = false;
            }
        }
        if (!xmlhttp5 && typeof XMLHttpRequest != 'undefined') {
            xmlhttp5 = new XMLHttpRequest();
        }
        var url='<?php echo base_url(); ?>' +'check-edit-url-code';
      //alert(inco);
     var url_id = document.getElementById('url_id').value;
            var formdata = new FormData();
            formdata.append("url_name", url_name);
            formdata.append("url_id", url_id);
         xmlhttp5.addEventListener("load", function () {
             //alert(xmlhttp5.responseText);
        if( xmlhttp5.responseText ==1){
            
            document.getElementById('url_check').innerHTML="This URL has already been exsist.Please try another one"
              document.getElementById('url_stat').value=1;
        }
        else{
            document.getElementById('url_check').innerHTML="";
              document.getElementById('url_stat').value=0;
        }
          
     
            }, false);
            xmlhttp5.addEventListener("error", function () {
                alert("not upload");
            }, false);
            xmlhttp5.addEventListener("abort", function () {
                alert("Aborted");
            }, false);

            xmlhttp5.open("POST", url);
            xmlhttp5.send(formdata);

    }
  
</script>