2017-03-30 11:20:06 +02:00
// swad_enrolment.c: enrolment (registration) or removing of users
2014-12-12 18:52:06 +01:00
/*
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 .
2019-01-07 21:52:19 +01:00
Copyright ( C ) 1999 - 2019 Antonio Ca <EFBFBD> as Vargas
2014-12-12 18:52:06 +01:00
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 *********************************/
/*****************************************************************************/
2018-10-17 10:32:18 +02:00
# define _GNU_SOURCE // For asprintf
# include <stdio.h> // For asprintf
2014-12-12 18:52:06 +01:00
# include <stdlib.h> // For exit, system, malloc, free, rand, etc.
# include <string.h> // For string functions
2014-12-12 22:39:55 +01:00
# include "swad_account.h"
2014-12-12 18:52:06 +01:00
# include "swad_announcement.h"
2017-06-10 21:38:10 +02:00
# include "swad_box.h"
2014-12-12 18:52:06 +01:00
# include "swad_database.h"
2016-06-16 19:30:29 +02:00
# include "swad_duplicate.h"
2017-03-30 11:20:06 +02:00
# include "swad_enrolment.h"
2018-11-09 20:47:39 +01:00
# include "swad_form.h"
2014-12-12 18:52:06 +01:00
# include "swad_global.h"
# include "swad_ID.h"
# include "swad_notification.h"
# include "swad_parameter.h"
2016-12-13 13:32:19 +01:00
# include "swad_role.h"
2017-06-11 20:09:59 +02:00
# include "swad_table.h"
2014-12-12 18:52:06 +01:00
# include "swad_user.h"
/*****************************************************************************/
/****************************** Public constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
2017-05-19 10:37:14 +02:00
static const bool Enr_ICanAdminOtherUsrs [ Rol_NUM_ROLES ] =
{
2017-05-21 18:08:35 +02:00
/* Users who can not admin */
2017-05-19 10:37:14 +02:00
false , // Rol_UNK
false , // Rol_GST
false , // Rol_USR
false , // Rol_STD
2017-05-22 14:52:11 +02:00
false , // Rol_NET
2017-05-21 18:08:35 +02:00
/* Users who can admin */
2017-05-19 10:37:14 +02:00
true , // Rol_TCH
true , // Rol_DEG_ADM
true , // Rol_CTR_ADM
true , // Rol_INS_ADM
true , // Rol_SYS_ADM
} ;
2014-12-12 18:52:06 +01:00
/*****************************************************************************/
/****************************** Internal types *******************************/
/*****************************************************************************/
2017-01-29 21:41:08 +01:00
# define Enr_NUM_REG_REM_USRS_ACTIONS 6
2014-12-12 18:52:06 +01:00
typedef enum
{
2017-01-29 21:41:08 +01:00
Enr_REG_REM_USRS_UNKNOWN_ACTION = 0 ,
2017-01-29 12:42:19 +01:00
Enr_REGISTER_SPECIFIED_USRS_IN_CRS = 1 ,
Enr_REMOVE_SPECIFIED_USRS_FROM_CRS = 2 ,
Enr_REMOVE_NOT_SPECIFIED_USRS_FROM_CRS = 3 ,
Enr_UPDATE_USRS_IN_CRS = 4 ,
Enr_ELIMINATE_USRS_FROM_PLATFORM = 5 ,
2014-12-12 18:52:06 +01:00
} Enr_RegRemUsrsAction_t ;
2014-12-12 22:39:55 +01:00
typedef enum
{
Enr_REQUEST_REMOVE_USR ,
Enr_REMOVE_USR ,
} Enr_ReqDelOrDelUsr_t ;
2014-12-12 18:52:06 +01:00
typedef enum
{
Enr_DO_NOT_REMOVE_WORKS ,
Enr_REMOVE_WORKS ,
} Enr_RemoveUsrWorks_t ;
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl ;
/*****************************************************************************/
/************************* Internal global variables *************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2017-03-30 11:20:06 +02:00
static void Enr_NotifyAfterEnrolment ( struct UsrData * UsrDat , Rol_Role_t NewRole ) ;
2015-09-17 20:41:31 +02:00
2015-09-14 09:50:55 +02:00
static void Enr_ReqAdminUsrs ( Rol_Role_t Role ) ;
2015-09-14 09:32:27 +02:00
static void Enr_ShowFormRegRemSeveralUsrs ( Rol_Role_t Role ) ;
2014-12-31 02:46:20 +01:00
2014-12-12 18:52:06 +01:00
static void Enr_PutAreaToEnterUsrsIDs ( void ) ;
static void Enr_PutActionsRegRemSeveralUsrs ( void ) ;
2015-09-14 09:50:55 +02:00
static void Enr_ReceiveFormUsrsCrs ( Rol_Role_t Role ) ;
2014-12-12 18:52:06 +01:00
static void Enr_RegisterUsr ( struct UsrData * UsrDat , Rol_Role_t RegRemRole ,
struct ListCodGrps * LstGrps , unsigned * NumUsrsRegistered ) ;
2015-11-20 14:44:54 +01:00
static void Enr_PutLinkToRemAllStdsThisCrs ( void ) ;
2017-03-30 11:20:06 +02:00
static void Enr_ShowEnrolmentRequestsGivenRoles ( unsigned RolesSelected ) ;
2016-03-24 15:09:52 +01:00
2017-03-30 11:20:06 +02:00
static void Enr_RemoveEnrolmentRequest ( long CrsCod , long UsrCod ) ;
static void Enr_RemoveExpiredEnrolmentRequests ( void ) ;
2014-12-12 18:52:06 +01:00
2015-09-12 14:12:40 +02:00
static void Enr_ReqRegRemUsr ( Rol_Role_t Role ) ;
static void Enr_ReqAnotherUsrIDToRegisterRemove ( Rol_Role_t Role ) ;
static void Enr_AskIfRegRemMe ( Rol_Role_t Role ) ;
static void Enr_AskIfRegRemAnotherUsr ( Rol_Role_t Role ) ;
static void Enr_AskIfRegRemUsr ( struct ListUsrCods * ListUsrCods , Rol_Role_t Role ) ;
2014-12-12 18:52:06 +01:00
static void Enr_ShowFormToEditOtherUsr ( void ) ;
2015-02-01 17:43:34 +01:00
static void Enr_AddAdm ( Sco_Scope_t Scope , long Cod , const char * InsCtrDegName ) ;
static void Enr_RegisterAdmin ( struct UsrData * UsrDat , Sco_Scope_t Scope ,
long Cod , const char * InsCtrDegName ) ;
2017-06-04 15:11:41 +02:00
static bool Enr_CheckIfICanRemUsrFromCrs ( void ) ;
2014-12-12 18:52:06 +01:00
static void Enr_ReqRemAdmOfDeg ( void ) ;
2015-02-01 17:06:49 +01:00
static void Enr_ReqRemOrRemAdm ( Enr_ReqDelOrDelUsr_t ReqDelOrDelUsr , Sco_Scope_t Scope ,
long Cod , const char * InsCtrDegName ) ;
2014-12-12 18:52:06 +01:00
2015-02-01 17:43:34 +01:00
static void Enr_ReqAddAdm ( Sco_Scope_t Scope , long Cod , const char * InsCtrDegName ) ;
2017-06-04 15:11:41 +02:00
static void Enr_AskIfRemoveUsrFromCrs ( struct UsrData * UsrDat ) ;
2014-12-12 18:52:06 +01:00
static void Enr_EffectivelyRemUsrFromCrs ( struct UsrData * UsrDat , struct Course * Crs ,
Enr_RemoveUsrWorks_t RemoveUsrWorks , Cns_QuietOrVerbose_t QuietOrVerbose ) ;
2014-12-12 22:39:55 +01:00
2018-10-10 23:56:42 +02:00
static void Enr_AskIfRemAdm ( bool ItsMe , Sco_Scope_t Scope ,
const char * InsCtrDegName ) ;
2015-02-01 17:06:49 +01:00
static void Enr_EffectivelyRemAdm ( struct UsrData * UsrDat , Sco_Scope_t Scope ,
long Cod , const char * InsCtrDegName ) ;
2014-12-12 18:52:06 +01:00
2015-11-20 14:44:54 +01:00
/*****************************************************************************/
2017-10-08 12:29:44 +02:00
/** Check if current course has students and show warning no students found **/
2015-11-20 14:44:54 +01:00
/*****************************************************************************/
2017-05-29 21:34:43 +02:00
void Enr_CheckStdsAndPutButtonToRegisterStdsInCurrentCrs ( void )
2015-11-20 14:44:54 +01:00
{
2017-05-29 21:34:43 +02:00
/***** Put link to register students *****/
2017-06-04 18:18:54 +02:00
if ( Gbl . Usrs . Me . Role . Logged = = Rol_TCH ) // Course selected and I am logged as teacher
2017-05-29 21:34:43 +02:00
if ( ! Gbl . CurrentCrs . Crs . NumUsrs [ Rol_STD ] ) // No students in course
Usr_ShowWarningNoUsersFound ( Rol_STD ) ;
2017-02-09 19:27:18 +01:00
}
/*****************************************************************************/
2017-10-08 12:29:44 +02:00
/****************** Put inline button to register students *******************/
2017-02-09 19:27:18 +01:00
/*****************************************************************************/
2017-05-29 21:34:43 +02:00
void Enr_PutButtonInlineToRegisterStds ( long CrsCod )
2017-02-09 19:27:18 +01:00
{
2017-05-29 21:34:43 +02:00
extern const char * Txt_Register_students ;
2017-02-09 19:27:18 +01:00
2017-06-20 14:43:26 +02:00
if ( Rol_GetRoleUsrInCrs ( Gbl . Usrs . Me . UsrDat . UsrCod , CrsCod ) = = Rol_TCH ) // I am a teacher in course
if ( ! Usr_GetNumUsrsInCrs ( Rol_STD , CrsCod ) ) // No students in course
2017-05-29 21:34:43 +02:00
{
2018-11-09 20:47:39 +01:00
Frm_StartForm ( ActReqEnrSevStd ) ;
2017-05-29 21:34:43 +02:00
Crs_PutParamCrsCod ( CrsCod ) ;
2017-06-11 19:02:40 +02:00
Btn_PutCreateButtonInline ( Txt_Register_students ) ;
2018-11-09 20:47:39 +01:00
Frm_EndForm ( ) ;
2017-05-29 21:34:43 +02:00
}
2015-11-20 14:44:54 +01:00
}
2015-01-16 12:11:27 +01:00
/*****************************************************************************/
/************ Show form to request sign up in the current course *************/
/*****************************************************************************/
void Enr_PutLinkToRequestSignUp ( void )
{
extern const char * Txt_Sign_up ;
/***** Show the form *****/
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkIconText ( ActReqSignUp , NULL , NULL ,
" hand-point-up.svg " ,
Txt_Sign_up ) ;
2015-01-16 12:11:27 +01:00
}
2014-12-12 20:25:00 +01:00
/*****************************************************************************/
/***************** Modify the role of a user in a course *********************/
/*****************************************************************************/
2016-12-17 21:36:57 +01:00
void Enr_ModifyRoleInCurrentCrs ( struct UsrData * UsrDat , Rol_Role_t NewRole )
2014-12-12 20:25:00 +01:00
{
2016-12-17 21:36:57 +01:00
/***** Check if user's role is allowed *****/
switch ( NewRole )
2014-12-12 20:25:00 +01:00
{
2017-05-18 19:13:41 +02:00
case Rol_STD :
2017-05-21 21:23:13 +02:00
case Rol_NET :
2017-05-18 19:13:41 +02:00
case Rol_TCH :
2016-12-17 21:36:57 +01:00
break ;
default :
Lay_ShowErrorAndExit ( " Wrong role. " ) ;
}
2014-12-12 20:25:00 +01:00
2016-12-17 21:36:57 +01:00
/***** Update the role of a user in a course *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ( " can not modify user's role in course " ,
" UPDATE crs_usr SET Role=%u "
" WHERE CrsCod=%ld AND UsrCod=%ld " ,
( unsigned ) NewRole , Gbl . CurrentCrs . Crs . CrsCod , UsrDat - > UsrCod ) ;
2015-09-17 20:41:31 +02:00
2017-07-02 20:36:15 +02:00
/***** Flush caches *****/
Usr_FlushCachesUsr ( ) ;
2014-12-12 20:25:00 +01:00
2017-07-02 20:36:15 +02:00
/***** Set user's roles *****/
2017-06-23 15:12:49 +02:00
UsrDat - > Roles . InCurrentCrs . Role = NewRole ;
UsrDat - > Roles . InCurrentCrs . Valid = true ;
2017-06-08 15:32:33 +02:00
UsrDat - > Roles . InCrss = - 1 ; // Force roles to be got from database
2016-12-17 21:36:57 +01:00
Rol_GetRolesInAllCrssIfNotYetGot ( UsrDat ) ; // Get roles
2017-07-02 20:36:15 +02:00
/***** Create notification for this user.
If this user wants to receive notifications by email ,
activate the sending of a notification * * * * */
Enr_NotifyAfterEnrolment ( UsrDat , NewRole ) ;
2014-12-12 20:25:00 +01:00
}
2014-12-12 18:52:06 +01:00
/*****************************************************************************/
/*********************** Register user in current course *********************/
/*****************************************************************************/
// Before calling this function, you must be sure that
// the user does not belong to the current course
void Enr_RegisterUsrInCurrentCrs ( struct UsrData * UsrDat , Rol_Role_t NewRole ,
Enr_KeepOrSetAccepted_t KeepOrSetAccepted )
{
extern const char * Usr_StringsUsrListTypeInDB [ Usr_NUM_USR_LIST_TYPES ] ;
/***** Check if user's role is allowed *****/
2015-09-17 20:41:31 +02:00
switch ( NewRole )
{
2017-05-18 19:13:41 +02:00
case Rol_STD :
2017-05-21 21:23:13 +02:00
case Rol_NET :
2017-05-18 19:13:41 +02:00
case Rol_TCH :
2015-09-17 20:41:31 +02:00
break ;
default :
Lay_ShowErrorAndExit ( " Wrong role. " ) ;
}
2014-12-12 18:52:06 +01:00
/***** Register user in current course in database *****/
2018-11-02 19:37:11 +01:00
DB_QueryINSERT ( " can not register user in course " ,
" INSERT INTO crs_usr "
" (CrsCod,UsrCod,Role,Accepted, "
" LastDowGrpCod,LastComGrpCod,LastAssGrpCod, "
" NumAccTst,LastAccTst,NumQstsLastTst, "
" UsrListType,ColsClassPhoto,ListWithPhotos) "
" VALUES "
" (%ld,%ld,%u,'%c', "
" -1,-1,-1, "
" 0,FROM_UNIXTIME(%ld),0, "
" '%s',%u,'%c') " ,
Gbl . CurrentCrs . Crs . CrsCod , UsrDat - > UsrCod , ( unsigned ) NewRole ,
KeepOrSetAccepted = = Enr_SET_ACCEPTED_TO_TRUE ? ' Y ' :
' N ' ,
( long ) ( time_t ) 0 , // The user never accessed to tests in this course
Usr_StringsUsrListTypeInDB [ Usr_SHOW_USRS_TYPE_DEFAULT ] ,
Usr_CLASS_PHOTO_COLS_DEF ,
Usr_LIST_WITH_PHOTOS_DEF ? ' Y ' :
' N ' ) ;
2017-07-02 20:36:15 +02:00
/***** Flush caches *****/
Usr_FlushCachesUsr ( ) ;
/***** Set roles *****/
2017-06-23 15:12:49 +02:00
UsrDat - > Roles . InCurrentCrs . Role = NewRole ;
UsrDat - > Roles . InCurrentCrs . Valid = true ;
2017-06-08 15:32:33 +02:00
UsrDat - > Roles . InCrss = - 1 ; // Force roles to be got from database
2016-12-13 13:32:19 +01:00
Rol_GetRolesInAllCrssIfNotYetGot ( UsrDat ) ; // Get roles
2014-12-12 18:52:06 +01:00
2014-12-12 22:39:55 +01:00
/***** Create notification for this user.
2016-11-16 23:19:52 +01:00
If this user wants to receive notifications by email ,
2014-12-12 22:39:55 +01:00
activate the sending of a notification * * * * */
2017-03-30 11:20:06 +02:00
Enr_NotifyAfterEnrolment ( UsrDat , NewRole ) ;
2014-12-12 18:52:06 +01:00
}
2015-09-17 20:41:31 +02:00
/*****************************************************************************/
/********* Create notification after register user in current course *********/
/*****************************************************************************/
2017-03-30 11:20:06 +02:00
static void Enr_NotifyAfterEnrolment ( struct UsrData * UsrDat , Rol_Role_t NewRole )
2015-09-17 20:41:31 +02:00
{
bool CreateNotif ;
bool NotifyByEmail ;
Ntf_NotifyEvent_t NotifyEvent ;
2018-10-10 23:56:42 +02:00
bool ItsMe = Usr_ItsMe ( UsrDat - > UsrCod ) ;
2015-09-17 20:41:31 +02:00
/***** Check if user's role is allowed *****/
switch ( NewRole )
{
2017-05-18 19:13:41 +02:00
case Rol_STD :
2017-05-21 18:08:35 +02:00
NotifyEvent = Ntf_EVENT_ENROLMENT_STD ;
2015-09-17 20:41:31 +02:00
break ;
2017-05-21 21:23:13 +02:00
case Rol_NET :
2017-06-04 18:18:54 +02:00
NotifyEvent = Ntf_EVENT_ENROLMENT_NET ;
2017-05-21 18:52:02 +02:00
break ;
2017-05-18 19:13:41 +02:00
case Rol_TCH :
2017-05-21 18:08:35 +02:00
NotifyEvent = Ntf_EVENT_ENROLMENT_TCH ;
2015-09-17 20:41:31 +02:00
break ;
default :
NotifyEvent = Ntf_EVENT_UNKNOWN ;
Lay_ShowErrorAndExit ( " Wrong role. " ) ;
}
2017-03-30 11:20:06 +02:00
/***** Remove possible enrolment request ******/
Enr_RemoveEnrolmentRequest ( Gbl . CurrentCrs . Crs . CrsCod , UsrDat - > UsrCod ) ;
2015-09-17 20:41:31 +02:00
2017-03-30 11:20:06 +02:00
/***** Remove old enrolment notifications before inserting the new one ******/
2017-05-21 18:08:35 +02:00
Ntf_MarkNotifToOneUsrAsRemoved ( Ntf_EVENT_ENROLMENT_STD , - 1 , UsrDat - > UsrCod ) ;
2017-06-04 18:18:54 +02:00
Ntf_MarkNotifToOneUsrAsRemoved ( Ntf_EVENT_ENROLMENT_NET , - 1 , UsrDat - > UsrCod ) ;
2017-05-21 18:08:35 +02:00
Ntf_MarkNotifToOneUsrAsRemoved ( Ntf_EVENT_ENROLMENT_TCH , - 1 , UsrDat - > UsrCod ) ;
2015-09-17 20:41:31 +02:00
/***** Create new notification ******/
CreateNotif = ( UsrDat - > Prefs . NotifNtfEvents & ( 1 < < NotifyEvent ) ) ;
2018-10-10 23:56:42 +02:00
NotifyByEmail = CreateNotif & & ! ItsMe & &
2015-09-17 20:41:31 +02:00
( UsrDat - > Prefs . EmailNtfEvents & ( 1 < < NotifyEvent ) ) ;
if ( CreateNotif )
Ntf_StoreNotifyEventToOneUser ( NotifyEvent , UsrDat , - 1L ,
( Ntf_Status_t ) ( NotifyByEmail ? Ntf_STATUS_BIT_EMAIL :
0 ) ) ;
}
2014-12-12 18:52:06 +01:00
/*****************************************************************************/
2017-09-20 17:25:00 +02:00
/****** Write a form to request another user's ID, @nickname or email ********/
2014-12-12 18:52:06 +01:00
/*****************************************************************************/
2017-09-20 17:25:00 +02:00
void Enr_WriteFormToReqAnotherUsrID ( Act_Action_t NextAction , void ( * FuncParams ) ( ) )
2014-12-12 18:52:06 +01:00
{
2019-02-22 21:47:50 +01:00
extern const char * The_ClassFormInBox [ The_NUM_THEMES ] ;
2014-12-12 22:39:55 +01:00
extern const char * Txt_nick_email_or_ID ;
extern const char * Txt_Continue ;
2014-12-12 18:52:06 +01:00
2016-11-16 23:19:52 +01:00
/***** Form to request user's ID, @nickname or email address *****/
2018-11-09 20:47:39 +01:00
Frm_StartForm ( NextAction ) ;
2017-09-20 17:25:00 +02:00
if ( FuncParams )
FuncParams ( ) ;
2018-10-16 21:56:01 +02:00
fprintf ( Gbl . F . Out , " <label for= \" OtherUsrIDNickOrEMail \" "
" class= \" %s RIGHT_MIDDLE \" > "
2016-12-20 02:18:50 +01:00
" %s: "
2018-10-16 21:56:01 +02:00
" </label> "
" <input type= \" text \" id= \" OtherUsrIDNickOrEMail \" "
" name= \" OtherUsrIDNickOrEMail \" "
" size= \" 18 \" maxlength= \" %u \" required= \" required \" /> " ,
2019-02-22 21:47:50 +01:00
The_ClassFormInBox [ Gbl . Prefs . Theme ] ,
2014-12-12 22:39:55 +01:00
Txt_nick_email_or_ID ,
2017-03-13 13:17:53 +01:00
Cns_MAX_CHARS_EMAIL_ADDRESS ) ;
2014-12-12 18:52:06 +01:00
2014-12-12 22:39:55 +01:00
/***** Send button*****/
2017-06-11 19:02:40 +02:00
Btn_PutConfirmButton ( Txt_Continue ) ;
2018-11-09 20:47:39 +01:00
Frm_EndForm ( ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
/****** Request acceptation / refusion of register in current course *********/
/*****************************************************************************/
void Enr_ReqAcceptRegisterInCrs ( void )
{
2017-03-30 15:20:25 +02:00
extern const char * Hlp_USERS_SignUp_confirm_enrolment ;
2017-03-30 11:20:06 +02:00
extern const char * Txt_Enrolment ;
extern const char * Txt_A_teacher_or_administrator_has_enroled_you_as_X_into_the_course_Y ;
2017-01-19 18:55:21 +01:00
extern const char * Txt_ROLES_SINGUL_abc [ Rol_NUM_ROLES ] [ Usr_NUM_SEXS ] ;
2017-03-30 11:20:06 +02:00
extern const char * Txt_Confirm_my_enrolment ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_Remove_me_from_this_course ;
2017-05-21 18:52:02 +02:00
Ntf_NotifyEvent_t NotifyEvent ;
2014-12-12 18:52:06 +01:00
2017-06-12 14:16:33 +02:00
/***** Start box *****/
2017-06-10 21:38:10 +02:00
Box_StartBox ( NULL , Txt_Enrolment , NULL ,
2017-06-12 15:03:29 +02:00
Hlp_USERS_SignUp_confirm_enrolment , Box_NOT_CLOSABLE ) ;
2016-04-05 14:04:23 +02:00
2014-12-12 18:52:06 +01:00
/***** Show message *****/
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_INFO , Txt_A_teacher_or_administrator_has_enroled_you_as_X_into_the_course_Y ,
2019-02-16 01:20:54 +01:00
Txt_ROLES_SINGUL_abc [ Gbl . Usrs . Me . UsrDat . Roles . InCurrentCrs . Role ] [ Gbl . Usrs . Me . UsrDat . Sex ] ,
Gbl . CurrentCrs . Crs . FullName ) ;
2014-12-12 18:52:06 +01:00
/***** Send button to accept register in the current course *****/
2017-06-08 15:32:33 +02:00
switch ( Gbl . Usrs . Me . UsrDat . Roles . InCurrentCrs . Role )
2017-05-21 18:52:02 +02:00
{
case Rol_STD :
2018-11-09 20:47:39 +01:00
Frm_StartForm ( ActAccEnrStd ) ;
2017-05-21 18:52:02 +02:00
break ;
2017-05-21 21:23:13 +02:00
case Rol_NET :
2018-11-09 20:47:39 +01:00
Frm_StartForm ( ActAccEnrNET ) ;
2017-05-21 18:52:02 +02:00
break ;
case Rol_TCH :
2018-11-09 20:47:39 +01:00
Frm_StartForm ( ActAccEnrTch ) ;
2017-05-21 18:52:02 +02:00
break ;
default :
Lay_ShowErrorAndExit ( " Wrong role. " ) ;
}
2017-06-11 19:02:40 +02:00
Btn_PutCreateButtonInline ( Txt_Confirm_my_enrolment ) ;
2018-11-09 20:47:39 +01:00
Frm_EndForm ( ) ;
2014-12-12 18:52:06 +01:00
/***** Send button to refuse register in the current course *****/
2017-06-08 15:32:33 +02:00
switch ( Gbl . Usrs . Me . UsrDat . Roles . InCurrentCrs . Role )
2017-05-21 18:52:02 +02:00
{
case Rol_STD :
2018-11-09 20:47:39 +01:00
Frm_StartForm ( ActRemMe_Std ) ;
2017-05-21 18:52:02 +02:00
break ;
2017-05-21 21:23:13 +02:00
case Rol_NET :
2018-11-09 20:47:39 +01:00
Frm_StartForm ( ActRemMe_NET ) ;
2017-05-21 18:52:02 +02:00
break ;
case Rol_TCH :
2018-11-09 20:47:39 +01:00
Frm_StartForm ( ActRemMe_Tch ) ;
2017-05-21 18:52:02 +02:00
break ;
default :
Lay_ShowErrorAndExit ( " Wrong role. " ) ;
}
2017-06-11 19:02:40 +02:00
Btn_PutRemoveButtonInline ( Txt_Remove_me_from_this_course ) ;
2018-11-09 20:47:39 +01:00
Frm_EndForm ( ) ;
2015-04-02 14:22:21 +02:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2017-06-10 21:38:10 +02:00
Box_EndBox ( ) ;
2014-12-12 18:52:06 +01:00
/***** Mark possible notification as seen *****/
2017-06-08 15:32:33 +02:00
switch ( Gbl . Usrs . Me . UsrDat . Roles . InCurrentCrs . Role )
2017-05-21 18:52:02 +02:00
{
case Rol_STD :
NotifyEvent = Ntf_EVENT_ENROLMENT_STD ;
break ;
2017-05-21 21:23:13 +02:00
case Rol_NET :
2017-06-04 18:18:54 +02:00
NotifyEvent = Ntf_EVENT_ENROLMENT_NET ;
2017-05-21 18:52:02 +02:00
break ;
case Rol_TCH :
NotifyEvent = Ntf_EVENT_ENROLMENT_TCH ;
break ;
default :
NotifyEvent = Ntf_EVENT_UNKNOWN ;
Lay_ShowErrorAndExit ( " Wrong role. " ) ;
break ;
}
Ntf_MarkNotifAsSeen ( NotifyEvent , - 1L , Gbl . CurrentCrs . Crs . CrsCod ,
2016-04-05 14:04:23 +02:00
Gbl . Usrs . Me . UsrDat . UsrCod ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
2017-03-30 11:20:06 +02:00
/****************** Put an enrolment into a notification ********************/
2014-12-12 18:52:06 +01:00
/*****************************************************************************/
2017-03-30 11:20:06 +02:00
void Enr_GetNotifEnrolment ( char SummaryStr [ Ntf_MAX_BYTES_SUMMARY + 1 ] ,
long CrsCod , long UsrCod )
2014-12-12 18:52:06 +01:00
{
2015-03-12 14:45:40 +01:00
extern const char * Txt_ROLES_SINGUL_Abc [ Rol_NUM_ROLES ] [ Usr_NUM_SEXS ] ;
2014-12-12 18:52:06 +01:00
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
struct UsrData UsrDat ;
Rol_Role_t Role ;
SummaryStr [ 0 ] = ' \0 ' ; // Return nothing on error
2018-10-20 21:19:30 +02:00
// This function may be called inside a web service, so don't report error
2014-12-12 18:52:06 +01:00
/***** Get user's role in course from database *****/
2018-10-30 17:47:57 +01:00
if ( DB_QuerySELECT ( & mysql_res , " can not get user's role "
" in course " ,
" SELECT Role "
" FROM crs_usr "
" WHERE CrsCod=%ld AND UsrCod=%ld " ,
CrsCod , UsrCod ) = = 1 ) // Result should have a unique row
2018-10-20 21:19:30 +02:00
{
/***** Get user's role in course *****/
row = mysql_fetch_row ( mysql_res ) ;
2014-12-12 18:52:06 +01:00
2018-10-20 21:19:30 +02:00
/* Initialize structure with user's data */
Usr_UsrDataConstructor ( & UsrDat ) ;
2014-12-12 18:52:06 +01:00
2018-10-20 21:19:30 +02:00
/* Get user's data */
UsrDat . UsrCod = UsrCod ;
Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod ( & UsrDat ) ;
2014-12-12 18:52:06 +01:00
2018-10-20 21:19:30 +02:00
/* Role (row[0]) */
Role = Rol_ConvertUnsignedStrToRole ( row [ 0 ] ) ;
Str_Copy ( SummaryStr , Txt_ROLES_SINGUL_Abc [ Role ] [ UsrDat . Sex ] ,
Ntf_MAX_BYTES_SUMMARY ) ;
2014-12-12 18:52:06 +01:00
2018-10-20 21:19:30 +02:00
/* Free memory used for user's data */
Usr_UsrDataDestructor ( & UsrDat ) ;
}
2014-12-12 18:52:06 +01:00
2018-10-20 21:19:30 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult ( & mysql_res ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
/***************************** Update user's data ****************************/
/*****************************************************************************/
// UsrDat->UsrCod must be > 0
void Enr_UpdateUsrData ( struct UsrData * UsrDat )
{
extern const char * Usr_StringsSexDB [ Usr_NUM_SEXS ] ;
2017-01-15 22:58:26 +01:00
char BirthdayStrDB [ Usr_BIRTHDAY_STR_DB_LENGTH + 1 ] ;
2014-12-12 18:52:06 +01:00
/***** Check if user's code is initialized *****/
if ( UsrDat - > UsrCod < = 0 )
Lay_ShowErrorAndExit ( " Can not update user's data. Wrong user's code. " ) ;
/***** Filter some user's data before updating */
Enr_FilterUsrDat ( UsrDat ) ;
/***** Update user's common data *****/
2018-10-08 12:37:29 +02:00
Usr_CreateBirthdayStrDB ( UsrDat , BirthdayStrDB ) ; // It can include start and ending apostrophes
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ( " can not update user's data " ,
" UPDATE usr_data "
" SET Password='%s', "
" Surname1='%s',Surname2='%s',FirstName='%s',Sex='%s', "
" CtyCod=%ld, "
" LocalAddress='%s',LocalPhone='%s', "
" FamilyAddress='%s',FamilyPhone='%s', "
" OriginPlace='%s',Birthday=%s, "
" Comments='%s' "
" WHERE UsrCod=%ld " ,
UsrDat - > Password ,
UsrDat - > Surname1 , UsrDat - > Surname2 , UsrDat - > FirstName ,
Usr_StringsSexDB [ UsrDat - > Sex ] ,
UsrDat - > CtyCod ,
UsrDat - > LocalAddress , UsrDat - > LocalPhone ,
UsrDat - > FamilyAddress , UsrDat - > FamilyPhone ,
UsrDat - > OriginPlace ,
BirthdayStrDB ,
UsrDat - > Comments ? UsrDat - > Comments :
" " ,
UsrDat - > UsrCod ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
/************************* Filter some user's data ***************************/
/*****************************************************************************/
2014-12-12 22:39:55 +01:00
void Enr_FilterUsrDat ( struct UsrData * UsrDat )
2014-12-12 18:52:06 +01:00
{
/***** Fix birthday *****/
if ( UsrDat - > Birthday . Year < Gbl . Now . Date . Year - 99 | |
UsrDat - > Birthday . Year > Gbl . Now . Date . Year - 16 )
2016-05-01 01:52:35 +02:00
UsrDat - > Birthday . Year =
2014-12-12 18:52:06 +01:00
UsrDat - > Birthday . Month =
2016-05-01 01:52:35 +02:00
UsrDat - > Birthday . Day = 0 ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
/**************** Update institution, centre and department ******************/
/*****************************************************************************/
void Enr_UpdateInstitutionCentreDepartment ( void )
{
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ( " can not update institution, centre and department " ,
" UPDATE usr_data "
" SET InsCtyCod=%ld,InsCod=%ld,CtrCod=%ld,DptCod=%ld "
" WHERE UsrCod=%ld " ,
Gbl . Usrs . Me . UsrDat . InsCtyCod ,
Gbl . Usrs . Me . UsrDat . InsCod ,
Gbl . Usrs . Me . UsrDat . Tch . CtrCod ,
Gbl . Usrs . Me . UsrDat . Tch . DptCod ,
Gbl . Usrs . Me . UsrDat . UsrCod ) ;
2014-12-12 18:52:06 +01:00
}
2014-12-31 02:46:20 +01:00
/*****************************************************************************/
/************** Form to request the user's ID of another user ****************/
/*****************************************************************************/
2015-09-14 09:50:55 +02:00
void Enr_ReqAdminStds ( void )
{
2017-05-18 19:13:41 +02:00
Enr_ReqAdminUsrs ( Rol_STD ) ;
2015-09-14 09:50:55 +02:00
}
2017-05-21 19:25:46 +02:00
void Enr_ReqAdminNonEditingTchs ( void )
{
2017-05-21 21:23:13 +02:00
Enr_ReqAdminUsrs ( Rol_NET ) ;
2017-05-21 19:25:46 +02:00
}
2015-09-14 09:50:55 +02:00
void Enr_ReqAdminTchs ( void )
{
2017-05-18 19:13:41 +02:00
Enr_ReqAdminUsrs ( Rol_TCH ) ;
2015-09-14 09:50:55 +02:00
}
static void Enr_ReqAdminUsrs ( Rol_Role_t Role )
2014-12-31 02:46:20 +01:00
{
2017-06-04 18:18:54 +02:00
switch ( Gbl . Usrs . Me . Role . Logged )
2014-12-31 02:46:20 +01:00
{
2017-05-18 19:13:41 +02:00
case Rol_GST :
case Rol_STD :
2017-05-21 21:23:13 +02:00
case Rol_NET :
Enr_AskIfRegRemMe ( Role ) ;
2014-12-31 02:46:20 +01:00
break ;
2017-05-18 19:13:41 +02:00
case Rol_TCH :
2015-09-14 17:25:21 +02:00
if ( Gbl . CurrentCrs . Crs . CrsCod > 0 & &
2017-05-18 19:13:41 +02:00
Role = = Rol_STD )
Enr_ShowFormRegRemSeveralUsrs ( Rol_STD ) ;
2014-12-31 02:46:20 +01:00
else
2017-05-18 19:13:41 +02:00
Enr_AskIfRegRemMe ( Rol_TCH ) ;
2014-12-31 02:46:20 +01:00
break ;
2015-04-07 21:44:24 +02:00
case Rol_DEG_ADM :
case Rol_CTR_ADM :
case Rol_INS_ADM :
case Rol_SYS_ADM :
2014-12-31 02:46:20 +01:00
if ( Gbl . CurrentCrs . Crs . CrsCod > 0 )
2015-09-14 09:32:27 +02:00
Enr_ShowFormRegRemSeveralUsrs ( Role ) ;
2014-12-31 02:46:20 +01:00
else
2015-09-14 09:50:55 +02:00
Enr_ReqAnotherUsrIDToRegisterRemove ( Role ) ;
2014-12-31 02:46:20 +01:00
break ;
default :
2019-02-16 20:44:31 +01:00
Lay_NoPermissionExit ( ) ;
2014-12-31 02:46:20 +01:00
break ;
}
}
2014-12-12 18:52:06 +01:00
/*****************************************************************************/
/***** Register/remove users (taken from a list) in/from current course ******/
/*****************************************************************************/
2015-09-14 09:32:27 +02:00
static void Enr_ShowFormRegRemSeveralUsrs ( Rol_Role_t Role )
2014-12-12 18:52:06 +01:00
{
2017-01-31 00:25:10 +01:00
extern const char * Hlp_USERS_Administration_administer_multiple_users ;
2014-12-12 18:52:06 +01:00
extern const char * The_ClassTitle [ The_NUM_THEMES ] ;
2017-01-31 00:25:10 +01:00
extern const char * Txt_Administer_multiple_students ;
2017-05-21 21:23:13 +02:00
extern const char * Txt_Administer_multiple_non_editing_teachers ;
2017-01-31 00:25:10 +01:00
extern const char * Txt_Administer_multiple_teachers ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_Step_1_Provide_a_list_of_users ;
extern const char * Txt_Type_or_paste_a_list_of_IDs_nicks_or_emails_ ;
2015-09-14 10:47:39 +02:00
extern const char * Txt_Step_2_Select_the_desired_action ;
extern const char * Txt_Step_3_Optionally_select_groups ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_Select_the_groups_in_from_which_you_want_to_register_remove_users_ ;
extern const char * Txt_No_groups_have_been_created_in_the_course_X_Therefore_ ;
2017-03-30 11:20:06 +02:00
extern const char * Txt_Step_4_Confirm_the_enrolment_removing ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_Confirm ;
2017-05-21 21:23:13 +02:00
Act_Action_t NextAction ;
const char * Title ;
2014-12-12 18:52:06 +01:00
2015-02-08 19:11:54 +01:00
/***** Put contextual links *****/
2017-05-29 22:07:43 +02:00
if ( Gbl . CurrentCrs . Crs . CrsCod > 0 ) // Course selected
2015-09-14 09:50:55 +02:00
{
fprintf ( Gbl . F . Out , " <div class= \" CONTEXT_MENU \" > " ) ;
2014-12-12 18:52:06 +01:00
2017-05-29 22:07:43 +02:00
switch ( Role )
{
case Rol_STD :
/* Put link to go to admin student */
Enr_PutLinkToAdminOneUsr ( ActReqMdfOneStd ) ;
/* Put link to remove all the students in the current course */
if ( Gbl . CurrentCrs . Crs . NumUsrs [ Rol_STD ] ) // This course has students
Enr_PutLinkToRemAllStdsThisCrs ( ) ;
break ;
case Rol_NET :
/* Put link to go to admin teacher */
Enr_PutLinkToAdminOneUsr ( ActReqMdfOneTch ) ;
break ;
case Rol_TCH :
/* Put link to go to admin teacher */
Enr_PutLinkToAdminOneUsr ( ActReqMdfOneTch ) ;
break ;
default :
NextAction = ActUnk ;
Title = NULL ;
Lay_ShowErrorAndExit ( " Wrong role. " ) ;
break ;
}
2015-02-08 19:11:54 +01:00
2015-09-14 09:50:55 +02:00
fprintf ( Gbl . F . Out , " </div> " ) ;
}
2014-12-12 18:52:06 +01:00
2017-03-30 11:20:06 +02:00
/***** Form to send students to be enroled / removed *****/
2017-05-21 21:23:13 +02:00
switch ( Role )
{
case Rol_STD :
NextAction = ActRcvFrmEnrSevStd ;
Title = Txt_Administer_multiple_students ;
break ;
case Rol_NET :
NextAction = ActRcvFrmEnrSevNET ;
Title = Txt_Administer_multiple_non_editing_teachers ;
break ;
case Rol_TCH :
NextAction = ActRcvFrmEnrSevTch ;
Title = Txt_Administer_multiple_teachers ;
break ;
default :
NextAction = ActUnk ;
Title = NULL ;
Lay_ShowErrorAndExit ( " Wrong role. " ) ;
break ;
}
2018-11-09 20:47:39 +01:00
Frm_StartForm ( NextAction ) ;
2015-04-11 23:46:21 +02:00
2017-06-12 14:16:33 +02:00
/***** Start box *****/
2017-06-10 21:38:10 +02:00
Box_StartBox ( NULL , Title , NULL ,
2017-06-12 15:03:29 +02:00
Hlp_USERS_Administration_administer_multiple_users , Box_NOT_CLOSABLE ) ;
2015-02-08 18:39:58 +01:00
2017-03-30 11:20:06 +02:00
/***** Step 1: List of students to be enroled / removed *****/
2015-08-01 08:40:58 +02:00
fprintf ( Gbl . F . Out , " <div class= \" %s LEFT_MIDDLE \" > "
2015-02-08 18:39:58 +01:00
" %s "
2014-12-26 17:55:42 +01:00
" </div> " ,
2014-12-12 18:52:06 +01:00
The_ClassTitle [ Gbl . Prefs . Theme ] ,
Txt_Step_1_Provide_a_list_of_users ) ;
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_INFO , Txt_Type_or_paste_a_list_of_IDs_nicks_or_emails_ ) ;
2014-12-12 18:52:06 +01:00
Enr_PutAreaToEnterUsrsIDs ( ) ;
2015-09-14 10:47:39 +02:00
/***** Step 2: Put different actions to register/remove users to/from current course *****/
2015-08-01 08:40:58 +02:00
fprintf ( Gbl . F . Out , " <div class= \" %s LEFT_MIDDLE \" > "
2015-02-08 18:39:58 +01:00
" %s "
2014-12-26 17:55:42 +01:00
" </div> " ,
2014-12-12 18:52:06 +01:00
The_ClassTitle [ Gbl . Prefs . Theme ] ,
2015-09-14 10:47:39 +02:00
Txt_Step_2_Select_the_desired_action ) ;
2014-12-12 18:52:06 +01:00
Enr_PutActionsRegRemSeveralUsrs ( ) ;
2015-09-14 10:47:39 +02:00
/***** Step 3: Select groups in which register / remove users *****/
2015-08-01 08:40:58 +02:00
fprintf ( Gbl . F . Out , " <div class= \" %s LEFT_MIDDLE \" > "
2015-02-08 18:39:58 +01:00
" %s "
2014-12-26 17:55:42 +01:00
" </div> " ,
2014-12-12 18:52:06 +01:00
The_ClassTitle [ Gbl . Prefs . Theme ] ,
2015-09-14 10:47:39 +02:00
Txt_Step_3_Optionally_select_groups ) ;
2014-12-12 18:52:06 +01:00
if ( Gbl . CurrentCrs . Crs . CrsCod > 0 ) // Course selected
{
if ( Gbl . CurrentCrs . Grps . NumGrps ) // This course has groups?
{
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_INFO , Txt_Select_the_groups_in_from_which_you_want_to_register_remove_users_ ) ;
2014-12-12 18:52:06 +01:00
Grp_ShowLstGrpsToChgOtherUsrsGrps ( - 1L ) ;
}
else
/* Write help message */
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_INFO , Txt_No_groups_have_been_created_in_the_course_X_Therefore_ ,
2019-02-16 01:20:54 +01:00
Gbl . CurrentCrs . Crs . FullName ) ;
2014-12-12 18:52:06 +01:00
}
2015-09-14 10:47:39 +02:00
/***** Step 4: Confirm register / remove students *****/
2015-08-01 08:40:58 +02:00
fprintf ( Gbl . F . Out , " <div class= \" %s LEFT_MIDDLE \" > "
2015-02-08 18:39:58 +01:00
" %s "
2014-12-26 17:55:42 +01:00
" </div> " ,
2014-12-12 18:52:06 +01:00
The_ClassTitle [ Gbl . Prefs . Theme ] ,
2017-03-30 11:20:06 +02:00
Txt_Step_4_Confirm_the_enrolment_removing ) ;
2014-12-12 18:52:06 +01:00
Pwd_AskForConfirmationOnDangerousAction ( ) ;
2017-06-12 14:16:33 +02:00
/***** Send button and end box *****/
2017-06-11 19:02:40 +02:00
Box_EndBoxWithButton ( Btn_CONFIRM_BUTTON , Txt_Confirm ) ;
2015-04-11 23:46:21 +02:00
2017-06-12 14:16:33 +02:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ( ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
/******************** Put a link (form) to remove old users ******************/
/*****************************************************************************/
2015-09-12 14:12:40 +02:00
void Enr_PutLinkToRemOldUsrs ( void )
2014-12-12 18:52:06 +01:00
{
2015-10-07 23:21:10 +02:00
extern const char * Txt_Eliminate_old_users ;
2014-12-12 18:52:06 +01:00
/***** Put form to remove old users *****/
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkIconText ( ActReqRemOldUsr , NULL , NULL ,
" trash.svg " ,
Txt_Eliminate_old_users ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
/*********************** Write form to remove old users **********************/
/*****************************************************************************/
void Enr_AskRemoveOldUsrs ( void )
{
2019-02-22 21:47:50 +01:00
extern const char * The_ClassFormInBox [ The_NUM_THEMES ] ;
2015-10-07 23:21:10 +02:00
extern const char * Txt_Eliminate_old_users ;
2017-03-30 11:20:06 +02:00
extern const char * Txt_Eliminate_all_users_who_are_not_enroled_on_any_courses_PART_1_OF_2 ;
extern const char * Txt_Eliminate_all_users_who_are_not_enroled_on_any_courses_PART_2_OF_2 ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_Eliminate ;
2014-12-12 22:39:55 +01:00
unsigned Months ;
2014-12-12 18:52:06 +01:00
2015-10-07 23:21:10 +02:00
/***** Start form *****/
2018-11-09 20:47:39 +01:00
Frm_StartForm ( ActRemOldUsr ) ;
2015-10-07 23:21:10 +02:00
2017-06-12 14:16:33 +02:00
/***** Start box *****/
2017-06-10 21:38:10 +02:00
Box_StartBox ( NULL , Txt_Eliminate_old_users , NULL ,
2017-06-12 15:03:29 +02:00
NULL , Box_NOT_CLOSABLE ) ;
2015-10-07 23:21:10 +02:00
/***** Form to request number of months without clicks *****/
2016-12-27 16:45:37 +01:00
fprintf ( Gbl . F . Out , " <label class= \" %s \" >%s " ,
2019-02-22 21:47:50 +01:00
The_ClassFormInBox [ Gbl . Prefs . Theme ] ,
2017-03-30 11:20:06 +02:00
Txt_Eliminate_all_users_who_are_not_enroled_on_any_courses_PART_1_OF_2 ) ;
2014-12-12 18:52:06 +01:00
fprintf ( Gbl . F . Out , " <select name= \" Months \" > " ) ;
2014-12-12 22:39:55 +01:00
for ( Months = Usr_MIN_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_USRS ;
Months < = Usr_MAX_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_USRS ;
Months + + )
2014-12-12 18:52:06 +01:00
{
fprintf ( Gbl . F . Out , " <option " ) ;
2015-12-21 11:07:54 +01:00
if ( Months = = Usr_DEF_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_USRS )
2014-12-12 18:52:06 +01:00
fprintf ( Gbl . F . Out , " selected= \" selected \" " ) ;
2014-12-12 22:39:55 +01:00
fprintf ( Gbl . F . Out , " >%u</option> " , Months ) ;
2014-12-12 18:52:06 +01:00
}
2016-12-27 16:45:37 +01:00
fprintf ( Gbl . F . Out , " </select> " ) ;
2017-03-30 11:20:06 +02:00
fprintf ( Gbl . F . Out , Txt_Eliminate_all_users_who_are_not_enroled_on_any_courses_PART_2_OF_2 ,
2014-12-12 18:52:06 +01:00
Cfg_PLATFORM_SHORT_NAME ) ;
2016-12-27 16:45:37 +01:00
fprintf ( Gbl . F . Out , " </label> " ) ;
2014-12-12 18:52:06 +01:00
2017-06-12 14:16:33 +02:00
/***** Send button and end box *****/
2017-06-11 19:02:40 +02:00
Box_EndBoxWithButton ( Btn_REMOVE_BUTTON , Txt_Eliminate ) ;
2015-10-07 23:21:10 +02:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ( ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
/******************************* Remove old users ****************************/
/*****************************************************************************/
void Enr_RemoveOldUsrs ( void )
{
2017-03-30 11:20:06 +02:00
extern const char * Txt_Eliminating_X_users_who_were_not_enroled_in_any_course_and_with_more_than_Y_months_without_access_to_Z ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_X_users_have_been_eliminated ;
unsigned MonthsWithoutAccess ;
2015-12-21 11:07:54 +01:00
time_t SecondsWithoutAccess ;
2014-12-12 18:52:06 +01:00
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
unsigned long NumUsr ;
unsigned long NumUsrs ;
unsigned NumUsrsEliminated = 0 ;
struct UsrData UsrDat ;
/***** Get parameter with number of months without access *****/
2017-01-29 21:41:08 +01:00
MonthsWithoutAccess = ( unsigned )
Par_GetParToUnsignedLong ( " Months " ,
Usr_MIN_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_USRS ,
Usr_MAX_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_USRS ,
( unsigned long ) UINT_MAX ) ;
2017-01-29 12:42:19 +01:00
if ( MonthsWithoutAccess = = UINT_MAX )
2015-12-21 11:07:54 +01:00
Lay_ShowErrorAndExit ( " Wrong number of months. " ) ;
SecondsWithoutAccess = ( time_t ) MonthsWithoutAccess * Dat_SECONDS_IN_ONE_MONTH ;
2014-12-12 18:52:06 +01:00
/***** Get old users from database *****/
2018-10-30 17:47:57 +01:00
NumUsrs = DB_QuerySELECT ( & mysql_res , " can not get old users " ,
" SELECT UsrCod FROM "
" ( "
" SELECT UsrCod FROM usr_last WHERE "
2019-02-13 13:32:11 +01:00
" LastTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu) "
2018-10-30 17:47:57 +01:00
" UNION "
" SELECT UsrCod FROM usr_data WHERE "
" UsrCod NOT IN (SELECT UsrCod FROM usr_last) "
" ) AS candidate_usrs "
" WHERE UsrCod NOT IN (SELECT DISTINCT UsrCod FROM crs_usr) " ,
( unsigned long ) SecondsWithoutAccess ) ;
if ( NumUsrs )
2014-12-12 18:52:06 +01:00
{
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_INFO , Txt_Eliminating_X_users_who_were_not_enroled_in_any_course_and_with_more_than_Y_months_without_access_to_Z ,
2019-02-16 01:20:54 +01:00
NumUsrs ,
MonthsWithoutAccess ,
Cfg_PLATFORM_SHORT_NAME ) ;
2014-12-12 18:52:06 +01:00
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor ( & UsrDat ) ;
/***** Remove users *****/
for ( NumUsr = 0 ;
NumUsr < NumUsrs ;
NumUsr + + )
{
row = mysql_fetch_row ( mysql_res ) ;
UsrDat . UsrCod = Str_ConvertStrCodToLongCod ( row [ 0 ] ) ;
if ( Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod ( & UsrDat ) ) // If user's data exist...
{
2014-12-12 22:39:55 +01:00
Acc_CompletelyEliminateAccount ( & UsrDat , Cns_QUIET ) ;
2014-12-12 18:52:06 +01:00
NumUsrsEliminated + + ;
}
}
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor ( & UsrDat ) ;
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult ( & mysql_res ) ;
/***** Move unused contents of messages to table of deleted contents of messages *****/
Msg_MoveUnusedMsgsContentToDeleted ( ) ;
}
/***** Write end message *****/
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_SUCCESS , Txt_X_users_have_been_eliminated ,
2019-02-16 01:20:54 +01:00
NumUsrsEliminated ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
2017-03-30 11:20:06 +02:00
/***** Put text area to enter/paste IDs of users to be enroled/removed ******/
2014-12-12 18:52:06 +01:00
/*****************************************************************************/
static void Enr_PutAreaToEnterUsrsIDs ( void )
{
2019-02-22 21:47:50 +01:00
extern const char * The_ClassFormInBox [ The_NUM_THEMES ] ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_List_of_nicks_emails_or_IDs ;
2016-12-26 18:35:52 +01:00
/***** Text area for users' IDs *****/
2017-06-11 20:09:59 +02:00
Tbl_StartTableCenter ( 2 ) ;
2017-05-01 12:36:24 +02:00
fprintf ( Gbl . F . Out , " <tr> "
2016-12-26 18:35:52 +01:00
" <td class= \" RIGHT_TOP \" > "
" <label for= \" UsrsIDs \" class= \" %s \" >%s:</label> "
2014-12-22 21:52:37 +01:00
" </td> "
2015-08-01 08:40:58 +02:00
" <td class= \" LEFT_TOP \" > "
2016-12-26 18:35:52 +01:00
" <textarea id= \" UsrsIDs \" name= \" UsrsIDs \" "
" cols= \" 60 \" rows= \" 10 \" > "
" </textarea> "
2014-12-12 18:52:06 +01:00
" </td> "
2017-05-01 12:36:24 +02:00
" </tr> " ,
2019-02-22 21:47:50 +01:00
The_ClassFormInBox [ Gbl . Prefs . Theme ] ,
2016-12-26 18:35:52 +01:00
Txt_List_of_nicks_emails_or_IDs ) ;
2017-06-11 20:09:59 +02:00
Tbl_EndTable ( ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
/*** Put different actions to register/remove users to/from current course ***/
/*****************************************************************************/
// Returns true if at least one action can be shown
2015-03-29 21:43:33 +02:00
bool Enr_PutActionsRegRemOneUsr ( bool ItsMe )
2014-12-12 18:52:06 +01:00
{
2019-02-22 21:47:50 +01:00
extern const char * The_ClassFormInBox [ The_NUM_THEMES ] ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_Modify_me_in_the_course_X ;
extern const char * Txt_Modify_user_in_the_course_X ;
2016-03-24 20:13:42 +01:00
extern const char * Txt_Register_me_in_X ;
2015-12-16 00:16:32 +01:00
extern const char * Txt_Register_USER_in_the_course_X ;
2016-06-14 23:52:22 +02:00
extern const char * Txt_Report_possible_duplicate_user ;
2015-12-16 00:16:32 +01:00
extern const char * Txt_Register_USER_as_an_administrator_of_the_degree_X ;
extern const char * Txt_Register_USER_as_an_administrator_of_the_centre_X ;
extern const char * Txt_Register_USER_as_an_administrator_of_the_institution_X ;
2018-10-07 18:07:01 +02:00
extern const char * Txt_Remove_me_from_THE_COURSE_X ;
extern const char * Txt_Remove_USER_from_THE_COURSE_X ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_Remove_me_as_an_administrator_of_the_degree_X ;
2015-12-16 00:16:32 +01:00
extern const char * Txt_Remove_USER_as_an_administrator_of_the_degree_X ;
2015-01-31 01:23:39 +01:00
extern const char * Txt_Remove_me_as_an_administrator_of_the_centre_X ;
2015-12-16 00:16:32 +01:00
extern const char * Txt_Remove_USER_as_an_administrator_of_the_centre_X ;
2015-01-31 01:23:39 +01:00
extern const char * Txt_Remove_me_as_an_administrator_of_the_institution_X ;
2015-12-16 00:16:32 +01:00
extern const char * Txt_Remove_USER_as_an_administrator_of_the_institution_X ;
2015-03-28 18:34:08 +01:00
extern const char * Txt_Eliminate_my_user_account ;
extern const char * Txt_Eliminate_user_account ;
2014-12-12 18:52:06 +01:00
unsigned NumOptionsShown = 0 ;
bool UsrBelongsToCrs = false ;
bool UsrIsDegAdmin = false ;
2015-01-31 01:23:39 +01:00
bool UsrIsCtrAdmin = false ;
bool UsrIsInsAdmin = false ;
2014-12-12 18:52:06 +01:00
bool OptionChecked = false ;
/***** Check if the other user belongs to the current course *****/
if ( Gbl . CurrentCrs . Crs . CrsCod > 0 )
2017-06-09 15:04:02 +02:00
UsrBelongsToCrs = Usr_CheckIfUsrBelongsToCurrentCrs ( & Gbl . Usrs . Other . UsrDat ) ;
2014-12-12 18:52:06 +01:00
2015-01-31 01:23:39 +01:00
if ( Gbl . CurrentIns . Ins . InsCod > 0 )
{
/***** Check if the other user is administrator of the current institution *****/
2015-02-01 20:17:24 +01:00
UsrIsInsAdmin = Usr_CheckIfUsrIsAdm ( Gbl . Usrs . Other . UsrDat . UsrCod ,
Sco_SCOPE_INS ,
Gbl . CurrentIns . Ins . InsCod ) ;
2015-01-31 01:23:39 +01:00
if ( Gbl . CurrentCtr . Ctr . CtrCod > 0 )
{
/***** Check if the other user is administrator of the current centre *****/
2015-02-01 20:17:24 +01:00
UsrIsCtrAdmin = Usr_CheckIfUsrIsAdm ( Gbl . Usrs . Other . UsrDat . UsrCod ,
Sco_SCOPE_CTR ,
Gbl . CurrentCtr . Ctr . CtrCod ) ;
2015-01-31 01:23:39 +01:00
if ( Gbl . CurrentDeg . Deg . DegCod > 0 )
/***** Check if the other user is administrator of the current degree *****/
2015-02-01 20:17:24 +01:00
UsrIsDegAdmin = Usr_CheckIfUsrIsAdm ( Gbl . Usrs . Other . UsrDat . UsrCod ,
Sco_SCOPE_DEG ,
Gbl . CurrentDeg . Deg . DegCod ) ;
2015-01-31 01:23:39 +01:00
}
}
2014-12-12 18:52:06 +01:00
/***** Start list of options *****/
2016-12-19 00:55:24 +01:00
fprintf ( Gbl . F . Out , " <ul class= \" LIST_LEFT %s \" style= \" margin:12px; \" > " ,
2019-02-22 21:47:50 +01:00
The_ClassFormInBox [ Gbl . Prefs . Theme ] ) ;
2014-12-12 18:52:06 +01:00
/***** Register user in course / Modify user's data *****/
2014-12-31 02:46:20 +01:00
if ( Gbl . CurrentCrs . Crs . CrsCod > 0 & &
2017-06-04 18:18:54 +02:00
Gbl . Usrs . Me . Role . Logged > = Rol_STD )
2014-12-12 18:52:06 +01:00
{
fprintf ( Gbl . F . Out , " <li> "
2018-10-16 21:56:01 +02:00
" <input type= \" radio \" id= \" RegRemAction%u \" "
" name= \" RegRemAction \" value= \" %u \" " ,
( unsigned ) Enr_REGISTER_MODIFY_ONE_USR_IN_CRS ,
2014-12-12 18:52:06 +01:00
( unsigned ) Enr_REGISTER_MODIFY_ONE_USR_IN_CRS ) ;
if ( ! OptionChecked )
{
fprintf ( Gbl . F . Out , " checked= \" checked \" " ) ;
OptionChecked = true ;
}
2016-12-21 01:51:30 +01:00
fprintf ( Gbl . F . Out , " /> "
2018-10-16 21:56:01 +02:00
" <label for= \" RegRemAction%u \" > " ,
( unsigned ) Enr_REGISTER_MODIFY_ONE_USR_IN_CRS ) ;
fprintf ( Gbl . F . Out ,
UsrBelongsToCrs ? ( ItsMe ? Txt_Modify_me_in_the_course_X :
Txt_Modify_user_in_the_course_X ) :
( ItsMe ? Txt_Register_me_in_X :
Txt_Register_USER_in_the_course_X ) ,
Gbl . CurrentCrs . Crs . ShrtName ) ;
fprintf ( Gbl . F . Out , " </label> "
" </li> " ) ;
2014-12-12 18:52:06 +01:00
NumOptionsShown + + ;
}
2015-01-31 01:23:39 +01:00
if ( Gbl . CurrentIns . Ins . InsCod > 0 )
2014-12-12 18:52:06 +01:00
{
2015-01-31 01:23:39 +01:00
if ( Gbl . CurrentCtr . Ctr . CtrCod > 0 )
2014-12-12 18:52:06 +01:00
{
2015-01-31 01:23:39 +01:00
if ( Gbl . CurrentDeg . Deg . DegCod > 0 )
/***** Register user as administrator of degree *****/
if ( ! UsrIsDegAdmin & &
2017-06-04 18:18:54 +02:00
Gbl . Usrs . Me . Role . Logged > = Rol_CTR_ADM )
2015-01-31 01:23:39 +01:00
{
fprintf ( Gbl . F . Out , " <li> "
2018-10-16 21:56:01 +02:00
" <input type= \" radio \" id= \" RegRemAction%u \" "
" name= \" RegRemAction \" value= \" %u \" " ,
( unsigned ) Enr_REGISTER_ONE_DEGREE_ADMIN ,
2015-01-31 01:23:39 +01:00
( unsigned ) Enr_REGISTER_ONE_DEGREE_ADMIN ) ;
if ( ! OptionChecked )
{
fprintf ( Gbl . F . Out , " checked= \" checked \" " ) ;
OptionChecked = true ;
}
2016-12-21 01:51:30 +01:00
fprintf ( Gbl . F . Out , " /> "
2018-10-16 21:56:01 +02:00
" <label for= \" RegRemAction%u \" > " ,
( unsigned ) Enr_REGISTER_ONE_DEGREE_ADMIN ) ;
fprintf ( Gbl . F . Out ,
Txt_Register_USER_as_an_administrator_of_the_degree_X ,
Gbl . CurrentDeg . Deg . ShrtName ) ;
fprintf ( Gbl . F . Out , " </label> "
" </li> " ) ;
2015-01-31 01:23:39 +01:00
NumOptionsShown + + ;
}
/***** Register user as administrator of centre *****/
if ( ! UsrIsCtrAdmin & &
2017-06-04 18:18:54 +02:00
Gbl . Usrs . Me . Role . Logged > = Rol_INS_ADM )
2015-01-31 01:23:39 +01:00
{
fprintf ( Gbl . F . Out , " <li> "
2018-10-16 21:56:01 +02:00
" <input type= \" radio \" id= \" RegRemAction%u \" "
" name= \" RegRemAction \" value= \" %u \" " ,
( unsigned ) Enr_REGISTER_ONE_CENTRE_ADMIN ,
2015-01-31 01:23:39 +01:00
( unsigned ) Enr_REGISTER_ONE_CENTRE_ADMIN ) ;
if ( ! OptionChecked )
{
fprintf ( Gbl . F . Out , " checked= \" checked \" " ) ;
OptionChecked = true ;
}
2016-12-21 01:51:30 +01:00
fprintf ( Gbl . F . Out , " /> "
2018-10-16 21:56:01 +02:00
" <label for= \" RegRemAction%u \" > " ,
( unsigned ) Enr_REGISTER_ONE_CENTRE_ADMIN ) ;
fprintf ( Gbl . F . Out ,
Txt_Register_USER_as_an_administrator_of_the_centre_X ,
Gbl . CurrentCtr . Ctr . ShrtName ) ;
fprintf ( Gbl . F . Out , " </label> "
" </li> " ) ;
2015-01-31 01:23:39 +01:00
NumOptionsShown + + ;
}
2014-12-12 18:52:06 +01:00
}
2015-01-31 01:23:39 +01:00
/***** Register user as administrator of institution *****/
if ( ! UsrIsInsAdmin & &
2017-06-04 18:18:54 +02:00
Gbl . Usrs . Me . Role . Logged = = Rol_SYS_ADM )
2015-01-31 01:23:39 +01:00
{
fprintf ( Gbl . F . Out , " <li> "
2018-10-16 21:56:01 +02:00
" <input type= \" radio \" id= \" RegRemAction%u \" "
" name= \" RegRemAction \" value= \" %u \" " ,
( unsigned ) Enr_REGISTER_ONE_INSTITUTION_ADMIN ,
2015-01-31 01:23:39 +01:00
( unsigned ) Enr_REGISTER_ONE_INSTITUTION_ADMIN ) ;
if ( ! OptionChecked )
{
fprintf ( Gbl . F . Out , " checked= \" checked \" " ) ;
OptionChecked = true ;
}
2016-12-21 01:51:30 +01:00
fprintf ( Gbl . F . Out , " /> "
2018-10-16 21:56:01 +02:00
" <label for= \" RegRemAction%u \" > " ,
( unsigned ) Enr_REGISTER_ONE_INSTITUTION_ADMIN ) ;
fprintf ( Gbl . F . Out , Txt_Register_USER_as_an_administrator_of_the_institution_X ,
Gbl . CurrentIns . Ins . ShrtName ) ;
fprintf ( Gbl . F . Out , " </label> "
" </li> " ) ;
2015-01-31 01:23:39 +01:00
NumOptionsShown + + ;
}
2014-12-12 18:52:06 +01:00
}
2016-06-14 23:52:22 +02:00
/***** Report user as possible duplicate *****/
2017-06-04 18:18:54 +02:00
if ( ! ItsMe & & Gbl . Usrs . Me . Role . Logged > = Rol_TCH )
2016-06-14 23:52:22 +02:00
{
fprintf ( Gbl . F . Out , " <li> "
2018-10-16 21:56:01 +02:00
" <input type= \" radio \" id= \" RegRemAction%u \" "
" name= \" RegRemAction \" value= \" %u \" " ,
( unsigned ) Enr_REPORT_USR_AS_POSSIBLE_DUPLICATE ,
2016-06-14 23:52:22 +02:00
( unsigned ) Enr_REPORT_USR_AS_POSSIBLE_DUPLICATE ) ;
if ( ! OptionChecked )
{
fprintf ( Gbl . F . Out , " checked= \" checked \" " ) ;
OptionChecked = true ;
}
2016-12-21 01:51:30 +01:00
fprintf ( Gbl . F . Out , " /> "
2018-10-16 21:56:01 +02:00
" <label for= \" RegRemAction%u \" > "
2016-12-21 01:51:30 +01:00
" %s "
" </label> "
" </li> " ,
2018-10-16 21:56:01 +02:00
( unsigned ) Enr_REPORT_USR_AS_POSSIBLE_DUPLICATE ,
2016-12-21 01:51:30 +01:00
Txt_Report_possible_duplicate_user ) ;
2016-06-14 23:52:22 +02:00
NumOptionsShown + + ;
}
2014-12-12 18:52:06 +01:00
/***** Remove user from the course *****/
if ( UsrBelongsToCrs )
{
fprintf ( Gbl . F . Out , " <li> "
2018-10-16 21:56:01 +02:00
" <input type= \" radio \" id= \" RegRemAction%u \" "
" name= \" RegRemAction \" value= \ %u \" " ,
( unsigned ) Enr_REMOVE_ONE_USR_FROM_CRS ,
2014-12-12 18:52:06 +01:00
( unsigned ) Enr_REMOVE_ONE_USR_FROM_CRS ) ;
if ( ! OptionChecked )
{
fprintf ( Gbl . F . Out , " checked= \" checked \" " ) ;
OptionChecked = true ;
}
2016-12-21 01:51:30 +01:00
fprintf ( Gbl . F . Out , " /> "
2018-10-16 21:56:01 +02:00
" <label for= \" RegRemAction%u \" > " ,
( unsigned ) Enr_REMOVE_ONE_USR_FROM_CRS ) ;
fprintf ( Gbl . F . Out ,
ItsMe ? Txt_Remove_me_from_THE_COURSE_X :
Txt_Remove_USER_from_THE_COURSE_X ,
Gbl . CurrentCrs . Crs . ShrtName ) ;
fprintf ( Gbl . F . Out , " </label> "
" </li> " ) ;
2014-12-12 18:52:06 +01:00
NumOptionsShown + + ;
}
2015-01-31 01:23:39 +01:00
if ( Gbl . CurrentIns . Ins . InsCod > 0 )
2014-12-12 18:52:06 +01:00
{
2015-01-31 01:23:39 +01:00
if ( Gbl . CurrentCtr . Ctr . CtrCod > 0 )
2014-12-12 18:52:06 +01:00
{
2015-01-31 01:23:39 +01:00
if ( Gbl . CurrentIns . Ins . InsCod > 0 )
/***** Remove user as an administrator of the degree *****/
if ( UsrIsDegAdmin & &
2017-06-04 18:18:54 +02:00
( ItsMe | | Gbl . Usrs . Me . Role . Logged > = Rol_CTR_ADM ) )
2015-01-31 01:23:39 +01:00
{
fprintf ( Gbl . F . Out , " <li> "
2018-10-16 21:56:01 +02:00
" <input type= \" radio \" id= \" RegRemAction%u \" "
" name= \" RegRemAction \" value= \" %u \" " ,
( unsigned ) Enr_REMOVE_ONE_DEGREE_ADMIN ,
2015-01-31 01:23:39 +01:00
( unsigned ) Enr_REMOVE_ONE_DEGREE_ADMIN ) ;
if ( ! OptionChecked )
{
fprintf ( Gbl . F . Out , " checked= \" checked \" " ) ;
OptionChecked = true ;
}
2016-12-21 01:51:30 +01:00
fprintf ( Gbl . F . Out , " /> "
2018-10-16 21:56:01 +02:00
" <label for= \" RegRemAction%u \" > " ,
( unsigned ) Enr_REMOVE_ONE_DEGREE_ADMIN ) ;
fprintf ( Gbl . F . Out ,
ItsMe ? Txt_Remove_me_as_an_administrator_of_the_degree_X :
Txt_Remove_USER_as_an_administrator_of_the_degree_X ,
Gbl . CurrentDeg . Deg . ShrtName ) ;
fprintf ( Gbl . F . Out , " </label> "
" </li> " ) ;
2015-01-31 01:23:39 +01:00
NumOptionsShown + + ;
}
/***** Remove user as an administrator of the centre *****/
if ( UsrIsCtrAdmin & &
2017-06-04 18:18:54 +02:00
( ItsMe | | Gbl . Usrs . Me . Role . Logged > = Rol_INS_ADM ) )
2015-01-31 01:23:39 +01:00
{
fprintf ( Gbl . F . Out , " <li> "
2018-10-16 21:56:01 +02:00
" <input type= \" radio \" id= \" RegRemAction%u \" "
" name= \" RegRemAction \" value= \" %u \" " ,
( unsigned ) Enr_REMOVE_ONE_CENTRE_ADMIN ,
2015-01-31 01:23:39 +01:00
( unsigned ) Enr_REMOVE_ONE_CENTRE_ADMIN ) ;
if ( ! OptionChecked )
{
fprintf ( Gbl . F . Out , " checked= \" checked \" " ) ;
OptionChecked = true ;
}
2016-12-21 01:51:30 +01:00
fprintf ( Gbl . F . Out , " /> "
2018-10-16 21:56:01 +02:00
" <label for= \" RegRemAction%u \" > " ,
( unsigned ) Enr_REMOVE_ONE_CENTRE_ADMIN ) ;
fprintf ( Gbl . F . Out ,
ItsMe ? Txt_Remove_me_as_an_administrator_of_the_centre_X :
Txt_Remove_USER_as_an_administrator_of_the_centre_X ,
Gbl . CurrentCtr . Ctr . ShrtName ) ;
fprintf ( Gbl . F . Out , " </label> "
" </li> " ) ;
2015-01-31 01:23:39 +01:00
NumOptionsShown + + ;
}
2014-12-12 18:52:06 +01:00
}
2015-01-31 01:23:39 +01:00
/***** Remove user as an administrator of the institution *****/
if ( UsrIsInsAdmin & &
2017-06-04 18:18:54 +02:00
( ItsMe | | Gbl . Usrs . Me . Role . Logged = = Rol_SYS_ADM ) )
2015-01-31 01:23:39 +01:00
{
fprintf ( Gbl . F . Out , " <li> "
2018-10-16 21:56:01 +02:00
" <input type= \" radio \" id= \" RegRemAction%u \" "
" name= \" RegRemAction \" value= \" %u \" " ,
( unsigned ) Enr_REMOVE_ONE_INSTITUTION_ADMIN ,
2015-01-31 01:23:39 +01:00
( unsigned ) Enr_REMOVE_ONE_INSTITUTION_ADMIN ) ;
if ( ! OptionChecked )
{
fprintf ( Gbl . F . Out , " checked= \" checked \" " ) ;
OptionChecked = true ;
}
2016-12-21 01:51:30 +01:00
fprintf ( Gbl . F . Out , " /> "
2018-10-16 21:56:01 +02:00
" <label for= \" RegRemAction%u \" > " ,
( unsigned ) Enr_REMOVE_ONE_INSTITUTION_ADMIN ) ;
fprintf ( Gbl . F . Out ,
ItsMe ? Txt_Remove_me_as_an_administrator_of_the_institution_X :
Txt_Remove_USER_as_an_administrator_of_the_institution_X ,
Gbl . CurrentIns . Ins . ShrtName ) ;
fprintf ( Gbl . F . Out , " </label> "
" </li> " ) ;
2015-01-31 01:23:39 +01:00
NumOptionsShown + + ;
}
2014-12-12 18:52:06 +01:00
}
/***** Eliminate user completely from platform *****/
2016-06-17 23:38:32 +02:00
if ( Acc_CheckIfICanEliminateAccount ( Gbl . Usrs . Other . UsrDat . UsrCod ) )
2014-12-12 18:52:06 +01:00
{
fprintf ( Gbl . F . Out , " <li> "
2018-10-16 21:56:01 +02:00
" <input type= \" radio \" id= \" RegRemAction%u \" "
" name= \" RegRemAction \" value= \" %u \" " ,
( unsigned ) Enr_ELIMINATE_ONE_USR_FROM_PLATFORM ,
2014-12-12 18:52:06 +01:00
( unsigned ) Enr_ELIMINATE_ONE_USR_FROM_PLATFORM ) ;
if ( ! OptionChecked )
fprintf ( Gbl . F . Out , " checked= \" checked \" " ) ;
2016-12-21 01:51:30 +01:00
fprintf ( Gbl . F . Out , " /> "
2018-10-16 21:56:01 +02:00
" <label for= \" RegRemAction%u \" > "
2016-12-21 01:51:30 +01:00
" %s "
" </label> "
" </li> " ,
2018-10-16 21:56:01 +02:00
( unsigned ) Enr_ELIMINATE_ONE_USR_FROM_PLATFORM ,
2015-03-28 18:34:08 +01:00
ItsMe ? Txt_Eliminate_my_user_account :
Txt_Eliminate_user_account ) ;
2014-12-12 18:52:06 +01:00
NumOptionsShown + + ;
}
/***** End list of options *****/
2016-12-19 00:55:24 +01:00
fprintf ( Gbl . F . Out , " </ul> " ) ;
2014-12-12 18:52:06 +01:00
return ( NumOptionsShown ? true :
false ) ;
}
/*****************************************************************************/
/*** Put different actions to register/remove users to/from current course ***/
/*****************************************************************************/
static void Enr_PutActionsRegRemSeveralUsrs ( void )
{
2019-02-22 21:47:50 +01:00
extern const char * The_ClassFormInBox [ The_NUM_THEMES ] ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_Register_the_users_indicated_in_step_1 ;
extern const char * Txt_Remove_the_users_indicated_in_step_1 ;
extern const char * Txt_Remove_the_users_not_indicated_in_step_1 ;
extern const char * Txt_Register_the_users_indicated_in_step_1_and_remove_the_users_not_indicated ;
extern const char * Txt_Eliminate_from_the_platform_the_users_indicated_in_step_1 ;
/***** Start list of options *****/
2016-12-19 00:55:24 +01:00
fprintf ( Gbl . F . Out , " <ul class= \" LIST_LEFT %s \" style= \" margin:12px; \" > " ,
2019-02-22 21:47:50 +01:00
The_ClassFormInBox [ Gbl . Prefs . Theme ] ) ;
2014-12-12 18:52:06 +01:00
/***** Register / remove users listed or not listed *****/
if ( Gbl . CurrentCrs . Crs . CrsCod > 0 ) // Course selected
fprintf ( Gbl . F . Out , " <li> "
2018-10-16 21:56:01 +02:00
" <input type= \" radio \" id= \" RegRemAction%u \" "
" name= \" RegRemAction \" value= \" %u \" checked= \" checked \" /> "
" <label for= \" RegRemAction%u \" > "
2016-12-21 01:51:30 +01:00
" %s "
" </label> "
" </li> "
2014-12-12 18:52:06 +01:00
" <li> "
2018-10-16 21:56:01 +02:00
" <input type= \" radio \" id= \" RegRemAction%u \" "
" name= \" RegRemAction \" value= \" %u \" /> "
" <label for= \" RegRemAction%u \" > "
2016-12-21 01:51:30 +01:00
" %s "
" </label> "
" </li> "
2014-12-12 18:52:06 +01:00
" <li> "
2018-10-16 21:56:01 +02:00
" <input type= \" radio \" id= \" RegRemAction%u \" "
" name= \" RegRemAction \" value= \" %u \" /> "
" <label for= \" RegRemAction%u \" > "
2016-12-21 01:51:30 +01:00
" %s "
" </label> "
" </li> "
2014-12-12 18:52:06 +01:00
" <li> "
2018-10-16 21:56:01 +02:00
" <input id= \" RegRemAction%u \" type= \" radio \" "
" name= \" RegRemAction \" value= \" %u \" /> "
" <label for= \" RegRemAction%u \" > "
2016-12-21 01:51:30 +01:00
" %s "
" </label> "
" </li> " ,
2014-12-12 18:52:06 +01:00
( unsigned ) Enr_REGISTER_SPECIFIED_USRS_IN_CRS ,
2018-10-16 21:56:01 +02:00
( unsigned ) Enr_REGISTER_SPECIFIED_USRS_IN_CRS ,
( unsigned ) Enr_REGISTER_SPECIFIED_USRS_IN_CRS ,
2014-12-12 18:52:06 +01:00
Txt_Register_the_users_indicated_in_step_1 ,
( unsigned ) Enr_REMOVE_SPECIFIED_USRS_FROM_CRS ,
2018-10-16 21:56:01 +02:00
( unsigned ) Enr_REMOVE_SPECIFIED_USRS_FROM_CRS ,
( unsigned ) Enr_REMOVE_SPECIFIED_USRS_FROM_CRS ,
2014-12-12 18:52:06 +01:00
Txt_Remove_the_users_indicated_in_step_1 ,
( unsigned ) Enr_REMOVE_NOT_SPECIFIED_USRS_FROM_CRS ,
2018-10-16 21:56:01 +02:00
( unsigned ) Enr_REMOVE_NOT_SPECIFIED_USRS_FROM_CRS ,
( unsigned ) Enr_REMOVE_NOT_SPECIFIED_USRS_FROM_CRS ,
2014-12-12 18:52:06 +01:00
Txt_Remove_the_users_not_indicated_in_step_1 ,
( unsigned ) Enr_UPDATE_USRS_IN_CRS ,
2018-10-16 21:56:01 +02:00
( unsigned ) Enr_UPDATE_USRS_IN_CRS ,
( unsigned ) Enr_UPDATE_USRS_IN_CRS ,
2014-12-12 18:52:06 +01:00
Txt_Register_the_users_indicated_in_step_1_and_remove_the_users_not_indicated ) ;
/***** Only for superusers *****/
2017-06-04 18:18:54 +02:00
if ( Gbl . Usrs . Me . Role . Logged = = Rol_SYS_ADM )
2014-12-12 18:52:06 +01:00
fprintf ( Gbl . F . Out , " <li> "
2018-10-16 21:56:01 +02:00
" <input type= \" radio \" id= \" RegRemAction%u \" "
" name= \" RegRemAction \" value= \" %u \" /> "
" <label for= \" RegRemAction%u \" > "
2016-12-21 01:51:30 +01:00
" %s "
" </label> "
" </li> " ,
2014-12-12 18:52:06 +01:00
( unsigned ) Enr_ELIMINATE_USRS_FROM_PLATFORM ,
2018-10-16 21:56:01 +02:00
( unsigned ) Enr_ELIMINATE_USRS_FROM_PLATFORM ,
( unsigned ) Enr_ELIMINATE_USRS_FROM_PLATFORM ,
2014-12-12 18:52:06 +01:00
Txt_Eliminate_from_the_platform_the_users_indicated_in_step_1 ) ;
/***** End list of options *****/
2016-12-19 00:55:24 +01:00
fprintf ( Gbl . F . Out , " </ul> " ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
/******* Receive the list of users of the course to register/remove **********/
/*****************************************************************************/
2015-09-14 09:50:55 +02:00
void Enr_ReceiveFormAdminStds ( void )
{
2017-05-18 19:13:41 +02:00
Enr_ReceiveFormUsrsCrs ( Rol_STD ) ;
2015-09-14 09:50:55 +02:00
}
2017-05-21 21:23:13 +02:00
void Enr_ReceiveFormAdminNonEditTchs ( void )
{
Enr_ReceiveFormUsrsCrs ( Rol_NET ) ;
}
2015-09-14 09:50:55 +02:00
void Enr_ReceiveFormAdminTchs ( void )
{
2017-05-18 19:13:41 +02:00
Enr_ReceiveFormUsrsCrs ( Rol_TCH ) ;
2015-09-14 09:50:55 +02:00
}
static void Enr_ReceiveFormUsrsCrs ( Rol_Role_t Role )
2014-12-12 18:52:06 +01:00
{
2017-03-30 11:20:06 +02:00
extern const char * Txt_In_a_type_of_group_with_single_enrolment_students_can_not_be_registered_in_more_than_one_group ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_No_user_has_been_eliminated ;
extern const char * Txt_One_user_has_been_eliminated ;
extern const char * Txt_No_user_has_been_removed ;
extern const char * Txt_One_user_has_been_removed ;
extern const char * Txt_X_users_have_been_eliminated ;
extern const char * Txt_X_users_have_been_removed ;
2017-03-30 11:20:06 +02:00
extern const char * Txt_No_user_has_been_enroled ;
extern const char * Txt_One_user_has_been_enroled ;
extern const char * Txt_X_users_have_been_enroled_including_possible_repetitions ;
2014-12-12 18:52:06 +01:00
struct
{
bool RemoveUsrs ;
bool RemoveSpecifiedUsrs ;
bool EliminateUsrs ;
bool RegisterUsrs ;
} WhatToDo ;
char * ListUsrsIDs ;
struct ListUsrCods ListUsrCods ; // List with users' codes for a given user's ID
unsigned NumUsrFound ;
const char * Ptr ;
unsigned NumCurrentUsr ;
unsigned NumUsrsRegistered = 0 ;
unsigned NumUsrsRemoved = 0 ;
unsigned NumUsrsEliminated = 0 ;
struct ListCodGrps LstGrps ;
struct UsrData UsrDat ;
bool ItLooksLikeAUsrID ;
Enr_RegRemUsrsAction_t RegRemUsrsAction ;
2015-09-14 10:47:39 +02:00
/***** Check the role of users to register / remove *****/
switch ( Role )
{
2017-05-18 19:13:41 +02:00
case Rol_STD :
2017-06-04 18:18:54 +02:00
if ( Gbl . Usrs . Me . Role . Logged < Rol_TCH ) // Can I register/remove students?
2017-05-22 00:51:45 +02:00
// No, I can not
Lay_ShowErrorAndExit ( " You are not allowed to perform this action. " ) ;
2015-09-14 10:47:39 +02:00
break ;
2017-05-22 00:51:45 +02:00
case Rol_NET :
2017-05-18 19:13:41 +02:00
case Rol_TCH :
2017-06-04 18:18:54 +02:00
if ( Gbl . Usrs . Me . Role . Logged < Rol_DEG_ADM ) // Can I register/remove teachers?
2017-05-22 00:51:45 +02:00
// No, I can not
2015-09-14 10:47:39 +02:00
Lay_ShowErrorAndExit ( " You are not allowed to perform this action. " ) ;
break ;
default :
Lay_ShowErrorAndExit ( " Wrong role. " ) ;
break ;
}
2014-12-12 18:52:06 +01:00
/***** Get confirmation *****/
if ( ! Pwd_GetConfirmationOnDangerousAction ( ) )
return ;
/***** Get the action to do *****/
WhatToDo . RemoveUsrs = false ;
WhatToDo . RemoveSpecifiedUsrs = false ;
WhatToDo . EliminateUsrs = false ;
WhatToDo . RegisterUsrs = false ;
2017-01-29 21:41:08 +01:00
RegRemUsrsAction = ( Enr_RegRemUsrsAction_t )
Par_GetParToUnsignedLong ( " RegRemAction " ,
0 ,
Enr_NUM_REG_REM_USRS_ACTIONS - 1 ,
( unsigned long ) Enr_REG_REM_USRS_UNKNOWN_ACTION ) ;
2017-01-29 12:42:19 +01:00
switch ( RegRemUsrsAction )
{
case Enr_REGISTER_SPECIFIED_USRS_IN_CRS :
WhatToDo . RemoveUsrs = false ;
WhatToDo . RemoveSpecifiedUsrs = false ; // Ignored
WhatToDo . EliminateUsrs = false ; // Ignored
WhatToDo . RegisterUsrs = true ;
break ;
case Enr_REMOVE_SPECIFIED_USRS_FROM_CRS :
WhatToDo . RemoveUsrs = true ;
WhatToDo . RemoveSpecifiedUsrs = true ;
WhatToDo . EliminateUsrs = false ;
WhatToDo . RegisterUsrs = false ;
break ;
case Enr_REMOVE_NOT_SPECIFIED_USRS_FROM_CRS :
WhatToDo . RemoveUsrs = true ;
WhatToDo . RemoveSpecifiedUsrs = false ;
WhatToDo . EliminateUsrs = false ;
WhatToDo . RegisterUsrs = false ;
break ;
case Enr_UPDATE_USRS_IN_CRS :
WhatToDo . RemoveUsrs = true ;
WhatToDo . RemoveSpecifiedUsrs = false ;
WhatToDo . EliminateUsrs = false ;
WhatToDo . RegisterUsrs = true ;
break ;
case Enr_ELIMINATE_USRS_FROM_PLATFORM :
2017-06-04 18:18:54 +02:00
if ( Gbl . Usrs . Me . Role . Logged = = Rol_SYS_ADM )
2014-12-12 18:52:06 +01:00
{
2017-01-29 12:42:19 +01:00
WhatToDo . RemoveUsrs = true ;
WhatToDo . RemoveSpecifiedUsrs = true ;
WhatToDo . EliminateUsrs = true ;
WhatToDo . RegisterUsrs = false ;
2014-12-12 18:52:06 +01:00
}
2017-01-29 12:42:19 +01:00
else
Lay_ShowErrorAndExit ( " You are not allowed to perform this action. " ) ;
break ;
default :
2014-12-12 18:52:06 +01:00
Lay_ShowErrorAndExit ( " Wrong registering / removing specification. " ) ;
2017-01-29 12:42:19 +01:00
break ;
2014-12-12 18:52:06 +01:00
}
2017-01-29 12:42:19 +01:00
/***** Get groups to which register/remove users *****/
LstGrps . NumGrps = 0 ;
if ( Gbl . CurrentCrs . Grps . NumGrps ) // This course has groups?
2014-12-12 18:52:06 +01:00
{
2017-01-29 12:42:19 +01:00
/***** Get list of groups types and groups in current course *****/
Grp_GetListGrpTypesAndGrpsInThisCrs ( Grp_ONLY_GROUP_TYPES_WITH_GROUPS ) ;
/***** Get the list of groups to which register/remove students *****/
LstGrps . GrpCods = NULL ; // Initialized to avoid bug reported by Coverity
LstGrps . NumGrps = 0 ; // Initialized to avoid bug reported by Coverity
Grp_GetLstCodsGrpWanted ( & LstGrps ) ;
2017-05-22 00:51:45 +02:00
/***** A student can't belong to more than one group
when the type of group only allows to register in one group * * * * */
2017-06-20 01:58:16 +02:00
if ( WhatToDo . RegisterUsrs )
2017-03-30 11:20:06 +02:00
/* Check if I have selected more than one group of single enrolment */
2017-06-20 01:58:16 +02:00
if ( ! Grp_CheckIfSelectionGrpsSingleEnrolmentIsValid ( Role , & LstGrps ) )
2014-12-12 18:52:06 +01:00
{
2017-01-29 12:42:19 +01:00
/* Show warning message and exit */
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_WARNING , Txt_In_a_type_of_group_with_single_enrolment_students_can_not_be_registered_in_more_than_one_group ) ;
2014-12-12 18:52:06 +01:00
2017-01-29 12:42:19 +01:00
/* Free memory used by lists of groups and abort */
Grp_FreeListCodGrp ( & LstGrps ) ;
Grp_FreeListGrpTypesAndGrps ( ) ;
return ;
}
}
2014-12-12 18:52:06 +01:00
2017-01-29 12:42:19 +01:00
/***** Get list of users' IDs *****/
if ( ( ListUsrsIDs = ( char * ) malloc ( ID_MAX_BYTES_LIST_USRS_IDS + 1 ) ) = = NULL )
2018-10-18 20:06:54 +02:00
Lay_NotEnoughMemoryExit ( ) ;
2017-01-29 12:42:19 +01:00
Par_GetParToText ( " UsrsIDs " , ListUsrsIDs , ID_MAX_BYTES_LIST_USRS_IDS ) ;
2014-12-12 18:52:06 +01:00
2017-01-29 12:42:19 +01:00
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor ( & UsrDat ) ;
2014-12-12 18:52:06 +01:00
2017-01-29 12:42:19 +01:00
/***** Remove users *****/
if ( WhatToDo . RemoveUsrs )
{
/***** Get list of users in current course *****/
2017-05-25 19:57:34 +02:00
Usr_GetListUsrs ( Sco_SCOPE_CRS , Role ) ;
2014-12-12 18:52:06 +01:00
2017-01-29 12:42:19 +01:00
if ( Gbl . Usrs . LstUsrs [ Role ] . NumUsrs )
2014-12-12 18:52:06 +01:00
{
2017-01-29 12:42:19 +01:00
/***** Initialize list of users to remove *****/
for ( NumCurrentUsr = 0 ;
NumCurrentUsr < Gbl . Usrs . LstUsrs [ Role ] . NumUsrs ;
NumCurrentUsr + + )
Gbl . Usrs . LstUsrs [ Role ] . Lst [ NumCurrentUsr ] . Remove = ! WhatToDo . RemoveSpecifiedUsrs ;
/***** Loop 1: go through form list setting if a student must be removed *****/
/* Get users from a list of users' IDs */
2014-12-12 18:52:06 +01:00
Ptr = ListUsrsIDs ;
while ( * Ptr )
{
/* Reset user */
UsrDat . UsrCod = - 1L ;
/* Find next string in text */
2017-03-07 19:55:29 +01:00
Str_GetNextStringUntilSeparator ( & Ptr , UsrDat . UsrIDNickOrEmail ,
2017-03-13 13:17:53 +01:00
Cns_MAX_BYTES_EMAIL_ADDRESS ) ;
2014-12-12 18:52:06 +01:00
/* Reset default list of users' codes */
ListUsrCods . NumUsrs = 0 ;
ListUsrCods . Lst = NULL ;
2017-01-29 12:42:19 +01:00
/* Check if string is a user's ID, user's nickname or user's email address */
2014-12-12 18:52:06 +01:00
if ( Nck_CheckIfNickWithArrobaIsValid ( UsrDat . UsrIDNickOrEmail ) ) // 1: It's a nickname
{
if ( ( UsrDat . UsrCod = Nck_GetUsrCodFromNickname ( UsrDat . UsrIDNickOrEmail ) ) > 0 )
{
ListUsrCods . NumUsrs = 1 ;
Usr_AllocateListUsrCods ( & ListUsrCods ) ;
ListUsrCods . Lst [ 0 ] = UsrDat . UsrCod ;
}
}
2017-01-29 12:42:19 +01:00
else if ( Mai_CheckIfEmailIsValid ( UsrDat . UsrIDNickOrEmail ) ) // 2: It's an email
2014-12-12 18:52:06 +01:00
{
if ( ( UsrDat . UsrCod = Mai_GetUsrCodFromEmail ( UsrDat . UsrIDNickOrEmail ) ) > 0 )
{
ListUsrCods . NumUsrs = 1 ;
Usr_AllocateListUsrCods ( & ListUsrCods ) ;
ListUsrCods . Lst [ 0 ] = UsrDat . UsrCod ;
}
}
else // 3: It looks like a user's ID
{
// Users' IDs are always stored internally in capitals and without leading zeros
Str_RemoveLeadingZeros ( UsrDat . UsrIDNickOrEmail ) ;
if ( ID_CheckIfUsrIDSeemsAValidID ( UsrDat . UsrIDNickOrEmail ) )
{
2017-01-29 12:42:19 +01:00
/***** Find users for this user's ID *****/
2014-12-12 18:52:06 +01:00
ID_ReallocateListIDs ( & UsrDat , 1 ) ; // Only one user's ID
2017-01-15 18:02:52 +01:00
Str_Copy ( UsrDat . IDs . List [ 0 ] . ID , UsrDat . UsrIDNickOrEmail ,
2017-03-07 01:56:41 +01:00
ID_MAX_BYTES_USR_ID ) ;
2017-01-29 12:42:19 +01:00
Str_ConvertToUpperText ( UsrDat . IDs . List [ 0 ] . ID ) ;
2014-12-12 18:52:06 +01:00
ID_GetListUsrCodsFromUsrID ( & UsrDat , NULL , & ListUsrCods , false ) ;
}
}
2017-01-29 12:42:19 +01:00
if ( WhatToDo . RemoveSpecifiedUsrs ) // Remove the specified users (of the role)
{
if ( ListUsrCods . NumUsrs = = 1 ) // If more than one user found ==> do not remove
for ( NumCurrentUsr = 0 ;
NumCurrentUsr < Gbl . Usrs . LstUsrs [ Role ] . NumUsrs ;
NumCurrentUsr + + )
if ( Gbl . Usrs . LstUsrs [ Role ] . Lst [ NumCurrentUsr ] . UsrCod = = ListUsrCods . Lst [ 0 ] ) // User found
Gbl . Usrs . LstUsrs [ Role ] . Lst [ NumCurrentUsr ] . Remove = true ; // Mark as removable
}
else // Remove all the users (of the role) except these specified
{
for ( NumCurrentUsr = 0 ;
NumCurrentUsr < Gbl . Usrs . LstUsrs [ Role ] . NumUsrs ;
NumCurrentUsr + + )
for ( NumUsrFound = 0 ;
NumUsrFound < ListUsrCods . NumUsrs ;
NumUsrFound + + )
if ( Gbl . Usrs . LstUsrs [ Role ] . Lst [ NumCurrentUsr ] . UsrCod = = ListUsrCods . Lst [ NumUsrFound ] ) // User found
Gbl . Usrs . LstUsrs [ Role ] . Lst [ NumCurrentUsr ] . Remove = false ; // Mark as not removable
}
2014-12-12 18:52:06 +01:00
/* Free memory used for list of users' codes found for this ID */
Usr_FreeListUsrCods ( & ListUsrCods ) ;
}
2017-01-29 12:42:19 +01:00
/***** Loop 2: go through users list removing users *****/
for ( NumCurrentUsr = 0 ;
NumCurrentUsr < Gbl . Usrs . LstUsrs [ Role ] . NumUsrs ;
NumCurrentUsr + + )
if ( Gbl . Usrs . LstUsrs [ Role ] . Lst [ NumCurrentUsr ] . Remove ) // If this student must be removed
{
UsrDat . UsrCod = Gbl . Usrs . LstUsrs [ Role ] . Lst [ NumCurrentUsr ] . UsrCod ;
if ( Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod ( & UsrDat ) ) // If user's data exist...
{
if ( WhatToDo . EliminateUsrs ) // Eliminate user completely from the platform
{
Acc_CompletelyEliminateAccount ( & UsrDat , Cns_QUIET ) ; // Remove definitely the user from the platform
NumUsrsEliminated + + ;
}
else
{
if ( Gbl . CurrentCrs . Grps . NumGrps ) // If there are groups in the course
{
if ( LstGrps . NumGrps ) // If the teacher has selected groups
{
if ( Grp_RemoveUsrFromGroups ( & UsrDat , & LstGrps ) ) // Remove user from the selected groups, not from the whole course
NumUsrsRemoved + + ;
}
else // The teacher has not selected groups
{
Enr_EffectivelyRemUsrFromCrs ( & UsrDat , & Gbl . CurrentCrs . Crs ,
Enr_DO_NOT_REMOVE_WORKS , Cns_QUIET ) ; // Remove user from the course
NumUsrsRemoved + + ;
}
}
else // No groups
{
Enr_EffectivelyRemUsrFromCrs ( & UsrDat , & Gbl . CurrentCrs . Crs ,
Enr_DO_NOT_REMOVE_WORKS , Cns_QUIET ) ; // Remove user from the course
NumUsrsRemoved + + ;
}
}
}
}
}
2014-12-12 18:52:06 +01:00
2017-01-29 12:42:19 +01:00
/***** Free memory for users list *****/
Usr_FreeUsrsList ( Role ) ;
}
2014-12-12 18:52:06 +01:00
2017-01-29 12:42:19 +01:00
/***** Register users *****/
if ( WhatToDo . RegisterUsrs ) // TODO: !!!!! NO CAMBIAR EL ROL DE LOS USUARIOS QUE YA EST<53> N EN LA ASIGNATURA SI HAY M<> S DE UN USUARIO ENCONTRADO PARA EL MISMO DNI !!!!!!
{
/***** Get users from a list of users' IDs ******/
Ptr = ListUsrsIDs ;
while ( * Ptr )
2014-12-12 18:52:06 +01:00
{
2017-01-29 12:42:19 +01:00
/* Reset user */
UsrDat . UsrCod = - 1L ;
ItLooksLikeAUsrID = false ;
/* Find next string in text */
2017-03-07 19:55:29 +01:00
Str_GetNextStringUntilSeparator ( & Ptr , UsrDat . UsrIDNickOrEmail ,
2017-03-13 13:17:53 +01:00
Cns_MAX_BYTES_EMAIL_ADDRESS ) ;
2017-01-29 12:42:19 +01:00
/* Reset default list of users' codes */
ListUsrCods . NumUsrs = 0 ;
ListUsrCods . Lst = NULL ;
/* Check if the string is a user's ID, a user's nickname or a user's email address */
if ( Nck_CheckIfNickWithArrobaIsValid ( UsrDat . UsrIDNickOrEmail ) ) // 1: It's a nickname
{
if ( ( UsrDat . UsrCod = Nck_GetUsrCodFromNickname ( UsrDat . UsrIDNickOrEmail ) ) > 0 )
2014-12-12 18:52:06 +01:00
{
2017-01-29 12:42:19 +01:00
ListUsrCods . NumUsrs = 1 ;
Usr_AllocateListUsrCods ( & ListUsrCods ) ;
ListUsrCods . Lst [ 0 ] = UsrDat . UsrCod ;
2014-12-12 18:52:06 +01:00
}
2017-01-29 12:42:19 +01:00
}
else if ( Mai_CheckIfEmailIsValid ( UsrDat . UsrIDNickOrEmail ) ) // 2: It's an email
{
if ( ( UsrDat . UsrCod = Mai_GetUsrCodFromEmail ( UsrDat . UsrIDNickOrEmail ) ) > 0 )
2014-12-12 18:52:06 +01:00
{
2017-01-29 12:42:19 +01:00
ListUsrCods . NumUsrs = 1 ;
Usr_AllocateListUsrCods ( & ListUsrCods ) ;
ListUsrCods . Lst [ 0 ] = UsrDat . UsrCod ;
}
}
else // 3: It looks like a user's ID
{
// Users' IDs are always stored internally in capitals and without leading zeros
Str_RemoveLeadingZeros ( UsrDat . UsrIDNickOrEmail ) ;
if ( ID_CheckIfUsrIDSeemsAValidID ( UsrDat . UsrIDNickOrEmail ) )
{
ItLooksLikeAUsrID = true ;
/* Find users for this user's ID */
ID_ReallocateListIDs ( & UsrDat , 1 ) ; // Only one user's ID
Str_Copy ( UsrDat . IDs . List [ 0 ] . ID , UsrDat . UsrIDNickOrEmail ,
2017-03-07 01:56:41 +01:00
ID_MAX_BYTES_USR_ID ) ;
2017-01-29 12:42:19 +01:00
Str_ConvertToUpperText ( UsrDat . IDs . List [ 0 ] . ID ) ;
ID_GetListUsrCodsFromUsrID ( & UsrDat , NULL , & ListUsrCods , false ) ;
2014-12-12 18:52:06 +01:00
}
2017-01-29 12:42:19 +01:00
}
/* Register user(s) */
if ( ListUsrCods . NumUsrs ) // User(s) found
for ( NumUsrFound = 0 ;
NumUsrFound < ListUsrCods . NumUsrs ;
NumUsrFound + + )
{
UsrDat . UsrCod = ListUsrCods . Lst [ NumUsrFound ] ;
Enr_RegisterUsr ( & UsrDat , Role , & LstGrps , & NumUsrsRegistered ) ;
}
else if ( ItLooksLikeAUsrID ) // User not found. He/she is a new user. Register him/her using ID
Enr_RegisterUsr ( & UsrDat , Role , & LstGrps , & NumUsrsRegistered ) ;
/* Free memory used for list of users' codes found for this ID */
Usr_FreeListUsrCods ( & ListUsrCods ) ;
2014-12-12 18:52:06 +01:00
}
2017-01-29 12:42:19 +01:00
}
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor ( & UsrDat ) ;
if ( NumUsrsEliminated )
/***** Move unused contents of messages to table of deleted contents of messages *****/
Msg_MoveUnusedMsgsContentToDeleted ( ) ;
2017-03-30 11:20:06 +02:00
/***** Write messages with the number of users enroled/removed *****/
2017-01-29 12:42:19 +01:00
if ( WhatToDo . RemoveUsrs )
{
if ( WhatToDo . EliminateUsrs ) // Eliminate completely from the platform
switch ( NumUsrsEliminated )
{
case 0 :
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_INFO , Txt_No_user_has_been_eliminated ) ;
2017-01-29 12:42:19 +01:00
break ;
case 1 :
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_SUCCESS , Txt_One_user_has_been_eliminated ) ;
2017-01-29 12:42:19 +01:00
break ;
default :
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_SUCCESS , Txt_X_users_have_been_eliminated ,
2019-02-16 01:20:54 +01:00
NumUsrsEliminated ) ;
2017-01-29 12:42:19 +01:00
break ;
}
else // Only remove from course / groups
switch ( NumUsrsRemoved )
2014-12-12 18:52:06 +01:00
{
case 0 :
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_INFO , Txt_No_user_has_been_removed ) ;
2014-12-12 18:52:06 +01:00
break ;
case 1 :
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_SUCCESS , Txt_One_user_has_been_removed ) ;
2014-12-12 18:52:06 +01:00
break ;
default :
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_SUCCESS , Txt_X_users_have_been_removed ,
2019-02-16 01:20:54 +01:00
NumUsrsRemoved ) ;
2014-12-12 18:52:06 +01:00
break ;
}
2017-01-29 12:42:19 +01:00
}
if ( WhatToDo . RegisterUsrs )
switch ( NumUsrsRegistered )
{
case 0 :
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_INFO , Txt_No_user_has_been_enroled ) ;
2017-01-29 12:42:19 +01:00
break ;
case 1 :
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_SUCCESS , Txt_One_user_has_been_enroled ) ;
2017-01-29 12:42:19 +01:00
break ;
default :
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_SUCCESS , Txt_X_users_have_been_enroled_including_possible_repetitions ,
2019-02-16 01:20:54 +01:00
NumUsrsRegistered ) ;
2017-01-29 12:42:19 +01:00
break ;
}
2014-12-12 18:52:06 +01:00
2017-01-29 12:42:19 +01:00
/***** Free memory used by the list of user's IDs *****/
free ( ListUsrsIDs ) ;
2014-12-12 18:52:06 +01:00
2017-01-29 12:42:19 +01:00
/***** Free memory with the list of groups to/from which register/remove users *****/
Grp_FreeListCodGrp ( & LstGrps ) ;
2014-12-12 18:52:06 +01:00
2017-01-29 12:42:19 +01:00
/***** Free list of groups types and groups in current course *****/
Grp_FreeListGrpTypesAndGrps ( ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
/********************** Register a user using his/her ID *********************/
/*****************************************************************************/
// If user does not exists, UsrDat->IDs must hold the user's ID
static void Enr_RegisterUsr ( struct UsrData * UsrDat , Rol_Role_t RegRemRole ,
struct ListCodGrps * LstGrps , unsigned * NumUsrsRegistered )
{
/***** Check if I can register this user *****/
2017-06-04 18:18:54 +02:00
if ( Gbl . Usrs . Me . Role . Logged = = Rol_TCH & &
2017-05-18 19:13:41 +02:00
RegRemRole ! = Rol_STD )
2017-03-21 00:57:11 +01:00
Lay_ShowErrorAndExit ( " A teacher only can register several users as students. " ) ;
2014-12-12 18:52:06 +01:00
/***** Check if the record of the user exists and get the type of user *****/
if ( UsrDat - > UsrCod > 0 ) // User exists in database
Usr_GetAllUsrDataFromUsrCod ( UsrDat ) ; // Get user's data
else // User does not exist in database, create it using his/her ID!
{
// Reset user's data
Usr_ResetUsrDataExceptUsrCodAndIDs ( UsrDat ) ; // It's necessary, because the same struct UsrDat was used for former user
2016-11-08 00:58:32 +01:00
// User does not exist in database; list of IDs is initialized
2014-12-12 18:52:06 +01:00
UsrDat - > IDs . List [ 0 ] . Confirmed = true ; // If he/she is a new user ==> his/her ID will be stored as confirmed in database
2016-11-08 00:58:32 +01:00
Acc_CreateNewUsr ( UsrDat ,
false ) ; // I am NOT creating my own account
2014-12-12 18:52:06 +01:00
}
/***** Register user in current course in database *****/
if ( Gbl . CurrentCrs . Crs . CrsCod > 0 ) // Course selected
{
2017-06-09 15:04:02 +02:00
if ( Usr_CheckIfUsrBelongsToCurrentCrs ( UsrDat ) )
2016-12-17 21:36:57 +01:00
{
2017-06-08 15:32:33 +02:00
if ( RegRemRole ! = UsrDat - > Roles . InCurrentCrs . Role ) // The role must be updated
2016-12-17 21:36:57 +01:00
/* Modify role */
Enr_ModifyRoleInCurrentCrs ( UsrDat , RegRemRole ) ;
}
2017-06-09 15:04:02 +02:00
else // User does not belong to this course
2016-12-17 20:44:13 +01:00
/* Register user */
Enr_RegisterUsrInCurrentCrs ( UsrDat , RegRemRole ,
2014-12-12 20:25:00 +01:00
Enr_SET_ACCEPTED_TO_FALSE ) ;
2014-12-12 18:52:06 +01:00
/***** Register user in the selected groups *****/
if ( Gbl . CurrentCrs . Grps . NumGrps ) // If there are groups in the course
Grp_RegisterUsrIntoGroups ( UsrDat , LstGrps ) ;
}
( * NumUsrsRegistered ) + + ;
}
/*****************************************************************************/
/**** Put a link (form) to remove all the students in the current course *****/
/*****************************************************************************/
2015-11-20 14:44:54 +01:00
static void Enr_PutLinkToRemAllStdsThisCrs ( void )
2014-12-12 18:52:06 +01:00
{
extern const char * Txt_Remove_all_students ;
/***** Put form to remove all the students in the current course *****/
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkIconText ( ActReqRemAllStdCrs , NULL , NULL ,
" trash.svg " ,
Txt_Remove_all_students ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
/********** Ask for removing all the students from current course ************/
/*****************************************************************************/
void Enr_AskRemAllStdsThisCrs ( void )
{
2017-01-31 09:42:54 +01:00
extern const char * Hlp_USERS_Administration_remove_all_students ;
2017-01-31 00:48:33 +01:00
extern const char * Txt_Remove_all_students ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_Do_you_really_want_to_remove_the_X_students_from_the_course_Y_ ;
2017-06-12 14:16:33 +02:00
/***** Start box *****/
2017-06-10 21:38:10 +02:00
Box_StartBox ( NULL , Txt_Remove_all_students , NULL ,
2017-06-12 15:03:29 +02:00
Hlp_USERS_Administration_remove_all_students , Box_NOT_CLOSABLE ) ;
2017-01-31 00:48:33 +01:00
2017-05-29 21:34:43 +02:00
if ( Gbl . CurrentCrs . Crs . NumUsrs [ Rol_STD ] )
2014-12-12 18:52:06 +01:00
{
2017-04-28 10:02:17 +02:00
/***** Show question and button to remove students *****/
/* Start alert */
2019-02-17 01:14:55 +01:00
Ale_ShowAlertAndButton1 ( Ale_QUESTION , Txt_Do_you_really_want_to_remove_the_X_students_from_the_course_Y_ ,
Gbl . CurrentCrs . Crs . NumUsrs [ Rol_STD ] ,
Gbl . CurrentCrs . Crs . FullName ) ;
2014-12-12 18:52:06 +01:00
2017-04-28 10:02:17 +02:00
/* Show form to request confirmation */
2018-11-09 20:47:39 +01:00
Frm_StartForm ( ActRemAllStdCrs ) ;
2014-12-12 18:52:06 +01:00
Grp_PutParamAllGroups ( ) ;
Pwd_AskForConfirmationOnDangerousAction ( ) ;
2017-06-11 19:02:40 +02:00
Btn_PutRemoveButton ( Txt_Remove_all_students ) ;
2018-11-09 20:47:39 +01:00
Frm_EndForm ( ) ;
2017-04-28 10:02:17 +02:00
/* End alert */
2017-06-11 19:02:40 +02:00
Ale_ShowAlertAndButton2 ( ActUnk , NULL , NULL , NULL , Btn_NO_BUTTON , NULL ) ;
2014-12-12 18:52:06 +01:00
}
2017-05-29 21:34:43 +02:00
else // Gbl.CurrentCrs.Crs.NumUsrs[Rol_STD] == 0
2017-02-09 19:27:18 +01:00
/***** Show warning indicating no students found *****/
2017-05-18 19:13:41 +02:00
Usr_ShowWarningNoUsersFound ( Rol_STD ) ;
2017-01-31 00:48:33 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2017-06-10 21:38:10 +02:00
Box_EndBox ( ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
/***************** Remove all the students from current course ***************/
/*****************************************************************************/
void Enr_RemAllStdsThisCrs ( void )
{
extern const char * Txt_The_X_students_who_belonged_to_the_course_Y_have_been_removed_from_it ;
unsigned NumStdsInCrs ;
if ( Pwd_GetConfirmationOnDangerousAction ( ) )
{
if ( ( NumStdsInCrs = Enr_RemAllStdsInCrs ( & Gbl . CurrentCrs . Crs ) ) )
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_SUCCESS , Txt_The_X_students_who_belonged_to_the_course_Y_have_been_removed_from_it ,
2019-02-16 01:20:54 +01:00
NumStdsInCrs , Gbl . CurrentCrs . Crs . FullName ) ;
2017-05-29 21:34:43 +02:00
else // NumStdsInCrs == 0
2017-02-09 19:27:18 +01:00
/***** Show warning indicating no students found *****/
2017-05-18 19:13:41 +02:00
Usr_ShowWarningNoUsersFound ( Rol_STD ) ;
2014-12-12 18:52:06 +01:00
}
}
/*****************************************************************************/
/***************** Remove all the students from a given course ***************/
/*****************************************************************************/
// Returns the numbers of students in the course before deletion
unsigned Enr_RemAllStdsInCrs ( struct Course * Crs )
{
unsigned NumStdsInCrs ;
unsigned NumUsr ;
/***** Get list of students in current course *****/
Gbl . Usrs . ClassPhoto . AllGroups = true ; // Get all the students of the current course
2017-05-25 19:57:34 +02:00
Usr_GetListUsrs ( Sco_SCOPE_CRS , Rol_STD ) ;
2017-05-18 19:13:41 +02:00
NumStdsInCrs = Gbl . Usrs . LstUsrs [ Rol_STD ] . NumUsrs ;
2014-12-12 18:52:06 +01:00
/***** Remove all the students *****/
for ( NumUsr = 0 ;
NumUsr < NumStdsInCrs ;
NumUsr + + )
{
2017-05-18 19:13:41 +02:00
Gbl . Usrs . Other . UsrDat . UsrCod = Gbl . Usrs . LstUsrs [ Rol_STD ] . Lst [ NumUsr ] . UsrCod ;
2014-12-12 18:52:06 +01:00
Enr_EffectivelyRemUsrFromCrs ( & Gbl . Usrs . Other . UsrDat , Crs ,
Enr_REMOVE_WORKS , Cns_QUIET ) ;
}
/***** Free memory for students list *****/
2017-05-18 19:13:41 +02:00
Usr_FreeUsrsList ( Rol_STD ) ;
2014-12-12 18:52:06 +01:00
return NumStdsInCrs ;
}
/*****************************************************************************/
/************* Form to request sign up in the current course *****************/
/*****************************************************************************/
void Enr_ReqSignUpInCrs ( void )
{
2017-03-30 11:20:06 +02:00
extern const char * Txt_You_were_already_enroled_as_X_in_the_course_Y ;
2015-03-12 14:45:40 +01:00
extern const char * Txt_ROLES_SINGUL_abc [ Rol_NUM_ROLES ] [ Usr_NUM_SEXS ] ;
2014-12-12 18:52:06 +01:00
/***** Check if I already belong to course *****/
2017-06-08 15:32:33 +02:00
if ( Gbl . Usrs . Me . UsrDat . Roles . InCurrentCrs . Role > = Rol_STD )
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_WARNING , Txt_You_were_already_enroled_as_X_in_the_course_Y ,
2019-02-16 01:20:54 +01:00
Txt_ROLES_SINGUL_abc [ Gbl . Usrs . Me . UsrDat . Roles . InCurrentCrs . Role ] [ Gbl . Usrs . Me . UsrDat . Sex ] ,
Gbl . CurrentCrs . Crs . FullName ) ;
2017-06-04 18:18:54 +02:00
else if ( Gbl . Usrs . Me . Role . Logged = = Rol_GST | |
Gbl . Usrs . Me . Role . Logged = = Rol_USR )
2014-12-12 18:52:06 +01:00
/***** Show form to modify only the user's role or the user's data *****/
2017-05-30 02:17:33 +02:00
Rec_ShowFormSignUpInCrsWithMySharedRecord ( ) ;
2014-12-12 18:52:06 +01:00
else
Lay_ShowErrorAndExit ( " You must be logged to sign up in a course. " ) ; // This never should happen
}
/*****************************************************************************/
/*********************** Sign up in the current course ***********************/
/*****************************************************************************/
void Enr_SignUpInCrs ( void )
{
2017-03-30 11:20:06 +02:00
extern const char * Txt_You_were_already_enroled_as_X_in_the_course_Y ;
2015-03-12 14:45:40 +01:00
extern const char * Txt_ROLES_SINGUL_abc [ Rol_NUM_ROLES ] [ Usr_NUM_SEXS ] ;
2017-03-30 11:20:06 +02:00
extern const char * Txt_Your_request_for_enrolment_as_X_in_the_course_Y_has_been_accepted_for_processing ;
2014-12-12 18:52:06 +01:00
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
Rol_Role_t RoleFromForm ;
long ReqCod = - 1L ;
/***** Check if I already belong to course *****/
2017-06-08 15:32:33 +02:00
if ( Gbl . Usrs . Me . UsrDat . Roles . InCurrentCrs . Role > = Rol_STD )
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_WARNING , Txt_You_were_already_enroled_as_X_in_the_course_Y ,
2019-02-16 01:20:54 +01:00
Txt_ROLES_SINGUL_abc [ Gbl . Usrs . Me . UsrDat . Roles . InCurrentCrs . Role ] [ Gbl . Usrs . Me . UsrDat . Sex ] ,
Gbl . CurrentCrs . Crs . FullName ) ;
2014-12-12 18:52:06 +01:00
else
{
/***** Get new role from record form *****/
2017-01-29 21:41:08 +01:00
RoleFromForm = ( Rol_Role_t )
Par_GetParToUnsignedLong ( " Role " ,
0 ,
Rol_NUM_ROLES - 1 ,
2017-05-18 19:13:41 +02:00
( unsigned long ) Rol_UNK ) ;
2014-12-12 18:52:06 +01:00
/* Check if role is correct */
2017-05-18 19:13:41 +02:00
if ( ! ( RoleFromForm = = Rol_STD | |
2017-05-22 00:51:45 +02:00
RoleFromForm = = Rol_NET | |
2017-05-18 19:13:41 +02:00
RoleFromForm = = Rol_TCH ) )
2014-12-12 18:52:06 +01:00
Lay_ShowErrorAndExit ( " Wrong role. " ) ;
/***** Try to get and old request of the same user in the same course from database *****/
2018-10-30 17:47:57 +01:00
if ( DB_QuerySELECT ( & mysql_res , " can not get enrolment request " ,
" SELECT ReqCod FROM crs_usr_requests "
" WHERE CrsCod=%ld AND UsrCod=%ld " ,
Gbl . CurrentCrs . Crs . CrsCod ,
Gbl . Usrs . Me . UsrDat . UsrCod ) )
2014-12-12 18:52:06 +01:00
{
row = mysql_fetch_row ( mysql_res ) ;
/* Get request code (row[0]) */
ReqCod = Str_ConvertStrCodToLongCod ( row [ 0 ] ) ;
}
/* Free structure that stores the query result */
DB_FreeMySQLResult ( & mysql_res ) ;
/***** Request user in current course in database *****/
if ( ReqCod > 0 ) // Old request exists in database
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ( " can not update enrolment request " ,
" UPDATE crs_usr_requests SET Role=%u,RequestTime=NOW() "
" WHERE ReqCod=%ld AND CrsCod=%ld AND UsrCod=%ld " ,
( unsigned ) RoleFromForm ,
ReqCod ,
Gbl . CurrentCrs . Crs . CrsCod ,
Gbl . Usrs . Me . UsrDat . UsrCod ) ;
2014-12-12 18:52:06 +01:00
else // No request in database for this user in this course
2018-11-03 01:45:36 +01:00
ReqCod =
DB_QueryINSERTandReturnCode ( " can not save enrolment request " ,
" INSERT INTO crs_usr_requests "
" (CrsCod,UsrCod,Role,RequestTime) "
" VALUES "
" (%ld,%ld,%u,NOW()) " ,
Gbl . CurrentCrs . Crs . CrsCod ,
Gbl . Usrs . Me . UsrDat . UsrCod ,
( unsigned ) RoleFromForm ) ;
2014-12-12 18:52:06 +01:00
/***** Show confirmation message *****/
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_SUCCESS , Txt_Your_request_for_enrolment_as_X_in_the_course_Y_has_been_accepted_for_processing ,
2019-02-16 01:20:54 +01:00
Txt_ROLES_SINGUL_abc [ RoleFromForm ] [ Gbl . Usrs . Me . UsrDat . Sex ] ,
Gbl . CurrentCrs . Crs . FullName ) ;
2014-12-12 18:52:06 +01:00
2017-03-30 11:20:06 +02:00
/***** Notify teachers or admins by email about the new enrolment request *****/
2014-12-12 18:52:06 +01:00
// If this course has teachers ==> send notification to teachers
// If this course has no teachers and I want to be a teacher ==> send notification to administrators or superusers
2017-05-21 14:43:10 +02:00
if ( Gbl . CurrentCrs . Crs . NumUsrs [ Rol_TCH ] | |
RoleFromForm = = Rol_TCH )
2017-05-18 13:36:23 +02:00
Ntf_StoreNotifyEventsToAllUsrs ( Ntf_EVENT_ENROLMENT_REQUEST , ReqCod ) ;
2014-12-12 18:52:06 +01:00
}
}
/*****************************************************************************/
2017-03-30 11:20:06 +02:00
/************** Put an enrolment request into a notification *****************/
2014-12-12 18:52:06 +01:00
/*****************************************************************************/
2017-03-30 11:20:06 +02:00
void Enr_GetNotifEnrolmentRequest ( char SummaryStr [ Ntf_MAX_BYTES_SUMMARY + 1 ] ,
char * * ContentStr ,
long ReqCod , bool GetContent )
2014-12-12 18:52:06 +01:00
{
2015-03-12 14:45:40 +01:00
extern const char * Txt_ROLES_SINGUL_Abc [ Rol_NUM_ROLES ] [ Usr_NUM_SEXS ] ;
2014-12-12 18:52:06 +01:00
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
struct UsrData UsrDat ;
Rol_Role_t DesiredRole ;
SummaryStr [ 0 ] = ' \0 ' ; // Return nothing on error
2018-10-20 21:19:30 +02:00
// This function may be called inside a web service, so don't report error
2014-12-12 18:52:06 +01:00
/***** Get user and requested role from database *****/
2018-10-30 17:47:57 +01:00
if ( DB_QuerySELECT ( & mysql_res , " can not get enrolment request " ,
" SELECT UsrCod,Role "
" FROM crs_usr_requests "
" WHERE ReqCod=%ld " ,
ReqCod ) = = 1 ) // Result should have a unique row
2018-10-20 21:19:30 +02:00
{
/***** Get user and requested role *****/
row = mysql_fetch_row ( mysql_res ) ;
2014-12-12 18:52:06 +01:00
2018-10-20 21:19:30 +02:00
/* Initialize structure with user's data */
Usr_UsrDataConstructor ( & UsrDat ) ;
2014-12-12 18:52:06 +01:00
2018-10-20 21:19:30 +02:00
/* User's code (row[0]) */
UsrDat . UsrCod = Str_ConvertStrCodToLongCod ( row [ 0 ] ) ;
Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod ( & UsrDat ) ;
/* Role (row[1]) */
DesiredRole = Rol_ConvertUnsignedStrToRole ( row [ 1 ] ) ;
Str_Copy ( SummaryStr , Txt_ROLES_SINGUL_Abc [ DesiredRole ] [ UsrDat . Sex ] ,
Ntf_MAX_BYTES_SUMMARY ) ;
if ( GetContent )
/* Write desired role into content */
if ( asprintf ( ContentStr ,
" %s " , // TODO: Write more info in this content
Txt_ROLES_SINGUL_Abc [ DesiredRole ] [ UsrDat . Sex ] ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
/* Free memory used for user's data */
Usr_UsrDataDestructor ( & UsrDat ) ;
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult ( & mysql_res ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
2017-04-28 09:43:32 +02:00
/******* Ask if reject the request for enrolment of a user in a course *******/
2014-12-12 18:52:06 +01:00
/*****************************************************************************/
void Enr_AskIfRejectSignUp ( void )
{
2017-03-30 11:20:06 +02:00
extern const char * Txt_THE_USER_X_is_already_enroled_in_the_course_Y ;
extern const char * Txt_Do_you_really_want_to_reject_the_enrolment_request_ ;
2015-03-12 14:45:40 +01:00
extern const char * Txt_ROLES_SINGUL_abc [ Rol_NUM_ROLES ] [ Usr_NUM_SEXS ] ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_Reject ;
Rol_Role_t Role ;
/***** Get user's code *****/
2016-01-25 14:40:57 +01:00
Usr_GetParamOtherUsrCodEncryptedAndGetListIDs ( ) ;
2014-12-12 18:52:06 +01:00
if ( Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod ( & Gbl . Usrs . Other . UsrDat ) ) // If user's data exist...
{
2017-06-09 15:04:02 +02:00
if ( Usr_CheckIfUsrBelongsToCurrentCrs ( & Gbl . Usrs . Other . UsrDat ) )
2014-12-12 18:52:06 +01:00
{
/* User already belongs to this course */
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_WARNING , Txt_THE_USER_X_is_already_enroled_in_the_course_Y ,
2019-02-16 01:20:54 +01:00
Gbl . Usrs . Other . UsrDat . FullName , Gbl . CurrentCrs . Crs . FullName ) ;
2016-11-18 01:07:00 +01:00
Rec_ShowSharedRecordUnmodifiable ( & Gbl . Usrs . Other . UsrDat ) ;
2014-12-12 18:52:06 +01:00
/* Remove inscription request because it has not sense */
2017-03-30 11:20:06 +02:00
Enr_RemoveEnrolmentRequest ( Gbl . CurrentCrs . Crs . CrsCod , Gbl . Usrs . Other . UsrDat . UsrCod ) ;
2014-12-12 18:52:06 +01:00
}
else // User does not belong to this course
{
2014-12-12 22:39:55 +01:00
Role = Rol_GetRequestedRole ( Gbl . Usrs . Other . UsrDat . UsrCod ) ;
2017-05-18 19:13:41 +02:00
if ( Role = = Rol_STD | |
2017-05-22 00:51:45 +02:00
Role = = Rol_NET | |
2017-05-18 19:13:41 +02:00
Role = = Rol_TCH )
2014-12-12 18:52:06 +01:00
{
2017-04-28 09:43:32 +02:00
/***** Show question and button to reject user's enrolment request *****/
/* Start alert */
2019-02-17 01:14:55 +01:00
Ale_ShowAlertAndButton1 ( Ale_QUESTION , Txt_Do_you_really_want_to_reject_the_enrolment_request_ ,
Gbl . Usrs . Other . UsrDat . FullName ,
Txt_ROLES_SINGUL_abc [ Role ] [ Gbl . Usrs . Other . UsrDat . Sex ] ,
Gbl . CurrentCrs . Crs . FullName ) ;
2014-12-12 18:52:06 +01:00
2017-04-28 09:43:32 +02:00
/* Show user's record */
Rec_ShowSharedRecordUnmodifiable ( & Gbl . Usrs . Other . UsrDat ) ;
2014-12-12 18:52:06 +01:00
2017-04-28 09:43:32 +02:00
/* End alert */
2017-05-25 14:25:22 +02:00
Ale_ShowAlertAndButton2 ( ActRejSignUp , NULL , NULL ,
2017-04-28 10:35:41 +02:00
Usr_PutParamOtherUsrCodEncrypted ,
2017-06-11 19:02:40 +02:00
Btn_REMOVE_BUTTON , Txt_Reject ) ;
2014-12-12 18:52:06 +01:00
}
else
Lay_ShowErrorAndExit ( " Wrong role. " ) ;
}
}
else
2019-02-16 20:07:52 +01:00
Acc_ShowAlertUserNotFoundOrYouDoNotHavePermission ( ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
2017-03-30 11:20:06 +02:00
/********* Reject the request for enrolment of a user in a course ***********/
2014-12-12 18:52:06 +01:00
/*****************************************************************************/
void Enr_RejectSignUp ( void )
{
2017-03-30 11:20:06 +02:00
extern const char * Txt_THE_USER_X_is_already_enroled_in_the_course_Y ;
extern const char * Txt_Enrolment_of_X_rejected ;
2014-12-12 18:52:06 +01:00
/***** Get user's code *****/
2016-01-25 14:40:57 +01:00
Usr_GetParamOtherUsrCodEncryptedAndGetListIDs ( ) ;
2014-12-12 18:52:06 +01:00
if ( Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod ( & Gbl . Usrs . Other . UsrDat ) ) // If user's data exist...
{
2017-06-09 15:04:02 +02:00
if ( Usr_CheckIfUsrBelongsToCurrentCrs ( & Gbl . Usrs . Other . UsrDat ) )
2014-12-12 18:52:06 +01:00
{
/* User already belongs to this course */
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_WARNING , Txt_THE_USER_X_is_already_enroled_in_the_course_Y ,
2019-02-16 01:20:54 +01:00
Gbl . Usrs . Other . UsrDat . FullName , Gbl . CurrentCrs . Crs . FullName ) ;
2016-11-18 01:07:00 +01:00
Rec_ShowSharedRecordUnmodifiable ( & Gbl . Usrs . Other . UsrDat ) ;
2014-12-12 18:52:06 +01:00
}
/* Remove inscription request */
2017-03-30 11:20:06 +02:00
Enr_RemoveEnrolmentRequest ( Gbl . CurrentCrs . Crs . CrsCod , Gbl . Usrs . Other . UsrDat . UsrCod ) ;
2014-12-12 18:52:06 +01:00
/* Confirmation message */
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_SUCCESS , Txt_Enrolment_of_X_rejected ,
2019-02-16 01:20:54 +01:00
Gbl . Usrs . Other . UsrDat . FullName ) ;
2014-12-12 18:52:06 +01:00
}
else
2019-02-16 20:07:52 +01:00
Acc_ShowAlertUserNotFoundOrYouDoNotHavePermission ( ) ;
2014-12-12 18:52:06 +01:00
/* Show again the rest of registrarion requests */
2017-03-30 11:20:06 +02:00
Enr_ShowEnrolmentRequests ( ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
2017-03-30 11:20:06 +02:00
/******** Show pending requests for enrolment in the current course *********/
2014-12-12 18:52:06 +01:00
/*****************************************************************************/
2017-03-30 11:20:06 +02:00
void Enr_ShowEnrolmentRequests ( void )
2016-03-24 15:09:52 +01:00
{
2017-03-30 11:20:06 +02:00
/***** Show enrolment request (default roles depend on my logged role) *****/
2017-06-04 18:18:54 +02:00
switch ( Gbl . Usrs . Me . Role . Logged )
2016-03-24 15:09:52 +01:00
{
2017-05-18 19:13:41 +02:00
case Rol_TCH :
Enr_ShowEnrolmentRequestsGivenRoles ( ( 1 < < Rol_STD ) |
2017-05-22 00:51:45 +02:00
( 1 < < Rol_NET ) |
( 1 < < Rol_TCH ) ) ;
2016-03-24 15:09:52 +01:00
break ;
case Rol_DEG_ADM :
case Rol_CTR_ADM :
case Rol_INS_ADM :
case Rol_SYS_ADM :
2017-05-22 00:51:45 +02:00
Enr_ShowEnrolmentRequestsGivenRoles ( ( 1 < < Rol_NET ) |
( 1 < < Rol_TCH ) ) ;
2016-03-24 15:09:52 +01:00
break ;
default :
2019-02-16 20:44:31 +01:00
Lay_NoPermissionExit ( ) ;
2016-03-24 15:09:52 +01:00
break ;
}
}
/*****************************************************************************/
2017-03-30 11:20:06 +02:00
/******* Update pending requests for enrolment in the current course ********/
2016-03-24 15:09:52 +01:00
/*****************************************************************************/
2017-03-30 11:20:06 +02:00
void Enr_UpdateEnrolmentRequests ( void )
2016-03-24 15:09:52 +01:00
{
2016-03-24 17:12:01 +01:00
unsigned RolesSelected ;
2016-03-24 15:09:52 +01:00
/***** Get selected roles *****/
2016-03-24 17:12:01 +01:00
RolesSelected = Rol_GetSelectedRoles ( ) ;
2016-03-24 15:09:52 +01:00
2017-03-30 11:20:06 +02:00
/***** Update enrolment requests *****/
Enr_ShowEnrolmentRequestsGivenRoles ( RolesSelected ) ;
2016-03-24 15:09:52 +01:00
}
/*****************************************************************************/
2017-03-30 11:20:06 +02:00
/************* Show pending requests for enrolment given roles **************/
2016-03-24 15:09:52 +01:00
/*****************************************************************************/
2017-03-30 11:20:06 +02:00
static void Enr_ShowEnrolmentRequestsGivenRoles ( unsigned RolesSelected )
2014-12-12 18:52:06 +01:00
{
2016-11-21 19:47:44 +01:00
extern const char * Hlp_USERS_Requests ;
2016-10-27 22:16:03 +02:00
extern const char * Sco_ScopeDB [ Sco_NUM_SCOPES ] ;
2019-02-22 21:47:50 +01:00
extern const char * The_ClassFormInBox [ The_NUM_THEMES ] ;
2017-03-30 11:20:06 +02:00
extern const char * Txt_Enrolment_requests ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_Scope ;
extern const char * Txt_Users ;
extern const char * Txt_Course ;
2017-05-30 21:43:05 +02:00
extern const char * Txt_ROLES_PLURAL_BRIEF_Abc [ Rol_NUM_ROLES ] ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_Requester ;
extern const char * Txt_Role ;
extern const char * Txt_Date ;
extern const char * Txt_Go_to_X ;
2015-03-12 14:45:40 +01:00
extern const char * Txt_ROLES_SINGUL_abc [ Rol_NUM_ROLES ] [ Usr_NUM_SEXS ] ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_Register ;
extern const char * Txt_Reject ;
2017-03-30 11:20:06 +02:00
extern const char * Txt_No_enrolment_requests ;
2014-12-12 18:52:06 +01:00
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
2018-10-30 17:47:57 +01:00
unsigned long NumReqs = 0 ; // Initialized to avoid warning
unsigned long NumReq ;
2014-12-12 18:52:06 +01:00
long ReqCod ;
struct Degree Deg ;
struct Course Crs ;
struct UsrData UsrDat ;
bool UsrExists ;
bool UsrBelongsToCrs ;
bool ShowPhoto = false ;
2017-01-28 15:58:46 +01:00
char PhotoURL [ PATH_MAX + 1 ] ;
2014-12-12 18:52:06 +01:00
Rol_Role_t DesiredRole ;
2017-05-22 00:51:45 +02:00
Act_Action_t NextAction ;
2014-12-12 18:52:06 +01:00
2017-03-30 11:20:06 +02:00
/***** Remove expired enrolment requests *****/
Enr_RemoveExpiredEnrolmentRequests ( ) ;
2016-03-27 20:33:39 +02:00
2016-03-24 16:49:36 +01:00
/***** Get scope *****/
Gbl . Scope . Allowed = 1 < < Sco_SCOPE_SYS |
1 < < Sco_SCOPE_CTY |
1 < < Sco_SCOPE_INS |
1 < < Sco_SCOPE_CTR |
1 < < Sco_SCOPE_DEG |
1 < < Sco_SCOPE_CRS ;
Gbl . Scope . Default = Sco_SCOPE_CRS ;
2016-06-24 20:34:58 +02:00
Sco_GetScope ( " ScopeEnr " ) ;
2016-03-24 16:49:36 +01:00
2017-06-12 14:16:33 +02:00
/***** Start box *****/
2017-06-10 21:38:10 +02:00
Box_StartBox ( " 100% " , Txt_Enrolment_requests , NULL ,
2017-06-12 15:03:29 +02:00
Hlp_USERS_Requests , Box_NOT_CLOSABLE ) ;
2015-10-04 16:24:10 +02:00
2014-12-12 18:52:06 +01:00
/***** Selection of scope and roles *****/
2017-05-01 12:36:24 +02:00
/* Start form and table */
2018-11-09 20:47:39 +01:00
Frm_StartForm ( ActUpdSignUpReq ) ;
2017-06-11 20:09:59 +02:00
Tbl_StartTableWideMargin ( 2 ) ;
2014-12-12 18:52:06 +01:00
/* Scope (whole platform, current centre, current degree or current course) */
fprintf ( Gbl . F . Out , " <tr> "
2016-03-27 21:36:52 +02:00
" <td class= \" RIGHT_MIDDLE \" > "
2016-12-20 02:18:50 +01:00
" <label for= \" ScopeEnr \" class= \" %s \" >%s:</label> "
2014-12-22 21:52:37 +01:00
" </td> "
2015-08-01 08:40:58 +02:00
" <td class= \" LEFT_MIDDLE \" > " ,
2019-02-22 21:47:50 +01:00
The_ClassFormInBox [ Gbl . Prefs . Theme ] , Txt_Scope ) ;
2016-06-24 20:34:58 +02:00
Sco_PutSelectorScope ( " ScopeEnr " , true ) ;
2014-12-12 18:52:06 +01:00
fprintf ( Gbl . F . Out , " </td> "
" </tr> " ) ;
/* Users' roles in listing */
fprintf ( Gbl . F . Out , " <tr> "
2016-03-27 21:36:52 +02:00
" <td class= \" RIGHT_TOP \" > "
" <label class= \" %s \" >%s:</label> "
2014-12-22 21:52:37 +01:00
" </td> "
2015-08-01 08:40:58 +02:00
" <td class= \" DAT LEFT_MIDDLE \" > " ,
2019-02-22 21:47:50 +01:00
The_ClassFormInBox [ Gbl . Prefs . Theme ] , Txt_Users ) ;
2017-05-18 19:13:41 +02:00
Rol_WriteSelectorRoles ( 1 < < Rol_STD |
2017-05-22 00:51:45 +02:00
1 < < Rol_NET |
2017-05-18 19:13:41 +02:00
1 < < Rol_TCH ,
2016-03-24 17:12:01 +01:00
RolesSelected ,
2016-03-24 16:49:36 +01:00
false , true ) ;
2014-12-12 18:52:06 +01:00
fprintf ( Gbl . F . Out , " </td> "
2017-05-01 12:36:24 +02:00
" </tr> " ) ;
2015-03-24 20:26:31 +01:00
2017-05-01 12:36:24 +02:00
/* End table and form */
2017-06-11 20:09:59 +02:00
Tbl_EndTable ( ) ;
2018-11-09 20:47:39 +01:00
Frm_EndForm ( ) ;
2014-12-12 18:52:06 +01:00
/***** Build query *****/
switch ( Gbl . Scope . Current )
{
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_SYS : // Show requesters for the whole platform
2017-06-04 18:18:54 +02:00
switch ( Gbl . Usrs . Me . Role . Logged )
2014-12-12 18:52:06 +01:00
{
2017-05-18 19:13:41 +02:00
case Rol_TCH :
2018-10-20 21:19:30 +02:00
// Requests in all courses in which I am teacher
2018-10-30 17:47:57 +01:00
NumReqs = DB_QuerySELECT ( & mysql_res , " can not get requests "
" for enrolment " ,
" SELECT crs_usr_requests.ReqCod, "
" crs_usr_requests.CrsCod, "
" crs_usr_requests.UsrCod, "
" crs_usr_requests.Role, "
" UNIX_TIMESTAMP(crs_usr_requests.RequestTime) "
" FROM crs_usr,crs_usr_requests "
" WHERE crs_usr.UsrCod=%ld "
" AND crs_usr.Role=%u "
" AND crs_usr.CrsCod=crs_usr_requests.CrsCod "
" AND ((1<<crs_usr_requests.Role)&%u)<>0 "
" ORDER BY crs_usr_requests.RequestTime DESC " ,
Gbl . Usrs . Me . UsrDat . UsrCod ,
( unsigned ) Rol_TCH ,
RolesSelected ) ;
2014-12-12 18:52:06 +01:00
break ;
2015-04-07 21:44:24 +02:00
case Rol_DEG_ADM :
2018-10-20 21:19:30 +02:00
// Requests in all degrees administrated by me
2018-10-30 17:47:57 +01:00
NumReqs = DB_QuerySELECT ( & mysql_res , " can not get requests "
" for enrolment " ,
" SELECT crs_usr_requests.ReqCod, "
" crs_usr_requests.CrsCod, "
" crs_usr_requests.UsrCod, "
" crs_usr_requests.Role, "
" UNIX_TIMESTAMP(crs_usr_requests.RequestTime) "
" FROM admin,courses,crs_usr_requests "
" WHERE admin.UsrCod=%ld AND admin.Scope='%s' "
" AND admin.Cod=courses.DegCod "
" AND courses.CrsCod=crs_usr_requests.CrsCod "
" AND ((1<<crs_usr_requests.Role)&%u)<>0 "
" ORDER BY crs_usr_requests.RequestTime DESC " ,
Gbl . Usrs . Me . UsrDat . UsrCod , Sco_ScopeDB [ Sco_SCOPE_DEG ] ,
RolesSelected ) ;
2014-12-12 18:52:06 +01:00
break ;
2015-09-27 02:15:48 +02:00
case Rol_CTR_ADM :
2018-10-20 21:19:30 +02:00
// Requests in all centres administrated by me
2018-10-30 17:47:57 +01:00
NumReqs = DB_QuerySELECT ( & mysql_res , " can not get requests "
" for enrolment " ,
" SELECT crs_usr_requests.ReqCod, "
" crs_usr_requests.CrsCod, "
" crs_usr_requests.UsrCod, "
" crs_usr_requests.Role, "
" UNIX_TIMESTAMP(crs_usr_requests.RequestTime) "
" FROM admin,degrees,courses,crs_usr_requests "
" WHERE admin.UsrCod=%ld AND admin.Scope='%s' "
" AND admin.Cod=degrees.CtrCod "
" AND degrees.DegCod=courses.DegCod "
" AND courses.CrsCod=crs_usr_requests.CrsCod "
" AND ((1<<crs_usr_requests.Role)&%u)<>0 "
" ORDER BY crs_usr_requests.RequestTime DESC " ,
Gbl . Usrs . Me . UsrDat . UsrCod , Sco_ScopeDB [ Sco_SCOPE_CTR ] ,
RolesSelected ) ;
2015-09-27 02:15:48 +02:00
break ;
case Rol_INS_ADM :
2018-10-20 21:19:30 +02:00
// Requests in all institutions administrated by me
2018-10-30 17:47:57 +01:00
NumReqs = DB_QuerySELECT ( & mysql_res , " can not get requests "
" for enrolment " ,
" SELECT crs_usr_requests.ReqCod, "
" crs_usr_requests.CrsCod, "
" crs_usr_requests.UsrCod, "
" crs_usr_requests.Role, "
" UNIX_TIMESTAMP(crs_usr_requests.RequestTime) "
" FROM admin,centres,degrees,courses,crs_usr_requests "
" WHERE admin.UsrCod=%ld AND admin.Scope='%s' "
" AND admin.Cod=centres.InsCod "
" AND centres.CtrCod=degrees.CtrCod "
" AND degrees.DegCod=courses.DegCod "
" AND courses.CrsCod=crs_usr_requests.CrsCod "
" AND ((1<<crs_usr_requests.Role)&%u)<>0 "
" ORDER BY crs_usr_requests.RequestTime DESC " ,
Gbl . Usrs . Me . UsrDat . UsrCod , Sco_ScopeDB [ Sco_SCOPE_INS ] ,
RolesSelected ) ;
2015-09-27 02:15:48 +02:00
break ;
2015-04-07 21:44:24 +02:00
case Rol_SYS_ADM :
2018-10-20 21:19:30 +02:00
// All requests
2018-10-30 17:47:57 +01:00
NumReqs = DB_QuerySELECT ( & mysql_res , " can not get requests "
" for enrolment " ,
" SELECT ReqCod, "
" CrsCod, "
" UsrCod, "
" Role, "
" UNIX_TIMESTAMP(RequestTime) "
" FROM crs_usr_requests "
" WHERE ((1<<Role)&%u)<>0 "
" ORDER BY RequestTime DESC " ,
RolesSelected ) ;
2014-12-12 18:52:06 +01:00
break ;
default :
2019-02-16 20:44:31 +01:00
Lay_NoPermissionExit ( ) ;
2014-12-12 18:52:06 +01:00
break ;
}
break ;
2015-12-15 02:55:45 +01:00
case Sco_SCOPE_CTY : // Show requesters for the current country
2017-06-04 18:18:54 +02:00
switch ( Gbl . Usrs . Me . Role . Logged )
2015-12-15 02:55:45 +01:00
{
2017-05-18 19:13:41 +02:00
case Rol_TCH :
2018-10-20 21:19:30 +02:00
// Requests in courses of this country in which I am teacher
2018-10-30 17:47:57 +01:00
NumReqs = DB_QuerySELECT ( & mysql_res , " can not get requests "
" for enrolment " ,
" SELECT crs_usr_requests.ReqCod, "
" crs_usr_requests.CrsCod, "
" crs_usr_requests.UsrCod, "
" crs_usr_requests.Role, "
" UNIX_TIMESTAMP(crs_usr_requests.RequestTime) "
" FROM crs_usr,institutions,centres,degrees,courses,crs_usr_requests "
" WHERE crs_usr.UsrCod=%ld "
" AND crs_usr.Role=%u "
" AND crs_usr.CrsCod=courses.CrsCod "
" AND courses.DegCod=degrees.DegCod "
" AND degrees.CtrCod=centres.CtrCod "
" AND centres.InsCod=institutions.InsCod "
" AND institutions.CtyCod=%ld "
" AND courses.CrsCod=crs_usr_requests.CrsCod "
" AND ((1<<crs_usr_requests.Role)&%u)<>0 "
" ORDER BY crs_usr_requests.RequestTime DESC " ,
Gbl . Usrs . Me . UsrDat . UsrCod ,
( unsigned ) Rol_TCH ,
Gbl . CurrentCty . Cty . CtyCod ,
RolesSelected ) ;
2015-12-15 02:55:45 +01:00
break ;
case Rol_DEG_ADM :
2018-10-20 21:19:30 +02:00
// Requests in degrees of this country administrated by me
2018-10-30 17:47:57 +01:00
NumReqs = DB_QuerySELECT ( & mysql_res , " can not get requests "
" for enrolment " ,
" SELECT crs_usr_requests.ReqCod, "
" crs_usr_requests.CrsCod, "
" crs_usr_requests.UsrCod, "
" crs_usr_requests.Role, "
" UNIX_TIMESTAMP(crs_usr_requests.RequestTime) "
" FROM admin,institutions,centres,degrees,courses,crs_usr_requests "
" WHERE admin.UsrCod=%ld AND admin.Scope='%s' "
" AND admin.Cod=degrees.DegCod "
" AND degrees.CtrCod=centres.CtrCod "
" AND centres.InsCod=institutions.InsCod "
" AND institutions.CtyCod=%ld "
" AND degrees.DegCod=courses.DegCod "
" AND courses.CrsCod=crs_usr_requests.CrsCod "
" AND ((1<<crs_usr_requests.Role)&%u)<>0 "
" ORDER BY crs_usr_requests.RequestTime DESC " ,
Gbl . Usrs . Me . UsrDat . UsrCod , Sco_ScopeDB [ Sco_SCOPE_DEG ] ,
Gbl . CurrentCty . Cty . CtyCod ,
RolesSelected ) ;
2015-12-15 02:55:45 +01:00
break ;
case Rol_CTR_ADM :
2018-10-20 21:19:30 +02:00
// Requests in centres of this country administrated by me
2018-10-30 17:47:57 +01:00
NumReqs = DB_QuerySELECT ( & mysql_res , " can not get requests "
" for enrolment " ,
" SELECT crs_usr_requests.ReqCod, "
" crs_usr_requests.CrsCod, "
" crs_usr_requests.UsrCod, "
" crs_usr_requests.Role, "
" UNIX_TIMESTAMP(crs_usr_requests.RequestTime) "
" FROM admin,institutions,centres,degrees,courses,crs_usr_requests "
" WHERE admin.UsrCod=%ld AND admin.Scope='%s' "
" AND admin.Cod=centres.CtrCod "
" AND centres.InsCod=institutions.InsCod "
" AND institutions.CtyCod=%ld "
" AND centres.CtrCod=degrees.CtrCod "
" AND degrees.DegCod=courses.DegCod "
" AND courses.CrsCod=crs_usr_requests.CrsCod "
" AND ((1<<crs_usr_requests.Role)&%u)<>0 "
" ORDER BY crs_usr_requests.RequestTime DESC " ,
Gbl . Usrs . Me . UsrDat . UsrCod , Sco_ScopeDB [ Sco_SCOPE_CTR ] ,
Gbl . CurrentCty . Cty . CtyCod ,
RolesSelected ) ;
2015-12-15 02:55:45 +01:00
break ;
case Rol_INS_ADM :
2018-10-20 21:19:30 +02:00
// Requests in institutions of this country administrated by me
2018-10-30 17:47:57 +01:00
NumReqs = DB_QuerySELECT ( & mysql_res , " can not get requests "
" for enrolment " ,
" SELECT crs_usr_requests.ReqCod, "
" crs_usr_requests.CrsCod, "
" crs_usr_requests.UsrCod, "
" crs_usr_requests.Role, "
" UNIX_TIMESTAMP(crs_usr_requests.RequestTime) "
" FROM admin,institutions,centres,degrees,courses,crs_usr_requests "
" WHERE admin.UsrCod=%ld AND admin.Scope='%s' "
" AND admin.Cod=institutions.InsCod "
" AND institutions.CtyCod=%ld "
" AND institutions.InsCod=centres.InsCod "
" AND centres.CtrCod=degrees.CtrCod "
" AND degrees.DegCod=courses.DegCod "
" AND courses.CrsCod=crs_usr_requests.CrsCod "
" AND ((1<<crs_usr_requests.Role)&%u)<>0 "
" ORDER BY crs_usr_requests.RequestTime DESC " ,
Gbl . Usrs . Me . UsrDat . UsrCod , Sco_ScopeDB [ Sco_SCOPE_INS ] ,
Gbl . CurrentCty . Cty . CtyCod ,
RolesSelected ) ;
2015-12-15 02:55:45 +01:00
break ;
case Rol_SYS_ADM :
2018-10-20 21:19:30 +02:00
// Requests in any course of this country
2018-10-30 17:47:57 +01:00
NumReqs = DB_QuerySELECT ( & mysql_res , " can not get requests "
" for enrolment " ,
" SELECT crs_usr_requests.ReqCod, "
" crs_usr_requests.CrsCod, "
" crs_usr_requests.UsrCod, "
" crs_usr_requests.Role, "
" UNIX_TIMESTAMP(crs_usr_requests.RequestTime) "
" FROM institutions,centres,degrees,courses,crs_usr_requests "
" WHERE institutions.CtyCod=%ld "
" AND institutions.InsCod=centres.InsCod "
" AND centres.CtrCod=degrees.CtrCod "
" AND degrees.DegCod=courses.DegCod "
" AND courses.CrsCod=crs_usr_requests.CrsCod "
" AND ((1<<crs_usr_requests.Role)&%u)<>0 "
" ORDER BY crs_usr_requests.RequestTime DESC " ,
Gbl . CurrentCty . Cty . CtyCod ,
RolesSelected ) ;
2015-12-15 02:55:45 +01:00
break ;
default :
2019-02-16 20:44:31 +01:00
Lay_NoPermissionExit ( ) ;
2015-12-15 02:55:45 +01:00
break ;
}
break ;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_INS : // Show requesters for the current institution
2017-06-04 18:18:54 +02:00
switch ( Gbl . Usrs . Me . Role . Logged )
2014-12-12 18:52:06 +01:00
{
2017-05-18 19:13:41 +02:00
case Rol_TCH :
2018-10-20 21:19:30 +02:00
// Requests in courses of this institution in which I am teacher
2018-10-30 17:47:57 +01:00
NumReqs = DB_QuerySELECT ( & mysql_res , " can not get requests "
" for enrolment " ,
" SELECT crs_usr_requests.ReqCod, "
" crs_usr_requests.CrsCod, "
" crs_usr_requests.UsrCod, "
" crs_usr_requests.Role, "
" UNIX_TIMESTAMP(crs_usr_requests.RequestTime) "
" FROM crs_usr,centres,degrees,courses,crs_usr_requests "
" WHERE crs_usr.UsrCod=%ld "
" AND crs_usr.Role=%u "
" AND crs_usr.CrsCod=courses.CrsCod "
" AND courses.DegCod=degrees.DegCod "
" AND degrees.CtrCod=centres.CtrCod "
" AND centres.InsCod=%ld "
" AND courses.CrsCod=crs_usr_requests.CrsCod "
" AND ((1<<crs_usr_requests.Role)&%u)<>0 "
" ORDER BY crs_usr_requests.RequestTime DESC " ,
Gbl . Usrs . Me . UsrDat . UsrCod ,
( unsigned ) Rol_TCH ,
Gbl . CurrentIns . Ins . InsCod ,
RolesSelected ) ;
2014-12-12 18:52:06 +01:00
break ;
2015-04-07 21:44:24 +02:00
case Rol_DEG_ADM :
2018-10-20 21:19:30 +02:00
// Requests in degrees of this institution administrated by me
2018-10-30 17:47:57 +01:00
NumReqs = DB_QuerySELECT ( & mysql_res , " can not get requests "
" for enrolment " ,
" SELECT crs_usr_requests.ReqCod, "
" crs_usr_requests.CrsCod, "
" crs_usr_requests.UsrCod, "
" crs_usr_requests.Role, "
" UNIX_TIMESTAMP(crs_usr_requests.RequestTime) "
" FROM admin,centres,degrees,courses,crs_usr_requests "
" WHERE admin.UsrCod=%ld AND admin.Scope='%s' "
" AND admin.Cod=degrees.DegCod "
" AND degrees.CtrCod=centres.CtrCod "
" AND centres.InsCod=%ld "
" AND degrees.DegCod=courses.DegCod "
" AND courses.CrsCod=crs_usr_requests.CrsCod "
" AND ((1<<crs_usr_requests.Role)&%u)<>0 "
" ORDER BY crs_usr_requests.RequestTime DESC " ,
Gbl . Usrs . Me . UsrDat . UsrCod , Sco_ScopeDB [ Sco_SCOPE_DEG ] ,
Gbl . CurrentIns . Ins . InsCod ,
RolesSelected ) ;
2014-12-12 18:52:06 +01:00
break ;
2015-09-27 02:15:48 +02:00
case Rol_CTR_ADM :
2018-10-20 21:19:30 +02:00
// Requests in centres of this institution administrated by me
2018-10-30 17:47:57 +01:00
NumReqs = DB_QuerySELECT ( & mysql_res , " can not get requests "
" for enrolment " ,
" SELECT crs_usr_requests.ReqCod, "
" crs_usr_requests.CrsCod, "
" crs_usr_requests.UsrCod, "
" crs_usr_requests.Role, "
" UNIX_TIMESTAMP(crs_usr_requests.RequestTime) "
" FROM admin,centres,degrees,courses,crs_usr_requests "
" WHERE admin.UsrCod=%ld AND admin.Scope='%s' "
" AND admin.Cod=centres.CtrCod "
" AND centres.InsCod=%ld "
" AND centres.CtrCod=degrees.CtrCod "
" AND degrees.DegCod=courses.DegCod "
" AND courses.CrsCod=crs_usr_requests.CrsCod "
" AND ((1<<crs_usr_requests.Role)&%u)<>0 "
" ORDER BY crs_usr_requests.RequestTime DESC " ,
Gbl . Usrs . Me . UsrDat . UsrCod , Sco_ScopeDB [ Sco_SCOPE_CTR ] ,
Gbl . CurrentIns . Ins . InsCod ,
RolesSelected ) ;
2015-09-27 02:15:48 +02:00
break ;
case Rol_INS_ADM : // If I am logged as admin of this institution, I can view all the requesters from this institution
case Rol_SYS_ADM :
2015-12-15 02:55:45 +01:00
// Requests in any course of this institution
2018-10-30 17:47:57 +01:00
NumReqs = DB_QuerySELECT ( & mysql_res , " can not get requests "
" for enrolment " ,
" SELECT crs_usr_requests.ReqCod, "
" crs_usr_requests.CrsCod, "
" crs_usr_requests.UsrCod, "
" crs_usr_requests.Role, "
" UNIX_TIMESTAMP(crs_usr_requests.RequestTime) "
" FROM centres,degrees,courses,crs_usr_requests "
" WHERE centres.InsCod=%ld "
" AND centres.CtrCod=degrees.CtrCod "
" AND degrees.DegCod=courses.DegCod "
" AND courses.CrsCod=crs_usr_requests.CrsCod "
" AND ((1<<crs_usr_requests.Role)&%u)<>0 "
" ORDER BY crs_usr_requests.RequestTime DESC " ,
Gbl . CurrentIns . Ins . InsCod ,
RolesSelected ) ;
2014-12-12 18:52:06 +01:00
break ;
default :
2019-02-16 20:44:31 +01:00
Lay_NoPermissionExit ( ) ;
2014-12-12 18:52:06 +01:00
break ;
}
break ;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_CTR : // Show requesters for the current centre
2017-06-04 18:18:54 +02:00
switch ( Gbl . Usrs . Me . Role . Logged )
2014-12-12 18:52:06 +01:00
{
2017-05-18 19:13:41 +02:00
case Rol_TCH :
2018-10-20 21:19:30 +02:00
// Requests in courses of this centre in which I am teacher
2018-10-30 17:47:57 +01:00
NumReqs = DB_QuerySELECT ( & mysql_res , " can not get requests "
" for enrolment " ,
" SELECT crs_usr_requests.ReqCod, "
" crs_usr_requests.CrsCod, "
" crs_usr_requests.UsrCod, "
" crs_usr_requests.Role, "
" UNIX_TIMESTAMP(crs_usr_requests.RequestTime) "
" FROM crs_usr,degrees,courses,crs_usr_requests "
" WHERE crs_usr.UsrCod=%ld "
" AND crs_usr.Role=%u "
" AND crs_usr.CrsCod=courses.CrsCod "
" AND courses.DegCod=degrees.DegCod "
" AND degrees.CtrCod=%ld "
" AND courses.CrsCod=crs_usr_requests.CrsCod "
" AND ((1<<crs_usr_requests.Role)&%u)<>0 "
" ORDER BY crs_usr_requests.RequestTime DESC " ,
Gbl . Usrs . Me . UsrDat . UsrCod ,
( unsigned ) Rol_TCH ,
Gbl . CurrentCtr . Ctr . CtrCod ,
RolesSelected ) ;
2014-12-12 18:52:06 +01:00
break ;
2015-04-07 21:44:24 +02:00
case Rol_DEG_ADM :
2018-10-20 21:19:30 +02:00
// Requests in degrees of this centre administrated by me
2018-10-30 17:47:57 +01:00
NumReqs = DB_QuerySELECT ( & mysql_res , " can not get requests "
" for enrolment " ,
" SELECT crs_usr_requests.ReqCod, "
" crs_usr_requests.CrsCod, "
" crs_usr_requests.UsrCod, "
" crs_usr_requests.Role, "
" UNIX_TIMESTAMP(crs_usr_requests.RequestTime) "
" FROM admin,degrees,courses,crs_usr_requests "
" WHERE admin.UsrCod=%ld AND admin.Scope='%s' "
" AND admin.Cod=degrees.DegCod "
" AND degrees.CtrCod=%ld "
" AND degrees.DegCod=courses.DegCod "
" AND courses.CrsCod=crs_usr_requests.CrsCod "
" AND ((1<<crs_usr_requests.Role)&%u)<>0 "
" ORDER BY crs_usr_requests.RequestTime DESC " ,
Gbl . Usrs . Me . UsrDat . UsrCod , Sco_ScopeDB [ Sco_SCOPE_DEG ] ,
Gbl . CurrentCtr . Ctr . CtrCod ,
RolesSelected ) ;
2014-12-12 18:52:06 +01:00
break ;
2015-09-27 02:15:48 +02:00
case Rol_CTR_ADM : // If I am logged as admin of this centre , I can view all the requesters from this centre
case Rol_INS_ADM : // If I am logged as admin of this institution, I can view all the requesters from this centre
case Rol_SYS_ADM :
2015-12-15 02:55:45 +01:00
// Request in any course of this centre
2018-10-30 17:47:57 +01:00
NumReqs = DB_QuerySELECT ( & mysql_res , " can not get requests "
" for enrolment " ,
" SELECT crs_usr_requests.ReqCod, "
" crs_usr_requests.CrsCod, "
" crs_usr_requests.UsrCod, "
" crs_usr_requests.Role, "
" UNIX_TIMESTAMP(crs_usr_requests.RequestTime) "
" FROM degrees,courses,crs_usr_requests "
" WHERE degrees.CtrCod=%ld "
" AND degrees.DegCod=courses.DegCod "
" AND courses.CrsCod=crs_usr_requests.CrsCod "
" AND ((1<<crs_usr_requests.Role)&%u)<>0 "
" ORDER BY crs_usr_requests.RequestTime DESC " ,
Gbl . CurrentCtr . Ctr . CtrCod ,
RolesSelected ) ;
2014-12-12 18:52:06 +01:00
break ;
default :
2019-02-16 20:44:31 +01:00
Lay_NoPermissionExit ( ) ;
2014-12-12 18:52:06 +01:00
break ;
}
break ;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_DEG : // Show requesters for the current degree
2017-06-04 18:18:54 +02:00
switch ( Gbl . Usrs . Me . Role . Logged )
2014-12-12 18:52:06 +01:00
{
2017-05-18 19:13:41 +02:00
case Rol_TCH :
2018-10-20 21:19:30 +02:00
// Requests in courses of this degree in which I am teacher
2018-10-30 17:47:57 +01:00
NumReqs = DB_QuerySELECT ( & mysql_res , " can not get requests "
" for enrolment " ,
" SELECT crs_usr_requests.ReqCod, "
" crs_usr_requests.CrsCod, "
" crs_usr_requests.UsrCod, "
" crs_usr_requests.Role, "
" UNIX_TIMESTAMP(crs_usr_requests.RequestTime) "
" FROM crs_usr,courses,crs_usr_requests "
" WHERE crs_usr.UsrCod=%ld "
" AND crs_usr.Role=%u "
" AND crs_usr.CrsCod=courses.CrsCod "
" AND courses.DegCod=%ld "
" AND courses.CrsCod=crs_usr_requests.CrsCod "
" AND ((1<<crs_usr_requests.Role)&%u)<>0 "
" ORDER BY crs_usr_requests.RequestTime DESC " ,
Gbl . Usrs . Me . UsrDat . UsrCod ,
( unsigned ) Rol_TCH ,
Gbl . CurrentDeg . Deg . DegCod ,
RolesSelected ) ;
2014-12-12 18:52:06 +01:00
break ;
2015-09-27 02:15:48 +02:00
case Rol_DEG_ADM : // If I am logged as admin of this degree , I can view all the requesters from this degree
case Rol_CTR_ADM : // If I am logged as admin of this centre , I can view all the requesters from this degree
case Rol_INS_ADM : // If I am logged as admin of this institution, I can view all the requesters from this degree
2015-04-07 21:44:24 +02:00
case Rol_SYS_ADM :
2015-12-15 02:55:45 +01:00
// Requests in any course of this degree
2018-10-30 17:47:57 +01:00
NumReqs = DB_QuerySELECT ( & mysql_res , " can not get requests "
" for enrolment " ,
" SELECT crs_usr_requests.ReqCod, "
" crs_usr_requests.CrsCod, "
" crs_usr_requests.UsrCod, "
" crs_usr_requests.Role, "
" UNIX_TIMESTAMP(crs_usr_requests.RequestTime) "
" FROM courses,crs_usr_requests "
" WHERE courses.DegCod=%ld "
" AND courses.CrsCod=crs_usr_requests.CrsCod "
" AND ((1<<crs_usr_requests.Role)&%u)<>0 "
" ORDER BY crs_usr_requests.RequestTime DESC " ,
Gbl . CurrentDeg . Deg . DegCod ,
RolesSelected ) ;
2014-12-12 18:52:06 +01:00
break ;
default :
2019-02-16 20:44:31 +01:00
Lay_NoPermissionExit ( ) ;
2014-12-12 18:52:06 +01:00
break ;
}
break ;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_CRS : // Show requesters for the current course
2017-06-04 18:18:54 +02:00
switch ( Gbl . Usrs . Me . Role . Logged )
2014-12-12 18:52:06 +01:00
{
2017-05-18 19:13:41 +02:00
case Rol_TCH : // If I am logged as teacher of this course , I can view all the requesters from this course
2015-09-27 02:15:48 +02:00
case Rol_DEG_ADM : // If I am logged as admin of this degree , I can view all the requesters from this course
case Rol_CTR_ADM : // If I am logged as admin of this centre , I can view all the requesters from this course
case Rol_INS_ADM : // If I am logged as admin of this institution, I can view all the requesters from this course
2015-04-07 21:44:24 +02:00
case Rol_SYS_ADM :
2018-10-20 21:19:30 +02:00
// Requests in this course
2018-10-30 17:47:57 +01:00
NumReqs = DB_QuerySELECT ( & mysql_res , " can not get requests "
" for enrolment " ,
" SELECT ReqCod,CrsCod,UsrCod,Role, "
" UNIX_TIMESTAMP(RequestTime) "
" FROM crs_usr_requests "
" WHERE CrsCod=%ld "
" AND ((1<<Role)&%u)<>0 "
" ORDER BY RequestTime DESC " ,
Gbl . CurrentCrs . Crs . CrsCod ,
RolesSelected ) ;
2014-12-12 18:52:06 +01:00
break ;
default :
2019-02-16 20:44:31 +01:00
Lay_NoPermissionExit ( ) ;
2014-12-12 18:52:06 +01:00
break ;
}
break ;
default :
2018-10-24 23:03:11 +02:00
Lay_WrongScopeExit ( ) ;
2014-12-12 18:52:06 +01:00
break ;
}
/***** List requests *****/
2018-10-30 17:47:57 +01:00
if ( NumReqs )
2014-12-12 18:52:06 +01:00
{
/* Initialize structure with user's data */
Usr_UsrDataConstructor ( & UsrDat ) ;
/* Start table */
2017-06-11 20:09:59 +02:00
Tbl_StartTableCenter ( 2 ) ;
2017-05-01 12:36:24 +02:00
fprintf ( Gbl . F . Out , " <th></th> "
2015-09-06 20:02:14 +02:00
" <th class= \" LEFT_TOP \" > "
2014-12-26 22:11:03 +01:00
" %s "
" </th> "
2015-09-06 20:02:14 +02:00
" <th class= \" RIGHT_TOP \" > "
2014-12-26 22:11:03 +01:00
" %s "
" </th> "
2015-09-06 20:02:14 +02:00
" <th colspan= \" 2 \" class= \" LEFT_TOP \" > "
2014-12-26 22:11:03 +01:00
" %s "
" </th> "
2015-09-06 20:02:14 +02:00
" <th class= \" LEFT_TOP \" > "
2014-12-26 22:11:03 +01:00
" %s "
" </th> "
2015-09-06 20:02:14 +02:00
" <th class= \" CENTER_TOP \" > "
2014-12-26 22:11:03 +01:00
" %s "
" </th> "
" <th></th> "
" <th></th> "
2014-12-12 18:52:06 +01:00
" </tr> " ,
Txt_Course ,
2017-05-30 21:43:05 +02:00
Txt_ROLES_PLURAL_BRIEF_Abc [ Rol_TCH ] ,
2014-12-12 18:52:06 +01:00
Txt_Requester ,
Txt_Role ,
Txt_Date ) ;
/* List requests */
for ( NumReq = 0 ;
2018-10-30 17:47:57 +01:00
NumReq < NumReqs ;
2014-12-12 18:52:06 +01:00
NumReq + + )
{
row = mysql_fetch_row ( mysql_res ) ;
/* Get request code (row[0]) */
ReqCod = Str_ConvertStrCodToLongCod ( row [ 0 ] ) ;
/* Get course code (row[1]) */
Crs . CrsCod = Str_ConvertStrCodToLongCod ( row [ 1 ] ) ;
/* Get user code (row[2]) */
UsrDat . UsrCod = Str_ConvertStrCodToLongCod ( row [ 2 ] ) ;
UsrExists = Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod ( & UsrDat ) ;
2015-09-12 14:12:40 +02:00
/***** Get requested role (row[3]) *****/
DesiredRole = Rol_ConvertUnsignedStrToRole ( row [ 3 ] ) ;
2014-12-12 18:52:06 +01:00
if ( UsrExists )
2015-09-17 11:21:49 +02:00
UsrBelongsToCrs = Usr_CheckIfUsrBelongsToCrs ( UsrDat . UsrCod ,
Crs . CrsCod ,
false ) ;
2014-12-12 18:52:06 +01:00
else
UsrBelongsToCrs = false ;
2015-09-12 14:12:40 +02:00
if ( UsrExists & &
! UsrBelongsToCrs & &
2017-05-18 19:13:41 +02:00
( DesiredRole = = Rol_STD | |
2017-05-22 00:51:45 +02:00
DesiredRole = = Rol_NET | |
2017-05-18 19:13:41 +02:00
DesiredRole = = Rol_TCH ) )
2014-12-12 18:52:06 +01:00
{
/***** Number *****/
fprintf ( Gbl . F . Out , " <tr> "
2015-08-01 08:40:58 +02:00
" <td class= \" DAT RIGHT_TOP \" > "
2018-10-30 17:47:57 +01:00
" %lu "
2014-12-22 21:52:37 +01:00
" </td> " ,
2018-10-30 17:47:57 +01:00
NumReqs - NumReq ) ;
2014-12-12 18:52:06 +01:00
/***** Link to course *****/
Crs_GetDataOfCourseByCod ( & Crs ) ;
Deg . DegCod = Crs . DegCod ;
Deg_GetDataOfDegreeByCod ( & Deg ) ;
2015-08-01 08:40:58 +02:00
fprintf ( Gbl . F . Out , " <td class= \" DAT LEFT_TOP \" > " ) ;
2018-11-09 20:47:39 +01:00
Frm_StartFormGoTo ( ActSeeCrsInf ) ;
2014-12-12 18:52:06 +01:00
Crs_PutParamCrsCod ( Crs . CrsCod ) ;
2018-10-17 14:12:09 +02:00
snprintf ( Gbl . Title , sizeof ( Gbl . Title ) ,
Txt_Go_to_X ,
Crs . FullName ) ;
2018-11-09 20:47:39 +01:00
Frm_LinkFormSubmit ( Gbl . Title , " DAT " , NULL ) ;
2014-12-22 21:52:37 +01:00
fprintf ( Gbl . F . Out , " %s > %s "
2015-03-13 00:16:02 +01:00
" </a> " ,
2016-10-28 10:03:37 +02:00
Deg . ShrtName , Crs . ShrtName ) ;
2018-11-09 20:47:39 +01:00
Frm_EndForm ( ) ;
2015-03-13 00:16:02 +01:00
fprintf ( Gbl . F . Out , " </td> " ) ;
2014-12-12 18:52:06 +01:00
/***** Number of teachers in the course *****/
2015-08-01 08:40:58 +02:00
fprintf ( Gbl . F . Out , " <td class= \" DAT RIGHT_TOP \" > "
2014-12-12 18:52:06 +01:00
" %u "
" </td> " ,
2017-05-21 14:43:10 +02:00
Crs . NumUsrs [ Rol_TCH ] ) ;
2014-12-12 18:52:06 +01:00
/***** User photo *****/
2015-08-01 08:40:58 +02:00
fprintf ( Gbl . F . Out , " <td class= \" DAT CENTER_TOP \" "
2015-09-28 18:28:29 +02:00
" style= \" width:22px; \" > " ) ;
2017-01-28 15:58:46 +01:00
ShowPhoto = Pho_ShowingUsrPhotoIsAllowed ( & UsrDat , PhotoURL ) ;
2014-12-30 15:14:43 +01:00
Pho_ShowUsrPhoto ( & UsrDat , ShowPhoto ? PhotoURL :
NULL ,
2016-01-14 10:31:09 +01:00
" PHOTO21x28 " , Pho_ZOOM , false ) ;
2014-12-12 18:52:06 +01:00
fprintf ( Gbl . F . Out , " </td> " ) ;
/***** User name *****/
2017-03-05 15:12:48 +01:00
fprintf ( Gbl . F . Out , " <td class= \" DAT LEFT_TOP \" > "
" <div class= \" REQUESTER_NAME \" > " ) ; // Limited width
Usr_WriteFirstNameBRSurnames ( & UsrDat ) ;
fprintf ( Gbl . F . Out , " </div> "
" </td> " ) ;
2014-12-12 18:52:06 +01:00
/***** Requested role (row[3]) *****/
2015-08-01 08:40:58 +02:00
fprintf ( Gbl . F . Out , " <td class= \" DAT LEFT_TOP \" > "
2014-12-22 21:52:37 +01:00
" %s "
" </td> " ,
2015-03-12 14:45:40 +01:00
Txt_ROLES_SINGUL_abc [ DesiredRole ] [ UsrDat . Sex ] ) ;
2014-12-12 18:52:06 +01:00
/***** Request time (row[4]) *****/
2015-10-24 21:41:41 +02:00
Msg_WriteMsgDate ( Dat_GetUNIXTimeFromStr ( row [ 4 ] ) , " DAT " ) ;
2014-12-12 18:52:06 +01:00
/***** Button to confirm the request *****/
2015-08-01 08:40:58 +02:00
fprintf ( Gbl . F . Out , " <td class= \" DAT LEFT_TOP \" > " ) ;
2017-05-22 00:51:45 +02:00
switch ( DesiredRole )
{
case Rol_STD :
NextAction = ActReqMdfStd ;
break ;
case Rol_NET :
NextAction = ActReqMdfNET ;
break ;
case Rol_TCH :
NextAction = ActReqMdfTch ;
break ;
default :
NextAction = ActUnk ;
Lay_ShowErrorAndExit ( " Wrong role. " ) ;
break ;
}
2018-11-09 20:47:39 +01:00
Frm_StartForm ( NextAction ) ;
2014-12-12 18:52:06 +01:00
Crs_PutParamCrsCod ( Crs . CrsCod ) ;
2015-04-02 18:39:49 +02:00
Usr_PutParamUsrCodEncrypted ( UsrDat . EncryptedUsrCod ) ;
2017-06-11 19:02:40 +02:00
Btn_PutCreateButtonInline ( Txt_Register ) ;
2018-11-09 20:47:39 +01:00
Frm_EndForm ( ) ;
2015-03-13 00:16:02 +01:00
fprintf ( Gbl . F . Out , " </td> " ) ;
2014-12-12 18:52:06 +01:00
/***** Button to reject the request *****/
2015-08-01 08:40:58 +02:00
fprintf ( Gbl . F . Out , " <td class= \" DAT LEFT_TOP \" > " ) ;
2018-11-09 20:47:39 +01:00
Frm_StartForm ( ActReqRejSignUp ) ;
2014-12-12 18:52:06 +01:00
Crs_PutParamCrsCod ( Crs . CrsCod ) ;
2015-04-02 18:39:49 +02:00
Usr_PutParamUsrCodEncrypted ( UsrDat . EncryptedUsrCod ) ;
2017-06-11 19:02:40 +02:00
Btn_PutRemoveButtonInline ( Txt_Reject ) ;
2018-11-09 20:47:39 +01:00
Frm_EndForm ( ) ;
2015-03-13 00:16:02 +01:00
fprintf ( Gbl . F . Out , " </td> "
2014-12-12 18:52:06 +01:00
" </tr> " ) ;
/***** Mark possible notification as seen *****/
2017-03-30 11:20:06 +02:00
Ntf_MarkNotifAsSeen ( Ntf_EVENT_ENROLMENT_REQUEST ,
2016-01-20 21:18:38 +01:00
ReqCod , Gbl . CurrentCrs . Crs . CrsCod ,
2014-12-12 18:52:06 +01:00
Gbl . Usrs . Me . UsrDat . UsrCod ) ;
}
else // User does not exists or user already belongs to course ==> remove pair from crs_usr_requests table
2017-03-30 11:20:06 +02:00
Enr_RemoveEnrolmentRequest ( Crs . CrsCod , UsrDat . UsrCod ) ;
2014-12-12 18:52:06 +01:00
}
2015-10-04 16:24:10 +02:00
/* End table */
2017-06-11 20:09:59 +02:00
Tbl_EndTable ( ) ;
2014-12-12 18:52:06 +01:00
/* Free memory used for user's data */
Usr_UsrDataDestructor ( & UsrDat ) ;
}
2015-10-04 16:24:10 +02:00
else // There are no requests
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_INFO , Txt_No_enrolment_requests ) ;
2015-10-04 16:24:10 +02:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2017-06-10 21:38:10 +02:00
Box_EndBox ( ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
2017-03-30 11:20:06 +02:00
/********************* Remove a request for enrolment ***********************/
2014-12-12 18:52:06 +01:00
/*****************************************************************************/
2017-03-30 11:20:06 +02:00
static void Enr_RemoveEnrolmentRequest ( long CrsCod , long UsrCod )
2014-12-12 18:52:06 +01:00
{
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
long ReqCod ;
/***** Mark possible notifications as removed
Important : do this before removing the request * * * * */
/* Request request code (returns 0 or 1 rows) */
2018-10-30 17:47:57 +01:00
if ( DB_QuerySELECT ( & mysql_res , " can not get request code " ,
" SELECT ReqCod FROM crs_usr_requests "
" WHERE CrsCod=%ld AND UsrCod=%ld " ,
CrsCod , UsrCod ) ) // Request exists
2014-12-12 18:52:06 +01:00
{
/* Get request code */
row = mysql_fetch_row ( mysql_res ) ;
ReqCod = Str_ConvertStrCodToLongCod ( row [ 0 ] ) ;
/* Mark possible notifications as removed */
2017-03-30 11:20:06 +02:00
Ntf_MarkNotifAsRemoved ( Ntf_EVENT_ENROLMENT_REQUEST , ReqCod ) ;
2014-12-12 18:52:06 +01:00
}
/* Free structure that stores the query result */
DB_FreeMySQLResult ( & mysql_res ) ;
2017-03-30 11:20:06 +02:00
/***** Remove enrolment request *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ( " can not remove a request for enrolment " ,
" DELETE FROM crs_usr_requests "
" WHERE CrsCod=%ld AND UsrCod=%ld " ,
CrsCod , UsrCod ) ;
2014-12-12 18:52:06 +01:00
}
2016-03-27 20:33:39 +02:00
/*****************************************************************************/
2017-03-30 11:20:06 +02:00
/******************* Remove expired requests for enrolment ******************/
2016-03-27 20:33:39 +02:00
/*****************************************************************************/
2017-03-30 11:20:06 +02:00
static void Enr_RemoveExpiredEnrolmentRequests ( void )
2016-03-27 20:33:39 +02:00
{
/***** Mark possible notifications as removed
Important : do this before removing the request * * * * */
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ( " can not set notification(s) as removed " ,
" UPDATE notif,crs_usr_requests "
" SET notif.Status=(notif.Status | %u) "
" WHERE notif.NotifyEvent=%u "
" AND notif.Cod=crs_usr_requests.ReqCod "
2019-02-13 13:32:11 +01:00
" AND crs_usr_requests.RequestTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu) " ,
2018-11-03 12:16:40 +01:00
( unsigned ) Ntf_STATUS_BIT_REMOVED ,
( unsigned ) Ntf_EVENT_ENROLMENT_REQUEST ,
Cfg_TIME_TO_DELETE_ENROLMENT_REQUESTS ) ;
2016-03-27 20:33:39 +02:00
2017-03-30 11:20:06 +02:00
/***** Remove expired requests for enrolment *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ( " can not remove expired requests for enrolment " ,
2019-02-13 13:32:11 +01:00
" DELETE LOW_PRIORITY FROM crs_usr_requests "
" WHERE RequestTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu) " ,
2018-11-02 22:00:31 +01:00
Cfg_TIME_TO_DELETE_ENROLMENT_REQUESTS ) ;
2016-03-27 20:33:39 +02:00
}
2014-12-31 01:32:42 +01:00
/*****************************************************************************/
/********************** Write a form to admin one user ***********************/
/*****************************************************************************/
2015-09-12 14:12:40 +02:00
void Enr_PutLinkToAdminOneUsr ( Act_Action_t NextAction )
2014-12-31 01:32:42 +01:00
{
2017-01-31 00:25:10 +01:00
extern const char * Txt_Administer_me ;
extern const char * Txt_Administer_one_user ;
2017-06-04 18:18:54 +02:00
const char * TitleText = Enr_ICanAdminOtherUsrs [ Gbl . Usrs . Me . Role . Logged ] ? Txt_Administer_one_user :
2017-06-20 14:43:26 +02:00
Txt_Administer_me ;
2014-12-31 01:32:42 +01:00
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkIconText ( NextAction , NULL , NULL ,
" user-cog.svg " ,
TitleText ) ;
2014-12-31 01:32:42 +01:00
}
2015-02-08 19:11:54 +01:00
/*****************************************************************************/
/******************* Write a form to admin several users *********************/
/*****************************************************************************/
2015-09-14 09:32:27 +02:00
void Enr_PutLinkToAdminSeveralUsrs ( Rol_Role_t Role )
2015-02-08 19:11:54 +01:00
{
2017-01-31 00:25:10 +01:00
extern const char * Txt_Administer_multiple_students ;
2017-05-29 22:07:43 +02:00
extern const char * Txt_Administer_multiple_non_editing_teachers ;
2017-01-31 00:25:10 +01:00
extern const char * Txt_Administer_multiple_teachers ;
2017-05-21 19:25:46 +02:00
Act_Action_t NextAction ;
const char * TitleText ;
2015-02-08 19:11:54 +01:00
2017-05-21 19:25:46 +02:00
switch ( Role )
{
case Rol_STD :
NextAction = ActReqEnrSevStd ;
TitleText = Txt_Administer_multiple_students ;
break ;
2017-05-21 21:23:13 +02:00
case Rol_NET :
2017-05-22 00:51:45 +02:00
NextAction = ActReqEnrSevNET ;
2017-05-29 22:07:43 +02:00
TitleText = Txt_Administer_multiple_non_editing_teachers ;
2017-05-21 19:25:46 +02:00
break ;
case Rol_TCH :
NextAction = ActReqEnrSevTch ;
TitleText = Txt_Administer_multiple_teachers ;
break ;
default :
NextAction = ActUnk ;
TitleText = NULL ;
Lay_ShowErrorAndExit ( " Wrong role. " ) ;
}
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkIconText ( NextAction , NULL , NULL ,
" users-cog.svg " ,
TitleText ) ;
2015-02-08 19:11:54 +01:00
}
2014-12-12 18:52:06 +01:00
/*****************************************************************************/
/************** Form to request the user's ID of another user ****************/
/*****************************************************************************/
2015-09-17 16:54:02 +02:00
void Enr_ReqRegRemOth ( void )
2015-09-12 14:12:40 +02:00
{
2017-05-29 22:07:43 +02:00
/***** Form to request user to be administered *****/
2017-05-18 19:13:41 +02:00
Enr_ReqRegRemUsr ( Rol_GST ) ;
2015-09-12 14:12:40 +02:00
}
void Enr_ReqRegRemStd ( void )
{
2019-01-11 12:59:41 +01:00
if ( Enr_ICanAdminOtherUsrs [ Gbl . Usrs . Me . Role . Logged ] )
{
/***** Put contextual links *****/
fprintf ( Gbl . F . Out , " <div class= \" CONTEXT_MENU \" > " ) ;
2017-05-29 22:07:43 +02:00
2019-01-11 12:59:41 +01:00
/* Put link to go to admin several students */
Enr_PutLinkToAdminSeveralUsrs ( Rol_STD ) ;
2017-05-29 22:07:43 +02:00
2019-01-11 12:59:41 +01:00
fprintf ( Gbl . F . Out , " </div> " ) ;
}
2017-05-29 22:07:43 +02:00
/***** Form to request user to be administered *****/
2017-05-18 19:13:41 +02:00
Enr_ReqRegRemUsr ( Rol_STD ) ;
2015-09-12 14:12:40 +02:00
}
void Enr_ReqRegRemTch ( void )
{
2017-05-29 22:07:43 +02:00
/***** Form to request user to be administered *****/
2017-05-18 19:13:41 +02:00
Enr_ReqRegRemUsr ( Rol_TCH ) ;
2015-09-12 14:12:40 +02:00
}
static void Enr_ReqRegRemUsr ( Rol_Role_t Role )
2014-12-12 18:52:06 +01:00
{
2017-06-04 18:18:54 +02:00
if ( Enr_ICanAdminOtherUsrs [ Gbl . Usrs . Me . Role . Logged ] )
2017-05-29 22:07:43 +02:00
/***** Form to request the user's ID of another user *****/
2015-09-16 00:15:20 +02:00
Enr_ReqAnotherUsrIDToRegisterRemove ( Role ) ;
else
2017-05-29 22:07:43 +02:00
/***** Form to request if register/remove me *****/
2015-09-16 00:15:20 +02:00
Enr_AskIfRegRemMe ( Role ) ;
}
2014-12-12 18:52:06 +01:00
/*****************************************************************************/
2016-11-16 23:19:52 +01:00
/****** Write a form to request another user's ID, @nickname or email ********/
2014-12-12 18:52:06 +01:00
/*****************************************************************************/
2015-09-12 14:12:40 +02:00
static void Enr_ReqAnotherUsrIDToRegisterRemove ( Rol_Role_t Role )
2014-12-12 18:52:06 +01:00
{
2017-01-31 00:25:10 +01:00
extern const char * Hlp_USERS_Administration_administer_one_user ;
extern const char * Txt_Administer_one_user ;
2017-05-22 00:51:45 +02:00
Act_Action_t NextAction ;
2014-12-12 18:52:06 +01:00
2017-06-12 14:16:33 +02:00
/***** Start box *****/
2017-06-10 21:38:10 +02:00
Box_StartBox ( NULL , Txt_Administer_one_user , NULL ,
2017-06-12 15:03:29 +02:00
Hlp_USERS_Administration_administer_one_user , Box_NOT_CLOSABLE ) ;
2014-12-12 18:52:06 +01:00
2015-02-08 18:45:13 +01:00
/***** Write form to request another user's ID *****/
2017-05-22 00:51:45 +02:00
switch ( Role )
{
case Rol_GST :
NextAction = ActReqMdfOth ;
break ;
case Rol_STD :
NextAction = ActReqMdfStd ;
break ;
case Rol_NET :
NextAction = ActReqMdfNET ;
break ;
case Rol_TCH :
NextAction = ActReqMdfTch ;
break ;
default :
NextAction = ActUnk ;
Lay_ShowErrorAndExit ( " Wrong role. " ) ;
break ;
}
2017-09-20 17:25:00 +02:00
Enr_WriteFormToReqAnotherUsrID ( NextAction , NULL ) ;
2015-02-08 18:45:13 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2017-06-10 21:38:10 +02:00
Box_EndBox ( ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
/********************** Ask me for register/remove me ************************/
/*****************************************************************************/
2015-09-12 14:12:40 +02:00
static void Enr_AskIfRegRemMe ( Rol_Role_t Role )
2014-12-12 18:52:06 +01:00
{
struct ListUsrCods ListUsrCods ;
/***** I only can admin me *****/
Gbl . Usrs . Other . UsrDat . UsrCod = Gbl . Usrs . Me . UsrDat . UsrCod ;
ListUsrCods . NumUsrs = 1 ;
Usr_AllocateListUsrCods ( & ListUsrCods ) ;
ListUsrCods . Lst [ 0 ] = Gbl . Usrs . Other . UsrDat . UsrCod ;
2015-09-12 14:12:40 +02:00
Enr_AskIfRegRemUsr ( & ListUsrCods , Role ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
/****************** Ask me for register/remove another user ******************/
/*****************************************************************************/
2015-09-17 16:54:02 +02:00
void Enr_AskIfRegRemAnotherOth ( void )
2015-09-12 14:12:40 +02:00
{
2017-05-18 19:13:41 +02:00
Enr_AskIfRegRemAnotherUsr ( Rol_GST ) ;
2015-09-12 14:12:40 +02:00
}
void Enr_AskIfRegRemAnotherStd ( void )
{
2017-05-18 19:13:41 +02:00
Enr_AskIfRegRemAnotherUsr ( Rol_STD ) ;
2015-09-12 14:12:40 +02:00
}
void Enr_AskIfRegRemAnotherTch ( void )
{
2017-05-18 19:13:41 +02:00
Enr_AskIfRegRemAnotherUsr ( Rol_TCH ) ;
2015-09-12 14:12:40 +02:00
}
static void Enr_AskIfRegRemAnotherUsr ( Rol_Role_t Role )
2014-12-12 18:52:06 +01:00
{
struct ListUsrCods ListUsrCods ;
/***** Check if UsrCod is present in parameters *****/
2016-01-25 14:40:57 +01:00
Usr_GetParamOtherUsrCodEncryptedAndGetListIDs ( ) ;
2014-12-12 18:52:06 +01:00
if ( Gbl . Usrs . Other . UsrDat . UsrCod > 0 )
{
/***** If UsrCod is present in parameters,
2017-03-30 11:20:06 +02:00
use this parameter to identify the user to be enroled / removed * * * * */
2014-12-12 18:52:06 +01:00
ListUsrCods . NumUsrs = 1 ;
Usr_AllocateListUsrCods ( & ListUsrCods ) ;
ListUsrCods . Lst [ 0 ] = Gbl . Usrs . Other . UsrDat . UsrCod ;
}
else // Parameter with user code not present
/***** If UsrCod is not present in parameters from form,
2017-03-30 11:20:06 +02:00
use user ' s ID to identify the user to be enroled / removed * * * * */
2014-12-12 18:52:06 +01:00
Usr_GetParamOtherUsrIDNickOrEMailAndGetUsrCods ( & ListUsrCods ) ;
2015-09-12 14:12:40 +02:00
Enr_AskIfRegRemUsr ( & ListUsrCods , Role ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
/********************** Ask me for register/remove user **********************/
/*****************************************************************************/
2015-09-12 14:12:40 +02:00
static void Enr_AskIfRegRemUsr ( struct ListUsrCods * ListUsrCods , Rol_Role_t Role )
2014-12-12 18:52:06 +01:00
{
extern const char * Txt_There_are_X_users_with_the_ID_Y ;
2017-03-30 11:20:06 +02:00
extern const char * Txt_THE_USER_X_is_already_enroled_in_the_course_Y ;
extern const char * Txt_THE_USER_X_is_already_in_the_course_Y_but_has_not_yet_accepted_the_enrolment ;
extern const char * Txt_THE_USER_X_already_exists_in_Y_but_is_not_yet_enroled_in_the_course_Z ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_THE_USER_X_already_exists_in_Y ;
2017-01-27 10:42:20 +01:00
extern const char * Txt_The_user_is_new_not_yet_in_X ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_If_this_is_a_new_user_in_X_you_should_indicate_her_his_ID ;
unsigned NumUsr ;
bool NewUsrIDValid ;
if ( ListUsrCods - > NumUsrs ) // User(s) found with the ID
{
/***** Warning if more than one user found *****/
if ( ListUsrCods - > NumUsrs > 1 )
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_INFO , Txt_There_are_X_users_with_the_ID_Y ,
2019-02-16 01:20:54 +01:00
ListUsrCods - > NumUsrs , Gbl . Usrs . Other . UsrDat . UsrIDNickOrEmail ) ;
2014-12-12 18:52:06 +01:00
/***** For each user found... *****/
for ( NumUsr = 0 ;
NumUsr < ListUsrCods - > NumUsrs ;
NumUsr + + )
{
/* Get user's data */
Gbl . Usrs . Other . UsrDat . UsrCod = ListUsrCods - > Lst [ NumUsr ] ;
Usr_GetAllUsrDataFromUsrCod ( & Gbl . Usrs . Other . UsrDat ) ;
if ( Gbl . CurrentCrs . Crs . CrsCod > 0 ) // Course selected
{
/* Check if this user belongs to the current course */
2017-06-09 15:04:02 +02:00
if ( Usr_CheckIfUsrBelongsToCurrentCrs ( & Gbl . Usrs . Other . UsrDat ) )
2014-12-12 18:52:06 +01:00
{
2017-06-09 15:04:02 +02:00
Gbl . Usrs . Other . UsrDat . Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs ( & Gbl . Usrs . Other . UsrDat ) ;
2014-12-12 18:52:06 +01:00
if ( Gbl . Usrs . Other . UsrDat . Accepted )
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_INFO , Txt_THE_USER_X_is_already_enroled_in_the_course_Y ,
2019-02-16 01:20:54 +01:00
Gbl . Usrs . Other . UsrDat . FullName , Gbl . CurrentCrs . Crs . FullName ) ;
2017-03-30 11:20:06 +02:00
else // Enrolment not yet accepted
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_INFO , Txt_THE_USER_X_is_already_in_the_course_Y_but_has_not_yet_accepted_the_enrolment ,
2019-02-16 01:20:54 +01:00
Gbl . Usrs . Other . UsrDat . FullName , Gbl . CurrentCrs . Crs . FullName ) ;
2014-12-12 18:52:06 +01:00
Enr_ShowFormToEditOtherUsr ( ) ;
}
else // User does not belong to the current course
{
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_INFO , Txt_THE_USER_X_already_exists_in_Y_but_is_not_yet_enroled_in_the_course_Z ,
2019-02-16 01:20:54 +01:00
Gbl . Usrs . Other . UsrDat . FullName ,
Cfg_PLATFORM_SHORT_NAME , Gbl . CurrentCrs . Crs . FullName ) ;
2014-12-12 18:52:06 +01:00
Enr_ShowFormToEditOtherUsr ( ) ;
}
}
else // No course selected
{
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_INFO , Txt_THE_USER_X_already_exists_in_Y ,
2019-02-16 01:20:54 +01:00
Gbl . Usrs . Other . UsrDat . FullName , Cfg_PLATFORM_SHORT_NAME ) ;
2014-12-12 18:52:06 +01:00
Enr_ShowFormToEditOtherUsr ( ) ;
}
}
/***** Free list of users' codes *****/
Usr_FreeListUsrCods ( ListUsrCods ) ;
}
else // No users found, he/she is a new user
{
/***** If UsrCod is not present in parameters from form,
2017-03-30 11:20:06 +02:00
use user ' s ID to identify the user to be enroled * * * * */
2014-12-12 18:52:06 +01:00
if ( Gbl . Usrs . Other . UsrDat . IDs . List )
NewUsrIDValid = ID_CheckIfUsrIDIsValid ( Gbl . Usrs . Other . UsrDat . IDs . List [ 0 ] . ID ) ; // Check the first element of the list
else
NewUsrIDValid = false ;
if ( NewUsrIDValid )
{
/***** Show form to enter the data of a new user *****/
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_INFO , Txt_The_user_is_new_not_yet_in_X ,
2019-02-16 01:20:54 +01:00
Cfg_PLATFORM_SHORT_NAME ) ;
2017-01-27 12:57:31 +01:00
Rec_ShowFormOtherNewSharedRecord ( & Gbl . Usrs . Other . UsrDat , Role ) ;
2014-12-12 18:52:06 +01:00
}
else // User's ID is not valid
{
/* Write message and request a new user's ID */
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_WARNING , Txt_If_this_is_a_new_user_in_X_you_should_indicate_her_his_ID ,
2019-02-16 01:20:54 +01:00
Cfg_PLATFORM_SHORT_NAME ) ;
2015-09-12 14:12:40 +02:00
Enr_ReqRegRemUsr ( Role ) ;
2014-12-12 18:52:06 +01:00
}
}
}
/*****************************************************************************/
/************ Show form to edit the record of an existing user ***************/
/*****************************************************************************/
static void Enr_ShowFormToEditOtherUsr ( void )
{
/***** User's record *****/
2017-05-09 20:56:02 +02:00
Rec_ShowSharedUsrRecord ( Rec_SHA_OTHER_EXISTING_USR_FORM ,
& Gbl . Usrs . Other . UsrDat , NULL ) ;
2014-12-12 18:52:06 +01:00
}
2015-02-01 14:47:40 +01:00
/*****************************************************************************/
/*************** Add an administrator to current institution *****************/
/*****************************************************************************/
void Enr_AddAdmToIns ( void )
{
2015-02-01 20:17:24 +01:00
Enr_AddAdm ( Sco_SCOPE_INS , Gbl . CurrentIns . Ins . InsCod , Gbl . CurrentIns . Ins . FullName ) ;
2015-02-01 14:47:40 +01:00
}
/*****************************************************************************/
/******************* Add an administrator to current centre ******************/
/*****************************************************************************/
void Enr_AddAdmToCtr ( void )
{
2015-02-01 20:17:24 +01:00
Enr_AddAdm ( Sco_SCOPE_CTR , Gbl . CurrentCtr . Ctr . CtrCod , Gbl . CurrentCtr . Ctr . FullName ) ;
2015-02-01 17:43:34 +01:00
}
2015-02-01 14:47:40 +01:00
2015-02-01 17:43:34 +01:00
/*****************************************************************************/
/******************* Add an administrator to current degree ******************/
/*****************************************************************************/
2015-02-01 14:47:40 +01:00
2015-02-01 17:43:34 +01:00
void Enr_AddAdmToDeg ( void )
{
2015-02-01 20:17:24 +01:00
Enr_AddAdm ( Sco_SCOPE_DEG , Gbl . CurrentDeg . Deg . DegCod , Gbl . CurrentDeg . Deg . FullName ) ;
2015-02-01 14:47:40 +01:00
}
2014-12-12 18:52:06 +01:00
/*****************************************************************************/
/******************* Add an administrator to current degree ******************/
/*****************************************************************************/
2015-02-01 17:43:34 +01:00
static void Enr_AddAdm ( Sco_Scope_t Scope , long Cod , const char * InsCtrDegName )
2014-12-12 18:52:06 +01:00
{
2015-02-01 20:17:24 +01:00
bool ICanRegister ;
2014-12-12 18:52:06 +01:00
2015-02-01 17:43:34 +01:00
if ( Cod > 0 )
2014-12-12 18:52:06 +01:00
{
/***** Get plain user's ID of the user to add/modify *****/
if ( Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ( ) )
{
2015-02-01 20:17:24 +01:00
/* Check if I am allowed to register user as administrator in institution/centre/degree */
2017-06-04 18:18:54 +02:00
ICanRegister = ( ( Scope = = Sco_SCOPE_DEG & & Gbl . Usrs . Me . Role . Logged > = Rol_CTR_ADM ) | |
( Scope = = Sco_SCOPE_CTR & & Gbl . Usrs . Me . Role . Logged > = Rol_INS_ADM ) | |
( Scope = = Sco_SCOPE_INS & & Gbl . Usrs . Me . Role . Logged = = Rol_SYS_ADM ) ) ;
2015-02-01 20:17:24 +01:00
if ( ICanRegister )
2014-12-12 18:52:06 +01:00
{
2015-02-01 20:17:24 +01:00
/***** Register administrator in current institution/centre/degree in database *****/
2015-02-01 17:43:34 +01:00
Enr_RegisterAdmin ( & Gbl . Usrs . Other . UsrDat , Scope ,
Cod , InsCtrDegName ) ;
2014-12-12 18:52:06 +01:00
/***** Show user's record *****/
2016-11-18 01:07:00 +01:00
Rec_ShowSharedRecordUnmodifiable ( & Gbl . Usrs . Other . UsrDat ) ;
2014-12-12 18:52:06 +01:00
}
else
2019-02-16 20:07:52 +01:00
Acc_ShowAlertUserNotFoundOrYouDoNotHavePermission ( ) ;
2014-12-12 18:52:06 +01:00
}
else
2019-02-16 20:07:52 +01:00
Acc_ShowAlertUserNotFoundOrYouDoNotHavePermission ( ) ;
2014-12-12 18:52:06 +01:00
}
}
2015-02-01 14:47:40 +01:00
/*****************************************************************************/
/**************** Register administrator in current institution **************/
/*****************************************************************************/
2015-02-01 17:43:34 +01:00
static void Enr_RegisterAdmin ( struct UsrData * UsrDat , Sco_Scope_t Scope , long Cod , const char * InsCtrDegName )
2015-02-01 14:47:40 +01:00
{
2016-10-27 15:06:11 +02:00
extern const char * Sco_ScopeDB [ Sco_NUM_SCOPES ] ;
2015-02-01 17:43:34 +01:00
extern const char * Txt_THE_USER_X_is_already_an_administrator_of_Y ;
2017-03-30 11:20:06 +02:00
extern const char * Txt_THE_USER_X_has_been_enroled_as_administrator_of_Y ;
2015-02-01 14:47:40 +01:00
2015-02-01 17:43:34 +01:00
/***** Check if user was and administrator of current institution/centre/degree *****/
if ( Usr_CheckIfUsrIsAdm ( UsrDat - > UsrCod , Scope , Cod ) )
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_SUCCESS , Txt_THE_USER_X_is_already_an_administrator_of_Y ,
2019-02-16 01:20:54 +01:00
UsrDat - > FullName , InsCtrDegName ) ;
2015-02-01 17:43:34 +01:00
else // User was not administrator of current institution/centre/degree
2015-02-01 14:47:40 +01:00
{
2015-02-01 17:43:34 +01:00
/***** Insert or replace administrator in current institution/centre/degree *****/
2018-11-02 16:39:35 +01:00
DB_QueryREPLACE ( " can not create administrator " ,
" REPLACE INTO admin "
" (UsrCod,Scope,Cod) "
" VALUES "
" (%ld,'%s',%ld) " ,
UsrDat - > UsrCod , Sco_ScopeDB [ Scope ] , Cod ) ;
2015-02-01 14:47:40 +01:00
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_SUCCESS , Txt_THE_USER_X_has_been_enroled_as_administrator_of_Y ,
2019-02-16 01:20:54 +01:00
UsrDat - > FullName , InsCtrDegName ) ;
2014-12-12 20:25:00 +01:00
}
}
2014-12-12 18:52:06 +01:00
/*****************************************************************************/
/****************** Ask for remove me from current course ********************/
/*****************************************************************************/
void Enr_ReqRemMeFromCrs ( void )
{
2017-06-04 15:11:41 +02:00
Enr_AskIfRemoveUsrFromCrs ( & Gbl . Usrs . Me . UsrDat ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
/************** Ask for remove of a user from current course *****************/
/*****************************************************************************/
void Enr_ReqRemUsrFromCrs ( void )
{
2017-06-04 15:11:41 +02:00
/***** Get user to be removed *****/
if ( Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ( ) )
{
if ( Enr_CheckIfICanRemUsrFromCrs ( ) )
Enr_AskIfRemoveUsrFromCrs ( & Gbl . Usrs . Other . UsrDat ) ;
else
2019-02-16 20:07:52 +01:00
Acc_ShowAlertUserNotFoundOrYouDoNotHavePermission ( ) ;
2017-06-04 15:11:41 +02:00
}
else
2019-02-16 20:07:52 +01:00
Acc_ShowAlertUserNotFoundOrYouDoNotHavePermission ( ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
/********************* Remove a user from current course *********************/
/*****************************************************************************/
2017-06-04 15:11:41 +02:00
void Enr_RemUsrFromCrs1 ( void )
2014-12-12 18:52:06 +01:00
{
2017-06-04 15:11:41 +02:00
extern const char * Txt_User_not_found_or_you_do_not_have_permission_ ;
2014-12-12 18:52:06 +01:00
if ( Pwd_GetConfirmationOnDangerousAction ( ) )
2017-06-04 15:11:41 +02:00
{
/***** Get user to be removed *****/
if ( Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ( ) )
{
if ( Enr_CheckIfICanRemUsrFromCrs ( ) )
Enr_EffectivelyRemUsrFromCrs ( & Gbl . Usrs . Other . UsrDat , & Gbl . CurrentCrs . Crs ,
Enr_REMOVE_WORKS , Cns_VERBOSE ) ;
else
{
2019-02-16 14:37:34 +01:00
Gbl . DelayedAlert . Type = Ale_WARNING ;
Str_Copy ( Gbl . DelayedAlert . Txt , Txt_User_not_found_or_you_do_not_have_permission_ ,
2018-10-16 15:16:32 +02:00
Ale_MAX_BYTES_ALERT ) ;
2017-06-04 15:11:41 +02:00
}
}
else
{
2019-02-16 14:37:34 +01:00
Gbl . DelayedAlert . Type = Ale_WARNING ;
Str_Copy ( Gbl . DelayedAlert . Txt , Txt_User_not_found_or_you_do_not_have_permission_ ,
2018-10-16 15:16:32 +02:00
Ale_MAX_BYTES_ALERT ) ;
2017-06-04 15:11:41 +02:00
}
}
}
void Enr_RemUsrFromCrs2 ( void )
{
2019-02-16 16:18:54 +01:00
Ale_ShowDelayedAlert ( ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
2017-06-04 15:11:41 +02:00
/*********** Check if I can remove another user in current course ************/
2014-12-12 18:52:06 +01:00
/*****************************************************************************/
2017-06-04 15:11:41 +02:00
static bool Enr_CheckIfICanRemUsrFromCrs ( void )
2014-12-12 18:52:06 +01:00
{
2018-10-10 14:03:06 +02:00
bool ItsMe ;
2014-12-12 18:52:06 +01:00
2018-10-10 14:03:06 +02:00
/* Check if I can remove another user from current course */
2017-06-04 18:18:54 +02:00
switch ( Gbl . Usrs . Me . Role . Logged )
2014-12-12 18:52:06 +01:00
{
2017-06-04 15:11:41 +02:00
case Rol_STD :
case Rol_NET :
2018-10-10 23:56:42 +02:00
ItsMe = Usr_ItsMe ( Gbl . Usrs . Other . UsrDat . UsrCod ) ;
2018-10-10 14:03:06 +02:00
return ItsMe ; // A student or non-editing teacher can remove herself/himself
2017-06-04 15:11:41 +02:00
case Rol_TCH :
case Rol_DEG_ADM :
case Rol_CTR_ADM :
case Rol_INS_ADM :
case Rol_SYS_ADM :
2018-10-10 14:03:06 +02:00
return true ; // A teacher or administrator can remove anyone
2017-06-04 15:11:41 +02:00
default :
return false ;
2014-12-12 18:52:06 +01:00
}
2017-06-04 18:18:54 +02:00
return false ;
2014-12-12 18:52:06 +01:00
}
2015-01-31 01:23:39 +01:00
/*****************************************************************************/
/******* Ask for remove of an administrator from current institution *********/
/*****************************************************************************/
static void Enr_ReqRemAdmOfIns ( void )
{
2015-02-01 20:17:24 +01:00
Enr_ReqRemOrRemAdm ( Enr_REQUEST_REMOVE_USR , Sco_SCOPE_INS ,
2015-02-01 17:06:49 +01:00
Gbl . CurrentIns . Ins . InsCod , Gbl . CurrentIns . Ins . FullName ) ;
2015-01-31 01:23:39 +01:00
}
/*****************************************************************************/
/********* Ask for remove of an administrator from current centre ************/
/*****************************************************************************/
static void Enr_ReqRemAdmOfCtr ( void )
{
2015-02-01 20:17:24 +01:00
Enr_ReqRemOrRemAdm ( Enr_REQUEST_REMOVE_USR , Sco_SCOPE_CTR ,
2015-02-01 17:06:49 +01:00
Gbl . CurrentCtr . Ctr . CtrCod , Gbl . CurrentCtr . Ctr . FullName ) ;
2015-01-31 01:23:39 +01:00
}
2014-12-12 18:52:06 +01:00
/*****************************************************************************/
/********* Ask for remove of an administrator from current degree ************/
/*****************************************************************************/
static void Enr_ReqRemAdmOfDeg ( void )
{
2015-02-01 20:17:24 +01:00
Enr_ReqRemOrRemAdm ( Enr_REQUEST_REMOVE_USR , Sco_SCOPE_DEG ,
2015-02-01 17:06:49 +01:00
Gbl . CurrentDeg . Deg . DegCod , Gbl . CurrentDeg . Deg . FullName ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
2015-01-31 01:23:39 +01:00
/************ Remove an administrator from current institution ***************/
2014-12-12 22:39:55 +01:00
/*****************************************************************************/
2015-01-31 01:23:39 +01:00
void Enr_RemAdmIns ( void )
2014-12-12 22:39:55 +01:00
{
2015-02-01 20:17:24 +01:00
Enr_ReqRemOrRemAdm ( Enr_REMOVE_USR , Sco_SCOPE_INS ,
2015-02-01 17:06:49 +01:00
Gbl . CurrentIns . Ins . InsCod , Gbl . CurrentIns . Ins . FullName ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
2015-01-31 01:23:39 +01:00
/*************** Remove an administrator from current centre *****************/
/*****************************************************************************/
void Enr_RemAdmCtr ( void )
{
2015-02-01 20:17:24 +01:00
Enr_ReqRemOrRemAdm ( Enr_REMOVE_USR , Sco_SCOPE_CTR ,
2015-02-01 17:06:49 +01:00
Gbl . CurrentCtr . Ctr . CtrCod , Gbl . CurrentCtr . Ctr . FullName ) ;
2015-01-31 01:23:39 +01:00
}
/*****************************************************************************/
/*************** Remove an administrator from current degree *****************/
/*****************************************************************************/
void Enr_RemAdmDeg ( void )
{
2015-02-01 20:17:24 +01:00
Enr_ReqRemOrRemAdm ( Enr_REMOVE_USR , Sco_SCOPE_DEG ,
2015-02-01 17:06:49 +01:00
Gbl . CurrentDeg . Deg . DegCod , Gbl . CurrentDeg . Deg . FullName ) ;
2015-01-31 01:23:39 +01:00
}
/*****************************************************************************/
/***************** Remove an admin from current institution ******************/
2014-12-12 18:52:06 +01:00
/*****************************************************************************/
2015-02-01 17:06:49 +01:00
static void Enr_ReqRemOrRemAdm ( Enr_ReqDelOrDelUsr_t ReqDelOrDelUsr , Sco_Scope_t Scope ,
long Cod , const char * InsCtrDegName )
2015-01-31 01:23:39 +01:00
{
2015-02-01 17:06:49 +01:00
extern const char * Txt_THE_USER_X_is_not_an_administrator_of_Y ;
2015-01-31 01:23:39 +01:00
bool ItsMe ;
bool ICanRemove ;
2015-02-01 17:06:49 +01:00
if ( Cod > 0 )
2015-01-31 01:23:39 +01:00
{
/***** Get user to be removed *****/
if ( Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ( ) )
{
2015-02-01 20:17:24 +01:00
/* Check if it's forbidden to remove an administrator */
2018-10-10 23:56:42 +02:00
ItsMe = Usr_ItsMe ( Gbl . Usrs . Other . UsrDat . UsrCod ) ;
2015-02-01 20:17:24 +01:00
ICanRemove = ( ItsMe | |
2017-06-04 18:18:54 +02:00
( Scope = = Sco_SCOPE_DEG & & Gbl . Usrs . Me . Role . Logged > = Rol_CTR_ADM ) | |
( Scope = = Sco_SCOPE_CTR & & Gbl . Usrs . Me . Role . Logged > = Rol_INS_ADM ) | |
( Scope = = Sco_SCOPE_INS & & Gbl . Usrs . Me . Role . Logged = = Rol_SYS_ADM ) ) ;
2015-01-31 01:23:39 +01:00
if ( ICanRemove )
{
2015-02-01 20:17:24 +01:00
/* Check if the other user is an admin of the current institution/centre/degree */
2015-02-01 17:06:49 +01:00
if ( Usr_CheckIfUsrIsAdm ( Gbl . Usrs . Other . UsrDat . UsrCod , Scope , Cod ) )
2015-02-01 20:17:24 +01:00
{ // The other user is an administrator of current institution/centre/degree ==> ask for removing or remove her/him
2015-01-31 01:23:39 +01:00
switch ( ReqDelOrDelUsr )
{
case Enr_REQUEST_REMOVE_USR : // Ask if remove administrator from current institution
2015-02-01 17:06:49 +01:00
Enr_AskIfRemAdm ( ItsMe , Scope , InsCtrDegName ) ;
2015-01-31 01:23:39 +01:00
break ;
case Enr_REMOVE_USR : // Remove administrator from current institution
2015-02-01 17:06:49 +01:00
Enr_EffectivelyRemAdm ( & Gbl . Usrs . Other . UsrDat , Scope ,
Cod , InsCtrDegName ) ;
2015-01-31 01:23:39 +01:00
break ;
}
}
else // The other user is not an administrator of current institution
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_WARNING , Txt_THE_USER_X_is_not_an_administrator_of_Y ,
2019-02-16 01:20:54 +01:00
Gbl . Usrs . Other . UsrDat . FullName , InsCtrDegName ) ;
2014-12-12 22:39:55 +01:00
}
else
2019-02-16 20:07:52 +01:00
Acc_ShowAlertUserNotFoundOrYouDoNotHavePermission ( ) ;
2014-12-12 22:39:55 +01:00
}
else
2019-02-16 20:07:52 +01:00
Acc_ShowAlertUserNotFoundOrYouDoNotHavePermission ( ) ;
2014-12-12 18:52:06 +01:00
}
}
2015-01-31 01:23:39 +01:00
/*****************************************************************************/
/**** Ask if really wanted to add an administrator to current institution ****/
/*****************************************************************************/
2015-02-01 17:43:34 +01:00
static void Enr_ReqAddAdm ( Sco_Scope_t Scope , long Cod , const char * InsCtrDegName )
2015-01-31 01:23:39 +01:00
{
2015-02-01 17:43:34 +01:00
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 ;
2015-01-31 01:23:39 +01:00
extern const char * Txt_Register_user_IN_A_COURSE_OR_DEGREE ;
2015-02-01 17:43:34 +01:00
static const Act_Action_t Enr_ActNewAdm [ Sco_NUM_SCOPES ] =
2015-01-31 01:23:39 +01:00
{
2015-02-01 20:17:24 +01:00
ActUnk , // Sco_SCOPE_UNK
ActUnk , // Sco_SCOPE_SYS,
ActUnk , // Sco_SCOPE_CTY,
ActNewAdmIns , // Sco_SCOPE_INS,
ActNewAdmCtr , // Sco_SCOPE_CTR,
ActNewAdmDeg , // Sco_SCOPE_DEG,
ActUnk , // Sco_SCOPE_CRS,
2015-02-01 17:43:34 +01:00
} ;
2015-02-01 20:17:24 +01:00
bool ICanRegister ;
2015-01-31 01:23:39 +01:00
2015-02-01 17:43:34 +01:00
if ( Cod > 0 )
2014-12-12 18:52:06 +01:00
{
/***** Get user's identificator of the user to register as admin *****/
if ( Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ( ) )
{
2015-02-01 20:17:24 +01:00
/* Check if I am allowed to register user as administrator in institution/centre/degree */
2017-06-04 18:18:54 +02:00
ICanRegister = ( ( Scope = = Sco_SCOPE_DEG & & Gbl . Usrs . Me . Role . Logged > = Rol_CTR_ADM ) | |
( Scope = = Sco_SCOPE_CTR & & Gbl . Usrs . Me . Role . Logged > = Rol_INS_ADM ) | |
( Scope = = Sco_SCOPE_INS & & Gbl . Usrs . Me . Role . Logged = = Rol_SYS_ADM ) ) ;
2015-02-01 20:17:24 +01:00
if ( ICanRegister )
2014-12-12 18:52:06 +01:00
{
2017-04-28 09:32:21 +02:00
if ( Usr_CheckIfUsrIsAdm ( Gbl . Usrs . Other . UsrDat . UsrCod , Scope , Cod ) ) // User is already an administrator of current institution/centre/degree
2014-12-12 18:52:06 +01:00
{
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_INFO , Txt_THE_USER_X_is_already_an_administrator_of_Y ,
2019-02-16 01:20:54 +01:00
Gbl . Usrs . Other . UsrDat . FullName , InsCtrDegName ) ;
2016-11-18 01:07:00 +01:00
Rec_ShowSharedRecordUnmodifiable ( & Gbl . Usrs . Other . UsrDat ) ;
2014-12-12 18:52:06 +01:00
}
else
{
2017-04-28 09:32:21 +02:00
/***** Show question and button to register user as administrator *****/
/* Start alert */
2019-02-17 01:14:55 +01:00
Ale_ShowAlertAndButton1 ( Ale_QUESTION , Txt_Do_you_really_want_to_register_the_following_user_as_an_administrator_of_X ,
InsCtrDegName ) ;
2017-04-28 09:32:21 +02:00
/* Show user's record */
2016-11-18 01:07:00 +01:00
Rec_ShowSharedRecordUnmodifiable ( & Gbl . Usrs . Other . UsrDat ) ;
2014-12-12 18:52:06 +01:00
2017-04-28 09:32:21 +02:00
/* End alert */
2017-05-25 14:25:22 +02:00
Ale_ShowAlertAndButton2 ( Enr_ActNewAdm [ Scope ] , NULL , NULL ,
2017-04-28 10:35:41 +02:00
Usr_PutParamOtherUsrCodEncrypted ,
2017-06-11 19:02:40 +02:00
Btn_CREATE_BUTTON , Txt_Register_user_IN_A_COURSE_OR_DEGREE ) ;
2014-12-12 18:52:06 +01:00
}
}
else
2019-02-16 20:07:52 +01:00
Acc_ShowAlertUserNotFoundOrYouDoNotHavePermission ( ) ;
2014-12-12 18:52:06 +01:00
}
else
2019-02-16 20:07:52 +01:00
Acc_ShowAlertUserNotFoundOrYouDoNotHavePermission ( ) ;
2014-12-12 18:52:06 +01:00
}
}
/*****************************************************************************/
2017-03-30 11:20:06 +02:00
/*************** Accept my enrolment in the current course ******************/
2014-12-12 18:52:06 +01:00
/*****************************************************************************/
void Enr_AcceptRegisterMeInCrs ( void )
{
2017-03-30 11:20:06 +02:00
extern const char * Txt_You_have_confirmed_your_enrolment_in_the_course_X ;
2014-12-12 18:52:06 +01:00
2017-03-30 11:20:06 +02:00
/***** Confirm my enrolment *****/
2014-12-12 18:52:06 +01:00
Enr_AcceptUsrInCrs ( Gbl . Usrs . Me . UsrDat . UsrCod ) ;
2017-03-30 11:20:06 +02:00
/***** Mark all notifications about enrolment (as student or as teacher)
2015-09-17 20:41:31 +02:00
in current course as removed * * * * */
2017-05-21 18:08:35 +02:00
Ntf_MarkNotifToOneUsrAsRemoved ( Ntf_EVENT_ENROLMENT_STD , - 1L ,
2015-09-17 20:41:31 +02:00
Gbl . Usrs . Me . UsrDat . UsrCod ) ;
2017-05-21 18:08:35 +02:00
Ntf_MarkNotifToOneUsrAsRemoved ( Ntf_EVENT_ENROLMENT_TCH , - 1L ,
2015-09-17 20:41:31 +02:00
Gbl . Usrs . Me . UsrDat . UsrCod ) ;
2014-12-12 18:52:06 +01:00
/***** Confirmation message *****/
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_SUCCESS , Txt_You_have_confirmed_your_enrolment_in_the_course_X ,
2019-02-16 01:20:54 +01:00
Gbl . CurrentCrs . Crs . FullName ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
/******************* Create and show data from other user ********************/
/*****************************************************************************/
2016-12-17 22:20:31 +01:00
void Enr_CreateNewUsr1 ( void )
2014-12-12 18:52:06 +01:00
{
2016-12-17 21:36:57 +01:00
extern const char * Txt_The_role_of_THE_USER_X_in_the_course_Y_has_changed_from_A_to_B ;
extern const char * Txt_ROLES_SINGUL_abc [ Rol_NUM_ROLES ] [ Usr_NUM_SEXS ] ;
2017-03-30 11:20:06 +02:00
extern const char * Txt_THE_USER_X_has_been_enroled_in_the_course_Y ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_The_ID_X_is_not_valid ;
2016-12-17 21:36:57 +01:00
Rol_Role_t OldRole ;
2014-12-12 18:52:06 +01:00
Rol_Role_t NewRole ;
/***** Get user's ID from form *****/
ID_GetParamOtherUsrIDPlain ( ) ; // User's ID was already modified and passed as a hidden parameter
2017-03-26 04:22:07 +02:00
/***** Initialize alert type and message *****/
2019-02-17 01:14:55 +01:00
Gbl . DelayedAlert . Type = Ale_NONE ; // Do not show alert
2016-12-17 22:20:31 +01:00
2014-12-12 18:52:06 +01:00
if ( ID_CheckIfUsrIDIsValid ( Gbl . Usrs . Other . UsrDat . IDs . List [ 0 ] . ID ) ) // User's ID valid
{
Gbl . Usrs . Other . UsrDat . UsrCod = - 1L ;
/***** Get new role *****/
NewRole = Rec_GetRoleFromRecordForm ( ) ;
/***** Get user's name from form *****/
Rec_GetUsrNameFromRecordForm ( & Gbl . Usrs . Other . UsrDat ) ;
/***** Create user *****/
Gbl . Usrs . Other . UsrDat . IDs . List [ 0 ] . Confirmed = true ; // User's ID will be stored as confirmed
2016-11-08 00:58:32 +01:00
Acc_CreateNewUsr ( & Gbl . Usrs . Other . UsrDat ,
false ) ; // I am NOT creating my own account
2014-12-12 18:52:06 +01:00
/***** Register user in current course in database *****/
if ( Gbl . CurrentCrs . Crs . CrsCod > 0 ) // Course selected
{
2017-06-09 15:04:02 +02:00
if ( Usr_CheckIfUsrBelongsToCurrentCrs ( & Gbl . Usrs . Other . UsrDat ) )
2016-12-17 21:36:57 +01:00
{
2017-06-08 15:32:33 +02:00
OldRole = Gbl . Usrs . Other . UsrDat . Roles . InCurrentCrs . Role ; // Remember old role before changing it
2016-12-17 21:36:57 +01:00
if ( NewRole ! = OldRole ) // The role must be updated
{
/* Modify role */
Enr_ModifyRoleInCurrentCrs ( & Gbl . Usrs . Other . UsrDat , NewRole ) ;
2016-12-17 22:20:31 +01:00
/* Success message */
2019-02-17 01:14:55 +01:00
Gbl . DelayedAlert . Type = Ale_SUCCESS ;
snprintf ( Gbl . DelayedAlert . Txt , sizeof ( Gbl . DelayedAlert . Txt ) ,
2018-10-16 21:56:01 +02:00
Txt_The_role_of_THE_USER_X_in_the_course_Y_has_changed_from_A_to_B ,
Gbl . Usrs . Other . UsrDat . FullName ,
Gbl . CurrentCrs . Crs . FullName ,
Txt_ROLES_SINGUL_abc [ OldRole ] [ Gbl . Usrs . Other . UsrDat . Sex ] ,
Txt_ROLES_SINGUL_abc [ NewRole ] [ Gbl . Usrs . Other . UsrDat . Sex ] ) ;
2016-12-17 21:36:57 +01:00
}
}
2017-06-09 15:04:02 +02:00
else // User does not belong to current course
2016-12-17 20:44:13 +01:00
{
/* Register user */
Enr_RegisterUsrInCurrentCrs ( & Gbl . Usrs . Other . UsrDat , NewRole ,
2014-12-12 20:25:00 +01:00
Enr_SET_ACCEPTED_TO_FALSE ) ;
2014-12-12 18:52:06 +01:00
2016-12-17 22:20:31 +01:00
/* Success message */
2019-02-17 01:14:55 +01:00
Gbl . DelayedAlert . Type = Ale_SUCCESS ;
snprintf ( Gbl . DelayedAlert . Txt , sizeof ( Gbl . DelayedAlert . Txt ) ,
2018-10-16 21:56:01 +02:00
Txt_THE_USER_X_has_been_enroled_in_the_course_Y ,
Gbl . Usrs . Other . UsrDat . FullName ,
Gbl . CurrentCrs . Crs . FullName ) ;
2016-12-17 20:44:13 +01:00
}
2017-06-04 18:18:54 +02:00
/***** Change user's groups *****/
if ( Gbl . CurrentCrs . Grps . NumGrps ) // This course has groups?
Grp_ChangeOtherUsrGrps ( ) ;
2014-12-12 18:52:06 +01:00
}
2016-12-17 22:20:31 +01:00
/***** Change current action *****/
2017-05-22 00:51:45 +02:00
switch ( NewRole )
{
case Rol_GST :
Gbl . Action . Act = ActCreOth ;
break ;
case Rol_STD :
Gbl . Action . Act = ActCreStd ;
break ;
case Rol_NET :
Gbl . Action . Act = ActCreNET ;
break ;
case Rol_TCH :
Gbl . Action . Act = ActCreTch ;
break ;
default :
Lay_ShowErrorAndExit ( " Wrong role. " ) ;
break ;
}
2016-12-17 22:20:31 +01:00
Tab_SetCurrentTab ( ) ;
2014-12-12 18:52:06 +01:00
}
else // User's ID not valid
{
2016-12-17 22:20:31 +01:00
/***** Error message *****/
2019-02-17 01:14:55 +01:00
Gbl . DelayedAlert . Type = Ale_ERROR ;
snprintf ( Gbl . DelayedAlert . Txt , sizeof ( Gbl . DelayedAlert . Txt ) ,
2018-10-16 21:56:01 +02:00
Txt_The_ID_X_is_not_valid ,
Gbl . Usrs . Other . UsrDat . IDs . List [ 0 ] . ID ) ;
2016-12-17 22:20:31 +01:00
}
}
void Enr_CreateNewUsr2 ( void )
{
2019-02-17 01:14:55 +01:00
if ( Gbl . DelayedAlert . Type = = Ale_ERROR ) // User's ID not valid
Ale_ShowDelayedAlert ( ) ;
2017-03-26 04:22:07 +02:00
else // User's ID valid
2016-12-17 22:20:31 +01:00
{
if ( Gbl . CurrentCrs . Crs . CrsCod > 0 ) // Course selected
2017-05-09 11:39:08 +02:00
/***** Show optional alert *****/
2019-02-17 01:14:55 +01:00
Ale_ShowDelayedAlert ( ) ;
2016-12-17 22:20:31 +01:00
/***** Show user's record *****/
Rec_ShowSharedRecordUnmodifiable ( & Gbl . Usrs . Other . UsrDat ) ;
2014-12-12 18:52:06 +01:00
}
}
/*****************************************************************************/
/**** Modify other user's data and register her/him in course and groups *****/
/*****************************************************************************/
2016-12-18 19:06:48 +01:00
void Enr_ModifyUsr1 ( void )
2014-12-12 18:52:06 +01:00
{
2016-12-17 21:36:57 +01:00
extern const char * Txt_The_role_of_THE_USER_X_in_the_course_Y_has_changed_from_A_to_B ;
extern const char * Txt_ROLES_SINGUL_abc [ Rol_NUM_ROLES ] [ Usr_NUM_SEXS ] ;
2017-03-30 11:20:06 +02:00
extern const char * Txt_THE_USER_X_has_been_enroled_in_the_course_Y ;
2014-12-12 18:52:06 +01:00
bool ItsMe ;
2016-12-17 21:36:57 +01:00
Rol_Role_t OldRole ;
2014-12-12 18:52:06 +01:00
Rol_Role_t NewRole ;
2016-12-18 19:06:48 +01:00
2017-03-26 04:22:07 +02:00
/***** Initialize alert type and message *****/
2019-02-17 01:14:55 +01:00
Gbl . DelayedAlert . Type = Ale_NONE ; // Do not show alert
2014-12-12 18:52:06 +01:00
/***** Get user from form *****/
if ( Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ( ) )
{
2018-10-10 23:56:42 +02:00
ItsMe = Usr_ItsMe ( Gbl . Usrs . Other . UsrDat . UsrCod ) ;
2014-12-12 18:52:06 +01:00
/***** Get the action to do *****/
2017-01-29 12:42:19 +01:00
Gbl . Usrs . RegRemAction = ( Enr_RegRemOneUsrAction_t )
2017-01-29 21:41:08 +01:00
Par_GetParToUnsignedLong ( " RegRemAction " ,
0 ,
Enr_REG_REM_ONE_USR_NUM_ACTIONS - 1 ,
( unsigned long ) Enr_REG_REM_ONE_USR_UNKNOWN_ACTION ) ;
2017-01-29 12:42:19 +01:00
switch ( Gbl . Usrs . RegRemAction )
{
case Enr_REGISTER_MODIFY_ONE_USR_IN_CRS :
2017-06-04 18:18:54 +02:00
if ( ItsMe | | Gbl . Usrs . Me . Role . Logged > = Rol_TCH )
2014-12-12 18:52:06 +01:00
{
2017-01-29 12:42:19 +01:00
/***** Get user's name from record form *****/
if ( Usr_ICanChangeOtherUsrData ( & Gbl . Usrs . Other . UsrDat ) )
Rec_GetUsrNameFromRecordForm ( & Gbl . Usrs . Other . UsrDat ) ;
2014-12-12 18:52:06 +01:00
2017-01-29 12:42:19 +01:00
/***** Update user's data in database *****/
Enr_UpdateUsrData ( & Gbl . Usrs . Other . UsrDat ) ;
2014-12-12 18:52:06 +01:00
2017-01-29 12:42:19 +01:00
if ( Gbl . CurrentCrs . Crs . CrsCod > 0 )
{
/***** Get new role from record form *****/
NewRole = Rec_GetRoleFromRecordForm ( ) ;
2016-12-17 20:44:13 +01:00
2017-01-29 12:42:19 +01:00
/***** Register user in current course in database *****/
2017-06-09 15:04:02 +02:00
if ( Usr_CheckIfUsrBelongsToCurrentCrs ( & Gbl . Usrs . Other . UsrDat ) )
2017-01-29 12:42:19 +01:00
{
2017-06-08 15:32:33 +02:00
OldRole = Gbl . Usrs . Other . UsrDat . Roles . InCurrentCrs . Role ; // Remember old role before changing it
2017-01-29 12:42:19 +01:00
if ( NewRole ! = OldRole ) // The role must be updated
{
/* Modify role */
Enr_ModifyRoleInCurrentCrs ( & Gbl . Usrs . Other . UsrDat , NewRole ) ;
2017-05-09 11:39:08 +02:00
/* Set success message */
2019-02-17 01:14:55 +01:00
Gbl . DelayedAlert . Type = Ale_SUCCESS ;
snprintf ( Gbl . DelayedAlert . Txt , sizeof ( Gbl . DelayedAlert . Txt ) ,
2018-10-16 21:56:01 +02:00
Txt_The_role_of_THE_USER_X_in_the_course_Y_has_changed_from_A_to_B ,
Gbl . Usrs . Other . UsrDat . FullName ,
Gbl . CurrentCrs . Crs . FullName ,
Txt_ROLES_SINGUL_abc [ OldRole ] [ Gbl . Usrs . Other . UsrDat . Sex ] ,
Txt_ROLES_SINGUL_abc [ NewRole ] [ Gbl . Usrs . Other . UsrDat . Sex ] ) ;
2014-12-12 18:52:06 +01:00
}
}
2017-06-09 15:04:02 +02:00
else // User does not belong to current course
2017-01-29 12:42:19 +01:00
{
/* Register user */
Enr_RegisterUsrInCurrentCrs ( & Gbl . Usrs . Other . UsrDat , NewRole ,
Enr_SET_ACCEPTED_TO_FALSE ) ;
2017-05-09 11:39:08 +02:00
/* Set success message */
2019-02-17 01:14:55 +01:00
Gbl . DelayedAlert . Type = Ale_SUCCESS ;
snprintf ( Gbl . DelayedAlert . Txt , sizeof ( Gbl . DelayedAlert . Txt ) ,
2018-10-16 21:56:01 +02:00
Txt_THE_USER_X_has_been_enroled_in_the_course_Y ,
Gbl . Usrs . Other . UsrDat . FullName , Gbl . CurrentCrs . Crs . FullName ) ;
2017-01-29 12:42:19 +01:00
}
2017-06-04 18:18:54 +02:00
/***** Change user's groups *****/
if ( Gbl . CurrentCrs . Grps . NumGrps ) // This course has groups?
{
if ( ItsMe )
Grp_ChangeMyGrps ( Cns_QUIET ) ;
else
Grp_ChangeOtherUsrGrps ( ) ;
}
2017-06-04 14:22:04 +02:00
/***** If it's me, change my roles *****/
if ( ItsMe )
{
2017-06-23 15:12:49 +02:00
Gbl . Usrs . Me . UsrDat . Roles . InCurrentCrs . Role = Gbl . Usrs . Other . UsrDat . Roles . InCurrentCrs . Role ;
Gbl . Usrs . Me . UsrDat . Roles . InCurrentCrs . Valid = true ;
2017-06-08 15:32:33 +02:00
Gbl . Usrs . Me . UsrDat . Roles . InCrss = Gbl . Usrs . Other . UsrDat . Roles . InCrss ;
2017-06-04 14:22:04 +02:00
Rol_SetMyRoles ( ) ;
}
2017-01-29 12:42:19 +01:00
/***** Change current action *****/
2017-05-22 00:51:45 +02:00
switch ( NewRole )
{
case Rol_GST :
Gbl . Action . Act = ActUpdOth ;
break ;
case Rol_STD :
Gbl . Action . Act = ActUpdStd ;
break ;
case Rol_NET :
Gbl . Action . Act = ActUpdNET ;
break ;
case Rol_TCH :
Gbl . Action . Act = ActUpdTch ;
break ;
default :
Lay_ShowErrorAndExit ( " Wrong role. " ) ;
break ;
}
2017-01-29 12:42:19 +01:00
Tab_SetCurrentTab ( ) ;
}
2014-12-12 18:52:06 +01:00
}
2017-01-29 12:42:19 +01:00
else
2019-02-17 01:14:55 +01:00
Gbl . DelayedAlert . Type = Ale_WARNING ;
2017-01-29 12:42:19 +01:00
break ;
case Enr_REGISTER_ONE_DEGREE_ADMIN :
2017-06-04 18:18:54 +02:00
if ( Gbl . Usrs . Me . Role . Logged < Rol_CTR_ADM )
2019-02-17 01:14:55 +01:00
Gbl . DelayedAlert . Type = Ale_WARNING ;
2017-01-29 12:42:19 +01:00
break ;
case Enr_REGISTER_ONE_CENTRE_ADMIN :
2017-06-04 18:18:54 +02:00
if ( Gbl . Usrs . Me . Role . Logged < Rol_INS_ADM )
2019-02-17 01:14:55 +01:00
Gbl . DelayedAlert . Type = Ale_WARNING ;
2017-01-29 12:42:19 +01:00
break ;
case Enr_REGISTER_ONE_INSTITUTION_ADMIN :
2017-06-04 18:18:54 +02:00
if ( Gbl . Usrs . Me . Role . Logged ! = Rol_SYS_ADM )
2019-02-17 01:14:55 +01:00
Gbl . DelayedAlert . Type = Ale_WARNING ;
2017-01-29 12:42:19 +01:00
break ;
case Enr_REPORT_USR_AS_POSSIBLE_DUPLICATE :
2017-06-04 18:18:54 +02:00
if ( ItsMe | | Gbl . Usrs . Me . Role . Logged < Rol_TCH )
2019-02-17 01:14:55 +01:00
Gbl . DelayedAlert . Type = Ale_WARNING ;
2017-01-29 12:42:19 +01:00
break ;
case Enr_REMOVE_ONE_USR_FROM_CRS :
2017-06-04 18:18:54 +02:00
if ( ! ItsMe & & Gbl . Usrs . Me . Role . Logged < Rol_TCH )
2019-02-17 01:14:55 +01:00
Gbl . DelayedAlert . Type = Ale_WARNING ;
2017-01-29 12:42:19 +01:00
break ;
case Enr_REMOVE_ONE_DEGREE_ADMIN :
2017-06-04 18:18:54 +02:00
if ( ! ItsMe & & Gbl . Usrs . Me . Role . Logged < Rol_CTR_ADM )
2019-02-17 01:14:55 +01:00
Gbl . DelayedAlert . Type = Ale_WARNING ;
2017-01-29 12:42:19 +01:00
break ;
case Enr_REMOVE_ONE_CENTRE_ADMIN :
2017-06-04 18:18:54 +02:00
if ( ! ItsMe & & Gbl . Usrs . Me . Role . Logged < Rol_INS_ADM )
2019-02-17 01:14:55 +01:00
Gbl . DelayedAlert . Type = Ale_WARNING ;
2017-01-29 12:42:19 +01:00
break ;
case Enr_REMOVE_ONE_INSTITUTION_ADMIN :
2017-06-04 18:18:54 +02:00
if ( ! ItsMe & & Gbl . Usrs . Me . Role . Logged ! = Rol_SYS_ADM )
2019-02-17 01:14:55 +01:00
Gbl . DelayedAlert . Type = Ale_WARNING ;
2017-01-29 12:42:19 +01:00
break ;
case Enr_ELIMINATE_ONE_USR_FROM_PLATFORM :
if ( ! Acc_CheckIfICanEliminateAccount ( Gbl . Usrs . Other . UsrDat . UsrCod ) )
2019-02-17 01:14:55 +01:00
Gbl . DelayedAlert . Type = Ale_WARNING ;
2017-01-29 12:42:19 +01:00
break ;
default :
2019-02-17 01:14:55 +01:00
Gbl . DelayedAlert . Type = Ale_WARNING ;
2017-01-29 12:42:19 +01:00
break ;
}
2014-12-12 18:52:06 +01:00
}
else
2019-02-17 01:14:55 +01:00
Gbl . DelayedAlert . Type = Ale_WARNING ;
2016-12-18 19:06:48 +01:00
}
2014-12-12 18:52:06 +01:00
2016-12-18 19:06:48 +01:00
void Enr_ModifyUsr2 ( void )
{
2019-02-17 01:14:55 +01:00
if ( Gbl . DelayedAlert . Type = = Ale_WARNING )
2019-02-16 20:07:52 +01:00
Acc_ShowAlertUserNotFoundOrYouDoNotHavePermission ( ) ;
2016-12-18 19:06:48 +01:00
else // No error
switch ( Gbl . Usrs . RegRemAction )
{
case Enr_REGISTER_MODIFY_ONE_USR_IN_CRS :
if ( Gbl . CurrentCrs . Crs . CrsCod > 0 )
2017-05-09 11:39:08 +02:00
/***** Show optional alert *****/
2019-02-17 01:14:55 +01:00
Ale_ShowDelayedAlert ( ) ;
2016-12-18 19:06:48 +01:00
/***** Show user's record *****/
Rec_ShowSharedRecordUnmodifiable ( & Gbl . Usrs . Other . UsrDat ) ;
break ;
case Enr_REGISTER_ONE_DEGREE_ADMIN :
Enr_ReqAddAdm ( Sco_SCOPE_DEG , Gbl . CurrentDeg . Deg . DegCod ,
Gbl . CurrentDeg . Deg . FullName ) ;
break ;
case Enr_REGISTER_ONE_CENTRE_ADMIN :
Enr_ReqAddAdm ( Sco_SCOPE_CTR , Gbl . CurrentCtr . Ctr . CtrCod ,
Gbl . CurrentCtr . Ctr . FullName ) ;
break ;
case Enr_REGISTER_ONE_INSTITUTION_ADMIN :
Enr_ReqAddAdm ( Sco_SCOPE_INS , Gbl . CurrentIns . Ins . InsCod ,
Gbl . CurrentIns . Ins . FullName ) ;
break ;
case Enr_REPORT_USR_AS_POSSIBLE_DUPLICATE :
Dup_ReportUsrAsPossibleDuplicate ( ) ;
break ;
case Enr_REMOVE_ONE_USR_FROM_CRS :
Enr_ReqRemUsrFromCrs ( ) ;
break ;
case Enr_REMOVE_ONE_DEGREE_ADMIN :
Enr_ReqRemAdmOfDeg ( ) ;
break ;
case Enr_REMOVE_ONE_CENTRE_ADMIN :
Enr_ReqRemAdmOfCtr ( ) ;
break ;
case Enr_REMOVE_ONE_INSTITUTION_ADMIN :
Enr_ReqRemAdmOfIns ( ) ;
break ;
case Enr_ELIMINATE_ONE_USR_FROM_PLATFORM :
Acc_ReqRemAccountOrRemAccount ( Acc_REQUEST_REMOVE_USR ) ;
break ;
2017-01-29 12:42:19 +01:00
default :
break ;
2016-12-18 19:06:48 +01:00
}
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
/********* Set a user's acceptation to true in the current course ************/
/*****************************************************************************/
void Enr_AcceptUsrInCrs ( long UsrCod )
{
2017-03-30 11:20:06 +02:00
/***** Set enrolment of a user to "accepted" in the current course *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ( " can not confirm user's enrolment " ,
" UPDATE crs_usr SET Accepted='Y' "
" WHERE CrsCod=%ld AND UsrCod=%ld " ,
Gbl . CurrentCrs . Crs . CrsCod , UsrCod ) ;
2014-12-12 18:52:06 +01:00
}
2014-12-12 22:39:55 +01:00
/*****************************************************************************/
/******************* Ask if really wanted to remove a user *******************/
/*****************************************************************************/
2017-06-04 15:11:41 +02:00
static void Enr_AskIfRemoveUsrFromCrs ( struct UsrData * UsrDat )
2014-12-12 22:39:55 +01:00
{
extern const char * Txt_Do_you_really_want_to_be_removed_from_the_course_X ;
extern const char * Txt_Do_you_really_want_to_remove_the_following_user_from_the_course_X ;
extern const char * Txt_Remove_me_from_this_course ;
extern const char * Txt_Remove_user_from_this_course ;
2017-06-04 15:11:41 +02:00
bool ItsMe ;
2017-05-22 00:51:45 +02:00
Act_Action_t NextAction ;
2014-12-12 22:39:55 +01:00
2017-06-09 15:04:02 +02:00
if ( Usr_CheckIfUsrBelongsToCurrentCrs ( UsrDat ) )
2014-12-12 22:39:55 +01:00
{
2018-10-10 23:56:42 +02:00
ItsMe = Usr_ItsMe ( Gbl . Usrs . Other . UsrDat . UsrCod ) ;
2017-06-04 15:11:41 +02:00
2017-04-27 23:44:00 +02:00
/***** Show question and button to remove user as administrator *****/
/* Start alert */
2019-02-17 01:14:55 +01:00
Ale_ShowAlertAndButton1 ( Ale_QUESTION , ItsMe ? Txt_Do_you_really_want_to_be_removed_from_the_course_X :
Txt_Do_you_really_want_to_remove_the_following_user_from_the_course_X ,
Gbl . CurrentCrs . Crs . FullName ) ;
2014-12-12 22:39:55 +01:00
2017-04-27 23:44:00 +02:00
/* Show user's record */
2016-11-18 01:07:00 +01:00
Rec_ShowSharedRecordUnmodifiable ( UsrDat ) ;
2014-12-12 22:39:55 +01:00
2017-04-27 23:44:00 +02:00
/* Show form to request confirmation */
2017-06-08 15:32:33 +02:00
switch ( UsrDat - > Roles . InCurrentCrs . Role )
2017-05-22 00:51:45 +02:00
{
case Rol_STD :
NextAction = ActRemStdCrs ;
break ;
case Rol_NET :
NextAction = ActRemNETCrs ;
break ;
case Rol_TCH :
NextAction = ActRemTchCrs ;
break ;
default :
NextAction = ActUnk ;
Lay_ShowErrorAndExit ( " Wrong role. " ) ;
break ;
}
2018-11-09 20:47:39 +01:00
Frm_StartForm ( NextAction ) ;
2015-04-02 18:39:49 +02:00
Usr_PutParamUsrCodEncrypted ( UsrDat - > EncryptedUsrCod ) ;
2014-12-12 22:39:55 +01:00
Pwd_AskForConfirmationOnDangerousAction ( ) ;
2017-06-11 19:02:40 +02:00
Btn_PutRemoveButton ( ItsMe ? Txt_Remove_me_from_this_course :
2015-03-24 17:47:26 +01:00
Txt_Remove_user_from_this_course ) ;
2018-11-09 20:47:39 +01:00
Frm_EndForm ( ) ;
2017-04-27 23:44:00 +02:00
/* End alert */
2017-06-11 19:02:40 +02:00
Ale_ShowAlertAndButton2 ( ActUnk , NULL , NULL , NULL , Btn_NO_BUTTON , NULL ) ;
2014-12-12 22:39:55 +01:00
}
2017-06-09 15:04:02 +02:00
else // User does not belong to current course
2019-02-16 20:07:52 +01:00
Acc_ShowAlertUserNotFoundOrYouDoNotHavePermission ( ) ;
2014-12-12 22:39:55 +01:00
}
/*****************************************************************************/
/************************ Remove a user from a course ************************/
/*****************************************************************************/
static void Enr_EffectivelyRemUsrFromCrs ( struct UsrData * UsrDat , struct Course * Crs ,
Enr_RemoveUsrWorks_t RemoveUsrWorks , Cns_QuietOrVerbose_t QuietOrVerbose )
{
extern const char * Txt_THE_USER_X_has_been_removed_from_the_course_Y ;
extern const char * Txt_User_not_found_or_you_do_not_have_permission_ ;
2018-10-10 23:56:42 +02:00
bool ItsMe = Usr_ItsMe ( UsrDat - > UsrCod ) ;
2014-12-12 22:39:55 +01:00
2017-06-09 15:04:02 +02:00
if ( Usr_CheckIfUsrBelongsToCurrentCrs ( UsrDat ) )
2014-12-12 22:39:55 +01:00
{
/***** Remove user from all the attendance events in course *****/
Att_RemoveUsrFromCrsAttEvents ( UsrDat - > UsrCod , Crs - > CrsCod ) ;
/***** Remove user from all the groups in course *****/
2017-06-20 14:43:26 +02:00
Grp_RemUsrFromAllGrpsInCrs ( UsrDat - > UsrCod , Crs - > CrsCod ) ;
2014-12-12 22:39:55 +01:00
/***** Remove user's status about reading of course information *****/
Inf_RemoveUsrFromCrsInfoRead ( UsrDat - > UsrCod , Crs - > CrsCod ) ;
/***** Remove works zone of this user in course *****/
if ( RemoveUsrWorks = = Enr_REMOVE_WORKS )
2017-06-04 15:11:41 +02:00
Brw_RemoveUsrWorksInCrs ( UsrDat , Crs ) ;
2014-12-12 22:39:55 +01:00
/***** Remove fields of this user in its course record *****/
2017-06-04 15:11:41 +02:00
Rec_RemoveFieldsCrsRecordInCrs ( UsrDat - > UsrCod , Crs ) ;
2014-12-12 22:39:55 +01:00
2015-01-25 18:50:43 +01:00
/***** Remove some information about files in course and groups *****/
Brw_RemoveSomeInfoAboutCrsUsrFilesFromDB ( UsrDat - > UsrCod , Crs - > CrsCod ) ;
2014-12-12 22:39:55 +01:00
2016-11-21 13:15:08 +01:00
/***** Remove test results made by user in course *****/
Tst_RemoveTestResultsMadeByUsrInCrs ( UsrDat - > UsrCod , Crs - > CrsCod ) ;
2014-12-12 22:39:55 +01:00
/***** Set all the notifications for this user in this course as removed,
except notifications about new messages * * * * */
2016-12-28 18:18:24 +01:00
Ntf_MarkNotifInCrsAsRemoved ( UsrDat - > UsrCod , Crs - > CrsCod ) ;
2014-12-12 22:39:55 +01:00
/***** Remove user from the table of courses-users *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ( " can not remove a user from a course " ,
" DELETE FROM crs_usr "
" WHERE CrsCod=%ld AND UsrCod=%ld " ,
Crs - > CrsCod , UsrDat - > UsrCod ) ;
2014-12-12 22:39:55 +01:00
2017-06-20 14:43:26 +02:00
/***** Flush caches *****/
2017-07-02 20:36:15 +02:00
Usr_FlushCachesUsr ( ) ;
2017-06-20 14:43:26 +02:00
2017-06-04 15:11:41 +02:00
/***** If it's me, change my roles *****/
if ( ItsMe )
{
2017-06-20 14:43:26 +02:00
/* Now I don't belong to current course */
Gbl . Usrs . Me . IBelongToCurrentCrs =
Gbl . Usrs . Me . UsrDat . Accepted = false ;
/* Fill the list with the courses I belong to */
Gbl . Usrs . Me . MyCrss . Filled = false ;
Usr_GetMyCourses ( ) ;
/* Set my roles */
Gbl . Usrs . Me . Role . FromSession =
Gbl . Usrs . Me . Role . Logged =
Gbl . Usrs . Me . Role . LoggedBeforeCloseSession =
Gbl . Usrs . Me . UsrDat . Roles . InCurrentCrs . Role =
UsrDat - > Roles . InCurrentCrs . Role = Rol_UNK ;
2017-06-23 15:12:49 +02:00
Gbl . Usrs . Me . UsrDat . Roles . InCurrentCrs . Valid =
UsrDat - > Roles . InCurrentCrs . Valid = true ;
2017-06-20 14:43:26 +02:00
Gbl . Usrs . Me . UsrDat . Roles . InCrss =
UsrDat - > Roles . InCrss = - 1 ; // not yet filled/calculated
2017-06-04 15:11:41 +02:00
Rol_SetMyRoles ( ) ;
}
2014-12-12 22:39:55 +01:00
if ( QuietOrVerbose = = Cns_VERBOSE )
{
2019-02-17 01:14:55 +01:00
Gbl . DelayedAlert . Type = Ale_SUCCESS ;
snprintf ( Gbl . DelayedAlert . Txt , sizeof ( Gbl . DelayedAlert . Txt ) ,
2018-10-16 21:56:01 +02:00
Txt_THE_USER_X_has_been_removed_from_the_course_Y ,
UsrDat - > FullName , Crs - > FullName ) ;
2014-12-12 22:39:55 +01:00
}
}
else // User does not belong to course
if ( QuietOrVerbose = = Cns_VERBOSE )
2017-06-04 15:11:41 +02:00
{
2019-02-17 01:14:55 +01:00
Gbl . DelayedAlert . Type = Ale_WARNING ;
Str_Copy ( Gbl . DelayedAlert . Txt , Txt_User_not_found_or_you_do_not_have_permission_ ,
2018-10-16 15:16:32 +02:00
Ale_MAX_BYTES_ALERT ) ;
2017-06-04 15:11:41 +02:00
}
2014-12-12 22:39:55 +01:00
}
2015-01-31 01:23:39 +01:00
/*****************************************************************************/
/** Ask if really wanted to remove an administrator from current institution */
/*****************************************************************************/
2018-10-10 23:56:42 +02:00
static void Enr_AskIfRemAdm ( bool ItsMe , Sco_Scope_t Scope ,
const char * InsCtrDegName )
2015-01-31 01:23:39 +01:00
{
2015-02-01 17:06:49 +01:00
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 ;
2015-01-31 01:23:39 +01:00
extern const char * Txt_Remove_me_as_an_administrator ;
2015-12-16 00:16:32 +01:00
extern const char * Txt_Remove_USER_as_an_administrator ;
2015-02-01 17:06:49 +01:00
static const Act_Action_t Enr_ActRemAdm [ Sco_NUM_SCOPES ] =
2015-01-31 01:23:39 +01:00
{
2015-02-01 20:17:24 +01:00
ActUnk , // Sco_SCOPE_UNK
ActUnk , // Sco_SCOPE_SYS,
ActUnk , // Sco_SCOPE_CTY,
ActRemAdmIns , // Sco_SCOPE_INS,
ActRemAdmCtr , // Sco_SCOPE_CTR,
ActRemAdmDeg , // Sco_SCOPE_DEG,
ActUnk , // Sco_SCOPE_CRS,
2015-02-01 17:06:49 +01:00
} ;
2014-12-12 22:39:55 +01:00
if ( Usr_ChkIfUsrCodExists ( Gbl . Usrs . Other . UsrDat . UsrCod ) )
{
2017-04-27 17:02:45 +02:00
/***** Show question and button to remove user as administrator *****/
/* Start alert */
2019-02-17 01:14:55 +01:00
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 ) ;
2014-12-12 22:39:55 +01:00
2017-04-27 17:02:45 +02:00
/* Show user's record */
2016-11-18 01:07:00 +01:00
Rec_ShowSharedRecordUnmodifiable ( & Gbl . Usrs . Other . UsrDat ) ;
2014-12-12 22:39:55 +01:00
2017-04-27 17:02:45 +02:00
/* End alert */
2017-05-25 14:25:22 +02:00
Ale_ShowAlertAndButton2 ( Enr_ActRemAdm [ Scope ] , NULL , NULL ,
2017-04-28 10:35:41 +02:00
Usr_PutParamOtherUsrCodEncrypted ,
2017-06-11 19:02:40 +02:00
Btn_REMOVE_BUTTON ,
2017-04-27 17:02:45 +02:00
ItsMe ? Txt_Remove_me_as_an_administrator :
Txt_Remove_USER_as_an_administrator ) ;
2014-12-12 22:39:55 +01:00
}
else
2015-01-31 01:23:39 +01:00
Lay_ShowErrorAndExit ( " User doesn't exist. " ) ;
}
/*****************************************************************************/
2015-02-01 17:06:49 +01:00
/**** Remove an administrator from current institution, centre or degree *****/
2015-01-31 01:23:39 +01:00
/*****************************************************************************/
2015-02-01 17:06:49 +01:00
static void Enr_EffectivelyRemAdm ( struct UsrData * UsrDat , Sco_Scope_t Scope ,
long Cod , const char * InsCtrDegName )
2015-01-31 01:23:39 +01:00
{
2016-10-27 15:06:11 +02:00
extern const char * Sco_ScopeDB [ Sco_NUM_SCOPES ] ;
2015-02-01 17:06:49 +01:00
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 ;
2015-01-31 01:23:39 +01:00
2015-02-01 17:06:49 +01:00
if ( Usr_CheckIfUsrIsAdm ( UsrDat - > UsrCod , Scope , Cod ) ) // User is administrator of current institution/centre/degree
2015-01-31 01:23:39 +01:00
{
/***** Remove user from the table of admins *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ( " can not remove an administrator " ,
" DELETE FROM admin "
" WHERE UsrCod=%ld AND Scope='%s' AND Cod=%ld " ,
UsrDat - > UsrCod , Sco_ScopeDB [ Scope ] , Cod ) ;
2015-01-31 01:23:39 +01:00
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_SUCCESS , Txt_THE_USER_X_has_been_removed_as_administrator_of_Y ,
2019-02-16 01:20:54 +01:00
UsrDat - > FullName , InsCtrDegName ) ;
2015-01-31 01:23:39 +01:00
}
2015-02-01 17:06:49 +01:00
else // User is not an administrator of the current institution/centre/degree
2019-02-16 14:37:34 +01:00
Ale_ShowAlert ( Ale_ERROR , Txt_THE_USER_X_is_not_an_administrator_of_Y ,
2019-02-16 01:20:54 +01:00
UsrDat - > FullName , InsCtrDegName ) ;
2014-12-12 22:39:55 +01:00
}