mirror of https://github.com/acanas/swad-core.git
Version 20.88.1: Jun 02, 2021 Queries moved to module swad_center_database.
This commit is contained in:
parent
17c04cc470
commit
920018f1f3
298
swad_center.c
298
swad_center.c
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "swad_center.h"
|
||||
#include "swad_center_config.h"
|
||||
#include "swad_center_database.h"
|
||||
#include "swad_database.h"
|
||||
#include "swad_error.h"
|
||||
#include "swad_figure.h"
|
||||
|
@ -90,8 +91,6 @@ static Ctr_Status_t Ctr_GetStatusBitsFromStatusTxt (Ctr_StatusTxt_t StatusTxt);
|
|||
|
||||
static void Ctr_PutParamOtherCtrCod (void *CtrCod);
|
||||
|
||||
static void Ctr_DB_UpdateCtrName (long CtrCod,const char *FieldName,const char *NewCtrName);
|
||||
|
||||
static void Ctr_ShowAlertAndButtonToGoToCtr (void);
|
||||
static void Ctr_PutParamGoToCtr (void *CtrCod);
|
||||
|
||||
|
@ -99,7 +98,6 @@ static void Ctr_PutFormToCreateCenter (const struct Plc_Places *Places);
|
|||
static void Ctr_PutHeadCentersForSeeing (bool OrderSelectable);
|
||||
static void Ctr_PutHeadCentersForEdition (void);
|
||||
static void Ctr_ReceiveFormRequestOrCreateCtr (unsigned Status);
|
||||
static void Ctr_DB_CreateCenter (unsigned Status);
|
||||
|
||||
static unsigned Ctr_GetNumCtrsInCty (long CtyCod);
|
||||
|
||||
|
@ -127,42 +125,7 @@ void Ctr_SeeCtrWithPendingDegs (void)
|
|||
const char *BgColor;
|
||||
|
||||
/***** Get centers with pending degrees *****/
|
||||
switch (Gbl.Usrs.Me.Role.Logged)
|
||||
{
|
||||
case Rol_CTR_ADM:
|
||||
NumCtrs = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get centers with pending degrees",
|
||||
"SELECT deg_degrees.CtrCod," // row[0]
|
||||
"COUNT(*)" // row[1]
|
||||
" FROM deg_degrees,"
|
||||
"ctr_admin,"
|
||||
"ctr_centers"
|
||||
" WHERE (deg_degrees.Status & %u)<>0"
|
||||
" AND deg_degrees.CtrCod=ctr_admin.CtrCod"
|
||||
" AND ctr_admin.UsrCod=%ld"
|
||||
" AND deg_degrees.CtrCod=ctr_centers.CtrCod"
|
||||
" GROUP BY deg_degrees.CtrCod"
|
||||
" ORDER BY ctr_centers.ShortName",
|
||||
(unsigned) Deg_STATUS_BIT_PENDING,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
break;
|
||||
case Rol_SYS_ADM:
|
||||
NumCtrs = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get centers with pending degrees",
|
||||
"SELECT deg_degrees.CtrCod," // row[0]
|
||||
"COUNT(*)" // row[1]
|
||||
" FROM deg_degrees,"
|
||||
"ctr_centers"
|
||||
" WHERE (deg_degrees.Status & %u)<>0"
|
||||
" AND deg_degrees.CtrCod=ctr_centers.CtrCod"
|
||||
" GROUP BY deg_degrees.CtrCod"
|
||||
" ORDER BY ctr_centers.ShortName",
|
||||
(unsigned) Deg_STATUS_BIT_PENDING);
|
||||
break;
|
||||
default: // Forbidden for other users
|
||||
return;
|
||||
}
|
||||
if (NumCtrs)
|
||||
if ((NumCtrs = Ctr_DB_GetCtrsWithPendingDegs (&mysql_res)))
|
||||
{
|
||||
/***** Begin box and table *****/
|
||||
Box_BoxTableBegin (NULL,Txt_Centers_with_pending_degrees,
|
||||
|
@ -262,7 +225,8 @@ void Ctr_ShowCtrsOfCurrentIns (void)
|
|||
Ctr_GetParamCtrOrder ();
|
||||
|
||||
/***** Get list of centers *****/
|
||||
Ctr_GetFullListOfCenters (Gbl.Hierarchy.Ins.InsCod);
|
||||
Ctr_GetFullListOfCenters (Gbl.Hierarchy.Ins.InsCod,
|
||||
Gbl.Hierarchy.Ctrs.SelectedOrder);
|
||||
|
||||
/***** Write menu to select country and institution *****/
|
||||
Hie_WriteMenuHierarchy ();
|
||||
|
@ -490,7 +454,8 @@ static void Ctr_EditCentersInternal (void)
|
|||
|
||||
/***** Get list of centers *****/
|
||||
Gbl.Hierarchy.Ctrs.SelectedOrder = Ctr_ORDER_BY_CENTER;
|
||||
Ctr_GetFullListOfCenters (Gbl.Hierarchy.Ins.InsCod);
|
||||
Ctr_GetFullListOfCenters (Gbl.Hierarchy.Ins.InsCod,
|
||||
Gbl.Hierarchy.Ctrs.SelectedOrder);
|
||||
|
||||
/***** Write menu to select country and institution *****/
|
||||
Hie_WriteMenuHierarchy ();
|
||||
|
@ -557,27 +522,11 @@ void Ctr_GetBasicListOfCenters (long InsCod)
|
|||
struct Ctr_Center *Ctr;
|
||||
|
||||
/***** Get centers from database *****/
|
||||
Gbl.Hierarchy.Ctrs.Num = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get centers",
|
||||
"SELECT CtrCod," // row[ 0]
|
||||
"InsCod," // row[ 1]
|
||||
"PlcCod," // row[ 2]
|
||||
"Status," // row[ 3]
|
||||
"RequesterUsrCod," // row[ 4]
|
||||
"Latitude," // row[ 5]
|
||||
"Longitude," // row[ 6]
|
||||
"Altitude," // row[ 7]
|
||||
"ShortName," // row[ 8]
|
||||
"FullName," // row[ 9]
|
||||
"WWW" // row[10]
|
||||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld"
|
||||
" ORDER BY FullName",
|
||||
InsCod);
|
||||
Gbl.Hierarchy.Ctrs.Num = Ctr_DB_GetListOfCtrsFull (&mysql_res,InsCod);
|
||||
|
||||
if (Gbl.Hierarchy.Ctrs.Num) // Centers found...
|
||||
{
|
||||
/***** Create list with courses in degree *****/
|
||||
/***** Create list with centers in institution *****/
|
||||
if ((Gbl.Hierarchy.Ctrs.Lst = calloc ((size_t) Gbl.Hierarchy.Ctrs.Num,
|
||||
sizeof (*Gbl.Hierarchy.Ctrs.Lst))) == NULL)
|
||||
Err_NotEnoughMemoryExit ();
|
||||
|
@ -607,59 +556,15 @@ void Ctr_GetBasicListOfCenters (long InsCod)
|
|||
/************* with number of users who claim to belong to them **************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Ctr_GetFullListOfCenters (long InsCod)
|
||||
void Ctr_GetFullListOfCenters (long InsCod,Ctr_Order_t SelectedOrder)
|
||||
{
|
||||
static const char *OrderBySubQuery[Ctr_NUM_ORDERS] =
|
||||
{
|
||||
[Ctr_ORDER_BY_CENTER ] = "FullName",
|
||||
[Ctr_ORDER_BY_NUM_USRS] = "NumUsrs DESC,FullName",
|
||||
};
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned NumCtr;
|
||||
struct Ctr_Center *Ctr;
|
||||
|
||||
/***** Get centers from database *****/
|
||||
Gbl.Hierarchy.Ctrs.Num = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get centers",
|
||||
"(SELECT ctr_centers.CtrCod," // row[ 0]
|
||||
"ctr_centers.InsCod," // row[ 1]
|
||||
"ctr_centers.PlcCod," // row[ 2]
|
||||
"ctr_centers.Status," // row[ 3]
|
||||
"ctr_centers.RequesterUsrCod," // row[ 4]
|
||||
"ctr_centers.Latitude," // row[ 5]
|
||||
"ctr_centers.Longitude," // row[ 6]
|
||||
"ctr_centers.Altitude," // row[ 7]
|
||||
"ctr_centers.ShortName," // row[ 8]
|
||||
"ctr_centers.FullName," // row[ 9]
|
||||
"ctr_centers.WWW," // row[10]
|
||||
"COUNT(*) AS NumUsrs" // row[11]
|
||||
" FROM ctr_centers,usr_data"
|
||||
" WHERE ctr_centers.InsCod=%ld"
|
||||
" AND ctr_centers.CtrCod=usr_data.CtrCod"
|
||||
" GROUP BY ctr_centers.CtrCod)"
|
||||
" UNION "
|
||||
"(SELECT CtrCod," // row[ 0]
|
||||
"InsCod," // row[ 1]
|
||||
"PlcCod," // row[ 2]
|
||||
"Status," // row[ 3]
|
||||
"RequesterUsrCod," // row[ 4]
|
||||
"Latitude," // row[ 5]
|
||||
"Longitude," // row[ 6]
|
||||
"Altitude," // row[ 7]
|
||||
"ShortName," // row[ 8]
|
||||
"FullName," // row[ 9]
|
||||
"WWW," // row[10]
|
||||
"0 AS NumUsrs" // row[11]
|
||||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld"
|
||||
" AND CtrCod NOT IN"
|
||||
" (SELECT DISTINCT CtrCod"
|
||||
" FROM usr_data))"
|
||||
" ORDER BY %s",
|
||||
InsCod,
|
||||
InsCod,
|
||||
OrderBySubQuery[Gbl.Hierarchy.Ctrs.SelectedOrder]);
|
||||
Gbl.Hierarchy.Ctrs.Num = Ctr_DB_GetListOfCtrsFullWithNumUsrs (&mysql_res,InsCod,SelectedOrder);
|
||||
|
||||
if (Gbl.Hierarchy.Ctrs.Num) // Centers found...
|
||||
{
|
||||
|
@ -714,21 +619,7 @@ bool Ctr_GetDataOfCenterByCod (struct Ctr_Center *Ctr)
|
|||
if (Ctr->CtrCod > 0)
|
||||
{
|
||||
/***** Get data of a center from database *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get data of a center",
|
||||
"SELECT CtrCod," // row[ 0]
|
||||
"InsCod," // row[ 1]
|
||||
"PlcCod," // row[ 2]
|
||||
"Status," // row[ 3]
|
||||
"RequesterUsrCod," // row[ 4]
|
||||
"Latitude," // row[ 5]
|
||||
"Longitude," // row[ 6]
|
||||
"Altitude," // row[ 7]
|
||||
"ShortName," // row[ 8]
|
||||
"FullName," // row[ 9]
|
||||
"WWW" // row[10]
|
||||
" FROM ctr_centers"
|
||||
" WHERE CtrCod=%ld",
|
||||
Ctr->CtrCod)) // Center found...
|
||||
if (Ctr_DB_GetDataOfCenterByCod (&mysql_res,Ctr->CtrCod)) // Center found...
|
||||
{
|
||||
/* Get row */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
@ -780,46 +671,6 @@ static void Ctr_GetDataOfCenterFromRow (struct Ctr_Center *Ctr,MYSQL_ROW row)
|
|||
Str_Copy (Ctr->WWW ,row[10],sizeof (Ctr->WWW ) - 1);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********** Get the institution code of a center from its code **************/
|
||||
/*****************************************************************************/
|
||||
|
||||
long Ctr_GetInsCodOfCenterByCod (long CtrCod)
|
||||
{
|
||||
/***** Trivial check: center code should be > 0 *****/
|
||||
if (CtrCod <= 0)
|
||||
return -1L;
|
||||
|
||||
/***** Get the institution code of a center from database *****/
|
||||
return DB_QuerySELECTCode ("can not get the institution of a center",
|
||||
"SELECT InsCod"
|
||||
" FROM ctr_centers"
|
||||
" WHERE CtrCod=%ld",
|
||||
CtrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*************** Get the short name of a center from its code ****************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Ctr_GetShortNameOfCenterByCod (struct Ctr_Center *Ctr)
|
||||
{
|
||||
/***** Trivial check: center code should be > 0 *****/
|
||||
if (Ctr->CtrCod <= 0)
|
||||
{
|
||||
Ctr->ShrtName[0] = '\0';
|
||||
return;
|
||||
}
|
||||
|
||||
/***** Get the short name of a center from database *****/
|
||||
DB_QuerySELECTString (Ctr->ShrtName,sizeof (Ctr->ShrtName) - 1,
|
||||
"can not get the short name of a center",
|
||||
"SELECT ShortName"
|
||||
" FROM ctr_centers"
|
||||
" WHERE CtrCod=%ld",
|
||||
Ctr->CtrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**************************** Free list of centers ***************************/
|
||||
/*****************************************************************************/
|
||||
|
@ -865,17 +716,8 @@ void Ctr_WriteSelectorOfCenter (void)
|
|||
|
||||
if (Gbl.Hierarchy.Ins.InsCod > 0)
|
||||
{
|
||||
/***** Get centers from database *****/
|
||||
NumCtrs = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get centers",
|
||||
"SELECT DISTINCT CtrCod," // row[0]
|
||||
"ShortName" // row[1]
|
||||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld"
|
||||
" ORDER BY ShortName",
|
||||
Gbl.Hierarchy.Ins.InsCod);
|
||||
|
||||
/***** Get centers *****/
|
||||
/***** Get centers in current institution from database *****/
|
||||
NumCtrs = Ctr_DB_GetListOfCtrsInCurrentIns (&mysql_res);
|
||||
for (NumCtr = 0;
|
||||
NumCtr < NumCtrs;
|
||||
NumCtr++)
|
||||
|
@ -1257,10 +1099,7 @@ void Ctr_RemoveCenter (void)
|
|||
Enr_DB_RemAdmins (HieLvl_CTR,Ctr_EditingCtr->CtrCod);
|
||||
|
||||
/***** Remove center *****/
|
||||
DB_QueryDELETE ("can not remove a center",
|
||||
"DELETE FROM ctr_centers"
|
||||
" WHERE CtrCod=%ld",
|
||||
Ctr_EditingCtr->CtrCod);
|
||||
Ctr_DB_RemoveCenter (Ctr_EditingCtr->CtrCod);
|
||||
|
||||
/***** Flush caches *****/
|
||||
Deg_FlushCacheNumDegsInCtr ();
|
||||
|
@ -1307,20 +1146,6 @@ void Ctr_ChangeCtrPlc (void)
|
|||
Txt_The_place_of_the_center_has_changed);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************** Update database changing old place by new place **************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Ctr_DB_UpdateCtrPlc (long CtrCod,long NewPlcCod)
|
||||
{
|
||||
DB_QueryUPDATE ("can not update the place of a center",
|
||||
"UPDATE ctr_centers"
|
||||
" SET PlcCod=%ld"
|
||||
" WHERE CtrCod=%ld",
|
||||
NewPlcCod,
|
||||
CtrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************ Change the name of a center ************************/
|
||||
/*****************************************************************************/
|
||||
|
@ -1418,43 +1243,6 @@ void Ctr_RenameCenter (struct Ctr_Center *Ctr,Cns_ShrtOrFullName_t ShrtOrFullNam
|
|||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************* Check if the name of center exists ********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
bool Ctr_DB_CheckIfCtrNameExistsInIns (const char *FieldName,const char *Name,
|
||||
long CtrCod,long InsCod)
|
||||
{
|
||||
/***** Get number of centers with a name from database *****/
|
||||
return (DB_QueryCOUNT ("can not check if the name of a center"
|
||||
" already existed",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld"
|
||||
" AND %s='%s'"
|
||||
" AND CtrCod<>%ld",
|
||||
InsCod,
|
||||
FieldName,
|
||||
Name,
|
||||
CtrCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/****************** Update center name in table of centers *******************/
|
||||
/*****************************************************************************/
|
||||
|
||||
static void Ctr_DB_UpdateCtrName (long CtrCod,const char *FieldName,const char *NewCtrName)
|
||||
{
|
||||
/***** Update center changing old name by new name */
|
||||
DB_QueryUPDATE ("can not update the name of a center",
|
||||
"UPDATE ctr_centers"
|
||||
" SET %s='%s'"
|
||||
" WHERE CtrCod=%ld",
|
||||
FieldName,
|
||||
NewCtrName,
|
||||
CtrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************* Change the URL of a center ************************/
|
||||
/*****************************************************************************/
|
||||
|
@ -1493,21 +1281,6 @@ void Ctr_ChangeCtrWWW (void)
|
|||
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**************** Update database changing old WWW by new WWW ****************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Ctr_DB_UpdateCtrWWW (long CtrCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1])
|
||||
{
|
||||
/***** Update database changing old WWW by new WWW *****/
|
||||
DB_QueryUPDATE ("can not update the web of a center",
|
||||
"UPDATE ctr_centers"
|
||||
" SET WWW='%s'"
|
||||
" WHERE CtrCod=%ld",
|
||||
NewWWW,
|
||||
CtrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********************** Change the status of a center ***********************/
|
||||
/*****************************************************************************/
|
||||
|
@ -1877,7 +1650,7 @@ static void Ctr_ReceiveFormRequestOrCreateCtr (unsigned Status)
|
|||
Ctr_EditingCtr->FullName);
|
||||
else // Add new center to database
|
||||
{
|
||||
Ctr_DB_CreateCenter (Status);
|
||||
Ctr_EditingCtr->CtrCod = Ctr_DB_CreateCenter (Ctr_EditingCtr,Status);
|
||||
Ale_CreateAlert (Ale_SUCCESS,NULL,
|
||||
Txt_Created_new_center_X,
|
||||
Ctr_EditingCtr->FullName);
|
||||
|
@ -1892,30 +1665,6 @@ static void Ctr_ReceiveFormRequestOrCreateCtr (unsigned Status)
|
|||
Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_center);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Create a new center ***************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
static void Ctr_DB_CreateCenter (unsigned Status)
|
||||
{
|
||||
/***** Create a new center *****/
|
||||
Ctr_EditingCtr->CtrCod =
|
||||
DB_QueryINSERTandReturnCode ("can not create a new center",
|
||||
"INSERT INTO ctr_centers"
|
||||
" (InsCod,PlcCod,Status,RequesterUsrCod,"
|
||||
"ShortName,FullName,WWW,PhotoAttribution)"
|
||||
" VALUES"
|
||||
" (%ld,%ld,%u,%ld,"
|
||||
"'%s','%s','%s','')",
|
||||
Ctr_EditingCtr->InsCod,
|
||||
Ctr_EditingCtr->PlcCod,
|
||||
Status,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
Ctr_EditingCtr->ShrtName,
|
||||
Ctr_EditingCtr->FullName,
|
||||
Ctr_EditingCtr->WWW);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************** Get number of centers ****************************/
|
||||
/*****************************************************************************/
|
||||
|
@ -2118,23 +1867,6 @@ unsigned Ctr_GetCachedNumCtrsWithMapInIns (long InsCod)
|
|||
return NumCtrsWithMap;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******* Get number of centers (of the current institution) in a place *******/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Ctr_DB_GetNumCtrsInPlc (long PlcCod)
|
||||
{
|
||||
/***** Get number of centers (of the current institution) in a place *****/
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get the number of centers in a place",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld"
|
||||
" AND PlcCod=%ld",
|
||||
Gbl.Hierarchy.Ins.InsCod,
|
||||
PlcCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************* Get number of centers with degrees ********************/
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -108,24 +108,18 @@ void Ctr_EditCenters (void);
|
|||
void Ctr_PutIconToViewCenters (void);
|
||||
|
||||
void Ctr_GetBasicListOfCenters (long InsCod);
|
||||
void Ctr_GetFullListOfCenters (long InsCod);
|
||||
void Ctr_GetFullListOfCenters (long InsCod,Ctr_Order_t SelectedOrder);
|
||||
bool Ctr_GetDataOfCenterByCod (struct Ctr_Center *Ctr);
|
||||
long Ctr_GetInsCodOfCenterByCod (long CtrCod);
|
||||
void Ctr_GetShortNameOfCenterByCod (struct Ctr_Center *Ctr);
|
||||
void Ctr_FreeListCenters (void);
|
||||
void Ctr_WriteSelectorOfCenter (void);
|
||||
void Ctr_PutParamCtrCod (long CtrCod);
|
||||
long Ctr_GetAndCheckParamOtherCtrCod (long MinCodAllowed);
|
||||
void Ctr_RemoveCenter (void);
|
||||
void Ctr_ChangeCtrPlc (void);
|
||||
void Ctr_DB_UpdateCtrPlc (long CtrCod,long NewPlcCod);
|
||||
void Ctr_RenameCenterShort (void);
|
||||
void Ctr_RenameCenterFull (void);
|
||||
void Ctr_RenameCenter (struct Ctr_Center *Ctr,Cns_ShrtOrFullName_t ShrtOrFullName);
|
||||
bool Ctr_DB_CheckIfCtrNameExistsInIns (const char *FieldName,const char *Name,
|
||||
long CtrCod,long InsCod);
|
||||
void Ctr_ChangeCtrWWW (void);
|
||||
void Ctr_DB_UpdateCtrWWW (long CtrCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1]);
|
||||
void Ctr_ChangeCtrStatus (void);
|
||||
void Ctr_ContEditAfterChgCtr (void);
|
||||
|
||||
|
@ -145,8 +139,6 @@ unsigned Ctr_GetCachedNumCtrsWithMapInSys (void);
|
|||
unsigned Ctr_GetCachedNumCtrsWithMapInCty (long CtyCod);
|
||||
unsigned Ctr_GetCachedNumCtrsWithMapInIns (long InsCod);
|
||||
|
||||
unsigned Ctr_DB_GetNumCtrsInPlc (long PlcCod);
|
||||
|
||||
unsigned Ctr_GetCachedNumCtrsWithDegs (const char *SubQuery,
|
||||
HieLvl_Level_t Scope,long Cod);
|
||||
unsigned Ctr_GetCachedNumCtrsWithCrss (const char *SubQuery,
|
||||
|
|
|
@ -32,8 +32,8 @@
|
|||
|
||||
#include "swad_center.h"
|
||||
#include "swad_center_config.h"
|
||||
// #include "swad_database.h"
|
||||
// #include "swad_error.h"
|
||||
#include "swad_database.h"
|
||||
#include "swad_error.h"
|
||||
// #include "swad_figure.h"
|
||||
// #include "swad_figure_cache.h"
|
||||
// #include "swad_form.h"
|
||||
|
@ -68,3 +68,325 @@ extern struct Globals Gbl;
|
|||
/*****************************************************************************/
|
||||
/***************************** Private prototypes ****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Create a new center ***************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
long Ctr_DB_CreateCenter (const struct Ctr_Center *Ctr,unsigned Status)
|
||||
{
|
||||
return
|
||||
DB_QueryINSERTandReturnCode ("can not create a new center",
|
||||
"INSERT INTO ctr_centers"
|
||||
" (InsCod,PlcCod,Status,RequesterUsrCod,"
|
||||
"ShortName,FullName,WWW,PhotoAttribution)"
|
||||
" VALUES"
|
||||
" (%ld,%ld,%u,%ld,"
|
||||
"'%s','%s','%s','')",
|
||||
Ctr->InsCod,
|
||||
Ctr->PlcCod,
|
||||
Status,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
Ctr->ShrtName,
|
||||
Ctr->FullName,
|
||||
Ctr->WWW);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************ Get basic list of centers ordered by name of center ************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Ctr_DB_GetListOfCtrsInCurrentIns (MYSQL_RES **mysql_res)
|
||||
{
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get centers",
|
||||
"SELECT DISTINCT CtrCod," // row[0]
|
||||
"ShortName" // row[1]
|
||||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld"
|
||||
" ORDER BY ShortName",
|
||||
Gbl.Hierarchy.Ins.InsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************ Get full list of centers ordered by name of center ************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Ctr_DB_GetListOfCtrsFull (MYSQL_RES **mysql_res,long InsCod)
|
||||
{
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get centers",
|
||||
"SELECT CtrCod," // row[ 0]
|
||||
"InsCod," // row[ 1]
|
||||
"PlcCod," // row[ 2]
|
||||
"Status," // row[ 3]
|
||||
"RequesterUsrCod," // row[ 4]
|
||||
"Latitude," // row[ 5]
|
||||
"Longitude," // row[ 6]
|
||||
"Altitude," // row[ 7]
|
||||
"ShortName," // row[ 8]
|
||||
"FullName," // row[ 9]
|
||||
"WWW" // row[10]
|
||||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld"
|
||||
" ORDER BY FullName",
|
||||
InsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************* Get full list of centers **************/
|
||||
/************* with number of users who claim to belong to them **************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Ctr_DB_GetListOfCtrsFullWithNumUsrs (MYSQL_RES **mysql_res,
|
||||
long InsCod,Ctr_Order_t SelectedOrder)
|
||||
{
|
||||
static const char *OrderBySubQuery[Ctr_NUM_ORDERS] =
|
||||
{
|
||||
[Ctr_ORDER_BY_CENTER ] = "FullName",
|
||||
[Ctr_ORDER_BY_NUM_USRS] = "NumUsrs DESC,"
|
||||
"FullName",
|
||||
};
|
||||
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get centers",
|
||||
"(SELECT ctr_centers.CtrCod," // row[ 0]
|
||||
"ctr_centers.InsCod," // row[ 1]
|
||||
"ctr_centers.PlcCod," // row[ 2]
|
||||
"ctr_centers.Status," // row[ 3]
|
||||
"ctr_centers.RequesterUsrCod," // row[ 4]
|
||||
"ctr_centers.Latitude," // row[ 5]
|
||||
"ctr_centers.Longitude," // row[ 6]
|
||||
"ctr_centers.Altitude," // row[ 7]
|
||||
"ctr_centers.ShortName," // row[ 8]
|
||||
"ctr_centers.FullName," // row[ 9]
|
||||
"ctr_centers.WWW," // row[10]
|
||||
"COUNT(*) AS NumUsrs" // row[11]
|
||||
" FROM ctr_centers,usr_data"
|
||||
" WHERE ctr_centers.InsCod=%ld"
|
||||
" AND ctr_centers.CtrCod=usr_data.CtrCod"
|
||||
" GROUP BY ctr_centers.CtrCod)"
|
||||
" UNION "
|
||||
"(SELECT CtrCod," // row[ 0]
|
||||
"InsCod," // row[ 1]
|
||||
"PlcCod," // row[ 2]
|
||||
"Status," // row[ 3]
|
||||
"RequesterUsrCod," // row[ 4]
|
||||
"Latitude," // row[ 5]
|
||||
"Longitude," // row[ 6]
|
||||
"Altitude," // row[ 7]
|
||||
"ShortName," // row[ 8]
|
||||
"FullName," // row[ 9]
|
||||
"WWW," // row[10]
|
||||
"0 AS NumUsrs" // row[11]
|
||||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld"
|
||||
" AND CtrCod NOT IN"
|
||||
" (SELECT DISTINCT CtrCod"
|
||||
" FROM usr_data))"
|
||||
" ORDER BY %s",
|
||||
InsCod,
|
||||
InsCod,
|
||||
OrderBySubQuery[SelectedOrder]);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************* Get centers with pending degrees ***********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Ctr_DB_GetCtrsWithPendingDegs (MYSQL_RES **mysql_res)
|
||||
{
|
||||
switch (Gbl.Usrs.Me.Role.Logged)
|
||||
{
|
||||
case Rol_CTR_ADM:
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get centers with pending degrees",
|
||||
"SELECT deg_degrees.CtrCod," // row[0]
|
||||
"COUNT(*)" // row[1]
|
||||
" FROM deg_degrees,"
|
||||
"ctr_admin,"
|
||||
"ctr_centers"
|
||||
" WHERE (deg_degrees.Status & %u)<>0"
|
||||
" AND deg_degrees.CtrCod=ctr_admin.CtrCod"
|
||||
" AND ctr_admin.UsrCod=%ld"
|
||||
" AND deg_degrees.CtrCod=ctr_centers.CtrCod"
|
||||
" GROUP BY deg_degrees.CtrCod"
|
||||
" ORDER BY ctr_centers.ShortName",
|
||||
(unsigned) Deg_STATUS_BIT_PENDING,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
case Rol_SYS_ADM:
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get centers with pending degrees",
|
||||
"SELECT deg_degrees.CtrCod," // row[0]
|
||||
"COUNT(*)" // row[1]
|
||||
" FROM deg_degrees,"
|
||||
"ctr_centers"
|
||||
" WHERE (deg_degrees.Status & %u)<>0"
|
||||
" AND deg_degrees.CtrCod=ctr_centers.CtrCod"
|
||||
" GROUP BY deg_degrees.CtrCod"
|
||||
" ORDER BY ctr_centers.ShortName",
|
||||
(unsigned) Deg_STATUS_BIT_PENDING);
|
||||
default: // Forbidden for other users
|
||||
Err_WrongRoleExit ();
|
||||
return 0; // Not reached
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************ Get data of center by code *************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Ctr_DB_GetDataOfCenterByCod (MYSQL_RES **mysql_res,long CtrCod)
|
||||
{
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get data of a center",
|
||||
"SELECT CtrCod," // row[ 0]
|
||||
"InsCod," // row[ 1]
|
||||
"PlcCod," // row[ 2]
|
||||
"Status," // row[ 3]
|
||||
"RequesterUsrCod," // row[ 4]
|
||||
"Latitude," // row[ 5]
|
||||
"Longitude," // row[ 6]
|
||||
"Altitude," // row[ 7]
|
||||
"ShortName," // row[ 8]
|
||||
"FullName," // row[ 9]
|
||||
"WWW" // row[10]
|
||||
" FROM ctr_centers"
|
||||
" WHERE CtrCod=%ld",
|
||||
CtrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********** Get the institution code of a center from its code **************/
|
||||
/*****************************************************************************/
|
||||
|
||||
long Ctr_DB_GetInsCodOfCenterByCod (long CtrCod)
|
||||
{
|
||||
/***** Trivial check: center code should be > 0 *****/
|
||||
if (CtrCod <= 0)
|
||||
return -1L;
|
||||
|
||||
/***** Get the institution code of a center from database *****/
|
||||
return DB_QuerySELECTCode ("can not get the institution of a center",
|
||||
"SELECT InsCod"
|
||||
" FROM ctr_centers"
|
||||
" WHERE CtrCod=%ld",
|
||||
CtrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*************** Get the short name of a center from its code ****************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Ctr_DB_GetShortNameOfCenterByCod (long CtrCod,char ShrtName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1])
|
||||
{
|
||||
/***** Trivial check: center code should be > 0 *****/
|
||||
if (CtrCod <= 0)
|
||||
{
|
||||
ShrtName[0] = '\0';
|
||||
return;
|
||||
}
|
||||
|
||||
/***** Get the short name of a center from database *****/
|
||||
DB_QuerySELECTString (ShrtName,Cns_HIERARCHY_MAX_BYTES_SHRT_NAME,
|
||||
"can not get the short name of a center",
|
||||
"SELECT ShortName"
|
||||
" FROM ctr_centers"
|
||||
" WHERE CtrCod=%ld",
|
||||
CtrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************* Check if the name of center exists ********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
bool Ctr_DB_CheckIfCtrNameExistsInIns (const char *FieldName,const char *Name,
|
||||
long CtrCod,long InsCod)
|
||||
{
|
||||
/***** Get number of centers with a name from database *****/
|
||||
return (DB_QueryCOUNT ("can not check if the name of a center"
|
||||
" already existed",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld"
|
||||
" AND %s='%s'"
|
||||
" AND CtrCod<>%ld",
|
||||
InsCod,
|
||||
FieldName,
|
||||
Name,
|
||||
CtrCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******* Get number of centers (of the current institution) in a place *******/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Ctr_DB_GetNumCtrsInPlc (long PlcCod)
|
||||
{
|
||||
/***** Get number of centers (of the current institution) in a place *****/
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get the number of centers in a place",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld"
|
||||
" AND PlcCod=%ld",
|
||||
Gbl.Hierarchy.Ins.InsCod,
|
||||
PlcCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************** Update database changing old place by new place **************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Ctr_DB_UpdateCtrPlc (long CtrCod,long NewPlcCod)
|
||||
{
|
||||
DB_QueryUPDATE ("can not update the place of a center",
|
||||
"UPDATE ctr_centers"
|
||||
" SET PlcCod=%ld"
|
||||
" WHERE CtrCod=%ld",
|
||||
NewPlcCod,
|
||||
CtrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/****************** Update center name in table of centers *******************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Ctr_DB_UpdateCtrName (long CtrCod,const char *FieldName,const char *NewCtrName)
|
||||
{
|
||||
/***** Update center changing old name by new name */
|
||||
DB_QueryUPDATE ("can not update the name of a center",
|
||||
"UPDATE ctr_centers"
|
||||
" SET %s='%s'"
|
||||
" WHERE CtrCod=%ld",
|
||||
FieldName,
|
||||
NewCtrName,
|
||||
CtrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**************** Update database changing old WWW by new WWW ****************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Ctr_DB_UpdateCtrWWW (long CtrCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1])
|
||||
{
|
||||
/***** Update database changing old WWW by new WWW *****/
|
||||
DB_QueryUPDATE ("can not update the web of a center",
|
||||
"UPDATE ctr_centers"
|
||||
" SET WWW='%s'"
|
||||
" WHERE CtrCod=%ld",
|
||||
NewWWW,
|
||||
CtrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/****************************** Remove a center ******************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Ctr_DB_RemoveCenter (long CtrCod)
|
||||
{
|
||||
DB_QueryDELETE ("can not remove a center",
|
||||
"DELETE FROM ctr_centers"
|
||||
" WHERE CtrCod=%ld",
|
||||
CtrCod);
|
||||
}
|
||||
|
|
|
@ -27,10 +27,11 @@
|
|||
/********************************* Headers ***********************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
// #include <mysql/mysql.h> // To access MySQL databases
|
||||
#include <mysql/mysql.h> // To access MySQL databases
|
||||
|
||||
// #include "swad_action.h"
|
||||
// #include "swad_constant.h"
|
||||
#include "swad_center.h"
|
||||
#include "swad_constant.h"
|
||||
// #include "swad_degree.h"
|
||||
// #include "swad_map.h"
|
||||
// #include "swad_role_type.h"
|
||||
|
@ -43,4 +44,24 @@
|
|||
/****************************** Public prototypes ****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
long Ctr_DB_CreateCenter (const struct Ctr_Center *Ctr,unsigned Status);
|
||||
|
||||
unsigned Ctr_DB_GetListOfCtrsInCurrentIns (MYSQL_RES **mysql_res);
|
||||
unsigned Ctr_DB_GetListOfCtrsFull (MYSQL_RES **mysql_res,long InsCod);
|
||||
unsigned Ctr_DB_GetListOfCtrsFullWithNumUsrs (MYSQL_RES **mysql_res,
|
||||
long InsCod,Ctr_Order_t SelectedOrder);
|
||||
unsigned Ctr_DB_GetCtrsWithPendingDegs (MYSQL_RES **mysql_res);
|
||||
unsigned Ctr_DB_GetDataOfCenterByCod (MYSQL_RES **mysql_res,long CtrCod);
|
||||
long Ctr_DB_GetInsCodOfCenterByCod (long CtrCod);
|
||||
void Ctr_DB_GetShortNameOfCenterByCod (long CtrCod,char ShrtName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1]);
|
||||
bool Ctr_DB_CheckIfCtrNameExistsInIns (const char *FieldName,const char *Name,
|
||||
long CtrCod,long InsCod);
|
||||
unsigned Ctr_DB_GetNumCtrsInPlc (long PlcCod);
|
||||
|
||||
void Ctr_DB_UpdateCtrPlc (long CtrCod,long NewPlcCod);
|
||||
void Ctr_DB_UpdateCtrName (long CtrCod,const char *FieldName,const char *NewCtrName);
|
||||
void Ctr_DB_UpdateCtrWWW (long CtrCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1]);
|
||||
|
||||
void Ctr_DB_RemoveCenter (long CtrCod);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par
|
|||
|
||||
TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
|
||||
*/
|
||||
#define Log_PLATFORM_VERSION "SWAD 20.88 (2021-06-02)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 20.88.1 (2021-06-02)"
|
||||
#define CSS_FILE "swad20.45.css"
|
||||
#define JS_FILE "swad20.69.1.js"
|
||||
/*
|
||||
TODO: Rename CENTRE to CENTER in help wiki.
|
||||
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
||||
|
||||
Version 20.88.1: Jun 02, 2021 Queries moved to module swad_center_database. (312668 lines)
|
||||
Version 20.88: Jun 02, 2021 New module swad_center_database for database queries related to centers. (312638 lines)
|
||||
Version 20.87.1: Jun 01, 2021 Database function moved from swad_calendar to swad_setting. (312549 lines)
|
||||
Version 20.87: Jun 01, 2021 New module swad_building_database for database queries related to buildings. (312538 lines)
|
||||
|
|
|
@ -532,7 +532,7 @@ void Cty_DB_UpdateCtyMapAttr (const char NewMapAttribution[Med_MAX_BYTES_ATTRIBU
|
|||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************************* Remove country ****************************/
|
||||
/******************************* Remove a country ****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Cty_DB_RemoveCty (long CtyCod)
|
||||
|
|
|
@ -280,22 +280,22 @@ long Deg_DB_GetCtrCodOfDegreeByCod (long DegCod)
|
|||
/************* Get the short name of a degree from its code ******************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Deg_DB_GetShortNameOfDegreeByCod (struct Deg_Degree *Deg)
|
||||
void Deg_DB_GetShortNameOfDegreeByCod (long DegCod,char ShrtName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1])
|
||||
{
|
||||
/***** Trivial check: degree code should be > 0 *****/
|
||||
if (Deg->DegCod > 0)
|
||||
if (DegCod > 0)
|
||||
{
|
||||
Deg->ShrtName[0] = '\0';
|
||||
ShrtName[0] = '\0';
|
||||
return;
|
||||
}
|
||||
|
||||
/***** Get the short name of a degree from database *****/
|
||||
DB_QuerySELECTString (Deg->ShrtName,sizeof (Deg->ShrtName) - 1,
|
||||
DB_QuerySELECTString (ShrtName,Cns_HIERARCHY_MAX_BYTES_SHRT_NAME,
|
||||
"can not get the short name of a degree",
|
||||
"SELECT ShortName"
|
||||
" FROM deg_degrees"
|
||||
" WHERE DegCod=%ld",
|
||||
Deg->DegCod);
|
||||
DegCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -661,7 +661,7 @@ void Deg_DB_RemoveDegTyp (long DegTypCod)
|
|||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Remove the degree *****************************/
|
||||
/****************************** Remove a degree ******************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Deg_DB_RemoveDeg (long DegCod)
|
||||
|
|
|
@ -53,7 +53,7 @@ void Deg_DB_GetDegTypeNameByCod (struct DegreeType *DegTyp);
|
|||
unsigned Deg_DB_GetDataOfDegreeByCod (MYSQL_RES **mysql_res,long DegCod);
|
||||
long Deg_DB_GetInsCodOfDegreeByCod (long DegCod);
|
||||
long Deg_DB_GetCtrCodOfDegreeByCod (long DegCod);
|
||||
void Deg_DB_GetShortNameOfDegreeByCod (struct Deg_Degree *Deg);
|
||||
void Deg_DB_GetShortNameOfDegreeByCod (long DegCod,char ShrtName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1]);
|
||||
bool Deg_DB_CheckIfDegreeTypeNameExists (const char *DegTypName,long DegTypCod);
|
||||
unsigned Deg_DB_GetNumDegsOfType (long DegTypCod);
|
||||
unsigned Deg_DB_GetDegsOfType (MYSQL_RES **mysql_res,long DegTypCod);
|
||||
|
|
|
@ -308,7 +308,6 @@ void Gbl_InitializeGlobals (void)
|
|||
|
||||
/* Flush caches */
|
||||
Cty_FlushCacheCountryName ();
|
||||
Ins_FlushCacheShortNameOfInstitution ();
|
||||
Ins_FlushCacheFullNameAndCtyOfInstitution ();
|
||||
|
||||
Ins_FlushCacheNumInssInCty ();
|
||||
|
|
|
@ -449,11 +449,6 @@ struct Globals
|
|||
Lan_Language_t Language;
|
||||
char CtyName[Cty_MAX_BYTES_NAME + 1];
|
||||
} CountryName;
|
||||
struct
|
||||
{
|
||||
long InsCod;
|
||||
char ShrtName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1];
|
||||
} InstitutionShrtName;
|
||||
struct
|
||||
{
|
||||
long InsCod;
|
||||
|
|
|
@ -860,40 +860,22 @@ static void Ins_GetDataOfInstitFromRow (struct Ins_Instit *Ins,MYSQL_ROW row)
|
|||
/*********** Get the short name of an institution from its code **************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Ins_FlushCacheShortNameOfInstitution (void)
|
||||
void Ins_DB_GetShortNameOfInstitution (long InsCod,char ShrtName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1])
|
||||
{
|
||||
Gbl.Cache.InstitutionShrtName.InsCod = -1L;
|
||||
Gbl.Cache.InstitutionShrtName.ShrtName[0] = '\0';
|
||||
}
|
||||
|
||||
void Ins_GetShortNameOfInstitution (struct Ins_Instit *Ins)
|
||||
/***** Trivial check: institution code should be > 0 *****/
|
||||
if (InsCod <= 0)
|
||||
{
|
||||
/***** 1. Fast check: Trivial case *****/
|
||||
if (Ins->InsCod <= 0)
|
||||
{
|
||||
Ins->ShrtName[0] = '\0'; // Empty name
|
||||
ShrtName[0] = '\0'; // Empty name
|
||||
return;
|
||||
}
|
||||
|
||||
/***** 2. Fast check: If cached... *****/
|
||||
if (Ins->InsCod == Gbl.Cache.InstitutionShrtName.InsCod)
|
||||
{
|
||||
Str_Copy (Ins->ShrtName,Gbl.Cache.InstitutionShrtName.ShrtName,
|
||||
sizeof (Ins->ShrtName) - 1);
|
||||
return;
|
||||
}
|
||||
|
||||
/***** 3. Slow: get short name of institution from database *****/
|
||||
Gbl.Cache.InstitutionShrtName.InsCod = Ins->InsCod;
|
||||
DB_QuerySELECTString (Gbl.Cache.InstitutionShrtName.ShrtName,
|
||||
sizeof (Gbl.Cache.InstitutionShrtName.ShrtName) - 1,
|
||||
/***** Get short name of institution from database *****/
|
||||
DB_QuerySELECTString (ShrtName,Cns_HIERARCHY_MAX_BYTES_SHRT_NAME,
|
||||
"can not get the short name of an institution",
|
||||
"SELECT ShortName"
|
||||
" FROM ins_instits"
|
||||
" WHERE InsCod=%ld",
|
||||
Ins->InsCod);
|
||||
Str_Copy (Ins->ShrtName,Gbl.Cache.InstitutionShrtName.ShrtName,
|
||||
sizeof (Ins->ShrtName) - 1);
|
||||
InsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -1392,7 +1374,6 @@ void Ins_RemoveInstitution (void)
|
|||
Ins_EditingIns->InsCod);
|
||||
|
||||
/***** Flush caches *****/
|
||||
Ins_FlushCacheShortNameOfInstitution ();
|
||||
Ins_FlushCacheFullNameAndCtyOfInstitution ();
|
||||
Dpt_FlushCacheNumDptsInIns ();
|
||||
Ctr_FlushCacheNumCtrsInIns ();
|
||||
|
@ -1541,7 +1522,6 @@ static void Ins_UpdateInsNameDB (long InsCod,const char *FieldName,const char *N
|
|||
InsCod);
|
||||
|
||||
/***** Flush caches *****/
|
||||
Ins_FlushCacheShortNameOfInstitution ();
|
||||
Ins_FlushCacheFullNameAndCtyOfInstitution ();
|
||||
}
|
||||
|
||||
|
|
|
@ -104,8 +104,7 @@ void Ins_GetFullListOfInstitutions (long CtyCod);
|
|||
|
||||
void Ins_WriteInstitutionNameAndCty (long InsCod);
|
||||
bool Ins_GetDataOfInstitutionByCod (struct Ins_Instit *Ins);
|
||||
void Ins_FlushCacheShortNameOfInstitution (void);
|
||||
void Ins_GetShortNameOfInstitution (struct Ins_Instit *Ins);
|
||||
void Ins_DB_GetShortNameOfInstitution (long InsCod,char ShrtName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1]);
|
||||
void Ins_FlushCacheFullNameAndCtyOfInstitution (void);
|
||||
|
||||
void Ins_FreeListInstitutions (void);
|
||||
|
|
10
swad_log.c
10
swad_log.c
|
@ -30,6 +30,7 @@
|
|||
|
||||
#include "swad_action.h"
|
||||
#include "swad_banner.h"
|
||||
#include "swad_center_database.h"
|
||||
#include "swad_config.h"
|
||||
#include "swad_database.h"
|
||||
#include "swad_degree_database.h"
|
||||
|
@ -334,15 +335,15 @@ void Log_GetAndShowLastClicks (void)
|
|||
|
||||
/* Get institution code (row[5]) */
|
||||
Hie.Ins.InsCod = Str_ConvertStrCodToLongCod (row[5]);
|
||||
Ins_GetShortNameOfInstitution (&Hie.Ins);
|
||||
Ins_DB_GetShortNameOfInstitution (Hie.Ins.InsCod,Hie.Ins.ShrtName);
|
||||
|
||||
/* Get center code (row[6]) */
|
||||
Hie.Ctr.CtrCod = Str_ConvertStrCodToLongCod (row[6]);
|
||||
Ctr_GetShortNameOfCenterByCod (&Hie.Ctr);
|
||||
Ctr_DB_GetShortNameOfCenterByCod (Hie.Ctr.CtrCod,Hie.Ctr.ShrtName);
|
||||
|
||||
/* Get degree code (row[7]) */
|
||||
Hie.Deg.DegCod = Str_ConvertStrCodToLongCod (row[7]);
|
||||
Deg_DB_GetShortNameOfDegreeByCod (&Hie.Deg);
|
||||
Deg_DB_GetShortNameOfDegreeByCod (Hie.Deg.DegCod,Hie.Deg.ShrtName);
|
||||
|
||||
/* Print table row */
|
||||
HTM_TR_Begin (NULL);
|
||||
|
@ -356,8 +357,7 @@ void Log_GetAndShowLastClicks (void)
|
|||
HTM_TD_End ();
|
||||
|
||||
HTM_TD_Begin ("class=\"LC_ROL %s\"",ClassRow);
|
||||
HTM_Txt ( // Role
|
||||
Txt_ROLES_SINGUL_Abc[Rol_ConvertUnsignedStrToRole (row[3])][Usr_SEX_UNKNOWN]);
|
||||
HTM_Txt (Txt_ROLES_SINGUL_Abc[Rol_ConvertUnsignedStrToRole (row[3])][Usr_SEX_UNKNOWN]); // Role
|
||||
HTM_TD_End ();
|
||||
|
||||
HTM_TD_Begin ("class=\"LC_CTY %s\"",ClassRow);
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "swad_action.h"
|
||||
#include "swad_box.h"
|
||||
#include "swad_degree_database.h"
|
||||
#include "swad_center_database.h"
|
||||
#include "swad_error.h"
|
||||
#include "swad_form.h"
|
||||
#include "swad_global.h"
|
||||
|
@ -143,7 +144,7 @@ void Lgo_DrawLogo (HieLvl_Level_t Scope,long Cod,const char *AltText,
|
|||
if (Scope == HieLvl_DEG) // && !LogoFound
|
||||
InsCod = Deg_DB_GetInsCodOfDegreeByCod (Cod);
|
||||
else if (Scope == HieLvl_CTR) // && !LogoFound
|
||||
InsCod = Ctr_GetInsCodOfCenterByCod (Cod);
|
||||
InsCod = Ctr_DB_GetInsCodOfCenterByCod (Cod);
|
||||
else
|
||||
InsCod = Cod;
|
||||
snprintf (PathLogo,sizeof (PathLogo),"%s/%02u/%u/logo/%u.png",
|
||||
|
|
|
@ -1115,6 +1115,7 @@ void Pho_ShowUsrPhoto (const struct UsrData *UsrDat,const char *PhotoURL,
|
|||
else
|
||||
Frm_BeginForm (ActSeeOthPubPrf);
|
||||
Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
|
||||
|
||||
HTM_BUTTON_SUBMIT_Begin (NULL,"BT_LINK",NULL);
|
||||
}
|
||||
|
||||
|
@ -1227,6 +1228,7 @@ void Pho_ShowUsrPhoto (const struct UsrData *UsrDat,const char *PhotoURL,
|
|||
if (PutLinkToPublicProfile)
|
||||
{
|
||||
HTM_BUTTON_End ();
|
||||
|
||||
Frm_EndForm ();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -363,7 +363,7 @@ void Set_DB_ChangeFirstDayOfWeek (unsigned FirstDayOfWeek)
|
|||
"UPDATE usr_data"
|
||||
" SET FirstDayOfWeek=%u"
|
||||
" WHERE UsrCod=%ld",
|
||||
Gbl.Prefs.FirstDayOfWeek,
|
||||
FirstDayOfWeek,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue