swad-core/swad_global.c

326 lines
11 KiB
C
Raw Normal View History

2014-12-01 23:55:08 +01:00
// swad_global.c: global variables
/*
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-2023 Antonio Ca<EFBFBD>as Vargas
2014-12-01 23:55:08 +01:00
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 ***********************************/
/*****************************************************************************/
2016-06-04 14:21:01 +02:00
#include <locale.h> // For setlocale
2019-12-29 12:39:00 +01:00
#include <stddef.h> // For NULL
2019-11-11 11:20:31 +01:00
#include <stdlib.h> // For exit
2014-12-01 23:55:08 +01:00
#include <string.h> // For string functions
#include <sys/time.h> // For gettimeofday
#include <sys/types.h> // For getpid
#include <unistd.h> // For getpid
#include "swad_action.h"
#include "swad_action_list.h"
2019-05-16 14:02:06 +02:00
#include "swad_API.h"
2015-11-21 20:23:28 +01:00
#include "swad_calendar.h"
#include "swad_call_for_exam.h"
2014-12-01 23:55:08 +01:00
#include "swad_config.h"
#include "swad_constant.h"
#include "swad_degree_type.h"
2020-04-14 17:15:17 +02:00
#include "swad_department.h"
2019-02-22 14:04:54 +01:00
#include "swad_follow.h"
2014-12-01 23:55:08 +01:00
#include "swad_global.h"
2021-02-11 22:57:09 +01:00
#include "swad_hierarchy.h"
#include "swad_hierarchy_level.h"
2014-12-01 23:55:08 +01:00
#include "swad_icon.h"
2020-04-14 17:15:17 +02:00
#include "swad_link.h"
2016-03-30 10:50:31 +02:00
#include "swad_parameter.h"
#include "swad_plugin.h"
#include "swad_process.h"
2020-02-20 23:48:48 +01:00
#include "swad_program.h"
2017-09-17 16:58:09 +02:00
#include "swad_project.h"
2017-06-20 14:43:26 +02:00
#include "swad_role.h"
#include "swad_room.h"
#include "swad_session_database.h"
2019-03-26 11:53:21 +01:00
#include "swad_setting.h"
2020-04-14 17:15:17 +02:00
#include "swad_statistic.h"
2014-12-01 23:55:08 +01:00
#include "swad_theme.h"
/*****************************************************************************/
/****************************** Public variables *****************************/
/*****************************************************************************/
struct Globals Gbl; // All the global parameters and variables must be in this structure
/*****************************************************************************/
/************* Intialize globals variables when starting program *************/
/*****************************************************************************/
void Gbl_InitializeGlobals (void)
{
2018-12-09 10:46:57 +01:00
extern const unsigned Txt_Current_CGI_SWAD_Language;
2016-06-23 13:51:37 +02:00
Rol_Role_t Role;
2014-12-01 23:55:08 +01:00
2016-06-04 14:21:01 +02:00
Gbl.Layout.WritingHTMLStart =
Gbl.Layout.HTMLStartWritten =
Gbl.Layout.DivsEndWritten =
Gbl.Layout.HTMLEndWritten = false;
if (!setlocale (LC_ALL,"es_ES.utf8")) // TODO: this should be internationalized!!!!!!!
2016-06-04 13:25:14 +02:00
exit (1);
2014-12-01 23:55:08 +01:00
Dat_SetStartExecutionTimeval ();
Dat_SetStartExecutionTimeUTC ();
2014-12-01 23:55:08 +01:00
Dat_GetAndConvertCurrentDateTime ();
Prc_SetPID ();
Par_SetIP ();
2019-02-11 21:35:36 +01:00
Cry_CreateUniqueNameEncrypted (Cry_GetUniqueNameEncrypted ());
2014-12-01 23:55:08 +01:00
srand ((unsigned int) Dat_GetStartExecutionTimeUTC ()); // Initialize seed for rand()
2014-12-01 23:55:08 +01:00
Gbl.WebService.IsWebService = false;
Fil_SetOutputFileToStdout ();
2014-12-01 23:55:08 +01:00
2018-12-09 10:46:57 +01:00
Gbl.Prefs.Language = Txt_Current_CGI_SWAD_Language;
2015-11-21 20:23:28 +01:00
Gbl.Prefs.FirstDayOfWeek = Cal_FIRST_DAY_OF_WEEK_DEFAULT; // Default first day of week
2017-05-04 11:03:44 +02:00
Gbl.Prefs.DateFormat = Dat_FORMAT_DEFAULT; // Default date format
Gbl.Prefs.Menu = Mnu_MENU_DEFAULT; // Default menu
Gbl.Prefs.Theme = The_THEME_DEFAULT; // Default theme
Gbl.Prefs.IconSet = Ico_ICON_SET_DEFAULT; // Default icon set
2014-12-01 23:55:08 +01:00
Gbl.Session.NumSessions = 0;
Gbl.Session.IsOpen = false;
Gbl.Session.HasBeenDisconnected = false;
2018-11-09 20:47:39 +01:00
Gbl.Session.Id[0] = '\0';
Gbl.Session.ParsInsertedIntoDB = false;
2014-12-01 23:55:08 +01:00
Gbl.Usrs.Me.UsrIdLogin[0] = '\0';
Gbl.Usrs.Me.LoginPlainPassword[0] = '\0';
Gbl.Usrs.Me.UsrDat.UsrCod = -1L;
Gbl.Usrs.Me.UsrDat.UsrIDNickOrEmail[0] = '\0';
Usr_UsrDataConstructor (&Gbl.Usrs.Me.UsrDat);
Usr_ResetMyLastData ();
Gbl.Usrs.Me.Logged = false;
2017-06-04 18:18:54 +02:00
Gbl.Usrs.Me.Role.Available = 0;
Gbl.Usrs.Me.Role.FromSession =
Gbl.Usrs.Me.Role.Logged =
Gbl.Usrs.Me.Role.LoggedBeforeCloseSession =
Gbl.Usrs.Me.Role.Max = Rol_UNK;
Gbl.Usrs.Me.Role.HasChanged = false;
2015-01-20 20:03:38 +01:00
Gbl.Usrs.Me.IBelongToCurrentIns = false;
Gbl.Usrs.Me.IBelongToCurrentCtr = false;
Gbl.Usrs.Me.IBelongToCurrentDeg = false;
2014-12-01 23:55:08 +01:00
Gbl.Usrs.Me.IBelongToCurrentCrs = false;
Gbl.Usrs.Me.MyPhotoExists = false;
Gbl.Usrs.Me.NumAccWithoutPhoto = 0;
Gbl.Usrs.Me.TimeLastAccToThisFileBrowser = LONG_MAX; // Initialized to a big value, so by default files are not shown as recent or new
2016-10-28 10:03:37 +02:00
Gbl.Usrs.Me.MyInss.Filled = false;
Gbl.Usrs.Me.MyCtrs.Filled = false;
Gbl.Usrs.Me.MyDegs.Filled = false;
Gbl.Usrs.Me.MyCrss.Filled = false;
Gbl.Usrs.Me.MyCrss.Num = 0;
2016-11-16 23:19:52 +01:00
Gbl.Usrs.Me.ConfirmEmailJustSent = false; // An email to confirm my email address has not just been sent
2014-12-01 23:55:08 +01:00
Gbl.Usrs.Other.UsrDat.UsrCod = -1L;
Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail[0] = '\0';
Usr_UsrDataConstructor (&Gbl.Usrs.Other.UsrDat);
2017-05-09 20:56:02 +02:00
Gbl.Action.Act = ActUnk;
Gbl.Action.Original = ActUnk; // Used in some actions to know what action gave rise to the current action
2016-01-17 15:10:54 +01:00
Gbl.Action.UsesAJAX = false;
2017-02-05 22:23:41 +01:00
Gbl.Action.IsAJAXAutoRefresh = false;
2016-01-17 15:10:54 +01:00
Gbl.Action.Tab = TabUnk;
2014-12-01 23:55:08 +01:00
2019-03-11 13:33:34 +01:00
Gbl.Usrs.Selected.Filled = false; // Lists of encrypted codes of users selected from form are not filled
Gbl.Usrs.Selected.ParSuffix = NULL; // Don't add suffix to param names
2019-03-12 09:27:04 +01:00
Gbl.Usrs.Selected.Option = Usr_OPTION_UNKNOWN;
2019-12-15 20:02:34 +01:00
for (Role = (Rol_Role_t) 0;
Role <= (Rol_Role_t) (Rol_NUM_ROLES - 1);
2016-06-23 13:51:37 +02:00
Role++)
{
Gbl.Usrs.LstUsrs[Role].Lst = NULL;
Gbl.Usrs.LstUsrs[Role].NumUsrs = 0;
2019-03-11 13:33:34 +01:00
Gbl.Usrs.Selected.List[Role] = NULL;
2016-06-23 13:51:37 +02:00
}
2017-05-23 18:15:59 +02:00
Gbl.Usrs.ListOtherRecipients = NULL;
2014-12-01 23:55:08 +01:00
2019-04-03 20:57:04 +02:00
/***** Reset current hierarchy *****/
Hie_ResetHierarchy ();
2014-12-01 23:55:08 +01:00
2020-01-08 14:04:25 +01:00
Gbl.Hierarchy.Ctys.Num = 0;
Gbl.Hierarchy.Ctys.Lst = NULL;
Gbl.Hierarchy.Ctys.SelectedOrder = Cty_ORDER_DEFAULT;
2020-01-07 00:09:30 +01:00
2020-01-08 14:04:25 +01:00
Gbl.Hierarchy.Inss.Num = 0;
Gbl.Hierarchy.Inss.Lst = NULL;
Gbl.Hierarchy.Inss.SelectedOrder = Ins_ORDER_DEFAULT;
2020-01-07 00:09:30 +01:00
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.ShrtName[0] = '\0';
Gbl.Hierarchy.Ins.FullName[0] = '\0';
Gbl.Hierarchy.Ins.WWW[0] = '\0';
2020-01-08 14:04:25 +01:00
Gbl.Hierarchy.Ctrs.Num = 0;
Gbl.Hierarchy.Ctrs.Lst = NULL;
Gbl.Hierarchy.Ctrs.SelectedOrder = Ctr_ORDER_DEFAULT;
2014-12-01 23:55:08 +01:00
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ctr.ShrtName[0] = '\0';
Gbl.Hierarchy.Ctr.FullName[0] = '\0';
2014-12-01 23:55:08 +01:00
2020-01-08 14:04:25 +01:00
Gbl.Hierarchy.Degs.Num = 0;
Gbl.Hierarchy.Degs.Lst = NULL;
Gbl.Hierarchy.Deg.ShrtName[0] =
Gbl.Hierarchy.Deg.FullName[0] = '\0';
2014-12-01 23:55:08 +01:00
2020-01-08 14:04:25 +01:00
Gbl.Hierarchy.Crs.ShrtName[0] =
Gbl.Hierarchy.Crs.FullName[0] = '\0';
2014-12-01 23:55:08 +01:00
2020-01-07 00:09:30 +01:00
Gbl.Crs.Info.ShowMsgMustBeRead = 0;
2020-04-12 02:47:32 +02:00
2020-01-07 00:09:30 +01:00
Gbl.Crs.Notices.HighlightNotCod = -1L; // No notice highlighted
2020-04-12 02:47:32 +02:00
2019-04-04 10:45:15 +02:00
Gbl.Crs.Grps.NumGrps = 0;
Gbl.Crs.Grps.WhichGrps = Grp_WHICH_GROUPS_DEFAULT;
Gbl.Crs.Grps.GrpTypes.LstGrpTypes = NULL;
Gbl.Crs.Grps.GrpTypes.NumGrpTypes = 0;
2019-04-04 10:45:15 +02:00
Gbl.Crs.Grps.GrpTypes.NestedCalls = 0;
Gbl.Crs.Grps.GrpTyp.GrpTypName[0] = '\0';
Gbl.Crs.Grps.GrpTyp.MandatoryEnrolment = true;
Gbl.Crs.Grps.GrpTyp.MultipleEnrolment = false;
Gbl.Crs.Grps.GrpTyp.MustBeOpened = false;
Gbl.Crs.Grps.GrpTyp.OpenTimeUTC = (time_t) 0;
Gbl.Crs.Grps.GrpCod = -1L; // -1L stands for the whole course
Gbl.Crs.Grps.GrpName[0] = '\0';
2020-04-14 17:15:17 +02:00
Gbl.Crs.Grps.RooCod = -1L; // -1L stands for no room assigned
2019-04-04 10:45:15 +02:00
Gbl.Crs.Grps.MaxStudents = Grp_NUM_STUDENTS_NOT_LIMITED;
Gbl.Crs.Grps.Open = false;
Gbl.Crs.Grps.LstGrpsSel.GrpCods = NULL;
Gbl.Crs.Grps.LstGrpsSel.NumGrps = 0;
Gbl.Crs.Grps.LstGrpsSel.NestedCalls = 0;
2020-04-12 02:47:32 +02:00
2019-04-04 10:45:15 +02:00
Gbl.Crs.Records.Field.Name[0] = '\0';
Gbl.Crs.Records.Field.NumLines = Rec_MIN_LINES_IN_EDITION_FIELD;
Gbl.Crs.Records.Field.Visibility = Rec_HIDDEN_FIELD;
Gbl.Crs.Records.LstFields.Lst = NULL;
Gbl.Crs.Records.LstFields.Num = 0;
Gbl.Crs.Records.LstFields.NestedCalls = 0;
2014-12-01 23:55:08 +01:00
Gbl.Usrs.Listing.RecsUsrs = Rec_RECORD_USERS_UNKNOWN;
2017-01-29 12:42:19 +01:00
Gbl.Usrs.Listing.RecsPerPag = Rec_DEF_RECORDS_PER_PAGE;
2017-05-30 11:43:50 +02:00
Gbl.Usrs.Listing.WithPhotos = Usr_LIST_WITH_PHOTOS_DEF;
2014-12-01 23:55:08 +01:00
2020-01-07 00:09:30 +01:00
Gbl.Usrs.ClassPhoto.AllGroups = true;
2014-12-01 23:55:08 +01:00
Gbl.Usrs.ClassPhoto.Cols = Usr_CLASS_PHOTO_COLS_DEF;
Gbl.Scope.Current = HieLvl_CRS;
2014-12-01 23:55:08 +01:00
Gbl.Usrs.Connected.TimeToRefreshInMs = Con_MAX_TIME_TO_REFRESH_CONNECTED_IN_MS;
2016-04-06 22:27:33 +02:00
/* User nickname */
2014-12-01 23:55:08 +01:00
Gbl.Usrs.Me.UsrDat.Nickname[0] = '\0';
/* File browser */
2015-10-03 00:38:01 +02:00
Gbl.FileBrowser.Id = 0;
2015-01-26 12:39:48 +01:00
Gbl.FileBrowser.Type = Brw_UNKNOWN;
2019-04-25 14:39:51 +02:00
Gbl.FileBrowser.FilFolLnk.Type = Brw_IS_UNKNOWN;
2014-12-01 23:55:08 +01:00
Gbl.FileBrowser.UploadingWithDropzone = false;
2019-05-16 14:02:06 +02:00
Gbl.WebService.Function = API_unknown;
2016-11-23 23:58:46 +01:00
2017-06-20 14:43:26 +02:00
/* Flush caches */
Cty_FlushCacheCountryName ();
Ins_FlushCacheFullNameAndCtyOfInstitution ();
2020-01-07 15:11:48 +01:00
2020-01-07 00:42:24 +01:00
Ins_FlushCacheNumInssInCty ();
2020-01-07 16:37:46 +01:00
Ctr_FlushCacheNumCtrsInCty ();
2020-01-07 16:08:13 +01:00
Deg_FlushCacheNumDegsInCty ();
2020-01-07 15:11:48 +01:00
Crs_FlushCacheNumCrssInCty ();
2020-01-06 18:27:43 +01:00
Dpt_FlushCacheNumDptsInIns ();
2020-01-07 00:09:30 +01:00
Ctr_FlushCacheNumCtrsInIns ();
Deg_FlushCacheNumDegsInIns ();
2020-01-06 18:43:48 +01:00
Crs_FlushCacheNumCrssInIns ();
2020-01-07 15:11:48 +01:00
Deg_FlushCacheNumDegsInCtr ();
2020-01-05 01:46:45 +01:00
Crs_FlushCacheNumCrssInCtr ();
2020-01-07 15:11:48 +01:00
2020-01-05 12:52:03 +01:00
Crs_FlushCacheNumCrssInDeg ();
2020-01-07 15:11:48 +01:00
Cty_FlushCacheNumUsrsWhoDontClaimToBelongToAnyCty ();
Cty_FlushCacheNumUsrsWhoClaimToBelongToAnotherCty ();
Cty_FlushCacheNumUsrsWhoClaimToBelongToCty ();
Ins_FlushCacheNumUsrsWhoClaimToBelongToIns ();
Ctr_FlushCacheNumUsrsWhoClaimToBelongToCtr ();
2017-06-20 14:43:26 +02:00
Usr_FlushCacheUsrIsSuperuser ();
Ins_FlushCacheUsrBelongsToIns ();
Ctr_FlushCacheUsrBelongsToCtr ();
Deg_FlushCacheUsrBelongsToDeg ();
Enr_FlushCacheUsrBelongsToCrs ();
Enr_FlushCacheUsrBelongsToCurrentCrs ();
Enr_FlushCacheUsrHasAcceptedInCurrentCrs ();
Enr_FlushCacheUsrSharesAnyOfMyCrs ();
Rol_FlushCacheMyRoleInCurrentCrs ();
2017-06-20 14:43:26 +02:00
Rol_FlushCacheRoleUsrInCrs ();
2019-04-11 15:24:05 +02:00
Prj_FlushCacheMyRolesInProject ();
2017-06-20 14:43:26 +02:00
Grp_FlushCacheIBelongToGrp ();
Grp_FlushCacheUsrSharesAnyOfMyGrpsInCurrentCrs ();
2019-02-22 14:04:54 +01:00
Fol_FlushCacheFollow ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************* Free memory, close files, remove lock file, etc. **************/
/*****************************************************************************/
void Gbl_Cleanup (void)
{
2017-05-22 11:49:16 +02:00
Rol_Role_t Role;
2016-04-23 23:39:07 +02:00
2016-01-17 15:10:54 +01:00
if (!Gbl.Action.UsesAJAX &&
2014-12-01 23:55:08 +01:00
!Gbl.WebService.IsWebService &&
2018-04-24 13:21:53 +02:00
Act_GetBrowserTab (Gbl.Action.Act) == Act_BRW_1ST_TAB)
Ses_DB_RemovePar ();
Enr_FreeMyCourses ();
Deg_FreeMyDegrees ();
Ctr_FreeMyCenters ();
Ins_FreeMyInstits ();
Cty_FreeMyCountrs ();
2014-12-01 23:55:08 +01:00
Usr_UsrDataDestructor (&Gbl.Usrs.Me.UsrDat);
Usr_UsrDataDestructor (&Gbl.Usrs.Other.UsrDat);
Rec_FreeListFields ();
Grp_FreeListGrpTypesAndGrps ();
Grp_FreeListCodSelectedGrps ();
2019-04-07 12:17:10 +02:00
Crs_FreeListCoursesInCurrentDegree ();
2020-01-08 14:04:25 +01:00
Deg_FreeListDegs (&Gbl.Hierarchy.Degs);
2014-12-01 23:55:08 +01:00
Ins_FreeListInstitutions ();
Ctr_FreeListCenters ();
2014-12-01 23:55:08 +01:00
Cty_FreeListCountries ();
2017-05-22 11:49:16 +02:00
2019-12-15 20:02:34 +01:00
for (Role = (Rol_Role_t) 0;
Role <= (Rol_Role_t) (Rol_NUM_ROLES - 1);
2017-05-22 11:49:16 +02:00
Role++)
Usr_FreeUsrsList (Role);
2014-12-01 23:55:08 +01:00
Usr_FreeListOtherRecipients ();
2019-11-15 03:34:48 +01:00
Usr_FreeListsSelectedEncryptedUsrsCods (&Gbl.Usrs.Selected);
2014-12-01 23:55:08 +01:00
Syl_FreeListItemsSyllabus ();
Par_FreePars ();
2019-03-09 20:12:44 +01:00
Ale_ResetAllAlerts ();
2014-12-01 23:55:08 +01:00
}