-
Notifications
You must be signed in to change notification settings - Fork 10
/
info.php
778 lines (693 loc) · 37 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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
<?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';
BrowsingHelper::init($neededObjAr);
$op = isset($_GET['op']) ? DataValidator::validate_string($_GET['op']) : false;
$today_date = today_dateFN();
//$self = 'list_chatrooms'; // x template
$self = whoami();
/**
* Negotiate page language if needed
*/
if (!isset($_SESSION['sess_user_language'])) {
Translator::loadSupportedLanguagesInSession();
$_SESSION['sess_user_language'] = Translator::negotiateLoginPageLanguage();
}
if ($op !== false && $op == 'course_info') {
$self = 'course-info';
$serviceId = DataValidator::is_uinteger($_GET['id']);
if ($serviceId !== false && $serviceId > 0) {
$coursesAr = $common_dh->get_courses_for_service($serviceId);
}
if (isset($coursesAr) && !AMA_Common_DataHandler::isError($coursesAr) && is_array($coursesAr) && count($coursesAr)>0) {
$currentTesterId = 0;
$currentTester = '';
$tester_dh = null;
// This will be used to populate the template fields
$courseInfoContent = array();
$courseInfoContent['firstcol_wideness'] = 'sixteen wide';
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)) {
$layout_dataAr['widgets']['provider_address_map'] = array (
'isActive'=>0
);
$provider_name = $testerInfoAr['nome'];
$courseInfoContent['provider_name'] = $testerInfoAr['nome'];
if (isset($testerInfoAr['descrizione']) && strlen($testerInfoAr['descrizione'])>0) {
$courseInfoContent['provider_description'] = $testerInfoAr['descrizione'];
}
if (isset($_SESSION['mobile-detect']) && $_SESSION['mobile-detect']->isMobile()) {
$courseInfoContent['provider_phone'] = BaseHtmlLib::link('tel:'.$testerInfoAr['telefono'], $testerInfoAr['telefono'])->getHtml();
} else {
$courseInfoContent['provider_phone'] = $testerInfoAr['telefono'];
}
if (isset($testerInfoAr['indirizzo']) && strlen(trim($testerInfoAr['indirizzo']))>0) {
$provAddress = trim($testerInfoAr['indirizzo']);
if (isset($testerInfoAr['provincia']) && strlen(trim($testerInfoAr['provincia']))>0) {
$provAddress .= ' - '.trim($testerInfoAr['provincia']);
if (isset($testerInfoAr['citta']) && strlen(trim($testerInfoAr['citta']))>0) {
$provAddress .= ' ('.strtoupper(trim($testerInfoAr['citta'])).')';
}
}
$addressLink = BaseHtmlLib::link('https://www.google.com/maps/place/'.urlencode($provAddress), $provAddress);
$addressLink->setAttribute('target', '_blank');
$courseInfoContent['provider_address'] = $addressLink->getHtml();
// configure map widget
$layout_dataAr['widgets']['provider_address_map'] = array (
'url' => 'https://maps.googleapis.com/maps/api/staticmap?center='.urlencode($provAddress).'&zoom=17&size=338x199&maptype=roadmap'.
'&markers=size:mid%7C'.urlencode($provAddress),
'isActive'=> strlen(trim($provAddress))>0 ? 1 : 0,
);
}
if (isset($testerInfoAr['e_mail']) && strlen($testerInfoAr['e_mail'])>0) {
$courseInfoContent['provider_email'] = BaseHtmlLib::link('mailto:'.$testerInfoAr['e_mail'], $testerInfoAr['e_mail'])->getHtml();
}
$tester = $testerInfoAr['puntatore'];
$tester_dh = AMA_DataHandler::instance(MultiPort::getDSN($tester));
$currentTesterId = $newTesterId;
$courseId = $courseData['id_corso'];
$course_dataHa = $tester_dh->get_course($courseId);
if (!AMA_DataHandler::isError($course_dataHa)) {
// supponiamo che tutti i dati di un servizio (su tester diversi) abbiano lo stesso valore
// quindi prendiamo solo l'ultimo
$courseInfoContent['course_title'] = $course_dataHa['titolo'];
$courseInfoContent['course_description'] = $course_dataHa['descr'];
$creditsLbl = 'Credit'.(intval($course_dataHa['crediti'])===1?'o':'i');
$courseInfoContent['course_credits'] = intval($course_dataHa['crediti'])>0 ? $course_dataHa['crediti'] .' '.translateFN($creditsLbl) : null;
$courseInfoContent['course_language'] = Translator::getLanguageInfoForLanguageId($course_dataHa['id_lingua'])['nome_lingua'];
$durationLbl = 'Or'.(intval($course_dataHa['duration_hours'])===1?'a':'e');
$courseInfoContent['course_duration'] = intval($course_dataHa['duration_hours'])>0 ? $course_dataHa['duration_hours'].' '.translateFN($durationLbl) : null;
// displayMainIndex uses $hide_visits as a global... set it :(
$hide_visits = 1; // default: no visits countg
$main_index = CourseViewer::displayMainIndex($userObj, $courseId, 1, 'struct', null,'structIndex', $tester_dh);
if ($main_index instanceof CBaseElement) {
$courseInfoContent['course_index'] = $main_index->getHtml();
}
} else {
$courseInfoContent['course_title'] = translateFN('Il corso');
}
}
} // if($newTesterId != $currentTesterId)
// instances loop
$courseId = $courseData['id_corso'];
$timestamp = time();
$instancesAr = $tester_dh->course_instance_subscribeable_get_list(
array('data_inizio_previsto', 'durata', 'data_fine', 'title','price','self_instruction','duration_hours','tipo_servizio'),
$courseId);
$CourseIstanceIscription=$tester_dh->course_users_instance_get($courseId);
$id_node=$courseId.'_0';
if(!AMA_DB::isError($instancesAr) && is_array($instancesAr) && count($instancesAr) > 0) {
foreach($instancesAr as $instance) {
$instanceId = $instance[0];
$flagSubscribe_link=false;
$isEnded = ($instance[3] > 0 && $instance[3] < time()) ? true : false;
if ($isEnded) {
$subscribe_link = BaseHtmlLib::link("#",'<i class="ban circle icon"></i>'.translateFN('corso terminato'));
$subscribe_link->setAttribute('class', 'red ui labeled icon right floated button');
$flagSubscribe_link=true;
} else {
foreach($CourseIstanceIscription as $courseIstance) {
$id_istanza=$courseIstance['id_istanza_corso'];
if ($id_istanza == $instanceId) {
$id_utente = $courseIstance ['id_utente'];
if ($id_utente == $userObj->getId ()) {
/**
* Subscribe button
*/
$statusUr = $courseIstance ['status'];
if ($statusUr == ADA_STATUS_SUBSCRIBED || $statusUr == ADA_SERVICE_SUBSCRIPTION_STATUS_COMPLETED) {
if ($userObj->tipo == AMA_TYPE_VISITOR) {
$subscribe_link = BaseHtmlLib::link ("#",'<i class="checkmark icon"></i>'.translateFN ( 'Già iscritto' ));
$subscribe_link->setAttribute('class', 'green ui labeled icon right floated button');
$flagSubscribe_link = true;
}
if ($userObj->tipo == AMA_TYPE_STUDENT) {
$subscribe_link = BaseHtmlLib::link ("browsing/view.php?id_node=$id_node&id_course=$courseId&id_course_instance=$id_istanza",
'<i class="angle right icon"></i>'.translateFN ('Accedi'));
$subscribe_link->setAttribute('class', 'blue ui labeled icon right floated button');
$flagSubscribe_link = true;
}
} else {
$subscribe_link = BaseHtmlLib::link ("info.php?op=subscribe&provider=$currentTesterId&course=$courseId&instance=$instanceId",
'<i class="signup icon"></i>'.translateFN ('iscriviti'));
$subscribe_link->setAttribute('class', 'green ui labeled icon right floated button');
$flagSubscribe_link = true;
}
}
} // if ($id_istanza == $instanceId)
}
if (!$flagSubscribe_link) {
$subscribe_link = BaseHtmlLib::link ("info.php?op=subscribe&provider=$currentTesterId&course=$courseId&instance=$instanceId",
'<i class="signup icon"></i>'.translateFN ('iscriviti'));
$subscribe_link->setAttribute('class', 'green ui labeled icon right floated button');
}
} // else of if ($isEnded)
/*
* 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');
}
/**
* Get instance information
*/
$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];
// instance price
if (intval($instance[5])>=0) {
$priceLbl = (intval($instance[5])===0 ? translateFN('Gratuito') : ADA_CURRENCY_SYMBOL.' '.
number_format($instance[5],ADA_CURRENCY_DECIMALS, ADA_CURRENCY_DECIMAL_POINT, ADA_CURRENCY_THOUSANDS_SEP));
$instanceData['price'] = array(
'order' => 0,
'icon' => 'money',
'header' => translateFN('Costo'),
'data' => $priceLbl
);
}
// instance tutor or self instruction
if (intval($instance[6])>=0) {
$instanceData['tutor'] = array(
'order' => 4,
'icon' => 'user',
'header' => translateFN('Tutor'),
'data' => (intval($instance[6])===0 ? $tutorFullName : translateFN('Corso in autoistruzione'))
);
}
// instance duration hours
if (intval($instance[7])>0) {
$instanceData['durata'] = array(
'order' => 2,
'icon' => 'time',
'header' => translateFN('Durata'),
'data' => $instance[7].' '.(intval($instance[7])===1 ? translateFN('ora'): translateFN('ore'))
);
}
// instance service type
if (strlen($instance[8])>0) {
$servicelevel=null;
/* if isset $_SESSION['service_level'] it means that the istallation supports course type */
if(isset($_SESSION['service_level'][$instance[8]])){
$servicelevel=$_SESSION['service_level'][$instance[8]];
}
if(!isset($servicelevel) || is_null($servicelevel)){$servicelevel=DEFAULT_SERVICE_TYPE_NAME;}
$instanceData['servicelevel'] = array(
'order' => 1,
'icon' => 'browser',
'header' => translateFN('Tipo di corso'),
'data' => translateFN($servicelevel)
);
}
// instance start and end dates
if (strlen($scheduled)>0 || strlen($end_date)>0) {
$dates = '';
if (strlen($scheduled)>0) $dates .= translateFN('Dal').' '.$scheduled;
if (strlen($end_date)>0) $dates .= ' '.translateFN('al').' '.$end_date;
if (strlen($dates)>0) {
$instanceData['dates'] = array(
'order' => 3,
'icon' => 'calendar',
'header' => translateFN('Date'),
'data' => $dates
);
}
}
$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
*/
$author_name = reset($course_infoAr);
/*
* The first element of the array come from concat_ws
*/
$label = translateFN('Corso') .': '. $course_infoAr['nome'].' - '.$course_infoAr['titolo'] . ' - '
. translateFN('Fornito Da').': '.$provider_name; //.' - ' . translateFN('Autore'). ': '. $author_name;
if (!isset($instancesCDOM)) {
// set first column wideness
$courseInfoContent['firstcol_wideness'] = 'eleven wide';
// instatiate second column
$instancesCDOM = CDOMElement::create('div','class:secondcol five wide column');
}
// a container for the current instance
$container = CDOMElement::create('div','class:classinfo');
$instancesCDOM->addChild($container);
// instance name
$instanceNameDIV = CDOMElement::create('div','class:ui top attached segment item');
$instanceNameDIV->addChild(new CText('<i class="users large icon"></i>'.$nome_instanza));
$container->addChild($instanceNameDIV);
// instance data
if (isset($instanceData) && is_array($instanceData) && count($instanceData)>0) {
// sort instanceData by 'order' field
usort($instanceData, function ($item1, $item2) {
if ($item1['order'] == $item2['order']) return 0;
return $item1['order'] < $item2['order'] ? -1 : 1;
});
$instanceDataSEGMENT = CDOMElement::create('div','class:ui attached segment');
$instanceDataDIV = CDOMElement::create('div','class:ui horizontal floated list');
$instanceDataSEGMENT->addChild($instanceDataDIV);
foreach ($instanceData as $aData) {
$instanceDataITEM = CDOMElement::create('div','class:item');
$instanceDataCONTENT = CDOMElement::create('div','class:content');
$instanceDataHEADER = CDOMElement::create('div','class:header');
$instanceDataHEADER->addChild(new CText($aData['header']));
$instanceDataCONTENT->addChild($instanceDataHEADER);
$instanceDataCONTENT->addChild(new CText($aData['data']));
$instanceDataITEM->addChild(CDOMElement::create('i','class:big icon '.$aData['icon']));
$instanceDataITEM->addChild($instanceDataCONTENT);
$instanceDataDIV->addChild($instanceDataITEM);
}
unset($instanceData);
$container->addChild($instanceDataSEGMENT);
}
// subscribe link
if (isset($subscribe_link) && $subscribe_link instanceof CElement) {
$subscribeDIV = CDOMElement::create('div','class:ui bottom attached segment');
$subscribeITEM = CDOMElement::create('div','class:item');
$subscribeITEM->addChild($subscribe_link);
$subscribeDIV->addChild($subscribeITEM);
$container->addChild($subscribeDIV);
}
$courseInfoContent['instancesColumn'] = $instancesCDOM->getHtml();
} // foreach($instancesAr as $instance)
} // if(!AMA_DB::isError($instancesAr) && is_array($instancesAr) && count($instancesAr) > 0)
} // foreach ($coursesAr as $courseData)
} else {
$errorMSG = CDOMElement::create('div','id:errorMSG,class:ui error icon large message');
$errorMSG->addChild(CDOMElement::create('i','class:attention icon'));
$MSGcontent = CDOMElement::create('div','class:content');
$MSGheader = CDOMElement::create('div','class:header');
$errorMSG->addChild($MSGcontent);
$MSGcontent->addChild($MSGheader);
$MSGheader->addChild(new CText(translateFN('Corso non trovato')));
}
$optionsAr['onload_func'] = 'initDoc('.intval(isset($errorMSG)).');';
} 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,AMA_FETCH_ASSOC);
if(!AMA_Common_DataHandler::isError($testerInfoAr)) {
$tester = $testerInfoAr['puntatore'];
$provider_name = $testerInfoAr['nome'];
$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)) {
$course_infoAr = $tester_dh->get_course($courseId);
$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 = CDOMElement::create('div','class:ui success icon large message');
$data->addChild(CDOMElement::create('i','class:ok sign icon'));
$MSGcontent = CDOMElement::create('div','class:content');
$MSGheader = CDOMElement::create('div','class:header');
$MSGtext = CDOMElement::create('span','class:message');
$data->addChild($MSGcontent);
$MSGcontent->addChild($MSGheader);
$MSGcontent->addChild($MSGtext);
$MSGheader->addChild(new CText(translateFN('La tua preiscrizione è stata effettuata con successo.')));
$MSGtext->addChild(BaseHtmlLib::link($userObj->getHomePage(), translateFN('Clicca qui')));
$MSGtext->addChild (new CText(' '.translateFN('per tornare alla tua home page')));
$doMailSend = false;
$doRedirect = false;
if ($course_instance_infoAR['price'] > 0) {
$args = '?provider='.$providerId.'&id_course='.$courseId.'&id_course_instance='.$instanceId;
$redirectUrl = HTTP_ROOT_DIR . '/browsing/student_course_instance_subscribe.php'.$args;
$doRedirect = true;
$doMailSend = true;
$mailTxt = [
"Gentile %s %s",
"hai effettuato la pre-iscrizione al corso <strong>%s</strong>, classe <strong>%s</strong>.",
"Se hai già effettuato il pagamento tramite PayPal non devi fare nulla, altrimenti effettua il bonifico usando le seguenti coordinate:",
"",
"Bonifico bancario",
"IBAN: <strong>%s</strong>",
"Intestato a: <strong>%s</strong>",
"Importo: <strong>" . ADA_CURRENCY_SYMBOL . "%s</strong>",
"",
"Nella causale del bonifico devi indicare: il tuo Nome e Cognome e il Titolo del corso. Invia il bonifico alla segreteria e ti verrà immediatamente attivata l'iscrizione.",
"",
"Per accedere al corso dovrai fare login, scrivendo il tuo username e la tua password a questo indirizzo: %s",
"",
"Buon lavoro",
];
$mailTxt = sprintf(
translateFN(implode(PHP_EOL, $mailTxt)),
$userObj->getFirstName(), $userObj->getLastName(),
$course_infoAr['titolo'],
$course_instance_infoAR['title'],
$testerInfoAr['iban'],
$testerInfoAr['ragione_sociale'],
number_format($course_instance_infoAR['price'], ADA_CURRENCY_DECIMALS, ADA_CURRENCY_DECIMAL_POINT, ADA_CURRENCY_THOUSANDS_SEP),
BaseHtmlLib::link(HTTP_ROOT_DIR, HTTP_ROOT_DIR)->getHtml()
);
} else {
$result = $tester_dh->course_instance_student_subscribe($instanceId, $userObj->getId(),ADA_STATUS_SUBSCRIBED, $startStudentLevel);
if(!AMA_DataHandler::isError($result)) {
$data = CDOMElement::create('div','class:ui success icon large message');
$data->addChild(CDOMElement::create('i','class:ok sign icon'));
$MSGcontent = CDOMElement::create('div','class:content');
$MSGheader = CDOMElement::create('div','class:header');
$MSGtext = CDOMElement::create('span','class:message');
$data->addChild($MSGcontent);
$MSGcontent->addChild($MSGheader);
$MSGcontent->addChild($MSGtext);
$MSGheader->addChild(new CText(translateFN('La tua iscrizione è stata effettuata con successo.')));
$MSGtext->addChild(BaseHtmlLib::link($userObj->getHomePage(), translateFN('Clicca qui')));
$MSGtext->addChild (new CText(' '.translateFN('per andare alla tua home page e accedere')));
$doMailSend = true;
$mailTxt = [
"Gentile %s %s",
"hai effettuato l'iscrizione al corso <strong>%s</strong>, classe <strong>%s</strong>.",
"",
"Per accedere al corso dovrai fare login, scrivendo il tuo username e la tua password a questo indirizzo: %s",
"",
"Buon lavoro",
];
$mailTxt = sprintf(
translateFN(implode(PHP_EOL, $mailTxt)),
$userObj->getFirstName(), $userObj->getLastName(),
$course_infoAr['titolo'],
$course_instance_infoAR['title'],
BaseHtmlLib::link(HTTP_ROOT_DIR, HTTP_ROOT_DIR)->getHtml()
);
}
}
if (defined('ADA_SEND_INSTANCE_SUBSCRIPTION_EMAIL') && ADA_SEND_INSTANCE_SUBSCRIPTION_EMAIL && strlen($userObj->getEmail()) > 0 && $doMailSend) {
/**
* Send the message an email message
* via PHPMailer
*/
require_once ROOT_DIR.'/include/phpMailer/ADAPHPMailer.php';
$phpmailer = new \PHPMailer\PHPMailer\ADAPHPMailer();
$phpmailer->CharSet = ADA_CHARSET;
$phpmailer->configSend();
$phpmailer->SetFrom(ADA_NOREPLY_MAIL_ADDRESS);
$phpmailer->IsHTML(true);
$phpmailer->Subject = sprintf(translateFN("[%s] - Iscrizione a %s"), PORTAL_NAME, $course_instance_infoAR['title']);
$phpmailer->AddAddress($userObj->getEmail(), $userObj->getFullName());
$phpmailer->Body = nl2br($mailTxt);
$phpmailer->AltBody = html_entity_decode(strip_tags($mailTxt), ENT_QUOTES, ADA_CHARSET);
if (DEV_ALLOW_SENDING_EMAILS) {
$emailed = $phpmailer->Send();
} else {
$emailed = true;
}
}
if ($doRedirect) {
redirect($redirectUrl);
}
// } else if($result->code == AMA_ERR_UNIQUE_KEY) {
// $data = new CText(translateFN('Risulti già preiscritto a questa edizione del corso'));
} else {
$data = CDOMElement::create('div','class:ui error icon large message');
$data->addChild(CDOMElement::create('i','class:attention icon'));
$MSGcontent = CDOMElement::create('div','class:content');
$MSGheader = CDOMElement::create('div','class:header');
$MSGtext = CDOMElement::create('span','class:message');
$data->addChild($MSGcontent);
$MSGcontent->addChild($MSGheader);
$MSGcontent->addChild($MSGtext);
$MSGheader->addChild(new CText(translateFN('Si è verificato un errore')));
$MSGtext->addChild(BaseHtmlLib::link($userObj->getHomePage(), translateFN('Clicca qui')));
$MSGtext->addChild (new CText(' '.translateFN('per tornare alla tua home page')));
}
} else {
$data = CDOMElement::create('div','class:ui error icon large message');
$data->addChild(CDOMElement::create('i','class:attention icon'));
$MSGcontent = CDOMElement::create('div','class:content');
$MSGheader = CDOMElement::create('div','class:header');
$MSGtext = CDOMElement::create('span','class:message');
$data->addChild($MSGcontent);
$MSGcontent->addChild($MSGheader);
$MSGcontent->addChild($MSGtext);
$MSGheader->addChild(new CText(translateFN('Si è verificato un errore aggiungendo lo studente al provider')));
$MSGtext->addChild(BaseHtmlLib::link($userObj->getHomePage(), translateFN('Clicca qui')));
$MSGtext->addChild (new CText(' '.translateFN('per tornare alla tua home page')));
}
}
$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
*/
$author_name = reset($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,AMA_FETCH_ASSOC);
if(!AMA_Common_DataHandler::isError($testerInfoAr)) {
$tester = $testerInfoAr['puntatore'];
$provider_name = $testerInfoAr['nome'];
$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 {
/**
* giorgio 13/ago/2013
* if it's not a multiprovider environment, must load only published course
* of the only selected single provider stored in GLOBALS.
* else make the default function call
*/
if (!MULTIPROVIDER)
{
// if provider is not set or there's an error loading its id, retirect to home
$redirect = false;
/**
* sets user selected provider name
*/
if (isset($GLOBALS['user_provider']))
$user_provider_name = $GLOBALS['user_provider'];
/**
* check if user selected provider name has a valid id in the database
*/
if (isset($user_provider_name))
{
$userTesterInfo = $common_dh->get_tester_info_from_pointer($user_provider_name);
$user_provider_id = (!AMA_DB::isError($userTesterInfo)) ? $userTesterInfo[0] : null;
$redirect = is_null($user_provider_id);
}
else $redirect = true;
if (!$redirect) $publishedServices = $common_dh->get_published_courses($user_provider_id);
else {
header ('Location: '.HTTP_ROOT_DIR.'/info.php');
die();
}
$thead_data = array(' ', 'ID', translateFN('corso'), translateFN('descrizione'), translateFN('crediti'),' ');
} else {
$thead_data = array(' ', 'ID', translateFN('corso'), translateFN('Fornito da'), translateFN('descrizione'), translateFN('crediti'),' ');
$publishedServices = $common_dh->get_published_courses(
isset($_GET['provider']) && intval($_GET['provider']>0) ? intval($_GET['provider']) : null
);
}
if(!AMA_Common_DataHandler::isError($publishedServices)) {
// $thead_data = array('nome', 'descrizione', 'durata (giorni)', 'informazioni');
$tbody_data = array();
foreach($publishedServices as $service) {
$serviceId = $service['id_servizio'];
$coursesAr = $common_dh->get_courses_for_service($serviceId);
if(!AMA_DB::isError($coursesAr)) {
$currentTesterId = 0;
$currentTester = '';
$tester_dh = null;
foreach($coursesAr as $courseData) {
$courseId = $courseData['id_corso'];
$Flag_course_has_instance=false;
$newTesterId = $courseData['id_tester'];
if($newTesterId != $currentTesterId) { // stesso corso su altro tester ?
$testerInfoAr = $common_dh->get_tester_info_from_id($newTesterId,AMA_FETCH_ASSOC);
if(!AMA_DB::isError($testerInfoAr)) {
$providerName = $testerInfoAr['nome'];
$tester = $testerInfoAr['puntatore'];
$tester_dh = AMA_DataHandler::instance(MultiPort::getDSN($tester));
$currentTesterId = $newTesterId;
$course_dataHa = $tester_dh->get_course($courseId);
$instancesAr = $tester_dh->course_instance_subscribeable_get_list(
array('data_inizio_previsto', 'durata', 'data_fine', 'title'),
$courseId);
if(is_array($instancesAr) && count($instancesAr) > 0) {
$Flag_course_has_instance=true;
}
if (!AMA_DB::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
}
}
}
$more_info_link = BaseHtmlLib::link("info.php?op=course_info&id=$serviceId",
'<i class="big icon info"></i>');
$more_info_link->setAttribute('title', strip_tags(translateFN('More info')));
$more_info_link->setAttribute('class', 'more_info_link');
$row = array($Flag_course_has_instance ? '<i class="sign icon add green"></i>' : null, $courseId, $service['nome']);
if (MULTIPROVIDER) array_push($row, $providerName);
array_push($row,
$service['descrizione'],
$credits,
// $service['durata_servizio'],
$more_info_link
);
$row['instances'] = null;
if ($Flag_course_has_instance) {
// sort by data_inizio_previsto DESC
uasort($instancesAr, function($a, $b){
if ($a['data_inizio_previsto'] == $b['data_inizio_previsto']) return 0;
return ($a['data_inizio_previsto'] > $b['data_inizio_previsto']) ? -1 : 1;
});
foreach ($instancesAr as $instKey => $instanceEl) {
foreach ($instanceEl as $iKey => $iVal) {
if (is_numeric($iKey)) unset($instancesAr[$instKey][$iKey]);
else if (stripos($iKey, 'data') !== false) $instancesAr[$instKey][$iKey] = ts2dFN($iVal);
}
$instancesAr[$instKey]['id_corso'] = $courseId;
$instancesAr[$instKey]['provider'] = $courseData['id_tester'];
$instancesAr[$instKey]['isstarted'] = ($instanceEl['data_inizio_previsto'] > 0 && $instanceEl['data_inizio_previsto'] <= time()) ? true : false;
$instancesAr[$instKey]['isended'] = ($instanceEl['data_fine'] > 0 && $instanceEl['data_fine'] < time()) ? true : false;
}
$row['instances'] = json_encode(array_values($instancesAr), JSON_UNESCAPED_SLASHES);
}
$tbody_data[] = $row;
}
} else {
$credits = 1; // should be ADA_DEFAULT_COURSE_CREDITS
}
}
$data = BaseHtmlLib::tableElement('id:infotable,class:'.ADA_SEMANTICUI_TABLECLASS, $thead_data, $tbody_data);
$optionsAr['onload_func'] = 'initDoc('.intval(MULTIPROVIDER).');';
} else {
$data = new CText(translateFN('Non sono stati pubblicati corsi'));
}
}
$title = translateFN('Corsi ai quali puoi iscriverti');
$help = '';
$layout_dataAr['JS_filename'] = array(
JQUERY_DATATABLE
);
$content_dataAr = array(
'course_title' => $title,
'user_name' => $user_name,
'user_type' => $user_type,
'status' => $status,
'label' => isset($label) ? $label : null,
'help' => $help,
'data' => isset($data) ? $data->getHtml() : null,
'errorMSG' => isset($errorMSG) ? $errorMSG->getHtml() : null,
);
/**
* Merge courseInfoContent into $content_dataAr
*/
if (isset($courseInfoContent)) $content_dataAr = array_merge($content_dataAr, $courseInfoContent);
/**
* Sends data to the rendering engine if it's not a PRESUBSCRIBED user subscribing to an instance
* in that case, this script is included by registration.php and $_SESSION['subscription_page'] is set
*/
if (!($userObj->getStatus() == ADA_STATUS_PRESUBSCRIBED && array_key_exists('subscription_page', $_SESSION))) {
ARE::render($layout_dataAr, $content_dataAr, NULL, (isset($optionsAr) ? $optionsAr : NULL));
}