| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467 |
- <?php
- /**
- * 问答显示业务
- * @author cp
- */
- class AskController extends DooController {
-
- private $userlogic;
- private $column;
- private $comart;
-
- function __construct() {
- Load::logic ( 'User' );
- $this->userlogic = new UserLogic ();
-
- include './protected/config/index.conf.php';
- $this->column=$column;
-
- Doo::loadModel('Article');
- $article=new Article();
- $cid=$this->column['COMPANY'];
-
- $this->comart=$article->getArticleByCid($cid,4);
-
- }
-
- /**
- * 进入问答网首页
- */
- public function index() {
-
- $data ['category_info'] = $this->userlogic->get_category_info ();
-
- if (isset ( $data ['category_info'] [0] ['rsort'] [0] ['aid'] ))
- $id = $data ['category_info'] [0] ['rsort'] [0] ['aid'];
- elseif (isset ( $data ['category_info'] [0] ['rsort'] [0] ['cid'] ))
- $id = $data ['category_info'] [0] ['rsort'] [0] ['cid'];
-
- $data ['index_info'] = array ("sort" => array () );
-
- if (isset ( $data ['category_info'] [0] ['rsort'] [0] ['cid'] ))
- $data ['index_info'] = $this->userlogic->get_category_by_pid ( $data ['category_info'] [0] ['rsort'] [0] ['cid'] );
-
- $data ['title'] = "";
- if (isset ( $data ['category_info'] [0] ['rsort'] [0] ['name'] ))
- $data ['title'] = $data ['category_info'] [0] ['rsort'] [0] ['name'];
-
- $data['map']='help';
- $data['comart']=$this->comart;
- $this->render ( 'helpIndex', $data );
- }
-
- /**
- * 显示帮助中心详情页
- */
- public function show_index_info() {
- $cid = $this->check_params ( 'cid' );
- $sid = $this->check_params ( 'sid' );
-
- //获取上一级分类
- $data ['catetory'] = $this->userlogic->get_category_by_cid ( $cid );
- //获取点击分类
- $data ['click_catetory'] = $this->userlogic->get_category_by_cid ( $sid );
- //获取点击分类的子分类
- $data ['catetory_child'] = $this->userlogic->get_category_by_pid ( $cid );
- $data ['defualt_info'] = array ("child_category" => array (), "article" => array () );
- $data ['title'] = "";
- $data ['defualt_info'] = $this->userlogic->get_category_by_pid ( $sid );
-
- if (isset ( $data ['catetory_child'] ['sort'] [0] ['name'] )) {
- $data ['title'] = $data ['click_catetory'] ['name'];
- } else {
- $data ['title'] = $data ['click_catetory'] ['name'];
-
- }
-
- $data ['id'] = $sid;
- $this->render ( 'index_info', $data, true );
- }
-
- /**
- * ajax显示文章
- */
- public function ajax_show_article() {
- $aid = $this->get_args ( 'aid' );
-
- $data = $this->userlogic->get_article_by_aid ( $aid );
- $e = json_encode ( $data );
- echo $e;
- }
-
- //显示首页文章
- public function show_index_article() {
-
- $cid = $this->check_params ( 'cid' );
- $aid = $this->check_params ( 'aid' );
-
- $data ['catetory'] = $this->userlogic->get_category_by_cid ( $cid );
- $data ['catetory_child'] = $this->userlogic->get_category_by_pid ( $cid );
- $data ['defualt_info'] = array ("child_category" => array (), "article" => array () );
- $data ['title'] = "";
-
- if (isset ( $data ['catetory_child'] ['child_category'] [0] )) {
- $data ['defualt_info'] = $this->userlogic->get_category_by_pid ( $data ['catetory_child'] ['child_category'] [0] ['cid'] );
- $data ['title'] = $data ['catetory_child'] ['child_category'] [0] ['name'];
- }
-
- $data ['article_info'] = $this->userlogic->get_article_by_aid ( $aid );
- $data ['id'] = $aid;
- $data['comart']=$this->comart;
- $this->render ( 'index_article', $data );
- }
-
- /**
- * ajax详情
- */
- public function ajax_show_catetory() {
- $cid = $this->get_args ( 'cid' );
- $data ['catetory'] = $this->userlogic->get_category_by_pid ( $cid );
- $e = json_encode ( $data );
- echo $e;
- }
-
- public function searchHelpNews(){
- $k = $this->get_args('k') ? $this->get_args('k') : "";
-
- $data ['article_list']=array('articles'=>array());
- if (!empty($k)){
- Doo::loadModel('ArticleDao');
- $ArticleDao=new ArticleDao();
- Doo::loadModel ( 'CategoryDao' );
- $categorydao = new CategoryDao ();
-
- $ArticleDaoList['articles']=$ArticleDao->find(array ( 'where' => 'title like "%'.$k.'%"', 'asArray' => TRUE ));
-
- foreach ( $ArticleDaoList['articles'] as $key => $value ) {
- $ArticleDaoList['articles'] [$key] ['category'] = $categorydao->get_category_by_cid ( $value ['cid'] );
- }
-
- $data ['article_list'] = $ArticleDaoList;
- }
-
- $data ['category'] = $this->userlogic->get_category_by_grade ();
- $data ['mod'] = 'article';
- $data ['cid'] = 0;
- $this->render ( "poslistHelpSearch", $data );die;
-
-
- $list=array();$next=0;$previous=0;
- if (!empty($k)){
- Doo::loadModel('Down');
- $down=new Down();
- $article=new Article();
-
- if ($onPage <= 0)
- $onPage = 1;
- $pageSize = 20;
- $o=$onPage;
- $lower = (-- $o) * $pageSize;
-
- $previous = $onPage != 0 ? $onPage - 1 : $onPage;
-
- if ($kind==2){
- $list=$down->find(array('where'=>'title like "%'.$k.'%" or key_number like "%'.$k.'%"','limit'=>$lower.','.$pageSize ,'asArray' => TRUE));
-
- $totalCount = $down->count(array('where'=>'title like "%'.$k.'%" or key_number like "%'.$k.'%"','limit'=>$lower.','.$pageSize ,'asArray' => TRUE));
- $total = intval ( $totalCount / $pageSize );
- $totalPage = ($totalCount % $pageSize) == 0 ? $total : $total + 1;
- $next = $onPage == $totalPage ? $totalPage : $onPage + 1;
-
- foreach ($list as $key=>$value){
- $url=explode("{b}", $value['down_url']);
-
- $list[$key]['down_url']=$url;
- }
-
- }elseif($kind==3){
- Doo::loadModel('ArticleDao');
- $ArticleDao=new ArticleDao();
-
- $list=$ArticleDao->find(array('select'=>'title,aid,cid,time','where'=>'title like "%'.$k.'%" ',
- 'limit'=>$lower.','.$pageSize ,'asArray' => TRUE));
- $totalCount = $ArticleDao->count(array('where'=>'title like "%'.$k.'%" ','asArray' => TRUE));
- $total = intval ( $totalCount / $pageSize );
- $totalPage = ($totalCount % $pageSize) == 0 ? $total : $total + 1;
- $next = $onPage == $totalPage ? $totalPage : $onPage + 1;
-
- }else{//or content like "%'.$k.'%"
- $list=$article->find(array('select'=>'title,aid,cid,time','where'=>'title like "%'.$k.'%" and ( cid=4 or cid=5 or cid=3 or cid=7)',
- 'limit'=>$lower.','.$pageSize ,'asArray' => TRUE));
- $totalCount = $article->count(array('where'=>'title like "%'.$k.'%" and ( cid=4 or cid=5 or cid=3 or cid=7)','asArray' => TRUE));
- $total = intval ( $totalCount / $pageSize );
- $totalPage = ($totalCount % $pageSize) == 0 ? $total : $total + 1;
- $next = $onPage == $totalPage ? $totalPage : $onPage + 1;
-
- foreach ($list as $key=>$value){
- if($value['cid']==4)
- $list[$key]['c']='公司新闻';
- elseif ($value['cid']==5)
- $list[$key]['c']='行业新闻';
- elseif ($value['cid']==3)
- $list[$key]['c']='培训教育';
- elseif ($value['cid']==7)
- $list[$key]['c']='软件更新';
- }
- }
-
- }
-
- $data['next']=$next;
- $data['previous']=$previous;
- $data['k']=$k;
- $data['onPage']=$onPage;
- $data['list']=$list;
- $data['kind']=$kind;
- $data['map']='sNews';
- $this->render ( "poslistHelpSearch", $data );
- }
-
- /**
- * 显示文章
- */
- public function show_article() {
- $cid = $this->check_params ( 'cid' );
-
- if ($cid === false)
- $cid = $this->get_args ( 'cid' );
-
- $cid = is_numeric ( $cid ) ? $cid : 0;
- $on_page = $this->check_params ( 'on_page' );
- $on_page = is_numeric ( $on_page ) && $on_page > 0 ? $on_page : 1;
- $action = '/article/' . $cid . '/';
- $page_size = 20;
- $condition = "";
-
- if ($cid >= 1)
- $condition .= " and cid = " . $cid;
-
- $page = $this->userlogic->get_page ( 'zhhelp_article', $condition, $on_page, $page_size, $action );
- $limit = " order by time desc limit " . $page ['lower'] . ", " . $page_size . " ";
- $page ['articles'] = $this->userlogic->get_article_list ( array (), $condition, $limit, 'zhhelp_article' );
- $data ['article_list'] = $page;
- $data ['category'] = $this->userlogic->get_category_by_grade ();
- $data ['mod'] = 'article';
- $data ['cid'] = $cid;
- $this->render ( 'poslist', $data );
- }
-
- /**
- * 进入添加文章
- */
- public function add_article() {
- $data ['category'] = $this->userlogic->get_category_by_grade ();
- $data ['mod'] = 'add_article';
- $this->render ( 'postnews', $data );
- }
-
- /**
- * 进入编辑文章
- */
- public function edit_article() {
- $aid = $this->check_params ( 'aid' );
- $data ['category'] = $this->userlogic->get_category_by_grade ();
- $data ['article'] = $this->userlogic->get_article_by_aid ( $aid );
- $data ['category_name'] = $this->userlogic->get_category_by_cid ( $data ['article'] ['cid'] );
- $data ['mod'] = 'article';
- $this->render ( 'edit_postnews', $data );
- }
-
- /**
- * 编辑文章
- */
- public function do_edit_article(){
- $data['aid']=$this->get_args('aid');
-
- $data ['cid'] = $this->get_args ( 'cid' );
-
- $data ['title'] = $this->get_args ( 'title' );
-
- $str = $_POST ['content'];
-
- $data ['content'] = $str;
-
- $data ['order'] = $this->get_args ( 'order' );
-
- if ( empty ( $data ['title'] ) || empty ( $data ['content'] ))
- die ( "填入数据不正确" );
-
- $this->userlogic->edit_article($data);
- header ( 'Content-Type:text/html;charset=utf-8' );
- @header ( "Location: " . WEB_SITE . "/article" );
- }
-
- /**
- * 添加文章
- */
- public function do_add_article() {
-
- $data ['cid'] = $this->get_args ( 'cid' );
-
- $data ['title'] = $this->get_args ( 'title' );
-
- $str = $_POST ['content'];
-
- $data ['content'] = $str;
-
- $data ['order'] = $this->get_args ( 'order' );
-
- if (empty ( $data ['cid'] ) || $data ['cid'] == 0 || empty ( $data ['title'] ) || empty ( $data ['content'] ))
- die ( "填入数据不正确" );
-
- $this->userlogic->add_article ( $data );
-
- $data ['category'] = $this->userlogic->get_category_by_grade ();
-
- $data ['mod'] = 'add_article';
-
- $this->render ( 'postnews', $data );
- }
-
- /**
- * 添加分类
- */
- public function add_categroy() {
- $data ['mod'] = 'add_categroy';
- $data ['category'] = $this->userlogic->get_category_by_grade ();
- $data ['category_lv2'] = $this->userlogic->get_category_by_grade ( 2 );
- $data ['cid'] = "";
- $this->render ( 'categroy', $data );
- }
-
- /**
- * 添加分类
- */
- public function do_add_categroy() {
- $data ['pid'] = $this->get_args ( 'pid' );
-
- $data ['name'] = $this->get_args ( 'name' );
-
- $data ['grade'] = $this->get_args ( 'grade' );
-
- $data ['displayorder'] = $this->get_args ( 'displayorder' );
-
- if (empty ( $data ['name'] ))
- die ( "填入数据不正确" );
-
- $this->userlogic->add_categroy ( $data );
-
- $data ['mod'] = 'add_categroy';
-
- $data ['category'] = $this->userlogic->get_category_by_grade ();
-
- $data ['category_lv2'] = $this->userlogic->get_category_by_grade ( 2 );
-
- $data ['cid'] = "";
-
- $this->render ( 'categroy', $data );
- }
-
- /**
- * 删除分类--删除子类和文章
- */
- function delete_categroy() {
- $cid = $this->check_params ( 'cid' );
-
- if (empty ( $cid ))
- die ( "填入数据不正确" );
-
- $this->userlogic->delete_categroy ( $cid );
-
- echo "success<a href='/add_categroy'>返回</a>";
- }
-
- /**
- * 删除文章
- */
- function delete_article() {
- $aid = $this->check_params ( 'aid' );
-
- if (empty ( $aid ))
- die ( "填入数据不正确" );
-
- $this->userlogic->delete_article ( $aid );
-
- echo "success<a href='/article'>返回</a>";
- }
-
- /**
- * 上传问题图片--移动到user
- */
- public function upload_article_img() {
-
- require_once (SITE_PATH . '/protected/plugin/Uploader.class.php');
-
- //上传配置
- $config = array ("savePath" => SITE_PATH . "/global/upload/img/", "maxSize" => 2000, //单位KB
- "allowFiles" => array (".gif", ".png", ".jpg", ".jpeg", ".bmp" ) );
- //上传图片框中的描述表单名称,
- $title = htmlspecialchars ( $_POST ['pictitle'], ENT_QUOTES );
- //生成上传实例对象并完成上传
- $up = new Uploader ( "upfile", $config );
-
- /**
- * 得到上传文件所对应的各个参数,数组结构
- * array(
- * "originalName" => "", //原始文件名
- * "name" => "", //新文件名
- * "url" => "", //返回的地址
- * "size" => "", //文件大小
- * "type" => "" , //文件类型
- * "state" => "" //上传状态,上传成功时必须返回"SUCCESS"
- * )
- */
-
- $info = $up->getFileInfo ();
- echo "{'url' :'" . $info ["name"] . "', 'title':'" . $title . "','original' :'" . $info ["originalName"] . "', 'state' :'" . $info ['state'] . "' }";
- /**
- * 向浏览器返回数据json数据
- * {
- * 'url' :'a.jpg', //保存后的文件路径
- * 'title' :'hello', //文件描述,对图片来说在前端会添加到title属性上
- * 'original' :'b.jpg', //原始文件名
- * 'state' :'SUCCESS' //上传状态,成功时返回SUCCESS,其他任何值将原样返回至图片上传框中
- * }
- */
- }
-
- /**
- * 获取get或者POST值
- * @param string $name 属性名称
- * @return fixed 值
- */
- function get_args($name) {
- if (isset ( $_GET [$name] )) {
- if (is_array ( $_GET [$name] ))
- return $_GET [$name];
- else
- return $_GET [$name] ;
-
- } elseif (isset ( $_POST [$name] )) {
- if (is_array ( $_POST [$name] ))
- return $_POST [$name];
- else
- return $_POST [$name] ;
- } else {
-
- return false;
- }
- }
-
- /**
- * 检测数据输入的非法字符和转义非法字符
- */
- function check_params($name = "") {
- if (isset ( $this->params [$name] )) {
-
- return $this->params [$name] ;
- } else {
-
- return false;
- }
- }
- }
- ?>
|