PHP歷理 列表模板和標籤庫

onestopweb發表於2024-08-10
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title><?php echo $titlebar;?></title>
    <link rel="stylesheet" href="/_/_js/layui/css/layui.css">
    <link rel="stylesheet" href="/_/_css/base.css">
    <script src="/_/_js/layui/layui.js"></script>
    <script src="/_/_js/jquery-1.10.1.min.js"></script>
</head>
<?php echo $setextCss;?>
<div class="layui-row t-container">
    <?php include ROOT . '_php/twig/menu.php';?>
    <div class="layui-col-xs12 layui-col-sm12 <?php echo $seissideCss;?>" id="top">
        <div class="m-map">
            <a href="###" class="g-l lb-menu"><i class="layui-icon">&#xe668;</i>&nbsp;選單</a>
            <a href="###" class="g-r lb-save"><i class="layui-icon">&#xe67a;</i>&nbsp;收藏</a>
            <ul>
                <li><a href="/admin.php">主頁</a> <span>/</span></li>
                <script>
                    var path = window.location.pathname;
                    var route = path.replace(/^(.+)\/[^\/]+$/, '$1');
                    var routename = path.substring(3, 6);
                    document.writeln('<li><a href="'+route+'">'+routename+'</a></li>');
                    var file = path;
                    var filename = path.substring(path.lastIndexOf('/') + 1);
                    if(filename.length<2){filename = 'index';}else{ filename = filename.replace(/\.[^/.]+$/, "")}
                    document.writeln('<li><a href="'+file+'">'+filename+'</a></li>');
                </script>
            </ul>
        </div>
        <form method="get" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
            <div class="layui-row layui-form m-search">
                <?php echo $form;?>
            </div>
            <div class="layui-btn-group m-btn">
                <button type="button" class="layui-btn layui-bg-red lb-btn" id="orderbying" lay-options="{}">
                    <span>排序</span>
                    <i class="layui-icon layui-icon-down layui-font-12"></i>
                </button>
                <button type="button" class="layui-btn layui-bg-orange lb-btn" id="toggle">切換</button>
                <button type="button" class="layui-btn layui-bg-blue lb-btn" id="show">展開</button>
                <button type="submit" class="layui-btn lb-btn">搜尋</button>
            </div>
        </form>
        <div class="layui-collapse">
            <?php echo $show;?>
        </div>
        <div class="m-page">
            <div id="paging"></div>
        </div>
        <div class="m-path">
            <?php echo $path;?>
        </div>
    </div>
    <?php include ROOT . '_php/twig/footer.php';?>
</div>
<script src="/_/_js/foot.js"></script>
</body>
</html>
<script>
    //orderby sql排序功能
    var link = window.location.search;
    if(link.indexOf('?') !== -1){
        var parameter = 'orderby';
        var pattern = new RegExp('\\b' + parameter + '=([^&]*)');
        if (link.match(pattern)) {
            link = link.replace(pattern, '');
            if (/[&]/.test(link.slice(-1))) {
                link = link.slice(0, -1);
            }
        }
    }else{
        link = '?';
    }
    layui.use(function () {
        var dropdown = layui.dropdown;
        dropdown.render({
            elem: '#orderbying',
            data: [<?php echo $orde;?>]
        });

    });
    //分頁功能
    layui.use(function(){
        var laypage = layui.laypage;
        var layer = layui.layer;
        laypage.render({
            elem: 'paging',
            count: <?php echo $number;?>,
            limit: <?php echo $pageSize;?>,
            prev: '<em>&lt;</em>',
            next: '<em>&gt;</em>',
            layout: ['skip','prev','next','count'],
            curr: function(){
                var page = location.search.match(/page=(\d+)/);
                return page ? page[1] : 1;
            }(),
            jump: function(e, first){
                if(!first){
                    var url=window.location.search;
                    if(url.indexOf("?")!=-1){
                        var str = url.substr(1);
                        strs = str.split("&");
                        var searchURL = '';
                        for(i=0;i<strs.length;i++) {
                            if(strs[i].split("=")[0]!='page'){
                                searchURL+='&'+strs[i].split("=")[0]+"="+strs[i].split("=")[1];
                            }
                        }
                        location.href = '?page='+e.curr+searchURL;
                    }else{
                        location.href = '?page='+e.curr;
                    }
                }
            }
        });
    });
</script>
<?php
function li_form_input($label,$type,$name,$value,$placeholder) {
    $html = "<div class='layui-col-xs12 layui-col-sm6 layui-col-md4'>".PHP_EOL;
    $html .= "<div class='layui-form-item'>".PHP_EOL;
    $html .= "<label class='layui-form-label'>$label</label>".PHP_EOL;
    $html .= "<div class='layui-input-block'>".PHP_EOL;
    $html .= "<input type='$type' name='$name' value='$value' placeholder='$placeholder' class='layui-input'>".PHP_EOL;
    $html .= "</div></div></div>".PHP_EOL;
    return $html;
}

function li_form_select($label,$name,$option){
    $html = "<div class='layui-col-xs12 layui-col-sm6 layui-col-md4'>".PHP_EOL;
    $html .= "<div class='layui-form-item'>".PHP_EOL;
    $html .= "<label class='layui-form-label'>$label</label>".PHP_EOL;
    $html .= "<div class='layui-input-block'>".PHP_EOL;
    $html .= "<select name='$name'>".PHP_EOL;
    $html .= $option.PHP_EOL;
    $html .= "</select></div></div></div>".PHP_EOL;
    return $html;
}

function li_form_selectSql($label,$name,$placeholder,$conn,$sql,$fag){
    $html = "<div class='layui-col-xs12 layui-col-sm6 layui-col-md4'>".PHP_EOL;
    $html .= "<div class='layui-form-item'>".PHP_EOL;
    $html .= "<label class='layui-form-label'>$label</label>".PHP_EOL;
    $html .= "<div class='layui-input-block'>".PHP_EOL;
    $html .= "<select name='$name'>".PHP_EOL;
    $option = "<option value='0' selected>$placeholder</option>".PHP_EOL;
    if($fag!=0){
        $option = "<option value='0'>$placeholder</option>".PHP_EOL;
    }
    $result = mysqli_query($conn,$sql);
    while ($res = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
        if($res['id']==$fag){
            $option .= "<option value='{$res['id']}' selected>{$res['news']}</option>".PHP_EOL;
        }else{
            $option .= "<option value='{$res['id']}'>{$res['news']}</option>".PHP_EOL;
        }
    }
    $html .= $option;
    $html .= "</select></div></div></div>".PHP_EOL;
    return $html;
}

function li_orde_json($title,$href){
    $js = "{title: '$title',href:link+'&orderby=$href'},".PHP_EOL;
    return $js;
}

function li_path_a($href,$icon,$name) {
    $html = "<a href='{$href}' class='layui-btn layui-btn-primary layui-border-red'><i class='layui-icon'>{$icon}</i>$name</a>".PHP_EOL;
    return $html;
}
<?php
ini_set('session.gc_maxlifetime', 86400); // 設定session的有效時間為24小時
session_start();
define('CHAOYI',true);
require  $_SERVER['DOCUMENT_ROOT'].'/_/_php/data/database.php';
require ROOT.'_php/data/common.php';
require ROOT.'_php/data/config.php';
require ROOT.'_php/temp/li.inc.php';

//重新定義標題
$titlebar = '使用者列表頁';
$tbname = 'U11';

//許可權設定
if(!($seroleId==1 || $seroleId==2 || $seroleId==3)){
    mysqli_close($conn);
    echo prompt('沒有許可權操作,請聯絡管理員','index.php',4,3);
    exit;
}

//顯示每頁顯示的條數
$pageSize = is_numeric($sepagenum) ? $sepagenum : 10;
$page=1;
if(isset($_GET['page']) && $_GET['page']>0){$page=$_GET['page'];}
$offset = $pageSize*($page-1);

//搜尋條件
$condition='';
if(isset($_GET['id'])){
    $id = filterHTML($_GET['id']);
    if($id!=''){
        $condition .= "AND a.id LIKE '{$id}'";
    }
}

if(isset($_GET['unum'])){
    $unum = filterHTML($_GET['unum']);
    if($unum!=''){
        $condition .= "AND a.unum LIKE '%{$unum}%'";
    }
}
if(isset($_GET['wxnum'])){
    $wxnum = filterHTML($_GET['wxnum']);
    if($wxnum!=''){
        $condition .= "AND a.wxnum LIKE '%{$wxnum}%'";
    }
}
if(isset($_GET['cname'])){
    $cname = filterHTML($_GET['cname']);
    if($cname!=''){
        $condition .= "AND a.cname LIKE '%{$cname}%'";
    }
}
if(isset($_GET['level_id'])){
    if($_GET['level_id']!=0){
        $condition .= "AND a.level_id={$_GET['level_id']} ";
    }
}
if(isset($_GET['role_id'])){
    if($_GET['role_id']!=0){
        $condition .= "AND a.role_id={$_GET['role_id']} ";
    }
}
if(isset($_GET['bond_id'])){
    if($_GET['bond_id']!=0){
        $condition .= "AND a.bond_id={$_GET['bond_id']} ";
    }
}
if(isset($_GET['sort'])){
    $sort = filterHTML($_GET['sort']);
    if($sort!=''){
        $condition .= "AND a.sort LIKE '%{$sort}%'";
    }
}

//重新排序條件
$reorder ='ORDER BY a.uptime DESC';
if(isset($_GET['orderby'])){
    $orderby = filterHTML($_GET['orderby']);
    if($orderby!=''){
        $reorder = $orderby;
    }
}

//獲取展示的資料
$sql = "SELECT a.id, a.unum, a.wximg, a.wxnum, a.uname, a.cname, a.tel, a.aduser_id, a.upuser_id, b.tit role, c.tit bond,d.tag tag,d.tit level, a.sort, SUBSTRING(a.adtime,3,14) adtime, SUBSTRING(a.uptime,3,14) uptime FROM u11 a LEFT JOIN u11role b ON a.role_id = b.id LEFT JOIN u11bond c ON a.bond_id = c.id LEFT JOIN u11level d ON a.level_id = d.id WHERE a.isnow=1 $condition $reorder LIMIT $offset,$pageSize";
$result = sqlQuery($conn,$sql);

//獲取頁數
$sqlnum = "SELECT COUNT(id) id FROM u11 a WHERE isnow=1 $condition LIMIT 1";
$resnum = sqlGetOne($conn,$sqlnum);
$number = $resnum['id'];

/**
 * 生成表單
 */
//生成表單HTML
$form = li_form_input($tbname.'-ID','text','id',$id,'請輸入ID');
$form .= li_form_input('會員號碼','text','unum',$unum,'請輸入會員名稱');
$form .= li_form_input('微訊號碼','text','wxnum',$wxnum,'請輸入微訊號碼');
$form .= li_form_input('真實姓名','text','cname',$cname,'請輸入真實姓名');
$form .= li_form_input('自定序號','text','sort',$sort,'請輸入排序');
$form .= li_form_selectSql('使用者等級','level_id','請輸入使用者等級',$conn,"SELECT id, CONCAT(tag,' ', tit) AS news FROM u11level ORDER BY sort ASC LIMIT 50",$_GET['level_id']);
$form .= li_form_selectSql('使用者許可權','role_id','請選擇使用者許可權',$conn,"SELECT id, CONCAT(tit) AS news FROM u11role ORDER BY sort ASC LIMIT 50",$_GET['role_id']);
$form .= li_form_selectSql('使用者關係','bond_id','請選擇使用者關係',$conn,"SELECT id, CONCAT(tit) AS news FROM u11bond ORDER BY sort ASC LIMIT 50",$_GET['bond_id']);

//生成列表展示的HTML
$show = "";
$enseid= enstr($seid);
$entbname = enstr($tbname);
while ($res = mysqli_fetch_array($result,MYSQLI_ASSOC)){
    $tel = substr($res['tel'], 0, 11);
    $show .= "<div class='layui-colla-item ui-item'><div class='layui-colla-title ui-title'><img src='{$res['wximg']}' height='20px' width='20px'> {$res['tag']}{$res['unum']}{$res['cname']} {$res['wxnum']} $tel</div><div class='layui-colla-content ui-content'><table class='layui-table ui-table layui-form'>";
    $enid = enstr($res['id']);
    $show .= "<tr><th>基本操作</th><td><span class='g-r'>{$tbname}-{$res['id']}</span> <a href='inup.php?f={$enid}'>修改</a> | <a href='javascript:void(0);' onclick=\"confirmDel('{$enid}','{$entbname}');\">刪除</a> | <a href='inse.php?f={$enid}&u={$enseid}&w=0'>檢視</a></td></tr>";
    $show .= "<tr><th>微信頭像</th><td><img src='{$res['wximg']}' height='50px' class='pimg'></td></tr>";
    $show .= "<tr><th>使用者等級</th><td>{$res['tag']}{$res['level']}</td></tr>";
    $show .= "<tr><th>會員號碼</th><td>{$res['unum']}</td></tr>";
    $show .= "<tr><th>真實姓名</th><td>{$res['cname']}</td></tr>";
    $show .= "<tr><th>微訊號碼</th><td>{$res['wxnum']}</td></tr>";
    $show .= "<tr><th>電話號碼</th><td>{$res['tel']}</td></tr>";
    $show .= "<tr><th>使用者許可權</th><td>{$res['role']}</td></tr>";
    $show .= "<tr><th>使用者關係</th><td>{$res['bond']}</td></tr>";
    $show .= "<tr><th>設定排序</th><td>使用者排序:{$res['sort']}</td></tr>";

    $weixin = sqlGetOne($conn,'SELECT CONCAT(b.tag,a.unum,a.cname) AS news FROM u11 a LEFT JOIN u11level b ON a.level_id = b.id WHERE a.id='.$res['aduser_id']);
    $show .= "<tr><th>註冊資訊</th><td>{$res['adtime']} of {$weixin['news']}</td></tr>";
    $weixin = sqlGetOne($conn,'SELECT CONCAT(b.tag,a.unum,a.cname) AS news FROM u11 a LEFT JOIN u11level b ON a.level_id = b.id WHERE a.id='.$res['upuser_id']);
    $show .= "<tr><th>修改資訊</th><td>{$res['uptime']} of {$weixin['news']}</td></tr>";
    $show .= "</table></div></div>";
}

//生成連結HTML
$path = li_path_a('inad.php','&#xe624;','新增使用者');

//生成搜尋JS
$orde = li_orde_json('建立時間-按新到舊排序','ORDER BY a.adtime DESC');
$orde .= li_orde_json('建立時間-按舊到新排序','ORDER BY a.adtime ASC');
$orde .= li_orde_json('修改時間-按新到舊排序','ORDER BY a.uptime DESC');
$orde .= li_orde_json('修改時間-按新到舊排序','ORDER BY a.uptime ASC');
$orde .= li_orde_json('會員名稱-小到大排序','ORDER BY a.unum ASC');
$orde .= li_orde_json('會員名稱-大到小排序','ORDER BY a.unum DESC');
$orde .= li_orde_json('自定序號-小到大排序','ORDER BY a.sort ASC');
$orde .= li_orde_json('自定序號-大到小排序','ORDER BY a.sort DESC');

mysqli_close($conn);
include ROOT . '_php/temp/li.tpl.php';
?>

效果圖:

相關文章