swad-core/swad_institution.c

2327 lines
82 KiB
C
Raw Normal View History

2014-12-01 23:55:08 +01:00
// swad_institution.c: institutions
/*
SWAD (Shared Workspace At a Distance),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
2016-01-01 20:19:43 +01:00
Copyright (C) 1999-2016 Antonio Ca<EFBFBD>as Vargas
2014-12-01 23:55:08 +01:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
#include <linux/stddef.h> // For NULL
#include <stdlib.h> // For calloc
#include <string.h> // For string functions
#include "swad_config.h"
#include "swad_constant.h"
#include "swad_database.h"
#include "swad_global.h"
2015-10-06 20:34:49 +02:00
#include "swad_help.h"
2014-12-01 23:55:08 +01:00
#include "swad_institution.h"
2015-01-17 13:31:25 +01:00
#include "swad_logo.h"
2014-12-01 23:55:08 +01:00
#include "swad_parameter.h"
#include "swad_QR.h"
#include "swad_text.h"
#include "swad_user.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
static void Ins_Configuration (bool PrintView);
2016-05-05 18:40:42 +02:00
static void Ins_PutIconsToPrintAndUpload (void);
2014-12-01 23:55:08 +01:00
2015-10-06 01:19:21 +02:00
static void Ins_ListInstitutions (void);
2016-03-16 22:40:35 +01:00
static void Ins_PutIconToEditInstitutions (void);
2016-03-16 13:23:10 +01:00
static void Ins_ListOneInstitutionForSeeing (struct Institution *Ins,unsigned NumIns);
2014-12-01 23:55:08 +01:00
static void Ins_PutHeadInstitutionsForSeeing (bool OrderSelectable);
static void Ins_GetParamInsOrderType (void);
static void Ins_ListInstitutionsForEdition (void);
static bool Ins_CheckIfICanEdit (struct Institution *Ins);
static Ins_StatusTxt_t Ins_GetStatusTxtFromStatusBits (Ins_Status_t Status);
static Ins_Status_t Ins_GetStatusBitsFromStatusTxt (Ins_StatusTxt_t StatusTxt);
static void Ins_PutParamOtherInsCod (long InsCod);
2016-03-01 23:58:48 +01:00
static bool Ins_RenameInstitution (struct Institution *Ins,Cns_ShortOrFullName_t ShortOrFullName);
2014-12-01 23:55:08 +01:00
static bool Ins_CheckIfInsNameExistsInCty (const char *FieldName,const char *Name,long InsCod,long CtyCod);
2016-10-20 19:46:06 +02:00
static void Ins_UpdateInsCtyDB (long InsCod,long CtyCod);
2016-03-01 23:58:48 +01:00
static void Ins_PutButtonToGoToIns (struct Institution *Ins);
2014-12-01 23:55:08 +01:00
static void Ins_PutFormToCreateInstitution (void);
static void Ins_PutHeadInstitutionsForEdition (void);
static void Ins_RecFormRequestOrCreateIns (unsigned Status);
static void Ins_CreateInstitution (struct Institution *Ins,unsigned Status);
/*****************************************************************************/
/***************** List institutions with pending centres ********************/
/*****************************************************************************/
void Ins_SeeInsWithPendingCtrs (void)
{
extern const char *Txt_Institutions_with_pending_centres;
extern const char *Txt_Institution;
extern const char *Txt_Centres_ABBREVIATION;
extern const char *Txt_There_are_no_institutions_with_requests_for_centres_to_be_confirmed;
char Query[1024];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumInss;
unsigned NumIns;
struct Institution Ins;
2015-09-04 19:26:08 +02:00
const char *BgColor;
2014-12-01 23:55:08 +01:00
/***** Get institutions with pending centres *****/
switch (Gbl.Usrs.Me.LoggedRole)
{
2015-04-07 21:44:24 +02:00
case Rol_INS_ADM:
2014-12-01 23:55:08 +01:00
sprintf (Query,"SELECT centres.InsCod,COUNT(*)"
" FROM centres,ins_admin,institutions"
" WHERE (centres.Status & %u)<>0"
" AND centres.InsCod=ins_admin.InsCod AND ins_admin.UsrCod='%ld'"
" AND centres.InsCod=institutions.InsCod"
" GROUP BY centres.InsCod ORDER BY institutions.ShortName",
(unsigned) Ctr_STATUS_BIT_PENDING,Gbl.Usrs.Me.UsrDat.UsrCod);
break;
2015-04-07 21:44:24 +02:00
case Rol_SYS_ADM:
2014-12-01 23:55:08 +01:00
sprintf (Query,"SELECT centres.InsCod,COUNT(*)"
" FROM centres,institutions"
" WHERE (centres.Status & %u)<>0"
" AND centres.InsCod=institutions.InsCod"
" GROUP BY centres.InsCod ORDER BY institutions.ShortName",
(unsigned) Ctr_STATUS_BIT_PENDING);
break;
default: // Forbidden for other users
return;
}
/***** Get institutions *****/
if ((NumInss = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get institutions with pending centres")))
{
/***** Write heading *****/
2015-04-12 18:01:06 +02:00
Lay_StartRoundFrameTable (NULL,2,Txt_Institutions_with_pending_centres);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<tr>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2014-12-01 23:55:08 +01:00
"</tr>",
Txt_Institution,
Txt_Centres_ABBREVIATION);
/***** List the institutions *****/
for (NumIns = 0;
NumIns < NumInss;
NumIns++)
{
/* Get next centre */
row = mysql_fetch_row (mysql_res);
/* Get institution code (row[0]) */
Ins.InsCod = Str_ConvertStrCodToLongCod (row[0]);
2015-09-04 19:26:08 +02:00
BgColor = (Ins.InsCod == Gbl.CurrentIns.Ins.InsCod) ? "LIGHT_BLUE" :
Gbl.ColorRows[Gbl.RowEvenOdd];
2014-12-01 23:55:08 +01:00
/* Get data of institution */
2015-12-09 19:51:17 +01:00
Ins_GetDataOfInstitutionByCod (&Ins,Ins_GET_BASIC_DATA);
2014-12-01 23:55:08 +01:00
2015-11-19 16:33:50 +01:00
/* Institution logo and name */
2015-11-12 00:53:30 +01:00
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"LEFT_MIDDLE %s\">",
2014-12-01 23:55:08 +01:00
BgColor);
2015-11-19 18:33:16 +01:00
Ins_DrawInstitutionLogoAndNameWithLink (&Ins,ActSeeCtr,
"DAT_NOBR","CENTER_MIDDLE");
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
/* Number of pending centres (row[1]) */
2015-09-04 17:10:27 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE %s\">"
2014-12-23 14:41:10 +01:00
"%s"
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>",
BgColor,row[1]);
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
}
2015-04-12 18:01:06 +02:00
Lay_EndRoundFrameTable ();
2014-12-01 23:55:08 +01:00
}
else
Lay_ShowAlert (Lay_INFO,Txt_There_are_no_institutions_with_requests_for_centres_to_be_confirmed);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2016-07-27 14:58:26 +02:00
/*****************************************************************************/
/********************** Draw institution logo with link **********************/
/*****************************************************************************/
2016-07-30 00:21:35 +02:00
void Ins_DrawInstitutionLogoWithLink (struct Institution *Ins,unsigned Size)
2016-07-27 14:58:26 +02:00
{
2016-07-30 00:21:35 +02:00
bool PutLink = !Gbl.Form.Inside; // Don't put link to institution if already inside a form
2016-07-27 14:58:26 +02:00
if (PutLink)
{
Act_FormStart (ActSeeInsInf);
Ins_PutParamInsCod (Ins->InsCod);
Act_LinkFormSubmit (Ins->FullName,NULL,NULL);
}
Log_DrawLogo (Sco_SCOPE_INS,Ins->InsCod,Ins->FullName,
Size,NULL,true);
if (PutLink)
{
fprintf (Gbl.F.Out,"</a>");
Act_FormEnd ();
}
}
2015-11-19 18:33:16 +01:00
/*****************************************************************************/
/****************** Draw institution logo and name with link *****************/
/*****************************************************************************/
void Ins_DrawInstitutionLogoAndNameWithLink (struct Institution *Ins,Act_Action_t Action,
const char *ClassLink,const char *ClassLogo)
{
extern const char *Txt_Go_to_X;
/***** Start form *****/
Act_FormGoToStart (Action);
Ins_PutParamInsCod (Ins->InsCod);
/***** Link to action *****/
sprintf (Gbl.Title,Txt_Go_to_X,Ins->FullName);
2016-07-01 17:13:41 +02:00
Act_LinkFormSubmit (Gbl.Title,ClassLink,NULL);
2015-11-19 18:33:16 +01:00
/***** Draw institution logo *****/
2015-12-13 13:53:00 +01:00
Log_DrawLogo (Sco_SCOPE_INS,Ins->InsCod,Ins->ShortName,20,ClassLogo,true);
2015-11-19 18:33:16 +01:00
/***** End link *****/
fprintf (Gbl.F.Out,"&nbsp;%s</a>",Ins->FullName);
/***** End form *****/
Act_FormEnd ();
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/*************** Show information of the current institution *****************/
/*****************************************************************************/
void Ins_ShowConfiguration (void)
{
Ins_Configuration (false);
2015-10-06 01:19:21 +02:00
/***** Show help to enroll me *****/
2015-10-06 20:34:49 +02:00
Hlp_ShowHelpWhatWouldYouLikeToDo ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************** Print information of the current institution ****************/
/*****************************************************************************/
void Ins_PrintConfiguration (void)
{
Ins_Configuration (true);
}
/*****************************************************************************/
/***************** Information of the current institution ********************/
/*****************************************************************************/
static void Ins_Configuration (bool PrintView)
{
2015-07-28 00:16:09 +02:00
extern const char *The_ClassForm[The_NUM_THEMES];
2016-10-20 19:46:06 +02:00
extern const char *Txt_Country;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Institution;
2015-02-04 20:03:23 +01:00
extern const char *Txt_Short_name;
2015-02-04 20:11:41 +01:00
extern const char *Txt_Web;
2015-03-07 18:09:42 +01:00
extern const char *Txt_Shortcut;
2015-12-07 23:13:08 +01:00
extern const char *Txt_STR_LANG_ID[1+Txt_NUM_LANGUAGES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_QR_code;
2016-05-30 19:44:21 +02:00
extern const char *Txt_Centres;
extern const char *Txt_Centres_of_INSTITUTION_X;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Degrees;
extern const char *Txt_Courses;
extern const char *Txt_Departments;
2015-12-09 19:51:17 +01:00
extern const char *Txt_Users_of_the_institution;
2014-12-01 23:55:08 +01:00
extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2016-10-20 19:46:06 +02:00
unsigned NumCty;
2014-12-01 23:55:08 +01:00
bool PutLink = !PrintView && Gbl.CurrentIns.Ins.WWW[0];
if (Gbl.CurrentIns.Ins.InsCod > 0)
{
2014-12-08 17:35:48 +01:00
/***** Start frame *****/
2016-03-18 20:07:40 +01:00
Lay_StartRoundFrame (NULL,NULL,PrintView ? NULL :
2016-05-05 18:40:42 +02:00
Ins_PutIconsToPrintAndUpload);
2014-12-08 17:35:48 +01:00
2014-12-01 23:55:08 +01:00
/***** Title *****/
2016-03-18 20:07:40 +01:00
fprintf (Gbl.F.Out,"<div class=\"TITLE_LOCATION\">");
2014-12-01 23:55:08 +01:00
if (PutLink)
fprintf (Gbl.F.Out,"<a href=\"%s\" target=\"_blank\""
" class=\"TITLE_LOCATION\" title=\"%s\">",
Gbl.CurrentIns.Ins.WWW,
Gbl.CurrentIns.Ins.FullName);
2015-02-01 20:17:24 +01:00
Log_DrawLogo (Sco_SCOPE_INS,Gbl.CurrentIns.Ins.InsCod,
2015-01-18 11:46:39 +01:00
Gbl.CurrentIns.Ins.ShortName,64,NULL,true);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<br />%s",Gbl.CurrentIns.Ins.FullName);
if (PutLink)
fprintf (Gbl.F.Out,"</a>");
2016-03-18 20:07:40 +01:00
fprintf (Gbl.F.Out,"</div>");
/***** Start table *****/
fprintf (Gbl.F.Out,"<table class=\"FRAME_TABLE CELLS_PAD_2\">");
2014-12-01 23:55:08 +01:00
2016-10-20 19:46:06 +02:00
/***** Country *****/
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"%s RIGHT_MIDDLE\">"
"%s:"
"</td>"
"<td class=\"DAT LEFT_MIDDLE\">",
The_ClassForm[Gbl.Prefs.Theme],
Txt_Country);
if (!PrintView &&
Gbl.Usrs.Me.LoggedRole == Rol_SYS_ADM) // Only system admins can move an institution to another country
{
/* Get list of countries */
Cty_GetListCountries (Cty_GET_BASIC_DATA);
/* Put form to select country */
Act_FormStart (ActChgInsCtyCfg);
fprintf (Gbl.F.Out,"<select name=\"OthCtyCod\""
" class=\"INPUT_SHORT_NAME\""
" onchange=\"document.getElementById('%s').submit();\">",
Gbl.Form.Id);
for (NumCty = 0;
NumCty < Gbl.Ctys.Num;
NumCty++)
fprintf (Gbl.F.Out,"<option value=\"%ld\"%s>%s</option>",
Gbl.Ctys.Lst[NumCty].CtyCod,
Gbl.Ctys.Lst[NumCty].CtyCod == Gbl.CurrentCty.Cty.CtyCod ? " selected=\"selected\"" :
"",
Gbl.Ctys.Lst[NumCty].Name[Gbl.Prefs.Language]);
fprintf (Gbl.F.Out,"</select>");
Act_FormEnd ();
/* Free list of countries */
Cty_FreeListCountries ();
}
else // I can not move institution to another country
fprintf (Gbl.F.Out,"%s",Gbl.CurrentCty.Cty.Name[Gbl.Prefs.Language]);
fprintf (Gbl.F.Out,"</td>"
"</tr>");
2014-12-01 23:55:08 +01:00
/***** Institution full name *****/
fprintf (Gbl.F.Out,"<tr>"
2015-07-28 00:16:09 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2014-12-23 14:41:10 +01:00
"%s:"
"</td>"
2015-08-03 22:24:32 +02:00
"<td class=\"DAT_N LEFT_MIDDLE\">",
2015-07-28 00:16:09 +02:00
The_ClassForm[Gbl.Prefs.Theme],
2014-12-01 23:55:08 +01:00
Txt_Institution);
if (PutLink)
fprintf (Gbl.F.Out,"<a href=\"%s\" target=\"_blank\""
" class=\"DAT_N\" title=\"%s\">",
Gbl.CurrentIns.Ins.WWW,
Gbl.CurrentIns.Ins.FullName);
fprintf (Gbl.F.Out,"%s",
Gbl.CurrentIns.Ins.FullName);
if (PutLink)
fprintf (Gbl.F.Out,"</a>");
fprintf (Gbl.F.Out,"</td>"
"</tr>");
/***** Institution short name *****/
fprintf (Gbl.F.Out,"<tr>"
2015-07-28 00:16:09 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2014-12-23 14:41:10 +01:00
"%s:"
"</td>"
2015-08-03 22:24:32 +02:00
"<td class=\"DAT LEFT_MIDDLE\">"
2014-12-23 14:41:10 +01:00
"%s"
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>",
2015-07-28 00:16:09 +02:00
The_ClassForm[Gbl.Prefs.Theme],
2015-02-04 20:03:23 +01:00
Txt_Short_name,
2014-12-01 23:55:08 +01:00
Gbl.CurrentIns.Ins.ShortName);
2015-02-04 20:11:41 +01:00
/***** Institution WWW *****/
if (Gbl.CurrentIns.Ins.WWW[0])
{
fprintf (Gbl.F.Out,"<tr>"
2015-07-28 00:16:09 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2015-02-04 20:11:41 +01:00
"%s:"
"</td>"
2015-08-03 22:24:32 +02:00
"<td class=\"DAT LEFT_MIDDLE\">"
2015-02-04 20:11:41 +01:00
"<a href=\"%s\" target=\"_blank\" class=\"DAT\">",
2015-07-28 00:16:09 +02:00
The_ClassForm[Gbl.Prefs.Theme],
2015-02-04 20:11:41 +01:00
Txt_Web,
Gbl.CurrentIns.Ins.WWW);
Str_LimitLengthHTMLStr (Gbl.CurrentIns.Ins.WWW,20);
fprintf (Gbl.F.Out,"%s"
"</a>"
"</td>"
"</tr>",
Gbl.CurrentIns.Ins.WWW);
}
/***** Shortcut to the institution *****/
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<tr>"
2015-07-28 00:16:09 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2014-12-23 14:41:10 +01:00
"%s:"
"</td>"
2015-08-03 22:24:32 +02:00
"<td class=\"LEFT_MIDDLE\">"
2015-03-07 21:08:44 +01:00
"<a href=\"%s/%s?ins=%ld\" class=\"DAT\" target=\"_blank\">"
"%s/%s?ins=%ld"
2014-12-23 14:41:10 +01:00
"</a>"
2014-12-01 23:55:08 +01:00
"</td>"
"</tr>",
2015-07-28 00:16:09 +02:00
The_ClassForm[Gbl.Prefs.Theme],
2015-03-07 18:09:42 +01:00
Txt_Shortcut,
2016-07-08 12:43:48 +02:00
Cfg_URL_SWAD_CGI,
2015-12-07 23:13:08 +01:00
Txt_STR_LANG_ID[Gbl.Prefs.Language],
Gbl.CurrentIns.Ins.InsCod,
2016-07-08 12:43:48 +02:00
Cfg_URL_SWAD_CGI,
2015-12-07 23:13:08 +01:00
Txt_STR_LANG_ID[Gbl.Prefs.Language],
Gbl.CurrentIns.Ins.InsCod);
2014-12-01 23:55:08 +01:00
if (PrintView)
{
/***** QR code with link to the institution *****/
fprintf (Gbl.F.Out,"<tr>"
2015-07-28 00:16:09 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2014-12-23 14:41:10 +01:00
"%s:"
"</td>"
2015-09-09 23:44:58 +02:00
"<td class=\"LEFT_MIDDLE\">",
2015-07-28 00:16:09 +02:00
The_ClassForm[Gbl.Prefs.Theme],
2014-12-01 23:55:08 +01:00
Txt_QR_code);
2015-09-28 18:28:29 +02:00
QR_LinkTo (250,"ins",Gbl.CurrentIns.Ins.InsCod);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
}
else
{
2015-12-09 19:51:17 +01:00
/***** Number of users who claim to belong to this institution *****/
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"%s RIGHT_MIDDLE\">"
"%s:"
"</td>"
"<td class=\"DAT LEFT_MIDDLE\">"
"%u"
"</td>"
"</tr>",
The_ClassForm[Gbl.Prefs.Theme],
Txt_Users_of_the_institution,
Usr_GetNumUsrsWhoClaimToBelongToIns (Gbl.CurrentIns.Ins.InsCod));
2014-12-01 23:55:08 +01:00
/***** Number of centres *****/
fprintf (Gbl.F.Out,"<tr>"
2015-07-28 00:16:09 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2016-05-30 19:44:21 +02:00
"%s:"
"</td>"
"<td class=\"LEFT_MIDDLE\">",
2015-07-28 00:16:09 +02:00
The_ClassForm[Gbl.Prefs.Theme],
2016-05-30 19:44:21 +02:00
Txt_Centres);
/* Form to go to see centres of this institution */
Act_FormGoToStart (ActSeeCtr);
2016-05-30 19:52:46 +02:00
Ins_PutParamInsCod (Gbl.CurrentIns.Ins.InsCod);
sprintf (Gbl.Title,Txt_Centres_of_INSTITUTION_X,
Gbl.CurrentIns.Ins.ShortName);
2016-07-01 17:13:41 +02:00
Act_LinkFormSubmit (Gbl.Title,"DAT",NULL);
2016-05-30 19:44:21 +02:00
fprintf (Gbl.F.Out,"%u</a>",
2014-12-01 23:55:08 +01:00
Ctr_GetNumCtrsInIns (Gbl.CurrentIns.Ins.InsCod));
2016-05-30 19:44:21 +02:00
Act_FormEnd ();
fprintf (Gbl.F.Out,"</td>"
"</tr>");
2014-12-01 23:55:08 +01:00
/***** Number of degrees *****/
fprintf (Gbl.F.Out,"<tr>"
2015-07-28 00:16:09 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2014-12-23 14:41:10 +01:00
"%s:"
"</td>"
2015-08-03 22:24:32 +02:00
"<td class=\"DAT LEFT_MIDDLE\">"
2014-12-23 14:41:10 +01:00
"%u"
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>",
2015-07-28 00:16:09 +02:00
The_ClassForm[Gbl.Prefs.Theme],
2014-12-01 23:55:08 +01:00
Txt_Degrees,
Deg_GetNumDegsInIns (Gbl.CurrentIns.Ins.InsCod));
/***** Number of courses *****/
fprintf (Gbl.F.Out,"<tr>"
2015-07-28 00:16:09 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2014-12-23 14:41:10 +01:00
"%s:"
"</td>"
2015-08-03 22:24:32 +02:00
"<td class=\"DAT LEFT_MIDDLE\">"
2014-12-23 14:41:10 +01:00
"%u"
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>",
2015-07-28 00:16:09 +02:00
The_ClassForm[Gbl.Prefs.Theme],
2014-12-01 23:55:08 +01:00
Txt_Courses,
Crs_GetNumCrssInIns (Gbl.CurrentIns.Ins.InsCod));
/***** Number of departments *****/
fprintf (Gbl.F.Out,"<tr>"
2015-07-28 00:16:09 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2014-12-23 14:41:10 +01:00
"%s:"
"</td>"
2015-08-03 22:24:32 +02:00
"<td class=\"DAT LEFT_MIDDLE\">"
2014-12-23 14:41:10 +01:00
"%u"
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>",
2015-07-28 00:16:09 +02:00
The_ClassForm[Gbl.Prefs.Theme],
2014-12-01 23:55:08 +01:00
Txt_Departments,
Dpt_GetNumDepartmentsInInstitution (Gbl.CurrentIns.Ins.InsCod));
2015-12-09 19:51:17 +01:00
/***** Number of teachers in courses of this institution *****/
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<tr>"
2015-07-28 00:16:09 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2014-12-23 14:41:10 +01:00
"%s:"
"</td>"
2015-08-03 22:24:32 +02:00
"<td class=\"DAT LEFT_MIDDLE\">"
2014-12-23 14:41:10 +01:00
"%u"
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>",
2015-07-28 00:16:09 +02:00
The_ClassForm[Gbl.Prefs.Theme],
2015-04-07 21:44:24 +02:00
Txt_ROLES_PLURAL_Abc[Rol_TEACHER][Usr_SEX_UNKNOWN],
Usr_GetNumUsrsInCrssOfIns (Rol_TEACHER,Gbl.CurrentIns.Ins.InsCod));
2014-12-01 23:55:08 +01:00
2015-12-09 19:51:17 +01:00
/***** Number of students in courses of this institution *****/
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<tr>"
2015-07-28 00:16:09 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2014-12-23 14:41:10 +01:00
"%s:"
"</td>"
2015-08-03 22:24:32 +02:00
"<td class=\"DAT LEFT_MIDDLE\">"
2014-12-23 14:41:10 +01:00
"%u"
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>",
2015-07-28 00:16:09 +02:00
The_ClassForm[Gbl.Prefs.Theme],
2015-04-07 21:44:24 +02:00
Txt_ROLES_PLURAL_Abc[Rol_STUDENT][Usr_SEX_UNKNOWN],
Usr_GetNumUsrsInCrssOfIns (Rol_STUDENT,Gbl.CurrentIns.Ins.InsCod));
2015-12-09 19:51:17 +01:00
/***** Number of users in courses of this institution *****/
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"%s RIGHT_MIDDLE\">"
"%s + %s:"
"</td>"
"<td class=\"DAT LEFT_MIDDLE\">"
"%u"
"</td>"
"</tr>",
The_ClassForm[Gbl.Prefs.Theme],
Txt_ROLES_PLURAL_Abc[Rol_TEACHER][Usr_SEX_UNKNOWN],
Txt_ROLES_PLURAL_Abc[Rol_STUDENT][Usr_SEX_UNKNOWN],
Usr_GetNumUsrsInCrssOfIns (Rol_UNKNOWN,Gbl.CurrentIns.Ins.InsCod));
2014-12-01 23:55:08 +01:00
}
2014-12-08 17:35:48 +01:00
2016-03-18 20:07:40 +01:00
/***** End table *****/
fprintf (Gbl.F.Out,"</table>");
/***** End frame *****/
Lay_EndRoundFrame ();
2014-12-01 23:55:08 +01:00
}
}
2016-03-18 20:07:40 +01:00
/*****************************************************************************/
2016-05-05 18:40:42 +02:00
/********* Put contextual icons in configuration of an institution ***********/
2016-03-18 20:07:40 +01:00
/*****************************************************************************/
2016-05-05 18:40:42 +02:00
static void Ins_PutIconsToPrintAndUpload (void)
2016-03-18 20:07:40 +01:00
{
extern const char *Txt_Print;
2016-05-05 18:40:42 +02:00
/***** Link to print info about institution *****/
2016-07-01 16:32:42 +02:00
Lay_PutContextualLink (ActPrnInsInf,NULL,
"print64x64.png",
Txt_Print,NULL,
NULL);
2016-05-05 18:40:42 +02:00
if (Gbl.Usrs.Me.LoggedRole >= Rol_INS_ADM)
2016-05-05 19:53:35 +02:00
/***** Link to upload logo of institution *****/
2016-05-05 20:16:28 +02:00
Log_PutIconToChangeLogo (Sco_SCOPE_INS);
2016-03-18 20:07:40 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/**************** List the institutions of the current country ***************/
/*****************************************************************************/
void Ins_ShowInssOfCurrentCty (void)
{
if (Gbl.CurrentCty.Cty.CtyCod > 0)
{
/***** Get parameter with the type of order in the list of institutions *****/
Ins_GetParamInsOrderType ();
/***** Get list of institutions *****/
Ins_GetListInstitutions (Gbl.CurrentCty.Cty.CtyCod,Ins_GET_EXTRA_DATA);
/***** Write menu to select country *****/
2015-07-25 20:07:38 +02:00
Deg_WriteMenuAllCourses ();
2014-12-01 23:55:08 +01:00
/***** List institutions *****/
2015-10-06 01:19:21 +02:00
Ins_ListInstitutions ();
2014-12-01 23:55:08 +01:00
/***** Free list of institutions *****/
Ins_FreeListInstitutions ();
}
}
/*****************************************************************************/
/*************** List the institutions of the current country ****************/
/*****************************************************************************/
2015-10-06 01:19:21 +02:00
static void Ins_ListInstitutions (void)
{
2016-03-20 14:11:04 +01:00
extern const char *Txt_Institutions_of_COUNTRY_X;
extern const char *Txt_No_institutions;
2016-03-16 13:23:10 +01:00
extern const char *Txt_Create_another_institution;
2015-10-06 01:19:21 +02:00
extern const char *Txt_Create_institution;
2016-03-20 14:11:04 +01:00
unsigned NumIns;
2015-10-06 01:19:21 +02:00
bool ICanEdit = (Gbl.Usrs.Me.LoggedRole >= Rol__GUEST_);
2016-03-20 14:11:04 +01:00
/***** Start frame *****/
sprintf (Gbl.Title,Txt_Institutions_of_COUNTRY_X,Gbl.CurrentCty.Cty.Name[Gbl.Prefs.Language]);
Lay_StartRoundFrame (NULL,Gbl.Title,ICanEdit ? Ins_PutIconToEditInstitutions :
NULL);
2015-10-06 01:19:21 +02:00
if (Gbl.Inss.Num) // There are institutions in the current country
2016-03-20 14:11:04 +01:00
{
/***** Start table *****/
2016-03-21 18:37:28 +01:00
fprintf (Gbl.F.Out,"<table class=\"FRAME_TABLE_MARGIN CELLS_PAD_2\">");
2016-03-20 14:11:04 +01:00
Ins_PutHeadInstitutionsForSeeing (true); // Order selectable
2016-03-16 12:49:28 +01:00
2016-03-20 14:11:04 +01:00
/***** Write all the institutions and their nuber of users *****/
for (NumIns = 0;
NumIns < Gbl.Inss.Num;
NumIns++)
Ins_ListOneInstitutionForSeeing (&(Gbl.Inss.Lst[NumIns]),NumIns + 1);
/***** End table *****/
fprintf (Gbl.F.Out,"</table>");
}
else // No insrtitutions created in the current country
Lay_ShowAlert (Lay_INFO,Txt_No_institutions);
/***** Button to create institution *****/
2016-03-16 12:49:28 +01:00
if (ICanEdit)
{
Act_FormStart (ActEdiIns);
2016-03-16 13:23:10 +01:00
Lay_PutConfirmButton (Gbl.Inss.Num ? Txt_Create_another_institution :
Txt_Create_institution);
2016-03-16 12:49:28 +01:00
Act_FormEnd ();
2015-10-06 01:19:21 +02:00
}
2014-12-01 23:55:08 +01:00
2016-03-16 12:49:28 +01:00
Lay_EndRoundFrame ();
2014-12-01 23:55:08 +01:00
}
2016-03-16 13:23:10 +01:00
/*****************************************************************************/
/******************** Put link (form) to edit institutions *******************/
/*****************************************************************************/
2016-03-16 22:40:35 +01:00
static void Ins_PutIconToEditInstitutions (void)
2016-03-16 13:23:10 +01:00
{
extern const char *Txt_Edit;
2016-07-01 16:32:42 +02:00
Lay_PutContextualLink (ActEdiIns,NULL,
"edit64x64.png",
Txt_Edit,NULL,
NULL);
2016-03-16 13:23:10 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************** List one institution for seeing **********************/
/*****************************************************************************/
static void Ins_ListOneInstitutionForSeeing (struct Institution *Ins,unsigned NumIns)
{
extern const char *Txt_INSTITUTION_STATUS[Ins_NUM_STATUS_TXT];
2015-11-19 16:09:51 +01:00
const char *TxtClassNormal;
const char *TxtClassStrong;
2015-09-04 19:26:08 +02:00
const char *BgColor;
2014-12-01 23:55:08 +01:00
Crs_StatusTxt_t StatusTxt;
2015-11-19 16:09:51 +01:00
if (Ins->Status & Ins_STATUS_BIT_PENDING)
{
TxtClassNormal = "DAT_LIGHT";
TxtClassStrong = "DAT_LIGHT";
}
else
{
TxtClassNormal = "DAT";
TxtClassStrong = "DAT_N";
}
2015-09-04 19:26:08 +02:00
BgColor = (Ins->InsCod == Gbl.CurrentIns.Ins.InsCod) ? "LIGHT_BLUE" :
Gbl.ColorRows[Gbl.RowEvenOdd];
2014-12-01 23:55:08 +01:00
/***** Number of institution in this list *****/
fprintf (Gbl.F.Out,"<tr>"
2015-09-04 17:10:27 +02:00
"<td class=\"%s RIGHT_MIDDLE %s\">"
2014-12-01 23:55:08 +01:00
"%u"
"</td>",
2015-11-19 16:09:51 +01:00
TxtClassNormal,BgColor,
2014-12-01 23:55:08 +01:00
NumIns);
2015-11-19 16:09:51 +01:00
/***** Institution logo and name *****/
2015-11-19 19:37:44 +01:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE %s\">",BgColor);
2015-11-19 18:33:16 +01:00
Ins_DrawInstitutionLogoAndNameWithLink (Ins,ActSeeCtr,
2015-11-19 19:37:44 +01:00
TxtClassStrong,"CENTER_MIDDLE");
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
/***** Stats *****/
2015-12-09 19:51:17 +01:00
/* Number of users who claim to belong to this institution */
2015-09-04 17:10:27 +02:00
fprintf (Gbl.F.Out,"<td class=\"%s RIGHT_MIDDLE %s\">"
2014-12-23 14:41:10 +01:00
"%u"
"</td>",
2015-12-09 19:51:17 +01:00
TxtClassNormal,BgColor,Ins->NumUsrsWhoClaimToBelongToIns);
/* Number of centres in this institution */
2015-09-04 17:10:27 +02:00
fprintf (Gbl.F.Out,"<td class=\"%s RIGHT_MIDDLE %s\">"
2014-12-23 14:41:10 +01:00
"%u"
"</td>",
2015-12-09 19:51:17 +01:00
TxtClassNormal,BgColor,Ins->NumCtrs);
/* Number of degrees in this institution */
2015-09-04 17:10:27 +02:00
fprintf (Gbl.F.Out,"<td class=\"%s RIGHT_MIDDLE %s\">"
2014-12-23 14:41:10 +01:00
"%u"
"</td>",
2015-12-09 19:51:17 +01:00
TxtClassNormal,BgColor,Ins->NumDegs);
/* Number of courses in this institution */
2015-09-04 17:10:27 +02:00
fprintf (Gbl.F.Out,"<td class=\"%s RIGHT_MIDDLE %s\">"
2014-12-23 14:41:10 +01:00
"%u"
"</td>",
2015-12-09 19:51:17 +01:00
TxtClassNormal,BgColor,Ins->NumCrss);
/* Number of departments in this institution */
2015-09-04 17:10:27 +02:00
fprintf (Gbl.F.Out,"<td class=\"%s RIGHT_MIDDLE %s\">"
2014-12-23 14:41:10 +01:00
"%u"
"</td>",
2015-12-09 19:51:17 +01:00
TxtClassNormal,BgColor,Ins->NumDpts);
/* Number of users in courses of this institution */
fprintf (Gbl.F.Out,"<td class=\"%s RIGHT_MIDDLE %s\">"
"%u"
"</td>",
TxtClassNormal,BgColor,Ins->NumUsrs);
2014-12-01 23:55:08 +01:00
/***** Institution status *****/
StatusTxt = Ins_GetStatusTxtFromStatusBits (Ins->Status);
2015-09-04 17:10:27 +02:00
fprintf (Gbl.F.Out,"<td class=\"%s LEFT_MIDDLE %s\">"
2014-12-23 14:41:10 +01:00
"%s"
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>",
2015-11-19 16:09:51 +01:00
TxtClassNormal,BgColor,Txt_INSTITUTION_STATUS[StatusTxt]);
2014-12-01 23:55:08 +01:00
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
}
/*****************************************************************************/
/**************** Write header with fields of an institution *****************/
/*****************************************************************************/
static void Ins_PutHeadInstitutionsForSeeing (bool OrderSelectable)
{
extern const char *Txt_INSTITUTIONS_HELP_ORDER[2];
extern const char *Txt_INSTITUTIONS_ORDER[2];
extern const char *Txt_Teachers_ABBREVIATION;
2015-12-09 19:51:17 +01:00
extern const char *Txt_Students_ABBREVIATION;
extern const char *Txt_Centres_ABBREVIATION;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Degrees_ABBREVIATION;
2015-12-09 19:51:17 +01:00
extern const char *Txt_Courses_ABBREVIATION;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Departments_ABBREVIATION;
extern const char *Txt_Status;
Ins_InssOrderType_t Order;
fprintf (Gbl.F.Out,"<tr>"
2015-11-19 16:09:51 +01:00
"<th></th>");
2014-12-01 23:55:08 +01:00
for (Order = Ins_ORDER_BY_INSTITUTION;
Order <= Ins_ORDER_BY_NUM_USRS;
Order++)
{
2015-12-09 19:51:17 +01:00
fprintf (Gbl.F.Out,"<th class=\"%s\">",
Order == Ins_ORDER_BY_INSTITUTION ? "LEFT_MIDDLE" :
"RIGHT_MIDDLE");
2014-12-01 23:55:08 +01:00
if (OrderSelectable)
{
Act_FormStart (ActSeeIns);
Par_PutHiddenParamUnsigned ("Order",(unsigned) Order);
2016-07-01 17:13:41 +02:00
Act_LinkFormSubmit (Txt_INSTITUTIONS_HELP_ORDER[Order],"TIT_TBL",NULL);
2014-12-01 23:55:08 +01:00
if (Order == Gbl.Inss.SelectedOrderType)
fprintf (Gbl.F.Out,"<u>");
}
fprintf (Gbl.F.Out,"%s",Txt_INSTITUTIONS_ORDER[Order]);
if (OrderSelectable)
{
if (Order == Gbl.Inss.SelectedOrderType)
fprintf (Gbl.F.Out,"</u>");
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</a>");
Act_FormEnd ();
2014-12-01 23:55:08 +01:00
}
fprintf (Gbl.F.Out,"</th>");
}
2015-09-06 20:02:14 +02:00
fprintf (Gbl.F.Out,"<th class=\"RIGHT_MIDDLE\">"
2015-12-09 19:51:17 +01:00
"%s"
2014-12-27 00:28:19 +01:00
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2015-12-09 19:51:17 +01:00
"<th class=\"RIGHT_MIDDLE\">"
"%s+<br />%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2014-12-01 23:55:08 +01:00
"</tr>",
2015-12-09 19:51:17 +01:00
Txt_Centres_ABBREVIATION,
2014-12-01 23:55:08 +01:00
Txt_Degrees_ABBREVIATION,
2015-12-09 19:51:17 +01:00
Txt_Courses_ABBREVIATION,
2014-12-01 23:55:08 +01:00
Txt_Departments_ABBREVIATION,
2015-12-14 16:44:14 +01:00
Txt_Teachers_ABBREVIATION,Txt_Students_ABBREVIATION,
2014-12-01 23:55:08 +01:00
Txt_Status);
}
/*****************************************************************************/
/******* Get parameter with the type or order in list of institutions ********/
/*****************************************************************************/
static void Ins_GetParamInsOrderType (void)
{
char UnsignedStr[10+1];
unsigned UnsignedNum;
Par_GetParToText ("Order",UnsignedStr,10);
if (sscanf (UnsignedStr,"%u",&UnsignedNum) == 1)
Gbl.Inss.SelectedOrderType = (Ins_InssOrderType_t) UnsignedNum;
else
Gbl.Inss.SelectedOrderType = Ins_DEFAULT_ORDER_TYPE;
}
/*****************************************************************************/
/************************ Put forms to edit institutions *********************/
/*****************************************************************************/
void Ins_EditInstitutions (void)
{
/***** Get list of institutions *****/
Ins_GetListInstitutions (Gbl.CurrentCty.Cty.CtyCod,Ins_GET_EXTRA_DATA);
/***** Put a form to create a new institution *****/
Ins_PutFormToCreateInstitution ();
/***** Forms to edit current institutions *****/
if (Gbl.Inss.Num)
Ins_ListInstitutionsForEdition ();
/***** Free list of institutions *****/
Ins_FreeListInstitutions ();
}
/*****************************************************************************/
/********************** Get list of current institutions *********************/
/*****************************************************************************/
// If CtyCod <= 0, get all institutions
void Ins_GetListInstitutions (long CtyCod,Ins_GetExtraData_t GetExtraData)
{
char OrderBySubQuery[256];
char Query[1024];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned NumIns;
struct Institution *Ins;
/***** Get institutions from database *****/
switch (GetExtraData)
{
2015-12-09 19:51:17 +01:00
case Ins_GET_BASIC_DATA:
2015-12-09 22:05:21 +01:00
sprintf (Query,"SELECT InsCod,CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW"
" FROM institutions"
" WHERE CtyCod='%ld'"
" ORDER BY FullName",
CtyCod);
2014-12-01 23:55:08 +01:00
break;
case Ins_GET_EXTRA_DATA:
switch (Gbl.Inss.SelectedOrderType)
{
case Ins_ORDER_BY_INSTITUTION:
sprintf (OrderBySubQuery,"FullName");
break;
case Ins_ORDER_BY_NUM_USRS:
sprintf (OrderBySubQuery,"NumUsrs DESC,FullName");
break;
}
2015-12-09 22:05:21 +01:00
sprintf (Query,"(SELECT institutions.InsCod,institutions.CtyCod,"
"institutions.Status,institutions.RequesterUsrCod,"
"institutions.ShortName,institutions.FullName,"
"institutions.WWW,COUNT(*) AS NumUsrs"
" FROM institutions,usr_data"
" WHERE institutions.CtyCod='%ld'"
" AND institutions.InsCod=usr_data.InsCod"
" GROUP BY institutions.InsCod)"
" UNION "
"(SELECT InsCod,CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW,0 AS NumUsrs"
" FROM institutions"
" WHERE CtyCod='%ld'"
" AND InsCod NOT IN"
" (SELECT DISTINCT InsCod FROM usr_data))"
" ORDER BY %s",
CtyCod,CtyCod,
OrderBySubQuery);
2014-12-01 23:55:08 +01:00
break;
}
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get institutions");
if (NumRows) // Institutions found...
{
// NumRows should be equal to Deg->NumCourses
Gbl.Inss.Num = (unsigned) NumRows;
/***** Create list with institutions *****/
if ((Gbl.Inss.Lst = (struct Institution *) calloc (NumRows,sizeof (struct Institution))) == NULL)
Lay_ShowErrorAndExit ("Not enough memory to store institutions.");
/***** Get the institutions *****/
for (NumIns = 0;
NumIns < Gbl.Inss.Num;
NumIns++)
{
Ins = &(Gbl.Inss.Lst[NumIns]);
/* Get next institution */
row = mysql_fetch_row (mysql_res);
/* Get institution code (row[0]) */
if ((Ins->InsCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of institution.");
/* Get country code (row[1]) */
Ins->CtyCod = Str_ConvertStrCodToLongCod (row[1]);
/* Get institution status (row[2]) */
if (sscanf (row[2],"%u",&(Ins->Status)) != 1)
Lay_ShowErrorAndExit ("Wrong institution status.");
/* Get requester user's code (row[3]) */
Ins->RequesterUsrCod = Str_ConvertStrCodToLongCod (row[3]);
/* Get the short name of the institution (row[4]) */
strcpy (Ins->ShortName,row[4]);
/* Get the full name of the institution (row[5]) */
strncpy (Ins->FullName,row[5],Ins_MAX_LENGTH_INSTITUTION_FULL_NAME);
Ins->FullName[Ins_MAX_LENGTH_INSTITUTION_FULL_NAME] = '\0';
2015-01-17 13:31:25 +01:00
/* Get the URL of the institution (row[6]) */
strcpy (Ins->WWW,row[6]);
2014-12-01 23:55:08 +01:00
/* Get extra data */
switch (GetExtraData)
{
2015-12-09 19:51:17 +01:00
case Ins_GET_BASIC_DATA:
Ins->NumUsrsWhoClaimToBelongToIns = 0;
Ins->NumCtrs = Ins->NumDegs = Ins->NumCrss = Ins->NumDpts = 0;
2015-12-14 12:13:41 +01:00
Ins->NumUsrs = 0;
2014-12-01 23:55:08 +01:00
break;
case Ins_GET_EXTRA_DATA:
2015-12-09 19:51:17 +01:00
/* Get number of users who claim to belong to this institution (row[7]) */
if (sscanf (row[7],"%u",&Ins->NumUsrsWhoClaimToBelongToIns) != 1)
Ins->NumUsrsWhoClaimToBelongToIns = 0;
2014-12-01 23:55:08 +01:00
/* Get number of centres in this institution */
Ins->NumCtrs = Ctr_GetNumCtrsInIns (Ins->InsCod);
2015-12-09 19:51:17 +01:00
/* Get number of degrees in this institution */
Ins->NumDegs = Deg_GetNumDegsInIns (Ins->InsCod);
/* Get number of degrees in this institution */
Ins->NumCrss = Crs_GetNumCrssInIns (Ins->InsCod);
2014-12-01 23:55:08 +01:00
/* Get number of departments in this institution */
Ins->NumDpts = Dpt_GetNumberOfDepartmentsInInstitution (Ins->InsCod);
2015-12-09 19:51:17 +01:00
/* Get number of users in courses */
2015-12-14 12:30:24 +01:00
Ins->NumUsrs = Usr_GetNumUsrsInCrssOfIns (Rol_UNKNOWN,Ins->InsCod); // Here Rol_UNKNOWN means "all users"
2014-12-01 23:55:08 +01:00
break;
}
}
}
else
Gbl.Inss.Num = 0;
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/************************* Get data of an institution ************************/
/*****************************************************************************/
bool Ins_GetDataOfInstitutionByCod (struct Institution *Ins,
Ins_GetExtraData_t GetExtraData)
{
char Query[1024];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
bool InsFound;
/***** Clear data *****/
Ins->CtyCod = -1L;
Ins->Status = (Ins_Status_t) 0;
Ins->RequesterUsrCod = -1L;
Ins->ShortName[0] =
2015-12-14 12:30:24 +01:00
Ins->FullName[0] =
Ins->WWW[0] = '\0';
Ins->NumUsrsWhoClaimToBelongToIns = 0;
Ins->NumCtrs = Ins->NumDegs = Ins->NumCrss = Ins->NumDpts = 0;
Ins->NumUsrs = 0;
2014-12-01 23:55:08 +01:00
/***** Check if institution code is correct *****/
if (Ins->InsCod <= 0)
return false;
// Ins->InsCod > 0
/***** Get data of an institution from database *****/
2015-01-17 13:31:25 +01:00
sprintf (Query,"SELECT CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW"
2014-12-01 23:55:08 +01:00
" FROM institutions WHERE InsCod='%ld'",
Ins->InsCod);
/***** Count number of rows in result *****/
if (DB_QuerySELECT (Query,&mysql_res,"can not get data of an institution")) // Institution found...
{
InsFound = true;
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get country code (row[0]) */
Ins->CtyCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get centre status (row[1]) */
if (sscanf (row[1],"%u",&(Ins->Status)) != 1)
Lay_ShowErrorAndExit ("Wrong institution status.");
/* Get requester user's code (row[2]) */
Ins->RequesterUsrCod = Str_ConvertStrCodToLongCod (row[2]);
/* Get the short name of the institution (row[3]) */
strcpy (Ins->ShortName,row[3]);
/* Get the full name of the institution (row[4]) */
strncpy (Ins->FullName,row[4],Ins_MAX_LENGTH_INSTITUTION_FULL_NAME);
Ins->FullName[Ins_MAX_LENGTH_INSTITUTION_FULL_NAME] = '\0';
2015-01-17 13:31:25 +01:00
/* Get the URL of the institution (row[5]) */
strcpy (Ins->WWW,row[5]);
2014-12-01 23:55:08 +01:00
/* Get extra data */
if (GetExtraData == Ins_GET_EXTRA_DATA)
{
/* Get number of centres in this institution */
Ins->NumCtrs = Ctr_GetNumCtrsInIns (Ins->InsCod);
/* Get number of departments in this institution */
Ins->NumDpts = Dpt_GetNumberOfDepartmentsInInstitution (Ins->InsCod);
/* Get number of degrees in this institution */
Ins->NumDegs = Deg_GetNumDegsInIns (Ins->InsCod);
2015-12-09 22:05:21 +01:00
/* Get number of users in courses of this institution */
2015-12-14 12:30:24 +01:00
Ins->NumUsrs = Usr_GetNumUsrsInCrssOfIns (Rol_UNKNOWN,Ins->InsCod); // Here Rol_UNKNOWN means "all users"
2014-12-01 23:55:08 +01:00
}
}
else
{
Ins->InsCod = -1L;
InsFound = false;
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return InsFound;
}
2015-10-10 22:16:46 +02:00
/*****************************************************************************/
/*********** Get the short name of an institution from its code **************/
/*****************************************************************************/
void Ins_GetShortNameOfInstitutionByCod (struct Institution *Ins)
{
char Query[512];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
Ins->ShortName[0] = '\0';
if (Ins->InsCod > 0)
{
/***** Get the short name of an institution from database *****/
sprintf (Query,"SELECT ShortName FROM institutions"
" WHERE InsCod ='%ld'",
Ins->InsCod);
if (DB_QuerySELECT (Query,&mysql_res,"can not get the short name of an institution") == 1)
{
/***** Get the short name of this institution *****/
row = mysql_fetch_row (mysql_res);
strcpy (Ins->ShortName,row[0]);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************* Free list of institutions *************************/
/*****************************************************************************/
void Ins_FreeListInstitutions (void)
{
if (Gbl.Inss.Lst)
{
/***** Free memory used by the list of institutions *****/
free ((void *) Gbl.Inss.Lst);
Gbl.Inss.Lst = NULL;
Gbl.Inss.Num = 0;
}
}
/*****************************************************************************/
/************************ Write selector of institution **********************/
/*****************************************************************************/
2015-07-25 20:20:07 +02:00
void Ins_WriteSelectorOfInstitution (void)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_Institution;
char Query[512];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumInss;
unsigned NumIns;
long InsCod;
/***** Start form *****/
2015-07-25 20:20:07 +02:00
Act_FormGoToStart (ActSeeCtr);
2015-09-28 18:28:29 +02:00
fprintf (Gbl.F.Out,"<select name=\"ins\" style=\"width:175px;\"");
2014-12-01 23:55:08 +01:00
if (Gbl.CurrentCty.Cty.CtyCod > 0)
2015-10-22 14:49:48 +02:00
fprintf (Gbl.F.Out," onchange=\"document.getElementById('%s').submit();\"",
2016-01-14 10:31:09 +01:00
Gbl.Form.Id);
2014-12-01 23:55:08 +01:00
else
fprintf (Gbl.F.Out," disabled=\"disabled\"");
fprintf (Gbl.F.Out,"><option value=\"\"");
if (Gbl.CurrentIns.Ins.InsCod < 0)
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out," disabled=\"disabled\">[%s]</option>",
Txt_Institution);
if (Gbl.CurrentCty.Cty.CtyCod > 0)
{
/***** Get institutions of selected country from database *****/
sprintf (Query,"SELECT DISTINCT InsCod,ShortName FROM institutions"
" WHERE CtyCod='%ld'"
" ORDER BY ShortName",
Gbl.CurrentCty.Cty.CtyCod);
NumInss = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get institutions");
/***** List institutions *****/
for (NumIns = 0;
NumIns < NumInss;
NumIns++)
{
/* Get next institution */
row = mysql_fetch_row (mysql_res);
/* Get institution code (row[0]) */
if ((InsCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of institution.");
/* Write option */
fprintf (Gbl.F.Out,"<option value=\"%ld\"",InsCod);
if (Gbl.CurrentIns.Ins.InsCod > 0 && InsCod == Gbl.CurrentIns.Ins.InsCod)
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%s</option>",row[1]);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/***** End form *****/
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</select>");
Act_FormEnd ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************* List all the institutions *************************/
/*****************************************************************************/
#define Ins_MAX_LENGTH_WWW_ON_SCREEN 10
static void Ins_ListInstitutionsForEdition (void)
{
2014-12-13 20:32:10 +01:00
extern const char *Txt_Institutions_of_COUNTRY_X;
2014-12-01 23:55:08 +01:00
extern const char *Txt_INSTITUTION_STATUS[Ins_NUM_STATUS_TXT];
unsigned NumIns;
struct Institution *Ins;
char WWW[Ins_MAX_LENGTH_WWW_ON_SCREEN+1];
struct UsrData UsrDat;
bool ICanEdit;
Ins_StatusTxt_t StatusTxt;
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** Write heading *****/
2014-12-13 20:32:10 +01:00
sprintf (Gbl.Title,Txt_Institutions_of_COUNTRY_X,
Gbl.CurrentCty.Cty.Name[Gbl.Prefs.Language]);
2015-04-12 18:01:06 +02:00
Lay_StartRoundFrameTable (NULL,2,Gbl.Title);
2014-12-01 23:55:08 +01:00
Ins_PutHeadInstitutionsForEdition ();
/***** Write all the institutions *****/
for (NumIns = 0;
NumIns < Gbl.Inss.Num;
NumIns++)
{
Ins = &Gbl.Inss.Lst[NumIns];
ICanEdit = Ins_CheckIfICanEdit (Ins);
/* Put icon to remove institution */
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"BM\">");
2015-07-22 11:30:21 +02:00
if (Ins->NumCtrs ||
2015-12-09 22:05:21 +01:00
Ins->NumUsrsWhoClaimToBelongToIns ||
2015-08-03 22:24:32 +02:00
Ins->NumUsrs || // Institution has centres or users ==> deletion forbidden
!ICanEdit)
2015-07-22 19:20:30 +02:00
Lay_PutIconRemovalNotAllowed ();
2014-12-01 23:55:08 +01:00
else
{
Act_FormStart (ActRemIns);
Ins_PutParamOtherInsCod (Ins->InsCod);
2015-07-22 19:59:28 +02:00
Lay_PutIconRemove ();
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
2014-12-01 23:55:08 +01:00
}
fprintf (Gbl.F.Out,"</td>");
/* Institution code */
2015-12-05 21:15:30 +01:00
fprintf (Gbl.F.Out,"<td class=\"DAT CODE\">"
2014-12-23 14:41:10 +01:00
"%ld"
"</td>",
2014-12-01 23:55:08 +01:00
Ins->InsCod);
/* Institution logo */
2015-08-03 22:24:32 +02:00
fprintf (Gbl.F.Out,"<td title=\"%s\" class=\"LEFT_MIDDLE\""
2015-09-28 18:28:29 +02:00
" style=\"width:25px;\">",
2014-12-01 23:55:08 +01:00
Ins->FullName);
2015-12-13 13:53:00 +01:00
Log_DrawLogo (Sco_SCOPE_INS,Ins->InsCod,Ins->ShortName,20,NULL,true);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>");
/* Institution short name */
2015-08-03 22:24:32 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_MIDDLE\">");
2014-12-01 23:55:08 +01:00
if (ICanEdit)
{
Act_FormStart (ActRenInsSho);
Ins_PutParamOtherInsCod (Ins->InsCod);
2015-10-22 14:49:48 +02:00
fprintf (Gbl.F.Out,"<input type=\"text\" name=\"ShortName\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_SHORT_NAME\""
2015-10-22 14:49:48 +02:00
" onchange=\"document.getElementById('%s').submit();\" />",
2014-12-01 23:55:08 +01:00
Ins_MAX_LENGTH_INSTITUTION_SHORT_NAME,Ins->ShortName,
2016-01-14 10:31:09 +01:00
Gbl.Form.Id);
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
2014-12-01 23:55:08 +01:00
}
else
fprintf (Gbl.F.Out,"%s",Ins->ShortName);
fprintf (Gbl.F.Out,"</td>");
/* Institution full name */
2015-08-03 22:24:32 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_MIDDLE\">");
2014-12-01 23:55:08 +01:00
if (ICanEdit)
{
Act_FormStart (ActRenInsFul);
Ins_PutParamOtherInsCod (Ins->InsCod);
2015-10-22 14:49:48 +02:00
fprintf (Gbl.F.Out,"<input type=\"text\" name=\"FullName\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_FULL_NAME\""
2015-10-22 14:49:48 +02:00
" onchange=\"document.getElementById('%s').submit();\" />",
2014-12-01 23:55:08 +01:00
Ins_MAX_LENGTH_INSTITUTION_FULL_NAME,Ins->FullName,
2016-01-14 10:31:09 +01:00
Gbl.Form.Id);
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
2014-12-01 23:55:08 +01:00
}
else
fprintf (Gbl.F.Out,"%s",Ins->FullName);
fprintf (Gbl.F.Out,"</td>");
/* Institution WWW */
2015-08-03 22:24:32 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_MIDDLE\">");
2014-12-01 23:55:08 +01:00
if (ICanEdit)
{
Act_FormStart (ActChgInsWWW);
Ins_PutParamOtherInsCod (Ins->InsCod);
2015-10-22 14:49:48 +02:00
fprintf (Gbl.F.Out,"<input type=\"text\" name=\"WWW\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_WWW\""
2015-10-22 14:49:48 +02:00
" onchange=\"document.getElementById('%s').submit();\" />",
2014-12-01 23:55:08 +01:00
Cns_MAX_LENGTH_WWW,Ins->WWW,
2016-01-14 10:31:09 +01:00
Gbl.Form.Id);
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
}
else
{
strncpy (WWW,Ins->WWW,Ins_MAX_LENGTH_WWW_ON_SCREEN);
WWW[Ins_MAX_LENGTH_WWW_ON_SCREEN] = '\0';
fprintf (Gbl.F.Out,"<a href=\"%s\" target=\"_blank\" class=\"DAT\" title=\"%s\">%s",
Ins->WWW,Ins->WWW,WWW);
if (strlen (Ins->WWW) > Ins_MAX_LENGTH_WWW_ON_SCREEN)
2016-01-15 11:41:45 +01:00
fprintf (Gbl.F.Out,"&hellip;");
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</a>");
}
fprintf (Gbl.F.Out,"</td>");
2015-12-14 16:44:14 +01:00
/* Number of users who claim to belong to this institution */
2015-08-03 22:24:32 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE\">"
2014-12-23 14:41:10 +01:00
"%u"
"</td>",
2015-12-14 16:44:14 +01:00
Ins->NumUsrsWhoClaimToBelongToIns);
2014-12-01 23:55:08 +01:00
/* Number of centres */
2015-08-03 22:24:32 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE\">"
2014-12-23 14:41:10 +01:00
"%u"
"</td>",
2014-12-01 23:55:08 +01:00
Ins->NumCtrs);
2015-12-14 16:44:14 +01:00
/* Number of users in courses of this institution */
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE\">"
"%u"
"</td>",
Ins->NumUsrs);
2015-12-05 21:15:30 +01:00
/* Institution status */
2014-12-01 23:55:08 +01:00
StatusTxt = Ins_GetStatusTxtFromStatusBits (Ins->Status);
2015-12-05 21:15:30 +01:00
fprintf (Gbl.F.Out,"<td class=\"DAT STATUS\">");
2015-04-07 21:44:24 +02:00
if (Gbl.Usrs.Me.LoggedRole == Rol_SYS_ADM &&
2014-12-01 23:55:08 +01:00
StatusTxt == Ins_STATUS_PENDING)
{
Act_FormStart (ActChgInsSta);
Ins_PutParamOtherInsCod (Ins->InsCod);
2015-12-05 21:15:30 +01:00
fprintf (Gbl.F.Out,"<select name=\"Status\" class=\"INPUT_STATUS\""
2015-10-22 14:49:48 +02:00
" onchange=\"document.getElementById('%s').submit();\">"
2014-12-01 23:55:08 +01:00
"<option value=\"%u\" selected=\"selected\">%s</option>"
"<option value=\"%u\">%s</option>"
2015-03-13 00:16:02 +01:00
"</select>",
2016-01-14 10:31:09 +01:00
Gbl.Form.Id,
2014-12-01 23:55:08 +01:00
(unsigned) Ins_GetStatusBitsFromStatusTxt (Ins_STATUS_PENDING),
Txt_INSTITUTION_STATUS[Ins_STATUS_PENDING],
(unsigned) Ins_GetStatusBitsFromStatusTxt (Ins_STATUS_ACTIVE),
Txt_INSTITUTION_STATUS[Ins_STATUS_ACTIVE]);
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
2014-12-01 23:55:08 +01:00
}
else
fprintf (Gbl.F.Out,"%s",Txt_INSTITUTION_STATUS[StatusTxt]);
fprintf (Gbl.F.Out,"</td>");
2015-12-05 21:15:30 +01:00
/* Institution requester */
2014-12-01 23:55:08 +01:00
UsrDat.UsrCod = Ins->RequesterUsrCod;
Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat);
2015-12-05 21:15:30 +01:00
fprintf (Gbl.F.Out,"<td class=\"INPUT_REQUESTER LEFT_TOP\">"
"<table class=\"INPUT_REQUESTER CELLS_PAD_2\">"
2014-12-01 23:55:08 +01:00
"<tr>");
2015-12-05 21:15:30 +01:00
Msg_WriteMsgAuthor (&UsrDat,100,6,"DAT",true,NULL);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</tr>"
"</table>"
"</td>"
"</tr>");
}
/***** End table *****/
2015-04-12 18:01:06 +02:00
Lay_EndRoundFrameTable ();
2014-12-01 23:55:08 +01:00
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}
/*****************************************************************************/
/************ Check if I can edit, remove, etc. an institution ***************/
/*****************************************************************************/
static bool Ins_CheckIfICanEdit (struct Institution *Ins)
{
2015-04-07 21:44:24 +02:00
return (bool) (Gbl.Usrs.Me.LoggedRole == Rol_SYS_ADM || // I am a superuser
2014-12-01 23:55:08 +01:00
((Ins->Status & Ins_STATUS_BIT_PENDING) != 0 && // Institution is not yet activated
Gbl.Usrs.Me.UsrDat.UsrCod == Ins->RequesterUsrCod)); // I am the requester
}
/*****************************************************************************/
/******************* Set StatusTxt depending on status bits ******************/
/*****************************************************************************/
// Ins_STATUS_UNKNOWN = 0 // Other
// Ins_STATUS_ACTIVE = 1 // 00 (Status == 0)
// Ins_STATUS_PENDING = 2 // 01 (Status == Ins_STATUS_BIT_PENDING)
// Ins_STATUS_REMOVED = 3 // 1- (Status & Ins_STATUS_BIT_REMOVED)
static Ins_StatusTxt_t Ins_GetStatusTxtFromStatusBits (Ins_Status_t Status)
{
if (Status == 0)
return Ins_STATUS_ACTIVE;
if (Status == Ins_STATUS_BIT_PENDING)
return Ins_STATUS_PENDING;
if (Status & Ins_STATUS_BIT_REMOVED)
return Ins_STATUS_REMOVED;
return Ins_STATUS_UNKNOWN;
}
/*****************************************************************************/
/******************* Set status bits depending on StatusTxt ******************/
/*****************************************************************************/
// Ins_STATUS_UNKNOWN = 0 // Other
// Ins_STATUS_ACTIVE = 1 // 00 (Status == 0)
// Ins_STATUS_PENDING = 2 // 01 (Status == Ins_STATUS_BIT_PENDING)
// Ins_STATUS_REMOVED = 3 // 1- (Status & Ins_STATUS_BIT_REMOVED)
static Ins_Status_t Ins_GetStatusBitsFromStatusTxt (Ins_StatusTxt_t StatusTxt)
{
switch (StatusTxt)
{
case Ins_STATUS_UNKNOWN:
case Ins_STATUS_ACTIVE:
return (Ins_Status_t) 0;
case Ins_STATUS_PENDING:
return Ins_STATUS_BIT_PENDING;
case Ins_STATUS_REMOVED:
return Ins_STATUS_BIT_REMOVED;
}
return (Ins_Status_t) 0;
}
/*****************************************************************************/
/***************** Write parameter with code of institution ******************/
/*****************************************************************************/
void Ins_PutParamInsCod (long InsCod)
{
2015-03-07 21:08:44 +01:00
Par_PutHiddenParamLong ("ins",InsCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************** Write parameter with code of institution ******************/
/*****************************************************************************/
static void Ins_PutParamOtherInsCod (long InsCod)
{
Par_PutHiddenParamLong ("OthInsCod",InsCod);
}
/*****************************************************************************/
/******************* Get parameter with code of institution ******************/
/*****************************************************************************/
long Ins_GetParamOtherInsCod (void)
{
char LongStr[1+10+1];
/***** Get parameter with code of institution *****/
Par_GetParToText ("OthInsCod",LongStr,1+10);
return Str_ConvertStrCodToLongCod (LongStr);
}
/*****************************************************************************/
/**************************** Remove a institution ***************************/
/*****************************************************************************/
void Ins_RemoveInstitution (void)
{
extern const char *Txt_To_remove_an_institution_you_must_first_remove_all_centres_and_users_in_the_institution;
extern const char *Txt_Institution_X_removed;
char Query[512];
struct Institution Ins;
2015-01-25 18:50:43 +01:00
char PathIns[PATH_MAX+1];
2014-12-01 23:55:08 +01:00
/***** Get institution code *****/
if ((Ins.InsCod = Ins_GetParamOtherInsCod ()) < 0)
Lay_ShowErrorAndExit ("Code of institution is missing.");
/***** Get data of the institution from database *****/
2015-12-09 22:05:21 +01:00
Ins_GetDataOfInstitutionByCod (&Ins,Ins_GET_EXTRA_DATA);
2014-12-01 23:55:08 +01:00
/***** Check if this institution has users *****/
2015-12-09 22:05:21 +01:00
if (!Ins_CheckIfICanEdit (&Ins))
Lay_ShowErrorAndExit ("You don't have permission to remove institution.");
else if (Ins.NumCtrs ||
Ins.NumUsrsWhoClaimToBelongToIns ||
Ins.NumUsrs) // Institution has centres or users ==> don't remove
2014-12-01 23:55:08 +01:00
Lay_ShowAlert (Lay_WARNING,Txt_To_remove_an_institution_you_must_first_remove_all_centres_and_users_in_the_institution);
else // Institution has no users ==> remove it
{
2015-01-20 02:00:42 +01:00
/***** Remove information related to files in institution *****/
2015-01-25 18:50:43 +01:00
Brw_RemoveInsFilesFromDB (Ins.InsCod);
/***** Remove directories of the institution *****/
sprintf (PathIns,"%s/%s/%02u/%u",
Cfg_PATH_SWAD_PUBLIC,Cfg_FOLDER_INS,
(unsigned) (Ins.InsCod % 100),
(unsigned) Ins.InsCod);
2016-10-06 22:18:33 +02:00
Fil_RemoveTree (PathIns);
2015-01-20 18:55:59 +01:00
2014-12-01 23:55:08 +01:00
/***** Remove institution *****/
2015-01-20 02:00:42 +01:00
sprintf (Query,"DELETE FROM institutions WHERE InsCod='%ld'",
Ins.InsCod);
2014-12-01 23:55:08 +01:00
DB_QueryDELETE (Query,"can not remove an institution");
/***** Write message to show the change made *****/
sprintf (Gbl.Message,Txt_Institution_X_removed,
Ins.FullName);
Lay_ShowAlert (Lay_SUCCESS,Gbl.Message);
}
/***** Show the form again *****/
Ins_EditInstitutions ();
}
/*****************************************************************************/
/***************** Change the short name of an institution *******************/
/*****************************************************************************/
void Ins_RenameInsShort (void)
{
2016-03-01 23:58:48 +01:00
struct Institution *Ins;
Ins = &Gbl.Inss.EditingIns;
if (Ins_RenameInstitution (Ins,Cns_SHORT_NAME))
if (Ins->InsCod == Gbl.CurrentIns.Ins.InsCod) // If renaming current institution...
strcpy (Gbl.CurrentIns.Ins.ShortName,Ins->ShortName); // Overwrite current institution name in order to show correctly in page title and heading
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************** Change the full name of an institution ********************/
/*****************************************************************************/
void Ins_RenameInsFull (void)
{
2016-03-01 23:58:48 +01:00
struct Institution *Ins;
Ins = &Gbl.Inss.EditingIns;
if (Ins_RenameInstitution (Ins,Cns_FULL_NAME))
if (Ins->InsCod == Gbl.CurrentIns.Ins.InsCod) // If renaming current institution...
strcpy (Gbl.CurrentIns.Ins.FullName,Ins->FullName); // Overwrite current institution name in order to show correctly in page title and heading
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Change the name of an institution **********************/
/*****************************************************************************/
2016-03-01 23:58:48 +01:00
// Returns true if the institution is renamed
// Returns false if the institution is not renamed
2014-12-01 23:55:08 +01:00
2016-03-01 23:58:48 +01:00
static bool Ins_RenameInstitution (struct Institution *Ins,Cns_ShortOrFullName_t ShortOrFullName)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_You_can_not_leave_the_name_of_the_institution_X_empty;
extern const char *Txt_The_institution_X_already_exists;
2016-03-01 23:58:48 +01:00
extern const char *Txt_The_institution_X_has_been_renamed_as_Y;
2014-12-01 23:55:08 +01:00
extern const char *Txt_The_name_of_the_institution_X_has_not_changed;
char Query[512];
const char *ParamName = NULL; // Initialized to avoid warning
const char *FieldName = NULL; // Initialized to avoid warning
unsigned MaxLength = 0; // Initialized to avoid warning
char *CurrentInsName = NULL; // Initialized to avoid warning
char NewInsName[Ins_MAX_LENGTH_INSTITUTION_FULL_NAME+1];
2016-03-01 23:58:48 +01:00
bool InstitutionHasBeenRenamed = false;
2014-12-01 23:55:08 +01:00
switch (ShortOrFullName)
{
case Cns_SHORT_NAME:
ParamName = "ShortName";
FieldName = "ShortName";
MaxLength = Ins_MAX_LENGTH_INSTITUTION_SHORT_NAME;
CurrentInsName = Ins->ShortName;
break;
case Cns_FULL_NAME:
ParamName = "FullName";
FieldName = "FullName";
MaxLength = Ins_MAX_LENGTH_INSTITUTION_FULL_NAME;
CurrentInsName = Ins->FullName;
break;
}
/***** Get parameters from form *****/
/* Get the code of the institution */
if ((Ins->InsCod = Ins_GetParamOtherInsCod ()) < 0)
Lay_ShowErrorAndExit ("Code of institution is missing.");
/* Get the new name for the institution */
Par_GetParToText (ParamName,NewInsName,MaxLength);
/***** Get from the database the old names of the institution *****/
2015-12-09 19:51:17 +01:00
Ins_GetDataOfInstitutionByCod (Ins,Ins_GET_BASIC_DATA);
2014-12-01 23:55:08 +01:00
/***** Check if new name is empty *****/
if (!NewInsName[0])
{
2016-10-20 19:46:06 +02:00
Gbl.Error = true;
2014-12-01 23:55:08 +01:00
sprintf (Gbl.Message,Txt_You_can_not_leave_the_name_of_the_institution_X_empty,
CurrentInsName);
}
else
{
/***** Check if old and new names are the same (this happens when user press enter with no changes in the form) *****/
if (strcmp (CurrentInsName,NewInsName)) // Different names
{
/***** If institution was in database... *****/
if (Ins_CheckIfInsNameExistsInCty (ParamName,NewInsName,Ins->InsCod,Gbl.CurrentCty.Cty.CtyCod))
{
2016-10-20 19:46:06 +02:00
Gbl.Error = true;
2014-12-01 23:55:08 +01:00
sprintf (Gbl.Message,Txt_The_institution_X_already_exists,
NewInsName);
}
else
{
/* Update the table changing old name by new name */
sprintf (Query,"UPDATE institutions SET %s='%s' WHERE InsCod='%ld'",
FieldName,NewInsName,Ins->InsCod);
DB_QueryUPDATE (Query,"can not update the name of an institution");
2016-03-01 23:58:48 +01:00
/* Write message to show the change made */
sprintf (Gbl.Message,Txt_The_institution_X_has_been_renamed_as_Y,
2014-12-01 23:55:08 +01:00
CurrentInsName,NewInsName);
2016-03-01 23:58:48 +01:00
/* Change current institution name in order to display it properly */
strncpy (CurrentInsName,NewInsName,MaxLength);
CurrentInsName[MaxLength] = '\0';
InstitutionHasBeenRenamed = true;
2014-12-01 23:55:08 +01:00
}
}
else // The same name
sprintf (Gbl.Message,Txt_The_name_of_the_institution_X_has_not_changed,
CurrentInsName);
}
2016-03-01 23:58:48 +01:00
return InstitutionHasBeenRenamed;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****** Check if the name of institution exists in the current country *******/
/*****************************************************************************/
static bool Ins_CheckIfInsNameExistsInCty (const char *FieldName,const char *Name,long InsCod,long CtyCod)
{
char Query[512];
/***** Get number of institutions in current country with a name from database *****/
sprintf (Query,"SELECT COUNT(*) FROM institutions"
" WHERE CtyCod='%ld' AND %s='%s' AND InsCod<>'%ld'",
CtyCod,FieldName,Name,InsCod);
return (DB_QueryCOUNT (Query,"can not check if the name of an institution already existed") != 0);
}
/*****************************************************************************/
/******************* Change the country of a institution *********************/
/*****************************************************************************/
2016-10-20 19:46:06 +02:00
void Ins_ChangeInsCtyInConfig (void)
{
extern const char *Txt_The_institution_X_already_exists;
extern const char *Txt_The_country_of_the_institution_X_has_changed_to_Y;
struct Country NewCty;
/***** Get parameters from form *****/
/* Get the new country code for the institution */
if ((NewCty.CtyCod = Cty_GetParamOtherCtyCod ()) < 0)
Lay_ShowErrorAndExit ("Code of country is missing.");
/***** Check if country has changed *****/
if (NewCty.CtyCod != Gbl.CurrentIns.Ins.CtyCod)
{
/***** Get data of the country from database *****/
Cty_GetDataOfCountryByCod (&NewCty,Cty_GET_BASIC_DATA);
/***** Check if it already exists an institution with the same name in the new country *****/
if (Ins_CheckIfInsNameExistsInCty ("ShortName",Gbl.CurrentIns.Ins.ShortName,-1L,NewCty.CtyCod))
{
Gbl.Error = true;
sprintf (Gbl.Message,Txt_The_institution_X_already_exists,
Gbl.CurrentIns.Ins.ShortName);
}
else if (Ins_CheckIfInsNameExistsInCty ("FullName",Gbl.CurrentIns.Ins.FullName,-1L,NewCty.CtyCod))
{
Gbl.Error = true;
sprintf (Gbl.Message,Txt_The_institution_X_already_exists,
Gbl.CurrentIns.Ins.FullName);
}
else
{
/***** Update the table changing the country of the institution *****/
Ins_UpdateInsCtyDB (Gbl.CurrentIns.Ins.InsCod,NewCty.CtyCod);
Gbl.CurrentIns.Ins.CtyCod =
Gbl.CurrentCty.Cty.CtyCod = NewCty.CtyCod;
/***** Initialize again current course, degree, centre... *****/
Deg_InitCurrentCourse ();
/***** Write message to show the change made *****/
sprintf (Gbl.Message,Txt_The_country_of_the_institution_X_has_changed_to_Y,
Gbl.CurrentIns.Ins.FullName,NewCty.Name[Gbl.Prefs.Language]);
}
}
}
/*****************************************************************************/
/*** Show msg. of success after changing an institution in instit. config. ***/
/*****************************************************************************/
void Ins_ContEditAfterChgInsInConfig (void)
{
/***** Write error/success message *****/
Lay_ShowAlert (Gbl.Error ? Lay_WARNING :
Lay_SUCCESS,
Gbl.Message);
/***** Show the form again *****/
Ins_ShowConfiguration ();
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-10-20 19:46:06 +02:00
/****************** Update country in table of institutions ******************/
/*****************************************************************************/
static void Ins_UpdateInsCtyDB (long InsCod,long CtyCod)
{
char Query[128];
/***** Update country in table of institutions *****/
sprintf (Query,"UPDATE institutions SET CtyCod='%ld' WHERE InsCod='%ld'",
CtyCod,InsCod);
DB_QueryUPDATE (Query,"can not update the country of an institution");
}
/*****************************************************************************/
2014-12-01 23:55:08 +01:00
/********************** Change the URL of a institution **********************/
/*****************************************************************************/
void Ins_ChangeInsWWW (void)
{
extern const char *Txt_The_new_web_address_is_X;
extern const char *Txt_You_can_not_leave_the_web_address_empty;
struct Institution *Ins;
char Query[256+Cns_MAX_LENGTH_WWW];
char NewWWW[Cns_MAX_LENGTH_WWW+1];
Ins = &Gbl.Inss.EditingIns;
/***** Get parameters from form *****/
/* Get the code of the institution */
if ((Ins->InsCod = Ins_GetParamOtherInsCod ()) < 0)
Lay_ShowErrorAndExit ("Code of institution is missing.");
/* Get the new WWW for the institution */
Par_GetParToText ("WWW",NewWWW,Cns_MAX_LENGTH_WWW);
2016-03-01 23:58:48 +01:00
/***** Get data of institution *****/
Ins_GetDataOfInstitutionByCod (Ins,Ins_GET_BASIC_DATA);
2014-12-01 23:55:08 +01:00
/***** Check if new WWW is empty *****/
if (NewWWW[0])
{
/* Update the table changing old WWW by new WWW */
sprintf (Query,"UPDATE institutions SET WWW='%s' WHERE InsCod='%ld'",
NewWWW,Ins->InsCod);
DB_QueryUPDATE (Query,"can not update the web of an institution");
/***** Write message to show the change made *****/
sprintf (Gbl.Message,Txt_The_new_web_address_is_X,
NewWWW);
Lay_ShowAlert (Lay_SUCCESS,Gbl.Message);
2016-03-01 23:58:48 +01:00
/***** Put button to go to institution changed *****/
Ins_PutButtonToGoToIns (Ins);
2014-12-01 23:55:08 +01:00
}
else
Lay_ShowAlert (Lay_WARNING,Txt_You_can_not_leave_the_web_address_empty);
/***** Show the form again *****/
strcpy (Ins->WWW,NewWWW);
Ins_EditInstitutions ();
}
/*****************************************************************************/
/******************** Change the status of an institution ********************/
/*****************************************************************************/
void Ins_ChangeInsStatus (void)
{
extern const char *Txt_The_status_of_the_institution_X_has_changed;
struct Institution *Ins;
char Query[256];
char UnsignedNum[10+1];
Ins_Status_t Status;
Ins_StatusTxt_t StatusTxt;
Ins = &Gbl.Inss.EditingIns;
/***** Get parameters from form *****/
/* Get institution code */
if ((Ins->InsCod = Ins_GetParamOtherInsCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of institution is missing.");
/* Get parameter with status */
Par_GetParToText ("Status",UnsignedNum,1);
if (sscanf (UnsignedNum,"%u",&Status) != 1)
Lay_ShowErrorAndExit ("Wrong status.");
StatusTxt = Ins_GetStatusTxtFromStatusBits (Status);
Status = Ins_GetStatusBitsFromStatusTxt (StatusTxt); // New status
/***** Get data of institution *****/
2015-12-09 19:51:17 +01:00
Ins_GetDataOfInstitutionByCod (Ins,Ins_GET_BASIC_DATA);
2014-12-01 23:55:08 +01:00
/***** Update status in table of institutions *****/
sprintf (Query,"UPDATE institutions SET Status='%u' WHERE InsCod='%ld'",
(unsigned) Status,Ins->InsCod);
DB_QueryUPDATE (Query,"can not update the status of an institution");
Ins->Status = Status;
/***** Write message to show the change made *****/
sprintf (Gbl.Message,Txt_The_status_of_the_institution_X_has_changed,
Ins->ShortName);
Lay_ShowAlert (Lay_SUCCESS,Gbl.Message);
2016-03-01 23:58:48 +01:00
/***** Put button to go to institution changed *****/
Ins_PutButtonToGoToIns (Ins);
2014-12-01 23:55:08 +01:00
/***** Show the form again *****/
Ins_EditInstitutions ();
}
2016-03-01 23:58:48 +01:00
/*****************************************************************************/
/*********** Show message of success after changing an institution ***********/
/*****************************************************************************/
void Ins_ContEditAfterChgIns (void)
{
if (Gbl.Error)
/***** Write error message *****/
Lay_ShowAlert (Lay_WARNING,Gbl.Message);
else
{
/***** Write success message showing the change made *****/
Lay_ShowAlert (Lay_INFO,Gbl.Message);
/***** Put button to go to institution changed *****/
Ins_PutButtonToGoToIns (&Gbl.Inss.EditingIns);
}
/***** Show the form again *****/
Ins_EditInstitutions ();
}
/*****************************************************************************/
/********************* Put button to go to institution ***********************/
/*****************************************************************************/
static void Ins_PutButtonToGoToIns (struct Institution *Ins)
{
extern const char *Txt_Go_to_X;
// If the institution is different to the current one...
if (Ins->InsCod != Gbl.CurrentIns.Ins.InsCod)
{
2016-03-24 21:03:48 +01:00
fprintf (Gbl.F.Out,"<div class=\"BUTTONS_AFTER_ALERT\">");
2016-03-02 00:15:51 +01:00
Act_FormStart (ActSeeCtr);
2016-03-01 23:58:48 +01:00
Ins_PutParamInsCod (Ins->InsCod);
sprintf (Gbl.Title,Txt_Go_to_X,Ins->ShortName);
2016-03-24 21:03:48 +01:00
Lay_PutConfirmButtonInline (Gbl.Title);
2016-03-01 23:58:48 +01:00
Act_FormEnd ();
2016-03-24 21:03:48 +01:00
fprintf (Gbl.F.Out,"</div>");
2016-03-01 23:58:48 +01:00
}
}
2015-01-17 13:31:25 +01:00
/*****************************************************************************/
/******** Show a form for sending a logo of the current institution **********/
/*****************************************************************************/
void Ins_RequestLogo (void)
{
2015-02-01 20:17:24 +01:00
Log_RequestLogo (Sco_SCOPE_INS);
2015-01-17 13:31:25 +01:00
}
/*****************************************************************************/
/************** Receive the logo of the current institution ******************/
/*****************************************************************************/
void Ins_ReceiveLogo (void)
{
2015-02-01 20:17:24 +01:00
Log_ReceiveLogo (Sco_SCOPE_INS);
2015-01-17 13:31:25 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2015-02-03 18:43:55 +01:00
/*************** Remove the logo of the current institution ******************/
/*****************************************************************************/
void Ins_RemoveLogo (void)
{
Log_RemoveLogo (Sco_SCOPE_INS);
}
/*****************************************************************************/
/****************** Put a form to create a new institution *******************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
static void Ins_PutFormToCreateInstitution (void)
{
2014-12-13 20:32:10 +01:00
extern const char *Txt_New_institution_of_COUNTRY_X;
2014-12-01 23:55:08 +01:00
extern const char *Txt_INSTITUTION_STATUS[Ins_NUM_STATUS_TXT];
extern const char *Txt_Create_institution;
struct Institution *Ins;
Ins = &Gbl.Inss.EditingIns;
/***** Start form *****/
2015-04-07 21:44:24 +02:00
if (Gbl.Usrs.Me.LoggedRole == Rol_SYS_ADM)
2014-12-01 23:55:08 +01:00
Act_FormStart (ActNewIns);
2015-04-07 21:44:24 +02:00
else if (Gbl.Usrs.Me.MaxRole >= Rol__GUEST_)
2014-12-01 23:55:08 +01:00
Act_FormStart (ActReqIns);
else
Lay_ShowErrorAndExit ("You can not edit institutions.");
/***** Start of frame *****/
2014-12-13 20:32:10 +01:00
sprintf (Gbl.Title,Txt_New_institution_of_COUNTRY_X,
Gbl.CurrentCty.Cty.Name[Gbl.Prefs.Language]);
2015-04-12 18:01:06 +02:00
Lay_StartRoundFrameTable (NULL,2,Gbl.Title);
2014-12-01 23:55:08 +01:00
/***** Write heading *****/
Ins_PutHeadInstitutionsForEdition ();
/***** Put icon to remove institution *****/
fprintf (Gbl.F.Out,"<tr>"
2015-07-22 19:20:30 +02:00
"<td class=\"BM\">");
Lay_PutIconRemovalNotAllowed ();
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
/***** Institution code *****/
2015-12-05 21:15:30 +01:00
fprintf (Gbl.F.Out,"<td class=\"CODE\"></td>");
2014-12-01 23:55:08 +01:00
/***** Institution logo *****/
2015-09-28 18:28:29 +02:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE\" style=\"width:25px;\">");
2015-12-13 13:53:00 +01:00
Log_DrawLogo (Sco_SCOPE_INS,-1L,"",20,NULL,true);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>");
/***** Institution short name *****/
2015-12-05 21:15:30 +01:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE\">"
2015-10-23 01:31:08 +02:00
"<input type=\"text\" name=\"ShortName\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_SHORT_NAME\" />"
2014-12-01 23:55:08 +01:00
"</td>",
Ins_MAX_LENGTH_INSTITUTION_SHORT_NAME,Ins->ShortName);
/***** Institution full name *****/
2015-12-05 21:15:30 +01:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE\">"
2015-10-23 01:31:08 +02:00
"<input type=\"text\" name=\"FullName\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_FULL_NAME\" />"
2014-12-01 23:55:08 +01:00
"</td>",
Ins_MAX_LENGTH_INSTITUTION_FULL_NAME,Ins->FullName);
/***** Institution WWW *****/
2015-12-05 21:15:30 +01:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE\">"
2015-10-23 01:31:08 +02:00
"<input type=\"text\" name=\"WWW\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_WWW\" />"
2014-12-01 23:55:08 +01:00
"</td>",
Cns_MAX_LENGTH_WWW,Ins->WWW);
2015-12-14 16:44:14 +01:00
/***** Number of users who claim to belong to this institution ****/
2015-08-03 22:24:32 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE\">"
2014-12-23 14:41:10 +01:00
"0"
"</td>");
2014-12-01 23:55:08 +01:00
/***** Number of centres *****/
2015-08-03 22:24:32 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE\">"
2014-12-23 14:41:10 +01:00
"0"
"</td>");
2014-12-01 23:55:08 +01:00
2015-12-14 16:44:14 +01:00
/***** Number of users in courses of this institution ****/
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE\">"
"0"
"</td>");
2015-12-05 21:15:30 +01:00
/***** Institution status *****/
fprintf (Gbl.F.Out,"<td class=\"DAT STATUS\">"
2014-12-23 14:41:10 +01:00
"%s"
"</td>",
2014-12-01 23:55:08 +01:00
Txt_INSTITUTION_STATUS[Ins_STATUS_PENDING]);
2015-12-05 21:15:30 +01:00
/***** Institution requester *****/
fprintf (Gbl.F.Out,"<td class=\"INPUT_REQUESTER LEFT_TOP\">"
"<table class=\"INPUT_REQUESTER CELLS_PAD_2\">"
2014-12-01 23:55:08 +01:00
"<tr>");
2015-12-05 21:15:30 +01:00
Msg_WriteMsgAuthor (&Gbl.Usrs.Me.UsrDat,100,6,"DAT",true,NULL);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</tr>"
"</table>"
"</td>"
"</tr>");
2015-04-11 23:46:21 +02:00
/***** Send button and end of frame *****/
2015-04-12 18:01:06 +02:00
Lay_EndRoundFrameTableWithButton (Lay_CREATE_BUTTON,Txt_Create_institution);
2014-12-01 23:55:08 +01:00
/***** End of form *****/
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/**************** Write header with fields of an institution *****************/
/*****************************************************************************/
static void Ins_PutHeadInstitutionsForEdition (void)
{
extern const char *Txt_Code;
2016-03-02 14:53:46 +01:00
extern const char *Txt_Short_name_of_the_institution;
extern const char *Txt_Full_name_of_the_institution;
2014-12-01 23:55:08 +01:00
extern const char *Txt_WWW;
extern const char *Txt_Users;
extern const char *Txt_Centres_ABBREVIATION;
2015-12-14 16:44:14 +01:00
extern const char *Txt_Teachers_ABBREVIATION;
extern const char *Txt_Students_ABBREVIATION;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Status;
extern const char *Txt_Requester;
fprintf (Gbl.F.Out,"<tr>"
2014-12-27 00:28:19 +01:00
"<th></th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2015-12-05 21:15:30 +01:00
"<th></th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2015-12-14 16:44:14 +01:00
"<th class=\"RIGHT_MIDDLE\">"
"%s+<br />%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2014-12-01 23:55:08 +01:00
"</tr>",
Txt_Code,
2016-03-02 14:53:46 +01:00
Txt_Short_name_of_the_institution,
Txt_Full_name_of_the_institution,
2014-12-01 23:55:08 +01:00
Txt_WWW,
Txt_Users,
Txt_Centres_ABBREVIATION,
2015-12-14 16:44:14 +01:00
Txt_Teachers_ABBREVIATION,Txt_Students_ABBREVIATION,
2014-12-01 23:55:08 +01:00
Txt_Status,
Txt_Requester);
}
/*****************************************************************************/
/*************** Receive form to request a new institution *******************/
/*****************************************************************************/
void Ins_RecFormReqIns (void)
{
Ins_RecFormRequestOrCreateIns ((unsigned) Ins_STATUS_BIT_PENDING);
}
/*****************************************************************************/
/***************** Receive form to create a new institution ******************/
/*****************************************************************************/
void Ins_RecFormNewIns (void)
{
Ins_RecFormRequestOrCreateIns (0);
}
/*****************************************************************************/
/*********** Receive form to request or create a new institution *************/
/*****************************************************************************/
static void Ins_RecFormRequestOrCreateIns (unsigned Status)
{
extern const char *Txt_The_institution_X_already_exists;
extern const char *Txt_You_must_specify_the_web_address_of_the_new_institution;
extern const char *Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_institution;
struct Institution *Ins;
Ins = &Gbl.Inss.EditingIns;
/***** Get parameters from form *****/
/* Set institution country */
Ins->CtyCod = Gbl.CurrentCty.Cty.CtyCod;
/* Get institution short name */
Par_GetParToText ("ShortName",Ins->ShortName,Ins_MAX_LENGTH_INSTITUTION_SHORT_NAME);
/* Get institution full name */
Par_GetParToText ("FullName",Ins->FullName,Ins_MAX_LENGTH_INSTITUTION_FULL_NAME);
/* Get institution WWW */
Par_GetParToText ("WWW",Ins->WWW,Cns_MAX_LENGTH_WWW);
if (Ins->ShortName[0] && Ins->FullName[0]) // If there's a institution name
{
if (Ins->WWW[0])
{
/***** If name of institution was in database... *****/
if (Ins_CheckIfInsNameExistsInCty ("ShortName",Ins->ShortName,-1L,Gbl.CurrentCty.Cty.CtyCod))
{
sprintf (Gbl.Message,Txt_The_institution_X_already_exists,
Ins->ShortName);
Lay_ShowAlert (Lay_WARNING,Gbl.Message);
}
else if (Ins_CheckIfInsNameExistsInCty ("FullName",Ins->FullName,-1L,Gbl.CurrentCty.Cty.CtyCod))
{
sprintf (Gbl.Message,Txt_The_institution_X_already_exists,
Ins->FullName);
Lay_ShowAlert (Lay_WARNING,Gbl.Message);
}
else // Add new institution to database
Ins_CreateInstitution (Ins,Status);
}
2015-01-17 13:31:25 +01:00
else // If there is not a web
2014-12-01 23:55:08 +01:00
Lay_ShowAlert (Lay_WARNING,Txt_You_must_specify_the_web_address_of_the_new_institution);
}
else // If there is not a institution name
Lay_ShowAlert (Lay_WARNING,Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_institution);
/***** Show the form again *****/
Ins_EditInstitutions ();
}
/*****************************************************************************/
/************************** Create a new institution *************************/
/*****************************************************************************/
static void Ins_CreateInstitution (struct Institution *Ins,unsigned Status)
{
extern const char *Txt_Created_new_institution_X;
char Query[2048];
/***** Create a new institution *****/
sprintf (Query,"INSERT INTO institutions (CtyCod,Status,RequesterUsrCod,"
2015-01-17 13:31:25 +01:00
"ShortName,FullName,WWW)"
2014-12-01 23:55:08 +01:00
" VALUES ('%ld','%u','%ld',"
2015-01-17 13:31:25 +01:00
"'%s','%s','%s')",
2014-12-01 23:55:08 +01:00
Ins->CtyCod,
Status,
Gbl.Usrs.Me.UsrDat.UsrCod,
Ins->ShortName,Ins->FullName,Ins->WWW);
2016-03-01 23:58:48 +01:00
Ins->InsCod = DB_QueryINSERTandReturnCode (Query,"can not create institution");
2014-12-01 23:55:08 +01:00
/***** Write success message *****/
sprintf (Gbl.Message,Txt_Created_new_institution_X,
Ins->FullName);
Lay_ShowAlert (Lay_SUCCESS,Gbl.Message);
2016-03-01 23:58:48 +01:00
/***** Put button to go to institution created *****/
Ins_PutButtonToGoToIns (Ins);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Get total number of institutions **********************/
/*****************************************************************************/
unsigned Ins_GetNumInssTotal (void)
{
char Query[256];
/***** Get total number of degrees from database *****/
sprintf (Query,"SELECT COUNT(*) FROM institutions");
return (unsigned) DB_QueryCOUNT (Query,"can not get the total number of institutions");
}
/*****************************************************************************/
/**************** Get number of institutions in a country ********************/
/*****************************************************************************/
unsigned Ins_GetNumInssInCty (long CtyCod)
{
char Query[256];
/***** Get number of degrees of a place from database *****/
sprintf (Query,"SELECT COUNT(*) FROM institutions"
" WHERE CtyCod='%ld'",CtyCod);
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of institutions in a country");
}
/*****************************************************************************/
/***************** Get number of institutions with centres *******************/
/*****************************************************************************/
unsigned Ins_GetNumInssWithCtrs (const char *SubQuery)
{
char Query[512];
/***** Get number of institutions with centres from database *****/
sprintf (Query,"SELECT COUNT(DISTINCT institutions.InsCod)"
" FROM institutions,centres"
" WHERE %sinstitutions.InsCod=centres.InsCod",
SubQuery);
return (unsigned) DB_QueryCOUNT (Query,"can not get number of institutions with centres");
}
/*****************************************************************************/
/****************** Get number of institutions with degrees ******************/
/*****************************************************************************/
unsigned Ins_GetNumInssWithDegs (const char *SubQuery)
{
char Query[512];
/***** Get number of institutions with degrees from database *****/
sprintf (Query,"SELECT COUNT(DISTINCT institutions.InsCod)"
" FROM institutions,centres,degrees"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod",
SubQuery);
return (unsigned) DB_QueryCOUNT (Query,"can not get number of institutions with degrees");
}
/*****************************************************************************/
/****************** Get number of institutions with courses ******************/
/*****************************************************************************/
unsigned Ins_GetNumInssWithCrss (const char *SubQuery)
{
char Query[512];
/***** Get number of institutions with courses from database *****/
sprintf (Query,"SELECT COUNT(DISTINCT institutions.InsCod)"
" FROM institutions,centres,degrees,courses"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod",
SubQuery);
return (unsigned) DB_QueryCOUNT (Query,"can not get number of institutions with courses");
}
/*****************************************************************************/
/****************** Get number of institutions with users ********************/
/*****************************************************************************/
unsigned Ins_GetNumInssWithUsrs (Rol_Role_t Role,const char *SubQuery)
{
char Query[512];
/***** Get number of institutions with users from database *****/
sprintf (Query,"SELECT COUNT(DISTINCT institutions.InsCod)"
" FROM institutions,centres,degrees,courses,crs_usr"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role='%u'",
SubQuery,(unsigned) Role);
return (unsigned) DB_QueryCOUNT (Query,"can not get number of institutions with users");
}
/*****************************************************************************/
/*************************** List institutions found *************************/
/*****************************************************************************/
// Returns number of institutions found
unsigned Ins_ListInssFound (const char *Query)
{
extern const char *Txt_institution;
extern const char *Txt_institutions;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumInss;
unsigned NumIns;
struct Institution Ins;
/***** Query database *****/
if ((NumInss = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get institutions")))
{
/***** Write heading *****/
/* Number of institutions found */
2016-04-17 23:13:00 +02:00
sprintf (Gbl.Title,"%u %s",
NumInss,NumInss == 1 ? Txt_institution :
Txt_institutions);
Lay_StartRoundFrameTable (NULL,2,Gbl.Title);
2014-12-01 23:55:08 +01:00
Ins_PutHeadInstitutionsForSeeing (false); // Order not selectable
/***** List the institutions (one row per centre) *****/
for (NumIns = 1;
NumIns <= NumInss;
NumIns++)
{
/* Get next institution */
row = mysql_fetch_row (mysql_res);
/* Get institution code (row[0]) */
Ins.InsCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get data of institution */
Ins_GetDataOfInstitutionByCod (&Ins,Ins_GET_EXTRA_DATA);
/* Write data of this centre */
Ins_ListOneInstitutionForSeeing (&Ins,NumIns);
}
2016-03-20 13:47:46 +01:00
/***** End table *****/
2015-04-12 18:01:06 +02:00
Lay_EndRoundFrameTable ();
2014-12-01 23:55:08 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumInss;
}