Location: PHPKode > projects > Nukequiz > html/modules/Nukequiz/admin/NQAExportQuestions.php
<?php
/*****************************************************************/
/* Nukequiz (tm)    v 3.1.0                                		 */
/* By: Kissoftware (hide@address.com)      		     */
/* http://www.kissoftware.org.uk                           		 */
/* http://www.kissoftware.co.uk                       		     */
/* Copyright © 2003-2008 by Kissoftware         				 */
/* See Docs For Information & Credits                 			 */
/* For More information Visit Forums Or The Online Help Manual	 */
/*****************************************************************/
$pagetitle = _NQ_ADMINQUIZEXPORTINFO;
include ("header.php");
nqmenuheader();
$backupdir = $nq_config['backup_directory'];
$imagesdir = $nq_config['images_directory'];
$main_dir = "modules/$module_name/$backupdir";///Main Backup Directory for exports
$path = "$main_dir";
if (!file_exists("$main_dir")) {
$old_umask = umask(0);
mkdir("$main_dir", 0777);
}
$export_dir = "modules/$module_name/export";///temp export directory
$path = "$export_dir";
if (!file_exists("$export_dir")) {
$old_umask = umask(0);
mkdir("$export_dir", 0777);
}
$resulta = $db->sql_query("SELECT admin_email FROM ".$prefix."_nquiz_quiz WHERE qid='$qid'");
list($adminemail) = $db->sql_fetchrow($resulta);
$title = str_replace(" ", "_", $title);
$result = $db->sql_query("SELECT * FROM ".$prefix."_nquiz_questions WHERE qid='$qid'");
$image = str_replace(" ", "_" , $image);
$fp = fopen("modules/$module_name/export/$title.csv","a");
$dp = fopen("modules/$module_name/export/$title.doc","a");
if(!$fp && !$dp) {
OpenTable();
echo "<center><br><b>"._NQ_FOLDERCHECK."</b>&nbsp;:&nbsp;$title<br><br></center>";
CloseTable();
exit;
}
$count='';
$ftitle = str_replace("_", " ", $title);
fwrite($dp,"$ftitle");
while(list($quesid, $qid, $ismcq, $ismultiple, $isoe, $question, $sol1, $sol2, $sol3, $sol4, $answer, $points, $qexplain, $quesfile, $hitcount) = $db->sql_fetchrow($result))
{
$question = ucwords(strtolower($question));
$qexplain = ucwords(strtolower($qexplain));
$sol1 = ucwords(strtolower($sol1));
$sol2 = ucwords(strtolower($sol2));
$sol3 = ucwords(strtolower($sol3));
$sol4 = ucwords(strtolower($sol4));
$search  = array("'",  "<br>",  ",");
$replace = array("\'", "", "{COMMA}");
$qexplain = str_replace($search, $replace, $qexplain);
$question = str_replace($search, $replace, $question);
$sol1 = str_replace($search,$replace,$sol1);
$sol2 = str_replace($search,$replace,$sol2);
$sol3 = str_replace($search,$replace,$sol3);
$sol4 = str_replace($search,$replace,$sol4);
fwrite($fp,"$ismcq,$ismultiple,$isoe,$question,$sol1,$sol2,$sol3,$sol4,$answer,$points,$qexplain,$quesfile\n");
$imagesource_file = "modules/$module_name/$imagesdir/$quizdir/$quesfile";
$imagedestination_file = "modules/$module_name/export/$quesfile";
copy ($imagesource_file, $imagedestination_file);
$no=$no+1;
if ($quesfile =='None'){$quesfile="";}
if ($ismcq =='1'){$options = "a) $sol1. \nb) $sol2. \nc) $sol3. \nd) $sol4.";}
if ($isoe =='1'){$sol2 = $sol3 = $sol4="";}
if ($isoe =='1'){$options = "---------------------------------------------";}
if ($multiple =='1'){$sol2 = $sol3 = $sol4="";}
if ($points >'1'){$marks = $points ._NQ_MARKS;} else {$marks = $points ._NQ_MARK;}
fwrite($dp,"$quesfile\n\n$no. $question\n($marks)\n\n$options\n\n");
$count++;
}
fwrite($dp,"\n\n"._NQ_PRODUCEDBYNQ."\n\n");
fclose($fp);
fclose($dp);
include_once("NQACreateArchive.php");
$folderpath ="modules/$module_name/export/";
$name ="modules/$module_name/$backupdir/$title.zip";
$z = new PHPZip();
$z -> Zip($folderpath, $name); 
nqremoveDir("modules/$module_name/export");
OpenTable();
echo "<br><center>";
$size = filesize("modules/$module_name/$backupdir/$title.zip");
$fsize= quizfilesizepre($size); 
echo ""._NQ_QUESTIONSEXPORTED.":&nbsp;<b>$count</b><br>";
echo "<br>"._NQ_CREATEDFILE.":&nbsp;$title.csv";
echo "<br>"._NQ_CREATEDFILE.":&nbsp;$title.doc";
echo "<br><br>"._NQ_ALLFILESINCLUDED."<br><br>";
echo ""._NQ_DOWNLOAD."&nbsp;<a href='modules/$module_name/$backupdir/$title.zip'>$title</a>&nbsp;[&nbsp;$fsize&nbsp;]<br>";
echo "<br><b>$no</b>&nbsp;"._NQ_FILESCOUNT."<br></center><br>";
echo "<center>[&nbsp;<a href='".$admin_file.".php?op=nqviewquizlist'>"._NQ_OK."&nbsp;]</center><br>";
CloseTable();
$now = time();
$formatdate = $nq_config['dateformat'];
$now = date($formatdate,$now);
$emailtemplate = $nq_config['templates'];
$reply = $nq_config['reply_email'];
$subject = ""._NQ_EXPORTEDQUIZ." : $title";
$from  = "FROM:$sitename<$reply>\nContent-Type: text/html; charset=iso-8859-1";
include_once("modules/$module_name/templates/$emailtemplate/t_6.php");
mail($adminemail, $subject, $emailbody, $from);
include ('footer.php');
?>
Return current item: Nukequiz