Browse Source

[svn r17658] Logic Changes - Fixed bugs founded when you edit some survey in advanced parameters, headers' name of the table that links have wrong direction and implemented possibility to take partial survey when the user is anonymus see FS#2510

Cristian Fasanando 16 years ago
parent
commit
7717d66e6a

+ 1 - 1
main/inc/lib/sortabletable.class.php

@@ -386,7 +386,7 @@ class SortableTable extends HTML_Table
 		$param['column'] = $column;
 		if ($sortable)
 		{
-			$link = '<a href="'.api_get_self().'?';
+			$link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;';
 			foreach ($param as $key => $value)
 			{
 				$link .= $this->param_prefix.$key.'='.urlencode($value).'&amp;';

+ 22 - 40
main/survey/create_new_survey.php

@@ -25,7 +25,7 @@
 * 	@author unknown, the initial survey that did not make it in 1.8 because of bad code
 * 	@author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts (if not all) of the code
 *	@author Julio Montoya Armas <gugli100@gmail.com>, Dokeos: Personality Test modification and rewriting large parts of the code
-* 	@version $Id: create_new_survey.php 17501 2009-01-02 03:03:34Z yannoo $
+* 	@version $Id: create_new_survey.php 17658 2009-01-12 16:07:22Z cfasanando $
 *
 * 	@todo only the available platform languages should be used => need an api get_languages and and api_get_available_languages (or a parameter)
 */
@@ -178,56 +178,40 @@ $surveytypes[1] = get_lang('Conditional');
 
 
 if ($_GET['action'] == 'add')
-{
-	//$form->addElement('select', 'survey_type', get_lang('SelectType'), $surveytypes, array('onchange' => 'if(document.getElementById(\'options\').style.display == \'none\'){document.getElementById(\'options\').style.display = \'block\';}else{document.getElementById(\'options\').style.display = \'none\';}'));	
+{		
 	$form->addElement('hidden','survey_type',0);
-    $form -> addElement('html','<div id="options" style="display: none;">');
-		
+    $form -> addElement('html','<div id="options" style="display: none;">');		
 	require_once(api_get_path(LIBRARY_PATH).'surveymanager.lib.php');
-	$survey_tree = new SurveyTree();
-	
+	$survey_tree = new SurveyTree();	
 	$list_surveys = $survey_tree->createList($survey_tree->surveylist);	
 	$list_surveys[0]=''; 
 	$form->addElement('select', 'parent_id', get_lang('ParentSurvey'), $list_surveys);
 	$defaults['parent_id']=0;
+} 
 
-}
-else
-{
-	// Aditional Parameters
-	$form -> addElement('html','<div class="row">
-	<div class="label">&nbsp;</div>
-	<div class="formw">
-		<a href="javascript://" onclick="if(document.getElementById(\'options\').style.display == \'none\'){document.getElementById(\'options\').style.display = \'block\';}else{document.getElementById(\'options\').style.display = \'none\';}"><img src="../img/add_na.gif" alt="" />'.get_lang('AdvancedParameters').'</a>
-	</div>
-	</div>');
-	$form -> addElement('html','<div id="options" style="display: none;">');
-}
- 
 if ($survey_data['survey_type']==1 || $_GET['action'] == 'add' )
 {
 	$form->addElement('checkbox', 'one_question_per_page', get_lang('OneQuestionPerPage'));
 	$form->addElement('checkbox', 'shuffle', get_lang('ActivateShuffle'));
 }
 
-if ($survey_data['anonymous']==0  )
-{
-	$form->addElement('checkbox', 'show_form_profile', get_lang('ShowFormProfile'));
-}
-
-
-
+if ((isset($_GET['action']) && $_GET['action'] == 'edit') && !empty($_GET['survey_id']) )
+{	
+	if ($survey_data['anonymous']==0  ) {
+		// Aditional Parameters
+		$form -> addElement('html','<div class="row">
+		<div class="label">&nbsp;</div>
+		<div class="formw">
+			<a href="javascript://" onclick="if(document.getElementById(\'options\').style.display == \'none\'){document.getElementById(\'options\').style.display = \'block\';}else{document.getElementById(\'options\').style.display = \'none\';}"><img src="../img/add_na.gif" alt="" />'.get_lang('AdvancedParameters').'</a>
+		</div>
+		</div>');
+		$form -> addElement('html','<div id="options" style="display:none">');		
+		$form->addElement('checkbox', 'show_form_profile', get_lang('ShowFormProfile'));
 
-if ($_GET['action'] == 'edit' && is_numeric($_GET['survey_id']) )
-{
-	if ($survey_data['show_form_profile']==1 && $survey_data['anonymous']==0  )
-	{
 		$field_list=SurveyUtil::make_field_list();
 		if (is_array ($field_list))
 		{
-			//TODO hide and show the list in a fancy DIV 
-			//$form->addElement('html', '<a href=javascript>'.get_lang('ViewFields').'</a> <div id="fields"  style="display: none;" >');
-
+			//TODO hide and show the list in a fancy DIV 			
 			foreach ($field_list  as $key=> $field)
 			{
 				if ($field['visibility']==1)
@@ -252,16 +236,14 @@ if ($_GET['action'] == 'edit' && is_numeric($_GET['survey_id']) )
 					}
 				}
 			}
-			//$form->addElement('html', '</div>');
-		}	
+		}		
+		$form->addElement('html', '</div>');
 	}
+ 	
 }
-
-$form -> addElement('html','</div>');
-
+$form -> addElement('html','</div><br />');
 $form->addElement('submit', 'submit_survey', get_lang('Ok'));
 
-
 // setting the rules
 if ($_GET['action'] == 'add')
 {

+ 8 - 1
main/survey/fillsurvey.php

@@ -625,6 +625,13 @@ if (isset ($_GET['show']) || isset ($_POST['personality']))
 
 		if (key_exists($_GET['show'], $paged_questions)) {
 			if (isset($_GET['user_id'])) {
+				
+			// get the user into survey answer table (user or anonymus)
+			$sql = "SELECT user FROM $table_survey_answer 
+				WHERE survey_id = (SELECT survey_id from $table_survey WHERE code ='".$survey_invitation['survey_code']."')";
+			$result_answer = api_sql_query($sql, __FILE__, __LINE__);
+			$row_answer = Database::fetch_array($result_answer,'ASSOC');	
+				
 			$sql = "SELECT survey_question.survey_group_sec1, survey_question.survey_group_sec2, survey_question.survey_group_pri,					
 					survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.sort, survey_question.type, survey_question.max_value,
 					survey_question_option.question_option_id, survey_question_option.option_text, survey_question_option.sort as option_sort
@@ -632,7 +639,7 @@ if (isset ($_GET['show']) || isset ($_POST['personality']))
 					LEFT JOIN $table_survey_question_option survey_question_option
 					ON survey_question.question_id = survey_question_option.question_id
 					WHERE survey_question.survey_id = '" . Database :: escape_string($survey_invitation['survey_id']) . "'
-					AND survey_question.question_id NOT IN (SELECT sa.question_id FROM ".$table_survey_answer." sa WHERE sa.user=".api_get_user_id()." )
+					AND survey_question.question_id NOT IN (SELECT sa.question_id FROM ".$table_survey_answer." sa WHERE sa.user='".$row_answer['user']."')
 					ORDER BY survey_question.sort, survey_question_option.sort ASC";
 			} else {
 			

+ 13 - 7
main/survey/survey.lib.php

@@ -24,7 +24,7 @@
 *	@package dokeos.survey
 * 	@author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts (if not all) of the code
 	@author Julio Montoya Armas <gugli100@gmail.com>, Dokeos: Personality Test modification and rewriting large parts of the code
-* 	@version $Id: survey.lib.php 17530 2009-01-04 20:28:07Z yannoo $
+* 	@version $Id: survey.lib.php 17658 2009-01-12 16:07:22Z cfasanando $
 *
 * 	@todo move this file to inc/lib
 * 	@todo use consistent naming for the functions (save vs store for instance)
@@ -4633,6 +4633,11 @@ class SurveyUtil {
 		$counter = 0;
 		while ($row = Database::fetch_array($result,'ASSOC'))
 		{
+			// get the user into survey answer table (user or anonymus)
+			$sql = "SELECT user FROM $table_survey_answer 
+				WHERE survey_id = (SELECT survey_id from $table_survey WHERE code ='".$row['code']."')";
+			$result_answer = api_sql_query($sql, __FILE__, __LINE__);
+			$row_answer = Database::fetch_array($result_answer,'ASSOC');	
 			echo '<tr>';
 			if ($row['answered'] == 0)
 			{
@@ -4646,7 +4651,7 @@ class SurveyUtil {
 			echo ($row['anonymous'] == 1)?get_lang('Yes'):get_lang('No');
 			echo '</td>';
 			echo '</tr>';
-			$link_available=self::show_link_available(api_get_user_id(),$row['code']);
+			$link_available=self::show_link_available(api_get_user_id(),$row['code'],$row_answer['user']);
 			if ($link_add===true && $link_available===true) {
 				echo '<tr><td><a href="fillsurvey.php?user_id='.api_get_user_id().'&amp;course='.$_course['sysCode'].'&amp;invitationcode='.$row['invitation_code'].'&amp;cidReq='.$_course['sysCode'].'">'.get_lang('CompleteTheSurveysQuestions').'</a></td><td></td></tr>';
 			}
@@ -4897,19 +4902,20 @@ class SurveyUtil {
 	}
 		/**
 	 * @author Isaac Flores Paz <florespaz@bidsoftperu.com>
-	 * @param Integer user_id
+	 * @param int $user_id - User ID
+	 * @param int $user_id_answer - User in survey answer table (user id or anonymus)
 	 * @return boolean  
 	 *  
 	 */
-	function show_link_available($user_id,$survey_code) {
+	function show_link_available($user_id,$survey_code,$user_answer) {
 		$table_survey = Database :: get_course_table(TABLE_SURVEY);
 		$table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION);
 		$table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER);
 		$table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
 
-		$sql='SELECT COUNT(*) as count FROM '.$table_survey_invitation.' WHERE user='.$user_id.' AND survey_code="'.$survey_code.'" AND answered="1";';
-		$sql2='SELECT COUNT(*) as count FROM '.$table_survey.' s INNER JOIN '.$table_survey_question.' q ON s.survey_id=q.survey_id WHERE s.code="'.$survey_code.'";';
-		$sql3='SELECT COUNT(*) as count FROM '.$table_survey_answer.' WHERE survey_id=(SELECT survey_id FROM '.$table_survey.' WHERE code="'.$survey_code.'" AND user='.$user_id.' )';		
+		$sql='SELECT COUNT(*) as count FROM '.$table_survey_invitation.' WHERE user='.$user_id.' AND survey_code="'.$survey_code.'" AND answered="1"';
+		$sql2='SELECT COUNT(*) as count FROM '.$table_survey.' s INNER JOIN '.$table_survey_question.' q ON s.survey_id=q.survey_id WHERE s.code="'.$survey_code.'" AND q.type NOT IN("pagebreak","comment")';
+		$sql3='SELECT COUNT(*) as count FROM '.$table_survey_answer.' WHERE survey_id=(SELECT survey_id FROM '.$table_survey.' WHERE code="'.$survey_code.'") AND user="'.$user_answer.'" ';		
 		
 		$result=api_sql_query($sql,__FILE__,__LINE__);
 		$result2=api_sql_query($sql2,__FILE__,__LINE__);