123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400 |
- <?php // $Id: index.php,v 1.44 2005/07/01 10:03:36 olivierb78 Exp $
- /*
- ==============================================================================
- Dokeos - elearning and course management software
- Copyright (c) 2004 Dokeos S.A.
- Copyright (c) 2003 University of Ghent (UGent)
- Copyright (c) 2001 Universite catholique de Louvain (UCL)
- Copyright (c) Olivier Brouckaert
- For a full list of contributors, see "credits.txt".
- The full license can be read in "license.txt".
- 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.
- See the GNU General Public License for more details.
- Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
- ==============================================================================
- */
- /**
- ==============================================================================
- * Index of the admin tools
- *
- * @package dokeos.admin
- ==============================================================================
- */
- $langFile='survey_answer';
- $cidReset=true;
- session_start();
- $lang = $_REQUEST['lang'];
- $_SESSION["user_language_choice"]=$lang;
- require_once ('../inc/global.inc.php');
- //api_protect_admin_script();
- require_once (api_get_path(LIBRARY_PATH).'/fileManage.lib.php');
- require_once (api_get_path(CONFIGURATION_PATH) ."/add_course.conf.php");
- require_once (api_get_path(LIBRARY_PATH)."/add_course.lib.inc.php");
- require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
- require (api_get_path(LIBRARY_PATH)."/groupmanager.lib.php");
- require_once (api_get_path(LIBRARY_PATH)."/surveymanager.lib.php");
- require_once (api_get_path(LIBRARY_PATH)."/usermanager.lib.php");
- if(!isset($_SESSION['page'])){
- $_SESSION['page'] = 0;
- }
- else if($_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']!=$_SERVER['HTTP_REFERER']){
- $_SESSION['page']++;
- }
- if(isset($_GET['page'])){
- $_SESSION['page'] = $_GET['page'];
- }
- $page = $_SESSION['page'];
- if(!isset($_SESSION['page'.$page])){
- $_SESSION['page'.$page] = $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
- }
- $nbQuestionsPerPage = 5;
- $db_name = stripslashes($_REQUEST['db_name']);
- $surveyid = intval($_REQUEST['surveyid']);
- $temp = stripslashes($_REQUEST['temp']);
- $uid1 = intval($_REQUEST['uid1']);
- $mail = stripslashes($_REQUEST['mail']);
- $group_offset = $group_offset_dist = empty($_REQUEST['group_offset']) ? 0 : intval($_REQUEST['group_offset']);
- $question_offset = $question_offset_dist = empty($_REQUEST['question_offset']) ? 0 : intval($_REQUEST['question_offset']);
- $indiceQuestion = $indiceQuestionDist = empty($_REQUEST['indiceQuestion']) ? 1 : intval($_REQUEST['indiceQuestion']);
- $sql = 'select * from '.$db_name.'.survey where survey_id='.$surveyid;
- $rs = api_sql_query($sql,__FILE__,__LINE__);
- $o_survey = mysql_fetch_object($rs);
- if(isset($_POST['saveandexit']) || isset($_POST['next']) || isset($_POST['finish']) || isset($_POST['printall'])){
- if(is_array($_POST['q'])){
- foreach($_POST['q'] as $question => $answer){
- if(is_array($answer)){
- $answer = implode(',',$answer);
- }
- $sql = 'SELECT 1
- FROM '.$db_name.'.survey_report
- WHERE user_id='.$uid1.'
- AND survey_id='.$surveyid.'
- AND qid='.intval($question);
-
- $rsAnswers = api_sql_query($sql,__FILE__,__LINE__);
-
- // if the answer soon exists we update it, else we insert it
- if(mysql_num_rows($rsAnswers)>0){
- $sql = 'UPDATE '.$db_name.'.survey_report
- SET answer="'.addslashes($answer).'"
- WHERE qid='.intval($question).'
- AND user_id='.$uid1.'
- AND survey_id='.$surveyid;
- }
- else {
- $sql = 'INSERT INTO '.$db_name.'.survey_report
- (id, qid, answer, survey_id, user_id) VALUES
- ("",'.intval($question).',"'.addslashes($answer).'", '.$surveyid.', '.$uid1.')';
- }
- $rs=api_sql_query($sql,__FILE__,__LINE__);
- }
- }
-
- if(isset($_POST['saveandexit'])){
- header("Location:thanks1.php?temp=$temp&surveyid=$surveyid&uid1=$uid1&db_name=$db_name&mail=$mail&lang=$lang");
- exit;
- }
-
- if(isset($_POST['finish']) || isset($_POST['printall'])){
- $survey_user_info_table = Database :: get_main_table(MAIN_SURVEY_USER_TABLE);
- $sql = 'UPDATE '.$survey_user_info_table.' SET
- attempted="yes"
- WHERE survey_id='.$surveyid.'
- AND db_name = "'.$db_name.'"
- AND email = "'.$mail.'"';
-
- $rs=api_sql_query($sql,__FILE__,__LINE__);
- if(isset($_POST['finish'])){
- header("Location:thanks1.php?temp=$temp&surveyid=$surveyid&uid1=$uid1&db_name=$db_name&mail=$mail&lang=$lang");
- exit;
- }
- }
-
- }
- $interbredcrump[] = array ("url" => "survey_list.php", "name" => get_lang('SurveyList'));
- $tool_name = $o_survey->title;
- Display::display_header($tool_name);
- api_display_tool_title("Survey Name : ".$o_survey->title);
- ob_start();
- // submit the answers
- // select the groups
- if(!isset($_POST['printall'])){
- $sql = 'SELECT DISTINCT survey_group.*
- FROM '.$db_name.'.survey_group
- INNER JOIN '.$db_name.'.questions
- ON survey_group.group_id = questions.gid
- AND questions.survey_id = survey_group.survey_id
- WHERE survey_group.survey_id='.$surveyid.'
- ORDER BY sortby ASC LIMIT '.$group_offset.',1';
- }
- else {
- $indiceQuestion = 1;
- $sql = 'SELECT DISTINCT survey_group.*
- FROM '.$db_name.'.survey_group
- INNER JOIN '.$db_name.'.questions
- ON survey_group.group_id = questions.gid
- AND questions.survey_id = survey_group.survey_id
- WHERE survey_group.survey_id='.$surveyid.'
- ORDER BY sortby ASC LIMIT 0,999';
- }
- $rsGroups = api_sql_query($sql);
- $sql = 'SELECT COUNT(DISTINCT survey_group.group_id)
- FROM '.$db_name.'.survey_group
- INNER JOIN '.$db_name.'.questions
- ON survey_group.group_id = questions.gid
- AND questions.survey_id = survey_group.survey_id
- WHERE survey_group.survey_id='.$surveyid;
- $rscount = api_sql_query($sql, __FILE__, __LINE__);
- list($nbGroups) = mysql_fetch_array($rscount);
- if(isset($_POST['printall'])){
- //display the name of the guy
- $sql = 'SELECT lastname, firstname FROM '.Database::get_main_table(MAIN_SURVEY_USER_TABLE).' WHERE user_id='.$uid1;
-
- $rsname = api_sql_query($sql, __FILE__, __LINE__);
- $user = api_store_result($rsname);
- echo '<center><strong>'.$user[0]['firstname'].' '.$user[0]['lastname'].'</strong></center><br /><br />';
- }
- echo '<table width="600" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#F6F5F5">
- <tr><td>';
- while($o_group = mysql_fetch_object($rsGroups) ){
-
- $intro = strip_tags($o_group->introduction);
- if($o_group->groupname!='No Group' && !empty($intro))
- {
- echo "<tr><td><br><table cellpadding='2' border='0' style='border: 1px solid'><tr><td align='center'>";
- echo $o_group->introduction;
- echo "</td></tr></table><br><br>";
- }
-
- $sql = 'SELECT *
- FROM '.$db_name.'.questions
- WHERE survey_id='.$surveyid.'
- AND gid='.intval($o_group->group_id).'
- ORDER BY sortby
- LIMIT '.$question_offset.',999';
-
- $rsQuestions = api_sql_query($sql);
- $nbQuestions = mysql_num_rows($rsQuestions);
- $iQuestions = 0;
- while($o_question = mysql_fetch_object($rsQuestions)){
-
-
- if(($iQuestions<$nbQuestionsPerPage || $o_group->groupname!='No Group' )|| isset($_POST['printall'])){
-
- // select the previous answer the user did
- $sql = ' SELECT answer
- FROM '.$db_name.'.survey_report
- WHERE user_id='.$uid1.' AND survey_id='.$surveyid.' AND qid='.$o_question->qid;
-
- $rsAttempt = api_sql_query($sql, __FILE__, __LINE__);
- list($answer) = mysql_fetch_array($rsAttempt);
-
-
- $o_question->caption = eregi_replace('^<p[^>]*>(.*)</p>','\\1', $o_question->caption);
- $o_question->caption = eregi_replace('(<[^ ]*) (style=."."[^>]*)(>)','\\1\\3', $o_question->caption);
- $o_question->caption = eregi_replace('(<[^ ]*) (style=.""[^>]*)(>)','\\1\\3', $o_question->caption);
- $o_question->caption = eregi_replace('(<[^ ]*)( style=."[^"]*")([^>]*)(>)','\\1\\2\\4', $o_question->caption);
-
-
- echo '<table><tr><td valign="top">'.$indiceQuestion.'- </td><td valign="top">'.stripslashes($o_question->caption).'</td></tr></table>';
-
- $sel1 = $sel2 = "";
- switch ($o_question -> qtype) {
-
- case 'Yes/No' :
- if($answer=='a1'){
- $sel1="checked";
- }
- else if($answer=='a2'){
- $sel2="checked";
- }
- echo " <input type=radio value='a1' $sel1 name='q[".$o_question->qid."]'>".$o_question->a1."
- <input type=radio value='a2' $sel2 name='q[".$o_question->qid."]'>".$o_question->a2."<BR><BR>";
- break;
-
-
-
-
- case 'Open Answer' :
- echo " <textarea cols='50' rows='6' name='q[".$o_question->qid."]'>".stripslashes($o_question->a1).
- "$answer</textarea><br><br>";
- break;
-
-
-
- case 'Multiple Choice (multiple answer)' :
- $answer = explode(',',$answer);
-
- $break = '';
- if($o_question->alignment=='vertical')
- {
- $break= "<tr>";
- }
- echo '<table cellpadding="4" cellspacing="0" align="left"><tr>';
- for($i = 1 ; $i <=10 ; $i++) {
- $current = 'a'.$i;
- $checked = '';
- if(in_array($current,$answer)){
- $checked = 'checked';
- }
- if(!empty($o_question->$current)){
- echo '<td><input value="'.$current.'" '.$checked.' type="checkbox" name="q['.$o_question->qid.'][]"></td><td align="left">'.stripslashes($o_question->$current).'</td>'.$break;
- }
- }
- echo "</tr></table><br><br>";
- break;
-
-
- case 'Multiple Choice (single answer)' :
-
- $break = '';
- if($o_question->alignment=='vertical')
- {
- $break= "<tr>";
- }
- echo '<table cellpadding="4" cellspacing="0" align="left"><tr>';
- for($i = 1 ; $i <=10 ; $i++) {
- $current = 'a'.$i;
- $checked = '';
- if($current == $answer){
- $checked = 'checked';
- }
- if(!empty($o_question->$current)){
- echo '<td align="left"><input value="'.$current.'" '.$checked.' type="radio" name="q['.$o_question->qid.']"></td><td align="left">'.stripslashes($o_question->$current).'</td>'.$break;
- }
- }
- echo "</tr></table><br><br>";
-
-
- break;
-
-
-
- case 'Numbered' :
-
- $answer = explode(',',$answer);
- echo '<table align="center">';
- for($i = 1 ; $i <=10 ; $i++) {
- $current = 'a'.$i;
- if(!empty($o_question->$current)){
- echo '<tr><td valign="top"><select name="q['.$o_question->qid.'][]">';
- for($j=0;$j<=10;$j++){
- $selected="";
- if($answer[$i-1]==$j){
- $selected="selected";
- }
- echo "<option value=$j $selected>".stripslashes($j)."</option>";
- }
- echo '</select><td valign="top"> '.$o_question->$current.'<br><br></tr></tr>';
- }
- }
- echo '</table>';
- break;
- }
-
-
- $iQuestions++;
- $indiceQuestion++;
- }
-
- }
- if($o_group->groupname!='No Group' || $nbQuestions <= $iQuestions){
- $group_offset++;
- $question_offset=0;
- }
- else {
- $question_offset += $iQuestions;
- }
- }
- echo '</td></tr></table><br /><br />';
- $content = ob_get_contents();
- ob_end_clean();
- $content = '<form method="post" action="'.$_SERVER['PHP_SELF'].'?surveyid='.$surveyid.'&db_name='.$db_name.'&temp='.$temp.'&uid1='.$uid1.'&mail='.$mail.'&group_offset='.$group_offset.'&question_offset='.$question_offset.'&indiceQuestion='.$indiceQuestion.'&cidReq='.$cidReq.'&lang='.$lang.'">'.$content;
- echo $content;
- ?>
- <table width="100%" border="0" cellpadding="0" cellspacing="0">
- <tr>
-
- <td align="center">
- <?php
- if(!isset($_POST['printall'])){
- if($_SESSION['page']==0)
- echo "<input type=\"button\" name=\"Back\" value=\"".get_lang('Back')."\" onclick=\"document.location='welcome_1.php?surveyid=".$surveyid.'&db_name='.$db_name.'&temp='.$temp.'&uid1='.$uid1.'&mail='.$mail."';\">";
- else {
- echo "<input type=\"button\" name=\"Back\" value=\"".get_lang('Back')."\" onclick=\"document.location='".$_SESSION['page'.($_SESSION['page']-1)]."&page=".($_SESSION['page']-1)."';\">";
- }
-
- if($group_offset < $nbGroups){
- echo '<input type="submit" name="saveandexit" value="'.get_lang('saveandexit').'" onclick="return confirm(\'Are you sure ?\')">';
- echo '<input type="submit" name="next" value="'.get_lang('Next').'"> ';
- }
- else {
- echo '<input type="submit" name="printall" value="'.get_lang('PrintAll').'">';
- echo '<input type="submit" name="finish" value="'.get_lang('Next').'" onclick="return confirm(\''.get_lang('AreYouSure').'\')">';
- }
- }
- else {
- echo '<script type="text/javascript">window.print()</script>';
- echo '<input type="submit" name="finish" value="'.get_lang('Finish').'" onclick="return confirm(\''.get_lang('AreYouSure').'\')">';
- }
- ?>
-
- </tr>
- </table>
- </form>
-
-
- <?php
- /*
- ==============================================================================
- FOOTER
- ==============================================================================
- */
- Display :: display_footer();
- ?>
|