<? global $vis_language;  ?>
<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['TXTOPENNEWTICKETS']; ?></h4>
        </div>
        <div class="modal-body">
            <div class="row">
                <div class="col-sm-12">
                    <form action="index.php" role="form" class="form-horizontal" name="vis_ticket_first_form" id="vis_ticket_first_form">
                        <div class="form-group">
                            <label class="col-sm-3 control-label txt_nowrap"><? echo $vis_language['TXTDEPARTMENT']; ?></label>
                            <div class="col-sm-9">
                                <select name="vis_department" id="vis_department_new" class="form-control input-sm selectpicker"<? if(count($departments)>10) echo ' data-live-search="true"';?> onchange="get_channel_list(this.value);"><?
									if($departments!=-1) for($i=0;$i<count($departments); $i++)
									echo '<option value="'.$departments[$i]['domain_id'].':'.$departments[$i]['department_id'].'">'.$departments[$i]['domain_name'].' :: '.$departments[$i]['department_name'].'</option>' ?>
									</select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><? echo $vis_language['TXTCHANNEL']; ?></label>
                            <div class="col-sm-9" id="vis_channel_list">
                                <select name="vis_channel" id="vis_channel" class="form-control input-sm selectpicker" <? if(count($channels)>10) echo 'data-live-search="true"';?>><?
									if($channels!=-1)
									{										
										for($i=0;$i<count($channels); $i++)
										{ 
										if($channels[$i]['channel_id']!=7){ //set for service item
										echo '<option '.((isset($operation['vis_channel_id']) && $operation['vis_channel_id']==$channels[$i]['channel_id']) || ($operation['vis_chat_type']=='livechatinc' && $channels[$i]['channel_id']=='8') ||($operation['vis_chat_type']=='teamviewer' && $channels[$i]['channel_id']=='14') || ($operation['vis_chat_type']=='clickdesk' && $channels[$i]['channel_id']=='17')|| ($operation['vis_chat_type']=='zopim' && $channels[$i]['channel_id']=='18')|| ($operation['vis_chat_type']=='teamviewersession' && $channels[$i]['channel_id']=='14')|| ($operation['vis_chat_type']=='gotomeeting' && $channels[$i]['channel_id']=='12') || ($operation['vis_chat_type']=='gotoassist' && $channels[$i]['channel_id']=='13') || ($operation['vis_chat_type']=='webex' && $channels[$i]['channel_id']=='15') || ($operation['vis_chat_type']=='twilio' && $channels[$i]['channel_id']=='16') || ($operation['vis_chat_type']=='livezilla' && $channels[$i]['channel_id']=='9') || ($operation['vis_chat_type']=='userlike' && $channels[$i]['channel_id']=='10') || ($operation['vis_chat_type']=='comm100' && $channels[$i]['channel_id']=='11')|| ($operation['vis_chat_type']=='exotel' && $channels[$i]['channel_id']=='19') || ($operation['vis_chat_type']=='googlecalender' && $channels[$i]['channel_id']=='20')||  ($operation['vis_chat_type']=='crisp' && $channels[$i]['channel_id']=='21')|| ($operation['vis_chat_type']=='aircall' && $channels[$i]['channel_id']=='22')|| ($operation['vis_chat_type']=='asterisk' && $channels[$i]['channel_id']=='23') ?'selected="selected"':'').'value="'.$channels[$i]['channel_id'].'" '.$chk.'>'.$channels[$i]['channel_name'].'</option>';
										}
									}
									}?>
								</select>
                            </div>
                        </div>
                        <? if((!isset($operation['vis_client']) && $operation['vis_client'] != 1) || isset($operation['vis_chat_id'])) { ?>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><? echo $vis_language['TXTINTERNALTICKET']; ?></label>
                            <div class="col-sm-9">                                
                                <label class="checkbox-inline i-checks">
								<input type="checkbox" name="vis_internal_ticket" id="vis_internal_ticket" value="0"><i></i>
							</label>
                            </div>
                        </div>     
                        <? } ?>
                    </form>
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <a class="btn btn-default" data-dismiss="modal"><? echo $vis_language['TXTCANCEL']; ?></a>
		 <? 
		 //echo $operation['vis_staff_name'].$operation['vis_visitor_name'];
		  if(isset($operation['twilio_msg'])){ 
		  $vis_email=($operation['vis_email_id']=='') ? "''" : "'".$operation['vis_email_id']."'";
		  ?>        
             <a class="btn btn-primary" data-dismiss="modal" onclick="$('#vis_workpanel_div').visExecution('load_module','<? echo $vis_language['TXTOPENNEWTICKETS']; ?>', {'vis_module':'ticket','vis_operation':'new_ticket','vis_domain_id':'<? echo $operation['vis_domain_id']; ?>','vis_chat_type':'<? echo $operation['vis_chat_type']; ?>','vis_chat_id':'<? echo $operation['vis_chat_id']; ?>', 'vis_twilio_msg':'yess', 'vis_internal_ticket':$('#vis_ticket_first_form #vis_internal_ticket').is(':checked')?1:0, 'department_id': $('#vis_ticket_first_form #vis_department_new').val(), 'channel_id': $('#vis_ticket_first_form #vis_channel').val(), 'vis_email_id':<? echo $vis_email; ?>});"><? echo $vis_language['TXTNEXT']; ?></a>
		<? }elseif(isset($operation['vis_chat_type']) && $operation['vis_chat_type']=='twilio' || $operation['vis_chat_type'] == 'teamviewer'){
				$vis_email=($operation['vis_email_id']=='') ? "''" : "'".$operation['vis_email_id']."'"; 
		?>
						 <a class="btn btn-primary" data-dismiss="modal" onclick="$('#vis_workpanel_div').visExecution('load_module','<? echo $vis_language['TXTOPENNEWTICKETS']; ?>', {'vis_module':'ticket','vis_operation':'new_ticket','vis_domain_id':'<? echo $operation['vis_domain_id']; ?>','vis_chat_type':'<? echo $operation['vis_chat_type']; ?>','vis_chat_id':'<? echo $operation['vis_chat_id']; ?>', 'vis_internal_ticket':$('#vis_ticket_first_form #vis_internal_ticket').is(':checked')?1:0, 'department_id': $('#vis_ticket_first_form #vis_department_new').val(), 'channel_id': $('#vis_ticket_first_form #vis_channel').val(), 'vis_email_id':<? echo $vis_email; ?>});"><? echo $vis_language['TXTNEXT']; ?></a>
        <? }elseif(isset($operation['vis_chat_type']) && $operation['vis_chat_type']=='crisp'){
			$vis_email=($operation['vis_email_id']=='') ? "''" : "'".$operation['vis_email_id']."'";
		?> 
		 <a class="btn btn-primary" data-dismiss="modal" onclick="$('#vis_workpanel_div').visExecution('load_module','<? echo $vis_language['TXTOPENNEWTICKETS']; ?>', {'vis_module':'ticket','vis_operation':'new_ticket','vis_domain_id':'<? echo $operation['vis_domain_id']; ?>','vis_chat_type':'<? echo $operation['vis_chat_type']; ?>',  'vis_session_id':'<? echo $operation['vis_session_id'];?>' , 'vis_website_id':'<?echo $operation['vis_website_id'];?>' , 'vis_client':'', 'vis_internal_ticket':$('#vis_ticket_first_form #vis_internal_ticket').is(':checked')?1:0, 'department_id': $('#vis_ticket_first_form #vis_department_new').val(), 'channel_id': $('#vis_ticket_first_form #vis_channel').val(), 'vis_email_id':<? echo $vis_email;?>});"><? echo $vis_language['TXTNEXT']; ?></a>
                            
        <?php }	elseif(isset($operation['vis_chat_type']) && isset($operation['vis_chat_id'])){
			$vis_email=($operation['vis_email_id']=='') ? "''" : "'".$operation['vis_email_id']."'"; 
		  ?> 
                         <a class="btn btn-primary" data-dismiss="modal" onclick="$('#vis_workpanel_div').visExecution('load_module','<? echo $vis_language['TXTOPENNEWTICKETS']; ?>', {'vis_module':'ticket','vis_operation':'new_ticket',<?php if(isset($operation['vis_aircall_domain_id'])){ echo "'vis_aircall_domain_id':'".$operation['vis_aircall_domain_id']."',"; }else if(isset($operation['vis_asterisk_domain_id'])){ echo "'vis_asterisk_domain_id':'".$operation['vis_asterisk_domain_id']."',"; }  ?>'vis_domain_id':'<? echo $operation['vis_domain_id']; ?>','vis_chat_type':'<? echo $operation['vis_chat_type']; ?>','vis_chat_id':'<? echo $operation['vis_chat_id']; ?>', 'vis_internal_ticket':$('#vis_ticket_first_form #vis_internal_ticket').is(':checked')?1:0, 'department_id': $('#vis_ticket_first_form #vis_department_new').val(), 'channel_id': $('#vis_ticket_first_form #vis_channel').val(), 'vis_email_id':<? echo $vis_email; ?><?php if($operation['vis_chat_type']=='userlike'){ echo ", 'vis_visitor_name':'".$operation['vis_visitor_name']."','vis_staff_name':'".$operation['vis_staff_name']."'";} else if($operation['vis_chat_type']=='zopim'){ echo ", 'vis_visitor_name':'".$operation['vis_visitor_name']."'";} ?>});"><? echo $vis_language['TXTNEXT']; ?></a>
        <? }elseif(isset($operation['vis_chat_type'])){
			$vis_email=($operation['vis_email_id']=='') ? "''" : "'".$operation['vis_email_id']."'";
		?> 
                          <a class="btn btn-primary" data-dismiss="modal" onclick="$('#vis_workpanel_div').visExecution('load_module','<? echo $vis_language['TXTOPENNEWTICKETS']; ?>', {'vis_module':'ticket','vis_operation':'new_ticket','vis_domain_id':'<? echo $operation['vis_domain_id']; ?>','vis_chat_type':'<? echo $operation['vis_chat_type']; ?>','vis_internal_ticket':$('#vis_ticket_first_form #vis_internal_ticket').is(':checked')?1:0, 'department_id': $('#vis_ticket_first_form #vis_department_new').val(), 'channel_id': $('#vis_ticket_first_form #vis_channel').val(), 'vis_email_id':<? echo $vis_email; ?><?php if($operation['vis_chat_type']=='clickdesk') echo ", 'vis_position':'".$operation['vis_position']."'"; elseif($operation['vis_chat_type']=='googlecalender' && $operation['vis_event']==1) echo ", 'vis_cal_id':'".$operation['vis_cal_id']."','vis_event_id':'".$operation['vis_event_id']."','vis_event':'1'"; elseif($operation['vis_chat_type']=='googlecalender' && $operation['vis_task']==1) echo ", 'vis_task_id':'".$operation['vis_task_id']."','vis_tasklist_id':'".$operation['vis_tasklist_id']."','vis_task':'1'"; ?>});"><? echo $vis_language['TXTNEXT']; ?></a>
        <?php } elseif(isset($operation['vis_client']) && $operation['vis_client']==1){ 
			  $vis_email=($operation['vis_email_id']=='') ? "'".$client['user_name']."'" : "'".$operation['vis_email_id']."'";
		?>        
						  <a class="btn btn-primary" data-dismiss="modal" onclick="$('#vis_workpanel_div').visExecution('load_module','<? echo $vis_language['TXTOPENNEWTICKETS']; ?>', {'vis_module':'ticket','vis_operation':'new_ticket','vis_domain_id':'<? echo $operation['vis_domain_id']; ?>', 'vis_internal_ticket':$('#vis_ticket_first_form #vis_internal_ticket').is(':checked')?1:0, 'department_id': $('#vis_ticket_first_form #vis_department_new').val(), 'channel_id': $('#vis_ticket_first_form #vis_channel').val()<? if(isset($operation['vis_client_id']) && is_numeric($operation['vis_client_id'])) echo ", 'vis_client_id': ".$operation['vis_client_id']; if(isset($operation['vis_tweet_details']) && $operation['vis_tweet_details']!='') echo ", 'vis_tweet_details':'".$operation['vis_tweet_details']."'"; ?>,'vis_email_id':<? echo $vis_email; ?>,'vis_contact_no': '<? echo $client['contact_number'];?>','vis_client':1});"><? echo $vis_language['TXTNEXT']; ?></a>
		<? }		else {?>
						  <a class="btn btn-primary" data-dismiss="modal" onclick="$('#vis_workpanel_div').visExecution('load_module','<? echo $vis_language['TXTOPENNEWTICKETS']; ?>', {'vis_module':'ticket','vis_operation':'new_ticket','vis_domain_id':'<? echo $operation['vis_domain_id']; ?>','vis_internal_ticket':$('#vis_ticket_first_form #vis_internal_ticket').is(':checked')?1:0, 'department_id': $('#vis_ticket_first_form #vis_department_new').val(), 'channel_id': $('#vis_ticket_first_form #vis_channel').val()<? if(isset($operation['vis_client_id']) && is_numeric($operation['vis_client_id'])) echo ", 'vis_client_id': ".$operation['vis_client_id']; if(isset($operation['vis_tweet_details']) && $operation['vis_tweet_details']!='') echo ", 'vis_tweet_details':'".$operation['vis_tweet_details']."'"; ?>});"><? echo $vis_language['TXTNEXT']; ?></a>
		<? }?>
        </div>
    </div>
</div>
<script>
    $(".selectpicker").selectpicker();
    function get_channel_list(dept_id){
        $.ajax({
            url: 'index.php',
            data: {'vis_module':"ticket", 'vis_operation':"get_channel_list", 'vis_dept':dept_id },
            type: "POST",
            dataType: "json",
            success: function(data) {
                    $("#vis_channel_list").html(data.channels);
                    $(".selectpicker").selectpicker();
                 }
        });
    }
</script>
