2014-12-12 18:52:06 +01:00
// swad_enrollment.c: enrollment (registration) or removing of users
/*
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 .
2015-01-01 14:34:06 +01:00
Copyright ( C ) 1999 - 2015 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 *********************************/
/*****************************************************************************/
# 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"
# include "swad_database.h"
# include "swad_enrollment.h"
# include "swad_global.h"
# include "swad_ID.h"
# include "swad_notification.h"
# include "swad_parameter.h"
# include "swad_user.h"
/*****************************************************************************/
/****************************** Public constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/****************************** Internal types *******************************/
/*****************************************************************************/
# define Enr_NUM_ACTIONS_REG_REM_USRS 5
typedef enum
{
Enr_REGISTER_SPECIFIED_USRS_IN_CRS = 0 ,
Enr_REMOVE_SPECIFIED_USRS_FROM_CRS = 1 ,
Enr_REMOVE_NOT_SPECIFIED_USRS_FROM_CRS = 2 ,
Enr_UPDATE_USRS_IN_CRS = 3 ,
Enr_ELIMINATE_USRS_FROM_PLATFORM = 4 ,
} 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 ****************************/
/*****************************************************************************/
2015-09-17 20:41:31 +02:00
static void Enr_NotifyAfterEnrollment ( struct UsrData * UsrDat , Rol_Role_t NewRole ) ;
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 ) ;
static void Enr_MarkOfficialStdsAsRemovable ( long ImpGrpCod , bool RemoveSpecifiedUsrs ) ;
static void Enr_RemoveEnrollmentRequest ( long CrsCod , long UsrCod ) ;
2015-09-12 14:12:40 +02:00
static void Enr_ReqRegRemUsr ( Rol_Role_t Role ) ;
2015-09-16 00:15:20 +02:00
static bool Enr_CheckIfICanAdminOtherUsrs ( void ) ;
2015-09-12 14:12:40 +02:00
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 ) ;
2014-12-12 22:39:55 +01:00
static void Enr_ReqRemOrRemUsrFromCrs ( Enr_ReqDelOrDelUsr_t ReqDelOrDelUsr ) ;
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 ) ;
2014-12-12 22:39:55 +01:00
static void Enr_AskIfRemoveUsrFromCrs ( struct UsrData * UsrDat , bool ItsMe ) ;
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
2015-02-01 17:06:49 +01:00
static void Enr_AskIfRemAdm ( bool ItsMe , Sco_Scope_t Scope , const char * InsCtrDegName ) ;
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-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 *****/
2015-04-02 18:39:49 +02:00
Act_PutContextualLink ( ActReqSignUp , NULL , " signup " , 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 *********************/
/*****************************************************************************/
void Enr_ModifyRoleInCurrentCrs ( struct UsrData * UsrDat ,
Rol_Role_t NewRole ,
Cns_QuietOrVerbose_t QuietOrVerbose )
{
extern const char * Txt_The_role_of_THE_USER_X_in_the_course_Y_has_changed_from_A_to_B ;
2015-03-12 14:45:40 +01:00
extern const char * Txt_ROLES_SINGUL_abc [ Rol_NUM_ROLES ] [ Usr_NUM_SEXS ] ;
2014-12-12 20:25:00 +01:00
char Query [ 256 ] ;
Rol_Role_t OldRole ;
/***** Change user's role if different *****/
OldRole = Rol_GetRoleInCrs ( Gbl . CurrentCrs . Crs . CrsCod , UsrDat - > UsrCod ) ;
if ( NewRole ! = OldRole ) // The role must be updated
{
/***** Check if user's role is allowed *****/
2015-09-17 20:41:31 +02:00
switch ( NewRole )
{
case Rol_STUDENT :
case Rol_TEACHER :
break ;
default :
Lay_ShowErrorAndExit ( " Wrong role. " ) ;
}
2014-12-12 20:25:00 +01:00
/***** Update the role of a user in a course *****/
sprintf ( Query , " UPDATE crs_usr SET Role='%u' "
" WHERE CrsCod='%ld' AND UsrCod='%ld' " ,
( unsigned ) NewRole , Gbl . CurrentCrs . Crs . CrsCod , UsrDat - > UsrCod ) ;
DB_QueryUPDATE ( Query , " can not modify user's role in course " ) ;
2015-09-17 20:41:31 +02:00
/***** Create notification for this user.
If this user wants to receive notifications by e - mail ,
activate the sending of a notification * * * * */
Enr_NotifyAfterEnrollment ( UsrDat , NewRole ) ;
2014-12-12 20:25:00 +01:00
/***** Show info message *****/
if ( QuietOrVerbose = = Cns_VERBOSE )
{
sprintf ( Gbl . Message , Txt_The_role_of_THE_USER_X_in_the_course_Y_has_changed_from_A_to_B ,
UsrDat - > FullName , Gbl . CurrentCrs . Crs . FullName ,
2015-03-12 14:45:40 +01:00
Txt_ROLES_SINGUL_abc [ OldRole ] [ UsrDat - > Sex ] ,
Txt_ROLES_SINGUL_abc [ NewRole ] [ UsrDat - > Sex ] ) ;
2014-12-12 20:25:00 +01:00
Lay_ShowAlert ( Lay_SUCCESS , Gbl . Message ) ;
}
UsrDat - > RoleInCurrentCrsDB = NewRole ;
UsrDat - > Roles | = ( 1 < < NewRole ) ;
}
}
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 ,
Cns_QuietOrVerbose_t QuietOrVerbose ,
Enr_KeepOrSetAccepted_t KeepOrSetAccepted )
{
extern const char * Usr_StringsUsrListTypeInDB [ Usr_NUM_USR_LIST_TYPES ] ;
extern const char * Txt_THE_USER_X_has_been_enrolled_in_the_course_Y ;
char Query [ 1024 ] ;
/***** Check if user's role is allowed *****/
2015-09-17 20:41:31 +02:00
switch ( NewRole )
{
case Rol_STUDENT :
case Rol_TEACHER :
break ;
default :
Lay_ShowErrorAndExit ( " Wrong role. " ) ;
}
2014-12-12 18:52:06 +01:00
/***** Register user in current course in database *****/
sprintf ( Query , " 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','0000-00-00','0', "
" '%s','%u','%c') " ,
Gbl . CurrentCrs . Crs . CrsCod , UsrDat - > UsrCod , ( unsigned ) NewRole ,
KeepOrSetAccepted = = Enr_SET_ACCEPTED_TO_TRUE ? ' Y ' :
' N ' ,
Usr_StringsUsrListTypeInDB [ Usr_SHOW_USRS_TYPE_DEFAULT ] ,
Usr_CLASS_PHOTO_COLS_DEF ,
Usr_LIST_WITH_PHOTOS_DEF ? ' Y ' :
' N ' ) ;
DB_QueryINSERT ( Query , " can not register user in course " ) ;
UsrDat - > RoleInCurrentCrsDB = NewRole ;
UsrDat - > Roles | = NewRole ;
2014-12-12 22:39:55 +01:00
/***** Create notification for this user.
If this user wants to receive notifications by e - mail ,
activate the sending of a notification * * * * */
2015-09-17 20:41:31 +02:00
Enr_NotifyAfterEnrollment ( UsrDat , NewRole ) ;
2014-12-12 18:52:06 +01:00
2014-12-12 22:39:55 +01:00
/***** Show info message *****/
2014-12-12 18:52:06 +01:00
if ( QuietOrVerbose = = Cns_VERBOSE )
{
2014-12-12 22:39:55 +01:00
sprintf ( Gbl . Message , Txt_THE_USER_X_has_been_enrolled_in_the_course_Y ,
UsrDat - > FullName , Gbl . CurrentCrs . Crs . FullName ) ;
2014-12-12 18:52:06 +01:00
Lay_ShowAlert ( Lay_SUCCESS , Gbl . Message ) ;
}
}
2015-09-17 20:41:31 +02:00
/*****************************************************************************/
/********* Create notification after register user in current course *********/
/*****************************************************************************/
static void Enr_NotifyAfterEnrollment ( struct UsrData * UsrDat , Rol_Role_t NewRole )
{
bool CreateNotif ;
bool NotifyByEmail ;
Ntf_NotifyEvent_t NotifyEvent ;
/***** Check if user's role is allowed *****/
switch ( NewRole )
{
case Rol_STUDENT :
NotifyEvent = Ntf_EVENT_ENROLLMENT_STUDENT ;
break ;
case Rol_TEACHER :
NotifyEvent = Ntf_EVENT_ENROLLMENT_TEACHER ;
break ;
default :
NotifyEvent = Ntf_EVENT_UNKNOWN ;
Lay_ShowErrorAndExit ( " Wrong role. " ) ;
}
/***** Remove possible enrollment request ******/
Enr_RemoveEnrollmentRequest ( Gbl . CurrentCrs . Crs . CrsCod , UsrDat - > UsrCod ) ;
/***** Remove old enrollment notifications before inserting the new one ******/
Ntf_SetNotifToOneUsrAsRemoved ( Ntf_EVENT_ENROLLMENT_STUDENT , - 1 , UsrDat - > UsrCod ) ;
Ntf_SetNotifToOneUsrAsRemoved ( Ntf_EVENT_ENROLLMENT_TEACHER , - 1 , UsrDat - > UsrCod ) ;
/***** Create new notification ******/
CreateNotif = ( UsrDat - > Prefs . NotifNtfEvents & ( 1 < < NotifyEvent ) ) ;
NotifyByEmail = CreateNotif & &
( UsrDat - > UsrCod ! = Gbl . Usrs . Me . UsrDat . UsrCod ) & &
( 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
/*****************************************************************************/
2014-12-12 22:39:55 +01:00
/****** Write a form to request another user's ID, @nickname or e-mail *******/
2014-12-12 18:52:06 +01:00
/*****************************************************************************/
2014-12-12 22:39:55 +01:00
void Enr_WriteFormToReqAnotherUsrID ( Act_Action_t NextAction )
2014-12-12 18:52:06 +01:00
{
2015-07-27 21:25:45 +02:00
extern const char * The_ClassForm [ 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
2014-12-12 22:39:55 +01:00
/***** Form to request user's ID, @nickname or e-mail address *****/
Act_FormStart ( NextAction ) ;
2015-07-27 21:25:45 +02:00
fprintf ( Gbl . F . Out , " <label class= \" %s RIGHT_MIDDLE \" > "
2015-07-25 20:51:17 +02:00
" %s: "
2015-04-12 18:01:06 +02:00
" </label> "
2014-12-12 22:39:55 +01:00
" <input type= \" text \" name= \" OtherUsrIDNickOrEMail \" "
2015-04-12 18:01:06 +02:00
" size= \" 20 \" maxlength= \" %u \" /> " ,
2015-07-27 21:25:45 +02:00
The_ClassForm [ Gbl . Prefs . Theme ] ,
2014-12-12 22:39:55 +01:00
Txt_nick_email_or_ID ,
Usr_MAX_BYTES_USR_LOGIN ) ;
2014-12-12 18:52:06 +01:00
2014-12-12 22:39:55 +01:00
/***** Send button*****/
2015-03-24 17:47:26 +01:00
Lay_PutConfirmButton ( Txt_Continue ) ;
2015-03-13 00:16:02 +01:00
Act_FormEnd ( ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
/****** Request acceptation / refusion of register in current course *********/
/*****************************************************************************/
void Enr_ReqAcceptRegisterInCrs ( void )
{
extern const char * Txt_A_teacher_or_administrator_has_enrolled_you_into_the_course_ ;
extern const char * Txt_Confirm_my_enrollment ;
extern const char * Txt_Remove_me_from_this_course ;
/***** Show message *****/
sprintf ( Gbl . Message , Txt_A_teacher_or_administrator_has_enrolled_you_into_the_course_ ,
Gbl . CurrentCrs . Crs . FullName ) ;
Lay_ShowAlert ( Lay_INFO , Gbl . Message ) ;
2015-04-02 14:22:21 +02:00
fprintf ( Gbl . F . Out , " <div class= \" CONTEXT_MENU \" > " ) ;
2014-12-12 18:52:06 +01:00
/***** Send button to accept register in the current course *****/
2015-09-17 20:41:31 +02:00
Act_PutContextualLink ( Gbl . Usrs . Me . UsrDat . RoleInCurrentCrsDB = = Rol_STUDENT ? ActAccEnrStd :
ActAccEnrTch ,
NULL , " ok_green " , Txt_Confirm_my_enrollment ) ;
2014-12-12 18:52:06 +01:00
/***** Send button to refuse register in the current course *****/
2015-09-17 20:41:31 +02:00
Act_PutContextualLink ( Gbl . Usrs . Me . UsrDat . RoleInCurrentCrsDB = = Rol_STUDENT ? ActRemMe_Std :
ActRemMe_Tch ,
NULL , " delon " , Txt_Remove_me_from_this_course ) ;
2015-04-02 14:22:21 +02:00
2015-03-13 00:16:02 +01:00
fprintf ( Gbl . F . Out , " </div> " ) ;
2014-12-12 18:52:06 +01:00
/***** Mark possible notification as seen *****/
2015-09-17 20:41:31 +02:00
Ntf_SetNotifAsSeen ( Gbl . Usrs . Me . UsrDat . RoleInCurrentCrsDB = = Rol_STUDENT ? Ntf_EVENT_ENROLLMENT_STUDENT :
Ntf_EVENT_ENROLLMENT_TEACHER ,
2014-12-12 18:52:06 +01:00
- 1L ,
Gbl . Usrs . Me . UsrDat . UsrCod ) ;
}
/*****************************************************************************/
/****************** Put an enrollment into a notification ********************/
/*****************************************************************************/
// This function may be called inside a web service, so don't report error
void Enr_GetNotifEnrollment ( char * SummaryStr ,
long CrsCod , long UsrCod ,
unsigned MaxChars )
{
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
char Query [ 256 ] ;
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
struct UsrData UsrDat ;
Rol_Role_t Role ;
SummaryStr [ 0 ] = ' \0 ' ; // Return nothing on error
/***** Get user's role in course from database *****/
sprintf ( Query , " SELECT Role "
" FROM crs_usr "
" WHERE CrsCod='%ld' AND UsrCod='%ld' " ,
CrsCod , UsrCod ) ;
if ( ! mysql_query ( & Gbl . mysql , Query ) )
if ( ( mysql_res = mysql_store_result ( & Gbl . mysql ) ) ! = NULL )
{
/***** Result should have a unique row *****/
if ( mysql_num_rows ( mysql_res ) = = 1 )
{
/***** Get user's role in course *****/
row = mysql_fetch_row ( mysql_res ) ;
/* Initialize structure with user's data */
Usr_UsrDataConstructor ( & UsrDat ) ;
/* Get user's data */
UsrDat . UsrCod = UsrCod ;
Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod ( & UsrDat ) ;
/* Role (row[0]) */
2014-12-12 20:25:00 +01:00
Role = Rol_ConvertUnsignedStrToRole ( row [ 0 ] ) ;
2015-03-12 14:45:40 +01:00
strcpy ( SummaryStr , Txt_ROLES_SINGUL_Abc [ Role ] [ UsrDat . Sex ] ) ;
2014-12-12 18:52:06 +01:00
if ( MaxChars )
Str_LimitLengthHTMLStr ( SummaryStr , MaxChars ) ;
/* Free memory used for user's data */
Usr_UsrDataDestructor ( & UsrDat ) ;
}
mysql_free_result ( mysql_res ) ;
}
}
/*****************************************************************************/
/***************************** Update user's data ****************************/
/*****************************************************************************/
// UsrDat->UsrCod must be > 0
void Enr_UpdateUsrData ( struct UsrData * UsrDat )
{
extern const char * The_ThemeId [ The_NUM_THEMES ] ;
2015-03-06 14:11:11 +01:00
extern const char * Ico_IconSetId [ Ico_NUM_ICON_SETS ] ;
2015-03-06 22:36:29 +01:00
extern const char * Pri_VisibilityDB [ Pri_NUM_OPTIONS_PRIVACY ] ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_STR_LANG_ID [ Txt_NUM_LANGUAGES ] ;
extern const char * Usr_StringsSexDB [ Usr_NUM_SEXS ] ;
char Query [ 2048 ] ;
/***** 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 *****/
sprintf ( Query , " UPDATE usr_data "
" SET Password='%s', "
" Surname1='%s',Surname2='%s',FirstName='%s',Sex='%s', "
2015-03-06 23:20:33 +01:00
" Layout='%u',Theme='%s',IconSet='%s',Language='%s',PhotoVisibility='%s',ProfileVisibility='%s', "
2014-12-12 18:52:06 +01:00
" CtyCod='%ld', "
" LocalAddress='%s',LocalPhone='%s',FamilyAddress='%s',FamilyPhone='%s',OriginPlace='%s',Birthday='%04u-%02u-%02u',Comments='%s' "
" WHERE UsrCod='%ld' " ,
UsrDat - > Password ,
UsrDat - > Surname1 , UsrDat - > Surname2 , UsrDat - > FirstName ,
Usr_StringsSexDB [ UsrDat - > Sex ] ,
( unsigned ) UsrDat - > Prefs . Layout ,
The_ThemeId [ UsrDat - > Prefs . Theme ] ,
Ico_IconSetId [ UsrDat - > Prefs . IconSet ] ,
Txt_STR_LANG_ID [ UsrDat - > Prefs . Language ] ,
2015-03-06 22:36:29 +01:00
Pri_VisibilityDB [ UsrDat - > PhotoVisibility ] ,
2015-03-06 23:20:33 +01:00
Pri_VisibilityDB [ UsrDat - > ProfileVisibility ] ,
2014-12-12 18:52:06 +01:00
UsrDat - > CtyCod ,
UsrDat - > LocalAddress , UsrDat - > LocalPhone ,
UsrDat - > FamilyAddress , UsrDat - > FamilyPhone , UsrDat - > OriginPlace ,
UsrDat - > Birthday . Year , UsrDat - > Birthday . Month , UsrDat - > Birthday . Day ,
UsrDat - > Comments ? UsrDat - > Comments :
" " ,
UsrDat - > UsrCod ) ;
DB_QueryUPDATE ( Query , " can not update user's data " ) ;
}
/*****************************************************************************/
/************************* 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 )
UsrDat - > Birthday . Year =
UsrDat - > Birthday . Month =
UsrDat - > Birthday . Day = 0 ;
}
/*****************************************************************************/
/**************** Update institution, centre and department ******************/
/*****************************************************************************/
void Enr_UpdateInstitutionCentreDepartment ( void )
{
char Query [ 256 ] ;
sprintf ( Query , " 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 ) ;
DB_QueryUPDATE ( Query , " can not update institution, centre and department " ) ;
}
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 )
{
Enr_ReqAdminUsrs ( Rol_STUDENT ) ;
}
void Enr_ReqAdminTchs ( void )
{
Enr_ReqAdminUsrs ( Rol_TEACHER ) ;
}
static void Enr_ReqAdminUsrs ( Rol_Role_t Role )
2014-12-31 02:46:20 +01:00
{
extern const char * Txt_You_dont_have_permission_to_perform_this_action ;
switch ( Gbl . Usrs . Me . LoggedRole )
{
2015-04-07 21:44:24 +02:00
case Rol__GUEST_ :
2015-09-12 14:12:40 +02:00
Enr_AskIfRegRemMe ( Rol__GUEST_ ) ;
break ;
2015-04-07 21:44:24 +02:00
case Rol_STUDENT :
2015-09-12 14:12:40 +02:00
Enr_AskIfRegRemMe ( Rol_STUDENT ) ;
2014-12-31 02:46:20 +01:00
break ;
2015-04-07 21:44:24 +02:00
case Rol_TEACHER :
2015-09-14 17:25:21 +02:00
if ( Gbl . CurrentCrs . Crs . CrsCod > 0 & &
Role = = Rol_STUDENT )
Enr_ShowFormRegRemSeveralUsrs ( Rol_STUDENT ) ;
2014-12-31 02:46:20 +01:00
else
2015-09-12 14:12:40 +02:00
Enr_AskIfRegRemMe ( Rol_TEACHER ) ;
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 :
Lay_ShowAlert ( Lay_ERROR , Txt_You_dont_have_permission_to_perform_this_action ) ;
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
{
extern const char * The_ClassTitle [ The_NUM_THEMES ] ;
2015-09-14 10:47:39 +02:00
extern const char * Txt_Admin_several_students ;
extern const char * Txt_Admin_several_teachers ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_Step_1_Provide_a_list_of_users ;
extern const char * Txt_Option_a_Import_students_from_the_official_lists ;
extern const char * Txt_Select_the_groups_of_students_you_want_to_register_in_remove_from_this_course ;
extern const char * Txt_Option_b_Type_or_paste_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_ ;
2015-09-14 10:47:39 +02:00
extern const char * Txt_Step_4_Confirm_the_enrollment_removing ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_Confirm ;
2015-02-08 18:20:52 +01:00
bool ExternalUsrsServiceAvailable = ( Cfg_EXTERNAL_LOGIN_CLIENT_COMMAND [ 0 ] ! = ' \0 ' ) ;
2014-12-12 18:52:06 +01:00
2015-02-08 19:11:54 +01:00
/***** Put contextual links *****/
2015-09-16 15:26:18 +02:00
if ( Role = = Rol_STUDENT & &
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
2015-09-14 09:50:55 +02:00
/* Put link to remove all the students in the current course */
2015-09-16 15:26:18 +02:00
Enr_PutLinkToRemAllStdsThisCrs ( ) ;
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
2015-04-11 23:46:21 +02:00
/***** Form to send students to be enrolled / removed *****/
2015-09-14 09:50:55 +02:00
Act_FormStart ( Role = = Rol_STUDENT ? ActRcvFrmEnrSevStd :
ActRcvFrmEnrSevTch ) ;
2015-04-11 23:46:21 +02:00
2015-02-08 18:39:58 +01:00
/***** Start frame *****/
2015-09-14 10:47:39 +02:00
Lay_StartRoundFrame ( NULL , Role = = Rol_STUDENT ? Txt_Admin_several_students :
Txt_Admin_several_teachers ) ;
2015-02-08 18:39:58 +01:00
2014-12-12 18:52:06 +01:00
/***** Step 1: List of students to be enrolled / 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 ) ;
2015-02-08 18:20:52 +01:00
if ( ExternalUsrsServiceAvailable )
2014-12-12 18:52:06 +01:00
{
2015-02-08 18:20:52 +01:00
/* Option a: get students from official lists */
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 "
2015-02-08 18:20:52 +01:00
" </div> " ,
The_ClassTitle [ Gbl . Prefs . Theme ] ,
Txt_Option_a_Import_students_from_the_official_lists ) ;
2014-12-12 18:52:06 +01:00
Lay_ShowAlert ( Lay_INFO , Txt_Select_the_groups_of_students_you_want_to_register_in_remove_from_this_course ) ;
Imp_ListMyImpGrpsAndStdsForm ( ) ;
2015-02-08 18:20:52 +01:00
/* Option b: get students' IDs from pasted text */
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 "
2015-02-08 18:20:52 +01:00
" </div> " ,
The_ClassTitle [ Gbl . Prefs . Theme ] ,
Txt_Option_b_Type_or_paste_a_list_of_users ) ;
2014-12-12 18:52:06 +01:00
}
Lay_ShowAlert ( Lay_INFO , Txt_Type_or_paste_a_list_of_IDs_nicks_or_emails_ ) ;
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?
{
Lay_ShowAlert ( Lay_INFO , Txt_Select_the_groups_in_from_which_you_want_to_register_remove_users_ ) ;
Grp_ShowLstGrpsToChgOtherUsrsGrps ( - 1L ) ;
}
else
{
/* Write help message */
sprintf ( Gbl . Message , Txt_No_groups_have_been_created_in_the_course_X_Therefore_ ,
Gbl . CurrentCrs . Crs . FullName ) ;
Lay_ShowAlert ( Lay_INFO , Gbl . Message ) ;
}
}
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 ] ,
2015-09-14 10:47:39 +02:00
Txt_Step_4_Confirm_the_enrollment_removing ) ;
2014-12-12 18:52:06 +01:00
Pwd_AskForConfirmationOnDangerousAction ( ) ;
2015-04-11 23:46:21 +02:00
/***** Send button and end frame *****/
2015-04-12 18:01:06 +02:00
Lay_EndRoundFrameWithButton ( Lay_CONFIRM_BUTTON , Txt_Confirm ) ;
2015-04-11 23:46:21 +02:00
/***** End of form *****/
Act_FormEnd ( ) ;
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
{
extern const char * Txt_Remove_old_users ;
/***** Put form to remove old users *****/
2015-04-02 18:39:49 +02:00
Act_PutContextualLink ( ActReqRemOldUsr , NULL , " delon " , Txt_Remove_old_users ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
/*********************** Write form to remove old users **********************/
/*****************************************************************************/
void Enr_AskRemoveOldUsrs ( void )
{
2015-07-27 21:25:45 +02:00
extern const char * The_ClassForm [ The_NUM_THEMES ] ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_Eliminate_all_users_who_are_not_enrolled_on_any_courses_PART_1_OF_2 ;
extern const char * Txt_Eliminate_all_users_who_are_not_enrolled_on_any_courses_PART_2_OF_2 ;
extern const char * Txt_Eliminate ;
unsigned MonthsWithoutAccess = Usr_DEF_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_USRS ;
2014-12-12 22:39:55 +01:00
unsigned Months ;
2014-12-12 18:52:06 +01:00
/***** Form to request number of months without clicks *****/
2015-08-01 08:40:58 +02:00
fprintf ( Gbl . F . Out , " <div class= \" CENTER_MIDDLE \" > " ) ;
2014-12-12 18:52:06 +01:00
Act_FormStart ( ActRemOldUsr ) ;
fprintf ( Gbl . F . Out , " <span class= \" %s \" >%s </span> " ,
2015-07-27 21:25:45 +02:00
The_ClassForm [ Gbl . Prefs . Theme ] ,
2014-12-12 18:52:06 +01:00
Txt_Eliminate_all_users_who_are_not_enrolled_on_any_courses_PART_1_OF_2 ) ;
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 " ) ;
2014-12-12 22:39:55 +01:00
if ( Months = = MonthsWithoutAccess )
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
}
fprintf ( Gbl . F . Out , " </select> "
" <span class= \" %s \" > " ,
2015-07-27 21:25:45 +02:00
The_ClassForm [ Gbl . Prefs . Theme ] ) ;
2014-12-12 18:52:06 +01:00
fprintf ( Gbl . F . Out , Txt_Eliminate_all_users_who_are_not_enrolled_on_any_courses_PART_2_OF_2 ,
Cfg_PLATFORM_SHORT_NAME ) ;
fprintf ( Gbl . F . Out , " </span> " ) ;
/***** Send button*****/
2015-03-24 17:47:26 +01:00
Lay_PutRemoveButton ( Txt_Eliminate ) ;
2015-03-13 00:16:02 +01:00
Act_FormEnd ( ) ;
fprintf ( Gbl . F . Out , " </div> " ) ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
/******************************* Remove old users ****************************/
/*****************************************************************************/
void Enr_RemoveOldUsrs ( void )
{
extern const char * Txt_Eliminating_X_users_who_were_not_enrolled_in_any_course_and_with_more_than_Y_months_without_access_to_Z ;
extern const char * Txt_X_users_have_been_eliminated ;
char UnsignedStr [ 10 + 1 ] ;
unsigned MonthsWithoutAccess ;
unsigned long SecondsWithoutAccess ;
char Query [ 1024 ] ;
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 *****/
Par_GetParToText ( " Months " , UnsignedStr , 10 ) ;
if ( sscanf ( UnsignedStr , " %u " , & MonthsWithoutAccess ) ! = 1 )
Lay_ShowErrorAndExit ( " Number of months without clicks is missing. " ) ;
if ( MonthsWithoutAccess < Usr_MIN_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_USRS | |
MonthsWithoutAccess > Usr_MAX_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_USRS )
Lay_ShowErrorAndExit ( " Wrong number of months without clicks. " ) ;
SecondsWithoutAccess = ( unsigned long ) MonthsWithoutAccess * Dat_SECONDS_IN_ONE_MONTH ;
/***** Get old users from database *****/
sprintf ( Query , " SELECT UsrCod FROM "
" ( "
" SELECT UsrCod FROM usr_last WHERE "
" UNIX_TIMESTAMP(LastTime) < UNIX_TIMESTAMP()-%lu "
" 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) " ,
SecondsWithoutAccess ) ;
if ( ( NumUsrs = DB_QuerySELECT ( Query , & mysql_res , " can not get old users " ) ) )
{
sprintf ( Gbl . Message , Txt_Eliminating_X_users_who_were_not_enrolled_in_any_course_and_with_more_than_Y_months_without_access_to_Z ,
NumUsrs ,
MonthsWithoutAccess ,
Cfg_PLATFORM_SHORT_NAME ) ;
Lay_ShowAlert ( Lay_INFO , Gbl . Message ) ;
/***** 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 *****/
sprintf ( Gbl . Message , Txt_X_users_have_been_eliminated ,
NumUsrsEliminated ) ;
Lay_ShowAlert ( Lay_SUCCESS , Gbl . Message ) ;
}
/*****************************************************************************/
/***** Put text area to enter/paste IDs of users to be enrolled/removed ******/
/*****************************************************************************/
static void Enr_PutAreaToEnterUsrsIDs ( void )
{
2015-07-27 21:25:45 +02:00
extern const char * The_ClassForm [ The_NUM_THEMES ] ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_List_of_nicks_emails_or_IDs ;
/***** Start of text area *****/
2014-12-27 01:07:14 +01:00
fprintf ( Gbl . F . Out , " <table style= \" margin:0 auto; \" > "
2014-12-12 18:52:06 +01:00
" <tr> "
2015-07-27 21:25:45 +02:00
" <td class= \" %s RIGHT_TOP \" > "
2015-07-25 20:51:17 +02:00
" %s: "
2014-12-22 21:52:37 +01:00
" </td> "
2015-08-01 08:40:58 +02:00
" <td class= \" LEFT_TOP \" > "
2015-04-11 16:42:07 +02:00
" <textarea name= \" UsrsIDs \" cols= \" 72 \" rows= \" 10 \" > " ,
2015-07-27 21:25:45 +02:00
The_ClassForm [ Gbl . Prefs . Theme ] ,
2014-12-12 18:52:06 +01:00
Txt_List_of_nicks_emails_or_IDs ) ;
/***** End of text area *****/
fprintf ( Gbl . F . Out , " </textarea> "
" </td> "
" </tr> "
" </table> " ) ;
}
/*****************************************************************************/
/*** 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
{
2015-07-27 21:25:45 +02:00
extern const char * The_ClassForm [ 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 ;
extern const char * Txt_Register_me_in_the_course_X ;
extern const char * Txt_Register_user_in_the_course_X ;
extern const char * Txt_Register_user_as_an_administrator_of_the_degree_X ;
2015-01-31 01:23:39 +01:00
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 ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_Remove_me_from_the_course_X ;
extern const char * Txt_Remove_user_from_the_course_X ;
extern const char * Txt_Remove_me_as_an_administrator_of_the_degree_X ;
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 ;
extern const char * Txt_Remove_user_as_an_administrator_of_the_centre_X ;
extern const char * Txt_Remove_me_as_an_administrator_of_the_institution_X ;
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 )
2015-09-17 11:21:49 +02:00
UsrBelongsToCrs = Usr_CheckIfUsrBelongsToCrs ( Gbl . Usrs . Other . UsrDat . UsrCod ,
Gbl . CurrentCrs . Crs . CrsCod ,
false ) ;
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 *****/
2015-09-06 19:51:06 +02:00
fprintf ( Gbl . F . Out , " <div class= \" CENTER_MIDDLE \" "
2015-09-18 18:08:43 +02:00
" style= \" display:inline-block; margin:10px; \" > "
2015-07-26 01:13:38 +02:00
" <ul class= \" LIST_LEFT %s \" > " ,
2015-07-27 21:25:45 +02:00
The_ClassForm [ 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 & &
2015-04-07 21:44:24 +02:00
Gbl . Usrs . Me . LoggedRole > = Rol_TEACHER )
2014-12-12 18:52:06 +01:00
{
sprintf ( Gbl . Message , UsrBelongsToCrs ? ( ItsMe ? Txt_Modify_me_in_the_course_X :
Txt_Modify_user_in_the_course_X ) :
( ItsMe ? Txt_Register_me_in_the_course_X :
Txt_Register_user_in_the_course_X ) ,
Gbl . CurrentCrs . Crs . ShortName ) ;
fprintf ( Gbl . F . Out , " <li> "
" <input type= \" radio \" name= \" RegRemAction \" value= \" %u \" " ,
( unsigned ) Enr_REGISTER_MODIFY_ONE_USR_IN_CRS ) ;
if ( ! OptionChecked )
{
fprintf ( Gbl . F . Out , " checked= \" checked \" " ) ;
OptionChecked = true ;
}
fprintf ( Gbl . F . Out , " />%s</li> " , Gbl . Message ) ;
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 & &
2015-04-07 21:44:24 +02:00
Gbl . Usrs . Me . LoggedRole > = Rol_CTR_ADM )
2015-01-31 01:23:39 +01:00
{
sprintf ( Gbl . Message , Txt_Register_user_as_an_administrator_of_the_degree_X ,
Gbl . CurrentDeg . Deg . ShortName ) ;
fprintf ( Gbl . F . Out , " <li> "
" <input type= \" radio \" name= \" RegRemAction \" value= \" %u \" " ,
( unsigned ) Enr_REGISTER_ONE_DEGREE_ADMIN ) ;
if ( ! OptionChecked )
{
fprintf ( Gbl . F . Out , " checked= \" checked \" " ) ;
OptionChecked = true ;
}
fprintf ( Gbl . F . Out , " />%s</li> " , Gbl . Message ) ;
NumOptionsShown + + ;
}
/***** Register user as administrator of centre *****/
if ( ! UsrIsCtrAdmin & &
2015-04-07 21:44:24 +02:00
Gbl . Usrs . Me . LoggedRole > = Rol_INS_ADM )
2015-01-31 01:23:39 +01:00
{
sprintf ( Gbl . Message , Txt_Register_user_as_an_administrator_of_the_centre_X ,
Gbl . CurrentCtr . Ctr . ShortName ) ;
fprintf ( Gbl . F . Out , " <li> "
" <input type= \" radio \" name= \" RegRemAction \" value= \" %u \" " ,
( unsigned ) Enr_REGISTER_ONE_CENTRE_ADMIN ) ;
if ( ! OptionChecked )
{
fprintf ( Gbl . F . Out , " checked= \" checked \" " ) ;
OptionChecked = true ;
}
fprintf ( Gbl . F . Out , " />%s</li> " , Gbl . Message ) ;
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 & &
2015-04-07 21:44:24 +02:00
Gbl . Usrs . Me . LoggedRole = = Rol_SYS_ADM )
2015-01-31 01:23:39 +01:00
{
sprintf ( Gbl . Message , Txt_Register_user_as_an_administrator_of_the_institution_X ,
Gbl . CurrentIns . Ins . ShortName ) ;
fprintf ( Gbl . F . Out , " <li> "
" <input type= \" radio \" name= \" RegRemAction \" value= \" %u \" " ,
( unsigned ) Enr_REGISTER_ONE_INSTITUTION_ADMIN ) ;
if ( ! OptionChecked )
{
fprintf ( Gbl . F . Out , " checked= \" checked \" " ) ;
OptionChecked = true ;
}
fprintf ( Gbl . F . Out , " />%s</li> " , Gbl . Message ) ;
NumOptionsShown + + ;
}
2014-12-12 18:52:06 +01:00
}
/***** Remove user from the course *****/
if ( UsrBelongsToCrs )
{
sprintf ( Gbl . Message ,
ItsMe ? Txt_Remove_me_from_the_course_X :
Txt_Remove_user_from_the_course_X ,
Gbl . CurrentCrs . Crs . ShortName ) ;
fprintf ( Gbl . F . Out , " <li> "
" <input type= \" radio \" name= \" RegRemAction \" value= \" %u \" " ,
( unsigned ) Enr_REMOVE_ONE_USR_FROM_CRS ) ;
if ( ! OptionChecked )
{
fprintf ( Gbl . F . Out , " checked= \" checked \" " ) ;
OptionChecked = true ;
}
fprintf ( Gbl . F . Out , " />%s</li> " , Gbl . Message ) ;
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 & &
2015-04-07 21:44:24 +02:00
( ItsMe | | Gbl . Usrs . Me . LoggedRole > = Rol_CTR_ADM ) )
2015-01-31 01:23:39 +01:00
{
sprintf ( Gbl . Message ,
ItsMe ? Txt_Remove_me_as_an_administrator_of_the_degree_X :
Txt_Remove_user_as_an_administrator_of_the_degree_X ,
Gbl . CurrentDeg . Deg . ShortName ) ;
fprintf ( Gbl . F . Out , " <li> "
" <input type= \" radio \" name= \" RegRemAction \" value= \" %u \" " ,
( unsigned ) Enr_REMOVE_ONE_DEGREE_ADMIN ) ;
if ( ! OptionChecked )
{
fprintf ( Gbl . F . Out , " checked= \" checked \" " ) ;
OptionChecked = true ;
}
fprintf ( Gbl . F . Out , " />%s</li> " , Gbl . Message ) ;
NumOptionsShown + + ;
}
/***** Remove user as an administrator of the centre *****/
if ( UsrIsCtrAdmin & &
2015-04-07 21:44:24 +02:00
( ItsMe | | Gbl . Usrs . Me . LoggedRole > = Rol_INS_ADM ) )
2015-01-31 01:23:39 +01:00
{
sprintf ( Gbl . Message ,
ItsMe ? Txt_Remove_me_as_an_administrator_of_the_centre_X :
Txt_Remove_user_as_an_administrator_of_the_centre_X ,
Gbl . CurrentCtr . Ctr . ShortName ) ;
fprintf ( Gbl . F . Out , " <li> "
" <input type= \" radio \" name= \" RegRemAction \" value= \" %u \" " ,
( unsigned ) Enr_REMOVE_ONE_CENTRE_ADMIN ) ;
if ( ! OptionChecked )
{
fprintf ( Gbl . F . Out , " checked= \" checked \" " ) ;
OptionChecked = true ;
}
fprintf ( Gbl . F . Out , " />%s</li> " , Gbl . Message ) ;
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 & &
2015-04-07 21:44:24 +02:00
( ItsMe | | Gbl . Usrs . Me . LoggedRole = = Rol_SYS_ADM ) )
2015-01-31 01:23:39 +01:00
{
sprintf ( Gbl . Message ,
ItsMe ? Txt_Remove_me_as_an_administrator_of_the_institution_X :
Txt_Remove_user_as_an_administrator_of_the_institution_X ,
2015-02-01 14:47:40 +01:00
Gbl . CurrentIns . Ins . ShortName ) ;
2015-01-31 01:23:39 +01:00
fprintf ( Gbl . F . Out , " <li> "
" <input type= \" radio \" name= \" RegRemAction \" value= \" %u \" " ,
( unsigned ) Enr_REMOVE_ONE_INSTITUTION_ADMIN ) ;
if ( ! OptionChecked )
{
fprintf ( Gbl . F . Out , " checked= \" checked \" " ) ;
OptionChecked = true ;
}
fprintf ( Gbl . F . Out , " />%s</li> " , Gbl . Message ) ;
NumOptionsShown + + ;
}
2014-12-12 18:52:06 +01:00
}
/***** Eliminate user completely from platform *****/
2014-12-12 22:39:55 +01:00
if ( Acc_CheckIfICanEliminateAccount ( ItsMe ) )
2014-12-12 18:52:06 +01:00
{
fprintf ( Gbl . F . Out , " <li> "
" <input type= \" radio \" name= \" RegRemAction \" value= \" %u \" " ,
( unsigned ) Enr_ELIMINATE_ONE_USR_FROM_PLATFORM ) ;
if ( ! OptionChecked )
fprintf ( Gbl . F . Out , " checked= \" checked \" " ) ;
fprintf ( Gbl . F . Out , " />%s</li> " ,
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 *****/
fprintf ( Gbl . F . Out , " </ul> "
" </div> " ) ;
return ( NumOptionsShown ? true :
false ) ;
}
/*****************************************************************************/
/*** Put different actions to register/remove users to/from current course ***/
/*****************************************************************************/
static void Enr_PutActionsRegRemSeveralUsrs ( void )
{
2015-07-27 21:25:45 +02:00
extern const char * The_ClassForm [ 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 *****/
2015-09-06 19:51:06 +02:00
fprintf ( Gbl . F . Out , " <div class= \" CENTER_MIDDLE \" "
" style= \" display:inline-block; \" > "
2015-07-27 21:25:45 +02:00
" <ul class= \" LIST_LEFT %s \" > " ,
The_ClassForm [ 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> "
" <input type= \" radio \" name= \" RegRemAction \" value= \" %u \" checked= \" checked \" /> "
" %s</li> "
" <li> "
" <input type= \" radio \" name= \" RegRemAction \" value= \" %u \" /> "
" %s</li> "
" <li> "
" <input type= \" radio \" name= \" RegRemAction \" value= \" %u \" /> "
" %s</li> "
" <li> "
" <input type= \" radio \" name= \" RegRemAction \" value= \" %u \" /> "
" %s</li> " ,
( unsigned ) Enr_REGISTER_SPECIFIED_USRS_IN_CRS ,
Txt_Register_the_users_indicated_in_step_1 ,
( unsigned ) Enr_REMOVE_SPECIFIED_USRS_FROM_CRS ,
Txt_Remove_the_users_indicated_in_step_1 ,
( unsigned ) Enr_REMOVE_NOT_SPECIFIED_USRS_FROM_CRS ,
Txt_Remove_the_users_not_indicated_in_step_1 ,
( unsigned ) Enr_UPDATE_USRS_IN_CRS ,
Txt_Register_the_users_indicated_in_step_1_and_remove_the_users_not_indicated ) ;
/***** Only for superusers *****/
2015-04-07 21:44:24 +02:00
if ( Gbl . Usrs . Me . LoggedRole = = Rol_SYS_ADM )
2014-12-12 18:52:06 +01:00
fprintf ( Gbl . F . Out , " <li> "
" <input type= \" radio \" name= \" RegRemAction \" value= \" %u \" /> "
" %s</li> " ,
( unsigned ) Enr_ELIMINATE_USRS_FROM_PLATFORM ,
Txt_Eliminate_from_the_platform_the_users_indicated_in_step_1 ) ;
/***** End list of options *****/
fprintf ( Gbl . F . Out , " </ul> "
" </div> " ) ;
}
/*****************************************************************************/
/******* Receive the list of users of the course to register/remove **********/
/*****************************************************************************/
2015-09-14 09:50:55 +02:00
void Enr_ReceiveFormAdminStds ( void )
{
Enr_ReceiveFormUsrsCrs ( Rol_STUDENT ) ;
}
void Enr_ReceiveFormAdminTchs ( void )
{
Enr_ReceiveFormUsrsCrs ( Rol_TEACHER ) ;
}
static void Enr_ReceiveFormUsrsCrs ( Rol_Role_t Role )
2014-12-12 18:52:06 +01:00
{
2015-09-14 17:25:21 +02:00
extern const char * Txt_You_must_specify_in_step_2_the_action_to_perform ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_In_a_type_of_group_with_single_enrollment_students_can_not_be_registered_in_more_than_one_group ;
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 ;
extern const char * Txt_No_user_has_been_enrolled ;
extern const char * Txt_One_user_has_been_enrolled ;
extern const char * Txt_X_users_have_been_enrolled_including_possible_repetitions ;
char ListExternalGrpCods [ Imp_MAX_BYTES_LIST_EXTERNAL_GRP_CODS + 1 ] ;
char ExternalStr [ 1 + 10 + 1 + Crs_LENGTH_INSTITUTIONAL_CRS_COD + 1 ] ;
char ExternalCrsCod [ Crs_LENGTH_INSTITUTIONAL_CRS_COD + 1 ] ;
char UnsignedStr [ 10 + 1 ] ;
unsigned UnsignedNum ;
long LongNum ;
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 ;
long GrpCod ;
unsigned NumUsrsRegistered = 0 ;
unsigned NumUsrsRemoved = 0 ;
unsigned NumUsrsEliminated = 0 ;
struct ListUsers * LstCurrentUsrs ;
struct ListCodGrps LstGrps ;
struct UsrData UsrDat ;
bool ItLooksLikeAUsrID ;
Enr_RegRemUsrsAction_t RegRemUsrsAction ;
bool ErrorInForm = false ;
2015-09-14 10:47:39 +02:00
/***** Check the role of users to register / remove *****/
switch ( Role )
{
case Rol_STUDENT :
break ;
case Rol_TEACHER :
if ( Gbl . Usrs . Me . LoggedRole < Rol_DEG_ADM ) // Can I register/remove teachers?
// No, I can not (TODO: teachers should be able to register/remove existing teachers)
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 ;
Par_GetParToText ( " RegRemAction " , UnsignedStr , 1 ) ;
if ( sscanf ( UnsignedStr , " %u " , & UnsignedNum ) = = 1 )
if ( UnsignedNum < Enr_NUM_ACTIONS_REG_REM_USRS )
switch ( RegRemUsrsAction = ( Enr_RegRemUsrsAction_t ) UnsignedNum )
{
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 :
2015-04-07 21:44:24 +02:00
if ( Gbl . Usrs . Me . LoggedRole = = Rol_SYS_ADM )
2014-12-12 18:52:06 +01:00
{
WhatToDo . RemoveUsrs = true ;
WhatToDo . RemoveSpecifiedUsrs = true ;
WhatToDo . EliminateUsrs = true ;
WhatToDo . RegisterUsrs = false ;
}
else
Lay_ShowErrorAndExit ( " You are not allowed to perform this action. " ) ;
break ;
default :
Lay_ShowErrorAndExit ( " Wrong registering / removing specification. " ) ;
break ;
}
else
Lay_ShowErrorAndExit ( " Wrong registering / removing specification. " ) ;
else
{
2015-09-14 17:25:21 +02:00
Lay_ShowAlert ( Lay_WARNING , Txt_You_must_specify_in_step_2_the_action_to_perform ) ;
2014-12-12 18:52:06 +01:00
/* Show form again */
2015-09-14 09:32:27 +02:00
Enr_ShowFormRegRemSeveralUsrs ( Role ) ;
2014-12-12 18:52:06 +01:00
ErrorInForm = true ;
}
if ( ! ErrorInForm )
{
/***** Get external groups of students *****/
Par_GetParMultiToText ( " ImpGrpCod " , ListExternalGrpCods , Imp_MAX_BYTES_LIST_EXTERNAL_GRP_CODS ) ;
/***** Get groups to which register/remove users *****/
LstGrps . NumGrps = 0 ;
if ( Gbl . CurrentCrs . Grps . NumGrps ) // This course has groups?
{
/***** 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 *****/
Grp_GetLstCodsGrpWanted ( & LstGrps ) ;
/***** A student can't belong to more than one group when the type of group only allows to register in one group *****/
if ( WhatToDo . RegisterUsrs & &
2015-09-14 10:47:39 +02:00
Role = = Rol_STUDENT & &
2014-12-12 18:52:06 +01:00
LstGrps . NumGrps > = 2 )
/* Check if I have selected more than one group of single enrollment */
if ( ! Grp_CheckIfSelectionGrpsIsValid ( & LstGrps ) )
{
/* Show warning message and exit */
Lay_ShowAlert ( Lay_WARNING , Txt_In_a_type_of_group_with_single_enrollment_students_can_not_be_registered_in_more_than_one_group ) ;
/* Free memory used by lists of groups and abort */
Grp_FreeListCodGrp ( & LstGrps ) ;
Grp_FreeListGrpTypesAndGrps ( ) ;
return ;
}
}
/***** Get list of users' IDs *****/
if ( ( ListUsrsIDs = ( char * ) malloc ( ID_MAX_BYTES_LIST_USRS_IDS + 1 ) ) = = NULL )
Lay_ShowErrorAndExit ( " Not enough memory to store users' IDs. " ) ;
Par_GetParToText ( " UsrsIDs " , ListUsrsIDs , ID_MAX_BYTES_LIST_USRS_IDS ) ;
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor ( & UsrDat ) ;
/***** Remove users *****/
if ( WhatToDo . RemoveUsrs )
{
/***** Get list of users in current course *****/
2015-09-14 10:47:39 +02:00
switch ( Role )
2014-12-12 18:52:06 +01:00
{
2015-04-07 21:44:24 +02:00
case Rol_STUDENT :
Usr_GetUsrsLst ( Rol_STUDENT , Sco_SCOPE_CRS , NULL , false ) ;
2014-12-12 18:52:06 +01:00
LstCurrentUsrs = & Gbl . Usrs . LstStds ;
break ;
2015-04-07 21:44:24 +02:00
case Rol_TEACHER :
Usr_GetUsrsLst ( Rol_TEACHER , Sco_SCOPE_CRS , NULL , false ) ;
2014-12-12 18:52:06 +01:00
LstCurrentUsrs = & Gbl . Usrs . LstTchs ;
break ;
default :
LstCurrentUsrs = NULL ; // To avoid warning
Lay_ShowErrorAndExit ( " Wrong role. " ) ; // If user manipulated the form
break ;
}
if ( LstCurrentUsrs - > NumUsrs )
{
/***** Initialize list of users to remove *****/
for ( NumCurrentUsr = 0 ;
NumCurrentUsr < LstCurrentUsrs - > NumUsrs ;
NumCurrentUsr + + )
LstCurrentUsrs - > Lst [ NumCurrentUsr ] . Remove = ! WhatToDo . RemoveSpecifiedUsrs ;
/***** Loop 1: go through form list setting if a student must be removed *****/
/* Step a: Get students from a list of official groups */
2015-09-14 10:47:39 +02:00
if ( Role = = Rol_STUDENT )
2014-12-12 18:52:06 +01:00
{
Ptr = ListExternalGrpCods ;
while ( * Ptr )
{
/* Find next external group code and course code in list */
Str_GetNextStringUntilSeparator ( & Ptr , ExternalStr , 1 + 10 + 1 + Crs_LENGTH_INSTITUTIONAL_CRS_COD ) ;
if ( sscanf ( ExternalStr , " %ld_%s " , & LongNum , ExternalCrsCod ) = = 2 )
{
GrpCod = LongNum ;
/* Mark users belonging to this official group as removable */
Enr_MarkOfficialStdsAsRemovable ( GrpCod , WhatToDo . RemoveSpecifiedUsrs ) ;
}
}
}
/* Step b: Get users from a list of users' IDs */
Ptr = ListUsrsIDs ;
while ( * Ptr )
{
/* Reset user */
UsrDat . UsrCod = - 1L ;
/* Find next string in text */
Str_GetNextStringUntilSeparator ( & Ptr , UsrDat . UsrIDNickOrEmail , Usr_MAX_BYTES_USR_LOGIN ) ;
/* Reset default list of users' codes */
ListUsrCods . NumUsrs = 0 ;
ListUsrCods . Lst = NULL ;
/* Check if string is a user's ID, user's nickname or user's e-mail address */
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 ;
}
}
else if ( Mai_CheckIfEmailIsValid ( UsrDat . UsrIDNickOrEmail ) ) // 2: It's an e-mail
{
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 ) ;
Str_ConvertToUpperText ( UsrDat . UsrIDNickOrEmail ) ;
if ( ID_CheckIfUsrIDSeemsAValidID ( UsrDat . UsrIDNickOrEmail ) )
{
/***** Find users for this user's ID *****/
ID_ReallocateListIDs ( & UsrDat , 1 ) ; // Only one user's ID
strcpy ( UsrDat . IDs . List [ 0 ] . ID , UsrDat . UsrIDNickOrEmail ) ;
ID_GetListUsrCodsFromUsrID ( & UsrDat , NULL , & ListUsrCods , false ) ;
}
}
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 < LstCurrentUsrs - > NumUsrs ;
NumCurrentUsr + + )
if ( LstCurrentUsrs - > Lst [ NumCurrentUsr ] . UsrCod = = ListUsrCods . Lst [ 0 ] ) // User found
LstCurrentUsrs - > Lst [ NumCurrentUsr ] . Remove = true ; // Mark as removable
}
else // Remove all the users (of the role) except these specified
{
for ( NumCurrentUsr = 0 ;
NumCurrentUsr < LstCurrentUsrs - > NumUsrs ;
NumCurrentUsr + + )
for ( NumUsrFound = 0 ;
NumUsrFound < ListUsrCods . NumUsrs ;
NumUsrFound + + )
if ( LstCurrentUsrs - > Lst [ NumCurrentUsr ] . UsrCod = = ListUsrCods . Lst [ NumUsrFound ] ) // User found
LstCurrentUsrs - > Lst [ NumCurrentUsr ] . Remove = false ; // Mark as not removable
}
/* Free memory used for list of users' codes found for this ID */
Usr_FreeListUsrCods ( & ListUsrCods ) ;
}
/***** Loop 2: go through users list removing users *****/
for ( NumCurrentUsr = 0 ;
NumCurrentUsr < LstCurrentUsrs - > NumUsrs ;
NumCurrentUsr + + )
if ( LstCurrentUsrs - > Lst [ NumCurrentUsr ] . Remove ) // If this student must be removed
{
UsrDat . UsrCod = LstCurrentUsrs - > Lst [ NumCurrentUsr ] . UsrCod ;
if ( Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod ( & UsrDat ) ) // If user's data exist...
{
if ( WhatToDo . EliminateUsrs ) // Eliminate user completely from the platform
{
2014-12-12 22:39:55 +01:00
Acc_CompletelyEliminateAccount ( & UsrDat , Cns_QUIET ) ; // Remove definitely the user from the platform
2014-12-12 18:52:06 +01:00
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 + + ;
}
}
}
}
}
/***** Free memory for users list *****/
Usr_FreeUsrsList ( LstCurrentUsrs ) ;
}
/***** 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 !!!!!!
{
/***** Step a: Get users from a list of official groups *****/
2015-09-14 10:47:39 +02:00
if ( Role = = Rol_STUDENT )
2014-12-12 18:52:06 +01:00
{
Ptr = ListExternalGrpCods ;
while ( * Ptr )
{
/* Find next official group code in list */
Str_GetNextStringUntilSeparator ( & Ptr , ExternalStr , 1 + 10 + 1 + Crs_LENGTH_INSTITUTIONAL_CRS_COD ) ;
if ( sscanf ( ExternalStr , " %ld_%s " , & LongNum , ExternalCrsCod ) = = 2 )
{
GrpCod = LongNum ;
/* Import official group of users */
Imp_ImportStdsFromAnImpGrp ( GrpCod , & LstGrps , & NumUsrsRegistered ) ;
/* Update the institutional course code to the external course code */
Crs_UpdateCurrentInstitutionalCrsCod ( & Gbl . CurrentCrs . Crs , ExternalCrsCod ) ;
}
}
}
/***** Step b: Get users from a list of users' IDs ******/
Ptr = ListUsrsIDs ;
while ( * Ptr )
{
/* Reset user */
UsrDat . UsrCod = - 1L ;
ItLooksLikeAUsrID = false ;
/* Find next string in text */
Str_GetNextStringUntilSeparator ( & Ptr , UsrDat . UsrIDNickOrEmail , Usr_MAX_BYTES_USR_LOGIN ) ;
/* 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 e-mail address */
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 ;
}
}
else if ( Mai_CheckIfEmailIsValid ( UsrDat . UsrIDNickOrEmail ) ) // 2: It's an e-mail
{
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 ) ;
Str_ConvertToUpperText ( 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
strcpy ( UsrDat . IDs . List [ 0 ] . ID , UsrDat . UsrIDNickOrEmail ) ;
ID_GetListUsrCodsFromUsrID ( & UsrDat , NULL , & ListUsrCods , false ) ;
}
}
/* Register user(s) */
if ( ListUsrCods . NumUsrs ) // User(s) found
for ( NumUsrFound = 0 ;
NumUsrFound < ListUsrCods . NumUsrs ;
NumUsrFound + + )
{
UsrDat . UsrCod = ListUsrCods . Lst [ NumUsrFound ] ;
2015-09-14 10:47:39 +02:00
Enr_RegisterUsr ( & UsrDat , Role , & LstGrps , & NumUsrsRegistered ) ;
2014-12-12 18:52:06 +01:00
}
else if ( ItLooksLikeAUsrID ) // User not found. He/she is a new user. Register him/her using ID
2015-09-14 10:47:39 +02:00
Enr_RegisterUsr ( & UsrDat , Role , & LstGrps , & NumUsrsRegistered ) ;
2014-12-12 18:52:06 +01:00
/* Free memory used for list of users' codes found for this ID */
Usr_FreeListUsrCods ( & ListUsrCods ) ;
}
}
/***** 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 ( ) ;
/***** Write messages with the number of users enrolled/removed *****/
if ( WhatToDo . RemoveUsrs )
{
if ( WhatToDo . EliminateUsrs ) // Eliminate completely from the platform
switch ( NumUsrsEliminated )
{
case 0 :
Lay_ShowAlert ( Lay_INFO , Txt_No_user_has_been_eliminated ) ;
break ;
case 1 :
Lay_ShowAlert ( Lay_SUCCESS , Txt_One_user_has_been_eliminated ) ;
break ;
default :
sprintf ( Gbl . Message , Txt_X_users_have_been_eliminated ,
NumUsrsEliminated ) ;
Lay_ShowAlert ( Lay_SUCCESS , Gbl . Message ) ;
break ;
}
else // Only remove from course / groups
switch ( NumUsrsRemoved )
{
case 0 :
Lay_ShowAlert ( Lay_INFO , Txt_No_user_has_been_removed ) ;
break ;
case 1 :
Lay_ShowAlert ( Lay_SUCCESS , Txt_One_user_has_been_removed ) ;
break ;
default :
sprintf ( Gbl . Message , Txt_X_users_have_been_removed ,
NumUsrsRemoved ) ;
Lay_ShowAlert ( Lay_SUCCESS , Gbl . Message ) ;
break ;
}
}
if ( WhatToDo . RegisterUsrs )
switch ( NumUsrsRegistered )
{
case 0 :
Lay_ShowAlert ( Lay_INFO , Txt_No_user_has_been_enrolled ) ;
break ;
case 1 :
Lay_ShowAlert ( Lay_SUCCESS , Txt_One_user_has_been_enrolled ) ;
break ;
default :
sprintf ( Gbl . Message , Txt_X_users_have_been_enrolled_including_possible_repetitions ,
NumUsrsRegistered ) ;
Lay_ShowAlert ( Lay_SUCCESS , Gbl . Message ) ;
break ;
}
/***** Free memory used by the list of user's IDs *****/
free ( ListUsrsIDs ) ;
/***** Free memory with the list of groups to/from which register/remove users *****/
Grp_FreeListCodGrp ( & LstGrps ) ;
/***** Free list of groups types and groups in current course *****/
Grp_FreeListGrpTypesAndGrps ( ) ;
}
}
/*****************************************************************************/
/********************** 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 *****/
2015-04-07 21:44:24 +02:00
if ( Gbl . Usrs . Me . LoggedRole = = Rol_TEACHER & &
RegRemRole ! = Rol_STUDENT )
2014-12-12 18:52:06 +01:00
Lay_ShowErrorAndExit ( " A teacher only can register new users if they are students. " ) ;
/***** 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
// User does not exist in database;list of IDs is initialized
UsrDat - > IDs . List [ 0 ] . Confirmed = true ; // If he/she is a new user ==> his/her ID will be stored as confirmed in database
2014-12-12 22:39:55 +01:00
Acc_CreateNewUsr ( UsrDat ) ;
2014-12-12 18:52:06 +01:00
}
/***** Register user in current course in database *****/
if ( Gbl . CurrentCrs . Crs . CrsCod > 0 ) // Course selected
{
2015-09-17 11:21:49 +02:00
if ( Usr_CheckIfUsrBelongsToCrs ( UsrDat - > UsrCod ,
Gbl . CurrentCrs . Crs . CrsCod ,
false ) ) // User does belong to current course, modify his/her role
2014-12-12 20:25:00 +01:00
Enr_ModifyRoleInCurrentCrs ( UsrDat , RegRemRole , Cns_QUIET ) ;
2014-12-12 18:52:06 +01:00
else
2014-12-12 20:25:00 +01:00
Enr_RegisterUsrInCurrentCrs ( UsrDat , RegRemRole , Cns_QUIET ,
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 ) + + ;
}
/*****************************************************************************/
/****** Mark the students belonging to an official group as removable ********/
/*****************************************************************************/
static void Enr_MarkOfficialStdsAsRemovable ( long ImpGrpCod , bool RemoveSpecifiedUsrs )
{
char Query [ 1024 ] ;
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
unsigned NumStds ;
unsigned NumStd ;
unsigned NumUsr ;
struct ListUsrCods ListUsrCods ; // List with users' codes for a given user's ID
unsigned NumUsrFound ;
/***** Get imported students belonging to this group from database *****/
sprintf ( Query , " SELECT UsrID FROM imported_students WHERE GrpCod='%ld' " ,
ImpGrpCod ) ;
NumStds = ( unsigned ) DB_QuerySELECT ( Query , & mysql_res , " can not get imported students " ) ;
/***** Mark the students from this official group as removable *****/
for ( NumStd = 0 ;
NumStd < NumStds ;
NumStd + + ) // For each student inside the official group...
{
/* Get user's ID of the student from official list */
row = mysql_fetch_row ( mysql_res ) ;
/***** Allocate space for the list *****/
ID_ReallocateListIDs ( & Gbl . Usrs . Other . UsrDat , 1 ) ;
strncpy ( Gbl . Usrs . Other . UsrDat . IDs . List [ 0 ] . ID , row [ 0 ] , ID_MAX_LENGTH_USR_ID ) ;
Gbl . Usrs . Other . UsrDat . IDs . List [ 0 ] . ID [ ID_MAX_LENGTH_USR_ID ] = ' \0 ' ;
// Users' IDs are always stored internally in capitals and without leading zeros
Str_RemoveLeadingZeros ( Gbl . Usrs . Other . UsrDat . IDs . List [ 0 ] . ID ) ;
Str_ConvertToUpperText ( Gbl . Usrs . Other . UsrDat . IDs . List [ 0 ] . ID ) ;
/* Check if this official user's ID is in the list of students */
if ( ID_CheckIfUsrIDIsValid ( Gbl . Usrs . Other . UsrDat . IDs . List [ 0 ] . ID ) )
if ( ID_GetListUsrCodsFromUsrID ( & Gbl . Usrs . Other . UsrDat , NULL , & ListUsrCods , false ) ) // User(s) found
{
for ( NumUsr = 0 ;
NumUsr < Gbl . Usrs . LstStds . NumUsrs ;
NumUsr + + )
for ( NumUsrFound = 0 ;
NumUsrFound < ListUsrCods . NumUsrs ;
NumUsrFound + + )
if ( Gbl . Usrs . LstStds . Lst [ NumUsr ] . UsrCod = = ListUsrCods . Lst [ NumUsrFound ] ) // User found
Gbl . Usrs . LstStds . Lst [ NumUsr ] . Remove = RemoveSpecifiedUsrs ;
/* Free memory used for list of users' codes found for this ID */
Usr_FreeListUsrCods ( & ListUsrCods ) ;
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult ( & mysql_res ) ;
}
/*****************************************************************************/
/**** Put a link (form) to remove all the students in the current course *****/
/*****************************************************************************/
2015-09-12 14:12:40 +02:00
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 *****/
2015-04-02 18:39:49 +02:00
Act_PutContextualLink ( ActReqRemAllStdCrs , NULL ,
" delon " , 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 )
{
extern const char * Txt_Do_you_really_want_to_remove_the_X_students_from_the_course_Y_ ;
extern const char * Txt_Remove_students ;
extern const char * Txt_No_users_found [ Rol_NUM_ROLES ] ;
unsigned NumStds ;
2015-04-07 21:44:24 +02:00
if ( ( NumStds = Usr_GetNumUsrsInCrs ( Rol_STUDENT , Gbl . CurrentCrs . Crs . CrsCod ) ) )
2014-12-12 18:52:06 +01:00
{
/***** Write message to confirm the removing *****/
sprintf ( Gbl . Message , Txt_Do_you_really_want_to_remove_the_X_students_from_the_course_Y_ ,
NumStds , Gbl . CurrentCrs . Crs . FullName ) ;
Lay_ShowAlert ( Lay_WARNING , Gbl . Message ) ;
/***** Form to remove all the students in current course *****/
Act_FormStart ( ActRemAllStdCrs ) ;
Grp_PutParamAllGroups ( ) ;
Pwd_AskForConfirmationOnDangerousAction ( ) ;
2015-03-24 17:47:26 +01:00
Lay_PutRemoveButton ( Txt_Remove_students ) ;
2015-03-13 00:16:02 +01:00
Act_FormEnd ( ) ;
2014-12-12 18:52:06 +01:00
}
else
{
2015-04-07 21:44:24 +02:00
sprintf ( Gbl . Message , Txt_No_users_found [ Rol_STUDENT ] ,
2014-12-12 18:52:06 +01:00
Gbl . CurrentCrs . Crs . FullName ) ;
Lay_ShowAlert ( Lay_WARNING , Gbl . Message ) ;
}
}
/*****************************************************************************/
/***************** 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 ;
extern const char * Txt_No_users_found [ Rol_NUM_ROLES ] ;
unsigned NumStdsInCrs ;
if ( Pwd_GetConfirmationOnDangerousAction ( ) )
{
if ( ( NumStdsInCrs = Enr_RemAllStdsInCrs ( & Gbl . CurrentCrs . Crs ) ) )
{
sprintf ( Gbl . Message , Txt_The_X_students_who_belonged_to_the_course_Y_have_been_removed_from_it ,
NumStdsInCrs , Gbl . CurrentCrs . Crs . FullName ) ;
Lay_ShowAlert ( Lay_SUCCESS , Gbl . Message ) ;
}
else
{
2015-04-07 21:44:24 +02:00
sprintf ( Gbl . Message , Txt_No_users_found [ Rol_STUDENT ] ,
2014-12-12 18:52:06 +01:00
Gbl . CurrentCrs . Crs . FullName ) ;
Lay_ShowAlert ( Lay_WARNING , Gbl . Message ) ;
}
}
}
/*****************************************************************************/
/***************** 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
2015-04-07 21:44:24 +02:00
Usr_GetUsrsLst ( Rol_STUDENT , Sco_SCOPE_CRS , NULL , false ) ;
2014-12-12 18:52:06 +01:00
NumStdsInCrs = Gbl . Usrs . LstStds . NumUsrs ;
/***** Remove all the students *****/
for ( NumUsr = 0 ;
NumUsr < NumStdsInCrs ;
NumUsr + + )
{
Gbl . Usrs . Other . UsrDat . UsrCod = Gbl . Usrs . LstStds . Lst [ NumUsr ] . UsrCod ;
Enr_EffectivelyRemUsrFromCrs ( & Gbl . Usrs . Other . UsrDat , Crs ,
Enr_REMOVE_WORKS , Cns_QUIET ) ;
}
/***** Free memory for students list *****/
Usr_FreeUsrsList ( & Gbl . Usrs . LstStds ) ;
return NumStdsInCrs ;
}
/*****************************************************************************/
/************* Form to request sign up in the current course *****************/
/*****************************************************************************/
void Enr_ReqSignUpInCrs ( void )
{
extern const char * Txt_You_were_already_enrolled_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 *****/
2015-04-07 21:44:24 +02:00
if ( Gbl . Usrs . Me . UsrDat . RoleInCurrentCrsDB > = Rol_STUDENT )
2014-12-12 18:52:06 +01:00
{
sprintf ( Gbl . Message , Txt_You_were_already_enrolled_as_X_in_the_course_Y ,
2015-03-12 14:45:40 +01:00
Txt_ROLES_SINGUL_abc [ Gbl . Usrs . Me . UsrDat . RoleInCurrentCrsDB ] [ Gbl . Usrs . Me . UsrDat . Sex ] ,
2014-12-12 18:52:06 +01:00
Gbl . CurrentCrs . Crs . FullName ) ;
Lay_ShowAlert ( Lay_WARNING , Gbl . Message ) ;
}
2015-04-07 21:44:24 +02:00
else if ( Gbl . Usrs . Me . LoggedRole = = Rol__GUEST_ | |
Gbl . Usrs . Me . LoggedRole = = Rol_VISITOR )
2014-12-12 18:52:06 +01:00
/***** Show form to modify only the user's role or the user's data *****/
Rec_ShowFormSignUpWithMyCommonRecord ( ) ;
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 )
{
extern const char * Txt_You_were_already_enrolled_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
extern const char * Txt_Your_request_for_enrollment_as_X_in_the_course_Y_has_been_accepted_for_processing ;
char Query [ 512 ] ;
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
char UnsignedStr [ 10 + 1 ] ;
Rol_Role_t RoleFromForm ;
long ReqCod = - 1L ;
unsigned NumUsrsToBeNotifiedByEMail ;
/***** Check if I already belong to course *****/
2015-04-07 21:44:24 +02:00
if ( Gbl . Usrs . Me . UsrDat . RoleInCurrentCrsDB > = Rol_STUDENT )
2014-12-12 18:52:06 +01:00
{
sprintf ( Gbl . Message , Txt_You_were_already_enrolled_as_X_in_the_course_Y ,
2015-03-12 14:45:40 +01:00
Txt_ROLES_SINGUL_abc [ Gbl . Usrs . Me . UsrDat . RoleInCurrentCrsDB ] [ Gbl . Usrs . Me . UsrDat . Sex ] ,
2014-12-12 18:52:06 +01:00
Gbl . CurrentCrs . Crs . FullName ) ;
Lay_ShowAlert ( Lay_WARNING , Gbl . Message ) ;
}
else
{
/***** Get new role from record form *****/
Par_GetParToText ( " Role " , UnsignedStr , 10 ) ;
2014-12-12 20:25:00 +01:00
RoleFromForm = Rol_ConvertUnsignedStrToRole ( UnsignedStr ) ;
2014-12-12 18:52:06 +01:00
/* Check if role is correct */
2015-04-07 21:44:24 +02:00
if ( ! ( RoleFromForm = = Rol_STUDENT | |
RoleFromForm = = Rol_TEACHER ) )
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 *****/
sprintf ( Query , " SELECT ReqCod FROM crs_usr_requests "
" WHERE CrsCod='%ld' AND UsrCod='%ld' " ,
Gbl . CurrentCrs . Crs . CrsCod ,
Gbl . Usrs . Me . UsrDat . UsrCod ) ;
if ( DB_QuerySELECT ( Query , & mysql_res , " can not get enrollment request " ) )
{
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
{
sprintf ( Query , " 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 ) ;
DB_QueryUPDATE ( Query , " can not update enrollment request " ) ;
}
else // No request in database for this user in this course
{
sprintf ( Query , " 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 ) ;
ReqCod = DB_QueryINSERTandReturnCode ( Query , " can not save enrollment request " ) ;
}
/***** Show confirmation message *****/
sprintf ( Gbl . Message , Txt_Your_request_for_enrollment_as_X_in_the_course_Y_has_been_accepted_for_processing ,
2015-03-12 14:45:40 +01:00
Txt_ROLES_SINGUL_abc [ RoleFromForm ] [ Gbl . Usrs . Me . UsrDat . Sex ] ,
2014-12-12 18:52:06 +01:00
Gbl . CurrentCrs . Crs . FullName ) ;
Lay_ShowAlert ( Lay_SUCCESS , Gbl . Message ) ;
/***** Notify teachers or admins by e-mail about the new enrollment request *****/
// 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
2015-04-07 21:44:24 +02:00
if ( Gbl . CurrentCrs . Crs . NumTchs | | RoleFromForm = = Rol_TEACHER )
2014-12-12 18:52:06 +01:00
{
NumUsrsToBeNotifiedByEMail = Ntf_StoreNotifyEventsToAllUsrs ( Ntf_EVENT_ENROLLMENT_REQUEST , ReqCod ) ;
Ntf_ShowAlertNumUsrsToBeNotifiedByEMail ( NumUsrsToBeNotifiedByEMail ) ;
}
}
}
/*****************************************************************************/
/************** Put an enrollment request into a notification *****************/
/*****************************************************************************/
// This function may be called inside a web service, so don't report error
void Enr_GetNotifEnrollmentRequest ( char * SummaryStr , char * * ContentStr ,
long ReqCod , unsigned MaxChars , bool GetContent )
{
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
char Query [ 256 ] ;
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
struct UsrData UsrDat ;
Rol_Role_t DesiredRole ;
SummaryStr [ 0 ] = ' \0 ' ; // Return nothing on error
/***** Get user and requested role from database *****/
sprintf ( Query , " SELECT UsrCod,Role, "
" DATE_FORMAT(RequestTime,'%%Y%%m%%d%%H%%i%%S') "
" FROM crs_usr_requests "
" WHERE ReqCod='%ld' " ,
ReqCod ) ;
if ( ! mysql_query ( & Gbl . mysql , Query ) )
if ( ( mysql_res = mysql_store_result ( & Gbl . mysql ) ) ! = NULL )
{
/***** Result should have a unique row *****/
if ( mysql_num_rows ( mysql_res ) = = 1 )
{
/***** Get user and requested role *****/
row = mysql_fetch_row ( mysql_res ) ;
/* Initialize structure with user's data */
Usr_UsrDataConstructor ( & UsrDat ) ;
/* User's code (row[0]) */
UsrDat . UsrCod = Str_ConvertStrCodToLongCod ( row [ 0 ] ) ;
Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod ( & UsrDat ) ;
/* Role (row[1]) */
2014-12-12 20:25:00 +01:00
DesiredRole = Rol_ConvertUnsignedStrToRole ( row [ 1 ] ) ;
2015-03-12 14:45:40 +01:00
strcpy ( SummaryStr , Txt_ROLES_SINGUL_Abc [ DesiredRole ] [ UsrDat . Sex ] ) ;
2014-12-12 18:52:06 +01:00
if ( MaxChars )
Str_LimitLengthHTMLStr ( SummaryStr , MaxChars ) ;
if ( GetContent )
if ( ( * ContentStr = ( char * ) malloc ( 16 + 1 ) ) )
/* Write date (row[2]) into content */
sprintf ( * ContentStr , " %c%c/%c%c/%c%c%c%c %c%c:%c%c " ,
row [ 2 ] [ 6 ] , row [ 2 ] [ 7 ] ,
row [ 2 ] [ 4 ] , row [ 2 ] [ 5 ] ,
row [ 2 ] [ 0 ] , row [ 2 ] [ 1 ] , row [ 2 ] [ 2 ] , row [ 2 ] [ 3 ] ,
row [ 2 ] [ 8 ] , row [ 2 ] [ 9 ] ,
row [ 2 ] [ 10 ] , row [ 2 ] [ 11 ] ) ;
/* Free memory used for user's data */
Usr_UsrDataDestructor ( & UsrDat ) ;
}
mysql_free_result ( mysql_res ) ;
}
}
/*****************************************************************************/
/****** Ask if reject the request for enrollment of a user in a course *******/
/*****************************************************************************/
void Enr_AskIfRejectSignUp ( void )
{
extern const char * Txt_THE_USER_X_is_already_enrolled_in_the_course_Y ;
extern const char * Txt_Do_you_really_want_to_reject_the_enrollment_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 ;
extern const char * Txt_User_not_found_or_you_do_not_have_permission_ ;
Rol_Role_t Role ;
/***** Get user's code *****/
Usr_GetParamOtherUsrCodEncrypted ( ) ;
if ( Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod ( & Gbl . Usrs . Other . UsrDat ) ) // If user's data exist...
{
2015-09-17 11:21:49 +02:00
if ( Usr_CheckIfUsrBelongsToCrs ( Gbl . Usrs . Other . UsrDat . UsrCod ,
Gbl . CurrentCrs . Crs . CrsCod ,
false ) )
2014-12-12 18:52:06 +01:00
{
/* User already belongs to this course */
sprintf ( Gbl . Message , Txt_THE_USER_X_is_already_enrolled_in_the_course_Y ,
Gbl . Usrs . Other . UsrDat . FullName , Gbl . CurrentCrs . Crs . FullName ) ;
Lay_ShowAlert ( Lay_WARNING , Gbl . Message ) ;
Rec_ShowCommonRecordUnmodifiable ( & Gbl . Usrs . Other . UsrDat ) ;
/* Remove inscription request because it has not sense */
Enr_RemoveEnrollmentRequest ( Gbl . CurrentCrs . Crs . CrsCod , Gbl . Usrs . Other . UsrDat . UsrCod ) ;
}
else // User does not belong to this course
{
2014-12-12 22:39:55 +01:00
Role = Rol_GetRequestedRole ( Gbl . Usrs . Other . UsrDat . UsrCod ) ;
2015-04-07 21:44:24 +02:00
if ( Role = = Rol_STUDENT | |
Role = = Rol_TEACHER )
2014-12-12 18:52:06 +01:00
{
/* Ask if reject */
sprintf ( Gbl . Message , Txt_Do_you_really_want_to_reject_the_enrollment_request_ ,
Gbl . Usrs . Other . UsrDat . FullName ,
2015-03-12 14:45:40 +01:00
Txt_ROLES_SINGUL_abc [ Role ] [ Gbl . Usrs . Other . UsrDat . Sex ] ,
2014-12-12 18:52:06 +01:00
Gbl . CurrentCrs . Crs . FullName ) ;
Lay_ShowAlert ( Lay_INFO , Gbl . Message ) ;
Rec_ShowCommonRecordUnmodifiable ( & Gbl . Usrs . Other . UsrDat ) ;
/* Button to confirm rejection */
Act_FormStart ( ActRejSignUp ) ;
2015-04-02 18:39:49 +02:00
Usr_PutParamOtherUsrCodEncrypted ( ) ;
2014-12-12 18:52:06 +01:00
2015-03-24 17:47:26 +01:00
Lay_PutConfirmButton ( Txt_Reject ) ;
2015-03-13 00:16:02 +01:00
Act_FormEnd ( ) ;
2014-12-12 18:52:06 +01:00
}
else
Lay_ShowErrorAndExit ( " Wrong role. " ) ;
}
}
else
Lay_ShowAlert ( Lay_WARNING , Txt_User_not_found_or_you_do_not_have_permission_ ) ;
}
/*****************************************************************************/
/********* Reject the request for enrollment of a user in a course ***********/
/*****************************************************************************/
void Enr_RejectSignUp ( void )
{
extern const char * Txt_THE_USER_X_is_already_enrolled_in_the_course_Y ;
extern const char * Txt_Enrollment_of_X_rejected ;
extern const char * Txt_User_not_found_or_you_do_not_have_permission_ ;
/***** Get user's code *****/
Usr_GetParamOtherUsrCodEncrypted ( ) ;
if ( Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod ( & Gbl . Usrs . Other . UsrDat ) ) // If user's data exist...
{
2015-09-17 11:21:49 +02:00
if ( Usr_CheckIfUsrBelongsToCrs ( Gbl . Usrs . Other . UsrDat . UsrCod ,
Gbl . CurrentCrs . Crs . CrsCod ,
false ) )
2014-12-12 18:52:06 +01:00
{
/* User already belongs to this course */
sprintf ( Gbl . Message , Txt_THE_USER_X_is_already_enrolled_in_the_course_Y ,
Gbl . Usrs . Other . UsrDat . FullName , Gbl . CurrentCrs . Crs . FullName ) ;
Lay_ShowAlert ( Lay_WARNING , Gbl . Message ) ;
Rec_ShowCommonRecordUnmodifiable ( & Gbl . Usrs . Other . UsrDat ) ;
}
/* Remove inscription request */
Enr_RemoveEnrollmentRequest ( Gbl . CurrentCrs . Crs . CrsCod , Gbl . Usrs . Other . UsrDat . UsrCod ) ;
/* Confirmation message */
sprintf ( Gbl . Message , Txt_Enrollment_of_X_rejected ,
Gbl . Usrs . Other . UsrDat . FullName ) ;
Lay_ShowAlert ( Lay_SUCCESS , Gbl . Message ) ;
}
else
Lay_ShowAlert ( Lay_WARNING , Txt_User_not_found_or_you_do_not_have_permission_ ) ;
/* Show again the rest of registrarion requests */
Enr_ShowEnrollmentRequests ( ) ;
}
/*****************************************************************************/
/******** Show pending requests for enrollment in the current course *********/
/*****************************************************************************/
void Enr_ShowEnrollmentRequests ( void )
{
2015-07-27 21:25:45 +02:00
extern const char * The_ClassForm [ The_NUM_THEMES ] ;
extern const char * The_ClassFormBold [ The_NUM_THEMES ] ;
2014-12-12 18:52:06 +01:00
extern const char * Txt_Scope ;
extern const char * Txt_Users ;
extern const char * Txt_Update ;
extern const char * Txt_Course ;
extern const char * Txt_Teachers_ABBREVIATION ;
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 ;
extern const char * Txt_No_enrollment_requests ;
unsigned Roles ;
char Query [ 1024 ] ;
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
unsigned NumReq ;
unsigned NumRequests ;
long ReqCod ;
struct Degree Deg ;
struct Course Crs ;
struct UsrData UsrDat ;
bool UsrExists ;
bool UsrBelongsToCrs ;
bool ShowPhoto = false ;
char PhotoURL [ PATH_MAX + 1 ] ;
Rol_Role_t DesiredRole ;
/***** Selection of scope and roles *****/
/* Start form */
Act_FormStart ( ActSeeSignUpReq ) ;
2014-12-27 01:07:14 +01:00
fprintf ( Gbl . F . Out , " <table style= \" margin:0 auto; border-spacing:4px; \" > " ) ;
2014-12-12 18:52:06 +01:00
/* Scope (whole platform, current centre, current degree or current course) */
fprintf ( Gbl . F . Out , " <tr> "
2015-07-27 21:25:45 +02:00
" <td class= \" %s RIGHT_MIDDLE \" > "
2014-12-22 21:52:37 +01:00
" %s: "
" </td> "
2015-08-01 08:40:58 +02:00
" <td class= \" LEFT_MIDDLE \" > " ,
2015-07-27 21:25:45 +02:00
The_ClassForm [ Gbl . Prefs . Theme ] ,
Txt_Scope ) ;
2015-02-01 20:17:24 +01:00
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 ;
2014-12-12 18:52:06 +01:00
Sco_GetScope ( ) ;
Sco_PutSelectorScope ( false ) ;
fprintf ( Gbl . F . Out , " </td> "
" </tr> " ) ;
/* Users' roles in listing */
fprintf ( Gbl . F . Out , " <tr> "
2015-07-27 21:25:45 +02:00
" <td class= \" %s RIGHT_TOP \" > "
2014-12-22 21:52:37 +01:00
" %s: "
" </td> "
2015-08-01 08:40:58 +02:00
" <td class= \" DAT LEFT_MIDDLE \" > " ,
2015-07-27 21:25:45 +02:00
The_ClassForm [ Gbl . Prefs . Theme ] ,
Txt_Users ) ;
2014-12-12 20:25:00 +01:00
Rol_GetSelectedRoles ( & Roles ) ;
2014-12-12 18:52:06 +01:00
if ( ! Roles )
/* Set default roles */
switch ( Gbl . Usrs . Me . LoggedRole )
{
2015-04-07 21:44:24 +02:00
case Rol_TEACHER :
Roles = ( 1 < < Rol_STUDENT ) | ( 1 < < Rol_TEACHER ) ;
2014-12-12 18:52:06 +01:00
break ;
2015-04-07 21:44:24 +02:00
case Rol_DEG_ADM :
case Rol_SYS_ADM :
Roles = ( 1 < < Rol_TEACHER ) ;
2014-12-12 18:52:06 +01:00
break ;
default :
Lay_ShowErrorAndExit ( " You don't have permission to list requesters. " ) ;
break ;
}
2014-12-12 20:25:00 +01:00
Rol_WriteSelectorRoles ( Roles ) ;
2014-12-12 18:52:06 +01:00
fprintf ( Gbl . F . Out , " </td> "
2015-03-24 20:26:31 +01:00
" </tr> "
" </table> " ) ;
/* Send button */
2015-04-02 14:22:21 +02:00
fprintf ( Gbl . F . Out , " <div class= \" CONTEXT_MENU \" > " ) ;
2015-07-27 21:25:45 +02:00
Act_LinkFormSubmitAnimated ( Txt_Update , The_ClassFormBold [ Gbl . Prefs . Theme ] ) ;
2015-04-12 18:01:06 +02:00
Lay_PutCalculateIconWithText ( Txt_Update , Txt_Update ) ;
2015-03-13 00:16:02 +01:00
Act_FormEnd ( ) ;
2015-04-02 14:22:21 +02:00
fprintf ( Gbl . F . Out , " </div> " ) ;
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
2014-12-12 18:52:06 +01:00
switch ( Gbl . Usrs . Me . LoggedRole )
{
2015-04-07 21:44:24 +02:00
case Rol_TEACHER :
2014-12-12 18:52:06 +01:00
sprintf ( Query , " SELECT crs_usr_requests.ReqCod,crs_usr_requests.CrsCod,crs_usr_requests.UsrCod,crs_usr_requests.Role,DATE_FORMAT(crs_usr_requests.RequestTime,'%%Y%%m%%d%%H%%i%%S') "
" FROM crs_usr,crs_usr_requests "
" WHERE crs_usr.UsrCod='%ld' "
" 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 ,
Roles ) ;
break ;
2015-04-07 21:44:24 +02:00
case Rol_DEG_ADM :
2014-12-12 18:52:06 +01:00
sprintf ( Query , " SELECT crs_usr_requests.ReqCod,crs_usr_requests.CrsCod,crs_usr_requests.UsrCod,crs_usr_requests.Role,DATE_FORMAT(crs_usr_requests.RequestTime,'%%Y%%m%%d%%H%%i%%S') "
2015-01-29 01:03:31 +01:00
" FROM admin,courses,crs_usr_requests "
" WHERE admin.UsrCod='%ld' AND admin.Scope='Deg' "
" AND admin.Cod=courses.DegCod "
2014-12-12 18:52:06 +01:00
" 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 ,
Roles ) ;
break ;
2015-04-07 21:44:24 +02:00
case Rol_SYS_ADM :
2014-12-12 18:52:06 +01:00
sprintf ( Query , " SELECT ReqCod,CrsCod,UsrCod,Role,DATE_FORMAT(RequestTime,'%%Y%%m%%d%%H%%i%%S') "
" FROM crs_usr_requests WHERE ((1<<Role)&%u)<>0 "
" ORDER BY RequestTime DESC " ,
Roles ) ;
break ;
default :
Lay_ShowErrorAndExit ( " You don't have permission to list requesters. " ) ;
break ;
}
break ;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_INS : // Show requesters for the current institution
2014-12-12 18:52:06 +01:00
switch ( Gbl . Usrs . Me . LoggedRole )
{
2015-04-07 21:44:24 +02:00
case Rol_TEACHER :
2014-12-12 18:52:06 +01:00
sprintf ( Query , " SELECT crs_usr_requests.ReqCod,crs_usr_requests.CrsCod,crs_usr_requests.UsrCod,crs_usr_requests.Role,DATE_FORMAT(crs_usr_requests.RequestTime,'%%Y%%m%%d%%H%%i%%S') "
" FROM crs_usr,centres,degrees,courses,crs_usr_requests "
" WHERE crs_usr.UsrCod='%ld' "
" AND centres.InsCod='%ld' "
" AND crs_usr.CrsCod=courses.CrsCod "
" AND degrees.DegCod=courses.DegCod "
" AND degrees.CtrCod=centres.CtrCod "
" 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 ,
Gbl . CurrentIns . Ins . InsCod ,
Roles ) ;
break ;
2015-04-07 21:44:24 +02:00
case Rol_DEG_ADM :
2014-12-12 18:52:06 +01:00
sprintf ( Query , " SELECT crs_usr_requests.ReqCod,crs_usr_requests.CrsCod,crs_usr_requests.UsrCod,crs_usr_requests.Role,DATE_FORMAT(crs_usr_requests.RequestTime,'%%Y%%m%%d%%H%%i%%S') "
2015-01-29 01:03:31 +01:00
" FROM admin,centres,degrees,courses,crs_usr_requests "
" WHERE admin.UsrCod='%ld' AND admin.Scope='Deg' "
2014-12-12 18:52:06 +01:00
" AND centres.InsCod='%ld' "
2015-01-29 01:03:31 +01:00
" AND admin.Cod=degrees.DegCod "
" AND admin.Cod=courses.DegCod "
2014-12-12 18:52:06 +01:00
" AND degrees.CtrCod=centres.CtrCod "
" 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 ,
Gbl . CurrentIns . Ins . InsCod ,
Roles ) ;
break ;
2015-04-07 21:44:24 +02:00
case Rol_SYS_ADM :
2014-12-12 18:52:06 +01:00
sprintf ( Query , " SELECT crs_usr_requests.ReqCod,crs_usr_requests.CrsCod,crs_usr_requests.UsrCod,crs_usr_requests.Role,DATE_FORMAT(crs_usr_requests.RequestTime,'%%Y%%m%%d%%H%%i%%S') "
" 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 ,
Roles ) ;
break ;
default :
Lay_ShowErrorAndExit ( " You don't have permission to list requesters. " ) ;
break ;
}
break ;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_CTR : // Show requesters for the current centre
2014-12-12 18:52:06 +01:00
switch ( Gbl . Usrs . Me . LoggedRole )
{
2015-04-07 21:44:24 +02:00
case Rol_TEACHER :
2014-12-12 18:52:06 +01:00
sprintf ( Query , " SELECT crs_usr_requests.ReqCod,crs_usr_requests.CrsCod,crs_usr_requests.UsrCod,crs_usr_requests.Role,DATE_FORMAT(crs_usr_requests.RequestTime,'%%Y%%m%%d%%H%%i%%S') "
" FROM crs_usr,degrees,courses,crs_usr_requests "
" WHERE crs_usr.UsrCod='%ld' "
" AND degrees.CtrCod='%ld' "
" AND crs_usr.CrsCod=courses.CrsCod "
" 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 ,
Gbl . CurrentCtr . Ctr . CtrCod ,
Roles ) ;
break ;
2015-04-07 21:44:24 +02:00
case Rol_DEG_ADM :
2014-12-12 18:52:06 +01:00
sprintf ( Query , " SELECT crs_usr_requests.ReqCod,crs_usr_requests.CrsCod,crs_usr_requests.UsrCod,crs_usr_requests.Role,DATE_FORMAT(crs_usr_requests.RequestTime,'%%Y%%m%%d%%H%%i%%S') "
2015-01-29 01:03:31 +01:00
" FROM admin,degrees,courses,crs_usr_requests "
" WHERE admin.UsrCod='%ld' AND admin.Scope='Deg' "
2014-12-12 18:52:06 +01:00
" AND degrees.CtrCod='%ld' "
2015-01-29 01:03:31 +01:00
" AND admin.Cod=degrees.DegCod "
" AND admin.Cod=courses.DegCod "
2014-12-12 18:52:06 +01:00
" 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 ,
Gbl . CurrentCtr . Ctr . CtrCod ,
Roles ) ;
break ;
2015-04-07 21:44:24 +02:00
case Rol_SYS_ADM :
2014-12-12 18:52:06 +01:00
sprintf ( Query , " SELECT crs_usr_requests.ReqCod,crs_usr_requests.CrsCod,crs_usr_requests.UsrCod,crs_usr_requests.Role,DATE_FORMAT(crs_usr_requests.RequestTime,'%%Y%%m%%d%%H%%i%%S') "
" 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 ,
Roles ) ;
break ;
default :
Lay_ShowErrorAndExit ( " You don't have permission to list requesters. " ) ;
break ;
}
break ;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_DEG : // Show requesters for the current degree
2014-12-12 18:52:06 +01:00
switch ( Gbl . Usrs . Me . LoggedRole )
{
2015-04-07 21:44:24 +02:00
case Rol_TEACHER :
2014-12-12 18:52:06 +01:00
sprintf ( Query , " SELECT crs_usr_requests.ReqCod,crs_usr_requests.CrsCod,crs_usr_requests.UsrCod,crs_usr_requests.Role,DATE_FORMAT(crs_usr_requests.RequestTime,'%%Y%%m%%d%%H%%i%%S') "
" FROM crs_usr,courses,crs_usr_requests "
" WHERE crs_usr.UsrCod='%ld' "
" 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 ,
Gbl . CurrentDeg . Deg . DegCod ,
Roles ) ;
break ;
2015-04-07 21:44:24 +02:00
case Rol_DEG_ADM :
case Rol_SYS_ADM :
2014-12-12 18:52:06 +01:00
sprintf ( Query , " SELECT crs_usr_requests.ReqCod,crs_usr_requests.CrsCod,crs_usr_requests.UsrCod,crs_usr_requests.Role,DATE_FORMAT(crs_usr_requests.RequestTime,'%%Y%%m%%d%%H%%i%%S') "
" 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 ,
Roles ) ;
break ;
default :
Lay_ShowErrorAndExit ( " You don't have permission to list requesters. " ) ;
break ;
}
break ;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_CRS : // Show requesters for the current course
2014-12-12 18:52:06 +01:00
switch ( Gbl . Usrs . Me . LoggedRole )
{
2015-04-07 21:44:24 +02:00
case Rol_TEACHER :
case Rol_DEG_ADM :
case Rol_SYS_ADM :
2014-12-12 18:52:06 +01:00
sprintf ( Query , " SELECT ReqCod,CrsCod,UsrCod,Role,DATE_FORMAT(RequestTime,'%%Y%%m%%d%%H%%i%%S') "
" FROM crs_usr_requests "
" WHERE CrsCod='%ld' "
" AND ((1<<Role)&%u)<>0 "
" ORDER BY RequestTime DESC " ,
Gbl . CurrentCrs . Crs . CrsCod , Roles ) ;
break ;
default :
Lay_ShowErrorAndExit ( " You don't have permission to list requesters. " ) ;
break ;
}
break ;
default :
Lay_ShowErrorAndExit ( " Wrong scope. " ) ;
break ;
}
NumRequests = ( unsigned ) DB_QuerySELECT ( Query , & mysql_res , " can not get requests for enrollment " ) ;
/***** List requests *****/
if ( NumRequests )
{
/* Initialize structure with user's data */
Usr_UsrDataConstructor ( & UsrDat ) ;
/* Start table */
2015-04-12 18:01:06 +02:00
Lay_StartRoundFrameTable ( NULL , 2 , NULL ) ;
2014-12-12 18:52:06 +01:00
fprintf ( Gbl . F . Out , " <tr> "
2014-12-26 22:11:03 +01:00
" <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 ,
Txt_Teachers_ABBREVIATION ,
Txt_Requester ,
Txt_Role ,
Txt_Date ) ;
/* List requests */
for ( NumReq = 0 ;
NumReq < NumRequests ;
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 & &
( DesiredRole = = Rol_STUDENT | |
DesiredRole = = Rol_TEACHER ) )
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 \" > "
2014-12-22 21:52:37 +01:00
" %u "
" </td> " ,
2014-12-12 18:52:06 +01:00
NumRequests - NumReq ) ;
/***** 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 \" > " ) ;
2014-12-12 18:52:06 +01:00
Act_FormGoToStart ( ActSeeCrsInf ) ;
Crs_PutParamCrsCod ( Crs . CrsCod ) ;
sprintf ( Gbl . Title , Txt_Go_to_X , Crs . FullName ) ;
Act_LinkFormSubmit ( Gbl . Title , " DAT " ) ;
2014-12-22 21:52:37 +01:00
fprintf ( Gbl . F . Out , " %s > %s "
2015-03-13 00:16:02 +01:00
" </a> " ,
2014-12-12 18:52:06 +01:00
Deg . ShortName , Crs . ShortName ) ;
2015-03-13 00:16:02 +01:00
Act_FormEnd ( ) ;
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> " ,
Crs . NumTchs ) ;
/***** User photo *****/
2015-08-01 08:40:58 +02:00
fprintf ( Gbl . F . Out , " <td class= \" DAT CENTER_TOP \" "
" style= \" width:18px; \" > " ) ;
2014-12-12 18:52:06 +01:00
ShowPhoto = Pho_ShowUsrPhotoIsAllowed ( & UsrDat , PhotoURL ) ;
2014-12-30 15:14:43 +01:00
Pho_ShowUsrPhoto ( & UsrDat , ShowPhoto ? PhotoURL :
NULL ,
2015-03-13 00:16:02 +01:00
" PHOTO18x24 " , Pho_ZOOM ) ;
2014-12-12 18:52:06 +01:00
fprintf ( Gbl . F . Out , " </td> " ) ;
/***** User name *****/
2015-08-01 08:40:58 +02:00
fprintf ( Gbl . F . Out , " <td class= \" DAT LEFT_TOP \" > " ) ;
2014-12-12 18:52:06 +01:00
Usr_RestrictLengthAndWriteName ( & UsrDat , 20 ) ;
/***** 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]) *****/
Msg_WriteMsgDate ( row [ 4 ] , " DAT " ) ;
/***** Button to confirm the request *****/
2015-08-01 08:40:58 +02:00
fprintf ( Gbl . F . Out , " <td class= \" DAT LEFT_TOP \" > " ) ;
2015-09-12 14:12:40 +02:00
Act_FormStart ( DesiredRole = = Rol_STUDENT ? ActReqMdfStd :
ActReqMdfTch ) ;
2014-12-12 18:52:06 +01:00
Crs_PutParamCrsCod ( Crs . CrsCod ) ;
2015-04-02 18:39:49 +02:00
Usr_PutParamUsrCodEncrypted ( UsrDat . EncryptedUsrCod ) ;
2015-03-24 17:47:26 +01:00
Lay_PutCreateButton ( Txt_Register ) ;
2015-03-13 00:16:02 +01:00
Act_FormEnd ( ) ;
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 \" > " ) ;
2014-12-12 18:52:06 +01:00
Act_FormStart ( ActReqRejSignUp ) ;
Crs_PutParamCrsCod ( Crs . CrsCod ) ;
2015-04-02 18:39:49 +02:00
Usr_PutParamUsrCodEncrypted ( UsrDat . EncryptedUsrCod ) ;
2015-03-24 17:47:26 +01:00
Lay_PutConfirmButton ( Txt_Reject ) ;
2015-03-13 00:16:02 +01:00
Act_FormEnd ( ) ;
fprintf ( Gbl . F . Out , " </td> "
2014-12-12 18:52:06 +01:00
" </tr> " ) ;
/***** Mark possible notification as seen *****/
Ntf_SetNotifAsSeen ( Ntf_EVENT_ENROLLMENT_REQUEST ,
ReqCod ,
Gbl . Usrs . Me . UsrDat . UsrCod ) ;
}
else // User does not exists or user already belongs to course ==> remove pair from crs_usr_requests table
Enr_RemoveEnrollmentRequest ( Crs . CrsCod , UsrDat . UsrCod ) ;
}
2015-04-11 23:46:21 +02:00
/* End frame */
2015-04-12 18:01:06 +02:00
Lay_EndRoundFrameTable ( ) ;
2014-12-12 18:52:06 +01:00
/* Free memory used for user's data */
Usr_UsrDataDestructor ( & UsrDat ) ;
}
else // There are no requests
Lay_ShowAlert ( Lay_INFO , Txt_No_enrollment_requests ) ;
}
/*****************************************************************************/
/******************** Remove a request for inscription ***********************/
/*****************************************************************************/
static void Enr_RemoveEnrollmentRequest ( long CrsCod , long UsrCod )
{
char Query [ 256 ] ;
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) */
sprintf ( Query , " SELECT ReqCod FROM crs_usr_requests "
" WHERE CrsCod='%ld' AND UsrCod='%ld' " ,
CrsCod , UsrCod ) ;
if ( DB_QuerySELECT ( Query , & mysql_res , " can not get request code " ) ) // Request exists
{
/* Get request code */
row = mysql_fetch_row ( mysql_res ) ;
ReqCod = Str_ConvertStrCodToLongCod ( row [ 0 ] ) ;
/* Mark possible notifications as removed */
Ntf_SetNotifAsRemoved ( Ntf_EVENT_ENROLLMENT_REQUEST , ReqCod ) ;
}
/* Free structure that stores the query result */
DB_FreeMySQLResult ( & mysql_res ) ;
/***** Remove enrollment request *****/
sprintf ( Query , " DELETE FROM crs_usr_requests "
" WHERE CrsCod='%ld' AND UsrCod='%ld' " ,
CrsCod , UsrCod ) ;
DB_QueryDELETE ( Query , " can not remove a request for enrollment " ) ;
}
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
{
2015-09-16 00:15:20 +02:00
extern const char * Txt_Admin_me ;
2014-12-31 01:32:42 +01:00
extern const char * Txt_Admin_one_user ;
2015-09-16 00:15:20 +02:00
Act_PutContextualLink ( NextAction , NULL , " configtest " ,
Enr_CheckIfICanAdminOtherUsrs ( ) ? Txt_Admin_one_user :
Txt_Admin_me ) ;
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
{
2015-09-14 10:47:39 +02:00
extern const char * Txt_Admin_several_students ;
extern const char * Txt_Admin_several_teachers ;
2015-02-08 19:11:54 +01:00
2015-09-14 17:25:21 +02:00
Act_PutContextualLink ( Role = = Rol_STUDENT ? ActReqEnrSevStd :
ActReqEnrSevTch ,
2015-09-14 10:47:39 +02:00
NULL , " configtest " ,
Role = = Rol_STUDENT ? Txt_Admin_several_students :
Txt_Admin_several_teachers ) ;
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
{
Enr_ReqRegRemUsr ( Rol__GUEST_ ) ;
}
void Enr_ReqRegRemStd ( void )
{
Enr_ReqRegRemUsr ( Rol_STUDENT ) ;
}
void Enr_ReqRegRemTch ( void )
{
Enr_ReqRegRemUsr ( Rol_TEACHER ) ;
}
static void Enr_ReqRegRemUsr ( Rol_Role_t Role )
2014-12-12 18:52:06 +01:00
{
2015-09-16 00:15:20 +02:00
if ( Enr_CheckIfICanAdminOtherUsrs ( ) )
Enr_ReqAnotherUsrIDToRegisterRemove ( Role ) ;
else
Enr_AskIfRegRemMe ( Role ) ;
}
/*****************************************************************************/
/*********** Check If I can admin other users (distinct to me) ***************/
/*****************************************************************************/
2014-12-12 18:52:06 +01:00
2015-09-16 00:15:20 +02:00
static bool Enr_CheckIfICanAdminOtherUsrs ( void )
{
2014-12-12 18:52:06 +01:00
switch ( Gbl . Usrs . Me . LoggedRole )
{
2015-09-16 00:15:20 +02:00
case Rol_UNKNOWN :
2015-04-07 21:44:24 +02:00
case Rol__GUEST_ :
2015-09-16 00:15:20 +02:00
case Rol_VISITOR :
2015-04-07 21:44:24 +02:00
case Rol_STUDENT :
2015-09-16 00:15:20 +02:00
return false ;
2015-04-07 21:44:24 +02:00
case Rol_TEACHER :
2015-09-16 00:15:20 +02:00
return ( Gbl . CurrentCrs . Crs . CrsCod > 0 ) ;
2015-04-07 21:44:24 +02:00
case Rol_DEG_ADM :
2015-09-16 00:15:20 +02:00
return ( Gbl . CurrentDeg . Deg . DegCod > 0 ) ;
2015-04-07 21:44:24 +02:00
case Rol_CTR_ADM :
2015-09-16 00:15:20 +02:00
return ( Gbl . CurrentCtr . Ctr . CtrCod > 0 ) ;
2015-04-07 21:44:24 +02:00
case Rol_INS_ADM :
2015-09-16 00:15:20 +02:00
return ( Gbl . CurrentIns . Ins . InsCod > 0 ) ;
2015-04-07 21:44:24 +02:00
case Rol_SYS_ADM :
2015-09-16 00:15:20 +02:00
return true ;
2014-12-12 18:52:06 +01:00
}
2015-09-16 00:15:20 +02:00
return false ;
2014-12-12 18:52:06 +01:00
}
/*****************************************************************************/
/****** Write a form to request another user's ID, @nickname or e-mail *******/
/*****************************************************************************/
2015-09-12 14:12:40 +02:00
static void Enr_ReqAnotherUsrIDToRegisterRemove ( Rol_Role_t Role )
2014-12-12 18:52:06 +01:00
{
2015-02-08 18:45:13 +01:00
extern const char * Txt_Admin_one_user ;
2014-12-12 18:52:06 +01:00
2015-02-08 18:45:13 +01:00
/***** Start frame *****/
2015-04-12 18:01:06 +02:00
Lay_StartRoundFrame ( NULL , Txt_Admin_one_user ) ;
2014-12-12 18:52:06 +01:00
2015-02-08 18:45:13 +01:00
/***** Write form to request another user's ID *****/
2015-09-17 16:54:02 +02:00
Enr_WriteFormToReqAnotherUsrID ( Role = = Rol_STUDENT ? ActReqMdfStd :
2015-09-12 14:12:40 +02:00
( Role = = Rol_TEACHER ? ActReqMdfTch :
2015-09-17 16:54:02 +02:00
ActReqMdfOth ) ) ;
2015-02-08 18:45:13 +01:00
/***** End frame *****/
2015-04-12 18:01:06 +02:00
Lay_EndRoundFrame ( ) ;
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
{
Enr_AskIfRegRemAnotherUsr ( Rol__GUEST_ ) ;
}
void Enr_AskIfRegRemAnotherStd ( void )
{
Enr_AskIfRegRemAnotherUsr ( Rol_STUDENT ) ;
}
void Enr_AskIfRegRemAnotherTch ( void )
{
Enr_AskIfRegRemAnotherUsr ( Rol_TEACHER ) ;
}
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 *****/
Usr_GetParamOtherUsrCodEncrypted ( ) ;
if ( Gbl . Usrs . Other . UsrDat . UsrCod > 0 )
{
/***** If UsrCod is present in parameters,
use this parameter to identify the user to be enrolled / removed * * * * */
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,
use user ' s ID to identify the user to be enrolled / removed * * * * */
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 ;
extern const char * Txt_THE_USER_X_is_already_enrolled_in_the_course_Y ;
extern const char * Txt_THE_USER_X_is_already_in_the_course_Y_but_has_not_yet_accepted_the_enrollment ;
extern const char * Txt_THE_USER_X_already_exists_in_Y_but_is_not_yet_enrolled_in_the_course_Z ;
extern const char * Txt_THE_USER_X_already_exists_in_Y ;
extern const char * Txt_The_user_is_new_does_not_exists_yet_in_X ;
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 )
{
sprintf ( Gbl . Message , Txt_There_are_X_users_with_the_ID_Y ,
ListUsrCods - > NumUsrs , Gbl . Usrs . Other . UsrDat . UsrIDNickOrEmail ) ;
Lay_ShowAlert ( Lay_INFO , Gbl . Message ) ;
}
/***** 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 */
2015-09-17 11:21:49 +02:00
if ( Usr_CheckIfUsrBelongsToCrs ( Gbl . Usrs . Other . UsrDat . UsrCod ,
Gbl . CurrentCrs . Crs . CrsCod ,
false ) )
2014-12-12 18:52:06 +01:00
{
2015-09-17 11:21:49 +02:00
Gbl . Usrs . Other . UsrDat . Accepted = Usr_CheckIfUsrBelongsToCrs ( Gbl . Usrs . Other . UsrDat . UsrCod ,
Gbl . CurrentCrs . Crs . CrsCod ,
true ) ;
2014-12-12 18:52:06 +01:00
if ( Gbl . Usrs . Other . UsrDat . Accepted )
sprintf ( Gbl . Message , Txt_THE_USER_X_is_already_enrolled_in_the_course_Y ,
Gbl . Usrs . Other . UsrDat . FullName , Gbl . CurrentCrs . Crs . FullName ) ;
else // Enrollment not yet accepted
sprintf ( Gbl . Message , Txt_THE_USER_X_is_already_in_the_course_Y_but_has_not_yet_accepted_the_enrollment ,
Gbl . Usrs . Other . UsrDat . FullName , Gbl . CurrentCrs . Crs . FullName ) ;
Lay_ShowAlert ( Lay_INFO , Gbl . Message ) ;
Enr_ShowFormToEditOtherUsr ( ) ;
}
else // User does not belong to the current course
{
sprintf ( Gbl . Message , Txt_THE_USER_X_already_exists_in_Y_but_is_not_yet_enrolled_in_the_course_Z ,
Gbl . Usrs . Other . UsrDat . FullName , Cfg_PLATFORM_SHORT_NAME , Gbl . CurrentCrs . Crs . FullName ) ;
Lay_ShowAlert ( Lay_INFO , Gbl . Message ) ;
Enr_ShowFormToEditOtherUsr ( ) ;
}
}
else // No course selected
{
sprintf ( Gbl . Message , Txt_THE_USER_X_already_exists_in_Y ,
Gbl . Usrs . Other . UsrDat . FullName , Cfg_PLATFORM_SHORT_NAME ) ;
Lay_ShowAlert ( Lay_INFO , Gbl . Message ) ;
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,
use user ' s ID to identify the user to be enrolled * * * * */
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 )
{
/* Initialize some data of this new user */
2015-04-07 21:44:24 +02:00
Gbl . Usrs . Other . UsrDat . RoleInCurrentCrsDB = Rol_STUDENT ;
2014-12-12 18:52:06 +01:00
Gbl . Usrs . Other . UsrDat . Roles = ( 1 < < Gbl . Usrs . Other . UsrDat . RoleInCurrentCrsDB ) ;
/***** Show form to enter the data of a new user *****/
sprintf ( Gbl . Message , Txt_The_user_is_new_does_not_exists_yet_in_X ,
Cfg_PLATFORM_SHORT_NAME ) ;
Lay_ShowAlert ( Lay_INFO , Gbl . Message ) ;
Rec_ShowFormOtherNewCommonRecord ( & Gbl . Usrs . Other . UsrDat ) ;
}
else // User's ID is not valid
{
/* Write message and request a new user's ID */
sprintf ( Gbl . Message , Txt_If_this_is_a_new_user_in_X_you_should_indicate_her_his_ID ,
Cfg_PLATFORM_SHORT_NAME ) ;
Lay_ShowAlert ( Lay_WARNING , Gbl . Message ) ;
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 )
{
/***** Buttons for edition *****/
2015-04-02 14:22:21 +02:00
fprintf ( Gbl . F . Out , " <div class= \" CONTEXT_MENU \" > " ) ;
2014-12-12 18:52:06 +01:00
if ( Pwd_CheckIfICanChangeOtherUsrPassword ( Gbl . Usrs . Other . UsrDat . UsrCod ) )
{
2015-04-03 00:15:51 +02:00
ID_PutLinkToChangeUsrIDs ( ) ; // Put link (form) to change user's IDs
2015-04-02 18:39:49 +02:00
Pwd_PutLinkToChangeOtherUsrPassword ( ) ; // Put link (form) to change user's password
2014-12-12 18:52:06 +01:00
}
2015-09-16 15:26:18 +02:00
Pho_PutLinkToChangeOtherUsrPhoto ( ) ; // Put link (form) to change user's photo
2015-03-29 21:43:33 +02:00
fprintf ( Gbl . F . Out , " </div> " ) ;
2014-12-12 18:52:06 +01:00
/***** User's record *****/
2015-03-05 21:42:02 +01:00
Rec_ShowSharedUsrRecord ( Rec_FORM_MODIFY_RECORD_OTHER_EXISTING_USR , & Gbl . Usrs . Other . UsrDat ) ;
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
{
extern const char * Txt_User_not_found_or_you_do_not_have_permission_ ;
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 */
2015-04-07 21:44:24 +02:00
ICanRegister = ( ( Scope = = Sco_SCOPE_DEG & & Gbl . Usrs . Me . LoggedRole > = Rol_CTR_ADM ) | |
( Scope = = Sco_SCOPE_CTR & & Gbl . Usrs . Me . LoggedRole > = Rol_INS_ADM ) | |
( Scope = = Sco_SCOPE_INS & & Gbl . Usrs . Me . LoggedRole = = 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 *****/
Rec_ShowCommonRecordUnmodifiable ( & Gbl . Usrs . Other . UsrDat ) ;
}
else
Lay_ShowAlert ( Lay_WARNING , Txt_User_not_found_or_you_do_not_have_permission_ ) ;
}
else
Lay_ShowAlert ( Lay_WARNING , Txt_User_not_found_or_you_do_not_have_permission_ ) ;
}
}
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
{
2015-02-01 17:43:34 +01:00
extern const char * Sco_ScopeAdminDB [ Sco_NUM_SCOPES ] ;
extern const char * Txt_THE_USER_X_is_already_an_administrator_of_Y ;
extern const char * Txt_THE_USER_X_has_been_enrolled_as_administrator_of_Y ;
2015-02-01 14:47:40 +01:00
char Query [ 512 ] ;
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 ) )
sprintf ( Gbl . Message , Txt_THE_USER_X_is_already_an_administrator_of_Y ,
UsrDat - > FullName , InsCtrDegName ) ;
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 *****/
2015-02-01 14:47:40 +01:00
sprintf ( Query , " REPLACE INTO admin (UsrCod,Scope,Cod) "
2015-02-01 17:43:34 +01:00
" VALUES ('%ld','%s','%ld') " ,
UsrDat - > UsrCod , Sco_ScopeAdminDB [ Scope ] , Cod ) ;
DB_QueryREPLACE ( Query , " can not create administrator " ) ;
2015-02-01 14:47:40 +01:00
2015-02-01 17:43:34 +01:00
sprintf ( Gbl . Message , Txt_THE_USER_X_has_been_enrolled_as_administrator_of_Y ,
UsrDat - > FullName , InsCtrDegName ) ;
2014-12-12 20:25:00 +01:00
}
Lay_ShowAlert ( Lay_SUCCESS , Gbl . Message ) ;
}
2014-12-12 18:52:06 +01:00
/*****************************************************************************/
/****************** Ask for remove me from current course ********************/
/*****************************************************************************/
void Enr_ReqRemMeFromCrs ( void )
{
Enr_AskIfRemoveUsrFromCrs ( & Gbl . Usrs . Me . UsrDat , true ) ;
}
/*****************************************************************************/
/************** Ask for remove of a user from current course *****************/
/*****************************************************************************/
void Enr_ReqRemUsrFromCrs ( void )
{
Enr_ReqRemOrRemUsrFromCrs ( Enr_REQUEST_REMOVE_USR ) ;
}
/*****************************************************************************/
/********************* Remove a user from current course *********************/
/*****************************************************************************/
void Enr_RemUsrFromCrs ( void )
{
if ( Pwd_GetConfirmationOnDangerousAction ( ) )
Enr_ReqRemOrRemUsrFromCrs ( Enr_REMOVE_USR ) ;
}
/*****************************************************************************/
/******************** Remove of a user from current course *******************/
/*****************************************************************************/
2014-12-12 22:39:55 +01:00
static void Enr_ReqRemOrRemUsrFromCrs ( Enr_ReqDelOrDelUsr_t ReqDelOrDelUsr )
2014-12-12 18:52:06 +01:00
{
extern const char * Txt_User_not_found_or_you_do_not_have_permission_ ;
bool ItsMe ;
bool ICanRemove ;
/***** Get user to be removed *****/
if ( Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ( ) )
{
/* Check if it's forbidden remove that user */
// A teacher can remove a student or himself
// An administrator can remove anyone
ItsMe = ( Gbl . Usrs . Me . UsrDat . UsrCod = = Gbl . Usrs . Other . UsrDat . UsrCod ) ;
2015-04-07 21:44:24 +02:00
ICanRemove = ( Gbl . Usrs . Me . LoggedRole = = Rol_STUDENT ? ItsMe :
2014-12-12 18:52:06 +01:00
( Gbl . Usrs . Me . LoggedRole > = Gbl . Usrs . Other . UsrDat . RoleInCurrentCrsDB ) ) ;
if ( ICanRemove )
switch ( ReqDelOrDelUsr )
{
case Enr_REQUEST_REMOVE_USR : // Ask if remove user from current course
Enr_AskIfRemoveUsrFromCrs ( & Gbl . Usrs . Other . UsrDat , ItsMe ) ;
break ;
case Enr_REMOVE_USR : // Remove user from current course
Enr_EffectivelyRemUsrFromCrs ( & Gbl . Usrs . Other . UsrDat , & Gbl . CurrentCrs . Crs ,
Enr_REMOVE_WORKS , Cns_VERBOSE ) ;
break ;
}
else
Lay_ShowAlert ( Lay_WARNING , Txt_User_not_found_or_you_do_not_have_permission_ ) ;
}
else
Lay_ShowAlert ( Lay_WARNING , Txt_User_not_found_or_you_do_not_have_permission_ ) ;
}
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
extern const char * Txt_User_not_found_or_you_do_not_have_permission_ ;
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 */
2015-01-31 01:23:39 +01:00
ItsMe = ( Gbl . Usrs . Me . UsrDat . UsrCod = = Gbl . Usrs . Other . UsrDat . UsrCod ) ;
2015-02-01 20:17:24 +01:00
ICanRemove = ( ItsMe | |
2015-04-07 21:44:24 +02:00
( Scope = = Sco_SCOPE_DEG & & Gbl . Usrs . Me . LoggedRole > = Rol_CTR_ADM ) | |
( Scope = = Sco_SCOPE_CTR & & Gbl . Usrs . Me . LoggedRole > = Rol_INS_ADM ) | |
( Scope = = Sco_SCOPE_INS & & Gbl . Usrs . Me . LoggedRole = = 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
{
2015-02-01 17:06:49 +01:00
sprintf ( Gbl . Message , Txt_THE_USER_X_is_not_an_administrator_of_Y ,
Gbl . Usrs . Other . UsrDat . FullName , InsCtrDegName ) ;
2014-12-12 22:39:55 +01:00
Lay_ShowAlert ( Lay_WARNING , Gbl . Message ) ;
}
}
else
Lay_ShowAlert ( Lay_WARNING , Txt_User_not_found_or_you_do_not_have_permission_ ) ;
}
else
Lay_ShowAlert ( Lay_WARNING , Txt_User_not_found_or_you_do_not_have_permission_ ) ;
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 ;
extern const char * Txt_User_not_found_or_you_do_not_have_permission_ ;
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 */
2015-04-07 21:44:24 +02:00
ICanRegister = ( ( Scope = = Sco_SCOPE_DEG & & Gbl . Usrs . Me . LoggedRole > = Rol_CTR_ADM ) | |
( Scope = = Sco_SCOPE_CTR & & Gbl . Usrs . Me . LoggedRole > = Rol_INS_ADM ) | |
( Scope = = Sco_SCOPE_INS & & Gbl . Usrs . Me . LoggedRole = = Rol_SYS_ADM ) ) ;
2015-02-01 20:17:24 +01:00
if ( ICanRegister )
2014-12-12 18:52:06 +01:00
{
2015-02-01 17:43:34 +01:00
if ( Usr_CheckIfUsrIsAdm ( Gbl . Usrs . Other . UsrDat . UsrCod , Scope , Cod ) ) // User is yet an administrator of current institution/centre/degree
2014-12-12 18:52:06 +01:00
{
2015-02-01 17:43:34 +01:00
sprintf ( Gbl . Message , Txt_THE_USER_X_is_already_an_administrator_of_Y ,
Gbl . Usrs . Other . UsrDat . FullName , InsCtrDegName ) ;
2014-12-12 18:52:06 +01:00
Lay_ShowAlert ( Lay_INFO , Gbl . Message ) ;
Rec_ShowCommonRecordUnmodifiable ( & Gbl . Usrs . Other . UsrDat ) ;
}
else
{
2015-02-01 17:43:34 +01:00
sprintf ( Gbl . Message , Txt_Do_you_really_want_to_register_the_following_user_as_an_administrator_of_X ,
InsCtrDegName ) ;
2014-12-12 18:52:06 +01:00
Lay_ShowAlert ( Lay_INFO , Gbl . Message ) ;
Rec_ShowCommonRecordUnmodifiable ( & Gbl . Usrs . Other . UsrDat ) ;
2015-02-01 17:43:34 +01:00
Act_FormStart ( Enr_ActNewAdm [ Scope ] ) ;
2015-04-02 18:39:49 +02:00
Usr_PutParamOtherUsrCodEncrypted ( ) ;
2015-03-24 17:47:26 +01:00
Lay_PutConfirmButton ( Txt_Register_user_IN_A_COURSE_OR_DEGREE ) ;
2015-03-13 00:16:02 +01:00
Act_FormEnd ( ) ;
2014-12-12 18:52:06 +01:00
}
}
else
Lay_ShowAlert ( Lay_WARNING , Txt_User_not_found_or_you_do_not_have_permission_ ) ;
}
else
Lay_ShowAlert ( Lay_WARNING , Txt_User_not_found_or_you_do_not_have_permission_ ) ;
}
}
/*****************************************************************************/
/*************** Accept my enrollment in the current course ******************/
/*****************************************************************************/
void Enr_AcceptRegisterMeInCrs ( void )
{
extern const char * Txt_You_have_confirmed_your_enrollment_in_the_course_X ;
/***** Confirm my enrollment *****/
Enr_AcceptUsrInCrs ( Gbl . Usrs . Me . UsrDat . UsrCod ) ;
2015-09-17 20:41:31 +02:00
/***** Mark all notifications about enrollment (as student or as teacher)
in current course as removed * * * * */
Ntf_SetNotifToOneUsrAsRemoved ( Ntf_EVENT_ENROLLMENT_STUDENT , - 1L ,
Gbl . Usrs . Me . UsrDat . UsrCod ) ;
Ntf_SetNotifToOneUsrAsRemoved ( Ntf_EVENT_ENROLLMENT_TEACHER , - 1L ,
Gbl . Usrs . Me . UsrDat . UsrCod ) ;
2014-12-12 18:52:06 +01:00
/***** Confirmation message *****/
sprintf ( Gbl . Message , Txt_You_have_confirmed_your_enrollment_in_the_course_X ,
Gbl . CurrentCrs . Crs . FullName ) ;
Lay_ShowAlert ( Lay_SUCCESS , Gbl . Message ) ;
}
/*****************************************************************************/
/******************* Create and show data from other user ********************/
/*****************************************************************************/
2015-09-12 14:12:40 +02:00
void Enr_CreateNewUsr ( void )
2014-12-12 18:52:06 +01:00
{
extern const char * Txt_The_ID_X_is_not_valid ;
Rol_Role_t NewRole ;
/***** Get user's ID from form *****/
ID_GetParamOtherUsrIDPlain ( ) ; // User's ID was already modified and passed as a hidden parameter
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 ( ) ;
2015-04-07 21:44:24 +02:00
if ( Gbl . Usrs . Me . LoggedRole = = Rol_TEACHER & &
NewRole ! = Rol_STUDENT )
2014-12-12 18:52:06 +01:00
Lay_ShowErrorAndExit ( " A teacher only can create new users as students. " ) ;
/***** 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
2014-12-12 22:39:55 +01:00
Acc_CreateNewUsr ( & Gbl . Usrs . Other . UsrDat ) ;
2014-12-12 18:52:06 +01:00
/***** Register user in current course in database *****/
if ( Gbl . CurrentCrs . Crs . CrsCod > 0 ) // Course selected
{
2015-09-17 11:21:49 +02:00
if ( Usr_CheckIfUsrBelongsToCrs ( Gbl . Usrs . Other . UsrDat . UsrCod ,
Gbl . CurrentCrs . Crs . CrsCod ,
false ) ) // User does belong to current course, modify his/her role
2014-12-12 20:25:00 +01:00
Enr_ModifyRoleInCurrentCrs ( & Gbl . Usrs . Other . UsrDat , NewRole , Cns_VERBOSE ) ;
2014-12-12 18:52:06 +01:00
else
2014-12-12 20:25:00 +01:00
Enr_RegisterUsrInCurrentCrs ( & Gbl . Usrs . Other . UsrDat , NewRole , Cns_VERBOSE ,
Enr_SET_ACCEPTED_TO_FALSE ) ;
2014-12-12 18:52:06 +01:00
/***** Change user's groups *****/
if ( Gbl . CurrentCrs . Grps . NumGrps ) // This course has groups?
Grp_ChangeOtherUsrGrps ( ) ;
}
/***** Show user's record *****/
Rec_ShowCommonRecordUnmodifiable ( & Gbl . Usrs . Other . UsrDat ) ;
}
else // User's ID not valid
{
/***** Write message *****/
sprintf ( Gbl . Message , Txt_The_ID_X_is_not_valid ,
Gbl . Usrs . Other . UsrDat . IDs . List [ 0 ] . ID ) ;
Lay_ShowAlert ( Lay_ERROR , Gbl . Message ) ;
}
}
/*****************************************************************************/
/**** Modify other user's data and register her/him in course and groups *****/
/*****************************************************************************/
2015-09-12 14:12:40 +02:00
void Enr_ModifyUsr ( void )
2014-12-12 18:52:06 +01:00
{
extern const char * Txt_User_not_found_or_you_do_not_have_permission_ ;
char UnsignedStr [ 10 + 1 ] ;
unsigned UnsignedNum ;
bool ItsMe ;
Enr_RegRemOneUsrAction_t RegRemAction ;
Rol_Role_t NewRole ;
bool Error = false ;
/***** Get user from form *****/
if ( Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ( ) )
{
ItsMe = ( Gbl . Usrs . Other . UsrDat . UsrCod = = Gbl . Usrs . Me . UsrDat . UsrCod ) ;
/***** Get the action to do *****/
Par_GetParToText ( " RegRemAction " , UnsignedStr , 1 ) ;
if ( sscanf ( UnsignedStr , " %u " , & UnsignedNum ) = = 1 )
if ( UnsignedNum < Enr_NUM_ACTIONS_REG_REM_ONE_USR )
switch ( ( RegRemAction = ( Enr_RegRemOneUsrAction_t ) UnsignedNum ) )
{
case Enr_REGISTER_MODIFY_ONE_USR_IN_CRS :
2015-04-07 21:44:24 +02:00
if ( ItsMe | | Gbl . Usrs . Me . LoggedRole > = Rol_TEACHER )
2014-12-12 18:52:06 +01:00
{
/***** Get user's name from record form *****/
2015-09-12 14:12:40 +02:00
if ( Gbl . Usrs . Me . LoggedRole > = Rol_DEG_ADM ) // Only an admin can change another user's name
2014-12-12 18:52:06 +01:00
Rec_GetUsrNameFromRecordForm ( & Gbl . Usrs . Other . UsrDat ) ;
/***** Update user's data in database *****/
Enr_UpdateUsrData ( & Gbl . Usrs . Other . UsrDat ) ;
if ( Gbl . CurrentCrs . Crs . CrsCod > 0 )
{
/***** Get new role from record form *****/
NewRole = Rec_GetRoleFromRecordForm ( ) ;
/***** Register user in current course in database *****/
2015-09-17 11:21:49 +02:00
if ( Usr_CheckIfUsrBelongsToCrs ( Gbl . Usrs . Other . UsrDat . UsrCod ,
Gbl . CurrentCrs . Crs . CrsCod ,
false ) ) // User does belong to current course, modify his/her role
2014-12-12 20:25:00 +01:00
Enr_ModifyRoleInCurrentCrs ( & Gbl . Usrs . Other . UsrDat , NewRole , Cns_VERBOSE ) ;
2014-12-12 18:52:06 +01:00
else
2014-12-12 20:25:00 +01:00
Enr_RegisterUsrInCurrentCrs ( & Gbl . Usrs . Other . UsrDat , NewRole , Cns_VERBOSE ,
Enr_SET_ACCEPTED_TO_FALSE ) ;
2014-12-12 18:52:06 +01:00
/***** Change user's groups *****/
if ( Gbl . CurrentCrs . Grps . NumGrps ) // This course has groups?
{
if ( ItsMe )
Grp_ChangeMyGrps ( ) ;
else
Grp_ChangeOtherUsrGrps ( ) ;
}
}
/***** Show user's record *****/
Rec_ShowCommonRecordUnmodifiable ( & Gbl . Usrs . Other . UsrDat ) ;
}
else
Error = true ;
break ;
case Enr_REGISTER_ONE_DEGREE_ADMIN :
2015-04-07 21:44:24 +02:00
if ( Gbl . Usrs . Me . LoggedRole > = Rol_CTR_ADM )
2015-02-01 20:17:24 +01:00
Enr_ReqAddAdm ( Sco_SCOPE_DEG , Gbl . CurrentDeg . Deg . DegCod ,
2015-02-01 17:43:34 +01:00
Gbl . CurrentDeg . Deg . FullName ) ;
2014-12-12 18:52:06 +01:00
else
Error = true ;
break ;
2015-01-31 01:23:39 +01:00
case Enr_REGISTER_ONE_CENTRE_ADMIN :
2015-04-07 21:44:24 +02:00
if ( Gbl . Usrs . Me . LoggedRole > = Rol_INS_ADM )
2015-02-01 20:17:24 +01:00
Enr_ReqAddAdm ( Sco_SCOPE_CTR , Gbl . CurrentCtr . Ctr . CtrCod ,
2015-02-01 17:43:34 +01:00
Gbl . CurrentCtr . Ctr . FullName ) ;
2015-01-31 01:23:39 +01:00
else
Error = true ;
break ;
case Enr_REGISTER_ONE_INSTITUTION_ADMIN :
2015-04-07 21:44:24 +02:00
if ( Gbl . Usrs . Me . LoggedRole = = Rol_SYS_ADM )
2015-02-01 20:17:24 +01:00
Enr_ReqAddAdm ( Sco_SCOPE_INS , Gbl . CurrentIns . Ins . InsCod ,
2015-02-01 17:43:34 +01:00
Gbl . CurrentIns . Ins . FullName ) ;
2015-01-31 01:23:39 +01:00
else
Error = true ;
break ;
2014-12-12 18:52:06 +01:00
case Enr_REMOVE_ONE_USR_FROM_CRS :
2015-04-07 21:44:24 +02:00
if ( ItsMe | | Gbl . Usrs . Me . LoggedRole > = Rol_TEACHER )
2014-12-12 18:52:06 +01:00
Enr_ReqRemUsrFromCrs ( ) ;
else
Error = true ;
break ;
case Enr_REMOVE_ONE_DEGREE_ADMIN :
2015-04-07 21:44:24 +02:00
if ( ItsMe | | Gbl . Usrs . Me . LoggedRole > = Rol_CTR_ADM )
2014-12-12 18:52:06 +01:00
Enr_ReqRemAdmOfDeg ( ) ;
else
Error = true ;
break ;
2015-01-31 01:23:39 +01:00
case Enr_REMOVE_ONE_CENTRE_ADMIN :
2015-04-07 21:44:24 +02:00
if ( ItsMe | | Gbl . Usrs . Me . LoggedRole > = Rol_INS_ADM )
2015-01-31 01:23:39 +01:00
Enr_ReqRemAdmOfCtr ( ) ;
else
Error = true ;
break ;
case Enr_REMOVE_ONE_INSTITUTION_ADMIN :
2015-04-07 21:44:24 +02:00
if ( ItsMe | | Gbl . Usrs . Me . LoggedRole = = Rol_SYS_ADM )
2015-01-31 01:23:39 +01:00
Enr_ReqRemAdmOfIns ( ) ;
else
Error = true ;
break ;
2014-12-12 18:52:06 +01:00
case Enr_ELIMINATE_ONE_USR_FROM_PLATFORM :
2014-12-12 22:39:55 +01:00
if ( Acc_CheckIfICanEliminateAccount ( ItsMe ) )
Acc_ReqRemUsrGbl ( ) ;
2014-12-12 18:52:06 +01:00
else
Error = true ;
break ;
default :
Error = true ;
break ;
}
else
Error = true ;
else
Error = true ;
}
else
Error = true ;
if ( Error )
Lay_ShowAlert ( Lay_WARNING , Txt_User_not_found_or_you_do_not_have_permission_ ) ;
}
/*****************************************************************************/
/********* Set a user's acceptation to true in the current course ************/
/*****************************************************************************/
void Enr_AcceptUsrInCrs ( long UsrCod )
{
char Query [ 512 ] ;
/***** Set enrollment of a user to "accepted" in the current course *****/
sprintf ( Query , " UPDATE crs_usr SET Accepted='Y' "
" WHERE CrsCod='%ld' AND UsrCod='%ld' " ,
Gbl . CurrentCrs . Crs . CrsCod , UsrCod ) ;
DB_QueryUPDATE ( Query , " can not confirm user's enrollment " ) ;
}
2014-12-12 22:39:55 +01:00
/*****************************************************************************/
/******************* Ask if really wanted to remove a user *******************/
/*****************************************************************************/
static void Enr_AskIfRemoveUsrFromCrs ( struct UsrData * UsrDat , bool ItsMe )
{
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 ;
extern const char * Txt_User_not_found_or_you_do_not_have_permission_ ;
2015-09-17 11:21:49 +02:00
if ( Usr_CheckIfUsrBelongsToCrs ( UsrDat - > UsrCod ,
Gbl . CurrentCrs . Crs . CrsCod ,
false ) )
2014-12-12 22:39:55 +01:00
{
sprintf ( Gbl . Message ,
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 ) ;
Lay_ShowAlert ( Lay_WARNING , Gbl . Message ) ;
Rec_ShowCommonRecordUnmodifiable ( UsrDat ) ;
2015-08-01 08:40:58 +02:00
fprintf ( Gbl . F . Out , " <div class= \" CENTER_MIDDLE \" > " ) ;
2015-09-17 20:58:10 +02:00
Act_FormStart ( UsrDat - > RoleInCurrentCrsDB = = Rol_STUDENT ? ActRemStdCrs :
ActRemTchCrs ) ;
2015-04-02 18:39:49 +02:00
Usr_PutParamUsrCodEncrypted ( UsrDat - > EncryptedUsrCod ) ;
2014-12-12 22:39:55 +01:00
Pwd_AskForConfirmationOnDangerousAction ( ) ;
2015-03-24 17:47:26 +01:00
Lay_PutRemoveButton ( ItsMe ? Txt_Remove_me_from_this_course :
Txt_Remove_user_from_this_course ) ;
2015-03-13 00:16:02 +01:00
Act_FormEnd ( ) ;
fprintf ( Gbl . F . Out , " </div> " ) ;
2014-12-12 22:39:55 +01:00
}
else
Lay_ShowAlert ( Lay_WARNING , Txt_User_not_found_or_you_do_not_have_permission_ ) ;
}
/*****************************************************************************/
/************************ 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_ ;
char Query [ 1024 ] ;
2015-09-17 11:21:49 +02:00
if ( Usr_CheckIfUsrBelongsToCrs ( UsrDat - > UsrCod ,
Crs - > CrsCod ,
false ) ) // User belongs to the course
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 *****/
Grp_RemUsrFromAllGrpsInCrs ( UsrDat , Crs , QuietOrVerbose ) ;
/***** 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 )
Brw_RemoveUsrWorksInCrs ( UsrDat , Crs , QuietOrVerbose ) ;
/***** Remove fields of this user in its course record *****/
Rec_RemoveFieldsCrsRecordInCrs ( UsrDat - > UsrCod , Crs , QuietOrVerbose ) ;
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
/***** Remove exams made by user in course *****/
Tst_RemoveExamsMadeByUsrInCrs ( UsrDat - > UsrCod , Crs - > CrsCod ) ;
/***** Set all the notifications for this user in this course as removed,
except notifications about new messages * * * * */
Ntf_SetNotifInCrsAsRemoved ( Crs - > CrsCod , UsrDat - > UsrCod ) ;
/***** Remove user from the table of courses-users *****/
sprintf ( Query , " DELETE FROM crs_usr "
" WHERE CrsCod='%ld' AND UsrCod='%ld' " ,
Crs - > CrsCod , UsrDat - > UsrCod ) ;
DB_QueryDELETE ( Query , " can not remove a user from a course " ) ;
if ( QuietOrVerbose = = Cns_VERBOSE )
{
sprintf ( Gbl . Message , Txt_THE_USER_X_has_been_removed_from_the_course_Y ,
UsrDat - > FullName , Crs - > FullName ) ;
Lay_ShowAlert ( Lay_SUCCESS , Gbl . Message ) ;
}
}
else // User does not belong to course
if ( QuietOrVerbose = = Cns_VERBOSE )
Lay_ShowAlert ( Lay_WARNING , Txt_User_not_found_or_you_do_not_have_permission_ ) ;
}
2015-01-31 01:23:39 +01:00
/*****************************************************************************/
/** Ask if really wanted to remove an administrator from current institution */
/*****************************************************************************/
2015-02-01 17:06:49 +01: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 ;
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 ) )
{
sprintf ( Gbl . Message ,
2015-02-01 17:06:49 +01:00
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
Lay_ShowAlert ( Lay_INFO , Gbl . Message ) ;
Rec_ShowCommonRecordUnmodifiable ( & Gbl . Usrs . Other . UsrDat ) ;
2015-02-01 17:06:49 +01:00
Act_FormStart ( Enr_ActRemAdm [ Scope ] ) ;
2015-04-02 18:39:49 +02:00
Usr_PutParamOtherUsrCodEncrypted ( ) ;
2015-03-24 17:47:26 +01:00
Lay_PutRemoveButton ( ItsMe ? Txt_Remove_me_as_an_administrator :
Txt_Remove_user_as_an_administrator ) ;
2015-03-13 00:16:02 +01:00
Act_FormEnd ( ) ;
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
{
2015-02-01 17:06:49 +01:00
extern const char * Sco_ScopeAdminDB [ Sco_NUM_SCOPES ] ;
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
char Query [ 1024 ] ;
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 *****/
sprintf ( Query , " DELETE FROM admin "
2015-02-01 17:06:49 +01:00
" WHERE UsrCod='%ld' AND Scope='%s' AND Cod='%ld' " ,
UsrDat - > UsrCod , Sco_ScopeAdminDB [ Scope ] , Cod ) ;
DB_QueryDELETE ( Query , " can not remove an administrator " ) ;
2015-01-31 01:23:39 +01:00
2015-02-01 17:06:49 +01:00
sprintf ( Gbl . Message , Txt_THE_USER_X_has_been_removed_as_administrator_of_Y ,
UsrDat - > FullName , InsCtrDegName ) ;
2015-01-31 01:23:39 +01:00
Lay_ShowAlert ( Lay_SUCCESS , Gbl . Message ) ;
}
2015-02-01 17:06:49 +01:00
else // User is not an administrator of the current institution/centre/degree
2015-01-31 01:23:39 +01:00
{
2015-02-01 17:06:49 +01:00
sprintf ( Gbl . Message , Txt_THE_USER_X_is_not_an_administrator_of_Y ,
UsrDat - > FullName , InsCtrDegName ) ;
2014-12-12 22:39:55 +01:00
Lay_ShowAlert ( Lay_ERROR , Gbl . Message ) ;
}
}