萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> CMS 教學

帝國CMS 批量修改信息標題功能開發全流程:後端邏輯、前端表單與權限控制完整實現

適用文件

  • e/data/html/list/alllistinfo.php(全部信息列表)
  • e/data/html/list/listinfo.php(分類信息列表)
  • 自定義系統模型列表文件

步驟一:注入後端處理函數

在文件中搜索 $ignamer=$ftnr['igr'];,其下一行插入:

function dp_editmoreinfotitle($add,$userid,$username){
  global $empire,$dbtbpre,$class_r;
  $classid=(int)$add['classid'];
  $infoid=$add['infoid'];
  $n1=$add['title'];
  $count=count($infoid);
  $tbname=$class_r[$classid]['tbname'];
  if(!$classid||!$tbname||!$count) {
    printerror("請選擇需要修改的信息",'history.go(-1)',1,0,1);
  }
  // 權限檢查
  $doselfinfo=CheckLevel($userid,$username,$classid,"news");
  if(!$doselfinfo['doeditinfo']) {
    printerror("沒有足夠的權限",'history.go(-1)',1,0,1);
  }
  $dopubid=0; $donum=0; $dolog=''; $infotb='';
  for($i=0;$i<$count;$i++) {
    $doinfoid=(int)$infoid[$i];
    if(empty($infotb)) {
      $index_r=$empire->fetch1("select classid,checked from {$dbtbpre}ecms_".$tbname."_index where id='$doinfoid' limit 1");
      if(!$index_r['classid']) continue;
      $infotb=ReturnInfoMainTbname($tbname,$index_r['checked']);
    }
    $do1=$n1[$i];
    $empire->query("update ".$infotb." set title='$do1' where id='$doinfoid'");
  }
  printerror("修改成功",$_SERVER['HTTP_REFERER'],1,0,1);
}

$enews=$_POST['enews'];
if($enews=="EditMoreInfoTitle"){
  hCheckEcmsRHash();
  dp_editmoreinfotitle($_POST,$logininid,$loginin);
}

步驟二:前端標題改為輸入框

搜索 <?=$r[title]?>,將其及上下行的 <a> 標籤(共 3 行)替換為:

<input type="text" name="title[]" value="<?=$oldtitle?>" style="width:99%">

步驟三:添加提交按鈕

搜索 <span id="moveclassnav"></span>,在其上方插入:

<input type="submit" name="Submit7" value="批量修改標題" onclick="document.listform.enews.value='EditMoreInfoTitle';document.listform.action='ListAllInfo.php';">

補充說明

  1. 樣式可自行調整(如加 class="form-control")。
  2. 備份 e/data/html/list/ 目錄,升級前備份。
  3. 可擴展:同理實現批量修改作者、來源、圖片、TAG、關鍵字等字段。

擴展案例展示

批量修改會員信息
批量修改 TAG 屬性
批量修改標題、文件名
copyright © 萬盛學電腦網 all rights reserved