<? 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;
	}?>
<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 $vis_language['TXTASSETS']; ?></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="#/cmdb/assets/<? echo $vis_language['TXTCMDB']; ?>" onclick="$('#vis_workpanel_div').visExecution('load_module', '<? echo $vis_language['TXTCMDB'];?>', {'vis_module':'cmdb', 'vis_operation':'assets'});"> <? echo $vis_language['TXTCMDB']; ?></a></li>
            <li class="active"><?=$vis_language['TXTIMPORT']?></li>
        </ul>
    </div>
</section>
<section class="padder">
    <section class="panel panel-default">
        <header class="panel-heading sub_header"><?=$vis_language['TXTIMPORT']?></header>
        <div class="panel-body">
           <form method="post" role="form" class="form-horizontal" enctype="multipart/form-data" name="vis_import_assets_form" id="vis_import_assets_form">
				<div class="form-group">
					 <label class="col-sm-2 control-label p-d-sm"><? echo $vis_language['TXTCITYPE']; ?></label>
			   <div class="col-sm-10">
				  <select class="form-control selectpicker" data-size="auto" data-container="body" name="vis_ci_type" id="vis_ci_type" <? if(count($confi_item_details) > 10) echo 'data-live-search="true"' ?>>
						<?php 
							echo vis_show_subcategories($confi_item_details,'');
						?>
                  </select>
			   </div>
				</div>
                <div class="form-group">
					 <label class="col-sm-2 control-label p-d-sm"><? echo $vis_language['TXTDEPARTMENT']; ?></label>
			   <div class="col-sm-10">
				  <select class="form-control selectpicker" data-size="auto" data-container="body" name="vis_department" id="vis_department" <? if(count($departments) > 10) echo 'data-live-search="true"' ?>>
						<?php 
							for($d=0;$d<count($departments);$d++){
								echo '<option value="'.$departments[$d]['department_id'].'">'.$departments[$d]['domain_name'].' : '.$departments[$d]['department_name'].'</option>';
							}
						?>
                  </select>
			   </div>
				</div>

				<div class="form-group">
                    <label for="vis_csvfile" class="col-sm-2 control-label"><? echo $vis_language['TXTSELECTCSV']; ?></label>
                    <div class="col-sm-10">
                        <input type="file" name="files" onchange="get_file_name();" class="filestyle" data-classButton="btn btn-link link" data-input="false"  data-icon="true" data-iconName="vh-chat" data-buttonText="<?=$vis_language['TXTCLICKHERE']?>" data-badge="true"/><input type="hidden" name="vis_location" value="<? echo VIS_DOMAIN; ?>" /><input type="hidden" name="vis_import_attachments" id="vis_import_attachments" value="" /><input type="hidden" name="vis_attachments" id="vis_attachments" value="" />
                        <div id="vis_csv_attachments"></div>
                    </div>
                </div>
                <div class="form-group">
                    <label for="vis_csvfile" class="col-sm-2 control-label">&nbsp;</label>
                    <div class="col-sm-10">
                        <label for="vis_csvfile" class="control-label">CSV file format- NAME, IMPACT, DESCRIPTION, MANAGE BY, USED BY, ASSIGNED ON,</label>
                    </div>
                </div>
				<input type="hidden" value="true" name="vis_import">
                <input type="hidden" name="vis_module" id="vis_module" value="cmdb" /> 
                <input type="hidden" name="vis_operation" id="vis_operation" value="import_assets" />
           <div class="b-2x b-t m-b-md"></div>
				<div class="col-sm col-sm-offset-2">
				<input type="button" onclick="import_assets();" class="btn btn-primary" value="<? echo $vis_language['TXTADD']; ?>" />
		   </div> <br/>  </div>
           </form>
    </section>
</section>

</section>
<style>
.wrapper-xxs {
    padding: 7px 5px 0 0!important;
}
</style>
<script src="<?= VIS_PATH_SCRIPT; ?>file-input/bootstrap-filestyle.min.js"></script>
<script>
function import_assets(){
	var file_name=$('input[type=file]').val();
	var extension = file_name.substr( (file_name.lastIndexOf('.') +1) );
	if(extension=='csv'){
		$('#vis_import_assets_form').submit();
	}else if(file_name==''){
		$("#vis_global_msg_div").visInterface("load_global_message", "<?= $vis_language['MSGPLZSELFILE'];?>");		
	}else{
		$("#vis_global_msg_div").visInterface("load_global_message", "<?= $vis_language['MSGSLECTUPLOADCSVFILE'];?>");
	}
}
function get_file_name(){
	var file_name=$('input[type=file]').val();
	$('#vis_csv_attachments').html('<div class="btn-group wrapper-xxs"><span class="btn btn-xs alert-success">'+file_name+'</span><button class="btn btn-xs alert-success" onclick="remove_file();" data-dismiss="alert" type="button"><i class="vh vh-cross"></i></button></div>');	
}
function remove_file(){
	var file_name=$('input[type=file]').val('');
	$('#vis_csv_attachments').hide();	
}
</script>