public function edit() { $id = isset($_GET['id']) && intval($_GET['id']) ? intval($_GET['id']) : showmessage(L('illegal_parameters'), HTTP_REFERER); if (!($edit_data = $this->db->get_one(array('id' => $id)))) { showmessage(L('notfound')); } pc_base::load_app_func('global'); if (isset($_POST['dosubmit'])) { $name = isset($_POST['name']) && trim($_POST['name']) ? trim($_POST['name']) : showmessage(L('name') . L('empty')); $dis_type = isset($_POST['dis_type']) && intval($_POST['dis_type']) ? intval($_POST['dis_type']) : 1; $cache = isset($_POST['cache']) && intval($_POST['cache']) ? intval($_POST['cache']) : 0; $num = isset($_POST['num']) && intval($_POST['num']) ? intval($_POST['num']) : 0; $type = isset($_POST['type']) && intval($_POST['type']) ? intval($_POST['type']) : 0; //检查名称是否已经存在 if ($edit_data['name'] != $name) { if ($this->db->get_one(array('name' => $name), 'id')) { showmessage(L('name') . L('exists')); } } $sql = array(); if ($type == '1') { //自定义SQL $data = isset($_POST['data']) && trim($_POST['data']) ? trim($_POST['data']) : showmessage(L('custom_sql') . L('empty')); $sql = array('data' => $data); } else { //模型配置方式 $module = isset($_POST['module']) && trim($_POST['module']) ? trim($_POST['module']) : showmessage(L('please_select_model')); $action = isset($_POST['action']) && trim($_POST['action']) ? trim($_POST['action']) : showmessage(L('please_select_action')); $html = pc_tag_class($module); $data = array(); if (isset($html[$action]) && is_array($html[$action])) { foreach ($html[$action] as $key => $val) { $val['validator']['reg_msg'] = $val['validator']['reg_msg'] ? $val['validator']['reg_msg'] : $val['name'] . L('inputerror'); ${$key} = isset($_POST[$key]) && trim($_POST[$key]) ? trim($_POST[$key]) : ''; if (!empty($val['validator'])) { if (isset($val['validator']['min']) && strlen(${$key}) < $val['validator']['min']) { showmessage($val['name'] . L('should') . L('is_greater_than') . $val['validator']['min'] . L('lambda')); } if (isset($val['validator']['max']) && strlen(${$key}) > $val['validator']['max']) { showmessage($val['name'] . L('should') . L('less_than') . $val['validator']['max'] . L('lambda')); } if (!preg_match('/' . $val['validator']['reg'] . '/' . $val['validator']['reg_param'], ${$key})) { showmessage($val['name'] . $val['validator']['reg_msg']); } } $data[$key] = ${$key}; } } $sql = array('data' => array2string($data), 'module' => $module, 'action' => $action); } if ($dis_type == 3) { $sql['template'] = isset($_POST['template']) && trim($_POST['template']) ? trim($_POST['template']) : ''; } //初始化数据 $sql['name'] = $name; $sql['type'] = $type; $sql['dis_type'] = $dis_type; $sql['cache'] = $cache; $sql['num'] = $num; if ($this->db->update($sql, array('id' => $id))) { //当为JS时,输出模板文件 if ($dis_type == 3) { $tpl = pc_base::load_sys_class('template_cache'); $str = $tpl->template_parse($sql['template']); $filepath = CACHE_PATH . 'caches_template' . DIRECTORY_SEPARATOR . 'dbsource' . DIRECTORY_SEPARATOR; if (!is_dir($filepath)) { mkdir($filepath, 0777, true); } @file_put_contents($filepath . $id . '.php', $str); } showmessage('', '', '', 'edit'); } else { showmessage(L('operation_failure')); } } else { pc_base::load_sys_class('form', '', 0); $modules = array_merge(array('' => L('please_select')), pc_base::load_config('modules')); $show_header = $show_validator = true; $type = isset($_GET['type']) ? intval($_GET['type']) : $edit_data['type']; $module = isset($_GET['module']) && trim($_GET['module']) ? trim($_GET['module']) : $edit_data['module']; $action = isset($_GET['action']) && trim($_GET['action']) ? trim($_GET['action']) : $edit_data['action']; if ($edit_data['type'] == 0) { $form_data = string2array($edit_data['data']); } if ($module) { $html = pc_tag_class($module); } pc_base::load_app_func('global', 'template'); include $this->admin_tpl('data_edit'); } }
/** * 修改标签向导 */ public function edit() { $id = isset($_GET['id']) && intval($_GET['id']) ? intval($_GET['id']) : showmessage(L('illegal_parameters'), HTTP_REFERER); if (!($edit_data = $this->db->get_one(array('id' => $id)))) { showmessage(L('notfound')); } pc_base::load_app_func('global', 'dbsource'); if (isset($_POST['dosubmit'])) { $name = isset($_POST['name']) && trim($_POST['name']) ? trim($_POST['name']) : showmessage(L('name') . L('empty')); $cache = isset($_POST['cache']) && intval($_POST['cache']) ? intval($_POST['cache']) : 0; $num = isset($_POST['num']) && intval($_POST['num']) ? intval($_POST['num']) : 0; $type = isset($_POST['type']) && intval($_POST['type']) ? intval($_POST['type']) : 0; //检查名称是否已经存在 if ($edit_data['name'] != $name) { if ($this->db->get_one(array('name' => $name), 'id')) { showmessage(L('name') . L('exists')); } } $siteid = $this->get_siteid(); if ($type == '1') { //自定义SQL $sql = isset($_POST['data']) && trim($_POST['data']) ? trim($_POST['data']) : showmessage(L('custom_sql') . L('empty')); $data['sql'] = $sql; $tag = '{pc:get sql="' . $sql . '" '; if ($cache) { $tag .= 'cache="' . $cache . '" '; } if ($_POST['page']) { $tag .= 'page="' . $_POST['page'] . '" '; } if ($_POST['dbsource']) { $data['dbsource'] = $_POST['dbsource']; $tag .= 'dbsource= "' . $_POST['dbsource'] . '" '; } if ($_POST['return']) { $tag .= 'return="' . $_POST['return'] . '"'; } $tag .= '}'; } elseif ($type == 0) { //模型配置 $module = isset($_POST['module']) && trim($_POST['module']) ? trim($_POST['module']) : showmessage(L('please_select_model')); $action = isset($_POST['action']) && trim($_POST['action']) ? trim($_POST['action']) : showmessage(L('please_select_action')); $html = pc_tag_class($module); $data = array(); $tag = '{pc:' . $module . ' action="' . $action . '" '; if (isset($html[$action]) && is_array($html[$action])) { foreach ($html[$action] as $key => $val) { $val['validator']['reg_msg'] = $val['validator']['reg_msg'] ? $val['validator']['reg_msg'] : $val['name'] . L('inputerror'); ${$key} = isset($_POST[$key]) && trim($_POST[$key]) ? trim($_POST[$key]) : ''; if (!empty($val['validator'])) { if (isset($val['validator']['min']) && strlen(${$key}) < $val['validator']['min']) { showmessage($val['name'] . L('should') . L('is_greater_than') . $val['validator']['min'] . L('lambda')); } if (isset($val['validator']['max']) && strlen(${$key}) > $val['validator']['max']) { showmessage($val['name'] . L('should') . L('less_than') . $val['validator']['max'] . L('lambda')); } if (!preg_match('/' . $val['validator']['reg'] . '/' . $val['validator']['reg_param'], ${$key})) { showmessage($val['name'] . $val['validator']['reg_msg']); } } $tag .= $key . '="' . ${$key} . '" '; $data[$key] = ${$key}; } } if ($_POST['page']) { $tag .= 'page="' . $_POST['page'] . '" '; } if ($num) { $tag .= ' num="' . $num . '" '; } if ($_POST['return']) { $tag .= ' return="' . $_POST['return'] . '" '; } if ($cache) { $tag .= ' cache="' . $cache . '" '; } $tag .= '}'; } else { //碎片 $data = isset($_POST['block']) && trim($_POST['block']) ? trim($_POST['block']) : showmessage(L('block_name_not_empty')); $tag = '{pc:block pos="' . $data . '"}'; } $tag .= "\n" . '{loop $data $n $r}' . "\n" . '<li><a href="{$r[\'url\']}" title="{$r[\'title\']}">{$r[\'title\']}</a></li>' . "\n" . '{/loop}' . "\n" . '{/pc}'; $tag = new_addslashes($tag); $data = is_array($data) ? array2string($data) : $data; $this->db->update(array('siteid' => $siteid, 'tag' => $tag, 'name' => $name, 'type' => $type, 'module' => $module, 'action' => $action, 'data' => $data, 'page' => $_POST['page'], 'return' => $_POST['return'], 'cache' => $cache, 'num' => $num), array('id' => $id)); showmessage('', '', '', 'edit'); } else { pc_base::load_sys_class('form', '', 0); $modules = array_merge(array('' => L('please_select')), pc_base::load_config('modules')); $show_header = $show_validator = true; $type = isset($_GET['type']) && intval($_GET['type']) ? intval($_GET['type']) : $edit_data['type']; $siteid = $this->get_siteid(); $dbsource_data = $dbsource = array(); $dbsource[] = L('please_select'); $dbsource_data = $this->dbsource->select(array('siteid' => $siteid), 'name'); foreach ($dbsource_data as $dbs) { $dbsource[$dbs['name']] = $dbs['name']; } $module = isset($_GET['module']) && trim($_GET['module']) ? trim($_GET['module']) : $edit_data['module']; $action = isset($_GET['action']) && trim($_GET['action']) ? trim($_GET['action']) : $edit_data['action']; if ($edit_data['type'] == 0 || $edit_data['type'] == 1) { $form_data = string2array($edit_data['data']); } if ($module) { $html = pc_tag_class($module); } pc_base::load_app_func('global', 'template'); include $this->admin_tpl('tag_edit'); } }