<? global $vis_language;
$tp=0;
if($status)$tp++;
if(isset($module_setting['vis_priority']))$tp++;
$tp++;
$tp++;
if(isset($module_setting['vis_category'])){
	$tp++;
	if(isset($module_setting['vis_show_subcategory']) && ($module_setting['vis_show_subcategory']==1 || $module_setting['vis_show_subcategory']==2)){
		$tp++;
		$module_setting['vis_subcategory']='';
		if(isset($module_setting['vis_show_item']) && ($module_setting['vis_show_item']==1 || $module_setting['vis_show_item']==2)){$tp++;$module_setting['vis_item']='';}
	}
}
if(VIS_ITIL==1)$tp++;
if($tp==1 || $tp==2){$class_properties="col-sm-6";}
if($tp==3 || $tp==5 || $tp==6){$class_properties="col-sm-4";}
if($tp==4 || $tp==7 || $tp==8){$class_properties="col-sm-3";}
$enddiv=0;
?>
<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['TXTOPENNEWPROBLEM']; ?></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="#/problem/filter_problem/<? echo $vis_language['TXTPROBLEMS']; ?>/8"><?= $vis_language['TXTPROBLEMS']; ?></a></li>
            <li class="active"><? echo $vis_language['TXTOPENNEWPROBLEM']; ?></li>
        </ul>
    </div>
</section>
<section class="padder">
    <section class="panel panel-default">
        <header class="panel-heading sub_header"><? echo $vis_language['TXTOPENNEWPROBLEM']; ?></header>
        <div class="panel-body">
            <form class="form-horizontal" method="post" enctype="multipart/form-data" name="vis_new_problem_form" id="vis_new_problem_form">
                <input type="hidden" value="<? echo $vis_department_id; ?>" name="vis_department" id="vis_department" />
				<div class="form-group">
					<label class="col-sm-1 control-label txt_left"><? echo $vis_language['TXTFROM']; ?></label>
					<div class="col-sm-11">
						<input class="form-control input-sm" type="text" name="vis_from" id="vis_from"  value="<? echo $operation['vis_email_id']; ?>" placeholder="<?= $vis_language['TXTTYPETOSEARCHEXISTINGSTAFFSEMAILADDRESS']?>" data-resize="no" style="width:100%"/>
							<script type="text/javascript">
								$(document).ready(function() {
									$("#vis_from").tokenInput(
										"index.php?vis_module=problem&vis_operation=get_staff",
										{
											theme: "facebook",
											searchDelay: 500,
											minChars: 3,
											queryParam: "vis_data",
											propertyToSearch: "email",
											tokenValue: "email",
											tokenLimit: 1,
											resultsFormatter: function(item){ return "<li>" + "<div style='display: inline-block; padding-left: 10px;'><div class='full_name'>" + item.full_name + " < " + item.email + " ></div></div></li>" },
											tokenFormatter: function(item) { return "<li><p>" + item.email + "</p></li>" }
										}
									);
									$("div.token-input-dropdown-facebook").css('width',$(".token-input-list-facebook").width()+2+'px');
									$("#vis_from").tokenInput("add", {id: '<?=VIS_STAFF_ID;?>', email: "<?=$login_staff[0]['email']; ?>"});
									$("#token-input-vis_from").parent().css('width','100%');
								});
								</script>

					</div>
				</div>
                <div class="form-group">
                    <label class="col-sm-1 control-label txt_left"><? echo $vis_language['TXTSUBJECT']; ?></label>
                    <div class="col-sm-11">
                        <input class="form-control input-sm" type="text" name="vis_subject" id="vis_subject" value="<?= $subject ?>">
                    </div>
                </div>
				<div class="form-group">
                    <label class="col-sm-1 control-label txt_left"><? echo $vis_language['TXTDESCRIPTION']; ?></label>
                    <div class="col-sm-11">
                        <textarea name="vis_description" id="vis_description" class="form-control" rows="10"></textarea>
                    </div>
                </div>

                <div class="form-group">
                  <? if($status){$enddiv++;?>
                   <div class="<?=$class_properties;?>">
                       <label class="col-sm-3 control-label  p-l-none txt_left"><? echo $vis_language['TXTSTATUS']; ?></label>
                       <div class="col-sm-9">
			   <select class="form-control input-sm selectpicker" name="vis_status" id="vis_status"<? if (count($status) > 10) echo ' data-live-search="true"'; ?>><? for ($i = 0; $i < count($status); $i++)
echo '<option value="' . $status[$i]['status_id'] . '">' . $status[$i]['status_name'] . '</option>'; ?>
			   </select>
		       </div>
                   </div>

                    <? }
			if($tp==1){echo "</div>";}
			if(isset($module_setting['vis_priority'])){$enddiv++;?>
                   <div class="<?=$class_properties;?>">
			<label class="col-sm-3 control-label  p-l-none txt_left"><? echo $vis_language['TXTPRIORITY']; ?></label>
			<div class="col-sm-9">
			       <select class="form-control input-sm selectpicker" name="vis_priority" id="vis_priority"<? if (count($priorities) > 10) echo ' data-live-search="true"'; ?>><? for ($i = 0; $i < count($priorities); $i++)
echo '<option value="' . $priorities[$i]['priority_id'] . '">' . $priorities[$i]['priority_name'] . '</option>'; ?>
				</select>
			</div>
                   </div>

                     <? }?>
		     <? if($tp==2 && $enddiv==2){$enddiv=0;echo "</div>";}
				   
		       if(1){$enddiv++;?>
                    <div class="<?=$class_properties;?>">
		        <label class="col-sm-3 control-label  p-l-none txt_left"><? echo $vis_language['TXTIMPACT']; ?></label>
	                <div class="col-sm-9">
			    <select class="form-control input-sm selectpicker" name="vis_impact" id="vis_impact"<? if (count($impact) > 10) echo ' data-live-search="true"'; ?>><? for ($i = 0; $i < count($impact); $i++)
echo '<option value="' . $impact[$i]['impact_id'] . '">' . $impact[$i]['name'] . '</option>'; ?>
			    </select>
		        </div>
                    </div>

                   <? }?>
			<? if(($tp==2 && $enddiv==2) || ($tp==3 && $enddiv==3) || ($tp==5 && $enddiv==3) || ($tp==6 && $enddiv==3)){
				if($tp!=5 && $tp!=6)$enddiv=0;echo "</div>";}?>
					
			<? if(($tp==5 && $enddiv==3) || ($tp==6 && $enddiv==3)){echo '<div class="form-group">';}?>
				
			<? if(1){$enddiv++;?>
                    <div class="<?=$class_properties;?>">
                        <label class="col-sm-3 control-label txt_left p-l-none p-r-none"><? echo $vis_language['TXTDUEBY']; ?></label>
                        <div class="col-sm-9">
                           <input type="text" name="vis_dueby" id="vis_dueby" class="form-control from_date input-sm" value="">
                        </div>
                    </div>

            <?php }?>
                <? if(($tp==2 && $enddiv==2) || ($tp==3 && $enddiv==3) || ($tp==4 && $enddiv==4) || ($tp==5 && $enddiv==3) || ($tp==6 && $enddiv==3) || ($tp==7 && $enddiv==4) || ($tp==8 && $enddiv==4)){
					if($tp!=5 && $tp!=6 && $tp!=7 && $tp!=8)$enddiv=0;echo "</div>";}?>
				<? if(($tp==5 && $enddiv==3) || ($tp==6 && $enddiv==3) || ($tp==7 && $enddiv==4) || ($tp==8 && $enddiv==4)){echo '<div class="form-group">';}?>    
                
			<? if(isset($module_setting['vis_category'])){$enddiv++;?>
                        <div class="<?=$class_properties;?>">
                            <label class="col-sm-3 control-label p-l-none txt_left"><? echo $vis_language['TXTTICKETCATEGORY']; ?></label>
                            <div class="col-sm-9" >
                                <select class="form-control input-sm selectpicker" name="vis_category" id="vis_category" <? if (count($ticket_cat_details) > 10) echo ' data-live-search="true"'; ?> onchange="get_subcategory(this.value);">
									<option value="0"><? echo $vis_language['TXTSELECT']; ?></option>
									<? if($ticket_cat_details!=-1)for ($i = 0; $i < count($ticket_cat_details); $i++){
   											 echo '<option value="' . $ticket_cat_details[$i]['category_id'] . '"';
												if($ticket_cat_details[$i]['category_id'] == $ticket_details_data['category_id']){ echo ' selected="selected"'; }
											echo ' >' . $ticket_cat_details[$i]['title'] . '</option>';
											}  ?> 
                                </select>
                            </div>
                        </div>  

                   <? if(($tp==2 && $enddiv==2) || ($tp==3 && $enddiv==3) || ($tp==4 && $enddiv==4) || ($tp==5 && $enddiv==3) || ($tp==6 && $enddiv==3) || ($tp==7 && $enddiv==4) || ($tp==8 && $enddiv==4) || ($tp==5 && $enddiv==5)){
					if($tp!=6 && $tp!=7 && $tp!=8)$enddiv=0;echo "</div>";}?>
				<? if(($tp==5 && $enddiv==3) || ($tp==6 && $enddiv==3) || ($tp==7 && $enddiv==4) || ($tp==8 && $enddiv==4)){echo '<div class="form-group">';}?>  
                 
		<? if(isset($module_setting['vis_subcategory'])){$enddiv++;?>
			<div class="<?=$class_properties;?>">
                            <label class="col-sm-3 control-label p-l-none txt_left"><? echo $vis_language['TXTTICKETSUBCATEGORY']; ?></label>
                            <div class="col-sm-9" id="ajax_subcategory">
                                <select class="form-control input-sm selectpicker" name="vis_subcategory" id="vis_subcategory" <? if (count($priorities) > 10) echo ' data-live-search="true"'; ?>  onchange="getitem(this.value);">
									<option value="0"><? echo $vis_language['TXTSELECT']; ?></option>
                                </select>
                            </div>
                        </div>

                  <? if(($tp==2 && $enddiv==2) || ($tp==3 && $enddiv==3) || ($tp==4 && $enddiv==4) || ($tp==5 && $enddiv==3) || ($tp==6 && $enddiv==3) || ($tp==7 && $enddiv==4) || ($tp==8 && $enddiv==4) || ($tp==5 && $enddiv==5) || ($tp==6 && $enddiv==6)){
					if($tp!=7 && $tp!=8 && ($tp!=5 && $enddiv!=3) )$enddiv=0;echo "</div>";}?>
				<? if(($tp==5 && $enddiv==3) || ($tp==6 && $enddiv==3) || ($tp==7 && $enddiv==4) || ($tp==8 && $enddiv==4)){echo '<div class="form-group">';}?>   
				 <? if(isset($module_setting['vis_item'])){$enddiv++;?>
                        <div class="<?=$class_properties;?>">
                            <label class="col-sm-3 control-label p-l-none txt_left"><? echo $vis_language['TXTTICKETITEM']; ?></label>
                            <div class="col-sm-9" id="ajax_item">
                                <select class="form-control input-sm selectpicker" name="vis_item" id="vis_item" <? if (count($ticket_types) > 10) echo ' data-live-search="true"'; ?>>
									<option value="0"><? echo $vis_language['TXTSELECT']; ?></option>
								</select>
                            </div>
                        </div>
                   
                       <?php }}}?>
				
				<? if(($tp==2 && $enddiv==2) || ($tp==3 && $enddiv==3) || ($tp==4 && $enddiv==4) || ($tp==5 && $enddiv==3) || ($tp==6 && $enddiv==3) || ($tp==7 && $enddiv==4) || ($tp==8 && $enddiv==4) || ($tp==7 && $enddiv==7) || ($tp==5 && $enddiv==5) || ($tp==6 && $enddiv==6)){
					if($tp!=8)$enddiv=0;echo "</div>";}?>
				
						<? if(VIS_ITIL==1){$enddiv++;?>
			<div class="<?=$class_properties;?>">
			     <label class="col-sm-3 control-label p-l-none txt_left"><? echo $vis_language['TXTLOCATION']; ?></label>
			     <div class="col-sm-9">
				   <select class="form-control input-sm selectpicker" name="vis_assets_location" id="vis_assets_location">
					<option value="0"><? echo $vis_language['TXTSELECT']; ?></option>
									    <?	if(isset($location_assets) && $location_assets!=NULL && $location_assets!=-1) {
										vis_show_subcategories($location_assets,''); ?>
										<?  } ?>
				   </select>
			     </div>
			</div>
                    <? }?>
                   
                <? if(($tp==2 && $enddiv==2) || ($tp==3 && $enddiv==3) || ($tp==4 && $enddiv==4) || ($tp==5 && $enddiv==3) || ($tp==6 && $enddiv==3) || ($tp==7 && $enddiv==4) || ($tp==8 && $enddiv==4) || ($tp==8 && $enddiv==8) || ($tp==7 && $enddiv==7) || ($tp==5 && $enddiv==5) || ($tp==6 && $enddiv==6)){echo "</div>"; }?>

				<div class="form-group">
					<label class="col-sm-1 control-label txt_left"><? echo $vis_language['TXTASSIGNEDTO']; ?></label>
					<div class="col-sm-11">
						<div class="ticketowner">
							<select name="vis_owner" <? if(count($staff_list)>10) echo ' data-live-search="true"';?> data-selector-label="<label class='m-n'><? echo $vis_language['TXTASSIGNEDTO']; ?></label>" class="selectpicker ticketowner">
                               <option value="0" selected="selected" data-content="<label class='checkbox-inline i-checks' onclick='javascript:assign_owner(0);'><input type='checkbox' checked='checked' class='staff_0'> <i></i><span class='m-l-xs font-normal'><? echo $vis_language['TXTUNASSIGNED'];?></span></label>"><? echo $vis_language['TXTUNASSIGNED'];?></option>
                               <? foreach ($staff_list as $staff) { ?>
                               <option value="<?= $staff['staff_id'];?>" data-content="<label class='checkbox-inline i-checks' onclick='javascript:assign_owner(<?= $staff['staff_id'];?>);'><input type='checkbox' class='staff_<?= $staff['staff_id']; ?>'> <i></i><span class='m-l-xs font-normal'><?= $staff['first_name'].' '.$staff['last_name'];?></span></label>"><?= $staff['first_name'].' '.$staff['last_name'];?></option>
                               <? } ?>
                           </select>

							<label class="padding-xs" id="owner_name"><?= $vis_language['TXTUNASSIGNED']; ?></label>
							<input type="hidden" name="vis_owner_list" id="vis_owner_list" value="0" />
							<input type="hidden" value="" name="vis_tag_list" id="vis_tag_list">
							<input type="hidden" value="" name="vis_label_list" id="vis_label_list">
						</div>
					</div>

                </div>
				<div class="form-group" style="display:<?= ($owner_cnt > 1)?'':'none' ?>" id="multipleownerlist">
					<label class="col-sm-1 control-label txt_left">Owners</label>
					<div class="col-sm-11">
						<div class="p-l-none" id="owners_list"></div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-1 control-label txt_left"><? echo $vis_language['TXTATTACHCI']; ?></label>
					<div class="col-sm-11">
						<span id="vis_select_cit_btn"><a href="javascript:void(0);" data-toggle="ajaxModal" data-modal-arguments="vis_module=cmdb&vis_operation=attach_ci&vis_static_area=vis_add_ciproduct_dialog&vis_department=<? echo $vis_department_id; ?>&attached_ci_ids=" class="btn btn-rounded btn-default btn-sm dropdown-toggle"><i class="vh vh-plus" style="font-size:10px;"></i> <? echo $vis_language['TXTSELECTCI']; ?></a></span>
						<div class="p-l-none" id="vis_attach_ci"><input type="hidden" name="vis_ci_attach" id="vis_ci_attach" value="" /></div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-1 control-label txt_left"><? echo $vis_language['TXTATTACHFILE']; ?></label>
					<div class="col-sm-11">
						<input type="file" name="files[]" multiple="multiple" class="filestyle" data-icon="false" data-classButton="btn btn-link link" data-buttonText="<? echo $vis_language['TXTATTACHFILE']; ?>" data-input="false" onchange="$(this).visExecution('upload_file', {'vis_static_area': '#vis_new_problem_attachments', 'vis_form': 'vis_new_problem_form', 'vis_form_attachment_area': '#vis_attachments'});">
                            <input type="hidden" name="vis_location" value="<? echo VIS_DOMAIN; ?>" />
                            <input type="hidden" name="vis_attachments" id="vis_attachments" value="" />
						<div class="p-l-none" id="vis_new_problem_attachments"></div>
                    </div>

                </div>
			<div class="b-2x b-t m-b-md"></div>
			<div class="form-group">				 
                          <div class="col-sm-12 text-right">
                                <button type="button" class="btn btn-primary m-l" onclick="$(this).visExecution('submit_form', {'vis_module': 'problem', 'vis_operation': 'open_new_problem', 'vis_form': 'vis_new_problem_form'})"><? echo $vis_language['TXTADDPROBLEM']; ?></button>
				<input type="hidden" name="vis_domain" value="<? echo $operation['domain_id']; ?>" />
				<input type="hidden" name="vis_client" id="vis_client" value="<? if (isset($client)) echo $client['client_id']; ?>" />
				<input type="hidden" name="vis_spam" id="vis_spam" value="<? if (isset($client)) echo $client['is_spam']; ?>" />
                          </div>
                       </div>
        </div>
        </form>
        </div>
    </section>
</section>
<script src="<?= VIS_PATH_SCRIPT; ?>file-input/bootstrap-filestyle.min.js"></script>
<?php
function vis_show_subcategories($location_assets,$call=NULL) {
         
        for($i=0;$i<count($location_assets);$i++) { ?>
		 <? echo '<option value="'.$location_assets[$i]['location_id'].'">'.ucfirst($location_assets[$i]['name']). '</option>';?>
				 <?php 
				if(isset($location_assets[$i]['subcat']) && $location_assets[$i]['subcat']!=NULL) { 
					 
					  vis_show_subcategories($location_assets[$i]['subcat'],'sub_cat'); 
					}
		}
		
    }
	?>
<script>
 var d = new Date();
var curr_time = d.getHours()+":"+d.getMinutes();
var curr_date= '<? echo date("M-d, Y")?> '+curr_time+'';
$(".selectpicker").selectpicker();
$('.from_date').datetimepicker({ format: "<?php echo VIS_DATETIMEPICKER_FORMAT;?>",defaultDate: curr_date});
<? if (!defined('VIS_HTML_EDITOR') || VIS_HTML_EDITOR == 1) { ?>
        $(function() {
            $('#vis_description').redactor({
				buttonSource: true,
				minHeight: 180, // pixels
                maxHeight: 180,
                imageUpload: "index.php?vis_tmpst=" + new Date().getTime() + "&vis_module=ticket&vis_operation=upload_file&vis_static_area=editor_image_upload",
                imageUploadParam: 'files',
				plugins: ['source'],
                deniedTags: ['html', 'head', 'link', 'body', 'meta', 'script','applet']
            });
			$(".redactor-toolbar").attr('z-index', '3 !important');
        });
<? } ?>
    function vis_remove_attachment(ticket_id, attach_location, vis_id) {
        var loc = '';
        loc = (attach_location != "" && typeof (attach_location) != "undefined") ? attach_location : "vis_attachments";
        $("#" + loc).val($("#" + loc).val().replace(ticket_id + ',', ''));
    }
	function vis_remove_ci_attachment(ticket_id){
		var attach_modi_val =$("#vis_ci_attach").val().replace(ticket_id + ',', '');
		$("#vis_ci_attach").val( attach_modi_val);
		var attach_ci_btn = '<a href="javascript:void(0);" data-toggle="ajaxModal" data-modal-arguments="vis_module=cmdb&vis_operation=attach_ci&vis_static_area=vis_add_ciproduct_dialog&vis_department=<? echo $vis_department_id; ?>&attached_ci_ids='+attach_modi_val+'" class="btn btn-rounded btn-default btn-sm dropdown-toggle"><i class="vh vh-plus" style="font-size:10px;"></i><?=$vis_language['TXTSELECTCI']?></a>';
		$('#vis_select_cit_btn').html(attach_ci_btn);
	}
        function get_subcategory(catid) {
	   <? if(isset($module_setting['vis_subcategory'])){ ?>
	  $('#ajax_subcategory').visExecution('load_operations', {'vis_module':'staff', 'vis_operation':'get_ticket_drp_subcategory', 'vis_category_id':catid, 'vis_flag':'ticket'}); 
	  <? }?>
        }
	function getitem(subcatid) {
	   <? if(isset($module_setting['vis_item'])){ ?>
	  $('#ajax_item').visExecution('load_operations', {'vis_module':'staff', 'vis_operation':'get_ticket_drp_item', 'vis_subcategory_id':subcatid, 'vis_flag':'ticket'}); 
	  <? }?>
       }
</script>
