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 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 class="layui-form m-body" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" 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 ad_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 ad_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 ad_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 ad_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 ad_path_a($href,$icon,$name) {
    $html = "<a href='{$href}' class='layui-btn layui-btn-primary layui-border-orange'><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/ad.inc.php';

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

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

//接收表單資料操作
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 = '/_/pic/U11/000000.jpg';
    if($_FILES['picfile']['name']){
        $picture = picfile($_FILES);
    }

    //插入一條資料
    $nowTime = date('Y-m-d H:i:s', time());
    $sql = "INSERT INTO u11 (unum, ucode, uname, upwd, wximg, wxnum, cname, tel, addr, ps, level_id, role_id, bond_id, sort, aduser_id, upuser_id, adtime, uptime)VALUES('$unum','$ucode','$uname','$upwd','$picture','$wxnum','$cname','$tel','$addr','$ps','$level_id','$role_id','$bond_id','$sort','$seid','$seid','$nowTime','$nowTime')";
    sqlQuery($conn,$sql);

    //向使用者擴充套件表插入一條資料,資料保留預設值
    $inid = mysqli_insert_id($conn);
    $sqlaa = "INSERT INTO u11aa (id, aduser_id, upuser_id, adtime, uptime)VALUES('$inid', '$seid', '$seid', '$nowTime', '$nowTime')";
    sqlQuery($conn,$sqlaa);

    //向使用者圖片表插入一條資料
    $sqlimg = "INSERT INTO u11img (img, user_id, aduser_id, adtime, upuser_id, uptime) VALUES ('$picture', '$inid', '$seid', '$nowTime', '$seid', '$nowTime')";
    sqlQuery($conn,$sqlimg);

    //關閉資料庫
    mysqli_close($conn);

    $enid = enstr($inid);
    echo prompt('新增資料成功',"inup.php?f={$enid}",1,3);
    exit;
}

/**
 * 生成HTML頁面
 */
//生成表單HTML
$form = ad_form_input('會員號碼','text','unum','1002','請輸入會員名稱');
$form .= ad_form_input('會員密碼','text','ucode','UH78GY7P','請輸入會員密碼');
$form .= ad_form_input('登陸英文','text','uname','ccc','請輸入登陸英文');
$form .= ad_form_input('登陸密碼','text','upwd','123456','請輸入登陸密碼');
$form .= ad_form_input('微信圖片','file','picfile','','微信圖片',1,0);
$form .= ad_form_input('微訊號碼','text','wxnum','onestopweb','請輸入微訊號碼');
$form .= ad_form_input('真實姓名','text','cname','測試姓名','請輸入真實姓名');
$form .= ad_form_textarea('電話號碼','tel','13556043422 19927673428','請輸入電話號碼');
$form .= ad_form_textarea('聯絡地址','addr','廣東中山 廣州番禺','請輸入聯絡地址');
$form .= ad_form_textarea('使用者備註','ps','閱誰問君誦,水落清香浮。','請輸入使用者備註');
$form .= ad_form_selectSql('使用者等級','level_id',$conn,"SELECT id, CONCAT(tag,' ', tit) AS news FROM u11level ORDER BY sort ASC LIMIT 50",'1',0);
$form .= ad_form_selectSql('使用者許可權','role_id',$conn,"SELECT id, CONCAT(tit) AS news FROM u11role ORDER BY sort ASC LIMIT 50",'1',0);
$form .= ad_form_selectSql('使用者關係','bond_id',$conn,"SELECT id, CONCAT(tit) AS news FROM u11bond ORDER BY sort ASC LIMIT 50",'1',0);
$form .= ad_form_input('自定序號','number','sort','999999','請輸入排序號1~999999',0);

//生成預覽HTML
$view = <<<'view'
<img class="pimg"  src="/_/pic/U11/000000.jpg" height="100px" title="預設" />
<hr>
<dl><dt>會員號碼:</dt> </dl><dl>
<dt>會員密碼:</dt> </dl><dl>
<dt>登陸英文:</dt></dl>
<dl><dt>登陸密碼:</dt> </dl>
<dl><dt>微信圖片:</dt>/_/pic/U11/000000.jpg</dl>
<dl><dt>微訊號:</dt></dl>
<dl><dt>真實姓名:</dt></dl>
<dl><dt>電話號碼:</dt></dl>
<dl><dt>聯絡地址:</dt></dl>
<dl><dt>使用者備註:</dt></dl>
<dl><dt>使用者等級:</dt>A 優質使用者</dl>
<dl><dt>使用者許可權:</dt>超級管理員 </dl>
<dl><dt>使用者關係:</dt>家庭 </dl>
<dl><dt>自定序號:</dt>999999 </dl>
<dl><dt>生成連結:</dt>http://192.168.1.70/?f=null</dl>
<dl><dt>建立時間:</dt></dl><dl>
<dt>建立使用者:</dt></dl>
<dl><dt>修改時間:</dt></dl>
<dl><dt>修改使用者:</dt></dl> 
view;

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

//生成連結HTML
$path = ad_path_a('index.php','&#xe65c;','返回列表');

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

效果圖:

相關文章