123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <?php
- /**
- * 系统文章管理
- *
- *
- *
- ***/
- defined('InShopNC') or exit('Access Invalid!');
- class documentControl extends SystemControl{
- public function __construct(){
- parent::__construct();
- Language::read('document');
- }
- /**
- * 系统文章管理首页
- */
- public function indexOp(){
- $this->documentOp();
- exit;
- }
- /**
- * 系统文章列表
- */
- public function documentOp(){
- $model_doc = Model('document');
- $doc_list = $model_doc->getList();
- Tpl::output('doc_list',$doc_list);
- Tpl::showpage('document.index');
- }
- /**
- * 系统文章编辑
- */
- public function editOp(){
- $lang = Language::getLangContent();
- /**
- * 更新
- */
- if(chksubmit()){
- /**
- * 验证
- */
- $obj_validate = new Validator();
- $obj_validate->validateparam = array(
- array("input"=>$_POST["doc_title"], "require"=>"true", "message"=>$lang['document_index_title_null']),
- array("input"=>$_POST["doc_content"], "require"=>"true", "message"=>$lang['document_index_content_null'])
- );
- $error = $obj_validate->validate();
- if ($error != ''){
- showMessage($error);
- }else {
- $param = array();
- $param['doc_id'] = intval($_POST['doc_id']);
- $param['doc_title'] = trim($_POST['doc_title']);
- $param['doc_content']= trim($_POST['doc_content']);
- $param['doc_time'] = time();
- $model_doc = Model('document');
- $result = $model_doc->update($param);
- if ($result){
- /**
- * 更新图片信息ID
- */
- $model_upload = Model('upload');
- if (is_array($_POST['file_id'])){
- foreach ($_POST['file_id'] as $k => $v){
- $v = intval($v);
- $update_array = array();
- $update_array['upload_id'] = $v;
- $update_array['item_id'] = intval($_POST['doc_id']);
- $model_upload->update($update_array);
- unset($update_array);
- }
- }
- $url = array(
- array(
- 'url'=>'index.php?act=document&op=document',
- 'msg'=>$lang['document_edit_back_to_list']
- ),
- array(
- 'url'=>'index.php?act=document&op=edit&doc_id='.intval($_POST['doc_id']),
- 'msg'=>$lang['document_edit_again']
- ),
- );
- $this->log(L('nc_edit,document_index_document').'[ID:'.$_POST['doc_id'].']',1);
- showMessage($lang['nc_common_save_succ'],$url);
- }else {
- showMessage($lang['nc_common_save_fail']);
- }
- }
- }
- /**
- * 编辑
- */
- if(empty($_GET['doc_id'])){
- showMessage($lang['miss_argument']);
- }
- $model_doc = Model('document');
- $doc = $model_doc->getOneById(intval($_GET['doc_id']));
- /**
- * 模型实例化
- */
- $model_upload = Model('upload');
- $condition['upload_type'] = '4';
- $condition['item_id'] = $doc['doc_id'];
- $file_upload = $model_upload->getUploadList($condition);
- if (is_array($file_upload)){
- foreach ($file_upload as $k => $v){
- $file_upload[$k]['upload_path'] = UPLOAD_SITE_URL.'/'.ATTACH_ARTICLE.'/'.$file_upload[$k]['file_name'];
- }
- }
- Tpl::output('PHPSESSID',session_id());
- Tpl::output('file_upload',$file_upload);
- Tpl::output('doc',$doc);
- Tpl::showpage('document.edit');
- }
- /**
- * 系统文章图片上传
- */
- public function document_pic_uploadOp(){
- /**
- * 上传图片
- */
- $upload = new UploadFile();
- $upload->set('default_dir',ATTACH_ARTICLE);
- $result = $upload->upfile('fileupload');
- if ($result){
- $_POST['pic'] = $upload->file_name;
- }else {
- echo 'error';exit;
- }
- /**
- * 模型实例化
- */
- $model_upload = Model('upload');
- /**
- * 图片数据入库
- */
- $insert_array = array();
- $insert_array['file_name'] = $_POST['pic'];
- $insert_array['upload_type'] = '4';
- $insert_array['file_size'] = $_FILES['fileupload']['size'];
- $insert_array['item_id'] = intval($_POST['item_id']);
- $insert_array['upload_time'] = time();
- $result = $model_upload->add($insert_array);
- if ($result){
- $data = array();
- $data['file_id'] = $result;
- $data['file_name'] = $_POST['pic'];
- $data['file_path'] = $_POST['pic'];
- /**
- * 整理为json格式
- */
- $output = json_encode($data);
- echo $output;
- }
- }
- /**
- * ajax操作
- */
- public function ajaxOp(){
- switch ($_GET['branch']){
- /**
- * 删除文章图片
- */
- case 'del_file_upload':
- if (intval($_GET['file_id']) > 0){
- $model_upload = Model('upload');
- /**
- * 删除图片
- */
- $file_array = $model_upload->getOneUpload(intval($_GET['file_id']));
- @unlink(BASE_UPLOAD_PATH.DS.ATTACH_ARTICLE.DS.$file_array['file_name']);
- /**
- * 删除信息
- */
- $model_upload->del(intval($_GET['file_id']));
- echo 'true';exit;
- }else {
- echo 'false';exit;
- }
- break;
- }
- }
- }
|