让dedecms联动模型支持dede_sys_enum的father字段自动追加

dede_sys_enum添加father字段,实现目的:在添加联动分类时,自动添加father的值。以500为分类界限。即:503的父类(father)为503,1001的father为1000。

 

主要修改的文件 stepselect_main.php文件。 

 

解决: 修改有三处。

 

1.主要添加内容:

$father = intval(floor($evalue/500))*500;  
 

2.修改内容:

$sql = "INSERT INTO `zuimoban_sys_enum`(`ename`,`evalue`,`egroup`,`disorder`,`issign`,`father`)   

                             VALUES('$ename','$evalue','$egroup','$disorder','$issign','$father'); ";  

<?php  

/** 

 * 联动选择管理 

 * 

 * @version        $Id: stepselect_main.php 2 13:23 2011-3-24 tianya $ 

 * @package        DedeCMS.Administrator 

 * @copyright      Copyright (c) 2007 - 2010, DesDev, Inc. 

 * @license         

 * @link            

 */  

require_once(dirname(__FILE__)."/config.php");  

CheckPurview('c_Stepselect');  

require_once(DEDEINC."/datalistcp.class.php");  

require_once(DEDEINC.'/enums.func.php');  

/*----------------- 

前台视图 

function __show() { } 

------------------*/  

$ENV_GOBACK_URL = (isset($ENV_GOBACK_URL) ? $ENV_GOBACK_URL : 'stepselect_main.php');  

if(empty($action))  

{  

    setcookie("ENV_GOBACK_URL",$dedeNowurl,time()+3600,"/");  

    if(!isset($egroup)) $egroup = '';  

    if(!isset($topvalue)) $topvalue = 0;  

    $etypes = array();  

    $egroups = array();  

    $dsql->Execute('me','SELECT * FROM `zuimoban_stepselect` ORDER BY id DESC');  

    while($arr = $dsql->GetArray())  

    {  

        $etypes[] = $arr;  

        $egroups[$arr['egroup']] = $arr['itemname'];  

    }  

  

    if($egroup!='')  

    {  

        $orderby = 'ORDER BY disorder ASC, evalue ASC';  

        if(!empty($topvalue))  

        {  

            // 判断是否为1级联动  

            if ($topvalue % 500 == 0)  

            {  

                $egroupsql = " WHERE egroup LIKE '$egroup' AND evalue>=$topvalue AND evalue < ".($topvalue + 500);  

            } else {   

                $egroupsql = " WHERE (evalue LIKE '$topvalue.%%%' OR evalue=$topvalue) AND egroup LIKE '$egroup'";  

            }  

        }  

        else  

        {  

            $egroupsql = " WHERE egroup LIKE '$egroup' ";  

        }  

        $sql = "SELECT * FROM `zuimoban_sys_enum` $egroupsql $orderby";  

    } else {  

        $egroupsql = '';  

        $sql = "SELECT * FROM `zuimoban_stepselect` ORDER BY id DESC";  

    }  

    //echo $sql;exit;  

    $dlist = new DataListCP();  

    $dlist->SetParameter('egroup',$egroup);  

    $dlist->SetParameter('topvalue',$topvalue);  

    $dlist->SetTemplet(DEDEADMIN."/templets/stepselect_main.htm");  

    $dlist->SetSource($sql);  

    $dlist->display();  

    exit();  

}  

else if($action=='edit' || $action=='addnew' || $action=='addenum' || $action=='view')  

{  

    AjaxHead();  

    include('./templets/stepselect_showajax.htm');  

    exit();  

}  

/*----------------- 

删除类型或枚举值 

function __del() { } 

------------------*/  

else if($action=='del')  

{  

    $arr = $dsql->GetOne("SELECT * FROM `zuimoban_stepselect` WHERE id='$id' ");  

    if(!is_array($arr))  

    {  

        ShowMsg("无法获取分类信息,不允许后续操作!", "stepselect_main.php?".ExecTime());  

        exit();  

    }  

    if($arr['issystem']==1)  

    {  

        ShowMsg("系统内置的枚举分类不能删除!", "stepselect_main.php?".ExecTime());  

        exit();  

    }  

    $dsql->ExecuteNoneQuery("DELETE FROM `zuimoban_stepselect` WHERE id='$id'; ");  

    $dsql->ExecuteNoneQuery("DELETE FROM `zuimoban_sys_enum` WHERE egroup='{$arr['egroup']}'; ");  

    ShowMsg("成功删除一个分类!", "stepselect_main.php?".ExecTime());  

    exit();  

}  

else if($action=='delenumAllSel')  

{  

    if(isset($ids) && is_array($ids))  

    {  

        $id = join(',', $ids);  

  

        $groups = array();  

        $dsql->Execute('me', "SELECT egroup FROM `zuimoban_sys_enum` WHERE id IN($id) GROUP BY egroup");  

        while($row = $dsql->GetArray('me'))  

        {  

            $groups[] = $row['egroup'];  

        }  

  

        $dsql->ExecuteNoneQuery("DELETE FROM `zuimoban_sys_enum` WHERE id IN($id); ");  

  

        //更新缓存  

        foreach($groups as $egropu)   

        {  

            WriteEnumsCache($egroup);  

        }  

  

        ShowMsg("成功删除选中的枚举分类!", $ENV_GOBACK_URL);  

    }  

    else  

    {  

        ShowMsg("你没选择任何分类!", "-1");  

    }  

    exit();  

}  

else if($action=='delenum')  

{  

    $row = $dsql->GetOne("SELECT egroup FROM `zuimoban_sys_enum` WHERE id = '$id' ");  

    $dsql->ExecuteNoneQuery("DELETE FROM `zuimoban_sys_enum` WHERE id='{$id}'; ");  

    WriteEnumsCache($row['egroup']);  

    ShowMsg("成功删除一个枚举!", $ENV_GOBACK_URL);  

    exit();  

}  

/*----------------- 

保存类型修改 

function __edit_save() { } 

------------------*/  

else if($action=='edit_save')  

{  

    if(preg_match("#[^0-9a-z_-]#i", $egroup))  

    {  

        ShowMsg("组名称不能有全角字符或特殊符号!","-1");  

        exit();  

    }  

    $dsql->ExecuteNoneQuery("UPDATE `zuimoban_stepselect` SET `itemname`='$itemname',`egroup`='$egroup' WHERE id='$id'; ");  

    ShowMsg("成功修改一个分类!", "stepselect_main.php?".ExecTime());  

    exit();  

}  

/*----------------- 

保存新类型 

function __addnew_save() { } 

------------------*/  

else if($action=='addnew_save')  

{  

    if(preg_match("#[^0-9a-z_-]#i", $egroup))  

    {  

        ShowMsg("组名称不能有全角字符或特殊符号!", "-1");  

        exit();  

    }  

    $arr = $dsql->GetOne("SELECT * FROM `zuimoban_stepselect` WHERE itemname LIKE '$itemname' OR egroup LIKE '$egroup' ");  

    if(is_array($arr))  

    {  

        ShowMsg("你指定的类别名称或组名称已经存在,不能使用!","stepselect_main.php");  

        exit();  

    }  

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/628c007e106d7a84a667ccc7079b7114.html