Esempio n. 1
0
    public function cache()
    {
        $sql = 'SELECT sort.id as catalog_sort_id,sort.catalog_sort,
		sort.catalog_sort_name,field.id,field.catalog_field,field.remark,
		field.catalog_default,field.selected,field.bak,field.batch,field.required,
		field.zh_name,style.formhtml AS style,style.type FROM ' . DB_PREFIX . 'field AS field 
		LEFT JOIN ' . DB_PREFIX . 'style AS style ON field.form_style=style.id 
		LEFT JOIN ' . DB_PREFIX . 'field_sort AS sort ON sort.id=field.catalog_sort_id WHERE 1  AND field.switch = 1';
        $sql .= " ORDER BY sort.order_id DESC,field.order_id DESC";
        $q = $this->db->query($sql);
        while ($data = $this->db->fetch_array($q)) {
            $data['catalog_field'] = catalog_prefix($data['catalog_field']);
            $default = $data['catalog_default'] = $data['catalog_default'] ? explode(',', $data['catalog_default']) : NULL;
            $data['selected'] = maybe_unserialize($data['selected']);
            if (is_string($data['selected']) && !empty($data['selected'])) {
                $data['selected'] = $this->content_change($data['type'], $data['selected']);
            }
            $datas[$data['catalog_sort']]['catalog_sort_id'] = $data['catalog_sort_id'];
            $datas[$data['catalog_sort']]['catalog_sort_name'] = $data['catalog_sort_name'];
            $datas[$data['catalog_sort']]['catalog_sort'] = $data['catalog_sort'];
            if ($data['type'] == 'text' || $data['type'] == 'textarea') {
                $data['style'] = str_replace(REPLACE_NAME, $data['catalog_field'], $data['style']);
            } elseif ($data['type'] == 'radio') {
                $style = str_replace(REPLACE_NAME, $data['catalog_field'], $data['style']);
                unset($data['style']);
                foreach ($default as $defaults) {
                    $data['style'] .= str_replace(REPLACE_DATA, $defaults, $style);
                }
            } elseif ($data['type'] == 'checkbox') {
                $style = str_replace(REPLACE_NAME, $data['catalog_field'] . '[]', $data['style']);
                unset($data['style']);
                foreach ($default as $defaults) {
                    $data['style'] .= str_replace(REPLACE_DATA, $defaults, $style);
                }
            } elseif ($data['type'] == 'option') {
                $style = $data['style'];
                unset($data['style']);
                foreach ($default as $defaults) {
                    $data['style'] .= str_replace(REPLACE_DATA, $defaults, $style);
                }
                $data['style'] = '<select name=' . $data['catalog_field'] . '><option value>请选择' . $data['zh_name'] . '</option>' . $data['style'] . '</select>';
            } elseif ($data['type'] == 'img') {
                if ($data['batch']) {
                    $data['style'] = str_replace(REPLACE_NAME, $data['catalog_field'] . '[]', $data['style']);
                } else {
                    $data['style'] = str_replace(REPLACE_NAME, $data['catalog_field'], $data['style']);
                }
            } else {
                continue;
            }
            $html = array('catalog_id' => $data['id'], 'zh_name' => $data['zh_name'], 'catalog_field' => $data['catalog_field'], 'remark' => $data['remark'], 'catalog_default' => $data['catalog_default'], 'selected' => $data['selected'], 'bak' => $data['bak'], 'batch' => $data['batch'], 'required' => $data['required'], 'type' => $data['type'], 'style' => $data['style']);
            $datas[$data['catalog_sort']]['html'][$data['catalog_field']] = $html;
            $datas[$data['catalog_sort']]['html'][$data['catalog_field']]['data'] = NULL;
        }
        $text = '<?php $cache=' . var_export($datas, true) . ';?>';
        hg_file_write(CACHE_SORT, $text);
    }
Esempio n. 2
0
 function get_catalog_field($where)
 {
     $sql = "SELECT catalog_field FROM " . DB_PREFIX . "content WHERE 1 " . $where;
     $q = $this->db->query($sql);
     //当前内容id是否已存在与内容表,并取出编目标识
     while ($data = $this->db->fetch_array($q)) {
         $data['catalog_field'] = catalog_prefix($data['catalog_field']);
         $arr_catalog_field[$data['catalog_field']] = $data['catalog_field'];
         //编目标识
     }
     return $arr_catalog_field;
 }
Esempio n. 3
0
 public function update()
 {
     $app_uniqueid = $this->input['app_uniqueid'] ? trim($this->input['app_uniqueid']) : '';
     $mod_uniqueid = $this->input['mod_uniqueid'] ? trim($this->input['mod_uniqueid']) : '';
     $content_id = $this->input['content_id'] ? intval($this->input['content_id']) : '';
     $error = $this->catalog->error($app_uniqueid, $mod_uniqueid, $content_id);
     if ($error) {
         $this->errorOutput($error);
     }
     $input = $this->input;
     //获取curl的post数组
     $update_user = array('update_user_id' => intval($this->user['user_id']), 'update_user_name' => $this->user['user_name'], 'update_time' => TIMENOW);
     $app_field = $this->catalog->app_field($app_uniqueid);
     //获取当前应用已启用的编目标识
     $where = $this->catalog->get_condition($app_uniqueid, $mod_uniqueid, $content_id);
     $sql = "SELECT id,catalog_field,value FROM " . DB_PREFIX . "content WHERE 1 " . $where;
     $q = $this->db->query($sql);
     //当前内容用到的编目标识,用于提取curl数组
     while ($data = $this->db->fetch_array($q)) {
         $data['catalog_field'] = catalog_prefix($data['catalog_field']);
         $arr_catalog_field[] = $data['catalog_field'];
         //当前内容id已经使用的编目标识
         $catalog_content[$data['catalog_field']] = array('id' => $data['id'], 'value' => $data['value']);
         $field_value[$data['catalog_field']] = $data['value'] ? $data['value'] : NULL;
     }
     $required = array();
     $required = $this->required($input, $_FILES, $app_field, $field_value);
     if (!empty($required)) {
         $required_ret = array();
         $required_ret['required'] = $required;
         $this->addItem($required_ret);
         $this->output();
     }
     if ($input['catalogdel']) {
         $this->delete(TRUE);
         if (stripos($input['catalogdel'], ',') !== false) {
             $catalogdel = explode(',', $input['catalogdel']);
         } else {
             $catalogdel = array(trim($input['catalogdel']));
         }
         $arr_catalog_field = array_diff($arr_catalog_field, $catalogdel);
         //清除掉已删除的编目标识
     }
     if ($input['materialdel']) {
         if (!is_array($input['materialdel'])) {
             $materialdel = array();
             $materialdel = explode(',', $input['materialdel']);
             $materialdel = array_filter($materialdel, "clean_array_null");
             $materialdel = array_filter($materialdel, "clean_array_num");
             if ($materialdel && is_array($materialdel)) {
                 $input['materialdel'] = trim(implode(',', $materialdel));
                 $this->catalog->deleteMaterial_id($input['materialdel']);
                 //删除无用素材.前端页面会记录用户操作无用的素材
             }
         }
     }
     if (!empty($arr_catalog_field) && is_array($arr_catalog_field)) {
         $images = array();
         foreach ($arr_catalog_field as $value) {
             $images[$value] = array();
             if ($app_field[$value]['type'] == 'img') {
                 $f_cid = $catalog_content[$value]['id'];
                 //编目内容id
                 $images_id = array();
                 if (isset($_FILES[$value]) && !empty($_FILES[$value])) {
                     if ($app_field[$value]['batch']) {
                         $_files = array();
                         foreach ($_FILES[$value] as $name => $f_value) {
                             foreach ($f_value as $keys => $values) {
                                 $_files[$keys][$name] = $values;
                             }
                         }
                         foreach ($_files as $_file) {
                             $img = $this->upload_img($_file, $f_cid);
                             if ($img == -1) {
                                 $this->errorOutput('图片服务器未安装');
                             }
                             $images[$value][] = $img;
                         }
                     } else {
                         $img = $this->upload_img($_FILES[$value], $f_cid);
                         if ($img == -1) {
                             $this->errorOutput('图片服务器未安装');
                         }
                         $images[$value][] = $img;
                     }
                     foreach ($images[$value] as $val) {
                         $images_id[$value][] = $val['id'];
                     }
                     if ($catalog_content[$value]['value'] && !$app_field[$value]['batch']) {
                         $this->catalogcore->delete('materials', array('id' => explode(',', $catalog_content[$value]['value'])));
                         //删除旧数据,单张图片上传模式
                     }
                     /*
                     $update_out[$value]=array(
                     'zh_name'=>$app_field[$value]['zh_name'],
                     'type'=>$app_field[$value]['type'],
                     'value'=>$images[$value]);
                     //unset($images_id);
                     *
                     */
                     unset($_FILES[$value]);
                 }
                 if ($app_field[$value]['batch']) {
                     if (stripos($catalog_content[$value]['value'], ',') !== false) {
                         $catalog_content[$value]['value'] = explode(',', $catalog_content[$value]['value']);
                     } elseif ($catalog_content[$value]['value']) {
                         $catalog_content[$value]['value'] = array(intval($catalog_content[$value]['value']));
                     }
                     if ($input['materialdel']) {
                         if (stripos($input['materialdel'], ',') !== false) {
                             $input['materialdel'] = explode(',', $input['materialdel']);
                         } else {
                             $input['materialdel'] = array(intval($input['materialdel']));
                         }
                         if ($catalog_content[$value]['value']) {
                             $catalog_content[$value]['value'] = array_diff($catalog_content[$value]['value'], $input['materialdel']);
                         }
                     }
                     if ($images_id[$value]) {
                         if ($catalog_content[$value]['value']) {
                             $content_array['value'][$value] = implode(',', array_merge($catalog_content[$value]['value'], $images_id[$value]));
                         } else {
                             $content_array['value'][$value] = implode(',', $images_id[$value]);
                         }
                     } else {
                         if ($catalog_content[$value]['value']) {
                             $content_array['value'][$value] = implode(',', $catalog_content[$value]['value']);
                         } else {
                             //$content_array['value'][$value]='';
                             $this->input['catalogdel'] = $value;
                             $this->delete(true, false);
                         }
                     }
                     $get_material_id = $catalog_content[$value]['value'] ? implode(',', $catalog_content[$value]['value']) : '';
                 } elseif (!$app_field[$value]['batch']) {
                     $is_update_Material = 1;
                     if ($images_id[$value]) {
                         $content_array['value'][$value] = implode(',', $images_id[$value]);
                         $is_update_Material = 0;
                     } elseif ($catalog_content[$value]['value']) {
                         $content_array['value'][$value] = $catalog_content[$value]['value'];
                     }
                     $get_material_id = $is_update_Material ? $catalog_content[$value]['value'] : '';
                     //如果为新上传的,则不用查找素材.如果为旧数据,则需要重新查出
                 }
                 $images[$value] = array_merge($images[$value], $this->catalog->get_Material($get_material_id));
                 //取旧图片数据.
             } elseif ($val['type'] == 'video') {
             } else {
                 if (is_array($input[$value])) {
                     $tmp = implode(',', $input[$value]);
                     $content_array['value'][$value] = $tmp;
                     unset($tmp);
                 } else {
                     $content_array['value'][$value] = $input[$value];
                 }
                 unset($input[$value]);
             }
         }
         $is_create_flag = FALSE;
         if (is_array($app_field)) {
             foreach ($app_field as $key => $value) {
                 if (isset($_FILES[$key]) && !empty($_FILES[$key])) {
                     $is_create_flag = TRUE;
                 } elseif (isset($input[$key]) && !empty($input[$key])) {
                     $is_create_flag = TRUE;
                 }
             }
         }
     } else {
         if (is_array($app_field)) {
             foreach ($app_field as $key => $value) {
                 if (!empty($_FILES[$key])) {
                     $is_create_flag = TRUE;
                 } elseif (isset($input[$key])) {
                     $is_create_flag = TRUE;
                 }
             }
         }
     }
     if ($is_create_flag) {
         $return_create = $this->create($input, $_FILES, TRUE);
     }
     $update_out = array();
     if (!empty($content_array)) {
         $catalog_field_string = "'" . trim(str_ireplace(CATALOG_PREFIX, '', implode("','", array_keys($content_array['value'])))) . "'";
         //去前缀
         $sql = "UPDATE " . DB_PREFIX . "content SET ";
         $count_content = count($content_array);
         $i = 0;
         //用于判断是否为最后一个字段
         foreach ($content_array as $key => $value) {
             $i++;
             $sql .= "{$key} = CASE catalog_field ";
             if (!empty($value) && is_array($value)) {
                 foreach ($value as $catalog_field => $content_value) {
                     $catalog_field_replace = trim(str_ireplace(CATALOG_PREFIX, '', $catalog_field));
                     //去掉前缀
                     $sql .= sprintf("WHEN %s THEN %s ", "'" . $catalog_field_replace . "'", "'" . $content_value . "'");
                     // 拼接SQL语句
                     if ($app_field[$catalog_field]['type'] == 'img') {
                         if ($content_value) {
                             $content_value = $images[$catalog_field];
                         } else {
                             $content_value = array();
                         }
                     } elseif ($app_field[$catalog_field]['type'] == 'checkbox' && $content_value) {
                         $content_value = explode(',', $content_value);
                     }
                     $update_out[$catalog_field] = array('zh_name' => $app_field[$catalog_field]['zh_name'], 'bak' => $app_field[$catalog_field]['bak'], 'type' => $app_field[$catalog_field]['type'], 'value' => $content_value);
                 }
                 if (!($i == $count_content)) {
                     $sql .= "END,";
                 }
             }
         }
         $sql .= "END WHERE 1 " . $where . " AND catalog_field IN ({$catalog_field_string})";
         $this->db->query($sql);
         $fields = '';
         foreach ($update_user as $k => $v) {
             if (is_string($v)) {
                 $fields .= $k . "='" . $v . "',";
             } elseif (is_int($v) || is_float($v)) {
                 $fields .= $k . '=' . $v . ',';
             }
         }
         $fields = rtrim($fields, ',');
         $sql = 'UPDATE ' . DB_PREFIX . 'content SET ' . $fields . ' WHERE 1 ' . $where . ' AND catalog_field IN (' . $catalog_field_string . ')';
         $this->db->query($sql);
     }
     if ($return_create) {
         foreach ($return_create as $key => $val) {
             $update_out[$key] = $val;
         }
     }
     $this->addItem_withkey('result', $update_out);
     $this->addItem_withkey('catalog_prefix', CATALOG_PREFIX);
     $this->output();
 }
Esempio n. 4
0
 /**
  * 获取某个应用某个模块某个内容
  * @param  content_id
  * @param  app_uniqueid
  * @param  mod_uniqueid
  */
 public function detail()
 {
     $rows = $this->rows;
     if (empty($this->input['content_id']) && $this->input['yes']) {
         $catalogs = FALSE;
     } else {
         $error = $this->catalog->error();
         if ($error) {
             $this->errorOutput($error);
         }
         $where = $this->catalog->get_condition();
         $sql = "SELECT sort.catalog_sort,field.catalog_field,content.id,content.value FROM " . DB_PREFIX . "field AS field LEFT JOIN catalog_content AS content ON field.catalog_field=content.catalog_field LEFT JOIN " . DB_PREFIX . "field_sort AS sort ON sort.id=field.catalog_sort_id WHERE 1 " . $where;
         $q = $this->db->query($sql);
         while ($data = $this->db->fetch_array($q)) {
             $data['catalog_field'] = catalog_prefix($data['catalog_field']);
             $datas[$data['catalog_field']] = array($data['catalog_field'] => $data['value'], 'data_id' => $data['id'], 'catalog_sort' => $data['catalog_sort']);
             $field[$data['catalog_field']] = $data['catalog_field'];
             //编目标识
         }
         if (!empty($datas) && is_array($datas)) {
             foreach ($rows as $sortk => $sortv) {
                 if (!empty($sortv['html']) && is_array($sortv['html'])) {
                     foreach ($sortv['html'] as $sortkk => $sortvv) {
                         if ($sortkk != $field[$sortkk]) {
                             unset($rows[$sortk]['html'][$sortkk]);
                             //unset掉不存在数据.
                             unset($field[$sortkk]);
                             //unset掉无用变量.
                         }
                     }
                 }
                 if (empty($rows[$sortk]['html']) && is_array($rows[$sortk]['html'])) {
                     unset($rows[$sortk]);
                     //unset掉空分类
                 }
             }
             foreach ($datas as $datas_key => $datas_value) {
                 if (stripos($rows[$datas_value['catalog_sort']]['html'][$datas_key]['style'], 'radio') !== false) {
                     $rows[$datas_value['catalog_sort']]['html'][$datas_key]['data'] = array('data_id' => $datas_value['data_id'], 'value' => $datas_value[$datas_key]);
                     $rows[$datas_value['catalog_sort']]['html'][$datas_key]['style'] = str_replace('value="' . $datas_value[$datas_key] . '"', 'value="' . $datas_value[$datas_key] . '"  checked="checked"', $rows[$datas_value['catalog_sort']]['html'][$datas_key]['style']);
                     $catalogs[$datas_value['catalog_sort']] = $rows[$datas_value['catalog_sort']];
                 } elseif (stripos($rows[$datas_value['catalog_sort']]['html'][$datas_key]['style'], 'option') !== false) {
                     $rows[$datas_value['catalog_sort']]['html'][$datas_key]['data'] = array('data_id' => $datas_value['data_id'], 'value' => $datas_value[$datas_key]);
                     $rows[$datas_value['catalog_sort']]['html'][$datas_key]['style'] = str_replace('value="' . $datas_value[$datas_key] . '"', 'value="' . $datas_value[$datas_key] . '"  selected="selected"', $rows[$datas_value['catalog_sort']]['html'][$datas_key]['style']);
                     $catalogs[$datas_value['catalog_sort']] = $rows[$datas_value['catalog_sort']];
                 } elseif (stripos($rows[$datas_value['catalog_sort']]['html'][$datas_key]['style'], 'checkbox') !== false) {
                     $checkbox_value_array = explode(',', $datas_value[$datas_key]);
                     $rows[$datas_value['catalog_sort']]['html'][$datas_key]['data'] = array('data_id' => $datas_value['data_id'], 'value' => $datas_value[$datas_key]);
                     if (isset($datas_value[$datas_key]) && !empty($datas_value[$datas_key])) {
                         foreach ($checkbox_value_array as $checkbox_value) {
                             $rows[$datas_value['catalog_sort']]['html'][$datas_key]['style'] = str_replace('value="' . $checkbox_value . '"', 'value="' . $checkbox_value . '"  checked="checked"', $rows[$datas_value['catalog_sort']]['html'][$datas_key]['style']);
                         }
                     }
                     $catalogs[$datas_value['catalog_sort']] = $rows[$datas_value['catalog_sort']];
                 } elseif (stripos($rows[$datas_value['catalog_sort']]['html'][$datas_key]['style'], 'file') !== false) {
                     $datas_value[$datas_key] = unserialize($datas_value[$datas_key]);
                     $rows[$datas_value['catalog_sort']]['html'][$datas_key]['data'] = array('data_id' => $datas_value['data_id'], 'value' => $datas_value[$datas_key]);
                     $rows[$datas_value['catalog_sort']]['html'][$datas_key]['style'] = str_replace(REPLACE_DATA, $datas_value[$datas_key], $rows[$datas_value['catalog_sort']]['html'][$datas_key]['style']);
                     $catalogs[$datas_value['catalog_sort']] = $rows[$datas_value['catalog_sort']];
                 } else {
                     $rows[$datas_value['catalog_sort']]['html'][$datas_key]['data'] = array('data_id' => $datas_value['data_id'], 'value' => $datas_value[$datas_key]);
                     $rows[$datas_value['catalog_sort']]['html'][$datas_key]['style'] = str_replace(REPLACE_DATA, $datas_value[$datas_key], $rows[$datas_value['catalog_sort']]['html'][$datas_key]['style']);
                     $catalogs[$datas_value['catalog_sort']] = $rows[$datas_value['catalog_sort']];
                 }
             }
             foreach ($catalogs as $catalogs_key => $catalogs_value) {
                 if (!empty($catalogs[$catalogs_key]['html']) && is_array($catalogs[$catalogs_key]['html'])) {
                     foreach ($catalogs[$catalogs_key]['html'] as $catalogs_key_key => $catalogs_value_value) {
                         $catalogs[$catalogs_key]['html'][$catalogs_key_key]['style'] = str_replace(REPLACE_DATA, '', $catalogs[$catalogs_key]['html'][$catalogs_key_key]['style']);
                     }
                 }
             }
         } else {
             //此内容id不存在则执行处理
             $catalogs = FALSE;
         }
     }
     $this->addItem($catalogs);
     $this->output();
 }