<? global $vis_language; ?>
<style>.list-group-item{padding:6px 15px;} .list-group-item .h5 a{ font-size:13px;}  #vis_article_rating1 .vh-2x{font-size:13px;} .rotaed180{-webkit-transform: rotate(180deg);
  -moz-transform: rotate(180deg);
  -ms-transform: rotate(180deg);
  -o-transform: rotate(180deg);
  transform: rotate(180deg);} .likeartd{ font-size:81%; color:#bbb;} </style>
<section class="container m-t-md">
   <div class="row">
      <div class="col-md-12">
         <section class="container">
            <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>
            <div class="col-md-8 col-sm-8">
            <div class="panel-body">
				 
               <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-12">
                        <span class="post-title h4 l-h-1x"><? echo $article['article_title']; ?></span>
                     </div>
                  </div>
                  <div class="col-sm-12 m-l-n">
                     <div class="col-sm-2 ">
                     <a class="thumb" >
                     <? if($authorDetails==null || $authorDetails=='default.jpg'){
																						$authorname=(trim($article['author_name'])!='')?$article['author_name']:$article['author'];
																						$namearr=explode(' ',$authorname);
																					$fullname='';
																					if($article['first_name']!=''){ 
																					$lastname=preg_split('//u', $article['last_name'], -1, PREG_SPLIT_NO_EMPTY); 
																					$firstname=preg_split('//u', $article['first_name'], -1, PREG_SPLIT_NO_EMPTY);
																					$fullname=ucfirst($firstname[0]).ucfirst($lastname[0]);
																					}else{
																						$firstname=preg_split('//u', $namearr[0], -1, PREG_SPLIT_NO_EMPTY);
																						$fullname=ucfirst($firstname[0]);
																					}
																						?>
<div class="l-avatar  m-t-sm">
<div class=""><? echo $fullname;?></div>
</div>
<? }else{ ?>
<div class="l-avatar  m-t-sm">
<img src="<? echo VIS_PATH_PROFILE.$authorDetails; ?>" class="img-circle">
</div>
<? }?>
</a>
                       <!-- <a class="thumb m-t-sm" >
                        <img  class="img-circle " src="<? //echo VIS_PATH_PROFILE.(($authorDetails==null)?'default.jpg':$authorDetails); ?>" alt=""></a>-->
                     </div>
                     <div class="col-sm-10 m-t-sm" style="padding-top: 4px;">
                        <div class="m-l-n-md "><?  echo (trim($article['author_name'])!='')?$article['author_name']:$article['author'];  ?></div>
                        <div class="m-l-n-md "><? echo format_datetime($article['entry_date']); ?></div>
                        
                        <!--<div class="m-l-n-md"><?if((($setting_details_for_rating!=-1 && $setting_details_for_rating[0]['content']!=0)) || ($setting_details_for_rating==-1)) { if($article['can_rate']==1) { ?>
                  <span class="vh-yellow m-b pull-left" id="vis_article_rating1" > <?
                     for($cn=0;$cn<$article['rating'];$cn++){ ?>
                  <? if(!isset($_COOKIE['article_id_'.$article['article_id']]) && $article['can_rate']==1 && !isset($operation['vis_rating'])) { ?><i class="vh vh-1x vh-star"></i><? } else { ?><i class="vh vh-1x vh-star"></i><? }
                     }
                     for($cn=$article['rating'];$cn<5;$cn++){?>
                  <? if(!isset($_COOKIE['article_id_'.$article['article_id']]) && $article['can_rate']==1 && !isset($operation['vis_rating'])) { ?><i class="vh vh-1x vh-star-empty"></i><? } else { ?><i class="vh vh-1x vh-star-empty"></i><? }
                     } ?> </span> <? } }?></div>-->
                     </div>
                     
                  </div>
               </div> 
               </div>
                
               
                     
                     <div class="line line-dashed b-b pull-in"></div>
                <div class="clear">
               <? echo '<div class="m-l">'.$article['content'].'</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>';
                  } 
				  
				  //if($check_article_rating_setting[0]['can_rate']!=0)
				  if((($setting_details_for_rating!=-1 && $setting_details_for_rating[0]['content']!=0)) || ($setting_details_for_rating==-1))
				  {
				  	?>
                  	<div class="line line-dashed b-b pull-in"></div>
                  	<? 
					//if((($setting_details_for_rating!=-1 && $setting_details_for_rating[0]['content']!=0)) || ($setting_details_for_rating==-1)) {
				  	?>
                    <div class="clear m-t m-l">
                        <div class="pull-left m-r">
                            <div class="h5"><? echo $vis_language['TXTWASTHISARTICLEHELPFUL'];?></div>
                            <div class="likeartd" id="foundcount"><? echo $article['art_likes'];?> <? echo $vis_language['TXTOUTOF'];?> <? echo $article['like_count'];?> <? echo $vis_language['TXTFOUNDTHISHELPFUL'];?></div>
                        </div>
                    
                        <div class="pull-left" id="setlikesunlike">
							<? if(isset($_COOKIE['article_id_'.$article['article_id']]) ||( $article['can_rate']==0 && !isset($operation['vis_ratingflag']))){ ?>
                            <a class="btn btn-empty bg-white b-a" style="cursor:text;"  ><i class="vh vh-thumbs-up vh-lg bg-white"></i></a>&nbsp;<a class="btn btn-empty bg-white b-a " style="cursor:text;" ><i class="vh vh-thumbs-up vh-lg vh-rotate-180 bg-white"></i></a>
                            <? }else{?>
                            <a class="btn btn-empty bg-white b-a" href="javascript:void(0);" onclick="set_rating(1);" ><i class="vh vh-thumbs-up vh-lg bg-white"></i></a>&nbsp;<a class="btn btn-empty bg-white b-a "  href="javascript:void(0);" onclick="set_rating(0);" ><i class="vh vh-thumbs-up vh-lg vh-rotate-180 bg-white"></i></a>
                            <? }?>
                        
                        </div>
                    </div>
                  	<? 
				  	//}
				  }
				  ?>
                     </div>
                     <?
                     if($comment!=-1) {
                     echo '<section class="chat-list m-t"><div class="line line-dashed b-b line-lg pull-in wrapper-sm"></div>';					
                     for($i=0;$i<count($comment);$i++) { ?>
                  <article class="chat-item chat-item-comment left">
                     <?if($comment[$i]['poster_id']==VIS_CLIENT_ID && $comment[$i]['poster_type'] == 1){?>
                    <? } ?>
                    <? if($comment[$i]['poster_image']=='' || $comment[$i]['poster_image']=='default.jpg'){
																					$authorname=(trim($comment[$i]['postername'])!='')?$comment[$i]['postername']:$comment[$i]['poster_name'];
											$namearr=explode(' ',$authorname);
											$fullname='';
											if($comment[$i]['first_name']!=''){ 
											$lastname=preg_split('//u', $comment[$i]['last_name'], -1, PREG_SPLIT_NO_EMPTY); 
											$firstname=preg_split('//u', $comment[$i]['first_name'], -1, PREG_SPLIT_NO_EMPTY);
											$fullname=ucfirst($firstname[0]).ucfirst($lastname[0]);
											}else{
												$firstname=preg_split('//u', $namearr[0], -1, PREG_SPLIT_NO_EMPTY);
												$fullname=ucfirst($firstname[0]);
											}
																					?>
<div class="l-avatar pull-left m-t-lg">
<div class="sm"><? echo $fullname;?></div>
</div>
<? }else{ ?>
<div class="l-avatar pull-left m-t-lg">
<img src="<? echo VIS_PATH_PROFILE.$comment[$i]['poster_image']; ?>" class="sm">
</div>
<? }?>
                    <!-- <span class="pull-left m-t-lg thumb-sm avatar"><img src="<? //echo VIS_PATH_PROFILE.(($comment[$i]['poster_image']=='')?'default.jpg':$comment[$i]['poster_image']); ?>" width="32" /></span>-->
                     <span class="m-l-sm"><? echo (trim($comment[$i]['postername'])!='')?$comment[$i]['postername']:$comment[$i]['poster_name']; ?></span>
                     <small class="text-muted m-l-sm"><? echo format_datetime($comment[$i]['entry_date']); ?></small>
                     <section class="chat-body m-t-xs">
                        <div class="panel bg-light dk text-sm m-b-none">
                           <div class="panel-body">
                              <span class="arrow left vis_blue_border"></span>
                              <p class="m-b-none"><? echo $comment[$i]['content']; ?></p>
                           </div>
                        </div>
                     </section>
                  </article>
                  <? }  echo '</section>';
                     }?>
               </div>
               <!-- /.clear -->
               <div class="clear">
                  <!--<?php if(!isset($_COOKIE['article_id_'.$article['article_id']]) && $article['can_rate']==1 && !isset($operation['vis_rating'])) { ?>
                     <form class="form-horizontal" role="form-rating" name="vis_article_rating" method="post">
                     <div class="line m-t-lg b-2x b-b line-lg pull-in"></div>
                     <div class="b-b wrapper-sm"><h4><? echo $vis_language['TXTRATING']; ?></h4></div>
                       <div class="form-group m-t">
                         <label class="col-sm-2 control-label"><? echo $vis_language['TXTRATING']; ?></label>
                         <div class="col-sm-8">
                           <label class="radio-inline i-checks">
                             <input type="radio" name="vis_rating" value="1" id="rating1"><i></i> Poor
                           </label>
                           <label class="radio-inline i-checks">
                             <input type="radio" name="vis_rating" value="2" id="rating2"><i></i> Fair
                           </label>
                           <label class="radio-inline i-checks">
                             <input type="radio" name="vis_rating" value="3" id="rating3" checked="checked"><i></i> Good
                           </label>
                           <label class="radio-inline i-checks">
                             <input type="radio" name="vis_rating" value="4" id="rating4"><i></i> Very Good
                           </label>
                           <label class="radio-inline i-checks">
                             <input type="radio" name="vis_rating" value="5" id="rating5"><i></i> Excellent
                           </label>
                           <button class="btn btn-primary m-l" type="submit"><? echo $vis_language['TXTSUBMIT']?></button>
                           <input name="vis_article_id" type="hidden" value="<? echo $article['article_id']; ?>" /><input type="hidden" name="vis_module" value="selfhelp" />
                           <input type="hidden" name="vis_operation" value="set_rating" /><input type="hidden" name="vis_client_id" value="0" />
                         </div>
                       </div>          
                     </form><? } ?> -->
                  <? if(($setting_details_for_comment==-1 || $setting_details_for_comment[0]['content']==1)){ ?>
                  <? if($article['can_comment']==1) { ?>
                  <form class="form-horizontal" id="vis_article_comment" name="vis_article_comment" method="post">
                     <div class="line line-dashed b-b line-lg pull-in wrapper-sm"></div>
                     <h5><? echo $vis_language['TXTLEAVECOMMENT']; ?></h5>
                     
                     
                     <div class="wrapper" >
                        <?if(!IS_LOGIN){?>
                        <div class="form-group m-t">
                           <label for="FirstName" class="col-sm-2 control-label"><? echo $vis_language['TXTFULLNAME']; ?></label>
                           <div class="col-sm-8">
                              <input type="text" class="form-control input-sm" data-type="text" name="vis_fullname" id="vis_fullname" value="<? if(isset($client[0]['first_name'])) echo $client[0]['first_name']; ?>">
                           </div>
                        </div>
                        <div class="form-group">
                           <label for="PersonalEmail" class="col-sm-2 control-label"><? echo $vis_language['TXTEMAIL']; ?></label>
                           <div class="col-sm-8">
                              <input type="email" class="form-control input-sm" name="vis_email" id="vis_email" value="<? if(isset($client[0]['email'])) echo $client[0]['email']; ?>">
                           </div>
                        </div>
                        <input type="hidden" name="vis_honeypot" id="vis_honeypot" />
                        <? } ?>
                        <div class="form-group">
                           <label for="Comment" class="col-sm-2 control-label"><? if($article['content_type']==1) echo $vis_language['TXTSUGGESTION'];
                              elseif($article['content_type']==2) echo $vis_language['TXTANSWER'];
                              else echo $vis_language['TXTCOMMENT']; ?></label>
                           <div class="col-sm-8"><textarea class="form-control input-sm" rows="6" name="vis_selfhelp_comment"></textarea></div>
                        </div>
                        <? if(($setting_details!=-1 && $setting_details[0]['content']!=0) && !IS_LOGIN){ ?>
                        <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 wrapper-sm"></div>
                        <div class="col-lg-offset-2 col-lg-8">
                           <?if(IS_LOGIN){?> <input name="vis_fullname" type="hidden" value="<? echo $client[0]['first_name']; ?>" /> <input name="vis_email" type="hidden" value="<? echo $client[0]['email']; ?>" /><? } ?>
                           <button type="button" class="btn btn-primary" onclick="submit_form();"><? echo $vis_language['TXTSUBMIT']?></button>
                           <input name="vis_article_id" type="hidden" value="<? echo $article['article_id']; ?>" />
                            <input name="vis_article_title" type="hidden" value="<? echo $article['article_url']; ?>" /><input type="hidden" name="vis_module" value="selfhelp" /><input type="hidden" name="vis_operation" value="set_comment" /><input type="hidden" name="vis_client_id" value="<? echo VIS_CLIENT_ID; ?>" /><input type="hidden" name="vis_domain_id" value="<? echo VIS_DOMAIN; ?>" /><input name="vis_static_url" type="hidden" value="<? echo $operation['vis_static_url']; ?>" />
                        </div>
                        </div>
                  </form>
                  <?  } }?> 
                  
               </div>
               <!-- /.wrapper-lg -->
            </div>
            
            
            <div class="col-md-4 col-sm-4">
            <div class="b-l">
            <div class="panel-heading">
 <h4 class="panel-title1"><span class="vh vh-self-help vh-warning"></span>&nbsp;<?php echo (!empty($parent_category_details))?$parent_category_details['selfhelp_title']:'solution';?></h4>
 </div>
 <div class="panel-body" style="padding-top:0px;">
                <ul class="list-group no-borders m-b-n">
				<? 	for($i=0;$i<count($right_selfhelp);$i++) {
						if(trim($right_selfhelp[$i]['article_url'])!=''):
							$artUrl = trim(str_replace(' ','-',preg_replace('/\s+/', ' ', strtolower(preg_replace('/[^A-Za-z0-9\-]/', ' ', $right_selfhelp[$i]['article_url'])))),"-");
						else:
							$artUrl = trim(str_replace(' ','-',preg_replace('/\s+/', ' ', strtolower(preg_replace('/[^A-Za-z0-9\-]/', ' ', $right_selfhelp[$i]['article_title'])))),"-");
						endif;
						//
						$database=new class_database();
						include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
						$object=new class_selfhelp($database);
       
						$filter=' article_url='.'"'.$artUrl.'" and language='.VIS_LANGUAGE;
						list($art_info, $art)=$object->get_article($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);  
						if(count($art)>=2):
						
							$lnk='?/selfhelp/view-article/'.$artUrl.'/'.$right_selfhelp[$i]['article_id'];	
						else:
						
							$lnk='?/selfhelp/view-article/'.$artUrl;
						endif;
						//
				?>
                  <li class="list-group-item">
                    <span class="pull-left">
                        <i class="vh vh-lg vh-file-o m-r-sm"></i>
                    </span>
                    <div class="h5 clear l-h"><a href="<?= $lnk; ?>" class="link"><?= $right_selfhelp[$i]['article_title']; ?></a></div>
                  </li>
				<? } ?> 
                </ul>
          </div>
         
         </div>
            </div>
            <!-- /.panel-body -->
         </section>
         <!-- /.panel -->
      </div>
      <!-- /.col-md-12 -->
   </div>
   <!-- /.row -->
   
  

</section>
<script>
   var curr_stamp=0;
   $('#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();
    }
    function submit_form(){
        if(curr_stamp==0 || (curr_stamp < (Date.now()-10000))){
           curr_stamp = Date.now();
           $("#vis_article_comment").submit();
       }
    }
    function set_rating(cnt)
    {		
		$.ajax
		({
		   url: 'index.php',
		   data: {'vis_module':"selfhelp", 'vis_operation':"set_articlelike" ,'vis_article_id':"<? echo $article['article_id'];?>",'vis_ratingflag':cnt},
		   type: "POST",
		   dataType: "json",
		   success: function(data)
		   {
			   $('#setlikesunlike').html(data.list);
						$('#foundcount').html(data.liketext);
			   if(data.vis_success=='true')
   					{
   					   $("#vis_submit_msg_div").show(); $("#vis_submit_msg_div").html(data.vis_message);
   					   setTimeout(function(){$("#vis_submit_msg_div").hide();},1000);
   				    } 
   					else
   				    {
   					   $("#vis_submit_err_div").show(); $("#vis_submit_err_div").html(data.vis_message);
   					   setTimeout(function(){$("#vis_submit_err_div").hide();},10000);
   				    }
		   }
		   });
   	 }
   	   
 function showcbox()
	{
		$('#commentbox').show();
		//$('#clkh').hide();
	}
	//check cookie
var excookie=ReadSetCookie('ARTICLEIDS');
if(excookie!=null)
{ 
var excookie1=excookie.split(',');

var chkflg=0;
for(var i=0; i<excookie1.length; i++){
				if(excookie1[i]==<? echo $article['article_id']; ?>){
					chkflg=1;
				}
		}
		if(chkflg==0){
					updatecount(<? echo $article['article_id']; ?>);
					excookie=excookie+','+<? echo $article['article_id']; ?>;
					CreateNewCookie('ARTICLEIDS',excookie,8);
		}
						
}else{
updatecount(<? echo $article['article_id']; ?>);
CreateNewCookie('ARTICLEIDS',<? echo $article['article_id']; ?>,8);
}

function updatecount(articleid){
	var data='vis_article_id='+articleid;
		$.ajax
		({
		   url: 'index.php',
		   data: {'vis_module':"selfhelp", 'vis_operation':"set_viewcount" ,'vis_article_id':"<? echo $article['article_id'];?>"},
		   type: "POST",
		   success: function(data)
		   {
						//alert('done');
					}
		});
	
}
	
function CreateNewCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function ReadSetCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}      
</script>

