<?php

////////////////////// FUNCTION | MODULE FUNCTION (c) i2d Technologies //////////////////////////////////

if (!function_exists('dynamicdrop_modal')) {
	function dynamicdrop_modal($alias,$encoding=0,$ref=0,$table=0,$title_field=0,$id_field=0,$drop_id=0){
  
   $form_name=$ref."_modal_dropname";
   $form_id=$drop_id;
   $label="Please Choose a ".$alias;
   $php_case="cat_fetch";
   $php_case_diag="cat_add";
   $php_file=app_json."/perl.txt";
   $drop_down_text="Choose Somth";
   
   

	
   ?>
  
   
   <style>
   .select2 {
width:100%!important;
}
   </style>
   <div class="col-md-12">


   <h5><?php echo $label; ?>
   
   
  </h5>
                <select class="form-control select2" tabindex="-1" aria-hidden="true" 
				id="<?php echo $form_id;?>" name="<?php echo $form_name; ?>">

<option value=""></option>
  			  </select>
				  
              </div>
              

			  
			  
<?php

$scripter=<<<script_marker

<script language="javascript">
/* Java Script Block 'dropdown modal' Starts (c) i2d Technologies */  

$(document).ready(function() {
function reloadajax(foo){

var foo = '#'+foo;


var flag="{$php_case}";


  $.ajax({
        
        Type : 'POST',
		
		contentType : "application/json; charset=utf-8",
		 
		dataType: 'json',

		cache	: false,

		url		: "{$php_file}",
       
	    data	: 'section_flag={$php_case}&ref={$ref}&encode={$encoding}&tbl={$table}&tbl_title={$title_field}&tbl_id_col={$id_field}',

		success : function(response){
			console.log(response);
			
			        		var options ;
					for (var i = 0; i < response.length; i++) {
						options += '<option value="' + response[i].id + '">' + response[i].name + '</option>'; 
					}
                                            $(foo).html(options);
						
			
				},
		error : function(error){
			console.log(error);
		},
				
				
});


}

reloadajax('{$form_id}');


  

		});
	  


/* Java Script Block 'dropdown modal' Ends (c) i2d Technologies */  

	  
</script>

script_marker;

echo $scripter;

   
}
}
//////////////////////////// HTML FUNCTION ENDS (c) i2d Technologies ///////////////////////////////////////

////////////////////// FUNCTION | MODULE FUNCTION (c) i2d Technologies //////////////////////////////////

if (!function_exists('dynamicdrop_adv')) {
	function dynamicdrop_adv($alias=0,$encoding=0,$editing=0,$ref=0,$table=0,$title_field=0,$id_field=0,$add_new=0,$other_id_col=0){
   if (array_key_exists('editing', $editing)) {
   $edit=$editing['editing'];
   }
   if (array_key_exists('selected_id', $editing)) {
   $selected_id=$editing['selected_id'];
   }
   if (array_key_exists('selected_text', $editing)) {
   $selected_text=$editing['selected_text'];
   }
	
   $form_name=$ref."_dropname";
   $form_id=$ref."_dropid";
   $label="Please Choose a ".$alias;
   $php_case="cat_fetch";
   $php_case_diag="cat_add";
   $php_file=app_json."/perl.txt";
   $drop_down_text="Choose Somth";
   
   $mod_id="test_modal".$ref;
   $mod_input_id="mod_1".$ref;
   $mod_btn_id="btn_mod_id".$ref;
   
   $modal_aray=array(
   'modal_id'=>$mod_id,
   'modal_heading'=>"Enter New Item",
   'label'=>"Please Type Below",
   'input_id'=>$mod_input_id,
   'input_name'=>"mod_name".$ref,
   'btn_name'=>"btn_mod_name".$ref,
   'btn_id'=>$mod_btn_id
   );
   
   
$t_title=$title_field;
$t_id=$id_field;
if($add_new!=0){
modal_diag($modal_aray);
} 
   
 
    
	
   ?>
  
   
   <style>
   .select2 {
width:100%!important;
}
   </style>
   <div class="col-md-12">


   <h5><?php echo $label; ?>
   
   <?php
   if($add_new!=0){
   ?> 
  
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a data-toggle="modal" id="btn-<?php echo $ref; ?>" href="#<?php echo "test_modal".$ref; ?>" class="btn btn-xs btn-success text-center"><i class="ti-plus"></i></a>
  <?php
   }
  ?>
  </h5>
                <select class="form-control select2" tabindex="-1" aria-hidden="true" id="<?php echo $form_id; ?>" name="<?php echo $form_name; ?>">
				
<?php if(isset($selected_id) && isset($selected_text)){ ?>
				
				
			<option value="<?php echo $selected_id; ?> "selected><?php if($encoding!=0){echo decode($selected_text);}
  else {echo $selected_text;} ?></option>
  
  
	<?php  }
  ?>
  			  </select>
				  
              </div>
              
  
			  
<?php

if(isset($selected_id) && $selected_id!=0) { 
$action="append";
} else {
$action="html"; } 


$scripter=<<<script_marker

<script language="javascript">

/* Java Script Block 'dropdown adv single' Starts (c) i2d Technologies */  


$(document).ready(function() {



function reloadajax(foo){

var foo = '#'+foo;


var flag="{$php_case}";


  $.ajax({
        
        Type : 'POST',
		
		contentType : "application/json; charset=utf-8",
		 
		dataType: 'json',

		cache	: false,

		url		: "{$php_file}",
       
	    data	: 'section_flag={$php_case}&ref={$ref}&encode={$encoding}&tbl={$table}&tbl_title={$title_field}&tbl_id_col={$id_field}',

		success : function(response){
			console.log(response);
			
			        		var options ;
					for (var i = 0; i < response.length; i++) {
						options += '<option value="' + response[i].id + '">' + response[i].name + '</option>'; 
					}
                                            $(foo).{$action}(options);
						
			
				},
		error : function(error){
			console.log(error);
		},
				
				
});
// end ajax()


}

reloadajax('{$form_id}');


  $("#{$mod_btn_id}").click(function() {
		 
	var cat_name = $("#{$mod_input_id}").val();	
	
	
	
	if(cat_name!=""){
		
		$.ajax({
        
        Type : 'POST',
		
		contentType : "application/json; charset=utf-8",
		 
		dataType: 'json',

		cache	: false,

		url		: "{$php_file}",
     
        
     	 data	: "item_name="+cat_name+"&section_flag={$php_case_diag}&encode={$encoding}&ref={$ref}&tbl={$table}&tbl_title={$title_field}&tbl_id_col={$id_field}",

		success : function(cat_response){
			        $("#{$mod_input_id}").val('');
					reloadajax('{$form_id}');
					console.log(cat_response);
			        if(cat_response=="inserted"){
					//$(foo).trigger("chosen:updated");	
					}
				},
	
        error   :  function(e_response){	
		
		//console.log(e_response);
		
		//var err=(e_response);
		
		
		}
		
		
});// end ajax()
	}
	});

		});
	  


/* Java Script Block 'dropdown adv single' Ends (c) i2d Technologies */  

	  
</script>

script_marker;

echo $scripter;

   
}
}
//////////////////////////// HTML FUNCTION ENDS (c) i2d Technologies ///////////////////////////////////////
////////////////////// FUNCTION | MODULE FUNCTION (c) i2d Technologies //////////////////////////////////

if (!function_exists('dynamicdrop_adv_multi')) {
	function dynamicdrop_adv_multi($alias=0,$encoding=0,$editing=0,$ref=0,$ref2=0,$prim_table=0,$sub_table=0,$title_field=0
	,$id_field=0,$parent_col=0,$parent_add=0,$child_add=0,$child_label=0){
   if (array_key_exists('editing', $editing)) {
   $edit=$editing['editing'];
   }
   if (array_key_exists('selected_id', $editing)) {
   $selected_id=$editing['selected_id'];
   }
   if (array_key_exists('selected_text', $editing)) {
   $selected_text=$editing['selected_text'];
   }
   if (array_key_exists('selected_id2', $editing)) {
   $selected_id2=$editing['selected_id2'];
   $selected_id_status=$editing['selected_id2']; 
   }
   else{
	$selected_id_status="0";   
   }
   if (array_key_exists('selected_text2', $editing)) {
   $selected_text2=$editing['selected_text2'];
   }
   
   
	
   $form_name=$ref."_multi_dropname";
   $form_name2=$ref2."_multi_dropname";
   $form_id=$ref."_multi_dropid";
   $form_id2=$ref."_multi_dropid_child";
   $label="Please Choose a ".$alias;
   $label2="Please Choose a ".$child_label;
   $php_case="cat_fetch";
   $php_case2="cat_fetch_multi";
   $php_case_diag="cat_add";
   $php_case_diag2="sub_cat_add_multi";
   $php_file=app_json."perl.txt";
   
   $mod_id="test_multi_modal".$ref;
   $mod_input_id="mod_multi_1".$ref;
   $mod_btn_id="btn_mod_multi_id".$ref;
   
   $modal_aray=array(
   'modal_id'=>$mod_id,
   'modal_heading'=>"Enter New Item",
   'label'=>"Please Type Below",
   'input_id'=>$mod_input_id,
   'table_name'=>$sub_table,
   'table_title'=>$title_field,
   'table_id'=>$id_field,
   'input_name'=>"mod_multi_name".$ref,
   'btn_name'=>"btn_mod_multi_name".$ref,
   'btn_id'=>$mod_btn_id);
if($parent_add!=0){
   modal_diag_adv($modal_aray);
}
   
   $mod_id2="test_multi_modal".$ref2;
   $mod_input_id2="mod_multi_1".$ref2;
   $mod_drop_id2="mod_multi_drop_sub".$ref2."_id";
   $mod_drop_name2="mod_multi_drop_sub".$ref2."_name";
   $mod_btn_id2="btn_mod_multi_id".$ref2;
    
	
 $modal_aray2=array(
   'modal_id'=>$mod_id2,
   'modal_heading'=>"Enter New Item",
   'label'=>"Please Type Below",
   'input_id'=>$mod_input_id2,
   'input_name'=>"mod_multi_name".$ref2,
   'btn_name'=>"btn_mod_multi_name".$ref2,
 'table_name'=>$sub_table,
   'table_title'=>$title_field,
   'table_id'=>$id_field,
   'btn_id'=>$mod_btn_id2,
   'parent_label'=>"Please Choose a ".$alias,
   'parent_id'=>$mod_drop_id2,
   'parent_name'=>$mod_drop_name2,
   'parent_encoding'=>0,
   'drop_id'=>$mod_drop_id2,
   'child_table'=>$sub_table,
   'child_table_title'=>$title_field,
   'child_table_id'=>$id_field,
   'parent_table'=>$prim_table,
   'parent_table_idcol'=>$id_field,
   'parent_ref'=>$ref
   
   );
 if($child_add!=0){
modal_diag_adv($modal_aray2);
 }   
   
     
   $child_modal_trigger_button_id="btn-".$ref2;
   ?>
  
   
      <style>
   .select2 {
width:100%!important;
}
   </style>
   <div class="col-md-12">


   <h5><?php echo $label; ?>
   <?php
   if($parent_add!=0){
   ?>
   
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a data-toggle="modal" id="btn-<?php echo $ref; ?>" href="#<?php echo "test_multi_modal".$ref; ?>" class="btn btn-xs btn-success text-center"><i class="ti-plus"></i></a>
   <?php } ?>
   </h5>
                <select class="form-control select2" tabindex="-1" aria-hidden="true" id="<?php echo $form_id; ?>" name="<?php echo $form_name; ?>">
<?php if(isset($selected_id) && isset($selected_text)){ ?>
				<option value="<?php echo $selected_id; ?> "selected><?php if($encoding!=0){echo decode($selected_text);}
  else {echo $selected_text;} ?></option>
	<?php  }
?>
  			  </select>
				  
              </div>
   <div class="col-md-12" id="childboy">


   <h5><?php echo $label2; ?>
   <?php
   if($child_add!=0){
   ?>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a id="<?php echo $child_modal_trigger_button_id; ?>" href="#" onclick="return false"; class="btn btn-xs btn-success text-center"><i class="ti-plus"></i></a>
   <?php } ?>
</h5>   
                <select class="form-control select2" tabindex="-1" aria-hidden="true" 
				id="<?php echo $form_id2; ?>" name="<?php echo $form_name2; ?>">
<?php if(isset($selected_id2) && isset($selected_text2)){ ?>
				<option value="<?php echo $selected_id2; ?> "selected><?php if($encoding!=0){echo decode($selected_text2);}
  else {echo $selected_text2;} ?></option>
<?php } ?>
</select>
</div>
			  
			  
<?php

$noaction="html";

if(isset($selected_id) && $selected_id!=0) { 

$opt="";

$action="append";
} else {
	
$opt="<option>Select An Option</option>";
	
$action="html"; } 


$scripter=<<<script_marker

<script language="javascript">
 $(document).ready(function() {

 function reloadajax(foo){

var foo = '#'+foo;


var flag="{$php_case}";


  $.ajax({
        
        Type : 'POST',
		
		contentType : "application/json; charset=utf-8",
		 
		dataType: 'json',

		cache	: false,

		url		: "{$php_file}",
       
	    data	: 'section_flag={$php_case}&ref={$ref}&encode={$encoding}&tbl={$sub_table}&tbl_title={$title_field}&tbl_id_col={$id_field}&tbl_parent_col={$parent_col}',

		success : function(response){
			//$(foo).empty;
			console.log(response);
			var options = '{$opt}';
			        		
			        		var options ;
					for (var i = 0; i < response.length; i++) {
						options += '<option value="' + response[i].id + '">' + response[i].name + '</option>'; 
					}
                                            $(foo).{$action}(options);
						
			
				},
		error : function(error){
			console.log(error);
		},
				
				
});
// end ajax()


}

reloadajax('{$form_id}');
/////////////////////////////////////////////////////////////////////////////////////////
function loadchild(doe , parent){


var doe = '#'+doe;

var parent = '#'+parent;
var parent_id = $(parent).val();


var flag="{$php_case2}";


  $.ajax({
        
        Type : 'POST',
		
		contentType : "application/json; charset=utf-8",
		 
		dataType: 'json',

		cache	: false,

		url		: "{$php_file}",
       
	    data	: 'section_flag={$php_case2}&parent='+parent_id+'&ref={$ref2}&encode={$encoding}&tbl={$sub_table}&tbl_title={$title_field}&tbl_id_col={$id_field}&tbl_parent_col={$parent_col}',

		success : function(response){
		    $(doe).prop( "disabled", false );
			$(doe).empty;
			console.log(response);
			
			        		var options = '{$opt}';
			        		var options ;
					for (var i = 0; i < response.length; i++) {
						options += '<option value="' + response[i].id + '">' + response[i].name + '</option>'; 
					}
                                            $(doe).{$noaction}(options);
						
			
				},
		error : function(error){
			console.log(error);
		},
				
				
});
// end ajax()


}

if('{$selected_id_status}' == "0")
             {
				 loadchild('{$form_id2}' , '{$form_id}');
			 }



$("#{$form_id}").change(function() {

loadchild('{$form_id2}' , '{$form_id}');

});


////////////////////////////////////////////////////////////////////////////////////////////////




  $("#{$mod_btn_id}").click(function() {

		 
	var cat_name = $("#{$mod_input_id}").val();	
	
	if(cat_name!=""){
		
		$.ajax({
        
        Type : 'POST',
		
		contentType : "application/json; charset=utf-8",
		 
		dataType: 'json',

		cache	: false,

		url		: "{$php_file}",
     
        
     	 data	: "item_name="+cat_name+"&section_flag={$php_case_diag}&encode={$encoding}&ref={$ref}&tbl={$sub_table}&tbl_title={$title_field}",

		success : function(cat_response){
			        $("#{$mod_input_id}").val('');
					reloadajax('{$form_id}');
					console.log(cat_response);
			        if(cat_response=="inserted"){
						
//reloadajax('{$form_id}');



				   
					}
				},
	
        error   :  function(e_response){	
		
		console.log(e_response);
		
		//var err=(e_response);
		
		
		}
		
		
});// end ajax()
	}
	});

/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
  $("#{$mod_btn_id2}").click(function() {
		 
	var cat_name = $("#{$mod_input_id2}").val();	
	var parent_sub_id = $("#{$mod_drop_id2}").val();	
		
	if(cat_name!=""){
		
		$.ajax({
        
        Type : 'POST',
		
		contentType : "application/json; charset=utf-8",
		 
		dataType: 'json',

		cache	: false,

		url		: "{$php_file}",
     
        
     	 data	: "item_name="+cat_name+"&section_flag={$php_case_diag2}&parent="+parent_sub_id+"&encode={$encoding}&ref={$ref2}&tbl={$sub_table}&tbl_title={$title_field}&parent_id={$parent_col}",

		success : function(cat_response){
			        $("#{$mod_input_id2}").val('');
					loadchild('{$form_id2}' , '{$form_id}');
					console.log(cat_response);
			        if(cat_response=="inserted"){
						
//reloadajax('{$form_id2}');
//loadchild('{$form_id2}' , '{$form_id}');


				   
					}
				},
	
        error   :  function(e_response){	
		
		console.log(e_response);
		
		//var err=(e_response);
		
		
		}
		
		
});// end ajax()
	}
	});
	
/////////////////////////////////////////////////////////////////////////////////////////////////	
/////////////////////////////////////////////////////////////////////////////////////////////////	
/////////////////////////////////////////////////////////////////////////////////////////////////	
/////////////////////////////////////////////////////////////////////////////////////////////////	
	
//////////	


		});


  
</script>

script_marker;

echo $scripter;

$scripter34=<<<script_marker34

<script language="javascript">

$(document).ready(function() {


 function reloadajax2(foo){

var foo = '#'+foo;


var flag="{$php_case}";


  $.ajax({
        
        Type : 'POST',
		
		contentType : "application/json; charset=utf-8",
		 
		dataType: 'json',

		cache	: false,

		url		: "{$php_file}",
       
	    data	: 'section_flag={$php_case}&ref={$ref}&encode={$encoding}&tbl={$sub_table}&tbl_title={$title_field}&tbl_id_col={$id_field}&tbl_parent_col={$parent_col}',

		success : function(response){
			//$(foo).empty;
			console.log(response);
			
			        		var options ;
					for (var i = 0; i < response.length; i++) {
						options += '<option value="' + response[i].id + '">' + response[i].name + '</option>'; 
					}
                                            $(foo).{$action}(options);
						
			
				},
		error : function(error){
			console.log(error);
		},
				
				
});
// end ajax()


}


$('#{$child_modal_trigger_button_id}').on('click', function() {
$("#{$mod_id2}").modal();		
reloadajax2('chachu_bush');
});	
	  });
  </script>
  
script_marker34;

echo $scripter34;

   
}
}


//////////////////////////// HTML FUNCTION ENDS (c) i2d Technologies ///////////////////////////////////////
///////////////////// CORE FUNCTION | MODULE FUNCTION (c) i2d Technologies //////////////////////////////////
if (!function_exists('commas_to_tags')) {
function commas_to_tags($string) { 

$text = explode(',', $string);

    return $text;
} 
}
/////////////////////////// function ends /////////////////////////////////

////////////////////// FUNCTION | MODULE FUNCTION (c) i2d Technologies //////////////////////////////////

if (!function_exists('select_choice')) {
	function select_choice($settings){
//added 3/4/2020

	if (array_key_exists('this_table', $settings)) {
   $table=$settings['this_table'];
   }
   if (array_key_exists('id_col', $settings)) {
   $id_col=$settings['id_col'];
   }
   if (array_key_exists('ref_col', $settings)) {
   $ref_col=$settings['ref_col'];
   }
   if (array_key_exists('ref', $settings)) {
   $ref=$settings['ref'];
   }
   if (array_key_exists('status_col', $settings)) {
   $status_col=$settings['status_col'];
   }
   if (array_key_exists('title_col', $settings)) {
   $title_col=$settings['title_col'];
   }
   if (array_key_exists('value_col', $settings)) {
   $value_col=$settings['value_col'];
   }
   if (array_key_exists('wysiwyg', $settings)) {
   $wysiwyg=$settings['wysiwyg'];
   }
   if (array_key_exists('max-length', $settings)) {
   $maxlength=$settings['max-length'];
   }

   $update_cols=array($title_col,$id_col,$value_col,$status_col,$ref_col);
	
	$updatesettings=array(
	'table'=>$table,
	'id_col'=>$id_col,
	'ref_value'=>$ref,
	'ref_col'=>$ref_col,
	'fields_array'=>$update_cols,
	'status_value'=>'Active',
	'status_col'=>$status_col,
	'order'=>'DESC',
	'order_col'=>$id_col,
	'errors'=>"1",
	'echo'=>"0",
	'limit'=>50,
	'type'=>'1cc');

	$updatesettings_load=db_fetch($updatesettings);
	
   ?>
   <!-- PAGE FUNCTION STARTS (c) i2d Technologies Website Engine -->
   
   <!--
<script type="text/javascript">
  $(document).ready(function() {
$('#<?php // echo $text_area_name; ?>').summernote({
  height: 10,                 // set editor height
  minHeight: null,             // set minimum height of editor
  maxHeight: null,             // set maximum height of editor
  toolbar: [
            [ 'font', [ 'bold','clear'] ]
        ]
  //focus: true                  // set focus to editable area after initializing summernote
});
  });
  </script>
  -->

   
   
   <script type="text/javascript">
  $(document).ready(function() {
<?php if($wysiwyg!=0){	 ?>
$('#message').summernote('editor.pasteHTML', $('select').val());
<?php  } else { ?>
$('#message').html($('select').val());
<?php } ?>
$('select').on('change', function(){
<?php if($wysiwyg!=0){	 ?>	
    //$('#message').val($(this).val());
	$('#message').summernote('code', '');
	$('#message').summernote('editor.pasteHTML', $(this).val());
<?php } else { ?>
    $('#message').html($(this).val());
<?php } ?>	
});
	  });
  </script>
  <div class="form-group">
                        <label class="control-label"><h5>Select a Option</h5></label>
	
  
  <select class="form-control">
<?php 
foreach ($updatesettings_load as $updateitem){
?>
	<option value="<?php echo $updateitem[$value_col]; ?>"style="font-size:18px;"><?php echo $updateitem[$title_col]; ?></option>
<br />
<?php } ?>    
	</select>
															<p>&nbsp;</p>
<?php if($wysiwyg!=0){	 ?>							 							

<script type="text/javascript">
  $(document).ready(function() {
$('#message').summernote({
  height: 100,                 // set editor height
  minHeight: null,             // set minimum height of editor
  maxHeight: null,             // set maximum height of editor
  toolbar: [
            [ 'style', [ 'style' ] ],
            [ 'font', [ 'bold', 'italic', 'underline', 'strikethrough', 'superscript', 'subscript', 'clear'] ],
            [ 'fontname', [ 'fontname' ] ],
            [ 'fontsize', [ 'fontsize' ] ],
            [ 'color', [ 'color' ] ],
            [ 'para', [ 'ol', 'ul', 'paragraph', 'height' ] ],
            [ 'table', [ 'table' ] ],
            [ 'insert', [ 'link'] ],
            [ 'view', [ 'undo', 'redo', 'fullscreen', 'codeview', 'help' ] ]
        ]
  //focus: true                  // set focus to editable area after initializing summernote
});
  });
  </script>
  



              
                 
				 


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

      
<textarea name="message" id="message"></textarea>
          </div>




<?php } else { ?>
  <textarea class="form-control" id="message" rows="5" maxlength="<?php echo $maxlength; ?>"></textarea>
<?php }  ?>
 

  <p>&nbsp;</p><p>&nbsp;</p>
												</div>
 <!-- PAGE FUNCTION ENDS (c) i2d Technologies Website Engine -->   
<?php   
}
}

















?>