default:
# ---- 目前網址 ----
$_SESSION['return_url'] = getCurrentUrl();
$op = "opList";
opList();
break;
```
2. 函數
admin/main.php ```
####################################################
# 列表
####################################################
function opList() {
global $xoopsDB, $xoopsTpl, $module_name, $kind, $ugmKind;
#---- 過濾讀出的變數值 ----
$myts = MyTextSanitizer::getInstance();
# ----得到ForeignKeyMainOption選項 ----------------------------
$ForeignKeyMainOption = $ugmKind->get_kindOption($kind);
$ForeignKeyForm = "
";
$xoopsTpl->assign('ForeignKeyForm', $ForeignKeyForm);
$xoopsTpl->assign('kind', $kind);
#身體array
$and_key = $kind ? " where a.kind='{$kind}'" : "";
//sn kind kind_gallery title summary content price amount enable date sort
$sql = "select a.*,b.title as kind_title
from " . $xoopsDB->prefix("cnu_show_prod") . " as a
left join " . $xoopsDB->prefix("cnu_show_kind") . " as b on a.kind=b.sn
{$and_key}
order by a.sort desc,a.date desc"; //die($sql);
//getPageBar($原sql語法, 每頁顯示幾筆資料, 最多顯示幾個頁數選項);
$p_count = 20;
$PageBar = getPageBar($sql, $p_count, 10);
$bar = $PageBar['bar'];
$sql = $PageBar['sql'];
$total = $PageBar['total'];
$bar = $total > $p_count ? $bar : "";
$xoopsTpl->assign("bar", $bar);
$result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 3, web_error());
$rows = array();
#----單檔圖片上傳
$subdir = "prod"; //子目錄(前後不要有 / )
$ugmUpFiles = new ugmUpFiles($module_name, $subdir); //實體化
$col_name = "prod";
$thumb = false ; //顯示縮圖 //資料表關鍵字
while ($row = $xoopsDB->fetchArray($result)) {
$row['sn'] = intval($row['sn']);
#一般文字
$row['title'] = $myts->htmlSpecialChars($row['title']);
$row['enable'] = intval($row['enable']);
$row['choice'] = intval($row['choice']);
$row['price'] = intval($row['price']);
$row['date'] = intval($row['date']);
$row['kind_title'] = $myts->htmlSpecialChars($row['kind_title']);
#日期
$row['date'] = date("Y-m-d", xoops_getUserTimestamp($row['date'])); //從資料庫撈出
$col_sn = $row['sn']; //關鍵字流水號
$row['prod'] = $ugmUpFiles->get_rowPicSingleUrl($col_name,$col_sn,$thumb);
#-----------------------------------
if($row['prod']){
$row['prod'] = "";
}
$rows[] = $row;
}
# ---- fancybox_code ----
if (!file_exists(XOOPS_ROOT_PATH . "/modules/tadtools/fancybox.php")) {
redirect_header("index.php", 3, _MA_NEED_TADTOOLS);
}
include_once XOOPS_ROOT_PATH . "/modules/tadtools/fancybox.php";
$fancybox = new fancybox('.showImg', '90%', '90%');
$reload = false;
$fancybox->render($reload);
#刪除-------------------------------------------------------
if (!file_exists(XOOPS_ROOT_PATH . "/modules/tadtools/sweet_alert.php")) {
redirect_header("index.php", 3, _MA_NEED_TADTOOLS);
}
include_once XOOPS_ROOT_PATH . "/modules/tadtools/sweet_alert.php";
$sweet_alert_obj = new sweet_alert();
$sweet_alert_obj->render('op_delete_js', "?op=opDelete&sn=", "sn");
# ------------------------------------------------------------
$xoopsTpl->assign("rows", $rows);
}
```
3. 樣板
templates/cnu\_show\_adm\_main.tpl ```
<{if $op=="opList"}>
<{/if}>
```
4.