<?php 
global $vis_language;
$request_data['vis_firstname'] = (isset($client_details[0]['first_name']))?$client_details[0]['first_name']:'';

$request_data['vis_lastname'] = (isset($client_details[0]['last_name']))?$client_details[0]['last_name']:'';
$request_data['vis_email'] = (isset($client_details[0]['email']))?$client_details[0]['email']:'';
//$client['client_id'] = (isset($client_details[0]['client_id']))?$client_details[0]['client_id']:'';
$client = $client_details[0];
$script=$captcha='';
$domain=$department=1;
if($form_group!=-1){
$form_group[0]['form_name'];
$script = stripslashes($form_group[0]['script']);
$form_group[0]['form_type'];
$form_group[0]['subject'];
$form_group[0]['department'];	
$arr = explode(':',$form_group[0]['department']);
$domain= $arr[0];
$department= $arr[1];

$captcha = $form_group[0]['captcha'];
}
/*if($form_group[0]['form_type']==1){
	$channel=5;
}else if($form_group[0]['form_type']==0){
	$channel=2;
}*/
$channel=5;
echo $script;
$style = (IS_LOGIN==1)?'display:none':'display:block'
?>
<style>
button.btn.btn-default.btn-sm.dropdown-toggle.selectpicker.bg-white{ height:30px; }
</style>
<header class="vis_login_head">
	<? if(isset($action[4]) && $action[4]!='' ) { ?> <script> $("#vis_submit_msg_div").show(); $("#vis_submit_msg_div").html('<? echo $vis_language['TXTTHANKYOU']; ?>'); </script><? }else { ?> <div id="vis_submit_msg_div" class="alert text-center alert-success" style="display:none"><? echo $vis_language['TXTTHANKYOU']; ?>!!!</div>  <? }/**/ ?>
	
</header>
<? //if(VIS_VIEW_SELFTICKET!=0) { ?>
<section class="container m-t-md" id="frm_container">
   <div class="row">
      <div class="col-md-12">
         <section class="container">        
                <div class="panel-body">
                  <div class="form-horizontal" >
					<!--<form class="form-horizontal" name="vis_submit_form" id="vis_submit_form" method="post">-->
                    <div class="col-md-12">
                      <div class="wrapper">
					  					 
						<h4><?php echo $form_group[0]['form_name'].'<div class="line line-dashed b-b line-lg pull-in"></div>'; //if($other_domain==1){ echo $form_group[0]['form_name'].'<div class="line line-dashed b-b line-lg pull-in"></div>'; } ?></h4>
						
                          <? //if(IS_LOGIN==0) { ?>
						 <!-- <div class="form-group">
							  <label for="mandatory fields" class="col-sm-2 control-label"> </label>
							  <div class="col-sm-8" style="text-align:right;">
								<? //echo $vis_language['MSGMANDATORYFIELDS']; ?>
							  </div>
						  </div>-->
                          <div class="form-group" style = "<?php echo $style; ?>">
                            <label for="FirstName" class="col-sm-2 control-label"><? echo $vis_language['TXTFIRSTNAME']; ?> <span style="color:#FF0000;">*</span></label>
                            <div class="col-sm-8">
                              <input type="text" class="form-control input-sm" data-type="text" data-required="true" name="vis_firstname" id="FirstName" value="<? echo $request_data['vis_firstname']; ?>" />
                            </div>
                          </div>
                          <div class="form-group" style = "<?php echo $style; ?>">
                            <label for="LastName" class="col-sm-2 control-label"><? echo $vis_language['TXTLASTNAME']; ?></label>
                            <div class="col-sm-8">
                              <input type="text" class="form-control input-sm" data-type="text" data-required="true" name="vis_lastname" id="LastName" value="<? echo $request_data['vis_lastname']; ?>" />
                            </div>
                          </div>
						  <?php if($form_group[0]['form_type']==1){ ?>
                          <div class="form-group" style = "<?php echo $style; ?>">
                            <label for="PersonalEmail" class="col-sm-2 control-label"><? echo $vis_language['TXTEMAIL']; ?> <span style="color:#FF0000;">*</span></label>
                            <div class="col-sm-8">
                              <input type="email" class="form-control input-sm" data-type="email" data-required="true" name="vis_email" id="PersonalEmail" value="<?= $request_data['vis_email']; ?>" />
                            </div>
                          </div>
						  <?php }if($form_group[0]['form_type']==0){ ?>
						  <div class="form-group" style = "<?php echo $style; ?>">
                            <label for="PersonalEmail" class="col-sm-2 control-label"><? echo $vis_language['TXTCONTACTNUMBER']; ?></label>
                            <div class="col-sm-8">
                              <input type="text" class="form-control input-sm" data-type="text" data-required="true" name="vis_contact_number" id="vis_contact_number" value="<?php echo $client['contact_number'];?>" />
                             
                            </div>
                          </div>
						  <?php } //} 
						  echo $form_field_var;						  
						 ?> 
						 
						 <style>						    button.btn.btn-default.btn-sm.dropdown-toggle.selectpicker.bg-white{ height:30px; }
						 </style>
						<div style="display:none;" id="vis_attachments"></div>
						<? if($captcha==1){ ?>
                            <div class="form-group">
                                <label for="Password" class="col-sm-2 control-label"><? echo $vis_language['TXTIMGVERIFY']; ?></label>
                                <div class="col-sm-8">
                                    <div class="col-sm-10">	
                                      <img src="<?= VIS_PATH_TEMPLATE ?>get_captcha.php?clr=<? echo str_replace("#",'',VIS_THEME_COLOR); ?>" alt="" id="captcha" class="col-sm-4"/>
                                      <div id="refresh" class="col-sm-3 m-t link"><i class="vh vh-lg vh-refresh"></i> <? echo $vis_language['TXTREFRESH']; ?></div>
                                    </div> 
                                      <input type="text" class="form-control input-sm" name="captchacode"  id="captchacode" autocomplete="off"/>
                                </div>
                            </div><? } ?>
						
                          <div class="line line-dashed b-b line-lg pull-in"></div>
                      </div> <!-- /.wrapper -->
                    </div> <!-- /.col-md-12 -->
                    
                    <div class="col-lg-offset-2 col-lg-8 m-b-lg col-0">
						  <input type="hidden" name="vis_module" id="vis_module" value="ticket" /> 
						  <input type="hidden" name="vis_operation" id="vis_operation" value="open_new_ticket" />
						  						  
						  <input type="hidden" name="vis_domain" id="vis_domain" value="<?php echo $domain; ?>" />
						  <input type="hidden" name="vis_department" id="vis_department" value="<?php echo $department; ?>" >
						  <input type="hidden" name="vis_status" value="1" />
                          <input type="hidden" name="vis_priority" id="vis_priority"  value="1" >
						  <input type="hidden" name="vis_type" id="vis_type" value="1" >
						  
						  <input type="hidden" name="vis_subject" id="vis_subject"  value="<?php echo $form_group[0]['subject']; ?>" >
						  <input type="hidden" name="vis_ticket_post" id="vis_ticket_post"  value="" >
						  <input type="hidden" name="vis_channel" id = "vis_channel" value="<?php echo $channel; ?>" />
						  <input type="hidden" name="vis_form_id" id="vis_form_id" value="<?php echo $action[3];?>" />
						  <input type="hidden" name="vis_honeypot" id="vis_honeypot" />
						
						  <button id="btn_submit_ticket" type="button" class="btn btn-primary" ><? echo $vis_language['TXTSUBMIT']; ?></button>
						 
                         <!--onclick="submit_form(0); " <button type="submit" class="btn btn-primary"><? echo $vis_language['TXTSUBMIT']; ?></button>
                          <input type="hidden" name="vis_module" value="ticket" /><input type="hidden" name="vis_operation" value="open_new_ticket" />-->
                          <?php /*if(IS_LOGIN==1) { ?>
						  <input type="hidden" name="vis_client" value="<? echo $client['client_id']; ?>" />
						  <input type="hidden" name="vis_from_name" value="<? echo $client['first_name'].' '.$client['last_name']; ?>" />
						  <input type="hidden" name="vis_from_email" value="<? echo $client['email']; ?>" />
						  <? }*/ ?>
                          <?php /*if(IS_LOGIN!=1){ ?><input type="hidden" name="vis_honeypot" id="vis_honeypot" /><? }*/ ?>
                    </div>
                    <!--</form>-->
                  </div>
                </div>
            </section> <!-- / .panel -->
		</div>
      </div><!-- /.row --><? //} ?>
 </section> <!-- / .panel -->

<script>

 $('.start').datetimepicker(); 
 
 var curr_stamp=0;
$(document).ready(function(){
    $("#btn_submit_ticket").click(function(){  

/*function submit_form(view_ticket) { */
    if(curr_stamp==0 || (curr_stamp < (Date.now()-10000))){
        var btn = $("#btn_submit_ticket");
        btn.button('loading');
        curr_stamp = Date.now();
        var tempcustom=Array();
        var i=0;
         $('[id^="field"]' ).each(function(){
			if($(this).is(":checkbox") || $(this).is(":radio")){
				if($(this).is(":checked")){
				   tempcustom[i]={cid:this.id,value:this.value};
				   i=i+1;
				}
			}
			else {
				 tempcustom[i]={cid:this.id,value:$(this).val()};
				   i=i+1;
			   }
            });
			
			<? $dmn =  '$("#vis_domain").val()'; ?>			
			
        $.ajax({
            url: 'index.php',
            dataType: 'json',
            data: {'vis_module':"ticket", 'vis_operation':"open_new_ticket", 'vis_firstname':$("#FirstName").val(), 'vis_lastname':$("#LastName").val(), 'vis_department':$("#vis_department").val(),'vis_channel':'<?php echo $channel; ?>', <?php if($form_group[0]['form_type']==1){ ?> 'vis_email':$("#PersonalEmail").val(), <?php }else if($form_group[0]['form_type']==0){ ?> 'vis_contact_number':$("#vis_contact_number").val(), <?php } ?>'vis_priority':$("#vis_priority").val(),'vis_attachments':$("#vis_attachments").html(), 'vis_type':$("#vis_type").val(),'vis_subject':$("#vis_subject").val(), 'vis_ticket_post':$("#vis_ticket_post").val(), 'vis_status':'1','vis_form_type':'<?php echo $form_group[0]['form_type']; ?>','vis_form_id':$("#vis_form_id").val() , 'vis_custom_form':'1', <? if($client['client_id']!='' && isset($client['client_id'])) { ?> 'vis_client':'<? echo $client['client_id']; ?>','vis_spam':'<? echo $client['is_spam']; ?>','vis_from_email':'<? echo $client['email']; ?>','vis_from_name':'<? echo $client['first_name']." ".$client['last_name']; ?>',<?  } ?> 'vis_domain':$("#vis_domain").val()<? if($captcha==1) { ?> ,'captchacode':$("#captchacode").val() <? } ?>,'form_field':tempcustom },
            type: "POST",
             success: function(data) {  //alert(data.vis_submitted);
                if(data.vis_submitted=='true')
                {
                    //window.location = "index.php?/ticket/forms/<?php echo $action[3];?>/"+data.vis_msg;
					//$('#vis_submit_form').trigger("reset");					
					$("#vis_submit_msg_div").show();
					$("#frm_container").hide();	
					var btn = $("#btn_submit_ticket"); btn.button('reset'); 
					$("#vis_submit_msg_div").html('<? echo $vis_language['TXTTHANKYOU']; ?>');			

                }
                else if(data.vis_submitted=='false') { //window.location = "index.php?/ticket/forms/<?php echo $action[3];?>/"+data.vis_msg; 
				//$('#vis_submit_form').trigger("reset");	
				$("#vis_submit_msg_div").show();
				$("#frm_container").hide();
				var btn = $("#btn_submit_ticket"); btn.button('reset');
				$("#vis_submit_msg_div").html('<? echo $vis_language['TXTTHANKYOU']; ?>'); 
				$("#vis_submit_msg_div").removeClass('alert-danger').addClass('alert-success');				
				}
                else if(data.vis_error_msg!='') {  var btn = $("#btn_submit_ticket");  $("#vis_submit_msg_div").show(); $("#vis_submit_msg_div").removeClass('alert-success').addClass('alert-danger'); $("#vis_submit_msg_div").html(data.vis_error_msg); window.scrollTo(0,0); btn.button('reset'); }		 
            }
        });
    }
/*} */
});
});
function vis_remove_attachment(attach_id,field_id){
	$.ajax({
        url: 'index.php',
        data: {'vis_module':"ticket", 'vis_operation':"remove_attachment", 'vis_attachment_id':attach_id },
        type: "POST",
        success: function(data) {  }
    });
    var attachments=$("#vis_attachment_count"+field_id).val();
	$("#vis_attachment_count"+field_id).val(eval(parseInt(attachments)-1));
	var max_attach=$("#vis_max_attach"+field_id).val();
	if((attachments-1)<=max_attach) $("#vis_attach_file"+field_id).css('display','');
}

$('#refresh').click(function() {  
    change_captcha();
 });

function change_captcha(){
    document.getElementById('captcha').src="<?= VIS_PATH_TEMPLATE ?>get_captcha.php?clr=<? echo str_replace("#",'',VIS_THEME_COLOR); ?>&rnd=" + Math.random();
 }
</script>
<script src="<? echo VIS_PATH_SCRIPT; ?>file-upload/jquery.ui.widget.js"></script>
<script src="<? echo VIS_PATH_SCRIPT; ?>file-upload/jquery.fileupload.js"></script>
 <script src="<?php echo VIS_PATH_SCRIPT; ?>file-input/bootstrap-filestyle.min.js"></script>

<script type="text/javascript">
$('body').on('drop', function (e) {
     return false;
});
$(document).on('click','.selectpicker',function(e){
	var winwdt=$(window).width();
	if(winwdt <810){
var lilen=$(this).next('#lst').children('ul').children().length;
$(this).next('#lst').css('overflow-y','scroll');
		if(lilen <3 && lilen>1)
		{$(this).next('#lst').css('min-height',(40*parseInt(lilen))+'px');
		}else{		$(this).next('#lst').css('min-height','120px');}
	}
	});
</script>
<script>
  function resizeIframe(obj) {
    obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
  }
</script>
