swad-core/swad_department.c

1228 lines
44 KiB
C
Raw Normal View History

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.
2019-01-07 21:52:19 +01:00
Copyright (C) 1999-2019 Antonio Ca<EFBFBD>as Vargas
2014-12-01 23:55:08 +01:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
#include <linux/stddef.h> // For NULL
2015-10-16 02:24:29 +02:00
#include <stdbool.h> // For boolean type
2014-12-01 23:55:08 +01:00
#include <stdlib.h> // For calloc
#include <string.h> // For string functions
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"
#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"
2019-04-08 23:34:58 +02:00
#include "swad_table.h"
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
2019-04-08 23:34:58 +02:00
static struct Department *Dpt_EditingDpt = NULL; // Static variable to keep the department being edited
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2017-01-29 12:42:19 +01:00
static void Dpt_GetParamDptOrder (void);
2016-03-16 22:46:38 +01:00
static void Dpt_PutIconToEditDpts (void);
2019-04-08 23:34:58 +02:00
static void Dpt_EditDepartmentsInternal (void);
2014-12-01 23:55:08 +01:00
static void Dpt_ListDepartmentsForEdition (void);
static void Dpt_PutParamDptCod (long 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);
static void Dpt_CreateDepartment (struct Department *Dpt);
2019-04-08 23:34:58 +02:00
static void Dpt_EditingDepartmentConstructor (void);
static void Dpt_EditingDepartmentDestructor (void);
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;
2017-01-29 12:42:19 +01:00
Dpt_Order_t Order;
2014-12-01 23:55:08 +01:00
unsigned NumDpt;
unsigned NumTchsInsWithDpt = 0; // Number of teachers from the current institution with department
unsigned NumTchsInOtherDpts;
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
2019-04-03 20:57:04 +02:00
/***** Get parameter with the type of order in the list of departments *****/
Dpt_GetParamDptOrder ();
/***** Get list of departments *****/
Dpt_GetListDepartments (Gbl.Hierarchy.Ins.InsCod);
/***** Start box and table *****/
2019-04-08 23:34:58 +02:00
snprintf (Gbl.Title,sizeof (Gbl.Title),
Txt_Departments_of_INSTITUTION_X,
Gbl.Hierarchy.Ins.FullName);
Box_StartBoxTable (NULL,Gbl.Title,
2019-04-03 20:57:04 +02:00
Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM ? Dpt_PutIconToEditDpts :
NULL,
Hlp_INSTITUTION_Departments,Box_NOT_CLOSABLE,2);
/***** Write heading *****/
fprintf (Gbl.F.Out,"<tr>");
for (Order = Dpt_ORDER_BY_DEPARTMENT;
Order <= Dpt_ORDER_BY_NUM_TCHS;
Order++)
{
fprintf (Gbl.F.Out,"<th class=\"LEFT_MIDDLE\">");
Frm_StartForm (ActSeeDpt);
Par_PutHiddenParamUnsigned ("Order",(unsigned) Order);
Frm_LinkFormSubmit (Txt_DEPARTMENTS_HELP_ORDER[Order],"TIT_TBL",NULL);
if (Order == Gbl.Dpts.SelectedOrder)
fprintf (Gbl.F.Out,"<u>");
fprintf (Gbl.F.Out,"%s",Txt_DEPARTMENTS_ORDER[Order]);
if (Order == Gbl.Dpts.SelectedOrder)
fprintf (Gbl.F.Out,"</u>");
fprintf (Gbl.F.Out,"</a>");
Frm_EndForm ();
fprintf (Gbl.F.Out,"</th>");
}
fprintf (Gbl.F.Out,"</tr>");
2014-12-01 23:55:08 +01:00
2019-04-03 20:57:04 +02:00
/***** Write all the departments and their nuber of teachers *****/
for (NumDpt = 0;
NumDpt < Gbl.Dpts.Num;
NumDpt++)
{
/* Write data of this department */
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<tr>"
2019-04-03 20:57:04 +02:00
"<td class=\"LEFT_MIDDLE\">"
"<a href=\"%s\" target=\"_blank\" class=\"DAT\">"
2014-12-22 19:59:27 +01:00
"%s"
2019-04-03 20:57:04 +02:00
"</a>"
2014-12-22 19:59:27 +01:00
"</td>"
2015-07-31 20:05:54 +02:00
"<td class=\"DAT RIGHT_MIDDLE\">"
2016-06-16 18:32:12 +02:00
"%u"
2014-12-22 19:59:27 +01:00
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>",
2019-04-03 20:57:04 +02:00
Gbl.Dpts.Lst[NumDpt].WWW,
Gbl.Dpts.Lst[NumDpt].FullName,
Gbl.Dpts.Lst[NumDpt].NumTchs);
2014-12-01 23:55:08 +01:00
2019-04-03 20:57:04 +02:00
/* Update number of teachers from the current institution
with department */
NumTchsInsWithDpt += Gbl.Dpts.Lst[NumDpt].NumTchs;
2014-12-01 23:55:08 +01:00
}
2019-04-03 20:57:04 +02:00
/***** Separation row *****/
fprintf (Gbl.F.Out,"<tr>"
"<td colspan=\"3\" class=\"DAT\">"
"&nbsp;"
"</td>"
"</tr>");
/***** Write teachers with other department *****/
NumTchsInOtherDpts = Usr_GetNumTchsCurrentInsInDepartment (0);
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"DAT LEFT_MIDDLE\">"
"%s"
"</td>"
"<td class=\"DAT RIGHT_MIDDLE\">"
"%u"
"</td>"
"</tr>",
Txt_Other_departments,NumTchsInOtherDpts);
NumTchsInsWithDpt += NumTchsInOtherDpts;
/***** Write teachers with no department *****/
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"DAT LEFT_MIDDLE\">"
"%s"
"</td>"
"<td class=\"DAT RIGHT_MIDDLE\">"
"%u"
"</td>"
"</tr>",
Txt_Department_unspecified,
Usr_GetTotalNumberOfUsersInCourses (Hie_INS,
1 << Rol_NET |
1 << Rol_TCH) -
NumTchsInsWithDpt);
/***** End table and box *****/
Box_EndBoxTable ();
/***** Free list of departments *****/
Dpt_FreeListDepartments ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******** Get parameter with the type or order in list of departments ********/
/*****************************************************************************/
2017-01-29 12:42:19 +01:00
static void Dpt_GetParamDptOrder (void)
2014-12-01 23:55:08 +01:00
{
2017-01-29 21:41:08 +01:00
Gbl.Dpts.SelectedOrder = (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
/*****************************************************************************/
2016-03-16 22:46:38 +01:00
static void Dpt_PutIconToEditDpts (void)
2014-12-01 23:55:08 +01:00
{
2017-06-11 19:13:28 +02:00
Ico_PutContextualIconToEdit (ActEdiDpt,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 *****/
Dpt_EditDepartmentsInternal ();
/***** Department destructor *****/
Dpt_EditingDepartmentDestructor ();
}
static void Dpt_EditDepartmentsInternal (void)
{
extern const char *Hlp_INSTITUTION_Departments_edit;
extern const char *Txt_Departments_of_INSTITUTION_X;
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
/***** Get list of institutions *****/
2019-04-03 20:57:04 +02:00
Ins_GetListInstitutions (Gbl.Hierarchy.Cty.CtyCod,Ins_GET_BASIC_DATA);
2014-12-01 23:55:08 +01:00
/***** Get list of departments *****/
2019-04-03 20:57:04 +02:00
Dpt_GetListDepartments (Gbl.Hierarchy.Ins.InsCod);
2014-12-01 23:55:08 +01:00
2019-04-08 23:34:58 +02:00
/***** Start box *****/
snprintf (Gbl.Title,sizeof (Gbl.Title),
Txt_Departments_of_INSTITUTION_X,
Gbl.Hierarchy.Ins.FullName);
Box_StartBox (NULL,Gbl.Title,NULL,
Hlp_INSTITUTION_Departments_edit,Box_NOT_CLOSABLE);
2014-12-01 23:55:08 +01:00
/***** Put a form to create a new department *****/
Dpt_PutFormToCreateDepartment ();
/***** Forms to edit current departments *****/
if (Gbl.Dpts.Num)
Dpt_ListDepartmentsForEdition ();
2019-04-08 23:34:58 +02:00
/***** End box *****/
Box_EndBox ();
2014-12-01 23:55:08 +01:00
/***** Free list of departments *****/
Dpt_FreeListDepartments ();
/***** 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
void Dpt_GetListDepartments (long InsCod)
{
2019-01-03 15:25:18 +01:00
static const char *OrderBySubQuery[Dpt_NUM_ORDERS] =
{
"FullName", // Dpt_ORDER_BY_DEPARTMENT
"NumTchs DESC,FullName", // Dpt_ORDER_BY_NUM_TCHS
};
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumDpt;
struct Department *Dpt;
2017-10-10 10:46:35 +02:00
/***** Free list of departments *****/
Dpt_FreeListDepartments (); // List is initialized to empty
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 *****/
2018-10-30 17:47:57 +01:00
Gbl.Dpts.Num = (unsigned) DB_QuerySELECT (&mysql_res,"can not get departments",
"(SELECT departments.DptCod,departments.InsCod,"
"departments.ShortName,departments.FullName,departments.WWW,"
"COUNT(DISTINCT usr_data.UsrCod) AS NumTchs"
" 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,InsCod,ShortName,FullName,WWW,0 AS NumTchs"
" 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,
2019-01-03 15:25:18 +01:00
OrderBySubQuery[Gbl.Dpts.SelectedOrder]);
2017-10-10 10:46:35 +02:00
if (Gbl.Dpts.Num) // Departments found...
{
/***** Create list with courses in degree *****/
if ((Gbl.Dpts.Lst = (struct Department *) calloc ((size_t) Gbl.Dpts.Num,
sizeof (struct Department))) == 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;
NumDpt < Gbl.Dpts.Num;
NumDpt++)
{
Dpt = &(Gbl.Dpts.Lst[NumDpt]);
/* 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.");
/* Get the short name of the department (row[2]) */
Str_Copy (Dpt->ShrtName,row[2],
Hie_MAX_BYTES_SHRT_NAME);
/* Get the full name of the department (row[3]) */
Str_Copy (Dpt->FullName,row[3],
Hie_MAX_BYTES_FULL_NAME);
/* Get the URL of the department (row[4]) */
Str_Copy (Dpt->WWW,row[4],
Cns_MAX_BYTES_WWW);
/* 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 *************************/
/*****************************************************************************/
void Dpt_GetDataOfDepartmentByCod (struct Department *Dpt)
{
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)
{
2017-01-15 18:02:52 +01:00
Str_Copy (Dpt->ShrtName,Txt_Another_department,
2017-03-08 14:12:33 +01:00
Hie_MAX_BYTES_SHRT_NAME);
2017-01-15 18:02:52 +01:00
Str_Copy (Dpt->FullName,Txt_Another_department,
2017-03-08 14:12:33 +01:00
Hie_MAX_BYTES_FULL_NAME);
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]);
/* Get the short name of the department (row[1]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Dpt->ShrtName,row[1],
2017-03-08 14:12:33 +01:00
Hie_MAX_BYTES_SHRT_NAME);
2014-12-01 23:55:08 +01:00
/* Get the full name of the department (row[2]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Dpt->FullName,row[2],
2017-03-08 14:12:33 +01:00
Hie_MAX_BYTES_FULL_NAME);
2014-12-01 23:55:08 +01:00
/* Get the URL of the department (row[3]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Dpt->WWW,row[3],
2017-03-07 01:56:41 +01:00
Cns_MAX_BYTES_WWW);
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 *************************/
/*****************************************************************************/
void Dpt_FreeListDepartments (void)
{
if (Gbl.Dpts.Lst)
2017-10-10 10:46:35 +02:00
/***** Free memory used by the list of departments *****/
2014-12-01 23:55:08 +01:00
free ((void *) Gbl.Dpts.Lst);
2017-10-10 10:46:35 +02:00
Gbl.Dpts.Lst = NULL;
Gbl.Dpts.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 *************************/
/*****************************************************************************/
static void Dpt_ListDepartmentsForEdition (void)
{
extern const char *Txt_Another_institution;
unsigned NumDpt;
struct Department *Dpt;
2016-10-28 10:03:37 +02:00
struct Instit Ins;
2014-12-01 23:55:08 +01:00
unsigned NumIns;
2019-04-08 23:34:58 +02:00
/***** Start table *****/
Tbl_StartTable (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;
NumDpt < Gbl.Dpts.Num;
NumDpt++)
{
Dpt = &Gbl.Dpts.Lst[NumDpt];
/* Get data of institution of this department */
Ins.InsCod = Dpt->InsCod;
2015-12-09 19:51:17 +01:00
Ins_GetDataOfInstitutionByCod (&Ins,Ins_GET_BASIC_DATA);
2014-12-01 23:55:08 +01:00
/* Put icon to remove department */
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"BM\">");
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
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRemDpt);
2014-12-01 23:55:08 +01:00
Dpt_PutParamDptCod (Dpt->DptCod);
2017-06-11 19:13:28 +02:00
Ico_PutIconRemove ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
fprintf (Gbl.F.Out,"</td>");
/* Department code */
2015-07-31 20:05:54 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"%ld&nbsp;"
"</td>",
2014-12-01 23:55:08 +01:00
Dpt->DptCod);
/* Institution */
2015-07-31 20:05:54 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgDptIns);
2014-12-01 23:55:08 +01:00
Dpt_PutParamDptCod (Dpt->DptCod);
2015-09-28 18:28:29 +02:00
fprintf (Gbl.F.Out,"<select name=\"OthInsCod\" style=\"width:62px;\""
2015-10-22 14:49:48 +02:00
"onchange=\"document.getElementById('%s').submit();\">"
2014-12-01 23:55:08 +01:00
"<option value=\"0\"",
2016-01-14 10:31:09 +01:00
Gbl.Form.Id);
2014-12-01 23:55:08 +01:00
if (Dpt->InsCod == 0)
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%s</option>",Txt_Another_institution);
for (NumIns = 0;
2019-04-04 10:45:15 +02:00
NumIns < Gbl.Hierarchy.Cty.Inss.Num;
2014-12-01 23:55:08 +01:00
NumIns++)
fprintf (Gbl.F.Out,"<option value=\"%ld\"%s>%s</option>",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Cty.Inss.Lst[NumIns].InsCod,
Gbl.Hierarchy.Cty.Inss.Lst[NumIns].InsCod == Dpt->InsCod ? " selected=\"selected\"" :
2014-12-01 23:55:08 +01:00
"",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Cty.Inss.Lst[NumIns].ShrtName);
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</select>");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
/* Department short name */
2015-07-31 20:05:54 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRenDptSho);
2014-12-01 23:55:08 +01:00
Dpt_PutParamDptCod (Dpt->DptCod);
2015-10-22 14:49:48 +02:00
fprintf (Gbl.F.Out,"<input type=\"text\" name=\"ShortName\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_SHORT_NAME\""
2015-10-22 14:49:48 +02:00
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-08 14:12:33 +01:00
Hie_MAX_CHARS_SHRT_NAME,Dpt->ShrtName,Gbl.Form.Id);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
/* Department full name */
2015-07-31 20:05:54 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRenDptFul);
2014-12-01 23:55:08 +01:00
Dpt_PutParamDptCod (Dpt->DptCod);
2015-10-22 14:49:48 +02:00
fprintf (Gbl.F.Out,"<input type=\"text\" name=\"FullName\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_FULL_NAME\""
2015-10-22 14:49:48 +02:00
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-08 14:12:33 +01:00
Hie_MAX_CHARS_FULL_NAME,Dpt->FullName,Gbl.Form.Id);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
/* Department WWW */
2015-07-31 20:05:54 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgDptWWW);
2014-12-01 23:55:08 +01:00
Dpt_PutParamDptCod (Dpt->DptCod);
2016-11-20 14:32:15 +01:00
fprintf (Gbl.F.Out,"<input type=\"url\" name=\"WWW\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_WWW\""
2015-10-22 14:49:48 +02:00
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-07 01:56:41 +01:00
Cns_MAX_CHARS_WWW,Dpt->WWW,Gbl.Form.Id);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
/* Number of teachers */
2015-07-31 20:05:54 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE\">"
2016-06-16 18:32:12 +02:00
"%u"
2014-12-22 19:59:27 +01:00
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>",
Dpt->NumTchs);
}
2019-04-08 23:34:58 +02:00
/***** End table *****/
Tbl_EndTable ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************** Write parameter with code of department ******************/
/*****************************************************************************/
static void Dpt_PutParamDptCod (long DptCod)
{
2017-10-10 12:37:09 +02:00
Par_PutHiddenParamLong (Dpt_PARAM_DPT_COD_NAME,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_You_can_not_leave_the_name_of_the_department_X_empty;
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
2017-03-08 14:12:33 +01:00
char NewDptName[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-08 14:12:33 +01:00
MaxBytes = Hie_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";
2017-03-08 14:12:33 +01:00
MaxBytes = Hie_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 *****/
if (!NewDptName[0])
2019-04-08 23:34:58 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_You_can_not_leave_the_name_of_the_department_X_empty,
CurrentDptName);
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 (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-04-08 23:34:58 +02:00
/***** Update name *****/
2017-01-17 03:10:43 +01:00
Str_Copy (CurrentDptName,NewDptName,
2017-03-07 11:03:05 +01:00
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;
extern const char *Txt_You_can_not_leave_the_web_address_empty;
2017-03-07 01:56:41 +01:00
char NewWWW[Cns_MAX_BYTES_WWW + 1];
2014-12-01 23:55:08 +01:00
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-04-08 23:34:58 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_You_can_not_leave_the_web_address_empty);
2014-12-01 23:55:08 +01:00
2019-04-08 23:34:58 +02:00
/***** Update web *****/
Str_Copy (Dpt_EditingDpt->WWW,NewWWW,
2017-03-07 01:56:41 +01:00
Cns_MAX_BYTES_WWW);
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 *****/
Dpt_EditDepartmentsInternal ();
/***** 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;
/***** Start form *****/
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActNewDpt);
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** Start box and table *****/
2017-06-10 21:38:10 +02:00
Box_StartBoxTable (NULL,Txt_New_department,NULL,
2019-04-08 23:34:58 +02:00
NULL,Box_NOT_CLOSABLE,2);
2014-12-01 23:55:08 +01:00
/***** Write heading *****/
fprintf (Gbl.F.Out,"<tr>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2014-12-01 23:55:08 +01:00
"</tr>",
Txt_Institution,
2015-02-04 20:03:23 +01:00
Txt_Short_name,
Txt_Full_name,
2014-12-01 23:55:08 +01:00
Txt_WWW);
/***** Institution *****/
fprintf (Gbl.F.Out,"<tr>"
2015-07-31 20:05:54 +02:00
"<td class=\"CENTER_MIDDLE\">"
2015-09-28 18:28:29 +02:00
"<select name=\"OthInsCod\" style=\"width:62px;\">"
2014-12-01 23:55:08 +01:00
"<option value=\"0\"");
2019-04-08 23:34:58 +02:00
if (Dpt_EditingDpt->InsCod == 0)
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%s</option>",Txt_Another_institution);
for (NumIns = 0;
2019-04-04 10:45:15 +02:00
NumIns < Gbl.Hierarchy.Cty.Inss.Num;
2014-12-01 23:55:08 +01:00
NumIns++)
fprintf (Gbl.F.Out,"<option value=\"%ld\"%s>%s</option>",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Cty.Inss.Lst[NumIns].InsCod,
2019-04-08 23:34:58 +02:00
Gbl.Hierarchy.Cty.Inss.Lst[NumIns].InsCod == Dpt_EditingDpt->InsCod ? " selected=\"selected\"" :
2014-12-01 23:55:08 +01:00
"",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Cty.Inss.Lst[NumIns].ShrtName);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</select>"
"</td>");
/***** Department short name *****/
2015-07-31 20:05:54 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">"
2015-10-23 01:31:08 +02:00
"<input type=\"text\" name=\"ShortName\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
2016-11-19 20:41:45 +01:00
" class=\"INPUT_SHORT_NAME\""
" required=\"required\" />"
2014-12-01 23:55:08 +01:00
"</td>",
2019-04-08 23:34:58 +02:00
Hie_MAX_CHARS_SHRT_NAME,Dpt_EditingDpt->ShrtName);
2014-12-01 23:55:08 +01:00
/***** Department full name *****/
2015-07-31 20:05:54 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">"
2015-10-23 01:31:08 +02:00
"<input type=\"text\" name=\"FullName\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
2016-11-19 20:41:45 +01:00
" class=\"INPUT_FULL_NAME\""
" required=\"required\" />"
2014-12-01 23:55:08 +01:00
"</td>",
2019-04-08 23:34:58 +02:00
Hie_MAX_CHARS_FULL_NAME,Dpt_EditingDpt->FullName);
2014-12-01 23:55:08 +01:00
/***** Department WWW *****/
2015-07-31 20:05:54 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">"
2016-11-20 14:32:15 +01:00
"<input type=\"url\" name=\"WWW\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
2016-11-19 20:41:45 +01:00
" class=\"INPUT_WWW\""
" required=\"required\" />"
2014-12-01 23:55:08 +01:00
"</td>"
"</tr>",
2019-04-08 23:34:58 +02:00
Cns_MAX_CHARS_WWW,Dpt_EditingDpt->WWW);
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End table, send button and end box *****/
2017-06-11 19:02:40 +02:00
Box_EndBoxTableWithButton (Btn_CREATE_BUTTON,Txt_Create_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
fprintf (Gbl.F.Out,"<tr>"
2015-09-06 20:02:14 +02:00
"<th class=\"CENTER_MIDDLE\">"
2015-09-05 19:19:39 +02:00
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"%s"
2015-09-05 19:19:39 +02:00
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"%s"
2015-09-05 19:19:39 +02:00
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"%s"
2015-09-05 19:19:39 +02:00
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"%s"
2015-09-05 19:19:39 +02:00
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"%s"
2015-09-05 19:19:39 +02:00
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"%s"
2015-09-05 19:19:39 +02:00
"</th>"
2014-12-01 23:55:08 +01:00
"</tr>",
Txt_Code,
Txt_Institution,
2015-02-04 20:03:23 +01:00
Txt_Short_name,
Txt_Full_name,
2014-12-01 23:55:08 +01:00
Txt_WWW,
2017-05-30 21:43:05 +02:00
Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************** Receive form to create a new department *******************/
/*****************************************************************************/
void Dpt_RecFormNewDpt (void)
{
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 */
2019-04-08 23:34:58 +02:00
Par_GetParToText ("ShortName",Dpt_EditingDpt->ShrtName,Hie_MAX_BYTES_SHRT_NAME);
2014-12-01 23:55:08 +01:00
/* Get department full name */
2019-04-08 23:34:58 +02:00
Par_GetParToText ("FullName",Dpt_EditingDpt->FullName,Hie_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 **************************/
/*****************************************************************************/
static void Dpt_CreateDepartment (struct Department *Dpt)
{
/***** 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 *****************/
/*****************************************************************************/
2017-05-31 22:51:40 +02:00
unsigned Dpt_GetNumDptsInIns (long InsCod)
2014-12-01 23:55:08 +01:00
{
/***** Get 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
}
/*****************************************************************************/
/*********************** 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;
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
2017-10-10 10:46:35 +02:00
/***** Get list of departments *****/
2014-12-01 23:55:08 +01:00
Dpt_GetListDepartments (InsCod);
2017-10-10 10:46:35 +02:00
/***** Selector to select department *****/
/* Start selector */
2017-10-10 12:37:09 +02:00
fprintf (Gbl.F.Out,"<select id=\"%s\" name=\"%s\""
2018-10-08 14:11:21 +02:00
" class=\"%s\"",
2017-10-10 12:37:09 +02:00
Dpt_PARAM_DPT_COD_NAME,Dpt_PARAM_DPT_COD_NAME,
2018-10-08 14:11:21 +02:00
SelectClass);
2017-09-21 21:58:14 +02:00
if (SubmitFormOnChange)
fprintf (Gbl.F.Out," onchange=\"document.getElementById('%s').submit();\"",
Gbl.Form.Id);
fprintf (Gbl.F.Out,"\">");
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;
fprintf (Gbl.F.Out,"<option value=\"-1\"");
if (DptCod < 0)
fprintf (Gbl.F.Out," selected=\"selected\"");
if (!NoDptSelectable)
fprintf (Gbl.F.Out," disabled=\"disabled\"");
fprintf (Gbl.F.Out,">%s</option>",TextWhenNoDptSelected);
}
2016-06-09 17:56:57 +02:00
2017-10-10 10:46:35 +02:00
/* Another department selected (different to all departments listed) */
fprintf (Gbl.F.Out,"<option value=\"0\"");
if (DptCod == 0)
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%s</option>",
Txt_Another_department);
}
/* List all departments */
2014-12-01 23:55:08 +01:00
for (NumDpt = 0;
NumDpt < Gbl.Dpts.Num;
NumDpt++)
{
fprintf (Gbl.F.Out,"<option value=\"%ld\"",Gbl.Dpts.Lst[NumDpt].DptCod);
2017-09-22 00:26:14 +02:00
if (Gbl.Dpts.Lst[NumDpt].DptCod == DptCod)
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%s</option>",Gbl.Dpts.Lst[NumDpt].FullName);
}
2016-06-09 17:56:57 +02:00
2017-10-10 10:46:35 +02:00
/* End selector */
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</select>");
2017-10-10 10:46:35 +02:00
/***** Free list of departments *****/
2014-12-01 23:55:08 +01:00
Dpt_FreeListDepartments ();
}
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 *****/
if ((Dpt_EditingDpt = (struct Department *) malloc (sizeof (struct Department))) == NULL)
Lay_ShowErrorAndExit ("Error allocating memory for department.");
/***** 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)
{
free ((void *) Dpt_EditingDpt);
Dpt_EditingDpt = NULL;
}
}