配置多值字段

摘要:if ($act == 'honor'){ if ($_POST && isset($_POST['img'])) { if(!$_POST["img"] or !$_POST["title"] or !$_POST["url"]){ $zbp-

if ($act == 'honor'){
    if ($_POST && isset($_POST['img'])) {
        if(!$_POST["img"] or !$_POST["title"] or !$_POST["url"]){
            $zbp->SetHint('bad','图片/标题/链接不能为空');
            Redirect('./main.php?act=honor');
            exit();
        }
        if ($_GET && isset($_GET['type'])) {
            if ($_GET['type'] == 'add') {
                if($zbp->Config('teke')->HasKey('UserHonor')){
                    $slidedata = json_decode($zbp->Config('teke')->UserHonor,true);
                }
                $slidedata[] = $_POST;
                foreach ($slidedata as $key => $row){
                    $order[$key] = $row['order'];
                }
                if(is_array($order)){
                    array_multisort($order, SORT_ASC,$slidedata);
                }
                $zbp->Config('teke')->UserHonor = json_encode($slidedata);
                $zbp->SaveConfig('teke');
                header("Refresh:0");
            }elseif($_GET['type'] == 'edit'){
                $slidedata = json_decode($zbp->Config('teke')->UserHonor,true);
                $editid = $_POST['editid'];
                unset($_POST['editid']);
                $slidedata[$editid] =$_POST;
                foreach ($slidedata as $key => $row) {
                    $order[$key] = $row['order'];
                }
                array_multisort($order, SORT_ASC,$slidedata);
                $zbp->Config('teke')->UserHonor = json_encode($slidedata);
                $zbp->SaveConfig('teke');
                $zbp->ShowHint('修改成功');
            }
        }
    }elseif ($_GET && isset($_GET['type'])) {
        if ($_GET['type'] == 'del') {
            $slidedata = json_decode($zbp->Config('teke')->UserHonor,true);
            $editid = $_GET['id'];
            unset($slidedata[$editid]);
            $zbp->Config('teke')->UserHonor = json_encode($slidedata);
            $zbp->SaveConfig('teke');
            $zbp->ShowHint('删除成功');
        }
    }
    ?>
    <dl>
        <dt>设置 <span>(请点击右侧 <img src="/zb_system/image/admin/ok.png" alt="对号"> 图标保存修改)</span></dt>
        <dd>
            <table width="100%" border="0" class="slidetable">
                <thead>
                <tr>
                    <th scope="col" width="9%" height="32" nowrap="nowrap">序号</th>
                    <th scope="col" width="58%">信息</th>
                    <th scope="col" width="10%">排序</th>
                    <th scope="col" width="9%">显示</th>
                    <th scope="col" width="14%">操作</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td colspan="5" style="padding:0;">
                        <form action="?act=honor&type=add" method="post">
                            <table class="slidetable" style="border:0;">
                                <tr>
                                    <td align="center" width="9%">0</td>
                                    <td width="58%">
                                        <div class="slideleft">
                                            <span class="slideimg dftimg">
                                                <span>
                                                    <input type="hidden" name="img" value="" class="thumbsrc">
                                                    <button type="button" value="" class="uploadimg uploadico">上传图片</button>
                                                </span>
                                                <img src="img/theme/uploadimg.png" class="thumbimg">
                                            </span>
                                        </div>
                                        <span class="slideset">
                                            <input type="text" name="title" value="" placeholder="请输入幻灯标题 (必填)" required="required" class="slidetext">
                                            <input type="text" name="url" value="" placeholder="请输入链接地址 (必填)" required="required" class="slidetext slidetexttitle">
                                        </span>
                                    </td>
                                    <td width="10%"><input type="text" name="order" value="99" class="slidetext slideorder"></td>
                                    <td width="9%"><input type="text" class="checkbox" name="isused" value="1"></td>
                                    <td width="14%"><input type="hidden" name="editid" value=""><input name="add" type="submit" class="format" value="增加"></td>
                                </tr>
                            </table>
                        </form>
                    </td>
                </tr>
                <?php
                $slidedata = json_decode($zbp->Config('teke')->UserHonor,true);
                if(is_array($slidedata)){
                    foreach ($slidedata as $key => $value) {
                        ?>
                        <tr>
                            <td colspan="5" style="padding:0;">
                                <form action="?act=honor&type=edit" class="setting slideitem" method="post" name="slide">
                                    <table class="slidetable" style="border:0; border-top:1px solid #ddd;">
                                        <tr>
                                            <td align="center" width="9%"><?php echo $value['order']; ?></td>
                                            <td width="58%">
                                                <div class="slideleft">
                                                    <span class="slideimg"">
                                                        <span>
                                                            <input type="hidden" name="img" value="<?php echo $value['img']; ?>" class="thumbsrc">
                                                            <button type="button" value="" class="uploadimg uploadico">上传图片</button>
                                                        </span>
                                                        <img src="<?php echo $value['img']; ?>" class="thumbimg">
                                                    </span>
                                                </div>
                                                <span class="slideset">
                                                    <input type="text" name="title" value="<?php echo $value['title']; ?>" placeholder="请输入幻灯标题 (必填)" required="required" class="slidetext">
                                                    <input type="text" name="url" value="<?php echo $value['url']; ?>" placeholder="请输入链接地址 (必填)" required="required" class="slidetext slidetexttitle">
                                                </span>
                                            </td>
                                            <td width="10%"><input type="text" name="order" value="<?php echo $value['order']; ?>" class="slidetext slideorder"></td>
                                            <td width="9%"><input type="text" class="checkbox" name="isused" value="<?php echo $value['isused']; ?>"></td>
                                            <td width="14%" nowrap="nowrap">
                                                <input type="hidden" name="editid" value="<?php echo $key; ?>">
                                                <input name="edit" type="submit" value="" class="setokicon">
                                                <input name="del" type="button" class="setdelicon" value="" onclick="if(confirm('您确定要进行删除操作吗?')){location.href='?act=honor&type=del&id=<?php echo $key; ?>'}"/>
                                            </td>
                                        </tr>
                                    </table>
                                </form>
                            </td>
                        </tr>
                    <?php }} ?>
                </tbody>
            </table>
        </dd>
    </dl>
    <?php
}


调用

{php}$slidedata = json_decode($zbp->Config('teke')->UserTeam,true);{/php}
{if isset($slidedata)}
{foreach $slidedata as $value}
{if $value['isused']}
<li>
    <a class="pic" href="{$value['img']}" target="_blank">
        <img src="{$value['img']}" alt="{$value['title']}">
    </a>
    <p>{$value['title']}</p>
</li>
{/if}
{/foreach}
{/if}


一次调用2个

{php}$slidedata = json_decode($zbp->Config('teke')->UserHonor,true);{/php}
{if isset($slidedata)}
{foreach array_chunk($slidedata, 2) as $value}
<li>
    <a class="pic" href="{GetValueInArray($value[0], 'img')}" target="_blank">
        <img src="{GetValueInArray($value[0], 'img')}" alt="{GetValueInArray($value[0], 'title')}">
        <p>{GetValueInArray($value[0], 'title')}</p>
    </a>
    <a class="pic" href="{GetValueInArray($value[1], 'img')}" target="_blank">
        <img src="{GetValueInArray($value[1], 'img')}" alt="{GetValueInArray($value[1], 'title')}">
        <p>{GetValueInArray($value[1], 'title')}</p>
    </a>
</li>
{/foreach}
{/if}