Beispiel #1
0
 /**
  * 修改数据源
  */
 public function edit()
 {
     $id = isset($_GET['id']) && intval($_GET['id']) ? intval($_GET['id']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
     if (!($edit_data = $this->db->getby_id($id))) {
         showmessage(L('notfound'));
     }
     Loader::helper('dbsource: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->where(array('name' => $name))->field('id')->find()) {
                 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 {
             // 模型配置方式
             $application = isset($_POST['application']) && trim($_POST['application']) ? trim($_POST['application']) : showmessage(L('please_select_model'));
             $do = isset($_POST['do']) && trim($_POST['do']) ? trim($_POST['do']) : showmessage(L('please_select_action'));
             $html = yun_tag_class($application);
             $data = array();
             if (isset($html[$do]) && is_array($html[$do])) {
                 foreach ($html[$do] 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), 'application' => $application, 'do' => $do);
         }
         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->where(array('id' => $id))->update($sql)) {
             // 当为JS时,输出模板文件
             if ($dis_type == 3) {
                 $tpl = Loader::lib('Template');
                 $str = $tpl->template_parse($sql['template']);
                 $filepath = DATA_PATH . 'dbsource' . DIRECTORY_SEPARATOR;
                 if (!is_dir($filepath)) {
                     mkdir($filepath, 0777, true);
                 }
                 @file_put_contents($filepath . $id . '.php', $str);
             }
             showmessage(L('operation_success'), '', '', 'edit');
         } else {
             showmessage(L('operation_failure'));
         }
     } else {
         $applications = array_merge(array('' => L('please_select')), C('application'));
         $show_header = $show_validator = true;
         $type = isset($_GET['type']) ? intval($_GET['type']) : $edit_data['type'];
         $application = isset($_GET['application']) && trim($_GET['application']) ? trim($_GET['application']) : $edit_data['application'];
         $do = isset($_GET['action']) && trim($_GET['do']) ? trim($_GET['do']) : $edit_data['do'];
         if ($edit_data['type'] == 0) {
             $form_data = string2array($edit_data['data']);
         }
         if ($application) {
             $html = yun_tag_class($application);
         }
         Loader::helper('template:global');
         include $this->view('data_edit');
     }
 }
Beispiel #2
0
 /**
  * 修改标签向导
  */
 public function edit()
 {
     $id = isset($_GET['id']) && intval($_GET['id']) ? intval($_GET['id']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
     if (!($edit_data = $this->db->getby_id($id))) {
         showmessage(L('notfound'));
     }
     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->where(array('name' => $name))->field('id')->find()) {
                 showmessage(L('name') . L('exists'));
             }
         }
         if ($type == '1') {
             // 自定义SQL
             $sql = isset($_POST['data']) && trim($_POST['data']) ? trim($_POST['data']) : showmessage(L('custom_sql') . L('empty'));
             $data['sql'] = $sql;
             $tag = '<!--{yun: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 .= '}' . $name . ' start-->';
         } elseif ($type == 0) {
             // 模型配置
             $application = isset($_POST['application']) && trim($_POST['application']) ? trim($_POST['application']) : showmessage(L('please_select_model'));
             $do = isset($_POST['do']) && trim($_POST['do']) ? trim($_POST['do']) : showmessage(L('please_select_action'));
             $html = yun_tag_class($application);
             $data = array();
             $tag = '<!--{yun:' . $application . ' do="' . $do . '" ';
             if (isset($html[$do]) && is_array($html[$do])) {
                 foreach ($html[$do] as $key => $val) {
                     $val['validator']['reg_msg'] = isset($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 (isset($val['validator']['reg']) && !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 .= '}' . $name . ' start-->';
         } else {
             // 碎片
             $data = isset($_POST['block']) && trim($_POST['block']) ? trim($_POST['block']) : showmessage(L('block_name_not_empty'));
             $tag = '<!--{yun:block pos="' . $data . '"}' . $name . ' start-->';
         }
         $tag .= "\n" . '{loop $data $n $r}' . "\n" . '<li><a href="{$r[\'url\']}" title="{$r[\'title\']}">{$r[\'title\']}</a></li>' . "\n" . '{/loop}' . "\n" . '<!--{/yun}' . $name . ' end-->';
         $data = is_array($data) ? array2string($data) : $data;
         $this->db->where(array('id' => $id))->update(array('tag' => $tag, 'name' => $name, 'type' => $type, 'application' => $application, 'do' => $do, 'data' => $data, 'page' => $_POST['page'], 'return' => $_POST['return'], 'cache' => $cache, 'num' => $num));
         showmessage(L('operation_success'), '', '', 'edit');
     } else {
         $applications = array_merge(array('' => L('please_select')), C('application'));
         $show_header = $show_validator = true;
         $type = isset($_GET['type']) && intval($_GET['type']) ? intval($_GET['type']) : $edit_data['type'];
         $dbsource_data = $dbsource = array();
         $dbsource[] = L('please_select');
         $dbsource_data = $this->dbsource->field('name')->select();
         foreach ($dbsource_data as $dbs) {
             $dbsource[$dbs['name']] = $dbs['name'];
         }
         $application = isset($_GET['application']) && trim($_GET['application']) ? trim($_GET['application']) : $edit_data['application'];
         $do = isset($_GET['do']) && trim($_GET['do']) ? trim($_GET['do']) : $edit_data['do'];
         if ($edit_data['type'] == 0 || $edit_data['type'] == 1) {
             $form_data = string2array($edit_data['data']);
         }
         if ($application) {
             $html = yun_tag_class($application);
         }
         include $this->view('tag_edit');
     }
 }