Version 18.8.17

This commit is contained in:
Antonio Cañas Vargas 2018-10-28 21:55:31 +01:00
parent 9d7b46ffc3
commit e2472291d3
21 changed files with 250 additions and 423 deletions

View File

@ -355,10 +355,11 @@ En OpenSWAD:
ps2pdf source.ps destination.pdf
*/
#define Log_PLATFORM_VERSION "SWAD 18.8.16 (2018-10-28)"
#define Log_PLATFORM_VERSION "SWAD 18.8.17 (2018-10-28)"
#define CSS_FILE "swad18.4.css"
#define JS_FILE "swad17.17.1.js"
/*
Version 18.8.17: Oct 28, 2018 Some asprintf for database queries changed by internal function. (236116 lines)
Version 18.8.16: Oct 28, 2018 Some asprintf for database queries changed by internal function. (236263 lines)
Version 18.8.15: Oct 28, 2018 Some asprintf for database queries changed by internal function. (236425 lines)
Version 18.8.14: Oct 28, 2018 Some asprintf for database queries changed by internal function. (236493 lines)

View File

@ -3331,17 +3331,6 @@ void DB_QueryDELETE_new (const char *MsgError)
DB_ExitOnMySQLError (MsgError);
}
void DB_QueryDELETE_free (const char *Query,const char *MsgError)
{
int Result;
/***** Query database *****/
Result = mysql_query (&Gbl.mysql,Query); // Returns 0 on success
free ((void *) Query);
if (Result)
DB_ExitOnMySQLError (MsgError);
}
void DB_QueryDELETE (const char *Query,const char *MsgError)
{
/***** Query database *****/

View File

@ -58,7 +58,6 @@ void DB_QueryUPDATE_new (const char *MsgError);
void DB_QueryUPDATE (const char *Query,const char *MsgError);
void DB_QueryDELETE_new (const char *MsgError);
void DB_QueryDELETE_free (const char *Query,const char *MsgError);
void DB_QueryDELETE (const char *Query,const char *MsgError);
void DB_Query_free (const char *Query,const char *MsgError);

View File

@ -1203,11 +1203,8 @@ void Fol_GetNotifFollower (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
void Fol_RemoveUsrFromUsrFollow (long UsrCod)
{
char *Query;
if (asprintf (&Query,"DELETE FROM usr_follow"
" WHERE FollowerCod=%ld OR FollowedCod=%ld",
UsrCod,UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove user from followers and followed");
DB_BuildQuery ("DELETE FROM usr_follow"
" WHERE FollowerCod=%ld OR FollowedCod=%ld",
UsrCod,UsrCod);
DB_QueryDELETE_new ("can not remove user from followers and followed");
}

View File

@ -469,13 +469,9 @@ static bool For_GetIfPstIsEnabled (long PstCod)
static void For_DeletePstFromDisabledPstTable (long PstCod)
{
char *Query;
/***** Remove post from disabled posts table *****/
if (asprintf (&Query,"DELETE FROM forum_disabled_post WHERE PstCod=%ld",
PstCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not unban a post of a forum");
DB_BuildQuery ("DELETE FROM forum_disabled_post WHERE PstCod=%ld",PstCod);
DB_QueryDELETE_new ("can not unban a post of a forum");
}
/*****************************************************************************/
@ -533,7 +529,6 @@ static long For_InsertForumPst (long ThrCod,long UsrCod,
static bool For_RemoveForumPst (long PstCod,struct Image *Image)
{
char *Query;
long ThrCod;
bool ThreadDeleted = false;
@ -548,10 +543,8 @@ static bool For_RemoveForumPst (long PstCod,struct Image *Image)
}
/***** Delete post from forum post table *****/
if (asprintf (&Query,"DELETE FROM forum_post WHERE PstCod=%ld",
PstCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove a post from a forum");
DB_BuildQuery ("DELETE FROM forum_post WHERE PstCod=%ld",PstCod);
DB_QueryDELETE_new ("can not remove a post from a forum");
/***** Delete the post from the table of disabled forum posts *****/
For_DeletePstFromDisabledPstTable (PstCod);
@ -615,8 +608,6 @@ static long For_InsertForumThread (long FirstPstCod)
static void For_RemoveThreadOnly (long ThrCod)
{
char *Query;
/***** Indicate that this thread has not been read by anyone *****/
For_DeleteThrFromReadThrs (ThrCod);
@ -624,10 +615,8 @@ static void For_RemoveThreadOnly (long ThrCod)
For_RemoveThrCodFromThrClipboard (ThrCod);
/***** Delete thread from forum thread table *****/
if (asprintf (&Query,"DELETE FROM forum_thread WHERE ThrCod=%ld",
ThrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove a thread from a forum");
DB_BuildQuery ("DELETE FROM forum_thread WHERE ThrCod=%ld",ThrCod);
DB_QueryDELETE_new ("can not remove a thread from a forum");
}
/*****************************************************************************/
@ -636,22 +625,17 @@ static void For_RemoveThreadOnly (long ThrCod)
static void For_RemoveThreadAndItsPsts (long ThrCod)
{
char *Query;
/***** Delete banned posts in thread *****/
if (asprintf (&Query,"DELETE forum_disabled_post"
" FROM forum_post,forum_disabled_post"
" WHERE forum_post.ThrCod=%ld"
" AND forum_post.PstCod=forum_disabled_post.PstCod",
ThrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not unban the posts of a thread of a forum");
DB_BuildQuery ("DELETE forum_disabled_post"
" FROM forum_post,forum_disabled_post"
" WHERE forum_post.ThrCod=%ld"
" AND forum_post.PstCod=forum_disabled_post.PstCod",
ThrCod);
DB_QueryDELETE_new ("can not unban the posts of a thread of a forum");
/***** Delete thread posts *****/
if (asprintf (&Query,"DELETE FROM forum_post WHERE ThrCod=%ld",
ThrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove the posts of a thread of a forum");
DB_BuildQuery ("DELETE FROM forum_post WHERE ThrCod=%ld",ThrCod);
DB_QueryDELETE_new ("can not remove the posts of a thread of a forum");
/***** Delete thread from forum thread table *****/
For_RemoveThreadOnly (ThrCod);
@ -912,13 +896,9 @@ static time_t For_GetThrReadTime (long ThrCod)
static void For_DeleteThrFromReadThrs (long ThrCod)
{
char *Query;
/***** Delete pairs ThrCod-UsrCod in forum_thr_read for a thread *****/
if (asprintf (&Query,"DELETE FROM forum_thr_read WHERE ThrCod=%ld",
ThrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove the status of reading of a thread of a forum");
DB_BuildQuery ("DELETE FROM forum_thr_read WHERE ThrCod=%ld",ThrCod);
DB_QueryDELETE_new ("can not remove the status of reading of a thread of a forum");
}
/*****************************************************************************/
@ -927,13 +907,9 @@ static void For_DeleteThrFromReadThrs (long ThrCod)
void For_RemoveUsrFromReadThrs (long UsrCod)
{
char *Query;
/***** Delete pairs ThrCod-UsrCod in forum_thr_read for a user *****/
if (asprintf (&Query,"DELETE FROM forum_thr_read WHERE UsrCod=%ld",
UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove the status of reading by a user of all the threads of a forum");
DB_BuildQuery ("DELETE FROM forum_thr_read WHERE UsrCod=%ld",UsrCod);
DB_QueryDELETE_new ("can not remove the status of reading by a user of all the threads of a forum");
}
/*****************************************************************************/
@ -4439,14 +4415,11 @@ static void For_InsertThrInClipboard (long ThrCod)
static void For_RemoveExpiredThrsClipboards (void)
{
char *Query;
/***** Remove all expired clipboards *****/
if (asprintf (&Query,"DELETE LOW_PRIORITY FROM forum_thr_clip"
" WHERE TimeInsert<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')",
Cfg_TIME_TO_DELETE_THREAD_CLIPBOARD) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove old threads from clipboards");
DB_BuildQuery ("DELETE LOW_PRIORITY FROM forum_thr_clip"
" WHERE TimeInsert<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')",
Cfg_TIME_TO_DELETE_THREAD_CLIPBOARD);
DB_QueryDELETE_new ("can not remove old threads from clipboards");
}
/*****************************************************************************/
@ -4455,13 +4428,9 @@ static void For_RemoveExpiredThrsClipboards (void)
static void For_RemoveThrCodFromThrClipboard (long ThrCod)
{
char *Query;
/***** Remove thread from thread clipboard *****/
if (asprintf (&Query,"DELETE FROM forum_thr_clip WHERE ThrCod=%ld",
ThrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove a thread from clipboard");
DB_BuildQuery ("DELETE FROM forum_thr_clip WHERE ThrCod=%ld",ThrCod);
DB_QueryDELETE_new ("can not remove a thread from clipboard");
}
/*****************************************************************************/
@ -4470,13 +4439,9 @@ static void For_RemoveThrCodFromThrClipboard (long ThrCod)
void For_RemoveUsrFromThrClipboard (long UsrCod)
{
char *Query;
/***** Remove clipboard of specified user *****/
if (asprintf (&Query,"DELETE FROM forum_thr_clip WHERE UsrCod=%ld",
UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove a thread from the clipboard of a user");
DB_BuildQuery ("DELETE FROM forum_thr_clip WHERE UsrCod=%ld",UsrCod);
DB_QueryDELETE_new ("can not remove a thread from the clipboard of a user");
}
/*****************************************************************************/
@ -4499,64 +4464,59 @@ void For_RemoveForums (Sco_Scope_t Scope,long ForumLocation)
{For_FORUM_DEGREE_USRS,For_FORUM_DEGREE_TCHS}, // Sco_SCOPE_DEG
{For_FORUM_COURSE_USRS,For_FORUM_COURSE_TCHS}, // Sco_SCOPE_CRS
};
char *Query;
/***** Remove disabled posts *****/
if (asprintf (&Query,"DELETE FROM forum_disabled_post"
" USING forum_thread,forum_post,forum_disabled_post"
" WHERE"
" (forum_thread.ForumType=%u"
" OR"
" forum_thread.ForumType=%u)"
" AND forum_thread.Location=%ld"
" AND forum_thread.ThrCod=forum_post.ThrCod"
" AND forum_post.PstCod=forum_disabled_post.PstCod",
ForumType[Scope].Usrs,
ForumType[Scope].Tchs,
ForumLocation) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove the disabled posts in forums");
DB_BuildQuery ("DELETE FROM forum_disabled_post"
" USING forum_thread,forum_post,forum_disabled_post"
" WHERE"
" (forum_thread.ForumType=%u"
" OR"
" forum_thread.ForumType=%u)"
" AND forum_thread.Location=%ld"
" AND forum_thread.ThrCod=forum_post.ThrCod"
" AND forum_post.PstCod=forum_disabled_post.PstCod",
ForumType[Scope].Usrs,
ForumType[Scope].Tchs,
ForumLocation);
DB_QueryDELETE_new ("can not remove the disabled posts in forums");
/***** Remove posts *****/
if (asprintf (&Query,"DELETE FROM forum_post"
" USING forum_thread,forum_post"
" WHERE"
" (forum_thread.ForumType=%u"
" OR"
" forum_thread.ForumType=%u)"
" AND forum_thread.Location=%ld"
" AND forum_thread.ThrCod=forum_post.ThrCod",
ForumType[Scope].Usrs,
ForumType[Scope].Tchs,
ForumLocation) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove posts in forums");
DB_BuildQuery ("DELETE FROM forum_post"
" USING forum_thread,forum_post"
" WHERE"
" (forum_thread.ForumType=%u"
" OR"
" forum_thread.ForumType=%u)"
" AND forum_thread.Location=%ld"
" AND forum_thread.ThrCod=forum_post.ThrCod",
ForumType[Scope].Usrs,
ForumType[Scope].Tchs,
ForumLocation);
DB_QueryDELETE_new ("can not remove posts in forums");
/***** Remove threads read *****/
if (asprintf (&Query,"DELETE FROM forum_thr_read"
" USING forum_thread,forum_thr_read"
" WHERE"
" (forum_thread.ForumType=%u"
" OR"
" forum_thread.ForumType=%u)"
" AND forum_thread.Location=%ld"
" AND forum_thread.ThrCod=forum_thr_read.ThrCod",
ForumType[Scope].Usrs,
ForumType[Scope].Tchs,
ForumLocation) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove read threads in forums");
DB_BuildQuery ("DELETE FROM forum_thr_read"
" USING forum_thread,forum_thr_read"
" WHERE"
" (forum_thread.ForumType=%u"
" OR"
" forum_thread.ForumType=%u)"
" AND forum_thread.Location=%ld"
" AND forum_thread.ThrCod=forum_thr_read.ThrCod",
ForumType[Scope].Usrs,
ForumType[Scope].Tchs,
ForumLocation);
DB_QueryDELETE_new ("can not remove read threads in forums");
/***** Remove threads *****/
if (asprintf (&Query,"DELETE FROM forum_thread"
" WHERE"
" (forum_thread.ForumType=%u"
" OR"
" forum_thread.ForumType=%u)"
" AND Location=%ld",
ForumType[Scope].Usrs,
ForumType[Scope].Tchs,
ForumLocation) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove threads in forums");
DB_BuildQuery ("DELETE FROM forum_thread"
" WHERE"
" (forum_thread.ForumType=%u"
" OR"
" forum_thread.ForumType=%u)"
" AND Location=%ld",
ForumType[Scope].Usrs,
ForumType[Scope].Tchs,
ForumLocation);
DB_QueryDELETE_new ("can not remove threads in forums");
}

View File

@ -1512,7 +1512,6 @@ void Gam_AskRemGame (void)
void Gam_RemoveGame (void)
{
extern const char *Txt_Game_X_removed;
char *Query;
struct Game Game;
/***** Get game code *****/
@ -1525,26 +1524,19 @@ void Gam_RemoveGame (void)
Lay_ShowErrorAndExit ("You can not remove this game.");
/***** Remove all the users in this game *****/
if (asprintf (&Query,"DELETE FROM gam_users WHERE GamCod=%ld",
Game.GamCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove users who are answered a game");
DB_BuildQuery ("DELETE FROM gam_users WHERE GamCod=%ld",Game.GamCod);
DB_QueryDELETE_new ("can not remove users who are answered a game");
/***** Remove all the questions in this game *****/
if (asprintf (&Query,"DELETE FROM gam_questions"
" WHERE GamCod=%ld",
Game.GamCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove questions of a game");
DB_BuildQuery ("DELETE FROM gam_questions WHERE GamCod=%ld",Game.GamCod);
DB_QueryDELETE_new ("can not remove questions of a game");
/***** Remove all the groups of this game *****/
Gam_RemoveAllTheGrpsAssociatedToAndGame (Game.GamCod);
/***** Remove game *****/
if (asprintf (&Query,"DELETE FROM games WHERE GamCod=%ld",
Game.GamCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove game");
DB_BuildQuery ("DELETE FROM games WHERE GamCod=%ld",Game.GamCod);
DB_QueryDELETE_new ("can not remove game");
/***** Write message to show the change made *****/
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
@ -1614,7 +1606,6 @@ static void Gam_PutButtonToResetGame (void)
void Gam_ResetGame (void)
{
extern const char *Txt_Game_X_reset;
char *Query;
struct Game Game;
/***** Get game code *****/
@ -1627,10 +1618,8 @@ void Gam_ResetGame (void)
Lay_ShowErrorAndExit ("You can not reset this game.");
/***** Remove all the users in this game *****/
if (asprintf (&Query,"DELETE FROM gam_users WHERE GamCod=%ld",
Game.GamCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove users who are answered a game");
DB_BuildQuery ("DELETE FROM gam_users WHERE GamCod=%ld",Game.GamCod);
DB_QueryDELETE_new ("can not remove users who are answered a game");
/***** Reset all the answers in this game *****/
DB_BuildQuery ("UPDATE gam_answers,gam_questions SET gam_answers.NumUsrs=0"
@ -2283,13 +2272,9 @@ bool Gam_CheckIfGamIsAssociatedToGrp (long GamCod,long GrpCod)
static void Gam_RemoveAllTheGrpsAssociatedToAndGame (long GamCod)
{
char *Query;
/***** Remove groups of the game *****/
if (asprintf (&Query,"DELETE FROM gam_grp WHERE GamCod=%ld",
GamCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove the groups associated to a game");
DB_BuildQuery ("DELETE FROM gam_grp WHERE GamCod=%ld",GamCod);
DB_QueryDELETE_new ("can not remove the groups associated to a game");
}
/*****************************************************************************/
@ -2298,14 +2283,10 @@ static void Gam_RemoveAllTheGrpsAssociatedToAndGame (long GamCod)
void Gam_RemoveGroup (long GrpCod)
{
char *Query;
/***** Remove group from all the games *****/
if (asprintf (&Query,"DELETE FROM gam_grp WHERE GrpCod=%ld",
GrpCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove group"
" from the associations between games and groups");
DB_BuildQuery ("DELETE FROM gam_grp WHERE GrpCod=%ld",GrpCod);
DB_QueryDELETE_new ("can not remove group"
" from the associations between games and groups");
}
/*****************************************************************************/
@ -2314,16 +2295,13 @@ void Gam_RemoveGroup (long GrpCod)
void Gam_RemoveGroupsOfType (long GrpTypCod)
{
char *Query;
/***** Remove group from all the games *****/
if (asprintf (&Query,"DELETE FROM gam_grp USING crs_grp,gam_grp"
" WHERE crs_grp.GrpTypCod=%ld"
" AND crs_grp.GrpCod=gam_grp.GrpCod",
GrpTypCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove groups of a type"
" from the associations between games and groups");
DB_BuildQuery ("DELETE FROM gam_grp USING crs_grp,gam_grp"
" WHERE crs_grp.GrpTypCod=%ld"
" AND crs_grp.GrpCod=gam_grp.GrpCod",
GrpTypCod);
DB_QueryDELETE_new ("can not remove groups of a type"
" from the associations between games and groups");
}
/*****************************************************************************/
@ -2423,53 +2401,47 @@ static void Gam_GetAndWriteNamesOfGrpsAssociatedToGame (struct Game *Game)
void Gam_RemoveGames (Sco_Scope_t Scope,long Cod)
{
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
char *Query;
/***** Remove all the users in course games *****/
if (asprintf (&Query,"DELETE FROM gam_users"
" USING games,gam_users"
" WHERE games.Scope='%s' AND games.Cod=%ld"
" AND games.GamCod=gam_users.GamCod",
Sco_ScopeDB[Scope],Cod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove users"
" who had answered games in a place on the hierarchy");
DB_BuildQuery ("DELETE FROM gam_users"
" USING games,gam_users"
" WHERE games.Scope='%s' AND games.Cod=%ld"
" AND games.GamCod=gam_users.GamCod",
Sco_ScopeDB[Scope],Cod);
DB_QueryDELETE_new ("can not remove users"
" who had answered games in a place on the hierarchy");
/***** Remove all the answers in course games *****/
if (asprintf (&Query,"DELETE FROM gam_answers"
" USING games,gam_questions,gam_answers"
" WHERE games.Scope='%s' AND games.Cod=%ld"
" AND games.GamCod=gam_questions.GamCod"
" AND gam_questions.QstCod=gam_answers.QstCod",
Sco_ScopeDB[Scope],Cod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove answers of games in a place on the hierarchy");
DB_BuildQuery ("DELETE FROM gam_answers"
" USING games,gam_questions,gam_answers"
" WHERE games.Scope='%s' AND games.Cod=%ld"
" AND games.GamCod=gam_questions.GamCod"
" AND gam_questions.QstCod=gam_answers.QstCod",
Sco_ScopeDB[Scope],Cod);
DB_QueryDELETE_new ("can not remove answers of games in a place on the hierarchy");
/***** Remove all the questions in course games *****/
if (asprintf (&Query,"DELETE FROM gam_questions"
" USING games,gam_questions"
" WHERE games.Scope='%s' AND games.Cod=%ld"
" AND games.GamCod=gam_questions.GamCod",
Sco_ScopeDB[Scope],Cod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove questions of games in a place on the hierarchy");
DB_BuildQuery ("DELETE FROM gam_questions"
" USING games,gam_questions"
" WHERE games.Scope='%s' AND games.Cod=%ld"
" AND games.GamCod=gam_questions.GamCod",
Sco_ScopeDB[Scope],Cod);
DB_QueryDELETE_new ("can not remove questions of games in a place on the hierarchy");
/***** Remove groups *****/
if (asprintf (&Query,"DELETE FROM gam_grp"
" USING games,gam_grp"
" WHERE games.Scope='%s' AND games.Cod=%ld"
" AND games.GamCod=gam_grp.GamCod",
Sco_ScopeDB[Scope],Cod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove all the groups"
" associated to games of a course");
DB_BuildQuery ("DELETE FROM gam_grp"
" USING games,gam_grp"
" WHERE games.Scope='%s' AND games.Cod=%ld"
" AND games.GamCod=gam_grp.GamCod",
Sco_ScopeDB[Scope],Cod);
DB_QueryDELETE_new ("can not remove all the groups"
" associated to games of a course");
/***** Remove course games *****/
if (asprintf (&Query,"DELETE FROM games"
" WHERE Scope='%s' AND Cod=%ld",
Sco_ScopeDB[Scope],Cod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove all the games in a place on the hierarchy");
DB_BuildQuery ("DELETE FROM games"
" WHERE Scope='%s' AND Cod=%ld",
Sco_ScopeDB[Scope],Cod);
DB_QueryDELETE_new ("can not remove all the games in a place on the hierarchy");
}
/*****************************************************************************/
@ -2575,13 +2547,9 @@ static unsigned Gam_GetParamQstInd (void)
static void Gam_RemAnswersOfAQuestion (long QstCod)
{
char *Query;
/***** Remove answers *****/
if (asprintf (&Query,"DELETE FROM gam_answers WHERE QstCod=%ld",
QstCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove the answers of a question");
DB_BuildQuery ("DELETE FROM gam_answers WHERE QstCod=%ld",QstCod);
DB_QueryDELETE_new ("can not remove the answers of a question");
}
/*****************************************************************************/

View File

@ -1210,18 +1210,16 @@ unsigned Grp_RemoveUsrFromGroups (struct UsrData *UsrDat,struct ListCodGrps *Lst
void Grp_RemUsrFromAllGrpsInCrs (long UsrCod,long CrsCod)
{
char *Query;
bool ItsMe = Usr_ItsMe (UsrCod);
/***** Remove user from all the groups of the course *****/
if (asprintf (&Query,"DELETE FROM crs_grp_usr"
" WHERE UsrCod=%ld AND GrpCod IN"
" (SELECT crs_grp.GrpCod FROM crs_grp_types,crs_grp"
" WHERE crs_grp_types.CrsCod=%ld"
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod)",
UsrCod,CrsCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove a user from all groups of a course");
DB_BuildQuery ("DELETE FROM crs_grp_usr"
" WHERE UsrCod=%ld AND GrpCod IN"
" (SELECT crs_grp.GrpCod FROM crs_grp_types,crs_grp"
" WHERE crs_grp_types.CrsCod=%ld"
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod)",
UsrCod,CrsCod);
DB_QueryDELETE_new ("can not remove a user from all groups of a course");
/***** Flush caches *****/
Grp_FlushCacheUsrSharesAnyOfMyGrpsInCurrentCrs ();
@ -1235,14 +1233,11 @@ void Grp_RemUsrFromAllGrpsInCrs (long UsrCod,long CrsCod)
void Grp_RemUsrFromAllGrps (long UsrCod)
{
char *Query;
bool ItsMe = Usr_ItsMe (UsrCod);
/***** Remove user from all groups *****/
if (asprintf (&Query,"DELETE FROM crs_grp_usr WHERE UsrCod=%ld",
UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove a user from the groups he/she belongs to");
DB_BuildQuery ("DELETE FROM crs_grp_usr WHERE UsrCod=%ld",UsrCod);
DB_QueryDELETE_new ("can not remove a user from the groups he/she belongs to");
/***** Flush caches *****/
Grp_FlushCacheUsrSharesAnyOfMyGrpsInCurrentCrs ();
@ -1256,15 +1251,13 @@ void Grp_RemUsrFromAllGrps (long UsrCod)
static void Grp_RemoveUsrFromGroup (long UsrCod,long GrpCod)
{
char *Query;
bool ItsMe = Usr_ItsMe (UsrCod);
/***** Remove user from group *****/
if (asprintf (&Query,"DELETE FROM crs_grp_usr"
" WHERE GrpCod=%ld AND UsrCod=%ld",
GrpCod,UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove a user from a group");
DB_BuildQuery ("DELETE FROM crs_grp_usr"
" WHERE GrpCod=%ld AND UsrCod=%ld",
GrpCod,UsrCod);
DB_QueryDELETE_new ("can not remove a user from a group");
/***** Flush caches *****/
Grp_FlushCacheUsrSharesAnyOfMyGrpsInCurrentCrs ();
@ -4018,7 +4011,6 @@ void Grp_RemoveGroup (void)
static void Grp_RemoveGroupTypeCompletely (void)
{
extern const char *Txt_Type_of_group_X_removed;
char *Query;
/***** Get name and type of the group from database *****/
Grp_GetDataOfGroupTypeByCod (&Gbl.CurrentCrs.Grps.GrpTyp);
@ -4043,23 +4035,20 @@ static void Grp_RemoveGroupTypeCompletely (void)
DB_QueryUPDATE_new ("can not update all groups of a type in course timetable");
/***** Remove all the students in groups of this type *****/
if (asprintf (&Query,"DELETE FROM crs_grp_usr WHERE GrpCod IN"
" (SELECT GrpCod FROM crs_grp WHERE GrpTypCod=%ld)",
Gbl.CurrentCrs.Grps.GrpTyp.GrpTypCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove users from all groups of a type");
DB_BuildQuery ("DELETE FROM crs_grp_usr WHERE GrpCod IN"
" (SELECT GrpCod FROM crs_grp WHERE GrpTypCod=%ld)",
Gbl.CurrentCrs.Grps.GrpTyp.GrpTypCod);
DB_QueryDELETE_new ("can not remove users from all groups of a type");
/***** Remove all the groups of this type *****/
if (asprintf (&Query,"DELETE FROM crs_grp WHERE GrpTypCod=%ld",
Gbl.CurrentCrs.Grps.GrpTyp.GrpTypCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove groups of a type");
DB_BuildQuery ("DELETE FROM crs_grp WHERE GrpTypCod=%ld",
Gbl.CurrentCrs.Grps.GrpTyp.GrpTypCod);
DB_QueryDELETE_new ("can not remove groups of a type");
/***** Remove the group type *****/
if (asprintf (&Query,"DELETE FROM crs_grp_types WHERE GrpTypCod=%ld",
Gbl.CurrentCrs.Grps.GrpTyp.GrpTypCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove a type of group");
DB_BuildQuery ("DELETE FROM crs_grp_types WHERE GrpTypCod=%ld",
Gbl.CurrentCrs.Grps.GrpTyp.GrpTypCod);
DB_QueryDELETE_new ("can not remove a type of group");
/***** Create message to show the change made *****/
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
@ -4079,7 +4068,6 @@ static void Grp_RemoveGroupCompletely (void)
{
extern const char *Txt_Group_X_removed;
struct GroupData GrpDat;
char *Query;
/***** Get name and type of the group from database *****/
GrpDat.GrpCod = Gbl.CurrentCrs.Grps.GrpCod;
@ -4103,16 +4091,14 @@ static void Grp_RemoveGroupCompletely (void)
DB_QueryUPDATE_new ("can not update a group in course timetable");
/***** Remove all the students in this group *****/
if (asprintf (&Query,"DELETE FROM crs_grp_usr WHERE GrpCod=%ld",
Gbl.CurrentCrs.Grps.GrpCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove users from a group");
DB_BuildQuery ("DELETE FROM crs_grp_usr WHERE GrpCod=%ld",
Gbl.CurrentCrs.Grps.GrpCod);
DB_QueryDELETE_new ("can not remove users from a group");
/***** Remove the group *****/
if (asprintf (&Query,"DELETE FROM crs_grp WHERE GrpCod=%ld",
Gbl.CurrentCrs.Grps.GrpCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove a group");
DB_BuildQuery ("DELETE FROM crs_grp WHERE GrpCod=%ld",
Gbl.CurrentCrs.Grps.GrpCod);
DB_QueryDELETE_new ("can not remove a group");
/***** Create message to show the change made *****/
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),

View File

@ -639,7 +639,6 @@ long Hld_GetParamHldCod (void)
void Hld_RemoveHoliday1 (void)
{
extern const char *Txt_Holiday_X_removed;
char *Query;
struct Holiday Hld;
/***** Get holiday code *****/
@ -650,10 +649,8 @@ void Hld_RemoveHoliday1 (void)
Hld_GetDataOfHolidayByCod (&Hld);
/***** Remove holiday *****/
if (asprintf (&Query,"DELETE FROM holidays WHERE HldCod=%ld",
Hld.HldCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove a holiday");
DB_BuildQuery ("DELETE FROM holidays WHERE HldCod=%ld",Hld.HldCod);
DB_QueryDELETE_new ("can not remove a holiday");
/***** Write message to show the change made *****/
Gbl.Alert.Type = Ale_SUCCESS;

View File

@ -741,14 +741,11 @@ static void Inf_SetIHaveReadIntoDB (bool IHaveRead)
void Inf_RemoveUsrFromCrsInfoRead (long UsrCod,long CrsCod)
{
char *Query;
/***** Remove user's status about reading of course information *****/
if (asprintf (&Query,"DELETE FROM crs_info_read"
" WHERE UsrCod=%ld AND CrsCod=%ld",
UsrCod,CrsCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not set that I have not read course info");
DB_BuildQuery ("DELETE FROM crs_info_read"
" WHERE UsrCod=%ld AND CrsCod=%ld",
UsrCod,CrsCod);
DB_QueryDELETE_new ("can not set that I have not read course info");
}
/*****************************************************************************/

View File

@ -1685,7 +1685,6 @@ void Ins_RemoveInstitution (void)
{
extern const char *Txt_To_remove_an_institution_you_must_first_remove_all_centres_and_users_in_the_institution;
extern const char *Txt_Institution_X_removed;
char *Query;
struct Instit Ins;
char PathIns[PATH_MAX + 1];
@ -1722,10 +1721,8 @@ void Ins_RemoveInstitution (void)
Fil_RemoveTree (PathIns);
/***** Remove institution *****/
if (asprintf (&Query,"DELETE FROM institutions WHERE InsCod=%ld",
Ins.InsCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove an institution");
DB_BuildQuery ("DELETE FROM institutions WHERE InsCod=%ld",Ins.InsCod);
DB_QueryDELETE_new ("can not remove an institution");
/***** Flush caches *****/
Ins_FlushCacheShortNameOfInstitution ();

View File

@ -487,7 +487,6 @@ long Lnk_GetParamLnkCod (void)
void Lnk_RemoveLink (void)
{
extern const char *Txt_Link_X_removed;
char *Query;
struct Link Lnk;
/***** Get link code *****/
@ -498,10 +497,8 @@ void Lnk_RemoveLink (void)
Lnk_GetDataOfLinkByCod (&Lnk);
/***** Remove link *****/
if (asprintf (&Query,"DELETE FROM links WHERE LnkCod=%ld",
Lnk.LnkCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove an institutional link");
DB_BuildQuery ("DELETE FROM links WHERE LnkCod=%ld",Lnk.LnkCod);
DB_QueryDELETE_new ("can not remove an institutional link");
/***** Write message to show the change made *****/
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),

View File

@ -543,7 +543,6 @@ long Mai_GetParamMaiCod (void)
void Mai_RemoveMailDomain (void)
{
extern const char *Txt_Email_domain_X_removed;
char *Query;
struct Mail Mai;
/***** Get mail code *****/
@ -554,10 +553,8 @@ void Mai_RemoveMailDomain (void)
Mai_GetDataOfMailDomainByCod (&Mai);
/***** Remove mail *****/
if (asprintf (&Query,"DELETE FROM mail_domains WHERE MaiCod=%ld",
Mai.MaiCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove a mail domain");
DB_BuildQuery ("DELETE FROM mail_domains WHERE MaiCod=%ld",Mai.MaiCod);
DB_QueryDELETE_new ("can not remove a mail domain");
/***** Write message to show the change made *****/
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
@ -1622,8 +1619,6 @@ static void Mai_NewUsrEmail (struct UsrData *UsrDat,bool ItsMe)
bool Mai_UpdateEmailInDB (const struct UsrData *UsrDat,const char NewEmail[Cns_MAX_BYTES_EMAIL_ADDRESS + 1])
{
char *Query;
/***** Check if the new email matches any of the confirmed emails of other users *****/
DB_BuildQuery ("SELECT COUNT(*) FROM usr_emails"
" WHERE E_mail='%s' AND Confirmed='Y'"
@ -1633,18 +1628,16 @@ bool Mai_UpdateEmailInDB (const struct UsrData *UsrDat,const char NewEmail[Cns_M
return false; // Don't update
/***** Delete email (not confirmed) for other users *****/
if (asprintf (&Query,"DELETE FROM pending_emails"
" WHERE E_mail='%s' AND UsrCod<>%ld",
NewEmail,UsrDat->UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove pending email for other users");
DB_BuildQuery ("DELETE FROM pending_emails"
" WHERE E_mail='%s' AND UsrCod<>%ld",
NewEmail,UsrDat->UsrCod);
DB_QueryDELETE_new ("can not remove pending email for other users");
if (asprintf (&Query,"DELETE FROM usr_emails"
" WHERE E_mail='%s' AND Confirmed='N'"
" AND UsrCod<>%ld",
NewEmail,UsrDat->UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove not confirmed email for other users");
DB_BuildQuery ("DELETE FROM usr_emails"
" WHERE E_mail='%s' AND Confirmed='N'"
" AND UsrCod<>%ld",
NewEmail,UsrDat->UsrCod);
DB_QueryDELETE_new ("can not remove not confirmed email for other users");
/***** Update email in database *****/
DB_BuildQuery ("REPLACE INTO usr_emails"
@ -1771,14 +1764,11 @@ bool Mai_SendMailMsgToConfirmEmail (void)
static void Mai_InsertMailKey (const char Email[Cns_MAX_BYTES_EMAIL_ADDRESS + 1],
const char MailKey[Mai_LENGTH_EMAIL_CONFIRM_KEY + 1])
{
char *Query;
/***** Remove expired pending emails from database *****/
if (asprintf (&Query,"DELETE FROM pending_emails"
" WHERE DateAndTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')",
Cfg_TIME_TO_DELETE_OLD_PENDING_EMAILS) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove old pending mail keys");
DB_BuildQuery ("DELETE FROM pending_emails"
" WHERE DateAndTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')",
Cfg_TIME_TO_DELETE_OLD_PENDING_EMAILS);
DB_QueryDELETE_new ("can not remove old pending mail keys");
/***** Insert mail key in database *****/
DB_BuildQuery ("INSERT INTO pending_emails"
@ -1801,7 +1791,6 @@ void Mai_ConfirmEmail (void)
extern const char *Txt_The_email_X_has_been_confirmed;
extern const char *Txt_The_email_address_has_not_been_confirmed;
extern const char *Txt_Failed_email_confirmation_key;
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
char MailKey[Mai_LENGTH_EMAIL_CONFIRM_KEY + 1];
@ -1837,10 +1826,8 @@ void Mai_ConfirmEmail (void)
if (KeyIsCorrect)
{
/***** Delete this key *****/
if (asprintf (&Query,"DELETE FROM pending_emails WHERE MailKey='%s'",
MailKey) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove an email key");
DB_BuildQuery ("DELETE FROM pending_emails WHERE MailKey='%s'",MailKey);
DB_QueryDELETE_new ("can not remove an email key");
/***** Check user's code and email
and get if email is already confirmed *****/

View File

@ -292,7 +292,6 @@ void Not_RequestRemNotice (void)
void Not_RemoveNotice (void)
{
char *Query;
long NotCod;
/***** Get the code of the notice to remove *****/
@ -309,11 +308,10 @@ void Not_RemoveNotice (void)
DB_QueryINSERT_new ("can not remove notice");
/* Remove notice */
if (asprintf (&Query,"DELETE FROM notices"
" WHERE NotCod=%ld AND CrsCod=%ld",
NotCod,Gbl.CurrentCrs.Crs.CrsCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove notice");
DB_BuildQuery ("DELETE FROM notices"
" WHERE NotCod=%ld AND CrsCod=%ld",
NotCod,Gbl.CurrentCrs.Crs.CrsCod);
DB_QueryDELETE_new ("can not remove notice");
/***** Mark possible notifications as removed *****/
Ntf_MarkNotifAsRemoved (Ntf_EVENT_NOTICE,NotCod);

View File

@ -1506,7 +1506,6 @@ static void Ntf_UpdateMyLastAccessToNotifications (void)
void Ntf_SendPendingNotifByEMailToAllUsrs (void)
{
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRow,NumRows;
@ -1559,11 +1558,10 @@ void Ntf_SendPendingNotifByEMailToAllUsrs (void)
DB_FreeMySQLResult (&mysql_res);
/***** Delete old notifications ******/
if (asprintf (&Query,"DELETE LOW_PRIORITY FROM notif"
" WHERE TimeNotif<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')",
Cfg_TIME_TO_DELETE_OLD_NOTIF) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove old notifications");
DB_BuildQuery ("DELETE LOW_PRIORITY FROM notif"
" WHERE TimeNotif<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')",
Cfg_TIME_TO_DELETE_OLD_NOTIF);
DB_QueryDELETE_new ("can not remove old notifications");
}
/*****************************************************************************/
@ -2101,12 +2099,8 @@ static unsigned Ntf_GetNumberOfMyNewUnseenNtfs (void)
void Ntf_RemoveUsrNtfs (long ToUsrCod)
{
char *Query;
/***** Delete notifications of a user ******/
if (asprintf (&Query,"DELETE LOW_PRIORITY FROM notif"
" WHERE ToUsrCod=%ld",
ToUsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove notifications of a user");
DB_BuildQuery ("DELETE LOW_PRIORITY FROM notif WHERE ToUsrCod=%ld",
ToUsrCod);
DB_QueryDELETE_new ("can not remove notifications of a user");
}

View File

@ -1030,12 +1030,8 @@ unsigned Pho_UpdateMyClicksWithoutPhoto (void)
void Pho_RemoveUsrFromTableClicksWithoutPhoto (long UsrCod)
{
char *Query;
if (asprintf (&Query,"DELETE FROM clicks_without_photo WHERE UsrCod=%ld",
UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove a user from the list of users without photo");
DB_BuildQuery ("DELETE FROM clicks_without_photo WHERE UsrCod=%ld",UsrCod);
DB_QueryDELETE_new ("can not remove a user from the list of users without photo");
}
/*****************************************************************************/
@ -1503,12 +1499,9 @@ static long Pho_GetDegWithAvgPhotoLeastRecentlyUpdated (void)
void Pho_RemoveObsoleteStatDegrees (void)
{
char *Query;
if (asprintf (&Query,"DELETE FROM sta_degrees"
" WHERE DegCod NOT IN (SELECT DegCod FROM degrees)") < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove old degrees from stats");
DB_BuildQuery ("DELETE FROM sta_degrees"
" WHERE DegCod NOT IN (SELECT DegCod FROM degrees)");
DB_QueryDELETE_new ("can not remove old degrees from stats");
}
/*****************************************************************************/

View File

@ -556,7 +556,6 @@ void Plc_RemovePlace (void)
{
extern const char *Txt_To_remove_a_place_you_must_first_remove_all_centres_of_that_place;
extern const char *Txt_Place_X_removed;
char *Query;
struct Place Plc;
/***** Get place code *****/
@ -572,10 +571,8 @@ void Plc_RemovePlace (void)
else // Place has no centres ==> remove it
{
/***** Remove place *****/
if (asprintf (&Query,"DELETE FROM places WHERE PlcCod=%ld",
Plc.PlcCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove a place");
DB_BuildQuery ("DELETE FROM places WHERE PlcCod=%ld",Plc.PlcCod);
DB_QueryDELETE_new ("can not remove a place");
/***** Write message to show the change made *****/
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),

View File

@ -486,7 +486,6 @@ long Plg_GetParamPlgCod (void)
void Plg_RemovePlugin (void)
{
extern const char *Txt_Plugin_X_removed;
char *Query;
struct Plugin Plg;
/***** Get plugin code *****/
@ -497,10 +496,8 @@ void Plg_RemovePlugin (void)
Plg_GetDataOfPluginByCod (&Plg);
/***** Remove plugin *****/
if (asprintf (&Query,"DELETE FROM plugins WHERE PlgCod=%ld",
Plg.PlgCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove a plugin");
DB_BuildQuery ("DELETE FROM plugins WHERE PlgCod=%ld",Plg.PlgCod);
DB_QueryDELETE_new ("can not remove a plugin");
/***** Write message to show the change made *****/
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),

View File

@ -216,14 +216,11 @@ void Pre_SetPrefsFromIP (void)
void Pre_RemoveOldPrefsFromIP (void)
{
char *Query;
/***** Remove old preferences *****/
if (asprintf (&Query,"DELETE LOW_PRIORITY FROM IP_prefs"
" WHERE LastChange<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')",
Cfg_TIME_TO_DELETE_IP_PREFS) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove old preferences");
DB_BuildQuery ("DELETE LOW_PRIORITY FROM IP_prefs"
" WHERE LastChange<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')",
Cfg_TIME_TO_DELETE_IP_PREFS);
DB_QueryDELETE_new ("can not remove old preferences");
}
/*****************************************************************************/

View File

@ -1057,13 +1057,9 @@ static void Prf_CreateUsrFigures (long UsrCod,const struct UsrFigures *UsrFigure
void Prf_RemoveUsrFigures (long UsrCod)
{
char *Query;
/***** Remove user's figures *****/
if (asprintf (&Query,"DELETE FROM usr_figures WHERE UsrCod=%ld",
UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not delete user's figures");
DB_BuildQuery ("DELETE FROM usr_figures WHERE UsrCod=%ld",UsrCod);
DB_QueryDELETE_new ("can not delete user's figures");
}
/*****************************************************************************/

View File

@ -2116,7 +2116,6 @@ static void Prj_RemUsrFromPrj (Prj_RoleInProject_t RoleInProject)
extern const char *Txt_THE_USER_X_has_been_removed_as_a_Y_from_the_project_Z;
extern const char *Txt_PROJECT_ROLES_SINGUL_abc[Prj_NUM_ROLES_IN_PROJECT];
extern const char *Txt_User_not_found_or_you_do_not_have_permission_;
char *Query;
struct Project Prj;
bool ItsMe;
@ -2137,13 +2136,12 @@ static void Prj_RemUsrFromPrj (Prj_RoleInProject_t RoleInProject)
if (Prj_CheckIfICanEditProject (Prj.PrjCod))
{
/***** Remove user from the table of project-users *****/
if (asprintf (&Query,"DELETE FROM prj_usr"
" WHERE PrjCod=%ld AND RoleInProject=%u AND UsrCod=%ld",
Prj.PrjCod,
(unsigned) RoleInProject,
Gbl.Usrs.Other.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove a user from a project");
DB_BuildQuery ("DELETE FROM prj_usr"
" WHERE PrjCod=%ld AND RoleInProject=%u AND UsrCod=%ld",
Prj.PrjCod,
(unsigned) RoleInProject,
Gbl.Usrs.Other.UsrDat.UsrCod);
DB_QueryDELETE_new ("can not remove a user from a project");
/***** Flush cache *****/
ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod);
@ -2760,7 +2758,6 @@ void Prj_ReqRemProject (void)
void Prj_RemoveProject (void)
{
extern const char *Txt_Project_X_removed;
char *Query;
struct Project Prj;
char PathRelPrj[PATH_MAX + 1];
@ -2778,22 +2775,20 @@ void Prj_RemoveProject (void)
if (Prj_CheckIfICanEditProject (Prj.PrjCod))
{
/***** Remove users in project *****/
if (asprintf (&Query,"DELETE FROM prj_usr USING projects,prj_usr"
" WHERE projects.PrjCod=%ld AND projects.CrsCod=%ld"
" AND projects.PrjCod=prj_usr.PrjCod",
Prj.PrjCod,Gbl.CurrentCrs.Crs.CrsCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove project");
DB_BuildQuery ("DELETE FROM prj_usr USING projects,prj_usr"
" WHERE projects.PrjCod=%ld AND projects.CrsCod=%ld"
" AND projects.PrjCod=prj_usr.PrjCod",
Prj.PrjCod,Gbl.CurrentCrs.Crs.CrsCod);
DB_QueryDELETE_new ("can not remove project");
/***** Flush cache *****/
Prj_FlushCacheMyRoleInProject ();
/***** Remove project *****/
if (asprintf (&Query,"DELETE FROM projects"
" WHERE PrjCod=%ld AND CrsCod=%ld",
Prj.PrjCod,Gbl.CurrentCrs.Crs.CrsCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove project");
DB_BuildQuery ("DELETE FROM projects"
" WHERE PrjCod=%ld AND CrsCod=%ld",
Prj.PrjCod,Gbl.CurrentCrs.Crs.CrsCod);
DB_QueryDELETE_new ("can not remove project");
/***** Remove information related to files in project *****/
Brw_RemovePrjFilesFromDB (Prj.PrjCod);
@ -3431,23 +3426,19 @@ static void Prj_UpdateProject (struct Project *Prj)
void Prj_RemoveCrsProjects (long CrsCod)
{
char *Query;
/***** Remove users in projects of the course *****/
if (asprintf (&Query,"DELETE FROM prj_usr USING projects,prj_usr"
" WHERE projects.CrsCod=%ld"
" AND projects.PrjCod=prj_usr.PrjCod",
CrsCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove all the projects of a course");
DB_BuildQuery ("DELETE FROM prj_usr USING projects,prj_usr"
" WHERE projects.CrsCod=%ld"
" AND projects.PrjCod=prj_usr.PrjCod",
CrsCod);
DB_QueryDELETE_new ("can not remove all the projects of a course");
/***** Flush cache *****/
Prj_FlushCacheMyRoleInProject ();
/***** Remove projects *****/
if (asprintf (&Query,"DELETE FROM projects WHERE CrsCod=%ld",CrsCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove all the projects of a course");
DB_BuildQuery ("DELETE FROM projects WHERE CrsCod=%ld",CrsCod);
DB_QueryDELETE_new ("can not remove all the projects of a course");
}
/*****************************************************************************/
@ -3456,13 +3447,11 @@ void Prj_RemoveCrsProjects (long CrsCod)
void Prj_RemoveUsrFromProjects (long UsrCod)
{
char *Query;
bool ItsMe;
/***** Remove user from projects *****/
if (asprintf (&Query,"DELETE FROM prj_usr WHERE UsrCod=%ld",UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove user from projects");
DB_BuildQuery ("DELETE FROM prj_usr WHERE UsrCod=%ld",UsrCod);
DB_QueryDELETE_new ("can not remove user from projects");
/***** Flush cache *****/
ItsMe = Usr_ItsMe (UsrCod);

View File

@ -683,7 +683,6 @@ void Rec_AskConfirmRemFieldWithRecords (unsigned NumRecords)
void Rec_RemoveFieldFromDB (void)
{
extern const char *Txt_Record_field_X_removed;
char *Query;
/***** Get from the database the name of the field *****/
Rec_GetFieldByCod (Gbl.CurrentCrs.Records.Field.FieldCod,
@ -692,16 +691,14 @@ void Rec_RemoveFieldFromDB (void)
&Gbl.CurrentCrs.Records.Field.Visibility);
/***** Remove field from all records *****/
if (asprintf (&Query,"DELETE FROM crs_records WHERE FieldCod=%ld",
Gbl.CurrentCrs.Records.Field.FieldCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove field from all students' records");
DB_BuildQuery ("DELETE FROM crs_records WHERE FieldCod=%ld",
Gbl.CurrentCrs.Records.Field.FieldCod);
DB_QueryDELETE_new ("can not remove field from all students' records");
/***** Remove the field *****/
if (asprintf (&Query,"DELETE FROM crs_record_fields WHERE FieldCod=%ld",
Gbl.CurrentCrs.Records.Field.FieldCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove field of record");
DB_BuildQuery ("DELETE FROM crs_record_fields WHERE FieldCod=%ld",
Gbl.CurrentCrs.Records.Field.FieldCod);
DB_QueryDELETE_new ("can not remove field of record");
/***** Write message to show the change made *****/
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
@ -2032,15 +2029,12 @@ void Rec_UpdateCrsRecord (long UsrCod)
void Rec_RemoveFieldsCrsRecordInCrs (long UsrCod,struct Course *Crs)
{
char *Query;
/***** Remove text of the field of record course *****/
if (asprintf (&Query,"DELETE FROM crs_records"
" WHERE UsrCod=%ld AND FieldCod IN"
" (SELECT FieldCod FROM crs_record_fields WHERE CrsCod=%ld)",
UsrCod,Crs->CrsCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove user's record in a course");
DB_BuildQuery ("DELETE FROM crs_records"
" WHERE UsrCod=%ld AND FieldCod IN"
" (SELECT FieldCod FROM crs_record_fields WHERE CrsCod=%ld)",
UsrCod,Crs->CrsCod);
DB_QueryDELETE_new ("can not remove user's record in a course");
}
/*****************************************************************************/
@ -2049,12 +2043,9 @@ void Rec_RemoveFieldsCrsRecordInCrs (long UsrCod,struct Course *Crs)
void Rec_RemoveFieldsCrsRecordAll (long UsrCod)
{
char *Query;
/***** Remove text of the field of record course *****/
if (asprintf (&Query,"DELETE FROM crs_records WHERE UsrCod=%ld",UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove user's records in all courses");
DB_BuildQuery ("DELETE FROM crs_records WHERE UsrCod=%ld",UsrCod);
DB_QueryDELETE_new ("can not remove user's records in all courses");
}
/*****************************************************************************/