Passed
Push — 1.10.x ( 3f2a42...07da6d )
by Yannick
43:34
created
main/gradebook/lib/be/evaluation.class.php 1 patch
Indentation   +744 added lines, -744 removed lines patch added patch discarded remove patch
@@ -9,364 +9,364 @@  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
-	public function get_description()
85
-	{
86
-		return $this->description;
87
-	}
88
-
89
-	public function get_user_id()
90
-	{
91
-		return $this->user_id;
92
-	}
93
-
94
-	public function get_course_code()
95
-	{
96
-		return $this->course_code;
97
-	}
98
-
99
-	/**
100
-	 * @return int
101
-	 */
102
-	public function getSessionId()
103
-	{
104
-		return $this->sessionId;
105
-	}
106
-
107
-	/**
108
-	 * @param int $sessionId
109
-	 */
110
-	public function setSessionId($sessionId)
111
-	{
112
-		$this->sessionId = intval($sessionId);
113
-	}
114
-
115
-	public function get_date()
116
-	{
117
-		return $this->created_at;
118
-	}
119
-
120
-	public function get_weight()
121
-	{
122
-		return $this->weight;
123
-	}
124
-
125
-	public function get_max()
126
-	{
127
-		return $this->eval_max;
128
-	}
129
-
130
-	public function get_type()
131
-	{
132
-		return $this->type;
133
-	}
134
-
135
-	public function is_visible()
136
-	{
137
-		return $this->visible;
138
-	}
139
-
140
-	public function get_locked()
141
-	{
142
-		return $this->locked;
143
-	}
144
-
145
-	public function is_locked()
146
-	{
147
-		return isset($this->locked) && $this->locked == 1 ? true : false;
148
-	}
149
-
150
-	public function set_id($id)
151
-	{
152
-		$this->id = $id;
153
-	}
154
-
155
-	public function set_name($name)
156
-	{
157
-		$this->name = $name;
158
-	}
159
-
160
-	public function set_description($description)
161
-	{
162
-		$this->description = $description;
163
-	}
164
-
165
-	public function set_user_id($user_id)
166
-	{
167
-		$this->user_id = $user_id;
168
-	}
169
-
170
-	public function set_course_code($course_code)
171
-	{
172
-		$this->course_code = $course_code;
173
-	}
174
-
175
-	public function set_date($date)
176
-	{
177
-		$this->created_at = $date;
178
-	}
179
-
180
-	public function set_weight($weight)
181
-	{
182
-		$this->weight = $weight;
183
-	}
184
-
185
-	public function set_max($max)
186
-	{
187
-		$this->eval_max = $max;
188
-	}
189
-
190
-	public function set_visible($visible)
191
-	{
192
-		$this->visible = $visible;
193
-	}
194
-
195
-	public function set_type($type)
196
-	{
197
-		$this->type = $type;
198
-	}
199
-
200
-	public function set_locked($locked)
201
-	{
202
-		$this->locked = $locked;
203
-	}
204
-
205
-	/**
206
-	 * Retrieve evaluations and return them as an array of Evaluation objects
207
-	 * @param int $id evaluation id
208
-	 * @param int $user_id user id (evaluation owner)
209
-	 * @param string $course_code course code
210
-	 * @param int $category_id parent category
211
-	 * @param $visible visible
212
-	 */
213
-	public static function load(
214
-		$id = null,
215
-		$user_id = null,
216
-		$course_code = null,
217
-		$category_id = null,
218
-		$visible = null,
219
-		$locked = null
220
-	) {
221
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
222
-		$sql = 'SELECT * FROM '.$tbl_grade_evaluations;
223
-		$paramcount = 0;
224
-
225
-		if (isset ($id)) {
226
-			$sql.= ' WHERE id = '.intval($id);
227
-			$paramcount ++;
228
-		}
229
-
230
-		if (isset ($user_id)) {
231
-			if ($paramcount != 0) $sql .= ' AND';
232
-			else $sql .= ' WHERE';
233
-			$sql .= ' user_id = '.intval($user_id);
234
-			$paramcount ++;
235
-		}
236
-
237
-		if (isset ($course_code) && $course_code <> '-1') {
238
-			if ($paramcount != 0) $sql .= ' AND';
239
-			else $sql .= ' WHERE';
240
-			$sql .= " course_code = '".Database::escape_string($course_code)."'";
241
-			$paramcount ++;
242
-		}
243
-
244
-		if (isset ($category_id)) {
245
-			if ($paramcount != 0) $sql .= ' AND';
246
-			else $sql .= ' WHERE';
247
-			$sql .= ' category_id = '.intval($category_id);
248
-			$paramcount ++;
249
-		}
250
-
251
-		if (isset ($visible)) {
252
-			if ($paramcount != 0) $sql .= ' AND';
253
-			else $sql .= ' WHERE';
254
-			$sql .= ' visible = '.intval($visible);
255
-			$paramcount ++;
256
-		}
257
-
258
-		if (isset ($locked)) {
259
-			if ($paramcount != 0) $sql .= ' AND';
260
-			else $sql .= ' WHERE';
261
-			$sql .= ' locked = '.intval($locked);
262
-		}
263
-
264
-		$result = Database::query($sql);
265
-		$alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
266
-
267
-		return $alleval;
268
-	}
269
-
270
-
271
-
272
-	/**
273
-	 * @param array $result
274
-	 * @return array
275
-	 */
276
-	private static function create_evaluation_objects_from_sql_result($result)
277
-	{
278
-		$alleval = array();
279
-		if (Database::num_rows($result)) {
280
-			while ($data = Database::fetch_array($result)) {
281
-				$eval= new Evaluation();
282
-				$eval->set_id($data['id']);
283
-				$eval->set_name($data['name']);
284
-				$eval->set_description($data['description']);
285
-				$eval->set_user_id($data['user_id']);
286
-				$eval->set_course_code($data['course_code']);
287
-				$eval->set_category_id($data['category_id']);
288
-				$eval->set_date(api_get_local_time($data['created_at']));
289
-				$eval->set_weight($data['weight']);
290
-				$eval->set_max($data['max']);
291
-				$eval->set_visible($data['visible']);
292
-				$eval->set_type($data['type']);
293
-				$eval->set_locked($data['locked']);
294
-				$eval->setSessionId(api_get_session_id());
295
-
296
-				$alleval[] = $eval;
297
-			}
298
-		}
299
-
300
-		return $alleval;
301
-	}
302
-
303
-	/**
304
-	 * Insert this evaluation into the database
305
-	 */
306
-	public function add()
307
-	{
308
-		if (isset($this->name) &&
309
-			isset($this->user_id) &&
310
-			isset($this->weight) &&
311
-			isset ($this->eval_max) &&
312
-			isset($this->visible)
313
-		) {
314
-			$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
315
-
316
-			$sql = 'INSERT INTO '.$tbl_grade_evaluations
317
-				.' (name, user_id, weight, max, visible';
318
-			if (isset($this->description)) {
319
-				$sql .= ',description';
320
-			}
321
-			if (isset($this->course_code)) {
322
-				$sql .= ', course_code';
323
-			}
324
-			if (isset($this->category)) {
325
-				$sql .= ', category_id';
326
-			}
327
-			$sql .= ', created_at';
328
-			$sql .= ',type';
329
-			$sql .= ") VALUES ('".Database::escape_string($this->get_name())."'"
330
-				.','.intval($this->get_user_id())
331
-				.','.floatval($this->get_weight())
332
-				.','.intval($this->get_max())
333
-				.','.intval($this->is_visible());
334
-			if (isset($this->description)) {
335
-				$sql .= ",'".Database::escape_string($this->get_description())."'";
336
-			}
337
-			if (isset($this->course_code)) {
338
-				$sql .= ",'".Database::escape_string($this->get_course_code())."'";
339
-			}
340
-			if (isset($this->category)) {
341
-				$sql .= ','.intval($this->get_category_id());
342
-			}
343
-			if (empty($this->type)) {
344
-				$this->type = 'evaluation';
345
-			}
346
-			$sql .= ", '".api_get_utc_datetime()."'";
347
-			$sql .= ',\''.Database::escape_string($this->type).'\'';
348
-			$sql .= ")";
349
-
350
-			Database::query($sql);
351
-			$this->set_id(Database::insert_id());
352
-		} else {
353
-			die('Error in Evaluation add: required field empty');
354
-		}
355
-	}
356
-
357
-	/**
358
-	 * @param int $idevaluation
359
-	 */
360
-	public function add_evaluation_log($idevaluation)
361
-	{
362
-		if (!empty($idevaluation)) {
363
-			$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
364
-			$tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG);
365
-			$eval = new Evaluation();
366
-			$dateobject = $eval->load($idevaluation,null,null,null,null);
367
-			$arreval = get_object_vars($dateobject[0]);
368
-			if (!empty($arreval['id'])) {
369
-				$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
+    public function get_description()
85
+    {
86
+        return $this->description;
87
+    }
88
+
89
+    public function get_user_id()
90
+    {
91
+        return $this->user_id;
92
+    }
93
+
94
+    public function get_course_code()
95
+    {
96
+        return $this->course_code;
97
+    }
98
+
99
+    /**
100
+     * @return int
101
+     */
102
+    public function getSessionId()
103
+    {
104
+        return $this->sessionId;
105
+    }
106
+
107
+    /**
108
+     * @param int $sessionId
109
+     */
110
+    public function setSessionId($sessionId)
111
+    {
112
+        $this->sessionId = intval($sessionId);
113
+    }
114
+
115
+    public function get_date()
116
+    {
117
+        return $this->created_at;
118
+    }
119
+
120
+    public function get_weight()
121
+    {
122
+        return $this->weight;
123
+    }
124
+
125
+    public function get_max()
126
+    {
127
+        return $this->eval_max;
128
+    }
129
+
130
+    public function get_type()
131
+    {
132
+        return $this->type;
133
+    }
134
+
135
+    public function is_visible()
136
+    {
137
+        return $this->visible;
138
+    }
139
+
140
+    public function get_locked()
141
+    {
142
+        return $this->locked;
143
+    }
144
+
145
+    public function is_locked()
146
+    {
147
+        return isset($this->locked) && $this->locked == 1 ? true : false;
148
+    }
149
+
150
+    public function set_id($id)
151
+    {
152
+        $this->id = $id;
153
+    }
154
+
155
+    public function set_name($name)
156
+    {
157
+        $this->name = $name;
158
+    }
159
+
160
+    public function set_description($description)
161
+    {
162
+        $this->description = $description;
163
+    }
164
+
165
+    public function set_user_id($user_id)
166
+    {
167
+        $this->user_id = $user_id;
168
+    }
169
+
170
+    public function set_course_code($course_code)
171
+    {
172
+        $this->course_code = $course_code;
173
+    }
174
+
175
+    public function set_date($date)
176
+    {
177
+        $this->created_at = $date;
178
+    }
179
+
180
+    public function set_weight($weight)
181
+    {
182
+        $this->weight = $weight;
183
+    }
184
+
185
+    public function set_max($max)
186
+    {
187
+        $this->eval_max = $max;
188
+    }
189
+
190
+    public function set_visible($visible)
191
+    {
192
+        $this->visible = $visible;
193
+    }
194
+
195
+    public function set_type($type)
196
+    {
197
+        $this->type = $type;
198
+    }
199
+
200
+    public function set_locked($locked)
201
+    {
202
+        $this->locked = $locked;
203
+    }
204
+
205
+    /**
206
+     * Retrieve evaluations and return them as an array of Evaluation objects
207
+     * @param int $id evaluation id
208
+     * @param int $user_id user id (evaluation owner)
209
+     * @param string $course_code course code
210
+     * @param int $category_id parent category
211
+     * @param $visible visible
212
+     */
213
+    public static function load(
214
+        $id = null,
215
+        $user_id = null,
216
+        $course_code = null,
217
+        $category_id = null,
218
+        $visible = null,
219
+        $locked = null
220
+    ) {
221
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
222
+        $sql = 'SELECT * FROM '.$tbl_grade_evaluations;
223
+        $paramcount = 0;
224
+
225
+        if (isset ($id)) {
226
+            $sql.= ' WHERE id = '.intval($id);
227
+            $paramcount ++;
228
+        }
229
+
230
+        if (isset ($user_id)) {
231
+            if ($paramcount != 0) $sql .= ' AND';
232
+            else $sql .= ' WHERE';
233
+            $sql .= ' user_id = '.intval($user_id);
234
+            $paramcount ++;
235
+        }
236
+
237
+        if (isset ($course_code) && $course_code <> '-1') {
238
+            if ($paramcount != 0) $sql .= ' AND';
239
+            else $sql .= ' WHERE';
240
+            $sql .= " course_code = '".Database::escape_string($course_code)."'";
241
+            $paramcount ++;
242
+        }
243
+
244
+        if (isset ($category_id)) {
245
+            if ($paramcount != 0) $sql .= ' AND';
246
+            else $sql .= ' WHERE';
247
+            $sql .= ' category_id = '.intval($category_id);
248
+            $paramcount ++;
249
+        }
250
+
251
+        if (isset ($visible)) {
252
+            if ($paramcount != 0) $sql .= ' AND';
253
+            else $sql .= ' WHERE';
254
+            $sql .= ' visible = '.intval($visible);
255
+            $paramcount ++;
256
+        }
257
+
258
+        if (isset ($locked)) {
259
+            if ($paramcount != 0) $sql .= ' AND';
260
+            else $sql .= ' WHERE';
261
+            $sql .= ' locked = '.intval($locked);
262
+        }
263
+
264
+        $result = Database::query($sql);
265
+        $alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
266
+
267
+        return $alleval;
268
+    }
269
+
270
+
271
+
272
+    /**
273
+     * @param array $result
274
+     * @return array
275
+     */
276
+    private static function create_evaluation_objects_from_sql_result($result)
277
+    {
278
+        $alleval = array();
279
+        if (Database::num_rows($result)) {
280
+            while ($data = Database::fetch_array($result)) {
281
+                $eval= new Evaluation();
282
+                $eval->set_id($data['id']);
283
+                $eval->set_name($data['name']);
284
+                $eval->set_description($data['description']);
285
+                $eval->set_user_id($data['user_id']);
286
+                $eval->set_course_code($data['course_code']);
287
+                $eval->set_category_id($data['category_id']);
288
+                $eval->set_date(api_get_local_time($data['created_at']));
289
+                $eval->set_weight($data['weight']);
290
+                $eval->set_max($data['max']);
291
+                $eval->set_visible($data['visible']);
292
+                $eval->set_type($data['type']);
293
+                $eval->set_locked($data['locked']);
294
+                $eval->setSessionId(api_get_session_id());
295
+
296
+                $alleval[] = $eval;
297
+            }
298
+        }
299
+
300
+        return $alleval;
301
+    }
302
+
303
+    /**
304
+     * Insert this evaluation into the database
305
+     */
306
+    public function add()
307
+    {
308
+        if (isset($this->name) &&
309
+            isset($this->user_id) &&
310
+            isset($this->weight) &&
311
+            isset ($this->eval_max) &&
312
+            isset($this->visible)
313
+        ) {
314
+            $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
315
+
316
+            $sql = 'INSERT INTO '.$tbl_grade_evaluations
317
+                .' (name, user_id, weight, max, visible';
318
+            if (isset($this->description)) {
319
+                $sql .= ',description';
320
+            }
321
+            if (isset($this->course_code)) {
322
+                $sql .= ', course_code';
323
+            }
324
+            if (isset($this->category)) {
325
+                $sql .= ', category_id';
326
+            }
327
+            $sql .= ', created_at';
328
+            $sql .= ',type';
329
+            $sql .= ") VALUES ('".Database::escape_string($this->get_name())."'"
330
+                .','.intval($this->get_user_id())
331
+                .','.floatval($this->get_weight())
332
+                .','.intval($this->get_max())
333
+                .','.intval($this->is_visible());
334
+            if (isset($this->description)) {
335
+                $sql .= ",'".Database::escape_string($this->get_description())."'";
336
+            }
337
+            if (isset($this->course_code)) {
338
+                $sql .= ",'".Database::escape_string($this->get_course_code())."'";
339
+            }
340
+            if (isset($this->category)) {
341
+                $sql .= ','.intval($this->get_category_id());
342
+            }
343
+            if (empty($this->type)) {
344
+                $this->type = 'evaluation';
345
+            }
346
+            $sql .= ", '".api_get_utc_datetime()."'";
347
+            $sql .= ',\''.Database::escape_string($this->type).'\'';
348
+            $sql .= ")";
349
+
350
+            Database::query($sql);
351
+            $this->set_id(Database::insert_id());
352
+        } else {
353
+            die('Error in Evaluation add: required field empty');
354
+        }
355
+    }
356
+
357
+    /**
358
+     * @param int $idevaluation
359
+     */
360
+    public function add_evaluation_log($idevaluation)
361
+    {
362
+        if (!empty($idevaluation)) {
363
+            $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
364
+            $tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG);
365
+            $eval = new Evaluation();
366
+            $dateobject = $eval->load($idevaluation,null,null,null,null);
367
+            $arreval = get_object_vars($dateobject[0]);
368
+            if (!empty($arreval['id'])) {
369
+                $sql = 'SELECT weight from '.$tbl_grade_evaluations.'
370 370
                         WHERE id='.$arreval['id'];
371 371
                 $rs = Database::query($sql);
372 372
                 $row_old_weight = Database::fetch_array($rs, 'ASSOC');
@@ -382,425 +382,425 @@  discard block
 block discarded – undo
382 382
                     'user_id_log' => api_get_user_id()
383 383
                 ];
384 384
                 Database::insert($tbl_grade_linkeval_log, $params);
385
-			}
386
-		}
387
-	}
388
-
389
-	/**
390
-	 * Update the properties of this evaluation in the database
391
-	 */
392
-	public function save()
393
-	{
394
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
395
-		$sql = 'UPDATE '.$tbl_grade_evaluations
396
-			." SET name = '".Database::escape_string($this->get_name())."'"
397
-			.', description = ';
398
-		if (isset($this->description)) {
399
-			$sql .= "'".Database::escape_string($this->get_description())."'";
400
-		}else {
401
-			$sql .= 'null';
402
-		}
403
-		$sql .= ', user_id = '.intval($this->get_user_id())
404
-			.', course_code = ';
405
-		if (isset($this->course_code)) {
406
-			$sql .= "'".Database::escape_string($this->get_course_code())."'";
407
-		} else {
408
-			$sql .= 'null';
409
-		}
410
-		$sql .= ', category_id = ';
411
-		if (isset($this->category)) {
412
-			$sql .= intval($this->get_category_id());
413
-		} else {
414
-			$sql .= 'null';
415
-		}
416
-		$sql .= ', weight = "'.Database::escape_string($this->get_weight()).'" '
417
-			.', max = '.intval($this->get_max())
418
-			.', visible = '.intval($this->is_visible())
419
-			.' WHERE id = '.intval($this->id);
420
-		//recorded history
421
-
422
-		$eval_log = new Evaluation();
423
-		$eval_log->add_evaluation_log($this->id);
424
-		Database::query($sql);
425
-	}
426
-
427
-	/**
428
-	 * Delete this evaluation from the database
429
-	 */
430
-	public function delete()
431
-	{
432
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
433
-		$sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id);
434
-		Database::query($sql);
435
-	}
436
-
437
-	/**
438
-	 * Check if an evaluation name (with the same parent category) already exists
439
-	 * @param $name name to check (if not given, the name property of this object will be checked)
440
-	 * @param $parent parent category
441
-	 */
442
-	public function does_name_exist($name, $parent)
443
-	{
444
-		if (!isset ($name)) {
445
-			$name = $this->name;
446
-			$parent = $this->category;
447
-		}
448
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
449
-		$sql = 'SELECT count(id) AS number'
450
-			.' FROM '.$tbl_grade_evaluations
451
-			." WHERE name = '".Database::escape_string($name)."'";
452
-
453
-		if (api_is_allowed_to_edit()) {
454
-			$parent = Category::load($parent);
455
-			$code = $parent[0]->get_course_code();
456
-			$courseInfo = api_get_course_info($code);
457
-			$courseId = $courseInfo['real_id'];
458
-
459
-			if (isset($code) && $code != '0') {
460
-				$main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
461
-				$sql .= ' AND user_id IN (
385
+            }
386
+        }
387
+    }
388
+
389
+    /**
390
+     * Update the properties of this evaluation in the database
391
+     */
392
+    public function save()
393
+    {
394
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
395
+        $sql = 'UPDATE '.$tbl_grade_evaluations
396
+            ." SET name = '".Database::escape_string($this->get_name())."'"
397
+            .', description = ';
398
+        if (isset($this->description)) {
399
+            $sql .= "'".Database::escape_string($this->get_description())."'";
400
+        }else {
401
+            $sql .= 'null';
402
+        }
403
+        $sql .= ', user_id = '.intval($this->get_user_id())
404
+            .', course_code = ';
405
+        if (isset($this->course_code)) {
406
+            $sql .= "'".Database::escape_string($this->get_course_code())."'";
407
+        } else {
408
+            $sql .= 'null';
409
+        }
410
+        $sql .= ', category_id = ';
411
+        if (isset($this->category)) {
412
+            $sql .= intval($this->get_category_id());
413
+        } else {
414
+            $sql .= 'null';
415
+        }
416
+        $sql .= ', weight = "'.Database::escape_string($this->get_weight()).'" '
417
+            .', max = '.intval($this->get_max())
418
+            .', visible = '.intval($this->is_visible())
419
+            .' WHERE id = '.intval($this->id);
420
+        //recorded history
421
+
422
+        $eval_log = new Evaluation();
423
+        $eval_log->add_evaluation_log($this->id);
424
+        Database::query($sql);
425
+    }
426
+
427
+    /**
428
+     * Delete this evaluation from the database
429
+     */
430
+    public function delete()
431
+    {
432
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
433
+        $sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id);
434
+        Database::query($sql);
435
+    }
436
+
437
+    /**
438
+     * Check if an evaluation name (with the same parent category) already exists
439
+     * @param $name name to check (if not given, the name property of this object will be checked)
440
+     * @param $parent parent category
441
+     */
442
+    public function does_name_exist($name, $parent)
443
+    {
444
+        if (!isset ($name)) {
445
+            $name = $this->name;
446
+            $parent = $this->category;
447
+        }
448
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
449
+        $sql = 'SELECT count(id) AS number'
450
+            .' FROM '.$tbl_grade_evaluations
451
+            ." WHERE name = '".Database::escape_string($name)."'";
452
+
453
+        if (api_is_allowed_to_edit()) {
454
+            $parent = Category::load($parent);
455
+            $code = $parent[0]->get_course_code();
456
+            $courseInfo = api_get_course_info($code);
457
+            $courseId = $courseInfo['real_id'];
458
+
459
+            if (isset($code) && $code != '0') {
460
+                $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
461
+                $sql .= ' AND user_id IN (
462 462
 					 SELECT user_id FROM '.$main_course_user_table.'
463 463
 					 WHERE
464 464
 						c_id = '.$courseId.' AND
465 465
 						status = '.COURSEMANAGER.'
466 466
 					)';
467
-			} else {
468
-				$sql .= ' AND user_id = '.api_get_user_id();
469
-			}
470
-
471
-		}else {
472
-			$sql .= ' AND user_id = '.api_get_user_id();
473
-		}
474
-
475
-		if (!isset ($parent)) {
476
-			$sql.= ' AND category_id is null';
477
-		} else {
478
-			$sql.= ' AND category_id = '.intval($parent);
479
-		}
480
-		$result = Database::query($sql);
481
-		$number=Database::fetch_row($result);
482
-
483
-		return $number[0] != 0;
484
-	}
485
-
486
-	/**
487
-	 * Are there any results for this evaluation yet ?
488
-	 * The 'max' property should not be changed then.
489
-	 */
490
-	public function has_results()
491
-	{
492
-		$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
493
-		$sql = 'SELECT count(id) AS number
467
+            } else {
468
+                $sql .= ' AND user_id = '.api_get_user_id();
469
+            }
470
+
471
+        }else {
472
+            $sql .= ' AND user_id = '.api_get_user_id();
473
+        }
474
+
475
+        if (!isset ($parent)) {
476
+            $sql.= ' AND category_id is null';
477
+        } else {
478
+            $sql.= ' AND category_id = '.intval($parent);
479
+        }
480
+        $result = Database::query($sql);
481
+        $number=Database::fetch_row($result);
482
+
483
+        return $number[0] != 0;
484
+    }
485
+
486
+    /**
487
+     * Are there any results for this evaluation yet ?
488
+     * The 'max' property should not be changed then.
489
+     */
490
+    public function has_results()
491
+    {
492
+        $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
493
+        $sql = 'SELECT count(id) AS number
494 494
 				FROM '.$tbl_grade_results.'
495 495
 				WHERE evaluation_id = '.intval($this->id);
496
-		$result = Database::query($sql);
497
-		$number=Database::fetch_row($result);
498
-
499
-		return ($number[0] != 0);
500
-	}
501
-
502
-	/**
503
-	 * Delete all results for this evaluation
504
-	 */
505
-	public function delete_results()
506
-	{
507
-		$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
508
-		$sql = 'DELETE FROM '.$tbl_grade_results.'
496
+        $result = Database::query($sql);
497
+        $number=Database::fetch_row($result);
498
+
499
+        return ($number[0] != 0);
500
+    }
501
+
502
+    /**
503
+     * Delete all results for this evaluation
504
+     */
505
+    public function delete_results()
506
+    {
507
+        $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
508
+        $sql = 'DELETE FROM '.$tbl_grade_results.'
509 509
 				WHERE evaluation_id = '.intval($this->id);
510
-		Database::query($sql);
511
-	}
512
-
513
-	/**
514
-	 * Delete this evaluation and all underlying results.
515
-	 */
516
-	public function delete_with_results()
517
-	{
518
-		$this->delete_results();
519
-		$this->delete();
520
-	}
521
-
522
-	/**
523
-	 * Check if the given score is possible for this evaluation
524
-	 */
525
-	public function is_valid_score($score)
526
-	{
527
-		return is_numeric($score) && $score >= 0 && $score <= $this->eval_max;
528
-	}
529
-
530
-	/**
531
-	 * Calculate the score of this evaluation
532
-	 * @param int $stud_id (default: all students who have results for this eval - then the average is returned)
533
-	 * @param string $type (best, average, ranking)
534
-	 * @return	array (score, max) if student is given
535
-	 * 			array (sum of scores, number of scores) otherwise
536
-	 * 			or null if no scores available
537
-	 */
538
-	public function calc_score($stud_id = null, $type = null)
539
-	{
510
+        Database::query($sql);
511
+    }
512
+
513
+    /**
514
+     * Delete this evaluation and all underlying results.
515
+     */
516
+    public function delete_with_results()
517
+    {
518
+        $this->delete_results();
519
+        $this->delete();
520
+    }
521
+
522
+    /**
523
+     * Check if the given score is possible for this evaluation
524
+     */
525
+    public function is_valid_score($score)
526
+    {
527
+        return is_numeric($score) && $score >= 0 && $score <= $this->eval_max;
528
+    }
529
+
530
+    /**
531
+     * Calculate the score of this evaluation
532
+     * @param int $stud_id (default: all students who have results for this eval - then the average is returned)
533
+     * @param string $type (best, average, ranking)
534
+     * @return	array (score, max) if student is given
535
+     * 			array (sum of scores, number of scores) otherwise
536
+     * 			or null if no scores available
537
+     */
538
+    public function calc_score($stud_id = null, $type = null)
539
+    {
540 540
         $useSession = true;
541
-		if (isset($stud_id) && empty($type)) {
542
-			$key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id;
543
-			$data = Session::read('calc_score');
541
+        if (isset($stud_id) && empty($type)) {
542
+            $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id;
543
+            $data = Session::read('calc_score');
544 544
             $results = isset($data[$key]) ? $data[$key] : null;
545 545
 
546 546
             if ($useSession == false) {
547 547
                 $results  = null;
548 548
             }
549
-			if (empty($results)) {
550
-				$results = Result::load(null, $stud_id, $this->id);
551
-				Session::write('calc_score', array($key => $results));
552
-			}
553
-
554
-			$score = 0;
555
-			/** @var Result $res */
556
-			foreach ($results as $res) {
557
-				$score = $res->get_score();
558
-			}
559
-
560
-			return array($score, $this->get_max());
561
-		} else {
562
-
563
-			$count = 0;
564
-			$sum = 0;
565
-			$bestResult = 0;
566
-			$weight = 0;
567
-			$sumResult = 0;
568
-
569
-			$key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id;
549
+            if (empty($results)) {
550
+                $results = Result::load(null, $stud_id, $this->id);
551
+                Session::write('calc_score', array($key => $results));
552
+            }
553
+
554
+            $score = 0;
555
+            /** @var Result $res */
556
+            foreach ($results as $res) {
557
+                $score = $res->get_score();
558
+            }
559
+
560
+            return array($score, $this->get_max());
561
+        } else {
562
+
563
+            $count = 0;
564
+            $sum = 0;
565
+            $bestResult = 0;
566
+            $weight = 0;
567
+            $sumResult = 0;
568
+
569
+            $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id;
570 570
             $data = Session::read('calc_score');
571 571
             $allResults = isset($data[$key]) ? $data[$key] : null;
572 572
             if ($useSession == false) {
573 573
                 $allResults  = null;
574 574
             }
575
-			if (empty($allResults)) {
576
-				$allResults = Result::load(null, null, $this->id);
577
-				Session::write($key, $allResults);
578
-			}
579
-
580
-			$students = array();
581
-			/** @var Result $res */
582
-			foreach ($allResults as $res) {
583
-				$score = $res->get_score();
584
-				if (!empty($score) || $score == '0') {
585
-					$count++;
586
-					$sum += $score / $this->get_max();
587
-					$sumResult += $score;
588
-					if ($score > $bestResult) {
589
-						$bestResult = $score;
590
-					}
591
-					$weight = $this->get_max();
592
-				}
593
-				$students[$res->get_user_id()] = $score;
594
-			}
595
-
596
-			if (empty($count)) {
597
-				return null;
598
-			}
599
-
600
-			switch ($type) {
601
-				case 'best':
602
-					return array($bestResult, $weight);
603
-					break;
604
-				case 'average':
605
-					return array($sumResult/$count, $weight);
606
-					break;
607
-				case 'ranking':
575
+            if (empty($allResults)) {
576
+                $allResults = Result::load(null, null, $this->id);
577
+                Session::write($key, $allResults);
578
+            }
579
+
580
+            $students = array();
581
+            /** @var Result $res */
582
+            foreach ($allResults as $res) {
583
+                $score = $res->get_score();
584
+                if (!empty($score) || $score == '0') {
585
+                    $count++;
586
+                    $sum += $score / $this->get_max();
587
+                    $sumResult += $score;
588
+                    if ($score > $bestResult) {
589
+                        $bestResult = $score;
590
+                    }
591
+                    $weight = $this->get_max();
592
+                }
593
+                $students[$res->get_user_id()] = $score;
594
+            }
595
+
596
+            if (empty($count)) {
597
+                return null;
598
+            }
599
+
600
+            switch ($type) {
601
+                case 'best':
602
+                    return array($bestResult, $weight);
603
+                    break;
604
+                case 'average':
605
+                    return array($sumResult/$count, $weight);
606
+                    break;
607
+                case 'ranking':
608 608
                     $students = array();
609 609
                     /** @var Result $res */
610 610
                     foreach ($allResults as $res) {
611 611
                         $score = $res->get_score();
612 612
                         $students[$res->get_user_id()] = $score;
613 613
                     }
614
-					return AbstractLink::getCurrentUserRanking($stud_id, $students);
615
-					break;
616
-				default:
617
-					return array($sum, $count);
618
-					break;
619
-			}
620
-		}
621
-	}
622
-
623
-	/**
624
-	 * Generate an array of possible categories where this evaluation can be moved to.
625
-	 * Notice: its own parent will be included in the list: it's up to the frontend
626
-	 * to disable this element.
627
-	 * @return array 2-dimensional array - every element contains 3 subelements (id, name, level)
628
-	 */
629
-	public function get_target_categories()
630
-	{
631
-		// - course independent evaluation
632
-		//   -> movable to root or other course independent categories
633
-		// - evaluation inside a course
634
-		//   -> movable to root, independent categories or categories inside the course
635
-		$user = (api_is_platform_admin() ? null : api_get_user_id());
636
-		$targets = array();
637
-		$level = 0;
638
-
639
-		$root = array(0, get_lang('RootCat'), $level);
640
-		$targets[] = $root;
641
-
642
-		if (isset($this->course_code) && !empty($this->course_code)) {
643
-			$crscats = Category::load(null,null,$this->course_code,0);
644
-			foreach ($crscats as $cat) {
645
-				$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
646
-				$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
647
-			}
648
-		}
649
-
650
-		$indcats = Category::load(null,$user,0,0);
651
-		foreach ($indcats as $cat) {
652
-			$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
653
-			$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
654
-		}
655
-
656
-		return $targets;
657
-	}
658
-
659
-	/**
660
-	 * Internal function used by get_target_categories()
661
-	 */
662
-	private function add_target_subcategories($targets, $level, $catid)
663
-	{
664
-		$subcats = Category::load(null,null,null,$catid);
665
-		foreach ($subcats as $cat) {
666
-			$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
667
-			$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
668
-		}
669
-		return $targets;
670
-	}
671
-
672
-	/**
673
-	 * Move this evaluation to the given category.
674
-	 * If this evaluation moves from inside a course to outside,
675
-	 * its course code is also changed.
676
-	 */
677
-	public function move_to_cat($cat)
678
-	{
679
-		$this->set_category_id($cat->get_id());
680
-		if ($this->get_course_code() != $cat->get_course_code()) {
681
-			$this->set_course_code($cat->get_course_code());
682
-		}
683
-		$this->save();
684
-	}
685
-
686
-	/**
687
-	 * Retrieve evaluations where a student has results for
688
-	 * and return them as an array of Evaluation objects
689
-	 * @param int $cat_id parent category (use 'null' to retrieve them in all categories)
690
-	 * @param int $stud_id student id
691
-	 */
692
-	public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id)
693
-	{
694
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
695
-		$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
696
-
697
-		$sql = 'SELECT * FROM '.$tbl_grade_evaluations.'
614
+                    return AbstractLink::getCurrentUserRanking($stud_id, $students);
615
+                    break;
616
+                default:
617
+                    return array($sum, $count);
618
+                    break;
619
+            }
620
+        }
621
+    }
622
+
623
+    /**
624
+     * Generate an array of possible categories where this evaluation can be moved to.
625
+     * Notice: its own parent will be included in the list: it's up to the frontend
626
+     * to disable this element.
627
+     * @return array 2-dimensional array - every element contains 3 subelements (id, name, level)
628
+     */
629
+    public function get_target_categories()
630
+    {
631
+        // - course independent evaluation
632
+        //   -> movable to root or other course independent categories
633
+        // - evaluation inside a course
634
+        //   -> movable to root, independent categories or categories inside the course
635
+        $user = (api_is_platform_admin() ? null : api_get_user_id());
636
+        $targets = array();
637
+        $level = 0;
638
+
639
+        $root = array(0, get_lang('RootCat'), $level);
640
+        $targets[] = $root;
641
+
642
+        if (isset($this->course_code) && !empty($this->course_code)) {
643
+            $crscats = Category::load(null,null,$this->course_code,0);
644
+            foreach ($crscats as $cat) {
645
+                $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
646
+                $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
647
+            }
648
+        }
649
+
650
+        $indcats = Category::load(null,$user,0,0);
651
+        foreach ($indcats as $cat) {
652
+            $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
653
+            $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
654
+        }
655
+
656
+        return $targets;
657
+    }
658
+
659
+    /**
660
+     * Internal function used by get_target_categories()
661
+     */
662
+    private function add_target_subcategories($targets, $level, $catid)
663
+    {
664
+        $subcats = Category::load(null,null,null,$catid);
665
+        foreach ($subcats as $cat) {
666
+            $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
667
+            $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
668
+        }
669
+        return $targets;
670
+    }
671
+
672
+    /**
673
+     * Move this evaluation to the given category.
674
+     * If this evaluation moves from inside a course to outside,
675
+     * its course code is also changed.
676
+     */
677
+    public function move_to_cat($cat)
678
+    {
679
+        $this->set_category_id($cat->get_id());
680
+        if ($this->get_course_code() != $cat->get_course_code()) {
681
+            $this->set_course_code($cat->get_course_code());
682
+        }
683
+        $this->save();
684
+    }
685
+
686
+    /**
687
+     * Retrieve evaluations where a student has results for
688
+     * and return them as an array of Evaluation objects
689
+     * @param int $cat_id parent category (use 'null' to retrieve them in all categories)
690
+     * @param int $stud_id student id
691
+     */
692
+    public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id)
693
+    {
694
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
695
+        $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
696
+
697
+        $sql = 'SELECT * FROM '.$tbl_grade_evaluations.'
698 698
 				WHERE id IN (
699 699
 					SELECT evaluation_id FROM '.$tbl_grade_results.'
700 700
 					WHERE user_id = '.intval($stud_id).' AND score IS NOT NULL
701 701
 				)';
702
-		if (!api_is_allowed_to_edit()) {
703
-			$sql .= ' AND visible = 1';
704
-		}
705
-		if (isset($cat_id)) {
706
-			$sql .= ' AND category_id = '.intval($cat_id);
707
-		} else {
708
-			$sql .= ' AND category_id >= 0';
709
-		}
710
-
711
-		$result = Database::query($sql);
712
-		$alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
713
-
714
-		return $alleval;
715
-	}
716
-
717
-	/**
718
-	 * Get a list of students that do not have a result record for this evaluation
719
-	 */
720
-	public function get_not_subscribed_students($first_letter_user = '')
721
-	{
722
-		$tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
723
-		$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
724
-
725
-		$sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user
726
-			." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'"
727
-			.' AND status = '.STUDENT
728
-			.' AND user_id NOT IN'
729
-			.' (SELECT user_id FROM '.$tbl_grade_results
730
-			.' WHERE evaluation_id = '.intval($this->id)
731
-			.' )'
732
-			.' ORDER BY lastname';
733
-
734
-		$result = Database::query($sql);
735
-		$users = Database::store_result($result);
736
-
737
-		return $users;
738
-	}
739
-
740
-	/**
741
-	 * Find evaluations by name
742
-	 * @param string $name_mask search string
743
-	 * @return array evaluation objects matching the search criterium
744
-	 * @todo can be written more efficiently using a new (but very complex) sql query
745
-	 */
746
-	public function find_evaluations($name_mask,$selectcat)
747
-	{
748
-		$rootcat = Category::load($selectcat);
749
-		$evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true);
750
-		$foundevals = array();
751
-		foreach ($evals as $eval) {
752
-			if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) {
753
-				$foundevals[] = $eval;
754
-			}
755
-		}
756
-		return $foundevals;
757
-	}
758
-
759
-	public function get_item_type()
760
-	{
761
-		return 'E';
762
-	}
763
-
764
-	public function get_icon_name()
765
-	{
766
-		return $this->has_results() ? 'evalnotempty' : 'evalempty';
767
-	}
768
-
769
-	/**
770
-	 * Locks an evaluation, only one who can unlock it is the platform administrator.
771
-	 * @param int locked 1 or unlocked 0
772
-	 *
773
-	 **/
774
-	function lock($locked)
775
-	{
776
-		$table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
777
-		$sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'";
778
-		Database::query($sql);
779
-	}
780
-
781
-	function check_lock_permissions()
782
-	{
783
-		if (api_is_platform_admin()) {
784
-			return true;
785
-		} else {
786
-			if ($this->is_locked()) {
787
-				api_not_allowed();
788
-			}
789
-		}
790
-	}
791
-
792
-	function delete_linked_data()
793
-	{
794
-
795
-	}
702
+        if (!api_is_allowed_to_edit()) {
703
+            $sql .= ' AND visible = 1';
704
+        }
705
+        if (isset($cat_id)) {
706
+            $sql .= ' AND category_id = '.intval($cat_id);
707
+        } else {
708
+            $sql .= ' AND category_id >= 0';
709
+        }
710
+
711
+        $result = Database::query($sql);
712
+        $alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
713
+
714
+        return $alleval;
715
+    }
716
+
717
+    /**
718
+     * Get a list of students that do not have a result record for this evaluation
719
+     */
720
+    public function get_not_subscribed_students($first_letter_user = '')
721
+    {
722
+        $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
723
+        $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
724
+
725
+        $sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user
726
+            ." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'"
727
+            .' AND status = '.STUDENT
728
+            .' AND user_id NOT IN'
729
+            .' (SELECT user_id FROM '.$tbl_grade_results
730
+            .' WHERE evaluation_id = '.intval($this->id)
731
+            .' )'
732
+            .' ORDER BY lastname';
733
+
734
+        $result = Database::query($sql);
735
+        $users = Database::store_result($result);
736
+
737
+        return $users;
738
+    }
739
+
740
+    /**
741
+     * Find evaluations by name
742
+     * @param string $name_mask search string
743
+     * @return array evaluation objects matching the search criterium
744
+     * @todo can be written more efficiently using a new (but very complex) sql query
745
+     */
746
+    public function find_evaluations($name_mask,$selectcat)
747
+    {
748
+        $rootcat = Category::load($selectcat);
749
+        $evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true);
750
+        $foundevals = array();
751
+        foreach ($evals as $eval) {
752
+            if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) {
753
+                $foundevals[] = $eval;
754
+            }
755
+        }
756
+        return $foundevals;
757
+    }
758
+
759
+    public function get_item_type()
760
+    {
761
+        return 'E';
762
+    }
763
+
764
+    public function get_icon_name()
765
+    {
766
+        return $this->has_results() ? 'evalnotempty' : 'evalempty';
767
+    }
768
+
769
+    /**
770
+     * Locks an evaluation, only one who can unlock it is the platform administrator.
771
+     * @param int locked 1 or unlocked 0
772
+     *
773
+     **/
774
+    function lock($locked)
775
+    {
776
+        $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
777
+        $sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'";
778
+        Database::query($sql);
779
+    }
780
+
781
+    function check_lock_permissions()
782
+    {
783
+        if (api_is_platform_admin()) {
784
+            return true;
785
+        } else {
786
+            if ($this->is_locked()) {
787
+                api_not_allowed();
788
+            }
789
+        }
790
+    }
791
+
792
+    function delete_linked_data()
793
+    {
794
+
795
+    }
796 796
 
797 797
     public function getStudentList()
798 798
     {
799 799
         return $this->studentList;
800 800
     }
801 801
 
802
-	public function setStudentList($list)
803
-	{
804
-		$this->studentList = $list;
805
-	}
802
+    public function setStudentList($list)
803
+    {
804
+        $this->studentList = $list;
805
+    }
806 806
 }
Please login to merge, or discard this patch.
main/gradebook/lib/GradebookUtils.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -249,7 +249,7 @@
 block discarded – undo
249 249
                     }
250 250
                 }
251 251
 
252
-               $modify_icons .= '<a href="gradebook_edit_all.php?selectcat=' .$cat->get_id() . '&cidReq=' . $cat->get_course_code() . '&id_session='.$cat->get_session_id().'">' .
252
+                $modify_icons .= '<a href="gradebook_edit_all.php?selectcat=' .$cat->get_id() . '&cidReq=' . $cat->get_course_code() . '&id_session='.$cat->get_session_id().'">' .
253 253
                     Display::return_icon(
254 254
                         'percentage.png',
255 255
                         get_lang('EditAllWeights'),
Please login to merge, or discard this patch.
main/admin/class_edit.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@
 block discarded – undo
4 4
 *	@package chamilo.admin
5 5
 */
6 6
 /**
7
- * Code
8
- */
7
+     * Code
8
+     */
9 9
 // Resetting the course id.
10 10
 $cidReset = true;
11 11
 
Please login to merge, or discard this patch.
main/admin/grade_models.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
                         array('name'=>'name',           'index'=>'name',        'width'=>'80',   'align'=>'left'),
81 81
                         array('name'=>'description',    'index'=>'description', 'width'=>'500',  'align'=>'left','sortable'=>'false'),
82 82
                         array('name'=>'actions',        'index'=>'actions',     'width'=>'100',  'align'=>'left','formatter'=>'action_formatter','sortable'=>'false')
83
-                       );
83
+                        );
84 84
 //Autowidth
85 85
 $extra_params['autowidth'] = 'true';
86 86
 //height auto
@@ -89,8 +89,8 @@  discard block
 block discarded – undo
89 89
 //With this function we can add actions to the jgrid (edit, delete, etc)
90 90
 $action_links = 'function action_formatter(cellvalue, options, rowObject) {
91 91
                          return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
92
-                         '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;"  href="?sec_token='.$token.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
93
-                         '\';
92
+                            '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;"  href="?sec_token='.$token.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
93
+                            '\';
94 94
                  }';
95 95
 ?>
96 96
 <script>
Please login to merge, or discard this patch.
main/admin/access_url_add_usergroup_to_url.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@
 block discarded – undo
87 87
                   <?php
88 88
                     echo Display::get_alphabet_options($firstLetterUserGroup);
89 89
                     echo Display::get_numeric_options(0, 9, $firstLetterUserGroup);
90
-                  ?>
90
+                    ?>
91 91
             </select>
92 92
         </td>
93 93
         <td width="20%">&nbsp;</td>
Please login to merge, or discard this patch.
main/admin/subscribe_class2course.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
     <select name="firstLetterClass" onchange="javascript:document.formulaire.formSent.value='2'; document.formulaire.submit();">
91 91
      <option value="">--</option>
92 92
      <?php
93
-     echo Display::get_alphabet_options($first_letter_class);
94
-     ?>
93
+        echo Display::get_alphabet_options($first_letter_class);
94
+        ?>
95 95
     </select>
96 96
    </td>
97 97
    <td width="20%">&nbsp;</td>
@@ -102,8 +102,8 @@  discard block
 block discarded – undo
102 102
     <select name="firstLetterCourse" onchange="javascript:document.formulaire.formSent.value='2'; document.formulaire.submit();">
103 103
      <option value="">--</option>
104 104
      <?php
105
-     echo Display::get_alphabet_options($first_letter_course);
106
-     ?>
105
+        echo Display::get_alphabet_options($first_letter_course);
106
+        ?>
107 107
     </select>
108 108
    </td>
109 109
   </tr>
Please login to merge, or discard this patch.
main/admin/user_edit.php 1 patch
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -157,27 +157,27 @@  discard block
 block discarded – undo
157 157
 $form->addElement('hidden', 'user_id', $user_id);
158 158
 
159 159
 if (api_is_western_name_order()) {
160
-	// Firstname
161
-	$form->addElement('text', 'firstname', get_lang('FirstName'));
162
-	$form->applyFilter('firstname', 'html_filter');
163
-	$form->applyFilter('firstname', 'trim');
164
-	$form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
165
-	// Lastname
166
-	$form->addElement('text', 'lastname', get_lang('LastName'));
167
-	$form->applyFilter('lastname', 'html_filter');
168
-	$form->applyFilter('lastname', 'trim');
169
-	$form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
160
+    // Firstname
161
+    $form->addElement('text', 'firstname', get_lang('FirstName'));
162
+    $form->applyFilter('firstname', 'html_filter');
163
+    $form->applyFilter('firstname', 'trim');
164
+    $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
165
+    // Lastname
166
+    $form->addElement('text', 'lastname', get_lang('LastName'));
167
+    $form->applyFilter('lastname', 'html_filter');
168
+    $form->applyFilter('lastname', 'trim');
169
+    $form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
170 170
 } else {
171
-	// Lastname
172
-	$form->addElement('text', 'lastname', get_lang('LastName'));
173
-	$form->applyFilter('lastname', 'html_filter');
174
-	$form->applyFilter('lastname', 'trim');
175
-	$form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
176
-	// Firstname
177
-	$form->addElement('text', 'firstname', get_lang('FirstName'));
178
-	$form->applyFilter('firstname', 'html_filter');
179
-	$form->applyFilter('firstname', 'trim');
180
-	$form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
171
+    // Lastname
172
+    $form->addElement('text', 'lastname', get_lang('LastName'));
173
+    $form->applyFilter('lastname', 'html_filter');
174
+    $form->applyFilter('lastname', 'trim');
175
+    $form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
176
+    // Firstname
177
+    $form->addElement('text', 'firstname', get_lang('FirstName'));
178
+    $form->applyFilter('firstname', 'html_filter');
179
+    $form->applyFilter('firstname', 'trim');
180
+    $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
181 181
 }
182 182
 
183 183
 // Official code
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 
200 200
 // OpenID
201 201
 if (api_get_setting('openid_authentication') == 'true') {
202
-	$form->addElement('text', 'openid', get_lang('OpenIDURL'));
202
+    $form->addElement('text', 'openid', get_lang('OpenIDURL'));
203 203
 }
204 204
 
205 205
 // Phone
@@ -225,18 +225,18 @@  discard block
 block discarded – undo
225 225
 $form->addHidden('cropResult', '');
226 226
 
227 227
 $form->addRule(
228
-	'picture',
229
-	get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')',
230
-	'filetype',
231
-	$allowed_picture_types
228
+    'picture',
229
+    get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')',
230
+    'filetype',
231
+    $allowed_picture_types
232 232
 );
233 233
 if (strlen($user_data['picture_uri']) > 0) {
234
-	$form->addElement('checkbox', 'delete_picture', '', get_lang('DelImage'));
234
+    $form->addElement('checkbox', 'delete_picture', '', get_lang('DelImage'));
235 235
 }
236 236
 
237 237
 // Username
238 238
 if (api_get_setting('login_is_email') != 'true') {
239
-	$form->addElement('text', 'username', get_lang('LoginName'), array('maxlength' => USERNAME_MAX_LENGTH));
239
+    $form->addElement('text', 'username', get_lang('LoginName'), array('maxlength' => USERNAME_MAX_LENGTH));
240 240
     $form->addRule('username', get_lang('ThisFieldIsRequired'), 'required');
241 241
     $form->addRule('username', sprintf(get_lang('UsernameMaxXCharacters'), (string)USERNAME_MAX_LENGTH), 'maxlength', USERNAME_MAX_LENGTH);
242 242
     $form->addRule('username', get_lang('OnlyLettersAndNumbersAllowed'), 'username');
@@ -308,15 +308,15 @@  discard block
 block discarded – undo
308 308
 
309 309
 // Platform admin
310 310
 if (api_is_platform_admin()) {
311
-	$group = array();
312
-	$group[] =$form->createElement('radio', 'platform_admin', null, get_lang('Yes'), 1);
313
-	$group[] =$form->createElement('radio', 'platform_admin', null, get_lang('No'), 0);
311
+    $group = array();
312
+    $group[] =$form->createElement('radio', 'platform_admin', null, get_lang('Yes'), 1);
313
+    $group[] =$form->createElement('radio', 'platform_admin', null, get_lang('No'), 0);
314 314
 
315
-	$user_data['status'] == 1 ? $display = 'block':$display = 'none';
315
+    $user_data['status'] == 1 ? $display = 'block':$display = 'none';
316 316
 
317
-	$form->addElement('html', '<div id="id_platform_admin" style="display:'.$display.'">');
318
-	$form->addGroup($group, 'admin', get_lang('PlatformAdmin'), null, false);
319
-	$form->addElement('html', '</div>');
317
+    $form->addElement('html', '<div id="id_platform_admin" style="display:'.$display.'">');
318
+    $form->addGroup($group, 'admin', get_lang('PlatformAdmin'), null, false);
319
+    $form->addElement('html', '</div>');
320 320
 }
321 321
 
322 322
 //Language
@@ -334,16 +334,16 @@  discard block
 block discarded – undo
334 334
 $form->addElement('label', get_lang('RegistrationDate'), $date);
335 335
 
336 336
 if (!$user_data['platform_admin']) {
337
-	// Expiration Date
338
-	$form->addElement('radio', 'radio_expiration_date', get_lang('ExpirationDate'), get_lang('NeverExpires'), 0);
339
-	$group = array ();
340
-	$group[] = $form->createElement('radio', 'radio_expiration_date', null, get_lang('Enabled'), 1);
341
-	$group[] = $form->createElement('DateTimePicker', 'expiration_date', null, array('onchange' => 'javascript: enable_expiration_date();'));
342
-	$form->addGroup($group, 'max_member_group', null, '', false);
343
-
344
-	// Active account or inactive account
345
-	$form->addElement('radio', 'active', get_lang('ActiveAccount'), get_lang('Active'), 1);
346
-	$form->addElement('radio', 'active', '', get_lang('Inactive'), 0);
337
+    // Expiration Date
338
+    $form->addElement('radio', 'radio_expiration_date', get_lang('ExpirationDate'), get_lang('NeverExpires'), 0);
339
+    $group = array ();
340
+    $group[] = $form->createElement('radio', 'radio_expiration_date', null, get_lang('Enabled'), 1);
341
+    $group[] = $form->createElement('DateTimePicker', 'expiration_date', null, array('onchange' => 'javascript: enable_expiration_date();'));
342
+    $form->addGroup($group, 'max_member_group', null, '', false);
343
+
344
+    // Active account or inactive account
345
+    $form->addElement('radio', 'active', get_lang('ActiveAccount'), get_lang('Active'), 1);
346
+    $form->addElement('radio', 'active', '', get_lang('Inactive'), 0);
347 347
 }
348 348
 
349 349
 // EXTRA FIELDS
@@ -366,18 +366,18 @@  discard block
 block discarded – undo
366 366
 $expiration_date = $user_data['expiration_date'];
367 367
 
368 368
 if (empty($expiration_date)) {
369
-	$user_data['radio_expiration_date'] = 0;
370
-	$user_data['expiration_date'] = api_get_local_time();
369
+    $user_data['radio_expiration_date'] = 0;
370
+    $user_data['expiration_date'] = api_get_local_time();
371 371
 } else {
372
-	$user_data['radio_expiration_date'] = 1;
373
-	$user_data['expiration_date'] = api_get_local_time($expiration_date);
372
+    $user_data['radio_expiration_date'] = 1;
373
+    $user_data['expiration_date'] = api_get_local_time($expiration_date);
374 374
 }
375 375
 $form->setDefaults($user_data);
376 376
 
377 377
 $error_drh = false;
378 378
 // Validate form
379 379
 if ($form->validate()) {
380
-	$user = $form->getSubmitValues(1);
380
+    $user = $form->getSubmitValues(1);
381 381
     $reset_password = intval($user['reset_password']);
382 382
     if ($reset_password == 2 && empty($user['password'])) {
383 383
         Display::addFlash(Display::return_message(get_lang('PasswordIsTooShort')));
@@ -385,18 +385,18 @@  discard block
 block discarded – undo
385 385
         exit();
386 386
     }
387 387
 
388
-	$is_user_subscribed_in_course = CourseManager::is_user_subscribed_in_course($user['user_id']);
388
+    $is_user_subscribed_in_course = CourseManager::is_user_subscribed_in_course($user['user_id']);
389 389
 
390
-	if ($user['status'] == DRH && $is_user_subscribed_in_course) {
391
-		$error_drh = true;
392
-	} else {
393
-		$picture_element = $form->getElement('picture');
394
-		$picture = $picture_element->getValue();
390
+    if ($user['status'] == DRH && $is_user_subscribed_in_course) {
391
+        $error_drh = true;
392
+    } else {
393
+        $picture_element = $form->getElement('picture');
394
+        $picture = $picture_element->getValue();
395 395
 
396
-		$picture_uri = $user_data['picture_uri'];
397
-		if (isset($user['delete_picture']) && $user['delete_picture']) {
398
-			$picture_uri = UserManager::delete_user_picture($user_id);
399
-		} elseif (!empty($picture['name'])) {
396
+        $picture_uri = $user_data['picture_uri'];
397
+        if (isset($user['delete_picture']) && $user['delete_picture']) {
398
+            $picture_uri = UserManager::delete_user_picture($user_id);
399
+        } elseif (!empty($picture['name'])) {
400 400
             $picture_uri = UserManager::update_user_picture(
401 401
                 $user_id,
402 402
                 $_FILES['picture']['name'],
@@ -404,30 +404,30 @@  discard block
 block discarded – undo
404 404
                 $user['cropResult']
405 405
                     
406 406
             );
407
-		}
407
+        }
408 408
 
409
-		$lastname = $user['lastname'];
410
-		$firstname = $user['firstname'];
409
+        $lastname = $user['lastname'];
410
+        $firstname = $user['firstname'];
411 411
         $password = $user['password'];
412 412
         $auth_source = isset($user['auth_source']) ? $user['auth_source'] : $userInfo['auth_source'];
413
-		$official_code = $user['official_code'];
414
-		$email = $user['email'];
415
-		$phone = $user['phone'];
416
-		$username = isset($user['username']) ? $user['username'] : $userInfo['username'];
417
-		$status = intval($user['status']);
418
-		$platform_admin = intval($user['platform_admin']);
419
-		$send_mail = intval($user['send_mail']);
420
-		$reset_password = intval($user['reset_password']);
421
-		$hr_dept_id = isset($user['hr_dept_id']) ? intval($user['hr_dept_id']) : null;
422
-		$language = $user['language'];
423
-
424
-		if ($user['radio_expiration_date'] == '1' && !$user_data['platform_admin']) {
413
+        $official_code = $user['official_code'];
414
+        $email = $user['email'];
415
+        $phone = $user['phone'];
416
+        $username = isset($user['username']) ? $user['username'] : $userInfo['username'];
417
+        $status = intval($user['status']);
418
+        $platform_admin = intval($user['platform_admin']);
419
+        $send_mail = intval($user['send_mail']);
420
+        $reset_password = intval($user['reset_password']);
421
+        $hr_dept_id = isset($user['hr_dept_id']) ? intval($user['hr_dept_id']) : null;
422
+        $language = $user['language'];
423
+
424
+        if ($user['radio_expiration_date'] == '1' && !$user_data['platform_admin']) {
425 425
             $expiration_date = $user['expiration_date'];
426
-		} else {
427
-			$expiration_date = null;
428
-		}
426
+        } else {
427
+            $expiration_date = null;
428
+        }
429 429
 
430
-		$active = $user_data['platform_admin'] ? 1 : intval($user['active']);
430
+        $active = $user_data['platform_admin'] ? 1 : intval($user['active']);
431 431
 
432 432
         //If the user is set to admin the status will be overwrite by COURSEMANAGER = 1
433 433
         if ($platform_admin == 1) {
@@ -461,31 +461,31 @@  discard block
 block discarded – undo
461 461
             $reset_password
462 462
         );
463 463
 
464
-		if (api_get_setting('openid_authentication') == 'true' && !empty($user['openid'])) {
465
-			$up = UserManager::update_openid($user_id, $user['openid']);
466
-		}
464
+        if (api_get_setting('openid_authentication') == 'true' && !empty($user['openid'])) {
465
+            $up = UserManager::update_openid($user_id, $user['openid']);
466
+        }
467 467
         $currentUserId = api_get_user_id();
468
-		if ($user_id != $currentUserId) {
469
-			if ($platform_admin == 1) {
468
+        if ($user_id != $currentUserId) {
469
+            if ($platform_admin == 1) {
470 470
                 UserManager::add_user_as_admin($user_id);
471
-			} else {
471
+            } else {
472 472
                 UserManager::remove_user_admin($user_id);
473
-			}
474
-		}
473
+            }
474
+        }
475 475
 
476 476
         $extraFieldValue = new ExtraFieldValue('user');
477 477
         $extraFieldValue->saveFieldValues($user);
478 478
 
479
-		$tok = Security::get_token();
480
-		header('Location: user_list.php?action=show_message&message='.urlencode(get_lang('UserUpdated')).'&sec_token='.$tok);
481
-		exit();
482
-	}
479
+        $tok = Security::get_token();
480
+        header('Location: user_list.php?action=show_message&message='.urlencode(get_lang('UserUpdated')).'&sec_token='.$tok);
481
+        exit();
482
+    }
483 483
 }
484 484
 
485 485
 $message = null;
486 486
 if ($error_drh) {
487
-	$err_msg = get_lang('StatusCanNotBeChangedToHumanResourcesManager');
488
-	$message = Display::return_message($err_msg, 'error');
487
+    $err_msg = get_lang('StatusCanNotBeChangedToHumanResourcesManager');
488
+    $message = Display::return_message($err_msg, 'error');
489 489
 }
490 490
 
491 491
 $content = null;
Please login to merge, or discard this patch.
main/admin/add_courses_to_usergroup.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -229,31 +229,31 @@  discard block
 block discarded – undo
229 229
   <td align="center">
230 230
   <div id="content_source">
231 231
       <?php
232
-      if (!($add_type=='multiple')) {
232
+        if (!($add_type=='multiple')) {
233 233
         ?>
234 234
         <input type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,'single')" />
235 235
         <div id="ajax_list_users_single"></div>
236 236
         <?php
237
-      } else {
238
-      ?>
237
+        } else {
238
+        ?>
239 239
       <div id="ajax_list_multiple">
240 240
         <?php echo Display::select('elements_not_in_name', $elements_not_in, '', array('style'=>'width:360px', 'multiple'=>'multiple','id'=>'elements_not_in','size'=>'15px'),false); ?>
241 241
       </div>
242 242
     <?php
243
-      }
244
-     ?>
243
+        }
244
+        ?>
245 245
   </div>
246 246
   </td>
247 247
   <td width="10%" valign="middle" align="center">
248 248
   <?php
249
-  if ($ajax_search) {
250
-  ?>
249
+    if ($ajax_search) {
250
+    ?>
251 251
     <button class="btn bt-default" type="button" onclick="remove_item(document.getElementById('elements_in'))" >
252 252
         <em class="fa fa-arrow-left"></em>
253 253
     </button>
254 254
   <?php
255
-  } else {
256
-  ?>
255
+    } else {
256
+    ?>
257 257
     <button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('elements_not_in'), document.getElementById('elements_in'))" onclick="moveItem(document.getElementById('elements_not_in'), document.getElementById('elements_in'))">
258 258
         <em class="fa fa-arrow-right"></em>
259 259
     </button>
@@ -262,8 +262,8 @@  discard block
 block discarded – undo
262 262
         <em class="fa fa-arrow-left"></em>
263 263
     </button>
264 264
     <?php
265
-  }
266
-  ?>
265
+    }
266
+    ?>
267 267
     <br /><br /><br /><br /><br /><br />
268 268
   </td>
269 269
   <td align="center">
Please login to merge, or discard this patch.
main/admin/user_export.php 1 patch
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /* For licensing terms, see /license.txt */
3 3
 /**
4
- *	@package chamilo.admin
5
- */
4
+         *	@package chamilo.admin
5
+         */
6 6
 
7 7
 $cidReset = true;
8 8
 
@@ -29,20 +29,20 @@  discard block
 block discarded – undo
29 29
 global $_configuration;
30 30
 
31 31
 if (api_is_multiple_url_enabled()) {
32
-	$tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
33
-	$access_url_id = api_get_current_access_url_id();
34
-	if ($access_url_id != -1){
35
-	$sql = "SELECT code,visual_code,title
32
+    $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
33
+    $access_url_id = api_get_current_access_url_id();
34
+    if ($access_url_id != -1){
35
+    $sql = "SELECT code,visual_code,title
36 36
 		FROM $course_table as c
37 37
 		INNER JOIN $tbl_course_rel_access_url as course_rel_url
38 38
 		ON (c.id = course_rel_url.c_id)
39 39
 		WHERE access_url_id = $access_url_id
40 40
 		ORDER BY visual_code";
41
-	}
41
+    }
42 42
 }
43 43
 $result = Database::query($sql);
44 44
 while ($course = Database::fetch_object($result)) {
45
-	$courses[$course->code] = $course->visual_code.' - '.$course->title;
45
+    $courses[$course->code] = $course->visual_code.' - '.$course->title;
46 46
 }
47 47
 $form = new FormValidator('export_users');
48 48
 $form->addElement('header', $tool_name);
@@ -56,13 +56,13 @@  discard block
 block discarded – undo
56 56
 $form->setDefaults(array('file_type' => 'csv'));
57 57
 
58 58
 if ($form->validate()) {
59
-	$export = $form->exportValues();
60
-	$file_type = $export['file_type'];
61
-	$course_code = Database::escape_string($export['course_code']);
62
-	$courseInfo = api_get_course_info($course_code);
63
-	$courseId = $courseInfo['real_id'];
59
+    $export = $form->exportValues();
60
+    $file_type = $export['file_type'];
61
+    $course_code = Database::escape_string($export['course_code']);
62
+    $courseInfo = api_get_course_info($course_code);
63
+    $courseId = $courseInfo['real_id'];
64 64
 
65
-	$sql = "SELECT
65
+    $sql = "SELECT
66 66
 				u.user_id 	AS UserId,
67 67
 				u.lastname 	AS LastName,
68 68
 				u.firstname 	AS FirstName,
@@ -73,96 +73,96 @@  discard block
 block discarded – undo
73 73
 				u.status		AS Status,
74 74
 				u.official_code	AS OfficialCode,
75 75
 				u.phone		AS Phone";
76
-	if (strlen($course_code) > 0) {
77
-		$sql .= " FROM $user_table u, $course_user_table cu
76
+    if (strlen($course_code) > 0) {
77
+        $sql .= " FROM $user_table u, $course_user_table cu
78 78
 					WHERE
79 79
 						u.user_id = cu.user_id AND
80 80
 						cu.c_id = $courseId AND
81 81
 						cu.relation_type<>".COURSE_RELATION_TYPE_RRHH."
82 82
 					ORDER BY lastname,firstname";
83
-		$filename = 'export_users_'.$course_code.'_'.api_get_local_time();
84
-	} else {
85
-		if (api_is_multiple_url_enabled()) {
86
-			$tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
87
-			$access_url_id = api_get_current_access_url_id();
88
-			if ($access_url_id != -1) {
89
-			$sql.= " FROM $user_table u
83
+        $filename = 'export_users_'.$course_code.'_'.api_get_local_time();
84
+    } else {
85
+        if (api_is_multiple_url_enabled()) {
86
+            $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
87
+            $access_url_id = api_get_current_access_url_id();
88
+            if ($access_url_id != -1) {
89
+            $sql.= " FROM $user_table u
90 90
 					INNER JOIN $tbl_user_rel_access_url as user_rel_url
91 91
 				ON (u.user_id= user_rel_url.user_id)
92 92
 				WHERE access_url_id = $access_url_id
93 93
 				ORDER BY lastname,firstname";
94
-			}
95
-		} else {
96
-			$sql .= " FROM $user_table u ORDER BY lastname,firstname";
97
-		}
98
-		$filename = 'export_users_'.api_get_local_time();
99
-	}
100
-	$data = array();
101
-	$extra_fields = UserManager::get_extra_fields(0, 0, 5, 'ASC',false);
102
-	if ($export['addcsvheader']=='1' AND $export['file_type']=='csv') {
103
-		if ($_configuration['password_encryption'] != 'none') {
104
-			$data[] = array(
105
-				'UserId',
106
-				'LastName',
107
-				'FirstName',
108
-				'Email',
109
-				'UserName',
110
-				'AuthSource',
111
-				'Status',
112
-				'OfficialCode',
113
-				'PhoneNumber',
114
-			);
115
-		} else {
116
-			$data[] = array(
117
-				'UserId',
118
-				'LastName',
119
-				'FirstName',
120
-				'Email',
121
-				'UserName',
122
-				'Password',
123
-				'AuthSource',
124
-				'Status',
125
-				'OfficialCode',
126
-				'PhoneNumber',
127
-			);
128
-		}
129
-
130
-		foreach($extra_fields as $extra) {
131
-			$data[0][]=$extra[1];
132
-		}
133
-	}
134
-
135
-	$res = Database::query($sql);
136
-	while($user = Database::fetch_array($res,'ASSOC')) {
137
-		$student_data = UserManager:: get_extra_user_data(
138
-			$user['UserId'],
139
-			true,
140
-			false
141
-		);
142
-		foreach($student_data as $key=>$value) {
143
-			$key = substr($key, 6);
144
-			if (is_array($value)) {
145
-				$user[$key] = $value[$key];
146
-			} else {
147
-				$user[$key] = $value;
148
-			}
149
-		}
150
-		$data[] = $user	;
151
-	}
152
-
153
-	switch ($file_type) {
154
-		case 'xml':
155
-			Export::arrayToXml($data, $filename, 'Contact', 'Contacts');
156
-			exit;
157
-			break;
158
-		case 'csv':
159
-			Export::arrayToCsv($data, $filename);
160
-			exit;
161
-		case 'xls':
162
-			Export::arrayToXls($data, $filename);
163
-			exit;
164
-			break;
165
-	}
94
+            }
95
+        } else {
96
+            $sql .= " FROM $user_table u ORDER BY lastname,firstname";
97
+        }
98
+        $filename = 'export_users_'.api_get_local_time();
99
+    }
100
+    $data = array();
101
+    $extra_fields = UserManager::get_extra_fields(0, 0, 5, 'ASC',false);
102
+    if ($export['addcsvheader']=='1' AND $export['file_type']=='csv') {
103
+        if ($_configuration['password_encryption'] != 'none') {
104
+            $data[] = array(
105
+                'UserId',
106
+                'LastName',
107
+                'FirstName',
108
+                'Email',
109
+                'UserName',
110
+                'AuthSource',
111
+                'Status',
112
+                'OfficialCode',
113
+                'PhoneNumber',
114
+            );
115
+        } else {
116
+            $data[] = array(
117
+                'UserId',
118
+                'LastName',
119
+                'FirstName',
120
+                'Email',
121
+                'UserName',
122
+                'Password',
123
+                'AuthSource',
124
+                'Status',
125
+                'OfficialCode',
126
+                'PhoneNumber',
127
+            );
128
+        }
129
+
130
+        foreach($extra_fields as $extra) {
131
+            $data[0][]=$extra[1];
132
+        }
133
+    }
134
+
135
+    $res = Database::query($sql);
136
+    while($user = Database::fetch_array($res,'ASSOC')) {
137
+        $student_data = UserManager:: get_extra_user_data(
138
+            $user['UserId'],
139
+            true,
140
+            false
141
+        );
142
+        foreach($student_data as $key=>$value) {
143
+            $key = substr($key, 6);
144
+            if (is_array($value)) {
145
+                $user[$key] = $value[$key];
146
+            } else {
147
+                $user[$key] = $value;
148
+            }
149
+        }
150
+        $data[] = $user	;
151
+    }
152
+
153
+    switch ($file_type) {
154
+        case 'xml':
155
+            Export::arrayToXml($data, $filename, 'Contact', 'Contacts');
156
+            exit;
157
+            break;
158
+        case 'csv':
159
+            Export::arrayToCsv($data, $filename);
160
+            exit;
161
+        case 'xls':
162
+            Export::arrayToXls($data, $filename);
163
+            exit;
164
+            break;
165
+    }
166 166
 }
167 167
 
168 168
 Display :: display_header($tool_name);
Please login to merge, or discard this patch.