AskController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <?php
  2. /**
  3. * 问答显示业务
  4. * @author cp
  5. */
  6. class AskController extends DooController {
  7. private $userlogic;
  8. private $column;
  9. private $comart;
  10. function __construct() {
  11. Load::logic ( 'User' );
  12. $this->userlogic = new UserLogic ();
  13. include './protected/config/index.conf.php';
  14. $this->column=$column;
  15. Doo::loadModel('Article');
  16. $article=new Article();
  17. $cid=$this->column['COMPANY'];
  18. $this->comart=$article->getArticleByCid($cid,4);
  19. }
  20. /**
  21. * 进入问答网首页
  22. */
  23. public function index() {
  24. $data ['category_info'] = $this->userlogic->get_category_info ();
  25. if (isset ( $data ['category_info'] [0] ['rsort'] [0] ['aid'] ))
  26. $id = $data ['category_info'] [0] ['rsort'] [0] ['aid'];
  27. elseif (isset ( $data ['category_info'] [0] ['rsort'] [0] ['cid'] ))
  28. $id = $data ['category_info'] [0] ['rsort'] [0] ['cid'];
  29. $data ['index_info'] = array ("sort" => array () );
  30. if (isset ( $data ['category_info'] [0] ['rsort'] [0] ['cid'] ))
  31. $data ['index_info'] = $this->userlogic->get_category_by_pid ( $data ['category_info'] [0] ['rsort'] [0] ['cid'] );
  32. $data ['title'] = "";
  33. if (isset ( $data ['category_info'] [0] ['rsort'] [0] ['name'] ))
  34. $data ['title'] = $data ['category_info'] [0] ['rsort'] [0] ['name'];
  35. $data['map']='help';
  36. $data['comart']=$this->comart;
  37. $this->render ( 'helpIndex', $data );
  38. }
  39. /**
  40. * 显示帮助中心详情页
  41. */
  42. public function show_index_info() {
  43. $cid = $this->check_params ( 'cid' );
  44. $sid = $this->check_params ( 'sid' );
  45. //获取上一级分类
  46. $data ['catetory'] = $this->userlogic->get_category_by_cid ( $cid );
  47. //获取点击分类
  48. $data ['click_catetory'] = $this->userlogic->get_category_by_cid ( $sid );
  49. //获取点击分类的子分类
  50. $data ['catetory_child'] = $this->userlogic->get_category_by_pid ( $cid );
  51. $data ['defualt_info'] = array ("child_category" => array (), "article" => array () );
  52. $data ['title'] = "";
  53. $data ['defualt_info'] = $this->userlogic->get_category_by_pid ( $sid );
  54. if (isset ( $data ['catetory_child'] ['sort'] [0] ['name'] )) {
  55. $data ['title'] = $data ['click_catetory'] ['name'];
  56. } else {
  57. $data ['title'] = $data ['click_catetory'] ['name'];
  58. }
  59. $data ['id'] = $sid;
  60. $this->render ( 'index_info', $data, true );
  61. }
  62. /**
  63. * ajax显示文章
  64. */
  65. public function ajax_show_article() {
  66. $aid = $this->get_args ( 'aid' );
  67. $data = $this->userlogic->get_article_by_aid ( $aid );
  68. $e = json_encode ( $data );
  69. echo $e;
  70. }
  71. //显示首页文章
  72. public function show_index_article() {
  73. $cid = $this->check_params ( 'cid' );
  74. $aid = $this->check_params ( 'aid' );
  75. $data ['catetory'] = $this->userlogic->get_category_by_cid ( $cid );
  76. $data ['catetory_child'] = $this->userlogic->get_category_by_pid ( $cid );
  77. $data ['defualt_info'] = array ("child_category" => array (), "article" => array () );
  78. $data ['title'] = "";
  79. if (isset ( $data ['catetory_child'] ['child_category'] [0] )) {
  80. $data ['defualt_info'] = $this->userlogic->get_category_by_pid ( $data ['catetory_child'] ['child_category'] [0] ['cid'] );
  81. $data ['title'] = $data ['catetory_child'] ['child_category'] [0] ['name'];
  82. }
  83. $data ['article_info'] = $this->userlogic->get_article_by_aid ( $aid );
  84. $data ['id'] = $aid;
  85. $data['comart']=$this->comart;
  86. $this->render ( 'index_article', $data );
  87. }
  88. /**
  89. * ajax详情
  90. */
  91. public function ajax_show_catetory() {
  92. $cid = $this->get_args ( 'cid' );
  93. $data ['catetory'] = $this->userlogic->get_category_by_pid ( $cid );
  94. $e = json_encode ( $data );
  95. echo $e;
  96. }
  97. public function searchHelpNews(){
  98. $k = $this->get_args('k') ? $this->get_args('k') : "";
  99. $data ['article_list']=array('articles'=>array());
  100. if (!empty($k)){
  101. Doo::loadModel('ArticleDao');
  102. $ArticleDao=new ArticleDao();
  103. Doo::loadModel ( 'CategoryDao' );
  104. $categorydao = new CategoryDao ();
  105. $ArticleDaoList['articles']=$ArticleDao->find(array ( 'where' => 'title like "%'.$k.'%"', 'asArray' => TRUE ));
  106. foreach ( $ArticleDaoList['articles'] as $key => $value ) {
  107. $ArticleDaoList['articles'] [$key] ['category'] = $categorydao->get_category_by_cid ( $value ['cid'] );
  108. }
  109. $data ['article_list'] = $ArticleDaoList;
  110. }
  111. $data ['category'] = $this->userlogic->get_category_by_grade ();
  112. $data ['mod'] = 'article';
  113. $data ['cid'] = 0;
  114. $this->render ( "poslistHelpSearch", $data );die;
  115. $list=array();$next=0;$previous=0;
  116. if (!empty($k)){
  117. Doo::loadModel('Down');
  118. $down=new Down();
  119. $article=new Article();
  120. if ($onPage <= 0)
  121. $onPage = 1;
  122. $pageSize = 20;
  123. $o=$onPage;
  124. $lower = (-- $o) * $pageSize;
  125. $previous = $onPage != 0 ? $onPage - 1 : $onPage;
  126. if ($kind==2){
  127. $list=$down->find(array('where'=>'title like "%'.$k.'%" or key_number like "%'.$k.'%"','limit'=>$lower.','.$pageSize ,'asArray' => TRUE));
  128. $totalCount = $down->count(array('where'=>'title like "%'.$k.'%" or key_number like "%'.$k.'%"','limit'=>$lower.','.$pageSize ,'asArray' => TRUE));
  129. $total = intval ( $totalCount / $pageSize );
  130. $totalPage = ($totalCount % $pageSize) == 0 ? $total : $total + 1;
  131. $next = $onPage == $totalPage ? $totalPage : $onPage + 1;
  132. foreach ($list as $key=>$value){
  133. $url=explode("{b}", $value['down_url']);
  134. $list[$key]['down_url']=$url;
  135. }
  136. }elseif($kind==3){
  137. Doo::loadModel('ArticleDao');
  138. $ArticleDao=new ArticleDao();
  139. $list=$ArticleDao->find(array('select'=>'title,aid,cid,time','where'=>'title like "%'.$k.'%" ',
  140. 'limit'=>$lower.','.$pageSize ,'asArray' => TRUE));
  141. $totalCount = $ArticleDao->count(array('where'=>'title like "%'.$k.'%" ','asArray' => TRUE));
  142. $total = intval ( $totalCount / $pageSize );
  143. $totalPage = ($totalCount % $pageSize) == 0 ? $total : $total + 1;
  144. $next = $onPage == $totalPage ? $totalPage : $onPage + 1;
  145. }else{//or content like "%'.$k.'%"
  146. $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)',
  147. 'limit'=>$lower.','.$pageSize ,'asArray' => TRUE));
  148. $totalCount = $article->count(array('where'=>'title like "%'.$k.'%" and ( cid=4 or cid=5 or cid=3 or cid=7)','asArray' => TRUE));
  149. $total = intval ( $totalCount / $pageSize );
  150. $totalPage = ($totalCount % $pageSize) == 0 ? $total : $total + 1;
  151. $next = $onPage == $totalPage ? $totalPage : $onPage + 1;
  152. foreach ($list as $key=>$value){
  153. if($value['cid']==4)
  154. $list[$key]['c']='公司新闻';
  155. elseif ($value['cid']==5)
  156. $list[$key]['c']='行业新闻';
  157. elseif ($value['cid']==3)
  158. $list[$key]['c']='培训教育';
  159. elseif ($value['cid']==7)
  160. $list[$key]['c']='软件更新';
  161. }
  162. }
  163. }
  164. $data['next']=$next;
  165. $data['previous']=$previous;
  166. $data['k']=$k;
  167. $data['onPage']=$onPage;
  168. $data['list']=$list;
  169. $data['kind']=$kind;
  170. $data['map']='sNews';
  171. $this->render ( "poslistHelpSearch", $data );
  172. }
  173. /**
  174. * 显示文章
  175. */
  176. public function show_article() {
  177. $cid = $this->check_params ( 'cid' );
  178. if ($cid === false)
  179. $cid = $this->get_args ( 'cid' );
  180. $cid = is_numeric ( $cid ) ? $cid : 0;
  181. $on_page = $this->check_params ( 'on_page' );
  182. $on_page = is_numeric ( $on_page ) && $on_page > 0 ? $on_page : 1;
  183. $action = '/article/' . $cid . '/';
  184. $page_size = 20;
  185. $condition = "";
  186. if ($cid >= 1)
  187. $condition .= " and cid = " . $cid;
  188. $page = $this->userlogic->get_page ( 'zhhelp_article', $condition, $on_page, $page_size, $action );
  189. $limit = " order by time desc limit " . $page ['lower'] . ", " . $page_size . " ";
  190. $page ['articles'] = $this->userlogic->get_article_list ( array (), $condition, $limit, 'zhhelp_article' );
  191. $data ['article_list'] = $page;
  192. $data ['category'] = $this->userlogic->get_category_by_grade ();
  193. $data ['mod'] = 'article';
  194. $data ['cid'] = $cid;
  195. $this->render ( 'poslist', $data );
  196. }
  197. /**
  198. * 进入添加文章
  199. */
  200. public function add_article() {
  201. $data ['category'] = $this->userlogic->get_category_by_grade ();
  202. $data ['mod'] = 'add_article';
  203. $this->render ( 'postnews', $data );
  204. }
  205. /**
  206. * 进入编辑文章
  207. */
  208. public function edit_article() {
  209. $aid = $this->check_params ( 'aid' );
  210. $data ['category'] = $this->userlogic->get_category_by_grade ();
  211. $data ['article'] = $this->userlogic->get_article_by_aid ( $aid );
  212. $data ['category_name'] = $this->userlogic->get_category_by_cid ( $data ['article'] ['cid'] );
  213. $data ['mod'] = 'article';
  214. $this->render ( 'edit_postnews', $data );
  215. }
  216. /**
  217. * 编辑文章
  218. */
  219. public function do_edit_article(){
  220. $data['aid']=$this->get_args('aid');
  221. $data ['cid'] = $this->get_args ( 'cid' );
  222. $data ['title'] = $this->get_args ( 'title' );
  223. $str = $_POST ['content'];
  224. $data ['content'] = $str;
  225. $data ['order'] = $this->get_args ( 'order' );
  226. if ( empty ( $data ['title'] ) || empty ( $data ['content'] ))
  227. die ( "填入数据不正确" );
  228. $this->userlogic->edit_article($data);
  229. header ( 'Content-Type:text/html;charset=utf-8' );
  230. @header ( "Location: " . WEB_SITE . "/article" );
  231. }
  232. /**
  233. * 添加文章
  234. */
  235. public function do_add_article() {
  236. $data ['cid'] = $this->get_args ( 'cid' );
  237. $data ['title'] = $this->get_args ( 'title' );
  238. $str = $_POST ['content'];
  239. $data ['content'] = $str;
  240. $data ['order'] = $this->get_args ( 'order' );
  241. if (empty ( $data ['cid'] ) || $data ['cid'] == 0 || empty ( $data ['title'] ) || empty ( $data ['content'] ))
  242. die ( "填入数据不正确" );
  243. $this->userlogic->add_article ( $data );
  244. $data ['category'] = $this->userlogic->get_category_by_grade ();
  245. $data ['mod'] = 'add_article';
  246. $this->render ( 'postnews', $data );
  247. }
  248. /**
  249. * 添加分类
  250. */
  251. public function add_categroy() {
  252. $data ['mod'] = 'add_categroy';
  253. $data ['category'] = $this->userlogic->get_category_by_grade ();
  254. $data ['category_lv2'] = $this->userlogic->get_category_by_grade ( 2 );
  255. $data ['cid'] = "";
  256. $this->render ( 'categroy', $data );
  257. }
  258. /**
  259. * 添加分类
  260. */
  261. public function do_add_categroy() {
  262. $data ['pid'] = $this->get_args ( 'pid' );
  263. $data ['name'] = $this->get_args ( 'name' );
  264. $data ['grade'] = $this->get_args ( 'grade' );
  265. $data ['displayorder'] = $this->get_args ( 'displayorder' );
  266. if (empty ( $data ['name'] ))
  267. die ( "填入数据不正确" );
  268. $this->userlogic->add_categroy ( $data );
  269. $data ['mod'] = 'add_categroy';
  270. $data ['category'] = $this->userlogic->get_category_by_grade ();
  271. $data ['category_lv2'] = $this->userlogic->get_category_by_grade ( 2 );
  272. $data ['cid'] = "";
  273. $this->render ( 'categroy', $data );
  274. }
  275. /**
  276. * 删除分类--删除子类和文章
  277. */
  278. function delete_categroy() {
  279. $cid = $this->check_params ( 'cid' );
  280. if (empty ( $cid ))
  281. die ( "填入数据不正确" );
  282. $this->userlogic->delete_categroy ( $cid );
  283. echo "success<a href='/add_categroy'>返回</a>";
  284. }
  285. /**
  286. * 删除文章
  287. */
  288. function delete_article() {
  289. $aid = $this->check_params ( 'aid' );
  290. if (empty ( $aid ))
  291. die ( "填入数据不正确" );
  292. $this->userlogic->delete_article ( $aid );
  293. echo "success<a href='/article'>返回</a>";
  294. }
  295. /**
  296. * 上传问题图片--移动到user
  297. */
  298. public function upload_article_img() {
  299. require_once (SITE_PATH . '/protected/plugin/Uploader.class.php');
  300. //上传配置
  301. $config = array ("savePath" => SITE_PATH . "/global/upload/img/", "maxSize" => 2000, //单位KB
  302. "allowFiles" => array (".gif", ".png", ".jpg", ".jpeg", ".bmp" ) );
  303. //上传图片框中的描述表单名称,
  304. $title = htmlspecialchars ( $_POST ['pictitle'], ENT_QUOTES );
  305. //生成上传实例对象并完成上传
  306. $up = new Uploader ( "upfile", $config );
  307. /**
  308. * 得到上传文件所对应的各个参数,数组结构
  309. * array(
  310. * "originalName" => "", //原始文件名
  311. * "name" => "", //新文件名
  312. * "url" => "", //返回的地址
  313. * "size" => "", //文件大小
  314. * "type" => "" , //文件类型
  315. * "state" => "" //上传状态,上传成功时必须返回"SUCCESS"
  316. * )
  317. */
  318. $info = $up->getFileInfo ();
  319. echo "{'url' :'" . $info ["name"] . "', 'title':'" . $title . "','original' :'" . $info ["originalName"] . "', 'state' :'" . $info ['state'] . "' }";
  320. /**
  321. * 向浏览器返回数据json数据
  322. * {
  323. * 'url' :'a.jpg', //保存后的文件路径
  324. * 'title' :'hello', //文件描述,对图片来说在前端会添加到title属性上
  325. * 'original' :'b.jpg', //原始文件名
  326. * 'state' :'SUCCESS' //上传状态,成功时返回SUCCESS,其他任何值将原样返回至图片上传框中
  327. * }
  328. */
  329. }
  330. /**
  331. * 获取get或者POST值
  332. * @param string $name 属性名称
  333. * @return fixed 值
  334. */
  335. function get_args($name) {
  336. if (isset ( $_GET [$name] )) {
  337. if (is_array ( $_GET [$name] ))
  338. return $_GET [$name];
  339. else
  340. return $_GET [$name] ;
  341. } elseif (isset ( $_POST [$name] )) {
  342. if (is_array ( $_POST [$name] ))
  343. return $_POST [$name];
  344. else
  345. return $_POST [$name] ;
  346. } else {
  347. return false;
  348. }
  349. }
  350. /**
  351. * 检测数据输入的非法字符和转义非法字符
  352. */
  353. function check_params($name = "") {
  354. if (isset ( $this->params [$name] )) {
  355. return $this->params [$name] ;
  356. } else {
  357. return false;
  358. }
  359. }
  360. }
  361. ?>