織夢dedeCMS後臺增加複製文檔功能

由於客戶需求,需要在dedecms 後臺添加文檔複製到另一個欄目下的功能,效果如下:

當選中想要選擇的文章後,點擊“複製”,會彈出對話框,提示需要複製的欄目

修改步驟如下:

1 打開dede/templets下的content_list.htm找到

<a href="javascript:;" onClick="moveArc(event,this,<?php echo (empty($channelid) ? 0 : $channelid); ?>)" class="layui-btn layui-btn-small">&nbsp;移動&nbsp;</a>

當前行的下方添加

<a href="javascript:;" onClick="copyArc(event,this,<?php echo (empty($channelid) ? 0 : $channelid); ?>);" class="layui-btn layui-btn-small"> 複製 </a>

2  打開dede/js/list.js 搜索 function moveArc(e, obj, cid)下約35行添加

function copyArc(e, obj, cid){
    var qstr=getCheckboxItem();
    if(qstr=='')
    {
        alert('必須選擇一個或多個文檔!');
        return;
    }
    LoadQuickDiv(e, 'archives_do.php?dopost=copyArchives&qstr='+qstr+'&channelid='+cid+'&rnd='+Math.random(), 'copyArchives', '450px', '180px');
    ChangeFullDiv('show');
}

3 打開後臺目錄(/dede)下archives_do.php約431行下添加

注意:需要在“else if($dopost=='moveArchives')” 的if 語句結束處之後添加:

/*-----------------------------
//複製文檔
------------------------------*/
elseif ($dopost == 'copyArchives') {
    CheckPurview('sys_ArcBatch');
    if (empty($totype)) {
        require_once(DEDEINC . '/typelink.class.php');
        if (!empty($aid) && empty($qstr)) $qstr = $aid;
 
        AjaxHead();
        $channelid = empty($channelid) ? 0 : $channelid;
        $tl = new TypeLink($aid);
        $typeOptions = $tl->GetOptionArray(0, $admin_catalogs, $channelid);
        $typeOptions = "<select name='totype' style='width:90%'>
        <option value='0'>請選擇複製到的位置...</option>\r\n
        $typeOptions
        </select>";
 
        //輸出AJAX可移動窗體
        $divname = 'copyArchives';
        echo "<div class='title' onmousemove=\"DropMoveHand('{$divname}', 225);\" onmousedown=\"DropStartHand();\" onmouseup=\"DropStopHand();\">\r\n";
        echo "    <div class='titLeft'>複製文檔</div>\r\n";
        echo "    <div class='titRight'><img src='images/ico-close.gif' style='cursor:pointer;' onclick='HideObj(\"{$divname}\");ChangeFullDiv(\"hide\");' alt='關閉' title='關閉' /></div>\r\n";
        echo "</div>\r\n";
        echo "<form name='quickeditform' action='archives_do.php' method='post'>\r\n";
        echo "<input type='hidden' name='dopost' value='{$dopost}' />\r\n";
        echo "<input type='hidden' name='qstr' value='{$qstr}' />\r\n";
        echo "<table width='100%' style='margin-top:6px;z-index:9000;'>\r\n";
        ?>
        <tr height='28'>
            <td width="80" class='bline'> 目標欄目:</td>
            <td class='bline'>
                <?php echo $typeOptions; ?>
            </td>
        </tr>
        <tr height='32'>
            <td width="80" class='bline'> 文檔ID:</td>
            <td class='bline'>
                <input type='text' name='tmpids' value="<?php echo $qstr; ?>" style='width:310px;overflow:hidden;'/>
                <br/>
                複製到的目標欄目必須和選定的文檔頻道類型一致,否則程序會自動勿略不符合的文檔。
            </td>
        </tr>
        <tr height='32'>
            <td colspan='2' align='center' style='padding-top:12px'>
                <input name="imageField" type="image" src="images/button_ok.gif" width="60" height="22" class="np"
                       border="0" style="cursor:pointer"/>
                  
                <img src="images/button_back.gif" width="60" height="22" border="0"
                     onclick='HideObj("<?php echo $divname; ?>");ChangeFullDiv("hide");' style="cursor:pointer"/>
            </td>
            </td>
        </tr>
        </table>
        </form>
        <?php
        //AJAX窗體結束
    } else {
        $totype = preg_replace("#[^0-9]#", '', $totype);
        $typeInfos = $dsql->GetOne("SELECT tp.channeltype,tp.ispart,tp.channeltype,ch.maintable,ch.addtable,ch.issystem FROM `#@__arctype` tp LEFT JOIN `#@__channeltype` ch on ch.id=tp.channeltype WHERE tp.id='$totype' ");
        $idtype = "id";
        if (!is_array($typeInfos)) {
            ShowMsg('參數錯誤!', '-1');
            exit();
        }
        if ($typeInfos['ispart'] != 0) {
            ShowMsg('文檔保存的欄目必須爲最終列表欄目!', '-1');
            exit();
        }
        if (empty($typeInfos['addtable'])) {
            $typeInfos['maintable'] = '`#@__archives`';
        }
        //增加單表模型判斷
        if ($typeInfos['issystem'] == -1) {
            $typeInfos['maintable'] = $typeInfos['addtable'];
            $idtype = "aid";
        }
        $arcids = preg_replace("#[^0-9,]#", '', preg_replace("#`#", ',', $qstr));
        $arc = '';
        $j = 0;
        $okids = array();
        $dsql->SetQuery("SELECT {$idtype},typeid FROM `{$typeInfos['maintable']}` WHERE {$idtype} in($arcids) AND channel='{$typeInfos['channeltype']}' ");
        $dsql->Execute();
        while ($row = $dsql->GetArray()) {
            if ($row['typeid'] != $totype) {
                
                $dsql->ExecuteNoneQuery("insert into `#@__arctiny` (typeid,typeid2,arcrank,channel,senddate,sortrank,mid) select typeid,typeid2,arcrank,channel,senddate,sortrank,mid from `#@__arctiny` where id='{$row[$idtype]}'");
                
                $xid = $dsql->GetLastID();
                
                $dsql->ExecuteNoneQuery("insert into `{$typeInfos['maintable']}`(id,typeid,typeid2,sortrank,flag,ismake,channel,arcrank,click,money,title,shorttitle,color,writer,source,litpic,pubdate,senddate,mid,keywords,lastpost,scores,goodpost,badpost,voteid,notpost,description,filename,dutyadmin,tackid,mtype,weight) select case when id>'0' then '$xid'  else '' end, case when typeid>'0' then '$totype'  else '' end,typeid2,sortrank,flag,ismake,channel,arcrank,click,money,title,shorttitle,color,writer,source,litpic,pubdate,senddate,mid,keywords ,lastpost,scores,goodpost,badpost,voteid,notpost,description,filename,dutyadmin,tackid,mtype,weight from `{$typeInfos['maintable']}` WHERE id='{$row[$idtype]}' ");
                
                $dsql->ExecuteNoneQuery("insert into `{$typeInfos['addtable']}`(aid,typeid,body,redirecturl,templet,userip) select case when aid>'0' then '$xid'  else '' end,$totype,body,redirecturl,templet,userip from `{$typeInfos['addtable']}` WHERE aid='{$row[$idtype]}' ");
                
                $okids[] = $row[$idtype];
                $j++;
            }
        }
 
        
    UpDateCatCache();
    $sql = " TRUNCATE TABLE `#@__arctiny`";
    $dsql->ExecuteNoneQuery($sql);
    
    //導入普通模型微數據
    $sql = "INSERT INTO `#@__arctiny`(id, typeid, typeid2, arcrank, channel, senddate, sortrank, mid)  
            SELECT id, typeid, typeid2, arcrank, channel, senddate, sortrank, mid FROM `#@__archives` ";
    $dsql->ExecuteNoneQuery($sql);
    
    //導入單表模型微數據
    $dsql->SetQuery("SELECT id,addtable FROM `#@__channeltype` WHERE id < -1 ");
    $dsql->Execute();
    $doarray = array();
    while($row = $dsql->GetArray())
    {
        $tb = str_replace('#@__', $cfg_dbprefix, $row['addtable']);
        if(empty($tb) || isset($doarray[$tb]) )
        {
            continue;
        }
        else
        {
            $sql = "INSERT INTO `#@__arctiny`(id, typeid, typeid2, arcrank, channel, senddate, sortrank, mid)  
                    SELECT aid, typeid, 0, arcrank, channel, senddate, 0, mid FROM `$tb` ";
            $rs = $dsql->executenonequery($sql);
            $doarray[$tb]  = 1;
        }
    }
        //更新HTML
        foreach ($okids as $aid) {
            $arc = new Archives($aid);
            $arc->MakeHtml();
        }
        ShowMsg("成功複製 $j 個文檔!", $ENV_GOBACK_URL);
        exit();
    }
} 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章