<?php

/**
 *      【橙创家校通v4.0】 (C)2010-2012 Tuntron Inc.
 *      
 *    	 http://www.tuntron.com   QQ：1121251729
 *
 *      &帮助管理-系统管理模块&
 */
 
 $Modname = '帮助管理 - 系统设置';
  
  $c=_get('c','index');
  $M = G_class('help');
  $catid = _get('catid','new');
  
  $help_cat = $M->C->read_all();
 
		 if(intval($catid)>0) {
            $help_catname = $M->C->read_one($catid);
        }else{
			if($catid=='new') $help_catname['name'] = '最新问题';
			if($catid=='hot') $help_catname['name'] = '热门问题';
		}
 
 
 switch ($c){
	 
	 case 'index':
	
		 $arrhelps = $M->read_all($catid);
		
		 	//每页显示数据量
			$listnum = '12';
			//当前页
			$pid=$_GET['p'];
			if(is_numeric($pid)&&$pid>0){
				$pid=(int)$pid;
			}else{
				$pid='1';
			}
			//链接地址
			$url = SITEURL . '?mod=system&do=help&catid=' . $catid;
			//数据总数
			$sum = count($arrhelps);
			$pidf = $pid-1;
			$start = $pidf*$listnum;
			$end = $listnum;
			foreach($arrhelps as $key=>$value){
				$array[] = $value;
			}
			$arrhelps = array();
			$arrhelps = array_slice($array, $start, $end);
			$pageinfo = grtpageno($url, $sum, $listnum, $pid);
		 
		 $arrhelp=fields_code($arrhelps,'id');
		 
	 break;
	 
	 
	 
	 case 'addhelp':
	  	
	 	$no_temp=1;
		$Modname = '添加帮助 - '.$Modname;
		$help_cat_option = $M->C->helpcat_option($catid);
		
		if($_POST){
		$post = $M->get_post($_POST);
		//if($post['groupid']==1) Note('禁止编辑系统管理员所在组！','>>点击返回<<');
		$re_id = $M-> save($post);
		Note('帮助添加成功！','>>点击查看<<',SITEURL.'?mod=system&do=help&c=content&catid='.$post['catid'].'&id='.$re_id);
		}
		
		require_once Template($do.'_add');
	 
	 break;
	 
	 
	 case 'addhelpcat':
	  
	  $post = $M->C->get_post($_POST);
	  $M->C-> save($post);
	  location(SITEURL.'?mod=system&do=help');
	  
	 break;
	  
	  case 'updatehelpcat':
	  
	  $post = $M->C->get_post($_POST);
	  $M->C-> save($post,$post['catid']);
	  location(SITEURL.'?mod=system&do=help&catid='.$post['catid']);
	  
	 break;
	  
	  
	case 'delhelpcat':
	
	$isarrhelp = $M->read_all($catid);
	if(is_array($isarrhelp)) {
		Note('分类删除失败，该分类下尚有内容！','>>点击返回<<');
	}else{
		$M->C-> delcat($catid);
		Note('分类删除成功！','>>点击返回<<',SITEURL.'?mod=system&do=help');
	}
	break;
	 
	 
	 
	case 'content':
	 
	 	$no_temp=1;
		$id=_get('id');
		$content = $M->read_one($id);

		//更新点击数
		$post =array($id=>array('pageview'=>$content['pageview']+1),);
		$M->update($post);
		
		$Modname = $content['title'].' - '.$Modname;
		require_once Template($do.'_content');
	 
	 break;
	 
	 case 'delhelp':
	 
	 $helpid = _get('id');
	 $M-> delhelp($helpid);
	 Note('帮助删除成功！','>>点击返回<<',SITEURL.'?mod=system&do=help&catid='.$catid);
	  
	 break;
 }

 if($no_temp<0) require_once Template($do);


?>