Beispiel #1
0
 /**
  * 添加/编辑内容
  */
 public function action()
 {
     $field = \Model\Field::fieldList($this->model['model_id'], array('field_status' => '1'));
     $id = $this->g('id');
     if (empty($id)) {
         $this->assign('method', 'POST');
         $this->assign('title', "添加 - {$this->model['lang_key']}");
     } else {
         $content = \Model\Content::findContent($this->table, $id, "{$this->fieldPrefix}id");
         if (empty($content)) {
             $this->error('不存在的内容');
         }
         $this->assign($content);
         $this->assign('method', 'PUT');
         $this->assign('id', $id);
         $this->assign('title', "编辑 - {$this->model['lang_key']}");
         foreach ($field as $key => $value) {
             $field[$key] = $value;
             $field[$key]['value'] = $content["{$this->fieldPrefix}{$value['field_name']}"];
         }
     }
     $this->assign('field', $field);
     $this->assign('form', new \Expand\Form\Form());
     $this->display(is_file(THEME . '/' . GROUP . "/{$this->theme}/" . MODULE . '/' . MODULE . "_action.php") ? MODULE . "_action" : 'Content_action');
 }
Beispiel #2
0
 /**
  * 删除模型
  */
 public function action()
 {
     $modelId = $this->isG('id', '请选择要删除的数据!');
     $model = \Model\ModelManage::findModel($modelId);
     if (empty($model)) {
         $this->error('模型不存在');
     }
     $this->db()->transaction();
     $deleteModelResult = \Model\ModelManage::deleteModel($modelId);
     if (empty($deleteModelResult)) {
         $this->db()->rollBack();
         $this->error('删除模型失败');
     }
     $deleteModelField = \Model\Field::deleteModelField($modelId);
     if (empty($deleteModelField)) {
         $this->db()->rollBack();
         $this->error('移除模型字段记录失败');
     }
     $this->db('menu')->where('menu_name = :name')->delete(['name' => $model['model_title']]);
     $this->db()->commit();
     $alterTableResult = \Model\ModelManage::alterTable(strtolower($model['model_name']));
     if (empty($alterTableResult)) {
         $log = new \Expand\Log();
         $failLog = "Alter Model Table Field: {$this->prefix}{$model['model_name']}" . date("Y-m-d H:i:s");
         $log->creatLog('modelError', $failLog);
         $this->error('删除数据库表失败,具体信息请查阅程序日志');
     }
     $this->success('删除成功');
 }
 /**
  * 添加/编辑内容
  */
 public function action()
 {
     $field = \Model\Field::fieldList($this->model['model_id'], '1');
     $id = $this->g('id');
     if (empty($id)) {
         $this->assign('method', 'POST');
         $this->assign('title', "{$GLOBALS['_LANG']['CONTENT']['ADD']} - {$this->model['lang_key']}");
     } else {
         $content = \Model\Content::findContent($this->table, $id, "{$this->fieldPrefix}id");
         if (empty($content)) {
             $this->error($GLOBALS['_LANG']['CONTENT']['NOT_EXIST_CONTENT']);
         }
         $this->assign($content);
         $this->assign('method', 'PUT');
         $this->assign('id', $id);
         $this->assign('title', "{$GLOBALS['_LANG']['CONTENT']['EDIT']} - {$this->model['lang_key']}");
         foreach ($field as $key => $value) {
             $field[$key] = $value;
             $field[$key]['value'] = $content["{$this->fieldPrefix}{$value['field_name']}"];
         }
     }
     $this->assign('field', $field);
     $this->assign('form', new \Expand\Form\Form());
     $this->layout(is_file(THEME . '/' . GROUP . "/{$this->theme['value']}/" . MODULE . "_action.php") ? MODULE . "_action" : 'Content_action');
 }
Beispiel #4
0
 /**
  * 添加字段
  */
 public function fieldAction()
 {
     $result = \Model\Field::addField();
     if ($result['status'] == false) {
         $this->error($result['mes']);
     }
     $this->success($GLOBALS['_LANG']['MODEL']['ADD_FIELD_SUCCESS'], $this->url('Team-Model-fieldList', array('id' => $result['mes']['model_id'])));
 }
Beispiel #5
0
 public function action($jump = FALSE, $commit = true)
 {
     \Model\Field::baseForm();
     parent::action($jump, $commit);
     if (empty($_GET['back_url'])) {
         $url = $this->url(GROUP . '-Model-fieldList', array('id' => $this->p('id'), 'model_id' => \Model\Field::$model['model_id']));
     } else {
         $url = base64_decode($_GET['back_url']);
     }
     $this->success('更新字段成功', $url);
 }
Beispiel #6
0
 public function action($jump = FALSE, $commit = FALSE)
 {
     \Model\Field::baseForm();
     parent::action($jump, $commit);
     $filedID = $this->db()->getLastInsert;
     \Model\Field::addField($filedID);
     if (empty($_GET['back_url'])) {
         $url = $this->url(GROUP . '-Model-fieldList', array('id' => $filedID, 'model_id' => \Model\Field::$model['model_id']));
     } else {
         $url = base64_decode($_GET['back_url']);
     }
     $this->success('添加字段成功', $url);
 }
Beispiel #7
0
 public function __init()
 {
     parent::__init();
     //表名
     $this->table = strtolower(MODULE);
     //表前缀
     $this->fieldPrefix = $this->table . "_";
     $this->assign('fieldPrefix', $this->fieldPrefix);
     //验证模型是否存在
     $this->model = \Model\ModelManage::findModel($this->table, 'model_name');
     if (empty($this->model)) {
         $this->error('不存在的模型');
     }
     $this->modelThemePrefixPath = THEME_PATH . '/' . MODULE . '/' . MODULE;
     //获取模型的字段列表
     $fieldShowType = ACTION == 'index' ? 'field_list' : 'field_form';
     $this->field = \Model\Field::fieldList($this->model['model_id'], ['field_status' => '1', $fieldShowType => '1']);
 }
Beispiel #8
0
 /**
  * 内容列表
  */
 public function _list()
 {
     $catid = $this->isG('id', '请选择分类');
     $catid = $this->categorys[$catid]['category_child'];
     $orderBy = "{$this->model}_id DESC";
     $field = \Model\Field::fieldList($this->modelInfo['model_id'], array('field_status' => '1', 'field_list' => '1'));
     $condition = "{$this->model}_catid in ({$catid}) AND {$this->model}_status = 1";
     foreach ($field as $key => $value) {
         if (!empty($_GET)) {
             foreach ($_GET as $gk => $gv) {
                 if ($gk == $value['field_name']) {
                     $condition .= " AND {$this->model}_{$value['field_name']} = :{$value['field_name']} ";
                     $data[$value['field_name']] = "{$gv}";
                 }
             }
         }
         //判断是否存在排序字段
         if ($value['field_name'] == 'listsort') {
             $orderBy = "{$this->model}_listsort ASC, {$orderBy}";
         }
     }
     $page = new \Expand\Page();
     $total = count($this->db($this->model)->where($condition)->select($data));
     $count = $page->total($total);
     $page->handle();
     $list = $this->db($this->model)->where($condition)->order($orderBy)->limit("{$page->firstRow}, {$page->listRows}")->select($data);
     $show = $page->show();
     $this->assign('title', $this->categorys[$catid]['category_name']);
     $this->assign('keyword', $this->categorys[$catid]['category_keyword']);
     $this->assign('description', $this->categorys[$catid]['category_description']);
     $this->assign('page', $show);
     $this->assign('list', $list);
     if (empty($this->categorys[$catid]['theme'])) {
         $theme = MODULE . "_list";
         $themeFunc = 'layout';
     } else {
         $theme = $this->categorys[$catid]['theme'];
         $themeFunc = 'display';
     }
     $this->layout(is_file(THEME . '/' . GROUP . "/{$this->theme}/" . MODULE . "/{$theme}.php") ? $theme : 'Content_list');
 }
Beispiel #9
0
 /**
  * 删除字段
  */
 public function fieldAction()
 {
     $id = $this->isG('id', $GLOBALS['_LANG']['COMMON']['DELETE_ID']);
     $field = \Model\Field::findField($id);
     if (empty($field)) {
         $this->error($GLOBALS['_LANG']['MODEL']['NOT_EXIST_FIELD']);
     }
     $removeFieldResult = \Model\Field::removeField($id);
     if (empty($removeFieldResult)) {
         $this->error($GLOBALS['_LANG']['COMMON']['DELETE_ERROR']);
     }
     $model = \Model\Model::findModel($field['model_id']);
     $alertTableFieldResult = \Model\Field::alertTableField($model['model_name'], $field['field_name']);
     if (empty($alertTableFieldResult)) {
         $log = new \Expand\Log();
         $failLog = "Delete Field: " . strtolower($model['model_name']) . "_{$field['field_name']}, Model:{$model['model_name']}  " . date("Y-m-d H:i:s");
         $log->creatLog('fieldError', $failLog);
         $this->error($GLOBALS['_LANG']['MODEL']['ALERT_TABLE_FIELD_ERROR']);
     }
     $this->success($GLOBALS['_LANG']['COMMON']['DELETE_SUCCESS']);
 }
Beispiel #10
0
 public function action()
 {
     $id = $this->isG('id', '请选择要删除的数据!');
     $field = \Model\Field::findField($id);
     if (empty($field)) {
         $this->error('不存在的字段');
     }
     $removeFieldResult = \Model\Field::removeField($id);
     if (empty($removeFieldResult)) {
         $this->error('删除失败');
     }
     $model = \Model\ModelManage::findModel($field['field_model_id']);
     $alertTableFieldResult = \Model\Field::alertTableField($model['model_name'], $field['field_name']);
     if (empty($alertTableFieldResult)) {
         $log = new \Expand\Log();
         $failLog = "Delete Field: " . strtolower($model['model_name']) . "_{$field['field_name']}, Model:{$model['model_name']}  " . date("Y-m-d H:i:s");
         $log->creatLog('fieldError', $failLog);
         $this->error('移除数据库表字段失败,具体信息请查阅程序日志');
     }
     $this->success('删除成功');
 }
Beispiel #11
0
 /**
  * 字段添加/编辑
  */
 public function fieldAction()
 {
     $fieldId = $this->g('id');
     $modelId = $this->isG('model', '请选择模型');
     $model = \Model\ModelManage::findModel($modelId);
     if (empty($fieldId)) {
         $this->assign('method', 'POST');
         $this->assign('title', "添加字段 - {$model['lang_key']}");
     } else {
         $field = \Model\Field::findField($fieldId);
         if (empty($field)) {
             $this->error('不存在的字段');
         }
         $this->assign($field);
         $this->assign('method', 'PUT');
         $this->assign('title', "编辑字段 - {$model['lang_key']}");
     }
     $fieldTypeOption = \Model\Option::findOption('fieldType');
     $this->assign('fieldTypeList', json_decode($fieldTypeOption['value'], true));
     $this->assign('modelId', $modelId);
     $this->layout();
 }
Beispiel #12
0
 /**
  * 字段添加/编辑
  */
 public function fieldAction()
 {
     $fieldId = $this->g('id');
     $modelId = $this->isG('model', $GLOBALS['_LANG']['MODEL']['SELECT_MODEL_ID']);
     $model = \Model\Model::findModel($modelId);
     if (empty($fieldId)) {
         $this->assign('method', 'POST');
         $this->assign('title', $GLOBALS['_LANG']['MODEL']['FIELD_ADD'] . " - {$model['lang_key']}");
     } else {
         $field = \Model\Field::findField($fieldId);
         if (empty($field)) {
             $this->error($GLOBALS['_LANG']['MODEL']['NOT_EXIST_FIELD']);
         }
         $this->assign($field);
         $this->assign('method', 'PUT');
         $this->assign('title', "{$GLOBALS['_LANG']['MODEL']['FIELD_EDIT']} - {$model['lang_key']}");
     }
     $fieldTypeOption = \Model\Option::findOption('fieldType');
     $this->assign('fieldTypeList', json_decode($fieldTypeOption['value'], true));
     $this->assign('modelId', $modelId);
     $this->layout();
 }
Beispiel #13
0
 /**
  * 基础表单
  */
 public static function baseFrom()
 {
     self::$table = strtolower(MODULE);
     self::$fieldPrefix = self::$table . "_";
     self::$model = \Model\ModelManage::findModel(self::$table, 'model_name');
     $field = \Model\Field::fieldList(self::$model['model_id'], array('field_status' => '1'));
     if (self::p('method') == 'PUT') {
         $data['noset'][self::$fieldPrefix . 'id'] = self::isP('id', '丢失模型ID');
         if (!self::findContent(self::$table, $data['noset'][self::$fieldPrefix . 'id'], self::$fieldPrefix . 'id')) {
             self::error('不存在的模型');
         }
     }
     foreach ($field as $value) {
         /**
          * 判断提交的字段是否为数组
          */
         if (is_array($_POST[$value['field_name']])) {
             $_POST[$value['field_name']] = (string) implode(',', $_POST[$value['field_name']]);
         }
         /**
          * 时间转换为时间戳
          */
         if ($value['field_type'] == 'date') {
             $_POST[$value['field_name']] = (string) strtotime($_POST[$value['field_name']]);
         }
         if ($value['field_required'] == '1') {
             if (!($data[self::$fieldPrefix . $value['field_name']] = self::p($value['field_name'])) && !is_numeric($data[self::$fieldPrefix . $value['field_name']])) {
                 self::error($value['field_display_name'] . '为必填选项');
             }
         } else {
             if (!($data[self::$fieldPrefix . $value['field_name']] = self::p($value['field_name']))) {
                 $data[self::$fieldPrefix . $value['field_name']] = $value['field_default'];
             }
         }
     }
     return $data;
 }
Beispiel #14
0
 /**
  * 更新字段
  */
 public function fieldAction()
 {
     $result = \Model\Field::updateField();
     $this->success('更新字段成功', $this->url(GROUP . '-Model-fieldList', array('id' => $result['model_id'])));
 }
 /**
  * 基础表单
  */
 public static function baseFrom()
 {
     self::$table = strtolower(MODULE);
     self::$fieldPrefix = self::$table . "_";
     self::$model = \Model\Model::findModel(self::$table, 'model_name');
     $field = \Model\Field::fieldList(self::$model['model_id'], '1');
     if (self::p('method') == 'PUT') {
         if (!($data['noset'][self::$fieldPrefix . 'id'] = self::isP('id'))) {
             return self::error($GLOBALS['_LANG']['MODEL']['LOST_MODEL_ID']);
         }
         if (!self::findContent(self::$table, $data['noset'][self::$fieldPrefix . 'id'], self::$fieldPrefix . 'id')) {
             return self::error($GLOBALS['_LANG']['MODEL']['NOT_EXIST_MODEL']);
         }
     }
     foreach ($field as $value) {
         /**
          * 判断提交的字段是否为数组
          */
         if (is_array($_POST[$value['field_name']])) {
             $_POST[$value['field_name']] = (string) implode(',', $_POST[$value['field_name']]);
         }
         /**
          * 时间转换为时间戳
          */
         if ($value['field_type'] == 'date') {
             $_POST[$value['field_name']] = (string) strtotime($_POST[$value['field_name']]);
         }
         if ($value['field_required'] == '1') {
             if (!($data[self::$fieldPrefix . $value['field_name']] = self::isP($value['field_name'])) && !is_numeric($data[self::$fieldPrefix . $value['field_name']])) {
                 return self::error($value['display_name'] . $GLOBALS['_LANG']['COMMON']['REQUIRED']);
             }
         } else {
             if (!($data[self::$fieldPrefix . $value['field_name']] = self::p($value['field_name']))) {
                 $data[self::$fieldPrefix . $value['field_name']] = $value['field_default'];
             }
         }
     }
     return self::success($data);
 }
Beispiel #16
0
 /**
  * 菜单基础表单
  */
 public static function baseFrom()
 {
     $fieldPrefix = "user_";
     $model = \Model\Model::findModel('user', 'model_name');
     $field = \Model\Field::fieldList($model['model_id'], '1');
     if (self::p('method') == 'PUT') {
         if (!($data['noset']['user_id'] = self::isP('user_id'))) {
             return self::error($GLOBALS['_LANG']['USER']['LOST_USER_ID']);
         }
         if (!self::findUser($data['noset']['user_id'])) {
             return self::error($GLOBALS['_LANG']['USER']['NOT_EXITS_USER']);
         }
     } elseif (self::p('method') == 'POST') {
         $data['user_createtime'] = time();
     }
     foreach ($field as $value) {
         /**
          * 判断提交的字段是否为数组
          */
         if (is_array($_POST[$value['field_name']])) {
             $_POST[$fieldPrefix . $value['field_name']] = implode(',', $_POST[$fieldPrefix . $value['field_name']]);
         }
         /**
          * 时间转换为时间戳
          */
         if ($value['field_type'] == 'date') {
             $_POST[$fieldPrefix . $value['field_name']] = strtotime($_POST[$fieldPrefix . $value['field_name']]);
         }
         if ($value['field_required'] == '1') {
             if (!($data[$fieldPrefix . $value['field_name']] = self::isP($fieldPrefix . $value['field_name'])) && !is_numeric($data[$fieldPrefix . $value['field_name']])) {
                 return self::error($value['display_name'] . $GLOBALS['_LANG']['COMMON']['REQUIRED']);
             }
         } else {
             if (!($data[$fieldPrefix . $value['field_name']] = self::p($fieldPrefix . $value['field_name']))) {
                 $data[$fieldPrefix . $value['field_name']] = $value['field_default'];
             }
         }
     }
     /**
      * 先移除密码
      */
     unset($data['user_password']);
     if (self::p('user_password')) {
         $password = self::p('user_password');
         if ($password != self::p('confirm_password')) {
             return self::error($GLOBALS['_LANG']['USER']['CONFIRM_PASSWORD_ERROR']);
         }
         $data['user_password'] = \Core\Func\CoreFunc::generatePwd($data['user_account'] . $password, 'PRIVATE_KEY');
     } elseif (self::p('method') == 'POST' && !self::p('user_password')) {
         return self::error($GLOBALS['_LANG']['USER']['ENTER_PASSWORD']);
     }
     return self::success($data);
 }