cate.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <?php
  2. class cate_c extends Control
  3. {
  4. var $module_sign = "cate";
  5. function __construct()
  6. {
  7. parent::Control();
  8. $this->load_model("cate");//读取分类
  9. $this->load_model("module");//读取模块
  10. }
  11. function cate_c()
  12. {
  13. $this->__construct();
  14. }
  15. function index_f()
  16. {
  17. sys_popedom($this->module_sign.":list","tpl");
  18. $this->cate_m->langid($_SESSION["sys_lang_id"]);
  19. $this->cate_m->get_all();
  20. $this->cate_m->format_list(0,0);
  21. $catelist = $this->cate_m->flist();
  22. if(!is_array($catelist)) $catelist = array();
  23. foreach($catelist AS $key=>$value)
  24. {
  25. $value["space"] = "";
  26. for($i=0;$i<$value["level"];$i++)
  27. {
  28. $value["space"] .= "  ";
  29. }
  30. $catelist[$key] = $value;
  31. }
  32. $this->tpl->assign("catelist",$catelist);
  33. //判断是否有编辑权限
  34. $ifmodify = sys_popedom($this->module_sign.":modify");
  35. $this->tpl->assign("ifmodify",$ifmodify);
  36. $this->tpl->display("cate/list.html");
  37. }
  38. function chk_f()
  39. {
  40. $this->cate_m->langid($_SESSION["sys_lang_id"]);
  41. $id = $this->trans_lib->int("id");
  42. $sign = $this->trans_lib->safe("sign");
  43. if(!$sign)
  44. {
  45. exit("error: 标识串为空");
  46. }
  47. //检测标识串是否符合要求
  48. if(!ereg("[a-z][a-z0-9\_]+",$sign))
  49. {
  50. exit("error: 标识串仅限小写英文字母,数字及下划线,且第一位必须是字母");
  51. }
  52. //检测唯一性
  53. $rs = $this->cate_m->chksign($sign,$id);
  54. if($rs)
  55. {
  56. exit("error: 标识串已被使用,请返回修改");
  57. }
  58. else
  59. {
  60. exit("ok");
  61. }
  62. }
  63. function set_f()
  64. {
  65. $order_list["post_date:desc"] = "最新发布排前";
  66. $order_list["post_date:asc"] = "最新发布排后";
  67. $order_list["modify_date:desc"] = "最新修改排前";
  68. $order_list["modify_date:asc"] = "最新修改排后";
  69. $order_list["replydate:desc"] = "最新回复排前";
  70. $order_list["replydate:asc"] = "最新回复排后";
  71. $order_list["hits:desc"] = "热门主题排前";
  72. $order_list["hits:asc"] = "冷门主题排前";
  73. $this->tpl->assign("order_list",$order_list);
  74. $id = $this->trans_lib->int("id");
  75. $tmp_popedom = $id ? $this->module_sign.":modify" : $this->module_sign.":add";
  76. sys_popedom($tmp_popedom,"tpl");//判断是否有相应的权限
  77. unset($tmp_popedom);
  78. $cateid = $this->trans_lib->int("cateid");
  79. if($cateid)
  80. {
  81. $p_rs = $this->cate_m->get_one($cateid);
  82. $mid = $p_rs["module_id"];
  83. }
  84. else
  85. {
  86. $mid = $this->trans_lib->int("mid");
  87. }
  88. if(!$id && !$mid)
  89. {
  90. //取得模块列表
  91. $modulelist = $this->module_m->module_list();
  92. $this->tpl->assign("modulelist",$modulelist);
  93. $this->tpl->display("cate/set_module.html");
  94. exit;
  95. }
  96. if($id)
  97. {
  98. $rs = $this->cate_m->get_one($id);
  99. $rs["note"] = $this->trans_lib->html_fck($rs["note"]);
  100. $this->tpl->assign("rs",$rs);
  101. $mid = $rs["module_id"];
  102. $cateid = $rs["parentid"];//父分类ID
  103. //如果有扩展字段
  104. if($rs["fields"])
  105. {
  106. $extlist = sys_id_list($rs["fields"]);
  107. $this->tpl->assign("extlist",$extlist);
  108. }
  109. }
  110. $this->tpl->assign("mid",$mid);
  111. //取得模块下的分类
  112. $this->cate_m->langid($_SESSION["sys_lang_id"]);
  113. $this->cate_m->get_catelist($mid);
  114. if(!$id)
  115. {
  116. $cate_html = $this->cate_m->html_select("cateid",$cateid,"设为根分类");
  117. }
  118. else
  119. {
  120. if($rs["parentid"])
  121. {
  122. $cate_html = $this->cate_m->html_select("cateid",$cateid,"",$cateid);
  123. }
  124. else
  125. {
  126. $cate_html = "<select name='cateid' id='cateid'><option value='0'>根分类不允许修改</option></select>";
  127. }
  128. }
  129. $this->tpl->assign("cate_html",$cate_html);
  130. //读取模块信息
  131. $m_rs = $this->module_m->get_one($mid);
  132. $this->tpl->assign("m_rs",$m_rs);
  133. //关联图片类型
  134. $this->load_model("gdtype");
  135. $gdlist = $this->gdtype_m->get_all();
  136. $this->tpl->assign("gdlist",$gdlist);
  137. //取得模块中的扩展字段
  138. $keylist = $this->module_m->fields_index($mid);
  139. $this->tpl->assign("keylist",$keylist);
  140. $this->tpl->display("cate/set.html");
  141. }
  142. //存储分类信息
  143. function setok_f()
  144. {
  145. $id = $this->trans_lib->int("id");
  146. $array = array();
  147. $array["cate_name"] = $this->trans_lib->safe("cate_name");
  148. $array["identifier"] = $this->trans_lib->safe("identifier");
  149. $tmp_popedom = $id ? $this->module_sign.":modify" : $this->module_sign.":add";
  150. sys_popedom($tmp_popedom,"tpl");//判断是否有相应的权限
  151. unset($tmp_popedom);
  152. $parentid = $this->trans_lib->int("cateid");
  153. if(!$id)
  154. {
  155. $mid = $this->trans_lib->int("mid");
  156. if(!$mid)
  157. {
  158. error("没有指到模块ID!",$this->url("cate,set"));
  159. }
  160. $array["module_id"] = $mid;
  161. $array["langid"] = $_SESSION["sys_lang_id"];
  162. $array["parentid"] = $parentid;
  163. }
  164. $array["tpl_index"] = $this->trans_lib->safe("tpl_index");
  165. $array["tpl_list"] = $this->trans_lib->safe("tpl_list");
  166. $array["tpl_file"] = $this->trans_lib->safe("tpl_file");
  167. $array["if_index"] = isset($_POST["if_index"]) ? 1 : 0;
  168. $array["status"] = isset($_POST["status"]) ? 1 : 0;
  169. $array["taxis"] = $this->trans_lib->int("taxis");
  170. $array["if_hidden"] = $this->trans_lib->int("if_hidden");
  171. $array["keywords"] = $this->trans_lib->safe("keywords");
  172. $array["description"] = $this->trans_lib->safe("description");
  173. $array["note"] = $this->trans_lib->html("note");
  174. $array["ifspec"] = $this->trans_lib->safe("ifspec");//开启/关闭分类为单页
  175. $array["inpic"] = $this->trans_lib->safe("inpic");//读取默认图片
  176. $array["psize"] = $this->trans_lib->int("psize");
  177. if($array["psize"]<1)
  178. {
  179. $array["psize"] = 30;
  180. }
  181. $array["target"] = $this->trans_lib->int("target");
  182. $array["linkurl"] = $this->trans_lib->safe("linkurl");
  183. $array["ordertype"] = $this->trans_lib->safe("ordertype");
  184. $array["subcate"] = $this->trans_lib->safe("subcate");
  185. $array["ico"] = $this->trans_lib->safe("ico");//图标
  186. $array["small_pic"] = $this->trans_lib->safe("small_pic");//小图
  187. $array["medium_pic"] = $this->trans_lib->safe("medium_pic");//中图
  188. $array["big_pic"] = $this->trans_lib->safe("big_pic");//大图
  189. //$array["taxis_asc"] = $this->trans_lib->checkbox("taxis_asc");//自定义排序从小排到大
  190. //存储要显示的扩展字段
  191. $extlist = $this->trans_lib->safe("extlist");
  192. //echo "<pre>".print_r($extlist,true)."</pre>";
  193. //exit;
  194. $array["fields"] = sys_id_string($extlist);
  195. //存储分类信息
  196. $this->cate_m->save($array,$id);
  197. if(!$id)
  198. {
  199. error("分类信息添加成功!",$this->url("cate","mid=".$mid));
  200. }
  201. else
  202. {
  203. //判断如果更改了父分类信息
  204. $rs = $this->cate_m->get_one($id);
  205. if($rs["parentid"] && $parentid && $rs["parentid"] != $parentid && $parentid != $id)
  206. {
  207. $update_array = array();
  208. $update_array["parentid"] = $parentid;
  209. $this->cate_m->save($update_array,$id);
  210. }
  211. //更新下级分类下的字段配置
  212. $next_fields_ok = $this->trans_lib->checkbox("next_fields_ok");
  213. if($next_fields_ok)
  214. {
  215. $this->cate_m->update_son_fields($array["fields"],$id);
  216. }
  217. error("分类信息更新操作成功",$this->url("cate","mid=".$rs["module_id"]));
  218. }
  219. }
  220. function ajax_status_f()
  221. {
  222. $id = $this->trans_lib->int("id");
  223. if(!$id)
  224. {
  225. exit("error:没有指定ID");
  226. }
  227. sys_popedom($this->module_sign.":check","ajax");
  228. $rs = $this->cate_m->get_one($id);
  229. $status = $rs["status"] ? 0 : 1;
  230. $this->cate_m->set_status($id,$status);
  231. exit("ok");
  232. }
  233. function ajax_del_f()
  234. {
  235. $id = $this->trans_lib->int("id");
  236. if(!$id)
  237. {
  238. exit("error:没有指定ID");
  239. }
  240. sys_popedom($this->module_sign.":delete","ajax");
  241. $rs = $this->cate_m->chk_son($id);
  242. if($rs)
  243. {
  244. exit("error: 对不起,您要删除的分类带有子分类,不允许删除");
  245. }
  246. //检测是否有内容
  247. unset($rs);
  248. $rs = $this->cate_m->chk_msg($id);
  249. if($rs)
  250. {
  251. exit("error: 对不起,您要删除的分类已经有内容了,不允许删除");
  252. }
  253. $this->cate_m->del($id);
  254. exit("ok");
  255. }
  256. function to_pinyin_f()
  257. {
  258. $title = $this->trans_lib->safe("title");
  259. if(!$title)
  260. {
  261. exit("false");
  262. }
  263. //加载拼音控件
  264. $this->load_lib("pingyin");
  265. $title = $this->trans_lib->charset($title,"UTF-8","GBK");
  266. $rs = $this->pingyin_lib->c($title);
  267. if(!$rs)
  268. {
  269. exit("false");
  270. }
  271. $rs = strtolower($rs);
  272. $rs = str_replace(" ","_",$rs);
  273. exit($rs);
  274. }
  275. function ajax_psize_f()
  276. {
  277. $id = $this->trans_lib->int("id");
  278. $val = $this->trans_lib->int("val");
  279. sys_popedom($this->module_sign.":modify","ajax");
  280. if(!$id)
  281. {
  282. exit("没有指定ID!");
  283. }
  284. $array = array();
  285. $array["psize"] = $val;
  286. $this->cate_m->save($array,$id);
  287. exit("ok");
  288. }
  289. function ajax_taxis_f()
  290. {
  291. $id = $this->trans_lib->int("id");
  292. $val = $this->trans_lib->int("val");
  293. sys_popedom($this->module_sign.":modify","ajax");
  294. if(!$id)
  295. {
  296. exit("没有指定ID!");
  297. }
  298. $array = array();
  299. $array["taxis"] = $val;
  300. $this->cate_m->save($array,$id);
  301. exit("ok");
  302. }
  303. }
  304. ?>