mirror of https://github.com/acanas/swad-core.git
Version 21.19: Sep 29, 2021 New module swad_network_database for database queries related to webs/social networks.
This commit is contained in:
parent
94948db72f
commit
f63f69f61d
9
Makefile
9
Makefile
|
@ -66,10 +66,11 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.o \
|
|||
swad_match.o swad_match_database.o swad_match_print.o \
|
||||
swad_match_result.o swad_media.o swad_media_database.o swad_menu.o \
|
||||
swad_message.o swad_message_database.o swad_MFU.o swad_MFU_database.o \
|
||||
swad_network.o swad_nickname.o swad_notice.o swad_notification.o \
|
||||
swad_notification_database.o swad_pagination.o swad_parameter.o \
|
||||
swad_password.o swad_photo.o swad_place.o swad_plugin.o swad_privacy.o \
|
||||
swad_profile.o swad_program.o swad_project.o \
|
||||
swad_network.o swad_network_database.o swad_nickname.o swad_notice.o \
|
||||
swad_notification.o swad_notification_database.o swad_pagination.o \
|
||||
swad_parameter.o swad_password.o swad_photo.o swad_place.o \
|
||||
swad_plugin.o swad_privacy.o swad_profile.o swad_program.o \
|
||||
swad_project.o \
|
||||
swad_QR.o \
|
||||
swad_record.o swad_report.o swad_role.o swad_room.o swad_RSS.o \
|
||||
swad_scope.o swad_search.o swad_session.o swad_setting.o \
|
||||
|
|
|
@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par
|
|||
|
||||
TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
|
||||
*/
|
||||
#define Log_PLATFORM_VERSION "SWAD 21.18 (2021-09-29)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 21.19 (2021-09-29)"
|
||||
#define CSS_FILE "swad20.45.css"
|
||||
#define JS_FILE "swad20.69.1.js"
|
||||
/*
|
||||
TODO: Rename CENTRE to CENTER in help wiki.
|
||||
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
||||
|
||||
Version 21.19: Sep 29, 2021 New module swad_network_database for database queries related to webs/social networks. (317644 lines)
|
||||
Version 21.18: Sep 29, 2021 New module swad_MFU_database for database queries related to most frequently used actions. (317529 lines)
|
||||
Version 21.17.4: Sep 29, 2021 Queries moved to module swad_message_database. (317408 lines)
|
||||
Version 21.17.3: Sep 29, 2021 Queries moved to module swad_message_database. (317431 lines)
|
||||
|
|
256
swad_network.c
256
swad_network.c
|
@ -37,6 +37,8 @@
|
|||
#include "swad_HTML.h"
|
||||
#include "swad_parameter.h"
|
||||
#include "swad_profile.h"
|
||||
#include "swad_network.h"
|
||||
#include "swad_network_database.h"
|
||||
#include "swad_theme.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -49,78 +51,10 @@ extern struct Globals Gbl;
|
|||
/***************************** Private constants *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#define Net_NUM_WEBS_AND_SOCIAL_NETWORKS 30
|
||||
typedef enum
|
||||
{
|
||||
Net_WWW, // Personal web page
|
||||
Net_500PX,
|
||||
Net_DELICIOUS,
|
||||
Net_DEVIANTART,
|
||||
Net_DIASPORA,
|
||||
Net_EDMODO,
|
||||
Net_FACEBOOK,
|
||||
Net_FLICKR,
|
||||
Net_FOURSQUARE,
|
||||
Net_GITHUB,
|
||||
Net_GNU_SOCIAL,
|
||||
Net_GOOGLE_PLUS,
|
||||
Net_GOOGLE_SCHOLAR,
|
||||
Net_IDENTICA,
|
||||
Net_INSTAGRAM,
|
||||
Net_LINKEDIN,
|
||||
Net_ORCID,
|
||||
Net_PAPERLI,
|
||||
Net_PINTEREST,
|
||||
Net_RESEARCH_GATE,
|
||||
Net_RESEARCHERID,
|
||||
Net_SCOOPIT,
|
||||
Net_SLIDESHARE,
|
||||
Net_STACK_OVERFLOW,
|
||||
Net_STORIFY,
|
||||
Net_TUMBLR,
|
||||
Net_TWITCH,
|
||||
Net_TWITTER,
|
||||
Net_WIKIPEDIA,
|
||||
Net_YOUTUBE,
|
||||
} Net_WebsAndSocialNetworks_t;
|
||||
#define Net_WEB_SOCIAL_NET_DEFAULT Net_WWW
|
||||
|
||||
#define Net_MAX_BYTES_NETWORK_NAME 32
|
||||
|
||||
static const char *Net_WebsAndSocialNetworksDB[Net_NUM_WEBS_AND_SOCIAL_NETWORKS] =
|
||||
{
|
||||
[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",
|
||||
[Net_TWITCH ] = "twitch",
|
||||
[Net_TWITTER ] = "twitter",
|
||||
[Net_WIKIPEDIA ] = "wikipedia",
|
||||
[Net_YOUTUBE ] = "youtube",
|
||||
};
|
||||
|
||||
static const char *Net_WebsAndSocialNetworksIcons[Net_NUM_WEBS_AND_SOCIAL_NETWORKS] =
|
||||
{
|
||||
[Net_WWW ] = "globe.svg",
|
||||
|
@ -224,14 +158,7 @@ void Net_ShowWebsAndSocialNets (const struct UsrData *UsrDat)
|
|||
NumURL++)
|
||||
{
|
||||
/***** 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]);
|
||||
Net_DB_GetURL (UsrDat->UsrCod,NumURL,URL);
|
||||
if (URL[0])
|
||||
/* Show the web / social network */
|
||||
Net_ShowAWebOrSocialNet (URL,
|
||||
|
@ -294,14 +221,7 @@ void Net_ShowFormMyWebsAndSocialNets (void)
|
|||
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]);
|
||||
Net_DB_GetURL (Gbl.Usrs.Me.UsrDat.UsrCod,NumURL,URL);
|
||||
|
||||
/***** Row for this web / social network *****/
|
||||
snprintf (StrName,sizeof (StrName),"URL%u",(unsigned) NumURL);
|
||||
|
@ -310,8 +230,11 @@ void Net_ShowFormMyWebsAndSocialNets (void)
|
|||
HTM_TD_Begin ("class=\"REC_C1_BOT LM\"");
|
||||
HTM_LABEL_Begin ("for=\"%s\" class=\"%s\"",
|
||||
StrName,The_ClassFormInBox[Gbl.Prefs.Theme]);
|
||||
HTM_IMG (Cfg_URL_ICON_PUBLIC,Net_WebsAndSocialNetworksIcons[NumURL],Net_WebsAndSocialNetworksTitle[NumURL],
|
||||
"class=\"CONTEXT_ICO_16x16\" style=\"margin-right:6px;\"");
|
||||
HTM_IMG (Cfg_URL_ICON_PUBLIC,
|
||||
Net_WebsAndSocialNetworksIcons[NumURL],
|
||||
Net_WebsAndSocialNetworksTitle[NumURL],
|
||||
"class=\"CONTEXT_ICO_16x16\""
|
||||
" style=\"margin-right:6px;\"");
|
||||
HTM_TxtColon (Net_WebsAndSocialNetworksTitle[NumURL]);
|
||||
HTM_LABEL_End ();
|
||||
HTM_TD_End ();
|
||||
|
@ -384,22 +307,10 @@ static void Net_GetMyWebsAndSocialNetsFromForm (void)
|
|||
|
||||
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);
|
||||
Net_DB_UpdateMyWeb (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'",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
Net_WebsAndSocialNetworksDB[NumURL]);
|
||||
Net_DB_RemoveMyWeb (NumURL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -410,14 +321,15 @@ static void Net_GetMyWebsAndSocialNetsFromForm (void)
|
|||
void Net_ShowWebAndSocialNetworksStats (void)
|
||||
{
|
||||
extern const char *Hlp_ANALYTICS_Figures_webs_social_networks;
|
||||
extern const char *Net_DB_WebsAndSocialNetworks[Net_NUM_WEBS_AND_SOCIAL_NETWORKS];
|
||||
extern const char *Txt_FIGURE_TYPES[Fig_NUM_FIGURES];
|
||||
extern const char *Txt_Web_social_network;
|
||||
extern const char *Txt_Number_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;
|
||||
unsigned NumNetworks;
|
||||
unsigned NumNetwork;
|
||||
Net_WebsAndSocialNetworks_t Web;
|
||||
char NetName[Net_MAX_BYTES_NETWORK_NAME + 1];
|
||||
unsigned NumUsrsTotal;
|
||||
|
@ -427,118 +339,7 @@ void Net_ShowWebAndSocialNetworksStats (void)
|
|||
NumUsrsTotal = Usr_GetTotalNumberOfUsers ();
|
||||
|
||||
/***** 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");
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
break;
|
||||
default:
|
||||
Err_WrongScopeExit ();
|
||||
break;
|
||||
}
|
||||
NumNetworks = Net_DB_GetWebAndSocialNetworksStats (&mysql_res);
|
||||
|
||||
/***** Begin box and table *****/
|
||||
Box_BoxTableBegin (NULL,Txt_FIGURE_TYPES[Fig_SOCIAL_NETWORKS],
|
||||
|
@ -553,9 +354,9 @@ void Net_ShowWebAndSocialNetworksStats (void)
|
|||
HTM_TR_End ();
|
||||
|
||||
/***** For each web / social network... *****/
|
||||
for (NumRow = 0;
|
||||
NumRow < NumRows;
|
||||
NumRow++)
|
||||
for (NumNetwork = 0;
|
||||
NumNetwork < NumNetworks;
|
||||
NumNetwork++)
|
||||
{
|
||||
/* Get row */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
@ -565,7 +366,7 @@ void Net_ShowWebAndSocialNetworksStats (void)
|
|||
for (Web = (Net_WebsAndSocialNetworks_t) 0;
|
||||
Web <= (Net_WebsAndSocialNetworks_t) (Net_NUM_WEBS_AND_SOCIAL_NETWORKS - 1);
|
||||
Web++)
|
||||
if (!strcmp (Net_WebsAndSocialNetworksDB[Web],NetName))
|
||||
if (!strcmp (Net_DB_WebsAndSocialNetworks[Web],NetName))
|
||||
break;
|
||||
if (Web < Net_NUM_WEBS_AND_SOCIAL_NETWORKS)
|
||||
{
|
||||
|
@ -576,8 +377,11 @@ void Net_ShowWebAndSocialNetworksStats (void)
|
|||
HTM_TR_Begin (NULL);
|
||||
|
||||
HTM_TD_Begin ("class=\"DAT LM\"");
|
||||
HTM_IMG (Cfg_URL_ICON_PUBLIC,Net_WebsAndSocialNetworksIcons[Web],Net_WebsAndSocialNetworksTitle[Web],
|
||||
"class=\"CONTEXT_ICO_16x16\" style=\"margin-right:6px;\"");
|
||||
HTM_IMG (Cfg_URL_ICON_PUBLIC,
|
||||
Net_WebsAndSocialNetworksIcons[Web],
|
||||
Net_WebsAndSocialNetworksTitle[Web],
|
||||
"class=\"CONTEXT_ICO_16x16\""
|
||||
" style=\"margin-right:6px;\"");
|
||||
HTM_Txt (Net_WebsAndSocialNetworksTitle[Web]);
|
||||
HTM_TD_End ();
|
||||
|
||||
|
@ -601,15 +405,3 @@ void Net_ShowWebAndSocialNetworksStats (void)
|
|||
/***** 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);
|
||||
}
|
||||
|
|
|
@ -31,10 +31,46 @@
|
|||
/***************************** Public constants ******************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#define Net_NUM_WEBS_AND_SOCIAL_NETWORKS 30
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************************* Public types ********************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
Net_WWW, // Personal web page
|
||||
Net_500PX,
|
||||
Net_DELICIOUS,
|
||||
Net_DEVIANTART,
|
||||
Net_DIASPORA,
|
||||
Net_EDMODO,
|
||||
Net_FACEBOOK,
|
||||
Net_FLICKR,
|
||||
Net_FOURSQUARE,
|
||||
Net_GITHUB,
|
||||
Net_GNU_SOCIAL,
|
||||
Net_GOOGLE_PLUS,
|
||||
Net_GOOGLE_SCHOLAR,
|
||||
Net_IDENTICA,
|
||||
Net_INSTAGRAM,
|
||||
Net_LINKEDIN,
|
||||
Net_ORCID,
|
||||
Net_PAPERLI,
|
||||
Net_PINTEREST,
|
||||
Net_RESEARCH_GATE,
|
||||
Net_RESEARCHERID,
|
||||
Net_SCOOPIT,
|
||||
Net_SLIDESHARE,
|
||||
Net_STACK_OVERFLOW,
|
||||
Net_STORIFY,
|
||||
Net_TUMBLR,
|
||||
Net_TWITCH,
|
||||
Net_TWITTER,
|
||||
Net_WIKIPEDIA,
|
||||
Net_YOUTUBE,
|
||||
} Net_WebsAndSocialNetworks_t;
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Public prototypes *****************************/
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -0,0 +1,266 @@
|
|||
// swad_network_database.c: users' webs and social networks, operations with database
|
||||
|
||||
/*
|
||||
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.
|
||||
Copyright (C) 1999-2021 Antonio Cañas Vargas
|
||||
|
||||
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>
|
||||
|
||||
// #include "swad_box.h"
|
||||
#include "swad_database.h"
|
||||
#include "swad_error.h"
|
||||
// #include "swad_figure.h"
|
||||
// #include "swad_form.h"
|
||||
#include "swad_global.h"
|
||||
// #include "swad_hierarchy_level.h"
|
||||
// #include "swad_HTML.h"
|
||||
#include "swad_network.h"
|
||||
#include "swad_network_database.h"
|
||||
// #include "swad_parameter.h"
|
||||
// #include "swad_profile.h"
|
||||
// #include "swad_theme.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/************** External global variables from others modules ****************/
|
||||
/*****************************************************************************/
|
||||
|
||||
extern struct Globals Gbl;
|
||||
|
||||
/*****************************************************************************/
|
||||
/****************************** Public constants *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
const char *Net_DB_WebsAndSocialNetworks[Net_NUM_WEBS_AND_SOCIAL_NETWORKS] =
|
||||
{
|
||||
[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",
|
||||
[Net_TWITCH ] = "twitch",
|
||||
[Net_TWITTER ] = "twitter",
|
||||
[Net_WIKIPEDIA ] = "wikipedia",
|
||||
[Net_YOUTUBE ] = "youtube",
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Private prototypes ****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************* Insert or replace web / social network ******************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Net_DB_UpdateMyWeb (Net_WebsAndSocialNetworks_t NumURL,
|
||||
const char URL[Cns_MAX_BYTES_WWW + 1])
|
||||
{
|
||||
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_DB_WebsAndSocialNetworks[NumURL],
|
||||
URL);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*************************** Get web / social network ************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Net_DB_GetURL (long UsrCod,Net_WebsAndSocialNetworks_t NumURL,
|
||||
char URL[Cns_MAX_BYTES_WWW + 1])
|
||||
{
|
||||
DB_QuerySELECTString (URL,Cns_MAX_BYTES_WWW,
|
||||
"can not get user's web / social network",
|
||||
"SELECT URL"
|
||||
" FROM usr_webs"
|
||||
" WHERE UsrCod=%ld"
|
||||
" AND Web='%s'",
|
||||
UsrCod,
|
||||
Net_DB_WebsAndSocialNetworks[NumURL]);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*************** Get stats about users' webs / social networks ***************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Net_DB_GetWebAndSocialNetworksStats (MYSQL_RES **mysql_res)
|
||||
{
|
||||
/***** Get number of users with a web / social network *****/
|
||||
switch (Gbl.Scope.Current)
|
||||
{
|
||||
case HieLvl_SYS:
|
||||
return (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");
|
||||
case HieLvl_CTY:
|
||||
return (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);
|
||||
case HieLvl_INS:
|
||||
return (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);
|
||||
case HieLvl_CTR:
|
||||
return (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);
|
||||
case HieLvl_DEG:
|
||||
return (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);
|
||||
case HieLvl_CRS:
|
||||
return (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);
|
||||
break;
|
||||
default:
|
||||
Err_WrongScopeExit ();
|
||||
return 0; // Not reached
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********************** Remove my web / social network **********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Net_DB_RemoveMyWeb (Net_WebsAndSocialNetworks_t NumURL)
|
||||
{
|
||||
DB_QueryDELETE ("can not remove user's web / social network",
|
||||
"DELETE FROM usr_webs"
|
||||
" WHERE UsrCod=%ld"
|
||||
" AND Web='%s'",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
Net_DB_WebsAndSocialNetworks[NumURL]);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************* 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);
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
// swad_network_database.h: users' webs and social networks, operations with database
|
||||
|
||||
#ifndef _SWAD_NET_DB
|
||||
#define _SWAD_NET_DB
|
||||
/*
|
||||
SWAD (Shared Workspace At a Distance in Spanish),
|
||||
is a web platform developed at the University of Granada (Spain),
|
||||
and used to support university teaching.
|
||||
|
||||
This file is part of SWAD core.
|
||||
Copyright (C) 1999-2021 Antonio Cañas Vargas
|
||||
|
||||
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 "swad_constant.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Public constants ******************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************************* Public types ********************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Public prototypes *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Net_DB_UpdateMyWeb (Net_WebsAndSocialNetworks_t NumURL,
|
||||
const char URL[Cns_MAX_BYTES_WWW + 1]);
|
||||
|
||||
void Net_DB_GetURL (long UsrCod,Net_WebsAndSocialNetworks_t NumURL,
|
||||
char URL[Cns_MAX_BYTES_WWW + 1]);
|
||||
unsigned Net_DB_GetWebAndSocialNetworksStats (MYSQL_RES **mysql_res);
|
||||
|
||||
void Net_DB_RemoveMyWeb (Net_WebsAndSocialNetworks_t NumURL);
|
||||
void Net_DB_RemoveUsrWebs (long UsrCod);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue