swad-core/swad_centre.c

2967 lines
103 KiB
C
Raw Normal View History

2014-12-01 23:55:08 +01:00
// swad_centre.c: centres
/*
SWAD (Shared Workspace At a Distance),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
2019-01-07 21:52:19 +01:00
Copyright (C) 1999-2019 Antonio Ca<EFBFBD>as Vargas
2014-12-01 23:55:08 +01:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
#include <linux/stddef.h> // For NULL
2015-10-16 02:24:29 +02:00
#include <stdbool.h> // For boolean type
2014-12-01 23:55:08 +01:00
#include <stdlib.h> // For calloc
#include <string.h> // For string functions
2016-03-29 10:24:14 +02:00
#include <sys/wait.h> // For the macro WEXITSTATUS
2016-03-28 19:30:37 +02:00
#include <unistd.h> // For unlink
2014-12-01 23:55:08 +01:00
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
2014-12-01 23:55:08 +01:00
#include "swad_centre.h"
#include "swad_constant.h"
#include "swad_database.h"
2018-11-09 20:47:39 +01:00
#include "swad_form.h"
2014-12-01 23:55:08 +01:00
#include "swad_global.h"
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_institution.h"
2018-12-08 16:43:13 +01:00
#include "swad_language.h"
2015-01-17 13:31:25 +01:00
#include "swad_logo.h"
2014-12-01 23:55:08 +01:00
#include "swad_parameter.h"
#include "swad_QR.h"
#include "swad_string.h"
2017-06-11 20:09:59 +02:00
#include "swad_table.h"
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
2016-03-28 19:30:37 +02:00
// Centre photo will be saved with:
// - maximum width of Ctr_PHOTO_SAVED_MAX_HEIGHT
// - maximum height of Ctr_PHOTO_SAVED_MAX_HEIGHT
// - maintaining the original aspect ratio (aspect ratio recommended: 3:2)
#define Ctr_RECOMMENDED_ASPECT_RATIO "3:2"
#define Ctr_PHOTO_SAVED_MAX_WIDTH 768
#define Ctr_PHOTO_SAVED_MAX_HEIGHT 512
#define Ctr_PHOTO_SAVED_QUALITY 75 // 1 to 100
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
static void Ctr_Configuration (bool PrintView);
2019-02-11 21:35:36 +01:00
static void Ctr_PutIconsCtrConfig (void);
2016-05-05 20:16:28 +02:00
static void Ctr_PutIconToChangePhoto (void);
2017-05-21 14:43:10 +02:00
static void Ctr_ShowNumUsrsInCrssOfCtr (Rol_Role_t Role);
2014-12-01 23:55:08 +01:00
static void Ctr_ListCentres (void);
2016-11-07 00:03:50 +01:00
static bool Ctr_CheckIfICanCreateCentres (void);
2018-11-15 10:33:45 +01:00
static void Ctr_PutIconsListingCentres (void);
2016-11-06 23:46:29 +01:00
static void Ctr_PutIconToEditCentres (void);
2016-03-16 13:23:10 +01:00
static void Ctr_ListOneCentreForSeeing (struct Centre *Ctr,unsigned NumCtr);
2017-01-29 12:42:19 +01:00
static void Ctr_GetParamCtrOrder (void);
2017-04-30 02:35:25 +02:00
static void Ctr_PutIconsEditingCentres (void);
2014-12-01 23:55:08 +01:00
static void Ctr_GetPhotoAttribution (long CtrCod,char **PhotoAttribution);
static void Ctr_FreePhotoAttribution (char **PhotoAttribution);
static void Ctr_ListCentresForEdition (void);
2016-11-06 23:46:29 +01:00
static bool Ctr_CheckIfICanEditACentre (struct Centre *Ctr);
2014-12-01 23:55:08 +01:00
static Ctr_StatusTxt_t Ctr_GetStatusTxtFromStatusBits (Ctr_Status_t Status);
static Ctr_Status_t Ctr_GetStatusBitsFromStatusTxt (Ctr_StatusTxt_t StatusTxt);
2016-10-23 19:40:14 +02:00
2014-12-01 23:55:08 +01:00
static void Ctr_PutParamOtherCtrCod (long CtrCod);
2016-10-23 19:40:14 +02:00
2016-10-20 16:49:42 +02:00
static void Ctr_UpdateCtrInsDB (long CtrCod,long InsCod);
2017-06-12 19:14:05 +02:00
static void Ctr_UpdateCtrPlcDB (long CtrCod,long NewPlcCod);
2017-03-09 11:16:17 +01:00
2016-10-28 10:03:37 +02:00
static void Ctr_RenameCentre (struct Centre *Ctr,Cns_ShrtOrFullName_t ShrtOrFullName);
2016-10-20 19:46:06 +02:00
static bool Ctr_CheckIfCtrNameExistsInIns (const char *FieldName,const char *Name,long CtrCod,long InsCod);
2017-03-09 11:16:17 +01:00
static void Ctr_UpdateInsNameDB (long CtrCod,const char *FieldName,const char *NewCtrName);
2017-01-28 15:58:46 +01:00
static void Ctr_UpdateCtrWWWDB (long CtrCod,
2017-03-07 01:56:41 +01:00
const char NewWWW[Cns_MAX_BYTES_WWW + 1]);
2017-05-11 20:55:04 +02:00
static void Ctr_ShowAlertAndButtonToGoToCtr (void);
static void Ctr_PutParamGoToCtr (void);
2015-01-17 13:31:25 +01:00
2014-12-01 23:55:08 +01:00
static void Ctr_PutFormToCreateCentre (void);
static void Ctr_PutHeadCentresForSeeing (bool OrderSelectable);
static void Ctr_PutHeadCentresForEdition (void);
static void Ctr_RecFormRequestOrCreateCtr (unsigned Status);
2017-05-11 20:55:04 +02:00
static void Ctr_CreateCentre (unsigned Status);
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/******************* List centres with pending degrees ***********************/
/*****************************************************************************/
void Ctr_SeeCtrWithPendingDegs (void)
{
2017-03-27 13:38:10 +02:00
extern const char *Hlp_SYSTEM_Hierarchy_pending;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Centres_with_pending_degrees;
extern const char *Txt_Centre;
extern const char *Txt_Degrees_ABBREVIATION;
extern const char *Txt_There_are_no_centres_with_requests_for_degrees_to_be_confirmed;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCtrs;
unsigned NumCtr;
struct Centre Ctr;
2015-09-04 19:26:08 +02:00
const char *BgColor;
2014-12-01 23:55:08 +01:00
/***** Get centres with pending degrees *****/
2017-06-04 18:18:54 +02:00
switch (Gbl.Usrs.Me.Role.Logged)
2014-12-01 23:55:08 +01:00
{
2015-04-07 21:44:24 +02:00
case Rol_CTR_ADM:
2018-10-30 13:59:37 +01:00
NumCtrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get centres"
" with pending degrees",
"SELECT degrees.CtrCod,COUNT(*)"
" FROM degrees,ctr_admin,centres"
" WHERE (degrees.Status & %u)<>0"
" AND degrees.CtrCod=ctr_admin.CtrCod"
" AND ctr_admin.UsrCod=%ld"
" AND degrees.CtrCod=centres.CtrCod"
" GROUP BY degrees.CtrCod ORDER BY centres.ShortName",
(unsigned) Deg_STATUS_BIT_PENDING,
Gbl.Usrs.Me.UsrDat.UsrCod);
2014-12-01 23:55:08 +01:00
break;
2015-04-07 21:44:24 +02:00
case Rol_SYS_ADM:
2018-10-30 13:59:37 +01:00
NumCtrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get centres"
" with pending degrees",
"SELECT degrees.CtrCod,COUNT(*)"
" FROM degrees,centres"
" WHERE (degrees.Status & %u)<>0"
" AND degrees.CtrCod=centres.CtrCod"
" GROUP BY degrees.CtrCod ORDER BY centres.ShortName",
(unsigned) Deg_STATUS_BIT_PENDING);
2014-12-01 23:55:08 +01:00
break;
default: // Forbidden for other users
return;
}
2018-10-30 13:59:37 +01:00
if (NumCtrs)
2014-12-01 23:55:08 +01:00
{
2017-06-12 14:16:33 +02:00
/***** Start box and table *****/
2017-06-10 21:38:10 +02:00
Box_StartBoxTable (NULL,Txt_Centres_with_pending_degrees,NULL,
2017-06-12 15:03:29 +02:00
Hlp_SYSTEM_Hierarchy_pending,Box_NOT_CLOSABLE,2);
2017-06-12 14:16:33 +02:00
/***** Wrtie heading *****/
2016-11-14 10:05:41 +01:00
fprintf (Gbl.F.Out,"<tr>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2014-12-01 23:55:08 +01:00
"</tr>",
Txt_Centre,
Txt_Degrees_ABBREVIATION);
/***** List the centres *****/
for (NumCtr = 0;
NumCtr < NumCtrs;
NumCtr++)
{
/* Get next centre */
row = mysql_fetch_row (mysql_res);
/* Get centre code (row[0]) */
Ctr.CtrCod = Str_ConvertStrCodToLongCod (row[0]);
2015-09-04 19:26:08 +02:00
BgColor = (Ctr.CtrCod == Gbl.CurrentCtr.Ctr.CtrCod) ? "LIGHT_BLUE" :
Gbl.ColorRows[Gbl.RowEvenOdd];
2014-12-01 23:55:08 +01:00
/* Get data of centre */
Ctr_GetDataOfCentreByCod (&Ctr);
2015-11-12 00:53:30 +01:00
/* Centre logo and full name */
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<tr>"
2015-11-12 00:53:30 +01:00
"<td class=\"LEFT_MIDDLE %s\">",
2014-12-01 23:55:08 +01:00
BgColor);
2015-11-19 19:37:44 +01:00
Ctr_DrawCentreLogoAndNameWithLink (&Ctr,ActSeeDeg,
"DAT_NOBR","CENTER_MIDDLE");
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
/* Number of pending degrees (row[1]) */
2015-09-04 17:10:27 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE %s\">"
2014-12-22 14:08:19 +01:00
"%s"
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>",
BgColor,row[1]);
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
}
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2017-06-10 21:38:10 +02:00
Box_EndBoxTable ();
2014-12-01 23:55:08 +01:00
}
else
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_INFO,Txt_There_are_no_centres_with_requests_for_degrees_to_be_confirmed);
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2015-11-19 19:37:44 +01:00
/*****************************************************************************/
2015-11-19 20:04:41 +01:00
/******************** Draw centre logo and name with link ********************/
2015-11-19 19:37:44 +01:00
/*****************************************************************************/
void Ctr_DrawCentreLogoAndNameWithLink (struct Centre *Ctr,Act_Action_t Action,
const char *ClassLink,const char *ClassLogo)
{
extern const char *Txt_Go_to_X;
/***** Start form *****/
2018-11-09 20:47:39 +01:00
Frm_StartFormGoTo (Action);
2015-11-19 19:37:44 +01:00
Ctr_PutParamCtrCod (Ctr->CtrCod);
/***** Link to action *****/
2018-10-17 01:08:42 +02:00
snprintf (Gbl.Title,sizeof (Gbl.Title),
Txt_Go_to_X,
Ctr->FullName);
2018-11-09 20:47:39 +01:00
Frm_LinkFormSubmit (Gbl.Title,ClassLink,NULL);
2015-11-19 19:37:44 +01:00
2015-11-19 20:04:41 +01:00
/***** Draw centre logo *****/
2019-01-11 02:55:01 +01:00
Log_DrawLogo (Sco_SCOPE_CTR,Ctr->CtrCod,Ctr->ShrtName,16,ClassLogo,true);
2015-11-19 19:37:44 +01:00
/***** End link *****/
fprintf (Gbl.F.Out,"&nbsp;%s</a>",Ctr->FullName);
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-11-19 19:37:44 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/****************** Show information of the current centre *******************/
/*****************************************************************************/
void Ctr_ShowConfiguration (void)
{
Ctr_Configuration (false);
2015-10-06 01:19:21 +02:00
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
}
/*****************************************************************************/
/****************** Print information of the current centre ******************/
/*****************************************************************************/
void Ctr_PrintConfiguration (void)
{
Ctr_Configuration (true);
}
/*****************************************************************************/
/******************* Information of the current centre ***********************/
/*****************************************************************************/
static void Ctr_Configuration (bool PrintView)
{
2016-11-13 16:48:36 +01:00
extern const char *Hlp_CENTRE_Information;
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormInBox[The_NUM_THEMES];
2016-10-20 16:49:42 +02:00
extern const char *Txt_Institution;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Centre;
2015-02-04 20:03:23 +01:00
extern const char *Txt_Short_name;
2017-06-12 19:14:05 +02:00
extern const char *Txt_Another_place;
2015-02-04 20:03:23 +01:00
extern const char *Txt_Web;
2015-03-07 18:09:42 +01:00
extern const char *Txt_Shortcut;
2018-12-08 16:43:13 +01:00
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_QR_code;
2015-12-09 22:05:21 +01:00
extern const char *Txt_Users_of_the_centre;
extern const char *Txt_Place;
extern const char *Txt_Degrees;
2016-05-30 19:40:20 +02:00
extern const char *Txt_Degrees_of_CENTRE_X;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Courses;
2016-10-20 16:49:42 +02:00
unsigned NumIns;
2017-06-12 19:14:05 +02:00
unsigned NumPlc;
2015-12-09 22:05:21 +01:00
struct Place Plc;
2017-01-28 15:58:46 +01:00
char PathPhoto[PATH_MAX + 1];
2014-12-01 23:55:08 +01:00
bool PhotoExists;
char *PhotoAttribution = NULL;
bool PutLink = !PrintView && Gbl.CurrentCtr.Ctr.WWW[0];
if (Gbl.CurrentCtr.Ctr.CtrCod > 0)
{
2015-01-14 00:32:23 +01:00
/***** Path to photo *****/
2018-10-17 01:08:42 +02:00
snprintf (PathPhoto,sizeof (PathPhoto),
2019-03-20 01:36:36 +01:00
"%s/%02u/%u/%u.jpg",
Cfg_PATH_CTR_PUBLIC,
2018-10-17 01:08:42 +02:00
(unsigned) (Gbl.CurrentCtr.Ctr.CtrCod % 100),
(unsigned) Gbl.CurrentCtr.Ctr.CtrCod,
(unsigned) Gbl.CurrentCtr.Ctr.CtrCod);
2014-12-01 23:55:08 +01:00
PhotoExists = Fil_CheckIfPathExists (PathPhoto);
2017-06-12 14:16:33 +02:00
/***** Start box *****/
2017-06-11 22:26:40 +02:00
if (PrintView)
Box_StartBox (NULL,NULL,NULL,
2017-06-12 15:03:29 +02:00
NULL,Box_NOT_CLOSABLE);
2017-06-11 22:26:40 +02:00
else
2019-02-11 21:35:36 +01:00
Box_StartBox (NULL,NULL,Ctr_PutIconsCtrConfig,
2017-06-12 15:03:29 +02:00
Hlp_CENTRE_Information,Box_NOT_CLOSABLE);
2014-12-08 17:35:48 +01:00
2014-12-01 23:55:08 +01:00
/***** Title *****/
2016-11-23 23:58:46 +01:00
fprintf (Gbl.F.Out,"<div class=\"FRAME_TITLE FRAME_TITLE_BIG\">");
2014-12-01 23:55:08 +01:00
if (PutLink)
fprintf (Gbl.F.Out,"<a href=\"%s\" target=\"_blank\""
2016-11-23 23:58:46 +01:00
" class=\"FRAME_TITLE_BIG\" title=\"%s\">",
2014-12-01 23:55:08 +01:00
Gbl.CurrentCtr.Ctr.WWW,
Gbl.CurrentCtr.Ctr.FullName);
2015-02-01 20:17:24 +01:00
Log_DrawLogo (Sco_SCOPE_CTR,Gbl.CurrentCtr.Ctr.CtrCod,
2016-10-28 10:03:37 +02:00
Gbl.CurrentCtr.Ctr.ShrtName,64,NULL,true);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<br />%s",Gbl.CurrentCtr.Ctr.FullName);
if (PutLink)
fprintf (Gbl.F.Out,"</a>");
2016-03-18 20:25:07 +01:00
fprintf (Gbl.F.Out,"</div>");
2014-12-01 23:55:08 +01:00
/***** Centre photo *****/
if (PhotoExists)
{
/* Get photo attribution */
Ctr_GetPhotoAttribution (Gbl.CurrentCtr.Ctr.CtrCod,&PhotoAttribution);
/* Photo image */
2016-03-18 20:25:07 +01:00
fprintf (Gbl.F.Out,"<div class=\"DAT_SMALL CENTER_MIDDLE\">");
2014-12-01 23:55:08 +01:00
if (PutLink)
fprintf (Gbl.F.Out,"<a href=\"%s\" target=\"_blank\" class=\"DAT_N\">",
Gbl.CurrentCtr.Ctr.WWW);
2019-03-20 01:36:36 +01:00
fprintf (Gbl.F.Out,"<img src=\"%s/%02u/%u/%u.jpg\""
2015-07-21 17:24:52 +02:00
" alt=\"%s\" title=\"%s\""
" class=\"%s\" />",
2019-03-20 01:36:36 +01:00
Cfg_URL_CTR_PUBLIC,
2014-12-01 23:55:08 +01:00
(unsigned) (Gbl.CurrentCtr.Ctr.CtrCod % 100),
(unsigned) Gbl.CurrentCtr.Ctr.CtrCod,
(unsigned) Gbl.CurrentCtr.Ctr.CtrCod,
2016-10-28 10:03:37 +02:00
Gbl.CurrentCtr.Ctr.ShrtName,
2015-07-21 17:24:52 +02:00
Gbl.CurrentCtr.Ctr.FullName,
2014-12-01 23:55:08 +01:00
PrintView ? "CENTRE_PHOTO_PRINT" :
"CENTRE_PHOTO_SHOW");
if (PutLink)
fprintf (Gbl.F.Out,"</a>");
2016-03-18 20:25:07 +01:00
fprintf (Gbl.F.Out,"</div>");
2014-12-01 23:55:08 +01:00
/* Photo attribution */
2016-10-24 18:00:21 +02:00
if (!PrintView &&
2017-06-04 18:18:54 +02:00
Gbl.Usrs.Me.Role.Logged >= Rol_CTR_ADM)
2016-10-24 18:00:21 +02:00
// Only centre admins, institution admins and centre admins
// have permission to edit photo attribution
2014-12-01 23:55:08 +01:00
{
2016-03-18 20:25:07 +01:00
fprintf (Gbl.F.Out,"<div class=\"CENTER_MIDDLE\">");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgCtrPhoAtt);
2016-03-28 19:30:37 +02:00
fprintf (Gbl.F.Out,"<textarea id=\"AttributionArea\""
" name=\"Attribution\" rows=\"2\""
2015-10-22 14:49:48 +02:00
" onchange=\"document.getElementById('%s').submit();\">",
2016-01-14 10:31:09 +01:00
Gbl.Form.Id);
2014-12-01 23:55:08 +01:00
if (PhotoAttribution)
fprintf (Gbl.F.Out,"%s",PhotoAttribution);
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</textarea>");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-03-18 20:25:07 +01:00
fprintf (Gbl.F.Out,"</div>");
2014-12-01 23:55:08 +01:00
}
else if (PhotoAttribution)
2016-03-18 20:25:07 +01:00
fprintf (Gbl.F.Out,"<div class=\"ATTRIBUTION\">"
2014-12-22 14:08:19 +01:00
"%s"
2016-03-18 20:25:07 +01:00
"</div>",
2014-12-01 23:55:08 +01:00
PhotoAttribution);
/* Free memory used for photo attribution */
Ctr_FreePhotoAttribution (&PhotoAttribution);
}
2016-03-18 20:25:07 +01:00
/***** Start table *****/
2017-06-11 20:09:59 +02:00
Tbl_StartTableWide (2);
2016-03-18 20:25:07 +01:00
2016-10-20 16:49:42 +02:00
/***** Institution *****/
fprintf (Gbl.F.Out,"<tr>"
2016-12-21 00:25:41 +01:00
"<td class=\"RIGHT_MIDDLE\">"
"<label for=\"OthInsCod\" class=\"%s\">%s:</label>"
2016-10-20 16:49:42 +02:00
"</td>"
2016-10-24 18:14:15 +02:00
"<td class=\"DAT_N LEFT_MIDDLE\">",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],
2016-10-20 16:49:42 +02:00
Txt_Institution);
if (!PrintView &&
2017-06-04 18:18:54 +02:00
Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)
2016-10-23 14:49:03 +02:00
// Only system admins can move a centre to another institution
2016-10-20 16:49:42 +02:00
{
/* Get list of institutions of the current country */
Ins_GetListInstitutions (Gbl.CurrentCty.Cty.CtyCod,Ins_GET_BASIC_DATA);
/* Put form to select institution */
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgCtrInsCfg);
2016-12-21 00:25:41 +01:00
fprintf (Gbl.F.Out,"<select id=\"OthInsCod\" name=\"OthInsCod\""
2016-10-20 16:49:42 +02:00
" class=\"INPUT_SHORT_NAME\""
" onchange=\"document.getElementById('%s').submit();\">",
Gbl.Form.Id);
for (NumIns = 0;
NumIns < Gbl.Inss.Num;
NumIns++)
fprintf (Gbl.F.Out,"<option value=\"%ld\"%s>%s</option>",
Gbl.Inss.Lst[NumIns].InsCod,
Gbl.Inss.Lst[NumIns].InsCod == Gbl.CurrentIns.Ins.InsCod ? " selected=\"selected\"" :
"",
2016-10-28 10:03:37 +02:00
Gbl.Inss.Lst[NumIns].ShrtName);
2016-10-20 16:49:42 +02:00
fprintf (Gbl.F.Out,"</select>");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-10-20 16:49:42 +02:00
/* Free list of institutions */
Ins_FreeListInstitutions ();
}
else // I can not move centre to another institution
fprintf (Gbl.F.Out,"%s",Gbl.CurrentIns.Ins.FullName);
fprintf (Gbl.F.Out,"</td>"
"</tr>");
2014-12-01 23:55:08 +01:00
/***** Centre full name *****/
fprintf (Gbl.F.Out,"<tr>"
2016-12-21 00:25:41 +01:00
"<td class=\"RIGHT_MIDDLE\">"
"<label for=\"FullName\" class=\"%s\">%s:</label>"
2014-12-22 14:08:19 +01:00
"</td>"
2015-07-28 10:15:44 +02:00
"<td class=\"DAT_N LEFT_MIDDLE\">",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],
2014-12-01 23:55:08 +01:00
Txt_Centre);
2016-10-22 22:39:53 +02:00
if (!PrintView &&
2017-06-04 18:18:54 +02:00
Gbl.Usrs.Me.Role.Logged >= Rol_INS_ADM)
2016-10-23 14:49:03 +02:00
// Only institution admins and system admins can edit centre full name
2016-10-22 22:39:53 +02:00
{
2016-10-23 14:49:03 +02:00
/* Form to change centre full name */
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRenCtrFulCfg);
2016-12-21 00:25:41 +01:00
fprintf (Gbl.F.Out,"<input type=\"text\""
" id=\"FullName\" name=\"FullName\""
2016-10-22 22:39:53 +02:00
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_FULL_NAME\""
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-08 14:12:33 +01:00
Hie_MAX_CHARS_FULL_NAME,
2016-10-22 22:39:53 +02:00
Gbl.CurrentCtr.Ctr.FullName,
Gbl.Form.Id);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-10-22 22:39:53 +02:00
}
else // I can not edit centre full name
fprintf (Gbl.F.Out,"%s",Gbl.CurrentCtr.Ctr.FullName);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
/***** Centre short name *****/
fprintf (Gbl.F.Out,"<tr>"
2016-12-21 00:25:41 +01:00
"<td class=\"RIGHT_MIDDLE\">"
"<label for=\"ShortName\" class=\"%s\">%s:</label>"
2016-10-23 12:07:16 +02:00
"</td>"
"<td class=\"DAT_N LEFT_MIDDLE\">",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],
2016-10-23 12:07:16 +02:00
Txt_Short_name);
if (!PrintView &&
2017-06-04 18:18:54 +02:00
Gbl.Usrs.Me.Role.Logged >= Rol_INS_ADM)
2016-10-23 14:49:03 +02:00
// Only institution admins and system admins can edit centre short name
2016-10-23 12:07:16 +02:00
{
2016-10-23 14:49:03 +02:00
/* Form to change centre short name */
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRenCtrShoCfg);
2016-12-21 00:25:41 +01:00
fprintf (Gbl.F.Out,"<input type=\"text\""
" id=\"ShortName\" name=\"ShortName\""
2016-10-23 12:07:16 +02:00
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_SHORT_NAME\""
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-08 14:12:33 +01:00
Hie_MAX_CHARS_SHRT_NAME,
2016-10-28 10:03:37 +02:00
Gbl.CurrentCtr.Ctr.ShrtName,
2016-10-23 12:07:16 +02:00
Gbl.Form.Id);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-10-23 12:07:16 +02:00
}
else // I can not edit centre short name
2016-10-28 10:03:37 +02:00
fprintf (Gbl.F.Out,"%s",Gbl.CurrentCtr.Ctr.ShrtName);
2016-10-23 12:07:16 +02:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
2014-12-01 23:55:08 +01:00
2017-06-12 19:14:05 +02:00
/***** Place *****/
Plc.PlcCod = Gbl.CurrentCtr.Ctr.PlcCod;
Plc_GetDataOfPlaceByCod (&Plc);
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"%s RIGHT_MIDDLE\">"
"%s:"
"</td>"
"<td class=\"DAT LEFT_MIDDLE\">",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],
2017-06-12 19:14:05 +02:00
Txt_Place);
if (!PrintView &&
Gbl.Usrs.Me.Role.Logged >= Rol_CTR_ADM)
// Only centre admins, institution admins and system admins
// can change centre place
{
/* Get list of places of the current institution */
Gbl.Plcs.SelectedOrder = Plc_ORDER_BY_PLACE;
Plc_GetListPlaces ();
/* Put form to select place */
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgCtrPlcCfg);
2017-06-12 19:14:05 +02:00
fprintf (Gbl.F.Out,"<select name=\"PlcCod\" class=\"INPUT_SHORT_NAME\""
" onchange=\"document.getElementById('%s').submit();\">",
Gbl.Form.Id);
fprintf (Gbl.F.Out,"<option value=\"0\"");
if (Gbl.CurrentCtr.Ctr.PlcCod == 0)
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%s</option>",Txt_Another_place);
for (NumPlc = 0;
NumPlc < Gbl.Plcs.Num;
NumPlc++)
fprintf (Gbl.F.Out,"<option value=\"%ld\"%s>%s</option>",
Gbl.Plcs.Lst[NumPlc].PlcCod,
(Gbl.Plcs.Lst[NumPlc].PlcCod == Gbl.CurrentCtr.Ctr.PlcCod) ? " selected=\"selected\"" :
"",
Gbl.Plcs.Lst[NumPlc].ShrtName);
fprintf (Gbl.F.Out,"</select>");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2017-06-12 19:14:05 +02:00
/* Free list of places */
Plc_FreeListPlaces ();
}
else // I can not change centre place
fprintf (Gbl.F.Out,"%s",Plc.FullName);
fprintf (Gbl.F.Out,"</td>"
"</tr>");
2015-02-04 20:03:23 +01:00
/***** Centre WWW *****/
2016-10-23 14:49:03 +02:00
fprintf (Gbl.F.Out,"<tr>"
2016-12-21 00:25:41 +01:00
"<td class=\"RIGHT_MIDDLE\">"
"<label for=\"WWW\" class=\"%s\">%s:</label>"
2016-10-23 14:49:03 +02:00
"</td>"
2017-06-12 19:14:05 +02:00
"<td class=\"LEFT_MIDDLE\">",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],
2016-10-23 14:49:03 +02:00
Txt_Web);
if (!PrintView &&
2017-06-04 18:18:54 +02:00
Gbl.Usrs.Me.Role.Logged >= Rol_CTR_ADM)
2016-10-24 18:14:15 +02:00
// Only centre admins, institution admins and system admins
// can change centre WWW
2015-02-04 20:03:23 +01:00
{
2016-10-23 14:49:03 +02:00
/* Form to change centre WWW */
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgCtrWWWCfg);
2016-12-21 00:25:41 +01:00
fprintf (Gbl.F.Out,"<input type=\"url\" id=\"WWW\" name=\"WWW\""
2016-10-23 14:49:03 +02:00
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_WWW\""
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-07 01:56:41 +01:00
Cns_MAX_CHARS_WWW,
2016-10-23 14:49:03 +02:00
Gbl.CurrentCtr.Ctr.WWW,
Gbl.Form.Id);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-10-23 14:49:03 +02:00
}
else // I can not change centre WWW
2017-03-04 01:27:54 +01:00
fprintf (Gbl.F.Out,"<div class=\"EXTERNAL_WWW_LONG\">"
2016-10-22 19:22:33 +02:00
"<a href=\"%s\" target=\"_blank\" class=\"DAT\">"
"%s"
2015-02-04 20:03:23 +01:00
"</a>"
2016-10-22 19:22:33 +02:00
"</div>",
Gbl.CurrentCtr.Ctr.WWW,
2015-02-04 20:03:23 +01:00
Gbl.CurrentCtr.Ctr.WWW);
2016-10-23 14:49:03 +02:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
2015-02-04 20:03:23 +01:00
/***** Shortcut to the centre *****/
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<tr>"
2015-07-27 21:25:45 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2014-12-22 14:08:19 +01:00
"%s:"
"</td>"
2015-07-28 10:15:44 +02:00
"<td class=\"DAT LEFT_MIDDLE\">"
2015-03-07 21:08:44 +01:00
"<a href=\"%s/%s?ctr=%ld\" class=\"DAT\" target=\"_blank\">"
"%s/%s?ctr=%ld"
2014-12-22 14:08:19 +01:00
"</a>"
2014-12-01 23:55:08 +01:00
"</td>"
"</tr>",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],
2015-03-07 18:09:42 +01:00
Txt_Shortcut,
2016-07-08 12:43:48 +02:00
Cfg_URL_SWAD_CGI,
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Gbl.Prefs.Language],
2015-12-07 23:13:08 +01:00
Gbl.CurrentCtr.Ctr.CtrCod,
2016-07-08 12:43:48 +02:00
Cfg_URL_SWAD_CGI,
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Gbl.Prefs.Language],
2015-12-07 23:13:08 +01:00
Gbl.CurrentCtr.Ctr.CtrCod);
2014-12-01 23:55:08 +01:00
if (PrintView)
{
/***** QR code with link to the centre *****/
fprintf (Gbl.F.Out,"<tr>"
2015-07-27 21:25:45 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2014-12-22 14:08:19 +01:00
"%s:"
"</td>"
2015-07-28 10:15:44 +02:00
"<td class=\"DAT LEFT_MIDDLE\">",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],
2014-12-01 23:55:08 +01:00
Txt_QR_code);
2015-09-28 18:28:29 +02:00
QR_LinkTo (250,"ctr",Gbl.CurrentCtr.Ctr.CtrCod);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
}
else
{
2015-12-09 22:05:21 +01:00
/***** Number of users who claim to belong to this centre *****/
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"%s RIGHT_MIDDLE\">"
"%s:"
"</td>"
"<td class=\"DAT LEFT_MIDDLE\">"
"%u"
"</td>"
"</tr>",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],
2015-12-09 22:05:21 +01:00
Txt_Users_of_the_centre,
Usr_GetNumUsrsWhoClaimToBelongToCtr (Gbl.CurrentCtr.Ctr.CtrCod));
2014-12-01 23:55:08 +01:00
/***** Number of degrees *****/
fprintf (Gbl.F.Out,"<tr>"
2015-07-27 21:25:45 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2016-05-30 19:40:20 +02:00
"%s:"
"</td>"
"<td class=\"LEFT_MIDDLE\">",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],
2016-05-30 19:40:20 +02:00
Txt_Degrees);
/* Form to go to see degrees of this centre */
2018-11-09 20:47:39 +01:00
Frm_StartFormGoTo (ActSeeDeg);
2016-05-30 19:52:46 +02:00
Ctr_PutParamCtrCod (Gbl.CurrentCtr.Ctr.CtrCod);
2018-10-17 01:08:42 +02:00
snprintf (Gbl.Title,sizeof (Gbl.Title),
Txt_Degrees_of_CENTRE_X,
Gbl.CurrentCtr.Ctr.ShrtName);
2018-11-09 20:47:39 +01:00
Frm_LinkFormSubmit (Gbl.Title,"DAT",NULL);
2016-05-30 19:40:20 +02:00
fprintf (Gbl.F.Out,"%u</a>",
2014-12-01 23:55:08 +01:00
Deg_GetNumDegsInCtr (Gbl.CurrentCtr.Ctr.CtrCod));
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-05-30 19:40:20 +02:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
2014-12-01 23:55:08 +01:00
/***** Number of courses *****/
fprintf (Gbl.F.Out,"<tr>"
2015-07-27 21:25:45 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2014-12-22 14:08:19 +01:00
"%s:"
"</td>"
2015-07-28 10:15:44 +02:00
"<td class=\"DAT LEFT_MIDDLE\">"
2014-12-22 14:08:19 +01:00
"%u"
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],
2014-12-01 23:55:08 +01:00
Txt_Courses,
Crs_GetNumCrssInCtr (Gbl.CurrentCtr.Ctr.CtrCod));
2015-12-09 22:05:21 +01:00
/***** Number of users in courses of this centre *****/
2017-05-21 14:43:10 +02:00
Ctr_ShowNumUsrsInCrssOfCtr (Rol_TCH);
2017-05-21 21:23:13 +02:00
Ctr_ShowNumUsrsInCrssOfCtr (Rol_NET);
2017-05-21 14:43:10 +02:00
Ctr_ShowNumUsrsInCrssOfCtr (Rol_STD);
Ctr_ShowNumUsrsInCrssOfCtr (Rol_UNK);
2014-12-01 23:55:08 +01:00
}
2014-12-08 17:35:48 +01:00
2016-03-18 20:48:24 +01:00
/***** End table *****/
2017-06-11 20:09:59 +02:00
Tbl_EndTable ();
2016-03-18 20:48:24 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2017-06-10 21:38:10 +02:00
Box_EndBox ();
2014-12-01 23:55:08 +01:00
}
}
2016-03-18 20:25:07 +01:00
/*****************************************************************************/
2016-05-05 20:16:28 +02:00
/************ Put contextual icons in configuration of a centre **************/
2016-03-18 20:25:07 +01:00
/*****************************************************************************/
2019-02-11 21:35:36 +01:00
static void Ctr_PutIconsCtrConfig (void)
2016-03-18 20:25:07 +01:00
{
2019-02-11 21:35:36 +01:00
/***** Put icon to print info about centre *****/
2017-06-11 19:13:28 +02:00
Ico_PutContextualIconToPrint (ActPrnCtrInf,NULL);
2016-05-05 19:53:35 +02:00
2019-02-11 21:35:36 +01:00
/***** Put icon to view places *****/
Plc_PutIconToViewPlaces ();
2017-06-04 18:18:54 +02:00
if (Gbl.Usrs.Me.Role.Logged >= Rol_CTR_ADM)
2016-10-24 18:25:12 +02:00
// Only centre admins, institution admins and system admins
2016-10-24 18:00:21 +02:00
// have permission to upload logo and photo of the centre
2016-05-05 19:53:35 +02:00
{
2019-02-11 21:35:36 +01:00
/***** Put icon to upload logo of centre *****/
2016-05-05 20:16:28 +02:00
Log_PutIconToChangeLogo (Sco_SCOPE_CTR);
2016-05-05 19:53:35 +02:00
2019-02-11 21:35:36 +01:00
/***** Put icon to upload photo of centre *****/
2016-05-05 20:16:28 +02:00
Ctr_PutIconToChangePhoto ();
2016-05-05 19:53:35 +02:00
}
2016-03-18 20:25:07 +01:00
}
2016-05-05 20:16:28 +02:00
/*****************************************************************************/
/************* Put contextual icons to upload photo of centre ****************/
/*****************************************************************************/
static void Ctr_PutIconToChangePhoto (void)
{
extern const char *Txt_Change_photo;
extern const char *Txt_Upload_photo;
2017-01-28 15:58:46 +01:00
char PathPhoto[PATH_MAX + 1];
2016-05-05 20:16:28 +02:00
bool PhotoExists;
/***** Link to upload photo of centre *****/
2018-10-17 01:08:42 +02:00
snprintf (PathPhoto,sizeof (PathPhoto),
2019-03-20 01:36:36 +01:00
"%s/%02u/%u/%u.jpg",
Cfg_PATH_CTR_PUBLIC,
2018-10-17 01:08:42 +02:00
(unsigned) (Gbl.CurrentCtr.Ctr.CtrCod % 100),
(unsigned) Gbl.CurrentCtr.Ctr.CtrCod,
(unsigned) Gbl.CurrentCtr.Ctr.CtrCod);
2016-05-05 20:16:28 +02:00
PhotoExists = Fil_CheckIfPathExists (PathPhoto);
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkOnlyIcon (ActReqCtrPho,NULL,NULL,
"camera.svg",
PhotoExists ? Txt_Change_photo :
Txt_Upload_photo);
2016-05-05 20:16:28 +02:00
}
2017-05-21 14:43:10 +02:00
/*****************************************************************************/
/**************** Number of users in courses of this centre ******************/
/*****************************************************************************/
static void Ctr_ShowNumUsrsInCrssOfCtr (Rol_Role_t Role)
{
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormInBox[The_NUM_THEMES];
2017-05-21 14:43:10 +02:00
extern const char *Txt_Users_in_courses;
extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"%s RIGHT_MIDDLE\">"
"%s:"
"</td>"
"<td class=\"DAT LEFT_MIDDLE\">"
"%u"
"</td>"
"</tr>",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],
2017-05-21 14:43:10 +02:00
(Role == Rol_UNK) ? Txt_Users_in_courses :
Txt_ROLES_PLURAL_Abc[Role][Usr_SEX_UNKNOWN],
Usr_GetNumUsrsInCrssOfCtr (Role,Gbl.CurrentCtr.Ctr.CtrCod));
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/*************** Show the centres of the current institution *****************/
/*****************************************************************************/
void Ctr_ShowCtrsOfCurrentIns (void)
{
if (Gbl.CurrentIns.Ins.InsCod > 0)
{
/***** Get parameter with the type of order in the list of centres *****/
2017-01-29 12:42:19 +01:00
Ctr_GetParamCtrOrder ();
2014-12-01 23:55:08 +01:00
/***** Get list of centres *****/
Ctr_GetListCentres (Gbl.CurrentIns.Ins.InsCod);
/***** Write menu to select country and institution *****/
2016-11-14 17:26:32 +01:00
Hie_WriteMenuHierarchy ();
2014-12-01 23:55:08 +01:00
/***** List centres *****/
Ctr_ListCentres ();
/***** Free list of centres *****/
Ctr_FreeListCentres ();
}
}
/*****************************************************************************/
/******************** List centres in this institution ***********************/
/*****************************************************************************/
static void Ctr_ListCentres (void)
{
2016-11-13 15:00:58 +01:00
extern const char *Hlp_INSTITUTION_Centres;
2016-03-20 13:47:46 +01:00
extern const char *Txt_Centres_of_INSTITUTION_X;
extern const char *Txt_No_centres;
2016-03-16 13:23:10 +01:00
extern const char *Txt_Create_another_centre;
2015-10-06 01:19:21 +02:00
extern const char *Txt_Create_centre;
2016-03-20 13:47:46 +01:00
unsigned NumCtr;
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** Start box *****/
2018-10-17 01:08:42 +02:00
snprintf (Gbl.Title,sizeof (Gbl.Title),
Txt_Centres_of_INSTITUTION_X,
Gbl.CurrentIns.Ins.FullName);
2018-11-15 10:33:45 +01:00
Box_StartBox (NULL,Gbl.Title,Ctr_PutIconsListingCentres,
2017-06-12 15:03:29 +02:00
Hlp_INSTITUTION_Centres,Box_NOT_CLOSABLE);
2016-03-20 13:47:46 +01:00
2015-10-06 01:19:21 +02:00
if (Gbl.Ctrs.Num) // There are centres in the current institution
2016-03-20 13:47:46 +01:00
{
/***** Start table *****/
2017-06-11 20:09:59 +02:00
Tbl_StartTableWideMargin (2);
2016-03-20 13:47:46 +01:00
Ctr_PutHeadCentresForSeeing (true); // Order selectable
/***** Write all the centres and their nuber of teachers *****/
for (NumCtr = 0;
NumCtr < Gbl.Ctrs.Num;
NumCtr++)
Ctr_ListOneCentreForSeeing (&(Gbl.Ctrs.Lst[NumCtr]),NumCtr + 1);
/***** End table *****/
2017-06-11 20:09:59 +02:00
Tbl_EndTable ();
2016-03-20 13:47:46 +01:00
}
else // No centres created in the current institution
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_INFO,Txt_No_centres);
2016-03-16 12:54:05 +01:00
2016-03-20 13:47:46 +01:00
/***** Button to create centre *****/
2016-11-07 00:03:50 +01:00
if (Ctr_CheckIfICanCreateCentres ())
2016-03-16 12:54:05 +01:00
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActEdiCtr);
2017-06-11 19:02:40 +02:00
Btn_PutConfirmButton (Gbl.Ctrs.Num ? Txt_Create_another_centre :
2016-03-16 13:23:10 +01:00
Txt_Create_centre);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-10-06 01:19:21 +02:00
}
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2017-06-10 21:38:10 +02:00
Box_EndBox ();
2014-12-01 23:55:08 +01:00
}
2016-11-06 23:46:29 +01:00
/*****************************************************************************/
2016-11-07 00:03:50 +01:00
/********************** Check if I can create centres ************************/
2016-11-06 23:46:29 +01:00
/*****************************************************************************/
2016-11-07 00:03:50 +01:00
static bool Ctr_CheckIfICanCreateCentres (void)
2016-11-06 23:46:29 +01:00
{
2017-06-04 18:18:54 +02:00
return (bool) (Gbl.Usrs.Me.Role.Logged >= Rol_GST);
2016-11-06 23:46:29 +01:00
}
/*****************************************************************************/
/***************** Put contextual icons in list of centres *******************/
/*****************************************************************************/
2018-11-15 10:33:45 +01:00
static void Ctr_PutIconsListingCentres (void)
2016-11-06 23:46:29 +01:00
{
/***** Put icon to edit centres *****/
2016-11-07 00:03:50 +01:00
if (Ctr_CheckIfICanCreateCentres ())
2016-11-06 23:46:29 +01:00
Ctr_PutIconToEditCentres ();
2017-03-26 14:57:47 +02:00
/***** Put icon to view places *****/
Plc_PutIconToViewPlaces ();
2016-11-06 23:46:29 +01:00
/***** Put icon to show a figure *****/
2019-02-12 14:46:14 +01:00
Gbl.Figures.FigureType = Fig_HIERARCHY;
Fig_PutIconToShowFigure ();
2016-11-06 23:46:29 +01:00
}
2016-03-16 13:23:10 +01:00
/*****************************************************************************/
/********************** Put link (form) to edit centres **********************/
/*****************************************************************************/
2016-11-06 23:46:29 +01:00
static void Ctr_PutIconToEditCentres (void)
2016-03-16 13:23:10 +01:00
{
2017-06-11 19:13:28 +02:00
Ico_PutContextualIconToEdit (ActEdiCtr,NULL);
2016-03-16 13:23:10 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************* List one centre for seeing ************************/
/*****************************************************************************/
static void Ctr_ListOneCentreForSeeing (struct Centre *Ctr,unsigned NumCtr)
{
extern const char *Txt_CENTRE_STATUS[Ctr_NUM_STATUS_TXT];
struct Place Plc;
2015-11-19 16:09:51 +01:00
const char *TxtClassNormal;
const char *TxtClassStrong;
2015-09-04 19:26:08 +02:00
const char *BgColor;
2017-03-17 00:46:28 +01:00
Ctr_StatusTxt_t StatusTxt;
2014-12-01 23:55:08 +01:00
/***** Get data of place of this centre *****/
Plc.PlcCod = Ctr->PlcCod;
Plc_GetDataOfPlaceByCod (&Plc);
2015-11-19 16:09:51 +01:00
if (Ctr->Status & Ctr_STATUS_BIT_PENDING)
{
TxtClassNormal = "DAT_LIGHT";
TxtClassStrong = "DAT_LIGHT";
}
else
{
TxtClassNormal = "DAT";
TxtClassStrong = "DAT_N";
}
2015-09-04 19:26:08 +02:00
BgColor = (Ctr->CtrCod == Gbl.CurrentCtr.Ctr.CtrCod) ? "LIGHT_BLUE" :
Gbl.ColorRows[Gbl.RowEvenOdd];
2014-12-01 23:55:08 +01:00
/***** Number of centre in this list *****/
fprintf (Gbl.F.Out,"<tr>"
2015-09-04 17:10:27 +02:00
"<td class=\"%s RIGHT_MIDDLE %s\">"
2014-12-01 23:55:08 +01:00
"%u"
"</td>",
2015-11-19 16:09:51 +01:00
TxtClassNormal,BgColor,
2014-12-01 23:55:08 +01:00
NumCtr);
2015-11-19 16:09:51 +01:00
/***** Centre logo and name *****/
2015-11-19 19:37:44 +01:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE %s\">",BgColor);
Ctr_DrawCentreLogoAndNameWithLink (Ctr,ActSeeDeg,
TxtClassStrong,"CENTER_MIDDLE");
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
2015-12-09 22:05:21 +01:00
/***** Number of users who claim to belong to this centre *****/
2015-09-04 17:10:27 +02:00
fprintf (Gbl.F.Out,"<td class=\"%s RIGHT_MIDDLE %s\">"
2014-12-22 14:08:19 +01:00
"%u"
"</td>",
2015-11-19 16:09:51 +01:00
TxtClassNormal,BgColor,
2015-12-09 22:05:21 +01:00
Ctr->NumUsrsWhoClaimToBelongToCtr);
/***** Place *****/
fprintf (Gbl.F.Out,"<td class=\"%s LEFT_MIDDLE %s\">"
"%s"
"</td>",
TxtClassNormal,BgColor,
2016-10-28 10:03:37 +02:00
Plc.ShrtName);
2014-12-01 23:55:08 +01:00
/***** Number of degrees *****/
2015-09-04 17:10:27 +02:00
fprintf (Gbl.F.Out,"<td class=\"%s RIGHT_MIDDLE %s\">"
2014-12-22 14:08:19 +01:00
"%u"
"</td>",
2015-11-19 16:09:51 +01:00
TxtClassNormal,BgColor,
2016-10-20 00:57:00 +02:00
Ctr->Degs.Num);
2014-12-01 23:55:08 +01:00
2015-12-09 22:05:21 +01:00
/***** Number of courses *****/
fprintf (Gbl.F.Out,"<td class=\"%s RIGHT_MIDDLE %s\">"
"%u"
"</td>",
TxtClassNormal,BgColor,
Ctr->NumCrss);
/***** Number of users in courses of this centre *****/
fprintf (Gbl.F.Out,"<td class=\"%s RIGHT_MIDDLE %s\">"
"%u"
"</td>",
TxtClassNormal,BgColor,
Ctr->NumUsrs);
2015-11-19 16:09:51 +01:00
2014-12-01 23:55:08 +01:00
/***** Centre status *****/
StatusTxt = Ctr_GetStatusTxtFromStatusBits (Ctr->Status);
2017-03-17 00:46:28 +01:00
fprintf (Gbl.F.Out,"<td class=\"%s LEFT_MIDDLE %s\">",
TxtClassNormal,BgColor);
if (StatusTxt != Ctr_STATUS_ACTIVE) // If active ==> do not show anything
fprintf (Gbl.F.Out,"%s",Txt_CENTRE_STATUS[StatusTxt]);
fprintf (Gbl.F.Out,"</td>"
"</tr>");
2014-12-01 23:55:08 +01:00
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
}
/*****************************************************************************/
/********** Get parameter with the type or order in list of centres **********/
/*****************************************************************************/
2017-01-29 12:42:19 +01:00
static void Ctr_GetParamCtrOrder (void)
2014-12-01 23:55:08 +01:00
{
2017-01-29 21:41:08 +01:00
Gbl.Ctrs.SelectedOrder = (Ctr_Order_t)
Par_GetParToUnsignedLong ("Order",
0,
Ctr_NUM_ORDERS - 1,
(unsigned long) Ctr_ORDER_DEFAULT);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************** Put forms to edit centres ************************/
/*****************************************************************************/
void Ctr_EditCentres (void)
{
2017-04-30 02:35:25 +02:00
extern const char *Hlp_INSTITUTION_Centres;
extern const char *Txt_Centres_of_INSTITUTION_X;
2016-10-20 21:09:01 +02:00
/***** Get list of places *****/
2017-06-12 18:17:24 +02:00
Gbl.Plcs.SelectedOrder = Plc_ORDER_BY_PLACE;
2016-10-20 21:09:01 +02:00
Plc_GetListPlaces ();
2014-12-01 23:55:08 +01:00
2016-10-20 21:09:01 +02:00
/***** Get list of centres *****/
2017-06-12 18:17:24 +02:00
Gbl.Ctrs.SelectedOrder = Ctr_ORDER_BY_CENTRE;
2016-10-20 21:09:01 +02:00
Ctr_GetListCentres (Gbl.CurrentIns.Ins.InsCod);
2014-12-01 23:55:08 +01:00
2018-11-15 10:33:45 +01:00
/***** Write menu to select country and institution *****/
Hie_WriteMenuHierarchy ();
2017-06-12 14:16:33 +02:00
/***** Start box *****/
2018-10-17 01:08:42 +02:00
snprintf (Gbl.Title,sizeof (Gbl.Title),
Txt_Centres_of_INSTITUTION_X,
Gbl.CurrentIns.Ins.FullName);
2017-06-10 21:38:10 +02:00
Box_StartBox (NULL,Gbl.Title,Ctr_PutIconsEditingCentres,
2017-06-12 15:03:29 +02:00
Hlp_INSTITUTION_Centres,Box_NOT_CLOSABLE);
2017-04-30 02:35:25 +02:00
2016-10-20 21:09:01 +02:00
/***** Put a form to create a new centre *****/
Ctr_PutFormToCreateCentre ();
2014-12-01 23:55:08 +01:00
2016-10-20 21:09:01 +02:00
/***** List current centres *****/
if (Gbl.Ctrs.Num)
Ctr_ListCentresForEdition ();
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2017-06-10 21:38:10 +02:00
Box_EndBox ();
2017-04-30 02:35:25 +02:00
2016-10-20 21:09:01 +02:00
/***** Free list of centres *****/
Ctr_FreeListCentres ();
2014-12-01 23:55:08 +01:00
2016-10-20 21:09:01 +02:00
/***** Free list of places *****/
Plc_FreeListPlaces ();
2014-12-01 23:55:08 +01:00
}
2017-04-30 02:35:25 +02:00
/*****************************************************************************/
/**************** Put contextual icons in edition of centres *****************/
/*****************************************************************************/
static void Ctr_PutIconsEditingCentres (void)
{
/***** Put icon to view centres *****/
Ctr_PutIconToViewCentres ();
/***** Put icon to view places *****/
Plc_PutIconToViewPlaces ();
2018-11-15 10:33:45 +01:00
/***** Put icon to show a figure *****/
2019-02-12 14:46:14 +01:00
Gbl.Figures.FigureType = Fig_HIERARCHY;
Fig_PutIconToShowFigure ();
2017-04-30 02:35:25 +02:00
}
2018-11-15 10:13:53 +01:00
void Ctr_PutIconToViewCentres (void)
2017-04-30 02:35:25 +02:00
{
2018-11-15 10:13:53 +01:00
extern const char *Txt_Centres;
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkOnlyIcon (ActSeeCtr,NULL,NULL,
"building.svg",
Txt_Centres);
2017-04-30 02:35:25 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/***** Get a list with all the centres or with those of an institution *******/
/*****************************************************************************/
// If InsCod <= 0 ==> get all the centres, of any institution
// In InsCod > 0 ==> get only the centres of the specified institution
void Ctr_GetListCentres (long InsCod)
{
2019-01-03 15:25:18 +01:00
static const char *OrderBySubQuery[Ctr_NUM_ORDERS] =
{
"FullName", // Ctr_ORDER_BY_CENTRE
"NumUsrs DESC,FullName", // Ctr_ORDER_BY_NUM_TCHS
};
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned NumCtr;
struct Centre *Ctr;
/***** Get centres from database *****/
2018-10-30 13:59:37 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get centres",
"(SELECT centres.CtrCod,centres.InsCod,centres.PlcCod,"
"centres.Status,centres.RequesterUsrCod,"
"centres.ShortName,centres.FullName,centres.WWW,"
"COUNT(DISTINCT usr_data.UsrCod) AS NumUsrs"
" FROM centres,usr_data"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=usr_data.CtrCod"
" GROUP BY centres.CtrCod)"
" UNION "
"(SELECT CtrCod,InsCod,PlcCod,Status,RequesterUsrCod,"
"ShortName,FullName,WWW,0 AS NumUsrs"
" FROM centres"
" WHERE centres.InsCod=%ld"
" AND CtrCod NOT IN"
" (SELECT DISTINCT CtrCod FROM usr_data))"
" ORDER BY %s",
InsCod,
InsCod,
2019-01-03 15:25:18 +01:00
OrderBySubQuery[Gbl.Ctrs.SelectedOrder]);
2014-12-01 23:55:08 +01:00
if (NumRows) // Centres found...
{
// NumRows should be equal to Deg->NumCourses
Gbl.Ctrs.Num = (unsigned) NumRows;
/***** Create list with courses in degree *****/
if ((Gbl.Ctrs.Lst = (struct Centre *) calloc (NumRows,sizeof (struct Centre))) == NULL)
2018-10-18 20:06:54 +02:00
Lay_NotEnoughMemoryExit ();
2014-12-01 23:55:08 +01:00
/***** Get the centres *****/
for (NumCtr = 0;
NumCtr < Gbl.Ctrs.Num;
NumCtr++)
{
Ctr = &(Gbl.Ctrs.Lst[NumCtr]);
/* Get next centre */
row = mysql_fetch_row (mysql_res);
/* Get centre code (row[0]) */
if ((Ctr->CtrCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
Lay_ShowErrorAndExit ("Wrong code of centre.");
/* Get institution code (row[1]) */
Ctr->InsCod = Str_ConvertStrCodToLongCod (row[1]);
/* Get place code (row[2]) */
Ctr->PlcCod = Str_ConvertStrCodToLongCod (row[2]);
/* Get centre status (row[3]) */
if (sscanf (row[3],"%u",&(Ctr->Status)) != 1)
Lay_ShowErrorAndExit ("Wrong centre status.");
/* Get requester user's code (row[4]) */
Ctr->RequesterUsrCod = Str_ConvertStrCodToLongCod (row[4]);
/* Get the short name of the centre (row[5]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Ctr->ShrtName,row[5],
2017-03-08 14:12:33 +01:00
Hie_MAX_BYTES_SHRT_NAME);
2014-12-01 23:55:08 +01:00
/* Get the full name of the centre (row[6]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Ctr->FullName,row[6],
2017-03-08 14:12:33 +01:00
Hie_MAX_BYTES_FULL_NAME);
2014-12-01 23:55:08 +01:00
2015-01-14 00:32:23 +01:00
/* Get the URL of the centre (row[7]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Ctr->WWW,row[7],
2017-03-07 01:56:41 +01:00
Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
2015-12-09 22:05:21 +01:00
/* Get number of users who claim to belong to this centre (row[8]) */
if (sscanf (row[8],"%u",&Ctr->NumUsrsWhoClaimToBelongToCtr) != 1)
Ctr->NumUsrsWhoClaimToBelongToCtr = 0;
/* Get number of degrees in this centre */
2016-10-20 00:57:00 +02:00
Ctr->Degs.Num = Deg_GetNumDegsInCtr (Ctr->CtrCod);
2014-12-01 23:55:08 +01:00
2015-12-09 22:05:21 +01:00
/* Get number of courses in this centre */
Ctr->NumCrss = Crs_GetNumCrssInCtr (Ctr->CtrCod);
/* Get number of users in courses of this centre */
2017-05-18 19:13:41 +02:00
Ctr->NumUsrs = Usr_GetNumUsrsInCrssOfCtr (Rol_UNK,Ctr->CtrCod); // Here Rol_UNK means "all users"
2014-12-01 23:55:08 +01:00
}
}
else
Gbl.Ctrs.Num = 0;
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/************************ Get data of centre by code *************************/
/*****************************************************************************/
bool Ctr_GetDataOfCentreByCod (struct Centre *Ctr)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2018-10-30 13:59:37 +01:00
unsigned long NumRows;
2014-12-01 23:55:08 +01:00
bool CtrFound = false;
/***** Clear data *****/
Ctr->InsCod = -1L;
Ctr->PlcCod = -1L;
Ctr->Status = (Ctr_Status_t) 0;
Ctr->RequesterUsrCod = -1L;
2016-10-28 10:03:37 +02:00
Ctr->ShrtName[0] = '\0';
2017-03-09 21:11:06 +01:00
Ctr->FullName[0] = '\0';
Ctr->WWW[0] = '\0';
2015-12-09 22:05:21 +01:00
Ctr->NumUsrsWhoClaimToBelongToCtr = 0;
2016-10-20 00:57:00 +02:00
Ctr->Degs.Num =
Ctr->NumCrss = 0;
2017-03-09 21:11:06 +01:00
Ctr->NumUsrs = 0;
2014-12-01 23:55:08 +01:00
/***** Check if centre code is correct *****/
if (Ctr->CtrCod > 0)
{
/***** Get data of a centre from database *****/
2018-10-30 13:59:37 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a centre",
"(SELECT centres.InsCod,centres.PlcCod,"
"centres.Status,centres.RequesterUsrCod,"
"centres.ShortName,centres.FullName,centres.WWW,"
"COUNT(DISTINCT usr_data.UsrCod) AS NumUsrs"
" FROM centres,usr_data"
" WHERE centres.CtrCod=%ld"
" AND centres.CtrCod=usr_data.CtrCod"
" GROUP BY centres.CtrCod)"
" UNION "
"(SELECT InsCod,PlcCod,"
"Status,RequesterUsrCod,"
"ShortName,FullName,WWW,"
"0 AS NumUsrs"
" FROM centres"
" WHERE CtrCod=%ld"
" AND CtrCod NOT IN"
" (SELECT DISTINCT CtrCod FROM usr_data))",
Ctr->CtrCod,
Ctr->CtrCod);
if (NumRows) // Centre found...
2014-12-01 23:55:08 +01:00
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get the code of the institution (row[0]) */
Ctr->InsCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get the code of the place (row[1]) */
Ctr->PlcCod = Str_ConvertStrCodToLongCod (row[1]);
/* Get centre status (row[2]) */
if (sscanf (row[2],"%u",&(Ctr->Status)) != 1)
Lay_ShowErrorAndExit ("Wrong centre status.");
/* Get requester user's code (row[3]) */
Ctr->RequesterUsrCod = Str_ConvertStrCodToLongCod (row[3]);
/* Get the short name of the centre (row[4]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Ctr->ShrtName,row[4],
2017-03-08 14:12:33 +01:00
Hie_MAX_BYTES_SHRT_NAME);
2014-12-01 23:55:08 +01:00
/* Get the full name of the centre (row[5]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Ctr->FullName,row[5],
2017-03-08 14:12:33 +01:00
Hie_MAX_BYTES_FULL_NAME);
2014-12-01 23:55:08 +01:00
2015-01-14 00:32:23 +01:00
/* Get the URL of the centre (row[6]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Ctr->WWW,row[6],
2017-03-07 01:56:41 +01:00
Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
2015-12-09 22:05:21 +01:00
/* Get number of users who claim to belong to this centre (row[7]) */
if (sscanf (row[7],"%u",&Ctr->NumUsrsWhoClaimToBelongToCtr) != 1)
Ctr->NumUsrsWhoClaimToBelongToCtr = 0;
2014-12-01 23:55:08 +01:00
2015-12-09 22:05:21 +01:00
/* Get number of degrees in this centre */
2016-10-20 00:57:00 +02:00
Ctr->Degs.Num = Deg_GetNumDegsInCtr (Ctr->CtrCod);
2015-12-09 22:05:21 +01:00
/* Get number of courses in this centre */
Ctr->NumCrss = Crs_GetNumCrssInCtr (Ctr->CtrCod);
/* Get number of users in courses of this centre */
2017-05-18 19:13:41 +02:00
Ctr->NumUsrs = Usr_GetNumUsrsInCrssOfCtr (Rol_UNK,Ctr->CtrCod); // Here Rol_UNK means "all users"
2014-12-01 23:55:08 +01:00
/* Set return value */
CtrFound = true;
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
return CtrFound;
}
2015-02-03 11:34:59 +01:00
/*****************************************************************************/
/*********** Get the institution code of a centre from its code **************/
/*****************************************************************************/
long Ctr_GetInsCodOfCentreByCod (long CtrCod)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long InsCod = -1L;
if (CtrCod > 0)
{
/***** Get the institution code of a centre from database *****/
2018-10-30 13:59:37 +01:00
if (DB_QuerySELECT (&mysql_res,"can not get the institution of a centre",
"SELECT InsCod FROM centres WHERE CtrCod=%ld",
CtrCod) == 1)
2015-02-03 11:34:59 +01:00
{
/***** Get the institution code of this centre *****/
row = mysql_fetch_row (mysql_res);
2015-02-04 19:18:09 +01:00
InsCod = Str_ConvertStrCodToLongCod (row[0]);
2015-02-03 11:34:59 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
return InsCod;
}
2015-10-10 22:16:46 +02:00
/*****************************************************************************/
/*************** Get the short name of a centre from its code ****************/
/*****************************************************************************/
void Ctr_GetShortNameOfCentreByCod (struct Centre *Ctr)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2016-10-28 10:03:37 +02:00
Ctr->ShrtName[0] = '\0';
2015-10-10 22:16:46 +02:00
if (Ctr->CtrCod > 0)
{
/***** Get the short name of a centre from database *****/
2018-10-30 13:59:37 +01:00
if (DB_QuerySELECT (&mysql_res,"can not get the short name of a centre",
"SELECT ShortName FROM centres"
" WHERE CtrCod=%ld",
Ctr->CtrCod) == 1)
2015-10-10 22:16:46 +02:00
{
/***** Get the short name of this centre *****/
row = mysql_fetch_row (mysql_res);
2017-01-13 01:51:23 +01:00
2017-01-17 03:10:43 +01:00
Str_Copy (Ctr->ShrtName,row[0],
2017-03-08 14:12:33 +01:00
Hie_MAX_BYTES_SHRT_NAME);
2015-10-10 22:16:46 +02:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/******************* Get photo attribution from database *********************/
/*****************************************************************************/
static void Ctr_GetPhotoAttribution (long CtrCod,char **PhotoAttribution)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2017-01-13 01:51:23 +01:00
size_t Length;
2014-12-01 23:55:08 +01:00
/***** Free possible former photo attribution *****/
Ctr_FreePhotoAttribution (PhotoAttribution);
/***** Get photo attribution from database *****/
2018-10-30 13:59:37 +01:00
if (DB_QuerySELECT (&mysql_res,"can not get photo attribution",
"SELECT PhotoAttribution"
" FROM centres WHERE CtrCod=%ld",
CtrCod))
2014-12-01 23:55:08 +01:00
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get the attribution of the photo of the centre (row[0]) */
if (row[0])
if (row[0][0])
{
2017-01-13 01:51:23 +01:00
Length = strlen (row[0]);
if (((*PhotoAttribution) = (char *) malloc (Length + 1)) == NULL)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Error allocating memory for photo attribution.");
2017-01-17 03:10:43 +01:00
Str_Copy (*PhotoAttribution,row[0],
Length);
2014-12-01 23:55:08 +01:00
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/****************** Free memory used for photo attribution *******************/
/*****************************************************************************/
static void Ctr_FreePhotoAttribution (char **PhotoAttribution)
{
if (*PhotoAttribution)
{
free ((void *) *PhotoAttribution);
*PhotoAttribution = NULL;
}
}
/*****************************************************************************/
/**************************** Free list of centres ***************************/
/*****************************************************************************/
void Ctr_FreeListCentres (void)
{
if (Gbl.Ctrs.Lst)
{
/***** Free memory used by the list of courses in degree *****/
free ((void *) Gbl.Ctrs.Lst);
Gbl.Ctrs.Lst = NULL;
Gbl.Ctrs.Num = 0;
}
}
/*****************************************************************************/
/************************** Write selector of centre *************************/
/*****************************************************************************/
2015-07-25 20:20:07 +02:00
void Ctr_WriteSelectorOfCentre (void)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_Centre;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCtrs;
unsigned NumCtr;
long CtrCod;
/***** Start form *****/
2018-11-09 20:47:39 +01:00
Frm_StartFormGoTo (ActSeeDeg);
2016-12-20 10:03:00 +01:00
fprintf (Gbl.F.Out,"<select id=\"ctr\" name=\"ctr\" style=\"width:175px;\"");
2014-12-01 23:55:08 +01:00
if (Gbl.CurrentIns.Ins.InsCod > 0)
2015-10-22 14:49:48 +02:00
fprintf (Gbl.F.Out," onchange=\"document.getElementById('%s').submit();\"",
2016-01-14 10:31:09 +01:00
Gbl.Form.Id);
2014-12-01 23:55:08 +01:00
else
fprintf (Gbl.F.Out," disabled=\"disabled\"");
fprintf (Gbl.F.Out,"><option value=\"\"");
if (Gbl.CurrentCtr.Ctr.CtrCod < 0)
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out," disabled=\"disabled\">[%s]</option>",
Txt_Centre);
if (Gbl.CurrentIns.Ins.InsCod > 0)
{
/***** Get centres from database *****/
2018-10-30 13:59:37 +01:00
NumCtrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get centres",
"SELECT DISTINCT CtrCod,ShortName"
" FROM centres"
" WHERE InsCod=%ld"
" ORDER BY ShortName",
Gbl.CurrentIns.Ins.InsCod);
2014-12-01 23:55:08 +01:00
/***** Get centres *****/
for (NumCtr = 0;
NumCtr < NumCtrs;
NumCtr++)
{
/* Get next centre */
row = mysql_fetch_row (mysql_res);
/* Get centre code (row[0]) */
if ((CtrCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of centre.");
/* Write option */
fprintf (Gbl.F.Out,"<option value=\"%ld\"",CtrCod);
if (Gbl.CurrentCtr.Ctr.CtrCod > 0 &&
CtrCod == Gbl.CurrentCtr.Ctr.CtrCod)
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%s</option>",row[1]);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/***** End form *****/
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</select>");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************************** List all the centres ****************************/
/*****************************************************************************/
static void Ctr_ListCentresForEdition (void)
{
extern const char *Txt_Another_place;
extern const char *Txt_CENTRE_STATUS[Ctr_NUM_STATUS_TXT];
unsigned NumCtr;
struct Centre *Ctr;
unsigned NumPlc;
2017-03-07 01:56:41 +01:00
char WWW[Cns_MAX_BYTES_WWW + 1];
2014-12-01 23:55:08 +01:00
struct UsrData UsrDat;
bool ICanEdit;
Ctr_StatusTxt_t StatusTxt;
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** Write heading *****/
2017-06-11 20:09:59 +02:00
Tbl_StartTableWide (2);
2014-12-01 23:55:08 +01:00
Ctr_PutHeadCentresForEdition ();
/***** Write all the centres *****/
for (NumCtr = 0;
NumCtr < Gbl.Ctrs.Num;
NumCtr++)
{
Ctr = &Gbl.Ctrs.Lst[NumCtr];
2016-11-06 23:46:29 +01:00
ICanEdit = Ctr_CheckIfICanEditACentre (Ctr);
2014-12-01 23:55:08 +01:00
/* Put icon to remove centre */
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"BM\">");
2016-10-20 00:57:00 +02:00
if (Ctr->Degs.Num ||
2015-12-09 22:05:21 +01:00
Ctr->NumUsrsWhoClaimToBelongToCtr ||
Ctr->NumUsrs || // Centre has degrees or users ==> deletion forbidden
2014-12-01 23:55:08 +01:00
!ICanEdit)
2017-06-11 19:13:28 +02:00
Ico_PutIconRemovalNotAllowed ();
2014-12-01 23:55:08 +01:00
else
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRemCtr);
2014-12-01 23:55:08 +01:00
Ctr_PutParamOtherCtrCod (Ctr->CtrCod);
2017-06-11 19:13:28 +02:00
Ico_PutIconRemove ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
fprintf (Gbl.F.Out,"</td>");
/* Centre code */
2015-12-05 21:15:30 +01:00
fprintf (Gbl.F.Out,"<td class=\"DAT CODE\">"
"%ld"
2014-12-22 14:08:19 +01:00
"</td>",
2014-12-01 23:55:08 +01:00
Ctr->CtrCod);
2015-01-14 00:32:23 +01:00
/* Centre logo */
2015-07-28 10:15:44 +02:00
fprintf (Gbl.F.Out,"<td title=\"%s\" class=\"LEFT_MIDDLE\""
2015-09-28 18:28:29 +02:00
" style=\"width:25px;\">",
2014-12-01 23:55:08 +01:00
Ctr->FullName);
2016-10-28 10:03:37 +02:00
Log_DrawLogo (Sco_SCOPE_CTR,Ctr->CtrCod,Ctr->ShrtName,20,NULL,true);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>");
/* Place */
2015-07-28 10:15:44 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_MIDDLE\">");
2014-12-01 23:55:08 +01:00
if (ICanEdit)
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgCtrPlc);
2014-12-01 23:55:08 +01:00
Ctr_PutParamOtherCtrCod (Ctr->CtrCod);
2015-09-28 18:28:29 +02:00
fprintf (Gbl.F.Out,"<select name=\"PlcCod\" style=\"width:62px;\""
2015-10-22 14:49:48 +02:00
" onchange=\"document.getElementById('%s').submit();\">",
2016-01-14 10:31:09 +01:00
Gbl.Form.Id);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<option value=\"0\"");
if (Ctr->PlcCod == 0)
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%s</option>",Txt_Another_place);
for (NumPlc = 0;
NumPlc < Gbl.Plcs.Num;
NumPlc++)
fprintf (Gbl.F.Out,"<option value=\"%ld\"%s>%s</option>",
Gbl.Plcs.Lst[NumPlc].PlcCod,
(Gbl.Plcs.Lst[NumPlc].PlcCod == Ctr->PlcCod) ? " selected=\"selected\"" :
"",
2016-10-28 10:03:37 +02:00
Gbl.Plcs.Lst[NumPlc].ShrtName);
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</select>");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
else
for (NumPlc = 0;
NumPlc < Gbl.Plcs.Num;
NumPlc++)
if (Gbl.Plcs.Lst[NumPlc].PlcCod == Ctr->PlcCod)
2016-10-28 10:03:37 +02:00
fprintf (Gbl.F.Out,"%s",Gbl.Plcs.Lst[NumPlc].ShrtName);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>");
/* Centre short name */
2015-07-28 10:15:44 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_MIDDLE\">");
2014-12-01 23:55:08 +01:00
if (ICanEdit)
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRenCtrSho);
2014-12-01 23:55:08 +01:00
Ctr_PutParamOtherCtrCod (Ctr->CtrCod);
2015-10-22 14:49:48 +02:00
fprintf (Gbl.F.Out,"<input type=\"text\" name=\"ShortName\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_SHORT_NAME\""
2015-10-22 14:49:48 +02:00
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-08 14:12:33 +01:00
Hie_MAX_CHARS_SHRT_NAME,Ctr->ShrtName,Gbl.Form.Id);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
}
else
2016-10-28 10:03:37 +02:00
fprintf (Gbl.F.Out,"%s",Ctr->ShrtName);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>");
/* Centre full name */
2015-07-28 10:15:44 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_MIDDLE\">");
2014-12-01 23:55:08 +01:00
if (ICanEdit)
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRenCtrFul);
2014-12-01 23:55:08 +01:00
Ctr_PutParamOtherCtrCod (Ctr->CtrCod);
2015-10-22 14:49:48 +02:00
fprintf (Gbl.F.Out,"<input type=\"text\" name=\"FullName\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_FULL_NAME\""
2015-10-22 14:49:48 +02:00
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-08 14:12:33 +01:00
Hie_MAX_CHARS_FULL_NAME,Ctr->FullName,Gbl.Form.Id);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
}
else
fprintf (Gbl.F.Out,"%s",Ctr->FullName);
fprintf (Gbl.F.Out,"</td>");
/* Centre WWW */
2015-07-28 10:15:44 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_MIDDLE\">");
2014-12-01 23:55:08 +01:00
if (ICanEdit)
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgCtrWWW);
2014-12-01 23:55:08 +01:00
Ctr_PutParamOtherCtrCod (Ctr->CtrCod);
2016-11-20 14:32:15 +01:00
fprintf (Gbl.F.Out,"<input type=\"url\" name=\"WWW\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_WWW\""
2015-10-22 14:49:48 +02:00
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-07 01:56:41 +01:00
Cns_MAX_CHARS_WWW,Ctr->WWW,Gbl.Form.Id);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
else
{
2017-01-17 03:10:43 +01:00
Str_Copy (WWW,Ctr->WWW,
2017-03-07 01:56:41 +01:00
Cns_MAX_BYTES_WWW);
2017-03-04 01:27:54 +01:00
fprintf (Gbl.F.Out,"<div class=\"EXTERNAL_WWW_SHORT\">"
"<a href=\"%s\" target=\"_blank\""
2017-01-17 03:10:43 +01:00
" class=\"DAT\" title=\"%s\">"
"%s"
2017-03-04 01:27:54 +01:00
"</a>"
"</div>",
2014-12-01 23:55:08 +01:00
Ctr->WWW,Ctr->WWW,WWW);
}
fprintf (Gbl.F.Out,"</td>");
2015-12-14 16:44:14 +01:00
/* Number of users who claim to belong to this centre */
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE\">"
"%u"
"</td>",
Ctr->NumUsrsWhoClaimToBelongToCtr);
/* Number of degrees */
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE\">"
"%u"
"</td>",
2016-10-20 00:57:00 +02:00
Ctr->Degs.Num);
2015-12-14 16:44:14 +01:00
/* Number of users in courses of this centre */
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE\">"
"%u"
"</td>",
Ctr->NumUsrs);
2017-03-17 00:46:28 +01:00
/* Centre requester */
UsrDat.UsrCod = Ctr->RequesterUsrCod;
2019-03-19 13:22:14 +01:00
Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS);
2017-05-02 01:05:23 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT INPUT_REQUESTER LEFT_TOP\">");
2017-05-02 01:16:06 +02:00
Msg_WriteMsgAuthor (&UsrDat,true,NULL);
2017-05-01 21:17:38 +02:00
fprintf (Gbl.F.Out,"</td>");
2017-03-17 00:46:28 +01:00
2014-12-01 23:55:08 +01:00
/* Centre status */
StatusTxt = Ctr_GetStatusTxtFromStatusBits (Ctr->Status);
2017-03-17 00:46:28 +01:00
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_MIDDLE\">");
2017-06-04 18:18:54 +02:00
if (Gbl.Usrs.Me.Role.Logged >= Rol_INS_ADM &&
2014-12-01 23:55:08 +01:00
StatusTxt == Ctr_STATUS_PENDING)
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgCtrSta);
2014-12-01 23:55:08 +01:00
Ctr_PutParamOtherCtrCod (Ctr->CtrCod);
2015-12-05 21:15:30 +01:00
fprintf (Gbl.F.Out,"<select name=\"Status\" class=\"INPUT_STATUS\""
2015-10-22 14:49:48 +02:00
" onchange=\"document.getElementById('%s').submit();\">"
2014-12-01 23:55:08 +01:00
"<option value=\"%u\" selected=\"selected\">%s</option>"
"<option value=\"%u\">%s</option>"
2015-03-13 00:16:02 +01:00
"</select>",
2016-01-14 10:31:09 +01:00
Gbl.Form.Id,
2014-12-01 23:55:08 +01:00
(unsigned) Ctr_GetStatusBitsFromStatusTxt (Ctr_STATUS_PENDING),
Txt_CENTRE_STATUS[Ctr_STATUS_PENDING],
(unsigned) Ctr_GetStatusBitsFromStatusTxt (Ctr_STATUS_ACTIVE),
Txt_CENTRE_STATUS[Ctr_STATUS_ACTIVE]);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
2017-03-17 00:46:28 +01:00
else if (StatusTxt != Ctr_STATUS_ACTIVE) // If active ==> do not show anything
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"%s",Txt_CENTRE_STATUS[StatusTxt]);
2017-03-17 00:46:28 +01:00
fprintf (Gbl.F.Out,"</td>"
2014-12-01 23:55:08 +01:00
"</tr>");
}
/***** End table *****/
2017-06-11 20:09:59 +02:00
Tbl_EndTable ();
2014-12-01 23:55:08 +01:00
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}
/*****************************************************************************/
/************** Check if I can edit, remove, etc. a centre *******************/
/*****************************************************************************/
2016-11-06 23:46:29 +01:00
static bool Ctr_CheckIfICanEditACentre (struct Centre *Ctr)
2014-12-01 23:55:08 +01:00
{
2017-06-04 18:18:54 +02:00
return (bool) (Gbl.Usrs.Me.Role.Logged >= Rol_INS_ADM || // I am an institution administrator or higher
2017-03-09 21:11:06 +01:00
((Ctr->Status & Ctr_STATUS_BIT_PENDING) != 0 && // Centre is not yet activated
Gbl.Usrs.Me.UsrDat.UsrCod == Ctr->RequesterUsrCod)); // I am the requester
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Set StatusTxt depending on status bits ******************/
/*****************************************************************************/
// Ctr_STATUS_UNKNOWN = 0 // Other
// Ctr_STATUS_ACTIVE = 1 // 00 (Status == 0)
// Ctr_STATUS_PENDING = 2 // 01 (Status == Ctr_STATUS_BIT_PENDING)
// Ctr_STATUS_REMOVED = 3 // 1- (Status & Ctr_STATUS_BIT_REMOVED)
static Ctr_StatusTxt_t Ctr_GetStatusTxtFromStatusBits (Ctr_Status_t Status)
{
if (Status == 0)
return Ctr_STATUS_ACTIVE;
if (Status == Ctr_STATUS_BIT_PENDING)
return Ctr_STATUS_PENDING;
if (Status & Ctr_STATUS_BIT_REMOVED)
return Ctr_STATUS_REMOVED;
return Ctr_STATUS_UNKNOWN;
}
/*****************************************************************************/
/******************* Set status bits depending on StatusTxt ******************/
/*****************************************************************************/
// Ctr_STATUS_UNKNOWN = 0 // Other
// Ctr_STATUS_ACTIVE = 1 // 00 (Status == 0)
// Ctr_STATUS_PENDING = 2 // 01 (Status == Ctr_STATUS_BIT_PENDING)
// Ctr_STATUS_REMOVED = 3 // 1- (Status & Ctr_STATUS_BIT_REMOVED)
static Ctr_Status_t Ctr_GetStatusBitsFromStatusTxt (Ctr_StatusTxt_t StatusTxt)
{
switch (StatusTxt)
{
case Ctr_STATUS_UNKNOWN:
case Ctr_STATUS_ACTIVE:
return (Ctr_Status_t) 0;
case Ctr_STATUS_PENDING:
return Ctr_STATUS_BIT_PENDING;
case Ctr_STATUS_REMOVED:
return Ctr_STATUS_BIT_REMOVED;
}
return (Ctr_Status_t) 0;
}
/*****************************************************************************/
/******************** Write parameter with code of centre ********************/
/*****************************************************************************/
void Ctr_PutParamCtrCod (long CtrCod)
{
2015-03-07 21:08:44 +01:00
Par_PutHiddenParamLong ("ctr",CtrCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************** Write parameter with code of other centre *****************/
/*****************************************************************************/
static void Ctr_PutParamOtherCtrCod (long CtrCod)
{
Par_PutHiddenParamLong ("OthCtrCod",CtrCod);
}
/*****************************************************************************/
/****************** Get parameter with code of other centre ******************/
/*****************************************************************************/
2017-05-31 21:05:59 +02:00
long Ctr_GetAndCheckParamOtherCtrCod (long MinCodAllowed)
2014-12-01 23:55:08 +01:00
{
2016-10-23 18:50:21 +02:00
long CtrCod;
2014-12-01 23:55:08 +01:00
2016-10-23 19:40:14 +02:00
/***** Get and check parameter with code of centre *****/
2017-05-31 21:05:59 +02:00
if ((CtrCod = Par_GetParToLong ("OthCtrCod")) < MinCodAllowed)
Lay_ShowErrorAndExit ("Code of centre is missing or invalid.");
2016-10-23 18:50:21 +02:00
return CtrCod;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************************* Remove a centre *****************************/
/*****************************************************************************/
void Ctr_RemoveCentre (void)
{
extern const char *Txt_To_remove_a_centre_you_must_first_remove_all_degrees_and_teachers_in_the_centre;
extern const char *Txt_Centre_X_removed;
struct Centre Ctr;
2017-01-28 15:58:46 +01:00
char PathCtr[PATH_MAX + 1];
2014-12-01 23:55:08 +01:00
/***** Get centre code *****/
2017-05-31 21:05:59 +02:00
Ctr.CtrCod = Ctr_GetAndCheckParamOtherCtrCod (1);
2014-12-01 23:55:08 +01:00
/***** Get data of the centre from database *****/
Ctr_GetDataOfCentreByCod (&Ctr);
/***** Check if this centre has teachers *****/
2016-10-20 00:57:00 +02:00
if (Ctr.Degs.Num ||
2015-12-14 12:13:41 +01:00
Ctr.NumUsrsWhoClaimToBelongToCtr ||
Ctr.NumUsrs) // Centre has degrees or users ==> don't remove
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_To_remove_a_centre_you_must_first_remove_all_degrees_and_teachers_in_the_centre);
2014-12-01 23:55:08 +01:00
else // Centre has no teachers ==> remove it
{
2016-10-28 00:23:02 +02:00
/***** Remove all the threads and posts in forums of the centre *****/
For_RemoveForums (Sco_SCOPE_CTR,Ctr.CtrCod);
/***** Remove surveys of the centre *****/
Svy_RemoveSurveys (Sco_SCOPE_CTR,Ctr.CtrCod);
2015-01-20 02:00:42 +01:00
/***** Remove information related to files in centre *****/
2015-01-25 18:50:43 +01:00
Brw_RemoveCtrFilesFromDB (Ctr.CtrCod);
2019-01-05 11:51:22 +01:00
/***** Remove all classrooms in centre *****/
Cla_RemoveAllClassroomsInCtr (Ctr.CtrCod);
2015-01-25 18:50:43 +01:00
/***** Remove directories of the centre *****/
2018-10-17 01:08:42 +02:00
snprintf (PathCtr,sizeof (PathCtr),
2019-03-20 01:36:36 +01:00
"%s/%02u/%u",
Cfg_PATH_CTR_PUBLIC,
2018-10-17 01:08:42 +02:00
(unsigned) (Ctr.CtrCod % 100),
(unsigned) Ctr.CtrCod);
2016-10-06 22:18:33 +02:00
Fil_RemoveTree (PathCtr);
2015-01-20 18:55:59 +01:00
2014-12-01 23:55:08 +01:00
/***** Remove centre *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove a centre",
"DELETE FROM centres WHERE CtrCod=%ld",
Ctr.CtrCod);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Centre_X_removed,
2019-02-16 00:03:58 +01:00
Ctr.FullName);
2014-12-01 23:55:08 +01:00
}
/***** Show the form again *****/
Ctr_EditCentres ();
}
/*****************************************************************************/
/********************* Change the institution of a centre ********************/
/*****************************************************************************/
2016-10-20 16:49:42 +02:00
void Ctr_ChangeCtrInsInConfig (void)
{
2016-10-20 19:46:06 +02:00
extern const char *Txt_The_centre_X_already_exists;
2016-10-20 16:49:42 +02:00
extern const char *Txt_The_centre_X_has_been_moved_to_the_institution_Y;
2016-10-28 10:03:37 +02:00
struct Instit NewIns;
2016-10-20 16:49:42 +02:00
2016-10-23 18:55:11 +02:00
/***** Get parameter with institution code *****/
2017-05-31 21:05:59 +02:00
NewIns.InsCod = Ins_GetAndCheckParamOtherInsCod (1);
2016-10-20 16:49:42 +02:00
2016-10-20 19:46:06 +02:00
/***** Check if institution has changed *****/
if (NewIns.InsCod != Gbl.CurrentCtr.Ctr.InsCod)
{
/***** Get data of new institution *****/
Ins_GetDataOfInstitutionByCod (&NewIns,Ins_GET_BASIC_DATA);
2016-10-20 16:49:42 +02:00
2016-10-20 19:46:06 +02:00
/***** Check if it already exists a centre with the same name in the new institution *****/
2017-03-09 21:11:06 +01:00
if (Ctr_CheckIfCtrNameExistsInIns ("ShortName",
Gbl.CurrentCtr.Ctr.ShrtName,
Gbl.CurrentCtr.Ctr.CtrCod,
NewIns.InsCod))
2019-03-09 20:12:44 +01:00
/***** Create warning message *****/
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_centre_X_already_exists,
Gbl.CurrentCtr.Ctr.ShrtName);
2017-03-09 21:11:06 +01:00
else if (Ctr_CheckIfCtrNameExistsInIns ("FullName",
Gbl.CurrentCtr.Ctr.FullName,
Gbl.CurrentCtr.Ctr.CtrCod,
NewIns.InsCod))
2019-03-09 20:12:44 +01:00
/***** Create warning message *****/
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_centre_X_already_exists,
Gbl.CurrentCtr.Ctr.FullName);
2016-10-20 19:46:06 +02:00
else
{
/***** Update institution in table of centres *****/
Ctr_UpdateCtrInsDB (Gbl.CurrentCtr.Ctr.CtrCod,NewIns.InsCod);
Gbl.CurrentCtr.Ctr.InsCod =
Gbl.CurrentIns.Ins.InsCod = NewIns.InsCod;
2016-10-20 16:49:42 +02:00
2016-10-20 19:46:06 +02:00
/***** Initialize again current course, degree, centre... *****/
2016-11-14 17:26:32 +01:00
Hie_InitHierarchy ();
2016-10-20 16:49:42 +02:00
2019-03-09 20:12:44 +01:00
/***** Create message to show the change made *****/
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_centre_X_has_been_moved_to_the_institution_Y,
Gbl.CurrentCtr.Ctr.FullName,NewIns.FullName);
2016-10-20 19:46:06 +02:00
}
}
2016-10-20 16:49:42 +02:00
}
/*****************************************************************************/
/** Show message of success after changing a centre in centre configuration **/
/*****************************************************************************/
void Ctr_ContEditAfterChgCtrInConfig (void)
{
/***** Write error/success message *****/
2019-03-09 20:12:44 +01:00
Ale_ShowAlerts (NULL);
2016-10-20 16:49:42 +02:00
/***** Show the form again *****/
Ctr_ShowConfiguration ();
}
/*****************************************************************************/
/******************* Update institution in table of centres ******************/
/*****************************************************************************/
static void Ctr_UpdateCtrInsDB (long CtrCod,long InsCod)
{
/***** Update institution in table of centres *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the institution of a centre",
"UPDATE centres SET InsCod=%ld WHERE CtrCod=%ld",
InsCod,CtrCod);
2016-10-20 16:49:42 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************ Change the place of a centre ***********************/
/*****************************************************************************/
2017-06-12 19:14:05 +02:00
void Ctr_ChangeCtrPlc (void)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_The_place_of_the_centre_has_changed;
2016-03-05 20:39:41 +01:00
long NewPlcCod;
2014-12-01 23:55:08 +01:00
2017-05-31 21:05:59 +02:00
/***** Get centre code *****/
Gbl.Ctrs.EditingCtr.CtrCod = Ctr_GetAndCheckParamOtherCtrCod (1);
2014-12-01 23:55:08 +01:00
2017-05-31 21:05:59 +02:00
/***** Get parameter with place code *****/
2016-03-05 20:39:41 +01:00
NewPlcCod = Plc_GetParamPlcCod ();
/***** Get data of centre from database *****/
2017-05-11 20:55:04 +02:00
Ctr_GetDataOfCentreByCod (&Gbl.Ctrs.EditingCtr);
2014-12-01 23:55:08 +01:00
/***** Update place in table of centres *****/
2017-06-12 19:14:05 +02:00
Ctr_UpdateCtrPlcDB (Gbl.Ctrs.EditingCtr.CtrCod,NewPlcCod);
2017-05-11 20:55:04 +02:00
Gbl.Ctrs.EditingCtr.PlcCod = NewPlcCod;
2014-12-01 23:55:08 +01:00
2019-03-09 20:12:44 +01:00
/***** Create alert to show the change made
2017-05-31 21:05:59 +02:00
and put button to go to centre changed *****/
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_place_of_the_centre_has_changed);
2017-05-11 20:55:04 +02:00
Ctr_ShowAlertAndButtonToGoToCtr ();
2016-03-01 19:23:02 +01:00
2014-12-01 23:55:08 +01:00
/***** Show the form again *****/
Ctr_EditCentres ();
}
2017-06-12 19:14:05 +02:00
void Ctr_ChangeCtrPlcInConfig (void)
{
extern const char *Txt_The_place_of_the_centre_has_changed;
long NewPlcCod;
/***** Get parameter with place code *****/
NewPlcCod = Plc_GetParamPlcCod ();
/***** Update place in table of centres *****/
Ctr_UpdateCtrPlcDB (Gbl.CurrentCtr.Ctr.CtrCod,NewPlcCod);
Gbl.CurrentCtr.Ctr.PlcCod = NewPlcCod;
/***** Write message to show the change made *****/
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_The_place_of_the_centre_has_changed);
2017-06-12 19:14:05 +02:00
/***** Show the form again *****/
Ctr_ShowConfiguration ();
}
/*****************************************************************************/
/************** Update database changing old place by new place **************/
/*****************************************************************************/
static void Ctr_UpdateCtrPlcDB (long CtrCod,long NewPlcCod)
{
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the place of a centre",
"UPDATE centres SET PlcCod=%ld WHERE CtrCod=%ld",
NewPlcCod,CtrCod);
2017-06-12 19:14:05 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************* Change the short name of a centre *********************/
/*****************************************************************************/
void Ctr_RenameCentreShort (void)
{
2017-05-31 21:05:59 +02:00
Gbl.Ctrs.EditingCtr.CtrCod = Ctr_GetAndCheckParamOtherCtrCod (1);
2016-10-28 10:03:37 +02:00
Ctr_RenameCentre (&Gbl.Ctrs.EditingCtr,Cns_SHRT_NAME);
2014-12-01 23:55:08 +01:00
}
2016-10-23 12:07:16 +02:00
void Ctr_RenameCentreShortInConfig (void)
{
2016-10-28 10:03:37 +02:00
Ctr_RenameCentre (&Gbl.CurrentCtr.Ctr,Cns_SHRT_NAME);
2016-10-23 12:07:16 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************* Change the full name of a centre **********************/
/*****************************************************************************/
void Ctr_RenameCentreFull (void)
{
2017-05-31 21:05:59 +02:00
Gbl.Ctrs.EditingCtr.CtrCod = Ctr_GetAndCheckParamOtherCtrCod (1);
2016-10-22 22:39:53 +02:00
Ctr_RenameCentre (&Gbl.Ctrs.EditingCtr,Cns_FULL_NAME);
}
2016-03-01 19:23:02 +01:00
2016-10-22 22:39:53 +02:00
void Ctr_RenameCentreFullInConfig (void)
{
Ctr_RenameCentre (&Gbl.CurrentCtr.Ctr,Cns_FULL_NAME);
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-03-01 23:58:48 +01:00
/************************ Change the name of a centre ************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-10-28 10:03:37 +02:00
static void Ctr_RenameCentre (struct Centre *Ctr,Cns_ShrtOrFullName_t ShrtOrFullName)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_You_can_not_leave_the_name_of_the_centre_X_empty;
extern const char *Txt_The_centre_X_already_exists;
extern const char *Txt_The_centre_X_has_been_renamed_as_Y;
extern const char *Txt_The_name_of_the_centre_X_has_not_changed;
const char *ParamName = NULL; // Initialized to avoid warning
const char *FieldName = NULL; // Initialized to avoid warning
2017-03-09 11:16:17 +01:00
unsigned MaxBytes = 0; // Initialized to avoid warning
2014-12-01 23:55:08 +01:00
char *CurrentCtrName = NULL; // Initialized to avoid warning
2017-03-08 14:12:33 +01:00
char NewCtrName[Hie_MAX_BYTES_FULL_NAME + 1];
2014-12-01 23:55:08 +01:00
2016-10-28 10:03:37 +02:00
switch (ShrtOrFullName)
2014-12-01 23:55:08 +01:00
{
2016-10-28 10:03:37 +02:00
case Cns_SHRT_NAME:
2014-12-01 23:55:08 +01:00
ParamName = "ShortName";
FieldName = "ShortName";
2017-03-09 11:16:17 +01:00
MaxBytes = Hie_MAX_BYTES_SHRT_NAME;
2016-10-28 10:03:37 +02:00
CurrentCtrName = Ctr->ShrtName;
2014-12-01 23:55:08 +01:00
break;
case Cns_FULL_NAME:
ParamName = "FullName";
FieldName = "FullName";
2017-03-09 11:16:17 +01:00
MaxBytes = Hie_MAX_BYTES_FULL_NAME;
2014-12-01 23:55:08 +01:00
CurrentCtrName = Ctr->FullName;
break;
}
/***** Get parameters from form *****/
/* Get the new name for the centre */
2017-03-09 11:16:17 +01:00
Par_GetParToText (ParamName,NewCtrName,MaxBytes);
2014-12-01 23:55:08 +01:00
/***** Get from the database the old names of the centre *****/
Ctr_GetDataOfCentreByCod (Ctr);
/***** Check if new name is empty *****/
if (!NewCtrName[0])
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_You_can_not_leave_the_name_of_the_centre_X_empty,
CurrentCtrName);
2014-12-01 23:55:08 +01:00
else
{
2019-01-02 15:10:51 +01:00
/***** Check if old and new names are the same
(this happens when return is pressed without changes) *****/
2014-12-01 23:55:08 +01:00
if (strcmp (CurrentCtrName,NewCtrName)) // Different names
{
/***** If degree was in database... *****/
2016-10-20 19:46:06 +02:00
if (Ctr_CheckIfCtrNameExistsInIns (ParamName,NewCtrName,Ctr->CtrCod,Gbl.CurrentIns.Ins.InsCod))
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_centre_X_already_exists,
NewCtrName);
2014-12-01 23:55:08 +01:00
else
{
/* Update the table changing old name by new name */
2017-03-09 11:16:17 +01:00
Ctr_UpdateInsNameDB (Ctr->CtrCod,FieldName,NewCtrName);
2014-12-01 23:55:08 +01:00
2016-03-01 19:23:02 +01:00
/* Write message to show the change made */
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_centre_X_has_been_renamed_as_Y,
CurrentCtrName,NewCtrName);
2016-03-01 19:23:02 +01:00
2016-03-01 23:58:48 +01:00
/* Change current centre name in order to display it properly */
2017-01-17 03:10:43 +01:00
Str_Copy (CurrentCtrName,NewCtrName,
2017-03-09 11:16:17 +01:00
MaxBytes);
2014-12-01 23:55:08 +01:00
}
}
else // The same name
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_INFO,NULL,
Txt_The_name_of_the_centre_X_has_not_changed,
CurrentCtrName);
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/********************* Check if the name of centre exists ********************/
/*****************************************************************************/
2016-10-20 19:46:06 +02:00
static bool Ctr_CheckIfCtrNameExistsInIns (const char *FieldName,const char *Name,long CtrCod,long InsCod)
2014-12-01 23:55:08 +01:00
{
/***** Get number of centres with a name from database *****/
2018-11-03 13:13:11 +01:00
return (DB_QueryCOUNT ("can not check if the name of a centre"
" already existed",
"SELECT COUNT(*) FROM centres"
" WHERE InsCod=%ld AND %s='%s' AND CtrCod<>%ld",
InsCod,FieldName,Name,CtrCod) != 0);
2014-12-01 23:55:08 +01:00
}
2017-03-09 11:16:17 +01:00
/*****************************************************************************/
/****************** Update centre name in table of centres *******************/
/*****************************************************************************/
static void Ctr_UpdateInsNameDB (long CtrCod,const char *FieldName,const char *NewCtrName)
{
/***** Update centre changing old name by new name */
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the name of a centre",
"UPDATE centres SET %s='%s' WHERE CtrCod=%ld",
FieldName,NewCtrName,CtrCod);
2017-03-09 11:16:17 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************* Change the URL of a centre ************************/
/*****************************************************************************/
void Ctr_ChangeCtrWWW (void)
{
extern const char *Txt_The_new_web_address_is_X;
extern const char *Txt_You_can_not_leave_the_web_address_empty;
2017-03-07 01:56:41 +01:00
char NewWWW[Cns_MAX_BYTES_WWW + 1];
2014-12-01 23:55:08 +01:00
2017-05-31 21:05:59 +02:00
/***** Get the code of the centre *****/
Gbl.Ctrs.EditingCtr.CtrCod = Ctr_GetAndCheckParamOtherCtrCod (1);
2014-12-01 23:55:08 +01:00
2017-05-31 21:05:59 +02:00
/***** Get the new WWW for the centre *****/
2017-03-07 01:56:41 +01:00
Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
2016-03-01 23:58:48 +01:00
/***** Get data of centre *****/
2017-05-11 20:55:04 +02:00
Ctr_GetDataOfCentreByCod (&Gbl.Ctrs.EditingCtr);
2016-03-01 23:58:48 +01:00
2014-12-01 23:55:08 +01:00
/***** Check if new WWW is empty *****/
if (NewWWW[0])
{
2016-10-23 14:49:03 +02:00
/***** Update database changing old WWW by new WWW *****/
2017-05-11 20:55:04 +02:00
Ctr_UpdateCtrWWWDB (Gbl.Ctrs.EditingCtr.CtrCod,NewWWW);
Str_Copy (Gbl.Ctrs.EditingCtr.WWW,NewWWW,
2017-05-31 21:05:59 +02:00
Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
2017-05-11 20:55:04 +02:00
/***** Write message to show the change made
and put button to go to centre changed *****/
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_new_web_address_is_X,
NewWWW);
2017-05-11 20:55:04 +02:00
Ctr_ShowAlertAndButtonToGoToCtr ();
2014-12-01 23:55:08 +01:00
}
else
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_can_not_leave_the_web_address_empty);
2016-10-23 14:49:03 +02:00
/***** Show the form again *****/
Ctr_EditCentres ();
}
void Ctr_ChangeCtrWWWInConfig (void)
{
extern const char *Txt_The_new_web_address_is_X;
extern const char *Txt_You_can_not_leave_the_web_address_empty;
2017-03-07 01:56:41 +01:00
char NewWWW[Cns_MAX_BYTES_WWW + 1];
2016-10-23 14:49:03 +02:00
/***** Get parameters from form *****/
/* Get the new WWW for the centre */
2017-03-07 01:56:41 +01:00
Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW);
2016-10-23 14:49:03 +02:00
/***** Check if new WWW is empty *****/
if (NewWWW[0])
2014-12-01 23:55:08 +01:00
{
2016-10-23 14:49:03 +02:00
/***** Update database changing old WWW by new WWW *****/
Ctr_UpdateCtrWWWDB (Gbl.CurrentCtr.Ctr.CtrCod,NewWWW);
2017-01-17 03:10:43 +01:00
Str_Copy (Gbl.CurrentCtr.Ctr.WWW,NewWWW,
2017-03-07 01:56:41 +01:00
Cns_MAX_BYTES_WWW);
2016-10-23 14:49:03 +02:00
/***** Write message to show the change made *****/
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_The_new_web_address_is_X,
2019-02-16 00:03:58 +01:00
NewWWW);
2014-12-01 23:55:08 +01:00
}
2016-10-23 14:49:03 +02:00
else
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_can_not_leave_the_web_address_empty);
2014-12-01 23:55:08 +01:00
/***** Show the form again *****/
2016-10-23 14:49:03 +02:00
Ctr_ShowConfiguration ();
}
/*****************************************************************************/
/**************** Update database changing old WWW by new WWW ****************/
/*****************************************************************************/
2017-01-28 15:58:46 +01:00
static void Ctr_UpdateCtrWWWDB (long CtrCod,
2017-03-07 01:56:41 +01:00
const char NewWWW[Cns_MAX_BYTES_WWW + 1])
2016-10-23 14:49:03 +02:00
{
/***** Update database changing old WWW by new WWW *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the web of a centre",
"UPDATE centres SET WWW='%s' WHERE CtrCod=%ld",
NewWWW,CtrCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********************** Change the status of a centre ***********************/
/*****************************************************************************/
void Ctr_ChangeCtrStatus (void)
{
extern const char *Txt_The_status_of_the_centre_X_has_changed;
Ctr_Status_t Status;
Ctr_StatusTxt_t StatusTxt;
2017-05-31 21:05:59 +02:00
/***** Get centre code *****/
Gbl.Ctrs.EditingCtr.CtrCod = Ctr_GetAndCheckParamOtherCtrCod (1);
2014-12-01 23:55:08 +01:00
2017-05-31 21:05:59 +02:00
/***** Get parameter with status *****/
2017-01-29 21:41:08 +01:00
Status = (Ctr_Status_t)
Par_GetParToUnsignedLong ("Status",
2017-05-31 21:05:59 +02:00
0,
(unsigned long) Ctr_MAX_STATUS,
(unsigned long) Ctr_WRONG_STATUS);
2017-01-29 12:42:19 +01:00
if (Status == Ctr_WRONG_STATUS)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Wrong status.");
StatusTxt = Ctr_GetStatusTxtFromStatusBits (Status);
Status = Ctr_GetStatusBitsFromStatusTxt (StatusTxt); // New status
/***** Get data of centre *****/
2017-05-11 20:55:04 +02:00
Ctr_GetDataOfCentreByCod (&Gbl.Ctrs.EditingCtr);
2014-12-01 23:55:08 +01:00
/***** Update status in table of centres *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the status of a centre",
"UPDATE centres SET Status=%u WHERE CtrCod=%ld",
(unsigned) Status,Gbl.Ctrs.EditingCtr.CtrCod);
2017-05-11 20:55:04 +02:00
Gbl.Ctrs.EditingCtr.Status = Status;
2014-12-01 23:55:08 +01:00
2017-05-11 20:55:04 +02:00
/***** Write message to show the change made
and put button to go to centre changed *****/
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_status_of_the_centre_X_has_changed,
Gbl.Ctrs.EditingCtr.ShrtName);
2017-05-11 20:55:04 +02:00
Ctr_ShowAlertAndButtonToGoToCtr ();
2016-03-01 19:23:02 +01:00
2014-12-01 23:55:08 +01:00
/***** Show the form again *****/
Ctr_EditCentres ();
}
2016-03-01 19:23:02 +01:00
/*****************************************************************************/
/************* Show message of success after changing a centre ***************/
/*****************************************************************************/
void Ctr_ContEditAfterChgCtr (void)
{
2017-05-11 20:55:04 +02:00
/***** Write message to show the change made
and put button to go to centre changed *****/
Ctr_ShowAlertAndButtonToGoToCtr ();
2016-03-01 19:23:02 +01:00
/***** Show the form again *****/
Ctr_EditCentres ();
}
/*****************************************************************************/
2017-05-11 20:55:04 +02:00
/***************** Write message to show the change made ********************/
/***************** and put button to go to centre changed ********************/
2016-03-01 19:23:02 +01:00
/*****************************************************************************/
2017-05-11 20:55:04 +02:00
// Gbl.Ctrs.EditingCtr is the centre that is beeing edited
// Gbl.CurrentCtr.Ctr is the current centre
2016-03-01 19:23:02 +01:00
2017-05-11 20:55:04 +02:00
static void Ctr_ShowAlertAndButtonToGoToCtr (void)
2016-03-01 19:23:02 +01:00
{
extern const char *Txt_Go_to_X;
2017-05-11 20:55:04 +02:00
// If the centre being edited is different to the current one...
if (Gbl.Ctrs.EditingCtr.CtrCod != Gbl.CurrentCtr.Ctr.CtrCod)
2016-03-01 23:58:48 +01:00
{
2017-05-11 21:53:37 +02:00
/***** Alert with button to go to centre *****/
2018-10-17 01:08:42 +02:00
snprintf (Gbl.Title,sizeof (Gbl.Title),
Txt_Go_to_X,
Gbl.Ctrs.EditingCtr.ShrtName);
2019-03-09 20:12:44 +01:00
Ale_ShowLastAlertAndButton (ActSeeDeg,NULL,NULL,Ctr_PutParamGoToCtr,
Btn_CONFIRM_BUTTON,Gbl.Title);
2016-03-01 23:58:48 +01:00
}
2017-05-11 20:55:04 +02:00
else
2017-05-11 21:53:37 +02:00
/***** Alert *****/
2019-03-09 20:12:44 +01:00
Ale_ShowAlerts (NULL);
2017-05-11 20:55:04 +02:00
}
static void Ctr_PutParamGoToCtr (void)
{
Ctr_PutParamCtrCod (Gbl.Ctrs.EditingCtr.CtrCod);
2016-03-01 19:23:02 +01:00
}
2015-01-14 00:32:23 +01:00
/*****************************************************************************/
/*********** Show a form for sending a logo of the current centre ************/
/*****************************************************************************/
void Ctr_RequestLogo (void)
{
2015-02-01 20:17:24 +01:00
Log_RequestLogo (Sco_SCOPE_CTR);
2015-01-14 00:32:23 +01:00
}
/*****************************************************************************/
2015-01-17 13:31:25 +01:00
/***************** Receive the logo of the current centre ********************/
2015-01-14 00:32:23 +01:00
/*****************************************************************************/
void Ctr_ReceiveLogo (void)
{
2015-02-01 20:17:24 +01:00
Log_ReceiveLogo (Sco_SCOPE_CTR);
2015-01-14 00:32:23 +01:00
}
2015-02-03 18:43:55 +01:00
/*****************************************************************************/
/****************** Remove the logo of the current centre ********************/
/*****************************************************************************/
void Ctr_RemoveLogo (void)
{
Log_RemoveLogo (Sco_SCOPE_CTR);
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/*********** Show a form for sending a photo of the current centre ***********/
/*****************************************************************************/
2015-01-14 00:32:23 +01:00
void Ctr_RequestPhoto (void)
2014-12-01 23:55:08 +01:00
{
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormInBox[The_NUM_THEMES];
2015-04-12 01:40:51 +02:00
extern const char *Txt_Photo;
2016-03-28 19:30:37 +02:00
extern const char *Txt_Recommended_aspect_ratio;
extern const char *Txt_Recommended_resolution;
extern const char *Txt_XxY_pixels_or_higher;
2014-12-01 23:55:08 +01:00
extern const char *Txt_File_with_the_photo;
2015-04-12 01:40:51 +02:00
/***** Start form to upload photo *****/
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRecCtrPho);
2015-04-12 01:40:51 +02:00
2017-06-12 14:16:33 +02:00
/***** Start box *****/
2017-06-10 21:38:10 +02:00
Box_StartBox (NULL,Txt_Photo,NULL,
2017-06-12 15:03:29 +02:00
NULL,Box_NOT_CLOSABLE);
2015-04-12 01:40:51 +02:00
2014-12-01 23:55:08 +01:00
/***** Write help message *****/
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_INFO,"%s: %s<br />"
2019-02-16 00:03:58 +01:00
"%s: %u&times;%u %s",
Txt_Recommended_aspect_ratio,
Ctr_RECOMMENDED_ASPECT_RATIO,
Txt_Recommended_resolution,
Ctr_PHOTO_SAVED_MAX_WIDTH,
Ctr_PHOTO_SAVED_MAX_HEIGHT,
Txt_XxY_pixels_or_higher);
2014-12-01 23:55:08 +01:00
2015-04-12 01:40:51 +02:00
/***** Upload photo *****/
fprintf (Gbl.F.Out,"<label class=\"%s\">"
2016-12-20 02:18:50 +01:00
"%s:&nbsp;"
2016-04-11 15:32:59 +02:00
"<input type=\"file\" name=\"%s\" accept=\"image/*\""
2016-12-20 02:18:50 +01:00
" onchange=\"document.getElementById('%s').submit();\" />"
"</label>",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],
2014-12-01 23:55:08 +01:00
Txt_File_with_the_photo,
2016-03-29 00:47:35 +02:00
Fil_NAME_OF_PARAM_FILENAME_ORG,
Gbl.Form.Id);
2015-03-24 17:47:26 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2017-06-10 21:38:10 +02:00
Box_EndBox ();
2015-04-12 01:40:51 +02:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************** Receive a photo of the current centre ********************/
/*****************************************************************************/
void Ctr_ReceivePhoto (void)
{
2016-03-28 19:30:37 +02:00
extern const char *Txt_Wrong_file_type;
2017-01-28 15:58:46 +01:00
char Path[PATH_MAX + 1];
2016-04-01 01:59:27 +02:00
struct Param *Param;
2017-01-28 15:58:46 +01:00
char FileNameImgSrc[PATH_MAX + 1];
2016-03-28 19:30:37 +02:00
char *PtrExtension;
size_t LengthExtension;
2017-01-15 18:02:52 +01:00
char MIMEType[Brw_MAX_BYTES_MIME_TYPE + 1];
2019-03-04 10:10:46 +01:00
char PathFileImgTmp[PATH_MAX + 1]; // Full name (including path and .jpg) of the destination temporary file
char PathFileImg[PATH_MAX + 1]; // Full name (including path and .jpg) of the destination file
2014-12-01 23:55:08 +01:00
bool WrongType = false;
2017-01-28 15:58:46 +01:00
char Command[1024 + PATH_MAX * 2];
2016-03-28 19:30:37 +02:00
int ReturnCode;
2019-02-17 01:14:55 +01:00
char ErrorMsg[256];
2014-12-01 23:55:08 +01:00
2016-04-01 12:47:32 +02:00
/***** Copy in disk the file received *****/
2016-04-04 12:13:37 +02:00
Param = Fil_StartReceptionOfFile (Fil_NAME_OF_PARAM_FILENAME_ORG,
FileNameImgSrc,MIMEType);
2016-03-28 19:30:37 +02:00
/* Check if the file type is image/ or application/octet-stream */
if (strncmp (MIMEType,"image/",strlen ("image/")))
if (strcmp (MIMEType,"application/octet-stream"))
if (strcmp (MIMEType,"application/octetstream"))
if (strcmp (MIMEType,"application/octet"))
WrongType = true;
if (WrongType)
{
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_Wrong_file_type);
2016-03-28 19:30:37 +02:00
return;
}
2016-03-29 13:25:33 +02:00
/***** Create private directories if not exist *****/
/* Create private directory for images if it does not exist */
2019-03-20 01:36:36 +01:00
Fil_CreateDirIfNotExists (Cfg_PATH_MEDIA_PRIVATE);
2016-03-28 19:30:37 +02:00
2016-03-29 13:25:33 +02:00
/* Create temporary private directory for images if it does not exist */
2019-03-20 01:36:36 +01:00
Fil_CreateDirIfNotExists (Cfg_PATH_MEDIA_TMP_PRIVATE);
2016-03-28 19:30:37 +02:00
/* Get filename extension */
2016-03-29 13:25:33 +02:00
if ((PtrExtension = strrchr (FileNameImgSrc,(int) '.')) == NULL)
2016-03-28 19:30:37 +02:00
{
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_Wrong_file_type);
2016-03-28 19:30:37 +02:00
return;
}
LengthExtension = strlen (PtrExtension);
2017-03-07 11:03:05 +01:00
if (LengthExtension < Fil_MIN_BYTES_FILE_EXTENSION ||
LengthExtension > Fil_MAX_BYTES_FILE_EXTENSION)
2016-03-28 19:30:37 +02:00
{
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_Wrong_file_type);
2016-03-28 19:30:37 +02:00
return;
}
2016-03-29 13:25:33 +02:00
/* End the reception of image in a temporary file */
2019-03-04 10:10:46 +01:00
snprintf (PathFileImgTmp,sizeof (PathFileImgTmp),
"%s/%s.%s",
2019-03-20 01:36:36 +01:00
Cfg_PATH_MEDIA_TMP_PRIVATE,Gbl.UniqueNameEncrypted,PtrExtension);
2019-03-04 10:10:46 +01:00
if (!Fil_EndReceptionOfFile (PathFileImgTmp,Param))
2016-03-28 19:30:37 +02:00
{
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,"Error copying file.");
2016-03-28 19:30:37 +02:00
return;
}
/***** Creates public directories if not exist *****/
2019-03-20 01:36:36 +01:00
Fil_CreateDirIfNotExists (Cfg_PATH_CTR_PUBLIC);
2018-10-17 01:08:42 +02:00
snprintf (Path,sizeof (Path),
2019-03-20 01:36:36 +01:00
"%s/%02u",
Cfg_PATH_CTR_PUBLIC,
2018-10-17 01:08:42 +02:00
(unsigned) (Gbl.CurrentCtr.Ctr.CtrCod % 100));
2014-12-01 23:55:08 +01:00
Fil_CreateDirIfNotExists (Path);
2018-10-17 01:08:42 +02:00
snprintf (Path,sizeof (Path),
2019-03-20 01:36:36 +01:00
"%s/%02u/%u",
Cfg_PATH_CTR_PUBLIC,
2018-10-17 01:08:42 +02:00
(unsigned) (Gbl.CurrentCtr.Ctr.CtrCod % 100),
(unsigned) Gbl.CurrentCtr.Ctr.CtrCod);
2014-12-01 23:55:08 +01:00
Fil_CreateDirIfNotExists (Path);
2016-03-28 19:30:37 +02:00
/***** Convert temporary file to public JPEG file *****/
2019-03-04 10:10:46 +01:00
snprintf (PathFileImg,sizeof (PathFileImg),
2019-03-20 01:36:36 +01:00
"%s/%02u/%u/%u.jpg",
Cfg_PATH_CTR_PUBLIC,
2018-10-17 01:08:42 +02:00
(unsigned) (Gbl.CurrentCtr.Ctr.CtrCod % 100),
(unsigned) Gbl.CurrentCtr.Ctr.CtrCod,
(unsigned) Gbl.CurrentCtr.Ctr.CtrCod);
2016-03-28 19:30:37 +02:00
/* Call to program that makes the conversion */
2018-10-17 01:08:42 +02:00
snprintf (Command,sizeof (Command),
"convert %s -resize '%ux%u>' -quality %u %s",
2019-03-04 10:10:46 +01:00
PathFileImgTmp,
2018-10-17 01:08:42 +02:00
Ctr_PHOTO_SAVED_MAX_WIDTH,
Ctr_PHOTO_SAVED_MAX_HEIGHT,
Ctr_PHOTO_SAVED_QUALITY,
2019-03-04 10:10:46 +01:00
PathFileImg);
2016-03-28 19:30:37 +02:00
ReturnCode = system (Command);
if (ReturnCode == -1)
2016-03-29 13:25:33 +02:00
Lay_ShowErrorAndExit ("Error when running command to process image.");
2016-03-28 19:30:37 +02:00
/***** Write message depending on return code *****/
ReturnCode = WEXITSTATUS(ReturnCode);
if (ReturnCode != 0)
2014-12-01 23:55:08 +01:00
{
2019-02-17 01:14:55 +01:00
snprintf (ErrorMsg,sizeof (ErrorMsg),
2018-10-16 21:56:01 +02:00
"Image could not be processed successfully.<br />"
"Error code returned by the program of processing: %d",
ReturnCode);
2019-02-17 01:14:55 +01:00
Lay_ShowErrorAndExit (ErrorMsg);
2014-12-01 23:55:08 +01:00
}
2016-03-28 19:30:37 +02:00
/***** Remove temporary file *****/
2019-03-04 10:10:46 +01:00
unlink (PathFileImgTmp);
2016-03-28 19:30:37 +02:00
2014-12-01 23:55:08 +01:00
/***** Show the centre information again *****/
Ctr_ShowConfiguration ();
}
/*****************************************************************************/
/**************** Change the attribution of a centre photo *******************/
/*****************************************************************************/
void Ctr_ChangeCtrPhotoAttribution (void)
{
2019-03-02 21:49:11 +01:00
char NewPhotoAttribution[Med_MAX_BYTES_ATTRIBUTION + 1];
2014-12-01 23:55:08 +01:00
/***** Get parameters from form *****/
/* Get the new photo attribution for the centre */
2019-03-02 21:49:11 +01:00
Par_GetParToText ("Attribution",NewPhotoAttribution,Med_MAX_BYTES_ATTRIBUTION);
2014-12-01 23:55:08 +01:00
/***** Update the table changing old attribution by new attribution *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the photo attribution"
" of the current centre",
"UPDATE centres SET PhotoAttribution='%s'"
" WHERE CtrCod=%ld",
NewPhotoAttribution,Gbl.CurrentCtr.Ctr.CtrCod);
2014-12-01 23:55:08 +01:00
/***** Show the centre information again *****/
Ctr_ShowConfiguration ();
}
/*****************************************************************************/
/********************* Put a form to create a new centre *********************/
/*****************************************************************************/
static void Ctr_PutFormToCreateCentre (void)
{
2017-04-30 02:35:25 +02:00
extern const char *Txt_New_centre;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Another_place;
extern const char *Txt_Create_centre;
unsigned NumPlc;
/***** Start form *****/
2017-06-04 18:18:54 +02:00
if (Gbl.Usrs.Me.Role.Logged >= Rol_INS_ADM)
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActNewCtr);
2017-06-04 18:18:54 +02:00
else if (Gbl.Usrs.Me.Role.Max >= Rol_GST)
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActReqCtr);
2014-12-01 23:55:08 +01:00
else
Lay_ShowErrorAndExit ("You can not edit centres.");
2017-06-12 14:16:33 +02:00
/***** Start box and table *****/
2017-06-10 21:38:10 +02:00
Box_StartBoxTable (NULL,Txt_New_centre,NULL,
2017-06-12 15:03:29 +02:00
NULL,Box_NOT_CLOSABLE,2);
2014-12-01 23:55:08 +01:00
2017-04-30 02:35:25 +02:00
/***** Write heading *****/
2014-12-01 23:55:08 +01:00
Ctr_PutHeadCentresForEdition ();
2017-04-30 02:56:25 +02:00
/***** Column to remove centre, disabled here *****/
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<tr>"
2017-04-30 02:35:25 +02:00
"<td class=\"BM\"></td>");
2014-12-01 23:55:08 +01:00
/***** Centre code *****/
2015-12-05 21:15:30 +01:00
fprintf (Gbl.F.Out,"<td class=\"CODE\"></td>");
2014-12-01 23:55:08 +01:00
/***** Centre logo *****/
2015-09-28 18:28:29 +02:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE\" style=\"width:25px;\">");
2015-12-13 13:53:00 +01:00
Log_DrawLogo (Sco_SCOPE_CTR,-1L,"",20,NULL,true);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>");
/***** Place *****/
2015-07-28 10:15:44 +02:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE\">"
2015-09-28 18:28:29 +02:00
"<select name=\"PlcCod\" style=\"width:62px;\">"
2014-12-01 23:55:08 +01:00
"<option value=\"0\"");
2017-05-11 20:55:04 +02:00
if (Gbl.Ctrs.EditingCtr.PlcCod == 0)
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%s</option>",Txt_Another_place);
for (NumPlc = 0;
NumPlc < Gbl.Plcs.Num;
NumPlc++)
fprintf (Gbl.F.Out,"<option value=\"%ld\"%s>%s</option>",
Gbl.Plcs.Lst[NumPlc].PlcCod,
2017-05-11 20:55:04 +02:00
(Gbl.Plcs.Lst[NumPlc].PlcCod == Gbl.Ctrs.EditingCtr.PlcCod) ? " selected=\"selected\"" :
"",
2016-10-28 10:03:37 +02:00
Gbl.Plcs.Lst[NumPlc].ShrtName);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</select>"
"</td>");
/***** Centre short name *****/
2015-07-28 10:15:44 +02:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE\">"
2015-10-23 01:31:08 +02:00
"<input type=\"text\" name=\"ShortName\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
2016-11-19 02:47:22 +01:00
" class=\"INPUT_SHORT_NAME\""
" required=\"required\" />"
2014-12-01 23:55:08 +01:00
"</td>",
2017-05-11 20:55:04 +02:00
Hie_MAX_CHARS_SHRT_NAME,Gbl.Ctrs.EditingCtr.ShrtName);
2014-12-01 23:55:08 +01:00
/***** Centre full name *****/
2015-07-28 10:15:44 +02:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE\">"
2015-10-23 01:31:08 +02:00
"<input type=\"text\" name=\"FullName\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
2016-11-19 02:47:22 +01:00
" class=\"INPUT_FULL_NAME\""
" required=\"required\" />"
2014-12-01 23:55:08 +01:00
"</td>",
2017-05-11 20:55:04 +02:00
Hie_MAX_CHARS_FULL_NAME,Gbl.Ctrs.EditingCtr.FullName);
2014-12-01 23:55:08 +01:00
/***** Centre WWW *****/
2015-07-28 10:15:44 +02:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE\">"
2016-11-20 14:32:15 +01:00
"<input type=\"url\" name=\"WWW\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
2016-11-19 02:47:22 +01:00
" class=\"INPUT_WWW\""
" required=\"required\" />"
2014-12-01 23:55:08 +01:00
"</td>",
2017-05-11 20:55:04 +02:00
Cns_MAX_CHARS_WWW,Gbl.Ctrs.EditingCtr.WWW);
2014-12-01 23:55:08 +01:00
2015-12-14 16:44:14 +01:00
/***** Number of users who claim to belong to this centre *****/
2015-07-28 10:15:44 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE\">"
2014-12-22 14:08:19 +01:00
"0"
"</td>");
2014-12-01 23:55:08 +01:00
/***** Number of degrees *****/
2015-07-28 10:15:44 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE\">"
2014-12-22 14:08:19 +01:00
"0"
"</td>");
2014-12-01 23:55:08 +01:00
2015-12-14 16:44:14 +01:00
/***** Number of users in courses of this centre *****/
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE\">"
"0"
"</td>");
2014-12-01 23:55:08 +01:00
/***** Centre requester *****/
2017-05-02 01:05:23 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT INPUT_REQUESTER LEFT_TOP\">");
2017-05-02 01:16:06 +02:00
Msg_WriteMsgAuthor (&Gbl.Usrs.Me.UsrDat,true,NULL);
2017-05-01 21:17:38 +02:00
fprintf (Gbl.F.Out,"</td>");
2017-03-17 00:46:28 +01:00
/***** Centre status *****/
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_MIDDLE\">"
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>");
2017-06-12 14:16:33 +02:00
/***** End table, send button and end box *****/
2017-06-11 19:02:40 +02:00
Box_EndBoxTableWithButton (Btn_CREATE_BUTTON,Txt_Create_centre);
2014-12-01 23:55:08 +01:00
2017-03-26 14:57:47 +02:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Write header with fields of a degree *******************/
/*****************************************************************************/
static void Ctr_PutHeadCentresForSeeing (bool OrderSelectable)
{
extern const char *Txt_CENTRES_HELP_ORDER[2];
extern const char *Txt_CENTRES_ORDER[2];
2015-12-09 22:05:21 +01:00
extern const char *Txt_Place;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Degrees_ABBREVIATION;
2015-12-09 22:05:21 +01:00
extern const char *Txt_Courses_ABBREVIATION;
2017-05-30 21:43:05 +02:00
extern const char *Txt_ROLES_PLURAL_BRIEF_Abc[Rol_NUM_ROLES];
2017-01-29 12:42:19 +01:00
Ctr_Order_t Order;
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<tr>"
2015-11-19 16:09:51 +01:00
"<th></th>");
2014-12-01 23:55:08 +01:00
for (Order = Ctr_ORDER_BY_CENTRE;
Order <= Ctr_ORDER_BY_NUM_TCHS;
Order++)
{
2015-12-09 22:05:21 +01:00
fprintf (Gbl.F.Out,"<th class=\"%s\">",
Order == Ctr_ORDER_BY_CENTRE ? "LEFT_MIDDLE" :
"RIGHT_MIDDLE");
2014-12-01 23:55:08 +01:00
if (OrderSelectable)
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActSeeCtr);
2014-12-01 23:55:08 +01:00
Par_PutHiddenParamUnsigned ("Order",(unsigned) Order);
2018-11-09 20:47:39 +01:00
Frm_LinkFormSubmit (Txt_CENTRES_HELP_ORDER[Order],"TIT_TBL",NULL);
2017-01-29 12:42:19 +01:00
if (Order == Gbl.Ctrs.SelectedOrder)
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<u>");
}
fprintf (Gbl.F.Out,"%s",Txt_CENTRES_ORDER[Order]);
if (OrderSelectable)
{
2017-01-29 12:42:19 +01:00
if (Order == Gbl.Ctrs.SelectedOrder)
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</u>");
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</a>");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
fprintf (Gbl.F.Out,"</th>");
}
2015-12-09 22:05:21 +01:00
fprintf (Gbl.F.Out,"<th class=\"LEFT_MIDDLE\">"
"%s"
"</th>"
"<th class=\"RIGHT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2016-02-02 19:35:35 +01:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2016-02-02 19:35:35 +01:00
"<th class=\"RIGHT_MIDDLE\">"
2015-12-09 22:05:21 +01:00
"%s+<br />%s"
"</th>"
"<th class=\"LEFT_MIDDLE\">"
"</th>"
"</tr>",
2015-11-19 16:09:51 +01:00
Txt_Place,
2015-12-09 22:05:21 +01:00
Txt_Degrees_ABBREVIATION,
Txt_Courses_ABBREVIATION,
2017-05-30 21:43:05 +02:00
Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH],
Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD]);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Write header with fields of a degree *******************/
/*****************************************************************************/
static void Ctr_PutHeadCentresForEdition (void)
{
extern const char *Txt_Code;
extern const char *Txt_Place;
2016-03-02 17:48:53 +01:00
extern const char *Txt_Short_name_of_the_centre;
extern const char *Txt_Full_name_of_the_centre;
2014-12-01 23:55:08 +01:00
extern const char *Txt_WWW;
2015-12-14 16:44:14 +01:00
extern const char *Txt_Users;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Degrees_ABBREVIATION;
2017-05-30 21:43:05 +02:00
extern const char *Txt_ROLES_PLURAL_BRIEF_Abc[Rol_NUM_ROLES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Requester;
fprintf (Gbl.F.Out,"<tr>"
2014-12-26 22:11:03 +01:00
"<th></th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-12-05 21:15:30 +01:00
"<th></th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-12-14 16:44:14 +01:00
"<th class=\"RIGHT_MIDDLE\">"
"%s+<br />%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"</th>"
2014-12-01 23:55:08 +01:00
"</tr>",
Txt_Code,
Txt_Place,
2016-03-02 17:48:53 +01:00
Txt_Short_name_of_the_centre,
Txt_Full_name_of_the_centre,
2014-12-01 23:55:08 +01:00
Txt_WWW,
2015-12-14 16:44:14 +01:00
Txt_Users,
2014-12-01 23:55:08 +01:00
Txt_Degrees_ABBREVIATION,
2017-05-30 21:43:05 +02:00
Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH],
Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD],
2014-12-01 23:55:08 +01:00
Txt_Requester);
}
/*****************************************************************************/
/****************** Receive form to request a new centre *********************/
/*****************************************************************************/
void Ctr_RecFormReqCtr (void)
{
Ctr_RecFormRequestOrCreateCtr ((unsigned) Ctr_STATUS_BIT_PENDING);
}
/*****************************************************************************/
/******************* Receive form to create a new centre *********************/
/*****************************************************************************/
void Ctr_RecFormNewCtr (void)
{
Ctr_RecFormRequestOrCreateCtr (0);
}
/*****************************************************************************/
/************* Receive form to request or create a new centre ****************/
/*****************************************************************************/
static void Ctr_RecFormRequestOrCreateCtr (unsigned Status)
{
extern const char *Txt_The_centre_X_already_exists;
extern const char *Txt_You_must_specify_the_web_address_of_the_new_centre;
extern const char *Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_centre;
/***** Get parameters from form *****/
/* Set centre institution */
2017-05-11 20:55:04 +02:00
Gbl.Ctrs.EditingCtr.InsCod = Gbl.CurrentIns.Ins.InsCod;
2014-12-01 23:55:08 +01:00
/* Get place */
2017-05-11 20:55:04 +02:00
if ((Gbl.Ctrs.EditingCtr.PlcCod = Plc_GetParamPlcCod ()) < 0) // 0 is reserved for "other place"
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_ERROR,"Wrong place.");
2014-12-01 23:55:08 +01:00
/* Get centre short name */
2017-05-11 20:55:04 +02:00
Par_GetParToText ("ShortName",Gbl.Ctrs.EditingCtr.ShrtName,Hie_MAX_BYTES_SHRT_NAME);
2014-12-01 23:55:08 +01:00
/* Get centre full name */
2017-05-11 20:55:04 +02:00
Par_GetParToText ("FullName",Gbl.Ctrs.EditingCtr.FullName,Hie_MAX_BYTES_FULL_NAME);
2014-12-01 23:55:08 +01:00
/* Get centre WWW */
2017-05-11 20:55:04 +02:00
Par_GetParToText ("WWW",Gbl.Ctrs.EditingCtr.WWW,Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
2017-05-11 20:55:04 +02:00
if (Gbl.Ctrs.EditingCtr.ShrtName[0] &&
Gbl.Ctrs.EditingCtr.FullName[0]) // If there's a centre name
2014-12-01 23:55:08 +01:00
{
2017-05-11 20:55:04 +02:00
if (Gbl.Ctrs.EditingCtr.WWW[0])
2014-12-01 23:55:08 +01:00
{
/***** If name of centre was in database... *****/
2017-05-11 20:55:04 +02:00
if (Ctr_CheckIfCtrNameExistsInIns ("ShortName",Gbl.Ctrs.EditingCtr.ShrtName,-1L,Gbl.CurrentIns.Ins.InsCod))
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_The_centre_X_already_exists,
2019-02-16 00:03:58 +01:00
Gbl.Ctrs.EditingCtr.ShrtName);
2017-05-11 20:55:04 +02:00
else if (Ctr_CheckIfCtrNameExistsInIns ("FullName",Gbl.Ctrs.EditingCtr.FullName,-1L,Gbl.CurrentIns.Ins.InsCod))
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_The_centre_X_already_exists,
2019-02-16 00:03:58 +01:00
Gbl.Ctrs.EditingCtr.FullName);
2014-12-01 23:55:08 +01:00
else // Add new centre to database
2017-05-11 20:55:04 +02:00
Ctr_CreateCentre (Status);
2014-12-01 23:55:08 +01:00
}
2015-01-14 00:32:23 +01:00
else // If there is not a web
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_specify_the_web_address_of_the_new_centre);
2014-12-01 23:55:08 +01:00
}
else // If there is not a centre name
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_centre);
2014-12-01 23:55:08 +01:00
/***** Show the form again *****/
Ctr_EditCentres ();
}
/*****************************************************************************/
/***************************** Create a new centre ***************************/
/*****************************************************************************/
2017-05-11 20:55:04 +02:00
// Gbl.Ctrs.EditingCtr must hold the centre beeing edited
2014-12-01 23:55:08 +01:00
2017-05-11 20:55:04 +02:00
static void Ctr_CreateCentre (unsigned Status)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_Created_new_centre_X;
/***** Create a new centre *****/
2018-11-03 01:45:36 +01:00
Gbl.Ctrs.EditingCtr.CtrCod =
DB_QueryINSERTandReturnCode ("can not create a new centre",
"INSERT INTO centres"
" (InsCod,PlcCod,Status,RequesterUsrCod,"
"ShortName,FullName,WWW,PhotoAttribution)"
" VALUES"
" (%ld,%ld,%u,%ld,"
"'%s','%s','%s','')",
Gbl.Ctrs.EditingCtr.InsCod,
Gbl.Ctrs.EditingCtr.PlcCod,
Status,
Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Ctrs.EditingCtr.ShrtName,
Gbl.Ctrs.EditingCtr.FullName,
Gbl.Ctrs.EditingCtr.WWW);
2017-05-11 20:55:04 +02:00
/***** Write message to show the change made
and put button to go to centre created *****/
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_Created_new_centre_X,
Gbl.Ctrs.EditingCtr.FullName);
2017-05-11 20:55:04 +02:00
Ctr_ShowAlertAndButtonToGoToCtr ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************** Get number of centres ****************************/
/*****************************************************************************/
unsigned Ctr_GetNumCtrsTotal (void)
{
/***** Get total number of centres from database *****/
2018-11-04 20:51:38 +01:00
return (unsigned) DB_GetNumRowsTable ("centres");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Get number of centres in a country **********************/
/*****************************************************************************/
unsigned Ctr_GetNumCtrsInCty (long CtyCod)
{
/***** Get number of centres of a country from database *****/
2018-11-03 13:13:11 +01:00
return
(unsigned) DB_QueryCOUNT ("can not get number of centres in a country",
"SELECT COUNT(*) FROM institutions,centres"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod",
CtyCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/**************** Get number of centres in an institution ********************/
/*****************************************************************************/
unsigned Ctr_GetNumCtrsInIns (long InsCod)
{
/***** Get number of centres of an institution from database *****/
2018-11-03 13:13:11 +01:00
return
(unsigned) DB_QueryCOUNT ("can not get number of centres in an institution",
"SELECT COUNT(*) FROM centres"
" WHERE InsCod=%ld",
InsCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2015-11-15 23:07:19 +01:00
/******* Get number of centres (of the current institution) in a place *******/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
unsigned Ctr_GetNumCtrsInPlc (long PlcCod)
{
2015-11-15 23:07:19 +01:00
/***** Get number of centres (of the current institution) in a place *****/
2018-11-03 13:13:11 +01:00
return
(unsigned) DB_QueryCOUNT ("can not get the number of centres in a place",
"SELECT COUNT(*) FROM centres"
" WHERE InsCod=%ld AND PlcCod=%ld",
Gbl.CurrentIns.Ins.InsCod,PlcCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Get number of centres with degrees ********************/
/*****************************************************************************/
unsigned Ctr_GetNumCtrsWithDegs (const char *SubQuery)
{
/***** Get number of centres with degrees from database *****/
2018-11-03 13:13:11 +01:00
return
(unsigned) DB_QueryCOUNT ("can not get number of centres with degrees",
"SELECT COUNT(DISTINCT centres.CtrCod)"
" FROM institutions,centres,degrees"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod",
SubQuery);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Get number of centres with courses ********************/
/*****************************************************************************/
unsigned Ctr_GetNumCtrsWithCrss (const char *SubQuery)
{
/***** Get number of centres with courses from database *****/
2018-11-03 13:13:11 +01:00
return
(unsigned) DB_QueryCOUNT ("can not get number of centres with courses",
"SELECT COUNT(DISTINCT centres.CtrCod)"
" FROM institutions,centres,degrees,courses"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod",
SubQuery);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Get number of centres with users **********************/
/*****************************************************************************/
unsigned Ctr_GetNumCtrsWithUsrs (Rol_Role_t Role,const char *SubQuery)
{
/***** Get number of centres with users from database *****/
2018-11-03 13:13:11 +01:00
return
(unsigned) DB_QueryCOUNT ("can not get number of centres with users",
"SELECT COUNT(DISTINCT centres.CtrCod)"
" FROM institutions,centres,degrees,courses,crs_usr"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u",
SubQuery,(unsigned) Role);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************************** List centres found ***************************/
/*****************************************************************************/
2018-10-30 13:59:37 +01:00
void Ctr_ListCtrsFound (MYSQL_RES **mysql_res,unsigned NumCtrs)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_centre;
extern const char *Txt_centres;
MYSQL_ROW row;
unsigned NumCtr;
struct Centre Ctr;
/***** Query database *****/
2018-10-30 13:59:37 +01:00
if (NumCtrs)
2014-12-01 23:55:08 +01:00
{
2017-06-12 14:16:33 +02:00
/***** Start box and table *****/
2014-12-01 23:55:08 +01:00
/* Number of centres found */
2018-10-17 01:08:42 +02:00
snprintf (Gbl.Title,sizeof (Gbl.Title),
"%u %s",
NumCtrs,(NumCtrs == 1) ? Txt_centre :
Txt_centres);
2017-06-10 21:38:10 +02:00
Box_StartBoxTable (NULL,Gbl.Title,NULL,
2017-06-12 15:03:29 +02:00
NULL,Box_NOT_CLOSABLE,2);
2017-06-12 14:16:33 +02:00
/***** Write heading *****/
2014-12-01 23:55:08 +01:00
Ctr_PutHeadCentresForSeeing (false); // Order not selectable
/***** List the centres (one row per centre) *****/
for (NumCtr = 1;
NumCtr <= NumCtrs;
NumCtr++)
{
/* Get next centre */
2018-10-30 13:59:37 +01:00
row = mysql_fetch_row (*mysql_res);
2014-12-01 23:55:08 +01:00
/* Get centre code (row[0]) */
Ctr.CtrCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get data of centre */
Ctr_GetDataOfCentreByCod (&Ctr);
/* Write data of this centre */
Ctr_ListOneCentreForSeeing (&Ctr,NumCtr);
}
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2017-06-10 21:38:10 +02:00
Box_EndBoxTable ();
2014-12-01 23:55:08 +01:00
}
/***** Free structure that stores the query result *****/
2018-10-30 13:59:37 +01:00
DB_FreeMySQLResult (mysql_res);
2014-12-01 23:55:08 +01:00
}