forked from GibbonEdu/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
1665 lines (1469 loc) · 56.2 KB
/
functions.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
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
Gibbon: the flexible, open school platform
Founded by Ross Parker at ICHK Secondary. Built by Ross Parker, Sandra Kuipers and the Gibbon community (https://gibbonedu.org/about/)
Copyright © 2010, Gibbon Foundation
Gibbon™, Gibbon Education Ltd. (Hong Kong)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
use Gibbon\Http\Url;
use Gibbon\Forms\Form;
use Gibbon\Services\Format;
use Gibbon\Data\PasswordPolicy;
use Gibbon\Domain\Students\MedicalGateway;
use Gibbon\Domain\System\AlertLevelGateway;
use Gibbon\Domain\System\SettingGateway;
use Gibbon\Forms\Input\Editor;
use Gibbon\Locale;
function getIPAddress()
{
$return = false;
if (getenv('HTTP_CLIENT_IP'))
$return = getenv('HTTP_CLIENT_IP');
else if (getenv('HTTP_X_FORWARDED_FOR'))
$return = getenv('HTTP_X_FORWARDED_FOR');
else if (getenv('HTTP_X_FORWARDED'))
$return = getenv('HTTP_X_FORWARDED');
else if (getenv('HTTP_FORWARDED_FOR'))
$return = getenv('HTTP_FORWARDED_FOR');
else if (getenv('HTTP_FORWARDED'))
$return = getenv('HTTP_FORWARDED');
else if (getenv('REMOTE_ADDR'))
$return = getenv('REMOTE_ADDR');
return $return;
}
/**
* Convert an HTML email body into a plain text email body.
*
* Deprecated. Use \Gibbon\Comms\Mailer::renderBody() instead, which internally
* handles the HTML and non-HTML rendered messages.
*
* @deprecated v25
* @version v12
* @since v12
*
* @param string $body
*
* @return string
*/
function emailBodyConvert($body)
{
$return = $body;
$return = preg_replace('#<br\s*/?>#i', "\n", $return);
$return = str_replace('</p>', "\n\n", $return);
$return = str_replace('</div>', "\n\n", $return);
$return = preg_replace("#\<a.+href\=[\"|\'](.+)[\"|\'].*\>.*\<\/a\>#U", '$1', $return);
$return = strip_tags($return, '<a>');
return $return;
}
/**
* Custom translation function to allow custom string replacement
*
* @param string $text Text to Translate. See documentation for
* Gibbon\Locale::translate for more info.
* @param array $params Assoc array of key value pairs for named
* string replacement. See documentation for
* Gibbon\Locale::translate for more info.
* @param array|string $options Options for translations (e.g. domain).
* Or string of domain (for backward
* compatibility, deprecated).
*
* @return string The resulted translation string.
*/
function __($text, $params = [], $options = [])
{
global $gibbon, $guid; // For backwards compatibilty
$args = func_get_args();
// Note: should remove the compatibility code in next
// version, then properly state function signature.
// Compatibility with __($guid, $text) and __($guid, $text, $domain) calls.
// Deprecated.
if ($args[0] === $guid) {
array_shift($args); // discard $guid
}
if (empty($args)) {
return ''; // if there is nothing after $guid, return nothing
}
// Basic __($text) signature handle by default.
$text = array_shift($args);
$params = [];
$options = [];
// Handle replacement parameters, if exists.
if (!empty($args) && is_array($args[0])) {
$params = array_shift($args);
}
// Handle options, if exists.
if (!empty($args)) {
$options = array_shift($args);
// Backward compatibility layer.
// Treat non-array options as 'domain'.
$options = is_array($options) ? $options : ['domain' => $options];
}
// Cancel out early for empty translations
if (empty($text)) {
return $text;
}
// Fallback to format string if global locale does not exists.
return isset($gibbon->locale)
? $gibbon->locale->translate($text, $params, $options)
: Locale::formatString($text, $params);
}
/**
* Custom translation function to allow custom string replacement with
* plural string.
*
* @param string $singular The singular message ID.
* @param string $plural The plural message ID.
* @param int $n The number (e.g. item count) to determine
* the translation for the respective grammatical
* number.
* @param array $params Assoc array of key value pairs for named
* string replacement.
* @param array $options Options for translations (e.g. domain).
*
* @return string Translated Text
*/
function __n(string $singular, string $plural, int $n, array $params = [], array $options = [])
{
global $gibbon;
return $gibbon->locale->translateN($singular, $plural, $n, $params, $options);
}
/**
* Identical to __() but automatically includes the current module as the text domain.
*
* @see __()
* @param string $text
* @param array $params
* @param array $options
* @return string
*/
function __m(string $text, array $params = [], array $options = [])
{
global $gibbon, $session;
if ($session->has('module')) {
$options['domain'] = $session->get('module');
}
return $gibbon->locale->translate($text, $params, $options);
}
//$valueMode can be "value" or "id" according to what goes into option's value field
//$selectMode can be "value" or "id" according to what is used to preselect an option
//$honourDefault can TRUE or FALSE, and determines whether or not the default grade is selected
function renderGradeScaleSelect($connection2, $guid, $gibbonScaleID, $fieldName, $valueMode, $honourDefault = true, $width = 50, $selectedMode = 'value', $selectedValue = null)
{
$return = false;
$return .= "<select name='$fieldName' id='$fieldName' style='width: " . $width . "px'>";
$dataSelect = array('gibbonScaleID' => $gibbonScaleID);
$sqlSelect = 'SELECT * FROM gibbonScaleGrade WHERE gibbonScaleID=:gibbonScaleID ORDER BY sequenceNumber';
$resultSelect = $connection2->prepare($sqlSelect);
$resultSelect->execute($dataSelect);
$return .= "<option value=''></option>";
$sequence = '';
$descriptor = '';
while ($rowSelect = $resultSelect->fetch()) {
$selected = '';
if ($honourDefault and is_null($selectedValue)) { //Select entry based on scale default
if ($rowSelect['isDefault'] == 'Y') {
$selected = 'selected';
}
} elseif ($selectedMode == 'value') { //Select entry based on value passed
if ($rowSelect['value'] == $selectedValue) {
$selected = 'selected';
}
} elseif ($selectedMode == 'id') { //Select entry based on id passed
if ($rowSelect['gibbonScaleGradeID'] == $selectedValue) {
$selected = 'selected';
}
}
if ($valueMode == 'value') {
$return .= "<option $selected value='" . htmlPrep($rowSelect['value']) . "'>" . htmlPrep(__($rowSelect['value'])) . '</option>';
} else {
$return .= "<option $selected value='" . htmlPrep($rowSelect['gibbonScaleGradeID']) . "'>" . htmlPrep(__($rowSelect['value'])) . '</option>';
}
}
$return .= '</select>';
return $return;
}
/**
* Archives one or more notifications, based on partial match of actionLink
* and total match of gibbonPersonID.
*
* @deprecated v25
* Should use NotificationGateway::archiveNotificationForPersonAction()
*
* @param \PDO $connection2 The PDO instance.
* @param string $guid The guid of current installation.
* @param int $gibbonPersonID The Gibbon person ID.
* @param string $actionLinkPart The partial string in an action link.
*
* @return bool Whether the database update was successful.
*/
function archiveNotification($connection2, $guid, $gibbonPersonID, $actionLink)
{
$return = true;
try {
$data = array('gibbonPersonID' => $gibbonPersonID, 'actionLink' => "%$actionLink%");
$sql = "UPDATE gibbonNotification SET status='Archived' WHERE gibbonPersonID=:gibbonPersonID AND actionLink LIKE :actionLink AND status='New'";
$result = $connection2->prepare($sql);
$result->execute($data);
} catch (PDOException $e) {
$return = false;
}
return $return;
}
/**
* Calculate the number of days before next birthday.
*
* Deprecated because it was only used in \Gibbon\Services\Format.
* Replaced by the private method \Gibbon\Services\Format::daysUntilNextBirthday().
*
* @deprecated v25
* @version v12
* @since v12
*
* @param string $birthday Accepts birthday in mysql date (YYYY-MM-DD).
*
* @return int Number of days before the next birthday. If today is a birthday, returns 0.
*/
function daysUntilNextBirthday($birthday)
{
$today = date('Y-m-d');
$btsString = substr($today, 0, 4) . '-' . substr($birthday, 5);
$bts = strtotime($btsString);
$ts = time();
if ($bts < $ts) {
$bts = strtotime(date('y', strtotime('+1 year')) . '-' . substr($birthday, 5));
}
$days = ceil(($bts - $ts) / 86400);
//Full year correction, and leap year correction
$includesLeap = false;
if (substr($birthday, 5, 2) < 3) { //Born in January or February, so check if this year is a leap year
$includesLeap = is_leap_year(substr($today, 0, 4));
} else { //Otherwise, check next year
$includesLeap = is_leap_year(substr($today, 0, 4) + 1);
}
if ($includesLeap == true and $days == 366) {
$days = 0;
} elseif ($includesLeap == false and $days == 365) {
$days = 0;
}
return $days;
}
/**
* This function written by David Walsh, shared under MIT License
* (http://davidwalsh.name/checking-for-leap-year-using-php)
*
* @deprecated v25
*
* @param int $year The year.
*
* @return bool
*/
function is_leap_year($year)
{
return (($year % 4) == 0) && ((($year % 100) != 0) || (($year % 400) == 0));
}
/**
* Check if a password matches the password policy in the
* settings.
*
* Deprecated. Use \Gibbon\Data\PasswordPolicy::validate() instead.
*
* @deprecated v25
* @version v25
* @since v12
*
* @param \PDO $connection2
* @param string $passwordNew
*
* @return bool
*/
function doesPasswordMatchPolicy($connection2, $passwordNew)
{
global $container;
/** @var PasswordPolicy */
$passwordPolicies = $container->get(PasswordPolicy::class);
try {
return $passwordPolicies->validate($passwordNew);
} catch (\Exception $e) {
return false;
}
}
/**
* Get an HTML list of all password policies.
*
* @deprecated v25
* @version v25
* @since v12
*
* @param string $guid
* @param \PDO $connection2
*
* @return string An unorder HTML list.
*/
function getPasswordPolicy($guid, $connection2)
{
global $container;
/** @var PasswordPolicy */
$passwordPolicies = $container->get(PasswordPolicy::class);
return $passwordPolicies->describeHTML();
}
function getFastFinder($connection2, $guid)
{
global $session;
$form = Form::create('fastFinder', Url::fromHandlerRoute('indexFindRedirect.php'), 'get');
$form->setClass('blank fullWidth');
$form->addHiddenValue('address', $session->get('address'));
$row = $form->addRow();
$row->addFinder('fastFinderSearch')
->fromAjax(Url::fromHandlerRoute('index_fastFinder_ajax.php'))
->setClass('w-full text-white flex items-center')
->setAria('label', __('Search'))
->setParameter('hintText', __('Start typing a name...'))
->setParameter('noResultsText', __('No results'))
->setParameter('searchingText', __('Searching...'))
->setParameter('tokenLimit', 1)
->setParameter('arialabel', __('Fast Finder'))
->addValidation('Validate.Presence', 'failureMessage: " "')
->append('<input type="submit" style="height:34px;padding:0 1rem;" value="' . __('Go') . '">');
$highestActionClass = getHighestGroupedAction($guid, '/modules/Planner/planner.php', $connection2);
$templateData = [
'roleCategory' => $session->get('gibbonRoleIDCurrentCategory'),
'studentIsAccessible' => isActionAccessible($guid, $connection2, '/modules/students/student_view.php'),
'staffIsAccessible' => isActionAccessible($guid, $connection2, '/modules/Staff/staff_view.php'),
'classIsAccessible' => isActionAccessible($guid, $connection2, '/modules/Planner/planner.php') && $highestActionClass != 'Lesson Planner_viewMyChildrensClasses',
'form' => $form->getOutput(),
];
return $templateData;
}
/**
* Get alert of the especified alert level.
*
* @deprecated v25
* Use AlertLevelGateway::getByID instead.
*
* @since v12
* @version v23
*
* @param string $guid
* @param \PDO $connection2
* @param int $gibbonAlertLevelID
*
* @return array|false
*/
function getAlert($guid, $connection2, $gibbonAlertLevelID)
{
$output = false;
$dataAlert = array('gibbonAlertLevelID' => $gibbonAlertLevelID);
$sqlAlert = 'SELECT * FROM gibbonAlertLevel WHERE gibbonAlertLevelID=:gibbonAlertLevelID';
$resultAlert = $connection2->prepare($sqlAlert);
$resultAlert->execute($dataAlert);
if ($resultAlert->rowCount() == 1) {
$rowAlert = $resultAlert->fetch();
$output = array();
$output['gibbonAlertLevelID'] = $rowAlert['gibbonAlertLevelID'];
$output['name'] = __($rowAlert['name']);
$output['nameShort'] = $rowAlert['nameShort'];
$output['color'] = $rowAlert['color'];
$output['colorBG'] = $rowAlert['colorBG'];
$output['description'] = __($rowAlert['description']);
$output['sequenceNumber'] = $rowAlert['sequenceNumber'];
}
return $output;
}
function getSalt()
{
$c = './aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789';
$s = '';
$l = strlen($c);
for ($x = 0; $x < 22; $x++) {
$ind = mt_rand(0, $l - 1);
$s .= $c[$ind];
}
return $s;
}
//Get information on a unit of work, inlcuding the possibility that it is a hooked unit
function getUnit($connection2, $gibbonUnitID, $gibbonCourseClassID)
{
$output = array();
$unitType = false;
if ($gibbonUnitID != '') {
try {
$dataUnit = array('gibbonUnitID' => $gibbonUnitID);
$sqlUnit = 'SELECT * FROM gibbonUnit WHERE gibbonUnitID=:gibbonUnitID';
$resultUnit = $connection2->prepare($sqlUnit);
$resultUnit->execute($dataUnit);
if ($resultUnit->rowCount() == 1) {
$rowUnit = $resultUnit->fetch();
if (isset($rowUnit['type'])) {
$unitType = $rowUnit['type'];
}
$output[0] = $rowUnit['name'];
$output[1] = '';
}
} catch (PDOException $e) {
}
}
return $output;
}
function getWeekNumber($date, $connection2, $guid)
{
global $session;
$week = 0;
try {
$dataWeek = array('gibbonSchoolYearID' => $session->get('gibbonSchoolYearID'));
$sqlWeek = 'SELECT * FROM gibbonSchoolYearTerm WHERE gibbonSchoolYearID=:gibbonSchoolYearID ORDER BY sequenceNumber';
$resultWeek = $connection2->prepare($sqlWeek);
$resultWeek->execute($dataWeek);
while ($rowWeek = $resultWeek->fetch()) {
$firstDayStamp = strtotime($rowWeek['firstDay']);
$lastDayStamp = strtotime($rowWeek['lastDay']);
while (date('N', $firstDayStamp) !== '1') {
$firstDayStamp = $firstDayStamp - 86400;
}
$head = $firstDayStamp;
while ($head <= ($date) and $head < ($lastDayStamp + 86399)) {
$head = $head + (86400 * 7);
++$week;
}
if ($head < ($lastDayStamp + 86399)) {
break;
}
}
} catch (PDOException $e) {
}
if ($week <= 0) {
return false;
} else {
return $week;
}
}
/**
* Render the editor. Updated v18 to use a twig template.
*
* @deprecated Since v25. Will be removed in the future.
* Please use \Gibbon\Forms\Input\Editor directly.
* @version v25
* @since v12
*
* @param string $guid Obsoleted parameter.
* @param boolean $tinymceInit
* @param string $id
* @param string $value
* @param integer $rows
* @param boolean $showMedia
* @param boolean $required
* @param boolean $initiallyHidden
* @param boolean $allowUpload
* @param string $initialFilter
* @param boolean $resourceAlphaSort
*
* @return string
*/
function getEditor($guid, $tinymceInit = true, $id = '', $value = '', $rows = 10, $showMedia = false, $required = false, $initiallyHidden = false, $allowUpload = true, $initialFilter = '', $resourceAlphaSort = false): string
{
$editor = (new Editor($id))
->tinymceInit($tinymceInit)
->setValue($value)
->setRows($rows)
->showMedia($showMedia)
->setRequired($required)
->initiallyHidden($initiallyHidden)
->allowUpload($allowUpload)
->initialFilter($initialFilter)
->resourceAlphaSort($resourceAlphaSort);
return $editor->getOutput();
}
function getYearGroups($connection2)
{
$output = false;
//Scan through year groups
//SELECT NORMAL
try {
$sql = 'SELECT * FROM gibbonYearGroup ORDER BY sequenceNumber';
$result = $connection2->query($sql);
while ($row = $result->fetch()) {
$output .= $row['gibbonYearGroupID'] . ',';
$output .= $row['name'] . ',';
}
} catch (PDOException $e) {
}
if ($output != false) {
$output = substr($output, 0, (strlen($output) - 1));
$output = explode(',', $output);
}
return $output;
}
function getYearGroupsFromIDList($guid, $connection2, $ids, $vertical = false, $translated = true)
{
$output = false;
try {
$sqlYears = 'SELECT DISTINCT nameShort, sequenceNumber FROM gibbonYearGroup ORDER BY sequenceNumber';
$resultYears = $connection2->query($sqlYears);
$years = explode(',', $ids ?? '');
if (count($years) > 0 and $years[0] != '') {
if (count($years) == $resultYears->rowCount()) {
$output = '<i>' . __('All') . '</i>';
} else {
try {
$dataYears = array();
$sqlYearsOr = '';
for ($i = 0; $i < count($years); ++$i) {
if ($i == 0) {
$dataYears["year$i"] = $years[$i];
$sqlYearsOr = $sqlYearsOr . ' WHERE gibbonYearGroupID=:year' . $i;
} else {
$dataYears["year$i"] = $years[$i];
$sqlYearsOr = $sqlYearsOr . ' OR gibbonYearGroupID=:year' . $i;
}
}
$sqlYears = "SELECT DISTINCT nameShort, sequenceNumber FROM gibbonYearGroup $sqlYearsOr ORDER BY sequenceNumber";
$resultYears = $connection2->prepare($sqlYears);
$resultYears->execute($dataYears);
} catch (PDOException $e) {
}
$count3 = 0;
while ($rowYears = $resultYears->fetch()) {
if ($count3 > 0) {
if ($vertical == false) {
$output .= ', ';
} else {
$output .= '<br/>';
}
}
if ($translated == true) {
$output .= __($rowYears['nameShort']);
} else {
$output .= $rowYears['nameShort'];
}
++$count3;
}
}
} else {
$output = '<i>' . __('None') . '</i>';
}
} catch (PDOException $e) {
}
return $output;
}
/**
* Gets terms in the specified school year
*
* @deprecated v25
* Use SchoolYearTermGateway::selectTermsBySchoolYear() instead.
*
* @since v12
* @version v12
*
* @param \PDO $connection2
* @param int $gibbonSchoolYearID
* @param boolean $short
*
* @return string[]
*/
function getTerms($connection2, $gibbonSchoolYearID, $short = false)
{
$output = false;
//Scan through year groups
$data = array('gibbonSchoolYearID' => $gibbonSchoolYearID);
$sql = 'SELECT * FROM gibbonSchoolYearTerm WHERE gibbonSchoolYearID=:gibbonSchoolYearID ORDER BY sequenceNumber';
$result = $connection2->prepare($sql);
$result->execute($data);
while ($row = $result->fetch()) {
$output .= $row['gibbonSchoolYearTermID'] . ',';
if ($short == true) {
$output .= $row['nameShort'] . ',';
} else {
$output .= $row['name'] . ',';
}
}
if ($output != false) {
$output = substr($output, 0, (strlen($output) - 1));
$output = explode(',', $output);
}
return $output;
}
/**
* Array sort for multidimensional arrays.
*
* Deprecated in favor of native usort.
*
* @since 2013
* @version v12.0.00
* @deprecated v26.0.00
*/
function msort($array, $id = 'id', $sort_ascending = true)
{
$temp_array = array();
while (count($array) > 0) {
$lowest_id = 0;
$index = 0;
foreach ($array as $item) {
if (isset($item[$id])) {
if ($array[$lowest_id][$id]) {
if (strtolower($item[$id]) < strtolower($array[$lowest_id][$id])) {
$lowest_id = $index;
}
}
}
++$index;
}
$temp_array[] = $array[$lowest_id];
$array = array_merge(array_slice($array, 0, $lowest_id), array_slice($array, $lowest_id + 1));
}
if ($sort_ascending) {
return $temp_array;
} else {
return array_reverse($temp_array);
}
}
/**
* Returns preformatted HTML indicator of max file upload size
*
* @since 2013
* @version v26
*
* @param bool $multiple Whether to show text about multiple files.
*/
function getMaxUpload($multiple = false)
{
// For backwards compatibilty
global $guid;
if ($multiple === $guid) {
$multiple = func_get_args()[1] ?? false;
}
$output = '';
$post = substr(ini_get('post_max_size'), 0, (strlen(ini_get('post_max_size')) - 1));
$file = substr(ini_get('upload_max_filesize'), 0, (strlen(ini_get('upload_max_filesize')) - 1));
$output .= "<div style='margin-top: 10px; font-style: italic; color: #c00'>";
if ($multiple == true) {
if ($post < $file) {
$output .= sprintf(__('Maximum size for all files: %1$sMB'), $post) . '<br/>';
} else {
$output .= sprintf(__('Maximum size for all files: %1$sMB'), $file) . '<br/>';
}
} else {
if ($post < $file) {
$output .= sprintf(__('Maximum file size: %1$sMB'), $post) . '<br/>';
} else {
$output .= sprintf(__('Maximum file size: %1$sMB'), $file) . '<br/>';
}
}
$output .= '</div>';
return $output;
}
//Encode strring using htmlentities with the ENT_QUOTES option
function htmlPrep($str)
{
return htmlentities($str ?? '', ENT_QUOTES, 'UTF-8');
}
/**
* Get the risk level of the highest-risk condition for an individual.
*
* Deprecated. Use \Gibbon\Domain\Student\MedicalGateway::getHighestMedicalRisk() instead.
*
* @deprecated v25
* @version v12
*
* @param string $guid Obsoleted parameter.
* @param int $gibbonPersonID The person ID.
* @param \PDO $connection2
*
* @return array An array of fields in the medical alert information of the person,
* or an empty array if none found.
*/
function getHighestMedicalRisk($guid, $gibbonPersonID, $connection2)
{
$output = false;
$dataAlert = array('gibbonPersonID' => $gibbonPersonID);
$sqlAlert = 'SELECT * FROM gibbonPersonMedical JOIN gibbonPersonMedicalCondition ON (gibbonPersonMedical.gibbonPersonMedicalID=gibbonPersonMedicalCondition.gibbonPersonMedicalID) JOIN gibbonAlertLevel ON (gibbonPersonMedicalCondition.gibbonAlertLevelID=gibbonAlertLevel.gibbonAlertLevelID) WHERE gibbonPersonID=:gibbonPersonID ORDER BY gibbonAlertLevel.sequenceNumber DESC';
$resultAlert = $connection2->prepare($sqlAlert);
$resultAlert->execute($dataAlert);
if ($resultAlert->rowCount() > 0) {
$rowAlert = $resultAlert->fetch();
$output = array();
$output[0] = $rowAlert['gibbonAlertLevelID'];
$output[1] = __($rowAlert['name']);
$output[2] = $rowAlert['nameShort'];
$output[3] = $rowAlert['color'];
$output[4] = $rowAlert['colorBG'];
}
return $output;
}
//Looks at the grouped actions accessible to the user in the current module and returns the highest
function getHighestGroupedAction($guid, $address, $connection2)
{
global $session;
if (empty($session->get('gibbonRoleIDCurrent'))) return false;
$output = false;
$module = getModuleName($address);
try {
$data = [
'actionName' => '%' . getActionName($address) . '%',
'gibbonRoleID' => $session->get('gibbonRoleIDCurrent'),
'moduleName' => $module,
];
$sql = 'SELECT
gibbonAction.name
FROM
gibbonAction
INNER JOIN gibbonModule ON (gibbonModule.gibbonModuleID=gibbonAction.gibbonModuleID)
INNER JOIN gibbonPermission ON (gibbonAction.gibbonActionID=gibbonPermission.gibbonActionID)
INNER JOIN gibbonRole ON (gibbonPermission.gibbonRoleID=gibbonRole.gibbonRoleID)
WHERE
gibbonAction.URLList LIKE :actionName AND
gibbonPermission.gibbonRoleID=:gibbonRoleID AND
gibbonModule.name=:moduleName
ORDER BY gibbonAction.precedence DESC, gibbonAction.gibbonActionID';
$result = $connection2->prepare($sql);
$result->execute($data);
if ($result->rowCount() > 0) {
$row = $result->fetch();
$output = $row['name'];
}
} catch (PDOException $e) {
}
return $output;
}
/**
* Returns the category of the specified role.
*
* Deprecated. Use RoleGateway::getRoleCategory() instead.
*
* @deprecated v25
* @version v12
* @since v12
*
* @param int $gibbonRoleID
* @param \PDO $connection2
*
* @return string|false
*/
function getRoleCategory($gibbonRoleID, $connection2)
{
$output = false;
$data = array('gibbonRoleID' => $gibbonRoleID);
$sql = 'SELECT * FROM gibbonRole WHERE gibbonRoleID=:gibbonRoleID';
$result = $connection2->prepare($sql);
$result->execute($data);
if ($result->rowCount() == 1) {
$row = $result->fetch();
$output = $row['category'];
}
return $output;
}
//Checks to see if a specified date (YYYY-MM-DD) is a day where school is open in the current academic year. There is an option to search all years
function isSchoolOpen($guid, $date, $connection2, $allYears = '')
{
global $session;
//Set test variables
$isInTerm = false;
$isSchoolDay = false;
$isSchoolOpen = false;
//Turn $date into UNIX timestamp and extract day of week
$timestamp = Format::timestamp($date);
$dayOfWeek = date('D', $timestamp);
//See if date falls into a school term
$data = [];
$sql = "SELECT gibbonSchoolYearTerm.firstDay, gibbonSchoolYearTerm.lastDay FROM gibbonSchoolYearTerm, gibbonSchoolYear WHERE gibbonSchoolYearTerm.gibbonSchoolYearID=gibbonSchoolYear.gibbonSchoolYearID";
if ($allYears != true) {
$data['gibbonSchoolYearID'] = $session->get('gibbonSchoolYearID');
$sql .= ' AND gibbonSchoolYear.gibbonSchoolYearID=:gibbonSchoolYearID';
}
$result = $connection2->prepare($sql);
$result->execute($data);
while ($row = $result->fetch()) {
if ($date >= $row['firstDay'] and $date <= $row['lastDay']) {
$isInTerm = true;
}
}
//See if date's day of week is a school day
if ($isInTerm == true) {
$data = array('nameShort' => $dayOfWeek);
$sql = "SELECT * FROM gibbonDaysOfWeek WHERE nameShort=:nameShort AND schoolDay='Y'";
$result = $connection2->prepare($sql);
$result->execute($data);
if ($result->rowCount() > 0) {
$isSchoolDay = true;
}
}
//See if there is a special day
if ($isInTerm == true and $isSchoolDay == true) {
$data = array('date' => $date);
$sql = "SELECT * FROM gibbonSchoolYearSpecialDay WHERE type='School Closure' AND date=:date";
$result = $connection2->prepare($sql);
$result->execute($data);
if ($result->rowCount() < 1) {
$isSchoolOpen = true;
}
}
return $isSchoolOpen;
}
function getAlertBar($guid, $connection2, $gibbonPersonID, $privacy = '', $divExtras = '', $div = true, $large = false, $target = "_self")
{
global $session, $container;
$output = '';
$alerts = [];
$target = ($target == "_blank") ? "_blank" : "_self";
$highestAction = getHighestGroupedAction($guid, '/modules/Students/student_view_details.php', $connection2);
if ($highestAction == 'View Student Profile_full' or $highestAction == 'View Student Profile_fullNoNotes' or $highestAction == 'View Student Profile_fullEditAllNotes') {
// Individual Needs
$dataAlert = array('gibbonPersonID' => $gibbonPersonID);
$sqlAlert = "SELECT * FROM gibbonINPersonDescriptor JOIN gibbonAlertLevel ON (gibbonINPersonDescriptor.gibbonAlertLevelID=gibbonAlertLevel.gibbonAlertLevelID) WHERE gibbonPersonID=:gibbonPersonID ORDER BY sequenceNumber DESC";
$resultAlert = $connection2->prepare($sqlAlert);
$resultAlert->execute($dataAlert);
if ($alert = $resultAlert->fetch()) {
$title = $resultAlert->rowCount() == 1
? $resultAlert->rowCount() . ' ' . sprintf(__('Individual Needs alert is set, with an alert level of %1$s.'), $alert['name'])
: $resultAlert->rowCount() . ' ' . sprintf(__('Individual Needs alerts are set, up to a maximum alert level of %1$s.'), $alert['name']);
$alerts[] = [
'highestLevel' => __($alert['name']),
'highestColour' => $alert['color'],
'highestColourBG' => $alert['colorBG'],
'tag' => __('IN'),
'title' => $title,
'link' => Url::fromModuleRoute('Students', 'student_view_details')
->withQueryParams(['gibbonPersonID' => $gibbonPersonID, 'subpage' => 'Individual Needs']),
];
}
// Academic
$gibbonAlertLevelID = '';
$alertThresholdText = '';
$dataAlert = array('gibbonPersonIDStudent' => $gibbonPersonID, 'gibbonSchoolYearID' => $session->get('gibbonSchoolYearID'), 'today' => date('Y-m-d'), 'date' => date('Y-m-d', (time() - (24 * 60 * 60 * 60))));
$sqlAlert = "SELECT *
FROM gibbonMarkbookEntry
JOIN gibbonMarkbookColumn ON (gibbonMarkbookEntry.gibbonMarkbookColumnID=gibbonMarkbookColumn.gibbonMarkbookColumnID)
JOIN gibbonCourseClass ON (gibbonMarkbookColumn.gibbonCourseClassID=gibbonCourseClass.gibbonCourseClassID)
JOIN gibbonCourse ON (gibbonCourseClass.gibbonCourseID=gibbonCourse.gibbonCourseID)
WHERE gibbonPersonIDStudent=:gibbonPersonIDStudent
AND (attainmentConcern='Y' OR effortConcern='Y')
AND complete='Y'
AND gibbonSchoolYearID=:gibbonSchoolYearID
AND completeDate<=:today
AND completeDate>:date
";
$resultAlert = $connection2->prepare($sqlAlert);
$resultAlert->execute($dataAlert);
$settingGateway = $container->get(SettingGateway::class);
$academicAlertLowThreshold = $settingGateway->getSettingByScope('Students', 'academicAlertLowThreshold');
$academicAlertMediumThreshold = $settingGateway->getSettingByScope('Students', 'academicAlertMediumThreshold');
$academicAlertHighThreshold = $settingGateway->getSettingByScope('Students', 'academicAlertHighThreshold');
if ($resultAlert->rowCount() >= $academicAlertHighThreshold) {
$gibbonAlertLevelID = 001;
$alertThresholdText = sprintf(__('This alert level occurs when there are more than %1$s events recorded for a student.'), $academicAlertHighThreshold);
} elseif ($resultAlert->rowCount() >= $academicAlertMediumThreshold) {
$gibbonAlertLevelID = 002;
$alertThresholdText = sprintf(__('This alert level occurs when there are between %1$s and %2$s events recorded for a student.'), $academicAlertMediumThreshold, ($academicAlertHighThreshold - 1));
} elseif ($resultAlert->rowCount() >= $academicAlertLowThreshold) {
$gibbonAlertLevelID = 003;
$alertThresholdText = sprintf(__('This alert level occurs when there are between %1$s and %2$s events recorded for a student.'), $academicAlertLowThreshold, ($academicAlertMediumThreshold - 1));
}
if ($gibbonAlertLevelID != '') {
/**
* @var AlertLevelGateway
*/
$alertLevelGateway = $container->get(AlertLevelGateway::class);
if ($alert = $alertLevelGateway->getByID($gibbonAlertLevelID)) {
$alerts[] = [
'highestLevel' => __($alert['name']),
'highestColour' => $alert['color'],
'highestColourBG' => $alert['colorBG'],
'tag' => __('A'),
'title' => sprintf(__('Student has a %1$s alert for academic concern over the past 60 days.'), __($alert['name'])) . ' ' . $alertThresholdText,
'link' => Url::fromModuleRoute('Students', 'student_view_details')
->withQueryParams([
'gibbonPersonID' => $gibbonPersonID,
'subpage' => 'Markbook',