swad-core/swad_course.c

2903 lines
100 KiB
C
Raw Normal View History

2014-12-01 23:55:08 +01:00
// swad_course.c: edition of courses
/*
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.
2020-01-01 14:53:57 +01:00
Copyright (C) 1999-2020 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 ***********************************/
/*****************************************************************************/
2018-10-20 12:03:57 +02:00
#define _GNU_SOURCE // For asprintf
2019-12-29 12:39:00 +01:00
#include <stddef.h> // For NULL
2018-10-20 12:03:57 +02:00
#include <stdio.h> // For asprintf
2020-01-03 22:16:51 +01:00
#include <stdlib.h> // For free
2014-12-01 23:55:08 +01:00
#include <string.h> // For string functions
#include "swad_course.h"
2019-12-29 13:13:09 +01:00
#include "swad_course_config.h"
2014-12-01 23:55:08 +01:00
#include "swad_database.h"
2018-11-09 20:47:39 +01:00
#include "swad_form.h"
2014-12-01 23:55:08 +01:00
#include "swad_global.h"
2015-10-06 20:34:49 +02:00
#include "swad_help.h"
2019-10-23 19:05:05 +02:00
#include "swad_HTML.h"
2019-12-29 12:39:00 +01:00
#include "swad_info.h"
2015-01-17 20:06:25 +01:00
#include "swad_logo.h"
2020-04-08 13:40:21 +02:00
#include "swad_search.h"
2020-04-02 03:28:08 +02:00
#include "swad_test_exam.h"
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/*************************** Public constants ********************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private types *********************************/
/*****************************************************************************/
/*****************************************************************************/
2019-04-07 19:49:53 +02:00
/**************************** Private variables ******************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2019-04-08 23:34:58 +02:00
static struct Course *Crs_EditingCrs = NULL; // Static variable to keep the course being edited
2019-04-07 19:49:53 +02:00
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/**************************** Private prototypes *****************************/
/*****************************************************************************/
static void Crs_WriteListMyCoursesToSelectOne (void);
2020-01-05 12:52:03 +01:00
static void Crs_GetListCrssInCurrentDeg (Crs_WhatCourses_t WhatCourses);
2014-12-01 23:55:08 +01:00
static void Crs_ListCourses (void);
2016-11-07 00:03:50 +01:00
static bool Crs_CheckIfICanCreateCourses (void);
2020-04-08 13:40:21 +02:00
static void Crs_PutIconsListCourses (__attribute__((unused)) void *Args);
2016-03-16 22:40:35 +01:00
static void Crs_PutIconToEditCourses (void);
2015-12-06 14:18:07 +01:00
static bool Crs_ListCoursesOfAYearForSeeing (unsigned Year);
2016-03-20 12:35:27 +01:00
2019-04-07 19:49:53 +02:00
static void Crs_EditCoursesInternal (void);
2020-04-08 13:40:21 +02:00
static void Crs_PutIconsEditingCourses (__attribute__((unused)) void *Args);
2017-04-30 12:44:53 +02:00
static void Crs_PutIconToViewCourses (void);
2014-12-01 23:55:08 +01:00
static void Crs_ListCoursesForEdition (void);
2016-07-04 09:54:36 +02:00
static void Crs_ListCoursesOfAYearForEdition (unsigned Year);
2014-12-01 23:55:08 +01:00
static bool Crs_CheckIfICanEdit (struct Course *Crs);
static Crs_StatusTxt_t Crs_GetStatusTxtFromStatusBits (Crs_Status_t Status);
static Crs_Status_t Crs_GetStatusBitsFromStatusTxt (Crs_StatusTxt_t StatusTxt);
static void Crs_PutFormToCreateCourse (void);
static void Crs_PutHeadCoursesForSeeing (void);
static void Crs_PutHeadCoursesForEdition (void);
static void Crs_RecFormRequestOrCreateCrs (unsigned Status);
static void Crs_GetParamsNewCourse (struct Course *Crs);
2017-03-09 11:16:17 +01:00
2017-05-11 20:04:38 +02:00
static void Crs_CreateCourse (unsigned Status);
2014-12-01 23:55:08 +01:00
static void Crs_GetDataOfCourseFromRow (struct Course *Crs,MYSQL_ROW row);
2016-06-12 01:18:35 +02:00
2017-01-13 01:51:23 +01:00
static void Crs_GetShortNamesByCod (long CrsCod,
2017-03-08 14:12:33 +01:00
char CrsShortName[Hie_MAX_BYTES_SHRT_NAME + 1],
char DegShortName[Hie_MAX_BYTES_SHRT_NAME + 1]);
2017-01-13 01:51:23 +01:00
2014-12-01 23:55:08 +01:00
static void Crs_EmptyCourseCompletely (long CrsCod);
2016-10-23 17:20:06 +02:00
2017-03-09 11:16:17 +01:00
static void Crs_UpdateCrsNameDB (long CrsCod,const char *FieldName,const char *NewCrsName);
2017-05-11 20:55:04 +02:00
static void Crs_PutButtonToGoToCrs (void);
static void Crs_PutButtonToRegisterInCrs (void);
2015-04-02 18:39:49 +02:00
2020-04-08 13:40:21 +02:00
static void Crs_PutIconToSearchCourses (__attribute__((unused)) void *Args);
2014-12-01 23:55:08 +01:00
static void Crs_PutParamOtherCrsCod (long CrsCod);
2017-05-31 21:05:59 +02:00
static long Crs_GetAndCheckParamOtherCrsCod (long MinCodAllowed);
2014-12-01 23:55:08 +01:00
static void Crs_WriteRowCrsData (unsigned NumCrs,MYSQL_ROW row,bool WriteColumnAccepted);
2019-04-07 19:49:53 +02:00
static void Crs_EditingCourseConstructor (void);
static void Crs_EditingCourseDestructor (void);
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/***************** Show introduction to the current course *******************/
/*****************************************************************************/
void Crs_ShowIntroduction (void)
{
/***** Course configuration *****/
2019-10-23 21:37:01 +02:00
HTM_DIV_Begin ("class=\"CM\"");
2019-12-29 13:13:09 +01:00
CrsCfg_Configuration (false);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2014-12-01 23:55:08 +01:00
/***** Course introduction *****/
Inf_ShowInfo ();
2015-10-06 01:19:21 +02:00
2017-03-30 11:20:06 +02:00
/***** Show help to enrol me *****/
2015-12-06 14:18:07 +01:00
Hlp_ShowHelpWhatWouldYouLikeToDo ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************ Write menu with my courses *************************/
/*****************************************************************************/
2015-12-15 01:33:09 +01:00
#define Crs_MAX_BYTES_TXT_LINK 40
2014-12-29 22:41:43 +01:00
2014-12-01 23:55:08 +01:00
static void Crs_WriteListMyCoursesToSelectOne (void)
{
2016-11-13 13:23:09 +01:00
extern const char *Hlp_PROFILE_Courses;
2019-11-18 14:21:01 +01:00
extern const char *The_ClassFormLinkInBox[The_NUM_THEMES];
extern const char *The_ClassFormLinkInBoxBold[The_NUM_THEMES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_My_courses;
2015-02-05 00:55:47 +01:00
extern const char *Txt_System;
2014-12-29 00:54:56 +01:00
struct Country Cty;
2016-10-28 10:03:37 +02:00
struct Instit Ins;
2014-12-29 00:54:56 +01:00
struct Centre Ctr;
2014-12-01 23:55:08 +01:00
struct Degree Deg;
struct Course Crs;
2017-01-13 01:51:23 +01:00
bool IsLastItemInLevel[1 + 5];
2014-12-29 20:22:46 +01:00
bool Highlight; // Highlight because degree, course, etc. is selected
2014-12-29 00:54:56 +01:00
MYSQL_RES *mysql_resCty;
MYSQL_RES *mysql_resIns;
MYSQL_RES *mysql_resCtr;
MYSQL_RES *mysql_resDeg;
MYSQL_RES *mysql_resCrs;
MYSQL_ROW row;
2016-04-16 15:05:18 +02:00
unsigned NumCty;
unsigned NumCtys;
unsigned NumIns;
unsigned NumInss;
unsigned NumCtr;
unsigned NumCtrs;
unsigned NumDeg;
unsigned NumDegs;
unsigned NumCrs;
unsigned NumCrss;
2017-01-13 01:51:23 +01:00
const char *ClassNormal;
2015-12-25 21:19:31 +01:00
char ClassHighlight[64];
2019-11-18 14:21:01 +01:00
ClassNormal = The_ClassFormLinkInBox[Gbl.Prefs.Theme];
2018-10-17 10:32:18 +02:00
snprintf (ClassHighlight,sizeof (ClassHighlight),
"%s LIGHT_BLUE",
2019-11-18 14:21:01 +01:00
The_ClassFormLinkInBoxBold[Gbl.Prefs.Theme]);
2014-12-29 00:54:56 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2020-03-26 02:54:30 +01:00
Box_BoxBegin (NULL,Txt_My_courses,
2020-04-08 13:40:21 +02:00
Crs_PutIconToSearchCourses,NULL,
2017-06-12 15:03:29 +02:00
Hlp_PROFILE_Courses,Box_NOT_CLOSABLE);
2019-10-26 12:25:27 +02:00
HTM_UL_Begin ("class=\"LIST_TREE\"");
2014-12-29 20:22:46 +01:00
/***** Write link to platform *****/
2019-04-03 20:57:04 +02:00
Highlight = (Gbl.Hierarchy.Cty.CtyCod <= 0);
2019-10-26 22:49:13 +02:00
HTM_LI_Begin ("class=\"%s\"",Highlight ? ClassHighlight :
ClassNormal);
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActMyCrs);
2015-12-25 22:05:28 +01:00
Cty_PutParamCtyCod (-1L);
2019-11-20 10:17:42 +01:00
HTM_BUTTON_SUBMIT_Begin (Txt_System,
2019-11-20 11:04:54 +01:00
Highlight ? ClassHighlight :
ClassNormal,
NULL);
2019-10-29 09:01:05 +01:00
Ico_PutIcon ("sitemap.svg",Txt_System,"ICO16x16");
2019-11-11 10:59:24 +01:00
HTM_TxtF ("&nbsp;%s",Txt_System);
2019-11-18 11:23:48 +01:00
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-26 22:49:13 +02:00
HTM_LI_End ();
2014-12-29 00:54:56 +01:00
/***** Get my countries *****/
NumCtys = Usr_GetCtysFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,&mysql_resCty);
for (NumCty = 0;
NumCty < NumCtys;
NumCty++)
2014-12-01 23:55:08 +01:00
{
2014-12-29 00:54:56 +01:00
/***** Get next institution *****/
row = mysql_fetch_row (mysql_resCty);
/***** Get data of this institution *****/
Cty.CtyCod = Str_ConvertStrCodToLongCod (row[0]);
2020-01-07 22:07:06 +01:00
if (!Cty_GetDataOfCountryByCod (&Cty))
2014-12-29 00:54:56 +01:00
Lay_ShowErrorAndExit ("Country not found.");
/***** Write link to country *****/
2019-04-03 20:57:04 +02:00
Highlight = (Gbl.Hierarchy.Ins.InsCod <= 0 &&
Gbl.Hierarchy.Cty.CtyCod == Cty.CtyCod);
2019-10-26 22:49:13 +02:00
HTM_LI_Begin ("class=\"%s\"",Highlight ? ClassHighlight :
ClassNormal);
2014-12-29 13:26:39 +01:00
IsLastItemInLevel[1] = (NumCty == NumCtys - 1);
Lay_IndentDependingOnLevel (1,IsLastItemInLevel);
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActMyCrs);
2014-12-29 00:54:56 +01:00
Cty_PutParamCtyCod (Cty.CtyCod);
2020-01-02 13:58:13 +01:00
HTM_BUTTON_SUBMIT_Begin (Act_GetActionText (ActSeeCtyInf),
Highlight ? ClassHighlight :
ClassNormal,
NULL);
2019-10-30 22:31:03 +01:00
Cty_DrawCountryMap (&Cty,"ICO16x16");
2019-11-11 10:59:24 +01:00
HTM_TxtF ("&nbsp;%s",Cty.Name[Gbl.Prefs.Language]);
2019-11-18 11:23:48 +01:00
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-26 22:49:13 +02:00
HTM_LI_End ();
2014-12-29 00:54:56 +01:00
/***** Get my institutions in this country *****/
2014-12-29 20:22:46 +01:00
NumInss = (unsigned) Usr_GetInssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,
Cty.CtyCod,&mysql_resIns);
2014-12-29 00:54:56 +01:00
for (NumIns = 0;
NumIns < NumInss;
NumIns++)
{
/***** Get next institution *****/
row = mysql_fetch_row (mysql_resIns);
/***** Get data of this institution *****/
Ins.InsCod = Str_ConvertStrCodToLongCod (row[0]);
2020-01-07 00:09:30 +01:00
if (!Ins_GetDataOfInstitutionByCod (&Ins))
2014-12-29 00:54:56 +01:00
Lay_ShowErrorAndExit ("Institution not found.");
/***** Write link to institution *****/
2019-04-03 20:57:04 +02:00
Highlight = (Gbl.Hierarchy.Ctr.CtrCod <= 0 &&
Gbl.Hierarchy.Ins.InsCod == Ins.InsCod);
2019-10-26 22:49:13 +02:00
HTM_LI_Begin ("class=\"%s\"",Highlight ? ClassHighlight :
ClassNormal);
2014-12-29 13:26:39 +01:00
IsLastItemInLevel[2] = (NumIns == NumInss - 1);
Lay_IndentDependingOnLevel (2,IsLastItemInLevel);
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActMyCrs);
2014-12-29 00:54:56 +01:00
Ins_PutParamInsCod (Ins.InsCod);
2020-01-02 13:58:13 +01:00
HTM_BUTTON_SUBMIT_Begin (Act_GetActionText (ActSeeInsInf),
Highlight ? ClassHighlight :
ClassNormal,
NULL);
2019-12-14 14:30:34 +01:00
Lgo_DrawLogo (Hie_INS,Ins.InsCod,Ins.ShrtName,16,NULL,true);
2019-11-18 11:23:48 +01:00
HTM_TxtF ("&nbsp;%s",Ins.ShrtName);
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-26 22:49:13 +02:00
HTM_LI_End ();
2014-12-29 00:54:56 +01:00
/***** Get my centres in this institution *****/
2014-12-29 20:22:46 +01:00
NumCtrs = (unsigned) Usr_GetCtrsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,
Ins.InsCod,&mysql_resCtr);
2014-12-29 00:54:56 +01:00
for (NumCtr = 0;
NumCtr < NumCtrs;
NumCtr++)
{
/***** Get next centre *****/
row = mysql_fetch_row (mysql_resCtr);
/***** Get data of this centre *****/
Ctr.CtrCod = Str_ConvertStrCodToLongCod (row[0]);
2020-01-05 02:18:20 +01:00
if (!Ctr_GetDataOfCentreByCod (&Ctr))
2014-12-29 00:54:56 +01:00
Lay_ShowErrorAndExit ("Centre not found.");
/***** Write link to centre *****/
2019-04-03 20:57:04 +02:00
Highlight = (Gbl.Hierarchy.Level == Hie_CTR &&
Gbl.Hierarchy.Ctr.CtrCod == Ctr.CtrCod);
2019-10-26 22:49:13 +02:00
HTM_LI_Begin ("class=\"%s\"",Highlight ? ClassHighlight :
ClassNormal);
2014-12-29 13:26:39 +01:00
IsLastItemInLevel[3] = (NumCtr == NumCtrs - 1);
Lay_IndentDependingOnLevel (3,IsLastItemInLevel);
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActMyCrs);
2014-12-29 00:54:56 +01:00
Ctr_PutParamCtrCod (Ctr.CtrCod);
2020-01-02 13:58:13 +01:00
HTM_BUTTON_SUBMIT_Begin (Act_GetActionText (ActSeeCtrInf),
Highlight ? ClassHighlight :
ClassNormal,
NULL);
2019-12-14 14:30:34 +01:00
Lgo_DrawLogo (Hie_CTR,Ctr.CtrCod,Ctr.ShrtName,16,NULL,true);
2019-11-18 11:23:48 +01:00
HTM_TxtF ("&nbsp;%s",Ctr.ShrtName);
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-26 22:49:13 +02:00
HTM_LI_End ();
2014-12-29 00:54:56 +01:00
/***** Get my degrees in this centre *****/
2014-12-29 20:22:46 +01:00
NumDegs = (unsigned) Usr_GetDegsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,
Ctr.CtrCod,&mysql_resDeg);
2014-12-29 00:54:56 +01:00
for (NumDeg = 0;
NumDeg < NumDegs;
NumDeg++)
{
/***** Get next degree *****/
row = mysql_fetch_row (mysql_resDeg);
/***** Get data of this degree *****/
Deg.DegCod = Str_ConvertStrCodToLongCod (row[0]);
2020-01-05 12:52:03 +01:00
if (!Deg_GetDataOfDegreeByCod (&Deg))
2014-12-29 00:54:56 +01:00
Lay_ShowErrorAndExit ("Degree not found.");
/***** Write link to degree *****/
2019-04-03 20:57:04 +02:00
Highlight = (Gbl.Hierarchy.Level == Hie_DEG &&
Gbl.Hierarchy.Deg.DegCod == Deg.DegCod);
2019-10-26 22:49:13 +02:00
HTM_LI_Begin ("class=\"%s\"",Highlight ? ClassHighlight :
ClassNormal);
2014-12-29 13:26:39 +01:00
IsLastItemInLevel[4] = (NumDeg == NumDegs - 1);
Lay_IndentDependingOnLevel (4,IsLastItemInLevel);
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActMyCrs);
2014-12-29 00:54:56 +01:00
Deg_PutParamDegCod (Deg.DegCod);
2020-01-02 13:58:13 +01:00
HTM_BUTTON_SUBMIT_Begin (Act_GetActionText (ActSeeDegInf),
Highlight ? ClassHighlight :
ClassNormal,
NULL);
2019-12-14 14:30:34 +01:00
Lgo_DrawLogo (Hie_DEG,Deg.DegCod,Deg.ShrtName,16,NULL,true);
2019-11-18 11:23:48 +01:00
HTM_TxtF ("&nbsp;%s",Deg.ShrtName);
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-26 22:49:13 +02:00
HTM_LI_End ();
2014-12-29 00:54:56 +01:00
/***** Get my courses in this degree *****/
2014-12-29 20:22:46 +01:00
NumCrss = (unsigned) Usr_GetCrssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,
Deg.DegCod,&mysql_resCrs);
2014-12-29 00:54:56 +01:00
for (NumCrs = 0;
NumCrs < NumCrss;
NumCrs++)
{
/***** Get next course *****/
row = mysql_fetch_row (mysql_resCrs);
/***** Get data of this course *****/
Crs.CrsCod = Str_ConvertStrCodToLongCod (row[0]);
2020-01-05 14:09:28 +01:00
if (!Crs_GetDataOfCourseByCod (&Crs))
2014-12-29 00:54:56 +01:00
Lay_ShowErrorAndExit ("Course not found.");
/***** Write link to course *****/
2019-04-03 20:57:04 +02:00
Highlight = (Gbl.Hierarchy.Level == Hie_CRS &&
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod == Crs.CrsCod);
2019-10-26 22:49:13 +02:00
HTM_LI_Begin ("class=\"%s\"",Highlight ? ClassHighlight :
ClassNormal);
2014-12-29 13:26:39 +01:00
IsLastItemInLevel[5] = (NumCrs == NumCrss - 1);
Lay_IndentDependingOnLevel (5,IsLastItemInLevel);
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActMyCrs);
2014-12-29 00:54:56 +01:00
Crs_PutParamCrsCod (Crs.CrsCod);
2019-12-30 12:25:45 +01:00
HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Crs.ShrtName),
2019-11-20 11:04:54 +01:00
Highlight ? ClassHighlight :
ClassNormal,
NULL);
2019-12-30 12:25:45 +01:00
Hie_FreeGoToMsg ();
2020-02-20 00:32:07 +01:00
Ico_PutIcon ("chalkboard-teacher.svg",Crs.FullName,"ICO16x16");
2019-11-18 11:23:48 +01:00
HTM_TxtF ("&nbsp;%s",Crs.ShrtName);
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2017-05-29 13:20:48 +02:00
/***** Put link to register students *****/
2017-05-29 21:34:43 +02:00
Enr_PutButtonInlineToRegisterStds (Crs.CrsCod);
2017-05-29 13:20:48 +02:00
2019-10-26 22:49:13 +02:00
HTM_LI_End ();
2014-12-29 00:54:56 +01:00
}
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_resCrs);
}
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_resDeg);
}
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_resCtr);
}
2014-12-01 23:55:08 +01:00
2014-12-29 00:54:56 +01:00
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_resIns);
2014-12-01 23:55:08 +01:00
}
2014-12-29 00:54:56 +01:00
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_resCty);
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-26 02:19:42 +02:00
HTM_UL_End ();
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********************** Get total number of courses *************************/
/*****************************************************************************/
unsigned Crs_GetNumCrssTotal (void)
{
/***** Get total number of courses from database *****/
2018-11-04 20:51:38 +01:00
return (unsigned) DB_GetNumRowsTable ("courses");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************** Get number of courses in a country ***********************/
/*****************************************************************************/
2020-01-07 15:11:48 +01:00
void Crs_FlushCacheNumCrssInCty (void)
{
Gbl.Cache.NumCrssInCty.CtyCod = -1L;
Gbl.Cache.NumCrssInCty.NumCrss = 0;
}
2014-12-01 23:55:08 +01:00
unsigned Crs_GetNumCrssInCty (long CtyCod)
{
2020-01-07 15:11:48 +01:00
/***** 1. Fast check: Trivial case *****/
if (CtyCod <= 0)
return 0;
/***** 2. Fast check: If cached... *****/
if (CtyCod == Gbl.Cache.NumCrssInCty.CtyCod)
return Gbl.Cache.NumCrssInCty.NumCrss;
/***** 3. Slow: number of courses in a country from database *****/
Gbl.Cache.NumCrssInCty.CtyCod = CtyCod;
Gbl.Cache.NumCrssInCty.NumCrss =
2018-11-03 13:13:11 +01:00
(unsigned) DB_QueryCOUNT ("can not get the number of courses in a country",
"SELECT COUNT(*)"
" FROM institutions,centres,degrees,courses"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod",
CtyCod);
2020-01-07 15:11:48 +01:00
return Gbl.Cache.NumCrssInCty.NumCrss;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/**************** Get number of courses in an institution ********************/
/*****************************************************************************/
2020-01-06 18:43:48 +01:00
void Crs_FlushCacheNumCrssInIns (void)
{
Gbl.Cache.NumCrssInIns.InsCod = -1L;
Gbl.Cache.NumCrssInIns.NumCrss = 0;
}
2014-12-01 23:55:08 +01:00
unsigned Crs_GetNumCrssInIns (long InsCod)
{
2020-01-06 18:43:48 +01:00
/***** 1. Fast check: Trivial case *****/
if (InsCod <= 0)
return 0;
/***** 2. Fast check: If cached... *****/
if (InsCod == Gbl.Cache.NumCrssInIns.InsCod)
return Gbl.Cache.NumCrssInIns.NumCrss;
/***** 3. Slow: number of courses in an institution from database *****/
Gbl.Cache.NumCrssInIns.InsCod = InsCod;
Gbl.Cache.NumCrssInIns.NumCrss =
2018-11-03 13:13:11 +01:00
(unsigned) DB_QueryCOUNT ("can not get the number of courses"
" in an institution",
"SELECT COUNT(*) FROM centres,degrees,courses"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod",
InsCod);
2020-01-06 18:43:48 +01:00
return Gbl.Cache.NumCrssInIns.NumCrss;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Get number of courses in a centre **********************/
/*****************************************************************************/
2020-01-05 01:46:45 +01:00
void Crs_FlushCacheNumCrssInCtr (void)
{
Gbl.Cache.NumCrssInCtr.CtrCod = -1L;
Gbl.Cache.NumCrssInCtr.NumCrss = 0;
}
2014-12-01 23:55:08 +01:00
unsigned Crs_GetNumCrssInCtr (long CtrCod)
{
2020-01-05 01:46:45 +01:00
/***** 1. Fast check: Trivial case *****/
if (CtrCod <= 0)
return 0;
/***** 2. Fast check: If cached... *****/
if (CtrCod == Gbl.Cache.NumCrssInCtr.CtrCod)
return Gbl.Cache.NumCrssInCtr.NumCrss;
/***** 3. Slow: number of courses in a centre from database *****/
Gbl.Cache.NumCrssInCtr.CtrCod = CtrCod;
Gbl.Cache.NumCrssInCtr.NumCrss =
2018-11-03 13:13:11 +01:00
(unsigned) DB_QueryCOUNT ("can not get the number of courses in a centre",
"SELECT COUNT(*) FROM degrees,courses"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod",
CtrCod);
2020-01-05 01:46:45 +01:00
return Gbl.Cache.NumCrssInCtr.NumCrss;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Get number of courses in a degree **********************/
/*****************************************************************************/
2020-01-05 12:52:03 +01:00
void Crs_FlushCacheNumCrssInDeg (void)
{
Gbl.Cache.NumCrssInDeg.DegCod = -1L;
Gbl.Cache.NumCrssInDeg.NumCrss = 0;
}
2014-12-01 23:55:08 +01:00
unsigned Crs_GetNumCrssInDeg (long DegCod)
{
2020-01-05 12:52:03 +01:00
/***** 1. Fast check: Trivial case *****/
if (DegCod <= 0)
return 0;
/***** 2. Fast check: If cached... *****/
if (DegCod == Gbl.Cache.NumCrssInDeg.DegCod)
return Gbl.Cache.NumCrssInDeg.NumCrss;
/***** 3. Slow: number of courses in a degree from database *****/
Gbl.Cache.NumCrssInDeg.DegCod = DegCod;
Gbl.Cache.NumCrssInDeg.NumCrss =
2018-11-03 13:13:11 +01:00
(unsigned) DB_QueryCOUNT ("can not get the number of courses in a degree",
"SELECT COUNT(*) FROM courses"
" WHERE DegCod=%ld",
DegCod);
2020-01-05 12:52:03 +01:00
return Gbl.Cache.NumCrssInDeg.NumCrss;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Get number of courses with users **********************/
/*****************************************************************************/
unsigned Crs_GetNumCrssWithUsrs (Rol_Role_t Role,const char *SubQuery)
{
/***** Get number of degrees with users from database *****/
2018-11-03 13:13:11 +01:00
return
(unsigned) DB_QueryCOUNT ("can not get number of courses with users",
"SELECT COUNT(DISTINCT courses.CrsCod)"
" FROM institutions,centres,degrees,courses,crs_usr"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u",
SubQuery,(unsigned) Role);
2014-12-01 23:55:08 +01:00
}
2015-07-25 20:20:07 +02:00
/*****************************************************************************/
/*************************** Write selector of course ************************/
/*****************************************************************************/
void Crs_WriteSelectorOfCourse (void)
{
extern const char *Txt_Course;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCrss;
unsigned NumCrs;
long CrsCod;
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
2018-11-09 20:47:39 +01:00
Frm_StartFormGoTo (ActSeeCrsInf);
2019-04-03 20:57:04 +02:00
if (Gbl.Hierarchy.Deg.DegCod > 0)
2019-11-05 15:47:35 +01:00
HTM_SELECT_Begin (true,
"id=\"crs\" name=\"crs\" class=\"HIE_SEL\"");
2015-07-25 20:20:07 +02:00
else
2019-11-05 15:47:35 +01:00
HTM_SELECT_Begin (false,
"id=\"crs\" name=\"crs\" class=\"HIE_SEL\""
" disabled=\"disabled\"");
2019-11-06 19:45:20 +01:00
HTM_OPTION (HTM_Type_STRING,"",Gbl.Hierarchy.Crs.CrsCod < 0,true,
2019-11-06 08:59:15 +01:00
"[%s]",Txt_Course);
2015-07-25 20:20:07 +02:00
2019-04-03 20:57:04 +02:00
if (Gbl.Hierarchy.Deg.DegCod > 0)
2015-07-25 20:20:07 +02:00
{
/***** Get courses belonging to the current degree from database *****/
2018-10-30 14:47:31 +01:00
NumCrss = (unsigned) DB_QuerySELECT (&mysql_res,"can not get courses"
" of a degree",
"SELECT CrsCod,ShortName FROM courses"
" WHERE DegCod=%ld"
" ORDER BY ShortName",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Deg.DegCod);
2015-07-25 20:20:07 +02:00
/***** Get courses of this degree *****/
for (NumCrs = 0;
NumCrs < NumCrss;
NumCrs++)
{
/* Get next course */
row = mysql_fetch_row (mysql_res);
/* Get course code (row[0]) */
if ((CrsCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong course.");
/* Write option */
2019-11-06 19:45:20 +01:00
HTM_OPTION (HTM_Type_LONG,&CrsCod,
2019-11-06 08:59:15 +01:00
Gbl.Hierarchy.Level == Hie_CRS && // Course selected
CrsCod == Gbl.Hierarchy.Crs.CrsCod,false,
"%s",row[1]);
2015-07-25 20:20:07 +02:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/***** End form *****/
2019-11-05 08:46:38 +01:00
HTM_SELECT_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-07-25 20:20:07 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************** Show courses of a degree *************************/
/*****************************************************************************/
void Crs_ShowCrssOfCurrentDeg (void)
{
2019-04-03 20:57:04 +02:00
/***** Trivial check *****/
if (Gbl.Hierarchy.Deg.DegCod <= 0) // No degree selected
return;
/***** Get list of courses in this degree *****/
2020-01-05 12:52:03 +01:00
Crs_GetListCrssInCurrentDeg (Crs_ALL_COURSES_EXCEPT_REMOVED);
2014-12-01 23:55:08 +01:00
2019-04-03 20:57:04 +02:00
/***** Write menu to select country, institution, centre and degree *****/
Hie_WriteMenuHierarchy ();
2014-12-01 23:55:08 +01:00
2019-04-03 20:57:04 +02:00
/***** Show list of courses *****/
Crs_ListCourses ();
2014-12-01 23:55:08 +01:00
2019-04-03 20:57:04 +02:00
/***** Free list of courses in this degree *****/
2019-04-07 12:17:10 +02:00
Crs_FreeListCoursesInCurrentDegree ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2016-04-16 15:05:18 +02:00
/*************** Create a list with courses in current degree ****************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2020-01-05 12:52:03 +01:00
static void Crs_GetListCrssInCurrentDeg (Crs_WhatCourses_t WhatCourses)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2016-04-16 15:05:18 +02:00
unsigned NumCrss;
2014-12-01 23:55:08 +01:00
unsigned NumCrs;
struct Course *Crs;
/***** Get courses of a degree from database *****/
switch (WhatCourses)
{
case Crs_ACTIVE_COURSES:
2018-10-30 14:47:31 +01:00
NumCrss = (unsigned) DB_QuerySELECT (&mysql_res,"can not get courses"
" of a degree",
"SELECT CrsCod,DegCod,Year,InsCrsCod,Status,RequesterUsrCod,ShortName,FullName"
" FROM courses WHERE DegCod=%ld AND Status=0"
" ORDER BY Year,ShortName",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Deg.DegCod);
2014-12-01 23:55:08 +01:00
break;
case Crs_ALL_COURSES_EXCEPT_REMOVED:
2018-10-30 14:47:31 +01:00
NumCrss = (unsigned) DB_QuerySELECT (&mysql_res,"can not get courses"
" of a degree",
"SELECT CrsCod,DegCod,Year,InsCrsCod,Status,RequesterUsrCod,ShortName,FullName"
" FROM courses WHERE DegCod=%ld AND (Status & %u)=0"
" ORDER BY Year,ShortName",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Deg.DegCod,
2018-10-30 14:47:31 +01:00
(unsigned) Crs_STATUS_BIT_REMOVED);
2014-12-01 23:55:08 +01:00
break;
default:
break;
}
2016-04-16 15:05:18 +02:00
if (NumCrss) // Courses found...
2014-12-01 23:55:08 +01:00
{
/***** Create list with courses in degree *****/
2020-01-08 14:04:25 +01:00
if ((Gbl.Hierarchy.Crss.Lst = (struct Course *) calloc ((size_t) NumCrss,
2019-04-03 20:57:04 +02:00
sizeof (struct Course))) == NULL)
2018-10-18 20:06:54 +02:00
Lay_NotEnoughMemoryExit ();
2014-12-01 23:55:08 +01:00
/***** Get the courses in degree *****/
for (NumCrs = 0;
2016-04-16 15:05:18 +02:00
NumCrs < NumCrss;
2014-12-01 23:55:08 +01:00
NumCrs++)
{
2020-01-08 14:04:25 +01:00
Crs = &Gbl.Hierarchy.Crss.Lst[NumCrs];
2014-12-01 23:55:08 +01:00
/* Get next course */
row = mysql_fetch_row (mysql_res);
Crs_GetDataOfCourseFromRow (Crs,row);
}
}
2016-04-16 15:05:18 +02:00
2020-01-08 14:04:25 +01:00
Gbl.Hierarchy.Crss.Num = NumCrss;
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/********************* Free list of courses in this degree *******************/
/*****************************************************************************/
2019-04-07 12:17:10 +02:00
void Crs_FreeListCoursesInCurrentDegree (void)
2014-12-01 23:55:08 +01:00
{
2020-01-08 14:04:25 +01:00
if (Gbl.Hierarchy.Crss.Lst)
2014-12-01 23:55:08 +01:00
{
/***** Free memory used by the list of courses in degree *****/
2020-01-08 14:04:25 +01:00
free (Gbl.Hierarchy.Crss.Lst);
Gbl.Hierarchy.Crss.Lst = NULL;
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/********************** Write selector of my coursess ************************/
/*****************************************************************************/
2018-10-09 17:56:18 +02:00
void Crs_WriteSelectorMyCoursesInBreadcrumb (void)
2014-12-01 23:55:08 +01:00
{
2015-12-26 18:58:35 +01:00
extern const char *Txt_Course;
2014-12-01 23:55:08 +01:00
unsigned NumMyCrs;
long CrsCod;
long DegCod;
long LastDegCod;
2017-03-08 14:12:33 +01:00
char CrsShortName[Hie_MAX_BYTES_SHRT_NAME + 1];
char DegShortName[Hie_MAX_BYTES_SHRT_NAME + 1];
2014-12-01 23:55:08 +01:00
/***** Fill the list with the courses I belong to, if not filled *****/
if (Gbl.Usrs.Me.Logged)
Usr_GetMyCourses ();
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
2018-11-09 20:47:39 +01:00
Frm_StartFormGoTo (Gbl.Usrs.Me.MyCrss.Num ? ActSeeCrsInf :
2019-02-15 13:39:37 +01:00
ActReqSch);
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** Start selector of courses *****/
2019-11-05 15:47:35 +01:00
HTM_SELECT_Begin (true,
"id=\"my_courses\" name=\"crs\"");
2014-12-01 23:55:08 +01:00
2015-12-28 01:39:58 +01:00
/***** Write an option when no course selected *****/
2019-04-04 10:45:15 +02:00
if (Gbl.Hierarchy.Crs.CrsCod <= 0) // No course selected
2019-11-06 19:45:20 +01:00
HTM_OPTION (HTM_Type_STRING,"-1",true,true,
2019-11-06 08:59:15 +01:00
"%s",Txt_Course);
2015-12-28 01:39:58 +01:00
2016-10-28 10:03:37 +02:00
if (Gbl.Usrs.Me.MyCrss.Num)
2014-12-01 23:55:08 +01:00
{
/***** Write an option for each of my courses *****/
for (NumMyCrs = 0, LastDegCod = -1L;
2016-10-28 10:03:37 +02:00
NumMyCrs < Gbl.Usrs.Me.MyCrss.Num;
2014-12-01 23:55:08 +01:00
NumMyCrs++)
{
2016-10-28 10:03:37 +02:00
CrsCod = Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].CrsCod;
DegCod = Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].DegCod;
2014-12-01 23:55:08 +01:00
Crs_GetShortNamesByCod (CrsCod,CrsShortName,DegShortName);
if (DegCod != LastDegCod)
{
2016-11-20 18:43:38 +01:00
if (LastDegCod > 0)
2019-11-09 20:31:17 +01:00
HTM_OPTGROUP_End ();
HTM_OPTGROUP_Begin (DegShortName);
2014-12-01 23:55:08 +01:00
LastDegCod = DegCod;
}
2019-11-06 19:45:20 +01:00
HTM_OPTION (HTM_Type_LONG,&Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].CrsCod,
2019-11-06 08:59:15 +01:00
CrsCod == Gbl.Hierarchy.Crs.CrsCod,false, // Course selected
"%s",CrsShortName);
2014-12-01 23:55:08 +01:00
}
2016-11-20 18:43:38 +01:00
if (LastDegCod > 0)
2019-11-09 20:31:17 +01:00
HTM_OPTGROUP_End ();
2014-12-01 23:55:08 +01:00
}
2016-11-20 18:43:38 +01:00
/***** Write an option with the current course
when I don't belong to it *****/
2019-04-03 20:57:04 +02:00
if (Gbl.Hierarchy.Level == Hie_CRS && // Course selected
2016-11-20 18:43:38 +01:00
!Gbl.Usrs.Me.IBelongToCurrentCrs) // I do not belong to it
2019-11-06 19:45:20 +01:00
HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Crs.CrsCod,true,true,
2019-11-06 08:59:15 +01:00
"%s",Gbl.Hierarchy.Crs.ShrtName);
2016-11-20 18:43:38 +01:00
2014-12-01 23:55:08 +01:00
/***** End form *****/
2019-11-05 08:46:38 +01:00
HTM_SELECT_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************* List courses in this degree ***********************/
/*****************************************************************************/
static void Crs_ListCourses (void)
{
2016-11-13 15:06:49 +01:00
extern const char *Hlp_DEGREE_Courses;
2016-03-20 12:35:27 +01:00
extern const char *Txt_Courses_of_DEGREE_X;
2016-03-20 13:18:56 +01:00
extern const char *Txt_No_courses;
2016-03-16 13:23:10 +01:00
extern const char *Txt_Create_another_course;
2015-10-06 01:19:21 +02:00
extern const char *Txt_Create_course;
2016-03-20 12:35:27 +01:00
unsigned Year;
2014-12-01 23:55:08 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2019-12-30 21:47:07 +01:00
Box_BoxBegin (NULL,Str_BuildStringStr (Txt_Courses_of_DEGREE_X,
Gbl.Hierarchy.Deg.ShrtName),
2020-04-08 13:40:21 +02:00
Crs_PutIconsListCourses,NULL,
2017-06-12 15:03:29 +02:00
Hlp_DEGREE_Courses,Box_NOT_CLOSABLE);
2019-12-30 21:47:07 +01:00
Str_FreeString ();
2016-03-20 12:35:27 +01:00
2020-01-08 14:04:25 +01:00
if (Gbl.Hierarchy.Crss.Num) // There are courses in the current degree
2016-03-20 12:35:27 +01:00
{
2019-10-20 22:00:28 +02:00
/***** Begin table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWideMarginPadding (2);
2016-03-20 12:35:27 +01:00
Crs_PutHeadCoursesForSeeing ();
/***** List the courses *****/
for (Year = 1;
Year <= Deg_MAX_YEARS_PER_DEGREE;
Year++)
if (Crs_ListCoursesOfAYearForSeeing (Year)) // If this year has courses ==>
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd; // ==> change color for the next year
2016-06-04 13:07:33 +02:00
Crs_ListCoursesOfAYearForSeeing (0); // Courses without a year selected
2016-03-20 12:35:27 +01:00
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2016-03-20 12:35:27 +01:00
}
else // No courses created in the current degree
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_INFO,Txt_No_courses);
2016-03-16 13:23:10 +01:00
2016-03-20 12:35:27 +01:00
/***** Button to create course *****/
2016-11-07 00:03:50 +01:00
if (Crs_CheckIfICanCreateCourses ())
2016-03-16 13:23:10 +01:00
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActEdiCrs);
2020-01-08 14:04:25 +01:00
Btn_PutConfirmButton (Gbl.Hierarchy.Crss.Num ? Txt_Create_another_course :
2020-01-05 12:52:03 +01:00
Txt_Create_course);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-10-06 01:19:21 +02:00
}
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2016-03-16 13:23:10 +01:00
}
2016-11-07 00:03:50 +01:00
/*****************************************************************************/
/********************** Check if I can create courses ************************/
/*****************************************************************************/
static bool Crs_CheckIfICanCreateCourses (void)
{
2017-06-04 18:18:54 +02:00
return (bool) (Gbl.Usrs.Me.Role.Logged >= Rol_GST);
2016-11-07 00:03:50 +01:00
}
/*****************************************************************************/
/***************** Put contextual icons in list of courses *******************/
/*****************************************************************************/
2020-04-08 13:40:21 +02:00
static void Crs_PutIconsListCourses (__attribute__((unused)) void *Args)
2016-11-07 00:03:50 +01:00
{
2020-04-08 13:40:21 +02:00
/***** Put icon to edit courses *****/
if (Crs_CheckIfICanCreateCourses ())
Crs_PutIconToEditCourses ();
2016-11-07 00:03:50 +01:00
2020-04-08 13:40:21 +02:00
/***** Put icon to show a figure *****/
Fig_PutIconToShowFigure (Fig_HIERARCHY);
2016-11-07 00:03:50 +01:00
}
2016-03-16 13:23:10 +01:00
/*****************************************************************************/
2018-11-15 18:51:13 +01:00
/************************* Put icon to edit courses **************************/
2016-03-16 13:23:10 +01:00
/*****************************************************************************/
2016-03-16 22:40:35 +01:00
static void Crs_PutIconToEditCourses (void)
2016-03-16 13:23:10 +01:00
{
2020-03-26 02:54:30 +01:00
Ico_PutContextualIconToEdit (ActEdiCrs,NULL,
NULL,NULL);
2014-12-01 23:55:08 +01:00
}
2015-12-06 14:18:07 +01:00
/*****************************************************************************/
/********************* List courses of a year for seeing *********************/
/*****************************************************************************/
// Return true if this year has courses
static bool Crs_ListCoursesOfAYearForSeeing (unsigned Year)
{
extern const char *Txt_COURSE_With_users;
extern const char *Txt_COURSE_Without_users;
2017-01-28 15:58:46 +01:00
extern const char *Txt_YEAR_OF_DEGREE[1 + Deg_MAX_YEARS_PER_DEGREE];
2015-12-06 14:18:07 +01:00
extern const char *Txt_COURSE_STATUS[Crs_NUM_STATUS_TXT];
unsigned NumCrs;
struct Course *Crs;
const char *TxtClassNormal;
const char *TxtClassStrong;
const char *BgColor;
Crs_StatusTxt_t StatusTxt;
bool ThisYearHasCourses = false;
2020-01-05 14:09:28 +01:00
unsigned NumUsrs[Rol_NUM_ROLES];
2015-12-06 14:18:07 +01:00
/***** Write all the courses of this year *****/
for (NumCrs = 0;
2020-01-08 14:04:25 +01:00
NumCrs < Gbl.Hierarchy.Crss.Num;
2015-12-06 14:18:07 +01:00
NumCrs++)
{
2020-01-08 14:04:25 +01:00
Crs = &(Gbl.Hierarchy.Crss.Lst[NumCrs]);
2015-12-06 14:18:07 +01:00
if (Crs->Year == Year) // The year of the course is this?
{
ThisYearHasCourses = true;
if (Crs->Status & Crs_STATUS_BIT_PENDING)
{
TxtClassNormal = "DAT_LIGHT";
2019-11-18 15:48:46 +01:00
TxtClassStrong = "BT_LINK LT DAT_LIGHT";
2015-12-06 14:18:07 +01:00
}
else
{
TxtClassNormal = "DAT";
2019-11-18 15:48:46 +01:00
TxtClassStrong = "BT_LINK LT DAT_N";
2015-12-06 14:18:07 +01:00
}
2018-10-04 22:45:16 +02:00
/* Check if this course is one of my courses */
BgColor = (Usr_CheckIfIBelongToCrs (Crs->CrsCod)) ? "LIGHT_BLUE" :
Gbl.ColorRows[Gbl.RowEvenOdd];
2015-12-06 14:18:07 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 00:05:24 +02:00
2020-01-05 14:09:28 +01:00
/* Get number of users */
2020-01-08 23:49:04 +01:00
NumUsrs[Rol_STD] = Usr_GetNumUsrsInCrss (Hie_CRS,Crs->CrsCod,1 << Rol_STD);
NumUsrs[Rol_NET] = Usr_GetNumUsrsInCrss (Hie_CRS,Crs->CrsCod,1 << Rol_NET);
NumUsrs[Rol_TCH] = Usr_GetNumUsrsInCrss (Hie_CRS,Crs->CrsCod,1 << Rol_TCH);
NumUsrs[Rol_UNK] = NumUsrs[Rol_STD] +
NumUsrs[Rol_NET] +
NumUsrs[Rol_TCH];
2020-01-05 14:09:28 +01:00
2019-10-07 00:05:24 +02:00
/* Put green tip if course has users */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s CM %s\" title=\"%s\"",
2019-10-10 23:14:13 +02:00
TxtClassNormal,BgColor,
2020-01-05 14:09:28 +01:00
NumUsrs[Rol_UNK] ? Txt_COURSE_With_users :
Txt_COURSE_Without_users);
HTM_Txt (NumUsrs[Rol_UNK] ? "&check;" :
"&nbsp;");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2015-12-06 14:18:07 +01:00
/* Institutional code of the course */
2019-11-10 12:36:37 +01:00
HTM_TD_Begin ("class=\"%s CM %s\"",TxtClassNormal,BgColor);
HTM_Txt (Crs->InstitutionalCrsCod);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2015-12-06 14:18:07 +01:00
/* Course year */
2019-11-10 12:36:37 +01:00
HTM_TD_Begin ("class=\"%s CM %s\"",TxtClassNormal,BgColor);
HTM_Txt (Txt_YEAR_OF_DEGREE[Crs->Year]);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2015-12-06 14:18:07 +01:00
/* Course full name */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s LM %s\"",TxtClassStrong,BgColor);
2018-11-09 20:47:39 +01:00
Frm_StartFormGoTo (ActSeeCrsInf);
2015-12-06 14:18:07 +01:00
Crs_PutParamCrsCod (Crs->CrsCod);
2019-12-30 12:25:45 +01:00
HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Crs->FullName),
TxtClassStrong,NULL);
Hie_FreeGoToMsg ();
2019-11-10 12:36:37 +01:00
HTM_Txt (Crs->FullName);
2019-11-18 11:23:48 +01:00
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2015-12-06 14:18:07 +01:00
2015-12-14 16:44:14 +01:00
/* Current number of teachers in this course */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor);
2020-01-05 14:09:28 +01:00
HTM_Unsigned (NumUsrs[Rol_TCH] +
NumUsrs[Rol_NET]);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2015-12-06 14:18:07 +01:00
2015-12-14 16:44:14 +01:00
/* Current number of students in this course */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor);
2020-01-05 14:09:28 +01:00
HTM_Unsigned (NumUsrs[Rol_STD]);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2015-12-06 14:18:07 +01:00
/* Course status */
StatusTxt = Crs_GetStatusTxtFromStatusBits (Crs->Status);
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s LM %s\"",TxtClassNormal,BgColor);
2017-03-17 00:46:28 +01:00
if (StatusTxt != Crs_STATUS_ACTIVE) // If active ==> do not show anything
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_COURSE_STATUS[StatusTxt]);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-10 21:21:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2015-12-06 14:18:07 +01:00
}
}
return ThisYearHasCourses;
}
2016-03-20 12:35:27 +01:00
/*****************************************************************************/
/****************** Put forms to edit courses in this degree *****************/
/*****************************************************************************/
2017-04-30 12:44:53 +02:00
void Crs_EditCourses (void)
2019-04-07 19:49:53 +02:00
{
/***** Course constructor *****/
Crs_EditingCourseConstructor ();
/***** Edit courses *****/
Crs_EditCoursesInternal ();
/***** Course destructor *****/
Crs_EditingCourseDestructor ();
}
static void Crs_EditCoursesInternal (void)
2016-03-20 12:35:27 +01:00
{
2017-04-30 12:44:53 +02:00
extern const char *Hlp_DEGREE_Courses;
extern const char *Txt_Courses_of_DEGREE_X;
/***** Get list of degrees in this centre *****/
2020-01-05 12:52:03 +01:00
Deg_GetListDegsInCurrentCtr ();
2017-04-30 12:44:53 +02:00
2019-04-07 12:17:10 +02:00
/***** Get list of courses in this degree *****/
2020-01-05 12:52:03 +01:00
Crs_GetListCrssInCurrentDeg (Crs_ALL_COURSES_EXCEPT_REMOVED);
2019-04-07 12:17:10 +02:00
2018-11-15 18:51:13 +01:00
/***** Write menu to select country, institution, centre and degree *****/
Hie_WriteMenuHierarchy ();
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2019-12-30 21:47:07 +01:00
Box_BoxBegin (NULL,Str_BuildStringStr (Txt_Courses_of_DEGREE_X,
Gbl.Hierarchy.Deg.ShrtName),
2020-04-08 13:40:21 +02:00
Crs_PutIconsEditingCourses,NULL,
2017-06-12 15:03:29 +02:00
Hlp_DEGREE_Courses,Box_NOT_CLOSABLE);
2019-12-30 21:47:07 +01:00
Str_FreeString ();
2017-04-30 12:44:53 +02:00
2016-03-20 12:35:27 +01:00
/***** Put a form to create or request a new course *****/
Crs_PutFormToCreateCourse ();
/***** Forms to edit current courses *****/
2020-01-08 14:04:25 +01:00
if (Gbl.Hierarchy.Crss.Num)
2016-03-20 12:35:27 +01:00
Crs_ListCoursesForEdition ();
2017-04-30 12:44:53 +02:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2017-04-30 12:44:53 +02:00
/***** Free list of courses in this degree *****/
2019-04-07 12:17:10 +02:00
Crs_FreeListCoursesInCurrentDegree ();
2017-04-30 12:44:53 +02:00
/***** Free list of degrees in this centre *****/
2020-01-08 14:04:25 +01:00
Deg_FreeListDegs (&Gbl.Hierarchy.Degs);
2017-04-30 12:44:53 +02:00
}
/*****************************************************************************/
/**************** Put contextual icons in edition of courses *****************/
/*****************************************************************************/
2020-04-08 13:40:21 +02:00
static void Crs_PutIconsEditingCourses (__attribute__((unused)) void *Args)
2018-11-15 18:51:13 +01:00
{
2020-04-08 13:40:21 +02:00
/***** Put icon to view degrees *****/
Crs_PutIconToViewCourses ();
2018-11-15 18:51:13 +01:00
2020-04-08 13:40:21 +02:00
/***** Put icon to show a figure *****/
Fig_PutIconToShowFigure (Fig_HIERARCHY);
2018-11-15 18:51:13 +01:00
}
/*****************************************************************************/
/************************* Put icon to view courses **************************/
/*****************************************************************************/
2017-04-30 12:44:53 +02:00
static void Crs_PutIconToViewCourses (void)
{
2018-11-15 18:51:13 +01:00
extern const char *Txt_Courses;
2020-03-26 02:54:30 +01:00
Lay_PutContextualLinkOnlyIcon (ActSeeCrs,NULL,
NULL,NULL,
2020-02-20 00:32:07 +01:00
"chalkboard-teacher.svg",
2019-01-12 03:00:59 +01:00
Txt_Courses);
2016-03-20 12:35:27 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************* List current courses for edition **********************/
/*****************************************************************************/
static void Crs_ListCoursesForEdition (void)
{
2016-07-04 09:54:36 +02:00
unsigned Year;
/***** Write heading *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWidePadding (2);
2016-07-04 09:54:36 +02:00
Crs_PutHeadCoursesForEdition ();
/***** List the courses *****/
for (Year = 1;
Year <= Deg_MAX_YEARS_PER_DEGREE;
Year++)
Crs_ListCoursesOfAYearForEdition (Year);
Crs_ListCoursesOfAYearForEdition (0);
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2016-07-04 09:54:36 +02:00
}
/*****************************************************************************/
/******************** List courses of a year for edition *********************/
/*****************************************************************************/
static void Crs_ListCoursesOfAYearForEdition (unsigned Year)
{
2017-01-28 15:58:46 +01:00
extern const char *Txt_YEAR_OF_DEGREE[1 + Deg_MAX_YEARS_PER_DEGREE];
2014-12-01 23:55:08 +01:00
extern const char *Txt_COURSE_STATUS[Crs_NUM_STATUS_TXT];
struct Course *Crs;
unsigned YearAux;
unsigned NumCrs;
struct UsrData UsrDat;
bool ICanEdit;
2020-01-05 14:09:28 +01:00
unsigned NumUsrs[Rol_NUM_ROLES];
2014-12-01 23:55:08 +01:00
Crs_StatusTxt_t StatusTxt;
2019-11-06 15:27:33 +01:00
unsigned StatusUnsigned;
2014-12-01 23:55:08 +01:00
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
2016-07-04 09:54:36 +02:00
/***** List courses of a given year *****/
for (NumCrs = 0;
2020-01-08 14:04:25 +01:00
NumCrs < Gbl.Hierarchy.Crss.Num;
2016-07-04 09:54:36 +02:00
NumCrs++)
{
2020-01-08 14:04:25 +01:00
Crs = &(Gbl.Hierarchy.Crss.Lst[NumCrs]);
2016-07-04 09:54:36 +02:00
if (Crs->Year == Year)
{
ICanEdit = Crs_CheckIfICanEdit (Crs);
2014-12-01 23:55:08 +01:00
2020-01-05 14:09:28 +01:00
/* Get number of users */
2020-01-08 23:49:04 +01:00
NumUsrs[Rol_STD] = Usr_GetNumUsrsInCrss (Hie_CRS,Crs->CrsCod,1 << Rol_STD);
NumUsrs[Rol_NET] = Usr_GetNumUsrsInCrss (Hie_CRS,Crs->CrsCod,1 << Rol_NET);
NumUsrs[Rol_TCH] = Usr_GetNumUsrsInCrss (Hie_CRS,Crs->CrsCod,1 << Rol_TCH);
NumUsrs[Rol_UNK] = NumUsrs[Rol_STD] +
NumUsrs[Rol_NET] +
NumUsrs[Rol_TCH];
2020-01-05 14:09:28 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-08 00:50:28 +02:00
/* Put icon to remove course */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"BM\"");
2020-01-05 14:09:28 +01:00
if (NumUsrs[Rol_UNK] || // Course has users ==> deletion forbidden
2016-07-04 09:54:36 +02:00
!ICanEdit)
2017-06-11 19:13:28 +02:00
Ico_PutIconRemovalNotAllowed ();
2016-07-04 09:54:36 +02:00
else // Crs->NumUsrs == 0 && ICanEdit
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRemCrs);
2016-07-04 09:54:36 +02:00
Crs_PutParamOtherCrsCod (Crs->CrsCod);
2017-06-11 19:13:28 +02:00
Ico_PutIconRemove ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-07-04 09:54:36 +02:00
}
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2016-07-04 09:54:36 +02:00
/* Course code */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT CODE\"");
2019-11-10 13:38:17 +01:00
HTM_Long (Crs->CrsCod);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2016-07-04 09:54:36 +02:00
/* Institutional code of the course */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT CM\"");
2016-07-04 09:54:36 +02:00
if (ICanEdit)
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgInsCrsCod);
2016-07-04 09:54:36 +02:00
Crs_PutParamOtherCrsCod (Crs->CrsCod);
2019-11-04 12:25:48 +01:00
HTM_INPUT_TEXT ("InsCrsCod",Crs_MAX_CHARS_INSTITUTIONAL_CRS_COD,
Crs->InstitutionalCrsCod,true,
"class=\"INPUT_INS_CODE\"");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-07-04 09:54:36 +02:00
}
else
2019-11-10 12:36:37 +01:00
HTM_Txt (Crs->InstitutionalCrsCod);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2016-07-04 09:54:36 +02:00
/* Course year */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT CM\"");
2016-07-04 09:54:36 +02:00
if (ICanEdit)
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgCrsYea);
2016-07-04 09:54:36 +02:00
Crs_PutParamOtherCrsCod (Crs->CrsCod);
2019-11-05 15:47:35 +01:00
HTM_SELECT_Begin (true,
"name=\"OthCrsYear\" class=\"HIE_SEL_NARROW\"");
2016-07-04 09:54:36 +02:00
for (YearAux = 0;
YearAux <= Deg_MAX_YEARS_PER_DEGREE;
YearAux++) // All the years are permitted because it's possible to move this course to another degree (with other active years)
2019-11-06 19:45:20 +01:00
HTM_OPTION (HTM_Type_UNSIGNED,&YearAux,
2019-11-06 08:59:15 +01:00
YearAux == Crs->Year,false,
"%s",Txt_YEAR_OF_DEGREE[YearAux]);
2019-11-05 08:46:38 +01:00
HTM_SELECT_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-07-04 09:54:36 +02:00
}
else
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_YEAR_OF_DEGREE[Crs->Year]);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2016-07-04 09:54:36 +02:00
/* Course short name */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT LM\"");
2016-07-04 09:54:36 +02:00
if (ICanEdit)
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRenCrsSho);
2016-07-04 09:54:36 +02:00
Crs_PutParamOtherCrsCod (Crs->CrsCod);
2019-11-04 12:25:48 +01:00
HTM_INPUT_TEXT ("ShortName",Hie_MAX_CHARS_SHRT_NAME,Crs->ShrtName,true,
"class=\"INPUT_SHORT_NAME\"");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-07-04 09:54:36 +02:00
}
else
2019-11-10 12:36:37 +01:00
HTM_Txt (Crs->ShrtName);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2016-07-04 09:54:36 +02:00
/* Course full name */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT LM\"");
2016-07-04 09:54:36 +02:00
if (ICanEdit)
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRenCrsFul);
2016-07-04 09:54:36 +02:00
Crs_PutParamOtherCrsCod (Crs->CrsCod);
2019-11-04 12:25:48 +01:00
HTM_INPUT_TEXT ("FullName",Hie_MAX_CHARS_FULL_NAME,Crs->FullName,true,
"class=\"INPUT_FULL_NAME\"");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-07-04 09:54:36 +02:00
}
else
2019-11-10 12:36:37 +01:00
HTM_Txt (Crs->FullName);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2016-07-04 09:54:36 +02:00
/* Current number of teachers in this course */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2020-01-05 14:09:28 +01:00
HTM_Unsigned (NumUsrs[Rol_TCH] +
NumUsrs[Rol_NET]);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2016-07-04 09:54:36 +02:00
/* Current number of students in this course */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2020-01-05 14:09:28 +01:00
HTM_Unsigned (NumUsrs[Rol_STD]);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2016-07-04 09:54:36 +02:00
2017-03-17 00:46:28 +01:00
/* Course requester */
UsrDat.UsrCod = Crs->RequesterUsrCod;
2019-03-19 13:22:14 +01:00
Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS);
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT INPUT_REQUESTER LT\"");
2017-05-02 01:16:06 +02:00
Msg_WriteMsgAuthor (&UsrDat,true,NULL);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2017-03-17 00:46:28 +01:00
2016-07-04 09:54:36 +02:00
/* Course status */
StatusTxt = Crs_GetStatusTxtFromStatusBits (Crs->Status);
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT LM\"");
2017-06-04 18:18:54 +02:00
if (Gbl.Usrs.Me.Role.Logged >= Rol_DEG_ADM &&
2016-07-04 09:54:36 +02:00
StatusTxt == Crs_STATUS_PENDING)
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgCrsSta);
2016-07-04 09:54:36 +02:00
Crs_PutParamOtherCrsCod (Crs->CrsCod);
2019-11-05 15:47:35 +01:00
HTM_SELECT_Begin (true,
"name=\"Status\" class=\"INPUT_STATUS\"");
2019-11-06 08:59:15 +01:00
2019-11-06 15:27:33 +01:00
StatusUnsigned = (unsigned) Crs_GetStatusBitsFromStatusTxt (Crs_STATUS_PENDING);
2019-11-06 19:45:20 +01:00
HTM_OPTION (HTM_Type_UNSIGNED,&StatusUnsigned,true,false,
2019-11-06 08:59:15 +01:00
"%s",Txt_COURSE_STATUS[Crs_STATUS_PENDING]);
2019-11-06 15:27:33 +01:00
StatusUnsigned = (unsigned) Crs_GetStatusBitsFromStatusTxt (Crs_STATUS_ACTIVE);
2019-11-06 19:45:20 +01:00
HTM_OPTION (HTM_Type_UNSIGNED,&StatusUnsigned,false,false,
2019-11-06 08:59:15 +01:00
"%s",Txt_COURSE_STATUS[Crs_STATUS_ACTIVE]);
2019-11-05 08:46:38 +01:00
HTM_SELECT_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-07-04 09:54:36 +02:00
}
2017-03-17 00:46:28 +01:00
else if (StatusTxt != Crs_STATUS_ACTIVE) // If active ==> do not show anything
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_COURSE_STATUS[StatusTxt]);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-10 21:21:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2016-07-04 09:54:36 +02:00
}
}
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 course *******************/
/*****************************************************************************/
static bool Crs_CheckIfICanEdit (struct Course *Crs)
{
2017-06-04 18:18:54 +02:00
return (bool) (Gbl.Usrs.Me.Role.Logged >= Rol_DEG_ADM || // I am a degree administrator or higher
2019-12-17 00:36:22 +01:00
((Crs->Status & Crs_STATUS_BIT_PENDING) != 0 && // Course is not yet activated
Gbl.Usrs.Me.UsrDat.UsrCod == Crs->RequesterUsrCod)); // I am the requester
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Set StatusTxt depending on status bits ******************/
/*****************************************************************************/
// Crs_STATUS_UNKNOWN = 0 // Other
// Crs_STATUS_ACTIVE = 1 // 00 (Status == 0)
// Crs_STATUS_PENDING = 2 // 01 (Status == Crs_STATUS_BIT_PENDING)
// Crs_STATUS_REMOVED = 3 // 1- (Status & Crs_STATUS_BIT_REMOVED)
static Crs_StatusTxt_t Crs_GetStatusTxtFromStatusBits (Crs_Status_t Status)
{
if (Status == 0)
return Crs_STATUS_ACTIVE;
if (Status == Crs_STATUS_BIT_PENDING)
return Crs_STATUS_PENDING;
if (Status & Crs_STATUS_BIT_REMOVED)
return Crs_STATUS_REMOVED;
return Crs_STATUS_UNKNOWN;
}
/*****************************************************************************/
/******************* Set status bits depending on StatusTxt ******************/
/*****************************************************************************/
// Crs_STATUS_UNKNOWN = 0 // Other
// Crs_STATUS_ACTIVE = 1 // 00 (Status == 0)
// Crs_STATUS_PENDING = 2 // 01 (Status == Crs_STATUS_BIT_PENDING)
// Crs_STATUS_REMOVED = 3 // 1- (Status & Crs_STATUS_BIT_REMOVED)
static Crs_Status_t Crs_GetStatusBitsFromStatusTxt (Crs_StatusTxt_t StatusTxt)
{
switch (StatusTxt)
{
case Crs_STATUS_UNKNOWN:
case Crs_STATUS_ACTIVE:
return (Crs_Status_t) 0;
case Crs_STATUS_PENDING:
return Crs_STATUS_BIT_PENDING;
case Crs_STATUS_REMOVED:
return Crs_STATUS_BIT_REMOVED;
}
return (Crs_Status_t) 0;
}
/*****************************************************************************/
/*********************** Put a form to create a new course *******************/
/*****************************************************************************/
static void Crs_PutFormToCreateCourse (void)
{
2017-04-30 12:44:53 +02:00
extern const char *Txt_New_course;
2017-01-28 15:58:46 +01:00
extern const char *Txt_YEAR_OF_DEGREE[1 + Deg_MAX_YEARS_PER_DEGREE];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Create_course;
unsigned Year;
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
2017-06-04 18:18:54 +02:00
if (Gbl.Usrs.Me.Role.Logged >= Rol_DEG_ADM)
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActNewCrs);
2017-06-04 18:18:54 +02:00
else if (Gbl.Usrs.Me.Role.Max >= Rol_GST)
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActReqCrs);
2014-12-01 23:55:08 +01:00
else
2019-10-26 01:56:36 +02:00
Lay_NoPermissionExit ();
2014-12-01 23:55:08 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
2020-03-26 02:54:30 +01:00
Box_BoxTableBegin (NULL,Txt_New_course,
NULL,NULL,
2017-06-12 15:03:29 +02:00
NULL,Box_NOT_CLOSABLE,2);
2017-06-12 14:16:33 +02:00
/***** Write heading *****/
2014-12-01 23:55:08 +01:00
Crs_PutHeadCoursesForEdition ();
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 00:05:24 +02:00
/***** Column to remove course, disabled here *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"BM\"");
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Course code *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"CODE\"");
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Institutional code of the course *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"CM\"");
2019-11-04 12:25:48 +01:00
HTM_INPUT_TEXT ("InsCrsCod",Crs_MAX_CHARS_INSTITUTIONAL_CRS_COD,
Crs_EditingCrs->InstitutionalCrsCod,false,
2019-11-04 09:45:57 +01:00
"class=\"INPUT_INS_CODE\"");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Year *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"CM\"");
2019-11-05 15:47:35 +01:00
HTM_SELECT_Begin (false,
"name=\"OthCrsYear\" class=\"HIE_SEL_NARROW\"");
2014-12-01 23:55:08 +01:00
for (Year = 0;
2016-02-29 18:53:26 +01:00
Year <= Deg_MAX_YEARS_PER_DEGREE;
2014-12-01 23:55:08 +01:00
Year++)
2019-11-06 19:45:20 +01:00
HTM_OPTION (HTM_Type_UNSIGNED,&Year,
2019-11-06 08:59:15 +01:00
Year == Crs_EditingCrs->Year,false,
"%s",Txt_YEAR_OF_DEGREE[Year]);
2019-11-05 08:46:38 +01:00
HTM_SELECT_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Course short name *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LM\"");
2019-11-04 12:25:48 +01:00
HTM_INPUT_TEXT ("ShortName",Hie_MAX_CHARS_SHRT_NAME,Crs_EditingCrs->ShrtName,false,
2019-11-04 09:45:57 +01:00
"class=\"INPUT_SHORT_NAME\" required=\"required\"");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Course full name *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LM\"");
2019-11-04 12:25:48 +01:00
HTM_INPUT_TEXT ("FullName",Hie_MAX_CHARS_FULL_NAME,Crs_EditingCrs->FullName,false,
2019-11-04 09:45:57 +01:00
"class=\"INPUT_FULL_NAME\" required=\"required\"");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2016-06-04 13:07:33 +02:00
/***** Current number of teachers in this course *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2019-11-10 13:51:07 +01:00
HTM_Unsigned (0);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2016-06-04 13:07:33 +02:00
/***** Current number of students in this course *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2019-11-10 13:51:07 +01:00
HTM_Unsigned (0);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Course requester *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT INPUT_REQUESTER LT\"");
2017-05-02 01:16:06 +02:00
Msg_WriteMsgAuthor (&Gbl.Usrs.Me.UsrDat,true,NULL);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2017-03-17 00:46:28 +01:00
/***** Course status *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT LM\"");
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End table, send button and end box *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create_course);
2014-12-01 23:55:08 +01:00
2015-04-11 23:46:21 +02:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Write header with fields of a course *******************/
/*****************************************************************************/
static void Crs_PutHeadCoursesForSeeing (void)
{
extern const char *Txt_Institutional_BR_code;
extern const char *Txt_Year_OF_A_DEGREE;
extern const char *Txt_Course;
2017-05-30 21:43:05 +02:00
extern const char *Txt_ROLES_PLURAL_BRIEF_Abc[Rol_NUM_ROLES];
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-11 09:09:19 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH (1,1,"BM",NULL);
HTM_TH (1,1,"CM",Txt_Institutional_BR_code);
HTM_TH (1,1,"CM",Txt_Year_OF_A_DEGREE);
HTM_TH (1,1,"LM",Txt_Course);
HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]);
HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD]);
HTM_TH_Empty (1);
2019-10-11 09:09:19 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Write header with fields of a course *******************/
/*****************************************************************************/
static void Crs_PutHeadCoursesForEdition (void)
{
extern const char *Txt_Code;
2015-10-06 01:19:21 +02:00
extern const char *Txt_Institutional_code;
extern const char *Txt_optional;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Year_OF_A_DEGREE;
2016-03-02 20:29:31 +01:00
extern const char *Txt_Short_name_of_the_course;
extern const char *Txt_Full_name_of_the_course;
2017-05-30 21:43:05 +02:00
extern const char *Txt_ROLES_PLURAL_BRIEF_Abc[Rol_NUM_ROLES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Requester;
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-11 09:09:19 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH (1,1,"BM",NULL);
HTM_TH (1,1,"RM",Txt_Code);
HTM_TH_Begin (1,1,"CM");
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s&nbsp;(%s)",Txt_Institutional_code,Txt_optional);
2019-10-23 19:05:05 +02:00
HTM_TH_End ();
HTM_TH (1,1,"CM",Txt_Year_OF_A_DEGREE);
HTM_TH (1,1,"LM",Txt_Short_name_of_the_course);
HTM_TH (1,1,"LM",Txt_Full_name_of_the_course);
HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]);
HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD]);
HTM_TH (1,1,"LM",Txt_Requester);
HTM_TH_Empty (1);
2019-10-11 09:09:19 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************** Receive form to request a new course *********************/
/*****************************************************************************/
void Crs_RecFormReqCrs (void)
{
2019-04-07 19:49:53 +02:00
/***** Course constructor *****/
Crs_EditingCourseConstructor ();
/***** Receive form to request a new course *****/
2014-12-01 23:55:08 +01:00
Crs_RecFormRequestOrCreateCrs ((unsigned) Crs_STATUS_BIT_PENDING);
}
/*****************************************************************************/
/******************* Receive form to create a new course *********************/
/*****************************************************************************/
void Crs_RecFormNewCrs (void)
{
2019-04-07 19:49:53 +02:00
/***** Course constructor *****/
Crs_EditingCourseConstructor ();
/***** Receive form to create a new course *****/
2014-12-01 23:55:08 +01:00
Crs_RecFormRequestOrCreateCrs (0);
}
/*****************************************************************************/
/************* Receive form to request or create a new course ****************/
/*****************************************************************************/
static void Crs_RecFormRequestOrCreateCrs (unsigned Status)
{
extern const char *Txt_The_course_X_already_exists;
2019-04-08 14:52:13 +02:00
extern const char *Txt_Created_new_course_X;
2014-12-01 23:55:08 +01:00
extern const char *Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_course;
2016-02-29 18:53:26 +01:00
extern const char *Txt_The_year_X_is_not_allowed;
2017-01-28 15:58:46 +01:00
extern const char *Txt_YEAR_OF_DEGREE[1 + Deg_MAX_YEARS_PER_DEGREE];
2014-12-01 23:55:08 +01:00
/***** Get parameters from form *****/
/* Set course degree */
2019-12-17 00:36:22 +01:00
// Deg.DegCod =
Crs_EditingCrs->DegCod = Gbl.Hierarchy.Deg.DegCod;
2014-12-01 23:55:08 +01:00
/* Get parameters of the new course */
2019-04-07 19:49:53 +02:00
Crs_GetParamsNewCourse (Crs_EditingCrs);
2014-12-01 23:55:08 +01:00
/***** Check if year is correct *****/
2019-04-07 19:49:53 +02:00
if (Crs_EditingCrs->Year <= Deg_MAX_YEARS_PER_DEGREE) // If year is valid
2014-12-01 23:55:08 +01:00
{
2019-04-07 19:49:53 +02:00
if (Crs_EditingCrs->ShrtName[0] &&
Crs_EditingCrs->FullName[0]) // If there's a course name
2014-12-01 23:55:08 +01:00
{
/***** If name of course was in database... *****/
2019-04-07 19:49:53 +02:00
if (Crs_CheckIfCrsNameExistsInYearOfDeg ("ShortName",Crs_EditingCrs->ShrtName,
-1L,Crs_EditingCrs->DegCod,Crs_EditingCrs->Year))
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_course_X_already_exists,
2019-04-07 19:49:53 +02:00
Crs_EditingCrs->ShrtName);
else if (Crs_CheckIfCrsNameExistsInYearOfDeg ("FullName",Crs_EditingCrs->FullName,
-1L,Crs_EditingCrs->DegCod,Crs_EditingCrs->Year))
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_course_X_already_exists,
2019-04-07 19:49:53 +02:00
Crs_EditingCrs->FullName);
2014-12-01 23:55:08 +01:00
else // Add new requested course to database
2019-04-08 14:52:13 +02:00
{
2017-05-11 20:04:38 +02:00
Crs_CreateCourse (Status);
2019-04-08 14:52:13 +02:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_Created_new_course_X,
Crs_EditingCrs->FullName);
}
2014-12-01 23:55:08 +01:00
}
else // If there is not a course name
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_course);
2014-12-01 23:55:08 +01:00
}
else // Year not valid
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_year_X_is_not_allowed,
2019-04-07 19:49:53 +02:00
Crs_EditingCrs->Year);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************** Get the parameters of a new course from form *****************/
/*****************************************************************************/
static void Crs_GetParamsNewCourse (struct Course *Crs)
{
2017-01-28 15:58:46 +01:00
char YearStr[2 + 1];
2014-12-01 23:55:08 +01:00
/***** Get parameters of the course from form *****/
/* Get institutional code */
2017-03-07 11:03:05 +01:00
Par_GetParToText ("InsCrsCod",Crs->InstitutionalCrsCod,Crs_MAX_BYTES_INSTITUTIONAL_CRS_COD);
2014-12-01 23:55:08 +01:00
/* Get year */
Par_GetParToText ("OthCrsYear",YearStr,2);
Crs->Year = Deg_ConvStrToYear (YearStr);
/* Get course short name */
2017-03-08 14:12:33 +01:00
Par_GetParToText ("ShortName",Crs->ShrtName,Hie_MAX_BYTES_SHRT_NAME);
2014-12-01 23:55:08 +01:00
/* Get course full name */
2017-03-08 14:12:33 +01:00
Par_GetParToText ("FullName",Crs->FullName,Hie_MAX_BYTES_FULL_NAME);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************* Add a new requested course to pending requests ****************/
/*****************************************************************************/
2017-05-11 20:04:38 +02:00
static void Crs_CreateCourse (unsigned Status)
2014-12-01 23:55:08 +01:00
{
/***** Insert new course into pending requests *****/
2019-04-07 19:49:53 +02:00
Crs_EditingCrs->CrsCod =
2018-11-03 01:45:36 +01:00
DB_QueryINSERTandReturnCode ("can not create a new course",
"INSERT INTO courses"
" (DegCod,Year,InsCrsCod,Status,RequesterUsrCod,"
"ShortName,FullName)"
" VALUES"
" (%ld,%u,'%s',%u,%ld,"
"'%s','%s')",
2019-04-07 19:49:53 +02:00
Crs_EditingCrs->DegCod,Crs_EditingCrs->Year,
Crs_EditingCrs->InstitutionalCrsCod,
2018-11-03 01:45:36 +01:00
Status,
Gbl.Usrs.Me.UsrDat.UsrCod,
2019-04-07 19:49:53 +02:00
Crs_EditingCrs->ShrtName,
Crs_EditingCrs->FullName);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2019-04-07 19:49:53 +02:00
/****************************** Remove a course ******************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
void Crs_RemoveCourse (void)
{
extern const char *Txt_To_remove_a_course_you_must_first_remove_all_users_in_the_course;
extern const char *Txt_Course_X_removed;
2019-04-07 19:49:53 +02:00
/***** Course constructor *****/
Crs_EditingCourseConstructor ();
2014-12-01 23:55:08 +01:00
/***** Get course code *****/
2019-04-08 12:21:16 +02:00
Crs_EditingCrs->CrsCod = Crs_GetAndCheckParamOtherCrsCod (1);
2014-12-01 23:55:08 +01:00
/***** Get data of the course from database *****/
2020-01-05 14:09:28 +01:00
Crs_GetDataOfCourseByCod (Crs_EditingCrs);
2014-12-01 23:55:08 +01:00
2019-04-08 12:21:16 +02:00
if (Crs_CheckIfICanEdit (Crs_EditingCrs))
2014-12-01 23:55:08 +01:00
{
/***** Check if this course has users *****/
2020-01-08 23:49:04 +01:00
if (Usr_GetNumUsrsInCrss (Hie_CRS,Crs_EditingCrs->CrsCod,
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH)) // Course has users ==> don't remove
2020-01-05 14:09:28 +01:00
Ale_ShowAlert (Ale_WARNING,
Txt_To_remove_a_course_you_must_first_remove_all_users_in_the_course);
2020-01-08 23:49:04 +01:00
else // Course has no users ==> remove it
2014-12-01 23:55:08 +01:00
{
/***** Remove course *****/
2019-04-08 12:21:16 +02:00
Crs_RemoveCourseCompletely (Crs_EditingCrs->CrsCod);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Course_X_removed,
2019-04-08 12:21:16 +02:00
Crs_EditingCrs->FullName);
2019-06-13 10:14:05 +02:00
Crs_EditingCrs->CrsCod = -1L; // To not showing button to go to course
2014-12-01 23:55:08 +01:00
}
}
else
2019-10-26 01:56:36 +02:00
Lay_NoPermissionExit ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Get data of a course from its code ********************/
/*****************************************************************************/
2020-01-05 14:09:28 +01:00
bool Crs_GetDataOfCourseByCod (struct Course *Crs)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
bool CrsFound = false;
2016-12-30 01:20:49 +01:00
/***** Clear data *****/
2016-12-28 02:40:15 +01:00
Crs->DegCod = -1L;
Crs->Year = 0;
Crs->Status = (Crs_Status_t) 0;
Crs->RequesterUsrCod = -1L;
Crs->ShrtName[0] = '\0';
Crs->FullName[0] = '\0';
2016-12-30 01:20:49 +01:00
/***** Check if course code is correct *****/
2016-12-28 02:40:15 +01:00
if (Crs->CrsCod > 0)
2014-12-01 23:55:08 +01:00
{
2016-12-28 02:40:15 +01:00
/***** Get data of a course from database *****/
2018-10-30 14:47:31 +01:00
if (DB_QuerySELECT (&mysql_res,"can not get data of a course",
2019-12-19 11:00:14 +01:00
"SELECT CrsCod," // row[0]
"DegCod," // row[1]
"Year," // row[2]
"InsCrsCod," // row[3]
"Status," // row[4]
"RequesterUsrCod," // row[5]
"ShortName," // row[6]
"FullName" // row[7]
2018-10-30 14:47:31 +01:00
" FROM courses WHERE CrsCod=%ld",
Crs->CrsCod)) // Course found...
2016-12-28 02:40:15 +01:00
{
/***** Get data of the course *****/
row = mysql_fetch_row (mysql_res);
Crs_GetDataOfCourseFromRow (Crs,row);
2014-12-01 23:55:08 +01:00
2016-12-30 01:20:49 +01:00
/* Set return value */
2016-12-28 02:40:15 +01:00
CrsFound = 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 CrsFound;
}
/*****************************************************************************/
/********** Get data of a course from a row resulting of a query *************/
/*****************************************************************************/
static void Crs_GetDataOfCourseFromRow (struct Course *Crs,MYSQL_ROW row)
{
/***** Get course code (row[0]) *****/
if ((Crs->CrsCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of course.");
/***** Get code of degree (row[1]) *****/
Crs->DegCod = Str_ConvertStrCodToLongCod (row[1]);
/***** Get year (row[2]) *****/
Crs->Year = Deg_ConvStrToYear (row[2]);
2015-12-06 01:02:47 +01:00
/***** Get institutional course code (row[3]) *****/
2017-01-17 03:10:43 +01:00
Str_Copy (Crs->InstitutionalCrsCod,row[3],
2017-03-07 11:03:05 +01:00
Crs_MAX_BYTES_INSTITUTIONAL_CRS_COD);
2014-12-01 23:55:08 +01:00
2016-03-03 01:24:58 +01:00
/***** Get course status (row[4]) *****/
if (sscanf (row[4],"%u",&(Crs->Status)) != 1)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Wrong course status.");
2016-03-03 01:24:58 +01:00
/***** Get requester user'code (row[5]) *****/
Crs->RequesterUsrCod = Str_ConvertStrCodToLongCod (row[5]);
2014-12-01 23:55:08 +01:00
2016-03-03 01:24:58 +01:00
/***** Get the short name of the course (row[6]) *****/
2017-01-17 03:10:43 +01:00
Str_Copy (Crs->ShrtName,row[6],
2017-03-08 14:12:33 +01:00
Hie_MAX_BYTES_SHRT_NAME);
2014-12-01 23:55:08 +01:00
2016-03-03 01:24:58 +01:00
/***** Get the full name of the course (row[7]) *****/
2017-01-17 03:10:43 +01:00
Str_Copy (Crs->FullName,row[7],
2017-03-08 14:12:33 +01:00
Hie_MAX_BYTES_FULL_NAME);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******* Get the short names of degree and course from a course code *********/
/*****************************************************************************/
2017-01-13 01:51:23 +01:00
static void Crs_GetShortNamesByCod (long CrsCod,
2017-03-08 14:12:33 +01:00
char CrsShortName[Hie_MAX_BYTES_SHRT_NAME + 1],
char DegShortName[Hie_MAX_BYTES_SHRT_NAME + 1])
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
DegShortName[0] = CrsShortName[0] = '\0';
if (CrsCod > 0)
{
/***** Get the short name of a degree from database *****/
2018-10-30 14:47:31 +01:00
if (DB_QuerySELECT (&mysql_res,"can not get the short name of a course",
"SELECT courses.ShortName,degrees.ShortName"
" FROM courses,degrees"
" WHERE courses.CrsCod=%ld"
" AND courses.DegCod=degrees.DegCod",
CrsCod) == 1)
2014-12-01 23:55:08 +01:00
{
/***** Get the short name of this course *****/
row = mysql_fetch_row (mysql_res);
2017-01-13 01:51:23 +01:00
2017-01-17 03:10:43 +01:00
Str_Copy (CrsShortName,row[0],
2017-03-08 14:12:33 +01:00
Hie_MAX_BYTES_SHRT_NAME);
2017-01-17 03:10:43 +01:00
Str_Copy (DegShortName,row[1],
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);
}
}
/*****************************************************************************/
/****************************** Remove a course ******************************/
/*****************************************************************************/
void Crs_RemoveCourseCompletely (long CrsCod)
{
2017-05-31 21:05:59 +02:00
if (CrsCod > 0)
{
/***** Empty course *****/
Crs_EmptyCourseCompletely (CrsCod);
2014-12-01 23:55:08 +01:00
2017-05-31 21:05:59 +02:00
/***** Remove course from table of last accesses to courses in database *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove a course",
"DELETE FROM crs_last WHERE CrsCod=%ld",
CrsCod);
2014-12-01 23:55:08 +01:00
2017-05-31 21:05:59 +02:00
/***** Remove course from table of courses in database *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove a course",
"DELETE FROM courses WHERE CrsCod=%ld",
CrsCod);
2017-05-31 21:05:59 +02:00
}
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********** Empty a course (remove all its information and users) ************/
/*****************************************************************************/
// Start removing less important things to more important things;
// so, in case of failure, important things can been removed in the future
static void Crs_EmptyCourseCompletely (long CrsCod)
{
struct Course Crs;
2017-01-28 15:58:46 +01:00
char PathRelCrs[PATH_MAX + 1];
2014-12-01 23:55:08 +01:00
2017-05-31 21:05:59 +02:00
if (CrsCod > 0)
{
/***** Get course data *****/
Crs.CrsCod = CrsCod;
2020-01-05 14:09:28 +01:00
Crs_GetDataOfCourseByCod (&Crs);
2017-05-31 21:05:59 +02:00
/***** Remove all the students in the course *****/
Enr_RemAllStdsInCrs (&Crs);
/***** Set all the notifications from the course as removed,
except notifications about new messages *****/
Ntf_MarkNotifInCrsAsRemoved (-1L,CrsCod);
/***** Remove information of the course ****/
/* Remove timetable of the course */
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove the timetable of a course",
"DELETE FROM timetable_crs WHERE CrsCod=%ld",
CrsCod);
2017-05-31 21:05:59 +02:00
/* Remove other information of the course */
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove info sources of a course",
"DELETE FROM crs_info_src WHERE CrsCod=%ld",
CrsCod);
2017-05-31 21:05:59 +02:00
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove info of a course",
"DELETE FROM crs_info_txt WHERE CrsCod=%ld",
CrsCod);
2017-05-31 21:05:59 +02:00
/***** Remove exam announcements in the course *****/
/* Mark all exam announcements in the course as deleted */
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not remove exam announcements of a course",
"UPDATE exam_announcements SET Status=%u"
" WHERE CrsCod=%ld",
(unsigned) Exa_DELETED_EXAM_ANNOUNCEMENT,CrsCod);
2017-05-31 21:05:59 +02:00
/***** Remove course cards of the course *****/
/* Remove content of course cards */
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove content of cards in a course",
"DELETE FROM crs_records"
" USING crs_record_fields,crs_records"
" WHERE crs_record_fields.CrsCod=%ld"
" AND crs_record_fields.FieldCod=crs_records.FieldCod",
CrsCod);
2017-05-31 21:05:59 +02:00
/* Remove definition of fields in course cards */
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove fields of cards in a course",
"DELETE FROM crs_record_fields WHERE CrsCod=%ld",
CrsCod);
2017-05-31 21:05:59 +02:00
2017-10-08 02:56:40 +02:00
/***** Remove information related to files in course,
including groups and projects,
so this function must be called
before removing groups and projects *****/
Brw_RemoveCrsFilesFromDB (CrsCod);
2017-05-31 21:05:59 +02:00
/***** Remove assignments of the course *****/
Asg_RemoveCrsAssignments (CrsCod);
2014-12-01 23:55:08 +01:00
2017-09-24 22:35:18 +02:00
/***** Remove projects of the course *****/
Prj_RemoveCrsProjects (CrsCod);
2017-05-31 21:05:59 +02:00
/***** Remove attendance events of the course *****/
Att_RemoveCrsAttEvents (CrsCod);
/***** Remove notices in the course *****/
/* Copy all notices from the course to table of deleted notices */
2018-11-02 19:37:11 +01:00
DB_QueryINSERT ("can not remove notices in a course",
"INSERT INTO notices_deleted"
" (NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif)"
" SELECT NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif"
" FROM notices"
" WHERE CrsCod=%ld",
CrsCod);
2018-10-27 14:14:34 +02:00
2017-05-31 21:05:59 +02:00
/* Remove all notices from the course */
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove notices in a course",
"DELETE FROM notices WHERE CrsCod=%ld",
CrsCod);
2017-05-31 21:05:59 +02:00
/***** Remove all the threads and posts in forums of the course *****/
2019-04-03 20:57:04 +02:00
For_RemoveForums (Hie_CRS,CrsCod);
2017-05-31 21:05:59 +02:00
2019-09-17 22:01:59 +02:00
/***** Remove games of the course *****/
Gam_RemoveGamesCrs (CrsCod);
2017-05-31 21:05:59 +02:00
/***** Remove surveys of the course *****/
2019-04-03 20:57:04 +02:00
Svy_RemoveSurveys (Hie_CRS,CrsCod);
2017-05-31 21:05:59 +02:00
/***** Remove all test exams made in the course *****/
2020-04-02 03:28:08 +02:00
TstExa_RemoveCrsExams (CrsCod);
2017-05-31 21:05:59 +02:00
/***** Remove all tests questions in the course *****/
Tst_RemoveCrsTests (CrsCod);
/***** Remove groups in the course *****/
/* Remove all the users in groups in the course */
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove users from groups of a course",
"DELETE FROM crs_grp_usr"
" USING crs_grp_types,crs_grp,crs_grp_usr"
" WHERE crs_grp_types.CrsCod=%ld"
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod",
CrsCod);
2017-05-31 21:05:59 +02:00
/* Remove all the groups in the course */
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove groups of a course",
"DELETE FROM crs_grp"
" USING crs_grp_types,crs_grp"
" WHERE crs_grp_types.CrsCod=%ld"
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod",
CrsCod);
2017-05-31 21:05:59 +02:00
/* Remove all the group types in the course */
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove types of group of a course",
"DELETE FROM crs_grp_types WHERE CrsCod=%ld",
CrsCod);
2017-05-31 21:05:59 +02:00
/***** Remove users' requests for inscription in the course *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove requests for inscription to a course",
"DELETE FROM crs_usr_requests WHERE CrsCod=%ld",
CrsCod);
2017-05-31 21:05:59 +02:00
/***** Remove possible users remaining in the course (teachers) *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove users from a course",
"DELETE FROM crs_usr WHERE CrsCod=%ld",
CrsCod);
2017-05-31 21:05:59 +02:00
/***** Remove directories of the course *****/
2018-10-17 10:32:18 +02:00
snprintf (PathRelCrs,sizeof (PathRelCrs),
2019-03-20 01:36:36 +01:00
"%s/%ld",
Cfg_PATH_CRS_PRIVATE,CrsCod);
2017-05-31 21:05:59 +02:00
Fil_RemoveTree (PathRelCrs);
2018-10-17 10:32:18 +02:00
snprintf (PathRelCrs,sizeof (PathRelCrs),
2019-03-20 01:36:36 +01:00
"%s/%ld",
Cfg_PATH_CRS_PUBLIC,CrsCod);
2017-05-31 21:05:59 +02:00
Fil_RemoveTree (PathRelCrs);
}
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************** Change the institutional code of a course ********************/
/*****************************************************************************/
void Crs_ChangeInsCrsCod (void)
{
extern const char *Txt_The_institutional_code_of_the_course_X_has_changed_to_Y;
extern const char *Txt_The_institutional_code_of_the_course_X_has_not_changed;
2017-03-07 11:03:05 +01:00
char NewInstitutionalCrsCod[Crs_MAX_BYTES_INSTITUTIONAL_CRS_COD + 1];
2014-12-01 23:55:08 +01:00
2019-04-07 19:49:53 +02:00
/***** Course constructor *****/
Crs_EditingCourseConstructor ();
2014-12-01 23:55:08 +01:00
/***** Get parameters from form *****/
/* Get course code */
2019-04-07 19:49:53 +02:00
Crs_EditingCrs->CrsCod = Crs_GetAndCheckParamOtherCrsCod (1);
2014-12-01 23:55:08 +01:00
/* Get institutional code */
2017-03-07 11:03:05 +01:00
Par_GetParToText ("InsCrsCod",NewInstitutionalCrsCod,Crs_MAX_BYTES_INSTITUTIONAL_CRS_COD);
2014-12-01 23:55:08 +01:00
/* Get data of the course */
2020-01-05 14:09:28 +01:00
Crs_GetDataOfCourseByCod (Crs_EditingCrs);
2014-12-01 23:55:08 +01:00
2019-04-07 19:49:53 +02:00
if (Crs_CheckIfICanEdit (Crs_EditingCrs))
2014-12-01 23:55:08 +01:00
{
/***** Change the institutional course code *****/
2019-04-07 19:49:53 +02:00
if (strcmp (NewInstitutionalCrsCod,Crs_EditingCrs->InstitutionalCrsCod))
2014-12-01 23:55:08 +01:00
{
2019-04-07 19:49:53 +02:00
Crs_UpdateInstitutionalCrsCod (Crs_EditingCrs,NewInstitutionalCrsCod);
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_institutional_code_of_the_course_X_has_changed_to_Y,
2019-04-07 19:49:53 +02:00
Crs_EditingCrs->ShrtName,
2019-03-09 20:12:44 +01:00
NewInstitutionalCrsCod);
2014-12-01 23:55:08 +01:00
}
else // The same institutional code
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_INFO,NULL,
Txt_The_institutional_code_of_the_course_X_has_not_changed,
2019-04-07 19:49:53 +02:00
Crs_EditingCrs->ShrtName);
2014-12-01 23:55:08 +01:00
}
else
2019-10-26 01:56:36 +02:00
Lay_NoPermissionExit ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************ Change the year of a course ************************/
/*****************************************************************************/
void Crs_ChangeCrsYear (void)
{
extern const char *Txt_The_course_X_already_exists_in_year_Y;
2017-01-28 15:58:46 +01:00
extern const char *Txt_YEAR_OF_DEGREE[1 + Deg_MAX_YEARS_PER_DEGREE];
2014-12-01 23:55:08 +01:00
extern const char *Txt_The_year_of_the_course_X_has_changed;
2016-02-29 18:53:26 +01:00
extern const char *Txt_The_year_X_is_not_allowed;
2017-01-28 15:58:46 +01:00
char YearStr[2 + 1];
2014-12-01 23:55:08 +01:00
unsigned NewYear;
2019-04-07 19:49:53 +02:00
/***** Course constructor *****/
Crs_EditingCourseConstructor ();
2014-12-01 23:55:08 +01:00
/***** Get parameters from form *****/
/* Get course code */
2019-04-07 19:49:53 +02:00
Crs_EditingCrs->CrsCod = Crs_GetAndCheckParamOtherCrsCod (1);
2014-12-01 23:55:08 +01:00
/* Get parameter with year */
Par_GetParToText ("OthCrsYear",YearStr,2);
NewYear = Deg_ConvStrToYear (YearStr);
2020-01-05 14:09:28 +01:00
Crs_GetDataOfCourseByCod (Crs_EditingCrs);
2014-12-01 23:55:08 +01:00
2019-04-07 19:49:53 +02:00
if (Crs_CheckIfICanEdit (Crs_EditingCrs))
2014-12-01 23:55:08 +01:00
{
2016-02-29 18:53:26 +01:00
if (NewYear <= Deg_MAX_YEARS_PER_DEGREE) // If year is valid
2014-12-01 23:55:08 +01:00
{
/***** If name of course was in database in the new year... *****/
2019-04-07 19:49:53 +02:00
if (Crs_CheckIfCrsNameExistsInYearOfDeg ("ShortName",Crs_EditingCrs->ShrtName,
-1L,Crs_EditingCrs->DegCod,NewYear))
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_course_X_already_exists_in_year_Y,
2019-04-07 19:49:53 +02:00
Crs_EditingCrs->ShrtName,
2019-03-09 20:12:44 +01:00
Txt_YEAR_OF_DEGREE[NewYear]);
2019-04-07 19:49:53 +02:00
else if (Crs_CheckIfCrsNameExistsInYearOfDeg ("FullName",Crs_EditingCrs->FullName,
-1L,Crs_EditingCrs->DegCod,NewYear))
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_course_X_already_exists_in_year_Y,
2019-04-07 19:49:53 +02:00
Crs_EditingCrs->FullName,
2019-03-09 20:12:44 +01:00
Txt_YEAR_OF_DEGREE[NewYear]);
2014-12-01 23:55:08 +01:00
else // Update year in database
{
/***** Update year in table of courses *****/
2019-04-07 19:49:53 +02:00
Crs_UpdateCrsYear (Crs_EditingCrs,NewYear);
2014-12-01 23:55:08 +01:00
2016-03-24 20:13:42 +01:00
/***** Create message to show the change made *****/
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_year_of_the_course_X_has_changed,
2019-04-07 19:49:53 +02:00
Crs_EditingCrs->ShrtName);
2014-12-01 23:55:08 +01:00
}
}
else // Year not valid
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_year_X_is_not_allowed,
NewYear);
2014-12-01 23:55:08 +01:00
}
else
2019-10-26 01:56:36 +02:00
Lay_NoPermissionExit ();
2014-12-01 23:55:08 +01:00
}
2016-06-12 01:18:35 +02:00
/*****************************************************************************/
/****************** Change the year/semester of a course *********************/
/*****************************************************************************/
2019-12-29 14:20:17 +01:00
void Crs_UpdateCrsYear (struct Course *Crs,unsigned NewYear)
2016-06-12 01:18:35 +02:00
{
/***** Update year/semester in table of courses *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the year of a course",
"UPDATE courses SET Year=%u WHERE CrsCod=%ld",
NewYear,Crs->CrsCod);
2016-06-12 01:18:35 +02:00
2016-07-02 11:26:08 +02:00
/***** Copy course year/semester *****/
2016-06-12 01:18:35 +02:00
Crs->Year = NewYear;
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-03-01 13:36:48 +01:00
/************* Change the institutional course code of a course **************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-03-01 13:36:48 +01:00
void Crs_UpdateInstitutionalCrsCod (struct Course *Crs,const char *NewInstitutionalCrsCod)
2014-12-01 23:55:08 +01:00
{
/***** Update institutional course code in table of courses *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the institutional code"
" of the current course",
"UPDATE courses SET InsCrsCod='%s' WHERE CrsCod=%ld",
NewInstitutionalCrsCod,Crs->CrsCod);
2014-12-01 23:55:08 +01:00
/***** Copy institutional course code *****/
2017-01-15 18:02:52 +01:00
Str_Copy (Crs->InstitutionalCrsCod,NewInstitutionalCrsCod,
2017-03-07 11:03:05 +01:00
Crs_MAX_BYTES_INSTITUTIONAL_CRS_COD);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2019-04-07 19:49:53 +02:00
/************************ Change the name of a course ************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
void Crs_RenameCourseShort (void)
{
2019-04-07 19:49:53 +02:00
/***** Course constructor *****/
Crs_EditingCourseConstructor ();
/***** Rename course *****/
Crs_EditingCrs->CrsCod = Crs_GetAndCheckParamOtherCrsCod (1);
Crs_RenameCourse (Crs_EditingCrs,Cns_SHRT_NAME);
2014-12-01 23:55:08 +01:00
}
2019-04-07 19:49:53 +02:00
void Crs_RenameCourseFull (void)
2016-10-23 18:23:37 +02:00
{
2019-04-07 19:49:53 +02:00
/***** Course constructor *****/
Crs_EditingCourseConstructor ();
/***** Rename course *****/
Crs_EditingCrs->CrsCod = Crs_GetAndCheckParamOtherCrsCod (1);
Crs_RenameCourse (Crs_EditingCrs,Cns_FULL_NAME);
2016-10-23 18:23:37 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************ Change the name of a course ************************/
/*****************************************************************************/
2019-12-29 14:20:17 +01:00
void Crs_RenameCourse (struct Course *Crs,Cns_ShrtOrFullName_t ShrtOrFullName)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_The_course_X_already_exists;
extern const char *Txt_The_name_of_the_course_X_has_changed_to_Y;
extern const char *Txt_The_name_of_the_course_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 *CurrentCrsName = NULL; // Initialized to avoid warning
2017-03-08 14:12:33 +01:00
char NewCrsName[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
CurrentCrsName = Crs->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
CurrentCrsName = Crs->FullName;
break;
}
/***** Get parameters from form *****/
/* Get the new name for the course */
2017-03-07 11:03:05 +01:00
Par_GetParToText (ParamName,NewCrsName,MaxBytes);
2014-12-01 23:55:08 +01:00
/***** Get from the database the data of the degree *****/
2020-01-05 14:09:28 +01:00
Crs_GetDataOfCourseByCod (Crs);
2014-12-01 23:55:08 +01:00
if (Crs_CheckIfICanEdit (Crs))
{
/***** Check if new name is empty *****/
2019-12-20 00:30:54 +01:00
if (NewCrsName[0])
2014-12-01 23:55:08 +01:00
{
2019-01-02 15:10:51 +01:00
/***** Check if old and new names are the same
(this happens when return is pressed without changes) *****/
2014-12-01 23:55:08 +01:00
if (strcmp (CurrentCrsName,NewCrsName)) // Different names
{
/***** If course was in database... *****/
2016-10-20 19:46:06 +02:00
if (Crs_CheckIfCrsNameExistsInYearOfDeg (ParamName,NewCrsName,Crs->CrsCod,
Crs->DegCod,Crs->Year))
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_course_X_already_exists,
NewCrsName);
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
Crs_UpdateCrsNameDB (Crs->CrsCod,FieldName,NewCrsName);
2014-12-01 23:55:08 +01:00
2019-03-09 20:12:44 +01:00
/* Create alert to show the change made */
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_name_of_the_course_X_has_changed_to_Y,
CurrentCrsName,NewCrsName);
2014-12-01 23:55:08 +01:00
2016-03-01 12:01:28 +01:00
/* Change current course name in order to display it properly */
2017-01-17 03:10:43 +01:00
Str_Copy (CurrentCrsName,NewCrsName,
2017-03-07 11:03:05 +01:00
MaxBytes);
2014-12-01 23:55:08 +01:00
}
}
else // The same name
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_INFO,NULL,
Txt_The_name_of_the_course_X_has_not_changed,
CurrentCrsName);
2014-12-01 23:55:08 +01:00
}
2019-12-20 00:30:54 +01:00
else
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
2014-12-01 23:55:08 +01:00
}
else
2019-10-26 01:56:36 +02:00
Lay_NoPermissionExit ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2017-03-09 11:16:17 +01:00
/********** Check if the name of course exists in existing courses ***********/
/*****************************************************************************/
2019-12-29 14:20:17 +01:00
bool Crs_CheckIfCrsNameExistsInYearOfDeg (const char *FieldName,const char *Name,long CrsCod,
long DegCod,unsigned Year)
2017-03-09 11:16:17 +01:00
{
/***** Get number of courses in a year of a degree and with a name from database *****/
2018-11-03 13:13:11 +01:00
return (DB_QueryCOUNT ("can not check if the name"
" of a course already existed",
"SELECT COUNT(*) FROM courses"
" WHERE DegCod=%ld AND Year=%u"
" AND %s='%s' AND CrsCod<>%ld",
DegCod,Year,FieldName,Name,CrsCod) != 0);
2017-03-09 11:16:17 +01:00
}
/*****************************************************************************/
/***************** Update course name in table of courses ********************/
/*****************************************************************************/
static void Crs_UpdateCrsNameDB (long CrsCod,const char *FieldName,const char *NewCrsName)
{
/***** Update course changing old name by new name *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the name of a course",
"UPDATE courses SET %s='%s' WHERE CrsCod=%ld",
FieldName,NewCrsName,CrsCod);
2017-03-09 11:16:17 +01:00
}
/*****************************************************************************/
2014-12-01 23:55:08 +01:00
/*********************** Change the status of a course ***********************/
/*****************************************************************************/
void Crs_ChangeCrsStatus (void)
{
extern const char *Txt_The_status_of_the_course_X_has_changed;
Crs_Status_t Status;
Crs_StatusTxt_t StatusTxt;
2019-04-07 19:49:53 +02:00
/***** Course constructor *****/
Crs_EditingCourseConstructor ();
2014-12-01 23:55:08 +01:00
/***** Get parameters from form *****/
/* Get course code */
2019-04-07 19:49:53 +02:00
Crs_EditingCrs->CrsCod = Crs_GetAndCheckParamOtherCrsCod (1);
2014-12-01 23:55:08 +01:00
/* Get parameter with status */
2017-01-29 21:41:08 +01:00
Status = (Crs_Status_t)
Par_GetParToUnsignedLong ("Status",
0,
(unsigned long) Crs_MAX_STATUS,
(unsigned long) Crs_WRONG_STATUS);
2017-01-29 12:42:19 +01:00
if (Status == Crs_WRONG_STATUS)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Wrong status.");
StatusTxt = Crs_GetStatusTxtFromStatusBits (Status);
Status = Crs_GetStatusBitsFromStatusTxt (StatusTxt); // New status
/***** Get data of course *****/
2020-01-05 14:09:28 +01:00
Crs_GetDataOfCourseByCod (Crs_EditingCrs);
2014-12-01 23:55:08 +01:00
/***** Update status in table of courses *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the status of a course",
"UPDATE courses SET Status=%u WHERE CrsCod=%ld",
2019-04-07 19:49:53 +02:00
(unsigned) Status,Crs_EditingCrs->CrsCod);
Crs_EditingCrs->Status = Status;
2014-12-01 23:55:08 +01:00
2019-03-09 20:12:44 +01:00
/***** Create alert to show the change made *****/
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_status_of_the_course_X_has_changed,
2019-04-07 19:49:53 +02:00
Crs_EditingCrs->ShrtName);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2019-04-08 14:52:13 +02:00
/********* Show alerts after changing a course and continue editing **********/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
void Crs_ContEditAfterChgCrs (void)
{
2016-03-24 20:13:42 +01:00
bool PutButtonToRequestRegistration;
2019-03-09 20:12:44 +01:00
if (Ale_GetTypeOfLastAlert () == Ale_SUCCESS)
2017-03-26 03:36:48 +02:00
{
2019-03-09 20:12:44 +01:00
/***** Start alert *****/
Ale_ShowLastAlertAndButton1 ();
2016-03-01 13:36:48 +01:00
/***** Put button to go to course changed *****/
2017-05-11 20:55:04 +02:00
Crs_PutButtonToGoToCrs ();
2016-03-24 20:13:42 +01:00
/***** Put button to request my registration in course *****/
PutButtonToRequestRegistration = false;
2017-06-04 18:18:54 +02:00
switch (Gbl.Usrs.Me.Role.Logged)
2016-03-24 20:13:42 +01:00
{
2017-05-18 19:13:41 +02:00
case Rol_GST: // I do not belong to any course
2016-03-24 20:13:42 +01:00
PutButtonToRequestRegistration = true;
break;
2017-05-18 19:13:41 +02:00
case Rol_USR:
2016-03-24 20:13:42 +01:00
PutButtonToRequestRegistration = !Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Me.UsrDat.UsrCod,
2019-04-07 19:49:53 +02:00
Crs_EditingCrs->CrsCod,
2016-03-24 20:13:42 +01:00
false);
break;
2017-05-18 19:13:41 +02:00
case Rol_STD:
2017-05-21 21:23:13 +02:00
case Rol_NET:
2017-05-18 19:13:41 +02:00
case Rol_TCH:
2019-04-07 19:49:53 +02:00
if (Crs_EditingCrs->CrsCod != Gbl.Hierarchy.Crs.CrsCod)
2016-03-24 20:13:42 +01:00
PutButtonToRequestRegistration = !Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Me.UsrDat.UsrCod,
2019-04-07 19:49:53 +02:00
Crs_EditingCrs->CrsCod,
2016-03-24 20:13:42 +01:00
false);
break;
default:
break;
}
if (PutButtonToRequestRegistration)
2017-05-11 20:55:04 +02:00
Crs_PutButtonToRegisterInCrs ();
2019-03-09 20:12:44 +01:00
/***** End alert *****/
2020-03-26 02:54:30 +01:00
Ale_ShowAlertAndButton2 (ActUnk,NULL,NULL,
NULL,NULL,
Btn_NO_BUTTON,NULL);
2016-03-01 13:36:48 +01:00
}
2014-12-01 23:55:08 +01:00
2019-03-09 20:12:44 +01:00
/***** Show possible delayed alerts *****/
Ale_ShowAlerts (NULL);
2017-05-11 20:04:38 +02:00
2014-12-01 23:55:08 +01:00
/***** Show the form again *****/
2019-04-07 19:49:53 +02:00
Crs_EditCoursesInternal ();
/***** Course destructor *****/
Crs_EditingCourseDestructor ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2016-03-01 12:01:28 +01:00
/************************ Put button to go to course *************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2017-05-11 20:55:04 +02:00
static void Crs_PutButtonToGoToCrs (void)
2014-12-01 23:55:08 +01:00
{
2017-05-11 20:55:04 +02:00
// If the course being edited is different to the current one...
2019-04-07 19:49:53 +02:00
if (Crs_EditingCrs->CrsCod != Gbl.Hierarchy.Crs.CrsCod)
2016-03-01 23:58:48 +01:00
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActSeeCrsInf);
2019-04-07 19:49:53 +02:00
Crs_PutParamCrsCod (Crs_EditingCrs->CrsCod);
2019-12-30 12:25:45 +01:00
Btn_PutConfirmButton (Hie_BuildGoToMsg (Crs_EditingCrs->ShrtName));
Hie_FreeGoToMsg ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-03-01 23:58:48 +01:00
}
2014-12-01 23:55:08 +01:00
}
2016-03-24 20:13:42 +01:00
/*****************************************************************************/
/************************ Put button to go to course *************************/
/*****************************************************************************/
2017-05-11 20:55:04 +02:00
static void Crs_PutButtonToRegisterInCrs (void)
2016-03-24 20:13:42 +01:00
{
extern const char *Txt_Register_me_in_X;
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActReqSignUp);
2019-04-08 23:34:58 +02:00
// If the course being edited is different to the current one...
2019-04-07 19:49:53 +02:00
if (Crs_EditingCrs->CrsCod != Gbl.Hierarchy.Crs.CrsCod)
Crs_PutParamCrsCod (Crs_EditingCrs->CrsCod);
2019-12-30 21:47:07 +01:00
Btn_PutCreateButton (Str_BuildStringStr (Txt_Register_me_in_X,
Crs_EditingCrs->ShrtName));
Str_FreeString ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-03-24 20:13:42 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************* Select one of my courses **************************/
/*****************************************************************************/
void Crs_ReqSelectOneOfMyCourses (void)
{
2018-10-09 13:08:41 +02:00
/***** Fill the list with the courses I belong to, if not filled *****/
2014-12-01 23:55:08 +01:00
Usr_GetMyCourses ();
2018-10-09 13:08:41 +02:00
/***** Select one of my courses *****/
2016-10-28 10:03:37 +02:00
if (Gbl.Usrs.Me.MyCrss.Num)
2015-10-06 01:19:21 +02:00
/* Show my courses */
2014-12-01 23:55:08 +01:00
Crs_WriteListMyCoursesToSelectOne ();
2017-03-30 11:20:06 +02:00
else // I am not enroled in any course
/* Show help to enrol me */
2015-10-06 20:34:49 +02:00
Hlp_ShowHelpWhatWouldYouLikeToDo ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2018-10-09 13:08:41 +02:00
/******************* Put an icon (form) to search courses ********************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2020-04-08 13:40:21 +02:00
static void Crs_PutIconToSearchCourses (__attribute__((unused)) void *Args)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_Search_courses;
2020-04-08 13:40:21 +02:00
/***** Put form to search / select courses *****/
Lay_PutContextualLinkOnlyIcon (ActReqSch,NULL,
Sch_PutLinkToSearchCoursesParams,NULL,
"search.svg",
Txt_Search_courses);
2014-12-01 23:55:08 +01:00
}
2018-10-09 17:56:18 +02:00
/*****************************************************************************/
/********** Put an icon (form) to select my courses in breadcrumb ************/
/*****************************************************************************/
void Crs_PutIconToSelectMyCoursesInBreadcrumb (void)
{
extern const char *Txt_My_courses;
2018-10-10 08:59:26 +02:00
if (Gbl.Usrs.Me.Logged) // I am logged
{
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
2019-01-11 12:47:02 +01:00
Frm_StartForm (ActMyCrs);
2018-10-09 17:56:18 +02:00
2019-01-11 12:47:02 +01:00
/***** Put icon with link *****/
2019-11-18 11:23:48 +01:00
HTM_INPUT_IMAGE (Gbl.Prefs.URLTheme,"sitemap.svg",Txt_My_courses,
"BC_ICON ICO_HIGHLIGHT");
/*
HTM_BUTTON_Begin (Txt_My_courses,NULL,NULL);
2019-10-30 00:42:01 +01:00
HTM_IMG (Gbl.Prefs.URLTheme,"sitemap.svg",Txt_My_courses,
2019-10-30 22:31:03 +01:00
"class=\"BC_ICON ICO_HIGHLIGHT\"");
2019-11-18 11:23:48 +01:00
HTM_BUTTON_End ();
*/
2019-01-11 12:47:02 +01:00
/***** End form *****/
Frm_EndForm ();
2018-10-10 08:59:26 +02:00
}
2018-10-09 17:56:18 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2018-10-09 13:41:55 +02:00
/****************** Put an icon (form) to select my courses ******************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2020-04-08 13:40:21 +02:00
void Crs_PutIconToSelectMyCourses (__attribute__((unused)) void *Args)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_My_courses;
2020-04-08 13:40:21 +02:00
if (Gbl.Usrs.Me.Logged) // I am logged
/***** Put icon with link *****/
Lay_PutContextualLinkOnlyIcon (ActMyCrs,NULL,
NULL,NULL,
"sitemap.svg",
Txt_My_courses);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Write parameter with code of course ********************/
/*****************************************************************************/
void Crs_PutParamCrsCod (long CrsCod)
{
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamLong (NULL,"crs",CrsCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Write parameter with code of course ********************/
/*****************************************************************************/
static void Crs_PutParamOtherCrsCod (long CrsCod)
{
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamLong (NULL,"OthCrsCod",CrsCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Get parameter with code of course *********************/
/*****************************************************************************/
2017-05-31 21:05:59 +02:00
static long Crs_GetAndCheckParamOtherCrsCod (long MinCodAllowed)
2014-12-01 23:55:08 +01:00
{
2016-10-23 18:32:46 +02:00
long CrsCod;
2014-12-01 23:55:08 +01:00
2016-10-23 19:40:14 +02:00
/***** Get and check parameter with code of course *****/
2017-05-31 21:05:59 +02:00
if ((CrsCod = Par_GetParToLong ("OthCrsCod")) < MinCodAllowed)
Lay_ShowErrorAndExit ("Code of course is missing or invalid.");
2016-10-23 18:32:46 +02:00
return CrsCod;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************** Write courses of a user **************************/
/*****************************************************************************/
2016-06-16 11:28:20 +02:00
void Crs_GetAndWriteCrssOfAUsr (const struct UsrData *UsrDat,Rol_Role_t Role)
2014-12-01 23:55:08 +01:00
{
2016-06-16 11:28:20 +02:00
extern const char *Txt_USER_in_COURSE;
2016-09-22 22:09:24 +02:00
extern const char *Txt_User[Usr_NUM_SEXS];
2016-06-16 11:28:20 +02:00
extern const char *Txt_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Degree;
extern const char *Txt_Year_OF_A_DEGREE;
extern const char *Txt_Course;
2017-05-30 21:43:05 +02:00
extern const char *Txt_ROLES_PLURAL_BRIEF_Abc[Rol_NUM_ROLES];
2018-10-30 01:00:46 +01:00
char *SubQuery;
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCrss;
unsigned NumCrs;
/***** Get courses of a user from database *****/
2018-10-30 01:00:46 +01:00
if (Role == Rol_UNK) // Role == Rol_UNK ==> any role
{
if (asprintf (&SubQuery,"%s","") < 0)
Lay_NotEnoughMemoryExit ();
}
2016-09-08 21:40:31 +02:00
else
2018-10-30 01:00:46 +01:00
{
if (asprintf (&SubQuery," AND crs_usr.Role=%u",(unsigned) Role) < 0)
Lay_NotEnoughMemoryExit ();
}
2018-10-30 14:47:31 +01:00
NumCrss = (unsigned) DB_QuerySELECT (&mysql_res,"can not get courses of a user",
"SELECT degrees.DegCod,courses.CrsCod,degrees.ShortName,degrees.FullName,"
"courses.Year,courses.FullName,centres.ShortName,crs_usr.Accepted"
" FROM crs_usr,courses,degrees,centres"
" WHERE crs_usr.UsrCod=%ld%s"
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
" ORDER BY degrees.FullName,courses.Year,courses.FullName",
UsrDat->UsrCod,SubQuery);
2018-10-30 01:00:46 +01:00
/***** Free allocated memory for subquery *****/
2019-11-06 19:45:20 +01:00
free (SubQuery);
2014-12-01 23:55:08 +01:00
/***** List the courses (one row per course) *****/
2018-10-30 01:00:46 +01:00
if (NumCrss)
2014-12-01 23:55:08 +01:00
{
2019-10-26 02:19:42 +02:00
/* Begin box and table */
2020-03-26 02:54:30 +01:00
Box_BoxTableBegin ("100%",NULL,
NULL,NULL,
2017-06-12 15:03:29 +02:00
NULL,Box_NOT_CLOSABLE,2);
2016-06-15 20:35:49 +02:00
2014-12-01 23:55:08 +01:00
/* Heading row */
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-11 09:09:19 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH_Begin (1,7,"LM");
2019-12-30 21:47:07 +01:00
HTM_TxtF ("%s:",Str_BuildStringStr (Txt_USER_in_COURSE,
Role == Rol_UNK ? Txt_User[Usr_SEX_UNKNOWN] : // Role == Rol_UNK ==> any role
Txt_ROLES_SINGUL_Abc[Role][UsrDat->Sex]));
Str_FreeString ();
2019-10-23 19:05:05 +02:00
HTM_TH_End ();
2019-10-11 09:09:19 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-10-04 01:35:40 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-11 09:09:19 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH (1,1,"BM",NULL);
HTM_TH (1,1,"BM",NULL);
HTM_TH (1,1,"LM",Txt_Degree);
HTM_TH (1,1,"CM",Txt_Year_OF_A_DEGREE);
HTM_TH (1,1,"LM",Txt_Course);
HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]);
HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD]);
2019-10-11 09:09:19 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/* Write courses */
for (NumCrs = 1;
NumCrs <= NumCrss;
NumCrs++)
{
/* Get next course */
row = mysql_fetch_row (mysql_res);
/* Write data of this course */
Crs_WriteRowCrsData (NumCrs,row,true);
}
2016-06-15 20:35:49 +02:00
2017-06-12 14:16:33 +02:00
/* End table and box */
2019-11-25 23:18:08 +01:00
Box_BoxTableEnd ();
2014-12-01 23:55:08 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
2018-10-30 17:47:57 +01:00
/**************************** List courses found *****************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2018-10-30 14:47:31 +01:00
void Crs_ListCrssFound (MYSQL_RES **mysql_res,unsigned NumCrss)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_course;
extern const char *Txt_courses;
extern const char *Txt_Degree;
extern const char *Txt_Year_OF_A_DEGREE;
extern const char *Txt_Course;
2017-05-30 21:43:05 +02:00
extern const char *Txt_ROLES_PLURAL_BRIEF_Abc[Rol_NUM_ROLES];
2014-12-01 23:55:08 +01:00
MYSQL_ROW row;
unsigned NumCrs;
/***** List the courses (one row per course) *****/
if (NumCrss)
{
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
2014-12-01 23:55:08 +01:00
/* Number of courses found */
2019-12-30 21:47:07 +01:00
Box_BoxTableBegin (NULL,Str_BuildStringLongStr ((long) NumCrss,
(NumCrss == 1) ? Txt_course :
Txt_courses),
2020-03-26 02:54:30 +01:00
NULL,NULL,
NULL,Box_NOT_CLOSABLE,2);
2019-12-30 21:47:07 +01:00
Str_FreeString ();
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** Heading row *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-11 09:09:19 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH (1,1,"BM",NULL);
HTM_TH (1,1,"LM",Txt_Degree);
HTM_TH (1,1,"CM",Txt_Year_OF_A_DEGREE);
HTM_TH (1,1,"LM",Txt_Course);
HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]);
HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD]);
2019-10-11 09:09:19 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** Write courses *****/
2014-12-01 23:55:08 +01:00
for (NumCrs = 1;
NumCrs <= NumCrss;
NumCrs++)
{
/* Get next course */
2018-10-30 14:47:31 +01:00
row = mysql_fetch_row (*mysql_res);
2014-12-01 23:55:08 +01:00
/* Write data of this course */
Crs_WriteRowCrsData (NumCrs,row,false);
}
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableEnd ();
2014-12-01 23:55:08 +01:00
}
/***** Free structure that stores the query result *****/
2018-10-30 14:47:31 +01:00
DB_FreeMySQLResult (mysql_res);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************** Write the data of a course (result of a query) ***************/
/*****************************************************************************/
static void Crs_WriteRowCrsData (unsigned NumCrs,MYSQL_ROW row,bool WriteColumnAccepted)
{
2017-03-30 11:20:06 +02:00
extern const char *Txt_Enrolment_confirmed;
extern const char *Txt_Enrolment_not_confirmed;
2017-01-28 15:58:46 +01:00
extern const char *Txt_YEAR_OF_DEGREE[1 + Deg_MAX_YEARS_PER_DEGREE];
2015-01-17 19:31:21 +01:00
struct Degree Deg;
2014-12-01 23:55:08 +01:00
long CrsCod;
unsigned NumTchs;
2016-06-04 13:07:33 +02:00
unsigned NumStds;
2019-11-19 11:03:05 +01:00
const char *ClassTxt;
const char *ClassLink;
2015-09-04 19:26:08 +02:00
const char *BgColor;
2014-12-01 23:55:08 +01:00
bool Accepted;
2016-06-16 11:28:20 +02:00
static unsigned RowEvenOdd = 1;
2014-12-01 23:55:08 +01:00
2015-01-21 10:26:08 +01:00
/*
2016-06-12 13:47:19 +02:00
SELECT degrees.DegCod 0
courses.CrsCod 1
degrees.ShortName 2
degrees.FullName 3
courses.Year 4
courses.FullName 5
centres.ShortName 6
crs_usr.Accepted 7 (only if WriteColumnAccepted == true)
2015-01-21 10:26:08 +01:00
*/
2014-12-01 23:55:08 +01:00
/***** Get degree code (row[0]) *****/
2015-01-17 19:31:21 +01:00
if ((Deg.DegCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Wrong code of degree.");
2020-01-05 12:52:03 +01:00
if (!Deg_GetDataOfDegreeByCod (&Deg))
2015-01-17 19:31:21 +01:00
Lay_ShowErrorAndExit ("Degree not found.");
2014-12-01 23:55:08 +01:00
/***** Get course code (row[1]) *****/
if ((CrsCod = Str_ConvertStrCodToLongCod (row[1])) < 0)
Lay_ShowErrorAndExit ("Wrong code of course.");
2016-06-04 13:07:33 +02:00
/***** Get number of teachers and students in this course *****/
2020-01-08 23:49:04 +01:00
NumTchs = Usr_GetNumUsrsInCrss (Hie_CRS,CrsCod,
1 << Rol_NET |
1 << Rol_TCH);
NumStds = Usr_GetNumUsrsInCrss (Hie_CRS,CrsCod,
1 << Rol_STD);
2016-06-04 13:07:33 +02:00
if (NumTchs + NumStds)
2014-12-01 23:55:08 +01:00
{
2019-11-19 11:03:05 +01:00
ClassTxt = "DAT_N";
ClassLink = "BT_LINK LT DAT_N";
2014-12-01 23:55:08 +01:00
}
else
{
2019-11-19 11:03:05 +01:00
ClassTxt = "DAT";
ClassLink = "BT_LINK LT DAT";
2014-12-01 23:55:08 +01:00
}
2019-04-04 10:45:15 +02:00
BgColor = (CrsCod == Gbl.Hierarchy.Crs.CrsCod) ? "LIGHT_BLUE" :
2016-06-16 11:28:20 +02:00
Gbl.ColorRows[RowEvenOdd];
2014-12-01 23:55:08 +01:00
/***** Start row *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2014-12-01 23:55:08 +01:00
2016-06-16 11:28:20 +02:00
/***** User has accepted joining to this course/to any course in degree/to any course? *****/
2014-12-01 23:55:08 +01:00
if (WriteColumnAccepted)
{
2016-09-07 18:48:10 +02:00
Accepted = (row[7][0] == 'Y');
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"BT %s\" title=\"%s\"",
2019-10-10 23:14:13 +02:00
BgColor,
Accepted ? Txt_Enrolment_confirmed :
Txt_Enrolment_not_confirmed);
2019-11-10 12:36:37 +01:00
HTM_Txt (Accepted ? "&check;" :
2018-12-08 19:30:14 +01:00
"&cross;");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
}
/***** Write number of course in this search *****/
2019-11-19 11:03:05 +01:00
HTM_TD_Begin ("class=\"%s RT %s\"",ClassTxt,BgColor);
2019-11-10 13:31:47 +01:00
HTM_Unsigned (NumCrs);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2015-09-04 17:10:27 +02:00
/***** Write degree logo, degree short name (row[2])
2015-12-06 01:02:47 +01:00
and centre short name (row[6]) *****/
2019-11-19 11:03:05 +01:00
HTM_TD_Begin ("class=\"LT %s\"",BgColor);
2018-11-09 20:47:39 +01:00
Frm_StartFormGoTo (ActSeeDegInf);
2015-01-17 19:31:21 +01:00
Deg_PutParamDegCod (Deg.DegCod);
2019-12-30 12:25:45 +01:00
HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (row[2]),ClassLink,NULL);
Hie_FreeGoToMsg ();
2019-12-14 14:30:34 +01:00
Lgo_DrawLogo (Hie_DEG,Deg.DegCod,Deg.ShrtName,20,"CT",true);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("&nbsp;%s&nbsp;(%s)",row[2],row[6]);
2019-11-18 11:23:48 +01:00
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2015-01-17 19:31:21 +01:00
/***** Write year (row[4]) *****/
2019-11-19 11:03:05 +01:00
HTM_TD_Begin ("class=\"%s CT %s\"",ClassTxt,BgColor);
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_YEAR_OF_DEGREE[Deg_ConvStrToYear (row[4])]);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2015-12-06 01:02:47 +01:00
/***** Write course full name (row[5]) *****/
2019-11-19 11:03:05 +01:00
HTM_TD_Begin ("class=\"LT %s\"",BgColor);
2018-11-09 20:47:39 +01:00
Frm_StartFormGoTo (ActSeeCrsInf);
2014-12-01 23:55:08 +01:00
Crs_PutParamCrsCod (CrsCod);
2019-12-30 12:25:45 +01:00
HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (row[5]),ClassLink,NULL);
Hie_FreeGoToMsg ();
2019-11-10 12:36:37 +01:00
HTM_Txt (row[5]);
2019-11-18 11:23:48 +01:00
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Write number of teachers in course *****/
2019-11-19 11:03:05 +01:00
HTM_TD_Begin ("class=\"%s RT %s\"",ClassTxt,BgColor);
2019-11-10 13:31:47 +01:00
HTM_Unsigned (NumTchs);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2016-06-04 13:07:33 +02:00
/***** Write number of students in course *****/
2019-11-19 11:03:05 +01:00
HTM_TD_Begin ("class=\"%s RT %s\"",ClassTxt,BgColor);
2019-11-10 13:31:47 +01:00
HTM_Unsigned (NumStds);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2016-06-04 13:07:33 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-10-07 00:05:24 +02:00
2016-06-16 11:28:20 +02:00
RowEvenOdd = 1 - RowEvenOdd;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************** Update my last click in current course ********************/
/*****************************************************************************/
void Crs_UpdateCrsLast (void)
{
2019-04-03 20:57:04 +02:00
if (Gbl.Hierarchy.Level == Hie_CRS && // Course selected
2017-06-04 18:18:54 +02:00
Gbl.Usrs.Me.Role.Logged >= Rol_STD)
2014-12-01 23:55:08 +01:00
/***** Update my last access to current course *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update last access to current course",
"REPLACE INTO crs_last (CrsCod,LastTime)"
" VALUES (%ld,NOW())",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
}
2017-03-27 01:14:38 +02:00
/*****************************************************************************/
/********************** Put link to remove old courses ***********************/
/*****************************************************************************/
void Crs_PutLinkToRemoveOldCrss (void)
{
extern const char *Txt_Eliminate_old_courses;
/***** Put form to remove old courses *****/
2020-03-26 02:54:30 +01:00
Lay_PutContextualLinkIconText (ActReqRemOldCrs,NULL,
NULL,NULL,
2019-01-12 03:00:59 +01:00
"trash.svg",
Txt_Eliminate_old_courses);
2017-03-27 01:14:38 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************** Write form to remove old courses *********************/
/*****************************************************************************/
void Crs_AskRemoveOldCrss (void)
{
2020-01-30 20:47:00 +01:00
extern const char *Hlp_SYSTEM_Maintenance_eliminate_old_courses;
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormInBox[The_NUM_THEMES];
2015-10-07 23:03:30 +02:00
extern const char *Txt_Eliminate_old_courses;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Eliminate_all_courses_whithout_users_PART_1_OF_2;
extern const char *Txt_Eliminate_all_courses_whithout_users_PART_2_OF_2;
extern const char *Txt_Eliminate;
unsigned MonthsWithoutAccess = Crs_DEF_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_CRSS;
unsigned i;
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRemOldCrs);
2015-10-07 23:03:30 +02:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2020-03-26 02:54:30 +01:00
Box_BoxBegin (NULL,Txt_Eliminate_old_courses,
NULL,NULL,
2020-01-30 20:47:00 +01:00
Hlp_SYSTEM_Maintenance_eliminate_old_courses,Box_NOT_CLOSABLE);
2015-10-07 23:03:30 +02:00
/***** Form to request number of months without clicks *****/
2019-11-02 23:40:52 +01:00
HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s&nbsp;",Txt_Eliminate_all_courses_whithout_users_PART_1_OF_2);
2019-11-05 15:47:35 +01:00
HTM_SELECT_Begin (false,
"name=\"Months\"");
2014-12-01 23:55:08 +01:00
for (i = Crs_MIN_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_CRSS;
i <= Crs_MAX_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_CRSS;
i++)
2019-11-06 19:45:20 +01:00
HTM_OPTION (HTM_Type_UNSIGNED,&i,
2019-11-06 08:59:15 +01:00
i == MonthsWithoutAccess,false,
"%u",i);
2019-11-05 08:46:38 +01:00
HTM_SELECT_End ();
2019-11-14 08:59:11 +01:00
HTM_NBSP ();
2019-11-11 00:15:44 +01:00
HTM_TxtF (Txt_Eliminate_all_courses_whithout_users_PART_2_OF_2,
Cfg_PLATFORM_SHORT_NAME);
2019-11-02 12:59:31 +01:00
HTM_LABEL_End ();
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** Send button and end box *****/
2019-11-25 23:18:08 +01:00
Box_BoxWithButtonEnd (Btn_REMOVE_BUTTON,Txt_Eliminate);
2015-10-07 23:03:30 +02:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/**************************** Remove old courses *****************************/
/*****************************************************************************/
void Crs_RemoveOldCrss (void)
{
extern const char *Txt_Eliminating_X_courses_whithout_users_and_with_more_than_Y_months_without_access;
extern const char *Txt_X_courses_have_been_eliminated;
unsigned MonthsWithoutAccess;
unsigned long SecondsWithoutAccess;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumCrs;
unsigned long NumCrss;
unsigned NumCrssRemoved = 0;
long CrsCod;
/***** Get parameter with number of months without access *****/
2017-01-29 21:41:08 +01:00
MonthsWithoutAccess = (unsigned)
Par_GetParToUnsignedLong ("Months",
Crs_MIN_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_CRSS,
Crs_MAX_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_CRSS,
UINT_MAX);
2017-01-29 12:42:19 +01:00
if (MonthsWithoutAccess == UINT_MAX)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Wrong number of months without clicks.");
SecondsWithoutAccess = (unsigned long) MonthsWithoutAccess * Dat_SECONDS_IN_ONE_MONTH;
/***** Get old courses from database *****/
2018-10-30 14:47:31 +01:00
NumCrss = DB_QuerySELECT (&mysql_res,"can not get old courses",
"SELECT CrsCod FROM crs_last WHERE"
2019-02-13 13:32:11 +01:00
" LastTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)"
2018-10-30 14:47:31 +01:00
" AND CrsCod NOT IN (SELECT DISTINCT CrsCod FROM crs_usr)",
SecondsWithoutAccess);
if (NumCrss)
2014-12-01 23:55:08 +01:00
{
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_INFO,Txt_Eliminating_X_courses_whithout_users_and_with_more_than_Y_months_without_access,
2019-02-16 00:15:59 +01:00
NumCrss,
MonthsWithoutAccess,
Cfg_PLATFORM_SHORT_NAME);
2014-12-01 23:55:08 +01:00
/***** Remove courses *****/
for (NumCrs = 0;
NumCrs < NumCrss;
NumCrs++)
{
row = mysql_fetch_row (mysql_res);
CrsCod = Str_ConvertStrCodToLongCod (row[0]);
Crs_RemoveCourseCompletely (CrsCod);
NumCrssRemoved++;
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/***** Write end message *****/
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_X_courses_have_been_eliminated,
2019-02-16 00:15:59 +01:00
NumCrssRemoved);
2014-12-01 23:55:08 +01:00
}
2019-04-07 19:49:53 +02:00
/*****************************************************************************/
/************************ Course constructor/destructor **********************/
/*****************************************************************************/
static void Crs_EditingCourseConstructor (void)
{
/***** Pointer must be NULL *****/
if (Crs_EditingCrs != NULL)
Lay_ShowErrorAndExit ("Error initializing course.");
/***** Allocate memory for course *****/
if ((Crs_EditingCrs = (struct Course *) malloc (sizeof (struct Course))) == NULL)
Lay_ShowErrorAndExit ("Error allocating memory for course.");
/***** Reset course *****/
Crs_EditingCrs->CrsCod = -1L;
Crs_EditingCrs->InstitutionalCrsCod[0] = '\0';
Crs_EditingCrs->DegCod = -1L;
Crs_EditingCrs->Year = 0;
Crs_EditingCrs->Status = 0;
Crs_EditingCrs->ShrtName[0] = '\0';
Crs_EditingCrs->FullName[0] = '\0';
}
static void Crs_EditingCourseDestructor (void)
{
/***** Free memory used for course *****/
if (Crs_EditingCrs != NULL)
{
2019-11-06 19:45:20 +01:00
free (Crs_EditingCrs);
2019-04-07 19:49:53 +02:00
Crs_EditingCrs = NULL;
}
}