<?
   global $vis_language;
   $paging_list='';
   for($i=0;$i<$view_info['page_count'];$i++) $paging_list.='<option value="'.$i.'" '.(($page==$i)?'selected="selected"':'').'>'.($i+1).'</option>';
   $changes_filters=array(12=>$vis_language['TXTALL'],13=>$vis_language['TXTOPEN'],14=>$vis_language['TXTCLOSED'],15=>$vis_language['TXTASSIGNED']);
?>
<section id="breadcrumb" class="row m-b m-l-none m-r-none">
   <div class="col-sm-4">
	<div id="url_header">
      <h3 class="m-b-xs text-black"><? echo $vis_language['TXTCHANGES'];?><span id="total_cnt"> (<? echo $changes_info['total']; ?>)</span></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>
        <? if(isset($operation['filter_id']) && $operation['filter_id']!='12'){?>
		<li><a class="link" href="#/changes/filter_changes/<? echo $vis_language['TXTCHANGES'];?>/12" onclick="location.reload();"><? echo $vis_language['TXTCHANGES'];?></a></li>
		 <? for($i=12;$i<=count($changes_filters)+11;$i++){
			if($operation['filter_id']==$i){?>
			 <li class="active"><? echo $changes_filters[$i]; ?> </li>
		 <? } } } else { ?>
        <li class="active"><? echo $vis_language['TXTCHANGES'];?></li>
		<? } ?>
      </ul>
	</div>
 </div>
 
 <div class="col-sm-8 m-t-md pull-right">
  <div class="btn-group pull-right m-l">&nbsp;
         <a class="btn btn-rounded btn-primary btn-sm dropdown-toggle" href="javascript:void(0);" data-toggle="ajaxModal" data-modal-arguments="vis_module=changes&vis_operation=new_changes_step_one&vis_static_area=vis_open_new_dialog"><i style="font-size:10px;" class="vh vh-plus"></i>  <? echo $vis_language['TXTNEW']; ?></a>
      </div> 
      

		<div class="col-sm-6 input-group b-a b-2x rounded pull-right">
			<input class="form-control rounded input-sm no-border" type="text" placeholder="<?php echo $vis_language['TXTSEARCHCHANGE']."...";?>" id="search_string" name="search_string">
			<span class="input-group-btn rounded b-l b-3x">
				<button class="btn btn-sm btn-rounded bg-white b-white btn-icon" type="submit" onclick="display_changes();">
				<i class="vh vh-search"></i>
				</button>
			</span>
		</div>
      </div>
   </div>
</section>

<? //if($view_info['page_count']>0){  ?>
<div  class="col-lg-12">
    <form name="vis_changes_form" id="vis_changes_form">
	 <input type="hidden" id="vis_filter_id" name="vis_filter_id" value="<? echo $operation['filter_id'];?>"/>
	 <input type="hidden" value="" name="vis_filter_enable" id="vis_filter_enable">
      <section class="panel panel-default">
         <div class="row wrapper clr" id="view_action">
		<header class="col-sm-12">
			<div class="pull-right" id="pg_1">
				<div class="btn-group">
					<div class="tkt_right_menu" id="paging" style="width:auto !important;">
					  <select name="pageing" class="form-control input-sm selectpicker pull-right paging v-middle" onChange="$(this).parents('#vis_workpanel_div').visExecution('load_area',{'vis_module':'<?php echo $operation['vis_module']; ?>', 'vis_operation':'<?php echo $operation['vis_operation']; ?>', 'vis_page':this.value, 'vis_filter_id':'<? echo $operation['filter_id'];?>'})">
					   <? echo $paging_list;?>
					   </select>
					  <div class="text-muted pull-right label_page"><? echo $vis_language['TXTPAGE']; ?>:</div>
					</div>
				</div>
			</div>
			<!--
			<div class="pull-right">
				<ul class="m-n footer_link">
					<li>
						<input type="hidden" value="export" name="vis_module">
						<input type="hidden" id="Exportall" name="Exportall">
						<input type="hidden" value="ticket_export" name="vis_operation">
						<input type="hidden" value="<? echo $view_info['vis_operation']; ?>" id="vis_export_function" name="vis_export_function">
						<a href="javascript:void(0);" class="link" data-toggle="ajaxModal" data-modal-arguments="vis_module=report&vis_operation=add_report_inqueue&vis_static_area=vis_open_new_dialog&vis_filter_id=<? echo $operation['filter_id'];?>&report_type=14" type="button"><? echo $vis_language['TXTEXPORTALL']; ?></a>
					</li>
				</ul>
			</div>
			-->
			<div id="tkt_left_menu">
				<div class="vis_mass_action">
					<div class="btn-group">
					  <button type="button" class="btn bg-empty btn-sm dropdown-toggle action_btn" data-toggle="dropdown">
						<i class="vh vh-action"></i>
						<span class="caret"></span>
					  </button>
					  <ul class="dropdown-menu">
                        <li><a href="javascript:void(0);" id="del" onclick="javascript:delete_changes();"><? echo $vis_language['TXTDELETE']; ?></a></li>
					  </ul>
					</div>
                    <div class="btn-group" id="get_departments_up">
						<button data-toggle="dropdown" class="btn bg-empty btn-sm dropdown-toggle action_btn bg-white" type="button" onclick="$('#get_departments_up').visExecution('load_area', {'vis_module': 'ticket', 'vis_operation': 'list_contents', 'vis_action': 'get_departments', 'vis_subaction': 'up'});"><span class="filter-option pull-left"><?= $vis_language['TXTMOVETO']; ?>&nbsp;</span><span class="caret"></span></button>
			        </div>
					<div class="btn-group" id="get_changetype_up">
                        <button data-toggle="dropdown" class="btn bg-empty btn-sm dropdown-toggle action_btn bg-white" type="button" onclick="$('#get_changetype_up').visExecution('load_operations', {'vis_module': 'ticket', 'vis_operation': 'list_contents', 'vis_action': 'get_changetype', 'vis_subaction': 'up'});"><span class="filter-option pull-left"><?= $vis_language['TXTCHANGETYPE']; ?>&nbsp;</span><span class="caret"></span></button>
                    </div>
					<div class="btn-group" id="get_impacts_up">
						<button data-toggle="dropdown" class="btn bg-empty btn-sm dropdown-toggle action_btn bg-white" type="button" onclick="$('#get_impacts_up').visExecution('load_area', {'vis_module': 'ticket', 'vis_operation': 'list_contents', 'vis_action': 'get_impacts', 'vis_subaction': 'up'});"><span class="filter-option pull-left"><?= $vis_language['TXTIMPACT']; ?>&nbsp;</span><span class="caret"></span></button>
			        </div>
					<div class="btn-group" id="get_priorities_up">
                        <button data-toggle="dropdown" class="btn bg-empty btn-sm dropdown-toggle action_btn bg-white" type="button" onclick="$('#get_priorities_up').visExecution('load_operations', {'vis_module': 'ticket', 'vis_operation': 'list_contents', 'vis_action': 'get_priorities', 'vis_subaction': 'up'});"><span class="filter-option pull-left"><?= $vis_language['TXTPRIORITY']; ?>&nbsp;</span><span class="caret"></span></button>
                    </div>
					<div class="btn-group" id="get_risks_up">
                        <button data-toggle="dropdown" class="btn bg-empty btn-sm dropdown-toggle action_btn bg-white" type="button" onclick="$('#get_risks_up').visExecution('load_area', {'vis_module': 'ticket', 'vis_operation': 'list_contents', 'vis_action': 'get_risks', 'vis_subaction': 'up'});"><span class="filter-option pull-left"><?= $vis_language['TXTRISK']; ?>&nbsp;</span><span class="caret"></span></button>
                    </div>
					<div class="btn-group" id="get_status_up">
                        <button data-toggle="dropdown" class="btn bg-empty btn-sm dropdown-toggle action_btn bg-white" type="button" onclick="$('#get_status_up').visExecution('load_area', {'vis_module': 'ticket', 'vis_operation': 'list_contents', 'vis_action': 'get_status', 'vis_subaction': 'up'});"><span class="filter-option pull-left"><?= $vis_language['TXTSTATUS']; ?>&nbsp;</span><span class="caret"></span></button>
                    </div>
                </div>
			</div>
		</header>
		</div>
         <div class="table-responsive scroll-x" id="vis_changes_list">
            <? include_once(VIS_PATH_TEMPLATE.'changes_list.php'); ?>
         </div>
         <footer class="wrapper panel-footer bg-white">
            <div class="row">
			<div class="col-sm-9 tkt_left_menu" id="tkt_left_menu">
				<div class="vis_mass_action_footer">
					<div class="btn-group">
					  <button type="button" class="btn bg-empty btn-sm dropdown-toggle action_btn" data-toggle="dropdown">
						<i class="vh vh-action"></i>
						<span class="caret"></span>
					  </button>
					  <ul class="dropdown-menu">
                        <li><a href="javascript:void(0);" id="del1" onclick="javascript:delete_changes();"><? echo $vis_language['TXTDELETE']; ?></a></li>
					  </ul>
					</div>
                    <div class="btn-group" id="get_departments_down">
						<button data-toggle="dropdown" class="btn bg-empty btn-sm dropdown-toggle action_btn bg-white" type="button" onclick="$('#get_departments_down').visExecution('load_area', {'vis_module': 'ticket', 'vis_operation': 'list_contents', 'vis_action': 'get_departments', 'vis_subaction': 'down'});"><span class="filter-option pull-left"><?= $vis_language['TXTMOVETO']; ?>&nbsp;</span><span class="caret"></span></button>
			        </div>
					<div class="btn-group" id="get_changetype_down">
                        <button data-toggle="dropdown" class="btn bg-empty btn-sm dropdown-toggle action_btn bg-white" type="button" onclick="$('#get_changetype_down').visExecution('load_operations', {'vis_module': 'ticket', 'vis_operation': 'list_contents', 'vis_action': 'get_changetype', 'vis_subaction': 'down'});"><span class="filter-option pull-left"><?= $vis_language['TXTCHANGETYPE']; ?>&nbsp;</span><span class="caret"></span></button>
                    </div>
					<div class="btn-group" id="get_impacts_down">
						<button data-toggle="dropdown" class="btn bg-empty btn-sm dropdown-toggle action_btn bg-white" type="button" onclick="$('#get_impacts_down').visExecution('load_area', {'vis_module': 'ticket', 'vis_operation': 'list_contents', 'vis_action': 'get_impacts', 'vis_subaction': 'down'});"><span class="filter-option pull-left"><?= $vis_language['TXTIMPACT']; ?>&nbsp;</span><span class="caret"></span></button>
			        </div>
					<div class="btn-group" id="get_priorities_down">
                        <button data-toggle="dropdown" class="btn bg-empty btn-sm dropdown-toggle action_btn bg-white" type="button" onclick="$('#get_priorities_down').visExecution('load_operations', {'vis_module': 'ticket', 'vis_operation': 'list_contents', 'vis_action': 'get_priorities', 'vis_subaction': 'down'});"><span class="filter-option pull-left"><?= $vis_language['TXTPRIORITY']; ?>&nbsp;</span><span class="caret"></span></button>
                    </div>
					<div class="btn-group" id="get_risks_down">
                        <button data-toggle="dropdown" class="btn bg-empty btn-sm dropdown-toggle action_btn bg-white" type="button" onclick="$('#get_risks_down').visExecution('load_area', {'vis_module': 'ticket', 'vis_operation': 'list_contents', 'vis_action': 'get_risks', 'vis_subaction': 'down'});"><span class="filter-option pull-left"><?= $vis_language['TXTRISK']; ?>&nbsp;</span><span class="caret"></span></button>
                    </div>
					<div class="btn-group" id="get_status_down">
                        <button data-toggle="dropdown" class="btn bg-empty btn-sm dropdown-toggle action_btn bg-white" type="button" onclick="$('#get_status_down').visExecution('load_area', {'vis_module': 'ticket', 'vis_operation': 'list_contents', 'vis_action': 'get_status', 'vis_subaction': 'down'});"><span class="filter-option pull-left"><?= $vis_language['TXTSTATUS']; ?>&nbsp;</span><span class="caret"></span></button>
                    </div>
                </div>
			</div>
               <div class="col-sm-3 text-right text-center-xs tkt_right_menu" id="paging">
                  <select name="pageing" class="form-control input-sm selectpicker pull-right paging v-middle" onChange="$(this).parents('#vis_workpanel_div').visExecution('load_area',{'vis_module':'<?php echo $operation['vis_module']; ?>', 'vis_operation':'<?php echo $operation['vis_operation']; ?>', 'vis_page':this.value})">
                  <? echo $paging_list;?>
                  </select>
                  <div class="text-muted pull-right label_page"><? echo $vis_language['TXTPAGE']; ?>:</div>
               </div>
            </div>
         </footer>
      </section>
   </form>
</div>
<script src="<?= VIS_PATH_SCRIPT; ?>dropdown_dropup.js"></script>
<?
if($view_info['page_count']==0){ 
 include(VIS_PATH_TEMPLATE.'no_record_yet.php');
}?>
<section class="fullFrame m-n" id="vis_no_record_search1" style="display:none;"> </section>
<script>
$('.from_date').datetimepicker({format: "MM/DD/YYYY"});
$('.selectpicker').selectpicker();

function delete_changes()
{
	var selected = [];
	var selected1 = [];
	var vis_action = "";
	$('#checkbox_data input:checked').each(function() {
		selected.push($(this).attr('name'));
		selected1.push($(this).attr('value'));
		vis_action +=$(this).attr('name')+"="+$(this).attr('value')+",";
	});
	if( selected.length > 0)
	 {
		vis_action= vis_action.substring(0, vis_action.length-1);
		$('#del').attr('data-toggle','ajaxModal');
		$('#del').attr('data-modal-arguments','vis_module=changes&vis_operation=get_changes_delete&vis_action='+vis_action+'&vis_changes_area=1&vis_static_area=vis_changes_delete_form');
		$('#del1').attr('data-toggle','ajaxModal');
		$('#del1').attr('data-modal-arguments','vis_module=changes&vis_operation=get_changes_delete&vis_action='+vis_action+'&vis_changes_area=1&vis_static_area=vis_changes_delete_form');
	 }
	 else
	{
		$("#vis_global_msg_div").visInterface("load_global_message", "<? echo $vis_language['MSGLGNTSEL'];?>");
		return false;
	}
}


/*$('#search_string').keyup(function(e){
    if(e.keyCode == 13){  filter(); }
});*/
function display_changes(){ filter(); }

function filter(){
	var search_string = $("#search_string").val();
	if(search_string.length <= 2)
		$("#vis_global_msg_div").visInterface("load_global_message", "<? echo $vis_language['TXTGLOBALSEARCHERROR']?>");
	else{
		var data = { 'vis_filter_enable':'1', 'vis_action':'no_load','criteria': search_string };
		$.ajax({
			url: 'index.php?vis_module=changes&vis_operation=view_changes',
			data: data,
			type: "POST",
			dataType: "json",
			success: function(data) {
				$(".tkt_right_menu").html(data.paging);
			/*	$("#search_string").parent().addClass('open');*/
				$("#vis_changes_list").html(data.list);
				$('#url_header').html('<h3 class="m-b-xs text-black"><? echo $vis_language['TXTSEARCHRESULT']; ?><span id="total_cnt"> ('+data.total_cnt+')</span></h3><div><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="#/changes/filter_changes/Changes/12" onclick="location.reload();"><? echo $vis_language['TXTCHANGES'];//$operation['view_title'];?></a></li><li class="active"><? echo $vis_language['TXTSEARCHRESULT']; ?></li></ul></div>').show();
				if(data.total_cnt==0){
					$("#vis_no_record_search1").show();
					$("#no_record_yet").hide();
					$("#vis_no_record_search1").html(data.list);
				}else $("#vis_no_record_search1").hide();
				toggle_mass_actions(); // To disable header & footer mass actions on list pages
			},
			error: function(xhr, ajaxOptions, thrownError) {$("#vis_global_msg_div").visInterface("load_global_message", "Error: "+xhr.status+" - "+thrownError);}
		});
	}
}

function update_ticket_property(update_id,action_id) { // update owner properties i.e. assign new/remove
	if(action_id==2){
		update_properties(update_id, 1);
	}
	else if(action_id==3){
		update_properties(update_id, 2);
	}else{
		var dept = new Array(); var vis_action='';
            $("[id^='vis_global_mass_chk_']:checked").each(function(i){
                var dept_id = $(this).attr('data-dept-id');
                dept[i] = dept_id + '-'+dept_id;

            });

		if(action_id==0) var action='delete';
		else if(action_id==4) var action='priority';
		else if(action_id==8) var action='impact';
		else if(action_id==9) var action='risk';
		else if(action_id==11) var action='changetype';
		$('#vis_global_msg_div').visExecution('submit_form', {'vis_module': 'changes', 'vis_operation': 'update_properties', 'vis_action': action, 'vis_form':'vis_changes_form', 'vis_update_id': update_id,'dept':dept});
	}
}

function update_properties(new_value, selector){
	var dept = new Array(); var vis_action='';
	$("[id^='vis_global_mass_chk_']:checked").each(function(i){
		var status = vis_action = '';
		var dept_id = $(this).attr('data-dept-id');
		var old_status_id = $(this).attr('data-status');
		if(selector == 2){ // status
			vis_action = 'status';
			if(new_value!=3 && $("#vis_lp_department_"+dept_id+"_status_"+new_value).length){ status += new_value + ','; }
			if(old_status_id!=3 && $("#vis_lp_department_"+dept_id+"_status_"+old_status_id).length){ status += old_status_id; }
			if(status!='') dept[i] = dept_id + '-'+status;
		}
		else if(selector == 1){ // dept
			vis_action = 'department';
			if(old_status_id != 3 && $("#vis_lp_department_"+dept_id+"_status_"+old_status_id).length){
				dept[i++] = dept_id + '-'+old_status_id;
			}
			if(old_status_id != 3 && $("#vis_lp_department_"+new_value+"_status_"+old_status_id).length){
				dept[i++] = new_value + '-'+old_status_id;
			}
		}
	});
	$('#vis_global_msg_div').visExecution('submit_form',{'vis_module':'changes', 'vis_operation':'update_properties', 'vis_action': vis_action, 'vis_form':'vis_changes_form', 'vis_update_id': new_value, 'dept': dept });
}
</script>
