",
ContainerClass[Status],
Not_ContainerWidth[TypeNoticesListing]);
/***** Write the date in the top part of the yellow note *****/
/* Write symbol to indicate if notice is obsolete or active */
if (TypeNoticesListing == Not_LIST_FULL_NOTICES)
{
if (Not_CheckIfICanEditNotices ())
{
/***** Put form to remove announcement *****/
Ico_PutContextualIconToRemove (ActReqRemNot,Not_PutParams);
/***** Put form to change the status of the notice *****/
switch (Status)
{
case Not_ACTIVE_NOTICE:
Lay_PutContextualLink (ActHidNot,NULL,Not_PutParams,
"eye-on64x64.png",
Txt_NOTICE_Active_Mark_as_obsolete,NULL,
NULL);
break;
case Not_OBSOLETE_NOTICE:
Lay_PutContextualLink (ActRevNot,NULL,Not_PutParams,
"eye-slash-on64x64.png",
Txt_NOTICE_Obsolete_Mark_as_active,NULL,
NULL);
break;
}
Act_FormEnd ();
}
else // Don't put forms
/* Status of the notice */
switch (Status)
{
case Not_ACTIVE_NOTICE:
fprintf (Gbl.F.Out,"
"
""
"",
Txt_NOTICE_Active_SINGULAR,
Gbl.Prefs.IconsURL,
Txt_NOTICE_Active_SINGULAR,
Txt_NOTICE_Active_SINGULAR);
break;
case Not_OBSOLETE_NOTICE:
fprintf (Gbl.F.Out,"
"
""
"",
Txt_NOTICE_Obsolete_SINGULAR,
Gbl.Prefs.IconsURL,
Txt_NOTICE_Obsolete_SINGULAR,
Txt_NOTICE_Obsolete_SINGULAR);
break;
}
}
/* Write the date */
UniqueId++;
fprintf (Gbl.F.Out,"
",
DateClass[Status]);
if (TypeNoticesListing == Not_LIST_BRIEF_NOTICES)
{
/* Form to view full notice */
Act_FormStart (ActSeeOneNot);
Not_PutHiddenParamNotCod (NotCod);
Act_LinkFormSubmit (Txt_See_full_notice,DateClass[Status],NULL);
}
fprintf (Gbl.F.Out,"",
UniqueId);
if (TypeNoticesListing == Not_LIST_BRIEF_NOTICES)
{
fprintf (Gbl.F.Out,"");
Act_FormEnd ();
}
fprintf (Gbl.F.Out,""
"
",
UniqueId,(long) TimeUTC,
(unsigned) Gbl.Prefs.DateFormat,Txt_Today);
/***** Write the content of the notice *****/
if (TypeNoticesListing == Not_LIST_BRIEF_NOTICES)
{
fprintf (Gbl.F.Out,"
%s
",Content);
/* Put form to view full notice */
fprintf (Gbl.F.Out,"
");
Lay_PutContextualLink (ActSeeOneNot,NULL,Not_PutParams,
"ellipsis32x32.gif",
Txt_See_full_notice,NULL,
NULL);
fprintf (Gbl.F.Out,"
");
}
else
fprintf (Gbl.F.Out,"
%s
",
TextClass[Status],Content);
/***** Write the author *****/
fprintf (Gbl.F.Out,"
", // Limited width
AuthorClass[Status]);
Usr_UsrDataConstructor (&UsrDat);
UsrDat.UsrCod = UsrCod;
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) // Get from the database the data of the autor
Usr_WriteFirstNameBRSurnames (&UsrDat);
Usr_UsrDataDestructor (&UsrDat);
fprintf (Gbl.F.Out,"
");
/***** End yellow note *****/
fprintf (Gbl.F.Out,"
");
}
/*****************************************************************************/
/******************* Get summary and content for a notice ********************/
/*****************************************************************************/
// This function may be called inside a web service, so don't report error
void Not_GetSummaryAndContentNotice (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
char **ContentStr,
long NotCod,bool GetContent)
{
char Query[512];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
size_t Length;
SummaryStr[0] = '\0'; // Return nothing on error
/***** Get subject of message from database *****/
sprintf (Query,"SELECT Content FROM notices WHERE NotCod=%ld",
NotCod);
if (!mysql_query (&Gbl.mysql,Query))
if ((mysql_res = mysql_store_result (&Gbl.mysql)) != NULL)
{
/***** Result should have a unique row *****/
if (mysql_num_rows (mysql_res) == 1)
{
/***** Get sumary / content *****/
row = mysql_fetch_row (mysql_res);
/***** Copy summary *****/
// TODO: Do only direct copy when a Subject of type VARCHAR(255) is available
if (strlen (row[0]) > Ntf_MAX_BYTES_SUMMARY)
{
strncpy (SummaryStr,row[0],
Ntf_MAX_BYTES_SUMMARY);
SummaryStr[Ntf_MAX_BYTES_SUMMARY] = '\0';
}
else
Str_Copy (SummaryStr,row[0],
Ntf_MAX_BYTES_SUMMARY);
/***** Copy content *****/
if (GetContent)
{
Length = strlen (row[0]);
if ((*ContentStr = (char *) malloc (Length + 1)) == NULL)
Lay_ShowErrorAndExit ("Error allocating memory for notification content.");
Str_Copy (*ContentStr,row[0],
Length);
}
}
mysql_free_result (mysql_res);
}
}
/*****************************************************************************/
/*************************** Get number of notices ***************************/
/*****************************************************************************/
// Returns the number of (active or obsolete) notices
// sent from this location (all the platform, current degree or current course)
unsigned Not_GetNumNotices (Sco_Scope_t Scope,Not_Status_t Status,unsigned *NumNotif)
{
char Query[1024];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumNotices;
/***** Get number of notices from database *****/
switch (Scope)
{
case Sco_SCOPE_SYS:
sprintf (Query,"SELECT COUNT(*),SUM(NumNotif)"
" FROM notices"
" WHERE Status=%u",
Status);
break;
case Sco_SCOPE_CTY:
sprintf (Query,"SELECT COUNT(*),SUM(notices.NumNotif)"
" FROM institutions,centres,degrees,courses,notices"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=notices.CrsCod"
" AND notices.Status=%u",
Gbl.CurrentCty.Cty.CtyCod,
Status);
break;
case Sco_SCOPE_INS:
sprintf (Query,"SELECT COUNT(*),SUM(notices.NumNotif)"
" FROM centres,degrees,courses,notices"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=notices.CrsCod"
" AND notices.Status=%u",
Gbl.CurrentIns.Ins.InsCod,
Status);
break;
case Sco_SCOPE_CTR:
sprintf (Query,"SELECT COUNT(*),SUM(notices.NumNotif)"
" FROM degrees,courses,notices"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=notices.CrsCod"
" AND notices.Status=%u",
Gbl.CurrentCtr.Ctr.CtrCod,
Status);
break;
case Sco_SCOPE_DEG:
sprintf (Query,"SELECT COUNT(*),SUM(notices.NumNotif)"
" FROM courses,notices"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=notices.CrsCod"
" AND notices.Status=%u",
Gbl.CurrentDeg.Deg.DegCod,
Status);
break;
case Sco_SCOPE_CRS:
sprintf (Query,"SELECT COUNT(*),SUM(NumNotif)"
" FROM notices"
" WHERE CrsCod=%ld"
" AND Status=%u",
Gbl.CurrentCrs.Crs.CrsCod,
Status);
break;
default:
Lay_ShowErrorAndExit ("Wrong scope.");
break;
}
DB_QuerySELECT (Query,&mysql_res,"can not get number of notices");
/***** Get number of notices *****/
row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%u",&NumNotices) != 1)
Lay_ShowErrorAndExit ("Error when getting number of notices.");
/***** Get number of notifications by email *****/
if (row[1])
{
if (sscanf (row[1],"%u",NumNotif) != 1)
Lay_ShowErrorAndExit ("Error when getting number of notifications of notices.");
}
else
*NumNotif = 0;
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumNotices;
}
/*****************************************************************************/
/************************ Get number of deleted notices **********************/
/*****************************************************************************/
// Returns the number of deleted notices
// sent from this location (all the platform, current degree or current course)
unsigned Not_GetNumNoticesDeleted (Sco_Scope_t Scope,unsigned *NumNotif)
{
char Query[1024];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumNotices;
/***** Get number of notices from database *****/
switch (Scope)
{
case Sco_SCOPE_SYS:
sprintf (Query,"SELECT COUNT(*),SUM(NumNotif)"
" FROM notices_deleted");
break;
case Sco_SCOPE_CTY:
sprintf (Query,"SELECT COUNT(*),SUM(notices_deleted.NumNotif)"
" FROM institutions,centres,degrees,courses,notices_deleted"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=notices_deleted.CrsCod",
Gbl.CurrentCty.Cty.CtyCod);
break;
case Sco_SCOPE_INS:
sprintf (Query,"SELECT COUNT(*),SUM(notices_deleted.NumNotif)"
" FROM centres,degrees,courses,notices_deleted"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=notices_deleted.CrsCod",
Gbl.CurrentIns.Ins.InsCod);
break;
case Sco_SCOPE_CTR:
sprintf (Query,"SELECT COUNT(*),SUM(notices_deleted.NumNotif)"
" FROM degrees,courses,notices_deleted"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=notices_deleted.CrsCod",
Gbl.CurrentCtr.Ctr.CtrCod);
break;
case Sco_SCOPE_DEG:
sprintf (Query,"SELECT COUNT(*),SUM(notices_deleted.NumNotif)"
" FROM courses,notices_deleted"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=notices_deleted.CrsCod",
Gbl.CurrentDeg.Deg.DegCod);
break;
case Sco_SCOPE_CRS:
sprintf (Query,"SELECT COUNT(*),SUM(NumNotif)"
" FROM notices_deleted"
" WHERE CrsCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod);
break;
default:
Lay_ShowErrorAndExit ("Wrong scope.");
break;
}
DB_QuerySELECT (Query,&mysql_res,"can not get number of deleted notices");
/***** Get number of notices *****/
row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%u",&NumNotices) != 1)
Lay_ShowErrorAndExit ("Error when getting number of deleted notices.");
/***** Get number of notifications by email *****/
if (row[1])
{
if (sscanf (row[1],"%u",NumNotif) != 1)
Lay_ShowErrorAndExit ("Error when getting number of notifications of deleted notices.");
}
else
*NumNotif = 0;
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumNotices;
}
/*****************************************************************************/
/*************** Put parameter with the code of a notice *********************/
/*****************************************************************************/
static void Not_PutParams (void)
{
Not_PutHiddenParamNotCod (Gbl.CurrentCrs.Notices.NotCod);
}
/*****************************************************************************/
/*************** Put parameter with the code of a notice *********************/
/*****************************************************************************/
void Not_PutHiddenParamNotCod (long NotCod)
{
Par_PutHiddenParamLong ("NotCod",NotCod);
}
/*****************************************************************************/
/*************** Get parameter with the code of a notice *********************/
/*****************************************************************************/
static long Not_GetParamNotCod (void)
{
long NotCod;
/***** Get notice code *****/
if ((NotCod = Par_GetParToLong ("NotCod")) <= 0)
Lay_ShowErrorAndExit ("Wrong code of notice.");
return NotCod;
}