/**
  * 生成
  *
  * @author          mrmsl <*****@*****.**>
  * @date            2013-05-14 11:30:05
  *
  * @return void 无返回值
  */
 public function buildAction()
 {
     $html_id = map_int(Filter::string($this->_pk_field), true);
     if (!$html_id) {
         $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L('PRIMARY_KEY,DATA,IS_EMPTY');
         trigger_error($log, E_USER_ERROR);
         $this->_ajaxReturn(false, L('BUILD,STATIC_PAGE,FAILURE'));
     }
     $caches = $this->cache();
     $error = '';
     $log = '';
     foreach ($html_id as $k => $v) {
         if (isset($caches[$v])) {
             $item = $caches[$v];
             $error .= $this->_build($item);
             $log .= ",{$item['tpl_name']}({$item[$this->_pk_field]})";
         } else {
             unset($html_id[$k]);
             $error .= ',id(' . $v . ')';
         }
     }
     $html_id && C('T_HTML_ID', $html_id);
     $log && C('T_LOG', $log);
     if ($error) {
         $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . $error . L('NOT_EXIST');
         trigger_error($log);
     }
     $this->_successAction();
 }
Beispiel #2
0
 /**
  * 生成
  *
  * @author          mrmsl <*****@*****.**>
  * @date            2013-05-14 11:30:05
  *
  * @return void 无返回值
  */
 public function buildAction()
 {
     $html_id = map_int(Filter::string($this->_pk_field), true);
     if (!$html_id) {
         $this->_model->addLog(L('PRIMARY_KEY,DATA,IS_EMPTY'), LOG_TYPE_INVALID_PARAM);
         $this->_ajaxReturn(false, L('BUILD,STATIC_PAGE,FAILURE'));
     }
     $caches = $this->_getCache();
     $error = '';
     $log = '';
     foreach ($html_id as $k => $v) {
         if (isset($caches[$v])) {
             $item = $caches[$v];
             $error .= $this->_build($item);
             $log .= ",{$item['tpl_name']}({$item[$this->_pk_field]})";
         } else {
             unset($html_id[$k]);
             $error .= ',id(' . $v . ')';
         }
     }
     $html_id && C('T_HTML_ID', $html_id);
     $log && C('T_LOG', $log);
     $error && $this->triggerError(__METHOD__ . ': ' . __LINE__ . ',' . $error . L('NOT_EXIST'));
     $this->_successAction();
 }
 /**
  * 添加或保存
  *
  * @author          mrmsl <*****@*****.**>
  * @lastmodify      2013-01-22 10:59:48 by mrmsl
  *
  * @return void 无返回值
  */
 public function addAction()
 {
     $check = $this->_model->startTrans()->checkCreate();
     //自动创建数据
     $check !== true && $this->_ajaxReturn(false, $check);
     //未通过验证
     $pk_field = $this->_pk_field;
     //主键
     $pk_value = $this->_model->{$pk_field};
     //角色id
     $this->_model->_priv_id = map_int($this->_model->_priv_id, true);
     //菜单权限
     $priv_id = $this->_model->_priv_id;
     $data = $this->_model->getProperty('_data');
     //数据,$model->data 在save()或add()后被重置为array()
     $diff_key = $this->_name_column . ',memo,sort_order';
     //比较差异字段
     $cache_data = $this->cache();
     if ($pk_value) {
         //编辑
         if ($pk_value == ADMIN_ROLE_ID && $this->_admin_info[$pk_field] != ADMIN_ROLE_ID) {
             //不可编辑指定角色。增加当前角色id判断 by mrmsl on 2012-07-05 08:50:27
             $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L('TRY,EDIT,CONTROLLER_NAME_ROLE') . "{$pk_field}: {$pk_value}";
             trigger_error($log, E_USER_ERROR);
             $this->_ajaxReturn(false, L('EDIT,FAILURE'));
         }
         if (!isset($cache_data[$pk_value])) {
             //角色不存在
             $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L("EDIT,CONTROLLER_NAME_ROLE,FAILURE,%: ,INVALID_PARAM,%:,CONTROLLER_NAME_ROLE,%{$pk_field}({$pk_value}),NOT_EXIST");
             trigger_error($log, E_USER_ERROR);
             $this->_ajaxReturn(false, L('EDIT,FAILURE'));
         }
         $role_info = $cache_data[$pk_value];
         if ($this->_model->save() === false) {
             //更新出错
             $this->_sqlErrorExit(L('EDIT,CONTROLLER_NAME_ROLE') . "{$role_info[$this->_name_column]}({$pk_value})" . L('FAILURE'), L('EDIT,FAILURE'));
         }
         $diff_priv = $this->diffRolePriv(array_keys($role_info['priv']), $priv_id);
         $diff = $this->_dataDiff($role_info, $data, $diff_key) . ($diff_priv['msg'] ? 'priv => ' . $diff_priv['msg'] : '');
         //差异
         //权限有变更
         $diff_priv['msg'] && $this->_model->setRolePriv($pk_value, $priv_id);
         //管理员操作日志
         $this->_model->addLog(L('EDIT,CONTROLLER_NAME_ROLE') . "{$role_info[$this->_name_column]}({$pk_value})." . $diff . L('SUCCESS'));
         $this->cache(null, null, null)->_ajaxReturn(true, L('EDIT,SUCCESS'));
     } else {
         $priv = $this->_getRolePriv($priv_id);
         $insert_data = "{$this->_name_column} => {$data[$this->_name_column]}, sort_order => " . (isset($data['sort_order']) ? $data['sort_order'] : -1) . " memo => {$data['memo']}" . ($priv['msg'] ? 'priv => ' . $priv['msg'] : '');
         //数据
         if (($insert_id = $this->_model->add()) === false) {
             //插入出错
             $this->_sqlErrorExit(L('ADD,CONTROLLER_NAME_ROLE') . $insert_data . L('FAILURE'), L('ADD,FAILURE'));
         }
         //权限
         $priv_id && $this->_model->setRolePriv($insert_id, $priv_id);
         $this->_model->addLog(L('ADD,CONTROLLER_NAME_ROLE') . $insert_data . L('SUCCESS'));
         $this->cache(null, null, null)->_ajaxReturn(true, L('ADD,SUCCESS'));
     }
 }
 /**
  * 清除缓存
  *
  * @author          mrmsl <*****@*****.**>
  * @date            2013-05-17 09:01:33
  *
  * @return void 无返回值
  */
 public function clearCacheAction()
 {
     $cate_id = Filter::string($pk_field = $this->_pk_field);
     $cate_id = map_int($cate_id, true);
     $cate_arr = $this->cache();
     if ($cate_id) {
         $error = '';
         $log = '';
         $template = $this->getViewTemplate();
         $name_column = $this->_name_column;
         $cache_path = $template->_cache_path . CONTROLLER_NAME . DS;
         foreach ($cate_id as $v) {
             if (isset($cate_arr[$v])) {
                 foreach (glob($cache_path . "index{$v}-*") as $filename) {
                     unlink($filename);
                 }
                 $log .= ",{$cate_arr[$v][$name_column]}({$v})";
             } else {
                 $error .= ',' . $v;
             }
         }
         if ($error) {
             $log_error = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L('CONTROLLER_NAME') . $error . L('NOT_EXIST');
             trigger_error($log_error);
         }
         if ($log) {
             $this->_model->addLog(L('CLEAR,CONTROLLER_NAME_CATEGORY,CACHE') . substr($log, 1) . L('SUCCESS'));
             $this->_ajaxReturn(true, L('CLEAR,SUCCESS'));
         } else {
             $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L('CLEAR,CONTROLLER_NAME_CATEGORY,CACHE,FAILURE,%: ,INVALID_PARAM,%:,CONTROLLER_NAME') . $error . L('NOT_EXIST');
             trigger_error($log, E_USER_ERROR);
         }
     }
     if (empty($error)) {
         $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L("CLEAR,CONTROLLER_NAME_CATEGORY,CACHE,FAILURE,%<br />,INVALID_PARAM,%:,CONTROLLER_NAME,%{$this->_pk_field},IS_EMPTY");
         trigger_error($log, E_USER_ERROR);
     }
     $this->_ajaxReturn(false, L('CLEAR,FAILURE'));
 }
 /**
  * 生成语言包
  *
  * @author          mrmsl <*****@*****.**>
  * @data            2013-06-21 16:03:22
  *
  * @return void 无返回值
  */
 public function buildAction()
 {
     if ($t_module_id = C('T_MODULE_ID')) {
         //$this->R()
         $module_id = $t_module_id;
     } else {
         $module_id = Filter::string($this->_pk_field);
     }
     if (!$module_id && null === $t_module_id) {
         $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L('PRIMARY_KEY,DATA,IS_EMPTY');
         trigger_error($log, E_USER_ERROR);
         $this->_ajaxReturn(false, L('BUILD,LANGUAGE_ITEM,CACHE,FAILURE'));
     }
     $module_id = 'all' == $module_id ? $this->_exclude_delete_id : map_int($module_id, true);
     if ($intersect = array_intersect($this->_exclude_delete_id, $module_id)) {
         //是否包含1,2,3
         foreach ($intersect as $v) {
             $module_id = array_merge($module_id, $this->_getChildrenIds($v, false, true));
         }
     }
     $module_id = array_unique($module_id);
     $modules = $this->cache();
     $error = '';
     $log = '';
     foreach ($module_id as $k => $v) {
         //验证语言模块
         if (isset($modules[$v])) {
             $item = $modules[$v];
             $log .= ",{$item['module_name']}({$item[$this->_pk_field]})";
         } else {
             unset($module_id[$k]);
             $error .= ',id(' . $v . ')';
         }
     }
     if (!$module_id && null === $t_module_id) {
         $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L('PRIMARY_KEY,DATA,IS_EMPTY');
         trigger_error($log, E_USER_ERROR);
         $this->_ajaxReturn(false, L('BUILD,LANGUAGE_ITEM,CACHE,FAILURE'));
     }
     $data = $this->_getBuildData($module_id);
     foreach ($data['php_data'] as $key => $content) {
         F($key, $content, LANG_PATH);
     }
     $this->_buildScriptItems($data['js_data']);
     if ($error) {
         $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . $error . L('NOT_EXIST');
         trigger_error($log);
     }
     if (null === $t_module_id) {
         $this->_model->addLog(L('BUILD,LANGUAGE_ITEM,CACHE') . $log . L('SUCCESS'));
         $this->_ajaxReturn(true, L('BUILD,SUCCESS'));
     }
 }
 /**
  * 后台删除博客,微博静态文件
  *
  * @author          mrmsl <*****@*****.**>
  * @date            2013-05-17 10:51:07
  *
  * @return void 无返回值
  */
 public function deleteBlogHtmlAction()
 {
     $pk_value = Filter::string($pk_field = $this->_pk_field);
     $pk_value = map_int($pk_value, true);
     if ($pk_value) {
         $error = '';
         $log = '';
         $name_column = empty($this->_name_column) ? '' : $this->_name_column;
         $field = $pk_field . ',link_url' . ($name_column ? ',' . $name_column : '');
         $data = $this->_model->field($field)->index($pk_field)->where(array($pk_field => array('IN', $pk_value)))->select();
         $delete = array();
         foreach ($pk_value as $v) {
             if (isset($data[$v])) {
                 $delete[] = array('link_url' => $data[$v]['link_url']);
                 $log .= ',' . ($name_column ? ",{$data[$v][$name_column]}({$v})" : $v);
             } else {
                 $error .= ',' . $v;
             }
         }
         if ($error) {
             $log_content = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L('CONTROLLER_NAME') . $error . L('NOT_EXIST');
             trigger_error($log_content, E_USER_ERROR);
         }
         if ($log) {
             $this->_deleteBlogHtml($delete);
             $this->_model->addLog(L('DELETE,CONTROLLER_NAME,STATIC_PAGE') . substr($log, 1) . L('SUCCESS'));
             $this->_ajaxReturn(true, L('DELETE,SUCCESS'));
         } else {
             $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L('DELETE,CONTROLLER_NAME,STATIC_PAGE,FAILURE,%: ,INVALID_PARAM,%:,CONTROLLER_NAME') . $error . L('NOT_EXIST');
             trigger_error($log, E_USER_ERROR);
         }
     }
     if (empty($error)) {
         $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L("DELETE,CONTROLLER_NAME,STATIC_PAGE,FAILURE,%: ,INVALID_PARAM,%:,CONTROLLER_NAME,%{$this->_pk_field},IS_EMPTY");
         trigger_error($log, E_USER_ERROR);
     }
     $this->_ajaxReturn(false, L('DELETE,FAILURE'));
 }