<? global $vis_language;
   $custom_field_count = count($customfield_details);
   $custom_field_type_array = array(4,5,6,7);
   $status =($customfield_details[0]['is_required'] == 1)?'<div class="radio i-checks m-r-lg pull-left"><label><input type="radio" name="vis_isrequired" checked="checked" id="vis_status_yes" value="1" /><i></i> '. $vis_language['TXTYES'].'</label></div><div class="radio i-checks m-r-lg pull-left"><label><input type="radio" name="vis_isrequired" id="vis_status_no" value="0" /><i></i> '. $vis_language['TXTNO'].'</label></div>':'<div class="radio i-checks m-r-lg pull-left"><label><input type="radio" name="vis_isrequired" id="vis_status_yes" value="1" /><i></i> '. $vis_language['TXTYES'].'</label></div><div class="radio i-checks m-r-lg pull-left"><label><input type="radio" name="vis_isrequired" id="vis_status_no" value="0" checked="checked" /><i></i> '. $vis_language['TXTNO'].'</label></div>';

   $user_editable = ($customfield_details[0]['is_user_editable'] == 1)?'<div class="radio i-checks m-r-lg pull-left"><label><input type="radio" name="vis_useredt" checked="checked" id="vis_user_yes" value="1" /><i></i> '. $vis_language['TXTYES'].'</label></div><div class="radio i-checks m-r-lg pull-left"><label><input type="radio" name="vis_useredt" id="vis_user_no" value="0" /><i></i> '. $vis_language['TXTNO'].'</label></div>':'<div class="radio i-checks m-r-lg pull-left"><label><input type="radio" name="vis_useredt" id="vis_user_yes" value="1" /><i></i> '. $vis_language['TXTYES'].'</label></div><div class="radio i-checks m-r-lg pull-left"><label><input type="radio" name="vis_useredt" id="vis_useredt" value="0" checked="checked" /><i></i> '. $vis_language['TXTNO'].'</label></div>';

   $staff_editable  =  ($customfield_details[0]['is_staff_editable'] == 1)?'<div class="radio i-checks m-r-lg pull-left"><label><input type="radio" name="vis_staffedt" checked="checked" id="vis_staff_yes" value="1" /><i></i> '. $vis_language['TXTYES'].'</label></div><div class="radio i-checks m-r-lg pull-left"><label><input type="radio" name="vis_staffedt" id="vis_staff_no" value="0" /><i></i> '. $vis_language['TXTNO'].'</label></div>':'<div class="radio i-checks m-r-lg pull-left"><label><input type="radio" name="vis_staffedt" id="vis_staff_yes" value="1" /><i></i> '. $vis_language['TXTYES'].'</label></div><div class="radio i-checks m-r-lg pull-left"><label><input type="radio" name="vis_staffedt" id="vis_staff_no" value="0" checked="checked" /><i></i> '. $vis_language['TXTNO'].'</label></div>';
   ?>
<section id="breadcrumb" class="row m-b m-l-none m-r-none">
   <div class="col-sm-6">
      <h3 class="m-b-xs text-black"><? echo $operation['view_title'];?></h3>
      <ul class="breadcrumb bg-empty no-border m-b-xxs no-padder">
         <li><a class="link" href="#/home/quick_view/<? echo $vis_language['TXTHOME']; ?>"><? echo $vis_language['TXTHOME']; ?></a></li>
         <li><a class="link" href="#/setting/setting_menu/<? echo $vis_language['TXTSETTINGS'];?>" onclick="$('#vis_workpanel_div').visExecution('load_module','<? echo $vis_language['TXTSETTINGS'];?>',{'vis_module':'setting','vis_operation':'setting_menu'});"><? echo $vis_language['TXTSETTINGS']; ?></a></li>
        <? if($operation['vis_section']=='service'){?>
         <li><a class="link" href="#/setting/view_service_item/<? echo $vis_language['TXTSERVICEITEM']; ?>" class="link"><? echo $vis_language['TXTSERVICEITEM']; ?></a> </li>
         <li> <a href="#/setting/view_service_field/<? echo $operation['view_title']; ?>" class="link"><? echo $operation['view_title']; ?></a></li>
         <? }else{?>
         <li><a class="link" href="#/setting/view_configuration/<? echo $vis_language['TXTCONFIGURATIONITEMTYPE']; ?>" class="link"><? echo $vis_language['TXTCONFIGURATIONITEMTYPE']; ?></a> </li>
         <li> <a href="#/setting/view_cifield/<? echo $vis_language['TXTCICUSTOMFIELD']; ?>" class="link"><? echo $operation['view_title']; ?></a></li>
         <? }?>
         <li class="active"> <?php echo $vis_language['TXTUPDATECICICUSTOMFIELD'];//$vis_language['TXTUPDATECICUSTOMFIELD']; ?></li>
      </ul>
      <div>
      </div>
   </div>
</section>
<section class="padder">
   <section class="panel panel-default">
      <header class="panel-heading sub_header"><?php echo $vis_language['TXTUPDATECICICUSTOMFIELD'];//$vis_language['TXTUPDATECICICUSTOMFIELD']; ?></header>
      <div class="panel-body">
         <form  class="form-horizontal" id="vis_cifield_edit_form" name="vis_cifield_edit_form" method="post">
            <input type="hidden"  name="vis_field_id" id="vis_field_id" value="<?php echo $customfield_details[0]['field_type']; ?>">
            <input type="hidden" id="vis_new_field_count" name="vis_new_field_count">
            <input type="hidden" name="vis_field_count" value="<? echo count($customfield_details); ?>" />
            <input type="hidden" name="vis_field_group" value="<?php echo $customfield_details[0]['field_group']; ?>" >
            <div class="form-group">
               <label class="col-sm-2 control-label font-bold"><? echo $vis_language['TXTFIELDDETAILS']; ?></label>
               <label class="col-sm-10"></label>
            </div>
            <? if(isset($operation['vis_section']) && $operation['vis_section']=='service'){?>
            	<div class="form-group">
                  <label class="col-sm-2 control-label">
                    <?= $vis_language['TXTSERVICEITEM']; ?>
                  </label>
                  <div class='col-sm-10'>
                    <select class='form-control input-sm selectpicker' name="vis_parent" id="vis_parent" <? if(count($service_details) > 10) echo 'data-live-search="true"' ?>>
                      <? for($i=0;$i<count($service_details);$i++){
						   if($customfield_details[0]['customgroup_id']==$service_details[$i]['item_id'])
						   	  $chk='selected="selected"';
						   else
						      $chk = '';
						   echo '<option '.$chk.' value="'.$service_details[$i]['item_id'].'">'.$service_details[$i]['name'].'</option>';
					     }?>
                    </select>
                  </div>
                </div>
                 <input name="vis_section" id="vis_section" type="hidden" value="service"/>
            <? }else{?>
            <input name="vis_parent" id="vis_parent" type="hidden" value="<? echo  $parent_item_details[0]['item_id']; ?>"/>
            <div class="form-group">
			<label class="col-sm-2 text-right"><?= $vis_language['TXTCITYPE']; ?></label>
			<div class="col-sm-10">
            	<span id="vis_parent_category" name="vis_parent_category" style="margin-top:20px;"><? echo  $parent_item_details[0]['name']; ?></span>
				<span class="vis_button label vh-success-bg m vis-pointer" data-toggle="ajaxModal" data-modal-arguments="vis_module=setting&vis_operation=view_configuration&vis_static_area=vis_client_merge_area&vis_set=1&vis_domain_id=<? echo $operation['vis_domain_id'];?>"><? echo $vis_language['TXTCHANGE']; ?></span>
			</div>
			</div>
            <? }?>
            <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTFIELDTITLE']; ?></label>
               <div class="col-sm-10">
                  <input  class="form-control input-sm" type="text" name="vis_customgroup_name" id="vis_customgroup_name" value="<? echo htmlentities($customfield_details[0]['field_name'], ENT_COMPAT, 'UTF-8'); ?>"  >
               </div>
            </div>
            <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTFIELDDESCRIPTION']; ?></label>
               <div class="col-sm-10">
                  <input class="form-control input-sm" type="text" id="vis_desc1" name="vis_desc1"  value="<? echo $customfield_details[0]['field_description']; ?>">
               </div>
            </div>
            <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTDISPLAYORDER']; ?></label>
               <div class="col-sm-10">
                  <input class="form-control input-sm" type="text" name="vis_displayorder" id="vis_displayorder" value="<? echo $customfield_details[0]['display_order']; ?>">
               </div>
            </div>
			  <?php
               if(!in_array($customfield_details[0]['field_type'], $custom_field_type_array) )
               {
               ?>
			   <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTDEFAULTVALUE']; ?></label>
               <div class="col-sm-10">
                  <span class="input-group-addon no-padder no-borders <? if($customfield_details[0]['field_type']==8) echo "start"; ?> "><input class="form-control input-sm" type="text" value="<? echo $customfield_details[0]['default_value']; ?>" name="field0" id="field0"></span>
                  <input class="form-control input-sm" type="hidden" name="custfield0" id="custfield0" value="<? echo $customfield_details[0]['customfield_id'] ?>">
               </div>
            </div>
			<? } ?>
            <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTUSEREDITABLE']; ?></label>
               <div class="col-sm-10">
                  <?php echo $user_editable; ?>
               </div>
            </div>
            <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTSTAFFEDITABLE']; ?></label>
               <div class="col-sm-10">
                  <?php echo $staff_editable; ?>
               </div>
            </div>
            <?php
               if(count($customfield_details) > 1  ||  in_array($customfield_details[0]['field_type'], $custom_field_type_array) )
               {
               ?>
            <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTOPTIONFIELDS']; ?></label>
               <div class="col-sm-10">
			   <table class="table123">
                  <?php
                      for($i=0;$i<count($customfield_details);$i++)  { 
                     ?>
				<tr><td>
				<? if( !in_array($customfield_details[0]['field_type'], array(5,6))) { ?>
				<label class="checkbox-inline p-d-sm i-checks"><input type="checkbox" name="chtab<?= $i; ?>" <? if($customfield_details[$i]['is_selected']==1) echo 'checked="checked"'; ?> value="1"><i></i></label><div class="form-group"></div>			
				<? if($language_details!=-1) {?>
				<label class="col-sm-3 control-label"><?
               for($l=0;$l<count($language_details);$l++) { ?> <? echo $language_details[$l]['language_name']; ?></label><div class="form-group"></div>			
               	<? }} }else {?>
				<div class="radio i-checks p-d-sm"><label><input type="radio" name="rdtab00" <? if($customfield_details[$i]['is_selected']==1) echo 'checked="checked"'; ?> value="<? echo $i; ?>"><i></i> </label></div><div class="form-group"></div>
				<? if($language_details!=-1) {?>
				<label class="col-sm-3 control-label"><?
               for($l=0;$l<count($language_details);$l++) { ?> <? echo $language_details[$l]['language_name']; ?></label><div class="form-group"></div>			
               	<? }}} ?></td>
                  <td><input class="form-control input-sm" type="text" id="<?php echo "field".$i; ?>" name="<?php echo "field".$i; ?>" value="<? echo $customfield_details[$i]['default_value']; ?>"><div class="form-group"></div>
                   <? if($language_details!=-1) { for($l=0;$l<count($language_details);$l++) { ?> <input class="form-control input-sm" type="text" name="vis_language_<? echo "field".$i.$language_details[$l]['language_id']; ?>" type="text" value="<? echo $customfield_array_lang[$i][$language_details[$l]['language_id']]; ?>" /><div class="form-group"></div><?}}?><div class="form-group"></div>
                  <input class="form-control input-sm" type="hidden" id="<?php echo "custfield".$i; ?>" name="<?php echo "custfield".$i; ?>" value="<? echo $customfield_details[$i]['customfield_id']; ?>">
				  </td></tr>
                  <?
                     }  ?>
				</table>
                  <?  	$custom_field_type = $customfield_details[0]['field_type'];
                     	$count = $custom_field_count + 1 ;
                     	if($custom_field_type == 5 || $custom_field_type == 6)
                     	{
                     		$fieldName = 'rdtab';
                     		$inputType = 'radio';
                     	}
                     	elseif($custom_field_type == 4 || $custom_field_type == 7)
                     	{
                     		$fieldName =  'chtab';
                     		$inputType = 'checkbox';
                     	}
                     ?>
                  <table id="<?php echo $fieldName.$count; ?>" class="table123" >
                     <tbody></tbody>
                  </table>
                  <i class="vh vh-plus" style="font-size:10px;"></i><a href="javascript:void(0)" id="newtab"  class="link m-xs" onclick="javascript:new_custom_tab('<?php echo $fieldName.$count;?>');"><? echo $vis_language['TXTADD']; ?></a>
                  <input type="hidden" name="rdcnt1" id="rdcnt1">
               </div>
            </div>
            <?php
               }
                           else
                            {
               			if($customfield_details[0]['field_type']!=8)
               			{
                 ?>
            <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTISREQUIRED']; ?></label>
               <div class="col-sm-10">
                  <? echo $status; ?>
               </div>
            </div>
            <?php
               }
                }

               ?>
            <div class="form-group">
                <label class="col-sm-2 control-label p-d-sm"><? echo $vis_language['TXTSTATUS']; ?></label>
                <div class="col-sm-1">
                   <label class="switch  <? if($customfield_details[0]['is_enabled']==0) echo 'radio-no-uncheck'; ?>  ">
                   <input type="checkbox"  name="vis_status"  id="vis_status" <? if($customfield_details[0]['is_enabled']==1) echo ' checked="checked"'; ?>>
                   <span ></span>
                   </label>
                </div>
            </div>
              <? if($language_details!=-1) { ?>
            <div class="form-group">
               <div class="col-sm-3"><h5><? echo $vis_language['MSGLANGTRANSFORCICUSTOMFIELDS']; ?></h5></div>
            </div>
            <div class="line b-b line-lg pull-in"></div>
            <br/>
            <?
               for($i=0;$i<count($language_details);$i++) { ?>
            <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $language_details[$i]['language_name']; ?></label>
               <div class="col-sm-10">
                  <input class="form-control input-sm" type="text" name="vis_language_<? echo $language_details[$i]['language_id']; ?>" type="text" value="<? echo $customfield_lang[$language_details[$i]['language_id']]; ?>" >
               </div>
            </div>
            <?
               }
               }  ?>
            <div class="line b-b line-lg pull-in"></div>
            <br/>
            <div class="form-group">
               <div class="col-sm-4 col-sm-offset-2">

				 <button type="button" class="btn btn-primary" onclick="$('#vis_workpanel_div').visExecution('submit_form',{'vis_module':'setting', 'vis_operation':'update_cifield', 'is_survey':'1','vis_form':'vis_cifield_edit_form','vis_section':'<?=$operation['vis_section']?>'})"><? echo $vis_language['TXTUPDATE']; ?></button>
               </div>
            </div>
      </div>
      </form>
      </div>
   </section>
</section>
<script>
   $('.start').datetimepicker();
   $(".selectpicker").selectpicker();
</script>
<script language="javascript">
   var fieldCount=0;
   var fieldCnt=0;
   var z=0;
   function new_custom_tab(did)
   {
       var obj = document.getElementById(did);
       var i = obj.rows.length;
       var tr = obj.insertRow(i);
       var td = tr.insertCell(0);
       var objName =   obj.id.substr(0, 5);
       var objeId =   parseInt(obj.id.substr(5, 5)) + parseInt(i);
       if(objName == 'chtab')
       {
	 
         td.innerHTML = '<label class="checkbox-inline p-d-sm i-checks"><input type="checkbox" name="'+objName+objeId+'" id="'+objName+objeId+'" value="1"><i></i> </label><div class="form-group"></div>';
          td.innerHTML += '<? if($language_details!=-1) { ?><label class="col-sm-3 control-label"><?
               for($l=0;$l<count($language_details);$l++) { ?> <? echo $language_details[$l]['language_name']; ?></label><div class="form-group"></div><?}}?>';
         td = tr.insertCell(1);
         td.innerHTML = '<input type="text" name="txt'+objName+objeId+'"  class="form-control input-sm"><div class="form-group"></div> ';
          td.innerHTML += '<? if($language_details!=-1) {for($l=0;$l<count($language_details);$l++) { ?><input type="text" name="vis_language_'+objName+objeId+'<? echo $language_details[$l]['language_id']; ?>" value="<? echo $customfield_array_lang[$language_details[$l]['language_id']]; ?>"  class="form-control input-sm"><div class="form-group"></div><?}}?>';
         document.getElementById('vis_new_field_count').value = objeId;
       }
       if(objName == 'rdtab')
       {
           td.innerHTML = '<div class="radio i-checks p-d-sm"><label><input type="radio" name="radtab00" id="'+objName+objeId+'" value="'+objeId+'"><i></i> </label></div><div class="form-group"></div>';
           td.innerHTML += '<? if($language_details!=-1) { ?><label class="col-sm-3 control-label"><?
               for($l=0;$l<count($language_details);$l++) { ?> <? echo $language_details[$l]['language_name']; ?></label><div class="form-group"></div><?}}?>';
           td = tr.insertCell(1);
           td.innerHTML = '<input type="text" name="txt'+objName+objeId+'" class="form-control input-sm"><div class="form-group"></div>';
            td.innerHTML += '<? if($language_details!=-1) {for($l=0;$l<count($language_details);$l++) { ?><input type="text" name="vis_language_'+objName+objeId+'<? echo $language_details[$l]['language_id']; ?>" value="<? echo $customfield_array_lang[$language_details[$l]['language_id']]; ?>"  class="form-control input-sm"><div class="form-group"></div><?}}?>';
           document.getElementById('vis_new_field_count').value = objeId;
       }
       i++;
   }
</script>
<style>
   .custom{
   border: 1px solid #cbd5dd;
   }
   .table123 td:first-child{
   width:2px;
   }
   .table123 td:nth-child(2){
   width:100%;
   }
   fieldset.scheduler-border {
   border: 1px solid #cbd5dd !important;
   padding: 0 1.4em 1.4em 1.4em !important;
   }
   legend.scheduler-border {
   font-size: 17px !important;
   margin-bottom:4px !important;
   width:inherit !important; /* Or auto */
   border-bottom:none !important;
   font-weight: bold !important;
   }
</style>
