-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathswad_agenda.c
1629 lines (1351 loc) · 54.6 KB
/
swad_agenda.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_agenda.c: user's agenda (personal organizer)
/*
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 3 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 <linux/limits.h> // For PATH_MAX
#include <stddef.h> // For NULL
#include <stdio.h> // For asprintf
#include <stdlib.h> // For calloc
#include <string.h> // For string functions
#include "swad_action_list.h"
#include "swad_agenda.h"
#include "swad_agenda_database.h"
#include "swad_autolink.h"
#include "swad_box.h"
#include "swad_database.h"
#include "swad_date.h"
#include "swad_error.h"
#include "swad_figure.h"
#include "swad_form.h"
#include "swad_global.h"
#include "swad_group.h"
#include "swad_hidden_visible.h"
#include "swad_HTML.h"
#include "swad_notification.h"
#include "swad_pagination.h"
#include "swad_parameter.h"
#include "swad_photo.h"
#include "swad_privacy.h"
#include "swad_QR.h"
#include "swad_setting.h"
#include "swad_string.h"
#include "swad_www.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
static const char *ParPast__FutureName = "Past__Future";
static const char *ParPrivatPublicName = "PrivatPublic";
static const char *ParHiddenVisiblName = "HiddenVisibl";
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
static void Agd_ResetAgenda (struct Agd_Agenda *Agenda);
static void Agd_ShowMyAgenda (struct Agd_Agenda *Agenda);
static void Agd_ShowFormToSelPast__FutureEvents (const struct Agd_Agenda *Agenda);
static void Agd_ShowFormToSelPrivatPublicEvents (const struct Agd_Agenda *Agenda);
static void Agd_ShowFormToSelHiddenVisiblEvents (const struct Agd_Agenda *Agenda);
static void Agd_PutParPast__FutureEvents (unsigned Past__FutureEvents);
static void Agd_PutParPrivatPublicEvents (unsigned PrivatPublicEvents);
static void Agd_PutParHiddenVisiblEvents (unsigned HiddenVisiblEvents);
static unsigned Agd_GetParsPast__FutureEvents (void);
static unsigned Agd_GetParsPrivatPublicEvents (void);
static unsigned Agd_GetParsHiddenVisiblEvents (void);
static void Agd_ShowEvents (struct Agd_Agenda *Agenda,
Agd_AgendaType_t AgendaType);
static void Agd_ShowEventsToday (struct Agd_Agenda *Agenda,
Agd_AgendaType_t AgendaType);
static void Agd_WriteHeaderListEvents (const struct Agd_Agenda *Agenda,
Agd_AgendaType_t AgendaType);
static void Agd_PutIconsMyFullAgenda (void *Agenda);
static void Agd_PutIconsMyPublicAgenda (void *EncryptedUsrCod);
static void Agd_PutIconToCreateNewEvent (void *Agenda);
static void Agd_PutIconToViewEditMyFullAgenda (void *EncryptedUsrCod);
static void Agd_PutIconToShowQR (void);
static void Agd_PutIconsOtherPublicAgenda (void *EncryptedUsrCod);
static void Agd_ShowOneEvent (struct Agd_Agenda *Agenda,
Agd_AgendaType_t AgendaType,long AgdCod);
static void Agd_GetParEventOrder (struct Agd_Agenda *Agenda);
static void Agd_PutFormsToRemEditOneEvent (struct Agd_Agenda *Agenda,
struct Agd_Event *AgdEvent,
const char *Anchor);
static void Agd_PutCurrentParsMyAgenda (void *Agenda);
static void Agd_GetPars (struct Agd_Agenda *Agenda,
Agd_AgendaType_t AgendaType);
static void Agd_GetListEvents (struct Agd_Agenda *Agenda,
Agd_AgendaType_t AgendaType);
static void Agd_GetventDataByCod (struct Agd_Event *AgdEvent);
static void Agd_FreeListEvents (struct Agd_Agenda *Agenda);
static void Agd_HideUnhideEvent (HidVis_HiddenOrVisible_t HiddenOrVisible);
/*****************************************************************************/
/******************* Check if I can view a user's agenda *********************/
/*****************************************************************************/
Usr_Can_t Agd_CheckIfICanViewUsrAgenda (struct Usr_Data *UsrDat)
{
/***** 1. Fast check: Am I logged? *****/
if (!Gbl.Usrs.Me.Logged)
return Usr_CAN_NOT;
/***** 2. Fast check: It's me? *****/
if (Usr_ItsMe (UsrDat->UsrCod) == Usr_ME)
return Usr_CAN;
/***** 3. Fast check: Am I logged as system admin? *****/
if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)
return Usr_CAN;
/***** 4. Slow check: Get if user shares any course with me from database *****/
return Enr_CheckIfUsrSharesAnyOfMyCrs (UsrDat) ? Usr_CAN :
Usr_CAN_NOT;
}
/*****************************************************************************/
/*************************** Reset agenda context ****************************/
/*****************************************************************************/
static void Agd_ResetAgenda (struct Agd_Agenda *Agenda)
{
Agenda->LstIsRead = false;
Agenda->Num = 0;
Agenda->LstAgdCods = NULL;
Agenda->Past__FutureEvents = Agd_DEFAULT_PAST___EVENTS |
Agd_DEFAULT_FUTURE_EVENTS;
Agenda->PrivatPublicEvents = Agd_DEFAULT_PRIVAT_EVENTS |
Agd_DEFAULT_PUBLIC_EVENTS;
Agenda->HiddenVisiblEvents = Agd_DEFAULT_HIDDEN_EVENTS |
Agd_DEFAULT_VISIBL_EVENTS;
Agenda->SelectedOrder = Agd_ORDER_DEFAULT;
Agenda->AgdCodToEdit = -1L;
Agenda->CurrentPage = 0;
}
/*****************************************************************************/
/********** Put form to log in and then show another user's agenda ***********/
/*****************************************************************************/
void Agd_PutFormLogInToShowUsrAgenda (void)
{
Usr_WriteFormLogin (ActLogInUsrAgd,Agd_PutParAgd);
}
void Agd_PutParAgd (void)
{
char NickWithArr[Nck_MAX_BYTES_NICK_WITH_ARROBA + 1];
snprintf (NickWithArr,sizeof (NickWithArr),"@%s",Gbl.Usrs.Other.UsrDat.Nickname);
Par_PutParString (NULL,"agd",NickWithArr);
}
/*****************************************************************************/
/******************************* Show my agenda ******************************/
/*****************************************************************************/
void Agd_GetParsAndShowMyAgenda (void)
{
struct Agd_Agenda Agenda;
/***** Reset agenda context *****/
Agd_ResetAgenda (&Agenda);
/***** Get parameters *****/
Agd_GetPars (&Agenda,Agd_MY_AGENDA);
/***** Show my agenda *****/
Agd_ShowMyAgenda (&Agenda);
}
static void Agd_ShowMyAgenda (struct Agd_Agenda *Agenda)
{
extern const char *Hlp_PROFILE_Agenda;
extern const char *Txt_My_agenda;
/***** Begin box *****/
Box_BoxBegin (Txt_My_agenda,Agd_PutIconsMyFullAgenda,Agenda,
Hlp_PROFILE_Agenda,Box_NOT_CLOSABLE);
/***** Put forms to choice which events to show *****/
Set_BeginSettingsHead ();
Agd_ShowFormToSelPast__FutureEvents (Agenda);
Agd_ShowFormToSelPrivatPublicEvents (Agenda);
Agd_ShowFormToSelHiddenVisiblEvents (Agenda);
Set_EndSettingsHead ();
/***** Show the current events in the user's agenda *****/
Agd_ShowEventsToday (Agenda,Agd_MY_AGENDA_TODAY);
/***** Show all my events *****/
Agd_ShowEvents (Agenda,Agd_MY_AGENDA);
/***** End box *****/
Box_BoxEnd ();
}
/*****************************************************************************/
/*************** Show form to select past / future events ********************/
/*****************************************************************************/
static void Agd_ShowFormToSelPast__FutureEvents (const struct Agd_Agenda *Agenda)
{
extern const char *Txt_AGENDA_PAST___FUTURE_EVENTS[Agd_NUM_PAST_FUTURE_EVENTS];
Agd_Past__FutureEvents_t PstFut;
static const char *Icon[Agd_NUM_PAST_FUTURE_EVENTS] =
{
[Agd_PAST___EVENTS] = "calendar-minus.svg",
[Agd_FUTURE_EVENTS] = "calendar-plus.svg",
};
Set_BeginOneSettingSelector ();
for (PstFut = Agd_PAST___EVENTS;
PstFut <= Agd_FUTURE_EVENTS;
PstFut++)
{
Set_BeginPref ((Agenda->Past__FutureEvents & (1 << PstFut)));
Frm_BeginForm (ActSeeMyAgd);
Agd_PutParsMyAgenda (Agenda->Past__FutureEvents ^ (1 << PstFut), // Toggle
Agenda->PrivatPublicEvents,
Agenda->HiddenVisiblEvents,
Agenda->SelectedOrder,
Agenda->CurrentPage,
-1L);
Ico_PutSettingIconLink (Icon[PstFut],Ico_BLACK,
Txt_AGENDA_PAST___FUTURE_EVENTS[PstFut]);
Frm_EndForm ();
Set_EndPref ();
}
Set_EndOneSettingSelector ();
}
/*****************************************************************************/
/************** Show form to select private / public events ******************/
/*****************************************************************************/
static void Agd_ShowFormToSelPrivatPublicEvents (const struct Agd_Agenda *Agenda)
{
extern const char *Txt_AGENDA_PRIVAT_PUBLIC_EVENTS[2];
Agd_PrivatPublicEvents_t PrvPub;
static struct
{
const char *Icon;
Ico_Color_t Color;
} Icon[Agd_NUM_PRIVAT_PUBLIC_EVENTS] =
{
[Agd_PRIVAT_EVENTS] = {"lock.svg" ,Ico_RED },
[Agd_PUBLIC_EVENTS] = {"unlock.svg",Ico_GREEN},
};
Set_BeginOneSettingSelector ();
for (PrvPub = Agd_PRIVAT_EVENTS;
PrvPub <= Agd_PUBLIC_EVENTS;
PrvPub++)
{
Set_BeginPref ((Agenda->PrivatPublicEvents & (1 << PrvPub)));
Frm_BeginForm (ActSeeMyAgd);
Agd_PutParsMyAgenda (Agenda->Past__FutureEvents,
Agenda->PrivatPublicEvents ^ (1 << PrvPub), // Toggle
Agenda->HiddenVisiblEvents,
Agenda->SelectedOrder,
Agenda->CurrentPage,
-1L);
Ico_PutSettingIconLink (Icon[PrvPub].Icon,Icon[PrvPub].Color,
Txt_AGENDA_PRIVAT_PUBLIC_EVENTS[PrvPub]);
Frm_EndForm ();
Set_EndPref ();
}
Set_EndOneSettingSelector ();
}
/*****************************************************************************/
/************* Show form to select hidden / visible events *******************/
/*****************************************************************************/
static void Agd_ShowFormToSelHiddenVisiblEvents (const struct Agd_Agenda *Agenda)
{
extern struct Ico_IconColor Ico_HiddenVisible[HidVis_NUM_HIDDEN_VISIBLE];
extern const char *Txt_AGENDA_HIDDEN_VISIBLE_EVENTS[HidVis_NUM_HIDDEN_VISIBLE];
HidVis_HiddenOrVisible_t HiddenOrVisible;
Set_BeginOneSettingSelector ();
for (HiddenOrVisible = HidVis_HIDDEN;
HiddenOrVisible <= HidVis_VISIBLE;
HiddenOrVisible++)
{
Set_BeginPref ((Agenda->HiddenVisiblEvents & (1 << HiddenOrVisible)));
Frm_BeginForm (ActSeeMyAgd);
Agd_PutParsMyAgenda (Agenda->Past__FutureEvents,
Agenda->PrivatPublicEvents,
Agenda->HiddenVisiblEvents ^ (1 << HiddenOrVisible), // Toggle
Agenda->SelectedOrder,
Agenda->CurrentPage,
-1L);
Ico_PutSettingIconLink (Ico_HiddenVisible[HiddenOrVisible].Icon,
Ico_HiddenVisible[HiddenOrVisible].Color,
Txt_AGENDA_HIDDEN_VISIBLE_EVENTS[HiddenOrVisible]);
Frm_EndForm ();
Set_EndPref ();
}
Set_EndOneSettingSelector ();
}
/*****************************************************************************/
/************************ Put hidden params for events ***********************/
/*****************************************************************************/
static void Agd_PutParPast__FutureEvents (unsigned Past__FutureEvents)
{
Par_PutParUnsigned (NULL,ParPast__FutureName,Past__FutureEvents);
}
static void Agd_PutParPrivatPublicEvents (unsigned PrivatPublicEvents)
{
Par_PutParUnsigned (NULL,ParPrivatPublicName,PrivatPublicEvents);
}
static void Agd_PutParHiddenVisiblEvents (unsigned HiddenVisiblEvents)
{
Par_PutParUnsigned (NULL,ParHiddenVisiblName,HiddenVisiblEvents);
}
/*****************************************************************************/
/************************ Get hidden params for events ***********************/
/*****************************************************************************/
static unsigned Agd_GetParsPast__FutureEvents (void)
{
return (unsigned) Par_GetParUnsignedLong (ParPast__FutureName,
0,
(1 << Agd_PAST___EVENTS) |
(1 << Agd_FUTURE_EVENTS),
Agd_DEFAULT_PAST___EVENTS |
Agd_DEFAULT_FUTURE_EVENTS);
}
static unsigned Agd_GetParsPrivatPublicEvents (void)
{
return (unsigned) Par_GetParUnsignedLong (ParPrivatPublicName,
0,
(1 << Agd_PRIVAT_EVENTS) |
(1 << Agd_PUBLIC_EVENTS),
Agd_DEFAULT_PRIVAT_EVENTS |
Agd_DEFAULT_PUBLIC_EVENTS);
}
static unsigned Agd_GetParsHiddenVisiblEvents (void)
{
return (unsigned) Par_GetParUnsignedLong (ParHiddenVisiblName,
0,
(1 << HidVis_HIDDEN) |
(1 << HidVis_VISIBLE),
Agd_DEFAULT_HIDDEN_EVENTS |
Agd_DEFAULT_VISIBL_EVENTS);
}
/*****************************************************************************/
/************************ Show another user's agenda *************************/
/*****************************************************************************/
void Agd_ShowUsrAgenda (void)
{
extern const char *Hlp_PROFILE_Agenda_public_agenda;
extern const char *Txt_Public_agenda_USER;
extern struct Usr_Data *Usr_UsrDat[Usr_NUM_ME_OR_OTHER];
struct Agd_Agenda Agenda;
Usr_MeOrOther_t MeOrOther;
char *Title;
static void (*FuncPutIcons[Usr_NUM_ME_OR_OTHER]) (void *EncryptedUsrCod) =
{
[Usr_ME ] = Agd_PutIconsMyPublicAgenda,
[Usr_OTHER] = Agd_PutIconsOtherPublicAgenda,
};
/***** Get user *****/
if (Usr_GetParOtherUsrCodEncryptedAndGetUsrData ())
switch (Agd_CheckIfICanViewUsrAgenda (&Gbl.Usrs.Other.UsrDat))
{
case Usr_CAN:
/***** Reset agenda context *****/
Agd_ResetAgenda (&Agenda);
/***** Begin box *****/
MeOrOther = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod);
if (asprintf (&Title,Txt_Public_agenda_USER,Usr_UsrDat[MeOrOther]->FullName) < 0)
Err_NotEnoughMemoryExit ();
Box_BoxBegin (Title,
FuncPutIcons[MeOrOther],Usr_UsrDat[MeOrOther]->EnUsrCod,
Hlp_PROFILE_Agenda_public_agenda,Box_NOT_CLOSABLE);
free (Title);
/***** Show the current events in the user's agenda *****/
Agd_ShowEventsToday (&Agenda,Agd_ANOTHER_AGENDA_TODAY);
/***** Show all visible events in the user's agenda *****/
Agd_ShowEvents (&Agenda,Agd_ANOTHER_AGENDA);
/***** End box *****/
Box_BoxEnd ();
break;
case Usr_CAN_NOT:
default:
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
break;
}
else
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
}
/*****************************************************************************/
/***************** Show another user's agenda after log in *******************/
/*****************************************************************************/
void Agd_ShowOtherAgendaAfterLogIn (void)
{
extern const char *Hlp_PROFILE_Agenda_public_agenda;
extern unsigned Txt_Current_CGI_SWAD_Language;
extern const char *Txt_Public_agenda_USER;
extern const char *Txt_Switching_to_LANGUAGE[1 + Lan_NUM_LANGUAGES];
extern struct Usr_Data *Usr_UsrDat[Usr_NUM_ME_OR_OTHER];
struct Agd_Agenda Agenda;
Usr_MeOrOther_t MeOrOther;
char *Title;
static void (*FuncPutIcons[Usr_NUM_ME_OR_OTHER]) (void *EncryptedUsrCod) =
{
[Usr_ME ] = Agd_PutIconToViewEditMyFullAgenda,
[Usr_OTHER] = Agd_PutIconsOtherPublicAgenda,
};
if (Gbl.Usrs.Me.Logged)
{
if (Gbl.Usrs.Me.UsrDat.Prefs.Language == Txt_Current_CGI_SWAD_Language)
{
/***** Get user *****/
/* If nickname is correct, user code is already got from nickname */
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat, // Existing user
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CRS))
{
/***** Reset agenda context *****/
Agd_ResetAgenda (&Agenda);
/***** Begin box *****/
MeOrOther = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod);
if (asprintf (&Title,Txt_Public_agenda_USER,Usr_UsrDat[MeOrOther]->FullName) < 0)
Err_NotEnoughMemoryExit ();
Box_BoxBegin (Title,
FuncPutIcons[MeOrOther],Usr_UsrDat[MeOrOther]->EnUsrCod,
Hlp_PROFILE_Agenda_public_agenda,Box_NOT_CLOSABLE);
free (Title);
/***** Show the current events in the user's agenda *****/
Agd_ShowEventsToday (&Agenda,Agd_ANOTHER_AGENDA_TODAY);
/***** Show all visible events in the user's agenda *****/
Agd_ShowEvents (&Agenda,Agd_ANOTHER_AGENDA);
/***** End box *****/
Box_BoxEnd ();
}
else
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
}
else
/* The current language is not my preferred language
==> change automatically to my language */
Ale_ShowAlert (Ale_INFO,Txt_Switching_to_LANGUAGE[Gbl.Usrs.Me.UsrDat.Prefs.Language]);
}
}
/*****************************************************************************/
/*************************** Show events in agenda ***************************/
/*****************************************************************************/
static void Agd_ShowEvents (struct Agd_Agenda *Agenda,
Agd_AgendaType_t AgendaType)
{
extern const char *Hlp_PROFILE_Agenda;
extern const char *Txt_Public_agenda_USER;
extern const char *Txt_My_agenda;
extern const char *Txt_No_events;
struct Pag_Pagination Pagination;
unsigned NumEvent;
static Pag_WhatPaginate_t WhatPaginate[Agd_NUM_AGENDA_TYPES] =
{
[Agd_MY_AGENDA_TODAY ] = Pag_MY_AGENDA, // not used
[Agd_MY_AGENDA ] = Pag_MY_AGENDA,
[Agd_ANOTHER_AGENDA_TODAY] = Pag_ANOTHER_AGENDA, // not used
[Agd_ANOTHER_AGENDA ] = Pag_ANOTHER_AGENDA,
};
/***** Get parameters *****/
Agd_GetPars (Agenda,AgendaType);
/***** Get list of events *****/
Agd_GetListEvents (Agenda,AgendaType);
/***** Compute variables related to pagination *****/
Pagination.NumItems = Agenda->Num;
Pagination.CurrentPage = (int) Agenda->CurrentPage;
Pag_CalculatePagination (&Pagination);
Agenda->CurrentPage = (unsigned) Pagination.CurrentPage;
/***** Write links to pages *****/
Pag_WriteLinksToPagesCentered (WhatPaginate[AgendaType],&Pagination,
Agenda,-1L);
if (Agenda->Num)
{
/***** Begin table *****/
HTM_TABLE_Begin ("TBL_SCROLL");
/***** Table head *****/
Agd_WriteHeaderListEvents (Agenda,AgendaType);
/***** Write all events *****/
for (NumEvent = Pagination.FirstItemVisible, The_ResetRowColor ();
NumEvent <= Pagination.LastItemVisible;
NumEvent++, The_ChangeRowColor ())
Agd_ShowOneEvent (Agenda,AgendaType,Agenda->LstAgdCods[NumEvent - 1]);
/***** End table *****/
HTM_TABLE_End ();
}
else
Ale_ShowAlert (Ale_INFO,Txt_No_events);
/***** Write again links to pages *****/
Pag_WriteLinksToPagesCentered (WhatPaginate[AgendaType],&Pagination,
Agenda,-1L);
/***** Free list of events *****/
Agd_FreeListEvents (Agenda);
}
/*****************************************************************************/
/************************ Show today events in agenda ************************/
/*****************************************************************************/
static void Agd_ShowEventsToday (struct Agd_Agenda *Agenda,
Agd_AgendaType_t AgendaType)
{
extern const char *Hlp_PROFILE_Agenda;
extern const char *Hlp_PROFILE_Agenda_public_agenda;
extern const char *Txt_Today;
extern const char *Txt_Public_agenda_USER;
extern const char *Txt_My_agenda;
extern const char *Txt_No_events;
unsigned NumEvent;
/***** Get parameters *****/
Agd_GetPars (Agenda,AgendaType);
/***** Get list of events *****/
Agd_GetListEvents (Agenda,AgendaType);
if (Agenda->Num)
{
/***** Begin box and table *****/
switch (AgendaType)
{
case Agd_MY_AGENDA_TODAY:
Box_BoxTableShadowBegin (Txt_Today,NULL,NULL,
Hlp_PROFILE_Agenda,2);
break;
case Agd_ANOTHER_AGENDA_TODAY:
Box_BoxTableShadowBegin (Txt_Today,NULL,NULL,
Hlp_PROFILE_Agenda_public_agenda,2);
break;
default:
break;
}
/***** Table head *****/
Agd_WriteHeaderListEvents (Agenda,AgendaType);
/***** Write all events *****/
for (NumEvent = 0, The_ResetRowColor ();
NumEvent < Agenda->Num;
NumEvent++, The_ChangeRowColor ())
Agd_ShowOneEvent (Agenda,AgendaType,Agenda->LstAgdCods[NumEvent]);
/***** End table and box *****/
Box_BoxTableEnd ();
}
/***** Free list of events *****/
Agd_FreeListEvents (Agenda);
}
/*****************************************************************************/
/*************** Put contextual icon to view/edit my agenda ******************/
/*****************************************************************************/
static void Agd_WriteHeaderListEvents (const struct Agd_Agenda *Agenda,
Agd_AgendaType_t AgendaType)
{
extern const char *Txt_START_END_TIME_HELP[Dat_NUM_START_END_TIME];
extern const char *Txt_START_END_TIME[Dat_NUM_START_END_TIME];
extern const char *Txt_Event;
extern const char *Txt_Location;
Dat_StartEndTime_t Order;
/***** Table head *****/
HTM_TR_Begin (NULL);
for (Order = (Dat_StartEndTime_t) 0;
Order <= (Dat_StartEndTime_t) (Dat_NUM_START_END_TIME - 1);
Order++)
{
HTM_TH_Begin (HTM_HEAD_LEFT);
switch (AgendaType)
{
case Agd_MY_AGENDA_TODAY:
case Agd_MY_AGENDA:
Frm_BeginForm (ActSeeMyAgd);
Pag_PutParPagNum (Pag_MY_AGENDA,Agenda->CurrentPage);
break;
case Agd_ANOTHER_AGENDA_TODAY:
case Agd_ANOTHER_AGENDA:
Frm_BeginForm (ActSeeUsrAgd);
Usr_PutParOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
Pag_PutParPagNum (Pag_ANOTHER_AGENDA,Agenda->CurrentPage);
break;
}
Agd_PutParsMyAgenda (Agenda->Past__FutureEvents,
Agenda->PrivatPublicEvents,
Agenda->HiddenVisiblEvents,
Order,
Agenda->CurrentPage,
-1L);
HTM_BUTTON_Submit_Begin (Txt_START_END_TIME_HELP[Order],
"class=\"BT_LINK\"");
if (Order == Agenda->SelectedOrder)
HTM_U_Begin ();
HTM_Txt (Txt_START_END_TIME[Order]);
if (Order == Agenda->SelectedOrder)
HTM_U_End ();
HTM_BUTTON_End ();
Frm_EndForm ();
HTM_TH_End ();
}
HTM_TH (Txt_Event ,HTM_HEAD_LEFT);
HTM_TH (Txt_Location,HTM_HEAD_LEFT);
HTM_TR_End ();
}
/*****************************************************************************/
/********************** Put contextual icons in agenda ***********************/
/*****************************************************************************/
static void Agd_PutIconsMyFullAgenda (void *Agenda)
{
/***** Put icon to create a new event *****/
Agd_PutIconToCreateNewEvent (Agenda);
/***** Put icon to show QR code *****/
Agd_PutIconToShowQR ();
}
static void Agd_PutIconsMyPublicAgenda (void *EncryptedUsrCod)
{
/***** Put icon to view/edit my full agenda *****/
Agd_PutIconToViewEditMyFullAgenda (EncryptedUsrCod);
/***** Put icon to show QR code *****/
Agd_PutIconToShowQR ();
}
static void Agd_PutIconToCreateNewEvent (void *Agenda)
{
((struct Agd_Agenda *) Agenda)->AgdCodToEdit = -1L;
Ico_PutContextualIconToAdd (ActFrmNewEvtMyAgd,NULL,
Agd_PutCurrentParsMyAgenda,Agenda);
}
static void Agd_PutIconToViewEditMyFullAgenda (void *EncryptedUsrCod)
{
Ico_PutContextualIconToEdit (ActSeeMyAgd,NULL,NULL,EncryptedUsrCod);
}
static void Agd_PutIconToShowQR (void)
{
char URL[WWW_MAX_BYTES_WWW + 1];
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
snprintf (URL,sizeof (URL),"%s/%s?agd=@%s",
Cfg_URL_SWAD_CGI,Lan_STR_LANG_ID[Gbl.Prefs.Language],
Gbl.Usrs.Me.UsrDat.Nickname);
QR_PutLinkToPrintQRCode (ActPrnAgdQR,
QR_PutParQRString,URL);
}
static void Agd_PutIconsOtherPublicAgenda (void *EncryptedUsrCod)
{
/***** Button to view user's public profile *****/
if (Pri_CheckIfICanView (Gbl.Usrs.Other.UsrDat.BaPrfVisibility,
&Gbl.Usrs.Other.UsrDat) == Usr_CAN)
Lay_PutContextualLinkOnlyIcon (ActSeeOthPubPrf,NULL,
Usr_PutParOtherUsrCodEncrypted,EncryptedUsrCod,
"user.svg",Ico_BLACK);
/***** Button to view user's record card *****/
if (Usr_CheckIfICanViewRecordStd (&Gbl.Usrs.Other.UsrDat) == Usr_CAN)
/* View student's records: common record card and course record card */
Lay_PutContextualLinkOnlyIcon (ActSeeRecOneStd,NULL,
Usr_PutParOtherUsrCodEncrypted,EncryptedUsrCod,
"address-card.svg",Ico_BLACK);
else if (Usr_CheckIfICanViewRecordTch (&Gbl.Usrs.Other.UsrDat) == Usr_CAN)
Lay_PutContextualLinkOnlyIcon (ActSeeRecOneTch,NULL,
Usr_PutParOtherUsrCodEncrypted,EncryptedUsrCod,
"address-card.svg",Ico_BLACK);
}
/*****************************************************************************/
/******************************* Show one event ******************************/
/*****************************************************************************/
static void Agd_ShowOneEvent (struct Agd_Agenda *Agenda,
Agd_AgendaType_t AgendaType,long AgdCod)
{
extern const char *Dat_TimeStatusClass[Dat_NUM_TIME_STATUS][HidVis_NUM_HIDDEN_VISIBLE];
extern const char *HidVis_TitleClass[HidVis_NUM_HIDDEN_VISIBLE];
extern const char *HidVis_DataClass[HidVis_NUM_HIDDEN_VISIBLE];
char *Anchor = NULL;
static unsigned UniqueId = 0;
char *Id;
struct Agd_Event AgdEvent;
Dat_StartEndTime_t StartEndTime;
char Txt[Cns_MAX_BYTES_TEXT + 1];
/***** Get data of this event *****/
AgdEvent.AgdCod = AgdCod;
switch (AgendaType)
{
case Agd_MY_AGENDA_TODAY:
case Agd_MY_AGENDA:
AgdEvent.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
break;
case Agd_ANOTHER_AGENDA_TODAY:
case Agd_ANOTHER_AGENDA:
AgdEvent.UsrCod = Gbl.Usrs.Other.UsrDat.UsrCod;
break;
}
Agd_GetventDataByCod (&AgdEvent);
/***** Set anchor string *****/
Frm_SetAnchorStr (AgdEvent.AgdCod,&Anchor);
/***** Write first row of data of this event *****/
HTM_TR_Begin (NULL);
/* Start/end date/time */
UniqueId++;
for (StartEndTime = (Dat_StartEndTime_t) 0;
StartEndTime <= (Dat_StartEndTime_t) (Dat_NUM_START_END_TIME - 1);
StartEndTime++)
{
if (asprintf (&Id,"agd_date_%u_%u",(unsigned) StartEndTime,UniqueId) < 0)
Err_NotEnoughMemoryExit ();
HTM_TD_Begin ("id=\"%s\" class=\"LT %s_%s %s\"",
Id,
Dat_TimeStatusClass[AgdEvent.TimeStatus][AgdEvent.HiddenOrVisible],
The_GetSuffix (),
The_GetColorRows ());
Dat_WriteLocalDateHMSFromUTC (Id,AgdEvent.TimeUTC[StartEndTime],
Gbl.Prefs.DateFormat,Dat_SEPARATOR_BREAK,
Dat_WRITE_TODAY |
Dat_WRITE_DATE_ON_SAME_DAY |
Dat_WRITE_WEEK_DAY |
Dat_WRITE_HOUR |
Dat_WRITE_MINUTE);
HTM_TD_End ();
free (Id);
}
/* Event */
HTM_TD_Begin ("class=\"LT %s\"",The_GetColorRows ());
HTM_ARTICLE_Begin (Anchor);
HTM_SPAN_Begin ("class=\"%s_%s\"",
HidVis_TitleClass[AgdEvent.HiddenOrVisible],
The_GetSuffix ());
HTM_Txt (AgdEvent.Title);
HTM_SPAN_End ();
HTM_ARTICLE_End ();
HTM_TD_End ();
/* Location */
HTM_TD_Begin ("class=\"LT %s\"",The_GetColorRows ());
HTM_SPAN_Begin ("class=\"%s_%s\"",
HidVis_TitleClass[AgdEvent.HiddenOrVisible],
The_GetSuffix ());
HTM_Txt (AgdEvent.Location);
HTM_SPAN_End ();
HTM_TD_End ();
HTM_TR_End ();
/***** Write second row of data of this event *****/
HTM_TR_Begin (NULL);
HTM_TD_Begin ("colspan=\"2\" class=\"LT %s\"",The_GetColorRows ());
switch (AgendaType)
{
case Agd_MY_AGENDA_TODAY:
case Agd_MY_AGENDA:
/* Forms to remove/edit this event */
Agd_PutFormsToRemEditOneEvent (Agenda,&AgdEvent,Anchor);
break;
default:
break;
}
HTM_TD_End ();
/* Text of the event */
HTM_TD_Begin ("colspan=\"2\" class=\"LT %s\"",The_GetColorRows ());
HTM_DIV_Begin ("class=\"PAR %s_%s\"",
HidVis_DataClass[AgdEvent.HiddenOrVisible],
The_GetSuffix ());
Agd_DB_GetEventTxt (&AgdEvent,Txt);
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
Txt,Cns_MAX_BYTES_TEXT,Str_DONT_REMOVE_SPACES);
ALn_InsertLinks (Txt,Cns_MAX_BYTES_TEXT,60); // Insert links
HTM_Txt (Txt);
HTM_DIV_End ();
HTM_TD_End ();
HTM_TR_End ();
/***** Free anchor string *****/
Frm_FreeAnchorStr (&Anchor);
}
/*****************************************************************************/
/******************* Put a link (form) to edit one event *********************/
/*****************************************************************************/
static void Agd_PutFormsToRemEditOneEvent (struct Agd_Agenda *Agenda,
struct Agd_Event *AgdEvent,
const char *Anchor)
{
static Act_Action_t ActionHideUnhide[HidVis_NUM_HIDDEN_VISIBLE] =
{
[HidVis_HIDDEN ] = ActUnhEvtMyAgd, // Hidden ==> action to unhide
[HidVis_VISIBLE] = ActHidEvtMyAgd, // Visible ==> action to hide
};
Agenda->AgdCodToEdit = AgdEvent->AgdCod; // Used as parameter in contextual links
/***** Icon to remove event *****/
Ico_PutContextualIconToRemove (ActReqRemEvtMyAgd,NULL,
Agd_PutCurrentParsMyAgenda,Agenda);
/***** Icon to hide/unhide event *****/
Ico_PutContextualIconToHideUnhide (ActionHideUnhide,Anchor,
Agd_PutCurrentParsMyAgenda,Agenda,
AgdEvent->HiddenOrVisible);
/***** Icon to edit event *****/
Ico_PutContextualIconToEdit (ActEdiOneEvtMyAgd,NULL,
Agd_PutCurrentParsMyAgenda,Agenda);
/***** Icon to make event public/private *****/
if (AgdEvent->Public)
Lay_PutContextualLinkOnlyIcon (ActPrvEvtMyAgd,NULL,
Agd_PutCurrentParsMyAgenda,Agenda,
"unlock.svg",Ico_GREEN);
else
Lay_PutContextualLinkOnlyIcon (ActPubEvtMyAgd,NULL,
Agd_PutCurrentParsMyAgenda,Agenda,
"lock.svg",Ico_RED);
}
/*****************************************************************************/
/****************** Parameters passed in my agenda forms *********************/
/*****************************************************************************/
static void Agd_PutCurrentParsMyAgenda (void *Agenda)
{
if (Agenda)
Agd_PutParsMyAgenda (((struct Agd_Agenda *) Agenda)->Past__FutureEvents,
((struct Agd_Agenda *) Agenda)->PrivatPublicEvents,
((struct Agd_Agenda *) Agenda)->HiddenVisiblEvents,
((struct Agd_Agenda *) Agenda)->SelectedOrder,
((struct Agd_Agenda *) Agenda)->CurrentPage,
((struct Agd_Agenda *) Agenda)->AgdCodToEdit);
}
/* The following function is called
when one or more parameters must be passed explicitely.
Each parameter is passed only if its value is distinct to default. */
void Agd_PutParsMyAgenda (unsigned Past__FutureEvents,
unsigned PrivatPublicEvents,
unsigned HiddenVisiblEvents,
Dat_StartEndTime_t Order,
unsigned NumPage,
long AgdCodToEdit)
{
if (Past__FutureEvents != (Agd_DEFAULT_PAST___EVENTS |
Agd_DEFAULT_FUTURE_EVENTS))
Agd_PutParPast__FutureEvents (Past__FutureEvents);
if (PrivatPublicEvents != (Agd_DEFAULT_PRIVAT_EVENTS |
Agd_DEFAULT_PUBLIC_EVENTS))
Agd_PutParPrivatPublicEvents (PrivatPublicEvents);
if (HiddenVisiblEvents != (Agd_DEFAULT_HIDDEN_EVENTS |
Agd_DEFAULT_VISIBL_EVENTS))
Agd_PutParHiddenVisiblEvents (HiddenVisiblEvents);
if (Order != Agd_ORDER_DEFAULT)
Par_PutParOrder ((unsigned) Order);
if (NumPage > 1)
Pag_PutParPagNum (Pag_MY_AGENDA,NumPage);
ParCod_PutPar (ParCod_Agd,AgdCodToEdit);
}
/*****************************************************************************/
/********** Get parameter with the type or order in list of events ***********/
/*****************************************************************************/
static void Agd_GetPars (struct Agd_Agenda *Agenda,
Agd_AgendaType_t AgendaType)
{
static Pag_WhatPaginate_t WhatPaginate[Agd_NUM_AGENDA_TYPES] =
{
[Agd_MY_AGENDA_TODAY ] = Pag_MY_AGENDA, // not used
[Agd_MY_AGENDA ] = Pag_MY_AGENDA,
[Agd_ANOTHER_AGENDA_TODAY] = Pag_ANOTHER_AGENDA, // not used
[Agd_ANOTHER_AGENDA ] = Pag_ANOTHER_AGENDA,
};
if (AgendaType == Agd_MY_AGENDA)
{
Agenda->Past__FutureEvents = Agd_GetParsPast__FutureEvents ();
Agenda->PrivatPublicEvents = Agd_GetParsPrivatPublicEvents ();
Agenda->HiddenVisiblEvents = Agd_GetParsHiddenVisiblEvents ();
}
Agd_GetParEventOrder (Agenda);
Agenda->CurrentPage = Pag_GetParPagNum (WhatPaginate[AgendaType]);
}
/*****************************************************************************/
/****** Put a hidden parameter with the type of order in list of events ******/
/*****************************************************************************/
void Agd_PutParEventsOrder (Dat_StartEndTime_t SelectedOrder)
{
if (SelectedOrder != Agd_ORDER_DEFAULT)
Par_PutParOrder ((unsigned) SelectedOrder);
}
/*****************************************************************************/
/********** Get parameter with the type or order in list of events ***********/
/*****************************************************************************/
static void Agd_GetParEventOrder (struct Agd_Agenda *Agenda)
{
static bool AlreadyGot = false;