"
""
"%u"
" | ",
NumRequests - NumReq);
/***** Link to course *****/
Crs_GetDataOfCourseByCod (&Crs);
Deg.DegCod = Crs.DegCod;
Deg_GetDataOfDegreeByCod (&Deg);
fprintf (Gbl.F.Out,"");
Act_FormGoToStart (ActSeeCrsInf);
Crs_PutParamCrsCod (Crs.CrsCod);
sprintf (Gbl.Title,Txt_Go_to_X,Crs.FullName);
Act_LinkFormSubmit (Gbl.Title,"DAT");
fprintf (Gbl.F.Out,"%s > %s"
"",
Deg.ShortName,Crs.ShortName);
Act_FormEnd ();
fprintf (Gbl.F.Out," | ");
/***** Number of teachers in the course *****/
fprintf (Gbl.F.Out,""
"%u"
" | ",
Crs.NumTchs);
/***** User photo *****/
fprintf (Gbl.F.Out,"");
ShowPhoto = Pho_ShowUsrPhotoIsAllowed (&UsrDat,PhotoURL);
Pho_ShowUsrPhoto (&UsrDat,ShowPhoto ? PhotoURL :
NULL,
"PHOTO18x24",Pho_ZOOM);
fprintf (Gbl.F.Out," | ");
/***** User name *****/
fprintf (Gbl.F.Out,"");
Usr_RestrictLengthAndWriteName (&UsrDat,20);
/***** Requested role (row[3]) *****/
fprintf (Gbl.F.Out," | "
"%s"
" | ",
Txt_ROLES_SINGUL_abc[DesiredRole][UsrDat.Sex]);
/***** Request time (row[4]) *****/
Msg_WriteMsgDate (row[4],"DAT");
/***** Button to confirm the request *****/
fprintf (Gbl.F.Out,"");
Act_FormStart (DesiredRole == Rol_STUDENT ? ActReqMdfStd :
ActReqMdfTch);
Crs_PutParamCrsCod (Crs.CrsCod);
Usr_PutParamUsrCodEncrypted (UsrDat.EncryptedUsrCod);
Lay_PutCreateButton (Txt_Register);
Act_FormEnd ();
fprintf (Gbl.F.Out," | ");
/***** Button to reject the request *****/
fprintf (Gbl.F.Out,"");
Act_FormStart (ActReqRejSignUp);
Crs_PutParamCrsCod (Crs.CrsCod);
Usr_PutParamUsrCodEncrypted (UsrDat.EncryptedUsrCod);
Lay_PutConfirmButton (Txt_Reject);
Act_FormEnd ();
fprintf (Gbl.F.Out," | "
"
");
/***** 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);
}
/* End frame */
Lay_EndRoundFrameTable ();
/* 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");
}
/*****************************************************************************/
/********************** Write a form to admin one user ***********************/
/*****************************************************************************/
void Enr_PutLinkToAdminOneUsr (Act_Action_t NextAction)
{
extern const char *Txt_Admin_me;
extern const char *Txt_Admin_one_user;
Act_PutContextualLink (NextAction,NULL,"configtest",
Enr_CheckIfICanAdminOtherUsrs () ? Txt_Admin_one_user :
Txt_Admin_me);
}
/*****************************************************************************/
/******************* Write a form to admin several users *********************/
/*****************************************************************************/
void Enr_PutLinkToAdminSeveralUsrs (Rol_Role_t Role)
{
extern const char *Txt_Admin_several_students;
extern const char *Txt_Admin_several_teachers;
Act_PutContextualLink (Role == Rol_STUDENT ? ActReqEnrSevStd :
ActReqEnrSevTch,
NULL,"configtest",
Role == Rol_STUDENT ? Txt_Admin_several_students :
Txt_Admin_several_teachers);
}
/*****************************************************************************/
/************** Form to request the user's ID of another user ****************/
/*****************************************************************************/
void Enr_ReqRegRemOth (void)
{
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)
{
if (Enr_CheckIfICanAdminOtherUsrs ())
Enr_ReqAnotherUsrIDToRegisterRemove (Role);
else
Enr_AskIfRegRemMe (Role);
}
/*****************************************************************************/
/*********** Check If I can admin other users (distinct to me) ***************/
/*****************************************************************************/
static bool Enr_CheckIfICanAdminOtherUsrs (void)
{
switch (Gbl.Usrs.Me.LoggedRole)
{
case Rol_UNKNOWN:
case Rol__GUEST_:
case Rol_VISITOR:
case Rol_STUDENT:
return false;
case Rol_TEACHER:
return (Gbl.CurrentCrs.Crs.CrsCod > 0);
case Rol_DEG_ADM:
return (Gbl.CurrentDeg.Deg.DegCod > 0);
case Rol_CTR_ADM:
return (Gbl.CurrentCtr.Ctr.CtrCod > 0);
case Rol_INS_ADM:
return (Gbl.CurrentIns.Ins.InsCod > 0);
case Rol_SYS_ADM:
return true;
}
return false;
}
/*****************************************************************************/
/****** Write a form to request another user's ID, @nickname or e-mail *******/
/*****************************************************************************/
static void Enr_ReqAnotherUsrIDToRegisterRemove (Rol_Role_t Role)
{
extern const char *Txt_Admin_one_user;
/***** Start frame *****/
Lay_StartRoundFrame (NULL,Txt_Admin_one_user);
/***** Write form to request another user's ID *****/
Enr_WriteFormToReqAnotherUsrID ( Role == Rol_STUDENT ? ActReqMdfStd :
(Role == Rol_TEACHER ? ActReqMdfTch :
ActReqMdfOth));
/***** End frame *****/
Lay_EndRoundFrame ();
}
/*****************************************************************************/
/********************** Ask me for register/remove me ************************/
/*****************************************************************************/
static void Enr_AskIfRegRemMe (Rol_Role_t Role)
{
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;
Enr_AskIfRegRemUsr (&ListUsrCods,Role);
}
/*****************************************************************************/
/****************** Ask me for register/remove another user ******************/
/*****************************************************************************/
void Enr_AskIfRegRemAnotherOth (void)
{
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)
{
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);
Enr_AskIfRegRemUsr (&ListUsrCods,Role);
}
/*****************************************************************************/
/********************** Ask me for register/remove user **********************/
/*****************************************************************************/
static void Enr_AskIfRegRemUsr (struct ListUsrCods *ListUsrCods,Rol_Role_t Role)
{
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 */
if (Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod,
Gbl.CurrentCrs.Crs.CrsCod,
false))
{
Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod,
Gbl.CurrentCrs.Crs.CrsCod,
true);
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 */
Gbl.Usrs.Other.UsrDat.RoleInCurrentCrsDB = Rol_STUDENT;
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);
Enr_ReqRegRemUsr (Role);
}
}
}
/*****************************************************************************/
/************ Show form to edit the record of an existing user ***************/
/*****************************************************************************/
static void Enr_ShowFormToEditOtherUsr (void)
{
/***** Buttons for edition *****/
fprintf (Gbl.F.Out,"");
/***** User's record *****/
Rec_ShowSharedUsrRecord (Rec_FORM_MODIFY_RECORD_OTHER_EXISTING_USR,&Gbl.Usrs.Other.UsrDat);
}
/*****************************************************************************/
/*************** Add an administrator to current institution *****************/
/*****************************************************************************/
void Enr_AddAdmToIns (void)
{
Enr_AddAdm (Sco_SCOPE_INS,Gbl.CurrentIns.Ins.InsCod,Gbl.CurrentIns.Ins.FullName);
}
/*****************************************************************************/
/******************* Add an administrator to current centre ******************/
/*****************************************************************************/
void Enr_AddAdmToCtr (void)
{
Enr_AddAdm (Sco_SCOPE_CTR,Gbl.CurrentCtr.Ctr.CtrCod,Gbl.CurrentCtr.Ctr.FullName);
}
/*****************************************************************************/
/******************* Add an administrator to current degree ******************/
/*****************************************************************************/
void Enr_AddAdmToDeg (void)
{
Enr_AddAdm (Sco_SCOPE_DEG,Gbl.CurrentDeg.Deg.DegCod,Gbl.CurrentDeg.Deg.FullName);
}
/*****************************************************************************/
/******************* Add an administrator to current degree ******************/
/*****************************************************************************/
static void Enr_AddAdm (Sco_Scope_t Scope,long Cod,const char *InsCtrDegName)
{
extern const char *Txt_User_not_found_or_you_do_not_have_permission_;
bool ICanRegister;
if (Cod > 0)
{
/***** Get plain user's ID of the user to add/modify *****/
if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ())
{
/* Check if I am allowed to register user as administrator in institution/centre/degree */
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));
if (ICanRegister)
{
/***** Register administrator in current institution/centre/degree in database *****/
Enr_RegisterAdmin (&Gbl.Usrs.Other.UsrDat,Scope,
Cod,InsCtrDegName);
/***** 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_);
}
}
/*****************************************************************************/
/**************** Register administrator in current institution **************/
/*****************************************************************************/
static void Enr_RegisterAdmin (struct UsrData *UsrDat,Sco_Scope_t Scope,long Cod,const char *InsCtrDegName)
{
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;
char Query[512];
/***** 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
{
/***** Insert or replace administrator in current institution/centre/degree *****/
sprintf (Query,"REPLACE INTO admin (UsrCod,Scope,Cod)"
" VALUES ('%ld','%s','%ld')",
UsrDat->UsrCod,Sco_ScopeAdminDB[Scope],Cod);
DB_QueryREPLACE (Query,"can not create administrator");
sprintf (Gbl.Message,Txt_THE_USER_X_has_been_enrolled_as_administrator_of_Y,
UsrDat->FullName,InsCtrDegName);
}
Lay_ShowAlert (Lay_SUCCESS,Gbl.Message);
}
/*****************************************************************************/
/****************** 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 *******************/
/*****************************************************************************/
static void Enr_ReqRemOrRemUsrFromCrs (Enr_ReqDelOrDelUsr_t ReqDelOrDelUsr)
{
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);
ICanRemove = (Gbl.Usrs.Me.LoggedRole == Rol_STUDENT ? ItsMe :
(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_);
}
/*****************************************************************************/
/******* Ask for remove of an administrator from current institution *********/
/*****************************************************************************/
static void Enr_ReqRemAdmOfIns (void)
{
Enr_ReqRemOrRemAdm (Enr_REQUEST_REMOVE_USR,Sco_SCOPE_INS,
Gbl.CurrentIns.Ins.InsCod,Gbl.CurrentIns.Ins.FullName);
}
/*****************************************************************************/
/********* Ask for remove of an administrator from current centre ************/
/*****************************************************************************/
static void Enr_ReqRemAdmOfCtr (void)
{
Enr_ReqRemOrRemAdm (Enr_REQUEST_REMOVE_USR,Sco_SCOPE_CTR,
Gbl.CurrentCtr.Ctr.CtrCod,Gbl.CurrentCtr.Ctr.FullName);
}
/*****************************************************************************/
/********* Ask for remove of an administrator from current degree ************/
/*****************************************************************************/
static void Enr_ReqRemAdmOfDeg (void)
{
Enr_ReqRemOrRemAdm (Enr_REQUEST_REMOVE_USR,Sco_SCOPE_DEG,
Gbl.CurrentDeg.Deg.DegCod,Gbl.CurrentDeg.Deg.FullName);
}
/*****************************************************************************/
/************ Remove an administrator from current institution ***************/
/*****************************************************************************/
void Enr_RemAdmIns (void)
{
Enr_ReqRemOrRemAdm (Enr_REMOVE_USR,Sco_SCOPE_INS,
Gbl.CurrentIns.Ins.InsCod,Gbl.CurrentIns.Ins.FullName);
}
/*****************************************************************************/
/*************** Remove an administrator from current centre *****************/
/*****************************************************************************/
void Enr_RemAdmCtr (void)
{
Enr_ReqRemOrRemAdm (Enr_REMOVE_USR,Sco_SCOPE_CTR,
Gbl.CurrentCtr.Ctr.CtrCod,Gbl.CurrentCtr.Ctr.FullName);
}
/*****************************************************************************/
/*************** Remove an administrator from current degree *****************/
/*****************************************************************************/
void Enr_RemAdmDeg (void)
{
Enr_ReqRemOrRemAdm (Enr_REMOVE_USR,Sco_SCOPE_DEG,
Gbl.CurrentDeg.Deg.DegCod,Gbl.CurrentDeg.Deg.FullName);
}
/*****************************************************************************/
/***************** Remove an admin from current institution ******************/
/*****************************************************************************/
static void Enr_ReqRemOrRemAdm (Enr_ReqDelOrDelUsr_t ReqDelOrDelUsr,Sco_Scope_t Scope,
long Cod,const char *InsCtrDegName)
{
extern const char *Txt_THE_USER_X_is_not_an_administrator_of_Y;
extern const char *Txt_User_not_found_or_you_do_not_have_permission_;
bool ItsMe;
bool ICanRemove;
if (Cod > 0)
{
/***** Get user to be removed *****/
if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ())
{
/* Check if it's forbidden to remove an administrator */
ItsMe = (Gbl.Usrs.Me.UsrDat.UsrCod == Gbl.Usrs.Other.UsrDat.UsrCod);
ICanRemove = (ItsMe ||
(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));
if (ICanRemove)
{
/* Check if the other user is an admin of the current institution/centre/degree */
if (Usr_CheckIfUsrIsAdm (Gbl.Usrs.Other.UsrDat.UsrCod,Scope,Cod))
{ // The other user is an administrator of current institution/centre/degree ==> ask for removing or remove her/him
switch (ReqDelOrDelUsr)
{
case Enr_REQUEST_REMOVE_USR: // Ask if remove administrator from current institution
Enr_AskIfRemAdm (ItsMe,Scope,InsCtrDegName);
break;
case Enr_REMOVE_USR: // Remove administrator from current institution
Enr_EffectivelyRemAdm (&Gbl.Usrs.Other.UsrDat,Scope,
Cod,InsCtrDegName);
break;
}
}
else // The other user is not an administrator of current institution
{
sprintf (Gbl.Message,Txt_THE_USER_X_is_not_an_administrator_of_Y,
Gbl.Usrs.Other.UsrDat.FullName,InsCtrDegName);
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_);
}
}
/*****************************************************************************/
/**** Ask if really wanted to add an administrator to current institution ****/
/*****************************************************************************/
static void Enr_ReqAddAdm (Sco_Scope_t Scope,long Cod,const char *InsCtrDegName)
{
extern const char *Txt_THE_USER_X_is_already_an_administrator_of_Y;
extern const char *Txt_Do_you_really_want_to_register_the_following_user_as_an_administrator_of_X;
extern const char *Txt_Register_user_IN_A_COURSE_OR_DEGREE;
extern const char *Txt_User_not_found_or_you_do_not_have_permission_;
static const Act_Action_t Enr_ActNewAdm[Sco_NUM_SCOPES] =
{
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,
};
bool ICanRegister;
if (Cod > 0)
{
/***** Get user's identificator of the user to register as admin *****/
if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ())
{
/* Check if I am allowed to register user as administrator in institution/centre/degree */
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));
if (ICanRegister)
{
if (Usr_CheckIfUsrIsAdm (Gbl.Usrs.Other.UsrDat.UsrCod,Scope,Cod)) // User is yet an administrator of current institution/centre/degree
{
sprintf (Gbl.Message,Txt_THE_USER_X_is_already_an_administrator_of_Y,
Gbl.Usrs.Other.UsrDat.FullName,InsCtrDegName);
Lay_ShowAlert (Lay_INFO,Gbl.Message);
Rec_ShowCommonRecordUnmodifiable (&Gbl.Usrs.Other.UsrDat);
}
else
{
sprintf (Gbl.Message,Txt_Do_you_really_want_to_register_the_following_user_as_an_administrator_of_X,
InsCtrDegName);
Lay_ShowAlert (Lay_INFO,Gbl.Message);
Rec_ShowCommonRecordUnmodifiable (&Gbl.Usrs.Other.UsrDat);
Act_FormStart (Enr_ActNewAdm[Scope]);
Usr_PutParamOtherUsrCodEncrypted ();
Lay_PutConfirmButton (Txt_Register_user_IN_A_COURSE_OR_DEGREE);
Act_FormEnd ();
}
}
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);
/***** 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);
/***** 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 ********************/
/*****************************************************************************/
void Enr_CreateNewUsr (void)
{
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 ();
if (Gbl.Usrs.Me.LoggedRole == Rol_TEACHER &&
NewRole != Rol_STUDENT)
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
Acc_CreateNewUsr (&Gbl.Usrs.Other.UsrDat);
/***** Register user in current course in database *****/
if (Gbl.CurrentCrs.Crs.CrsCod > 0) // Course selected
{
if (Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod,
Gbl.CurrentCrs.Crs.CrsCod,
false)) // User does belong to current course, modify his/her role
Enr_ModifyRoleInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole,Cns_VERBOSE);
else
Enr_RegisterUsrInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole,Cns_VERBOSE,
Enr_SET_ACCEPTED_TO_FALSE);
/***** 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 *****/
/*****************************************************************************/
void Enr_ModifyUsr (void)
{
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:
if (ItsMe || Gbl.Usrs.Me.LoggedRole >= Rol_TEACHER)
{
/***** Get user's name from record form *****/
if (Gbl.Usrs.Me.LoggedRole >= Rol_DEG_ADM) // Only an admin can change another user's name
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 *****/
if (Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod,
Gbl.CurrentCrs.Crs.CrsCod,
false)) // User does belong to current course, modify his/her role
Enr_ModifyRoleInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole,Cns_VERBOSE);
else
Enr_RegisterUsrInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole,Cns_VERBOSE,
Enr_SET_ACCEPTED_TO_FALSE);
/***** 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:
if (Gbl.Usrs.Me.LoggedRole >= Rol_CTR_ADM)
Enr_ReqAddAdm (Sco_SCOPE_DEG,Gbl.CurrentDeg.Deg.DegCod,
Gbl.CurrentDeg.Deg.FullName);
else
Error = true;
break;
case Enr_REGISTER_ONE_CENTRE_ADMIN:
if (Gbl.Usrs.Me.LoggedRole >= Rol_INS_ADM)
Enr_ReqAddAdm (Sco_SCOPE_CTR,Gbl.CurrentCtr.Ctr.CtrCod,
Gbl.CurrentCtr.Ctr.FullName);
else
Error = true;
break;
case Enr_REGISTER_ONE_INSTITUTION_ADMIN:
if (Gbl.Usrs.Me.LoggedRole == Rol_SYS_ADM)
Enr_ReqAddAdm (Sco_SCOPE_INS,Gbl.CurrentIns.Ins.InsCod,
Gbl.CurrentIns.Ins.FullName);
else
Error = true;
break;
case Enr_REMOVE_ONE_USR_FROM_CRS:
if (ItsMe || Gbl.Usrs.Me.LoggedRole >= Rol_TEACHER)
Enr_ReqRemUsrFromCrs ();
else
Error = true;
break;
case Enr_REMOVE_ONE_DEGREE_ADMIN:
if (ItsMe || Gbl.Usrs.Me.LoggedRole >= Rol_CTR_ADM)
Enr_ReqRemAdmOfDeg ();
else
Error = true;
break;
case Enr_REMOVE_ONE_CENTRE_ADMIN:
if (ItsMe || Gbl.Usrs.Me.LoggedRole >= Rol_INS_ADM)
Enr_ReqRemAdmOfCtr ();
else
Error = true;
break;
case Enr_REMOVE_ONE_INSTITUTION_ADMIN:
if (ItsMe || Gbl.Usrs.Me.LoggedRole == Rol_SYS_ADM)
Enr_ReqRemAdmOfIns ();
else
Error = true;
break;
case Enr_ELIMINATE_ONE_USR_FROM_PLATFORM:
if (Acc_CheckIfICanEliminateAccount (ItsMe))
Acc_ReqRemUsrGbl ();
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");
}
/*****************************************************************************/
/******************* 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_;
if (Usr_CheckIfUsrBelongsToCrs (UsrDat->UsrCod,
Gbl.CurrentCrs.Crs.CrsCod,
false))
{
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);
fprintf (Gbl.F.Out,"");
Act_FormStart (UsrDat->RoleInCurrentCrsDB == Rol_STUDENT ? ActRemStdCrs :
ActRemTchCrs);
Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
Pwd_AskForConfirmationOnDangerousAction ();
Lay_PutRemoveButton (ItsMe ? Txt_Remove_me_from_this_course :
Txt_Remove_user_from_this_course);
Act_FormEnd ();
fprintf (Gbl.F.Out,"
");
}
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];
if (Usr_CheckIfUsrBelongsToCrs (UsrDat->UsrCod,
Crs->CrsCod,
false)) // User belongs to the course
{
/***** 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);
/***** Remove some information about files in course and groups *****/
Brw_RemoveSomeInfoAboutCrsUsrFilesFromDB (UsrDat->UsrCod,Crs->CrsCod);
/***** 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_);
}
/*****************************************************************************/
/** Ask if really wanted to remove an administrator from current institution */
/*****************************************************************************/
static void Enr_AskIfRemAdm (bool ItsMe,Sco_Scope_t Scope,const char *InsCtrDegName)
{
extern const char *Txt_Do_you_really_want_to_be_removed_as_an_administrator_of_X;
extern const char *Txt_Do_you_really_want_to_remove_the_following_user_as_an_administrator_of_X;
extern const char *Txt_Remove_me_as_an_administrator;
extern const char *Txt_Remove_user_as_an_administrator;
static const Act_Action_t Enr_ActRemAdm[Sco_NUM_SCOPES] =
{
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,
};
if (Usr_ChkIfUsrCodExists (Gbl.Usrs.Other.UsrDat.UsrCod))
{
sprintf (Gbl.Message,
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);
Lay_ShowAlert (Lay_INFO,Gbl.Message);
Rec_ShowCommonRecordUnmodifiable (&Gbl.Usrs.Other.UsrDat);
Act_FormStart (Enr_ActRemAdm[Scope]);
Usr_PutParamOtherUsrCodEncrypted ();
Lay_PutRemoveButton (ItsMe ? Txt_Remove_me_as_an_administrator :
Txt_Remove_user_as_an_administrator);
Act_FormEnd ();
}
else
Lay_ShowErrorAndExit ("User doesn't exist.");
}
/*****************************************************************************/
/**** Remove an administrator from current institution, centre or degree *****/
/*****************************************************************************/
static void Enr_EffectivelyRemAdm (struct UsrData *UsrDat,Sco_Scope_t Scope,
long Cod,const char *InsCtrDegName)
{
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;
char Query[1024];
if (Usr_CheckIfUsrIsAdm (UsrDat->UsrCod,Scope,Cod)) // User is administrator of current institution/centre/degree
{
/***** Remove user from the table of admins *****/
sprintf (Query,"DELETE FROM admin"
" WHERE UsrCod='%ld' AND Scope='%s' AND Cod='%ld'",
UsrDat->UsrCod,Sco_ScopeAdminDB[Scope],Cod);
DB_QueryDELETE (Query,"can not remove an administrator");
sprintf (Gbl.Message,Txt_THE_USER_X_has_been_removed_as_administrator_of_Y,
UsrDat->FullName,InsCtrDegName);
Lay_ShowAlert (Lay_SUCCESS,Gbl.Message);
}
else // User is not an administrator of the current institution/centre/degree
{
sprintf (Gbl.Message,Txt_THE_USER_X_is_not_an_administrator_of_Y,
UsrDat->FullName,InsCtrDegName);
Lay_ShowAlert (Lay_ERROR,Gbl.Message);
}
}