-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathswad_layout.c
1804 lines (1545 loc) · 59.9 KB
/
swad_layout.c
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
// swad_layout.c: page layout
/*
SWAD (Shared Workspace At a Distance),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
Copyright (C) 1999-2025 Antonio Cañas Vargas
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
#define _GNU_SOURCE // For asprintf
#include <stddef.h> // For NULL
#include <stdio.h> // For asprintf
#include <stdlib.h> // For exit
#include <string.h> // For string functions
#include "swad_action.h"
#include "swad_action_list.h"
#include "swad_API.h"
#include "swad_banner.h"
#include "swad_box.h"
#include "swad_calendar.h"
#include "swad_call_for_exam.h"
#include "swad_changelog.h"
#include "swad_config.h"
#include "swad_connected.h"
#include "swad_database.h"
#include "swad_error.h"
#include "swad_exam_session.h"
#include "swad_figure.h"
#include "swad_firewall_database.h"
#include "swad_follow.h"
#include "swad_form.h"
#include "swad_global.h"
#include "swad_help.h"
#include "swad_hierarchy.h"
#include "swad_hierarchy_type.h"
#include "swad_holiday.h"
#include "swad_HTML.h"
#include "swad_language.h"
#include "swad_system_link.h"
#include "swad_log.h"
#include "swad_log_database.h"
#include "swad_logo.h"
#include "swad_match.h"
#include "swad_MFU.h"
#include "swad_notice.h"
#include "swad_notification.h"
#include "swad_parameter.h"
#include "swad_process.h"
#include "swad_setting.h"
#include "swad_setting_database.h"
#include "swad_tab.h"
#include "swad_theme.h"
#include "swad_timeline.h"
#include "swad_timeline_who.h"
#include "swad_user_database.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
const char *Lay_HighlightClass[Lay_NUM_HIGHLIGHT] =
{
[Lay_NO_HIGHLIGHT] = NULL,
[Lay_HIGHLIGHT ] = "class=\"BG_HIGHLIGHT\"",
};
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
static void Lay_WritePageTitle (void);
static void Lay_WriteRedirToMyLangOnLogIn (void);
static void Lay_WriteRedirToMyLangOnViewUsrAgd (void);
static void Lay_WriteScripts (void);
static void Lay_WriteScriptMathJax (void);
static void Lay_WriteScriptInit (void);
static void Lay_WriteScriptParsAJAX (void);
static void Lay_WriteScriptCustomDropzone (void);
static void Lay_WritePageTopHeading (void);
static void Lay_WriteBreadcrumb (void);
static void Lay_ShowLeftColumn (void);
static void Lay_ShowRightColumn (void);
static void Lay_WriteFootFromHTMLFile (void);
static void Lay_HelpTextEditor (const char *Text,const char *InlineMath,const char *Equation);
/*****************************************************************************/
/*********************** Write the start of the page *************************/
/*****************************************************************************/
void Lay_WriteStartOfPage (void)
{
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
extern unsigned Txt_Current_CGI_SWAD_Language;
static const char *LayoutMainZone[Mnu_NUM_MENUS] =
{
[Mnu_MENU_HORIZONTAL] = "main_horizontal",
[Mnu_MENU_VERTICAL ] = "main_vertical",
};
Act_BrowserTab_t BrowserTab;
/***** If, when this function is called, the head is being written
or the head is already written ==> don't do anything *****/
if (Gbl.Layout.WritingHTMLStart ||
Gbl.Layout.HTMLStartWritten)
return;
/***** Compute connected users to be displayed in right column *****/
Con_ComputeConnectedUsrsBelongingToCurrentCrs ();
/***** Send head width the file type for the HTTP protocol *****/
if (Gbl.Action.UsesAJAX)
// Don't generate a full HTML page, only the content of a DIV or similar
{
HTM_Txt ("Content-Type: text/html; charset=windows-1252\r\n\r\n");
Gbl.Layout.WritingHTMLStart = false;
Gbl.Layout.HTMLStartWritten = Gbl.Layout.DivsEndWritten = true;
return;
}
/***** If serving a web service ==> don't do anything *****/
if (Gbl.WebService.IsWebService)
{
Gbl.Layout.WritingHTMLStart = false;
Gbl.Layout.HTMLStartWritten = Gbl.Layout.DivsEndWritten = true;
return;
}
Gbl.Layout.WritingHTMLStart = true;
/***** Get browser tab associated to current action *****/
BrowserTab = Act_GetBrowserTab (Gbl.Action.Act);
switch (BrowserTab)
{
case Act_NEW:
case Act_2ND:
Gbl.Prefs.Theme = The_THEME_WHITE; // In a new tab, use white background
break;
default:
break;
}
/***** Write header to standard output to avoid timeout *****/
// Two \r\n are necessary
fprintf (stdout,"Content-type: text/html; charset=windows-1252\r\n\r\n"
"<!DOCTYPE html>\n");
/***** Write start of HTML code *****/
// WARNING: It is necessary to comment the line 'AddDefaultCharset UTF8'
// in httpd.conf to enable meta tag
HTM_TxtF ("<html lang=\"%s\" style=\"color-scheme:%s\">\n",
Lan_STR_LANG_ID[Gbl.Prefs.Language],
Gbl.Prefs.Theme == The_THEME_DARK ? "dark" :
"light");
HTM_Txt ("<head>\n"
"<meta http-equiv=\"Content-Type\" content=\"text/html;charset=windows-1252\" />\n"
"<meta name=\"description\" content=\"A free-software, educational, online tool for managing courses and students.\" />\n"
"<meta name=\"keywords\" content=\"");
HTM_Txt (Cfg_PLATFORM_SHORT_NAME);
HTM_Txt (","
"SWAD,"
"shared workspace at a distance,"
"educational platform,"
"sistema web de apoyo a la docencia,"
"plataforma educativa,"
"campus virtual,"
"SWADroid,"
"LMS,"
"Learning Management System\" />\n");
/* Viewport (used for responsive design) */
HTM_Txt ("<meta name=\"viewport\""
" content=\"width=device-width, initial-scale=1.0\">\n");
/* Title */
Lay_WritePageTitle ();
/* Canonical URL */
HTM_TxtF ("<link rel=\"canonical\" href=\"%s\" />\n",Cfg_URL_SWAD_CGI);
/* Favicon */
HTM_TxtF ("<link type=\"image/x-icon\" href=\"%s/favicon.ico\" rel=\"icon\" />\n",
Cfg_URL_ICON_PUBLIC);
HTM_TxtF ("<link type=\"image/x-icon\" href=\"%s/favicon.ico\" rel=\"shortcut icon\" />\n",
Cfg_URL_ICON_PUBLIC);
/* Style sheet for SWAD */
HTM_TxtF ("<link rel=\"stylesheet\" href=\"%s/%s\" type=\"text/css\" />\n",
Cfg_URL_SWAD_PUBLIC,CSS_FILE);
/* Style sheets for Font Awesome */
HTM_TxtF ("<link rel=\"stylesheet\""
" href=\"%s/fontawesome/css/fontawesome.css\""
" type=\"text/css\" />\n",
Cfg_URL_SWAD_PUBLIC);
HTM_TxtF ("<link rel=\"stylesheet\""
" href=\"%s/fontawesome/css/solid.css\""
" type=\"text/css\" />\n",
Cfg_URL_SWAD_PUBLIC);
/* Style sheet for Dropzone.js (http://www.dropzonejs.com/) */
// The public directory dropzone must hold:
// dropzone.js
// css/dropzone.css
// images/[email protected]
// images/spritemap.png
switch (Gbl.Action.Act)
{
case ActFrmCreDocIns: // Brw_ADMI_DOC_INS
case ActFrmCreShaIns: // Brw_ADMI_SHR_INS
case ActFrmCreDocCtr: // Brw_ADMI_DOC_CTR
case ActFrmCreShaCtr: // Brw_ADMI_SHR_CTR
case ActFrmCreDocDeg: // Brw_ADMI_DOC_DEG
case ActFrmCreShaDeg: // Brw_ADMI_SHR_DEG
case ActFrmCreDocCrs: // Brw_ADMI_DOC_CRS
case ActFrmCreDocGrp: // Brw_ADMI_DOC_GRP
case ActFrmCreTchCrs: // Brw_ADMI_TCH_CRS
case ActFrmCreTchGrp: // Brw_ADMI_TCH_GRP
case ActFrmCreShaCrs: // Brw_ADMI_SHR_CRS
case ActFrmCreShaGrp: // Brw_ADMI_SHR_GRP
case ActFrmCreAsgUsr: // Brw_ADMI_ASG_USR
case ActFrmCreAsgCrs: // Brw_ADMI_ASG_CRS
case ActFrmCreWrkUsr: // Brw_ADMI_WRK_USR
case ActFrmCreWrkCrs: // Brw_ADMI_WRK_CRS
case ActFrmCreDocPrj: // Brw_ADMI_DOC_PRJ
case ActFrmCreAssPrj: // Brw_ADMI_ASS_PRJ
case ActFrmCreMrkCrs: // Brw_ADMI_MRK_CRS
case ActFrmCreMrkGrp: // Brw_ADMI_MRK_GRP
case ActFrmCreBrf: // Brw_ADMI_BRF_USR
HTM_TxtF ("<link rel=\"stylesheet\""
" href=\"%s/dropzone/css/dropzone.css\""
" type=\"text/css\" />\n",
Cfg_URL_SWAD_PUBLIC);
break;
default:
break;
}
/* Redirect to correct language */
if (Gbl.Usrs.Me.Logged && // I am logged
Gbl.Usrs.Me.UsrDat.Prefs.Language != Txt_Current_CGI_SWAD_Language) // My language != current language
{
if (Gbl.Action.Original == ActLogIn || // Regular log in
Gbl.Action.Original == ActLogInNew) // Log in when checking account
Lay_WriteRedirToMyLangOnLogIn ();
else if (Gbl.Action.Original == ActLogInUsrAgd) // Log in to view another user's public agenda
Lay_WriteRedirToMyLangOnViewUsrAgd ();
}
/* Write initial scripts depending on the action */
Lay_WriteScripts ();
HTM_Txt ("</head>\n");
/***** HTML body *****/
switch (BrowserTab)
{
case Act_1ST:
HTM_TxtF ("<body class=\"BODY_%s\" onload=\"init();\">\n",
The_GetSuffix ());
HTM_DIV_Begin ("id=\"zoomLyr\" class=\"ZOOM ZOOM_%s\"",
The_GetSuffix ());
HTM_IMG (Cfg_URL_ICON_PUBLIC,"usr_bl.jpg",NULL,
"class=\"IMG_USR\" id=\"zoomImg\"");
HTM_DIV_Begin ("id=\"zoomTxt\" class=\"CM\"");
HTM_DIV_End ();
HTM_DIV_End ();
break;
case Act_NEW:
case Act_2ND:
HTM_Txt ("<body onload=\"init();\"");
switch (Gbl.Action.Act)
{
case ActNewMch:
case ActResMch:
case ActBckMch:
case ActPlyPauMch:
case ActFwdMch:
case ActChgNumColMch:
case ActChgVisResMchQst:
case ActMchCntDwn:
HTM_Txt (" class=\"MCH_BG\"");
break;
default:
break;
}
HTM_Txt (">\n");
Gbl.Layout.WritingHTMLStart = false;
Gbl.Layout.HTMLStartWritten =
Gbl.Layout.DivsEndWritten = true;
return;
default:
HTM_Txt ("<body>\n");
Gbl.Layout.WritingHTMLStart = false;
Gbl.Layout.HTMLStartWritten =
Gbl.Layout.DivsEndWritten = true;
return;
}
/***** Begin box that contains the whole page except the foot *****/
HTM_DIV_Begin ("id=\"whole_page\"");
/***** Header of layout *****/
Lay_WritePageTopHeading ();
/***** 3rd. row (tabs) *****/
Tab_DrawTabs ();
/***** 4th row: main zone *****/
HTM_DIV_Begin ("id=\"main_zone\"");
/* Left column */
if (Gbl.Prefs.SideCols & Lay_SHOW_LEFT_COLUMN) // Left column visible
{
HTM_Txt ("<aside id=\"left_col\">");
Lay_ShowLeftColumn ();
HTM_Txt ("</aside>");
}
/* Right column */
// Right column is written before central column
// but it must be drawn at right using "position:absolute; right:0".
// The reason to write right column before central column
// is that central column may hold a lot of content drawn slowly.
if (Gbl.Prefs.SideCols & Lay_SHOW_RIGHT_COLUMN) // Right column visible
{
HTM_Txt ("<aside id=\"right_col\">");
Lay_ShowRightColumn ();
HTM_Txt ("</aside>");
}
/* Central (main) column */
switch (Gbl.Prefs.SideCols)
{
case 0:
HTM_DIV_Begin ("id=\"main_zone_central_none\"");
break;
case Lay_SHOW_LEFT_COLUMN:
HTM_DIV_Begin ("id=\"main_zone_central_left\"");
break;
case Lay_SHOW_RIGHT_COLUMN:
HTM_DIV_Begin ("id=\"main_zone_central_right\"");
break;
case (Lay_SHOW_LEFT_COLUMN | Lay_SHOW_RIGHT_COLUMN):
HTM_DIV_Begin ("id=\"main_zone_central_both\"");
break;
}
HTM_DIV_Begin ("id=\"main_zone_central_container\" class=\"TAB_ON_%s\"",
The_GetSuffix ());
/* Layout with horizontal or vertical menu */
HTM_DIV_Begin ("id=\"%s\"",LayoutMainZone[Gbl.Prefs.Menu]);
/* Menu */
Mnu_WriteMenuThisTab ();
/* Begin canvas: main zone for actions output */
HTM_MAIN_Begin ("MAIN_ZONE_CANVAS");
/* If it is mandatory to read any information about course */
Inf_WriteMsgYouMustReadInfo ();
Gbl.Layout.WritingHTMLStart = false;
Gbl.Layout.HTMLStartWritten = true;
/* Write message indicating number of clicks allowed before sending my photo */
Usr_InformAboutNumClicksBeforePhoto ();
}
/*****************************************************************************/
/*********************** Write status 204 No Content *************************/
/*****************************************************************************/
void Lay_WriteHTTPStatus204NoContent (void)
{
/***** The HTTP response is a code status *****/
/* Don't write HTML at all */
Gbl.Layout.HTMLStartWritten =
Gbl.Layout.DivsEndWritten =
Gbl.Layout.HTMLEndWritten = true;
/* Begin HTTP response */
fprintf (stdout,"Content-type: text/plain; charset=windows-1252\n");
/* Return HTTP status code 204 No Content:
The server has successfully fulfilled the request
and there is no additional content to send
in the response payload body. */
fprintf (stdout,"Status: 204\r\n\r\n");
}
/*****************************************************************************/
/************************ Write the end of the page **************************/
/*****************************************************************************/
void Lay_WriteEndOfPage (void)
{
if (!Gbl.Layout.DivsEndWritten)
{
/***** End of central part of main zone *****/
HTM_MAIN_End (); // Canvas (main zone to output content of the current action)
HTM_DIV_End (); // Layout with horizontal or vertical menu
HTM_DIV_End (); // main_zone_central_container
/***** Write page footer *****/
if (Act_GetBrowserTab (Gbl.Action.Act) == Act_1ST)
Lay_WriteFootFromHTMLFile ();
/***** End of main zone and page *****/
HTM_DIV_End (); // main_zone_central
HTM_DIV_End (); // main_zone
HTM_DIV_End (); // whole_page_* (box that contains the whole page except the foot)
Gbl.Layout.DivsEndWritten = true;
}
}
/*****************************************************************************/
/************************* Write the title of the page ***********************/
/*****************************************************************************/
static void Lay_WritePageTitle (void)
{
extern const char *Txt_TAGLINE;
HTM_TITLE_Begin ();
if (Par_GetMethod () == Par_METHOD_GET &&
Gbl.Hierarchy.Node[Hie_DEG].HieCod > 0)
{
HTM_TxtF ("%s > %s",
Cfg_PLATFORM_SHORT_NAME,Gbl.Hierarchy.Node[Hie_DEG].ShrtName);
if (Gbl.Hierarchy.Level == Hie_CRS)
HTM_TxtF (" > %s",Gbl.Hierarchy.Node[Hie_CRS].ShrtName);
}
else
HTM_TxtF ("%s: %s",Cfg_PLATFORM_SHORT_NAME,Txt_TAGLINE);
HTM_TITLE_End ();
}
/*****************************************************************************/
/************* Write script and meta to redirect to my language **************/
/*****************************************************************************/
static void Lay_WriteRedirToMyLangOnLogIn (void)
{
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
HTM_TxtF ("<meta http-equiv=\"refresh\""
" content=\"0; url='%s/%s?act=%ld&ses=%s'\">",
Cfg_URL_SWAD_CGI,
Lan_STR_LANG_ID[Gbl.Usrs.Me.UsrDat.Prefs.Language],
Act_GetActCod (ActLogInLan),
Gbl.Session.Id);
}
static void Lay_WriteRedirToMyLangOnViewUsrAgd (void)
{
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
HTM_TxtF ("<meta http-equiv=\"refresh\""
" content=\"0; url='%s/%s?act=%ld&ses=%s&agd=@%s'\">",
Cfg_URL_SWAD_CGI,
Lan_STR_LANG_ID[Gbl.Usrs.Me.UsrDat.Prefs.Language],
Act_GetActCod (ActLogInUsrAgdLan),
Gbl.Session.Id,
Gbl.Usrs.Other.UsrDat.Nickname);
}
/*****************************************************************************/
/************ Write some scripts depending on the current action *************/
/*****************************************************************************/
static void Lay_WriteScripts (void)
{
extern const char *Txt_DAYS[7];
extern const char *Txt_DAYS2[7];
extern const char *Txt_Exam_of_X;
struct Hld_Holidays Holidays;
struct Cfe_CallsForExams ExamAnns;
unsigned DayOfWeek; /* 0, 1, 2, 3, 4, 5, 6 */
unsigned NumHld;
unsigned NumExamAnnouncement; // Number of exam announcement
/***** General scripts for swad *****/
HTM_SCRIPT_Begin (Cfg_URL_SWAD_PUBLIC "/" JS_FILE,NULL);
HTM_SCRIPT_End ();
/***** Script for MathJax *****/
Lay_WriteScriptMathJax ();
/***** Write script with init function executed after loading page *****/
Lay_WriteScriptInit ();
/***** Write script to set parameters needed by AJAX *****/
Lay_WriteScriptParsAJAX ();
/***** Write script to initialize variables used to draw dates *****/
HTM_SCRIPT_Begin (NULL,NULL);
HTM_Txt ("\tconst DAYS = [");
for (DayOfWeek = 0;
DayOfWeek < 7;
DayOfWeek++)
{
if (DayOfWeek)
HTM_Comma ();
HTM_TxtF ("'%s'",Txt_DAYS[DayOfWeek]);
}
HTM_Txt ("];\n");
HTM_Txt ("\tconst DAYS2 = [");
for (DayOfWeek = 0;
DayOfWeek < 7;
DayOfWeek++)
{
if (DayOfWeek)
HTM_Comma ();
HTM_TxtF ("'%s'",Txt_DAYS2[DayOfWeek]);
}
HTM_Txt ("];\n");
HTM_SCRIPT_End ();
/***** Prepare script to draw months *****/
if ((Gbl.Prefs.SideCols & Lay_SHOW_LEFT_COLUMN) || // Left column visible
Gbl.Action.Act == ActSeeCal || // Viewing calendar
Gbl.Action.Act == ActPrnCal || // Printing calendar
Gbl.Action.Act == ActChgCal1stDay) // Changing first day
{
/***** Reset places context *****/
Hld_ResetHolidays (&Holidays);
/***** Get list of holidays *****/
Holidays.SelectedOrder = Hld_ORDER_BY_START_DATE;
Hld_GetListHolidays (&Holidays);
/***** Reset exam announcements context *****/
Cfe_ResetCallsForExams (&ExamAnns);
/***** Create list of exam announcements *****/
Cfe_CreateListCallsForExams (&ExamAnns);
/***** Write script to initialize variables used to draw months *****/
HTM_SCRIPT_Begin (NULL,NULL);
HTM_Txt ("\tconst STR_EXAM = '");
HTM_TxtF (Txt_Exam_of_X,Gbl.Hierarchy.Node[Hie_CRS].FullName);
HTM_Txt ("';\n");
HTM_Txt ("\tvar Hlds = [];\n");
for (NumHld = 0;
NumHld < Holidays.Num;
NumHld++)
HTM_TxtF ("\tHlds.push({ PlcCod: %ld, HldTyp: %u, StartDate: %s, EndDate: %s, Name: '%s' });\n",
Holidays.Lst[NumHld].PlcCod,
(unsigned) Holidays.Lst[NumHld].HldTyp,
Holidays.Lst[NumHld].StartDate.YYYYMMDD,
Holidays.Lst[NumHld].EndDate.YYYYMMDD,
Holidays.Lst[NumHld].Name);
HTM_TxtF ("\tvar LstExamAnnouncements = [];\n");
for (NumExamAnnouncement = 0;
NumExamAnnouncement < ExamAnns.NumCallsForExams;
NumExamAnnouncement++)
HTM_TxtF ("LstExamAnnouncements.push({ ExaCod: %ld, Year: %u, Month: %u, Day: %u });\n",
ExamAnns.Lst[NumExamAnnouncement].ExaCod,
ExamAnns.Lst[NumExamAnnouncement].ExamDate.Year,
ExamAnns.Lst[NumExamAnnouncement].ExamDate.Month,
ExamAnns.Lst[NumExamAnnouncement].ExamDate.Day);
HTM_SCRIPT_End ();
/***** Free list of exam announcements *****/
Cfe_FreeListCallsForExams (&ExamAnns);
/***** Free list of holidays *****/
Hld_FreeListHolidays (&Holidays);
}
/***** Scripts depending on action *****/
switch (Gbl.Action.Act)
{
/***** Script to print world map *****/
case ActSeeCty:
Cty_WriteScriptGoogleGeochart ();
break;
/***** Script for uploading files using Dropzone.js (http://www.dropzonejs.com/) *****/
// The public directory dropzone must hold:
// dropzone.js
// css/dropzone.css
// images/[email protected]
// images/spritemap.png
case ActFrmCreDocIns: // Brw_ADMI_DOC_INS
case ActFrmCreShaIns: // Brw_ADMI_SHR_INS
case ActFrmCreDocCtr: // Brw_ADMI_DOC_CTR
case ActFrmCreShaCtr: // Brw_ADMI_SHR_CTR
case ActFrmCreDocDeg: // Brw_ADMI_DOC_DEG
case ActFrmCreShaDeg: // Brw_ADMI_SHR_DEG
case ActFrmCreDocCrs: // Brw_ADMI_DOC_CRS
case ActFrmCreDocGrp: // Brw_ADMI_DOC_GRP
case ActFrmCreTchCrs: // Brw_ADMI_TCH_CRS
case ActFrmCreTchGrp: // Brw_ADMI_TCH_GRP
case ActFrmCreShaCrs: // Brw_ADMI_SHR_CRS
case ActFrmCreShaGrp: // Brw_ADMI_SHR_GRP
case ActFrmCreAsgUsr: // Brw_ADMI_ASG_USR
case ActFrmCreAsgCrs: // Brw_ADMI_ASG_CRS
case ActFrmCreWrkUsr: // Brw_ADMI_WRK_USR
case ActFrmCreWrkCrs: // Brw_ADMI_WRK_CRS
case ActFrmCreDocPrj: // Brw_ADMI_DOC_PRJ
case ActFrmCreAssPrj: // Brw_ADMI_ASS_PRJ
case ActFrmCreMrkCrs: // Brw_ADMI_MRK_CRS
case ActFrmCreMrkGrp: // Brw_ADMI_MRK_GRP
case ActFrmCreBrf: // Brw_ADMI_BRF_USR
// Use charset="windows-1252" to force error messages in windows-1252 (default is UTF-8)
HTM_SCRIPT_Begin (Cfg_URL_SWAD_PUBLIC "/dropzone/dropzone.js","windows-1252");
HTM_SCRIPT_End ();
Lay_WriteScriptCustomDropzone ();
break;
case ActSeeAllStaCrs:
case ActReqAccGbl:
case ActSeeAccGbl:
case ActReqAccCrs:
case ActSeeAccCrs:
HTM_SCRIPT_Begin (Cfg_URL_SWAD_PUBLIC "/jstz/jstz.js",NULL);
HTM_SCRIPT_End ();
break;
default:
break;
}
}
// Change page title
//function changeTitle(title) {
// document.title = title;
//}
/*****************************************************************************/
/************ Write some scripts depending on the current action *************/
/*****************************************************************************/
static void Lay_WriteScriptMathJax (void)
{
/* MathJax 2.5.1 (obsolete) */
/*
#ifdef Cfg_MATHJAX_LOCAL
// Use the local copy of MathJax
HTM_SCRIPT_Begin (Cfg_URL_SWAD_PUBLIC "/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML",NULL);
#else
// Use the MathJax Content Delivery Network (CDN)
HTM_SCRIPT_Begin ("//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML",NULL);
#endif
HTM_SCRIPT_End ();
*/
/* MathJax 3.0.1 (march 2020)
Source:
http://docs.mathjax.org/en/latest/web/configuration.html
*/
/* Configuration Using an In-Line Script */
/*
HTM_Txt ("<script type=\"text/x-mathjax-config\">\n"
"MathJax = {\n"
" tex: {\n"
" inlineMath: [['$','$'], ['\\\\(','\\\\)']]\n"
" }\n"
"};\n"
"</script>");
*/
/* Using a Local File for Configuration
Using a Local File for Configuration
If you are using the same MathJax configuration over multiple pages,
you may find it convenient to store your configuration
in a separate JavaScript file that you load into the page.
For example, you could create a file called mathjax-config.js that contains
window.MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']],
},
svg: {
fontCache: 'global'
}
};
and then use
<script src="mathjax-config.js" defer></script>
<script type="text/javascript" id="MathJax-script" defer
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js">
</script>
to first load your configuration file,
and then load the tex-svg component from the jsdelivr CDN.
Note that here we use the defer attribute on both scripts
so that they will execute in order,
but still not block the rest of the page
while the files are being downloaded to the browser.
If the async attribute were used,
there is no guarantee that the configuration would run first,
and so you could get instances
where MathJax doesn't get properly configured,
and they would seem to occur randomly.
*/
HTM_TxtF ("<script src=\"%s/mathjax-config.js\" defer>\n"
"</script>\n",
Cfg_URL_SWAD_PUBLIC);
#ifdef Cfg_MATHJAX_LOCAL
// Use the local copy of MathJax
HTM_TxtF ("<script type=\"text/javascript\" id=\"MathJax-script\" defer"
" src=\"%s/mathjax/tex-chtml.js\">\n"
"</script>\n",
Cfg_URL_SWAD_PUBLIC);
#else
// Use the MathJax Content Delivery Network (CDN)
HTM_TxtF ("<script type=\"text/javascript\" id=\"MathJax-script\" defer"
" src=\"https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js\">\n"
"</script>\n");
#endif
}
/*****************************************************************************/
/******* Write script with init function executed after loading page *********/
/*****************************************************************************/
static void Lay_WriteScriptInit (void)
{
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
bool RefreshConnected;
bool RefreshLastClicks = false;
bool RefreshNewTimeline = false;
bool RefreshOldTimeline = false;
bool RefreshMatchStd = false;
bool RefreshMatchTch = false;
RefreshConnected = Act_GetBrowserTab (Gbl.Action.Act) == Act_1ST &&
(Gbl.Prefs.SideCols & Lay_SHOW_RIGHT_COLUMN); // Right column visible
switch (Gbl.Action.Act)
{
/* Last clicks */
case ActLstClk:
RefreshLastClicks = true;
break;
/* Global timeline */
case ActSeeGblTL:
case ActRcvPstGblTL:
case ActRcvComGblTL:
case ActReqRemPubGblTL:
case ActRemPubGblTL:
case ActReqRemComGblTL:
case ActRemComGblTL:
RefreshNewTimeline = true;
RefreshOldTimeline = true;
break;
/* User timeline */
case ActSeeOthPubPrf:
case ActRcvPstUsrTL:
case ActRcvComUsrTL:
case ActReqRemPubUsrTL:
case ActRemPubUsrTL:
case ActReqRemComUsrTL:
case ActRemComUsrTL:
RefreshOldTimeline = true;
break;
/* Match */
case ActJoiMch:
case ActSeeMchAnsQstStd:
case ActRemMchAnsQstStd:
case ActAnsMchQstStd:
RefreshMatchStd = true;
break;
case ActNewMch:
case ActResMch:
case ActBckMch:
case ActPlyPauMch:
case ActFwdMch:
case ActChgNumColMch:
case ActChgVisResMchQst:
case ActMchCntDwn:
RefreshMatchTch = true;
break;
default:
break;
}
HTM_SCRIPT_Begin (NULL,NULL);
Dat_WriteScriptMonths ();
if (RefreshNewTimeline) // Refresh new timeline via AJAX
HTM_TxtF ("\tvar delayNewTml = %lu;\n",Cfg_TIME_TO_REFRESH_TIMELINE);
else if (RefreshMatchStd) // Refresh match via AJAX
HTM_TxtF ("\tconst delayMatch = %lu;\n",Cfg_TIME_TO_REFRESH_MATCH_STD);
else if (RefreshMatchTch) // Refresh match via AJAX
HTM_TxtF ("\tconst delayMatch = %lu;\n",Cfg_TIME_TO_REFRESH_MATCH_TCH);
/***** Function init () ******/
HTM_Txt ("function init() {\n");
HTM_TxtF ("\tactionAJAX = \"%s\";\n",Lan_STR_LANG_ID[Gbl.Prefs.Language]);
if (RefreshConnected) // Refresh connected users via AJAX
{
Con_WriteScriptClockConnected ();
HTM_TxtF ("\tsetTimeout('refreshConnected()',%lu);\n",
Gbl.Usrs.Connected.TimeToRefreshInMs);
}
if (RefreshLastClicks) // Refresh last clicks via AJAX
HTM_TxtF ("\tsetTimeout('refreshLastClicks()',%lu);\n",
Cfg_TIME_TO_REFRESH_LAST_CLICKS);
else if (RefreshNewTimeline || RefreshOldTimeline) // Refresh timeline via AJAX
{
if (RefreshNewTimeline)
HTM_Txt ("\tsetTimeout('refreshNewTimeline()',delayNewTml);\n");
if (RefreshOldTimeline)
HTM_Txt ("\twindow.addEventListener('scroll', handleInfiniteScroll);\n");
}
else if (RefreshMatchStd) // Refresh match for a student via AJAX
HTM_Txt ("\tsetTimeout('refreshMatchStd()',delayMatch);\n");
else if (RefreshMatchTch) // Refresh match for a teacher via AJAX
HTM_Txt ("\tsetTimeout('refreshMatchTch()',delayMatch);\n");
HTM_Txt ("}\n");
HTM_SCRIPT_End ();
}
/*****************************************************************************/
/************** Write script to set parameters needed by AJAX ****************/
/*****************************************************************************/
static void Lay_WriteScriptParsAJAX (void)
{
/***** Begin script *****/
HTM_SCRIPT_Begin (NULL,NULL);
/***** Parameters with code of session and current course code *****/
// Refresh parameters
HTM_TxtF ("const refreshParamIdSes = \"ses=%s\";\n"
"const refreshParamCrsCod = \"crs=%ld\";\n",
Gbl.Session.Id,
Gbl.Hierarchy.Node[Hie_CRS].HieCod);
/***** Parameter to refresh connected users *****/
if (Act_GetBrowserTab (Gbl.Action.Act) == Act_1ST)
// Refresh parameter
HTM_TxtF ("const refreshParamNxtActCon = \"act=%ld\";\n",
Act_GetActCod (ActRefCon));
/***** Parameters related with expanding/contracting folders in file browsers *****/
if (Gbl.FileBrowser.Type != Brw_UNKNOWN)
/* In all actions related to file browsers ==>
put parameters used by AJAX */
// Refresh parameters
HTM_TxtF ("const refreshParamExpand = \"act=%ld\";\n"
"const refreshParamContract = \"act=%ld\";\n",
Act_GetActCod (Brw_GetActionExpand ()),
Act_GetActCod (Brw_GetActionContract ()));
/***** Parameters related with other actions *****/
switch (Gbl.Action.Act)
{
/* Parameters related with global timeline refreshing */
case ActSeeGblTL:
case ActRcvPstGblTL:
case ActRcvComGblTL:
case ActReqRemPubGblTL:
case ActRemPubGblTL:
case ActReqRemComGblTL:
case ActRemComGblTL:
/* In all actions related to view or editing global timeline ==>
put parameters used by AJAX */
// Refresh parameters
HTM_TxtF ("const refreshParamNxtActNewPub = \"act=%ld\";\n"
"const refreshParamNxtActOldPub = \"act=%ld\";\n"
"const refreshParamWho = \"Who=%u\";\n",
Act_GetActCod (ActRefNewPubGblTL),
Act_GetActCod (ActRefOldPubGblTL),
(unsigned) TmlWho_GetGlobalWho ()); // Global variable got in a priori function
break;
/* Parameters related with user timeline refreshing */
case ActSeeOthPubPrf:
case ActRcvPstUsrTL:
case ActRcvComUsrTL:
case ActReqRemPubUsrTL:
case ActRemPubUsrTL:
case ActReqRemComUsrTL:
case ActRemComUsrTL:
/* In all actions related to view or editing user's timeline ==>
put parameters used by AJAX */
if (Gbl.Usrs.Other.UsrDat.UsrCod <= 0)
Usr_GetParOtherUsrCodEncrypted (&Gbl.Usrs.Other.UsrDat);
// Refresh parameters
HTM_TxtF ("const refreshParamNxtActOldPub = \"act=%ld\";\n"
"const refreshParamUsr = \"OtherUsrCod=%s\";\n",
Act_GetActCod (ActRefOldPubUsrTL),
Gbl.Usrs.Other.UsrDat.EnUsrCod);
break;
/* Parameters related with match refreshing (for students) */
case ActJoiMch:
case ActSeeMchAnsQstStd:
case ActRemMchAnsQstStd:
case ActAnsMchQstStd:
// Refresh parameters
HTM_TxtF ("const refreshParamNxtActMch = \"act=%ld\";\n"
"const refreshParamMchCod = \"MchCod=%ld\";\n",
Act_GetActCod (ActRefMchStd),
Mch_GetMchCodBeingPlayed ());
break;
/* Parameters related with match refreshing (for teachers) */
case ActNewMch:
case ActResMch:
case ActBckMch:
case ActPlyPauMch:
case ActFwdMch:
case ActChgNumColMch:
case ActChgVisResMchQst:
case ActMchCntDwn:
// Handle keys in keyboard/presenter
HTM_Txt ("document.addEventListener(\"keydown\",handleMatchKeys);\n");
// Refresh parameters
HTM_TxtF ("const refreshParamNxtActMch = \"act=%ld\";\n"
"const refreshParamMchCod = \"MchCod=%ld\";\n",
Act_GetActCod (ActRefMchTch),
Mch_GetMchCodBeingPlayed ());
break;
/* Parameter related with clicks refreshing */
case ActLstClk:
// Refresh parameter
HTM_TxtF ("const refreshParamNxtActLstClk = \"act=%ld\";\n",
Act_GetActCod (ActRefLstClk));
break;
default:
break;
}
/***** End script *****/
HTM_SCRIPT_End ();
}
/*****************************************************************************/
/******* Write script to customize upload of files using Dropzone.js *********/
/*****************************************************************************/
// More info: http://www.dropzonejs.com/
static void Lay_WriteScriptCustomDropzone (void)
{
// "myAwesomeDropzone" is the camelized version of the HTML element's ID
// Add a line "forceFallback: true,\n" to test classic upload
HTM_SCRIPT_Begin (NULL,NULL);
HTM_TxtF ("Dropzone.options.myAwesomeDropzone = {\n"
"maxFiles: 100,\n"
"parallelUploads: 100,\n"
"maxFilesize: %lu,\n"
"fallback: function() {\n"
"document.getElementById('dropzone-upload').style.display='none';\n"
"document.getElementById('classic-upload').style.display='block';\n"
"}\n"
"};\n",
(unsigned long) (Fil_MAX_FILE_SIZE / (1024ULL * 1024ULL) - 1));
HTM_SCRIPT_End ();
}