Version 20.51.21: Mar 19, 2021 Notices database tables renamed.

This commit is contained in:
acanas 2021-03-19 12:21:20 +01:00
parent bc4f1949fa
commit dcae8af717
7 changed files with 187 additions and 154 deletions

View File

@ -1092,9 +1092,23 @@ CREATE TABLE IF NOT EXISTS msg_snt_deleted (
INDEX(CrsCod),
INDEX(UsrCod));
--
-- Table notices: stores the yellow notes (post-it)
-- Table not_deleted: stores the yellow notes (post-it) that have been deleted
--
CREATE TABLE IF NOT EXISTS notices (
CREATE TABLE IF NOT EXISTS not_deleted (
NotCod INT NOT NULL,
CrsCod INT NOT NULL DEFAULT -1,
UsrCod INT NOT NULL,
CreatTime DATETIME NOT NULL,
Content TEXT NOT NULL,
NumNotif INT NOT NULL DEFAULT 0,
UNIQUE INDEX(NotCod),
INDEX(CrsCod),
INDEX(UsrCod),
INDEX(CreatTime));
--
-- Table not_notices: stores the yellow notes (post-it)
--
CREATE TABLE IF NOT EXISTS not_notices (
NotCod INT NOT NULL AUTO_INCREMENT,
CrsCod INT NOT NULL DEFAULT -1,
UsrCod INT NOT NULL,
@ -1108,20 +1122,6 @@ CREATE TABLE IF NOT EXISTS notices (
INDEX(CreatTime),
INDEX(Status));
--
-- Table notices_deleted: stores the yellow notes (post-it) that have been deleted
--
CREATE TABLE IF NOT EXISTS notices_deleted (
NotCod INT NOT NULL,
CrsCod INT NOT NULL DEFAULT -1,
UsrCod INT NOT NULL,
CreatTime DATETIME NOT NULL,
Content TEXT NOT NULL,
NumNotif INT NOT NULL DEFAULT 0,
UNIQUE INDEX(NotCod),
INDEX(CrsCod),
INDEX(UsrCod),
INDEX(CreatTime));
--
-- Table ntf_notifications: stores the notifications of events
--
CREATE TABLE IF NOT EXISTS ntf_notifications (

View File

@ -3968,11 +3968,12 @@ int swad__sendNotice (struct soap *soap,
/* Get the code of the inserted item */
NotCod =
DB_QueryINSERTandReturnCode ("can not create message",
"INSERT INTO notices"
"INSERT INTO not_notices"
" (CrsCod,UsrCod,CreatTime,Content,Status)"
" VALUES"
" (%ld,%ld,NOW(),'%s',%u)",
Gbl.Hierarchy.Crs.CrsCod,Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
body,(unsigned) Not_ACTIVE_NOTICE);
/***** Create notifications *****/

View File

@ -159,11 +159,16 @@ static void RSS_WriteNotices (FILE *FileRSS,struct Crs_Course *Crs)
/***** Get active notices in course *****/
NumNotices = DB_QuerySELECT (&mysql_res,"can not get notices from database",
"SELECT NotCod,UNIX_TIMESTAMP(CreatTime) AS T,UsrCod,Content"
" FROM notices"
" WHERE CrsCod=%ld AND Status=%u"
"SELECT NotCod," // row[0]
"UNIX_TIMESTAMP(CreatTime) AS T," // row[1]
"UsrCod," // row[2]
"Content" // row[3]
" FROM not_notices"
" WHERE CrsCod=%ld"
" AND Status=%u"
" ORDER BY T DESC",
Crs->CrsCod,(unsigned) Not_ACTIVE_NOTICE);
Crs->CrsCod,
(unsigned) Not_ACTIVE_NOTICE);
/***** Write items with notices *****/
if (NumNotices)

View File

@ -600,13 +600,18 @@ TODO: Salvador Romero Cort
TODO: FIX BUG, URGENT! En las fechas como parámetro Dat_WriteParamsIniEndDates(), por ejemplo al cambiar el color de la gráfica de accesos por día y hora, no se respeta la zona horaria.
*/
#define Log_PLATFORM_VERSION "SWAD 20.51.20 (2021-03-19)"
#define Log_PLATFORM_VERSION "SWAD 20.51.21 (2021-03-19)"
#define CSS_FILE "swad20.45.css"
#define JS_FILE "swad20.6.2.js"
/*
TODO: Rename CENTRE to CENTER in help wiki.
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
Version 20.51.21: Mar 19, 2021 Notices database tables renamed. (308101 lines)
2 changes necessary in database:
RENAME TABLE notices TO not_notices;
RENAME TABLE notices_deleted TO not_deleted;
Version 20.51.20: Mar 19, 2021 Rooms database tables renamed. (308069 lines)
2 changes necessary in database:
RENAME TABLE room_MAC TO roo_MACs;

View File

@ -1988,16 +1988,22 @@ static void Crs_EmptyCourseCompletely (long CrsCod)
/***** Remove notices in the course *****/
/* Copy all notices from the course to table of deleted notices */
DB_QueryINSERT ("can not remove notices in a course",
"INSERT INTO notices_deleted"
"INSERT INTO not_deleted"
" (NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif)"
" SELECT NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif"
" FROM notices"
" SELECT NotCod,"
"CrsCod,"
"UsrCod,"
"CreatTime,"
"Content,"
"NumNotif"
" FROM not_notices"
" WHERE CrsCod=%ld",
CrsCod);
/* Remove all notices from the course */
DB_QueryDELETE ("can not remove notices in a course",
"DELETE FROM notices WHERE CrsCod=%ld",
"DELETE FROM not_notices"
" WHERE CrsCod=%ld",
CrsCod);
/***** Remove all the threads and posts in forums of the course *****/

View File

@ -2281,9 +2281,36 @@ mysql> DESCRIBE msg_snt_deleted;
"INDEX(CrsCod),"
"INDEX(UsrCod))");
/***** Table notices *****/
/***** Table not_deleted *****/
/*
mysql> DESCRIBE notices;
mysql> DESCRIBE not_deleted;
+-----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------+------+-----+---------+-------+
| NotCod | int(11) | NO | PRI | NULL | |
| CrsCod | int(11) | NO | MUL | -1 | |
| UsrCod | int(11) | NO | MUL | NULL | |
| CreatTime | datetime | NO | MUL | NULL | |
| Content | text | NO | | NULL | |
| NumNotif | int(11) | NO | | 0 | |
+-----------+----------+------+-----+---------+-------+
6 rows in set (0.01 sec)
*/
DB_CreateTable ("CREATE TABLE IF NOT EXISTS not_deleted ("
"NotCod INT NOT NULL,"
"CrsCod INT NOT NULL DEFAULT -1,"
"UsrCod INT NOT NULL,"
"CreatTime DATETIME NOT NULL,"
"Content TEXT NOT NULL,"
"NumNotif INT NOT NULL DEFAULT 0,"
"UNIQUE INDEX(NotCod),"
"INDEX(CrsCod),"
"INDEX(UsrCod),"
"INDEX(CreatTime))");
/***** Table not_notices *****/
/*
mysql> DESCRIBE not_notices;
+-----------+------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+------------+------+-----+---------+----------------+
@ -2297,7 +2324,7 @@ mysql> DESCRIBE notices;
+-----------+------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)
*/
DB_CreateTable ("CREATE TABLE IF NOT EXISTS notices ("
DB_CreateTable ("CREATE TABLE IF NOT EXISTS not_notices ("
"NotCod INT NOT NULL AUTO_INCREMENT,"
"CrsCod INT NOT NULL DEFAULT -1,"
"UsrCod INT NOT NULL,"
@ -2311,33 +2338,6 @@ mysql> DESCRIBE notices;
"INDEX(CreatTime),"
"INDEX(Status))");
/***** Table notices_deleted *****/
/*
mysql> DESCRIBE notices_deleted;
+-----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------+------+-----+---------+-------+
| NotCod | int(11) | NO | PRI | NULL | |
| CrsCod | int(11) | NO | MUL | -1 | |
| UsrCod | int(11) | NO | MUL | NULL | |
| CreatTime | datetime | NO | MUL | NULL | |
| Content | text | NO | | NULL | |
| NumNotif | int(11) | NO | | 0 | |
+-----------+----------+------+-----+---------+-------+
6 rows in set (0.01 sec)
*/
DB_CreateTable ("CREATE TABLE IF NOT EXISTS notices_deleted ("
"NotCod INT NOT NULL,"
"CrsCod INT NOT NULL DEFAULT -1,"
"UsrCod INT NOT NULL,"
"CreatTime DATETIME NOT NULL,"
"Content TEXT NOT NULL,"
"NumNotif INT NOT NULL DEFAULT 0,"
"UNIQUE INDEX(NotCod),"
"INDEX(CrsCod),"
"INDEX(UsrCod),"
"INDEX(CreatTime))");
/***** Table ntf_notifications *****/
/*
mysql> DESCRIBE ntf_notifications;

View File

@ -172,7 +172,7 @@ static long Not_InsertNoticeInDB (const char *Content)
/***** Insert notice in the database *****/
return
DB_QueryINSERTandReturnCode ("can not create notice",
"INSERT INTO notices"
"INSERT INTO not_notices"
" (CrsCod,UsrCod,CreatTime,Content,Status)"
" VALUES"
" (%ld,%ld,NOW(),'%s',%u)",
@ -189,7 +189,9 @@ static void Not_UpdateNumUsrsNotifiedByEMailAboutNotice (long NotCod,unsigned Nu
{
/***** Update number of users notified *****/
DB_QueryUPDATE ("can not update the number of notifications of a notice",
"UPDATE notices SET NumNotif=%u WHERE NotCod=%ld",
"UPDATE not_notices"
" SET NumNotif=%u"
" WHERE NotCod=%ld",
NumUsrsToBeNotifiedByEMail,NotCod);
}
@ -242,8 +244,10 @@ void Not_HideActiveNotice (void)
/***** Set notice as hidden *****/
DB_QueryUPDATE ("can not hide notice",
"UPDATE notices SET Status=%u"
" WHERE NotCod=%ld AND CrsCod=%ld",
"UPDATE not_notices"
" SET Status=%u"
" WHERE NotCod=%ld"
" AND CrsCod=%ld",
(unsigned) Not_OBSOLETE_NOTICE,
NotCod,Gbl.Hierarchy.Crs.CrsCod);
@ -267,8 +271,10 @@ void Not_RevealHiddenNotice (void)
/***** Set notice as active *****/
DB_QueryUPDATE ("can not reveal notice",
"UPDATE notices SET Status=%u"
" WHERE NotCod=%ld AND CrsCod=%ld",
"UPDATE not_notices"
" SET Status=%u"
" WHERE NotCod=%ld"
" AND CrsCod=%ld",
(unsigned) Not_ACTIVE_NOTICE,
NotCod,Gbl.Hierarchy.Crs.CrsCod);
@ -323,17 +329,24 @@ void Not_RemoveNotice (void)
/***** Remove notice *****/
/* Copy notice to table of deleted notices */
DB_QueryINSERT ("can not remove notice",
"INSERT IGNORE INTO notices_deleted"
"INSERT IGNORE INTO not_deleted"
" (NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif)"
" SELECT NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif"
" FROM notices"
" WHERE NotCod=%ld AND CrsCod=%ld",
" SELECT NotCod,"
"CrsCod,"
"UsrCod,"
"CreatTime,"
"Content,"
"NumNotif"
" FROM not_notices"
" WHERE NotCod=%ld"
" AND CrsCod=%ld",
NotCod,Gbl.Hierarchy.Crs.CrsCod);
/* Remove notice */
DB_QueryDELETE ("can not remove notice",
"DELETE FROM notices"
" WHERE NotCod=%ld AND CrsCod=%ld",
"DELETE FROM not_notices"
" WHERE NotCod=%ld"
" AND CrsCod=%ld",
NotCod,Gbl.Hierarchy.Crs.CrsCod);
/***** Mark possible notifications as removed *****/
@ -383,8 +396,9 @@ void Not_ShowNotices (Not_Listing_t TypeNoticesListing,long HighlightNotCod)
"UsrCod,"
"Content,"
"Status"
" FROM notices"
" WHERE CrsCod=%ld AND Status=%u"
" FROM not_notices"
" WHERE CrsCod=%ld"
" AND Status=%u"
" ORDER BY CreatTime DESC",
Gbl.Hierarchy.Crs.CrsCod,
(unsigned) Not_ACTIVE_NOTICE);
@ -396,7 +410,7 @@ void Not_ShowNotices (Not_Listing_t TypeNoticesListing,long HighlightNotCod)
"UsrCod,"
"Content,"
"Status"
" FROM notices"
" FROM not_notices"
" WHERE CrsCod=%ld"
" ORDER BY CreatTime DESC",
Gbl.Hierarchy.Crs.CrsCod);
@ -565,11 +579,11 @@ static void Not_GetDataAndShowNotice (long NotCod)
/***** Get notice data from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get notice from database",
"SELECT UNIX_TIMESTAMP(CreatTime) AS F,"
"UsrCod,"
"Content,"
"Status"
" FROM notices"
"SELECT UNIX_TIMESTAMP(CreatTime) AS F," // row[0]
"UsrCod," // row[1]
"Content," // row[2]
"Status" // row[3]
" FROM not_notices"
" WHERE NotCod=%ld AND CrsCod=%ld",
NotCod,Gbl.Hierarchy.Crs.CrsCod))
{
@ -772,7 +786,9 @@ void Not_GetSummaryAndContentNotice (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
/***** Get subject of message from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get content of notice",
"SELECT Content FROM notices WHERE NotCod=%ld",
"SELECT Content" // row[0]
" FROM not_notices"
" WHERE NotCod=%ld",
NotCod) == 1) // Result should have a unique row
{
/***** Get sumary / content *****/
@ -822,79 +838,79 @@ unsigned Not_GetNumNotices (Hie_Lvl_Level_t Scope,Not_Status_t Status,unsigned *
{
case Hie_Lvl_SYS:
DB_QuerySELECT (&mysql_res,"can not get number of notices",
"SELECT COUNT(*),"
"SUM(NumNotif)"
" FROM notices"
"SELECT COUNT(*)," // row[0]
"SUM(NumNotif)" // row[1]
" FROM not_notices"
" WHERE Status=%u",
Status);
break;
case Hie_Lvl_CTY:
DB_QuerySELECT (&mysql_res,"can not get number of notices",
"SELECT COUNT(*),"
"SUM(notices.NumNotif)"
" FROM ins_instits,"
"ctr_centers,"
"deg_degrees,"
"crs_courses,"
"notices"
"SELECT COUNT(*)," // row[0]
"SUM(not_notices.NumNotif)" // row[1]
" FROM ins_instits,"
"ctr_centers,"
"deg_degrees,"
"crs_courses,"
"not_notices"
" WHERE ins_instits.CtyCod=%ld"
" AND ins_instits.InsCod=ctr_centers.InsCod"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=notices.CrsCod"
" AND notices.Status=%u",
" AND ins_instits.InsCod=ctr_centers.InsCod"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=not_notices.CrsCod"
" AND not_notices.Status=%u",
Gbl.Hierarchy.Cty.CtyCod,
Status);
break;
case Hie_Lvl_INS:
DB_QuerySELECT (&mysql_res,"can not get number of notices",
"SELECT COUNT(*),"
"SUM(notices.NumNotif)"
" FROM ctr_centers,"
"deg_degrees,"
"crs_courses,"
"notices"
"SELECT COUNT(*)," // row[0]
"SUM(not_notices.NumNotif)" // row[1]
" FROM ctr_centers,"
"deg_degrees,"
"crs_courses,"
"not_notices"
" WHERE ctr_centers.InsCod=%ld"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=notices.CrsCod"
" AND notices.Status=%u",
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=not_notices.CrsCod"
" AND not_notices.Status=%u",
Gbl.Hierarchy.Ins.InsCod,
Status);
break;
case Hie_Lvl_CTR:
DB_QuerySELECT (&mysql_res,"can not get number of notices",
"SELECT COUNT(*),"
"SUM(notices.NumNotif)"
" FROM deg_degrees,"
"crs_courses,"
"notices"
"SELECT COUNT(*)," // row[0]
"SUM(not_notices.NumNotif)" // row[1]
" FROM deg_degrees,"
"crs_courses,"
"not_notices"
" WHERE deg_degrees.CtrCod=%ld"
" AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=notices.CrsCod"
" AND notices.Status=%u",
" AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=not_notices.CrsCod"
" AND not_notices.Status=%u",
Gbl.Hierarchy.Ctr.CtrCod,
Status);
break;
case Hie_Lvl_DEG:
DB_QuerySELECT (&mysql_res,"can not get number of notices",
"SELECT COUNT(*),"
"SUM(notices.NumNotif)"
" FROM crs_courses,"
"notices"
"SELECT COUNT(*)," // row[0]
"SUM(not_notices.NumNotif)" // row[1]
" FROM crs_courses,"
"not_notices"
" WHERE crs_courses.DegCod=%ld"
" AND crs_courses.CrsCod=notices.CrsCod"
" AND notices.Status=%u",
" AND crs_courses.CrsCod=not_notices.CrsCod"
" AND not_notices.Status=%u",
Gbl.Hierarchy.Deg.DegCod,
Status);
break;
case Hie_Lvl_CRS:
DB_QuerySELECT (&mysql_res,"can not get number of notices",
"SELECT COUNT(*),"
"SUM(NumNotif)"
" FROM notices"
"SELECT COUNT(*)," // row[0]
"SUM(NumNotif)" // row[1]
" FROM not_notices"
" WHERE CrsCod=%ld"
" AND Status=%u",
" AND Status=%u",
Gbl.Hierarchy.Crs.CrsCod,
Status);
break;
@ -940,67 +956,67 @@ unsigned Not_GetNumNoticesDeleted (Hie_Lvl_Level_t Scope,unsigned *NumNotif)
{
case Hie_Lvl_SYS:
DB_QuerySELECT (&mysql_res,"can not get number of deleted notices",
"SELECT COUNT(*),"
"SUM(NumNotif)"
" FROM notices_deleted");
"SELECT COUNT(*)," // row[0]
"SUM(NumNotif)" // row[1]
" FROM not_deleted");
break;
case Hie_Lvl_CTY:
DB_QuerySELECT (&mysql_res,"can not get number of deleted notices",
"SELECT COUNT(*),"
"SUM(notices_deleted.NumNotif)"
"SELECT COUNT(*)," // row[0]
"SUM(not_deleted.NumNotif)" // row[1]
" FROM ins_instits,"
"ctr_centers,"
"deg_degrees,"
"crs_courses,"
"notices_deleted"
"not_deleted"
" WHERE ins_instits.CtyCod=%ld"
" AND ins_instits.InsCod=ctr_centers.InsCod"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=notices_deleted.CrsCod",
" AND ins_instits.InsCod=ctr_centers.InsCod"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=not_deleted.CrsCod",
Gbl.Hierarchy.Cty.CtyCod);
break;
case Hie_Lvl_INS:
DB_QuerySELECT (&mysql_res,"can not get number of deleted notices",
"SELECT COUNT(*),"
"SUM(notices_deleted.NumNotif)"
" FROM ctr_centers,"
"deg_degrees,"
"crs_courses,"
"notices_deleted"
"SELECT COUNT(*)," // row[0]
"SUM(not_deleted.NumNotif)" // row[1]
" FROM ctr_centers,"
"deg_degrees,"
"crs_courses,"
"not_deleted"
" WHERE ctr_centers.InsCod=%ld"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=notices_deleted.CrsCod",
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=not_deleted.CrsCod",
Gbl.Hierarchy.Ins.InsCod);
break;
case Hie_Lvl_CTR:
DB_QuerySELECT (&mysql_res,"can not get number of deleted notices",
"SELECT COUNT(*),"
"SUM(notices_deleted.NumNotif)"
" FROM deg_degrees,"
"crs_courses,"
"notices_deleted"
"SELECT COUNT(*)," // row[0]
"SUM(not_deleted.NumNotif)" // row[1]
" FROM deg_degrees,"
"crs_courses,"
"not_deleted"
" WHERE deg_degrees.CtrCod=%ld"
" AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=notices_deleted.CrsCod",
" AND crs_courses.CrsCod=not_deleted.CrsCod",
Gbl.Hierarchy.Ctr.CtrCod);
break;
case Hie_Lvl_DEG:
DB_QuerySELECT (&mysql_res,"can not get number of deleted notices",
"SELECT COUNT(*),"
"SUM(notices_deleted.NumNotif)"
" FROM crs_courses,"
"notices_deleted"
"SELECT COUNT(*)," // row[0]
"SUM(not_deleted.NumNotif)" // row[1]
" FROM crs_courses,"
"not_deleted"
" WHERE crs_courses.DegCod=%ld"
" AND crs_courses.CrsCod=notices_deleted.CrsCod",
" AND crs_courses.CrsCod=not_deleted.CrsCod",
Gbl.Hierarchy.Deg.DegCod);
break;
case Hie_Lvl_CRS:
DB_QuerySELECT (&mysql_res,"can not get number of deleted notices",
"SELECT COUNT(*),"
"SUM(NumNotif)"
" FROM notices_deleted"
"SELECT COUNT(*)," // row[0]
"SUM(NumNotif)" // row[1]
" FROM not_deleted"
" WHERE CrsCod=%ld",
Gbl.Hierarchy.Crs.CrsCod);
break;