Version 20.78: May 19, 2021 New module swad_chat_database for database queries related to chat.

This commit is contained in:
acanas 2021-05-19 15:07:24 +02:00
parent dbfbac03e3
commit 5e0df18bd8
4 changed files with 152 additions and 168 deletions

View File

@ -33,9 +33,9 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_agenda.o \
swad_banner.o swad_banner_database.o swad_box.o swad_building.o \ swad_banner.o swad_banner_database.o swad_box.o swad_building.o \
swad_button.o \ swad_button.o \
swad_calendar.o swad_call_for_exam.o swad_center.o \ swad_calendar.o swad_call_for_exam.o swad_center.o \
swad_center_config.o swad_chat.o swad_config.o swad_connected.o \ swad_center_config.o swad_chat.o swad_chat_database.o swad_config.o \
swad_cookie.o swad_country.o swad_country_config.o swad_course.o \ swad_connected.o swad_cookie.o swad_country.o swad_country_config.o \
swad_course_config.o swad_cryptography.o \ swad_course.o swad_course_config.o swad_cryptography.o \
swad_database.o swad_date.o swad_degree.o swad_degree_config.o \ swad_database.o swad_date.o swad_degree.o swad_degree_config.o \
swad_degree_type.o swad_department.o swad_duplicate.o \ swad_degree_type.o swad_department.o swad_duplicate.o \
swad_enrolment.o swad_error.o swad_exam.o swad_exam_log.o \ swad_enrolment.o swad_error.o swad_exam.o swad_exam_log.o \

View File

@ -25,24 +25,11 @@
/********************************* Headers ***********************************/ /********************************* Headers ***********************************/
/*****************************************************************************/ /*****************************************************************************/
// #include <stddef.h> // For NULL
// #include <stdlib.h> // For calloc
// #include <string.h> // For string functions
#include "swad_banner.h" #include "swad_banner.h"
#include "swad_banner_database.h" #include "swad_banner_database.h"
// #include "swad_box.h"
// #include "swad_constant.h"
#include "swad_config.h" #include "swad_config.h"
#include "swad_database.h" #include "swad_database.h"
// #include "swad_error.h"
// #include "swad_form.h"
#include "swad_global.h" #include "swad_global.h"
// #include "swad_HTML.h"
// #include "swad_language.h"
// #include "swad_link.h"
// #include "swad_parameter.h"
// #include "swad_photo.h"
/*****************************************************************************/ /*****************************************************************************/
/************** External global variables from others modules ****************/ /************** External global variables from others modules ****************/

View File

@ -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. TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
*/ */
#define Log_PLATFORM_VERSION "SWAD 20.77 (2021-05-18)" #define Log_PLATFORM_VERSION "SWAD 20.78 (2021-05-19)"
#define CSS_FILE "swad20.45.css" #define CSS_FILE "swad20.45.css"
#define JS_FILE "swad20.69.1.js" #define JS_FILE "swad20.69.1.js"
/* /*
TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename CENTRE to CENTER in help wiki.
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
Version 20.78: May 19, 2021 New module swad_chat_database for database queries related to chat. (311327 lines)
Version 20.77: May 18, 2021 New module swad_banner_database for database queries related to banners. (311249 lines) Version 20.77: May 18, 2021 New module swad_banner_database for database queries related to banners. (311249 lines)
Version 20.76: May 11, 2021 New module swad_atendance_database for database queries related to attendance events. (311109 lines) Version 20.76: May 11, 2021 New module swad_atendance_database for database queries related to attendance events. (311109 lines)
Version 20.75: May 11, 2021 New module swad_assignment_database for database queries related to assignments. (310858 lines) Version 20.75: May 11, 2021 New module swad_assignment_database for database queries related to assignments. (310858 lines)

View File

@ -31,6 +31,7 @@
#include "swad_box.h" #include "swad_box.h"
#include "swad_chat.h" #include "swad_chat.h"
#include "swad_chat_database.h"
#include "swad_config.h" #include "swad_config.h"
#include "swad_database.h" #include "swad_database.h"
#include "swad_error.h" #include "swad_error.h"
@ -70,7 +71,6 @@ extern struct Globals Gbl;
static void Cht_WriteLinkToChat1 (const char *RoomCode,const char *RoomShrtName,const char *RoomFullName, static void Cht_WriteLinkToChat1 (const char *RoomCode,const char *RoomShrtName,const char *RoomFullName,
unsigned Level,bool IsLastItemInLevel[1 + Cht_CHAT_MAX_LEVELS]); unsigned Level,bool IsLastItemInLevel[1 + Cht_CHAT_MAX_LEVELS]);
static void Cht_WriteLinkToChat2 (const char *RoomCode,const char *RoomFullName); static void Cht_WriteLinkToChat2 (const char *RoomCode,const char *RoomFullName);
static unsigned Cht_GetNumUsrsInChatRoom (const char *RoomCode);
/*****************************************************************************/ /*****************************************************************************/
/****************** List available whiteboard/chat rooms *********************/ /****************** List available whiteboard/chat rooms *********************/
@ -128,103 +128,107 @@ void Cht_ShowListOfAvailableChatRooms (void)
Box_BoxBegin (NULL,Txt_Chat_rooms, Box_BoxBegin (NULL,Txt_Chat_rooms,
NULL,NULL, NULL,NULL,
NULL,Box_NOT_CLOSABLE); NULL,Box_NOT_CLOSABLE);
HTM_UL_Begin ("class=\"LIST_TREE\"");
/***** Title of top level *****/ /***** Begin list *****/
HTM_LI_Begin ("class=\"DAT\""); HTM_UL_Begin ("class=\"LIST_TREE\"");
Ico_PutIcon ("comments.svg",Txt_Chat_rooms,"ICO16x16");
HTM_TxtF ("&nbsp;%s",Txt_Chat_rooms);
HTM_LI_End ();
/***** Link to chat available for all the users *****/ /***** Title of top level *****/
IsLastItemInLevel[1] = (!Gbl.Usrs.Me.IBelongToCurrentCrs && HTM_LI_Begin ("class=\"DAT\"");
!Gbl.Usrs.Me.MyDegs.Num); Ico_PutIcon ("comments.svg",Txt_Chat_rooms,"ICO16x16");
snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),"%s (%s)", HTM_TxtF ("&nbsp;%s",Txt_Chat_rooms);
Txt_General,Txt_SEX_PLURAL_abc[Usr_SEX_ALL]); HTM_LI_End ();
Cht_WriteLinkToChat1 ("GBL_USR",Txt_SEX_PLURAL_Abc[Usr_SEX_ALL],ThisRoomFullName,1,IsLastItemInLevel);
Ico_PutIcon ("comments.svg",ThisRoomFullName,"ICO16x16");
Cht_WriteLinkToChat2 ("GBL_USR",ThisRoomFullName);
IsLastItemInLevel[1] = !Gbl.Usrs.Me.MyDegs.Num; /***** Link to chat available for all the users *****/
switch (Gbl.Usrs.Me.Role.Logged) IsLastItemInLevel[1] = (!Gbl.Usrs.Me.IBelongToCurrentCrs &&
{ !Gbl.Usrs.Me.MyDegs.Num);
case Rol_STD: snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),"%s (%s)",
snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),"%s (%s)", Txt_General,Txt_SEX_PLURAL_abc[Usr_SEX_ALL]);
Txt_General,Txt_ROLES_PLURAL_abc[Rol_STD][Usr_SEX_ALL]); Cht_WriteLinkToChat1 ("GBL_USR",Txt_SEX_PLURAL_Abc[Usr_SEX_ALL],ThisRoomFullName,1,IsLastItemInLevel);
Cht_WriteLinkToChat1 ("GBL_STD",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD], Ico_PutIcon ("comments.svg",ThisRoomFullName,"ICO16x16");
ThisRoomFullName,1,IsLastItemInLevel); Cht_WriteLinkToChat2 ("GBL_USR",ThisRoomFullName);
Ico_PutIcon ("comments.svg",ThisRoomFullName,"ICO16x16");
Cht_WriteLinkToChat2 ("GBL_STD",ThisRoomFullName);
break;
case Rol_NET:
case Rol_TCH:
snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),"%s (%s)",
Txt_General,Txt_ROLES_PLURAL_abc[Rol_TCH][Usr_SEX_ALL]);
Cht_WriteLinkToChat1 ("GBL_TCH",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH],
ThisRoomFullName,1,IsLastItemInLevel);
Ico_PutIcon ("comments.svg",ThisRoomFullName,"ICO16x16");
Cht_WriteLinkToChat2 ("GBL_TCH",ThisRoomFullName);
break;
default:
break;
}
/***** Link to chat of users from my degrees *****/ IsLastItemInLevel[1] = !Gbl.Usrs.Me.MyDegs.Num;
for (NumMyDeg = 0; switch (Gbl.Usrs.Me.Role.Logged)
NumMyDeg < Gbl.Usrs.Me.MyDegs.Num;
NumMyDeg++)
{
/* Get data of this degree */
Deg.DegCod = Gbl.Usrs.Me.MyDegs.Degs[NumMyDeg].DegCod;
if (!Deg_GetDataOfDegreeByCod (&Deg))
Err_WrongDegreeExit ();
/* Link to the room of this degree */
IsLastItemInLevel[1] = (NumMyDeg == Gbl.Usrs.Me.MyDegs.Num - 1);
snprintf (ThisRoomCode,sizeof (ThisRoomCode),"DEG_%ld",Deg.DegCod);
snprintf (ThisRoomShrtName,sizeof (ThisRoomShrtName),"%s",
Deg.ShrtName);
snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),"%s %s",
Txt_Degree,Deg.ShrtName);
Cht_WriteLinkToChat1 (ThisRoomCode,ThisRoomShrtName,ThisRoomFullName,1,IsLastItemInLevel);
Lgo_DrawLogo (Hie_Lvl_DEG,Deg.DegCod,Deg.ShrtName,16,NULL,true);
Cht_WriteLinkToChat2 (ThisRoomCode,ThisRoomFullName);
/* Get my courses in this degree from database */
NumCrss = Usr_GetCrssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,Deg.DegCod,&mysql_res);
for (NumCrs = 0;
NumCrs < NumCrss;
NumCrs++)
{
/* Get next course */
row = mysql_fetch_row (mysql_res);
/* Get course code */
if ((Crs.CrsCod = Str_ConvertStrCodToLongCod (row[0])) > 0)
{ {
/* Get data of this course */ case Rol_STD:
Crs_GetDataOfCourseByCod (&Crs); snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),"%s (%s)",
Txt_General,Txt_ROLES_PLURAL_abc[Rol_STD][Usr_SEX_ALL]);
/* Link to the room of this course */ Cht_WriteLinkToChat1 ("GBL_STD",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD],
IsLastItemInLevel[2] = (NumCrs == NumCrss - 1); ThisRoomFullName,1,IsLastItemInLevel);
snprintf (ThisRoomCode,sizeof (ThisRoomCode),"CRS_%ld", Ico_PutIcon ("comments.svg",ThisRoomFullName,"ICO16x16");
Crs.CrsCod); Cht_WriteLinkToChat2 ("GBL_STD",ThisRoomFullName);
snprintf (ThisRoomShrtName,sizeof (ThisRoomShrtName),"%s", break;
Crs.ShrtName); case Rol_NET:
snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),"%s %s", case Rol_TCH:
Txt_Course,Crs.ShrtName); snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),"%s (%s)",
Cht_WriteLinkToChat1 (ThisRoomCode,ThisRoomShrtName,ThisRoomFullName,2,IsLastItemInLevel); Txt_General,Txt_ROLES_PLURAL_abc[Rol_TCH][Usr_SEX_ALL]);
Ico_PutIcon ("chalkboard-teacher.svg",ThisRoomFullName,"ICO16x16"); Cht_WriteLinkToChat1 ("GBL_TCH",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH],
Cht_WriteLinkToChat2 (ThisRoomCode,ThisRoomFullName); ThisRoomFullName,1,IsLastItemInLevel);
Ico_PutIcon ("comments.svg",ThisRoomFullName,"ICO16x16");
Cht_WriteLinkToChat2 ("GBL_TCH",ThisRoomFullName);
break;
default:
break;
} }
}
/***** Free structure that stores the query result *****/ /***** Link to chat of users from my degrees *****/
DB_FreeMySQLResult (&mysql_res); for (NumMyDeg = 0;
} NumMyDeg < Gbl.Usrs.Me.MyDegs.Num;
NumMyDeg++)
{
/* Get data of this degree */
Deg.DegCod = Gbl.Usrs.Me.MyDegs.Degs[NumMyDeg].DegCod;
if (!Deg_GetDataOfDegreeByCod (&Deg))
Err_WrongDegreeExit ();
/* Link to the room of this degree */
IsLastItemInLevel[1] = (NumMyDeg == Gbl.Usrs.Me.MyDegs.Num - 1);
snprintf (ThisRoomCode,sizeof (ThisRoomCode),"DEG_%ld",Deg.DegCod);
snprintf (ThisRoomShrtName,sizeof (ThisRoomShrtName),"%s",
Deg.ShrtName);
snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),"%s %s",
Txt_Degree,Deg.ShrtName);
Cht_WriteLinkToChat1 (ThisRoomCode,ThisRoomShrtName,ThisRoomFullName,1,IsLastItemInLevel);
Lgo_DrawLogo (Hie_Lvl_DEG,Deg.DegCod,Deg.ShrtName,16,NULL,true);
Cht_WriteLinkToChat2 (ThisRoomCode,ThisRoomFullName);
/* Get my courses in this degree from database */
NumCrss = Usr_GetCrssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,Deg.DegCod,&mysql_res);
for (NumCrs = 0;
NumCrs < NumCrss;
NumCrs++)
{
/* Get next course */
row = mysql_fetch_row (mysql_res);
/* Get course code */
if ((Crs.CrsCod = Str_ConvertStrCodToLongCod (row[0])) > 0)
{
/* Get data of this course */
Crs_GetDataOfCourseByCod (&Crs);
/* Link to the room of this course */
IsLastItemInLevel[2] = (NumCrs == NumCrss - 1);
snprintf (ThisRoomCode,sizeof (ThisRoomCode),"CRS_%ld",
Crs.CrsCod);
snprintf (ThisRoomShrtName,sizeof (ThisRoomShrtName),"%s",
Crs.ShrtName);
snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),"%s %s",
Txt_Course,Crs.ShrtName);
Cht_WriteLinkToChat1 (ThisRoomCode,ThisRoomShrtName,ThisRoomFullName,2,IsLastItemInLevel);
Ico_PutIcon ("chalkboard-teacher.svg",ThisRoomFullName,"ICO16x16");
Cht_WriteLinkToChat2 (ThisRoomCode,ThisRoomFullName);
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/***** End list *****/
HTM_UL_End ();
/***** End box *****/ /***** End box *****/
HTM_UL_End ();
Box_BoxEnd (); Box_BoxEnd ();
} }
@ -243,14 +247,7 @@ void Cht_ShowListOfChatRoomsWithUsrs (void)
unsigned NumRoom; unsigned NumRoom;
/***** Get chat rooms with connected users from database *****/ /***** Get chat rooms with connected users from database *****/
NumRooms = (unsigned) NumRooms = Cht_DB_GetListOfChatRoomsWithUsrs (&mysql_res);
DB_QuerySELECT (&mysql_res,"can not get chat rooms with connected users",
"SELECT RoomCode," // row[0]
"NumUsrs" // row[1]
" FROM cht_rooms"
" WHERE NumUsrs>0"
" ORDER BY NumUsrs DESC,"
"RoomCode");
if (NumRooms) // If not empty chat rooms found if (NumRooms) // If not empty chat rooms found
{ {
/***** Begin box and table *****/ /***** Begin box and table *****/
@ -258,34 +255,32 @@ void Cht_ShowListOfChatRoomsWithUsrs (void)
NULL,NULL, NULL,NULL,
NULL,Box_NOT_CLOSABLE,2); NULL,Box_NOT_CLOSABLE,2);
/***** Write heading *****/ /***** Write heading *****/
HTM_TR_Begin (NULL); HTM_TR_Begin (NULL);
HTM_TH (1,1,"CM LIGHT_BLUE",Txt_CHAT_Room_code);
HTM_TH (1,1,"LM LIGHT_BLUE",Txt_Number_of_users);
HTM_TR_End ();
HTM_TH (1,1,"CM LIGHT_BLUE",Txt_CHAT_Room_code); /***** Loop over chat rooms *****/
HTM_TH (1,1,"LM LIGHT_BLUE",Txt_Number_of_users); for (NumRoom = 0;
NumRoom < NumRooms;
NumRoom++)
{
/* Get next chat room */
row = mysql_fetch_row (mysql_res);
HTM_TR_End (); HTM_TR_Begin (NULL);
/***** Loop over chat rooms *****/ HTM_TD_Begin ("class=\"DAT LM\"");
for (NumRoom = 0; HTM_Txt (row[0]);
NumRoom < NumRooms; HTM_TD_End ();
NumRoom++)
{
/* Get next chat room */
row = mysql_fetch_row (mysql_res);
HTM_TR_Begin (NULL); HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Txt (row[1]);
HTM_TD_End ();
HTM_TD_Begin ("class=\"DAT LM\""); HTM_TR_End ();
HTM_Txt (row[0]); }
HTM_TD_End ();
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Txt (row[1]);
HTM_TD_End ();
HTM_TR_End ();
}
/***** End table and box *****/ /***** End table and box *****/
Box_BoxTableEnd (); Box_BoxTableEnd ();
@ -304,32 +299,48 @@ static void Cht_WriteLinkToChat1 (const char *RoomCode,const char *RoomShrtName,
{ {
extern const char *The_ClassFormLinkInBox[The_NUM_THEMES]; extern const char *The_ClassFormLinkInBox[The_NUM_THEMES];
/***** Begin list item *****/
HTM_LI_Begin (NULL); HTM_LI_Begin (NULL);
Lay_IndentDependingOnLevel (Level,IsLastItemInLevel);
Frm_BeginForm (ActCht);
Cht_WriteParamsRoomCodeAndNames (RoomCode,RoomShrtName,RoomFullName);
HTM_BUTTON_SUBMIT_Begin (RoomFullName,The_ClassFormLinkInBox[Gbl.Prefs.Theme],NULL); Lay_IndentDependingOnLevel (Level,IsLastItemInLevel);
/***** Begin form *****/
Frm_BeginForm (ActCht);
Cht_WriteParamsRoomCodeAndNames (RoomCode,RoomShrtName,RoomFullName);
/* Begin button */
HTM_BUTTON_SUBMIT_Begin (RoomFullName,The_ClassFormLinkInBox[Gbl.Prefs.Theme],NULL);
} }
static void Cht_WriteLinkToChat2 (const char *RoomCode,const char *RoomFullName) static void Cht_WriteLinkToChat2 (const char *RoomCode,const char *RoomFullName)
{ {
extern const char *Txt_connected_PLURAL; extern const char *Txt_connected_PLURAL;
extern const char *Txt_connected_SINGULAR; extern const char *Txt_connected_SINGULAR;
unsigned NumUsrsInRoom = Cht_GetNumUsrsInChatRoom (RoomCode); unsigned NumUsrsInRoom = Cht_DB_GetNumUsrsInChatRoom (RoomCode);
if (NumUsrsInRoom) /* Begin strong if room has users */
HTM_STRONG_Begin (); if (NumUsrsInRoom)
HTM_TxtF ("&nbsp;%s",RoomFullName); HTM_STRONG_Begin ();
if (NumUsrsInRoom > 1)
HTM_TxtF (" [%d %s]",NumUsrsInRoom,Txt_connected_PLURAL);
else if (NumUsrsInRoom == 1)
HTM_TxtF (" [1 %s]",Txt_connected_SINGULAR);
if (NumUsrsInRoom)
HTM_STRONG_End ();
HTM_BUTTON_End ();
Frm_EndForm (); /* Room name and users */
HTM_TxtF ("&nbsp;%s",RoomFullName);
if (NumUsrsInRoom > 1)
HTM_TxtF (" [%d %s]",NumUsrsInRoom,Txt_connected_PLURAL);
else if (NumUsrsInRoom == 1)
HTM_TxtF (" [1 %s]",Txt_connected_SINGULAR);
/* End strong if room has users */
if (NumUsrsInRoom)
HTM_STRONG_End ();
/* End button */
HTM_BUTTON_End ();
/***** End form *****/
Frm_EndForm ();
/***** End list item *****/
HTM_LI_End (); HTM_LI_End ();
} }
@ -344,21 +355,6 @@ void Cht_WriteParamsRoomCodeAndNames (const char *RoomCode,const char *RoomShrtN
Par_PutHiddenParamString (NULL,"RoomFullName",RoomFullName); Par_PutHiddenParamString (NULL,"RoomFullName",RoomFullName);
} }
/*****************************************************************************/
/*************** Get number of users connected to a chat room ****************/
/*****************************************************************************/
static unsigned Cht_GetNumUsrsInChatRoom (const char *RoomCode)
{
/***** Get number of users connected to chat rooms from database *****/
return DB_QuerySELECTUnsigned ("can not get number of users"
" connected to a chat room",
"SELECT NumUsrs"
" FROM cht_rooms"
" WHERE RoomCode='%s'",
RoomCode);
}
/*****************************************************************************/ /*****************************************************************************/
/******************************* Enter a chat room ***************************/ /******************************* Enter a chat room ***************************/
/*****************************************************************************/ /*****************************************************************************/