Completed
Pull Request — 1.11.x (#1339)
by José
73:57 queued 34:43
created
main/inc/lib/javascript/svgedit/extensions/imagelib/index.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -23,22 +23,22 @@  discard block
 block discarded – undo
23 23
 $array_to_search = is_array($docs_and_folders) ? $docs_and_folders : array();
24 24
 
25 25
 if (count($array_to_search) > 0) {
26
-	while (list($key) = each($array_to_search)) {
27
-		$all_files[] = basename($array_to_search[$key]['path']);
28
-	}
26
+    while (list($key) = each($array_to_search)) {
27
+        $all_files[] = basename($array_to_search[$key]['path']);
28
+    }
29 29
 }
30 30
 
31 31
 //get all svg and png files
32 32
 $accepted_extensions = array('.svg', '.png');
33 33
 
34 34
 if (is_array($all_files) && count($all_files) > 0) {
35
-	foreach ($all_files as & $file) {
36
-		$slideshow_extension = strrchr($file, '.');
37
-		$slideshow_extension = strtolower($slideshow_extension);
38
-		if (in_array($slideshow_extension, $accepted_extensions)) {
39
-			$png_svg_files[] =$file;
40
-		}
41
-	}
35
+    foreach ($all_files as & $file) {
36
+        $slideshow_extension = strrchr($file, '.');
37
+        $slideshow_extension = strtolower($slideshow_extension);
38
+        if (in_array($slideshow_extension, $accepted_extensions)) {
39
+            $png_svg_files[] =$file;
40
+        }
41
+    }
42 42
 }
43 43
 
44 44
 $disk_path = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/document/images/gallery/';
@@ -57,24 +57,24 @@  discard block
 block discarded – undo
57 57
 <?php
58 58
 echo '<h2>'.get_lang('Course').': '.$course_info['name'].'</h2>';
59 59
 if (!empty($png_svg_files)) {
60
-	echo '<h3>'.get_lang('SelectSVGEditImage').'</h3>';
61
-	echo '<ul>';
62
-	foreach($png_svg_files as $filename) {
63
-		$image=$disk_path.$filename;
64
-
65
-		if (strpos($filename, "svg")){
66
-			$new_sizes['width'] = 60;
67
-			$new_sizes['height'] = 60;
68
-		}
69
-		else {
70
-			$new_sizes = api_resize_image($image, 60, 60);
71
-		}
72
-
73
-		echo '<li style="display:inline; padding:8px;"><a href="'.$web_path.$filename.'" alt "'.$filename.'" title="'.$filename.'"><img src="'.$web_path.$filename.'" width="'.$new_sizes['width'].'" height="'.$new_sizes['height'].'" border="0"></a></li>';
74
-	}
75
-	echo '</ul>';
60
+    echo '<h3>'.get_lang('SelectSVGEditImage').'</h3>';
61
+    echo '<ul>';
62
+    foreach($png_svg_files as $filename) {
63
+        $image=$disk_path.$filename;
64
+
65
+        if (strpos($filename, "svg")){
66
+            $new_sizes['width'] = 60;
67
+            $new_sizes['height'] = 60;
68
+        }
69
+        else {
70
+            $new_sizes = api_resize_image($image, 60, 60);
71
+        }
72
+
73
+        echo '<li style="display:inline; padding:8px;"><a href="'.$web_path.$filename.'" alt "'.$filename.'" title="'.$filename.'"><img src="'.$web_path.$filename.'" width="'.$new_sizes['width'].'" height="'.$new_sizes['height'].'" border="0"></a></li>';
74
+    }
75
+    echo '</ul>';
76 76
 } else {
77
-	Display::display_warning_message(get_lang('NoSVGImagesInImagesGalleryPath'));
77
+    Display::display_warning_message(get_lang('NoSVGImagesInImagesGalleryPath'));
78 78
 }
79 79
 ?>
80 80
 </body>
Please login to merge, or discard this patch.
main/document/create_draw.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -46,59 +46,59 @@  discard block
 block discarded – undo
46 46
 // Please, do not modify this dirname formatting
47 47
 
48 48
 if (strstr($dir, '..')) {
49
-	$dir = '/';
49
+    $dir = '/';
50 50
 }
51 51
 
52 52
 if ($dir[0] == '.') {
53
-	$dir = substr($dir, 1);
53
+    $dir = substr($dir, 1);
54 54
 }
55 55
 
56 56
 if ($dir[0] != '/') {
57
-	$dir = '/'.$dir;
57
+    $dir = '/'.$dir;
58 58
 }
59 59
 
60 60
 if ($dir[strlen($dir) - 1] != '/') {
61
-	$dir .= '/';
61
+    $dir .= '/';
62 62
 }
63 63
 
64 64
 $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir;
65 65
 
66 66
 if (!is_dir($filepath)) {
67
-	$filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
68
-	$dir = '/';
67
+    $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
68
+    $dir = '/';
69 69
 }
70 70
 
71 71
 $groupId = api_get_group_id();
72 72
 
73 73
 if (!empty($groupId)) {
74
-	$interbreadcrumb[] = array (
74
+    $interbreadcrumb[] = array (
75 75
         "url" => "../group/group_space.php?".api_get_cidreq(),
76 76
         "name" => get_lang('GroupSpace')
77 77
     );
78
-	$noPHP_SELF = true;
79
-	$group = GroupManager :: get_group_properties($groupId);
80
-	$path = explode('/', $dir);
81
-	if ('/'.$path[1] != $group['directory']) {
82
-		api_not_allowed(true);
83
-	}
78
+    $noPHP_SELF = true;
79
+    $group = GroupManager :: get_group_properties($groupId);
80
+    $path = explode('/', $dir);
81
+    if ('/'.$path[1] != $group['directory']) {
82
+        api_not_allowed(true);
83
+    }
84 84
 }
85 85
 
86 86
 $interbreadcrumb[] = array(
87
-	"url" => "./document.php?".api_get_cidreq(),
88
-	"name" => get_lang('Documents')
87
+    "url" => "./document.php?".api_get_cidreq(),
88
+    "name" => get_lang('Documents')
89 89
 );
90 90
 
91 91
 if (!$is_allowed_in_course) {
92
-	api_not_allowed(true);
92
+    api_not_allowed(true);
93 93
 }
94 94
 
95 95
 if (!($is_allowed_to_edit || $_SESSION['group_member_with_upload_rights'] ||
96
-	DocumentManager::is_my_shared_folder(
97
-		api_get_user_id(),
98
-		Security::remove_XSS($dir),
99
-		api_get_session_id()))
96
+    DocumentManager::is_my_shared_folder(
97
+        api_get_user_id(),
98
+        Security::remove_XSS($dir),
99
+        api_get_session_id()))
100 100
 ) {
101
-	api_not_allowed(true);
101
+    api_not_allowed(true);
102 102
 }
103 103
 
104 104
 
@@ -106,10 +106,10 @@  discard block
 block discarded – undo
106 106
 Event::event_access_tool(TOOL_DOCUMENT);
107 107
 $display_dir = $dir;
108 108
 if (isset ($group)) {
109
-	$display_dir = explode('/', $dir);
110
-	unset ($display_dir[0]);
111
-	unset ($display_dir[1]);
112
-	$display_dir = implode('/', $display_dir);
109
+    $display_dir = explode('/', $dir);
110
+    unset ($display_dir[0]);
111
+    unset ($display_dir[1]);
112
+    $display_dir = implode('/', $display_dir);
113 113
 }
114 114
 
115 115
 // Interbreadcrumb for the current directory root path
@@ -123,9 +123,9 @@  discard block
 block discarded – undo
123 123
 } else {
124 124
     foreach ($document_data['parents'] as $document_sub_data) {
125 125
         $interbreadcrumb[] = array(
126
-			'url' => $document_sub_data['document_url'],
127
-			'name' => $document_sub_data['title']
128
-		);
126
+            'url' => $document_sub_data['document_url'],
127
+            'name' => $document_sub_data['title']
128
+        );
129 129
     }
130 130
 }
131 131
 Display :: display_header($nameTools, 'Doc');
@@ -137,13 +137,13 @@  discard block
 block discarded – undo
137 137
 
138 138
 if (api_browser_support('svg')) {
139 139
 
140
-	//automatic loading the course language
141
-	$svgedit_code_translation_table = array('' => 'en', 'pt' => 'pt-Pt', 'sr' => 'sr_latn');
142
-	$langsvgedit = api_get_language_isocode();
143
-	$langsvgedit = isset($svgedit_code_translation_table[$langsvgedit]) ? $svgedit_code_translation_table[$langsvgedit] : $langsvgedit;
144
-	$langsvgedit = file_exists(api_get_path(LIBRARY_PATH).'javascript/svgedit/locale/lang.'.$langsvgedit.'.js') ? $langsvgedit : 'en';
145
-	$svg_url= api_get_path(WEB_LIBRARY_PATH).'javascript/svgedit/svg-editor.php?lang='.$langsvgedit;
146
-	?>
140
+    //automatic loading the course language
141
+    $svgedit_code_translation_table = array('' => 'en', 'pt' => 'pt-Pt', 'sr' => 'sr_latn');
142
+    $langsvgedit = api_get_language_isocode();
143
+    $langsvgedit = isset($svgedit_code_translation_table[$langsvgedit]) ? $svgedit_code_translation_table[$langsvgedit] : $langsvgedit;
144
+    $langsvgedit = file_exists(api_get_path(LIBRARY_PATH).'javascript/svgedit/locale/lang.'.$langsvgedit.'.js') ? $langsvgedit : 'en';
145
+    $svg_url= api_get_path(WEB_LIBRARY_PATH).'javascript/svgedit/svg-editor.php?lang='.$langsvgedit;
146
+    ?>
147 147
 	<script>
148 148
 		document.write ('<iframe id="frame" frameborder="0" scrolling="no" src="<?php echo  $svg_url; ?>" width="100%" height="100%"><noframes><p>Sorry, your browser does not handle frames</p></noframes></iframe>');
149 149
         function resizeIframe() {
@@ -161,10 +161,10 @@  discard block
 block discarded – undo
161 161
 
162 162
     <?php
163 163
     echo '<noscript>';
164
-	echo '<iframe style="height: 550px; width: 100%;" scrolling="no" frameborder="0" src="'.$svg_url.'"><noframes><p>Sorry, your browser does not handle frames</p></noframes></iframe>';
165
-	echo '</noscript>';
164
+    echo '<iframe style="height: 550px; width: 100%;" scrolling="no" frameborder="0" src="'.$svg_url.'"><noframes><p>Sorry, your browser does not handle frames</p></noframes></iframe>';
165
+    echo '</noscript>';
166 166
 } else {
167
-	Display::display_error_message(get_lang('BrowserDontSupportsSVG'));
167
+    Display::display_error_message(get_lang('BrowserDontSupportsSVG'));
168 168
 }
169 169
 
170 170
 Display :: display_footer();
Please login to merge, or discard this patch.
main/document/edit_draw.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 //path for svg-edit save
44 44
 $_SESSION['draw_dir'] = Security::remove_XSS($dir);
45 45
 if ($_SESSION['draw_dir'] == '/') {
46
-	$_SESSION['draw_dir'] = '';
46
+    $_SESSION['draw_dir'] = '';
47 47
 }
48 48
 $_SESSION['draw_file'] = basename(Security::remove_XSS($file_path));
49 49
 $get_file = Security::remove_XSS($file_path);
@@ -59,26 +59,26 @@  discard block
 block discarded – undo
59 59
 /* Please, do not modify this dirname formatting */
60 60
 
61 61
 if (strstr($dir, '..')) {
62
-	$dir = '/';
62
+    $dir = '/';
63 63
 }
64 64
 
65 65
 if ($dir[0] == '.') {
66
-	$dir = substr($dir, 1);
66
+    $dir = substr($dir, 1);
67 67
 }
68 68
 
69 69
 if ($dir[0] != '/') {
70
-	$dir = '/'.$dir;
70
+    $dir = '/'.$dir;
71 71
 }
72 72
 
73 73
 if ($dir[strlen($dir) - 1] != '/') {
74
-	$dir .= '/';
74
+    $dir .= '/';
75 75
 }
76 76
 
77 77
 $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir;
78 78
 
79 79
 if (!is_dir($filepath)) {
80
-	$filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
81
-	$dir = '/';
80
+    $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
81
+    $dir = '/';
82 82
 }
83 83
 
84 84
 //groups //TODO:clean
@@ -87,8 +87,8 @@  discard block
 block discarded – undo
87 87
         'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
88 88
         'name' => get_lang('GroupSpace'),
89 89
     );
90
-	$group_document = true;
91
-	$noPHP_SELF = true;
90
+    $group_document = true;
91
+    $noPHP_SELF = true;
92 92
 }
93 93
 
94 94
 $is_certificate_mode = DocumentManager::is_certificate_mode($dir);
@@ -114,10 +114,10 @@  discard block
 block discarded – undo
114 114
 }
115 115
 
116 116
 $is_allowedToEdit = api_is_allowed_to_edit(null, true) || $_SESSION['group_member_with_upload_rights'] ||
117
-	DocumentManager::is_my_shared_folder(api_get_user_id(), $dir, $current_session_id);
117
+    DocumentManager::is_my_shared_folder(api_get_user_id(), $dir, $current_session_id);
118 118
 
119 119
 if (!$is_allowedToEdit) {
120
-	api_not_allowed(true);
120
+    api_not_allowed(true);
121 121
 }
122 122
 
123 123
 Event::event_access_tool(TOOL_DOCUMENT);
@@ -131,13 +131,13 @@  discard block
 block discarded – undo
131 131
 echo '</div>';
132 132
 
133 133
 if (api_browser_support('svg')) {
134
-	//automatic loading the course language
135
-	$svgedit_code_translation_table = array('' => 'en', 'pt' => 'pt-Pt', 'sr' => 'sr_latn');
136
-	$langsvgedit  = api_get_language_isocode();
137
-	$langsvgedit = isset($svgedit_code_translation_table[$langsvgedit]) ? $svgedit_code_translation_table[$langsvgedit] : $langsvgedit;
138
-	$langsvgedit = file_exists(api_get_path(LIBRARY_PATH).'javascript/svgedit/locale/lang.'.$langsvgedit.'.js') ? $langsvgedit : 'en';
139
-	$svg_url = api_get_path(WEB_LIBRARY_PATH).'javascript/svgedit/svg-editor.php?url=../../../../../courses/'.$courseDir.$dir.$file.'&lang='.$langsvgedit;
140
-	?>
134
+    //automatic loading the course language
135
+    $svgedit_code_translation_table = array('' => 'en', 'pt' => 'pt-Pt', 'sr' => 'sr_latn');
136
+    $langsvgedit  = api_get_language_isocode();
137
+    $langsvgedit = isset($svgedit_code_translation_table[$langsvgedit]) ? $svgedit_code_translation_table[$langsvgedit] : $langsvgedit;
138
+    $langsvgedit = file_exists(api_get_path(LIBRARY_PATH).'javascript/svgedit/locale/lang.'.$langsvgedit.'.js') ? $langsvgedit : 'en';
139
+    $svg_url = api_get_path(WEB_LIBRARY_PATH).'javascript/svgedit/svg-editor.php?url=../../../../../courses/'.$courseDir.$dir.$file.'&lang='.$langsvgedit;
140
+    ?>
141 141
 	<script>
142 142
 	document.write ('<iframe id="frame" frameborder="0" scrolling="no" src="<?php echo  $svg_url; ?>" width="100%" height="100%"><noframes><p>Sorry, your browser does not handle frames</p></noframes></iframe>');
143 143
 	function resizeIframe() {
@@ -155,9 +155,9 @@  discard block
 block discarded – undo
155 155
 
156 156
     <?php
157 157
     echo '<noscript>';
158
-	echo '<iframe style="height: 550px; width: 100%;" scrolling="no" frameborder="0\' src="'.$svg_url.'"<noframes><p>Sorry, your browser does not handle frames</p></noframes></iframe>';
159
-	echo '</noscript>';
158
+    echo '<iframe style="height: 550px; width: 100%;" scrolling="no" frameborder="0\' src="'.$svg_url.'"<noframes><p>Sorry, your browser does not handle frames</p></noframes></iframe>';
159
+    echo '</noscript>';
160 160
 } else {
161
-	Display::display_error_message(get_lang('BrowserDontSupportsSVG'));
161
+    Display::display_error_message(get_lang('BrowserDontSupportsSVG'));
162 162
 }
163 163
 Display::display_footer();
Please login to merge, or discard this patch.
main/inc/lib/exercise_show_functions.lib.php 1 patch
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -17,25 +17,25 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class ExerciseShowFunctions
19 19
 {
20
-	/**
21
-	 * Shows the answer to a fill-in-the-blanks question, as HTML
20
+    /**
21
+     * Shows the answer to a fill-in-the-blanks question, as HTML
22 22
      * @param int $feedbackType
23
-	 * @param string    $answer
24
-	 * @param int $id       Exercise ID
25
-	 * @param int $questionId      Question ID
23
+     * @param string    $answer
24
+     * @param int $id       Exercise ID
25
+     * @param int $questionId      Question ID
26 26
      * @param int $resultsDisabled
27 27
      * @param string $originalStudentAnswer
28 28
      *
29
-	 * @return void
30
-	 */
31
-	public static function display_fill_in_blanks_answer(
32
-	    $feedbackType,
33
-	    $answer,
34
-	    $id,
35
-	    $questionId,
36
-	    $resultsDisabled,
37
-	    $originalStudentAnswer = '',
38
-	    $showTotalScoreAndUserChoices
29
+     * @return void
30
+     */
31
+    public static function display_fill_in_blanks_answer(
32
+        $feedbackType,
33
+        $answer,
34
+        $id,
35
+        $questionId,
36
+        $resultsDisabled,
37
+        $originalStudentAnswer = '',
38
+        $showTotalScoreAndUserChoices
39 39
     ) {
40 40
         $answerHTML = FillBlanks::getHtmlDisplayForAnswer($answer, $resultsDisabled, $showTotalScoreAndUserChoices);
41 41
         if (strpos($originalStudentAnswer, 'font color') !== false) {
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
             </tr>
65 65
         <?php
66 66
         }
67
-	}
67
+    }
68 68
 
69 69
     /**
70 70
      * Shows the answer to a calculated question, as HTML
@@ -105,20 +105,20 @@  discard block
 block discarded – undo
105 105
         }
106 106
     }
107 107
 
108
-	/**
109
-	 * Shows the answer to a free-answer question, as HTML
110
-	 * @param string    Answer text
111
-	 * @param int       Exercise ID
112
-	 * @param int       Question ID
113
-	 * @return void
114
-	 */
115
-	public static function display_free_answer(
116
-	    $feedback_type,
117
-	    $answer,
118
-	    $exe_id,
119
-	    $questionId,
120
-	    $questionScore = null,
121
-	    $results_disabled = 0
108
+    /**
109
+     * Shows the answer to a free-answer question, as HTML
110
+     * @param string    Answer text
111
+     * @param int       Exercise ID
112
+     * @param int       Question ID
113
+     * @return void
114
+     */
115
+    public static function display_free_answer(
116
+        $feedback_type,
117
+        $answer,
118
+        $exe_id,
119
+        $questionId,
120
+        $questionScore = null,
121
+        $results_disabled = 0
122 122
     ) {
123 123
         $comments = Event::get_comments($exe_id, $questionId);
124 124
 
@@ -136,17 +136,17 @@  discard block
 block discarded – undo
136 136
                 echo '</tr>';
137 137
             }
138 138
         }
139
-	}
139
+    }
140 140
 
141 141
     /**
142
-    * @param $feedback_type
143
-    * @param $answer
144
-    * @param $id
145
-    * @param $questionId
146
-    * @param null $nano
147
-    * @param int $results_disabled
142
+     * @param $feedback_type
143
+     * @param $answer
144
+     * @param $id
145
+     * @param $questionId
146
+     * @param null $nano
147
+     * @param int $results_disabled
148 148
      */
149
-	public static function display_oral_expression_answer($feedback_type, $answer, $id, $questionId, $fileUrl = null, $results_disabled = 0)
149
+    public static function display_oral_expression_answer($feedback_type, $answer, $id, $questionId, $fileUrl = null, $results_disabled = 0)
150 150
     {
151 151
         if (isset($fileUrl)) {
152 152
             echo '
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
         }
185 185
     }
186 186
 
187
-	/**
188
-	 * Displays the answer to a hotspot question
187
+    /**
188
+     * Displays the answer to a hotspot question
189 189
      * @param int $feedback_type
190 190
      * @param int $answerId
191 191
      * @param string $answer
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
      * @param int $resultsDisabled
195 195
      * @param int $orderColor
196 196
      */
197
-	public static function display_hotspot_answer(
197
+    public static function display_hotspot_answer(
198 198
         $feedback_type,
199 199
         $answerId,
200 200
         $answer,
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
             }
218 218
         }
219 219
 
220
-		$hotspot_colors = array(
220
+        $hotspot_colors = array(
221 221
             "", // $i starts from 1 on next loop (ugly fix)
222 222
             "#4271B5",
223 223
             "#FE8E16",
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
             "#F7BDE2"
235 235
         );
236 236
 
237
-		?>
237
+        ?>
238 238
 		<table class="data_table">
239 239
 		<tr>
240 240
             <td class="text-center" width="5%">
@@ -246,10 +246,10 @@  discard block
 block discarded – undo
246 246
 			<td class="text-left" width="10%">
247 247
 				<?php
248 248
                 if (!$hide_expected_answer) {
249
-    				$my_choice = $studentChoice ? get_lang('Correct') : get_lang('Fault');
250
-    				echo $my_choice;
249
+                    $my_choice = $studentChoice ? get_lang('Correct') : get_lang('Fault');
250
+                    echo $my_choice;
251 251
                 }
252
-				?>
252
+                ?>
253 253
 			</td>
254 254
 			<?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
255 255
 			<td class="text-left" width="60%">
@@ -257,29 +257,29 @@  discard block
 block discarded – undo
257 257
                 if ($studentChoice) {
258 258
                     echo '<span style="font-weight: bold; color: #008000;">'.nl2br($answerComment).'</span>';
259 259
                 }
260
-				?>
260
+                ?>
261 261
 			</td>
262 262
 			<?php } else { ?>
263 263
 				<td class="text-left" width="60%">&nbsp;</td>
264 264
 			<?php } ?>
265 265
 		</tr>
266 266
 		<?php
267
-	}
268
-
269
-	/**
270
-	 * Display the answers to a multiple choice question
271
-	 * @param int $feedback_type Feedback type
272
-	 * @param integer Answer type
273
-	 * @param integer Student choice
274
-	 * @param string  Textual answer
275
-	 * @param string  Comment on answer
276
-	 * @param string  Correct answer comment
277
-	 * @param integer Exercise ID
278
-	 * @param integer Question ID
279
-	 * @param boolean Whether to show the answer comment or not
280
-	 * @return void
281
-	 */
282
-	public static function display_unique_or_multiple_answer(
267
+    }
268
+
269
+    /**
270
+     * Display the answers to a multiple choice question
271
+     * @param int $feedback_type Feedback type
272
+     * @param integer Answer type
273
+     * @param integer Student choice
274
+     * @param string  Textual answer
275
+     * @param string  Comment on answer
276
+     * @param string  Correct answer comment
277
+     * @param integer Exercise ID
278
+     * @param integer Question ID
279
+     * @param boolean Whether to show the answer comment or not
280
+     * @return void
281
+     */
282
+    public static function display_unique_or_multiple_answer(
283 283
         $feedback_type,
284 284
         $answerType,
285 285
         $studentChoice,
@@ -307,14 +307,14 @@  discard block
 block discarded – undo
307 307
         }
308 308
 
309 309
         $icon = in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION)) ? 'radio':'checkbox';
310
-		$icon .= $studentChoice?'_on':'_off';
311
-		$icon .= '.gif';
310
+        $icon .= $studentChoice?'_on':'_off';
311
+        $icon .= '.gif';
312 312
 
313
-		$iconAnswer = in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION)) ? 'radio':'checkbox';
314
-		$iconAnswer .= $answerCorrect?'_on':'_off';
315
-		$iconAnswer .= '.gif';
313
+        $iconAnswer = in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION)) ? 'radio':'checkbox';
314
+        $iconAnswer .= $answerCorrect?'_on':'_off';
315
+        $iconAnswer .= '.gif';
316 316
 
317
-		?>
317
+        ?>
318 318
 		<tr>
319 319
 		<td width="5%">
320 320
 			<?php echo Display::return_icon($icon); ?>
@@ -328,39 +328,39 @@  discard block
 block discarded – undo
328 328
 		</td>
329 329
 		<td width="40%">
330 330
 			<?php
331
-			echo $answer;
332
-			?>
331
+            echo $answer;
332
+            ?>
333 333
 		</td>
334 334
 
335 335
 		<?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
336 336
 		<td width="20%">
337 337
 			<?php
338 338
             if ($studentChoice) {
339
-				if ($answerCorrect) {
339
+                if ($answerCorrect) {
340 340
                     $color = 'green';
341
-					//echo '<span style="font-weight: bold; color: #008000;">'.nl2br($answerComment).'</span>';
342
-				} else {
341
+                    //echo '<span style="font-weight: bold; color: #008000;">'.nl2br($answerComment).'</span>';
342
+                } else {
343 343
                     $color = 'black';
344 344
                     //echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br($answerComment).'</span>';
345
-				}
346
-				if ($hide_expected_answer) {
347
-				    $color = '';
348
-				}
345
+                }
346
+                if ($hide_expected_answer) {
347
+                    $color = '';
348
+                }
349 349
                 echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
350
-			}
351
-			?>
350
+            }
351
+            ?>
352 352
 		</td>
353 353
 			<?php
354
-		    if ($ans==1) {
355
-		        $comm = Event::get_comments($id,$questionId);
356
-			}
357
-		    ?>
354
+            if ($ans==1) {
355
+                $comm = Event::get_comments($id,$questionId);
356
+            }
357
+            ?>
358 358
 		 <?php } else { ?>
359 359
 			<td>&nbsp;</td>
360 360
 		<?php } ?>
361 361
 		</tr>
362 362
 		<?php
363
-	}
363
+    }
364 364
 
365 365
     /**
366 366
      * Display the answers to a multiple choice question
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
         if (isset($new_options[$studentChoice])) {
414 414
             echo get_lang($new_options[$studentChoice]['name']);
415 415
         } else {
416
-        	echo '-';
416
+            echo '-';
417 417
         }
418 418
 
419 419
         ?>
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
         <td width="5%">
422 422
         <?php
423 423
 
424
-		//Expected choice
424
+        //Expected choice
425 425
         if (!$hide_expected_answer) {
426 426
             if (isset($new_options[$answerCorrect])) {
427 427
                 echo get_lang($new_options[$answerCorrect]['name']);
@@ -447,8 +447,8 @@  discard block
 block discarded – undo
447 447
                 }
448 448
 
449 449
                 if ($hide_expected_answer) {
450
-				    $color = '';
451
-				}
450
+                    $color = '';
451
+                }
452 452
 
453 453
                 echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
454 454
             }
@@ -466,19 +466,19 @@  discard block
 block discarded – undo
466 466
         <?php
467 467
     }
468 468
 
469
-     /**
470
-     * Display the answers to a multiple choice question
471
-     *
472
-     * @param integer Answer type
473
-     * @param integer Student choice
474
-     * @param string  Textual answer
475
-     * @param string  Comment on answer
476
-     * @param string  Correct answer comment
477
-     * @param integer Exercise ID
478
-     * @param integer Question ID
479
-     * @param boolean Whether to show the answer comment or not
480
-     * @return void
481
-     */
469
+        /**
470
+         * Display the answers to a multiple choice question
471
+         *
472
+         * @param integer Answer type
473
+         * @param integer Student choice
474
+         * @param string  Textual answer
475
+         * @param string  Comment on answer
476
+         * @param string  Correct answer comment
477
+         * @param integer Exercise ID
478
+         * @param integer Question ID
479
+         * @param boolean Whether to show the answer comment or not
480
+         * @return void
481
+         */
482 482
     public static function display_multiple_answer_combination_true_false(
483 483
         $feedback_type,
484 484
         $answerType,
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
         <tr>
510 510
         <td width="5%">
511 511
         <?php
512
-		//Your choice
512
+        //Your choice
513 513
         $question = new MultipleAnswerCombinationTrueFalse();
514 514
         if (isset($question->options[$studentChoice])) {
515 515
             echo $question->options[$studentChoice];
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
         </td>
521 521
         <td width="5%">
522 522
         <?php
523
-		//Expected choice
523
+        //Expected choice
524 524
         if (!$hide_expected_answer) {
525 525
             if (isset($question->options[$answerCorrect])) {
526 526
                 echo $question->options[$answerCorrect];
@@ -545,14 +545,14 @@  discard block
 block discarded – undo
545 545
             <?php
546 546
             //@todo replace this harcoded value
547 547
             if ($studentChoice) {
548
-                 $color = "black";
548
+                    $color = "black";
549 549
                 if ($studentChoice == $answerCorrect) {
550 550
                     $color = "green";
551 551
                 }
552
-            	//echo '<span style="font-weight: bold; color: #000;">'.nl2br($answerComment).'</span>';
552
+                //echo '<span style="font-weight: bold; color: #000;">'.nl2br($answerComment).'</span>';
553 553
                 if ($hide_expected_answer) {
554 554
                     $color = '';
555
-				}
555
+                }
556 556
                 echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
557 557
             }
558 558
             ?>
Please login to merge, or discard this patch.
main/gradebook/lib/be/evaluation.class.php 1 patch
Indentation   +748 added lines, -748 removed lines patch added patch discarded remove patch
@@ -9,367 +9,367 @@  discard block
 block discarded – undo
9 9
  */
10 10
 class Evaluation implements GradebookItem
11 11
 {
12
-	private $id;
13
-	private $name;
14
-	private $description;
15
-	private $user_id;
16
-	private $course_code;
17
-	/** @var Category */
18
-	private $category;
19
-	private $created_at;
20
-	private $weight;
21
-	private $eval_max;
22
-	private $visible;
23
-	private $sessionId;
24
-	public $studentList;
25
-
26
-	/**
27
-	 * Construct
28
-	 */
29
-	public function __construct()
30
-	{
31
-	}
32
-
33
-	/**
34
-	 * @return Category
35
-	 */
36
-	public function getCategory()
37
-	{
38
-		return $this->category;
39
-	}
40
-
41
-	/**
42
-	 * @param Category $category
43
-	 */
44
-	public function setCategory($category)
45
-	{
46
-		$this->category = $category;
47
-	}
48
-
49
-	/**
50
-	 * @return int
51
-	 */
52
-	public function get_category_id()
53
-	{
54
-		return $this->category->get_id();
55
-	}
56
-
57
-	/**
58
-	 * @param int $category_id
59
-	 */
60
-	public function set_category_id($category_id)
61
-	{
62
-		$categories = Category::load($category_id);
63
-		if (isset($categories[0])) {
64
-			$this->setCategory($categories[0]);
65
-		}
66
-	}
67
-
68
-	/**
69
-	 * @return int
70
-	 */
71
-	public function get_id()
72
-	{
73
-		return $this->id;
74
-	}
75
-
76
-	/**
77
-	 * @return string
78
-	 */
79
-	public function get_name()
80
-	{
81
-		return $this->name;
82
-	}
83
-
84
-	/**
85
-	 * @return string
86
-	 */
87
-	public function get_description()
88
-	{
89
-		return $this->description;
90
-	}
91
-
92
-	public function get_user_id()
93
-	{
94
-		return $this->user_id;
95
-	}
96
-
97
-	public function get_course_code()
98
-	{
99
-		return $this->course_code;
100
-	}
101
-
102
-	/**
103
-	 * @return int
104
-	 */
105
-	public function getSessionId()
106
-	{
107
-		return $this->sessionId;
108
-	}
109
-
110
-	/**
111
-	 * @param int $sessionId
112
-	 */
113
-	public function setSessionId($sessionId)
114
-	{
115
-		$this->sessionId = intval($sessionId);
116
-	}
117
-
118
-	public function get_date()
119
-	{
120
-		return $this->created_at;
121
-	}
122
-
123
-	public function get_weight()
124
-	{
125
-		return $this->weight;
126
-	}
127
-
128
-	public function get_max()
129
-	{
130
-		return $this->eval_max;
131
-	}
132
-
133
-	public function get_type()
134
-	{
135
-		return $this->type;
136
-	}
137
-
138
-	public function is_visible()
139
-	{
140
-		return $this->visible;
141
-	}
142
-
143
-	public function get_locked()
144
-	{
145
-		return $this->locked;
146
-	}
147
-
148
-	public function is_locked()
149
-	{
150
-		return isset($this->locked) && $this->locked == 1 ? true : false;
151
-	}
152
-
153
-	public function set_id($id)
154
-	{
155
-		$this->id = $id;
156
-	}
157
-
158
-	public function set_name($name)
159
-	{
160
-		$this->name = $name;
161
-	}
162
-
163
-	public function set_description($description)
164
-	{
165
-		$this->description = $description;
166
-	}
167
-
168
-	public function set_user_id($user_id)
169
-	{
170
-		$this->user_id = $user_id;
171
-	}
172
-
173
-	public function set_course_code($course_code)
174
-	{
175
-		$this->course_code = $course_code;
176
-	}
177
-
178
-	public function set_date($date)
179
-	{
180
-		$this->created_at = $date;
181
-	}
182
-
183
-	public function set_weight($weight)
184
-	{
185
-		$this->weight = $weight;
186
-	}
187
-
188
-	public function set_max($max)
189
-	{
190
-		$this->eval_max = $max;
191
-	}
192
-
193
-	public function set_visible($visible)
194
-	{
195
-		$this->visible = $visible;
196
-	}
197
-
198
-	public function set_type($type)
199
-	{
200
-		$this->type = $type;
201
-	}
202
-
203
-	public function set_locked($locked)
204
-	{
205
-		$this->locked = $locked;
206
-	}
207
-
208
-	/**
209
-	 * Retrieve evaluations and return them as an array of Evaluation objects
210
-	 * @param int $id evaluation id
211
-	 * @param int $user_id user id (evaluation owner)
212
-	 * @param string $course_code course code
213
-	 * @param int $category_id parent category
214
-	 * @param integer $visible visible
215
-	 */
216
-	public static function load(
217
-		$id = null,
218
-		$user_id = null,
219
-		$course_code = null,
220
-		$category_id = null,
221
-		$visible = null,
222
-		$locked = null
223
-	) {
224
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
225
-		$sql = 'SELECT * FROM '.$tbl_grade_evaluations;
226
-		$paramcount = 0;
227
-
228
-		if (isset ($id)) {
229
-			$sql.= ' WHERE id = '.intval($id);
230
-			$paramcount ++;
231
-		}
232
-
233
-		if (isset ($user_id)) {
234
-			if ($paramcount != 0) $sql .= ' AND';
235
-			else $sql .= ' WHERE';
236
-			$sql .= ' user_id = '.intval($user_id);
237
-			$paramcount ++;
238
-		}
239
-
240
-		if (isset ($course_code) && $course_code <> '-1') {
241
-			if ($paramcount != 0) $sql .= ' AND';
242
-			else $sql .= ' WHERE';
243
-			$sql .= " course_code = '".Database::escape_string($course_code)."'";
244
-			$paramcount ++;
245
-		}
246
-
247
-		if (isset ($category_id)) {
248
-			if ($paramcount != 0) $sql .= ' AND';
249
-			else $sql .= ' WHERE';
250
-			$sql .= ' category_id = '.intval($category_id);
251
-			$paramcount ++;
252
-		}
253
-
254
-		if (isset ($visible)) {
255
-			if ($paramcount != 0) $sql .= ' AND';
256
-			else $sql .= ' WHERE';
257
-			$sql .= ' visible = '.intval($visible);
258
-			$paramcount ++;
259
-		}
260
-
261
-		if (isset ($locked)) {
262
-			if ($paramcount != 0) $sql .= ' AND';
263
-			else $sql .= ' WHERE';
264
-			$sql .= ' locked = '.intval($locked);
265
-		}
266
-
267
-		$result = Database::query($sql);
268
-		$alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
269
-
270
-		return $alleval;
271
-	}
272
-
273
-
274
-
275
-	/**
276
-	 * @param array $result
277
-	 * @return array
278
-	 */
279
-	private static function create_evaluation_objects_from_sql_result($result)
280
-	{
281
-		$alleval = array();
282
-		if (Database::num_rows($result)) {
283
-			while ($data = Database::fetch_array($result)) {
284
-				$eval= new Evaluation();
285
-				$eval->set_id($data['id']);
286
-				$eval->set_name($data['name']);
287
-				$eval->set_description($data['description']);
288
-				$eval->set_user_id($data['user_id']);
289
-				$eval->set_course_code($data['course_code']);
290
-				$eval->set_category_id($data['category_id']);
291
-				$eval->set_date(api_get_local_time($data['created_at']));
292
-				$eval->set_weight($data['weight']);
293
-				$eval->set_max($data['max']);
294
-				$eval->set_visible($data['visible']);
295
-				$eval->set_type($data['type']);
296
-				$eval->set_locked($data['locked']);
297
-				$eval->setSessionId(api_get_session_id());
298
-
299
-				$alleval[] = $eval;
300
-			}
301
-		}
302
-
303
-		return $alleval;
304
-	}
305
-
306
-	/**
307
-	 * Insert this evaluation into the database
308
-	 */
309
-	public function add()
310
-	{
311
-		if (isset($this->name) &&
312
-			isset($this->user_id) &&
313
-			isset($this->weight) &&
314
-			isset ($this->eval_max) &&
315
-			isset($this->visible)
316
-		) {
317
-			$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
318
-
319
-			$sql = 'INSERT INTO '.$tbl_grade_evaluations
320
-				.' (name, user_id, weight, max, visible';
321
-			if (isset($this->description)) {
322
-				$sql .= ',description';
323
-			}
324
-			if (isset($this->course_code)) {
325
-				$sql .= ', course_code';
326
-			}
327
-			if (isset($this->category)) {
328
-				$sql .= ', category_id';
329
-			}
330
-			$sql .= ', created_at';
331
-			$sql .= ',type';
332
-			$sql .= ") VALUES ('".Database::escape_string($this->get_name())."'"
333
-				.','.intval($this->get_user_id())
334
-				.','.floatval($this->get_weight())
335
-				.','.intval($this->get_max())
336
-				.','.intval($this->is_visible());
337
-			if (isset($this->description)) {
338
-				$sql .= ",'".Database::escape_string($this->get_description())."'";
339
-			}
340
-			if (isset($this->course_code)) {
341
-				$sql .= ",'".Database::escape_string($this->get_course_code())."'";
342
-			}
343
-			if (isset($this->category)) {
344
-				$sql .= ','.intval($this->get_category_id());
345
-			}
346
-			if (empty($this->type)) {
347
-				$this->type = 'evaluation';
348
-			}
349
-			$sql .= ", '".api_get_utc_datetime()."'";
350
-			$sql .= ',\''.Database::escape_string($this->type).'\'';
351
-			$sql .= ")";
352
-
353
-			Database::query($sql);
354
-			$this->set_id(Database::insert_id());
355
-		} else {
356
-			die('Error in Evaluation add: required field empty');
357
-		}
358
-	}
359
-
360
-	/**
361
-	 * @param int $idevaluation
362
-	 */
363
-	public function add_evaluation_log($idevaluation)
364
-	{
365
-		if (!empty($idevaluation)) {
366
-			$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
367
-			$tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG);
368
-			$eval = new Evaluation();
369
-			$dateobject = $eval->load($idevaluation,null,null,null,null);
370
-			$arreval = get_object_vars($dateobject[0]);
371
-			if (!empty($arreval['id'])) {
372
-				$sql = 'SELECT weight from '.$tbl_grade_evaluations.'
12
+    private $id;
13
+    private $name;
14
+    private $description;
15
+    private $user_id;
16
+    private $course_code;
17
+    /** @var Category */
18
+    private $category;
19
+    private $created_at;
20
+    private $weight;
21
+    private $eval_max;
22
+    private $visible;
23
+    private $sessionId;
24
+    public $studentList;
25
+
26
+    /**
27
+     * Construct
28
+     */
29
+    public function __construct()
30
+    {
31
+    }
32
+
33
+    /**
34
+     * @return Category
35
+     */
36
+    public function getCategory()
37
+    {
38
+        return $this->category;
39
+    }
40
+
41
+    /**
42
+     * @param Category $category
43
+     */
44
+    public function setCategory($category)
45
+    {
46
+        $this->category = $category;
47
+    }
48
+
49
+    /**
50
+     * @return int
51
+     */
52
+    public function get_category_id()
53
+    {
54
+        return $this->category->get_id();
55
+    }
56
+
57
+    /**
58
+     * @param int $category_id
59
+     */
60
+    public function set_category_id($category_id)
61
+    {
62
+        $categories = Category::load($category_id);
63
+        if (isset($categories[0])) {
64
+            $this->setCategory($categories[0]);
65
+        }
66
+    }
67
+
68
+    /**
69
+     * @return int
70
+     */
71
+    public function get_id()
72
+    {
73
+        return $this->id;
74
+    }
75
+
76
+    /**
77
+     * @return string
78
+     */
79
+    public function get_name()
80
+    {
81
+        return $this->name;
82
+    }
83
+
84
+    /**
85
+     * @return string
86
+     */
87
+    public function get_description()
88
+    {
89
+        return $this->description;
90
+    }
91
+
92
+    public function get_user_id()
93
+    {
94
+        return $this->user_id;
95
+    }
96
+
97
+    public function get_course_code()
98
+    {
99
+        return $this->course_code;
100
+    }
101
+
102
+    /**
103
+     * @return int
104
+     */
105
+    public function getSessionId()
106
+    {
107
+        return $this->sessionId;
108
+    }
109
+
110
+    /**
111
+     * @param int $sessionId
112
+     */
113
+    public function setSessionId($sessionId)
114
+    {
115
+        $this->sessionId = intval($sessionId);
116
+    }
117
+
118
+    public function get_date()
119
+    {
120
+        return $this->created_at;
121
+    }
122
+
123
+    public function get_weight()
124
+    {
125
+        return $this->weight;
126
+    }
127
+
128
+    public function get_max()
129
+    {
130
+        return $this->eval_max;
131
+    }
132
+
133
+    public function get_type()
134
+    {
135
+        return $this->type;
136
+    }
137
+
138
+    public function is_visible()
139
+    {
140
+        return $this->visible;
141
+    }
142
+
143
+    public function get_locked()
144
+    {
145
+        return $this->locked;
146
+    }
147
+
148
+    public function is_locked()
149
+    {
150
+        return isset($this->locked) && $this->locked == 1 ? true : false;
151
+    }
152
+
153
+    public function set_id($id)
154
+    {
155
+        $this->id = $id;
156
+    }
157
+
158
+    public function set_name($name)
159
+    {
160
+        $this->name = $name;
161
+    }
162
+
163
+    public function set_description($description)
164
+    {
165
+        $this->description = $description;
166
+    }
167
+
168
+    public function set_user_id($user_id)
169
+    {
170
+        $this->user_id = $user_id;
171
+    }
172
+
173
+    public function set_course_code($course_code)
174
+    {
175
+        $this->course_code = $course_code;
176
+    }
177
+
178
+    public function set_date($date)
179
+    {
180
+        $this->created_at = $date;
181
+    }
182
+
183
+    public function set_weight($weight)
184
+    {
185
+        $this->weight = $weight;
186
+    }
187
+
188
+    public function set_max($max)
189
+    {
190
+        $this->eval_max = $max;
191
+    }
192
+
193
+    public function set_visible($visible)
194
+    {
195
+        $this->visible = $visible;
196
+    }
197
+
198
+    public function set_type($type)
199
+    {
200
+        $this->type = $type;
201
+    }
202
+
203
+    public function set_locked($locked)
204
+    {
205
+        $this->locked = $locked;
206
+    }
207
+
208
+    /**
209
+     * Retrieve evaluations and return them as an array of Evaluation objects
210
+     * @param int $id evaluation id
211
+     * @param int $user_id user id (evaluation owner)
212
+     * @param string $course_code course code
213
+     * @param int $category_id parent category
214
+     * @param integer $visible visible
215
+     */
216
+    public static function load(
217
+        $id = null,
218
+        $user_id = null,
219
+        $course_code = null,
220
+        $category_id = null,
221
+        $visible = null,
222
+        $locked = null
223
+    ) {
224
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
225
+        $sql = 'SELECT * FROM '.$tbl_grade_evaluations;
226
+        $paramcount = 0;
227
+
228
+        if (isset ($id)) {
229
+            $sql.= ' WHERE id = '.intval($id);
230
+            $paramcount ++;
231
+        }
232
+
233
+        if (isset ($user_id)) {
234
+            if ($paramcount != 0) $sql .= ' AND';
235
+            else $sql .= ' WHERE';
236
+            $sql .= ' user_id = '.intval($user_id);
237
+            $paramcount ++;
238
+        }
239
+
240
+        if (isset ($course_code) && $course_code <> '-1') {
241
+            if ($paramcount != 0) $sql .= ' AND';
242
+            else $sql .= ' WHERE';
243
+            $sql .= " course_code = '".Database::escape_string($course_code)."'";
244
+            $paramcount ++;
245
+        }
246
+
247
+        if (isset ($category_id)) {
248
+            if ($paramcount != 0) $sql .= ' AND';
249
+            else $sql .= ' WHERE';
250
+            $sql .= ' category_id = '.intval($category_id);
251
+            $paramcount ++;
252
+        }
253
+
254
+        if (isset ($visible)) {
255
+            if ($paramcount != 0) $sql .= ' AND';
256
+            else $sql .= ' WHERE';
257
+            $sql .= ' visible = '.intval($visible);
258
+            $paramcount ++;
259
+        }
260
+
261
+        if (isset ($locked)) {
262
+            if ($paramcount != 0) $sql .= ' AND';
263
+            else $sql .= ' WHERE';
264
+            $sql .= ' locked = '.intval($locked);
265
+        }
266
+
267
+        $result = Database::query($sql);
268
+        $alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
269
+
270
+        return $alleval;
271
+    }
272
+
273
+
274
+
275
+    /**
276
+     * @param array $result
277
+     * @return array
278
+     */
279
+    private static function create_evaluation_objects_from_sql_result($result)
280
+    {
281
+        $alleval = array();
282
+        if (Database::num_rows($result)) {
283
+            while ($data = Database::fetch_array($result)) {
284
+                $eval= new Evaluation();
285
+                $eval->set_id($data['id']);
286
+                $eval->set_name($data['name']);
287
+                $eval->set_description($data['description']);
288
+                $eval->set_user_id($data['user_id']);
289
+                $eval->set_course_code($data['course_code']);
290
+                $eval->set_category_id($data['category_id']);
291
+                $eval->set_date(api_get_local_time($data['created_at']));
292
+                $eval->set_weight($data['weight']);
293
+                $eval->set_max($data['max']);
294
+                $eval->set_visible($data['visible']);
295
+                $eval->set_type($data['type']);
296
+                $eval->set_locked($data['locked']);
297
+                $eval->setSessionId(api_get_session_id());
298
+
299
+                $alleval[] = $eval;
300
+            }
301
+        }
302
+
303
+        return $alleval;
304
+    }
305
+
306
+    /**
307
+     * Insert this evaluation into the database
308
+     */
309
+    public function add()
310
+    {
311
+        if (isset($this->name) &&
312
+            isset($this->user_id) &&
313
+            isset($this->weight) &&
314
+            isset ($this->eval_max) &&
315
+            isset($this->visible)
316
+        ) {
317
+            $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
318
+
319
+            $sql = 'INSERT INTO '.$tbl_grade_evaluations
320
+                .' (name, user_id, weight, max, visible';
321
+            if (isset($this->description)) {
322
+                $sql .= ',description';
323
+            }
324
+            if (isset($this->course_code)) {
325
+                $sql .= ', course_code';
326
+            }
327
+            if (isset($this->category)) {
328
+                $sql .= ', category_id';
329
+            }
330
+            $sql .= ', created_at';
331
+            $sql .= ',type';
332
+            $sql .= ") VALUES ('".Database::escape_string($this->get_name())."'"
333
+                .','.intval($this->get_user_id())
334
+                .','.floatval($this->get_weight())
335
+                .','.intval($this->get_max())
336
+                .','.intval($this->is_visible());
337
+            if (isset($this->description)) {
338
+                $sql .= ",'".Database::escape_string($this->get_description())."'";
339
+            }
340
+            if (isset($this->course_code)) {
341
+                $sql .= ",'".Database::escape_string($this->get_course_code())."'";
342
+            }
343
+            if (isset($this->category)) {
344
+                $sql .= ','.intval($this->get_category_id());
345
+            }
346
+            if (empty($this->type)) {
347
+                $this->type = 'evaluation';
348
+            }
349
+            $sql .= ", '".api_get_utc_datetime()."'";
350
+            $sql .= ',\''.Database::escape_string($this->type).'\'';
351
+            $sql .= ")";
352
+
353
+            Database::query($sql);
354
+            $this->set_id(Database::insert_id());
355
+        } else {
356
+            die('Error in Evaluation add: required field empty');
357
+        }
358
+    }
359
+
360
+    /**
361
+     * @param int $idevaluation
362
+     */
363
+    public function add_evaluation_log($idevaluation)
364
+    {
365
+        if (!empty($idevaluation)) {
366
+            $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
367
+            $tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG);
368
+            $eval = new Evaluation();
369
+            $dateobject = $eval->load($idevaluation,null,null,null,null);
370
+            $arreval = get_object_vars($dateobject[0]);
371
+            if (!empty($arreval['id'])) {
372
+                $sql = 'SELECT weight from '.$tbl_grade_evaluations.'
373 373
                         WHERE id='.$arreval['id'];
374 374
                 $rs = Database::query($sql);
375 375
                 $row_old_weight = Database::fetch_array($rs, 'ASSOC');
@@ -385,426 +385,426 @@  discard block
 block discarded – undo
385 385
                     'user_id_log' => api_get_user_id()
386 386
                 ];
387 387
                 Database::insert($tbl_grade_linkeval_log, $params);
388
-			}
389
-		}
390
-	}
391
-
392
-	/**
393
-	 * Update the properties of this evaluation in the database
394
-	 */
395
-	public function save()
396
-	{
397
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
398
-		$sql = 'UPDATE '.$tbl_grade_evaluations
399
-			." SET name = '".Database::escape_string($this->get_name())."'"
400
-			.', description = ';
401
-		if (isset($this->description)) {
402
-			$sql .= "'".Database::escape_string($this->get_description())."'";
403
-		}else {
404
-			$sql .= 'null';
405
-		}
406
-		$sql .= ', user_id = '.intval($this->get_user_id())
407
-			.', course_code = ';
408
-		if (isset($this->course_code)) {
409
-			$sql .= "'".Database::escape_string($this->get_course_code())."'";
410
-		} else {
411
-			$sql .= 'null';
412
-		}
413
-		$sql .= ', category_id = ';
414
-		if (isset($this->category)) {
415
-			$sql .= intval($this->get_category_id());
416
-		} else {
417
-			$sql .= 'null';
418
-		}
419
-		$sql .= ', weight = "'.Database::escape_string($this->get_weight()).'" '
420
-			.', max = '.intval($this->get_max())
421
-			.', visible = '.intval($this->is_visible())
422
-			.' WHERE id = '.intval($this->id);
423
-		//recorded history
424
-
425
-		$eval_log = new Evaluation();
426
-		$eval_log->add_evaluation_log($this->id);
427
-		Database::query($sql);
428
-	}
429
-
430
-	/**
431
-	 * Delete this evaluation from the database
432
-	 */
433
-	public function delete()
434
-	{
435
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
436
-		$sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id);
437
-		Database::query($sql);
438
-	}
439
-
440
-	/**
441
-	 * Check if an evaluation name (with the same parent category) already exists
442
-	 * @param $name name to check (if not given, the name property of this object will be checked)
443
-	 * @param $parent parent category
444
-	 */
445
-	public function does_name_exist($name, $parent)
446
-	{
447
-		if (!isset ($name)) {
448
-			$name = $this->name;
449
-			$parent = $this->category;
450
-		}
451
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
452
-		$sql = 'SELECT count(id) AS number'
453
-			.' FROM '.$tbl_grade_evaluations
454
-			." WHERE name = '".Database::escape_string($name)."'";
455
-
456
-		if (api_is_allowed_to_edit()) {
457
-			$parent = Category::load($parent);
458
-			$code = $parent[0]->get_course_code();
459
-			$courseInfo = api_get_course_info($code);
460
-			$courseId = $courseInfo['real_id'];
461
-
462
-			if (isset($code) && $code != '0') {
463
-				$main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
464
-				$sql .= ' AND user_id IN (
388
+            }
389
+        }
390
+    }
391
+
392
+    /**
393
+     * Update the properties of this evaluation in the database
394
+     */
395
+    public function save()
396
+    {
397
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
398
+        $sql = 'UPDATE '.$tbl_grade_evaluations
399
+            ." SET name = '".Database::escape_string($this->get_name())."'"
400
+            .', description = ';
401
+        if (isset($this->description)) {
402
+            $sql .= "'".Database::escape_string($this->get_description())."'";
403
+        }else {
404
+            $sql .= 'null';
405
+        }
406
+        $sql .= ', user_id = '.intval($this->get_user_id())
407
+            .', course_code = ';
408
+        if (isset($this->course_code)) {
409
+            $sql .= "'".Database::escape_string($this->get_course_code())."'";
410
+        } else {
411
+            $sql .= 'null';
412
+        }
413
+        $sql .= ', category_id = ';
414
+        if (isset($this->category)) {
415
+            $sql .= intval($this->get_category_id());
416
+        } else {
417
+            $sql .= 'null';
418
+        }
419
+        $sql .= ', weight = "'.Database::escape_string($this->get_weight()).'" '
420
+            .', max = '.intval($this->get_max())
421
+            .', visible = '.intval($this->is_visible())
422
+            .' WHERE id = '.intval($this->id);
423
+        //recorded history
424
+
425
+        $eval_log = new Evaluation();
426
+        $eval_log->add_evaluation_log($this->id);
427
+        Database::query($sql);
428
+    }
429
+
430
+    /**
431
+     * Delete this evaluation from the database
432
+     */
433
+    public function delete()
434
+    {
435
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
436
+        $sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id);
437
+        Database::query($sql);
438
+    }
439
+
440
+    /**
441
+     * Check if an evaluation name (with the same parent category) already exists
442
+     * @param $name name to check (if not given, the name property of this object will be checked)
443
+     * @param $parent parent category
444
+     */
445
+    public function does_name_exist($name, $parent)
446
+    {
447
+        if (!isset ($name)) {
448
+            $name = $this->name;
449
+            $parent = $this->category;
450
+        }
451
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
452
+        $sql = 'SELECT count(id) AS number'
453
+            .' FROM '.$tbl_grade_evaluations
454
+            ." WHERE name = '".Database::escape_string($name)."'";
455
+
456
+        if (api_is_allowed_to_edit()) {
457
+            $parent = Category::load($parent);
458
+            $code = $parent[0]->get_course_code();
459
+            $courseInfo = api_get_course_info($code);
460
+            $courseId = $courseInfo['real_id'];
461
+
462
+            if (isset($code) && $code != '0') {
463
+                $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
464
+                $sql .= ' AND user_id IN (
465 465
 					 SELECT user_id FROM '.$main_course_user_table.'
466 466
 					 WHERE
467 467
 						c_id = '.$courseId.' AND
468 468
 						status = '.COURSEMANAGER.'
469 469
 					)';
470
-			} else {
471
-				$sql .= ' AND user_id = '.api_get_user_id();
472
-			}
473
-
474
-		}else {
475
-			$sql .= ' AND user_id = '.api_get_user_id();
476
-		}
477
-
478
-		if (!isset ($parent)) {
479
-			$sql.= ' AND category_id is null';
480
-		} else {
481
-			$sql.= ' AND category_id = '.intval($parent);
482
-		}
483
-		$result = Database::query($sql);
484
-		$number=Database::fetch_row($result);
485
-
486
-		return $number[0] != 0;
487
-	}
488
-
489
-	/**
490
-	 * Are there any results for this evaluation yet ?
491
-	 * The 'max' property should not be changed then.
492
-	 */
493
-	public function has_results()
494
-	{
495
-		$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
496
-		$sql = 'SELECT count(id) AS number
470
+            } else {
471
+                $sql .= ' AND user_id = '.api_get_user_id();
472
+            }
473
+
474
+        }else {
475
+            $sql .= ' AND user_id = '.api_get_user_id();
476
+        }
477
+
478
+        if (!isset ($parent)) {
479
+            $sql.= ' AND category_id is null';
480
+        } else {
481
+            $sql.= ' AND category_id = '.intval($parent);
482
+        }
483
+        $result = Database::query($sql);
484
+        $number=Database::fetch_row($result);
485
+
486
+        return $number[0] != 0;
487
+    }
488
+
489
+    /**
490
+     * Are there any results for this evaluation yet ?
491
+     * The 'max' property should not be changed then.
492
+     */
493
+    public function has_results()
494
+    {
495
+        $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
496
+        $sql = 'SELECT count(id) AS number
497 497
 				FROM '.$tbl_grade_results.'
498 498
 				WHERE evaluation_id = '.intval($this->id);
499
-		$result = Database::query($sql);
500
-		$number=Database::fetch_row($result);
501
-
502
-		return ($number[0] != 0);
503
-	}
504
-
505
-	/**
506
-	 * Delete all results for this evaluation
507
-	 */
508
-	public function delete_results()
509
-	{
510
-		$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
511
-		$sql = 'DELETE FROM '.$tbl_grade_results.'
499
+        $result = Database::query($sql);
500
+        $number=Database::fetch_row($result);
501
+
502
+        return ($number[0] != 0);
503
+    }
504
+
505
+    /**
506
+     * Delete all results for this evaluation
507
+     */
508
+    public function delete_results()
509
+    {
510
+        $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
511
+        $sql = 'DELETE FROM '.$tbl_grade_results.'
512 512
 				WHERE evaluation_id = '.intval($this->id);
513
-		Database::query($sql);
514
-	}
515
-
516
-	/**
517
-	 * Delete this evaluation and all underlying results.
518
-	 */
519
-	public function delete_with_results()
520
-	{
521
-		$this->delete_results();
522
-		$this->delete();
523
-	}
524
-
525
-	/**
526
-	 * Check if the given score is possible for this evaluation
527
-	 */
528
-	public function is_valid_score($score)
529
-	{
530
-		return is_numeric($score) && $score >= 0 && $score <= $this->eval_max;
531
-	}
532
-
533
-	/**
534
-	 * Calculate the score of this evaluation
535
-	 * @param int $stud_id (default: all students who have results for this eval - then the average is returned)
536
-	 * @param string $type (best, average, ranking)
537
-	 * @return	array (score, max) if student is given
538
-	 * 			array (sum of scores, number of scores) otherwise
539
-	 * 			or null if no scores available
540
-	 */
541
-	public function calc_score($stud_id = null, $type = null)
542
-	{
513
+        Database::query($sql);
514
+    }
515
+
516
+    /**
517
+     * Delete this evaluation and all underlying results.
518
+     */
519
+    public function delete_with_results()
520
+    {
521
+        $this->delete_results();
522
+        $this->delete();
523
+    }
524
+
525
+    /**
526
+     * Check if the given score is possible for this evaluation
527
+     */
528
+    public function is_valid_score($score)
529
+    {
530
+        return is_numeric($score) && $score >= 0 && $score <= $this->eval_max;
531
+    }
532
+
533
+    /**
534
+     * Calculate the score of this evaluation
535
+     * @param int $stud_id (default: all students who have results for this eval - then the average is returned)
536
+     * @param string $type (best, average, ranking)
537
+     * @return	array (score, max) if student is given
538
+     * 			array (sum of scores, number of scores) otherwise
539
+     * 			or null if no scores available
540
+     */
541
+    public function calc_score($stud_id = null, $type = null)
542
+    {
543 543
         $useSession = true;
544
-		if (isset($stud_id) && empty($type)) {
545
-			$key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id;
546
-			$data = Session::read('calc_score');
544
+        if (isset($stud_id) && empty($type)) {
545
+            $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id;
546
+            $data = Session::read('calc_score');
547 547
             $results = isset($data[$key]) ? $data[$key] : null;
548 548
 
549 549
             if ($useSession == false) {
550 550
                 $results  = null;
551 551
             }
552
-			if (empty($results)) {
553
-				$results = Result::load(null, $stud_id, $this->id);
554
-				Session::write('calc_score', array($key => $results));
555
-			}
556
-
557
-			$score = 0;
558
-			/** @var Result $res */
559
-			foreach ($results as $res) {
560
-				$score = $res->get_score();
561
-			}
562
-
563
-			return array($score, $this->get_max());
564
-		} else {
565
-
566
-			$count = 0;
567
-			$sum = 0;
568
-			$bestResult = 0;
569
-			$weight = 0;
570
-			$sumResult = 0;
571
-
572
-			$key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id;
552
+            if (empty($results)) {
553
+                $results = Result::load(null, $stud_id, $this->id);
554
+                Session::write('calc_score', array($key => $results));
555
+            }
556
+
557
+            $score = 0;
558
+            /** @var Result $res */
559
+            foreach ($results as $res) {
560
+                $score = $res->get_score();
561
+            }
562
+
563
+            return array($score, $this->get_max());
564
+        } else {
565
+
566
+            $count = 0;
567
+            $sum = 0;
568
+            $bestResult = 0;
569
+            $weight = 0;
570
+            $sumResult = 0;
571
+
572
+            $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id;
573 573
             $data = Session::read('calc_score');
574 574
             $allResults = isset($data[$key]) ? $data[$key] : null;
575 575
             if ($useSession == false) {
576 576
                 $allResults  = null;
577 577
             }
578
-			if (empty($allResults)) {
579
-				$allResults = Result::load(null, null, $this->id);
580
-				Session::write($key, $allResults);
581
-			}
582
-
583
-			$students = array();
584
-			/** @var Result $res */
585
-			foreach ($allResults as $res) {
586
-				$score = $res->get_score();
587
-				if (!empty($score) || $score == '0') {
588
-					$count++;
589
-					$sum += $score / $this->get_max();
590
-					$sumResult += $score;
591
-					if ($score > $bestResult) {
592
-						$bestResult = $score;
593
-					}
594
-					$weight = $this->get_max();
595
-				}
596
-				$students[$res->get_user_id()] = $score;
597
-			}
598
-
599
-			if (empty($count)) {
600
-				return null;
601
-			}
602
-
603
-			switch ($type) {
604
-				case 'best':
605
-					return array($bestResult, $weight);
606
-					break;
607
-				case 'average':
608
-					return array($sumResult/$count, $weight);
609
-					break;
610
-				case 'ranking':
578
+            if (empty($allResults)) {
579
+                $allResults = Result::load(null, null, $this->id);
580
+                Session::write($key, $allResults);
581
+            }
582
+
583
+            $students = array();
584
+            /** @var Result $res */
585
+            foreach ($allResults as $res) {
586
+                $score = $res->get_score();
587
+                if (!empty($score) || $score == '0') {
588
+                    $count++;
589
+                    $sum += $score / $this->get_max();
590
+                    $sumResult += $score;
591
+                    if ($score > $bestResult) {
592
+                        $bestResult = $score;
593
+                    }
594
+                    $weight = $this->get_max();
595
+                }
596
+                $students[$res->get_user_id()] = $score;
597
+            }
598
+
599
+            if (empty($count)) {
600
+                return null;
601
+            }
602
+
603
+            switch ($type) {
604
+                case 'best':
605
+                    return array($bestResult, $weight);
606
+                    break;
607
+                case 'average':
608
+                    return array($sumResult/$count, $weight);
609
+                    break;
610
+                case 'ranking':
611 611
                     $students = array();
612 612
                     /** @var Result $res */
613 613
                     foreach ($allResults as $res) {
614 614
                         $score = $res->get_score();
615 615
                         $students[$res->get_user_id()] = $score;
616 616
                     }
617
-					return AbstractLink::getCurrentUserRanking($stud_id, $students);
618
-					break;
619
-				default:
620
-					return array($sum, $count);
621
-					break;
622
-			}
623
-		}
624
-	}
625
-
626
-	/**
627
-	 * Generate an array of possible categories where this evaluation can be moved to.
628
-	 * Notice: its own parent will be included in the list: it's up to the frontend
629
-	 * to disable this element.
630
-	 * @return array 2-dimensional array - every element contains 3 subelements (id, name, level)
631
-	 */
632
-	public function get_target_categories()
633
-	{
634
-		// - course independent evaluation
635
-		//   -> movable to root or other course independent categories
636
-		// - evaluation inside a course
637
-		//   -> movable to root, independent categories or categories inside the course
638
-		$user = (api_is_platform_admin() ? null : api_get_user_id());
639
-		$targets = array();
640
-		$level = 0;
641
-
642
-		$root = array(0, get_lang('RootCat'), $level);
643
-		$targets[] = $root;
644
-
645
-		if (isset($this->course_code) && !empty($this->course_code)) {
646
-			$crscats = Category::load(null,null,$this->course_code,0);
647
-			foreach ($crscats as $cat) {
648
-				$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
649
-				$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
650
-			}
651
-		}
652
-
653
-		$indcats = Category::load(null,$user,0,0);
654
-		foreach ($indcats as $cat) {
655
-			$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
656
-			$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
657
-		}
658
-
659
-		return $targets;
660
-	}
661
-
662
-	/**
663
-	 * Internal function used by get_target_categories()
664
-	 * @param integer $level
665
-	 */
666
-	private function add_target_subcategories($targets, $level, $catid)
667
-	{
668
-		$subcats = Category::load(null,null,null,$catid);
669
-		foreach ($subcats as $cat) {
670
-			$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
671
-			$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
672
-		}
673
-		return $targets;
674
-	}
675
-
676
-	/**
677
-	 * Move this evaluation to the given category.
678
-	 * If this evaluation moves from inside a course to outside,
679
-	 * its course code is also changed.
680
-	 */
681
-	public function move_to_cat($cat)
682
-	{
683
-		$this->set_category_id($cat->get_id());
684
-		if ($this->get_course_code() != $cat->get_course_code()) {
685
-			$this->set_course_code($cat->get_course_code());
686
-		}
687
-		$this->save();
688
-	}
689
-
690
-	/**
691
-	 * Retrieve evaluations where a student has results for
692
-	 * and return them as an array of Evaluation objects
693
-	 * @param int $cat_id parent category (use 'null' to retrieve them in all categories)
694
-	 * @param int $stud_id student id
695
-	 */
696
-	public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id)
697
-	{
698
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
699
-		$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
700
-
701
-		$sql = 'SELECT * FROM '.$tbl_grade_evaluations.'
617
+                    return AbstractLink::getCurrentUserRanking($stud_id, $students);
618
+                    break;
619
+                default:
620
+                    return array($sum, $count);
621
+                    break;
622
+            }
623
+        }
624
+    }
625
+
626
+    /**
627
+     * Generate an array of possible categories where this evaluation can be moved to.
628
+     * Notice: its own parent will be included in the list: it's up to the frontend
629
+     * to disable this element.
630
+     * @return array 2-dimensional array - every element contains 3 subelements (id, name, level)
631
+     */
632
+    public function get_target_categories()
633
+    {
634
+        // - course independent evaluation
635
+        //   -> movable to root or other course independent categories
636
+        // - evaluation inside a course
637
+        //   -> movable to root, independent categories or categories inside the course
638
+        $user = (api_is_platform_admin() ? null : api_get_user_id());
639
+        $targets = array();
640
+        $level = 0;
641
+
642
+        $root = array(0, get_lang('RootCat'), $level);
643
+        $targets[] = $root;
644
+
645
+        if (isset($this->course_code) && !empty($this->course_code)) {
646
+            $crscats = Category::load(null,null,$this->course_code,0);
647
+            foreach ($crscats as $cat) {
648
+                $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
649
+                $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
650
+            }
651
+        }
652
+
653
+        $indcats = Category::load(null,$user,0,0);
654
+        foreach ($indcats as $cat) {
655
+            $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
656
+            $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
657
+        }
658
+
659
+        return $targets;
660
+    }
661
+
662
+    /**
663
+     * Internal function used by get_target_categories()
664
+     * @param integer $level
665
+     */
666
+    private function add_target_subcategories($targets, $level, $catid)
667
+    {
668
+        $subcats = Category::load(null,null,null,$catid);
669
+        foreach ($subcats as $cat) {
670
+            $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
671
+            $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
672
+        }
673
+        return $targets;
674
+    }
675
+
676
+    /**
677
+     * Move this evaluation to the given category.
678
+     * If this evaluation moves from inside a course to outside,
679
+     * its course code is also changed.
680
+     */
681
+    public function move_to_cat($cat)
682
+    {
683
+        $this->set_category_id($cat->get_id());
684
+        if ($this->get_course_code() != $cat->get_course_code()) {
685
+            $this->set_course_code($cat->get_course_code());
686
+        }
687
+        $this->save();
688
+    }
689
+
690
+    /**
691
+     * Retrieve evaluations where a student has results for
692
+     * and return them as an array of Evaluation objects
693
+     * @param int $cat_id parent category (use 'null' to retrieve them in all categories)
694
+     * @param int $stud_id student id
695
+     */
696
+    public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id)
697
+    {
698
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
699
+        $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
700
+
701
+        $sql = 'SELECT * FROM '.$tbl_grade_evaluations.'
702 702
 				WHERE id IN (
703 703
 					SELECT evaluation_id FROM '.$tbl_grade_results.'
704 704
 					WHERE user_id = '.intval($stud_id).' AND score IS NOT NULL
705 705
 				)';
706
-		if (!api_is_allowed_to_edit()) {
707
-			$sql .= ' AND visible = 1';
708
-		}
709
-		if (isset($cat_id)) {
710
-			$sql .= ' AND category_id = '.intval($cat_id);
711
-		} else {
712
-			$sql .= ' AND category_id >= 0';
713
-		}
714
-
715
-		$result = Database::query($sql);
716
-		$alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
717
-
718
-		return $alleval;
719
-	}
720
-
721
-	/**
722
-	 * Get a list of students that do not have a result record for this evaluation
723
-	 */
724
-	public function get_not_subscribed_students($first_letter_user = '')
725
-	{
726
-		$tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
727
-		$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
728
-
729
-		$sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user
730
-			." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'"
731
-			.' AND status = '.STUDENT
732
-			.' AND user_id NOT IN'
733
-			.' (SELECT user_id FROM '.$tbl_grade_results
734
-			.' WHERE evaluation_id = '.intval($this->id)
735
-			.' )'
736
-			.' ORDER BY lastname';
737
-
738
-		$result = Database::query($sql);
739
-		$users = Database::store_result($result);
740
-
741
-		return $users;
742
-	}
743
-
744
-	/**
745
-	 * Find evaluations by name
746
-	 * @param string $name_mask search string
747
-	 * @return array evaluation objects matching the search criterium
748
-	 * @todo can be written more efficiently using a new (but very complex) sql query
749
-	 */
750
-	public function find_evaluations($name_mask,$selectcat)
751
-	{
752
-		$rootcat = Category::load($selectcat);
753
-		$evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true);
754
-		$foundevals = array();
755
-		foreach ($evals as $eval) {
756
-			if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) {
757
-				$foundevals[] = $eval;
758
-			}
759
-		}
760
-		return $foundevals;
761
-	}
762
-
763
-	public function get_item_type()
764
-	{
765
-		return 'E';
766
-	}
767
-
768
-	public function get_icon_name()
769
-	{
770
-		return $this->has_results() ? 'evalnotempty' : 'evalempty';
771
-	}
772
-
773
-	/**
774
-	 * Locks an evaluation, only one who can unlock it is the platform administrator.
775
-	 * @param int locked 1 or unlocked 0
776
-	 *
777
-	 **/
778
-	function lock($locked)
779
-	{
780
-		$table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
781
-		$sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'";
782
-		Database::query($sql);
783
-	}
784
-
785
-	function check_lock_permissions()
786
-	{
787
-		if (api_is_platform_admin()) {
788
-			return true;
789
-		} else {
790
-			if ($this->is_locked()) {
791
-				api_not_allowed();
792
-			}
793
-		}
794
-	}
795
-
796
-	function delete_linked_data()
797
-	{
798
-
799
-	}
706
+        if (!api_is_allowed_to_edit()) {
707
+            $sql .= ' AND visible = 1';
708
+        }
709
+        if (isset($cat_id)) {
710
+            $sql .= ' AND category_id = '.intval($cat_id);
711
+        } else {
712
+            $sql .= ' AND category_id >= 0';
713
+        }
714
+
715
+        $result = Database::query($sql);
716
+        $alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
717
+
718
+        return $alleval;
719
+    }
720
+
721
+    /**
722
+     * Get a list of students that do not have a result record for this evaluation
723
+     */
724
+    public function get_not_subscribed_students($first_letter_user = '')
725
+    {
726
+        $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
727
+        $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
728
+
729
+        $sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user
730
+            ." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'"
731
+            .' AND status = '.STUDENT
732
+            .' AND user_id NOT IN'
733
+            .' (SELECT user_id FROM '.$tbl_grade_results
734
+            .' WHERE evaluation_id = '.intval($this->id)
735
+            .' )'
736
+            .' ORDER BY lastname';
737
+
738
+        $result = Database::query($sql);
739
+        $users = Database::store_result($result);
740
+
741
+        return $users;
742
+    }
743
+
744
+    /**
745
+     * Find evaluations by name
746
+     * @param string $name_mask search string
747
+     * @return array evaluation objects matching the search criterium
748
+     * @todo can be written more efficiently using a new (but very complex) sql query
749
+     */
750
+    public function find_evaluations($name_mask,$selectcat)
751
+    {
752
+        $rootcat = Category::load($selectcat);
753
+        $evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true);
754
+        $foundevals = array();
755
+        foreach ($evals as $eval) {
756
+            if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) {
757
+                $foundevals[] = $eval;
758
+            }
759
+        }
760
+        return $foundevals;
761
+    }
762
+
763
+    public function get_item_type()
764
+    {
765
+        return 'E';
766
+    }
767
+
768
+    public function get_icon_name()
769
+    {
770
+        return $this->has_results() ? 'evalnotempty' : 'evalempty';
771
+    }
772
+
773
+    /**
774
+     * Locks an evaluation, only one who can unlock it is the platform administrator.
775
+     * @param int locked 1 or unlocked 0
776
+     *
777
+     **/
778
+    function lock($locked)
779
+    {
780
+        $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
781
+        $sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'";
782
+        Database::query($sql);
783
+    }
784
+
785
+    function check_lock_permissions()
786
+    {
787
+        if (api_is_platform_admin()) {
788
+            return true;
789
+        } else {
790
+            if ($this->is_locked()) {
791
+                api_not_allowed();
792
+            }
793
+        }
794
+    }
795
+
796
+    function delete_linked_data()
797
+    {
798
+
799
+    }
800 800
 
801 801
     public function getStudentList()
802 802
     {
803 803
         return $this->studentList;
804 804
     }
805 805
 
806
-	public function setStudentList($list)
807
-	{
808
-		$this->studentList = $list;
809
-	}
806
+    public function setStudentList($list)
807
+    {
808
+        $this->studentList = $list;
809
+    }
810 810
 }
Please login to merge, or discard this patch.
main/inc/lib/chat.lib.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -39,12 +39,12 @@  discard block
 block discarded – undo
39 39
     }
40 40
 
41 41
     /**
42
-    * Set user chat status
43
-    * @param int 0 if disconnected, 1 if connected
44
-    * @param integer $status
42
+     * Set user chat status
43
+     * @param int 0 if disconnected, 1 if connected
44
+     * @param integer $status
45 45
      *
46
-    * @return void
47
-    */
46
+     * @return void
47
+     */
48 48
     public function setUserStatus($status)
49 49
     {
50 50
         UserManager::update_extra_field_value(api_get_user_id(), 'user_chat_status', $status);
@@ -148,10 +148,10 @@  discard block
 block discarded – undo
148 148
     }
149 149
 
150 150
     /**
151
-    * Returns an array of messages inside a chat session with a specific user
152
-    * @param int The ID of the user with whom the current user is chatting
153
-    * @return array Messages list
154
-    */
151
+     * Returns an array of messages inside a chat session with a specific user
152
+     * @param int The ID of the user with whom the current user is chatting
153
+     * @return array Messages list
154
+     */
155 155
     public function box_session($user_id)
156 156
     {
157 157
         $items = array();
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
             }
300 300
         }
301 301
          
302
-         return false;
302
+            return false;
303 303
     }
304 304
     
305 305
     public function is_chat_blocked_by_exercises()
Please login to merge, or discard this patch.
main/gradebook/lib/fe/linkform.class.php 1 patch
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -10,133 +10,133 @@
 block discarded – undo
10 10
  */
11 11
 class LinkForm extends FormValidator
12 12
 {
13
-	const TYPE_CREATE = 1;
14
-	const TYPE_MOVE = 2;
15
-	/** @var Category */
16
-	private $category_object;
17
-	private $link_object;
18
-	private $extra;
13
+    const TYPE_CREATE = 1;
14
+    const TYPE_MOVE = 2;
15
+    /** @var Category */
16
+    private $category_object;
17
+    private $link_object;
18
+    private $extra;
19 19
 
20
-	/**
21
-	 * Builds a form containing form items based on a given parameter
22
-	 * @param int form_type 1=choose link
23
-	 * @param obj cat_obj the category object
24
-	 * @param string form name
25
-	 * @param method
26
-	 * @param action
27
-	 */
28
-	public function __construct(
29
-		$form_type,
30
-		$category_object,
31
-		$link_object,
32
-		$form_name,
33
-		$method = 'post',
34
-		$action = null,
35
-		$extra = null
36
-	) {
37
-		parent :: __construct($form_name, $method, $action);
20
+    /**
21
+     * Builds a form containing form items based on a given parameter
22
+     * @param int form_type 1=choose link
23
+     * @param obj cat_obj the category object
24
+     * @param string form name
25
+     * @param method
26
+     * @param action
27
+     */
28
+    public function __construct(
29
+        $form_type,
30
+        $category_object,
31
+        $link_object,
32
+        $form_name,
33
+        $method = 'post',
34
+        $action = null,
35
+        $extra = null
36
+    ) {
37
+        parent :: __construct($form_name, $method, $action);
38 38
 
39
-		if (isset ($category_object)) {
40
-			$this->category_object = $category_object;
41
-		} else {
42
-			if (isset($link_object)) {
43
-				$this->link_object = $link_object;
44
-			}
45
-		}
39
+        if (isset ($category_object)) {
40
+            $this->category_object = $category_object;
41
+        } else {
42
+            if (isset($link_object)) {
43
+                $this->link_object = $link_object;
44
+            }
45
+        }
46 46
 
47
-		if (isset ($extra)) {
48
-			$this->extra = $extra;
49
-		}
50
-		if ($form_type == self :: TYPE_CREATE) {
51
-			$this->build_create();
52
-		} elseif ($form_type == self :: TYPE_MOVE) {
53
-			$this->build_move();
54
-		}
55
-	}
47
+        if (isset ($extra)) {
48
+            $this->extra = $extra;
49
+        }
50
+        if ($form_type == self :: TYPE_CREATE) {
51
+            $this->build_create();
52
+        } elseif ($form_type == self :: TYPE_MOVE) {
53
+            $this->build_move();
54
+        }
55
+    }
56 56
 
57
-	protected function build_move()
58
-	{
59
-		$renderer =& $this->defaultRenderer();
60
-		$renderer->setCustomElementTemplate('<span>{element}</span> ');
61
-		$this->addElement('static',null,null,'"'.$this->link_object->get_name().'" ');
62
-		$this->addElement('static',null,null,get_lang('MoveTo').' : ');
63
-		$select = $this->addElement('select','move_cat',null,null);
64
-		$line = '';
65
-		foreach ($this->link_object->get_target_categories() as $cat) {
66
-			for ($i=0;$i<$cat[2];$i++) {
67
-				$line .= '&mdash;';
68
-			}
69
-			$select->addoption($line.' '.$cat[1],$cat[0]);
70
-			$line = '';
71
-		}
72
-		$this->addElement('submit', null, get_lang('Ok'));
73
-	}
57
+    protected function build_move()
58
+    {
59
+        $renderer =& $this->defaultRenderer();
60
+        $renderer->setCustomElementTemplate('<span>{element}</span> ');
61
+        $this->addElement('static',null,null,'"'.$this->link_object->get_name().'" ');
62
+        $this->addElement('static',null,null,get_lang('MoveTo').' : ');
63
+        $select = $this->addElement('select','move_cat',null,null);
64
+        $line = '';
65
+        foreach ($this->link_object->get_target_categories() as $cat) {
66
+            for ($i=0;$i<$cat[2];$i++) {
67
+                $line .= '&mdash;';
68
+            }
69
+            $select->addoption($line.' '.$cat[1],$cat[0]);
70
+            $line = '';
71
+        }
72
+        $this->addElement('submit', null, get_lang('Ok'));
73
+    }
74 74
 
75
-	/**
76
-	 * Builds the form
77
-	 */
78
-	protected function build_create()
79
-	{
80
-		$this->addElement('header', get_lang('MakeLink'));
81
-		$select = $this->addElement(
82
-			'select',
83
-			'select_link',
84
-			get_lang('ChooseLink'),
85
-			null,
86
-			array('onchange' => 'document.create_link.submit()')
87
-		);
75
+    /**
76
+     * Builds the form
77
+     */
78
+    protected function build_create()
79
+    {
80
+        $this->addElement('header', get_lang('MakeLink'));
81
+        $select = $this->addElement(
82
+            'select',
83
+            'select_link',
84
+            get_lang('ChooseLink'),
85
+            null,
86
+            array('onchange' => 'document.create_link.submit()')
87
+        );
88 88
 
89
-		$linkTypes = LinkFactory::get_all_types();
89
+        $linkTypes = LinkFactory::get_all_types();
90 90
 
91
-		$select->addoption('['.get_lang('ChooseLink').']', 0);
91
+        $select->addoption('['.get_lang('ChooseLink').']', 0);
92 92
 
93
-		$courseCode = $this->category_object->get_course_code();
93
+        $courseCode = $this->category_object->get_course_code();
94 94
 
95
-		foreach ($linkTypes as $linkType) {
96
-			// The hot potatoe link will be added "inside" the exercise option.
97
-			if ($linkType == LINK_HOTPOTATOES) {
98
-				continue;
99
-			}
100
-			$link = $this->createLink($linkType, $courseCode);
101
-			// disable this element if the link works with a dropdownlist
102
-			// and if there are no links left
103
-			if (!$link->needs_name_and_description() && count($link->get_all_links()) == '0') {
104
-				$select->addoption($link->get_type_name(), $linkType, 'disabled');
105
-			} else {
106
-				if ($link->get_type() == LINK_EXERCISE) {
107
-					// Adding exercise
108
-					$select->addoption($link->get_type_name(), $linkType);
109
-					// Adding hot potatoes
110
-					$linkHot = $this->createLink(LINK_HOTPOTATOES, $courseCode);
111
-					$select->addoption(
112
-						'&nbsp;&nbsp;&nbsp;'.$linkHot->get_type_name(),
113
-						LINK_HOTPOTATOES
114
-					);
115
-				} else {
116
-					$select->addoption($link->get_type_name(), $linkType);
117
-				}
118
-			}
119
-		}
95
+        foreach ($linkTypes as $linkType) {
96
+            // The hot potatoe link will be added "inside" the exercise option.
97
+            if ($linkType == LINK_HOTPOTATOES) {
98
+                continue;
99
+            }
100
+            $link = $this->createLink($linkType, $courseCode);
101
+            // disable this element if the link works with a dropdownlist
102
+            // and if there are no links left
103
+            if (!$link->needs_name_and_description() && count($link->get_all_links()) == '0') {
104
+                $select->addoption($link->get_type_name(), $linkType, 'disabled');
105
+            } else {
106
+                if ($link->get_type() == LINK_EXERCISE) {
107
+                    // Adding exercise
108
+                    $select->addoption($link->get_type_name(), $linkType);
109
+                    // Adding hot potatoes
110
+                    $linkHot = $this->createLink(LINK_HOTPOTATOES, $courseCode);
111
+                    $select->addoption(
112
+                        '&nbsp;&nbsp;&nbsp;'.$linkHot->get_type_name(),
113
+                        LINK_HOTPOTATOES
114
+                    );
115
+                } else {
116
+                    $select->addoption($link->get_type_name(), $linkType);
117
+                }
118
+            }
119
+        }
120 120
 
121
-		if (isset($this->extra)) {
122
-			$this->setDefaults(array('select_link' => $this->extra));
123
-		}
124
-	}
121
+        if (isset($this->extra)) {
122
+            $this->setDefaults(array('select_link' => $this->extra));
123
+        }
124
+    }
125 125
 
126
-	/**
127
-	 * @param integer $link
128
-	 * @param null|string $courseCode
129
-	 * @return AttendanceLink|DropboxLink|ExerciseLink|ForumThreadLink|LearnpathLink|null|StudentPublicationLink|SurveyLink
130
-	 */
131
-	private function createLink($link, $courseCode)
132
-	{
133
-		$link = LinkFactory::create($link);
134
-		if (!empty($courseCode)) {
135
-			$link->set_course_code($courseCode);
136
-		} elseif(!empty($_GET['course_code'])) {
137
-			$link->set_course_code(Database::escape_string($_GET['course_code'], null, false));
138
-		}
126
+    /**
127
+     * @param integer $link
128
+     * @param null|string $courseCode
129
+     * @return AttendanceLink|DropboxLink|ExerciseLink|ForumThreadLink|LearnpathLink|null|StudentPublicationLink|SurveyLink
130
+     */
131
+    private function createLink($link, $courseCode)
132
+    {
133
+        $link = LinkFactory::create($link);
134
+        if (!empty($courseCode)) {
135
+            $link->set_course_code($courseCode);
136
+        } elseif(!empty($_GET['course_code'])) {
137
+            $link->set_course_code(Database::escape_string($_GET['course_code'], null, false));
138
+        }
139 139
 
140
-		return $link;
141
-	}
140
+        return $link;
141
+    }
142 142
 }
Please login to merge, or discard this patch.
main/gradebook/lib/be/forumthreadlink.class.php 1 patch
Indentation   +260 added lines, -260 removed lines patch added patch discarded remove patch
@@ -10,54 +10,54 @@  discard block
 block discarded – undo
10 10
  */
11 11
 class ForumThreadLink extends AbstractLink
12 12
 {
13
-	private $forum_thread_table = null;
14
-	private $itemprop_table = null;
15
-
16
-	/**
17
-	 * Constructor
18
-	 */
19
-	public function __construct()
20
-	{
21
-		parent::__construct();
22
-		$this->set_type(LINK_FORUM_THREAD);
23
-	}
24
-
25
-	/**
26
-	 * @return string
27
-	 */
28
-	public function get_type_name()
29
-	{
30
-		return get_lang('ForumThreads');
31
-	}
32
-
33
-	/**
34
-	 * @return bool
35
-	 */
36
-	public function is_allowed_to_change_name()
37
-	{
38
-		return false;
39
-	}
40
-
41
-	/**
42
-	 * Generate an array of exercises that a teacher hasn't created a link for.
43
-	 * @return array 2-dimensional array - every element contains 2 subelements (id, name)
44
-	 */
45
-	public function get_not_created_links()
46
-	{
47
-		if (empty($this->course_code)) {
48
-			die('Error in get_not_created_links() : course code not set');
49
-		}
50
-
51
-		$tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
52
-
53
-		$sql = 'SELECT thread_id,thread_title,thread_title_qualify FROM '.$this->get_forum_thread_table()
54
-			.' forum_thread WHERE thread_id NOT IN'
55
-			.' (SELECT ref_id FROM '.$tbl_grade_links
56
-			.' WHERE type = '.LINK_FORUM_THREAD
57
-			." AND c_id = ".intval($this->course_id)
58
-			.') AND forum_thread.session_id='.api_get_session_id().'';
59
-
60
-		$result = Database::query($sql);
13
+    private $forum_thread_table = null;
14
+    private $itemprop_table = null;
15
+
16
+    /**
17
+     * Constructor
18
+     */
19
+    public function __construct()
20
+    {
21
+        parent::__construct();
22
+        $this->set_type(LINK_FORUM_THREAD);
23
+    }
24
+
25
+    /**
26
+     * @return string
27
+     */
28
+    public function get_type_name()
29
+    {
30
+        return get_lang('ForumThreads');
31
+    }
32
+
33
+    /**
34
+     * @return bool
35
+     */
36
+    public function is_allowed_to_change_name()
37
+    {
38
+        return false;
39
+    }
40
+
41
+    /**
42
+     * Generate an array of exercises that a teacher hasn't created a link for.
43
+     * @return array 2-dimensional array - every element contains 2 subelements (id, name)
44
+     */
45
+    public function get_not_created_links()
46
+    {
47
+        if (empty($this->course_code)) {
48
+            die('Error in get_not_created_links() : course code not set');
49
+        }
50
+
51
+        $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
52
+
53
+        $sql = 'SELECT thread_id,thread_title,thread_title_qualify FROM '.$this->get_forum_thread_table()
54
+            .' forum_thread WHERE thread_id NOT IN'
55
+            .' (SELECT ref_id FROM '.$tbl_grade_links
56
+            .' WHERE type = '.LINK_FORUM_THREAD
57
+            ." AND c_id = ".intval($this->course_id)
58
+            .') AND forum_thread.session_id='.api_get_session_id().'';
59
+
60
+        $result = Database::query($sql);
61 61
 
62 62
         $cats = array();
63 63
         while ($data = Database::fetch_array($result)) {
@@ -72,29 +72,29 @@  discard block
 block discarded – undo
72 72
         }
73 73
 
74 74
         return $cats;
75
-	}
76
-
77
-	/**
78
-	 * Generate an array of all exercises available.
79
-	 * @return array 2-dimensional array - every element contains 2 subelements (id, name)
80
-	 */
81
-	public function get_all_links()
82
-	{
83
-		if (empty($this->course_code)) {
84
-			die('Error in get_not_created_links() : course code not set');
85
-		}
86
-
87
-		$tbl_grade_links 	= Database :: get_course_table(TABLE_FORUM_THREAD);
88
-		$tbl_item_property	= Database :: get_course_table(TABLE_ITEM_PROPERTY);
89
-		$session_id = api_get_session_id();
90
-
91
-		if ($session_id) {
92
-			$session_condition = 'tl.session_id='.api_get_session_id();
93
-		} else {
94
-			$session_condition = '(tl.session_id = 0 OR tl.session_id IS NULL)';
95
-		}
96
-
97
-		$sql = 'SELECT tl.thread_id, tl.thread_title, tl.thread_title_qualify
75
+    }
76
+
77
+    /**
78
+     * Generate an array of all exercises available.
79
+     * @return array 2-dimensional array - every element contains 2 subelements (id, name)
80
+     */
81
+    public function get_all_links()
82
+    {
83
+        if (empty($this->course_code)) {
84
+            die('Error in get_not_created_links() : course code not set');
85
+        }
86
+
87
+        $tbl_grade_links 	= Database :: get_course_table(TABLE_FORUM_THREAD);
88
+        $tbl_item_property	= Database :: get_course_table(TABLE_ITEM_PROPERTY);
89
+        $session_id = api_get_session_id();
90
+
91
+        if ($session_id) {
92
+            $session_condition = 'tl.session_id='.api_get_session_id();
93
+        } else {
94
+            $session_condition = '(tl.session_id = 0 OR tl.session_id IS NULL)';
95
+        }
96
+
97
+        $sql = 'SELECT tl.thread_id, tl.thread_title, tl.thread_title_qualify
98 98
 				FROM '.$tbl_grade_links.' tl INNER JOIN '.$tbl_item_property.' ip
99 99
 				ON (tl.thread_id = ip.ref AND tl.c_id = ip.c_id )
100 100
 				WHERE
@@ -105,24 +105,24 @@  discard block
 block discarded – undo
105 105
                     '.$session_condition.'
106 106
                 ';
107 107
 
108
-		$result = Database::query($sql);
108
+        $result = Database::query($sql);
109 109
 
110
-		while ($data = Database::fetch_array($result)) {
111
-			if ( isset($data['thread_title_qualify']) and $data['thread_title_qualify']!=""){
112
-				$cats[] = array ($data['thread_id'], $data['thread_title_qualify']);
113
-			} else {
114
-				$cats[] = array ($data['thread_id'], $data['thread_title']);
115
-			}
116
-		}
117
-		$my_cats = isset($cats) ? $cats : null;
110
+        while ($data = Database::fetch_array($result)) {
111
+            if ( isset($data['thread_title_qualify']) and $data['thread_title_qualify']!=""){
112
+                $cats[] = array ($data['thread_id'], $data['thread_title_qualify']);
113
+            } else {
114
+                $cats[] = array ($data['thread_id'], $data['thread_title']);
115
+            }
116
+        }
117
+        $my_cats = isset($cats) ? $cats : null;
118 118
 
119
-		return $my_cats;
120
-	}
119
+        return $my_cats;
120
+    }
121 121
 
122 122
     /**
123
-    * Has anyone done this exercise yet ?
124
-    * @return boolean
125
-    */
123
+     * Has anyone done this exercise yet ?
124
+     * @return boolean
125
+     */
126 126
     public function has_results()
127 127
     {
128 128
         $table = Database :: get_course_table(TABLE_FORUM_POST);
@@ -134,40 +134,40 @@  discard block
 block discarded – undo
134 134
         $number = Database::fetch_row($result);
135 135
 
136 136
         return $number[0] != 0;
137
-	}
137
+    }
138 138
 
139
-	/**
140
-	 * @param int    $stud_id
139
+    /**
140
+     * @param int    $stud_id
141 141
      * @param string $type
142 142
      *
143
-	 * @return array|null
144
-	 */
145
-	public function calc_score($stud_id = null, $type = null)
146
-	{
143
+     * @return array|null
144
+     */
145
+    public function calc_score($stud_id = null, $type = null)
146
+    {
147 147
         require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
148 148
         $threadInfo = get_thread_information($this->get_ref_id());
149 149
 
150
-		$thread_qualify = Database :: get_course_table(TABLE_FORUM_THREAD_QUALIFY);
150
+        $thread_qualify = Database :: get_course_table(TABLE_FORUM_THREAD_QUALIFY);
151 151
 
152
-		$sql = 'SELECT thread_qualify_max
152
+        $sql = 'SELECT thread_qualify_max
153 153
 		        FROM '.Database :: get_course_table(TABLE_FORUM_THREAD)."
154 154
   				WHERE c_id = ".$this->course_id." AND thread_id = '".$this->get_ref_id()."'";
155
-		$query = Database::query($sql);
156
-		$assignment = Database::fetch_array($query);
155
+        $query = Database::query($sql);
156
+        $assignment = Database::fetch_array($query);
157 157
 
158
-		$sql = "SELECT * FROM $thread_qualify
158
+        $sql = "SELECT * FROM $thread_qualify
159 159
 				WHERE c_id = ".$this->course_id." AND thread_id = ".$this->get_ref_id();
160
-		if (isset($stud_id)) {
161
-			$sql .= ' AND user_id = '.intval($stud_id);
162
-		}
160
+        if (isset($stud_id)) {
161
+            $sql .= ' AND user_id = '.intval($stud_id);
162
+        }
163 163
 
164
-		// order by id, that way the student's first attempt is accessed first
165
-		$sql .= ' ORDER BY qualify_time DESC';
164
+        // order by id, that way the student's first attempt is accessed first
165
+        $sql .= ' ORDER BY qualify_time DESC';
166 166
 
167
-		$scores = Database::query($sql);
167
+        $scores = Database::query($sql);
168 168
 
169
-		// for 1 student
170
-		if (isset($stud_id)) {
169
+        // for 1 student
170
+        if (isset($stud_id)) {
171 171
             if ($threadInfo['thread_peer_qualify'] == 0) {
172 172
                 // Classic way of calculate score
173 173
                 if ($data = Database::fetch_array($scores)) {
@@ -195,175 +195,175 @@  discard block
 block discarded – undo
195 195
                 }
196 196
                 return [$score/$counter, $assignment['thread_qualify_max']];
197 197
             }
198
-		} else {
199
-			// All students -> get average
200
-			$students = array();  // user list, needed to make sure we only
201
-			// take first attempts into account
202
-			$counter = 0;
203
-			$sum = 0;
204
-			$bestResult = 0;
205
-			$weight = 0;
206
-			$sumResult = 0;
207
-
208
-			while ($data = Database::fetch_array($scores)) {
209
-				if (!(array_key_exists($data['user_id'], $students))) {
210
-					if ($assignment['thread_qualify_max'] != 0) {
211
-						$students[$data['user_id']] = $data['qualify'];
212
-						$counter++;
213
-						$sum += $data['qualify'] / $assignment['thread_qualify_max'];
214
-						$sumResult += $data['qualify'];
215
-						if ($data['qualify'] > $bestResult) {
216
-							$bestResult = $data['qualify'];
217
-						}
218
-						$weight = $assignment['thread_qualify_max'];
219
-					}
220
-				}
221
-			}
222
-
223
-			if ($counter == 0) {
224
-				return null;
225
-			} else {
226
-				switch ($type) {
227
-					case 'best':
228
-						return array($bestResult, $weight);
229
-						break;
230
-					case 'average':
231
-						return array($sumResult/$counter, $weight);
232
-						break;
233
-					case 'ranking':
234
-						return AbstractLink::getCurrentUserRanking($stud_id, $students);
235
-						break;
236
-					default:
237
-						return array($sum, $counter);
238
-						break;
239
-				}
240
-			}
241
-		}
242
-	}
243
-
244
-	/**
245
-	 * Lazy load function to get the database table of the student publications
246
-	 */
247
-	private function get_forum_thread_table()
248
-	{
249
-		return $this->forum_thread_table = Database :: get_course_table(TABLE_FORUM_THREAD);
250
-	}
251
-
252
-	public function needs_name_and_description()
253
-	{
254
-		return false;
255
-	}
256
-
257
-	public function needs_max()
258
-	{
259
-		return false;
260
-	}
261
-
262
-	public function needs_results()
263
-	{
264
-		return false;
265
-	}
198
+        } else {
199
+            // All students -> get average
200
+            $students = array();  // user list, needed to make sure we only
201
+            // take first attempts into account
202
+            $counter = 0;
203
+            $sum = 0;
204
+            $bestResult = 0;
205
+            $weight = 0;
206
+            $sumResult = 0;
207
+
208
+            while ($data = Database::fetch_array($scores)) {
209
+                if (!(array_key_exists($data['user_id'], $students))) {
210
+                    if ($assignment['thread_qualify_max'] != 0) {
211
+                        $students[$data['user_id']] = $data['qualify'];
212
+                        $counter++;
213
+                        $sum += $data['qualify'] / $assignment['thread_qualify_max'];
214
+                        $sumResult += $data['qualify'];
215
+                        if ($data['qualify'] > $bestResult) {
216
+                            $bestResult = $data['qualify'];
217
+                        }
218
+                        $weight = $assignment['thread_qualify_max'];
219
+                    }
220
+                }
221
+            }
222
+
223
+            if ($counter == 0) {
224
+                return null;
225
+            } else {
226
+                switch ($type) {
227
+                    case 'best':
228
+                        return array($bestResult, $weight);
229
+                        break;
230
+                    case 'average':
231
+                        return array($sumResult/$counter, $weight);
232
+                        break;
233
+                    case 'ranking':
234
+                        return AbstractLink::getCurrentUserRanking($stud_id, $students);
235
+                        break;
236
+                    default:
237
+                        return array($sum, $counter);
238
+                        break;
239
+                }
240
+            }
241
+        }
242
+    }
243
+
244
+    /**
245
+     * Lazy load function to get the database table of the student publications
246
+     */
247
+    private function get_forum_thread_table()
248
+    {
249
+        return $this->forum_thread_table = Database :: get_course_table(TABLE_FORUM_THREAD);
250
+    }
251
+
252
+    public function needs_name_and_description()
253
+    {
254
+        return false;
255
+    }
256
+
257
+    public function needs_max()
258
+    {
259
+        return false;
260
+    }
261
+
262
+    public function needs_results()
263
+    {
264
+        return false;
265
+    }
266 266
 
267 267
     /**
268 268
      * @return string
269 269
      */
270
-	public function get_name()
271
-	{
272
-		$this->get_exercise_data();
273
-		$thread_title=isset($this->exercise_data['thread_title']) ? $this->exercise_data['thread_title'] : '';
274
-		$thread_title_qualify=isset($this->exercise_data['thread_title_qualify']) ? $this->exercise_data['thread_title_qualify'] : '';
275
-		if ( isset($thread_title_qualify) && $thread_title_qualify!="") {
276
-			return $this->exercise_data['thread_title_qualify'];
277
-		} else {
278
-			return $thread_title;
279
-		}
280
-	}
270
+    public function get_name()
271
+    {
272
+        $this->get_exercise_data();
273
+        $thread_title=isset($this->exercise_data['thread_title']) ? $this->exercise_data['thread_title'] : '';
274
+        $thread_title_qualify=isset($this->exercise_data['thread_title_qualify']) ? $this->exercise_data['thread_title_qualify'] : '';
275
+        if ( isset($thread_title_qualify) && $thread_title_qualify!="") {
276
+            return $this->exercise_data['thread_title_qualify'];
277
+        } else {
278
+            return $thread_title;
279
+        }
280
+    }
281 281
 
282 282
     /**
283 283
      * @return string
284 284
      */
285
-	public function get_description()
286
-	{
287
-		return '';//$this->exercise_data['description'];
288
-	}
289
-
290
-	/**
291
-	 * Check if this still links to an exercise
292
-	 */
293
-	public function is_valid_link()
294
-	{
295
-		$sql = 'SELECT count(id) from '.$this->get_forum_thread_table().'
285
+    public function get_description()
286
+    {
287
+        return '';//$this->exercise_data['description'];
288
+    }
289
+
290
+    /**
291
+     * Check if this still links to an exercise
292
+     */
293
+    public function is_valid_link()
294
+    {
295
+        $sql = 'SELECT count(id) from '.$this->get_forum_thread_table().'
296 296
         		WHERE c_id = '.$this->course_id.' AND thread_id = '.$this->get_ref_id().' AND session_id='.api_get_session_id().'';
297
-		$result = Database::query($sql);
298
-		$number = Database::fetch_row($result);
299
-		return ($number[0] != 0);
300
-	}
301
-
302
-	public function get_test_id()
303
-	{
304
-		return 'DEBUG:ID';
305
-	}
306
-
307
-	public function get_link()
308
-	{
309
-		$sessionId = api_get_session_id();
310
-		//it was extracts the forum id
311
-		$sql = 'SELECT * FROM '.$this->get_forum_thread_table()."
297
+        $result = Database::query($sql);
298
+        $number = Database::fetch_row($result);
299
+        return ($number[0] != 0);
300
+    }
301
+
302
+    public function get_test_id()
303
+    {
304
+        return 'DEBUG:ID';
305
+    }
306
+
307
+    public function get_link()
308
+    {
309
+        $sessionId = api_get_session_id();
310
+        //it was extracts the forum id
311
+        $sql = 'SELECT * FROM '.$this->get_forum_thread_table()."
312 312
     			WHERE c_id = '.$this->course_id.' AND thread_id = '".$this->get_ref_id()."' AND session_id = ".$sessionId."";
313
-		$result = Database::query($sql);
314
-		$row    = Database::fetch_array($result,'ASSOC');
315
-		$forum_id=$row['forum_id'];
316
-
317
-		$url = api_get_path(WEB_PATH).'main/forum/viewthread.php?'.api_get_cidreq_params($this->get_course_code(), $sessionId).'&thread='.$this->get_ref_id().'&gradebook=view&forum='.$forum_id;
318
-		return $url;
319
-	}
320
-
321
-	private function get_exercise_data()
322
-	{
323
-		$session_id = api_get_session_id();
324
-		if ($session_id) {
325
-			$session_condition = 'session_id='.api_get_session_id();
326
-		} else {
327
-			$session_condition = '(session_id = 0 OR session_id IS NULL)';
328
-		}
329
-
330
-		if (!isset($this->exercise_data)) {
331
-			$sql = 'SELECT * FROM '.$this->get_forum_thread_table().'
313
+        $result = Database::query($sql);
314
+        $row    = Database::fetch_array($result,'ASSOC');
315
+        $forum_id=$row['forum_id'];
316
+
317
+        $url = api_get_path(WEB_PATH).'main/forum/viewthread.php?'.api_get_cidreq_params($this->get_course_code(), $sessionId).'&thread='.$this->get_ref_id().'&gradebook=view&forum='.$forum_id;
318
+        return $url;
319
+    }
320
+
321
+    private function get_exercise_data()
322
+    {
323
+        $session_id = api_get_session_id();
324
+        if ($session_id) {
325
+            $session_condition = 'session_id='.api_get_session_id();
326
+        } else {
327
+            $session_condition = '(session_id = 0 OR session_id IS NULL)';
328
+        }
329
+
330
+        if (!isset($this->exercise_data)) {
331
+            $sql = 'SELECT * FROM '.$this->get_forum_thread_table().'
332 332
                     WHERE c_id = '.$this->course_id.' AND  thread_id = '.$this->get_ref_id().' AND '.$session_condition;
333
-			$query = Database::query($sql);
334
-			$this->exercise_data = Database::fetch_array($query);
335
-		}
336
-		return $this->exercise_data;
337
-	}
338
-
339
-	public function get_icon_name()
340
-	{
341
-		return 'forum';
342
-	}
343
-
344
-	function save_linked_data()
345
-	{
346
-		$weight = (float)$this->get_weight();
347
-		$ref_id = $this->get_ref_id();
348
-
349
-		if (!empty($ref_id)) {
350
-			$sql = 'UPDATE '.$this->get_forum_thread_table().' SET thread_weight='.$weight.'
333
+            $query = Database::query($sql);
334
+            $this->exercise_data = Database::fetch_array($query);
335
+        }
336
+        return $this->exercise_data;
337
+    }
338
+
339
+    public function get_icon_name()
340
+    {
341
+        return 'forum';
342
+    }
343
+
344
+    function save_linked_data()
345
+    {
346
+        $weight = (float)$this->get_weight();
347
+        $ref_id = $this->get_ref_id();
348
+
349
+        if (!empty($ref_id)) {
350
+            $sql = 'UPDATE '.$this->get_forum_thread_table().' SET thread_weight='.$weight.'
351 351
                     WHERE c_id = '.$this->course_id.' AND thread_id= '.$ref_id;
352
-			Database::query($sql);
353
-		}
354
-	}
355
-
356
-	function delete_linked_data()
357
-	{
358
-		$ref_id = $this->get_ref_id();
359
-		if (!empty($ref_id)) {
360
-			//Cleans forum
361
-			$sql = 'UPDATE '.$this->get_forum_thread_table().' SET
352
+            Database::query($sql);
353
+        }
354
+    }
355
+
356
+    function delete_linked_data()
357
+    {
358
+        $ref_id = $this->get_ref_id();
359
+        if (!empty($ref_id)) {
360
+            //Cleans forum
361
+            $sql = 'UPDATE '.$this->get_forum_thread_table().' SET
362 362
 			        thread_qualify_max = 0,
363 363
 			        thread_weight = 0,
364 364
 			        thread_title_qualify = ""
365 365
                     WHERE c_id = '.$this->course_id.' AND thread_id= '.$ref_id;
366
-			Database::query($sql);
367
-		}
368
-	}
366
+            Database::query($sql);
367
+        }
368
+    }
369 369
 }
Please login to merge, or discard this patch.
main/survey/survey.php 1 patch
Indentation   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -20,8 +20,8 @@  discard block
 block discarded – undo
20 20
 // Coach can't view this page
21 21
 $extend_rights_for_coachs = api_get_setting('extend_rights_for_coach_on_survey');
22 22
 $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
23
-	api_get_user_id(),
24
-	api_get_course_info()
23
+    api_get_user_id(),
24
+    api_get_course_info()
25 25
 );
26 26
 
27 27
 if ($isDrhOfCourse) {
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
     (api_is_course_coach() && $extend_rights_for_coachs == 'false')
33 33
 ) {    
34 34
     api_not_allowed(true);
35
-	exit;
35
+    exit;
36 36
 }
37 37
 
38 38
 // Database table definitions
@@ -49,21 +49,21 @@  discard block
 block discarded – undo
49 49
 
50 50
 // Breadcrumbs
51 51
 $interbreadcrumb[] = array(
52
-		'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php',
53
-		'name' => get_lang('SurveyList'),
52
+        'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php',
53
+        'name' => get_lang('SurveyList'),
54 54
 );
55 55
 
56 56
 // Getting the survey information
57 57
 if (!empty($_GET['survey_id'])) {
58
-	$course_code = api_get_course_id();
59
-	if ($course_code!=-1) {
60
-		$survey_data = SurveyManager::get_survey($survey_id);
61
-	} else {
62
-		Display :: display_header(get_lang('ToolSurvey'));
63
-		Display :: display_error_message(get_lang('NotAllowed'), false);
64
-		Display :: display_footer();
65
-		exit;
66
-	}
58
+    $course_code = api_get_course_id();
59
+    if ($course_code!=-1) {
60
+        $survey_data = SurveyManager::get_survey($survey_id);
61
+    } else {
62
+        Display :: display_header(get_lang('ToolSurvey'));
63
+        Display :: display_error_message(get_lang('NotAllowed'), false);
64
+        Display :: display_footer();
65
+        exit;
66
+    }
67 67
 } else {
68 68
     Display :: display_header(get_lang('ToolSurvey'));
69 69
     Display :: display_error_message(get_lang('NotAllowed'), false);
@@ -76,30 +76,30 @@  discard block
 block discarded – undo
76 76
 $is_survey_type_1 = $survey_data['survey_type'] == 1;
77 77
 
78 78
 if (api_strlen(strip_tags($survey_data['title'])) > 40) {
79
-	$tool_name .= '...';
79
+    $tool_name .= '...';
80 80
 }
81 81
 
82 82
 if ($is_survey_type_1 && ($action == 'addgroup' || $action == 'deletegroup')) {
83
-	$_POST['name'] = trim($_POST['name']);
84
-	if ($action == 'addgroup') {
85
-		if (!empty($_POST['group_id'])) {
86
-			Database::query('UPDATE '.$table_survey_question_group.' SET description = \''.Database::escape_string($_POST['description']).'\'
83
+    $_POST['name'] = trim($_POST['name']);
84
+    if ($action == 'addgroup') {
85
+        if (!empty($_POST['group_id'])) {
86
+            Database::query('UPDATE '.$table_survey_question_group.' SET description = \''.Database::escape_string($_POST['description']).'\'
87 87
 			                 WHERE c_id = '.$course_id.' AND id = \''.Database::escape_string($_POST['group_id']).'\'');
88
-			$sendmsg = 'GroupUpdatedSuccessfully';
89
-		} elseif(!empty($_POST['name'])) {
90
-			Database::query('INSERT INTO '.$table_survey_question_group.' (c_id, name,description,survey_id) values ('.$course_id.', \''.Database::escape_string($_POST['name']).'\',\''.Database::escape_string($_POST['description']).'\',\''.Database::escape_string($survey_id).'\') ');
91
-			$sendmsg = 'GroupCreatedSuccessfully';
92
-		} else {
93
-			$sendmsg = 'GroupNeedName';
94
-		}
95
-	}
96
-
97
-	if ($action == 'deletegroup') {
98
-		Database::query('DELETE FROM '.$table_survey_question_group.' WHERE c_id = '.$course_id.' AND id = '.intval($_GET['gid']).' and survey_id = '.intval($survey_id));
99
-		$sendmsg = 'GroupDeletedSuccessfully';
100
-	}
101
-	header('Location: '.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&sendmsg='.$sendmsg);
102
-	exit;
88
+            $sendmsg = 'GroupUpdatedSuccessfully';
89
+        } elseif(!empty($_POST['name'])) {
90
+            Database::query('INSERT INTO '.$table_survey_question_group.' (c_id, name,description,survey_id) values ('.$course_id.', \''.Database::escape_string($_POST['name']).'\',\''.Database::escape_string($_POST['description']).'\',\''.Database::escape_string($survey_id).'\') ');
91
+            $sendmsg = 'GroupCreatedSuccessfully';
92
+        } else {
93
+            $sendmsg = 'GroupNeedName';
94
+        }
95
+    }
96
+
97
+    if ($action == 'deletegroup') {
98
+        Database::query('DELETE FROM '.$table_survey_question_group.' WHERE c_id = '.$course_id.' AND id = '.intval($_GET['gid']).' and survey_id = '.intval($survey_id));
99
+        $sendmsg = 'GroupDeletedSuccessfully';
100
+    }
101
+    header('Location: '.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&sendmsg='.$sendmsg);
102
+    exit;
103 103
 }
104 104
 
105 105
 // Displaying the header
@@ -113,13 +113,13 @@  discard block
 block discarded – undo
113 113
 $message_information    = isset($_GET['message']) ? Security::remove_XSS($_GET['message']) : null;
114 114
 
115 115
 if (isset($action)) {
116
-	if (($action == 'moveup' || $action == 'movedown') && isset($_GET['question_id'])) {
117
-		SurveyManager::move_survey_question($my_action_survey,$my_question_id_survey,$my_survey_id_survey);
118
-		Display::display_confirmation_message(get_lang('SurveyQuestionMoved'));
119
-	}
120
-	if ($action == 'delete' AND is_numeric($_GET['question_id'])) {
121
-		SurveyManager::delete_survey_question($my_survey_id_survey, $my_question_id_survey, $survey_data['is_shared']);
122
-	}
116
+    if (($action == 'moveup' || $action == 'movedown') && isset($_GET['question_id'])) {
117
+        SurveyManager::move_survey_question($my_action_survey,$my_question_id_survey,$my_survey_id_survey);
118
+        Display::display_confirmation_message(get_lang('SurveyQuestionMoved'));
119
+    }
120
+    if ($action == 'delete' AND is_numeric($_GET['question_id'])) {
121
+        SurveyManager::delete_survey_question($my_survey_id_survey, $my_question_id_survey, $survey_data['is_shared']);
122
+    }
123 123
 }
124 124
 
125 125
 if (!empty($survey_data['survey_version'])) echo '<b>'.get_lang('Version').': '.$survey_data['survey_version'].'</b>';
@@ -137,26 +137,26 @@  discard block
 block discarded – undo
137 137
 echo '<div class="actions">'.$survey_actions.'</div>';
138 138
 
139 139
 if ($survey_data['survey_type'] == 0) {
140
-	echo '<div class="panel panel-default">';
140
+    echo '<div class="panel panel-default">';
141 141
         echo '<div class="panel-body">';
142
-	echo '<a 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.png', get_lang('YesNo'), null, ICON_SIZE_BIG).'</a>';
143
-	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.png', get_lang('UniqueSelect'), null, ICON_SIZE_BIG).'</a>';
144
-	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.png', get_lang('MultipleResponse'), null, ICON_SIZE_BIG).'</a>';
145
-	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.png', get_lang('Open'), null, ICON_SIZE_BIG).'</a>';
146
-	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.png', get_lang('Dropdown'), null, ICON_SIZE_BIG).'</a>';
147
-	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.png', get_lang('Percentage'), null, ICON_SIZE_BIG).'</a>';
148
-	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.png', get_lang('Score'), null, ICON_SIZE_BIG).'</a>';
149
-	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.png', get_lang('Comment'), null, ICON_SIZE_BIG).'</a>';
150
-	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.png', get_lang('Pagebreak'), null, ICON_SIZE_BIG).'</a>';
151
-	echo '</div>';
142
+    echo '<a 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.png', get_lang('YesNo'), null, ICON_SIZE_BIG).'</a>';
143
+    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.png', get_lang('UniqueSelect'), null, ICON_SIZE_BIG).'</a>';
144
+    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.png', get_lang('MultipleResponse'), null, ICON_SIZE_BIG).'</a>';
145
+    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.png', get_lang('Open'), null, ICON_SIZE_BIG).'</a>';
146
+    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.png', get_lang('Dropdown'), null, ICON_SIZE_BIG).'</a>';
147
+    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.png', get_lang('Percentage'), null, ICON_SIZE_BIG).'</a>';
148
+    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.png', get_lang('Score'), null, ICON_SIZE_BIG).'</a>';
149
+    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.png', get_lang('Comment'), null, ICON_SIZE_BIG).'</a>';
150
+    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.png', get_lang('Pagebreak'), null, ICON_SIZE_BIG).'</a>';
151
+    echo '</div>';
152 152
         echo '</div>';
153 153
 } else {
154
-	echo '<div class="panel panel-default">';
154
+    echo '<div class="panel panel-default">';
155 155
         echo '<div class="panel-body">';
156
-	echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&amp;action=add&type=personality&amp;survey_id='.$survey_id.'">';
157
-	echo Display::return_icon("yesno.png");
158
-	echo '</a></div>';
159
-	echo '</div>';
156
+    echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&amp;action=add&type=personality&amp;survey_id='.$survey_id.'">';
157
+    echo Display::return_icon("yesno.png");
158
+    echo '</a></div>';
159
+    echo '</div>';
160 160
         echo '</div>';
161 161
 }
162 162
 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 echo '		<th width="50" >'.get_lang('NumberOfOptions').'</th>';
170 170
 echo '		<th width="100">'.get_lang('Modify').'</th>';
171 171
 if ($is_survey_type_1) {
172
-	echo '<th width="100">'.get_lang('Condition').'</th>';
172
+    echo '<th width="100">'.get_lang('Condition').'</th>';
173 173
     echo '<th width="40">'.get_lang('Group').'</th>';
174 174
 }
175 175
 echo '	</tr>';
@@ -196,97 +196,97 @@  discard block
 block discarded – undo
196 196
 $result = Database::query($sql);
197 197
 $question_counter_max = Database::num_rows($result);
198 198
 while ($row = Database::fetch_array($result, 'ASSOC')) {
199
-	echo '<tr>';
200
-	echo '	<td>'.$question_counter.'</td>';
201
-	echo '	<td>';
202
-	if (api_strlen($row['survey_question']) > 100) {
203
-		echo api_substr(strip_tags($row['survey_question']), 0, 100).' ... ';
204
-	} else {
205
-		echo $row['survey_question'];
206
-	}
207
-
208
-	if ($row['type'] == 'yesno') {
209
-		$tool_name = get_lang('YesNo');
210
-	} else if ($row['type'] == 'multiplechoice') {
211
-		$tool_name = get_lang('UniqueSelect');
212
-	} else {
213
-		$tool_name = get_lang(api_ucfirst(Security::remove_XSS($row['type'])));
214
-	}
215
-
216
-	echo '</td>';
217
-	echo '	<td>'.$tool_name.'</td>';
218
-	echo '	<td>'.$row['number_of_options'].'</td>';
219
-	echo '	<td>';
220
-	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>';
221
-	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>';
222
-	if ($question_counter > 1) {
223
-		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>';
224
-	} else {
225
-		Display::display_icon('up_na.png','&nbsp;','',ICON_SIZE_SMALL);
226
-	}
227
-	if ($question_counter < $question_counter_max) {
228
-		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>';
229
-	} else {
230
-		Display::display_icon('down_na.png','&nbsp;','',ICON_SIZE_SMALL);
231
-	}
232
-	echo '	</td>';
233
-	$question_counter++;
234
-
235
-	if ($is_survey_type_1) {
236
-    	echo '<td>'.(($row['survey_group_pri']==0)?get_lang('Secondary'):get_lang('Primary')).'</td>';
199
+    echo '<tr>';
200
+    echo '	<td>'.$question_counter.'</td>';
201
+    echo '	<td>';
202
+    if (api_strlen($row['survey_question']) > 100) {
203
+        echo api_substr(strip_tags($row['survey_question']), 0, 100).' ... ';
204
+    } else {
205
+        echo $row['survey_question'];
206
+    }
207
+
208
+    if ($row['type'] == 'yesno') {
209
+        $tool_name = get_lang('YesNo');
210
+    } else if ($row['type'] == 'multiplechoice') {
211
+        $tool_name = get_lang('UniqueSelect');
212
+    } else {
213
+        $tool_name = get_lang(api_ucfirst(Security::remove_XSS($row['type'])));
214
+    }
215
+
216
+    echo '</td>';
217
+    echo '	<td>'.$tool_name.'</td>';
218
+    echo '	<td>'.$row['number_of_options'].'</td>';
219
+    echo '	<td>';
220
+    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>';
221
+    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>';
222
+    if ($question_counter > 1) {
223
+        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>';
224
+    } else {
225
+        Display::display_icon('up_na.png','&nbsp;','',ICON_SIZE_SMALL);
226
+    }
227
+    if ($question_counter < $question_counter_max) {
228
+        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>';
229
+    } else {
230
+        Display::display_icon('down_na.png','&nbsp;','',ICON_SIZE_SMALL);
231
+    }
232
+    echo '	</td>';
233
+    $question_counter++;
234
+
235
+    if ($is_survey_type_1) {
236
+        echo '<td>'.(($row['survey_group_pri']==0)?get_lang('Secondary'):get_lang('Primary')).'</td>';
237 237
         echo '<td>'.(($row['survey_group_pri']==0)?$groups[$row['survey_group_sec1']].'-'.$groups[$row['survey_group_sec2']]:$groups[$row['survey_group_pri']]).'</td>';
238 238
     }
239
-	echo '</tr>';
239
+    echo '</tr>';
240 240
 }
241 241
 
242 242
 echo '</table>';
243 243
 
244 244
 if ($is_survey_type_1) {
245
-	echo '<br /><br /><b>'.get_lang('ManageGroups').'</b><br /><br />';
246
-
247
-	if (in_array($_GET['sendmsg'], array('GroupUpdatedSuccessfully', 'GroupDeletedSuccessfully', 'GroupCreatedSuccessfully'))) {
248
-		echo Display::display_confirmation_message(get_lang($_GET['sendmsg']), false);
249
-	}
250
-
251
-	if (in_array($_GET['sendmsg'], array('GroupNeedName'))){
252
-		echo Display::display_warning_message(get_lang($_GET['sendmsg']), false);
253
-	}
254
-	echo '<table border="0"><tr><td width="100">'.get_lang('Name').'</td><td>'.get_lang('Description').'</td></tr></table>';
255
-	echo '<form action="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?action=addgroup&survey_id='.$survey_id.'" method="post">';
256
-	if ($_GET['action'] == 'editgroup') {
257
-		$sql = 'SELECT name,description FROM '.$table_survey_question_group.' WHERE id = '.intval($_GET['gid']).' AND survey_id = '.intval($survey_id).' limit 1';
258
-		$rs = Database::query($sql);
259
-		$editedrow = Database::fetch_array($rs,'ASSOC');
260
-		echo	'<input type="text" maxlength="20" name="name" value="'.$editedrow['name'].'" size="10" disabled>';
261
-		echo	'<input type="text" maxlength="150" name="description" value="'.$editedrow['description'].'" size="40">';
262
-		echo	'<input type="hidden" name="group_id" value="'.Security::remove_XSS($_GET['gid']).'">';
263
-		echo	'<input type="submit" value="'.get_lang('Save').'"'.'<input type="button" value="'.get_lang('Cancel').'" onclick="window.location.href = \'survey.php?survey_id='.Security::remove_XSS($survey_id).'\';" />';
264
-	} else {
265
-		echo	'<input type="text" maxlength="20" name="name" value="" size="10">';
266
-		echo	'<input type="text" maxlength="250" name="description" value="" size="80">';
267
-		echo	'<input type="submit" value="'.get_lang('Create').'"';
268
-	}
269
-	echo	'</form><br />';
270
-
271
-	echo '<table class="data_table">';
272
-	echo '	<tr class="row_odd">';
273
-	echo '		<th width="200">'.get_lang('Name').'</th>';
274
-	echo '		<th>'.get_lang('Description').'</th>';
275
-	echo '		<th width="100">'.get_lang('Modify').'</th>';
276
-	echo '	</tr>';
277
-
278
-	$sql = 'SELECT id,name,description FROM '.$table_survey_question_group.' WHERE c_id = '.$course_id.' AND survey_id = '.intval($survey_id).' ORDER BY name';
279
-
280
-	$rs = Database::query($sql);
281
-	while($row = Database::fetch_array($rs,ASSOC)){
282
-		$grouplist .= '<tr><td>'.$row['name'].'</td><td>'.$row['description'].'</td><td>'.
283
-		'<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&gid='.$row['id'].'&action=editgroup">'.
284
-		Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL).'</a> '.
285
-		'<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;">'.
286
-		Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
287
-		'</td></tr>';
288
-	}
289
-	echo $grouplist.'</table>';
245
+    echo '<br /><br /><b>'.get_lang('ManageGroups').'</b><br /><br />';
246
+
247
+    if (in_array($_GET['sendmsg'], array('GroupUpdatedSuccessfully', 'GroupDeletedSuccessfully', 'GroupCreatedSuccessfully'))) {
248
+        echo Display::display_confirmation_message(get_lang($_GET['sendmsg']), false);
249
+    }
250
+
251
+    if (in_array($_GET['sendmsg'], array('GroupNeedName'))){
252
+        echo Display::display_warning_message(get_lang($_GET['sendmsg']), false);
253
+    }
254
+    echo '<table border="0"><tr><td width="100">'.get_lang('Name').'</td><td>'.get_lang('Description').'</td></tr></table>';
255
+    echo '<form action="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?action=addgroup&survey_id='.$survey_id.'" method="post">';
256
+    if ($_GET['action'] == 'editgroup') {
257
+        $sql = 'SELECT name,description FROM '.$table_survey_question_group.' WHERE id = '.intval($_GET['gid']).' AND survey_id = '.intval($survey_id).' limit 1';
258
+        $rs = Database::query($sql);
259
+        $editedrow = Database::fetch_array($rs,'ASSOC');
260
+        echo	'<input type="text" maxlength="20" name="name" value="'.$editedrow['name'].'" size="10" disabled>';
261
+        echo	'<input type="text" maxlength="150" name="description" value="'.$editedrow['description'].'" size="40">';
262
+        echo	'<input type="hidden" name="group_id" value="'.Security::remove_XSS($_GET['gid']).'">';
263
+        echo	'<input type="submit" value="'.get_lang('Save').'"'.'<input type="button" value="'.get_lang('Cancel').'" onclick="window.location.href = \'survey.php?survey_id='.Security::remove_XSS($survey_id).'\';" />';
264
+    } else {
265
+        echo	'<input type="text" maxlength="20" name="name" value="" size="10">';
266
+        echo	'<input type="text" maxlength="250" name="description" value="" size="80">';
267
+        echo	'<input type="submit" value="'.get_lang('Create').'"';
268
+    }
269
+    echo	'</form><br />';
270
+
271
+    echo '<table class="data_table">';
272
+    echo '	<tr class="row_odd">';
273
+    echo '		<th width="200">'.get_lang('Name').'</th>';
274
+    echo '		<th>'.get_lang('Description').'</th>';
275
+    echo '		<th width="100">'.get_lang('Modify').'</th>';
276
+    echo '	</tr>';
277
+
278
+    $sql = 'SELECT id,name,description FROM '.$table_survey_question_group.' WHERE c_id = '.$course_id.' AND survey_id = '.intval($survey_id).' ORDER BY name';
279
+
280
+    $rs = Database::query($sql);
281
+    while($row = Database::fetch_array($rs,ASSOC)){
282
+        $grouplist .= '<tr><td>'.$row['name'].'</td><td>'.$row['description'].'</td><td>'.
283
+        '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&gid='.$row['id'].'&action=editgroup">'.
284
+        Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL).'</a> '.
285
+        '<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;">'.
286
+        Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
287
+        '</td></tr>';
288
+    }
289
+    echo $grouplist.'</table>';
290 290
 }
291 291
 
292 292
 Session::erase('answer_count');
Please login to merge, or discard this patch.