document.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. /**
  3. * 系统文章管理
  4. *
  5. *
  6. *
  7. ***/
  8. defined('InShopNC') or exit('Access Invalid!');
  9. class documentControl extends SystemControl{
  10. public function __construct(){
  11. parent::__construct();
  12. Language::read('document');
  13. }
  14. /**
  15. * 系统文章管理首页
  16. */
  17. public function indexOp(){
  18. $this->documentOp();
  19. exit;
  20. }
  21. /**
  22. * 系统文章列表
  23. */
  24. public function documentOp(){
  25. $model_doc = Model('document');
  26. $doc_list = $model_doc->getList();
  27. Tpl::output('doc_list',$doc_list);
  28. Tpl::showpage('document.index');
  29. }
  30. /**
  31. * 系统文章编辑
  32. */
  33. public function editOp(){
  34. $lang = Language::getLangContent();
  35. /**
  36. * 更新
  37. */
  38. if(chksubmit()){
  39. /**
  40. * 验证
  41. */
  42. $obj_validate = new Validator();
  43. $obj_validate->validateparam = array(
  44. array("input"=>$_POST["doc_title"], "require"=>"true", "message"=>$lang['document_index_title_null']),
  45. array("input"=>$_POST["doc_content"], "require"=>"true", "message"=>$lang['document_index_content_null'])
  46. );
  47. $error = $obj_validate->validate();
  48. if ($error != ''){
  49. showMessage($error);
  50. }else {
  51. $param = array();
  52. $param['doc_id'] = intval($_POST['doc_id']);
  53. $param['doc_title'] = trim($_POST['doc_title']);
  54. $param['doc_content']= trim($_POST['doc_content']);
  55. $param['doc_time'] = time();
  56. $model_doc = Model('document');
  57. $result = $model_doc->update($param);
  58. if ($result){
  59. /**
  60. * 更新图片信息ID
  61. */
  62. $model_upload = Model('upload');
  63. if (is_array($_POST['file_id'])){
  64. foreach ($_POST['file_id'] as $k => $v){
  65. $v = intval($v);
  66. $update_array = array();
  67. $update_array['upload_id'] = $v;
  68. $update_array['item_id'] = intval($_POST['doc_id']);
  69. $model_upload->update($update_array);
  70. unset($update_array);
  71. }
  72. }
  73. $url = array(
  74. array(
  75. 'url'=>'index.php?act=document&op=document',
  76. 'msg'=>$lang['document_edit_back_to_list']
  77. ),
  78. array(
  79. 'url'=>'index.php?act=document&op=edit&doc_id='.intval($_POST['doc_id']),
  80. 'msg'=>$lang['document_edit_again']
  81. ),
  82. );
  83. $this->log(L('nc_edit,document_index_document').'[ID:'.$_POST['doc_id'].']',1);
  84. showMessage($lang['nc_common_save_succ'],$url);
  85. }else {
  86. showMessage($lang['nc_common_save_fail']);
  87. }
  88. }
  89. }
  90. /**
  91. * 编辑
  92. */
  93. if(empty($_GET['doc_id'])){
  94. showMessage($lang['miss_argument']);
  95. }
  96. $model_doc = Model('document');
  97. $doc = $model_doc->getOneById(intval($_GET['doc_id']));
  98. /**
  99. * 模型实例化
  100. */
  101. $model_upload = Model('upload');
  102. $condition['upload_type'] = '4';
  103. $condition['item_id'] = $doc['doc_id'];
  104. $file_upload = $model_upload->getUploadList($condition);
  105. if (is_array($file_upload)){
  106. foreach ($file_upload as $k => $v){
  107. $file_upload[$k]['upload_path'] = UPLOAD_SITE_URL.'/'.ATTACH_ARTICLE.'/'.$file_upload[$k]['file_name'];
  108. }
  109. }
  110. Tpl::output('PHPSESSID',session_id());
  111. Tpl::output('file_upload',$file_upload);
  112. Tpl::output('doc',$doc);
  113. Tpl::showpage('document.edit');
  114. }
  115. /**
  116. * 系统文章图片上传
  117. */
  118. public function document_pic_uploadOp(){
  119. /**
  120. * 上传图片
  121. */
  122. $upload = new UploadFile();
  123. $upload->set('default_dir',ATTACH_ARTICLE);
  124. $result = $upload->upfile('fileupload');
  125. if ($result){
  126. $_POST['pic'] = $upload->file_name;
  127. }else {
  128. echo 'error';exit;
  129. }
  130. /**
  131. * 模型实例化
  132. */
  133. $model_upload = Model('upload');
  134. /**
  135. * 图片数据入库
  136. */
  137. $insert_array = array();
  138. $insert_array['file_name'] = $_POST['pic'];
  139. $insert_array['upload_type'] = '4';
  140. $insert_array['file_size'] = $_FILES['fileupload']['size'];
  141. $insert_array['item_id'] = intval($_POST['item_id']);
  142. $insert_array['upload_time'] = time();
  143. $result = $model_upload->add($insert_array);
  144. if ($result){
  145. $data = array();
  146. $data['file_id'] = $result;
  147. $data['file_name'] = $_POST['pic'];
  148. $data['file_path'] = $_POST['pic'];
  149. /**
  150. * 整理为json格式
  151. */
  152. $output = json_encode($data);
  153. echo $output;
  154. }
  155. }
  156. /**
  157. * ajax操作
  158. */
  159. public function ajaxOp(){
  160. switch ($_GET['branch']){
  161. /**
  162. * 删除文章图片
  163. */
  164. case 'del_file_upload':
  165. if (intval($_GET['file_id']) > 0){
  166. $model_upload = Model('upload');
  167. /**
  168. * 删除图片
  169. */
  170. $file_array = $model_upload->getOneUpload(intval($_GET['file_id']));
  171. @unlink(BASE_UPLOAD_PATH.DS.ATTACH_ARTICLE.DS.$file_array['file_name']);
  172. /**
  173. * 删除信息
  174. */
  175. $model_upload->del(intval($_GET['file_id']));
  176. echo 'true';exit;
  177. }else {
  178. echo 'false';exit;
  179. }
  180. break;
  181. }
  182. }
  183. }