Version 18.7.19

This commit is contained in:
Antonio Cañas Vargas 2018-10-20 21:19:30 +02:00
parent 20bb37c40e
commit d06dcb0895
3 changed files with 607 additions and 575 deletions

View File

@ -355,10 +355,11 @@ En OpenSWAD:
ps2pdf source.ps destination.pdf ps2pdf source.ps destination.pdf
*/ */
#define Log_PLATFORM_VERSION "SWAD 18.7.18 (2018-10-20)" #define Log_PLATFORM_VERSION "SWAD 18.7.19 (2018-10-20)"
#define CSS_FILE "swad18.4.css" #define CSS_FILE "swad18.4.css"
#define JS_FILE "swad17.17.1.js" #define JS_FILE "swad17.17.1.js"
/* /*
Version 18.7.19: Oct 20, 2018 Some sprintf for database queries changed by asprintf. (237089 lines)
Version 18.7.18: Oct 20, 2018 Some sprintf for database queries changed by asprintf. (237060 lines) Version 18.7.18: Oct 20, 2018 Some sprintf for database queries changed by asprintf. (237060 lines)
Version 18.7.17: Oct 20, 2018 Some sprintf for database queries changed by asprintf. (237047 lines) Version 18.7.17: Oct 20, 2018 Some sprintf for database queries changed by asprintf. (237047 lines)
Version 18.7.16: Oct 20, 2018 Some sprintf for database queries changed by asprintf. (237016 lines) Version 18.7.16: Oct 20, 2018 Some sprintf for database queries changed by asprintf. (237016 lines)

View File

@ -25,6 +25,9 @@
/*********************************** Headers *********************************/ /*********************************** Headers *********************************/
/*****************************************************************************/ /*****************************************************************************/
#define _GNU_SOURCE // For asprintf
#include <stdio.h> // For asprintf
#include "swad_account.h" #include "swad_account.h"
#include "swad_box.h" #include "swad_box.h"
#include "swad_database.h" #include "swad_database.h"
@ -79,7 +82,7 @@ void Dup_ReportUsrAsPossibleDuplicate (void)
{ {
extern const char *Txt_Thank_you_for_reporting_a_possible_duplicate_user; extern const char *Txt_Thank_you_for_reporting_a_possible_duplicate_user;
extern const char *Txt_User_not_found_or_you_do_not_have_permission_; extern const char *Txt_User_not_found_or_you_do_not_have_permission_;
char Query[256]; char *Query;
bool ItsMe; bool ItsMe;
/***** Get user to be reported as possible duplicate *****/ /***** Get user to be reported as possible duplicate *****/
@ -90,13 +93,14 @@ void Dup_ReportUsrAsPossibleDuplicate (void)
if (!ItsMe && Gbl.Usrs.Me.Role.Logged >= Rol_TCH) if (!ItsMe && Gbl.Usrs.Me.Role.Logged >= Rol_TCH)
{ {
/***** Insert possible duplicate into database *****/ /***** Insert possible duplicate into database *****/
sprintf (Query,"REPLACE INTO usr_duplicated" if (asprintf (&Query,"REPLACE INTO usr_duplicated"
" (UsrCod,InformerCod,InformTime)" " (UsrCod,InformerCod,InformTime)"
" VALUES" " VALUES"
" (%ld,%ld,NOW())", " (%ld,%ld,NOW())",
Gbl.Usrs.Other.UsrDat.UsrCod, Gbl.Usrs.Other.UsrDat.UsrCod,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
DB_QueryINSERT (Query,"can not report duplicate"); Lay_NotEnoughMemoryExit ();
DB_QueryINSERT_free (Query,"can not report duplicate");
/***** Show feedback message *****/ /***** Show feedback message *****/
Ale_ShowAlert (Ale_SUCCESS,Txt_Thank_you_for_reporting_a_possible_duplicate_user); Ale_ShowAlert (Ale_SUCCESS,Txt_Thank_you_for_reporting_a_possible_duplicate_user);
@ -132,7 +136,7 @@ void Dup_ListDuplicateUsrs (void)
extern const char *Hlp_USERS_Duplicates_possibly_duplicate_users; extern const char *Hlp_USERS_Duplicates_possibly_duplicate_users;
extern const char *Txt_Possibly_duplicate_users; extern const char *Txt_Possibly_duplicate_users;
extern const char *Txt_Informants; extern const char *Txt_Informants;
char Query[1024]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumUsrs; unsigned NumUsrs;
@ -145,11 +149,12 @@ void Dup_ListDuplicateUsrs (void)
Hlp_USERS_Duplicates_possibly_duplicate_users,Box_NOT_CLOSABLE); Hlp_USERS_Duplicates_possibly_duplicate_users,Box_NOT_CLOSABLE);
/***** Build query *****/ /***** Build query *****/
sprintf (Query,"SELECT UsrCod,COUNT(*) AS N,MIN(UNIX_TIMESTAMP(InformTime)) AS T" if (asprintf (&Query,"SELECT UsrCod,COUNT(*) AS N,MIN(UNIX_TIMESTAMP(InformTime)) AS T"
" FROM usr_duplicated" " FROM usr_duplicated"
" GROUP BY UsrCod" " GROUP BY UsrCod"
" ORDER BY N DESC,T DESC"); " ORDER BY N DESC,T DESC") < 0)
NumUsrs = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get possibly duplicate users"); Lay_NotEnoughMemoryExit ();
NumUsrs = (unsigned) DB_QuerySELECT_free (Query,&mysql_res,"can not get possibly duplicate users");
/***** List possible duplicated users *****/ /***** List possible duplicated users *****/
if (NumUsrs) if (NumUsrs)
@ -229,6 +234,9 @@ void Dup_ListDuplicateUsrs (void)
/***** Show warning indicating no users found *****/ /***** Show warning indicating no users found *****/
Usr_ShowWarningNoUsersFound (Rol_UNK); Usr_ShowWarningNoUsersFound (Rol_UNK);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** End box *****/ /***** End box *****/
Box_EndBox (); Box_EndBox ();
} }
@ -253,7 +261,7 @@ static void Dup_ListSimilarUsrs (void)
extern const char *Hlp_USERS_Duplicates_similar_users; extern const char *Hlp_USERS_Duplicates_similar_users;
extern const char *Txt_Similar_users; extern const char *Txt_Similar_users;
struct UsrData UsrDat; struct UsrData UsrDat;
char Query[512 + Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME * 3]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumUsrs; unsigned NumUsrs;
@ -266,7 +274,8 @@ static void Dup_ListSimilarUsrs (void)
/***** Build query *****/ /***** Build query *****/
if (Gbl.Usrs.Other.UsrDat.Surname1[0] && if (Gbl.Usrs.Other.UsrDat.Surname1[0] &&
Gbl.Usrs.Other.UsrDat.FirstName[0]) // Name and surname 1 not empty Gbl.Usrs.Other.UsrDat.FirstName[0]) // Name and surname 1 not empty
sprintf (Query,"SELECT DISTINCT UsrCod FROM" {
if (asprintf (&Query,"SELECT DISTINCT UsrCod FROM"
"(SELECT DISTINCT UsrCod FROM usr_IDs" "(SELECT DISTINCT UsrCod FROM usr_IDs"
" WHERE UsrID IN (SELECT UsrID FROM usr_IDs WHERE UsrCod=%ld)" " WHERE UsrID IN (SELECT UsrID FROM usr_IDs WHERE UsrCod=%ld)"
" UNION" " UNION"
@ -276,12 +285,15 @@ static void Dup_ListSimilarUsrs (void)
Gbl.Usrs.Other.UsrDat.UsrCod, Gbl.Usrs.Other.UsrDat.UsrCod,
Gbl.Usrs.Other.UsrDat.Surname1, Gbl.Usrs.Other.UsrDat.Surname1,
Gbl.Usrs.Other.UsrDat.Surname2, Gbl.Usrs.Other.UsrDat.Surname2,
Gbl.Usrs.Other.UsrDat.FirstName); Gbl.Usrs.Other.UsrDat.FirstName) < 0)
Lay_NotEnoughMemoryExit ();
}
else else
sprintf (Query,"SELECT DISTINCT UsrCod FROM usr_IDs" if (asprintf (&Query,"SELECT DISTINCT UsrCod FROM usr_IDs"
" WHERE UsrID IN (SELECT UsrID FROM usr_IDs WHERE UsrCod=%ld)", " WHERE UsrID IN (SELECT UsrID FROM usr_IDs WHERE UsrCod=%ld)",
Gbl.Usrs.Other.UsrDat.UsrCod); Gbl.Usrs.Other.UsrDat.UsrCod) < 0)
NumUsrs = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get similar users"); Lay_NotEnoughMemoryExit ();
NumUsrs = (unsigned) DB_QuerySELECT_free (Query,&mysql_res,"can not get similar users");
/***** List possible similar users *****/ /***** List possible similar users *****/
if (NumUsrs) if (NumUsrs)
@ -370,6 +382,9 @@ static void Dup_ListSimilarUsrs (void)
/***** Show warning indicating no users found *****/ /***** Show warning indicating no users found *****/
Usr_ShowWarningNoUsersFound (Rol_UNK); Usr_ShowWarningNoUsersFound (Rol_UNK);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** End box *****/ /***** End box *****/
Box_EndBox (); Box_EndBox ();
} }
@ -380,11 +395,12 @@ static void Dup_ListSimilarUsrs (void)
static bool Dup_CheckIfUsrIsDup (long UsrCod) static bool Dup_CheckIfUsrIsDup (long UsrCod)
{ {
char Query[128]; char *Query;
sprintf (Query,"SELECT COUNT(*) FROM usr_duplicated WHERE UsrCod=%ld", if (asprintf (&Query,"SELECT COUNT(*) FROM usr_duplicated WHERE UsrCod=%ld",
UsrCod); UsrCod) < 0)
return (DB_QueryCOUNT (Query,"can not if user is in list of possible duplicate users") != 0); Lay_NotEnoughMemoryExit ();
return (DB_QueryCOUNT_free (Query,"can not if user is in list of possible duplicate users") != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -460,10 +476,11 @@ void Dup_RemoveUsrFromListDupUsrs (void)
void Dup_RemoveUsrFromDuplicated (long UsrCod) void Dup_RemoveUsrFromDuplicated (long UsrCod)
{ {
char Query[128]; char *Query;
/***** Remove user from list of duplicated users *****/ /***** Remove user from list of duplicated users *****/
sprintf (Query,"DELETE FROM usr_duplicated WHERE UsrCod=%ld", if (asprintf (&Query,"DELETE FROM usr_duplicated WHERE UsrCod=%ld",
UsrCod); UsrCod) < 0)
DB_QueryDELETE (Query,"can not remove a user from possible duplicates"); Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove a user from possible duplicates");
} }

View File

@ -209,7 +209,7 @@ void Enr_PutLinkToRequestSignUp (void)
void Enr_ModifyRoleInCurrentCrs (struct UsrData *UsrDat,Rol_Role_t NewRole) void Enr_ModifyRoleInCurrentCrs (struct UsrData *UsrDat,Rol_Role_t NewRole)
{ {
char Query[256]; char *Query;
/***** Check if user's role is allowed *****/ /***** Check if user's role is allowed *****/
switch (NewRole) switch (NewRole)
@ -223,10 +223,11 @@ void Enr_ModifyRoleInCurrentCrs (struct UsrData *UsrDat,Rol_Role_t NewRole)
} }
/***** Update the role of a user in a course *****/ /***** Update the role of a user in a course *****/
sprintf (Query,"UPDATE crs_usr SET Role=%u" if (asprintf (&Query,"UPDATE crs_usr SET Role=%u"
" WHERE CrsCod=%ld AND UsrCod=%ld", " WHERE CrsCod=%ld AND UsrCod=%ld",
(unsigned) NewRole,Gbl.CurrentCrs.Crs.CrsCod,UsrDat->UsrCod); (unsigned) NewRole,Gbl.CurrentCrs.Crs.CrsCod,UsrDat->UsrCod) < 0)
DB_QueryUPDATE (Query,"can not modify user's role in course"); Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not modify user's role in course");
/***** Flush caches *****/ /***** Flush caches *****/
Usr_FlushCachesUsr (); Usr_FlushCachesUsr ();
@ -253,7 +254,7 @@ void Enr_RegisterUsrInCurrentCrs (struct UsrData *UsrDat,Rol_Role_t NewRole,
Enr_KeepOrSetAccepted_t KeepOrSetAccepted) Enr_KeepOrSetAccepted_t KeepOrSetAccepted)
{ {
extern const char *Usr_StringsUsrListTypeInDB[Usr_NUM_USR_LIST_TYPES]; extern const char *Usr_StringsUsrListTypeInDB[Usr_NUM_USR_LIST_TYPES];
char Query[1024]; char *Query;
/***** Check if user's role is allowed *****/ /***** Check if user's role is allowed *****/
switch (NewRole) switch (NewRole)
@ -267,7 +268,7 @@ void Enr_RegisterUsrInCurrentCrs (struct UsrData *UsrDat,Rol_Role_t NewRole,
} }
/***** Register user in current course in database *****/ /***** Register user in current course in database *****/
sprintf (Query,"INSERT INTO crs_usr" if (asprintf (&Query,"INSERT INTO crs_usr"
" (CrsCod,UsrCod,Role,Accepted," " (CrsCod,UsrCod,Role,Accepted,"
"LastDowGrpCod,LastComGrpCod,LastAssGrpCod," "LastDowGrpCod,LastComGrpCod,LastAssGrpCod,"
"NumAccTst,LastAccTst,NumQstsLastTst," "NumAccTst,LastAccTst,NumQstsLastTst,"
@ -284,8 +285,9 @@ void Enr_RegisterUsrInCurrentCrs (struct UsrData *UsrDat,Rol_Role_t NewRole,
Usr_StringsUsrListTypeInDB[Usr_SHOW_USRS_TYPE_DEFAULT], Usr_StringsUsrListTypeInDB[Usr_SHOW_USRS_TYPE_DEFAULT],
Usr_CLASS_PHOTO_COLS_DEF, Usr_CLASS_PHOTO_COLS_DEF,
Usr_LIST_WITH_PHOTOS_DEF ? 'Y' : Usr_LIST_WITH_PHOTOS_DEF ? 'Y' :
'N'); 'N') < 0)
DB_QueryINSERT (Query,"can not register user in course"); Lay_NotEnoughMemoryExit ();
DB_QueryINSERT_free (Query,"can not register user in course");
/***** Flush caches *****/ /***** Flush caches *****/
Usr_FlushCachesUsr (); Usr_FlushCachesUsr ();
@ -466,31 +468,29 @@ void Enr_ReqAcceptRegisterInCrs (void)
/*****************************************************************************/ /*****************************************************************************/
/****************** Put an enrolment into a notification ********************/ /****************** Put an enrolment into a notification ********************/
/*****************************************************************************/ /*****************************************************************************/
// This function may be called inside a web service, so don't report error
void Enr_GetNotifEnrolment (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1], void Enr_GetNotifEnrolment (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
long CrsCod,long UsrCod) long CrsCod,long UsrCod)
{ {
extern const char *Txt_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS]; extern const char *Txt_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
char Query[256]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
struct UsrData UsrDat; struct UsrData UsrDat;
Rol_Role_t Role; Rol_Role_t Role;
SummaryStr[0] = '\0'; // Return nothing on error SummaryStr[0] = '\0'; // Return nothing on error
// This function may be called inside a web service, so don't report error
/***** Get user's role in course from database *****/ /***** Get user's role in course from database *****/
sprintf (Query,"SELECT Role" if (asprintf (&Query,"SELECT Role"
" FROM crs_usr" " FROM crs_usr"
" WHERE CrsCod=%ld AND UsrCod=%ld", " WHERE CrsCod=%ld AND UsrCod=%ld",
CrsCod,UsrCod); CrsCod,UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
if (!mysql_query (&Gbl.mysql,Query)) if (DB_QuerySELECT_free (Query,&mysql_res,"can not get user's role"
if ((mysql_res = mysql_store_result (&Gbl.mysql)) != NULL) " in course") == 1) // Result should have a unique row
{
/***** Result should have a unique row *****/
if (mysql_num_rows (mysql_res) == 1)
{ {
/***** Get user's role in course *****/ /***** Get user's role in course *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -511,8 +511,8 @@ void Enr_GetNotifEnrolment (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
Usr_UsrDataDestructor (&UsrDat); Usr_UsrDataDestructor (&UsrDat);
} }
mysql_free_result (mysql_res); /***** Free structure that stores the query result *****/
} DB_FreeMySQLResult (&mysql_res);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -525,7 +525,6 @@ void Enr_UpdateUsrData (struct UsrData *UsrDat)
extern const char *Usr_StringsSexDB[Usr_NUM_SEXS]; extern const char *Usr_StringsSexDB[Usr_NUM_SEXS];
char BirthdayStrDB[Usr_BIRTHDAY_STR_DB_LENGTH + 1]; char BirthdayStrDB[Usr_BIRTHDAY_STR_DB_LENGTH + 1];
char *Query; char *Query;
size_t CommentsLength;
/***** Check if user's code is initialized *****/ /***** Check if user's code is initialized *****/
if (UsrDat->UsrCod <= 0) if (UsrDat->UsrCod <= 0)
@ -536,22 +535,7 @@ void Enr_UpdateUsrData (struct UsrData *UsrDat)
/***** Update user's common data *****/ /***** Update user's common data *****/
Usr_CreateBirthdayStrDB (UsrDat,BirthdayStrDB); // It can include start and ending apostrophes Usr_CreateBirthdayStrDB (UsrDat,BirthdayStrDB); // It can include start and ending apostrophes
if (UsrDat->Comments) if (asprintf (&Query,"UPDATE usr_data"
CommentsLength = strlen (UsrDat->Comments);
else
CommentsLength = 0;
if ((Query = (char *) malloc (2048 +
Pwd_BYTES_ENCRYPTED_PASSWORD + // Password
Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME * 3 +// Surname1, Surname2, FirstName
Usr_MAX_BYTES_ADDRESS + // LocalAddress
Usr_MAX_BYTES_PHONE + // LocalPhone
Usr_MAX_BYTES_ADDRESS + // FamilyAddress
Usr_MAX_BYTES_PHONE + // FamilyPhone
Usr_MAX_BYTES_ADDRESS + // OriginPlace
Usr_BIRTHDAY_STR_DB_LENGTH + // BirthdayStrDB
CommentsLength)) == NULL) // Comments
Lay_NotEnoughMemoryExit ();
sprintf (Query,"UPDATE usr_data"
" SET Password='%s'," " SET Password='%s',"
"Surname1='%s',Surname2='%s',FirstName='%s',Sex='%s'," "Surname1='%s',Surname2='%s',FirstName='%s',Sex='%s',"
"CtyCod=%ld," "CtyCod=%ld,"
@ -568,11 +552,11 @@ void Enr_UpdateUsrData (struct UsrData *UsrDat)
UsrDat->FamilyAddress,UsrDat->FamilyPhone, UsrDat->FamilyAddress,UsrDat->FamilyPhone,
UsrDat->OriginPlace, UsrDat->OriginPlace,
BirthdayStrDB, BirthdayStrDB,
CommentsLength ? UsrDat->Comments : UsrDat->Comments ? UsrDat->Comments :
"", "",
UsrDat->UsrCod); UsrDat->UsrCod) < 0)
DB_QueryUPDATE (Query,"can not update user's data"); Lay_NotEnoughMemoryExit ();
free ((void *) Query); DB_QueryUPDATE_free (Query,"can not update user's data");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -595,17 +579,18 @@ void Enr_FilterUsrDat (struct UsrData *UsrDat)
void Enr_UpdateInstitutionCentreDepartment (void) void Enr_UpdateInstitutionCentreDepartment (void)
{ {
char Query[256]; char *Query;
sprintf (Query,"UPDATE usr_data" if (asprintf (&Query,"UPDATE usr_data"
" SET InsCtyCod=%ld,InsCod=%ld,CtrCod=%ld,DptCod=%ld" " SET InsCtyCod=%ld,InsCod=%ld,CtrCod=%ld,DptCod=%ld"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.InsCtyCod, Gbl.Usrs.Me.UsrDat.InsCtyCod,
Gbl.Usrs.Me.UsrDat.InsCod, Gbl.Usrs.Me.UsrDat.InsCod,
Gbl.Usrs.Me.UsrDat.Tch.CtrCod, Gbl.Usrs.Me.UsrDat.Tch.CtrCod,
Gbl.Usrs.Me.UsrDat.Tch.DptCod, Gbl.Usrs.Me.UsrDat.Tch.DptCod,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
DB_QueryUPDATE (Query,"can not update institution, centre and department"); Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not update institution, centre and department");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -869,7 +854,7 @@ void Enr_RemoveOldUsrs (void)
extern const char *Txt_X_users_have_been_eliminated; extern const char *Txt_X_users_have_been_eliminated;
unsigned MonthsWithoutAccess; unsigned MonthsWithoutAccess;
time_t SecondsWithoutAccess; time_t SecondsWithoutAccess;
char Query[1024]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumUsr; unsigned long NumUsr;
@ -888,7 +873,7 @@ void Enr_RemoveOldUsrs (void)
SecondsWithoutAccess = (time_t) MonthsWithoutAccess * Dat_SECONDS_IN_ONE_MONTH; SecondsWithoutAccess = (time_t) MonthsWithoutAccess * Dat_SECONDS_IN_ONE_MONTH;
/***** Get old users from database *****/ /***** Get old users from database *****/
sprintf (Query,"SELECT UsrCod FROM" if (asprintf (&Query,"SELECT UsrCod FROM"
"(" "("
"SELECT UsrCod FROM usr_last WHERE" "SELECT UsrCod FROM usr_last WHERE"
" LastTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')" " LastTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')"
@ -897,8 +882,9 @@ void Enr_RemoveOldUsrs (void)
" UsrCod NOT IN (SELECT UsrCod FROM usr_last)" " UsrCod NOT IN (SELECT UsrCod FROM usr_last)"
") AS candidate_usrs" ") AS candidate_usrs"
" WHERE UsrCod NOT IN (SELECT DISTINCT UsrCod FROM crs_usr)", " WHERE UsrCod NOT IN (SELECT DISTINCT UsrCod FROM crs_usr)",
(unsigned long) SecondsWithoutAccess); (unsigned long) SecondsWithoutAccess) < 0)
if ((NumUsrs = DB_QuerySELECT (Query,&mysql_res,"can not get old users"))) Lay_NotEnoughMemoryExit ();
if ((NumUsrs = DB_QuerySELECT_free (Query,&mysql_res,"can not get old users")))
{ {
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
Txt_Eliminating_X_users_who_were_not_enroled_in_any_course_and_with_more_than_Y_months_without_access_to_Z, Txt_Eliminating_X_users_who_were_not_enroled_in_any_course_and_with_more_than_Y_months_without_access_to_Z,
@ -2027,7 +2013,7 @@ void Enr_SignUpInCrs (void)
extern const char *Txt_You_were_already_enroled_as_X_in_the_course_Y; extern const char *Txt_You_were_already_enroled_as_X_in_the_course_Y;
extern const char *Txt_ROLES_SINGUL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS]; extern const char *Txt_ROLES_SINGUL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
extern const char *Txt_Your_request_for_enrolment_as_X_in_the_course_Y_has_been_accepted_for_processing; extern const char *Txt_Your_request_for_enrolment_as_X_in_the_course_Y_has_been_accepted_for_processing;
char Query[512]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
Rol_Role_t RoleFromForm; Rol_Role_t RoleFromForm;
@ -2058,11 +2044,12 @@ void Enr_SignUpInCrs (void)
Lay_ShowErrorAndExit ("Wrong role."); Lay_ShowErrorAndExit ("Wrong role.");
/***** Try to get and old request of the same user in the same course from database *****/ /***** Try to get and old request of the same user in the same course from database *****/
sprintf (Query,"SELECT ReqCod FROM crs_usr_requests" if (asprintf (&Query,"SELECT ReqCod FROM crs_usr_requests"
" WHERE CrsCod=%ld AND UsrCod=%ld", " WHERE CrsCod=%ld AND UsrCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod, Gbl.CurrentCrs.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
if (DB_QuerySELECT (Query,&mysql_res,"can not get enrolment request")) Lay_NotEnoughMemoryExit ();
if (DB_QuerySELECT_free (Query,&mysql_res,"can not get enrolment request"))
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
/* Get request code (row[0]) */ /* Get request code (row[0]) */
@ -2074,24 +2061,26 @@ void Enr_SignUpInCrs (void)
/***** Request user in current course in database *****/ /***** Request user in current course in database *****/
if (ReqCod > 0) // Old request exists in database if (ReqCod > 0) // Old request exists in database
{ {
sprintf (Query,"UPDATE crs_usr_requests SET Role=%u,RequestTime=NOW()" if (asprintf (&Query,"UPDATE crs_usr_requests SET Role=%u,RequestTime=NOW()"
" WHERE ReqCod=%ld AND CrsCod=%ld AND UsrCod=%ld", " WHERE ReqCod=%ld AND CrsCod=%ld AND UsrCod=%ld",
(unsigned) RoleFromForm, (unsigned) RoleFromForm,
ReqCod, ReqCod,
Gbl.CurrentCrs.Crs.CrsCod, Gbl.CurrentCrs.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
DB_QueryUPDATE (Query,"can not update enrolment request"); Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not update enrolment request");
} }
else // No request in database for this user in this course else // No request in database for this user in this course
{ {
sprintf (Query,"INSERT INTO crs_usr_requests" if (asprintf (&Query,"INSERT INTO crs_usr_requests"
" (CrsCod,UsrCod,Role,RequestTime)" " (CrsCod,UsrCod,Role,RequestTime)"
" VALUES" " VALUES"
" (%ld,%ld,%u,NOW())", " (%ld,%ld,%u,NOW())",
Gbl.CurrentCrs.Crs.CrsCod, Gbl.CurrentCrs.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) RoleFromForm); (unsigned) RoleFromForm) < 0)
ReqCod = DB_QueryINSERTandReturnCode (Query,"can not save enrolment request"); Lay_NotEnoughMemoryExit ();
ReqCod = DB_QueryINSERTandReturnCode_free (Query,"can not save enrolment request");
} }
/***** Show confirmation message *****/ /***** Show confirmation message *****/
@ -2113,32 +2102,29 @@ void Enr_SignUpInCrs (void)
/*****************************************************************************/ /*****************************************************************************/
/************** Put an enrolment request into a notification *****************/ /************** Put an enrolment request into a notification *****************/
/*****************************************************************************/ /*****************************************************************************/
// This function may be called inside a web service, so don't report error
void Enr_GetNotifEnrolmentRequest (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1], void Enr_GetNotifEnrolmentRequest (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
char **ContentStr, char **ContentStr,
long ReqCod,bool GetContent) long ReqCod,bool GetContent)
{ {
extern const char *Txt_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS]; extern const char *Txt_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
char Query[256]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
struct UsrData UsrDat; struct UsrData UsrDat;
Rol_Role_t DesiredRole; Rol_Role_t DesiredRole;
SummaryStr[0] = '\0'; // Return nothing on error SummaryStr[0] = '\0'; // Return nothing on error
// This function may be called inside a web service, so don't report error
/***** Get user and requested role from database *****/ /***** Get user and requested role from database *****/
sprintf (Query,"SELECT UsrCod,Role" if (asprintf (&Query,"SELECT UsrCod,Role"
" FROM crs_usr_requests" " FROM crs_usr_requests"
" WHERE ReqCod=%ld", " WHERE ReqCod=%ld",
ReqCod); ReqCod) < 0)
Lay_NotEnoughMemoryExit ();
if (!mysql_query (&Gbl.mysql,Query)) if (DB_QuerySELECT_free (Query,&mysql_res,"can not get enrolment request") == 1) // Result should have a unique row
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 *****/ /***** Get user and requested role *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -2166,8 +2152,8 @@ void Enr_GetNotifEnrolmentRequest (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
Usr_UsrDataDestructor (&UsrDat); Usr_UsrDataDestructor (&UsrDat);
} }
mysql_free_result (mysql_res); /***** Free structure that stores the query result *****/
} DB_FreeMySQLResult (&mysql_res);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2338,7 +2324,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
extern const char *Txt_Register; extern const char *Txt_Register;
extern const char *Txt_Reject; extern const char *Txt_Reject;
extern const char *Txt_No_enrolment_requests; extern const char *Txt_No_enrolment_requests;
char Query[1024]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumReq; unsigned NumReq;
@ -2414,7 +2400,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
{ {
case Rol_TCH: case Rol_TCH:
// Requests in all courses in which I am teacher // Requests in all courses in which I am teacher
sprintf (Query,"SELECT crs_usr_requests.ReqCod," if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod," "crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod," "crs_usr_requests.UsrCod,"
"crs_usr_requests.Role," "crs_usr_requests.Role,"
@ -2427,11 +2413,12 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" ORDER BY crs_usr_requests.RequestTime DESC", " ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_TCH, (unsigned) Rol_TCH,
RolesSelected); RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Rol_DEG_ADM: case Rol_DEG_ADM:
// Requests in all degrees administrated by me // Requests in all degrees administrated by me
sprintf (Query,"SELECT crs_usr_requests.ReqCod," if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod," "crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod," "crs_usr_requests.UsrCod,"
"crs_usr_requests.Role," "crs_usr_requests.Role,"
@ -2443,11 +2430,12 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" AND ((1<<crs_usr_requests.Role)&%u)<>0" " AND ((1<<crs_usr_requests.Role)&%u)<>0"
" ORDER BY crs_usr_requests.RequestTime DESC", " ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_DEG], Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_DEG],
RolesSelected); RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Rol_CTR_ADM: case Rol_CTR_ADM:
// Requests in all centres administrated by me // Requests in all centres administrated by me
sprintf (Query,"SELECT crs_usr_requests.ReqCod," if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod," "crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod," "crs_usr_requests.UsrCod,"
"crs_usr_requests.Role," "crs_usr_requests.Role,"
@ -2460,11 +2448,12 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" AND ((1<<crs_usr_requests.Role)&%u)<>0" " AND ((1<<crs_usr_requests.Role)&%u)<>0"
" ORDER BY crs_usr_requests.RequestTime DESC", " ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_CTR], Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_CTR],
RolesSelected); RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Rol_INS_ADM: case Rol_INS_ADM:
// Requests in all institutions administrated by me // Requests in all institutions administrated by me
sprintf (Query,"SELECT crs_usr_requests.ReqCod," if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod," "crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod," "crs_usr_requests.UsrCod,"
"crs_usr_requests.Role," "crs_usr_requests.Role,"
@ -2478,11 +2467,12 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" AND ((1<<crs_usr_requests.Role)&%u)<>0" " AND ((1<<crs_usr_requests.Role)&%u)<>0"
" ORDER BY crs_usr_requests.RequestTime DESC", " ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_INS], Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_INS],
RolesSelected); RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Rol_SYS_ADM: case Rol_SYS_ADM:
// All requests // All requests
sprintf (Query,"SELECT ReqCod," if (asprintf (&Query,"SELECT ReqCod,"
"CrsCod," "CrsCod,"
"UsrCod," "UsrCod,"
"Role," "Role,"
@ -2490,7 +2480,8 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" FROM crs_usr_requests" " FROM crs_usr_requests"
" WHERE ((1<<Role)&%u)<>0" " WHERE ((1<<Role)&%u)<>0"
" ORDER BY RequestTime DESC", " ORDER BY RequestTime DESC",
RolesSelected); RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
default: default:
Lay_ShowErrorAndExit ("You don't have permission to list requesters."); Lay_ShowErrorAndExit ("You don't have permission to list requesters.");
@ -2502,7 +2493,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
{ {
case Rol_TCH: case Rol_TCH:
// Requests in courses of this country in which I am teacher // Requests in courses of this country in which I am teacher
sprintf (Query,"SELECT crs_usr_requests.ReqCod," if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod," "crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod," "crs_usr_requests.UsrCod,"
"crs_usr_requests.Role," "crs_usr_requests.Role,"
@ -2521,11 +2512,12 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_TCH, (unsigned) Rol_TCH,
Gbl.CurrentCty.Cty.CtyCod, Gbl.CurrentCty.Cty.CtyCod,
RolesSelected); RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Rol_DEG_ADM: case Rol_DEG_ADM:
// Requests in degrees of this country administrated by me // Requests in degrees of this country administrated by me
sprintf (Query,"SELECT crs_usr_requests.ReqCod," if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod," "crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod," "crs_usr_requests.UsrCod,"
"crs_usr_requests.Role," "crs_usr_requests.Role,"
@ -2542,11 +2534,12 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" ORDER BY crs_usr_requests.RequestTime DESC", " ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_DEG], Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_DEG],
Gbl.CurrentCty.Cty.CtyCod, Gbl.CurrentCty.Cty.CtyCod,
RolesSelected); RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Rol_CTR_ADM: case Rol_CTR_ADM:
// Requests in centres of this country administrated by me // Requests in centres of this country administrated by me
sprintf (Query,"SELECT crs_usr_requests.ReqCod," if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod," "crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod," "crs_usr_requests.UsrCod,"
"crs_usr_requests.Role," "crs_usr_requests.Role,"
@ -2563,11 +2556,12 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" ORDER BY crs_usr_requests.RequestTime DESC", " ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_CTR], Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_CTR],
Gbl.CurrentCty.Cty.CtyCod, Gbl.CurrentCty.Cty.CtyCod,
RolesSelected); RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Rol_INS_ADM: case Rol_INS_ADM:
// Requests in institutions of this country administrated by me // Requests in institutions of this country administrated by me
sprintf (Query,"SELECT crs_usr_requests.ReqCod," if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod," "crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod," "crs_usr_requests.UsrCod,"
"crs_usr_requests.Role," "crs_usr_requests.Role,"
@ -2584,11 +2578,12 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" ORDER BY crs_usr_requests.RequestTime DESC", " ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_INS], Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_INS],
Gbl.CurrentCty.Cty.CtyCod, Gbl.CurrentCty.Cty.CtyCod,
RolesSelected); RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Rol_SYS_ADM: case Rol_SYS_ADM:
// Requests in any course of this country // Requests in any course of this country
sprintf (Query,"SELECT crs_usr_requests.ReqCod," if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod," "crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod," "crs_usr_requests.UsrCod,"
"crs_usr_requests.Role," "crs_usr_requests.Role,"
@ -2602,7 +2597,8 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" AND ((1<<crs_usr_requests.Role)&%u)<>0" " AND ((1<<crs_usr_requests.Role)&%u)<>0"
" ORDER BY crs_usr_requests.RequestTime DESC", " ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.CurrentCty.Cty.CtyCod, Gbl.CurrentCty.Cty.CtyCod,
RolesSelected); RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
default: default:
Lay_ShowErrorAndExit ("You don't have permission to list requesters."); Lay_ShowErrorAndExit ("You don't have permission to list requesters.");
@ -2614,7 +2610,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
{ {
case Rol_TCH: case Rol_TCH:
// Requests in courses of this institution in which I am teacher // Requests in courses of this institution in which I am teacher
sprintf (Query,"SELECT crs_usr_requests.ReqCod," if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod," "crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod," "crs_usr_requests.UsrCod,"
"crs_usr_requests.Role," "crs_usr_requests.Role,"
@ -2632,11 +2628,12 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_TCH, (unsigned) Rol_TCH,
Gbl.CurrentIns.Ins.InsCod, Gbl.CurrentIns.Ins.InsCod,
RolesSelected); RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Rol_DEG_ADM: case Rol_DEG_ADM:
// Requests in degrees of this institution administrated by me // Requests in degrees of this institution administrated by me
sprintf (Query,"SELECT crs_usr_requests.ReqCod," if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod," "crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod," "crs_usr_requests.UsrCod,"
"crs_usr_requests.Role," "crs_usr_requests.Role,"
@ -2652,11 +2649,12 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" ORDER BY crs_usr_requests.RequestTime DESC", " ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_DEG], Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_DEG],
Gbl.CurrentIns.Ins.InsCod, Gbl.CurrentIns.Ins.InsCod,
RolesSelected); RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Rol_CTR_ADM: case Rol_CTR_ADM:
// Requests in centres of this institution administrated by me // Requests in centres of this institution administrated by me
sprintf (Query,"SELECT crs_usr_requests.ReqCod," if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod," "crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod," "crs_usr_requests.UsrCod,"
"crs_usr_requests.Role," "crs_usr_requests.Role,"
@ -2672,12 +2670,13 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" ORDER BY crs_usr_requests.RequestTime DESC", " ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_CTR], Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_CTR],
Gbl.CurrentIns.Ins.InsCod, Gbl.CurrentIns.Ins.InsCod,
RolesSelected); RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Rol_INS_ADM: // If I am logged as admin of this institution, I can view all the requesters from this institution case Rol_INS_ADM: // If I am logged as admin of this institution, I can view all the requesters from this institution
case Rol_SYS_ADM: case Rol_SYS_ADM:
// Requests in any course of this institution // Requests in any course of this institution
sprintf (Query,"SELECT crs_usr_requests.ReqCod," if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod," "crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod," "crs_usr_requests.UsrCod,"
"crs_usr_requests.Role," "crs_usr_requests.Role,"
@ -2690,7 +2689,8 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" AND ((1<<crs_usr_requests.Role)&%u)<>0" " AND ((1<<crs_usr_requests.Role)&%u)<>0"
" ORDER BY crs_usr_requests.RequestTime DESC", " ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.CurrentIns.Ins.InsCod, Gbl.CurrentIns.Ins.InsCod,
RolesSelected); RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
default: default:
Lay_ShowErrorAndExit ("You don't have permission to list requesters."); Lay_ShowErrorAndExit ("You don't have permission to list requesters.");
@ -2702,7 +2702,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
{ {
case Rol_TCH: case Rol_TCH:
// Requests in courses of this centre in which I am teacher // Requests in courses of this centre in which I am teacher
sprintf (Query,"SELECT crs_usr_requests.ReqCod," if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod," "crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod," "crs_usr_requests.UsrCod,"
"crs_usr_requests.Role," "crs_usr_requests.Role,"
@ -2719,11 +2719,12 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_TCH, (unsigned) Rol_TCH,
Gbl.CurrentCtr.Ctr.CtrCod, Gbl.CurrentCtr.Ctr.CtrCod,
RolesSelected); RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Rol_DEG_ADM: case Rol_DEG_ADM:
// Requests in degrees of this centre administrated by me // Requests in degrees of this centre administrated by me
sprintf (Query,"SELECT crs_usr_requests.ReqCod," if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod," "crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod," "crs_usr_requests.UsrCod,"
"crs_usr_requests.Role," "crs_usr_requests.Role,"
@ -2738,13 +2739,14 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" ORDER BY crs_usr_requests.RequestTime DESC", " ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_DEG], Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_DEG],
Gbl.CurrentCtr.Ctr.CtrCod, Gbl.CurrentCtr.Ctr.CtrCod,
RolesSelected); RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Rol_CTR_ADM: // If I am logged as admin of this centre , I can view all the requesters from this centre case Rol_CTR_ADM: // If I am logged as admin of this centre , I can view all the requesters from this centre
case Rol_INS_ADM: // If I am logged as admin of this institution, I can view all the requesters from this centre case Rol_INS_ADM: // If I am logged as admin of this institution, I can view all the requesters from this centre
case Rol_SYS_ADM: case Rol_SYS_ADM:
// Request in any course of this centre // Request in any course of this centre
sprintf (Query,"SELECT crs_usr_requests.ReqCod," if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod," "crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod," "crs_usr_requests.UsrCod,"
"crs_usr_requests.Role," "crs_usr_requests.Role,"
@ -2756,7 +2758,8 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" AND ((1<<crs_usr_requests.Role)&%u)<>0" " AND ((1<<crs_usr_requests.Role)&%u)<>0"
" ORDER BY crs_usr_requests.RequestTime DESC", " ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.CurrentCtr.Ctr.CtrCod, Gbl.CurrentCtr.Ctr.CtrCod,
RolesSelected); RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
default: default:
Lay_ShowErrorAndExit ("You don't have permission to list requesters."); Lay_ShowErrorAndExit ("You don't have permission to list requesters.");
@ -2768,7 +2771,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
{ {
case Rol_TCH: case Rol_TCH:
// Requests in courses of this degree in which I am teacher // Requests in courses of this degree in which I am teacher
sprintf (Query,"SELECT crs_usr_requests.ReqCod," if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod," "crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod," "crs_usr_requests.UsrCod,"
"crs_usr_requests.Role," "crs_usr_requests.Role,"
@ -2784,14 +2787,15 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_TCH, (unsigned) Rol_TCH,
Gbl.CurrentDeg.Deg.DegCod, Gbl.CurrentDeg.Deg.DegCod,
RolesSelected); RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Rol_DEG_ADM: // If I am logged as admin of this degree , I can view all the requesters from this degree case Rol_DEG_ADM: // If I am logged as admin of this degree , I can view all the requesters from this degree
case Rol_CTR_ADM: // If I am logged as admin of this centre , I can view all the requesters from this degree case Rol_CTR_ADM: // If I am logged as admin of this centre , I can view all the requesters from this degree
case Rol_INS_ADM: // If I am logged as admin of this institution, I can view all the requesters from this degree case Rol_INS_ADM: // If I am logged as admin of this institution, I can view all the requesters from this degree
case Rol_SYS_ADM: case Rol_SYS_ADM:
// Requests in any course of this degree // Requests in any course of this degree
sprintf (Query,"SELECT crs_usr_requests.ReqCod," if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod," "crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod," "crs_usr_requests.UsrCod,"
"crs_usr_requests.Role," "crs_usr_requests.Role,"
@ -2802,7 +2806,8 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" AND ((1<<crs_usr_requests.Role)&%u)<>0" " AND ((1<<crs_usr_requests.Role)&%u)<>0"
" ORDER BY crs_usr_requests.RequestTime DESC", " ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.CurrentDeg.Deg.DegCod, Gbl.CurrentDeg.Deg.DegCod,
RolesSelected); RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
default: default:
Lay_ShowErrorAndExit ("You don't have permission to list requesters."); Lay_ShowErrorAndExit ("You don't have permission to list requesters.");
@ -2818,14 +2823,15 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
case Rol_INS_ADM: // If I am logged as admin of this institution, I can view all the requesters from this course case Rol_INS_ADM: // If I am logged as admin of this institution, I can view all the requesters from this course
case Rol_SYS_ADM: case Rol_SYS_ADM:
// Requests in this course // Requests in this course
sprintf (Query,"SELECT ReqCod,CrsCod,UsrCod,Role," if (asprintf (&Query,"SELECT ReqCod,CrsCod,UsrCod,Role,"
"UNIX_TIMESTAMP(RequestTime)" "UNIX_TIMESTAMP(RequestTime)"
" FROM crs_usr_requests" " FROM crs_usr_requests"
" WHERE CrsCod=%ld" " WHERE CrsCod=%ld"
" AND ((1<<Role)&%u)<>0" " AND ((1<<Role)&%u)<>0"
" ORDER BY RequestTime DESC", " ORDER BY RequestTime DESC",
Gbl.CurrentCrs.Crs.CrsCod, Gbl.CurrentCrs.Crs.CrsCod,
RolesSelected); RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
default: default:
Lay_ShowErrorAndExit ("You don't have permission to list requesters."); Lay_ShowErrorAndExit ("You don't have permission to list requesters.");
@ -2837,7 +2843,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
break; break;
} }
NumRequests = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get requests for enrolment"); NumRequests = (unsigned) DB_QuerySELECT_free (Query,&mysql_res,"can not get requests for enrolment");
/***** List requests *****/ /***** List requests *****/
if (NumRequests) if (NumRequests)
@ -3023,7 +3029,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
static void Enr_RemoveEnrolmentRequest (long CrsCod,long UsrCod) static void Enr_RemoveEnrolmentRequest (long CrsCod,long UsrCod)
{ {
char Query[256]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
long ReqCod; long ReqCod;
@ -3031,10 +3037,11 @@ static void Enr_RemoveEnrolmentRequest (long CrsCod,long UsrCod)
/***** Mark possible notifications as removed /***** Mark possible notifications as removed
Important: do this before removing the request *****/ Important: do this before removing the request *****/
/* Request request code (returns 0 or 1 rows) */ /* Request request code (returns 0 or 1 rows) */
sprintf (Query,"SELECT ReqCod FROM crs_usr_requests" if (asprintf (&Query,"SELECT ReqCod FROM crs_usr_requests"
" WHERE CrsCod=%ld AND UsrCod=%ld", " WHERE CrsCod=%ld AND UsrCod=%ld",
CrsCod,UsrCod); CrsCod,UsrCod) < 0)
if (DB_QuerySELECT (Query,&mysql_res,"can not get request code")) // Request exists Lay_NotEnoughMemoryExit ();
if (DB_QuerySELECT_free (Query,&mysql_res,"can not get request code")) // Request exists
{ {
/* Get request code */ /* Get request code */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3047,10 +3054,11 @@ static void Enr_RemoveEnrolmentRequest (long CrsCod,long UsrCod)
DB_FreeMySQLResult (&mysql_res); DB_FreeMySQLResult (&mysql_res);
/***** Remove enrolment request *****/ /***** Remove enrolment request *****/
sprintf (Query,"DELETE FROM crs_usr_requests" if (asprintf (&Query,"DELETE FROM crs_usr_requests"
" WHERE CrsCod=%ld AND UsrCod=%ld", " WHERE CrsCod=%ld AND UsrCod=%ld",
CrsCod,UsrCod); CrsCod,UsrCod) < 0)
DB_QueryDELETE (Query,"can not remove a request for enrolment"); Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove a request for enrolment");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3059,25 +3067,27 @@ static void Enr_RemoveEnrolmentRequest (long CrsCod,long UsrCod)
static void Enr_RemoveExpiredEnrolmentRequests (void) static void Enr_RemoveExpiredEnrolmentRequests (void)
{ {
char Query[512]; char *Query;
/***** Mark possible notifications as removed /***** Mark possible notifications as removed
Important: do this before removing the request *****/ Important: do this before removing the request *****/
sprintf (Query,"UPDATE notif,crs_usr_requests" if (asprintf (&Query,"UPDATE notif,crs_usr_requests"
" SET notif.Status=(notif.Status | %u)" " SET notif.Status=(notif.Status | %u)"
" WHERE notif.NotifyEvent=%u" " WHERE notif.NotifyEvent=%u"
" AND notif.Cod=crs_usr_requests.ReqCod" " AND notif.Cod=crs_usr_requests.ReqCod"
" AND crs_usr_requests.RequestTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')", " AND crs_usr_requests.RequestTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')",
(unsigned) Ntf_STATUS_BIT_REMOVED, (unsigned) Ntf_STATUS_BIT_REMOVED,
(unsigned) Ntf_EVENT_ENROLMENT_REQUEST, (unsigned) Ntf_EVENT_ENROLMENT_REQUEST,
Cfg_TIME_TO_DELETE_ENROLMENT_REQUESTS); Cfg_TIME_TO_DELETE_ENROLMENT_REQUESTS) < 0)
DB_QueryUPDATE (Query,"can not set notification(s) as removed"); Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not set notification(s) as removed");
/***** Remove expired requests for enrolment *****/ /***** Remove expired requests for enrolment *****/
sprintf (Query,"DELETE FROM crs_usr_requests" if (asprintf (&Query,"DELETE FROM crs_usr_requests"
" WHERE RequestTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')", " WHERE RequestTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')",
Cfg_TIME_TO_DELETE_ENROLMENT_REQUESTS); Cfg_TIME_TO_DELETE_ENROLMENT_REQUESTS) < 0)
DB_QueryDELETE (Query,"can not remove expired requests for enrolment"); Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove expired requests for enrolment");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3463,7 +3473,7 @@ static void Enr_RegisterAdmin (struct UsrData *UsrDat,Sco_Scope_t Scope,long Cod
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES]; extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
extern const char *Txt_THE_USER_X_is_already_an_administrator_of_Y; extern const char *Txt_THE_USER_X_is_already_an_administrator_of_Y;
extern const char *Txt_THE_USER_X_has_been_enroled_as_administrator_of_Y; extern const char *Txt_THE_USER_X_has_been_enroled_as_administrator_of_Y;
char Query[512]; char *Query;
/***** Check if user was and administrator of current institution/centre/degree *****/ /***** Check if user was and administrator of current institution/centre/degree *****/
if (Usr_CheckIfUsrIsAdm (UsrDat->UsrCod,Scope,Cod)) if (Usr_CheckIfUsrIsAdm (UsrDat->UsrCod,Scope,Cod))
@ -3473,12 +3483,13 @@ static void Enr_RegisterAdmin (struct UsrData *UsrDat,Sco_Scope_t Scope,long Cod
else // User was not administrator of current institution/centre/degree else // User was not administrator of current institution/centre/degree
{ {
/***** Insert or replace administrator in current institution/centre/degree *****/ /***** Insert or replace administrator in current institution/centre/degree *****/
sprintf (Query,"REPLACE INTO admin" if (asprintf (&Query,"REPLACE INTO admin"
" (UsrCod,Scope,Cod)" " (UsrCod,Scope,Cod)"
" VALUES" " VALUES"
" (%ld,'%s',%ld)", " (%ld,'%s',%ld)",
UsrDat->UsrCod,Sco_ScopeDB[Scope],Cod); UsrDat->UsrCod,Sco_ScopeDB[Scope],Cod) < 0)
DB_QueryREPLACE (Query,"can not create administrator"); Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not create administrator");
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
Txt_THE_USER_X_has_been_enroled_as_administrator_of_Y, Txt_THE_USER_X_has_been_enroled_as_administrator_of_Y,
@ -4129,13 +4140,14 @@ void Enr_ModifyUsr2 (void)
void Enr_AcceptUsrInCrs (long UsrCod) void Enr_AcceptUsrInCrs (long UsrCod)
{ {
char Query[512]; char *Query;
/***** Set enrolment of a user to "accepted" in the current course *****/ /***** Set enrolment of a user to "accepted" in the current course *****/
sprintf (Query,"UPDATE crs_usr SET Accepted='Y'" if (asprintf (&Query,"UPDATE crs_usr SET Accepted='Y'"
" WHERE CrsCod=%ld AND UsrCod=%ld", " WHERE CrsCod=%ld AND UsrCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod,UsrCod); Gbl.CurrentCrs.Crs.CrsCod,UsrCod) < 0)
DB_QueryUPDATE (Query,"can not confirm user's enrolment"); Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not confirm user's enrolment");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -4207,7 +4219,7 @@ static void Enr_EffectivelyRemUsrFromCrs (struct UsrData *UsrDat,struct Course *
{ {
extern const char *Txt_THE_USER_X_has_been_removed_from_the_course_Y; 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_; extern const char *Txt_User_not_found_or_you_do_not_have_permission_;
char Query[1024]; char *Query;
bool ItsMe = Usr_ItsMe (UsrDat->UsrCod); bool ItsMe = Usr_ItsMe (UsrDat->UsrCod);
if (Usr_CheckIfUsrBelongsToCurrentCrs (UsrDat)) if (Usr_CheckIfUsrBelongsToCurrentCrs (UsrDat))
@ -4239,10 +4251,11 @@ static void Enr_EffectivelyRemUsrFromCrs (struct UsrData *UsrDat,struct Course *
Ntf_MarkNotifInCrsAsRemoved (UsrDat->UsrCod,Crs->CrsCod); Ntf_MarkNotifInCrsAsRemoved (UsrDat->UsrCod,Crs->CrsCod);
/***** Remove user from the table of courses-users *****/ /***** Remove user from the table of courses-users *****/
sprintf (Query,"DELETE FROM crs_usr" if (asprintf (&Query,"DELETE FROM crs_usr"
" WHERE CrsCod=%ld AND UsrCod=%ld", " WHERE CrsCod=%ld AND UsrCod=%ld",
Crs->CrsCod,UsrDat->UsrCod); Crs->CrsCod,UsrDat->UsrCod) < 0)
DB_QueryDELETE (Query,"can not remove a user from a course"); Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove a user from a course");
/***** Flush caches *****/ /***** Flush caches *****/
Usr_FlushCachesUsr (); Usr_FlushCachesUsr ();
@ -4347,15 +4360,16 @@ static void Enr_EffectivelyRemAdm (struct UsrData *UsrDat,Sco_Scope_t Scope,
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES]; extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
extern const char *Txt_THE_USER_X_has_been_removed_as_administrator_of_Y; 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; extern const char *Txt_THE_USER_X_is_not_an_administrator_of_Y;
char Query[1024]; char *Query;
if (Usr_CheckIfUsrIsAdm (UsrDat->UsrCod,Scope,Cod)) // User is administrator of current institution/centre/degree if (Usr_CheckIfUsrIsAdm (UsrDat->UsrCod,Scope,Cod)) // User is administrator of current institution/centre/degree
{ {
/***** Remove user from the table of admins *****/ /***** Remove user from the table of admins *****/
sprintf (Query,"DELETE FROM admin" if (asprintf (&Query,"DELETE FROM admin"
" WHERE UsrCod=%ld AND Scope='%s' AND Cod=%ld", " WHERE UsrCod=%ld AND Scope='%s' AND Cod=%ld",
UsrDat->UsrCod,Sco_ScopeDB[Scope],Cod); UsrDat->UsrCod,Sco_ScopeDB[Scope],Cod) < 0)
DB_QueryDELETE (Query,"can not remove an administrator"); Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove an administrator");
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
Txt_THE_USER_X_has_been_removed_as_administrator_of_Y, Txt_THE_USER_X_has_been_removed_as_administrator_of_Y,