swad-core/swad_chat.c

647 lines
25 KiB
C
Raw Normal View History

2014-12-01 23:55:08 +01:00
// swad_chat.c: chat
/*
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.
2019-01-07 21:52:19 +01:00
Copyright (C) 1999-2019 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 <linux/stddef.h> // For NULL
2015-10-16 02:24:29 +02:00
#include <stdbool.h> // For boolean type
2014-12-01 23:55:08 +01:00
#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_chat.h"
#include "swad_config.h"
#include "swad_database.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"
2018-12-08 16:43:13 +01:00
#include "swad_language.h"
2015-01-17 20:06:25 +01:00
#include "swad_logo.h"
2014-12-01 23:55:08 +01:00
#include "swad_parameter.h"
#include "swad_string.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
#define Cht_CHAT_MAX_LEVELS 3
2017-03-09 21:24:06 +01:00
#define Cht_MAX_CHARS_ROOM_CODE 16 // 16, maximum number of chars of the code of a chat room
#define Cht_MAX_BYTES_ROOM_CODE Cht_MAX_CHARS_ROOM_CODE // 16
2017-03-07 11:03:05 +01:00
2017-03-08 14:12:33 +01:00
#define Cht_MAX_CHARS_ROOM_SHRT_NAME (128 - 1) // 127, maximum number of chars of the short name of a chat room
#define Cht_MAX_BYTES_ROOM_SHRT_NAME ((Cht_MAX_CHARS_ROOM_SHRT_NAME + 1) * Str_MAX_BYTES_PER_CHAR - 1) // 2047
2017-03-07 11:03:05 +01:00
2017-03-08 14:12:33 +01:00
#define Cht_MAX_CHARS_ROOM_FULL_NAME (256 - 1) // 255, maximum number of chars of the full name of a chat room
#define Cht_MAX_BYTES_ROOM_FULL_NAME ((Cht_MAX_CHARS_ROOM_FULL_NAME + 1) * Str_MAX_BYTES_PER_CHAR - 1) // 4095
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2017-03-07 11:03:05 +01:00
static void Cht_WriteLinkToChat1 (const char *RoomCode,const char *RoomShrtName,const char *RoomFullName,
2017-01-28 15:58:46 +01:00
unsigned Level,bool IsLastItemInLevel[1 + Cht_CHAT_MAX_LEVELS]);
2015-01-17 19:31:21 +01:00
static void Cht_WriteLinkToChat2 (const char *RoomCode,const char *RoomFullName);
2014-12-29 20:22:46 +01:00
static unsigned Cht_GetNumUsrsInChatRoom (const char *RoomCode);
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/****************** List available whiteboard/chat rooms *********************/
/*****************************************************************************/
void Cht_ShowChatRooms (void)
{
extern const char *Txt_To_use_chat_you_must_have_installed_the_software_X_and_add_Y_;
2017-04-21 14:39:21 +02:00
extern const char *Txt_Unfortunately_Firefox_and_Chrome_no_longer_allow_Java_to_run_;
2014-12-01 23:55:08 +01:00
/***** Help message about software needed to use the whiteboard/chat *****/
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_INFO,Txt_To_use_chat_you_must_have_installed_the_software_X_and_add_Y_,
2019-02-16 00:03:58 +01:00
Cfg_JAVA_URL,Cfg_JAVA_NAME,
Cfg_PLATFORM_SERVER);
2014-12-01 23:55:08 +01:00
/***** List available chat rooms *****/
Cht_ShowListOfAvailableChatRooms ();
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_Unfortunately_Firefox_and_Chrome_no_longer_allow_Java_to_run_);
2017-04-21 14:39:21 +02:00
2017-06-04 18:18:54 +02:00
if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)
2014-12-01 23:55:08 +01:00
Cht_ShowListOfChatRoomsWithUsrs ();
}
/*****************************************************************************/
/*********************** Show list of available chat rooms *******************/
/*****************************************************************************/
void Cht_ShowListOfAvailableChatRooms (void)
{
extern const char *Txt_Chat_rooms;
extern const char *Txt_General;
extern const char *Txt_SEX_PLURAL_Abc[Usr_NUM_SEXS];
extern const char *Txt_SEX_PLURAL_abc[Usr_NUM_SEXS];
extern const char *Txt_ROLES_PLURAL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2017-05-30 21:43:05 +02:00
extern const char *Txt_ROLES_PLURAL_BRIEF_Abc[Rol_NUM_ROLES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Degree;
extern const char *Txt_Course;
2017-01-28 15:58:46 +01:00
bool IsLastItemInLevel[1 + Cht_CHAT_MAX_LEVELS];
2014-12-01 23:55:08 +01:00
unsigned NumMyDeg;
struct Degree Deg;
struct Course Crs;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2015-01-17 19:31:21 +01:00
unsigned long NumRow;
unsigned long NumRows;
2017-03-07 11:03:05 +01:00
char ThisRoomCode [Cht_MAX_BYTES_ROOM_CODE + 1];
char ThisRoomShrtName[Cht_MAX_BYTES_ROOM_SHRT_NAME + 1];
char ThisRoomFullName[Cht_MAX_BYTES_ROOM_FULL_NAME + 1];
2014-12-01 23:55:08 +01:00
/***** Fill the list with the degrees I belong to *****/
Usr_GetMyDegrees ();
2017-06-12 14:16:33 +02:00
/***** Start box *****/
2017-06-10 21:38:10 +02:00
Box_StartBox (NULL,Txt_Chat_rooms,NULL,
2017-06-12 15:03:29 +02:00
NULL,Box_NOT_CLOSABLE);
2016-12-19 00:55:24 +01:00
fprintf (Gbl.F.Out,"<ul class=\"LIST_LEFT\">");
2014-12-01 23:55:08 +01:00
/***** Title of top level *****/
2015-09-28 18:28:29 +02:00
fprintf (Gbl.F.Out,"<li class=\"DAT\" style=\"height:25px;\">"
2019-01-11 02:55:01 +01:00
"<img src=\"%s/comments.svg\""
2015-07-21 17:24:52 +02:00
" alt=\"%s\" title=\"%s\""
2019-01-11 02:55:01 +01:00
" class=\"ICO16x16\" />"
2014-12-29 20:22:46 +01:00
" %s"
"</li>",
2019-03-20 01:36:36 +01:00
Cfg_URL_ICON_PUBLIC,
2015-07-25 19:23:40 +02:00
Txt_Chat_rooms,
Txt_Chat_rooms,
2015-07-21 17:24:52 +02:00
Txt_Chat_rooms);
2014-12-01 23:55:08 +01:00
/***** Link to chat available for all the users *****/
2017-05-20 12:04:12 +02:00
IsLastItemInLevel[1] = (!Gbl.Usrs.Me.IBelongToCurrentCrs &&
2016-10-28 10:03:37 +02:00
!Gbl.Usrs.Me.MyDegs.Num);
2018-10-17 10:32:18 +02:00
snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),
"%s (%s)",
Txt_General,Txt_SEX_PLURAL_abc[Usr_SEX_ALL]);
2015-01-17 19:31:21 +01:00
Cht_WriteLinkToChat1 ("GBL_USR",Txt_SEX_PLURAL_Abc[Usr_SEX_ALL],ThisRoomFullName,1,IsLastItemInLevel);
2019-01-11 02:55:01 +01:00
fprintf (Gbl.F.Out,"<img src=\"%s/comments.svg\""
2015-09-05 11:48:44 +02:00
" alt=\"%s\" title=\"%s\""
2019-01-11 02:55:01 +01:00
" class=\"ICO16x16\" />",
2019-03-20 01:36:36 +01:00
Cfg_URL_ICON_PUBLIC,
2015-07-25 19:23:40 +02:00
ThisRoomFullName,
ThisRoomFullName);
2015-01-17 19:31:21 +01:00
Cht_WriteLinkToChat2 ("GBL_USR",ThisRoomFullName);
2016-10-28 10:03:37 +02:00
IsLastItemInLevel[1] = !Gbl.Usrs.Me.MyDegs.Num;
2017-06-04 18:18:54 +02:00
switch (Gbl.Usrs.Me.Role.Logged)
2014-12-01 23:55:08 +01:00
{
2017-05-18 19:13:41 +02:00
case Rol_STD:
2018-10-17 10:32:18 +02:00
snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),
"%s (%s)",
Txt_General,Txt_ROLES_PLURAL_abc[Rol_STD][Usr_SEX_ALL]);
2017-05-30 21:43:05 +02:00
Cht_WriteLinkToChat1 ("GBL_STD",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD],ThisRoomFullName,1,IsLastItemInLevel);
2019-01-11 02:55:01 +01:00
fprintf (Gbl.F.Out,"<img src=\"%s/comments.svg\""
2015-09-05 11:48:44 +02:00
" alt=\"%s\" title=\"%s\""
2019-01-11 02:55:01 +01:00
" class=\"ICO16x16\" />",
2019-03-20 01:36:36 +01:00
Cfg_URL_ICON_PUBLIC,
2015-07-21 17:24:52 +02:00
ThisRoomFullName,ThisRoomFullName);
2015-01-17 19:31:21 +01:00
Cht_WriteLinkToChat2 ("GBL_STD",ThisRoomFullName);
2014-12-01 23:55:08 +01:00
break;
2017-05-21 21:23:13 +02:00
case Rol_NET:
2017-05-18 19:13:41 +02:00
case Rol_TCH:
2018-10-17 10:32:18 +02:00
snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),
"%s (%s)",
Txt_General,Txt_ROLES_PLURAL_abc[Rol_TCH][Usr_SEX_ALL]);
2017-05-30 21:43:05 +02:00
Cht_WriteLinkToChat1 ("GBL_TCH",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH],ThisRoomFullName,1,IsLastItemInLevel);
2019-01-11 02:55:01 +01:00
fprintf (Gbl.F.Out,"<img src=\"%s/comments.svg\""
2015-09-05 11:48:44 +02:00
" alt=\"%s\" title=\"%s\""
2019-01-11 02:55:01 +01:00
" class=\"ICO16x16\" />",
2019-03-20 01:36:36 +01:00
Cfg_URL_ICON_PUBLIC,
2015-07-21 17:24:52 +02:00
ThisRoomFullName,ThisRoomFullName);
2015-01-17 19:31:21 +01:00
Cht_WriteLinkToChat2 ("GBL_TCH",ThisRoomFullName);
2014-12-01 23:55:08 +01:00
break;
default:
break;
}
/***** Link to chat of users from my degrees *****/
for (NumMyDeg = 0;
2016-10-28 10:03:37 +02:00
NumMyDeg < Gbl.Usrs.Me.MyDegs.Num;
2014-12-01 23:55:08 +01:00
NumMyDeg++)
{
/* Get data of this degree */
2016-10-28 10:03:37 +02:00
Deg.DegCod = Gbl.Usrs.Me.MyDegs.Degs[NumMyDeg].DegCod;
2014-12-01 23:55:08 +01:00
if (!Deg_GetDataOfDegreeByCod (&Deg))
Lay_ShowErrorAndExit ("Degree not found.");
/* Link to the room of this degree */
2016-10-28 10:03:37 +02:00
IsLastItemInLevel[1] = (NumMyDeg == Gbl.Usrs.Me.MyDegs.Num - 1);
2018-10-17 10:32:18 +02:00
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);
2016-10-28 10:03:37 +02:00
Cht_WriteLinkToChat1 (ThisRoomCode,ThisRoomShrtName,ThisRoomFullName,1,IsLastItemInLevel);
2019-04-03 20:57:04 +02:00
Log_DrawLogo (Hie_DEG,Deg.DegCod,Deg.ShrtName,16,NULL,true);
2015-01-17 19:31:21 +01:00
Cht_WriteLinkToChat2 (ThisRoomCode,ThisRoomFullName);
2014-12-01 23:55:08 +01:00
/* Get my courses in this degree from database */
if ((NumRows = Usr_GetCrssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,Deg.DegCod,&mysql_res)) > 0) // Courses found in this degree
for (NumRow = 0;
NumRow < NumRows;
NumRow++)
{
/* 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 */
2015-01-17 19:31:21 +01:00
IsLastItemInLevel[2] = (NumRow == NumRows - 1);
2018-10-17 10:32:18 +02:00
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);
2016-10-28 10:03:37 +02:00
Cht_WriteLinkToChat1 (ThisRoomCode,ThisRoomShrtName,ThisRoomFullName,2,IsLastItemInLevel);
2019-01-11 02:55:01 +01:00
fprintf (Gbl.F.Out,"<img src=\"%s/list-ol.svg\""
2015-09-05 11:48:44 +02:00
" alt=\"%s\" title=\"%s\""
2019-01-11 02:55:01 +01:00
" class=\"ICO16x16\" />",
2019-03-20 01:36:36 +01:00
Cfg_URL_ICON_PUBLIC,
2015-07-21 17:24:52 +02:00
ThisRoomFullName,ThisRoomFullName);
2015-01-17 19:31:21 +01:00
Cht_WriteLinkToChat2 (ThisRoomCode,ThisRoomFullName);
2014-12-01 23:55:08 +01:00
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/***** End table *****/
2016-12-19 00:55:24 +01:00
fprintf (Gbl.F.Out,"</ul>");
2017-06-10 21:38:10 +02:00
Box_EndBox ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************** Show list of chat rooms with users *******************/
/*****************************************************************************/
void Cht_ShowListOfChatRoomsWithUsrs (void)
{
extern const char *Txt_Rooms_with_users;
extern const char *Txt_CHAT_Room_code;
extern const char *Txt_No_of_users;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRow,NumRows;
/***** Get chat rooms with connected users from database *****/
2018-10-30 13:59:37 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get chat rooms"
" with connected users",
"SELECT RoomCode,NumUsrs FROM chat"
" WHERE NumUsrs>0"
" ORDER BY NumUsrs DESC,RoomCode");
2014-12-01 23:55:08 +01:00
if (NumRows > 0) // If not empty chat rooms found
{
2017-06-12 14:16:33 +02:00
/***** Start box and table *****/
2017-06-10 21:38:10 +02:00
Box_StartBoxTable (NULL,Txt_Rooms_with_users,NULL,
2017-06-12 15:03:29 +02:00
NULL,Box_NOT_CLOSABLE,2);
2017-06-12 14:16:33 +02:00
/***** Write heading *****/
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<tr>"
2015-09-06 20:02:14 +02:00
"<th class=\"CENTER_MIDDLE LIGHT_BLUE\">"
2015-04-12 18:01:06 +02:00
"%s"
2015-09-05 19:19:39 +02:00
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE LIGHT_BLUE\">"
2014-12-22 14:08:19 +01:00
"%s"
2015-09-05 19:19:39 +02:00
"</th>"
2014-12-01 23:55:08 +01:00
"</tr>",
2015-09-04 19:26:08 +02:00
Txt_CHAT_Room_code,
Txt_No_of_users);
2014-12-01 23:55:08 +01:00
/***** Loop over chat rooms *****/
for (NumRow = 0;
NumRow < NumRows;
NumRow++)
{
/* Get next chat room */
row = mysql_fetch_row (mysql_res);
fprintf (Gbl.F.Out,"<tr>"
2015-07-28 11:05:10 +02:00
"<td class=\"DAT LEFT_MIDDLE\">"
2014-12-22 14:08:19 +01:00
"%s"
"</td>"
2015-07-28 11:05:10 +02:00
"<td class=\"DAT RIGHT_MIDDLE\">"
2014-12-22 14:08:19 +01:00
"%s"
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>",
row[0],row[1]);
}
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2017-06-10 21:38:10 +02:00
Box_EndBoxTable ();
2014-12-01 23:55:08 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/******************** Write title and link to a chat room ********************/
/*****************************************************************************/
2017-03-07 11:03:05 +01:00
static void Cht_WriteLinkToChat1 (const char *RoomCode,const char *RoomShrtName,const char *RoomFullName,
2017-01-28 15:58:46 +01:00
unsigned Level,bool IsLastItemInLevel[1 + Cht_CHAT_MAX_LEVELS])
2014-12-01 23:55:08 +01:00
{
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormInBox[The_NUM_THEMES];
2014-12-01 23:55:08 +01:00
2015-09-28 18:28:29 +02:00
fprintf (Gbl.F.Out,"<li style=\"height:25px;\">");
2014-12-29 13:26:39 +01:00
Lay_IndentDependingOnLevel (Level,IsLastItemInLevel);
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActCht);
2017-03-07 11:03:05 +01:00
Cht_WriteParamsRoomCodeAndNames (RoomCode,RoomShrtName,RoomFullName);
2019-02-22 21:47:50 +01:00
Frm_LinkFormSubmit (RoomFullName,The_ClassFormInBox[Gbl.Prefs.Theme],NULL);
2015-01-17 19:31:21 +01:00
}
static void Cht_WriteLinkToChat2 (const char *RoomCode,const char *RoomFullName)
{
extern const char *Txt_connected_PLURAL;
extern const char *Txt_connected_SINGULAR;
unsigned NumUsrsInRoom = Cht_GetNumUsrsInChatRoom (RoomCode);
2014-12-29 20:22:46 +01:00
if (NumUsrsInRoom)
fprintf (Gbl.F.Out,"<strong>");
2015-07-25 19:23:40 +02:00
fprintf (Gbl.F.Out," %s",RoomFullName);
2014-12-01 23:55:08 +01:00
if (NumUsrsInRoom > 1)
fprintf (Gbl.F.Out," [%d %s]",
NumUsrsInRoom,Txt_connected_PLURAL);
else if (NumUsrsInRoom == 1)
fprintf (Gbl.F.Out," [1 %s]",
Txt_connected_SINGULAR);
2014-12-29 20:22:46 +01:00
if (NumUsrsInRoom)
fprintf (Gbl.F.Out,"</strong>");
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</a>");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</li>");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*** Write parameters with code and names (short and full) of a chat room ****/
/*****************************************************************************/
2017-03-07 11:03:05 +01:00
void Cht_WriteParamsRoomCodeAndNames (const char *RoomCode,const char *RoomShrtName,const char *RoomFullName)
2014-12-01 23:55:08 +01:00
{
Par_PutHiddenParamString ("RoomCode",RoomCode);
2017-03-07 11:03:05 +01:00
Par_PutHiddenParamString ("RoomShrtName",RoomShrtName);
2014-12-01 23:55:08 +01:00
Par_PutHiddenParamString ("RoomFullName",RoomFullName);
}
/*****************************************************************************/
/*************** Get number of users connected to a chat room ****************/
/*****************************************************************************/
2014-12-29 20:22:46 +01:00
static unsigned Cht_GetNumUsrsInChatRoom (const char *RoomCode)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2014-12-29 20:22:46 +01:00
unsigned NumUsrs = 0;
2014-12-01 23:55:08 +01:00
/***** Get number of users connected to chat rooms from database *****/
2018-10-30 13:59:37 +01:00
if (DB_QuerySELECT (&mysql_res,"can not get number of users"
" connected to a chat room",
"SELECT NumUsrs FROM chat WHERE RoomCode='%s'",
RoomCode))
2014-12-01 23:55:08 +01:00
{
/* Get number of users connected to the chat room */
row = mysql_fetch_row (mysql_res);
if (row[0])
2014-12-29 20:22:46 +01:00
if (sscanf (row[0],"%u",&NumUsrs) != 1)
NumUsrs = 0;
2014-12-01 23:55:08 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumUsrs;
}
/*****************************************************************************/
/******************************* Enter a chat room ***************************/
/*****************************************************************************/
2017-03-07 11:03:05 +01:00
#define Cht_MAX_BYTES_ROOM_CODES ((2 + Deg_MAX_DEGREES_PER_USR + Crs_MAX_COURSES_PER_USR) * Cht_MAX_BYTES_ROOM_CODE)
#define Cht_MAX_BYTES_ROOM_SHRT_NAMES ((2 + Deg_MAX_DEGREES_PER_USR + Crs_MAX_COURSES_PER_USR) * Cht_MAX_BYTES_ROOM_SHRT_NAME)
#define Cht_MAX_BYTES_ROOM_FULL_NAMES ((2 + Deg_MAX_DEGREES_PER_USR + Crs_MAX_COURSES_PER_USR) * Cht_MAX_BYTES_ROOM_FULL_NAME)
2017-01-17 03:10:43 +01:00
2014-12-01 23:55:08 +01:00
void Cht_OpenChatWindow (void)
{
extern const char *Txt_SEX_PLURAL_Abc[Usr_NUM_SEXS];
extern const char *Txt_SEX_PLURAL_abc[Usr_NUM_SEXS];
extern const char *Txt_General;
extern const char *Txt_ROLES_PLURAL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2017-05-30 21:43:05 +02:00
extern const char *Txt_ROLES_PLURAL_BRIEF_Abc[Rol_NUM_ROLES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Degree;
extern const char *Txt_Course;
2017-03-07 11:03:05 +01:00
char RoomCode[Cht_MAX_BYTES_ROOM_CODE + 1];
char RoomShrtName[Cht_MAX_BYTES_ROOM_SHRT_NAME + 1];
char RoomFullName [Cht_MAX_BYTES_ROOM_FULL_NAME + 1];
2017-01-13 01:51:23 +01:00
char UsrName[Usr_MAX_BYTES_FULL_NAME + 1];
2014-12-01 23:55:08 +01:00
unsigned NumMyDeg;
unsigned NumMyCrs;
struct Degree Deg;
struct Course Crs;
2017-03-07 11:03:05 +01:00
char ThisRoomCode[Cht_MAX_BYTES_ROOM_CODE + 1];
char ThisRoomShortName[Cht_MAX_BYTES_ROOM_SHRT_NAME + 1];
char ThisRoomFullName [Cht_MAX_BYTES_ROOM_FULL_NAME + 1];
char ListRoomCodes [Cht_MAX_BYTES_ROOM_CODES + 1];
char ListRoomShrtNames[Cht_MAX_BYTES_ROOM_SHRT_NAMES + 1];
char ListRoomFullNames [Cht_MAX_BYTES_ROOM_FULL_NAMES + 1];
2014-12-01 23:55:08 +01:00
FILE *FileChat;
/***** Get the code and the nombre of the room *****/
2017-03-07 11:03:05 +01:00
Par_GetParToText ("RoomCode",RoomCode,Cht_MAX_BYTES_ROOM_CODE);
2014-12-01 23:55:08 +01:00
2017-03-07 11:03:05 +01:00
Par_GetParToText ("RoomShrtName",RoomShrtName,Cht_MAX_BYTES_ROOM_SHRT_NAME);
2014-12-01 23:55:08 +01:00
2017-03-07 11:03:05 +01:00
Par_GetParToText ("RoomFullName",RoomFullName,Cht_MAX_BYTES_ROOM_FULL_NAME);
2014-12-01 23:55:08 +01:00
2017-03-07 11:03:05 +01:00
if (!RoomCode[0] || !RoomShrtName[0] || !RoomFullName[0])
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Wrong code or name of chat room.");
if (strcspn (RoomCode," \t\n\r") != strlen (RoomCode)) // If RoomCode contiene espacios
Lay_ShowErrorAndExit ("Wrong code of chat room.");
/***** Fill the lists with the degrees and courses I belong to *****/
Usr_GetMyDegrees ();
Usr_GetMyCourses ();
/***** Build my user's name *****/
2017-01-17 03:10:43 +01:00
Str_Copy (UsrName,Gbl.Usrs.Me.UsrDat.Surname1,
Usr_MAX_BYTES_FULL_NAME);
2014-12-01 23:55:08 +01:00
if (Gbl.Usrs.Me.UsrDat.Surname2[0])
{
2017-01-17 03:33:05 +01:00
Str_Concat (UsrName," ",
Usr_MAX_BYTES_FULL_NAME);
Str_Concat (UsrName,Gbl.Usrs.Me.UsrDat.Surname2,
Usr_MAX_BYTES_FULL_NAME);
2014-12-01 23:55:08 +01:00
}
2017-01-17 03:33:05 +01:00
Str_Concat (UsrName,", ",
Usr_MAX_BYTES_FULL_NAME);
Str_Concat (UsrName,Gbl.Usrs.Me.UsrDat.FirstName,
Usr_MAX_BYTES_FULL_NAME);
2014-12-01 23:55:08 +01:00
/***** Build the lists of available rooms *****/
2018-10-17 10:32:18 +02:00
snprintf (ListRoomCodes,sizeof (ListRoomCodes),
"#%s",
RoomCode);
2017-03-07 11:03:05 +01:00
Str_Copy (ListRoomShrtNames,RoomShrtName,
Cht_MAX_BYTES_ROOM_SHRT_NAMES);
2017-01-17 03:10:43 +01:00
Str_Copy (ListRoomFullNames ,RoomFullName,
2017-03-07 11:03:05 +01:00
Cht_MAX_BYTES_ROOM_FULL_NAMES);
2017-01-13 01:51:23 +01:00
2014-12-01 23:55:08 +01:00
if (strcmp (RoomCode,"GBL_USR"))
{
2017-01-17 03:33:05 +01:00
Str_Concat (ListRoomCodes,"|#GBL_USR",
2017-03-07 11:03:05 +01:00
Cht_MAX_BYTES_ROOM_CODES);
2017-01-13 01:51:23 +01:00
2018-10-17 10:32:18 +02:00
snprintf (RoomShrtName,sizeof (RoomShrtName),
"|%s",
Txt_SEX_PLURAL_Abc[Usr_SEX_ALL]);
2017-03-07 11:03:05 +01:00
Str_Concat (ListRoomShrtNames,RoomShrtName,
Cht_MAX_BYTES_ROOM_SHRT_NAMES);
2017-01-13 01:51:23 +01:00
2018-10-17 10:32:18 +02:00
snprintf (RoomFullName,sizeof (RoomFullName),
"|%s (%s)",
Txt_General,Txt_SEX_PLURAL_abc[Usr_SEX_ALL]);
2017-01-17 03:33:05 +01:00
Str_Concat (ListRoomFullNames,RoomFullName,
2017-03-07 11:03:05 +01:00
Cht_MAX_BYTES_ROOM_FULL_NAMES);
2014-12-01 23:55:08 +01:00
}
2017-01-13 01:51:23 +01:00
2017-06-04 18:18:54 +02:00
if (Gbl.Usrs.Me.Role.Logged == Rol_STD)
2014-12-01 23:55:08 +01:00
if (strcmp (RoomCode,"GBL_STD"))
{
2017-01-17 03:33:05 +01:00
Str_Concat (ListRoomCodes,"|#GBL_STD",
2017-03-07 11:03:05 +01:00
Cht_MAX_BYTES_ROOM_CODES);
2017-01-13 01:51:23 +01:00
2018-10-17 10:32:18 +02:00
snprintf (RoomShrtName,sizeof (RoomShrtName),
"|%s",
Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD]);
2017-03-07 11:03:05 +01:00
Str_Concat (ListRoomShrtNames,RoomShrtName,
Cht_MAX_BYTES_ROOM_SHRT_NAMES);
2017-01-13 01:51:23 +01:00
2018-10-17 10:32:18 +02:00
snprintf (RoomFullName,sizeof (RoomFullName),
"|%s (%s)",
Txt_General,Txt_ROLES_PLURAL_abc[Rol_STD][Usr_SEX_ALL]);
2017-01-17 03:33:05 +01:00
Str_Concat (ListRoomFullNames,RoomFullName,
2017-03-07 11:03:05 +01:00
Cht_MAX_BYTES_ROOM_FULL_NAMES);
2014-12-01 23:55:08 +01:00
}
2017-01-13 01:51:23 +01:00
2017-06-04 18:18:54 +02:00
if (Gbl.Usrs.Me.Role.Logged == Rol_NET ||
Gbl.Usrs.Me.Role.Logged == Rol_TCH)
2014-12-01 23:55:08 +01:00
if (strcmp (RoomCode,"GBL_TCH"))
{
2017-01-17 03:33:05 +01:00
Str_Concat (ListRoomCodes,"|#GBL_TCH",
2017-03-07 11:03:05 +01:00
Cht_MAX_BYTES_ROOM_CODES);
2017-01-13 01:51:23 +01:00
2018-10-17 10:32:18 +02:00
snprintf (RoomShrtName,sizeof (RoomShrtName),
"|%s",
Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]);
2017-03-07 11:03:05 +01:00
Str_Concat (ListRoomShrtNames,RoomShrtName,
Cht_MAX_BYTES_ROOM_SHRT_NAMES);
2017-01-13 01:51:23 +01:00
2018-10-17 10:32:18 +02:00
snprintf (RoomFullName,sizeof (RoomFullName),
"|%s (%s)",
Txt_General,Txt_ROLES_PLURAL_abc[Rol_TCH][Usr_SEX_ALL]);
2017-01-17 03:33:05 +01:00
Str_Concat (ListRoomFullNames,RoomFullName,
2017-03-07 11:03:05 +01:00
Cht_MAX_BYTES_ROOM_FULL_NAMES);
2014-12-01 23:55:08 +01:00
}
2017-01-13 01:51:23 +01:00
2014-12-01 23:55:08 +01:00
for (NumMyDeg = 0;
2016-10-28 10:03:37 +02:00
NumMyDeg < Gbl.Usrs.Me.MyDegs.Num;
2014-12-01 23:55:08 +01:00
NumMyDeg++)
{
2018-10-17 10:32:18 +02:00
snprintf (ThisRoomCode,sizeof (ThisRoomCode),
"DEG_%ld",
Gbl.Usrs.Me.MyDegs.Degs[NumMyDeg].DegCod);
2014-12-01 23:55:08 +01:00
if (strcmp (RoomCode,ThisRoomCode))
{
2017-01-17 03:33:05 +01:00
Str_Concat (ListRoomCodes,"|#",
2017-03-07 11:03:05 +01:00
Cht_MAX_BYTES_ROOM_CODES);
2017-01-17 03:33:05 +01:00
Str_Concat (ListRoomCodes,ThisRoomCode,
2017-03-07 11:03:05 +01:00
Cht_MAX_BYTES_ROOM_CODES);
2014-12-01 23:55:08 +01:00
/* Get data of this degree */
2016-10-28 10:03:37 +02:00
Deg.DegCod = Gbl.Usrs.Me.MyDegs.Degs[NumMyDeg].DegCod;
2014-12-01 23:55:08 +01:00
Deg_GetDataOfDegreeByCod (&Deg);
2018-10-17 10:32:18 +02:00
snprintf (ThisRoomShortName,sizeof (ThisRoomShortName),
"%s",
Deg.ShrtName);
2017-03-07 11:03:05 +01:00
Str_Concat (ListRoomShrtNames,"|",
Cht_MAX_BYTES_ROOM_SHRT_NAMES);
Str_Concat (ListRoomShrtNames,ThisRoomShortName,
Cht_MAX_BYTES_ROOM_SHRT_NAMES);
2014-12-01 23:55:08 +01:00
2018-10-17 10:32:18 +02:00
snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),
"%s %s",
Txt_Degree,Deg.ShrtName);
2017-01-17 03:33:05 +01:00
Str_Concat (ListRoomFullNames,"|",
2017-03-07 11:03:05 +01:00
Cht_MAX_BYTES_ROOM_FULL_NAMES);
2017-01-17 03:33:05 +01:00
Str_Concat (ListRoomFullNames,ThisRoomFullName,
2017-03-07 11:03:05 +01:00
Cht_MAX_BYTES_ROOM_FULL_NAMES);
2014-12-01 23:55:08 +01:00
}
}
2017-01-13 01:51:23 +01:00
2014-12-01 23:55:08 +01:00
for (NumMyCrs = 0;
2016-10-28 10:03:37 +02:00
NumMyCrs < Gbl.Usrs.Me.MyCrss.Num;
2014-12-01 23:55:08 +01:00
NumMyCrs++)
{
2018-10-17 10:32:18 +02:00
snprintf (ThisRoomCode,sizeof (ThisRoomCode),
"CRS_%ld",
Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].CrsCod);
2014-12-01 23:55:08 +01:00
if (strcmp (RoomCode,ThisRoomCode))
{
2017-01-17 03:33:05 +01:00
Str_Concat (ListRoomCodes,"|#",
2017-03-07 11:03:05 +01:00
Cht_MAX_BYTES_ROOM_CODES);
2017-01-17 03:33:05 +01:00
Str_Concat (ListRoomCodes,ThisRoomCode,
2017-03-07 11:03:05 +01:00
Cht_MAX_BYTES_ROOM_CODES);
2014-12-01 23:55:08 +01:00
/* Get data of this course */
2016-10-28 10:03:37 +02:00
Crs.CrsCod = Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].CrsCod;
2014-12-01 23:55:08 +01:00
Crs_GetDataOfCourseByCod (&Crs);
2018-10-17 10:32:18 +02:00
snprintf (ThisRoomShortName,sizeof (ThisRoomShortName),
"%s",
Crs.ShrtName);
2017-03-07 11:03:05 +01:00
Str_Concat (ListRoomShrtNames,"|",
Cht_MAX_BYTES_ROOM_SHRT_NAMES);
Str_Concat (ListRoomShrtNames,ThisRoomShortName,
Cht_MAX_BYTES_ROOM_SHRT_NAMES);
2017-01-15 02:05:24 +01:00
2018-10-17 10:32:18 +02:00
snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),
"%s %s",
Txt_Course,Crs.ShrtName);
2017-01-17 03:33:05 +01:00
Str_Concat (ListRoomFullNames,"|",
2017-03-07 11:03:05 +01:00
Cht_MAX_BYTES_ROOM_FULL_NAMES);
2017-01-17 03:33:05 +01:00
Str_Concat (ListRoomFullNames,ThisRoomFullName,
2017-03-07 11:03:05 +01:00
Cht_MAX_BYTES_ROOM_FULL_NAMES);
2014-12-01 23:55:08 +01:00
}
}
/***** Open index.html file with the HTML page for the chat *****/
if ((FileChat = fopen (Cfg_PATH_AND_FILE_REL_CHAT_PRIVATE,"rb")) == NULL)
Lay_ShowErrorAndExit ("Can not open chat.");
/***** Start writing the index.html file to the output *****/
2014-12-21 14:47:04 +01:00
fprintf (Gbl.F.Out,"Content-type: text/html; charset=windows-1252\n\n"); // Two carriage returns at the end of the line are mandatory!
2014-12-01 23:55:08 +01:00
Gbl.Layout.HTMLStartWritten = true;
/***** Copy index.html file until the end of the applet code *****/
2016-09-19 17:49:25 +02:00
Str_WriteUntilStrFoundInFileIncludingStr (Gbl.F.Out,FileChat,"<applet",
Str_NO_SKIP_HTML_COMMENTS);
Str_WriteUntilStrFoundInFileIncludingStr (Gbl.F.Out,FileChat,">",
Str_NO_SKIP_HTML_COMMENTS);
2014-12-01 23:55:08 +01:00
/***** Write parameters *****/
fprintf (Gbl.F.Out,"\n<param name=\"nick\" value=\"N%s\">",
Gbl.Session.Id);
fprintf (Gbl.F.Out,"\n<param name=\"realname\" value=\"%s\">",
UsrName);
fprintf (Gbl.F.Out,"\n<param name=\"host\" value=\"%s\">",
Gbl.IP);
fprintf (Gbl.F.Out,"\n<param name=\"server_name\" value=\"%s\">",
Cfg_PLATFORM_SERVER);
fprintf (Gbl.F.Out,"\n<param name=\"port\" value=\"5000\">");
2019-03-20 01:36:36 +01:00
fprintf (Gbl.F.Out,"\n<param name=\"image_bl\" value=\"%s/usr_bl.jpg\">",
Cfg_URL_ICON_PUBLIC);
fprintf (Gbl.F.Out,"\n<param name=\"image_url\" value=\"%s/%s.jpg\">",
Cfg_URL_PHOTO_PUBLIC,Gbl.Usrs.Me.UsrDat.Photo);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"\n<param name=\"channel_name\" value=\"%s\">",
ListRoomCodes);
fprintf (Gbl.F.Out,"\n<param name=\"tab\" value=\"%s\">",
2017-03-07 11:03:05 +01:00
ListRoomShrtNames);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"\n<param name=\"topic\" value=\"%s\">",
ListRoomFullNames);
/***** Copy index.html file until the end *****/
2016-09-19 17:49:25 +02:00
Str_WriteUntilStrFoundInFileIncludingStr (Gbl.F.Out,FileChat,"</html>",
Str_NO_SKIP_HTML_COMMENTS);
2014-12-01 23:55:08 +01:00
/***** Close index.html file *****/
fclose (FileChat);
2015-11-27 21:24:24 +01:00
Gbl.Layout.DivsEndWritten = Gbl.Layout.HTMLEndWritten = true;
2014-12-01 23:55:08 +01:00
}