:::

7-6 根據不同狀態顯示標籤

  1. 由於上一單元有將管理員和使用者的界面做了調整,管理員看得到已關閉和已過期資訊,因此,管理員必須知道哪些資料是被關閉,哪些資料是已經過期的,避免在認知上和使用者有所衝突。
  2. 已關閉的資訊可以直接修改 /templates/tad_signup_index.tpl 樣板來做:
    <{if $action.enable!=1}>
      <span class="label label-danger">已關閉</span>
    <{/if}>  
  3. 另外已過期需要比對日期,所以,在 index.php 中做處理

    //顯示預設頁面內容
    function list_actions()
    {
        global $xoopsTpl, $xoopsDB, $isAdmin;
    
        $tbl=$xoopsDB->prefix('actions');
    
        $where=$isAdmin?'':"WHERE `enable` = '1' and `end_date` > NOW()";
    
        $sql="SELECT * FROM `{$tbl}` $where ORDER BY `end_date` DESC";
        //送至資料庫
        $result = $xoopsDB->query($sql) or web_error($sql);
        //取回資料
        $actions=[];
        $myts              = MyTextSanitizer::getInstance();
        while($action=$xoopsDB->fetchArray($result)){
            $action['title']   = $myts->htmlSpecialChars($action['title']);
            $action['content'] = $myts->displayTarea($action['content'], 1, 1, 1, 1, 0);    
            $action['overdue'] = time() > strtotime($action['end_date'])?1:0;
            $actions[]=$action;
        }
    
        $xoopsTpl->assign('actions', $actions);
    
        include_once XOOPS_ROOT_PATH . "/modules/tadtools/sweet_alert.php";
        $sweet_alert = new sweet_alert();
        $sweet_alert->render("delete_action", "admin/main.php?op=delete_action&action_id=", 'action_id');
    }
  4. 接著再去修改 /templates/tad_signup_index.tpl 樣板,加入對應的處置:

    <{if $action.overdue}>
      <span class="label label-warning">已過期</span>
    <{/if}> 

     


:::

書籍目錄

展開 | 闔起

https%3A%2F%2Fcampus-xoops.tn.edu.tw%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbsn%3D29%26tbdsn%3D925

計數器

今天: 4369436943694369
昨天: 3438343834383438
總計: 7394698739469873946987394698739469873946987394698