<? global $vis_language; 
   $form_field_count = count($formfield_details);
   $form_field_type_array = array(4,5,6,7);
   $editor = $placeholder = $tooltip = $html_attribute = $field_description = $default_value = $no_of_file = $reg_exp = $is_req = $is_inline = '';
   //echo '<pre>'; print_r($formfield_details); echo '</pre>';
   $htm_attr = stripslashes($formfield_details[0]['html_attribute']);
   
   if($formfield_details[0]['field_type'] == 3   ){ // for textarea
	   $checked_y = ($formfield_details[0]['is_editor']==1)?'checked':'';
	   $checked_n = ($formfield_details[0]['is_editor']==0)?'checked':'';
	   $editor = '<div class="form-group"><div class="col-sm-2 control-label">'.$vis_language['TXTHTMLEDITOR'].'</div><div class="col-sm-10 "><div class="radio i-checks m-r-lg pull-left"><label><input name="vis_editor" id="vis_editor" type="radio" value="1" '.$checked_y.' ><i></i>'.$vis_language['TXTYES'].'</label></div><div class="radio i-checks m-r-lg pull-left"><label><input name="vis_editor" id="vis_editor" type="radio" value="0" '.$checked_n.' ><i></i> '.$vis_language['TXTNO'].'</label></div></div></div>';
   }
	   $placeholder = '<div class="form-group"><div class="col-sm-2 control-label">'.$vis_language['TXTPLACEHOLDER'].'</div><div class="col-sm-10"><input type="text" name="vis_placeholder" id="vis_placeholder" value="'.$formfield_details[0]['placeholder'].'" class="form-control input-sm"></div></div>';
	  
       $tooltip =  '<div class="form-group"><div class="col-sm-2 control-label">'.$vis_language['TXTTOOLTIP'].'</div><div class="col-sm-10"><input type="text" name="vis_tooltip" id="vis_tooltip" value="'.$formfield_details[0]['tooltip'].'" class="form-control input-sm"></div></div>';
	   
	   $html_attribute =  '<div class="form-group"><div class="col-sm-2 control-label">'.$vis_language['TXTHTMLATTRIBUTE'].'</div><div class="col-sm-10"><input type="text" name="vis_html_attribute" id="vis_html_attribute" value=\''.$htm_attr.'\'  class="form-control input-sm" placeholder="'.$vis_language['TXTOPTIONAL'].'" ></div></div>';
	   
	   $field_description='<div class="form-group">
								<div class="col-sm-2  control-label">'.$vis_language['TXTFIELDDESCRIPTION'].'</div>
								<div class="col-sm-10">
									<input name="vis_desc" id="vis_desc"  value="'.$formfield_details[0]['field_description'].'"  type="text" class="form-control input-sm">
								</div>
							</div>';
	   $class = ($formfield_details[0]['field_type']==8)?' start ':'';
	   $default_value='<div class="form-group">
							<div class="col-sm-2 control-label">'.$vis_language['TXTDEFAULTVALUE'].'</div>
							<div class="col-sm-10">
								<input name="vis_def"  id="vis_def" value="'.$formfield_details[0]['default_value'].'" type="text" class="form-control input-sm '.$class.'">
								<input class="form-control input-sm" type="hidden" name="custfield0" id="custfield0" value="'.$formfield_details[0]['formfield_id'].'">
							</div>
						</div>';
	   
	   $note = '<div class="form-group">
					<div class="col-sm-2 control-label">'.$vis_language['TXTCONTENT'].'</div>
					<div class="col-sm-10">
						<textarea   name="vis_desc" id="vis_desc" class="form-control input-sm">'.$formfield_details[0]['field_description'].'</textarea>
						<input class="form-control input-sm" type="hidden" name="custfield0" id="custfield0" value="'.$formfield_details[0]['formfield_id'].'">
					</div>
				</div>';
	   
	  if($formfield_details[0]['field_type'] == 9 ){ //file upload		   
		   $sel1 = ($formfield_details[0]['regular_expression'] == 'text')?'selected="selected"':'';
		   $sel2 = ($formfield_details[0]['regular_expression'] == 'application')?'selected="selected"':''; 
		   $sel3 = ($formfield_details[0]['regular_expression'] == 'image')?'selected="selected"':''; 
		   
		   $no_of_file = '<div class="form-group">
							<div class="col-sm-2 control-label">'.$vis_language['TXTNOOFATTACHMENTS'].'</div>
							<div class="col-sm-10">
								<input type="text" name="vis_file_cnt" id="vis_file_cnt" class="form-control input-sm" value="'.$formfield_details[0]['no_of_file'].'" >
								<input class="form-control input-sm" type="hidden" name="custfield0" id="custfield0" value="'.$formfield_details[0]['formfield_id'].'">
							</div>
						  </div>';
		  
		    $reg_exp = '<div class="form-group">
					<div class="col-sm-2 control-label">'.$vis_language['TXTREGULAREXPRESSIONVALIDATION'].'</div>
					<div class="col-sm-10">
						<select name="vis_regexp" id="vis_regexp" class="input-sm form-control selectpicker">
							<option value="none">'.$vis_language['TXTNONE'].'</option>
							
							<option value="text" '.$sel1.'>'.$vis_language['TXTTEXT'].'</option>
							<option value="application" '.$sel2.'>'.$vis_language['TXTAPPLICATION'].'</option>
							<option value="image" '.$sel3.'>'.$vis_language['TXTIMAGE'].'</option>
						</select>
					</div>
				</div>';
		  
	   }else{
		    $sel1 = ($formfield_details[0]['regular_expression'] == 'email')?'selected="selected"':'';
			$sel2 = ($formfield_details[0]['regular_expression'] == 'numeric')?'selected="selected"':'';
			$sel3 = ($formfield_details[0]['regular_expression'] == 'alphabetic')?'selected="selected"':'';
			$sel4 = ($formfield_details[0]['regular_expression'] == 'alnumhyphen')?'selected="selected"':'';
		   
			$reg_exp ='<div class="form-group"><div class="col-sm-2 control-label">'.$vis_language['TXTREGULAREXPRESSIONVALIDATION'].'</div><div class="col-sm-10"><select name="vis_regexp" id="vis_regexp" class="input-sm form-control selectpicker"><option value="none">'.$vis_language['TXTNONE'].'</option><option value="email" '.$sel1.'>'.$vis_language['TXTEMAIL'].'</option><option value="numeric" '.$sel2.'>'.$vis_language['TXTNUMERIC'].'</option><option value="alphabetic" '.$sel3.'>'.$vis_language['TXTALPHABETIC'].'</option><option value="alnumhyphen" '.$sel4.'>'.$vis_language['TXTALPHANUMERIC'].'</option></select></div></div>';
	   }
	   if($formfield_details[0]['field_type'] <4){
		   $chk_req_y = ($formfield_details[0]['is_required'] == 1)?'checked':'';
		   $chk_req_N = ($formfield_details[0]['is_required'] == 0)?'checked':'';
	       $is_req = '<div class="form-group"><div class="col-sm-2 control-label">'.$vis_language['TXTISREQUIRED'].'</div><div class="col-sm-10 "><div class="radio i-checks m-r-lg pull-left"><label><input name="vis_req" id="vis_req" type="radio" value="1" '.$chk_req_y.'><i></i> '.$vis_language['TXTYES'].'</label></div><div class="radio i-checks m-r-lg pull-left"><label><input name="vis_req" id="vis_req" type="radio" value="0" '.$chk_req_N.' ><i></i> '.$vis_language['TXTNO'].'</label></div></div></div>';
	   }
	   if($formfield_details[0]['field_type']==4 || $formfield_details[0]['field_type']==5){
		 $chk_inline_y = ($formfield_details[0]['inline'] == 1)?'checked':'';
		 $chk_inline_N = ($formfield_details[0]['inline'] == 0)?'checked':'';
		 $is_inline = '<div class="form-group"><div class="col-sm-2 control-label">'.$vis_language['TXTISINLINE'].'</div><div class="col-sm-10 "><div class="radio i-checks m-r-lg pull-left"><label><input name="vis_inline" id="vis_inline" type="radio" value="1" '.$chk_inline_y.' ><i></i> '.$vis_language['TXTYES'].'</label></div><div class="radio i-checks m-r-lg pull-left"><label><input name="vis_inline" id="vis_inline" type="radio" value="0" '.$chk_inline_N.' ><i></i> '.$vis_language['TXTNO'].'</label></div></div></div>';
	   }
	   
	   switch($formfield_details[0]['field_type']){
		   case 1 : //textbox
					$note = '';
		   break;
		   
		   case 2 : //password
					$note = '';
		   break;
		   
		   case 3 : //textarea
					$note = '';
		   break;
		   
		   case 4 : //checkbox
					$placeholder = $default_value = $reg_exp = $note = '';	
		   break;
		   
		   case 5 : //Radio button
					$placeholder = $default_value = $reg_exp = $note = '';	
		   break;
		   
		   case 6 : //Select box
					$placeholder = $default_value = $reg_exp = $note = '';	
		   break;
		   
		   case 7 : //Multiselect box
					$placeholder = $default_value = $reg_exp = $note = '';	
		   break;
		   
		   case 8 : //date-time					
					$placeholder =  $reg_exp = $note = '';	
		   break;
		   
		   case 9 : //file-upload		
					$placeholder = $tooltip = $field_description = $default_value = $reg_exp = $note = '';
		   break;
		   
		   case 10 : //note
					$editor = $placeholder = $tooltip = $html_attribute = $field_description = $default_value = $no_of_file = $reg_exp = $is_req = $is_inline = '';
		   break;

	   }
  
   ?>
<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>
		 <li><a class="link" href="#/setting/view_form_groups/Form Builder/<? echo $vis_language['TXTFORMGROUP'];?>" ><? echo $vis_language['TXTFORMGROUP']; ?></a></li>
         <li> <a href="#/setting/view_formfield/Form field"  class="link"><? echo $operation['view_title']; ?></a></li>
         <li class="active"> <?php echo $vis_language['TXTUPDATEFORMFIELD']; ?></li>
      </ul>
      <div>
      </div>
   </div>
</section>
<section class="padder">
   <section class="panel panel-default">
      <header class="panel-heading sub_header"><?php echo $vis_language['TXTUPDATEFORMFIELD']; ?></header>
      <div class="panel-body">
         <form  class="form-horizontal" id="vis_formfield_edit_form" name="vis_formfield_edit_form" method="post">
            <input type="hidden"  name="vis_field_id" id="vis_field_id" value="<?php echo $formfield_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($formfield_details); ?>" />
            <input type="hidden" name="vis_field_group" value="<?php echo $formfield_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>
            <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTFORMGROUP']; ?></label>
               <div class="col-sm-10">
                  <select  name="vis_form_group_id" class="input-sm form-control selectpicker"  <? if(count($form_group_details)>10) echo 'data-live-search="true"';?> id="vis_form_group_id" >
                     <?php
                        for($k=0;$k<count($form_group_details);$k++)
                        {
                            if($formfield_details[0]['formgroup_id'] == $form_group_details[$k]['formgroup_id']) $selected = 'selected="selected"';
                            else $selected = '';

                            ?>
                     <option <?php echo $selected; ?> value="<? echo $form_group_details[$k]['formgroup_id']; ?>"><? echo $form_group_details[$k]['formgroup_name']; ?></option>
                     <?php
                        }
                        ?>
                  </select>
               </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_formgroup_name" id="vis_formgroup_name" value="<? echo htmlentities($formfield_details[0]['field_name'], ENT_COMPAT, 'UTF-8'); ?>"  >
               </div>
            </div>
			<?php echo $note;
				  echo $no_of_file;
				  echo $placeholder;
				  echo $default_value;
				  echo $field_description;
				  echo $tooltip;
				  echo $html_attribute; 			
			?>            
            <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 $formfield_details[0]['display_order']; ?>">
               </div>
            </div>
			<?php echo $is_inline;
				  echo $reg_exp;
				  echo $editor;
				  echo $is_req;
			?>
			              
            <?php
               if(count($formfield_details) > 1  ||  in_array($formfield_details[0]['field_type'], $form_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($formfield_details);$i++)  { 
						
                     ?>
				<tr><td>
				<? if( !in_array($formfield_details[0]['field_type'], array(5,6))) { ?>
				<label class="checkbox-inline p-d-sm i-checks"><input type="checkbox" name="chtab<?= $i; ?>" <? if($formfield_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($formfield_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 $formfield_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 $formfield_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 $formfield_details[$i]['formfield_id']; ?>">
				  </td></tr>
                  <?
                     }  ?>
				</table>
                  <?  	$form_field_type = $formfield_details[0]['field_type'];
                     	$count = $form_field_count + 1 ;
                     	if($form_field_type == 5 || $form_field_type == 6)
                     	{
                     		$fieldName = 'rdtab';
                     		$inputType = 'radio';
                     	}
                     	elseif($form_field_type == 4 || $form_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 } ?>
            <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($formfield_details[0]['is_enabled']==0) echo 'radio-no-uncheck'; ?>  ">
                   <input type="checkbox"  name="vis_status"  id="vis_status" <? if($formfield_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-12"><h5><? echo $vis_language['MSGLANGTRANSFORFORMFIELDS']; ?></h5></div>
            </div>
            <div class="line b-b line-lg pull-in"></div>
            <br/>
            <?
               for($l=0;$l<count($language_details);$l++) { ?>
            <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $language_details[$l]['language_name']; ?></label>
               <div class="col-sm-10">
                  <input class="form-control input-sm" type="text" name="vis_language_<? echo $language_details[$l]['language_id']; ?>" type="text" value="<? echo $formgroup_lang[$language_details[$l]['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_formfield', 'vis_form':'vis_formfield_edit_form'})"><? 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 $formfield_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="1"><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 $formfield_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>
