Version 18.8.12

This commit is contained in:
Antonio Cañas Vargas 2018-10-27 14:46:08 +02:00
parent ff800923cc
commit d90d736fa8
19 changed files with 200 additions and 263 deletions

View File

@ -857,14 +857,11 @@ static bool ID_CheckIfConfirmed (long UsrCod,const char *UsrID)
static void ID_RemoveUsrIDFromDB (long UsrCod,const char *UsrID)
{
char *Query;
/***** Remove one of my user's IDs *****/
if (asprintf (&Query,"DELETE FROM usr_IDs"
" WHERE UsrCod=%ld AND UsrID='%s'",
UsrCod,UsrID) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not remove a user's ID");
DB_BuildQuery ("DELETE FROM usr_IDs"
" WHERE UsrCod=%ld AND UsrID='%s'",
UsrCod,UsrID);
DB_QueryREPLACE_new ("can not remove a user's ID");
}
/*****************************************************************************/

View File

@ -372,13 +372,12 @@ void MFU_UpdateMFUActions (void)
DB_FreeMySQLResult (&mysql_res);
/***** Update score for the current action *****/
if (asprintf (&Query,"REPLACE INTO actions_MFU"
" (UsrCod,ActCod,Score,LastClick)"
" VALUES"
" (%ld,%ld,'%f',NOW())",
Gbl.Usrs.Me.UsrDat.UsrCod,ActCod,Score) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not update most frequently used actions");
DB_BuildQuery ("REPLACE INTO actions_MFU"
" (UsrCod,ActCod,Score,LastClick)"
" VALUES"
" (%ld,%ld,'%f',NOW())",
Gbl.Usrs.Me.UsrDat.UsrCod,ActCod,Score);
DB_QueryREPLACE_new ("can not update most frequently used actions");
/***** Update score for other actions *****/
if (asprintf (&Query,"UPDATE actions_MFU SET Score=GREATEST(Score*'%f','%f')"

View File

@ -599,20 +599,18 @@ void Ann_RemoveAnnouncement (void)
void Ann_MarkAnnouncementAsSeen (void)
{
char *Query;
long AnnCod;
/***** Get the code of the global announcement *****/
AnnCod = Ann_GetParamAnnCod ();
/***** Mark announcement as seen *****/
if (asprintf (&Query,"REPLACE INTO ann_seen"
" (AnnCod,UsrCod)"
" VALUES"
" (%ld,%ld)",
AnnCod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not mark announcement as seen");
DB_BuildQuery ("REPLACE INTO ann_seen"
" (AnnCod,UsrCod)"
" VALUES"
" (%ld,%ld)",
AnnCod,Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryREPLACE_new ("can not mark announcement as seen");
/***** Show other announcements again *****/
Ann_ShowMyAnnouncementsNotMarkedAsSeen ();

View File

@ -2611,20 +2611,17 @@ void Att_RegUsrInAttEventNotChangingComments (long AttCod,long UsrCod)
static void Att_RegUsrInAttEventChangingComments (long AttCod,long UsrCod,bool Present,
const char *CommentStd,const char *CommentTch)
{
char *Query;
/***** Register user as assistant to an event in database *****/
if (asprintf (&Query,"REPLACE INTO att_usr"
" (AttCod,UsrCod,Present,CommentStd,CommentTch)"
" VALUES"
" (%ld,%ld,'%c','%s','%s')",
AttCod,UsrCod,
Present ? 'Y' :
'N',
CommentStd,
CommentTch) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not register user in an event");
DB_BuildQuery ("REPLACE INTO att_usr"
" (AttCod,UsrCod,Present,CommentStd,CommentTch)"
" VALUES"
" (%ld,%ld,'%c','%s','%s')",
AttCod,UsrCod,
Present ? 'Y' :
'N',
CommentStd,
CommentTch);
DB_QueryREPLACE_new ("can not register user in an event");
}
/*****************************************************************************/
@ -2633,14 +2630,11 @@ static void Att_RegUsrInAttEventChangingComments (long AttCod,long UsrCod,bool P
static void Att_RemoveUsrFromAttEvent (long AttCod,long UsrCod)
{
char *Query;
/***** Remove user if there is no comment in database *****/
if (asprintf (&Query,"DELETE FROM att_usr"
" WHERE AttCod=%ld AND UsrCod=%ld",
AttCod,UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not remove student from an event");
DB_BuildQuery ("DELETE FROM att_usr"
" WHERE AttCod=%ld AND UsrCod=%ld",
AttCod,UsrCod);
DB_QueryREPLACE_new ("can not remove student from an event");
}
/*****************************************************************************/

View File

@ -355,10 +355,11 @@ En OpenSWAD:
ps2pdf source.ps destination.pdf
*/
#define Log_PLATFORM_VERSION "SWAD 18.8.11 (2018-10-27)"
#define Log_PLATFORM_VERSION "SWAD 18.8.12 (2018-10-27)"
#define CSS_FILE "swad18.4.css"
#define JS_FILE "swad17.17.1.js"
/*
Version 18.8.12: Oct 27, 2018 Some asprintf for database queries changed by internal function. (236870 lines)
Version 18.8.11: Oct 27, 2018 Some asprintf for database queries changed by internal function. (236921 lines)
Version 18.8.10: Oct 27, 2018 Some asprintf for database queries changed by internal function. (236975 lines)
Version 18.8.9: Oct 26, 2018 Some asprintf for database queries changed by internal function. (237082 lines)

View File

@ -640,19 +640,16 @@ static void Con_ShowConnectedUsrsWithARoleBelongingToCurrentCrsOnRightColumn (Ro
void Con_UpdateMeInConnectedList (void)
{
char *Query;
/***** Update my entry in connected list.
The role which is stored is the role of the last click *****/
if (asprintf (&Query,"REPLACE INTO connected"
" (UsrCod,RoleInLastCrs,LastCrsCod,LastTime)"
" VALUES"
" (%ld,%u,%ld,NOW())",
DB_BuildQuery ("REPLACE INTO connected"
" (UsrCod,RoleInLastCrs,LastCrsCod,LastTime)"
" VALUES"
" (%ld,%u,%ld,NOW())",
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Gbl.Usrs.Me.Role.Logged,
Gbl.CurrentCrs.Crs.CrsCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not update list of connected users");
Gbl.CurrentCrs.Crs.CrsCod);
DB_QueryREPLACE_new ("can not update list of connected users");
}
/*****************************************************************************/

View File

@ -3437,7 +3437,6 @@ static void Enr_RegisterAdmin (struct UsrData *UsrDat,Sco_Scope_t Scope,long Cod
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_has_been_enroled_as_administrator_of_Y;
char *Query;
/***** Check if user was and administrator of current institution/centre/degree *****/
if (Usr_CheckIfUsrIsAdm (UsrDat->UsrCod,Scope,Cod))
@ -3447,13 +3446,12 @@ static void Enr_RegisterAdmin (struct UsrData *UsrDat,Sco_Scope_t Scope,long Cod
else // User was not administrator of current institution/centre/degree
{
/***** Insert or replace administrator in current institution/centre/degree *****/
if (asprintf (&Query,"REPLACE INTO admin"
" (UsrCod,Scope,Cod)"
" VALUES"
" (%ld,'%s',%ld)",
UsrDat->UsrCod,Sco_ScopeDB[Scope],Cod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not create administrator");
DB_BuildQuery ("REPLACE INTO admin"
" (UsrCod,Scope,Cod)"
" VALUES"
" (%ld,'%s',%ld)",
UsrDat->UsrCod,Sco_ScopeDB[Scope],Cod);
DB_QueryREPLACE_new ("can not create administrator");
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
Txt_THE_USER_X_has_been_enroled_as_administrator_of_Y,

View File

@ -4528,22 +4528,20 @@ static void Brw_StoreSizeOfFileTreeInDB (void)
{
long Cod = Brw_GetCodForFiles ();
long ZoneUsrCod = Brw_GetZoneUsrCodForFiles ();
char *Query;
/***** Update size of the file browser in database *****/
if (asprintf (&Query,"REPLACE INTO file_browser_size"
" (FileBrowser,Cod,ZoneUsrCod,"
"NumLevels,NumFolders,NumFiles,TotalSize)"
" VALUES"
" (%u,%ld,%ld,"
"%u,'%lu','%lu','%llu')",
(unsigned) Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type],Cod,ZoneUsrCod,
Gbl.FileBrowser.Size.NumLevls,
Gbl.FileBrowser.Size.NumFolds,
Gbl.FileBrowser.Size.NumFiles,
Gbl.FileBrowser.Size.TotalSiz) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not store the size of a file browser");
DB_BuildQuery ("REPLACE INTO file_browser_size"
" (FileBrowser,Cod,ZoneUsrCod,"
"NumLevels,NumFolders,NumFiles,TotalSize)"
" VALUES"
" (%u,%ld,%ld,"
"%u,'%lu','%lu','%llu')",
(unsigned) Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type],Cod,ZoneUsrCod,
Gbl.FileBrowser.Size.NumLevls,
Gbl.FileBrowser.Size.NumFolds,
Gbl.FileBrowser.Size.NumFiles,
Gbl.FileBrowser.Size.TotalSiz);
DB_QueryREPLACE_new ("can not store the size of a file browser");
}
/*****************************************************************************/
@ -5552,7 +5550,6 @@ void Brw_CreateDirDownloadTmp (void)
static void Brw_GetAndUpdateDateLastAccFileBrowser (void)
{
long Cod;
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
@ -5630,15 +5627,14 @@ static void Brw_GetAndUpdateDateLastAccFileBrowser (void)
DB_FreeMySQLResult (&mysql_res);
/***** Update date of my last access to file browser in this course *****/
if (asprintf (&Query,"REPLACE INTO file_browser_last"
" (UsrCod,FileBrowser,Cod,LastClick)"
" VALUES"
" (%ld,%u,%ld,NOW())",
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Brw_FileBrowserForDB_file_browser_last[Gbl.FileBrowser.Type],
Cod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not update date of last access to a file browser");
DB_BuildQuery ("REPLACE INTO file_browser_last"
" (UsrCod,FileBrowser,Cod,LastClick)"
" VALUES"
" (%ld,%u,%ld,NOW())",
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Brw_FileBrowserForDB_file_browser_last[Gbl.FileBrowser.Type],
Cod);
DB_QueryREPLACE_new ("can not update date of last access to a file browser");
}
/*****************************************************************************/

View File

@ -998,7 +998,6 @@ static void Fol_PutIconToUnfollow (struct UsrData *UsrDat)
void Fol_FollowUsr1 (void)
{
extern const char *Txt_User_not_found_or_you_do_not_have_permission_;
char *Query;
bool CreateNotif;
bool NotifyByEmail;
@ -1012,14 +1011,13 @@ void Fol_FollowUsr1 (void)
Gbl.Usrs.Other.UsrDat.UsrCod))
{
/***** Follow user in database *****/
if (asprintf (&Query,"REPLACE INTO usr_follow"
" (FollowerCod,FollowedCod,FollowTime)"
" VALUES"
" (%ld,%ld,NOW())",
Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Usrs.Other.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not follow user");
DB_BuildQuery ("REPLACE INTO usr_follow"
" (FollowerCod,FollowedCod,FollowTime)"
" VALUES"
" (%ld,%ld,NOW())",
Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Usrs.Other.UsrDat.UsrCod);
DB_QueryREPLACE_new ("can not follow user");
/***** This follow must be notified by email? *****/
CreateNotif = (Gbl.Usrs.Other.UsrDat.Prefs.NotifNtfEvents & (1 << Ntf_EVENT_FOLLOWER));
@ -1067,7 +1065,6 @@ void Fol_FollowUsr2 (void)
void Fol_UnfollowUsr1 (void)
{
extern const char *Txt_User_not_found_or_you_do_not_have_permission_;
char *Query;
/***** Get user to be unfollowed *****/
if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ())
@ -1077,12 +1074,11 @@ void Fol_UnfollowUsr1 (void)
Gbl.Usrs.Other.UsrDat.UsrCod))
{
/***** Unfollow user in database *****/
if (asprintf (&Query,"DELETE FROM usr_follow"
" WHERE FollowerCod=%ld AND FollowedCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Usrs.Other.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not unfollow user");
DB_BuildQuery ("DELETE FROM usr_follow"
" WHERE FollowerCod=%ld AND FollowedCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Usrs.Other.UsrDat.UsrCod);
DB_QueryREPLACE_new ("can not unfollow user");
}
Gbl.Alert.Type = Ale_SUCCESS;
}

View File

@ -484,16 +484,13 @@ static void For_DeletePstFromDisabledPstTable (long PstCod)
static void For_InsertPstIntoBannedPstTable (long PstCod)
{
char *Query;
/***** Remove post from banned posts table *****/
if (asprintf (&Query,"REPLACE INTO forum_disabled_post"
" (PstCod,UsrCod,DisableTime)"
" VALUES"
" (%ld,%ld,NOW())",
PstCod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not ban a post of a forum");
DB_BuildQuery ("REPLACE INTO forum_disabled_post"
" (PstCod,UsrCod,DisableTime)"
" VALUES"
" (%ld,%ld,NOW())",
PstCod,Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryREPLACE_new ("can not ban a post of a forum");
}
/*****************************************************************************/
@ -794,17 +791,14 @@ static long For_GetLastPstCod (long ThrCod)
static void For_UpdateThrReadTime (long ThrCod,
time_t CreatTimeUTCOfTheMostRecentPostRead)
{
char *Query;
/***** Insert or replace pair ThrCod-UsrCod in forum_thr_read *****/
if (asprintf (&Query,"REPLACE INTO forum_thr_read"
" (ThrCod,UsrCod,ReadTime)"
" VALUES"
" (%ld,%ld,FROM_UNIXTIME(%ld))",
ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod,
(long) CreatTimeUTCOfTheMostRecentPostRead) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not update the status of reading of a thread of a forum");
DB_BuildQuery ("REPLACE INTO forum_thr_read"
" (ThrCod,UsrCod,ReadTime)"
" VALUES"
" (%ld,%ld,FROM_UNIXTIME(%ld))",
ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod,
(long) CreatTimeUTCOfTheMostRecentPostRead);
DB_QueryREPLACE_new ("can not update the status of reading of a thread of a forum");
}
/*****************************************************************************/
@ -4443,19 +4437,16 @@ static void For_MoveThrToCurrentForum (long ThrCod)
static void For_InsertThrInClipboard (long ThrCod)
{
char *Query;
/***** Remove expired thread clipboards *****/
For_RemoveExpiredThrsClipboards ();
/***** Add thread to my clipboard *****/
if (asprintf (&Query,"REPLACE INTO forum_thr_clip"
" (ThrCod,UsrCod)"
" VALUES"
" (%ld,%ld)",
ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not add thread to clipboard");
DB_BuildQuery ("REPLACE INTO forum_thr_clip"
" (ThrCod,UsrCod)"
" VALUES"
" (%ld,%ld)",
ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryREPLACE_new ("can not add thread to clipboard");
}
/*****************************************************************************/

View File

@ -1701,18 +1701,15 @@ Inf_InfoSrc_t Inf_ConvertFromStrDBToInfoSrc (const char *StrInfoSrcDB)
static void Inf_SetInfoTxtIntoDB (const char *InfoTxtHTML,const char *InfoTxtMD)
{
char *Query;
/***** Insert or replace info source for a specific type of course information *****/
if (asprintf (&Query,"REPLACE INTO crs_info_txt"
" (CrsCod,InfoType,InfoTxtHTML,InfoTxtMD)"
" VALUES"
" (%ld,'%s','%s','%s')",
DB_BuildQuery ("REPLACE INTO crs_info_txt"
" (CrsCod,InfoType,InfoTxtHTML,InfoTxtMD)"
" VALUES"
" (%ld,'%s','%s','%s')",
Gbl.CurrentCrs.Crs.CrsCod,
Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type],
InfoTxtHTML,InfoTxtMD) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not update info text");
InfoTxtHTML,InfoTxtMD);
DB_QueryREPLACE_new ("can not update info text");
}
/*****************************************************************************/

View File

@ -1491,14 +1491,11 @@ static void Mai_RemoveEmail (struct UsrData *UsrDat)
static void Mai_RemoveEmailFromDB (long UsrCod,const char Email[Cns_MAX_BYTES_EMAIL_ADDRESS + 1])
{
char *Query;
/***** Remove an old email address *****/
if (asprintf (&Query,"DELETE FROM usr_emails"
" WHERE UsrCod=%ld AND E_mail='%s'",
UsrCod,Email) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not remove an old email address");
DB_BuildQuery ("DELETE FROM usr_emails"
" WHERE UsrCod=%ld AND E_mail='%s'",
UsrCod,Email);
DB_QueryREPLACE_new ("can not remove an old email address");
}
/*****************************************************************************/
@ -1653,13 +1650,12 @@ bool Mai_UpdateEmailInDB (const struct UsrData *UsrDat,const char NewEmail[Cns_M
DB_QueryDELETE_free (Query,"can not remove not confirmed email for other users");
/***** Update email in database *****/
if (asprintf (&Query,"REPLACE INTO usr_emails"
" (UsrCod,E_mail,CreatTime)"
" VALUES"
" (%ld,'%s',NOW())",
UsrDat->UsrCod,NewEmail) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not update email");
DB_BuildQuery ("REPLACE INTO usr_emails"
" (UsrCod,E_mail,CreatTime)"
" VALUES"
" (%ld,'%s',NOW())",
UsrDat->UsrCod,NewEmail);
DB_QueryREPLACE_new ("can not update email");
return true; // Successfully updated
}
@ -1788,15 +1784,14 @@ static void Mai_InsertMailKey (const char Email[Cns_MAX_BYTES_EMAIL_ADDRESS + 1]
DB_QueryDELETE_free (Query,"can not remove old pending mail keys");
/***** Insert mail key in database *****/
if (asprintf (&Query,"INSERT INTO pending_emails"
" (UsrCod,E_mail,MailKey,DateAndTime)"
" VALUES"
" (%ld,'%s','%s',NOW())",
Gbl.Usrs.Me.UsrDat.UsrCod,
Email,
MailKey) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not create pending password");
DB_BuildQuery ("INSERT INTO pending_emails"
" (UsrCod,E_mail,MailKey,DateAndTime)"
" VALUES"
" (%ld,'%s','%s',NOW())",
Gbl.Usrs.Me.UsrDat.UsrCod,
Email,
MailKey);
DB_QueryREPLACE_new ("can not create pending password");
}
/*****************************************************************************/

View File

@ -390,7 +390,6 @@ void Net_UpdateMyWebsAndSocialNets (void)
static void Net_GetMyWebsAndSocialNetsFromForm (void)
{
char *Query;
Net_WebsAndSocialNetworks_t Web;
char URL[Cns_MAX_BYTES_WWW + 1];
@ -406,24 +405,22 @@ static void Net_GetMyWebsAndSocialNetsFromForm (void)
if (URL[0])
{
/***** Insert or replace web / social network *****/
if (asprintf (&Query,"REPLACE INTO usr_webs"
" (UsrCod,Web,URL)"
" VALUES"
" (%ld,'%s','%s')",
Gbl.Usrs.Me.UsrDat.UsrCod,
Net_WebsAndSocialNetworksDB[Web],
URL) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not update user's web / social network");
DB_BuildQuery ("REPLACE INTO usr_webs"
" (UsrCod,Web,URL)"
" VALUES"
" (%ld,'%s','%s')",
Gbl.Usrs.Me.UsrDat.UsrCod,
Net_WebsAndSocialNetworksDB[Web],
URL);
DB_QueryREPLACE_new ("can not update user's web / social network");
}
else
{
/***** Remove web / social network *****/
if (asprintf (&Query,"DELETE FROM usr_webs WHERE UsrCod=%ld AND Web='%s'",
Gbl.Usrs.Me.UsrDat.UsrCod,
Net_WebsAndSocialNetworksDB[Web]) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not remove user's web / social network");
DB_BuildQuery ("DELETE FROM usr_webs WHERE UsrCod=%ld AND Web='%s'",
Gbl.Usrs.Me.UsrDat.UsrCod,
Net_WebsAndSocialNetworksDB[Web]);
DB_QueryDELETE_new ("can not remove user's web / social network");
}
}

View File

@ -498,14 +498,11 @@ void Nck_RemoveOtherUsrNick (void)
static void Nck_RemoveNicknameFromDB (long UsrCod,const char *Nickname)
{
char *Query;
/***** Remove a nickname *****/
if (asprintf (&Query,"DELETE FROM usr_nicknames"
" WHERE UsrCod=%ld AND Nickname='%s'",
UsrCod,Nickname) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not remove a nickname");
DB_BuildQuery ("DELETE FROM usr_nicknames"
" WHERE UsrCod=%ld AND Nickname='%s'",
UsrCod,Nickname);
DB_QueryREPLACE_new ("can not remove a nickname");
}
/*****************************************************************************/
@ -634,14 +631,11 @@ static void Nck_UpdateUsrNick (struct UsrData *UsrDat)
void Nck_UpdateNickInDB (long UsrCod,const char *NewNickname)
{
char *Query;
/***** Update user's nickname in database *****/
if (asprintf (&Query,"REPLACE INTO usr_nicknames"
" (UsrCod,Nickname,CreatTime)"
" VALUES"
" (%ld,'%s',NOW())",
UsrCod,NewNickname) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not update nickname");
DB_BuildQuery ("REPLACE INTO usr_nicknames"
" (UsrCod,Nickname,CreatTime)"
" VALUES"
" (%ld,'%s',NOW())",
UsrCod,NewNickname);
DB_QueryREPLACE_new ("can not update nickname");
}

View File

@ -1890,7 +1890,6 @@ static void Ntf_UpdateNumNotifSent (long DegCod,long CrsCod,
Ntf_NotifyEvent_t NotifyEvent,
unsigned NumEvents,unsigned NumMails)
{
char *Query;
unsigned CurrentNumEvents;
unsigned CurrentNumMails;
@ -1898,15 +1897,14 @@ static void Ntf_UpdateNumNotifSent (long DegCod,long CrsCod,
Ntf_GetNumNotifSent (DegCod,CrsCod,NotifyEvent,&CurrentNumEvents,&CurrentNumMails);
/***** Update number of users notified *****/
if (asprintf (&Query,"REPLACE INTO sta_notif"
" (DegCod,CrsCod,NotifyEvent,NumEvents,NumMails)"
" VALUES"
" (%ld,%ld,%u,%u,%u)",
DegCod,CrsCod,(unsigned) NotifyEvent,
CurrentNumEvents + NumEvents,
CurrentNumMails + NumMails) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not update the number of sent notifications");
DB_BuildQuery ("REPLACE INTO sta_notif"
" (DegCod,CrsCod,NotifyEvent,NumEvents,NumMails)"
" VALUES"
" (%ld,%ld,%u,%u,%u)",
DegCod,CrsCod,(unsigned) NotifyEvent,
CurrentNumEvents + NumEvents,
CurrentNumMails + NumMails);
DB_QueryREPLACE_new ("can not update the number of sent notifications");
}
/*****************************************************************************/

View File

@ -512,26 +512,22 @@ static void Pwd_CreateANewPassword (char PlainPassword[Pwd_MAX_BYTES_PLAIN_PASSW
void Pwd_SetMyPendingPassword (char PlainPassword[Pwd_MAX_BYTES_PLAIN_PASSWORD + 1])
{
char *Query;
/***** Encrypt my pending password *****/
Cry_EncryptSHA512Base64 (PlainPassword,Gbl.Usrs.Me.PendingPassword);
/***** Remove expired pending passwords from database *****/
if (asprintf (&Query,"DELETE FROM pending_passwd"
" WHERE DateAndTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')",
Cfg_TIME_TO_DELETE_OLD_PENDING_PASSWORDS) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove expired pending passwords");
DB_BuildQuery ("DELETE FROM pending_passwd"
" WHERE DateAndTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')",
Cfg_TIME_TO_DELETE_OLD_PENDING_PASSWORDS);
DB_QueryDELETE_new ("can not remove expired pending passwords");
/***** Update my current password in database *****/
if (asprintf (&Query,"REPLACE INTO pending_passwd"
" (UsrCod,PendingPassword,DateAndTime)"
" VALUES"
" (%ld,'%s',NOW())",
Gbl.Usrs.Me.UsrDat.UsrCod,Gbl.Usrs.Me.PendingPassword) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not create pending password");
DB_BuildQuery ("REPLACE INTO pending_passwd"
" (UsrCod,PendingPassword,DateAndTime)"
" VALUES"
" (%ld,'%s',NOW())",
Gbl.Usrs.Me.UsrDat.UsrCod,Gbl.Usrs.Me.PendingPassword);
DB_QueryREPLACE_new ("can not create pending password");
}
/*****************************************************************************/

View File

@ -2405,17 +2405,15 @@ static void Pho_GetNumStdsInDegree (long DegCod,Usr_Sex_t Sex,int *NumStds,int *
static void Pho_UpdateDegStats (long DegCod,Usr_Sex_t Sex,unsigned NumStds,unsigned NumStdsWithPhoto,long TimeToComputeAvgPhotoInMicroseconds)
{
extern const char *Usr_StringsSexDB[Usr_NUM_SEXS];
char *Query;
if (asprintf (&Query,"REPLACE INTO sta_degrees"
" (DegCod,Sex,NumStds,NumStdsWithPhoto,"
"TimeAvgPhoto,TimeToComputeAvgPhoto)"
" VALUES"
" (%ld,'%s',%u,%u,NOW(),%ld)",
DegCod,Usr_StringsSexDB[Sex],NumStds,NumStdsWithPhoto,
TimeToComputeAvgPhotoInMicroseconds) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not save stats of a degree");
DB_BuildQuery ("REPLACE INTO sta_degrees"
" (DegCod,Sex,NumStds,NumStdsWithPhoto,"
"TimeAvgPhoto,TimeToComputeAvgPhoto)"
" VALUES"
" (%ld,'%s',%u,%u,NOW(),%ld)",
DegCod,Usr_StringsSexDB[Sex],NumStds,NumStdsWithPhoto,
TimeToComputeAvgPhotoInMicroseconds);
DB_QueryREPLACE_new ("can not save stats of a degree");
}
/*****************************************************************************/

View File

@ -175,41 +175,38 @@ void Pre_SetPrefsFromIP (void)
{
extern const char *The_ThemeId[The_NUM_THEMES];
extern const char *Ico_IconSetId[Ico_NUM_ICON_SETS];
char *Query;
/***** Update preferences from current IP in database *****/
if (asprintf (&Query,"REPLACE INTO IP_prefs"
" (IP,UsrCod,LastChange,"
"FirstDayOfWeek,DateFormat,Theme,IconSet,Menu,SideCols)"
" VALUES"
" ('%s',%ld,NOW(),"
"%u,%u,'%s','%s',%u,%u)",
Gbl.IP,Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Prefs.FirstDayOfWeek,
(unsigned) Gbl.Prefs.DateFormat,
The_ThemeId[Gbl.Prefs.Theme],
Ico_IconSetId[Gbl.Prefs.IconSet],
(unsigned) Gbl.Prefs.Menu,
Gbl.Prefs.SideCols) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not store preferences from current IP address");
DB_BuildQuery ("REPLACE INTO IP_prefs"
" (IP,UsrCod,LastChange,"
"FirstDayOfWeek,DateFormat,Theme,IconSet,Menu,SideCols)"
" VALUES"
" ('%s',%ld,NOW(),"
"%u,%u,'%s','%s',%u,%u)",
Gbl.IP,Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Prefs.FirstDayOfWeek,
(unsigned) Gbl.Prefs.DateFormat,
The_ThemeId[Gbl.Prefs.Theme],
Ico_IconSetId[Gbl.Prefs.IconSet],
(unsigned) Gbl.Prefs.Menu,
Gbl.Prefs.SideCols);
DB_QueryREPLACE_new ("can not store preferences from current IP address");
/***** If a user is logged, update its preferences in database for all its IP's *****/
if (Gbl.Usrs.Me.Logged)
{
if (asprintf (&Query,"UPDATE IP_prefs"
" SET FirstDayOfWeek=%u,DateFormat=%u,"
"Theme='%s',IconSet='%s',Menu=%u,SideCols=%u"
" WHERE UsrCod=%ld",
Gbl.Prefs.FirstDayOfWeek,
(unsigned) Gbl.Prefs.DateFormat,
The_ThemeId[Gbl.Prefs.Theme],
Ico_IconSetId[Gbl.Prefs.IconSet],
(unsigned) Gbl.Prefs.Menu,
Gbl.Prefs.SideCols,
Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not update your preferences");
DB_BuildQuery ("UPDATE IP_prefs"
" SET FirstDayOfWeek=%u,DateFormat=%u,"
"Theme='%s',IconSet='%s',Menu=%u,SideCols=%u"
" WHERE UsrCod=%ld",
Gbl.Prefs.FirstDayOfWeek,
(unsigned) Gbl.Prefs.DateFormat,
The_ThemeId[Gbl.Prefs.Theme],
Ico_IconSetId[Gbl.Prefs.IconSet],
(unsigned) Gbl.Prefs.Menu,
Gbl.Prefs.SideCols,
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryUPDATE_new ("can not update your preferences");
}
}

View File

@ -1949,7 +1949,6 @@ static void Prj_AddUsrToProject (Prj_RoleInProject_t RoleInProject)
long PrjCod;
struct ListUsrCods ListUsrCods;
unsigned NumUsr;
char *Query;
bool ItsMe;
/***** Get project code *****/
@ -1971,14 +1970,13 @@ static void Prj_AddUsrToProject (Prj_RoleInProject_t RoleInProject)
Usr_GetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat);
/* Add user to project */
if (asprintf (&Query,"REPLACE INTO prj_usr"
" (PrjCod,RoleInProject,UsrCod)"
" VALUES"
" (%ld,%u,%ld)",
PrjCod,(unsigned) RoleInProject,
Gbl.Usrs.Other.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not add user to project");
DB_BuildQuery ("REPLACE INTO prj_usr"
" (PrjCod,RoleInProject,UsrCod)"
" VALUES"
" (%ld,%u,%ld)",
PrjCod,(unsigned) RoleInProject,
Gbl.Usrs.Other.UsrDat.UsrCod);
DB_QueryREPLACE_new ("can not add user to project");
/***** Flush cache *****/
ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod);