long Par_GetParToLong (const char *ParamName) { char LongStr[1 + 10 + 1]; /***** Get parameter with long number *****/ Par_GetParToText (ParamName,LongStr,1 + 10); return Str_ConvertStrCodToLongCod (LongStr); }
static void Ban_GetListBanners (MYSQL_RES **mysql_res,unsigned long NumRows) { MYSQL_ROW row; unsigned NumBan; struct Banner *Ban; /***** Get banners from database *****/ if (NumRows) // Banners found... { Gbl.Banners.Num = (unsigned) NumRows; /***** Create list with banners *****/ if ((Gbl.Banners.Lst = (struct Banner *) calloc (NumRows,sizeof (struct Banner))) == NULL) Lay_NotEnoughMemoryExit (); /***** Get the banners *****/ for (NumBan = 0; NumBan < Gbl.Banners.Num; NumBan++) { Ban = &(Gbl.Banners.Lst[NumBan]); /* Get next banner */ row = mysql_fetch_row (*mysql_res); /* Get banner code (row[0]) */ if ((Ban->BanCod = Str_ConvertStrCodToLongCod (row[0])) < 0) Lay_ShowErrorAndExit ("Wrong code of banner."); /* Get if banner is hidden (row[1]) */ Ban->Hidden = (row[1][0] == 'Y'); /* Get the short name of the banner (row[2]) */ Str_Copy (Ban->ShrtName,row[2], Ban_MAX_BYTES_SHRT_NAME); /* Get the full name of the banner (row[3]) */ Str_Copy (Ban->FullName,row[3], Ban_MAX_BYTES_FULL_NAME); /* Get the image of the banner (row[4]) */ Str_Copy (Ban->Img,row[4], Ban_MAX_BYTES_IMAGE); /* Get the URL of the banner (row[5]) */ Str_Copy (Ban->WWW,row[5], Cns_MAX_BYTES_WWW); } } else Gbl.Banners.Num = 0; /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (mysql_res); }
static void Not_GetDataAndShowNotice (long NotCod,bool ICanEditNotices) { char Query[512]; MYSQL_RES *mysql_res; MYSQL_ROW row; char Content[Cns_MAX_BYTES_TEXT+1]; time_t TimeUTC; long UsrCod; unsigned UnsignedNum; Not_Status_t Status; /***** Get notice data from database *****/ sprintf (Query,"SELECT UNIX_TIMESTAMP(CreatTime) AS F,UsrCod,Content,Status" " FROM notices" " WHERE NotCod='%ld' AND CrsCod='%ld'", NotCod, Gbl.CurrentCrs.Crs.CrsCod); if (DB_QuerySELECT (Query,&mysql_res,"can not get notice from database")) { row = mysql_fetch_row (mysql_res); /* Get creation time (row[0] holds the UTC date-time) */ TimeUTC = Dat_GetUNIXTimeFromStr (row[0]); /* Get user code (row[1]) */ UsrCod = Str_ConvertStrCodToLongCod (row[1]); /* Get the content (row[2]) and insert links*/ strncpy (Content,row[2],Cns_MAX_BYTES_TEXT); Str_InsertLinks (Content,Cns_MAX_BYTES_TEXT, Not_MaxCharsURLOnScreen[Not_LIST_FULL_NOTICES]); /* Get status of the notice (row[3]) */ Status = Not_OBSOLETE_NOTICE; if (sscanf (row[3],"%u",&UnsignedNum) == 1) if (UnsignedNum < Not_NUM_STATUS) Status = (Not_Status_t) UnsignedNum; /***** Draw the notice *****/ Not_DrawANotice (Not_LIST_FULL_NOTICES, NotCod, TimeUTC,Content,UsrCod,Status, ICanEditNotices); } /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); }
void Par_GetMainParameters (void) { extern Act_Action_t Act_FromActCodToAction[1 + Act_MAX_ACTION_COD]; extern const char *The_ThemeId[The_NUM_THEMES]; extern const char *Ico_IconSetId[Ico_NUM_ICON_SETS]; long ActCod; char Nickname[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1]; char URL[PATH_MAX + 1]; char LongStr[1 + 10 + 1]; /***** Reset codes of country, institution, centre, degree and course *****/ Gbl.Hierarchy.Cty.CtyCod = Gbl.Hierarchy.Ins.InsCod = Gbl.Hierarchy.Ctr.CtrCod = Gbl.Hierarchy.Deg.DegCod = Gbl.Hierarchy.Crs.CrsCod = -1L; // First of all, get action, and session identifier. // So, if other parameters have been stored in the database, there will be no problems to get them. /***** Get action to perform *****/ if (Gbl.WebService.IsWebService) { Gbl.Action.Act = Gbl.Action.Original = ActWebSvc; Tab_SetCurrentTab (); return; } /***** Set default action *****/ Gbl.Action.Act = Gbl.Action.Original = ActUnk; /***** Get another user's nickname, if exists (this nickname is used to go to another user's profile, not to get the logged user) *****/ if (Par_GetParToText ("usr",Nickname,Nck_MAX_BYTES_NICKNAME_FROM_FORM)) { if (Nickname[0]) { /* Set another user's nickname */ Str_RemoveLeadingArrobas (Nickname); Str_Copy (Gbl.Usrs.Other.UsrDat.Nickname,Nickname, // without arroba Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA); // This user's code is used to go to public profile // and to refresh old publishings in user's timeline // If user does not exist ==> UsrCod = -1 Gbl.Usrs.Other.UsrDat.UsrCod = Nck_GetUsrCodFromNickname (Gbl.Usrs.Other.UsrDat.Nickname); Gbl.Action.Act = Gbl.Action.Original = ActSeeOthPubPrf; // Set default action if no other is specified } } else if (Par_GetParToText ("agd",Nickname,Nck_MAX_BYTES_NICKNAME_FROM_FORM)) { if (Nickname[0]) { /* Set another user's nickname */ Str_RemoveLeadingArrobas (Nickname); Str_Copy (Gbl.Usrs.Other.UsrDat.Nickname,Nickname, // without arroba Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA); // This user's code is used to go to public agenda // If user does not exist ==> UsrCod = -1 Gbl.Usrs.Other.UsrDat.UsrCod = Nck_GetUsrCodFromNickname (Gbl.Usrs.Other.UsrDat.Nickname); Gbl.Action.Act = Gbl.Action.Original = ActFrmLogInUsrAgd; // Set default action if no other is specified } } /***** Get action to perform *****/ ActCod = Par_GetParToLong ("act"); if (ActCod >= 0 && ActCod <= Act_MAX_ACTION_COD) Gbl.Action.Act = Gbl.Action.Original = Act_FromActCodToAction[ActCod]; /***** Some preliminary adjusts depending on action *****/ switch (Act_GetBrowserTab (Gbl.Action.Act)) { case Act_AJAX_NORMAL: Gbl.Action.UsesAJAX = true; Gbl.Action.IsAJAXAutoRefresh = false; break; case Act_AJAX_RFRESH: Gbl.Action.UsesAJAX = true; Gbl.Action.IsAJAXAutoRefresh = true; break; default: Gbl.Action.UsesAJAX = false; Gbl.Action.IsAJAXAutoRefresh = false; break; } /***** Get session identifier, if exists *****/ Par_GetParToText ("ses",Gbl.Session.Id,Cns_BYTES_SESSION_ID); if (Gbl.Session.Id[0]) { /***** Get user's code, password, current degree and current course from stored session *****/ if (Ses_GetSessionData ()) Gbl.Session.IsOpen = true; else { Gbl.Session.HasBeenDisconnected = true; Gbl.Session.Id[0] = '\0'; } } else { // Try old parameter "IdSes" (allowed for compatibility, to be removed soon) Par_GetParToText ("IdSes",Gbl.Session.Id,Cns_BYTES_SESSION_ID); if (Gbl.Session.Id[0]) { /***** Get user's code, password, current degree and current course from stored session *****/ if (Ses_GetSessionData ()) Gbl.Session.IsOpen = true; else { Gbl.Session.HasBeenDisconnected = true; Gbl.Session.Id[0] = '\0'; } } } /***** Get user password and login *****/ switch (Gbl.Action.Act) { case ActLogIn: case ActFrmLogInUsrAgd: case ActLogInUsrAgd: // This action is necessary here when log in fails Pwd_GetParamUsrPwdLogin (); /* falls through */ /* no break */ case ActReqSndNewPwd: case ActSndNewPwd: Usr_GetParamUsrIdLogin (); break; } /***** Try to get settings changed from current IP *****/ Set_GetSettingsFromIP (); if (!Gbl.Session.IsOpen) // When no session open (no logged user)... { /***** Try to get settings changed from current IP *****/ if (Gbl.Prefs.Theme == The_THEME_UNKNOWN) Gbl.Prefs.Theme = The_THEME_DEFAULT; /***** Set path of theme *****/ snprintf (URL,sizeof (URL), "%s/%s", Cfg_URL_ICON_THEMES_PUBLIC,The_ThemeId[Gbl.Prefs.Theme]); Str_Copy (Gbl.Prefs.URLTheme,URL, PATH_MAX); /***** Set path of icon set *****/ snprintf (URL,sizeof (URL), "%s/%s", Cfg_URL_ICON_SETS_PUBLIC,Ico_IconSetId[Gbl.Prefs.IconSet]); Str_Copy (Gbl.Prefs.URLIconSet,URL, PATH_MAX); } /***** Get country if exists (from menu) *****/ Par_GetParToText ("cty",LongStr,1 + 10); if (LongStr[0]) // Parameter "cty" available { Gbl.Hierarchy.Cty.CtyCod = Str_ConvertStrCodToLongCod (LongStr); Gbl.Hierarchy.Ins.InsCod = Gbl.Hierarchy.Ctr.CtrCod = Gbl.Hierarchy.Deg.DegCod = Gbl.Hierarchy.Crs.CrsCod = -1L; } /***** Get institution if exists (from menu) *****/ Par_GetParToText ("ins",LongStr,1 + 10); if (LongStr[0]) // Parameter "ins" available { Gbl.Hierarchy.Ins.InsCod = Str_ConvertStrCodToLongCod (LongStr); Gbl.Hierarchy.Ctr.CtrCod = Gbl.Hierarchy.Deg.DegCod = Gbl.Hierarchy.Crs.CrsCod = -1L; } /***** Get centre if exists (from menu) *****/ Par_GetParToText ("ctr",LongStr,1 + 10); if (LongStr[0]) // Parameter "ctr" available { Gbl.Hierarchy.Ctr.CtrCod = Str_ConvertStrCodToLongCod (LongStr); Gbl.Hierarchy.Deg.DegCod = Gbl.Hierarchy.Crs.CrsCod = -1L; } /***** Get numerical degree code if exists (from menu) *****/ Par_GetParToText ("deg",LongStr,1 + 10); if (LongStr[0]) // Parameter "deg" available { Gbl.Hierarchy.Deg.DegCod = Str_ConvertStrCodToLongCod (LongStr); Gbl.Hierarchy.Crs.CrsCod = -1L; // Reset possible course from session } /***** Get numerical course code if exists (from menu) *****/ Par_GetParToText ("crs",LongStr,1 + 10); if (LongStr[0]) // Parameter "crs" available Gbl.Hierarchy.Crs.CrsCod = Str_ConvertStrCodToLongCod (LongStr); // Overwrite CrsCod from session /***** Get tab to activate *****/ Gbl.Action.Tab = TabUnk; if (Gbl.Action.Act == ActMnu) { Gbl.Action.Tab = (Tab_Tab_t) Par_GetParToUnsignedLong ("NxtTab", (unsigned long) TabUnk, Tab_NUM_TABS - 1, (unsigned long) TabUnk); Tab_DisableIncompatibleTabs (); } else // Set tab depending on current action Tab_SetCurrentTab (); }
void Not_ShowNotices (Not_Listing_t TypeNoticesListing,bool ICanEditNotices) { extern const char *Txt_All_notices; extern const char *Txt_No_notices; char Query[512]; MYSQL_RES *mysql_res; MYSQL_ROW row; char StrWidth[10+2+1]; char PathRelRSSFile[PATH_MAX+1]; long NotCod; unsigned long NumNot; unsigned long NumNotices; char Content[Cns_MAX_BYTES_TEXT+1]; time_t TimeUTC; long UsrCod; unsigned UnsignedNum; Not_Status_t Status; /***** A course must be selected (Gbl.CurrentCrs.Crs.CrsCod > 0) *****/ if (Gbl.CurrentCrs.Crs.CrsCod > 0) { /***** Get notices from database *****/ switch (TypeNoticesListing) { case Not_LIST_BRIEF_NOTICES: sprintf (Query,"SELECT NotCod,UNIX_TIMESTAMP(CreatTime) AS F,UsrCod,Content,Status" " FROM notices" " WHERE CrsCod='%ld' AND Status='%u'" " ORDER BY CreatTime DESC", Gbl.CurrentCrs.Crs.CrsCod, (unsigned) Not_ACTIVE_NOTICE); break; case Not_LIST_FULL_NOTICES: sprintf (Query,"SELECT NotCod,UNIX_TIMESTAMP(CreatTime) AS F,UsrCod,Content,Status" " FROM notices" " WHERE CrsCod='%ld'" " ORDER BY CreatTime DESC", Gbl.CurrentCrs.Crs.CrsCod); break; } NumNotices = DB_QuerySELECT (Query,&mysql_res,"can not get notices from database"); if (TypeNoticesListing == Not_LIST_FULL_NOTICES) { if (NumNotices) { /***** Start frame *****/ sprintf (StrWidth,"%upx", Not_ContainerWidth[Not_LIST_FULL_NOTICES] + 50); Lay_StartRoundFrame (StrWidth,Txt_All_notices); } else Lay_ShowAlert (Lay_INFO,Txt_No_notices); } /***** Link to RSS file *****/ if (TypeNoticesListing == Not_LIST_BRIEF_NOTICES) { /* Create RSS file if not exists */ sprintf (PathRelRSSFile,"%s/%s/%ld/%s/%s", Cfg_PATH_SWAD_PUBLIC,Cfg_FOLDER_CRS,Gbl.CurrentCrs.Crs.CrsCod,Cfg_RSS_FOLDER,Cfg_RSS_FILE); if (!Fil_CheckIfPathExists (PathRelRSSFile)) RSS_UpdateRSSFileForACrs (&Gbl.CurrentCrs.Crs); /* Put a link to the RSS file */ fprintf (Gbl.F.Out,"<div class=\"CENTER_MIDDLE\">" "<a href=\""); RSS_WriteRSSLink (Gbl.F.Out,Gbl.CurrentCrs.Crs.CrsCod); fprintf (Gbl.F.Out,"\" target=\"_blank\">" "<img src=\"%s/rss16x16.gif\"" " alt=\"RSS\" title=\"RSS\"" " class=\"ICON20x20\" />" "</a>" "</div>", Gbl.Prefs.IconsURL); } /***** Show the notices *****/ for (NumNot = 0; NumNot < NumNotices; NumNot++) { row = mysql_fetch_row (mysql_res); /* Get notice code (row[0]) */ if (sscanf (row[0],"%ld",&NotCod) != 1) Lay_ShowErrorAndExit ("Wrong code of notice."); /* Get creation time (row[1] holds the UTC date-time) */ TimeUTC = Dat_GetUNIXTimeFromStr (row[1]); /* Get user code (row[2]) */ UsrCod = Str_ConvertStrCodToLongCod (row[2]); /* Get the content (row[3]) and insert links */ strncpy (Content,row[3],Cns_MAX_BYTES_TEXT); Str_InsertLinks (Content,Cns_MAX_BYTES_TEXT, Not_MaxCharsURLOnScreen[TypeNoticesListing]); if (TypeNoticesListing == Not_LIST_BRIEF_NOTICES) Str_LimitLengthHTMLStr (Content,Not_MAX_CHARS_ON_NOTICE); /* Get status of the notice (row[4]) */ Status = Not_OBSOLETE_NOTICE; if (sscanf (row[4],"%u",&UnsignedNum) == 1) if (UnsignedNum < Not_NUM_STATUS) Status = (Not_Status_t) UnsignedNum; /* Draw the notice */ Not_DrawANotice (TypeNoticesListing, NotCod, TimeUTC,Content,UsrCod,Status, ICanEditNotices); } if (TypeNoticesListing == Not_LIST_FULL_NOTICES && NumNotices) /***** End frame *****/ Lay_EndRoundFrame (); /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); /***** Mark possible notification as seen *****/ Ntf_MarkNotifAsSeen (Ntf_EVENT_NOTICE, -1L,Gbl.CurrentCrs.Crs.CrsCod, Gbl.Usrs.Me.UsrDat.UsrCod); } }