swad-core/swad_user.c

8529 lines
306 KiB
C
Raw Normal View History

2014-12-01 23:55:08 +01:00
// swad_user.c: users
/*
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.
2017-01-13 01:51:23 +01:00
Copyright (C) 1999-2017 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 3 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 <ctype.h> // For isalnum, isdigit, etc.
#include <limits.h> // For maximum values
#include <linux/limits.h> // For PATH_MAX
#include <linux/stddef.h> // For NULL
#include <stdlib.h> // For exit, system, malloc, free, rand, etc.
#include <string.h> // For string functions
#include <sys/wait.h> // For the macro WEXITSTATUS
#include <unistd.h> // For access, lstat, getpid, chdir, symlink, unlink
2014-12-12 22:39:55 +01:00
#include "swad_account.h"
2014-12-01 23:55:08 +01:00
#include "swad_announcement.h"
2015-11-21 20:23:28 +01:00
#include "swad_calendar.h"
2014-12-01 23:55:08 +01:00
#include "swad_config.h"
#include "swad_connected.h"
#include "swad_course.h"
#include "swad_database.h"
2016-06-16 19:30:29 +02:00
#include "swad_duplicate.h"
2017-03-30 11:20:06 +02:00
#include "swad_enrolment.h"
2014-12-01 23:55:08 +01:00
#include "swad_global.h"
#include "swad_group.h"
2015-10-06 20:34:49 +02:00
#include "swad_help.h"
2016-11-14 16:47:46 +01:00
#include "swad_hierarchy.h"
2014-12-01 23:55:08 +01:00
#include "swad_ID.h"
2017-05-07 18:06:34 +02:00
#include "swad_language.h"
2016-06-03 13:42:28 +02:00
#include "swad_MFU.h"
2014-12-01 23:55:08 +01:00
#include "swad_nickname.h"
#include "swad_notification.h"
#include "swad_parameter.h"
#include "swad_password.h"
#include "swad_preference.h"
2016-12-09 13:59:33 +01:00
#include "swad_privacy.h"
2016-12-07 00:41:36 +01:00
#include "swad_QR.h"
2014-12-01 23:55:08 +01:00
#include "swad_record.h"
2016-12-13 13:32:19 +01:00
#include "swad_role.h"
2015-01-04 15:48:24 +01:00
#include "swad_tab.h"
2014-12-01 23:55:08 +01:00
#include "swad_user.h"
/*****************************************************************************/
/****************************** Public constants *****************************/
/*****************************************************************************/
const char *Usr_StringsSexDB[Usr_NUM_SEXS] =
{
"unknown",
"female",
"male",
"all",
};
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
const char *Usr_StringsUsrListTypeInDB[Usr_NUM_USR_LIST_TYPES] =
{
2017-01-29 21:41:08 +01:00
"", // Usr_LIST_UNKNOWN
"classphoto", // Usr_LIST_AS_CLASS_PHOTO
"list", // Usr_LIST_AS_LISTING
2014-12-01 23:55:08 +01:00
};
const char *Usr_IconsClassPhotoOrList[Usr_NUM_USR_LIST_TYPES] =
{
2017-01-29 21:41:08 +01:00
"", // Usr_LIST_UNKNOWN
"classphoto16x16.gif", // Usr_LIST_AS_CLASS_PHOTO
"list64x64.gif", // Usr_LIST_AS_LISTING
2014-12-01 23:55:08 +01:00
};
2016-07-25 16:08:25 +02:00
#define Usr_NUM_MAIN_FIELDS_DATA_ADM 7
#define Usr_NUM_ALL_FIELDS_DATA_GST 17
2014-12-01 23:55:08 +01:00
#define Usr_NUM_ALL_FIELDS_DATA_STD 13
#define Usr_NUM_ALL_FIELDS_DATA_TCH 11
const char *Usr_UsrDatMainFieldNames[Usr_NUM_MAIN_FIELDS_DATA_USR];
2017-03-08 03:48:23 +01:00
#define Usr_MAX_BYTES_QUERY_GET_LIST_USRS (16 * 1024 - 1)
2017-01-16 01:51:01 +01:00
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/****************************** Internal types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/************************* Internal global variables *************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
static void Usr_GetMyLastData (void);
static void Usr_GetUsrCommentsFromString (char *Str,struct UsrData *UsrDat);
static Usr_Sex_t Usr_GetSexFromStr (const char *Str);
static bool Usr_CheckIfMyBirthdayHasNotBeenCongratulated (void);
static void Usr_InsertMyBirthday (void);
2016-09-22 01:28:31 +02:00
static void Usr_RemoveTemporaryTableMyCourses (void);
2014-12-01 23:55:08 +01:00
static void Usr_GetParamOtherUsrIDNickOrEMail (void);
static bool Usr_ChkUsrAndGetUsrDataFromDirectLogin (void);
static bool Usr_ChkUsrAndGetUsrDataFromSession (void);
2016-03-01 03:16:29 +01:00
static void Usr_ShowAlertUsrDoesNotExistsOrWrongPassword (void);
static void Usr_ShowAlertThereAreMoreThanOneUsr (void);
2014-12-01 23:55:08 +01:00
static void Usr_SetUsrRoleAndPrefs (void);
static void Usr_InsertMyLastData (void);
static void Usr_WriteRowGstAllData (struct UsrData *UsrDat);
2016-06-16 11:28:20 +02:00
static void Usr_WriteRowStdAllData (struct UsrData *UsrDat,char *GroupNames);
static void Usr_WriteRowTchAllData (struct UsrData *UsrDat);
static void Usr_WriteRowAdmData (unsigned NumUsr,struct UsrData *UsrDat);
2016-04-23 13:23:09 +02:00
static void Usr_WriteMainUsrDataExceptUsrID (struct UsrData *UsrDat,
2016-07-27 14:58:26 +02:00
const char *BgColor);
2016-07-25 16:08:25 +02:00
static void Usr_WriteEmail (struct UsrData *UsrDat,const char *BgColor);
2016-04-23 13:23:09 +02:00
static void Usr_WriteUsrData (const char *BgColor,
const char *Data,const char *Link,
bool NonBreak,bool Accepted);
2014-12-01 23:55:08 +01:00
2017-01-16 01:51:01 +01:00
static void Usr_BuildQueryToGetUsrsLstCrs (Rol_Role_t Role,
2017-03-08 03:48:23 +01:00
char Query[Usr_MAX_BYTES_QUERY_GET_LIST_USRS + 1]);
2016-06-24 15:31:09 +02:00
2014-12-01 23:55:08 +01:00
static void Usr_GetAdmsLst (Sco_Scope_t Scope);
static void Usr_GetGstsLst (Sco_Scope_t Scope);
2016-06-23 13:10:43 +02:00
static void Usr_GetListUsrsFromQuery (const char *Query,Rol_Role_t Role,Sco_Scope_t Scope);
static void Usr_AllocateUsrsList (Rol_Role_t Role);
2016-07-04 12:50:17 +02:00
2016-07-04 14:03:04 +02:00
static void Usr_PutButtonToConfirmIWantToSeeBigList (unsigned NumUsrs,const char *OnSubmit);
2016-07-04 12:50:17 +02:00
static void Usr_ShowWarningListIsTooBig (unsigned NumUsrs);
2014-12-01 23:55:08 +01:00
static void Usr_AllocateListOtherRecipients (void);
static void Usr_FormToSelectUsrListType (Act_Action_t NextAction,Usr_ShowUsrsType_t ListType);
2016-06-23 13:10:43 +02:00
static Usr_Sex_t Usr_GetSexOfUsrsLst (Rol_Role_t Role);
2014-12-01 23:55:08 +01:00
2015-09-30 23:10:15 +02:00
static void Usr_PutCheckboxToSelectUser (struct UsrData *UsrDat,bool UsrIsTheMsgSender);
2015-10-02 01:04:28 +02:00
static void Usr_PutCheckboxListWithPhotos (void);
2015-09-30 23:10:15 +02:00
2014-12-01 23:55:08 +01:00
static void Usr_ListMainDataGsts (bool PutCheckBoxToSelectUsr);
static void Usr_ListMainDataStds (bool PutCheckBoxToSelectUsr);
static void Usr_ListMainDataTchs (bool PutCheckBoxToSelectUsr);
static void Usr_GetAndUpdateUsrListType (void);
2017-01-29 21:41:08 +01:00
static void Usr_GetUsrListTypeFromForm (void);
2014-12-01 23:55:08 +01:00
static void Usr_GetMyUsrListTypeFromDB (void);
static void Usr_UpdateMyUsrListTypeInDB (void);
2017-01-29 21:41:08 +01:00
static void Usr_GetParamColsClassPhotoFromForm (void);
2014-12-01 23:55:08 +01:00
static void Usr_GetMyColsClassPhotoFromDB (void);
static void Usr_UpdateMyColsClassPhotoInDB (void);
static void Usr_GetAndUpdatePrefAboutListWithPhotos (void);
static bool Usr_GetParamListWithPhotosFromForm (void);
static void Usr_UpdateMyPrefAboutListWithPhotosPhotoInDB (void);
2015-04-02 18:39:49 +02:00
2015-09-17 16:54:02 +02:00
static void Usr_PutLinkToSeeAdmins (void);
static void Usr_PutLinkToSeeGuests (void);
2016-03-18 21:28:45 +01:00
2016-11-07 01:23:17 +01:00
static void Usr_PutIconsListGsts (void);
2016-11-07 00:46:13 +01:00
static void Usr_PutIconsListStds (void);
2016-11-07 01:01:21 +01:00
static void Usr_PutIconsListTchs (void);
2016-11-07 00:46:13 +01:00
2016-03-18 21:28:45 +01:00
static void Usr_PutIconToPrintGsts (void);
static void Usr_PutIconToPrintStds (void);
static void Usr_PutIconToPrintTchs (void);
static void Usr_PutIconToShowGstsAllData (void);
2016-11-27 14:10:31 +01:00
static void Usr_PutLinkToShowGstsAllData (void);
2016-03-18 21:28:45 +01:00
static void Usr_PutIconToShowStdsAllData (void);
2016-11-27 14:10:31 +01:00
static void Usr_PutLinkToShowStdsAllData (void);
2016-03-18 21:28:45 +01:00
static void Usr_PutIconToShowTchsAllData (void);
2016-11-27 14:10:31 +01:00
static void Usr_PutLinkToShowTchsAllData (void);
2016-03-18 21:28:45 +01:00
static void Usr_ShowGstsAllDataParams (void);
static void Usr_ShowStdsAllDataParams (void);
static void Usr_ShowTchsAllDataParams (void);
2015-04-02 18:39:49 +02:00
2014-12-01 23:55:08 +01:00
static void Usr_DrawClassPhoto (Usr_ClassPhotoType_t ClassPhotoType,
Rol_Role_t RoleInClassPhoto);
2014-12-12 18:50:36 +01:00
static unsigned Usr_GetNumUsrsNotBelongingToAnyCrs (void);
static float Usr_GetNumCrssPerUsr (Rol_Role_t Role);
static float Usr_GetNumUsrsPerCrs (Rol_Role_t Role);
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/**** Show alert about number of clicks remaining before sending my photo ****/
/*****************************************************************************/
void Usr_InformAboutNumClicksBeforePhoto (void)
{
2016-04-23 23:39:07 +02:00
extern struct Act_Actions Act_Actions[Act_NUM_ACTIONS];
2014-12-01 23:55:08 +01:00
extern const char *Txt_You_must_send_your_photo_because_;
extern const char *Txt_You_can_only_perform_X_further_actions_;
2017-05-10 10:25:01 +02:00
char Message[512]; // Don't use Gbl.Alert.Txt here, because it may be filled with another message and such message would be overwritten
2014-12-01 23:55:08 +01:00
if (Gbl.Usrs.Me.NumAccWithoutPhoto)
{
2014-12-12 22:39:55 +01:00
if (Gbl.Usrs.Me.NumAccWithoutPhoto >= Pho_MAX_CLICKS_WITHOUT_PHOTO)
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_send_your_photo_because_);
2016-10-21 00:38:34 +02:00
else if (Act_Actions[Gbl.Action.Act].BrowserWindow == Act_THIS_WINDOW)
2014-12-01 23:55:08 +01:00
{
sprintf (Message,Txt_You_can_only_perform_X_further_actions_,
2014-12-12 22:39:55 +01:00
Pho_MAX_CLICKS_WITHOUT_PHOTO-Gbl.Usrs.Me.NumAccWithoutPhoto);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Message);
2014-12-01 23:55:08 +01:00
2015-09-02 23:51:44 +02:00
fprintf (Gbl.F.Out,"<div class=\"CENTER_MIDDLE\">");
2015-04-02 18:39:49 +02:00
Pho_PutLinkToChangeMyPhoto ();
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</div>");
}
}
}
/*****************************************************************************/
/************************** Create data for a user ***************************/
/*****************************************************************************/
void Usr_UsrDataConstructor (struct UsrData *UsrDat)
{
/***** Allocate memory for the comments *****/
2017-01-17 03:10:43 +01:00
if ((UsrDat->Comments = malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Not enough memory to store user's data.");
/***** Initialize to zero the data of the user *****/
Usr_ResetUsrDataExceptUsrCodAndIDs (UsrDat);
UsrDat->IDs.Num = 0;
UsrDat->IDs.List = NULL;
}
/*****************************************************************************/
/****************** Reset user's data except UsrCod and ID *******************/
/*****************************************************************************/
// UsrCod and ID are not changed
void Usr_ResetUsrDataExceptUsrCodAndIDs (struct UsrData *UsrDat)
{
UsrDat->EncryptedUsrCod[0] = '\0';
UsrDat->Nickname[0] = '\0';
UsrDat->Password[0] = '\0';
2015-04-07 21:44:24 +02:00
UsrDat->RoleInCurrentCrsDB = Rol_UNKNOWN;
2016-12-13 13:32:19 +01:00
UsrDat->Roles = -1; // < 0 ==> not yet got from database
2014-12-01 23:55:08 +01:00
UsrDat->Accepted = true;
UsrDat->Sex = Usr_SEX_UNKNOWN;
2016-01-18 10:21:18 +01:00
UsrDat->Surname1[0] = '\0';
UsrDat->Surname2[0] = '\0';
2014-12-01 23:55:08 +01:00
UsrDat->FirstName[0] = '\0';
2016-01-18 10:21:18 +01:00
UsrDat->FullName[0] = '\0';
2014-12-01 23:55:08 +01:00
UsrDat->Email[0] = '\0';
UsrDat->EmailConfirmed = false;
UsrDat->Photo[0] = '\0';
2016-01-17 15:10:54 +01:00
UsrDat->PhotoVisibility = Pri_PHOTO_VISIBILITY_DEFAULT;
UsrDat->ProfileVisibility = Pri_PROFILE_VISIBILITY_DEFAULT;
2014-12-01 23:55:08 +01:00
UsrDat->CtyCod = -1L;
UsrDat->OriginPlace[0] = '\0';
UsrDat->StrBirthday[0] = '\0';
2016-01-18 10:21:18 +01:00
UsrDat->Birthday.Day = 0;
2014-12-01 23:55:08 +01:00
UsrDat->Birthday.Month = 0;
2016-01-18 10:21:18 +01:00
UsrDat->Birthday.Year = 0;
UsrDat->LocalAddress[0] = '\0';
UsrDat->LocalPhone[0] = '\0';
2014-12-01 23:55:08 +01:00
UsrDat->FamilyAddress[0] = '\0';
2016-01-18 10:21:18 +01:00
UsrDat->FamilyPhone[0] = '\0';
2014-12-01 23:55:08 +01:00
if (UsrDat->Comments)
UsrDat->Comments[0] = '\0';
2016-01-18 10:21:18 +01:00
UsrDat->InsCtyCod = -1L;
UsrDat->InsCod = -1L;
2014-12-01 23:55:08 +01:00
UsrDat->Tch.CtrCod = -1L;
UsrDat->Tch.DptCod = -1L;
2016-01-18 10:21:18 +01:00
UsrDat->Tch.Office[0] = '\0';
2014-12-01 23:55:08 +01:00
UsrDat->Tch.OfficePhone[0] = '\0';
2016-01-18 10:21:18 +01:00
UsrDat->Prefs.Language = Txt_LANGUAGE_UNKNOWN; // Language unknown
2015-11-21 20:23:28 +01:00
UsrDat->Prefs.FirstDayOfWeek = Cal_FIRST_DAY_OF_WEEK_DEFAULT; // Default first day of week
2017-05-04 02:19:23 +02:00
UsrDat->Prefs.DateFormat = Dat_FORMAT_DEFAULT ; // Default date format
2016-01-18 10:21:18 +01:00
UsrDat->Prefs.Theme = The_THEME_DEFAULT;
UsrDat->Prefs.IconSet = Ico_ICON_SET_DEFAULT;
UsrDat->Prefs.Menu = Mnu_MENU_DEFAULT;
UsrDat->Prefs.SideCols = Cfg_DEFAULT_COLUMNS;
2014-12-01 23:55:08 +01:00
UsrDat->Prefs.EmailNtfEvents = 0; // By default, don't notify anything
}
/*****************************************************************************/
/**************************** Reset my last data *****************************/
/*****************************************************************************/
void Usr_ResetMyLastData (void)
{
2017-01-29 12:42:19 +01:00
Gbl.Usrs.Me.UsrLast.WhatToSearch = Sch_WHAT_TO_SEARCH_DEFAULT;
2014-12-01 23:55:08 +01:00
Gbl.Usrs.Me.UsrLast.LastCrs = -1L;
Gbl.Usrs.Me.UsrLast.LastTab = TabUnk;
Gbl.Usrs.Me.UsrLast.LastAccNotif = 0;
}
/*****************************************************************************/
/**************** Free memory used to store the data of a user ***************/
/*****************************************************************************/
void Usr_UsrDataDestructor (struct UsrData *UsrDat)
{
/***** Free memory allocated for comments *****/
if (UsrDat->Comments)
{
free ((void *) UsrDat->Comments);
UsrDat->Comments = NULL;
}
/***** Free memory allocated for list of IDs *****/
ID_FreeListIDs (UsrDat);
}
/*****************************************************************************/
/************* Get all the user's data from a given user's code **************/
/*****************************************************************************/
// Input: UsrDat->UsrCod must hold user's code
void Usr_GetAllUsrDataFromUsrCod (struct UsrData *UsrDat)
{
ID_GetListIDsFromUsrCod (UsrDat);
Usr_GetUsrDataFromUsrCod (UsrDat);
}
/*****************************************************************************/
/**************** Allocate memory for the list of users' codes ***************/
/*****************************************************************************/
void Usr_AllocateListUsrCods (struct ListUsrCods *ListUsrCods)
{
if ((ListUsrCods->Lst = (long *) malloc (ListUsrCods->NumUsrs * sizeof (long))) == NULL)
Lay_ShowErrorAndExit ("Not enough memory to store list of users' codes.");
}
/*****************************************************************************/
/****************** Free memory for the list of users' codes *****************/
/*****************************************************************************/
void Usr_FreeListUsrCods (struct ListUsrCods *ListUsrCods)
{
if (ListUsrCods->NumUsrs && ListUsrCods->Lst)
{
free ((void *) ListUsrCods->Lst);
ListUsrCods->Lst = NULL;
ListUsrCods->NumUsrs = 0;
}
}
/*****************************************************************************/
2016-01-20 21:18:38 +01:00
/******** Get user's code from database using encrypted user's code **********/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
// Input: UsrDat->EncryptedUsrCod must hold user's encrypted code
void Usr_GetUsrCodFromEncryptedUsrCod (struct UsrData *UsrDat)
{
2017-03-13 20:32:03 +01:00
char Query[128 + Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64];
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
if (UsrDat->EncryptedUsrCod[0])
{
/***** Get user's code from database *****/
2017-03-13 20:32:03 +01:00
sprintf (Query,"SELECT UsrCod FROM usr_data WHERE EncryptedUsrCod='%s'",
2014-12-01 23:55:08 +01:00
UsrDat->EncryptedUsrCod);
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get user's code");
if (NumRows != 1)
Lay_ShowErrorAndExit ("Error when getting user's code.");
2016-01-20 21:18:38 +01:00
/***** Get user's code *****/
2014-12-01 23:55:08 +01:00
row = mysql_fetch_row (mysql_res);
UsrDat->UsrCod = Str_ConvertStrCodToLongCod (row[0]);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
else
UsrDat->UsrCod = -1L;
}
2016-01-20 21:18:38 +01:00
/*****************************************************************************/
/********* Get encrypted user's code from database using user's code *********/
/*****************************************************************************/
// Input: UsrDat->UsrCod must hold user's code
2016-12-04 03:50:25 +01:00
void Usr_GetEncryptedUsrCodFromUsrCod (struct UsrData *UsrDat) // TODO: Remove this funcion, it's not used
2016-01-20 21:18:38 +01:00
{
2017-03-13 20:32:03 +01:00
char Query[128];
2016-01-20 21:18:38 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
if (UsrDat->UsrCod > 0)
{
/***** Get encrypted user's code from database *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"SELECT EncryptedUsrCod FROM usr_data WHERE UsrCod=%ld",
2016-01-20 21:18:38 +01:00
UsrDat->UsrCod);
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get encrypted user's code");
if (NumRows != 1)
Lay_ShowErrorAndExit ("Error when getting encrypted user's code.");
/***** Get encrypted user's code *****/
row = mysql_fetch_row (mysql_res);
2017-01-15 18:02:52 +01:00
Str_Copy (UsrDat->EncryptedUsrCod,row[0],
2017-03-07 01:56:41 +01:00
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
2016-01-20 21:18:38 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
else
UsrDat->EncryptedUsrCod[0] = '\0';
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************ Get user's data from database giving a user's code *************/
/*****************************************************************************/
// UsrDat->UsrCod must contain an existing user's code
void Usr_GetUsrDataFromUsrCod (struct UsrData *UsrDat)
{
2017-01-28 15:58:46 +01:00
extern const char *Txt_STR_LANG_ID[1 + Txt_NUM_LANGUAGES];
2014-12-01 23:55:08 +01:00
extern const char *The_ThemeId[The_NUM_THEMES];
extern const char *Ico_IconSetId[Ico_NUM_ICON_SETS];
char Query[1024];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
The_Theme_t Theme;
Ico_IconSet_t IconSet;
Txt_Language_t Lan;
/***** Get user's data from database *****/
sprintf (Query,"SELECT EncryptedUsrCod,Password,Surname1,Surname2,FirstName,Sex,"
2017-05-04 11:03:44 +02:00
"Theme,IconSet,Language,FirstDayOfWeek,DateFormat,"
"Photo,PhotoVisibility,ProfileVisibility,"
2014-12-01 23:55:08 +01:00
"CtyCod,InsCtyCod,InsCod,DptCod,CtrCod,Office,OfficePhone,"
2017-01-15 22:58:26 +01:00
"LocalAddress,LocalPhone,FamilyAddress,FamilyPhone,OriginPlace,"
"DATE_FORMAT(Birthday,'%%Y%%m%%d'),Comments,"
2015-01-02 01:19:27 +01:00
"Menu,SideCols,NotifNtfEvents,EmailNtfEvents"
2017-03-24 01:09:27 +01:00
" FROM usr_data WHERE UsrCod=%ld",
2014-12-01 23:55:08 +01:00
UsrDat->UsrCod);
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get user's data");
/***** Check number of rows in result *****/
if (NumRows != 1)
Lay_ShowErrorAndExit ("Error when getting user's data.");
/***** Read user's data *****/
row = mysql_fetch_row (mysql_res);
2016-01-20 21:18:38 +01:00
/* Get encrypted user's code */
2017-01-15 18:02:52 +01:00
Str_Copy (UsrDat->EncryptedUsrCod,row[0],
2017-03-07 01:56:41 +01:00
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
2014-12-01 23:55:08 +01:00
/* Get encrypted password */
2017-01-17 03:10:43 +01:00
Str_Copy (UsrDat->Password,row[1],
2017-03-13 14:22:36 +01:00
Pwd_BYTES_ENCRYPTED_PASSWORD);
2014-12-01 23:55:08 +01:00
/* Get roles */
2014-12-12 20:25:00 +01:00
UsrDat->RoleInCurrentCrsDB = Rol_GetRoleInCrs (Gbl.CurrentCrs.Crs.CrsCod,UsrDat->UsrCod);
2016-12-13 13:32:19 +01:00
UsrDat->Roles = -1; // Force roles to be got from database
Rol_GetRolesInAllCrssIfNotYetGot (UsrDat);
2015-04-07 21:44:24 +02:00
if (UsrDat->RoleInCurrentCrsDB == Rol_UNKNOWN)
UsrDat->RoleInCurrentCrsDB = (UsrDat->Roles < (1 << Rol_STUDENT)) ?
Rol__GUEST_ : // User does not belong to any course
2015-09-17 11:21:49 +02:00
Rol_VISITOR; // User belongs to some courses
2014-12-01 23:55:08 +01:00
/* Get name */
2017-01-17 03:10:43 +01:00
Str_Copy (UsrDat->Surname1,row[2],
2017-03-07 19:55:29 +01:00
Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
2017-01-17 03:10:43 +01:00
Str_Copy (UsrDat->Surname2,row[3],
2017-03-07 19:55:29 +01:00
Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
2017-01-17 03:10:43 +01:00
Str_Copy (UsrDat->FirstName,row[4],
2017-03-07 19:55:29 +01:00
Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
2014-12-01 23:55:08 +01:00
/* Get sex */
UsrDat->Sex = Usr_GetSexFromStr (row[5]);
/* Get theme */
UsrDat->Prefs.Theme = The_THEME_DEFAULT;
for (Theme = (The_Theme_t) 0;
Theme < The_NUM_THEMES;
Theme++)
2015-11-27 12:57:56 +01:00
if (!strcasecmp (row[6],The_ThemeId[Theme]))
2014-12-01 23:55:08 +01:00
{
UsrDat->Prefs.Theme = Theme;
break;
}
/* Get icon set */
UsrDat->Prefs.IconSet = Ico_ICON_SET_DEFAULT;
for (IconSet = (Ico_IconSet_t) 0;
IconSet < Ico_NUM_ICON_SETS;
IconSet++)
2015-11-27 12:57:56 +01:00
if (!strcasecmp (row[7],Ico_IconSetId[IconSet]))
2014-12-01 23:55:08 +01:00
{
UsrDat->Prefs.IconSet = IconSet;
break;
}
/* Get language */
2015-12-07 23:13:08 +01:00
UsrDat->Prefs.Language = Txt_LANGUAGE_UNKNOWN; // Language unknown
for (Lan = (Txt_Language_t) 1;
Lan <= Txt_NUM_LANGUAGES;
2014-12-01 23:55:08 +01:00
Lan++)
2015-11-27 12:57:56 +01:00
if (!strcasecmp (row[8],Txt_STR_LANG_ID[Lan]))
2014-12-01 23:55:08 +01:00
{
UsrDat->Prefs.Language = Lan;
break;
}
2015-11-21 20:23:28 +01:00
/* Get first day of week */
2017-05-04 11:03:44 +02:00
UsrDat->Prefs.FirstDayOfWeek = Cal_GetFirstDayOfWeekFromStr (row[9]);
/* Get date format */
UsrDat->Prefs.DateFormat = Dat_GetDateFormatFromStr (row[10]);
2015-11-21 20:23:28 +01:00
2014-12-01 23:55:08 +01:00
/* Get rest of data */
2017-05-04 11:03:44 +02:00
Str_Copy (UsrDat->Photo,row[11],
2017-03-07 01:56:41 +01:00
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
2017-05-04 11:03:44 +02:00
UsrDat->PhotoVisibility = Pri_GetVisibilityFromStr (row[12]);
UsrDat->ProfileVisibility = Pri_GetVisibilityFromStr (row[13]);
UsrDat->CtyCod = Str_ConvertStrCodToLongCod (row[14]);
UsrDat->InsCtyCod = Str_ConvertStrCodToLongCod (row[15]);
UsrDat->InsCod = Str_ConvertStrCodToLongCod (row[16]);
UsrDat->Tch.DptCod = Str_ConvertStrCodToLongCod (row[17]);
UsrDat->Tch.CtrCod = Str_ConvertStrCodToLongCod (row[18]);
Str_Copy (UsrDat->Tch.Office,row[19],
2017-03-08 14:12:33 +01:00
Usr_MAX_BYTES_ADDRESS);
2017-05-04 11:03:44 +02:00
Str_Copy (UsrDat->Tch.OfficePhone,row[20],
2017-01-17 03:10:43 +01:00
Usr_MAX_BYTES_PHONE);
2017-05-04 11:03:44 +02:00
Str_Copy (UsrDat->LocalAddress,row[21],
2017-03-08 14:12:33 +01:00
Usr_MAX_BYTES_ADDRESS);
2017-05-04 11:03:44 +02:00
Str_Copy (UsrDat->LocalPhone,row[22],
2017-01-17 03:10:43 +01:00
Usr_MAX_BYTES_PHONE);
2017-05-04 11:03:44 +02:00
Str_Copy (UsrDat->FamilyAddress,row[23],
2017-03-08 14:12:33 +01:00
Usr_MAX_BYTES_ADDRESS);
2017-05-04 11:03:44 +02:00
Str_Copy (UsrDat->FamilyPhone,row[24],
2017-01-17 03:10:43 +01:00
Usr_MAX_BYTES_PHONE);
2017-05-04 11:03:44 +02:00
Str_Copy (UsrDat->OriginPlace,row[25],
2017-03-08 14:12:33 +01:00
Usr_MAX_BYTES_ADDRESS);
2017-01-15 22:58:26 +01:00
2017-05-04 11:03:44 +02:00
Dat_GetDateFromYYYYMMDD (&(UsrDat->Birthday),row[26]);
2016-05-01 01:52:35 +02:00
2017-05-04 11:03:44 +02:00
Usr_GetUsrCommentsFromString (row[27] ? row[27] :
2014-12-01 23:55:08 +01:00
"",
UsrDat); // Get the comments comunes a todas the courses
2015-01-02 01:19:27 +01:00
/* Get menu */
2017-05-04 11:03:44 +02:00
UsrDat->Prefs.Menu = Mnu_GetMenuFromStr (row[28]);
2015-01-02 01:19:27 +01:00
2014-12-01 23:55:08 +01:00
/* Get if user wants to show side columns */
2017-05-04 11:03:44 +02:00
if (sscanf (row[29],"%u",&UsrDat->Prefs.SideCols) == 1)
2014-12-01 23:55:08 +01:00
{
2014-12-27 13:09:29 +01:00
if (UsrDat->Prefs.SideCols > Lay_SHOW_BOTH_COLUMNS)
2014-12-27 13:49:17 +01:00
UsrDat->Prefs.SideCols = Cfg_DEFAULT_COLUMNS;
2014-12-01 23:55:08 +01:00
}
else
2014-12-27 13:09:29 +01:00
UsrDat->Prefs.SideCols = Cfg_DEFAULT_COLUMNS;
2014-12-01 23:55:08 +01:00
2015-03-24 00:01:40 +01:00
/* Get on which events I want to be notified inside the platform */
2017-05-04 11:03:44 +02:00
if (sscanf (row[30],"%u",&UsrDat->Prefs.NotifNtfEvents) != 1)
2014-12-01 23:55:08 +01:00
UsrDat->Prefs.NotifNtfEvents = (unsigned) -1; // 0xFF..FF
2016-11-16 23:19:52 +01:00
/* Get on which events I want to be notified by email */
2017-05-04 11:03:44 +02:00
if (sscanf (row[31],"%u",&UsrDat->Prefs.EmailNtfEvents) != 1)
2014-12-01 23:55:08 +01:00
UsrDat->Prefs.EmailNtfEvents = 0;
if (UsrDat->Prefs.EmailNtfEvents >= (1 << Ntf_NUM_NOTIFY_EVENTS)) // Maximum binary value for NotifyEvents is 000...0011...11
UsrDat->Prefs.EmailNtfEvents = 0;
Str_ConvertToTitleType (UsrDat->Surname1 );
Str_ConvertToTitleType (UsrDat->Surname2 );
Str_ConvertToTitleType (UsrDat->FirstName);
/* Create full name using FirstName, Surname1 and Surname2 */
Usr_BuildFullName (UsrDat);
Dat_ConvDateToDateStr (&(UsrDat->Birthday),UsrDat->StrBirthday);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2016-11-16 23:19:52 +01:00
/***** Get nickname and email *****/
2014-12-01 23:55:08 +01:00
Nck_GetNicknameFromUsrCod (UsrDat->UsrCod,UsrDat->Nickname);
2015-11-16 14:54:12 +01:00
Mai_GetEmailFromUsrCod (UsrDat);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********* Get the comments in the record of a user from a string ************/
/*****************************************************************************/
static void Usr_GetUsrCommentsFromString (char *Str,struct UsrData *UsrDat)
{
/***** Check that memory for comments is allocated *****/
if (UsrDat->Comments)
/***** Copy comments from Str to Comments *****/
2017-01-17 03:10:43 +01:00
Str_Copy (UsrDat->Comments,Str,
Cns_MAX_BYTES_TEXT);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********** Get user's last data from database giving a user's code **********/
/*****************************************************************************/
static void Usr_GetMyLastData (void)
{
char Query[256];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned UnsignedNum;
/***** Get user's data from database *****/
sprintf (Query,"SELECT WhatToSearch,LastCrs,LastTab,UNIX_TIMESTAMP(LastAccNotif)"
2017-03-24 01:09:27 +01:00
" FROM usr_last WHERE UsrCod=%ld",
2014-12-01 23:55:08 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod);
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get user's last data");
/***** Check number of rows in result *****/
if (NumRows == 0)
{
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** Create entry for me in table of user's last data *****/
Usr_ResetMyLastData ();
Usr_InsertMyLastData ();
}
else if (NumRows == 1)
{
row = mysql_fetch_row (mysql_res);
/* Get last type of search */
2017-01-29 12:42:19 +01:00
Gbl.Usrs.Me.UsrLast.WhatToSearch = Sch_SEARCH_UNKNOWN;
2014-12-01 23:55:08 +01:00
if (sscanf (row[0],"%u",&UnsignedNum) == 1)
if (UnsignedNum < Sch_NUM_WHAT_TO_SEARCH)
Gbl.Usrs.Me.UsrLast.WhatToSearch = (Sch_WhatToSearch_t) UnsignedNum;
2017-01-29 12:42:19 +01:00
if (Gbl.Usrs.Me.UsrLast.WhatToSearch == Sch_SEARCH_UNKNOWN)
Gbl.Usrs.Me.UsrLast.WhatToSearch = Sch_WHAT_TO_SEARCH_DEFAULT;
2014-12-01 23:55:08 +01:00
/* Get last course */
Gbl.Usrs.Me.UsrLast.LastCrs = Str_ConvertStrCodToLongCod (row[1]);
/* Get last tab */
Gbl.Usrs.Me.UsrLast.LastTab = TabPrf; // By default, set last tab to the profile tab
if (sscanf (row[2],"%u",&UnsignedNum) == 1)
2015-12-28 12:55:08 +01:00
if (UnsignedNum >= 1 ||
UnsignedNum <= Tab_NUM_TABS)
2016-10-12 14:02:56 +02:00
Gbl.Usrs.Me.UsrLast.LastTab = (Tab_Tab_t) UnsignedNum;
2014-12-01 23:55:08 +01:00
/* Get last access to notifications */
Gbl.Usrs.Me.UsrLast.LastAccNotif = 0L;
if (row[3])
sscanf (row[3],"%ld",&(Gbl.Usrs.Me.UsrLast.LastAccNotif));
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
else
Lay_ShowErrorAndExit ("Error when getting user's last data.");
}
/*****************************************************************************/
/****************************** Get sex from string **************************/
/*****************************************************************************/
static Usr_Sex_t Usr_GetSexFromStr (const char *Str)
{
Usr_Sex_t Sex;
for (Sex = (Usr_Sex_t) 0;
Sex < Usr_NUM_SEXS;
Sex++)
if (!strcasecmp (Str,Usr_StringsSexDB[Sex]))
return Sex;
return Usr_SEX_UNKNOWN;
}
/*****************************************************************************/
/********** Build full name using FirstName, Surname1 and Surname2 ***********/
/*****************************************************************************/
void Usr_BuildFullName (struct UsrData *UsrDat)
{
2017-01-17 03:10:43 +01:00
Str_Copy (UsrDat->FullName,UsrDat->FirstName,
Usr_MAX_BYTES_FULL_NAME);
2014-12-01 23:55:08 +01:00
if (UsrDat->Surname1[0])
{
2017-01-17 03:33:05 +01:00
Str_Concat (UsrDat->FullName," ",
Usr_MAX_BYTES_FULL_NAME);
Str_Concat (UsrDat->FullName,UsrDat->Surname1,
Usr_MAX_BYTES_FULL_NAME);
2014-12-01 23:55:08 +01:00
}
if (UsrDat->Surname2[0])
{
2017-01-17 03:33:05 +01:00
Str_Concat (UsrDat->FullName," ",
Usr_MAX_BYTES_FULL_NAME);
Str_Concat (UsrDat->FullName,UsrDat->Surname2,
Usr_MAX_BYTES_FULL_NAME);
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
2017-03-05 15:12:48 +01:00
/********* Write user name in two lines. 1: first name, 2: surnames **********/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2017-03-05 15:12:48 +01:00
void Usr_WriteFirstNameBRSurnames (const struct UsrData *UsrDat)
2014-12-01 23:55:08 +01:00
{
2017-03-05 15:12:48 +01:00
/***** Write first name and surname 1 *****/
fprintf (Gbl.F.Out,"%s<br />%s",UsrDat->FirstName,UsrDat->Surname1);
2014-12-01 23:55:08 +01:00
2017-03-05 15:12:48 +01:00
/***** Write surname2 if exists *****/
2014-12-01 23:55:08 +01:00
if (UsrDat->Surname2[0])
2017-03-05 15:12:48 +01:00
fprintf (Gbl.F.Out," %s",UsrDat->Surname2);
2014-12-01 23:55:08 +01:00
}
2015-01-31 01:23:39 +01:00
/*****************************************************************************/
2016-10-19 01:46:40 +02:00
/***** Check if a user is an administrator of a degree/centre/institution ****/
2015-01-31 01:23:39 +01:00
/*****************************************************************************/
2015-02-01 16:08:58 +01:00
bool Usr_CheckIfUsrIsAdm (long UsrCod,Sco_Scope_t Scope,long Cod)
2015-01-31 01:23:39 +01:00
{
2016-10-27 15:06:11 +02:00
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
2017-03-13 20:32:03 +01:00
char Query[256];
2014-12-01 23:55:08 +01:00
2016-10-27 15:06:11 +02:00
if (Sco_ScopeDB[Scope])
2015-02-01 16:08:58 +01:00
{
/***** Get if a user is administrator of a degree from database *****/
sprintf (Query,"SELECT COUNT(*) FROM admin"
2017-03-24 01:09:27 +01:00
" WHERE UsrCod=%ld AND Scope='%s' AND Cod=%ld",
2016-10-27 15:06:11 +02:00
UsrCod,Sco_ScopeDB[Scope],Cod);
2015-02-01 16:08:58 +01:00
return (DB_QueryCOUNT (Query,"can not check if a user is administrator") != 0);
}
2015-02-01 20:17:24 +01:00
return false;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Check if a user is a superuser ************************/
/*****************************************************************************/
bool Usr_CheckIfUsrIsSuperuser (long UsrCod)
{
2016-10-27 22:16:03 +02:00
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
2017-03-13 20:32:03 +01:00
char Query[256];
2017-01-27 01:02:52 +01:00
static struct
{
long UsrCod;
bool IsSuperuser;
2017-03-01 15:23:30 +01:00
} Cached =
2017-01-27 01:02:52 +01:00
{
-1L,
false
};
2014-12-01 23:55:08 +01:00
2017-01-27 01:02:52 +01:00
if (UsrCod <= 0)
{
/***** Trivial case *****/
2017-03-01 15:23:30 +01:00
Cached.UsrCod = -1L;
Cached.IsSuperuser = false;
2017-01-27 01:02:52 +01:00
}
2017-03-01 15:23:30 +01:00
else if (UsrCod != Cached.UsrCod) // If not cached...
2017-01-27 01:02:52 +01:00
{
/***** Get if a user is superuser from database *****/
sprintf (Query,"SELECT COUNT(*) FROM admin"
2017-03-24 01:09:27 +01:00
" WHERE UsrCod=%ld AND Scope='%s'",
2017-01-27 01:02:52 +01:00
UsrCod,Sco_ScopeDB[Sco_SCOPE_SYS]);
2017-03-01 15:23:30 +01:00
Cached.UsrCod = UsrCod;
Cached.IsSuperuser = (DB_QueryCOUNT (Query,"can not check if a user is superuser") != 0);
2017-01-27 01:02:52 +01:00
}
2017-03-01 15:23:30 +01:00
return Cached.IsSuperuser;
2017-01-27 01:02:52 +01:00
}
2017-01-27 10:42:20 +01:00
/*****************************************************************************/
/**************** Check if I can change another user's data ******************/
/*****************************************************************************/
bool Usr_ICanChangeOtherUsrData (const struct UsrData *UsrDat)
{
if (UsrDat->UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) // It's me
return true;
/***** Check if I have permission to see another user's IDs *****/
switch (Gbl.Usrs.Me.LoggedRole)
{
case Rol_TEACHER:
2017-01-27 15:21:01 +01:00
/* Check 1: I can change data of users who do not exist in database */
if (UsrDat->UsrCod <= 0) // User does not exist (when creating a new user)
return true;
2017-01-27 18:45:38 +01:00
/* Check 2: I change data of users without password */
if (!UsrDat->Password[0]) // User has no password (never logged)
2017-01-27 15:21:01 +01:00
return true;
return false;
2017-01-27 10:42:20 +01:00
case Rol_DEG_ADM:
case Rol_CTR_ADM:
case Rol_INS_ADM:
case Rol_SYS_ADM:
2017-01-28 18:08:06 +01:00
return Usr_ICanEditOtherUsr (UsrDat);
2017-01-27 10:42:20 +01:00
default:
return false;
}
}
2017-01-27 01:02:52 +01:00
/*****************************************************************************/
2017-01-28 18:08:06 +01:00
/***************** Check if I can edit another user's data *******************/
2017-01-27 01:02:52 +01:00
/*****************************************************************************/
2017-01-28 18:08:06 +01:00
bool Usr_ICanEditOtherUsr (const struct UsrData *UsrDat)
2017-01-27 01:02:52 +01:00
{
2017-01-28 18:08:06 +01:00
if (UsrDat->UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) // It's me
return true;
2017-01-27 01:02:52 +01:00
switch (Gbl.Usrs.Me.LoggedRole)
{
case Rol_DEG_ADM:
/* If I am an administrator of current degree,
I only can edit users from current degree who have accepted */
if (Usr_CheckIfUsrBelongsToDeg (UsrDat->UsrCod,Gbl.CurrentDeg.Deg.DegCod))
// Degree admins can't edit superusers' data
if (!Usr_CheckIfUsrIsSuperuser (UsrDat->UsrCod))
return true;
return false;
case Rol_CTR_ADM:
/* If I am an administrator of current centre,
I only can edit from current centre who have accepted */
if (Usr_CheckIfUsrBelongsToCtr (UsrDat->UsrCod,Gbl.CurrentCtr.Ctr.CtrCod))
// Centre admins can't edit superusers' data
if (!Usr_CheckIfUsrIsSuperuser (UsrDat->UsrCod))
return true;
return false;
case Rol_INS_ADM:
/* If I am an administrator of current institution,
I only can edit from current institution who have accepted */
if (Usr_CheckIfUsrBelongsToIns (UsrDat->UsrCod,Gbl.CurrentIns.Ins.InsCod))
// Institution admins can't edit superusers' data
if (!Usr_CheckIfUsrIsSuperuser (UsrDat->UsrCod))
return true;
return false;
case Rol_SYS_ADM:
return true;
default:
return false;
}
2014-12-01 23:55:08 +01:00
}
2016-06-16 18:05:23 +02:00
/*****************************************************************************/
/********************* Get number of courses of a user ***********************/
/*****************************************************************************/
unsigned Usr_GetNumCrssOfUsr (long UsrCod)
{
char Query[128];
/***** Get the number of courses of a user from database ******/
2017-03-24 01:09:27 +01:00
sprintf (Query,"SELECT COUNT(*) FROM crs_usr WHERE UsrCod=%ld",
2016-06-16 18:05:23 +02:00
UsrCod);
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of courses of a user");
}
/*****************************************************************************/
/*************** Get number of courses of a user not accepted ****************/
/*****************************************************************************/
unsigned Usr_GetNumCrssOfUsrNotAccepted (long UsrCod)
{
char Query[256];
/***** Get the number of courses of a user not accepted from database ******/
sprintf (Query,"SELECT COUNT(*) FROM crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE UsrCod=%ld AND Accepted='N'",
2016-06-16 18:05:23 +02:00
UsrCod);
2016-06-20 09:43:27 +02:00
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of courses of a user");
2016-06-16 18:05:23 +02:00
}
2015-03-09 19:22:25 +01:00
/*****************************************************************************/
/********* Get number of courses in with a user have a given role ************/
/*****************************************************************************/
2015-03-14 17:39:04 +01:00
unsigned Usr_GetNumCrssOfUsrWithARole (long UsrCod,Rol_Role_t Role)
2015-03-09 19:22:25 +01:00
{
2017-03-13 20:32:03 +01:00
char Query[256];
2015-03-09 19:22:25 +01:00
2016-06-16 18:05:23 +02:00
/***** Get the number of courses of a user with a role from database ******/
2015-03-09 19:22:25 +01:00
sprintf (Query,"SELECT COUNT(*) FROM crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE UsrCod=%ld AND Role=%u",
2015-03-09 19:22:25 +01:00
UsrCod,(unsigned) Role);
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of courses of a user with a role");
}
2016-06-20 09:43:27 +02:00
/*****************************************************************************/
/********* Get number of courses in with a user have a given role ************/
/*****************************************************************************/
unsigned Usr_GetNumCrssOfUsrWithARoleNotAccepted (long UsrCod,Rol_Role_t Role)
{
2017-03-13 20:32:03 +01:00
char Query[256];
2016-06-20 09:43:27 +02:00
/***** Get the number of courses of a user with a role from database ******/
sprintf (Query,"SELECT COUNT(*) FROM crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE UsrCod=%ld AND Role=%u AND Accepted='N'",
2016-06-20 09:43:27 +02:00
UsrCod,(unsigned) Role);
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of courses of a user with a role");
}
2015-03-09 19:22:25 +01:00
/*****************************************************************************/
2015-03-12 14:45:40 +01:00
/******* Get number of users with different role in courses of a user ********/
2015-03-09 19:22:25 +01:00
/*****************************************************************************/
2015-03-19 19:10:43 +01:00
unsigned Usr_GetNumUsrsInCrssOfAUsr (long UsrCod,Rol_Role_t UsrRole,
Rol_Role_t OthersRole)
2015-03-09 19:22:25 +01:00
{
2017-03-13 20:32:03 +01:00
char Query[512];
2015-04-11 23:46:21 +02:00
unsigned NumUsrs;
2015-03-19 19:10:43 +01:00
// This query can be made in a unique, but slower, query
// The temporary table achieves speedup from ~2s to few ms
/***** Remove temporary table if exists *****/
2016-09-22 01:28:31 +02:00
sprintf (Query,"DROP TEMPORARY TABLE IF EXISTS usr_courses_tmp");
2015-03-19 19:10:43 +01:00
if (mysql_query (&Gbl.mysql,Query))
DB_ExitOnMySQLError ("can not remove temporary tables");
2016-09-22 01:52:02 +02:00
/***** Create temporary table with all user's courses for a role *****/
2016-09-22 01:28:31 +02:00
sprintf (Query,"CREATE TEMPORARY TABLE IF NOT EXISTS usr_courses_tmp"
2015-03-19 19:10:43 +01:00
" (CrsCod INT NOT NULL,UNIQUE INDEX (CrsCod))"
" ENGINE=MEMORY"
" SELECT CrsCod FROM crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE UsrCod=%ld AND Role=%u",
2015-03-19 19:10:43 +01:00
UsrCod,(unsigned) UsrRole);
if (mysql_query (&Gbl.mysql,Query))
DB_ExitOnMySQLError ("can not create temporary table");
2015-03-09 19:22:25 +01:00
/***** Get the number of teachers in a course from database ******/
2015-03-19 19:10:43 +01:00
sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
2016-09-22 01:28:31 +02:00
" FROM crs_usr,usr_courses_tmp"
" WHERE crs_usr.CrsCod=usr_courses_tmp.CrsCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u",
2015-03-19 19:10:43 +01:00
(unsigned) OthersRole);
2015-04-11 23:46:21 +02:00
NumUsrs = (unsigned) DB_QueryCOUNT (Query,"can not get the number of users");
2015-03-19 19:10:43 +01:00
/***** Remove temporary table *****/
2016-09-22 01:28:31 +02:00
sprintf (Query,"DROP TEMPORARY TABLE IF EXISTS usr_courses_tmp");
2015-03-19 19:10:43 +01:00
if (mysql_query (&Gbl.mysql,Query))
DB_ExitOnMySQLError ("can not remove temporary tables");
2015-04-11 23:46:21 +02:00
return NumUsrs;
2015-03-09 19:22:25 +01:00
}
2016-12-09 13:59:33 +01:00
/*****************************************************************************/
/************ Check if I can view the record card of a student ***************/
/*****************************************************************************/
bool Usr_CheckIfICanViewRecordStd (const struct UsrData *UsrDat)
{
2017-01-28 15:58:46 +01:00
if (UsrDat->RoleInCurrentCrsDB != Rol_STUDENT) // Not a student in the current course
return false;
2016-12-09 13:59:33 +01:00
2017-01-28 15:58:46 +01:00
// The user is a student in the current course
switch (Gbl.Usrs.Me.LoggedRole)
{
case Rol_STUDENT:
case Rol_TEACHER:
case Rol_SYS_ADM:
return true;
default:
return false;
}
2016-12-09 13:59:33 +01:00
}
/*****************************************************************************/
/************ Check if I can view the record card of a teacher ***************/
/*****************************************************************************/
2016-12-13 13:32:19 +01:00
bool Usr_CheckIfICanViewRecordTch (struct UsrData *UsrDat)
2016-12-09 13:59:33 +01:00
{
2016-12-13 13:32:19 +01:00
/***** 1. Fast check: Am I logged? *****/
if (!Gbl.Usrs.Me.Logged)
2016-12-09 13:59:33 +01:00
return false;
2016-12-13 13:32:19 +01:00
/***** 2. Fast/slow check: Is he/she a teacher in any course? *****/
Rol_GetRolesInAllCrssIfNotYetGot (UsrDat);
if (!(UsrDat->Roles & (1 << Rol_TEACHER)))
2016-12-09 13:59:33 +01:00
return false;
2016-12-13 13:32:19 +01:00
// He/she is a teacher
2016-12-09 13:59:33 +01:00
/***** 3. Fast check: It's me? *****/
if (Gbl.Usrs.Me.UsrDat.UsrCod == UsrDat->UsrCod)
return true;
/***** 4. Fast check: Am I logged as system admin? *****/
if (Gbl.Usrs.Me.LoggedRole == Rol_SYS_ADM)
return true;
/***** 5. Slow check: Get if user shares any course with me from database *****/
return Usr_CheckIfUsrSharesAnyOfMyCrs (UsrDat);
}
/*****************************************************************************/
/******************* Check if I can view a user's agenda *********************/
/*****************************************************************************/
2016-12-13 13:32:19 +01:00
bool Usr_CheckIfICanViewUsrAgenda (struct UsrData *UsrDat)
2016-12-09 13:59:33 +01:00
{
/***** 1. Fast check: Am I logged? *****/
if (!Gbl.Usrs.Me.Logged)
return false;
/***** 2. Fast check: It's me? *****/
if (Gbl.Usrs.Me.UsrDat.UsrCod == UsrDat->UsrCod)
return true;
/***** 3. Fast check: Am I logged as system admin? *****/
if (Gbl.Usrs.Me.LoggedRole == Rol_SYS_ADM)
return true;
/***** 4. Slow check: Get if user shares any course with me from database *****/
return Usr_CheckIfUsrSharesAnyOfMyCrs (UsrDat);
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/*************** Check if a user belongs to any of my courses ****************/
/*****************************************************************************/
2016-12-13 13:32:19 +01:00
bool Usr_CheckIfUsrSharesAnyOfMyCrs (struct UsrData *UsrDat)
2014-12-01 23:55:08 +01:00
{
2016-09-22 01:28:31 +02:00
char Query[256];
2016-12-09 13:59:33 +01:00
bool IBelongToCurrentCrs;
bool HeBelongsToCurrentCrs;
static struct
{
2016-12-09 14:50:21 +01:00
long UsrCod;
2016-12-09 13:59:33 +01:00
bool UsrSharesAnyOfMyCrs;
} Cached =
{
-1L,
false
}; // A cache. If this function is called consecutive times
// with the same user, only the first time is slow
/***** 1. Fast check: Am I logged? *****/
if (!Gbl.Usrs.Me.Logged)
return false;
/***** 2. Fast check: It is a valid user code? *****/
if (UsrDat->UsrCod <= 0)
return false;
/***** 3. Fast check: It's me? *****/
if (Gbl.Usrs.Me.UsrDat.UsrCod == UsrDat->UsrCod)
return true;
2016-12-13 13:32:19 +01:00
/***** 4. Fast check: Is already calculated if user shares any course with me? *****/
if (UsrDat->UsrCod == Cached.UsrCod)
return Cached.UsrSharesAnyOfMyCrs;
2016-12-09 13:59:33 +01:00
/***** 5. Fast check: Is course selected and we both belong to it? *****/
IBelongToCurrentCrs = Gbl.Usrs.Me.UsrDat.RoleInCurrentCrsDB == Rol_STUDENT ||
Gbl.Usrs.Me.UsrDat.RoleInCurrentCrsDB == Rol_TEACHER;
HeBelongsToCurrentCrs = UsrDat->RoleInCurrentCrsDB == Rol_STUDENT ||
UsrDat->RoleInCurrentCrsDB == Rol_TEACHER;
if (IBelongToCurrentCrs && HeBelongsToCurrentCrs) // Course selected and we both belong to it
return true;
2016-12-13 13:32:19 +01:00
/***** 6. Fast/slow check: Does he/she belong to any course? *****/
Rol_GetRolesInAllCrssIfNotYetGot (UsrDat);
if (!(UsrDat->Roles & ((1 << Rol_STUDENT) | // Any of his/her roles is student
(1 << Rol_TEACHER)))) // or teacher?
return false;
2016-12-09 13:59:33 +01:00
2016-12-09 14:17:32 +01:00
/***** 7. Slow check: Get if user shares any course with me from database *****/
2016-12-13 14:54:00 +01:00
/* Fill the list with the courses I belong to (if not already filled) */
Usr_GetMyCourses ();
/* Check if user shares any course with me */
2016-09-22 01:28:31 +02:00
sprintf (Query,"SELECT COUNT(*) FROM crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE UsrCod=%ld"
2016-09-22 01:28:31 +02:00
" AND CrsCod IN (SELECT CrsCod FROM my_courses_tmp)",
2016-12-09 13:59:33 +01:00
UsrDat->UsrCod);
Cached.UsrSharesAnyOfMyCrs = DB_QueryCOUNT (Query,"can not check if a user shares any course with you") != 0;
2016-12-09 14:50:21 +01:00
Cached.UsrCod = UsrDat->UsrCod;
2016-12-09 13:59:33 +01:00
return Cached.UsrSharesAnyOfMyCrs;
2014-12-01 23:55:08 +01:00
}
2015-03-06 14:11:11 +01:00
/*****************************************************************************/
/*** Check if a user belongs to any of my courses but has a different role ***/
/*****************************************************************************/
bool Usr_CheckIfUsrSharesAnyOfMyCrsWithDifferentRole (long UsrCod)
{
char Query[512];
2016-09-22 01:52:02 +02:00
bool UsrSharesAnyOfMyCrsWithDifferentRole;
2016-12-09 13:59:33 +01:00
/***** 1. Fast check: Am I logged? *****/
if (!Gbl.Usrs.Me.Logged)
return false;
2016-12-13 14:54:00 +01:00
/***** 2. Slow check: Get if user shares any course with me
with a different role, from database *****/
/* Fill the list with the courses I belong to (if not already filled) */
Usr_GetMyCourses ();
/* Remove temporary table if exists */
2016-09-22 01:52:02 +02:00
sprintf (Query,"DROP TEMPORARY TABLE IF EXISTS usr_courses_tmp");
if (mysql_query (&Gbl.mysql,Query))
DB_ExitOnMySQLError ("can not remove temporary tables");
2016-12-13 14:54:00 +01:00
/* Create temporary table with all user's courses for a role */
2016-09-22 01:52:02 +02:00
sprintf (Query,"CREATE TEMPORARY TABLE IF NOT EXISTS usr_courses_tmp "
"(CrsCod INT NOT NULL,Role TINYINT NOT NULL,"
2016-09-22 02:02:19 +02:00
"UNIQUE INDEX(CrsCod,Role)) ENGINE=MEMORY"
2017-03-24 01:09:27 +01:00
" SELECT CrsCod,Role FROM crs_usr WHERE UsrCod=%ld",
2016-09-22 01:52:02 +02:00
UsrCod);
if (mysql_query (&Gbl.mysql,Query))
DB_ExitOnMySQLError ("can not create temporary table");
2015-03-06 14:11:11 +01:00
2016-12-13 14:54:00 +01:00
/* Get if a user shares any course with me from database */
2016-09-22 01:52:02 +02:00
sprintf (Query,"SELECT COUNT(*) FROM my_courses_tmp,usr_courses_tmp"
" WHERE my_courses_tmp.CrsCod=usr_courses_tmp.CrsCod"
" AND my_courses_tmp.Role<>usr_courses_tmp.Role");
UsrSharesAnyOfMyCrsWithDifferentRole = (DB_QueryCOUNT (Query,"can not check if a user shares any course with you") != 0);
2016-12-13 14:54:00 +01:00
/* Remove temporary table if exists */
2016-09-22 01:52:02 +02:00
sprintf (Query,"DROP TEMPORARY TABLE IF EXISTS usr_courses_tmp");
if (mysql_query (&Gbl.mysql,Query))
DB_ExitOnMySQLError ("can not remove temporary tables");
return UsrSharesAnyOfMyCrsWithDifferentRole;
2015-03-06 14:11:11 +01:00
}
2016-10-27 01:30:14 +02:00
/*****************************************************************************/
/**** Get all my countries (those of my courses) and store them in a list ****/
/*****************************************************************************/
2016-10-28 10:03:37 +02:00
void Usr_GetMyCountrs (void)
2016-10-27 01:30:14 +02:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCty;
unsigned NumCtys;
long CtyCod;
/***** If my countries are yet filled, there's nothing to do *****/
2016-10-28 10:03:37 +02:00
if (!Gbl.Usrs.Me.MyCtys.Filled)
2016-10-27 01:30:14 +02:00
{
2016-10-28 10:03:37 +02:00
Gbl.Usrs.Me.MyCtys.Num = 0;
2016-10-27 01:30:14 +02:00
/***** Get my institutions from database *****/
if ((NumCtys = (unsigned) Usr_GetCtysFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,&mysql_res)) > 0) // Countries found
for (NumCty = 0;
NumCty < NumCtys;
NumCty++)
{
/* Get next country */
row = mysql_fetch_row (mysql_res);
/* Get country code */
if ((CtyCod = Str_ConvertStrCodToLongCod (row[0])) > 0)
{
2016-10-28 10:03:37 +02:00
if (Gbl.Usrs.Me.MyCtys.Num == Cty_MAX_COUNTRS_PER_USR)
2016-10-27 01:30:14 +02:00
Lay_ShowErrorAndExit ("Maximum number of countries of a user exceeded.");
2016-10-28 10:03:37 +02:00
Gbl.Usrs.Me.MyCtys.Ctys[Gbl.Usrs.Me.MyCtys.Num].CtyCod = CtyCod;
Gbl.Usrs.Me.MyCtys.Ctys[Gbl.Usrs.Me.MyCtys.Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]);
2016-10-27 01:30:14 +02:00
2016-10-28 10:03:37 +02:00
Gbl.Usrs.Me.MyCtys.Num++;
2016-10-27 01:30:14 +02:00
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** Set boolean that indicates that my institutions are yet filled *****/
2016-10-28 10:03:37 +02:00
Gbl.Usrs.Me.MyCtys.Filled = true;
2016-10-27 01:30:14 +02:00
}
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/** Get all my institutions (those of my courses) and store them in a list ***/
/*****************************************************************************/
2016-10-28 10:03:37 +02:00
void Usr_GetMyInstits (void)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumIns;
unsigned NumInss;
long InsCod;
/***** If my institutions are yet filled, there's nothing to do *****/
2016-10-28 10:03:37 +02:00
if (!Gbl.Usrs.Me.MyInss.Filled)
2014-12-01 23:55:08 +01:00
{
2016-10-28 10:03:37 +02:00
Gbl.Usrs.Me.MyInss.Num = 0;
2014-12-01 23:55:08 +01:00
/***** Get my institutions from database *****/
2014-12-29 00:54:56 +01:00
if ((NumInss = (unsigned) Usr_GetInssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,-1L,&mysql_res)) > 0) // Institutions found
2014-12-01 23:55:08 +01:00
for (NumIns = 0;
NumIns < NumInss;
NumIns++)
{
/* Get next institution */
row = mysql_fetch_row (mysql_res);
/* Get institution code */
if ((InsCod = Str_ConvertStrCodToLongCod (row[0])) > 0)
{
2016-10-28 10:03:37 +02:00
if (Gbl.Usrs.Me.MyInss.Num == Ins_MAX_INSTITS_PER_USR)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Maximum number of institutions of a user exceeded.");
2016-10-28 10:03:37 +02:00
Gbl.Usrs.Me.MyInss.Inss[Gbl.Usrs.Me.MyInss.Num].InsCod = InsCod;
Gbl.Usrs.Me.MyInss.Inss[Gbl.Usrs.Me.MyInss.Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]);
2014-12-01 23:55:08 +01:00
2016-10-28 10:03:37 +02:00
Gbl.Usrs.Me.MyInss.Num++;
2014-12-01 23:55:08 +01:00
}
2014-12-29 00:54:56 +01:00
}
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** Set boolean that indicates that my institutions are yet filled *****/
2016-10-28 10:03:37 +02:00
Gbl.Usrs.Me.MyInss.Filled = true;
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/***** Get all my centres (those of my courses) and store them in a list *****/
/*****************************************************************************/
void Usr_GetMyCentres (void)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCtr;
unsigned NumCtrs;
long CtrCod;
/***** If my centres are yet filled, there's nothing to do *****/
2016-10-28 10:03:37 +02:00
if (!Gbl.Usrs.Me.MyCtrs.Filled)
2014-12-01 23:55:08 +01:00
{
2016-10-28 10:03:37 +02:00
Gbl.Usrs.Me.MyCtrs.Num = 0;
2014-12-01 23:55:08 +01:00
/***** Get my centres from database *****/
if ((NumCtrs = (unsigned) Usr_GetCtrsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,-1L,&mysql_res)) > 0) // Centres found
for (NumCtr = 0;
NumCtr < NumCtrs;
NumCtr++)
{
/* Get next centre */
row = mysql_fetch_row (mysql_res);
/* Get centre code */
if ((CtrCod = Str_ConvertStrCodToLongCod (row[0])) > 0)
{
2016-10-28 10:03:37 +02:00
if (Gbl.Usrs.Me.MyCtrs.Num == Ctr_MAX_CENTRES_PER_USR)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Maximum number of centres of a user exceeded.");
2016-10-28 10:03:37 +02:00
Gbl.Usrs.Me.MyCtrs.Ctrs[Gbl.Usrs.Me.MyCtrs.Num].CtrCod = CtrCod;
Gbl.Usrs.Me.MyCtrs.Ctrs[Gbl.Usrs.Me.MyCtrs.Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]);
2014-12-01 23:55:08 +01:00
2016-10-28 10:03:37 +02:00
Gbl.Usrs.Me.MyCtrs.Num++;
2014-12-01 23:55:08 +01:00
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** Set boolean that indicates that my centres are yet filled *****/
2016-10-28 10:03:37 +02:00
Gbl.Usrs.Me.MyCtrs.Filled = true;
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/***** Get all my degrees (those of my courses) and store them in a list *****/
/*****************************************************************************/
void Usr_GetMyDegrees (void)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumDeg;
unsigned NumDegs;
long DegCod;
/***** If my degrees are yet filled, there's nothing to do *****/
2016-10-28 10:03:37 +02:00
if (!Gbl.Usrs.Me.MyDegs.Filled)
2014-12-01 23:55:08 +01:00
{
2016-10-28 10:03:37 +02:00
Gbl.Usrs.Me.MyDegs.Num = 0;
2014-12-01 23:55:08 +01:00
/***** Get my degrees from database *****/
if ((NumDegs = (unsigned) Usr_GetDegsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,-1L,&mysql_res)) > 0) // Degrees found
for (NumDeg = 0;
NumDeg < NumDegs;
NumDeg++)
{
/* Get next degree */
row = mysql_fetch_row (mysql_res);
/* Get degree code */
if ((DegCod = Str_ConvertStrCodToLongCod (row[0])) > 0)
{
2016-10-28 10:03:37 +02:00
if (Gbl.Usrs.Me.MyDegs.Num == Deg_MAX_DEGREES_PER_USR)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Maximum number of degrees of a user exceeded.");
2016-10-28 10:03:37 +02:00
Gbl.Usrs.Me.MyDegs.Degs[Gbl.Usrs.Me.MyDegs.Num].DegCod = DegCod;
Gbl.Usrs.Me.MyDegs.Degs[Gbl.Usrs.Me.MyDegs.Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]);
2014-12-01 23:55:08 +01:00
2016-10-28 10:03:37 +02:00
Gbl.Usrs.Me.MyDegs.Num++;
2014-12-01 23:55:08 +01:00
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** Set boolean that indicates that my degrees are yet filled *****/
2016-10-28 10:03:37 +02:00
Gbl.Usrs.Me.MyDegs.Filled = true;
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/*************** Get all my courses and store them in a list *****************/
/*****************************************************************************/
void Usr_GetMyCourses (void)
{
2017-03-13 20:32:03 +01:00
char Query[1024];
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCrs;
unsigned NumCrss;
long CrsCod;
/***** If my courses are yet filled, there's nothing to do *****/
2016-10-28 10:03:37 +02:00
if (!Gbl.Usrs.Me.MyCrss.Filled)
2014-12-01 23:55:08 +01:00
{
2016-10-28 10:03:37 +02:00
Gbl.Usrs.Me.MyCrss.Num = 0;
2014-12-01 23:55:08 +01:00
2016-09-22 01:28:31 +02:00
if (Gbl.Usrs.Me.Logged)
{
/***** Remove temporary table with my courses *****/
Usr_RemoveTemporaryTableMyCourses ();
/***** Create temporary table with my courses *****/
sprintf (Query,"CREATE TEMPORARY TABLE IF NOT EXISTS my_courses_tmp "
"(CrsCod INT NOT NULL,"
"Role TINYINT NOT NULL,"
"DegCod INT NOT NULL,"
2016-09-22 02:02:19 +02:00
"UNIQUE INDEX(CrsCod,Role,DegCod)) ENGINE=MEMORY"
2016-09-22 01:28:31 +02:00
" SELECT crs_usr.CrsCod,crs_usr.Role,courses.DegCod"
" FROM crs_usr,courses,degrees"
2017-03-24 01:09:27 +01:00
" WHERE crs_usr.UsrCod=%ld"
2016-09-22 01:28:31 +02:00
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" ORDER BY degrees.ShortName,courses.ShortName",
Gbl.Usrs.Me.UsrDat.UsrCod);
if (mysql_query (&Gbl.mysql,Query))
DB_ExitOnMySQLError ("can not create temporary table");
/***** Get my courses from database *****/
sprintf (Query,"SELECT CrsCod,Role,DegCod FROM my_courses_tmp");
NumCrss = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get the courses you belong to");
/***** Get my courses from database *****/
for (NumCrs = 0;
NumCrs < NumCrss;
NumCrs++)
{
/* Get next course */
row = mysql_fetch_row (mysql_res);
/* Get course code */
if ((CrsCod = Str_ConvertStrCodToLongCod (row[0])) > 0)
{
2016-10-28 10:03:37 +02:00
if (Gbl.Usrs.Me.MyCrss.Num == Crs_MAX_COURSES_PER_USR)
2016-09-22 01:28:31 +02:00
Lay_ShowErrorAndExit ("Maximum number of courses of a user exceeded.");
2016-10-28 10:03:37 +02:00
Gbl.Usrs.Me.MyCrss.Crss[Gbl.Usrs.Me.MyCrss.Num].CrsCod = CrsCod;
Gbl.Usrs.Me.MyCrss.Crss[Gbl.Usrs.Me.MyCrss.Num].Role = Rol_ConvertUnsignedStrToRole (row[1]);
Gbl.Usrs.Me.MyCrss.Crss[Gbl.Usrs.Me.MyCrss.Num].DegCod = Str_ConvertStrCodToLongCod (row[2]);
Gbl.Usrs.Me.MyCrss.Num++;
2016-09-22 01:28:31 +02:00
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2014-12-01 23:55:08 +01:00
2016-09-22 01:28:31 +02:00
/***** Set boolean that indicates that my courses are yet filled *****/
2016-10-28 10:03:37 +02:00
Gbl.Usrs.Me.MyCrss.Filled = true;
}
}
/*****************************************************************************/
/************************ Free the list of my countries ************************/
/*****************************************************************************/
void Usr_FreeMyCountrs (void)
{
if (Gbl.Usrs.Me.MyCtys.Filled)
{
/***** Reset list *****/
Gbl.Usrs.Me.MyCtys.Filled = false;
Gbl.Usrs.Me.MyCtys.Num = 0;
}
}
/*****************************************************************************/
/********************* Free the list of my institutions **********************/
/*****************************************************************************/
void Usr_FreeMyInstits (void)
{
if (Gbl.Usrs.Me.MyInss.Filled)
{
/***** Reset list *****/
Gbl.Usrs.Me.MyInss.Filled = false;
Gbl.Usrs.Me.MyInss.Num = 0;
}
}
/*****************************************************************************/
/************************ Free the list of my centres ************************/
/*****************************************************************************/
void Usr_FreeMyCentres (void)
{
if (Gbl.Usrs.Me.MyCtrs.Filled)
{
/***** Reset list *****/
Gbl.Usrs.Me.MyCtrs.Filled = false;
Gbl.Usrs.Me.MyCtrs.Num = 0;
}
}
/*****************************************************************************/
/************************ Free the list of my degrees ************************/
/*****************************************************************************/
void Usr_FreeMyDegrees (void)
{
if (Gbl.Usrs.Me.MyDegs.Filled)
{
/***** Reset list *****/
Gbl.Usrs.Me.MyDegs.Filled = false;
Gbl.Usrs.Me.MyDegs.Num = 0;
2016-09-22 01:28:31 +02:00
}
}
2014-12-01 23:55:08 +01:00
2016-09-22 01:28:31 +02:00
/*****************************************************************************/
/************************ Free the list of my courses ************************/
/*****************************************************************************/
2014-12-01 23:55:08 +01:00
2016-09-22 01:28:31 +02:00
void Usr_FreeMyCourses (void)
{
2016-10-28 10:03:37 +02:00
if (Gbl.Usrs.Me.MyCrss.Filled)
2016-09-22 01:28:31 +02:00
{
/***** Reset list *****/
2016-10-28 10:03:37 +02:00
Gbl.Usrs.Me.MyCrss.Filled = false;
Gbl.Usrs.Me.MyCrss.Num = 0;
2014-12-01 23:55:08 +01:00
2016-09-22 01:28:31 +02:00
/***** Remove temporary table with my courses *****/
Usr_RemoveTemporaryTableMyCourses ();
2014-12-01 23:55:08 +01:00
}
}
2016-09-22 01:28:31 +02:00
/*****************************************************************************/
/************************ Free the list of my courses ************************/
/*****************************************************************************/
static void Usr_RemoveTemporaryTableMyCourses (void)
{
char Query[128];
/***** Remove temporary table with my courses *****/
sprintf (Query,"DROP TEMPORARY TABLE IF EXISTS my_courses_tmp");
if (mysql_query (&Gbl.mysql,Query))
DB_ExitOnMySQLError ("can not remove temporary table");
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2015-09-16 19:22:32 +02:00
/**************** Check if a user belongs to an institution ******************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2017-01-27 01:02:52 +01:00
bool Usr_CheckIfUsrBelongsToIns (long UsrCod,long InsCod)
2014-12-01 23:55:08 +01:00
{
char Query[512];
2017-01-27 01:02:52 +01:00
static struct
{
long UsrCod;
long InsCod;
bool Belongs;
2017-03-01 15:23:30 +01:00
} Cached =
2017-01-27 01:02:52 +01:00
{
-1L,
-1L,
false
};
2015-09-16 19:22:32 +02:00
2015-09-17 11:21:49 +02:00
if (UsrCod <= 0 ||
InsCod <= 0)
2017-01-27 01:02:52 +01:00
{
/***** Trivial case *****/
2017-03-01 15:23:30 +01:00
Cached.UsrCod = -1L;
Cached.InsCod = -1L;
Cached.Belongs = false;
2017-01-27 01:02:52 +01:00
}
2017-03-01 15:23:30 +01:00
else if (UsrCod != Cached.UsrCod ||
InsCod != Cached.InsCod) // If not cached...
2017-01-27 01:02:52 +01:00
{
/***** Get is a user belongs to an institution from database *****/
sprintf (Query,"SELECT COUNT(DISTINCT centres.InsCod)"
" FROM crs_usr,courses,degrees,centres"
2017-03-24 01:09:27 +01:00
" WHERE crs_usr.UsrCod=%ld"
2017-01-27 01:02:52 +01:00
" AND crs_usr.Accepted='Y'"
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
2017-03-24 01:09:27 +01:00
" AND centres.InsCod=%ld",
2017-01-27 01:02:52 +01:00
UsrCod,InsCod);
2017-03-01 15:23:30 +01:00
Cached.UsrCod = UsrCod;
Cached.InsCod = InsCod;
Cached.Belongs = (DB_QueryCOUNT (Query,"can not check if a user belongs to an institution") != 0);
2017-01-27 01:02:52 +01:00
}
2015-09-17 11:21:49 +02:00
2017-03-01 15:23:30 +01:00
return Cached.Belongs;
2015-09-16 19:22:32 +02:00
}
2014-12-01 23:55:08 +01:00
2015-09-16 19:22:32 +02:00
/*****************************************************************************/
/******************* Check if a user belongs to a centre *********************/
/*****************************************************************************/
2014-12-01 23:55:08 +01:00
2017-01-27 01:02:52 +01:00
bool Usr_CheckIfUsrBelongsToCtr (long UsrCod,long CtrCod)
2015-09-16 19:22:32 +02:00
{
char Query[512];
2017-01-27 01:02:52 +01:00
static struct
{
long UsrCod;
long CtrCod;
bool Belongs;
2017-03-01 15:23:30 +01:00
} Cached =
2017-01-27 01:02:52 +01:00
{
-1L,
-1L,
false
};
2015-09-16 19:22:32 +02:00
2015-09-17 11:21:49 +02:00
if (UsrCod <= 0 ||
CtrCod <= 0)
2017-01-27 01:02:52 +01:00
{
/***** Trivial case *****/
2017-03-01 15:23:30 +01:00
Cached.UsrCod = -1L;
Cached.CtrCod = -1L;
Cached.Belongs = false;
2017-01-27 01:02:52 +01:00
}
2017-03-01 15:23:30 +01:00
else if (UsrCod != Cached.UsrCod ||
CtrCod != Cached.CtrCod) // If not cached...
2017-01-27 01:02:52 +01:00
{
/***** Get is a user belongs to a centre from database *****/
sprintf (Query,"SELECT COUNT(DISTINCT degrees.CtrCod)"
" FROM crs_usr,courses,degrees"
2017-03-24 01:09:27 +01:00
" WHERE crs_usr.UsrCod=%ld"
2017-01-27 01:02:52 +01:00
" AND crs_usr.Accepted='Y'" // Only if user accepted
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
2017-03-24 01:09:27 +01:00
" AND degrees.CtrCod=%ld",
2017-01-27 01:02:52 +01:00
UsrCod,CtrCod);
2017-03-01 15:23:30 +01:00
Cached.UsrCod = UsrCod;
Cached.CtrCod = CtrCod;
Cached.Belongs = (DB_QueryCOUNT (Query,"can not check if a user belongs to a centre") != 0);
2017-01-27 01:02:52 +01:00
}
2015-09-17 11:21:49 +02:00
2017-03-01 15:23:30 +01:00
return Cached.Belongs;
2015-09-16 19:22:32 +02:00
}
2014-12-01 23:55:08 +01:00
2015-09-16 19:22:32 +02:00
/*****************************************************************************/
/******************* Check if a user belongs to a degree *********************/
/*****************************************************************************/
2017-01-27 01:02:52 +01:00
bool Usr_CheckIfUsrBelongsToDeg (long UsrCod,long DegCod)
2015-09-16 19:22:32 +02:00
{
char Query[512];
2017-01-27 01:02:52 +01:00
static struct
{
long UsrCod;
long DegCod;
bool Belongs;
2017-03-01 15:23:30 +01:00
} Cached =
2017-01-27 01:02:52 +01:00
{
-1L,
-1L,
false
};
2014-12-01 23:55:08 +01:00
2015-09-17 11:21:49 +02:00
if (UsrCod <= 0 ||
DegCod <= 0)
2017-01-27 01:02:52 +01:00
{
/***** Trivial case *****/
2017-03-01 15:23:30 +01:00
Cached.UsrCod = -1L;
Cached.DegCod = -1L;
Cached.Belongs = false;
2017-01-27 01:02:52 +01:00
}
2017-03-01 15:23:30 +01:00
else if (UsrCod != Cached.UsrCod ||
DegCod != Cached.DegCod) // If not cached...
2017-01-27 01:02:52 +01:00
{
/***** Get is a user belongs to a degree from database *****/
sprintf (Query,"SELECT COUNT(DISTINCT courses.DegCod)"
" FROM crs_usr,courses"
2017-03-24 01:09:27 +01:00
" WHERE crs_usr.UsrCod=%ld"
2017-01-27 01:02:52 +01:00
" AND crs_usr.Accepted='Y'" // Only if user accepted
" AND crs_usr.CrsCod=courses.CrsCod"
2017-03-24 01:09:27 +01:00
" AND courses.DegCod=%ld",
2017-01-27 01:02:52 +01:00
UsrCod,DegCod);
2017-03-01 15:23:30 +01:00
Cached.UsrCod = UsrCod;
Cached.DegCod = DegCod;
Cached.Belongs = (DB_QueryCOUNT (Query,"can not check if a user belongs to a degree") != 0);
2017-01-27 01:02:52 +01:00
}
2015-09-17 11:21:49 +02:00
2017-03-01 15:23:30 +01:00
return Cached.Belongs;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Check if a user belongs to a course ********************/
/*****************************************************************************/
2017-01-27 01:02:52 +01:00
bool Usr_CheckIfUsrBelongsToCrs (long UsrCod,long CrsCod,
2015-09-17 11:21:49 +02:00
bool CountOnlyAcceptedCourses)
2014-12-01 23:55:08 +01:00
{
2015-09-16 19:22:32 +02:00
char Query[512];
const char *SubQuery;
2014-12-01 23:55:08 +01:00
2015-09-17 11:21:49 +02:00
/***** Trivial case *****/
2014-12-01 23:55:08 +01:00
if (UsrCod <= 0 ||
CrsCod <= 0)
return false;
/***** Get if a user belongs to a course from database *****/
2015-09-16 19:22:32 +02:00
SubQuery = (CountOnlyAcceptedCourses ? " AND crs_usr.Accepted='Y'" :
"");
2014-12-01 23:55:08 +01:00
sprintf (Query,"SELECT COUNT(*) FROM crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE CrsCod=%ld AND UsrCod=%ld%s",
2015-09-16 19:22:32 +02:00
CrsCod,UsrCod,SubQuery);
2014-12-01 23:55:08 +01:00
return (DB_QueryCOUNT (Query,"can not check if a user belongs to a course") != 0);
}
2016-10-27 01:30:14 +02:00
/*****************************************************************************/
/********************** Check if I belong to a country **********************/
/*****************************************************************************/
bool Usr_CheckIfIBelongToCty (long CtyCod)
{
unsigned NumMyCty;
/***** Fill the list with the institutions I belong to *****/
2016-10-28 10:03:37 +02:00
Usr_GetMyCountrs ();
2016-10-27 01:30:14 +02:00
/***** Check if the country passed as parameter is any of my countries *****/
for (NumMyCty = 0;
2016-10-28 10:03:37 +02:00
NumMyCty < Gbl.Usrs.Me.MyCtys.Num;
2016-10-27 01:30:14 +02:00
NumMyCty++)
2016-10-28 10:03:37 +02:00
if (Gbl.Usrs.Me.MyCtys.Ctys[NumMyCty].CtyCod == CtyCod)
2016-10-27 01:30:14 +02:00
return true;
return false;
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/******************** Check if I belong to an institution ********************/
/*****************************************************************************/
bool Usr_CheckIfIBelongToIns (long InsCod)
{
unsigned NumMyIns;
/***** Fill the list with the institutions I belong to *****/
2016-10-28 10:03:37 +02:00
Usr_GetMyInstits ();
2014-12-01 23:55:08 +01:00
/***** Check if the institution passed as parameter is any of my institutions *****/
for (NumMyIns = 0;
2016-10-28 10:03:37 +02:00
NumMyIns < Gbl.Usrs.Me.MyInss.Num;
2014-12-01 23:55:08 +01:00
NumMyIns++)
2016-10-28 10:03:37 +02:00
if (Gbl.Usrs.Me.MyInss.Inss[NumMyIns].InsCod == InsCod)
2014-12-01 23:55:08 +01:00
return true;
return false;
}
/*****************************************************************************/
/*********************** Check if I belong to a centre ***********************/
/*****************************************************************************/
bool Usr_CheckIfIBelongToCtr (long CtrCod)
{
unsigned NumMyCtr;
/***** Fill the list with the centres I belong to *****/
Usr_GetMyCentres ();
/***** Check if the centre passed as parameter is any of my centres *****/
for (NumMyCtr = 0;
2016-10-28 10:03:37 +02:00
NumMyCtr < Gbl.Usrs.Me.MyCtrs.Num;
2014-12-01 23:55:08 +01:00
NumMyCtr++)
2016-10-28 10:03:37 +02:00
if (Gbl.Usrs.Me.MyCtrs.Ctrs[NumMyCtr].CtrCod == CtrCod)
2014-12-01 23:55:08 +01:00
return true;
return false;
}
/*****************************************************************************/
/*********************** Check if I belong to a degree ***********************/
/*****************************************************************************/
bool Usr_CheckIfIBelongToDeg (long DegCod)
{
unsigned NumMyDeg;
/***** Fill the list with the degrees I belong to *****/
Usr_GetMyDegrees ();
/***** Check if the degree passed as parameter is any of 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++)
2016-10-28 10:03:37 +02:00
if (Gbl.Usrs.Me.MyDegs.Degs[NumMyDeg].DegCod == DegCod)
2014-12-01 23:55:08 +01:00
return true;
return false;
}
/*****************************************************************************/
/*********************** Check if I belong to a course ***********************/
/*****************************************************************************/
bool Usr_CheckIfIBelongToCrs (long CrsCod)
{
unsigned NumMyCrs;
/***** Fill the list with the courses I belong to *****/
Usr_GetMyCourses ();
/***** Check if the course passed as parameter is any of my courses *****/
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++)
2016-10-28 10:03:37 +02:00
if (Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].CrsCod == CrsCod)
2014-12-01 23:55:08 +01:00
return true;
return false;
}
/*****************************************************************************/
2014-12-29 00:54:56 +01:00
/**************** Get the countries of a user from database ******************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
// Returns the number of rows of the result
2014-12-29 00:54:56 +01:00
unsigned Usr_GetCtysFromUsr (long UsrCod,MYSQL_RES **mysql_res)
2014-12-01 23:55:08 +01:00
{
2017-01-28 15:58:46 +01:00
extern const char *Txt_STR_LANG_ID[1 + Txt_NUM_LANGUAGES];
2017-03-13 20:32:03 +01:00
char Query[1024];
2014-12-01 23:55:08 +01:00
/***** Get the institutions a user belongs to from database *****/
2014-12-29 00:54:56 +01:00
sprintf (Query,"SELECT countries.CtyCod,MAX(crs_usr.Role)"
" FROM crs_usr,courses,degrees,centres,institutions,countries"
2017-03-24 01:09:27 +01:00
" WHERE crs_usr.UsrCod=%ld"
2014-12-01 23:55:08 +01:00
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
" AND centres.InsCod=institutions.InsCod"
2014-12-29 00:54:56 +01:00
" AND institutions.CtyCod=countries.CtyCod"
" GROUP BY countries.CtyCod"
" ORDER BY countries.Name_%s",
UsrCod,Txt_STR_LANG_ID[Gbl.Prefs.Language]);
return (unsigned) DB_QuerySELECT (Query,mysql_res,"can not get the countries a user belongs to");
}
/*****************************************************************************/
/************** Get the institutions of a user from database *****************/
/*****************************************************************************/
// Returns the number of rows of the result
unsigned long Usr_GetInssFromUsr (long UsrCod,long CtyCod,MYSQL_RES **mysql_res)
{
2017-03-13 20:32:03 +01:00
char Query[1024];
2014-12-29 00:54:56 +01:00
/***** Get the institutions a user belongs to from database *****/
if (CtyCod > 0)
sprintf (Query,"SELECT institutions.InsCod,MAX(crs_usr.Role)"
" FROM crs_usr,courses,degrees,centres,institutions"
2017-03-24 01:09:27 +01:00
" WHERE crs_usr.UsrCod=%ld"
2014-12-29 00:54:56 +01:00
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
" AND centres.InsCod=institutions.InsCod"
2017-03-24 01:09:27 +01:00
" AND institutions.CtyCod=%ld"
2014-12-29 00:54:56 +01:00
" GROUP BY institutions.InsCod"
" ORDER BY institutions.ShortName",
UsrCod,CtyCod);
else
sprintf (Query,"SELECT institutions.InsCod,MAX(crs_usr.Role)"
" FROM crs_usr,courses,degrees,centres,institutions"
2017-03-24 01:09:27 +01:00
" WHERE crs_usr.UsrCod=%ld"
2014-12-29 00:54:56 +01:00
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
" AND centres.InsCod=institutions.InsCod"
" GROUP BY institutions.InsCod"
" ORDER BY institutions.ShortName",
UsrCod);
2014-12-01 23:55:08 +01:00
return DB_QuerySELECT (Query,mysql_res,"can not get the institutions a user belongs to");
}
/*****************************************************************************/
/***************** Get the centres of a user from database *******************/
/*****************************************************************************/
// Returns the number of rows of the result
unsigned long Usr_GetCtrsFromUsr (long UsrCod,long InsCod,MYSQL_RES **mysql_res)
{
2017-03-13 20:32:03 +01:00
char Query[1024];
2014-12-01 23:55:08 +01:00
/***** Get from database the centres a user belongs to *****/
if (InsCod > 0)
sprintf (Query,"SELECT centres.CtrCod,MAX(crs_usr.Role)"
" FROM crs_usr,courses,degrees,centres"
2017-03-24 01:09:27 +01:00
" WHERE crs_usr.UsrCod=%ld"
2014-12-01 23:55:08 +01:00
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
2017-03-24 01:09:27 +01:00
" AND centres.InsCod=%ld"
2014-12-01 23:55:08 +01:00
" GROUP BY centres.CtrCod ORDER BY centres.ShortName",
UsrCod,InsCod);
else
sprintf (Query,"SELECT degrees.CtrCod,MAX(crs_usr.Role)"
" FROM crs_usr,courses,degrees,centres"
2017-03-24 01:09:27 +01:00
" WHERE crs_usr.UsrCod=%ld"
2014-12-01 23:55:08 +01:00
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
" GROUP BY centres.CtrCod ORDER BY centres.ShortName",
UsrCod);
return DB_QuerySELECT (Query,mysql_res,"can not check the centres a user belongs to");
}
/*****************************************************************************/
/***************** Get the degrees of a user from database *******************/
/*****************************************************************************/
// Returns the number of rows of the result
unsigned long Usr_GetDegsFromUsr (long UsrCod,long CtrCod,MYSQL_RES **mysql_res)
{
2017-03-13 20:32:03 +01:00
char Query[1024];
2014-12-01 23:55:08 +01:00
/***** Get from database the degrees a user belongs to *****/
if (CtrCod > 0)
sprintf (Query,"SELECT degrees.DegCod,MAX(crs_usr.Role)"
" FROM crs_usr,courses,degrees"
2017-03-24 01:09:27 +01:00
" WHERE crs_usr.UsrCod=%ld"
2016-10-28 10:03:37 +02:00
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
2017-03-24 01:09:27 +01:00
" AND degrees.CtrCod=%ld"
2014-12-01 23:55:08 +01:00
" GROUP BY degrees.DegCod ORDER BY degrees.ShortName",
UsrCod,CtrCod);
else
sprintf (Query,"SELECT degrees.DegCod,MAX(crs_usr.Role)"
" FROM crs_usr,courses,degrees"
2017-03-24 01:09:27 +01:00
" WHERE crs_usr.UsrCod=%ld"
2016-10-28 10:03:37 +02:00
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
2014-12-01 23:55:08 +01:00
" GROUP BY degrees.DegCod ORDER BY degrees.ShortName",
UsrCod);
2016-10-28 10:03:37 +02:00
return DB_QuerySELECT (Query,mysql_res,"can not check the degrees"
" a user belongs to");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************** Get all the courses of a user from database ******************/
/*****************************************************************************/
// Returns the number of rows of the result
unsigned long Usr_GetCrssFromUsr (long UsrCod,long DegCod,MYSQL_RES **mysql_res)
{
2017-03-13 20:32:03 +01:00
char Query[1024];
2014-12-01 23:55:08 +01:00
/***** Get from database the courses a user belongs to *****/
2016-09-22 01:28:31 +02:00
if (DegCod > 0) // Courses in a degree
2014-12-01 23:55:08 +01:00
sprintf (Query,"SELECT crs_usr.CrsCod,crs_usr.Role,courses.DegCod"
" FROM crs_usr,courses"
2017-03-24 01:09:27 +01:00
" WHERE crs_usr.UsrCod=%ld"
2016-06-23 21:18:11 +02:00
" AND crs_usr.CrsCod=courses.CrsCod"
2017-03-24 01:09:27 +01:00
" AND courses.DegCod=%ld"
2014-12-01 23:55:08 +01:00
" ORDER BY courses.ShortName",
UsrCod,DegCod);
2016-09-22 01:28:31 +02:00
else // All the courses
2014-12-01 23:55:08 +01:00
sprintf (Query,"SELECT crs_usr.CrsCod,crs_usr.Role,courses.DegCod"
" FROM crs_usr,courses,degrees"
2017-03-24 01:09:27 +01:00
" WHERE crs_usr.UsrCod=%ld"
2016-06-23 21:18:11 +02:00
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
2014-12-01 23:55:08 +01:00
" ORDER BY degrees.ShortName,courses.ShortName",
UsrCod);
return DB_QuerySELECT (Query,mysql_res,"can not get the courses a user belongs to");
}
/*****************************************************************************/
/******** Check if a user exists with a given encrypted user's code **********/
/*****************************************************************************/
2017-03-13 20:32:03 +01:00
bool Usr_ChkIfEncryptedUsrCodExists (const char EncryptedUsrCod[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64])
2014-12-01 23:55:08 +01:00
{
2017-03-13 20:32:03 +01:00
char Query[128 + Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64];
2014-12-01 23:55:08 +01:00
/***** Get if an encrypted user's code already existed in database *****/
2017-03-13 20:32:03 +01:00
sprintf (Query,"SELECT COUNT(*) FROM usr_data WHERE EncryptedUsrCod='%s'",
2014-12-01 23:55:08 +01:00
EncryptedUsrCod);
return (DB_QueryCOUNT (Query,"can not check if an encrypted user's code already existed") != 0);
}
/*****************************************************************************/
2016-03-01 03:16:29 +01:00
/***************************** Write landing page ****************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-03-01 03:16:29 +01:00
void Usr_WriteLandingPage (void)
2014-12-01 23:55:08 +01:00
{
2016-03-01 03:16:29 +01:00
/***** Form to log in *****/
2016-12-05 13:26:12 +01:00
Usr_WriteFormLogin (ActLogIn,NULL);
2015-10-06 01:19:21 +02:00
2016-03-21 19:52:40 +01:00
/***** Form to go to request the creation of a new account *****/
Acc_ShowFormGoToRequestNewAccount ();
2016-03-01 03:16:29 +01:00
}
/*****************************************************************************/
/************************ Write form for user log out ************************/
/*****************************************************************************/
void Usr_WriteFormLogout (void)
{
/***** Form to change my role *****/
Usr_ShowFormsLogoutAndRole ();
2017-03-30 11:20:06 +02:00
/***** Show help to enrol me *****/
2016-03-01 03:16:29 +01:00
Hlp_ShowHelpWhatWouldYouLikeToDo ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Message and form shown after log out ******************/
/*****************************************************************************/
void Usr_Logout (void)
{
extern const char *Txt_The_session_has_been_closed;
/***** Confirmation message *****/
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_INFO,Txt_The_session_has_been_closed);
2014-12-01 23:55:08 +01:00
/***** Form to log in *****/
2016-12-05 13:26:12 +01:00
Usr_WriteFormLogin (ActLogIn,NULL);
2014-12-01 23:55:08 +01:00
/***** Advertisement about mobile app *****/
Lay_AdvertisementMobile ();
}
2016-02-29 16:22:11 +01:00
/*****************************************************************************/
/*************************** Put link to log in ******************************/
/*****************************************************************************/
void Usr_PutLinkToLogin (void)
{
extern const char *Txt_Log_in;
2017-04-17 19:03:21 +02:00
Lay_PutContextualLink (ActFrmLogIn,NULL,NULL,
2016-07-01 16:32:42 +02:00
"login-green64x64.png",
Txt_Log_in,Txt_Log_in,
NULL);
2016-02-29 16:22:11 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************ Write form for user log in *************************/
/*****************************************************************************/
2016-12-04 03:50:25 +01:00
void Usr_WriteFormLogin (Act_Action_t NextAction,void (*FuncParams) ())
2014-12-01 23:55:08 +01:00
{
2017-03-02 21:18:52 +01:00
extern const char *Hlp_PROFILE_LogIn;
2015-03-27 16:56:48 +01:00
extern const char *Txt_Log_in;
2016-06-15 14:42:28 +02:00
extern const char *Txt_User[Usr_NUM_SEXS];
2014-12-01 23:55:08 +01:00
extern const char *Txt_nick_email_or_ID;
extern const char *Txt_Password;
2015-03-27 16:56:48 +01:00
extern const char *Txt_password;
2014-12-01 23:55:08 +01:00
2015-03-27 16:56:48 +01:00
/***** Links to other actions *****/
2015-04-02 14:22:21 +02:00
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
2015-03-27 16:56:48 +01:00
2016-03-01 03:16:29 +01:00
Acc_PutLinkToCreateAccount ();
2015-04-02 18:39:49 +02:00
Pwd_PutLinkToSendNewPasswd ();
2017-05-07 18:06:34 +02:00
Lan_PutLinkToChangeLanguage ();
2015-03-27 16:56:48 +01:00
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</div>");
2015-09-02 23:51:44 +02:00
fprintf (Gbl.F.Out,"<div class=\"CENTER_MIDDLE\">");
2016-12-04 03:50:25 +01:00
/***** Start form *****/
Act_FormStart (NextAction);
if (FuncParams)
FuncParams ();
/***** Start frame and table *****/
2017-03-02 21:18:52 +01:00
Lay_StartRoundFrameTable (NULL,Txt_Log_in,NULL,Hlp_PROFILE_LogIn,2);
2014-12-01 23:55:08 +01:00
2016-12-26 16:58:49 +01:00
/***** User's ID/nickname *****/
fprintf (Gbl.F.Out,"<div class=\"LEFT_MIDDLE\">"
"<label>"
"<img src=\"%s/user64x64.gif\" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />"
2016-12-26 16:58:49 +01:00
"<input type=\"text\" name=\"UsrId\""
" size=\"18\" maxlength=\"%u\" placeholder=\"%s\""
" value=\"%s\""
2016-12-26 13:09:21 +01:00
" autofocus=\"autofocus\" required=\"required\" />"
2016-12-26 16:58:49 +01:00
"</label>"
"</div>",
2015-03-27 16:56:48 +01:00
Gbl.Prefs.IconsURL,
2016-06-15 14:42:28 +02:00
Txt_User[Usr_SEX_UNKNOWN],
Txt_User[Usr_SEX_UNKNOWN],
2017-03-13 13:17:53 +01:00
Cns_MAX_CHARS_EMAIL_ADDRESS,
2015-03-24 17:47:26 +01:00
Txt_nick_email_or_ID,
2016-12-26 16:58:49 +01:00
Gbl.Usrs.Me.UsrIdLogin);
/***** User's password *****/
fprintf (Gbl.F.Out,"<div class=\"LEFT_MIDDLE\">"
"<label>"
"<img src=\"%s/key64x64.gif\" alt=\"%s\" title=\"%s\""
" class=\"ICO20x20\" />"
"<input type=\"password\" name=\"UsrPwd\""
" size=\"18\" maxlength=\"%u\" placeholder=\"%s\" />"
"</label>"
"</div>",
2015-03-27 16:56:48 +01:00
Gbl.Prefs.IconsURL,
2014-12-01 23:55:08 +01:00
Txt_Password,
2015-07-21 12:40:41 +02:00
Txt_Password,
2017-03-07 01:56:41 +01:00
Pwd_MAX_CHARS_PLAIN_PASSWORD,
2015-03-27 16:56:48 +01:00
Txt_password);
2014-12-01 23:55:08 +01:00
2016-12-04 03:50:25 +01:00
/***** Send button and end table and frame *****/
2016-11-14 10:05:41 +01:00
Lay_EndRoundFrameTableWithButton (Lay_CONFIRM_BUTTON,Txt_Log_in);
2016-12-04 03:50:25 +01:00
/***** End form *****/
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
2014-12-01 23:55:08 +01:00
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</div>");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Write type and name of logged user **********************/
/*****************************************************************************/
void Usr_WelcomeUsr (void)
{
extern const unsigned Txt_Current_CGI_SWAD_Language;
2015-07-22 18:59:44 +02:00
extern const char *Txt_Happy_birthday;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Welcome_X_and_happy_birthday[Usr_NUM_SEXS];
2016-10-10 19:25:25 +02:00
extern const char *Txt_Welcome_X[Usr_NUM_SEXS];
extern const char *Txt_Welcome[Usr_NUM_SEXS];
2017-01-28 15:58:46 +01:00
extern const char *Txt_Switching_to_LANGUAGE[1 + Txt_NUM_LANGUAGES];
2014-12-01 23:55:08 +01:00
bool CongratulateMyBirthday;
if (Gbl.Usrs.Me.Logged)
{
if (Gbl.Usrs.Me.UsrDat.Prefs.Language == Txt_Current_CGI_SWAD_Language)
{
2015-09-02 23:51:44 +02:00
fprintf (Gbl.F.Out,"<div class=\"CENTER_MIDDLE\""
2015-09-28 18:28:29 +02:00
" style=\"margin:12px;\">");
2014-12-01 23:55:08 +01:00
2016-10-10 17:53:56 +02:00
/***** Welcome to a user *****/
2014-12-01 23:55:08 +01:00
if (Gbl.Usrs.Me.UsrDat.FirstName[0])
{
CongratulateMyBirthday = false;
if (Gbl.Usrs.Me.UsrDat.Birthday.Day == Gbl.Now.Date.Day &&
Gbl.Usrs.Me.UsrDat.Birthday.Month == Gbl.Now.Date.Month)
if ((CongratulateMyBirthday = Usr_CheckIfMyBirthdayHasNotBeenCongratulated ()))
{
Usr_InsertMyBirthday ();
2015-07-22 18:59:44 +02:00
fprintf (Gbl.F.Out,"<img src=\"%s/%s/cake128x128.gif\""
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO160x160\" />",
2015-07-22 18:59:44 +02:00
Gbl.Prefs.PathIconSet,Cfg_ICON_128x128,
Txt_Happy_birthday,
Txt_Happy_birthday);
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_Welcome_X_and_happy_birthday[Gbl.Usrs.Me.UsrDat.Sex],
2014-12-01 23:55:08 +01:00
Gbl.Usrs.Me.UsrDat.FirstName);
}
if (!CongratulateMyBirthday)
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_Welcome_X[Gbl.Usrs.Me.UsrDat.Sex],
2014-12-01 23:55:08 +01:00
Gbl.Usrs.Me.UsrDat.FirstName);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_INFO,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
else
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_INFO,Txt_Welcome[Gbl.Usrs.Me.UsrDat.Sex]);
2014-12-01 23:55:08 +01:00
2016-11-16 23:19:52 +01:00
/***** Warning to confirm my email address *****/
2016-10-10 19:25:25 +02:00
if (Gbl.Usrs.Me.UsrDat.Email[0] &&
!Gbl.Usrs.Me.UsrDat.EmailConfirmed)
Mai_PutButtonToCheckEmailAddress ();
2017-03-30 11:20:06 +02:00
/***** Show help to enrol me *****/
2015-10-06 20:34:49 +02:00
Hlp_ShowHelpWhatWouldYouLikeToDo ();
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</div>");
/***** Show the global announcements I have not seen *****/
Ann_ShowMyAnnouncementsNotMarkedAsSeen ();
}
2016-12-05 13:26:12 +01:00
else
/* The current language is not my preferred language
==> change automatically to my language */
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_INFO,Txt_Switching_to_LANGUAGE[Gbl.Usrs.Me.UsrDat.Prefs.Language]);
2014-12-01 23:55:08 +01:00
}
}
2016-05-01 01:52:35 +02:00
/*****************************************************************************/
/************ Write birthday string to insert or update database *************/
/*****************************************************************************/
void Usr_CreateBirthdayStrDB (const struct UsrData *UsrDat,
2017-01-15 22:58:26 +01:00
char BirthdayStrDB[Usr_BIRTHDAY_STR_DB_LENGTH + 1])
2016-05-01 01:52:35 +02:00
{
if (UsrDat->Birthday.Year == 0 ||
UsrDat->Birthday.Month == 0 ||
UsrDat->Birthday.Day == 0)
2017-01-17 03:10:43 +01:00
Str_Copy (BirthdayStrDB,"NULL",
Usr_BIRTHDAY_STR_DB_LENGTH);
2016-05-01 01:52:35 +02:00
else
sprintf (BirthdayStrDB,"'%04u-%02u-%02u'",
UsrDat->Birthday.Year,
UsrDat->Birthday.Month,
UsrDat->Birthday.Day);
}
/*****************************************************************************/
2014-12-01 23:55:08 +01:00
/*************** Check if my birthday is already congratulated ***************/
/*****************************************************************************/
static bool Usr_CheckIfMyBirthdayHasNotBeenCongratulated (void)
{
2017-03-13 20:32:03 +01:00
char Query[128];
2014-12-01 23:55:08 +01:00
/***** Delete old birthdays *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"SELECT COUNT(*) FROM birthdays_today WHERE UsrCod=%ld",
2014-12-01 23:55:08 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod);
return (DB_QueryCOUNT (Query,"can not check if my birthday has been congratulated") == 0);
}
/*****************************************************************************/
/******** Insert my user's code in table of birthdays already wished *********/
/*****************************************************************************/
static void Usr_InsertMyBirthday (void)
{
char Query[256];
/***** Delete old birthdays *****/
sprintf (Query,"DELETE FROM birthdays_today WHERE Today<>CURDATE()");
DB_QueryDELETE (Query,"can not delete old birthdays");
/***** Insert new birthday *****/
2017-03-13 13:17:53 +01:00
sprintf (Query,"INSERT INTO birthdays_today"
" (UsrCod,Today)"
" VALUES"
2017-03-24 01:09:27 +01:00
" (%ld,CURDATE())",
2014-12-01 23:55:08 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryINSERT (Query,"can not insert birthday");
}
/*****************************************************************************/
/************************ Write form for user log in *************************/
/*****************************************************************************/
void Usr_PutFormLogIn (void)
{
extern const char *The_ClassHead[The_NUM_THEMES];
extern const char *Txt_Log_in;
/***** Link to log in form *****/
Act_FormStart (ActFrmLogIn);
2016-07-01 17:13:41 +02:00
Act_LinkFormSubmit (Txt_Log_in,The_ClassHead[Gbl.Prefs.Theme],NULL);
2015-12-08 19:21:40 +01:00
fprintf (Gbl.F.Out,"<img src=\"%s/login-green64x64.png\""
2015-07-22 18:59:44 +02:00
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />"
2015-11-30 16:21:56 +01:00
"<span id=\"login_txt\">&nbsp;%s</span>"
"</a>",
2015-12-08 19:21:40 +01:00
Gbl.Prefs.IconsURL,
2015-07-22 18:59:44 +02:00
Txt_Log_in,
Txt_Log_in,
Txt_Log_in);
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Write type and name of logged user **********************/
/*****************************************************************************/
void Usr_WriteLoggedUsrHead (void)
{
extern const char *The_ClassUsr[The_NUM_THEMES];
extern const char *The_ClassHead[The_NUM_THEMES];
2016-11-13 12:52:07 +01:00
extern const char *Txt_Role;
2015-03-12 14:45:40 +01:00
extern const char *Txt_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2014-12-01 23:55:08 +01:00
bool ShowPhoto;
2017-01-28 15:58:46 +01:00
char PhotoURL[PATH_MAX + 1];
2017-03-06 01:31:06 +01:00
unsigned NumAvailableRoles = Rol_GetNumAvailableRoles ();
fprintf (Gbl.F.Out,"<div class=\"HEAD_USR %s\">",
The_ClassUsr[Gbl.Prefs.Theme]);
2014-12-01 23:55:08 +01:00
2016-12-27 16:45:37 +01:00
/***** User's role *****/
2017-03-06 01:31:06 +01:00
if (NumAvailableRoles == 1)
2016-11-13 12:52:07 +01:00
{
Act_FormStart (ActFrmRolSes);
Act_LinkFormSubmit (Txt_Role,The_ClassUsr[Gbl.Prefs.Theme],NULL);
fprintf (Gbl.F.Out,"%s</a>",
2015-03-12 14:45:40 +01:00
Txt_ROLES_SINGUL_Abc[Gbl.Usrs.Me.LoggedRole][Gbl.Usrs.Me.UsrDat.Sex]);
2016-11-13 12:52:07 +01:00
Act_FormEnd ();
2017-03-06 01:31:06 +01:00
fprintf (Gbl.F.Out,":&nbsp;");
2016-11-13 12:52:07 +01:00
}
2014-12-01 23:55:08 +01:00
else
{
2016-12-10 18:32:35 +01:00
Rol_PutFormToChangeMyRole ();
2017-03-06 01:31:06 +01:00
fprintf (Gbl.F.Out,"&nbsp;");
2014-12-01 23:55:08 +01:00
}
2016-01-20 14:07:15 +01:00
/***** Show my photo *****/
2017-01-28 15:58:46 +01:00
ShowPhoto = Pho_ShowingUsrPhotoIsAllowed (&Gbl.Usrs.Me.UsrDat,PhotoURL);
2014-12-30 15:14:43 +01:00
Pho_ShowUsrPhoto (&Gbl.Usrs.Me.UsrDat,ShowPhoto ? PhotoURL :
NULL,
2016-01-14 10:31:09 +01:00
"PHOTO18x24",Pho_ZOOM,false);
2014-12-01 23:55:08 +01:00
/***** User's name *****/
2017-03-06 01:31:06 +01:00
if (Gbl.Usrs.Me.UsrDat.FirstName[0])
fprintf (Gbl.F.Out,"&nbsp;%s",Gbl.Usrs.Me.UsrDat.FirstName);
2014-12-01 23:55:08 +01:00
2017-03-06 01:31:06 +01:00
fprintf (Gbl.F.Out,"</div>");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************** Put a form to close current session (log out) ***************/
/*****************************************************************************/
void Usr_PutFormLogOut (void)
{
extern const char *The_ClassHead[The_NUM_THEMES];
extern const char *Txt_Log_out;
Act_FormStart (ActLogOut);
2016-07-01 17:13:41 +02:00
Act_LinkFormSubmit (Txt_Log_out,The_ClassHead[Gbl.Prefs.Theme],NULL);
2015-12-08 19:21:40 +01:00
fprintf (Gbl.F.Out,"<img src=\"%s/logout-red64x64.png\""
2015-07-22 18:59:44 +02:00
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />"
2015-11-30 16:21:56 +01:00
"<span id=\"login_txt\">&nbsp;%s</span>"
"</a>",
2015-12-08 19:21:40 +01:00
Gbl.Prefs.IconsURL,
2015-07-22 18:59:44 +02:00
Txt_Log_out,
Txt_Log_out,
Txt_Log_out);
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******* Get parameter with my plain user's ID or nickname from a form *******/
/*****************************************************************************/
void Usr_GetParamUsrIdLogin (void)
{
2017-03-13 13:17:53 +01:00
Par_GetParToText ("UsrId",Gbl.Usrs.Me.UsrIdLogin,Cns_MAX_BYTES_EMAIL_ADDRESS);
2016-09-23 15:03:25 +02:00
// Users' IDs are always stored internally without leading zeros
2014-12-01 23:55:08 +01:00
Str_RemoveLeadingZeros (Gbl.Usrs.Me.UsrIdLogin);
}
/*****************************************************************************/
/******* Get parameter user's identificator of other user from a form ********/
/*****************************************************************************/
static void Usr_GetParamOtherUsrIDNickOrEMail (void)
{
2016-11-16 23:19:52 +01:00
/***** Get parameter with the plain user's ID, @nick or email of another user *****/
2017-01-29 21:41:08 +01:00
Par_GetParToText ("OtherUsrIDNickOrEMail",
Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail,
2017-03-13 13:17:53 +01:00
Cns_MAX_BYTES_EMAIL_ADDRESS);
2014-12-01 23:55:08 +01:00
// If it's a user's ID (if does not contain '@')
2015-10-07 19:55:13 +02:00
if (strchr (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail,(int) '@') != NULL) // '@' not found
2014-12-01 23:55:08 +01:00
{
// Users' IDs are always stored internally in capitals and without leading zeros
Str_RemoveLeadingZeros (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail);
2016-03-21 19:52:40 +01:00
// Str_ConvertToUpperText (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail);
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/******* Get parameter user's identificator of other user from a form ********/
/******* and get user's data ********/
/*****************************************************************************/
2016-11-16 23:19:52 +01:00
// Returns the number of users for a given ID, @nick or email
2014-12-01 23:55:08 +01:00
2014-12-12 18:50:36 +01:00
unsigned Usr_GetParamOtherUsrIDNickOrEMailAndGetUsrCods (struct ListUsrCods *ListUsrCods)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_The_ID_nickname_or_email_X_is_not_valid;
2015-10-07 19:55:13 +02:00
bool Wrong = false;
2014-12-01 23:55:08 +01:00
/***** Reset default list of users' codes *****/
ListUsrCods->NumUsrs = 0;
ListUsrCods->Lst = NULL;
2016-11-16 23:19:52 +01:00
/***** Get parameter with the plain user's ID, @nick or email of another user *****/
2014-12-01 23:55:08 +01:00
Usr_GetParamOtherUsrIDNickOrEMail ();
2016-11-16 23:19:52 +01:00
/***** Check if it's an ID, a nickname or an email address *****/
2015-10-07 19:55:13 +02:00
if (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail[0])
2014-12-01 23:55:08 +01:00
{
2015-10-07 19:55:13 +02:00
if (Nck_CheckIfNickWithArrobaIsValid (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail)) // 1: It's a nickname
2014-12-01 23:55:08 +01:00
{
2015-10-07 19:55:13 +02:00
if ((Gbl.Usrs.Other.UsrDat.UsrCod = Nck_GetUsrCodFromNickname (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail)) > 0)
{
ListUsrCods->NumUsrs = 1; // One user found
Usr_AllocateListUsrCods (ListUsrCods);
ListUsrCods->Lst[0] = Gbl.Usrs.Other.UsrDat.UsrCod;
}
2014-12-01 23:55:08 +01:00
}
2016-11-16 23:19:52 +01:00
else if (Mai_CheckIfEmailIsValid (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail)) // 2: It's an email
2014-12-01 23:55:08 +01:00
{
2015-10-07 19:55:13 +02:00
if ((Gbl.Usrs.Other.UsrDat.UsrCod = Mai_GetUsrCodFromEmail (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail)) > 0)
{
ListUsrCods->NumUsrs = 1; // One user found
Usr_AllocateListUsrCods (ListUsrCods);
ListUsrCods->Lst[0] = Gbl.Usrs.Other.UsrDat.UsrCod;
}
2014-12-01 23:55:08 +01:00
}
2016-11-16 23:19:52 +01:00
else // 3: It's not a nickname nor email
2014-12-01 23:55:08 +01:00
{
2015-10-07 19:55:13 +02:00
// Users' IDs are always stored internally in capitals and without leading zeros
Str_RemoveLeadingZeros (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail);
if (ID_CheckIfUsrIDIsValid (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail))
2014-12-01 23:55:08 +01:00
{
2016-03-21 19:52:40 +01:00
/* Allocate space for the list */
ID_ReallocateListIDs (&Gbl.Usrs.Other.UsrDat,1);
2014-12-01 23:55:08 +01:00
2017-01-15 18:02:52 +01:00
Str_Copy (Gbl.Usrs.Other.UsrDat.IDs.List[0].ID,
Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail,
2017-03-07 01:56:41 +01:00
ID_MAX_BYTES_USR_ID);
2016-03-21 19:52:40 +01:00
Str_ConvertToUpperText (Gbl.Usrs.Other.UsrDat.IDs.List[0].ID);
2014-12-01 23:55:08 +01:00
2016-03-21 19:52:40 +01:00
/* Check if user's ID exists in database */
ID_GetListUsrCodsFromUsrID (&Gbl.Usrs.Other.UsrDat,NULL,ListUsrCods,false);
2014-12-01 23:55:08 +01:00
}
2016-11-16 23:19:52 +01:00
else // Not a valid user's nickname, email or ID
2015-10-07 19:55:13 +02:00
Wrong = true;
2014-12-01 23:55:08 +01:00
}
2015-10-07 19:55:13 +02:00
}
else // Empty string
Wrong = true;
if (Wrong)
{
2016-11-16 23:19:52 +01:00
/***** String is not a valid user's nickname, email or ID *****/
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_ID_nickname_or_email_X_is_not_valid,
2015-10-07 19:55:13 +02:00
Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
return ListUsrCods->NumUsrs;
}
/*****************************************************************************/
/********* Put hidden parameter encrypted user's code of other user **********/
/*****************************************************************************/
2017-02-17 06:32:57 +01:00
void Usr_PutParamMyUsrCodEncrypted (void)
{
Usr_PutParamUsrCodEncrypted (Gbl.Usrs.Me.UsrDat.EncryptedUsrCod);
}
2015-04-02 18:39:49 +02:00
void Usr_PutParamOtherUsrCodEncrypted (void)
{
Usr_PutParamUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
}
2017-03-07 01:56:41 +01:00
void Usr_PutParamUsrCodEncrypted (const char EncryptedUsrCod[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1])
2014-12-01 23:55:08 +01:00
{
Par_PutHiddenParamString ("OtherUsrCod",EncryptedUsrCod);
}
/*****************************************************************************/
/********* Get hidden parameter encrypted user's code of other user **********/
/*****************************************************************************/
2016-01-25 14:40:57 +01:00
void Usr_GetParamOtherUsrCodEncrypted (struct UsrData *UsrDat)
2014-12-01 23:55:08 +01:00
{
2016-06-17 01:05:50 +02:00
Par_GetParToText ("OtherUsrCod",UsrDat->EncryptedUsrCod,
2017-03-07 01:56:41 +01:00
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
2016-01-25 14:40:57 +01:00
if (UsrDat->EncryptedUsrCod[0]) // If parameter exists...
2014-12-01 23:55:08 +01:00
{
2016-01-25 14:40:57 +01:00
Usr_GetUsrCodFromEncryptedUsrCod (UsrDat);
if (UsrDat->UsrCod < 0) // Check is user's code is valid
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Wrong user's code.");
}
2016-01-25 14:40:57 +01:00
else
UsrDat->UsrCod = -1L;
}
/*****************************************************************************/
/********* Get hidden parameter encrypted user's code of other user **********/
/*****************************************************************************/
void Usr_GetParamOtherUsrCodEncryptedAndGetListIDs (void)
{
Usr_GetParamOtherUsrCodEncrypted (&Gbl.Usrs.Other.UsrDat);
2016-09-23 15:03:25 +02:00
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0) // If parameter exists...
2016-01-25 14:40:57 +01:00
ID_GetListIDsFromUsrCod (&Gbl.Usrs.Other.UsrDat);
2016-09-23 15:03:25 +02:00
else // Parameter does not exist
2014-12-01 23:55:08 +01:00
{
Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail[0] = '\0';
Gbl.Usrs.Other.UsrDat.IDs.Num = 0;
Gbl.Usrs.Other.UsrDat.IDs.List = NULL;
}
}
/*****************************************************************************/
/*** Get parameter encrypted user's code of other user and get user's data ***/
/*****************************************************************************/
// Return true if user exists
bool Usr_GetParamOtherUsrCodEncryptedAndGetUsrData (void)
{
/***** Get parameter with encrypted user's code *****/
2016-01-25 14:40:57 +01:00
Usr_GetParamOtherUsrCodEncryptedAndGetListIDs ();
2014-12-01 23:55:08 +01:00
2016-01-14 01:39:02 +01:00
/***** Check if user exists and get her/his data *****/
2014-12-01 23:55:08 +01:00
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat)) // Existing user
return true;
return false;
}
/*****************************************************************************/
/** Check and get user data from session, from internal or external login... */
/*****************************************************************************/
void Usr_ChkUsrAndGetUsrData (void)
{
extern const char *Txt_The_session_has_expired_due_to_inactivity;
2016-12-04 03:50:25 +01:00
struct
{
bool PutForm;
Act_Action_t Action;
void (*FuncParams) ();
} FormLogin =
{
false,
2016-12-05 13:26:12 +01:00
ActLogIn,
2016-12-04 03:50:25 +01:00
NULL
};
2014-12-01 23:55:08 +01:00
Act_Action_t Action;
if (Gbl.Session.HasBeenDisconnected)
{
2017-02-05 22:23:41 +01:00
if (!Gbl.Action.UsesAJAX)
2014-12-01 23:55:08 +01:00
{
2016-01-17 15:10:54 +01:00
Gbl.Action.Act = ActLogOut;
2015-01-04 15:48:24 +01:00
Tab_SetCurrentTab ();
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_The_session_has_expired_due_to_inactivity);
2016-12-04 03:50:25 +01:00
FormLogin.PutForm = true;
2014-12-01 23:55:08 +01:00
}
}
else // !Gbl.Session.HasBeenDisconnected
{
/***** Check user and get user's data *****/
2016-01-17 15:10:54 +01:00
if (Gbl.Action.Act == ActCreUsrAcc)
2014-12-01 23:55:08 +01:00
{
2016-11-08 00:58:32 +01:00
/***** Create my new account and login *****/
if (Acc_CreateMyNewAccountAndLogIn ()) // User logged in
2014-12-01 23:55:08 +01:00
{
Gbl.Usrs.Me.Logged = true;
Usr_SetUsrRoleAndPrefs ();
Act_AdjustCurrentAction ();
Ses_CreateSession ();
/* Set preferences from current IP */
2015-03-14 17:39:04 +01:00
Pre_SetPrefsFromIP ();
2014-12-01 23:55:08 +01:00
/* Send message via email to confirm the new email address */
Mai_SendMailMsgToConfirmEmail ();
}
}
2016-01-17 15:10:54 +01:00
else // Gbl.Action.Act != ActCreUsrAcc
2014-12-01 23:55:08 +01:00
{
/***** Check user and get user's data *****/
if (Gbl.Session.IsOpen)
{
2016-11-08 00:58:32 +01:00
if (Usr_ChkUsrAndGetUsrDataFromSession ()) // User logged in
2014-12-01 23:55:08 +01:00
{
Gbl.Usrs.Me.Logged = true;
Usr_SetUsrRoleAndPrefs ();
2017-02-05 22:23:41 +01:00
if (Gbl.Action.IsAJAXAutoRefresh) // If refreshing ==> don't refresh LastTime in session
2014-12-01 23:55:08 +01:00
Ses_UpdateSessionLastRefreshInDB ();
else
{
Act_AdjustCurrentAction ();
Ses_UpdateSessionDataInDB ();
Con_UpdateMeInConnectedList ();
}
}
else
2016-12-04 03:50:25 +01:00
FormLogin.PutForm = true;
2014-12-01 23:55:08 +01:00
}
2016-12-05 13:26:12 +01:00
else if (Gbl.Action.Act == ActLogIn ||
2016-12-04 04:22:36 +01:00
Gbl.Action.Act == ActLogInUsrAgd) // Login using @nickname, email or ID from form
2016-09-23 15:03:25 +02:00
{
if (Usr_ChkUsrAndGetUsrDataFromDirectLogin ()) // User logged in
{
Gbl.Usrs.Me.Logged = true;
Usr_SetUsrRoleAndPrefs ();
Act_AdjustCurrentAction ();
Ses_CreateSession ();
Pre_SetPrefsFromIP (); // Set preferences from current IP
}
else
2016-12-04 03:50:25 +01:00
{
FormLogin.PutForm = true;
2016-12-04 04:22:36 +01:00
if (Gbl.Action.Act == ActLogInUsrAgd)
2016-12-04 03:50:25 +01:00
{
2016-12-04 04:22:36 +01:00
FormLogin.Action = ActLogInUsrAgd;
2016-12-05 13:26:12 +01:00
FormLogin.FuncParams = Agd_PutParamAgd;
2016-12-04 03:50:25 +01:00
}
}
2016-09-23 15:03:25 +02:00
}
2016-12-05 13:26:12 +01:00
else if (Gbl.Action.Act == ActLogInNew) // Empty account without password, login using encrypted user's code
2014-12-01 23:55:08 +01:00
{
2016-09-23 15:03:25 +02:00
/***** Get user's data *****/
Usr_GetParamOtherUsrCodEncrypted (&Gbl.Usrs.Me.UsrDat);
Usr_GetUsrCodFromEncryptedUsrCod (&Gbl.Usrs.Me.UsrDat);
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Me.UsrDat)) // User logged in
2014-12-01 23:55:08 +01:00
{
Gbl.Usrs.Me.Logged = true;
Usr_SetUsrRoleAndPrefs ();
Act_AdjustCurrentAction ();
Ses_CreateSession ();
2015-03-14 17:39:04 +01:00
Pre_SetPrefsFromIP (); // Set preferences from current IP
2014-12-01 23:55:08 +01:00
}
else
2016-12-04 03:50:25 +01:00
FormLogin.PutForm = true;
2014-12-01 23:55:08 +01:00
}
}
}
/***** If session disconnected or error in login, show form to login *****/
2016-12-04 03:50:25 +01:00
if (FormLogin.PutForm)
2014-12-01 23:55:08 +01:00
{
2016-12-04 03:50:25 +01:00
Usr_WriteFormLogin (FormLogin.Action,FormLogin.FuncParams);
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit (NULL);
}
/***** Adjust tab and action *****/
2017-02-05 22:23:41 +01:00
if (!Gbl.Action.UsesAJAX)
2014-12-01 23:55:08 +01:00
{
if (Gbl.Usrs.Me.Logged)
{
/***** Set default tab when unknown *****/
2016-01-17 15:10:54 +01:00
if (Gbl.Action.Tab == TabUnk)
2014-12-01 23:55:08 +01:00
{
2016-01-17 15:10:54 +01:00
// Don't adjust Gbl.Action.Act here
Gbl.Action.Tab = ((Gbl.Usrs.Me.UsrLast.LastTab == TabCrs) &&
2014-12-01 23:55:08 +01:00
(Gbl.CurrentCrs.Crs.CrsCod <= 0)) ? TabSys :
Gbl.Usrs.Me.UsrLast.LastTab;
2015-01-04 15:48:24 +01:00
Tab_DisableIncompatibleTabs ();
2014-12-01 23:55:08 +01:00
}
Usr_UpdateMyLastData ();
Crs_UpdateCrsLast ();
}
2016-01-17 15:10:54 +01:00
else if (Gbl.Action.Act == ActUnk) // No user logged and unknown action
2014-12-01 23:55:08 +01:00
Act_AdjustActionWhenNoUsrLogged ();
/***** When I change to another tab, go to the first option allowed *****/
2016-01-17 15:10:54 +01:00
if (Gbl.Action.Act == ActMnu)
2014-12-01 23:55:08 +01:00
{
if (Gbl.Usrs.Me.Logged)
{
2016-06-03 13:42:28 +02:00
if ((Action = MFU_GetMyLastActionInCurrentTab ()) == ActUnk)
2015-12-08 01:47:48 +01:00
Action = Mnu_GetFirstActionAvailableInCurrentTab ();
2014-12-01 23:55:08 +01:00
}
else
2015-12-08 01:47:48 +01:00
Action = Mnu_GetFirstActionAvailableInCurrentTab ();
2014-12-01 23:55:08 +01:00
if (Action != ActUnk)
2016-01-17 15:10:54 +01:00
Gbl.Action.Act = Action;
2014-12-01 23:55:08 +01:00
}
}
}
/*****************************************************************************/
/************** Check user and get user's data when direct login *************/
/*****************************************************************************/
// Returns true if user logged in successfully
// Returns false if user not logged in
static bool Usr_ChkUsrAndGetUsrDataFromDirectLogin (void)
{
struct ListUsrCods ListUsrCods;
bool PasswordCorrect = false;
2015-10-07 19:55:13 +02:00
/***** Check if user typed anything *****/
if (!Gbl.Usrs.Me.UsrIdLogin)
{
2016-03-01 03:16:29 +01:00
Usr_ShowAlertUsrDoesNotExistsOrWrongPassword ();
2015-10-07 19:55:13 +02:00
return false;
}
if (!Gbl.Usrs.Me.UsrIdLogin[0])
{
2016-03-01 03:16:29 +01:00
Usr_ShowAlertUsrDoesNotExistsOrWrongPassword ();
2015-10-07 19:55:13 +02:00
return false;
}
2016-11-16 23:19:52 +01:00
/***** Check if user has typed his user's ID, his nickname or his email address *****/
2014-12-01 23:55:08 +01:00
if (Nck_CheckIfNickWithArrobaIsValid (Gbl.Usrs.Me.UsrIdLogin)) // 1: It's a nickname
{
// User is trying to log using his/her nickname
if ((Gbl.Usrs.Me.UsrDat.UsrCod = Nck_GetUsrCodFromNickname (Gbl.Usrs.Me.UsrIdLogin)) <= 0)
{
2016-03-01 03:16:29 +01:00
Usr_ShowAlertUsrDoesNotExistsOrWrongPassword ();
2014-12-01 23:55:08 +01:00
return false;
}
}
2016-11-16 23:19:52 +01:00
else if (Mai_CheckIfEmailIsValid (Gbl.Usrs.Me.UsrIdLogin)) // 2: It's an email
2014-12-01 23:55:08 +01:00
{
2016-11-16 23:19:52 +01:00
// User is trying to log using his/her email
2014-12-01 23:55:08 +01:00
if ((Gbl.Usrs.Me.UsrDat.UsrCod = Mai_GetUsrCodFromEmail (Gbl.Usrs.Me.UsrIdLogin)) <= 0)
{
2016-03-01 03:16:29 +01:00
Usr_ShowAlertUsrDoesNotExistsOrWrongPassword ();
2014-12-01 23:55:08 +01:00
return false;
}
}
2016-11-16 23:19:52 +01:00
else // 3: It's not a nickname nor email
2014-12-01 23:55:08 +01:00
{
// Users' IDs are always stored internally in capitals and without leading zeros
Str_RemoveLeadingZeros (Gbl.Usrs.Me.UsrIdLogin);
if (ID_CheckIfUsrIDIsValid (Gbl.Usrs.Me.UsrIdLogin))
{
/***** Allocate space for the list *****/
ID_ReallocateListIDs (&Gbl.Usrs.Me.UsrDat,1);
2017-01-15 18:02:52 +01:00
Str_Copy (Gbl.Usrs.Me.UsrDat.IDs.List[0].ID,Gbl.Usrs.Me.UsrIdLogin,
2017-03-07 01:56:41 +01:00
ID_MAX_BYTES_USR_ID);
2014-12-01 23:55:08 +01:00
Str_ConvertToUpperText (Gbl.Usrs.Me.UsrDat.IDs.List[0].ID);
/* Check if user's ID exists in database, and get user's data */
if (ID_GetListUsrCodsFromUsrID (&Gbl.Usrs.Me.UsrDat,
Gbl.Usrs.Me.LoginEncryptedPassword, // Check password
&ListUsrCods,false))
{
if (ListUsrCods.NumUsrs == 1)
{
/* Free memory used for list of users' codes found for this ID */
Usr_FreeListUsrCods (&ListUsrCods);
PasswordCorrect = true;
}
else // ListUsrCods.NumUsrs > 1
{
/* Free memory used for list of users' codes found for this ID */
Usr_FreeListUsrCods (&ListUsrCods);
2016-03-01 03:16:29 +01:00
Usr_ShowAlertThereAreMoreThanOneUsr ();
2014-12-01 23:55:08 +01:00
return false;
}
}
else if (ID_GetListUsrCodsFromUsrID (&Gbl.Usrs.Me.UsrDat,
NULL, // Don't check password
&ListUsrCods,false))
{
if (ListUsrCods.NumUsrs == 1)
{
/* Free memory used for list of users' codes found for this ID */
Usr_FreeListUsrCods (&ListUsrCods);
if (Pwd_CheckPendingPassword ())
{
Pwd_AssignMyPendingPasswordToMyCurrentPassword ();
PasswordCorrect = true;
}
else
{
2016-03-01 03:16:29 +01:00
Usr_ShowAlertUsrDoesNotExistsOrWrongPassword ();
2014-12-01 23:55:08 +01:00
return false;
}
}
else // ListUsrCods.NumUsrs > 1
{
/* Free memory used for list of users' codes found for this ID */
Usr_FreeListUsrCods (&ListUsrCods);
2016-03-01 03:16:29 +01:00
Usr_ShowAlertThereAreMoreThanOneUsr ();
2014-12-01 23:55:08 +01:00
return false;
}
}
else // No users found for this ID
{
2016-03-01 03:16:29 +01:00
Usr_ShowAlertUsrDoesNotExistsOrWrongPassword ();
2014-12-01 23:55:08 +01:00
return false;
}
}
2016-11-16 23:19:52 +01:00
else // String is not a valid user's nickname, email or ID
2014-12-01 23:55:08 +01:00
{
2016-03-01 03:16:29 +01:00
Usr_ShowAlertUsrDoesNotExistsOrWrongPassword ();
2014-12-01 23:55:08 +01:00
return false;
}
}
/***** Get user's data *****/
Usr_GetAllUsrDataFromUsrCod (&Gbl.Usrs.Me.UsrDat);
/***** Check password *****/
/* Check user's password:
is the encrypted password typed by user or coming from the session
the same as that stored in database? */
if (!PasswordCorrect)
PasswordCorrect = Pwd_CheckCurrentPassword ();
if (!PasswordCorrect) // If my password is not correct...
{
if (Pwd_CheckPendingPassword ())
Pwd_AssignMyPendingPasswordToMyCurrentPassword ();
else
{
2016-03-01 03:16:29 +01:00
Usr_ShowAlertUsrDoesNotExistsOrWrongPassword ();
2014-12-01 23:55:08 +01:00
return false;
}
}
return true;
}
/*****************************************************************************/
/******** Check user and get user's data when the session is open ************/
/*****************************************************************************/
static bool Usr_ChkUsrAndGetUsrDataFromSession (void)
{
/***** Session is open and user's code is get from session *****/
Gbl.Usrs.Me.UsrDat.UsrCod = Gbl.Session.UsrCod;
/* Check if user exists in database, and get his/her data */
if (!Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Me.UsrDat))
{
2016-03-01 03:16:29 +01:00
Usr_ShowAlertUsrDoesNotExistsOrWrongPassword ();
2014-12-01 23:55:08 +01:00
return false;
}
/* Check user's password:
the encrypted password typed by user or coming from the session
is the same as the stored in database? */
if (!Pwd_CheckCurrentPassword ()) // If my password is not correct...
{
2016-03-01 03:16:29 +01:00
Usr_ShowAlertUsrDoesNotExistsOrWrongPassword ();
2014-12-01 23:55:08 +01:00
return false;
}
return true;
}
/*****************************************************************************/
2016-03-01 03:16:29 +01:00
/** Show alert indicating that user does not exists or password is incorrect */
/*****************************************************************************/
static void Usr_ShowAlertUsrDoesNotExistsOrWrongPassword (void)
{
extern const char *Txt_The_user_does_not_exist_or_password_is_incorrect;
2016-12-04 03:50:25 +01:00
// Gbl.Action.Act = ActFrmLogIn;
// Tab_SetCurrentTab ();
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_The_user_does_not_exist_or_password_is_incorrect);
2016-03-01 03:16:29 +01:00
}
/*****************************************************************************/
/****** Show alert indicating that more than one user share the same ID ******/
/*****************************************************************************/
static void Usr_ShowAlertThereAreMoreThanOneUsr (void)
{
extern const char *Txt_There_are_more_than_one_user_with_the_ID_X_Please_type_a_nick_or_email;
Gbl.Action.Act = ActFrmLogIn;
Tab_SetCurrentTab ();
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_There_are_more_than_one_user_with_the_ID_X_Please_type_a_nick_or_email,
2016-03-01 03:16:29 +01:00
Gbl.Usrs.Me.UsrIdLogin);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Gbl.Alert.Txt);
2016-03-01 03:16:29 +01:00
}
/*****************************************************************************/
2014-12-01 23:55:08 +01:00
/**** Check if users exists, if his password is correct, get his data... *****/
/*****************************************************************************/
static void Usr_SetUsrRoleAndPrefs (void)
{
extern const char *The_ThemeId[The_NUM_THEMES];
extern const char *Ico_IconSetId[Ico_NUM_ICON_SETS];
2015-02-01 20:17:24 +01:00
bool ICanBeInsAdm = false;
bool ICanBeCtrAdm = false;
bool ICanBeDegAdm = false;
2014-12-01 23:55:08 +01:00
2015-02-01 20:17:24 +01:00
// In this point I am logged
2014-12-01 23:55:08 +01:00
2015-12-07 23:13:08 +01:00
/***** Set my language if unknown *****/
if (Gbl.Usrs.Me.UsrDat.Prefs.Language == Txt_LANGUAGE_UNKNOWN) // I have not chosen language
2017-05-07 18:06:34 +02:00
Lan_UpdateMyLanguageToCurrentLanguage (); // Update my language in database
2015-12-07 23:13:08 +01:00
2014-12-01 23:55:08 +01:00
/***** Set preferences from my preferences *****/
2015-11-21 21:00:18 +01:00
Gbl.Prefs.FirstDayOfWeek = Gbl.Usrs.Me.UsrDat.Prefs.FirstDayOfWeek;
2017-05-04 11:03:44 +02:00
Gbl.Prefs.DateFormat = Gbl.Usrs.Me.UsrDat.Prefs.DateFormat;
2015-11-27 12:57:56 +01:00
Gbl.Prefs.Menu = Gbl.Usrs.Me.UsrDat.Prefs.Menu;
Gbl.Prefs.SideCols = Gbl.Usrs.Me.UsrDat.Prefs.SideCols;
2015-11-21 21:00:18 +01:00
2014-12-01 23:55:08 +01:00
Gbl.Prefs.Theme = Gbl.Usrs.Me.UsrDat.Prefs.Theme;
sprintf (Gbl.Prefs.PathTheme,"%s/%s/%s",
Gbl.Prefs.IconsURL,Cfg_ICON_FOLDER_THEMES,
The_ThemeId[Gbl.Prefs.Theme]);
Gbl.Prefs.IconSet = Gbl.Usrs.Me.UsrDat.Prefs.IconSet;
sprintf (Gbl.Prefs.PathIconSet,"%s/%s/%s",
Gbl.Prefs.IconsURL,Cfg_ICON_FOLDER_ICON_SETS,
Ico_IconSetId[Gbl.Prefs.IconSet]);
/***** Get my last data *****/
Usr_GetMyLastData ();
2016-12-05 13:26:12 +01:00
if (Gbl.Action.Act == ActLogIn ||
Gbl.Action.Act == ActLogInNew) // If I just logged in...
2014-12-01 23:55:08 +01:00
{
/***** WhatToSearch is stored in session,
but in login it is got from user's last data *****/
Gbl.Search.WhatToSearch = Gbl.Usrs.Me.UsrLast.WhatToSearch;
/***** If no course selected, go to my last visited course *****/
if (Gbl.CurrentCrs.Crs.CrsCod <= 0 &&
Gbl.Usrs.Me.UsrLast.LastCrs > 0)
{
Gbl.CurrentCrs.Crs.CrsCod = Gbl.Usrs.Me.UsrLast.LastCrs;
/* Initialize again current course, degree, centre... */
2016-11-14 17:26:32 +01:00
Hie_InitHierarchy ();
2014-12-01 23:55:08 +01:00
/* Get again my role in this course */
2014-12-12 20:25:00 +01:00
Gbl.Usrs.Me.UsrDat.RoleInCurrentCrsDB = Rol_GetRoleInCrs (Gbl.CurrentCrs.Crs.CrsCod,Gbl.Usrs.Me.UsrDat.UsrCod);
2014-12-01 23:55:08 +01:00
}
}
/***** Set the user's role I am logged *****/
2016-12-13 13:32:19 +01:00
Rol_GetRolesInAllCrssIfNotYetGot (&Gbl.Usrs.Me.UsrDat); // Get my roles if not yet got
2016-12-15 02:22:47 +01:00
Gbl.Usrs.Me.MaxRole = Rol_GetMaxRole ((unsigned) Gbl.Usrs.Me.UsrDat.Roles);
2015-04-07 21:44:24 +02:00
Gbl.Usrs.Me.LoggedRole = (Gbl.Usrs.Me.RoleFromSession == Rol_UNKNOWN) ? // If no logged role retrieved from session...
2014-12-01 23:55:08 +01:00
Gbl.Usrs.Me.MaxRole : // ...set current logged role to maximum role in database
Gbl.Usrs.Me.RoleFromSession; // Get logged role from session
/***** Construct the path to my directory *****/
Usr_ConstructPathUsr (Gbl.Usrs.Me.UsrDat.UsrCod,Gbl.Usrs.Me.PathDir);
/***** Check if my photo exists and create a link to it ****/
2016-07-08 12:43:48 +02:00
Gbl.Usrs.Me.MyPhotoExists = Pho_BuildLinkToPhoto (&Gbl.Usrs.Me.UsrDat,Gbl.Usrs.Me.PhotoURL);
2014-12-01 23:55:08 +01:00
2015-02-01 20:17:24 +01:00
/***** Check if I am administrator of current institution/centre/degree *****/
if (Gbl.CurrentIns.Ins.InsCod > 0)
{
/* Check if I am and administrator of current institution */
ICanBeInsAdm = Usr_CheckIfUsrIsAdm (Gbl.Usrs.Me.UsrDat.UsrCod,
Sco_SCOPE_INS,
Gbl.CurrentIns.Ins.InsCod);
if (Gbl.CurrentCtr.Ctr.CtrCod > 0)
{
/* Check if I am and administrator of current centre */
ICanBeCtrAdm = Usr_CheckIfUsrIsAdm (Gbl.Usrs.Me.UsrDat.UsrCod,
Sco_SCOPE_CTR,
Gbl.CurrentCtr.Ctr.CtrCod);
if (Gbl.CurrentDeg.Deg.DegCod > 0)
/* Check if I am and administrator of current degree */
ICanBeDegAdm = Usr_CheckIfUsrIsAdm (Gbl.Usrs.Me.UsrDat.UsrCod,
Sco_SCOPE_DEG,
Gbl.CurrentDeg.Deg.DegCod);
}
}
2015-02-01 16:08:58 +01:00
2014-12-01 23:55:08 +01:00
/***** Check if I belong to current course *****/
if (Gbl.CurrentCrs.Crs.CrsCod > 0)
Gbl.Usrs.Me.IBelongToCurrentCrs = Usr_CheckIfIBelongToCrs (Gbl.CurrentCrs.Crs.CrsCod);
2015-01-20 20:03:38 +01:00
else
Gbl.Usrs.Me.IBelongToCurrentCrs = false;
if (Gbl.Usrs.Me.IBelongToCurrentCrs)
2015-09-17 11:21:49 +02:00
Gbl.Usrs.Me.UsrDat.Accepted = Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.CurrentCrs.Crs.CrsCod,
true);
else
Gbl.Usrs.Me.UsrDat.Accepted = false;
2015-01-20 20:03:38 +01:00
/***** Check if I belong to current degree *****/
if (Gbl.CurrentDeg.Deg.DegCod > 0)
{
if (Gbl.Usrs.Me.IBelongToCurrentCrs)
Gbl.Usrs.Me.IBelongToCurrentDeg = true;
else
Gbl.Usrs.Me.IBelongToCurrentDeg = Usr_CheckIfIBelongToDeg (Gbl.CurrentDeg.Deg.DegCod);
}
else
Gbl.Usrs.Me.IBelongToCurrentDeg = false;
/***** Check if I belong to current centre *****/
if (Gbl.CurrentCtr.Ctr.CtrCod > 0)
{
if (Gbl.Usrs.Me.IBelongToCurrentDeg)
Gbl.Usrs.Me.IBelongToCurrentCtr = true;
else
Gbl.Usrs.Me.IBelongToCurrentCtr = Usr_CheckIfIBelongToCtr (Gbl.CurrentCtr.Ctr.CtrCod);
}
else
Gbl.Usrs.Me.IBelongToCurrentCtr = false;
/***** Check if I belong to current institution *****/
if (Gbl.CurrentIns.Ins.InsCod > 0)
{
if (Gbl.Usrs.Me.IBelongToCurrentCtr)
Gbl.Usrs.Me.IBelongToCurrentIns = true;
else
Gbl.Usrs.Me.IBelongToCurrentIns = Usr_CheckIfIBelongToIns (Gbl.CurrentIns.Ins.InsCod);
}
else
Gbl.Usrs.Me.IBelongToCurrentIns = false;
2014-12-01 23:55:08 +01:00
/***** Build my list of available roles for current course *****/
if (Gbl.CurrentCrs.Crs.CrsCod > 0)
{
if (Gbl.Usrs.Me.IBelongToCurrentCrs)
2016-03-03 01:10:54 +01:00
Gbl.Usrs.Me.AvailableRoles = (1 << Gbl.Usrs.Me.UsrDat.RoleInCurrentCrsDB);
2015-04-07 21:44:24 +02:00
else if (Gbl.Usrs.Me.MaxRole >= Rol_STUDENT)
Gbl.Usrs.Me.AvailableRoles = (1 << Rol_VISITOR);
2014-12-01 23:55:08 +01:00
else
2015-04-07 21:44:24 +02:00
Gbl.Usrs.Me.AvailableRoles = (1 << Rol__GUEST_);
2014-12-01 23:55:08 +01:00
}
else // No course selected
Gbl.Usrs.Me.AvailableRoles = (1 << Gbl.Usrs.Me.MaxRole);
2015-02-01 20:17:24 +01:00
if (ICanBeInsAdm)
2015-04-07 21:44:24 +02:00
Gbl.Usrs.Me.AvailableRoles |= (1 << Rol_INS_ADM);
2015-02-01 20:17:24 +01:00
if (ICanBeCtrAdm)
2015-04-07 21:44:24 +02:00
Gbl.Usrs.Me.AvailableRoles |= (1 << Rol_CTR_ADM);
2015-02-01 20:17:24 +01:00
if (ICanBeDegAdm)
2015-04-07 21:44:24 +02:00
Gbl.Usrs.Me.AvailableRoles |= (1 << Rol_DEG_ADM);
2014-12-01 23:55:08 +01:00
if (Usr_CheckIfUsrIsSuperuser (Gbl.Usrs.Me.UsrDat.UsrCod))
2015-04-07 21:44:24 +02:00
Gbl.Usrs.Me.AvailableRoles |= (1 << Rol_SYS_ADM);
2014-12-01 23:55:08 +01:00
/***** Check if the role I am logged is now available for me *****/
if (!(Gbl.Usrs.Me.AvailableRoles & (1 << Gbl.Usrs.Me.LoggedRole))) // Current type I am logged is not available for me
/* Set the lowest role available for me */
2015-04-07 21:44:24 +02:00
for (Gbl.Usrs.Me.LoggedRole = Rol_UNKNOWN;
2014-12-01 23:55:08 +01:00
Gbl.Usrs.Me.LoggedRole < Rol_NUM_ROLES;
Gbl.Usrs.Me.LoggedRole++)
if (Gbl.Usrs.Me.AvailableRoles & (1 << Gbl.Usrs.Me.LoggedRole))
break;
}
/*****************************************************************************/
2015-04-02 13:38:05 +02:00
/************** Show forms to log out and to change my role ******************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2015-04-02 13:38:05 +02:00
void Usr_ShowFormsLogoutAndRole (void)
2014-12-01 23:55:08 +01:00
{
2016-11-13 12:35:01 +01:00
extern const char *Hlp_PROFILE_Session_role;
2015-07-28 00:16:09 +02:00
extern const char *The_ClassForm[The_NUM_THEMES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Log_out;
2016-11-13 12:35:01 +01:00
extern const char *Txt_Role;
2016-11-13 13:01:44 +01:00
extern const char *Txt_You_are_now_LOGGED_IN_as_X;
2014-12-01 23:55:08 +01:00
extern const char *Txt_logged[Usr_NUM_SEXS];
2015-03-12 14:45:40 +01:00
extern const char *Txt_ROLES_SINGUL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2016-11-13 12:35:01 +01:00
extern const char *Txt_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2014-12-01 23:55:08 +01:00
/***** Link to log out *****/
2015-04-02 14:22:21 +02:00
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
2017-04-17 19:03:21 +02:00
Lay_PutContextualLink (ActLogOut,NULL,NULL,
2016-07-01 16:32:42 +02:00
"logout-red64x64.png",
Txt_Log_out,Txt_Log_out,
NULL);
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</div>");
2014-12-01 23:55:08 +01:00
/***** Write message with my new logged role *****/
2016-11-13 12:35:01 +01:00
if (Gbl.Usrs.Me.RoleHasChanged)
{
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_You_are_now_LOGGED_IN_as_X,
2016-11-13 12:35:01 +01:00
Txt_logged[Gbl.Usrs.Me.UsrDat.Sex],
Txt_ROLES_SINGUL_abc[Gbl.Usrs.Me.LoggedRole][Gbl.Usrs.Me.UsrDat.Sex]);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt);
2016-11-13 12:35:01 +01:00
}
/***** Start frame *****/
Lay_StartRoundFrame (NULL,Txt_Role,NULL,Hlp_PROFILE_Session_role);
2014-12-01 23:55:08 +01:00
/***** Put a form to change my role *****/
2016-11-13 12:52:07 +01:00
if (Rol_GetNumAvailableRoles () == 1)
2016-12-27 16:45:37 +01:00
fprintf (Gbl.F.Out,"<span class=\"DAT\">%s:&nbsp;</span>"
"<span class=\"DAT_N_BOLD\">%s</span>",
2016-11-13 12:52:07 +01:00
Txt_Role,
Txt_ROLES_SINGUL_Abc[Gbl.Usrs.Me.LoggedRole][Gbl.Usrs.Me.UsrDat.Sex]);
else
2014-12-01 23:55:08 +01:00
{
2016-12-27 16:45:37 +01:00
fprintf (Gbl.F.Out,"<label class=\"%s\">%s:&nbsp;",
2015-07-28 00:16:09 +02:00
The_ClassForm[Gbl.Prefs.Theme],Txt_Role);
2016-12-10 18:32:35 +01:00
Rol_PutFormToChangeMyRole ();
2016-12-27 16:45:37 +01:00
fprintf (Gbl.F.Out,"</label>");
2014-12-01 23:55:08 +01:00
}
2016-11-13 12:35:01 +01:00
/***** End frame *****/
Lay_EndRoundFrame ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2014-12-12 18:50:36 +01:00
/******* Check a user's code and get all user's data from user's code ********/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2014-12-12 18:50:36 +01:00
// Input: UsrDat->UsrCod must hold a valid user code
// Output: When true ==> UsrDat will hold all user's data
// When false ==> UsrDat is reset, except user's code
2014-12-01 23:55:08 +01:00
2014-12-12 18:50:36 +01:00
bool Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (struct UsrData *UsrDat)
2014-12-01 23:55:08 +01:00
{
2014-12-12 18:50:36 +01:00
/***** Check if a user exists having this user's code *****/
if (Usr_ChkIfUsrCodExists (UsrDat->UsrCod))
{
/* Get user's data */
Usr_GetAllUsrDataFromUsrCod (UsrDat);
return true;
}
2014-12-01 23:55:08 +01:00
2014-12-12 18:50:36 +01:00
/***** No user's code found *****/
UsrDat->UsrIDNickOrEmail[0] = '\0';
Usr_ResetUsrDataExceptUsrCodAndIDs (UsrDat);
return false;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2014-12-12 18:50:36 +01:00
/********* Update my last accessed course, tab and time in database **********/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2014-12-12 18:50:36 +01:00
void Usr_UpdateMyLastData (void)
2014-12-01 23:55:08 +01:00
{
2014-12-12 18:50:36 +01:00
char Query[256];
2014-12-01 23:55:08 +01:00
/***** Check if it exists an entry for me *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"SELECT COUNT(*) FROM usr_last WHERE UsrCod=%ld",
2014-12-01 23:55:08 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod);
if (DB_QueryCOUNT (Query,"can not get last user's click"))
{
/***** Update my last accessed course, tab and time of click in database *****/
2015-01-22 00:17:12 +01:00
// WhatToSearch, LastAccNotif remain unchanged
2017-03-24 01:09:27 +01:00
sprintf (Query,"UPDATE usr_last SET LastCrs=%ld,LastTab=%u,LastTime=NOW()"
" WHERE UsrCod=%ld",
2014-12-01 23:55:08 +01:00
Gbl.CurrentCrs.Crs.CrsCod,
2016-01-17 15:10:54 +01:00
(unsigned) Gbl.Action.Tab,
2014-12-01 23:55:08 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryUPDATE (Query,"can not update last user's data");
}
else
Usr_InsertMyLastData ();
}
/*****************************************************************************/
/*************** Create new entry for my last data in database ***************/
/*****************************************************************************/
static void Usr_InsertMyLastData (void)
{
char Query[256];
/***** Insert my last accessed course, tab and time of click in database *****/
2016-04-30 17:16:41 +02:00
sprintf (Query,"INSERT INTO usr_last"
2016-05-01 16:35:53 +02:00
" (UsrCod,WhatToSearch,LastCrs,LastTab,LastTime,LastAccNotif)"
2016-04-30 17:16:41 +02:00
" VALUES"
2017-03-24 01:09:27 +01:00
" (%ld,%u,%ld,%u,NOW(),FROM_UNIXTIME(%ld))",
2014-12-01 23:55:08 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod,
2016-04-30 17:16:41 +02:00
(unsigned) Sch_SEARCH_ALL,
2014-12-01 23:55:08 +01:00
Gbl.CurrentCrs.Crs.CrsCod,
2016-04-30 17:16:41 +02:00
(unsigned) Gbl.Action.Tab,
(long) (time_t) 0); // The user never accessed to notifications
2014-12-01 23:55:08 +01:00
DB_QueryINSERT (Query,"can not insert last user's data");
}
2016-06-15 00:34:00 +02:00
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-06-15 20:04:15 +02:00
/*********** Write a row of a table with the main data of a user *************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2017-03-08 03:48:23 +01:00
#define Usr_MAX_BYTES_BG_COLOR (16 - 1)
2017-01-15 22:58:26 +01:00
2016-06-15 20:04:15 +02:00
void Usr_WriteRowUsrMainData (unsigned NumUsr,struct UsrData *UsrDat,
2016-04-23 13:23:09 +02:00
bool PutCheckBoxToSelectUsr)
2014-12-01 23:55:08 +01:00
{
2017-03-30 11:20:06 +02:00
extern const char *Txt_Enrolment_confirmed;
extern const char *Txt_Enrolment_not_confirmed;
2017-03-08 03:48:23 +01:00
char BgColor[Usr_MAX_BYTES_BG_COLOR + 1];
2017-01-15 22:58:26 +01:00
char PhotoURL[PATH_MAX + 1];
2014-12-01 23:55:08 +01:00
bool ShowPhoto;
2016-06-15 19:54:43 +02:00
bool UsrIsTheMsgSender = PutCheckBoxToSelectUsr &&
(UsrDat->UsrCod == Gbl.Usrs.Other.UsrDat.UsrCod);
2016-10-28 10:03:37 +02:00
struct Instit Ins;
2014-12-01 23:55:08 +01:00
/***** Start row *****/
fprintf (Gbl.F.Out,"<tr>");
/***** Checkbox to select user *****/
// Two colors are used alternatively to better distinguish the rows
2016-06-16 11:28:20 +02:00
if (UsrIsTheMsgSender)
2017-01-17 03:10:43 +01:00
Str_Copy (BgColor,"LIGHT_GREEN",
2017-03-08 03:48:23 +01:00
Usr_MAX_BYTES_BG_COLOR);
2016-06-16 11:28:20 +02:00
else
sprintf (BgColor,"COLOR%u",Gbl.RowEvenOdd);
2015-03-13 00:16:02 +01:00
if (PutCheckBoxToSelectUsr)
2014-12-12 18:50:36 +01:00
{
2015-09-04 17:10:27 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE %s\">",BgColor);
2015-09-30 23:10:15 +02:00
Usr_PutCheckboxToSelectUser (UsrDat,UsrIsTheMsgSender);
2014-12-12 18:50:36 +01:00
fprintf (Gbl.F.Out,"</td>");
}
2014-12-01 23:55:08 +01:00
2017-03-30 11:20:06 +02:00
/***** User has accepted enrolment? *****/
2014-12-12 18:50:36 +01:00
fprintf (Gbl.F.Out,"<td class=\"");
if (UsrIsTheMsgSender)
fprintf (Gbl.F.Out,"BM_SEL");
else
2015-09-03 00:59:03 +02:00
fprintf (Gbl.F.Out,"BM%u",Gbl.RowEvenOdd);
2014-12-12 18:50:36 +01:00
fprintf (Gbl.F.Out,"\">"
2015-07-22 18:59:44 +02:00
"<img src=\"%s/%s16x16.gif\""
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />"
2014-12-01 23:55:08 +01:00
"</td>",
2014-12-12 18:50:36 +01:00
Gbl.Prefs.IconsURL,
UsrDat->Accepted ? "ok_on" :
"tr",
2017-03-30 11:20:06 +02:00
UsrDat->Accepted ? Txt_Enrolment_confirmed :
Txt_Enrolment_not_confirmed,
UsrDat->Accepted ? Txt_Enrolment_confirmed :
Txt_Enrolment_not_confirmed);
2014-12-01 23:55:08 +01:00
2016-06-15 19:54:43 +02:00
/***** Write number of user in the list *****/
2015-09-04 17:10:27 +02:00
fprintf (Gbl.F.Out,"<td class=\"%s RIGHT_MIDDLE %s\">"
2016-06-16 11:28:20 +02:00
"%u"
2014-12-26 16:55:46 +01:00
"</td>",
2016-06-16 11:28:20 +02:00
UsrDat->Accepted ? "USR_LIST_NUM_N" :
"USR_LIST_NUM",
2014-12-26 16:55:46 +01:00
BgColor,
2014-12-12 18:50:36 +01:00
NumUsr);
2014-12-01 23:55:08 +01:00
if (Gbl.Usrs.Listing.WithPhotos)
{
2016-06-15 19:54:43 +02:00
/***** Show user's photo *****/
2016-06-16 11:28:20 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE %s\">",BgColor);
2017-01-28 15:58:46 +01:00
ShowPhoto = Pho_ShowingUsrPhotoIsAllowed (UsrDat,PhotoURL);
2014-12-30 15:14:43 +01:00
Pho_ShowUsrPhoto (UsrDat,ShowPhoto ? PhotoURL :
NULL,
2016-01-14 10:31:09 +01:00
"PHOTO21x28",Pho_ZOOM,false);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>");
}
2016-06-15 19:54:43 +02:00
/****** Write user's IDs ******/
2015-09-04 17:10:27 +02:00
fprintf (Gbl.F.Out,"<td class=\"%s LEFT_MIDDLE %s\">",
2014-12-01 23:55:08 +01:00
UsrDat->Accepted ? "DAT_SMALL_N" :
2014-12-26 16:55:46 +01:00
"DAT_SMALL",
BgColor);
2017-05-09 20:56:02 +02:00
ID_WriteUsrIDs (UsrDat,NULL);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>");
2016-06-15 19:54:43 +02:00
/***** Write rest of main user's data *****/
2014-12-01 23:55:08 +01:00
Ins.InsCod = UsrDat->InsCod;
2015-12-09 19:51:17 +01:00
Ins_GetDataOfInstitutionByCod (&Ins,Ins_GET_BASIC_DATA);
2016-07-27 14:58:26 +02:00
Usr_WriteMainUsrDataExceptUsrID (UsrDat,BgColor);
2016-07-30 00:21:35 +02:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE %s\">",BgColor);
Ins_DrawInstitutionLogoWithLink (&Ins,25);
2016-07-27 14:58:26 +02:00
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
/***** End row *****/
fprintf (Gbl.F.Out,"</tr>");
}
/*****************************************************************************/
/*************** Write a row of a table with the data of a guest *************/
/*****************************************************************************/
static void Usr_WriteRowGstAllData (struct UsrData *UsrDat)
{
2017-01-28 15:58:46 +01:00
char PhotoURL[PATH_MAX + 1];
2014-12-01 23:55:08 +01:00
bool ShowPhoto;
2016-10-28 10:03:37 +02:00
struct Instit Ins;
2014-12-01 23:55:08 +01:00
struct Centre Ctr;
struct Department Dpt;
/***** Start row *****/
fprintf (Gbl.F.Out,"<tr>");
if (Gbl.Usrs.Listing.WithPhotos)
{
/***** Show guest's photo *****/
2015-09-03 17:14:30 +02:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE COLOR%u\">",
Gbl.RowEvenOdd);
2017-01-28 15:58:46 +01:00
ShowPhoto = Pho_ShowingUsrPhotoIsAllowed (UsrDat,PhotoURL);
2014-12-30 15:14:43 +01:00
Pho_ShowUsrPhoto (UsrDat,ShowPhoto ? PhotoURL :
NULL,
2016-01-14 10:31:09 +01:00
"PHOTO21x28",Pho_NO_ZOOM,false);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>");
}
/****** Write user's ID ******/
2015-09-03 17:14:30 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT_SMALL LEFT_MIDDLE COLOR%u\">",
Gbl.RowEvenOdd);
2017-05-09 20:56:02 +02:00
ID_WriteUsrIDs (UsrDat,NULL);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"&nbsp;</td>");
/***** Write rest of guest's main data *****/
Ins.InsCod = UsrDat->InsCod;
2015-12-09 19:51:17 +01:00
Ins_GetDataOfInstitutionByCod (&Ins,Ins_GET_BASIC_DATA);
2016-07-27 14:58:26 +02:00
Usr_WriteMainUsrDataExceptUsrID (UsrDat,Gbl.ColorRows[Gbl.RowEvenOdd]);
2016-07-25 16:08:25 +02:00
Usr_WriteEmail (UsrDat,Gbl.ColorRows[Gbl.RowEvenOdd]);
2016-07-27 14:58:26 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],
Ins.FullName,
NULL,true,false);
2014-12-01 23:55:08 +01:00
/***** Write the rest of the data of the guest *****/
if (UsrDat->Tch.CtrCod > 0)
{
Ctr.CtrCod = UsrDat->Tch.CtrCod;
Ctr_GetDataOfCentreByCod (&Ctr);
}
2015-09-03 17:14:30 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],
2014-12-01 23:55:08 +01:00
UsrDat->Tch.CtrCod > 0 ? Ctr.FullName :
"&nbsp;",
NULL,true,false);
if (UsrDat->Tch.DptCod > 0)
{
Dpt.DptCod = UsrDat->Tch.DptCod;
Dpt_GetDataOfDepartmentByCod (&Dpt);
}
2015-09-03 17:14:30 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],
2014-12-01 23:55:08 +01:00
UsrDat->Tch.DptCod > 0 ? Dpt.FullName :
"&nbsp;",
NULL,true,false);
2015-09-03 17:14:30 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],
2014-12-01 23:55:08 +01:00
UsrDat->Tch.Office[0] ? UsrDat->Tch.Office :
"&nbsp;",
NULL,true,false);
2015-09-03 17:14:30 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],
2014-12-01 23:55:08 +01:00
UsrDat->Tch.OfficePhone[0] ? UsrDat->Tch.OfficePhone :
"&nbsp;",
NULL,true,false);
2015-09-03 17:14:30 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],
2014-12-01 23:55:08 +01:00
UsrDat->LocalAddress[0] ? UsrDat->LocalAddress :
"&nbsp;",
NULL,true,false);
2015-09-03 17:14:30 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],
2014-12-01 23:55:08 +01:00
UsrDat->LocalPhone[0] ? UsrDat->LocalPhone :
"&nbsp;",
NULL,true,false);
2015-09-03 17:14:30 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],
2014-12-01 23:55:08 +01:00
UsrDat->FamilyAddress[0] ? UsrDat->FamilyAddress :
"&nbsp;",
NULL,true,false);
2015-09-03 17:14:30 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],
2014-12-01 23:55:08 +01:00
UsrDat->FamilyPhone[0] ? UsrDat->FamilyPhone :
"&nbsp;",
NULL,true,false);
2015-09-03 17:14:30 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],
2014-12-01 23:55:08 +01:00
UsrDat->OriginPlace[0] ? UsrDat->OriginPlace :
"&nbsp;",
NULL,true,false);
2015-09-03 17:14:30 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],
2014-12-01 23:55:08 +01:00
UsrDat->StrBirthday[0] ? UsrDat->StrBirthday :
"&nbsp;",
NULL,true,false);
/***** End row *****/
fprintf (Gbl.F.Out,"</tr>");
}
/*****************************************************************************/
/************ Write a row of a table with the data of a student **************/
/*****************************************************************************/
2016-06-16 11:28:20 +02:00
static void Usr_WriteRowStdAllData (struct UsrData *UsrDat,char *GroupNames)
2014-12-01 23:55:08 +01:00
{
2017-01-28 15:58:46 +01:00
char PhotoURL[PATH_MAX + 1];
2014-12-01 23:55:08 +01:00
bool ShowPhoto;
unsigned NumGrpTyp,NumField;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2017-01-15 22:58:26 +01:00
char Text[Cns_MAX_BYTES_TEXT + 1];
2016-10-28 10:03:37 +02:00
struct Instit Ins;
2015-04-07 21:44:24 +02:00
bool ShowData = (Gbl.Usrs.Me.LoggedRole == Rol_TEACHER && UsrDat->Accepted) ||
2016-04-23 13:23:09 +02:00
Gbl.Usrs.Me.LoggedRole >= Rol_DEG_ADM;
2014-12-01 23:55:08 +01:00
/***** Start row *****/
fprintf (Gbl.F.Out,"<tr>");
if (Gbl.Usrs.Listing.WithPhotos)
{
/***** Show student's photo *****/
2015-09-03 17:14:30 +02:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE COLOR%u\">",
Gbl.RowEvenOdd);
2017-01-28 15:58:46 +01:00
ShowPhoto = Pho_ShowingUsrPhotoIsAllowed (UsrDat,PhotoURL);
2014-12-30 15:14:43 +01:00
Pho_ShowUsrPhoto (UsrDat,ShowPhoto ? PhotoURL :
NULL,
2016-01-14 10:31:09 +01:00
"PHOTO21x28",Pho_NO_ZOOM,false);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>");
}
/****** Write user's ID ******/
2015-09-03 17:14:30 +02:00
fprintf (Gbl.F.Out,"<td class=\"%s LEFT_MIDDLE COLOR%u\">",
2014-12-01 23:55:08 +01:00
UsrDat->Accepted ? "DAT_SMALL_N" :
2014-12-26 16:55:46 +01:00
"DAT_SMALL",
2015-09-03 17:14:30 +02:00
Gbl.RowEvenOdd);
2017-05-09 20:56:02 +02:00
ID_WriteUsrIDs (UsrDat,NULL);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"&nbsp;</td>");
/***** Write rest of main student's data *****/
Ins.InsCod = UsrDat->InsCod;
2015-12-09 19:51:17 +01:00
Ins_GetDataOfInstitutionByCod (&Ins,Ins_GET_BASIC_DATA);
2016-07-27 14:58:26 +02:00
Usr_WriteMainUsrDataExceptUsrID (UsrDat,Gbl.ColorRows[Gbl.RowEvenOdd]);
2016-07-25 16:08:25 +02:00
Usr_WriteEmail (UsrDat,Gbl.ColorRows[Gbl.RowEvenOdd]);
2016-07-27 14:58:26 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],
Ins.FullName,
NULL,true,UsrDat->Accepted);
2014-12-01 23:55:08 +01:00
/***** Write the rest of the data of the student *****/
2015-09-03 17:14:30 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],
2015-09-04 17:43:18 +02:00
UsrDat->LocalAddress[0] ? (ShowData ? UsrDat->LocalAddress :
2014-12-01 23:55:08 +01:00
"********") :
"&nbsp;",
NULL,true,UsrDat->Accepted);
2015-09-03 17:14:30 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],
2015-09-04 17:43:18 +02:00
UsrDat->LocalPhone[0] ? (ShowData ? UsrDat->LocalPhone :
2014-12-01 23:55:08 +01:00
"********") :
"&nbsp;",
NULL,true,UsrDat->Accepted);
2015-09-03 17:14:30 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],
2014-12-01 23:55:08 +01:00
UsrDat->FamilyAddress[0] ? (ShowData ? UsrDat->FamilyAddress :
"********") :
"&nbsp;",
NULL,true,UsrDat->Accepted);
2015-09-03 17:14:30 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],
2015-09-04 17:43:18 +02:00
UsrDat->FamilyPhone[0] ? (ShowData ? UsrDat->FamilyPhone :
2014-12-01 23:55:08 +01:00
"********") :
"&nbsp;",
NULL,true,UsrDat->Accepted);
2015-09-03 17:14:30 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],
2015-09-04 17:43:18 +02:00
UsrDat->OriginPlace[0] ? (ShowData ? UsrDat->OriginPlace :
2014-12-01 23:55:08 +01:00
"********") :
"&nbsp;",
NULL,true,UsrDat->Accepted);
2015-09-03 17:14:30 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],
2015-09-04 17:43:18 +02:00
UsrDat->StrBirthday[0] ? (ShowData ? UsrDat->StrBirthday :
2014-12-01 23:55:08 +01:00
"********") :
"&nbsp;",
NULL,true,UsrDat->Accepted);
2015-02-01 20:17:24 +01:00
if (Gbl.Scope.Current == Sco_SCOPE_CRS)
2014-12-01 23:55:08 +01:00
{
/***** Write the groups a the que pertenece the student *****/
for (NumGrpTyp = 0;
NumGrpTyp < Gbl.CurrentCrs.Grps.GrpTypes.Num;
NumGrpTyp++)
if (Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].NumGrps) // If current course tiene groups of este type
{
2017-01-16 01:51:01 +01:00
Grp_GetNamesGrpsStdBelongsTo (Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].GrpTypCod,
UsrDat->UsrCod,GroupNames);
2015-09-03 17:14:30 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],GroupNames,NULL,true,UsrDat->Accepted);
2014-12-01 23:55:08 +01:00
}
/***** Fields of the record dependientes of the course *****/
for (NumField = 0;
NumField < Gbl.CurrentCrs.Records.LstFields.Num;
NumField++)
{
/* Get the text of the field */
if (Rec_GetFieldFromCrsRecord (UsrDat->UsrCod,Gbl.CurrentCrs.Records.LstFields.Lst[NumField].FieldCod,&mysql_res))
{
row = mysql_fetch_row (mysql_res);
2017-01-17 03:10:43 +01:00
Str_Copy (Text,row[0],
Cns_MAX_BYTES_TEXT);
2014-12-01 23:55:08 +01:00
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
Text,Cns_MAX_BYTES_TEXT,false); // Se convierte of HTML a HTML respetuoso
}
else
Text[0] = '\0';
2015-09-03 17:14:30 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],Text,NULL,false,UsrDat->Accepted);
2014-12-01 23:55:08 +01:00
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
}
}
/***** End row *****/
fprintf (Gbl.F.Out,"</tr>");
}
/*****************************************************************************/
/*** Write a row of a table with the data of a teacher or an administrator ***/
/*****************************************************************************/
2016-06-16 11:28:20 +02:00
static void Usr_WriteRowTchAllData (struct UsrData *UsrDat)
2014-12-01 23:55:08 +01:00
{
2017-01-28 15:58:46 +01:00
char PhotoURL[PATH_MAX + 1];
2014-12-01 23:55:08 +01:00
bool ShowPhoto;
2016-10-28 10:03:37 +02:00
struct Instit Ins;
2014-12-01 23:55:08 +01:00
bool ItsMe = (Gbl.Usrs.Me.UsrDat.UsrCod == UsrDat->UsrCod);
bool ShowData = (ItsMe || UsrDat->Accepted ||
2015-04-07 21:44:24 +02:00
Gbl.Usrs.Me.LoggedRole == Rol_DEG_ADM ||
Gbl.Usrs.Me.LoggedRole == Rol_SYS_ADM);
2014-12-01 23:55:08 +01:00
struct Centre Ctr;
struct Department Dpt;
/***** Start row *****/
fprintf (Gbl.F.Out,"<tr>");
if (Gbl.Usrs.Listing.WithPhotos)
{
/***** Show teacher's photo *****/
2015-09-03 17:14:30 +02:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE COLOR%u\">",
Gbl.RowEvenOdd);
2017-01-28 15:58:46 +01:00
ShowPhoto = Pho_ShowingUsrPhotoIsAllowed (UsrDat,PhotoURL);
2014-12-30 15:14:43 +01:00
Pho_ShowUsrPhoto (UsrDat,ShowPhoto ? PhotoURL :
NULL,
2016-01-14 10:31:09 +01:00
"PHOTO21x28",Pho_NO_ZOOM,false);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>");
}
/****** Write the user's ID ******/
2015-09-03 17:14:30 +02:00
fprintf (Gbl.F.Out,"<td class=\"%s LEFT_MIDDLE COLOR%u\">",
2014-12-01 23:55:08 +01:00
UsrDat->Accepted ? "DAT_SMALL_N" :
2014-12-26 16:55:46 +01:00
"DAT_SMALL",
2015-09-03 17:14:30 +02:00
Gbl.RowEvenOdd);
2017-05-09 20:56:02 +02:00
ID_WriteUsrIDs (UsrDat,NULL);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"&nbsp;</td>");
/***** Write rest of main teacher's data *****/
Ins.InsCod = UsrDat->InsCod;
2015-12-09 19:51:17 +01:00
Ins_GetDataOfInstitutionByCod (&Ins,Ins_GET_BASIC_DATA);
2016-07-27 14:58:26 +02:00
Usr_WriteMainUsrDataExceptUsrID (UsrDat,Gbl.ColorRows[Gbl.RowEvenOdd]);
2016-07-25 16:08:25 +02:00
Usr_WriteEmail (UsrDat,Gbl.ColorRows[Gbl.RowEvenOdd]);
2016-07-27 14:58:26 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],
Ins.FullName,
NULL,true,UsrDat->Accepted);
2014-12-01 23:55:08 +01:00
/***** Write the rest of teacher's data *****/
if (ShowData && UsrDat->Tch.CtrCod > 0)
{
Ctr.CtrCod = UsrDat->Tch.CtrCod;
Ctr_GetDataOfCentreByCod (&Ctr);
}
2015-09-03 17:14:30 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],
2014-12-01 23:55:08 +01:00
(ShowData && UsrDat->Tch.CtrCod > 0) ? Ctr.FullName :
"&nbsp;",
NULL,true,UsrDat->Accepted);
if (ShowData && UsrDat->Tch.DptCod > 0)
{
Dpt.DptCod = UsrDat->Tch.DptCod;
Dpt_GetDataOfDepartmentByCod (&Dpt);
}
2015-09-03 17:14:30 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],
2014-12-01 23:55:08 +01:00
(ShowData && UsrDat->Tch.DptCod > 0) ? Dpt.FullName :
"&nbsp;",
NULL,true,UsrDat->Accepted);
2015-09-03 17:14:30 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],
2014-12-01 23:55:08 +01:00
(ShowData && UsrDat->Tch.Office[0]) ? UsrDat->Tch.Office :
"&nbsp;",
NULL,true,UsrDat->Accepted);
2015-09-03 17:14:30 +02:00
Usr_WriteUsrData (Gbl.ColorRows[Gbl.RowEvenOdd],
2014-12-01 23:55:08 +01:00
(ShowData && UsrDat->Tch.OfficePhone[0]) ? UsrDat->Tch.OfficePhone :
"&nbsp;",
NULL,true,UsrDat->Accepted);
fprintf (Gbl.F.Out,"</tr>");
}
/*****************************************************************************/
2016-04-23 13:23:09 +02:00
/********** Write a row of a table with the data of an administrator *********/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-06-16 11:28:20 +02:00
static void Usr_WriteRowAdmData (unsigned NumUsr,struct UsrData *UsrDat)
2014-12-01 23:55:08 +01:00
{
2017-01-28 15:58:46 +01:00
char PhotoURL[PATH_MAX + 1];
2014-12-01 23:55:08 +01:00
bool ShowPhoto;
2016-10-28 10:03:37 +02:00
struct Instit Ins;
2014-12-01 23:55:08 +01:00
/***** Start row *****/
fprintf (Gbl.F.Out,"<tr>");
/***** Write number of user *****/
2016-06-16 18:32:12 +02:00
fprintf (Gbl.F.Out,"<td class=\"USR_LIST_NUM_N CENTER_MIDDLE COLOR%u\">"
"%u"
2014-12-26 16:55:46 +01:00
"</td>",
2015-09-03 17:14:30 +02:00
Gbl.RowEvenOdd,NumUsr);
2014-12-01 23:55:08 +01:00
if (Gbl.Usrs.Listing.WithPhotos)
{
/***** Show administrator's photo *****/
2015-09-03 17:14:30 +02:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE COLOR%u\">",
Gbl.RowEvenOdd);
2017-01-28 15:58:46 +01:00
ShowPhoto = Pho_ShowingUsrPhotoIsAllowed (UsrDat,PhotoURL);
2014-12-30 15:14:43 +01:00
Pho_ShowUsrPhoto (UsrDat,ShowPhoto ? PhotoURL :
NULL,
2016-01-14 10:31:09 +01:00
"PHOTO21x28",Pho_ZOOM,false);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>");
}
/****** Write the user's ID ******/
2015-09-03 17:14:30 +02:00
fprintf (Gbl.F.Out,"<td class=\"%s LEFT_MIDDLE COLOR%u\">",
2014-12-01 23:55:08 +01:00
UsrDat->Accepted ? "DAT_SMALL_N" :
2014-12-26 16:55:46 +01:00
"DAT_SMALL",
2015-09-03 17:14:30 +02:00
Gbl.RowEvenOdd);
2017-05-09 20:56:02 +02:00
ID_WriteUsrIDs (UsrDat,NULL);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"&nbsp;</td>");
/***** Write rest of main administrator's data *****/
Ins.InsCod = UsrDat->InsCod;
2015-12-09 19:51:17 +01:00
Ins_GetDataOfInstitutionByCod (&Ins,Ins_GET_BASIC_DATA);
2016-07-27 14:58:26 +02:00
Usr_WriteMainUsrDataExceptUsrID (UsrDat,Gbl.ColorRows[Gbl.RowEvenOdd]);
2016-07-30 00:21:35 +02:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE %s\">",Gbl.ColorRows[Gbl.RowEvenOdd]);
Ins_DrawInstitutionLogoWithLink (&Ins,25);
2016-07-27 14:58:26 +02:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
2014-12-01 23:55:08 +01:00
/***** Write degrees which are administrated by this administrator *****/
2016-11-14 16:47:46 +01:00
Hie_GetAndWriteInsCtrDegAdminBy (UsrDat->UsrCod,
2015-11-23 13:14:13 +01:00
Gbl.Usrs.Listing.WithPhotos ? Usr_NUM_MAIN_FIELDS_DATA_ADM :
Usr_NUM_MAIN_FIELDS_DATA_ADM-1);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************* Write main data of a user *************************/
/*****************************************************************************/
2016-04-23 13:23:09 +02:00
static void Usr_WriteMainUsrDataExceptUsrID (struct UsrData *UsrDat,
2016-07-27 14:58:26 +02:00
const char *BgColor)
2014-12-01 23:55:08 +01:00
{
Usr_WriteUsrData (BgColor,
UsrDat->Surname1[0] ? UsrDat->Surname1 :
"&nbsp;",
NULL,true,UsrDat->Accepted);
Usr_WriteUsrData (BgColor,
UsrDat->Surname2[0] ? UsrDat->Surname2 :
"&nbsp;",
NULL,true,UsrDat->Accepted);
Usr_WriteUsrData (BgColor,
UsrDat->FirstName[0] ? UsrDat->FirstName :
"&nbsp;",
NULL,true,UsrDat->Accepted);
2016-07-25 16:08:25 +02:00
}
/*****************************************************************************/
2016-11-16 23:19:52 +01:00
/**************************** Write user's email *****************************/
2016-07-25 16:08:25 +02:00
/*****************************************************************************/
static void Usr_WriteEmail (struct UsrData *UsrDat,const char *BgColor)
{
bool ShowEmail;
2017-03-13 13:17:53 +01:00
char MailLink[7 + Cns_MAX_BYTES_EMAIL_ADDRESS + 1]; // mailto:mail_address
2016-07-25 16:08:25 +02:00
2016-04-23 13:23:09 +02:00
if (UsrDat->Email[0])
{
2017-01-27 15:21:01 +01:00
ShowEmail = Mai_ICanSeeOtherUsrEmail (UsrDat);
if (ShowEmail)
sprintf (MailLink,"mailto:%s",UsrDat->Email);
2016-04-23 13:23:09 +02:00
}
else
ShowEmail = false;
2014-12-01 23:55:08 +01:00
Usr_WriteUsrData (BgColor,
UsrDat->Email[0] ? (ShowEmail ? UsrDat->Email :
"********") :
"&nbsp;",
ShowEmail ? MailLink :
NULL,
true,UsrDat->Accepted);
}
/*****************************************************************************/
/********************* Write a cell with data of a user **********************/
/*****************************************************************************/
2016-04-23 13:23:09 +02:00
static void Usr_WriteUsrData (const char *BgColor,
const char *Data,const char *Link,
bool NonBreak,bool Accepted)
2014-12-01 23:55:08 +01:00
{
2017-03-06 10:11:10 +01:00
/***** Start table cell *****/
2015-09-04 17:10:27 +02:00
fprintf (Gbl.F.Out,"<td class=\"%s LEFT_MIDDLE %s\">",
2014-12-01 23:55:08 +01:00
Accepted ? (NonBreak ? "DAT_SMALL_NOBR_N" :
"DAT_SMALL_N") :
(NonBreak ? "DAT_SMALL_NOBR" :
2014-12-26 16:55:46 +01:00
"DAT_SMALL"),
BgColor);
2017-03-06 10:11:10 +01:00
/***** Container to limit length *****/
fprintf (Gbl.F.Out,"<div class=\"USR_DAT\">");
/***** Start link *****/
if (Link)
2016-07-27 14:58:26 +02:00
fprintf (Gbl.F.Out,"<a href=\"%s\" class=\"%s\" target=\"_blank\">",
Link,
Accepted ? "DAT_SMALL_NOBR_N" :
"DAT_SMALL_NOBR");
2017-03-06 10:11:10 +01:00
/***** Write data *****/
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"%s",Data);
if (NonBreak)
fprintf (Gbl.F.Out,"&nbsp;");
2017-03-06 10:11:10 +01:00
/***** End link *****/
if (Link)
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</a>");
2017-03-06 10:11:10 +01:00
/***** End container and table cell *****/
fprintf (Gbl.F.Out,"</div>"
"</td>");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************* Get number of users with a role in a course *******************/
/*****************************************************************************/
unsigned Usr_GetNumUsrsInCrs (Rol_Role_t Role,long CrsCod)
{
2017-03-13 20:32:03 +01:00
char Query[256];
2014-12-01 23:55:08 +01:00
/***** Get the number of teachers in a course from database ******/
sprintf (Query,"SELECT COUNT(*) FROM crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE CrsCod=%ld AND Role=%u",
2014-12-01 23:55:08 +01:00
CrsCod,(unsigned) Role);
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of users in a course");
}
/*****************************************************************************/
/*********** Count how many users with a role belong to a degree *************/
/*****************************************************************************/
unsigned Usr_GetNumUsrsInCrssOfDeg (Rol_Role_t Role,long DegCod)
{
char Query[512];
2015-12-09 19:51:17 +01:00
/***** Get the number of users in courses of a degree from database ******/
2014-12-01 23:55:08 +01:00
sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
" FROM courses,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE courses.DegCod=%ld"
2014-12-01 23:55:08 +01:00
" AND courses.CrsCod=crs_usr.CrsCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u",
2014-12-01 23:55:08 +01:00
DegCod,(unsigned) Role);
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of users in courses of a degree");
}
/*****************************************************************************/
/************ Count how many users with a role belong to a centre ************/
/*****************************************************************************/
2015-12-09 22:05:21 +01:00
// Here Rol_UNKNOWN means students or teachers
2014-12-01 23:55:08 +01:00
unsigned Usr_GetNumUsrsInCrssOfCtr (Rol_Role_t Role,long CtrCod)
{
char Query[512];
2015-12-09 19:51:17 +01:00
/***** Get the number of users in courses of a centre from database ******/
2015-12-09 22:05:21 +01:00
if (Role == Rol_UNKNOWN) // Any user
sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
" FROM degrees,courses,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE degrees.CtrCod=%ld"
2015-12-09 22:05:21 +01:00
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod",
CtrCod);
else
2015-12-14 12:13:41 +01:00
// This query is very slow.
// It's a bad idea to get number of teachers or students for a big list of centres
2015-12-09 22:05:21 +01:00
sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
" FROM degrees,courses,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE degrees.CtrCod=%ld"
2015-12-09 22:05:21 +01:00
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u",
2015-12-09 22:05:21 +01:00
CtrCod,(unsigned) Role);
2014-12-01 23:55:08 +01:00
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of users in courses of a centre");
}
/*****************************************************************************/
/********* Count how many users with a role belong to an institution *********/
/*****************************************************************************/
2015-12-09 19:51:17 +01:00
// Here Rol_UNKNOWN means students or teachers
2014-12-01 23:55:08 +01:00
unsigned Usr_GetNumUsrsInCrssOfIns (Rol_Role_t Role,long InsCod)
{
char Query[512];
2015-12-09 22:05:21 +01:00
/***** Get the number of users in courses of an institution from database ******/
2015-12-09 19:51:17 +01:00
if (Role == Rol_UNKNOWN) // Any user
sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
" FROM centres,degrees,courses,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE centres.InsCod=%ld"
2015-12-09 19:51:17 +01:00
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod",
InsCod);
else
2015-12-14 12:13:41 +01:00
// This query is very slow.
// It's a bad idea to get number of teachers or students for a big list of institutions
2015-12-09 19:51:17 +01:00
sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
" FROM centres,degrees,courses,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE centres.InsCod=%ld"
2015-12-09 19:51:17 +01:00
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u",
2015-12-09 19:51:17 +01:00
InsCod,(unsigned) Role);
2014-12-01 23:55:08 +01:00
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of users in courses of an institution");
}
/*****************************************************************************/
/****** Count how many users with a role belong to courses of a country ******/
/*****************************************************************************/
2015-11-17 01:22:57 +01:00
// Here Rol_UNKNOWN means students or teachers
2015-12-09 19:51:17 +01:00
2014-12-01 23:55:08 +01:00
unsigned Usr_GetNumUsrsInCrssOfCty (Rol_Role_t Role,long CtyCod)
{
char Query[512];
2015-12-09 19:51:17 +01:00
/***** Get the number of users in courses of a country from database ******/
2015-11-17 01:22:57 +01:00
if (Role == Rol_UNKNOWN) // Any user
sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
" FROM institutions,centres,degrees,courses,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE institutions.CtyCod=%ld"
2015-11-17 01:22:57 +01:00
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod",
CtyCod);
2014-12-01 23:55:08 +01:00
else
2015-12-14 12:13:41 +01:00
// This query is very slow.
// It's a bad idea to get number of teachers or students for a big list of countries
2015-11-17 01:22:57 +01:00
sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
" FROM institutions,centres,degrees,courses,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE institutions.CtyCod=%ld"
2015-11-17 01:22:57 +01:00
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u",
2015-11-17 01:22:57 +01:00
CtyCod,(unsigned) Role);
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of users in courses of a country");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******** Get the user's code of a random student from current course ********/
/*****************************************************************************/
// Returns user's code or -1 if no user found
long Usr_GetRamdomStdFromCrs (long CrsCod)
{
char Query[256];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long UsrCod = -1L; // -1 means user not found
/***** Get a random student from current course from database *****/
sprintf (Query,"SELECT UsrCod FROM crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE CrsCod=%ld AND Role=%u"
2014-12-01 23:55:08 +01:00
" ORDER BY RAND(NOW()) LIMIT 1",
2015-04-07 21:44:24 +02:00
CrsCod,(unsigned) Rol_STUDENT);
2014-12-01 23:55:08 +01:00
if (DB_QuerySELECT (Query,&mysql_res,"can not get a random student from the current course"))
{
/***** Get user code *****/
row = mysql_fetch_row (mysql_res);
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
}
2015-03-16 14:05:16 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2014-12-01 23:55:08 +01:00
return UsrCod;
}
/*****************************************************************************/
/*********** Get the user's code of a random student from a group ************/
/*****************************************************************************/
// Returns user's code or -1 if no user found
long Usr_GetRamdomStdFromGrp (long GrpCod)
{
char Query[512];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long UsrCod = -1L; // -1 means user not found
/***** Get a random student from a group from database *****/
sprintf (Query,"SELECT crs_grp_usr.UsrCod FROM crs_grp_usr,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE crs_grp_usr.GrpCod=%ld"
2016-06-23 21:18:11 +02:00
" AND crs_grp_usr.UsrCod=crs_usr.UsrCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u ORDER BY RAND(NOW()) LIMIT 1",
2015-04-07 21:44:24 +02:00
GrpCod,(unsigned) Rol_STUDENT);
2014-12-01 23:55:08 +01:00
if (DB_QuerySELECT (Query,&mysql_res,"can not get a random student from a group"))
{
/***** Get user code *****/
row = mysql_fetch_row (mysql_res);
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
return UsrCod;
}
/*****************************************************************************/
/**** Get number of teachers from the current institution in a department ****/
/*****************************************************************************/
unsigned Usr_GetNumTchsCurrentInsInDepartment (long DptCod)
{
2017-03-13 20:32:03 +01:00
char Query[512];
2014-12-01 23:55:08 +01:00
/***** Get the number of teachers
from the current institution in a department *****/
sprintf (Query,"SELECT COUNT(DISTINCT usr_data.UsrCod)"
" FROM usr_data,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE usr_data.InsCod=%ld AND usr_data.DptCod=%ld"
" AND usr_data.UsrCod=crs_usr.UsrCod AND crs_usr.Role=%u",
2015-04-07 21:44:24 +02:00
Gbl.CurrentIns.Ins.InsCod,DptCod,(unsigned) Rol_TEACHER);
2014-12-01 23:55:08 +01:00
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of teachers in a department");
}
/*****************************************************************************/
2015-12-09 19:51:17 +01:00
/*********** Get number of users who claim to belong to a country ************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2015-12-09 19:51:17 +01:00
unsigned Usr_GetNumUsrsWhoClaimToBelongToCty (long CtyCod)
2014-12-01 23:55:08 +01:00
{
2015-12-09 19:51:17 +01:00
char Query[128];
/***** Get the number of users in a country from database *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"SELECT COUNT(UsrCod) FROM usr_data WHERE CtyCod=%ld",
2015-12-09 19:51:17 +01:00
CtyCod);
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of users in a country");
}
/*****************************************************************************/
/******** Get number of users who claim to belong to an institution **********/
/*****************************************************************************/
unsigned Usr_GetNumUsrsWhoClaimToBelongToIns (long InsCod)
{
char Query[128];
2014-12-01 23:55:08 +01:00
/***** Get the number of users in an institution from database *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"SELECT COUNT(UsrCod) FROM usr_data WHERE InsCod=%ld",
2015-12-09 19:51:17 +01:00
InsCod);
2014-12-01 23:55:08 +01:00
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of users in an institution");
}
2015-12-09 22:05:21 +01:00
/*****************************************************************************/
/*********** Get number of users who claim to belong to a centre *************/
/*****************************************************************************/
unsigned Usr_GetNumUsrsWhoClaimToBelongToCtr (long CtrCod)
{
char Query[128];
/***** Get the number of users in a centre from database *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"SELECT COUNT(UsrCod) FROM usr_data WHERE CtrCod=%ld",
2015-12-09 22:05:21 +01:00
CtrCod);
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of users in a centre");
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/******************* Get number of teachers in a centre **********************/
/*****************************************************************************/
unsigned Usr_GetNumberOfTeachersInCentre (long CtrCod)
{
2017-03-13 20:32:03 +01:00
char Query[512];
2014-12-01 23:55:08 +01:00
/***** Get the number of teachers in a centre from database *****/
sprintf (Query,"SELECT COUNT(DISTINCT usr_data.UsrCod)"
" FROM usr_data,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE usr_data.CtrCod=%ld"
" AND usr_data.UsrCod=crs_usr.UsrCod AND crs_usr.Role=%u",
2015-04-07 21:44:24 +02:00
CtrCod,(unsigned) Rol_TEACHER);
2014-12-01 23:55:08 +01:00
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of teachers in a centre");
}
/*****************************************************************************/
/******* Build query to get list with data of users in current course ********/
/*****************************************************************************/
2017-01-16 01:51:01 +01:00
static void Usr_BuildQueryToGetUsrsLstCrs (Rol_Role_t Role,
2017-03-08 03:48:23 +01:00
char Query[Usr_MAX_BYTES_QUERY_GET_LIST_USRS + 1])
2014-12-01 23:55:08 +01:00
{
unsigned NumPositiveCods = 0;
unsigned NumNegativeCods = 0;
2017-01-28 15:58:46 +01:00
char LongStr[1 + 10 + 1];
2014-12-01 23:55:08 +01:00
unsigned NumGrpSel;
long GrpCod;
unsigned NumGrpTyp;
bool *AddStdsWithoutGroupOf;
2016-07-25 20:42:37 +02:00
const char *QueryFields =
"usr_data.UsrCod,"
"usr_data.EncryptedUsrCod,"
2017-01-27 01:02:52 +01:00
"usr_data.Password,"
2016-07-25 20:42:37 +02:00
"usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName,"
"usr_data.Sex,"
"usr_data.Photo,"
"usr_data.PhotoVisibility,"
2017-03-01 14:53:18 +01:00
"usr_data.CtyCod,"
2016-07-25 20:55:25 +02:00
"usr_data.InsCod,"
2016-07-26 01:03:41 +02:00
"crs_usr.Role,"
2016-07-25 20:42:37 +02:00
"crs_usr.Accepted";
2016-07-25 20:24:07 +02:00
/*
2016-07-26 01:03:41 +02:00
row[ 0]: usr_data.UsrCod
row[ 1]: usr_data.EncryptedUsrCod
2017-01-27 01:02:52 +01:00
row[ 2]: usr_data.Password (used to check if a teacher can edit user's data)
row[ 3]: usr_data.Surname1
row[ 4]: usr_data.Surname2
row[ 5]: usr_data.FirstName
row[ 6]: usr_data.Sex
row[ 7]: usr_data.Photo
row[ 8]: usr_data.PhotoVisibility
2017-03-01 14:53:18 +01:00
row[ 9]: usr_data.CtyCod
row[10]: usr_data.InsCod
row[11]: crs_usr.Role (only if Scope == Sco_SCOPE_CRS)
row[12]: crs_usr.Accepted (only if Scope == Sco_SCOPE_CRS)
2016-07-25 20:24:07 +02:00
*/
2014-12-01 23:55:08 +01:00
/***** If there are no groups selected, don't do anything *****/
2015-04-07 21:44:24 +02:00
if (Role == Rol_STUDENT &&
2014-12-01 23:55:08 +01:00
(!Gbl.Usrs.ClassPhoto.AllGroups &&
!Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps))
{
Query[0] = '\0';
return;
}
/***** Create query for users in the course *****/
2016-01-17 15:10:54 +01:00
if (Gbl.Action.Act == ActReqMsgUsr) // Selecting users to write a message
2016-07-25 20:42:37 +02:00
sprintf (Query,"SELECT %s FROM crs_usr,usr_data"
2017-03-24 01:09:27 +01:00
" WHERE crs_usr.CrsCod=%ld"
" AND crs_usr.Role=%u"
2014-12-01 23:55:08 +01:00
" AND crs_usr.UsrCod NOT IN"
2017-03-24 01:09:27 +01:00
" (SELECT ToUsrCod FROM msg_banned WHERE FromUsrCod=%ld)"
2014-12-01 23:55:08 +01:00
" AND crs_usr.UsrCod=usr_data.UsrCod", // Do not get banned users
2016-07-25 20:42:37 +02:00
QueryFields,
2014-12-01 23:55:08 +01:00
Gbl.CurrentCrs.Crs.CrsCod,(unsigned) Role,
Gbl.Usrs.Me.UsrDat.UsrCod);
else
2016-07-25 20:42:37 +02:00
sprintf (Query,"SELECT %s FROM crs_usr,usr_data"
2017-03-24 01:09:27 +01:00
" WHERE crs_usr.CrsCod=%ld"
" AND crs_usr.Role=%u"
2014-12-01 23:55:08 +01:00
" AND crs_usr.UsrCod=usr_data.UsrCod",
2016-07-25 20:42:37 +02:00
QueryFields,
2014-12-01 23:55:08 +01:00
Gbl.CurrentCrs.Crs.CrsCod,(unsigned) Role);
/***** Select users in selected groups (only for students) *****/
2015-04-07 21:44:24 +02:00
if (Role == Rol_STUDENT && !Gbl.Usrs.ClassPhoto.AllGroups)
2014-12-01 23:55:08 +01:00
{
/***** Get list of groups types in current course *****/
Grp_GetListGrpTypesInThisCrs (Grp_ONLY_GROUP_TYPES_WITH_GROUPS);
/***** Allocate memory for list of booleans AddStdsWithoutGroupOf *****/
if ((AddStdsWithoutGroupOf = (bool *) calloc (Gbl.CurrentCrs.Grps.GrpTypes.Num,sizeof (bool))) == NULL)
Lay_ShowErrorAndExit ("Not enough memory to store types of group.");
/***** Initialize vector of booleans that indicates whether it's necessary add to the list
the students who don't belong to any group of each type *****/
for (NumGrpTyp = 0;
NumGrpTyp < Gbl.CurrentCrs.Grps.GrpTypes.Num;
NumGrpTyp++)
AddStdsWithoutGroupOf[NumGrpTyp] = false;
/***** Create query with the students who belong to the groups selected *****/
if (Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps) // If there are groups selected...
{
/* Check if there are positive and negative codes in the list */
for (NumGrpSel = 0;
NumGrpSel < Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps;
NumGrpSel++)
2017-01-19 20:55:31 +01:00
if ((GrpCod = Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrpSel]) > 0)
2014-12-01 23:55:08 +01:00
NumPositiveCods++;
else
for (NumGrpTyp = 0;
NumGrpTyp < Gbl.CurrentCrs.Grps.GrpTypes.Num;
NumGrpTyp++)
if (Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].GrpTypCod == -GrpCod)
{
AddStdsWithoutGroupOf[NumGrpTyp] = true;
break;
}
/* If there are positive codes, add the students who belong to groups with those codes */
if (NumPositiveCods)
{
2017-01-16 01:51:01 +01:00
Str_Concat (Query," AND (crs_usr.UsrCod IN"
" (SELECT DISTINCT UsrCod FROM crs_grp_usr WHERE",
2017-03-08 03:48:23 +01:00
Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
2014-12-01 23:55:08 +01:00
NumPositiveCods = 0;
for (NumGrpSel = 0;
NumGrpSel < Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps;
NumGrpSel++)
2017-01-19 20:55:31 +01:00
if ((GrpCod = Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrpSel]) > 0)
2014-12-01 23:55:08 +01:00
{
2017-01-16 01:51:01 +01:00
Str_Concat (Query,NumPositiveCods ? " OR GrpCod='" :
" GrpCod='",
2017-03-08 03:48:23 +01:00
Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
2014-12-01 23:55:08 +01:00
sprintf (LongStr,"%ld",GrpCod);
2017-01-17 03:33:05 +01:00
Str_Concat (Query,LongStr,
2017-03-08 03:48:23 +01:00
Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
2017-01-17 03:33:05 +01:00
Str_Concat (Query,"'",
2017-03-08 03:48:23 +01:00
Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
2014-12-01 23:55:08 +01:00
NumPositiveCods++;
}
2017-01-17 03:33:05 +01:00
Str_Concat (Query,")",
2017-03-08 03:48:23 +01:00
Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
2014-12-01 23:55:08 +01:00
}
}
/***** Create a query with the students who don't belong to any group *****/
for (NumGrpTyp = 0;
NumGrpTyp < Gbl.CurrentCrs.Grps.GrpTypes.Num;
NumGrpTyp++)
if (AddStdsWithoutGroupOf[NumGrpTyp])
{
if (NumPositiveCods || NumNegativeCods)
2017-01-17 03:33:05 +01:00
Str_Concat (Query," OR ",
2017-03-08 03:48:23 +01:00
Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
2014-12-01 23:55:08 +01:00
else
2017-01-17 03:33:05 +01:00
Str_Concat (Query," AND (",
2017-03-08 03:48:23 +01:00
Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
2014-12-01 23:55:08 +01:00
/* Select all the students of the course who don't belong to any group of type GrpTypCod */
2017-01-16 01:51:01 +01:00
Str_Concat (Query,"crs_usr.UsrCod NOT IN"
" (SELECT DISTINCT crs_grp_usr.UsrCod"
" FROM crs_grp,crs_grp_usr"
" WHERE crs_grp.GrpTypCod='",
2017-03-08 03:48:23 +01:00
Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
2014-12-01 23:55:08 +01:00
sprintf (LongStr,"%ld",Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].GrpTypCod);
2017-01-17 03:33:05 +01:00
Str_Concat (Query,LongStr,
2017-03-08 03:48:23 +01:00
Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
2017-01-16 01:51:01 +01:00
Str_Concat (Query,"' AND crs_grp.GrpCod=crs_grp_usr.GrpCod)",
2017-03-08 03:48:23 +01:00
Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
2014-12-01 23:55:08 +01:00
NumNegativeCods++;
}
if (NumPositiveCods ||
NumNegativeCods)
2017-01-17 03:33:05 +01:00
Str_Concat (Query,")",
2017-03-08 03:48:23 +01:00
Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
2014-12-01 23:55:08 +01:00
/***** Free memory used by the list of booleans AddStdsWithoutGroupOf *****/
free ((void *) AddStdsWithoutGroupOf);
/***** Free list of groups types in current course *****/
Grp_FreeListGrpTypesAndGrps ();
}
/***** The last part of the query is for ordering the list *****/
2017-01-16 01:51:01 +01:00
Str_Concat (Query," ORDER BY "
"usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName,"
2017-01-17 03:33:05 +01:00
"usr_data.UsrCod",
2017-03-08 03:48:23 +01:00
Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2016-06-23 11:31:51 +02:00
/*********** Get list of users with a given role in a given scope ************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-06-23 11:31:51 +02:00
// Role can be:
// - Rol_STUDENT
// - Rol_TEACHER
2014-12-01 23:55:08 +01:00
2016-06-23 13:10:43 +02:00
void Usr_GetListUsrs (Rol_Role_t Role,Sco_Scope_t Scope)
2014-12-01 23:55:08 +01:00
{
2017-03-08 03:48:23 +01:00
char Query[Usr_MAX_BYTES_QUERY_GET_LIST_USRS + 1]; // Big query when the course has lot of groups
2016-07-25 20:42:37 +02:00
const char *QueryFields =
"DISTINCT usr_data.UsrCod,"
"usr_data.EncryptedUsrCod,"
2017-01-27 01:02:52 +01:00
"usr_data.Password,"
2016-07-25 20:42:37 +02:00
"usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName,"
"usr_data.Sex,"
"usr_data.Photo,"
"usr_data.PhotoVisibility,"
2017-03-01 14:53:18 +01:00
"usr_data.CtyCod,"
2016-07-25 20:42:37 +02:00
"usr_data.InsCod";
2016-07-25 20:24:07 +02:00
/*
2016-07-26 01:03:41 +02:00
row[ 0]: usr_data.UsrCod
row[ 1]: usr_data.EncryptedUsrCod
2017-01-28 17:17:35 +01:00
row[ 2]: usr_data.Password
2017-01-27 01:02:52 +01:00
row[ 3]: usr_data.Surname1
row[ 4]: usr_data.Surname2
row[ 5]: usr_data.FirstName
row[ 6]: usr_data.Sex
row[ 7]: usr_data.Photo
row[ 8]: usr_data.PhotoVisibility
2017-03-01 14:53:18 +01:00
row[ 9]: usr_data.CtyCod
row[10]: usr_data.InsCod
row[11]: crs_usr.Role (only if Scope == Sco_SCOPE_CRS)
row[12]: crs_usr.Accepted (only if Scope == Sco_SCOPE_CRS)
2016-07-25 20:24:07 +02:00
*/
2016-07-25 20:42:37 +02:00
/***** Build query *****/
2016-06-23 11:31:51 +02:00
switch (Scope)
{
case Sco_SCOPE_SYS:
/* Get users in courses from the whole platform */
2017-01-27 01:02:52 +01:00
sprintf (Query,"SELECT %s"
" FROM usr_data,crs_usr"
2016-06-23 11:31:51 +02:00
" WHERE usr_data.UsrCod=crs_usr.UsrCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u"
2016-06-23 11:31:51 +02:00
" ORDER BY "
"usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName,"
"usr_data.UsrCod",
2016-07-25 20:42:37 +02:00
QueryFields,
2016-06-23 11:31:51 +02:00
(unsigned) Role);
break;
case Sco_SCOPE_CTY:
/* Get users in courses from the current country */
2017-01-27 01:02:52 +01:00
sprintf (Query,"SELECT %s"
" FROM usr_data,crs_usr,courses,degrees,centres,institutions"
2016-06-23 11:31:51 +02:00
" WHERE usr_data.UsrCod=crs_usr.UsrCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u"
2016-06-23 11:31:51 +02:00
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
" AND centres.InsCod=institutions.InsCod"
2017-03-24 01:09:27 +01:00
" AND institutions.CtyCod=%ld"
2016-06-23 11:31:51 +02:00
" ORDER BY "
"usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName,"
"usr_data.UsrCod",
2016-07-25 20:42:37 +02:00
QueryFields,
2016-06-23 11:31:51 +02:00
(unsigned) Role,
Gbl.CurrentCty.Cty.CtyCod);
break;
case Sco_SCOPE_INS:
/* Get users in courses from the current institution */
2017-01-27 01:02:52 +01:00
sprintf (Query,"SELECT %s"
" FROM usr_data,crs_usr,courses,degrees,centres"
2016-06-23 11:31:51 +02:00
" WHERE usr_data.UsrCod=crs_usr.UsrCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u"
2016-06-23 11:31:51 +02:00
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
2017-03-24 01:09:27 +01:00
" AND centres.InsCod=%ld"
2016-06-23 11:31:51 +02:00
" ORDER BY "
"usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName,"
"usr_data.UsrCod",
2016-07-25 20:42:37 +02:00
QueryFields,
2016-06-23 11:31:51 +02:00
(unsigned) Role,
Gbl.CurrentIns.Ins.InsCod);
break;
case Sco_SCOPE_CTR:
/* Get users in courses from the current centre */
2017-01-27 01:02:52 +01:00
sprintf (Query,"SELECT %s"
" FROM usr_data,crs_usr,courses,degrees"
2016-06-23 11:31:51 +02:00
" WHERE usr_data.UsrCod=crs_usr.UsrCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u"
2016-06-23 11:31:51 +02:00
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
2017-03-24 01:09:27 +01:00
" AND degrees.CtrCod=%ld"
2016-06-23 11:31:51 +02:00
" ORDER BY "
"usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName,"
"usr_data.UsrCod",
2016-07-25 20:42:37 +02:00
QueryFields,
2016-06-23 11:31:51 +02:00
(unsigned) Role,
Gbl.CurrentCtr.Ctr.CtrCod);
break;
case Sco_SCOPE_DEG:
/* Get users in courses from the current degree */
2017-01-27 01:02:52 +01:00
sprintf (Query,"SELECT %s"
" FROM usr_data,crs_usr,courses"
2016-06-23 11:31:51 +02:00
" WHERE usr_data.UsrCod=crs_usr.UsrCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u"
2016-06-23 11:31:51 +02:00
" AND crs_usr.CrsCod=courses.CrsCod"
2017-03-24 01:09:27 +01:00
" AND courses.DegCod=%ld"
2016-06-23 11:31:51 +02:00
" ORDER BY "
"usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName,"
"usr_data.UsrCod",
2016-07-25 20:42:37 +02:00
QueryFields,
2016-06-23 11:31:51 +02:00
(unsigned) Role,
Gbl.CurrentDeg.Deg.DegCod);
break;
case Sco_SCOPE_CRS:
/* Get users from the current course */
2016-06-23 21:18:11 +02:00
Usr_BuildQueryToGetUsrsLstCrs (Role,Query);
2016-06-23 11:31:51 +02:00
break;
default:
Lay_ShowErrorAndExit ("Wrong scope.");
break;
}
/*
if (Gbl.Usrs.Me.LoggedRole == Rol_ROLE_SYS_ADM)
Lay_ShowAlert (Lay_INFO,Query);
*/
/***** Get list of users from database given a query *****/
2016-06-23 13:10:43 +02:00
Usr_GetListUsrsFromQuery (Query,Role,Scope);
2016-06-23 11:31:51 +02:00
}
/*****************************************************************************/
2017-03-01 14:53:18 +01:00
/*********** Search for users with a given role in current scope *************/
2016-06-23 11:31:51 +02:00
/*****************************************************************************/
2016-06-29 18:27:49 +02:00
void Usr_SearchListUsrs (Rol_Role_t Role)
2016-06-23 11:31:51 +02:00
{
2017-03-13 20:32:03 +01:00
char Query[Usr_MAX_BYTES_QUERY_GET_LIST_USRS + 1];
2016-07-25 20:42:37 +02:00
const char *QueryFields =
"DISTINCT usr_data.UsrCod,"
"usr_data.EncryptedUsrCod,"
2017-01-27 15:21:01 +01:00
"usr_data.Password,"
2016-07-25 20:42:37 +02:00
"usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName,"
"usr_data.Sex,"
"usr_data.Photo,"
"usr_data.PhotoVisibility,"
2017-03-01 14:53:18 +01:00
"usr_data.CtyCod,"
2016-07-25 20:42:37 +02:00
"usr_data.InsCod";
2016-07-25 20:24:07 +02:00
/*
2016-07-26 01:20:08 +02:00
row[ 0]: usr_data.UsrCod
row[ 1]: usr_data.EncryptedUsrCod
2017-01-28 17:17:35 +01:00
row[ 2]: usr_data.Password
2017-01-27 15:21:01 +01:00
row[ 3]: usr_data.Surname1
row[ 4]: usr_data.Surname2
row[ 5]: usr_data.FirstName
row[ 6]: usr_data.Sex
row[ 7]: usr_data.Photo
row[ 8]: usr_data.PhotoVisibility
2017-03-01 14:53:18 +01:00
row[ 9]: usr_data.CtyCod
row[10]: usr_data.InsCod
row[11]: crs_usr.Role (only if Scope == Sco_SCOPE_CRS)
row[12]: crs_usr.Accepted (only if Scope == Sco_SCOPE_CRS)
2016-07-25 20:24:07 +02:00
*/
2016-07-25 20:42:37 +02:00
const char *OrderQuery = "candidate_users.UsrCod=usr_data.UsrCod"
" ORDER BY "
"usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName,"
"usr_data.UsrCod";
/***** Build query *****/
// if Gbl.Scope.Current is course ==> 3 columns are retrieved: UsrCod, Sex, Accepted
// else ==> 2 columns are retrieved: UsrCod, Sex
// Search is faster (aproximately x2) using a temporary table to store users found in the whole platform
2016-06-27 12:35:15 +02:00
switch (Role)
{
case Rol_UNKNOWN: // Here Rol_UNKNOWN means any rol (role does not matter)
switch (Gbl.Scope.Current)
{
case Sco_SCOPE_SYS:
/* Search users from the whole platform */
2016-07-26 01:20:08 +02:00
sprintf (Query,"SELECT %s"
" FROM candidate_users,usr_data"
2016-06-27 19:37:45 +02:00
" WHERE %s",
2016-07-25 20:42:37 +02:00
QueryFields,OrderQuery);
2016-06-27 12:35:15 +02:00
break;
case Sco_SCOPE_CTY:
/* Search users in courses from the current country */
2016-07-26 01:20:08 +02:00
sprintf (Query,"SELECT %s"
" FROM candidate_users,crs_usr,courses,degrees,centres,institutions,usr_data"
2016-06-27 12:35:15 +02:00
" WHERE candidate_users.UsrCod=crs_usr.UsrCod"
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
" AND centres.InsCod=institutions.InsCod"
2017-03-24 01:09:27 +01:00
" AND institutions.CtyCod=%ld"
2016-06-27 19:37:45 +02:00
" AND %s",
2016-07-25 20:42:37 +02:00
QueryFields,
2016-06-27 19:37:45 +02:00
Gbl.CurrentCty.Cty.CtyCod,
OrderQuery);
2016-06-27 12:35:15 +02:00
break;
case Sco_SCOPE_INS:
/* Search users in courses from the current institution */
2016-07-26 01:20:08 +02:00
sprintf (Query,"SELECT %s"
" FROM candidate_users,crs_usr,courses,degrees,centres,usr_data"
2016-06-27 12:35:15 +02:00
" WHERE candidate_users.UsrCod=crs_usr.UsrCod"
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
2017-03-24 01:09:27 +01:00
" AND centres.InsCod=%ld"
2016-06-27 19:37:45 +02:00
" AND %s",
2016-07-25 20:42:37 +02:00
QueryFields,
2016-06-27 19:37:45 +02:00
Gbl.CurrentIns.Ins.InsCod,
OrderQuery);
2016-06-27 12:35:15 +02:00
break;
case Sco_SCOPE_CTR:
/* Search users in courses from the current centre */
2016-07-26 01:20:08 +02:00
sprintf (Query,"SELECT %s"
" FROM candidate_users,crs_usr,courses,degrees,usr_data"
2016-06-27 12:35:15 +02:00
" WHERE candidate_users.UsrCod=crs_usr.UsrCod"
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
2017-03-24 01:09:27 +01:00
" AND degrees.CtrCod=%ld"
2016-06-27 19:37:45 +02:00
" AND %s",
2016-07-25 20:42:37 +02:00
QueryFields,
2016-06-27 19:37:45 +02:00
Gbl.CurrentCtr.Ctr.CtrCod,
OrderQuery);
2016-06-27 12:35:15 +02:00
break;
case Sco_SCOPE_DEG:
/* Search users in courses from the current degree */
2016-07-26 01:20:08 +02:00
sprintf (Query,"SELECT %s"
" FROM candidate_users,crs_usr,courses,usr_data"
2016-06-27 12:35:15 +02:00
" WHERE candidate_users.UsrCod=crs_usr.UsrCod"
" AND crs_usr.CrsCod=courses.CrsCod"
2017-03-24 01:09:27 +01:00
" AND courses.DegCod=%ld"
2016-06-27 19:37:45 +02:00
" AND %s",
2016-07-25 20:42:37 +02:00
QueryFields,
2016-06-27 19:37:45 +02:00
Gbl.CurrentDeg.Deg.DegCod,
OrderQuery);
2016-06-27 12:35:15 +02:00
break;
case Sco_SCOPE_CRS:
/* Search users in courses from the current course */
2016-07-26 01:20:08 +02:00
sprintf (Query,"SELECT %s,crs_usr.Role,crs_usr.Accepted"
" FROM candidate_users,crs_usr,usr_data"
2016-06-27 12:35:15 +02:00
" WHERE candidate_users.UsrCod=crs_usr.UsrCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.CrsCod=%ld"
2016-06-27 19:37:45 +02:00
" AND %s",
2016-07-25 20:42:37 +02:00
QueryFields,
2016-06-27 19:37:45 +02:00
Gbl.CurrentCrs.Crs.CrsCod,
OrderQuery);
2016-06-27 12:35:15 +02:00
break;
default:
Lay_ShowErrorAndExit ("Wrong scope.");
break;
}
break;
case Rol__GUEST_: // Guests (scope is not used)
/* Search users with no courses */
2016-07-26 01:20:08 +02:00
sprintf (Query,"SELECT %s"
" FROM candidate_users,usr_data"
2016-06-27 14:30:53 +02:00
" WHERE candidate_users.UsrCod NOT IN (SELECT UsrCod FROM crs_usr)"
2016-06-27 19:37:45 +02:00
" AND %s",
2016-07-25 20:42:37 +02:00
QueryFields,
2016-06-27 19:37:45 +02:00
OrderQuery);
2016-06-27 14:30:53 +02:00
break;
case Rol_STUDENT:
case Rol_TEACHER:
/*
To achieve maximum speed, it's important to do the things in this order:
1) Search for user's name (UsrQuery) getting candidate users
2) Filter the candidate users according to scope
*/
switch (Gbl.Scope.Current)
2016-06-27 12:35:15 +02:00
{
2016-06-27 14:30:53 +02:00
case Sco_SCOPE_SYS:
/* Search users in courses from the whole platform */
2016-07-26 01:20:08 +02:00
sprintf (Query,"SELECT %s"
" FROM candidate_users,crs_usr,usr_data"
2016-06-27 14:30:53 +02:00
" WHERE candidate_users.UsrCod=crs_usr.UsrCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u"
2016-06-27 19:37:45 +02:00
" AND %s",
2016-07-25 20:42:37 +02:00
QueryFields,
2016-06-27 19:37:45 +02:00
(unsigned) Role,
OrderQuery);
2016-06-27 12:35:15 +02:00
break;
2016-06-27 14:30:53 +02:00
case Sco_SCOPE_CTY:
/* Search users in courses from the current country */
2016-07-26 01:20:08 +02:00
sprintf (Query,"SELECT %s"
" FROM candidate_users,crs_usr,courses,degrees,centres,institutions,usr_data"
2016-06-27 14:30:53 +02:00
" WHERE candidate_users.UsrCod=crs_usr.UsrCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u"
2016-06-27 14:30:53 +02:00
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
" AND centres.InsCod=institutions.InsCod"
2017-03-24 01:09:27 +01:00
" AND institutions.CtyCod=%ld"
2016-06-27 19:37:45 +02:00
" AND %s",
2016-07-25 20:42:37 +02:00
QueryFields,
2016-06-27 14:30:53 +02:00
(unsigned) Role,
2016-06-27 19:37:45 +02:00
Gbl.CurrentCty.Cty.CtyCod,
OrderQuery);
2016-06-27 12:35:15 +02:00
break;
2016-06-27 14:30:53 +02:00
case Sco_SCOPE_INS:
/* Search users in courses from the current institution */
2016-07-26 01:20:08 +02:00
sprintf (Query,"SELECT %s"
" FROM candidate_users,crs_usr,courses,degrees,centres,usr_data"
2016-06-27 14:30:53 +02:00
" WHERE candidate_users.UsrCod=crs_usr.UsrCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u"
2016-06-27 14:30:53 +02:00
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
2017-03-24 01:09:27 +01:00
" AND centres.InsCod=%ld"
2016-06-27 19:37:45 +02:00
" AND %s",
2016-07-25 20:42:37 +02:00
QueryFields,
2016-06-27 14:30:53 +02:00
(unsigned) Role,
2016-06-27 19:37:45 +02:00
Gbl.CurrentIns.Ins.InsCod,
OrderQuery);
2016-06-27 12:35:15 +02:00
break;
case Sco_SCOPE_CTR:
/* Search users in courses from the current centre */
2016-07-26 01:20:08 +02:00
sprintf (Query,"SELECT %s"
" FROM candidate_users,crs_usr,courses,degrees,usr_data"
2016-06-27 14:30:53 +02:00
" WHERE candidate_users.UsrCod=crs_usr.UsrCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u"
2016-06-27 14:30:53 +02:00
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
2017-03-24 01:09:27 +01:00
" AND degrees.CtrCod=%ld"
2016-06-27 19:37:45 +02:00
" AND %s",
2016-07-25 20:42:37 +02:00
QueryFields,
2016-06-27 14:30:53 +02:00
(unsigned) Role,
2016-06-27 19:37:45 +02:00
Gbl.CurrentCtr.Ctr.CtrCod,
OrderQuery);
2016-06-27 12:35:15 +02:00
break;
case Sco_SCOPE_DEG:
/* Search users in courses from the current degree */
2016-07-26 01:20:08 +02:00
sprintf (Query,"SELECT %s"
" FROM candidate_users,crs_usr,courses,usr_data"
2016-06-27 14:30:53 +02:00
" WHERE candidate_users.UsrCod=crs_usr.UsrCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u"
2016-06-27 14:30:53 +02:00
" AND crs_usr.CrsCod=courses.CrsCod"
2017-03-24 01:09:27 +01:00
" AND courses.DegCod=%ld"
2016-06-27 19:37:45 +02:00
" AND %s",
2016-07-25 20:42:37 +02:00
QueryFields,
2016-06-27 14:30:53 +02:00
(unsigned) Role,
2016-06-27 19:37:45 +02:00
Gbl.CurrentDeg.Deg.DegCod,
OrderQuery);
2016-06-27 12:35:15 +02:00
break;
case Sco_SCOPE_CRS:
/* Search users in courses from the current course */
2016-07-26 01:20:08 +02:00
sprintf (Query,"SELECT %s,crs_usr.Role,crs_usr.Accepted"
" FROM candidate_users,crs_usr,usr_data"
2016-06-27 14:30:53 +02:00
" WHERE candidate_users.UsrCod=crs_usr.UsrCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u"
" AND crs_usr.CrsCod=%ld"
2016-06-27 19:37:45 +02:00
" AND %s",
2016-07-25 20:42:37 +02:00
QueryFields,
2016-06-27 14:30:53 +02:00
(unsigned) Role,
2016-06-27 19:37:45 +02:00
Gbl.CurrentCrs.Crs.CrsCod,
OrderQuery);
2016-06-27 12:35:15 +02:00
break;
default:
Lay_ShowErrorAndExit ("Wrong scope.");
break;
}
break;
default:
Lay_ShowErrorAndExit ("Wrong role.");
break;
}
2016-06-23 19:02:57 +02:00
// if (Gbl.Usrs.Me.LoggedRole == Rol_ROLE_SYS_ADM)
2016-06-23 21:18:11 +02:00
// Lay_ShowAlert (Lay_INFO,Query);
2016-06-23 19:02:57 +02:00
2016-06-23 11:31:51 +02:00
/***** Get list of users from database given a query *****/
2016-06-23 13:10:43 +02:00
Usr_GetListUsrsFromQuery (Query,Role,Gbl.Scope.Current);
2016-06-20 09:43:27 +02:00
}
2016-06-24 15:31:09 +02:00
/*****************************************************************************/
/*************** Create temporary table with candidate users *****************/
/*****************************************************************************/
2017-03-13 20:32:03 +01:00
void Usr_CreateTmpTableAndSearchCandidateUsrs (const char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1])
2016-06-24 15:31:09 +02:00
{
2017-03-13 20:32:03 +01:00
char Query[256 + Sch_MAX_BYTES_SEARCH_QUERY];
2016-06-24 15:31:09 +02:00
/***** Create temporary table with candidate users *****/
/*
- Search is faster (aproximately x2) using temporary tables.
- Searching for names is made in the whole platform
and stored in this table.
*/
sprintf (Query,"CREATE TEMPORARY TABLE candidate_users"
" (UsrCod INT NOT NULL,UNIQUE INDEX(UsrCod)) ENGINE=MEMORY"
" SELECT UsrCod FROM usr_data WHERE %s",
2016-06-29 18:27:49 +02:00
SearchQuery);
2016-06-24 15:31:09 +02:00
if (mysql_query (&Gbl.mysql,Query))
DB_ExitOnMySQLError ("can not create temporary table");
}
/*****************************************************************************/
2016-06-27 14:30:53 +02:00
/***************** Drop temporary table with candidate users *****************/
2016-06-24 15:31:09 +02:00
/*****************************************************************************/
2016-06-29 18:27:49 +02:00
void Usr_DropTmpTableWithCandidateUsrs (void)
2016-06-24 15:31:09 +02:00
{
char Query[128];
2016-06-27 14:30:53 +02:00
sprintf (Query,"DROP TEMPORARY TABLE IF EXISTS candidate_users");
2016-06-24 15:31:09 +02:00
if (mysql_query (&Gbl.mysql,Query))
2016-06-27 14:30:53 +02:00
DB_ExitOnMySQLError ("can not remove temporary table");
2016-06-24 15:31:09 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/******************** Get list with data of administrators *******************/
/*****************************************************************************/
static void Usr_GetAdmsLst (Sco_Scope_t Scope)
{
2016-10-27 22:16:03 +02:00
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
2017-03-13 20:32:03 +01:00
char Query[2048];
2016-07-25 20:42:37 +02:00
const char *QueryFields =
"UsrCod,"
"EncryptedUsrCod,"
2017-01-28 17:17:35 +01:00
"Password,"
2016-07-25 20:42:37 +02:00
"Surname1,"
"Surname2,"
"FirstName,"
"Sex,"
"Photo,"
"PhotoVisibility,"
2017-03-01 14:53:18 +01:00
"CtyCod,"
2016-07-25 20:42:37 +02:00
"InsCod";
2016-07-25 20:24:07 +02:00
/*
2017-03-01 14:53:18 +01:00
row[ 0]: usr_data.UsrCod
row[ 1]: usr_data.EncryptedUsrCod
row[ 2]: usr_data.Password
row[ 3]: usr_data.Surname1
row[ 4]: usr_data.Surname2
row[ 5]: usr_data.FirstName
row[ 6]: usr_data.Sex
row[ 7]: usr_data.Photo
row[ 8]: usr_data.PhotoVisibility
row[ 9]: usr_data.CtyCod
row[10]: usr_data.InsCod
2016-07-25 20:24:07 +02:00
*/
2016-07-25 20:42:37 +02:00
/***** Build query *****/
2015-11-24 10:29:07 +01:00
// Important: it is better to use:
// SELECT... WHERE UsrCod IN (SELECT...) OR UsrCod IN (SELECT...) <-- fast
// instead of using or with different joins:
// SELECT... WHERE (...) OR (...) <-- very slow
2014-12-01 23:55:08 +01:00
switch (Scope)
{
2015-11-23 13:14:13 +01:00
case Sco_SCOPE_SYS: // All admins
2016-07-25 20:42:37 +02:00
sprintf (Query,"SELECT %s FROM usr_data"
" WHERE UsrCod IN "
"(SELECT DISTINCT UsrCod FROM admin)"
" ORDER BY Surname1,Surname2,FirstName,UsrCod",
QueryFields);
2014-12-01 23:55:08 +01:00
break;
2015-11-23 13:14:13 +01:00
case Sco_SCOPE_CTY: // System admins
// and admins of the institutions, centres and degrees in the current country
2016-07-25 20:42:37 +02:00
sprintf (Query,"SELECT %s FROM usr_data"
2015-11-23 16:34:58 +01:00
" WHERE UsrCod IN "
"(SELECT UsrCod FROM admin"
2016-10-27 22:16:03 +02:00
" WHERE Scope='%s')"
2015-11-23 16:34:58 +01:00
" OR UsrCod IN "
"(SELECT admin.UsrCod FROM admin,institutions"
2016-10-27 22:16:03 +02:00
" WHERE admin.Scope='%s'"
2015-11-23 13:14:13 +01:00
" AND admin.Cod=institutions.InsCod"
2017-03-24 01:09:27 +01:00
" AND institutions.CtyCod=%ld)"
2015-11-23 16:34:58 +01:00
" OR UsrCod IN "
"(SELECT admin.UsrCod FROM admin,centres,institutions"
2016-10-27 22:16:03 +02:00
" WHERE admin.Scope='%s'"
2015-11-23 13:14:13 +01:00
" AND admin.Cod=centres.CtrCod"
" AND centres.InsCod=institutions.InsCod"
2017-03-24 01:09:27 +01:00
" AND institutions.CtyCod=%ld)"
2015-11-23 16:34:58 +01:00
" OR UsrCod IN "
"(SELECT admin.UsrCod FROM admin,degrees,centres,institutions"
2016-10-27 22:16:03 +02:00
" WHERE admin.Scope='%s'"
2015-11-23 13:14:13 +01:00
" AND admin.Cod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
" AND centres.InsCod=institutions.InsCod"
2017-03-24 01:09:27 +01:00
" AND institutions.CtyCod=%ld)"
2015-11-23 16:34:58 +01:00
" ORDER BY Surname1,Surname2,FirstName,UsrCod",
2016-07-25 20:42:37 +02:00
QueryFields,
2016-10-27 22:16:03 +02:00
Sco_ScopeDB[Sco_SCOPE_SYS],
Sco_ScopeDB[Sco_SCOPE_INS],Gbl.CurrentCty.Cty.CtyCod,
Sco_ScopeDB[Sco_SCOPE_CTR],Gbl.CurrentCty.Cty.CtyCod,
Sco_ScopeDB[Sco_SCOPE_DEG],Gbl.CurrentCty.Cty.CtyCod);
2015-11-23 00:44:39 +01:00
break;
2015-11-23 13:14:13 +01:00
case Sco_SCOPE_INS: // System admins,
// admins of the current institution,
// and admins of the centres and degrees in the current institution
2016-07-25 20:42:37 +02:00
sprintf (Query,"SELECT %s FROM usr_data"
2015-11-23 16:34:58 +01:00
" WHERE UsrCod IN "
"(SELECT UsrCod FROM admin"
2016-10-27 22:16:03 +02:00
" WHERE Scope='%s')"
2015-11-23 16:34:58 +01:00
" OR UsrCod IN "
"(SELECT UsrCod FROM admin"
2017-03-24 01:09:27 +01:00
" WHERE Scope='%s' AND Cod=%ld)"
2015-11-23 16:34:58 +01:00
" OR UsrCod IN "
"(SELECT admin.UsrCod FROM admin,centres"
2016-10-27 22:16:03 +02:00
" WHERE admin.Scope='%s'"
2015-11-23 13:14:13 +01:00
" AND admin.Cod=centres.CtrCod"
2017-03-24 01:09:27 +01:00
" AND centres.InsCod=%ld)"
2015-11-23 16:34:58 +01:00
" OR UsrCod IN "
"(SELECT admin.UsrCod FROM admin,degrees,centres"
2016-10-27 22:16:03 +02:00
" WHERE admin.Scope='%s'"
2015-11-23 13:14:13 +01:00
" AND admin.Cod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
2017-03-24 01:09:27 +01:00
" AND centres.InsCod=%ld)"
2015-11-23 16:34:58 +01:00
" ORDER BY Surname1,Surname2,FirstName,UsrCod",
2016-07-25 20:42:37 +02:00
QueryFields,
2016-10-27 22:16:03 +02:00
Sco_ScopeDB[Sco_SCOPE_SYS],
Sco_ScopeDB[Sco_SCOPE_INS],Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CTR],Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_DEG],Gbl.CurrentIns.Ins.InsCod);
2014-12-01 23:55:08 +01:00
break;
2015-11-23 13:14:13 +01:00
case Sco_SCOPE_CTR: // System admins,
// admins of the current institution,
// admins and the current centre,
// and admins of the degrees in the current centre
2016-07-25 20:42:37 +02:00
sprintf (Query,"SELECT %s FROM usr_data"
2015-11-23 16:34:58 +01:00
" WHERE UsrCod IN "
"(SELECT UsrCod FROM admin"
2016-10-27 22:16:03 +02:00
" WHERE Scope='%s')"
2015-11-23 16:34:58 +01:00
" OR UsrCod IN "
"(SELECT UsrCod FROM admin"
2017-03-24 01:09:27 +01:00
" WHERE Scope='%s' AND Cod=%ld)"
2015-11-23 16:34:58 +01:00
" OR UsrCod IN "
"(SELECT UsrCod FROM admin"
2017-03-24 01:09:27 +01:00
" WHERE Scope='%s' AND Cod=%ld)"
2015-11-23 16:34:58 +01:00
" OR UsrCod IN "
"(SELECT admin.UsrCod FROM admin,degrees"
2016-10-27 22:16:03 +02:00
" WHERE admin.Scope='%s'"
2015-11-23 13:14:13 +01:00
" AND admin.Cod=degrees.DegCod"
2017-03-24 01:09:27 +01:00
" AND degrees.CtrCod=%ld)"
2015-11-23 16:34:58 +01:00
" ORDER BY Surname1,Surname2,FirstName,UsrCod",
2016-07-25 20:42:37 +02:00
QueryFields,
2016-10-27 22:16:03 +02:00
Sco_ScopeDB[Sco_SCOPE_SYS],
Sco_ScopeDB[Sco_SCOPE_INS],Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CTR],Gbl.CurrentCtr.Ctr.CtrCod,
Sco_ScopeDB[Sco_SCOPE_DEG],Gbl.CurrentCtr.Ctr.CtrCod);
2014-12-01 23:55:08 +01:00
break;
2015-11-23 13:14:13 +01:00
case Sco_SCOPE_DEG: // System admins
// and admins of the current institution, centre or degree
2016-07-25 20:42:37 +02:00
sprintf (Query,"SELECT %s FROM usr_data"
2015-11-23 16:34:58 +01:00
" WHERE UsrCod IN "
"(SELECT UsrCod FROM admin"
2016-10-27 22:16:03 +02:00
" WHERE Scope='%s')"
2015-11-23 16:34:58 +01:00
" OR UsrCod IN "
"(SELECT UsrCod FROM admin"
2017-03-24 01:09:27 +01:00
" WHERE Scope='%s' AND Cod=%ld)"
2015-11-23 16:34:58 +01:00
" OR UsrCod IN "
"(SELECT UsrCod FROM admin"
2017-03-24 01:09:27 +01:00
" WHERE Scope='%s' AND Cod=%ld)"
2015-11-23 16:34:58 +01:00
" OR UsrCod IN "
"(SELECT UsrCod FROM admin"
2017-03-24 01:09:27 +01:00
" WHERE Scope='%s' AND Cod=%ld)"
2015-11-23 16:34:58 +01:00
" ORDER BY Surname1,Surname2,FirstName,UsrCod",
2016-07-25 20:42:37 +02:00
QueryFields,
2016-10-27 22:16:03 +02:00
Sco_ScopeDB[Sco_SCOPE_SYS],
Sco_ScopeDB[Sco_SCOPE_INS],Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CTR],Gbl.CurrentCtr.Ctr.CtrCod,
Sco_ScopeDB[Sco_SCOPE_DEG],Gbl.CurrentDeg.Deg.DegCod);
2014-12-01 23:55:08 +01:00
break;
default: // not aplicable
2015-11-23 13:14:13 +01:00
Lay_ShowErrorAndExit ("Wrong scope.");
break;
2014-12-01 23:55:08 +01:00
}
2016-06-21 10:32:06 +02:00
/***** Get list of administrators from database *****/
2016-06-23 13:10:43 +02:00
Usr_GetListUsrsFromQuery (Query,Rol_DEG_ADM,Scope);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************ Get list with data of guests ***********************/
/*****************************************************************************/
static void Usr_GetGstsLst (Sco_Scope_t Scope)
{
char Query[512];
2016-07-25 20:42:37 +02:00
const char *QueryFields =
"UsrCod,"
"EncryptedUsrCod,"
2017-01-28 17:17:35 +01:00
"Password,"
2016-07-25 20:42:37 +02:00
"Surname1,"
"Surname2,"
"FirstName,"
"Sex,"
"Photo,"
"PhotoVisibility,"
2017-03-01 14:53:18 +01:00
"CtyCod,"
2016-07-25 20:42:37 +02:00
"InsCod";
2016-07-25 20:24:07 +02:00
/*
2017-03-01 14:53:18 +01:00
row[ 0]: usr_data.UsrCod
row[ 1]: usr_data.EncryptedUsrCod
row[ 2]: usr_data.Password
row[ 3]: usr_data.Surname1
row[ 4]: usr_data.Surname2
row[ 5]: usr_data.FirstName
row[ 6]: usr_data.Sex
row[ 7]: usr_data.Photo
row[ 8]: usr_data.PhotoVisibility
row[ 9]: usr_data.CtyCod
row[10]: usr_data.InsCod
2016-07-25 20:24:07 +02:00
*/
2016-07-25 20:42:37 +02:00
/***** Build query *****/
2014-12-01 23:55:08 +01:00
switch (Scope)
{
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_SYS:
2016-07-25 20:42:37 +02:00
sprintf (Query,"SELECT %s FROM usr_data"
" WHERE UsrCod NOT IN (SELECT UsrCod FROM crs_usr)"
" ORDER BY Surname1,Surname2,FirstName,UsrCod",
QueryFields);
2014-12-01 23:55:08 +01:00
break;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_CTY:
2016-07-25 20:42:37 +02:00
sprintf (Query,"SELECT %s FROM usr_data"
2017-03-24 01:09:27 +01:00
" WHERE (CtyCod=%ld OR InsCtyCod=%ld)"
2014-12-01 23:55:08 +01:00
" AND UsrCod NOT IN (SELECT UsrCod FROM crs_usr)"
" ORDER BY Surname1,Surname2,FirstName,UsrCod",
2016-07-25 20:42:37 +02:00
QueryFields,
2014-12-01 23:55:08 +01:00
Gbl.CurrentCty.Cty.CtyCod,
Gbl.CurrentCty.Cty.CtyCod);
break;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_INS:
2016-07-25 20:42:37 +02:00
sprintf (Query,"SELECT %s FROM usr_data"
2017-03-24 01:09:27 +01:00
" WHERE InsCod=%ld"
2014-12-01 23:55:08 +01:00
" AND UsrCod NOT IN (SELECT UsrCod FROM crs_usr)"
" ORDER BY Surname1,Surname2,FirstName,UsrCod",
2016-07-25 20:42:37 +02:00
QueryFields,
2014-12-01 23:55:08 +01:00
Gbl.CurrentIns.Ins.InsCod);
break;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_CTR:
2016-07-25 20:42:37 +02:00
sprintf (Query,"SELECT %s FROM usr_data"
2017-03-24 01:09:27 +01:00
" WHERE CtrCod=%ld"
2014-12-01 23:55:08 +01:00
" AND UsrCod NOT IN (SELECT UsrCod FROM crs_usr)"
" ORDER BY Surname1,Surname2,FirstName,UsrCod",
2016-07-25 20:42:37 +02:00
QueryFields,
2014-12-01 23:55:08 +01:00
Gbl.CurrentCtr.Ctr.CtrCod);
break;
default: // not aplicable
return;
}
/***** Get list of students from database *****/
2016-06-23 13:10:43 +02:00
Usr_GetListUsrsFromQuery (Query,Rol__GUEST_,Scope);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********** Get the user's codes of all the students of a degree ************/
/*****************************************************************************/
void Usr_GetUnorderedStdsCodesInDeg (long DegCod)
{
2016-07-25 20:42:37 +02:00
char Query[1024];
const char *QueryFields =
"DISTINCT usr_data.UsrCod,"
"usr_data.EncryptedUsrCod,"
2017-01-28 17:17:35 +01:00
"usr_data.Password,"
2016-07-25 20:42:37 +02:00
"usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName,"
"usr_data.Sex,"
"usr_data.Photo,"
"usr_data.PhotoVisibility,"
2017-03-01 14:53:18 +01:00
"usr_data.CtyCod,"
2016-07-25 20:42:37 +02:00
"usr_data.InsCod";
/*
2017-03-01 14:53:18 +01:00
row[ 0]: usr_data.UsrCod
row[ 1]: usr_data.EncryptedUsrCod
row[ 2]: usr_data.Password
row[ 3]: usr_data.Surname1
row[ 4]: usr_data.Surname2
row[ 5]: usr_data.FirstName
row[ 6]: usr_data.Sex
row[ 7]: usr_data.Photo
row[ 8]: usr_data.PhotoVisibility
row[ 9]: usr_data.CtyCod
row[10]: usr_data.InsCod
2016-07-25 20:42:37 +02:00
*/
2014-12-01 23:55:08 +01:00
2016-06-23 13:10:43 +02:00
Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs = 0;
2014-12-01 23:55:08 +01:00
2015-04-07 21:44:24 +02:00
if (Usr_GetNumUsrsInCrssOfDeg (Rol_STUDENT,DegCod))
2014-12-01 23:55:08 +01:00
{
/***** Get the students in a degree from database *****/
2016-07-25 20:42:37 +02:00
sprintf (Query,"SELECT %s FROM courses,crs_usr,usr_data"
2017-03-24 01:09:27 +01:00
" WHERE courses.DegCod=%ld"
2016-05-05 10:01:35 +02:00
" AND courses.CrsCod=crs_usr.CrsCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u"
2014-12-01 23:55:08 +01:00
" AND crs_usr.UsrCod=usr_data.UsrCod",
2016-07-25 20:42:37 +02:00
QueryFields,
2015-04-07 21:44:24 +02:00
DegCod,(unsigned) Rol_STUDENT);
2014-12-01 23:55:08 +01:00
/***** Get list of students from database *****/
2016-06-23 13:10:43 +02:00
Usr_GetListUsrsFromQuery (Query,Rol_STUDENT,Sco_SCOPE_DEG);
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/********************** Get list of users from database **********************/
/*****************************************************************************/
2016-06-23 13:10:43 +02:00
static void Usr_GetListUsrsFromQuery (const char *Query,Rol_Role_t Role,Sco_Scope_t Scope)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumUsr;
2016-07-25 20:24:07 +02:00
struct UsrInList *UsrInList;
2014-12-01 23:55:08 +01:00
bool Abort = false;
if (!Query[0])
{
2016-06-23 13:10:43 +02:00
Gbl.Usrs.LstUsrs[Role].NumUsrs = 0;
2014-12-01 23:55:08 +01:00
return;
}
/***** Query database *****/
2016-06-23 13:10:43 +02:00
if ((Gbl.Usrs.LstUsrs[Role].NumUsrs = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get list of users")))
2014-12-01 23:55:08 +01:00
{
2016-06-23 13:10:43 +02:00
if (Gbl.Usrs.LstUsrs[Role].NumUsrs > Cfg_MAX_USRS_IN_LIST)
2014-12-01 23:55:08 +01:00
{
2016-06-23 13:10:43 +02:00
Usr_ShowWarningListIsTooBig (Gbl.Usrs.LstUsrs[Role].NumUsrs);
2014-12-01 23:55:08 +01:00
Abort = true;
}
else
{
/***** Allocate memory for the list of users *****/
2016-06-23 13:10:43 +02:00
Usr_AllocateUsrsList (Role);
2014-12-01 23:55:08 +01:00
2016-06-21 10:32:06 +02:00
/***** Get list of users *****/
2014-12-01 23:55:08 +01:00
for (NumUsr = 0;
2016-06-23 13:10:43 +02:00
NumUsr < Gbl.Usrs.LstUsrs[Role].NumUsrs;
2014-12-01 23:55:08 +01:00
NumUsr++)
{
2016-06-21 10:32:06 +02:00
/* Get next user */
2014-12-01 23:55:08 +01:00
row = mysql_fetch_row (mysql_res);
2016-07-25 20:24:07 +02:00
/*
2016-07-26 01:03:41 +02:00
row[ 0]: usr_data.UsrCod
row[ 1]: usr_data.EncryptedUsrCod
2017-01-27 01:02:52 +01:00
row[ 2]: usr_data.Password (used to check if a teacher can edit user's data)
row[ 3]: usr_data.Surname1
row[ 4]: usr_data.Surname2
row[ 5]: usr_data.FirstName
row[ 6]: usr_data.Sex
row[ 7]: usr_data.Photo
row[ 8]: usr_data.PhotoVisibility
2017-03-01 14:53:18 +01:00
row[ 9]: usr_data.CtyCod
row[10]: usr_data.InsCod
row[11]: crs_usr.Role (only if Scope == Sco_SCOPE_CRS)
row[12]: crs_usr.Accepted (only if Scope == Sco_SCOPE_CRS)
2016-07-25 20:24:07 +02:00
*/
UsrInList = &Gbl.Usrs.LstUsrs[Role].Lst[NumUsr];
/* Get user's code (row[0]) */
UsrInList->UsrCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get encrypted user's code (row[1]) */
2017-01-15 18:02:52 +01:00
Str_Copy (UsrInList->EncryptedUsrCod,row[1],
2017-03-07 01:56:41 +01:00
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
2016-07-25 20:24:07 +02:00
2017-01-27 01:02:52 +01:00
/* Get encrypted password (row[2]) */
Str_Copy (UsrInList->Password,row[2],
2017-03-13 14:22:36 +01:00
Pwd_BYTES_ENCRYPTED_PASSWORD);
2017-01-27 01:02:52 +01:00
/* Get user's surname 1 (row[3]) */
Str_Copy (UsrInList->Surname1,row[3],
2017-03-07 19:55:29 +01:00
Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
2016-07-25 20:24:07 +02:00
2017-01-27 01:02:52 +01:00
/* Get user's surname 2 (row[4]) */
Str_Copy (UsrInList->Surname2,row[4],
2017-03-07 19:55:29 +01:00
Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
2016-07-25 20:24:07 +02:00
2017-01-27 01:02:52 +01:00
/* Get user's first name (row[5]) */
Str_Copy (UsrInList->FirstName,row[5],
2017-03-07 19:55:29 +01:00
Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
2016-07-25 20:24:07 +02:00
2017-01-27 01:02:52 +01:00
/* Get user's sex (row[6]) */
UsrInList->Sex = Usr_GetSexFromStr (row[6]);
2016-07-25 20:24:07 +02:00
2017-01-27 01:02:52 +01:00
/* Get user's photo (row[7]) */
Str_Copy (UsrInList->Photo,row[7],
2017-03-07 01:56:41 +01:00
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
2016-07-25 20:24:07 +02:00
2017-01-27 01:02:52 +01:00
/* Get user's photo visibility (row[8]) */
UsrInList->PhotoVisibility = Pri_GetVisibilityFromStr (row[8]);
2016-07-25 20:24:07 +02:00
2017-03-01 14:53:18 +01:00
/* Get user's country code (row[9]) */
UsrInList->CtyCod = Str_ConvertStrCodToLongCod (row[9]);
/* Get user's institution code (row[10]) */
UsrInList->InsCod = Str_ConvertStrCodToLongCod (row[10]);
2016-07-25 20:24:07 +02:00
2017-03-30 11:20:06 +02:00
/* Get user's role and acceptance of enrolment in course(s)
2017-03-01 14:53:18 +01:00
(row[11], row[12] if Scope == Sco_SCOPE_CRS) */
2016-06-27 13:57:01 +02:00
switch (Role)
{
case Rol_UNKNOWN: // Here Rol_UNKNOWN means any user
switch (Scope)
{
case Sco_SCOPE_UNK: // Unknown
Lay_ShowErrorAndExit ("Wrong scope.");
break;
case Sco_SCOPE_SYS: // System
2016-07-26 01:03:41 +02:00
// Query result has not a column with the acceptation
UsrInList->RoleInCurrentCrsDB = Rol_UNKNOWN;
2016-07-25 20:24:07 +02:00
if (Usr_GetNumCrssOfUsr (UsrInList->UsrCod))
UsrInList->Accepted = (Usr_GetNumCrssOfUsrNotAccepted (UsrInList->UsrCod) == 0);
2016-06-27 13:57:01 +02:00
else
2016-07-25 20:24:07 +02:00
UsrInList->Accepted = false;
2016-06-27 13:57:01 +02:00
break;
case Sco_SCOPE_CTY: // Country
case Sco_SCOPE_INS: // Institution
case Sco_SCOPE_CTR: // Centre
case Sco_SCOPE_DEG: // Degree
2016-07-26 01:03:41 +02:00
// Query result has not a column with the acceptation
UsrInList->RoleInCurrentCrsDB = Rol_UNKNOWN;
2016-07-25 20:24:07 +02:00
UsrInList->Accepted = (Usr_GetNumCrssOfUsrNotAccepted (UsrInList->UsrCod) == 0);
2016-06-27 13:57:01 +02:00
break;
case Sco_SCOPE_CRS: // Course
2016-07-26 01:03:41 +02:00
// Query result has a column with the acceptation
2017-03-01 14:53:18 +01:00
UsrInList->RoleInCurrentCrsDB = Rol_ConvertUnsignedStrToRole (row[11]);
UsrInList->Accepted = (row[12][0] == 'Y');
2016-06-27 13:57:01 +02:00
break;
}
break;
2016-07-25 21:08:53 +02:00
case Rol__GUEST_: // Guests have no courses,...
// ...so they have not accepted...
// ...inscription in any course
2016-06-27 20:21:31 +02:00
case Rol_DEG_ADM: // Any admin (degree, centre, institution or system)
2016-07-26 01:03:41 +02:00
UsrInList->RoleInCurrentCrsDB = Rol_UNKNOWN;
2016-07-25 20:24:07 +02:00
UsrInList->Accepted = false;
2016-06-27 13:57:01 +02:00
break;
case Rol_STUDENT:
case Rol_TEACHER:
switch (Scope)
{
case Sco_SCOPE_UNK: // Unknown
Lay_ShowErrorAndExit ("Wrong scope.");
break;
case Sco_SCOPE_SYS: // System
case Sco_SCOPE_CTY: // Country
case Sco_SCOPE_INS: // Institution
case Sco_SCOPE_CTR: // Centre
case Sco_SCOPE_DEG: // Degree
2016-07-26 01:03:41 +02:00
// Query result has not a column with the acceptation
UsrInList->RoleInCurrentCrsDB = Rol_UNKNOWN;
2016-07-25 20:24:07 +02:00
UsrInList->Accepted = (Usr_GetNumCrssOfUsrWithARoleNotAccepted (UsrInList->UsrCod,Role) == 0);
2016-06-27 13:57:01 +02:00
break;
case Sco_SCOPE_CRS: // Course
2016-07-26 01:03:41 +02:00
// Query result has a column with the acceptation
2017-03-01 14:53:18 +01:00
UsrInList->RoleInCurrentCrsDB = Rol_ConvertUnsignedStrToRole (row[11]);
UsrInList->Accepted = (row[12][0] == 'Y');
2016-06-27 13:57:01 +02:00
break;
}
break;
default:
Lay_ShowErrorAndExit ("Wrong role.");
break;
2016-06-21 10:32:06 +02:00
}
2014-12-01 23:55:08 +01:00
/* By default, users are not removed */
2016-07-25 20:24:07 +02:00
UsrInList->Remove = false;
2014-12-01 23:55:08 +01:00
}
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
if (Abort)
Lay_ShowErrorAndExit (NULL);
}
2016-07-25 20:55:25 +02:00
/*****************************************************************************/
/********************** Copy user's basic data from list *********************/
/*****************************************************************************/
void Usr_CopyBasicUsrDataFromList (struct UsrData *UsrDat,const struct UsrInList *UsrInList)
{
UsrDat->UsrCod = UsrInList->UsrCod;
2017-01-15 22:58:26 +01:00
Str_Copy (UsrDat->EncryptedUsrCod,UsrInList->EncryptedUsrCod,
2017-03-07 01:56:41 +01:00
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
2017-01-17 03:10:43 +01:00
Str_Copy (UsrDat->Surname1,UsrInList->Surname1,
2017-03-07 19:55:29 +01:00
Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
2017-01-17 03:10:43 +01:00
Str_Copy (UsrDat->Surname2,UsrInList->Surname2,
2017-03-07 19:55:29 +01:00
Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
2017-01-17 03:10:43 +01:00
Str_Copy (UsrDat->FirstName,UsrInList->FirstName,
2017-03-07 19:55:29 +01:00
Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
2016-07-25 20:55:25 +02:00
UsrDat->Sex = UsrInList->Sex;
2017-01-15 22:58:26 +01:00
Str_Copy (UsrDat->Photo,UsrInList->Photo,
2017-03-07 01:56:41 +01:00
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
2016-07-25 20:55:25 +02:00
UsrDat->PhotoVisibility = UsrInList->PhotoVisibility;
2017-03-01 14:53:18 +01:00
UsrDat->CtyCod = UsrInList->CtyCod;
2016-07-25 20:55:25 +02:00
UsrDat->InsCod = UsrInList->InsCod;
2016-07-26 01:03:41 +02:00
UsrDat->RoleInCurrentCrsDB = UsrInList->RoleInCurrentCrsDB;
2016-07-25 20:55:25 +02:00
UsrDat->Accepted = UsrInList->Accepted;
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************** Allocate space for list of users *********************/
/*****************************************************************************/
2016-06-23 13:10:43 +02:00
static void Usr_AllocateUsrsList (Rol_Role_t Role)
2014-12-01 23:55:08 +01:00
{
/*
2015-02-01 20:17:24 +01:00
if (Gbl.Usrs.Me.LoggedRole == Rol_ROLE_SYS_ADM)
2014-12-01 23:55:08 +01:00
{
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,"Memory used by list = %lu",(long) sizeof (struct UsrInList) * NumUsrs);
Lay_ShowAlert (Lay_INFO,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
*/
2016-06-23 13:10:43 +02:00
if (Gbl.Usrs.LstUsrs[Role].NumUsrs)
if ((Gbl.Usrs.LstUsrs[Role].Lst = (struct UsrInList *) calloc (Gbl.Usrs.LstUsrs[Role].NumUsrs,sizeof (struct UsrInList))) == NULL)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Not enough memory to store users list.");
}
/*****************************************************************************/
/********************* Free space used for list of users *********************/
/*****************************************************************************/
2016-06-23 13:10:43 +02:00
void Usr_FreeUsrsList (Rol_Role_t Role)
2014-12-01 23:55:08 +01:00
{
2016-06-23 13:10:43 +02:00
if (Gbl.Usrs.LstUsrs[Role].NumUsrs)
2014-12-01 23:55:08 +01:00
{
/***** Free the list itself *****/
2016-06-23 13:10:43 +02:00
if (Gbl.Usrs.LstUsrs[Role].Lst)
2014-12-01 23:55:08 +01:00
{
2016-06-23 13:10:43 +02:00
free ((void *) Gbl.Usrs.LstUsrs[Role].Lst);
Gbl.Usrs.LstUsrs[Role].Lst = NULL;
2014-12-01 23:55:08 +01:00
}
/***** Reset number of users *****/
2016-06-23 13:10:43 +02:00
Gbl.Usrs.LstUsrs[Role].NumUsrs = 0;
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/******** Show form to confirm that I want to see a big list of users ********/
/*****************************************************************************/
2016-07-04 14:03:04 +02:00
bool Usr_GetIfShowBigList (unsigned NumUsrs,const char *OnSubmit)
2014-12-01 23:55:08 +01:00
{
bool ShowBigList;
/***** If list of users is too big... *****/
2016-07-04 12:50:17 +02:00
if (NumUsrs > Cfg_MIN_NUM_USERS_TO_CONFIRM_SHOW_BIG_LIST)
{
/***** Get parameter with user's confirmation
to see a big list of users *****/
2017-01-28 20:32:50 +01:00
if (!(ShowBigList = Par_GetParToBool ("ShowBigList")))
2016-07-04 14:03:04 +02:00
Usr_PutButtonToConfirmIWantToSeeBigList (NumUsrs,OnSubmit);
2016-07-04 12:50:17 +02:00
return ShowBigList;
}
else
2014-12-01 23:55:08 +01:00
return true; // List is not too big ==> show it
}
/*****************************************************************************/
/******** Show form to confirm that I want to see a big list of users ********/
/*****************************************************************************/
2016-07-04 14:03:04 +02:00
static void Usr_PutButtonToConfirmIWantToSeeBigList (unsigned NumUsrs,const char *OnSubmit)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_Show_anyway;
2015-09-02 23:51:44 +02:00
fprintf (Gbl.F.Out,"<div class=\"CENTER_MIDDLE\">");
2014-12-01 23:55:08 +01:00
/***** Show warning *****/
2016-07-04 12:50:17 +02:00
Usr_ShowWarningListIsTooBig (NumUsrs);
2014-12-01 23:55:08 +01:00
/***** Put form to confirm that I want to see the big list *****/
2016-07-04 14:03:04 +02:00
Act_FormStartOnSubmit (Gbl.Action.Act,OnSubmit);
2014-12-01 23:55:08 +01:00
Grp_PutParamsCodGrps ();
2017-02-01 11:23:48 +01:00
Usr_PutParamsPrefsAboutUsrList ();
2016-01-17 15:10:54 +01:00
Usr_PutExtraParamsUsrList (Gbl.Action.Act);
2014-12-01 23:55:08 +01:00
Par_PutHiddenParamChar ("ShowBigList",'Y');
/***** Send button *****/
2015-03-24 17:47:26 +01:00
Lay_PutConfirmButton (Txt_Show_anyway);
2016-07-04 14:03:04 +02:00
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
2016-07-04 12:50:17 +02:00
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</div>");
2014-12-01 23:55:08 +01:00
}
2016-07-04 12:50:17 +02:00
/*****************************************************************************/
/************************** Show big list warning ****************************/
/*****************************************************************************/
static void Usr_ShowWarningListIsTooBig (unsigned NumUsrs)
{
extern const char *Txt_The_list_of_X_users_is_too_large_to_be_displayed;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_list_of_X_users_is_too_large_to_be_displayed,
2016-07-04 12:50:17 +02:00
NumUsrs);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Gbl.Alert.Txt);
2016-07-04 12:50:17 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************* Write parameter with the list of users selected ***************/
/*****************************************************************************/
void Usr_PutHiddenParUsrCodAll (Act_Action_t NextAction,const char *ListUsrCods)
{
2017-05-09 10:32:54 +02:00
/***** Put a parameter indicating that a list of several users is present *****/
Par_PutHiddenParamChar ("MultiUsrs",'Y');
/***** Put a parameter with the encrypted user codes of several users *****/
2014-12-01 23:55:08 +01:00
if (Gbl.Session.IsOpen)
Ses_InsertHiddenParInDB (NextAction,"UsrCodAll",ListUsrCods);
else
Par_PutHiddenParamString ("UsrCodAll",ListUsrCods);
}
/*****************************************************************************/
/************************* Get list of selected users ************************/
/*****************************************************************************/
2016-07-04 14:03:04 +02:00
void Usr_GetListsSelectedUsrsCods (void)
2014-12-01 23:55:08 +01:00
{
unsigned Length;
/***** Allocate memory for the lists of users *****/
2015-09-30 23:10:15 +02:00
Usr_AllocateListSelectedUsrCodAll ();
Usr_AllocateListSelectedUsrCodTch ();
Usr_AllocateListSelectedUsrCodStd ();
2014-12-01 23:55:08 +01:00
/***** Get selected users *****/
if (Gbl.Session.IsOpen) // If the session is open, get parameter from DB
{
2017-05-09 10:32:54 +02:00
Ses_GetHiddenParFromDB (Gbl.Action.Act,"UsrCodAll",Gbl.Usrs.Select.All,
Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS);
Str_ChangeFormat (Str_FROM_FORM,Str_TO_TEXT,Gbl.Usrs.Select.All,
Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS,true);
2014-12-01 23:55:08 +01:00
}
else
2017-05-09 10:32:54 +02:00
Par_GetParMultiToText ("UsrCodAll",Gbl.Usrs.Select.All,
Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS);
2014-12-01 23:55:08 +01:00
2017-05-09 10:32:54 +02:00
Par_GetParMultiToText ("UsrCodTch",Gbl.Usrs.Select.Tch,
Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS); // Teachers or guests
2014-12-01 23:55:08 +01:00
2017-05-09 10:32:54 +02:00
Par_GetParMultiToText ("UsrCodStd",Gbl.Usrs.Select.Std,
Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS); // Students
2014-12-01 23:55:08 +01:00
/*
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,"UsrCodAll = %s / UsrCodTch = %s / UsrCodStd = %s",
2014-12-01 23:55:08 +01:00
Gbl.Usrs.Select.All,Gbl.Usrs.Select.Tch,Gbl.Usrs.Select.Std);
2017-05-10 10:25:01 +02:00
Lay_ShowErrorAndExit (Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
*/
/***** Add teachers to the list with all selected users *****/
if (Gbl.Usrs.Select.Tch[0])
{
if (Gbl.Usrs.Select.All[0])
2017-05-09 10:32:54 +02:00
if ((Length = strlen (Gbl.Usrs.Select.All)) <
Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS)
2014-12-01 23:55:08 +01:00
{
2017-01-28 15:58:46 +01:00
Gbl.Usrs.Select.All[Length ] = Par_SEPARATOR_PARAM_MULTIPLE;
Gbl.Usrs.Select.All[Length + 1] = '\0';
2014-12-01 23:55:08 +01:00
}
2017-01-15 02:05:24 +01:00
Str_Concat (Gbl.Usrs.Select.All,Gbl.Usrs.Select.Tch,
Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS);
2014-12-01 23:55:08 +01:00
}
/***** Add students to the list with all selected users *****/
if (Gbl.Usrs.Select.Std[0])
{
if (Gbl.Usrs.Select.All[0])
2017-05-09 10:32:54 +02:00
if ((Length = strlen (Gbl.Usrs.Select.All)) <
Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS)
2014-12-01 23:55:08 +01:00
{
2017-01-28 15:58:46 +01:00
Gbl.Usrs.Select.All[Length ] = Par_SEPARATOR_PARAM_MULTIPLE;
Gbl.Usrs.Select.All[Length + 1] = '\0';
2014-12-01 23:55:08 +01:00
}
2017-01-15 02:05:24 +01:00
Str_Concat (Gbl.Usrs.Select.All,Gbl.Usrs.Select.Std,
Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS);
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/*** Get list of recipients of a message written explicitely by the sender ***/
/*****************************************************************************/
// Returns true if no errors
bool Usr_GetListMsgRecipientsWrittenExplicitelyBySender (bool WriteErrorMsgs)
{
extern const char *Txt_There_is_no_user_with_nickname_X;
extern const char *Txt_There_is_no_user_with_email_X;
extern const char *Txt_There_are_more_than_one_user_with_the_ID_X_Please_type_a_nick_or_email;
2016-11-16 23:19:52 +01:00
extern const char *Txt_There_is_no_user_with_ID_nick_or_email_X;
2014-12-01 23:55:08 +01:00
extern const char *Txt_The_ID_nickname_or_email_X_is_not_valid;
2016-07-04 17:40:34 +02:00
size_t LengthSelectedUsrsCods;
size_t LengthUsrCod;
2014-12-01 23:55:08 +01:00
const char *Ptr;
2017-03-13 13:17:53 +01:00
char UsrIDNickOrEmail[Cns_MAX_BYTES_EMAIL_ADDRESS + 1];
2014-12-01 23:55:08 +01:00
struct UsrData UsrDat;
struct ListUsrCods ListUsrCods;
bool Error = false;
/***** Allocate memory for the lists of users's IDs *****/
2015-09-30 23:10:15 +02:00
Usr_AllocateListSelectedUsrCodAll ();
2016-07-04 17:40:34 +02:00
LengthSelectedUsrsCods = strlen (Gbl.Usrs.Select.All);
2014-12-01 23:55:08 +01:00
/***** Allocate memory for the lists of recipients written explicetely *****/
Usr_AllocateListOtherRecipients ();
/***** Get recipients written explicetely *****/
2017-01-29 21:41:08 +01:00
Par_GetParToText ("OtherRecipients",Gbl.Usrs.ListOtherRecipients,
Nck_MAX_BYTES_LIST_NICKS);
2014-12-01 23:55:08 +01:00
/***** Add encrypted users' IDs to the list with all selected users *****/
if (Gbl.Usrs.ListOtherRecipients[0])
{
/* Initialize structure with user's data */
Usr_UsrDataConstructor (&UsrDat);
/* Get next plain user's ID or nickname */
Ptr = Gbl.Usrs.ListOtherRecipients;
while (*Ptr)
{
/* Find next string in text until comma or semicolon (leading and trailing spaces are removed) */
2017-03-13 20:32:03 +01:00
Str_GetNextStringUntilComma (&Ptr,UsrIDNickOrEmail,Cns_MAX_BYTES_EMAIL_ADDRESS);
2014-12-01 23:55:08 +01:00
/* Check if string is plain user's ID or nickname and get encrypted user's ID */
if (UsrIDNickOrEmail[0])
{
/***** Reset default list of users' codes *****/
ListUsrCods.NumUsrs = 0;
ListUsrCods.Lst = NULL;
if (Nck_CheckIfNickWithArrobaIsValid (UsrIDNickOrEmail)) // 1: It's a nickname
{
if ((UsrDat.UsrCod = Nck_GetUsrCodFromNickname (UsrIDNickOrEmail)) > 0)
{
ListUsrCods.NumUsrs = 1;
Usr_AllocateListUsrCods (&ListUsrCods);
2017-03-12 12:52:40 +01:00
ListUsrCods.Lst[0] = UsrDat.UsrCod;
2014-12-01 23:55:08 +01:00
}
else
{
if (WriteErrorMsgs)
{
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_There_is_no_user_with_nickname_X,
2014-12-01 23:55:08 +01:00
UsrIDNickOrEmail);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
Error = true;
}
}
2016-11-16 23:19:52 +01:00
else if (Mai_CheckIfEmailIsValid (UsrIDNickOrEmail)) // 2: It's an email
2014-12-01 23:55:08 +01:00
{
if ((UsrDat.UsrCod = Mai_GetUsrCodFromEmail (UsrIDNickOrEmail)) > 0)
{
ListUsrCods.NumUsrs = 1;
Usr_AllocateListUsrCods (&ListUsrCods);
ListUsrCods.Lst[0] = Gbl.Usrs.Other.UsrDat.UsrCod;
}
else
{
if (WriteErrorMsgs)
{
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_There_is_no_user_with_email_X,
2014-12-01 23:55:08 +01:00
UsrIDNickOrEmail);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
Error = true;
}
}
2016-11-16 23:19:52 +01:00
else // 3: It's not a nickname nor email
2014-12-01 23:55:08 +01:00
{
// Users' IDs are always stored internally in capitals and without leading zeros
Str_RemoveLeadingZeros (UsrIDNickOrEmail);
Str_ConvertToUpperText (UsrIDNickOrEmail);
if (ID_CheckIfUsrIDIsValid (UsrIDNickOrEmail))
{
// It seems a user's ID
/***** Allocate space for the list *****/
ID_ReallocateListIDs (&UsrDat,1);
2017-01-15 18:02:52 +01:00
Str_Copy (UsrDat.IDs.List[0].ID,UsrIDNickOrEmail,
2017-03-07 01:56:41 +01:00
ID_MAX_BYTES_USR_ID);
2014-12-01 23:55:08 +01:00
/***** Check if a user exists having this user's ID *****/
if (ID_GetListUsrCodsFromUsrID (&UsrDat,NULL,&ListUsrCods,false))
{
if (ListUsrCods.NumUsrs > 1) // Two or more user share the same user's ID
{// TODO: Consider forbid IDs here
if (WriteErrorMsgs)
{
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_There_are_more_than_one_user_with_the_ID_X_Please_type_a_nick_or_email,
2014-12-01 23:55:08 +01:00
UsrIDNickOrEmail);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_ERROR,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
Error = true;
}
}
else // No users found
{
if (WriteErrorMsgs)
{
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_There_is_no_user_with_ID_nick_or_email_X,
2014-12-01 23:55:08 +01:00
UsrIDNickOrEmail);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_ERROR,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
Error = true;
}
}
2016-11-16 23:19:52 +01:00
else // String is not a valid user's nickname, email or ID
2014-12-01 23:55:08 +01:00
{
if (WriteErrorMsgs)
{
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_ID_nickname_or_email_X_is_not_valid,
2014-12-01 23:55:08 +01:00
UsrIDNickOrEmail);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
Error = true;
}
}
if (ListUsrCods.NumUsrs == 1) // Only if user is valid
{
/* Get user's data */
Usr_GetUsrDataFromUsrCod (&UsrDat); // Really only EncryptedUsrCod is needed
/* Find if encrypted user's code is already in list */
2015-09-30 23:10:15 +02:00
if (!Usr_FindUsrCodInListOfSelectedUsrs (UsrDat.EncryptedUsrCod)) // If not in list ==> add it
2014-12-01 23:55:08 +01:00
{
2017-03-12 12:52:40 +01:00
LengthUsrCod = strlen (UsrDat.EncryptedUsrCod);
2014-12-01 23:55:08 +01:00
/* Add encrypted user's code to list of users */
2017-03-12 12:52:40 +01:00
if (LengthSelectedUsrsCods == 0) // First user in list
2014-12-01 23:55:08 +01:00
{
2017-03-12 12:52:40 +01:00
if (LengthUsrCod < Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS)
{
/* Add user */
Str_Copy (Gbl.Usrs.Select.All,
UsrDat.EncryptedUsrCod,
Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS);
LengthSelectedUsrsCods = LengthUsrCod;
}
2014-12-01 23:55:08 +01:00
}
2017-03-12 12:52:40 +01:00
else // Not first user in list
2016-07-04 17:40:34 +02:00
{
2017-03-12 12:52:40 +01:00
if (LengthSelectedUsrsCods + (1 + LengthUsrCod) <
Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS)
2014-12-01 23:55:08 +01:00
{
2017-03-12 12:52:40 +01:00
/* Add separator */
2016-07-04 17:40:34 +02:00
Gbl.Usrs.Select.All[LengthSelectedUsrsCods] = Par_SEPARATOR_PARAM_MULTIPLE;
2017-03-12 12:52:40 +01:00
LengthSelectedUsrsCods++;
/* Add user */
Str_Copy (Gbl.Usrs.Select.All + LengthSelectedUsrsCods,
UsrDat.EncryptedUsrCod,
Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS);
LengthSelectedUsrsCods += LengthUsrCod;
2014-12-01 23:55:08 +01:00
}
2016-07-04 17:40:34 +02:00
}
2014-12-01 23:55:08 +01:00
}
}
/***** Free list of users' codes *****/
Usr_FreeListUsrCods (&ListUsrCods);
}
}
/* Free memory used for user's data */
Usr_UsrDataDestructor (&UsrDat);
}
return Error;
}
/*****************************************************************************/
/************** Find if encrypted user's code is yet in list *****************/
/*****************************************************************************/
// Returns true if EncryptedUsrCodToFind is in Gbl.Usrs.Select.All
2015-09-30 23:10:15 +02:00
bool Usr_FindUsrCodInListOfSelectedUsrs (const char *EncryptedUsrCodToFind)
2014-12-01 23:55:08 +01:00
{
const char *Ptr;
2017-03-07 01:56:41 +01:00
char EncryptedUsrCod[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1];
2014-12-01 23:55:08 +01:00
2015-09-30 23:10:15 +02:00
if (Gbl.Usrs.Select.All)
2014-12-01 23:55:08 +01:00
{
2015-09-30 23:10:15 +02:00
Ptr = Gbl.Usrs.Select.All;
while (*Ptr)
{
2017-03-13 14:22:36 +01:00
Par_GetNextStrUntilSeparParamMult (&Ptr,EncryptedUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
2015-09-30 23:10:15 +02:00
if (!strcmp (EncryptedUsrCodToFind,EncryptedUsrCod))
return true; // Found!
}
2014-12-01 23:55:08 +01:00
}
2015-09-30 23:10:15 +02:00
return false; // List not allocated or user not found
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************ Count number of valid users' IDs in encrypted list *************/
/*****************************************************************************/
2015-09-30 23:10:15 +02:00
unsigned Usr_CountNumUsrsInListOfSelectedUsrs (void)
2014-12-01 23:55:08 +01:00
{
const char *Ptr;
unsigned NumUsrs = 0;
struct UsrData UsrDat;
/***** Loop over the list Gbl.Usrs.Select.All to count the number of users *****/
Ptr = Gbl.Usrs.Select.All;
while (*Ptr)
{
2017-03-13 14:22:36 +01:00
Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EncryptedUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
2014-12-01 23:55:08 +01:00
Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat);
if (UsrDat.UsrCod > 0)
NumUsrs++;
}
return NumUsrs;
}
/*****************************************************************************/
/********************* Allocate memory for list of users *********************/
/*****************************************************************************/
2015-09-30 23:10:15 +02:00
void Usr_AllocateListSelectedUsrCodAll (void)
2014-12-01 23:55:08 +01:00
{
if (!Gbl.Usrs.Select.All)
{
2017-01-15 02:05:24 +01:00
if ((Gbl.Usrs.Select.All = (char *) malloc (Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS + 1)) == NULL)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Not enough memory to store list of users.");
Gbl.Usrs.Select.All[0] = '\0';
}
}
/*****************************************************************************/
/****************** Allocate memory for list of students *********************/
/*****************************************************************************/
2015-09-30 23:10:15 +02:00
void Usr_AllocateListSelectedUsrCodStd (void)
2014-12-01 23:55:08 +01:00
{
if (!Gbl.Usrs.Select.Std)
{
2015-11-24 10:29:07 +01:00
if ((Gbl.Usrs.Select.Std = (char *) malloc (Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS + 1)) == NULL)
2015-09-30 23:10:15 +02:00
Lay_ShowErrorAndExit ("Not enough memory to store list of users.");
2014-12-01 23:55:08 +01:00
Gbl.Usrs.Select.Std[0] = '\0';
}
}
/*****************************************************************************/
2015-09-30 23:10:15 +02:00
/************* Allocate memory for list of teachers or guests ****************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2015-09-30 23:10:15 +02:00
void Usr_AllocateListSelectedUsrCodTch (void)
2014-12-01 23:55:08 +01:00
{
if (!Gbl.Usrs.Select.Tch)
{
2015-11-24 10:29:07 +01:00
if ((Gbl.Usrs.Select.Tch = (char *) malloc (Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS + 1)) == NULL)
2015-09-30 23:10:15 +02:00
Lay_ShowErrorAndExit ("Not enough memory to store list of users.");
2014-12-01 23:55:08 +01:00
Gbl.Usrs.Select.Tch[0] = '\0';
}
}
/*****************************************************************************/
2016-07-04 14:03:04 +02:00
/************ Free memory used by list of selected users' codes **************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-07-04 14:03:04 +02:00
void Usr_FreeListsSelectedUsrsCods (void)
2014-12-01 23:55:08 +01:00
{
if (Gbl.Usrs.Select.All)
{
free ((void *) Gbl.Usrs.Select.All);
Gbl.Usrs.Select.All = NULL;
}
if (Gbl.Usrs.Select.Tch)
{
free ((void *) Gbl.Usrs.Select.Tch);
Gbl.Usrs.Select.Tch = NULL;
}
if (Gbl.Usrs.Select.Std)
{
free ((void *) Gbl.Usrs.Select.Std);
Gbl.Usrs.Select.Std = NULL;
}
}
/*****************************************************************************/
/********** Allocate memory for list of users's IDs or nicknames *************/
/*****************************************************************************/
static void Usr_AllocateListOtherRecipients (void)
{
if (!Gbl.Usrs.ListOtherRecipients)
{
2015-11-24 10:29:07 +01:00
if ((Gbl.Usrs.ListOtherRecipients = malloc (Nck_MAX_BYTES_LIST_NICKS + 1)) == NULL)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Not enough memory to store list of recipients.");
Gbl.Usrs.ListOtherRecipients[0] = '\0';
}
}
/*****************************************************************************/
/****************** Free memory for the list of nicknames ********************/
/*****************************************************************************/
void Usr_FreeListOtherRecipients (void)
{
if (Gbl.Usrs.ListOtherRecipients)
{
free ((void *) Gbl.Usrs.ListOtherRecipients);
Gbl.Usrs.ListOtherRecipients = NULL;
}
}
/*****************************************************************************/
2015-04-11 14:38:15 +02:00
/*************************** Selection of list type **************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
void Usr_ShowFormsToSelectUsrListType (Act_Action_t NextAction)
{
2016-12-23 22:19:03 +01:00
fprintf (Gbl.F.Out,"<div class=\"PREF_CONTAINER\">");
2017-01-29 21:41:08 +01:00
/***** Select Usr_LIST_AS_CLASS_PHOTO *****/
2016-12-23 22:19:03 +01:00
fprintf (Gbl.F.Out,"<div class=\"%s\">",
2017-01-29 21:41:08 +01:00
Gbl.Usrs.Me.ListType == Usr_LIST_AS_CLASS_PHOTO ? "PREF_ON" :
"PREF_OFF");
Usr_FormToSelectUsrListType (NextAction,Usr_LIST_AS_CLASS_PHOTO);
2014-12-01 23:55:08 +01:00
/* Number of columns in the class photo */
Act_FormStart (NextAction);
Grp_PutParamsCodGrps ();
2017-01-29 21:41:08 +01:00
Usr_PutParamUsrListType (Usr_LIST_AS_CLASS_PHOTO);
2014-12-01 23:55:08 +01:00
Usr_PutParamListWithPhotos ();
Usr_PutExtraParamsUsrList (NextAction);
Usr_PutSelectorNumColsClassPhoto ();
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
2016-12-23 22:19:03 +01:00
fprintf (Gbl.F.Out,"</div>");
2014-12-01 23:55:08 +01:00
2017-01-29 21:41:08 +01:00
/***** Select Usr_LIST_AS_LISTING *****/
2016-12-23 22:19:03 +01:00
fprintf (Gbl.F.Out,"<div class=\"%s\">",
2017-01-29 21:41:08 +01:00
Gbl.Usrs.Me.ListType == Usr_LIST_AS_LISTING ? "PREF_ON" :
"PREF_OFF");
Usr_FormToSelectUsrListType (NextAction,Usr_LIST_AS_LISTING);
2014-12-01 23:55:08 +01:00
/* See the photos in list? */
Act_FormStart (NextAction);
Grp_PutParamsCodGrps ();
2017-01-29 21:41:08 +01:00
Usr_PutParamUsrListType (Usr_LIST_AS_LISTING);
2014-12-01 23:55:08 +01:00
Usr_PutExtraParamsUsrList (NextAction);
Usr_PutCheckboxListWithPhotos ();
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
2016-12-23 22:19:03 +01:00
fprintf (Gbl.F.Out,"</div>");
fprintf (Gbl.F.Out,"</div>");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************* Put a radio element to select a users' list type **************/
/*****************************************************************************/
static void Usr_FormToSelectUsrListType (Act_Action_t NextAction,Usr_ShowUsrsType_t ListType)
{
2015-07-27 21:25:45 +02:00
extern const char *The_ClassFormNoWrap[The_NUM_THEMES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_USR_LIST_TYPES[Usr_NUM_USR_LIST_TYPES];
Act_FormStart (NextAction);
Grp_PutParamsCodGrps ();
Usr_PutParamUsrListType (ListType);
2017-02-01 11:23:48 +01:00
Usr_PutParamListWithPhotos ();
2014-12-01 23:55:08 +01:00
Usr_PutExtraParamsUsrList (NextAction);
2016-07-01 17:13:41 +02:00
Act_LinkFormSubmit (Txt_USR_LIST_TYPES[ListType],
2016-07-04 14:33:31 +02:00
The_ClassFormNoWrap[Gbl.Prefs.Theme],
NextAction == ActReqMsgUsr ? "CopyMessageToHiddenFields()" :
NULL);
2015-12-26 21:46:56 +01:00
fprintf (Gbl.F.Out,"<img src=\"%s/%s\""
2015-07-22 18:59:44 +02:00
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />"
2015-04-11 14:38:15 +02:00
" %s</a>",
2014-12-01 23:55:08 +01:00
Gbl.Prefs.IconsURL,
Usr_IconsClassPhotoOrList[ListType],
Txt_USR_LIST_TYPES[ListType],
2015-07-22 18:59:44 +02:00
Txt_USR_LIST_TYPES[ListType],
2014-12-01 23:55:08 +01:00
Txt_USR_LIST_TYPES[ListType]);
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************** Put extra parameters for a list of users ******************/
/*****************************************************************************/
void Usr_PutExtraParamsUsrList (Act_Action_t NextAction)
{
2016-01-17 15:10:54 +01:00
switch (Gbl.Action.Act)
2014-12-01 23:55:08 +01:00
{
2015-09-20 19:20:05 +02:00
case ActLstGst:
2014-12-01 23:55:08 +01:00
case ActLstStd:
case ActLstTch:
2016-06-24 20:34:58 +02:00
Sco_PutParamScope ("ScopeUsr",Gbl.Scope.Current);
2014-12-01 23:55:08 +01:00
break;
case ActSeeOneAtt:
case ActRecAttStd:
Att_PutParamAttCod (Gbl.AttEvents.AttCod);
break;
case ActReqMsgUsr:
Usr_PutHiddenParUsrCodAll (NextAction,Gbl.Usrs.Select.All);
2015-03-03 19:21:59 +01:00
Msg_PutHiddenParamOtherRecipients ();
2016-07-01 14:40:01 +02:00
Msg_PutHiddenParamsSubjectAndContent ();
2015-12-22 13:22:35 +01:00
if (Gbl.Msg.Reply.IsReply)
2014-12-01 23:55:08 +01:00
{
Par_PutHiddenParamChar ("IsReply",'Y');
2015-12-22 13:22:35 +01:00
Msg_PutHiddenParamMsgCod (Gbl.Msg.Reply.OriginalMsgCod);
2015-12-24 00:31:45 +01:00
}
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
2015-12-24 13:02:02 +01:00
{
2015-04-02 18:39:49 +02:00
Usr_PutParamOtherUsrCodEncrypted ();
2015-12-24 13:02:02 +01:00
if (Gbl.Msg.ShowOnlyOneRecipient)
Par_PutHiddenParamChar ("ShowOnlyOneRecipient",'Y');
}
2014-12-01 23:55:08 +01:00
break;
2015-10-19 21:49:45 +02:00
case ActSeeUseGbl:
2016-11-27 14:10:31 +01:00
/* Used in selector of "Class photo"/"List"
in STATS > Figures > Institutions */
2016-11-06 15:36:26 +01:00
Sta_PutHiddenParamFigures ();
2015-10-19 21:49:45 +02:00
break;
2014-12-01 23:55:08 +01:00
case ActSeePhoDeg:
Pho_PutHiddenParamTypeOfAvg ();
Pho_PutHiddenParamPhotoSize ();
Pho_PutHiddenParamOrderDegrees ();
break;
default:
break;
}
}
/*****************************************************************************/
/******************** List users to select some of them **********************/
/*****************************************************************************/
void Usr_ListUsersToSelect (Rol_Role_t Role)
{
/***** If there are no users, don't list anything *****/
2016-06-23 13:51:37 +02:00
if (!Gbl.Usrs.LstUsrs[Role].NumUsrs)
return;
2014-12-01 23:55:08 +01:00
/***** Put a row to select all users *****/
2016-12-26 16:58:49 +01:00
Usr_PutCheckboxToSelectAllUsers (Role);
2014-12-01 23:55:08 +01:00
/***** Draw the classphoto/list *****/
switch (Gbl.Usrs.Me.ListType)
{
2017-01-29 21:41:08 +01:00
case Usr_LIST_AS_CLASS_PHOTO:
2014-12-01 23:55:08 +01:00
Usr_DrawClassPhoto (Usr_CLASS_PHOTO_SEL,Role);
break;
2017-01-29 21:41:08 +01:00
case Usr_LIST_AS_LISTING:
2014-12-01 23:55:08 +01:00
Usr_ListUsrsForSelection (Role);
break;
2017-01-29 21:41:08 +01:00
default:
break;
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
2016-12-26 16:58:49 +01:00
/******** Put a row, in a classphoto or a list, to select all users **********/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-12-26 16:58:49 +01:00
void Usr_PutCheckboxToSelectAllUsers (Rol_Role_t Role)
2014-12-01 23:55:08 +01:00
{
2015-03-12 14:45:40 +01:00
extern const char *Txt_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2014-12-01 23:55:08 +01:00
extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
Usr_Sex_t Sex;
fprintf (Gbl.F.Out,"<tr>"
2016-12-21 00:06:11 +01:00
"<th colspan=\"%u\" class=\"LEFT_MIDDLE LIGHT_BLUE\">"
"<label>",
2015-09-04 19:26:08 +02:00
Usr_GetColumnsForSelectUsrs ());
2015-04-07 21:44:24 +02:00
if (Role == Rol_STUDENT)
2016-12-21 00:06:11 +01:00
fprintf (Gbl.F.Out,"<input type=\"checkbox\""
" name=\"SEL_UNSEL_STDS\" value=\"\""
2015-09-06 20:02:14 +02:00
" onclick=\"togglecheckChildren(this,'UsrCodStd')\" />");
2015-09-30 23:10:15 +02:00
else // Role == Rol_TEACHER or Role == Rol__GUEST_
2016-12-21 00:06:11 +01:00
fprintf (Gbl.F.Out,"<input type=\"checkbox\""
" name=\"SEL_UNSEL_TCHS\" value=\"\""
2015-09-06 20:02:14 +02:00
" onclick=\"togglecheckChildren(this,'UsrCodTch')\" />");
2016-06-23 13:10:43 +02:00
Sex = Usr_GetSexOfUsrsLst (Role);
2015-09-05 19:19:39 +02:00
fprintf (Gbl.F.Out,"%s:"
2016-12-21 00:06:11 +01:00
"</label>"
2015-09-05 19:19:39 +02:00
"</th>"
2014-12-01 23:55:08 +01:00
"</tr>",
2016-06-23 13:10:43 +02:00
Gbl.Usrs.LstUsrs[Role].NumUsrs == 1 ? Txt_ROLES_SINGUL_Abc[Role][Sex] :
Txt_ROLES_PLURAL_Abc[Role][Sex]);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************** Get sex of a list of users ***********************/
/*****************************************************************************/
2016-06-23 13:10:43 +02:00
static Usr_Sex_t Usr_GetSexOfUsrsLst (Rol_Role_t Role)
2014-12-01 23:55:08 +01:00
{
Usr_Sex_t Sex;
unsigned NumUsr;
/***** If no users, sex is undefined *****/
2016-06-23 13:10:43 +02:00
if (Gbl.Usrs.LstUsrs[Role].NumUsrs == 0)
2014-12-01 23:55:08 +01:00
return Usr_SEX_UNKNOWN;
/***** Initialize sex to that of first user in list *****/
2016-06-23 13:10:43 +02:00
Sex = Gbl.Usrs.LstUsrs[Role].Lst[0].Sex;
2014-12-01 23:55:08 +01:00
/***** Search if there is one user at least with different sex than the first one *****/
for (NumUsr = 1;
2016-06-23 13:10:43 +02:00
NumUsr < Gbl.Usrs.LstUsrs[Role].NumUsrs;
2014-12-01 23:55:08 +01:00
NumUsr++)
2016-06-23 13:10:43 +02:00
if (Gbl.Usrs.LstUsrs[Role].Lst[NumUsr].Sex != Sex)
2014-12-01 23:55:08 +01:00
return Usr_SEX_UNKNOWN;
return Sex;
}
/*****************************************************************************/
/**** Get number of table columns, in classphoto or list, to select users ****/
/*****************************************************************************/
unsigned Usr_GetColumnsForSelectUsrs (void)
{
2017-01-29 21:41:08 +01:00
return (Gbl.Usrs.Me.ListType == Usr_LIST_AS_CLASS_PHOTO) ? Gbl.Usrs.ClassPhoto.Cols :
(Gbl.Usrs.Listing.WithPhotos ? 1 + Usr_NUM_MAIN_FIELDS_DATA_USR :
Usr_NUM_MAIN_FIELDS_DATA_USR);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******* Put a checkbox, in a classphoto or a list, to select a user *********/
/*****************************************************************************/
2015-09-30 23:10:15 +02:00
static void Usr_PutCheckboxToSelectUser (struct UsrData *UsrDat,bool UsrIsTheMsgSender)
2014-12-01 23:55:08 +01:00
{
2015-09-30 23:10:15 +02:00
bool CheckboxChecked;
/***** Check box *****/
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<input type=\"checkbox\" name=\"");
2015-09-30 23:10:15 +02:00
if (UsrDat->RoleInCurrentCrsDB == Rol_STUDENT)
fprintf (Gbl.F.Out,"UsrCodStd\" value=\"%s\""
" onclick=\"checkParent(this,'SEL_UNSEL_STDS')\"",
UsrDat->EncryptedUsrCod);
else // Role == Rol_TEACHER or Role == Rol__GUEST_
fprintf (Gbl.F.Out,"UsrCodTch\" value=\"%s\""
" onclick=\"checkParent(this,'SEL_UNSEL_TCHS')\"",
UsrDat->EncryptedUsrCod);
/***** Check box must be checked? *****/
CheckboxChecked = false;
if (UsrIsTheMsgSender)
CheckboxChecked = true;
2014-12-01 23:55:08 +01:00
else
2015-09-30 23:10:15 +02:00
/* Check if user is in lists of selected users */
CheckboxChecked = Usr_FindUsrCodInListOfSelectedUsrs (UsrDat->EncryptedUsrCod);
if (CheckboxChecked)
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out," checked=\"checked\"");
2015-09-30 23:10:15 +02:00
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out," />");
}
/*****************************************************************************/
/********* Put a checkbox to select whether list users with photos ***********/
/*****************************************************************************/
2015-10-02 01:04:28 +02:00
static void Usr_PutCheckboxListWithPhotos (void)
2014-12-01 23:55:08 +01:00
{
2015-07-28 00:16:09 +02:00
extern const char *The_ClassForm[The_NUM_THEMES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Display_photos;
Par_PutHiddenParamChar ("WithPhotosExists",'Y');
/***** Put checkbox to select whether list users with photos *****/
2016-12-26 16:58:49 +01:00
fprintf (Gbl.F.Out,"<label class=\"%s\">"
"<input type=\"checkbox\" name=\"WithPhotos\""
" value=\"Y\"",
The_ClassForm[Gbl.Prefs.Theme]);
2014-12-01 23:55:08 +01:00
if (Gbl.Usrs.Listing.WithPhotos)
fprintf (Gbl.F.Out," checked=\"checked\"");
2015-10-22 14:49:48 +02:00
fprintf (Gbl.F.Out," onclick=\"document.getElementById('%s').submit();\" />"
2016-12-26 16:58:49 +01:00
"%s"
"</label>",
Gbl.Form.Id,Txt_Display_photos);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********************** Set field names of user's data **********************/
/*****************************************************************************/
2016-06-16 14:34:17 +02:00
void Usr_SetUsrDatMainFieldNames (void)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_No_INDEX;
extern const char *Txt_Photo;
extern const char *Txt_ID;
extern const char *Txt_Surname_1;
extern const char *Txt_Surname_2;
extern const char *Txt_First_name;
extern const char *Txt_Institution;
/***** Initialize field names *****/
Usr_UsrDatMainFieldNames[0] = "&nbsp;";
Usr_UsrDatMainFieldNames[1] = Txt_No_INDEX;
Usr_UsrDatMainFieldNames[2] = Txt_Photo;
Usr_UsrDatMainFieldNames[3] = Txt_ID;
Usr_UsrDatMainFieldNames[4] = Txt_Surname_1;
Usr_UsrDatMainFieldNames[5] = Txt_Surname_2;
Usr_UsrDatMainFieldNames[6] = Txt_First_name;
2016-07-25 16:08:25 +02:00
Usr_UsrDatMainFieldNames[7] = Txt_Institution;
2014-12-01 23:55:08 +01:00
}
2016-06-16 18:32:12 +02:00
/*****************************************************************************/
/************ Write header with main field names of user's data **************/
/*****************************************************************************/
void Usr_WriteHeaderFieldsUsrDat (bool PutCheckBoxToSelectUsr)
{
unsigned NumCol;
fprintf (Gbl.F.Out,"<tr>");
/***** First column used for selection *****/
if (PutCheckBoxToSelectUsr)
fprintf (Gbl.F.Out,"<th class=\"LEFT_MIDDLE LIGHT_BLUE\">"
"</th>");
/***** Columns for user's data fields *****/
for (NumCol = 0;
NumCol < Usr_NUM_MAIN_FIELDS_DATA_USR;
NumCol++)
if (NumCol != 2 || Gbl.Usrs.Listing.WithPhotos) // Skip photo column if I don't want this column
fprintf (Gbl.F.Out,"<th class=\"LEFT_MIDDLE LIGHT_BLUE\">"
"%s&nbsp;"
"</th>",
Usr_UsrDatMainFieldNames[NumCol]);
fprintf (Gbl.F.Out,"</tr>");
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************** List guests' main data ***************************/
/*****************************************************************************/
static void Usr_ListMainDataGsts (bool PutCheckBoxToSelectUsr)
{
unsigned NumUsr;
struct UsrData UsrDat;
/***** Initialize field names *****/
Usr_SetUsrDatMainFieldNames ();
2016-06-23 13:10:43 +02:00
if (Gbl.Usrs.LstUsrs[Rol__GUEST_].NumUsrs)
2014-12-01 23:55:08 +01:00
{
/***** Heading row with column names *****/
2016-06-16 18:32:12 +02:00
Usr_WriteHeaderFieldsUsrDat (PutCheckBoxToSelectUsr); // Columns for the data
2014-12-01 23:55:08 +01:00
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
2016-07-25 21:08:53 +02:00
/***** List guests' data *****/
2016-06-16 11:28:20 +02:00
for (NumUsr = 0, Gbl.RowEvenOdd = 0;
2016-07-25 21:08:53 +02:00
NumUsr < Gbl.Usrs.LstUsrs[Rol__GUEST_].NumUsrs;
NumUsr++, Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd)
2014-12-01 23:55:08 +01:00
{
2016-07-25 21:08:53 +02:00
/* Copy user's basic data from list */
Usr_CopyBasicUsrDataFromList (&UsrDat,&Gbl.Usrs.LstUsrs[Rol__GUEST_].Lst[NumUsr]);
2016-06-16 11:28:20 +02:00
2016-07-25 21:08:53 +02:00
/* Get list of user's IDs */
ID_GetListIDsFromUsrCod (&UsrDat);
2016-07-27 14:58:26 +02:00
/* Show row for this guest */
2016-07-25 21:08:53 +02:00
Usr_WriteRowUsrMainData (NumUsr + 1,&UsrDat,true);
2014-12-01 23:55:08 +01:00
}
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}
2016-06-23 13:10:43 +02:00
else // Gbl.Usrs.LstUsrs[Rol__GUEST_].NumUsrs == 0
2015-04-07 21:44:24 +02:00
Usr_ShowWarningNoUsersFound (Rol__GUEST_);
2014-12-01 23:55:08 +01:00
2016-06-23 13:10:43 +02:00
/***** Free memory for guests list *****/
Usr_FreeUsrsList (Rol__GUEST_);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************************** List main students' data ************************/
/*****************************************************************************/
static void Usr_ListMainDataStds (bool PutCheckBoxToSelectUsr)
{
unsigned NumUsr;
char *GroupNames;
struct UsrData UsrDat;
/***** Initialize field names *****/
Usr_SetUsrDatMainFieldNames ();
GroupNames = NULL; // To avoid warning
2016-06-23 13:10:43 +02:00
if (Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs)
2014-12-01 23:55:08 +01:00
{
/***** Allocate memory for the string with the list of group names where student belongs to *****/
2017-03-07 11:03:05 +01:00
if ((GroupNames = (char *) malloc ((Grp_MAX_BYTES_GROUP_NAME + 3) *
2017-01-28 15:58:46 +01:00
Gbl.CurrentCrs.Grps.GrpTypes.NumGrpsTotal)) == NULL)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Not enough memory to store names of groups.");
/***** Start table with list of students *****/
if (!Gbl.Usrs.ClassPhoto.AllGroups)
{
fprintf (Gbl.F.Out,"<tr>"
2015-09-02 23:51:44 +02:00
"<td colspan=\"%u\" class=\"TIT CENTER_MIDDLE\">",
2014-12-01 23:55:08 +01:00
1 + Usr_NUM_MAIN_FIELDS_DATA_USR);
Grp_WriteNamesOfSelectedGrps ();
fprintf (Gbl.F.Out,"</td>"
"</tr>");
}
/***** Heading row with column names *****/
2016-06-16 18:32:12 +02:00
Usr_WriteHeaderFieldsUsrDat (PutCheckBoxToSelectUsr); // Columns for the data
2014-12-01 23:55:08 +01:00
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** List students' data *****/
2016-06-16 11:28:20 +02:00
for (NumUsr = 0, Gbl.RowEvenOdd = 0;
2016-07-25 21:08:53 +02:00
NumUsr < Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs;
NumUsr++, Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd)
2014-12-01 23:55:08 +01:00
{
2016-07-25 20:55:25 +02:00
/* Copy user's basic data from list */
Usr_CopyBasicUsrDataFromList (&UsrDat,&Gbl.Usrs.LstUsrs[Rol_STUDENT].Lst[NumUsr]);
2016-06-16 11:28:20 +02:00
2016-07-25 20:55:25 +02:00
/* Get list of user's IDs */
ID_GetListIDsFromUsrCod (&UsrDat);
2016-07-27 14:58:26 +02:00
/* Show row for this student */
2016-07-25 21:08:53 +02:00
Usr_WriteRowUsrMainData (NumUsr + 1,&UsrDat,PutCheckBoxToSelectUsr);
2014-12-01 23:55:08 +01:00
}
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
/***** Free memory used by the string with the list of group names where student belongs to *****/
free ((void *) GroupNames);
}
2016-06-23 13:10:43 +02:00
else // Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs == 0
2017-02-09 19:27:18 +01:00
{
/***** Show warning indicating no students found *****/
2015-04-07 21:44:24 +02:00
Usr_ShowWarningNoUsersFound (Rol_STUDENT);
2014-12-01 23:55:08 +01:00
2017-03-30 11:20:06 +02:00
/***** Button to enrol students *****/
Enr_PutButtonToEnrolStudents ();
2017-02-09 19:27:18 +01:00
}
2014-12-01 23:55:08 +01:00
/***** Free memory for students list *****/
2016-06-23 13:10:43 +02:00
Usr_FreeUsrsList (Rol_STUDENT);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************** List main teachers' data *************************/
/*****************************************************************************/
static void Usr_ListMainDataTchs (bool PutCheckBoxToSelectUsr)
{
unsigned NumColumns;
unsigned NumCol;
unsigned NumUsr;
struct UsrData UsrDat;
/***** Initialize field names *****/
Usr_SetUsrDatMainFieldNames ();
2016-06-23 13:10:43 +02:00
if (Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs)
2014-12-01 23:55:08 +01:00
{
/***** Initialize number of columns *****/
NumColumns = Usr_NUM_MAIN_FIELDS_DATA_USR;
/***** Heading row with column names *****/
/* Start row */
fprintf (Gbl.F.Out,"<tr>");
/* First column used for selection */
if (PutCheckBoxToSelectUsr)
2015-09-06 20:02:14 +02:00
fprintf (Gbl.F.Out,"<th class=\"LEFT_MIDDLE LIGHT_BLUE\">"
2014-12-26 16:55:46 +01:00
"&nbsp;"
2015-09-05 19:19:39 +02:00
"</th>");
2014-12-01 23:55:08 +01:00
/* Columns for the data */
for (NumCol = 0;
NumCol < NumColumns;
NumCol++)
if (NumCol != 2 || Gbl.Usrs.Listing.WithPhotos) // Skip photo column if I don't want this column
2015-09-06 20:02:14 +02:00
fprintf (Gbl.F.Out,"<th class=\"LEFT_MIDDLE LIGHT_BLUE\">"
2014-12-26 16:55:46 +01:00
"%s&nbsp;"
2015-09-05 19:19:39 +02:00
"</th>",
2015-09-04 19:26:08 +02:00
Usr_UsrDatMainFieldNames[NumCol]);
2014-12-01 23:55:08 +01:00
/* End row */
fprintf (Gbl.F.Out,"</tr>");
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
2016-07-25 21:08:53 +02:00
/***** List teachers' data *****/
2016-06-16 11:28:20 +02:00
for (NumUsr = 0, Gbl.RowEvenOdd = 0;
2016-07-25 21:08:53 +02:00
NumUsr < Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs;
NumUsr++, Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd)
2014-12-01 23:55:08 +01:00
{
2016-07-25 20:55:25 +02:00
/* Copy user's basic data from list */
Usr_CopyBasicUsrDataFromList (&UsrDat,&Gbl.Usrs.LstUsrs[Rol_TEACHER].Lst[NumUsr]);
2016-06-16 11:28:20 +02:00
2016-07-25 20:55:25 +02:00
/* Get list of user's IDs */
ID_GetListIDsFromUsrCod (&UsrDat);
2016-07-27 14:58:26 +02:00
/* Show row for this teacher */
2016-07-25 21:08:53 +02:00
Usr_WriteRowUsrMainData (NumUsr + 1,&UsrDat,PutCheckBoxToSelectUsr);
2014-12-01 23:55:08 +01:00
}
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}
2016-06-23 13:10:43 +02:00
else // Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs == 0
2017-02-09 19:27:18 +01:00
{
/***** Show warning indicating no teachers found *****/
Usr_ShowWarningNoUsersFound (Rol_TEACHER);
2017-03-30 11:20:06 +02:00
/***** Button to enrol a teacher *****/
Enr_PutButtonToEnrolOneTeacher ();
2017-02-09 19:27:18 +01:00
}
2014-12-01 23:55:08 +01:00
/***** Free memory for teachers list *****/
2016-06-23 13:10:43 +02:00
Usr_FreeUsrsList (Rol_TEACHER);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************************** List guests' data *****************************/
/*****************************************************************************/
void Usr_ListAllDataGsts (void)
{
extern const char *Txt_Photo;
extern const char *Txt_ID;
extern const char *Txt_Surname_1;
extern const char *Txt_Surname_2;
extern const char *Txt_First_name;
extern const char *Txt_Institution;
2016-07-25 16:08:25 +02:00
extern const char *Txt_Email;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Centre;
extern const char *Txt_Department;
extern const char *Txt_Office;
extern const char *Txt_Phone;
extern const char *Txt_Local_address;
extern const char *Txt_Family_address;
extern const char *Txt_Place_of_origin;
extern const char *Txt_Date_of_birth;
unsigned NumColumnsCommonCard;
unsigned NumCol;
unsigned NumUsr;
struct UsrData UsrDat;
2016-07-25 16:08:25 +02:00
const char *FieldNames[Usr_NUM_ALL_FIELDS_DATA_GST];
2014-12-01 23:55:08 +01:00
/***** Initialize field names *****/
FieldNames[ 0] = Txt_Photo;
FieldNames[ 1] = Txt_ID;
FieldNames[ 2] = Txt_Surname_1;
FieldNames[ 3] = Txt_Surname_2;
FieldNames[ 4] = Txt_First_name;
2016-07-27 14:58:26 +02:00
FieldNames[ 5] = Txt_Email;
FieldNames[ 6] = Txt_Institution;
2014-12-01 23:55:08 +01:00
FieldNames[ 7] = Txt_Centre;
FieldNames[ 8] = Txt_Department;
FieldNames[ 9] = Txt_Office;
FieldNames[10] = Txt_Phone;
FieldNames[11] = Txt_Local_address;
FieldNames[12] = Txt_Phone;
FieldNames[13] = Txt_Family_address;
FieldNames[14] = Txt_Phone;
FieldNames[15] = Txt_Place_of_origin;
FieldNames[16] = Txt_Date_of_birth;
/***** Get and update type of list,
number of columns in class photo
and preference about view photos *****/
Usr_GetAndUpdatePrefsAboutUsrList ();
/***** Get scope *****/
Sco_SetScopesForListingGuests ();
2016-06-24 20:34:58 +02:00
Sco_GetScope ("ScopeUsr");
2014-12-01 23:55:08 +01:00
2017-01-28 17:17:35 +01:00
/****** Get list of guests ******/
2014-12-01 23:55:08 +01:00
Usr_GetGstsLst (Gbl.Scope.Current);
2016-06-23 13:10:43 +02:00
if (Gbl.Usrs.LstUsrs[Rol__GUEST_].NumUsrs)
2014-12-01 23:55:08 +01:00
{
/***** Set number of columns *****/
2016-07-25 16:08:25 +02:00
NumColumnsCommonCard = Usr_NUM_ALL_FIELDS_DATA_GST;
2014-12-01 23:55:08 +01:00
/***** Start table with list of guests *****/
2017-05-01 12:36:24 +02:00
Lay_StartTableWide (0);
2014-12-01 23:55:08 +01:00
/* Start row */
2017-05-01 12:36:24 +02:00
fprintf (Gbl.F.Out,"<tr>");
2014-12-01 23:55:08 +01:00
2014-12-08 17:35:48 +01:00
/* Columns for the data */
2014-12-01 23:55:08 +01:00
for (NumCol = (Gbl.Usrs.Listing.WithPhotos ? 0 :
1);
NumCol < NumColumnsCommonCard;
NumCol++)
2015-09-06 20:02:14 +02:00
fprintf (Gbl.F.Out,"<th class=\"LEFT_MIDDLE LIGHT_BLUE\">"
2014-12-26 16:55:46 +01:00
"%s&nbsp;"
2015-09-05 19:19:39 +02:00
"</th>",
2015-09-04 19:26:08 +02:00
FieldNames[NumCol]);
2014-12-01 23:55:08 +01:00
/* End row */
fprintf (Gbl.F.Out,"</tr>");
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** List guests' data *****/
2016-06-16 11:28:20 +02:00
for (NumUsr = 0, Gbl.RowEvenOdd = 0;
2016-06-23 13:10:43 +02:00
NumUsr < Gbl.Usrs.LstUsrs[Rol__GUEST_].NumUsrs; )
2014-12-01 23:55:08 +01:00
{
2016-06-23 13:10:43 +02:00
UsrDat.UsrCod = Gbl.Usrs.LstUsrs[Rol__GUEST_].Lst[NumUsr].UsrCod;
2014-12-01 23:55:08 +01:00
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) // If user's data exist...
{
UsrDat.Accepted = false; // Guests have no courses,...
// ...so they have not accepted...
// ...inscription in any course
NumUsr++;
Usr_WriteRowGstAllData (&UsrDat);
2016-06-16 11:28:20 +02:00
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
2014-12-01 23:55:08 +01:00
}
}
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
/***** End of table *****/
2017-05-01 12:36:24 +02:00
Lay_EndTable ();
2014-12-01 23:55:08 +01:00
}
2016-06-23 13:10:43 +02:00
else // Gbl.Usrs.LstUsrs[Rol__GUEST_].NumUsrs == 0
2015-04-07 21:44:24 +02:00
Usr_ShowWarningNoUsersFound (Rol__GUEST_);
2014-12-01 23:55:08 +01:00
2016-06-23 13:10:43 +02:00
/***** Free memory for guests list *****/
Usr_FreeUsrsList (Rol__GUEST_);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************************** List students' data ***************************/
/*****************************************************************************/
void Usr_ListAllDataStds (void)
{
extern const char *Txt_Photo;
extern const char *Txt_ID;
extern const char *Txt_Surname_1;
extern const char *Txt_Surname_2;
extern const char *Txt_First_name;
extern const char *Txt_Institution;
2016-07-25 16:08:25 +02:00
extern const char *Txt_Email;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Local_address;
extern const char *Txt_Phone;
extern const char *Txt_Family_address;
extern const char *Txt_Place_of_origin;
extern const char *Txt_Date_of_birth;
extern const char *Txt_Group;
2014-12-12 18:50:36 +01:00
extern const char *Txt_RECORD_FIELD_VISIBILITY_RECORD[Rec_NUM_TYPES_VISIBILITY];
2014-12-01 23:55:08 +01:00
unsigned NumColumnsCommonCard;
unsigned NumColumnsCardAndGroups;
unsigned NumColumnsTotal;
unsigned NumCol;
unsigned NumUsr;
char *GroupNames;
unsigned NumGrpTyp,NumField;
struct UsrData UsrDat;
const char *FieldNames[Usr_NUM_ALL_FIELDS_DATA_STD];
2017-01-16 01:51:01 +01:00
size_t Length;
2014-12-01 23:55:08 +01:00
/***** Initialize field names *****/
FieldNames[ 0] = Txt_Photo;
FieldNames[ 1] = Txt_ID;
FieldNames[ 2] = Txt_Surname_1;
FieldNames[ 3] = Txt_Surname_2;
FieldNames[ 4] = Txt_First_name;
2016-07-27 14:58:26 +02:00
FieldNames[ 5] = Txt_Email;
FieldNames[ 6] = Txt_Institution;
2014-12-01 23:55:08 +01:00
FieldNames[ 7] = Txt_Local_address;
FieldNames[ 8] = Txt_Phone;
FieldNames[ 9] = Txt_Family_address;
FieldNames[10] = Txt_Phone;
FieldNames[11] = Txt_Place_of_origin;
FieldNames[12] = Txt_Date_of_birth;
GroupNames = NULL; // To avoid warning
/***** Get and update type of list,
number of columns in class photo
and preference about view photos *****/
Usr_GetAndUpdatePrefsAboutUsrList ();
/***** Get scope *****/
Sco_SetScopesForListingStudents ();
2016-06-24 20:34:58 +02:00
Sco_GetScope ("ScopeUsr");
2014-12-01 23:55:08 +01:00
2016-11-27 12:45:42 +01:00
/***** If the scope is the current course... *****/
2016-11-25 03:21:02 +01:00
if (Gbl.Scope.Current == Sco_SCOPE_CRS)
2016-11-27 12:45:42 +01:00
{
/* Get list of groups types and groups in current course
This is necessary to show columns with group selection */
Grp_GetListGrpTypesInThisCrs (Grp_ONLY_GROUP_TYPES_WITH_GROUPS);
/* Get groups to show */
2016-11-25 03:21:02 +01:00
Grp_GetParCodsSeveralGrpsToShowUsrs ();
2016-11-27 12:45:42 +01:00
}
2016-11-25 03:21:02 +01:00
2017-01-28 17:17:35 +01:00
/****** Get list of students in current course ******/
2016-06-23 13:10:43 +02:00
Usr_GetListUsrs (Rol_STUDENT,Gbl.Scope.Current);
2014-12-01 23:55:08 +01:00
2016-06-23 13:10:43 +02:00
if (Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs)
2014-12-01 23:55:08 +01:00
{
2015-02-01 20:17:24 +01:00
if (Gbl.Scope.Current == Sco_SCOPE_CRS)
2014-12-01 23:55:08 +01:00
/***** Get list of record fields in current course *****/
Rec_GetListRecordFieldsInCurrentCrs ();
/***** Set number of columns *****/
NumColumnsCommonCard = Usr_NUM_ALL_FIELDS_DATA_STD;
2015-02-01 20:17:24 +01:00
if (Gbl.Scope.Current == Sco_SCOPE_CRS)
2014-12-01 23:55:08 +01:00
{
NumColumnsCardAndGroups = NumColumnsCommonCard + Gbl.CurrentCrs.Grps.GrpTypes.Num;
NumColumnsTotal = NumColumnsCardAndGroups + Gbl.CurrentCrs.Records.LstFields.Num;
}
else
NumColumnsTotal = NumColumnsCardAndGroups = NumColumnsCommonCard;
/***** Allocate memory for the string with the list of group names where student belongs to *****/
2015-02-01 20:17:24 +01:00
if (Gbl.Scope.Current == Sco_SCOPE_CRS)
2017-01-16 01:51:01 +01:00
{
2017-03-07 11:03:05 +01:00
Length = (Grp_MAX_BYTES_GROUP_NAME + 2) * Gbl.CurrentCrs.Grps.GrpTypes.NumGrpsTotal;
2017-01-16 01:51:01 +01:00
if ((GroupNames = (char *) malloc (Length + 1)) == NULL)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Not enough memory to store names of groups.");
2017-01-16 01:51:01 +01:00
}
2014-12-01 23:55:08 +01:00
/***** Start table with list of students *****/
2017-05-01 12:36:24 +02:00
Lay_StartTableWide (0);
2014-12-01 23:55:08 +01:00
if (!Gbl.Usrs.ClassPhoto.AllGroups)
{
fprintf (Gbl.F.Out,"<tr>"
2015-09-02 23:51:44 +02:00
"<td colspan=\"%u\" class=\"TIT CENTER_MIDDLE\">",
2014-12-01 23:55:08 +01:00
NumColumnsTotal);
Grp_WriteNamesOfSelectedGrps ();
fprintf (Gbl.F.Out,"</td>"
"</tr>");
}
/***** Heading row with column names *****/
/* Start row */
fprintf (Gbl.F.Out,"<tr>");
2015-01-02 18:05:56 +01:00
/* 1. Columns for the data */
2014-12-01 23:55:08 +01:00
for (NumCol = (Gbl.Usrs.Listing.WithPhotos ? 0 :
1);
NumCol < NumColumnsCommonCard;
NumCol++)
2015-09-06 20:02:14 +02:00
fprintf (Gbl.F.Out,"<th class=\"LEFT_MIDDLE LIGHT_BLUE\">"
2014-12-26 16:55:46 +01:00
"%s&nbsp;"
2015-09-05 19:19:39 +02:00
"</th>",
2015-09-04 19:26:08 +02:00
FieldNames[NumCol]);
2014-12-01 23:55:08 +01:00
/* 2. Columns for the groups */
2015-02-01 20:17:24 +01:00
if (Gbl.Scope.Current == Sco_SCOPE_CRS)
2014-12-01 23:55:08 +01:00
{
if (Gbl.CurrentCrs.Grps.GrpTypes.Num)
for (NumGrpTyp = 0;
NumGrpTyp < Gbl.CurrentCrs.Grps.GrpTypes.Num;
NumGrpTyp++)
if (Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].NumGrps) // If current course tiene groups of este type
2015-09-06 20:02:14 +02:00
fprintf (Gbl.F.Out,"<th class=\"LEFT_MIDDLE LIGHT_BLUE\">"
2014-12-26 16:55:46 +01:00
"%s %s&nbsp;"
2015-09-05 19:19:39 +02:00
"</th>",
2015-09-04 19:26:08 +02:00
Txt_Group,
2014-12-01 23:55:08 +01:00
Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].GrpTypName);
if (Gbl.CurrentCrs.Records.LstFields.Num)
{
/* 3. Names of record fields that depend on the course */
for (NumField = 0;
NumField < Gbl.CurrentCrs.Records.LstFields.Num;
NumField++)
2015-09-06 20:02:14 +02:00
fprintf (Gbl.F.Out,"<th class=\"LEFT_MIDDLE LIGHT_BLUE\">"
2014-12-26 16:55:46 +01:00
"%s&nbsp;"
2015-09-05 19:19:39 +02:00
"</th>",
2015-09-04 19:26:08 +02:00
Gbl.CurrentCrs.Records.LstFields.Lst[NumField].Name);
2014-12-01 23:55:08 +01:00
/* 4. Visibility type for the record fields that depend on the course, in other row */
2015-09-05 19:19:39 +02:00
fprintf (Gbl.F.Out,"</tr>"
"<tr>");
2014-12-01 23:55:08 +01:00
for (NumCol = 0;
NumCol < NumColumnsCardAndGroups;
NumCol++)
if (NumCol != 1 || Gbl.Usrs.Listing.WithPhotos) // Skip photo column if I don't want it in listing
2015-09-04 19:26:08 +02:00
fprintf (Gbl.F.Out,"<td class=\"VERY_LIGHT_BLUE\">"
"</td>");
2014-12-01 23:55:08 +01:00
for (NumField = 0;
NumField < Gbl.CurrentCrs.Records.LstFields.Num;
NumField++)
2015-09-06 20:02:14 +02:00
fprintf (Gbl.F.Out,"<th class=\"LEFT_MIDDLE VERY_LIGHT_BLUE\">"
2014-12-26 16:55:46 +01:00
"(%s)&nbsp;"
2015-09-05 19:19:39 +02:00
"</th>",
2014-12-26 16:55:46 +01:00
Txt_RECORD_FIELD_VISIBILITY_RECORD[Gbl.CurrentCrs.Records.LstFields.Lst[NumField].Visibility]);
2014-12-01 23:55:08 +01:00
}
}
/* End row */
fprintf (Gbl.F.Out,"</tr>");
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** List students' data *****/
2016-06-16 11:28:20 +02:00
for (NumUsr = 0, Gbl.RowEvenOdd = 0;
2016-06-23 13:10:43 +02:00
NumUsr < Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs; )
2014-12-01 23:55:08 +01:00
{
2016-06-23 13:10:43 +02:00
UsrDat.UsrCod = Gbl.Usrs.LstUsrs[Rol_STUDENT].Lst[NumUsr].UsrCod;
2014-12-01 23:55:08 +01:00
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) // If user's data exist...
{
2016-06-23 13:10:43 +02:00
UsrDat.Accepted = Gbl.Usrs.LstUsrs[Rol_STUDENT].Lst[NumUsr].Accepted;
2014-12-01 23:55:08 +01:00
NumUsr++;
Usr_WriteRowStdAllData (&UsrDat,GroupNames);
2016-06-16 11:28:20 +02:00
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
2014-12-01 23:55:08 +01:00
}
}
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
/***** End of table *****/
2017-05-01 12:36:24 +02:00
Lay_EndTable ();
2014-12-01 23:55:08 +01:00
/***** Free memory used by the string with the list of group names where student belongs to *****/
2015-02-01 20:17:24 +01:00
if (Gbl.Scope.Current == Sco_SCOPE_CRS)
2014-12-01 23:55:08 +01:00
free ((void *) GroupNames);
}
2016-06-23 13:10:43 +02:00
else // Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs == 0
2015-04-07 21:44:24 +02:00
Usr_ShowWarningNoUsersFound (Rol_STUDENT);
2014-12-01 23:55:08 +01:00
/***** Free memory for list of selected groups *****/
Grp_FreeListCodSelectedGrps ();
/***** Free memory for students list *****/
2016-06-23 13:10:43 +02:00
Usr_FreeUsrsList (Rol_STUDENT);
2014-12-01 23:55:08 +01:00
/***** Free list of groups types and groups in current course *****/
Grp_FreeListGrpTypesAndGrps ();
}
/*****************************************************************************/
/*************** List users (of current course) for selection ****************/
/*****************************************************************************/
void Usr_ListUsrsForSelection (Rol_Role_t Role)
{
unsigned NumUsr;
struct UsrData UsrDat;
/***** Initialize field names *****/
Usr_SetUsrDatMainFieldNames ();
/***** Heading row with column names *****/
2016-06-16 18:32:12 +02:00
Usr_WriteHeaderFieldsUsrDat (true); // Columns for the data
2014-12-01 23:55:08 +01:00
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** List users' data *****/
2016-06-23 13:51:37 +02:00
for (NumUsr = 0, Gbl.RowEvenOdd = 0;
NumUsr < Gbl.Usrs.LstUsrs[Role].NumUsrs; )
2014-12-01 23:55:08 +01:00
{
2016-06-23 13:51:37 +02:00
UsrDat.UsrCod = Gbl.Usrs.LstUsrs[Role].Lst[NumUsr].UsrCod;
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) // If user's data exist...
{
UsrDat.Accepted = Gbl.Usrs.LstUsrs[Role].Lst[NumUsr].Accepted;
Usr_WriteRowUsrMainData (++NumUsr,&UsrDat,true);
2016-06-16 11:28:20 +02:00
2016-06-23 13:51:37 +02:00
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
}
2014-12-01 23:55:08 +01:00
}
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}
/*****************************************************************************/
/************************** List all teachers' data **************************/
/*****************************************************************************/
void Usr_ListAllDataTchs (void)
{
extern const char *Txt_Photo;
extern const char *Txt_ID;
extern const char *Txt_Surname_1;
extern const char *Txt_Surname_2;
extern const char *Txt_First_name;
extern const char *Txt_Institution;
2016-07-25 16:08:25 +02:00
extern const char *Txt_Email;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Centre;
extern const char *Txt_Department;
extern const char *Txt_Office;
extern const char *Txt_Phone;
unsigned NumColumns;
unsigned NumCol;
unsigned NumUsr;
struct UsrData UsrDat;
const char *FieldNames[Usr_NUM_ALL_FIELDS_DATA_TCH];
/***** Initialize field names *****/
FieldNames[ 0] = Txt_Photo;
FieldNames[ 1] = Txt_ID;
FieldNames[ 2] = Txt_Surname_1;
FieldNames[ 3] = Txt_Surname_2;
FieldNames[ 4] = Txt_First_name;
2016-07-27 14:58:26 +02:00
FieldNames[ 5] = Txt_Email;
FieldNames[ 6] = Txt_Institution;
2014-12-01 23:55:08 +01:00
FieldNames[ 7] = Txt_Centre;
FieldNames[ 8] = Txt_Department;
FieldNames[ 9] = Txt_Office;
FieldNames[10] = Txt_Phone;
/***** Get and update type of list,
number of columns in class photo
and preference about view photos *****/
Usr_GetAndUpdatePrefsAboutUsrList ();
/***** Get scope *****/
2015-10-19 21:49:45 +02:00
Gbl.Scope.Allowed = 1 << Sco_SCOPE_SYS |
1 << Sco_SCOPE_CTY |
2015-02-01 20:17:24 +01:00
1 << Sco_SCOPE_INS |
2015-10-19 21:49:45 +02:00
1 << Sco_SCOPE_CTR |
1 << Sco_SCOPE_DEG |
2015-02-01 20:17:24 +01:00
1 << Sco_SCOPE_CRS;
Gbl.Scope.Default = Sco_SCOPE_CRS;
2016-06-24 20:34:58 +02:00
Sco_GetScope ("ScopeUsr");
2014-12-01 23:55:08 +01:00
2017-01-28 17:17:35 +01:00
/***** Get list of teachers *****/
2016-06-23 13:10:43 +02:00
Usr_GetListUsrs (Rol_TEACHER,Gbl.Scope.Current);
2014-12-01 23:55:08 +01:00
2016-06-23 13:10:43 +02:00
if (Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs)
2014-12-01 23:55:08 +01:00
{
/***** Initialize number of columns *****/
NumColumns = Usr_NUM_ALL_FIELDS_DATA_TCH;
/***** Start table with list of teachers *****/
2017-05-01 12:36:24 +02:00
Lay_StartTableWide (0);
2014-12-01 23:55:08 +01:00
/* Start row */
2017-05-01 12:36:24 +02:00
fprintf (Gbl.F.Out,"<tr>");
2014-12-01 23:55:08 +01:00
for (NumCol = (Gbl.Usrs.Listing.WithPhotos ? 0 :
1);
NumCol < NumColumns;
NumCol++)
2015-09-06 20:02:14 +02:00
fprintf (Gbl.F.Out,"<th class=\"LEFT_MIDDLE LIGHT_BLUE\">"
2014-12-26 16:55:46 +01:00
"%s&nbsp;"
2015-09-05 19:19:39 +02:00
"</th>",
2015-09-04 19:26:08 +02:00
FieldNames[NumCol]);
2014-12-01 23:55:08 +01:00
/* End row */
fprintf (Gbl.F.Out,"</tr>");
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** List data of teachers *****/
2016-06-16 11:28:20 +02:00
for (NumUsr = 0, Gbl.RowEvenOdd = 0;
2016-06-23 13:10:43 +02:00
NumUsr < Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs; )
2014-12-01 23:55:08 +01:00
{
2016-06-23 13:10:43 +02:00
UsrDat.UsrCod = Gbl.Usrs.LstUsrs[Rol_TEACHER].Lst[NumUsr].UsrCod;
2014-12-01 23:55:08 +01:00
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) // If user's data exist...
{
2016-06-23 13:10:43 +02:00
UsrDat.Accepted = Gbl.Usrs.LstUsrs[Rol_TEACHER].Lst[NumUsr].Accepted;
2014-12-01 23:55:08 +01:00
NumUsr++;
Usr_WriteRowTchAllData (&UsrDat);
2016-06-16 11:28:20 +02:00
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
2014-12-01 23:55:08 +01:00
}
}
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
/***** End of table *****/
2017-05-01 12:36:24 +02:00
Lay_EndTable ();
2014-12-01 23:55:08 +01:00
}
2016-06-23 13:10:43 +02:00
else // Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs == 0
2017-02-09 19:27:18 +01:00
/***** Show warning indicating no teachers found *****/
Usr_ShowWarningNoUsersFound (Rol_TEACHER);
2014-12-01 23:55:08 +01:00
/***** Free memory for teachers list *****/
2016-06-23 13:10:43 +02:00
Usr_FreeUsrsList (Rol_TEACHER);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************************** List users found *****************************/
/*****************************************************************************/
// Returns number of users found
2017-03-13 20:32:03 +01:00
unsigned Usr_ListUsrsFound (Rol_Role_t Role,const char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY])
2014-12-01 23:55:08 +01:00
{
2016-06-27 12:35:15 +02:00
extern const char *Txt_user[Usr_NUM_SEXS];
extern const char *Txt_users[Usr_NUM_SEXS];
2014-12-01 23:55:08 +01:00
extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2015-03-12 14:45:40 +01:00
extern const char *Txt_ROLES_SINGUL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2014-12-01 23:55:08 +01:00
extern const char *Txt_ROLES_PLURAL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2016-06-29 18:27:49 +02:00
unsigned NumUsrs;
2014-12-01 23:55:08 +01:00
unsigned NumUsr;
struct UsrData UsrDat;
2016-06-29 18:27:49 +02:00
Usr_Sex_t Sex;
2016-07-25 20:24:07 +02:00
struct UsrInList *UsrInList;
2014-12-01 23:55:08 +01:00
/***** Initialize field names *****/
Usr_SetUsrDatMainFieldNames ();
2016-06-24 15:31:09 +02:00
/***** Create temporary table with candidate users *****/
// Search is faster (aproximately x2) using temporary tables
2016-06-29 18:27:49 +02:00
Usr_CreateTmpTableAndSearchCandidateUsrs (SearchQuery);
2016-06-24 15:31:09 +02:00
2016-06-21 10:32:06 +02:00
/***** Search for users *****/
2016-06-24 15:31:09 +02:00
Usr_SearchListUsrs (Role);
2016-06-23 13:10:43 +02:00
if ((NumUsrs = Gbl.Usrs.LstUsrs[Role].NumUsrs))
2014-12-01 23:55:08 +01:00
{
/***** Write heading *****/
/* Number of users found */
2016-06-23 13:10:43 +02:00
Sex = Usr_GetSexOfUsrsLst (Role);
2016-04-17 23:51:14 +02:00
sprintf (Gbl.Title,"%u %s",
2016-06-27 12:35:15 +02:00
NumUsrs,(Role == Rol_UNKNOWN) ? ((NumUsrs == 1) ? Txt_user[Sex] :
Txt_users[Sex]) :
((NumUsrs == 1) ? Txt_ROLES_SINGUL_abc[Role][Sex] :
Txt_ROLES_PLURAL_abc[Role][Sex]));
2016-11-13 23:52:51 +01:00
Lay_StartRoundFrameTable (NULL,Gbl.Title,NULL,NULL,2);
2014-12-01 23:55:08 +01:00
/***** Heading row with column names *****/
2016-06-16 18:32:12 +02:00
Gbl.Usrs.Listing.WithPhotos = true;
Usr_WriteHeaderFieldsUsrDat (false); // Columns for the data
2014-12-01 23:55:08 +01:00
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** List data of users *****/
2016-06-16 11:28:20 +02:00
for (NumUsr = 0, Gbl.RowEvenOdd = 0;
2014-12-01 23:55:08 +01:00
NumUsr < NumUsrs;
NumUsr++)
{
2016-07-25 20:24:07 +02:00
UsrInList = &Gbl.Usrs.LstUsrs[Role].Lst[NumUsr];
/* Copy user's basic data from list */
2016-07-25 20:55:25 +02:00
Usr_CopyBasicUsrDataFromList (&UsrDat,UsrInList);
2016-07-25 20:24:07 +02:00
/* Get list of user's IDs */
ID_GetListIDsFromUsrCod (&UsrDat);
/* Write data of this user */
Usr_WriteRowUsrMainData (NumUsr + 1,&UsrDat,false);
/* Write all the courses this user belongs to */
if (Role != Rol__GUEST_ && // Guests do not belong to any course
Gbl.Usrs.Me.LoggedRole >= Rol_DEG_ADM) // Only admins can view the courses
{
fprintf (Gbl.F.Out,"<tr>"
"<td colspan=\"2\" class=\"COLOR%u\"></td>"
"<td colspan=\"%u\" class=\"COLOR%u\">",
Gbl.RowEvenOdd,
Usr_NUM_MAIN_FIELDS_DATA_USR-2,
Gbl.RowEvenOdd);
2016-09-08 22:53:04 +02:00
if (Role == Rol_UNKNOWN)
{
Crs_GetAndWriteCrssOfAUsr (&UsrDat,Rol_TEACHER);
Crs_GetAndWriteCrssOfAUsr (&UsrDat,Rol_STUDENT);
}
else
Crs_GetAndWriteCrssOfAUsr (&UsrDat,Role);
2016-07-25 20:24:07 +02:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
}
2016-06-16 11:28:20 +02:00
2016-07-25 20:24:07 +02:00
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
2014-12-01 23:55:08 +01:00
}
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
2016-03-20 13:47:46 +01:00
/***** End table *****/
2015-04-12 18:01:06 +02:00
Lay_EndRoundFrameTable ();
2014-12-01 23:55:08 +01:00
}
/***** Free memory for teachers list *****/
2016-06-23 13:10:43 +02:00
Usr_FreeUsrsList (Role);
2014-12-01 23:55:08 +01:00
2016-06-29 18:27:49 +02:00
/***** Drop temporary table with candidate users *****/
2016-06-27 14:30:53 +02:00
Usr_DropTmpTableWithCandidateUsrs ();
2016-06-24 15:31:09 +02:00
2014-12-01 23:55:08 +01:00
return NumUsrs;
}
/*****************************************************************************/
/**************************** List administrators ****************************/
/*****************************************************************************/
void Usr_ListDataAdms (void)
{
2016-11-20 20:03:47 +01:00
extern const char *Hlp_USERS_Administrators;
2015-07-28 00:16:09 +02:00
extern const char *The_ClassForm[The_NUM_THEMES];
2015-04-12 18:01:06 +02:00
extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2016-03-28 00:31:49 +02:00
extern const char *Txt_Scope;
2014-12-01 23:55:08 +01:00
extern const char *Txt_No_INDEX;
extern const char *Txt_Photo;
extern const char *Txt_ID;
extern const char *Txt_Surname_1;
extern const char *Txt_Surname_2;
extern const char *Txt_First_name;
extern const char *Txt_Email;
extern const char *Txt_Institution;
unsigned NumCol;
unsigned NumUsr;
struct UsrData UsrDat;
const char *FieldNames[Usr_NUM_MAIN_FIELDS_DATA_ADM];
2015-09-12 14:12:40 +02:00
/***** Put contextual links *****/
2016-10-24 20:09:00 +02:00
if (Gbl.Usrs.Me.LoggedRole >= Rol_TEACHER)
2015-09-12 14:12:40 +02:00
{
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
2016-10-24 20:09:00 +02:00
if (Gbl.Usrs.Me.LoggedRole == Rol_SYS_ADM)
2016-11-20 20:03:47 +01:00
{
2016-10-24 20:09:00 +02:00
/* Put link to remove old users */
Usr_PutLinkToSeeGuests ();
2015-09-17 16:54:02 +02:00
2016-11-20 20:03:47 +01:00
/* Put link to list possible duplicate users */
Dup_PutLinkToListDupUsrs ();
}
2015-09-12 14:12:40 +02:00
/* Put link to go to admin one user */
2015-09-17 16:54:02 +02:00
Enr_PutLinkToAdminOneUsr (ActReqMdfOneOth);
2016-10-24 20:09:00 +02:00
if (Gbl.Usrs.Me.LoggedRole == Rol_SYS_ADM)
/* Put link to remove old users */
Enr_PutLinkToRemOldUsrs ();
2015-09-12 14:12:40 +02:00
fprintf (Gbl.F.Out,"</div>");
}
2014-12-01 23:55:08 +01:00
/***** Initialize field names *****/
FieldNames[0] = Txt_No_INDEX;
FieldNames[1] = Txt_Photo;
FieldNames[2] = Txt_ID;
FieldNames[3] = Txt_Surname_1;
FieldNames[4] = Txt_Surname_2;
FieldNames[5] = Txt_First_name;
2016-07-25 16:08:25 +02:00
FieldNames[6] = Txt_Institution;
2014-12-01 23:55:08 +01:00
/***** Get and update type of list,
number of columns in class photo
and preference about view photos *****/
Usr_GetAndUpdatePrefsAboutUsrList ();
/***** Get scope *****/
2015-07-27 19:42:24 +02:00
Gbl.Scope.Allowed = 1 << Sco_SCOPE_SYS |
1 << Sco_SCOPE_CTY |
2015-02-01 20:17:24 +01:00
1 << Sco_SCOPE_INS |
2015-07-27 19:42:24 +02:00
1 << Sco_SCOPE_CTR |
2015-02-01 20:17:24 +01:00
1 << Sco_SCOPE_DEG;
Gbl.Scope.Default = Sco_SCOPE_DEG;
2016-06-24 20:34:58 +02:00
Sco_GetScope ("ScopeUsr");
2014-12-01 23:55:08 +01:00
2017-01-28 17:17:35 +01:00
/***** Get list of administrators *****/
2016-03-28 00:31:49 +02:00
Usr_GetAdmsLst (Gbl.Scope.Current);
2016-06-15 13:20:07 +02:00
/***** Start frame with list of administrators *****/
2016-11-12 22:00:50 +01:00
Lay_StartRoundFrame (NULL,Txt_ROLES_PLURAL_Abc[Rol_DEG_ADM][Usr_SEX_UNKNOWN],
2016-11-20 20:03:47 +01:00
NULL,Hlp_USERS_Administrators);
2016-03-28 00:31:49 +02:00
2014-12-01 23:55:08 +01:00
/***** Form to select range of administrators *****/
2016-12-20 02:18:50 +01:00
fprintf (Gbl.F.Out,"<div class=\"CENTER_MIDDLE\">");
2015-09-17 17:49:46 +02:00
Act_FormStart (ActLstOth);
2014-12-01 23:55:08 +01:00
Usr_PutParamListWithPhotos ();
2016-12-20 02:18:50 +01:00
fprintf (Gbl.F.Out,"<label class=\"%s\">%s:&nbsp;",
The_ClassForm[Gbl.Prefs.Theme],Txt_Scope);
Sco_PutSelectorScope ("ScopeUsr",true);
fprintf (Gbl.F.Out,"</label>");
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
fprintf (Gbl.F.Out,"</div>");
2014-12-01 23:55:08 +01:00
2016-06-23 13:10:43 +02:00
if (Gbl.Usrs.LstUsrs[Rol_DEG_ADM].NumUsrs)
2014-12-01 23:55:08 +01:00
{
2015-10-02 01:04:28 +02:00
/****** Show photos? *****/
fprintf (Gbl.F.Out,"<div class=\"CENTER_MIDDLE\""
" style=\"margin-bottom:8px;\">");
2015-09-17 17:49:46 +02:00
Act_FormStart (ActLstOth);
2016-06-24 20:34:58 +02:00
Sco_PutParamScope ("ScopeUsr",Gbl.Scope.Current);
2014-12-01 23:55:08 +01:00
Usr_PutCheckboxListWithPhotos ();
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
fprintf (Gbl.F.Out,"</div>");
2014-12-01 23:55:08 +01:00
/***** Heading row with column names *****/
2016-06-16 18:32:12 +02:00
fprintf (Gbl.F.Out,"<table>"
2015-10-02 01:04:28 +02:00
"<tr>");
2014-12-01 23:55:08 +01:00
for (NumCol = 0;
2016-03-28 00:31:49 +02:00
NumCol < Usr_NUM_MAIN_FIELDS_DATA_ADM;
2014-12-01 23:55:08 +01:00
NumCol++)
if (NumCol != 1 || Gbl.Usrs.Listing.WithPhotos) // Skip photo column if I don't want this column
2015-09-06 20:02:14 +02:00
fprintf (Gbl.F.Out,"<th class=\"LEFT_MIDDLE LIGHT_BLUE\">"
2014-12-26 16:55:46 +01:00
"%s&nbsp;"
2015-09-05 19:19:39 +02:00
"</th>",
2015-09-04 19:26:08 +02:00
FieldNames[NumCol]);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</tr>");
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** List data of administrators *****/
2016-06-16 11:28:20 +02:00
for (NumUsr = 0, Gbl.RowEvenOdd = 0;
2016-06-23 13:10:43 +02:00
NumUsr < Gbl.Usrs.LstUsrs[Rol_DEG_ADM].NumUsrs; )
2014-12-01 23:55:08 +01:00
{
2016-06-23 13:10:43 +02:00
UsrDat.UsrCod = Gbl.Usrs.LstUsrs[Rol_DEG_ADM].Lst[NumUsr].UsrCod;
2014-12-01 23:55:08 +01:00
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) // If user's data exist...
{
2016-06-23 13:10:43 +02:00
UsrDat.Accepted = Gbl.Usrs.LstUsrs[Rol_DEG_ADM].Lst[NumUsr].Accepted;
2014-12-01 23:55:08 +01:00
Usr_WriteRowAdmData (++NumUsr,&UsrDat);
2016-06-16 11:28:20 +02:00
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
2014-12-01 23:55:08 +01:00
}
}
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
/***** End of table *****/
2015-10-02 01:04:28 +02:00
fprintf (Gbl.F.Out,"</table>");
2014-12-01 23:55:08 +01:00
}
2016-06-23 13:10:43 +02:00
else // Gbl.Usrs.LstUsrs[Rol_DEG_ADM].NumUsrs == 0
2017-02-09 19:27:18 +01:00
/***** Show warning indicating no admins found *****/
Usr_ShowWarningNoUsersFound (Rol_DEG_ADM);
2014-12-01 23:55:08 +01:00
2016-06-15 13:20:07 +02:00
/***** End frame *****/
2016-03-28 00:31:49 +02:00
Lay_EndRoundFrame ();
2016-06-23 13:10:43 +02:00
/***** Free memory for administrators list *****/
Usr_FreeUsrsList (Rol_DEG_ADM);
2014-12-01 23:55:08 +01:00
}
2017-02-01 11:23:48 +01:00
/*****************************************************************************/
/****************** Put hidden parameters with type of list, *****************/
/****************** number of columns in class photo *************************/
/****************** and preference about view photos *************************/
/*****************************************************************************/
void Usr_PutParamsPrefsAboutUsrList (void)
{
Usr_PutParamUsrListType (Gbl.Usrs.Me.ListType);
Usr_PutParamColsClassPhoto ();
Usr_PutParamListWithPhotos ();
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************* Get and update type of list, **********************/
/********************* number of columns in class photo **********************/
/********************* and preference about view photos **********************/
/*****************************************************************************/
void Usr_GetAndUpdatePrefsAboutUsrList (void)
{
/***** Get and update type of list *****/
Usr_GetAndUpdateUsrListType ();
/***** Get and update number of columns in class photo *****/
Usr_GetAndUpdateColsClassPhoto ();
/***** Get and update preference about view photos *****/
Usr_GetAndUpdatePrefAboutListWithPhotos ();
}
/*****************************************************************************/
/****************** Get from form the type of users' list ********************/
/*****************************************************************************/
static void Usr_GetAndUpdateUsrListType (void)
{
/***** Get type of list used to select users from form *****/
2017-01-29 21:41:08 +01:00
Usr_GetUsrListTypeFromForm ();
if (Gbl.Usrs.Me.ListType != Usr_LIST_UNKNOWN)
2014-12-01 23:55:08 +01:00
/* Save in the database the type of list preferred by me */
Usr_UpdateMyUsrListTypeInDB ();
else
2017-01-29 21:41:08 +01:00
/* If parameter can't be retrieved from,
get my preference from database */
2014-12-01 23:55:08 +01:00
Usr_GetMyUsrListTypeFromDB ();
}
/*****************************************************************************/
/************* Put a hidden parameter with the users' list type **************/
/*****************************************************************************/
void Usr_PutParamUsrListType (Usr_ShowUsrsType_t ListType)
{
Par_PutHiddenParamUnsigned ("UsrListType",(unsigned) ListType);
}
/*****************************************************************************/
/****************** Get from form the type of users' list ********************/
/*****************************************************************************/
2017-01-29 21:41:08 +01:00
static void Usr_GetUsrListTypeFromForm (void)
2014-12-01 23:55:08 +01:00
{
2017-01-29 21:41:08 +01:00
Gbl.Usrs.Me.ListType = (Usr_ShowUsrsType_t)
Par_GetParToUnsignedLong ("UsrListType",
0,
Usr_NUM_USR_LIST_TYPES - 1,
(unsigned long) Usr_LIST_UNKNOWN);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************** Get my preference about type of users' list ******************/
/*****************************************************************************/
static void Usr_GetMyUsrListTypeFromDB (void)
{
2017-03-13 20:32:03 +01:00
char Query[256];
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
Usr_ShowUsrsType_t ListType;
/***** Get type of listing of users from database *****/
2016-06-16 18:05:23 +02:00
sprintf (Query,"SELECT UsrListType FROM crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE CrsCod=%ld AND UsrCod=%ld",
2014-12-01 23:55:08 +01:00
Gbl.CurrentCrs.Crs.CrsCod,Gbl.Usrs.Me.UsrDat.UsrCod);
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get type of listing of users");
if (NumRows == 1) // Should be one only row
{
/* Get type of users' listing used to select some of them */
Gbl.Usrs.Me.ListType = Usr_SHOW_USRS_TYPE_DEFAULT;
row = mysql_fetch_row (mysql_res);
if (row[0])
for (ListType = (Usr_ShowUsrsType_t) 0;
ListType < Usr_NUM_USR_LIST_TYPES;
ListType++)
if (!strcasecmp (row[0],Usr_StringsUsrListTypeInDB[ListType]))
{
Gbl.Usrs.Me.ListType = ListType;
break;
}
}
else if (NumRows == 0) // If I am an administrator or superuser and I don't belong to current course, then the result will be the default
Gbl.Usrs.Me.ListType = Usr_SHOW_USRS_TYPE_DEFAULT;
else // Error in databse: more than one row for a user in course
Lay_ShowErrorAndExit ("Error when getting type of listing of users.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/***************** Save my preference about type of users' list **************/
/*****************************************************************************/
static void Usr_UpdateMyUsrListTypeInDB (void)
{
2017-03-13 20:32:03 +01:00
char Query[256];
2014-12-01 23:55:08 +01:00
/***** Update type of users listing *****/
sprintf (Query,"UPDATE crs_usr SET UsrListType='%s'"
2017-03-24 01:09:27 +01:00
" WHERE CrsCod=%ld AND UsrCod=%ld",
2014-12-01 23:55:08 +01:00
Usr_StringsUsrListTypeInDB[Gbl.Usrs.Me.ListType],
Gbl.CurrentCrs.Crs.CrsCod,Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryUPDATE (Query,"can not update type of listing");
}
/*****************************************************************************/
/************* Get and update number of columns in class photo ***************/
/*****************************************************************************/
void Usr_GetAndUpdateColsClassPhoto (void)
{
/***** Get the number of columns in class photo from form *****/
2017-01-29 21:41:08 +01:00
Usr_GetParamColsClassPhotoFromForm ();
if (Gbl.Usrs.ClassPhoto.Cols)
/* Save the number of columns into the database */
2014-12-01 23:55:08 +01:00
Usr_UpdateMyColsClassPhotoInDB ();
else
2017-01-29 21:41:08 +01:00
/* If parameter can't be retrieved from form,
get my preference from database */
2014-12-01 23:55:08 +01:00
Usr_GetMyColsClassPhotoFromDB ();
}
/*****************************************************************************/
/****** Put a hidden parameter with the number of colums in class photo ******/
/*****************************************************************************/
void Usr_PutParamColsClassPhoto (void)
{
Par_PutHiddenParamUnsigned ("ColsClassPhoto",Gbl.Usrs.ClassPhoto.Cols);
}
/*****************************************************************************/
/************* Get from form the number of colums in class photo *************/
/*****************************************************************************/
2017-01-29 21:41:08 +01:00
static void Usr_GetParamColsClassPhotoFromForm (void)
2014-12-01 23:55:08 +01:00
{
2017-01-29 21:41:08 +01:00
Gbl.Usrs.ClassPhoto.Cols = (unsigned)
Par_GetParToUnsignedLong ("ColsClassPhoto",
1,
Usr_CLASS_PHOTO_COLS_MAX,
0);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/** Get my prefs. about number of colums in class photo for current course ***/
/*****************************************************************************/
static void Usr_GetMyColsClassPhotoFromDB (void)
{
2017-03-13 20:32:03 +01:00
char Query[256];
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
Gbl.Usrs.ClassPhoto.Cols = Usr_CLASS_PHOTO_COLS_DEF;
/***** If user logged and course selected... *****/
if (Gbl.Usrs.Me.Logged && Gbl.CurrentCrs.Crs.CrsCod > 0)
{
/***** Get number of columns in class photo from database *****/
sprintf (Query,"SELECT ColsClassPhoto FROM crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE CrsCod=%ld AND UsrCod=%ld",
2014-12-01 23:55:08 +01:00
Gbl.CurrentCrs.Crs.CrsCod,Gbl.Usrs.Me.UsrDat.UsrCod);
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get number of columns in class photo");
if (NumRows == 1) // Should be one only row
{
/* Get number of columns in class photo */
row = mysql_fetch_row (mysql_res);
if (row[0])
if (sscanf (row[0],"%u",&Gbl.Usrs.ClassPhoto.Cols) == 1)
if (Gbl.Usrs.ClassPhoto.Cols < 1 ||
Gbl.Usrs.ClassPhoto.Cols > Usr_CLASS_PHOTO_COLS_MAX)
Gbl.Usrs.ClassPhoto.Cols = Usr_CLASS_PHOTO_COLS_DEF;
}
else if (NumRows > 1) // Error in databse: more than one row for a user in course
Lay_ShowErrorAndExit ("Error when getting number of columns in class photo.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
}
/*****************************************************************************/
/** Save my prefs. about number of colums in class photo for current course **/
/*****************************************************************************/
static void Usr_UpdateMyColsClassPhotoInDB (void)
{
char Query[256];
if (Gbl.Usrs.Me.UsrDat.UsrCod > 0 && Gbl.CurrentCrs.Crs.CrsCod > 0)
{
/***** Update number of colums in class photo for current course *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"UPDATE crs_usr SET ColsClassPhoto=%u"
" WHERE CrsCod=%ld AND UsrCod=%ld",
2014-12-01 23:55:08 +01:00
Gbl.Usrs.ClassPhoto.Cols,
Gbl.CurrentCrs.Crs.CrsCod,Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryUPDATE (Query,"can not update number of columns in class photo");
}
}
/*****************************************************************************/
/********** Get and update preference about photos in users' list ************/
/*****************************************************************************/
static void Usr_GetAndUpdatePrefAboutListWithPhotos (void)
{
2017-01-29 21:41:08 +01:00
/***** Get my preference about photos in users' list from form *****/
2014-12-01 23:55:08 +01:00
if (Usr_GetParamListWithPhotosFromForm ())
2017-01-29 21:41:08 +01:00
/* Save preference about photos in users' list into the database */
2014-12-01 23:55:08 +01:00
Usr_UpdateMyPrefAboutListWithPhotosPhotoInDB ();
else
2017-01-29 21:41:08 +01:00
/* If parameter can't be retrieved from form,
get my preference from database */
2014-12-01 23:55:08 +01:00
Usr_GetMyPrefAboutListWithPhotosFromDB ();
}
/*****************************************************************************/
/** Put a hidden parameter with the preference about photos in users' list ***/
/*****************************************************************************/
void Usr_PutParamListWithPhotos (void)
{
Par_PutHiddenParamChar ("WithPhotosExists",'Y');
Par_PutHiddenParamChar ("WithPhotos",
Gbl.Usrs.Listing.WithPhotos ? 'Y' :
'N');
}
/*****************************************************************************/
/********* Get from form the preference about photos in users' list **********/
/*****************************************************************************/
static bool Usr_GetParamListWithPhotosFromForm (void)
{
/***** Get if exists parameter with preference about photos in users' list *****/
2017-01-28 20:32:50 +01:00
if (Par_GetParToBool ("WithPhotosExists"))
2014-12-01 23:55:08 +01:00
{
2017-01-29 21:45:28 +01:00
/***** Parameter with preference about photos in users' list exists, so get it *****/
Gbl.Usrs.Listing.WithPhotos = Par_GetParToBool ("WithPhotos");
return true;
2014-12-01 23:55:08 +01:00
}
2017-01-29 21:45:28 +01:00
Gbl.Usrs.Listing.WithPhotos = Usr_LIST_WITH_PHOTOS_DEF;
return false;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***** Get my preference about photos in users' list for current course ******/
/*****************************************************************************/
void Usr_GetMyPrefAboutListWithPhotosFromDB (void)
{
2017-03-13 20:32:03 +01:00
char Query[256];
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
Gbl.Usrs.Listing.WithPhotos = Usr_LIST_WITH_PHOTOS_DEF;
/***** If no user logged or not course selected... *****/
if (Gbl.Usrs.Me.Logged && Gbl.CurrentCrs.Crs.CrsCod)
{
/***** Get if listing of users must show photos from database *****/
sprintf (Query,"SELECT ListWithPhotos FROM crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE CrsCod=%ld AND UsrCod=%ld",
2014-12-01 23:55:08 +01:00
Gbl.CurrentCrs.Crs.CrsCod,Gbl.Usrs.Me.UsrDat.UsrCod);
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not check if listing of users must show photos");
if (NumRows == 1) // Should be one only row
{
/* Get number of columns in class photo */
Gbl.Usrs.Listing.WithPhotos = Usr_LIST_WITH_PHOTOS_DEF;
row = mysql_fetch_row (mysql_res);
2016-09-07 18:48:10 +02:00
Gbl.Usrs.Listing.WithPhotos = (row[0][0] == 'Y');
2014-12-01 23:55:08 +01:00
}
else if (NumRows > 1) // Error in databse: more than one row for a user in course
Lay_ShowErrorAndExit ("Error when checking if listing of users must show photos.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
}
/*****************************************************************************/
/**** Save my preference about photos in users' list for current course ******/
/*****************************************************************************/
static void Usr_UpdateMyPrefAboutListWithPhotosPhotoInDB (void)
{
char Query[256];
if (Gbl.Usrs.Me.UsrDat.UsrCod > 0 && Gbl.CurrentCrs.Crs.CrsCod > 0)
{
/***** Update number of colums in class photo for current course *****/
sprintf (Query,"UPDATE crs_usr SET ListWithPhotos='%c'"
2017-03-24 01:09:27 +01:00
" WHERE CrsCod=%ld AND UsrCod=%ld",
2014-12-01 23:55:08 +01:00
Gbl.Usrs.Listing.WithPhotos ? 'Y' :
'N',
Gbl.CurrentCrs.Crs.CrsCod,Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryUPDATE (Query,"can not update your preference about photos in listing");
}
}
2015-09-17 16:54:02 +02:00
/*****************************************************************************/
/********** Put a link (form) to show list or class photo of guests **********/
/*****************************************************************************/
static void Usr_PutLinkToSeeAdmins (void)
{
2016-06-15 13:40:16 +02:00
extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2015-09-17 16:54:02 +02:00
/***** Put form to list admins *****/
2017-04-17 19:03:21 +02:00
Lay_PutContextualLink (ActLstOth,NULL,NULL,
2016-07-01 16:32:42 +02:00
"adm16x16.gif",
2016-06-15 13:40:16 +02:00
Txt_ROLES_PLURAL_Abc[Rol_DEG_ADM][Usr_SEX_UNKNOWN],
2016-07-01 16:32:42 +02:00
Txt_ROLES_PLURAL_Abc[Rol_DEG_ADM][Usr_SEX_UNKNOWN],
NULL);
2015-09-17 16:54:02 +02:00
}
/*****************************************************************************/
/********** Put a link (form) to show list or class photo of guests **********/
/*****************************************************************************/
static void Usr_PutLinkToSeeGuests (void)
{
2016-06-15 13:40:16 +02:00
extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2015-09-17 16:54:02 +02:00
/***** Put form to list guests *****/
2017-04-17 19:03:21 +02:00
Lay_PutContextualLink (ActLstGst,NULL,NULL,
2016-07-01 16:32:42 +02:00
"usrs64x64.gif",
Txt_ROLES_PLURAL_Abc[Rol__GUEST_][Usr_SEX_UNKNOWN],
2016-06-15 13:40:16 +02:00
Txt_ROLES_PLURAL_Abc[Rol__GUEST_][Usr_SEX_UNKNOWN],
2016-07-01 16:32:42 +02:00
NULL);
2015-09-17 16:54:02 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************* Show list or class photo of guests ********************/
/*****************************************************************************/
void Usr_SeeGuests (void)
{
2016-11-20 20:03:47 +01:00
extern const char *Hlp_USERS_Guests;
2015-07-28 00:16:09 +02:00
extern const char *The_ClassForm[The_NUM_THEMES];
2015-04-11 23:46:21 +02:00
extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2016-03-28 00:18:41 +02:00
extern const char *Txt_Scope;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Show_records;
2015-09-12 14:12:40 +02:00
/***** Put contextual links *****/
2015-09-17 16:54:02 +02:00
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
2015-09-12 14:12:40 +02:00
2015-09-17 16:54:02 +02:00
/* Put link to remove old users */
Usr_PutLinkToSeeAdmins ();
2015-09-12 14:12:40 +02:00
2015-09-17 16:54:02 +02:00
/* Put link to go to admin one user */
Enr_PutLinkToAdminOneUsr (ActReqMdfOneOth);
if (Gbl.Usrs.Me.LoggedRole == Rol_SYS_ADM)
2015-09-16 00:34:25 +02:00
/* Put link to remove old users */
Enr_PutLinkToRemOldUsrs ();
2015-09-17 16:54:02 +02:00
fprintf (Gbl.F.Out,"</div>");
2015-09-12 14:12:40 +02:00
2014-12-01 23:55:08 +01:00
/***** Get and update type of list,
number of columns in class photo
and preference about view photos *****/
Usr_GetAndUpdatePrefsAboutUsrList ();
/***** Get scope *****/
Sco_SetScopesForListingGuests ();
2016-06-24 20:34:58 +02:00
Sco_GetScope ("ScopeUsr");
2014-12-01 23:55:08 +01:00
2017-01-28 17:17:35 +01:00
/***** Get list of guests in current scope *****/
2014-12-01 23:55:08 +01:00
Usr_GetGstsLst (Gbl.Scope.Current);
2016-07-04 14:03:04 +02:00
if (Usr_GetIfShowBigList (Gbl.Usrs.LstUsrs[Rol__GUEST_].NumUsrs,NULL))
2014-12-01 23:55:08 +01:00
{
2016-03-28 00:18:41 +02:00
/***** Get list of selected users *****/
2016-07-04 14:03:04 +02:00
Usr_GetListsSelectedUsrsCods ();
2016-03-28 00:18:41 +02:00
/***** Start frame *****/
2016-11-12 22:00:50 +01:00
Lay_StartRoundFrame (NULL,Txt_ROLES_PLURAL_Abc[Rol__GUEST_][Usr_SEX_UNKNOWN],
2016-11-20 20:03:47 +01:00
Usr_PutIconsListGsts,Hlp_USERS_Guests);
2014-12-01 23:55:08 +01:00
2016-03-28 00:18:41 +02:00
/***** Form to select range of guests *****/
switch (Gbl.Usrs.Me.LoggedRole)
{
case Rol_CTR_ADM:
case Rol_INS_ADM:
case Rol_SYS_ADM:
fprintf (Gbl.F.Out,"<div class=\"CENTER_MIDDLE\">");
Act_FormStart (ActLstGst);
2017-02-01 11:23:48 +01:00
Usr_PutParamsPrefsAboutUsrList ();
2016-12-20 02:18:50 +01:00
fprintf (Gbl.F.Out,"<label class=\"%s\">%s:&nbsp;",
2016-03-28 00:18:41 +02:00
The_ClassForm[Gbl.Prefs.Theme],Txt_Scope);
2016-06-24 20:34:58 +02:00
Sco_PutSelectorScope ("ScopeUsr",true);
2016-12-20 02:18:50 +01:00
fprintf (Gbl.F.Out,"</label>");
2016-03-28 00:18:41 +02:00
Act_FormEnd ();
fprintf (Gbl.F.Out,"</div>");
break;
default:
break;
}
2015-10-02 01:04:28 +02:00
2016-06-23 13:10:43 +02:00
if (Gbl.Usrs.LstUsrs[Rol__GUEST_].NumUsrs)
2016-03-28 00:18:41 +02:00
{
2015-10-02 01:04:28 +02:00
/***** Form to select type of list of users *****/
Usr_ShowFormsToSelectUsrListType (ActLstGst);
2016-11-27 14:10:31 +01:00
/***** Draw a class photo with guests *****/
switch (Gbl.Usrs.Me.ListType)
{
2017-01-29 21:41:08 +01:00
case Usr_LIST_AS_CLASS_PHOTO:
2016-11-27 14:10:31 +01:00
Lay_WriteHeaderClassPhoto (false,true,
(Gbl.Scope.Current == Sco_SCOPE_CTR ||
Gbl.Scope.Current == Sco_SCOPE_INS) ? Gbl.CurrentIns.Ins.InsCod :
-1L,
-1L,
-1L);
break;
2017-01-29 21:41:08 +01:00
case Usr_LIST_AS_LISTING:
2016-11-27 14:10:31 +01:00
Usr_PutLinkToShowGstsAllData ();
break;
2017-01-29 21:41:08 +01:00
default:
break;
2016-11-27 14:10:31 +01:00
}
2015-04-11 17:33:14 +02:00
/* Start form */
2015-09-17 16:54:02 +02:00
Act_FormStart (ActSeeRecSevGst);
2014-12-01 23:55:08 +01:00
2016-03-18 22:17:35 +01:00
/* Start table */
2017-05-01 12:36:24 +02:00
Lay_StartTableWide (0);
2016-03-18 22:17:35 +01:00
2014-12-01 23:55:08 +01:00
/* Put a row to select all users */
2016-12-26 16:58:49 +01:00
Usr_PutCheckboxToSelectAllUsers (Rol__GUEST_);
2014-12-01 23:55:08 +01:00
/* Draw the classphoto/list */
switch (Gbl.Usrs.Me.ListType)
{
2017-01-29 21:41:08 +01:00
case Usr_LIST_AS_CLASS_PHOTO:
2014-12-01 23:55:08 +01:00
Usr_DrawClassPhoto (Usr_CLASS_PHOTO_SEL_SEE,
2015-04-07 21:44:24 +02:00
Rol__GUEST_);
2014-12-01 23:55:08 +01:00
break;
2017-01-29 21:41:08 +01:00
case Usr_LIST_AS_LISTING:
2014-12-01 23:55:08 +01:00
Usr_ListMainDataGsts (true);
break;
2017-01-29 21:41:08 +01:00
default:
break;
2014-12-01 23:55:08 +01:00
}
2015-10-02 01:04:28 +02:00
/* End table */
2017-05-01 12:36:24 +02:00
Lay_EndTable ();
2015-10-02 01:04:28 +02:00
/* Send button */
Lay_PutConfirmButton (Txt_Show_records);
2014-12-01 23:55:08 +01:00
2015-04-11 23:46:21 +02:00
/* End form */
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
2014-12-01 23:55:08 +01:00
}
2016-03-28 00:18:41 +02:00
else
Usr_ShowWarningNoUsersFound (Rol__GUEST_);
/***** End frame *****/
Lay_EndRoundFrame ();
2014-12-01 23:55:08 +01:00
}
2016-06-23 13:10:43 +02:00
/***** Free memory for guests list *****/
Usr_FreeUsrsList (Rol__GUEST_);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Show list or class photo of students *******************/
/*****************************************************************************/
void Usr_SeeStudents (void)
{
2016-11-18 00:17:53 +01:00
extern const char *Hlp_USERS_Students;
2015-07-28 00:16:09 +02:00
extern const char *The_ClassForm[The_NUM_THEMES];
2015-04-11 23:46:21 +02:00
extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2016-03-28 01:02:34 +02:00
extern const char *Txt_Scope;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Show_records;
bool ICanViewRecords;
2015-09-12 14:12:40 +02:00
/***** Put contextual links *****/
2016-10-24 20:09:00 +02:00
if (Gbl.Usrs.Me.LoggedRole >= Rol_STUDENT)
2014-12-01 23:55:08 +01:00
{
2015-04-02 14:22:21 +02:00
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
2014-12-01 23:55:08 +01:00
2016-10-24 20:09:00 +02:00
if (Gbl.Usrs.Me.LoggedRole >= Rol_TEACHER) // I am logged as teacher or admin
{
/* Put link to go to admin one user */
Enr_PutLinkToAdminOneUsr (ActReqMdfOneStd);
2014-12-01 23:55:08 +01:00
2016-10-24 20:09:00 +02:00
if (Gbl.CurrentCrs.Crs.CrsCod > 0) // Course selected
{
/* Put link to go to admin several users */
Enr_PutLinkToAdminSeveralUsrs (Rol_STUDENT);
2015-09-12 14:12:40 +02:00
2016-10-24 20:09:00 +02:00
/* Put link to edit record fields */
Rec_PutLinkToEditRecordFields ();
}
}
else
/* Put link to go to admin one user */
Enr_PutLinkToAdminOneUsr (ActReqMdfOneStd);
2015-09-12 14:12:40 +02:00
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</div>");
}
/***** Get and update type of list,
number of columns in class photo
and preference about view photos *****/
Usr_GetAndUpdatePrefsAboutUsrList ();
/***** Get scope *****/
Sco_SetScopesForListingStudents ();
2016-06-24 20:34:58 +02:00
Sco_GetScope ("ScopeUsr");
2015-02-01 20:17:24 +01:00
ICanViewRecords = (Gbl.Scope.Current == Sco_SCOPE_CRS &&
2015-04-07 21:44:24 +02:00
(Gbl.Usrs.Me.LoggedRole == Rol_STUDENT ||
Gbl.Usrs.Me.LoggedRole == Rol_TEACHER ||
Gbl.Usrs.Me.LoggedRole == Rol_SYS_ADM));
2014-12-01 23:55:08 +01:00
2016-11-25 03:21:02 +01:00
/***** Get groups to show ******/
if (Gbl.Scope.Current == Sco_SCOPE_CRS)
Grp_GetParCodsSeveralGrpsToShowUsrs ();
2017-01-28 17:17:35 +01:00
/***** Get list of students *****/
2016-11-25 03:21:02 +01:00
Usr_GetListUsrs (Rol_STUDENT,Gbl.Scope.Current);
2016-11-24 22:28:11 +01:00
/***** Start frame *****/
Lay_StartRoundFrame (NULL,Txt_ROLES_PLURAL_Abc[Rol_STUDENT][Usr_SEX_UNKNOWN],
Usr_PutIconsListStds,Hlp_USERS_Students);
2014-12-01 23:55:08 +01:00
/***** Form to select groups *****/
2015-02-01 20:17:24 +01:00
if (Gbl.Scope.Current == Sco_SCOPE_CRS)
2014-12-01 23:55:08 +01:00
Grp_ShowFormToSelectSeveralGroups (ActLstStd);
2016-07-04 14:03:04 +02:00
if (Usr_GetIfShowBigList (Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs,NULL))
2014-12-01 23:55:08 +01:00
{
2016-03-28 01:02:34 +02:00
/***** Get list of selected users *****/
2016-07-04 14:03:04 +02:00
Usr_GetListsSelectedUsrsCods ();
2014-12-01 23:55:08 +01:00
2016-03-28 01:02:34 +02:00
/***** Form to select range of students *****/
switch (Gbl.Usrs.Me.LoggedRole)
{
case Rol_DEG_ADM:
case Rol_SYS_ADM:
fprintf (Gbl.F.Out,"<div class=\"CENTER_MIDDLE\">");
Act_FormStart (ActLstStd);
2017-02-01 11:23:48 +01:00
Usr_PutParamsPrefsAboutUsrList ();
2016-12-20 02:18:50 +01:00
fprintf (Gbl.F.Out,"<label class=\"%s\">%s:&nbsp;",
2016-03-28 01:02:34 +02:00
The_ClassForm[Gbl.Prefs.Theme],Txt_Scope);
2016-06-24 20:34:58 +02:00
Sco_PutSelectorScope ("ScopeUsr",true);
2016-12-20 02:18:50 +01:00
fprintf (Gbl.F.Out,"</label>");
2016-03-28 01:02:34 +02:00
Act_FormEnd ();
fprintf (Gbl.F.Out,"</div>");
break;
default:
break;
}
2016-06-23 13:10:43 +02:00
if (Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs)
2016-03-28 01:02:34 +02:00
{
2015-10-02 01:04:28 +02:00
/***** Form to select type of list of users *****/
Usr_ShowFormsToSelectUsrListType (ActLstStd);
2014-12-01 23:55:08 +01:00
/***** Draw a class photo with students of the course *****/
2016-11-27 14:10:31 +01:00
switch (Gbl.Usrs.Me.ListType)
{
2017-01-29 21:41:08 +01:00
case Usr_LIST_AS_CLASS_PHOTO:
2016-11-27 14:10:31 +01:00
Lay_WriteHeaderClassPhoto (false,true,
(Gbl.Scope.Current == Sco_SCOPE_CRS ||
Gbl.Scope.Current == Sco_SCOPE_DEG ||
Gbl.Scope.Current == Sco_SCOPE_CTR ||
Gbl.Scope.Current == Sco_SCOPE_INS) ? Gbl.CurrentIns.Ins.InsCod :
-1L,
(Gbl.Scope.Current == Sco_SCOPE_CRS ||
Gbl.Scope.Current == Sco_SCOPE_DEG) ? Gbl.CurrentDeg.Deg.DegCod :
-1L,
Gbl.Scope.Current == Sco_SCOPE_CRS ? Gbl.CurrentCrs.Crs.CrsCod :
-1L);
break;
2017-01-29 21:41:08 +01:00
case Usr_LIST_AS_LISTING:
2016-11-27 14:10:31 +01:00
Usr_PutLinkToShowStdsAllData ();
break;
2017-01-29 21:41:08 +01:00
default:
break;
2016-11-27 14:10:31 +01:00
}
2015-04-11 17:33:14 +02:00
/* Start form */
2014-12-01 23:55:08 +01:00
if (ICanViewRecords)
{
Act_FormStart (ActSeeRecSevStd);
Grp_PutParamsCodGrps ();
}
2016-03-18 22:17:35 +01:00
/* Start table */
2017-05-01 12:36:24 +02:00
Lay_StartTableWide (0);
2016-03-18 22:17:35 +01:00
2014-12-01 23:55:08 +01:00
/* Put a row to select all users */
if (ICanViewRecords)
2016-12-26 16:58:49 +01:00
Usr_PutCheckboxToSelectAllUsers (Rol_STUDENT);
2014-12-01 23:55:08 +01:00
/* Draw the classphoto/list */
switch (Gbl.Usrs.Me.ListType)
{
2017-01-29 21:41:08 +01:00
case Usr_LIST_AS_CLASS_PHOTO:
2014-12-01 23:55:08 +01:00
Usr_DrawClassPhoto (ICanViewRecords ? Usr_CLASS_PHOTO_SEL_SEE :
Usr_CLASS_PHOTO_SEE,
2015-04-07 21:44:24 +02:00
Rol_STUDENT);
2014-12-01 23:55:08 +01:00
break;
2017-01-29 21:41:08 +01:00
case Usr_LIST_AS_LISTING:
2014-12-01 23:55:08 +01:00
Usr_ListMainDataStds (ICanViewRecords);
break;
2017-01-29 21:41:08 +01:00
default:
break;
2014-12-01 23:55:08 +01:00
}
2015-10-02 01:04:28 +02:00
/* End table */
2017-05-01 12:36:24 +02:00
Lay_EndTable ();
2015-10-02 01:04:28 +02:00
2014-12-01 23:55:08 +01:00
if (ICanViewRecords)
{
2015-10-02 01:04:28 +02:00
/* Send button */
Lay_PutConfirmButton (Txt_Show_records);
/* End form */
Act_FormEnd ();
2014-12-01 23:55:08 +01:00
}
2016-03-28 01:02:34 +02:00
}
else
{
/***** Show warning indicating no students found *****/
Usr_ShowWarningNoUsersFound (Rol_STUDENT);
2015-10-02 01:04:28 +02:00
2017-03-30 11:20:06 +02:00
/***** Button to enrol students *****/
Enr_PutButtonToEnrolStudents ();
2014-12-01 23:55:08 +01:00
}
2015-11-20 14:44:54 +01:00
}
2016-11-24 22:28:11 +01:00
/***** End frame *****/
Lay_EndRoundFrame ();
2014-12-01 23:55:08 +01:00
/***** Free memory for students list *****/
2016-06-23 13:10:43 +02:00
Usr_FreeUsrsList (Rol_STUDENT);
2014-12-01 23:55:08 +01:00
/***** Free memory for list of selected groups *****/
Grp_FreeListCodSelectedGrps ();
}
/*****************************************************************************/
/******************** Show list or class photo of teachers *******************/
/*****************************************************************************/
void Usr_SeeTeachers (void)
{
2016-11-18 00:17:53 +01:00
extern const char *Hlp_USERS_Teachers;
2015-07-28 00:16:09 +02:00
extern const char *The_ClassForm[The_NUM_THEMES];
2015-04-11 23:46:21 +02:00
extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2016-03-28 00:44:24 +02:00
extern const char *Txt_Scope;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Show_records;
bool ICanViewRecords;
2015-09-12 14:12:40 +02:00
/***** Put contextual links *****/
2016-10-24 20:09:00 +02:00
if (Gbl.Usrs.Me.LoggedRole >= Rol_TEACHER) // I am logged as teacher or admin
2015-09-12 14:12:40 +02:00
{
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
/* Put link to go to admin one user */
Enr_PutLinkToAdminOneUsr (ActReqMdfOneTch);
/* Put link to go to admin several users */
2016-10-24 20:09:00 +02:00
if (Gbl.CurrentCrs.Crs.CrsCod > 0 && // Course selected
Gbl.Usrs.Me.LoggedRole >= Rol_DEG_ADM) // I am logged as admin
2015-09-14 17:25:21 +02:00
Enr_PutLinkToAdminSeveralUsrs (Rol_TEACHER);
2015-09-12 14:12:40 +02:00
fprintf (Gbl.F.Out,"</div>");
}
2014-12-01 23:55:08 +01:00
/***** Get and update type of list,
number of columns in class photo
and preference about view photos *****/
Usr_GetAndUpdatePrefsAboutUsrList ();
/***** Get scope *****/
2015-10-19 21:49:45 +02:00
Gbl.Scope.Allowed = 1 << Sco_SCOPE_SYS |
1 << Sco_SCOPE_CTY |
2015-02-01 20:17:24 +01:00
1 << Sco_SCOPE_INS |
2015-10-19 21:49:45 +02:00
1 << Sco_SCOPE_CTR |
1 << Sco_SCOPE_DEG |
2015-02-01 20:17:24 +01:00
1 << Sco_SCOPE_CRS;
Gbl.Scope.Default = Sco_SCOPE_CRS;
2016-06-24 20:34:58 +02:00
Sco_GetScope ("ScopeUsr");
2015-02-01 20:17:24 +01:00
ICanViewRecords = (Gbl.Scope.Current == Sco_SCOPE_CRS);
2014-12-01 23:55:08 +01:00
2017-01-28 17:17:35 +01:00
/***** Get list of teachers *****/
2016-06-23 13:10:43 +02:00
Usr_GetListUsrs (Rol_TEACHER,Gbl.Scope.Current);
2014-12-01 23:55:08 +01:00
2016-07-04 14:03:04 +02:00
if (Usr_GetIfShowBigList (Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs,NULL))
2014-12-01 23:55:08 +01:00
{
2016-03-28 00:44:24 +02:00
/***** Start frame *****/
2016-11-12 22:00:50 +01:00
Lay_StartRoundFrame (NULL,Txt_ROLES_PLURAL_Abc[Rol_TEACHER][Usr_SEX_UNKNOWN],
2016-11-18 00:17:53 +01:00
Usr_PutIconsListTchs,Hlp_USERS_Teachers);
2016-03-28 00:44:24 +02:00
/***** Form to select scope *****/
fprintf (Gbl.F.Out,"<div class=\"CENTER_MIDDLE\">");
Act_FormStart (ActLstTch);
2017-02-01 11:23:48 +01:00
Usr_PutParamsPrefsAboutUsrList ();
2016-12-20 02:18:50 +01:00
fprintf (Gbl.F.Out,"<label class=\"%s\">%s:&nbsp;",
2016-03-28 00:44:24 +02:00
The_ClassForm[Gbl.Prefs.Theme],Txt_Scope);
2016-06-24 20:34:58 +02:00
Sco_PutSelectorScope ("ScopeUsr",true);
2016-12-20 02:18:50 +01:00
fprintf (Gbl.F.Out,"</label>");
2016-03-28 00:44:24 +02:00
Act_FormEnd ();
fprintf (Gbl.F.Out,"</div>");
2016-06-23 13:10:43 +02:00
if (Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs)
2014-12-01 23:55:08 +01:00
{
2015-10-02 01:04:28 +02:00
/***** Form to select type of list of users *****/
Usr_ShowFormsToSelectUsrListType (ActLstTch);
/***** Draw a class photo with teachers of the course *****/
2016-11-27 14:10:31 +01:00
switch (Gbl.Usrs.Me.ListType)
{
2017-01-29 21:41:08 +01:00
case Usr_LIST_AS_CLASS_PHOTO:
2016-11-27 14:10:31 +01:00
Lay_WriteHeaderClassPhoto (false,true,
(Gbl.Scope.Current == Sco_SCOPE_CRS ||
Gbl.Scope.Current == Sco_SCOPE_DEG ||
Gbl.Scope.Current == Sco_SCOPE_CTR ||
Gbl.Scope.Current == Sco_SCOPE_INS) ? Gbl.CurrentIns.Ins.InsCod :
-1L,
(Gbl.Scope.Current == Sco_SCOPE_CRS ||
Gbl.Scope.Current == Sco_SCOPE_DEG) ? Gbl.CurrentDeg.Deg.DegCod :
-1L,
Gbl.Scope.Current == Sco_SCOPE_CRS ? Gbl.CurrentCrs.Crs.CrsCod :
-1L);
break;
2017-01-29 21:41:08 +01:00
case Usr_LIST_AS_LISTING:
2016-11-27 14:10:31 +01:00
if (Gbl.Usrs.Me.LoggedRole >= Rol_DEG_ADM)
Usr_PutLinkToShowTchsAllData ();
break;
2017-01-29 21:41:08 +01:00
default:
break;
2016-11-27 14:10:31 +01:00
}
2015-04-11 17:33:14 +02:00
/* Start form */
2014-12-01 23:55:08 +01:00
if (ICanViewRecords)
Act_FormStart (ActSeeRecSevTch);
2016-03-18 22:17:35 +01:00
/* Start table */
2017-05-01 12:36:24 +02:00
Lay_StartTableWide (0);
2016-03-18 22:17:35 +01:00
2014-12-01 23:55:08 +01:00
/* Put a row to select all users */
if (ICanViewRecords)
2016-12-26 16:58:49 +01:00
Usr_PutCheckboxToSelectAllUsers (Rol_TEACHER);
2014-12-01 23:55:08 +01:00
/***** Draw the classphoto/list *****/
switch (Gbl.Usrs.Me.ListType)
{
2017-01-29 21:41:08 +01:00
case Usr_LIST_AS_CLASS_PHOTO:
2014-12-01 23:55:08 +01:00
Usr_DrawClassPhoto (ICanViewRecords ? Usr_CLASS_PHOTO_SEL_SEE :
Usr_CLASS_PHOTO_SEE,
2015-04-07 21:44:24 +02:00
Rol_TEACHER);
2014-12-01 23:55:08 +01:00
break;
2017-01-29 21:41:08 +01:00
case Usr_LIST_AS_LISTING:
2014-12-01 23:55:08 +01:00
Usr_ListMainDataTchs (ICanViewRecords);
break;
2017-01-29 21:41:08 +01:00
default:
break;
2014-12-01 23:55:08 +01:00
}
2015-10-02 01:04:28 +02:00
/* End table */
2017-05-01 12:36:24 +02:00
Lay_EndTable ();
2015-10-02 01:04:28 +02:00
2014-12-01 23:55:08 +01:00
if (ICanViewRecords)
{
2015-10-02 01:04:28 +02:00
/* Send button */
Lay_PutConfirmButton (Txt_Show_records);
/* End form */
Act_FormEnd ();
2014-12-01 23:55:08 +01:00
}
}
2016-03-28 00:44:24 +02:00
else
2017-02-09 19:27:18 +01:00
{
/***** Show warning indicating no teachers found *****/
Usr_ShowWarningNoUsersFound (Rol_TEACHER);
2017-03-30 11:20:06 +02:00
/***** Button to enrol a teacher *****/
Enr_PutButtonToEnrolOneTeacher ();
2017-02-09 19:27:18 +01:00
}
2016-03-28 00:44:24 +02:00
/***** End frame *****/
Lay_EndRoundFrame ();
2014-12-01 23:55:08 +01:00
}
/***** Free memory for teachers list *****/
2016-06-23 13:10:43 +02:00
Usr_FreeUsrsList (Rol_TEACHER);
2014-12-01 23:55:08 +01:00
}
2016-11-07 01:23:17 +01:00
/*****************************************************************************/
/***************** Put contextual icons in list of guests ********************/
/*****************************************************************************/
static void Usr_PutIconsListGsts (void)
{
2017-01-29 21:41:08 +01:00
switch (Gbl.Usrs.Me.ListType)
2016-11-07 01:23:17 +01:00
{
2017-01-29 21:41:08 +01:00
case Usr_LIST_AS_CLASS_PHOTO:
if (Gbl.Usrs.LstUsrs[Rol__GUEST_].NumUsrs)
/***** Put icon to print guests *****/
Usr_PutIconToPrintGsts ();
break;
case Usr_LIST_AS_LISTING:
/***** Put icon to show all data of guests *****/
Usr_PutIconToShowGstsAllData ();
break;
default:
break;
2016-11-07 01:23:17 +01:00
}
/***** Put icon to show a figure *****/
Gbl.Stat.FigureType = Sta_USERS;
Sta_PutIconToShowFigure ();
}
2016-11-07 00:46:13 +01:00
/*****************************************************************************/
/**************** Put contextual icons in list of students *******************/
/*****************************************************************************/
static void Usr_PutIconsListStds (void)
{
2017-01-29 21:41:08 +01:00
switch (Gbl.Usrs.Me.ListType)
2016-11-07 00:46:13 +01:00
{
2017-01-29 21:41:08 +01:00
case Usr_LIST_AS_CLASS_PHOTO:
if (Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs)
/***** Put icon to print students *****/
Usr_PutIconToPrintStds ();
break;
case Usr_LIST_AS_LISTING:
/***** Put icon to show all data of students *****/
Usr_PutIconToShowStdsAllData ();
break;
default:
break;
2016-11-07 00:46:13 +01:00
}
/***** Put icon to show a figure *****/
Gbl.Stat.FigureType = Sta_USERS;
Sta_PutIconToShowFigure ();
2016-11-07 01:01:21 +01:00
}
/*****************************************************************************/
/**************** Put contextual icons in list of teachers *******************/
/*****************************************************************************/
static void Usr_PutIconsListTchs (void)
{
2017-01-29 21:41:08 +01:00
switch (Gbl.Usrs.Me.ListType)
2016-11-07 01:01:21 +01:00
{
2017-01-29 21:41:08 +01:00
case Usr_LIST_AS_CLASS_PHOTO:
if (Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs)
/***** Put icon to print teachers *****/
Usr_PutIconToPrintTchs ();
break;
case Usr_LIST_AS_LISTING:
/***** Put icon to show all data of teachers *****/
Usr_PutIconToShowTchsAllData ();
break;
default:
break;
2016-11-07 01:01:21 +01:00
}
/***** Put icon to show a figure *****/
Gbl.Stat.FigureType = Sta_USERS;
Sta_PutIconToShowFigure ();
2016-11-07 00:46:13 +01:00
}
2016-03-18 21:28:45 +01:00
/*****************************************************************************/
/***************** Functions used to print lists of users ********************/
/*****************************************************************************/
static void Usr_PutIconToPrintGsts (void)
{
2017-04-30 23:48:48 +02:00
Lay_PutContextualIconToPrint (ActPrnGstPho,Usr_ShowGstsAllDataParams);
2016-03-18 21:28:45 +01:00
}
static void Usr_PutIconToPrintStds (void)
{
2017-04-30 23:48:48 +02:00
Lay_PutContextualIconToPrint (ActPrnStdPho,Usr_ShowStdsAllDataParams);
2016-03-18 21:28:45 +01:00
}
static void Usr_PutIconToPrintTchs (void)
{
2017-04-30 23:48:48 +02:00
Lay_PutContextualIconToPrint (ActPrnTchPho,Usr_ShowTchsAllDataParams);
2016-03-18 21:28:45 +01:00
}
2016-11-27 14:10:31 +01:00
/*****************************************************************************/
/**************** Functions used to list all data of users *******************/
/*****************************************************************************/
2016-03-18 21:28:45 +01:00
static void Usr_PutIconToShowGstsAllData (void)
{
extern const char *Txt_Show_all_data;
2017-04-17 19:03:21 +02:00
Lay_PutContextualLink (ActLstGstAll,NULL,Usr_ShowGstsAllDataParams,
2016-07-01 16:32:42 +02:00
"table64x64.gif",
Txt_Show_all_data,NULL,
NULL);
2016-03-18 21:28:45 +01:00
}
2016-11-27 14:10:31 +01:00
static void Usr_PutLinkToShowGstsAllData (void)
{
extern const char *Txt_Show_all_data;
2016-12-26 16:58:49 +01:00
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
2017-04-17 19:03:21 +02:00
Lay_PutContextualLink (ActLstGstAll,NULL,Usr_ShowGstsAllDataParams,
2016-11-27 14:10:31 +01:00
"table64x64.gif",
Txt_Show_all_data,Txt_Show_all_data,
NULL);
2016-12-26 16:58:49 +01:00
fprintf (Gbl.F.Out,"</div>");
2016-11-27 14:10:31 +01:00
}
2016-03-18 21:28:45 +01:00
static void Usr_PutIconToShowStdsAllData (void)
{
extern const char *Txt_Show_all_data;
2017-04-17 19:03:21 +02:00
Lay_PutContextualLink (ActLstStdAll,NULL,Usr_ShowStdsAllDataParams,
2016-07-01 16:32:42 +02:00
"table64x64.gif",
Txt_Show_all_data,NULL,
NULL);
2016-03-18 21:28:45 +01:00
}
2016-11-27 14:10:31 +01:00
static void Usr_PutLinkToShowStdsAllData (void)
{
extern const char *Txt_Show_all_data;
2016-12-26 16:58:49 +01:00
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
2017-04-17 19:03:21 +02:00
Lay_PutContextualLink (ActLstStdAll,NULL,Usr_ShowStdsAllDataParams,
2016-11-27 14:10:31 +01:00
"table64x64.gif",
Txt_Show_all_data,Txt_Show_all_data,
NULL);
2016-12-26 16:58:49 +01:00
fprintf (Gbl.F.Out,"</div>");
2016-11-27 14:10:31 +01:00
}
2016-03-18 21:28:45 +01:00
static void Usr_PutIconToShowTchsAllData (void)
{
extern const char *Txt_Show_all_data;
2017-04-17 19:03:21 +02:00
Lay_PutContextualLink (ActLstTchAll,NULL,Usr_ShowTchsAllDataParams,
2016-07-01 16:32:42 +02:00
"table64x64.gif",
Txt_Show_all_data,NULL,
NULL);
2016-03-18 21:28:45 +01:00
}
2016-11-27 14:10:31 +01:00
static void Usr_PutLinkToShowTchsAllData (void)
{
extern const char *Txt_Show_all_data;
2016-12-26 16:58:49 +01:00
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
2017-04-17 19:03:21 +02:00
Lay_PutContextualLink (ActLstTchAll,NULL,Usr_ShowTchsAllDataParams,
2016-11-27 14:10:31 +01:00
"table64x64.gif",
Txt_Show_all_data,Txt_Show_all_data,
NULL);
2016-12-26 16:58:49 +01:00
fprintf (Gbl.F.Out,"</div>");
2016-11-27 14:10:31 +01:00
}
2016-03-18 21:28:45 +01:00
static void Usr_ShowGstsAllDataParams (void)
{
Usr_PutParamListWithPhotos ();
Usr_PutExtraParamsUsrList (ActLstGstAll);
}
static void Usr_ShowStdsAllDataParams (void)
{
Grp_PutParamsCodGrps ();
Usr_PutParamListWithPhotos ();
Usr_PutExtraParamsUsrList (ActLstStdAll);
}
static void Usr_ShowTchsAllDataParams (void)
{
2016-06-24 20:34:58 +02:00
Sco_PutParamScope ("ScopeUsr",Gbl.Scope.Current);
2016-03-18 21:28:45 +01:00
Usr_PutParamListWithPhotos ();
Usr_PutExtraParamsUsrList (ActLstTchAll);
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************* Draw class photo with guests ready to be printed **************/
/*****************************************************************************/
void Usr_SeeGstClassPhotoPrn (void)
{
/***** Get and update type of list,
number of columns in class photo
and preference about view photos *****/
Usr_GetAndUpdatePrefsAboutUsrList ();
/***** Get scope *****/
Sco_SetScopesForListingGuests ();
2016-06-24 20:34:58 +02:00
Sco_GetScope ("ScopeUsr");
2014-12-01 23:55:08 +01:00
2017-01-28 17:17:35 +01:00
/***** Get list of guests *****/
2014-12-01 23:55:08 +01:00
Usr_GetGstsLst (Gbl.Scope.Current);
2016-06-23 13:10:43 +02:00
if (Gbl.Usrs.LstUsrs[Rol__GUEST_].NumUsrs)
2014-12-01 23:55:08 +01:00
{
/***** Draw the guests' class photo *****/
2016-03-18 22:17:35 +01:00
Lay_WriteHeaderClassPhoto (true,true,
2015-02-01 20:17:24 +01:00
(Gbl.Scope.Current == Sco_SCOPE_CTR ||
Gbl.Scope.Current == Sco_SCOPE_INS) ? Gbl.CurrentIns.Ins.InsCod :
2016-03-28 00:44:24 +02:00
-1L,
2014-12-01 23:55:08 +01:00
-1L,-1L);
2017-05-01 12:36:24 +02:00
Lay_StartTableWide (0);
2015-04-07 21:44:24 +02:00
Usr_DrawClassPhoto (Usr_CLASS_PHOTO_PRN,Rol__GUEST_);
2017-05-01 12:36:24 +02:00
Lay_EndTable ();
2014-12-01 23:55:08 +01:00
}
else
2015-04-07 21:44:24 +02:00
Usr_ShowWarningNoUsersFound (Rol__GUEST_);
2014-12-01 23:55:08 +01:00
2016-06-23 13:10:43 +02:00
/***** Free memory for guests list *****/
Usr_FreeUsrsList (Rol__GUEST_);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/**************** Draw class photo with students ready to print **************/
/*****************************************************************************/
void Usr_SeeStdClassPhotoPrn (void)
{
/***** Get and update type of list,
number of columns in class photo
and preference about view photos *****/
Usr_GetAndUpdatePrefsAboutUsrList ();
/***** Get scope *****/
Sco_SetScopesForListingStudents ();
2016-06-24 20:34:58 +02:00
Sco_GetScope ("ScopeUsr");
2014-12-01 23:55:08 +01:00
/****** Get groups to show ******/
Grp_GetParCodsSeveralGrpsToShowUsrs ();
2017-01-28 17:17:35 +01:00
/***** Get list of students *****/
2016-06-23 13:10:43 +02:00
Usr_GetListUsrs (Rol_STUDENT,Gbl.Scope.Current);
2014-12-01 23:55:08 +01:00
2016-06-23 13:10:43 +02:00
if (Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs)
2014-12-01 23:55:08 +01:00
{
/***** Draw the students' class photo *****/
2016-03-18 22:17:35 +01:00
Lay_WriteHeaderClassPhoto (true,true,
2015-02-01 20:17:24 +01:00
(Gbl.Scope.Current == Sco_SCOPE_CRS ||
Gbl.Scope.Current == Sco_SCOPE_DEG ||
Gbl.Scope.Current == Sco_SCOPE_CTR ||
Gbl.Scope.Current == Sco_SCOPE_INS) ? Gbl.CurrentIns.Ins.InsCod :
2016-06-23 13:51:37 +02:00
-1L,
2015-02-01 20:17:24 +01:00
(Gbl.Scope.Current == Sco_SCOPE_CRS ||
Gbl.Scope.Current == Sco_SCOPE_DEG) ? Gbl.CurrentDeg.Deg.DegCod :
2016-06-23 13:51:37 +02:00
-1L,
Gbl.Scope.Current == Sco_SCOPE_CRS ? Gbl.CurrentCrs.Crs.CrsCod :
-1L);
2017-05-01 12:36:24 +02:00
Lay_StartTableWide (0);
2015-04-07 21:44:24 +02:00
Usr_DrawClassPhoto (Usr_CLASS_PHOTO_PRN,Rol_STUDENT);
2017-05-01 12:36:24 +02:00
Lay_EndTable ();
2014-12-01 23:55:08 +01:00
}
else
2015-04-07 21:44:24 +02:00
Usr_ShowWarningNoUsersFound (Rol_STUDENT);
2014-12-01 23:55:08 +01:00
/***** Free memory for students list *****/
2016-06-23 13:10:43 +02:00
Usr_FreeUsrsList (Rol_STUDENT);
2014-12-01 23:55:08 +01:00
/***** Free memory for list of selected groups *****/
Grp_FreeListCodSelectedGrps ();
}
/*****************************************************************************/
/**************** Draw class photo with teachers ready to print **************/
/*****************************************************************************/
void Usr_SeeTchClassPhotoPrn (void)
{
/***** Get and update type of list,
number of columns in class photo
and preference about view photos *****/
Usr_GetAndUpdatePrefsAboutUsrList ();
/***** Get scope *****/
2015-10-19 21:49:45 +02:00
Gbl.Scope.Allowed = 1 << Sco_SCOPE_SYS |
1 << Sco_SCOPE_CTY |
2015-02-01 20:17:24 +01:00
1 << Sco_SCOPE_INS |
2015-10-19 21:49:45 +02:00
1 << Sco_SCOPE_CTR |
1 << Sco_SCOPE_DEG |
2015-02-01 20:17:24 +01:00
1 << Sco_SCOPE_CRS;
Gbl.Scope.Default = Sco_SCOPE_CRS;
2016-06-24 20:34:58 +02:00
Sco_GetScope ("ScopeUsr");
2014-12-01 23:55:08 +01:00
2017-01-28 17:17:35 +01:00
/***** Get list of teachers *****/
2016-06-23 13:10:43 +02:00
Usr_GetListUsrs (Rol_TEACHER,Gbl.Scope.Current);
2014-12-01 23:55:08 +01:00
2016-06-23 13:10:43 +02:00
if (Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs)
2014-12-01 23:55:08 +01:00
{
/***** Draw the teachers' class photo *****/
2016-03-18 22:17:35 +01:00
Lay_WriteHeaderClassPhoto (true,true,
2015-02-01 20:17:24 +01:00
(Gbl.Scope.Current == Sco_SCOPE_CRS ||
Gbl.Scope.Current == Sco_SCOPE_DEG ||
Gbl.Scope.Current == Sco_SCOPE_CTR ||
Gbl.Scope.Current == Sco_SCOPE_INS) ? Gbl.CurrentIns.Ins.InsCod :
2016-06-23 11:31:51 +02:00
-1L,
2015-02-01 20:17:24 +01:00
(Gbl.Scope.Current == Sco_SCOPE_CRS ||
Gbl.Scope.Current == Sco_SCOPE_DEG) ? Gbl.CurrentDeg.Deg.DegCod :
2016-06-23 11:31:51 +02:00
-1L,
Gbl.Scope.Current == Sco_SCOPE_CRS ? Gbl.CurrentCrs.Crs.CrsCod :
-1L);
2017-05-01 12:36:24 +02:00
Lay_StartTableWide (0);
2015-04-07 21:44:24 +02:00
Usr_DrawClassPhoto (Usr_CLASS_PHOTO_PRN,Rol_TEACHER);
2017-05-01 12:36:24 +02:00
Lay_EndTable ();
2014-12-01 23:55:08 +01:00
}
else
2017-02-09 19:27:18 +01:00
/***** Show warning indicating no teachers found *****/
Usr_ShowWarningNoUsersFound (Rol_TEACHER);
2014-12-01 23:55:08 +01:00
/***** Free memory for teachers list *****/
2016-06-23 13:10:43 +02:00
Usr_FreeUsrsList (Rol_TEACHER);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************** Draw class photo with students or teachers ***************/
/*****************************************************************************/
static void Usr_DrawClassPhoto (Usr_ClassPhotoType_t ClassPhotoType,
Rol_Role_t RoleInClassPhoto)
{
unsigned NumUsr;
bool TRIsOpen = false;
bool PutCheckBoxToSelectUsr = (ClassPhotoType == Usr_CLASS_PHOTO_SEL ||
2015-03-06 14:11:11 +01:00
ClassPhotoType == Usr_CLASS_PHOTO_SEL_SEE);
2014-12-01 23:55:08 +01:00
bool ShowPhoto;
bool UsrIsTheMsgSender;
2015-12-13 12:51:41 +01:00
const char *ClassPhoto = "PHOTO21x28"; // Default photo size
2017-01-28 15:58:46 +01:00
char PhotoURL[PATH_MAX + 1];
2014-12-01 23:55:08 +01:00
struct UsrData UsrDat;
/***** Set width and height of photos *****/
switch (ClassPhotoType)
{
case Usr_CLASS_PHOTO_SEL:
2015-12-13 12:51:41 +01:00
ClassPhoto = "PHOTO21x28";
2014-12-01 23:55:08 +01:00
break;
case Usr_CLASS_PHOTO_SEL_SEE:
case Usr_CLASS_PHOTO_SEE:
2015-12-13 12:51:41 +01:00
ClassPhoto = "PHOTO45x60";
2014-12-01 23:55:08 +01:00
break;
case Usr_CLASS_PHOTO_PRN:
2015-12-13 12:51:41 +01:00
ClassPhoto = "PHOTO45x60";
2014-12-01 23:55:08 +01:00
break;
}
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** Loop for showing users photos, names and place of birth *****/
for (NumUsr = 0;
2016-06-23 13:10:43 +02:00
NumUsr < Gbl.Usrs.LstUsrs[RoleInClassPhoto].NumUsrs; )
2014-12-01 23:55:08 +01:00
{
if ((NumUsr % Gbl.Usrs.ClassPhoto.Cols) == 0)
{
fprintf (Gbl.F.Out,"<tr>");
TRIsOpen = true;
}
2016-07-26 01:51:48 +02:00
/* Copy user's basic data from list */
Usr_CopyBasicUsrDataFromList (&UsrDat,&Gbl.Usrs.LstUsrs[RoleInClassPhoto].Lst[NumUsr]);
2014-12-01 23:55:08 +01:00
2016-07-26 01:51:48 +02:00
/* Get list of user's IDs */
ID_GetListIDsFromUsrCod (&UsrDat);
2014-12-01 23:55:08 +01:00
2016-07-26 01:51:48 +02:00
/***** Begin user's cell *****/
fprintf (Gbl.F.Out,"<td class=\"CLASSPHOTO CENTER_BOTTOM");
if (ClassPhotoType == Usr_CLASS_PHOTO_SEL &&
UsrDat.UsrCod == Gbl.Usrs.Other.UsrDat.UsrCod)
{
UsrIsTheMsgSender = true;
fprintf (Gbl.F.Out," LIGHT_GREEN");
}
else
UsrIsTheMsgSender = false;
fprintf (Gbl.F.Out,"\">");
2014-12-01 23:55:08 +01:00
2016-07-26 01:51:48 +02:00
/***** Checkbox to select this user *****/
if (PutCheckBoxToSelectUsr)
Usr_PutCheckboxToSelectUser (&UsrDat,UsrIsTheMsgSender);
2014-12-01 23:55:08 +01:00
2016-07-26 01:51:48 +02:00
/***** Show photo *****/
2017-01-28 15:58:46 +01:00
ShowPhoto = Pho_ShowingUsrPhotoIsAllowed (&UsrDat,PhotoURL);
2016-07-26 01:51:48 +02:00
Pho_ShowUsrPhoto (&UsrDat,ShowPhoto ? PhotoURL :
NULL,
ClassPhoto,Pho_ZOOM,false);
2014-12-01 23:55:08 +01:00
2016-07-26 01:51:48 +02:00
/***** Photo foot *****/
2017-03-03 21:06:34 +01:00
fprintf (Gbl.F.Out,"<div class=\"CLASSPHOTO_CAPTION\">");
2014-12-01 23:55:08 +01:00
2016-07-26 01:51:48 +02:00
/* Name */
if (UsrDat.FirstName[0])
fprintf (Gbl.F.Out,"%s",UsrDat.FirstName);
else
fprintf (Gbl.F.Out,"&nbsp;");
fprintf (Gbl.F.Out,"<br />");
if (UsrDat.Surname1[0])
fprintf (Gbl.F.Out,"%s",UsrDat.Surname1);
else
fprintf (Gbl.F.Out,"&nbsp;");
fprintf (Gbl.F.Out,"<br />");
if (UsrDat.Surname2[0])
fprintf (Gbl.F.Out,"%s",UsrDat.Surname2);
else
fprintf (Gbl.F.Out,"&nbsp;");
2014-12-01 23:55:08 +01:00
2017-03-03 21:06:34 +01:00
fprintf (Gbl.F.Out,"</div>");
2016-07-26 01:51:48 +02:00
/***** End of user's cell *****/
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
2016-07-26 01:51:48 +02:00
if ((++NumUsr % Gbl.Usrs.ClassPhoto.Cols) == 0)
{
fprintf (Gbl.F.Out,"</tr>");
TRIsOpen = false;
}
2014-12-01 23:55:08 +01:00
}
if (TRIsOpen)
fprintf (Gbl.F.Out,"</tr>");
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}
/*****************************************************************************/
/***************** Write selector of columns in class photo ******************/
/*****************************************************************************/
void Usr_PutSelectorNumColsClassPhoto (void)
{
2015-07-28 00:16:09 +02:00
extern const char *The_ClassForm[The_NUM_THEMES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_columns;
unsigned Cols;
/***** Start selector *****/
2016-12-20 02:18:50 +01:00
fprintf (Gbl.F.Out,"<label class=\"%s\">"
"<select name=\"ColsClassPhoto\""
2015-10-22 14:49:48 +02:00
" onchange=\"document.getElementById('%s').submit();\">",
2016-12-20 02:18:50 +01:00
The_ClassForm[Gbl.Prefs.Theme],Gbl.Form.Id);
2014-12-01 23:55:08 +01:00
/***** Put a row in selector for every number from 1 to Usr_CLASS_PHOTO_COLS_MAX *****/
for (Cols = 1;
Cols <= Usr_CLASS_PHOTO_COLS_MAX;
Cols++)
{
fprintf (Gbl.F.Out,"<option");
if (Cols == Gbl.Usrs.ClassPhoto.Cols)
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%u</option>",Cols);
}
/***** End selector *****/
fprintf (Gbl.F.Out,"</select>"
2016-12-20 02:18:50 +01:00
"%s</label>",
Txt_columns);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********** Build the relative path of a user from his user's code ***********/
/*****************************************************************************/
2014-12-12 18:50:36 +01:00
void Usr_ConstructPathUsr (long UsrCod,char *PathUsr)
2014-12-01 23:55:08 +01:00
{
2017-01-28 15:58:46 +01:00
char PathUsrs[PATH_MAX + 1];
char PathAboveUsr[PATH_MAX + 1];
2014-12-01 23:55:08 +01:00
/***** Path for users *****/
sprintf (PathUsrs,"%s/%s",Cfg_PATH_SWAD_PRIVATE,Cfg_FOLDER_USR);
Fil_CreateDirIfNotExists (PathUsrs);
/***** Path above user's ID *****/
sprintf (PathAboveUsr,"%s/%02u",PathUsrs,(unsigned) (UsrCod % 100));
Fil_CreateDirIfNotExists (PathAboveUsr);
/***** Path for user *****/
sprintf (PathUsr,"%s/%ld",PathAboveUsr,UsrCod);
}
/*****************************************************************************/
/************** Check if a user exists with a given user's code **************/
/*****************************************************************************/
bool Usr_ChkIfUsrCodExists (long UsrCod)
{
2017-03-13 20:32:03 +01:00
char Query[128];
2014-12-01 23:55:08 +01:00
if (UsrCod <= 0) // Wrong user's code
return false;
/***** Get if a user exists in database *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"SELECT COUNT(*) FROM usr_data WHERE UsrCod=%ld",
2014-12-01 23:55:08 +01:00
UsrCod);
return (DB_QueryCOUNT (Query,"can not check if a user exists") != 0);
}
/*****************************************************************************/
/********************** Show warning "no users found" ************************/
/*****************************************************************************/
// Use Rol_ROLE_UNKNOWN type to display "no users found"
void Usr_ShowWarningNoUsersFound (Rol_Role_t Role)
{
extern const char *Txt_No_users_found[Rol_NUM_ROLES];
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_INFO,Txt_No_users_found[Role]);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************ See stats about the platform ***********************/
/*****************************************************************************/
2015-11-17 01:22:57 +01:00
// Here Rol_ROLE_UNKNOWN means "all users"
2014-12-01 23:55:08 +01:00
void Usr_GetAndShowNumUsrsInPlatform (Rol_Role_t Role)
{
2015-11-17 01:22:57 +01:00
extern const char *Txt_Total;
2014-12-01 23:55:08 +01:00
extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
unsigned NumUsrs;
float NumCrssPerUsr;
float NumUsrsPerCrs;
2015-11-17 01:22:57 +01:00
char *Class = (Role == Rol_UNKNOWN) ? "DAT_N_LINE_TOP RIGHT_BOTTOM" :
"DAT RIGHT_BOTTOM";
2014-12-01 23:55:08 +01:00
/***** Get the number of users belonging to any course *****/
2015-04-07 21:44:24 +02:00
if (Role == Rol__GUEST_) // Users not beloging to any course
2014-12-01 23:55:08 +01:00
NumUsrs = Usr_GetNumUsrsNotBelongingToAnyCrs ();
else
2015-11-17 01:22:57 +01:00
NumUsrs = Sta_GetTotalNumberOfUsersInCourses (Gbl.Scope.Current,Role);
2014-12-01 23:55:08 +01:00
/***** Get average number of courses per user *****/
2015-04-07 21:44:24 +02:00
NumCrssPerUsr = (Role == Rol__GUEST_) ? 0 :
2015-11-17 01:22:57 +01:00
Usr_GetNumCrssPerUsr (Role);
2014-12-01 23:55:08 +01:00
/***** Query the number of users per course *****/
2015-04-07 21:44:24 +02:00
NumUsrsPerCrs = (Role == Rol__GUEST_) ? 0 :
2015-11-17 01:22:57 +01:00
Usr_GetNumUsrsPerCrs (Role);
2014-12-01 23:55:08 +01:00
/***** Write the total number of users *****/
fprintf (Gbl.F.Out,"<tr>"
2015-11-17 01:22:57 +01:00
"<td class=\"%s\">"
2014-12-26 16:55:46 +01:00
"%s"
"</td>"
2015-11-17 01:22:57 +01:00
"<td class=\"%s\">"
2014-12-26 16:55:46 +01:00
"%u"
"</td>"
2015-11-17 01:22:57 +01:00
"<td class=\"%s\">"
2014-12-26 16:55:46 +01:00
"%.2f"
"</td>"
2015-11-17 01:22:57 +01:00
"<td class=\"%s\">"
2014-12-26 16:55:46 +01:00
"%.2f"
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>",
2015-11-17 01:22:57 +01:00
Class,(Role == Rol_UNKNOWN) ? Txt_Total :
Txt_ROLES_PLURAL_Abc[Role][Usr_SEX_UNKNOWN],
Class,NumUsrs,
Class,NumCrssPerUsr,
Class,NumUsrsPerCrs);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******** Get total number of users who do not belong to any course **********/
/*****************************************************************************/
static unsigned Usr_GetNumUsrsNotBelongingToAnyCrs (void)
{
char Query[256];
/***** Get number of users who are in table of users but not in table courses-users *****/
2017-03-13 20:32:03 +01:00
sprintf (Query,"SELECT COUNT(*) FROM usr_data WHERE UsrCod NOT IN"
2014-12-01 23:55:08 +01:00
" (SELECT DISTINCT(UsrCod) FROM crs_usr)");
return (unsigned) DB_QueryCOUNT (Query,"can not get number of users who do not belong to any course");
}
/*****************************************************************************/
2015-11-17 01:22:57 +01:00
/************ Get average number of courses with users of a role *************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
static float Usr_GetNumCrssPerUsr (Rol_Role_t Role)
{
char Query[1024];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
float NumCrssPerUsr;
/***** Get number of courses per user from database *****/
switch (Gbl.Scope.Current)
{
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_SYS:
2015-11-17 01:22:57 +01:00
if (Role == Rol_UNKNOWN) // Any user
sprintf (Query,"SELECT AVG(NumCrss) FROM "
"(SELECT COUNT(CrsCod) AS NumCrss"
" FROM crs_usr"
" GROUP BY UsrCod) AS NumCrssTable");
else
sprintf (Query,"SELECT AVG(NumCrss) FROM "
"(SELECT COUNT(CrsCod) AS NumCrss"
" FROM crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE Role=%u GROUP BY UsrCod) AS NumCrssTable",
2015-11-17 01:22:57 +01:00
(unsigned) Role);
2014-12-01 23:55:08 +01:00
break;
2015-03-09 12:38:52 +01:00
case Sco_SCOPE_CTY:
2015-11-17 01:22:57 +01:00
if (Role == Rol_UNKNOWN) // Any user
sprintf (Query,"SELECT AVG(NumCrss) FROM "
"(SELECT COUNT(crs_usr.CrsCod) AS NumCrss"
" FROM institutions,centres,degrees,courses,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE institutions.CtyCod=%ld"
2015-11-17 01:22:57 +01:00
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" GROUP BY crs_usr.UsrCod) AS NumCrssTable",
Gbl.CurrentCty.Cty.CtyCod);
else
sprintf (Query,"SELECT AVG(NumCrss) FROM "
"(SELECT COUNT(crs_usr.CrsCod) AS NumCrss"
" FROM institutions,centres,degrees,courses,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE institutions.CtyCod=%ld"
2015-11-17 01:22:57 +01:00
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u"
2015-11-17 01:22:57 +01:00
" GROUP BY crs_usr.UsrCod) AS NumCrssTable",
Gbl.CurrentCty.Cty.CtyCod,
(unsigned) Role);
2015-03-09 12:38:52 +01:00
break;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_INS:
2015-11-17 01:22:57 +01:00
if (Role == Rol_UNKNOWN) // Any user
sprintf (Query,"SELECT AVG(NumCrss) FROM "
"(SELECT COUNT(crs_usr.CrsCod) AS NumCrss"
" FROM centres,degrees,courses,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE centres.InsCod=%ld"
2015-11-17 01:22:57 +01:00
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" GROUP BY crs_usr.UsrCod) AS NumCrssTable",
Gbl.CurrentIns.Ins.InsCod);
else
sprintf (Query,"SELECT AVG(NumCrss) FROM "
"(SELECT COUNT(crs_usr.CrsCod) AS NumCrss"
" FROM centres,degrees,courses,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE centres.InsCod=%ld"
2015-11-17 01:22:57 +01:00
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u"
2015-11-17 01:22:57 +01:00
" GROUP BY crs_usr.UsrCod) AS NumCrssTable",
Gbl.CurrentIns.Ins.InsCod,
(unsigned) Role);
2014-12-01 23:55:08 +01:00
break;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_CTR:
2015-11-17 01:22:57 +01:00
if (Role == Rol_UNKNOWN) // Any user
sprintf (Query,"SELECT AVG(NumCrss) FROM "
"(SELECT COUNT(crs_usr.CrsCod) AS NumCrss"
" FROM degrees,courses,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE degrees.CtrCod=%ld"
2015-11-17 01:22:57 +01:00
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" GROUP BY crs_usr.UsrCod) AS NumCrssTable",
Gbl.CurrentCtr.Ctr.CtrCod);
else
sprintf (Query,"SELECT AVG(NumCrss) FROM "
"(SELECT COUNT(crs_usr.CrsCod) AS NumCrss"
" FROM degrees,courses,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE degrees.CtrCod=%ld"
2015-11-17 01:22:57 +01:00
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u"
2015-11-17 01:22:57 +01:00
" GROUP BY crs_usr.UsrCod) AS NumCrssTable",
Gbl.CurrentCtr.Ctr.CtrCod,
(unsigned) Role);
2014-12-01 23:55:08 +01:00
break;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_DEG:
2015-11-17 01:22:57 +01:00
if (Role == Rol_UNKNOWN) // Any user
sprintf (Query,"SELECT AVG(NumCrss) FROM "
"(SELECT COUNT(crs_usr.CrsCod) AS NumCrss"
" FROM courses,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE courses.DegCod=%ld"
2015-11-17 01:22:57 +01:00
" AND courses.CrsCod=crs_usr.CrsCod"
" GROUP BY crs_usr.UsrCod) AS NumCrssTable",
Gbl.CurrentDeg.Deg.DegCod);
else
sprintf (Query,"SELECT AVG(NumCrss) FROM "
"(SELECT COUNT(crs_usr.CrsCod) AS NumCrss"
" FROM courses,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE courses.DegCod=%ld"
2015-11-17 01:22:57 +01:00
" AND courses.CrsCod=crs_usr.CrsCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u"
2015-11-17 01:22:57 +01:00
" GROUP BY crs_usr.UsrCod) AS NumCrssTable",
Gbl.CurrentDeg.Deg.DegCod,
(unsigned) Role);
2014-12-01 23:55:08 +01:00
break;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_CRS:
2014-12-01 23:55:08 +01:00
return 1.0;
default:
Lay_ShowErrorAndExit ("Wrong scope.");
break;
}
DB_QuerySELECT (Query,&mysql_res,"can not get number of courses per user");
/***** Get number of courses *****/
row = mysql_fetch_row (mysql_res);
NumCrssPerUsr = Str_GetFloatNumFromStr (row[0]);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumCrssPerUsr;
}
/*****************************************************************************/
/************ Get average number of courses with users of a type *************/
/*****************************************************************************/
static float Usr_GetNumUsrsPerCrs (Rol_Role_t Role)
{
char Query[1024];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
float NumUsrsPerCrs;
/***** Get number of users per course from database *****/
switch (Gbl.Scope.Current)
{
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_SYS:
2015-11-17 01:22:57 +01:00
if (Role == Rol_UNKNOWN) // Any user
sprintf (Query,"SELECT AVG(NumUsrs) FROM "
"(SELECT COUNT(UsrCod) AS NumUsrs"
" FROM crs_usr"
" GROUP BY CrsCod) AS NumUsrsTable");
else
sprintf (Query,"SELECT AVG(NumUsrs) FROM "
"(SELECT COUNT(UsrCod) AS NumUsrs"
" FROM crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE Role=%u GROUP BY CrsCod) AS NumUsrsTable",
2015-11-17 01:22:57 +01:00
(unsigned) Role);
2014-12-01 23:55:08 +01:00
break;
2015-03-09 12:38:52 +01:00
case Sco_SCOPE_CTY:
2015-11-17 01:22:57 +01:00
if (Role == Rol_UNKNOWN) // Any user
sprintf (Query,"SELECT AVG(NumUsrs) FROM "
"(SELECT COUNT(crs_usr.UsrCod) AS NumUsrs"
" FROM institutions,centres,degrees,courses,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE institutions.CtyCod=%ld"
2015-11-17 01:22:57 +01:00
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" GROUP BY crs_usr.CrsCod) AS NumUsrsTable",
Gbl.CurrentCty.Cty.CtyCod);
else
sprintf (Query,"SELECT AVG(NumUsrs) FROM "
"(SELECT COUNT(crs_usr.UsrCod) AS NumUsrs"
" FROM institutions,centres,degrees,courses,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE institutions.CtyCod=%ld"
2015-11-17 01:22:57 +01:00
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u"
2015-11-17 01:22:57 +01:00
" GROUP BY crs_usr.CrsCod) AS NumUsrsTable",
Gbl.CurrentCty.Cty.CtyCod,
(unsigned) Role);
2015-03-09 12:38:52 +01:00
break;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_INS:
2015-11-17 01:22:57 +01:00
if (Role == Rol_UNKNOWN) // Any user
sprintf (Query,"SELECT AVG(NumUsrs) FROM "
"(SELECT COUNT(crs_usr.UsrCod) AS NumUsrs"
" FROM centres,degrees,courses,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE centres.InsCod=%ld"
2015-11-17 01:22:57 +01:00
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" GROUP BY crs_usr.CrsCod) AS NumUsrsTable",
Gbl.CurrentIns.Ins.InsCod);
else
sprintf (Query,"SELECT AVG(NumUsrs) FROM "
"(SELECT COUNT(crs_usr.UsrCod) AS NumUsrs"
" FROM centres,degrees,courses,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE centres.InsCod=%ld"
2015-11-17 01:22:57 +01:00
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u"
2015-11-17 01:22:57 +01:00
" GROUP BY crs_usr.CrsCod) AS NumUsrsTable",
Gbl.CurrentIns.Ins.InsCod,
(unsigned) Role);
2014-12-01 23:55:08 +01:00
break;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_CTR:
2015-11-17 01:22:57 +01:00
if (Role == Rol_UNKNOWN) // Any user
sprintf (Query,"SELECT AVG(NumUsrs) FROM "
"(SELECT COUNT(crs_usr.UsrCod) AS NumUsrs"
" FROM degrees,courses,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE degrees.CtrCod=%ld"
2015-11-17 01:22:57 +01:00
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" GROUP BY crs_usr.CrsCod) AS NumUsrsTable",
Gbl.CurrentCtr.Ctr.CtrCod);
else
sprintf (Query,"SELECT AVG(NumUsrs) FROM "
"(SELECT COUNT(crs_usr.UsrCod) AS NumUsrs"
" FROM degrees,courses,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE degrees.CtrCod=%ld"
2015-11-17 01:22:57 +01:00
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u"
2015-11-17 01:22:57 +01:00
" GROUP BY crs_usr.CrsCod) AS NumUsrsTable",
Gbl.CurrentCtr.Ctr.CtrCod,
(unsigned) Role);
2014-12-01 23:55:08 +01:00
break;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_DEG:
2015-11-17 01:22:57 +01:00
if (Role == Rol_UNKNOWN) // Any user
sprintf (Query,"SELECT AVG(NumUsrs) FROM "
"(SELECT COUNT(crs_usr.UsrCod) AS NumUsrs"
" FROM courses,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE courses.DegCod=%ld"
2015-11-17 01:22:57 +01:00
" AND courses.CrsCod=crs_usr.CrsCod"
" GROUP BY crs_usr.CrsCod) AS NumUsrsTable",
Gbl.CurrentDeg.Deg.DegCod);
else
sprintf (Query,"SELECT AVG(NumUsrs) FROM "
"(SELECT COUNT(crs_usr.UsrCod) AS NumUsrs"
" FROM courses,crs_usr"
2017-03-24 01:09:27 +01:00
" WHERE courses.DegCod=%ld"
2015-11-17 01:22:57 +01:00
" AND courses.CrsCod=crs_usr.CrsCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u"
2015-11-17 01:22:57 +01:00
" GROUP BY crs_usr.CrsCod) AS NumUsrsTable",
Gbl.CurrentDeg.Deg.DegCod,
(unsigned) Role);
2014-12-01 23:55:08 +01:00
break;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_CRS:
2015-11-17 01:22:57 +01:00
return (float) ( Role == Rol_UNKNOWN ? Gbl.CurrentCrs.Crs.NumUsrs : // Any user
(Role == Rol_TEACHER ? Gbl.CurrentCrs.Crs.NumTchs : // Teachers
Gbl.CurrentCrs.Crs.NumStds)); // Students
2014-12-01 23:55:08 +01:00
default:
Lay_ShowErrorAndExit ("Wrong scope.");
break;
}
DB_QuerySELECT (Query,&mysql_res,"can not get number of users per course");
/***** Get number of users *****/
row = mysql_fetch_row (mysql_res);
NumUsrsPerCrs = Str_GetFloatNumFromStr (row[0]);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumUsrsPerCrs;
}
2015-03-29 01:06:00 +01:00
/*****************************************************************************/
/****************** Check if a user is banned in ranking *********************/
/*****************************************************************************/
bool Usr_CheckIfUsrBanned (long UsrCod)
{
char Query[128];
2017-03-24 01:09:27 +01:00
sprintf (Query,"SELECT COUNT(*) FROM usr_banned WHERE UsrCod=%ld",
2015-03-29 01:06:00 +01:00
UsrCod);
return (DB_QueryCOUNT (Query,"can not check if user is banned") != 0);
}
/*****************************************************************************/
2015-12-12 02:01:20 +01:00
/**************** Remove user from banned users in ranking *******************/
2015-03-29 01:06:00 +01:00
/*****************************************************************************/
void Usr_RemoveUsrFromUsrBanned (long UsrCod)
{
char Query[128];
2017-03-24 01:09:27 +01:00
sprintf (Query,"DELETE FROM usr_banned WHERE UsrCod=%ld",
2015-03-29 01:06:00 +01:00
UsrCod);
DB_QueryDELETE (Query,"can not remove user from users banned");
}
2016-12-07 00:41:36 +01:00
/*****************************************************************************/
/**************************** Show a user QR code ****************************/
/*****************************************************************************/
void Usr_PrintUsrQRCode (void)
{
2017-03-01 18:53:51 +01:00
extern const char *Txt_User_not_found_or_you_do_not_have_permission_;
char NewNicknameWithArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
2016-12-07 00:41:36 +01:00
2017-03-01 18:53:51 +01:00
if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ())
{
/***** Start frame *****/
Lay_StartRoundFrame (NULL,Gbl.Usrs.Other.UsrDat.FullName,NULL,NULL);
2016-12-07 00:41:36 +01:00
2017-03-01 18:53:51 +01:00
/***** Show QR code *****/
if (Gbl.Usrs.Other.UsrDat.Nickname[0])
{
sprintf (NewNicknameWithArroba,"@%s",Gbl.Usrs.Other.UsrDat.Nickname);
QR_ImageQRCode (NewNicknameWithArroba);
}
/***** End frame *****/
Lay_EndRoundFrame ();
}
else
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_User_not_found_or_you_do_not_have_permission_);
2016-12-07 00:41:36 +01:00
}
2017-03-04 01:59:27 +01:00
/*****************************************************************************/
/********************* Write the author of an assignment *********************/
/*****************************************************************************/
void Usr_WriteAuthor1Line (long UsrCod,bool Hidden)
{
bool ShowPhoto = false;
char PhotoURL[PATH_MAX + 1];
struct UsrData UsrDat;
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** Get data of author *****/
UsrDat.UsrCod = UsrCod;
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat))
ShowPhoto = Pho_ShowingUsrPhotoIsAllowed (&UsrDat,PhotoURL);
/***** Show photo *****/
Pho_ShowUsrPhoto (&UsrDat,ShowPhoto ? PhotoURL :
NULL,
"PHOTO15x20",Pho_ZOOM,false);
/***** Write name *****/
fprintf (Gbl.F.Out,"<div class=\"AUTHOR_1_LINE %s\">%s</div>",
Hidden ? "AUTHOR_TXT_LIGHT" :
"AUTHOR_TXT",
UsrDat.FullName);
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}