forked from lynxlab/ada2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.php
382 lines (343 loc) · 18.6 KB
/
info.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<?php
/**
*
* @package user
* @author Stefano Penge <steve@lynxlab.com>
* @author Maurizio "Graffio" Mazzoneschi <graffio@lynxlab.com>
* @author Vito Modena <vito@lynxlab.com>
* @copyright Copyright (c) 2009-2010, Lynx s.r.l.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU Public License v.2
* @link info
* @version 0.1
*/
/**
* Base config file
*/
require_once realpath(dirname(__FILE__)) . '/config_path.inc.php';
/**
* Clear node and layout variable in $_SESSION
*/
$variableToClearAR = array('node', 'layout', 'course', 'course_instance');
/**
* Performs basic controls before entering this module
*/
/**
* Users (types) allowed to access this module.
*/
$allowedUsersAr = array(AMA_TYPE_VISITOR, AMA_TYPE_STUDENT, AMA_TYPE_TUTOR, AMA_TYPE_AUTHOR, AMA_TYPE_SWITCHER);
/**
* Get needed objects
*/
$neededObjAr = array(
AMA_TYPE_VISITOR => array('layout'),
AMA_TYPE_STUDENT => array('layout'),
AMA_TYPE_TUTOR => array('layout'),
AMA_TYPE_AUTHOR => array('layout'),
AMA_TYPE_SWITCHER => array('layout'),
AMA_TYPE_ADMIN => array('layout')
);
require_once ROOT_DIR . '/include/module_init.inc.php';
require_once ROOT_DIR . '/browsing/include/browsing_functions.inc.php';
$op = DataValidator::validate_string($_GET['op']);
$today_date = today_dateFN();
//$self = 'list_chatrooms'; // x template
//$self = whoami();
if($op !== false && $op == 'course_info') {
$serviceId = DataValidator::is_uinteger($_GET['id']);
if($serviceId !== false && $serviceId > 0) {
$coursesAr = $common_dh->get_courses_for_service($serviceId);
$thead_data = array(translateFN('data inizio previsto'), translateFN('data fine'),translateFN('crediti'), translateFN('azioni'));
//$thead_data = array(translateFN('nome'), translateFN('data inizio previsto'), translateFN('durata'), translateFN('data fine'), translateFN('tutor'), translateFN('azioni'));
$tbody_data = array();
if(!AMA_Common_DataHandler::isError($coursesAr)) {
$currentTesterId = 0;
$currentTester = '';
$tester_dh = null;
foreach($coursesAr as $courseData) {
$newTesterId = $courseData['id_tester'];
if($newTesterId != $currentTesterId) {
$testerInfoAr = $common_dh->get_tester_info_from_id($newTesterId,'AMA_FETCH_ASSOC');
if(!AMA_Common_DataHandler::isError($testerInfoAr)) {
$provider_name = $testerInfoAr[1];
$tester = $testerInfoAr[10];
// $tester = $testerInfoAr['puntatore'];
// get_tester_info_from_id usa $db->getRow quindi restituisce un array numerico
$tester_dh = AMA_DataHandler::instance(MultiPort::getDSN($tester));
$currentTesterId = $newTesterId;
$course_dataHa = $tester_dh->get_course($courseId);
if (!AMA_DataHandler::isError($course_dataHa)) {
$credits = $course_dataHa['crediti'];
// supponiamo che tutti i corsi di un servizio (su tester diversi) abbiano lo stesso numero di crediti
// quindi prendiamo solo l'ultimo
} else {
$credits = 1; // should be ADA_DEFAULT_COURSE_CREDITS
}
}
}
$courseId = $courseData['id_corso'];
//ISTANZE CORSO NON INIZIATE
$instancesAr = $tester_dh->course_instance_subscribeable_get_list(
array('data_inizio_previsto', 'durata', 'data_fine', 'title'),
$courseId);
if(is_array($instancesAr) && count($instancesAr) > 0) {
foreach($instancesAr as $instance) {
$instanceId = $instance[0];
$subscribe_link = BaseHtmlLib::link(
"info.php?op=subscribe&provider=$currentTesterId&course=$courseId&instance=$instanceId",
translateFN('Iscriviti'));
/*
* Da migliorare, spostare l'ottenimento dei dati necessari in un'unica query
* per ogni istanza corso (qualcosa che vada a sostituire course_instance_get_list solo in questo caso.
*/
$tutorId = $tester_dh->course_instance_tutor_get($instanceId);
if(!AMA_DataHandler::isError($tutorId) && $tutorId !== false) {
$tutor_infoAr = $tester_dh->get_tutor($tutorId);
if(!AMA_DataHandler::isError($tutor_infoAr)) {
$tutorFullName = $tutor_infoAr['nome'] . ' ' . $tutor_infoAr['cognome'];
} else {
$tutorFullName = translateFN('Utente non trovato');
}
} else {
$tutorFullName = translateFN('Ancora non assegnato');
}
$duration = sprintf("%d giorni", $instance[2]);
$scheduled = AMA_DataHandler::ts_to_date($instance[1]);
$end_date = AMA_DataHandler::ts_to_date($instance[3]);
$nome_instanza = $instance[4];
$course_infoAr = $tester_dh->get_course_info_for_course_instance($instanceId);
/*
* The first element of the array come from concat_ws
* the key of the array is like this [concat_ws(' ',u.nome,u.cognome)]
* the best way to get the value is to access directly the value
*/
list($key,$author_name) = each($course_infoAr);
/*
* The first element of the array come from concat_ws
*/
$label = translateFN('Corso') .': '. $course_infoAr['nome'].' - '.$course_infoAr['titolo'] . ' - '
. translateFN('Ente').': '.$provider_name; //.' - ' . translateFN('Autore'). ': '. $author_name;
// print_r($value);
// $output = array_slice($course_infoAr, 0, 1);
// print_r($output);
/*
$tbody_data[] = array(
$nome_instanza,
$scheduled,
$duration,
$end_date,
$tutorFullName,
$subscribe_link
);
*
*/
$tbody_data[] = array(
$scheduled ,
// $duration, why?
$end_date,
// $tutorFullName, why?
$credits,
$subscribe_link
);
}
}
}
}
if(count($tbody_data) > 0) {
$data = BaseHtmlLib::tableElement('', $thead_data, $tbody_data);
} else {
$course_infoAr = $tester_dh->get_course($courseId);
// print_r($course_infoAr);
$label = translateFN('Corso') .': '. $course_infoAr['nome'].' - '.$course_infoAr['titolo'] . ' - '
. translateFN('Ente').': '.$provider_name;
$data = new CText(translateFN('Al momento non sono presenti edizioni del corso a cui puoi iscriverti'));
}
} else {
$data = new CText('Corso non trovato');
}
} else if($op !== false && $op == 'subscribe') {
$providerId = DataValidator::is_uinteger($_GET['provider']);
$courseId = DataValidator::is_uinteger($_GET['course']);
$instanceId = DataValidator::is_uinteger($_GET['instance']);
$_SESSION['subscription_page'] = HTTP_ROOT_DIR . '/info.php?op=subscribe&provider='.$providerId.
'&course='.$courseId.'&instance='.$instanceId;
if($userObj instanceof ADAUser) {
if($providerId !== false && $courseId !== false && $instanceId !== false) {
$testerInfoAr = $common_dh->get_tester_info_from_id($providerId);
if(!AMA_Common_DataHandler::isError($testerInfoAr)) {
$tester = $testerInfoAr[10];
$provider_name = $testerInfoAr[1];
$testersAr[0] = $tester; // it is a pointer (string)
$tester_dh = AMA_DataHandler::instance(MultiPort::getDSN($tester));
$course_instance_infoAR = $tester_dh->course_instance_get($instanceId);
if (!AMA_DataHandler::isError($course_instance_infoAR)) {
$startStudentLevel = $course_instance_infoAR['start_level_student'];
// add user to tester DB
$id_tester_user = Multiport::setUser($userObj,$testersAr,$update_user_data = FALSE);
if ($id_tester_user !== FALSE ) {
$result = $tester_dh->course_instance_student_presubscribe_add($instanceId, $userObj->getId(),$startStudentLevel);
if(!AMA_DataHandler::isError($result) || $result->code == AMA_ERR_UNIQUE_KEY) {
$data = new CText(translateFN('La tua preiscrizione è stata effettuata con successo.'));
if ($course_instance_infoAR['price'] > 0) {
$args = '?provider='.$providerId.'&course='.$courseId.'&instance='.$instanceId;
header('Location: ' . HTTP_ROOT_DIR . '/browsing/student_course_instance_subscribe.php'.$args);
exit();
} else {
$result = $tester_dh->course_instance_student_subscribe($instanceId, $userObj->getId(),ADA_STATUS_SUBSCRIBED, $startStudentLevel);
if(!AMA_DataHandler::isError($result)) {
$info_div = CDOMElement::create('DIV', 'id:info_div');
$info_div->setAttribute('class', 'info_div');
$label_text = CDOMElement::create('span','class:info');
$label_text->addChild(new CText(translateFN('La tua iscrizione è stata effettuata con successo.')));
$info_div->addChild($label_text);
$homeUser = $userObj->getHomePage();
$link_span = CDOMElement::create('span','class:info_link');
$link_to_home = BaseHtmlLib::link($homeUser, translateFN('vai alla home per accedere.'));
$link_span->addChild($link_to_home);
$info_div->addChild($link_span);
//$data = new CText(translateFN('La tua iscrizione è stata effettuata con successo.'));
$data = $info_div;
}
}
// } else if($result->code == AMA_ERR_UNIQUE_KEY) {
// $data = new CText(translateFN('Risulti già preiscritto a questa edizione del corso'));
} else {
$data = new CText(translateFN('Si è verificato un errore'));
}
} else {
$data = new CText('Si è verificato un errore aggiungendo lo studente al provider');
}
}
$course_infoAr = $tester_dh->get_course_info_for_course_instance($instanceId);
/*
* The first element of the array come from concat_ws
* the key of the array is like this [concat_ws(' ',u.nome,u.cognome)]
* the best way to get the value is to access directly the value
*/
list($key,$author_name) = each($course_infoAr);
/*
* The first element of the array come from concat_ws
*/
$label = translateFN('Corso') .': '. $course_infoAr['nome'].' - '.$course_infoAr['titolo'] . ' - '
. translateFN('Ente').': '.$provider_name; //.' - ' . translateFN('Autore'). ': '. $author_name;
} else {
$data = new CText('Si è verificato un errore');
}
}
} else {
header('Location: ' . HTTP_ROOT_DIR . '/login_required.php');
exit();
}
} else if (($op !== false && $op == 'undo_subscription')) {
$providerId = DataValidator::is_uinteger($_GET['provider']);
$courseId = DataValidator::is_uinteger($_GET['course']);
$instanceId = DataValidator::is_uinteger($_GET['instance']);
$studentId = DataValidator::is_uinteger($_GET['student']);
$testerInfoAr = $common_dh->get_tester_info_from_id($providerId);
if(!AMA_Common_DataHandler::isError($testerInfoAr)) {
$tester = $testerInfoAr[10];
$provider_name = $testerInfoAr[1];
$testersAr[0] = $tester; // it is a pointer (string)
$tester_dh = AMA_DataHandler::instance(MultiPort::getDSN($tester));
$course_instance_infoAR = $tester_dh->course_instance_get($instanceId);
if (!AMA_DataHandler::isError($course_instance_infoAR)) {
$result = $tester_dh->course_instance_student_presubscribe_remove($instanceId, $userObj->getId());
if(!AMA_DataHandler::isError($result)) {
$info_div = CDOMElement::create('DIV', 'id:info_div');
$info_div->setAttribute('class', 'info_div');
$label_text = CDOMElement::create('span','class:info');
$label_text->addChild(new CText(translateFN('La tua pre-iscrizione è stata annullata.')));
$info_div->addChild($label_text);
$homeUser = $userObj->getHomePage();
$link_span = CDOMElement::create('span','class:info_link');
$link_to_home = BaseHtmlLib::link($homeUser, translateFN('Torna alla home.'));
$link_span->addChild($link_to_home);
$info_div->addChild($link_span);
$data = $info_div;
} else {
$info_div = CDOMElement::create('DIV', 'id:info_div');
$info_div->setAttribute('class', 'info_div');
$label_text = CDOMElement::create('span','class:info');
$label_text->addChild(new CText(translateFN("C'è stato un problema annullando la tua pre-iscrizione.")));
$info_div->addChild($label_text);
$homeUser = $userObj->getHomePage();
$link_span = CDOMElement::create('span','class:info_link');
$link_to_home = BaseHtmlLib::link($homeUser, translateFN('Torna alla home.'));
$link_span->addChild($link_to_home);
$info_div->addChild($link_span);
//$data = new CText(translateFN('La tua iscrizione è stata effettuata con successo.'));
$data = $info_div;
}
}
}
}
else {
$publishedServices = $common_dh->get_published_courses();
if(!AMA_Common_DataHandler::isError($publishedServices)) {
// $thead_data = array('nome', 'descrizione', 'durata (giorni)', 'informazioni');
$thead_data = array(translateFN('nome'), translateFN('descrizione'), translateFN('crediti'), translateFN('informazioni'));
$tbody_data = array();
foreach($publishedServices as $service) {
// $serviceId = $service['id_servizio'];
$serviceId = $service['id_servizio'];
$coursesAr = $common_dh-> get_courses_for_service($serviceId);
if (!AMA_DataHandler::isError($coursesAr)) {
$currentTesterId = 0;
$currentTester = '';
$tester_dh = null;
foreach($coursesAr as $courseData) {
$courseId = $courseData['id_corso'];
$newTesterId = $courseData['id_tester'];
if($newTesterId != $currentTesterId) { // stesso corso su altro tester ?
$testerInfoAr = $common_dh->get_tester_info_from_id($newTesterId);
if(!AMA_Common_DataHandler::isError($testerInfoAr)) {
$tester = $testerInfoAr[10];
$tester_dh = AMA_DataHandler::instance(MultiPort::getDSN($tester));
$currentTesterId = $newTesterId;
$course_dataHa = $tester_dh->get_course($courseId);
if (!AMA_DataHandler::isError($course_dataHa)) {
$credits = $course_dataHa['crediti'];
// supponiamo che tutti i corsi di un servizio (su tester diversi) abbiano lo stesso numero di crediti
// quindi prendiamo solo l'ultimo
} else {
$credits = 1; // should be ADA_DEFAULT_COURSE_CREDITS
}
}
}
}
} else {
$credits = 1; // should be ADA_DEFAULT_COURSE_CREDITS
}
$more_info_link = BaseHtmlLib::link(
"info.php?op=course_info&id=$serviceId",
translateFN('More info'));
$tbody_data[] = array(
$service['nome'],
$service['descrizione'],
$credits,
// $service['durata_servizio'],
$more_info_link
);
}
$data = BaseHtmlLib::tableElement('', $thead_data, $tbody_data);
} else {
$data = new CText(translateFN('Non sono stati pubblicati corsi'));
}
}
$title = translateFN('Corsi ai quali puoi iscriverti');
$help = '';
$homeUser = $userObj->getHomePage();
$link_to_home = BaseHtmlLib::link($homeUser, translateFN('Home'));
$content_dataAr = array(
'course_title' => $title,
'user_name' => $user_name,
'user_type' => $user_type,
'status' => $status,
'label' => $label,
'help' => $help,
'data' => $data->getHtml(),
'home' => $link_to_home->getHtml()
);
/**
* Sends data to the rendering engine
*/
ARE::render($layout_dataAr, $content_dataAr);