swad-core/swad_network.c

618 lines
21 KiB
C
Raw Normal View History

2014-12-01 23:55:08 +01:00
// swad_network.c: users' webs and social networks
/*
SWAD (Shared Workspace At a Distance),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
2021-02-09 12:43:45 +01:00
Copyright (C) 1999-2021 Antonio Ca<EFBFBD>as Vargas
2014-12-01 23:55:08 +01:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
#include <string.h>
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
2014-12-01 23:55:08 +01:00
#include "swad_database.h"
#include "swad_error.h"
2020-04-14 17:15:17 +02:00
#include "swad_figure.h"
2018-11-09 20:47:39 +01:00
#include "swad_form.h"
2014-12-01 23:55:08 +01:00
#include "swad_global.h"
#include "swad_hierarchy_level.h"
2019-10-23 19:05:05 +02:00
#include "swad_HTML.h"
2014-12-01 23:55:08 +01:00
#include "swad_parameter.h"
2015-03-14 17:39:04 +01:00
#include "swad_profile.h"
2014-12-01 23:55:08 +01:00
#include "swad_theme.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
2020-03-06 12:22:20 +01:00
#define Net_NUM_WEBS_AND_SOCIAL_NETWORKS 30
2014-12-01 23:55:08 +01:00
typedef enum
{
Net_WWW, // Personal web page
2015-03-03 21:15:52 +01:00
Net_500PX,
2014-12-01 23:55:08 +01:00
Net_DELICIOUS,
2015-03-03 21:15:52 +01:00
Net_DEVIANTART,
2015-03-10 14:37:45 +01:00
Net_DIASPORA,
2014-12-01 23:55:08 +01:00
Net_EDMODO,
Net_FACEBOOK,
Net_FLICKR,
Net_FOURSQUARE,
2014-12-06 18:26:16 +01:00
Net_GITHUB,
2015-09-11 13:54:15 +02:00
Net_GNU_SOCIAL,
2014-12-01 23:55:08 +01:00
Net_GOOGLE_PLUS,
Net_GOOGLE_SCHOLAR,
2015-09-11 13:54:15 +02:00
Net_IDENTICA,
2014-12-01 23:55:08 +01:00
Net_INSTAGRAM,
Net_LINKEDIN,
2015-09-09 23:44:58 +02:00
Net_ORCID,
2014-12-01 23:55:08 +01:00
Net_PAPERLI,
Net_PINTEREST,
Net_RESEARCH_GATE,
2015-09-09 23:44:58 +02:00
Net_RESEARCHERID,
2014-12-01 23:55:08 +01:00
Net_SCOOPIT,
Net_SLIDESHARE,
2016-06-19 15:18:46 +02:00
Net_STACK_OVERFLOW,
2014-12-01 23:55:08 +01:00
Net_STORIFY,
Net_TUMBLR,
2020-03-06 12:22:20 +01:00
Net_TWITCH,
2014-12-01 23:55:08 +01:00
Net_TWITTER,
Net_WIKIPEDIA,
Net_YOUTUBE,
} Net_WebsAndSocialNetworks_t;
2017-01-29 21:41:08 +01:00
#define Net_WEB_SOCIAL_NET_DEFAULT Net_WWW
2014-12-01 23:55:08 +01:00
2017-03-07 19:55:29 +01:00
#define Net_MAX_BYTES_NETWORK_NAME 32
2017-01-17 03:10:43 +01:00
2019-11-22 01:04:03 +01:00
static const char *Net_WebsAndSocialNetworksDB[Net_NUM_WEBS_AND_SOCIAL_NETWORKS] =
2014-12-01 23:55:08 +01:00
{
2019-11-22 01:04:03 +01:00
[Net_WWW ] = "www",
[Net_500PX ] = "500px",
[Net_DELICIOUS ] = "delicious",
[Net_DEVIANTART ] = "deviantart",
[Net_DIASPORA ] = "diaspora",
[Net_EDMODO ] = "edmodo",
[Net_FACEBOOK ] = "facebook",
[Net_FLICKR ] = "flickr",
[Net_FOURSQUARE ] = "foursquare",
[Net_GITHUB ] = "github",
[Net_GNU_SOCIAL ] = "gnusocial",
[Net_GOOGLE_PLUS ] = "googleplus",
[Net_GOOGLE_SCHOLAR] = "googlescholar",
[Net_IDENTICA ] = "identica",
[Net_INSTAGRAM ] = "instagram",
[Net_LINKEDIN ] = "linkedin",
[Net_ORCID ] = "orcid",
[Net_PAPERLI ] = "paperli",
[Net_PINTEREST ] = "pinterest",
[Net_RESEARCH_GATE ] = "researchgate",
[Net_RESEARCHERID ] = "researcherid",
[Net_SCOOPIT ] = "scoopit",
[Net_SLIDESHARE ] = "slideshare",
[Net_STACK_OVERFLOW] = "stackoverflow",
[Net_STORIFY ] = "storify",
[Net_TUMBLR ] = "tumblr",
2020-03-06 12:22:20 +01:00
[Net_TWITCH ] = "twitch",
2019-11-22 01:04:03 +01:00
[Net_TWITTER ] = "twitter",
[Net_WIKIPEDIA ] = "wikipedia",
[Net_YOUTUBE ] = "youtube",
2014-12-01 23:55:08 +01:00
};
2019-11-22 01:04:03 +01:00
static const char *Net_WebsAndSocialNetworksIcons[Net_NUM_WEBS_AND_SOCIAL_NETWORKS] =
2015-12-12 19:47:10 +01:00
{
2019-11-22 01:04:03 +01:00
[Net_WWW ] = "globe.svg",
[Net_500PX ] = "500px-brands.svg",
[Net_DELICIOUS ] = "delicious-brands.svg",
[Net_DEVIANTART ] = "deviantart-brands.svg",
[Net_DIASPORA ] = "diaspora-brands.svg",
[Net_EDMODO ] = "edmodo64x64.png",
[Net_FACEBOOK ] = "facebook-brands.svg",
[Net_FLICKR ] = "flickr-brands.svg",
[Net_FOURSQUARE ] = "foursquare-brands.svg",
[Net_GITHUB ] = "github-brands.svg",
[Net_GNU_SOCIAL ] = "gnusocial64x64.png",
[Net_GOOGLE_PLUS ] = "google-plus-brands.svg",
[Net_GOOGLE_SCHOLAR] = "googlescholar.svg",
[Net_IDENTICA ] = "identica64x64.png",
[Net_INSTAGRAM ] = "instagram-brands.svg",
[Net_LINKEDIN ] = "linkedin-brands.svg",
[Net_ORCID ] = "orcid64x64.png",
[Net_PAPERLI ] = "paperli64x64.png",
[Net_PINTEREST ] = "pinterest-brands.svg",
[Net_RESEARCH_GATE ] = "researchgate-brands.svg",
[Net_RESEARCHERID ] = "researcherid64x64.png",
[Net_SCOOPIT ] = "scoopit64x64.png",
[Net_SLIDESHARE ] = "slideshare-brands.svg",
[Net_STACK_OVERFLOW] = "stack-overflow-brands.svg",
[Net_STORIFY ] = "storify64x64.png",
[Net_TUMBLR ] = "tumblr-brands.svg",
2020-03-06 12:22:20 +01:00
[Net_TWITCH ] = "twitch-brands.svg",
2019-11-22 01:04:03 +01:00
[Net_TWITTER ] = "twitter-brands.svg",
[Net_WIKIPEDIA ] = "wikipedia-w-brands.svg",
[Net_YOUTUBE ] = "youtube-brands.svg",
2015-12-12 19:47:10 +01:00
};
2019-11-22 01:04:03 +01:00
static const char *Net_WebsAndSocialNetworksTitle[Net_NUM_WEBS_AND_SOCIAL_NETWORKS] =
2014-12-01 23:55:08 +01:00
{
2019-11-22 01:04:03 +01:00
[Net_WWW ] = "WWW",
[Net_500PX ] = "500px",
[Net_DELICIOUS ] = "Delicious",
[Net_DEVIANTART ] = "DeviantArt",
[Net_DIASPORA ] = "Diaspora",
[Net_EDMODO ] = "Edmodo",
[Net_FACEBOOK ] = "Facebook",
[Net_FLICKR ] = "Flickr",
[Net_FOURSQUARE ] = "Foursquare",
[Net_GITHUB ] = "GitHub",
[Net_GNU_SOCIAL ] = "GNU Social",
[Net_GOOGLE_PLUS ] = "Google+",
[Net_GOOGLE_SCHOLAR] = "Google Scholar",
[Net_IDENTICA ] = "identi.ca",
[Net_INSTAGRAM ] = "Instagram",
[Net_LINKEDIN ] = "LinkedIn",
[Net_ORCID ] = "ORCID",
[Net_PAPERLI ] = "Paper.li",
[Net_PINTEREST ] = "Pinterest",
[Net_RESEARCH_GATE ] = "Research Gate",
[Net_RESEARCHERID ] = "ResearcherID",
[Net_SCOOPIT ] = "Scoop.it",
[Net_SLIDESHARE ] = "Slideshare",
[Net_STACK_OVERFLOW] = "Stack Overflow",
[Net_STORIFY ] = "Storify",
[Net_TUMBLR ] = "Tumblr",
2020-03-06 12:22:20 +01:00
[Net_TWITCH ] = "Twitch",
2019-11-22 01:04:03 +01:00
[Net_TWITTER ] = "Twitter",
[Net_WIKIPEDIA ] = "Wikipedia",
[Net_YOUTUBE ] = "YouTube",
2014-12-01 23:55:08 +01:00
};
2018-10-08 18:41:56 +02:00
#define Net_MY_WEBS_ID "my_webs_section"
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2015-03-14 17:39:04 +01:00
static void Net_ShowAWebOrSocialNet (const char *URL,
const char *Icon,const char *Title);
2016-11-07 16:35:58 +01:00
2020-04-08 03:41:05 +02:00
static void Net_PutIconsWebsSocialNetworks (__attribute__((unused)) void *Args);
2016-11-07 16:35:58 +01:00
2014-12-01 23:55:08 +01:00
static void Net_GetMyWebsAndSocialNetsFromForm (void);
/*****************************************************************************/
/************************** Show webs / social networks **********************/
/*****************************************************************************/
2015-03-14 17:39:04 +01:00
void Net_ShowWebsAndSocialNets (const struct UsrData *UsrDat)
2014-12-01 23:55:08 +01:00
{
Net_WebsAndSocialNetworks_t NumURL;
2017-03-07 01:56:41 +01:00
char URL[Cns_MAX_BYTES_WWW + 1];
2014-12-01 23:55:08 +01:00
/***** Begin container *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"REC_WEBS\"");
2014-12-01 23:55:08 +01:00
2015-03-14 17:39:04 +01:00
/***** Show link to public profile *****/
Net_ShowAWebOrSocialNet (Prf_GetURLPublicProfile (URL,UsrDat->Nickname),
2019-01-11 02:55:01 +01:00
"swad64x64.png",Cfg_PLATFORM_SHORT_NAME);
2015-03-14 17:39:04 +01:00
/***** Show the rest of webs / social networks *****/
2019-12-15 20:02:34 +01:00
for (NumURL = (Net_WebsAndSocialNetworks_t) 0;
NumURL <= (Net_WebsAndSocialNetworks_t) (Net_NUM_WEBS_AND_SOCIAL_NETWORKS - 1);
2014-12-01 23:55:08 +01:00
NumURL++)
{
2015-03-14 17:39:04 +01:00
/***** Check if exists the web / social network for this user *****/
DB_QuerySELECTString (URL,sizeof (URL) - 1,
"can not get user's web / social network",
"SELECT URL" // row[0]
" FROM usr_webs"
" WHERE UsrCod=%ld"
" AND Web='%s'",
UsrDat->UsrCod,
Net_WebsAndSocialNetworksDB[NumURL]);
if (URL[0])
2015-03-14 17:39:04 +01:00
/* Show the web / social network */
Net_ShowAWebOrSocialNet (URL,
2015-12-12 19:47:10 +01:00
Net_WebsAndSocialNetworksIcons[NumURL],
Net_WebsAndSocialNetworksTitle[NumURL]);
2014-12-01 23:55:08 +01:00
}
2015-03-14 17:39:04 +01:00
/***** End container *****/
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2014-12-01 23:55:08 +01:00
}
2015-03-14 17:39:04 +01:00
/*****************************************************************************/
/************************** Show a web / social network **********************/
/*****************************************************************************/
static void Net_ShowAWebOrSocialNet (const char *URL,
const char *Icon,const char *Title)
{
/***** Write link and icon *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"ICO_HIGHLIGHT\" style=\"display:inline;\"");
2019-10-28 20:38:29 +01:00
HTM_A_Begin ("href=\"%s\" target=\"_blank\" title=\"%s\"",URL,Title);
2019-10-29 21:41:54 +01:00
Ico_PutIcon (Icon,Title,"ICO16x16");
2019-10-28 13:56:04 +01:00
HTM_A_End ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2015-03-14 17:39:04 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************* Show form to edit my social networks ******************/
/*****************************************************************************/
void Net_ShowFormMyWebsAndSocialNets (void)
{
2016-11-13 13:44:20 +01:00
extern const char *Hlp_PROFILE_Webs;
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormInBox[The_NUM_THEMES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Webs_social_networks;
2019-02-18 19:35:52 +01:00
extern const char *Txt_Save_changes;
2014-12-01 23:55:08 +01:00
Net_WebsAndSocialNetworks_t NumURL;
2017-03-07 01:56:41 +01:00
char URL[Cns_MAX_BYTES_WWW + 1];
2019-11-08 01:10:32 +01:00
char StrRecordWidth[Cns_MAX_DECIMAL_DIGITS_UINT + 2 + 1];
2019-11-04 09:45:57 +01:00
char StrName[32];
2018-10-08 18:41:56 +02:00
/***** Begin section *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_Begin (Net_MY_WEBS_ID);
2014-12-01 23:55:08 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
snprintf (StrRecordWidth,sizeof (StrRecordWidth),"%upx",Rec_RECORD_WIDTH);
2019-10-25 22:48:34 +02:00
Box_BoxBegin (StrRecordWidth,Txt_Webs_social_networks,
2020-04-08 03:41:05 +02:00
Net_PutIconsWebsSocialNetworks,NULL,
2019-02-18 19:35:52 +01:00
Hlp_PROFILE_Webs,Box_NOT_CLOSABLE);
2014-12-01 23:55:08 +01:00
2019-10-20 22:00:28 +02:00
/***** Begin table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginPadding (2);
2019-02-18 19:35:52 +01:00
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
2019-02-18 19:35:52 +01:00
Frm_StartFormAnchor (ActChgMyNet,Net_MY_WEBS_ID);
/***** List webs and social networks *****/
2019-12-15 20:02:34 +01:00
for (NumURL = (Net_WebsAndSocialNetworks_t) 0;
NumURL <= (Net_WebsAndSocialNetworks_t) (Net_NUM_WEBS_AND_SOCIAL_NETWORKS - 1);
2014-12-01 23:55:08 +01:00
NumURL++)
{
/***** Get user's web / social network from database *****/
DB_QuerySELECTString (URL,sizeof (URL) - 1,
"can not get user's web / social network",
"SELECT URL" // row[0]
" FROM usr_webs"
" WHERE UsrCod=%ld"
" AND Web='%s'",
Gbl.Usrs.Me.UsrDat.UsrCod,
Net_WebsAndSocialNetworksDB[NumURL]);
2014-12-01 23:55:08 +01:00
/***** Row for this web / social network *****/
snprintf (StrName,sizeof (StrName),"URL%u",(unsigned) NumURL);
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 17:36:41 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"REC_C1_BOT LM\"");
2019-11-12 15:41:58 +01:00
HTM_LABEL_Begin ("for=\"%s\" class=\"%s\"",
StrName,The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-10-30 00:42:01 +01:00
HTM_IMG (Cfg_URL_ICON_PUBLIC,Net_WebsAndSocialNetworksIcons[NumURL],Net_WebsAndSocialNetworksTitle[NumURL],
2019-10-30 22:31:03 +01:00
"class=\"CONTEXT_ICO_16x16\" style=\"margin-right:6px;\"");
2020-06-18 20:06:17 +02:00
HTM_TxtColon (Net_WebsAndSocialNetworksTitle[NumURL]);
2019-11-02 12:59:31 +01:00
HTM_LABEL_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 17:36:41 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"REC_C2_BOT LM\"");
2020-04-27 03:16:55 +02:00
HTM_INPUT_URL (StrName,URL,HTM_DONT_SUBMIT_ON_CHANGE,
2019-11-12 15:41:58 +01:00
"id=\"%s\" class=\"REC_C2_BOT_INPUT\"",StrName);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 17:36:41 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
2019-02-18 19:35:52 +01:00
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2019-02-18 19:35:52 +01:00
/***** Confirm button *****/
Btn_PutConfirmButton (Txt_Save_changes);
/***** End form *****/
Frm_EndForm ();
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2018-10-08 18:41:56 +02:00
/***** End section *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_End ();
2014-12-01 23:55:08 +01:00
}
2016-11-07 16:35:58 +01:00
/*****************************************************************************/
/************** Put contextual icons in my web / social networks *************/
/*****************************************************************************/
2020-04-08 03:41:05 +02:00
static void Net_PutIconsWebsSocialNetworks (__attribute__((unused)) void *Args)
2016-11-07 16:35:58 +01:00
{
2020-04-08 03:41:05 +02:00
/***** Put icon to show a figure *****/
Fig_PutIconToShowFigure (Fig_SOCIAL_NETWORKS);
2016-11-07 16:35:58 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/**************** Update and show data from identified user ******************/
/*****************************************************************************/
void Net_UpdateMyWebsAndSocialNets (void)
{
/***** Get my web and social networks from form *****/
Net_GetMyWebsAndSocialNetsFromForm ();
/***** Show form again *****/
2018-10-09 13:41:55 +02:00
Rec_ShowMySharedRecordAndMore ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********* Get data fields about web and social networks from form ***********/
/*****************************************************************************/
static void Net_GetMyWebsAndSocialNetsFromForm (void)
{
2019-02-18 19:35:52 +01:00
Net_WebsAndSocialNetworks_t NumURL;
char ParamName[3 + 10 + 1];
2017-03-07 01:56:41 +01:00
char URL[Cns_MAX_BYTES_WWW + 1];
2014-12-01 23:55:08 +01:00
2019-02-18 19:35:52 +01:00
/***** Get URLs *****/
2019-12-15 20:02:34 +01:00
for (NumURL = (Net_WebsAndSocialNetworks_t) 0;
NumURL <= (Net_WebsAndSocialNetworks_t) (Net_NUM_WEBS_AND_SOCIAL_NETWORKS - 1);
2019-02-18 19:35:52 +01:00
NumURL++)
{
/***** Get URL from the form *****/
snprintf (ParamName,sizeof (ParamName),"URL%u",(unsigned) NumURL);
2019-02-18 19:35:52 +01:00
Par_GetParToText (ParamName,URL,Cns_MAX_BYTES_WWW);
if (URL[0])
/***** Insert or replace web / social network *****/
DB_QueryREPLACE ("can not update user's web / social network",
"REPLACE INTO usr_webs"
" (UsrCod,Web,URL)"
" VALUES"
" (%ld,'%s','%s')",
Gbl.Usrs.Me.UsrDat.UsrCod,
Net_WebsAndSocialNetworksDB[NumURL],
URL);
else
/***** Remove web / social network *****/
DB_QueryDELETE ("can not remove user's web / social network",
"DELETE FROM usr_webs"
" WHERE UsrCod=%ld"
" AND Web='%s'",
2019-02-18 19:35:52 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod,
Net_WebsAndSocialNetworksDB[NumURL]);
}
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************** Show stats about users' webs / social networks ***************/
/*****************************************************************************/
void Net_ShowWebAndSocialNetworksStats (void)
{
2017-12-19 18:41:19 +01:00
extern const char *Hlp_ANALYTICS_Figures_webs_social_networks;
2019-02-12 14:46:14 +01:00
extern const char *Txt_FIGURE_TYPES[Fig_NUM_FIGURES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Web_social_network;
2020-05-07 14:15:39 +02:00
extern const char *Txt_Number_of_users;
2014-12-01 23:55:08 +01:00
extern const char *Txt_PERCENT_of_users;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2018-11-01 12:02:58 +01:00
unsigned NumRows = 0; // Initialized to avoid warning
2017-01-17 03:10:43 +01:00
unsigned NumRow;
2014-12-01 23:55:08 +01:00
Net_WebsAndSocialNetworks_t Web;
2017-03-07 19:55:29 +01:00
char NetName[Net_MAX_BYTES_NETWORK_NAME + 1];
2017-05-25 19:57:34 +02:00
unsigned NumUsrsTotal;
2014-12-01 23:55:08 +01:00
unsigned NumUsrs;
2017-05-25 19:57:34 +02:00
/***** Get total number of users in current scope *****/
NumUsrsTotal = Usr_GetTotalNumberOfUsers ();
2014-12-01 23:55:08 +01:00
/***** Get number of users with a web / social network *****/
switch (Gbl.Scope.Current)
{
case HieLvl_SYS:
NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get number of users"
" with webs / social networks",
"SELECT Web," // row[0]
"COUNT(*) AS N" // row[1]
" FROM usr_webs"
" GROUP BY Web"
" ORDER BY N DESC,"
"Web");
2014-12-01 23:55:08 +01:00
break;
case HieLvl_CTY:
NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get number of users"
" with webs / social networks",
"SELECT usr_webs.Web," // row[0]
"COUNT(DISTINCT usr_webs.UsrCod) AS N" // row[1]
" FROM ins_instits,"
"ctr_centers,"
"deg_degrees,"
"crs_courses,"
"crs_users,"
"usr_webs"
" 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=crs_users.CrsCod"
" AND crs_users.UsrCod=usr_webs.UsrCod"
" GROUP BY usr_webs.Web"
" ORDER BY N DESC,"
"usr_webs.Web",
Gbl.Hierarchy.Cty.CtyCod);
2015-03-09 12:09:31 +01:00
break;
case HieLvl_INS:
NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get number of users"
" with webs / social networks",
"SELECT usr_webs.Web," // row[0]
"COUNT(DISTINCT usr_webs.UsrCod) AS N" // row[1]
" FROM ctr_centers,"
"deg_degrees,"
"crs_courses,"
"crs_users,"
"usr_webs"
" WHERE ctr_centers.InsCod=%ld"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=crs_users.CrsCod"
" AND crs_users.UsrCod=usr_webs.UsrCod"
" GROUP BY usr_webs.Web"
" ORDER BY N DESC,"
"usr_webs.Web",
Gbl.Hierarchy.Ins.InsCod);
2014-12-01 23:55:08 +01:00
break;
case HieLvl_CTR:
NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get number of users"
" with webs / social networks",
"SELECT usr_webs.Web," // row[0]
"COUNT(DISTINCT usr_webs.UsrCod) AS N" // row[1]
" FROM deg_degrees,"
"crs_courses,"
"crs_users,"
"usr_webs"
" WHERE deg_degrees.CtrCod=%ld"
" AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=crs_users.CrsCod"
" AND crs_users.UsrCod=usr_webs.UsrCod"
" GROUP BY usr_webs.Web"
" ORDER BY N DESC,"
"usr_webs.Web",
Gbl.Hierarchy.Ctr.CtrCod);
2014-12-01 23:55:08 +01:00
break;
case HieLvl_DEG:
NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get number of users"
" with webs / social networks",
"SELECT usr_webs.Web," // row[0]
"COUNT(DISTINCT usr_webs.UsrCod) AS N" // row[1]
" FROM crs_courses,"
"crs_users,"
"usr_webs"
" WHERE crs_courses.DegCod=%ld"
" AND crs_courses.CrsCod=crs_users.CrsCod"
" AND crs_users.UsrCod=usr_webs.UsrCod"
" GROUP BY usr_webs.Web"
" ORDER BY N DESC,"
"usr_webs.Web",
Gbl.Hierarchy.Deg.DegCod);
2014-12-01 23:55:08 +01:00
break;
case HieLvl_CRS:
NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get number of users"
" with webs / social networks",
"SELECT usr_webs.Web," // row[0]
"COUNT(DISTINCT usr_webs.UsrCod) AS N" // row[1]
" FROM crs_users,"
"usr_webs"
" WHERE crs_users.CrsCod=%ld"
" AND crs_users.UsrCod=usr_webs.UsrCod"
" GROUP BY usr_webs.Web"
" ORDER BY N DESC,"
"usr_webs.Web",
Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
break;
default:
Err_WrongScopeExit ();
2014-12-01 23:55:08 +01:00
break;
}
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
2020-03-26 02:54:30 +01:00
Box_BoxTableBegin (NULL,Txt_FIGURE_TYPES[Fig_SOCIAL_NETWORKS],
NULL,NULL,
2017-12-19 18:41:19 +01:00
Hlp_ANALYTICS_Figures_webs_social_networks,Box_NOT_CLOSABLE,2);
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** Write heading *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-12 00:07:52 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH (1,1,"LM",Txt_Web_social_network);
2020-05-07 14:15:39 +02:00
HTM_TH (1,1,"RM",Txt_Number_of_users);
2019-10-23 19:05:05 +02:00
HTM_TH (1,1,"RM",Txt_PERCENT_of_users);
2019-10-12 00:07:52 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/***** 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],sizeof (NetName) - 1);
2019-12-15 20:02:34 +01:00
for (Web = (Net_WebsAndSocialNetworks_t) 0;
Web <= (Net_WebsAndSocialNetworks_t) (Net_NUM_WEBS_AND_SOCIAL_NETWORKS - 1);
2014-12-01 23:55:08 +01:00
Web++)
2017-01-17 03:10:43 +01:00
if (!strcmp (Net_WebsAndSocialNetworksDB[Web],NetName))
2014-12-01 23:55:08 +01:00
break;
if (Web < Net_NUM_WEBS_AND_SOCIAL_NETWORKS)
{
/* Get number of users (row[1]) */
if (sscanf (row[1],"%u",&NumUsrs) != 1)
Err_ShowErrorAndExit ("Error when getting number of files.");
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 17:36:41 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT LM\"");
2019-10-30 22:31:03 +01:00
HTM_IMG (Cfg_URL_ICON_PUBLIC,Net_WebsAndSocialNetworksIcons[Web],Net_WebsAndSocialNetworksTitle[Web],
"class=\"CONTEXT_ICO_16x16\" style=\"margin-right:6px;\"");
2019-11-10 12:36:37 +01:00
HTM_Txt (Net_WebsAndSocialNetworksTitle[Web]);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 17:36:41 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2019-11-10 13:31:47 +01:00
HTM_Unsigned (NumUsrs);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 17:36:41 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2019-11-11 00:15:44 +01:00
HTM_Percentage (NumUsrsTotal ? 100.0 * (double) NumUsrs /
(double) NumUsrsTotal :
0.0);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 17:36:41 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
}
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableEnd ();
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/******************* Remove user's webs / social networks ********************/
/*****************************************************************************/
void Net_DB_RemoveUsrWebs (long UsrCod)
{
DB_QueryDELETE ("can not remove user's webs / social networks",
"DELETE FROM usr_webs"
" WHERE UsrCod=%ld",
UsrCod);
}