ctrl.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. <?php
  2. class ctrl_c extends Control
  3. {
  4. var $module_sign = "module";
  5. function __construct()
  6. {
  7. parent::Control();
  8. $this->load_model("module");//读取模块列表
  9. }
  10. function ctrl_c()
  11. {
  12. $this->__construct();
  13. }
  14. function gset_f()
  15. {
  16. sys_popedom($this->module_sign.":group","tpl");
  17. $id = $this->trans_lib->int("id");
  18. if($id)
  19. {
  20. $this->tpl->assign("id",$id);
  21. $rs = $this->module_m->group_one($id);
  22. $this->tpl->assign("rs",$rs);
  23. }
  24. $this->tpl->display("ctrl/gset.html");
  25. }
  26. function gsetok_f()
  27. {
  28. sys_popedom($this->module_sign.":group","tpl");
  29. $id = $this->trans_lib->int("id");
  30. $array["title"] = $this->trans_lib->safe("title");
  31. $array["status"] = $this->trans_lib->int("status");
  32. $array["taxis"] = $this->trans_lib->int("taxis");
  33. $array["js_function"] = $this->trans_lib->safe("js_function");
  34. if(!$id)
  35. {
  36. $array["langid"] = $_SESSION["sys_lang_id"];
  37. }
  38. $this->module_m->group_save($array,$id);
  39. error("模块组编辑/添加成功!",$this->url("ctrl"));
  40. }
  41. function gdel_f()
  42. {
  43. sys_popedom($this->module_sign.":group","ajax");
  44. $id = $this->trans_lib->int("id");
  45. if(!$id)
  46. {
  47. exit("error:没有指定组ID");
  48. }
  49. $condition = array();
  50. $condition["groupid"] = $id;
  51. $condition["langid"] = $_SESSION["sys_lang_id"];
  52. $rslist = $this->module_m->get_list(0,$condition);
  53. if($rslist)
  54. {
  55. exit("error:模块组中有相应的模块信息,请先转移或删除!");
  56. }
  57. $this->module_m->group_del($id);
  58. exit("ok");
  59. }
  60. function index_f()
  61. {
  62. sys_popedom($this->module_sign.":list","tpl");
  63. $groupid = $this->trans_lib->int("groupid");
  64. $condition = array();
  65. if($groupid)
  66. {
  67. $condition["groupid"] = $groupid;
  68. $this->tpl->assign("groupid",$groupid);
  69. }
  70. $condition["langid"] = $_SESSION["sys_lang_id"];
  71. $pageid = $this->trans_lib->int(SYS_PAGEID);
  72. $rslist = $this->module_m->get_list($pageid,$condition);
  73. $this->tpl->assign("rslist",$rslist);
  74. $total = $this->module_m->get_count();//读取模块总数
  75. $page_url = $this->url("ctrl,index","groupid=".$groupid);
  76. $pagelist = $this->page_lib->page($page_url,$total);
  77. if($pagelist)
  78. {
  79. $this->tpl->assign("pagelist",$pagelist);
  80. }
  81. //获取所有模块
  82. $grouplist = $this->module_m->all_module_group();
  83. $this->tpl->assign("grouplist",$grouplist);
  84. $this->tpl->display("ctrl/list.html");
  85. }
  86. //更改状态
  87. function status_f()
  88. {
  89. $id = $this->trans_lib->int("id");
  90. if(!$id)
  91. {
  92. exit("error: 操作非法,没有指定ID");
  93. }
  94. sys_popedom($this->module_sign.":check","ajax");
  95. $rs = $this->module_m->get_one($id);
  96. if($rs["if_system"])
  97. {
  98. exit("error: 核心模块不允许此操作");
  99. }
  100. $this->module_m->status($id);
  101. exit("ok");
  102. }
  103. //删除模块
  104. function del_f()
  105. {
  106. $id = $this->trans_lib->int("id");
  107. if(!$id)
  108. {
  109. exit("error: 操作非法,没有指定ID");
  110. }
  111. sys_popedom($this->module_sign.":delete","ajax");
  112. //判断是否有内容
  113. $rs = $this->module_m->if_list($id);
  114. if($rs)
  115. {
  116. exit("error: 该模块已经有内容了,不允许删除");
  117. }
  118. //判断是否是核心模块,核心模块不允许删除
  119. $if_system = $this->module_m->if_system_module($id);
  120. if($if_system)
  121. {
  122. exit("error: 系统模块不允许删除");
  123. }
  124. //删除模块操作
  125. $this->module_m->del($id);
  126. exit("ok");
  127. }
  128. //编辑或添加模块
  129. function set_f()
  130. {
  131. $id = $this->trans_lib->int("id");
  132. $inc_module = array();
  133. $layout = array();
  134. if($id)
  135. {
  136. sys_popedom($this->module_sign.":modify","tpl");
  137. //[读取数据]
  138. $rs = $this->module_m->get_one($id);
  139. if($rs["inc_module"])
  140. {
  141. $inc_module = explode(",",$rs["inc_module"]);
  142. }
  143. //读取字段列表
  144. $tmp_list = $this->module_m->fields_index($id);
  145. if($tmp_list)
  146. {
  147. $mlist = array();
  148. foreach($tmp_list AS $key=>$value)
  149. {
  150. if($value["input"] != "edit") $mlist[] = $value;
  151. }
  152. unset($tmp_list);
  153. $this->tpl->assign("keylist",$mlist);
  154. }
  155. if($rs["layout"]) $layout = sys_id_list($rs["layout"]);
  156. }
  157. else
  158. {
  159. sys_popedom($this->module_sign.":add","tpl");
  160. $rs["popedom"] = array();
  161. }
  162. $this->tpl->assign("layout",$layout);
  163. $this->tpl->assign("inc_module",$inc_module);
  164. $this->tpl->assign("rs",$rs);
  165. //读取使用权限的字段
  166. $this->load_model("identifier");
  167. $popedom_list = $this->identifier_m->get_sign("popedom");
  168. $this->tpl->assign("popedom_list",$popedom_list);
  169. //取得模块组
  170. $group_list = $this->module_m->top();
  171. $this->tpl->assign("group_list",$group_list);
  172. //关联图片类型
  173. $this->load_model("gdtype");
  174. $gdlist = $this->gdtype_m->get_all();
  175. $this->tpl->assign("gdlist",$gdlist);
  176. $this->tpl->display("ctrl/set.html");
  177. }
  178. //存储信息
  179. function setok_f()
  180. {
  181. $id = $this->trans_lib->int("id");
  182. $array = array();
  183. $array["title"] = $this->trans_lib->safe("title");//模块名
  184. if(!$array["title"])
  185. {
  186. error("标题不允许为空",site_url("ctrl,set","id=".$id));
  187. }
  188. $array["group_id"] = $this->trans_lib->int("group_id");//组ID
  189. $array["note"] = $this->trans_lib->safe("note");//备注
  190. if(!$id)
  191. {
  192. sys_popedom($this->module_sign.":add","tpl");
  193. //在添加操作时核心参数的配置
  194. //判断标识符是否使用了
  195. $array["langid"] = $_SESSION["sys_lang_id"];//读取ID
  196. $array["identifier"] = $this->trans_lib->safe("identifier");//标识签,必须是唯一的
  197. if(!$array["identifier"])
  198. {
  199. error("标识串不允许为空",site_url("ctrl,set","id=".$id));
  200. }
  201. $chk_msg = $this->chk_identifier_f($array["identifier"]);
  202. if(!$chk_msg)
  203. {
  204. error("标识符不符合系统要求",site_url("ctrl,set","id=".$id));
  205. }
  206. //分析控制层是否符合系统要求
  207. $array["ctrl_init"] = $this->trans_lib->safe("ctrl_init");
  208. if(!$array["ctrl_init"])
  209. {
  210. $array["ctrl_init"] = $this->trans_lib->safe("ctrl_init_val");
  211. }
  212. if(!$array["ctrl_init"])
  213. {
  214. error("控制层配置为空,请检查",site_url("ctrl,set"));
  215. }
  216. if(!ereg("[a-z][a-z0-9\_]+",$array["ctrl_init"]))
  217. {
  218. error("控制层仅限字母,数字及下划线且要求必须是字母开头",site_url("ctrl,set"));
  219. }
  220. if(!file_exists(APP."control/".$array["ctrl_init"].".php"))
  221. {
  222. error("没有找到控制层文件:(",site_url("ctrl,set"));
  223. }
  224. }
  225. else
  226. {
  227. sys_popedom($this->module_sign.":modify","tpl");
  228. $rs = $this->module_m->get_one($id);
  229. $array["ctrl_init"] = $rs["ctrl_init"];
  230. }
  231. $array["taxis"] = $this->trans_lib->int("taxis");//排序
  232. if($array["ctrl_init"] == "list")
  233. {
  234. $array["if_cate"] = $this->trans_lib->int("if_cate");//是否分类支持
  235. $array["if_point"] = $this->trans_lib->int("if_point");//点数
  236. $array["if_thumb"] = $array["if_thumb_m"] = 0;
  237. $if_thumb = $this->trans_lib->int("if_thumb");
  238. if($if_thumb)
  239. {
  240. $array["if_thumb"] = 1;
  241. $array["if_thumb_m"] = $if_thumb == 2 ? 1 : 0;
  242. }
  243. $array["inpic"] = $this->trans_lib->safe("inpic");//读取默认图片
  244. $array["if_propety"] = $this->trans_lib->int("if_propety");
  245. $array["if_biz"] = $this->trans_lib->int("if_biz");//是否支持电子商务
  246. $array["if_url_m"] = $this->trans_lib->int("if_url_m");//第三方链接地址是否必填
  247. $array["insearch"] = $this->trans_lib->int("insearch");
  248. $array["if_content"] = $this->trans_lib->checkbox("if_content");//列表读内容
  249. $array["if_email"] = $this->trans_lib->int("if_email");//邮件通知
  250. $array["link_id"] = $this->trans_lib->int("link_id");//联动搜索
  251. $array["search_id"] = $this->trans_lib->safe("search_id");//联动搜索的字段
  252. $array["psize"] = $this->trans_lib->int("psize");//默认分页数量
  253. $array["if_subtitle"] = $this->trans_lib->int("if_subtitle");//是否启用副标题功能
  254. $array["tplset"] = $this->trans_lib->safe("tplset");//设定展示格式
  255. $array["title_nickname"] = $this->trans_lib->safe("title_nickname");
  256. $array["subtitle_nickname"] = $this->trans_lib->safe("subtitle_nickname");
  257. $array["sign_nickname"] = $this->trans_lib->safe("sign_nickname");
  258. $array["if_sign_m"] = $this->trans_lib->int("if_sign_m");//标识串是否必填
  259. $array["if_ext"] = $this->trans_lib->int("if_ext");
  260. $array["if_des"] = $this->trans_lib->int("if_des");
  261. $array["if_list"] = $this->trans_lib->int("if_list");
  262. $array["if_msg"] = $this->trans_lib->int("if_msg");
  263. $layout = $this->trans_lib->safe("layout");
  264. $array["layout"] = sys_id_string($layout);
  265. }
  266. else
  267. {
  268. $array["layout"] = "";
  269. }
  270. $array["ico"] = $this->trans_lib->safe("ico");//图标
  271. $array["small_pic"] = $this->trans_lib->safe("small_pic");//小图
  272. $array["medium_pic"] = $this->trans_lib->safe("medium_pic");//中图
  273. $array["big_pic"] = $this->trans_lib->safe("big_pic");//大图
  274. //读取权限配置信息
  275. $popedom = $this->trans_lib->safe("popedom");
  276. $array["popedom"] = $popedom ? implode(",",$popedom) : "";//收集权限
  277. $this->module_m->save($array,$id);
  278. Error("模块信息配置成功",site_url("ctrl"));
  279. }
  280. function chk_identifier_f($val="")
  281. {
  282. $exit = $val ? false : true;
  283. if(!$val)
  284. {
  285. $val = $this->trans_lib->safe("identifier");
  286. }
  287. if(!$val)
  288. {
  289. if($exit)
  290. {
  291. exit("error: 标识串为空");
  292. }
  293. else
  294. {
  295. return false;
  296. }
  297. }
  298. //判断这个标识符是否有被使用
  299. $if_used = $this->module_m->chk_identifier($val);
  300. if($if_used)
  301. {
  302. if($exit)
  303. {
  304. exit("error: 标识串已经被使用");
  305. }
  306. else
  307. {
  308. return false;
  309. }
  310. }
  311. //判断标识串是否符合要求
  312. if(!ereg("[a-z][a-z0-9\_]+",$val))
  313. {
  314. if($exit)
  315. {
  316. exit("error: 标识串仅限小写英文字母,数字及下划线,且第一位必须是字母");
  317. }
  318. else
  319. {
  320. return false;
  321. }
  322. }
  323. if($exit)
  324. {
  325. exit("ok");
  326. }
  327. else
  328. {
  329. return true;
  330. }
  331. }
  332. //字段管理列表
  333. function fields_f()
  334. {
  335. $id = $this->trans_lib->int("id");
  336. if(!$id)
  337. {
  338. error("操作非法,没有指定ID",site_url("ctrl"));
  339. }
  340. sys_popedom($this->module_sign.":list","tpl");
  341. $this->tpl->assign("id",$id);
  342. //读取字段管理
  343. $rslist = $this->module_m->fields_index($id);
  344. $this->tpl->assign("rslist",$rslist);
  345. //读取当前模块的配置信息
  346. $rs = $this->module_m->get_one($id);
  347. $this->tpl->assign("rs",$rs);
  348. $this->tpl->display("ctrl/fields.html");
  349. }
  350. //更改状态
  351. function fields_status_f()
  352. {
  353. $id = $this->trans_lib->int("id");
  354. if(!$id)
  355. {
  356. exit("error: 操作非法,没有指定ID");
  357. }
  358. sys_popedom($this->module_sign.":check","ajax");
  359. $this->module_m->fields_status($id);
  360. exit("ok");
  361. }
  362. //添加或删除一个字段
  363. function fields_set_f()
  364. {
  365. $id = $this->trans_lib->int("id");
  366. if($id)
  367. {
  368. sys_popedom($this->module_sign.":modify","tpl");
  369. $rs = $this->module_m->fields_one($id);
  370. $this->tpl->assign("rs",$rs);
  371. $this->tpl->assign("module_id",$rs["module_id"]);
  372. $module_id = $rs["module_id"];
  373. }
  374. else
  375. {
  376. sys_popedom($this->module_sign.":add","tpl");
  377. $module_id = $this->trans_lib->int("module_id");
  378. $this->tpl->assign("module_id",$module_id);
  379. }
  380. //读取模块信息
  381. $m_rs = $this->module_m->get_one($id);
  382. $this->tpl->assign("m_rs",$m_rs);
  383. $input_list = $this->module_m->input_type($_SESSION["sys_lang_id"]);
  384. $this->tpl->assign("input_list",$input_list);
  385. //关联模块
  386. $m_list = $this->module_m->all_module(1,"ctrl_init='list'");
  387. $this->tpl->assign("m_list",$m_list);
  388. //关联图片类型
  389. $this->load_model("gdtype");
  390. $gdlist = $this->gdtype_m->get_all();
  391. $this->tpl->assign("gdlist",$gdlist);
  392. $this->tpl->display("ctrl/fields_set.html");
  393. }
  394. //存储添加/编辑后的字段信息
  395. function fields_setok_f()
  396. {
  397. $id = $this->trans_lib->int("id");
  398. if($id)
  399. {
  400. sys_popedom($this->module_sign.":modify","tpl");
  401. $rs = $this->module_m->fields_one($id);
  402. $module_id = $rs["module_id"];
  403. }
  404. else
  405. {
  406. sys_popedom($this->module_sign.":add","tpl");
  407. $module_id = $this->trans_lib->int("module_id");
  408. }
  409. if(!$module_id)
  410. {
  411. error("操作非法",site_url("ctrl"));
  412. }
  413. if(!$id)
  414. {
  415. $array["module_id"] = $module_id;
  416. $array["identifier"] = $this->trans_lib->safe("identifier");
  417. if(!$array["identifier"])
  418. {
  419. error("标识串不允许为空",site_url("ctrl,fields_set","module_id=".$module_id));
  420. }
  421. //判断标识符是否使用了
  422. $chk_msg = $this->chk_identifier2_f($array["identifier"],$module_id);
  423. if(!$chk_msg)
  424. {
  425. error("标识符不符合系统要求",site_url("ctrl,fields_set","module_id=".$module_id));
  426. }
  427. $array["input"] = $this->trans_lib->safe("input");
  428. if($array["input"] == "edit")
  429. {
  430. $array["tbl"] = "c";
  431. }
  432. else
  433. {
  434. $array["tbl"] = "ext";
  435. }
  436. }
  437. $input_type = $id ? $rs["input"] : $array["input"];
  438. //
  439. $array["title"] = $this->trans_lib->safe("title");
  440. $array["if_post"] = $this->trans_lib->int("if_post");
  441. $array["if_guest"] = $this->trans_lib->int("if_guest");
  442. $array["sub_left"] = $this->trans_lib->safe("sub_left");
  443. $array["sub_note"] = $this->trans_lib->safe("sub_note");
  444. $array["width"] = $this->trans_lib->safe("width");
  445. $array["height"] = $this->trans_lib->safe("height");
  446. $array["default_val"] = $this->trans_lib->safe("default_val");
  447. if($input_type == "module")
  448. {
  449. $array["link_id"] = $this->trans_lib->safe("in_module_id");
  450. }
  451. else
  452. {
  453. $array["link_id"] = $this->trans_lib->int("link_id");
  454. }
  455. $array["list_val"] = $this->trans_lib->safe("list_val");
  456. $array["taxis"] = $this->trans_lib->int("taxis");
  457. $array["if_must"] = $this->trans_lib->int("if_must");
  458. $array["if_html"] = $this->trans_lib->int("if_html");
  459. $array["error_note"] = $this->trans_lib->safe("error_note");
  460. $array["show_html"] = $this->trans_lib->checkbox("show_html");
  461. $array["if_js"] = $this->trans_lib->checkbox("if_js");
  462. $array["if_search"] = $this->trans_lib->int("if_search");
  463. $this->module_m->fields_save($array,$id);
  464. error("字段数据配置成功",site_url("ctrl,fields","id=".$module_id));
  465. }
  466. function chk_identifier2_f($val="",$module_id=0)
  467. {
  468. $exit = $val ? false : true;
  469. if(!$val)
  470. {
  471. $val = $this->trans_lib->safe("identifier");
  472. }
  473. //取得模块ID
  474. if(!$module_id)
  475. {
  476. $module_id = $this->trans_lib->int("module_id");
  477. }
  478. if(!$val)
  479. {
  480. if($exit)
  481. {
  482. exit("error: 标识串为空");
  483. }
  484. else
  485. {
  486. return false;
  487. }
  488. }
  489. if(!$module_id)
  490. {
  491. if($exit)
  492. {
  493. exit("error: 没有指定模块ID");
  494. }
  495. else
  496. {
  497. return false;
  498. }
  499. }
  500. //判断这个标识符是否有被使用
  501. $if_used = $this->module_m->chk_identifier2($val,$module_id);
  502. if($if_used)
  503. {
  504. if($exit)
  505. {
  506. exit("error: 标识串已经被使用");
  507. }
  508. else
  509. {
  510. return false;
  511. }
  512. }
  513. //判断标识串是否符合要求
  514. if(!ereg("[a-z]+",$val))
  515. {
  516. if($exit)
  517. {
  518. exit("error: 标识串仅限小写英文字母,数字及下划线,且第一位必须是字母");
  519. }
  520. else
  521. {
  522. return false;
  523. }
  524. }
  525. if($exit)
  526. {
  527. exit("ok");
  528. }
  529. else
  530. {
  531. return true;
  532. }
  533. }
  534. function fields_del_f()
  535. {
  536. $id = $this->trans_lib->int("id");
  537. if(!$id)
  538. {
  539. exit("error: 操作非法,没有指定ID");
  540. }
  541. sys_popedom($this->module_sign.":delete","tpl");
  542. //删除模块操作
  543. $this->module_m->fields_del($id);
  544. exit("ok");
  545. }
  546. }
  547. ?>