lang.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <?php
  2. class lang_c extends Control
  3. {
  4. var $module_sign = "lang";
  5. function __construct()
  6. {
  7. parent::Control();
  8. $this->load_model("lang");
  9. }
  10. function lang_c()
  11. {
  12. $this->__construct();
  13. }
  14. function index_f()
  15. {
  16. sys_popedom($this->module_sign.":list","tpl");
  17. $rslist = $this->lang_m->get_list();
  18. $this->tpl->assign("rslist",$rslist);
  19. $this->tpl->display("lang/list.html");
  20. }
  21. function list_f()
  22. {
  23. $id = $this->trans_lib->safe("id");
  24. if(!$id)
  25. {
  26. error("操作非法,没有指定ID",site_url('lang'));
  27. }
  28. sys_popedom($this->module_sign.":list","tpl");
  29. $rs = $this->lang_m->get_one($id);
  30. $this->tpl->assign("rs",$rs);
  31. $tmplist = $this->lang_m->lang_list($id);
  32. if(!$tmplist) $tmplist = array();
  33. $rslist = !$rs["ifsystem"] ? $this->lang_m->lang_list("",1) : $tmplist;
  34. $tlist = array();
  35. foreach($tmplist AS $key=>$value)
  36. {
  37. $tlist[$value["var"]] = $value["val"];
  38. }
  39. if(!$rslist) $rslist = array();
  40. foreach($rslist AS $key=>$value)
  41. {
  42. if($tlist[$value["var"]])
  43. {
  44. $value["val"] = $tlist[$value["var"]]; //替换新版
  45. }
  46. if($value["val"])
  47. {
  48. $value["val"] = str_replace("&","&amp;",$value["val"]);
  49. $value["val"] = str_replace("'","&#39;",$value["val"]);
  50. $value["val"] = str_replace('"',"&quot;",$value["val"]);
  51. $value["val"] = str_replace("<","&lt;",$value["val"]);
  52. $value["val"] = str_replace(">","&gt;",$value["val"]);
  53. }
  54. $rslist[$key] = $value;
  55. }
  56. $this->tpl->assign("rslist",$rslist);
  57. $ltype_array = array("all"=>"全局","www"=>"前台","admin"=>"后台");
  58. $this->tpl->assign("ltype",$ltype_array);
  59. $this->tpl->display("lang/lang.html");
  60. }
  61. function ajax_setok_f()
  62. {
  63. $id = $this->trans_lib->int("id");
  64. $array = array();
  65. $array["val"] = $this->trans_lib->safe("val");
  66. if(!$array["val"])
  67. {
  68. exit("error: 值不允许为空");
  69. }
  70. $array["val"] = str_replace("&gt;",">",$array["val"]);
  71. $array["val"] = str_replace("&lt;","<",$array["val"]);
  72. $array["val"] = str_replace("&quot;",'"',$array["val"]);
  73. $array["val"] = str_replace("&#39;","'",$array["val"]);
  74. $array["val"] = str_replace("&amp;","&",$array["val"]);
  75. if($id)
  76. {
  77. $langid = $this->trans_lib->safe("langid");
  78. sys_popedom($this->module_sign.":modify","ajax");
  79. //读取ID信息
  80. $rs = $this->lang_m->lang_one($id);
  81. if(!$rs)
  82. {
  83. exit("error: 找不到相关变量信息!");
  84. }
  85. if($rs["langid"] != $langid)
  86. {
  87. $tmp_rs = $this->lang_m->lang_one_var($rs["var"],$langid);
  88. if($tmp_rs)
  89. {
  90. $this->lang_m->save_m($array,$tmp_rs["id"]);
  91. }
  92. else
  93. {
  94. $array["langid"] = $langid;
  95. $array["ltype"] = $rs["ltype"];
  96. $array["var"] = $rs["var"];
  97. $this->lang_m->save_m($array);
  98. }
  99. }
  100. else
  101. {
  102. $this->lang_m->save_m($array,$id);
  103. }
  104. exit("ok");
  105. }
  106. else
  107. {
  108. sys_popedom($this->module_sign.":add","ajax");
  109. $array["langid"] = $this->trans_lib->safe("langid");
  110. $array["ltype"] = $this->trans_lib->safe("ltype");
  111. $array["var"] = $this->trans_lib->safe("var");
  112. if(!$array["langid"] || !$array["ltype"] || !$array["var"])
  113. {
  114. exit("error: 操作非法,数据不完整");
  115. }
  116. $chk = $this->lang_m->chk_msg($array["var"],$array["langid"],$array["ltype"]);
  117. if($chk)
  118. {
  119. exit("error: 变量名已经存在");
  120. }
  121. $this->lang_m->save_m($array);
  122. exit("ok");
  123. }
  124. }
  125. function set_f()
  126. {
  127. $id = $this->trans_lib->safe("id");
  128. if($id)
  129. {
  130. sys_popedom($this->module_sign.":modify","tpl");
  131. $rs = $this->lang_m->get_one($id);
  132. $this->tpl->assign("rs",$rs);
  133. }
  134. else
  135. {
  136. sys_popedom($this->module_sign.":add","tpl");
  137. }
  138. $this->tpl->display("lang/set.html");
  139. }
  140. //信息存储
  141. function setok_f()
  142. {
  143. $id = $this->trans_lib->safe("id");
  144. $array = array();
  145. $array["title"] = $this->trans_lib->safe("title");
  146. if($id)
  147. {
  148. sys_popedom($this->module_sign.":modify","tpl");
  149. }
  150. else
  151. {
  152. sys_popedom($this->module_sign.":add","tpl");
  153. $array["langid"] = $this->trans_lib->safe("langid");
  154. if(!$array["langid"])
  155. {
  156. error("操作非法,没有指定语言ID",site_url("lang"));
  157. }
  158. }
  159. $array["note"] = $this->trans_lib->safe("note");
  160. $array["taxis"] = $this->trans_lib->int("taxis");
  161. $array["ico"] = $this->trans_lib->safe("ico");//图标
  162. $array["small_pic"] = $this->trans_lib->safe("small_pic");//小图
  163. $array["medium_pic"] = $this->trans_lib->safe("medium_pic");//中图
  164. $array["big_pic"] = $this->trans_lib->safe("big_pic");//大图
  165. //存储分类信息
  166. $this->lang_m->save($array,$id);
  167. error("语言包信息配置成功",site_url("lang"));
  168. }
  169. function ajax_status_f()
  170. {
  171. $id = $this->trans_lib->safe("id");
  172. if(!$id)
  173. {
  174. exit("error:没有指定ID");
  175. }
  176. sys_popedom($this->module_sign.":check","ajax");
  177. $rs = $this->lang_m->get_one($id);
  178. $status = $rs["status"] ? 0 : 1;
  179. $this->lang_m->set_status($id,$status);
  180. exit("ok");
  181. }
  182. function ajax_default_f()
  183. {
  184. $id = $this->trans_lib->safe("id");
  185. if(!$id)
  186. {
  187. exit("error:没有指定ID");
  188. }
  189. sys_popedom($this->module_sign.":check","ajax");
  190. $this->lang_m->set_default($id);
  191. exit("ok");
  192. }
  193. function ajax_del_f()
  194. {
  195. $id = $this->trans_lib->safe("id");
  196. if(!$id)
  197. {
  198. exit("error:没有指定ID");
  199. }
  200. sys_popedom($this->module_sign.":delete","ajax");
  201. $rs = $this->lang_m->get_one($id);
  202. if($rs["ifsystem"])
  203. {
  204. exit("error: 对不起,系统语言包不允许删除");
  205. }
  206. if($rs["ifdefault"])
  207. {
  208. exit("error: 对不起,默认语言包不允许删除");
  209. }
  210. $this->lang_m->del($id);
  211. exit("ok");
  212. }
  213. function ajax_lang_del_f()
  214. {
  215. $id = $this->trans_lib->int("id");
  216. if(!$id)
  217. {
  218. exit("error:没有指定ID");
  219. }
  220. sys_popedom($this->module_sign.":delete","ajax");
  221. $rs = $this->lang_m->lang_one($id);
  222. if(!$rs)
  223. {
  224. exit("error:没有找到相关数据!");
  225. }
  226. $this->lang_m->del_m($rs["var"]);
  227. exit("ok");
  228. }
  229. function ajax_chk_f()
  230. {
  231. $id = $this->trans_lib->safe("id");
  232. if(!$id)
  233. {
  234. exit("error: 检测失败,没有指定ID");
  235. }
  236. if(!ereg("[a-z]+",$id))
  237. {
  238. exit("error: 语言ID只能用字母表示");
  239. }
  240. $rs = $this->lang_m->get_one($id);
  241. if($rs)
  242. {
  243. exit("error: 对不起,当前语言包变量已经被使用!");
  244. }
  245. exit("ok");
  246. }
  247. }
  248. ?>