:::

5-4-3 修正可發布活動者可看到的東西

您沒有觀看影片的權限

您沒有觀看影片的權限

請先登入,登入後,確認您的權限後,即可觀看影片。

  1. 搜尋一下 can_add,因為有些地方,除了是有發布活動權限以外,還要注意是不是活動發布者本人。
  2. 先修改活動列表,主要要改兩部份,一個是活動狀態的顯示:未關閉、未額滿、未過期的就顯示「報名中」,其餘就變成「無法報名」
  3. 另一個是活動的管理:不是自己的活動,而且也不是管理員的話,就不要有修改功能,所以修改 templates\op_tad_signup_actions_index.tpl
    <table class="table table-bordered">
        <!--略-->
        <tbody>
            <{foreach from=$all_data key=id item=action name=all_data}>
                <tr>
                    <td>
                        <{if $action.enable && $action.number > $action.signup|@count && $xoops_isuser && $action.end_date|strtotime >= $smarty.now}>
                            <i class="fa fa-check text-success" data-toggle="tooltip" title="報名中" aria-hidden="true"></i>
                        <{else}>
                            <i class="fa fa-times text-danger" data-toggle="tooltip" title="無法報名" aria-hidden="true"></i>
                        <{/if}>
                        <a href="<{$xoops_url}>/modules/tad_signup/index.php?id=<{$action.id}>"><{$action.title}></a>
                    </td>
                    <!--略-->
                    <td>
                        <{if $smarty.session.can_add && ($action.uid==$now_uid || $smarty.session.tad_signup_adm)}>
                            <a href="<{$xoops_url}>/modules/tad_signup/index.php?op=tad_signup_actions_edit&id=<{$action.id}>" class="btn btn-sm btn-warning"><i class="fa fa-pencil" aria-hidden="true"></i> 編輯活動</a>
                            <a href="<{$xoops_url}>/modules/tad_signup/index.php?op=tad_signup_actions_copy&id=<{$action.id}>" class="btn btn-sm btn-info"><i class="fa fa-copy" aria-hidden="true"></i> 複製活動</a>
                        <{/if}>
    
                        <!--略-->
                    </td>
                </tr>
            <{/foreach}>
        </tbody>
    </table>

     

  4. 當然該物件方法也要提供需要的 $now_uid ,故修改 class\Tad_signup_actions.php
    //列出所有資料
    public static function index($only_enable = true)
    {
        global $xoopsTpl, $xoopsModuleConfig, $xoopsUser;
        /*--略--*/
        
        $now_uid = $xoopsUser ? $xoopsUser->uid() : 0;
        $xoopsTpl->assign('now_uid', $now_uid);
    }

     

  5. 除了判別 $now_uid 外,還要有實質的阻擋動作,故修改 class\Tad_signup_actions.php,並重整一下程式碼,使之邏輯更清晰:
    //編輯表單
    public static function create($id = '')
    {
        global $xoopsTpl, $xoopsUser;
    
        if (!Utility::power_chk('tad_signup', 1)) {
            redirect_header($_SERVER['PHP_SELF'], 3, "您沒有權限使用此功能");
        }
    
        $uid = $xoopsUser ? $xoopsUser->uid() : 0;
    
        if ($id) {
            //抓取預設值
            $db_values = self::get($id);
    
            if ($uid != $db_values['uid'] && !$_SESSION['tad_signup_adm']) {
                redirect_header($_SERVER['PHP_SELF'], 3, "您沒有權限使用此功能");
            }
            /*--略--*/
        } else {
            $xoopsTpl->assign('uid', $uid);
        }
    
        /*--略--*/
    }

     

  6. 接著修改單一活動頁面,把一些管理功能也加上判斷,並把錄取欄位顯示出來,只隱藏工具按鈕,再把原本的 <{$uid}> 改為 <{$now_uid}> 避免混淆,故修改 templates\op_tad_signup_actions_show.tpl
    <table class="table" data-toggle="table" data-pagination="true" data-search="true" data-mobile-responsive="true">
        <thead>
            <tr>
                <{foreach from=$signup.0.tdc key=col_name item=user name=tdc}>
                    <th data-sortable="true"><{$col_name}></th>
                <{/foreach}>
                <th data-sortable="true">錄取</th>
                <th data-sortable="true">報名日期</th>
            </tr>
        </thead>
        <tbody>
            <{foreach from=$signup item=signup_data}>
                <tr>
                    <{foreach from=$signup_data.tdc key=col_name item=user_data}>
                        <td>
                            <{foreach from=$user_data item=data}>
                                <{if ($smarty.session.can_add && $uid == $now_uid) || $signup_data.uid == $now_uid}>
                                    <!--略-->
                                <{else}>
                                    <!--略-->
                                <{/if}>
                            <{/foreach}>
                        </td>
                    <{/foreach}>
                    <td>
                        <{if $signup_data.accept==='1'}>
                            <div class="text-primary">錄取</div>
                            <{if $smarty.session.can_add && $uid == $now_uid}>
                                <a href="<{$xoops_url}>/modules/tad_signup/index.php?op=tad_signup_data_accept&id=<{$signup_data.id}>&action_id=<{$id}>&accept=0" class="btn btn-sm btn-warning">改成未錄取</a>
                            <{/if}>
                        <{elseif $signup_data.accept==='0'}>
                            <div class="text-danger">未錄取</div>
                            <{if $smarty.session.can_add && $uid == $now_uid}>
                                <a href="<{$xoops_url}>/modules/tad_signup/index.php?op=tad_signup_data_accept&id=<{$signup_data.id}>&action_id=<{$id}>&accept=1" class="btn btn-sm btn-success">改成錄取</a>
                            <{/if}>
                        <{else}>
                            <div class="text-muted">尚未設定</div>
                            <{if $smarty.session.can_add && $uid == $now_uid}>
                                <a href="<{$xoops_url}>/modules/tad_signup/index.php?op=tad_signup_data_accept&id=<{$signup_data.id}>&action_id=<{$id}>&accept=0" class="btn btn-sm btn-warning">未錄取</a>
                                <a href="<{$xoops_url}>/modules/tad_signup/index.php?op=tad_signup_data_accept&id=<{$signup_data.id}>&action_id=<{$id}>&accept=1" class="btn btn-sm btn-success">錄取</a>
                            <{/if}>
                        <{/if}>
                    </td>
                    <td><{$signup_data.signup_date}></td>
                </tr>
            <{/foreach}>
        </tbody>
    </table>

     

  7. 當然,方法也要改成送出 $now_uid,故修改 class\Tad_signup_actions.php
    //以流水號秀出某筆資料內容
    public static function show($id = '')
    {
        global $xoopsDB, $xoopsTpl, $xoopsUser;
    
        /*--略--*/
    
        $now_uid = $xoopsUser ? $xoopsUser->uid() : 0;
        $xoopsTpl->assign('now_uid', $now_uid);
    }

     

link to https://github.com/tadlearn/tad_signup/commit/bb6a841bc82aa6f3531e5454873e85d78a50ed74 \


:::

搜尋

QR Code 區塊

https%3A%2F%2Ftad0616.net%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbsn%3D48%26tbdsn%3D1722

書籍目錄

展開 | 闔起

線上使用者

52人線上 (13人在瀏覽線上書籍)

會員: 0

訪客: 52

更多…