2014-12-01 23:55:08 +01:00
|
|
|
|
// swad_department.c: departments
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
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.
|
2021-02-09 12:43:45 +01:00
|
|
|
|
Copyright (C) 1999-2021 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
|
2014-12-01 23:55:08 +01:00
|
|
|
|
#include <stdlib.h> // For calloc
|
|
|
|
|
#include <string.h> // For string functions
|
|
|
|
|
|
2017-06-10 21:38:10 +02:00
|
|
|
|
#include "swad_box.h"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
#include "swad_constant.h"
|
|
|
|
|
#include "swad_database.h"
|
|
|
|
|
#include "swad_department.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"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
#include "swad_institution.h"
|
2018-12-08 16:43:13 +01:00
|
|
|
|
#include "swad_language.h"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
#include "swad_parameter.h"
|
|
|
|
|
#include "swad_string.h"
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************** External global variables from others modules ****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
extern struct Globals Gbl;
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Private constants *****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************************* Private types *******************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Private variables *****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-04-13 20:50:47 +02:00
|
|
|
|
static struct Dpt_Department *Dpt_EditingDpt = NULL; // Static variable to keep the department being edited
|
2019-04-08 23:34:58 +02:00
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Private prototypes ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-04-13 21:26:47 +02:00
|
|
|
|
static void Dpt_ResetDepartments (struct Dpt_Departments *Departments);
|
|
|
|
|
|
2020-04-13 20:50:47 +02:00
|
|
|
|
static Dpt_Order_t Dpt_GetParamDptOrder (void);
|
2020-04-08 18:18:46 +02:00
|
|
|
|
static void Dpt_PutIconToEditDpts (__attribute__((unused)) void *Args);
|
2020-04-13 21:26:47 +02:00
|
|
|
|
static void Dpt_EditDepartmentsInternal (void);
|
2020-04-13 20:50:47 +02:00
|
|
|
|
|
|
|
|
|
static void Dpt_GetListDepartments (struct Dpt_Departments *Departments,long InsCod);
|
|
|
|
|
|
|
|
|
|
static void Dpt_ListDepartmentsForEdition (const struct Dpt_Departments *Departments);
|
2020-10-14 00:59:24 +02:00
|
|
|
|
static void Dpt_PutParamDptCod (void *DptCod);
|
2017-03-09 11:16:17 +01:00
|
|
|
|
|
2016-10-28 10:03:37 +02:00
|
|
|
|
static void Dpt_RenameDepartment (Cns_ShrtOrFullName_t ShrtOrFullName);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
static bool Dpt_CheckIfDepartmentNameExists (const char *FieldName,const char *Name,long DptCod);
|
2017-03-09 11:16:17 +01:00
|
|
|
|
static void Dpt_UpdateDegNameDB (long DptCod,const char *FieldName,const char *NewDptName);
|
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
static void Dpt_PutFormToCreateDepartment (void);
|
|
|
|
|
static void Dpt_PutHeadDepartments (void);
|
2020-04-13 20:50:47 +02:00
|
|
|
|
static void Dpt_CreateDepartment (struct Dpt_Department *Dpt);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2019-04-08 23:34:58 +02:00
|
|
|
|
static void Dpt_EditingDepartmentConstructor (void);
|
|
|
|
|
static void Dpt_EditingDepartmentDestructor (void);
|
|
|
|
|
|
2020-04-13 20:50:47 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************* Reset departments context *************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-04-13 21:26:47 +02:00
|
|
|
|
static void Dpt_ResetDepartments (struct Dpt_Departments *Departments)
|
2020-04-13 20:50:47 +02:00
|
|
|
|
{
|
|
|
|
|
Departments->Num = 0;
|
|
|
|
|
Departments->Lst = NULL;
|
|
|
|
|
Departments->SelectedOrder = Dpt_ORDER_DEFAULT;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************* List all the departments **************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Dpt_SeeDepts (void)
|
|
|
|
|
{
|
2016-11-28 10:57:34 +01:00
|
|
|
|
extern const char *Hlp_INSTITUTION_Departments;
|
2019-04-08 23:34:58 +02:00
|
|
|
|
extern const char *Txt_Departments_of_INSTITUTION_X;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
extern const char *Txt_DEPARTMENTS_HELP_ORDER[2];
|
|
|
|
|
extern const char *Txt_DEPARTMENTS_ORDER[2];
|
|
|
|
|
extern const char *Txt_Other_departments;
|
|
|
|
|
extern const char *Txt_Department_unspecified;
|
2020-04-13 20:50:47 +02:00
|
|
|
|
struct Dpt_Departments Departments;
|
2017-01-29 12:42:19 +01:00
|
|
|
|
Dpt_Order_t Order;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
unsigned NumDpt;
|
2020-02-14 10:02:58 +01:00
|
|
|
|
unsigned NumTchsInsInOtherDpts;
|
|
|
|
|
unsigned NumTchsInsWithNoDpt;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2019-04-03 20:57:04 +02:00
|
|
|
|
/***** Trivial check *****/
|
|
|
|
|
if (Gbl.Hierarchy.Ins.InsCod <= 0) // No institution selected
|
|
|
|
|
return;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2020-04-13 20:50:47 +02:00
|
|
|
|
/***** Reset departments context *****/
|
|
|
|
|
Dpt_ResetDepartments (&Departments);
|
|
|
|
|
|
2019-04-03 20:57:04 +02:00
|
|
|
|
/***** Get parameter with the type of order in the list of departments *****/
|
2020-04-13 20:50:47 +02:00
|
|
|
|
Departments.SelectedOrder = Dpt_GetParamDptOrder ();
|
2019-04-03 20:57:04 +02:00
|
|
|
|
|
|
|
|
|
/***** Get list of departments *****/
|
2020-04-13 20:50:47 +02:00
|
|
|
|
Dpt_GetListDepartments (&Departments,Gbl.Hierarchy.Ins.InsCod);
|
2019-04-03 20:57:04 +02:00
|
|
|
|
|
2019-10-26 02:19:42 +02:00
|
|
|
|
/***** Begin box and table *****/
|
2020-03-26 02:54:30 +01:00
|
|
|
|
if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)
|
|
|
|
|
Box_BoxTableBegin (NULL,Str_BuildStringStr (Txt_Departments_of_INSTITUTION_X,
|
|
|
|
|
Gbl.Hierarchy.Ins.FullName),
|
2020-04-08 18:18:46 +02:00
|
|
|
|
Dpt_PutIconToEditDpts,NULL,
|
2020-03-26 02:54:30 +01:00
|
|
|
|
Hlp_INSTITUTION_Departments,Box_NOT_CLOSABLE,2);
|
|
|
|
|
else
|
|
|
|
|
Box_BoxTableBegin (NULL,Str_BuildStringStr (Txt_Departments_of_INSTITUTION_X,
|
|
|
|
|
Gbl.Hierarchy.Ins.FullName),
|
|
|
|
|
NULL,NULL,
|
|
|
|
|
Hlp_INSTITUTION_Departments,Box_NOT_CLOSABLE,2);
|
2019-12-30 21:47:07 +01:00
|
|
|
|
Str_FreeString ();
|
2019-04-03 20:57:04 +02:00
|
|
|
|
|
|
|
|
|
/***** Write heading *****/
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TR_Begin (NULL);
|
2019-12-15 01:10:36 +01:00
|
|
|
|
for (Order = Dpt_ORDER_BY_DEPARTMENT;
|
2019-04-03 20:57:04 +02:00
|
|
|
|
Order <= Dpt_ORDER_BY_NUM_TCHS;
|
|
|
|
|
Order++)
|
|
|
|
|
{
|
2020-02-14 10:02:58 +01:00
|
|
|
|
HTM_TH_Begin (1,1,Order == Dpt_ORDER_BY_NUM_TCHS ? "RM" :
|
|
|
|
|
"LM");
|
2019-10-13 15:24:06 +02:00
|
|
|
|
|
2019-04-03 20:57:04 +02:00
|
|
|
|
Frm_StartForm (ActSeeDpt);
|
2019-11-03 13:19:32 +01:00
|
|
|
|
Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) Order);
|
2019-11-20 10:17:42 +01:00
|
|
|
|
HTM_BUTTON_SUBMIT_Begin (Txt_DEPARTMENTS_HELP_ORDER[Order],"BT_LINK TIT_TBL",NULL);
|
2020-04-13 20:50:47 +02:00
|
|
|
|
if (Order == Departments.SelectedOrder)
|
2019-11-10 16:41:47 +01:00
|
|
|
|
HTM_U_Begin ();
|
2019-11-10 12:36:37 +01:00
|
|
|
|
HTM_Txt (Txt_DEPARTMENTS_ORDER[Order]);
|
2020-04-13 20:50:47 +02:00
|
|
|
|
if (Order == Departments.SelectedOrder)
|
2019-11-10 16:41:47 +01:00
|
|
|
|
HTM_U_End ();
|
2019-11-18 11:23:48 +01:00
|
|
|
|
HTM_BUTTON_End ();
|
2019-04-03 20:57:04 +02:00
|
|
|
|
Frm_EndForm ();
|
2019-10-13 15:24:06 +02:00
|
|
|
|
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TH_End ();
|
2019-04-03 20:57:04 +02:00
|
|
|
|
}
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TR_End ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2020-04-13 20:50:47 +02:00
|
|
|
|
/***** Write all the Dpt_GetListDepartmentsdepartments and their nuber of teachers *****/
|
2019-04-03 20:57:04 +02:00
|
|
|
|
for (NumDpt = 0;
|
2020-04-13 20:50:47 +02:00
|
|
|
|
NumDpt < Departments.Num;
|
2019-04-03 20:57:04 +02:00
|
|
|
|
NumDpt++)
|
|
|
|
|
{
|
|
|
|
|
/* Write data of this department */
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TR_Begin (NULL);
|
2019-10-07 08:55:06 +02:00
|
|
|
|
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"LM\"");
|
2019-10-28 20:38:29 +01:00
|
|
|
|
HTM_A_Begin ("href=\"%s\" target=\"_blank\" class=\"DAT\"",
|
2020-04-13 20:50:47 +02:00
|
|
|
|
Departments.Lst[NumDpt].WWW);
|
|
|
|
|
HTM_Txt (Departments.Lst[NumDpt].FullName);
|
2019-10-28 13:56:04 +01:00
|
|
|
|
HTM_A_End ();
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_End ();
|
2019-10-07 08:55:06 +02:00
|
|
|
|
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"DAT RM\"");
|
2020-04-13 20:50:47 +02:00
|
|
|
|
HTM_Unsigned (Departments.Lst[NumDpt].NumTchs);
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_End ();
|
2019-10-07 08:55:06 +02:00
|
|
|
|
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TR_End ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
2019-04-03 20:57:04 +02:00
|
|
|
|
|
|
|
|
|
/***** Separation row *****/
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TR_Begin (NULL);
|
|
|
|
|
HTM_TD_Begin ("colspan=\"3\" class=\"DAT\"");
|
2019-11-14 08:59:11 +01:00
|
|
|
|
HTM_NBSP ();
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
HTM_TR_End ();
|
2019-04-03 20:57:04 +02:00
|
|
|
|
|
2020-02-14 10:02:58 +01:00
|
|
|
|
/***** Write teachers of this institution with other department *****/
|
|
|
|
|
NumTchsInsInOtherDpts = Usr_GetNumTchsCurrentInsInDepartment (0);
|
|
|
|
|
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TR_Begin (NULL);
|
2019-10-07 08:55:06 +02:00
|
|
|
|
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"DAT LM\"");
|
2019-11-10 12:36:37 +01:00
|
|
|
|
HTM_Txt (Txt_Other_departments);
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_End ();
|
2019-10-07 08:55:06 +02:00
|
|
|
|
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"DAT RM\"");
|
2020-02-14 10:02:58 +01:00
|
|
|
|
HTM_Unsigned (NumTchsInsInOtherDpts);
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_End ();
|
2019-10-07 08:55:06 +02:00
|
|
|
|
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TR_End ();
|
2019-04-03 20:57:04 +02:00
|
|
|
|
|
|
|
|
|
/***** Write teachers with no department *****/
|
2020-02-14 10:02:58 +01:00
|
|
|
|
NumTchsInsWithNoDpt = Usr_GetNumTchsCurrentInsInDepartment (-1L);
|
|
|
|
|
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TR_Begin (NULL);
|
2019-10-07 08:55:06 +02:00
|
|
|
|
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"DAT LM\"");
|
2019-11-10 12:36:37 +01:00
|
|
|
|
HTM_Txt (Txt_Department_unspecified);
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_End ();
|
2019-10-07 08:55:06 +02:00
|
|
|
|
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"DAT RM\"");
|
2020-02-14 10:02:58 +01:00
|
|
|
|
HTM_Unsigned (NumTchsInsWithNoDpt);
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_End ();
|
2019-10-07 08:55:06 +02:00
|
|
|
|
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TR_End ();
|
2019-04-03 20:57:04 +02:00
|
|
|
|
|
|
|
|
|
/***** End table and box *****/
|
2019-11-25 23:18:08 +01:00
|
|
|
|
Box_BoxTableEnd ();
|
2019-04-03 20:57:04 +02:00
|
|
|
|
|
|
|
|
|
/***** Free list of departments *****/
|
2020-04-13 20:50:47 +02:00
|
|
|
|
Dpt_FreeListDepartments (&Departments);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******** Get parameter with the type or order in list of departments ********/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-04-13 20:50:47 +02:00
|
|
|
|
static Dpt_Order_t Dpt_GetParamDptOrder (void)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2020-04-13 20:50:47 +02:00
|
|
|
|
return (Dpt_Order_t) Par_GetParToUnsignedLong ("Order",
|
|
|
|
|
0,
|
|
|
|
|
Dpt_NUM_ORDERS - 1,
|
|
|
|
|
(unsigned long) Dpt_ORDER_DEFAULT);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2016-03-16 22:46:38 +01:00
|
|
|
|
/************************ Put icon to edit departments ***********************/
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-04-08 18:18:46 +02:00
|
|
|
|
static void Dpt_PutIconToEditDpts (__attribute__((unused)) void *Args)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2020-04-08 18:18:46 +02:00
|
|
|
|
Ico_PutContextualIconToEdit (ActEdiDpt,NULL,
|
|
|
|
|
NULL,NULL);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******* Put forms to edit the departments of the current institution ********/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Dpt_EditDepartments (void)
|
|
|
|
|
{
|
2019-04-08 23:34:58 +02:00
|
|
|
|
/***** Department constructor *****/
|
|
|
|
|
Dpt_EditingDepartmentConstructor ();
|
|
|
|
|
|
|
|
|
|
/***** Edit departments *****/
|
2020-04-13 21:26:47 +02:00
|
|
|
|
Dpt_EditDepartmentsInternal ();
|
2019-04-08 23:34:58 +02:00
|
|
|
|
|
|
|
|
|
/***** Department destructor *****/
|
|
|
|
|
Dpt_EditingDepartmentDestructor ();
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-13 21:26:47 +02:00
|
|
|
|
static void Dpt_EditDepartmentsInternal (void)
|
2019-04-08 23:34:58 +02:00
|
|
|
|
{
|
|
|
|
|
extern const char *Hlp_INSTITUTION_Departments_edit;
|
|
|
|
|
extern const char *Txt_Departments_of_INSTITUTION_X;
|
2020-04-13 21:26:47 +02:00
|
|
|
|
struct Dpt_Departments Departments;
|
2019-04-08 23:34:58 +02:00
|
|
|
|
|
2019-04-03 20:57:04 +02:00
|
|
|
|
/***** Trivial check *****/
|
2019-04-08 23:34:58 +02:00
|
|
|
|
if (Gbl.Hierarchy.Ins.InsCod <= 0) // An institution must be selected
|
2019-04-03 20:57:04 +02:00
|
|
|
|
return;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2020-04-13 21:26:47 +02:00
|
|
|
|
/***** Reset departments context *****/
|
|
|
|
|
Dpt_ResetDepartments (&Departments);
|
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/***** Get list of institutions *****/
|
2020-01-07 22:07:06 +01:00
|
|
|
|
Ins_GetBasicListOfInstitutions (Gbl.Hierarchy.Cty.CtyCod);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Get list of departments *****/
|
2020-04-13 21:26:47 +02:00
|
|
|
|
Dpt_GetListDepartments (&Departments,Gbl.Hierarchy.Ins.InsCod);
|
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_Departments_of_INSTITUTION_X,
|
2020-03-26 02:54:30 +01:00
|
|
|
|
Gbl.Hierarchy.Ins.FullName),
|
|
|
|
|
NULL,NULL,
|
2019-04-08 23:34:58 +02:00
|
|
|
|
Hlp_INSTITUTION_Departments_edit,Box_NOT_CLOSABLE);
|
2019-12-30 21:47:07 +01:00
|
|
|
|
Str_FreeString ();
|
2019-04-08 23:34:58 +02:00
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/***** Put a form to create a new department *****/
|
|
|
|
|
Dpt_PutFormToCreateDepartment ();
|
|
|
|
|
|
|
|
|
|
/***** Forms to edit current departments *****/
|
2020-04-13 21:26:47 +02:00
|
|
|
|
if (Departments.Num)
|
|
|
|
|
Dpt_ListDepartmentsForEdition (&Departments);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2019-04-08 23:34:58 +02:00
|
|
|
|
/***** End box *****/
|
2019-10-25 22:48:34 +02:00
|
|
|
|
Box_BoxEnd ();
|
2019-04-08 23:34:58 +02:00
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/***** Free list of departments *****/
|
2020-04-13 21:26:47 +02:00
|
|
|
|
Dpt_FreeListDepartments (&Departments);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Free list of institutions *****/
|
|
|
|
|
Ins_FreeListInstitutions ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************** Get list of departments **************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
// If InsCod > 0 ==> get departments of an institution
|
2017-10-10 10:46:35 +02:00
|
|
|
|
// If InsCod <= 0 ==> an empty list is returned
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2020-04-13 20:50:47 +02:00
|
|
|
|
static void Dpt_GetListDepartments (struct Dpt_Departments *Departments,long InsCod)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2019-01-03 15:25:18 +01:00
|
|
|
|
static const char *OrderBySubQuery[Dpt_NUM_ORDERS] =
|
|
|
|
|
{
|
2019-11-21 00:40:35 +01:00
|
|
|
|
[Dpt_ORDER_BY_DEPARTMENT] = "FullName",
|
|
|
|
|
[Dpt_ORDER_BY_NUM_TCHS ] = "NumTchs 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 NumDpt;
|
2020-04-13 20:50:47 +02:00
|
|
|
|
struct Dpt_Department *Dpt;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2017-10-10 10:46:35 +02:00
|
|
|
|
/***** Free list of departments *****/
|
2020-04-13 20:50:47 +02:00
|
|
|
|
Dpt_FreeListDepartments (Departments); // List is initialized to empty
|
2017-10-10 10:46:35 +02:00
|
|
|
|
|
|
|
|
|
if (InsCod > 0) // Institution specified
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2017-10-10 10:46:35 +02:00
|
|
|
|
/***** Get departments from database *****/
|
2020-04-13 20:50:47 +02:00
|
|
|
|
Departments->Num = (unsigned)
|
|
|
|
|
DB_QuerySELECT (&mysql_res,"can not get departments",
|
|
|
|
|
"(SELECT departments.DptCod," // row[0]
|
|
|
|
|
"departments.InsCod," // row[1]
|
|
|
|
|
"departments.ShortName," // row[2]
|
|
|
|
|
"departments.FullName," // row[3]
|
|
|
|
|
"departments.WWW," // row[4]
|
|
|
|
|
"COUNT(DISTINCT usr_data.UsrCod) AS NumTchs" // row[5]
|
|
|
|
|
" FROM departments,usr_data,crs_usr"
|
|
|
|
|
" WHERE departments.InsCod=%ld"
|
|
|
|
|
" AND departments.DptCod=usr_data.DptCod"
|
|
|
|
|
" AND usr_data.UsrCod=crs_usr.UsrCod"
|
|
|
|
|
" AND crs_usr.Role IN (%u,%u)"
|
|
|
|
|
" GROUP BY departments.DptCod)"
|
|
|
|
|
" UNION "
|
|
|
|
|
"(SELECT DptCod," // row[0]
|
|
|
|
|
"InsCod," // row[1]
|
|
|
|
|
"ShortName," // row[2]
|
|
|
|
|
"FullName," // row[3]
|
|
|
|
|
"WWW," // row[4]
|
|
|
|
|
"0 AS NumTchs" // row[5]
|
|
|
|
|
" FROM departments"
|
|
|
|
|
" WHERE InsCod=%ld AND DptCod NOT IN"
|
|
|
|
|
" (SELECT DISTINCT usr_data.DptCod"
|
|
|
|
|
" FROM usr_data,crs_usr"
|
|
|
|
|
" WHERE crs_usr.Role IN (%u,%u)"
|
|
|
|
|
" AND crs_usr.UsrCod=usr_data.UsrCod))"
|
|
|
|
|
" ORDER BY %s",
|
|
|
|
|
InsCod,(unsigned) Rol_NET,(unsigned) Rol_TCH,
|
|
|
|
|
InsCod,(unsigned) Rol_NET,(unsigned) Rol_TCH,
|
|
|
|
|
OrderBySubQuery[Departments->SelectedOrder]);
|
|
|
|
|
if (Departments->Num) // Departments found...
|
2017-10-10 10:46:35 +02:00
|
|
|
|
{
|
|
|
|
|
/***** Create list with courses in degree *****/
|
2021-02-15 16:25:55 +01:00
|
|
|
|
if ((Departments->Lst = calloc (Departments->Num,
|
|
|
|
|
sizeof (*Departments->Lst))) == NULL)
|
2018-10-18 20:06:54 +02:00
|
|
|
|
Lay_NotEnoughMemoryExit ();
|
2017-10-10 10:46:35 +02:00
|
|
|
|
|
|
|
|
|
/***** Get the departments *****/
|
|
|
|
|
for (NumDpt = 0;
|
2020-04-13 20:50:47 +02:00
|
|
|
|
NumDpt < Departments->Num;
|
2017-10-10 10:46:35 +02:00
|
|
|
|
NumDpt++)
|
|
|
|
|
{
|
2020-04-13 20:50:47 +02:00
|
|
|
|
Dpt = &(Departments->Lst[NumDpt]);
|
2017-10-10 10:46:35 +02:00
|
|
|
|
|
|
|
|
|
/* Get next department */
|
|
|
|
|
row = mysql_fetch_row (mysql_res);
|
|
|
|
|
|
|
|
|
|
/* Get department code (row[0]) */
|
|
|
|
|
if ((Dpt->DptCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
|
|
|
|
|
Lay_ShowErrorAndExit ("Wrong code of department.");
|
|
|
|
|
|
|
|
|
|
/* Get institution code (row[1]) */
|
|
|
|
|
if ((Dpt->InsCod = Str_ConvertStrCodToLongCod (row[1])) < 0)
|
|
|
|
|
Lay_ShowErrorAndExit ("Wrong code of institution.");
|
|
|
|
|
|
2021-02-15 22:49:44 +01:00
|
|
|
|
/* Get short name (row[2]), full name (row[3])
|
|
|
|
|
and URL (row[4]) of the department */
|
2021-02-15 16:25:55 +01:00
|
|
|
|
Str_Copy (Dpt->ShrtName,row[2],sizeof (Dpt->ShrtName) - 1);
|
|
|
|
|
Str_Copy (Dpt->FullName,row[3],sizeof (Dpt->FullName) - 1);
|
2021-02-15 22:49:44 +01:00
|
|
|
|
Str_Copy (Dpt->WWW ,row[4],sizeof (Dpt->WWW ) - 1);
|
2017-10-10 10:46:35 +02:00
|
|
|
|
|
|
|
|
|
/* Get number of non-editing teachers and teachers in this department (row[5]) */
|
|
|
|
|
if (sscanf (row[5],"%u",&Dpt->NumTchs) != 1)
|
|
|
|
|
Dpt->NumTchs = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2017-10-10 10:46:35 +02:00
|
|
|
|
/***** Free structure that stores the query result *****/
|
|
|
|
|
DB_FreeMySQLResult (&mysql_res);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************** Get department full name *************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-04-13 20:50:47 +02:00
|
|
|
|
void Dpt_GetDataOfDepartmentByCod (struct Dpt_Department *Dpt)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_Another_department;
|
|
|
|
|
MYSQL_RES *mysql_res;
|
|
|
|
|
MYSQL_ROW row;
|
|
|
|
|
unsigned long NumRows;
|
|
|
|
|
|
|
|
|
|
/***** Clear data *****/
|
|
|
|
|
Dpt->InsCod = -1L;
|
2016-10-28 10:03:37 +02:00
|
|
|
|
Dpt->ShrtName[0] = Dpt->FullName[0] = Dpt->WWW[0] = '\0';
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Dpt->NumTchs = 0;
|
|
|
|
|
|
|
|
|
|
/***** Check if department code is correct *****/
|
|
|
|
|
if (Dpt->DptCod == 0)
|
|
|
|
|
{
|
2021-02-15 16:25:55 +01:00
|
|
|
|
Str_Copy (Dpt->ShrtName,Txt_Another_department,sizeof (Dpt->ShrtName) - 1);
|
|
|
|
|
Str_Copy (Dpt->FullName,Txt_Another_department,sizeof (Dpt->FullName) - 1);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
else if (Dpt->DptCod > 0)
|
|
|
|
|
{
|
|
|
|
|
/***** Get data of a department from database *****/
|
2018-10-30 17:47:57 +01:00
|
|
|
|
NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a department",
|
|
|
|
|
"(SELECT departments.InsCod,departments.ShortName,departments.FullName,departments.WWW,"
|
|
|
|
|
"COUNT(DISTINCT usr_data.UsrCod) AS NumTchs"
|
|
|
|
|
" FROM departments,usr_data,crs_usr"
|
|
|
|
|
" WHERE departments.DptCod=%ld"
|
|
|
|
|
" AND departments.DptCod=usr_data.DptCod"
|
|
|
|
|
" AND usr_data.UsrCod=crs_usr.UsrCod"
|
|
|
|
|
" AND crs_usr.Role=%u"
|
|
|
|
|
" GROUP BY departments.DptCod)"
|
|
|
|
|
" UNION "
|
|
|
|
|
"(SELECT InsCod,ShortName,FullName,WWW,0"
|
|
|
|
|
" FROM departments"
|
|
|
|
|
" WHERE DptCod=%ld AND DptCod NOT IN"
|
|
|
|
|
" (SELECT DISTINCT usr_data.DptCod FROM usr_data,crs_usr"
|
|
|
|
|
" WHERE crs_usr.Role=%u AND crs_usr.UsrCod=usr_data.UsrCod))",
|
|
|
|
|
Dpt->DptCod,(unsigned) Rol_TCH,
|
|
|
|
|
Dpt->DptCod,(unsigned) Rol_TCH);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
if (NumRows) // Department found...
|
|
|
|
|
{
|
|
|
|
|
/* Get row */
|
|
|
|
|
row = mysql_fetch_row (mysql_res);
|
|
|
|
|
|
|
|
|
|
/* Get the code of the institution (row[0]) */
|
|
|
|
|
Dpt->InsCod = Str_ConvertStrCodToLongCod (row[0]);
|
|
|
|
|
|
2021-02-15 22:49:44 +01:00
|
|
|
|
/* Get short name (row[1]), full name (row[2])
|
|
|
|
|
and URL (row[3]) of the department */
|
2021-02-15 16:25:55 +01:00
|
|
|
|
Str_Copy (Dpt->ShrtName,row[1],sizeof (Dpt->ShrtName) - 1);
|
|
|
|
|
Str_Copy (Dpt->FullName,row[2],sizeof (Dpt->FullName) - 1);
|
2021-02-15 22:49:44 +01:00
|
|
|
|
Str_Copy (Dpt->WWW ,row[3],sizeof (Dpt->WWW ) - 1);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/* Get number of teachers in this department (row[4]) */
|
|
|
|
|
if (sscanf (row[4],"%u",&Dpt->NumTchs) != 1)
|
|
|
|
|
Dpt->NumTchs = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** Free structure that stores the query result *****/
|
|
|
|
|
DB_FreeMySQLResult (&mysql_res);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************** Free list of departments *************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-04-13 20:50:47 +02:00
|
|
|
|
void Dpt_FreeListDepartments (struct Dpt_Departments *Departments)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2020-04-13 20:50:47 +02:00
|
|
|
|
if (Departments->Lst)
|
2017-10-10 10:46:35 +02:00
|
|
|
|
/***** Free memory used by the list of departments *****/
|
2020-04-13 20:50:47 +02:00
|
|
|
|
free (Departments->Lst);
|
2017-10-10 10:46:35 +02:00
|
|
|
|
|
2020-04-13 20:50:47 +02:00
|
|
|
|
Departments->Lst = NULL;
|
|
|
|
|
Departments->Num = 0;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************** Get number of departments in an institution ******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
unsigned Dpt_GetNumDepartmentsInInstitution (long InsCod)
|
|
|
|
|
{
|
|
|
|
|
/***** Get number of departments in an institution from database *****/
|
2018-11-03 15:33:20 +01:00
|
|
|
|
return
|
|
|
|
|
(unsigned) DB_QueryCOUNT ("can not get number of departments"
|
|
|
|
|
" in an institution",
|
|
|
|
|
"SELECT COUNT(*) FROM departments"
|
|
|
|
|
" WHERE InsCod=%ld",
|
|
|
|
|
InsCod);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************** List all the departments *************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-04-13 20:50:47 +02:00
|
|
|
|
static void Dpt_ListDepartmentsForEdition (const struct Dpt_Departments *Departments)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_Another_institution;
|
|
|
|
|
unsigned NumDpt;
|
2020-04-13 20:50:47 +02:00
|
|
|
|
struct Dpt_Department *Dpt;
|
2021-02-11 00:58:53 +01:00
|
|
|
|
struct Ins_Instit Ins;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
unsigned NumIns;
|
|
|
|
|
|
2019-10-20 22:00:28 +02:00
|
|
|
|
/***** Begin table *****/
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TABLE_BeginPadding (2);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2017-06-12 14:16:33 +02:00
|
|
|
|
/***** Write heading *****/
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Dpt_PutHeadDepartments ();
|
|
|
|
|
|
|
|
|
|
/***** Write all the departments *****/
|
|
|
|
|
for (NumDpt = 0;
|
2020-04-13 20:50:47 +02:00
|
|
|
|
NumDpt < Departments->Num;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
NumDpt++)
|
|
|
|
|
{
|
2020-04-13 20:50:47 +02:00
|
|
|
|
Dpt = &Departments->Lst[NumDpt];
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/* Get data of institution of this department */
|
|
|
|
|
Ins.InsCod = Dpt->InsCod;
|
2020-01-07 00:09:30 +01:00
|
|
|
|
Ins_GetDataOfInstitutionByCod (&Ins);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TR_Begin (NULL);
|
2019-10-08 22:33:19 +02:00
|
|
|
|
|
|
|
|
|
/* Put icon to remove department */
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"BM\"");
|
2014-12-01 23:55:08 +01:00
|
|
|
|
if (Dpt->NumTchs) // Department has teachers ==> deletion forbidden
|
2017-06-11 19:13:28 +02:00
|
|
|
|
Ico_PutIconRemovalNotAllowed ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
else
|
2020-10-14 00:59:24 +02:00
|
|
|
|
Ico_PutContextualIconToRemove (ActRemDpt,NULL,
|
|
|
|
|
Dpt_PutParamDptCod,&Dpt->DptCod);
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_End ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/* Department code */
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"DAT RM\"");
|
2019-11-11 00:15:44 +01:00
|
|
|
|
HTM_TxtF ("%ld ",Dpt->DptCod);
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_End ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/* Institution */
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"CM\"");
|
2018-11-09 20:47:39 +01:00
|
|
|
|
Frm_StartForm (ActChgDptIns);
|
2020-10-14 00:59:24 +02:00
|
|
|
|
Dpt_PutParamDptCod (&Dpt->DptCod);
|
2020-04-27 03:16:55 +02:00
|
|
|
|
HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE,
|
2019-11-05 15:47:35 +01:00
|
|
|
|
"name=\"OthInsCod\" class=\"HIE_SEL_NARROW\"");
|
2019-11-06 19:45:20 +01:00
|
|
|
|
HTM_OPTION (HTM_Type_STRING,"0",Dpt->InsCod == 0,false,
|
|
|
|
|
"%s",Txt_Another_institution);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
for (NumIns = 0;
|
2020-01-08 14:04:25 +01:00
|
|
|
|
NumIns < Gbl.Hierarchy.Inss.Num;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
NumIns++)
|
2020-01-08 14:04:25 +01:00
|
|
|
|
HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Inss.Lst[NumIns].InsCod,
|
|
|
|
|
Gbl.Hierarchy.Inss.Lst[NumIns].InsCod == Dpt->InsCod,false,
|
|
|
|
|
"%s",Gbl.Hierarchy.Inss.Lst[NumIns].ShrtName);
|
2019-11-05 08:46:38 +01:00
|
|
|
|
HTM_SELECT_End ();
|
2018-11-09 20:47:39 +01:00
|
|
|
|
Frm_EndForm ();
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_End ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/* Department short name */
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"CM\"");
|
2018-11-09 20:47:39 +01:00
|
|
|
|
Frm_StartForm (ActRenDptSho);
|
2020-10-14 00:59:24 +02:00
|
|
|
|
Dpt_PutParamDptCod (&Dpt->DptCod);
|
2021-02-11 22:57:09 +01:00
|
|
|
|
HTM_INPUT_TEXT ("ShortName",Cns_HIERARCHY_MAX_CHARS_SHRT_NAME,Dpt->ShrtName,
|
2020-04-27 03:16:55 +02:00
|
|
|
|
HTM_SUBMIT_ON_CHANGE,
|
2019-11-04 12:25:48 +01:00
|
|
|
|
"class=\"INPUT_SHORT_NAME\"");
|
2018-11-09 20:47:39 +01:00
|
|
|
|
Frm_EndForm ();
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_End ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/* Department full name */
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"CM\"");
|
2018-11-09 20:47:39 +01:00
|
|
|
|
Frm_StartForm (ActRenDptFul);
|
2020-10-14 00:59:24 +02:00
|
|
|
|
Dpt_PutParamDptCod (&Dpt->DptCod);
|
2021-02-11 22:57:09 +01:00
|
|
|
|
HTM_INPUT_TEXT ("FullName",Cns_HIERARCHY_MAX_CHARS_FULL_NAME,Dpt->FullName,
|
2020-04-27 03:16:55 +02:00
|
|
|
|
HTM_SUBMIT_ON_CHANGE,
|
2019-11-04 12:25:48 +01:00
|
|
|
|
"class=\"INPUT_FULL_NAME\"");
|
2018-11-09 20:47:39 +01:00
|
|
|
|
Frm_EndForm ();
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_End ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/* Department WWW */
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"CM\"");
|
2018-11-09 20:47:39 +01:00
|
|
|
|
Frm_StartForm (ActChgDptWWW);
|
2020-10-14 00:59:24 +02:00
|
|
|
|
Dpt_PutParamDptCod (&Dpt->DptCod);
|
2020-04-27 03:16:55 +02:00
|
|
|
|
HTM_INPUT_URL ("WWW",Dpt->WWW,HTM_SUBMIT_ON_CHANGE,
|
2019-12-19 11:00:14 +01:00
|
|
|
|
"class=\"INPUT_WWW_NARROW\" required=\"required\"");
|
2018-11-09 20:47:39 +01:00
|
|
|
|
Frm_EndForm ();
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_End ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/* Number of teachers */
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"DAT RM\"");
|
2019-11-10 13:31:47 +01:00
|
|
|
|
HTM_Unsigned (Dpt->NumTchs);
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_End ();
|
2019-10-07 08:55:06 +02:00
|
|
|
|
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TR_End ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-08 23:34:58 +02:00
|
|
|
|
/***** End table *****/
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TABLE_End ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****************** Write parameter with code of department ******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-10-14 00:59:24 +02:00
|
|
|
|
static void Dpt_PutParamDptCod (void *DptCod)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2020-10-14 00:59:24 +02:00
|
|
|
|
if (DptCod)
|
|
|
|
|
Par_PutHiddenParamLong (NULL,Dpt_PARAM_DPT_COD_NAME,*((long *) DptCod));
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2017-05-31 21:05:59 +02:00
|
|
|
|
/******************* Get parameter with code of department *******************/
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2017-05-31 21:05:59 +02:00
|
|
|
|
long Dpt_GetAndCheckParamDptCod (long MinCodAllowed)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2017-05-31 21:05:59 +02:00
|
|
|
|
long DptCod;
|
|
|
|
|
|
|
|
|
|
/***** Get and check parameter with code of department *****/
|
2017-10-10 12:37:09 +02:00
|
|
|
|
if ((DptCod = Par_GetParToLong (Dpt_PARAM_DPT_COD_NAME)) < MinCodAllowed)
|
2017-05-31 21:05:59 +02:00
|
|
|
|
Lay_ShowErrorAndExit ("Code of department is missing or invalid.");
|
|
|
|
|
|
|
|
|
|
return DptCod;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Remove a department ***************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Dpt_RemoveDepartment (void)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_To_remove_a_department_you_must_first_remove_all_teachers_in_the_department;
|
|
|
|
|
extern const char *Txt_Department_X_removed;
|
2019-04-08 23:34:58 +02:00
|
|
|
|
|
|
|
|
|
/***** Department constructor *****/
|
|
|
|
|
Dpt_EditingDepartmentConstructor ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Get department code *****/
|
2019-04-08 23:34:58 +02:00
|
|
|
|
Dpt_EditingDpt->DptCod = Dpt_GetAndCheckParamDptCod (1);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Get data of the department from database *****/
|
2019-04-08 23:34:58 +02:00
|
|
|
|
Dpt_GetDataOfDepartmentByCod (Dpt_EditingDpt);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Check if this department has teachers *****/
|
2019-04-08 23:34:58 +02:00
|
|
|
|
if (Dpt_EditingDpt->NumTchs) // Department has teachers ==> don't remove
|
|
|
|
|
Ale_CreateAlert (Ale_WARNING,NULL,
|
|
|
|
|
Txt_To_remove_a_department_you_must_first_remove_all_teachers_in_the_department);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
else // Department has no teachers ==> remove it
|
|
|
|
|
{
|
|
|
|
|
/***** Remove department *****/
|
2018-11-02 22:00:31 +01:00
|
|
|
|
DB_QueryDELETE ("can not remove a department",
|
|
|
|
|
"DELETE FROM departments WHERE DptCod=%ld",
|
2019-04-08 23:34:58 +02:00
|
|
|
|
Dpt_EditingDpt->DptCod);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Write message to show the change made *****/
|
2019-04-08 23:34:58 +02:00
|
|
|
|
Ale_CreateAlert (Ale_SUCCESS,NULL,
|
|
|
|
|
Txt_Department_X_removed,
|
|
|
|
|
Dpt_EditingDpt->FullName);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****************** Change the institution of a department *******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Dpt_ChangeDepartIns (void)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_The_institution_of_the_department_has_changed;
|
2019-04-08 23:34:58 +02:00
|
|
|
|
long NewInsCod;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2019-04-08 23:34:58 +02:00
|
|
|
|
/***** Department constructor *****/
|
|
|
|
|
Dpt_EditingDepartmentConstructor ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Get parameters from form *****/
|
|
|
|
|
/* Get the code of the department */
|
2019-04-08 23:34:58 +02:00
|
|
|
|
Dpt_EditingDpt->DptCod = Dpt_GetAndCheckParamDptCod (1);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/* Get parameter with institution code */
|
2019-04-08 23:34:58 +02:00
|
|
|
|
NewInsCod = Ins_GetAndCheckParamOtherInsCod (1);
|
|
|
|
|
|
|
|
|
|
/***** Get data of the department from database *****/
|
|
|
|
|
Dpt_GetDataOfDepartmentByCod (Dpt_EditingDpt);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Update institution in table of departments *****/
|
2018-11-03 12:16:40 +01:00
|
|
|
|
DB_QueryUPDATE ("can not update the institution of a department",
|
|
|
|
|
"UPDATE departments SET InsCod=%ld WHERE DptCod=%ld",
|
2019-04-08 23:34:58 +02:00
|
|
|
|
NewInsCod,Dpt_EditingDpt->DptCod);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Write message to show the change made *****/
|
2019-04-08 23:34:58 +02:00
|
|
|
|
Ale_CreateAlert (Ale_SUCCESS,NULL,
|
|
|
|
|
Txt_The_institution_of_the_department_has_changed);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************* Change the short name of a department *******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Dpt_RenameDepartShort (void)
|
|
|
|
|
{
|
2019-04-08 23:34:58 +02:00
|
|
|
|
/***** Department constructor *****/
|
|
|
|
|
Dpt_EditingDepartmentConstructor ();
|
|
|
|
|
|
|
|
|
|
/***** Rename department *****/
|
2016-10-28 10:03:37 +02:00
|
|
|
|
Dpt_RenameDepartment (Cns_SHRT_NAME);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************* Change the full name of a department ********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Dpt_RenameDepartFull (void)
|
|
|
|
|
{
|
2019-04-08 23:34:58 +02:00
|
|
|
|
/***** Department constructor *****/
|
|
|
|
|
Dpt_EditingDepartmentConstructor ();
|
|
|
|
|
|
|
|
|
|
/***** Rename department *****/
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Dpt_RenameDepartment (Cns_FULL_NAME);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************ Change the name of a degree ************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2016-10-28 10:03:37 +02:00
|
|
|
|
static void Dpt_RenameDepartment (Cns_ShrtOrFullName_t ShrtOrFullName)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_The_department_X_already_exists;
|
|
|
|
|
extern const char *Txt_The_department_X_has_been_renamed_as_Y;
|
|
|
|
|
extern const char *Txt_The_name_of_the_department_X_has_not_changed;
|
|
|
|
|
const char *ParamName = NULL; // Initialized to avoid warning
|
|
|
|
|
const char *FieldName = NULL; // Initialized to avoid warning
|
2017-03-07 11:03:05 +01:00
|
|
|
|
size_t MaxBytes = 0; // Initialized to avoid warning
|
2014-12-01 23:55:08 +01:00
|
|
|
|
char *CurrentDptName = NULL; // Initialized to avoid warning
|
2021-02-11 22:57:09 +01:00
|
|
|
|
char NewDptName[Cns_HIERARCHY_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";
|
2021-02-11 22:57:09 +01:00
|
|
|
|
MaxBytes = Cns_HIERARCHY_MAX_BYTES_SHRT_NAME;
|
2019-04-08 23:34:58 +02:00
|
|
|
|
CurrentDptName = Dpt_EditingDpt->ShrtName;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
break;
|
|
|
|
|
case Cns_FULL_NAME:
|
|
|
|
|
ParamName = "FullName";
|
|
|
|
|
FieldName = "FullName";
|
2021-02-11 22:57:09 +01:00
|
|
|
|
MaxBytes = Cns_HIERARCHY_MAX_BYTES_FULL_NAME;
|
2019-04-08 23:34:58 +02:00
|
|
|
|
CurrentDptName = Dpt_EditingDpt->FullName;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** Get parameters from form *****/
|
|
|
|
|
/* Get the code of the department */
|
2019-04-08 23:34:58 +02:00
|
|
|
|
Dpt_EditingDpt->DptCod = Dpt_GetAndCheckParamDptCod (1);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/* Get the new name for the department */
|
2017-03-07 11:03:05 +01:00
|
|
|
|
Par_GetParToText (ParamName,NewDptName,MaxBytes);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Get from the database the old names of the department *****/
|
2019-04-08 23:34:58 +02:00
|
|
|
|
Dpt_GetDataOfDepartmentByCod (Dpt_EditingDpt);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Check if new name is empty *****/
|
2019-12-20 00:30:54 +01:00
|
|
|
|
if (NewDptName[0])
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
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 (CurrentDptName,NewDptName)) // Different names
|
|
|
|
|
{
|
|
|
|
|
/***** If degree was in database... *****/
|
2019-04-08 23:34:58 +02:00
|
|
|
|
if (Dpt_CheckIfDepartmentNameExists (ParamName,NewDptName,Dpt_EditingDpt->DptCod))
|
|
|
|
|
Ale_CreateAlert (Ale_WARNING,NULL,
|
|
|
|
|
Txt_The_department_X_already_exists,
|
|
|
|
|
NewDptName);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Update the table changing old name by new name */
|
2019-04-08 23:34:58 +02:00
|
|
|
|
Dpt_UpdateDegNameDB (Dpt_EditingDpt->DptCod,FieldName,NewDptName);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2017-03-09 11:16:17 +01:00
|
|
|
|
/* Write message to show the change made */
|
2019-04-08 23:34:58 +02:00
|
|
|
|
Ale_CreateAlert (Ale_SUCCESS,NULL,
|
|
|
|
|
Txt_The_department_X_has_been_renamed_as_Y,
|
|
|
|
|
CurrentDptName,NewDptName);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else // The same name
|
2019-04-08 23:34:58 +02:00
|
|
|
|
Ale_CreateAlert (Ale_INFO,NULL,
|
|
|
|
|
Txt_The_name_of_the_department_X_has_not_changed,
|
|
|
|
|
CurrentDptName);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
2019-12-20 00:30:54 +01:00
|
|
|
|
else
|
|
|
|
|
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2019-04-08 23:34:58 +02:00
|
|
|
|
/***** Update name *****/
|
2021-02-15 16:25:55 +01:00
|
|
|
|
Str_Copy (CurrentDptName,NewDptName,MaxBytes);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************* Check if the name of department exists ******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static bool Dpt_CheckIfDepartmentNameExists (const char *FieldName,const char *Name,long DptCod)
|
|
|
|
|
{
|
|
|
|
|
/***** Get number of departments with a name from database *****/
|
2018-11-03 15:33:20 +01:00
|
|
|
|
return (DB_QueryCOUNT ("can not check if the name"
|
|
|
|
|
" of a department already existed",
|
|
|
|
|
"SELECT COUNT(*) FROM departments"
|
|
|
|
|
" WHERE %s='%s' AND DptCod<>%ld",
|
|
|
|
|
FieldName,Name,DptCod) != 0);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-09 11:16:17 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************* Update department name in table of departments ****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void Dpt_UpdateDegNameDB (long DptCod,const char *FieldName,const char *NewDptName)
|
|
|
|
|
{
|
|
|
|
|
/***** Update department changing old name by new name *****/
|
2018-11-03 12:16:40 +01:00
|
|
|
|
DB_QueryUPDATE ("can not update the name of a department",
|
|
|
|
|
"UPDATE departments SET %s='%s' WHERE DptCod=%ld",
|
|
|
|
|
FieldName,NewDptName,DptCod);
|
2017-03-09 11:16:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/******************************************************************************/
|
|
|
|
|
/*********************** Change the URL of a department *********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Dpt_ChangeDptWWW (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-08 23:34:58 +02:00
|
|
|
|
/***** Department constructor *****/
|
|
|
|
|
Dpt_EditingDepartmentConstructor ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Get parameters from form *****/
|
|
|
|
|
/* Get the code of the department */
|
2019-04-08 23:34:58 +02:00
|
|
|
|
Dpt_EditingDpt->DptCod = Dpt_GetAndCheckParamDptCod (1);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/* Get the new WWW for the department */
|
2017-03-07 01:56:41 +01:00
|
|
|
|
Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2019-04-08 23:34:58 +02:00
|
|
|
|
/***** Get data of the department from database *****/
|
|
|
|
|
Dpt_GetDataOfDepartmentByCod (Dpt_EditingDpt);
|
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/***** Check if new WWW is empty *****/
|
|
|
|
|
if (NewWWW[0])
|
|
|
|
|
{
|
|
|
|
|
/* Update the table changing old WWW by new WWW */
|
2018-11-03 12:16:40 +01:00
|
|
|
|
DB_QueryUPDATE ("can not update the web of a department",
|
|
|
|
|
"UPDATE departments SET WWW='%s' WHERE DptCod=%ld",
|
2019-04-08 23:34:58 +02:00
|
|
|
|
NewWWW,Dpt_EditingDpt->DptCod);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Write message to show the change made *****/
|
2019-04-08 23:34:58 +02: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 ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2019-04-08 23:34:58 +02:00
|
|
|
|
/***** Update web *****/
|
2021-02-15 16:25:55 +01:00
|
|
|
|
Str_Copy (Dpt_EditingDpt->WWW,NewWWW,sizeof (Dpt_EditingDpt->WWW) - 1);
|
2019-04-08 23:34:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******* Show alerts after changing a department and continue editing ********/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Dpt_ContEditAfterChgDpt (void)
|
|
|
|
|
{
|
|
|
|
|
/***** Write message to show the change made *****/
|
|
|
|
|
Ale_ShowAlerts (NULL);
|
|
|
|
|
|
|
|
|
|
/***** Show the form again *****/
|
2020-04-13 21:26:47 +02:00
|
|
|
|
Dpt_EditDepartmentsInternal ();
|
2019-04-08 23:34:58 +02:00
|
|
|
|
|
|
|
|
|
/***** Department destructor *****/
|
|
|
|
|
Dpt_EditingDepartmentDestructor ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************* Put a form to create a new department *******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void Dpt_PutFormToCreateDepartment (void)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_New_department;
|
|
|
|
|
extern const char *Txt_Institution;
|
2015-02-04 20:03:23 +01:00
|
|
|
|
extern const char *Txt_Short_name;
|
|
|
|
|
extern const char *Txt_Full_name;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
extern const char *Txt_WWW;
|
|
|
|
|
extern const char *Txt_Another_institution;
|
|
|
|
|
extern const char *Txt_Create_department;
|
|
|
|
|
unsigned NumIns;
|
|
|
|
|
|
2019-10-20 22:00:28 +02:00
|
|
|
|
/***** Begin form *****/
|
2018-11-09 20:47:39 +01:00
|
|
|
|
Frm_StartForm (ActNewDpt);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2019-10-26 02:19:42 +02:00
|
|
|
|
/***** Begin box and table *****/
|
2020-03-26 02:54:30 +01:00
|
|
|
|
Box_BoxTableBegin (NULL,Txt_New_department,
|
|
|
|
|
NULL,NULL,
|
2019-04-08 23:34:58 +02:00
|
|
|
|
NULL,Box_NOT_CLOSABLE,2);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Write heading *****/
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TR_Begin (NULL);
|
2019-10-11 15:36:50 +02:00
|
|
|
|
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TH (1,1,"LM",Txt_Institution);
|
|
|
|
|
HTM_TH (1,1,"LM",Txt_Short_name);
|
|
|
|
|
HTM_TH (1,1,"LM",Txt_Full_name);
|
|
|
|
|
HTM_TH (1,1,"LM",Txt_WWW);
|
2019-10-11 15:36:50 +02:00
|
|
|
|
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TR_End ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TR_Begin (NULL);
|
2019-10-07 08:55:06 +02:00
|
|
|
|
|
|
|
|
|
/***** Institution *****/
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"CM\"");
|
2020-04-27 03:16:55 +02:00
|
|
|
|
HTM_SELECT_Begin (HTM_DONT_SUBMIT_ON_CHANGE,
|
2019-11-05 15:47:35 +01:00
|
|
|
|
"name=\"OthInsCod\" class=\"HIE_SEL_NARROW\"");
|
2019-11-06 19:45:20 +01:00
|
|
|
|
HTM_OPTION (HTM_Type_STRING,"0",Dpt_EditingDpt->InsCod == 0,false,
|
|
|
|
|
"%s",Txt_Another_institution);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
for (NumIns = 0;
|
2020-01-08 14:04:25 +01:00
|
|
|
|
NumIns < Gbl.Hierarchy.Inss.Num;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
NumIns++)
|
2020-01-08 14:04:25 +01:00
|
|
|
|
HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Inss.Lst[NumIns].InsCod,
|
|
|
|
|
Gbl.Hierarchy.Inss.Lst[NumIns].InsCod == Dpt_EditingDpt->InsCod,false,
|
|
|
|
|
"%s",Gbl.Hierarchy.Inss.Lst[NumIns].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
|
|
|
|
|
|
|
|
|
/***** Department short name *****/
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"CM\"");
|
2021-02-11 22:57:09 +01:00
|
|
|
|
HTM_INPUT_TEXT ("ShortName",Cns_HIERARCHY_MAX_CHARS_SHRT_NAME,Dpt_EditingDpt->ShrtName,
|
2020-04-27 03:16:55 +02:00
|
|
|
|
HTM_DONT_SUBMIT_ON_CHANGE,
|
2019-11-04 09:45:57 +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
|
|
|
|
|
|
|
|
|
/***** Department full name *****/
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"CM\"");
|
2021-02-11 22:57:09 +01:00
|
|
|
|
HTM_INPUT_TEXT ("FullName",Cns_HIERARCHY_MAX_CHARS_FULL_NAME,Dpt_EditingDpt->FullName,
|
2020-04-27 03:16:55 +02:00
|
|
|
|
HTM_DONT_SUBMIT_ON_CHANGE,
|
2019-11-04 09:45:57 +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
|
|
|
|
|
|
|
|
|
/***** Department WWW *****/
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"CM\"");
|
2020-04-27 03:16:55 +02:00
|
|
|
|
HTM_INPUT_URL ("WWW",Dpt_EditingDpt->WWW,HTM_DONT_SUBMIT_ON_CHANGE,
|
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 ();
|
2019-10-07 08:55:06 +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_department);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2017-06-12 14:16:33 +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 Dpt_PutHeadDepartments (void)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_Code;
|
|
|
|
|
extern const char *Txt_Institution;
|
2015-02-04 20:03:23 +01:00
|
|
|
|
extern const char *Txt_Short_name;
|
|
|
|
|
extern const char *Txt_Full_name;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
extern const char *Txt_WWW;
|
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
|
|
|
|
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TR_Begin (NULL);
|
2019-10-11 15:36:50 +02:00
|
|
|
|
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TH_Empty (1);
|
|
|
|
|
HTM_TH (1,1,"RM",Txt_Code);
|
|
|
|
|
HTM_TH (1,1,"LM",Txt_Institution);
|
|
|
|
|
HTM_TH (1,1,"LM",Txt_Short_name);
|
|
|
|
|
HTM_TH (1,1,"LM",Txt_Full_name);
|
|
|
|
|
HTM_TH (1,1,"LM",Txt_WWW);
|
|
|
|
|
HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]);
|
2019-10-11 15:36:50 +02:00
|
|
|
|
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TR_End ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************** Receive form to create a new department *******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-05-05 21:49:00 +02:00
|
|
|
|
void Dpt_ReceiveFormNewDpt (void)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_The_department_X_already_exists;
|
2019-04-08 23:34:58 +02:00
|
|
|
|
extern const char *Txt_Created_new_department_X;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
extern const char *Txt_You_must_specify_the_web_address_of_the_new_department;
|
|
|
|
|
extern const char *Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_department;
|
|
|
|
|
|
2019-04-08 23:34:58 +02:00
|
|
|
|
/***** Department constructor *****/
|
|
|
|
|
Dpt_EditingDepartmentConstructor ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Get parameters from form *****/
|
|
|
|
|
/* Get institution */
|
2019-04-08 23:34:58 +02:00
|
|
|
|
Dpt_EditingDpt->InsCod = Ins_GetAndCheckParamOtherInsCod (1);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/* Get department short name */
|
2021-02-11 22:57:09 +01:00
|
|
|
|
Par_GetParToText ("ShortName",Dpt_EditingDpt->ShrtName,Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/* Get department full name */
|
2021-02-11 22:57:09 +01:00
|
|
|
|
Par_GetParToText ("FullName",Dpt_EditingDpt->FullName,Cns_HIERARCHY_MAX_BYTES_FULL_NAME);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/* Get department WWW */
|
2019-04-08 23:34:58 +02:00
|
|
|
|
Par_GetParToText ("WWW",Dpt_EditingDpt->WWW,Cns_MAX_BYTES_WWW);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2019-04-08 23:34:58 +02:00
|
|
|
|
if (Dpt_EditingDpt->ShrtName[0] &&
|
|
|
|
|
Dpt_EditingDpt->FullName[0]) // If there's a department name
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2019-04-08 23:34:58 +02:00
|
|
|
|
if (Dpt_EditingDpt->WWW[0])
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
|
|
|
|
/***** If name of department was in database... *****/
|
2019-04-08 23:34:58 +02:00
|
|
|
|
if (Dpt_CheckIfDepartmentNameExists ("ShortName",Dpt_EditingDpt->ShrtName,-1L))
|
|
|
|
|
Ale_CreateAlert (Ale_WARNING,NULL,
|
|
|
|
|
Txt_The_department_X_already_exists,
|
|
|
|
|
Dpt_EditingDpt->ShrtName);
|
|
|
|
|
else if (Dpt_CheckIfDepartmentNameExists ("FullName",Dpt_EditingDpt->FullName,-1L))
|
|
|
|
|
Ale_CreateAlert (Ale_WARNING,NULL,
|
|
|
|
|
Txt_The_department_X_already_exists,
|
|
|
|
|
Dpt_EditingDpt->FullName);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
else // Add new department to database
|
2019-04-08 23:34:58 +02:00
|
|
|
|
{
|
|
|
|
|
Dpt_CreateDepartment (Dpt_EditingDpt);
|
2019-04-09 00:24:50 +02:00
|
|
|
|
Ale_CreateAlert (Ale_SUCCESS,NULL,
|
|
|
|
|
Txt_Created_new_department_X,
|
|
|
|
|
Dpt_EditingDpt->FullName);
|
2019-04-08 23:34:58 +02:00
|
|
|
|
}
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
else // If there is not a web
|
2019-04-08 23:34:58 +02:00
|
|
|
|
Ale_CreateAlert (Ale_WARNING,NULL,
|
|
|
|
|
Txt_You_must_specify_the_web_address_of_the_new_department);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
else // If there is not a department name
|
2019-04-08 23:34:58 +02:00
|
|
|
|
Ale_CreateAlert (Ale_WARNING,NULL,
|
|
|
|
|
Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_department);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************** Create a new department **************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-04-13 20:50:47 +02:00
|
|
|
|
static void Dpt_CreateDepartment (struct Dpt_Department *Dpt)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
|
|
|
|
/***** Create a new department *****/
|
2018-11-02 19:37:11 +01:00
|
|
|
|
DB_QueryINSERT ("can not create a new department",
|
|
|
|
|
"INSERT INTO departments"
|
|
|
|
|
" (InsCod,ShortName,FullName,WWW)"
|
|
|
|
|
" VALUES"
|
|
|
|
|
" (%ld,'%s','%s','%s')",
|
|
|
|
|
Dpt->InsCod,Dpt->ShrtName,Dpt->FullName,Dpt->WWW);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************** Get number of departments ************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
unsigned Dpt_GetTotalNumberOfDepartments (void)
|
|
|
|
|
{
|
|
|
|
|
/***** Get number of departments from database *****/
|
2018-11-04 20:51:38 +01:00
|
|
|
|
return (unsigned) DB_GetNumRowsTable ("departments");
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/**************** Get number of departments in a institution *****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-01-06 18:27:43 +01:00
|
|
|
|
void Dpt_FlushCacheNumDptsInIns (void)
|
|
|
|
|
{
|
|
|
|
|
Gbl.Cache.NumDptsInIns.InsCod = -1L;
|
|
|
|
|
Gbl.Cache.NumDptsInIns.NumDpts = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 22:51:40 +02:00
|
|
|
|
unsigned Dpt_GetNumDptsInIns (long InsCod)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2020-01-06 18:27:43 +01:00
|
|
|
|
/***** 1. Fast check: Trivial case *****/
|
|
|
|
|
if (InsCod <= 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
/***** 2. Fast check: If cached... *****/
|
|
|
|
|
if (InsCod == Gbl.Cache.NumDptsInIns.InsCod)
|
|
|
|
|
return Gbl.Cache.NumDptsInIns.NumDpts;
|
|
|
|
|
|
|
|
|
|
/***** 3. Slow: number of departments of an institution from database *****/
|
|
|
|
|
Gbl.Cache.NumDptsInIns.InsCod = InsCod;
|
|
|
|
|
Gbl.Cache.NumDptsInIns.NumDpts =
|
2018-11-03 15:33:20 +01:00
|
|
|
|
(unsigned) DB_QueryCOUNT ("can not get number of departments"
|
|
|
|
|
" in an institution",
|
|
|
|
|
"SELECT COUNT(*) FROM departments"
|
|
|
|
|
" WHERE InsCod=%ld",
|
|
|
|
|
InsCod);
|
2020-01-06 18:27:43 +01:00
|
|
|
|
return Gbl.Cache.NumDptsInIns.NumDpts;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*********************** Put selector for department *************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2017-10-10 10:46:35 +02:00
|
|
|
|
void Dpt_WriteSelectorDepartment (long InsCod,long DptCod,
|
2018-10-08 14:11:21 +02:00
|
|
|
|
const char *SelectClass,
|
2017-10-10 10:46:35 +02:00
|
|
|
|
long FirstOption,
|
|
|
|
|
const char *TextWhenNoDptSelected,
|
|
|
|
|
bool SubmitFormOnChange)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2017-10-10 10:46:35 +02:00
|
|
|
|
extern const char *Txt_Another_department;
|
2020-04-13 20:50:47 +02:00
|
|
|
|
struct Dpt_Departments Departments;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
unsigned NumDpt;
|
2017-10-10 10:46:35 +02:00
|
|
|
|
bool NoDptSelectable;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2020-04-13 20:50:47 +02:00
|
|
|
|
/***** Reset departments context *****/
|
|
|
|
|
Dpt_ResetDepartments (&Departments);
|
|
|
|
|
|
2017-10-10 10:46:35 +02:00
|
|
|
|
/***** Get list of departments *****/
|
2020-04-13 20:50:47 +02:00
|
|
|
|
Dpt_GetListDepartments (&Departments,InsCod);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2017-10-10 10:46:35 +02:00
|
|
|
|
/***** Selector to select department *****/
|
|
|
|
|
/* Start selector */
|
2019-11-05 15:47:35 +01:00
|
|
|
|
HTM_SELECT_Begin (SubmitFormOnChange,
|
|
|
|
|
"id=\"%s\" name=\"%s\" class=\"%s\"",
|
|
|
|
|
Dpt_PARAM_DPT_COD_NAME,Dpt_PARAM_DPT_COD_NAME,SelectClass);
|
2016-06-09 17:56:57 +02:00
|
|
|
|
|
2017-10-10 10:46:35 +02:00
|
|
|
|
if (FirstOption <= 0)
|
|
|
|
|
{
|
|
|
|
|
/* Option when no department selected */
|
|
|
|
|
if (FirstOption < 0)
|
|
|
|
|
{
|
|
|
|
|
NoDptSelectable = false;
|
|
|
|
|
if (TextWhenNoDptSelected)
|
|
|
|
|
if (TextWhenNoDptSelected[0])
|
|
|
|
|
NoDptSelectable = true;
|
|
|
|
|
|
2019-11-06 19:45:20 +01:00
|
|
|
|
HTM_OPTION (HTM_Type_STRING,"-1",DptCod < 0,!NoDptSelectable,
|
|
|
|
|
"%s",TextWhenNoDptSelected);
|
2017-10-10 10:46:35 +02:00
|
|
|
|
}
|
2016-06-09 17:56:57 +02:00
|
|
|
|
|
2017-10-10 10:46:35 +02:00
|
|
|
|
/* Another department selected (different to all departments listed) */
|
2019-11-06 19:45:20 +01:00
|
|
|
|
HTM_OPTION (HTM_Type_STRING,"0",DptCod == 0,false,
|
|
|
|
|
"%s",Txt_Another_department);
|
2017-10-10 10:46:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* List all departments */
|
2014-12-01 23:55:08 +01:00
|
|
|
|
for (NumDpt = 0;
|
2020-04-13 20:50:47 +02:00
|
|
|
|
NumDpt < Departments.Num;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
NumDpt++)
|
2020-04-13 20:50:47 +02:00
|
|
|
|
HTM_OPTION (HTM_Type_LONG,&Departments.Lst[NumDpt].DptCod,
|
|
|
|
|
Departments.Lst[NumDpt].DptCod == DptCod,false,
|
|
|
|
|
"%s",Departments.Lst[NumDpt].FullName);
|
2016-06-09 17:56:57 +02:00
|
|
|
|
|
2017-10-10 10:46:35 +02:00
|
|
|
|
/* End selector */
|
2019-11-05 08:46:38 +01:00
|
|
|
|
HTM_SELECT_End ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2017-10-10 10:46:35 +02:00
|
|
|
|
/***** Free list of departments *****/
|
2020-04-13 20:50:47 +02:00
|
|
|
|
Dpt_FreeListDepartments (&Departments);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
2019-04-08 23:34:58 +02:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************** Department constructor/destructor ********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void Dpt_EditingDepartmentConstructor (void)
|
|
|
|
|
{
|
|
|
|
|
/***** Pointer must be NULL *****/
|
|
|
|
|
if (Dpt_EditingDpt != NULL)
|
|
|
|
|
Lay_ShowErrorAndExit ("Error initializing department.");
|
|
|
|
|
|
|
|
|
|
/***** Allocate memory for department *****/
|
2021-02-15 16:25:55 +01:00
|
|
|
|
if ((Dpt_EditingDpt = malloc (sizeof (*Dpt_EditingDpt))) == NULL)
|
|
|
|
|
Lay_NotEnoughMemoryExit ();
|
2019-04-08 23:34:58 +02:00
|
|
|
|
|
|
|
|
|
/***** Reset department *****/
|
|
|
|
|
Dpt_EditingDpt->DptCod = -1L;
|
|
|
|
|
Dpt_EditingDpt->InsCod = -1L;
|
|
|
|
|
Dpt_EditingDpt->ShrtName[0] = '\0';
|
|
|
|
|
Dpt_EditingDpt->FullName[0] = '\0';
|
|
|
|
|
Dpt_EditingDpt->WWW[0] = '\0';
|
|
|
|
|
Dpt_EditingDpt->NumTchs = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void Dpt_EditingDepartmentDestructor (void)
|
|
|
|
|
{
|
2019-04-09 00:24:50 +02:00
|
|
|
|
/***** Free memory used for department *****/
|
2019-04-08 23:34:58 +02:00
|
|
|
|
if (Dpt_EditingDpt != NULL)
|
|
|
|
|
{
|
2019-11-06 19:45:20 +01:00
|
|
|
|
free (Dpt_EditingDpt);
|
2019-04-08 23:34:58 +02:00
|
|
|
|
Dpt_EditingDpt = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|