<? global $vis_language; ?>
<style>.list-group-item{padding:6px 15px;} .list-group-item .h5 a{ font-size:13px;} .h4 a.link, .h4 .blnk{ font-size:14px;} </style>
 <?  if(VIS_HEAD_MENU_SELFHELP!= 0) { ?>
<section class="container m-t-md" id="main_div">
     <!-- /.row -->
      <? if($parentid==0) {?>
    <div class="col-md-8 col-sm-8">
    <? }else{?>
    <div>
    <? }?>
 <? if($selfhelp!=-1) $a=count($selfhelp); for($i=0;$i<count($selfhelp);$i++) { ?>
	<?if($i%2==0 && $parentid==0){?><div class="row"><? } if( $parentid==0){?>
	<div class="col-md-6 col-sm-6"><? } ?>
    <div class="panel-heading b-b">
				
		
         <h4 class="panel-title1"><span class="vh vh-self-help vh-warning"></span>&nbsp;<?= $selfhelp[$i]['selfhelp_title']; ?></h4>
       <?php if( $parentid!=0){ ?>
	   <div class="btn-group">
		   <a class="btn btn-xs btn-rounded <?php echo ($operation['vis_sorted_by'] == 'popularity')?' btn-primary ':'btn-default'; ?>" onclick="article_sort('popularity');"><? echo $vis_language['TXTPOPULAR']; ?></a>  
	   </div>
		<div class="btn-group">
		   <a class="btn btn-xs btn-rounded <?php echo ($operation['vis_sorted_by'] == 'mostcommented')?' btn-primary ':'btn-default'; ?>" onclick="article_sort('mostcommented');"><? echo $vis_language['TXTMOSTCOMMENTED']; ?></a>  
	   </div><? } ?>
  </div>
  <div class="panel-body" id="main_div">
    <div class="row">
		<? for($j=0;$j<count($selfhelp[$i]['subcat']);$j++) {  ?>
        <div class="col-md-12 col-sm-12">
            <ul class="list-group no-borders m-b-none">
              <li class="list-group-item l-h-2x">
                <span class="pull-left m-r-sm">
                    <i class="vh vh-lg vh-folder-o active"></i>
                </span>
                <div class="h4 clear l-h-1x text-left">
				<? if($selfhelp[$i]['subcat'][$j]['article'][1]!=-1 || (count($selfhelp[$i]['subcat'][$j]['subcat'][0]['subcat'])>0 && $selfhelp[$i]['subcat'][$j]['subcat'][0]['subcat']!=-1)) { if($selfhelp[$i]['subcat'][$j]['toatlarticlecount']==0){ echo '<span class="blnk">'.$selfhelp[$i]['subcat'][$j]['selfhelp_title'].' (0)</span>'; } else{ ?><a href="<?= ((isset($url_rewrite) && $url_rewrite==1)?('/self-help/'.$selfhelp[$i]['subcat'][$j]['selfhelp_id'].'/'):('?/selfhelp/categories/'.trim(str_replace(' ','-',preg_replace('/\s+/', ' ', strtolower(preg_replace('/[^A-Za-z0-9\-]/', ' ', $selfhelp[$i]['subcat'][$j]['selfhelp_title'])))),"-").'/'.$selfhelp[$i]['subcat'][$j]['selfhelp_id'])); ?>" class="link active"><?= $selfhelp[$i]['subcat'][$j]['selfhelp_title']; ?> (<?= $selfhelp[$i]['subcat'][$j]['toatlarticlecount']; ?>)</a><? }} else { echo '<span class="blnk">'.$selfhelp[$i]['subcat'][$j]['selfhelp_title'].' (0)</span>'; } ?></div>
              </li>
            </ul>
        </div> <!-- /.col-md-12 .col-sm-12 -->
        <? } ?>
    </div> <!-- /.row -->
    <div class="row">		
        <div class="col-md-12 col-sm-12">
            <ul class="list-group no-borders m-b-n">
			<? 	if($selfhelp[$i]['article'][1]!=-1) for($j=0; $j<count($selfhelp[$i]['article'][1]); $j++) {
			if($selfhelp[$i]['article'][1][$j]['is_enabled']!=0) {
				if(trim($selfhelp[$i]['article'][1][$j]['article_url'])!=''):
					$artUrl = trim(str_replace(' ','-',preg_replace('/\s+/', ' ', strtolower(preg_replace('/[^A-Za-z0-9\-]/', ' ', $selfhelp[$i]['article'][1][$j]['article_url'])))),"-");
			else:
				$artUrl = trim(str_replace(' ','-',preg_replace('/\s+/', ' ', strtolower(preg_replace('/[^A-Za-z0-9\-]/', ' ', $selfhelp[$i]['article'][1][$j]['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=((isset($url_rewrite) && $url_rewrite==1)?('/self-help/article/'.$selfhelp[$i]['article'][1][$j]['article_id'].'/'.rawurlencode($selfhelp[$i]['article'][1][$j]['article_title'])):('?/selfhelp/view-article/'.$artUrl.'/'.$selfhelp[$i]['article'][1][$j]['article_id']));
							
						else:
						
							$lnk=((isset($url_rewrite) && $url_rewrite==1)?('/self-help/article/'.$selfhelp[$i]['article'][1][$j]['article_id'].'/'.rawurlencode($selfhelp[$i]['article'][1][$j]['article_title'])):('?/selfhelp/view-article/'.$artUrl));
						endif;
						//
			
			
			?>
			
			
            
				   <?php if( $parentid!=0){ ?>
					     <li class="list-group-item">
				   <div class="clear"> 
							<span class="pull-left">
								<i class="vh vh-lg vh-file-o m-r-sm"></i>
							</span>
                          <span class="h5 m-t-xs m-l-xs m-r-n"><a href="<?= $lnk; ?>" title="<?= $selfhelp[$i]['article'][1][$j]['article_title']; ?>" class="link"><?= $selfhelp[$i]['article'][1][$j]['article_title']; ?></a></span>
						     <span class="vh-yellow m-l-md pull-right">
                           <? //for($cn=0;$cn<$selfhelp[$i]['article'][1][$j]['rating'];$cn++){ ?><!--<i class="vh vh-lg vh-star"></i>--><? //}
                              //for($cn=$selfhelp[$i]['article'][1][$j]['rating'];$cn<5;$cn++){ ?><!--<i class="vh vh-lg vh-star-empty"></i>--><? //} ?>
         <span class="post-overview-count">
									<aside><span style="color: #333333;" class="h5"><?= $selfhelp[$i]['article'][1][$j]['commentCount']; ?></span></aside>
									<? echo $vis_language['TXTCOMMENT']; ?>
							  </span>
							  <span class="post-overview-count">
									<aside><span style="color: #333333;" class="h5"><?= $selfhelp[$i]['article'][1][$j]['art_likes']; ?></span></aside>
									<? echo $vis_language['TXTVOTE']; ?>
							  </span>	
                     </span>
                          <div class="m-t-xs m-r-n">
                              <span class="h6 m-l-lg m-r-sm"><? echo (trim($selfhelp[$i]['article'][1][$j]['author_name'])!='')?$selfhelp[$i]['article'][1][$j]['author_name']:$selfhelp[$i]['article'][1][$j]['author']; ?></span>
                              <span class="h6 m-r-md"><?= format_datetime($selfhelp[$i]['article'][1][$j]['entry_date']); ?></span>
							  							
                          </div>
                        </div></li>
                     <? } else { if($j<=4){?>   
						   <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;?>" title="<?= $selfhelp[$i]['article'][1][$j]['article_title']; ?>" class="link"><?= $selfhelp[$i]['article'][1][$j]['article_title']; ?></a></div></li>
             <? } }?> 
				<? }
		if($j==5 && $parentid==0){?><a class="link m-l" href="<?= ((isset($url_rewrite) && $url_rewrite==1)?('/self-help/'.$selfhelp[$i]['selfhelp_id'].'/'):('?/selfhelp/categories/'.trim(str_replace(' ','-',preg_replace('/\s+/', ' ', strtolower(preg_replace('/[^A-Za-z0-9\-]/', ' ', $selfhelp[$i]['selfhelp_title'])))),"-").'/'.$selfhelp[$i]['selfhelp_id'])); ?>"><? echo "More..";?></a><? } } ?>
            </ul>
        </div> <!-- /.col-md-12 .col-sm-12 -->
    </div> <!-- /.row -->
  </div>
 <?php if( $parentid!=0){ ?>
  <div class="row padder clr m-b m-t" id="paging_bottom" <? if($selfhelp[$i]['article'][1]==-1) echo 'style="display:none;"'; ?>>
	   <div class="col-sm-12 text-center">
		  <ul class="pagination-sm pagination" id="forum_pagination"></ul>
	   </div> </div>
  <? } if( $parentid==0){ ?> </div> 
		<? }if($parentid==0 && ($i%2!=0 || $a==($i+1))){?></div><?}}?>
  </div><!--close main div-->
  
  <? if($parentid==0) {?>
  <div class="col-md-4 col-sm-4">
  <div class="row b-l">
	<? if($recent_articles!=-1 && $parentid==0) { $recent_arts = array_filter($recent_articles);?>
        <div>
            <div class="panel-heading">
				 <h4 class="panel-title1"><span class="vh vh-rss vh-warning"></span>&nbsp;<? echo $vis_language['TXTRECENTARTICLES']; ?></h4>
          </div>
		  <? if(!empty($recent_arts)){ ?>
		  <div class="panel-body">
                <ul class="list-group no-borders m-b-n">
				<? 	for($i=0;$i<count($recent_articles);$i++) {
						if(trim($recent_articles[$i]['article_url'])!=''):
							$artUrl = trim(str_replace(' ','-',preg_replace('/\s+/', ' ', strtolower(preg_replace('/[^A-Za-z0-9\-]/', ' ', $recent_articles[$i]['article_url'])))),"-");
						else:
							$artUrl = trim(str_replace(' ','-',preg_replace('/\s+/', ' ', strtolower(preg_replace('/[^A-Za-z0-9\-]/', ' ', $recent_articles[$i]['article_title'])))),"-");
						endif; 
						
						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($art!=-1 && count($art)>=2):
							$lnk='?/selfhelp/view-article/'.$artUrl.'/'.$recent_articles[$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; ?>" title="<?= $recent_articles[$i]['article_title']; ?>" class="link"><?= $recent_articles[$i]['article_title']; ?></a></div>
						</li>
				<? 	} ?>					
                </ul>
          </div> <!-- /.panel-body -->
		  <? } ?>
  		</div> <!-- /.col-md-6 .col-sm-6 -->
		<? } if($featured_articles!=-1 && $parentid==0) { $featured_arts = array_filter($featured_articles);?>
        <div >
          <div class="panel-heading">
				 <h4 class="panel-title1"><span class="vh vh-star vh-warning"></span>&nbsp;<? echo $vis_language['TXTFEATUREDARTICLES']; ?></h4>
           
          </div>
		  <? if(!empty($featured_arts)){ ?>
          <div class="panel-body">
                <ul class="list-group no-borders m-b-n">
				
				<? //if($featured_articles[$i][0]!='')	
				for($i=0;$i<count($featured_articles);$i++) {
						if(trim($featured_articles[$i]['article_url'])!=''):
							$artUrl = trim(str_replace(' ','-',preg_replace('/\s+/', ' ', strtolower(preg_replace('/[^A-Za-z0-9\-]/', ' ', $featured_articles[$i]['article_url'])))),"-");
						else:
							$artUrl = trim(str_replace(' ','-',preg_replace('/\s+/', ' ', strtolower(preg_replace('/[^A-Za-z0-9\-]/', ' ', $featured_articles[$i]['article_title'])))),"-");
						endif;
						
						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($art!=-1 && count($art)>=2):
							$lnk='?/selfhelp/view-article/'.$artUrl.'/'.$featured_articles[$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; ?>" title="<?= $featured_articles[$i]['article_title']; ?>" class="link"><?= $featured_articles[$i]['article_title']; ?></a></div>
                  </li>
				<? } ?> 
                </ul>
          </div> <!-- /.panel-body -->
		  <? } ?>
  		</div> <!-- /.col-md-6 .col-sm-6 -->
		<? } ?>
    </div>
  </div>
  <? }?>
   
   <? if(VIS_HEAD_MENU_SUBMITTICKET==1 || (VIS_HEAD_MENU_SUBMITTICKET==2 && IS_LOGIN!=0))
   {?>
<div style="clear:both;"></div>
<div class="text-center m-t" style="background:#f2f4f8; padding:25px;">
<h2><? echo $vis_language['TXTLETSHELPU']; ?></h2>
<br />
<p id="submittks"><a class="btn btn-lg btn-primary" href="index.php?<?php echo (VIS_HEAD_MENU_SUBMITTICKET==1 || (VIS_HEAD_MENU_SUBMITTICKET==2  && IS_LOGIN))?'/ticket/submit-ticket':'/home/login';?>"><? echo $vis_language['TXTSUBMITATICKET']; ?></a></p>
</div>
  
  <? }?> 
</section>
<? } ?>
<script>
	 <? if($page_count>0) { ?>
       $('.pagination-sm').twbsPagination({
   		totalPages:<?php echo $page_count; ?>,
   		startPage:<?php echo $page+1; ?>,
   		visiblePages:3,
   		first:false,
   		last:false,
   		onPageClick: function (event, page) {
   		$.ajax({
   		url: 'index.php',
   		data: {'vis_module':"selfhelp", 'vis_operation':"view_selfhelp_group", 'vis_page':page-1 ,'vis_parent_id':'<?= $parentid;?>', 'vis_sorted_by':'<? echo $operation['vis_sorted_by'];?>','vis_action':"<?= $operation['vis_action']?>"},
   		type: "POST",
   		success: function(data) {            
   			$("#main_div").html(data);
   		}
   		});
       }
     });
     <? }?>
         function article_sort(vis_sort) {
   	$.ajax({
           url: 'index.php',
           data: {'vis_module':"selfhelp", 'vis_operation':"view_selfhelp_group", 'vis_parent_id':"<?= $parentid; ?>", 'vis_sorted_by':vis_sort,'vis_action':"<?= $operation['vis_action']?>"},
           type: "POST",
           success: function(data) {$('#main_div').html(data);}
       });
   }
   </script>
