mirror of https://github.com/acanas/swad-core.git
Version 20.99: Sep 10, 2021 Queries moved to module swad_institution_database.
This commit is contained in:
parent
986005e2ca
commit
87d72a9d6f
|
@ -406,7 +406,8 @@ unsigned Ctr_DB_GetNumCtrsWithMapInIns (long InsCod)
|
||||||
" FROM ctr_centers"
|
" FROM ctr_centers"
|
||||||
" WHERE InsCod=%ld"
|
" WHERE InsCod=%ld"
|
||||||
" AND (Latitude<>0"
|
" AND (Latitude<>0"
|
||||||
" OR Longitude<>0)",
|
" OR"
|
||||||
|
" Longitude<>0)",
|
||||||
InsCod);
|
InsCod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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.
|
TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
|
||||||
*/
|
*/
|
||||||
#define Log_PLATFORM_VERSION "SWAD 20.98 (2021-09-10)"
|
#define Log_PLATFORM_VERSION "SWAD 20.99 (2021-09-10)"
|
||||||
#define CSS_FILE "swad20.45.css"
|
#define CSS_FILE "swad20.45.css"
|
||||||
#define JS_FILE "swad20.69.1.js"
|
#define JS_FILE "swad20.69.1.js"
|
||||||
/*
|
/*
|
||||||
TODO: Rename CENTRE to CENTER in help wiki.
|
TODO: Rename CENTRE to CENTER in help wiki.
|
||||||
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
||||||
|
|
||||||
|
Version 20.99: Sep 10, 2021 Queries moved to module swad_institution_database. (314758 lines)
|
||||||
Version 20.98: Sep 10, 2021 New module swad_institution_database for database queries related to institutions. (314663 lines)
|
Version 20.98: Sep 10, 2021 New module swad_institution_database for database queries related to institutions. (314663 lines)
|
||||||
Version 20.97: Sep 10, 2021 Code refactoring related to scope. (314566 lines)
|
Version 20.97: Sep 10, 2021 Code refactoring related to scope. (314566 lines)
|
||||||
Version 20.96.7: Sep 09, 2021 Queries moved to module swad_exam_database. (314527 lines)
|
Version 20.96.7: Sep 09, 2021 Queries moved to module swad_exam_database. (314527 lines)
|
||||||
|
|
|
@ -126,7 +126,7 @@ void Ins_SeeInsWithPendingCtrs (void)
|
||||||
extern const char *Txt_There_are_no_institutions_with_requests_for_centers_to_be_confirmed;
|
extern const char *Txt_There_are_no_institutions_with_requests_for_centers_to_be_confirmed;
|
||||||
MYSQL_RES *mysql_res;
|
MYSQL_RES *mysql_res;
|
||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
unsigned NumInss;
|
unsigned NumInss = 0;
|
||||||
unsigned NumIns;
|
unsigned NumIns;
|
||||||
struct Ins_Instit Ins;
|
struct Ins_Instit Ins;
|
||||||
const char *BgColor;
|
const char *BgColor;
|
||||||
|
@ -135,37 +135,14 @@ void Ins_SeeInsWithPendingCtrs (void)
|
||||||
switch (Gbl.Usrs.Me.Role.Logged)
|
switch (Gbl.Usrs.Me.Role.Logged)
|
||||||
{
|
{
|
||||||
case Rol_INS_ADM:
|
case Rol_INS_ADM:
|
||||||
NumInss = (unsigned)
|
NumInss = Ins_DB_GetInsWithPendingCtrsAdminByMe (&mysql_res);
|
||||||
DB_QuerySELECT (&mysql_res,"can not get institutions with pending centers",
|
|
||||||
"SELECT ctr_centers.InsCod," // row[0]
|
|
||||||
"COUNT(*)" // row[1]
|
|
||||||
" FROM ctr_centers,"
|
|
||||||
"ins_admin,"
|
|
||||||
"ins_instits"
|
|
||||||
" WHERE (ctr_centers.Status & %u)<>0"
|
|
||||||
" AND ctr_centers.InsCod=ins_admin.InsCod"
|
|
||||||
" AND ins_admin.UsrCod=%ld"
|
|
||||||
" AND ctr_centers.InsCod=ins_instits.InsCod"
|
|
||||||
" GROUP BY ctr_centers.InsCod"
|
|
||||||
" ORDER BY ins_instits.ShortName",
|
|
||||||
(unsigned) Ctr_STATUS_BIT_PENDING,
|
|
||||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
|
||||||
break;
|
break;
|
||||||
case Rol_SYS_ADM:
|
case Rol_SYS_ADM:
|
||||||
NumInss = (unsigned)
|
NumInss = Ins_DB_GetAllInsWithPendingCtr (&mysql_res);
|
||||||
DB_QuerySELECT (&mysql_res,"can not get institutions with pending centers",
|
|
||||||
"SELECT ctr_centers.InsCod," // row[0]
|
|
||||||
"COUNT(*)" // row[1]
|
|
||||||
" FROM ctr_centers,"
|
|
||||||
"ins_instits"
|
|
||||||
" WHERE (ctr_centers.Status & %u)<>0"
|
|
||||||
" AND ctr_centers.InsCod=ins_instits.InsCod"
|
|
||||||
" GROUP BY ctr_centers.InsCod"
|
|
||||||
" ORDER BY ins_instits.ShortName",
|
|
||||||
(unsigned) Ctr_STATUS_BIT_PENDING);
|
|
||||||
break;
|
break;
|
||||||
default: // Forbidden for other users
|
default: // Forbidden for other users
|
||||||
return;
|
Err_WrongRoleExit ();
|
||||||
|
break; // Not reached
|
||||||
}
|
}
|
||||||
|
|
||||||
/***** Get institutions *****/
|
/***** Get institutions *****/
|
||||||
|
@ -636,21 +613,7 @@ void Ins_GetBasicListOfInstitutions (long CtyCod)
|
||||||
struct Ins_Instit *Ins;
|
struct Ins_Instit *Ins;
|
||||||
|
|
||||||
/***** Get institutions from database *****/
|
/***** Get institutions from database *****/
|
||||||
Gbl.Hierarchy.Inss.Num = (unsigned)
|
if ((Gbl.Hierarchy.Inss.Num = Ins_DB_GetInssInCtyOrderedByFullName (&mysql_res,CtyCod))) // Institutions found...
|
||||||
DB_QuerySELECT (&mysql_res,"can not get institutions",
|
|
||||||
"SELECT InsCod," // row[0]
|
|
||||||
"CtyCod," // row[1]
|
|
||||||
"Status," // row[2]
|
|
||||||
"RequesterUsrCod," // row[3]
|
|
||||||
"ShortName," // row[4]
|
|
||||||
"FullName," // row[5]
|
|
||||||
"WWW" // row[6]
|
|
||||||
" FROM ins_instits"
|
|
||||||
" WHERE CtyCod=%ld"
|
|
||||||
" ORDER BY FullName",
|
|
||||||
CtyCod);
|
|
||||||
|
|
||||||
if (Gbl.Hierarchy.Inss.Num) // Institutions found...
|
|
||||||
{
|
{
|
||||||
/***** Create list with institutions *****/
|
/***** Create list with institutions *****/
|
||||||
if ((Gbl.Hierarchy.Inss.Lst = calloc ((size_t) Gbl.Hierarchy.Inss.Num,
|
if ((Gbl.Hierarchy.Inss.Lst = calloc ((size_t) Gbl.Hierarchy.Inss.Num,
|
||||||
|
@ -686,53 +649,13 @@ void Ins_GetBasicListOfInstitutions (long CtyCod)
|
||||||
|
|
||||||
void Ins_GetFullListOfInstitutions (long CtyCod)
|
void Ins_GetFullListOfInstitutions (long CtyCod)
|
||||||
{
|
{
|
||||||
static const char *OrderBySubQuery[Ins_NUM_ORDERS] =
|
|
||||||
{
|
|
||||||
[Ins_ORDER_BY_INSTITUTION] = "FullName",
|
|
||||||
[Ins_ORDER_BY_NUM_USRS ] = "NumUsrs DESC,FullName",
|
|
||||||
};
|
|
||||||
MYSQL_RES *mysql_res;
|
MYSQL_RES *mysql_res;
|
||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
unsigned NumIns;
|
unsigned NumIns;
|
||||||
struct Ins_Instit *Ins;
|
struct Ins_Instit *Ins;
|
||||||
|
|
||||||
/***** Get institutions from database *****/
|
/***** Get institutions from database *****/
|
||||||
/* Query database */
|
if ((Gbl.Hierarchy.Inss.Num = Ins_DB_GetFullListOfInssInCty (&mysql_res,CtyCod))) // Institutions found...
|
||||||
Gbl.Hierarchy.Inss.Num = (unsigned)
|
|
||||||
DB_QuerySELECT (&mysql_res,"can not get institutions",
|
|
||||||
"(SELECT ins_instits.InsCod," // row[0]
|
|
||||||
"ins_instits.CtyCod," // row[1]
|
|
||||||
"ins_instits.Status," // row[2]
|
|
||||||
"ins_instits.RequesterUsrCod," // row[3]
|
|
||||||
"ins_instits.ShortName," // row[4]
|
|
||||||
"ins_instits.FullName," // row[5]
|
|
||||||
"ins_instits.WWW," // row[6]
|
|
||||||
"COUNT(*) AS NumUsrs" // row[7]
|
|
||||||
" FROM ins_instits,"
|
|
||||||
"usr_data"
|
|
||||||
" WHERE ins_instits.CtyCod=%ld"
|
|
||||||
" AND ins_instits.InsCod=usr_data.InsCod"
|
|
||||||
" GROUP BY ins_instits.InsCod)"
|
|
||||||
" UNION "
|
|
||||||
"(SELECT InsCod," // row[0]
|
|
||||||
"CtyCod," // row[1]
|
|
||||||
"Status," // row[2]
|
|
||||||
"RequesterUsrCod," // row[3]
|
|
||||||
"ShortName," // row[4]
|
|
||||||
"FullName," // row[5]
|
|
||||||
"WWW," // row[6]
|
|
||||||
"0 AS NumUsrs" // row[7]
|
|
||||||
" FROM ins_instits"
|
|
||||||
" WHERE CtyCod=%ld"
|
|
||||||
" AND InsCod NOT IN"
|
|
||||||
" (SELECT DISTINCT InsCod"
|
|
||||||
" FROM usr_data))"
|
|
||||||
" ORDER BY %s",
|
|
||||||
CtyCod,
|
|
||||||
CtyCod,
|
|
||||||
OrderBySubQuery[Gbl.Hierarchy.Inss.SelectedOrder]);
|
|
||||||
|
|
||||||
if (Gbl.Hierarchy.Inss.Num) // Institutions found...
|
|
||||||
{
|
{
|
||||||
/***** Create list with institutions *****/
|
/***** Create list with institutions *****/
|
||||||
if ((Gbl.Hierarchy.Inss.Lst = calloc ((size_t) Gbl.Hierarchy.Inss.Num,
|
if ((Gbl.Hierarchy.Inss.Lst = calloc ((size_t) Gbl.Hierarchy.Inss.Num,
|
||||||
|
@ -804,17 +727,7 @@ bool Ins_GetDataOfInstitutionByCod (struct Ins_Instit *Ins)
|
||||||
if (Ins->InsCod > 0)
|
if (Ins->InsCod > 0)
|
||||||
{
|
{
|
||||||
/***** Get data of an institution from database *****/
|
/***** Get data of an institution from database *****/
|
||||||
if (DB_QuerySELECT (&mysql_res,"can not get data of an institution",
|
if (Ins_DB_GetDataOfInstitutionByCod (&mysql_res,Ins->InsCod)) // Institution found...
|
||||||
"SELECT InsCod," // row[0]
|
|
||||||
"CtyCod," // row[1]
|
|
||||||
"Status," // row[2]
|
|
||||||
"RequesterUsrCod," // row[3]
|
|
||||||
"ShortName," // row[4]
|
|
||||||
"FullName," // row[5]
|
|
||||||
"WWW" // row[6]
|
|
||||||
" FROM ins_instits"
|
|
||||||
" WHERE InsCod=%ld",
|
|
||||||
Ins->InsCod)) // Institution found...
|
|
||||||
{
|
{
|
||||||
/* Get institution data */
|
/* Get institution data */
|
||||||
row = mysql_fetch_row (mysql_res);
|
row = mysql_fetch_row (mysql_res);
|
||||||
|
@ -837,6 +750,15 @@ bool Ins_GetDataOfInstitutionByCod (struct Ins_Instit *Ins)
|
||||||
|
|
||||||
static void Ins_GetDataOfInstitFromRow (struct Ins_Instit *Ins,MYSQL_ROW row)
|
static void Ins_GetDataOfInstitFromRow (struct Ins_Instit *Ins,MYSQL_ROW row)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
row[0]: InsCod
|
||||||
|
row[1]: CtyCod
|
||||||
|
row[2]: Status
|
||||||
|
row[3]: RequesterUsrCod
|
||||||
|
row[4]: ShortName
|
||||||
|
row[5]: FullName
|
||||||
|
row[6]: WWW
|
||||||
|
*/
|
||||||
/***** Get institution code (row[0]) *****/
|
/***** Get institution code (row[0]) *****/
|
||||||
if ((Ins->InsCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
|
if ((Ins->InsCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
|
||||||
Err_WrongInstitExit ();
|
Err_WrongInstitExit ();
|
||||||
|
@ -859,20 +781,19 @@ static void Ins_GetDataOfInstitFromRow (struct Ins_Instit *Ins,MYSQL_ROW row)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/************ Get the full name of an institution from its code **************/
|
/******** Get short name and country of an institution from its code *********/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
void Ins_FlushCacheFullNameAndCtyOfInstitution (void)
|
void Ins_FlushCacheFullNameAndCtyOfInstitution (void)
|
||||||
{
|
{
|
||||||
Gbl.Cache.InstitutionShrtNameAndCty.InsCod = -1L;
|
Gbl.Cache.InstitutionShrtNameAndCty.InsCod = -1L;
|
||||||
Gbl.Cache.InstitutionShrtNameAndCty.ShrtName[0] = '\0';
|
Gbl.Cache.InstitutionShrtNameAndCty.ShrtName[0] = '\0';
|
||||||
Gbl.Cache.InstitutionShrtNameAndCty.CtyName[0] = '\0';
|
Gbl.Cache.InstitutionShrtNameAndCty.CtyName[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Ins_GetShrtNameAndCtyOfInstitution (struct Ins_Instit *Ins,
|
static void Ins_GetShrtNameAndCtyOfInstitution (struct Ins_Instit *Ins,
|
||||||
char CtyName[Cns_HIERARCHY_MAX_BYTES_FULL_NAME + 1])
|
char CtyName[Cns_HIERARCHY_MAX_BYTES_FULL_NAME + 1])
|
||||||
{
|
{
|
||||||
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
|
|
||||||
MYSQL_RES *mysql_res;
|
MYSQL_RES *mysql_res;
|
||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
|
|
||||||
|
@ -897,15 +818,7 @@ static void Ins_GetShrtNameAndCtyOfInstitution (struct Ins_Instit *Ins,
|
||||||
/***** 3. Slow: get short name and country of institution from database *****/
|
/***** 3. Slow: get short name and country of institution from database *****/
|
||||||
Gbl.Cache.InstitutionShrtNameAndCty.InsCod = Ins->InsCod;
|
Gbl.Cache.InstitutionShrtNameAndCty.InsCod = Ins->InsCod;
|
||||||
|
|
||||||
if (DB_QuerySELECT (&mysql_res,"can not get short name and country"
|
if (Ins_DB_GetShrtNameAndCtyOfIns (&mysql_res,Ins->InsCod) == 1)
|
||||||
" of an institution",
|
|
||||||
"SELECT ins_instits.ShortName," // row[0]
|
|
||||||
"cty_countrs.Name_%s" // row[1]
|
|
||||||
" FROM ins_instits,"
|
|
||||||
"cty_countrs"
|
|
||||||
" WHERE ins_instits.InsCod=%ld"
|
|
||||||
" AND ins_instits.CtyCod=cty_countrs.CtyCod",
|
|
||||||
Lan_STR_LANG_ID[Gbl.Prefs.Language],Ins->InsCod) == 1)
|
|
||||||
{
|
{
|
||||||
/* Get row */
|
/* Get row */
|
||||||
row = mysql_fetch_row (mysql_res);
|
row = mysql_fetch_row (mysql_res);
|
||||||
|
@ -977,15 +890,8 @@ void Ins_WriteSelectorOfInstitution (void)
|
||||||
|
|
||||||
if (Gbl.Hierarchy.Cty.CtyCod > 0)
|
if (Gbl.Hierarchy.Cty.CtyCod > 0)
|
||||||
{
|
{
|
||||||
/***** Get institutions of selected country from database *****/
|
/***** Get institutions of current country *****/
|
||||||
NumInss = (unsigned)
|
NumInss = Ins_DB_GetInssInCtyOrderedByShrtName (&mysql_res,Gbl.Hierarchy.Cty.CtyCod);
|
||||||
DB_QuerySELECT (&mysql_res,"can not get institutions",
|
|
||||||
"SELECT DISTINCT InsCod," // row[0]
|
|
||||||
"ShortName" // row[1]
|
|
||||||
" FROM ins_instits"
|
|
||||||
" WHERE CtyCod=%ld"
|
|
||||||
" ORDER BY ShortName",
|
|
||||||
Gbl.Hierarchy.Cty.CtyCod);
|
|
||||||
|
|
||||||
/***** List institutions *****/
|
/***** List institutions *****/
|
||||||
for (NumIns = 0;
|
for (NumIns = 0;
|
||||||
|
@ -1355,10 +1261,7 @@ void Ins_RemoveInstitution (void)
|
||||||
Adm_DB_RemAdmins (HieLvl_INS,Ins_EditingIns->InsCod);
|
Adm_DB_RemAdmins (HieLvl_INS,Ins_EditingIns->InsCod);
|
||||||
|
|
||||||
/***** Remove institution *****/
|
/***** Remove institution *****/
|
||||||
DB_QueryDELETE ("can not remove an institution",
|
Ins_DB_RemoveInstitution (Ins_EditingIns->InsCod);
|
||||||
"DELETE FROM ins_instits"
|
|
||||||
" WHERE InsCod=%ld",
|
|
||||||
Ins_EditingIns->InsCod);
|
|
||||||
|
|
||||||
/***** Flush caches *****/
|
/***** Flush caches *****/
|
||||||
Ins_FlushCacheFullNameAndCtyOfInstitution ();
|
Ins_FlushCacheFullNameAndCtyOfInstitution ();
|
||||||
|
@ -1481,12 +1384,7 @@ void Ins_RenameInstitution (struct Ins_Instit *Ins,Cns_ShrtOrFullName_t ShrtOrFu
|
||||||
static void Ins_UpdateInsNameDB (long InsCod,const char *FieldName,const char *NewInsName)
|
static void Ins_UpdateInsNameDB (long InsCod,const char *FieldName,const char *NewInsName)
|
||||||
{
|
{
|
||||||
/***** Update institution changing old name by new name */
|
/***** Update institution changing old name by new name */
|
||||||
DB_QueryUPDATE ("can not update the name of an institution",
|
Ins_DB_UpdateInsName (InsCod,FieldName,NewInsName);
|
||||||
"UPDATE ins_instits"
|
|
||||||
" SET %s='%s'"
|
|
||||||
" WHERE InsCod=%ld",
|
|
||||||
FieldName,NewInsName,
|
|
||||||
InsCod);
|
|
||||||
|
|
||||||
/***** Flush caches *****/
|
/***** Flush caches *****/
|
||||||
Ins_FlushCacheFullNameAndCtyOfInstitution ();
|
Ins_FlushCacheFullNameAndCtyOfInstitution ();
|
||||||
|
@ -1563,12 +1461,7 @@ void Ins_ChangeInsStatus (void)
|
||||||
Ins_GetDataOfInstitutionByCod (Ins_EditingIns);
|
Ins_GetDataOfInstitutionByCod (Ins_EditingIns);
|
||||||
|
|
||||||
/***** Update status in table of institutions *****/
|
/***** Update status in table of institutions *****/
|
||||||
DB_QueryUPDATE ("can not update the status of an institution",
|
Ins_DB_UpdateInsStatus (Status,Ins_EditingIns->InsCod);
|
||||||
"UPDATE ins_instits"
|
|
||||||
" SET Status=%u"
|
|
||||||
" WHERE InsCod=%ld",
|
|
||||||
(unsigned) Status,
|
|
||||||
Ins_EditingIns->InsCod);
|
|
||||||
Ins_EditingIns->Status = Status;
|
Ins_EditingIns->Status = Status;
|
||||||
|
|
||||||
/***** Create message to show the change made
|
/***** Create message to show the change made
|
||||||
|
@ -1875,13 +1768,8 @@ unsigned Ins_GetNumInssInCty (long CtyCod)
|
||||||
|
|
||||||
/***** 2. Slow: number of institutions in a country from database *****/
|
/***** 2. Slow: number of institutions in a country from database *****/
|
||||||
Gbl.Cache.NumInssInCty.CtyCod = CtyCod;
|
Gbl.Cache.NumInssInCty.CtyCod = CtyCod;
|
||||||
Gbl.Cache.NumInssInCty.NumInss = (unsigned)
|
Gbl.Cache.NumInssInCty.NumInss = Ins_DB_GetNumInssInCty (CtyCod);
|
||||||
DB_QueryCOUNT ("can not get the number of institutions in a country",
|
Gbl.Cache.NumInssInCty.Valid = true;
|
||||||
"SELECT COUNT(*)"
|
|
||||||
" FROM ins_instits"
|
|
||||||
" WHERE CtyCod=%ld",
|
|
||||||
CtyCod);
|
|
||||||
Gbl.Cache.NumInssInCty.Valid = true;
|
|
||||||
FigCch_UpdateFigureIntoCache (FigCch_NUM_INSS,HieLvl_CTY,Gbl.Cache.NumInssInCty.CtyCod,
|
FigCch_UpdateFigureIntoCache (FigCch_NUM_INSS,HieLvl_CTY,Gbl.Cache.NumInssInCty.CtyCod,
|
||||||
FigCch_UNSIGNED,&Gbl.Cache.NumInssInCty.NumInss);
|
FigCch_UNSIGNED,&Gbl.Cache.NumInssInCty.NumInss);
|
||||||
return Gbl.Cache.NumInssInCty.NumInss;
|
return Gbl.Cache.NumInssInCty.NumInss;
|
||||||
|
@ -2083,7 +1971,7 @@ static void Ins_FormToGoToMap (struct Ins_Instit *Ins)
|
||||||
{
|
{
|
||||||
extern const char *Txt_Map;
|
extern const char *Txt_Map;
|
||||||
|
|
||||||
if (Ins_GetIfMapIsAvailable (Ins->InsCod))
|
if (Ins_DB_GetIfMapIsAvailable (Ins->InsCod))
|
||||||
{
|
{
|
||||||
Ins_EditingIns = Ins; // Used to pass parameter with the code of the institution
|
Ins_EditingIns = Ins; // Used to pass parameter with the code of the institution
|
||||||
Lay_PutContextualLinkOnlyIcon (ActSeeInsInf,NULL,
|
Lay_PutContextualLinkOnlyIcon (ActSeeInsInf,NULL,
|
||||||
|
@ -2092,36 +1980,3 @@ static void Ins_FormToGoToMap (struct Ins_Instit *Ins)
|
||||||
Txt_Map);
|
Txt_Map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/********** Check if any of the centers in an institution has map ************/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
bool Ins_GetIfMapIsAvailable (long InsCod)
|
|
||||||
{
|
|
||||||
MYSQL_RES *mysql_res;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
bool MapIsAvailable = false;
|
|
||||||
|
|
||||||
/***** Get if any center in current institution has a coordinate set
|
|
||||||
(coordinates 0, 0 means not set ==> don't show map) *****/
|
|
||||||
if (DB_QuerySELECT (&mysql_res,"can not get if map is available",
|
|
||||||
"SELECT EXISTS" // row[0]
|
|
||||||
"(SELECT *"
|
|
||||||
" FROM ctr_centers"
|
|
||||||
" WHERE InsCod=%ld"
|
|
||||||
" AND (Latitude<>0"
|
|
||||||
" OR"
|
|
||||||
" Longitude<>0))",
|
|
||||||
InsCod))
|
|
||||||
{
|
|
||||||
/* Get if map is available */
|
|
||||||
row = mysql_fetch_row (mysql_res);
|
|
||||||
MapIsAvailable = (row[0][0] == '1');
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Free structure that stores the query result */
|
|
||||||
DB_FreeMySQLResult (&mysql_res);
|
|
||||||
|
|
||||||
return MapIsAvailable;
|
|
||||||
}
|
|
||||||
|
|
|
@ -135,6 +135,4 @@ unsigned Ins_GetCachedNumInssWithUsrs (Rol_Role_t Role);
|
||||||
|
|
||||||
void Ins_ListInssFound (MYSQL_RES **mysql_res,unsigned NumInss);
|
void Ins_ListInssFound (MYSQL_RES **mysql_res,unsigned NumInss);
|
||||||
|
|
||||||
bool Ins_GetIfMapIsAvailable (long InsCod);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -72,7 +72,6 @@ extern struct Globals Gbl;
|
||||||
static void InsCfg_Configuration (bool PrintView);
|
static void InsCfg_Configuration (bool PrintView);
|
||||||
static void InsCfg_PutIconsToPrintAndUpload (__attribute__((unused)) void *Args);
|
static void InsCfg_PutIconsToPrintAndUpload (__attribute__((unused)) void *Args);
|
||||||
static void InsCfg_Title (bool PutLink);
|
static void InsCfg_Title (bool PutLink);
|
||||||
static void InsCfg_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom);
|
|
||||||
static void InsCfg_Map (void);
|
static void InsCfg_Map (void);
|
||||||
static void InsCfg_Country (bool PrintView,bool PutForm);
|
static void InsCfg_Country (bool PrintView,bool PutForm);
|
||||||
static void InsCfg_FullName (bool PutForm);
|
static void InsCfg_FullName (bool PutForm);
|
||||||
|
@ -147,52 +146,52 @@ static void InsCfg_Configuration (bool PrintView)
|
||||||
/**************************** Left part ***********************************/
|
/**************************** Left part ***********************************/
|
||||||
HTM_DIV_Begin ("class=\"HIE_CFG_LEFT HIE_CFG_WIDTH\"");
|
HTM_DIV_Begin ("class=\"HIE_CFG_LEFT HIE_CFG_WIDTH\"");
|
||||||
|
|
||||||
/***** Begin table *****/
|
/***** Begin table *****/
|
||||||
HTM_TABLE_BeginWidePadding (2);
|
HTM_TABLE_BeginWidePadding (2);
|
||||||
|
|
||||||
/***** Country *****/
|
/***** Country *****/
|
||||||
InsCfg_Country (PrintView,PutFormCty);
|
InsCfg_Country (PrintView,PutFormCty);
|
||||||
|
|
||||||
/***** Institution name *****/
|
/***** Institution name *****/
|
||||||
InsCfg_FullName (PutFormName);
|
InsCfg_FullName (PutFormName);
|
||||||
InsCfg_ShrtName (PutFormName);
|
InsCfg_ShrtName (PutFormName);
|
||||||
|
|
||||||
/***** Institution WWW *****/
|
/***** Institution WWW *****/
|
||||||
InsCfg_WWW (PrintView,PutFormWWW);
|
InsCfg_WWW (PrintView,PutFormWWW);
|
||||||
|
|
||||||
/***** Shortcut to the institution *****/
|
/***** Shortcut to the institution *****/
|
||||||
InsCfg_Shortcut (PrintView);
|
InsCfg_Shortcut (PrintView);
|
||||||
|
|
||||||
NumCtrsWithMap = Ctr_GetCachedNumCtrsWithMapInIns (Gbl.Hierarchy.Ins.InsCod);
|
NumCtrsWithMap = Ctr_GetCachedNumCtrsWithMapInIns (Gbl.Hierarchy.Ins.InsCod);
|
||||||
if (PrintView)
|
if (PrintView)
|
||||||
/***** QR code with link to the institution *****/
|
/***** QR code with link to the institution *****/
|
||||||
InsCfg_QR ();
|
InsCfg_QR ();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NumCtrs = Ctr_GetCachedNumCtrsInIns (Gbl.Hierarchy.Ins.InsCod);
|
NumCtrs = Ctr_GetCachedNumCtrsInIns (Gbl.Hierarchy.Ins.InsCod);
|
||||||
|
|
||||||
/***** Number of users who claim to belong to this institution,
|
/***** Number of users who claim to belong to this institution,
|
||||||
number of centers,
|
number of centers,
|
||||||
number of degrees,
|
number of degrees,
|
||||||
number of courses,
|
number of courses,
|
||||||
number of departments *****/
|
number of departments *****/
|
||||||
InsCfg_NumUsrs ();
|
InsCfg_NumUsrs ();
|
||||||
HieCfg_NumCtrs (NumCtrs,
|
HieCfg_NumCtrs (NumCtrs,
|
||||||
true); // Put form
|
true); // Put form
|
||||||
HieCfg_NumCtrsWithMap (NumCtrs,NumCtrsWithMap);
|
HieCfg_NumCtrsWithMap (NumCtrs,NumCtrsWithMap);
|
||||||
InsCfg_NumDegs ();
|
InsCfg_NumDegs ();
|
||||||
InsCfg_NumCrss ();
|
InsCfg_NumCrss ();
|
||||||
InsCfg_NumDpts ();
|
InsCfg_NumDpts ();
|
||||||
|
|
||||||
/***** Number of users in courses of this institution *****/
|
/***** Number of users in courses of this institution *****/
|
||||||
HieCfg_NumUsrsInCrss (HieLvl_INS,Gbl.Hierarchy.Ins.InsCod,Rol_TCH);
|
HieCfg_NumUsrsInCrss (HieLvl_INS,Gbl.Hierarchy.Ins.InsCod,Rol_TCH);
|
||||||
HieCfg_NumUsrsInCrss (HieLvl_INS,Gbl.Hierarchy.Ins.InsCod,Rol_NET);
|
HieCfg_NumUsrsInCrss (HieLvl_INS,Gbl.Hierarchy.Ins.InsCod,Rol_NET);
|
||||||
HieCfg_NumUsrsInCrss (HieLvl_INS,Gbl.Hierarchy.Ins.InsCod,Rol_STD);
|
HieCfg_NumUsrsInCrss (HieLvl_INS,Gbl.Hierarchy.Ins.InsCod,Rol_STD);
|
||||||
HieCfg_NumUsrsInCrss (HieLvl_INS,Gbl.Hierarchy.Ins.InsCod,Rol_UNK);
|
HieCfg_NumUsrsInCrss (HieLvl_INS,Gbl.Hierarchy.Ins.InsCod,Rol_UNK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***** End table *****/
|
/***** End table *****/
|
||||||
HTM_TABLE_End ();
|
HTM_TABLE_End ();
|
||||||
|
|
||||||
/***** End of left part *****/
|
/***** End of left part *****/
|
||||||
HTM_DIV_End ();
|
HTM_DIV_End ();
|
||||||
|
@ -202,8 +201,8 @@ static void InsCfg_Configuration (bool PrintView)
|
||||||
{
|
{
|
||||||
HTM_DIV_Begin ("class=\"HIE_CFG_RIGHT HIE_CFG_WIDTH\"");
|
HTM_DIV_Begin ("class=\"HIE_CFG_RIGHT HIE_CFG_WIDTH\"");
|
||||||
|
|
||||||
/***** Institution map *****/
|
/***** Institution map *****/
|
||||||
InsCfg_Map ();
|
InsCfg_Map ();
|
||||||
|
|
||||||
HTM_DIV_End ();
|
HTM_DIV_End ();
|
||||||
}
|
}
|
||||||
|
@ -245,32 +244,6 @@ static void InsCfg_Title (bool PutLink)
|
||||||
Gbl.Hierarchy.Ins.FullName); // Text full name
|
Gbl.Hierarchy.Ins.FullName); // Text full name
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/********* Get average coordinates of centers in current institution *********/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
static void InsCfg_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom)
|
|
||||||
{
|
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get average coordinates of centers of current institution
|
|
||||||
with both coordinates set
|
|
||||||
(coordinates 0, 0 means not set ==> don't show map) *****/
|
|
||||||
if (asprintf (&Query,
|
|
||||||
"SELECT AVG(Latitude)," // row[0]
|
|
||||||
"AVG(Longitude)," // row[1]
|
|
||||||
"GREATEST(MAX(Latitude)-MIN(Latitude),"
|
|
||||||
"MAX(Longitude)-MIN(Longitude))" // row[2]
|
|
||||||
" FROM ctr_centers"
|
|
||||||
" WHERE InsCod=%ld"
|
|
||||||
" AND Latitude<>0"
|
|
||||||
" AND Longitude<>0",
|
|
||||||
Gbl.Hierarchy.Ins.InsCod) < 0)
|
|
||||||
Err_NotEnoughMemoryExit ();
|
|
||||||
Map_GetCoordAndZoom (Coord,Zoom,Query);
|
|
||||||
free (Query);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/****************************** Draw center map ******************************/
|
/****************************** Draw center map ******************************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -300,21 +273,14 @@ static void InsCfg_Map (void)
|
||||||
HTM_SCRIPT_Begin (NULL,NULL);
|
HTM_SCRIPT_Begin (NULL,NULL);
|
||||||
|
|
||||||
/* Let's create a map with pretty Mapbox Streets tiles */
|
/* Let's create a map with pretty Mapbox Streets tiles */
|
||||||
InsCfg_GetCoordAndZoom (&InsAvgCoord,&Zoom);
|
Ins_DB_GetCoordAndZoom (&InsAvgCoord,&Zoom);
|
||||||
Map_CreateMap (InsCfg_MAP_CONTAINER_ID,&InsAvgCoord,Zoom);
|
Map_CreateMap (InsCfg_MAP_CONTAINER_ID,&InsAvgCoord,Zoom);
|
||||||
|
|
||||||
/* Add Mapbox Streets tile layer to our map */
|
/* Add Mapbox Streets tile layer to our map */
|
||||||
Map_AddTileLayer ();
|
Map_AddTileLayer ();
|
||||||
|
|
||||||
/* Get centers with coordinates */
|
/* Get centers with coordinates */
|
||||||
NumCtrs = (unsigned)
|
NumCtrs = Ins_DB_GetCtrsWithCoordsInCurrentIns (&mysql_res);
|
||||||
DB_QuerySELECT (&mysql_res,"can not get centers with coordinates",
|
|
||||||
"SELECT CtrCod" // row[0]
|
|
||||||
" FROM ctr_centers"
|
|
||||||
" WHERE InsCod=%ld"
|
|
||||||
" AND Latitude<>0"
|
|
||||||
" AND Longitude<>0",
|
|
||||||
Gbl.Hierarchy.Ins.InsCod);
|
|
||||||
|
|
||||||
/* Add a marker and a popup for each center */
|
/* Add a marker and a popup for each center */
|
||||||
for (NumCtr = 0;
|
for (NumCtr = 0;
|
||||||
|
@ -385,16 +351,16 @@ static void InsCfg_Country (bool PrintView,bool PutForm)
|
||||||
{
|
{
|
||||||
Frm_BeginFormGoTo (ActSeeCtyInf);
|
Frm_BeginFormGoTo (ActSeeCtyInf);
|
||||||
Cty_PutParamCtyCod (Gbl.Hierarchy.Cty.CtyCod);
|
Cty_PutParamCtyCod (Gbl.Hierarchy.Cty.CtyCod);
|
||||||
HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Gbl.Hierarchy.Cty.Name[Gbl.Prefs.Language]),
|
HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Gbl.Hierarchy.Cty.Name[Gbl.Prefs.Language]),
|
||||||
"BT_LINK LT DAT",NULL);
|
"BT_LINK LT DAT",NULL);
|
||||||
Hie_FreeGoToMsg ();
|
Hie_FreeGoToMsg ();
|
||||||
}
|
}
|
||||||
Cty_DrawCountryMap (&Gbl.Hierarchy.Cty,"COUNTRY_MAP_TINY");
|
Cty_DrawCountryMap (&Gbl.Hierarchy.Cty,"COUNTRY_MAP_TINY");
|
||||||
HTM_NBSP ();
|
HTM_NBSP ();
|
||||||
HTM_Txt (Gbl.Hierarchy.Cty.Name[Gbl.Prefs.Language]);
|
HTM_Txt (Gbl.Hierarchy.Cty.Name[Gbl.Prefs.Language]);
|
||||||
if (!PrintView)
|
if (!PrintView)
|
||||||
{
|
{
|
||||||
HTM_BUTTON_End ();
|
HTM_BUTTON_End ();
|
||||||
Frm_EndForm ();
|
Frm_EndForm ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -464,13 +430,13 @@ static void InsCfg_NumUsrs (void)
|
||||||
/***** Number of users *****/
|
/***** Number of users *****/
|
||||||
HTM_TR_Begin (NULL);
|
HTM_TR_Begin (NULL);
|
||||||
|
|
||||||
/* Label */
|
/* Label */
|
||||||
Frm_LabelColumn ("RT",NULL,Txt_Users_of_the_institution);
|
Frm_LabelColumn ("RT",NULL,Txt_Users_of_the_institution);
|
||||||
|
|
||||||
/* Data */
|
/* Data */
|
||||||
HTM_TD_Begin ("class=\"DAT LB\"");
|
HTM_TD_Begin ("class=\"DAT LB\"");
|
||||||
HTM_Unsigned (Usr_GetCachedNumUsrsWhoClaimToBelongToIns (&Gbl.Hierarchy.Ins));
|
HTM_Unsigned (Usr_GetCachedNumUsrsWhoClaimToBelongToIns (&Gbl.Hierarchy.Ins));
|
||||||
HTM_TD_End ();
|
HTM_TD_End ();
|
||||||
|
|
||||||
HTM_TR_End ();
|
HTM_TR_End ();
|
||||||
}
|
}
|
||||||
|
@ -486,13 +452,13 @@ static void InsCfg_NumDegs (void)
|
||||||
/***** Number of degrees *****/
|
/***** Number of degrees *****/
|
||||||
HTM_TR_Begin (NULL);
|
HTM_TR_Begin (NULL);
|
||||||
|
|
||||||
/* Label */
|
/* Label */
|
||||||
Frm_LabelColumn ("RT",NULL,Txt_Degrees);
|
Frm_LabelColumn ("RT",NULL,Txt_Degrees);
|
||||||
|
|
||||||
/* Data */
|
/* Data */
|
||||||
HTM_TD_Begin ("class=\"DAT LB\"");
|
HTM_TD_Begin ("class=\"DAT LB\"");
|
||||||
HTM_Unsigned (Deg_GetCachedNumDegsInIns (Gbl.Hierarchy.Ins.InsCod));
|
HTM_Unsigned (Deg_GetCachedNumDegsInIns (Gbl.Hierarchy.Ins.InsCod));
|
||||||
HTM_TD_End ();
|
HTM_TD_End ();
|
||||||
|
|
||||||
HTM_TR_End ();
|
HTM_TR_End ();
|
||||||
}
|
}
|
||||||
|
@ -508,13 +474,13 @@ static void InsCfg_NumCrss (void)
|
||||||
/***** Number of courses *****/
|
/***** Number of courses *****/
|
||||||
HTM_TR_Begin (NULL);
|
HTM_TR_Begin (NULL);
|
||||||
|
|
||||||
/* Label */
|
/* Label */
|
||||||
Frm_LabelColumn ("RT",NULL,Txt_Courses);
|
Frm_LabelColumn ("RT",NULL,Txt_Courses);
|
||||||
|
|
||||||
/* Data */
|
/* Data */
|
||||||
HTM_TD_Begin ("class=\"DAT LB\"");
|
HTM_TD_Begin ("class=\"DAT LB\"");
|
||||||
HTM_Unsigned (Crs_GetCachedNumCrssInIns (Gbl.Hierarchy.Ins.InsCod));
|
HTM_Unsigned (Crs_GetCachedNumCrssInIns (Gbl.Hierarchy.Ins.InsCod));
|
||||||
HTM_TD_End ();
|
HTM_TD_End ();
|
||||||
|
|
||||||
HTM_TR_End ();
|
HTM_TR_End ();
|
||||||
}
|
}
|
||||||
|
@ -530,13 +496,13 @@ static void InsCfg_NumDpts (void)
|
||||||
/***** Number of departments *****/
|
/***** Number of departments *****/
|
||||||
HTM_TR_Begin (NULL);
|
HTM_TR_Begin (NULL);
|
||||||
|
|
||||||
/* Label */
|
/* Label */
|
||||||
Frm_LabelColumn ("RT",NULL,Txt_Departments);
|
Frm_LabelColumn ("RT",NULL,Txt_Departments);
|
||||||
|
|
||||||
/* Data */
|
/* Data */
|
||||||
HTM_TD_Begin ("class=\"DAT LB\"");
|
HTM_TD_Begin ("class=\"DAT LB\"");
|
||||||
HTM_Unsigned (Dpt_DB_GetNumDepartmentsInInstitution (Gbl.Hierarchy.Ins.InsCod));
|
HTM_Unsigned (Dpt_DB_GetNumDepartmentsInInstitution (Gbl.Hierarchy.Ins.InsCod));
|
||||||
HTM_TD_End ();
|
HTM_TD_End ();
|
||||||
|
|
||||||
HTM_TR_End ();
|
HTM_TR_End ();
|
||||||
}
|
}
|
||||||
|
@ -673,4 +639,3 @@ void InsCfg_ContEditAfterChgIns (void)
|
||||||
/***** Show the form again *****/
|
/***** Show the form again *****/
|
||||||
InsCfg_ShowConfiguration ();
|
InsCfg_ShowConfiguration ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,30 +25,15 @@
|
||||||
/********************************* Headers ***********************************/
|
/********************************* Headers ***********************************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
// #include <stdbool.h> // For boolean type
|
#define _GNU_SOURCE // For asprintf
|
||||||
// #include <stddef.h> // For NULL
|
#include <stdio.h> // For asprintf
|
||||||
// #include <stdlib.h> // For free
|
|
||||||
// #include <string.h> // For string functions
|
|
||||||
|
|
||||||
// #include "swad_admin_database.h"
|
|
||||||
#include "swad_database.h"
|
#include "swad_database.h"
|
||||||
// #include "swad_department.h"
|
#include "swad_error.h"
|
||||||
// #include "swad_enrolment_database.h"
|
|
||||||
// #include "swad_error.h"
|
|
||||||
// #include "swad_figure.h"
|
|
||||||
// #include "swad_figure_cache.h"
|
|
||||||
// #include "swad_form.h"
|
|
||||||
// #include "swad_forum.h"
|
|
||||||
#include "swad_global.h"
|
#include "swad_global.h"
|
||||||
#include "swad_hierarchy.h"
|
#include "swad_hierarchy.h"
|
||||||
// #include "swad_hierarchy_level.h"
|
|
||||||
// #include "swad_HTML.h"
|
|
||||||
#include "swad_institution.h"
|
#include "swad_institution.h"
|
||||||
#include "swad_institution_database.h"
|
#include "swad_institution_database.h"
|
||||||
// #include "swad_logo.h"
|
|
||||||
// #include "swad_message.h"
|
|
||||||
// #include "swad_place.h"
|
|
||||||
// #include "swad_survey.h"
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/************** External global variables from others modules ****************/
|
/************** External global variables from others modules ****************/
|
||||||
|
@ -100,7 +85,6 @@ long Ins_DB_CreateInstitution (const struct Ins_Instit *Ins,unsigned Status)
|
||||||
|
|
||||||
void Ins_DB_UpdateInsCty (long InsCod,long CtyCod)
|
void Ins_DB_UpdateInsCty (long InsCod,long CtyCod)
|
||||||
{
|
{
|
||||||
/***** Update country in table of institutions *****/
|
|
||||||
DB_QueryUPDATE ("can not update the country of an institution",
|
DB_QueryUPDATE ("can not update the country of an institution",
|
||||||
"UPDATE ins_instits"
|
"UPDATE ins_instits"
|
||||||
" SET CtyCod=%ld"
|
" SET CtyCod=%ld"
|
||||||
|
@ -109,6 +93,35 @@ void Ins_DB_UpdateInsCty (long InsCod,long CtyCod)
|
||||||
InsCod);
|
InsCod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/****************** Update status in table of institutions *******************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Ins_DB_UpdateInsStatus (long InsCod,Ins_Status_t Status)
|
||||||
|
{
|
||||||
|
DB_QueryUPDATE ("can not update the status of an institution",
|
||||||
|
"UPDATE ins_instits"
|
||||||
|
" SET Status=%u"
|
||||||
|
" WHERE InsCod=%ld",
|
||||||
|
(unsigned) Status,
|
||||||
|
InsCod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/*************************** Update institution name *************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Ins_DB_UpdateInsName (long InsCod,const char *FieldName,const char *NewInsName)
|
||||||
|
{
|
||||||
|
/***** Update institution changing old name by new name */
|
||||||
|
DB_QueryUPDATE ("can not update the name of an institution",
|
||||||
|
"UPDATE ins_instits"
|
||||||
|
" SET %s='%s'"
|
||||||
|
" WHERE InsCod=%ld",
|
||||||
|
FieldName,NewInsName,
|
||||||
|
InsCod);
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/**************** Update database changing old WWW by new WWW ****************/
|
/**************** Update database changing old WWW by new WWW ****************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -124,6 +137,26 @@ void Ins_DB_UpdateInsWWW (long InsCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1])
|
||||||
InsCod);
|
InsCod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/************************* Get data of an institution ************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Ins_DB_GetDataOfInstitutionByCod (MYSQL_RES **mysql_res,long InsCod)
|
||||||
|
{
|
||||||
|
return (unsigned)
|
||||||
|
DB_QuerySELECT (mysql_res,"can not get data of an institution",
|
||||||
|
"SELECT InsCod," // row[0]
|
||||||
|
"CtyCod," // row[1]
|
||||||
|
"Status," // row[2]
|
||||||
|
"RequesterUsrCod," // row[3]
|
||||||
|
"ShortName," // row[4]
|
||||||
|
"FullName," // row[5]
|
||||||
|
"WWW" // row[6]
|
||||||
|
" FROM ins_instits"
|
||||||
|
" WHERE InsCod=%ld",
|
||||||
|
InsCod);
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/*********** Get the short name of an institution from its code **************/
|
/*********** Get the short name of an institution from its code **************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -146,6 +179,27 @@ void Ins_DB_GetShortNameOfInstitution (long InsCod,char ShrtName[Cns_HIERARCHY_M
|
||||||
InsCod);
|
InsCod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/******** Get short name and country of an institution from its code *********/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Ins_DB_GetShrtNameAndCtyOfIns (MYSQL_RES **mysql_res,long InsCod)
|
||||||
|
{
|
||||||
|
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
|
||||||
|
|
||||||
|
return (unsigned)
|
||||||
|
DB_QuerySELECT (mysql_res,"can not get short name and country"
|
||||||
|
" of an institution",
|
||||||
|
"SELECT ins_instits.ShortName," // row[0]
|
||||||
|
"cty_countrs.Name_%s" // row[1]
|
||||||
|
" FROM ins_instits,"
|
||||||
|
"cty_countrs"
|
||||||
|
" WHERE ins_instits.InsCod=%ld"
|
||||||
|
" AND ins_instits.CtyCod=cty_countrs.CtyCod",
|
||||||
|
Lan_STR_LANG_ID[Gbl.Prefs.Language],
|
||||||
|
InsCod);
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/****** Check if the name of institution exists in the current country *******/
|
/****** Check if the name of institution exists in the current country *******/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -155,7 +209,6 @@ bool Ins_DB_CheckIfInsNameExistsInCty (const char *FieldName,
|
||||||
long InsCod,
|
long InsCod,
|
||||||
long CtyCod)
|
long CtyCod)
|
||||||
{
|
{
|
||||||
/***** Get number of institutions in current country with a name from database *****/
|
|
||||||
return (DB_QueryCOUNT ("can not check if the name of an institution"
|
return (DB_QueryCOUNT ("can not check if the name of an institution"
|
||||||
" already existed",
|
" already existed",
|
||||||
"SELECT COUNT(*)"
|
"SELECT COUNT(*)"
|
||||||
|
@ -166,6 +219,147 @@ bool Ins_DB_CheckIfInsNameExistsInCty (const char *FieldName,
|
||||||
CtyCod,FieldName,Name,InsCod) != 0);
|
CtyCod,FieldName,Name,InsCod) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/***************** Get all institutions with pending centers *****************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Ins_DB_GetAllInsWithPendingCtr (MYSQL_RES **mysql_res)
|
||||||
|
{
|
||||||
|
return (unsigned)
|
||||||
|
DB_QuerySELECT (mysql_res,"can not get institutions with pending centers",
|
||||||
|
"SELECT ctr_centers.InsCod," // row[0]
|
||||||
|
"COUNT(*)" // row[1]
|
||||||
|
" FROM ctr_centers,"
|
||||||
|
"ins_instits"
|
||||||
|
" WHERE (ctr_centers.Status & %u)<>0"
|
||||||
|
" AND ctr_centers.InsCod=ins_instits.InsCod"
|
||||||
|
" GROUP BY ctr_centers.InsCod"
|
||||||
|
" ORDER BY ins_instits.ShortName",
|
||||||
|
(unsigned) Ctr_STATUS_BIT_PENDING);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/************* Get institutions with pending centers admin by me *************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Ins_DB_GetInsWithPendingCtrsAdminByMe (MYSQL_RES **mysql_res)
|
||||||
|
{
|
||||||
|
return (unsigned)
|
||||||
|
DB_QuerySELECT (mysql_res,"can not get institutions with pending centers",
|
||||||
|
"SELECT ctr_centers.InsCod," // row[0]
|
||||||
|
"COUNT(*)" // row[1]
|
||||||
|
" FROM ctr_centers,"
|
||||||
|
"ins_admin,"
|
||||||
|
"ins_instits"
|
||||||
|
" WHERE (ctr_centers.Status & %u)<>0"
|
||||||
|
" AND ctr_centers.InsCod=ins_admin.InsCod"
|
||||||
|
" AND ins_admin.UsrCod=%ld"
|
||||||
|
" AND ctr_centers.InsCod=ins_instits.InsCod"
|
||||||
|
" GROUP BY ctr_centers.InsCod"
|
||||||
|
" ORDER BY ins_instits.ShortName",
|
||||||
|
(unsigned) Ctr_STATUS_BIT_PENDING,
|
||||||
|
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/************* Get institutions in country ordered by short name *************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Ins_DB_GetInssInCtyOrderedByShrtName (MYSQL_RES **mysql_res,long CtyCod)
|
||||||
|
{
|
||||||
|
return (unsigned)
|
||||||
|
DB_QuerySELECT (mysql_res,"can not get institutions",
|
||||||
|
"SELECT DISTINCT InsCod," // row[0]
|
||||||
|
"ShortName" // row[1]
|
||||||
|
" FROM ins_instits"
|
||||||
|
" WHERE CtyCod=%ld"
|
||||||
|
" ORDER BY ShortName",
|
||||||
|
CtyCod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/******* Get basic list of institutions ordered by name of institution *******/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Ins_DB_GetInssInCtyOrderedByFullName (MYSQL_RES **mysql_res,long CtyCod)
|
||||||
|
{
|
||||||
|
return (unsigned)
|
||||||
|
DB_QuerySELECT (mysql_res,"can not get institutions",
|
||||||
|
"SELECT InsCod," // row[0]
|
||||||
|
"CtyCod," // row[1]
|
||||||
|
"Status," // row[2]
|
||||||
|
"RequesterUsrCod," // row[3]
|
||||||
|
"ShortName," // row[4]
|
||||||
|
"FullName," // row[5]
|
||||||
|
"WWW" // row[6]
|
||||||
|
" FROM ins_instits"
|
||||||
|
" WHERE CtyCod=%ld"
|
||||||
|
" ORDER BY FullName",
|
||||||
|
CtyCod);
|
||||||
|
}
|
||||||
|
/*****************************************************************************/
|
||||||
|
/************* Get full list of institutions **************/
|
||||||
|
/************* with number of users who claim to belong to them **************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Ins_DB_GetFullListOfInssInCty (MYSQL_RES **mysql_res,long CtyCod)
|
||||||
|
{
|
||||||
|
static const char *OrderBySubQuery[Ins_NUM_ORDERS] =
|
||||||
|
{
|
||||||
|
[Ins_ORDER_BY_INSTITUTION] = "FullName",
|
||||||
|
[Ins_ORDER_BY_NUM_USRS ] = "NumUsrs DESC,FullName",
|
||||||
|
};
|
||||||
|
|
||||||
|
/***** Get institutions from database *****/
|
||||||
|
return (unsigned)
|
||||||
|
DB_QuerySELECT (mysql_res,"can not get institutions",
|
||||||
|
"(SELECT ins_instits.InsCod," // row[0]
|
||||||
|
"ins_instits.CtyCod," // row[1]
|
||||||
|
"ins_instits.Status," // row[2]
|
||||||
|
"ins_instits.RequesterUsrCod," // row[3]
|
||||||
|
"ins_instits.ShortName," // row[4]
|
||||||
|
"ins_instits.FullName," // row[5]
|
||||||
|
"ins_instits.WWW," // row[6]
|
||||||
|
"COUNT(*) AS NumUsrs" // row[7]
|
||||||
|
" FROM ins_instits,"
|
||||||
|
"usr_data"
|
||||||
|
" WHERE ins_instits.CtyCod=%ld"
|
||||||
|
" AND ins_instits.InsCod=usr_data.InsCod"
|
||||||
|
" GROUP BY ins_instits.InsCod)"
|
||||||
|
" UNION "
|
||||||
|
"(SELECT InsCod," // row[0]
|
||||||
|
"CtyCod," // row[1]
|
||||||
|
"Status," // row[2]
|
||||||
|
"RequesterUsrCod," // row[3]
|
||||||
|
"ShortName," // row[4]
|
||||||
|
"FullName," // row[5]
|
||||||
|
"WWW," // row[6]
|
||||||
|
"0 AS NumUsrs" // row[7]
|
||||||
|
" FROM ins_instits"
|
||||||
|
" WHERE CtyCod=%ld"
|
||||||
|
" AND InsCod NOT IN"
|
||||||
|
" (SELECT DISTINCT InsCod"
|
||||||
|
" FROM usr_data))"
|
||||||
|
" ORDER BY %s",
|
||||||
|
CtyCod,
|
||||||
|
CtyCod,
|
||||||
|
OrderBySubQuery[Gbl.Hierarchy.Inss.SelectedOrder]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/**************** Get number of institutions in a country ********************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Ins_DB_GetNumInssInCty (long CtyCod)
|
||||||
|
{
|
||||||
|
return (unsigned)
|
||||||
|
DB_QueryCOUNT ("can not get the number of institutions in a country",
|
||||||
|
"SELECT COUNT(*)"
|
||||||
|
" FROM ins_instits"
|
||||||
|
" WHERE CtyCod=%ld",
|
||||||
|
CtyCod);
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/****************** Get number of institutions with centres ******************/
|
/****************** Get number of institutions with centres ******************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -256,3 +450,90 @@ unsigned Ins_DB_GetNumInnsWithUsrs (Rol_Role_t Role,
|
||||||
" AND crs_users.Role=%u",
|
" AND crs_users.Role=%u",
|
||||||
SubQuery,(unsigned) Role);
|
SubQuery,(unsigned) Role);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/********** Check if any of the centers in an institution has map ************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
bool Ins_DB_GetIfMapIsAvailable (long InsCod)
|
||||||
|
{
|
||||||
|
MYSQL_RES *mysql_res;
|
||||||
|
MYSQL_ROW row;
|
||||||
|
bool MapIsAvailable = false;
|
||||||
|
|
||||||
|
/***** Get if any center in current institution has a coordinate set
|
||||||
|
(coordinates 0, 0 means not set ==> don't show map) *****/
|
||||||
|
if (DB_QuerySELECT (&mysql_res,"can not get if map is available",
|
||||||
|
"SELECT EXISTS" // row[0]
|
||||||
|
"(SELECT *"
|
||||||
|
" FROM ctr_centers"
|
||||||
|
" WHERE InsCod=%ld"
|
||||||
|
" AND (Latitude<>0"
|
||||||
|
" OR"
|
||||||
|
" Longitude<>0))",
|
||||||
|
InsCod))
|
||||||
|
{
|
||||||
|
/* Get if map is available */
|
||||||
|
row = mysql_fetch_row (mysql_res);
|
||||||
|
MapIsAvailable = (row[0][0] == '1');
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Free structure that stores the query result */
|
||||||
|
DB_FreeMySQLResult (&mysql_res);
|
||||||
|
|
||||||
|
return MapIsAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/********* Get average coordinates of centers in current institution *********/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Ins_DB_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom)
|
||||||
|
{
|
||||||
|
char *Query;
|
||||||
|
|
||||||
|
/***** Get average coordinates of centers of current institution
|
||||||
|
with both coordinates set
|
||||||
|
(coordinates 0, 0 means not set ==> don't show map) *****/
|
||||||
|
if (asprintf (&Query,
|
||||||
|
"SELECT AVG(Latitude)," // row[0]
|
||||||
|
"AVG(Longitude)," // row[1]
|
||||||
|
"GREATEST(MAX(Latitude)-MIN(Latitude),"
|
||||||
|
"MAX(Longitude)-MIN(Longitude))" // row[2]
|
||||||
|
" FROM ctr_centers"
|
||||||
|
" WHERE InsCod=%ld"
|
||||||
|
" AND Latitude<>0"
|
||||||
|
" AND Longitude<>0",
|
||||||
|
Gbl.Hierarchy.Ins.InsCod) < 0)
|
||||||
|
Err_NotEnoughMemoryExit ();
|
||||||
|
Map_GetCoordAndZoom (Coord,Zoom,Query);
|
||||||
|
free (Query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/******** Get centres which have coordinates in current institution **********/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Ins_DB_GetCtrsWithCoordsInCurrentIns (MYSQL_RES **mysql_res)
|
||||||
|
{
|
||||||
|
return (unsigned)
|
||||||
|
DB_QuerySELECT (mysql_res,"can not get centers with coordinates",
|
||||||
|
"SELECT CtrCod" // row[0]
|
||||||
|
" FROM ctr_centers"
|
||||||
|
" WHERE InsCod=%ld"
|
||||||
|
" AND Latitude<>0"
|
||||||
|
" AND Longitude<>0",
|
||||||
|
Gbl.Hierarchy.Ins.InsCod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/***************************** Remove institution ****************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Ins_DB_RemoveInstitution (long InsCod)
|
||||||
|
{
|
||||||
|
DB_QueryDELETE ("can not remove an institution",
|
||||||
|
"DELETE FROM ins_instits"
|
||||||
|
" WHERE InsCod=%ld",
|
||||||
|
InsCod);
|
||||||
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
#include "swad_constant.h"
|
#include "swad_constant.h"
|
||||||
#include "swad_hierarchy_level.h"
|
#include "swad_hierarchy_level.h"
|
||||||
|
#include "swad_map.h"
|
||||||
#include "swad_role_type.h"
|
#include "swad_role_type.h"
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -41,18 +42,37 @@
|
||||||
|
|
||||||
long Ins_DB_CreateInstitution (const struct Ins_Instit *Ins,unsigned Status);
|
long Ins_DB_CreateInstitution (const struct Ins_Instit *Ins,unsigned Status);
|
||||||
void Ins_DB_UpdateInsCty (long InsCod,long CtyCod);
|
void Ins_DB_UpdateInsCty (long InsCod,long CtyCod);
|
||||||
|
void Ins_DB_UpdateInsStatus (long InsCod,Ins_Status_t Status);
|
||||||
|
void Ins_DB_UpdateInsName (long InsCod,const char *FieldName,const char *NewInsName);
|
||||||
void Ins_DB_UpdateInsWWW (long InsCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1]);
|
void Ins_DB_UpdateInsWWW (long InsCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1]);
|
||||||
|
|
||||||
|
unsigned Ins_DB_GetDataOfInstitutionByCod (MYSQL_RES **mysql_res,long InsCod);
|
||||||
void Ins_DB_GetShortNameOfInstitution (long InsCod,char ShrtName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1]);
|
void Ins_DB_GetShortNameOfInstitution (long InsCod,char ShrtName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1]);
|
||||||
|
unsigned Ins_DB_GetShrtNameAndCtyOfIns (MYSQL_RES **mysql_res,long InsCod);
|
||||||
bool Ins_DB_CheckIfInsNameExistsInCty (const char *FieldName,
|
bool Ins_DB_CheckIfInsNameExistsInCty (const char *FieldName,
|
||||||
const char *Name,
|
const char *Name,
|
||||||
long InsCod,
|
long InsCod,
|
||||||
long CtyCod);
|
long CtyCod);
|
||||||
|
|
||||||
|
unsigned Ins_DB_GetAllInsWithPendingCtr (MYSQL_RES **mysql_res);
|
||||||
|
unsigned Ins_DB_GetInsWithPendingCtrsAdminByMe (MYSQL_RES **mysql_res);
|
||||||
|
|
||||||
|
unsigned Ins_DB_GetInssInCtyOrderedByShrtName (MYSQL_RES **mysql_res,long CtyCod);
|
||||||
|
unsigned Ins_DB_GetInssInCtyOrderedByFullName (MYSQL_RES **mysql_res,long CtyCod);
|
||||||
|
unsigned Ins_DB_GetFullListOfInssInCty (MYSQL_RES **mysql_res,long CtyCod);
|
||||||
|
|
||||||
|
unsigned Ins_DB_GetNumInssInCty (long CtyCod);
|
||||||
|
|
||||||
unsigned Ins_DB_GetNumInssWithCtrs (HieLvl_Level_t Scope,long Cod);
|
unsigned Ins_DB_GetNumInssWithCtrs (HieLvl_Level_t Scope,long Cod);
|
||||||
unsigned Ins_DB_GetNumInssWithDegs (HieLvl_Level_t Scope,long Cod);
|
unsigned Ins_DB_GetNumInssWithDegs (HieLvl_Level_t Scope,long Cod);
|
||||||
unsigned Ins_DB_GetNumInssWithCrss (HieLvl_Level_t Scope,long Cod);
|
unsigned Ins_DB_GetNumInssWithCrss (HieLvl_Level_t Scope,long Cod);
|
||||||
unsigned Ins_DB_GetNumInnsWithUsrs (Rol_Role_t Role,
|
unsigned Ins_DB_GetNumInnsWithUsrs (Rol_Role_t Role,
|
||||||
HieLvl_Level_t Scope,long Cod);
|
HieLvl_Level_t Scope,long Cod);
|
||||||
|
|
||||||
|
bool Ins_DB_GetIfMapIsAvailable (long InsCod);
|
||||||
|
void Ins_DB_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom);
|
||||||
|
unsigned Ins_DB_GetCtrsWithCoordsInCurrentIns (MYSQL_RES **mysql_res);
|
||||||
|
|
||||||
|
void Ins_DB_RemoveInstitution (long InsCod);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue