<?php
/*
+-----------------------------------------------------------------------------+
| $Id: content.php 2010-05-24 12:37:44Z Bleakwind $
| Manage content
| Copyright (c) 2003-2010 Bleakwind (www.weaverdream.com)
| http://www.weaverdream.com/
| Release under the GNU Lesser General Public License Version 3 (LGPLv3):
|   http://www.gnu.org/licenses/lgpl.html
+-----------------------------------------------------------------------------+
*/

if (!defined( 'ENTRY_INDEX')){
    echo "<h1>Forbidden</h1><p>You don't have permission to access on this server.</p>";
    exit;
}

$setting_cover['length']    = 40;
$setting_cover['size']      = 2097152;
$setting_cover['type']      = ".gif,.jpg,.png";
$setting_cover['dir']       = date("Y")."/".date("Ym")."/".date("Ymd")."/";

$setting_attach['length']   = 40;
$setting_attach['size']     = 2097152;
$setting_attach['dir']      = date("Y")."/".date("Ym")."/".date("Ymd")."/";

$js_submit                  = "";

// public ajax
function upload_submit($form,$action,$prompt)
{
    global $LANGUAGE,$LANGLIST,$SETTING;
    $ajax_response = new xajaxResponse();
    $ajax_response->assign($prompt, "innerHTML", "<img src=\"".$SETTING['dir_images_admin']."/loading.gif\" border=\"0\" align=\"absmiddle\" />");
    $ajax_response->remove($form."_upload_target");
    $ajax_response->append($prompt, "innerHTML", "<iframe id=\"".$form."_upload_target\" name=\"".$form."_upload_target\" width=\"0\" height=\"0\" scrolling=\"no\" frameborder=\"0\" src=\"about:blank\" style=\"display:none;\"></iframe>");
    $ajax_response->assign($form,"action",$action);
    $ajax_response->assign($form,"target",$form."_upload_target");
    $ajax_response->script("$('#".$form."').submit();");
    return $ajax_response;
}
$bwajax->register(XAJAX_FUNCTION, "upload_submit");
function content_if_enable($id, $value)
{
    global $LANGUAGE,$LANGLIST,$SETTING,$sys,$content_info;
    $ajax_response = new xajaxResponse();
    if (preg_match("/^add|amend$/i", $sys->get['ope'])) {
        if ( $value == "3"){
            $ajax_response->assign($id, "style.display", 'inline');
        } else {
            $ajax_response->assign($id, "style.display", 'none');
        }
    }
    return $ajax_response;
}
$bwajax->register(XAJAX_FUNCTION, "content_if_enable");
function content_if_top($id, $value)
{
    global $LANGUAGE,$LANGLIST,$SETTING,$sys,$content_info;
    $ajax_response = new xajaxResponse();
    if (preg_match("/^add|amend$/i", $sys->get['ope'])) {
        if ( $value == "3"){
            $ajax_response->assign($id, "style.display", 'inline');
        } else {
            $ajax_response->assign($id, "style.display", 'none');
        }
    }
    return $ajax_response;
}
$bwajax->register(XAJAX_FUNCTION, "content_if_top");
function content_if_view($id, $value)
{
    global $LANGUAGE,$LANGLIST,$SETTING,$sys,$content_info;
    $ajax_response = new xajaxResponse();
    if (preg_match("/^add|amend$/i", $sys->get['ope'])) {
        if ( $value == "1"){
            $ajax_response->assign($id, "style.display", 'inline');
        } else {
            $ajax_response->assign($id, "style.display", 'none');
        }
    }
    return $ajax_response;
}
$bwajax->register(XAJAX_FUNCTION, "content_if_view");
function content_if_inerface($id, $value)
{
    global $LANGUAGE,$LANGLIST,$SETTING,$sys,$content_info;
    $ajax_response = new xajaxResponse();
    if (preg_match("/^add|amend$/i", $sys->get['ope'])) {
        if ( $value == "1"){
            $ajax_response->assign($id, "style.display", 'inline');
        } else {
            $ajax_response->assign($id, "style.display", 'none');
        }
    }
    return $ajax_response;
}
$bwajax->register(XAJAX_FUNCTION, "content_if_inerface");
function content_if_turn($id, $value, $detail="")
{
    global $LANGUAGE,$LANGLIST,$SETTING,$article_info;
    $ajax_response = new xajaxResponse();
    if (!empty($detail) && !is_array($detail)) {
        $detail = preg_split("/[\s,|]+/", $detail);
    }
    if ( $value == "true"){
        $ajax_response->assign($id, "style.display", 'inline');
        if (is_array($detail) && count($detail)>0) {
            foreach ($detail as $v) {
                $ajax_response->assign($v, "style.display", 'none');
            }
        }
    }else{
        $ajax_response->assign($id, "style.display", 'none');
        if (is_array($detail) && count($detail)>0) {
            foreach ($detail as $v) {
                $ajax_response->assign($v, "style.display", 'inline');
            }
        }
    }
    return $ajax_response;
}
$bwajax->register(XAJAX_FUNCTION, "content_if_turn");
//////
// cover ajax
function cover_upload_return($state,$type,$search,$form,$input,$input_value,$submit,$list,$prompt,$msg)
{
    global $LANGUAGE,$LANGLIST,$SETTING,$MEMBER,$ADMIN,$sys,$setting_cover;
    $ajax_response = new xajaxResponse();
    $ajax_response->assign($form,"action","javascript:void(null);");
    $ajax_response->assign($form,"target","_self");

    if ($state == "1") {
        $ajax_response->assign($input, "innerHTML", $input_value);
    }

    if ($type == "amend"){
        $scheduler_info = $sys->return_scheduler_info($search);
        $content_id     = $scheduler_info['content_id'];
        $file_str       = "";
        $filelist       = func::db_select(DB_TABLE_CONTENT_COVER, "*", "content_id=".$content_id, "", "id DESC");
        $file_value     = $filelist['0'];
        if (!empty($file_value)){
            $path   = $SETTING['dir_content_cover']."/".$file_value['dir'];
            if (!file_exists($path)) { func::make_dir($path); }
            if (!empty($file_value['filename']) && file_exists($path.$file_value['filename'])) {
                list($width, $height, $type, $attr) = getimagesize($path.$file_value['filename']);
                $size = $width > $height ? "width=45" : "height=45";
                $file_str = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr align=\"center\"><td width=\"30%\"><span onclick=\"xajax_cover_del('amend','".$content_id."','".$file_value['id']."','".$list."','".$prompt."');\" style=\"cursor:pointer;color:#EA7408;\"><img src=\"".$SETTING['dir_images_admin']."/icon_delete.gif\" alt=\"Delete\" /></span></td><td width=\"70%\"><div style=\"border:1px solid #CCCCCC;background-color:#EEEEEE;\"><img src=\"".$path.$file_value['filename']."\" ".$size." border=\"0\" align=\"absmiddle\" /></div></td></tr></table>\n";
            }
        }
        if (empty($file_str)) {
            $file_str = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr align=\"center\"><td width=\"30%\">&nbsp;</td><td width=\"70%\"><div style=\"border:1px solid #CCCCCC;background-color:#EEEEEE;width:45px;height:45px;\"><br />缩略图</div></td></tr></table>\n";
        }
    } else {
        $admin_id       = $search;
        $file_str       = "";
        $filelist       = func::db_select(DB_TABLE_CONTENT_COVER, "*", "content_id=0 AND admin_id=".$admin_id, "", "id DESC");
        $file_value     = $filelist['0'];
        if (!empty($file_value)){
            $path   = $SETTING['dir_content_cover']."/".$file_value['dir'];
            if (!file_exists($path)) { func::make_dir($path); }
            if (!empty($file_value['filename']) && file_exists($path.$file_value['filename'])) {
                list($width, $height, $type, $attr) = getimagesize($path.$file_value['filename']);
                $size = $width > $height ? "width=45" : "height=45";
                $file_str = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr align=\"center\"><td width=\"30%\"><span onclick=\"xajax_cover_del('add','".$admin_id."','".$file_value['id']."','".$list."','".$prompt."');\" style=\"cursor:pointer;color:#EA7408;\"><img src=\"".$SETTING['dir_images_admin']."/icon_delete.gif\" alt=\"Delete\" /></span></td><td width=\"70%\"><div style=\"border:1px solid #CCCCCC;background-color:#EEEEEE;\"><img src=\"".$path.$file_value['filename']."\" ".$size." border=\"0\" align=\"absmiddle\" /></div></td></tr></table>\n";
            }
        }
        if (empty($file_str)) {
            $file_str = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr align=\"center\"><td width=\"30%\">&nbsp;</td><td width=\"70%\"><div style=\"border:1px solid #CCCCCC;background-color:#EEEEEE;width:45px;height:45px;\"><br />缩略图</div></td></tr></table>\n";
        }
    }
    $ajax_response->assign($list,"innerHTML",$file_str);

    $ajax_response->assign($prompt, "innerHTML", $msg);
    $ajax_response->assign($submit,"disabled",false);
    return $ajax_response;
}
$bwajax->register(XAJAX_FUNCTION, "cover_upload_return");
function cover_get($type,$search,$file_input,$file,$submit,$list,$prompt)
{
    global $LANGUAGE,$LANGLIST,$SETTING,$MEMBER,$ADMIN,$sys,$setting_cover;
    $ajax_response = new xajaxResponse();

    $ajax_response->assign($prompt, "innerHTML", "<img src=\"".$SETTING['dir_images_admin']."/loading.gif\" border=\"0\" align=\"absmiddle\" />");
    $cover_type = explode(",",$setting_cover['type']);
    if (empty($file)) {
        $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">请输入文件地址</span>");
        $ajax_response->assign($submit,"disabled",false);
    }else{
        preg_match("/([^\/.]*)\.[^\/.]*$/", $file, $name_primal); $name_primal = $name_primal[1];
        preg_match("/[^\/.]*(\.[^\/.]*)$/", $file, $name_extend); $name_extend = strtolower($name_extend[1]);
        if (empty($name_primal)) {
            $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">获取文件名失败</span>");
            $ajax_response->assign($submit,"disabled",false);
        } elseif (!in_array($name_extend, $cover_type)) {
            $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">文件类型不符合要求<!-- file type error --></span>");
            $ajax_response->assign($submit,"disabled",false);
        } else {

            $result_state = "1";

            if ($type == "amend"){
                $scheduler_info = $sys->return_scheduler_info($search);
                $content_id     = $scheduler_info['content_id'];
                if (!preg_match("/^[1-9][0-9]*$/",$content_id)){
                    $result_state = "0";
                    $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">非法操作<!-- content_id error --></span>");
                    $ajax_response->assign($submit,"disabled",false);
                } else {
                    $filelist = func::db_select(DB_TABLE_CONTENT_COVER, "*", "content_id=".$content_id, "", "id DESC");
                    if (count($filelist) > 1){
                        $result = func::db_delete(DB_TABLE_CONTENT_COVER, "content_id=".$content_id." AND id!=".$filelist[0]['id']);
                        if (!$result) {
                            $result_state = "0";
                            $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">删除多余的记录失败<!-- delete excrescent error --></span>");
                            $ajax_response->assign($submit,"disabled",false);
                        }
                    }
                    if ($result_state == "1") {
                        $file_value = $filelist[0];
                        if (!empty($file_value['dir'])){
                            $dir    = $file_value['dir'];
                            $path   = $SETTING['dir_content_cover']."/".$dir;
                        } else {
                            $dir    = $setting_cover['dir'];
                            $path   = $SETTING['dir_content_cover']."/".$dir;
                        }
                        if (!file_exists($path)) { func::make_dir($path); }

                        $filename       = "";
                        $file_notexists = false;
                        while($file_notexists === false){
                            $name_base = func::return_lenstr(sha1($name_primal.microtime()),$setting_cover['length']);
                            $filename = $name_base.$name_extend;
                            if(!file_exists($path.$filename)) {
                                $file_notexists = true;
                            }
                        }

                        if (!@copy($file, $path.$filename)) {
                            $result_state = "0";
                            $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">获取内容失败<!-- copy error --></span>");
                            $ajax_response->assign($submit,"disabled",false);
                        } else {
                            if (!empty($file_value['filename'])){
                                if (file_exists($path.$file_value['filename'])) {
                                    @chmod($path.$file_value['filename'], $SETTING['chmod_mode_file']);
                                    @unlink($path.$file_value['filename']);
                                }
                            }
                            $sql_data = array(
                                "dir"           => "'".$dir."'",
                                "filename"      => "'".$filename."'",
                                "content_id"    => "'".$content_id."'",
                                "admin_id"      => "'".$ADMIN['mid']."'",
                            );
                            if (count($filelist) > 0) {
                                $result = func::db_update(DB_TABLE_CONTENT_COVER, $sql_data, "id=".$file_value['id']);
                            } else {
                                $result = func::db_insert(DB_TABLE_CONTENT_COVER, $sql_data);
                            }
                            if (!$result) {
                                if (file_exists($path.$filename)) {
                                    @chmod($path.$filename, $SETTING['chmod_mode_file']);
                                    @unlink($path.$filename);
                                }
                                $result_state = "0";
                                $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">更新数据库失败<!-- db update error --></span>");
                                $ajax_response->assign($submit,"disabled",false);
                            }
                        }
                    }
                }
            } else {
                $admin_id   = $search;
                if (!preg_match("/^[1-9][0-9]*$/",$admin_id)){
                    $result_state = "0";
                    $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">非法操作<!-- admin_id error --></span>");
                    $ajax_response->assign($submit,"disabled",false);
                } else {
                    $filelist = func::db_select(DB_TABLE_CONTENT_COVER, "*", "content_id=0 AND admin_id=".$admin_id, "", "id DESC");
                    if (count($filelist) > 1){
                        $result = func::db_delete(DB_TABLE_CONTENT_COVER, "content_id=0 AND admin_id=".$admin_id." AND id!=".$filelist[0]['id']);
                        if (!$result) {
                            $result_state = "0";
                            $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">删除多余的记录失败<!-- delete excrescent error --></span>");
                            $ajax_response->assign($submit,"disabled",false);
                        }
                    }
                    if ($result_state == "1") {
                        $file_value = $filelist[0];
                        if (!empty($file_value['dir'])){
                            $dir    = $file_value['dir'];
                            $path   = $SETTING['dir_content_cover']."/".$dir;
                        } else {
                            $dir    = $setting_cover['dir'];
                            $path   = $SETTING['dir_content_cover']."/".$dir;
                        }
                        if (!file_exists($path)) { func::make_dir($path); }

                        $filename       = "";
                        $file_notexists = false;
                        while($file_notexists === false){
                            $name_base = func::return_lenstr(sha1($name_primal.microtime()),$setting_cover['length']);
                            $filename = $name_base.$name_extend;
                            if(!file_exists($path.$filename)) {
                                $file_notexists = true;
                            }
                        }

                        if (!@copy($file, $path.$filename)) {
                            $result_state = "0";
                            $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">获取内容失败<!-- copy error --></span>");
                            $ajax_response->assign($submit,"disabled",false);
                        } else {
                            if (!empty($file_value['filename'])){
                                if (file_exists($path.$file_value['filename'])) {
                                    @chmod($path.$file_value['filename'], $SETTING['chmod_mode_file']);
                                    @unlink($path.$file_value['filename']);
                                }
                            }
                            $sql_data = array(
                                "dir"           => "'".$dir."'",
                                "filename"      => "'".$filename."'",
                                "content_id"    => "'0'",
                                "admin_id"      => "'".$ADMIN['mid']."'",
                            );
                            if (count($filelist) > 0) {
                                $result = func::db_update(DB_TABLE_CONTENT_COVER, $sql_data, "id=".$file_value['id']);
                            } else {
                                $result = func::db_insert(DB_TABLE_CONTENT_COVER, $sql_data);
                            }
                            if (!$result) {
                                if (file_exists($path.$filename)) {
                                    @chmod($path.$filename, $SETTING['chmod_mode_file']);
                                    @unlink($path.$filename);
                                }
                                $result_state = "0";
                                $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">更新数据库失败<!-- db update error --></span>");
                                $ajax_response->assign($submit,"disabled",false);
                            }
                        }
                    }
                }
            }

            if ($result_state == "1"){
                if ($type == "amend"){
                    $scheduler_info = $sys->return_scheduler_info($search);
                    $content_id     = $scheduler_info['content_id'];
                    $file_str       = "";
                    $filelist       = func::db_select(DB_TABLE_CONTENT_COVER, "*", "content_id=".$content_id, "", "id DESC");
                    $file_value     = $filelist['0'];
                    if (!empty($file_value)){
                        $path   = $SETTING['dir_content_cover']."/".$file_value['dir'];
                        if (!file_exists($path)) { func::make_dir($path); }
                        if (!empty($file_value['filename']) && file_exists($path.$file_value['filename'])) {
                            list($width, $height, $type, $attr) = getimagesize($path.$file_value['filename']);
                            $size = $width > $height ? "width=45" : "height=45";
                            $file_str = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr align=\"center\"><td width=\"30%\"><span onclick=\"xajax_cover_del('amend','".$content_id."','".$file_value['id']."','".$list."','".$prompt."');\" style=\"cursor:pointer;color:#EA7408;\"><img src=\"".$SETTING['dir_images_admin']."/icon_delete.gif\" alt=\"Delete\" /></span></td><td width=\"70%\"><div style=\"border:1px solid #CCCCCC;background-color:#EEEEEE;\"><img src=\"".$path.$file_value['filename']."\" ".$size." border=\"0\" align=\"absmiddle\" /></div></td></tr></table>\n";
                        }
                    }
                    if (empty($file_str)) {
                        $file_str = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr align=\"center\"><td width=\"30%\">&nbsp;</td><td width=\"70%\"><div style=\"border:1px solid #CCCCCC;background-color:#EEEEEE;width:45px;height:45px;\"><br />缩略图</div></td></tr></table>\n";
                    }
                } else {
                    $admin_id       = $search;
                    $file_str       = "";
                    $filelist       = func::db_select(DB_TABLE_CONTENT_COVER, "*", "content_id=0 AND admin_id=".$admin_id, "", "id DESC");
                    $file_value     = $filelist['0'];
                    if (!empty($file_value)){
                        $path   = $SETTING['dir_content_cover']."/".$file_value['dir'];
                        if (!file_exists($path)) { func::make_dir($path); }
                        if (!empty($file_value['filename']) && file_exists($path.$file_value['filename'])) {
                            list($width, $height, $type, $attr) = getimagesize($path.$file_value['filename']);
                            $size = $width > $height ? "width=45" : "height=45";
                            $file_str = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr align=\"center\"><td width=\"30%\"><span onclick=\"xajax_cover_del('add','".$admin_id."','".$file_value['id']."','".$list."','".$prompt."');\" style=\"cursor:pointer;color:#EA7408;\"><img src=\"".$SETTING['dir_images_admin']."/icon_delete.gif\" alt=\"Delete\" /></span></td><td width=\"70%\"><div style=\"border:1px solid #CCCCCC;background-color:#EEEEEE;\"><img src=\"".$path.$file_value['filename']."\" ".$size." border=\"0\" align=\"absmiddle\" /></div></td></tr></table>\n";
                        }
                    }
                    if (empty($file_str)) {
                        $file_str = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr align=\"center\"><td width=\"30%\">&nbsp;</td><td width=\"70%\"><div style=\"border:1px solid #CCCCCC;background-color:#EEEEEE;width:45px;height:45px;\"><br />缩略图</div></td></tr></table>\n";
                    }
                }
                $ajax_response->assign($list,"innerHTML",$file_str);
                $ajax_response->assign($file_input, "value", "");
                $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_succeed\">文件获取成功<!-- get file succeed --></span>");
            }

            $ajax_response->assign($submit,"disabled",false);
        }
    }
    return $ajax_response;
}
$bwajax->register(XAJAX_FUNCTION, "cover_get");
function cover_del($type,$search,$del,$list,$prompt)
{
    global $LANGUAGE,$LANGLIST,$SETTING,$MEMBER,$ADMIN,$sys,$setting_cover;
    $ajax_response = new xajaxResponse();

    $ajax_response->assign($prompt, "innerHTML", "");

    $result_state = "1";

    if ($type == "amend"){
        $scheduler_info = $sys->return_scheduler_info($search);
        $content_id     = $scheduler_info['content_id'];
        if (!preg_match("/^[1-9][0-9]*$/",$content_id)){
            $result_state = "0";
            $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">非法操作<!-- content_id error --></span>");
            $ajax_response->assign($submit,"disabled",false);
        } else {
            if (!preg_match("/^[1-9][0-9]*$/",$del)){
                $result_state = "0";
                $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">非法操作<!-- del error --></span>");
                $ajax_response->assign($submit,"disabled",false);
            } else {
                $filelist = func::db_select(DB_TABLE_CONTENT_COVER, "*", "id=".$del, "", "id DESC");
                $file_value = $filelist[0];
                if (!empty($file_value['dir'])){
                    $dir    = $file_value['dir'];
                    $path   = $SETTING['dir_content_cover']."/".$dir;
                    if (!empty($file_value['filename'])){
                        if (file_exists($path.$file_value['filename'])) {
                            @chmod($path.$file_value['filename'], $SETTING['chmod_mode_file']);
                            @unlink($path.$file_value['filename']);
                        }
                    }
                }
                $sql_data = array(
                    "filename" => "''",
                );
                if (count($filelist) > 0) {
                    $result = func::db_update(DB_TABLE_CONTENT_COVER, $sql_data, "id=".$file_value['id']);
                }
                if (!$result) {
                    $result_state = "0";
                    $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">更新数据库失败<!-- db update error --></span>");
                    $ajax_response->assign($submit,"disabled",false);
                }

            }
        }
    } else {
        $admin_id   = $search;
        if (!preg_match("/^[1-9][0-9]*$/",$admin_id)){
            $result_state = "0";
            $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">非法操作<!-- admin_id error --></span>");
            $ajax_response->assign($submit,"disabled",false);
        } else {
            if (!preg_match("/^[1-9][0-9]*$/",$del)){
                $result_state = "0";
                $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">非法操作<!-- del error --></span>");
                $ajax_response->assign($submit,"disabled",false);
            } else {
                $filelist   = func::db_select(DB_TABLE_CONTENT_COVER, "*", "id=".$del, "", "id DESC");
                $file_value = $filelist[0];
                if (!empty($file_value['dir'])){
                    $dir    = $file_value['dir'];
                    $path   = $SETTING['dir_content_cover']."/".$dir;
                    if (!empty($file_value['filename'])){
                        if (file_exists($path.$file_value['filename'])) {
                            @chmod($path.$file_value['filename'], $SETTING['chmod_mode_file']);
                            @unlink($path.$file_value['filename']);
                        }
                    }
                }
                $sql_data = array(
                    "filename" => "''",
                );
                if (count($filelist) > 0) {
                    $result = func::db_update(DB_TABLE_CONTENT_COVER, $sql_data, "id=".$file_value['id']);
                }
                if (!$result) {
                    $result_state = "0";
                    $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">更新数据库失败<!-- db update error --></span>");
                    $ajax_response->assign($submit,"disabled",false);
                }

            }
        }
    }

    if ($result_state == "1"){
        if ($type == "amend"){
            $scheduler_info = $sys->return_scheduler_info($search);
            $content_id     = $scheduler_info['content_id'];
            $file_str       = "";
            $filelist       = func::db_select(DB_TABLE_CONTENT_COVER, "*", "content_id=".$content_id, "", "id DESC");
            $file_value     = $filelist['0'];
            if (!empty($file_value)){
                $path   = $SETTING['dir_content_cover']."/".$file_value['dir'];
                if (!file_exists($path)) { func::make_dir($path); }
                if (!empty($file_value['filename']) && file_exists($path.$file_value['filename'])) {
                    list($width, $height, $type, $attr) = getimagesize($path.$file_value['filename']);
                    $size = $width > $height ? "width=45" : "height=45";
                    $file_str = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr align=\"center\"><td width=\"30%\"><span onclick=\"xajax_cover_del('amend','".$content_id."','".$file_value['id']."','".$list."','".$prompt."');\" style=\"cursor:pointer;color:#EA7408;\"><img src=\"".$SETTING['dir_images_admin']."/icon_delete.gif\" alt=\"Delete\" /></span></td><td width=\"70%\"><div style=\"border:1px solid #CCCCCC;background-color:#EEEEEE;\"><img src=\"".$path.$file_value['filename']."\" ".$size." border=\"0\" align=\"absmiddle\" /></div></td></tr></table>\n";
                }
            }
            if (empty($file_str)) {
                $file_str = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr align=\"center\"><td width=\"30%\">&nbsp;</td><td width=\"70%\"><div style=\"border:1px solid #CCCCCC;background-color:#EEEEEE;width:45px;height:45px;\"><br />缩略图</div></td></tr></table>\n";
            }
        } else {
            $admin_id       = $search;
            $file_str       = "";
            $filelist       = func::db_select(DB_TABLE_CONTENT_COVER, "*", "content_id=0 AND admin_id=".$admin_id, "", "id DESC");
            $file_value     = $filelist['0'];
            if (!empty($file_value)){
                $path   = $SETTING['dir_content_cover']."/".$file_value['dir'];
                if (!file_exists($path)) { func::make_dir($path); }
                if (!empty($file_value['filename']) && file_exists($path.$file_value['filename'])) {
                    list($width, $height, $type, $attr) = getimagesize($path.$file_value['filename']);
                    $size = $width > $height ? "width=45" : "height=45";
                    $file_str = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr align=\"center\"><td width=\"30%\"><span onclick=\"xajax_cover_del('add','".$admin_id."','".$file_value['id']."','".$list."','".$prompt."');\" style=\"cursor:pointer;color:#EA7408;\"><img src=\"".$SETTING['dir_images_admin']."/icon_delete.gif\" alt=\"Delete\" /></span></td><td width=\"70%\"><div style=\"border:1px solid #CCCCCC;background-color:#EEEEEE;\"><img src=\"".$path.$file_value['filename']."\" ".$size." border=\"0\" align=\"absmiddle\" /></div></td></tr></table>\n";
                }
            }
            if (empty($file_str)) {
                $file_str = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr align=\"center\"><td width=\"30%\">&nbsp;</td><td width=\"70%\"><div style=\"border:1px solid #CCCCCC;background-color:#EEEEEE;width:45px;height:45px;\"><br />缩略图</div></td></tr></table>\n";
            }
        }
        $ajax_response->assign($list, "innerHTML", $file_str);
    }

    return $ajax_response;
}
$bwajax->register(XAJAX_FUNCTION, "cover_del");
//////
// attach ajax
function attach_showselect($preview, $field_id, $prompt, $value)
{
    global $LANGUAGE,$LANGLIST,$SETTING,$MEMBER,$ADMIN,$sys,$setting_attach;
    $ajax_response = new xajaxResponse();
    if (empty($value)) {
        $ajax_response->assign($preview, "innerHTML", "<div style=\"border:1px solid #CCCCCC;background-color:#EEEEEE;width:45px;height:45px;\"><br />预览</div>\n");
        $ajax_response->assign($prompt, "innerHTML", "");
    } else {
        $field_item  = func::db_select(DB_TABLE_SETMODEL_FIELD, "*", "id=".$field_id);
        $field_item  = $field_item[0];
        if (empty($field_item['value'])) {
            $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">没有允许的附件类型,请在模型中设定附件类型!</span>");
            $ajax_response->assign($submit,"disabled",false);
        } else {

            $attach_type = preg_split("/[\s,|]+/", $field_item['value']);
            preg_match("/[^\/.]*(\.[^\/.]*)$/", $value, $name_extend); $name_extend = strtolower($name_extend[1]);
            if (!preg_match("/[a-z0-9\.]{1,9}/i", $name_extend) || !in_array($name_extend, $attach_type)) {
                $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">文件类型不符合要求<!-- file type error --></span>");
            } else {
                if (preg_match("/^(\.gif|\.jpg|\.png)$/i", $name_extend) && substr($prompt,-11) == "_get_prompt"){
                    $size = "width=45 height=45";
                    $ajax_response->assign($preview, "innerHTML", "<div style=\"border:1px solid #CCCCCC;background-color:#EEEEEE;width:45px;height:45px;\"><img src=\"".$value."\" ".$size." border=\"0\" align=\"absmiddle\" /></div>");
                } else {
                    $ajax_response->assign($preview, "innerHTML", "<div style=\"border:1px solid #CCCCCC;background-color:#EEEEEE;width:45px;height:45px;\"><br />".$name_extend."</div>\n");
                }
                $ajax_response->assign($prompt, "innerHTML", "");
            }
        }
    }
    return $ajax_response;
}
$bwajax->register(XAJAX_FUNCTION, "attach_showselect");
function attach_upload_return($area_id,$state,$submit,$prompt,$msg)
{
    global $LANGUAGE,$LANGLIST,$SETTING,$MEMBER,$ADMIN,$sys,$setting_attach;
    $ajax_response = new xajaxResponse();
    if (preg_match("/^amend$/i", $sys->get['ope'])) {
        $form = "content_amend";
    } else {
        $form = "content_add";
    }
    $ajax_response->assign($form,"action","javascript:void(null);");
    $ajax_response->assign($form,"target","_self");

    $ajax_response->assign($prompt, "innerHTML", $msg);

    if ($state == "1") {
        $ajax_response->script("xajax_content_model_".$area_id."_show('".$sys->get['ope']."');");
    }

    $ajax_response->assign($submit,"disabled",false);
    return $ajax_response;
}
$bwajax->register(XAJAX_FUNCTION, "attach_upload_return");
function attach_get($area_id,$search,$field_id,$file,$submit,$brief,$prompt)
{
    global $LANGUAGE,$LANGLIST,$SETTING,$MEMBER,$ADMIN,$sys,$setting_attach;
    $ajax_response = new xajaxResponse();
    //$ajax_response->alert(print_r($search, true)); $ajax_response->assign($submit,"disabled",false); return $ajax_response;

    $ajax_response->assign($prompt, "innerHTML", "<img src=\"".$SETTING['dir_images_admin']."/loading.gif\" border=\"0\" align=\"absmiddle\" />");

    $field_item  = func::db_select(DB_TABLE_SETMODEL_FIELD, "*", "id=".$field_id);
    $field_item  = $field_item[0];
    if (empty($field_item['value'])) {
        $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">没有允许的附件类型,请在模型中设定附件类型!</span>");
        $ajax_response->assign($submit,"disabled",false);
    } else {

        $attach_type = preg_split("/[\s,|]+/", $field_item['value']);

        if (empty($file)) {
            $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">请输入文件地址</span>");
            $ajax_response->assign($submit,"disabled",false);
        }else{
            preg_match("/([^\/.]*)\.[^\/.]*$/", $file, $name_primal); $name_primal = $name_primal[1];
            preg_match("/[^\/.]*(\.[^\/.]*)$/", $file, $name_extend); $name_extend = strtolower($name_extend[1]);
            if (empty($name_primal)) {
                $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">获取文件名失败</span>");
                $ajax_response->assign($submit,"disabled",false);
            } elseif (!preg_match("/[a-z0-9\.]{1,9}/i", $name_extend) || !in_array($name_extend, $attach_type)) {
                $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">文件类型不符合要求<!-- file type error --></span>");
                $ajax_response->assign($submit,"disabled",false);
            } else {

                $result_state = "1";

                if (!preg_match("/^[a-z0-9_]+$/",$search)){
                    $result_state = "0";
                    $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">非法操作<!-- key_id error --></span>");
                    $ajax_response->assign($submit,"disabled",false);
                } else {
                    $dir    = $setting_attach['dir'];
                    $path   = $SETTING['dir_content_attach']."/".$dir;
                    if (!file_exists($path)) { func::make_dir($path); }

                    $filename       = "";
                    $file_notexists = false;
                    while($file_notexists === false){
                        $name_base = func::return_lenstr(sha1($name_primal.microtime()),$setting_attach['length']);
                        $filename = $name_base.$name_extend;
                        if(!file_exists($target_dir.$filename)) {
                            $file_notexists = true;
                        }
                    }

                    if (!@copy($file, $path.$filename)) {
                        $result_state = "0";
                        $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">获取内容失败<!-- copy error --></span>");
                        $ajax_response->assign($submit,"disabled",false);
                    }else{
                        $sql_data   = array(
                            "dir"               => "'".$dir."'",
                            "filename"          => "'".$filename."'",
                            "brief"             => "'".addslashes($brief)."'",
                            "key_id"           => "'".$search."'",
                            "admin_id"          => "'".(int)$ADMIN['mid']."'",
                            "time"              => $sys->nowtime,
                            "down"              => "0",
                        );
                        $result = func::db_insert(DB_TABLE_CONTENT_ATTACH, $sql_data);
                        if (!$result) {
                            if (file_exists($path.$filename)) {
                                @chmod($path.$filename, $SETTING['chmod_mode_file']);
                                @unlink($path.$filename);
                            }
                            $result_state = "0";
                            $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">更新数据库失败<!-- db update error --></span>");
                            $ajax_response->assign($submit,"disabled",false);
                        }
                    }
                }

                if ($result_state == "1"){
                    $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_succeed\">文件获取成功<!-- get file succeed --></span>");
                    $ajax_response->script("xajax_content_model_".$area_id."_show('".$sys->get['ope']."');");
                }

                $ajax_response->assign($submit,"disabled",false);
            }
        }
    }
    return $ajax_response;
}
$bwajax->register(XAJAX_FUNCTION, "attach_get");
function attach_del($area_id,$search,$del,$list)
{
    global $LANGUAGE,$LANGLIST,$SETTING,$MEMBER,$ADMIN,$sys,$setting_attach;
    $ajax_response = new xajaxResponse();

    $result_state = "1";

    if (!preg_match("/^[a-z0-9_]+$/",$search)){
        $result_state = "0";
        $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">非法操作<!-- key_id error --></span>");
        $ajax_response->assign($submit,"disabled",false);
    } else {
        if (!preg_match("/^[1-9][0-9]*$/",$del)){
            $result_state = "0";
            $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">非法操作<!-- del error --></span>");
            $ajax_response->assign($submit,"disabled",false);
        } else {
            $filelist = func::db_select(DB_TABLE_CONTENT_ATTACH, "*", "id=".$del, "", "id DESC");
            $file_value = $filelist[0];
            if (!empty($file_value['dir'])){
                $dir    = $file_value['dir'];
                $path   = $SETTING['dir_content_attach']."/".$dir;
                if (!empty($file_value['filename'])){
                    if (file_exists($path.$filelist[0]['filename'])) {
                        @chmod($path.$file_value['filename'], $SETTING['chmod_mode_file']);
                        @unlink($path.$file_value['filename']);
                    }
                }
            }
            $result = func::db_delete(DB_TABLE_CONTENT_ATTACH,  "id=".$file_value['id']);
            if (!$result) {
                $result_state = "0";
                $ajax_response->assign($prompt, "innerHTML", "<span class=\"prompt_failed\">更新数据库失败<!-- db update error --></span>");
                $ajax_response->assign($submit,"disabled",false);
            }
        }
    }

    if ($result_state == "1"){
        $ajax_response->script("xajax_content_model_".$area_id."_show('".$sys->get['ope']."');");
    }

    return $ajax_response;
}
$bwajax->register(XAJAX_FUNCTION, "attach_del");
//////
// content_model_single_show
function content_model_single_show($type)
{
    global $LANGUAGE,$LANGLIST,$SETTING,$CONFIGURE,$MEMBER,$ADMIN,$db,$sys,$c, $ajax_response;
    $ajax_response = new xajaxResponse();
    //$ajax_response->assign("test_output", "innerHTML", "<pre>".print_r($value, true)); $ajax_response->assign($submit,"disabled",false); return $ajax_response;
    list($single_str,$single_js)    = content_model_single("single");
    list($multi_str,$multi_js)      = content_model_multi("multi");
    if (!empty($single_js['before'])) { $ajax_response->script($single_js['before']); }
    $ajax_response->assign("area_model_single", "innerHTML", $single_str);
    if (!empty($single_js['after'])) { $ajax_response->script($single_js['after']); }
    if ($type == "amend") {
        $area_content_submit    = '<input type="button" id="content_submit" name="content_submit" value="编辑" class="button"';
        $area_content_submit    .= 'onclick="xajax.$(\'content_submit\').disabled=true;';
        $area_content_submit    .= 'xajax.$(\'content_submit\').value=\'请等待...\';';
        $area_content_submit    .= $single_js['submit'];
        $area_content_submit    .= $multi_js['submit'];
        $area_content_submit    .= 'xajax_submit_form(\'amend\',xajax.getFormValues(\'content_amend\'),\'content_submit\');">';
    } else {
        $area_content_submit    = '<input type="button" id="content_submit" name="content_submit" value="添加" class="button"';
        $area_content_submit    .= 'onclick="xajax.$(\'content_submit\').disabled=true;';
        $area_content_submit    .= 'xajax.$(\'content_submit\').value=\'请等待...\';';
        $area_content_submit    .= $single_js['submit'];
        $area_content_submit    .= $multi_js['submit'];
        $area_content_submit    .= 'xajax_submit_form(\'add\',xajax.getFormValues(\'content_add\'),\'content_submit\');">';
    }
    $ajax_response->assign("area_content_submit", "innerHTML", $area_content_submit);
    return $ajax_response;
}
$bwajax->register(XAJAX_FUNCTION, "content_model_single_show");
// content_model_multi_show
function content_model_multi_show($type)
{
    global $LANGUAGE,$LANGLIST,$SETTING,$CONFIGURE,$MEMBER,$ADMIN,$db,$sys,$c, $ajax_response;
    $ajax_response = new xajaxResponse();
    //$ajax_response->assign("test_output", "innerHTML", "<pre>".print_r($value, true)); $ajax_response->assign($submit,"disabled",false); return $ajax_response;
    list($single_str,$single_js)    = content_model_single("single");
    list($multi_str,$multi_js)      = content_model_multi("multi");
    if (!empty($multi_js['before'])) { $ajax_response->script($multi_js['before']); }
    $ajax_response->assign("area_model_multi", "innerHTML", $multi_str);
    if (!empty($multi_js['after'])) { $ajax_response->script($multi_js['after']); }
    if ($type == "amend") {
        $area_content_submit    = '<input type="button" id="content_submit" name="content_submit" value="编辑" class="button"';
        $area_content_submit    .= 'onclick="xajax.$(\'content_submit\').disabled=true;';
        $area_content_submit    .= 'xajax.$(\'content_submit\').value=\'请等待...\';';
        $area_content_submit    .= $single_js['submit'];
        $area_content_submit    .= $multi_js['submit'];
        $area_content_submit    .= 'xajax_submit_form(\'amend\',xajax.getFormValues(\'content_amend\'),\'content_submit\');">';
    } else {
        $area_content_submit    = '<input type="button" id="content_submit" name="content_submit" value="添加" class="button"';
        $area_content_submit    .= 'onclick="xajax.$(\'content_submit\').disabled=true;';
        $area_content_submit    .= 'xajax.$(\'content_submit\').value=\'请等待...\';';
        $area_content_submit    .= $single_js['submit'];
        $area_content_submit    .= $multi_js['submit'];
        $area_content_submit    .= 'xajax_submit_form(\'add\',xajax.getFormValues(\'content_add\'),\'content_submit\');">';
    }
    $ajax_response->assign("area_content_submit", "innerHTML", $area_content_submit);
    return $ajax_response;
}
$bwajax->register(XAJAX_FUNCTION, "content_model_multi_show");
// content_model_single
function content_model_single($area_id)
{
    global $LANGUAGE,$LANGLIST,$SETTING,$CONFIGURE,$MEMBER,$ADMIN,$db,$sys,$c,$setting_cover,$setting_attach,$sys,$trans_list,$content_info,$ajax_response;
    $error = false;
    //$ajax_response->assign("test_output", "innerHTML", "<pre>".print_r($value, true)); $ajax_response->assign($submit,"disabled",false); return $ajax_response;

    if (preg_match("/^add|amend$/i", $sys->get['ope'])) {
        if ( $ADMIN['ag_privilege']['content'] != "1" ) {
            $ajax_response->alert($iderror."!<!-- privilege not allow -->");
            $ajax_response->assign($submit,"value",$submit_value);
            $ajax_response->assign($submit,"disabled",false);
        } else {
            $result_str         = "";
            $result_js          = array();
            if (preg_match("/^amend$/i", $sys->get['ope'])) {
                $sys_type = "content_amend";
            } else {
                $sys_type = "content_add";
            }
            if (is_array($sys->model_array['level']) && count($sys->model_array['level'])>0) {
            // The first layer
            foreach ($sys->model_array['level'] as $model_content_key => $model_content_item) {
            if ($model_content_item == "content" && $sys->table_list[$model_content_key]['recordtype'] == "1" && is_array($sys->field_array[$model_content_key]) && count($sys->field_array[$model_content_key]) > 0){
                if ($sys->get['ope'] == "amend") {
                    $upper_id   = $content_info['content']['content_id'];
                    $this_id    = "0";
                    if (is_array($content_info[$model_content_key][$content_info['content']['content_id']]) && count($content_info[$model_content_key][$content_info['content']['content_id']])>0) {
                        foreach($content_info[$model_content_key][$content_info['content']['content_id']] as $k => $v) {
                            $this_id    = $k;
                        }
                    }
                } else {
                    $upper_id   = "0";
                    $this_id    = "0";
                }
                $this_type              = "content_info";
                $this_depth             = "1";
                $this_key               = $model_content_key;
                $this_mark              = $model_content_key.'_'.$upper_id.'_'.$this_id;
                $result_str             .= '<div id="area_'.$model_content_key.'" class="block_record1">';
                $result_str             .= '<table width="100%" cellpadding="3" cellspacing="0" border="0" align="center">';
                $result_str             .= '<tr><td colspan="3" align="center" class="block_subtitle1">'.$sys->table_list[$model_content_key]['name'].'['.$sys->table_list[$model_content_key]['code'].']</td></tr>';
                list($str_temp, $js_temp) = content_model_show_form($area_id, $this_type, $this_key, $upper_id, $this_id, $this_depth);
                $result_str             .= $str_temp;
                $result_js['before']    .= $js_temp['before'];
                $result_js['after']     .= $js_temp['after'];
                $result_js['submit']    .= $js_temp['submit'];
                $result_str             .= '</table>';
                $result_str             .= '</div>';
            }
            }
            }
            return array($result_str, $result_js);
        }
    }
}
// content_model_multi
function content_model_multi($area_id)
{
    global $LANGUAGE,$LANGLIST,$SETTING,$CONFIGURE,$MEMBER,$ADMIN,$db,$sys,$c,$setting_cover,$setting_attach,$sys,$trans_list,$content_info,$ajax_response;
    $error = false;
    //$ajax_response->assign("test_output", "innerHTML", "<pre>".print_r($value, true)); $ajax_response->assign($submit,"disabled",false); return $ajax_response;

    if (preg_match("/^add|amend$/i", $sys->get['ope'])) {
        if ( $ADMIN['ag_privilege']['content'] != "1" ) {
            $ajax_response->alert($iderror."!<!-- privilege not allow -->");
            $ajax_response->assign($submit,"value",$submit_value);
            $ajax_response->assign($submit,"disabled",false);
        } else {
            $result_str         = "";
            $result_js          = array();
            if (preg_match("/^amend$/i", $sys->get['ope'])) {
                $sys_type = "content_amend";
            } else {
                $sys_type = "content_add";
            }
            if (is_array($sys->model_array['level']) && count($sys->model_array['level'])>0) {
            // The first layer
            foreach ($sys->model_array['level'] as $model_content_key => $model_content_item) {
            if ($model_content_item == "content" && $sys->table_list[$model_content_key]['recordtype'] != "1" && is_array($sys->field_array[$model_content_key]) && count($sys->field_array[$model_content_key]) > 0){
                if ($sys->get['ope'] == "amend") {
                    $upper_id   = $content_info['content']['content_id'];
                    $this_id    = 0;
                } else {
                    $upper_id   = "0";
                    $this_id    = "0";
                }
                $this_type              = "content_add";
                $this_depth             = "1";
                $this_key               = $model_content_key;
                $this_mark              = $model_content_key.'_'.$upper_id.'_'.$this_id;
                $result_str             .= '<div id="area_'.$model_content_key.'" class="block_record1">';
                $result_str             .= '<table width="100%" cellpadding="3" cellspacing="0" border="0" align="center">';
                $result_str             .= '<tr><td colspan="3" align="center" class="block_subtitle1">'.$sys->table_list[$model_content_key]['name'].'['.$sys->table_list[$model_content_key]['code'].']</td></tr>';
                list($str_temp, $js_temp) = content_model_show_form($area_id, $this_type, $this_key, $upper_id, $this_id, $this_depth);
                $result_str             .= $str_temp;
                $result_js['before']    .= $js_temp['before'];
                $result_js['after']     .= $js_temp['after'];
                $result_js['submit']    .= $js_temp['submit'];
                $result_str             .= '<tr>';
                $result_str             .= '<td colspan="3" align="center" class="block_subtitle'.$this_depth.'">';
                $result_str             .= '<input type="button" id="'.$this_type.'_'.$this_mark.'" name="'.$this_type.'_'.$this_mark.'" value="添加['.$sys->table_list[$this_key]['code'].']" class="button'.$this_depth.'"';
                $result_str             .= 'onclick="xajax.$(\'content_add_'.$this_mark.'\').disabled=true;';
                $result_str             .= 'xajax.$(\'content_add_'.$this_mark.'\').value=\'请等待...\';';
                $result_str             .= $result_js['submit'];
                $result_str             .= 'xajax_content_model_add(\''.$area_id.'\',\''.$this_key.'\',\''.$upper_id.'\',\''.$this_id.'\',xajax.getFormValues(\''.$sys_type.'\'), \'content_add_'.$this_mark.'\');">';
                $result_str             .= '</td>';
                $result_str             .= '</tr>';
                $result_str             .= '</table>';
                if (is_array($content_info[$this_key][$upper_id]) && count($content_info[$this_key][$upper_id]) > 0){
                // Loop first value
                foreach ($content_info[$this_key][$upper_id] as $content_info_key => $content_info_item) {
                    if ($sys->get['ope'] == "amend") {
                        $upper_id   = $content_info['content']['content_id'];
                        $this_id    = $content_info_key;
                    } else {
                        $upper_id   = "0";
                        $this_id    = $content_info_key;
                    }
                    $this_type              = "content_info";
                    $this_depth             = "1";
                    $this_key               = $model_content_key;
                    $this_mark              = $model_content_key.'_'.$upper_id.'_'.$this_id;
                    $result_str             .= '<div class="block_record'.$this_depth.'">';
                    $result_str             .= '<table width="100%" cellpadding="3" cellspacing="0" border="0" align="center">';
                    $result_str             .= '<tr align="left">';
                    $result_str             .= '<td width="10%" nowrap class="block_left'.$this_depth.'">ID</td>';
                    $result_str             .= '<td width="70%" class="block_right">'.$content_info_key.'</td>';
                    $result_str             .= '<td width="20%" class="block_right">&nbsp;</td>';
                    $result_str             .= '</tr>';
                    list($str_temp, $js_temp) = content_model_show_form($area_id, $this_type, $this_key, $upper_id, $this_id, $this_depth);
                    $result_str             .= $str_temp;
                    $result_js['before']    .= $js_temp['before'];
                    $result_js['after']     .= $js_temp['after'];
                    $result_js['submit']    .= $js_temp['submit'];
                    $result_str             .= '<tr>';
                    $result_str             .= '<td colspan="3" align="right" class="block_subtitle'.$this_depth.'">';
                    $result_str             .= '<input type="button" id="content_delete_'.$this_mark.'" name="content_delete_'.$this_mark.'" value="删除本条数据" class="button'.$this_depth.'"';
                    $result_str             .= 'onclick="xajax.$(\'content_delete_'.$this_mark.'\').disabled=true;';
                    $result_str             .= 'xajax.$(\'content_delete_'.$this_mark.'\').value=\'请等待...\';';
                    $result_str             .= 'xajax_content_model_del(\''.$area_id.'\',\''.$this_key.'\',\''.$upper_id.'\',\''.$this_id.'\',xajax.getFormValues(\''.$sys_type.'\'), \'content_delete_'.$this_mark.'\');">';
                    $result_str             .= '</td>';
                    $result_str             .= '</tr>';
                    $result_str             .= '</table>';
                    // The second layer
                    foreach ( $sys->model_array['level'] as $model_content_sub_key => $model_content_sub_item) {
                    if ($model_content_sub_item == $this_key && $sys->table_list[$model_content_sub_key]['recordtype'] != "1" && is_array($sys->field_array[$model_content_sub_key]) && count($sys->field_array[$model_content_sub_key]) > 0){
                        if ($sys->get['ope'] == "amend") {
                            $upper_id   = $content_info_key;
                            $this_id    = 0;
                        } else {
                            $upper_id   = $content_info_key;
                            $this_id    = 0;
                        }
                        $this_type              = "content_add";
                        $this_depth             = "2";
                        $this_key               = $model_content_sub_key;
                        $this_mark              = $model_content_sub_key.'_'.$upper_id.'_'.$this_id;
                        $result_str             .= '<div id="area_'.$model_content_sub_key.'_'.$content_info_key.'" class="block_record2">';
                        $result_str             .= '<table width="100%" cellpadding="3" cellspacing="0" border="0" align="center">';
                        $result_str             .= '<tr><td colspan="3" align="center" class="block_subtitle2">'.$sys->table_list[$model_content_sub_key]['name'].'['.$sys->table_list[$model_content_sub_key]['code'].']</td></tr>';
                        list($str_temp, $js_temp) = content_model_show_form($area_id, $this_type, $this_key, $upper_id, $this_id, $this_depth);
                        $result_str             .= $str_temp;
                        $result_js['before']    .= $js_temp['before'];
                        $result_js['after']     .= $js_temp['after'];
                        $result_js['submit']    .= $js_temp['submit'];
                        $result_str             .= '<tr>';
                        $result_str             .= '<td colspan="3" align="center" class="block_subtitle2">';
                        $result_str             .= '<input type="button" id="'.$this_type.'_'.$this_mark.'" name="'.$this_type.'_'.$this_mark.'" value="添加['.$sys->table_list[$this_key]['code'].']" class="button2"';
                        $result_str             .= 'onclick="xajax.$(\'content_add_'.$this_mark.'\').disabled=true;';
                        $result_str             .= 'xajax.$(\'content_add_'.$this_mark.'\').value=\'请等待...\';';
                        $result_str             .= $result_js['submit'];
                        $result_str             .= 'xajax_content_model_add(\''.$area_id.'\',\''.$this_key.'\',\''.$upper_id.'\',\''.$this_id.'\',xajax.getFormValues(\''.$sys_type.'\'), \'content_add_'.$this_mark.'\');">';
                        $result_str             .= '</td>';
                        $result_str             .= '</tr>';
                        $result_str             .= '</table>';
                        if (is_array($content_info[$this_key][$content_info_key]) && count($content_info[$this_key][$content_info_key]) > 0){
                        // Loop second value
                        foreach ( $content_info[$this_key][$content_info_key] as $content_info_sub_key => $content_info_sub_item){
                            if ($sys->get['ope'] == "amend") {
                                $upper_id   = $content_info_key;
                                $this_id    = $content_info_sub_key;
                            } else {
                                $upper_id   = $content_info_key;
                                $this_id    = $content_info_sub_key;
                            }
                            $this_type              = "content_info";
                            $this_depth             = "2";
                            $this_key               = $model_content_sub_key;
                            $this_mark              = $this_key.'_'.$upper_id.'_'.$this_id;
                            $result_str             .= '<div class="block_record2">';
                            $result_str             .= '<table width="100%" cellpadding="3" cellspacing="0" border="0" align="center">';
                            $result_str             .= '<tr align="left">';
                            $result_str             .= '<td width="10%" nowrap class="block_left2">ID</td>';
                            $result_str             .= '<td width="70%" class="block_right">'.$content_info_sub_key.'</td>';
                            $result_str             .= '<td width="20%" class="block_right">&nbsp;</td>';
                            $result_str             .= '</tr>';
                            list($str_temp, $js_temp) = content_model_show_form($area_id, $this_type, $this_key, $upper_id, $this_id, $this_depth);
                            $result_str             .= $str_temp;
                            $result_js['before']    .= $js_temp['before'];
                            $result_js['after']     .= $js_temp['after'];
                            $result_js['submit']    .= $js_temp['submit'];
                            $result_str             .= '<tr>';
                            $result_str             .= '<td colspan="3" align="right" class="block_subtitle2">';
                            $result_str             .= '<input type="button" id="content_delete_'.$this_mark.'" name="content_delete_'.$this_mark.'" value="删除本条数据" class="button2"';
                            $result_str             .= 'onclick="xajax.$(\'content_delete_'.$this_mark.'\').disabled=true;';
                            $result_str             .= 'xajax.$(\'content_delete_'.$this_mark.'\').value=\'请等待...\';';
                            $result_str             .= 'xajax_content_model_del(\''.$area_id.'\',\''.$this_key.'\',\''.$content_info_key.'\',\''.$content_info_sub_key.'\',xajax.getFormValues(\''.$sys_type.'\'), \'content_delete_'.$this_mark.'\');">';
                            $result_str             .= '</td>';
                            $result_str             .= '</tr>';
                            $result_str             .= '</table>';
                            $result_str             .= '</div>';
                        }
                        }
                        $result_str .= '</div>';
                    }
                    }
                    $result_str .= '</div>';
                }
                }
                $result_str .= '</div>';
            }
            }
            }
            return array($result_str, $result_js);
        }
    }
}
// content_model_show_form
function content_model_show_form($area_id, $this_type, $this_key, $upper_id, $this_id, $this_depth)
{
    global $LANGUAGE,$LANGLIST,$SETTING,$CONFIGURE,$MEMBER,$ADMIN,$db,$sys,$c,$setting_cover,$setting_attach,$sys,$trans_list,$content_info,$ajax_response;
    $result_str     = "";
    $result_js      = array();
    if (preg_match("/^amend$/i", $sys->get['ope'])) {
        $sys_type = "content_amend";
    } else {
        $sys_type = "content_add";
    }
    foreach ($sys->field_array[$this_key] as $field_key => $field_item) {
    if ($field_item['team'] == "4") {
        $this_id_array  = '['.$this_key.']['.$upper_id.']['.$this_id.']['.$field_item['code'].']';
        $this_id_mark   = ''.$this_key.'_'.$upper_id.'_'.$this_id.'_'.$field_item['code'].'';
        $this_id_js1    = '\\['.$this_key.'\\]\\['.$upper_id.'\\]\\['.$this_id.'\\]\\['.$field_item['code'].'\\]';
        $this_id_js2    = '\\\['.$this_key.'\\\]\\\['.$upper_id.'\\\]\\\['.$this_id.'\\\]\\\['.$field_item['code'].'\\\]';
        $result_str .= '<tr align="left">';
        $result_str .= '<td width="10%" nowrap class="block_left'.$this_depth.'">'.$field_item['name'].'</td>';
        if ($field_item['table_rowformat'] == "1") {
            if ($field_item['type'] == "singletext"){
                if ($this_type == "content_info"){
                    $this_value = $content_info[$this_key][$upper_id][$this_id][$field_item['code']];
                } else {
                    $this_value = "";
                }
                $result_str .= '<td width="70%" class="block_right">';
                $result_str .= '<input type="text" id="'.$this_type.$this_id_array.'" name="'.$this_type.$this_id_array.'" maxlength="'.$field_item['length'].'" size="88" style="width:460px;" value="'.$this_value.'" class="input">';
                $result_str .= '</td><td width="20%" class="block_right"><span id="'.$this_type.$this_id_array.'_return" class="prompt"><span class="prompt_primal">'.$field_item['prompt'].'</span></span></td></tr>';
            }elseif ($field_item['type'] == "multitext"){
                if ($this_type == "content_info"){
                    $this_value = $content_info[$this_key][$upper_id][$this_id][$field_item['code']];
                } else {
                    $this_value = "";
                }
                $result_str .= '<td width="70%" class="block_right">';
                $result_str .= '<textarea id="'.$this_type.$this_id_array.'" name="'.$this_type.$this_id_array.'" rows="6" cols="88" style="width:460px;" class="textarea">'.$this_value.'</textarea>';
                $result_str .= '</td><td width="20%" class="block_right"><span id="'.$this_type.$this_id_array.'_return" class="prompt"><span class="prompt_primal">'.$field_item['prompt'].'</span></span></td></tr>';
            }elseif ($field_item['type'] == "htmlfile"){
                if ($this_type == "content_info"){
                    $this_value = $content_info[$this_key][$upper_id][$this_id][$field_item['code']];
                } else {
                    $this_value = "";
                }
                $result_str .= '<td width="70%" class="block_right">';
                $result_str .= '<textarea id="'.$this_type.$this_id_array.'" name="'.$this_type.$this_id_array.'" rows="6" cols="88" style="width:460px;" class="textarea">'.$this_value.'</textarea>';
                $result_str .= '</td><td width="20%" class="block_right"><span id="'.$this_type.$this_id_array.'_return" class="prompt"><span class="prompt_primal">'.$field_item['prompt'].'</span></span></td></tr>';
            }elseif ($field_item['type'] == "int"){
                if ($this_type == "content_info"){
                    $this_value = (int)$content_info[$this_key][$upper_id][$this_id][$field_item['code']];
                } else {
                    $this_value = "0";
                }
                $result_str .= '<td width="70%" class="block_right">';
                $result_str .= '<input type="text" id="'.$this_type.$this_id_array.'" name="'.$this_type.$this_id_array.'" maxlength="'.$field_item['length'].'" size="42" style="width:230px;" value="'.$this_value.'" class="input">';
                $result_str .= '</td><td width="20%" class="block_right"><span id="'.$this_type.$this_id_array.'_return" class="prompt"><span class="prompt_primal">'.$field_item['prompt'].'</span></span></td></tr>';
            }elseif ($field_item['type'] == "decimal"){
                if ($this_type == "content_info"){
                    $this_value = $content_info[$this_key][$upper_id][$this_id][$field_item['code']];
                } else {
                    $this_value = "0";
                }
                preg_match("/^([0-9]+)(\,[0-9]+)?$/i",$field_item['length'],$matches);
                $field_item['length_total'] = (int)$matches[1] + (int)$matches[2] + 1;
                $result_str .= '<td width="70%" class="block_right">';
                $result_str .= '<input type="text" id="'.$this_type.$this_id_array.'" name="'.$this_type.$this_id_array.'" maxlength="'.$field_item['length_total'].'" size="42" style="width:230px;" value="'.$this_value.'" class="input">';
                $result_str .= '</td><td width="20%" class="block_right"><span id="'.$this_type.$this_id_array.'_return" class="prompt"><span class="prompt_primal">'.$field_item['prompt'].'</span></span></td></tr>';
            }elseif ($field_item['type'] == "time"){
                if ($this_type == "content_info"){
                    if (preg_match("/^[1-9][0-9]{0,10}$/i", $content_info[$this_key][$upper_id][$this_id][$field_item['code']])){
                        $this_value = date("Y-m-d", $content_info[$this_key][$upper_id][$this_id][$field_item['code']]);
                    } else {
                        $this_value = date("Y-m-d");
                    }
                } else {
                    $this_value = date("Y-m-d");
                }
                $result_str .= '<td width="70%" class="block_right">';
                $result_str .= '<input type="text" id="'.$this_type.$this_id_array.'" name="'.$this_type.$this_id_array.'" size="10" style="width:70px;" maxlength="10" value="'.$this_value.'" class="input" />';
                $result_str .= '</td><td width="20%" class="block_right"><span id="'.$this_type.$this_id_array.'_return" class="prompt"><span class="prompt_primal">'.$field_item['prompt'].'</span></span></td></tr>';
                $result_js['after'] .= "$('#".$this_type.$this_id_js2."').datepicker({changeMonth: true, changeYear: true, yearRange: '-50:+50', dateFormat: 'yy-mm-dd', showOn: 'button', buttonImage: 'admin/template/default/{\$dir_images_admin}/icon_calendar.gif', buttonImageOnly: true});\n";
            }elseif ($field_item['type'] == "option"){
                if ($this_type == "content_info"){
                    $this_value = $content_info[$this_key][$upper_id][$this_id][$field_item['code']];
                } else {
                    $this_value = "";
                }
                $result_str .= '<td width="70%" class="block_right">';
                $field_item['value'] = explode("|", $field_item['value']);
                if (is_array($field_item['value']) && count($field_item['value'])>0) {
                    $result_str .= '<select id="'.$this_type.$this_id_array.'" name="'.$this_type.$this_id_array.'" class="select">';
                    foreach($field_item['value'] as $v){
                        preg_match("/([0-9]+)\,([^,]+)\,([a-z0-9_]+)\:?([1]?)/i", $v, $this_option);
                        if ($this_type == "content_info"){
                            if ($this_option[1] == $this_value) {
                                $this_state = ' selected="selected"';
                            } else {
                                $this_state = '';
                            }
                        }
                        $result_str .= '<option value="'.$this_option[1].'" '.$this_state.'>'.$this_option[2].'</option>';
                    }
                    $result_str .= '</select>';
                }
                $result_str .= '</td><td width="20%" class="block_right"><span id="'.$this_type.$this_id_array.'_return" class="prompt"><span class="prompt_primal">'.$field_item['prompt'].'</span></span></td></tr>';
            }elseif ($field_item['type'] == "radio"){
                if ($this_type == "content_info"){
                    $this_value = $content_info[$this_key][$upper_id][$this_id][$field_item['code']];
                } else {
                    $this_value = "";
                }
                $result_str .= '<td width="70%" class="block_right">';
                $field_item['value'] = explode("|", $field_item['value']);
                if (is_array($field_item['value']) && count($field_item['value'])>0) {
                    foreach($field_item['value'] as $v){
                        preg_match("/([0-9]+)\,([^,]+)\,([a-z0-9_]+)\:?([1]?)/i", $v, $this_option);
                        if ($this_type == "content_info"){
                            if ($this_option[1] == $this_value) {
                                $this_state = ' checked="checked"';
                            } else {
                                $this_state = '';
                            }
                        }
                        $result_str .= '<input type="radio" id="'.$this_type.$this_id_array.'" name="'.$this_type.$this_id_array.'" value="'.$this_option[1].'" '.$this_state.' class="checkbox">'.$this_option[2].'';
                    }
                }
                $result_str .= '</td><td width="20%" class="block_right"><span id="'.$this_type.$this_id_array.'_return" class="prompt"><span class="prompt_primal">'.$field_item['prompt'].'</span></span></td></tr>';
            }elseif ($field_item['type'] == "checkbox"){
                if ($this_type == "content_info"){
                    $this_value = preg_split("/[\s,|]+/", $content_info[$this_key][$upper_id][$this_id][$field_item['code']]);
                } else {
                    $this_value = "";
                }
                $result_str .= '<td width="70%" class="block_right">';
                $field_item['value'] = explode("|", $field_item['value']);
                if (is_array($field_item['value']) && count($field_item['value'])>0) {
                    foreach($field_item['value'] as $v){
                        preg_match("/([0-9]+)\,([^,]+)\,([a-z0-9_]+)\:?([1]?)/i", $v, $this_option);
                        if ($this_type == "content_info"){
                            if (in_array($this_option[1], $this_value)) {
                                $this_state = ' checked="checked"';
                            } else {
                                $this_state = '';
                            }
                        }
                        $result_str .= '<input type="checkbox" id="'.$this_type.$this_id_array.'[]" name="'.$this_type.$this_id_array.'[]" value="'.$this_option[1].'" '.$this_state.' class="checkbox">'.$this_option[2].'';
                    }
                }
                $result_str .= '</td><td width="20%" class="block_right"><span id="'.$this_type.$this_id_array.'_return" class="prompt"><span class="prompt_primal">'.$field_item['prompt'].'</span></span></td></tr>';
            }elseif ($field_item['type'] == "attach"){
                $result_str .= '<td width="90%" class="block_right" colspan="2">';
                $field_item['value'] = preg_split("/[\s,|]+/", $field_item['value']);

                $attach_list            = $this_id_mark."_list";
                $attach_where           = "key_id='".$this_id_mark."' AND admin_id='".$ADMIN['mid']."'";
                $attach_table           = DB_TABLE_CONTENT_ATTACH;
                $attach_dir             = $SETTING['dir_content_attach'];
                list($attach_list_result, $attach_list_result_js) = $sys->return_content_attach_list($area_id,$attach_list,$attach_where,$attach_table,$attach_dir,$this_id_mark);
                $attach_list_result_js  = trim($attach_list_result_js);
                if (!empty($attach_list_result_js)) {
                    $attach_list_result     = $attach_list_result."\n<script type=\"text/javascript\">\n<!-- \n".$attach_list_result_js."\n //-->\n</script>\n";
                }
                $attach_select          = "attach_select";
                $attach_select_result   = "<div style=\"border:1px solid #CCCCCC;background-color:#EEEEEE;width:45px;height:45px;\"><br />预览</div>\n";

                $result_str .= '<input type="hidden" id="'.$this_type.$this_id_array.'" name="'.$this_type.$this_id_array.'" value="'.$this_id_mark.'">';
                $result_str .= '<table width="100%" border="0" cellspacing="0" cellpadding="1">
                  <tr>
                    <td colspan="6" align="left">允许的文件类型:['.implode("|", $field_item['value']).']<span id="'.$this_type.$this_id_array.'_return" class="prompt"><span class="prompt_primal">'.$field_item['prompt'].'</span></span></td>
                  </tr>
                  <tr>
                    <td width="5%" rowspan="2" align="center"><b>描<br />述</b></td>
                    <td width="25%" rowspan="2" align="left"><textarea id="'.$this_id_mark.'_brief" name="'.$this_id_mark.'_brief" rows="2" cols="24" class="textarea"></textarea></td>
                    <td width="5%" rowspan="2" align="center"><span id="'.$this_id_mark.'_select" name="'.$this_id_mark.'_select">'.$attach_select_result.'</span></td>
                    <td width="25%" align="left"><span id="'.$this_id_mark.'_upload_input" name="'.$this_id_mark.'_upload_input"><input type="file" id="'.$this_id_mark.'_upload" name="'.$this_id_mark.'_upload" size="12" style="width:140px;" class="input" onchange="xajax_attach_showselect(\''.$this_id_mark.'_select\',\''.$field_item['id'].'\',\''.$this_id_mark.'_upload_prompt\',this.value);" /></span></td>
                    <td width="10%" align="left"><input type="button" id="'.$this_id_mark.'_upload_submit" name="'.$this_id_mark.'_upload_submit" value="本地上传" class="button" onclick="xajax.$(\''.$this_id_mark.'_upload_submit\').disabled=true;xajax_upload_submit(\''.$sys_type.'\',\''.$CONFIGURE['common']['control_admin'].'?act=content&ope=saveattach_upload&area_id='.$area_id.'&key_id='.$this_id_mark.'&field_id='.$field_item['id'].'\',\''.$this_id_mark.'_upload_prompt\');"></td>
                    <td width="30%" align="left"><span id="'.$this_id_mark.'_upload_prompt" name="'.$this_id_mark.'_upload_prompt"></span></td>
                  </tr>
                  <tr>
                    <td width="25%" align="left"><span id="'.$this_id_mark.'_get_input" name="'.$this_id_mark.'_get_input"><input type="text" id="'.$this_id_mark.'_get" name="'.$this_id_mark.'_get" size="24" style="width:140px;" class="input" onchange="xajax_attach_showselect(\''.$this_id_mark.'_select\',\''.$field_item['id'].'\',\''.$this_id_mark.'_get_prompt\',this.value);" /></span></td>
                    <td width="10%" align="left"><input type="button" id="'.$this_id_mark.'_get_submit" name="'.$this_id_mark.'_get_submit" value="地址获取" class="button" onclick="xajax.$(\''.$this_id_mark.'_get_submit\').disabled=true;xajax_attach_get(\''.$area_id.'\',\''.$this_id_mark.'\',\''.$field_item['id'].'\','.$this_id_mark.'_get.value,\''.$this_id_mark.'_get_submit\','.$this_id_mark.'_brief.value,\''.$this_id_mark.'_get_prompt\');"></td>
                    <td width="30%" align="left"><span id="'.$this_id_mark.'_get_prompt" name="'.$this_id_mark.'_get_prompt"></span></td>
                  </tr>
                  <tr>
                    <td colspan="6" align="left"><span id="'.$this_id_mark.'_list" name="'.$this_id_mark.'_list">'.$attach_list_result.'</span></td>
                  </tr>
                </table>';
                $result_str .= '</td></tr>';
            }else{
                $result_str .= '<td width="70%" class="block_right">';
                $result_str .= '<input type="text" id="'.$this_type.$this_id_array.'" name="'.$this_type.$this_id_array.'" maxlength="255" size="88" style="width:460px;" value="" class="input">';
                $result_str .= '</td><td width="20%" class="block_right"><span id="'.$this_type.$this_id_array.'_return" class="prompt"><span class="prompt_primal">'.$field_item['prompt'].'</span></span></td></tr>';
            }
        } else {
            if ($field_item['type'] == "singletext"){
                if ($this_type == "content_info"){
                    $this_value = $content_info[$this_key][$upper_id][$this_id][$field_item['code']];
                } else {
                    $this_value = "";
                }
                $result_str .= '<td width="70%" class="block_right">';
                $result_str .= '<input type="text" id="'.$this_type.$this_id_array.'" name="'.$this_type.$this_id_array.'" maxlength="'.$field_item['length'].'" size="88" style="width:460px;" value="'.$this_value.'" class="input">';
                $result_str .= '</td><td width="20%" class="block_right"><span id="'.$this_type.$this_id_array.'_return" class="prompt"><span class="prompt_primal">'.$field_item['prompt'].'</span></span></td></tr>';
            }elseif ($field_item['type'] == "multitext"){
                if ($this_type == "content_info"){
                    $this_value = $content_info[$this_key][$upper_id][$this_id][$field_item['code']];
                } else {
                    $this_value = "";
                }
                $result_str .= '<td width="70%" class="block_right">';
                $result_str .= '<textarea id="'.$this_type.$this_id_array.'" name="'.$this_type.$this_id_array.'" rows="6" cols="88" style="width:460px;" class="textarea">'.$this_value.'</textarea>';
                $result_str .= '</td><td width="20%" class="block_right"><span id="'.$this_type.$this_id_array.'_return" class="prompt"><span class="prompt_primal">'.$field_item['prompt'].'</span></span></td></tr>';
            }elseif ($field_item['type'] == "htmlfile"){
                if ($this_type == "content_info"){
                    $this_value = $content_info[$this_key][$upper_id][$this_id][$field_item['code']];
                } else {
                    $this_value = "";
                }
                $result_str .= '<td width="70%" class="block_right">';
                $result_str .= '<textarea id="'.$this_type.$this_id_array.'" name="'.$this_type.$this_id_array.'" rows="6" cols="88" style="width:460px;" class="textarea">'.$this_value.'</textarea>';
                $result_str .= '</td><td width="20%" class="block_right"><span id="'.$this_type.$this_id_array.'_return" class="prompt"><span class="prompt_primal">'.$field_item['prompt'].'</span></span></td></tr>';
            }elseif ($field_item['type'] == "html"){
                if ($this_type == "content_info"){
                    $this_value = $content_info[$this_key][$upper_id][$this_id][$field_item['code']];
                } else {
                    $this_value = "";
                }
                $result_str .= '<td width="90%" class="block_right" colspan="2">';
                $result_str .= '<textarea id="'.$this_id_mark.'" name="'.$this_id_mark.'" rows="6" cols="88" style="width:460px;" class="textarea">'.$this_value.'</textarea>';
                $result_str .= '<span id="'.$this_type.$this_id_array.'_return" class="prompt"><span class="prompt_primal">'.$field_item['prompt'].'</span></span>';
                $result_str .= '</td></tr>';
                //$result_js  .= "CKEDITOR.remove({name:'".$this_id_mark."'});\n";
                //$result_js  .= "if (CKEDITOR.instances.".$this_id_mark.") { CKEDITOR.remove(CKEDITOR.instances.".$this_id_mark."); }\n";
                //$result_js  .= "if (CKEDITOR.instances['".$this_id_mark."']) { CKEDITOR.remove(CKEDITOR.instances['".$this_id_mark."']); }\n";
                $result_js['before']    .= "if (CKEDITOR.instances.".$this_id_mark.") { CKEDITOR.instances.".$this_id_mark.".destroy(); }\n";
                $result_js['after']     .= "CKEDITOR.replace('".$this_id_mark."');\n";
                $result_js['submit']    .= "xajax.$('".$this_id_mark."').value = CKEDITOR.instances.".$this_id_mark.".getData();\n";
            }elseif ($field_item['type'] == "int"){
                if ($this_type == "content_info"){
                    $this_value = (int)$content_info[$this_key][$upper_id][$this_id][$field_item['code']];
                } else {
                    $this_value = "0";
                }
                $result_str .= '<td width="70%" class="block_right">';
                $result_str .= '<input type="text" id="'.$this_type.$this_id_array.'" name="'.$this_type.$this_id_array.'" maxlength="'.$field_item['length'].'" size="42" style="width:230px;" value="'.$this_value.'" class="input">';
                $result_str .= '</td><td width="20%" class="block_right"><span id="'.$this_type.$this_id_array.'_return" class="prompt"><span class="prompt_primal">'.$field_item['prompt'].'</span></span></td></tr>';
            }elseif ($field_item['type'] == "decimal"){
                if ($this_type == "content_info"){
                    $this_value = $content_info[$this_key][$upper_id][$this_id][$field_item['code']];
                } else {
                    $this_value = "0";
                }
                preg_match("/^([0-9]+)(\,[0-9]+)?$/i",$field_item['length'],$matches);
                $field_item['length_total'] = (int)$matches[1] + (int)$matches[2] + 1;
                $result_str .= '<td width="70%" class="block_right">';
                $result_str .= '<input type="text" id="'.$this_type.$this_id_array.'" name="'.$this_type.$this_id_array.'" maxlength="'.$field_item['length_total'].'" size="42" style="width:230px;" value="'.$this_value.'" class="input">';
                $result_str .= '</td><td width="20%" class="block_right"><span id="'.$this_type.$this_id_array.'_return" class="prompt"><span class="prompt_primal">'.$field_item['prompt'].'</span></span></td></tr>';
            }elseif ($field_item['type'] == "time"){
                if ($this_type == "content_info"){
                    if (preg_match("/^[1-9][0-9]{0,10}$/i", $content_info[$this_key][$upper_id][$this_id][$field_item['code']])){
                        $this_value = date("Y-m-d", $content_info[$this_key][$upper_id][$this_id][$field_item['code']]);
                    } else {
                        $this_value = date("Y-m-d");
                    }
                } else {
                    $this_value = date("Y-m-d");
                }
                $result_str .= '<td width="70%" class="block_right">';
                $result_str .= '<input type="text" id="'.$this_type.$this_id_array.'" name="'.$this_type.$this_id_array.'" size="10" style="width:70px;" maxlength="10" value="'.$this_value.'" class="input" />';
                $result_str .= '</td><td width="20%" class="block_right"><span id="'.$this_type.$this_id_array.'_return" class="prompt"><span class="prompt_primal">'.$field_item['prompt'].'</span></span></td></tr>';
                $result_js['after'] .= "$('#".$this_type.$this_id_js2."').datepicker({changeMonth: true, changeYear: true, yearRange: '-50:+50', dateFormat: 'yy-mm-dd', showOn: 'button', buttonImage: 'admin/template/default/{\$dir_images_admin}/icon_calendar.gif', buttonImageOnly: true});\n";
            }elseif ($field_item['type'] == "option"){
                if ($this_type == "content_info"){
                    $this_value = $content_info[$this_key][$upper_id][$this_id][$field_item['code']];
                } else {
                    $this_value = "";
                }
                $result_str .= '<td width="70%" class="block_right">';
                $field_item['value'] = explode("|", $field_item['value']);
                if (is_array($field_item['value']) && count($field_item['value'])>0) {
                    $result_str .= '<select id="'.$this_type.$this_id_array.'" name="'.$this_type.$this_id_array.'" class="select">';
                    foreach($field_item['value'] as $v){
                        preg_match("/([0-9]+)\,([^,]+)\,([a-z0-9_]+)\:?([1]?)/i", $v, $this_option);
                        if ($this_type == "content_info"){
                            if ($this_option[1] == $this_value) {
                                $this_state = ' selected="selected"';
                            } else {
                                $this_state = '';
                            }
                        }
                        $result_str .= '<option value="'.$this_option[1].'" '.$this_state.'>'.$this_option[2].'</option>';
                    }
                    $result_str .= '</select>';
                }
                $result_str .= '</td><td width="20%" class="block_right"><span id="'.$this_type.$this_id_array.'_return" class="prompt"><span class="prompt_primal">'.$field_item['prompt'].'</span></span></td></tr>';
            }elseif ($field_item['type'] == "radio"){
                if ($this_type == "content_info"){
                    $this_value = $content_info[$this_key][$upper_id][$this_id][$field_item['code']];
                } else {
                    $this_value = "";
                }
                $result_str .= '<td width="70%" class="block_right">';
                $field_item['value'] = explode("|", $field_item['value']);
                if (is_array($field_item['value']) && count($field_item['value'])>0) {
                    foreach($field_item['value'] as $v){
                        preg_match("/([0-9]+)\,([^,]+)\,([a-z0-9_]+)\:?([1]?)/i", $v, $this_option);
                        if ($this_type == "content_info"){
                            if ($this_option[1] == $this_value) {
                                $this_state = ' checked="checked"';
                            } else {
                                $this_state = '';
                            }
                        }
                        $result_str .= '<input type="radio" id="'.$this_type.$this_id_array.'" name="'.$this_type.$this_id_array.'" value="'.$this_option[1].'" '.$this_state.' class="checkbox">'.$this_option[2].'';
                    }
                }
                $result_str .= '</td><td width="20%" class="block_right"><span id="'.$this_type.$this_id_array.'_return" class="prompt"><span class="prompt_primal">'.$field_item['prompt'].'</span></span></td></tr>';
            }elseif ($field_item['type'] == "checkbox"){
                if ($this_type == "content_info"){
                    $this_value = preg_split("/[\s,|]+/", $content_info[$this_key][$upper_id][$this_id][$field_item['code']]);
                } else {
                    $this_value = "";
                }
                $result_str .= '<td width="70%" class="block_right">';
                $field_item['value'] = explode("|", $field_item['value']);
                if (is_array($field_item['value']) && count($field_item['value'])>0) {
                    foreach($field_item['value'] as $v){
                        preg_match("/([0-9]+)\,([^,]+)\,([a-z0-9_]+)\:?([1]?)/i", $v, $this_option);
                        if ($this_type == "content_info"){
                            if (in_array($this_option[1], $this_value)) {
                                $this_state = ' checked="checked"';
                            } else {
                                $this_state = '';
                            }
                        }
                        $result_str .= '<input type="checkbox" id="'.$this_type.$this_id_array.'[]" name="'.$this_type.$this_id_array.'[]" value="'.$this_option[1].'" '.$this_state.' class="checkbox">'.$this_option[2].'';
                    }
                }
                $result_str .= '</td><td width="20%" class="block_right"><span id="'.$this_type.$this_id_array.'_return" class="prompt"><span class="prompt_primal">'.$field_item['prompt'].'</span></span></td></tr>';
            }elseif ($field_item['type'] == "attach"){
                $result_str .= '<td width="90%" class="block_right" colspan="2">';
                $field_item['value'] = preg_split("/[\s,|]+/", $field_item['value']);

                $attach_list            = $this_id_mark."_list";
                $attach_where           = "key_id='".$this_id_mark."' AND admin_id='".$ADMIN['mid']."'";
                $attach_table           = DB_TABLE_CONTENT_ATTACH;
                $attach_dir             = $SETTING['dir_content_attach'];
                list($attach_list_result, $attach_list_result_js) = $sys->return_content_attach_list($area_id,$attach_list,$attach_where,$attach_table,$attach_dir,$this_id_mark);
                $attach_list_result_js  = trim($attach_list_result_js);
                if (!empty($attach_list_result_js)) {
                    $attach_list_result     = $attach_list_result."\n<script type=\"text/javascript\">\n<!-- \n".$attach_list_result_js."\n //-->\n</script>\n";
                }
                $attach_select          = "attach_select";
                $attach_select_result   = "<div style=\"border:1px solid #CCCCCC;background-color:#EEEEEE;width:45px;height:45px;\"><br />预览</div>\n";

                $result_str .= '<input type="hidden" id="'.$this_type.$this_id_array.'" name="'.$this_type.$this_id_array.'" value="'.$this_id_mark.'">';
                $result_str .= '<table width="100%" border="0" cellspacing="0" cellpadding="1">
                  <tr>
                    <td colspan="6" align="left">允许的文件类型:['.implode("|", $field_item['value']).']<span id="'.$this_type.$this_id_array.'_return" class="prompt"><span class="prompt_primal">'.$field_item['prompt'].'</span></span></td>
                  </tr>
                  <tr>
                    <td width="5%" rowspan="2" align="center"><b>描<br />述</b></td>
                    <td width="25%" rowspan="2" align="left"><textarea id="'.$this_id_mark.'_brief" name="'.$this_id_mark.'_brief" rows="2" cols="24" class="textarea"></textarea></td>
                    <td width="5%" rowspan="2" align="center"><span id="'.$this_id_mark.'_select" name="'.$this_id_mark.'_select">'.$attach_select_result.'</span></td>
                    <td width="25%" align="left"><span id="'.$this_id_mark.'_upload_input" name="'.$this_id_mark.'_upload_input"><input type="file" id="'.$this_id_mark.'_upload" name="'.$this_id_mark.'_upload" size="12" style="width:140px;" class="input" onchange="xajax_attach_showselect(\''.$this_id_mark.'_select\',\''.$field_item['id'].'\',\''.$this_id_mark.'_upload_prompt\',this.value);" /></span></td>
                    <td width="10%" align="left"><input type="button" id="'.$this_id_mark.'_upload_submit" name="'.$this_id_mark.'_upload_submit" value="本地上传" class="button" onclick="xajax.$(\''.$this_id_mark.'_upload_submit\').disabled=true;xajax_upload_submit(\''.$sys_type.'\',\''.$CONFIGURE['common']['control_admin'].'?act=content&ope=saveattach_upload&area_id='.$area_id.'&key_id='.$this_id_mark.'&field_id='.$field_item['id'].'\',\''.$this_id_mark.'_upload_prompt\');"></td>
                    <td width="30%" align="left"><span id="'.$this_id_mark.'_upload_prompt" name="'.$this_id_mark.'_upload_prompt"></span></td>
                  </tr>
                  <tr>
                    <td width="25%" align="left"><span id="'.$this_id_mark.'_get_input" name="'.$this_id_mark.'_get_input"><input type="text" id="'.$this_id_mark.'_get" name="'.$this_id_mark.'_get" size="24" style="width:140px;" class="input" onchange="xajax_attach_showselect(\''.$this_id_mark.'_select\',\''.$field_item['id'].'\',\''.$this_id_mark.'_get_prompt\',this.value);" /></span></td>
                    <td width="10%" align="left"><input type="button" id="'.$this_id_mark.'_get_submit" name="'.$this_id_mark.'_get_submit" value="地址获取" class="button" onclick="xajax.$(\''.$this_id_mark.'_get_submit\').disabled=true;xajax_attach_get(\''.$area_id.'\',\''.$this_id_mark.'\',\''.$field_item['id'].'\','.$this_id_mark.'_get.value,\''.$this_id_mark.'_get_submit\','.$this_id_mark.'_brief.value,\''.$this_id_mark.'_get_prompt\');"></td>
                    <td width="30%" align="left"><span id="'.$this_id_mark.'_get_prompt" name="'.$this_id_mark.'_get_prompt"></span></td>
                  </tr>
                  <tr>
                    <td colspan="6" align="left"><span id="'.$this_id_mark.'_list" name="'.$this_id_mark.'_list">'.$attach_list_result.'</span></td>
                  </tr>
                </table>';
                $result_str .= '</td></tr>';
            }else{
                $result_str .= '<td width="70%" class="block_right">';
                $result_str .= '<input type="text" id="'.$this_type.$this_id_array.'" name="'.$this_type.$this_id_array.'" maxlength="255" size="88" style="width:460px;" value="" class="input">';
                $result_str .= '</td><td width="20%" class="block_right"><span id="'.$this_type.$this_id_array.'_return" class="prompt"><span class="prompt_primal">'.$field_item['prompt'].'</span></span></td></tr>';
            }
        }
    }
    }
    return array($result_str,$result_js);
}
// content_model_add
function content_model_add($area_id, $table, $upper_id, $this_id, $value, $submit)
{
    global $LANGUAGE,$LANGLIST,$SETTING,$CONFIGURE,$MEMBER,$ADMIN,$db,$sys,$c,$setting_cover,$setting_attach,$sys,$trans_list, $content_info;
    $ajax_response = new xajaxResponse();
    $error = false;
    //$ajax_response->alert(print_r($value,true));$ajax_response->assign($submit,"disabled",false); return $ajax_response;
    $this_type  = "content_add";
    if (preg_match("/^add|amend$/i", $sys->get['ope'])) {
        if ( $ADMIN['ag_privilege']['content'] != "1" ) {
            $ajax_response->alert($iderror."!<!-- privilege not allow -->");
            $ajax_response->assign($submit,"value",$submit_value);
            $ajax_response->assign($submit,"disabled",false);
        } else {

            if (is_array($sys->model_array['field'][$table]) && count($sys->model_array['field'][$table]) > 0) {
                $sql_data = array();
                foreach ($sys->model_array['field'][$table] as $k_f => $v_f) {
                    if ($v_f == $table."_id") {
                        // ...
                    } else if ($v_f == $sys->model_array['level'][$table]."_id") {
                        $sql_data[$v_f] = "'".addslashes($upper_id)."'";
                    } elseif ($v_f == "member_id") {
                        $sql_data[$v_f] = "'".addslashes((int)$ADMIN['mid'])."'";
                    } elseif ($sys->field_array[$table][$v_f]['type'] == "checkbox") {
                        if (is_array($value[$this_type][$table][$upper_id][$this_id][$v_f]) && count($value[$this_type][$table][$upper_id][$this_id][$v_f])>0){
                            $this_value = implode(",", $value[$this_type][$table][$upper_id][$this_id][$v_f]);
                        }
                        $sql_data[$v_f] = "'".addslashes($this_value)."'";
                    } elseif ($sys->field_array[$table][$v_f]['type'] == "html") {
                        $sql_data[$v_f] = "'".addslashes($value[''.$table.'_'.$upper_id.'_'.$this_id.'_'.$v_f.''])."'";
                    } elseif ($sys->field_array[$table][$v_f]['type'] == "attach") {
                        $sql_data[$v_f] = "'".addslashes($value[$this_type][$table][$upper_id][$this_id][$v_f])."'";
                    } else {
                        $sql_data[$v_f] = "'".addslashes($value[$this_type][$table][$upper_id][$this_id][$v_f])."'";
                    }
                }
                $insert_id = func::db_insert($SETTING['config_db_prefix'].$table, $sql_data);
                if (!preg_match("/[1-9][0-9]{0,10}/i", $insert_id)) {
                    $error = true;
                    $ajax_response->alert("更新数据库出现错误![".$SETTING['config_db_prefix'].$table."_DB_INSERT]");
                } else {
                    $sql_data_model = array();
                    foreach ($sys->model_array['field'][$table] as $k_f => $v_f) {
                        if ($sys->field_array[$table][$v_f]['type'] == "attach") {
                            $sql_data_model[$v_f]       = "'".addslashes($table.'_'.$upper_id.'_'.$insert_id.'_'.$v_f)."'";
                            $sql_data_attach = array();
                            $sql_data_attach['key_id']  = "'".addslashes($table.'_'.$upper_id.'_'.$insert_id.'_'.$v_f)."'";
                            $result = func::db_update(DB_TABLE_CONTENT_ATTACH, $sql_data_attach, "key_id='".$value[$this_type][$table][$upper_id][$this_id][$v_f]."'");
                            if (!$result) {
                                $error = true;
                                $ajax_response->alert("更新数据库出现错误![".DB_TABLE_CONTENT_ATTACH."_DB_UPDATE]");
                            }
                        }
                    }
                    if (is_array($sql_data_model) && count($sql_data_model)>0) {
                        $result = func::db_update($SETTING['config_db_prefix'].$table, $sql_data_model, $table."_id=".$insert_id);
                        if (!$result) {
                            $error = true;
                            $ajax_response->alert("更新数据库出现错误![".$SETTING['config_db_prefix'].$table."_DB_UPDATE]");
                        }
                    }
                }
            }
            $ajax_response->script("xajax_content_model_".$area_id."_show('".$sys->get['ope']."');");
        }
    }
    return $ajax_response;
}
$bwajax->register(XAJAX_FUNCTION, "content_model_add");
// content_model_del
function content_model_del($area_id, $table, $upper_id, $this_id, $value, $submit)
{
    global $LANGUAGE,$LANGLIST,$SETTING,$CONFIGURE,$MEMBER,$ADMIN,$db,$sys,$c,$setting_cover,$setting_attach,$sys,$trans_list, $content_info;
    $ajax_response = new xajaxResponse();
    $error = false;
    //$ajax_response->assign("test_output", "innerHTML", "<pre>".print_r($value,true));$ajax_response->assign($submit,"disabled",false); return $ajax_response;

    if (preg_match("/^add|amend$/i", $sys->get['ope'])) {
        if ( $ADMIN['ag_privilege']['content'] != "1" ) {
            $ajax_response->alert($iderror."!<!-- privilege not allow -->");
            $ajax_response->assign($submit,"value",$submit_value);
            $ajax_response->assign($submit,"disabled",false);
        } else {
            // delete attach
            if (is_array($value['content_info'][$table][$upper_id][$this_id]) && count($value['content_info'][$table][$upper_id][$this_id]) > 0) {
                if (is_array($sys->model_array['field'][$table]) && count($sys->model_array['field'][$table]) > 0) {
                    foreach ($sys->model_array['field'][$table] as $k_f => $v_f) {
                        if ($sys->field_array[$table][$v_f]['team'] == "4" && $sys->field_array[$table][$v_f]['type'] == "attach") {
                            if (is_array($value['content_attach']) && count($value['content_attach'])) {
                                foreach ($value['content_attach'] as $k_a => $v_a) {
                                    if($v_a['key_id'] == $value['content_info'][$table][$upper_id][$this_id][$v_f]){
                                        if (file_exists($v_a['filename'])) {
                                            @chmod($v_a['filename'], $SETTING['chmod_mode_file']);
                                            @unlink($v_a['filename']);
                                        }
                                        $result = func::db_delete(DB_TABLE_CONTENT_ATTACH, "id=".$k_a."");
                                        if (!$result) {
                                            $error = true;
                                            $ajax_response->alert("更新数据库出现错误![".DB_TABLE_CONTENT_ATTACH."_DB_DELETE]");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            $result = func::db_delete($SETTING['config_db_prefix'].$table, $table."_id=".$this_id."");
            if (!$result) {
                $error = true;
                $ajax_response->alert("更新数据库出现错误![".$SETTING['config_db_prefix'].$table."_DB_DELETE]");
            } else {
                if (is_array($sys->model_array['level']) && count($sys->model_array['level']) > 0) {
                    foreach ($sys->model_array['level'] as $k_l => $v_l) {
                        if (is_array($value['content_info'][$k_l][$this_id]) && count(is_array($value['content_info'][$k_l][$this_id])>0)) {
                            foreach($value['content_info'][$k_l][$this_id] as $k_sub => $v_sub) {
                                // delete attach
                                if (is_array($v_sub) && count($v_sub) > 0) {
                                    if (is_array($sys->model_array['field'][$k_l]) && count($sys->model_array['field'][$k_l]) > 0) {
                                        foreach ($sys->model_array['field'][$k_l] as $k_f => $v_f) {
                                            if ($sys->field_array[$k_l][$v_f]['team'] == "4" && $sys->field_array[$k_l][$v_f]['type'] == "attach") {
                                                if (is_array($value['content_attach']) && count($value['content_attach'])) {
                                                    foreach ($value['content_attach'] as $k_a => $v_a) {
                                                        if($v_a['key_id'] == $v_sub[$v_f]){
                                                            if (file_exists($v_a['filename'])) {
                                                                @chmod($v_a['filename'], $SETTING['chmod_mode_file']);
                                                                @unlink($v_a['filename']);
                                                            }
                                                            $result = func::db_delete(DB_TABLE_CONTENT_ATTACH, "id=".$k_a."");
                                                            if (!$result) {
                                                                $error = true;
                                                                $ajax_response->alert("更新数据库出现错误![".DB_TABLE_CONTENT_ATTACH."_DB_DELETE]");
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if ($v_l == $table) {
                            $result = func::db_delete($SETTING['config_db_prefix'].$k_l, $table."_id=".$this_id);
                            if (!$result) {
                                $error = true;
                                $ajax_response->alert("更新数据库出现错误![".$SETTING['config_db_prefix'].$k_l."_DB_DELETE]");
                            }
                        }
                    }
                }
            }
            $ajax_response->script("xajax_content_model_".$area_id."_show('".$sys->get['ope']."');");
        }
    }
    return $ajax_response;
}
$bwajax->register(XAJAX_FUNCTION, "content_model_del");
// form post ajax
function submit_form($type, $value, $submit)
{
    global $LANGUAGE,$LANGLIST,$SETTING,$CONFIGURE,$MEMBER,$ADMIN,$db,$sys,$c,$setting_cover,$setting_attach,$sys,$trans_list, $content_info;
    $ajax_response = new xajaxResponse();
    $error = false;
    //$ajax_response->alert(print_r($value, true)); $ajax_response->assign($submit,"disabled",false); return $ajax_response;

    if (preg_match("/^add|amend$/i", $sys->get['ope'])) {
        if ($type == "amend") {
            $submit_value   = "编辑";
            $iderror        = "类别错误";
        } else {
            $submit_value   = "添加";
            $iderror        = "所属类别错误";
        }

        if ( $ADMIN['ag_privilege']['content'] != "1" ) {
            $ajax_response->alert($iderror."!<!-- privilege not allow -->");
            $ajax_response->assign($submit,"value",$submit_value);
            $ajax_response->assign($submit,"disabled",false);
        } else {

            if( !is_array($value['content']['channel']) || count($value['content']['channel'])<=0 ) {
                $error = true;
                if(empty($anchor)) { $anchor = "content[channel]"; }
                $ajax_response->assign("content[channel]_return", "innerHTML", "<span class=\"prompt_bubble\"><p>必须选择所属类别<!-- channel error --></p></span>");
            } else {
                $ajax_response->assign("content[channel]_return", "innerHTML", "");
            }

            if( empty($value['content']['phrase']) ) {
                $error = true;
                if(empty($anchor)) { $anchor = "content[phrase]"; }
                $ajax_response->assign("content[phrase]_return", "innerHTML", "<span class=\"prompt_bubble\"><p>必须填写简短标题<!-- phrase error --></p></span>");
            } elseif( mb_strlen($value['content']['phrase'], "utf-8") > 60) {
                $error = true;
                if(empty($anchor)) { $anchor = "content[phrase]"; }
                $ajax_response->assign("content[phrase]_return", "innerHTML", "<span class=\"prompt_bubble\"><p>简短标题不能大于60字节<!-- phrase error --></p></span>");
            } else {
                $ajax_response->assign("content[phrase]_return", "innerHTML", "");
            }

            if( empty($value['content']['subject']) ) {
                $error = true;
                if(empty($anchor)) { $anchor = "content[subject]"; }
                $ajax_response->assign("content[subject]_return", "innerHTML", "<span class=\"prompt_bubble\"><p>必须填写完整标题<!-- subject error --></p></span>");
            } elseif( mb_strlen($value['content']['subject'], "utf-8") > 255) {
                $error = true;
                if(empty($anchor)) { $anchor = "content[subject]"; }
                $ajax_response->assign("content[subject]_return", "innerHTML", "<span class=\"prompt_bubble\"><p>完整标题不能大于255字节<!-- subject error --></p></span>");
            } else {
                $ajax_response->assign("content[subject]_return", "innerHTML", "");
            }

            if( mb_strlen($value['content']['keyword'], "utf-8") > 255) {
                $error = true;
                if(empty($anchor)) { $anchor = "content[keyword]"; }
                $ajax_response->assign("content[keyword]_return", "innerHTML", "<span class=\"prompt_bubble\"><p>关键字不能大于255字节<!-- keyword error --></p></span>");
            } else {
                $ajax_response->assign("content[keyword]_return", "innerHTML", "");
            }

            if( mb_strlen($value['content']['brief'], "utf-8") > 255) {
                $error = true;
                if(empty($anchor)) { $anchor = "content[brief]"; }
                $ajax_response->assign("content[brief]_return", "innerHTML", "<span class=\"prompt_bubble\"><p>简短标题不能大于255字节<!-- brief error --></p></span>");
            } else {
                $ajax_response->assign("content[brief]_return", "innerHTML", "");
            }

            if( !preg_match("/^[1-9][0-9]{0,10}|0$/i", $value['content']['click']) ) {
                $error = true;
                if(empty($anchor)) { $anchor = "content[click]"; }
                $ajax_response->assign("content[click]_return", "innerHTML", "<span class=\"prompt_bubble\"><p>点击必须为数字<!-- if_top error --></p></span>");
            } else {
                $ajax_response->assign("content[click]_return", "innerHTML", "");
            }

            if (is_array($trans_list) && count($trans_list)>0) {
                foreach($trans_list as $v_trans) {
                    if($v_trans['if_must'] == "1") {
                        if ( !preg_match("/^[1-9][0-9]{0,10}$/i", $value['content']['trans'][$v_trans['id']]) ) {
                            $error = true;
                            if(empty($anchor)) { $anchor = "content[trans][".$v_trans['id']."]"; }
                            $ajax_response->assign("content[trans][".$v_trans['id']."]_return", "innerHTML", "<span class=\"prompt_bubble\"><p>横向分类必须选择[".$v_trans['name']."]</p></span>");
                        } else {
                            $ajax_response->assign("content[trans][".$v_trans['id']."]_return", "innerHTML", "");
                        }
                    }
                }
            }

            if( !preg_match("/^[123]$/i", $value['content']['if_enable']) ) {
                $error = true;
                if(empty($anchor)) { $anchor = "content[if_enable]"; }
                $ajax_response->assign("content[if_enable]_return", "innerHTML", "<span class=\"prompt_bubble\"><p>是否开启发生错误<!-- if_enable error --></p></span>");
            }elseif( $value['content']['if_enable'] == "3" ) {
                if( empty($value['content']['if_enable_begin']) || empty($value['content']['if_enable_end']) ) {
                    $error = true;
                    if(empty($anchor)) { $anchor = "content[if_enable]"; }
                    $ajax_response->assign("content[if_enable]_return", "innerHTML", "<span class=\"prompt_bubble\"><p>对是否开启定时必须填写开始和结束时间<!-- if_enable error --></p></span>");
                } else {
                    $ajax_response->assign("content[if_enable]_return", "innerHTML", "");
                }
            }

            if( !preg_match("/^[123]$/i", $value['content']['if_top']) ) {
                $error = true;
                if(empty($anchor)) { $anchor = "content[if_top]"; }
                $ajax_response->assign("content[if_top]_return", "innerHTML", "<span class=\"prompt_bubble\"><p>是否置顶发生错误<!-- if_top error --></p></span>");
            }elseif( $value['content']['if_top'] == "3" ) {
                if( empty($value['content']['if_top_begin']) || empty($value['content']['if_top_end']) ) {
                    $error = true;
                    if(empty($anchor)) { $anchor = "content[if_top]"; }
                    $ajax_response->assign("content[if_top]_return", "innerHTML", "<span class=\"prompt_bubble\"><p>对是否开启置顶必须填写开始和结束时间<!-- if_top error --></p></span>");
                } else {
                    $ajax_response->assign("content[if_top]_return", "innerHTML", "");
                }
            }

            if( !preg_match("/^[12]$/i", $value['content']['if_view']) ) {
                $error = true;
                if(empty($anchor)) { $anchor = "content[if_view]"; }
                $ajax_response->assign("content[if_view]_return", "innerHTML", "<span class=\"prompt_bubble\"><p>是否查看发生错误<!-- if_view error --></p></span>");
            }elseif( $value['content']['if_view'] == "1" ) {
                if( !preg_match("/^[12]$/i", $value['content']['if_view_privilege']) ) {
                    $error = true;
                    if(empty($anchor)) { $anchor = "content[if_view_privilege]"; }
                    $ajax_response->assign("content[if_view_privilege]_return", "innerHTML", "<span class=\"prompt_bubble\"><p>对是否查看开启必须选择权限<!-- if_top error --></p></span>");
                } else {
                    $ajax_response->assign("content[if_view_privilege]_return", "innerHTML", "");
                }
            }

            if( !preg_match("/^[12]$/i", $value['content']['if_inerface']) ) {
                $error = true;
                if(empty($anchor)) { $anchor = "content[if_inerface]"; }
                $ajax_response->assign("content[if_inerface]_return", "innerHTML", "<span class=\"prompt_bubble\"><p>交互信息发生错误<!-- if_inerface error --></p></span>");
            }elseif( $value['content']['if_inerface'] == "1" ) {
                if( !preg_match("/^[12]$/i", $value['content']['if_inerface_identity']) ||
                    !preg_match("/^[12]$/i", $value['content']['if_inerface_check']) ||
                    !preg_match("/^[12]$/i", $value['content']['if_inerface_privilege']) ) {
                    $error = true;
                    if(empty($anchor)) { $anchor = "content[if_inerface_privilege]"; }
                    $ajax_response->assign("content[if_inerface_privilege]_return", "innerHTML", "<span class=\"prompt_bubble\"><p>对交互信息开启必须选择身份,审核,权限<!-- if_top error --></p></span>");
                } else {
                    $ajax_response->assign("content[if_inerface_privilege]_return", "innerHTML", "");
                }
            }

            if( $value['content']['if_turn'] == "1" ) {
                if( !preg_match("/^1|2$/i", $value['content']['if_turn_type']) ) {
                    $error = true;
                    if(empty($anchor)) { $anchor = "content[if_turn_detail]"; }
                    $ajax_response->assign("content[if_turn_detail]_return", "innerHTML", "<span class=\"prompt_bubble\"><p>转向类型发生错误!<!-- content[if_turn_type] error --></p></span>");
                } elseif( empty($value['content']['if_turn_url']) ) {
                    $error = true;
                    if(empty($anchor)) { $anchor = "content[if_turn_detail]"; }
                    $ajax_response->assign("content[if_turn_detail]_return", "innerHTML", "<span class=\"prompt_bubble\"><p>转向地址必须填写<!-- content[if_turn_url] error --></p></span>");
                } else {
                    $ajax_response->assign("content[if_turn_detail]_return", "innerHTML", "");
                }
            }

            if($error){
                $ajax_response->assign($submit,"value",$submit_value);
                $ajax_response->assign($submit,"disabled",false);
                $ajax_response->redirect("#".$anchor);
            }else{

                if ($type == "amend") {
                    $scheduler_info = $sys->return_scheduler_info($sys->get['scheduler_id']);
                    $this_content_id = $scheduler_info['content_id'];
                    if (is_array($sys->model_array['tree']) && count($sys->model_array['tree']) > 0) {
                        foreach($sys->model_array['tree'] as $k => $v) {
                            if (!$error) {
                                if ($k == "content"){
                                    if (is_array($value['content']['prefix']) && count($value['content']['prefix'])>0) {
                                        $this_prefix = implode(",", $value['content']['prefix']);
                                    } else {
                                        $this_prefix = "";
                                    }
                                    if (!empty($value['content']['keyword'])) {
                                        $this_keyword = implode(",", preg_split("/[\s,]+/", $value['content']['keyword']));
                                    } else {
                                        $this_keyword = "";
                                    }
                                    $sql_data = array(
                                        'phrase'                    => "'".addslashes($value['content']['phrase'])."'",
                                        'subject'                   => "'".addslashes($value['content']['subject'])."'",
                                        'color'                     => "'".addslashes((int)$value['content']['color'])."'",
                                        'fontstyle'                 => "'".addslashes((int)$value['content']['fontstyle'])."'",
                                        'decoration'                => "'".addslashes((int)$value['content']['decoration'])."'",
                                        'prefix'                    => "'".addslashes($this_prefix)."'",
                                        'author'                    => "'".addslashes($value['content']['author'])."'",
                                        'excerpt'                   => "'".addslashes($value['content']['excerpt'])."'",
                                        'template_content'           => "'".addslashes($value['content']['template_content'])."'",
                                        'click'                     => "'".addslashes((int)$value['content']['click'])."'",
                                        'keyword'                   => "'".addslashes($this_keyword)."'",
                                        'brief'                     => "'".addslashes($value['content']['brief'])."'",
                                        'if_enable'                 => "'".addslashes((int)$value['content']['if_enable'])."'",
                                        'if_enable_begin'           => "'".addslashes((int)strtotime($value['content']['if_enable_begin']))."'",
                                        'if_enable_end'             => "'".addslashes((int)strtotime($value['content']['if_enable_end']))."'",
                                        'if_top'                    => "'".addslashes((int)$value['content']['if_top'])."'",
                                        'if_top_begin'              => "'".addslashes((int)strtotime($value['content']['if_top_begin']))."'",
                                        'if_top_end'                => "'".addslashes((int)strtotime($value['content']['if_top_end']))."'",
                                        'if_view'                   => "'".addslashes((int)$value['content']['if_view'])."'",
                                        'if_view_privilege'         => "'".addslashes((int)$value['content']['if_view_privilege'])."'",
                                        'if_inerface'               => "'".addslashes((int)$value['content']['if_inerface'])."'",
                                        'if_inerface_privilege'     => "'".addslashes((int)$value['content']['if_inerface_privilege'])."'",
                                        'if_inerface_identity'      => "'".addslashes((int)$value['content']['if_inerface_identity'])."'",
                                        'if_inerface_check'         => "'".addslashes((int)$value['content']['if_inerface_check'])."'",
                                        'if_turn'                   => "'".addslashes((int)$value['content']['if_turn'])."'",
                                        'if_turn_type'              => "'".addslashes((int)$value['content']['if_turn_type'])."'",
                                        'if_turn_url'               => "'".addslashes($value['content']['if_turn_url'])."'",
                                        'rank'                      => "'".addslashes((int)$value['content']['rank'])."'",
                                    );
                                    $result = func::db_update($SETTING['config_db_prefix'].$k, $sql_data, "content_id='".$this_content_id."'");
                                    if (!$result) {
                                        $error = true;
                                        $ajax_response->alert("更新数据库出现错误![".$SETTING['config_db_prefix'].$k."]");
                                    }
                                } elseif ($sys->model_array['level'][$k] == "content" && $sys->model_array['recordtype'][$k] == "1") {
                                    $sql_data = array();
                                    $this_total_record = func::db_count_record($SETTING['config_db_prefix'].$k, "content_id='".addslashes($this_content_id)."'");
                                    if ($this_total_record > 0) {
                                        $this_content_info  = func::db_select($SETTING['config_db_prefix'].$k, $k."_id", "content_id='".addslashes($this_content_id)."'", "1", $k."_id DESC");
                                        $upper_where_id = $this_content_id;
                                        $this_where_id  = $this_content_info[0][$k."_id"];
                                        $upper_id       = $this_content_id;
                                        $this_id        = $this_content_info[0][$k."_id"];
                                        if ($this_total_record > 1) {
                                            $this_delete_result = func::db_delete($SETTING['config_db_prefix'].$k,  $k."_id!=".$this_where_id);
                                        }
                                        if (is_array($sys->model_array['field'][$k]) && count($sys->model_array['field'][$k]) > 0) {
                                            $sql_data['content_id'] = "'".addslashes($this_content_id)."'";
                                            $sql_data["member_id"] = "'".addslashes($ADMIN['mid'])."'";
                                            foreach ($sys->model_array['field'][$k] as $k_f => $v_f) {
                                                if ($sys->field_array[$k][$v_f]['team'] == "4") {
                                                    if ($sys->field_array[$k][$v_f]['type'] == "checkbox") {
                                                        if (is_array($value['content_info'][$k][$upper_where_id][$this_where_id][$v_f]) && count($value['content_info'][$k][$upper_where_id][$this_where_id][$v_f])>0){
                                                            $this_value = implode(",", $value['content_info'][$k][$upper_where_id][$this_where_id][$v_f]);
                                                        }
                                                        $sql_data[$v_f] = "'".addslashes($this_value)."'";
                                                    } elseif ($sys->field_array[$k][$v_f]['type'] == "html") {
                                                        $sql_data[$v_f] = "'".addslashes($value[''.$k.'_'.$upper_where_id.'_'.$this_where_id.'_'.$v_f.''])."'";
                                                    } elseif ($sys->field_array[$k][$v_f]['type'] == "attach") {
                                                        $sql_data[$v_f] = "'".addslashes($k."_".$upper_id."_".$this_id."_".$v_f)."'";
                                                        $sql_data_attach = array();
                                                        $sql_data_attach['key_id']  = "'".addslashes($k.'_'.$upper_id.'_'.$this_id.'_'.$v_f)."'";
                                                        $result = func::db_update(DB_TABLE_CONTENT_ATTACH, $sql_data_attach, "key_id='".$value['content_info'][$k][$upper_where_id][$this_where_id][$v_f]."'");
                                                        if (!$result) {
                                                            $error = true;
                                                            $ajax_response->alert("更新数据库出现错误![".DB_TABLE_CONTENT_ATTACH."_DB_UPDATE]");
                                                        }
                                                    } else {
                                                        $sql_data[$v_f] = "'".addslashes($value['content_info'][$k][$upper_where_id][$this_where_id][$v_f])."'";
                                                    }
                                                }
                                            }
                                            $result = func::db_update($SETTING['config_db_prefix'].$k, $sql_data, $k."_id='".$this_id."'");
                                            if (!$result) {
                                                $error = true;
                                                $ajax_response->alert("更新数据库出现错误![".$SETTING['config_db_prefix'].$k."_DB_UPDATE]");
                                            }
                                        }
                                    } else {
                                        $upper_where_id = $this_content_id;
                                        $this_where_id  = 0;
                                        $upper_id       = $this_content_id;
                                        $this_id        = 0;
                                        if (is_array($sys->model_array['field'][$k]) && count($sys->model_array['field'][$k]) > 0) {
                                            $sql_data['content_id'] = "'".addslashes($this_content_id)."'";
                                            $sql_data["member_id"] = "'".addslashes($ADMIN['mid'])."'";
                                            foreach ($sys->model_array['field'][$k] as $k_f => $v_f) {
                                                if ($sys->field_array[$k][$v_f]['team'] == "4") {
                                                    if ($sys->field_array[$k][$v_f]['type'] == "checkbox") {
                                                        if (is_array($value['content_info'][$k][$upper_where_id][$this_where_id][$v_f]) && count($value['content_info'][$k][$upper_where_id][$this_where_id][$v_f])>0){
                                                            $this_value = implode(",", $value['content_info'][$k][$upper_where_id][$this_where_id][$v_f]);
                                                        }
                                                        $sql_data[$v_f] = "'".addslashes($this_value)."'";
                                                    } elseif ($sys->field_array[$k][$v_f]['type'] == "html") {
                                                        $sql_data[$v_f] = "'".addslashes($value[''.$k.'_'.$upper_where_id.'_'.$this_where_id.'_'.$v_f.''])."'";
                                                    } else {
                                                        $sql_data[$v_f] = "'".addslashes($value['content_info'][$k][$upper_where_id][$this_where_id][$v_f])."'";
                                                    }
                                                }
                                            }
                                            $this_id = func::db_insert($SETTING['config_db_prefix'].$k, $sql_data);
                                            if (!preg_match("/^[1-9][0-9]{0,10}$/i", $this_id)) {
                                                $error = true;
                                                $ajax_response->alert("更新数据库出现错误![".$SETTING['config_db_prefix'].$k."_DB_INSERT]");
                                            } else {
                                                $sql_data = array();
                                                foreach ($sys->model_array['field'][$k] as $k_f => $v_f) {
                                                    if ($sys->field_array[$k][$v_f]['team'] == "4") {
                                                        if ($sys->field_array[$k][$v_f]['type'] == "attach") {
                                                            $sql_data[$v_f] = "'".addslashes($k."_".$upper_id."_".$this_id."_".$v_f)."'";
                                                            $sql_data_attach = array();
                                                            $sql_data_attach['key_id']  = "'".addslashes($k.'_'.$upper_id.'_'.$this_id.'_'.$v_f)."'";
                                                            $result = func::db_update(DB_TABLE_CONTENT_ATTACH, $sql_data_attach, "key_id='".$value['content_info'][$k][$upper_where_id][$this_where_id][$v_f]."'");
                                                            if (!$result) {
                                                                $error = true;
                                                                $ajax_response->alert("更新数据库出现错误![".DB_TABLE_CONTENT_ATTACH."_DB_UPDATE]");
                                                            }
                                                        }
                                                    }
                                                }
                                                $result = func::db_update($SETTING['config_db_prefix'].$k, $sql_data, $k."_id='".$this_id."'");
                                                if (!$result) {
                                                    $error = true;
                                                    $ajax_response->alert("更新数据库出现错误![".$SETTING['config_db_prefix'].$k."_DB_UPDATE]");
                                                }
                                            }
                                        }
                                    }
                                } else {
                                    if (is_array($value['content_info'][$k]) && count($value['content_info'][$k]) > 0) {
                                        foreach($value['content_info'][$k] as $k_g => $v_g) {
                                            if (is_array($v_g) && count($v_g) > 0) {
                                                foreach($v_g as $k_r => $v_r) {
                                                    $sql_data = array();
                                                    if (is_array($sys->model_array['field'][$k]) && count($sys->model_array['field'][$k]) > 0) {
                                                        $this_upper_id = $k_g;
                                                        $sql_data[$sys->model_array['level'][$k]."_id"] = "'".addslashes($this_upper_id)."'";
                                                        $sql_data["member_id"] = "'".addslashes($ADMIN['mid'])."'";
                                                        foreach ($sys->model_array['field'][$k] as $k_f => $v_f) {
                                                            if ($sys->field_array[$k][$v_f]['team'] == "4") {
                                                                if ($sys->field_array[$k][$v_f]['type'] == "checkbox") {
                                                                    if (is_array($value['content_info'][$k][$k_g][$k_r][$v_f]) && count($value['content_info'][$k][$k_g][$k_r][$v_f])>0){
                                                                        $this_value = implode(",", $value['content_info'][$k][$k_g][$k_r][$v_f]);
                                                                    }
                                                                    $sql_data[$v_f] = "'".addslashes($this_value)."'";
                                                                } elseif ($sys->field_array[$k][$v_f]['type'] == "html") {
                                                                    $sql_data[$v_f] = "'".addslashes($value[''.$k.'_'.$k_g.'_'.$k_r.'_'.$v_f.''])."'";
                                                                } elseif ($sys->field_array[$k][$v_f]['type'] == "attach") {
                                                                    $sql_data[$v_f] = "'".addslashes($value['content_info'][$k][$k_g][$k_r][$v_f])."'";
                                                                } else {
                                                                    $sql_data[$v_f] = "'".addslashes($value['content_info'][$k][$k_g][$k_r][$v_f])."'";
                                                                }
                                                            }
                                                        }
                                                        $result = func::db_update($SETTING['config_db_prefix'].$k, $sql_data, $k."_id='".$k_r."'");
                                                        if (!$result) {
                                                            $error = true;
                                                            $ajax_response->alert("更新数据库出现错误![".$SETTING['config_db_prefix'].$k."_DB_UPDATE]");
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    // delete temp attach
                                    if (is_array($value['content_add'][$k]) && count($value['content_add'][$k]) > 0) {
                                        foreach($value['content_add'][$k] as $k_g => $v_g) {
                                            if (is_array($sys->model_array['field'][$k]) && count($sys->model_array['field'][$k]) > 0) {
                                                foreach ($sys->model_array['field'][$k] as $k_f => $v_f) {
                                                    if ($sys->field_array[$k][$v_f]['team'] == "4" && $sys->field_array[$k][$v_f]['type'] == "attach") {
                                                        if (is_array($value['content_attach']) && count($value['content_attach'])) {
                                                            foreach ($value['content_attach'] as $k_a => $v_a) {
                                                                if($v_a['key_id'] == $value['content_add'][$k][$k_g][0][$v_f]){
                                                                    if (file_exists($v_a['filename'])) {
                                                                        @chmod($v_a['filename'], $SETTING['chmod_mode_file']);
                                                                        @unlink($v_a['filename']);
                                                                    }
                                                                    $result = func::db_delete(DB_TABLE_CONTENT_ATTACH, "id=".$k_a."");
                                                                    if (!$result) {
                                                                        $error = true;
                                                                        $ajax_response->alert("更新数据库出现错误![".DB_TABLE_CONTENT_ATTACH."_DB_DELETE]");
                                                                    } else {
                                                                        unset($value['content_attach'][$k_a]);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        // attach brief update
                        if (is_array($value['content_attach']) && count($value['content_attach'])>0) {
                            foreach ($value['content_attach'] as $k_a => $v_a) {
                                $sql_data_attach = array();
                                $sql_data_attach['brief']  = "'".addslashes($v_a['brief'])."'";
                                $result = func::db_update(DB_TABLE_CONTENT_ATTACH, $sql_data_attach, "id='".$k_a."'");
                                if (!$result) {
                                    $error = true;
                                    $ajax_response->alert("更新数据库出现错误![".DB_TABLE_CONTENT_ATTACH."_DB_UPDATE]");
                                }
                            }
                        }
                        // trans
                        if (!$error) {
                            if (is_array($trans_list) && count($trans_list)>0) {
                                foreach($trans_list as $v_trans) {
                                    $this_if_have = func::db_count_record(DB_TABLE_TRANS_CONTENT, "content_id='".addslashes($this_content_id)."' AND trans_group_id='".$v_trans['id']."'");
                                    if ( preg_match("/^[1-9][0-9]{0,10}$/i", $value['content']['trans'][$v_trans['id']] )) {
                                        if ($this_if_have > 0) {
                                            $sql_data = array(
                                                "trans_id"          => "".$value['content']['trans'][$v_trans['id']]."",
                                            );
                                            $result = func::db_update(DB_TABLE_TRANS_CONTENT, $sql_data, "content_id='".addslashes($this_content_id)."' AND trans_group_id='".$v_trans['id']."'");
                                            if (!$result) {
                                                $ajax_response->alert("更新数据库发生错误[".DB_TABLE_TRANS_CONTENT."]");
                                            }
                                        } else {
                                            $sql_data = array(
                                                "content_id"        => "".addslashes($this_content_id)."",
                                                "trans_group_id"    => "".$v_trans['id']."",
                                                "trans_id"          => "".$value['content']['trans'][$v_trans['id']]."",
                                            );
                                            $result = func::db_insert(DB_TABLE_TRANS_CONTENT, $sql_data);
                                            if (!$result) {
                                                $ajax_response->alert("插入数据库发生错误[".DB_TABLE_TRANS_CONTENT."]");
                                            }
                                        }
                                    } else {
                                        $result_delete = func::db_delete(DB_TABLE_TRANS_CONTENT, "content_id='".addslashes($this_content_id)."' AND trans_group_id='".$v_trans['id']."'");
                                    }
                                }
                            }
                        }
                        // scheduler
                        if (!$error) {
                            $result = func::db_delete(DB_TABLE_SCHEDULER, "content_id=".$this_content_id." AND channel_id NOT IN (".implode(",",$value['content']['channel']).")");
                            if (!$result) {
                                $ajax_response->alert("清理所属类别失败[".DB_TABLE_SCHEDULER."]");
                            } else {
                                foreach($value['content']['channel'] as $v) {
                                    $if_exists_channel = func::db_count_record(DB_TABLE_SCHEDULER, "content_id='".$this_content_id."' AND channel_id='".$v."'");
                                    if ($if_exists_channel <= 0) {
                                        $sql_data = array(
                                                        "content_id"  => "'".$this_content_id."'",
                                                        "channel_id"  => "'".$v."'",
                                                    );
                                        $result = func::db_insert(DB_TABLE_SCHEDULER, $sql_data);
                                        if (!$result) {
                                            $ajax_response->alert("更新调度表失败[".$db->ErrorMsg()."]");
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if($error){
                        $ajax_response->assign($submit,"value",$submit_value);
                        $ajax_response->assign($submit,"disabled",false);
                    }else{
                        $ajax_response->redirect($CONFIGURE['common']['control_admin']."?act=content&channel_id=".$scheduler_info['channel_id']."&pag=".$sys->get['pag']);
                    }

                } else {
                    $this_content_id = "";
                    if (is_array($sys->model_array['tree']) && count($sys->model_array['tree']) > 0) {
                        foreach($sys->model_array['tree'] as $k => $v) {
                            if (!$error) {
                                if ($k == "content"){
                                    if (is_array($value['content']['prefix']) && count($value['content']['prefix'])>0) {
                                        $this_prefix = implode(",", $value['content']['prefix']);
                                    } else {
                                        $this_prefix = "";
                                    }
                                    if (!empty($value['content']['keyword'])) {
                                        $this_keyword = implode(",", preg_split("/[\s,]+/", $value['content']['keyword']));
                                    } else {
                                        $this_keyword = "";
                                    }
                                    $sql_data = array(
                                        'phrase'                    => "'".addslashes($value['content']['phrase'])."'",
                                        'subject'                   => "'".addslashes($value['content']['subject'])."'",
                                        'color'                     => "'".addslashes((int)$value['content']['color'])."'",
                                        'fontstyle'                 => "'".addslashes((int)$value['content']['fontstyle'])."'",
                                        'decoration'                => "'".addslashes((int)$value['content']['decoration'])."'",
                                        'prefix'                    => "'".addslashes($this_prefix)."'",
                                        'author'                    => "'".addslashes($value['content']['author'])."'",
                                        'excerpt'                   => "'".addslashes($value['content']['excerpt'])."'",
                                        'template_content'           => "'".addslashes($value['content']['template_content'])."'",
                                        'click'                     => "'".addslashes((int)$value['content']['click'])."'",
                                        'keyword'                   => "'".addslashes($this_keyword)."'",
                                        'brief'                     => "'".addslashes($value['content']['brief'])."'",
                                        'post_id'                   => "'".addslashes($ADMIN['mid'])."'",
                                        'post_username'             => "'".addslashes($MEMBER['username'])."'",
                                        'post_ip'                   => "'".addslashes(func::return_ip())."'",
                                        'post_time'                 => "'".addslashes($sys->nowtime)."'",
                                        'if_enable'                 => "'".addslashes((int)$value['content']['if_enable'])."'",
                                        'if_enable_begin'           => "'".addslashes((int)strtotime($value['content']['if_enable_begin']))."'",
                                        'if_enable_end'             => "'".addslashes((int)strtotime($value['content']['if_enable_end']))."'",
                                        'if_top'                    => "'".addslashes((int)$value['content']['if_top'])."'",
                                        'if_top_begin'              => "'".addslashes((int)strtotime($value['content']['if_top_begin']))."'",
                                        'if_top_end'                => "'".addslashes((int)strtotime($value['content']['if_top_end']))."'",
                                        'if_view'                   => "'".addslashes((int)$value['content']['if_view'])."'",
                                        'if_view_privilege'         => "'".addslashes((int)$value['content']['if_view_privilege'])."'",
                                        'if_inerface'               => "'".addslashes((int)$value['content']['if_inerface'])."'",
                                        'if_inerface_privilege'     => "'".addslashes((int)$value['content']['if_inerface_privilege'])."'",
                                        'if_inerface_identity'      => "'".addslashes((int)$value['content']['if_inerface_identity'])."'",
                                        'if_inerface_check'         => "'".addslashes((int)$value['content']['if_inerface_check'])."'",
                                        'if_turn'                   => "'".addslashes((int)$value['content']['if_turn'])."'",
                                        'if_turn_type'              => "'".addslashes((int)$value['content']['if_turn_type'])."'",
                                        'if_turn_url'               => "'".addslashes($value['content']['if_turn_url'])."'",
                                        'rank'                      => "'".addslashes((int)$value['content']['rank'])."'",
                                    );
                                    $this_content_id = func::db_insert($SETTING['config_db_prefix'].$k, $sql_data);
                                    if (!preg_match("/^[1-9][0-9]{0,10}$/i", $this_content_id)) {
                                        $error = true;
                                        $ajax_response->alert("更新数据库出现错误![".$SETTING['config_db_prefix'].$k."]");
                                    }
                                } elseif ($sys->model_array['level'][$k] == "content" && $sys->model_array['recordtype'][$k] == "1") {
                                    $sql_data = array();
                                    $this_total_record = func::db_count_record($SETTING['config_db_prefix'].$k, "content_id='".addslashes($this_content_id)."'");
                                    if ($this_total_record > 0) {
                                        $this_content_info  = func::db_select($SETTING['config_db_prefix'].$k, $k."_id", "content_id='".addslashes($this_content_id)."'", "1", $k."_id DESC");
                                        $upper_where_id = "0";
                                        $this_where_id  = "0";
                                        $upper_id       = $this_content_id;
                                        $this_id        = $this_content_info[0][$k."_id"];
                                        if ($this_total_record > 1) {
                                            $this_delete_result = func::db_delete($SETTING['config_db_prefix'].$k,  $k."_id!=".$this_where_id);
                                        }
                                        if (is_array($sys->model_array['field'][$k]) && count($sys->model_array['field'][$k]) > 0) {
                                            $sql_data['content_id'] = "'".addslashes($this_content_id)."'";
                                            $sql_data["member_id"] = "'".addslashes($ADMIN['mid'])."'";
                                            foreach ($sys->model_array['field'][$k] as $k_f => $v_f) {
                                                if ($sys->field_array[$k][$v_f]['team'] == "4") {
                                                    if ($sys->field_array[$k][$v_f]['type'] == "checkbox") {
                                                        if (is_array($value['content_info'][$k][$upper_where_id][$this_where_id][$v_f]) && count($value['content_info'][$k][$upper_where_id][$this_where_id][$v_f])>0){
                                                            $this_value = implode(",", $value['content_info'][$k][$upper_where_id][$this_where_id][$v_f]);
                                                        }
                                                        $sql_data[$v_f] = "'".addslashes($this_value)."'";
                                                    } elseif ($sys->field_array[$k][$v_f]['type'] == "html") {
                                                        $sql_data[$v_f] = "'".addslashes($value[''.$k.'_'.$upper_where_id.'_'.$this_where_id.'_'.$v_f.''])."'";
                                                    } elseif ($sys->field_array[$k][$v_f]['type'] == "attach") {
                                                        $sql_data[$v_f] = "'".addslashes($k."_".$upper_id."_".$this_id."_".$v_f)."'";
                                                        $sql_data_attach = array();
                                                        $sql_data_attach['key_id']  = "'".addslashes($k.'_'.$upper_id.'_'.$this_id.'_'.$v_f)."'";
                                                        $result = func::db_update(DB_TABLE_CONTENT_ATTACH, $sql_data_attach, "key_id='".$value['content_info'][$k][$upper_where_id][$this_where_id][$v_f]."'");
                                                        if (!$result) {
                                                            $error = true;
                                                            $ajax_response->alert("更新数据库出现错误![".DB_TABLE_CONTENT_ATTACH."_DB_UPDATE]");
                                                        }
                                                    } else {
                                                        $sql_data[$v_f] = "'".addslashes($value['content_info'][$k][$upper_where_id][$this_where_id][$v_f])."'";
                                                    }
                                                }
                                            }
                                            $result = func::db_update($SETTING['config_db_prefix'].$k, $sql_data, $k."_id='".$this_id."'");
                                            if (!$result) {
                                                $error = true;
                                                $ajax_response->alert("更新数据库出现错误![".$SETTING['config_db_prefix'].$k."_DB_UPDATE]");
                                            }
                                        }
                                    } else {
                                        $upper_where_id = 0;
                                        $this_where_id  = 0;
                                        $upper_id       = $this_content_id;
                                        $this_id        = 0;
                                        if (is_array($sys->model_array['field'][$k]) && count($sys->model_array['field'][$k]) > 0) {
                                            $sql_data['content_id'] = "'".addslashes($this_content_id)."'";
                                            $sql_data["member_id"] = "'".addslashes($ADMIN['mid'])."'";
                                            foreach ($sys->model_array['field'][$k] as $k_f => $v_f) {
                                                if ($sys->field_array[$k][$v_f]['team'] == "4") {
                                                    if ($sys->field_array[$k][$v_f]['type'] == "checkbox") {
                                                        if (is_array($value['content_info'][$k][$upper_where_id][$this_where_id][$v_f]) && count($value['content_info'][$k][$upper_where_id][$this_where_id][$v_f])>0){
                                                            $this_value = implode(",", $value['content_info'][$k][$upper_where_id][$this_where_id][$v_f]);
                                                        }
                                                        $sql_data[$v_f] = "'".addslashes($this_value)."'";
                                                    } elseif ($sys->field_array[$k][$v_f]['type'] == "html") {
                                                        $sql_data[$v_f] = "'".addslashes($value[''.$k.'_'.$upper_where_id.'_'.$this_where_id.'_'.$v_f.''])."'";
                                                    } else {
                                                        $sql_data[$v_f] = "'".addslashes($value['content_info'][$k][$upper_where_id][$this_where_id][$v_f])."'";
                                                    }
                                                }
                                            }
                                            $this_id = func::db_insert($SETTING['config_db_prefix'].$k, $sql_data);
                                            if (!preg_match("/^[1-9][0-9]{0,10}$/i", $this_id)) {
                                                $error = true;
                                                $ajax_response->alert("更新数据库出现错误![".$SETTING['config_db_prefix'].$k."_DB_INSERT]");
                                            } else {
                                                $sql_data = array();
                                                foreach ($sys->model_array['field'][$k] as $k_f => $v_f) {
                                                    if ($sys->field_array[$k][$v_f]['team'] == "4") {
                                                        if ($sys->field_array[$k][$v_f]['type'] == "attach") {
                                                            $sql_data[$v_f] = "'".addslashes($k."_".$upper_id."_".$this_id."_".$v_f)."'";
                                                            $sql_data_attach = array();
                                                            $sql_data_attach['key_id']  = "'".addslashes($k.'_'.$upper_id.'_'.$this_id.'_'.$v_f)."'";
                                                            $result = func::db_update(DB_TABLE_CONTENT_ATTACH, $sql_data_attach, "key_id='".$value['content_info'][$k][$upper_where_id][$this_where_id][$v_f]."'");
                                                            if (!$result) {
                                                                $error = true;
                                                                $ajax_response->alert("更新数据库出现错误![".DB_TABLE_CONTENT_ATTACH."_DB_UPDATE]");
                                                            }
                                                        }
                                                    }
                                                }
                                                $result = func::db_update($SETTING['config_db_prefix'].$k, $sql_data, $k."_id='".$this_id."'");
                                                if (!$result) {
                                                    $error = true;
                                                    $ajax_response->alert("更新数据库出现错误![".$SETTING['config_db_prefix'].$k."_DB_UPDATE]");
                                                }
                                            }
                                        }
                                    }
                                } else {
                                    if (is_array($value['content_info'][$k]) && count($value['content_info'][$k]) > 0) {
                                        foreach($value['content_info'][$k] as $k_g => $v_g) {
                                            if (is_array($v_g) && count($v_g) > 0) {
                                                foreach($v_g as $k_r => $v_r) {
                                                    $sql_data = array();
                                                    if (is_array($sys->model_array['field'][$k]) && count($sys->model_array['field'][$k]) > 0) {
                                                        if ($sys->model_array['level'][$k] == "content") {
                                                            $this_upper_id = $this_content_id;
                                                        } else {
                                                            $this_upper_id = $k_g;
                                                        }
                                                        $sql_data[$sys->model_array['level'][$k]."_id"] = "'".addslashes($this_upper_id)."'";
                                                        $sql_data["member_id"] = "'".addslashes($ADMIN['mid'])."'";
                                                        foreach ($sys->model_array['field'][$k] as $k_f => $v_f) {
                                                            if ($sys->field_array[$k][$v_f]['team'] == "4") {
                                                                if ($sys->field_array[$k][$v_f]['type'] == "checkbox") {
                                                                    if (is_array($value['content_info'][$k][$k_g][$k_r][$v_f]) && count($value['content_info'][$k][$k_g][$k_r][$v_f])>0){
                                                                        $this_value = implode(",", $value['content_info'][$k][$k_g][$k_r][$v_f]);
                                                                    }
                                                                    $sql_data[$v_f] = "'".addslashes($this_value)."'";
                                                                } elseif ($sys->field_array[$k][$v_f]['type'] == "html") {
                                                                    $sql_data[$v_f] = "'".addslashes($value[''.$k.'_'.$k_g.'_'.$k_r.'_'.$v_f.''])."'";
                                                                } elseif ($sys->field_array[$k][$v_f]['type'] == "attach") {
                                                                    $sql_data[$v_f] = "'".addslashes($k."_".$this_upper_id."_".$k_r."_".$v_f)."'";
                                                                    $sql_data_attach = array();
                                                                    $sql_data_attach['key_id']  = "'".addslashes($k.'_'.$this_upper_id.'_'.$k_r.'_'.$v_f)."'";
                                                                    $result = func::db_update(DB_TABLE_CONTENT_ATTACH, $sql_data_attach, "key_id='".$value['content_info'][$k][$k_g][$k_r][$v_f]."'");
                                                                    if (!$result) {
                                                                        $error = true;
                                                                        $ajax_response->alert("更新数据库出现错误![".DB_TABLE_CONTENT_ATTACH."_DB_UPDATE]");
                                                                    }
                                                                } else {
                                                                    $sql_data[$v_f] = "'".addslashes($value['content_info'][$k][$k_g][$k_r][$v_f])."'";
                                                                }
                                                            }
                                                        }
                                                        $result = func::db_update($SETTING['config_db_prefix'].$k, $sql_data, $k."_id='".$k_r."'");
                                                        if (!$result) {
                                                            $error = true;
                                                            $ajax_response->alert("更新数据库出现错误![".$SETTING['config_db_prefix'].$k."_DB_UPDATE]");
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    // delete temp attach
                                    if (is_array($value['content_add'][$k]) && count($value['content_add'][$k]) > 0) {
                                        foreach($value['content_add'][$k] as $k_g => $v_g) {
                                            if (is_array($sys->model_array['field'][$k]) && count($sys->model_array['field'][$k]) > 0) {
                                                foreach ($sys->model_array['field'][$k] as $k_f => $v_f) {
                                                    if ($sys->field_array[$k][$v_f]['team'] == "4" && $sys->field_array[$k][$v_f]['type'] == "attach") {
                                                        if (is_array($value['content_attach']) && count($value['content_attach'])) {
                                                            foreach ($value['content_attach'] as $k_a => $v_a) {
                                                                if($v_a['key_id'] == $value['content_add'][$k][$k_g][0][$v_f]){
                                                                    if (file_exists($v_a['filename'])) {
                                                                        @chmod($v_a['filename'], $SETTING['chmod_mode_file']);
                                                                        @unlink($v_a['filename']);
                                                                    }
                                                                    $result = func::db_delete(DB_TABLE_CONTENT_ATTACH, "id=".$k_a."");
                                                                    if (!$result) {
                                                                        $error = true;
                                                                        $ajax_response->alert("更新数据库出现错误![".DB_TABLE_CONTENT_ATTACH."_DB_DELETE]");
                                                                    } else {
                                                                        unset($value['content_attach'][$k_a]);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        // attach brief update
                        if (is_array($value['content_attach']) && count($value['content_attach'])>0) {
                            foreach ($value['content_attach'] as $k_a => $v_a) {
                                $sql_data_attach = array();
                                $sql_data_attach['brief']  = "'".addslashes($v_a['brief'])."'";
                                $result = func::db_update(DB_TABLE_CONTENT_ATTACH, $sql_data_attach, "id='".$k_a."'");
                                if (!$result) {
                                    $error = true;
                                    $ajax_response->alert("更新数据库出现错误![".DB_TABLE_CONTENT_ATTACH."_DB_UPDATE]");
                                }
                            }
                        }
                        // cover
                        if (!$error) {
                            $sql_data = array(
                                "content_id" => "'".$this_content_id."'",
                            );
                            $result = func::db_update(DB_TABLE_CONTENT_COVER, $sql_data, "content_id=0 AND admin_id='".$ADMIN['mid']."'");
                            if (!$result) {
                                $ajax_response->alert("封面数据库更新失败!");
                            }
                        }
                        // trans
                        if (!$error) {
                            if (is_array($trans_list) && count($trans_list)>0) {
                                foreach($trans_list as $v_trans) {
                                    $this_if_have = func::db_count_record(DB_TABLE_TRANS_CONTENT, "content_id='".addslashes($this_content_id)."' AND trans_group_id='".$v_trans['id']."'");
                                    if ( preg_match("/^[1-9][0-9]{0,10}$/i", $value['content']['trans'][$v_trans['id']] )) {
                                        if ($this_if_have > 0) {
                                            $sql_data = array(
                                                "trans_id"          => "".$value['content']['trans'][$v_trans['id']]."",
                                            );
                                            $result = func::db_update(DB_TABLE_TRANS_CONTENT, $sql_data, "content_id='".addslashes($this_content_id)."' AND trans_group_id='".$v_trans['id']."'");
                                            if (!$result) {
                                                $ajax_response->alert("更新数据库发生错误[".DB_TABLE_TRANS_CONTENT."]");
                                            }
                                        } else {
                                            $sql_data = array(
                                                "content_id"        => "".addslashes($this_content_id)."",
                                                "trans_group_id"    => "".$v_trans['id']."",
                                                "trans_id"          => "".$value['content']['trans'][$v_trans['id']]."",
                                            );
                                            $result = func::db_insert(DB_TABLE_TRANS_CONTENT, $sql_data);
                                            if (!$result) {
                                                $ajax_response->alert("插入数据库发生错误[".DB_TABLE_TRANS_CONTENT."]");
                                            }
                                        }
                                    } else {
                                        $result_delete = func::db_delete(DB_TABLE_TRANS_CONTENT, "content_id='".addslashes($this_content_id)."' AND trans_group_id='".$v_trans['id']."'");
                                    }
                                }
                            }
                        }
                        // scheduler
                        if (!$error) {
                            $result = func::db_delete(DB_TABLE_SCHEDULER, "content_id=".$this_content_id." AND channel_id NOT IN (".implode(",",$value['content']['channel']).")");
                            if (!$result) {
                                $ajax_response->alert("清理所属类别失败[".DB_TABLE_SCHEDULER."]");
                            } else {
                                foreach($value['content']['channel'] as $v) {
                                    $if_exists_channel = func::db_count_record(DB_TABLE_SCHEDULER, "content_id='".$this_content_id."' AND channel_id='".$v."'");
                                    if ($if_exists_channel <= 0) {
                                        $sql_data = array(
                                                        "content_id"  => "'".$this_content_id."'",
                                                        "channel_id"  => "'".$v."'",
                                                    );
                                        $result = func::db_insert(DB_TABLE_SCHEDULER, $sql_data);
                                        if (!$result) {
                                            $ajax_response->alert("更新调度表失败[".$db->ErrorMsg()."]");
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if($error){
                        $ajax_response->assign($submit,"value",$submit_value);
                        $ajax_response->assign($submit,"disabled",false);
                    }else{
                        $ajax_response->redirect($CONFIGURE['common']['control_admin']."?act=content&channel_id=".$sys->get['channel_id']."&pag=".$sys->get['pag']);
                    }
                }
            }
        }
    }
    return $ajax_response;
}
$bwajax->register(XAJAX_FUNCTION, "submit_form");
//////

if($sys->get['ope'] == "add"){

    if (!preg_match("/^[1-9][0-9]*$/",$sys->get['channel_id'])){
        $sys->prompt("failed","非法操作!<!-- channel_id error -->");
    }else{

        if ( $ADMIN['ag_privilege']['content'] != "1" ) {
            $sys->prompt("failed","您没有权限进行此操作!<!-- privilege not allow -->");
        } else {

            $sys->return_channel_info($sys->get['channel_id']);
            $sys->return_channel_path($sys->channel_info['channel_id']);

            $sys->return_setmodel_info($sys->channel_info['setmodel_id']);
            $sys->return_table_list();
            $sys->return_field_array();
            $sys->return_model_array();

            if (is_array($sys->model_array['tree']) && count($sys->model_array['tree']) > 0) {
                foreach($sys->model_array['tree'] as $k => $v) {
                    if (is_array($v) && count($v) > 0) {
                        if ($k != "content" && $sys->model_array['recordtype'][$k] != "1") {
                            $sql_select = implode(",", $sys->model_array['select'][$k]);
                            $sql_table  = implode("", $sys->model_array['table'][$k]);
                            if ($sys->model_array['level'][$k] == "content"){
                                $sql_where = $k.".content_id=0 AND ".$k.".member_id=".$ADMIN['mid']."";
                            } else {
                                $sql_where = $sys->model_array['level'][$k].".content_id=0 AND ".$sys->model_array['level'][$k].".member_id=".$ADMIN['mid']."";
                            }
                            $sql = "SELECT ".$sql_select." ".$sql_table."
                                    WHERE ".$sql_where."
                                    GROUP BY ".$k.".".$k."_id";
                            $result = &$db->Execute($sql);
                            if (!$result) {
                                echo $db->ErrorMsg();
                            } else {
                                while (!$result->EOF) {
                                    if (is_array($sys->model_array['field'][$k]) && count($sys->model_array['field'][$k]) > 0) {
                                        foreach ($sys->model_array['field'][$k] as $k_f => $v_f) {
                                            $content_info[$k][$result->fields[$sys->model_array['level'][$k]."_id"]][$result->fields[$k."_id"]][$v_f] = $result->fields[$v_f];
                                        }
                                    }
                                    $result->MoveNext();
                                }
                            }
                        }
                    }
                }
            }

            $channel_list[] = $sys->get['channel_id'];
            $channel_tree = $sys->channel_tree;
            if (is_array($channel_tree) && count($channel_tree) > 0) {
                foreach($channel_tree as $v){
                    if ($v['setmodel_id'] != $sys->channel_info['setmodel_id']) {
                        $channel_tree[$v['id']]['disable'] = "1";
                    }
                }
            }

            $array_select   = array("content_prefix","content_color","content_fontstyle","content_decoration");
            $select_option  = $sys->return_select($array_select);

            $trans_list     = $sys->return_trans_list($sys->channel_info['setmodel_id']);

            $prompt         = "cover_upload_prompt";
            $list           = "cover_str";
            $thumb          = "";
            $filelist       = func::db_select(DB_TABLE_CONTENT_COVER, "*", "content_id=0 AND admin_id=".$ADMIN['mid'], "", "id DESC");
            $file_value     = $filelist['0'];
            if (!empty($file_value)){
                $path       = $SETTING['dir_content_cover']."/".$file_value['dir'];
                if (!file_exists($path)) { func::make_dir($path); }
                if (!empty($file_value['filename']) && file_exists($path.$file_value['filename'])) {
                    list($width, $height, $type, $attr) = getimagesize($path.$file_value['filename']);
                    $size   = $width > $height ? "width=45" : "height=45";
                    $thumb  = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr align=\"center\"><td width=\"30%\"><span onclick=\"xajax_cover_del('add','".$ADMIN['mid']."','".$file_value['id']."','".$list."','".$prompt."');\" style=\"cursor:pointer;color:#EA7408;\"><img src=\"".$SETTING['dir_images_admin']."/icon_delete.gif\" alt=\"Delete\" /></span></td><td width=\"70%\"><div style=\"border:1px solid #CCCCCC;background-color:#EEEEEE;\"><img src=\"".$path.$file_value['filename']."\" ".$size." border=\"0\" align=\"absmiddle\" /></div></td></tr></table>\n";
                }
            }
            if (empty($thumb)) {
                $thumb      = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr align=\"center\"><td width=\"30%\">&nbsp;</td><td width=\"70%\"><div style=\"border:1px solid #CCCCCC;background-color:#EEEEEE;width:45px;height:45px;\"><br />缩略图</div></td></tr></table>\n";
            }
            $t->assign( $list, $thumb );

            $t->assign(array(
                "channel_info"          => $sys->channel_info,
                "channel_path"       => $sys->channel_path,
                "setmodel_info"         => $sys->setmodel_info,
                "table_list"            => $sys->table_list,
                "field_array"           => $sys->field_array,
                "model_array"           => $sys->model_array,
                "content_info"          => $content_info,

                "channel_list"          => $channel_list,
                "channel_tree"          => $channel_tree,
                "select_option"         => $select_option,
                "trans_list"            => $trans_list,

                "setting_cover"         => $setting_cover,
                "setting_attach"        => $setting_attach,
                "attach_list_result"    => $attach_list_result,
                "attach_select_result"  => $attach_select_result,
            ));
        }
    }

}elseif($sys->get['ope'] == "amend"){

    if ( $ADMIN['ag_privilege']['content'] != "1" ) {
        $sys->prompt("failed","您没有权限进行此操作!<!-- privilege not allow -->");
    } else {
        if (!preg_match("/^[1-9][0-9]*$/",$sys->get['scheduler_id'])){
            $sys->prompt("failed","非法操作!<!-- scheduler_id error -->");
        }else{
            $scheduler_info = $sys->return_scheduler_info($sys->get['scheduler_id']);
            if (!preg_match("/^[1-9][0-9]*$/",$scheduler_info['scheduler_id'])) {
                $sys->prompt("failed","非法操作!<!-- scheduler_id error -->");
            } elseif (!preg_match("/^[1-9][0-9]*$/",$scheduler_info['channel_id'])) {
                $sys->prompt("failed","非法操作!<!-- channel_id error -->");
            } elseif (!preg_match("/^[1-9][0-9]*$/",$scheduler_info['content_id'])) {
                $sys->prompt("failed","非法操作!<!-- content_id error -->");
            } else {

                $sys->return_channel_info($scheduler_info['channel_id']);
                $sys->return_channel_path($sys->channel_info['channel_id']);

                $sys->return_setmodel_info($sys->channel_info['setmodel_id']);
                $sys->return_table_list();
                $sys->return_field_array();
                $sys->return_model_array();

                $content_info   = $sys->return_content_info($scheduler_info['scheduler_id'],false);

                $channel_id = func::db_select(DB_TABLE_SCHEDULER, "channel_id", "content_id=".$scheduler_info['content_id'], "", "id DESC");
                if (is_array($channel_id) && count($channel_id) > 0) {
                    foreach($channel_id as $channel_tmp){
                        $channel_list[] = $channel_tmp['channel_id'];
                    }
                }
                $channel_tree = $sys->channel_tree;
                if (is_array($channel_tree) && count($channel_tree) > 0) {
                    foreach($channel_tree as $v){
                        if ($v['setmodel_id'] != $sys->channel_info['setmodel_id']) {
                            $channel_tree[$v['id']]['disable'] = "1";
                        }
                    }
                }

                $array_select   = array("content_prefix","content_color","content_fontstyle","content_decoration");
                $select_option  = $sys->return_select($array_select);

                $trans_list     = $sys->return_trans_list($sys->channel_info['setmodel_id']);

                $prompt         = "cover_upload_prompt";
                $list           = "cover_str";
                $thumb          = "";
                $filelist       = func::db_select(DB_TABLE_CONTENT_COVER, "*", "content_id=".$scheduler_info['content_id'], "", "id DESC");
                $file_value     = $filelist['0'];
                if (!empty($file_value)){
                    $path       = $SETTING['dir_content_cover']."/".$file_value['dir'];
                    if (!file_exists($path)) { func::make_dir($path); }
                    if (!empty($file_value['filename']) && file_exists($path.$file_value['filename'])) {
                        list($width, $height, $type, $attr) = getimagesize($path.$file_value['filename']);
                        $size   = $width > $height ? "width=45" : "height=45";
                        $thumb  = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr align=\"center\"><td width=\"30%\"><span onclick=\"xajax_cover_del('amend','".$scheduler_info['content_id']."','".$file_value['id']."','".$list."','".$prompt."');\" style=\"cursor:pointer;color:#EA7408;\"><img src=\"".$SETTING['dir_images_admin']."/icon_delete.gif\" alt=\"Delete\" /></span></td><td width=\"70%\"><div style=\"border:1px solid #CCCCCC;background-color:#EEEEEE;\"><img src=\"".$path.$file_value['filename']."\" ".$size." border=\"0\" align=\"absmiddle\" /></div></td></tr></table>\n";
                    }
                }
                if (empty($thumb)) {
                    $thumb      = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr align=\"center\"><td width=\"30%\">&nbsp;</td><td width=\"70%\"><div style=\"border:1px solid #CCCCCC;background-color:#EEEEEE;width:45px;height:45px;\"><br />缩略图</div></td></tr></table>\n";
                }
                $t->assign( $list, $thumb );

                $t->assign(array(
                    "channel_info"          => $sys->channel_info,
                    "channel_path"       => $sys->channel_path,
                    "setmodel_info"         => $sys->setmodel_info,
                    "table_list"            => $sys->table_list,
                    "field_array"           => $sys->field_array,
                    "model_array"           => $sys->model_array,
                    "scheduler_info"        => $scheduler_info,
                    "content_info"          => $content_info,

                    "channel_list"          => $channel_list,
                    "channel_tree"          => $channel_tree,
                    "select_option"         => $select_option,
                    "trans_list"            => $trans_list,

                    "setting_cover"         => $setting_cover,
                    "setting_attach"        => $setting_attach,
                    "attach_list_result"    => $attach_list_result,
                    "attach_select_result"  => $attach_select_result,
                ));
            }
        }
    }

}elseif($sys->get['ope'] == "savecover_upload"){
    $bwupload->lang_msg = array(
        '0'             => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['0'],
        '1'             => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['1'],
        '2'             => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['2'],
        '3'             => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['3'],
        '4'             => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['4'],
        '6'             => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['6'],
        '7'             => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['7'],
        '8'             => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['8'],
        'invalid'       => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['invalid'],
        'error_size'    => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['error_size'],
        'error_type'    => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['error_type'],
        'upload_failed' => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['upload_failed'],
        'error_empty'   => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['error_empty'],
    );
    $bwupload->set_size($setting_cover['size']);
    $bwupload->set_type($setting_cover['type']);

    $result_state   = "1";
    $error_msg      = "";

    if ($sys->get['type'] == "amend"){

        $scheduler_info = $sys->return_scheduler_info($sys->get['scheduler_id']);
        $content_id     = $scheduler_info['content_id'];
        if (!preg_match("/^[1-9][0-9]*$/",$content_id)){
            $result_state = "0";
            $error_msg = "非法操作<!-- content_id error -->";
        } else {
            $filelist = func::db_select(DB_TABLE_CONTENT_COVER, "*", "content_id=".$content_id, "", "id DESC");
            if (count($filelist) > 1){
                $result = func::db_delete(DB_TABLE_CONTENT_COVER, "content_id=".$content_id." AND id!=".$filelist[0]['id']);
                if (!$result) {
                    $result_state = "0";
                    $error_msg = "删除多余的记录失败<!-- delete excrescent error -->";
                }
            }
            if ($result_state == "1") {
                $file_value = $filelist[0];
                if (!empty($file_value['dir'])){
                    $dir    = $file_value['dir'];
                    $path   = $SETTING['dir_content_cover']."/".$dir;
                } else {
                    $dir    = $setting_cover['dir'];
                    $path   = $SETTING['dir_content_cover']."/".$dir;
                }
                if (!file_exists($path)) { func::make_dir($path); }

                if( !$bwupload->upload_file($path,"cover_upload") ){
                    $result_state = "0";
                    $error_msg = $bwupload->error_msg."<!-- upload error -->";
                }else{
                    $result_state = $bwupload->proceed['cover_upload']['succeed'];
                    $error_msg = $bwupload->proceed['cover_upload']['error']."<!-- upload error message -->";
                    if ($result_state == "1") {
                        if (!empty($file_value['filename'])){
                            if (file_exists($path.$file_value['filename'])) {
                                @chmod($path.$file_value['filename'], $SETTING['chmod_mode_file']);
                                @unlink($path.$file_value['filename']);
                            }
                        }
                        $sql_data = array(
                            "dir"           => "'".$dir."'",
                            "filename"      => "'".$bwupload->proceed['cover_upload']['result_name']."'",
                            "content_id"    => "'".$content_id."'",
                            "admin_id"      => "'".$ADMIN['mid']."'",
                        );
                        if (count($filelist) > 0) {
                            $result = func::db_update(DB_TABLE_CONTENT_COVER, $sql_data, "id=".$file_value['id']);
                        } else {
                            $result = func::db_insert(DB_TABLE_CONTENT_COVER, $sql_data);
                        }
                        if (!$result) {
                            if (file_exists($path.$bwupload->proceed['cover_upload']['result_name'])) {
                                @chmod($path.$bwupload->proceed['cover_upload']['result_name'], $SETTING['chmod_mode_file']);
                                @unlink($path.$bwupload->proceed['cover_upload']['result_name']);
                            }
                            $result_state = "0";
                            $error_msg = "更新数据库失败<!-- upload db cover error -->";
                        }
                    }
                }
            }
        }
        $CONFIGURE['common']['if_output_template'] = "0";
        $prompt_style = $result_state == "1" ? "prompt_succeed" : "prompt_failed";
        $bwjs->write("parent.xajax_cover_upload_return('".$result_state."',
                   'amend',
                   '".$sys->get['scheduler_id']."',
                   'content_amend',
                   'cover_upload_input',
                   '<input type=\"file\" id=\"cover_upload\" name=\"cover_upload\" size=\"30\" style=\"width:250px;\" class=\"input\" />',
                   'cover_upload_submit',
                   'cover_str',
                   'cover_upload_prompt',
                   '<span class=\"".$prompt_style."\">".$error_msg."</span>');");
    } else {

        $admin_id = $ADMIN['mid'];
        if (!preg_match("/^[1-9][0-9]*$/",$admin_id)){
            $result_state = "0";
            $error_msg = "非法操作<!-- admin_id error -->";
        } else {
            $filelist = func::db_select(DB_TABLE_CONTENT_COVER, "*", "content_id=0 AND admin_id=".$admin_id, "", "id DESC");
            if (count($filelist) > 1){
                $result = func::db_delete(DB_TABLE_CONTENT_COVER, "content_id=0 AND admin_id=".$admin_id." AND id!=".$filelist[0]['id']);
                if (!$result) {
                    $result_state = "0";
                    $error_msg = "删除多余的记录失败<!-- delete excrescent error -->";
                }
            }
            if ($result_state == "1") {
                $file_value = $filelist[0];
                if (!empty($file_value['dir'])){
                    $dir    = $file_value['dir'];
                    $path   = $SETTING['dir_content_cover']."/".$dir;
                } else {
                    $dir    = $setting_cover['dir'];
                    $path   = $SETTING['dir_content_cover']."/".$dir;
                }
                if (!file_exists($path)) { func::make_dir($path); }

                if( !$bwupload->upload_file($path,"cover_upload") ){
                    $result_state = "0";
                    $error_msg = $bwupload->error_msg."<!-- upload error -->";
                }else{
                    $result_state = $bwupload->proceed['cover_upload']['succeed'];
                    $error_msg = $bwupload->proceed['cover_upload']['error']."<!-- upload error message -->";
                    if ($result_state == "1") {
                        if (!empty($file_value['filename'])){
                            if (file_exists($path.$file_value['filename'])) {
                                @chmod($path.$file_value['filename'], $SETTING['chmod_mode_file']);
                                @unlink($path.$file_value['filename']);
                            }
                        }
                        $sql_data = array(
                            "dir"           => "'".$dir."'",
                            "filename"      => "'".$bwupload->proceed['cover_upload']['result_name']."'",
                            "content_id"    => "'0'",
                            "admin_id"      => "'".$ADMIN['mid']."'",
                        );
                        if (count($filelist) > 0) {
                            $result = func::db_update(DB_TABLE_CONTENT_COVER, $sql_data, "id=".$file_value['id']);
                        } else {
                            $result = func::db_insert(DB_TABLE_CONTENT_COVER, $sql_data);
                        }
                        if (!$result) {
                            if (file_exists($path.$bwupload->proceed['cover_upload']['result_name'])) {
                                @chmod($path.$bwupload->proceed['cover_upload']['result_name'], $SETTING['chmod_mode_file']);
                                @unlink($path.$bwupload->proceed['cover_upload']['result_name']);
                            }
                            $result_state = "0";
                            $error_msg = "更新数据库失败<!-- upload db cover error -->";
                        }
                    }
                }
            }
        }
        $CONFIGURE['common']['if_output_template'] = "0";
        $prompt_style = $result_state == "1" ? "prompt_succeed" : "prompt_failed";
        $bwjs->write("parent.xajax_cover_upload_return('".$result_state."',
                   'add',
                   '".$ADMIN['mid']."',
                   'content_add',
                   'cover_upload_input',
                   '<input type=\"file\" id=\"cover_upload\" name=\"cover_upload\" size=\"30\" style=\"width:250px;\" class=\"input\" />',
                   'cover_upload_submit',
                   'cover_str',
                   'cover_upload_prompt',
                   '<span class=\"".$prompt_style."\">".$error_msg."</span>');");
    }

}elseif($sys->get['ope'] == "saveattach_upload"){
    $bwupload->lang_msg = array(
        '0'             => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['0'],
        '1'             => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['1'],
        '2'             => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['2'],
        '3'             => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['3'],
        '4'             => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['4'],
        '6'             => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['6'],
        '7'             => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['7'],
        '8'             => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['8'],
        'invalid'       => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['invalid'],
        'error_size'    => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['error_size'],
        'error_type'    => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['error_type'],
        'upload_failed' => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['upload_failed'],
        'error_empty'   => $LANGUAGE['s']['_public']['lib_class_bwupload_class']['error_empty'],
    );

    $result_state   = "1";
    $error_msg      = "";

    $area_id        = $sys->get['area_id'];
    $key_id         = $sys->get['key_id'];
    $field_id       = $sys->get['field_id'];
    if (!preg_match("/^[a-z0-9_]+$/",$key_id)){
        $result_state = "0";
        $error_msg = "非法操作<!-- key_id error -->";
    } elseif (!preg_match("/^[1-9][0-9]{0,10}$/",$field_id)){
        $result_state = "0";
        $error_msg = "非法操作<!-- field_id error -->";
    } else {
        $field_item  = func::db_select(DB_TABLE_SETMODEL_FIELD, "*", "id=".$field_id);
        $field_item  = $field_item[0];
        if (empty($field_item['value'])) {
            $result_state = "0";
            $error_msg = "没有允许的附件类型,请在模型中设定附件类型<!-- value error -->";
        } else {

            $dir    = $setting_attach['dir'];
            $path   = $SETTING['dir_content_attach']."/".$dir;
            if (!file_exists($path)) { func::make_dir($path); }

            $bwupload->set_size($setting_attach['size']);
            $bwupload->set_type($field_item['value']);
            if( !$bwupload->upload_file($path,$key_id."_upload") ){
                $result_state = "0";
                $error_msg = $bwupload->error_msg."<!-- upload error -->";
            }else{
                $result_state = $bwupload->proceed[$key_id.'_upload']['succeed'];
                $error_msg = $bwupload->proceed[$key_id.'_upload']['error']."<!-- upload error message -->";
                if ($result_state == "1") {
                    $sql_data = array(
                        "brief"             => "'".addslashes($_POST[$key_id.'_brief'])."'",
                        "dir"               => "'".$dir."'",
                        "filename"          => "'".$bwupload->proceed[$key_id.'_upload']['result_name']."'",
                        "key_id"            => "'".$sys->get['key_id']."'",
                        "admin_id"          => "'".(int)$ADMIN['mid']."'",
                        "time"              => $sys->nowtime,
                        "down"              => "0",
                    );
                    $result = func::db_insert(DB_TABLE_CONTENT_ATTACH, $sql_data);
                    if (!$result) {
                        if (file_exists($path.$bwupload->proceed[$key_id.'_upload']['result_name'])) {
                            @chmod($path.$bwupload->proceed[$key_id.'_upload']['result_name'], $SETTING['chmod_mode_file']);
                            @unlink($path.$bwupload->proceed[$key_id.'_upload']['result_name']);
                        }
                        $result_state = "0";
                        $error_msg = "更新数据库失败<!-- upload db attach_name error -->";
                    }
                }
            }
        }
    }
    $CONFIGURE['common']['if_output_template'] = "0";
    $prompt_style = $result_state == "1" ? "prompt_succeed" : "prompt_failed";
    $bwjs->write("parent.xajax_attach_upload_return('".$area_id."',
        '".$result_state."',
        '".$key_id."_upload_submit',
        '".$key_id."_upload_prompt',
        '<span class=\"".$prompt_style."\">".$error_msg."</span>');");

}elseif($sys->get['ope'] == "if_enable"){

    if ( $ADMIN['ag_privilege']['content'] != "1" ) {
        $sys->prompt("failed","您没有权限进行此操作!<!-- privilege not allow -->");
    } else {
        // check the post
        if (!preg_match("/^[1-9][0-9]*$/",$sys->get['scheduler_id'])) {
            $sys->prompt("failed","非法操作!<!-- scheduler_id error -->");
        } elseif (!preg_match("/^[123]{1}$/",$sys->get['if_enable'])) {
            $sys->prompt("failed","非法操作!<!-- if_enable error -->");
        } else {

            $scheduler_info = $sys->return_scheduler_info($sys->get['scheduler_id']);

            if (!preg_match("/^[1-9][0-9]*$/",$scheduler_info['content_id'])) {
                $sys->prompt("failed","非法操作!<!-- content_id error -->");
            } else {
                $sql_data = array(
                    "if_enable" => $sys->get['if_enable'],
                );
                $result = func::db_update(DB_TABLE_CONTENT, $sql_data, "content_id='".$scheduler_info['content_id']."'");
                if (!$result) {
                    $sys->prompt("failed","非法操作!<!-- db_update failed -->");
                }
                $sys->prompt("jump",$CONFIGURE['common']['control_admin']."?act=content&channel_id=".$scheduler_info['channel_id']."&pag=".$sys->get['pag']);
            }
        }
   }

}elseif($sys->get['ope'] == "if_top"){
    if ( $ADMIN['ag_privilege']['content'] != "1" ) {
        $sys->prompt("failed","您没有权限进行此操作!<!-- privilege not allow -->");
    } else {
        // check the post
        if (!preg_match("/^[1-9][0-9]*$/",$sys->get['scheduler_id'])) {
            $sys->prompt("failed","非法操作!<!-- scheduler_id error -->");
        } elseif (!preg_match("/^[123]{1}$/",$sys->get['if_top'])) {
            $sys->prompt("failed","非法操作!<!-- if_top error -->");
        } else {

            $scheduler_info = $sys->return_scheduler_info($sys->get['scheduler_id']);

            if (!preg_match("/^[1-9][0-9]*$/",$scheduler_info['content_id'])) {
                $sys->prompt("failed","非法操作!<!-- content_id error -->");
            } else {
                $sql_data = array(
                    "if_top" => $sys->get['if_top'],
                );
                $result = func::db_update(DB_TABLE_CONTENT, $sql_data, "content_id='".$scheduler_info['content_id']."'");
                if (!$result) {
                    $sys->prompt("failed","非法操作!<!-- db_update failed -->");
                }
                $sys->prompt("jump",$CONFIGURE['common']['control_admin']."?act=content&channel_id=".$scheduler_info['channel_id']."&pag=".$sys->get['pag']);
            }
        }
   }

}elseif($sys->get['ope'] == "del"){
    // check the post
    if ( $ADMIN['ag_privilege']['content'] != "1" ) {
        $sys->prompt("failed","您没有权限进行此操作!<!-- privilege not allow -->");
    } else {

        $this_array = array();
        if (!empty($sys->get['scheduler_id'])){
            if (is_array($sys->get['scheduler_id'])) {
                foreach ($sys->get['scheduler_id'] as $v) {
                    if (preg_match("/^[1-9][0-9]{0,10}$/",$v)) {
                        $this_array[$v] = $v;
                    }
                }
            } else {
                if (preg_match("/^[1-9][0-9]{0,10}$/",$sys->get['scheduler_id'])) {
                    $this_array[$sys->get['scheduler_id']] = $sys->get['scheduler_id'];
                }
            }
        }
        if (!empty($sys->post['scheduler_id'])){
            if (is_array($sys->post['scheduler_id'])) {
                foreach ($sys->post['scheduler_id'] as $v) {
                    if (preg_match("/^[1-9][0-9]{0,10}$/",$v)) {
                        $this_array[$v] = $v;
                    }
                }
            } else {
                if (preg_match("/^[1-9][0-9]{0,10}$/",$sys->post['scheduler_id'])) {
                    $this_array[$sys->post['scheduler_id']] = $sys->post['scheduler_id'];
                }
            }
        }

        if (!empty($sys->get['choice'])){
            if (is_array($sys->get['choice'])) {
                foreach ($sys->get['choice'] as $v) {
                    if (preg_match("/^[1-9][0-9]{0,10}$/",$v)) {
                        $this_array[$v] = $v;
                    }
                }
            } else {
                if (preg_match("/^[1-9][0-9]{0,10}$/",$sys->get['choice'])) {
                    $this_array[$sys->get['choice']] = $sys->get['choice'];
                }
            }
        }
        if (!empty($sys->post['choice'])){
            if (is_array($sys->post['choice'])) {
                foreach ($sys->post['choice'] as $v) {
                    if (preg_match("/^[1-9][0-9]{0,10}$/",$v)) {
                        $this_array[$v] = $v;
                    }
                }
            } else {
                if (preg_match("/^[1-9][0-9]{0,10}$/",$sys->post['choice'])) {
                    $this_array[$sys->post['choice']] = $sys->post['choice'];
                }
            }
        }
        if (!empty($this_array)) {
            foreach ($this_array as $v) {
                if (preg_match("/^[1-9][0-9]{0,10}$/",$v)) {

                    $scheduler_info = $sys->return_scheduler_info($v);
                    if (preg_match("/^[1-9][0-9]*$/",$scheduler_info['scheduler_id'])) {

                        func::db_delete(DB_TABLE_SCHEDULER, "id=".$scheduler_info['scheduler_id']."");
                        $scheduler_if_hava  = func::db_count_record(DB_TABLE_SCHEDULER, "content_id='".addslashes($scheduler_info['content_id'])."'");
                        if ($scheduler_if_hava <= 0) {
                            func::db_delete(DB_TABLE_CONTENT, "content_id=".$scheduler_info['content_id']."");
                            func::db_delete(DB_TABLE_TRANS_CONTENT, "content_id=".$scheduler_info['content_id']."");
                            $filelist = func::db_select(DB_TABLE_CONTENT_COVER, "*", "content_id=".$scheduler_info['scheduler_id'], "", "id DESC");
                            if (is_array($filelist) && count($filelist)>0){
                                foreach($filelist as $file){
                                    @chmod($SETTING['dir_content_cover']."/".$file['dir']."/".$file['filename'], $SETTING['chmod_mode_file']);
                                    @unlink($SETTING['dir_content_cover']."/".$file['dir']."/".$file['filename']);
                                }
                                $result = func::db_delete(DB_TABLE_CONTENT_COVER, "content_id=".$scheduler_info['scheduler_id']."");
                                if (!$result) {
                                    $sys->prompt("failed","封面数据库信息删除失败!<!-- DB_TABLE_CONTENT_COVER delete failed -->");
                                }
                            }

                            $content_info   = $sys->return_content_info($scheduler_info['scheduler_id']);
                            if (is_array($sys->model_array['level']) && count($sys->model_array['level'])>0) {
                                foreach($sys->model_array['level'] as $k => $v) {
                                    if($v == "content"){
                                        $item_id = array();
                                        $item_list  = func::db_select($SETTING['config_db_prefix'].$k, $k."_id", "content_id=".$scheduler_info['scheduler_id']);
                                        if (is_array($item_list) && count($item_list) > 0) {
                                            foreach($item_list as $k_i => $v_i){
                                                $item_id[] = $v_i[$k."_id"];
                                            }
                                        }
                                        if (is_array($item_id) && count($item_id) > 0) {
                                            foreach($sys->model_array['level'] as $k_sub => $v_sub) {
                                                if($v_sub == $k){
                                                    func::db_delete($SETTING['config_db_prefix'].$k_sub, $v_sub."_id IN (".implode(",", $item_id).")");
                                                }
                                            }
                                        }
                                        func::db_delete($SETTING['config_db_prefix'].$k, "content_id=".$scheduler_info['scheduler_id']."");
                                    }
                                }
                                $filelist = array();
                                if (is_array($content_info['attach_mark']) && count($content_info['attach_mark'])>0){
                                    $filelist = func::db_select(DB_TABLE_CONTENT_ATTACH, "*", "key_id IN (".implode(",", $content_info['attach_mark']).")", "", "id DESC");
                                }
                                if (is_array($filelist) && count($filelist)>0){
                                    foreach($filelist as $file){
                                        @chmod($SETTING['dir_content_attach']."/".$file['dir']."/".$file['filename'], $SETTING['chmod_mode_file']);
                                        @unlink($SETTING['dir_content_attach']."/".$file['dir']."/".$file['filename']);
                                    }
                                    $result = func::db_delete(DB_TABLE_CONTENT_ATTACH, "key_id IN (".implode(",", $content_info['attach_mark']).")");
                                    if (!$result) {
                                        $sys->prompt("failed","附件数据库信息删除失败!<!-- DB_TABLE_CONTENT_ATTACH delete failed -->");
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    $sys->prompt("jump",$CONFIGURE['common']['control_admin']."?act=content&channel_id=".$scheduler_info['channel_id']."&pag=".$sys->get['pag']);

} else {

    if( !preg_match("/^[1-9][0-9]*|0$/",$sys->get['channel_id'])  ){
        $sys->prompt("failed","非法操作!<!-- channel_id error -->");
    }else{

        $where              = "";
        $where_total        = "";
        $sys->channel_info['id'] = "0";
        if( preg_match("/^[1-9][0-9]*$/",$sys->get['channel_id'])  ){
            $sys->return_channel_info($sys->get['channel_id']);
            $sys->return_channel_path($sys->channel_info['channel_id']);

            if (preg_match("/^[1-9][0-9]*$/",$sys->channel_info['id'])) {
                $channel_sub    = $sys->return_channel_list($sys->channel_info['id']);
                $channel_allsub = $sys->return_channel_list($sys->channel_info['id'], null, array('allsub' => "1"));

                $where          = " AND scheduler.channel_id=".$sys->channel_info['id']."";
                $where_total    = " AND channel_id=".$sys->channel_info['id']."";

                $where          = substr(trim($where), 0, 3) == "AND" ? substr(trim($where), 3) : trim($where);
                $where_total    = substr(trim($where_total), 0, 3) == "AND" ? substr(trim($where_total), 3) : trim($where_total);
                $where          = $where != "" ? "WHERE ".$where : "";
            }
        }

        $total_record = func::db_count_record(DB_TABLE_CONTENT, $where_total);
        $bwpage->set_record_listnum("20");
        $bwpage->set_record($total_record);
        $bwpage->page($CONFIGURE['common']['control_admin']."?act=content&pag=%s");
        $sql = "SELECT scheduler.id as scheduler_id,
                    content.*,
                    cover.id as cover_id, cover.dir as cover_dir, cover.filename as cover_filename,
                    channel.id as channel_id, channel.name as channel_name
                FROM ".DB_TABLE_SCHEDULER." scheduler
                    LEFT JOIN ".DB_TABLE_CONTENT." content ON content.content_id=scheduler.content_id
                    LEFT JOIN ".DB_TABLE_CHANNEL." channel ON channel.id=scheduler.channel_id
                    LEFT JOIN ".DB_TABLE_CONTENT_COVER." cover ON cover.content_id=content.content_id
                ".$where."
                GROUP BY scheduler.id
                ORDER BY content.if_top, content.post_time DESC
                LIMIT ".$bwpage->record_listfirst.",".$bwpage->record_listnum;
        $result = &$db->Execute($sql);
        if (!$result) {
            echo $db->ErrorMsg();
        } else {
            while (!$result->EOF) {
                $content_list[$result->fields['content_id']] = array(
                    'scheduler_id'              => $result->fields['scheduler_id'],

                    'content_id'                => $result->fields['content_id'],
                    'phrase'                    => $result->fields['phrase'],
                    'phrase_len'                => mb_strwidth($result->fields['phrase'],"UTF-8"),
                    'subject'                   => $result->fields['subject'],
                    'subject_len'               => mb_strwidth($result->fields['subject'],"UTF-8"),
                    'color'                     => $result->fields['color'],
                    'fontstyle'                 => $result->fields['fontstyle'],
                    'decoration'                => $result->fields['decoration'],
                    'prefix'                    => $result->fields['prefix'],
                    'author'                    => $result->fields['author'],
                    'excerpt'                   => $result->fields['excerpt'],
                    'template_content'           => $result->fields['template_content'],
                    'click'                     => $result->fields['click'],
                    'keyword'                   => $result->fields['keyword'],
                    'brief'                     => $result->fields['brief'],
                    'post_id'                   => $result->fields['post_id'],
                    'post_username'             => $result->fields['post_username'],
                    'post_ip'                   => $result->fields['post_ip'],
                    'post_time'                 => $result->fields['post_time'],
                    'verify_id'                 => $result->fields['verify_id'],
                    'verify_username'           => $result->fields['verify_username'],
                    'verify_ip'                 => $result->fields['verify_ip'],
                    'verify_time'               => $result->fields['verify_time'],
                    'if_enable'                 => $result->fields['if_enable'],
                    'if_enable_begin'           => $result->fields['if_enable_begin'],
                    'if_enable_end'             => $result->fields['if_enable_end'],
                    'if_top'                    => $result->fields['if_top'],
                    'if_top_begin'              => $result->fields['if_top_begin'],
                    'if_top_end'                => $result->fields['if_top_end'],
                    'if_view'                   => $result->fields['if_view'],
                    'if_view_privilege'         => $result->fields['if_view_privilege'],
                    'if_inerface'               => $result->fields['if_inerface'],
                    'if_inerface_privilege'     => $result->fields['if_inerface_privilege'],
                    'if_inerface_identity'      => $result->fields['if_inerface_identity'],
                    'if_inerface_check'         => $result->fields['if_inerface_check'],
                    'if_turn'                   => $result->fields['if_turn'],
                    'if_turn_type'              => $result->fields['if_turn_type'],
                    'if_turn_url'               => $result->fields['if_turn_url'],
                    'rank'                      => $result->fields['rank'],

                    'cover_id'                  => $result->fields['cover_id'],
                    'cover_dir'                 => $result->fields['cover_dir'],
                    'cover_filename'            => $result->fields['cover_filename'],

                    'channel_id'                => $result->fields['channel_id'],
                    'channel_name'              => $result->fields['channel_name'],
                    'channel_name_len'          => mb_strwidth($result->fields['channel_name'],"UTF-8"),
                 );
                $result->MoveNext();
            }
        }

        $t->assign(array(
            "channel_info"          => $sys->channel_info,
            "channel_path"          => $sys->channel_path,
            "channel_sub"           => $channel_sub,
            "channel_allsub"        => $channel_allsub,

            "content_list"          => $content_list,
            "pagination"            => $bwpage->pagination,
        ));
    }
}
?>