Exemple #1
0
static unsigned Sch_SearchDegreesInDB (const char *RangeQuery)
  {
   char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
   MYSQL_RES *mysql_res;
   unsigned NumDegs;

   /***** Check scope *****/
   if (Gbl.Scope.Current != Hie_CRS)
      /***** Check user's permission *****/
      if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_DEGREES))
	 /***** Split degree string into words *****/
	 if (Sch_BuildSearchQuery (SearchQuery,"degrees.FullName",NULL,NULL))
	   {
	    /***** Query database and list degrees found *****/
	    NumDegs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get degrees",
						 "SELECT degrees.DegCod"
						 " FROM degrees,centres,institutions,countries"
						 " WHERE %s"
						 " AND degrees.CtrCod=centres.CtrCod"
						 " AND centres.InsCod=institutions.InsCod"
						 " AND institutions.CtyCod=countries.CtyCod"
						 "%s"
						 " ORDER BY degrees.FullName,institutions.FullName",
						 SearchQuery,RangeQuery);
	    Deg_ListDegsFound (&mysql_res,NumDegs);
	    return NumDegs;
	   }

   return 0;
  }
Exemple #2
0
unsigned Pag_GetLastPageMsgFromSession (Pag_WhatPaginate_t WhatPaginate)
  {
   MYSQL_RES *mysql_res;
   MYSQL_ROW row;
   unsigned long NumRows;
   unsigned NumPage;

   /***** Get last page of received/sent messages from database *****/
   NumRows = DB_QuerySELECT (&mysql_res,"can not get last page of messages",
			     "SELECT %s FROM sessions"
			     " WHERE SessionId='%s'",
			     WhatPaginate == Pag_MESSAGES_RECEIVED ? "LastPageMsgRcv" :
								     "LastPageMsgSnt",
			     Gbl.Session.Id);

   /***** Check number of rows of the result ****/
   if (NumRows != 1)
      Lay_ShowErrorAndExit ("Error when getting last page of messages.");

   /***** Get last page of messages *****/
   row = mysql_fetch_row (mysql_res);
   if (sscanf (row[0],"%u",&NumPage) == 1)
      if (NumPage == 0)
         NumPage = 1;

   return NumPage;
  }
Exemple #3
0
static void Ban_EditBannersInternal (void)
  {
   extern const char *Hlp_SYSTEM_Banners_edit;
   extern const char *Txt_Banners;
   MYSQL_RES *mysql_res;
   unsigned long NumRows;

   /***** Get list of banners *****/
   NumRows = DB_QuerySELECT (&mysql_res,"can not get banners",
			     "SELECT BanCod,Hidden,ShortName,FullName,Img,WWW"
			     " FROM banners ORDER BY ShortName");
   Ban_GetListBanners (&mysql_res,NumRows);

   /***** Start box *****/
   Box_StartBox (NULL,Txt_Banners,Ban_PutIconsEditingBanners,
                 Hlp_SYSTEM_Banners_edit,Box_NOT_CLOSABLE);

   /***** Put a form to create a new banner *****/
   Ban_PutFormToCreateBanner ();

   /***** Forms to edit current banners *****/
   if (Gbl.Banners.Num)
      Ban_ListBannersForEdition ();

   /***** End box *****/
   Box_EndBox ();

   /***** Free list of banners *****/
   Ban_FreeListBanners ();
  }
Exemple #4
0
static unsigned Sch_SearchCoursesInDB (const char *RangeQuery)
  {
   char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
   MYSQL_RES *mysql_res;
   unsigned NumCrss;

   /***** Check user's permission *****/
   if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_COURSES))
      /***** Split course string into words *****/
      if (Sch_BuildSearchQuery (SearchQuery,"courses.FullName",NULL,NULL))
	{
	 /***** Query database and list courses found *****/
	 NumCrss = (unsigned) DB_QuerySELECT (&mysql_res,"can not get courses",
					      "SELECT degrees.DegCod,courses.CrsCod,degrees.ShortName,degrees.FullName,"
					      "courses.Year,courses.FullName,centres.ShortName"
					      " FROM courses,degrees,centres,institutions,countries"
					      " WHERE %s"
					      " AND courses.DegCod=degrees.DegCod"
					      " AND degrees.CtrCod=centres.CtrCod"
					      " AND centres.InsCod=institutions.InsCod"
					      " AND institutions.CtyCod=countries.CtyCod"
					      "%s"
					      " ORDER BY courses.FullName,institutions.FullName,degrees.FullName,courses.Year",
					      SearchQuery,RangeQuery);
	 Crs_ListCrssFound (&mysql_res,NumCrss);
	 return NumCrss;
	}

   return 0;
  }
Exemple #5
0
static unsigned Sch_SearchInstitutionsInDB (const char *RangeQuery)
  {
   extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
   char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
   MYSQL_RES *mysql_res;
   unsigned NumInss;

   /***** Check scope *****/
   if (Gbl.Scope.Current != Hie_CTR &&
       Gbl.Scope.Current != Hie_DEG &&
       Gbl.Scope.Current != Hie_CRS)
      /***** Check user's permission *****/
      if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_INSTITS))
	 /***** Split institutions string into words *****/
	 if (Sch_BuildSearchQuery (SearchQuery,"institutions.FullName",NULL,NULL))
	   {
	    /***** Query database and list institutions found *****/
	    NumInss = (unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions",
				                 "SELECT institutions.InsCod"
						 " FROM institutions,countries"
						 " WHERE %s"
						 " AND institutions.CtyCod=countries.CtyCod"
						 "%s"
						 " ORDER BY institutions.FullName,countries.Name_%s",
						 SearchQuery,RangeQuery,
						 Lan_STR_LANG_ID[Gbl.Prefs.Language]);
	    Ins_ListInssFound (&mysql_res,NumInss);
	    return NumInss;
	   }

   return 0;
  }
Exemple #6
0
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);
  }
Exemple #7
0
void Ban_GetDataOfBannerByCod (struct Banner *Ban)
  {
   MYSQL_RES *mysql_res;
   MYSQL_ROW row;
   unsigned long NumRows;

   /***** Clear data *****/
   Ban->Hidden = false;
   Ban->ShrtName[0] = Ban->FullName[0] = Ban->Img[0] = Ban->WWW[0] = '\0';

   /***** Check if banner code is correct *****/
   if (Ban->BanCod > 0)
     {
      /***** Get data of a banner from database *****/
      NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a banner",
				"SELECT Hidden,ShortName,FullName,Img,WWW"
			        " FROM banners WHERE BanCod=%ld",
			        Ban->BanCod);
      if (NumRows) // Banner found...
        {
         /* Get row */
         row = mysql_fetch_row (mysql_res);

         /* Get if the banner is hidden (row[0]) */
         Ban->Hidden = (row[0][0] == 'Y');

         /* Get the short name of the banner (row[1]) */
         Str_Copy (Ban->ShrtName,row[1],
                   Ban_MAX_BYTES_SHRT_NAME);

         /* Get the full name of the banner (row[2]) */
         Str_Copy (Ban->FullName,row[2],
                   Ban_MAX_BYTES_FULL_NAME);

         /* Get the image of the banner (row[3]) */
         Str_Copy (Ban->Img,row[3],
                   Ban_MAX_BYTES_IMAGE);

         /* Get the URL of the banner (row[4]) */
         Str_Copy (Ban->WWW,row[4],
                   Cns_MAX_BYTES_WWW);
        }

      /***** Free structure that stores the query result *****/
      DB_FreeMySQLResult (&mysql_res);
     }
  }
Exemple #8
0
void Net_ShowWebsAndSocialNets (const struct UsrData *UsrDat)
  {
   MYSQL_RES *mysql_res;
   MYSQL_ROW row;
   Net_WebsAndSocialNetworks_t NumURL;
   char URL[Cns_MAX_BYTES_WWW + 1];

   /***** Start container *****/
   fprintf (Gbl.F.Out,"<div class=\"REC_WEBS\">");

   /***** Show link to public profile *****/
   Net_ShowAWebOrSocialNet (Prf_GetURLPublicProfile (URL,UsrDat->Nickname),
                            "swad64x64.png",Cfg_PLATFORM_SHORT_NAME);

   /***** Show the rest of webs / social networks *****/
   for (NumURL = (Net_WebsAndSocialNetworks_t) 0;
	NumURL < Net_NUM_WEBS_AND_SOCIAL_NETWORKS;
	NumURL++)
     {
      /***** Check if exists the web / social network for this user *****/
      if (DB_QuerySELECT (&mysql_res,"can not get user's web / social network",
	                  "SELECT URL FROM usr_webs"
			  " WHERE UsrCod=%ld AND Web='%s'",
			  UsrDat->UsrCod,Net_WebsAndSocialNetworksDB[NumURL]))
	{
	 /* Get URL */
	 row = mysql_fetch_row (mysql_res);
	 Str_Copy (URL,row[0],
	           Cns_MAX_BYTES_WWW);

	 /* Show the web / social network */
	 Net_ShowAWebOrSocialNet (URL,
	                          Net_WebsAndSocialNetworksIcons[NumURL],
	                          Net_WebsAndSocialNetworksTitle[NumURL]);
	}

      /***** Free structure that stores the query result *****/
      DB_FreeMySQLResult (&mysql_res);
     }

   /***** End container *****/
   fprintf (Gbl.F.Out,"</div>");
  }
Exemple #9
0
void Ban_WriteMenuWithBanners (void)
  {
   MYSQL_RES *mysql_res;
   unsigned long NumRows;
   unsigned NumBan;

   /***** Get random banner *****/
   // The banner(s) will change once in a while
   NumRows = DB_QuerySELECT (&mysql_res,"can not get banners",
			     "SELECT BanCod,Hidden,ShortName,FullName,Img,WWW"
			     " FROM banners"
			     " WHERE Hidden='N'"
			     " ORDER BY RAND(%lu) LIMIT %u",
			     (unsigned long) (Gbl.StartExecutionTimeUTC / Cfg_TIME_TO_CHANGE_BANNER),
			     Cfg_NUMBER_OF_BANNERS);
   Ban_GetListBanners (&mysql_res,NumRows);

   /***** Write all the banners *****/
   for (NumBan = 0;
	NumBan < Gbl.Banners.Num;
	NumBan++)
     {
      /* Write data of this banner */
      fprintf (Gbl.F.Out,"<div class=\"CENTER_MIDDLE\">");
      Frm_StartForm (ActClkBan);
      Ban_PutParamBanCod (Gbl.Banners.Lst[NumBan].BanCod);
      Par_PutHiddenParamString ("URL",Gbl.Banners.Lst[NumBan].WWW);
      Frm_LinkFormSubmit (Gbl.Banners.Lst[NumBan].FullName,"BANNER",NULL);
      fprintf (Gbl.F.Out,"<img src=\"%s/%s\""
                         " alt=\"%s\" title=\"%s\""
                         " class=\"BANNER\" />"
                         "</a>",
               Cfg_URL_BANNER_PUBLIC,
               Gbl.Banners.Lst[NumBan].Img,
               Gbl.Banners.Lst[NumBan].ShrtName,
               Gbl.Banners.Lst[NumBan].FullName);
      Frm_EndForm ();
      fprintf (Gbl.F.Out,"</div>");
     }

   /***** Free list of banners *****/
   Ban_FreeListBanners ();
  }
Exemple #10
0
void Ban_SeeBanners (void)
  {
   extern const char *Hlp_SYSTEM_Banners;
   extern const char *Txt_Banners;
   extern const char *Txt_No_banners;
   extern const char *Txt_New_banner;
   MYSQL_RES *mysql_res;
   unsigned long NumRows;

   /***** Get list of banners *****/
   NumRows = DB_QuerySELECT (&mysql_res,"can not get banners",
			     "SELECT BanCod,Hidden,ShortName,FullName,Img,WWW"
			     " FROM banners"
			     " WHERE Hidden='N'"
			     " ORDER BY ShortName");
   Ban_GetListBanners (&mysql_res,NumRows);

   /***** Start box *****/
   Box_StartBox (NULL,Txt_Banners,Ban_PutIconsListingBanners,
                 Hlp_SYSTEM_Banners,Box_NOT_CLOSABLE);

   /***** Write all banners *****/
   if (Gbl.Banners.Num)	// There are banners
      Ban_WriteListOfBanners ();
   else			// No banners created
      Ale_ShowAlert (Ale_INFO,Txt_No_banners);

   /***** Button to create banner *****/
   if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)
     {
      Frm_StartForm (ActEdiBan);
      Btn_PutConfirmButton (Txt_New_banner);
      Frm_EndForm ();
     }

   /***** End box *****/
   Box_EndBox ();

   /***** Free list of banners *****/
   Ban_FreeListBanners ();
  }
Exemple #11
0
static unsigned Sch_SearchCountriesInDB (const char *RangeQuery)
  {
   extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
   char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
   char FieldName[4+1+2+1];	// Example: Name_en
   MYSQL_RES *mysql_res;
   unsigned NumCtys;

   /***** Check scope *****/
   if (Gbl.Scope.Current != Hie_INS &&
       Gbl.Scope.Current != Hie_CTR &&
       Gbl.Scope.Current != Hie_DEG &&
       Gbl.Scope.Current != Hie_CRS)
      /***** Check user's permission *****/
      if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_COUNTRIES))
	{
	 /***** Split countries string into words *****/
	 snprintf (FieldName,sizeof (FieldName),
	           "Name_%s",
		   Lan_STR_LANG_ID[Gbl.Prefs.Language]);
	 if (Sch_BuildSearchQuery (SearchQuery,FieldName,NULL,NULL))
	   {
	    /***** Query database and list institutions found *****/
	    NumCtys = (unsigned) DB_QuerySELECT (&mysql_res,"can not get countries",
						 "SELECT CtyCod"
						 " FROM countries"
						 " WHERE %s%s"
						 " ORDER BY Name_%s",
						 SearchQuery,RangeQuery,
						 Lan_STR_LANG_ID[Gbl.Prefs.Language]);
	    Cty_ListCtysFound (&mysql_res,NumCtys);
	    return NumCtys;
	   }
	}

   return 0;
  }
Exemple #12
0
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 e-mail *****/
   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;
  }
Exemple #13
0
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);
     }
  }
Exemple #14
0
static unsigned Sch_SearchMyDocumentsInDB (const char *RangeQuery)
  {
   extern const char *Txt_document_from_me;
   extern const char *Txt_documents_from_me;
   char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
   MYSQL_RES *mysql_res;
   unsigned long NumDocs;

   /***** Check user's permission *****/
   if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_MY_DOCUMENTS))
      /***** Split document string into words *****/
      if (Sch_BuildSearchQuery (SearchQuery,"SUBSTRING_INDEX(files.Path,'/',-1)",
				"_latin1 "," COLLATE latin1_general_ci"))
	{
	 /***** Build the query *****/
	 NumDocs = DB_QuerySELECT (&mysql_res,"can not get files",
				   "SELECT * FROM "
				   "("
				   "SELECT files.FilCod,"	// Institution
				   "SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot,"
				   "institutions.InsCod,institutions.ShortName AS InsShortName,"
				   "-1 AS CtrCod,'' AS CtrShortName,"
				   "-1 AS DegCod,'' AS DegShortName,"
				   "-1 AS CrsCod,'' AS CrsShortName,"
				   "-1 AS GrpCod"
				   " FROM files,courses,degrees,centres,institutions,countries"
				   " WHERE files.PublisherUsrCod=%ld AND %s"
				   " AND files.FileBrowser IN (%u,%u)"
				   " AND files.Cod=institutions.InsCod"
				   " AND institutions.CtyCod=countries.CtyCod"
				   "%s"
				   " UNION "
				   "SELECT files.FilCod,"	// Centre
				   "SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot,"
				   "institutions.InsCod,institutions.ShortName AS InsShortName,"
				   "centres.CtrCod,centres.ShortName AS CtrShortName,"
				   "-1 AS DegCod,'' AS DegShortName,"
				   "-1 AS CrsCod,'' AS CrsShortName,"
				   "-1 AS GrpCod"
				   " FROM files,courses,degrees,centres,institutions,countries"
				   " WHERE files.PublisherUsrCod=%ld AND %s"
				   " AND files.FileBrowser IN (%u,%u)"
				   " AND files.Cod=centres.CtrCod"
				   " AND centres.InsCod=institutions.InsCod"
				   " AND institutions.CtyCod=countries.CtyCod"
				   "%s"
				   " UNION "
				   "SELECT files.FilCod,"	// Degree
				   "SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot,"
				   "institutions.InsCod,institutions.ShortName AS InsShortName,"
				   "centres.CtrCod,centres.ShortName AS CtrShortName,"
				   "degrees.DegCod,degrees.ShortName AS DegShortName,"
				   "-1 AS CrsCod,'' AS CrsShortName,"
				   "-1 AS GrpCod"
				   " FROM files,courses,degrees,centres,institutions,countries"
				   " WHERE files.PublisherUsrCod=%ld AND %s"
				   " AND files.FileBrowser IN (%u,%u)"
				   " AND files.Cod=degrees.DegCod"
				   " AND degrees.CtrCod=centres.CtrCod"
				   " AND centres.InsCod=institutions.InsCod"
				   " AND institutions.CtyCod=countries.CtyCod"
				   "%s"
				   " UNION "
				   "SELECT files.FilCod,"	// Course
				   "SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot,"
				   "institutions.InsCod,institutions.ShortName AS InsShortName,"
				   "centres.CtrCod,centres.ShortName AS CtrShortName,"
				   "degrees.DegCod,degrees.ShortName AS DegShortName,"
				   "courses.CrsCod,courses.ShortName AS CrsShortName,"
				   "-1 AS GrpCod"
				   " FROM files,courses,degrees,centres,institutions,countries"
				   " WHERE files.PublisherUsrCod=%ld AND %s"
				   " AND files.FileBrowser IN (%u,%u,%u,%u)"
				   " AND files.Cod=courses.CrsCod"
				   " AND courses.DegCod=degrees.DegCod"
				   " AND degrees.CtrCod=centres.CtrCod"
				   " AND centres.InsCod=institutions.InsCod"
				   " AND institutions.CtyCod=countries.CtyCod"
				   "%s"
				   " UNION "
				   "SELECT files.FilCod,"	// Group
				   "SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot,"
				   "institutions.InsCod,institutions.ShortName AS InsShortName,"
				   "centres.CtrCod,centres.ShortName AS CtrShortName,"
				   "degrees.DegCod,degrees.ShortName AS DegShortName,"
				   "courses.CrsCod,courses.ShortName AS CrsShortName,"
				   "crs_grp.GrpCod"
				   " FROM files,crs_grp,crs_grp_types,courses,degrees,centres,institutions,countries"
				   " WHERE files.PublisherUsrCod=%ld AND %s"
				   " AND files.FileBrowser IN (%u,%u,%u,%u)"
				   " AND files.Cod=crs_grp.GrpCod"
				   " AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod"
				   " AND crs_grp_types.CrsCod=courses.CrsCod"
				   " AND courses.DegCod=degrees.DegCod"
				   " AND degrees.CtrCod=centres.CtrCod"
				   " AND centres.InsCod=institutions.InsCod"
				   " AND institutions.CtyCod=countries.CtyCod"
				   "%s"
				   " UNION "
				   "SELECT files.FilCod,"	// Briefcase
				   "SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot,"
				   "-1 AS InsCod,'' AS InsShortName,"
				   "-1 AS CtrCod,'' AS CtrShortName,"
				   "-1 AS DegCod,'' AS DegShortName,"
				   "-1 AS CrsCod,'' AS CrsShortName,"
				   "-1 AS GrpCod"
				   " FROM files"
				   " WHERE files.PublisherUsrCod=%ld AND %s"
				   " AND files.FileBrowser=%u"
				   ") AS selected_files"
				   " WHERE PathFromRoot<>''"
				   " ORDER BY InsShortName,CtrShortName,DegShortName,CrsShortName,PathFromRoot",
				   Gbl.Usrs.Me.UsrDat.UsrCod,SearchQuery,
				   (unsigned) Brw_ADMI_DOC_INS,
				   (unsigned) Brw_ADMI_SHR_INS,
				   RangeQuery,
				   Gbl.Usrs.Me.UsrDat.UsrCod,SearchQuery,
				   (unsigned) Brw_ADMI_DOC_CTR,
				   (unsigned) Brw_ADMI_SHR_CTR,
				   RangeQuery,
				   Gbl.Usrs.Me.UsrDat.UsrCod,SearchQuery,
				   (unsigned) Brw_ADMI_DOC_DEG,
				   (unsigned) Brw_ADMI_SHR_DEG,
				   RangeQuery,
				   Gbl.Usrs.Me.UsrDat.UsrCod,SearchQuery,
				   (unsigned) Brw_ADMI_DOC_CRS,
				   (unsigned) Brw_ADMI_TCH_CRS,
				   (unsigned) Brw_ADMI_SHR_CRS,
				   (unsigned) Brw_ADMI_MRK_CRS,
				   RangeQuery,
				   Gbl.Usrs.Me.UsrDat.UsrCod,SearchQuery,
				   (unsigned) Brw_ADMI_DOC_GRP,
				   (unsigned) Brw_ADMI_TCH_GRP,
				   (unsigned) Brw_ADMI_SHR_GRP,
				   (unsigned) Brw_ADMI_MRK_GRP,
				   RangeQuery,
				   Gbl.Usrs.Me.UsrDat.UsrCod,SearchQuery,
				   (unsigned) Brw_ADMI_BRF_USR);

	 /***** List documents found *****/
	 Brw_ListDocsFound (&mysql_res,NumDocs,
			    Txt_document_from_me,
	                    Txt_documents_from_me);

	 return (unsigned) NumDocs;
	}

   return 0;
  }
Exemple #15
0
static unsigned Sch_SearchDocumentsInMyCoursesInDB (const char *RangeQuery)
  {
   extern const char *Txt_document_in_my_courses;
   extern const char *Txt_documents_in_my_courses;
   char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
   MYSQL_RES *mysql_res;
   unsigned long NumDocs;

   /***** Check user's permission *****/
   if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_DOCUM_IN_MY_COURSES))
      /***** Split document string into words *****/
      if (Sch_BuildSearchQuery (SearchQuery,"SUBSTRING_INDEX(files.Path,'/',-1)",
				"_latin1 "," COLLATE latin1_general_ci"))
	{
	 /***** Create temporary table with codes of files in documents and shared areas accessible by me.
		It is necessary to speed up the second query *****/
	 DB_Query ("can not remove temporary table",
	           "DROP TEMPORARY TABLE IF EXISTS my_files_crs,my_files_grp");

	 DB_Query ("can not create temporary table",
		   "CREATE TEMPORARY TABLE my_files_crs"
		   " (FilCod INT NOT NULL,UNIQUE INDEX(FilCod))"
		   " ENGINE=MEMORY"
		   " SELECT files.FilCod FROM crs_usr,files"
		   " WHERE crs_usr.UsrCod=%ld"
		   " AND crs_usr.CrsCod=files.Cod"
		   " AND files.FileBrowser IN (%u,%u,%u,%u)",
		   Gbl.Usrs.Me.UsrDat.UsrCod,
		   (unsigned) Brw_ADMI_DOC_CRS,
		   (unsigned) Brw_ADMI_TCH_CRS,
		   (unsigned) Brw_ADMI_SHR_CRS,
		   (unsigned) Brw_ADMI_MRK_CRS);

	 DB_Query ("can not create temporary table",
	           "CREATE TEMPORARY TABLE my_files_grp"
		   " (FilCod INT NOT NULL,UNIQUE INDEX(FilCod))"
		   " ENGINE=MEMORY"
		   " SELECT files.FilCod FROM crs_grp_usr,files"
		   " WHERE crs_grp_usr.UsrCod=%ld"
		   " AND crs_grp_usr.GrpCod=files.Cod"
		   " AND files.FileBrowser IN (%u,%u,%u,%u)",
		   Gbl.Usrs.Me.UsrDat.UsrCod,
		   (unsigned) Brw_ADMI_DOC_GRP,
		   (unsigned) Brw_ADMI_TCH_GRP,
		   (unsigned) Brw_ADMI_SHR_GRP,
		   (unsigned) Brw_ADMI_MRK_GRP);

	 /***** Build the query *****/
	 NumDocs = DB_QuerySELECT (&mysql_res,"can not get files",
				   "SELECT * FROM "
				   "("
				   "SELECT files.FilCod,"
				   "SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot,"
				   "institutions.InsCod,institutions.ShortName AS InsShortName,"
				   "centres.CtrCod,centres.ShortName AS CtrShortName,"
				   "degrees.DegCod,degrees.ShortName AS DegShortName,"
				   "courses.CrsCod,courses.ShortName AS CrsShortName,"
				   "-1 AS GrpCod"
				   " FROM files,courses,degrees,centres,institutions,countries"
				   " WHERE files.FilCod IN (SELECT FilCod FROM my_files_crs) AND %s"
				   " AND files.FileBrowser IN (%u,%u,%u,%u)"
				   " AND files.Cod=courses.CrsCod"
				   " AND courses.DegCod=degrees.DegCod"
				   " AND degrees.CtrCod=centres.CtrCod"
				   " AND centres.InsCod=institutions.InsCod"
				   " AND institutions.CtyCod=countries.CtyCod"
				   "%s"
				   " UNION "
				   "SELECT files.FilCod,"
				   "SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot,"
				   "institutions.InsCod,institutions.ShortName AS InsShortName,"
				   "centres.CtrCod,centres.ShortName AS CtrShortName,"
				   "degrees.DegCod,degrees.ShortName AS DegShortName,"
				   "courses.CrsCod,courses.ShortName AS CrsShortName,"
				   "crs_grp.GrpCod"
				   " FROM files,crs_grp,crs_grp_types,courses,degrees,centres,institutions,countries"
				   " WHERE files.FilCod IN (SELECT FilCod FROM my_files_grp) AND %s"
				   " AND files.FileBrowser IN (%u,%u,%u,%u)"
				   " AND files.Cod=crs_grp.GrpCod"
				   " AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod"
				   " AND crs_grp_types.CrsCod=courses.CrsCod"
				   " AND courses.DegCod=degrees.DegCod"
				   " AND degrees.CtrCod=centres.CtrCod"
				   " AND centres.InsCod=institutions.InsCod"
				   " AND institutions.CtyCod=countries.CtyCod"
				   "%s"
				   ") AS selected_files"
				   " WHERE PathFromRoot<>''"
				   " ORDER BY InsShortName,CtrShortName,DegShortName,CrsShortName,PathFromRoot",
				   SearchQuery,
				   (unsigned) Brw_ADMI_DOC_CRS,
				   (unsigned) Brw_ADMI_TCH_CRS,
				   (unsigned) Brw_ADMI_SHR_CRS,
				   (unsigned) Brw_ADMI_MRK_CRS,
				   RangeQuery,
				   SearchQuery,
				   (unsigned) Brw_ADMI_DOC_GRP,
				   (unsigned) Brw_ADMI_TCH_GRP,
				   (unsigned) Brw_ADMI_SHR_GRP,
				   (unsigned) Brw_ADMI_MRK_GRP,
				   RangeQuery);

	 /***** List documents found *****/
	 Brw_ListDocsFound (&mysql_res,NumDocs,
	                    Txt_document_in_my_courses,
	                    Txt_documents_in_my_courses);

	 /***** Drop temporary table *****/
	 DB_Query ("can not remove temporary table",
		   "DROP TEMPORARY TABLE IF EXISTS my_files_crs,my_files_grp");

	 return (unsigned) NumDocs;
	}

   return 0;
  }
Exemple #16
0
static unsigned Sch_SearchOpenDocumentsInDB (const char *RangeQuery)
  {
   extern const char *Txt_open_document;
   extern const char *Txt_open_documents;
   char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
   MYSQL_RES *mysql_res;
   unsigned long NumDocs;

   /***** Check user's permission *****/
   if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_OPEN_DOCUMENTS))
      /***** Split document string into words *****/
      if (Sch_BuildSearchQuery (SearchQuery,"SUBSTRING_INDEX(files.Path,'/',-1)",
				"_latin1 "," COLLATE latin1_general_ci"))
	{
	 /***** Query database *****/
	 NumDocs = DB_QuerySELECT (&mysql_res,"can not get files",
				   "SELECT * FROM "
				   "("
				   "SELECT files.FilCod,"	// Institution
				   "SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot,"
				   "institutions.InsCod,institutions.ShortName AS InsShortName,"
				   "-1 AS CtrCod,'' AS CtrShortName,"
				   "-1 AS DegCod,'' AS DegShortName,"
				   "-1 AS CrsCod,'' AS CrsShortName,"
				   "-1 AS GrpCod"
				   " FROM files,courses,degrees,centres,institutions,countries"
				   " WHERE files.Public='Y' AND %s"
				   " AND files.FileBrowser IN (%u,%u)"
				   " AND files.Cod=institutions.InsCod"
				   " AND institutions.CtyCod=countries.CtyCod"
				   "%s"
				   " UNION "
				   "SELECT files.FilCod,"	// Centre
				   "SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot,"
				   "institutions.InsCod,institutions.ShortName AS InsShortName,"
				   "centres.CtrCod,centres.ShortName AS CtrShortName,"
				   "-1 AS DegCod,'' AS DegShortName,"
				   "-1 AS CrsCod,'' AS CrsShortName,"
				   "-1 AS GrpCod"
				   " FROM files,courses,degrees,centres,institutions,countries"
				   " WHERE files.Public='Y' AND %s"
				   " AND files.FileBrowser IN (%u,%u)"
				   " AND files.Cod=centres.CtrCod"
				   " AND centres.InsCod=institutions.InsCod"
				   " AND institutions.CtyCod=countries.CtyCod"
				   "%s"
				   " UNION "
				   "SELECT files.FilCod,"	// Degree
				   "SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot,"
				   "institutions.InsCod,institutions.ShortName AS InsShortName,"
				   "centres.CtrCod,centres.ShortName AS CtrShortName,"
				   "degrees.DegCod,degrees.ShortName AS DegShortName,"
				   "-1,'' AS CrsShortName,"
				   "-1"
				   " FROM files,courses,degrees,centres,institutions,countries"
				   " WHERE files.Public='Y' AND %s"
				   " AND files.FileBrowser IN (%u,%u)"
				   " AND files.Cod=degrees.DegCod"
				   " AND degrees.CtrCod=centres.CtrCod"
				   " AND centres.InsCod=institutions.InsCod"
				   " AND institutions.CtyCod=countries.CtyCod"
				   "%s"
				   " UNION "
				   "SELECT files.FilCod,"	// Course
				   "SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot,"
				   "institutions.InsCod,institutions.ShortName AS InsShortName,"
				   "centres.CtrCod,centres.ShortName AS CtrShortName,"
				   "degrees.DegCod,degrees.ShortName AS DegShortName,"
				   "courses.CrsCod,courses.ShortName AS CrsShortName,"
				   "-1"
				   " FROM files,courses,degrees,centres,institutions,countries"
				   " WHERE files.Public='Y' AND %s"
				   " AND files.FileBrowser IN (%u,%u)"
				   " AND files.Cod=courses.CrsCod"
				   " AND courses.DegCod=degrees.DegCod"
				   " AND degrees.CtrCod=centres.CtrCod"
				   " AND centres.InsCod=institutions.InsCod"
				   " AND institutions.CtyCod=countries.CtyCod"
				   "%s"
				   ") AS selected_files"
				   " WHERE PathFromRoot<>''"
				   " ORDER BY InsShortName,CtrShortName,DegShortName,CrsShortName,PathFromRoot",
				   SearchQuery,
				   (unsigned) Brw_ADMI_DOC_INS,
				   (unsigned) Brw_ADMI_SHR_INS,
				   RangeQuery,
				   SearchQuery,
				   (unsigned) Brw_ADMI_DOC_CTR,
				   (unsigned) Brw_ADMI_SHR_CTR,
				   RangeQuery,
				   SearchQuery,
				   (unsigned) Brw_ADMI_DOC_DEG,
				   (unsigned) Brw_ADMI_SHR_DEG,
				   RangeQuery,
				   SearchQuery,
				   (unsigned) Brw_ADMI_DOC_CRS,
				   (unsigned) Brw_ADMI_SHR_CRS,
				   RangeQuery);

	 /***** List documents found *****/
	 Brw_ListDocsFound (&mysql_res,NumDocs,
			    Txt_open_document,
	                    Txt_open_documents);

	 return (unsigned) NumDocs;
	}

   return 0;
  }
Exemple #17
0
void Net_ShowFormMyWebsAndSocialNets (void)
  {
   extern const char *Hlp_PROFILE_Webs;
   extern const char *The_ClassFormInBox[The_NUM_THEMES];
   extern const char *Txt_Webs_social_networks;
   extern const char *Txt_Save_changes;
   MYSQL_RES *mysql_res;
   MYSQL_ROW row;
   Net_WebsAndSocialNetworks_t NumURL;
   char URL[Cns_MAX_BYTES_WWW + 1];
   char StrRecordWidth[10 + 1];

   /***** Start section *****/
   Lay_StartSection (Net_MY_WEBS_ID);

   /***** Start box *****/
   snprintf (StrRecordWidth,sizeof (StrRecordWidth),
	     "%upx",
	     Rec_RECORD_WIDTH);
   Box_StartBox (StrRecordWidth,Txt_Webs_social_networks,
	         Net_PutIconsWebsSocialNetworks,
                 Hlp_PROFILE_Webs,Box_NOT_CLOSABLE);

   /***** Start table *****/
   Tbl_StartTable (2);

   /***** Start form *****/
   Frm_StartFormAnchor (ActChgMyNet,Net_MY_WEBS_ID);

   /***** List webs and social networks *****/
   for (NumURL = (Net_WebsAndSocialNetworks_t) 0;
	NumURL < Net_NUM_WEBS_AND_SOCIAL_NETWORKS;
	NumURL++)
     {
      /***** Get user's web / social network from database *****/
      if (DB_QuerySELECT (&mysql_res,"can not get user's web / social network",
			  "SELECT URL FROM usr_webs"
			  " WHERE UsrCod=%ld AND Web='%s'",
			  Gbl.Usrs.Me.UsrDat.UsrCod,
			  Net_WebsAndSocialNetworksDB[NumURL]))
	{
	 /***** Read the data comunes a all the users *****/
	 row = mysql_fetch_row (mysql_res);

	 /* Get URL */
	 Str_Copy (URL,row[0],
	           Cns_MAX_BYTES_WWW);
	}
      else
	 URL[0] = '\0';

      /***** Free structure that stores the query result *****/
      DB_FreeMySQLResult (&mysql_res);

      /***** Row for this web / social network *****/
      fprintf (Gbl.F.Out,"<tr>"

			 "<td class=\"REC_C1_BOT LEFT_MIDDLE\">"
			 "<label for=\"URL%u\" class=\"%s\">"
			 "<img src=\"%s/%s\""
			 " alt=\"%s\" title=\"%s\""
                         " class=\"CONTEXT_ICO_16x16\""
			 " style=\"margin-right:6px;\" />"
			 "%s:"
			 "</label>"
			 "</td>"

			 "<td class=\"REC_C2_BOT LEFT_MIDDLE\">"
			 "<input type=\"url\" id=\"URL%u\" name=\"URL%u\""
			 " maxlength=\"%u\" value=\"%s\""
		         " class=\"REC_C2_BOT_INPUT\" />"
			 "</td>"

			 "</tr>",
	       (unsigned) NumURL,The_ClassFormInBox[Gbl.Prefs.Theme],
	       Cfg_URL_ICON_PUBLIC,Net_WebsAndSocialNetworksIcons[NumURL],
	       Net_WebsAndSocialNetworksTitle[NumURL],
	       Net_WebsAndSocialNetworksTitle[NumURL],
	       Net_WebsAndSocialNetworksTitle[NumURL],
	       (unsigned) NumURL,(unsigned) NumURL,
	       Cns_MAX_CHARS_WWW,URL);
     }

   /***** End table *****/
   Tbl_EndTable ();

   /***** Confirm button *****/
   Btn_PutConfirmButton (Txt_Save_changes);

   /***** End form *****/
   Frm_EndForm ();

   /***** End box *****/
   Box_EndBox ();

   /***** End section *****/
   Lay_EndSection ();
  }
Exemple #18
0
void Net_ShowWebAndSocialNetworksStats (void)
  {
   extern const char *Hlp_ANALYTICS_Figures_webs_social_networks;
   extern const char *Txt_FIGURE_TYPES[Fig_NUM_FIGURES];
   extern const char *Txt_Web_social_network;
   extern const char *Txt_No_of_users;
   extern const char *Txt_PERCENT_of_users;
   MYSQL_RES *mysql_res;
   MYSQL_ROW row;
   unsigned NumRows = 0;	// Initialized to avoid warning
   unsigned NumRow;
   Net_WebsAndSocialNetworks_t Web;
   char NetName[Net_MAX_BYTES_NETWORK_NAME + 1];
   unsigned NumUsrsTotal;
   unsigned NumUsrs;

   /***** Get total number of users in current scope *****/
   NumUsrsTotal = (Gbl.Scope.Current == Hie_SYS) ? Usr_GetTotalNumberOfUsersInPlatform () :
                                                         Usr_GetTotalNumberOfUsersInCourses (Gbl.Scope.Current,
                                                                                             1 << Rol_STD |
                                                                                             1 << Rol_NET |
                                                                                             1 << Rol_TCH);

   /***** Get number of users with a web / social network *****/
   switch (Gbl.Scope.Current)
     {
      case Hie_SYS:
         NumRows =
         (unsigned) DB_QuerySELECT (&mysql_res,"can not get number of users"
					       " with webs / social networks",
				    "SELECT Web,COUNT(*) AS N"
				    " FROM usr_webs"
				    " GROUP BY Web"
				    " ORDER BY N DESC,Web");
         break;
      case Hie_CTY:
         NumRows =
         (unsigned) DB_QuerySELECT (&mysql_res,"can not get number of users"
					       " with webs / social networks",
				    "SELECT usr_webs.Web,"
				    "COUNT(DISTINCT usr_webs.UsrCod) AS N"
				    " FROM institutions,centres,degrees,courses,crs_usr,usr_webs"
				    " WHERE institutions.CtyCod=%ld"
				    " AND institutions.InsCod=centres.InsCod"
				    " AND centres.CtrCod=degrees.CtrCod"
				    " AND degrees.DegCod=courses.DegCod"
				    " AND courses.CrsCod=crs_usr.CrsCod"
				    " AND crs_usr.UsrCod=usr_webs.UsrCod"
				    " GROUP BY usr_webs.Web"
				    " ORDER BY N DESC,usr_webs.Web",
				    Gbl.Hierarchy.Cty.CtyCod);
         break;
      case Hie_INS:
         NumRows =
         (unsigned) DB_QuerySELECT (&mysql_res,"can not get number of users"
					       " with webs / social networks",
				    "SELECT usr_webs.Web,"
				    "COUNT(DISTINCT usr_webs.UsrCod) AS N"
				    " FROM centres,degrees,courses,crs_usr,usr_webs"
				    " WHERE centres.InsCod=%ld"
				    " AND centres.CtrCod=degrees.CtrCod"
				    " AND degrees.DegCod=courses.DegCod"
				    " AND courses.CrsCod=crs_usr.CrsCod"
				    " AND crs_usr.UsrCod=usr_webs.UsrCod"
				    " GROUP BY usr_webs.Web"
				    " ORDER BY N DESC,usr_webs.Web",
				    Gbl.Hierarchy.Ins.InsCod);
         break;
      case Hie_CTR:
         NumRows =
         (unsigned) DB_QuerySELECT (&mysql_res,"can not get number of users"
					       " with webs / social networks",
				    "SELECT usr_webs.Web,"
				    "COUNT(DISTINCT usr_webs.UsrCod) AS N"
				    " FROM degrees,courses,crs_usr,usr_webs"
				    " WHERE degrees.CtrCod=%ld"
				    " AND degrees.DegCod=courses.DegCod"
				    " AND courses.CrsCod=crs_usr.CrsCod"
				    " AND crs_usr.UsrCod=usr_webs.UsrCod"
				    " GROUP BY usr_webs.Web"
				    " ORDER BY N DESC,usr_webs.Web",
				    Gbl.Hierarchy.Ctr.CtrCod);
         break;
      case Hie_DEG:
         NumRows =
         (unsigned) DB_QuerySELECT (&mysql_res,"can not get number of users"
					       " with webs / social networks",
				    "SELECT usr_webs.Web,"
				    "COUNT(DISTINCT usr_webs.UsrCod) AS N"
				    " FROM courses,crs_usr,usr_webs"
				    " WHERE courses.DegCod=%ld"
				    " AND courses.CrsCod=crs_usr.CrsCod"
				    " AND crs_usr.UsrCod=usr_webs.UsrCod"
				    " GROUP BY usr_webs.Web"
				    " ORDER BY N DESC,usr_webs.Web",
				    Gbl.Hierarchy.Deg.DegCod);
         break;
      case Hie_CRS:
         NumRows =
         (unsigned) DB_QuerySELECT (&mysql_res,"can not get number of users"
					       " with webs / social networks",
				    "SELECT usr_webs.Web,"
				    "COUNT(DISTINCT usr_webs.UsrCod) AS N"
				    " FROM crs_usr,usr_webs"
				    " WHERE crs_usr.CrsCod=%ld"
				    " AND crs_usr.UsrCod=usr_webs.UsrCod"
				    " GROUP BY usr_webs.Web"
				    " ORDER BY N DESC,usr_webs.Web",
				    Gbl.Hierarchy.Crs.CrsCod);
         break;
      default:
	 Lay_WrongScopeExit ();
	 break;
     }

   /***** Start box and table *****/
   Box_StartBoxTable (NULL,Txt_FIGURE_TYPES[Fig_SOCIAL_NETWORKS],NULL,
                      Hlp_ANALYTICS_Figures_webs_social_networks,Box_NOT_CLOSABLE,2);

   /***** Write heading *****/
   fprintf (Gbl.F.Out,"<tr>"
                      "<th class=\"LEFT_MIDDLE\">"
                      "%s"
                      "</th>"
                      "<th class=\"RIGHT_MIDDLE\">"
                      "%s"
                      "</th>"
                      "<th class=\"RIGHT_MIDDLE\">"
                      "%s"
                      "</th>"
                      "</tr>",
            Txt_Web_social_network,
            Txt_No_of_users,
            Txt_PERCENT_of_users);

   /***** For each web / social network... *****/
   for (NumRow = 0;
	NumRow < NumRows;
	NumRow++)
     {
      /* Get row */
      row = mysql_fetch_row (mysql_res);

      /* Get web / social network (row[0]) */
      Str_Copy (NetName,row[0],
                Net_MAX_BYTES_NETWORK_NAME);
      for (Web = (Net_WebsAndSocialNetworks_t) 0;
	   Web < Net_NUM_WEBS_AND_SOCIAL_NETWORKS;
	   Web++)
	 if (!strcmp (Net_WebsAndSocialNetworksDB[Web],NetName))
	    break;
      if (Web < Net_NUM_WEBS_AND_SOCIAL_NETWORKS)
	{
	 /* Get number of users (row[1]) */
	 if (sscanf (row[1],"%u",&NumUsrs) != 1)
	    Lay_ShowErrorAndExit ("Error when getting number of files.");

	 fprintf (Gbl.F.Out,"<tr>"
			    "<td class=\"DAT LEFT_MIDDLE\">"
			    "<img src=\"%s/%s\""
			    " alt=\"%s\" title=\"%s\""
                            " class=\"CONTEXT_ICO_16x16\""
			    " style=\"margin-right:6px;\" />"
			    "%s</td>"
			    "<td class=\"DAT RIGHT_MIDDLE\">"
			    "%u"
			    "</td>"
			    "<td class=\"DAT RIGHT_MIDDLE\">"
			    "%.2f%%"
			    "</td>"
			    "</tr>",
		  Cfg_URL_ICON_PUBLIC,Net_WebsAndSocialNetworksIcons[Web],
		  Net_WebsAndSocialNetworksTitle[Web],
		  Net_WebsAndSocialNetworksTitle[Web],
		  Net_WebsAndSocialNetworksTitle[Web],
		  NumUsrs,
		  NumUsrsTotal ? 100.0 * (float) NumUsrs / (float) NumUsrsTotal :
			         0.0);
	}
     }

   /***** End table and box *****/
   Box_EndBoxTable ();

   /***** Free structure that stores the query result *****/
   DB_FreeMySQLResult (&mysql_res);
  }