<? global $vis_language; 	
	function vis_show_subcategories($confi_item_details,$call) {
		for($i=0;$i<count($confi_item_details);$i++) { 
				$ci_type .='<option value="'.$confi_item_details[$i]['item_id'].'">'.$confi_item_details[$i]['name'].'</option>';
				if(isset($confi_item_details[$i]['subcat']) && $confi_item_details[$i]['subcat']!=NULL) { 
					$ci_type .= vis_show_subcategories($confi_item_details[$i]['subcat'],'sub_cat'); 
				}
			}
		return $ci_type;
	}						
?>
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title"><? echo$vis_language['TXTADDCI']; ?></h4>
        </div>
        <div class="modal-body">
            <div class="row">
                <div class="col-sm-12">
                <form method="post" role="form" class="form-horizontal" name="vis_ciitem_form" id="vis_ciitem_form">
				<div class="form-group">
                    <div class="col-sm-6">
						<select class="form-control selectpicker" name="vis_configuration_item" id="vis_configuration_item" <? if(count($confi_item_details) > 10) echo 'data-live-search="true"' ?> onchange="vis_apply_filter();">
						<option value=""><?=$vis_language['TXTSELECT']?></option>
						<?php 
						/*
						for($p=0;$p<count($confi_item_details);$p++){ 
							echo '<option value="'.$confi_item_details[$p]['item_id'].'">'.$confi_item_details[$p]['name'].'</option>';
						}*/
						
						echo vis_show_subcategories($confi_item_details,'');
							
						?>
                        </select>
                    </div>
				   <div class="col-sm-6">
						<input type="text" id="search_language_variables" onkeyup="vis_apply_filter();" placeholder="<?= $vis_language['TXTSEARCH'];?>" class="form-control">
                   </div>
				   
                </div>
                <div class="form-group" id="vis_show_amt_balance">
                    <div class="col-sm-12" id="configuration_item">
                    </div>
                </div>
				<input type="hidden" name="vis_attach_prev_ci" id="vis_attach_prev_ci" value="<?=$operation['attached_ci_ids']?>">
              </form>
              </div>
            </div>
        </div>
        <div class="modal-footer">
			<a class="btn btn-default" data-dismiss="modal"><? echo $vis_language['TXTCANCEL']; ?></a>
            <a class="btn btn-primary" onclick="$(this).visExecution('submit_form',{'vis_module':'<?=$operation['vis_module']?>', 'vis_operation':'attach_ci', 'vis_static_area':'<?=$operation['vis_static_area']?>', 'vis_form':'vis_ciitem_form', 'vis_item_details':'1', 'vis_department':'<?=$operation['vis_department']?>'});"><? echo $vis_language['TXTATTACH']; ?></a>
        </div>
    </div>
</div>

<script type="text/javascript">
	$('.selectpicker').selectpicker();
	function vis_apply_filter(){
		var filter = $("#search_language_variables").val();
		var config_item = $("#vis_configuration_item").val();
		var data = {'vis_configuration_id':''+config_item+'', 'vis_filter':''+filter+'', 'vis_filter_enable':'', 'attached_id':'<?=$operation['attached_ci_ids']?>','vis_department':'<?=$operation['vis_department']?>'};   
		if(filter.length<=2 && config_item==0){
			  $("#configuration_item").html('<div style="text-align:center;"><?= $vis_language['TXTGLOBALSEARCHERROR'];?></div>');
			  return false;
		}else{
		$.ajax({
			url: 'index.php?vis_module=<?=$operation['vis_module'];?>&vis_operation=change_cofiguration',
			data: data,
			type: "POST",
			dataType: "json",
			success: function(data) {
				$("#configuration_item").html(data.list);
			},
			error: function(xhr, ajaxOptions, thrownError) {$("#vis_global_msg_div").visInterface("load_global_message", "Error: "+xhr.status+" - "+thrownError);}
		});
		}
	}
</script>
<script>
</script>
