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;?>
<body>
<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 params = new URLSearchParams(window.location.search);
                    var val = params.get('f')
                    var deval = window.atob(decodeURIComponent(val));
                    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+'?f='+val+'">'+filename+'?id='+deval+'</a></li>');
                </script>
            </ul>
        </div>
        <form class="layui-form m-body" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']).'?f='.$f;?>" enctype="multipart/form-data">
            <blockquote class="layui-elem-quote">
                <h2><?php echo $titlebar;?></h2>
                <p><span>操作資訊:<?php echo date("Y-m-d H:i:s");?> of <?php echo $seid?></span> </p>
            </blockquote>
            <div class="layui-card layui-panel">
                <div class="layui-row">
                    <div class="layui-col-xs12 layui-col-sm12 <?php echo $seiscolCss?>">
                        <div class="layui-card">
                            <div class="layui-card-header">
                                <h3>修改資料</h3>
                            </div>
                            <div class="layui-card-body" >
                                <?php echo $form?>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn" lay-submit="" lay-filter="submit">立即提交</button>
                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>
                    <div class="layui-col-xs12 layui-col-sm12 <?php echo $seiscolCss?>">
                        <div class="layui-card">
                            <div class="layui-card-header">
                                <h3>頁面預覽</h3>
                            </div>
                            <div class="layui-card-body ui-view" >
                                <?php echo $view;?>
                            </div>
                            <div class="layui-card-header">
                                <h3>操作提示</h3>
                            </div>
                            <div class="layui-card-body" >
                                <?php echo $hint;?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
        <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>
<?php

function up_form_input($label,$type,$name,$value,$placeholder,$display='1',$required='1') {
    $html = "<div class='layui-form-item'>".PHP_EOL;
    $html .= "<label class='layui-form-label'>$label</label>".PHP_EOL;
    if($display=='1'){
        $html .= "<div class='layui-input-block'>".PHP_EOL;
    }else{
        $html .= "<div class='layui-input-inline'>".PHP_EOL;
    }
    if($required=='1'){
        $html .= "<input type='$type' name='$name' value='$value' placeholder='$placeholder' autocomplete='off' required lay-verify='required' class='layui-input'>".PHP_EOL;
    }else{
        $html .= "<input type='$type' name='$name' value='$value' placeholder='$placeholder' autocomplete='off' class='layui-input'>".PHP_EOL;
    }
    $html .= "</div></div>".PHP_EOL;
    return $html;
}

function up_form_textarea($label,$name,$value,$placeholder){
    $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 .= "<textarea name='$name' placeholder='$placeholder' class='layui-textarea' autoHeight='true' style='overflow-y:hidden'>$value</textarea>".PHP_EOL;
    $html .= "</div></div>".PHP_EOL;
    return $html;
}

function up_form_select($label,$name,$option,$display='1'){
    $html = "<div class='layui-form-item'>".PHP_EOL;
    $html .= "<label class='layui-form-label'>$label</label>".PHP_EOL;
    if($display=='1'){
        $html .= "<div class='layui-input-block'>".PHP_EOL;
    }else{
        $html .= "<div class='layui-input-inline'>".PHP_EOL;
    }
    $html .= "<select name='$name'>".PHP_EOL;
    $html .= $option;
    $html .= "</select></div></div>".PHP_EOL;
    return $html;
}
function up_form_selectSql($label,$name,$conn,$sql,$fag,$display='1'){
    $html = "<div class='layui-form-item'>".PHP_EOL;
    $html .= "<label class='layui-form-label'>$label</label>".PHP_EOL;
    if($display=='1'){
        $html .= "<div class='layui-input-block'>".PHP_EOL;
    }else{
        $html .= "<div class='layui-input-inline'>".PHP_EOL;
    }
    $html .= "<select name='$name'>".PHP_EOL;
    $option = "";
    $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>".PHP_EOL;
    return $html;
}

function up_view_dl($name,$value){
    $html ="<dl><dt>{$name}:</dt>".PHP_EOL;
    $html .=$value.PHP_EOL;
    $html .=" </dl>".PHP_EOL;
    return $html;
}

function up_view_dlArr($name,$str){
    $html ="<dl><dt>{$name}:</dt>".PHP_EOL;
    $arr = strtoarr($str);
    foreach ($arr as $key => $value) {
        if($key==0){
            $html .= "<dd>首要的:$value</dd>".PHP_EOL;
        }else{
            $number = $key+1;
            $html .= "<dd>第{$number}個:$value</dd>".PHP_EOL;
        }
    }
    $html .=" </dl>".PHP_EOL;
    return $html;
}

function up_view_dlSql($name,$conn,$sql){
    $html ="<dl><dt>{$name}:</dt>".PHP_EOL;
    $result = sqlGetOne($conn,$sql);
    $html .=$result['news'].PHP_EOL;
    $html .=" </dl>".PHP_EOL;
    return $html;
}

function up_view_imgSql($src,$conn,$sql){
    $html="<img class='pimg'  src='$src' height='100px' title='主圖' alt='主圖' />";
    $result = mysqli_query($conn,$sql);
    while ($res = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
        $html .= "<img class='pimg' src='{$res['img']}' height='100px' title='{$res['tit']} &#10;{$res['cont']}' alt='{$res['tit']}' />".PHP_EOL;
    }
    return $html;
}

function up_path_a($href,$icon,$name) {
    $html = "<a href='{$href}' class='layui-btn layui-btn-primary layui-border-blue'><i class='layui-icon'>{$icon}</i>$name</a>".PHP_EOL;
    return $html;
}
<?php
ini_set('session.gc_maxlifetime', 86400);
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/load/picture.php';
require ROOT.'_php/temp/up.inc.php';

//重新定義標題
$titlebar = '修改使用者';

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

//安全設定
$f = trim($_GET['f']);
$id = destr($f);
if(!is_numeric($id)){
    mysqli_close($conn);
    echo prompt('解碼不正確,請聯絡管理員','index.php',2,3);
    exit;
}

//獲取展示的資料
$ssql = "SELECT id, unum, ucode, uname, upwd, wximg, wxnum, cname, tel, addr, ps, level_id, role_id, bond_id, sort, sessid, isnow, aduser_id, upuser_id, adtime, uptime FROM u11 WHERE id=$id LIMIT 1";
$result = sqlGetOne($conn, $ssql);

//接收表單資料操作
if($_SERVER["REQUEST_METHOD"] == "POST"){
    $unum = filterHTML($_POST["unum"]);
    $ucode = filterHTML($_POST["ucode"]);
    $uname = filterHTML($_POST["uname"]);
    $upwd = enstr($_POST["upwd"]);
    $wxnum = filterHTML($_POST["wxnum"]);
    $cname = filterHTML($_POST["cname"]);
    $tel = strtostr($_POST["tel"]);
    $addr = strtostr($_POST["addr"]);
    $ps = filterHTML($_POST["ps"]);
    $level_id = filterHTML($_POST["level_id"]);
    $role_id = filterHTML($_POST["role_id"]);
    $bond_id = filterHTML($_POST["bond_id"]);
    $sort = filterHTML($_POST["sort"]);

    //開始上傳圖片,可空
    $picture = null;
    if($_FILES['picfile']['name']){
        $picture = picfile($_FILES);
    }

    //插入一條資料
    $nowTime = date('Y-m-d H:i:s', time());
    if($picture == null){
        $sql = "UPDATE u11 SET unum = '$unum' , ucode = '$ucode' , uname = '$uname' , upwd = '$upwd' , wxnum = '$wxnum' , cname = '$cname' , tel = '$tel' , addr = '$addr' , ps = '$ps' , level_id = '$level_id' , role_id = '$role_id' , bond_id = '$bond_id' , sort = '$sort' , upuser_id = '$seid' , uptime = '$nowTime' WHERE id = '$id'";
    }else{
        $sql = "UPDATE u11 SET unum = '$unum' , ucode = '$ucode' , uname = '$uname' , upwd = '$upwd' , wximg = '$picture' , wxnum = '$wxnum' , cname = '$cname' , tel = '$tel' , addr = '$addr' , ps = '$ps' , level_id = '$level_id' , role_id = '$role_id' , bond_id = '$bond_id' , sort = '$sort' , upuser_id = '$seid' , uptime = '$nowTime' WHERE id = '$id'";
        //向使用者圖片表插入一條資料
        $sqlimg = "INSERT INTO u11img (img, user_id, aduser_id, adtime, upuser_id, uptime) VALUES ('$picture', '$id', '$seid', '$nowTime', '$seid', '$nowTime')";
        sqlQuery($conn,$sqlimg);
    }
    sqlQuery($conn,$sql);

    mysqli_close($conn);
    echo prompt('修改資料成功',"?f={$f}",1,3);
    exit;
}

/**
 * 生成HTML頁面
 */
// 生成表單HTML
$form = up_form_input('會員名稱','text','unum',$result['unum'],'請輸入會員名稱');
$form .= up_form_input('會員密碼','text','ucode',$result['ucode'],'請輸入會員密碼');
$form .= up_form_input('登陸英文','text','uname',$result['uname'],'請輸入登陸英文');
$form .= up_form_input('登陸密碼','text','upwd',destr($result['upwd']),'請輸入登陸密碼');
$form .= up_form_input('微信圖片','file','picfile','','微信圖片',1,0);
$form .= up_form_input('微訊號碼','text','wxnum',$result['wxnum'],'請輸入微訊號碼');
$form .= up_form_input('真實姓名','text','cname',$result['cname'],'請輸入真實姓名');
$form .= up_form_textarea('電話號碼','tel',$result['tel'],'請輸入電話號碼');
$form .= up_form_textarea('聯絡地址','addr',$result['addr'],'請輸入聯絡地址');
$form .= up_form_textarea('使用者備註','ps',$result['ps'],'請輸入使用者備註');

$form .= up_form_selectSql('使用者等級','level_id',$conn,"SELECT id, CONCAT(tag,' ', tit) AS news FROM u11level ORDER BY sort ASC LIMIT 50",$result['level_id'],0);
$form .= up_form_selectSql('使用者許可權','role_id',$conn,"SELECT id, CONCAT(tit) AS news FROM u11role ORDER BY sort ASC LIMIT 50",$result['role_id'],0);
$form .= up_form_selectSql('使用者關係','bond_id',$conn,"SELECT id, CONCAT(tit) AS news FROM u11bond ORDER BY sort ASC LIMIT 50",$result['bond_id'],0);

$form .= up_form_input('自定序號','number','sort',"{$result['sort']}",'請輸入排序號1~999999',0);

//生成預覽HTML
$view = up_view_imgSql($result['wximg'],$conn,"SELECT img, tit, cont FROM u11img WHERE user_id = {$result['id']} ORDER BY sort ASC LIMIT 10");
$view .= '<hr>';
$view .= up_view_dl('編號ID',$result['id']);
$view .= up_view_dl('會員名稱',$result['unum']);
$view .= up_view_dl('會員密碼',$result['ucode']);
$view .= up_view_dl('登陸英文',$result['uname']);
$view .= up_view_dl('登陸密碼',$result['upwd']);
$view .= up_view_dl('微信圖片',$result['wximg']);
$view .= up_view_dl('微訊號',$result['wxnum']);
$view .= up_view_dl('真實姓名',$result['cname']);
$view .= up_view_dlArr('電話號碼',$result['tel']);
$view .= up_view_dlArr('聯絡地址',$result['addr']);
$view .= up_view_dl('使用者備註',$result['ps']);
$view .= up_view_dlSql('使用者等級',$conn,"SELECT CONCAT(tag,' ', tit,' -&gt; ', cont) AS news FROM u11level WHERE id = {$result['level_id']} LIMIT 1");
$view .= up_view_dlSql('使用者許可權',$conn,"SELECT CONCAT(tit,' -&gt; ', cont) AS news FROM u11role WHERE id = {$result['role_id']} LIMIT 1");
$view .= up_view_dlSql('使用者關係',$conn,"SELECT CONCAT(tit,' -&gt; ', cont) AS news FROM u11bond WHERE id = {$result['bond_id']} LIMIT 1");
$view .= up_view_dl('自定序號',$result['sort']);
$view .= up_view_dl('生成連結','http://192.168.1.70/?i=HDU676750001onestopweb');
$view .= up_view_dlSql('新增使用者',$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={$result['aduser_id']} LIMIT 1");
$view .= up_view_dl('新增時間',$result['adtime']);
$view .= up_view_dlSql('修改使用者',$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={$result['upuser_id']} LIMIT 1");
$view .= up_view_dl('修改時間',$result['uptime']);

//生成提示HTML
$hint = <<<'hint'
<ul>
    <li>提示資訊:暫無</li>
    <li>提示資訊:暫無</li>
</ul>
hint;

//生成連結HTML
$path = up_path_a('index.php?id='.$id,'&#xe65c;','返回列表');
$path .= up_path_a('inupaa.php?f='.$f,'&#xe642;','預設設定');
$path .= up_path_a('###子圖列表','&#xe64a;','子圖列表');
$path .= up_path_a('###新增子圖','&#xe624;','新增子圖');

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

效果圖:

相關文章