Browse Source

[svn r16410] Survey - versioning implemented

Julio Montoya 16 năm trước cách đây
mục cha
commit
138e1aa4af

+ 382 - 3
main/inc/lib/surveymanager.lib.php

@@ -1900,11 +1900,390 @@ function sort_table($data, $column = 0, $direction = SORT_ASC, $type = SORT_REGU
 			$answers[] = $row;
 
 		return $answers;
-
 	}
+}
 
+/**
+ * 
+ * Manage the "versioning" of a conditional survey
+ * 
+ * */
+class SurveyTree
+{
+	var $surveylist;	 
+	var $plainsurveylist;
+	var $numbersurveys;
+	
+	/**
+	 * Sets the surveylist and the plainsurveylist
+	 */
+	function __construct()
+    {        
+        // Database table definitions
+		$table_survey 			= Database :: get_course_table(TABLE_SURVEY);
+		$table_survey_question 	= Database :: get_course_table(TABLE_SURVEY_QUESTION);
+		$table_user 			= Database :: get_main_table(TABLE_MAIN_USER);
+	
+		// searching
+		$search_restriction = SurveyUtil::survey_search_restriction();
+		if ($search_restriction)
+		{
+			$search_restriction = ' AND '.$search_restriction;
+		}
+		$sql = "SELECT survey.survey_id , survey.parent_id, survey_version, survey.code as name
+		FROM $table_survey survey 
+		LEFT JOIN  $table_survey_question  survey_question 
+		ON survey.survey_id = survey_question.survey_id , $table_user user 
+		WHERE survey.author = user.user_id 
+		GROUP BY survey.survey_id";
+		
+		$res = api_sql_query($sql, __FILE__, __LINE__);
+		$surveys_parents = array ();			
+		$refs = array();
+		$list = array();
+		$last=array();		
+		$plain_array=array();
+					
+		while ($survey = Database::fetch_array($res,'ASSOC'))
+		{
+			$plain_array[$survey['survey_id']]=$survey;
+			$surveys_parents[]=$survey['survey_version'];			
+			$thisref = &$refs[ $survey['survey_id'] ];		
+			$thisref['parent_id'] = $survey['parent_id'];
+			$thisref['name'] = $survey['name'];
+			$thisref['id'] = $survey['survey_id'];
+			$thisref['survey_version'] = $survey['survey_version'];						
+			if ($survey['parent_id'] == 0) 
+			{
+				$list[ $survey['survey_id'] ] = &$thisref;					
+			} 
+			else 
+			{
+				$refs[ $survey['parent_id'] ]['children'][ $survey['survey_id'] ] = &$thisref;				
+			}			
+		}			
+        $this->surveylist = $list;
+        $this->plainsurveylist = $plain_array;         
+    }
+    /* 
+    function read_children($space=array(),$i=0)
+	{			
+		foreach ( $this->surveylist  as $key=>$node)
+		{
+			if (is_array($node['children']))
+			{				
+				if (($node['parent_id']==0))
+				{					
+					//echo '1<br>';		
+				}
+				else
+				{
+					$space[]='2>'; 
+				}
+				
+				//if have children										
+				for ($j=0;$j<count($space);$j++)
+				{
+					//echo $space[$j]; echo 'dd<br>';
+				}
+				//echo $node['name']; echo '3<br>';
+				read_children($node['children'],$space,$i);										
+			}
+			else
+			{				
+				
+				for ($j=0;$j<count($space);$j++)
+				{
+					echo $space[$j]; echo '4<br>';
+				}				
+				echo $node['name']; echo '5<br>';
+				
+			}
+		}		
+	}
+	*/
+	/*
+	if (($key==$id))
+			{
+				echo $node['name']; echo '<br>';
+				//$node['children']=array();
+				return $node['children']; 
+			}
+			else
+			{ 
+				if (is_array($node['children']))
+				{	
+					return SurveyTree::get_children($node['children'],$id);
+				}
+				else
+				{
+					//return SurveyTree::get_children($node, $id);
+				}
+			}	
+	 */
 
-
-
+	/**
+	 * This function gets all the children of a given survey id
+	 *
+	 * @param  array the list where we are going to search the children
+	 * @param  id the id of the survey
+	 * @return array the children of a given survey id
+	 *
+	 * @author Julio Montoya <gugli100@gmail.com>, Dokeos 
+	 * @version September 2008
+	 */
+	function get_children($list,$id)
+	{			
+		$result=array();
+		foreach ($list as $key=>$node)
+		{
+			if ($key==$id)
+			{
+				$result = $node['children'];						
+				break;																							
+			}			
+			if (is_array($node['children']))
+			{		
+				//echo $key; echo '--<br>';					
+				$re=SurveyTree::get_children($node['children'],$id);
+				if (!empty($re))
+				{
+					$result=$re;
+				}																									
+			}
+			else
+			{		
+				//echo $key; echo '-<br>';				
+			}			
+		}
+		return $result;
+	}
+		
+	/**
+	 * This function gets the parent id of a survey
+	 *
+	 * @param  int survey id
+	 * @return int survey parent id
+	 *
+	 * @author Julio Montoya <gugli100@gmail.com>, Dokeos 
+	 * @version September 2008
+	 */
+	function getParentId($id)
+	{	
+		$node = $this->plainsurveylist[$id];
+		if (is_array($node)&& !empty($node['parent_id']))
+			return $node['parent_id'];
+		else
+			return -1;			
+	}
+	
+	/**
+	 * This function gets all the siblings of a given survey id
+	 *
+	 * @param  array the list where we are going to search the children
+	 * @param  id the id of the survey
+	 * @return array the children of a given survey id
+	 *
+	 * @author Julio Montoya <gugli100@gmail.com>, Dokeos 
+	 * @version September 2008
+	 */
+	function nextSibling($id)
+    {
+		$result=array();
+		$parent_id = SurveyTree::getParentId($id);			
+		$siblings  = SurveyTree::get_children($this->surveylist ,$parent_id);
+		//print_r($siblings);  
+		if (count($siblings) > 1) 
+		{			
+			// $key> $id means that the siblings are order 1 2 3 and we suppose that you can't change that order 
+			foreach ($siblings as $key=>$bro)
+			{
+				if ($key> $id && $key != $id)
+				{
+					$result[$key]=($bro);
+				}					
+			}				
+		}
+		return $result;		
+    }
+    
+	/**
+	 * 
+	 * This function shows the last sibling from a given list of surveys
+	 * @param  id of the survey
+	 * @author Julio Montoya <gugli100@gmail.com>, Dokeos 
+	 * @version September 2008
+	 * 
+	 */
+	function lastSibling($id)
+    {	
+		$result=array();
+		$parent_id = SurveyTree::getParentId($id);			
+		$siblings  = SurveyTree::get_children($this->surveylist ,$parent_id);
+		//print_r($siblings);  
+		if (count($siblings) > 1) 
+		{			
+			// $key> $id means that the siblings are order 1 2 3 and we suppose that you can't change that order
+			$i=0; 
+			foreach ($siblings as $key=>$bro)
+			{
+				if ($key> $id && $key != $id&& $i==count($siblings)-1)
+				{
+					$result[$key]=($bro);
+				}		
+				$i++;			
+			}				
+		}
+		return $result;		
+    }
+    
+    
+	/**
+	 * 
+	 * This function shows the last children of a branch 
+	 * @param  list of nodes
+	 * @return array of the lastest node
+	 * @author Julio Montoya <gugli100@gmail.com>, Dokeos 
+	 * @version September 2008
+	 * 
+	 */
+	function get_last_children_from_branch($list)
+	{	
+		$result=array();		
+		foreach ($list as $key=>$node)
+		{			 
+			//echo 'frist<br>'; echo $key;
+			//print_r($node);
+			if ($node['parent_id']!=0)
+			{				
+				$list_bros = SurveyTree::lastSibling($key);				
+				//echo '   list_bro <br>';	
+				//print_r($list_bros);
+				if (is_array($list_bros) && !empty($list_bros))					
+				{
+					foreach	($list_bros as $bro)
+					{					
+						//echo '0';						
+						if (is_array($bro['children']))
+						{
+							//print_r($bro['children']);							
+							return $result[]=SurveyTree::get_last_children_from_branch($bro['children']);
+						}
+						else
+						{	
+							//echo 'esl';		
+							$result=$bro;
+							//print_r($bro);
+							return $result;
+						}
+					}
+				}
+				else
+				{
+					//SurveyTree::get_last_children_from_branch($list_bros);
+					//echo 'sss';
+					//if if (is_array($node['children']))
+					$children = SurveyTree::get_children($node,$key);
+					//return $result[]=SurveyTree::get_last_children_from_branch($node);
+					if (is_array($node['children']))
+					{
+						return $result[]=SurveyTree::get_last_children_from_branch($node['children']);
+					}
+					else											
+					{					
+						//return $result[]=SurveyTree::get_last_children_from_branch($node['children']);					
+						return $result[]=$node;						
+					}
+		
+				}
+			}
+			else
+			{
+				//print_r($key);print_r($node['children']);
+				if (is_array($node['children']))
+				{
+					$result[]=SurveyTree::get_last_children_from_branch($node['children']);
+				}
+				else	
+				{
+					$result[]=$node;					
+				}
+			}	
+		}
+		return $result;
+	}
+	/*
+*
+	 * 
+	 * This function show the last children of list 
+	 * @param  id
+	 * @param  array 
+	 * @return array of the lastest node
+	 * @author Julio Montoya <gugli100@gmail.com>, Dokeos 
+	 * @version September 2008
+	 * 
+
+	 
+	function get_last_children($id,$last)
+	{		
+		foreach ( $this->_list as $key=>$node)
+		{
+			if (($node['parent_id']==$id))
+			{
+				$last=$node['name']; echo '<br>';				
+			}
+			else
+			{
+				if (is_array($node['children']))
+				{
+					return $last = get_last_children($node['children'],$id);	
+				}			
+			}	
+		}
+		return $last;
+	}
+	*/
+	/**
+	 * This function creates a list of all surveys id 
+	 * @param  list of nodes
+	 * @return array with the structure survey_id => survey_name 
+	 * @author Julio Montoya <gugli100@gmail.com>, Dokeos 
+	 * @version September 2008
+	 * 
+	 */
+	function createList($list)
+	{
+		$result=array();				
+		foreach ($list as $key=>$node)
+		{			
+			if (is_array($node['children']))
+			{		
+				//echo $key; echo '--<br>';
+				//print_r($node);
+				//echo '<br>';
+				$result[$key]= $node['name'];		
+				$re=SurveyTree::createList($node['children']);
+				if (!empty($re))
+				{				
+					if (is_array($re))
+						foreach ($re as $key=>$r)
+						{						
+							$result[$key]=''.$r;
+						}
+					else				
+					{
+						$result[]=$re;
+					}
+					
+				}																									
+			}
+			else
+			{		
+				//echo $key; echo '-<br>';
+				$result[$key]=$node['name'];			
+			}			
+		}			
+		return $result;
+	}	
 }
 ?>

+ 11 - 13
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 16249 2008-09-05 15:46:31Z elixir_inter $
+* 	@version $Id: create_new_survey.php 16410 2008-09-22 17:43:07Z juliomontoya $
 *
 * 	@todo only the available platform languages should be used => need an api get_languages and and api_get_available_languages (or a parameter)
 */
@@ -172,22 +172,20 @@ $form -> addElement('html','<div class="row">
 $surveytypes[0] = get_lang('Normal');
 $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('html','<div id="options" style="display: none;">');
 		
-	$sql = 'SELECT survey_id,title FROM '.$table_survey.' WHERE survey_type = 1 AND author = '.$_SESSION['_user']['user_id'];
-	$rs = api_sql_query($sql,__FILE__,__LINE__);
-	if(Database::num_rows($rs)>0)
-	{
-		$list_surveys[0] = '';
-		while($row = Database::fetch_array($rs,NUM))
-		{
-			$list_surveys[$row[0]] = $row[1];
-		}
-		$form->addElement('select', 'parent_id', get_lang('ParentSurvey'), $list_surveys);
-	}
+	require_once(api_get_path(LIBRARY_PATH).'surveymanager.lib.php');
+	$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
 {
@@ -268,7 +266,7 @@ $form->addRule('survey_title', '<div class="required">'.get_lang('ThisFieldIsReq
 $form->addRule('start_date', get_lang('InvalidDate'), 'date');
 $form->addRule('end_date', get_lang('InvalidDate'), 'date');
 $form->addRule(array ('start_date', 'end_date'), get_lang('StartDateShouldBeBeforeEndDate'), 'date_compare', 'lte');
-
+	
 // setting the default values
 $form->setDefaults($defaults);
 

+ 152 - 23
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 16401 2008-09-21 17:45:28Z elixir_inter $
+* 	@version $Id: survey.lib.php 16410 2008-09-22 17:43:07Z juliomontoya $
 *
 * 	@todo move this file to inc/lib
 * 	@todo use consistent naming for the functions (save vs store for instance)
@@ -33,7 +33,6 @@ $config['survey']['debug'] = false;
 require_once(api_get_path(LIBRARY_PATH).'usermanager.lib.php');
 class survey_manager
 {
-
 	/******************************************************************************************************
 											SURVEY FUNCTIONS
 	 *****************************************************************************************************/
@@ -205,16 +204,26 @@ class survey_manager
 							$additional['values'] .= ",'".$getversion['survey_version'].".1'";							 
 						}
 					}
-					else
-					{
-						if(strpos($row['survey_version'], '.')===false){
-							$row['survey_version'] = $row['survey_version'] + 1;
-							$additional['values'] .= ",'".$row['survey_version']."'";
-						} else {
-							$getlast= split('\.',$row['survey_version']);
+					else 
+					{	
+						$row = Database::fetch_array($rs,ASSOC);			
+						$pos = strpos($row['survey_version']);
+						if($pos===false)
+						{ 
+							//$new_version= substr($row['survey_version'],$pos, count())
+							echo $row['survey_version'] = $row['survey_version'] + 1; 
+							echo $additional['values'] .= ",'".$row['survey_version']."'";
+						} 
+						else 
+						{
+							$getlast= split('\.',$row['survey_version']);						
 							$lastversion = array_pop($getlast);
 							$lastversion = $lastversion + 1;
-							$insertnewversion = implode('.',$getlast).'.'.$lastversion;
+							$add=implode('.',$getlast);
+							if ($add!='')
+								$insertnewversion = $add.'.'.$lastversion;
+							else
+								$insertnewversion = $lastversion;
 							$additional['values'] .= ",'".$insertnewversion."'";
 						}
 					}
@@ -4241,6 +4250,38 @@ class SurveyUtil {
 	}
 	
 	
+	function display_survey_list_for_coach()
+	{
+		$parameters = array();
+		if ($_GET['do_search'])
+		{
+			$message = get_lang('DisplaySearchResults').'<br />';
+			$message .= '<a href="'.api_get_self().'">'.get_lang('DisplayAll').'</a>';
+			Display::display_normal_message($message, false);
+		}
+	
+		// Create a sortable table with survey-data
+		$table = new SortableTable('surveys', 'get_number_of_surveys_for_coach', 'get_survey_data_for_coach',2);
+		$table->set_additional_parameters($parameters);
+		$table->set_header(0, '', false);
+		$table->set_header(1, get_lang('SurveyName'));
+		$table->set_header(2, get_lang('SurveyCode'));
+		$table->set_header(3, get_lang('NumberOfQuestions'));
+		$table->set_header(4, get_lang('Author'));
+		$table->set_header(5, get_lang('Language'));
+		//$table->set_header(6, get_lang('Shared'));
+		$table->set_header(6, get_lang('AvailableFrom'));
+		$table->set_header(7, get_lang('AvailableUntill'));
+		$table->set_header(8, get_lang('Invite'));
+		$table->set_header(9, get_lang('Anonymous'));
+		$table->set_header(10, get_lang('Modify'), false,'width="120"');
+		$table->set_column_filter(9, 'anonymous_filter');
+		$table->set_column_filter(10, 'modify_filter_for_coach');	
+		$table->display();
+	}
+	
+	
+	
 	/**
 	 * This function changes the modify column of the sortable table
 	 *
@@ -4253,22 +4294,36 @@ class SurveyUtil {
 	function modify_filter($survey_id)
 	{
 		global $charset;
-		$survey_id = Security::remove_XSS($survey_id);
-		if (!api_is_course_coach(false,true))
-			$return = '<a href="create_new_survey.php?'.api_get_cidreq().'&amp;action=edit&amp;survey_id='.$survey_id.'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
-		
-		if (!api_is_course_coach(false,true))
-			$return .= '<a href="survey_list.php?'.api_get_cidreq().'&amp;action=delete&amp;survey_id='.$survey_id.'" onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang("DeleteSurvey").'?',ENT_QUOTES,$charset)).'\')) return false;">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>';
+		$survey_id = Security::remove_XSS($survey_id);		
+		$return = '<a href="create_new_survey.php?'.api_get_cidreq().'&amp;action=edit&amp;survey_id='.$survey_id.'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
+		$return .= '<a href="survey_list.php?'.api_get_cidreq().'&amp;action=delete&amp;survey_id='.$survey_id.'" onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang("DeleteSurvey").'?',ENT_QUOTES,$charset)).'\')) return false;">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>';
 		//$return .= '<a href="create_survey_in_another_language.php?id_survey='.$survey_id.'">'.Display::return_icon('copy.gif', get_lang('Copy')).'</a>';
 		//$return .= '<a href="survey.php?survey_id='.$survey_id.'">'.Display::return_icon('add.gif', get_lang('Add')).'</a>';
 		$return .= '<a href="preview.php?'.api_get_cidreq().'&amp;survey_id='.$survey_id.'">'.Display::return_icon('preview.gif', get_lang('Preview')).'</a>';
 		$return .= '<a href="survey_invite.php?'.api_get_cidreq().'&amp;survey_id='.$survey_id.'">'.Display::return_icon('survey_publish.gif', get_lang('Publish')).'</a>';
 		$return .= '<a href="survey_list.php?'.api_get_cidreq().'&amp;action=empty&amp;survey_id='.$survey_id.'" onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang("EmptySurvey").'?')).'\')) return false;">'.Display::return_icon('empty.gif', get_lang('EmptySurvey')).'</a>';
-		
-		if (!api_is_course_coach(false,true))
-			$return .= '<a href="reporting.php?'.api_get_cidreq().'&amp;survey_id='.$survey_id.'">'.Display::return_icon('statistics.gif', get_lang('Reporting')).'</a>';
+		$return .= '<a href="reporting.php?'.api_get_cidreq().'&amp;survey_id='.$survey_id.'">'.Display::return_icon('statistics.gif', get_lang('Reporting')).'</a>';
 		return $return;
 	}
+	
+	
+	function modify_filter_for_coach($survey_id)
+	{
+		global $charset;
+		$survey_id = Security::remove_XSS($survey_id);		
+	//	$return = '<a href="create_new_survey.php?'.api_get_cidreq().'&amp;action=edit&amp;survey_id='.$survey_id.'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
+		//$return .= '<a href="survey_list.php?'.api_get_cidreq().'&amp;action=delete&amp;survey_id='.$survey_id.'" onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang("DeleteSurvey").'?',ENT_QUOTES,$charset)).'\')) return false;">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>';
+		//$return .= '<a href="create_survey_in_another_language.php?id_survey='.$survey_id.'">'.Display::return_icon('copy.gif', get_lang('Copy')).'</a>';
+		//$return .= '<a href="survey.php?survey_id='.$survey_id.'">'.Display::return_icon('add.gif', get_lang('Add')).'</a>';
+		$return .= '<a href="preview.php?'.api_get_cidreq().'&amp;survey_id='.$survey_id.'">'.Display::return_icon('preview.gif', get_lang('Preview')).'</a>';
+		$return .= '<a href="survey_invite.php?'.api_get_cidreq().'&amp;survey_id='.$survey_id.'">'.Display::return_icon('survey_publish.gif', get_lang('Publish')).'</a>';
+		$return .= '<a href="survey_list.php?'.api_get_cidreq().'&amp;action=empty&amp;survey_id='.$survey_id.'" onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang("EmptySurvey").'?')).'\')) return false;">'.Display::return_icon('empty.gif', get_lang('EmptySurvey')).'</a>';
+		//$return .= '<a href="reporting.php?'.api_get_cidreq().'&amp;survey_id='.$survey_id.'">'.Display::return_icon('statistics.gif', get_lang('Reporting')).'</a>';
+		return $return;
+	}
+	
+	
+	
 	/**
 	 * Returns "yes" when given parameter is one, "no" for any other value
 	 * @param	integer	Whether anonymous or not
@@ -4342,9 +4397,31 @@ class SurveyUtil {
 		$res = api_sql_query($sql, __FILE__, __LINE__);
 		$obj = Database::fetch_object($res);
 		return $obj->total_number_of_items;
+	}
 	
+	function get_number_of_surveys_for_coach()
+	{
+		/*global $table_survey;	
+		$search_restriction = SurveyUtil::survey_search_restriction();
+		if ($search_restriction)
+		{
+			$search_restriction = 'WHERE '.$search_restriction;
+		}	
+		$sql = "SELECT count(survey_id) AS total_number_of_items FROM ".$table_survey.' '.$search_restriction;
+		$res = api_sql_query($sql, __FILE__, __LINE__);
+		$obj = Database::fetch_object($res);
+		return $obj->total_number_of_items;
+		*/
+		
+		//ugly fix	
+		require_once(api_get_path(LIBRARY_PATH).'surveymanager.lib.php');
+		$survey_tree = new SurveyTree();			
+		return count($survey_tree->get_last_children_from_branch($survey_tree->surveylist));
+		
+			
 	}
 	
+	
 	/**
 	 * This function gets all the survey data that is to be displayed in the sortable table
 	 *
@@ -4368,9 +4445,7 @@ class SurveyUtil {
 		if ($search_restriction)
 		{
 			$search_restriction = ' AND '.$search_restriction;
-		}
-		
-		$session_condition = intval($_SESSION['id_session'])==0 ? '' : ' AND survey.session_id IN(0,'.intval($_SESSION['id_session']).') '; 
+		}		
 		
 		//IF(is_shared<>0,'V','-')	 					AS col6,
 		$sql = "SELECT
@@ -4389,7 +4464,6 @@ class SurveyUtil {
 				 LEFT JOIN $table_survey_question survey_question ON survey.survey_id = survey_question.survey_id
 	             , $table_user user
 	             WHERE survey.author = user.user_id
-				$session_condition
 	             $search_restriction
 	             ";
 		$sql .= " GROUP BY survey.survey_id";
@@ -4404,6 +4478,60 @@ class SurveyUtil {
 		return $surveys;
 	}
 	
+	function get_survey_data_for_coach($from, $number_of_items, $column, $direction)
+	{
+		//echo '<pre>';		
+		//echo '----------------';
+		require_once(api_get_path(LIBRARY_PATH).'surveymanager.lib.php');
+		$survey_tree = new SurveyTree();
+		$last_version_surveys = $survey_tree->get_last_children_from_branch($survey_tree->surveylist);
+		//echo '----------------';
+		//print_r($last_version_surveys);		
+		$list=array();
+		foreach($last_version_surveys as $survey)
+		{
+			$list[]=$survey['id'];
+		}
+		$table_survey 			= Database :: get_course_table(TABLE_SURVEY);
+		$table_survey_question 	= Database :: get_course_table(TABLE_SURVEY_QUESTION);
+		$table_user 			= Database :: get_main_table(TABLE_MAIN_USER);
+
+		//print_r($survey_tree->surveylist);
+		
+		//IF(is_shared<>0,'V','-')	 					AS col6,
+		$sql = "SELECT
+					survey.survey_id							AS col0,
+	                survey.title	AS col1,
+					survey.code									AS col2,
+					count(survey_question.question_id)			AS col3,
+	                CONCAT(user.firstname, ' ', user.lastname)	AS col4,
+	                survey.lang									AS col5,	                
+					survey.avail_from							AS col6,
+	                survey.avail_till							AS col7,
+	                CONCAT('<a href=\"survey_invitation.php?view=answered&amp;survey_id=',survey.survey_id,'\">',survey.answered,'</a> / <a href=\"survey_invitation.php?view=invited&amp;survey_id=',survey.survey_id,'\">',survey.invited, '</a>')	AS col8,
+	                survey.anonymous							AS col9,
+	                survey.survey_id							AS col10
+	             FROM $table_survey survey
+				 LEFT JOIN $table_survey_question survey_question ON survey.survey_id = survey_question.survey_id
+	             , $table_user user
+	             WHERE survey.author = user.user_id AND survey.survey_id IN (".implode(',',$list).")
+	             $search_restriction
+	             ";
+		$sql .= " GROUP BY survey.survey_id";
+		$sql .= " ORDER BY col$column $direction ";
+		$sql .= " LIMIT $from,$number_of_items";
+	
+		$res = api_sql_query($sql, __FILE__, __LINE__);
+		$surveys = array ();
+		while ($survey = Database::fetch_array($res))
+		{
+			$surveys[] = $survey;
+		}
+		return $surveys;
+	}
+	
+	
+	
 	/**
 	 * Display all the active surveys for the given course user
 	 *
@@ -4699,4 +4827,5 @@ class SurveyUtil {
 		return $field_list_array;
 	}
 }
+
 ?>

+ 3 - 2
main/survey/survey.php

@@ -24,7 +24,7 @@
 *	@package dokeos.survey
 * 	@author unknown
 * 	@author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
-* 	@version $Id: survey.php 16249 2008-09-05 15:46:31Z elixir_inter $
+* 	@version $Id: survey.php 16410 2008-09-22 17:43:07Z juliomontoya $
 *
 * 	@todo use quickforms for the forms
 */
@@ -41,7 +41,8 @@ require_once('survey.lib.php');
 require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
 
 /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
-if (!api_is_allowed_to_edit(false,true))
+// coach can't view this page
+if (!api_is_allowed_to_edit(false,true) || api_is_course_coach() )
 {
 	Display :: display_header(get_lang('Survey'));
 	Display :: display_error_message(get_lang('NotAllowed'), false);

+ 29 - 6
main/survey/survey_list.php

@@ -26,7 +26,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 of the code
 *	@author Julio Montoya Armas <gugli100@gmail.com>, Dokeos: Personality Test modification and rewriting large parts of the code
-* 	@version $Id: survey_list.php 16249 2008-09-05 15:46:31Z elixir_inter $
+* 	@version $Id: survey_list.php 16410 2008-09-22 17:43:07Z juliomontoya $
 *
 * 	@todo use quickforms for the forms
 */
@@ -43,7 +43,7 @@ require_once('survey.lib.php');
 require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
 
 /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
-if (!api_is_allowed_to_edit(false,true)) //users only see a list of surveys
+if (!api_is_allowed_to_edit(false,true)) //coach can see this 
 {
 	Display :: display_header(get_lang('SurveyList'));
 	SurveyUtil::survey_list_user($_user['user_id']);
@@ -137,7 +137,7 @@ if ($_POST['action'])
 	}
 }
 
-if (api_is_allowed_to_edit(false,true))
+if (!api_is_course_coach())
 {
 	// Action links
 	echo '<a href="create_new_survey.php?'.api_get_cidreq().'&amp;action=add">'.get_lang('CreateNewSurvey').'</a> | ';
@@ -145,8 +145,11 @@ if (api_is_allowed_to_edit(false,true))
 //echo '<a href="survey_all_courses.php">'.get_lang('CreateExistingSurvey').'</a> | ';
 echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;search=advanced">'.get_lang('Search').'</a>';
 
-//Main content
-SurveyUtil::display_survey_list();
+//Load main content
+if (api_is_course_coach())
+	SurveyUtil::display_survey_list_for_coach();
+else
+	SurveyUtil::display_survey_list();
 
 // Footer
 Display :: display_footer();
@@ -164,7 +167,27 @@ function modify_filter($survey_id)
 {
 	return SurveyUtil::modify_filter($survey_id);
 }
+
+function get_number_of_surveys_for_coach()
+{
+	return SurveyUtil::get_number_of_surveys_for_coach();
+}
+function get_survey_data_for_coach($from, $number_of_items, $column, $direction)
+{
+	return SurveyUtil::get_survey_data_for_coach($from, $number_of_items, $column, $direction);
+}
+
+
+function modify_filter_for_coach($survey_id)
+{
+	return SurveyUtil::modify_filter_for_coach($survey_id);
+}
+
 function anonymous_filter($anonymous)
 {
 	return SurveyUtil::anonymous_filter($anonymous);
-}
+}
+
+
+
+