<?  global $vis_language;
   $flag = ($custom_field_var != '')?1:0;
   
   if($custIds != -1 && $custom_field_var != ''): ?>
<script> $("#vis_submit_msg_div").show(); $("#vis_submit_msg_div").html('<? echo $vis_language['MSGFEEDBACKERR']; ?>'); </script> 
<? endif; ?>  
 <section class="container m-t-md">
   <div class="row">
      <div class="col-md-12">
        <section class="panel shadow-none">
        
         <header class="panel-heading bg-white  m-b">
            <div class="wrapper b-b">
               <div class="row m-b-sm">
                  <div class="col-md-12">
                     <div class="row">
                        <label class="col-md-2 m-b h4 font-bold"><a href="index.php?/ticket/ticket-details/<?= $ticket_details['ticket_hash'].'/'.$ticket_details['ticket_id'];?>"><?= $ticket_details['ticket_hash']. ' : '; ?></a></label>
                        <div class="col-md-10  m-b h4 font-bold "><a href="index.php?/ticket/ticket-details/<?= $ticket_details['ticket_hash'].'/'.$ticket_details['ticket_id'];?>"><?= $ticket_details['subject']; ?></a></div>
                     </div>
                  </div>
                  <div class="col-md-6">
                     <div class="row">
                        <label class="col-md-4 font-bold"><?= $vis_language['TXTCREATEDON']; ?></label>
                        <div class="col-md-8"><?= format_datetime($ticket_details['receive_date']); ?></div>
                     </div>
                  </div>
                  <div class="col-md-6">
                     <div class="row">
                        <label class="col-md-4 font-bold"><?= $vis_language['TXTMODIFIEDON']; ?></label>
                        <div class="col-md-8"><?=  format_datetime($ticket_details['modify_date']); ?></div>
                     </div>
                  </div>
                  <div class="col-md-6">
                     <div class="row">
                        <label class="col-md-4 font-bold"><?= $vis_language['TXTDEPARTMENT']; ?></label>
                        <div class="col-md-8"><?= $ticket_details['department_name']; ?></div>
                     </div>
                  </div>
                  <div class="col-md-6">
                     <div class="row">
                        <label class="col-md-4 font-bold"><?= $vis_language['TXTSTATUS']; ?></label>
                        <div class="col-md-8"><?= $ticket_details['ticket_status']; ?></div>
                     </div>
                  </div>
                  <? if($ticket_type != -1): ?>
                  <div class="col-md-6">
                     <div class="row">
                        <label class="col-md-4 font-bold"><?= $vis_language['TXTTICKETTYPE']; ?></label>
                        <div class="col-md-8"><?= $ticket_details['ticket_type']; ?></div>
                     </div>
                  </div>
                  <? endif;?>								 
                  <? if($ticket_priority != -1): ?>
                  <div class="col-md-6">
                     <div class="row">
                        <label class="col-md-4 font-bold"><?= $vis_language['TXTPRIORITY']; ?></label>
                        <div class="col-md-8"><?= $ticket_details['ticket_priority']; ?></div>
                     </div>
                  </div>
                  <? endif;
                     if(VIS_HEAD_MENU_ASSIGNEDTO==1){ ?>
                  <div class="col-md-12">
                     <div class="row">
                        <div class="col-md-2 font-bold"><?= $vis_language['TXTASSIGNTO']; ?></div>
                        <div class="col-md-10">
                           <? if($ticket_details['owner'] == "") echo $vis_language['TXTUNASSIGNED'];
                              else{
                                    $owners=explode(',',$ticket_details['owner']);
                                    for($i=0;$i<count($owners);$i++){ ?>
                           <span class="btn btn-xs alert-success m-r-xs"><?= $owners[$i]; ?></span>
                           <? }
                              } ?>
                        </div>
                     </div>
                  </div>
                  <? } 
                     if(VIS_ITIL==1 && isset($service_ticket_details) && $service_ticket_details!=-1){?>  
                  <div class="m-b col-md-12">
                     <div class="row">
                        <div class="col-sm-3 m-t-xs">
                           <label><? echo $vis_language['TXTSERVICEITEM']?></label>
                           <span class="m-l-sm"><? echo $service_details[0]['name'];?></span>
                        </div>
                        <div class="col-sm-3 m-t-xs">
                           <label><? echo $vis_language['TXTCOST'];?></label>
                           <span class="m-l-sm"><? echo $service_ticket_details[0]['total_cost'].' '.$domain[0]['currency'];?></span>
                        </div>
                        <div class="col-sm-3 m-t-xs">
                           <label><? echo $vis_language['TXTQUANTITY']; ?></label>
                           <span class="m-l-sm"><? echo $service_ticket_details[0]['quantity'];?></span>
                        </div>
                        <div class="col-sm-3 m-t-xs">
                           <label><? echo $vis_language['TXTTOTAL']; ?></label>
                           <span class="m-l-sm"><? echo $service_ticket_details[0]['quantity']*$service_ticket_details[0]['total_cost'].' '.$domain[0]['currency'];?></span>
                        </div>
                     </div>
                  </div>
                  <? if($service_custom_details!=-1){?>
                  <div class="row m-t">
                     <div class="col-md-12">
                        <? for($i=0;$i<count($service_custom_details);$i++){?>
                        <!--<div class="form-group">
                           <label class="col-sm-2 control-label text-right" title=""><? echo $service_custom_details[$i]['field_name']?></label>
                           <div class="col-sm-10">
                               <label class="control-label"><? echo $service_custom_details[$i]['field_value'];?>&nbsp;</label>
                           </div>
                           </div>-->
                        <? if($service_custom_details[$i]['field_type']==7 || $service_custom_details[$i]['field_type']==4){
                           if($t==0){?>
                        <div class="form-group">
                           <label class="col-sm-2 control-label text-right" title=""><? echo $service_custom_details[$i]['field_name']?></label>
                           <div class="col-sm-10">
                              <label class="control-label"><? echo $service_custom_details[$i]['field_value'];?>&nbsp;</label>
                              <? }else {?>
                              , <label class="control-label"><? echo $service_custom_details[$i]['field_value'];?>&nbsp;</label>
                              <? }$t++;?>
                              <? }else{
                                 if(($t>0 && $service_custom_details[$i]['field_type']!=7) || ($t>0 && $service_custom_details[$i]['field_type']!=4)){ 
                                 		echo '</div></div>';
                                 		$t=0;
                                 }?>                   
                              <div class="form-group">
                                 <label class="col-sm-2 control-label text-right" title=""><? echo $service_custom_details[$i]['field_name']?></label>
                                 <div class="col-sm-10">
                                    <label class="control-label"><? echo $service_custom_details[$i]['field_value'];?>&nbsp;</label>
                                 </div>
                              </div>
                              <? }
                                 ?> 		
                              <? }?> 	
                           </div>
                        </div>
                        <? }?>
                        <?php }?>    
                     </div>
                  </div>
         </header>
         <div class="panel-body no-padder">
         <form class="form-horizontal" id="vis_form_client_feedback" name="vis_form_client_feedback" method="post" role="form">
         <div class="col-md-12">
         <?
            if(VIS_HEAD_MENU_RATING==1){ ?>
         <div class="wrapper col-sm-offset-2">
         <label class="col-sm-4 control-label font-bold" ><? echo $vis_language['TXTRATETICKET']; ?></label>
         <span class="vh-yellow m-l-xs h3 " id="vis_rating_class">
         <?   $ticket_details['rating']; if($ticket_details['rating'] == 0) {
            for($cn=0;$cn<5;$cn++) 
            {
            $rate = $cn+1;					  
            echo '<a href="javascript:void(0);" onclick="set_rating('.$rate.')" ><i class="vh  vh-lg '.($cn<$ticket_details['rating']?'vh-star':'vh-star-empty').'"></i></a>';
            }
            } 
            else   
            {
            for($cn=0;$cn<5;$cn++) 							  
            echo '<i class="vh vh-lg '.($cn<$ticket_details['rating']?'vh-star':'vh-star-empty').'"></i>';
            }
            ?> 
         </span> 
         </div><div class="wrapper b-b m-b"> </div><? } ?> 
         <? if($custom_field_var != ''){ ?>
         <div id="vis_global_msg_div" class="alert alert-danger" style="display: none;"></div>
         <? echo $custom_field_var; ?>
         
         <div class="form-group">
         </div>
         </div>
         <?php if($custIds == -1) { ?> 
         <div class="col-lg-offset-2 col-lg-8 m-b-lg">
         <button type="submit" class="btn btn-primary" onclick="return check_customdata();"><?= $vis_language['TXTSUBMIT']; ?></button>
         <input type="hidden" name="vis_operation" value="add_feedback" /><input type="hidden" name="vis_module" value="ticket" /><input type="hidden" name="vis_email" value="<? echo $user_email; ?>" />
         <input type="hidden" name="vis_department" value="<? echo $derpartment_id; ?>" />
         <input type="hidden" name="vis_ticket_id" id="vis_ticket_id" value="<? echo $ticket_id; ?>" />
        
         </div>
         <?php } }?>
         </div>
         </form>    
         </div>
         </div>
      </section>
      <!-- / .panel -->
   </div>
</div>
</section>
<!-- /.row -->
<script>

  $('.start').datetimepicker({
        format: "<?php echo VIS_DATETIMEPICKER_FORMAT;?>"
	 });
   function set_rating(rating)
   {
   	var rating_data ='';
   	 $.ajax({
             url: 'index.php',
             dataType: 'json',
             data: {'vis_module':"ticket", 'vis_operation':"rate_ticket", 'ticket_id':$("#vis_ticket_id").val(),'rate_flag':1,'rate':rating},
             type: "POST",
             success: function(data) {
   		    if($.trim(data) == 1)
   		    {
   				for(cn=0;cn<5;cn++) 							  
   				rating_data +=  '<i class="vh  '+(cn<rating?'vh-star':'vh-star-empty')+'"></i>';
   				$('#vis_rating_class').html(rating_data);
   			    $("#vis_submit_msg_div").show(); $("#vis_submit_msg_div").html('<?= $vis_language['MSGSUCCOPRT']; ?>');
   			}
             }
         });
   		
   }
   function check_customdata()
   {
		var val =  $('#vis_form_client_feedback').find('input[name!=vis_operation]').serialize();
        
		var textareaval='';
         $('[id^="field"]' ).each(function(){
		if($(this).is("textarea")){
				 textareaval=textareaval+'&'+this.id+'='+$(this).val();
			}
            });
	
		 var returns=true;
   	 $.ajax({
             url: 'index.php',
             dataType: 'json',
             data: val+textareaval+'&vis_operation=check_customdata&location=3',
             type: "POST",
			 async:false,
             success: function(data) {
			if(data.res==0)
				 {
					 $("#vis_submit_err_div").show();
					 $("#vis_submit_err_div").html(data.msg); window.scrollTo(0,0);
				 setTimeout(function(){$("#vis_submit_err_div").hide();},10000);
//					  $("#vis_global_msg_div").html(data.msg);

returns=false;
				 }
				 else
				 {
					 returns=true;
				 }
				 
			             }
         });
		 return returns; 
	  
   }
 

</script>
