<? global $vis_language; ?>

<section  class="container m-t-md fourms">
<div class="row">
   <div class="col-md-12">
      <section class="panel shadow-none">
         <header class="vis_login_head">
            <? if(isset($operation['message']) && $operation['message']!="") { ?> <script> $("#vis_submit_msg_div").show(); $("#vis_submit_msg_div").html('<? echo $operation['message']; ?>');setTimeout(function(){$("#vis_submit_msg_div").hide();},10000);</script> <? } else if(isset($operation['error_message']) && $operation['error_message']!=""){ ?><script> $("#vis_submit_err_div").show(); $("#vis_submit_err_div").html('<? echo $operation['error_message']; ?>');setTimeout(function(){$("#vis_submit_err_div").hide();},10000); </script><? } ?>
         </header>
         <?php if(!empty($forumTopic) &&  ($forumTopic['is_spam']==0 || ($forumTopic['is_spam']==1 && $forumTopic['user_id']==VIS_CLIENT_ID && $forumTopic['is_client']==1))){?>
         <div class="panel-body">
			 <div id="follower">
			<? if(IS_LOGIN) {
			   if($topic_followers==-1) { ?>
			<a id="vis_follower" class="btn btn-link btn-sm link pull-right  vis_link_button"  href="javascript:void(0);" onclick=" add_topic_follow(<? echo $forumTopic['topic_id']; ?>,this.id);"><?=$vis_language['TXTFOLLOW'];?></a><? }
			   else if($topic_followers!=-1) {?>
			<a id="vis_remove_follower" class="btn btn-link btn-sm link pull-right vis_link_button" href="javascript:void(0);" onclick=" delete_followers(<? echo $forumTopic['topic_id']; ?>,this.id);"><?=$vis_language['TXTUNFOLLOW'];?></a>
			<? }
			   } ?></div>
            <span class="pull-left post-vote thumb-sm" style="text-align: center;">	
            <? if($topic_likes==-1) {?>
            <a id="topic_up" rel="nofollow"  href="javascript:void(0);" onclick=" topic_like(0,'');" class="vote-up" title="Like"> <i class="vh vh-angle-up"></i></a>
            <? } 
               else {?><span id="topic_up" class="vote-up"><i class="vh vh-angle-up"></i></span> 
           <? } ?> <div id="like_cnt">
              <? if($forumTopic['likeCount'] > 0){
               ?>
            <a href="javascript:void(0);" data-toggle="ajaxModal" data-modal-arguments="vis_module=forums&vis_operation=forum_likes&parent_type=0&vis_topic_id=<? echo $forumTopic['topic_id']; ?>&cache=true"> <span id="topic_like" class='block m-xxs font-bold'><?=$forumTopic['likeCount'];?></span></a>	
            <? }
               else echo "<span  id='topic_like' class='block m-xxs font-bold'>".$forumTopic['likeCount']."</span>";?></div><?
               if($topic_likes!=-1) {?>
            <a id="topic_down" rel="nofollow" href="javascript:void(0);" onclick=" topic_unlike(0,'');" class="vote-down" title="Unlike"><i class="vh vh-angle-down"></i></a>	
            <? } 
               else {?><span id="topic_down" class="vote-down"><i class="vh vh-angle-down"></i></span> 
            <? } ?>
            </span>		
            <div class="clear">
               <div class="form-group">
				 
                  <div class="col-sm-12 m-l-n m-t-n-xs">
                     <div style="text-align: justify;" class="col-sm-10">
                        <span class="post-title h4 l-h-1x"><? echo $forumTopic['title']; ?></span>
                     </div>
                  </div>
                  <div class="col-sm-12 m-l-n">
                     <div class="col-sm-1 m-t-sm">
                     <a  >
                     <? if($forumTopic['image_path']=='' || $forumTopic['image_path']=='default.jpg'){?>
<div class="l-avatar">
<? if($forumTopic['first_name']!=''){
	$firstname=preg_split('//u', $forumTopic['first_name'], -1, PREG_SPLIT_NO_EMPTY);
$lastname=preg_split('//u', $forumTopic['last_name'], -1, PREG_SPLIT_NO_EMPTY);
	?>
    <div class="thumb"><? echo ucfirst($firstname[0]).ucfirst($lastname[0]);?></div>
    <? }else{ ?>
    <img class="img-circle" src="<?= VIS_PATH_PROFILE.'default.jpg';?>">
    <? }?>

</div>
<? }else{ ?>
<div class="l-avatar">
<img src="<? echo VIS_PATH_PROFILE; echo $forumTopic['image_path']; ?>" class="img-circle">
</div>
<? }?>
</a>
                        <!--<a class="thumb m-t-sm" >
                        <img  class="img-circle " src="<? //echo VIS_PATH_PROFILE; echo ($forumTopic['image_path']=='')?'default.jpg':$forumTopic['image_path']; ?>" alt=""></a>-->
                     </div>
                     <div class="col-sm-11 m-t">
                        <div class="m-l-n fsize12"><? echo $forumTopic['first_name'].' '.$forumTopic['last_name']; ?></div>
                        <div class="m-l-n fsize12"><? echo format_datetime($forumTopic['creation_date']); ?></div>
                     </div>
                  </div>
               </div>
               <div class="line line-dashed b-b line-lg pull-in wrapper-sm"></div>
               <? echo '<div class="m-l">'.$forumTopic['description'].'</div>';
                  if($attachment!=-1) {
                  for($i=0;$i<count($attachment);$i++) {
                  echo '<div class="btn-group wrapper"><a href="?vis_module=export&vis_operation=get_attachment&vis_attachment='.$attachment[$i]['attachment_id'].'"><label class="btn btn-xs alert-success">'.addslashes($attachment[$i]['file_name']).' ('.format_size($attachment[$i]['file_size']).')</label></a></div>';
                  }
                  echo '</span>';
                  } ?>
               </div><!-- /.clear -->
                  <? if($forumTopic['is_spam']!=1){ include(VIS_PATH_TEMPLATE . 'topic_comment_list.php');}?>
            <div class="clear">
               <form class="form-horizontal" id="vis_topic_comment" name="vis_topic_comment" method="post">
                  <?if(!IS_LOGIN){?>
                  Please <a class="link" onclick="check_login();" href="javascript:void(0);"><? echo strtolower($vis_language['TXTLOGIN']);?></a>  <? echo strtolower($vis_language['TXTTO'].' '.$vis_language['TXTLEAVECOMMENT']);?>
                  <? }else { if($forumTopic['is_lock']!=1 && $forumTopic['is_spam']!=1) {?>
                  <div class="form-group">
                     <label for="Comment" class="col-sm-2 control-label"><? echo $vis_language['TXTREPLY']; ?></label>
                     <div class="col-sm-8"><textarea class="form-control input-sm" rows="6" id ="vis_forum_comment" name="vis_forum_comment"><?php if(isset($signature) && $signature!='') echo $signature; ?></textarea></div>
                  </div>
                  <div class="row m-b-sm">
                     <div class="col-sm-8 p-l-none">
                        <div id="progress" class="progress" style="display:none; height:14px;">
                           <div class="progress-bar progress-bar-success"></div>
                        </div>
                     </div>
                     <div class="col-sm-2 control-label">
                        <span class="btn btn-link link btn_upload_file vis_font_size_none text-primary" id="vis_attach_file"><?= $vis_language['TXTATTACHFILE']; ?> <input class="form-control" type="file" id="fileupload1"></span>
                        <div style="display:none;" id="vis_attachments"></div>
                     </div>
                  </div>
                  <div class="row m-b-sm">
                     <label for="Message" class="col-sm-2 control-label"></label>
                     <div id="vis_new_attachments1" class="col-sm-8 p-l-none"></div>
                  </div>
                  <div class="line line-dashed b-b line-lg pull-in"></div>
                  <div class="col-lg-offset-2 col-lg-8">					
                     <button type="button" class="btn btn-primary" onclick="submit_form();"><? echo $vis_language['TXTSUBMIT']?></button>                             
                  </div>
                  <? } } ?>
               </form>
            </div>
         </div>
         <!-- /.panel-body -->
      <? } else {  echo '<section class="wrapper fullFrame">
            <div class="fullMiddle m-xl text-center h4">'.$vis_language['TXTWIDNORECORDFOUND'].'</div>
                         </section>'; }?></section>
      <!-- /.panel -->
   </div>
   <!-- /.col-md-12 -->
</div>
<!-- /.row -->
</div>  <!-- / .container -->
<script>
   var curr_stamp=0;
   
   $('#refresh').click(function() { 
       change_captcha();
    });
   
    function delete_comment(topic_id,comment_id,cnt){
   	   result = confirm('<?php echo $vis_language['MSGSURE']; ?>');if(result== false) return false;
   	   if(result){
   	 	$.ajax
   			({
   			   url: 'index.php',
   			   data: {'vis_module':"forums", 'vis_operation':"delete_topic_comment" ,'vis_topic_id':topic_id,'vis_comment_id':comment_id},
   			   type: "POST",
   			   dataType: "json",
   			   success: function(data)
   			   {	
   				      	if(data.vis_submitted=='true')
   					   {
						   if(cnt>1){
							   $("#vis_submit_msg_div").show(); $("#vis_submit_msg_div").html("<?= $vis_language['MSGSUCCOPRT'];?>");
							   $("#message_span_"+comment_id).hide();
							   $("#comment_"+comment_id).html('');
							   var count=$("#comment_count").text();
							   $("#comment_count").html(count-1);
							}
							else {
								 setTimeout(function(){window.location = "index.php?/forums/topic-details/<? echo $forumTopic['title']; ?>/<? echo $forumTopic['topic_id'];?>"}, 500);
							}
   					   } else
   					   {
   						   $(window).scrollTop(0);
   						   $("#vis_submit_err_div").show(); $("#vis_submit_err_div").html(data.vis_msg);
   						   setTimeout(function(){$("#vis_submit_err_div").hide();},10000);
   
   					   }	
   				   }
   			   });
   	   }
    }
    <? if(!defined('VIS_HEAD_MENU_HTML_EDITOR') || VIS_HEAD_MENU_HTML_EDITOR==1) { ?>    
	$(function(){
		$('#vis_forum_comment').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',		
			focus: true,
		    plugins: ['source'],
			deniedTags: ['html', 'head', 'link', 'body', 'meta', 'script','applet']
		});
	});
<? } ?>
   
   	function vis_remove_attachment(attach_id){
   	 $.ajax({
           url: 'index.php',
           data: {'vis_module':"ticket", 'vis_operation':"remove_attachment", 'vis_attachment_id':attach_id },
           type: "POST",
           success: function(data) {  }
       });
   
   }
   
   	$(function () {
   
   	var url = 'index.php?vis_module=ticket&vis_operation=upload_file&vis_parent_type=10';
   	$('#fileupload1').fileupload({
   		url: url,
   		done: function (e, data) {
   		$("#vis_new_attachments1").append(data.result);
   		}
   	});
   
   }); 
   
    function change_captcha(){
   
       document.getElementById('captcha').src="<?= VIS_PATH_TEMPLATE ?>get_captcha.php?clr=<? echo str_replace("#",'',VIS_THEME_COLOR); ?>&rnd=" + Math.random();
   
    }
     function add_topic_follow(topic_id,id)
      {
   			$.ajax
   			({
   			   url: 'index.php',
   			   data: {'vis_module':"forums", 'vis_operation':"add_followers" ,'topic_id':topic_id},
   			   type: "POST",
   			   dataType: "json",
   			   success: function(data)
   			   {	
   					if(data.vis_submitted=='true')
   					{
   					   $(window).scrollTop(0);
   					   $("#vis_submit_msg_div").show(); $("#vis_submit_msg_div").html("<?= $vis_language['MSGSUCCOPRT'];?>");
   					   $("#"+id).hide();
   					   $("#follower").html('<a id="vis_remove_follower" class="btn btn-link btn-sm link pull-right vis_link_button" href="javascript:void(0);" onclick=" delete_followers(<? echo $forumTopic['topic_id']; ?>,this.id);"><?=$vis_language['TXTUNFOLLOW'];?></a>'); 
   					   setTimeout(function(){$("#vis_submit_msg_div").hide();},1000);
   				    } 
   					else
   				    {
   					   $(window).scrollTop(0);
   					   $("#vis_submit_err_div").show(); $("#vis_submit_err_div").html(data.vis_msg);
   					   setTimeout(function(){$("#vis_submit_err_div").hide();},10000);
   				    }
   				 }
   			   });
   	   }
   	function delete_followers(topic_id,id)
      {		
   			$.ajax
   			({
   			   url: 'index.php',
   			   data: {'vis_module':"forums", 'vis_operation':"delete_followers" ,'vis_topic_id':topic_id},
   			   type: "POST",
   			   dataType: "json",
   			   success: function(data)
   			   {	
   					if(data.vis_submitted=='true')
   					{
   					   $(window).scrollTop(0);
   					   $("#vis_submit_msg_div").show(); $("#vis_submit_msg_div").html("<?= $vis_language['MSGSUCCOPRT'];?>");
   					   $("#"+id).hide();
   					   $("#follower").html('<a id="vis_follower" class="btn btn-link btn-sm link pull-right  vis_link_button"  href="javascript:void(0);" onclick=" add_topic_follow(<? echo $forumTopic['topic_id']; ?>,this.id);"><?=$vis_language['TXTFOLLOW'];?></a>'); 
   					   setTimeout(function(){$("#vis_submit_msg_div").hide();},1000);
   				    } 
   					else
   				    {
   					   $(window).scrollTop(0);
   					   $("#vis_submit_err_div").show(); $("#vis_submit_err_div").html(data.vis_msg);
   					   setTimeout(function(){$("#vis_submit_err_div").hide();},10000);
   				    }	
   			 }
   			   });
   	   }
   	   
     function topic_like(parent_type,comment_id)
      {
   			if(parent_type==0 && comment_id=='')
   			   parent_id = <? echo $forumTopic['topic_id'];?>;
   		   else 
   			   parent_id = comment_id; 
   			$.ajax
   			({
   			   url: 'index.php',
   			   data: {'vis_module':"forums", 'vis_operation':"forum_topic_like" ,'parent_id':parent_id,'parent_type':parent_type,'comment_id':comment_id},
   			   type: "POST",
   			   dataType: "json",
   			   success: function(data)
   			   {
   				      if(data.vis_submitted=='true')
   					   { 
						   if(parent_type==1){
						   $("#comment_like_count_"+comment_id).html("<a  href='javascript:void(0);' data-toggle='ajaxModal' data-modal-arguments='vis_module=forums&vis_operation=forum_likes&parent_type=1&cache=true&vis_topic_id="+comment_id+"'> <span class='block m-xxs font-bold'>"+data.like_count+"</span></a>");
						   $('#up_'+parent_id).removeAttr("style");
						   $('#up_'+parent_id).removeAttr("href");
						   $('#up_'+parent_id).removeAttr("onclick");
						   $('#up_'+parent_id).removeAttr("title");
						   $('#down_'+parent_id).attr("onclick","topic_unlike(1,"+parent_id+");");
						   $('#down_'+parent_id).attr("style","cursor: pointer;");
						   $('#down_'+parent_id).attr("title","Unlike");
						   } else { 
						   $('#like_cnt').html('<a href="javascript:void(0);" data-toggle="ajaxModal" data-modal-arguments="vis_module=forums&vis_operation=forum_likes&parent_type=0&vis_topic_id=<? echo $forumTopic['topic_id']; ?>&cache=true"> <span id="topic_like" class="block m-xxs font-bold">'+data.like_count+'</span></a>'); 
						   $('#topic_up').removeAttr("style");
						   $('#topic_up').removeAttr("href");
						   $('#topic_up').removeAttr("onclick");
						   $('#topic_up').removeAttr("title");
						   $('#topic_down').attr("onclick","topic_unlike(0,'');");
						   $('#topic_down').attr("style","cursor: pointer;");
						   $('#topic_down').attr("title","Unlike");
						   }		
						 						   
   					   } 
   					   else{					   
   						   check_login();
   					   }
   				   }
   			   });
   	   }
   	   
   	function topic_unlike(parent_type,comment_id)
      {
   		   if(parent_type==0 && comment_id=='')
   			   parent_id = <? echo $forumTopic['topic_id'];?>;
   		   else 
   			   parent_id = comment_id; 
   			$.ajax
   		   ({
   			   url: 'index.php',
   			   data: {'vis_module':"forums", 'vis_operation':"forum_topic_unlike" ,'parent_id':parent_id,'parent_type':parent_type,'comment_id':comment_id},
   			   type: "POST",
   			   dataType: "json",
   			   success: function(data)
   			   {		   
   					if(data.vis_submitted=='true')
   					   {
						   if(parent_type==1){
						   if(data.like_count>0)
							$("#comment_like_count_"+comment_id).html("<a  href='javascript:void(0);' data-toggle='ajaxModal' data-modal-arguments='vis_module=forums&vis_operation=forum_likes&parent_type=1&cache=true&vis_topic_id="+comment_id+"'> <span class='block m-xxs font-bold'>"+data.like_count+"</span></a>");
						   else
						   $('#comment_like_count_'+comment_id).html('<span class="block m-xxs font-bold">'+data.like_count+'</span>');
						   $('#up_'+parent_id).attr("onclick","topic_like(1,"+parent_id+");");
						   $('#up_'+parent_id).attr("style","cursor: pointer;");
						   $('#up_'+parent_id).attr("title","Like");
						   $('#down_'+parent_id).removeAttr("style");
						   $('#down_'+parent_id).removeAttr("onclick");
						   $('#down_'+parent_id).removeAttr("href");
						   $('#down_'+parent_id).removeAttr("title");
						   } else {
						   if(data.like_count>0)
						   $('#like_cnt').html('<a href="javascript:void(0);" data-toggle="ajaxModal" data-modal-arguments="vis_module=forums&vis_operation=forum_likes&parent_type=0&vis_topic_id=<? echo $forumTopic['topic_id']; ?>&cache=true"> <span id="topic_like" class="block m-xxs font-bold">'+data.like_count+'</span></a>'); 
						   else
						   $('#like_cnt').html('<span id="topic_like" class="block m-xxs font-bold">'+data.like_count+'</span>'); 
						   $('#topic_up').attr("onclick","topic_like(0,'');");
						   $('#topic_up').attr("style","cursor: pointer;");
						   $('#topic_up').attr("title","Like");
						   $('#topic_down').removeAttr("style");
						   $('#topic_down').removeAttr("onclick");
						   $('#topic_down').removeAttr("href");
						   $('#topic_down').removeAttr("title");
						   }		
   					   } 
   					   else{					   
   						   check_login();
   					   }
   			   }
   		   });
   	 }
    
    function submit_form(){
   
        if(curr_stamp==0 || (curr_stamp < (Date.now()-10000))){
   
           curr_stamp = Date.now();
   
           $.ajax({
   
           url: 'index.php',
   
           data: {'vis_module':"forums", 'vis_operation':"set_comment" ,'vis_domain_id':<? echo VIS_DOMAIN;?>, 'vis_attachments':$("#vis_attachments").html(),'vis_forum_comment':$("#vis_forum_comment").val() ,'vis_topic_id':<? echo $forumTopic['topic_id']; ?> , 'vis_fullname':"<? echo $client[0]['first_name'].' '.$client[0]['last_name']; ?>" ,'vis_email':"<? echo $client[0]['email']; ?>",'vis_image_path':'<? echo $client[0]['image_path']; ?>'},
   
           type: "POST",
   		 
   		 dataType: "json",
   
           success: function(data) {
   		 if(data.vis_submitted=='true')
                  {
                      $("#vis_submit_msg_div").show(); $("#vis_submit_msg_div").html("<?= $vis_language['MSGSUCCOPRT'];?>");
                      $("#comment_div").html(data.comments);
                      $(window).scrollTop(0);
                      $("#vis_new_attachments1").html('');
                      $('.redactor-editor').html('<?php if(isset($signature) && $signature!='') echo $signature; ?>');
                      $("#vis_forum_comment").val('<?php if(isset($signature) && $signature!='') echo $signature; ?>');
   					  $("#follower").html('<a id="vis_remove_follower" class="btn btn-link btn-sm link pull-right vis_link_button" href="javascript:void(0);" onclick=" delete_followers(<? echo $forumTopic['topic_id']; ?>,this.id);"><?=$vis_language['TXTUNFOLLOW'];?></a>'); 
                      setTimeout(function(){$("#vis_submit_msg_div").hide();},1000);
                  } else
                  {
                      $(window).scrollTop(0);
                      $("#vis_submit_err_div").show(); $("#vis_submit_err_div").html(data.vis_msg);
                      setTimeout(function(){$("#vis_submit_err_div").hide();},10000);
   
                  }	
   		  }
   
       });
   
       }
   
    }
   function check_login(){
   	 $.ajax({
           url: 'index.php',
           data: {'vis_module':"home", 'vis_operation':"login", 'vis_forum_login':1, 'vis_action':"#/forums/topic-details/<? echo $forumTopic['title']; ?>/<? echo $forumTopic['topic_id'];?>"},
           type: "POST",
           success: function(data) { 
			    $(".fourms").html(data);
			   }
       });
   
   }
    
       
</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="<?= VIS_PATH_SCRIPT; ?>file-input/bootstrap-filestyle.min.js"></script>
