swad-core/swad_centre.c

2011 lines
68 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.
2020-01-01 14:53:57 +01:00
Copyright (C) 1999-2020 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 ***********************************/
/*****************************************************************************/
2015-10-16 02:24:29 +02:00
#include <stdbool.h> // For boolean type
2019-12-29 12:39:00 +01:00
#include <stddef.h> // For NULL
2020-01-03 22:16:51 +01:00
#include <stdlib.h> // For free
2014-12-01 23:55:08 +01:00
#include <string.h> // For string functions
#include "swad_centre.h"
2019-12-29 14:02:58 +01:00
#include "swad_centre_config.h"
2014-12-01 23:55:08 +01:00
#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"
2019-10-23 19:05:05 +02:00
#include "swad_HTML.h"
2015-01-17 13:31:25 +01:00
#include "swad_logo.h"
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
2019-04-08 23:34:58 +02:00
static struct Centre *Ctr_EditingCtr = NULL; // Static variable to keep the centre being edited
2019-04-06 21:39:35 +02:00
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
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
2019-04-06 21:39:35 +02:00
static void Ctr_EditCentresInternal (void);
2017-04-30 02:35:25 +02:00
static void Ctr_PutIconsEditingCentres (void);
2019-12-19 11:00:14 +01:00
static void Ctr_GetDataOfCentreFromRow (struct Centre *Ctr,MYSQL_ROW row);
2014-12-01 23:55:08 +01:00
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
2017-03-09 11:16:17 +01:00
static void Ctr_UpdateInsNameDB (long CtrCod,const char *FieldName,const char *NewCtrName);
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
2019-04-06 21:39:35 +02:00
static void Ctr_EditingCentreConstructor (void);
static void Ctr_EditingCentreDestructor (void);
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
{
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableBegin (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 *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-11 01:02:51 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH (1,1,"LM",Txt_Centre);
HTM_TH (1,1,"RM",Txt_Degrees_ABBREVIATION);
2019-10-11 01:02:51 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/***** 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]);
2019-04-03 20:57:04 +02:00
BgColor = (Ctr.CtrCod == Gbl.Hierarchy.Ctr.CtrCod) ? "LIGHT_BLUE" :
Gbl.ColorRows[Gbl.RowEvenOdd];
2014-12-01 23:55:08 +01:00
/* Get data of centre */
2020-01-05 02:18:20 +01:00
Ctr_GetDataOfCentreByCod (&Ctr);
2014-12-01 23:55:08 +01:00
2015-11-12 00:53:30 +01:00
/* Centre logo and full name */
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 23:02:50 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LM %s\"",BgColor);
2015-11-19 19:37:44 +01:00
Ctr_DrawCentreLogoAndNameWithLink (&Ctr,ActSeeDeg,
2019-11-18 09:53:50 +01:00
"BT_LINK DAT_NOBR","CM");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Number of pending degrees (row[1]) */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
2019-11-10 12:36:37 +01:00
HTM_Txt (row[1]);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableEnd ();
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)
{
2019-10-20 22:00:28 +02:00
/***** Begin 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 *****/
2019-12-30 12:25:45 +01:00
HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Ctr->FullName),ClassLink,NULL);
Hie_FreeGoToMsg ();
2015-11-19 19:37:44 +01:00
2019-10-27 09:28:51 +01:00
/***** Centre logo and name *****/
2019-12-14 14:30:34 +01:00
Lgo_DrawLogo (Hie_CTR,Ctr->CtrCod,Ctr->ShrtName,16,ClassLogo,true);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("&nbsp;%s",Ctr->FullName);
2015-11-19 19:37:44 +01:00
/***** End link *****/
2019-11-18 09:53:50 +01:00
HTM_BUTTON_End ();
2015-11-19 19:37:44 +01:00
/***** 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 the centres of the current institution *****************/
/*****************************************************************************/
void Ctr_ShowCtrsOfCurrentIns (void)
{
2019-04-03 20:57:04 +02:00
/***** Trivial check *****/
if (Gbl.Hierarchy.Ins.InsCod <= 0) // No institution selected
return;
/***** Get parameter with the type of order in the list of centres *****/
Ctr_GetParamCtrOrder ();
2014-12-01 23:55:08 +01:00
2019-04-03 20:57:04 +02:00
/***** Get list of centres *****/
Ctr_GetListCentres (Gbl.Hierarchy.Ins.InsCod);
2014-12-01 23:55:08 +01:00
2019-04-03 20:57:04 +02:00
/***** Write menu to select country and institution *****/
Hie_WriteMenuHierarchy ();
2014-12-01 23:55:08 +01:00
2019-04-03 20:57:04 +02:00
/***** List centres *****/
Ctr_ListCentres ();
2014-12-01 23:55:08 +01:00
2019-04-03 20:57:04 +02:00
/***** Free list of centres *****/
Ctr_FreeListCentres ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** 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
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2019-12-30 21:47:07 +01:00
Box_BoxBegin (NULL,Str_BuildStringStr (Txt_Centres_of_INSTITUTION_X,
Gbl.Hierarchy.Ins.FullName),
2019-12-30 14:55:25 +01:00
Ctr_PutIconsListingCentres,
2017-06-12 15:03:29 +02:00
Hlp_INSTITUTION_Centres,Box_NOT_CLOSABLE);
2019-12-30 21:47:07 +01:00
Str_FreeString ();
2016-03-20 13:47:46 +01:00
2019-04-04 10:45:15 +02:00
if (Gbl.Hierarchy.Ins.Ctrs.Num) // There are centres in the current institution
2016-03-20 13:47:46 +01:00
{
2019-10-20 22:00:28 +02:00
/***** Begin table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWideMarginPadding (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;
2019-04-04 10:45:15 +02:00
NumCtr < Gbl.Hierarchy.Ins.Ctrs.Num;
2016-03-20 13:47:46 +01:00
NumCtr++)
2019-04-04 10:45:15 +02:00
Ctr_ListOneCentreForSeeing (&(Gbl.Hierarchy.Ins.Ctrs.Lst[NumCtr]),NumCtr + 1);
2016-03-20 13:47:46 +01:00
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
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);
2019-04-04 10:45:15 +02:00
Btn_PutConfirmButton (Gbl.Hierarchy.Ins.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 *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
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)
{
2019-12-19 18:03:26 +01:00
extern const char *Txt_Map;
2014-12-01 23:55:08 +01:00
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";
2019-11-18 15:48:46 +01:00
TxtClassStrong = "BT_LINK LT DAT_LIGHT";
2015-11-19 16:09:51 +01:00
}
else
{
TxtClassNormal = "DAT";
2019-11-18 15:48:46 +01:00
TxtClassStrong = "BT_LINK LT DAT_N";
2015-11-19 16:09:51 +01:00
}
2019-04-03 20:57:04 +02:00
BgColor = (Ctr->CtrCod == Gbl.Hierarchy.Ctr.CtrCod) ? "LIGHT_BLUE" :
Gbl.ColorRows[Gbl.RowEvenOdd];
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-06 12:00:55 +02:00
/***** Number of centre in this list *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor);
2019-11-10 13:31:47 +01:00
HTM_Unsigned (NumCtr);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2015-11-19 16:09:51 +01:00
/***** Centre logo and name *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LM %s\"",BgColor);
2015-11-19 19:37:44 +01:00
Ctr_DrawCentreLogoAndNameWithLink (Ctr,ActSeeDeg,
2019-10-15 15:23:38 +02:00
TxtClassStrong,"CM");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
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 *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor);
2020-01-05 01:46:45 +01:00
HTM_Unsigned (Usr_GetNumUsrsWhoClaimToBelongToCtr (Ctr->CtrCod));
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2015-12-09 22:05:21 +01:00
/***** Place *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s LM %s\"",TxtClassNormal,BgColor);
2019-11-10 12:36:37 +01:00
HTM_Txt (Plc.ShrtName);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2019-12-19 18:03:26 +01:00
/***** Place *****/
HTM_TD_Begin ("class=\"%s CM %s\"",TxtClassNormal,BgColor);
if (Ctr->Coord.Latitude ||
Ctr->Coord.Longitude)
{
Ctr_EditingCtr = Ctr; // Used to pass parameter with the code of the centre
Lay_PutContextualLinkOnlyIcon (ActSeeCtrInf,NULL,Ctr_PutParamGoToCtr,
"map-marker-alt.svg",
Txt_Map);
}
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Number of degrees *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor);
2020-01-05 02:18:20 +01:00
HTM_Unsigned (Deg_GetNumDegsInCtr (Ctr->CtrCod));
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2015-12-09 22:05:21 +01:00
/***** Number of courses *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor);
2020-01-05 01:46:45 +01:00
HTM_Unsigned (Crs_GetNumCrssInCtr (Ctr->CtrCod));
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2015-12-09 22:05:21 +01:00
/***** Number of users in courses of this centre *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor);
2020-01-05 00:51:12 +01:00
HTM_Unsigned (Usr_GetNumUsrsInCrssOfCtr (Rol_UNK, // Here Rol_UNK means "all users"
Ctr->CtrCod));
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2015-11-19 16:09:51 +01:00
2014-12-01 23:55:08 +01:00
/***** Centre status *****/
StatusTxt = Ctr_GetStatusTxtFromStatusBits (Ctr->Status);
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s LM %s\"",TxtClassNormal,BgColor);
2017-03-17 00:46:28 +01:00
if (StatusTxt != Ctr_STATUS_ACTIVE) // If active ==> do not show anything
2019-11-11 00:15:44 +01:00
HTM_Txt (Txt_CENTRE_STATUS[StatusTxt]);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 23:18:45 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
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
{
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Ins.Ctrs.SelectedOrder = (Ctr_Order_t)
2017-01-29 21:41:08 +01:00
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)
2019-04-06 21:39:35 +02:00
{
/***** Centre constructor *****/
Ctr_EditingCentreConstructor ();
/***** Edit centres *****/
Ctr_EditCentresInternal ();
/***** Centre destructor *****/
Ctr_EditingCentreDestructor ();
}
static void Ctr_EditCentresInternal (void)
2014-12-01 23:55:08 +01:00
{
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 *****/
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Ins.Ctrs.SelectedOrder = Ctr_ORDER_BY_CENTRE;
2019-04-03 20:57:04 +02:00
Ctr_GetListCentres (Gbl.Hierarchy.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 ();
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2019-12-30 21:47:07 +01:00
Box_BoxBegin (NULL,Str_BuildStringStr (Txt_Centres_of_INSTITUTION_X,
Gbl.Hierarchy.Ins.FullName),
2019-12-30 14:55:25 +01:00
Ctr_PutIconsEditingCentres,
2017-06-12 15:03:29 +02:00
Hlp_INSTITUTION_Centres,Box_NOT_CLOSABLE);
2019-12-30 21:47:07 +01:00
Str_FreeString ();
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 *****/
2019-04-04 10:45:15 +02:00
if (Gbl.Hierarchy.Ins.Ctrs.Num)
2016-10-20 21:09:01 +02:00
Ctr_ListCentresForEdition ();
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
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] =
{
2019-11-21 00:40:35 +01:00
[Ctr_ORDER_BY_CENTRE ] = "FullName",
2019-12-15 20:02:34 +01:00
[Ctr_ORDER_BY_NUM_USRS] = "NumUsrs DESC,FullName",
2019-01-03 15:25:18 +01:00
};
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",
2020-01-05 01:46:45 +01:00
"SELECT CtrCod," // row[ 0]
"InsCod," // row[ 1]
"PlcCod," // row[ 2]
"Status," // row[ 3]
"RequesterUsrCod," // row[ 4]
"Latitude," // row[ 5]
"Longitude," // row[ 6]
"Altitude," // row[ 7]
"ShortName," // row[ 8]
"FullName," // row[ 9]
"WWW" // row[10]
2018-10-30 13:59:37 +01:00
" FROM centres"
2020-01-05 01:46:45 +01:00
" WHERE InsCod=%ld"
2018-10-30 13:59:37 +01:00
" ORDER BY %s",
InsCod,
2019-04-04 10:45:15 +02:00
OrderBySubQuery[Gbl.Hierarchy.Ins.Ctrs.SelectedOrder]);
2014-12-01 23:55:08 +01:00
if (NumRows) // Centres found...
{
// NumRows should be equal to Deg->NumCourses
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Ins.Ctrs.Num = (unsigned) NumRows;
2014-12-01 23:55:08 +01:00
/***** Create list with courses in degree *****/
2019-12-19 11:00:14 +01:00
if ((Gbl.Hierarchy.Ins.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;
2019-04-04 10:45:15 +02:00
NumCtr < Gbl.Hierarchy.Ins.Ctrs.Num;
2014-12-01 23:55:08 +01:00
NumCtr++)
{
2019-04-04 10:45:15 +02:00
Ctr = &(Gbl.Hierarchy.Ins.Ctrs.Lst[NumCtr]);
2014-12-01 23:55:08 +01:00
/* Get next centre */
row = mysql_fetch_row (mysql_res);
2019-12-19 11:00:14 +01:00
Ctr_GetDataOfCentreFromRow (Ctr,row);
2014-12-01 23:55:08 +01:00
}
}
else
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Ins.Ctrs.Num = 0;
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/************************ Get data of centre by code *************************/
/*****************************************************************************/
2020-01-05 02:18:20 +01:00
bool Ctr_GetDataOfCentreByCod (struct Centre *Ctr)
2014-12-01 23:55:08 +01:00
{
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 *****/
2020-01-05 12:52:03 +01:00
Ctr->InsCod = -1L;
Ctr->PlcCod = -1L;
Ctr->Status = (Ctr_Status_t) 0;
2014-12-01 23:55:08 +01:00
Ctr->RequesterUsrCod = -1L;
2020-01-05 12:52:03 +01:00
Ctr->ShrtName[0] = '\0';
Ctr->FullName[0] = '\0';
Ctr->WWW[0] = '\0';
Ctr->Degs.Num = 0;
Ctr->Degs.Lst = NULL;
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",
2020-01-05 01:46:45 +01:00
"SELECT CtrCod," // row[ 0]
"InsCod," // row[ 1]
"PlcCod," // row[ 2]
"Status," // row[ 3]
"RequesterUsrCod," // row[ 4]
"Latitude," // row[ 5]
"Longitude," // row[ 6]
"Altitude," // row[ 7]
"ShortName," // row[ 8]
"FullName," // row[ 9]
"WWW" // row[10]
2018-10-30 13:59:37 +01:00
" FROM centres"
2020-01-05 01:46:45 +01:00
" WHERE CtrCod=%ld",
2018-10-30 13:59:37 +01:00
Ctr->CtrCod);
if (NumRows) // Centre found...
2014-12-01 23:55:08 +01:00
{
/* Get row */
row = mysql_fetch_row (mysql_res);
2019-12-19 11:00:14 +01:00
Ctr_GetDataOfCentreFromRow (Ctr,row);
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;
}
2019-12-19 11:00:14 +01:00
/*****************************************************************************/
/********** Get data of a centre from a row resulting of a query *************/
/*****************************************************************************/
static void Ctr_GetDataOfCentreFromRow (struct Centre *Ctr,MYSQL_ROW row)
{
/***** 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 latitude (row[5]) *****/
2020-01-03 20:31:02 +01:00
Ctr->Coord.Latitude = Map_GetLatitudeFromStr (row[5]);
2019-12-19 11:00:14 +01:00
/***** Get longitude (row[6]) *****/
2020-01-03 20:31:02 +01:00
Ctr->Coord.Longitude = Map_GetLongitudeFromStr (row[6]);
2019-12-19 11:00:14 +01:00
/***** Get altitude (row[7]) *****/
2020-01-03 20:31:02 +01:00
Ctr->Coord.Altitude = Map_GetAltitudeFromStr (row[7]);
2019-12-19 11:00:14 +01:00
/***** Get the short name of the centre (row[8]) *****/
Str_Copy (Ctr->ShrtName,row[8],
Hie_MAX_BYTES_SHRT_NAME);
/***** Get the full name of the centre (row[9]) *****/
Str_Copy (Ctr->FullName,row[9],
Hie_MAX_BYTES_FULL_NAME);
/***** Get the URL of the centre (row[10]) *****/
Str_Copy (Ctr->WWW,row[10],
Cns_MAX_BYTES_WWW);
}
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
/*****************************************************************************/
/**************************** Free list of centres ***************************/
/*****************************************************************************/
void Ctr_FreeListCentres (void)
{
2019-04-04 10:45:15 +02:00
if (Gbl.Hierarchy.Ins.Ctrs.Lst)
2014-12-01 23:55:08 +01:00
{
/***** Free memory used by the list of courses in degree *****/
2019-11-06 19:45:20 +01:00
free (Gbl.Hierarchy.Ins.Ctrs.Lst);
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Ins.Ctrs.Lst = NULL;
Gbl.Hierarchy.Ins.Ctrs.Num = 0;
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/************************** 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;
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
2018-11-09 20:47:39 +01:00
Frm_StartFormGoTo (ActSeeDeg);
2019-11-05 15:47:35 +01:00
2019-04-03 20:57:04 +02:00
if (Gbl.Hierarchy.Ins.InsCod > 0)
2019-11-05 15:47:35 +01:00
HTM_SELECT_Begin (true,
"id=\"ctr\" name=\"ctr\" class=\"HIE_SEL\"");
2014-12-01 23:55:08 +01:00
else
2019-11-05 15:47:35 +01:00
HTM_SELECT_Begin (false,
"id=\"ctr\" name=\"ctr\" class=\"HIE_SEL\""
" disabled=\"disabled\"");
2019-11-06 19:45:20 +01:00
HTM_OPTION (HTM_Type_STRING,"",
2019-11-06 02:20:35 +01:00
Gbl.Hierarchy.Ctr.CtrCod < 0,true,
"[%s]",Txt_Centre);
2014-12-01 23:55:08 +01:00
2019-04-03 20:57:04 +02:00
if (Gbl.Hierarchy.Ins.InsCod > 0)
2014-12-01 23:55:08 +01:00
{
/***** 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",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.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 */
2019-11-06 19:45:20 +01:00
HTM_OPTION (HTM_Type_LONG,&CtrCod,
2019-11-06 02:20:35 +01:00
Gbl.Hierarchy.Ctr.CtrCod > 0 &&
CtrCod == Gbl.Hierarchy.Ctr.CtrCod,false,
"%s",row[1]);
2014-12-01 23:55:08 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/***** End form *****/
2019-11-05 08:46:38 +01:00
HTM_SELECT_End ();
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;
2019-11-06 15:27:33 +01:00
unsigned StatusUnsigned;
2014-12-01 23:55:08 +01:00
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** Write heading *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWidePadding (2);
2014-12-01 23:55:08 +01:00
Ctr_PutHeadCentresForEdition ();
/***** Write all the centres *****/
for (NumCtr = 0;
2019-04-04 10:45:15 +02:00
NumCtr < Gbl.Hierarchy.Ins.Ctrs.Num;
2014-12-01 23:55:08 +01:00
NumCtr++)
{
2019-04-04 10:45:15 +02:00
Ctr = &Gbl.Hierarchy.Ins.Ctrs.Lst[NumCtr];
2014-12-01 23:55:08 +01:00
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 */
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
HTM_TD_Begin ("class=\"BM\"");
2020-01-05 00:51:12 +01:00
if (!ICanEdit)
2017-06-11 19:13:28 +02:00
Ico_PutIconRemovalNotAllowed ();
2020-01-05 02:18:20 +01:00
else if (Deg_GetNumDegsInCtr (Ctr->CtrCod)) // Centre has degrees
2020-01-05 00:51:12 +01:00
Ico_PutIconRemovalNotAllowed ();
2020-01-05 01:46:45 +01:00
else if (Usr_GetNumUsrsWhoClaimToBelongToCtr (Ctr->CtrCod)) // Centre has users who claim to belong to it
2020-01-05 00:51:12 +01:00
Ico_PutIconRemovalNotAllowed ();
else if (Usr_GetNumUsrsInCrssOfCtr (Rol_UNK, // Here Rol_UNK means "all users"
2020-01-05 01:46:45 +01:00
Ctr->CtrCod)) // Centre has users
2020-01-05 00:51:12 +01:00
Ico_PutIconRemovalNotAllowed ();
2020-01-05 01:46:45 +01:00
else // I can remove centre
2014-12-01 23:55:08 +01:00
{
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
}
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Centre code */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT CODE\"");
2019-11-10 13:38:17 +01:00
HTM_Long (Ctr->CtrCod);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2015-01-14 00:32:23 +01:00
/* Centre logo */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("title=\"%s\" class=\"HIE_LOGO\"",Ctr->FullName);
2019-12-14 14:30:34 +01:00
Lgo_DrawLogo (Hie_CTR,Ctr->CtrCod,Ctr->ShrtName,20,NULL,true);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Place */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT LM\"");
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);
2019-11-05 15:47:35 +01:00
HTM_SELECT_Begin (true,
"name=\"PlcCod\" class=\"PLC_SEL\"");
2019-11-06 19:45:20 +01:00
HTM_OPTION (HTM_Type_STRING,"0",
2019-11-06 02:20:35 +01:00
Ctr->PlcCod == 0,false,
"%s",Txt_Another_place);
2014-12-01 23:55:08 +01:00
for (NumPlc = 0;
NumPlc < Gbl.Plcs.Num;
NumPlc++)
2019-11-06 19:45:20 +01:00
HTM_OPTION (HTM_Type_LONG,&Gbl.Plcs.Lst[NumPlc].PlcCod,
2019-11-06 02:20:35 +01:00
Gbl.Plcs.Lst[NumPlc].PlcCod == Ctr->PlcCod,false,
"%s",Gbl.Plcs.Lst[NumPlc].ShrtName);
2019-11-05 08:46:38 +01:00
HTM_SELECT_End ();
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)
2019-11-10 12:36:37 +01:00
HTM_Txt (Gbl.Plcs.Lst[NumPlc].ShrtName);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Centre short name */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT LM\"");
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);
2019-11-04 12:25:48 +01:00
HTM_INPUT_TEXT ("ShortName",Hie_MAX_CHARS_SHRT_NAME,Ctr->ShrtName,true,
"class=\"INPUT_SHORT_NAME\"");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
else
2019-11-10 12:36:37 +01:00
HTM_Txt (Ctr->ShrtName);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Centre full name */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT LM\"");
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);
2019-11-04 12:25:48 +01:00
HTM_INPUT_TEXT ("FullName",Hie_MAX_CHARS_FULL_NAME,Ctr->FullName,true,
"class=\"INPUT_FULL_NAME\"");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
else
2019-11-10 12:36:37 +01:00
HTM_Txt (Ctr->FullName);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Centre WWW */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT LM\"");
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);
2019-11-04 12:25:48 +01:00
HTM_INPUT_URL ("WWW",Ctr->WWW,true,
2019-12-19 11:00:14 +01:00
"class=\"INPUT_WWW_NARROW\" required=\"required\"");
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);
2019-10-23 21:37:01 +02:00
HTM_DIV_Begin ("class=\"EXTERNAL_WWW_SHORT\"");
2019-10-28 20:38:29 +01:00
HTM_A_Begin ("href=\"%s\" target=\"_blank\""
" class=\"DAT\" title=\"%s\"",Ctr->WWW,Ctr->WWW);
2019-11-10 12:36:37 +01:00
HTM_Txt (WWW);
2019-10-28 13:56:04 +01:00
HTM_A_End ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2014-12-01 23:55:08 +01:00
}
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
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 */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2020-01-05 01:46:45 +01:00
HTM_Unsigned (Usr_GetNumUsrsWhoClaimToBelongToCtr (Ctr->CtrCod));
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2015-12-14 16:44:14 +01:00
/* Number of degrees */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2020-01-05 02:18:20 +01:00
HTM_Unsigned (Deg_GetNumDegsInCtr (Ctr->CtrCod));
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2015-12-14 16:44:14 +01:00
/* Number of users in courses of this centre */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2020-01-05 00:51:12 +01:00
HTM_Unsigned (Usr_GetNumUsrsInCrssOfCtr (Rol_UNK, // Here Rol_UNK means "all users"
Ctr->CtrCod));
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2015-12-14 16:44:14 +01:00
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);
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT INPUT_REQUESTER LT\"");
2017-05-02 01:16:06 +02:00
Msg_WriteMsgAuthor (&UsrDat,true,NULL);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2017-03-17 00:46:28 +01:00
2014-12-01 23:55:08 +01:00
/* Centre status */
StatusTxt = Ctr_GetStatusTxtFromStatusBits (Ctr->Status);
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT LM\"");
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);
2019-11-05 15:47:35 +01:00
HTM_SELECT_Begin (true,
"name=\"Status\" class=\"INPUT_STATUS\"");
2019-11-06 02:20:35 +01:00
2019-11-06 15:27:33 +01:00
StatusUnsigned = (unsigned) Ctr_GetStatusBitsFromStatusTxt (Ctr_STATUS_PENDING);
2019-11-06 19:45:20 +01:00
HTM_OPTION (HTM_Type_UNSIGNED,&StatusUnsigned,true,false,
2019-11-06 02:20:35 +01:00
"%s",Txt_CENTRE_STATUS[Ctr_STATUS_PENDING]);
2019-11-06 15:27:33 +01:00
StatusUnsigned = (unsigned) Ctr_GetStatusBitsFromStatusTxt (Ctr_STATUS_ACTIVE);
2019-11-06 19:45:20 +01:00
HTM_OPTION (HTM_Type_UNSIGNED,&StatusUnsigned,false,false,
2019-11-06 02:20:35 +01:00
"%s",Txt_CENTRE_STATUS[Ctr_STATUS_ACTIVE]);
2019-11-05 08:46:38 +01:00
HTM_SELECT_End ();
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
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_CENTRE_STATUS[StatusTxt]);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
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)
{
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamLong (NULL,"ctr",CtrCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************** Write parameter with code of other centre *****************/
/*****************************************************************************/
static void Ctr_PutParamOtherCtrCod (long CtrCod)
{
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamLong (NULL,"OthCtrCod",CtrCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************** 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;
2017-01-28 15:58:46 +01:00
char PathCtr[PATH_MAX + 1];
2014-12-01 23:55:08 +01:00
2019-04-06 21:39:35 +02:00
/***** Centre constructor *****/
Ctr_EditingCentreConstructor ();
2014-12-01 23:55:08 +01:00
/***** Get centre code *****/
2019-04-06 21:39:35 +02:00
Ctr_EditingCtr->CtrCod = Ctr_GetAndCheckParamOtherCtrCod (1);
2014-12-01 23:55:08 +01:00
/***** Get data of the centre from database *****/
2020-01-05 02:18:20 +01:00
Ctr_GetDataOfCentreByCod (Ctr_EditingCtr);
2014-12-01 23:55:08 +01:00
/***** Check if this centre has teachers *****/
2020-01-05 02:18:20 +01:00
if (Deg_GetNumDegsInCtr (Ctr_EditingCtr->CtrCod)) // Centre has degrees
2020-01-05 01:46:45 +01:00
Ale_ShowAlert (Ale_WARNING,
Txt_To_remove_a_centre_you_must_first_remove_all_degrees_and_teachers_in_the_centre);
else if (Usr_GetNumUsrsWhoClaimToBelongToCtr (Ctr_EditingCtr->CtrCod)) // Centre has users who claim to belong to it
Ale_ShowAlert (Ale_WARNING,
Txt_To_remove_a_centre_you_must_first_remove_all_degrees_and_teachers_in_the_centre);
else if (Usr_GetNumUsrsInCrssOfCtr (Rol_UNK, // Here Rol_UNK means "all users"
Ctr_EditingCtr->CtrCod)) // Centre has users
Ale_ShowAlert (Ale_WARNING,
Txt_To_remove_a_centre_you_must_first_remove_all_degrees_and_teachers_in_the_centre);
2020-01-05 00:51:12 +01:00
else // Centre has no degrees or users ==> remove it
2014-12-01 23:55:08 +01:00
{
2016-10-28 00:23:02 +02:00
/***** Remove all the threads and posts in forums of the centre *****/
2019-04-06 21:39:35 +02:00
For_RemoveForums (Hie_CTR,Ctr_EditingCtr->CtrCod);
2016-10-28 00:23:02 +02:00
/***** Remove surveys of the centre *****/
2019-04-06 21:39:35 +02:00
Svy_RemoveSurveys (Hie_CTR,Ctr_EditingCtr->CtrCod);
2016-10-28 00:23:02 +02:00
2015-01-20 02:00:42 +01:00
/***** Remove information related to files in centre *****/
2019-04-06 21:39:35 +02:00
Brw_RemoveCtrFilesFromDB (Ctr_EditingCtr->CtrCod);
2015-01-25 18:50:43 +01:00
2019-01-05 11:51:22 +01:00
/***** Remove all classrooms in centre *****/
2019-04-06 21:39:35 +02:00
Cla_RemoveAllClassroomsInCtr (Ctr_EditingCtr->CtrCod);
2019-01-05 11:51:22 +01:00
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,
2019-04-06 21:39:35 +02:00
(unsigned) (Ctr_EditingCtr->CtrCod % 100),
(unsigned) Ctr_EditingCtr->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",
2019-04-06 21:39:35 +02:00
Ctr_EditingCtr->CtrCod);
2014-12-01 23:55:08 +01:00
2020-01-05 00:51:12 +01:00
/***** Flush caches *****/
2020-01-05 02:18:20 +01:00
Deg_FlushCacheNumDegsInCtr ();
2020-01-05 01:46:45 +01:00
Crs_FlushCacheNumCrssInCtr ();
Usr_FlushCacheNumUsrsWhoClaimToBelongToCtr ();
Usr_FlushCacheNumUsrsInCrssOfCtr ();
2020-01-05 00:51:12 +01:00
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2019-04-08 15:33:29 +02:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_Centre_X_removed,
Ctr_EditingCtr->FullName);
2019-06-13 10:14:05 +02:00
Ctr_EditingCtr->CtrCod = -1L; // To not showing button to go to centre
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
2019-04-06 21:39:35 +02:00
/***** Centre constructor *****/
Ctr_EditingCentreConstructor ();
2017-05-31 21:05:59 +02:00
/***** Get centre code *****/
2019-04-06 21:39:35 +02:00
Ctr_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 *****/
2020-01-05 02:18:20 +01:00
Ctr_GetDataOfCentreByCod (Ctr_EditingCtr);
2014-12-01 23:55:08 +01:00
/***** Update place in table of centres *****/
2019-04-06 21:39:35 +02:00
Ctr_UpdateCtrPlcDB (Ctr_EditingCtr->CtrCod,NewPlcCod);
Ctr_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);
2014-12-01 23:55:08 +01:00
}
2017-06-12 19:14:05 +02:00
/*****************************************************************************/
/************** Update database changing old place by new place **************/
/*****************************************************************************/
2019-12-29 14:02:58 +01:00
void Ctr_UpdateCtrPlcDB (long CtrCod,long NewPlcCod)
2017-06-12 19:14:05 +02:00
{
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
/*****************************************************************************/
2019-04-06 21:39:35 +02:00
/************************ Change the name of a centre ************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
void Ctr_RenameCentreShort (void)
{
2019-04-06 21:39:35 +02:00
/***** Centre constructor *****/
Ctr_EditingCentreConstructor ();
/***** Rename centre *****/
Ctr_EditingCtr->CtrCod = Ctr_GetAndCheckParamOtherCtrCod (1);
Ctr_RenameCentre (Ctr_EditingCtr,Cns_SHRT_NAME);
2014-12-01 23:55:08 +01:00
}
2019-04-06 21:39:35 +02:00
void Ctr_RenameCentreFull (void)
2016-10-23 12:07:16 +02:00
{
2019-04-06 21:39:35 +02:00
/***** Centre constructor *****/
Ctr_EditingCentreConstructor ();
/***** Rename centre *****/
Ctr_EditingCtr->CtrCod = Ctr_GetAndCheckParamOtherCtrCod (1);
Ctr_RenameCentre (Ctr_EditingCtr,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
/*****************************************************************************/
2019-12-29 14:02:58 +01:00
void Ctr_RenameCentre (struct Centre *Ctr,Cns_ShrtOrFullName_t ShrtOrFullName)
2014-12-01 23:55:08 +01:00
{
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 *****/
2020-01-05 02:18:20 +01:00
Ctr_GetDataOfCentreByCod (Ctr);
2014-12-01 23:55:08 +01:00
/***** Check if new name is empty *****/
if (!NewCtrName[0])
2019-12-20 00:30:54 +01:00
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
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... *****/
2019-04-03 20:57:04 +02:00
if (Ctr_CheckIfCtrNameExistsInIns (ParamName,NewCtrName,Ctr->CtrCod,Gbl.Hierarchy.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 ********************/
/*****************************************************************************/
2019-12-29 14:02:58 +01:00
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;
2017-03-07 01:56:41 +01:00
char NewWWW[Cns_MAX_BYTES_WWW + 1];
2014-12-01 23:55:08 +01:00
2019-04-06 21:39:35 +02:00
/***** Centre constructor *****/
Ctr_EditingCentreConstructor ();
2017-05-31 21:05:59 +02:00
/***** Get the code of the centre *****/
2019-04-06 21:39:35 +02:00
Ctr_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 *****/
2020-01-05 02:18:20 +01:00
Ctr_GetDataOfCentreByCod (Ctr_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 *****/
2019-04-06 21:39:35 +02:00
Ctr_UpdateCtrWWWDB (Ctr_EditingCtr->CtrCod,NewWWW);
Str_Copy (Ctr_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);
2014-12-01 23:55:08 +01:00
}
else
2019-12-20 00:30:54 +01:00
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
2016-10-23 14:49:03 +02:00
}
/*****************************************************************************/
/**************** Update database changing old WWW by new WWW ****************/
/*****************************************************************************/
2019-12-29 14:02:58 +01:00
void Ctr_UpdateCtrWWWDB (long CtrCod,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;
2019-04-06 21:39:35 +02:00
/***** Centre constructor *****/
Ctr_EditingCentreConstructor ();
2017-05-31 21:05:59 +02:00
/***** Get centre code *****/
2019-04-06 21:39:35 +02:00
Ctr_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 *****/
2020-01-05 02:18:20 +01:00
Ctr_GetDataOfCentreByCod (Ctr_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",
2019-04-06 21:39:35 +02:00
(unsigned) Status,Ctr_EditingCtr->CtrCod);
Ctr_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,
2019-04-06 21:39:35 +02:00
Ctr_EditingCtr->ShrtName);
2019-04-08 15:33:29 +02:00
}
/*****************************************************************************/
/********* Show alerts after changing a centre and continue editing **********/
/*****************************************************************************/
void Ctr_ContEditAfterChgCtr (void)
{
/***** Write message to show the change made
and put button to go to centre 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 *****/
2019-04-06 21:39:35 +02:00
Ctr_EditCentresInternal ();
2016-03-01 19:23:02 +01:00
2019-04-06 21:39:35 +02:00
/***** Centre destructor *****/
Ctr_EditingCentreDestructor ();
2016-03-01 19:23:02 +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 ********************/
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
{
2017-05-11 20:55:04 +02:00
// If the centre being edited is different to the current one...
2019-04-06 21:39:35 +02:00
if (Ctr_EditingCtr->CtrCod != Gbl.Hierarchy.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 *****/
2019-03-09 20:12:44 +01:00
Ale_ShowLastAlertAndButton (ActSeeDeg,NULL,NULL,Ctr_PutParamGoToCtr,
2019-12-30 12:25:45 +01:00
Btn_CONFIRM_BUTTON,
Hie_BuildGoToMsg (Ctr_EditingCtr->ShrtName));
Hie_FreeGoToMsg ();
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)
{
2019-04-06 21:39:35 +02:00
Ctr_PutParamCtrCod (Ctr_EditingCtr->CtrCod);
2016-03-01 19:23:02 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************* 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;
2019-10-20 22:00:28 +02:00
/***** Begin 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
2019-10-26 01:56:36 +02:00
Lay_NoPermissionExit ();
2014-12-01 23:55:08 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableBegin (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 ();
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 23:18:45 +02:00
/***** Column to remove centre, disabled here *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"BM\"");
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Centre code *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"CODE\"");
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Centre logo *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("title=\"%s\" class=\"HIE_LOGO\"",Ctr_EditingCtr->FullName);
2019-12-14 14:30:34 +01:00
Lgo_DrawLogo (Hie_CTR,-1L,"",20,NULL,true);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Place *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LM\"");
2019-11-05 15:47:35 +01:00
HTM_SELECT_Begin (false,
2019-11-19 21:59:30 +01:00
"name=\"PlcCod\" class=\"PLC_SEL\"");
2019-11-06 19:45:20 +01:00
HTM_OPTION (HTM_Type_STRING,"0",
2019-11-06 02:20:35 +01:00
Ctr_EditingCtr->PlcCod == 0,false,
"%s",Txt_Another_place);
2014-12-01 23:55:08 +01:00
for (NumPlc = 0;
NumPlc < Gbl.Plcs.Num;
NumPlc++)
2019-11-06 19:45:20 +01:00
HTM_OPTION (HTM_Type_LONG,&Gbl.Plcs.Lst[NumPlc].PlcCod,
2019-11-06 02:20:35 +01:00
Gbl.Plcs.Lst[NumPlc].PlcCod == Ctr_EditingCtr->PlcCod,false,
"%s",Gbl.Plcs.Lst[NumPlc].ShrtName);
2019-11-05 08:46:38 +01:00
HTM_SELECT_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Centre short name *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LM\"");
2019-11-04 12:25:48 +01:00
HTM_INPUT_TEXT ("ShortName",Hie_MAX_CHARS_SHRT_NAME,Ctr_EditingCtr->ShrtName,false,
2019-11-03 18:22:11 +01:00
"class=\"INPUT_SHORT_NAME\" required=\"required\"");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Centre full name *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LM\"");
2019-11-04 12:25:48 +01:00
HTM_INPUT_TEXT ("FullName",Hie_MAX_CHARS_FULL_NAME,Ctr_EditingCtr->FullName,false,
2019-11-03 18:22:11 +01:00
"class=\"INPUT_FULL_NAME\" required=\"required\"");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Centre WWW *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LM\"");
2019-11-04 12:25:48 +01:00
HTM_INPUT_URL ("WWW",Ctr_EditingCtr->WWW,false,
2019-12-19 11:00:14 +01:00
"class=\"INPUT_WWW_NARROW\" required=\"required\"");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
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 *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2019-11-10 13:51:07 +01:00
HTM_Unsigned (0);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Number of degrees *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2019-11-10 13:51:07 +01:00
HTM_Unsigned (0);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2015-12-14 16:44:14 +01:00
/***** Number of users in courses of this centre *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2019-11-10 13:51:07 +01:00
HTM_Unsigned (0);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2015-12-14 16:44:14 +01:00
2014-12-01 23:55:08 +01:00
/***** Centre requester *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT INPUT_REQUESTER LT\"");
2017-05-02 01:16:06 +02:00
Msg_WriteMsgAuthor (&Gbl.Usrs.Me.UsrDat,true,NULL);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2017-03-17 00:46:28 +01:00
/***** Centre status *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT LM\"");
HTM_TD_End ();
2019-10-07 23:18:45 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End table, send button and end box *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableWithButtonEnd (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;
2019-12-19 18:03:26 +01:00
extern const char *Txt_Map;
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
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-11 01:02:51 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH_Empty (1);
2019-10-11 01:02:51 +02:00
2019-12-15 20:02:34 +01:00
for (Order = (Ctr_Order_t) 0;
Order <= (Ctr_Order_t) (Ctr_NUM_ORDERS - 1);
2014-12-01 23:55:08 +01:00
Order++)
{
2019-10-23 19:05:05 +02:00
HTM_TH_Begin (1,1,Order == Ctr_ORDER_BY_CENTRE ? "LM" :
2019-12-19 18:03:26 +01:00
"RM");
2014-12-01 23:55:08 +01:00
if (OrderSelectable)
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActSeeCtr);
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) Order);
2019-12-19 18:03:26 +01:00
HTM_BUTTON_SUBMIT_Begin (Txt_CENTRES_HELP_ORDER[Order],
Order == Ctr_ORDER_BY_CENTRE ? "BT_LINK LM TIT_TBL" :
"BT_LINK RM TIT_TBL",
NULL);
2019-04-04 10:45:15 +02:00
if (Order == Gbl.Hierarchy.Ins.Ctrs.SelectedOrder)
2019-11-10 16:41:47 +01:00
HTM_U_Begin ();
2014-12-01 23:55:08 +01:00
}
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_CENTRES_ORDER[Order]);
2014-12-01 23:55:08 +01:00
if (OrderSelectable)
{
2019-04-04 10:45:15 +02:00
if (Order == Gbl.Hierarchy.Ins.Ctrs.SelectedOrder)
2019-11-10 16:41:47 +01:00
HTM_U_End ();
2019-11-18 09:53:50 +01:00
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
2019-10-23 19:05:05 +02:00
HTM_TH_End ();
2014-12-01 23:55:08 +01:00
}
2019-10-11 01:02:51 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH (1,1,"LM",Txt_Place);
2019-12-19 18:03:26 +01:00
HTM_TH (1,1,"CM",Txt_Map);
2019-10-23 19:05:05 +02:00
HTM_TH (1,1,"RM",Txt_Degrees_ABBREVIATION);
HTM_TH (1,1,"RM",Txt_Courses_ABBREVIATION);
HTM_TH_Begin (1,1,"RM");
2019-11-11 00:15:44 +01:00
HTM_TxtF ("%s+",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]);
2019-11-09 21:08:20 +01:00
HTM_BR ();
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD]);
2019-10-23 19:05:05 +02:00
HTM_TH_End ();
HTM_TH_Empty (1);
2019-10-11 01:02:51 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
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;
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
HTM_TH_Empty (1);
HTM_TH (1,1,"RM",Txt_Code);
HTM_TH_Empty (1);
HTM_TH (1,1,"LM",Txt_Place);
HTM_TH (1,1,"LM",Txt_Short_name_of_the_centre);
HTM_TH (1,1,"LM",Txt_Full_name_of_the_centre);
HTM_TH (1,1,"LM",Txt_WWW);
HTM_TH (1,1,"RM",Txt_Users);
HTM_TH (1,1,"RM",Txt_Degrees_ABBREVIATION);
HTM_TH_Begin (1,1,"RM");
2019-11-11 00:15:44 +01:00
HTM_TxtF ("%s+",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]);
2019-11-09 21:08:20 +01:00
HTM_BR ();
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD]);
2019-10-23 19:05:05 +02:00
HTM_TH_End ();
HTM_TH (1,1,"LM",Txt_Requester);
HTM_TH_Empty (1);
2019-10-11 01:02:51 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************** Receive form to request a new centre *********************/
/*****************************************************************************/
void Ctr_RecFormReqCtr (void)
{
2019-04-06 21:39:35 +02:00
/***** Centre constructor *****/
Ctr_EditingCentreConstructor ();
/***** Receive form to request a new centre *****/
2014-12-01 23:55:08 +01:00
Ctr_RecFormRequestOrCreateCtr ((unsigned) Ctr_STATUS_BIT_PENDING);
}
/*****************************************************************************/
/******************* Receive form to create a new centre *********************/
/*****************************************************************************/
void Ctr_RecFormNewCtr (void)
{
2019-04-06 21:39:35 +02:00
/***** Centre constructor *****/
Ctr_EditingCentreConstructor ();
/***** Receive form to create a new centre *****/
2014-12-01 23:55:08 +01:00
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;
2019-04-08 15:33:29 +02:00
extern const char *Txt_Created_new_centre_X;
2014-12-01 23:55:08 +01:00
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 */
2019-04-06 21:39:35 +02:00
Ctr_EditingCtr->InsCod = Gbl.Hierarchy.Ins.InsCod;
2014-12-01 23:55:08 +01:00
/* Get place */
2019-04-06 21:39:35 +02:00
if ((Ctr_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 */
2019-04-06 21:39:35 +02:00
Par_GetParToText ("ShortName",Ctr_EditingCtr->ShrtName,Hie_MAX_BYTES_SHRT_NAME);
2014-12-01 23:55:08 +01:00
/* Get centre full name */
2019-04-06 21:39:35 +02:00
Par_GetParToText ("FullName",Ctr_EditingCtr->FullName,Hie_MAX_BYTES_FULL_NAME);
2014-12-01 23:55:08 +01:00
/* Get centre WWW */
2019-04-06 21:39:35 +02:00
Par_GetParToText ("WWW",Ctr_EditingCtr->WWW,Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
2019-04-06 21:39:35 +02:00
if (Ctr_EditingCtr->ShrtName[0] &&
Ctr_EditingCtr->FullName[0]) // If there's a centre name
2014-12-01 23:55:08 +01:00
{
2019-04-06 21:39:35 +02:00
if (Ctr_EditingCtr->WWW[0])
2014-12-01 23:55:08 +01:00
{
/***** If name of centre was in database... *****/
2019-04-06 21:39:35 +02:00
if (Ctr_CheckIfCtrNameExistsInIns ("ShortName",Ctr_EditingCtr->ShrtName,-1L,Gbl.Hierarchy.Ins.InsCod))
2019-04-08 15:33:29 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_centre_X_already_exists,
Ctr_EditingCtr->ShrtName);
2019-04-06 21:39:35 +02:00
else if (Ctr_CheckIfCtrNameExistsInIns ("FullName",Ctr_EditingCtr->FullName,-1L,Gbl.Hierarchy.Ins.InsCod))
2019-04-08 15:33:29 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_centre_X_already_exists,
Ctr_EditingCtr->FullName);
2014-12-01 23:55:08 +01:00
else // Add new centre to database
2019-04-08 15:33:29 +02:00
{
2017-05-11 20:55:04 +02:00
Ctr_CreateCentre (Status);
2019-04-08 15:33:29 +02:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_Created_new_centre_X,
Ctr_EditingCtr->FullName);
}
2014-12-01 23:55:08 +01:00
}
2015-01-14 00:32:23 +01:00
else // If there is not a web
2019-04-08 15:33:29 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
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-04-08 15:33:29 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_centre);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************************** Create a new centre ***************************/
/*****************************************************************************/
2017-05-11 20:55:04 +02:00
static void Ctr_CreateCentre (unsigned Status)
2014-12-01 23:55:08 +01:00
{
/***** Create a new centre *****/
2019-04-06 21:39:35 +02:00
Ctr_EditingCtr->CtrCod =
2018-11-03 01:45:36 +01:00
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','')",
2019-04-06 21:39:35 +02:00
Ctr_EditingCtr->InsCod,
Ctr_EditingCtr->PlcCod,
2018-11-03 01:45:36 +01:00
Status,
Gbl.Usrs.Me.UsrDat.UsrCod,
2019-04-06 21:39:35 +02:00
Ctr_EditingCtr->ShrtName,
Ctr_EditingCtr->FullName,
Ctr_EditingCtr->WWW);
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",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.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
{
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
2014-12-01 23:55:08 +01:00
/* Number of centres found */
2019-12-30 21:47:07 +01:00
Box_BoxTableBegin (NULL,Str_BuildStringLongStr ((long) NumCtrs,
(NumCtrs == 1) ? Txt_centre :
Txt_centres),
2019-12-30 20:41:40 +01:00
NULL,NULL,Box_NOT_CLOSABLE,2);
2019-12-30 21:47:07 +01:00
Str_FreeString ();
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 */
2020-01-05 02:18:20 +01:00
Ctr_GetDataOfCentreByCod (&Ctr);
2014-12-01 23:55:08 +01:00
/* Write data of this centre */
Ctr_ListOneCentreForSeeing (&Ctr,NumCtr);
}
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableEnd ();
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
}
2019-04-06 21:39:35 +02:00
/*****************************************************************************/
/************************ Centre constructor/destructor **********************/
/*****************************************************************************/
static void Ctr_EditingCentreConstructor (void)
{
/***** Pointer must be NULL *****/
if (Ctr_EditingCtr != NULL)
Lay_ShowErrorAndExit ("Error initializing centre.");
/***** Allocate memory for centre *****/
if ((Ctr_EditingCtr = (struct Centre *) malloc (sizeof (struct Centre))) == NULL)
Lay_ShowErrorAndExit ("Error allocating memory for centre.");
/***** Reset centre *****/
2019-06-13 10:14:05 +02:00
Ctr_EditingCtr->CtrCod = -1L;
Ctr_EditingCtr->InsCod = -1L;
Ctr_EditingCtr->PlcCod = -1L;
2020-01-05 12:52:03 +01:00
Ctr_EditingCtr->Status = (Ctr_Status_t) 0;
2019-04-06 21:39:35 +02:00
Ctr_EditingCtr->RequesterUsrCod = -1L;
2019-06-13 10:14:05 +02:00
Ctr_EditingCtr->ShrtName[0] = '\0';
Ctr_EditingCtr->FullName[0] = '\0';
Ctr_EditingCtr->WWW[0] = '\0';
Ctr_EditingCtr->Degs.Num = 0;
Ctr_EditingCtr->Degs.Lst = NULL;
2019-04-06 21:39:35 +02:00
}
static void Ctr_EditingCentreDestructor (void)
{
2019-04-07 19:49:53 +02:00
/***** Free memory used for centre *****/
2019-04-06 21:39:35 +02:00
if (Ctr_EditingCtr != NULL)
{
2019-11-06 19:45:20 +01:00
free (Ctr_EditingCtr);
2019-04-06 21:39:35 +02:00
Ctr_EditingCtr = NULL;
}
}