//
// ------------------------------------------------------------------------ //
// Based on XoopsHP1.01 by Yoshi, aka HowardGee. //
// ------------------------------------------------------------------------ //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// You may not change or alter any portion of this comment or credits //
// of supporting developers from this source code or any supporting //
// source code which is considered copyrighted (c) material of the //
// original comment or credit authors. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program; if not, write to the Free Software //
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
// ------------------------------------------------------------------------ //
include '../../../include/cp_header.php';
if ( file_exists("../language/".$xoopsConfig['language']."/main.php") ) {
include "../language/".$xoopsConfig['language']."/main.php";
} else {
include "../language/english/main.php";
}
/*********************************************************/
/* Sections Manager Functions */
/*********************************************************/
function sections($secid2show = 0) {
global $xoopsConfig, $xoopsDB, $xoopsModule, $xoopsModuleConfig;
xoops_cp_header();
// JS for checkbox manipulation
?>
"._AM_SECCONF."";
include '../module_prefix.php';
$result = $xoopsDB->query("SELECT secid, secname, secdesc, display, expire FROM ".$xoopsDB->prefix($module_prefix."_sections")." ORDER BY secname");
if ($xoopsDB->getRowsNum($result) > 0) {
$myts =& MyTextSanitizer::getInstance();
echo "
"._MD_CURACTIVESEC._MD_CLICK2EDIT." ";
echo "";
echo " ";
echo ""._MD_ADDARTICLE." ";
echo "";
echo " ";
echo ""._MD_LAST20ART." ";
echo "";
echo "";
}
echo " ";
echo ""._MD_ADDNEWSEC." ";
echo "";
}
function secartedit($artid) {
global $xoopsDB, $xoopsConfig, $xoopsModule, $xoopsModuleConfig;
$myts =& MyTextSanitizer::getInstance();
xoops_cp_header();
echo ""._AM_SECCONF." ";
$artid = intval($artid);
include '../module_prefix.php';
$result = $xoopsDB->query("SELECT artid, secid, title, content, display, expire FROM ".$xoopsDB->prefix($module_prefix."_quiz")." WHERE artid=$artid");
list($artid, $secid, $title, $content, $display, $expire) = $xoopsDB->fetchRow($result);
$artid = intval($artid);
$secid = intval($secid);
$title = $myts->displayTarea($myts->stripSlashesGPC($title));
$content = $myts->htmlSpecialChars($myts->stripSlashesGPC($content));
$display = intval($display);
$expire = $myts->stripSlashesGPC($expire);
$expire = $myts->displayTarea($expire);
echo ""._MD_EDITARTICLE." ";
echo " ";
echo ""._MD_SECNAMEC." "._MD_MAXCHAR." ";
echo " ";
echo ""._MD_SECDESC." "._MD_EXDESC." ";
echo " ";
echo " ";
echo ""._MD_LT_DISPLAY." ";
$checked = ($display) ? "checked" : "";
echo " ";
$currenttime = formatTimestamp(time(), "Y-m-d H:i:s");
$endtime = formatTimestamp(time()+$xoopsModuleConfig['default_days']*86400, "Y-m-d H:i:s");
if ($expire != '0000-00-00 00:00:00') {
if ($expire > $currenttime) {
echo ""._MD_LT_SET_EXPIRE." : ";
echo " ";
echo " ";
echo ""._MD_LT_CURRENT_TIME." : ".$currenttime." ";
} else {
echo ""._MD_LT_EXPIRE." : ";
echo $expire."("._MD_LT_EXPIRED.") ";
echo ""._MD_LT_SET_EXPIRE." : ";
echo " ";
echo " ";
echo ""._MD_LT_CURRENT_TIME." : ".$currenttime." ";
}
} else {
echo ""._MD_LT_SET_EXPIRE." : ";
echo " ";
echo " ";
echo ""._MD_LT_CURRENT_TIME." : ".$currenttime." ";
}
echo " ";
echo "";
}
function cgi_replace($content) {
global $xoopsDB, $xoopsModule;
if (!ereg(_XD_FB_CODE4RESULTS_MARKER, $content)) {
$content = ereg_replace(_XD_FB_CODE4RESULTS_INSERT, _XD_FB_CODE4RESULTS."\n\n" . _XD_FB_CODE4RESULTS_INSERT, $content);
if (!ereg(_XD_FB_CODE4STARTUP, $content)) {
$content = ereg_replace(_XD_FB_CODE4STARTUP_INSERT, "\\0\n\n"._XD_FB_CODE4STARTUP."\n", $content);
} else {
redirect_header("index.php",3,_MD_ERRORQUIZFILE);
}
if (!ereg(_XD_FB_CODE4SEND, $content)) {
$content = ereg_replace(_XD_FB_CODE4SEND_INSERT, "\\0\n\n"._XD_FB_CODE4SEND, $content);
} else {
redirect_header("index.php",3,_MD_ERRORQUIZFILE);
}
}
$content = ereg_replace("toLocaleString","toGMTString",$content);
$action = XOOPS_URL . "/modules/" . $xoopsModule->dirname() . "/process_form.php";
return(ereg_replace("var ResultForm = 'stripSlashesGPC($_POST['secname']) : '';
if (empty($_POST['secname'])) {
redirect_header("index.php", 2, _MD_ERRORSECNAME);
} else {
$secname = $myts->stripSlashesGPC($_POST['secname']);
}
$secdesc = !empty($_POST['secdesc']) ? $myts->stripSlashesGPC($_POST['secdesc']) : '';
$display = intval(empty($_POST['display']) ? 0 : 1);
$setexpire = intval(empty($_POST['setexpire']) ? 0 : 1);
$expire = ($setexpire) ? $myts->stripSlashesGPC($_POST['expire']) : '';
$expire = $xoopsDB->quoteString($expire);
$secname = $xoopsDB->quoteString($secname);
$secdesc = $xoopsDB->quoteString($secdesc);
include '../module_prefix.php';
$newid = $xoopsDB->genId($xoopsDB->prefix($module_prefix."_sections")."_secid_seq");
include '../module_prefix.php';
$mytable = $xoopsDB->prefix($module_prefix."_sections");
$result = $xoopsDB->query("INSERT INTO ".$mytable." (secid, secname, secdesc, display, expire) VALUES ($newid, $secname, $secdesc, $display, $expire)");
if ($result) {
redirect_header("index.php?op=sections",2,_MD_DBUPDATED);
break;
} else {
var_dump($result, $module_prefix, $newid, $display, $expire);
redirect_header("index.php?op=sections",2,_AM_MSG_UPDATE_FAILED);
}
case "secartdelete":
xoops_cp_header();
echo ""._AM_SECCONF." ";
$myts =& MyTextSanitizer::getInstance();
if (!empty($_POST['artid'])) {
$artid = intval($_POST['artid']);
} elseif (!empty($_GET['artid'])) {
$artid = intval($_GET['artid']);
} else {
$artid = 0;
}
$artid = intval($artid);
include '../module_prefix.php';
$result = $xoopsDB->query("SELECT title FROM ".$xoopsDB->prefix($module_prefix."_quiz")." WHERE artid=$artid");
list($title) = $xoopsDB->fetchRow($result);
$title = $myts->displayTarea($title);
xoops_confirm(array('op' => 'secartdelete_ok', 'artid' => $artid), 'index.php', sprintf(_MD_DELETETHISART,$title).' '._MD_RUSUREDELART);
break;
case 'secartdelete_ok':
$artid = !empty($_POST['artid']) ? intval($_POST['artid']) : 0;
if ($artid <= 0) {
redirect_header("index.php?op=sections",2,_MD_DBNOTUPDATED);
}
include '../module_prefix.php';
$xoopsDB->query("DETELE FROM ".$xoopsDB->prefix($module_prefix."_quiz")." WHERE artid=$artid");
include '../module_prefix.php';
$xoopsDB->query("DETELE FROM ".$xoopsDB->prefix($module_prefix."_results")." WHERE quiz_id=$artid");
redirect_header("index.php?op=sections",2,_MD_DBUPDATED);
break;
case "sectionchange":
if ($secid <= 0) {
redirect_header("index.php?op=sections",2,_MD_DBNOTUPDATED);
}
$myts =& MyTextSanitizer::getInstance();
if (empty($_POST['secname'])) {
redirect_header("index.php", 2, _MD_ERRORSECNAME);
} else {
$secname = $myts->stripSlashesGPC($_POST['secname']);
}
$secdesc = !empty($_POST['secdesc']) ? $myts->stripSlashesGPC($_POST['secdesc']) : '';
$secname = $xoopsDB->quoteString($secname);
$secdesc = $xoopsDB->quoteString($secdesc);
$display = intval(empty($_POST['display']) ? 0 : 1);
$setexpire = intval(empty($_POST['setexpire']) ? 0 : 1);
$expire = ($setexpire) ? $myts->stripSlashesGPC($_POST['expire']) : '';
$expire = $xoopsDB->quoteString($expire);
include '../module_prefix.php';
$secid = intval($secid);
$xoopsDB->query("UPDATE ".$xoopsDB->prefix($module_prefix."_sections")." SET secname=$secname, secdesc=$secdesc, display=$display, expire=$expire WHERE secid=$secid");
redirect_header("index.php?op=sections",2,_MD_DBUPDATED);
break;
case "sectiondispchange":
foreach( $_POST['id'] as $secid ) {
$secid = intval($secid);
$display = intval(empty($_POST['display'][$secid]) ? 0 : 1);
include '../module_prefix.php';
$xoopsDB->query("UPDATE ".$xoopsDB->prefix($module_prefix."_sections")." set display=$display WHERE secid=$secid");
}
redirect_header("index.php?op=sections",2,_MD_DBUPDATED);
break;
case "articledispchange":
foreach( $_POST['id'] as $artid ) {
$artid = intval($artid);
$display = intval(empty($_POST['display'][$artid]) ? 0 : 1);
include '../module_prefix.php';
$xoopsDB->query("UPDATE ".$xoopsDB->prefix($module_prefix."_quiz")." set display=$display WHERE artid=$artid");
}
redirect_header("index.php?op=sections",2,_MD_DBUPDATED);
break;
case "secarticleadd":
if ($secid <= 0) {
redirect_header("index.php?op=sections",2,_MD_ERRORSECNAME);
}
$myts =& MyTextSanitizer::getInstance();
if (empty($_POST['title'])) {
redirect_header("index.php?op=sections",2,_MD_ERRORARTNAME);
} else {
$title = $myts->stripSlashesGPC($_POST['title']);
}
$title = $xoopsDB->quoteString($title);
$content = is_uploaded_file($_FILES['quizfile']['tmp_name']) ? implode(file($_FILES['quizfile']['tmp_name'])) : '';
if (empty($content)) {
redirect_header("index.php?op=sections",2,_MD_ERRORARTCONT);
}
$content = cgi_replace($content);
$content = $xoopsDB->quoteString($content);
$posted = $xoopsDB->quoteString(date("Y-m-d H:i:s"));
$poster = $xoopsUser->getVar("uid");
$results_to = $xoopsDB->quoteString($xoopsUser->getVar("email"));
$display = intval(empty($_POST['display']) ? 0 : 1);
$setexpire = intval(empty($_POST['setexpire']) ? 0 : 1);
$expire = ($setexpire) ? $myts->stripSlashesGPC($_POST['expire']) : '';
$expire = $xoopsDB->quoteString($expire);
include '../module_prefix.php';
$newid = $xoopsDB->genId($xoopsDB->prefix($module_prefix."_quiz")."_artid_seq");
include '../module_prefix.php';
$result = $xoopsDB->query("INSERT INTO ".$xoopsDB->prefix($module_prefix."_quiz")." (artid, secid, title, content, posted, poster, results_to, counter, display, expire) VALUES ($newid, $secid, $title, $content, $posted, $poster, $results_to, 0, $display, $expire)");
if ( $result ) {
redirect_header("index.php?op=sections",2,_MD_DBUPDATED);
break;
} else {
xoops_cp_header();
echo "";
xoops_cp_footer();
exit();
}
case "secartedit":
$artid = !empty($_REQUEST['artid']) ? intval($_REQUEST['artid']) : 0;
if ($artid > 0) {
secartedit($artid);
}
break;
case "secartchange":
$artid = !empty($_POST['artid']) ? intval($_POST['artid']) : 0;
if ($artid <= 0) {
redirect_header("index.php?op=sections",2,_MD_DBNOTUPDATED);
}
$myts =& MyTextSanitizer::getInstance();
$secid = intval($_POST['secid']);
$title = !empty($_POST['title']) ? $myts->stripSlashesGPC($_POST['title']) : '';
$content = is_uploaded_file($_FILES['quizfile']['tmp_name']) ? implode(file($_FILES['quizfile']['tmp_name'])) : '';
$display = intval(empty($_POST['display']) ? 0 : 1);
$setexpire = intval(empty($_POST['setexpire']) ? 0 : 1);
$expire = ($setexpire) ? $myts->stripSlashesGPC($_POST['expire']) : '';
$expire = $xoopsDB->quoteString($expire);
$title = $xoopsDB->quoteString($title);
if (empty($content)){
include '../module_prefix.php';
$xoopsDB->query("UPDATE ".$xoopsDB->prefix($module_prefix."_quiz")." SET secid=$secid, title=$title, display=$display, expire=$expire WHERE artid=$artid");
} else {
$content = cgi_replace($content);
$content = $xoopsDB->quoteString($content);
include '../module_prefix.php';
$xoopsDB->query("UPDATE ".$xoopsDB->prefix($module_prefix."_quiz")." SET secid=$secid, title=$title, content=$content, display=$display, expire=$expire WHERE artid=$artid");
}
redirect_header("index.php?op=sections",2,_MD_DBUPDATED);
break;
case "sectiondelete":
xoops_cp_header();
echo ""._AM_SECCONF." ";
xoops_confirm(array('op' => 'sectiondelete_ok', 'secid' => $secid), 'index.php', _MD_RUSUREDELSEC.' '._MD_THISDELETESALL);
break;
case 'sectiondelete_ok':
include '../module_prefix.php';
$sql = sprintf("DELETE FROM %s WHERE secid = %u", $xoopsDB->prefix($module_prefix."_quiz"), $secid);
$xoopsDB->query($sql);
include '../module_prefix.php';
$sql = sprintf("DELETE FROM %s WHERE secid = %u", $xoopsDB->prefix($module_prefix."_sections"), $secid);
$xoopsDB->query($sql);
redirect_header("index.php?op=sections",2,_MD_DBUPDATED);
break;
case "resultdelete":
xoops_cp_header();
echo ""._AM_SECCONF." ";
$myts =& MyTextSanitizer::getInstance();
if (!empty($_POST['res_id'])) {
$res_id = intval($_POST['res_id']);
} elseif (!empty($_GET['res_id'])) {
$res_id = intval($_GET['res_id']);
} else {
$res_id = 0;
}
include '../module_prefix.php';
$result = $xoopsDB->query("SELECT quiz_id, uid, score, timestamp FROM ".$xoopsDB->prefix($module_prefix."_results")." WHERE id=$res_id");
list($quiz_id, $uid, $score, $timestamp) = $xoopsDB->fetchRow($result);
include '../module_prefix.php';
$result = $xoopsDB->query("SELECT title FROM ".$xoopsDB->prefix($module_prefix.'_quiz')." WHERE artid=$quiz_id");
list($title) = $xoopsDB->fetchRow($result);
$message = " "._MD_RUSUREDELREC." ";
$message .= ""._MD_LT_STUDENT." "._MD_LT_TITLE." "._MD_LT_SCORE." "._MD_LT_DATE." ";
$message .= "".$xoopsUser->getUnameFromId($uid)." $title $score $timestamp ";
$message .= "
";
xoops_confirm(array('op' => 'resultdelete_ok', 'res_id' => $res_id, 'artid' => $quiz_id), 'index.php', $message);
break;
case "resultdelete_ok":
$res_id = !empty($_POST['res_id']) ? intval($_POST['res_id']) : 0;
$artid = !empty($_POST['artid']) ? intval($_POST['artid']) : 0;
if ($res_id <= 0) {
redirect_header("index.php?op=sections",2,_MD_DBNOTUPDATED);
}
include '../module_prefix.php';
$sql = sprintf("DELETE FROM %s WHERE id = %u", $xoopsDB->prefix($module_prefix."_results"), $res_id);
$xoopsDB->query($sql);
redirect_header("../index.php?op=viewresults&artid=$artid",2,_MD_DBUPDATED);
break;
default:
sections();
break;
}
xoops_cp_footer();
?>