ソースを参照

Merge branch '1.9.x' of github.com:chamilo/chamilo-lms into 1.9.x

Yannick Warnier 11 年 前
コミット
ad02d9fd85

+ 34 - 22
main/attendance/attendance_calendar.php

@@ -15,12 +15,12 @@ if (isset($_SESSION['gradebook'])) {
 	$param_gradebook = '&gradebook='.Security::remove_XSS($_SESSION['gradebook']);
 }
 if (!$is_locked_attendance || api_is_platform_admin()) {
-	echo '<div class="actions">';	
+	echo '<div class="actions">';
 	if ($action == 'calendar_add') {
 		echo '<a href="index.php?'.api_get_cidreq().'&action=calendar_list&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('back.png',get_lang('AttendanceCalendar'),'',ICON_SIZE_MEDIUM).'</a>';
 	} else {
 		echo '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('back.png',get_lang('AttendanceSheet'),'',ICON_SIZE_MEDIUM).'</a>';
-		
+
 		echo '<a href="index.php?'.api_get_cidreq().'&action=calendar_add&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('add.png',get_lang('AddDateAndTime'),'',ICON_SIZE_MEDIUM).'</a>';
 		echo '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDeleteAllDates').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=calendar_all_delete&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('clean.png',get_lang('CleanCalendar'),'',ICON_SIZE_MEDIUM).'</a>';
 	}
@@ -47,14 +47,21 @@ if ($error_checkdate) {
 }
 
 if (isset($action) && $action == 'calendar_add') {
-	// calendar add form		
+	// calendar add form
     $form = new FormValidator('attendance_calendar_add','POST','index.php?action=calendar_add&attendance_id='.$attendance_id.$param_gradebook.'&'.api_get_cidreq(),'');
     $form->addElement('header', get_lang('AddADateTime'));
-    $form->addElement('datepicker', 'date_time', '', array('form_name'=>'attendance_calendar_add'), 5);
+    $form->addElement('date_time_picker', 'date_time');
     $defaults['date_time'] = date('Y-m-d H:i', api_strtotime(api_get_local_time()));
 
-    $form->addElement('checkbox', 'repeat', null, get_lang('RepeatDate'),  array('onclick' => "javascript: if(this.checked){document.getElementById('repeat-date-attendance').style.display='block';}else{document.getElementById('repeat-date-attendance').style.display='none';}",
-    ));
+    $form->addElement(
+        'checkbox',
+        'repeat',
+        null,
+        get_lang('RepeatDate'),
+        array(
+            'onclick' => "javascript: if(this.checked){document.getElementById('repeat-date-attendance').style.display='block';}else{document.getElementById('repeat-date-attendance').style.display='none';}",
+        )
+    );
 
     $defaults['repeat'] = $repeat;
 
@@ -62,36 +69,41 @@ if (isset($action) && $action == 'calendar_add') {
         $form->addElement('html', '<div id="repeat-date-attendance" style="display:block">');
     } else {
         $form->addElement('html', '<div id="repeat-date-attendance" style="display:none">');
-    }        
-    $a_repeat_type = array('daily'=>get_lang('RepeatDaily'), 'weekly'=>get_lang('RepeatWeekly'), 'monthlyByDate'=>get_lang('RepeatMonthlyByDate'));        
+    }
+    $a_repeat_type = array(
+        'daily' => get_lang('RepeatDaily'),
+        'weekly' => get_lang('RepeatWeekly'),
+        'monthlyByDate' => get_lang('RepeatMonthlyByDate')
+    );
     $form->addElement('select', 'repeat_type', get_lang('RepeatType') , $a_repeat_type);
-    $form->addElement('datepickerdate', 'end_date_time', get_lang('RepeatEnd'), array('form_name'=>'attendance_calendar_add'));
-    $defaults['end_date_time'] = date('Y-m-d 12:00:00');        
+
+    $form->addElement('date_picker', 'end_date_time', get_lang('RepeatEnd'), array('form_name'=>'attendance_calendar_add'));
+    $defaults['end_date_time'] = date('Y-m-d');
     $form->addElement('html', '</div>');
 
     $defaults['repeat_type'] = 'weekly';
 
     $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
     $form->setDefaults($defaults);
-    $form->display();	
+    $form->display();
 } else {
 	// calendar list
     echo Display::page_subheader(get_lang('CalendarList'));
-	echo '<div class="attendance-calendar-list">';	
+	echo '<div class="attendance-calendar-list">';
 	if (!empty($attendance_calendar)) {
-		foreach ($attendance_calendar as $calendar) {	
-			echo '<div class="attendance-calendar-row">';				
+		foreach ($attendance_calendar as $calendar) {
+			echo '<div class="attendance-calendar-row">';
 				if ((isset($action) && $action == 'calendar_edit') && (isset($calendar_id) && $calendar_id == $calendar['id'])) {
-					// calendar edit form				
-					echo '<div class="attendance-calendar-edit">';				
-						$form = new FormValidator('attendance_calendar_edit','POST','index.php?action=calendar_edit&attendance_id='.$attendance_id.'&calendar_id='.$calendar_id.'&'.api_get_cidreq().$param_gradebook,'');					
-						$form->addElement('datepicker', 'date_time', '', array('form_name'=>'attendance_calendar_edit'), 5);
+					// calendar edit form
+					echo '<div class="attendance-calendar-edit">';
+						$form = new FormValidator('attendance_calendar_edit','POST','index.php?action=calendar_edit&attendance_id='.$attendance_id.'&calendar_id='.$calendar_id.'&'.api_get_cidreq().$param_gradebook,'');
+						$form->addElement('date_time_picker', 'date_time', '', array('form_name'=>'attendance_calendar_edit'), 5);
 						$defaults['date_time'] = $calendar['date_time'];
 						$form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
 						$form->addElement('style_submit_button', 'cancel', get_lang('Cancel'), 'class="cancel"');
 						$form->setDefaults($defaults);
 						$form->display();
-					echo '</div>';						
+					echo '</div>';
 				} else {
 					echo Display::return_icon('lp_calendar_event.png', get_lang('DateTime')).' '.substr($calendar['date_time'], 0, strlen($calendar['date_time'])- 3) .'&nbsp;';
 					if (!$is_locked_attendance || api_is_platform_admin()) {
@@ -100,11 +112,11 @@ if (isset($action) && $action == 'calendar_add') {
                         echo '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index.php?'.api_get_cidreq().$param_gradebook.'&action=calendar_delete&calendar_id='.intval($calendar['id']).'&attendance_id='.$attendance_id.'">'.Display::return_icon('delete.png', get_lang('Delete'), array('style'=>'vertical-align:middle'), ICON_SIZE_SMALL).'</a>';
                         echo '</span>';
                     }
-				}	
+				}
 			echo '</div>';
 		}
 	} else {
 		echo Display::return_message(get_lang('ThereAreNoRegisteredDatetimeYet'), 'warning');
 	}
-	echo '</div>';			
-}
+	echo '</div>';
+}

+ 13 - 12
main/attendance/attendance_controller.php

@@ -316,20 +316,21 @@
 				if (!isset($_POST['cancel'])) {
                     if (isset($_POST['repeat'])) {
                         //@todo  check this error_logs
-                        $start_datetime = api_strtotime(api_get_utc_datetime($attendance->build_datetime_from_array($_POST['date_time'])),'UTC');
-                        //error_log('$start_datetime '.$start_datetime);
+                        $start_datetime = api_strtotime(
+                            api_get_utc_datetime($_POST['date_time']), 'UTC'
+                        );
 
-                        $_POST['end_date_time']['H'] = $_POST['date_time']['H'];
-                        $_POST['end_date_time']['i'] = $_POST['date_time']['i'];
-                        //error_log($attendance->build_datetime_from_array($_POST['end_date_time']));
-
-                        $end_datetime = api_strtotime(api_get_utc_datetime($attendance->build_datetime_from_array($_POST['end_date_time'])),'UTC');
-                        //error_log('$end_datetime '.$end_datetime);
-                        $checkdate = checkdate($_POST['end_date_time']['F'], $_POST['end_date_time']['d'], $_POST['end_date_time']['Y']);
+                        $end_datetime = api_strtotime(api_get_utc_datetime($_POST['end_date_time'].' 23:59:59'), 'UTC');
+                        $checkdate = api_is_valid_date(api_get_utc_datetime($_POST['end_date_time'].' 23:59:59'));
 
                         $repeat_type = $_POST['repeat_type'];
                         if (($end_datetime > $start_datetime) && $checkdate) {
-                            $affected_rows = $attendance->attendance_repeat_calendar_add($attendance_id, $start_datetime, $end_datetime, $repeat_type);
+                            $affected_rows = $attendance->attendance_repeat_calendar_add(
+                                $attendance_id,
+                                $start_datetime,
+                                $end_datetime,
+                                $repeat_type
+                            );
                             $action = 'calendar_list';
                         } else {
                             if (!$checkdate) {
@@ -341,7 +342,7 @@
                             $action = 'calendar_add';
                         }
                     } else {
-                        $datetime = $attendance->build_datetime_from_array($_POST['date_time']);
+                        $datetime = $_POST['date_time'];
                         $datetimezone = api_get_utc_datetime($datetime);
                         if (!empty($datetime)) {
 	                       $attendance->set_date_time($datetimezone);
@@ -545,4 +546,4 @@
         Export::export_html_to_pdf($content, $params);
         exit;
     }
-}
+}

+ 4 - 5
main/attendance/attendance_edit.php

@@ -7,7 +7,6 @@
 * @package chamilo.attendance
 */
 
-
 // protect a course script
 api_protect_course_script(true);
 
@@ -41,15 +40,15 @@ $form->add_html_editor('description', get_lang('Description'), false, false, arr
 if (Gradebook::is_active()) {
     if (!empty($attendance_qualify_title) || !empty($attendance_weight)) {
         $advanced = '<a href="javascript://" class="advanced_parameters"><span id="img_plus_and_minus">&nbsp;'.Display::return_icon('div_hide.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).' '.get_lang('AdvancedParameters').'</span></a>';
-        $form->addElement('advanced_settings',$advanced);    
-    
-	$form->addElement('html','<div id="id_qualify" style="display:block">');    
+        $form->addElement('advanced_settings',$advanced);
+
+	$form->addElement('html','<div id="id_qualify" style="display:block">');
 	$form->addElement('checkbox', 'attendance_qualify_gradebook', '', get_lang('QualifyAttendanceGradebook'),array('checked'=>'true','onclick'=>'javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}'));
 	$form->addElement('html','<div id="options_field" style="display:block">');
     } else {
 	$advanced = '<a href="javascript://" class="advanced_parameters"><span id="img_plus_and_minus">&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).' '.get_lang('AdvancedParameters').'</span></a>';
         $form->addElement('advanced_settings',$advanced);
-	$form->addElement('html','<div id="id_qualify" style="display:none">');    
+	$form->addElement('html','<div id="id_qualify" style="display:none">');
 	$form->addElement('checkbox', 'attendance_qualify_gradebook', '', get_lang('QualifyAttendanceGradebook'),'onclick="javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}"');
 	$form->addElement('html','<div id="options_field" style="display:none">');
     }

+ 2 - 2
main/inc/lib/course.lib.php

@@ -4255,9 +4255,9 @@ class CourseManager
 
     /**
      * @deprecated seems not to be used
-     * @return ResultSet
      */
-    static function list_inactive_courses($ceiling, $visibility_level = COURSE_VISIBILITY_REGISTERED) {
+    static function list_inactive_courses($ceiling, $visibility_level = COURSE_VISIBILITY_REGISTERED)
+    {
         $ceiling = is_numeric($ceiling) ? (int) $ceiling : strtotime($ceiling);
         $ceiling = date('Y-m-d H:i:s', $ceiling);
         $visibility_level = $visibility_level ? $visibility_level : '0';

+ 0 - 4
main/inc/lib/formvalidator/Element/DateRangePicker.php

@@ -98,7 +98,6 @@ class DateRangePicker extends HTML_QuickForm_text
      */
     function validateDates($dates)
     {
-
         if (empty($dates['start']) || empty($dates['end'])) {
             return false;
         }
@@ -115,7 +114,4 @@ class DateRangePicker extends HTML_QuickForm_text
 
         return true;
     }
-
-
-
 }

+ 1 - 0
main/inc/lib/formvalidator/Element/datepickerdate.php

@@ -8,6 +8,7 @@ class HTML_QuickForm_datepickerdate extends HTML_QuickForm_date
 {
 	/**
 	 * Constructor
+     * @deprecated use class DatePicker
 	 */
 	public function HTML_QuickForm_datepickerdate($elementName = null, $elementLabel = null, $attributes = null)
     {

+ 4 - 0
main/inc/lib/formvalidator/FormValidator.class.php

@@ -384,6 +384,7 @@ EOT;
      * A rule is added to check if the date is a valid one
      * @param string $label						The label for the form-element
      * @param string $name						The element name
+     * @deprecated
      */
     function add_datepicker($name, $label)
     {
@@ -397,6 +398,7 @@ EOT;
      * A rule is added to check if the date is a valid one
      * @param string $label						The label for the form-element
      * @param string $name						The element name
+     * @deprecated
      */
     function add_datepickerdate($name, $label)
     {
@@ -411,6 +413,7 @@ EOT;
      * before the second one.
      * @param string $label						The label for the form-element
      * @param string $name						The element name
+     * @deprecated
      */
     function add_timewindow($name_1, $name_2, $label_1, $label_2)
     {
@@ -421,6 +424,7 @@ EOT;
 
     /**
      * Adds a button to the form to add resources.
+     * @deprecated
      */
     function add_resource_button()
     {

+ 11 - 28
main/inc/lib/formvalidator/Rule/Date.php

@@ -1,40 +1,23 @@
 <?php
-// $Id: Date.php 6187 2005-09-07 10:23:57Z bmol $
-/*
-==============================================================================
-	Dokeos - elearning and course management software
+/* For licensing terms, see /license.txt */
+/** @author Bart Mollet, Julio Montoya */
+require_once 'HTML/QuickForm/Rule.php';
 
-	Copyright (c) 2004-2005 Dokeos S.A.
-	Copyright (c) Bart Mollet, Hogeschool Gent
-
-	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 address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
-	Mail: info@dokeos.com
-==============================================================================
-*/
-require_once ('HTML/QuickForm/Rule.php');
 /**
- * QuickForm rule to check a date
+ * Class HTML_QuickForm_Rule_Date
  */
 class HTML_QuickForm_Rule_Date extends HTML_QuickForm_Rule
 {
 	/**
-	 * Function to check a date
+	 * Check a date
 	 * @see HTML_QuickForm_Rule
-	 * @param array $date An array with keys F (month), d (day) and Y (year)
+	 * @param string $date example 2014-04-30
+     * @param array $options
+     *
 	 * @return boolean True if date is valid
 	 */
-	function validate($date, $options)
+	public function validate($date, $options)
 	{
-		return checkdate($date['F'], $date['d'], $date['Y']);
+        return api_is_valid_date($date, 'Y-m-d');
 	}
-}
+}

+ 8 - 33
main/inc/lib/formvalidator/Rule/DateCompare.php

@@ -1,46 +1,21 @@
 <?php
-// $Id: DateCompare.php 6187 2005-09-07 10:23:57Z bmol $
-/*
-==============================================================================
-	Dokeos - elearning and course management software
-
-	Copyright (c) 2004-2005 Dokeos S.A.
-	Copyright (c) Bart Mollet, Hogeschool Gent
-
-	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 address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
-	Mail: info@dokeos.com
-==============================================================================
-*/
+/* For licensing terms, see /license.txt */
+/** @author Bart Mollet, Julio Montoya */
 require_once 'HTML/QuickForm/Rule/Compare.php';
 /**
- * QuickForm rule to compare 2 dates
+ * Class HTML_QuickForm_Rule_DateCompare
  */
 class HTML_QuickForm_Rule_DateCompare extends HTML_QuickForm_Rule_Compare
 {
     /**
      * Validate 2 dates
-     * @param array $values Array with the 2 dates. Each element in this array
-     * should be an array width keys  F (month), d (day) and Y (year)
-     * @param string $operator The operator to use (default '==')
-     * @return boolean True if the 2 given dates match the operator
+     * @param array $values Array with the 2 dates.
+     * @param $operator
+     *
+     * @return boolean true if the 2 given dates match the operator
      */
     function validate($values, $operator = null)
     {
-    	$date1 = $values[0];
-    	$date2 = $values[1];
-        $time1 = mktime($date1['H'],$date1['i'],0,$date1['F'],$date1['d'],$date1['Y']);
-        $time2 = mktime($date2['H'],$date2['i'],0,$date2['F'],$date2['d'],$date2['Y']);
-		return parent::validate(array($time1,$time2),$operator);
+        return api_strtotime($values[0]) < api_strtotime($values[1]);
     }
 }
-?>

+ 33 - 23
main/inc/lib/gradebook.lib.php

@@ -1,26 +1,24 @@
 <?php
 /* For licensing terms, see /license.txt */
 /**
-*   This class provides methods for the notebook management.
-*   Include/require it in your code to use its features.
-*   @package chamilo.library
-*/
+ *   This class provides methods for the notebook management.
+ *   Include/require it in your code to use its features.
+ *   @package chamilo.library
+ */
 /**
  * Code
  */
-
-class Gradebook extends Model {
-
+class Gradebook extends Model
+{
     public $columns = array('id', 'name', 'description', 'course_code', 'parent_id', 'grade_model_id', 'session_id', 'weight', 'user_id');
 
-
-    public function __construct() {
+    public function __construct()
+    {
         $this->table                        = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
         $this->table_skill                  = Database::get_main_table(TABLE_MAIN_SKILL);
         $this->table_skill_rel_gradebook    = Database::get_main_table(TABLE_MAIN_SKILL_REL_GRADEBOOK);
     }
 
-
     /**
      * Returns true if the gradebook is active and visible in a course, false
      * otherwise.
@@ -32,8 +30,10 @@ class Gradebook extends Model {
     {
         $name = 'gradebook';
         $table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
-        $sql = "SELECT * from $table WHERE variable='course_hide_tools' AND subkey='$name'";
-        $setting = ResultSet::create($sql)->first();
+        $sql = "SELECT * from $table WHERE variable='course_hide_tools' AND subkey='$name' LIMIT 1";
+        $result = Database::query($sql);
+        $setting = Database::store_result($result);
+        $setting = isset($setting[0]) ? $setting[0] : null;
         $setting = $setting ? $setting : array();
         $inactive = isset($setting['selected_value']) && $setting['selected_value'] == 'true';
 
@@ -43,17 +43,20 @@ class Gradebook extends Model {
 
         $c_id = $c_id ? intval($c_id) : api_get_course_int_id();
         $table  = Database::get_course_table(TABLE_TOOL_LIST);
-        $sql = "SELECT * from $table WHERE c_id = $c_id and name='$name'";
-        $item = ResultSet::create($sql)->first();
+        $sql = "SELECT * from $table WHERE c_id = $c_id and name='$name' LIMIT 1";
+        $result = Database::query($sql);
+        $item = Database::store_result($result, 'ASSOC');
+        $item = isset($item[0]) ? $item[0] : null;
         if (empty($item)) {
             return true;
         }
         return $item['visibility'] == '1';
     }
 
-    public function get_all($options = array()) {
+    public function get_all($options = array())
+    {
         $gradebooks = parent::get_all($options);
-        foreach($gradebooks as &$gradebook) {
+        foreach ($gradebooks as &$gradebook) {
             if (empty($gradebook['name'])) {
                 $gradebook['name'] = $gradebook['course_code'];
             }
@@ -62,11 +65,13 @@ class Gradebook extends Model {
         return $gradebooks;
     }
 
-    public function update($params) {
+    public function update($params)
+    {
         return parent::update($params);
     }
 
-    public function update_skills_to_gradebook($gradebook_id, $skill_list) {
+    public function update_skills_to_gradebook($gradebook_id, $skill_list)
+    {
 
         if (!empty($skill_list)) {
 
@@ -112,8 +117,8 @@ class Gradebook extends Model {
      * @param   string  action add, edit
      * @return  obj     form validator obj
      */
-    public function show_skill_form($gradebook_id, $url, $header = null) {
-
+    public function show_skill_form($gradebook_id, $url, $header = null)
+    {
         $form = new FormValidator('gradebook_add_skill', 'POST', $url);
         // Setting the form elements
         if (!isset($header)) {
@@ -145,7 +150,12 @@ class Gradebook extends Model {
         return $form;
     }
 
-    function get_skills_by_gradebook($gradebook_id) {
+    /**
+     * @param int $gradebook_id
+     * @return array|resource
+     */
+    function get_skills_by_gradebook($gradebook_id)
+    {
         $gradebook_id = intval($gradebook_id);
         $sql = "SELECT skill.id, skill.name FROM {$this->table_skill} skill INNER JOIN {$this->table_skill_rel_gradebook} skill_rel_gradebook
                     ON skill.id = skill_rel_gradebook.skill_id
@@ -155,11 +165,11 @@ class Gradebook extends Model {
         return $result;
     }
 
-
     /**
      * Displays the title + grid
      */
-    public function display() {
+    public function display()
+    {
         // action links
         echo Display::grid_html('gradebooks');
     }

+ 1 - 0
main/inc/lib/groupmanager.lib.php

@@ -340,6 +340,7 @@ class GroupManager
     /**
      * Create a group for every class subscribed to the current course
      * @param int $category_id The category in which the groups should be created
+     * @return array
      */
     public static function create_class_groups($category_id)
     {

+ 1 - 0
main/inc/lib/result_set.class.php

@@ -5,6 +5,7 @@
  *
  * @license see /license.txt
  * @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
+ * @deprecated
  */
 class ResultSet implements Countable, Iterator
 {

+ 37 - 43
main/inc/lib/surveymanager.lib.php

@@ -12,7 +12,8 @@
  * Manage the "versioning" of a conditional survey
  * @package chamilo.survey
  * */
-class SurveyTree {
+class SurveyTree
+{
 	public $surveylist;
 	public $plainsurveylist;
 	public $numbersurveys;
@@ -20,7 +21,8 @@ class SurveyTree {
 	/**
 	 * Sets the surveylist and the plainsurveylist
 	 */
-	public function __construct() {
+	public function __construct()
+    {
         // Database table definitions
 		$table_survey 			= Database :: get_course_table(TABLE_SURVEY);
 		$table_survey_question 	= Database :: get_course_table(TABLE_SURVEY_QUESTION);
@@ -31,16 +33,15 @@ class SurveyTree {
 		if ($search_restriction) {
 			$search_restriction = ' AND '.$search_restriction;
 		}
-		
 		$course_id = api_get_course_int_id();
-		
-
-		$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
+		$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.c_id 			=  $course_id AND 
-					survey_question.c_id 	=  $course_id AND 
+					survey.c_id 			=  $course_id AND
+					survey_question.c_id 	=  $course_id AND
 					survey.author 			= user.user_id
 				GROUP BY survey.survey_id";
 
@@ -48,11 +49,10 @@ class SurveyTree {
 		$surveys_parents = array ();
 		$refs = array();
 		$list = array();
-		$last=array();
+		$last = array();
 		$plain_array=array();
 
-		while ($survey = Database::fetch_array($res,'ASSOC'))
-		{
+		while ($survey = Database::fetch_array($res,'ASSOC')) {
 			$plain_array[$survey['survey_id']]=$survey;
 			$surveys_parents[]=$survey['survey_version'];
 			$thisref = &$refs[ $survey['survey_id'] ];
@@ -60,18 +60,16 @@ class SurveyTree {
 			$thisref['name'] = $survey['name'];
 			$thisref['id'] = $survey['survey_id'];
 			$thisref['survey_version'] = $survey['survey_version'];
-			if ($survey['parent_id'] == 0)
-			{
+			if ($survey['parent_id'] == 0) {
 				$list[ $survey['survey_id'] ] = &$thisref;
-			}
-			else
-			{
+			} else {
 				$refs[ $survey['parent_id'] ]['children'][ $survey['survey_id'] ] = &$thisref;
 			}
 		}
         $this->surveylist = $list;
         $this->plainsurveylist = $plain_array;
     }
+
 	/**
 	 * This function gets the parent id of a survey
 	 *
@@ -81,53 +79,49 @@ class SurveyTree {
 	 * @author Julio Montoya <gugli100@gmail.com>, Dokeos
 	 * @version September 2008
 	 */
-	public function getParentId ($id) {
+	public function getParentId($id)
+    {
 		$node = $this->plainsurveylist[$id];
-		if (is_array($node)&& !empty($node['parent_id']))
+		if (is_array($node)&& !empty($node['parent_id'])) {
 			return $node['parent_id'];
-		else
+        } else {
 			return -1;
+        }
 	}
+
 	/**
 	 * 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
+	 * @author Julio Montoya <gugli100@gmail.com>
 	 * @version September 2008
-	 *
 	 */
-	public function createList ($list) {
-		$result=array();
-		if(is_array($list)) {
+	public function createList ($list)
+    {
+		$result = array();
+		if (is_array($list)) {
 			foreach ($list as $key=>$node) {
-				if (is_array($node['children']))
-				{
+				if (isset($node['children']) && is_array($node['children'])) {
 					//echo $key; echo '--<br>';
 					//print_r($node);
 					//echo '<br>';
 					$result[$key]= $node['name'];
-					$re=self::createList($node['children']);
-					if (!empty($re))
-					{
-						if (is_array($re))
-							foreach ($re as $key=>$r)
-							{
-								$result[$key]=''.$r;
-							}
-						else
-						{
+					$re = self::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>';
+				} else {
 					$result[$key]=$node['name'];
 				}
 			}
 		}
+
 		return $result;
 	}
-}
+}

+ 4 - 4
main/inc/lib/usermanager.lib.php

@@ -4205,8 +4205,8 @@ class UserManager
                     }
                     break;
                 case self::USER_FIELD_TYPE_DATE:
-                    $form->addElement('datepickerdate', 'extra_'.$field_details[1], $field_details[3], array('form_name' => $form_name));
-                    $form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear', 1900);
+                    $form->addElement('date_picker', 'extra_'.$field_details[1], $field_details[3]);
+                    //$form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear', 1900);
                     $defaults['extra_'.$field_details[1]] = date('Y-m-d 12:00:00');
                     $form->setDefaults($defaults);
                     if (!$admin_permissions) {
@@ -4216,8 +4216,8 @@ class UserManager
                     $form->applyFilter('theme', 'trim');
                     break;
                 case self::USER_FIELD_TYPE_DATETIME:
-                    $form->addElement('datepicker', 'extra_'.$field_details[1], $field_details[3], array('form_name' => $form_name));
-                    $form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear', 1900);
+                    $form->addElement('date_time_picker', 'extra_'.$field_details[1], $field_details[3]);
+                    //$form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear', 1900);
                     $defaults['extra_'.$field_details[1]] = date('Y-m-d 12:00:00');
                     $form->setDefaults($defaults);
                     if (!$admin_permissions) {

+ 54 - 45
main/survey/create_new_survey.php

@@ -1,5 +1,4 @@
 <?php
-
 /* For licensing terms, see /license.txt */
 
 /**
@@ -27,24 +26,25 @@ require_once 'survey.lib.php';
 require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
 require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
 
-$htmlHeadXtra[] = '<script type="text/javascript">
-		function advanced_parameters() {
-			if(document.getElementById(\'options\').style.display == \'none\') {
-					document.getElementById(\'options\').style.display = \'block\';
-					document.getElementById(\'plus_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_hide.gif', get_lang('Hide'), array('style' => 'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
-			} else {
-					document.getElementById(\'options\').style.display = \'none\';
-					document.getElementById(\'plus_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_show.gif', get_lang('Show'), array('style' => 'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
-			}
-		}
-
-		function setFocus(){
-		  $("#surveycode_title").focus();
-		}
-		$(document).ready(function () {
-		  setFocus();
-		});
-	</script>';
+$htmlHeadXtra[] = '<script>
+    function advanced_parameters() {
+        if (document.getElementById(\'options\').style.display == \'none\') {
+            document.getElementById(\'options\').style.display = \'block\';
+            document.getElementById(\'plus_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_hide.gif', get_lang('Hide'), array('style' => 'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
+        } else {
+            document.getElementById(\'options\').style.display = \'none\';
+            document.getElementById(\'plus_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_show.gif', get_lang('Show'), array('style' => 'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
+        }
+    }
+
+    function setFocus(){
+        $("#surveycode_title").focus();
+    }
+
+    $(document).ready(function () {
+      setFocus();
+    });
+</script>';
 
 // Database table definitions
 $table_survey = Database :: get_course_table(TABLE_SURVEY);
@@ -55,39 +55,45 @@ $table_gradebook_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
 /** @todo this has to be moved to a more appropriate place (after the display_header of the code) */
 // If user is not teacher or if he's a coach trying to access an element out of his session
 if (!api_is_allowed_to_edit()) {
-    if (!api_is_course_coach() || (!empty($_GET['survey_id']) && !api_is_element_in_the_session(TOOL_SURVEY, intval($_GET['survey_id'])))) {
+    if (!api_is_course_coach() ||
+        (!empty($_GET['survey_id']) &&
+        !api_is_element_in_the_session(TOOL_SURVEY, $_GET['survey_id']))
+    ) {
         api_not_allowed(true);
         exit;
     }
 }
 
 // Getting the survey information
-$survey_id = Security::remove_XSS($_GET['survey_id']);
+$survey_id = isset($_GET['survey_id']) ? intval($_GET['survey_id']) : null;
 $survey_data = survey_manager::get_survey($survey_id);
 
 // Additional information
 $course_id = api_get_course_id();
 $session_id = api_get_session_id();
-$gradebook_link_type = 8; // LINK_SURVEY
-
-/* $urlname = strip_tags(api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40));
-  if (api_strlen(strip_tags($survey_data['title'])) > 40) {
-  $urlname .= '...';
-  } */
-$urlname = $survey_data['title'];
-
+$gradebook_link_type = 8;
+$urlname = isset($survey_data['title']) ? strip_tags($survey_data['title']) : null;
 
 // Breadcrumbs
 if ($_GET['action'] == 'add') {
-    $interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
+    $interbreadcrumb[] = array(
+        'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(),
+        'name' => get_lang('SurveyList')
+    );
     $tool_name = get_lang('CreateNewSurvey');
 }
 if ($_GET['action'] == 'edit' && is_numeric($survey_id)) {
-    $interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
-    $interbreadcrumb[] = array('url' => 'survey.php?survey_id='.$survey_id, 'name' => strip_tags($urlname));
+    $interbreadcrumb[] = array(
+        'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(),
+        'name' => get_lang('SurveyList')
+    );
+    $interbreadcrumb[] = array(
+        'url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&'.api_get_cidreq(),
+        'name' => Security::remove_XSS($urlname)
+    );
     $tool_name = get_lang('EditSurvey');
 }
-
+$gradebook_link_id = null;
 // Getting the default values
 if ($_GET['action'] == 'edit' && isset($survey_id) && is_numeric($survey_id)) {
     $defaults = $survey_data;
@@ -105,9 +111,9 @@ if ($_GET['action'] == 'edit' && isset($survey_id) && is_numeric($survey_id)) {
     }
 } else {
     $defaults['survey_language'] = $_course['language'];
-    $defaults['start_date'] = date('d-F-Y H:i');
+    $defaults['start_date'] = date('Y-m-d', api_strtotime(api_get_local_time()));
     $startdateandxdays = time() + 864000; // today + 10 days
-    $defaults['end_date'] = date('d-F-Y H:i', $startdateandxdays);
+    $defaults['end_date'] = date('Y-m-d', $startdateandxdays);
     //$defaults['survey_share']['survey_share'] = 0;
     //$form_share_value = 1;
     $defaults['anonymous'] = 0;
@@ -124,7 +130,6 @@ if ($_GET['action'] == 'edit' && isset($survey_id) && is_numeric($survey_id)) {
 }
 
 $survey_code = $form->addElement('text', 'survey_code', get_lang('SurveyCode'), array('size' => '20', 'maxlength' => '20', 'id' => 'surveycode_title'));
-//$form->applyFilter('survey_code', 'html_filter');
 
 if ($_GET['action'] == 'edit') {
     $survey_code->freeze();
@@ -146,8 +151,8 @@ $form->addElement('html_editor', 'survey_subtitle', get_lang('SurveySubTitle'),
 
 // Pass the language of the survey in the form
 $form->addElement('hidden', 'survey_language');
-$form->addElement('datepickerdate', 'start_date', get_lang('StartDate'), array('form_name' => 'survey'));
-$form->addElement('datepickerdate', 'end_date', get_lang('EndDate'), array('form_name' => 'survey'));
+$form->addElement('date_picker', 'start_date', get_lang('StartDate'));
+$form->addElement('date_picker', 'end_date', get_lang('EndDate'));
 
 //$group = '';
 //$group[] =& HTML_QuickForm::createElement('radio', 'survey_share', null, get_lang('Yes'), $form_share_value);
@@ -159,8 +164,12 @@ $form->addElement('html_editor', 'survey_introduction', get_lang('SurveyIntroduc
 $form->addElement('html_editor', 'survey_thanks', get_lang('SurveyThanks'), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '130', 'ToolbarStartExpanded' => false));
 
 // Aditional Parameters
-$form->addElement('advanced_settings', '<a href="javascript: void(0);" onclick="javascript: advanced_parameters();" >
-        <span id="plus_minus">&nbsp;'.Display::return_icon('div_show.gif', null, array('style' => 'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'</span></a>');
+$form->addElement(
+    'advanced_settings',
+    '<a href="javascript: void(0);" onclick="javascript: advanced_parameters();">
+        <span id="plus_minus">&nbsp;'.
+        Display::return_icon('div_show.gif', null, array('style' => 'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'</span></a>'
+);
 
 $form->addElement('html', '<div id="options" style="display: none;">');
 
@@ -187,14 +196,13 @@ if ($_GET['action'] == 'add') {
     $defaults['parent_id'] = 0;
 }
 
-if ($survey_data['survey_type'] == 1 || $_GET['action'] == 'add') {
+if (isset($survey_data['survey_type']) && $survey_data['survey_type'] == 1 || $_GET['action'] == 'add') {
     $form->addElement('checkbox', 'one_question_per_page', null, get_lang('OneQuestionPerPage'));
     $form->addElement('checkbox', 'shuffle', null, get_lang('ActivateShuffle'));
 }
-
+$input_name_list = null;
 if ((isset($_GET['action']) && $_GET['action'] == 'edit') && !empty($survey_id)) {
     if ($survey_data['anonymous'] == 0) {
-
         $form->addElement('checkbox', 'show_form_profile', null, get_lang('ShowFormProfile'), 'onclick="javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}"');
 
         if ($survey_data['show_form_profile'] == 1) {
@@ -212,7 +220,8 @@ if ((isset($_GET['action']) && $_GET['action'] == 'edit') && !empty($survey_id))
                     $input_name_list.= 'profile_'.$key.',';
                 }
             }
-            // Necesary to know the fields
+
+            // Necessary to know the fields
             $form->addElement('hidden', 'input_name_list', $input_name_list);
 
             // Set defaults form fields
@@ -309,7 +318,7 @@ if ($form->validate()) {
         Display::display_confirmation_message($return['message'], false);
     } else {
         // Redirecting to the survey page (whilst showing the return message)
-        header('location:survey.php?survey_id='.$return['id'].'&message='.$return['message']);
+        header('location: '.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$return['id'].'&message='.$return['message'].'&'.api_get_cidreq());
         exit;
     }
 } else {

+ 175 - 91
main/survey/fillsurvey.php

@@ -1,18 +1,17 @@
 <?php
-
 /* For licensing terms, see /license.txt */
 
 /**
- *    @package chamilo.survey
- *     @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>, Chamilo: Personality Test modification and rewriting large parts of the code as well
- *     @version $Id: survey_list.php 10680 2007-01-11 21:26:23Z pcool $
- *
- *     @todo use quickforms for the forms
- *     @todo check if the user already filled the survey and if this is the case then the answers have to be updated and not stored again.
- *           alterantively we could not allow people from filling the survey twice.
- *     @todo performance could be improved if not the survey_id was stored with the invitation but the survey_code
+*    @package chamilo.survey
+*     @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>, Chamilo: Personality Test modification and rewriting large parts of the code as well
+*     @version $Id: survey_list.php 10680 2007-01-11 21:26:23Z pcool $
+*
+*     @todo use quickforms for the forms
+*     @todo check if the user already filled the survey and if this is the case then the answers have to be updated and not stored again.
+*           alterantively we could not allow people from filling the survey twice.
+*     @todo performance could be improved if not the survey_id was stored with the invitation but the survey_code
  */
 // Language file that needs to be included
 $language_file = 'survey';
@@ -32,7 +31,10 @@ require_once 'survey.lib.php';
 
 // Breadcrumbs
 if (!empty($_user)) {
-    $interbreadcrumb[] = array('url' => 'survey_list.php?cidReq='.Security::remove_XSS($_GET['course']), 'name' => get_lang('SurveyList'));
+    $interbreadcrumb[] = array(
+        'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?cidReq='.Security::remove_XSS($_GET['course']),
+        'name' => get_lang('SurveyList')
+    );
 }
 
 // Database table definitions
@@ -41,7 +43,6 @@ $table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER);
 $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
 $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
 $table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION);
-
 $table_user = Database :: get_main_table(TABLE_MAIN_USER);
 
 // Check if user is anonymous or not
@@ -63,7 +64,7 @@ if (empty($course_info)) {
 }
 
 $course_id = $course_info['real_id'];
-$surveyCode = isset($_GET['scode']) ? Database::escape_string($_GET['scode']) : ''; 
+$surveyCode = isset($_GET['scode']) ? Database::escape_string($_GET['scode']) : '';
 
 if ($surveyCode != "") {
     // Firstly we check if this survey is ready for anonymous use:
@@ -73,11 +74,11 @@ if ($surveyCode != "") {
     // If is anonymous and is not allowed to take the survey to anonymous users, forbid access:
     if (!isset($rowAnonymous['anonymous']) || ($rowAnonymous['anonymous'] == 0 && api_is_anonymous($_user['user_id'], true)) || count($rowAnonymous) == 0) {
         api_not_allowed();
-    } 
+    }
 // If is anonymous and it is allowed to take the survey as anonymous, mark survey as anonymous:
 } else {
     //nothing to do
-} 
+}
 
 // Header
 Display :: display_header(get_lang('ToolSurvey'));
@@ -99,9 +100,9 @@ if ($invitationcode == 'auto' && isset($_GET['scode'])) {
 	      $autoInvitationcode = "auto-ANONY_".md5(time())."-$surveyCode";
     } else {
         // New invitation code from userid
-        $autoInvitationcode = "auto-$userid-$surveyCode"; 				
+        $autoInvitationcode = "auto-$userid-$surveyCode";
     }
-	
+
     // The survey code must exist in this course, or the URL is invalid
     $sql = "SELECT * FROM $table_survey WHERE c_id = $course_id AND code = '".$surveyCode."'";
     $result = Database::query($sql);
@@ -125,7 +126,10 @@ if ($invitationcode == 'auto' && isset($_GET['scode'])) {
 }
 
 // Now we check if the invitationcode is valid
-$sql = "SELECT * FROM $table_survey_invitation WHERE c_id = $course_id AND invitation_code = '".Database :: escape_string($invitationcode)."'";
+$sql = "SELECT * FROM $table_survey_invitation
+        WHERE
+            c_id = $course_id AND
+            invitation_code = '".Database :: escape_string($invitationcode)."'";
 $result = Database::query($sql); // false = suppress errors
 if (Database::num_rows($result) < 1) {
     Display :: display_error_message(get_lang('WrongInvitationCode'), false);
@@ -142,11 +146,12 @@ if ($isAnonymous && isset($_SESSION['surveyuser']) || ($survey_invitation['answe
     exit;
 }
 
-
-
 // Checking if there is another survey with this code.
 // If this is the case there will be a language choice
-$sql = "SELECT * FROM $table_survey WHERE c_id = $course_id AND code='".Database::escape_string($survey_invitation['survey_code'])."'";
+$sql = "SELECT * FROM $table_survey
+        WHERE
+            c_id = $course_id AND
+            code='".Database::escape_string($survey_invitation['survey_code'])."'";
 $result = Database::query($sql);
 
 if (Database::num_rows($result) > 1) {
@@ -177,7 +182,10 @@ $survey_data['survey_id'] = $survey_invitation['survey_id'];
 if (count($_POST) > 0) {
     if ($survey_data['survey_type'] === '0') {
         // Getting all the types of the question (because of the special treatment of the score question type
-        $sql = "SELECT * FROM $table_survey_question WHERE c_id = $course_id AND survey_id = '".Database::escape_string($survey_invitation['survey_id'])."'";
+        $sql = "SELECT * FROM $table_survey_question
+                WHERE
+                    c_id = $course_id AND
+                    survey_id = '".Database::escape_string($survey_invitation['survey_id'])."'";
         $result = Database::query($sql);
 
         while ($row = Database::fetch_array($result, 'ASSOC')) {
@@ -206,11 +214,13 @@ if (count($_POST) > 0) {
                         }
                         SurveyUtil::store_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $option_id, $option_value, $survey_data);
                     }
-                }
-                // All the other question types (open question, multiple choice, percentage, ...)
-                else {
+                } else {
+                    // All the other question types (open question, multiple choice, percentage, ...)
                     if ($types[$survey_question_id] == 'percentage') {
-                        $sql = "SELECT * FROM $table_survey_question_option WHERE c_id = $course_id AND question_option_id='".Database::escape_string($value)."'";
+                        $sql = "SELECT * FROM $table_survey_question_option
+                                WHERE
+                                    c_id = $course_id AND
+                                    question_option_id='".Database::escape_string($value)."'";
                         $result = Database::query($sql);
                         $row = Database::fetch_array($result, 'ASSOC');
                         $option_value = $row['option_text'];
@@ -236,8 +246,10 @@ if (count($_POST) > 0) {
             $shuffle = ' ORDER BY RAND() ';
         }
         $sql = "SELECT * FROM $table_survey_question
-                WHERE c_id = $course_id AND survey_id = '".Database::escape_string($survey_invitation['survey_id'])."'
-                AND survey_group_pri = '0' $shuffle";
+                WHERE
+                    c_id = $course_id AND
+                    survey_id = '".Database::escape_string($survey_invitation['survey_id'])."' AND
+                    survey_group_pri = '0' $shuffle";
         $result = Database::query($sql);
         // There is only one question type for conditional surveys
         while ($row = Database::fetch_array($result, 'ASSOC')) {
@@ -309,8 +321,12 @@ if ($survey_data['form_fields'] != '' && $survey_data['anonymous'] == 0 && is_ar
     }
 
     // We use the same form as in auth/profile.php
-    $form = new FormValidator('profile', 'post', api_get_self()."?".str_replace('&show_form=1', '&show_form=1', $_SERVER['QUERY_STRING']), null,
-            array('style' => 'width: 75%; float: '.($text_dir == 'rtl' ? 'right;' : 'left;'))
+    $form = new FormValidator(
+        'profile',
+        'post',
+        api_get_self()."?".str_replace('&show_form=1', '&show_form=1', $_SERVER['QUERY_STRING']),
+        null,
+        array('style' => 'width: 75%; float: '.($text_dir == 'rtl' ? 'right;' : 'left;'))
     );
 
     if (api_is_western_name_order()) {
@@ -519,27 +535,55 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
                 // Get the user into survey answer table (user or anonymus)
                 $my_user_id = ($survey_data['anonymous'] == 1) ? $_SESSION['surveyuser'] : api_get_user_id();
 
-                $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
-                    FROM $table_survey_question survey_question
-                    LEFT JOIN $table_survey_question_option survey_question_option
-                    ON survey_question.question_id = survey_question_option.question_id AND survey_question_option.c_id = $course_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='".$my_user_id."') AND
-                    survey_question.c_id =  $course_id
-                    ORDER BY survey_question.sort, survey_question_option.sort ASC";
+                $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
+                        FROM $table_survey_question survey_question
+                        LEFT JOIN $table_survey_question_option survey_question_option
+                            ON survey_question.question_id = survey_question_option.question_id AND survey_question_option.c_id = $course_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='".$my_user_id."') AND
+                                    survey_question.c_id =  $course_id
+                                ORDER BY survey_question.sort, survey_question_option.sort ASC";
             } else {
-                $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
-                    FROM $table_survey_question survey_question
-                    LEFT JOIN $table_survey_question_option survey_question_option
-                    ON survey_question.question_id = survey_question_option.question_id AND survey_question_option.c_id = $course_id
-                    WHERE survey_question.survey_id = '".Database::escape_string($survey_invitation['survey_id'])."' AND
-                    survey_question.question_id IN (".implode(',', $paged_questions[$_GET['show']]).") AND
-                    survey_question.c_id =  $course_id
-                    ORDER BY survey_question.sort, survey_question_option.sort ASC";
+                $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
+                        FROM $table_survey_question survey_question
+                        LEFT JOIN $table_survey_question_option survey_question_option
+                            ON survey_question.question_id = survey_question_option.question_id AND survey_question_option.c_id = $course_id
+                        WHERE
+                            survey_question.survey_id = '".Database::escape_string($survey_invitation['survey_id'])."' AND
+                            survey_question.question_id IN (".implode(',', $paged_questions[$_GET['show']]).") AND
+                            survey_question.c_id =  $course_id
+                        ORDER BY survey_question.sort, survey_question_option.sort ASC";
             }
 
             $result = Database::query($sql);
@@ -559,9 +603,8 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
                     $questions[$row['sort']]['type'] = $row['type'];
                     $questions[$row['sort']]['options'][$row['question_option_id']] = $row['option_text'];
                     $questions[$row['sort']]['maximum_score'] = $row['max_value'];
-                }
-                // If the type is a pagebreak we are finished loading the questions for this page
-                else {
+                } else {
+                    // If the type is a pagebreak we are finished loading the questions for this page
                     break;
                 }
                 $counter++;
@@ -584,12 +627,14 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
             // Get current user results
             $results = array();
             $sql = "SELECT survey_group_pri, user, SUM(value) as value
-                    FROM $table_survey_answer as survey_answer INNER JOIN $table_survey_question as survey_question
-                    ON  (survey_question.question_id = survey_answer.question_id)
-                    WHERE  survey_answer.survey_id='".$my_survey_id."' AND
-                           survey_answer.user='".$current_user."' AND
-                           survey_answer.c_id = $course_id AND
-                           survey_question.c_id = $course_id AND
+                    FROM $table_survey_answer as survey_answer
+                    INNER JOIN $table_survey_question as survey_question
+                    ON (survey_question.question_id = survey_answer.question_id)
+                    WHERE
+                        survey_answer.survey_id='".$my_survey_id."' AND
+                       survey_answer.user='".$current_user."' AND
+                       survey_answer.c_id = $course_id AND
+                       survey_question.c_id = $course_id AND
                     GROUP BY survey_group_pri
                     ORDER BY survey_group_pri
                     ";
@@ -606,16 +651,20 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
             $totals = array();
             $sql = "SELECT SUM(temp.value) as value, temp.survey_group_pri FROM
                     (
-                    SELECT MAX(value) as value,  survey_group_pri, survey_question.question_id
-                    FROM $table_survey_question as survey_question
-                    INNER JOIN $table_survey_question_option as survey_question_option
-                    ON (survey_question.question_id = survey_question_option.question_id)
-                    WHERE  survey_question.survey_id='".$my_survey_id."'  AND
-                           survey_question.c_id = $course_id AND
-                           survey_question_option.c_id = $course_id AND
-                           survey_group_sec1='0' AND
-                           survey_group_sec2='0'
-                    GROUP BY survey_group_pri, survey_question.question_id
+                        SELECT
+                            MAX(value) as value,
+                            survey_group_pri,
+                            survey_question.question_id
+                        FROM $table_survey_question as survey_question
+                        INNER JOIN $table_survey_question_option as survey_question_option
+                        ON (survey_question.question_id = survey_question_option.question_id)
+                        WHERE
+                            survey_question.survey_id='".$my_survey_id."'  AND
+                            survey_question.c_id = $course_id AND
+                            survey_question_option.c_id = $course_id AND
+                            survey_group_sec1='0' AND
+                            survey_group_sec2='0'
+                        GROUP BY survey_group_pri, survey_question.question_id
                     ) as temp
 
                     GROUP BY temp.survey_group_pri
@@ -775,9 +824,11 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
                     if (empty($_SESSION['page_questions_sec']) && !is_array($_SESSION['page_questions_sec']) && count($_SESSION['page_questions_sec'] == 0)) {
 
                         $sql = "SELECT * FROM $table_survey_question
-                                     WHERE c_id = $course_id AND survey_id = '".$my_survey_id."'
-                                       AND ($secondary )
-                                     ORDER BY sort ASC";
+                                 WHERE
+                                    c_id = $course_id AND
+                                    survey_id = '".$my_survey_id."' AND
+                                    ($secondary )
+                                 ORDER BY sort ASC";
                         $result = Database::query($sql);
                         $counter = 0;
                         while ($row = Database::fetch_array($result, 'ASSOC')) {
@@ -811,15 +862,28 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
                     //echo '<pre>'; print_r($paged_questions_sec); echo '</pre>';
                     if (is_array($paged_questions_sec)) {
 
-                        $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
+                        $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
                                 FROM $table_survey_question survey_question
                                 LEFT JOIN $table_survey_question_option survey_question_option
-                                ON survey_question.question_id = survey_question_option.question_id AND survey_question_option.c_id = $course_id
-                                WHERE   survey_question.survey_id = '".$my_survey_id."' AND
-                                        survey_question.c_id = $course_id AND
-                                        survey_question.question_id IN (".implode(',', $paged_questions_sec[$val]).")
+                                ON survey_question.question_id = survey_question_option.question_id AND
+                                survey_question_option.c_id = $course_id
+                                WHERE
+                                    survey_question.survey_id = '".$my_survey_id."' AND
+                                    survey_question.c_id = $course_id AND
+                                    survey_question.question_id IN (".implode(',', $paged_questions_sec[$val]).")
                                 ORDER  $shuffle ";
 
                         $result = Database::query($sql);
@@ -870,9 +934,12 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
 
             if (empty($_SESSION['paged_questions'])) {
                 $sql = "SELECT * FROM $table_survey_question
-                             WHERE c_id = $course_id AND survey_id = '".Database::escape_string($survey_invitation['survey_id'])."'
-                               AND survey_group_sec1='0' AND survey_group_sec2='0'
-                             ORDER ".$order_sql." ";
+                        WHERE
+                            c_id = $course_id AND
+                            survey_id = '".Database::escape_string($survey_invitation['survey_id'])."' AND
+                            survey_group_sec1='0' AND
+                            survey_group_sec2='0'
+                        ORDER ".$order_sql." ";
                 //echo '<br />'; echo '<br />';
                 $result = Database::query($sql);
                 $counter = 0;
@@ -914,15 +981,28 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
                 if ($imploded != '') {
                     // The answers are always in the same order NO shuffle
                     $order_sql = ' BY survey_question.sort, survey_question_option.sort ASC ';
-                    $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
+                    $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
                             FROM $table_survey_question survey_question
                             LEFT JOIN $table_survey_question_option survey_question_option
-                            ON survey_question.question_id = survey_question_option.question_id AND survey_question_option.c_id = $course_id
-                            WHERE    survey_question.survey_id = '".Database :: escape_string($survey_invitation['survey_id'])."' AND
-                                     survey_question.c_id = $course_id  AND
-                                     survey_question.question_id IN (".$imploded.")
+                            ON survey_question.question_id = survey_question_option.question_id AND
+                            survey_question_option.c_id = $course_id
+                            WHERE
+                                survey_question.survey_id = '".Database :: escape_string($survey_invitation['survey_id'])."' AND
+                                 survey_question.c_id = $course_id  AND
+                                 survey_question.question_id IN (".$imploded.")
                             ORDER $order_sql ";
                     $result = Database::query($sql);
                     $question_counter_max = Database :: num_rows($result);
@@ -961,7 +1041,11 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
 }
 
 // Selecting the maximum number of pages
-$sql = "SELECT * FROM $table_survey_question WHERE c_id = $course_id AND type='".Database::escape_string('pagebreak')."' AND survey_id='".Database::escape_string($survey_invitation['survey_id'])."'";
+$sql = "SELECT * FROM $table_survey_question
+        WHERE
+            c_id = $course_id AND
+            type='".Database::escape_string('pagebreak')."' AND
+            survey_id='".Database::escape_string($survey_invitation['survey_id'])."'";
 $result = Database::query($sql);
 $numberofpages = Database::num_rows($result) + 1;
 

+ 2 - 3
main/survey/generate_link.php

@@ -1,5 +1,4 @@
 <?php
-
 /* For licensing terms, see /license.txt */
 
 $language_file = 'survey';
@@ -17,8 +16,8 @@ if (empty($survey_id)) {
 
 $survey_data = survey_manager::get_survey($survey_id);
 
-$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
-$interbreadcrumb[] = array('url' => 'survey.php?survey_id='.$survey_id, 'name' => strip_tags($survey_data['title']));
+$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
+$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id, 'name' => strip_tags($survey_data['title']));
 
 Display::display_header(get_lang('Survey'), 'Survey');
 

+ 2 - 1
main/survey/index.php

@@ -1,3 +1,4 @@
 <?php
 require_once '../inc/global.inc.php';
-header('location: survey_list.php?'.api_get_cidReq());
+header('location: '.api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidReq());
+exit;

+ 1 - 6
main/survey/link.php

@@ -3,11 +3,6 @@
 
 require_once '../inc/global.inc.php';
 
-/*
-if (!api_is_allowed_to_edit(false, true)) {
-    api_not_allowed(true);
-}*/
-
 $survey_id = isset($_REQUEST['i']) ? intval($_REQUEST['i']) : null;
 
 if (empty($survey_id)) {
@@ -41,4 +36,4 @@ if ($hash_is_valid && $course_info) {
     }
 } else {
     api_not_allowed(true);
-}
+}

+ 49 - 29
main/survey/preview.php

@@ -34,22 +34,28 @@ $surveyId = Database::escape_string($_GET['survey_id']);
 $userInvited = 0;
 
 //query to ask if logged user is allowed to see the preview (if he is invited of he is a teacher)
-$sql = "SELECT survey_invitation.user FROM $table_survey_invitation survey_invitation LEFT JOIN $table_survey survey
-       ON survey_invitation.survey_code = survey.code WHERE survey_invitation.c_id = $course_id AND survey.survey_id = $surveyId AND survey_invitation.user = $userId";
+$sql = "SELECT survey_invitation.user
+        FROM $table_survey_invitation survey_invitation
+        LEFT JOIN $table_survey survey
+        ON survey_invitation.survey_code = survey.code
+        WHERE
+          survey_invitation.c_id = $course_id AND
+          survey.survey_id = $surveyId AND
+          survey_invitation.user = $userId";
 $result = Database::query($sql);
 if (Database::num_rows($result) > 0) {
-    $userInvited = 1;    
+    $userInvited = 1;
 }
-if($userInvited == 0) {
-    if(!api_is_allowed_to_edit()) {    
+if ($userInvited == 0) {
+    if(!api_is_allowed_to_edit()) {
         api_not_allowed();
-    }                
+    }
 }
 // We exit here if ther is no valid $_GET parameter
 if (!isset($_GET['survey_id']) || !is_numeric($_GET['survey_id'])){
-	Display :: display_header(get_lang('SurveyPreview'));
-	Display :: display_error_message(get_lang('InvallidSurvey'), false);
-	Display :: display_footer();
+	Display::display_header(get_lang('SurveyPreview'));
+	Display::display_error_message(get_lang('InvallidSurvey'), false);
+	Display::display_footer();
 	exit;
 }
 
@@ -58,22 +64,17 @@ $survey_id = intval($_GET['survey_id']);
 $survey_data = survey_manager::get_survey($survey_id);
 
 if (empty($survey_data)) {
-	Display :: display_header(get_lang('SurveyPreview'));
-	Display :: display_error_message(get_lang('InvallidSurvey'), false);
-	Display :: display_footer();
+	Display::display_header(get_lang('SurveyPreview'));
+	Display::display_error_message(get_lang('InvallidSurvey'), false);
+	Display::display_footer();
 	exit;
 }
 
-/*$urlname = strip_tags(api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40));
-if (api_strlen(strip_tags($survey_data['title'])) > 40) {
-	$urlname .= '...';
-}*/
-
 $urlname = strip_tags($survey_data['title']);
 
 // Breadcrumbs
-$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
-$interbreadcrumb[] = array('url' => 'survey.php?survey_id='.$survey_id, 'name' => $urlname);
+$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
+$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id, 'name' => $urlname);
 
 // Header
 Display :: display_header(get_lang('SurveyPreview'));
@@ -111,13 +112,15 @@ if (api_is_course_admin() || (api_is_course_admin() && $_GET['isStudentView'] ==
 		exit;
 	}
 
+    $questions = array();
+
 	if (isset($_GET['show'])) {
 		// Getting all the questions for this page and add them to a multidimensional array where the first index is the page.
 		// as long as there is no pagebreak fount we keep adding questions to the page
 		$questions_displayed = array();
 		$paged_questions = array();
 		$counter = 0;
-		$sql = "SELECT * FROM $table_survey_question 
+		$sql = "SELECT * FROM $table_survey_question
 		        WHERE c_id = $course_id AND survey_id = '".Database::escape_string($survey_id)."'
 				ORDER BY sort ASC";
 		$result = Database::query($sql);
@@ -133,15 +136,26 @@ if (api_is_course_admin() || (api_is_course_admin() && $_GET['isStudentView'] ==
         } else {
             $questions_exists = false;
         }
-		
+
 		if (array_key_exists($_GET['show'], $paged_questions)) {
-			$sql = "SELECT 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
-					FROM $table_survey_question survey_question LEFT JOIN $table_survey_question_option survey_question_option
-					ON survey_question.question_id = survey_question_option.question_id AND survey_question_option.c_id = $course_id 
-					WHERE 	survey_question.survey_id = '".Database::escape_string($survey_id)."' AND 
-							survey_question.question_id IN (".Database::escape_string(implode(',',$paged_questions[$_GET['show']])).") AND							
-							survey_question.c_id =  $course_id 
+			$sql = "SELECT
+                        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
+					FROM $table_survey_question survey_question
+					LEFT JOIN $table_survey_question_option survey_question_option
+					ON survey_question.question_id = survey_question_option.question_id AND survey_question_option.c_id = $course_id
+					WHERE
+					    survey_question.survey_id = '".Database::escape_string($survey_id)."' AND
+						survey_question.question_id IN (".Database::escape_string(implode(',',$paged_questions[$_GET['show']])).") AND
+						survey_question.c_id =  $course_id
 					ORDER BY survey_question.sort, survey_question_option.sort ASC";
 
 			$result = Database::query($sql);
@@ -166,8 +180,13 @@ if (api_is_course_admin() || (api_is_course_admin() && $_GET['isStudentView'] ==
 			}
 		}
 	}
+
 	// Selecting the maximum number of pages
-	$sql = "SELECT * FROM $table_survey_question WHERE c_id = $course_id AND type='".Database::escape_string('pagebreak')."' AND survey_id='".Database::escape_string($survey_id)."'";
+	$sql = "SELECT * FROM $table_survey_question
+	        WHERE
+	            c_id = $course_id AND
+	            type='".Database::escape_string('pagebreak')."' AND
+	            survey_id='".Database::escape_string($survey_id)."'";
 	$result = Database::query($sql);
 	$numberofpages = Database::num_rows($result) + 1;
 	// Displaying the form with the questions
@@ -176,6 +195,7 @@ if (api_is_course_admin() || (api_is_course_admin() && $_GET['isStudentView'] ==
 	} else {
 		$show = 0;
 	}
+
 	echo '<form id="question" name="question" method="post" action="'.api_get_self().'?survey_id='.Security::remove_XSS($survey_id).'&show='.$show.'">';
 
 	if (is_array($questions) && count($questions) > 0) {

+ 26 - 16
main/survey/question.php

@@ -17,12 +17,12 @@ require_once '../inc/global.inc.php';
 // Including additional libraries
 require_once 'survey.lib.php';
 
-$htmlHeadXtra[] = '<script type="text/javascript">
-						$(document).ready( function() {
-							$("button").click(function() {
-								$("#is_executable").attr("value",$(this).attr("name"));
-							});
-		 				} ); </script>';
+$htmlHeadXtra[] = '<script>
+$(document).ready( function() {
+    $("button").click(function() {
+        $("#is_executable").attr("value",$(this).attr("name"));
+    });
+} ); </script>';
 
 /** @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)) {
@@ -33,7 +33,7 @@ if (!api_is_allowed_to_edit(false, true)) {
 }
 
 // Is valid request
-$is_valid_request = $_REQUEST['is_executable'];
+$is_valid_request = isset($_REQUEST['is_executable']) ? $_REQUEST['is_executable'] : null;
 if ($request_index != $is_valid_request) {
 	if ($request_index == 'save_question') {
 		unset($_POST[$request_index]);
@@ -70,17 +70,20 @@ if (api_strlen(strip_tags($survey_data['title'])) > 40) {
 }
 
 if ($survey_data['survey_type'] == 1) {
-	$sql = 'SELECT id FROM '.Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP).' WHERE c_id = '.$course_id.' AND survey_id = '.(int)$_GET['survey_id'].' LIMIT 1';
+	$sql = 'SELECT id FROM '.Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP).'
+	        WHERE
+                c_id = '.$course_id.' AND
+                survey_id = '.(int)$_GET['survey_id'].' LIMIT 1';
 	$rs = Database::query($sql);
 	if(Database::num_rows($rs)===0) {
-		header('Location: survey.php?survey_id='.(int)$_GET['survey_id'].'&message='.'YouNeedToCreateGroups');
+		header('Location: '.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.(int)$_GET['survey_id'].'&message='.'YouNeedToCreateGroups');
 		exit;
 	}
 }
 
 // Breadcrumbs
-$interbreadcrumb[] = array ('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
-$interbreadcrumb[] = array ('url' => 'survey.php?survey_id='.Security::remove_XSS($_GET['survey_id']), 'name' => strip_tags($urlname));
+$interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
+$interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.Security::remove_XSS($_GET['survey_id']), 'name' => strip_tags($urlname));
 
 // Tool name
 if ($_GET['action'] == 'add') {
@@ -95,7 +98,7 @@ $possible_types = array('personality', 'yesno', 'multiplechoice', 'multiplerespo
 
 // Actions
 $actions = '<div class="actions">';
-$actions .= '<a href="survey.php?survey_id='.Security::remove_XSS($_GET['survey_id']).'">'.Display::return_icon('back.png', get_lang('BackToSurvey'),'',ICON_SIZE_MEDIUM).'</a>';
+$actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.Security::remove_XSS($_GET['survey_id']).'">'.Display::return_icon('back.png', get_lang('BackToSurvey'),'',ICON_SIZE_MEDIUM).'</a>';
 $actions .= '</div>';
 // Checking if it is a valid type
 if (!in_array($_GET['type'], $possible_types)) {
@@ -116,7 +119,11 @@ if (empty($_POST['save_question']) && in_array($_GET['type'], $possible_types))
 		if (isset($_SESSION['temp_sys_message'])) {
 			$error_message=$_SESSION['temp_sys_message'];
 			unset($_SESSION['temp_sys_message']);
-			if ($error_message == 'PleaseEnterAQuestion' || $error_message == 'PleasFillAllAnswer'|| $error_message == 'PleaseChooseACondition'|| $error_message == 'ChooseDifferentCategories') {
+			if ($error_message == 'PleaseEnterAQuestion' ||
+                $error_message == 'PleasFillAllAnswer'||
+                $error_message == 'PleaseChooseACondition'||
+                $error_message == 'ChooseDifferentCategories'
+            ) {
 				Display::display_error_message(get_lang($error_message), true);
 			}
 		}
@@ -154,7 +161,10 @@ if (empty($_POST['save_question']) && in_array($_GET['type'], $possible_types))
 	// An action has been performed (for instance adding a possible answer, moving an answer, ...)
 	if ($_POST) {
 		$form_content = $_POST;
-		$form_content = $form->handle_action($form_content);
+		$form_content = $form->handle_action(
+            $survey_data,
+            $form_content
+        );
 	}
 
 	if ($error_message != '') {
@@ -169,12 +179,12 @@ if (empty($_POST['save_question']) && in_array($_GET['type'], $possible_types))
 		unset($_SESSION['temp_horizontalvertical']);
 	}
 
-	$form->create_form($form_content);
+	$form->create_form($survey_data, $form_content);
 	$form->render_form();
 } else {
 	$form_content = $_POST;
 	$form = new survey_question();
-	$form->handle_action($form_content);
+	$form->handle_action($survey_data, $form_content);
 }
 
 // Footer

+ 27 - 13
main/survey/reporting.php

@@ -17,7 +17,6 @@ $language_file = 'survey';
 require_once '../inc/global.inc.php';
 require_once 'survey.lib.php';
 $this_section = SECTION_COURSES;
-
 $survey_id = intval($_GET['survey_id']);
 
 // Export
@@ -25,17 +24,17 @@ $survey_id = intval($_GET['survey_id']);
  * @todo use export_table_csv($data, $filename = 'export')
  */
 if (isset($_POST['export_report']) && $_POST['export_report']) {
-	switch($_POST['export_format']) {
+	switch ($_POST['export_format']) {
 		case 'xls':
 			$survey_data = survey_manager::get_survey($survey_id);
 			$filename = 'survey_results_'.$survey_id.'.xls';
-			$data = SurveyUtil::export_complete_report_xls($filename, $_GET['user_id']);
+			$data = SurveyUtil::export_complete_report_xls($survey_data, $filename, $_GET['user_id']);
 			exit;
 			break;
 		case 'csv':
 		default:
 			$survey_data = survey_manager::get_survey($survey_id);
-			$data = SurveyUtil::export_complete_report($_GET['user_id']);
+			$data = SurveyUtil::export_complete_report($survey_data, $_GET['user_id']);
 
 			//$filename = 'fileexport.csv';
 			$filename = 'survey_results_'.$survey_id.'.csv';
@@ -61,8 +60,19 @@ if (isset($_POST['export_report']) && $_POST['export_report']) {
 	}
 }
 
+if ($survey_data['anonymous'] == 0) {
+    $people_filled_full_data = true;
+} else {
+    $people_filled_full_data = false;
+}
+$people_filled = survey_manager::get_people_who_filled_survey(
+    $_GET['survey_id'],
+    $people_filled_full_data
+);
+
 // Checking the parameters
-SurveyUtil::check_parameters();
+SurveyUtil::check_parameters($people_filled);
+
 
 /** @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)) {
@@ -92,12 +102,15 @@ if (api_strlen(strip_tags($survey_data['title'])) > 40) {
 }
 
 // Breadcrumbs
-$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
-$interbreadcrumb[] = array('url' => 'survey.php?survey_id='.$survey_id, 'name' => $urlname);
+$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
+$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id, 'name' => $urlname);
 if (!$_GET['action'] OR $_GET['action'] == 'overview') {
 	$tool_name = get_lang('Reporting');
 } else {
-	$interbreadcrumb[] = array('url' => 'reporting.php?survey_id='.$survey_id, 'name' => get_lang('Reporting'));
+	$interbreadcrumb[] = array(
+        'url' => api_get_path(WEB_CODE_PATH).'survey/reporting.php?survey_id='.$survey_id,
+        'name' => get_lang('Reporting')
+    );
 	switch ($_GET['action']) {
 		case 'questionreport':
 			$tool_name = get_lang('DetailedReportByQuestion');
@@ -118,19 +131,20 @@ if (!$_GET['action'] OR $_GET['action'] == 'overview') {
 Display::display_header($tool_name, 'Survey');
 
 // Action handling
-SurveyUtil::handle_reporting_actions();
+SurveyUtil::handle_reporting_actions($people_filled);
 
 // Actions bar
 echo '<div class="actions">';
-echo '<a href="survey.php?survey_id='.$survey_id.'">'.Display::return_icon('back.png', get_lang('BackToSurvey'),'',ICON_SIZE_MEDIUM).'</a>';
+echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'">'.
+    Display::return_icon('back.png', get_lang('BackToSurvey'),'',ICON_SIZE_MEDIUM).'</a>';
 echo '</div>';
 
 // Content
 if (!$_GET['action'] || $_GET['action'] == 'overview') {
 	$myweb_survey_id = $survey_id;
-	echo '<div class="sectiontitle"><a href="reporting.php?action=questionreport&amp;survey_id='.$myweb_survey_id.'">'.Display::return_icon('survey_reporting_question.gif',get_lang('DetailedReportByQuestion')).' '.get_lang('DetailedReportByQuestion').'</a></div><div class="sectioncomment">'.get_lang('DetailedReportByQuestionDetail').' </div>';
-	echo '<div class="sectiontitle"><a href="reporting.php?action=userreport&amp;survey_id='.$myweb_survey_id.'">'.Display::return_icon('survey_reporting_user.gif',get_lang('DetailedReportByUser')).' '.get_lang('DetailedReportByUser').'</a></div><div class="sectioncomment">'.get_lang('DetailedReportByUserDetail').'.</div>';
-	echo '<div class="sectiontitle"><a href="reporting.php?action=comparativereport&amp;survey_id='.$myweb_survey_id.'">'.Display::return_icon('survey_reporting_comparative.gif',get_lang('ComparativeReport')).' '.get_lang('ComparativeReport').'</a></div><div class="sectioncomment">'.get_lang('ComparativeReportDetail').'.</div>';
+	echo '<div class="sectiontitle"><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=questionreport&amp;survey_id='.$myweb_survey_id.'">'.Display::return_icon('survey_reporting_question.gif',get_lang('DetailedReportByQuestion')).' '.get_lang('DetailedReportByQuestion').'</a></div><div class="sectioncomment">'.get_lang('DetailedReportByQuestionDetail').' </div>';
+	echo '<div class="sectiontitle"><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=userreport&amp;survey_id='.$myweb_survey_id.'">'.Display::return_icon('survey_reporting_user.gif',get_lang('DetailedReportByUser')).' '.get_lang('DetailedReportByUser').'</a></div><div class="sectioncomment">'.get_lang('DetailedReportByUserDetail').'.</div>';
+	echo '<div class="sectiontitle"><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=comparativereport&amp;survey_id='.$myweb_survey_id.'">'.Display::return_icon('survey_reporting_comparative.gif',get_lang('ComparativeReport')).' '.get_lang('ComparativeReport').'</a></div><div class="sectioncomment">'.get_lang('ComparativeReportDetail').'.</div>';
 	echo '<div class="sectiontitle"><a href="reporting.php?action=completereport&amp;survey_id='.$myweb_survey_id.'">'.Display::return_icon('survey_reporting_complete.gif',get_lang('CompleteReport')).' '.get_lang('CompleteReport').'</a></div><div class="sectioncomment">'.get_lang('CompleteReportDetail').'</div>';
 }
 

+ 37 - 20
main/survey/survey.download.inc.php

@@ -22,11 +22,14 @@ function check_download_survey($course, $invitation, $doc_url) {
 	// Database table definitions
 	$table_survey 					= Database :: get_course_table(TABLE_SURVEY);
 	$table_survey_question 			= Database :: get_course_table(TABLE_SURVEY_QUESTION);
-	$table_survey_question_option 	= Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);		
+	$table_survey_question_option 	= Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
 	$table_survey_invitation 		= Database :: get_course_table(TABLE_SURVEY_INVITATION);
 
 	// Now we check if the invitationcode is valid
-	$sql = "SELECT * FROM $table_survey_invitation WHERE c_id = $course_id AND invitation_code = '".Database::escape_string($invitation)."'";
+	$sql = "SELECT * FROM $table_survey_invitation
+	        WHERE
+	            c_id = $course_id AND
+	            invitation_code = '".Database::escape_string($invitation)."'";
 	$result = Database::query($sql);
 	if (Database::num_rows($result) < 1) {
 		Display :: display_error_message(get_lang('WrongInvitationCode'), false);
@@ -47,7 +50,10 @@ function check_download_survey($course, $invitation, $doc_url) {
 	// Fetch survey ID
 
 	// If this is the case there will be a language choice
-	$sql = "SELECT * FROM $table_survey WHERE c_id = $course_id AND code='".Database::escape_string($survey_invitation['survey_code'])."'";
+	$sql = "SELECT * FROM $table_survey
+	        WHERE
+	            c_id = $course_id AND
+	            code='".Database::escape_string($survey_invitation['survey_code'])."'";
 	$result = Database::query($sql);
 	if (Database::num_rows($result) > 1) {
 		if ($_POST['language']) {
@@ -69,22 +75,33 @@ function check_download_survey($course, $invitation, $doc_url) {
 		$survey_invitation['survey_id'] = $row['survey_id'];
 	}
 
-	$sql = "SELECT count(*) FROM $table_survey WHERE c_id = $course_id AND survey_id = ".$survey_invitation['survey_id']."
-								and (
-									title LIKE '%$doc_url%'
-									or subtitle LIKE '%$doc_url%'
-									or intro LIKE '%$doc_url%'
-									or surveythanks LIKE '%$doc_url%'
-								)
-		union select count(*) from $table_survey_question  where c_id = $course_id AND survey_id = ".$survey_invitation['survey_id']."
-								and (
-									survey_question LIKE '%$doc_url%'
-									or survey_question_comment LIKE '%$doc_url%'
-								)
-		union select count(*) from $table_survey_question_option where c_id = $course_id AND survey_id = ".$survey_invitation['survey_id']."
-								and (
-									option_text LIKE '%$doc_url%'
-								)";
+	$sql = "SELECT count(*)
+	        FROM $table_survey
+	        WHERE
+	            c_id = $course_id AND
+	            survey_id = ".$survey_invitation['survey_id']." AND (
+                    title LIKE '%$doc_url%'
+                    or subtitle LIKE '%$doc_url%'
+                    or intro LIKE '%$doc_url%'
+                    or surveythanks LIKE '%$doc_url%'
+                )
+		    UNION
+		        SELECT count(*)
+		        FROM $table_survey_question
+		        WHERE
+		            c_id = $course_id AND
+		            survey_id = ".$survey_invitation['survey_id']." AND (
+                        survey_question LIKE '%$doc_url%'
+                        or survey_question_comment LIKE '%$doc_url%'
+                    )
+		    UNION
+		        SELECT count(*)
+		        FROM $table_survey_question_option
+		        WHERE
+		            c_id = $course_id AND
+		            survey_id = ".$survey_invitation['survey_id']." AND (
+                        option_text LIKE '%$doc_url%'
+                    )";
 	$result = Database::query($sql);
 	if (Database::num_rows($result) == 0) {
 		Display :: display_error_message(get_lang('WrongInvitationCode'), false);
@@ -92,4 +109,4 @@ function check_download_survey($course, $invitation, $doc_url) {
 		exit;
 	}
 	return $_course;
-}
+}

ファイルの差分が大きいため隠しています
+ 257 - 203
main/survey/survey.lib.php


+ 44 - 43
main/survey/survey.php

@@ -46,7 +46,7 @@ $survey_id = intval($_GET['survey_id']);
 $course_id = api_get_course_int_id();
 
 // Breadcrumbs
-$interbreadcrumb[] = array ('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
+$interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
 
 // Getting the survey information
 if (isset($_GET['survey_id'])) {
@@ -69,10 +69,12 @@ if (api_strlen(strip_tags($survey_data['title'])) > 40) {
 	$tool_name .= '...';
 }
 
-if ($is_survey_type_1 && $_GET['action'] == 'addgroup' || $_GET['action'] == 'deletegroup') {
+if ($is_survey_type_1 &&
+    isset($_GET['action']) &&
+    ($_GET['action'] == 'addgroup' || $_GET['action'] == 'deletegroup')
+) {
 	$_POST['name'] = trim($_POST['name']);
-
-	if (($_GET['action'] == 'addgroup')) {
+	if ($_GET['action'] == 'addgroup') {
 		if (!empty($_POST['group_id'])) {
 			Database::query('UPDATE '.$table_survey_question_group.' SET description = \''.Database::escape_string($_POST['description']).'\'
 			                 WHERE c_id = '.$course_id.' AND id = \''.Database::escape_string($_POST['group_id']).'\'');
@@ -89,7 +91,7 @@ if ($is_survey_type_1 && $_GET['action'] == 'addgroup' || $_GET['action'] == 'de
 		Database::query('DELETE FROM '.$table_survey_question_group.' WHERE c_id = '.$course_id.' AND id = '.Database::escape_string($_GET['gid']).' and survey_id = '.Database::escape_string($survey_id));
 		$sendmsg = 'GroupDeletedSuccessfully';
 	}
-	header('Location:survey.php?survey_id='.$survey_id.'&sendmsg='.$sendmsg);
+	header('Location: '.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&sendmsg='.$sendmsg);
 	exit;
 }
 
@@ -98,10 +100,10 @@ if ($is_survey_type_1 && $_GET['action'] == 'addgroup' || $_GET['action'] == 'de
 Display::display_header($tool_name, 'Survey');
 
 // Action handling
-$my_action_survey		= Security::remove_XSS($_GET['action']);
-$my_question_id_survey  = Security::remove_XSS($_GET['question_id']);
+$my_action_survey		= isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
+$my_question_id_survey  = isset($_GET['question_id']) ? Security::remove_XSS($_GET['question_id']) : null;
 $my_survey_id_survey    = Security::remove_XSS($_GET['survey_id']);
-$message_information    = Security::remove_XSS($_GET['message']);
+$message_information    = isset($_GET['message']) ? Security::remove_XSS($_GET['message']) : null;
 
 if (isset($_GET['action'])) {
 	if (($_GET['action'] == 'moveup' || $_GET['action'] == 'movedown') && isset($_GET['question_id'])) {
@@ -133,30 +135,29 @@ if (!empty($survey_data['survey_version'])) echo '<b>'.get_lang('Version').': '.
 SurveyUtil::check_first_last_question($_GET['survey_id']);
 
 // Action links
-$survey_actions = '<a href="create_new_survey.php?'.api_get_cidreq().'&amp;action=edit&amp;survey_id='.$survey_id.'">'.Display::return_icon('edit.png', get_lang('EditSurvey'),'',ICON_SIZE_MEDIUM).'</a>';
-$survey_actions .= '<a href="survey_list.php?'.api_get_cidreq().'&amp;action=delete&amp;survey_id='.$survey_id.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('DeleteSurvey').'?', ENT_QUOTES)).'\')) return false;">'.Display::return_icon('delete.png', get_lang('DeleteSurvey'),'',ICON_SIZE_MEDIUM).'</a>';
-//$survey_actions .= '<a href="create_survey_in_another_language.php?id_survey='.$survey_id.'">'.Display::return_icon('copy.gif', get_lang('Copy')).'</a>';
-$survey_actions .= '<a href="preview.php?'.api_get_cidreq().'&amp;survey_id='.$survey_id.'">'.Display::return_icon('preview_view.png', get_lang('Preview'),'',ICON_SIZE_MEDIUM).'</a>';
-$survey_actions .= '<a href="survey_invite.php?'.api_get_cidreq().'&amp;survey_id='.$survey_id.'">'.Display::return_icon('mail_send.png', get_lang('Publish'),'',ICON_SIZE_MEDIUM).'</a>';
-$survey_actions .= '<a href="reporting.php?'.api_get_cidreq().'&amp;survey_id='.$survey_id.'">'.Display::return_icon('stats.png', get_lang('Reporting'),'',ICON_SIZE_MEDIUM).'</a>';
+$survey_actions = '<a href="'.api_get_path(WEB_CODE_PATH).'survey/create_new_survey.php?'.api_get_cidreq().'&amp;action=edit&amp;survey_id='.$survey_id.'">'.Display::return_icon('edit.png', get_lang('EditSurvey'),'',ICON_SIZE_MEDIUM).'</a>';
+$survey_actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq().'&amp;action=delete&amp;survey_id='.$survey_id.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('DeleteSurvey').'?', ENT_QUOTES)).'\')) return false;">'.Display::return_icon('delete.png', get_lang('DeleteSurvey'),'',ICON_SIZE_MEDIUM).'</a>';
+//$survey_actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/create_survey_in_another_language.php?id_survey='.$survey_id.'">'.Display::return_icon('copy.gif', get_lang('Copy')).'</a>';
+$survey_actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/preview.php?'.api_get_cidreq().'&amp;survey_id='.$survey_id.'">'.Display::return_icon('preview_view.png', get_lang('Preview'),'',ICON_SIZE_MEDIUM).'</a>';
+$survey_actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invite.php?'.api_get_cidreq().'&amp;survey_id='.$survey_id.'">'.Display::return_icon('mail_send.png', get_lang('Publish'),'',ICON_SIZE_MEDIUM).'</a>';
+$survey_actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?'.api_get_cidreq().'&amp;survey_id='.$survey_id.'">'.Display::return_icon('stats.png', get_lang('Reporting'),'',ICON_SIZE_MEDIUM).'</a>';
 echo '<div class="actions">'.$survey_actions.'</div>';
 
 if ($survey_data['survey_type'] == 0) {
 	echo '<div class="actionsbig">';
-	echo '<a style="padding-left:0px;" href="question.php?'.api_get_cidreq().'&amp;action=add&type=yesno&amp;survey_id='.$survey_id.'">'.Display::return_icon('yesno.gif', get_lang('YesNo')).'</a>';
-	echo '<a href="question.php?'.api_get_cidreq().'&amp;action=add&type=multiplechoice&amp;survey_id='.$survey_id.'">'.Display::return_icon('mcua.gif', get_lang('UniqueSelect')).'<br /></a>';
-	echo '<a href="question.php?'.api_get_cidreq().'&amp;action=add&type=multipleresponse&amp;survey_id='.$survey_id.'">'.Display::return_icon('mcma.gif', get_lang('MultipleResponse')).'</a>';
-	echo '<a href="question.php?'.api_get_cidreq().'&amp;action=add&type=open&amp;survey_id='.$survey_id.'">'.Display::return_icon('open_answer.gif', get_lang('Open')).'<br /></a>';
-	echo '<a href="question.php?'.api_get_cidreq().'&amp;action=add&type=dropdown&amp;survey_id='.$survey_id.'">'.Display::return_icon('dropdown.gif', get_lang('Dropdown')).'<br /></a>';
-	echo '<a href="question.php?'.api_get_cidreq().'&amp;action=add&type=percentage&amp;survey_id='.$survey_id.'">'.Display::return_icon('percentagequestion.gif', get_lang('Percentage')).'<br /></a>';
-	echo '<a href="question.php?'.api_get_cidreq().'&amp;action=add&type=score&amp;survey_id='.$survey_id.'">'.Display::return_icon('scorequestion.gif', get_lang('Score')).'</a>';
-	echo '<a href="question.php?'.api_get_cidreq().'&amp;action=add&type=comment&amp;survey_id='.$survey_id.'">'.Display::return_icon('commentquestion.gif', get_lang('Comment')).'</a>';
-	echo '<a href="question.php?'.api_get_cidreq().'&amp;action=add&type=pagebreak&amp;survey_id='.$survey_id.'">'.Display::return_icon('page_end.gif', get_lang('Pagebreak')).'</a>';
+	echo '<a style="padding-left:0px;" href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&amp;action=add&type=yesno&amp;survey_id='.$survey_id.'">'.Display::return_icon('yesno.gif', get_lang('YesNo')).'</a>';
+	echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&amp;action=add&type=multiplechoice&amp;survey_id='.$survey_id.'">'.Display::return_icon('mcua.gif', get_lang('UniqueSelect')).'<br /></a>';
+	echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&amp;action=add&type=multipleresponse&amp;survey_id='.$survey_id.'">'.Display::return_icon('mcma.gif', get_lang('MultipleResponse')).'</a>';
+	echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&amp;action=add&type=open&amp;survey_id='.$survey_id.'">'.Display::return_icon('open_answer.gif', get_lang('Open')).'<br /></a>';
+	echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&amp;action=add&type=dropdown&amp;survey_id='.$survey_id.'">'.Display::return_icon('dropdown.gif', get_lang('Dropdown')).'<br /></a>';
+	echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&amp;action=add&type=percentage&amp;survey_id='.$survey_id.'">'.Display::return_icon('percentagequestion.gif', get_lang('Percentage')).'<br /></a>';
+	echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&amp;action=add&type=score&amp;survey_id='.$survey_id.'">'.Display::return_icon('scorequestion.gif', get_lang('Score')).'</a>';
+	echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&amp;action=add&type=comment&amp;survey_id='.$survey_id.'">'.Display::return_icon('commentquestion.gif', get_lang('Comment')).'</a>';
+	echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&amp;action=add&type=pagebreak&amp;survey_id='.$survey_id.'">'.Display::return_icon('page_end.gif', get_lang('Pagebreak')).'</a>';
 	echo '</div>';
 } else {
 	echo '<div class="actionsbig">';
-	//echo '<a href="group.php?'.api_get_cidreq().'&amp;action=add&amp;survey_id='.$survey_id.'"><img src="../img/yesno.gif" /><br />'.get_lang('Add groups').'</a></div>';
-	echo '<a style="padding-left:0px;" href="question.php?'.api_get_cidreq().'&amp;action=add&type=personality&amp;survey_id='.$survey_id.'"><img src="../img/yesno.gif" /></a></div>';
+	echo '<a style="padding-left:0px;" href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&amp;action=add&type=personality&amp;survey_id='.$survey_id.'"><img src="../img/yesno.gif" /></a></div>';
 	echo '</div>';
 }
 
@@ -176,20 +177,22 @@ echo '	</tr>';
 
 // Displaying the table contents with all the questions
 $question_counter = 1;
-$sql = "SELECT * FROM $table_survey_question_group WHERE c_id = '.$course_id.' AND survey_id = '".Database::escape_string($survey_id)."' ORDER BY id";
+$sql = "SELECT * FROM $table_survey_question_group
+        WHERE c_id = '.$course_id.' AND survey_id = '".Database::escape_string($survey_id)."' ORDER BY id";
 $result = Database::query($sql);
 $groups = array();
 while ($row = Database::fetch_array($result)) {
     $groups[$row['id']] = $row['name'];
 }
 $sql = "SELECT survey_question.*, count(survey_question_option.question_option_id) as number_of_options
-			FROM $table_survey_question survey_question
-			LEFT JOIN $table_survey_question_option survey_question_option
-			ON survey_question.question_id = survey_question_option.question_id AND survey_question_option.c_id = $course_id
-			WHERE    survey_question.survey_id 	= '".Database::escape_string($survey_id)."' AND
-			         survey_question.c_id 		= $course_id
-			GROUP BY survey_question.question_id
-			ORDER BY survey_question.sort ASC";
+        FROM $table_survey_question survey_question
+        LEFT JOIN $table_survey_question_option survey_question_option
+        ON survey_question.question_id = survey_question_option.question_id AND survey_question_option.c_id = $course_id
+        WHERE
+            survey_question.survey_id 	= '".Database::escape_string($survey_id)."' AND
+             survey_question.c_id 		= $course_id
+        GROUP BY survey_question.question_id
+        ORDER BY survey_question.sort ASC";
 
 $result = Database::query($sql);
 $question_counter_max = Database::num_rows($result);
@@ -215,15 +218,15 @@ while ($row = Database::fetch_array($result, 'ASSOC')) {
 	echo '	<td>'.$tool_name.'</td>';
 	echo '	<td>'.$row['number_of_options'].'</td>';
 	echo '	<td>';
-	echo '		<a href="question.php?'.api_get_cidreq().'&amp;action=edit&amp;type='.$row['type'].'&amp;survey_id='.$survey_id.'&amp;question_id='.$row['question_id'].'">'.Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>';
-	echo '		<a href="survey.php?'.api_get_cidreq().'&amp;action=delete&amp;survey_id='.$survey_id.'&amp;question_id='.$row['question_id'].'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("DeleteSurveyQuestion").'?',ENT_QUOTES,$charset)).'\')) return false;">'.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
+	echo '		<a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&amp;action=edit&amp;type='.$row['type'].'&amp;survey_id='.$survey_id.'&amp;question_id='.$row['question_id'].'">'.Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>';
+	echo '		<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?'.api_get_cidreq().'&amp;action=delete&amp;survey_id='.$survey_id.'&amp;question_id='.$row['question_id'].'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("DeleteSurveyQuestion").'?',ENT_QUOTES,$charset)).'\')) return false;">'.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
 	if ($question_counter > 1) {
-		echo '		<a href="survey.php?'.api_get_cidreq().'&amp;action=moveup&amp;survey_id='.$survey_id.'&amp;question_id='.$row['question_id'].'">'.Display::return_icon('up.png', get_lang('MoveUp'),'',ICON_SIZE_SMALL).'</a>';
+		echo '		<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?'.api_get_cidreq().'&amp;action=moveup&amp;survey_id='.$survey_id.'&amp;question_id='.$row['question_id'].'">'.Display::return_icon('up.png', get_lang('MoveUp'),'',ICON_SIZE_SMALL).'</a>';
 	} else {
 		Display::display_icon('up_na.png','&nbsp;','',ICON_SIZE_SMALL);
 	}
 	if ($question_counter < $question_counter_max) {
-		echo '		<a href="survey.php?'.api_get_cidreq().'&amp;action=movedown&amp;survey_id='.$survey_id.'&amp;question_id='.$row['question_id'].'">'.Display::return_icon('down.png', get_lang('MoveDown'),'',ICON_SIZE_SMALL).'</a>';
+		echo '		<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?'.api_get_cidreq().'&amp;action=movedown&amp;survey_id='.$survey_id.'&amp;question_id='.$row['question_id'].'">'.Display::return_icon('down.png', get_lang('MoveDown'),'',ICON_SIZE_SMALL).'</a>';
 	} else {
 		Display::display_icon('down_na.png','&nbsp;','',ICON_SIZE_SMALL);
 	}
@@ -249,10 +252,8 @@ if ($is_survey_type_1) {
 	if (in_array($_GET['sendmsg'], array('GroupNeedName'))){
 		echo Display::display_warning_message(get_lang($_GET['sendmsg']), false);
 	}
-
 	echo '<table border="0"><tr><td width="100">'.get_lang('Name').'</td><td>'.get_lang('Description').'</td></tr></table>';
-
-	echo '<form action="survey.php?action=addgroup&survey_id='.$survey_id.'" method="post">';
+	echo '<form action="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?action=addgroup&survey_id='.$survey_id.'" method="post">';
 	if ($_GET['action'] == 'editgroup') {
 		$sql = 'SELECT name,description FROM '.$table_survey_question_group.' WHERE id = '.Database::escape_string($_GET['gid']).' AND survey_id = '.Database::escape_string($survey_id).' limit 1';
 		$rs = Database::query($sql);
@@ -280,9 +281,9 @@ if ($is_survey_type_1) {
 	$rs = Database::query($sql);
 	while($row = Database::fetch_array($rs,ASSOC)){
 		$grouplist .= '<tr><td>'.$row['name'].'</td><td>'.$row['description'].'</td><td>'.
-		'<a href="survey.php?survey_id='.$survey_id.'&gid='.$row['id'].'&action=editgroup">'.
+		'<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&gid='.$row['id'].'&action=editgroup">'.
 		Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL).'</a> '.
-		'<a href="survey.php?survey_id='.$survey_id.'&gid='.$row['id'].'&action=deletegroup" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('DeleteSurveyGroup'),$row['name']).'?',ENT_QUOTES)).'\')) return false;">'.
+		'<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&gid='.$row['id'].'&action=deletegroup" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('DeleteSurveyGroup'),$row['name']).'?',ENT_QUOTES)).'\')) return false;">'.
 		Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
 		'</td></tr>';
 	}
@@ -290,4 +291,4 @@ if ($is_survey_type_1) {
 }
 
 // Footer
-Display :: display_footer();
+Display :: display_footer();

+ 8 - 22
main/survey/survey_invitation.php

@@ -63,8 +63,8 @@ if (api_strlen(strip_tags($survey_data['title'])) > 40) {
 }
 
 // Breadcrumbs
-$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
-$interbreadcrumb[] = array('url' => 'survey.php?survey_id='.$survey_id, 'name' => $urlname);
+$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
+$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id, 'name' => $urlname);
 
 
 // Displaying the header
@@ -110,24 +110,24 @@ echo '	</tr>';
 
 $course_id = api_get_course_int_id();
 
-$sql = "SELECT survey_invitation.*, user.firstname, user.lastname, user.email 
-            FROM $table_survey_invitation survey_invitation
-			LEFT JOIN $table_user user ON (survey_invitation.user = user.user_id AND survey_invitation.c_id = $course_id)
-			WHERE survey_invitation.survey_code = '".Database::escape_string($survey_data['code'])."' ";
+$sql = "SELECT survey_invitation.*, user.firstname, user.lastname, user.email
+        FROM $table_survey_invitation survey_invitation
+        LEFT JOIN $table_user user ON (survey_invitation.user = user.user_id AND survey_invitation.c_id = $course_id)
+        WHERE survey_invitation.survey_code = '".Database::escape_string($survey_data['code'])."' ";
 
 $res = Database::query($sql);
 while ($row = Database::fetch_assoc($res)) {
 	if (!$_GET['view'] || $_GET['view'] == 'invited' || ($_GET['view'] == 'answered' && in_array($row['user'], $answered_data)) || ($_GET['view'] == 'unanswered' && !in_array($row['user'], $answered_data))) {
 		echo '<tr>';
 		if (is_numeric($row['user'])) {
-			echo '			<td><a href="../user/userInfo.php?editMainUserInfo='.$row['user'].'">'.api_get_person_name($row['firstname'], $row['lastname']).'</a></td>';
+			echo '			<td><a href="'.api_get_path(WEB_CODE_PATH).'user/userInfo.php?editMainUserInfo='.$row['user'].'">'.api_get_person_name($row['firstname'], $row['lastname']).'</a></td>';
 		} else {
 				echo '	<td>'.$row['user'].'</td>';
 		}
 		echo '	<td>'.$row['invitation_date'].'</td>';
 		echo '	<td>';
 		if (in_array($row['user'], $answered_data)) {
-			echo '<a href="reporting.php?action=userreport&amp;survey_id='.$survey_id.'&amp;user='.$row['user'].'">'.get_lang('ViewAnswers').'</a>';
+			echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=userreport&amp;survey_id='.$survey_id.'&amp;user='.$row['user'].'">'.get_lang('ViewAnswers').'</a>';
 		} else {
 			echo '-';
 		}
@@ -141,17 +141,3 @@ echo '</table>';
 
 // Footer
 Display :: display_footer();
-
-/**
- * @todo add the additional parameters
- */
-/*
-$table = new SortableTable('survey_invitations', 'get_number_of_survey_invitations', 'get_survey_invitations_data',2);
-$table->set_additional_parameters($parameters);
-$table->set_header(0, get_lang('User'));
-$table->set_header(1, get_lang('InvitationCode'));
-$table->set_header(2, get_lang('InvitationDate'));
-$table->set_header(3, get_lang('Answered'));
-$table->set_column_filter(3, 'SurveyUtil::modify_filter');
-$table->display();
-*/

+ 15 - 11
main/survey/survey_invite.php

@@ -17,7 +17,7 @@
 $language_file = 'survey';
 
 // Including the global initialization file
-require '../inc/global.inc.php';
+require_once '../inc/global.inc.php';
 
 // Including additional libraries
 require_once 'survey.lib.php';
@@ -57,11 +57,11 @@ if (api_strlen(strip_tags($survey_data['title'])) > 40) {
 }
 
 // Breadcrumbs
-$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
+$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
 if (api_is_course_admin()) {
-	$interbreadcrumb[] = array('url' => 'survey.php?survey_id='.$survey_id, 'name' => $urlname);
+	$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id, 'name' => $urlname);
 } else {
-	$interbreadcrumb[] = array('url' => 'survey_invite.php?survey_id='.$survey_id, 'name' => $urlname);
+	$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_invite.php?survey_id='.$survey_id, 'name' => $urlname);
 }
 $tool_name = get_lang('SurveyPublication');
 
@@ -86,20 +86,24 @@ if (Database::num_rows($result) > 1) {
 
 // Invited / answered message
 if ($survey_data['invited'] > 0 && !isset($_POST['submit'])) {
-	$message  = '<a href="survey_invitation.php?view=answered&amp;survey_id='.$survey_data['survey_id'].'">'.$survey_data['answered'].'</a> ';
+	$message  = '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=answered&amp;survey_id='.$survey_data['survey_id'].'">'.$survey_data['answered'].'</a> ';
 	$message .= get_lang('HaveAnswered').' ';
-	$message .= '<a href="survey_invitation.php?view=invited&amp;survey_id='.$survey_data['survey_id'].'">'.$survey_data['invited'].'</a> ';
+	$message .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=invited&amp;survey_id='.$survey_data['survey_id'].'">'.$survey_data['invited'].'</a> ';
 	$message .= get_lang('WereInvited');
 	Display::display_normal_message($message, false);
 }
 
 // Building the form for publishing the survey
 $form = new FormValidator('publish_form', 'post', api_get_self().'?survey_id='.$survey_id.'&'.api_get_cidReq());
-
 $form->addElement('header', '', $tool_name);
 
 // Course users
-$complete_user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), api_get_session_id(), '', api_sort_by_first_name() ? 'ORDER BY firstname' : 'ORDER BY lastname');
+$complete_user_list = CourseManager::get_user_list_from_course_code(
+    api_get_course_id(),
+    api_get_session_id(),
+    '',
+    api_sort_by_first_name() ? 'ORDER BY firstname' : 'ORDER BY lastname'
+);
 $possible_users = array();
 foreach ($complete_user_list as & $user) {
 	$possible_users[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']);
@@ -208,9 +212,9 @@ if ($form->validate()) {
 	$row = Database::fetch_array($result);
 	$total_invited = $row['invited'];
     if ($total_invited > 0) {
-    	$message  = '<a href="survey_invitation.php?view=answered&amp;survey_id='.$survey_data['survey_id'].'">'.$survey_data['answered'].'</a> ';
+    	$message  = '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=answered&amp;survey_id='.$survey_data['survey_id'].'">'.$survey_data['answered'].'</a> ';
     	$message .= get_lang('HaveAnswered').' ';
-    	$message .= '<a href="survey_invitation.php?view=invited&amp;survey_id='.$survey_data['survey_id'].'">'.$total_invited.'</a> ';
+    	$message .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=invited&amp;survey_id='.$survey_data['survey_id'].'">'.$total_invited.'</a> ';
     	$message .= get_lang('WereInvited');
     	Display::display_normal_message($message, false);
     	Display::display_confirmation_message($total_count.' '.get_lang('InvitationsSend'));
@@ -231,4 +235,4 @@ if ($form->validate()) {
 	$form->setDefaults($defaults);
     $form->display();
 }
-Display :: display_footer();
+Display :: display_footer();

+ 7 - 7
main/survey/survey_list.php

@@ -49,7 +49,7 @@ $table_user 			= Database :: get_main_table(TABLE_MAIN_USER);
 
 // Language variables
 if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
-    $interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
+    $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
     $tool_name = get_lang('SearchASurvey');
 } else {
     $tool_name = get_lang('SurveyList');
@@ -81,16 +81,17 @@ if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['survey
 
     $return = survey_manager :: delete_survey($_GET['survey_id']);
     if ($return) {
-        Display :: display_confirmation_message(get_lang('SurveyDeleted'), false);
+        Display::display_confirmation_message(get_lang('SurveyDeleted'), false);
     } else {
-        Display :: display_error_message(get_lang('ErrorOccurred'), false);
+        Display::display_error_message(get_lang('ErrorOccurred'), false);
     }
 }
 
 if (isset($_GET['action']) && $_GET['action'] == 'empty') {
     $mysession = api_get_session_id();
-    if ( $mysession != 0 ) {
-        if (!((api_is_course_coach() || api_is_platform_admin()) && api_is_element_in_the_session(TOOL_SURVEY,intval($_GET['survey_id'])))) {
+    if ($mysession != 0) {
+        if (!((api_is_course_coach() || api_is_platform_admin()) &&
+            api_is_element_in_the_session(TOOL_SURVEY, $_GET['survey_id']))) {
             // The coach can't empty a survey not belonging to his session
             api_not_allowed();
             exit;
@@ -131,9 +132,8 @@ if (isset($_POST['action']) && $_POST['action']) {
 echo '<div class="actions">';
 if (!api_is_course_coach() || $extend_rights_for_coachs == 'true') {
 	// Action links
-	echo '<a href="create_new_survey.php?'.api_get_cidreq().'&amp;action=add">'.Display::return_icon('new_survey.png', get_lang('CreateNewSurvey'),'',ICON_SIZE_MEDIUM).'</a> ';
+	echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/create_new_survey.php?'.api_get_cidreq().'&amp;action=add">'.Display::return_icon('new_survey.png', get_lang('CreateNewSurvey'),'',ICON_SIZE_MEDIUM).'</a> ';
 }
-//echo '<a href="survey_all_courses.php">'.get_lang('CreateExistingSurvey').'</a> ';
 echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;search=advanced">'.Display::return_icon('search.png', get_lang('Search'),'',ICON_SIZE_MEDIUM).'</a>';
 echo '</div>';
 

この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません