"
""
""
"");
Msg_IndentDependingOnLevel (Level,IsLastItemInLevel);
fprintf (Gbl.F.Out,"");
Act_FormStart (ActCht);
Cht_WriteParamsRoomCodeAndNames (RoomCode,RoomShortName,RoomFullName);
Act_LinkFormSubmit (RoomFullName,(NumUsrsInRoom > 0) ? The_ClassFormulB[Gbl.Prefs.Theme] :
The_ClassFormul[Gbl.Prefs.Theme]);
fprintf (Gbl.F.Out,"%s %s",Icon,RoomFullName);
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);
fprintf (Gbl.F.Out,""
""
" | "
" "
" "
" | "
"
");
}
/*****************************************************************************/
/*** Write parameters with code and names (short and full) of a chat room ****/
/*****************************************************************************/
void Cht_WriteParamsRoomCodeAndNames (const char *RoomCode,const char *RoomShortName,const char *RoomFullName)
{
Par_PutHiddenParamString ("RoomCode",RoomCode);
Par_PutHiddenParamString ("RoomShortName",RoomShortName);
Par_PutHiddenParamString ("RoomFullName",RoomFullName);
}
/*****************************************************************************/
/*************** Get number of users connected to a chat room ****************/
/*****************************************************************************/
int Cht_GetNumUsrsInChatRoom (const char *RoomCode)
{
char Query[512];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
int NumUsrs = -1; // -1 ==> room is not in database. We can not know the number of usrs connected
/***** Get number of users connected to chat rooms from database *****/
sprintf (Query,"SELECT NumUsrs FROM chat WHERE RoomCode='%s'",RoomCode);
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get number of users connected to a chat room");
/***** Check number of rows of the result *****/
if (NumRows == 1)
{
/* Get number of users connected to the chat room */
row = mysql_fetch_row (mysql_res);
if (row[0])
if (sscanf (row[0],"%d",&NumUsrs) == 1)
if (NumUsrs < 0)
NumUsrs = -1;
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumUsrs;
}
/*****************************************************************************/
/******************************* Enter a chat room ***************************/
/*****************************************************************************/
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];
extern const char *Txt_Students_ABBREVIATION;
extern const char *Txt_Teachers_ABBREVIATION;
extern const char *Txt_Degree;
extern const char *Txt_Course;
char RoomCode [MAX_LENGTH_ROOM_CODE +1];
char RoomShortName[MAX_LENGTH_ROOM_SHORT_NAME+1];
char RoomFullName [MAX_LENGTH_ROOM_FULL_NAME +1];
char UsrName[3*(Usr_MAX_BYTES_NAME+1)];
unsigned NumMyDeg;
unsigned NumMyCrs;
struct Degree Deg;
struct Course Crs;
char ThisRoomCode [MAX_LENGTH_ROOM_CODE +1];
char ThisRoomShortName[MAX_LENGTH_ROOM_SHORT_NAME+1];
char ThisRoomFullName [MAX_LENGTH_ROOM_FULL_NAME +1];
char ListRoomCodes [(3+Deg_MAX_DEGREES_PER_USR+Crs_MAX_COURSES_PER_USR)*MAX_LENGTH_ROOM_CODE +1];
char ListRoomShortNames[(3+Deg_MAX_DEGREES_PER_USR+Crs_MAX_COURSES_PER_USR)*MAX_LENGTH_ROOM_SHORT_NAME+1];
char ListRoomFullNames [(3+Deg_MAX_DEGREES_PER_USR+Crs_MAX_COURSES_PER_USR)*MAX_LENGTH_ROOM_FULL_NAME +1];
FILE *FileChat;
/***** Get the code and the nombre of the room *****/
Par_GetParToText ("RoomCode",RoomCode,MAX_LENGTH_ROOM_CODE);
Par_GetParToText ("RoomShortName",RoomShortName,MAX_LENGTH_ROOM_SHORT_NAME);
Par_GetParToText ("RoomFullName",RoomFullName,MAX_LENGTH_ROOM_FULL_NAME);
if (!RoomCode[0] || !RoomShortName[0] || !RoomFullName[0])
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 *****/
strcpy (UsrName,Gbl.Usrs.Me.UsrDat.Surname1);
if (Gbl.Usrs.Me.UsrDat.Surname2[0])
{
strcat (UsrName," ");
strcat (UsrName,Gbl.Usrs.Me.UsrDat.Surname2);
}
strcat (UsrName,", ");
strcat (UsrName,Gbl.Usrs.Me.UsrDat.FirstName);
/***** Build the lists of available rooms *****/
sprintf (ListRoomCodes,"#%s",RoomCode);
strcpy (ListRoomShortNames,RoomShortName);
strcpy (ListRoomFullNames ,RoomFullName);
if (strcmp (RoomCode,"GBL_USR"))
{
strcat (ListRoomCodes,"|#GBL_USR");
sprintf (RoomShortName,"|%s",Txt_SEX_PLURAL_Abc[Usr_SEX_ALL]);
strcat (ListRoomShortNames,RoomShortName);
sprintf (RoomFullName,"|%s (%s)",Txt_General,Txt_SEX_PLURAL_abc[Usr_SEX_ALL]);
strcat (ListRoomFullNames,RoomFullName);
}
if (Gbl.Usrs.Me.LoggedRole == Rol_ROLE_STUDENT)
if (strcmp (RoomCode,"GBL_STD"))
{
strcat (ListRoomCodes,"|#GBL_STD");
sprintf (RoomShortName,"|%s",Txt_Students_ABBREVIATION);
strcat (ListRoomShortNames,RoomShortName);
sprintf (RoomFullName,"|%s (%s)",Txt_General,Txt_ROLES_PLURAL_abc[Rol_ROLE_STUDENT][Usr_SEX_ALL]);
strcat (ListRoomFullNames,RoomFullName);
}
if (Gbl.Usrs.Me.LoggedRole == Rol_ROLE_TEACHER)
if (strcmp (RoomCode,"GBL_TCH"))
{
strcat (ListRoomCodes,"|#GBL_TCH");
sprintf (RoomShortName,"|%s",Txt_Teachers_ABBREVIATION);
strcat (ListRoomShortNames,RoomShortName);
sprintf (RoomFullName,"|%s (%s)",Txt_General,Txt_ROLES_PLURAL_abc[Rol_ROLE_TEACHER][Usr_SEX_ALL]);
strcat (ListRoomFullNames,RoomFullName);
}
for (NumMyDeg = 0;
NumMyDeg < Gbl.Usrs.Me.MyDegrees.Num;
NumMyDeg++)
{
sprintf (ThisRoomCode,"DEG_%ld",Gbl.Usrs.Me.MyDegrees.Degs[NumMyDeg].DegCod);
if (strcmp (RoomCode,ThisRoomCode))
{
strcat (ListRoomCodes,"|#");
strcat (ListRoomCodes,ThisRoomCode);
/* Get data of this degree */
Deg.DegCod = Gbl.Usrs.Me.MyDegrees.Degs[NumMyDeg].DegCod;
Deg_GetDataOfDegreeByCod (&Deg);
sprintf (ThisRoomShortName,"%s",Deg.ShortName);
strcat (ListRoomShortNames,"|");
strcat (ListRoomShortNames,ThisRoomShortName);
sprintf (ThisRoomFullName,"%s %s",Txt_Degree,Deg.ShortName);
strcat (ListRoomFullNames,"|");
strcat (ListRoomFullNames,ThisRoomFullName);
}
}
for (NumMyCrs = 0;
NumMyCrs < Gbl.Usrs.Me.MyCourses.Num;
NumMyCrs++)
{
sprintf (ThisRoomCode,"CRS_%ld",Gbl.Usrs.Me.MyCourses.Crss[NumMyCrs].CrsCod);
if (strcmp (RoomCode,ThisRoomCode))
{
strcat (ListRoomCodes,"|#");
strcat (ListRoomCodes,ThisRoomCode);
/* Get data of this course */
Crs.CrsCod = Gbl.Usrs.Me.MyCourses.Crss[NumMyCrs].CrsCod;
Crs_GetDataOfCourseByCod (&Crs);
sprintf (ThisRoomShortName,"%s",Crs.ShortName);
strcat (ListRoomShortNames,"|");
strcat (ListRoomShortNames,ThisRoomShortName);
sprintf (ThisRoomFullName,"%s %s",Txt_Course,Crs.ShortName);
strcat (ListRoomFullNames,"|");
strcat (ListRoomFullNames,ThisRoomFullName);
}
}
/***** 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 *****/
fprintf (Gbl.F.Out,"Content-type: text/html; charset=ISO-8859-1\n\n"); // Two carriage returns at the end of the line are mandatory!
Gbl.Layout.HTMLStartWritten = true;
/***** Copy index.html file until the end of the applet code *****/
Str_WriteUntilStrFoundInFileIncludingStr (Gbl.F.Out,FileChat,"