/** * 新增与更新数据 *@param $act add为新增、edit为编辑 *@param $go 为1时,获取post *@param $id 传人数据id *@examlpe */ public function add($act = NULL, $go = false, $id = NULL) { $app = A('App', 'Public'); import('ORG.Net.FileSystem'); $sys = new FileSystem(); import('ORG.Net.UploadFile'); $up = new UploadFile(); $arr_type = C('UPLOAD_TYPE'); $arr_type = explode(',', $arr_type); $up->allowExts = $arr_type; $upload = C('TMPL_PARSE_STRING.__UPLOAD__'); $up->savePath = ROOT . '/' . $upload . '/'; $up->maxSize = C('UPLOAD_SIZE'); $up->charset = 'UTF-8'; $up->autoSub = true; $up->allowNull = true; //main $Bug = D('Bug_table'); $userid = $_SESSION['login']['se_id']; $username = $_SESSION['login']['se_user']; if ($go == false) { $this->assign('uniqid', uniqid()); if ($act == 'add') { $this->assign('act', 'add'); $this->display(); } else { if (!is_int((int) $id)) { $id = NULL; $this->show('无法获取ID'); } else { $map['id'] = array('eq', $id); $info = $Bug->relation(true)->where($map)->find(); $this->assign('constr', $constr); $constr = ''; $this->assign('id', $id); $this->assign('act', 'edit'); $this->assign('info', $info); $this->display(); unset($info, $uinfo, $map); } } } else { $data = $Bug->create(); $content = $_POST['content']; $fulltext = strip_tags($content); $fulltext = preg_replace("/[\n\r\t\v]/iu", "", $fulltext); $fulltext = pinyin($fulltext, ' '); $fulltext = preg_replace("/\\s+/u", " ", $fulltext); $fulltext = trim($fulltext); $solution = $_POST['solution']; $data['baseinfo'] = array('content' => $content, 'solution' => $solution); $data['fulltext'] = array('content_index' => $fulltext); $ischg = 0; if ($up->upload()) { $info = $up->getUploadFileInfo(); $data['files'] = $info[0]['savename']; $ischg = 1; } else { $errorNo = $up->getErrorNo(); if ($errorNo != 2) { echo $info = $up->getErrorMsg(); exit; } } if ($act == 'add') { $Public = A('Index', 'Public'); $role = $Public->check('Bug', array('c')); if ($role < 0) { echo $role; exit; } $data['user_id'] = $userid; $data['addtime'] = date("Y-m-d H:i:s", time()); $add = $Bug->relation(true)->add($data); if ($add > 0) { echo 1; } else { $path = ROOT . '/' . $upload . '/' . $info[0]['savename']; if ($info[0]['savename'] && file_exists($path)) { $sys->delFile($path); } echo 0; } unset($data, $Public); } elseif ($act == 'edit') { $Public = A('Index', 'Public'); $role = $Public->check('Bug', array('u')); if ($role < 0) { echo $role; exit; } if (!is_int((int) $id)) { echo 0; } else { if ($role != 'all' && !in_array('a', $role)) { $user_id = $Bug->where('id=' . $id)->getField('user_id'); if ($userid != $user_id) { echo 2; exit; } } if ($ischg == 1) { $oldfile = I('oldfile'); $path = ROOT . '/' . $upload . '/' . $oldfile; if ($oldfile && file_exists($path)) { $sys->delFile($path); } } $map['id'] = array('eq', $id); $edit = $Bug->relation(true)->where($map)->save($data); unset($map); if ($edit !== false) { echo 1; } else { echo 0; } unset($data, $Public); } } } unset($Bug); }
/** * 上传附件 *@param $id 数据id值 *@examlpe */ public function upfile($id) { $Public = A('Index', 'Public'); $Log = A('Log', 'Public'); $role = $Public->check('Report', array('c')); if ($role < 0) { echo $role; exit; } import('ORG.Net.FileSystem'); $sys = new FileSystem(); import('ORG.Net.UploadFile'); $up = new UploadFile(); $arr_type = C('UPLOAD_TYPE'); $arr_type = explode(',', $arr_type); $up->allowExts = $arr_type; $upload = C('TMPL_PARSE_STRING.__UPLOAD__'); $up->savePath = ROOT . '/' . $upload . '/'; $up->maxSize = C('UPLOAD_SIZE'); $up->charset = 'UTF-8'; $up->autoSub = true; $up->allowNull = true; //main $files_table = M('Report_files_table'); $report_table = M('Report_table'); $rid = intval($id); $uid = $_SESSION['login']['se_id']; $username = $_SESSION['login']['se_user']; $report = $report_table->where('id=' . $rid)->find(); if ($up->upload()) { $info = $up->getUploadFileInfo(); $data = array('rid' => $rid, 'user_id' => $uid, 'path' => $info[0]['savename'], 'addtime' => date("Y-m-d H:i:s", time())); $add = $files_table->add($data); } else { $errorNo = $up->getErrorNo(); if ($errorNo != 2) { echo $info = $up->getErrorMsg(); exit; } } if ($add > 0) { $descrtption = $username . '上传了关于BUG编号为:' . $report['bugno'] . '的附件'; $log_data = array('pro_id' => $report['pid'], 'descrtption' => $descrtption); $Log->actLog($log_data); echo 1; } else { echo 0; } }