diff --git a/Makefile b/Makefile
index e07912dc..c0312172 100644
--- a/Makefile
+++ b/Makefile
@@ -26,10 +26,11 @@
# #
###############################################################################
-OBJS = swad_account.o swad_account_database.o swad_action.o swad_agenda.o \
- swad_agenda_database.o swad_alert.o swad_announcement.o \
- swad_announcement_database.o swad_API.o swad_assignment.o \
- swad_assignment_database.o swad_attendance.o swad_attendance_database.o \
+OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.o \
+ swad_admin_database.o swad_agenda.o swad_agenda_database.o swad_alert.o \
+ swad_announcement.o swad_announcement_database.o swad_API.o \
+ swad_assignment.o swad_assignment_database.o swad_attendance.o \
+ swad_attendance_database.o \
swad_banner.o swad_banner_database.o swad_box.o swad_building.o \
swad_building_database.o swad_button.o \
swad_calendar.o swad_call_for_exam.o swad_call_for_exam_database.o \
diff --git a/swad_account.c b/swad_account.c
index 14f6edc5..e2d6fa25 100644
--- a/swad_account.c
+++ b/swad_account.c
@@ -29,6 +29,7 @@
#include "swad_account.h"
#include "swad_account_database.h"
+#include "swad_admin_database.h"
#include "swad_agenda_database.h"
#include "swad_announcement_database.h"
#include "swad_attendance_database.h"
@@ -996,7 +997,7 @@ void Acc_CompletelyEliminateAccount (struct UsrData *UsrDat,
UsrDat->FullName);
/***** Remove user as administrator of any degree/center/institution *****/
- Enr_DB_RemUsrAsAdmin (UsrDat->UsrCod);
+ Adm_DB_RemUsrAsAdmin (UsrDat->UsrCod);
if (QuietOrVerbose == Cns_VERBOSE)
Ale_ShowAlert (Ale_SUCCESS,Txt_THE_USER_X_has_been_removed_as_administrator,
diff --git a/swad_action.c b/swad_action.c
index 064f9585..18535fc5 100644
--- a/swad_action.c
+++ b/swad_action.c
@@ -26,6 +26,7 @@
#include "swad_account.h"
#include "swad_action.h"
+#include "swad_admin.h"
#include "swad_agenda.h"
#include "swad_announcement.h"
#include "swad_attendance.h"
@@ -1449,14 +1450,14 @@ const struct Act_Actions Act_Actions[Act_NUM_ACTIONS] =
[ActRemMe_NET ] = {1641,-1,TabUnk,ActLstTch ,0x3D0, 0, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Enr_ReqRemMeFromCrs ,NULL},
[ActRemMe_Tch ] = {1461,-1,TabUnk,ActLstTch ,0x3E0, 0, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Enr_ReqRemMeFromCrs ,NULL},
- [ActNewAdmIns ] = {1337,-1,TabUnk,ActLstOth ,0x200,0x200,0x200,0x200,0x200,0x200,0x200,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Enr_AddAdmToIns ,NULL},
- [ActRemAdmIns ] = {1338,-1,TabUnk,ActLstOth ,0x300,0x300,0x300,0x300,0x300,0x300,0x300,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Enr_RemAdmIns ,NULL},
+ [ActNewAdmIns ] = {1337,-1,TabUnk,ActLstOth ,0x200,0x200,0x200,0x200,0x200,0x200,0x200,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Adm_AddAdmToIns ,NULL},
+ [ActRemAdmIns ] = {1338,-1,TabUnk,ActLstOth ,0x300,0x300,0x300,0x300,0x300,0x300,0x300,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Adm_RemAdmIns ,NULL},
- [ActNewAdmCtr ] = {1339,-1,TabUnk,ActLstOth ,0x300,0x300,0x300,0x300,0x300,0x300,0x300,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Enr_AddAdmToCtr ,NULL},
- [ActRemAdmCtr ] = {1340,-1,TabUnk,ActLstOth ,0x380,0x380,0x380,0x380,0x380,0x380,0x380,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Enr_RemAdmCtr ,NULL},
+ [ActNewAdmCtr ] = {1339,-1,TabUnk,ActLstOth ,0x300,0x300,0x300,0x300,0x300,0x300,0x300,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Adm_AddAdmToCtr ,NULL},
+ [ActRemAdmCtr ] = {1340,-1,TabUnk,ActLstOth ,0x380,0x380,0x380,0x380,0x380,0x380,0x380,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Adm_RemAdmCtr ,NULL},
- [ActNewAdmDeg ] = { 586,-1,TabUnk,ActLstOth ,0x380,0x380,0x380,0x380,0x380,0x380,0x380,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Enr_AddAdmToDeg ,NULL},
- [ActRemAdmDeg ] = { 584,-1,TabUnk,ActLstOth ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Enr_RemAdmDeg ,NULL},
+ [ActNewAdmDeg ] = { 586,-1,TabUnk,ActLstOth ,0x380,0x380,0x380,0x380,0x380,0x380,0x380,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Adm_AddAdmToDeg ,NULL},
+ [ActRemAdmDeg ] = { 584,-1,TabUnk,ActLstOth ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Adm_RemAdmDeg ,NULL},
[ActRcvFrmEnrSevStd ] = {1428,-1,TabUnk,ActLstStd ,0x3E0,0x3C0, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Enr_ReceiveFormAdminStds ,NULL},
[ActRcvFrmEnrSevNET ] = {1643,-1,TabUnk,ActLstTch ,0x3C0,0x3C0, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Enr_ReceiveFormAdminNonEditTchs,NULL},
diff --git a/swad_admin.c b/swad_admin.c
new file mode 100644
index 00000000..1a9589b0
--- /dev/null
+++ b/swad_admin.c
@@ -0,0 +1,475 @@
+// swad_admin.c: administrators
+
+/*
+ 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-2021 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 .
+*/
+/*****************************************************************************/
+/*********************************** Headers *********************************/
+/*****************************************************************************/
+
+// #define _GNU_SOURCE // For asprintf
+// #include // For asprintf
+// #include // For exit, system, malloc, free, rand, etc.
+// #include // For string functions
+
+// #include "swad_account.h"
+// #include "swad_account_database.h"
+#include "swad_admin.h"
+#include "swad_admin_database.h"
+// #include "swad_announcement.h"
+// #include "swad_attendance_database.h"
+// #include "swad_box.h"
+// #include "swad_database.h"
+// #include "swad_duplicate.h"
+// #include "swad_enrolment.h"
+// #include "swad_enrolment_database.h"
+// #include "swad_error.h"
+// #include "swad_exam_print.h"
+// #include "swad_form.h"
+#include "swad_global.h"
+// #include "swad_hierarchy.h"
+// #include "swad_HTML.h"
+// #include "swad_ID.h"
+// #include "swad_match.h"
+// #include "swad_message.h"
+// #include "swad_notification.h"
+// #include "swad_parameter.h"
+// #include "swad_photo.h"
+// #include "swad_role.h"
+// #include "swad_setting.h"
+// #include "swad_test_print.h"
+// #include "swad_user.h"
+
+/*****************************************************************************/
+/****************************** Public constants *****************************/
+/*****************************************************************************/
+
+const bool Adm_ICanAdminOtherUsrs[Rol_NUM_ROLES] =
+ {
+ /* Users who can not admin */
+ [Rol_UNK ] = false,
+ [Rol_GST ] = false,
+ [Rol_USR ] = false,
+ [Rol_STD ] = false,
+ [Rol_NET ] = false,
+ /* Users who can admin */
+ [Rol_TCH ] = true,
+ [Rol_DEG_ADM] = true,
+ [Rol_CTR_ADM] = true,
+ [Rol_INS_ADM] = true,
+ [Rol_SYS_ADM] = true,
+ };
+
+/*****************************************************************************/
+/***************************** Private constants *****************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/******************************* Private types *******************************/
+/*****************************************************************************/
+
+
+/*****************************************************************************/
+/************** External global variables from others modules ****************/
+/*****************************************************************************/
+
+extern struct Globals Gbl;
+
+/*****************************************************************************/
+/************************** Private global variables *************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/***************************** Private prototypes ****************************/
+/*****************************************************************************/
+
+static void Adm_ReqAddAdm (HieLvl_Level_t Scope,long Cod,
+ const char *InsCtrDegName);
+static void Enr_AddAdm (HieLvl_Level_t Scope,long Cod,
+ const char *InsCtrDegName);
+static void Adm_RegisterAdmin (struct UsrData *UsrDat,
+ HieLvl_Level_t Scope,long Cod,
+ const char *InsCtrDegName);
+
+static void Adm_ReqRemOrRemAdm (Enr_ReqDelOrDelUsr_t ReqDelOrDelUsr,
+ HieLvl_Level_t Scope,long Cod,
+ const char *InsCtrDegName);
+static void Adm_AskIfRemAdm (bool ItsMe,HieLvl_Level_t Scope,
+ const char *InsCtrDegName);
+static void Adm_EffectivelyRemAdm (struct UsrData *UsrDat,
+ HieLvl_Level_t Scope,long Cod,
+ const char *InsCtrDegName);
+
+/*****************************************************************************/
+/**** Ask if really wanted to add an administrator to current institution ****/
+/*****************************************************************************/
+
+void Adm_ReqAddAdmOfIns (void)
+ {
+ Adm_ReqAddAdm (HieLvl_INS,Gbl.Hierarchy.Ins.InsCod,Gbl.Hierarchy.Ins.FullName);
+ }
+
+/*****************************************************************************/
+/****** Ask if really wanted to add an administrator to current center *******/
+/*****************************************************************************/
+
+void Adm_ReqAddAdmOfCtr (void)
+ {
+ Adm_ReqAddAdm (HieLvl_CTR,Gbl.Hierarchy.Ctr.CtrCod,Gbl.Hierarchy.Ctr.FullName);
+ }
+
+/*****************************************************************************/
+/****** Ask if really wanted to add an administrator to current degree *******/
+/*****************************************************************************/
+
+void Adm_ReqAddAdmOfDeg (void)
+ {
+ Adm_ReqAddAdm (HieLvl_DEG,Gbl.Hierarchy.Deg.DegCod,Gbl.Hierarchy.Deg.FullName);
+ }
+
+/*****************************************************************************/
+/**** Ask if really wanted to add an administrator to current institution ****/
+/*****************************************************************************/
+
+static void Adm_ReqAddAdm (HieLvl_Level_t Scope,long Cod,
+ const char *InsCtrDegName)
+ {
+ extern const char *Txt_THE_USER_X_is_already_an_administrator_of_Y;
+ extern const char *Txt_Do_you_really_want_to_register_the_following_user_as_an_administrator_of_X;
+ extern const char *Txt_Register_user_IN_A_COURSE_OR_DEGREE;
+ static const Act_Action_t Enr_ActNewAdm[HieLvl_NUM_LEVELS] =
+ {
+ [HieLvl_UNK] = ActUnk,
+ [HieLvl_SYS] = ActUnk,
+ [HieLvl_CTY] = ActUnk,
+ [HieLvl_INS] = ActNewAdmIns,
+ [HieLvl_CTR] = ActNewAdmCtr,
+ [HieLvl_DEG] = ActNewAdmDeg,
+ [HieLvl_CRS] = ActUnk,
+ };
+ bool ICanRegister;
+
+ if (Cod > 0)
+ {
+ /***** Get user's identificator of the user to register as admin *****/
+ if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ())
+ {
+ /* Check if I am allowed to register user as administrator in institution/center/degree */
+ ICanRegister = ((Scope == HieLvl_DEG && Gbl.Usrs.Me.Role.Logged >= Rol_CTR_ADM) ||
+ (Scope == HieLvl_CTR && Gbl.Usrs.Me.Role.Logged >= Rol_INS_ADM) ||
+ (Scope == HieLvl_INS && Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM));
+ if (ICanRegister)
+ {
+ if (Usr_CheckIfUsrIsAdm (Gbl.Usrs.Other.UsrDat.UsrCod,Scope,Cod)) // User is already an administrator of current institution/center/degree
+ {
+ Ale_ShowAlert (Ale_INFO,Txt_THE_USER_X_is_already_an_administrator_of_Y,
+ Gbl.Usrs.Other.UsrDat.FullName,InsCtrDegName);
+ Rec_ShowSharedRecordUnmodifiable (&Gbl.Usrs.Other.UsrDat);
+ }
+ else
+ {
+ /***** Show question and button to register user as administrator *****/
+ /* Begin alert */
+ Ale_ShowAlertAndButton1 (Ale_QUESTION,Txt_Do_you_really_want_to_register_the_following_user_as_an_administrator_of_X,
+ InsCtrDegName);
+
+ /* Show user's record */
+ Rec_ShowSharedRecordUnmodifiable (&Gbl.Usrs.Other.UsrDat);
+
+ /* End alert */
+ Ale_ShowAlertAndButton2 (Enr_ActNewAdm[Scope],NULL,NULL,
+ Usr_PutParamOtherUsrCodEncrypted,Gbl.Usrs.Other.UsrDat.EnUsrCod,
+ Btn_CREATE_BUTTON,Txt_Register_user_IN_A_COURSE_OR_DEGREE);
+ }
+ }
+ else
+ Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
+ }
+ else
+ Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
+ }
+ }
+
+/*****************************************************************************/
+/*************** Add an administrator to current institution *****************/
+/*****************************************************************************/
+
+void Adm_AddAdmToIns (void)
+ {
+ Enr_AddAdm (HieLvl_INS,Gbl.Hierarchy.Ins.InsCod,Gbl.Hierarchy.Ins.FullName);
+ }
+
+/*****************************************************************************/
+/******************* Add an administrator to current center ******************/
+/*****************************************************************************/
+
+void Adm_AddAdmToCtr (void)
+ {
+ Enr_AddAdm (HieLvl_CTR,Gbl.Hierarchy.Ctr.CtrCod,Gbl.Hierarchy.Ctr.FullName);
+ }
+
+/*****************************************************************************/
+/******************* Add an administrator to current degree ******************/
+/*****************************************************************************/
+
+void Adm_AddAdmToDeg (void)
+ {
+ Enr_AddAdm (HieLvl_DEG,Gbl.Hierarchy.Deg.DegCod,Gbl.Hierarchy.Deg.FullName);
+ }
+
+/*****************************************************************************/
+/******************* Add an administrator to current degree ******************/
+/*****************************************************************************/
+
+static void Enr_AddAdm (HieLvl_Level_t Scope,long Cod,
+ const char *InsCtrDegName)
+ {
+ bool ICanRegister;
+
+ if (Cod > 0)
+ {
+ /***** Get plain user's ID of the user to add/modify *****/
+ if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ())
+ {
+ /* Check if I am allowed to register user as administrator in institution/center/degree */
+ ICanRegister = ((Scope == HieLvl_DEG && Gbl.Usrs.Me.Role.Logged >= Rol_CTR_ADM) ||
+ (Scope == HieLvl_CTR && Gbl.Usrs.Me.Role.Logged >= Rol_INS_ADM) ||
+ (Scope == HieLvl_INS && Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM));
+ if (ICanRegister)
+ {
+ /***** Register administrator in current institution/center/degree in database *****/
+ Adm_RegisterAdmin (&Gbl.Usrs.Other.UsrDat,Scope,
+ Cod,InsCtrDegName);
+
+ /***** Show user's record *****/
+ Rec_ShowSharedRecordUnmodifiable (&Gbl.Usrs.Other.UsrDat);
+ }
+ else
+ Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
+ }
+ else
+ Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
+ }
+ }
+
+/*****************************************************************************/
+/**************** Register administrator in current institution **************/
+/*****************************************************************************/
+
+static void Adm_RegisterAdmin (struct UsrData *UsrDat,
+ HieLvl_Level_t Scope,long Cod,
+ const char *InsCtrDegName)
+ {
+ extern const char *Txt_THE_USER_X_is_already_an_administrator_of_Y;
+ extern const char *Txt_THE_USER_X_has_been_enroled_as_administrator_of_Y;
+
+ /***** Check if user was and administrator of current institution/center/degree *****/
+ if (Usr_CheckIfUsrIsAdm (UsrDat->UsrCod,Scope,Cod))
+ Ale_ShowAlert (Ale_SUCCESS,Txt_THE_USER_X_is_already_an_administrator_of_Y,
+ UsrDat->FullName,InsCtrDegName);
+ else // User was not administrator of current institution/center/degree
+ {
+ /***** Insert or replace administrator in current institution/center/degree *****/
+ Adm_DB_InsertAdmin (UsrDat->UsrCod,Scope,Cod);
+
+ Ale_ShowAlert (Ale_SUCCESS,Txt_THE_USER_X_has_been_enroled_as_administrator_of_Y,
+ UsrDat->FullName,InsCtrDegName);
+ }
+ }
+
+/*****************************************************************************/
+/******* Ask for remove of an administrator from current institution *********/
+/*****************************************************************************/
+
+void Adm_ReqRemAdmOfIns (void)
+ {
+ Adm_ReqRemOrRemAdm (Enr_REQUEST_REMOVE_USR,HieLvl_INS,
+ Gbl.Hierarchy.Ins.InsCod,Gbl.Hierarchy.Ins.FullName);
+ }
+
+/*****************************************************************************/
+/********* Ask for remove of an administrator from current center ************/
+/*****************************************************************************/
+
+void Adm_ReqRemAdmOfCtr (void)
+ {
+ Adm_ReqRemOrRemAdm (Enr_REQUEST_REMOVE_USR,HieLvl_CTR,
+ Gbl.Hierarchy.Ctr.CtrCod,Gbl.Hierarchy.Ctr.FullName);
+ }
+
+/*****************************************************************************/
+/********* Ask for remove of an administrator from current degree ************/
+/*****************************************************************************/
+
+void Adm_ReqRemAdmOfDeg (void)
+ {
+ Adm_ReqRemOrRemAdm (Enr_REQUEST_REMOVE_USR,HieLvl_DEG,
+ Gbl.Hierarchy.Deg.DegCod,Gbl.Hierarchy.Deg.FullName);
+ }
+
+/*****************************************************************************/
+/************ Remove an administrator from current institution ***************/
+/*****************************************************************************/
+
+void Adm_RemAdmIns (void)
+ {
+ Adm_ReqRemOrRemAdm (Enr_REMOVE_USR,HieLvl_INS,
+ Gbl.Hierarchy.Ins.InsCod,Gbl.Hierarchy.Ins.FullName);
+ }
+
+/*****************************************************************************/
+/*************** Remove an administrator from current center *****************/
+/*****************************************************************************/
+
+void Adm_RemAdmCtr (void)
+ {
+ Adm_ReqRemOrRemAdm (Enr_REMOVE_USR,HieLvl_CTR,
+ Gbl.Hierarchy.Ctr.CtrCod,Gbl.Hierarchy.Ctr.FullName);
+ }
+
+/*****************************************************************************/
+/*************** Remove an administrator from current degree *****************/
+/*****************************************************************************/
+
+void Adm_RemAdmDeg (void)
+ {
+ Adm_ReqRemOrRemAdm (Enr_REMOVE_USR,HieLvl_DEG,
+ Gbl.Hierarchy.Deg.DegCod,Gbl.Hierarchy.Deg.FullName);
+ }
+
+/*****************************************************************************/
+/***************** Remove an admin from current institution ******************/
+/*****************************************************************************/
+
+static void Adm_ReqRemOrRemAdm (Enr_ReqDelOrDelUsr_t ReqDelOrDelUsr,
+ HieLvl_Level_t Scope,long Cod,
+ const char *InsCtrDegName)
+ {
+ extern const char *Txt_THE_USER_X_is_not_an_administrator_of_Y;
+ bool ItsMe;
+ bool ICanRemove;
+
+ if (Cod > 0)
+ {
+ /***** Get user to be removed *****/
+ if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ())
+ {
+ /* Check if it's forbidden to remove an administrator */
+ ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod);
+ ICanRemove = (ItsMe ||
+ (Scope == HieLvl_DEG && Gbl.Usrs.Me.Role.Logged >= Rol_CTR_ADM) ||
+ (Scope == HieLvl_CTR && Gbl.Usrs.Me.Role.Logged >= Rol_INS_ADM) ||
+ (Scope == HieLvl_INS && Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM));
+ if (ICanRemove)
+ {
+ /* Check if the other user is an admin of the current institution/center/degree */
+ if (Usr_CheckIfUsrIsAdm (Gbl.Usrs.Other.UsrDat.UsrCod,Scope,Cod))
+ { // The other user is an administrator of current institution/center/degree ==> ask for removing or remove her/him
+ switch (ReqDelOrDelUsr)
+ {
+ case Enr_REQUEST_REMOVE_USR: // Ask if remove administrator from current institution
+ Adm_AskIfRemAdm (ItsMe,Scope,InsCtrDegName);
+ break;
+ case Enr_REMOVE_USR: // Remove administrator from current institution
+ Adm_EffectivelyRemAdm (&Gbl.Usrs.Other.UsrDat,Scope,
+ Cod,InsCtrDegName);
+ break;
+ }
+ }
+ else // The other user is not an administrator of current institution
+ Ale_ShowAlert (Ale_WARNING,Txt_THE_USER_X_is_not_an_administrator_of_Y,
+ Gbl.Usrs.Other.UsrDat.FullName,InsCtrDegName);
+ }
+ else
+ Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
+ }
+ else
+ Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
+ }
+ }
+
+/*****************************************************************************/
+/** Ask if really wanted to remove an administrator from current institution */
+/*****************************************************************************/
+
+static void Adm_AskIfRemAdm (bool ItsMe,HieLvl_Level_t Scope,
+ const char *InsCtrDegName)
+ {
+ extern const char *Txt_Do_you_really_want_to_be_removed_as_an_administrator_of_X;
+ extern const char *Txt_Do_you_really_want_to_remove_the_following_user_as_an_administrator_of_X;
+ extern const char *Txt_Remove_me_as_an_administrator;
+ extern const char *Txt_Remove_USER_as_an_administrator;
+ static const Act_Action_t Enr_ActRemAdm[HieLvl_NUM_LEVELS] =
+ {
+ [HieLvl_UNK] = ActUnk,
+ [HieLvl_SYS] = ActUnk,
+ [HieLvl_CTY] = ActUnk,
+ [HieLvl_INS] = ActRemAdmIns,
+ [HieLvl_CTR] = ActRemAdmCtr,
+ [HieLvl_DEG] = ActRemAdmDeg,
+ [HieLvl_CRS] = ActUnk,
+ };
+
+ if (Usr_ChkIfUsrCodExists (Gbl.Usrs.Other.UsrDat.UsrCod))
+ {
+ /***** Show question and button to remove user as administrator *****/
+ /* Begin alert */
+ Ale_ShowAlertAndButton1 (Ale_QUESTION,ItsMe ? Txt_Do_you_really_want_to_be_removed_as_an_administrator_of_X :
+ Txt_Do_you_really_want_to_remove_the_following_user_as_an_administrator_of_X,
+ InsCtrDegName);
+
+ /* Show user's record */
+ Rec_ShowSharedRecordUnmodifiable (&Gbl.Usrs.Other.UsrDat);
+
+ /* End alert */
+ Ale_ShowAlertAndButton2 (Enr_ActRemAdm[Scope],NULL,NULL,
+ Usr_PutParamOtherUsrCodEncrypted,Gbl.Usrs.Other.UsrDat.EnUsrCod,
+ Btn_REMOVE_BUTTON,
+ ItsMe ? Txt_Remove_me_as_an_administrator :
+ Txt_Remove_USER_as_an_administrator);
+ }
+ else
+ Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
+ }
+
+/*****************************************************************************/
+/**** Remove an administrator from current institution, center or degree *****/
+/*****************************************************************************/
+
+static void Adm_EffectivelyRemAdm (struct UsrData *UsrDat,
+ HieLvl_Level_t Scope,long Cod,
+ const char *InsCtrDegName)
+ {
+ extern const char *Txt_THE_USER_X_has_been_removed_as_administrator_of_Y;
+ extern const char *Txt_THE_USER_X_is_not_an_administrator_of_Y;
+
+ if (Usr_CheckIfUsrIsAdm (UsrDat->UsrCod,Scope,Cod)) // User is administrator of current institution/center/degree
+ {
+ /***** Remove user as administrator of institution, center or degree *****/
+ Adm_DB_RemAdmin (UsrDat->UsrCod,Scope,Cod);
+
+ Ale_ShowAlert (Ale_SUCCESS,Txt_THE_USER_X_has_been_removed_as_administrator_of_Y,
+ UsrDat->FullName,InsCtrDegName);
+ }
+ else // User is not an administrator of the current institution/center/degree
+ Ale_ShowAlert (Ale_ERROR,Txt_THE_USER_X_is_not_an_administrator_of_Y,
+ UsrDat->FullName,InsCtrDegName);
+ }
diff --git a/swad_admin.h b/swad_admin.h
new file mode 100644
index 00000000..95e26f6f
--- /dev/null
+++ b/swad_admin.h
@@ -0,0 +1,65 @@
+// swad_admin.h: administrators
+
+#ifndef _SWAD_ADM
+#define _SWAD_ADM
+/*
+ SWAD (Shared Workspace At a Distance in Spanish),
+ 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-2021 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 .
+*/
+/*****************************************************************************/
+/********************************** Headers **********************************/
+/*****************************************************************************/
+
+#include "swad_admin.h"
+// #include "swad_course.h"
+#include "swad_enrolment.h"
+#include "swad_hierarchy.h"
+// #include "swad_notification.h"
+// #include "swad_user.h"
+
+/*****************************************************************************/
+/****************************** Public constants *****************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/******************************** Public types *******************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/****************************** Public prototypes ****************************/
+/*****************************************************************************/
+
+void Adm_ReqAddAdmOfIns (void);
+void Adm_ReqAddAdmOfCtr (void);
+void Adm_ReqAddAdmOfDeg (void);
+
+void Adm_AddAdmToIns (void);
+void Adm_AddAdmToCtr (void);
+void Adm_AddAdmToDeg (void);
+
+void Adm_ReqRemAdmOfIns (void);
+void Adm_ReqRemAdmOfCtr (void);
+void Adm_ReqRemAdmOfDeg (void);
+
+void Adm_RemAdmIns (void);
+void Adm_RemAdmCtr (void);
+void Adm_RemAdmDeg (void);
+
+#endif
diff --git a/swad_admin_database.c b/swad_admin_database.c
new file mode 100644
index 00000000..f89313c1
--- /dev/null
+++ b/swad_admin_database.c
@@ -0,0 +1,116 @@
+// swad_admin_database.c: administrators operations with database
+
+/*
+ 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-2021 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 .
+*/
+/*****************************************************************************/
+/*********************************** Headers *********************************/
+/*****************************************************************************/
+
+#include "swad_database.h"
+#include "swad_admin.h"
+#include "swad_admin_database.h"
+// #include "swad_error.h"
+// #include "swad_global.h"
+
+/*****************************************************************************/
+/****************************** Public constants *****************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/***************************** Private constants *****************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/******************************* Private types *******************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/************** External global variables from others modules ****************/
+/*****************************************************************************/
+
+extern struct Globals Gbl;
+
+/*****************************************************************************/
+/************************** Private global variables *************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/***************************** Private prototypes ****************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/** Insert/replace user as administrator of an institution, center or degree */
+/*****************************************************************************/
+
+void Adm_DB_InsertAdmin (long UsrCod,HieLvl_Level_t Scope,long Cod)
+ {
+ DB_QueryREPLACE ("can not create administrator",
+ "REPLACE INTO usr_admins"
+ " (UsrCod,Scope,Cod)"
+ " VALUES"
+ " (%ld,'%s',%ld)",
+ UsrCod,
+ Sco_GetDBStrFromScope (Scope),
+ Cod);
+ }
+
+/*****************************************************************************/
+/***** Remove user as administrator of an institution, center or degree ******/
+/*****************************************************************************/
+
+void Adm_DB_RemAdmin (long UsrCod,HieLvl_Level_t Scope,long Cod)
+ {
+ DB_QueryDELETE ("can not remove an administrator",
+ "DELETE FROM usr_admins"
+ " WHERE UsrCod=%ld"
+ " AND Scope='%s'"
+ " AND Cod=%ld",
+ UsrCod,
+ Sco_GetDBStrFromScope (Scope),
+ Cod);
+ }
+
+/*****************************************************************************/
+/******* Remove user as administrator of any degree/center/institution *******/
+/*****************************************************************************/
+
+void Adm_DB_RemUsrAsAdmin (long UsrCod)
+ {
+ DB_QueryDELETE ("can not remove a user as administrator",
+ "DELETE FROM usr_admins"
+ " WHERE UsrCod=%ld",
+ UsrCod);
+ }
+
+/*****************************************************************************/
+/********* Remove administrators of an institution, center or degree *********/
+/*****************************************************************************/
+
+void Adm_DB_RemAdmins (HieLvl_Level_t Scope,long Cod)
+ {
+ DB_QueryDELETE ("can not remove administrators",
+ "DELETE FROM usr_admins"
+ " WHERE Scope='%s'"
+ " AND Cod=%ld",
+ Sco_GetDBStrFromScope (Scope),
+ Cod);
+ }
diff --git a/swad_admin_database.h b/swad_admin_database.h
new file mode 100644
index 00000000..874b3975
--- /dev/null
+++ b/swad_admin_database.h
@@ -0,0 +1,49 @@
+// swad_admin_database.h: administrators operations with database
+
+#ifndef _SWAD_ADM_DB
+#define _SWAD_ADM_DB
+/*
+ SWAD (Shared Workspace At a Distance in Spanish),
+ 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-2021 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 .
+*/
+/*****************************************************************************/
+/********************************** Headers **********************************/
+/*****************************************************************************/
+
+#include "swad_hierarchy.h"
+
+/*****************************************************************************/
+/****************************** Public constants *****************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/******************************** Public types *******************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/****************************** Public prototypes ****************************/
+/*****************************************************************************/
+
+void Adm_DB_InsertAdmin (long UsrCod,HieLvl_Level_t Scope,long Cod);
+void Adm_DB_RemAdmin (long UsrCod,HieLvl_Level_t Scope,long Cod);
+void Adm_DB_RemUsrAsAdmin (long UsrCod);
+void Adm_DB_RemAdmins (HieLvl_Level_t Scope,long Cod);
+
+#endif
diff --git a/swad_center.c b/swad_center.c
index b6f5280f..13e8c2a7 100644
--- a/swad_center.c
+++ b/swad_center.c
@@ -30,6 +30,7 @@
#include // For free
#include // For string functions
+#include "swad_admin_database.h"
#include "swad_center.h"
#include "swad_center_config.h"
#include "swad_center_database.h"
@@ -1097,7 +1098,7 @@ void Ctr_RemoveCenter (void)
Fil_RemoveTree (PathCtr);
/***** Remove administrators of this center *****/
- Enr_DB_RemAdmins (HieLvl_CTR,Ctr_EditingCtr->CtrCod);
+ Adm_DB_RemAdmins (HieLvl_CTR,Ctr_EditingCtr->CtrCod);
/***** Remove center *****/
Ctr_DB_RemoveCenter (Ctr_EditingCtr->CtrCod);
diff --git a/swad_changelog.h b/swad_changelog.h
index 50d980e3..84af37ab 100644
--- a/swad_changelog.h
+++ b/swad_changelog.h
@@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par
TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
*/
-#define Log_PLATFORM_VERSION "SWAD 20.91.3 (2021-06-11)"
+#define Log_PLATFORM_VERSION "SWAD 20.92 (2021-06-11)"
#define CSS_FILE "swad20.45.css"
#define JS_FILE "swad20.69.1.js"
/*
TODO: Rename CENTRE to CENTER in help wiki.
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
+ Version 20.92: Jun 09, 2021 New modules swad_admin and swad_admin_database for administrators. (313381 lines)
Version 20.91.3: Jun 11, 2021 Queries moved to module swad_enrolment_database. (313173 lines)
Version 20.91.2: Jun 11, 2021 Queries moved to module swad_enrolment_database. (313143 lines)
Version 20.91.1: Jun 10, 2021 Queries moved to module swad_enrolment_database. (313145 lines)
diff --git a/swad_degree.c b/swad_degree.c
index 07866389..4f1b4dda 100644
--- a/swad_degree.c
+++ b/swad_degree.c
@@ -30,6 +30,7 @@
#include // For free
#include // For string functions
+#include "swad_admin_database.h"
#include "swad_course_database.h"
#include "swad_database.h"
#include "swad_degree.h"
@@ -1364,7 +1365,7 @@ void Deg_RemoveDegreeCompletely (long DegCod)
Fil_RemoveTree (PathDeg);
/***** Remove administrators of this degree *****/
- Enr_DB_RemAdmins (HieLvl_DEG,DegCod);
+ Adm_DB_RemAdmins (HieLvl_DEG,DegCod);
/***** Remove the degree *****/
Deg_DB_RemoveDeg (DegCod);
diff --git a/swad_enrolment.c b/swad_enrolment.c
index 85383447..dbb18261 100644
--- a/swad_enrolment.c
+++ b/swad_enrolment.c
@@ -32,6 +32,7 @@
#include "swad_account.h"
#include "swad_account_database.h"
+#include "swad_admin.h"
#include "swad_announcement.h"
#include "swad_attendance_database.h"
#include "swad_box.h"
@@ -64,22 +65,6 @@
/***************************** Private constants *****************************/
/*****************************************************************************/
-static const bool Enr_ICanAdminOtherUsrs[Rol_NUM_ROLES] =
- {
- /* Users who can not admin */
- [Rol_UNK ] = false,
- [Rol_GST ] = false,
- [Rol_USR ] = false,
- [Rol_STD ] = false,
- [Rol_NET ] = false,
- /* Users who can admin */
- [Rol_TCH ] = true,
- [Rol_DEG_ADM] = true,
- [Rol_CTR_ADM] = true,
- [Rol_INS_ADM] = true,
- [Rol_SYS_ADM] = true,
- };
-
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
@@ -95,12 +80,6 @@ typedef enum
Enr_ELIMINATE_USRS_FROM_PLATFORM = 5,
} Enr_RegRemUsrsAction_t;
-typedef enum
- {
- Enr_REQUEST_REMOVE_USR,
- Enr_REMOVE_USR,
- } Enr_ReqDelOrDelUsr_t;
-
/* Remove important user production (works and match results)? */
typedef enum
{
@@ -163,28 +142,14 @@ static void Enr_AskIfRegRemUsr (struct ListUsrCods *ListUsrCods,Rol_Role_t Role)
static void Enr_ShowFormToEditOtherUsr (void);
-static void Enr_AddAdm (HieLvl_Level_t Scope,long Cod,const char *InsCtrDegName);
-static void Enr_RegisterAdmin (struct UsrData *UsrDat,HieLvl_Level_t Scope,
- long Cod,const char *InsCtrDegName);
-
static bool Enr_CheckIfICanRemUsrFromCrs (void);
-static void Enr_ReqRemAdmOfDeg (void);
-static void Enr_ReqRemOrRemAdm (Enr_ReqDelOrDelUsr_t ReqDelOrDelUsr,HieLvl_Level_t Scope,
- long Cod,const char *InsCtrDegName);
-
-static void Enr_ReqAddAdm (HieLvl_Level_t Scope,long Cod,const char *InsCtrDegName);
static void Enr_AskIfRemoveUsrFromCrs (struct UsrData *UsrDat);
static void Enr_EffectivelyRemUsrFromCrs (struct UsrData *UsrDat,
struct Crs_Course *Crs,
Enr_RemoveUsrProduction_t RemoveUsrWorks,
Cns_QuietOrVerbose_t QuietOrVerbose);
-static void Enr_AskIfRemAdm (bool ItsMe,HieLvl_Level_t Scope,
- const char *InsCtrDegName);
-static void Enr_EffectivelyRemAdm (struct UsrData *UsrDat,HieLvl_Level_t Scope,
- long Cod,const char *InsCtrDegName);
-
/*****************************************************************************/
/** Check if current course has students and show warning no students found **/
/*****************************************************************************/
@@ -2419,9 +2384,10 @@ static void Enr_RemUsrEnrolmentRequestInCrs (long UsrCod,long CrsCod)
void Enr_PutLinkToAdminOneUsr (Act_Action_t NextAction)
{
+ extern const bool Adm_ICanAdminOtherUsrs[Rol_NUM_ROLES];
extern const char *Txt_Administer_me;
extern const char *Txt_Administer_one_user;
- const char *TitleText = Enr_ICanAdminOtherUsrs[Gbl.Usrs.Me.Role.Logged] ? Txt_Administer_one_user :
+ const char *TitleText = Adm_ICanAdminOtherUsrs[Gbl.Usrs.Me.Role.Logged] ? Txt_Administer_one_user :
Txt_Administer_me;
Lay_PutContextualLinkIconText (NextAction,NULL,
@@ -2479,11 +2445,13 @@ void Enr_ReqRegRemOth (void)
void Enr_ReqRegRemStd (void)
{
+ extern const bool Adm_ICanAdminOtherUsrs[Rol_NUM_ROLES];
+
/***** Contextual menu *****/
- if (Enr_ICanAdminOtherUsrs[Gbl.Usrs.Me.Role.Logged])
+ if (Adm_ICanAdminOtherUsrs[Gbl.Usrs.Me.Role.Logged])
{
Mnu_ContextMenuBegin ();
- Enr_PutLinkToAdminSeveralUsrs (Rol_STD); // Admin several students
+ Enr_PutLinkToAdminSeveralUsrs (Rol_STD); // Admin several students
Mnu_ContextMenuEnd ();
}
@@ -2499,7 +2467,9 @@ void Enr_ReqRegRemTch (void)
static void Enr_ReqRegRemUsr (Rol_Role_t Role)
{
- if (Enr_ICanAdminOtherUsrs[Gbl.Usrs.Me.Role.Logged])
+ extern const bool Adm_ICanAdminOtherUsrs[Rol_NUM_ROLES];
+
+ if (Adm_ICanAdminOtherUsrs[Gbl.Usrs.Me.Role.Logged])
/***** Form to request the user's ID of another user *****/
Enr_ReqAnotherUsrIDToRegisterRemove (Role);
else
@@ -2720,90 +2690,6 @@ static void Enr_ShowFormToEditOtherUsr (void)
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
}
-/*****************************************************************************/
-/*************** Add an administrator to current institution *****************/
-/*****************************************************************************/
-
-void Enr_AddAdmToIns (void)
- {
- Enr_AddAdm (HieLvl_INS,Gbl.Hierarchy.Ins.InsCod,Gbl.Hierarchy.Ins.FullName);
- }
-
-/*****************************************************************************/
-/******************* Add an administrator to current center ******************/
-/*****************************************************************************/
-
-void Enr_AddAdmToCtr (void)
- {
- Enr_AddAdm (HieLvl_CTR,Gbl.Hierarchy.Ctr.CtrCod,Gbl.Hierarchy.Ctr.FullName);
- }
-
-/*****************************************************************************/
-/******************* Add an administrator to current degree ******************/
-/*****************************************************************************/
-
-void Enr_AddAdmToDeg (void)
- {
- Enr_AddAdm (HieLvl_DEG,Gbl.Hierarchy.Deg.DegCod,Gbl.Hierarchy.Deg.FullName);
- }
-
-/*****************************************************************************/
-/******************* Add an administrator to current degree ******************/
-/*****************************************************************************/
-
-static void Enr_AddAdm (HieLvl_Level_t Scope,long Cod,const char *InsCtrDegName)
- {
- bool ICanRegister;
-
- if (Cod > 0)
- {
- /***** Get plain user's ID of the user to add/modify *****/
- if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ())
- {
- /* Check if I am allowed to register user as administrator in institution/center/degree */
- ICanRegister = ((Scope == HieLvl_DEG && Gbl.Usrs.Me.Role.Logged >= Rol_CTR_ADM) ||
- (Scope == HieLvl_CTR && Gbl.Usrs.Me.Role.Logged >= Rol_INS_ADM) ||
- (Scope == HieLvl_INS && Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM));
- if (ICanRegister)
- {
- /***** Register administrator in current institution/center/degree in database *****/
- Enr_RegisterAdmin (&Gbl.Usrs.Other.UsrDat,Scope,
- Cod,InsCtrDegName);
-
- /***** Show user's record *****/
- Rec_ShowSharedRecordUnmodifiable (&Gbl.Usrs.Other.UsrDat);
- }
- else
- Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
- }
- else
- Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
- }
- }
-
-/*****************************************************************************/
-/**************** Register administrator in current institution **************/
-/*****************************************************************************/
-
-static void Enr_RegisterAdmin (struct UsrData *UsrDat,HieLvl_Level_t Scope,long Cod,const char *InsCtrDegName)
- {
- extern const char *Txt_THE_USER_X_is_already_an_administrator_of_Y;
- extern const char *Txt_THE_USER_X_has_been_enroled_as_administrator_of_Y;
-
- /***** Check if user was and administrator of current institution/center/degree *****/
- if (Usr_CheckIfUsrIsAdm (UsrDat->UsrCod,Scope,Cod))
- Ale_ShowAlert (Ale_SUCCESS,Txt_THE_USER_X_is_already_an_administrator_of_Y,
- UsrDat->FullName,InsCtrDegName);
- else // User was not administrator of current institution/center/degree
- {
- /***** Insert or replace administrator in current institution/center/degree *****/
- Enr_DB_InsertAdmin (UsrDat->UsrCod,Scope,Cod);
-
- Ale_ShowAlert (Ale_SUCCESS,Txt_THE_USER_X_has_been_enroled_as_administrator_of_Y,
- UsrDat->FullName,InsCtrDegName);
- }
- }
-
/*****************************************************************************/
/****************** Ask for remove me from current course ********************/
/*****************************************************************************/
@@ -2890,178 +2776,6 @@ static bool Enr_CheckIfICanRemUsrFromCrs (void)
return false;
}
-/*****************************************************************************/
-/******* Ask for remove of an administrator from current institution *********/
-/*****************************************************************************/
-
-static void Enr_ReqRemAdmOfIns (void)
- {
- Enr_ReqRemOrRemAdm (Enr_REQUEST_REMOVE_USR,HieLvl_INS,
- Gbl.Hierarchy.Ins.InsCod,Gbl.Hierarchy.Ins.FullName);
- }
-
-/*****************************************************************************/
-/********* Ask for remove of an administrator from current center ************/
-/*****************************************************************************/
-
-static void Enr_ReqRemAdmOfCtr (void)
- {
- Enr_ReqRemOrRemAdm (Enr_REQUEST_REMOVE_USR,HieLvl_CTR,
- Gbl.Hierarchy.Ctr.CtrCod,Gbl.Hierarchy.Ctr.FullName);
- }
-
-/*****************************************************************************/
-/********* Ask for remove of an administrator from current degree ************/
-/*****************************************************************************/
-
-static void Enr_ReqRemAdmOfDeg (void)
- {
- Enr_ReqRemOrRemAdm (Enr_REQUEST_REMOVE_USR,HieLvl_DEG,
- Gbl.Hierarchy.Deg.DegCod,Gbl.Hierarchy.Deg.FullName);
- }
-
-/*****************************************************************************/
-/************ Remove an administrator from current institution ***************/
-/*****************************************************************************/
-
-void Enr_RemAdmIns (void)
- {
- Enr_ReqRemOrRemAdm (Enr_REMOVE_USR,HieLvl_INS,
- Gbl.Hierarchy.Ins.InsCod,Gbl.Hierarchy.Ins.FullName);
- }
-
-/*****************************************************************************/
-/*************** Remove an administrator from current center *****************/
-/*****************************************************************************/
-
-void Enr_RemAdmCtr (void)
- {
- Enr_ReqRemOrRemAdm (Enr_REMOVE_USR,HieLvl_CTR,
- Gbl.Hierarchy.Ctr.CtrCod,Gbl.Hierarchy.Ctr.FullName);
- }
-
-/*****************************************************************************/
-/*************** Remove an administrator from current degree *****************/
-/*****************************************************************************/
-
-void Enr_RemAdmDeg (void)
- {
- Enr_ReqRemOrRemAdm (Enr_REMOVE_USR,HieLvl_DEG,
- Gbl.Hierarchy.Deg.DegCod,Gbl.Hierarchy.Deg.FullName);
- }
-
-/*****************************************************************************/
-/***************** Remove an admin from current institution ******************/
-/*****************************************************************************/
-
-static void Enr_ReqRemOrRemAdm (Enr_ReqDelOrDelUsr_t ReqDelOrDelUsr,HieLvl_Level_t Scope,
- long Cod,const char *InsCtrDegName)
- {
- extern const char *Txt_THE_USER_X_is_not_an_administrator_of_Y;
- bool ItsMe;
- bool ICanRemove;
-
- if (Cod > 0)
- {
- /***** Get user to be removed *****/
- if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ())
- {
- /* Check if it's forbidden to remove an administrator */
- ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod);
- ICanRemove = (ItsMe ||
- (Scope == HieLvl_DEG && Gbl.Usrs.Me.Role.Logged >= Rol_CTR_ADM) ||
- (Scope == HieLvl_CTR && Gbl.Usrs.Me.Role.Logged >= Rol_INS_ADM) ||
- (Scope == HieLvl_INS && Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM));
- if (ICanRemove)
- {
- /* Check if the other user is an admin of the current institution/center/degree */
- if (Usr_CheckIfUsrIsAdm (Gbl.Usrs.Other.UsrDat.UsrCod,Scope,Cod))
- { // The other user is an administrator of current institution/center/degree ==> ask for removing or remove her/him
- switch (ReqDelOrDelUsr)
- {
- case Enr_REQUEST_REMOVE_USR: // Ask if remove administrator from current institution
- Enr_AskIfRemAdm (ItsMe,Scope,InsCtrDegName);
- break;
- case Enr_REMOVE_USR: // Remove administrator from current institution
- Enr_EffectivelyRemAdm (&Gbl.Usrs.Other.UsrDat,Scope,
- Cod,InsCtrDegName);
- break;
- }
- }
- else // The other user is not an administrator of current institution
- Ale_ShowAlert (Ale_WARNING,Txt_THE_USER_X_is_not_an_administrator_of_Y,
- Gbl.Usrs.Other.UsrDat.FullName,InsCtrDegName);
- }
- else
- Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
- }
- else
- Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
- }
- }
-
-/*****************************************************************************/
-/**** Ask if really wanted to add an administrator to current institution ****/
-/*****************************************************************************/
-
-static void Enr_ReqAddAdm (HieLvl_Level_t Scope,long Cod,const char *InsCtrDegName)
- {
- extern const char *Txt_THE_USER_X_is_already_an_administrator_of_Y;
- extern const char *Txt_Do_you_really_want_to_register_the_following_user_as_an_administrator_of_X;
- extern const char *Txt_Register_user_IN_A_COURSE_OR_DEGREE;
- static const Act_Action_t Enr_ActNewAdm[HieLvl_NUM_LEVELS] =
- {
- [HieLvl_UNK] = ActUnk,
- [HieLvl_SYS] = ActUnk,
- [HieLvl_CTY] = ActUnk,
- [HieLvl_INS] = ActNewAdmIns,
- [HieLvl_CTR] = ActNewAdmCtr,
- [HieLvl_DEG] = ActNewAdmDeg,
- [HieLvl_CRS] = ActUnk,
- };
- bool ICanRegister;
-
- if (Cod > 0)
- {
- /***** Get user's identificator of the user to register as admin *****/
- if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ())
- {
- /* Check if I am allowed to register user as administrator in institution/center/degree */
- ICanRegister = ((Scope == HieLvl_DEG && Gbl.Usrs.Me.Role.Logged >= Rol_CTR_ADM) ||
- (Scope == HieLvl_CTR && Gbl.Usrs.Me.Role.Logged >= Rol_INS_ADM) ||
- (Scope == HieLvl_INS && Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM));
- if (ICanRegister)
- {
- if (Usr_CheckIfUsrIsAdm (Gbl.Usrs.Other.UsrDat.UsrCod,Scope,Cod)) // User is already an administrator of current institution/center/degree
- {
- Ale_ShowAlert (Ale_INFO,Txt_THE_USER_X_is_already_an_administrator_of_Y,
- Gbl.Usrs.Other.UsrDat.FullName,InsCtrDegName);
- Rec_ShowSharedRecordUnmodifiable (&Gbl.Usrs.Other.UsrDat);
- }
- else
- {
- /***** Show question and button to register user as administrator *****/
- /* Begin alert */
- Ale_ShowAlertAndButton1 (Ale_QUESTION,Txt_Do_you_really_want_to_register_the_following_user_as_an_administrator_of_X,
- InsCtrDegName);
-
- /* Show user's record */
- Rec_ShowSharedRecordUnmodifiable (&Gbl.Usrs.Other.UsrDat);
-
- /* End alert */
- Ale_ShowAlertAndButton2 (Enr_ActNewAdm[Scope],NULL,NULL,
- Usr_PutParamOtherUsrCodEncrypted,Gbl.Usrs.Other.UsrDat.EnUsrCod,
- Btn_CREATE_BUTTON,Txt_Register_user_IN_A_COURSE_OR_DEGREE);
- }
- }
- else
- Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
- }
- else
- Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
- }
- }
-
/*****************************************************************************/
/*************** Accept my enrolment in the current course ******************/
/*****************************************************************************/
@@ -3376,16 +3090,13 @@ void Enr_ModifyUsr2 (void)
Enr_ShowFormToEditOtherUsr ();
break;
case Enr_REGISTER_ONE_DEGREE_ADMIN:
- Enr_ReqAddAdm (HieLvl_DEG,Gbl.Hierarchy.Deg.DegCod,
- Gbl.Hierarchy.Deg.FullName);
+ Adm_ReqAddAdmOfDeg ();
break;
case Enr_REGISTER_ONE_CENTER_ADMIN:
- Enr_ReqAddAdm (HieLvl_CTR,Gbl.Hierarchy.Ctr.CtrCod,
- Gbl.Hierarchy.Ctr.FullName);
+ Adm_ReqAddAdmOfCtr ();
break;
case Enr_REGISTER_ONE_INSTITUTION_ADMIN:
- Enr_ReqAddAdm (HieLvl_INS,Gbl.Hierarchy.Ins.InsCod,
- Gbl.Hierarchy.Ins.FullName);
+ Adm_ReqAddAdmOfIns ();
break;
case Enr_REPORT_USR_AS_POSSIBLE_DUPLICATE:
Dup_ReportUsrAsPossibleDuplicate ();
@@ -3394,13 +3105,13 @@ void Enr_ModifyUsr2 (void)
Enr_ReqRemUsrFromCrs ();
break;
case Enr_REMOVE_ONE_DEGREE_ADMIN:
- Enr_ReqRemAdmOfDeg ();
+ Adm_ReqRemAdmOfDeg ();
break;
case Enr_REMOVE_ONE_CENTER_ADMIN:
- Enr_ReqRemAdmOfCtr ();
+ Adm_ReqRemAdmOfCtr ();
break;
case Enr_REMOVE_ONE_INSTITUTION_ADMIN:
- Enr_ReqRemAdmOfIns ();
+ Adm_ReqRemAdmOfIns ();
break;
case Enr_ELIMINATE_ONE_USR_FROM_PLATFORM:
Acc_ReqRemAccountOrRemAccount (Acc_REQUEST_REMOVE_USR);
@@ -3560,70 +3271,3 @@ static void Enr_EffectivelyRemUsrFromCrs (struct UsrData *UsrDat,
if (QuietOrVerbose == Cns_VERBOSE)
Ale_CreateAlertUserNotFoundOrYouDoNotHavePermission ();
}
-
-/*****************************************************************************/
-/** Ask if really wanted to remove an administrator from current institution */
-/*****************************************************************************/
-
-static void Enr_AskIfRemAdm (bool ItsMe,HieLvl_Level_t Scope,
- const char *InsCtrDegName)
- {
- extern const char *Txt_Do_you_really_want_to_be_removed_as_an_administrator_of_X;
- extern const char *Txt_Do_you_really_want_to_remove_the_following_user_as_an_administrator_of_X;
- extern const char *Txt_Remove_me_as_an_administrator;
- extern const char *Txt_Remove_USER_as_an_administrator;
- static const Act_Action_t Enr_ActRemAdm[HieLvl_NUM_LEVELS] =
- {
- [HieLvl_UNK] = ActUnk,
- [HieLvl_SYS] = ActUnk,
- [HieLvl_CTY] = ActUnk,
- [HieLvl_INS] = ActRemAdmIns,
- [HieLvl_CTR] = ActRemAdmCtr,
- [HieLvl_DEG] = ActRemAdmDeg,
- [HieLvl_CRS] = ActUnk,
- };
-
- if (Usr_ChkIfUsrCodExists (Gbl.Usrs.Other.UsrDat.UsrCod))
- {
- /***** Show question and button to remove user as administrator *****/
- /* Begin alert */
- Ale_ShowAlertAndButton1 (Ale_QUESTION,ItsMe ? Txt_Do_you_really_want_to_be_removed_as_an_administrator_of_X :
- Txt_Do_you_really_want_to_remove_the_following_user_as_an_administrator_of_X,
- InsCtrDegName);
-
- /* Show user's record */
- Rec_ShowSharedRecordUnmodifiable (&Gbl.Usrs.Other.UsrDat);
-
- /* End alert */
- Ale_ShowAlertAndButton2 (Enr_ActRemAdm[Scope],NULL,NULL,
- Usr_PutParamOtherUsrCodEncrypted,Gbl.Usrs.Other.UsrDat.EnUsrCod,
- Btn_REMOVE_BUTTON,
- ItsMe ? Txt_Remove_me_as_an_administrator :
- Txt_Remove_USER_as_an_administrator);
- }
- else
- Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
- }
-
-/*****************************************************************************/
-/**** Remove an administrator from current institution, center or degree *****/
-/*****************************************************************************/
-
-static void Enr_EffectivelyRemAdm (struct UsrData *UsrDat,HieLvl_Level_t Scope,
- long Cod,const char *InsCtrDegName)
- {
- extern const char *Txt_THE_USER_X_has_been_removed_as_administrator_of_Y;
- extern const char *Txt_THE_USER_X_is_not_an_administrator_of_Y;
-
- if (Usr_CheckIfUsrIsAdm (UsrDat->UsrCod,Scope,Cod)) // User is administrator of current institution/center/degree
- {
- /***** Remove user as administrator of institution, center or degree *****/
- Enr_DB_RemAdmin (UsrDat->UsrCod,Scope,Cod);
-
- Ale_ShowAlert (Ale_SUCCESS,Txt_THE_USER_X_has_been_removed_as_administrator_of_Y,
- UsrDat->FullName,InsCtrDegName);
- }
- else // User is not an administrator of the current institution/center/degree
- Ale_ShowAlert (Ale_ERROR,Txt_THE_USER_X_is_not_an_administrator_of_Y,
- UsrDat->FullName,InsCtrDegName);
- }
diff --git a/swad_enrolment.h b/swad_enrolment.h
index 695eb50a..c0bb06c5 100644
--- a/swad_enrolment.h
+++ b/swad_enrolment.h
@@ -67,6 +67,12 @@ typedef enum
Enr_ELIMINATE_ONE_USR_FROM_PLATFORM = 10,
} Enr_RegRemOneUsrAction_t;
+typedef enum
+ {
+ Enr_REQUEST_REMOVE_USR,
+ Enr_REMOVE_USR,
+ } Enr_ReqDelOrDelUsr_t;
+
/*****************************************************************************/
/****************************** Public prototypes ****************************/
/*****************************************************************************/
@@ -123,17 +129,11 @@ void Enr_ReqRegRemTch (void);
void Enr_AskIfRegRemAnotherOth (void);
void Enr_AskIfRegRemAnotherStd (void);
void Enr_AskIfRegRemAnotherTch (void);
-void Enr_AddAdmToIns (void);
-void Enr_AddAdmToCtr (void);
-void Enr_AddAdmToDeg (void);
void Enr_ReqRemMeFromCrs (void);
void Enr_ReqRemUsrFromCrs (void);
void Enr_RemUsrFromCrs1 (void);
void Enr_RemUsrFromCrs2 (void);
-void Enr_RemAdmIns (void);
-void Enr_RemAdmCtr (void);
-void Enr_RemAdmDeg (void);
void Enr_AcceptRegisterMeInCrs (void);
void Enr_CreateNewUsr1 (void);
diff --git a/swad_enrolment_database.c b/swad_enrolment_database.c
index 65a7ebf3..0bfc2599 100644
--- a/swad_enrolment_database.c
+++ b/swad_enrolment_database.c
@@ -25,34 +25,11 @@
/*********************************** Headers *********************************/
/*****************************************************************************/
-// #define _GNU_SOURCE // For asprintf
-// #include // For asprintf
-// #include // For exit, system, malloc, free, rand, etc.
-// #include // For string functions
-
-// #include "swad_account.h"
-// #include "swad_announcement.h"
-// #include "swad_attendance_database.h"
-// #include "swad_box.h"
#include "swad_database.h"
-// #include "swad_duplicate.h"
#include "swad_enrolment.h"
#include "swad_enrolment_database.h"
#include "swad_error.h"
-// #include "swad_exam_print.h"
-// #include "swad_form.h"
#include "swad_global.h"
-// #include "swad_hierarchy.h"
-// #include "swad_HTML.h"
-// #include "swad_ID.h"
-// #include "swad_match.h"
-// #include "swad_message.h"
-// #include "swad_notification.h"
-// #include "swad_parameter.h"
-// #include "swad_photo.h"
-// #include "swad_role.h"
-// #include "swad_test_print.h"
-// #include "swad_user.h"
/*****************************************************************************/
/****************************** Public constants *****************************/
@@ -815,61 +792,3 @@ void Enr_DB_RemoveExpiredEnrolmentRequests (void)
" WHERE RequestTime // For free
#include // For string functions
+#include "swad_admin_database.h"
#include "swad_database.h"
#include "swad_department.h"
#include "swad_enrolment_database.h"
@@ -1366,7 +1367,7 @@ void Ins_RemoveInstitution (void)
Fil_RemoveTree (PathIns);
/***** Remove administrators of this institution *****/
- Enr_DB_RemAdmins (HieLvl_INS,Ins_EditingIns->InsCod);
+ Adm_DB_RemAdmins (HieLvl_INS,Ins_EditingIns->InsCod);
/***** Remove institution *****/
DB_QueryDELETE ("can not remove an institution",