線上書籍

Home

[1071]XOOPS模組開發

<?php /*-----------引入檔案區--------------*/ include_once "header.php"; $xoopsOption['template_main'] = "snews_index.tpl"; include_once XOOPS_ROOT_PATH . "/header.php"; /*-----------function區--------------*/ //顯示內容 function snews_show($sn) { global $xoopsTpl, $xoopsDB, $TadUpFiles; $myts = MyTextSanitizer::getInstance(); $tbl = $xoopsDB->prefix('snews'); $sql = "SELECT * FROM `$tbl` WHERE `sn` = '{$sn}'"; $result = $xoopsDB->query($sql) or web_error($sql); $snews = $xoopsDB->fetchArray($result); $snews['content'] = $myts->displayTarea($snews['content'], 1, 0, 0, 0, 0); $snews['title'] = $myts->htmlSpecialChars($snews['title']); $snews['username'] = $myts->htmlSpecialChars($snews['username']); $TadUpFiles->set_col('sn', $sn); $snews['cover'] = $TadUpFiles->show_files('pic', false); $TadUpFiles->set_col('snews', $sn); $snews['files'] = $TadUpFiles->show_files(); // die(var_dump($snews)); $xoopsTpl->assign('snews', $snews); 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 = new sweet_alert(); $sweet_alert->render("snews_del", "index.php?op=snews_delete&sn=", 'sn'); } //顯示列表 function snews_list() { global $xoopsTpl, $xoopsDB, $TadUpFiles; $myts = MyTextSanitizer::getInstance(); $tbl = $xoopsDB->prefix('snews'); $sql = "SELECT * FROM `$tbl` ORDER BY `update_time` DESC"; //getPageBar($原sql語法, 每頁顯示幾筆資料, 最多顯示幾個頁數選項); $PageBar = getPageBar($sql, 3, 10); $bar = $PageBar['bar']; $sql = $PageBar['sql']; $total = $PageBar['total']; $result = $xoopsDB->query($sql) or web_error($sql); $all = array(); while ($snews = $xoopsDB->fetchArray($result)) { $snews['content'] = $myts->displayTarea($snews['content'], 1, 0, 0, 0, 0); $snews['title'] = $myts->htmlSpecialChars($snews['title']); $snews['username'] = $myts->htmlSpecialChars($snews['username']); $TadUpFiles->set_col('sn', $snews['sn']); $snews['cover'] = $TadUpFiles->get_pic_file('thumb'); $all[] = $snews; } $xoopsTpl->assign('all', $all); $xoopsTpl->assign('bar', $bar); $xoopsTpl->assign('total', $total); } //刪除內容 function snews_delete($sn) { global $xoopsTpl, $xoopsDB, $TadUpFiles; $tbl = $xoopsDB->prefix('snews'); $sql = "DELETE FROM `$tbl` WHERE `sn` = '{$sn}'"; $xoopsDB->queryF($sql) or web_error($sql); $TadUpFiles->set_col('sn', $sn); $TadUpFiles->del_files(); $TadUpFiles->set_col('snews', $sn); $TadUpFiles->del_files(); } /*-----------執行動作判斷區----------*/ include_once $GLOBALS['xoops']->path('/modules/system/include/functions.php'); $op = system_CleanVars($_REQUEST, 'op', '', 'string'); $sn = system_CleanVars($_REQUEST, 'sn', 0, 'int'); switch ($op) { //下載檔案 case "tufdl": $files_sn = isset($_GET['files_sn']) ? intval($_GET['files_sn']) : ""; $TadUpFiles->add_file_counter($files_sn, false, true); exit; case "snews_delete": snews_delete($sn); header("location: index.php"); exit; default: if ($sn) { snews_show($sn); $op = "snews_show"; } else { snews_list(); $op = "snews_list"; } break; } /*-----------秀出結果區--------------*/ $xoopsTpl->assign('op', $op); $xoopsTpl->assign("toolbar", toolbar_bootstrap($interface_menu)); include_once XOOPS_ROOT_PATH . '/footer.php';