swad-core/swad_institution.c

1958 lines
68 KiB
C
Raw Permalink Normal View History

2014-12-01 23:55:08 +01:00
// swad_institution.c: institutions
/*
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.
Copyright (C) 1999-2024 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 ***********************************/
/*****************************************************************************/
#define _GNU_SOURCE // For asprintf
2019-12-29 16:21:42 +01:00
#include <stdbool.h> // For boolean type
2019-12-29 12:39:00 +01:00
#include <stddef.h> // For NULL
#include <stdio.h> // For asprintf
2020-01-03 22:16:51 +01:00
#include <stdlib.h> // For free
2014-12-01 23:55:08 +01:00
#include <string.h> // For string functions
#include "swad_action_list.h"
#include "swad_admin_database.h"
#include "swad_box.h"
#include "swad_browser_database.h"
#include "swad_center_database.h"
2014-12-01 23:55:08 +01:00
#include "swad_database.h"
2020-04-14 17:15:17 +02:00
#include "swad_department.h"
#include "swad_enrolment_database.h"
#include "swad_error.h"
2020-04-14 17:15:17 +02:00
#include "swad_figure.h"
2020-05-02 13:39:59 +02:00
#include "swad_figure_cache.h"
2018-11-09 20:47:39 +01:00
#include "swad_form.h"
#include "swad_forum_database.h"
2014-12-01 23:55:08 +01:00
#include "swad_global.h"
2021-02-11 22:57:09 +01:00
#include "swad_hierarchy.h"
#include "swad_hierarchy_config.h"
#include "swad_hierarchy_type.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"
#include "swad_institution_database.h"
2015-01-17 13:31:25 +01:00
#include "swad_logo.h"
2020-04-14 17:15:17 +02:00
#include "swad_message.h"
#include "swad_parameter.h"
#include "swad_parameter_code.h"
2020-04-14 17:15:17 +02:00
#include "swad_place.h"
#include "swad_survey.h"
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
static struct Hie_Node *Ins_EditingIns = NULL; // Static variable to keep the institution being edited
2019-04-06 20:43:31 +02:00
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2015-10-06 01:19:21 +02:00
static void Ins_ListInstitutions (void);
2020-04-08 18:18:46 +02:00
static void Ins_PutIconsListingInstitutions (__attribute__((unused)) void *Args);
2016-03-16 22:40:35 +01:00
static void Ins_PutIconToEditInstitutions (void);
static void Ins_ListOneInstitutionForSeeing (struct Hie_Node *Ins,unsigned NumIns);
2014-12-01 23:55:08 +01:00
static void Ins_PutHeadInstitutionsForSeeing (bool OrderSelectable);
2017-03-02 00:53:34 +01:00
2019-04-06 20:43:31 +02:00
static void Ins_EditInstitutionsInternal (void);
2020-04-08 18:18:46 +02:00
static void Ins_PutIconsEditingInstitutions (__attribute__((unused)) void *Args);
2017-04-30 01:20:18 +02:00
static void Ins_GetInstitDataFromRow (MYSQL_RES *mysql_res,
struct Hie_Node *Ins,
bool GetNumUsrsWhoClaimToBelongToIns);
2020-01-07 22:07:06 +01:00
2019-04-06 20:43:31 +02:00
static void Ins_ListInstitutionsForEdition (void);
static Usr_Can_t Ins_CheckIfICanEdit (struct Hie_Node *Ins);
2016-10-23 19:40:14 +02:00
static void Ins_UpdateInsNameDB (long InsCod,const char *FldName,const char *NewName);
2017-03-09 11:16:17 +01:00
2019-04-06 20:43:31 +02:00
static void Ins_ShowAlertAndButtonToGoToIns (void);
2016-03-01 23:58:48 +01:00
2019-04-06 20:43:31 +02:00
static void Ins_PutFormToCreateInstitution (void);
2014-12-01 23:55:08 +01:00
static void Ins_PutHeadInstitutionsForEdition (void);
static void Ins_ReceiveRequestOrCreateIns (Hie_Status_t Status);
2019-04-04 14:48:05 +02:00
2019-04-06 20:43:31 +02:00
static void Ins_EditingInstitutionConstructor ();
static void Ins_EditingInstitutionDestructor ();
2014-12-01 23:55:08 +01:00
static void Ins_FormToGoToMap (struct Hie_Node *Ins);
2020-01-14 13:30:18 +01:00
static void Ins_GetAndShowInssOrderedByNumCtrs (void);
static void Ins_GetAndShowInssOrderedByNumDegs (void);
static void Ins_GetAndShowInssOrderedByNumCrss (void);
static void Ins_GetAndShowInssOrderedByNumUsrsInCrss (void);
static void Ins_GetAndShowInssOrderedByNumUsrsWhoClaimToBelongToThem (void);
static void Ins_ShowInss (MYSQL_RES **mysql_res,unsigned NumInss,
const char *TxtFigure);
static unsigned Ins_GetInsAndStat (struct Hie_Node *Ins,MYSQL_RES *mysql_res);
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/***************** List institutions with pending centers ********************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
void Ins_SeeInsWithPendingCtrs (void)
{
extern bool (*Hie_GetDataByCod[Hie_NUM_LEVELS]) (struct Hie_Node *Node);
2020-01-30 20:47:00 +01:00
extern const char *Hlp_SYSTEM_Pending;
extern const char *Txt_Institutions_with_pending_centers;
extern const char *Txt_HIERARCHY_SINGUL_Abc[Hie_NUM_LEVELS];
extern const char *Txt_Centers_ABBREVIATION;
extern const char *Txt_There_are_no_institutions_with_requests_for_centers_to_be_confirmed;
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumInss = 0;
2014-12-01 23:55:08 +01:00
unsigned NumIns;
struct Hie_Node Ins;
2015-09-04 19:26:08 +02:00
const char *BgColor;
2014-12-01 23:55:08 +01:00
/***** Get institutions with pending centers *****/
2017-06-04 18:18:54 +02:00
switch (Gbl.Usrs.Me.Role.Logged)
2014-12-01 23:55:08 +01:00
{
2015-04-07 21:44:24 +02:00
case Rol_INS_ADM:
NumInss = Ins_DB_GetInsWithPendingCtrsAdminByMe (&mysql_res);
2014-12-01 23:55:08 +01:00
break;
2015-04-07 21:44:24 +02:00
case Rol_SYS_ADM:
NumInss = Ins_DB_GetAllInsWithPendingCtr (&mysql_res);
2014-12-01 23:55:08 +01:00
break;
default: // Forbidden for other users
Err_WrongRoleExit ();
break; // Not reached
2014-12-01 23:55:08 +01:00
}
/***** Get institutions *****/
2018-10-31 16:16:57 +01:00
if (NumInss)
2014-12-01 23:55:08 +01:00
{
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
Box_BoxTableBegin (Txt_Institutions_with_pending_centers,NULL,NULL,
2020-01-30 20:47:00 +01:00
Hlp_SYSTEM_Pending,Box_NOT_CLOSABLE,2);
2017-06-12 14:16:33 +02:00
/***** Write heading *****/
HTM_TR_Begin (NULL);
HTM_TH (Txt_HIERARCHY_SINGUL_Abc[Hie_INS],HTM_HEAD_LEFT );
HTM_TH (Txt_Centers_ABBREVIATION ,HTM_HEAD_RIGHT);
HTM_TR_End ();
2019-10-12 00:07:52 +02:00
/***** List the institutions *****/
for (NumIns = 0, The_ResetRowColor ();
NumIns < NumInss;
NumIns++, The_ChangeRowColor ())
{
/* Get next center */
row = mysql_fetch_row (mysql_res);
2014-12-01 23:55:08 +01:00
/* Get institution code (row[0]) */
Ins.HieCod = Str_ConvertStrCodToLongCod (row[0]);
BgColor = (Ins.HieCod == Gbl.Hierarchy.Node[Hie_INS].HieCod) ? "BG_HIGHLIGHT" :
The_GetColorRows ();
2014-12-01 23:55:08 +01:00
/* Get data of institution */
Hie_GetDataByCod[Hie_INS] (&Ins);
2014-12-01 23:55:08 +01:00
/* Institution logo and name */
HTM_TR_Begin (NULL);
2014-12-01 23:55:08 +01:00
HTM_TD_Begin ("class=\"LM DAT_%s NOWRAP %s\"",
The_GetSuffix (),BgColor);
Ins_DrawInstitLogoAndNameWithLink (&Ins,ActSeeCtr,"CM ICO16x16");
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Number of pending centers (row[1]) */
HTM_TD_Begin ("class=\"RM DAT_%s %s\"",
The_GetSuffix (),BgColor);
HTM_Txt (row[1]);
HTM_TD_End ();
2019-10-07 17:36:41 +02:00
HTM_TR_End ();
}
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableEnd ();
2014-12-01 23:55:08 +01:00
}
else
Ale_ShowAlert (Ale_INFO,Txt_There_are_no_institutions_with_requests_for_centers_to_be_confirmed);
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2016-07-27 14:58:26 +02:00
/*****************************************************************************/
/********************** Draw institution logo with link **********************/
/*****************************************************************************/
void Ins_DrawInstitutionLogoWithLink (struct Hie_Node *Ins,const char *IconClass)
2016-07-27 14:58:26 +02:00
{
Hie_PutLink_t PutLink = Frm_CheckIfInside () ? Hie_DONT_PUT_LINK : // Don't put link to institution if already inside a form
Hie_PUT_LINK;
2016-07-30 00:21:35 +02:00
if (PutLink == Hie_PUT_LINK)
2016-07-27 14:58:26 +02:00
{
Frm_BeginForm (ActSeeInsInf);
ParCod_PutPar (ParCod_Ins,Ins->HieCod);
HTM_BUTTON_Submit_Begin (Ins->FullName,"class=\"BT_LINK\"");
2016-07-27 14:58:26 +02:00
}
Lgo_DrawLogo (Hie_INS,Ins,IconClass);
if (PutLink == Hie_PUT_LINK)
2016-07-27 14:58:26 +02:00
{
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-07-27 14:58:26 +02:00
}
}
2015-11-19 18:33:16 +01:00
/*****************************************************************************/
/****************** Draw institution logo and name with link *****************/
/*****************************************************************************/
void Ins_DrawInstitLogoAndNameWithLink (struct Hie_Node *Ins,Act_Action_t Action,
const char *IconClass)
2015-11-19 18:33:16 +01:00
{
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
Frm_BeginFormGoTo (Action);
ParCod_PutPar (ParCod_Ins,Ins->HieCod);
2015-11-19 18:33:16 +01:00
/***** Link to action *****/
HTM_BUTTON_Submit_Begin (Str_BuildGoToTitle (Ins->FullName),
"class=\"BT_LINK LT\"");
Str_FreeGoToTitle ();
2015-11-19 18:33:16 +01:00
/***** Institution logo and name *****/
Lgo_DrawLogo (Hie_INS,Ins,IconClass);
HTM_NBSPTxt (Ins->FullName);
2015-11-19 18:33:16 +01:00
/***** End link *****/
HTM_BUTTON_End ();
2015-11-19 18:33:16 +01:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2020-01-14 13:30:18 +01:00
/***** Map *****/
Ins_FormToGoToMap (Ins);
2015-11-19 18:33:16 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/**************** List the institutions of the current country ***************/
/*****************************************************************************/
void Ins_ShowInssOfCurrentCty (void)
{
if (Gbl.Hierarchy.Node[Hie_CTY].HieCod > 0)
2014-12-01 23:55:08 +01:00
{
/***** Get parameter with the type of order in the list of institutions *****/
Gbl.Hierarchy.List[Hie_INS].SelectedOrder = Hie_GetParHieOrder ();
2014-12-01 23:55:08 +01:00
/***** Get list of institutions *****/
Ins_GetFullListOfInstitutions (Gbl.Hierarchy.Node[Hie_CTY].HieCod);
2014-12-01 23:55:08 +01:00
/***** Write menu to select country *****/
2016-11-14 17:26:32 +01:00
Hie_WriteMenuHierarchy ();
2014-12-01 23:55:08 +01:00
/***** List institutions *****/
2015-10-06 01:19:21 +02:00
Ins_ListInstitutions ();
2014-12-01 23:55:08 +01:00
/***** Free list of institutions *****/
Hie_FreeList (Hie_CTY);
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/*************** List the institutions of the current country ****************/
/*****************************************************************************/
2015-10-06 01:19:21 +02:00
static void Ins_ListInstitutions (void)
{
2016-11-13 14:56:59 +01:00
extern const char *Hlp_COUNTRY_Institutions;
2016-03-20 14:11:04 +01:00
extern const char *Txt_Institutions_of_COUNTRY_X;
extern const char *Txt_No_institutions;
char *Title;
2016-03-20 14:11:04 +01:00
unsigned NumIns;
2015-10-06 01:19:21 +02:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
if (asprintf (&Title,Txt_Institutions_of_COUNTRY_X,
Gbl.Hierarchy.Node[Hie_CTY].FullName) < 0)
Err_NotEnoughMemoryExit ();
Box_BoxBegin (Title,Ins_PutIconsListingInstitutions,NULL,
2017-06-12 15:03:29 +02:00
Hlp_COUNTRY_Institutions,Box_NOT_CLOSABLE);
free (Title);
2016-03-20 14:11:04 +01:00
if (Gbl.Hierarchy.List[Hie_CTY].Num) // There are institutions in the current country
{
/***** Begin table *****/
HTM_TABLE_Begin ("TBL_SCROLL");
/***** Heading *****/
Ins_PutHeadInstitutionsForSeeing (true); // Order selectable
/***** Write all institutions and their nuber of users *****/
for (NumIns = 0, The_ResetRowColor ();
NumIns < Gbl.Hierarchy.List[Hie_CTY].Num;
NumIns++, The_ChangeRowColor ())
Ins_ListOneInstitutionForSeeing (&(Gbl.Hierarchy.List[Hie_CTY].Lst[NumIns]),
NumIns + 1);
/***** End table *****/
HTM_TABLE_End ();
}
else // No insrtitutions created in the current country
Ale_ShowAlert (Ale_INFO,Txt_No_institutions);
2016-03-20 14:11:04 +01:00
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2014-12-01 23:55:08 +01:00
}
2016-11-06 21:51:21 +01:00
/*****************************************************************************/
/*************** Put contextual icons in list of institutions ****************/
/*****************************************************************************/
2020-04-08 18:18:46 +02:00
static void Ins_PutIconsListingInstitutions (__attribute__((unused)) void *Args)
2016-11-06 21:51:21 +01:00
{
2020-04-08 18:18:46 +02:00
/***** Put icon to edit institutions *****/
if (Hie_CheckIfICanEdit () == Usr_CAN)
2020-04-08 18:18:46 +02:00
Ins_PutIconToEditInstitutions ();
2016-11-06 21:51:21 +01:00
2020-04-08 18:18:46 +02:00
/***** Put icon to show a figure *****/
Fig_PutIconToShowFigure (Fig_INSTITS);
2016-11-06 21:51:21 +01:00
}
2016-03-16 13:23:10 +01:00
/*****************************************************************************/
/******************** Put link (form) to edit institutions *******************/
/*****************************************************************************/
2016-03-16 22:40:35 +01:00
static void Ins_PutIconToEditInstitutions (void)
2016-03-16 13:23:10 +01:00
{
Ico_PutContextualIconToEdit (ActEdiIns,NULL,NULL,NULL);
2016-03-16 13:23:10 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************** List one institution for seeing **********************/
/*****************************************************************************/
static void Ins_ListOneInstitutionForSeeing (struct Hie_Node *Ins,unsigned NumIns)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_INSTITUTION_STATUS[Hie_NUM_STATUS_TXT];
2015-11-19 16:09:51 +01:00
const char *TxtClassNormal;
const char *TxtClassStrong;
2015-09-04 19:26:08 +02:00
const char *BgColor;
2014-12-01 23:55:08 +01:00
if (Ins->Status & Hie_STATUS_BIT_PENDING)
2015-11-19 16:09:51 +01:00
{
TxtClassNormal =
TxtClassStrong = "DAT_LIGHT";
2015-11-19 16:09:51 +01:00
}
else
{
TxtClassNormal = "DAT";
TxtClassStrong = "DAT_STRONG";
2015-11-19 16:09:51 +01:00
}
BgColor = (Ins->HieCod == Gbl.Hierarchy.Node[Hie_INS].HieCod) ? "BG_HIGHLIGHT" :
The_GetColorRows ();
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 17:36:41 +02:00
/***** Number of institution in this list *****/
HTM_TD_Begin ("class=\"RT %s_%s %s\"",
TxtClassNormal,The_GetSuffix (),BgColor);
HTM_Unsigned (NumIns);
HTM_TD_End ();
/***** Institution logo and name *****/
HTM_TD_Begin ("class=\"LT %s_%s %s\"",
TxtClassStrong,The_GetSuffix (),BgColor);
Ins_DrawInstitLogoAndNameWithLink (Ins,ActSeeCtr,"CT ICO16x16");
HTM_TD_End ();
/***** Number of users who claim to belong to this institution *****/
HTM_TD_Begin ("class=\"RT %s_%s %s\"",
TxtClassNormal,The_GetSuffix (),BgColor);
HTM_Unsigned (Hie_GetCachedNumUsrsWhoClaimToBelongTo (Hie_INS,Ins));
HTM_TD_End ();
/***** Other stats *****/
/* Number of centers in this institution */
HTM_TD_Begin ("class=\"RT %s_%s %s\"",
TxtClassNormal,The_GetSuffix (),BgColor);
HTM_Unsigned (Hie_GetCachedNumNodesInHieLvl (Hie_CTR, // Number of centers...
Hie_INS, // ...in institution
Ins->HieCod));
HTM_TD_End ();
/* Number of degrees in this institution */
HTM_TD_Begin ("class=\"RT %s_%s %s\"",
TxtClassNormal,The_GetSuffix (),BgColor);
HTM_Unsigned (Hie_GetCachedNumNodesInHieLvl (Hie_DEG, // Number of degrees...
Hie_INS, // ...in institution
Ins->HieCod));
HTM_TD_End ();
/* Number of courses in this institution */
HTM_TD_Begin ("class=\"RT %s_%s %s\"",
TxtClassNormal,The_GetSuffix (),BgColor);
HTM_Unsigned (Hie_GetCachedNumNodesInHieLvl (Hie_CRS, // Number of courses...
Hie_INS, // ...in institution
Ins->HieCod));
HTM_TD_End ();
/* Number of departments in this institution */
HTM_TD_Begin ("class=\"RT %s_%s %s\"",
TxtClassNormal,The_GetSuffix (),BgColor);
HTM_Unsigned (Dpt_GetNumDptsInIns (Ins->HieCod));
HTM_TD_End ();
/* Number of users in courses of this institution */
HTM_TD_Begin ("class=\"RT %s_%s %s\"",
TxtClassNormal,The_GetSuffix (),BgColor);
HTM_Unsigned (Enr_GetCachedNumUsrsInCrss (Hie_INS,Ins->HieCod,
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH)); // Any user);
HTM_TD_End ();
/***** Institution status *****/
Hie_WriteStatusCell (Ins->Status,TxtClassNormal,BgColor,Txt_INSTITUTION_STATUS);
2019-10-07 17:36:41 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/**************** Write header with fields of an institution *****************/
/*****************************************************************************/
static void Ins_PutHeadInstitutionsForSeeing (bool OrderSelectable)
{
extern const char *Txt_INSTITUTIONS_HELP_ORDER[2];
extern const char *Txt_INSTITUTIONS_ORDER[2];
2017-05-30 21:43:05 +02:00
extern const char *Txt_ROLES_PLURAL_BRIEF_Abc[Rol_NUM_ROLES];
extern const char *Txt_Centers_ABBREVIATION;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Degrees_ABBREVIATION;
2015-12-09 19:51:17 +01:00
extern const char *Txt_Courses_ABBREVIATION;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Departments_ABBREVIATION;
Hie_Order_t Order;
static HTM_HeadAlign Align[Hie_NUM_ORDERS] =
2020-01-07 22:25:05 +01:00
{
[Hie_ORDER_BY_NAME ] = HTM_HEAD_LEFT,
[Hie_ORDER_BY_NUM_USRS] = HTM_HEAD_RIGHT
2020-01-07 22:25:05 +01:00
};
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
HTM_TH_Empty (1);
for (Order = (Hie_Order_t) 0;
Order <= (Hie_Order_t) (Hie_NUM_ORDERS - 1);
Order++)
2014-12-01 23:55:08 +01:00
{
HTM_TH_Begin (Align[Order]);
if (OrderSelectable)
{
Frm_BeginForm (ActSeeIns);
Par_PutParUnsigned (NULL,"Order",(unsigned) Order);
HTM_BUTTON_Submit_Begin (Txt_INSTITUTIONS_HELP_ORDER[Order],
"class=\"BT_LINK RT\"");
if (Order == Gbl.Hierarchy.List[Hie_CTY].SelectedOrder)
HTM_U_Begin ();
}
HTM_Txt (Txt_INSTITUTIONS_ORDER[Order]);
if (OrderSelectable)
{
if (Order == Gbl.Hierarchy.List[Hie_CTY].SelectedOrder)
HTM_U_End ();
HTM_BUTTON_End ();
Frm_EndForm ();
}
HTM_TH_End ();
2014-12-01 23:55:08 +01:00
}
HTM_TH (Txt_Centers_ABBREVIATION ,HTM_HEAD_RIGHT);
HTM_TH (Txt_Degrees_ABBREVIATION ,HTM_HEAD_RIGHT);
HTM_TH (Txt_Courses_ABBREVIATION ,HTM_HEAD_RIGHT);
HTM_TH (Txt_Departments_ABBREVIATION,HTM_HEAD_RIGHT);
HTM_TH_Begin (HTM_HEAD_RIGHT);
HTM_TxtF ("%s+",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]);
HTM_BR ();
HTM_Txt (Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD]);
2019-10-23 19:05:05 +02:00
HTM_TH_End ();
HTM_TH_Empty (1);
2019-10-12 00:07:52 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-10-05 13:09:24 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************ Put forms to edit institutions *********************/
/*****************************************************************************/
void Ins_EditInstitutions (void)
2019-04-06 20:43:31 +02:00
{
/***** Institution constructor *****/
Ins_EditingInstitutionConstructor ();
/***** Edit institutions *****/
Ins_EditInstitutionsInternal ();
/***** Institution destructor *****/
Ins_EditingInstitutionDestructor ();
}
static void Ins_EditInstitutionsInternal (void)
2014-12-01 23:55:08 +01:00
{
2017-04-30 01:20:18 +02:00
extern const char *Hlp_COUNTRY_Institutions;
extern const char *Txt_Institutions_of_COUNTRY_X;
char *Title;
2017-04-30 01:20:18 +02:00
2014-12-01 23:55:08 +01:00
/***** Get list of institutions *****/
Ins_GetFullListOfInstitutions (Gbl.Hierarchy.Node[Hie_CTY].HieCod);
2014-12-01 23:55:08 +01:00
2018-11-15 12:21:48 +01:00
/***** Write menu to select country *****/
Hie_WriteMenuHierarchy ();
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
if (asprintf (&Title,Txt_Institutions_of_COUNTRY_X,
Gbl.Hierarchy.Node[Hie_CTY].FullName) < 0)
Err_NotEnoughMemoryExit ();
Box_BoxBegin (Title,Ins_PutIconsEditingInstitutions,NULL,
2017-06-12 15:03:29 +02:00
Hlp_COUNTRY_Institutions,Box_NOT_CLOSABLE);
free (Title);
2017-04-30 01:20:18 +02:00
/***** Put a form to create a new institution *****/
Ins_PutFormToCreateInstitution ();
2014-12-01 23:55:08 +01:00
/***** Forms to edit current institutions *****/
if (Gbl.Hierarchy.List[Hie_CTY].Num)
Ins_ListInstitutionsForEdition ();
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2017-04-30 01:20:18 +02:00
2014-12-01 23:55:08 +01:00
/***** Free list of institutions *****/
Hie_FreeList (Hie_CTY);
2014-12-01 23:55:08 +01:00
}
2017-04-30 01:20:18 +02:00
/*****************************************************************************/
2018-11-15 12:21:48 +01:00
/************ Put contextual icons in edition of institutions ****************/
/*****************************************************************************/
2020-04-08 18:18:46 +02:00
static void Ins_PutIconsEditingInstitutions (__attribute__((unused)) void *Args)
2018-11-15 12:21:48 +01:00
{
2020-04-08 18:18:46 +02:00
/***** Put icon to view institutions *****/
Ico_PutContextualIconToView (ActSeeIns,NULL,NULL,NULL);
2018-11-15 12:21:48 +01:00
2020-04-08 18:18:46 +02:00
/***** Put icon to show a figure *****/
Fig_PutIconToShowFigure (Fig_INSTITS);
2018-11-15 12:21:48 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2020-01-07 22:07:06 +01:00
/******* Get basic list of institutions ordered by name of institution *******/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2020-01-07 22:07:06 +01:00
void Ins_GetBasicListOfInstitutions (long CtyCod)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
unsigned NumIns;
/***** Get institutions from database *****/
if ((Gbl.Hierarchy.List[Hie_CTY].Num = Ins_DB_GetInssInCtyOrderedByFullName (&mysql_res,CtyCod))) // Institutions found...
2014-12-01 23:55:08 +01:00
{
/***** Create list with institutions *****/
if ((Gbl.Hierarchy.List[Hie_CTY].Lst = calloc ((size_t) Gbl.Hierarchy.List[Hie_CTY].Num,
sizeof (*Gbl.Hierarchy.List[Hie_CTY].Lst))) == NULL)
Err_NotEnoughMemoryExit ();
2014-12-01 23:55:08 +01:00
/***** Get the institutions *****/
for (NumIns = 0;
NumIns < Gbl.Hierarchy.List[Hie_CTY].Num;
2014-12-01 23:55:08 +01:00
NumIns++)
2020-01-07 22:07:06 +01:00
/* Get institution data */
Ins_GetInstitDataFromRow (mysql_res,&Gbl.Hierarchy.List[Hie_CTY].Lst[NumIns],
false); // Don't get number of users who claim to belong to this institution
2020-01-07 22:07:06 +01:00
}
else
Gbl.Hierarchy.List[Hie_CTY].Lst = NULL;
2014-12-01 23:55:08 +01:00
2020-01-07 22:07:06 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2014-12-01 23:55:08 +01:00
2020-01-07 22:07:06 +01:00
/*****************************************************************************/
/************* Get full list of institutions **************/
/************* with number of users who claim to belong to them **************/
/*****************************************************************************/
2014-12-01 23:55:08 +01:00
2020-01-07 22:07:06 +01:00
void Ins_GetFullListOfInstitutions (long CtyCod)
{
MYSQL_RES *mysql_res;
unsigned NumIns;
2014-12-01 23:55:08 +01:00
2020-01-07 22:07:06 +01:00
/***** Get institutions from database *****/
if ((Gbl.Hierarchy.List[Hie_CTY].Num = Ins_DB_GetFullListOfInssInCty (&mysql_res,CtyCod))) // Institutions found...
2020-01-07 22:07:06 +01:00
{
/***** Create list with institutions *****/
if ((Gbl.Hierarchy.List[Hie_CTY].Lst = calloc ((size_t) Gbl.Hierarchy.List[Hie_CTY].Num,
sizeof (*Gbl.Hierarchy.List[Hie_CTY].Lst))) == NULL)
Err_NotEnoughMemoryExit ();
2020-01-07 22:07:06 +01:00
/***** Get the institutions *****/
for (NumIns = 0;
NumIns < Gbl.Hierarchy.List[Hie_CTY].Num;
2020-01-07 22:07:06 +01:00
NumIns++)
/* Get institution data */
Ins_GetInstitDataFromRow (mysql_res,&Gbl.Hierarchy.List[Hie_CTY].Lst[NumIns],
true); // Get number of users who claim to belong to this institution
2014-12-01 23:55:08 +01:00
}
else
Gbl.Hierarchy.List[Hie_CTY].Lst = NULL;
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2017-03-02 00:53:34 +01:00
/*****************************************************************************/
/***************** Write institution full name and country *******************/
/*****************************************************************************/
// If ClassLink == NULL ==> do not put link
void Ins_WriteInstitutionNameAndCty (long InsCod)
{
struct Hie_Node Ins;
char CtyName[Nam_MAX_BYTES_FULL_NAME + 1];
2017-03-02 00:53:34 +01:00
2019-03-07 13:00:18 +01:00
/***** Get institution short name and country name *****/
Ins.HieCod = InsCod;
2019-03-07 13:00:18 +01:00
Ins_GetShrtNameAndCtyOfInstitution (&Ins,CtyName);
2017-03-02 00:53:34 +01:00
2019-03-07 13:00:18 +01:00
/***** Write institution short name and country name *****/
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s&nbsp;(%s)",Ins.ShrtName,CtyName);
2017-03-02 00:53:34 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************* Get data of an institution ************************/
/*****************************************************************************/
bool Ins_GetInstitDataByCod (struct Hie_Node *Node)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
bool Found = false;
2014-12-01 23:55:08 +01:00
/***** Clear data *****/
Node->PrtCod = -1L;
Node->Status = (Hie_Status_t) 0;
Node->RequesterUsrCod = -1L;
Node->ShrtName[0] =
Node->FullName[0] =
Node->WWW[0] = '\0';
Node->NumUsrsWhoClaimToBelong.Valid = false;
2014-12-01 23:55:08 +01:00
/***** Check if institution code is correct *****/
if (Node->HieCod > 0)
2014-12-01 23:55:08 +01:00
{
2016-12-30 01:20:49 +01:00
/***** Get data of an institution from database *****/
if (Ins_DB_GetInsDataByCod (&mysql_res,Node->HieCod)) // Institution found...
2016-12-30 01:20:49 +01:00
{
2020-01-07 22:07:06 +01:00
/* Get institution data */
Ins_GetInstitDataFromRow (mysql_res,Node,
false); // Don't get number of users who claim to belong to this institution
2014-12-01 23:55:08 +01:00
2016-12-30 01:20:49 +01:00
/* Set return value */
Found = true;
2014-12-01 23:55:08 +01:00
}
2016-12-30 01:20:49 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2014-12-01 23:55:08 +01:00
return Found;
2014-12-01 23:55:08 +01:00
}
2020-01-07 22:07:06 +01:00
/*****************************************************************************/
/********** Get data of a center from a row resulting of a query *************/
2020-01-07 22:07:06 +01:00
/*****************************************************************************/
static void Ins_GetInstitDataFromRow (MYSQL_RES *mysql_res,
struct Hie_Node *Ins,
bool GetNumUsrsWhoClaimToBelongToIns)
2020-01-07 22:07:06 +01:00
{
MYSQL_ROW row;
/***** Get next row from result *****/
row = mysql_fetch_row (mysql_res);
/*
row[0]: InsCod
row[1]: CtyCod
row[2]: Status
row[3]: RequesterUsrCod
row[4]: ShortName
row[5]: FullName
row[6]: WWW
row[7]: number of users who claim to belong to this institution
*/
2020-01-07 22:07:06 +01:00
/***** Get institution code (row[0]) *****/
if ((Ins->HieCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
Err_WrongInstitExit ();
2020-01-07 22:07:06 +01:00
/***** Get country code (row[1]) *****/
Ins->PrtCod = Str_ConvertStrCodToLongCod (row[1]);
2020-01-07 22:07:06 +01:00
/***** Get institution status (row[2]) *****/
if (sscanf (row[2],"%u",&(Ins->Status)) != 1)
Err_WrongStatusExit ();
2020-01-07 22:07:06 +01:00
/***** Get requester user's code (row[3]) *****/
Ins->RequesterUsrCod = Str_ConvertStrCodToLongCod (row[3]);
/***** Get short name (row[4]), full name (row[5])
and URL (row[6]) of the institution *****/
Str_Copy (Ins->ShrtName,row[4],sizeof (Ins->ShrtName) - 1);
Str_Copy (Ins->FullName,row[5],sizeof (Ins->FullName) - 1);
Str_Copy (Ins->WWW ,row[6],sizeof (Ins->WWW ) - 1);
/***** Get number of users who claim to belong to this institution (row[7]) *****/
Ins->NumUsrsWhoClaimToBelong.Valid = false;
if (GetNumUsrsWhoClaimToBelongToIns)
if (sscanf (row[7],"%u",&(Ins->NumUsrsWhoClaimToBelong.NumUsrs)) == 1)
Ins->NumUsrsWhoClaimToBelong.Valid = true;
2020-01-07 22:07:06 +01:00
}
2017-03-02 00:53:34 +01:00
/*****************************************************************************/
/******** Get short name and country of an institution from its code *********/
2017-03-02 00:53:34 +01:00
/*****************************************************************************/
2017-06-20 14:43:26 +02:00
void Ins_FlushCacheFullNameAndCtyOfInstitution (void)
{
Gbl.Cache.InstitutionShrtNameAndCty.Valid = false;
2017-06-20 14:43:26 +02:00
}
void Ins_GetShrtNameAndCtyOfInstitution (struct Hie_Node *Ins,
char CtyName[Nam_MAX_BYTES_FULL_NAME + 1])
2017-03-02 00:53:34 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2017-06-20 14:43:26 +02:00
/***** 1. Fast check: Trivial case *****/
if (Ins->HieCod <= 0)
2017-03-02 00:53:34 +01:00
{
2019-03-07 13:00:18 +01:00
Ins->ShrtName[0] = '\0'; // Empty name
2017-03-02 00:53:34 +01:00
CtyName[0] = '\0'; // Empty name
2017-06-20 14:43:26 +02:00
return;
2017-03-02 00:53:34 +01:00
}
2017-06-20 14:43:26 +02:00
/***** 2. Fast check: If cached... *****/
if (Gbl.Cache.InstitutionShrtNameAndCty.Valid &&
Ins->HieCod == Gbl.Cache.InstitutionShrtNameAndCty.HieCod)
2017-06-20 14:43:26 +02:00
{
2019-03-07 13:00:18 +01:00
Str_Copy (Ins->ShrtName,Gbl.Cache.InstitutionShrtNameAndCty.ShrtName,
sizeof (Ins->ShrtName) - 1);
2019-03-07 13:00:18 +01:00
Str_Copy (CtyName,Gbl.Cache.InstitutionShrtNameAndCty.CtyName,
Nam_MAX_BYTES_FULL_NAME);
2017-06-20 14:43:26 +02:00
return;
}
2017-03-02 00:53:34 +01:00
2019-03-07 13:00:18 +01:00
/***** 3. Slow: get short name and country of institution from database *****/
Gbl.Cache.InstitutionShrtNameAndCty.HieCod = Ins->HieCod;
2017-03-02 00:53:34 +01:00
if (Ins_DB_GetInsShrtNameAndCty (&mysql_res,Ins->HieCod) == 1)
2017-06-20 14:43:26 +02:00
{
/* Get row */
row = mysql_fetch_row (mysql_res);
2017-03-02 00:53:34 +01:00
/* Get short name (row[0]) and country name (row[1]) of this institution */
2019-03-07 13:00:18 +01:00
Str_Copy (Gbl.Cache.InstitutionShrtNameAndCty.ShrtName,row[0],
sizeof (Gbl.Cache.InstitutionShrtNameAndCty.ShrtName) - 1);
Str_Copy (Gbl.Cache.InstitutionShrtNameAndCty.CtyName ,row[1],
sizeof (Gbl.Cache.InstitutionShrtNameAndCty.CtyName ) - 1);
2015-10-10 22:16:46 +02:00
}
2017-06-20 14:43:26 +02:00
else
{
2019-03-07 13:00:18 +01:00
Gbl.Cache.InstitutionShrtNameAndCty.ShrtName[0] = '\0';
Gbl.Cache.InstitutionShrtNameAndCty.CtyName [0] = '\0';
2017-06-20 14:43:26 +02:00
}
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
2019-03-07 13:00:18 +01:00
Str_Copy (Ins->ShrtName,Gbl.Cache.InstitutionShrtNameAndCty.ShrtName,
sizeof (Ins->ShrtName) - 1);
Str_Copy (CtyName ,Gbl.Cache.InstitutionShrtNameAndCty.CtyName ,
Nam_MAX_BYTES_FULL_NAME);
Gbl.Cache.InstitutionShrtNameAndCty.Valid = true;
2015-10-10 22:16:46 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************ Write selector of institution **********************/
/*****************************************************************************/
2015-07-25 20:20:07 +02:00
void Ins_WriteSelectorOfInstitution (void)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_HIERARCHY_SINGUL_Abc[Hie_NUM_LEVELS];
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumInss;
unsigned NumIns;
long InsCod;
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
Frm_BeginFormGoTo (ActSeeCtr);
2014-12-01 23:55:08 +01:00
/***** Begin selector *****/
if (Gbl.Hierarchy.Node[Hie_CTY].HieCod > 0)
HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE,NULL,
"id=\"ins\" name=\"ins\" class=\"HIE_SEL INPUT_%s\"",
The_GetSuffix ());
else
HTM_SELECT_Begin (HTM_DONT_SUBMIT_ON_CHANGE,NULL,
"id=\"ins\" name=\"ins\" class=\"HIE_SEL INPUT_%s\""
" disabled=\"disabled\"",
The_GetSuffix ());
2014-12-01 23:55:08 +01:00
HTM_OPTION (HTM_Type_STRING,"",
Gbl.Hierarchy.Node[Hie_INS].HieCod < 0 ? HTM_OPTION_SELECTED :
HTM_OPTION_UNSELECTED,
HTM_OPTION_DISABLED,
"[%s]",Txt_HIERARCHY_SINGUL_Abc[Hie_INS]);
2014-12-01 23:55:08 +01:00
if (Gbl.Hierarchy.Node[Hie_CTY].HieCod > 0)
{
/***** Get institutions of current country *****/
NumInss = Ins_DB_GetInssInCtyOrderedByShrtName (&mysql_res,Gbl.Hierarchy.Node[Hie_CTY].HieCod);
/***** List institutions *****/
for (NumIns = 0;
NumIns < NumInss;
NumIns++)
{
/* Get next institution */
row = mysql_fetch_row (mysql_res);
/* Get institution code (row[0]) */
if ((InsCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
Err_WrongInstitExit ();
/* Write option */
HTM_OPTION (HTM_Type_LONG,&InsCod,
Gbl.Hierarchy.Node[Hie_INS].HieCod > 0 &&
InsCod == Gbl.Hierarchy.Node[Hie_INS].HieCod ? HTM_OPTION_SELECTED :
HTM_OPTION_UNSELECTED,
HTM_OPTION_ENABLED,
"%s",row[1]);
}
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2014-12-01 23:55:08 +01:00
/***** End selector *****/
HTM_SELECT_End ();
2014-12-01 23:55:08 +01:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************************** List all institutions ***************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2019-04-06 20:43:31 +02:00
static void Ins_ListInstitutionsForEdition (void)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_INSTITUTION_STATUS[Hie_NUM_STATUS_TXT];
static Act_Action_t ActionRename[Nam_NUM_SHRT_FULL_NAMES] =
{
[Nam_SHRT_NAME] = ActRenInsSho,
[Nam_FULL_NAME] = ActRenInsFul,
};
2014-12-01 23:55:08 +01:00
unsigned NumIns;
struct Hie_Node *Ins;
2017-03-07 01:56:41 +01:00
char WWW[Cns_MAX_BYTES_WWW + 1];
struct Usr_Data UsrDat;
Usr_Can_t ICanEdit;
2020-05-03 21:56:55 +02:00
unsigned NumCtrs;
2020-05-03 20:58:03 +02:00
unsigned NumUsrsIns;
2020-01-06 11:58:05 +01:00
unsigned NumUsrsInCrssOfIns;
const char *Names[Nam_NUM_SHRT_FULL_NAMES];
2014-12-01 23:55:08 +01:00
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** Begin table *****/
HTM_TABLE_Begin ("TBL_SCROLL");
2014-12-01 23:55:08 +01:00
/***** Write heading *****/
Ins_PutHeadInstitutionsForEdition ();
/***** Write all institutions *****/
for (NumIns = 0;
NumIns < Gbl.Hierarchy.List[Hie_CTY].Num;
NumIns++)
{
Ins = &Gbl.Hierarchy.List[Hie_CTY].Lst[NumIns];
ICanEdit = Ins_CheckIfICanEdit (Ins);
NumCtrs = Hie_GetNumNodesInHieLvl (Hie_CTR, // Number of centers...
Hie_INS, // ...in institution
Ins->HieCod);
NumUsrsIns = Hie_GetNumUsrsWhoClaimToBelongTo (Hie_INS,Ins);
NumUsrsInCrssOfIns = Enr_GetNumUsrsInCrss (Hie_INS,Ins->HieCod,
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH); // Any user
HTM_TR_Begin (NULL);
/* Put icon to remove institution */
HTM_TD_Begin ("class=\"BT\"");
if (ICanEdit == Usr_CAN_NOT ||
NumCtrs || // Institution has centers
NumUsrsIns || // Institution has users
NumUsrsInCrssOfIns) // Institution has users
// Institution has centers or users ==> deletion forbidden
Ico_PutIconRemovalNotAllowed ();
else
Ico_PutContextualIconToRemove (ActRemIns,NULL,
Hie_PutParOtherHieCod,&Ins->HieCod);
HTM_TD_End ();
/* Institution code */
HTM_TD_Begin ("class=\"CODE DAT_%s\"",The_GetSuffix ());
HTM_Long (Ins->HieCod);
HTM_TD_End ();
/* Institution logo */
HTM_TD_Begin ("title=\"%s\" class=\"HIE_LOGO\"",Ins->FullName);
Lgo_DrawLogo (Hie_INS,Ins,"ICO20x20");
HTM_TD_End ();
/* Institution short name and full name */
Names[Nam_SHRT_NAME] = Ins->ShrtName;
Names[Nam_FULL_NAME] = Ins->FullName;
Nam_ExistingShortAndFullNames (ActionRename,
ParCod_OthHie,Ins->HieCod,
Names,
ICanEdit == Usr_CAN ? Frm_PUT_FORM :
Frm_DONT_PUT_FORM);
/* Institution WWW */
HTM_TD_Begin ("class=\"LT DAT_%s\"",The_GetSuffix ());
switch (ICanEdit)
{
case Usr_CAN:
Frm_BeginForm (ActChgInsWWW);
ParCod_PutPar (ParCod_OthHie,Ins->HieCod);
HTM_INPUT_URL ("WWW",Ins->WWW,HTM_SUBMIT_ON_CHANGE,
"class=\"INPUT_WWW INPUT_%s\""
" required=\"required\"",
The_GetSuffix ());
Frm_EndForm ();
break;
case Usr_CAN_NOT:
default:
Str_Copy (WWW,Ins->WWW,sizeof (WWW) - 1);
HTM_DIV_Begin ("class=\"EXTERNAL_WWW_SHRT\"");
HTM_A_Begin ("href=\"%s\" target=\"_blank\" title=\"%s\""
" class=\"DAT_%s\"",
Ins->WWW,
The_GetSuffix (),
Ins->WWW);
HTM_Txt (WWW);
HTM_A_End ();
HTM_DIV_End ();
break;
}
HTM_TD_End ();
/* Number of users who claim to belong to this institution */
HTM_TD_Unsigned (NumUsrsIns);
/* Number of centers */
HTM_TD_Unsigned (NumCtrs);
/* Number of users in courses of this institution */
HTM_TD_Unsigned (NumUsrsInCrssOfIns);
/* Institution requester */
HTM_TD_Begin ("class=\"LT DAT_%s INPUT_REQUESTER\"",
The_GetSuffix ());
UsrDat.UsrCod = Ins->RequesterUsrCod;
Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CRS);
Usr_WriteAuthor (&UsrDat,Cns_ENABLED);
HTM_TD_End ();
/* Institution status */
Hie_WriteStatusCellEditable (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM ? Usr_CAN :
Usr_CAN_NOT,
Ins->Status,ActChgInsSta,Ins->HieCod,
Txt_INSTITUTION_STATUS);
HTM_TR_End ();
}
2014-12-01 23:55:08 +01:00
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2014-12-01 23:55:08 +01:00
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}
/*****************************************************************************/
/************ Check if I can edit, remove, etc. an institution ***************/
/*****************************************************************************/
static Usr_Can_t Ins_CheckIfICanEdit (struct Hie_Node *Ins)
2014-12-01 23:55:08 +01:00
{
return (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM || // I am a superuser
((Ins->Status & Hie_STATUS_BIT_PENDING) != 0 && // Institution is not yet activated
Gbl.Usrs.Me.UsrDat.UsrCod == Ins->RequesterUsrCod)) ? Usr_CAN : // I am the requester
Usr_CAN_NOT;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/**************************** Remove a institution ***************************/
/*****************************************************************************/
void Ins_RemoveInstitution (void)
{
extern bool (*Hie_GetDataByCod[Hie_NUM_LEVELS]) (struct Hie_Node *Node);
extern const char *Txt_To_remove_an_institution_you_must_first_remove_all_centers_and_users_in_the_institution;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Institution_X_removed;
2017-01-28 15:58:46 +01:00
char PathIns[PATH_MAX + 1];
2014-12-01 23:55:08 +01:00
2019-04-06 20:43:31 +02:00
/***** Institution constructor *****/
Ins_EditingInstitutionConstructor ();
2014-12-01 23:55:08 +01:00
/***** Get institution code *****/
Ins_EditingIns->HieCod = ParCod_GetAndCheckPar (ParCod_OthHie);
2014-12-01 23:55:08 +01:00
/***** Get data of the institution from database *****/
Hie_GetDataByCod[Hie_INS] (Ins_EditingIns);
2014-12-01 23:55:08 +01:00
/***** Check if I can edit this institution *****/
if (Ins_CheckIfICanEdit (Ins_EditingIns) == Usr_CAN_NOT)
Err_NoPermissionExit ();
/***** Check if this institution has centers or users *****/
if (Hie_GetNumNodesInHieLvl (Hie_CTR, // Number of centers...
Hie_INS, // ...in institution
Ins_EditingIns->HieCod))
// Institution has centers ==> don't remove
2020-01-06 11:58:05 +01:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_To_remove_an_institution_you_must_first_remove_all_centers_and_users_in_the_institution);
else if (Hie_GetNumUsrsWhoClaimToBelongTo (Hie_INS,Ins_EditingIns))
2020-01-06 11:58:05 +01:00
// Institution has users ==> don't remove
2019-04-08 15:33:29 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_To_remove_an_institution_you_must_first_remove_all_centers_and_users_in_the_institution);
else if (Enr_GetNumUsrsInCrss (Hie_INS,Ins_EditingIns->HieCod,
2020-01-08 23:49:04 +01:00
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH)) // Any user
2020-01-06 18:00:23 +01:00
// Institution has users ==> don't remove
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_To_remove_an_institution_you_must_first_remove_all_centers_and_users_in_the_institution);
2014-12-01 23:55:08 +01:00
else // Institution has no users ==> remove it
{
/***** Remove all threads and posts in forums of the institution *****/
For_DB_RemoveForums (Hie_INS,Ins_EditingIns->HieCod);
2016-10-28 00:25:31 +02:00
/***** Remove surveys of the institution *****/
Svy_RemoveSurveys (Hie_INS,Ins_EditingIns->HieCod);
2016-10-28 00:25:31 +02:00
2015-01-20 02:00:42 +01:00
/***** Remove information related to files in institution *****/
Brw_DB_RemoveInsFiles (Ins_EditingIns->HieCod);
2015-01-25 18:50:43 +01:00
/***** Remove directories of the institution *****/
snprintf (PathIns,sizeof (PathIns),"%s/%02u/%u",
2019-03-20 01:36:36 +01:00
Cfg_PATH_INS_PUBLIC,
(unsigned) (Ins_EditingIns->HieCod % 100),
(unsigned) Ins_EditingIns->HieCod);
2016-10-06 22:18:33 +02:00
Fil_RemoveTree (PathIns);
2015-01-20 18:55:59 +01:00
/***** Remove administrators of this institution *****/
Adm_DB_RemAdmins (Hie_INS,Ins_EditingIns->HieCod);
2014-12-01 23:55:08 +01:00
/***** Remove institution *****/
Ins_DB_RemoveInstitution (Ins_EditingIns->HieCod);
2014-12-01 23:55:08 +01:00
2017-06-20 14:43:26 +02:00
/***** Flush caches *****/
Ins_FlushCacheFullNameAndCtyOfInstitution ();
2020-01-06 18:27:43 +01:00
Dpt_FlushCacheNumDptsInIns ();
Hie_FlushCachedNumNodesInHieLvl (Hie_CTR,Hie_INS); // Number of centers in institution
Hie_FlushCachedNumNodesInHieLvl (Hie_DEG,Hie_INS); // Number of degrees in institution
Hie_FlushCachedNumNodesInHieLvl (Hie_CRS,Hie_INS); // Number of courses in institution
Hie_FlushCacheNumUsrsWhoClaimToBelongTo (Hie_INS);
2017-06-20 14:43:26 +02:00
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2019-04-08 15:33:29 +02:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_Institution_X_removed,
Ins_EditingIns->FullName);
2019-06-13 10:14:05 +02:00
Ins_EditingIns->HieCod = -1L; // To not showing button to go to institution
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
2019-05-16 14:22:10 +02:00
/********************* Change the name of an institution *********************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
void Ins_RenameInsShort (void)
{
2019-04-04 14:48:05 +02:00
/***** Institution constructor *****/
2019-04-06 20:43:31 +02:00
Ins_EditingInstitutionConstructor ();
2019-04-04 14:48:05 +02:00
/***** Rename institution *****/
Ins_EditingIns->HieCod = ParCod_GetAndCheckPar (ParCod_OthHie);
Ins_RenameInstitution (Ins_EditingIns,Nam_SHRT_NAME);
2014-12-01 23:55:08 +01:00
}
2019-04-06 20:43:31 +02:00
void Ins_RenameInsFull (void)
2016-10-22 18:24:57 +02:00
{
2019-04-04 14:48:05 +02:00
/***** Institution constructor *****/
2019-04-06 20:43:31 +02:00
Ins_EditingInstitutionConstructor ();
2019-04-04 14:48:05 +02:00
/***** Rename institution *****/
Ins_EditingIns->HieCod = ParCod_GetAndCheckPar (ParCod_OthHie);
Ins_RenameInstitution (Ins_EditingIns,Nam_FULL_NAME);
2019-04-06 20:43:31 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/******************** Change the name of an institution **********************/
/*****************************************************************************/
void Ins_RenameInstitution (struct Hie_Node *Ins,Nam_ShrtOrFullName_t ShrtOrFull)
2014-12-01 23:55:08 +01:00
{
extern bool (*Hie_GetDataByCod[Hie_NUM_LEVELS]) (struct Hie_Node *Node);
extern const char *Nam_Fields[Nam_NUM_SHRT_FULL_NAMES];
extern unsigned Nam_MaxBytes[Nam_NUM_SHRT_FULL_NAMES];
extern const char *Txt_X_already_exists;
2016-03-01 23:58:48 +01:00
extern const char *Txt_The_institution_X_has_been_renamed_as_Y;
extern const char *Txt_The_name_X_has_not_changed;
char *CurrentName[Nam_NUM_SHRT_FULL_NAMES] =
2014-12-01 23:55:08 +01:00
{
[Nam_SHRT_NAME] = Ins->ShrtName,
[Nam_FULL_NAME] = Ins->FullName,
};
char NewName[Nam_MAX_BYTES_FULL_NAME + 1];
2014-12-01 23:55:08 +01:00
2016-10-22 17:27:30 +02:00
/***** Get the new name for the institution from form *****/
Nam_GetParShrtOrFullName (ShrtOrFull,NewName);
2014-12-01 23:55:08 +01:00
/***** Get from the database the old names of the institution *****/
Hie_GetDataByCod[Hie_INS] (Ins);
2014-12-01 23:55:08 +01:00
/***** Check if new name is empty *****/
if (NewName[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) *****/
if (strcmp (CurrentName[ShrtOrFull],NewName)) // Different names
2014-12-01 23:55:08 +01:00
{
/***** If institution was not in database... *****/
if (Ins_DB_CheckIfInsNameExistsInCty (Nam_Fields[ShrtOrFull],
NewName,Ins->HieCod,
Gbl.Hierarchy.Node[Hie_CTY].HieCod,
0)) // Unused
Ale_CreateAlert (Ale_WARNING,NULL,Txt_X_already_exists,NewName);
2014-12-01 23:55:08 +01:00
else
{
/* Update the table changing old name by new name */
Ins_UpdateInsNameDB (Ins->HieCod,
Nam_Fields[ShrtOrFull],NewName);
2014-12-01 23:55:08 +01:00
2017-03-09 11:16:17 +01:00
/* Create message to show the change made */
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_institution_X_has_been_renamed_as_Y,
CurrentName[ShrtOrFull],NewName);
2016-03-01 23:58:48 +01:00
/* Change current institution name in order to display it properly */
Str_Copy (CurrentName[ShrtOrFull],NewName,
Nam_MaxBytes[ShrtOrFull]);
2014-12-01 23:55:08 +01:00
}
}
else // The same name
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_INFO,NULL,
Txt_The_name_X_has_not_changed,
CurrentName[ShrtOrFull]);
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
}
2016-10-22 17:27:30 +02:00
/*****************************************************************************/
/************ Update institution name in table of institutions ***************/
/*****************************************************************************/
static void Ins_UpdateInsNameDB (long InsCod,const char *FldName,const char *NewName)
2016-10-22 17:27:30 +02:00
{
/***** Update institution changing old name by new name */
Ins_DB_UpdateInsName (InsCod,FldName,NewName);
2017-06-20 14:43:26 +02:00
/***** Flush caches *****/
Ins_FlushCacheFullNameAndCtyOfInstitution ();
2016-10-22 17:27:30 +02:00
}
2016-10-20 19:46:06 +02:00
/*****************************************************************************/
2014-12-01 23:55:08 +01:00
/********************** Change the URL of a institution **********************/
/*****************************************************************************/
void Ins_ChangeInsWWW (void)
{
extern bool (*Hie_GetDataByCod[Hie_NUM_LEVELS]) (struct Hie_Node *Node);
2014-12-01 23:55:08 +01:00
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-04 14:48:05 +02:00
/***** Institution constructor *****/
2019-04-06 20:43:31 +02:00
Ins_EditingInstitutionConstructor ();
2019-04-04 14:48:05 +02:00
2014-12-01 23:55:08 +01:00
/***** Get parameters from form *****/
/* Get the code of the institution */
Ins_EditingIns->HieCod = ParCod_GetAndCheckPar (ParCod_OthHie);
2014-12-01 23:55:08 +01:00
/* Get the new WWW for the institution */
Par_GetParText ("WWW",NewWWW,Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
2016-03-01 23:58:48 +01:00
/***** Get data of institution *****/
Hie_GetDataByCod[Hie_INS] (Ins_EditingIns);
2016-03-01 23:58:48 +01:00
2014-12-01 23:55:08 +01:00
/***** Check if new WWW is empty *****/
if (NewWWW[0])
{
2016-10-22 19:49:33 +02:00
/***** Update database changing old WWW by new WWW *****/
Ins_DB_UpdateInsWWW (Ins_EditingIns->HieCod,NewWWW);
Str_Copy (Ins_EditingIns->WWW,NewWWW,sizeof (Ins_EditingIns->WWW) - 1);
2014-12-01 23:55:08 +01:00
2017-05-11 21:53:37 +02:00
/***** Write message to show the change made
and put button to go to institution changed *****/
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_new_web_address_is_X,
NewWWW);
2014-12-01 23:55:08 +01:00
}
else
2019-12-20 00:30:54 +01:00
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Change the status of an institution ********************/
/*****************************************************************************/
void Ins_ChangeInsStatus (void)
{
extern bool (*Hie_GetDataByCod[Hie_NUM_LEVELS]) (struct Hie_Node *Node);
2014-12-01 23:55:08 +01:00
extern const char *Txt_The_status_of_the_institution_X_has_changed;
Hie_Status_t Status;
2014-12-01 23:55:08 +01:00
2019-04-04 14:48:05 +02:00
/***** Institution constructor *****/
2019-04-06 20:43:31 +02:00
Ins_EditingInstitutionConstructor ();
2019-04-04 14:48:05 +02:00
2014-12-01 23:55:08 +01:00
/***** Get parameters from form *****/
/* Get institution code */
Ins_EditingIns->HieCod = ParCod_GetAndCheckPar (ParCod_OthHie);
2014-12-01 23:55:08 +01:00
/* Get parameter with status */
Status = Hie_GetParStatus (); // New status
2014-12-01 23:55:08 +01:00
/***** Get data of institution *****/
Hie_GetDataByCod[Hie_INS] (Ins_EditingIns);
2014-12-01 23:55:08 +01:00
/***** Update status *****/
Ins_DB_UpdateInsStatus (Ins_EditingIns->HieCod,Status);
2019-04-06 20:43:31 +02:00
Ins_EditingIns->Status = Status;
2014-12-01 23:55:08 +01:00
2019-04-08 15:33:29 +02:00
/***** Create message to show the change made
2017-05-11 21:53:37 +02:00
and put button to go to institution changed *****/
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_status_of_the_institution_X_has_changed,
2019-04-06 20:43:31 +02:00
Ins_EditingIns->ShrtName);
2019-04-08 15:33:29 +02:00
}
/*****************************************************************************/
/****** Show alerts after changing an institution and continue editing *******/
/*****************************************************************************/
void Ins_ContEditAfterChgIns (void)
{
/***** Write message to show the change made
and put button to go to institution changed *****/
2019-04-06 20:43:31 +02:00
Ins_ShowAlertAndButtonToGoToIns ();
2016-03-01 23:58:48 +01:00
2014-12-01 23:55:08 +01:00
/***** Show the form again *****/
2019-04-06 20:43:31 +02:00
Ins_EditInstitutionsInternal ();
2016-03-01 23:58:48 +01:00
2019-04-06 20:43:31 +02:00
/***** Institution destructor *****/
Ins_EditingInstitutionDestructor ();
2016-03-01 23:58:48 +01:00
}
/*****************************************************************************/
2017-05-11 21:53:37 +02:00
/*************** Write message to show the change made *****************/
/*************** and put button to go to institution changed *****************/
2016-03-01 23:58:48 +01:00
/*****************************************************************************/
2019-04-06 20:43:31 +02:00
static void Ins_ShowAlertAndButtonToGoToIns (void)
2016-03-01 23:58:48 +01:00
{
2019-04-08 23:34:58 +02:00
// If the institution being edited is different to the current one...
if (Ins_EditingIns->HieCod != Gbl.Hierarchy.Node[Hie_INS].HieCod)
2019-04-04 14:48:05 +02:00
{
2019-04-08 15:33:29 +02:00
/***** Alert with button to go to institution *****/
2020-03-26 02:54:30 +01:00
Ale_ShowLastAlertAndButton (ActSeeCtr,NULL,NULL,
Ins_PutParInsCod,&Ins_EditingIns->HieCod,
2019-12-30 12:25:45 +01:00
Btn_CONFIRM_BUTTON,
Str_BuildGoToTitle (Ins_EditingIns->ShrtName));
Str_FreeGoToTitle ();
2019-04-04 14:48:05 +02:00
}
2017-05-11 21:53:37 +02:00
else
/***** Alert *****/
2019-03-09 20:12:44 +01:00
Ale_ShowAlerts (NULL);
2017-05-11 21:53:37 +02:00
}
2015-02-03 18:43:55 +01:00
/*****************************************************************************/
/****************** Put a form to create a new institution *******************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2019-04-06 20:43:31 +02:00
static void Ins_PutFormToCreateInstitution (void)
2014-12-01 23:55:08 +01:00
{
Act_Action_t NextAction = ActUnk;
const char *Names[Nam_NUM_SHRT_FULL_NAMES];
struct Hie_Node Node;
2014-12-01 23:55:08 +01:00
/***** Set action depending on role *****/
2017-06-04 18:18:54 +02:00
if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)
NextAction = ActNewIns;
2017-06-04 18:18:54 +02:00
else if (Gbl.Usrs.Me.Role.Max >= Rol_GST)
NextAction = ActReqIns;
2014-12-01 23:55:08 +01:00
else
Err_NoPermissionExit ();
2014-12-01 23:55:08 +01:00
/***** Begin form to create *****/
Frm_BeginFormTable (NextAction,NULL,NULL,NULL,"TBL_SCROLL");
2014-12-01 23:55:08 +01:00
/***** Write heading *****/
Ins_PutHeadInstitutionsForEdition ();
HTM_TR_Begin (NULL);
/***** Column to remove institution, disabled here *****/
HTM_TD_Begin ("class=\"BM\"");
HTM_TD_End ();
/***** Institution code *****/
HTM_TD_Begin ("class=\"CODE\"");
HTM_TD_End ();
/***** Institution logo *****/
HTM_TD_Begin ("title=\"%s\" class=\"HIE_LOGO\"",Ins_EditingIns->FullName);
Node.HieCod = -1L;
Node.ShrtName[0] = '\0';
Lgo_DrawLogo (Hie_INS,&Node,"ICO20x20");
HTM_TD_End ();
/***** Institution short name and full name *****/
Names[Nam_SHRT_NAME] = Ins_EditingIns->ShrtName;
Names[Nam_FULL_NAME] = Ins_EditingIns->FullName;
Nam_NewShortAndFullNames (Names);
/***** Institution WWW *****/
HTM_TD_Begin ("class=\"LM\"");
HTM_INPUT_URL ("WWW",Ins_EditingIns->WWW,HTM_DONT_SUBMIT_ON_CHANGE,
"class=\"INPUT_WWW INPUT_%s\""
" required=\"required\"",The_GetSuffix ());
HTM_TD_End ();
/***** Number of users who claim to belong to this institution ****/
HTM_TD_Unsigned (0);
/***** Number of centers *****/
HTM_TD_Unsigned (0);
/***** Number of users in courses of this institution ****/
HTM_TD_Unsigned (0);
/***** Institution requester *****/
HTM_TD_Begin ("class=\"LT DAT_%s INPUT_REQUESTER\"",The_GetSuffix ());
Usr_WriteAuthor (&Gbl.Usrs.Me.UsrDat,Cns_ENABLED);
HTM_TD_End ();
/***** Institution status *****/
HTM_TD_Empty (1);
HTM_TR_End ();
/***** End form to create *****/
Frm_EndFormTable (Btn_CREATE_BUTTON);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/**************** Write header with fields of an institution *****************/
/*****************************************************************************/
static void Ins_PutHeadInstitutionsForEdition (void)
{
extern const char *Txt_Code;
2016-03-02 14:53:46 +01:00
extern const char *Txt_Short_name_of_the_institution;
extern const char *Txt_Full_name_of_the_institution;
2014-12-01 23:55:08 +01:00
extern const char *Txt_WWW;
extern const char *Txt_Users;
extern const char *Txt_Centers_ABBREVIATION;
2017-05-30 21:43:05 +02:00
extern const char *Txt_ROLES_PLURAL_BRIEF_Abc[Rol_NUM_ROLES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Requester;
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
HTM_TH_Empty (1);
HTM_TH (Txt_Code ,HTM_HEAD_RIGHT);
HTM_TH_Empty (1);
HTM_TH (Txt_Short_name_of_the_institution,HTM_HEAD_LEFT );
HTM_TH (Txt_Full_name_of_the_institution ,HTM_HEAD_LEFT );
HTM_TH (Txt_WWW ,HTM_HEAD_LEFT );
HTM_TH (Txt_Users ,HTM_HEAD_RIGHT);
HTM_TH (Txt_Centers_ABBREVIATION ,HTM_HEAD_RIGHT);
HTM_TH_Begin (HTM_HEAD_RIGHT);
HTM_TxtF ("%s+",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]);
HTM_BR ();
HTM_Txt (Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD]);
HTM_TH_End ();
HTM_TH (Txt_Requester ,HTM_HEAD_LEFT );
HTM_TH_Empty (1);
2019-10-12 00:07:52 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************** Receive form to request a new institution *******************/
/*****************************************************************************/
void Ins_ReceiveReqIns (void)
2014-12-01 23:55:08 +01:00
{
2019-04-04 14:48:05 +02:00
/***** Institution constructor *****/
2019-04-06 20:43:31 +02:00
Ins_EditingInstitutionConstructor ();
2019-04-04 14:48:05 +02:00
/***** Receive form to request a new institution *****/
Ins_ReceiveRequestOrCreateIns ((Hie_Status_t) Hie_STATUS_BIT_PENDING);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************** Receive form to create a new institution ******************/
/*****************************************************************************/
void Ins_ReceiveNewIns (void)
2014-12-01 23:55:08 +01:00
{
2019-04-04 14:48:05 +02:00
/***** Institution constructor *****/
2019-04-06 20:43:31 +02:00
Ins_EditingInstitutionConstructor ();
2019-04-04 14:48:05 +02:00
/***** Receive form to create a new institution *****/
Ins_ReceiveRequestOrCreateIns ((Hie_Status_t) 0);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********** Receive form to request or create a new institution *************/
/*****************************************************************************/
static void Ins_ReceiveRequestOrCreateIns (Hie_Status_t Status)
2014-12-01 23:55:08 +01:00
{
2019-04-08 15:33:29 +02:00
extern const char *Txt_Created_new_institution_X;
char *Names[Nam_NUM_SHRT_FULL_NAMES];
2014-12-01 23:55:08 +01:00
/***** Get parameters from form *****/
/* Set institution country */
Ins_EditingIns->PrtCod = Gbl.Hierarchy.Node[Hie_CTY].HieCod;
2014-12-01 23:55:08 +01:00
/* Get institution short name and full name */
Names[Nam_SHRT_NAME] = Ins_EditingIns->ShrtName;
Names[Nam_FULL_NAME] = Ins_EditingIns->FullName;
Nam_GetParsShrtAndFullName (Names);
/* Get institution URL */
Par_GetParText ("WWW",Ins_EditingIns->WWW,Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
2019-04-06 20:43:31 +02:00
if (Ins_EditingIns->ShrtName[0] &&
Ins_EditingIns->FullName[0]) // If there's a institution name
2014-12-01 23:55:08 +01:00
{
2019-04-06 20:43:31 +02:00
if (Ins_EditingIns->WWW[0])
2014-12-01 23:55:08 +01:00
{
/***** If name of institution was not in database... *****/
if (!Nam_CheckIfNameExists (Ins_DB_CheckIfInsNameExistsInCty,
(const char **) Names,
-1L,
Gbl.Hierarchy.Node[Hie_CTY].HieCod,
0)) // Unused
2019-04-08 15:33:29 +02:00
{
Ins_EditingIns->HieCod = Ins_DB_CreateInstitution (Ins_EditingIns,Status);
Ale_CreateAlert (Ale_SUCCESS,NULL,Txt_Created_new_institution_X,
Names[Nam_FULL_NAME]);
2019-04-08 15:33:29 +02:00
}
2014-12-01 23:55:08 +01:00
}
2015-01-17 13:31:25 +01:00
else // If there is not a web
Ale_CreateAlertYouMustSpecifyTheWebAddress ();
2014-12-01 23:55:08 +01:00
}
else // If there is not a institution name
Ale_CreateAlertYouMustSpecifyShrtNameAndFullName ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************** Get number of institutions with users ********************/
/*****************************************************************************/
unsigned Ins_GetCachedNumInssWithUsrs (Rol_Role_t Role)
2014-12-01 23:55:08 +01:00
{
2020-05-03 20:58:03 +02:00
static const FigCch_FigureCached_t FigureInss[Rol_NUM_ROLES] =
{
[Rol_STD] = FigCch_NUM_INSS_WITH_STDS, // Students
[Rol_NET] = FigCch_NUM_INSS_WITH_NETS, // Non-editing teachers
[Rol_TCH] = FigCch_NUM_INSS_WITH_TCHS, // Teachers
};
unsigned NumInssWithUsrs;
long HieCod = Hie_GetCurrentCod ();
2020-05-03 20:58:03 +02:00
/***** Get number of institutions with users from cache *****/
if (!FigCch_GetFigureFromCache (FigureInss[Role],Gbl.Scope.Current,HieCod,
2020-05-03 20:58:03 +02:00
FigCch_UNSIGNED,&NumInssWithUsrs))
{
/***** Get current number of institutions with users from database and update cache *****/
NumInssWithUsrs = Ins_DB_GetNumInnsWithUsrs (Role,Gbl.Scope.Current,HieCod);
FigCch_UpdateFigureIntoCache (FigureInss[Role],Gbl.Scope.Current,HieCod,
2020-05-03 20:58:03 +02:00
FigCch_UNSIGNED,&NumInssWithUsrs);
}
return NumInssWithUsrs;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************************** List institutions found *************************/
/*****************************************************************************/
2018-10-31 16:16:57 +01:00
void Ins_ListInssFound (MYSQL_RES **mysql_res,unsigned NumInss)
2014-12-01 23:55:08 +01:00
{
extern bool (*Hie_GetDataByCod[Hie_NUM_LEVELS]) (struct Hie_Node *Node);
extern const char *Txt_HIERARCHY_SINGUL_abc[Hie_NUM_LEVELS];
extern const char *Txt_HIERARCHY_PLURAL_abc[Hie_NUM_LEVELS];
char *Title;
2014-12-01 23:55:08 +01:00
unsigned NumIns;
struct Hie_Node Ins;
2014-12-01 23:55:08 +01:00
2018-10-31 16:16:57 +01:00
/***** List the institutions (one row per institution) *****/
if (NumInss)
2014-12-01 23:55:08 +01:00
{
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
2014-12-01 23:55:08 +01:00
/* Number of institutions found */
if (asprintf (&Title,"%u %s",NumInss,
NumInss == 1 ? Txt_HIERARCHY_SINGUL_abc[Hie_INS] :
Txt_HIERARCHY_PLURAL_abc[Hie_INS]) < 0)
Err_NotEnoughMemoryExit ();
Box_BoxTableBegin (Title,NULL,NULL,NULL,Box_NOT_CLOSABLE,2);
free (Title);
2017-06-12 14:16:33 +02:00
/***** Write heading *****/
2014-12-01 23:55:08 +01:00
Ins_PutHeadInstitutionsForSeeing (false); // Order not selectable
2017-02-28 00:59:01 +01:00
/***** List the institutions (one row per institution) *****/
for (NumIns = 1, The_ResetRowColor ();
2014-12-01 23:55:08 +01:00
NumIns <= NumInss;
NumIns++, The_ChangeRowColor ())
2014-12-01 23:55:08 +01:00
{
/* Get next institution */
Ins.HieCod = DB_GetNextCode (*mysql_res);
2014-12-01 23:55:08 +01:00
/* Get data of institution */
Hie_GetDataByCod[Hie_INS] (&Ins);
2014-12-01 23:55:08 +01:00
2017-02-28 00:59:01 +01:00
/* Write data of this institution */
2014-12-01 23:55:08 +01:00
Ins_ListOneInstitutionForSeeing (&Ins,NumIns);
}
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableEnd ();
2014-12-01 23:55:08 +01:00
}
/***** Free structure that stores the query result *****/
2018-10-31 16:16:57 +01:00
DB_FreeMySQLResult (mysql_res);
2014-12-01 23:55:08 +01:00
}
2019-04-04 14:48:05 +02:00
/*****************************************************************************/
/********************** Institution constructor/destructor *******************/
/*****************************************************************************/
2019-04-06 20:43:31 +02:00
static void Ins_EditingInstitutionConstructor (void)
2019-04-04 14:48:05 +02:00
{
2019-04-06 21:39:35 +02:00
/***** Pointer must be NULL *****/
2019-04-06 20:43:31 +02:00
if (Ins_EditingIns != NULL)
Err_WrongInstitExit ();
2019-04-04 14:48:05 +02:00
/***** Allocate memory for institution *****/
if ((Ins_EditingIns = malloc (sizeof (*Ins_EditingIns))) == NULL)
Err_NotEnoughMemoryExit ();
2019-04-04 14:48:05 +02:00
/***** Reset institution *****/
Ins_EditingIns->HieCod = -1L;
Ins_EditingIns->PrtCod = -1L;
Ins_EditingIns->ShrtName[0] = '\0';
Ins_EditingIns->FullName[0] = '\0';
Ins_EditingIns->WWW[0] = '\0';
2019-04-06 20:43:31 +02:00
}
static void Ins_EditingInstitutionDestructor (void)
2019-04-04 14:48:05 +02:00
{
/***** Free memory used for institution *****/
2019-04-06 20:43:31 +02:00
if (Ins_EditingIns != NULL)
2019-04-04 14:48:05 +02:00
{
2019-11-06 19:45:20 +01:00
free (Ins_EditingIns);
2019-04-06 20:43:31 +02:00
Ins_EditingIns = NULL;
2019-04-04 14:48:05 +02:00
}
}
2020-01-09 15:36:12 +01:00
2020-01-14 09:18:06 +01:00
/*****************************************************************************/
2020-01-14 13:30:18 +01:00
/********************* Form to go to institution map *************************/
2020-01-14 09:18:06 +01:00
/*****************************************************************************/
static void Ins_FormToGoToMap (struct Hie_Node *Ins)
2020-01-14 09:18:06 +01:00
{
if (Ctr_DB_CheckIfMapIsAvailableInIns (Ins->HieCod))
2020-01-14 09:18:06 +01:00
{
Ins_EditingIns = Ins; // Used to pass parameter with the code of the institution
2020-03-26 02:54:30 +01:00
Lay_PutContextualLinkOnlyIcon (ActSeeInsInf,NULL,
Ins_PutParInsCod,&Ins_EditingIns->HieCod,
"map-marker-alt.svg",Ico_BLACK);
2020-01-14 09:18:06 +01:00
}
}
/*****************************************************************************/
/***************** Write parameter with code of institution ******************/
/*****************************************************************************/
void Ins_PutParInsCod (void *InsCod)
{
if (InsCod)
ParCod_PutPar (ParCod_Ins,*((long *) InsCod));
}
/*****************************************************************************/
/****************** Get and show stats about institutions ********************/
/*****************************************************************************/
void Ins_GetAndShowInstitutionsStats (void)
{
extern const char *Hlp_ANALYTICS_Figures_institutions;
extern const char *Txt_HIERARCHY_PLURAL_Abc[Hie_NUM_LEVELS];
struct Fig_Figures Figures;
/***** Begin box *****/
Box_BoxBegin (Txt_HIERARCHY_PLURAL_Abc[Hie_INS],NULL,NULL,
Hlp_ANALYTICS_Figures_institutions,Box_NOT_CLOSABLE);
/***** Form to select type of list used to display degree photos *****/
Set_GetAndUpdatePrefsAboutUsrList ();
Figures.Level = Gbl.Scope.Current;
Figures.FigureType = Fig_INSTITS;
Usr_ShowFormsToSelectUsrListType (ActSeeUseGbl,Fig_PutParsFigures,&Figures,NULL);
/***** Institutions ordered by number of centers *****/
Ins_GetAndShowInssOrderedByNumCtrs ();
/***** Institutions ordered by number of degrees *****/
HTM_BR ();
Ins_GetAndShowInssOrderedByNumDegs ();
/***** Institutions ordered by number of courses *****/
HTM_BR ();
Ins_GetAndShowInssOrderedByNumCrss ();
/***** Institutions ordered by number of users in courses *****/
HTM_BR ();
Ins_GetAndShowInssOrderedByNumUsrsInCrss ();
/***** Institutions ordered by number of users who claim to belong to them *****/
HTM_BR ();
Ins_GetAndShowInssOrderedByNumUsrsWhoClaimToBelongToThem ();
/***** End box *****/
Box_BoxEnd ();
}
/*****************************************************************************/
/**** Get and show stats about institutions ordered by number of centers *****/
/*****************************************************************************/
static void Ins_GetAndShowInssOrderedByNumCtrs (void)
{
extern const char *Txt_Institutions_by_number_of_centers;
extern const char *Txt_HIERARCHY_PLURAL_Abc[Hie_NUM_LEVELS];
MYSQL_RES *mysql_res;
unsigned NumInss;
Box_BoxBegin (Txt_Institutions_by_number_of_centers,NULL,NULL,
NULL,Box_NOT_CLOSABLE);
HTM_TABLE_Begin ("TBL_SCROLL");
/***** Get institutions ordered by number of centers *****/
NumInss = Ins_DB_GetInssOrderedByNumCtrs (&mysql_res);
/***** Show institutions *****/
Ins_ShowInss (&mysql_res,NumInss,Txt_HIERARCHY_PLURAL_Abc[Hie_CTR]);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
HTM_TABLE_End ();
Box_BoxEnd ();
}
/*****************************************************************************/
/**** Get and show stats about institutions ordered by number of degrees *****/
/*****************************************************************************/
static void Ins_GetAndShowInssOrderedByNumDegs (void)
{
extern const char *Txt_Institutions_by_number_of_degrees;
extern const char *Txt_HIERARCHY_PLURAL_Abc[Hie_NUM_LEVELS];
MYSQL_RES *mysql_res;
unsigned NumInss;
Box_BoxBegin (Txt_Institutions_by_number_of_degrees,NULL,NULL,
NULL,Box_NOT_CLOSABLE);
HTM_TABLE_Begin ("TBL_SCROLL");
/***** Get institutions ordered by number of degrees *****/
NumInss = Ins_DB_GetInssOrderedByNumDegs (&mysql_res);
/***** Show institutions *****/
Ins_ShowInss (&mysql_res,NumInss,Txt_HIERARCHY_PLURAL_Abc[Hie_DEG]);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
HTM_TABLE_End ();
Box_BoxEnd ();
}
/*****************************************************************************/
/**** Get and show stats about institutions ordered by number of courses *****/
/*****************************************************************************/
static void Ins_GetAndShowInssOrderedByNumCrss (void)
{
extern const char *Txt_Institutions_by_number_of_courses;
extern const char *Txt_HIERARCHY_PLURAL_Abc[Hie_NUM_LEVELS];
MYSQL_RES *mysql_res;
unsigned NumInss;
Box_BoxBegin (Txt_Institutions_by_number_of_courses,NULL,NULL,
NULL,Box_NOT_CLOSABLE);
HTM_TABLE_Begin ("TBL_SCROLL");
/***** Get institutions ordered by number of courses *****/
NumInss = Ins_DB_GetInssOrderedByNumCrss (&mysql_res);
/***** Show institutions *****/
Ins_ShowInss (&mysql_res,NumInss,Txt_HIERARCHY_PLURAL_Abc[Hie_CRS]);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
HTM_TABLE_End ();
Box_BoxEnd ();
}
/*****************************************************************************/
/***** Get and show stats about institutions ordered by users in courses *****/
/*****************************************************************************/
static void Ins_GetAndShowInssOrderedByNumUsrsInCrss (void)
{
extern const char *Txt_Institutions_by_number_of_users_in_courses;
extern const char *Txt_Users;
MYSQL_RES *mysql_res;
unsigned NumInss;
Box_BoxBegin (Txt_Institutions_by_number_of_users_in_courses,NULL,NULL,
NULL,Box_NOT_CLOSABLE);
HTM_TABLE_Begin ("TBL_SCROLL");
/***** Get institutions ordered by number of users in courses *****/
NumInss = Ins_DB_GetInssOrderedByNumUsrsInCrss (&mysql_res);
/***** Show institutions *****/
Ins_ShowInss (&mysql_res,NumInss,Txt_Users);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
HTM_TABLE_End ();
Box_BoxEnd ();
}
/*****************************************************************************/
/************* Get and show stats about institutions ordered by **************/
/************* number of users who claim to belong to them **************/
/*****************************************************************************/
static void Ins_GetAndShowInssOrderedByNumUsrsWhoClaimToBelongToThem (void)
{
extern const char *Txt_Institutions_by_number_of_users_who_claim_to_belong_to_them;
extern const char *Txt_Users;
MYSQL_RES *mysql_res;
unsigned NumInss;
Box_BoxBegin (Txt_Institutions_by_number_of_users_who_claim_to_belong_to_them,
NULL,NULL,
NULL,Box_NOT_CLOSABLE);
HTM_TABLE_Begin ("TBL_SCROLL");
/***** Get institutions ordered by number of users who claim to belong to them *****/
NumInss = Ins_DB_GetInssOrderedByNumUsrsWhoClaimToBelongToThem (&mysql_res);
/***** Show institutions *****/
Ins_ShowInss (&mysql_res,NumInss,Txt_Users);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
HTM_TABLE_End ();
Box_BoxEnd ();
}
/*****************************************************************************/
/****************** Get and show stats about institutions ********************/
/*****************************************************************************/
static void Ins_ShowInss (MYSQL_RES **mysql_res,unsigned NumInss,
const char *TxtFigure)
{
extern const char *Txt_HIERARCHY_SINGUL_Abc[Hie_NUM_LEVELS];
unsigned NumIns;
unsigned NumOrder;
unsigned NumberLastRow;
unsigned NumberThisRow;
struct Hie_Node Ins;
bool TRIsOpen = false;
/***** Query database *****/
if (NumInss)
{
/* Draw the classphoto/list */
switch (Gbl.Usrs.Me.ListType)
{
case Set_USR_LIST_AS_CLASS_PHOTO:
/***** Draw institutions as a class photo *****/
for (NumIns = 0;
NumIns < NumInss;)
{
if ((NumIns % Gbl.Usrs.ClassPhoto.Cols) == 0)
{
HTM_TR_Begin (NULL);
TRIsOpen = true;
}
/***** Get institution data and statistic *****/
NumberThisRow = Ins_GetInsAndStat (&Ins,*mysql_res);
/***** Write link to institution *****/
HTM_TD_Begin ("class=\"CM FORM_IN_%s\"",
The_GetSuffix ());
Ins_DrawInstitutionLogoWithLink (&Ins,"ICO40x40");
HTM_BR ();
HTM_Unsigned (NumberThisRow);
HTM_TD_End ();
if ((++NumIns % Gbl.Usrs.ClassPhoto.Cols) == 0)
{
HTM_TR_End ();
TRIsOpen = false;
}
}
if (TRIsOpen)
HTM_TR_End ();
break;
case Set_USR_LIST_AS_LISTING:
/***** Draw institutions as a list *****/
HTM_TR_Begin (NULL);
HTM_TH_Empty (1);
HTM_TH (Txt_HIERARCHY_SINGUL_Abc[Hie_INS],HTM_HEAD_LEFT );
HTM_TH (TxtFigure ,HTM_HEAD_RIGHT);
HTM_TR_End ();
for (NumIns = 1, NumOrder = 1, NumberLastRow = 0;
NumIns <= NumInss;
NumIns++)
{
/***** Get institution data and statistic *****/
NumberThisRow = Ins_GetInsAndStat (&Ins,*mysql_res);
HTM_TR_Begin (NULL);
/***** Number of order *****/
if (NumberThisRow != NumberLastRow)
NumOrder = NumIns;
HTM_TD_Unsigned (NumOrder);
/***** Write link to institution *****/
HTM_TD_Begin ("class=\"LM FORM_IN_%s\"",
The_GetSuffix ());
/* Icon and name of this institution */
Frm_BeginForm (ActSeeInsInf);
ParCod_PutPar (ParCod_Ins,Ins.HieCod);
HTM_BUTTON_Submit_Begin (Ins.ShrtName,
"class=\"LM BT_LINK\"");
if (Gbl.Usrs.Listing.WithPhotos)
{
Lgo_DrawLogo (Hie_INS,&Ins,"ICO40x40");
HTM_NBSP ();
}
HTM_Txt (Ins.FullName);
HTM_BUTTON_End ();
Frm_EndForm ();
HTM_TD_End ();
/***** Write statistic *****/
HTM_TD_Unsigned (NumberThisRow);
HTM_TR_End ();
NumberLastRow = NumberThisRow;
}
break;
default:
break;
}
}
}
/*****************************************************************************/
/******************** Get institution data and statistic *********************/
/*****************************************************************************/
static unsigned Ins_GetInsAndStat (struct Hie_Node *Ins,MYSQL_RES *mysql_res)
{
extern bool (*Hie_GetDataByCod[Hie_NUM_LEVELS]) (struct Hie_Node *Node);
MYSQL_ROW row;
unsigned NumberThisRow;
/***** Get next institution *****/
row = mysql_fetch_row (mysql_res);
/***** Get data of this institution (row[0]) *****/
Ins->HieCod = Str_ConvertStrCodToLongCod (row[0]);
if (!Hie_GetDataByCod[Hie_INS] (Ins))
Err_WrongInstitExit ();
/***** Get statistic (row[1]) *****/
if (sscanf (row[1],"%u",&NumberThisRow) != 1)
Err_ShowErrorAndExit ("Error in statistic");
return NumberThisRow;
}