swad-core/swad_degree.c

2598 lines
90 KiB
C
Raw Normal View History

2014-12-01 23:55:08 +01:00
// swad_degree.c: degrees
/*
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.
2017-01-13 01:51:23 +01:00
Copyright (C) 1999-2017 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 <ctype.h> // For isprint, isspace, etc.
#include <linux/stddef.h> // For NULL
2015-10-16 02:24:29 +02:00
#include <stdbool.h> // For boolean type
2014-12-01 23:55:08 +01:00
#include <stdio.h> // For fprintf, etc.
#include <stdlib.h> // For exit, system, calloc, free, etc.
#include <string.h> // For string functions
#include <mysql/mysql.h> // To access MySQL databases
#include "swad_changelog.h"
#include "swad_config.h"
#include "swad_database.h"
#include "swad_degree.h"
2016-03-20 16:30:52 +01:00
#include "swad_degree_type.h"
2014-12-01 23:55:08 +01:00
#include "swad_exam.h"
#include "swad_global.h"
2015-10-06 20:34:49 +02:00
#include "swad_help.h"
2016-11-14 16:47:46 +01:00
#include "swad_hierarchy.h"
2014-12-01 23:55:08 +01:00
#include "swad_indicator.h"
#include "swad_info.h"
2015-01-17 13:31:25 +01:00
#include "swad_logo.h"
2014-12-01 23:55:08 +01:00
#include "swad_notification.h"
#include "swad_parameter.h"
#include "swad_QR.h"
#include "swad_RSS.h"
#include "swad_string.h"
2015-01-04 15:48:24 +01:00
#include "swad_tab.h"
2014-12-01 23:55:08 +01:00
#include "swad_text.h"
2015-01-04 15:48:24 +01:00
#include "swad_theme.h"
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/*************************** Public constants ********************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private types *********************************/
/*****************************************************************************/
typedef enum
{
Deg_FIRST_YEAR,
Deg_LAST_YEAR,
} Deg_FirstOrLastYear_t;
/*****************************************************************************/
/**************************** Private constants ******************************/
/*****************************************************************************/
/*****************************************************************************/
/**************************** Private prototypes *****************************/
/*****************************************************************************/
static void Deg_Configuration (bool PrintView);
2016-05-05 20:16:28 +02:00
static void Deg_PutIconsToPrintAndUpload (void);
2014-12-01 23:55:08 +01:00
static void Deg_ListDegreesForEdition (void);
2016-11-06 23:56:43 +01:00
static bool Deg_CheckIfICanEditADegree (struct Degree *Deg);
2014-12-01 23:55:08 +01:00
static Deg_StatusTxt_t Deg_GetStatusTxtFromStatusBits (Deg_Status_t Status);
static Deg_Status_t Deg_GetStatusBitsFromStatusTxt (Deg_StatusTxt_t StatusTxt);
static void Deg_PutFormToCreateDegree (void);
static void Deg_PutHeadDegreesForSeeing (void);
static void Deg_PutHeadDegreesForEdition (void);
2017-05-11 20:04:38 +02:00
static void Deg_CreateDegree (unsigned Status);
2016-03-20 13:18:56 +01:00
2014-12-01 23:55:08 +01:00
static void Deg_ListDegrees (void);
2016-11-07 00:03:50 +01:00
static bool Deg_CheckIfICanCreateDegrees (void);
2016-11-06 23:56:43 +01:00
static void Deg_PutIconsListDegrees (void);
2016-03-20 13:18:56 +01:00
static void Deg_PutIconToEditDegrees (void);
static void Deg_ListOneDegreeForSeeing (struct Degree *Deg,unsigned NumDeg);
2017-04-30 02:56:25 +02:00
static void Deg_PutIconsEditingDegrees (void);
static void Deg_PutIconToViewDegrees (void);
2014-12-01 23:55:08 +01:00
static void Deg_RecFormRequestOrCreateDeg (unsigned Status);
static void Deg_PutParamOtherDegCod (long DegCod);
static void Deg_GetDataOfDegreeFromRow (struct Degree *Deg,MYSQL_ROW row);
2017-03-09 11:16:17 +01:00
2016-10-28 10:03:37 +02:00
static void Deg_RenameDegree (struct Degree *Deg,Cns_ShrtOrFullName_t ShrtOrFullName);
2016-10-20 19:46:06 +02:00
static bool Deg_CheckIfDegNameExistsInCtr (const char *FieldName,const char *Name,long DegCod,long CtrCod);
2017-03-09 11:16:17 +01:00
static void Deg_UpdateDegNameDB (long DegCod,const char *FieldName,const char *NewDegName);
2016-10-20 16:49:42 +02:00
static void Deg_UpdateDegCtrDB (long DegCod,long CtrCod);
2017-03-07 01:56:41 +01:00
static void Deg_UpdateDegWWWDB (long DegCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1]);
2016-10-19 23:17:36 +02:00
2017-05-11 20:04:38 +02:00
static void Deg_PutParamGoToDeg (void);
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/******************* List degrees with pending courses ***********************/
/*****************************************************************************/
void Deg_SeeDegWithPendingCrss (void)
{
2017-03-27 13:38:10 +02:00
extern const char *Hlp_SYSTEM_Hierarchy_pending;
2016-10-27 22:16:03 +02:00
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Degrees_with_pending_courses;
extern const char *Txt_Degree;
extern const char *Txt_Courses_ABBREVIATION;
extern const char *Txt_There_are_no_degrees_with_requests_for_courses_to_be_confirmed;
char Query[1024];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumDegs;
unsigned NumDeg;
struct Degree Deg;
2015-09-04 19:26:08 +02:00
const char *BgColor;
2014-12-01 23:55:08 +01:00
/***** Get degrees with pending courses *****/
switch (Gbl.Usrs.Me.LoggedRole)
{
2015-04-07 21:44:24 +02:00
case Rol_DEG_ADM:
2014-12-01 23:55:08 +01:00
sprintf (Query,"SELECT courses.DegCod,COUNT(*)"
2015-01-29 01:03:31 +01:00
" FROM admin,courses,degrees"
2017-03-24 01:09:27 +01:00
" WHERE admin.UsrCod=%ld AND admin.Scope='%s'"
2015-01-29 01:03:31 +01:00
" AND admin.Cod=courses.DegCod"
" AND (courses.Status & %u)<>0"
2014-12-01 23:55:08 +01:00
" AND courses.DegCod=degrees.DegCod"
" GROUP BY courses.DegCod ORDER BY degrees.ShortName",
2016-10-27 22:16:03 +02:00
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_DEG],
(unsigned) Crs_STATUS_BIT_PENDING);
2014-12-01 23:55:08 +01:00
break;
2015-04-07 21:44:24 +02:00
case Rol_SYS_ADM:
2014-12-01 23:55:08 +01:00
sprintf (Query,"SELECT courses.DegCod,COUNT(*)"
" FROM courses,degrees"
" WHERE (courses.Status & %u)<>0"
" AND courses.DegCod=degrees.DegCod"
" GROUP BY courses.DegCod ORDER BY degrees.ShortName",
(unsigned) Crs_STATUS_BIT_PENDING);
break;
default: // Forbidden for other users
return;
}
/***** Get degrees *****/
if ((NumDegs = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get degrees with pending courses")))
{
/***** Write heading *****/
2016-11-14 10:05:41 +01:00
Lay_StartRoundFrameTable (NULL,Txt_Degrees_with_pending_courses,
2017-03-27 13:38:10 +02:00
NULL,Hlp_SYSTEM_Hierarchy_pending,2);
2016-11-14 10:05:41 +01:00
fprintf (Gbl.F.Out,"<tr>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2014-12-01 23:55:08 +01:00
"</tr>",
Txt_Degree,
Txt_Courses_ABBREVIATION);
/***** List the degrees *****/
for (NumDeg = 0;
NumDeg < NumDegs;
NumDeg++)
{
/* Get next degree */
row = mysql_fetch_row (mysql_res);
/* Get degree code (row[0]) */
Deg.DegCod = Str_ConvertStrCodToLongCod (row[0]);
2015-09-04 19:26:08 +02:00
BgColor = (Deg.DegCod == Gbl.CurrentDeg.Deg.DegCod) ? "LIGHT_BLUE" :
Gbl.ColorRows[Gbl.RowEvenOdd];
2014-12-01 23:55:08 +01:00
/* Get data of degree */
Deg_GetDataOfDegreeByCod (&Deg);
2015-11-12 01:27:33 +01:00
/* Degree logo and full name */
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<tr>"
2015-11-12 01:27:33 +01:00
"<td class=\"LEFT_MIDDLE %s\">",
2014-12-01 23:55:08 +01:00
BgColor);
2015-11-19 20:04:41 +01:00
Deg_DrawDegreeLogoAndNameWithLink (&Deg,ActSeeCrs,
"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 courses (row[1]) */
2015-09-04 17:10:27 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE %s\">"
2014-12-22 19:59:27 +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
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_INFO,Txt_There_are_no_degrees_with_requests_for_courses_to_be_confirmed);
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2015-11-19 20:04:41 +01:00
/*****************************************************************************/
/******************** Draw degree logo and name with link ********************/
/*****************************************************************************/
void Deg_DrawDegreeLogoAndNameWithLink (struct Degree *Deg,Act_Action_t Action,
const char *ClassLink,const char *ClassLogo)
{
extern const char *Txt_Go_to_X;
/***** Start form *****/
Act_FormGoToStart (Action);
Deg_PutParamDegCod (Deg->DegCod);
/***** Link to action *****/
sprintf (Gbl.Title,Txt_Go_to_X,Deg->FullName);
2016-07-01 17:13:41 +02:00
Act_LinkFormSubmit (Gbl.Title,ClassLink,NULL);
2015-11-19 20:04:41 +01:00
/***** Draw degree logo *****/
2016-10-28 10:03:37 +02:00
Log_DrawLogo (Sco_SCOPE_DEG,Deg->DegCod,Deg->ShrtName,20,ClassLogo,true);
2015-11-19 20:04:41 +01:00
/***** End link *****/
fprintf (Gbl.F.Out,"&nbsp;%s</a>",Deg->FullName);
/***** End form *****/
Act_FormEnd ();
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/****************** Show information of the current degree *******************/
/*****************************************************************************/
void Deg_ShowConfiguration (void)
{
Deg_Configuration (false);
2015-10-06 01:19:21 +02:00
2017-03-30 11:20:06 +02:00
/***** Show help to enrol me *****/
2015-10-06 20:34:49 +02:00
Hlp_ShowHelpWhatWouldYouLikeToDo ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************** Print information of the current degree ******************/
/*****************************************************************************/
void Deg_PrintConfiguration (void)
{
Deg_Configuration (true);
}
/*****************************************************************************/
/******************* Information of the current degree ***********************/
/*****************************************************************************/
static void Deg_Configuration (bool PrintView)
{
2016-11-13 16:55:27 +01:00
extern const char *Hlp_DEGREE_Information;
2015-07-27 21:25:45 +02:00
extern const char *The_ClassForm[The_NUM_THEMES];
2016-10-19 20:43:26 +02:00
extern const char *Txt_Centre;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Degree;
2015-02-04 20:03:23 +01:00
extern const char *Txt_Short_name;
2015-02-04 20:05:54 +01:00
extern const char *Txt_Web;
2015-03-07 18:09:42 +01:00
extern const char *Txt_Shortcut;
2017-01-28 15:58:46 +01:00
extern const char *Txt_STR_LANG_ID[1 + Txt_NUM_LANGUAGES];
2016-10-19 20:43:26 +02:00
extern const char *Txt_Courses;
extern const char *Txt_Courses_of_DEGREE_X;
2014-12-01 23:55:08 +01:00
extern const char *Txt_QR_code;
extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2016-10-19 20:43:26 +02:00
unsigned NumCtr;
2014-12-01 23:55:08 +01:00
bool PutLink = !PrintView && Gbl.CurrentDeg.Deg.WWW[0];
if (Gbl.CurrentDeg.Deg.DegCod > 0)
{
2014-12-08 17:35:48 +01:00
/***** Start frame *****/
2016-11-13 16:55:27 +01:00
Lay_StartRoundFrame (NULL,NULL,
PrintView ? NULL :
Deg_PutIconsToPrintAndUpload,
PrintView ? NULL :
Hlp_DEGREE_Information);
2014-12-08 17:35:48 +01:00
2014-12-01 23:55:08 +01:00
/***** Title *****/
2016-11-23 23:58:46 +01:00
fprintf (Gbl.F.Out,"<div class=\"FRAME_TITLE FRAME_TITLE_BIG\">");
2014-12-01 23:55:08 +01:00
if (PutLink)
fprintf (Gbl.F.Out,"<a href=\"%s\" target=\"_blank\""
2016-11-23 23:58:46 +01:00
" class=\"FRAME_TITLE_BIG\" title=\"%s\">",
2014-12-01 23:55:08 +01:00
Gbl.CurrentDeg.Deg.WWW,
Gbl.CurrentDeg.Deg.FullName);
2015-02-01 20:17:24 +01:00
Log_DrawLogo (Sco_SCOPE_DEG,Gbl.CurrentDeg.Deg.DegCod,
2016-10-28 10:03:37 +02:00
Gbl.CurrentDeg.Deg.ShrtName,64,NULL,true);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<br />%s",
Gbl.CurrentDeg.Deg.FullName);
if (PutLink)
fprintf (Gbl.F.Out,"</a>");
2016-03-18 20:48:24 +01:00
fprintf (Gbl.F.Out,"</div>");
/***** Start table *****/
2017-05-01 10:22:16 +02:00
Lay_StartTableWide (2);
2014-12-01 23:55:08 +01:00
2016-10-19 20:43:26 +02:00
/***** Centre *****/
fprintf (Gbl.F.Out,"<tr>"
2016-12-21 01:29:14 +01:00
"<td class=\"RIGHT_MIDDLE\">"
"<label for=\"OthCtrCod\" class=\"%s\">%s:</label>"
2016-10-19 20:43:26 +02:00
"</td>"
2016-10-24 18:25:12 +02:00
"<td class=\"DAT_N LEFT_MIDDLE\">",
2016-10-19 20:43:26 +02:00
The_ClassForm[Gbl.Prefs.Theme],
Txt_Centre);
if (!PrintView &&
2016-10-23 14:49:03 +02:00
Gbl.Usrs.Me.LoggedRole >= Rol_INS_ADM)
// Only institution admins and system admin can move a degree to another centre
2016-10-19 20:43:26 +02:00
{
/* Get list of centres of the current institution */
Ctr_GetListCentres (Gbl.CurrentIns.Ins.InsCod);
/* Put form to select centre */
Act_FormStart (ActChgDegCtrCfg);
2016-12-21 01:29:14 +01:00
fprintf (Gbl.F.Out,"<select id=\"OthCtrCod\" name=\"OthCtrCod\""
2016-10-20 16:49:42 +02:00
" class=\"INPUT_SHORT_NAME\""
2016-10-19 20:43:26 +02:00
" onchange=\"document.getElementById('%s').submit();\">",
Gbl.Form.Id);
for (NumCtr = 0;
NumCtr < Gbl.Ctrs.Num;
NumCtr++)
fprintf (Gbl.F.Out,"<option value=\"%ld\"%s>%s</option>",
Gbl.Ctrs.Lst[NumCtr].CtrCod,
Gbl.Ctrs.Lst[NumCtr].CtrCod == Gbl.CurrentCtr.Ctr.CtrCod ? " selected=\"selected\"" :
"",
2016-10-28 10:03:37 +02:00
Gbl.Ctrs.Lst[NumCtr].ShrtName);
2016-10-19 20:43:26 +02:00
fprintf (Gbl.F.Out,"</select>");
Act_FormEnd ();
/* Free list of centres */
Ctr_FreeListCentres ();
}
2016-10-20 16:49:42 +02:00
else // I can not move degree to another centre
2016-10-19 20:43:26 +02:00
fprintf (Gbl.F.Out,"%s",Gbl.CurrentCtr.Ctr.FullName);
fprintf (Gbl.F.Out,"</td>"
"</tr>");
2014-12-01 23:55:08 +01:00
/***** Degree full name *****/
fprintf (Gbl.F.Out,"<tr>"
2016-12-21 01:29:14 +01:00
"<td class=\"RIGHT_MIDDLE\">"
"<label for=\"FullName\" class=\"%s\">%s:</label>"
2014-12-22 19:59:27 +01:00
"</td>"
2015-07-31 19:49:21 +02:00
"<td class=\"DAT_N LEFT_MIDDLE\">",
2015-07-27 21:25:45 +02:00
The_ClassForm[Gbl.Prefs.Theme],
2014-12-01 23:55:08 +01:00
Txt_Degree);
2016-10-23 16:04:36 +02:00
if (!PrintView &&
Gbl.Usrs.Me.LoggedRole >= Rol_CTR_ADM)
2016-10-24 18:25:12 +02:00
// Only centre admins, institution admins and system admins
// can edit degree full name
2016-10-23 16:04:36 +02:00
{
/* Form to change degree full name */
Act_FormStart (ActRenDegFulCfg);
2016-12-21 01:29:14 +01:00
fprintf (Gbl.F.Out,"<input type=\"text\""
" id=\"FullName\" name=\"FullName\""
2016-10-23 16:04:36 +02:00
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_FULL_NAME\""
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-08 14:12:33 +01:00
Hie_MAX_CHARS_FULL_NAME,
2016-10-23 16:04:36 +02:00
Gbl.CurrentDeg.Deg.FullName,
Gbl.Form.Id);
Act_FormEnd ();
}
else // I can not edit degree full name
fprintf (Gbl.F.Out,"%s",Gbl.CurrentDeg.Deg.FullName);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>"
2016-10-23 16:04:36 +02:00
"</tr>");
2014-12-01 23:55:08 +01:00
/***** Degree short name *****/
fprintf (Gbl.F.Out,"<tr>"
2016-12-21 01:29:14 +01:00
"<td class=\"RIGHT_MIDDLE\">"
"<label for=\"ShortName\" class=\"%s\">%s:</label>"
2016-10-23 16:15:28 +02:00
"</td>"
"<td class=\"DAT_N LEFT_MIDDLE\">",
2015-07-27 21:25:45 +02:00
The_ClassForm[Gbl.Prefs.Theme],
2016-10-23 16:15:28 +02:00
Txt_Short_name);
if (!PrintView &&
Gbl.Usrs.Me.LoggedRole >= Rol_CTR_ADM)
2016-10-24 18:25:12 +02:00
// Only centre admins, institution admins and system admins
// can edit degree short name
2016-10-23 16:15:28 +02:00
{
/* Form to change degree short name */
Act_FormStart (ActRenDegShoCfg);
2016-12-21 01:29:14 +01:00
fprintf (Gbl.F.Out,"<input type=\"text\""
" id=\"ShortName\" name=\"ShortName\""
2016-10-23 16:15:28 +02:00
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_SHORT_NAME\""
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-08 14:12:33 +01:00
Hie_MAX_CHARS_SHRT_NAME,
2016-10-28 10:03:37 +02:00
Gbl.CurrentDeg.Deg.ShrtName,
2016-10-23 16:15:28 +02:00
Gbl.Form.Id);
Act_FormEnd ();
}
else // I can not edit degree short name
2016-10-28 10:03:37 +02:00
fprintf (Gbl.F.Out,"%s",Gbl.CurrentDeg.Deg.ShrtName);
2016-10-23 16:15:28 +02:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
2014-12-01 23:55:08 +01:00
2015-02-04 20:05:54 +01:00
/***** Degree WWW *****/
2016-10-23 16:37:45 +02:00
fprintf (Gbl.F.Out,"<tr>"
2016-12-21 01:29:14 +01:00
"<td class=\"RIGHT_MIDDLE\">"
"<label for=\"WWW\" class=\"%s\">%s:</label>"
2016-10-23 16:37:45 +02:00
"</td>"
"<td class=\"DAT LEFT_MIDDLE\">",
The_ClassForm[Gbl.Prefs.Theme],
Txt_Web);
if (!PrintView &&
2016-10-24 18:25:12 +02:00
Gbl.Usrs.Me.LoggedRole >= Rol_DEG_ADM)
// Only degree admins, centre admins, institution admins
// and system admins can change degree WWW
2015-02-04 20:05:54 +01:00
{
2016-10-23 16:37:45 +02:00
/* Form to change degree WWW */
Act_FormStart (ActChgDegWWWCfg);
2016-12-21 01:29:14 +01:00
fprintf (Gbl.F.Out,"<input type=\"url\" id=\"WWW\" name=\"WWW\""
2016-10-23 16:37:45 +02:00
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_WWW\""
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-07 01:56:41 +01:00
Cns_MAX_CHARS_WWW,
2016-10-23 16:37:45 +02:00
Gbl.CurrentDeg.Deg.WWW,
Gbl.Form.Id);
Act_FormEnd ();
}
else // I can not change degree WWW
2017-03-04 01:27:54 +01:00
fprintf (Gbl.F.Out,"<div class=\"EXTERNAL_WWW_LONG\">"
2016-10-22 19:26:54 +02:00
"<a href=\"%s\" target=\"_blank\" class=\"DAT\">"
"%s"
2015-02-04 20:05:54 +01:00
"</a>"
2016-10-22 19:26:54 +02:00
"</div>",
Gbl.CurrentDeg.Deg.WWW,
2015-02-04 20:05:54 +01:00
Gbl.CurrentDeg.Deg.WWW);
2016-10-23 16:37:45 +02:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
2015-02-04 20:05:54 +01:00
/***** Shortcut to the degree *****/
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<tr>"
2015-07-27 21:25:45 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"%s:"
"</td>"
2015-07-31 19:49:21 +02:00
"<td class=\"DAT LEFT_MIDDLE\">"
2015-03-07 21:08:44 +01:00
"<a href=\"%s/%s?deg=%ld\" class=\"DAT\" target=\"_blank\">"
"%s/%s?deg=%ld"
2014-12-22 19:59:27 +01:00
"</a>"
2014-12-01 23:55:08 +01:00
"</td>"
"</tr>",
2015-07-27 21:25:45 +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],
2015-11-21 20:23:28 +01:00
Gbl.CurrentDeg.Deg.DegCod,
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],
2015-11-21 20:23:28 +01:00
Gbl.CurrentDeg.Deg.DegCod);
2014-12-01 23:55:08 +01:00
if (PrintView)
{
/***** QR code with link to the degree *****/
fprintf (Gbl.F.Out,"<tr>"
2015-07-27 21:25:45 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"%s:"
"</td>"
2015-07-31 19:49:21 +02:00
"<td class=\"DAT LEFT_MIDDLE\">",
2015-07-27 21:25:45 +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,"deg",Gbl.CurrentDeg.Deg.DegCod);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
}
else
{
/***** Number of courses *****/
fprintf (Gbl.F.Out,"<tr>"
2015-07-27 21:25:45 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"%s:"
"</td>"
2016-05-30 19:36:49 +02:00
"<td class=\"LEFT_MIDDLE\">",
2015-07-27 21:25:45 +02:00
The_ClassForm[Gbl.Prefs.Theme],
2016-05-30 19:36:49 +02:00
Txt_Courses);
/* Form to go to see courses of this degree */
Act_FormGoToStart (ActSeeCrs);
Deg_PutParamDegCod (Gbl.CurrentDeg.Deg.DegCod);
2016-05-30 19:52:46 +02:00
sprintf (Gbl.Title,Txt_Courses_of_DEGREE_X,
2016-10-28 10:03:37 +02:00
Gbl.CurrentDeg.Deg.ShrtName);
2016-07-01 17:13:41 +02:00
Act_LinkFormSubmit (Gbl.Title,"DAT",NULL);
2016-05-30 19:36:49 +02:00
fprintf (Gbl.F.Out,"%u</a>",
2016-05-30 19:16:43 +02:00
Crs_GetNumCrssInDeg (Gbl.CurrentDeg.Deg.DegCod));
2016-05-30 19:36:49 +02:00
Act_FormEnd ();
fprintf (Gbl.F.Out,"</td>"
"</tr>");
2014-12-01 23:55:08 +01:00
/***** Number of teachers *****/
fprintf (Gbl.F.Out,"<tr>"
2015-07-27 21:25:45 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"%s:"
"</td>"
2015-07-31 19:49:21 +02:00
"<td class=\"DAT LEFT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"%u"
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>",
2015-07-27 21:25:45 +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_GetNumUsrsInCrssOfDeg (Rol_TEACHER,Gbl.CurrentDeg.Deg.DegCod));
2014-12-01 23:55:08 +01:00
/***** Number of students *****/
fprintf (Gbl.F.Out,"<tr>"
2015-07-27 21:25:45 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"%s:"
"</td>"
2015-07-31 19:49:21 +02:00
"<td class=\"DAT LEFT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"%u"
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>",
2015-07-27 21:25:45 +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_GetNumUsrsInCrssOfDeg (Rol_STUDENT,Gbl.CurrentDeg.Deg.DegCod));
2014-12-01 23:55:08 +01:00
}
2014-12-08 17:35:48 +01:00
2016-03-18 20:48:24 +01:00
/***** End table *****/
2017-05-01 10:22:16 +02:00
Lay_EndTable ();
2016-03-18 20:48:24 +01:00
2014-12-08 17:35:48 +01:00
/***** End frame *****/
2016-03-18 20:48:24 +01:00
Lay_EndRoundFrame ();
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
2016-05-05 20:16:28 +02:00
/************ Put contextual icons in configuration of a degree **************/
2016-03-18 20:48:24 +01:00
/*****************************************************************************/
2016-05-05 20:16:28 +02:00
static void Deg_PutIconsToPrintAndUpload (void)
2016-03-18 20:48:24 +01:00
{
2016-05-05 20:16:28 +02:00
/***** Link to print info about degree *****/
2017-04-30 23:48:48 +02:00
Lay_PutContextualIconToPrint (ActPrnDegInf,NULL);
2016-05-05 20:16:28 +02:00
if (Gbl.Usrs.Me.LoggedRole >= Rol_DEG_ADM)
2016-10-24 18:25:12 +02:00
// Only degree admins, centre admins, institution admins and system admins
// have permission to upload logo of the degree
2016-05-05 20:16:28 +02:00
/***** Link to upload logo of degree *****/
Log_PutIconToChangeLogo (Sco_SCOPE_DEG);
2016-03-18 20:48:24 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/*************************** Write selector of degree ************************/
/*****************************************************************************/
2016-11-14 16:47:46 +01:00
void Deg_WriteSelectorOfDegree (void)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_Degree;
2017-03-11 20:59:09 +01:00
char Query[256];
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumDegs;
unsigned NumDeg;
long DegCod;
/***** Start form *****/
2015-07-25 20:20:07 +02:00
Act_FormGoToStart (ActSeeCrs);
2016-12-20 10:03:00 +01:00
fprintf (Gbl.F.Out,"<select id=\"deg\" name=\"deg\" style=\"width:175px;\"");
2014-12-01 23:55:08 +01:00
if (Gbl.CurrentCtr.Ctr.CtrCod > 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\"");
2016-12-27 16:45:37 +01:00
fprintf (Gbl.F.Out,">"
"<option value=\"\"");
2014-12-01 23:55:08 +01:00
if (Gbl.CurrentDeg.Deg.DegCod < 0)
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out," disabled=\"disabled\">[%s]</option>",
Txt_Degree);
if (Gbl.CurrentCtr.Ctr.CtrCod > 0)
{
/***** Get degrees belonging to the current centre from database *****/
sprintf (Query,"SELECT DegCod,ShortName FROM degrees"
2017-03-24 01:09:27 +01:00
" WHERE CtrCod=%ld ORDER BY ShortName",
2014-12-01 23:55:08 +01:00
Gbl.CurrentCtr.Ctr.CtrCod);
NumDegs = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get degrees of a centre");
/***** Get degrees of this centre *****/
for (NumDeg = 0;
NumDeg < NumDegs;
NumDeg++)
{
/* Get next degree */
row = mysql_fetch_row (mysql_res);
/* Get degree code (row[0]) */
if ((DegCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
2015-07-25 20:20:07 +02:00
Lay_ShowErrorAndExit ("Wrong degree.");
2014-12-01 23:55:08 +01:00
/* Write option */
fprintf (Gbl.F.Out,"<option value=\"%ld\"",DegCod);
if (Gbl.CurrentDeg.Deg.DegCod > 0 &&
(DegCod == Gbl.CurrentDeg.Deg.DegCod))
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
}
/*****************************************************************************/
/************* Show the degrees belonging to the current centre **************/
/*****************************************************************************/
void Deg_ShowDegsOfCurrentCtr (void)
{
if (Gbl.CurrentCtr.Ctr.CtrCod > 0)
{
/***** Get list of centres and degrees *****/
Ctr_GetListCentres (Gbl.CurrentIns.Ins.InsCod);
Deg_GetListDegsOfCurrentCtr ();
/***** Write menu to select country, institution and centre *****/
2016-11-14 17:26:32 +01:00
Hie_WriteMenuHierarchy ();
2014-12-01 23:55:08 +01:00
/***** Show list of degrees *****/
Deg_ListDegrees ();
/***** Free list of degrees and centres *****/
2016-10-20 00:57:00 +02:00
Deg_FreeListDegs (&Gbl.CurrentCtr.Ctr.Degs);
2014-12-01 23:55:08 +01:00
Ctr_FreeListCentres ();
}
}
/*****************************************************************************/
/********************* List current degrees for edition **********************/
/*****************************************************************************/
static void Deg_ListDegreesForEdition (void)
{
extern const char *Txt_DEGREE_STATUS[Deg_NUM_STATUS_TXT];
unsigned NumDeg;
struct DegreeType *DegTyp;
struct Degree *Deg;
unsigned NumDegTyp;
2017-03-07 01:56:41 +01:00
char WWW[Cns_MAX_BYTES_WWW + 1];
2014-12-01 23:55:08 +01:00
struct UsrData UsrDat;
bool ICanEdit;
Deg_StatusTxt_t StatusTxt;
2016-04-16 15:05:18 +02:00
unsigned NumCrss;
2014-12-01 23:55:08 +01:00
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** Write heading *****/
2017-05-01 10:22:16 +02:00
Lay_StartTableWide (2);
2014-12-01 23:55:08 +01:00
Deg_PutHeadDegreesForEdition ();
/***** List the degrees *****/
for (NumDeg = 0;
2016-10-20 00:57:00 +02:00
NumDeg < Gbl.CurrentCtr.Ctr.Degs.Num;
2014-12-01 23:55:08 +01:00
NumDeg++)
{
2016-10-20 00:57:00 +02:00
Deg = &(Gbl.CurrentCtr.Ctr.Degs.Lst[NumDeg]);
2014-12-01 23:55:08 +01:00
2016-04-16 15:05:18 +02:00
NumCrss = Crs_GetNumCrssInDeg (Deg->DegCod);
2016-11-06 23:56:43 +01:00
ICanEdit = Deg_CheckIfICanEditADegree (Deg);
2014-12-01 23:55:08 +01:00
/* Put icon to remove degree */
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"BM\">");
2016-04-16 15:05:18 +02:00
if (NumCrss || // Degree has courses ==> deletion forbidden
2014-12-01 23:55:08 +01:00
!ICanEdit)
2015-07-22 19:20:30 +02:00
Lay_PutIconRemovalNotAllowed ();
2014-12-01 23:55:08 +01:00
else
{
Act_FormStart (ActRemDeg);
Deg_PutParamOtherDegCod (Deg->DegCod);
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>");
/* Degree code */
2015-12-05 21:15:30 +01:00
fprintf (Gbl.F.Out,"<td class=\"DAT CODE\">"
2014-12-22 19:59:27 +01:00
"%ld"
"</td>",
2014-12-01 23:55:08 +01:00
Deg->DegCod);
/* Degree logo */
2015-12-05 13:37:23 +01:00
fprintf (Gbl.F.Out,"<td title=\"%s LEFT_MIDDLE\" style=\"width:25px;\">",
2014-12-01 23:55:08 +01:00
Deg->FullName);
2016-10-28 10:03:37 +02:00
Log_DrawLogo (Sco_SCOPE_DEG,Deg->DegCod,Deg->ShrtName,20,NULL,true);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>");
/* Degree short name */
2015-07-31 19:49:21 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_MIDDLE\">");
2014-12-01 23:55:08 +01:00
if (ICanEdit)
{
Act_FormStart (ActRenDegSho);
Deg_PutParamOtherDegCod (Deg->DegCod);
2015-10-22 14:49:48 +02:00
fprintf (Gbl.F.Out,"<input type=\"text\" name=\"ShortName\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_SHORT_NAME\""
2015-10-22 14:49:48 +02:00
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-08 14:12:33 +01:00
Hie_MAX_CHARS_SHRT_NAME,Deg->ShrtName,Gbl.Form.Id);
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
2014-12-01 23:55:08 +01:00
}
else
2016-10-28 10:03:37 +02:00
fprintf (Gbl.F.Out,"%s",Deg->ShrtName);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>");
/* Degree full name */
2015-07-31 19:49:21 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_MIDDLE\">");
2014-12-01 23:55:08 +01:00
if (ICanEdit)
{
Act_FormStart (ActRenDegFul);
Deg_PutParamOtherDegCod (Deg->DegCod);
2015-10-22 14:49:48 +02:00
fprintf (Gbl.F.Out,"<input type=\"text\" name=\"FullName\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_FULL_NAME\""
2015-10-22 14:49:48 +02:00
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-08 14:12:33 +01:00
Hie_MAX_CHARS_FULL_NAME,Deg->FullName,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",Deg->FullName);
fprintf (Gbl.F.Out,"</td>");
/* Degree type */
2015-07-31 19:49:21 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_MIDDLE\">");
2014-12-01 23:55:08 +01:00
if (ICanEdit)
{
Act_FormStart (ActChgDegTyp);
Deg_PutParamOtherDegCod (Deg->DegCod);
2015-09-06 19:51:06 +02:00
fprintf (Gbl.F.Out,"<select name=\"OthDegTypCod\""
2015-09-28 18:28:29 +02:00
" style=\"width:62px;\""
2015-10-22 14:49:48 +02:00
" onchange=\"document.getElementById('%s').submit();\">",
2016-01-14 10:31:09 +01:00
Gbl.Form.Id);
2014-12-01 23:55:08 +01:00
for (NumDegTyp = 0;
NumDegTyp < Gbl.Degs.DegTypes.Num;
NumDegTyp++)
{
DegTyp = &Gbl.Degs.DegTypes.Lst[NumDegTyp];
fprintf (Gbl.F.Out,"<option value=\"%ld\"%s>%s</option>",
DegTyp->DegTypCod,
(DegTyp->DegTypCod == Deg->DegTypCod) ? " selected=\"selected\"" :
"",
DegTyp->DegTypName);
}
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</select>");
Act_FormEnd ();
2014-12-01 23:55:08 +01:00
}
else
for (NumDegTyp = 0;
NumDegTyp < Gbl.Degs.DegTypes.Num;
NumDegTyp++)
if (Gbl.Degs.DegTypes.Lst[NumDegTyp].DegTypCod == Deg->DegTypCod)
fprintf (Gbl.F.Out,"%s",Gbl.Degs.DegTypes.Lst[NumDegTyp].DegTypName);
fprintf (Gbl.F.Out,"</td>");
/* Degree WWW */
2015-07-31 19:49:21 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_MIDDLE\">");
2014-12-01 23:55:08 +01:00
if (ICanEdit)
{
Act_FormStart (ActChgDegWWW);
Deg_PutParamOtherDegCod (Deg->DegCod);
2016-11-20 14:32:15 +01:00
fprintf (Gbl.F.Out,"<input type=\"url\" name=\"WWW\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_WWW\""
2015-10-22 14:49:48 +02:00
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-07 01:56:41 +01:00
Cns_MAX_CHARS_WWW,Deg->WWW,Gbl.Form.Id);
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
2014-12-01 23:55:08 +01:00
}
else
{
2017-01-17 03:10:43 +01:00
Str_Copy (WWW,Deg->WWW,
2017-03-07 01:56:41 +01:00
Cns_MAX_BYTES_WWW);
2017-03-04 01:27:54 +01:00
fprintf (Gbl.F.Out,"<div class=\"EXTERNAL_WWW_SHORT\">"
"<a href=\"%s\" target=\"_blank\""
2017-01-17 03:10:43 +01:00
" class=\"DAT\" title=\"%s\">"
"%s"
2017-03-04 01:27:54 +01:00
"</a>"
"</div>",
2014-12-01 23:55:08 +01:00
Deg->WWW,Deg->WWW,WWW);
}
fprintf (Gbl.F.Out,"</td>");
/* Current number of courses in this degree */
2015-07-31 19:49:21 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"%u"
"</td>",
2016-04-16 15:05:18 +02:00
NumCrss);
2014-12-01 23:55:08 +01:00
2017-03-17 00:46:28 +01:00
/* Degree requester */
UsrDat.UsrCod = Deg->RequesterUsrCod;
Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat);
2017-05-02 01:05:23 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT INPUT_REQUESTER LEFT_TOP\">");
2017-05-02 01:16:06 +02:00
Msg_WriteMsgAuthor (&UsrDat,true,NULL);
2017-05-01 21:17:38 +02:00
fprintf (Gbl.F.Out,"</td>");
2017-03-17 00:46:28 +01:00
2014-12-01 23:55:08 +01:00
/* Degree status */
StatusTxt = Deg_GetStatusTxtFromStatusBits (Deg->Status);
2017-03-17 00:46:28 +01:00
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_MIDDLE\">");
2015-04-07 21:44:24 +02:00
if (Gbl.Usrs.Me.LoggedRole >= Rol_CTR_ADM &&
2014-12-01 23:55:08 +01:00
StatusTxt == Deg_STATUS_PENDING)
{
Act_FormStart (ActChgDegSta);
Deg_PutParamOtherDegCod (Deg->DegCod);
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) Deg_GetStatusBitsFromStatusTxt (Deg_STATUS_PENDING),
Txt_DEGREE_STATUS[Deg_STATUS_PENDING],
(unsigned) Deg_GetStatusBitsFromStatusTxt (Deg_STATUS_ACTIVE),
Txt_DEGREE_STATUS[Deg_STATUS_ACTIVE]);
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
2014-12-01 23:55:08 +01:00
}
2017-03-17 00:46:28 +01:00
else if (StatusTxt != Deg_STATUS_ACTIVE) // If active ==> do not show anything
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"%s",Txt_DEGREE_STATUS[StatusTxt]);
2017-03-17 00:46:28 +01:00
fprintf (Gbl.F.Out,"</td>"
2014-12-01 23:55:08 +01:00
"</tr>");
}
/***** End table *****/
2017-05-01 10:22:16 +02:00
Lay_EndTable ();
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. a degree *******************/
/*****************************************************************************/
2016-11-06 23:56:43 +01:00
static bool Deg_CheckIfICanEditADegree (struct Degree *Deg)
2014-12-01 23:55:08 +01:00
{
2015-04-07 21:44:24 +02:00
return (bool) (Gbl.Usrs.Me.LoggedRole >= Rol_CTR_ADM || // I am a centre administrator or higher
2014-12-01 23:55:08 +01:00
((Deg->Status & Deg_STATUS_BIT_PENDING) != 0 && // Degree is not yet activated
Gbl.Usrs.Me.UsrDat.UsrCod == Deg->RequesterUsrCod)); // I am the requester
}
/*****************************************************************************/
/******************* Set StatusTxt depending on status bits ******************/
/*****************************************************************************/
// Deg_STATUS_UNKNOWN = 0 // Other
// Deg_STATUS_ACTIVE = 1 // 00 (Status == 0)
// Deg_STATUS_PENDING = 2 // 01 (Status == Deg_STATUS_BIT_PENDING)
// Deg_STATUS_REMOVED = 3 // 1- (Status & Deg_STATUS_BIT_REMOVED)
static Deg_StatusTxt_t Deg_GetStatusTxtFromStatusBits (Deg_Status_t Status)
{
if (Status == 0)
return Deg_STATUS_ACTIVE;
if (Status == Deg_STATUS_BIT_PENDING)
return Deg_STATUS_PENDING;
if (Status & Deg_STATUS_BIT_REMOVED)
return Deg_STATUS_REMOVED;
return Deg_STATUS_UNKNOWN;
}
/*****************************************************************************/
/******************* Set status bits depending on StatusTxt ******************/
/*****************************************************************************/
// Deg_STATUS_UNKNOWN = 0 // Other
// Deg_STATUS_ACTIVE = 1 // 00 (Status == 0)
// Deg_STATUS_PENDING = 2 // 01 (Status == Deg_STATUS_BIT_PENDING)
// Deg_STATUS_REMOVED = 3 // 1- (Status & Deg_STATUS_BIT_REMOVED)
static Deg_Status_t Deg_GetStatusBitsFromStatusTxt (Deg_StatusTxt_t StatusTxt)
{
switch (StatusTxt)
{
case Deg_STATUS_UNKNOWN:
case Deg_STATUS_ACTIVE:
return (Deg_Status_t) 0;
case Deg_STATUS_PENDING:
return Deg_STATUS_BIT_PENDING;
case Deg_STATUS_REMOVED:
return Deg_STATUS_BIT_REMOVED;
}
return (Deg_Status_t) 0;
}
/*****************************************************************************/
/*********************** Put a form to create a new degree *******************/
/*****************************************************************************/
static void Deg_PutFormToCreateDegree (void)
{
2017-04-30 02:56:25 +02:00
extern const char *Txt_New_degree;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Create_degree;
struct Degree *Deg;
struct DegreeType *DegTyp;
unsigned NumDegTyp;
2017-03-26 17:32:19 +02:00
/***** Degree data *****/
Deg = &Gbl.Degs.EditingDeg;
2014-12-01 23:55:08 +01:00
/***** Start form *****/
2015-04-07 21:44:24 +02:00
if (Gbl.Usrs.Me.LoggedRole >= Rol_CTR_ADM)
2014-12-01 23:55:08 +01:00
Act_FormStart (ActNewDeg);
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 (ActReqDeg);
else
Lay_ShowErrorAndExit ("You can not edit degrees.");
2017-04-30 02:56:25 +02:00
/***** Start frame *****/
Lay_StartRoundFrameTable (NULL,Txt_New_degree,NULL,NULL,2);
2014-12-01 23:55:08 +01:00
2017-03-26 17:32:19 +02:00
/***** Table head *****/
2014-12-01 23:55:08 +01:00
Deg_PutHeadDegreesForEdition ();
2017-04-30 02:56:25 +02:00
/***** Column to remove degree, disabled here *****/
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<tr>"
2017-04-30 02:56:25 +02:00
"<td class=\"BM\"></td>");
2014-12-01 23:55:08 +01:00
/***** Degree 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
/***** Degree logo *****/
2016-10-20 21:09:01 +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_DEG,-1L,"",20,NULL,true);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>");
/***** Degree short name *****/
2015-07-31 19:49:21 +02: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\""
2016-11-19 02:54:56 +01:00
" class=\"INPUT_SHORT_NAME\""
" required=\"required\" />"
2014-12-01 23:55:08 +01:00
"</td>",
2017-03-08 14:12:33 +01:00
Hie_MAX_CHARS_SHRT_NAME,Deg->ShrtName);
2014-12-01 23:55:08 +01:00
/***** Degree full name *****/
2015-07-31 19:49:21 +02: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\""
2016-11-19 02:54:56 +01:00
" class=\"INPUT_FULL_NAME\""
" required=\"required\" />"
2014-12-01 23:55:08 +01:00
"</td>",
2017-03-08 14:12:33 +01:00
Hie_MAX_CHARS_FULL_NAME,Deg->FullName);
2014-12-01 23:55:08 +01:00
/***** Degree type *****/
2015-07-31 19:49:21 +02:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE\">"
2015-09-28 18:28:29 +02:00
"<select name=\"OthDegTypCod\" style=\"width:62px;\">");
2014-12-01 23:55:08 +01:00
for (NumDegTyp = 0;
NumDegTyp < Gbl.Degs.DegTypes.Num;
NumDegTyp++)
{
DegTyp = &Gbl.Degs.DegTypes.Lst[NumDegTyp];
fprintf (Gbl.F.Out,"<option value=\"%ld\"%s>%s</option>",
DegTyp->DegTypCod,
DegTyp->DegTypCod == Deg->DegTypCod ? " selected=\"selected\"" :
"",
DegTyp->DegTypName);
}
fprintf (Gbl.F.Out,"</select>"
"</td>");
/***** Degree WWW *****/
2015-07-31 19:49:21 +02:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE\">"
2016-11-20 14:32:15 +01:00
"<input type=\"url\" name=\"WWW\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
2016-11-19 02:54:56 +01:00
" class=\"INPUT_WWW\""
" required=\"required\" />"
2014-12-01 23:55:08 +01:00
"</td>",
2017-03-07 01:56:41 +01:00
Cns_MAX_CHARS_WWW,Deg->WWW);
2014-12-01 23:55:08 +01:00
/***** Current number of courses in this degree *****/
2015-07-31 19:49:21 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"0"
"</td>");
2014-12-01 23:55:08 +01:00
/***** Degree requester *****/
2017-05-02 01:05:23 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT INPUT_REQUESTER LEFT_TOP\">");
2017-05-02 01:16:06 +02:00
Msg_WriteMsgAuthor (&Gbl.Usrs.Me.UsrDat,true,NULL);
2017-05-01 21:17:38 +02:00
fprintf (Gbl.F.Out,"</td>");
2017-03-17 00:46:28 +01:00
/***** Degree status *****/
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_MIDDLE\">"
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>");
2017-03-26 17:32:19 +02:00
/***** End table *****/
fprintf (Gbl.F.Out,"</table>");
2017-04-30 02:56:25 +02:00
/***** Send button and end of frame *****/
Lay_EndRoundFrameTableWithButton (Lay_CREATE_BUTTON,Txt_Create_degree);
2014-12-01 23:55:08 +01:00
2015-04-11 23:46:21 +02:00
/***** End form *****/
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Write header with fields of a degree *******************/
/*****************************************************************************/
static void Deg_PutHeadDegreesForSeeing (void)
{
extern const char *Txt_Degree;
2015-12-05 21:15:30 +01:00
extern const char *Txt_Type;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Courses_ABBREVIATION;
fprintf (Gbl.F.Out,"<tr>"
"<th class=\"BM\"></th>"
"<th></th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"</th>"
2014-12-01 23:55:08 +01:00
"</tr>",
Txt_Degree,
2015-12-05 21:15:30 +01:00
Txt_Type,
2017-03-17 00:46:28 +01:00
Txt_Courses_ABBREVIATION);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Write header with fields of a degree *******************/
/*****************************************************************************/
static void Deg_PutHeadDegreesForEdition (void)
{
extern const char *Txt_Code;
2016-03-02 19:29:56 +01:00
extern const char *Txt_Short_name_of_the_degree;
extern const char *Txt_Full_name_of_the_degree;
2015-12-05 21:15:30 +01:00
extern const char *Txt_Type;
2014-12-01 23:55:08 +01:00
extern const char *Txt_WWW;
extern const char *Txt_Courses_ABBREVIATION;
extern const char *Txt_Requester;
fprintf (Gbl.F.Out,"<tr>"
"<th class=\"BM\"></th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-26 22:11:03 +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-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"</th>"
2014-12-01 23:55:08 +01:00
"</tr>",
Txt_Code,
2016-03-02 19:29:56 +01:00
Txt_Short_name_of_the_degree,
Txt_Full_name_of_the_degree,
2015-12-05 21:15:30 +01:00
Txt_Type,
2014-12-01 23:55:08 +01:00
Txt_WWW,
Txt_Courses_ABBREVIATION,
Txt_Requester);
}
/*****************************************************************************/
/******************** Convert string to year of a degree *********************/
/*****************************************************************************/
unsigned Deg_ConvStrToYear (const char *StrYear)
{
int Year;
if (sscanf (StrYear,"%d",&Year) != 1)
return 0;
if (Year < 0)
return 0;
if (Year > Deg_MAX_YEARS_PER_DEGREE)
return Deg_MAX_YEARS_PER_DEGREE;
return (unsigned) Year;
}
/*****************************************************************************/
/***************************** Create a new degree ***************************/
/*****************************************************************************/
2017-05-11 20:55:04 +02:00
// Gbl.Degs.EditingDeg must hold the degree beeing edited
2014-12-01 23:55:08 +01:00
2017-05-11 20:04:38 +02:00
static void Deg_CreateDegree (unsigned Status)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_Created_new_degree_X;
2017-01-28 15:58:46 +01:00
char Query[512 +
2017-03-08 14:12:33 +01:00
Hie_MAX_BYTES_SHRT_NAME +
Hie_MAX_BYTES_FULL_NAME +
2017-03-07 01:56:41 +01:00
Cns_MAX_BYTES_WWW];
2014-12-01 23:55:08 +01:00
/***** Create a new degree *****/
2017-05-11 20:04:38 +02:00
sprintf (Query,"INSERT INTO degrees (CtrCod,DegTypCod,Status,"
"RequesterUsrCod,ShortName,FullName,WWW)"
" VALUES (%ld,%ld,%u,%ld,'%s','%s','%s')",
Gbl.Degs.EditingDeg.CtrCod,
Gbl.Degs.EditingDeg.DegTypCod,
Status,
Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Degs.EditingDeg.ShrtName,
Gbl.Degs.EditingDeg.FullName,
Gbl.Degs.EditingDeg.WWW);
Gbl.Degs.EditingDeg.DegCod = DB_QueryINSERTandReturnCode (Query,"can not create a new degree");
/***** Write message to show the change made
and put button to go to degree created *****/
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_SUCCESS;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_Created_new_degree_X,
2017-05-11 20:04:38 +02:00
Gbl.Degs.EditingDeg.FullName);
Deg_ShowAlertAndButtonToGoToDeg ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************** List degrees belonging to the current centre *****************/
/*****************************************************************************/
static void Deg_ListDegrees (void)
{
2016-11-13 15:04:02 +01:00
extern const char *Hlp_CENTRE_Degrees;
2016-03-20 13:18:56 +01:00
extern const char *Txt_Degrees_of_CENTRE_X;
extern const char *Txt_No_degrees;
2016-03-16 13:23:10 +01:00
extern const char *Txt_Create_another_degree;
2015-10-06 01:19:21 +02:00
extern const char *Txt_Create_degree;
2016-03-20 13:18:56 +01:00
unsigned NumDeg;
2014-12-01 23:55:08 +01:00
2016-03-20 13:18:56 +01:00
/***** Start frame *****/
2016-10-28 10:03:37 +02:00
sprintf (Gbl.Title,Txt_Degrees_of_CENTRE_X,Gbl.CurrentCtr.Ctr.ShrtName);
2016-11-13 15:04:02 +01:00
Lay_StartRoundFrame (NULL,Gbl.Title,
Deg_PutIconsListDegrees,Hlp_CENTRE_Degrees);
2016-03-20 13:18:56 +01:00
2016-10-20 00:57:00 +02:00
if (Gbl.CurrentCtr.Ctr.Degs.Num) // There are degrees in the current centre
2016-03-20 13:18:56 +01:00
{
2017-04-30 14:03:45 +02:00
/***** Write heading *****/
2017-05-01 12:36:24 +02:00
Lay_StartTableWideMargin (2);
2016-03-20 13:18:56 +01:00
Deg_PutHeadDegreesForSeeing ();
/***** List the degrees *****/
for (NumDeg = 0;
2016-10-20 00:57:00 +02:00
NumDeg < Gbl.CurrentCtr.Ctr.Degs.Num;
2016-03-20 13:18:56 +01:00
NumDeg++)
2016-10-20 00:57:00 +02:00
Deg_ListOneDegreeForSeeing (&(Gbl.CurrentCtr.Ctr.Degs.Lst[NumDeg]),NumDeg + 1);
2016-03-20 13:18:56 +01:00
/***** End table *****/
2017-05-01 12:36:24 +02:00
Lay_EndTable ();
2016-03-20 13:18:56 +01:00
}
else // No degrees created in the current centre
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_INFO,Txt_No_degrees);
2016-03-16 12:59:57 +01:00
2016-03-20 13:18:56 +01:00
/***** Button to create degree *****/
2016-11-07 00:03:50 +01:00
if (Deg_CheckIfICanCreateDegrees ())
2016-03-16 12:59:57 +01:00
{
Act_FormStart (ActEdiDeg);
2016-10-20 00:57:00 +02:00
Lay_PutConfirmButton (Gbl.CurrentCtr.Ctr.Degs.Num ? Txt_Create_another_degree :
Txt_Create_degree);
2016-03-16 12:59:57 +01:00
Act_FormEnd ();
2015-10-06 01:19:21 +02:00
}
2016-03-20 13:18:56 +01:00
/***** End frame *****/
Lay_EndRoundFrame ();
}
2016-11-06 23:56:43 +01:00
/*****************************************************************************/
2016-11-07 00:03:50 +01:00
/********************** Check if I can create degrees ************************/
2016-11-06 23:56:43 +01:00
/*****************************************************************************/
2016-11-07 00:03:50 +01:00
static bool Deg_CheckIfICanCreateDegrees (void)
2016-11-06 23:56:43 +01:00
{
return (bool) (Gbl.Usrs.Me.LoggedRole >= Rol__GUEST_);
}
/*****************************************************************************/
/***************** Put contextual icons in list of degrees *******************/
/*****************************************************************************/
static void Deg_PutIconsListDegrees (void)
{
/***** Put icon to edit degrees *****/
2016-11-07 00:03:50 +01:00
if (Deg_CheckIfICanCreateDegrees ())
2016-11-06 23:56:43 +01:00
Deg_PutIconToEditDegrees ();
2017-03-26 16:47:02 +02:00
/***** Put icon to view degree types *****/
DT_PutIconToViewDegreeTypes ();
2016-11-06 23:56:43 +01:00
/***** Put icon to show a figure *****/
Gbl.Stat.FigureType = Sta_HIERARCHY;
Sta_PutIconToShowFigure ();
}
2016-03-20 13:18:56 +01:00
/*****************************************************************************/
/********************** Put link (form) to edit degrees **********************/
/*****************************************************************************/
static void Deg_PutIconToEditDegrees (void)
{
2017-04-30 23:48:48 +02:00
Lay_PutContextualIconToEdit (ActEdiDeg,NULL);
2016-03-20 13:18:56 +01:00
}
/*****************************************************************************/
/************************ List one degree for seeing *************************/
/*****************************************************************************/
static void Deg_ListOneDegreeForSeeing (struct Degree *Deg,unsigned NumDeg)
{
extern const char *Txt_DEGREE_With_courses;
extern const char *Txt_DEGREE_Without_courses;
extern const char *Txt_DEGREE_STATUS[Deg_NUM_STATUS_TXT];
struct DegreeType DegTyp;
const char *TxtClassNormal;
const char *TxtClassStrong;
const char *BgColor;
2017-03-17 00:46:28 +01:00
Deg_StatusTxt_t StatusTxt;
2016-04-16 15:05:18 +02:00
unsigned NumCrss;
/***** Get number of courses in this degree *****/
NumCrss = Crs_GetNumCrssInDeg (Deg->DegCod);
2016-03-20 13:18:56 +01:00
/***** Get data of type of degree of this degree *****/
DegTyp.DegTypCod = Deg->DegTypCod;
2016-03-20 22:31:57 +01:00
if (!DT_GetDataOfDegreeTypeByCod (&DegTyp))
2016-03-20 13:18:56 +01:00
Lay_ShowErrorAndExit ("Code of type of degree not found.");
if (Deg->Status & Deg_STATUS_BIT_PENDING)
{
TxtClassNormal = "DAT_LIGHT";
TxtClassStrong = "DAT_LIGHT";
}
else
{
TxtClassNormal = "DAT";
TxtClassStrong = "DAT_N";
}
BgColor = (Deg->DegCod == Gbl.CurrentDeg.Deg.DegCod) ? "LIGHT_BLUE" :
Gbl.ColorRows[Gbl.RowEvenOdd];
/***** Put green tip if degree has courses *****/
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"CENTER_MIDDLE %s\">"
"<img src=\"%s/%s16x16.gif\""
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />"
2016-03-20 13:18:56 +01:00
"</td>",
BgColor,
Gbl.Prefs.IconsURL,
2016-04-16 15:05:18 +02:00
NumCrss ? "ok_green" :
"tr",
NumCrss ? Txt_DEGREE_With_courses :
Txt_DEGREE_Without_courses,
NumCrss ? Txt_DEGREE_With_courses :
Txt_DEGREE_Without_courses);
2016-03-20 13:18:56 +01:00
/***** Number of degree in this list *****/
fprintf (Gbl.F.Out,"<td class=\"%s RIGHT_MIDDLE %s\">"
"%u"
"</td>",
TxtClassNormal,BgColor,
NumDeg);
/***** Degree logo and name *****/
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE %s\">",BgColor);
Deg_DrawDegreeLogoAndNameWithLink (Deg,ActSeeCrs,
TxtClassStrong,"CENTER_MIDDLE");
fprintf (Gbl.F.Out,"</td>");
/***** Type of degree *****/
fprintf (Gbl.F.Out,"<td class=\"%s LEFT_MIDDLE %s\">"
"%s"
"</td>",
TxtClassNormal,BgColor,DegTyp.DegTypName);
/***** Current number of courses in this degree *****/
fprintf (Gbl.F.Out,"<td class=\"%s RIGHT_MIDDLE %s\">"
"%u"
"</td>",
2016-04-16 15:05:18 +02:00
TxtClassNormal,BgColor,NumCrss);
2016-03-20 13:18:56 +01:00
/***** Degree status *****/
StatusTxt = Deg_GetStatusTxtFromStatusBits (Deg->Status);
2017-03-17 00:46:28 +01:00
fprintf (Gbl.F.Out,"<td class=\"%s LEFT_MIDDLE %s\">",
TxtClassNormal,BgColor);
if (StatusTxt != Deg_STATUS_ACTIVE) // If active ==> do not show anything
fprintf (Gbl.F.Out,"%s",Txt_DEGREE_STATUS[StatusTxt]);
fprintf (Gbl.F.Out,"</td>"
"</tr>");
2016-03-20 13:18:56 +01:00
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************************** Put forms to edit degrees ***********************/
/*****************************************************************************/
void Deg_EditDegrees (void)
{
2017-04-30 02:56:25 +02:00
extern const char *Hlp_CENTRE_Degrees;
extern const char *Txt_Degrees_of_CENTRE_X;
2017-04-30 14:03:45 +02:00
extern const char *Txt_No_types_of_degree;
2014-12-01 23:55:08 +01:00
/***** Get list of degrees in the current centre *****/
Deg_GetListDegsOfCurrentCtr ();
2016-10-20 21:09:01 +02:00
/***** Get list of degree types *****/
2017-03-24 13:22:54 +01:00
DT_GetListDegreeTypes (Sco_SCOPE_SYS,DT_ORDER_BY_DEGREE_TYPE);
2014-12-01 23:55:08 +01:00
2017-04-30 02:56:25 +02:00
/***** Start frame *****/
sprintf (Gbl.Title,Txt_Degrees_of_CENTRE_X,
Gbl.CurrentCtr.Ctr.FullName);
Lay_StartRoundFrame (NULL,Gbl.Title,Deg_PutIconsEditingDegrees,
Hlp_CENTRE_Degrees);
2016-10-20 21:09:01 +02:00
if (Gbl.Degs.DegTypes.Num)
2014-12-01 23:55:08 +01:00
{
2016-10-20 21:09:01 +02:00
/***** Put a form to create a new degree *****/
Deg_PutFormToCreateDegree ();
2014-12-01 23:55:08 +01:00
2016-10-20 21:09:01 +02:00
/***** Forms to edit current degrees *****/
if (Gbl.CurrentCtr.Ctr.Degs.Num)
Deg_ListDegreesForEdition ();
2014-12-01 23:55:08 +01:00
}
2016-10-20 21:09:01 +02:00
else // No degree types
2014-12-01 23:55:08 +01:00
{
2017-03-26 17:32:19 +02:00
/***** Warning message *****/
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_No_types_of_degree);
2017-03-26 17:32:19 +02:00
/***** Form to create the first degree type *****/
2017-04-30 14:03:45 +02:00
if (DT_CheckIfICanCreateDegreeTypes ())
DT_EditDegreeTypes ();
2014-12-01 23:55:08 +01:00
}
2017-04-30 02:56:25 +02:00
/***** End frame *****/
Lay_EndRoundFrame ();
2016-10-20 21:09:01 +02:00
/***** Free list of degree types *****/
DT_FreeListDegreeTypes ();
2014-12-01 23:55:08 +01:00
/***** Free list of degrees in the current centre *****/
2016-10-20 00:57:00 +02:00
Deg_FreeListDegs (&Gbl.CurrentCtr.Ctr.Degs);
2014-12-01 23:55:08 +01:00
}
2017-04-30 02:56:25 +02:00
/*****************************************************************************/
/**************** Put contextual icons in edition of degrees *****************/
/*****************************************************************************/
static void Deg_PutIconsEditingDegrees (void)
{
/***** Put icon to view degrees *****/
Deg_PutIconToViewDegrees ();
/***** Put icon to view types of degree *****/
DT_PutIconToViewDegreeTypes ();
}
static void Deg_PutIconToViewDegrees (void)
{
2017-04-30 23:48:48 +02:00
Lay_PutContextualIconToView (ActSeeDeg,NULL);
2017-04-30 02:56:25 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-04-16 15:05:18 +02:00
/********** Create a list with all the degrees that have students ************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-04-16 15:05:18 +02:00
void Deg_GetListAllDegsWithStds (struct ListDegrees *Degs)
2014-12-01 23:55:08 +01:00
{
char Query[1024];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumDeg;
/***** Get degrees admin by me from database *****/
2016-04-16 15:05:18 +02:00
sprintf (Query,"SELECT DISTINCTROW degrees.DegCod,degrees.CtrCod,"
"degrees.DegTypCod,degrees.Status,degrees.RequesterUsrCod,"
"degrees.ShortName,degrees.FullName,degrees.WWW"
" FROM degrees,courses,crs_usr"
2016-04-16 18:21:06 +02:00
" WHERE degrees.DegCod=courses.DegCod"
2016-04-16 15:05:18 +02:00
" AND courses.CrsCod=crs_usr.CrsCod"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u"
2016-04-16 15:05:18 +02:00
" ORDER BY degrees.ShortName",
(unsigned) Rol_STUDENT);
Degs->Num = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get degrees admin by you");
if (Degs->Num) // Degrees found...
2014-12-01 23:55:08 +01:00
{
/***** Create list with degrees *****/
2016-04-16 15:05:18 +02:00
if ((Degs->Lst = (struct Degree *) calloc (Degs->Num,sizeof (struct Degree))) == NULL)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Not enough memory to store degrees admin by you.");
/***** Get the degrees *****/
for (NumDeg = 0;
2016-04-16 15:05:18 +02:00
NumDeg < Degs->Num;
2014-12-01 23:55:08 +01:00
NumDeg++)
{
/* Get next degree */
row = mysql_fetch_row (mysql_res);
2016-04-16 15:05:18 +02:00
Deg_GetDataOfDegreeFromRow (&(Degs->Lst[NumDeg]),row);
2014-12-01 23:55:08 +01:00
}
}
else
2016-04-16 15:05:18 +02:00
Degs->Lst = NULL;
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/************ Get a list with the degrees of the current centre **************/
/*****************************************************************************/
2016-10-20 00:57:00 +02:00
void Deg_GetListDegsOfCurrentCtr (void)
2014-12-01 23:55:08 +01:00
{
2017-03-11 20:59:09 +01:00
char Query[256];
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned NumDeg;
/***** Get degrees of the current centre from database *****/
2015-12-06 01:37:22 +01:00
sprintf (Query,"SELECT DegCod,CtrCod,DegTypCod,Status,RequesterUsrCod,"
2016-02-29 18:53:26 +01:00
"ShortName,FullName,WWW"
2017-03-24 01:09:27 +01:00
" FROM degrees WHERE CtrCod=%ld ORDER BY FullName",
2015-12-06 01:37:22 +01:00
Gbl.CurrentCtr.Ctr.CtrCod);
2014-12-01 23:55:08 +01:00
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get degrees of a centre");
/***** Count number of rows in result *****/
if (NumRows) // Degrees found...
{
2016-10-20 00:57:00 +02:00
Gbl.CurrentCtr.Ctr.Degs.Num = (unsigned) NumRows;
2014-12-01 23:55:08 +01:00
/***** Create list with degrees of this centre *****/
2016-10-20 00:57:00 +02:00
if ((Gbl.CurrentCtr.Ctr.Degs.Lst = (struct Degree *) calloc (Gbl.CurrentCtr.Ctr.Degs.Num,
sizeof (struct Degree))) == NULL)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Not enough memory to store degrees of a centre.");
/***** Get the degrees of this centre *****/
for (NumDeg = 0;
2016-10-20 00:57:00 +02:00
NumDeg < Gbl.CurrentCtr.Ctr.Degs.Num;
2014-12-01 23:55:08 +01:00
NumDeg++)
{
/* Get next degree */
row = mysql_fetch_row (mysql_res);
2016-10-20 00:57:00 +02:00
Deg_GetDataOfDegreeFromRow (&Gbl.CurrentCtr.Ctr.Degs.Lst[NumDeg],row);
2014-12-01 23:55:08 +01:00
}
}
2016-10-20 00:57:00 +02:00
else
Gbl.CurrentCtr.Ctr.Degs.Num = 0;
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
2016-10-20 00:57:00 +02:00
/*************************** Free list of degrees ****************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-10-20 00:57:00 +02:00
void Deg_FreeListDegs (struct ListDegrees *Degs)
2014-12-01 23:55:08 +01:00
{
2016-10-20 00:57:00 +02:00
if (Degs->Lst)
2014-12-01 23:55:08 +01:00
{
2016-10-20 00:57:00 +02:00
free ((void *) Degs->Lst);
Degs->Lst = NULL;
Degs->Num = 0;
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/****************** Receive form to request a new degree *********************/
/*****************************************************************************/
void Deg_RecFormReqDeg (void)
{
Deg_RecFormRequestOrCreateDeg ((unsigned) Deg_STATUS_BIT_PENDING);
}
/*****************************************************************************/
/******************* Receive form to create a new degree *********************/
/*****************************************************************************/
void Deg_RecFormNewDeg (void)
{
Deg_RecFormRequestOrCreateDeg (0);
}
/*****************************************************************************/
/******************* Receive form to create a new degree *********************/
/*****************************************************************************/
static void Deg_RecFormRequestOrCreateDeg (unsigned Status)
{
extern const char *Txt_The_degree_X_already_exists;
extern const char *Txt_You_must_specify_the_web_address_of_the_new_degree;
extern const char *Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_degree;
/***** Get parameters from form *****/
/* Set degree centre */
2017-05-11 20:04:38 +02:00
Gbl.Degs.EditingDeg.CtrCod = Gbl.CurrentCtr.Ctr.CtrCod;
2014-12-01 23:55:08 +01:00
/* Get degree short name */
2017-05-11 20:04:38 +02:00
Par_GetParToText ("ShortName",Gbl.Degs.EditingDeg.ShrtName,Hie_MAX_BYTES_SHRT_NAME);
2014-12-01 23:55:08 +01:00
/* Get degree full name */
2017-05-11 20:04:38 +02:00
Par_GetParToText ("FullName",Gbl.Degs.EditingDeg.FullName,Hie_MAX_BYTES_FULL_NAME);
2014-12-01 23:55:08 +01:00
/* Get degree type */
2017-05-11 20:04:38 +02:00
if ((Gbl.Degs.EditingDeg.DegTypCod = DT_GetParamOtherDegTypCod ()) <= 0)
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_ERROR,"Wrong type of degree.");
2014-12-01 23:55:08 +01:00
/* Get degree WWW */
2017-05-11 20:04:38 +02:00
Par_GetParToText ("WWW",Gbl.Degs.EditingDeg.WWW,Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
2017-05-11 20:04:38 +02:00
if (Gbl.Degs.EditingDeg.ShrtName[0] &&
Gbl.Degs.EditingDeg.FullName[0]) // If there's a degree name
2014-12-01 23:55:08 +01:00
{
2017-05-11 20:04:38 +02:00
if (Gbl.Degs.EditingDeg.WWW[0])
2014-12-01 23:55:08 +01:00
{
/***** If name of degree was in database... *****/
2017-05-11 20:04:38 +02:00
if (Deg_CheckIfDegNameExistsInCtr ("ShortName",Gbl.Degs.EditingDeg.ShrtName,-1L,Gbl.Degs.EditingDeg.CtrCod))
2014-12-01 23:55:08 +01:00
{
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_degree_X_already_exists,
2017-05-11 20:04:38 +02:00
Gbl.Degs.EditingDeg.ShrtName);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
2017-05-11 20:04:38 +02:00
else if (Deg_CheckIfDegNameExistsInCtr ("FullName",Gbl.Degs.EditingDeg.FullName,-1L,Gbl.Degs.EditingDeg.CtrCod))
2014-12-01 23:55:08 +01:00
{
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_degree_X_already_exists,
2017-05-11 20:04:38 +02:00
Gbl.Degs.EditingDeg.FullName);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
else // Add new degree to database
2017-05-11 20:04:38 +02:00
Deg_CreateDegree (Status);
2014-12-01 23:55:08 +01:00
}
else // If there is not a degree logo or web
{
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,"%s",Txt_You_must_specify_the_web_address_of_the_new_degree);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
}
else // If there is not a degree name
{
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,"%s",Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_degree);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
/***** Show the form again *****/
Deg_EditDegrees ();
}
/*****************************************************************************/
/************************ Request removing of a degree ***********************/
/*****************************************************************************/
void Deg_RemoveDegree (void)
{
extern const char *Txt_To_remove_a_degree_you_must_first_remove_all_courses_in_the_degree;
extern const char *Txt_Degree_X_removed;
struct Degree Deg;
/***** Get degree code *****/
2016-10-23 19:40:14 +02:00
Deg.DegCod = Deg_GetAndCheckParamOtherDegCod ();
2014-12-01 23:55:08 +01:00
2016-03-01 13:36:48 +01:00
/***** Get data of degree *****/
2014-12-01 23:55:08 +01:00
Deg_GetDataOfDegreeByCod (&Deg);
/***** Check if this degree has courses *****/
2016-04-16 15:05:18 +02:00
if (Crs_GetNumCrssInDeg (Deg.DegCod)) // Degree has courses ==> don't remove
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_To_remove_a_degree_you_must_first_remove_all_courses_in_the_degree);
2014-12-01 23:55:08 +01:00
else // Degree has no courses ==> remove it
{
/***** Remove degree *****/
Deg_RemoveDegreeCompletely (Deg.DegCod);
/***** Write message to show the change made *****/
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_Degree_X_removed,
2014-12-01 23:55:08 +01:00
Deg.FullName);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
/***** Show the form again *****/
Deg_EditDegrees ();
}
/*****************************************************************************/
/******************** Write parameter with code of degree ********************/
/*****************************************************************************/
void Deg_PutParamDegCod (long DegCod)
{
2015-03-07 21:08:44 +01:00
Par_PutHiddenParamLong ("deg",DegCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Write parameter with code of degree ********************/
/*****************************************************************************/
static void Deg_PutParamOtherDegCod (long DegCod)
{
Par_PutHiddenParamLong ("OthDegCod",DegCod);
}
/*****************************************************************************/
/********************* Get parameter with code of degree *********************/
/*****************************************************************************/
2016-10-23 19:40:14 +02:00
long Deg_GetAndCheckParamOtherDegCod (void)
2014-12-01 23:55:08 +01:00
{
2016-10-23 18:39:04 +02:00
long DegCod;
2014-12-01 23:55:08 +01:00
2016-10-23 19:40:14 +02:00
/***** Get and check parameter with code of degree *****/
2017-01-28 20:32:50 +01:00
if ((DegCod = Par_GetParToLong ("OthDegCod")) <= 0)
2016-10-23 18:39:04 +02:00
Lay_ShowErrorAndExit ("Code of degree is missing.");
return DegCod;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Get data of a degree from its code ********************/
/*****************************************************************************/
// Returns true if degree found
bool Deg_GetDataOfDegreeByCod (struct Degree *Deg)
{
2017-03-11 20:59:09 +01:00
char Query[256];
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
bool DegFound = false;
2016-12-30 01:20:49 +01:00
/***** Clear data *****/
Deg->CtrCod = -1L;
Deg->DegTypCod = -1L;
Deg->Status = (Deg_Status_t) 0;
Deg->RequesterUsrCod = -1L;
Deg->ShrtName[0] = '\0';
Deg->FullName[0] = '\0';
Deg->WWW[0] = '\0';
Deg->LstCrss = NULL;
/***** Check if degree code is correct *****/
if (Deg->DegCod > 0)
2014-12-01 23:55:08 +01:00
{
2016-12-30 01:20:49 +01:00
/***** Get data of a degree from database *****/
sprintf (Query,"SELECT DegCod,CtrCod,DegTypCod,Status,RequesterUsrCod,"
"ShortName,FullName,WWW"
2017-03-24 01:09:27 +01:00
" FROM degrees WHERE DegCod=%ld",
2016-12-30 01:20:49 +01:00
Deg->DegCod);
if (DB_QuerySELECT (Query,&mysql_res,"can not get data of a degree")) // Degree found...
{
/***** Get data of degree *****/
row = mysql_fetch_row (mysql_res);
Deg_GetDataOfDegreeFromRow (Deg,row);
2014-12-01 23:55:08 +01:00
2016-12-30 01:20:49 +01:00
/* Set return value */
DegFound = true;
}
2014-12-01 23:55:08 +01:00
2016-12-30 01:20:49 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2014-12-01 23:55:08 +01:00
}
return DegFound;
}
/*****************************************************************************/
/********** Get data of a degree from a row resulting of a query *************/
/*****************************************************************************/
static void Deg_GetDataOfDegreeFromRow (struct Degree *Deg,MYSQL_ROW row)
{
/***** Get degree code (row[0]) *****/
if ((Deg->DegCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of degree.");
/***** Get centre code (row[1]) *****/
Deg->CtrCod = Str_ConvertStrCodToLongCod (row[1]);
/***** Get the code of the degree type (row[2]) *****/
Deg->DegTypCod = Str_ConvertStrCodToLongCod (row[2]);
/* Get course status (row[3]) */
if (sscanf (row[3],"%u",&(Deg->Status)) != 1)
Lay_ShowErrorAndExit ("Wrong degree status.");
/* Get requester user's code (row[4]) */
Deg->RequesterUsrCod = Str_ConvertStrCodToLongCod (row[4]);
/***** Get degree short name (row[5]) *****/
2017-01-17 03:10:43 +01:00
Str_Copy (Deg->ShrtName,row[5],
2017-03-08 14:12:33 +01:00
Hie_MAX_BYTES_SHRT_NAME);
2014-12-01 23:55:08 +01:00
/***** Get degree full name (row[6]) *****/
2017-01-17 03:10:43 +01:00
Str_Copy (Deg->FullName,row[6],
2017-03-08 14:12:33 +01:00
Hie_MAX_BYTES_FULL_NAME);
2014-12-01 23:55:08 +01:00
2016-02-29 18:53:26 +01:00
/***** Get WWW (row[7]) *****/
2017-01-17 03:10:43 +01:00
Str_Copy (Deg->WWW,row[7],
2017-03-07 01:56:41 +01:00
Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************* Get the short name of a degree from its code ******************/
/*****************************************************************************/
void Deg_GetShortNameOfDegreeByCod (struct Degree *Deg)
{
2017-03-11 20:59:09 +01:00
char Query[128];
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2016-10-28 10:03:37 +02:00
Deg->ShrtName[0] = '\0';
2014-12-01 23:55:08 +01:00
if (Deg->DegCod > 0)
{
/***** Get the short name of a degree from database *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"SELECT ShortName FROM degrees WHERE DegCod=%ld",
2014-12-01 23:55:08 +01:00
Deg->DegCod);
if (DB_QuerySELECT (Query,&mysql_res,"can not get the short name of a degree") == 1)
{
/***** Get the short name of this degree *****/
row = mysql_fetch_row (mysql_res);
2017-01-13 01:51:23 +01:00
2017-01-17 03:10:43 +01:00
Str_Copy (Deg->ShrtName,row[0],
2017-03-08 14:12:33 +01:00
Hie_MAX_BYTES_SHRT_NAME);
2014-12-01 23:55:08 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
}
2015-02-03 11:34:59 +01:00
/*****************************************************************************/
/************* Get the centre code of a degree from its code *****************/
/*****************************************************************************/
long Deg_GetCtrCodOfDegreeByCod (long DegCod)
{
char Query[128];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long CtrCod = -1L;
if (DegCod > 0)
{
/***** Get the centre code of a degree from database *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"SELECT CtrCod FROM degrees WHERE DegCod=%ld",
2015-02-03 11:34:59 +01:00
DegCod);
if (DB_QuerySELECT (Query,&mysql_res,"can not get the centre of a degree") == 1)
{
/***** Get the centre code of this degree *****/
row = mysql_fetch_row (mysql_res);
CtrCod = Str_ConvertStrCodToLongCod (row[0]);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
return CtrCod;
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********** Get the institution code of a degree from its code ***************/
/*****************************************************************************/
long Deg_GetInsCodOfDegreeByCod (long DegCod)
{
2015-02-03 11:34:59 +01:00
char Query[256];
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long InsCod = -1L;
if (DegCod > 0)
{
2015-02-03 11:34:59 +01:00
/***** Get the institution code of a degree from database *****/
2014-12-01 23:55:08 +01:00
sprintf (Query,"SELECT centres.InsCod FROM degrees,centres"
2017-03-24 01:09:27 +01:00
" WHERE degrees.DegCod=%ld"
2017-03-11 20:59:09 +01:00
" AND degrees.CtrCod=centres.CtrCod",
2014-12-01 23:55:08 +01:00
DegCod);
if (DB_QuerySELECT (Query,&mysql_res,"can not get the institution of a degree") == 1)
{
2015-02-03 11:34:59 +01:00
/***** Get the institution code of this degree *****/
2014-12-01 23:55:08 +01:00
row = mysql_fetch_row (mysql_res);
InsCod = Str_ConvertStrCodToLongCod (row[0]);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
return InsCod;
}
/*****************************************************************************/
/***************************** Remove a degree *******************************/
/*****************************************************************************/
2016-03-20 16:30:52 +01:00
void Deg_RemoveDegreeCompletely (long DegCod)
2014-12-01 23:55:08 +01:00
{
2016-10-27 22:16:03 +02:00
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
2017-03-11 20:59:09 +01:00
char Query[128];
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRow,NumRows;
long CrsCod;
2017-01-28 15:58:46 +01:00
char PathDeg[PATH_MAX + 1];
2014-12-01 23:55:08 +01:00
/***** Get courses of a degree from database *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"SELECT CrsCod FROM courses WHERE DegCod=%ld",
2017-03-11 20:59:09 +01:00
DegCod);
2014-12-01 23:55:08 +01:00
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get courses of a degree");
/* Get courses in this degree */
for (NumRow = 0;
NumRow < NumRows;
NumRow++)
{
/* Get next course */
row = mysql_fetch_row (mysql_res);
/* Get course code (row[0]) */
if ((CrsCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of course.");
/* Remove course */
Crs_RemoveCourseCompletely (CrsCod);
}
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
2016-10-27 23:38:53 +02:00
/***** Remove all the threads and posts in forums of the degree *****/
2016-10-28 00:23:02 +02:00
For_RemoveForums (Sco_SCOPE_DEG,DegCod);
/***** Remove surveys of the degree *****/
Svy_RemoveSurveys (Sco_SCOPE_DEG,DegCod);
2014-12-01 23:55:08 +01:00
2015-01-20 02:00:42 +01:00
/***** Remove information related to files in degree *****/
2015-01-25 18:50:43 +01:00
Brw_RemoveDegFilesFromDB (DegCod);
/***** Remove directories of the degree *****/
sprintf (PathDeg,"%s/%s/%02u/%u",
Cfg_PATH_SWAD_PUBLIC,Cfg_FOLDER_DEG,
(unsigned) (DegCod % 100),
(unsigned) DegCod);
2016-10-06 22:18:33 +02:00
Fil_RemoveTree (PathDeg);
2015-01-20 18:55:59 +01:00
2014-12-01 23:55:08 +01:00
/***** Remove administrators of this degree *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"DELETE FROM admin WHERE Scope='%s' AND Cod=%ld",
2016-10-27 22:16:03 +02:00
Sco_ScopeDB[Sco_SCOPE_DEG],DegCod);
2014-12-01 23:55:08 +01:00
DB_QueryDELETE (Query,"can not remove administrators of a degree");
/***** Remove the degree *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"DELETE FROM degrees WHERE DegCod=%ld",
2015-01-20 02:00:42 +01:00
DegCod);
2014-12-01 23:55:08 +01:00
DB_QueryDELETE (Query,"can not remove a degree");
/***** Delete all the degrees in sta_degrees table not present in degrees table *****/
Pho_RemoveObsoleteStatDegrees ();
}
/*****************************************************************************/
/********************* Change the short name of a degree *********************/
/*****************************************************************************/
void Deg_RenameDegreeShort (void)
{
2016-10-23 19:40:14 +02:00
Gbl.Degs.EditingDeg.DegCod = Deg_GetAndCheckParamOtherDegCod ();
2016-10-28 10:03:37 +02:00
Deg_RenameDegree (&Gbl.Degs.EditingDeg,Cns_SHRT_NAME);
2014-12-01 23:55:08 +01:00
}
2016-10-23 16:15:28 +02:00
void Deg_RenameDegreeShortInConfig (void)
{
2016-10-28 10:03:37 +02:00
Deg_RenameDegree (&Gbl.CurrentDeg.Deg,Cns_SHRT_NAME);
2016-10-23 16:15:28 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************* Change the full name of a degree **********************/
/*****************************************************************************/
void Deg_RenameDegreeFull (void)
{
2016-10-23 19:40:14 +02:00
Gbl.Degs.EditingDeg.DegCod = Deg_GetAndCheckParamOtherDegCod ();
2016-10-23 16:04:36 +02:00
Deg_RenameDegree (&Gbl.Degs.EditingDeg,Cns_FULL_NAME);
}
2016-03-01 13:36:48 +01:00
2016-10-23 16:04:36 +02:00
void Deg_RenameDegreeFullInConfig (void)
{
Deg_RenameDegree (&Gbl.CurrentDeg.Deg,Cns_FULL_NAME);
}
2016-03-01 13:36:48 +01:00
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************ Change the name of a degree ************************/
/*****************************************************************************/
2016-10-28 10:03:37 +02:00
static void Deg_RenameDegree (struct Degree *Deg,Cns_ShrtOrFullName_t ShrtOrFullName)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_You_can_not_leave_the_name_of_the_degree_X_empty;
extern const char *Txt_The_degree_X_already_exists;
extern const char *Txt_The_name_of_the_degree_X_has_changed_to_Y;
extern const char *Txt_The_name_of_the_degree_X_has_not_changed;
const char *ParamName = NULL; // Initialized to avoid warning
const char *FieldName = NULL; // Initialized to avoid warning
2017-03-07 11:03:05 +01:00
unsigned MaxBytes = 0; // Initialized to avoid warning
2014-12-01 23:55:08 +01:00
char *CurrentDegName = NULL; // Initialized to avoid warning
2017-03-08 14:12:33 +01:00
char NewDegName[Hie_MAX_BYTES_FULL_NAME + 1];
2014-12-01 23:55:08 +01:00
2016-10-28 10:03:37 +02:00
switch (ShrtOrFullName)
2014-12-01 23:55:08 +01:00
{
2016-10-28 10:03:37 +02:00
case Cns_SHRT_NAME:
2014-12-01 23:55:08 +01:00
ParamName = "ShortName";
FieldName = "ShortName";
2017-03-08 14:12:33 +01:00
MaxBytes = Hie_MAX_BYTES_SHRT_NAME;
2016-10-28 10:03:37 +02:00
CurrentDegName = Deg->ShrtName;
2014-12-01 23:55:08 +01:00
break;
case Cns_FULL_NAME:
ParamName = "FullName";
FieldName = "FullName";
2017-03-08 14:12:33 +01:00
MaxBytes = Hie_MAX_BYTES_FULL_NAME;
2014-12-01 23:55:08 +01:00
CurrentDegName = Deg->FullName;
break;
}
/***** Get parameters from form *****/
/* Get the new name for the degree */
2017-03-07 11:03:05 +01:00
Par_GetParToText (ParamName,NewDegName,MaxBytes);
2014-12-01 23:55:08 +01:00
2016-03-01 13:36:48 +01:00
/***** Get data of degree *****/
Deg_GetDataOfDegreeByCod (Deg);
2014-12-01 23:55:08 +01:00
/***** Check if new name is empty *****/
if (!NewDegName[0])
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_WARNING;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_You_can_not_leave_the_name_of_the_degree_X_empty,
2014-12-01 23:55:08 +01:00
CurrentDegName);
}
else
{
/***** Check if old and new names are the same (this happens when user press enter with no changes in the form) *****/
if (strcmp (CurrentDegName,NewDegName)) // Different names
{
/***** If degree was in database... *****/
2016-10-20 19:46:06 +02:00
if (Deg_CheckIfDegNameExistsInCtr (ParamName,NewDegName,Deg->DegCod,Deg->CtrCod))
2014-12-01 23:55:08 +01:00
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_WARNING;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_degree_X_already_exists,NewDegName);
2014-12-01 23:55:08 +01:00
}
else
{
/* Update the table changing old name by new name */
2017-03-09 11:16:17 +01:00
Deg_UpdateDegNameDB (Deg->DegCod,FieldName,NewDegName);
2014-12-01 23:55:08 +01:00
2016-03-01 13:36:48 +01:00
/* Write message to show the change made */
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_SUCCESS;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_name_of_the_degree_X_has_changed_to_Y,
2014-12-01 23:55:08 +01:00
CurrentDegName,NewDegName);
2016-03-01 13:36:48 +01:00
/* Change current degree name in order to display it properly */
2017-01-17 03:10:43 +01:00
Str_Copy (CurrentDegName,NewDegName,
2017-03-07 11:03:05 +01:00
MaxBytes);
2014-12-01 23:55:08 +01:00
}
}
else // The same name
2017-03-26 03:45:13 +02:00
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_INFO;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_name_of_the_degree_X_has_not_changed,
2014-12-01 23:55:08 +01:00
CurrentDegName);
2017-03-26 03:45:13 +02:00
}
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/********************* Check if the name of degree exists ********************/
/*****************************************************************************/
2016-10-20 19:46:06 +02:00
static bool Deg_CheckIfDegNameExistsInCtr (const char *FieldName,const char *Name,long DegCod,long CtrCod)
2014-12-01 23:55:08 +01:00
{
2017-03-09 11:16:17 +01:00
char Query[256 + Hie_MAX_BYTES_FULL_NAME];
2014-12-01 23:55:08 +01:00
/***** Get number of degrees with a type and a name from database *****/
sprintf (Query,"SELECT COUNT(*) FROM degrees"
2017-03-24 01:09:27 +01:00
" WHERE CtrCod=%ld AND %s='%s' AND DegCod<>%ld",
2015-11-04 22:51:41 +01:00
CtrCod,FieldName,Name,DegCod);
2014-12-01 23:55:08 +01:00
return (DB_QueryCOUNT (Query,"can not check if the name of a degree already existed") != 0);
}
2017-03-09 11:16:17 +01:00
/*****************************************************************************/
/***************** Update degree name in table of degrees ********************/
/*****************************************************************************/
static void Deg_UpdateDegNameDB (long DegCod,const char *FieldName,const char *NewDegName)
{
char Query[128 + Hie_MAX_BYTES_FULL_NAME];
/***** Update degree changing old name by new name *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"UPDATE degrees SET %s='%s' WHERE DegCod=%ld",
2017-03-09 11:16:17 +01:00
FieldName,NewDegName,DegCod);
DB_QueryUPDATE (Query,"can not update the name of a degree");
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************ Change the centre of a degree **********************/
/*****************************************************************************/
2016-10-20 16:49:42 +02:00
void Deg_ChangeDegCtrInConfig (void)
2016-10-19 20:43:26 +02:00
{
2016-10-20 19:46:06 +02:00
extern const char *Txt_The_degree_X_already_exists;
2016-10-19 20:43:26 +02:00
extern const char *Txt_The_degree_X_has_been_moved_to_the_centre_Y;
struct Centre NewCtr;
2016-10-23 18:50:21 +02:00
/***** Get parameter with centre code *****/
2016-10-23 19:40:14 +02:00
NewCtr.CtrCod = Ctr_GetAndCheckParamOtherCtrCod ();
2016-10-19 20:43:26 +02:00
2016-10-20 20:02:59 +02:00
/***** Check if centre has changed *****/
2016-10-20 19:46:06 +02:00
if (NewCtr.CtrCod != Gbl.CurrentDeg.Deg.CtrCod)
{
/***** Get data of new centre *****/
Ctr_GetDataOfCentreByCod (&NewCtr);
2016-10-19 20:43:26 +02:00
2016-10-20 19:46:06 +02:00
/***** Check if it already exists a degree with the same name in the new centre *****/
2016-10-28 10:03:37 +02:00
if (Deg_CheckIfDegNameExistsInCtr ("ShortName",Gbl.CurrentDeg.Deg.ShrtName,Gbl.CurrentDeg.Deg.DegCod,NewCtr.CtrCod))
2016-10-20 19:46:06 +02:00
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_WARNING;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_degree_X_already_exists,
2016-10-28 10:03:37 +02:00
Gbl.CurrentDeg.Deg.ShrtName);
2016-10-20 19:46:06 +02:00
}
else if (Deg_CheckIfDegNameExistsInCtr ("FullName",Gbl.CurrentDeg.Deg.FullName,Gbl.CurrentDeg.Deg.DegCod,NewCtr.CtrCod))
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_WARNING;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_degree_X_already_exists,
2016-10-20 19:46:06 +02:00
Gbl.CurrentDeg.Deg.FullName);
}
else
{
/***** Update centre in table of degrees *****/
Deg_UpdateDegCtrDB (Gbl.CurrentDeg.Deg.DegCod,NewCtr.CtrCod);
Gbl.CurrentDeg.Deg.CtrCod =
Gbl.CurrentCtr.Ctr.CtrCod = NewCtr.CtrCod;
/***** Initialize again current course, degree, centre... *****/
2016-11-14 17:26:32 +01:00
Hie_InitHierarchy ();
2016-10-20 19:46:06 +02:00
/***** Create message to show the change made *****/
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_SUCCESS;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_degree_X_has_been_moved_to_the_centre_Y,
2016-10-20 19:46:06 +02:00
Gbl.CurrentDeg.Deg.FullName,
Gbl.CurrentCtr.Ctr.FullName);
}
}
2016-10-19 20:43:26 +02:00
}
/*****************************************************************************/
2016-10-20 16:49:42 +02:00
/** Show message of success after changing a degree in degree configuration **/
2016-10-19 20:43:26 +02:00
/*****************************************************************************/
void Deg_ContEditAfterChgDegInConfig (void)
{
2017-03-26 03:45:13 +02:00
/***** Write success / warning message *****/
2017-05-11 23:45:46 +02:00
Ale_ShowPendingAlert ();
2016-10-19 20:43:26 +02:00
/***** Show the form again *****/
Deg_ShowConfiguration ();
}
2016-10-19 23:17:36 +02:00
/*****************************************************************************/
/********************** Update centre in table of degrees ********************/
/*****************************************************************************/
2016-10-20 16:49:42 +02:00
static void Deg_UpdateDegCtrDB (long DegCod,long CtrCod)
2016-10-19 23:17:36 +02:00
{
char Query[128];
/***** Update centre in table of degrees *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"UPDATE degrees SET CtrCod=%ld WHERE DegCod=%ld",
2016-10-19 23:17:36 +02:00
CtrCod,DegCod);
DB_QueryUPDATE (Query,"can not update the centre of a degree");
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************* Change the WWW of a degree ************************/
/*****************************************************************************/
void Deg_ChangeDegWWW (void)
{
extern const char *Txt_The_new_web_address_is_X;
extern const char *Txt_You_can_not_leave_the_web_address_empty;
2017-03-07 01:56:41 +01:00
char NewWWW[Cns_MAX_BYTES_WWW + 1];
2014-12-01 23:55:08 +01:00
/***** Get parameters from form *****/
/* Get the code of the degree */
2017-05-11 20:04:38 +02:00
Gbl.Degs.EditingDeg.DegCod = Deg_GetAndCheckParamOtherDegCod ();
2014-12-01 23:55:08 +01:00
/* Get the new WWW for the degree */
2017-03-07 01:56:41 +01:00
Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
2016-03-01 13:36:48 +01:00
/***** Get data of degree *****/
2017-05-11 20:04:38 +02:00
Deg_GetDataOfDegreeByCod (&Gbl.Degs.EditingDeg);
2016-03-01 13:36:48 +01:00
2014-12-01 23:55:08 +01:00
/***** Check if new WWW is empty *****/
if (NewWWW[0])
{
2016-03-01 13:36:48 +01:00
/***** Update the table changing old WWW by new WWW *****/
2017-05-11 20:04:38 +02:00
Deg_UpdateDegWWWDB (Gbl.Degs.EditingDeg.DegCod,NewWWW);
Str_Copy (Gbl.Degs.EditingDeg.WWW,NewWWW,
2017-03-07 01:56:41 +01:00
Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
2017-05-11 20:04:38 +02:00
/***** Write message to show the change made
and put button to go to degree changed *****/
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_SUCCESS;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_new_web_address_is_X,NewWWW);
2017-05-11 20:04:38 +02:00
Deg_ShowAlertAndButtonToGoToDeg ();
2014-12-01 23:55:08 +01:00
}
else
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_You_can_not_leave_the_web_address_empty);
2016-10-23 16:37:45 +02:00
/***** Show the form again *****/
Deg_EditDegrees ();
}
void Deg_ChangeDegWWWInConfig (void)
{
extern const char *Txt_The_new_web_address_is_X;
extern const char *Txt_You_can_not_leave_the_web_address_empty;
2017-03-07 01:56:41 +01:00
char NewWWW[Cns_MAX_BYTES_WWW + 1];
2016-10-23 16:37:45 +02:00
/***** Get parameters from form *****/
/* Get the new WWW for the degree */
2017-03-07 01:56:41 +01:00
Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW);
2016-10-23 16:37:45 +02:00
/***** Check if new WWW is empty *****/
if (NewWWW[0])
2014-12-01 23:55:08 +01:00
{
2016-10-23 16:37:45 +02:00
/***** Update the table changing old WWW by new WWW *****/
Deg_UpdateDegWWWDB (Gbl.CurrentDeg.Deg.DegCod,NewWWW);
2017-01-17 03:10:43 +01:00
Str_Copy (Gbl.CurrentDeg.Deg.WWW,NewWWW,
2017-03-07 01:56:41 +01:00
Cns_MAX_BYTES_WWW);
2016-10-23 16:37:45 +02:00
/***** Write message to show the change made *****/
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_new_web_address_is_X,NewWWW);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
2016-10-23 16:37:45 +02:00
else
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_You_can_not_leave_the_web_address_empty);
2014-12-01 23:55:08 +01:00
/***** Show the form again *****/
2016-10-23 16:37:45 +02:00
Deg_ShowConfiguration ();
}
/*****************************************************************************/
/**************** Update database changing old WWW by new WWW ****************/
/*****************************************************************************/
2017-03-07 01:56:41 +01:00
static void Deg_UpdateDegWWWDB (long DegCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1])
2016-10-23 16:37:45 +02:00
{
2017-03-07 01:56:41 +01:00
char Query[256 + Cns_MAX_BYTES_WWW];
2016-10-23 16:37:45 +02:00
/***** Update database changing old WWW by new WWW *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"UPDATE degrees SET WWW='%s' WHERE DegCod=%ld",
2016-10-23 16:37:45 +02:00
NewWWW,DegCod);
DB_QueryUPDATE (Query,"can not update the web of a degree");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********************** Change the status of a degree ***********************/
/*****************************************************************************/
void Deg_ChangeDegStatus (void)
{
extern const char *Txt_The_status_of_the_degree_X_has_changed;
2017-03-11 20:59:09 +01:00
char Query[128];
2014-12-01 23:55:08 +01:00
Deg_Status_t Status;
Deg_StatusTxt_t StatusTxt;
/***** Get parameters from form *****/
/* Get degree code */
2017-05-11 20:04:38 +02:00
Gbl.Degs.EditingDeg.DegCod = Deg_GetAndCheckParamOtherDegCod ();
2014-12-01 23:55:08 +01:00
/* Get parameter with status */
2017-01-29 21:41:08 +01:00
Status = (Deg_Status_t)
Par_GetParToUnsignedLong ("Status",
0,
(unsigned long) Deg_MAX_STATUS,
(unsigned long) Deg_WRONG_STATUS);
2017-01-29 12:42:19 +01:00
if (Status == Deg_WRONG_STATUS)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Wrong status.");
StatusTxt = Deg_GetStatusTxtFromStatusBits (Status);
Status = Deg_GetStatusBitsFromStatusTxt (StatusTxt); // New status
/***** Get data of degree *****/
2017-05-11 20:04:38 +02:00
Deg_GetDataOfDegreeByCod (&Gbl.Degs.EditingDeg);
2014-12-01 23:55:08 +01:00
/***** Update status in table of degrees *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"UPDATE degrees SET Status=%u WHERE DegCod=%ld",
2017-05-11 20:04:38 +02:00
(unsigned) Status,Gbl.Degs.EditingDeg.DegCod);
2014-12-01 23:55:08 +01:00
DB_QueryUPDATE (Query,"can not update the status of a degree");
2017-05-11 20:04:38 +02:00
Gbl.Degs.EditingDeg.Status = Status;
2014-12-01 23:55:08 +01:00
2017-05-11 20:04:38 +02:00
/***** Write message to show the change made
and put button to go to degree changed *****/
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_SUCCESS;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_status_of_the_degree_X_has_changed,
2017-05-11 20:04:38 +02:00
Gbl.Degs.EditingDeg.ShrtName);
Deg_ShowAlertAndButtonToGoToDeg ();
2016-03-01 13:36:48 +01:00
/***** Show the form again *****/
Deg_EditDegrees ();
}
/*****************************************************************************/
/************* Show message of success after changing a degree ***************/
/*****************************************************************************/
void Deg_ContEditAfterChgDeg (void)
{
2017-05-11 20:55:04 +02:00
/***** Write message to show the change made
and put button to go to degree changed *****/
2017-05-11 20:04:38 +02:00
Deg_ShowAlertAndButtonToGoToDeg ();
2016-03-01 13:36:48 +01:00
2014-12-01 23:55:08 +01:00
/***** Show the form again *****/
Deg_EditDegrees ();
}
2016-03-01 13:36:48 +01:00
/*****************************************************************************/
2017-05-11 20:55:04 +02:00
/***************** Write message to show the change made ********************/
/***************** and put button to go to degree changed ********************/
2016-03-01 13:36:48 +01:00
/*****************************************************************************/
2017-05-11 20:04:38 +02:00
// Gbl.Degs.EditingDeg is the degree that is beeing edited
2017-05-11 20:55:04 +02:00
// Gbl.CurrentDeg.Deg is the current degree
2016-03-01 13:36:48 +01:00
2017-05-11 20:04:38 +02:00
void Deg_ShowAlertAndButtonToGoToDeg (void)
2016-03-01 13:36:48 +01:00
{
extern const char *Txt_Go_to_X;
2017-05-11 20:04:38 +02:00
// If the degree being edited is different to the current one...
if (Gbl.Degs.EditingDeg.DegCod != Gbl.CurrentDeg.Deg.DegCod)
2016-03-01 23:58:48 +01:00
{
2017-05-11 21:53:37 +02:00
/***** Alert with button to go to degree *****/
2017-05-11 20:04:38 +02:00
sprintf (Gbl.Title,Txt_Go_to_X,Gbl.Degs.EditingDeg.ShrtName);
2017-05-11 23:45:46 +02:00
Ale_ShowAlertAndButton (Gbl.Alert.Type,Gbl.Alert.Txt,
2017-05-11 21:53:37 +02:00
ActSeeCrs,NULL,Deg_PutParamGoToDeg,
Lay_CONFIRM_BUTTON,Gbl.Title);
2016-03-01 23:58:48 +01:00
}
2017-05-11 20:04:38 +02:00
else
2017-05-11 21:53:37 +02:00
/***** Alert *****/
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Gbl.Alert.Type,Gbl.Alert.Txt);
2017-05-11 20:04:38 +02:00
}
static void Deg_PutParamGoToDeg (void)
{
Deg_PutParamDegCod (Gbl.Degs.EditingDeg.DegCod);
2016-03-01 13:36:48 +01:00
}
2015-01-17 19:31:21 +01:00
/*****************************************************************************/
/*********** Show a form for sending a logo of the current degree ************/
/*****************************************************************************/
void Deg_RequestLogo (void)
{
2015-02-01 20:17:24 +01:00
Log_RequestLogo (Sco_SCOPE_DEG);
2015-01-17 19:31:21 +01:00
}
/*****************************************************************************/
/***************** Receive the logo of the current degree ********************/
/*****************************************************************************/
void Deg_ReceiveLogo (void)
{
2015-02-01 20:17:24 +01:00
Log_ReceiveLogo (Sco_SCOPE_DEG);
2015-01-17 19:31:21 +01:00
}
2015-02-03 18:43:55 +01:00
/*****************************************************************************/
/****************** Remove the logo of the current degree ********************/
/*****************************************************************************/
void Deg_RemoveLogo (void)
{
Log_RemoveLogo (Sco_SCOPE_DEG);
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/*********************** Get total number of degrees *************************/
/*****************************************************************************/
unsigned Deg_GetNumDegsTotal (void)
{
2017-03-11 20:59:09 +01:00
char Query[128];
2014-12-01 23:55:08 +01:00
/***** Get total number of degrees from database *****/
sprintf (Query,"SELECT COUNT(*) FROM degrees");
return (unsigned) DB_QueryCOUNT (Query,"can not get the total number of degrees");
}
/*****************************************************************************/
/********************* Get number of degrees in a country ********************/
/*****************************************************************************/
unsigned Deg_GetNumDegsInCty (long InsCod)
{
char Query[512];
/***** Get number of degrees in a country from database *****/
sprintf (Query,"SELECT COUNT(*) FROM institutions,centres,degrees"
2017-03-24 01:09:27 +01:00
" WHERE institutions.CtyCod=%ld"
2014-12-01 23:55:08 +01:00
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod",
InsCod);
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of degrees in a country");
}
/*****************************************************************************/
/****************** Get number of degrees in an institution ******************/
/*****************************************************************************/
unsigned Deg_GetNumDegsInIns (long InsCod)
{
char Query[512];
/***** Get number of degrees in an institution from database *****/
sprintf (Query,"SELECT COUNT(*) FROM centres,degrees"
2017-03-24 01:09:27 +01:00
" WHERE centres.InsCod=%ld"
2014-12-01 23:55:08 +01:00
" AND centres.CtrCod=degrees.CtrCod",
InsCod);
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of degrees in an institution");
}
/*****************************************************************************/
/******************** Get number of degrees in a centre **********************/
/*****************************************************************************/
unsigned Deg_GetNumDegsInCtr (long CtrCod)
{
2017-03-11 20:59:09 +01:00
char Query[128];
2014-12-01 23:55:08 +01:00
/***** Get number of degrees in a centre from database *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"SELECT COUNT(*) FROM degrees WHERE CtrCod=%ld",
2014-12-01 23:55:08 +01:00
CtrCod);
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of degrees in a centre");
}
/*****************************************************************************/
/********************* Get number of centres with courses ********************/
/*****************************************************************************/
unsigned Deg_GetNumDegsWithCrss (const char *SubQuery)
{
char Query[512];
/***** Get number of degrees with courses from database *****/
sprintf (Query,"SELECT COUNT(DISTINCT degrees.DegCod)"
" 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 degrees with courses");
}
/*****************************************************************************/
/********************* Get number of degrees with users **********************/
/*****************************************************************************/
unsigned Deg_GetNumDegsWithUsrs (Rol_Role_t Role,const char *SubQuery)
{
char Query[512];
/***** Get number of degrees with users from database *****/
sprintf (Query,"SELECT COUNT(DISTINCT degrees.DegCod)"
" 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"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u",
2014-12-01 23:55:08 +01:00
SubQuery,(unsigned) Role);
return (unsigned) DB_QueryCOUNT (Query,"can not get number of degrees with users");
}
/*****************************************************************************/
2015-11-23 00:44:39 +01:00
/***** Write institutions, centres and degrees administrated by an admin *****/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-11-14 16:47:46 +01:00
void Hie_GetAndWriteInsCtrDegAdminBy (long UsrCod,unsigned ColSpan)
2014-12-01 23:55:08 +01:00
{
2016-10-27 22:16:03 +02:00
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_all_degrees;
2015-11-23 13:14:13 +01:00
char Query[1024];
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2015-11-23 00:44:39 +01:00
unsigned NumRow;
unsigned NumRows;
2016-10-28 10:03:37 +02:00
struct Instit Ins;
2015-11-23 00:44:39 +01:00
struct Centre Ctr;
2015-11-19 20:04:41 +01:00
struct Degree Deg;
2014-12-01 23:55:08 +01:00
2015-11-23 00:44:39 +01:00
/***** Get institutions, centres, degrees admin by user from database *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"(SELECT %u AS S,-1 AS Cod,'' AS FullName"
2015-01-29 01:03:31 +01:00
" FROM admin"
2017-03-24 01:09:27 +01:00
" WHERE UsrCod=%ld"
2016-10-27 22:16:03 +02:00
" AND Scope='%s')"
2015-11-23 00:44:39 +01:00
" UNION "
2017-03-24 01:09:27 +01:00
"(SELECT %u AS S,admin.Cod,institutions.FullName"
2015-11-23 00:44:39 +01:00
" FROM admin,institutions"
2017-03-24 01:09:27 +01:00
" WHERE admin.UsrCod=%ld"
2016-10-27 22:16:03 +02:00
" AND admin.Scope='%s'"
2015-11-23 00:44:39 +01:00
" AND admin.Cod=institutions.InsCod)"
" UNION "
2017-03-24 01:09:27 +01:00
"(SELECT %u AS S,admin.Cod,centres.FullName"
2015-11-23 00:44:39 +01:00
" FROM admin,centres"
2017-03-24 01:09:27 +01:00
" WHERE admin.UsrCod=%ld"
2016-10-27 22:16:03 +02:00
" AND admin.Scope='%s'"
2015-11-23 00:44:39 +01:00
" AND admin.Cod=centres.CtrCod)"
2014-12-01 23:55:08 +01:00
" UNION "
2017-03-24 01:09:27 +01:00
"(SELECT %u AS S,admin.Cod,degrees.FullName"
2015-01-29 01:03:31 +01:00
" FROM admin,degrees"
2017-03-24 01:09:27 +01:00
" WHERE admin.UsrCod=%ld"
2016-10-27 22:16:03 +02:00
" AND admin.Scope='%s'"
2015-01-29 01:03:31 +01:00
" AND admin.Cod=degrees.DegCod)"
2015-11-23 13:14:13 +01:00
" ORDER BY S,FullName",
2016-10-27 22:16:03 +02:00
(unsigned) Sco_SCOPE_SYS,UsrCod,Sco_ScopeDB[Sco_SCOPE_SYS],
(unsigned) Sco_SCOPE_INS,UsrCod,Sco_ScopeDB[Sco_SCOPE_INS],
(unsigned) Sco_SCOPE_CTR,UsrCod,Sco_ScopeDB[Sco_SCOPE_CTR],
(unsigned) Sco_SCOPE_DEG,UsrCod,Sco_ScopeDB[Sco_SCOPE_DEG]);
2015-11-23 00:44:39 +01:00
if ((NumRows = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get institutions, centres, degrees admin by a user")))
2014-12-01 23:55:08 +01:00
/***** Get the list of degrees *****/
for (NumRow = 1;
NumRow <= NumRows;
NumRow++)
{
/***** Indent *****/
fprintf (Gbl.F.Out,"<tr>"
2015-09-03 00:59:03 +02:00
"<td class=\"RIGHT_TOP COLOR%u\">"
2015-07-21 20:07:46 +02:00
"<img src=\"%s/%s20x20.gif\""
" alt=\"\" title=\"\""
2016-11-14 10:05:41 +01:00
" class=\"ICO25x25\" />"
2014-12-01 23:55:08 +01:00
"</td>",
2015-09-03 00:59:03 +02:00
Gbl.RowEvenOdd,Gbl.Prefs.IconsURL,
2014-12-01 23:55:08 +01:00
NumRow == NumRows ? "subend" :
"submid");
2015-11-23 00:44:39 +01:00
/***** Write institution, centre, degree *****/
2015-07-31 19:49:21 +02:00
fprintf (Gbl.F.Out,"<td colspan=\"%u\""
2015-09-03 00:59:03 +02:00
" class=\"DAT_SMALL_NOBR LEFT_TOP COLOR%u\">",
ColSpan - 1,Gbl.RowEvenOdd);
2014-12-01 23:55:08 +01:00
2015-11-23 00:44:39 +01:00
/* Get next institution, centre, degree */
2014-12-01 23:55:08 +01:00
row = mysql_fetch_row (mysql_res);
2015-11-23 00:44:39 +01:00
/* Get scope */
switch (Sco_GetScopeFromUnsignedStr (row[0]))
{
case Sco_SCOPE_SYS: // System
2015-12-12 19:47:10 +01:00
fprintf (Gbl.F.Out,"<img src=\"%s/swad64x64.gif\""
2015-11-23 00:44:39 +01:00
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />"
2015-11-23 00:44:39 +01:00
"&nbsp;%s",
2014-12-01 23:55:08 +01:00
Gbl.Prefs.IconsURL,
Txt_all_degrees,
2015-07-21 20:07:46 +02:00
Txt_all_degrees,
2014-12-01 23:55:08 +01:00
Txt_all_degrees);
2015-11-23 00:44:39 +01:00
break;
case Sco_SCOPE_INS: // Institution
Ins.InsCod = Str_ConvertStrCodToLongCod (row[1]);
if (Ins.InsCod > 0)
{
/* Get data of institution */
2015-12-09 19:51:17 +01:00
Ins_GetDataOfInstitutionByCod (&Ins,Ins_GET_BASIC_DATA);
2015-11-23 00:44:39 +01:00
/* Write institution logo and name */
Ins_DrawInstitutionLogoAndNameWithLink (&Ins,ActSeeInsInf,
"DAT_SMALL_NOBR","LEFT_TOP");
}
break;
case Sco_SCOPE_CTR: // Centre
Ctr.CtrCod = Str_ConvertStrCodToLongCod (row[1]);
if (Ctr.CtrCod > 0)
{
/* Get data of centre */
Ctr_GetDataOfCentreByCod (&Ctr);
/* Write centre logo and name */
Ctr_DrawCentreLogoAndNameWithLink (&Ctr,ActSeeCtrInf,
"DAT_SMALL_NOBR","LEFT_TOP");
}
break;
case Sco_SCOPE_DEG: // Degree
Deg.DegCod = Str_ConvertStrCodToLongCod (row[1]);
if (Deg.DegCod > 0)
{
/* Get data of degree */
Deg_GetDataOfDegreeByCod (&Deg);
/* Write degree logo and name */
Deg_DrawDegreeLogoAndNameWithLink (&Deg,ActSeeDegInf,
"DAT_SMALL_NOBR","LEFT_TOP");
}
break;
default: // There are no administrators in other scopes
Lay_ShowErrorAndExit ("Wrong scope.");
break;
}
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/****************************** List degrees found ***************************/
/*****************************************************************************/
// Returns number of degrees found
unsigned Deg_ListDegsFound (const char *Query)
{
extern const char *Txt_degree;
extern const char *Txt_degrees;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumDegs;
unsigned NumDeg;
struct Degree Deg;
/***** Query database *****/
if ((NumDegs = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get degrees")))
{
/***** Write heading *****/
/* Number of degrees found */
2016-04-17 23:28:38 +02:00
sprintf (Gbl.Title,"%u %s",
NumDegs,(NumDegs == 1) ? Txt_degree :
Txt_degrees);
2016-11-13 23:52:51 +01:00
Lay_StartRoundFrameTable (NULL,Gbl.Title,NULL,NULL,2);
2014-12-01 23:55:08 +01:00
Deg_PutHeadDegreesForSeeing ();
/***** List the degrees (one row per degree) *****/
for (NumDeg = 1;
NumDeg <= NumDegs;
NumDeg++)
{
/* Get next degree */
row = mysql_fetch_row (mysql_res);
/* Get degree code (row[0]) */
Deg.DegCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get data of degree */
Deg_GetDataOfDegreeByCod (&Deg);
/* Write data of this degree */
Deg_ListOneDegreeForSeeing (&Deg,NumDeg);
}
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 NumDegs;
}