swad-core/swad_course.c

3391 lines
123 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.
2017-01-13 01:51:23 +01:00
Copyright (C) 1999-2017 Antonio Ca<EFBFBD>as Vargas
2014-12-01 23:55:08 +01:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
#include <linux/limits.h> // For PATH_MAX
#include <linux/stddef.h> // For NULL
#include <limits.h> // For maximum values
#include <stdlib.h> // For getenv, etc.
#include <string.h> // For string functions
#include "swad_course.h"
#include "swad_constant.h"
#include "swad_database.h"
#include "swad_degree.h"
2017-03-30 11:20:06 +02:00
#include "swad_enrolment.h"
2014-12-01 23:55:08 +01:00
#include "swad_exam.h"
#include "swad_global.h"
2015-10-06 20:34:49 +02:00
#include "swad_help.h"
2016-11-14 16:47:46 +01:00
#include "swad_hierarchy.h"
2014-12-01 23:55:08 +01:00
#include "swad_indicator.h"
2015-01-17 20:06:25 +01:00
#include "swad_logo.h"
2014-12-01 23:55:08 +01:00
#include "swad_notification.h"
#include "swad_parameter.h"
#include "swad_QR.h"
#include "swad_RSS.h"
2015-01-04 15:48:24 +01:00
#include "swad_tab.h"
2014-12-01 23:55:08 +01:00
#include "swad_theme.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/*************************** Public constants ********************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private types *********************************/
/*****************************************************************************/
/*****************************************************************************/
/**************************** Private constants ******************************/
/*****************************************************************************/
/*****************************************************************************/
/**************************** Private prototypes *****************************/
/*****************************************************************************/
static void Crs_Configuration (bool PrintView);
2016-03-18 19:23:30 +01:00
static void Crs_PutIconToPrint (void);
2014-12-01 23:55:08 +01:00
static void Crs_WriteListMyCoursesToSelectOne (void);
static void Crs_GetListCoursesInDegree (Crs_WhatCourses_t WhatCourses);
static void Crs_ListCourses (void);
2016-11-07 00:03:50 +01:00
static bool Crs_CheckIfICanCreateCourses (void);
static void Crs_PutIconsListCourses (void);
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
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
2016-10-20 16:49:42 +02:00
static void Crs_UpdateCrsDegDB (long CrsCod,long DegCod);
2016-10-19 19:21:26 +02:00
2016-06-12 01:18:35 +02:00
static void Crs_UpdateCrsYear (struct Course *Crs,unsigned NewYear);
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
2016-10-28 10:03:37 +02:00
static void Crs_RenameCourse (struct Course *Crs,Cns_ShrtOrFullName_t ShrtOrFullName);
2017-03-09 11:16:17 +01:00
static bool Crs_CheckIfCrsNameExistsInYearOfDeg (const char *FieldName,const char *Name,long CrsCod,
long DegCod,unsigned Year);
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
2014-12-13 20:32:10 +01:00
static void Crs_PutLinkToSearchCourses (void);
2016-06-24 20:34:58 +02:00
static void Sch_PutLinkToSearchCoursesParams (void);
2014-12-01 23:55:08 +01:00
static void Crs_PutParamOtherCrsCod (long CrsCod);
2016-10-23 19:40:14 +02:00
static long Crs_GetAndCheckParamOtherCrsCod (void);
2014-12-01 23:55:08 +01:00
static void Crs_WriteRowCrsData (unsigned NumCrs,MYSQL_ROW row,bool WriteColumnAccepted);
/*****************************************************************************/
/***************** Show introduction to the current course *******************/
/*****************************************************************************/
void Crs_ShowIntroduction (void)
{
/***** Course configuration *****/
2015-10-06 23:47:34 +02:00
fprintf (Gbl.F.Out,"<div class=\"CENTER_MIDDLE\">");
2014-12-01 23:55:08 +01:00
Crs_Configuration (false);
fprintf (Gbl.F.Out,"</div>");
/***** 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
}
/*****************************************************************************/
/***************** Print configuration of the current course *****************/
/*****************************************************************************/
void Crs_PrintConfiguration (void)
{
Crs_Configuration (true);
}
/*****************************************************************************/
/***************** Configuration of the current course ***********************/
/*****************************************************************************/
static void Crs_Configuration (bool PrintView)
{
2016-11-13 16:59:04 +01:00
extern const char *Hlp_COURSE_Information;
2015-07-27 21:25:45 +02:00
extern const char *The_ClassForm[The_NUM_THEMES];
2016-10-19 01:46:40 +02:00
extern const char *Txt_Degree;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Course;
2015-02-04 20:03:23 +01:00
extern const char *Txt_Short_name;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Year_OF_A_DEGREE;
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_Not_applicable;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Institutional_code;
extern const char *Txt_Internal_code;
2015-03-07 18:09:42 +01:00
extern const char *Txt_Shortcut;
2017-01-28 15:58:46 +01:00
extern const char *Txt_STR_LANG_ID[1 + Txt_NUM_LANGUAGES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_QR_code;
extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
extern const char *Txt_Indicators;
extern const char *Txt_of_PART_OF_A_TOTAL;
2016-10-19 01:46:40 +02:00
unsigned NumDeg;
2014-12-01 23:55:08 +01:00
unsigned Year;
2016-06-10 10:22:22 +02:00
int NumIndicatorsFromDB;
struct Ind_IndicatorsCrs Indicators;
2015-04-07 21:44:24 +02:00
bool IsForm = (!PrintView && Gbl.Usrs.Me.LoggedRole >= Rol_TEACHER);
2014-12-01 23:55:08 +01:00
bool PutLink = !PrintView && Gbl.CurrentDeg.Deg.WWW[0];
2014-12-08 17:35:48 +01:00
/***** Messages and links above the frame *****/
if (!PrintView)
2014-12-01 23:55:08 +01:00
{
2017-03-30 11:20:06 +02:00
/* Link to request enrolment in the current course */
2015-04-07 21:44:24 +02:00
if (Gbl.Usrs.Me.LoggedRole == Rol__GUEST_ ||
Gbl.Usrs.Me.LoggedRole == Rol_VISITOR)
2016-03-18 19:23:30 +01:00
{
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
2015-01-16 12:11:27 +01:00
Enr_PutLinkToRequestSignUp ();
2016-03-18 19:23:30 +01:00
fprintf (Gbl.F.Out,"</div>");
}
2014-12-01 23:55:08 +01:00
}
2014-12-08 17:35:48 +01:00
/***** Start frame *****/
2016-11-13 16:59:04 +01:00
Lay_StartRoundFrame (NULL,NULL,
PrintView ? NULL :
Crs_PutIconToPrint,
PrintView ? NULL :
Hlp_COURSE_Information);
2014-12-08 17:35:48 +01:00
2014-12-01 23:55:08 +01:00
/***** Title *****/
2016-11-23 23:58:46 +01:00
fprintf (Gbl.F.Out,"<div class=\"FRAME_TITLE FRAME_TITLE_BIG\">");
2014-12-01 23:55:08 +01:00
if (PutLink)
fprintf (Gbl.F.Out,"<a href=\"%s\" target=\"_blank\""
2016-11-23 23:58:46 +01:00
" class=\"FRAME_TITLE_BIG\" title=\"%s\">",
2014-12-01 23:55:08 +01:00
Gbl.CurrentDeg.Deg.WWW,
Gbl.CurrentDeg.Deg.FullName);
2015-02-01 20:17:24 +01:00
Log_DrawLogo (Sco_SCOPE_DEG,Gbl.CurrentDeg.Deg.DegCod,
2016-10-28 10:03:37 +02:00
Gbl.CurrentDeg.Deg.ShrtName,64,NULL,true);
2014-12-01 23:55:08 +01:00
if (PutLink)
fprintf (Gbl.F.Out,"</a>");
fprintf (Gbl.F.Out,"<br />%s"
2016-03-18 19:23:30 +01:00
"</div>",
2014-12-01 23:55:08 +01:00
Gbl.CurrentCrs.Crs.FullName);
2016-03-18 19:23:30 +01:00
/***** Start table *****/
2017-05-01 10:22:16 +02:00
Lay_StartTableWide (2);
2016-03-18 19:23:30 +01:00
2016-10-19 20:43:26 +02:00
/***** Degree *****/
2016-10-19 01:46:40 +02:00
fprintf (Gbl.F.Out,"<tr>"
2016-12-21 00:45:51 +01:00
"<td class=\"RIGHT_MIDDLE\">"
"<label for=\"OthDegCod\" class=\"%s\">%s:</label>"
2016-10-19 01:46:40 +02:00
"</td>"
"<td class=\"DAT LEFT_MIDDLE\">",
The_ClassForm[Gbl.Prefs.Theme],
Txt_Degree);
2016-10-19 20:43:26 +02:00
if (!PrintView &&
2016-10-23 14:49:03 +02:00
Gbl.Usrs.Me.LoggedRole >= Rol_CTR_ADM)
// Only centre admins, institution admins and system admin can move a course to another degree
2016-10-19 01:46:40 +02:00
{
2016-10-20 00:57:00 +02:00
/* Get list of degrees of the current centre */
Deg_GetListDegsOfCurrentCtr ();
/* Put form to select degree */
2016-10-19 01:46:40 +02:00
Act_FormStart (ActChgCrsDegCfg);
2016-12-21 00:45:51 +01:00
fprintf (Gbl.F.Out,"<select id=\"OthDegCod\" name=\"OthDegCod\""
2016-10-20 16:49:42 +02:00
" class=\"INPUT_SHORT_NAME\""
2016-10-19 01:46:40 +02:00
" onchange=\"document.getElementById('%s').submit();\">",
Gbl.Form.Id);
for (NumDeg = 0;
2016-10-20 00:57:00 +02:00
NumDeg < Gbl.CurrentCtr.Ctr.Degs.Num;
2016-10-19 01:46:40 +02:00
NumDeg++)
fprintf (Gbl.F.Out,"<option value=\"%ld\"%s>%s</option>",
2016-10-20 00:57:00 +02:00
Gbl.CurrentCtr.Ctr.Degs.Lst[NumDeg].DegCod,
Gbl.CurrentCtr.Ctr.Degs.Lst[NumDeg].DegCod == Gbl.CurrentDeg.Deg.DegCod ? " selected=\"selected\"" :
"",
2016-10-28 10:03:37 +02:00
Gbl.CurrentCtr.Ctr.Degs.Lst[NumDeg].ShrtName);
2016-10-19 01:46:40 +02:00
fprintf (Gbl.F.Out,"</select>");
Act_FormEnd ();
2016-10-19 01:55:50 +02:00
2016-10-20 00:57:00 +02:00
/* Free list of degrees of the current centre */
Deg_FreeListDegs (&Gbl.CurrentCtr.Ctr.Degs);
2016-10-19 01:46:40 +02:00
}
2016-10-19 20:43:26 +02:00
else // I can not move course to another degree
2016-10-19 01:46:40 +02:00
fprintf (Gbl.F.Out,"%s",Gbl.CurrentDeg.Deg.FullName);
fprintf (Gbl.F.Out,"</td>"
"</tr>");
2014-12-01 23:55:08 +01:00
/***** Course full name *****/
fprintf (Gbl.F.Out,"<tr>"
2016-12-21 00:45:51 +01:00
"<td class=\"RIGHT_MIDDLE\">"
"<label for=\"FullName\" class=\"%s\">%s:</label>"
2016-10-23 17:20:06 +02:00
"</td>"
"<td class=\"DAT_N LEFT_MIDDLE\">",
The_ClassForm[Gbl.Prefs.Theme],
Txt_Course);
if (!PrintView &&
Gbl.Usrs.Me.LoggedRole >= Rol_DEG_ADM)
// Only degree admins, centre admins, institution admins and system admins can edit course full name
{
/* Form to change course full name */
Act_FormStart (ActRenCrsFulCfg);
2016-12-21 00:45:51 +01:00
fprintf (Gbl.F.Out,"<input type=\"text\""
" id=\"FullName\" name=\"FullName\""
2016-10-23 17:20:06 +02:00
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_FULL_NAME\""
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-08 14:12:33 +01:00
Hie_MAX_CHARS_FULL_NAME,
2016-10-23 17:20:06 +02:00
Gbl.CurrentCrs.Crs.FullName,
Gbl.Form.Id);
Act_FormEnd ();
}
else // I can not edit course full name
fprintf (Gbl.F.Out,"%s",Gbl.CurrentCrs.Crs.FullName);
fprintf (Gbl.F.Out,"</td>"
"</tr>");
2014-12-01 23:55:08 +01:00
/***** Course short name *****/
fprintf (Gbl.F.Out,"<tr>"
2016-12-21 00:45:51 +01:00
"<td class=\"RIGHT_MIDDLE\">"
"<label for=\"ShortName\" class=\"%s\">%s:</label>"
2016-10-23 18:23:37 +02:00
"</td>"
"<td class=\"DAT_N LEFT_MIDDLE\">",
The_ClassForm[Gbl.Prefs.Theme],
Txt_Short_name);
if (!PrintView &&
Gbl.Usrs.Me.LoggedRole >= Rol_DEG_ADM)
// Only degree admins, centre admins, institution admins and system admins can edit course short name
{
/* Form to change course short name */
Act_FormStart (ActRenCrsShoCfg);
2016-12-21 00:45:51 +01:00
fprintf (Gbl.F.Out,"<input type=\"text\""
" id=\"ShortName\" name=\"ShortName\""
2016-10-23 18:23:37 +02:00
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_SHORT_NAME\""
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-08 14:12:33 +01:00
Hie_MAX_CHARS_SHRT_NAME,
2016-10-28 10:03:37 +02:00
Gbl.CurrentCrs.Crs.ShrtName,
2016-10-23 18:23:37 +02:00
Gbl.Form.Id);
Act_FormEnd ();
}
else // I can not edit course short name
2016-10-28 10:03:37 +02:00
fprintf (Gbl.F.Out,"%s",Gbl.CurrentCrs.Crs.ShrtName);
2016-10-23 18:23:37 +02:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
2014-12-01 23:55:08 +01:00
/***** Course year *****/
fprintf (Gbl.F.Out,"<tr>"
2016-12-21 00:45:51 +01:00
"<td class=\"RIGHT_MIDDLE\">"
"<label for=\"OthCrsYear\" class=\"%s\">%s:</label>"
2014-12-22 19:59:27 +01:00
"</td>"
2015-07-28 11:27:16 +02:00
"<td class=\"DAT LEFT_MIDDLE\">",
2015-12-24 18:21:39 +01:00
The_ClassForm[Gbl.Prefs.Theme],
2014-12-01 23:55:08 +01:00
Txt_Year_OF_A_DEGREE);
if (IsForm)
{
2016-06-12 01:18:35 +02:00
Act_FormStart (ActChgCrsYeaCfg);
2016-12-21 00:45:51 +01:00
fprintf (Gbl.F.Out,"<select id=\"OthCrsYear\" name=\"OthCrsYear\""
2016-06-12 01:18:35 +02:00
" onchange=\"document.getElementById('%s').submit();\">",
Gbl.Form.Id);
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++)
2016-02-29 18:53:26 +01:00
fprintf (Gbl.F.Out,"<option value=\"%u\"%s>%s</option>",
Year,
Year == Gbl.CurrentCrs.Crs.Year ? " selected=\"selected\"" :
"",
Txt_YEAR_OF_DEGREE[Year]);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</select>");
2016-06-12 01:18:35 +02:00
Act_FormEnd ();
2014-12-01 23:55:08 +01:00
}
else
2015-12-06 14:18:07 +01:00
fprintf (Gbl.F.Out,"%s",
Gbl.CurrentCrs.Crs.Year ? Txt_YEAR_OF_DEGREE[Gbl.CurrentCrs.Crs.Year] :
Txt_Not_applicable);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
if (!PrintView)
{
/***** Institutional code of the course *****/
fprintf (Gbl.F.Out,"<tr>"
2016-12-21 00:45:51 +01:00
"<td class=\"RIGHT_MIDDLE\">"
"<label for=\"InsCrsCod\" class=\"%s\">%s:</label>"
2014-12-22 19:59:27 +01:00
"</td>"
2015-07-28 11:27:16 +02:00
"<td class=\"DAT LEFT_MIDDLE\">",
2015-07-27 21:25:45 +02:00
The_ClassForm[Gbl.Prefs.Theme],
2014-12-01 23:55:08 +01:00
Txt_Institutional_code);
if (IsForm)
2016-06-12 01:18:35 +02:00
{
Act_FormStart (ActChgInsCrsCodCfg);
2016-12-21 00:45:51 +01:00
fprintf (Gbl.F.Out,"<input type=\"text\""
" id=\"InsCrsCod\" name=\"InsCrsCod\""
2016-06-12 01:18:35 +02:00
" size=\"%u\" maxlength=\"%u\" value=\"%s\""
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-07 11:03:05 +01:00
Crs_MAX_CHARS_INSTITUTIONAL_CRS_COD,
Crs_MAX_CHARS_INSTITUTIONAL_CRS_COD,
2016-06-12 01:18:35 +02:00
Gbl.CurrentCrs.Crs.InstitutionalCrsCod,
Gbl.Form.Id);
Act_FormEnd ();
}
2014-12-01 23:55:08 +01:00
else
fprintf (Gbl.F.Out,"%s",Gbl.CurrentCrs.Crs.InstitutionalCrsCod);
fprintf (Gbl.F.Out,"</td>"
"</tr>");
/***** Internal code of the course *****/
fprintf (Gbl.F.Out,"<tr>"
2015-07-27 21:25:45 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"%s:"
"</td>"
2015-07-28 11:27:16 +02:00
"<td class=\"DAT LEFT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"%ld"
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>",
2015-07-27 21:25:45 +02:00
The_ClassForm[Gbl.Prefs.Theme],
2015-07-25 20:07:38 +02:00
Txt_Internal_code,
2014-12-01 23:55:08 +01:00
Gbl.CurrentCrs.Crs.CrsCod);
}
/***** Link to the course *****/
fprintf (Gbl.F.Out,"<tr>"
2015-07-27 21:25:45 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"%s:"
"</td>"
2015-07-28 11:27:16 +02:00
"<td class=\"DAT LEFT_MIDDLE\">"
2015-03-07 21:08:44 +01:00
"<a href=\"%s/%s?crs=%ld\" class=\"DAT\" target=\"_blank\">"
"%s/%s?crs=%ld</a>"
2014-12-01 23:55:08 +01:00
"</td>"
"</tr>",
2015-07-27 21:25:45 +02:00
The_ClassForm[Gbl.Prefs.Theme],
2015-03-07 18:09:42 +01:00
Txt_Shortcut,
2016-07-08 12:43:48 +02:00
Cfg_URL_SWAD_CGI,
2015-12-07 23:13:08 +01:00
Txt_STR_LANG_ID[Gbl.Prefs.Language],
2015-11-21 20:23:28 +01:00
Gbl.CurrentCrs.Crs.CrsCod,
2016-07-08 12:43:48 +02:00
Cfg_URL_SWAD_CGI,
2015-12-07 23:13:08 +01:00
Txt_STR_LANG_ID[Gbl.Prefs.Language],
2015-11-21 20:23:28 +01:00
Gbl.CurrentCrs.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
if (PrintView)
{
/***** QR code with link to the course *****/
fprintf (Gbl.F.Out,"<tr>"
2015-07-27 21:25:45 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"%s:"
"</td>"
2015-07-28 11:27:16 +02:00
"<td class=\"DAT LEFT_MIDDLE\">",
2015-07-27 21:25:45 +02:00
The_ClassForm[Gbl.Prefs.Theme],
2014-12-01 23:55:08 +01:00
Txt_QR_code);
2015-09-28 18:28:29 +02:00
QR_LinkTo (250,"crs",Gbl.CurrentCrs.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
}
else
{
/***** Number of teachers *****/
fprintf (Gbl.F.Out,"<tr>"
2015-07-27 21:25:45 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"%s:"
"</td>"
2015-07-28 11:27:16 +02:00
"<td class=\"DAT LEFT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"%u"
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>",
2015-07-27 21:25:45 +02:00
The_ClassForm[Gbl.Prefs.Theme],
2015-04-07 21:44:24 +02:00
Txt_ROLES_PLURAL_Abc[Rol_TEACHER][Usr_SEX_UNKNOWN],Gbl.CurrentCrs.Crs.NumTchs);
2014-12-01 23:55:08 +01:00
/***** Number of students *****/
fprintf (Gbl.F.Out,"<tr>"
2015-07-27 21:25:45 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"%s:"
"</td>"
2015-07-28 11:27:16 +02:00
"<td class=\"DAT LEFT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"%u"
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>",
2015-07-27 21:25:45 +02:00
The_ClassForm[Gbl.Prefs.Theme],
2015-04-07 21:44:24 +02:00
Txt_ROLES_PLURAL_Abc[Rol_STUDENT][Usr_SEX_UNKNOWN],Gbl.CurrentCrs.Crs.NumStds);
2014-12-01 23:55:08 +01:00
/***** Indicators *****/
2016-06-10 10:22:22 +02:00
NumIndicatorsFromDB = Ind_GetNumIndicatorsCrsFromDB (Gbl.CurrentCrs.Crs.CrsCod);
Ind_ComputeAndStoreIndicatorsCrs (Gbl.CurrentCrs.Crs.CrsCod,
NumIndicatorsFromDB,&Indicators);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<tr>"
2015-07-27 21:25:45 +02:00
"<td class=\"%s RIGHT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"%s:"
"</td>"
2016-06-12 01:18:35 +02:00
"<td class=\"LEFT_MIDDLE\">",
2015-07-27 21:25:45 +02:00
The_ClassForm[Gbl.Prefs.Theme],
2016-06-12 01:18:35 +02:00
Txt_Indicators);
Act_FormStart (ActReqStaCrs);
sprintf (Gbl.Title,"%u %s %u",
Indicators.NumIndicators,Txt_of_PART_OF_A_TOTAL,Ind_NUM_INDICATORS);
2016-07-01 17:13:41 +02:00
Act_LinkFormSubmit (Gbl.Title,"DAT",NULL);
2016-06-12 01:18:35 +02:00
fprintf (Gbl.F.Out,"%s "
2017-05-02 16:57:49 +02:00
"<img src=\"%s/%s\" alt=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />",
2016-06-12 01:18:35 +02:00
Gbl.Title,
2014-12-01 23:55:08 +01:00
Gbl.Prefs.IconsURL,
2017-05-02 16:57:49 +02:00
(Indicators.NumIndicators == Ind_NUM_INDICATORS) ? "ok_green16x16.gif" :
"warning64x64.png",
2016-06-12 01:18:35 +02:00
Gbl.Title);
Act_FormEnd ();
fprintf (Gbl.F.Out,"</td>"
"</tr>");
2014-12-08 17:35:48 +01:00
}
2014-12-01 23:55:08 +01:00
2016-03-18 19:23:30 +01:00
/***** End table *****/
2017-05-01 10:22:16 +02:00
Lay_EndTable ();
2014-12-01 23:55:08 +01:00
2016-03-18 19:23:30 +01:00
/***** End frame *****/
Lay_EndRoundFrame ();
}
/*****************************************************************************/
/************* Put icon to print the configuration of a course ***************/
/*****************************************************************************/
static void Crs_PutIconToPrint (void)
{
2017-04-30 23:48:48 +02:00
Lay_PutContextualIconToPrint (ActPrnCrsInf,NULL);
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-04-23 23:39:07 +02:00
extern struct Act_Actions Act_Actions[Act_NUM_ACTIONS];
2016-11-13 13:23:09 +01:00
extern const char *Hlp_PROFILE_Courses;
2015-07-27 21:25:45 +02:00
extern const char *The_ClassForm[The_NUM_THEMES];
2015-12-25 22:05:28 +01:00
extern const char *The_ClassFormDark[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-01 23:55:08 +01:00
extern const char *Txt_Go_to_X;
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-03-07 01:56:41 +01:00
char ActTxt[Act_MAX_BYTES_ACTION_TXT + 1];
2017-01-13 01:51:23 +01:00
const char *ClassNormal;
2015-12-25 21:19:31 +01:00
char ClassHighlight[64];
2017-01-13 01:51:23 +01:00
ClassNormal = The_ClassForm[Gbl.Prefs.Theme];
2015-12-25 22:05:28 +01:00
sprintf (ClassHighlight,"%s LIGHT_BLUE",The_ClassFormDark[Gbl.Prefs.Theme]);
2014-12-29 00:54:56 +01:00
/***** Table start *****/
2016-11-13 13:23:09 +01:00
Lay_StartRoundFrame (NULL,Txt_My_courses,NULL,Hlp_PROFILE_Courses);
2016-12-19 00:55:24 +01:00
fprintf (Gbl.F.Out,"<ul class=\"LIST_LEFT\">");
2014-12-29 20:22:46 +01:00
/***** Write link to platform *****/
2015-12-25 21:19:31 +01:00
Highlight = (Gbl.CurrentCty.Cty.CtyCod <= 0);
fprintf (Gbl.F.Out,"<li class=\"%s\" style=\"height:25px;\">",
Highlight ? ClassHighlight :
ClassNormal);
2015-12-25 22:05:28 +01:00
Act_FormStart (ActMyCrs);
Cty_PutParamCtyCod (-1L);
2015-02-05 00:55:47 +01:00
Act_LinkFormSubmit (Txt_System,
2015-12-25 21:19:31 +01:00
Highlight ? ClassHighlight :
2016-07-01 17:13:41 +02:00
ClassNormal,NULL);
2015-12-15 01:33:09 +01:00
fprintf (Gbl.F.Out,"<img src=\"%s/sys64x64.gif\""
2015-07-21 17:37:37 +02:00
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />&nbsp;%s</a>",
2014-12-29 00:54:56 +01:00
Gbl.Prefs.IconsURL,
2015-02-05 00:55:47 +01:00
Txt_System,
2015-12-25 21:19:31 +01:00
Txt_System,
2015-02-05 00:55:47 +01:00
Txt_System);
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
fprintf (Gbl.F.Out,"</li>");
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]);
2015-12-09 19:51:17 +01:00
if (!Cty_GetDataOfCountryByCod (&Cty,Cty_GET_BASIC_DATA))
2014-12-29 00:54:56 +01:00
Lay_ShowErrorAndExit ("Country not found.");
/***** Write link to country *****/
2015-12-25 21:19:31 +01:00
Highlight = (Gbl.CurrentIns.Ins.InsCod <= 0 &&
Gbl.CurrentCty.Cty.CtyCod == Cty.CtyCod);
fprintf (Gbl.F.Out,"<li class=\"%s\" style=\"height:25px;\">",
Highlight ? ClassHighlight :
ClassNormal);
2014-12-29 13:26:39 +01:00
IsLastItemInLevel[1] = (NumCty == NumCtys - 1);
Lay_IndentDependingOnLevel (1,IsLastItemInLevel);
2015-12-25 22:05:28 +01:00
Act_FormStart (ActMyCrs);
2014-12-29 00:54:56 +01:00
Cty_PutParamCtyCod (Cty.CtyCod);
Act_LinkFormSubmit (Act_GetActionTextFromDB (Act_Actions[ActSeeCtyInf].ActCod,ActTxt),
2015-12-25 21:19:31 +01:00
Highlight ? ClassHighlight :
2016-07-01 17:13:41 +02:00
ClassNormal,NULL);
2014-12-29 00:54:56 +01:00
/* Country map */
2015-07-21 17:37:37 +02:00
fprintf (Gbl.F.Out,"<img src=\"%s/%s/%s/%s.png\""
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />&nbsp;%s</a>",
2014-12-29 00:54:56 +01:00
Gbl.Prefs.IconsURL,Cfg_ICON_FOLDER_COUNTRIES,
Cty.Alpha2,
Cty.Alpha2,
Cty.Alpha2,
2015-12-25 21:19:31 +01:00
Cty.Name[Gbl.Prefs.Language],
Cty.Name[Gbl.Prefs.Language]);
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
fprintf (Gbl.F.Out,"</li>");
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]);
2015-12-09 19:51:17 +01:00
if (!Ins_GetDataOfInstitutionByCod (&Ins,Ins_GET_BASIC_DATA))
2014-12-29 00:54:56 +01:00
Lay_ShowErrorAndExit ("Institution not found.");
/***** Write link to institution *****/
2015-12-25 21:19:31 +01:00
Highlight = (Gbl.CurrentCtr.Ctr.CtrCod <= 0 &&
Gbl.CurrentIns.Ins.InsCod == Ins.InsCod);
2017-03-04 19:46:46 +01:00
fprintf (Gbl.F.Out,"<li class=\"MY_CRSS_LNK %s\" style=\"height:25px;\">",
2015-12-25 21:19:31 +01:00
Highlight ? ClassHighlight :
ClassNormal);
2014-12-29 13:26:39 +01:00
IsLastItemInLevel[2] = (NumIns == NumInss - 1);
Lay_IndentDependingOnLevel (2,IsLastItemInLevel);
2015-12-25 22:05:28 +01:00
Act_FormStart (ActMyCrs);
2014-12-29 00:54:56 +01:00
Ins_PutParamInsCod (Ins.InsCod);
Act_LinkFormSubmit (Act_GetActionTextFromDB (Act_Actions[ActSeeInsInf].ActCod,ActTxt),
2015-12-25 21:19:31 +01:00
Highlight ? ClassHighlight :
2016-07-01 17:13:41 +02:00
ClassNormal,NULL);
2016-10-28 10:03:37 +02:00
Log_DrawLogo (Sco_SCOPE_INS,Ins.InsCod,Ins.ShrtName,20,NULL,true);
2017-03-04 19:46:46 +01:00
fprintf (Gbl.F.Out,"&nbsp;%s</a>",Ins.FullName);
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
fprintf (Gbl.F.Out,"</li>");
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]);
if (!Ctr_GetDataOfCentreByCod (&Ctr))
Lay_ShowErrorAndExit ("Centre not found.");
/***** Write link to centre *****/
2015-12-25 21:19:31 +01:00
Highlight = (Gbl.CurrentDeg.Deg.DegCod <= 0 &&
Gbl.CurrentCtr.Ctr.CtrCod == Ctr.CtrCod);
2017-03-04 19:46:46 +01:00
fprintf (Gbl.F.Out,"<li class=\"MY_CRSS_LNK %s\" style=\"height:25px;\">",
2015-12-25 21:19:31 +01:00
Highlight ? ClassHighlight :
ClassNormal);
2014-12-29 13:26:39 +01:00
IsLastItemInLevel[3] = (NumCtr == NumCtrs - 1);
Lay_IndentDependingOnLevel (3,IsLastItemInLevel);
2015-12-25 22:05:28 +01:00
Act_FormStart (ActMyCrs);
2014-12-29 00:54:56 +01:00
Ctr_PutParamCtrCod (Ctr.CtrCod);
Act_LinkFormSubmit (Act_GetActionTextFromDB (Act_Actions[ActSeeCtrInf].ActCod,ActTxt),
2015-12-25 21:19:31 +01:00
Highlight ? ClassHighlight :
2016-07-01 17:13:41 +02:00
ClassNormal,NULL);
2016-10-28 10:03:37 +02:00
Log_DrawLogo (Sco_SCOPE_CTR,Ctr.CtrCod,Ctr.ShrtName,20,NULL,true);
2017-03-04 19:46:46 +01:00
fprintf (Gbl.F.Out,"&nbsp;%s</a>",Ctr.FullName);
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
fprintf (Gbl.F.Out,"</li>");
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]);
if (!Deg_GetDataOfDegreeByCod (&Deg))
Lay_ShowErrorAndExit ("Degree not found.");
/***** Write link to degree *****/
2015-12-25 21:19:31 +01:00
Highlight = (Gbl.CurrentCrs.Crs.CrsCod <= 0 &&
Gbl.CurrentDeg.Deg.DegCod == Deg.DegCod);
2017-03-04 19:46:46 +01:00
fprintf (Gbl.F.Out,"<li class=\"MY_CRSS_LNK %s\" style=\"height:25px;\">",
2015-12-25 21:19:31 +01:00
Highlight ? ClassHighlight :
ClassNormal);
2014-12-29 13:26:39 +01:00
IsLastItemInLevel[4] = (NumDeg == NumDegs - 1);
Lay_IndentDependingOnLevel (4,IsLastItemInLevel);
2015-12-25 22:05:28 +01:00
Act_FormStart (ActMyCrs);
2014-12-29 00:54:56 +01:00
Deg_PutParamDegCod (Deg.DegCod);
Act_LinkFormSubmit (Act_GetActionTextFromDB (Act_Actions[ActSeeDegInf].ActCod,ActTxt),
2015-12-25 21:19:31 +01:00
Highlight ? ClassHighlight :
2016-07-01 17:13:41 +02:00
ClassNormal,NULL);
2016-10-28 10:03:37 +02:00
Log_DrawLogo (Sco_SCOPE_DEG,Deg.DegCod,Deg.ShrtName,20,NULL,true);
2017-03-04 19:46:46 +01:00
fprintf (Gbl.F.Out,"&nbsp;%s</a>",Deg.FullName);
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
fprintf (Gbl.F.Out,"</li>");
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]);
if (!Crs_GetDataOfCourseByCod (&Crs))
Lay_ShowErrorAndExit ("Course not found.");
/***** Write link to course *****/
2015-12-25 21:19:31 +01:00
Highlight = (Gbl.CurrentCrs.Crs.CrsCod == Crs.CrsCod);
2017-03-04 19:46:46 +01:00
fprintf (Gbl.F.Out,"<li class=\"MY_CRSS_LNK %s\" style=\"height:25px;\">",
2015-12-25 21:19:31 +01:00
Highlight ? ClassHighlight :
ClassNormal);
2014-12-29 13:26:39 +01:00
IsLastItemInLevel[5] = (NumCrs == NumCrss - 1);
Lay_IndentDependingOnLevel (5,IsLastItemInLevel);
2015-12-25 22:05:28 +01:00
Act_FormStart (ActMyCrs);
2014-12-29 00:54:56 +01:00
Crs_PutParamCrsCod (Crs.CrsCod);
2016-10-28 10:03:37 +02:00
sprintf (Gbl.Title,Txt_Go_to_X,Crs.ShrtName);
2015-12-25 21:19:31 +01:00
Act_LinkFormSubmit (Gbl.Title,
Highlight ? ClassHighlight :
2016-07-01 17:13:41 +02:00
ClassNormal,NULL);
2015-12-05 12:31:24 +01:00
fprintf (Gbl.F.Out,"<img src=\"%s/dot64x64.png\""
2015-07-21 17:37:37 +02:00
" alt=\"%s\" title=\"%s\""
2017-03-04 19:46:46 +01:00
" class=\"ICO20x20\" />"
"&nbsp;%s"
"</a>",
2015-07-21 17:37:37 +02:00
Gbl.Prefs.IconsURL,
2016-10-28 10:03:37 +02:00
Crs.ShrtName,
2017-03-04 19:46:46 +01:00
Crs.FullName,
2015-07-21 17:37:37 +02:00
Crs.FullName);
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
2014-12-29 20:22:46 +01:00
fprintf (Gbl.F.Out,"</li>");
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);
/***** End frame *****/
2016-12-19 00:55:24 +01:00
fprintf (Gbl.F.Out,"</ul>");
2015-04-12 18:01:06 +02:00
Lay_EndRoundFrame ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********************** Get total number of courses *************************/
/*****************************************************************************/
unsigned Crs_GetNumCrssTotal (void)
{
char Query[256];
/***** Get total number of courses from database *****/
sprintf (Query,"SELECT COUNT(*) FROM courses");
return (unsigned) DB_QueryCOUNT (Query,"can not get the total number of courses");
}
/*****************************************************************************/
/****************** Get number of courses in a country ***********************/
/*****************************************************************************/
unsigned Crs_GetNumCrssInCty (long CtyCod)
{
2015-12-09 22:05:21 +01:00
char Query[256];
2014-12-01 23:55:08 +01:00
/***** Get number of courses in a country from database *****/
sprintf (Query,"SELECT COUNT(*) FROM institutions,centres,degrees,courses"
2017-03-24 01:09:27 +01:00
" WHERE institutions.CtyCod=%ld"
2014-12-01 23:55:08 +01:00
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod",
CtyCod);
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of courses in a country");
}
/*****************************************************************************/
/**************** Get number of courses in an institution ********************/
/*****************************************************************************/
unsigned Crs_GetNumCrssInIns (long InsCod)
{
2015-12-09 22:05:21 +01:00
char Query[256];
2014-12-01 23:55:08 +01:00
/***** Get number of courses in a degree from database *****/
sprintf (Query,"SELECT COUNT(*) FROM centres,degrees,courses"
2017-03-24 01:09:27 +01:00
" WHERE centres.InsCod=%ld"
2014-12-01 23:55:08 +01:00
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod",
InsCod);
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of courses in an institution");
}
/*****************************************************************************/
/******************** Get number of courses in a centre **********************/
/*****************************************************************************/
unsigned Crs_GetNumCrssInCtr (long CtrCod)
{
2015-12-09 22:05:21 +01:00
char Query[256];
2014-12-01 23:55:08 +01:00
/***** Get number of courses in a degree from database *****/
sprintf (Query,"SELECT COUNT(*) FROM degrees,courses"
2017-03-24 01:09:27 +01:00
" WHERE degrees.CtrCod=%ld"
2015-12-09 22:05:21 +01:00
" AND degrees.DegCod=courses.DegCod",
2014-12-01 23:55:08 +01:00
CtrCod);
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of courses in a centre");
}
/*****************************************************************************/
/******************** Get number of courses in a degree **********************/
/*****************************************************************************/
unsigned Crs_GetNumCrssInDeg (long DegCod)
{
2015-12-09 22:05:21 +01:00
char Query[128];
2014-12-01 23:55:08 +01:00
/***** Get number of courses in a degree from database *****/
sprintf (Query,"SELECT COUNT(*) FROM courses"
2017-03-24 01:09:27 +01:00
" WHERE DegCod=%ld",
2014-12-01 23:55:08 +01:00
DegCod);
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of courses in a degree");
}
/*****************************************************************************/
/********************* Get number of courses with users **********************/
/*****************************************************************************/
unsigned Crs_GetNumCrssWithUsrs (Rol_Role_t Role,const char *SubQuery)
{
char Query[512];
/***** Get number of degrees with users from database *****/
sprintf (Query,"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"
2017-03-24 01:09:27 +01:00
" AND crs_usr.Role=%u",
2014-12-01 23:55:08 +01:00
SubQuery,(unsigned) Role);
return (unsigned) DB_QueryCOUNT (Query,"can not get number of courses with users");
}
2015-07-25 20:20:07 +02:00
/*****************************************************************************/
/*************************** Write selector of course ************************/
/*****************************************************************************/
void Crs_WriteSelectorOfCourse (void)
{
extern const char *Txt_Course;
char Query[512];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCrss;
unsigned NumCrs;
long CrsCod;
/***** Start form *****/
Act_FormGoToStart (ActSeeCrsInf);
2016-12-20 10:03:00 +01:00
fprintf (Gbl.F.Out,"<select id=\"crs\" name=\"crs\" style=\"width:175px;\"");
2015-07-25 20:20:07 +02:00
if (Gbl.CurrentDeg.Deg.DegCod > 0)
2015-10-22 14:49:48 +02:00
fprintf (Gbl.F.Out," onchange=\"document.getElementById('%s').submit();\"",
2016-01-14 10:31:09 +01:00
Gbl.Form.Id);
2015-07-25 20:20:07 +02:00
else
fprintf (Gbl.F.Out," disabled=\"disabled\"");
fprintf (Gbl.F.Out,"><option value=\"\"");
if (Gbl.CurrentCrs.Crs.CrsCod < 0)
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out," disabled=\"disabled\">[%s]</option>",
Txt_Course);
if (Gbl.CurrentDeg.Deg.DegCod > 0)
{
/***** Get courses belonging to the current degree from database *****/
sprintf (Query,"SELECT CrsCod,ShortName FROM courses"
2017-03-24 01:09:27 +01:00
" WHERE DegCod=%ld"
2015-07-25 20:20:07 +02:00
" ORDER BY ShortName",
Gbl.CurrentDeg.Deg.DegCod);
NumCrss = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get courses of a degree");
/***** 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 */
fprintf (Gbl.F.Out,"<option value=\"%ld\"",CrsCod);
if (Gbl.CurrentCrs.Crs.CrsCod > 0 &&
(CrsCod == Gbl.CurrentCrs.Crs.CrsCod))
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%s</option>",row[1]);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/***** End form *****/
fprintf (Gbl.F.Out,"</select>");
Act_FormEnd ();
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************** Show courses of a degree *************************/
/*****************************************************************************/
void Crs_ShowCrssOfCurrentDeg (void)
{
if (Gbl.CurrentDeg.Deg.DegCod > 0)
{
/***** Get list of courses in this degree *****/
Crs_GetListCoursesInDegree (Crs_ALL_COURSES_EXCEPT_REMOVED);
/***** Write menu to select country, institution, centre and degree *****/
2016-11-14 17:26:32 +01:00
Hie_WriteMenuHierarchy ();
2014-12-01 23:55:08 +01:00
/***** Show list of courses *****/
Crs_ListCourses ();
/***** Free list of courses in this degree *****/
Crs_FreeListCoursesInDegree (&Gbl.CurrentDeg.Deg);
}
}
/*****************************************************************************/
2016-04-16 15:05:18 +02:00
/*************** Create a list with courses in current degree ****************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
static void Crs_GetListCoursesInDegree (Crs_WhatCourses_t WhatCourses)
{
char Query[512];
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:
2016-03-03 01:10:54 +01:00
sprintf (Query,"SELECT CrsCod,DegCod,Year,InsCrsCod,Status,RequesterUsrCod,ShortName,FullName"
2017-03-24 01:09:27 +01:00
" FROM courses WHERE DegCod=%ld AND Status=0"
2014-12-01 23:55:08 +01:00
" ORDER BY Year,ShortName",
Gbl.CurrentDeg.Deg.DegCod);
break;
case Crs_ALL_COURSES_EXCEPT_REMOVED:
2016-03-03 01:10:54 +01:00
sprintf (Query,"SELECT CrsCod,DegCod,Year,InsCrsCod,Status,RequesterUsrCod,ShortName,FullName"
2017-03-24 01:09:27 +01:00
" FROM courses WHERE DegCod=%ld AND (Status & %u)=0"
2014-12-01 23:55:08 +01:00
" ORDER BY Year,ShortName",
Gbl.CurrentDeg.Deg.DegCod,
(unsigned) Crs_STATUS_BIT_REMOVED);
break;
default:
break;
}
2016-04-16 15:05:18 +02:00
NumCrss = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get the courses of a degree");
2014-12-01 23:55:08 +01:00
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 *****/
2016-04-16 15:05:18 +02:00
if ((Gbl.CurrentDeg.Deg.LstCrss = (struct Course *) calloc ((size_t) NumCrss,sizeof (struct Course))) == NULL)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Not enough memory to store the courses of a degree.");
/***** 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++)
{
Crs = &(Gbl.CurrentDeg.Deg.LstCrss[NumCrs]);
/* Get next course */
row = mysql_fetch_row (mysql_res);
Crs_GetDataOfCourseFromRow (Crs,row);
}
}
2016-04-16 15:05:18 +02:00
Gbl.CurrentDeg.NumCrss = 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 *******************/
/*****************************************************************************/
void Crs_FreeListCoursesInDegree (struct Degree *Deg)
{
if (Deg->LstCrss)
{
/***** Free memory used by the list of courses in degree *****/
free ((void *) Deg->LstCrss);
Deg->LstCrss = NULL;
}
}
/*****************************************************************************/
/********************** Write selector of my coursess ************************/
/*****************************************************************************/
void Crs_WriteSelectorMyCourses (void)
{
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 ();
/***** Start form *****/
2016-10-28 10:03:37 +02:00
Act_FormGoToStart (Gbl.Usrs.Me.MyCrss.Num ? ActSeeCrsInf :
2016-11-20 18:43:38 +01:00
ActSysReqSch);
2014-12-01 23:55:08 +01:00
/***** Start of selector of courses *****/
2016-12-27 16:45:37 +01:00
fprintf (Gbl.F.Out,"<select id=\"my_courses\" name=\"crs\""
2015-10-22 14:49:48 +02:00
" onchange=\"document.getElementById('%s').submit();\">",
2016-01-14 10:31:09 +01:00
Gbl.Form.Id);
2014-12-01 23:55:08 +01:00
2015-12-28 01:39:58 +01:00
/***** Write an option when no course selected *****/
2016-11-20 18:43:38 +01:00
if (Gbl.CurrentCrs.Crs.CrsCod <= 0) // No course selected
fprintf (Gbl.F.Out,"<option value=\"-1\""
" disabled=\"disabled\" selected=\"selected\">"
"%s"
"</option>",
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)
fprintf (Gbl.F.Out,"</optgroup>");
fprintf (Gbl.F.Out,"<optgroup label=\"%s\">",DegShortName);
2014-12-01 23:55:08 +01:00
LastDegCod = DegCod;
}
fprintf (Gbl.F.Out,"<option value=\"%ld\"",
2016-10-28 10:03:37 +02:00
Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].CrsCod);
2016-11-20 18:43:38 +01:00
if (CrsCod == Gbl.CurrentCrs.Crs.CrsCod) // Course selected
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%s</option>",CrsShortName);
}
2016-11-20 18:43:38 +01:00
if (LastDegCod > 0)
fprintf (Gbl.F.Out,"</optgroup>");
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 *****/
if (Gbl.CurrentCrs.Crs.CrsCod > 0 && // Course selected
!Gbl.Usrs.Me.IBelongToCurrentCrs) // I do not belong to it
fprintf (Gbl.F.Out,"<option value=\"%ld\""
" disabled=\"disabled\" selected=\"selected\">"
"%s"
"</option>",
Gbl.CurrentCrs.Crs.CrsCod,
Gbl.CurrentCrs.Crs.ShrtName);
2014-12-01 23:55:08 +01:00
/***** End form *****/
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</select>");
Act_FormEnd ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************* List 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
2016-03-20 12:35:27 +01:00
/***** Start frame *****/
2016-10-28 10:03:37 +02:00
sprintf (Gbl.Title,Txt_Courses_of_DEGREE_X,Gbl.CurrentDeg.Deg.ShrtName);
2016-11-13 15:06:49 +01:00
Lay_StartRoundFrame (NULL,Gbl.Title,
Crs_PutIconsListCourses,Hlp_DEGREE_Courses);
2016-03-20 12:35:27 +01:00
2016-04-16 15:05:18 +02:00
if (Gbl.CurrentDeg.NumCrss) // There are courses in the current degree
2016-03-20 12:35:27 +01:00
{
/***** Start table *****/
2017-05-01 12:36:24 +02:00
Lay_StartTableWideMargin (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 *****/
2017-05-01 12:36:24 +02:00
Lay_EndTable ();
2016-03-20 12:35:27 +01:00
}
else // No courses created in the current degree
2017-05-11 23:45:46 +02: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
{
Act_FormStart (ActEdiCrs);
2016-04-16 15:05:18 +02:00
Lay_PutConfirmButton (Gbl.CurrentDeg.NumCrss ? Txt_Create_another_course :
Txt_Create_course);
2016-03-16 13:23:10 +01:00
Act_FormEnd ();
2015-10-06 01:19:21 +02:00
}
2014-12-01 23:55:08 +01:00
2016-03-20 12:35:27 +01:00
/***** End frame *****/
2016-03-16 13:23:10 +01:00
Lay_EndRoundFrame ();
}
2016-11-07 00:03:50 +01:00
/*****************************************************************************/
/********************** Check if I can create courses ************************/
/*****************************************************************************/
static bool Crs_CheckIfICanCreateCourses (void)
{
return (bool) (Gbl.Usrs.Me.LoggedRole >= Rol__GUEST_);
}
/*****************************************************************************/
/***************** Put contextual icons in list of courses *******************/
/*****************************************************************************/
static void Crs_PutIconsListCourses (void)
{
/***** Put icon to edit courses *****/
if (Crs_CheckIfICanCreateCourses ())
Crs_PutIconToEditCourses ();
/***** Put icon to show a figure *****/
Gbl.Stat.FigureType = Sta_HIERARCHY;
Sta_PutIconToShowFigure ();
}
2016-03-16 13:23:10 +01:00
/*****************************************************************************/
/********************** Put link (form) to edit courses **********************/
/*****************************************************************************/
2016-03-16 22:40:35 +01:00
static void Crs_PutIconToEditCourses (void)
2016-03-16 13:23:10 +01:00
{
2017-04-30 23:48:48 +02:00
Lay_PutContextualIconToEdit (ActEdiCrs,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_Go_to_X;
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;
/***** Write all the courses of this year *****/
for (NumCrs = 0;
2016-04-16 15:05:18 +02:00
NumCrs < Gbl.CurrentDeg.NumCrss;
2015-12-06 14:18:07 +01:00
NumCrs++)
{
Crs = &(Gbl.CurrentDeg.Deg.LstCrss[NumCrs]);
if (Crs->Year == Year) // The year of the course is this?
{
ThisYearHasCourses = true;
if (Crs->Status & Crs_STATUS_BIT_PENDING)
{
TxtClassNormal = "DAT_LIGHT";
TxtClassStrong = "DAT_LIGHT";
}
else
{
TxtClassNormal = "DAT";
TxtClassStrong = "DAT_N";
}
BgColor = (Crs->CrsCod == Gbl.CurrentCrs.Crs.CrsCod) ? "LIGHT_BLUE" :
Gbl.ColorRows[Gbl.RowEvenOdd];
/* Put green tip if course has users */
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"CENTER_MIDDLE %s\">"
"<img src=\"%s/%s16x16.gif\""
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />"
2015-12-06 14:18:07 +01:00
"</td>",
BgColor,
Gbl.Prefs.IconsURL,
Crs->NumUsrs ? "ok_green" :
"tr",
Crs->NumUsrs ? Txt_COURSE_With_users :
Txt_COURSE_Without_users,
Crs->NumUsrs ? Txt_COURSE_With_users :
Txt_COURSE_Without_users);
/* Institutional code of the course */
fprintf (Gbl.F.Out,"<td class=\"%s CENTER_MIDDLE %s\">"
"%s"
"</td>",
TxtClassNormal,BgColor,
Crs->InstitutionalCrsCod);
/* Course year */
fprintf (Gbl.F.Out,"<td class=\"%s CENTER_MIDDLE %s\">"
"%s"
"</td>",
TxtClassNormal,BgColor,
Txt_YEAR_OF_DEGREE[Crs->Year]);
/* Course full name */
fprintf (Gbl.F.Out,"<td class=\"%s LEFT_MIDDLE %s\">",
TxtClassStrong,BgColor);
Act_FormGoToStart (ActSeeCrsInf);
Crs_PutParamCrsCod (Crs->CrsCod);
sprintf (Gbl.Title,Txt_Go_to_X,Crs->FullName);
2016-07-01 17:13:41 +02:00
Act_LinkFormSubmit (Gbl.Title,TxtClassStrong,NULL);
2015-12-06 14:18:07 +01:00
fprintf (Gbl.F.Out,"%s</a>",
Crs->FullName);
Act_FormEnd ();
fprintf (Gbl.F.Out,"</td>");
2015-12-14 16:44:14 +01:00
/* Current number of teachers in this course */
2015-12-06 14:18:07 +01:00
fprintf (Gbl.F.Out,"<td class=\"%s RIGHT_MIDDLE %s\">"
"%u"
"</td>",
2015-12-14 16:44:14 +01:00
TxtClassNormal,BgColor,Crs->NumTchs);
2015-12-06 14:18:07 +01:00
2015-12-14 16:44:14 +01:00
/* Current number of students in this course */
2015-12-06 14:18:07 +01:00
fprintf (Gbl.F.Out,"<td class=\"%s RIGHT_MIDDLE %s\">"
"%u"
"</td>",
2015-12-14 16:44:14 +01:00
TxtClassNormal,BgColor,Crs->NumStds);
2015-12-06 14:18:07 +01:00
/* Course status */
StatusTxt = Crs_GetStatusTxtFromStatusBits (Crs->Status);
2017-03-17 00:46:28 +01:00
fprintf (Gbl.F.Out,"<td class=\"%s LEFT_MIDDLE %s\">",
TxtClassNormal,BgColor);
if (StatusTxt != Crs_STATUS_ACTIVE) // If active ==> do not show anything
fprintf (Gbl.F.Out,"%s",Txt_COURSE_STATUS[StatusTxt]);
fprintf (Gbl.F.Out,"</td>"
"</tr>");
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)
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 courses in this degree *****/
Crs_GetListCoursesInDegree (Crs_ALL_COURSES_EXCEPT_REMOVED);
/***** Get list of degrees in this centre *****/
Deg_GetListDegsOfCurrentCtr ();
/***** Start frame *****/
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_Courses_of_DEGREE_X,Gbl.CurrentDeg.Deg.ShrtName);
Lay_StartRoundFrame (NULL,Gbl.Alert.Txt,Crs_PutIconToViewCourses,
2017-04-30 12:44:53 +02:00
Hlp_DEGREE_Courses);
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 *****/
2016-04-16 15:05:18 +02:00
if (Gbl.CurrentDeg.NumCrss)
2016-03-20 12:35:27 +01:00
Crs_ListCoursesForEdition ();
2017-04-30 12:44:53 +02:00
/***** End frame *****/
Lay_EndRoundFrame ();
/***** Free list of courses in this degree *****/
Crs_FreeListCoursesInDegree (&Gbl.CurrentDeg.Deg);
/***** Free list of degrees in this centre *****/
Deg_FreeListDegs (&Gbl.CurrentCtr.Ctr.Degs);
}
/*****************************************************************************/
/**************** Put contextual icons in edition of courses *****************/
/*****************************************************************************/
static void Crs_PutIconToViewCourses (void)
{
2017-04-30 23:48:48 +02:00
Lay_PutContextualIconToView (ActSeeCrs,NULL);
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 *****/
2017-05-01 10:22:16 +02:00
Lay_StartTableWide (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 *****/
2017-05-01 10:22:16 +02:00
Lay_EndTable ();
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;
Crs_StatusTxt_t StatusTxt;
/***** 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;
NumCrs < Gbl.CurrentDeg.NumCrss;
NumCrs++)
{
Crs = &(Gbl.CurrentDeg.Deg.LstCrss[NumCrs]);
if (Crs->Year == Year)
{
ICanEdit = Crs_CheckIfICanEdit (Crs);
2014-12-01 23:55:08 +01:00
2016-07-04 09:54:36 +02:00
/* Put icon to remove course */
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"BM\">");
if (Crs->NumUsrs || // Course has users ==> deletion forbidden
!ICanEdit)
Lay_PutIconRemovalNotAllowed ();
else // Crs->NumUsrs == 0 && ICanEdit
{
Act_FormStart (ActRemCrs);
Crs_PutParamOtherCrsCod (Crs->CrsCod);
Lay_PutIconRemove ();
Act_FormEnd ();
}
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
2016-07-04 09:54:36 +02:00
/* Course code */
fprintf (Gbl.F.Out,"<td class=\"DAT CODE\">"
"%ld"
"</td>",
Crs->CrsCod);
2014-12-01 23:55:08 +01:00
2016-07-04 09:54:36 +02:00
/* Institutional code of the course */
fprintf (Gbl.F.Out,"<td class=\"DAT CENTER_MIDDLE\">");
if (ICanEdit)
{
Act_FormStart (ActChgInsCrsCod);
Crs_PutParamOtherCrsCod (Crs->CrsCod);
fprintf (Gbl.F.Out,"<input type=\"text\" name=\"InsCrsCod\""
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_INS_CODE\""
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-07 11:03:05 +01:00
Crs_MAX_CHARS_INSTITUTIONAL_CRS_COD,
2016-07-04 09:54:36 +02:00
Crs->InstitutionalCrsCod,
Gbl.Form.Id);
Act_FormEnd ();
}
else
fprintf (Gbl.F.Out,"%s",Crs->InstitutionalCrsCod);
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
2016-07-04 09:54:36 +02:00
/* Course year */
fprintf (Gbl.F.Out,"<td class=\"DAT CENTER_MIDDLE\">");
if (ICanEdit)
{
Act_FormStart (ActChgCrsYea);
Crs_PutParamOtherCrsCod (Crs->CrsCod);
fprintf (Gbl.F.Out,"<select name=\"OthCrsYear\""
" style=\"width:50px;\""
" onchange=\"document.getElementById('%s').submit();\">",
Gbl.Form.Id);
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)
fprintf (Gbl.F.Out,"<option value=\"%u\"%s>%s</option>",
YearAux,
YearAux == Crs->Year ? " selected=\"selected\"" :
"",
Txt_YEAR_OF_DEGREE[YearAux]);
fprintf (Gbl.F.Out,"</select>");
Act_FormEnd ();
}
else
fprintf (Gbl.F.Out,"%s",Txt_YEAR_OF_DEGREE[Crs->Year]);
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
2016-07-04 09:54:36 +02:00
/* Course short name */
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_MIDDLE\">");
if (ICanEdit)
{
Act_FormStart (ActRenCrsSho);
Crs_PutParamOtherCrsCod (Crs->CrsCod);
fprintf (Gbl.F.Out,"<input type=\"text\" name=\"ShortName\""
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_SHORT_NAME\""
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-08 14:12:33 +01:00
Hie_MAX_CHARS_SHRT_NAME,Crs->ShrtName,
2016-07-04 09:54:36 +02:00
Gbl.Form.Id);
Act_FormEnd ();
}
else
2016-10-28 10:03:37 +02:00
fprintf (Gbl.F.Out,"%s",Crs->ShrtName);
2016-07-04 09:54:36 +02:00
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
2016-07-04 09:54:36 +02:00
/* Course full name */
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_MIDDLE\">");
if (ICanEdit)
{
Act_FormStart (ActRenCrsFul);
Crs_PutParamOtherCrsCod (Crs->CrsCod);
fprintf (Gbl.F.Out,"<input type=\"text\" name=\"FullName\""
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_FULL_NAME\""
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-08 14:12:33 +01:00
Hie_MAX_CHARS_FULL_NAME,Crs->FullName,
2016-07-04 09:54:36 +02:00
Gbl.Form.Id);
Act_FormEnd ();
}
else
fprintf (Gbl.F.Out,"%s",Crs->FullName);
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
2016-07-04 09:54:36 +02:00
/* Current number of teachers in this course */
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE\">"
"%u"
"</td>",
Crs->NumTchs);
/* Current number of students in this course */
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE\">"
"%u"
"</td>",
Crs->NumStds);
2017-03-17 00:46:28 +01:00
/* Course requester */
UsrDat.UsrCod = Crs->RequesterUsrCod;
Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat);
2017-05-02 01:05:23 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT INPUT_REQUESTER LEFT_TOP\">");
2017-05-02 01:16:06 +02:00
Msg_WriteMsgAuthor (&UsrDat,true,NULL);
2017-05-01 21:17:38 +02:00
fprintf (Gbl.F.Out,"</td>");
2017-03-17 00:46:28 +01:00
2016-07-04 09:54:36 +02:00
/* Course status */
StatusTxt = Crs_GetStatusTxtFromStatusBits (Crs->Status);
2017-03-17 00:46:28 +01:00
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_MIDDLE\">");
2016-07-04 09:54:36 +02:00
if (Gbl.Usrs.Me.LoggedRole >= Rol_DEG_ADM &&
StatusTxt == Crs_STATUS_PENDING)
{
Act_FormStart (ActChgCrsSta);
Crs_PutParamOtherCrsCod (Crs->CrsCod);
fprintf (Gbl.F.Out,"<select name=\"Status\" class=\"INPUT_STATUS\""
" onchange=\"document.getElementById('%s').submit();\">"
"<option value=\"%u\" selected=\"selected\">%s</option>"
"<option value=\"%u\">%s</option>"
"</select>",
Gbl.Form.Id,
(unsigned) Crs_GetStatusBitsFromStatusTxt (Crs_STATUS_PENDING),
Txt_COURSE_STATUS[Crs_STATUS_PENDING],
(unsigned) Crs_GetStatusBitsFromStatusTxt (Crs_STATUS_ACTIVE),
Txt_COURSE_STATUS[Crs_STATUS_ACTIVE]);
Act_FormEnd ();
}
2017-03-17 00:46:28 +01:00
else if (StatusTxt != Crs_STATUS_ACTIVE) // If active ==> do not show anything
2016-07-04 09:54:36 +02:00
fprintf (Gbl.F.Out,"%s",Txt_COURSE_STATUS[StatusTxt]);
2017-03-17 00:46:28 +01:00
fprintf (Gbl.F.Out,"</td>"
2016-07-04 09:54:36 +02:00
"</tr>");
}
}
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)
{
2015-04-07 21:44:24 +02:00
return (bool) (Gbl.Usrs.Me.LoggedRole >= Rol_DEG_ADM || // I am a degree administrator or higher
2014-12-01 23:55:08 +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
}
/*****************************************************************************/
/******************* 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;
/***** Start form *****/
2015-04-07 21:44:24 +02:00
if (Gbl.Usrs.Me.LoggedRole >= Rol_DEG_ADM)
2014-12-01 23:55:08 +01:00
Act_FormStart (ActNewCrs);
2015-04-07 21:44:24 +02:00
else if (Gbl.Usrs.Me.MaxRole >= Rol__GUEST_)
2014-12-01 23:55:08 +01:00
Act_FormStart (ActReqCrs);
else
Lay_ShowErrorAndExit ("You can not edit courses.");
/***** Write heading *****/
2017-04-30 12:44:53 +02:00
Lay_StartRoundFrameTable (NULL,Txt_New_course,NULL,NULL,2);
2014-12-01 23:55:08 +01:00
Crs_PutHeadCoursesForEdition ();
2017-04-30 14:03:45 +02:00
/***** Column to remove course, disabled here *****/
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<tr>"
2017-04-30 14:03:45 +02:00
"<td class=\"BM\"></td>");
2014-12-01 23:55:08 +01:00
/***** Course code *****/
2015-12-05 21:15:30 +01:00
fprintf (Gbl.F.Out,"<td class=\"CODE\"></td>");
2014-12-01 23:55:08 +01:00
/***** Institutional code of the course *****/
2015-07-28 11:27:16 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">"
2015-10-23 01:31:08 +02:00
"<input type=\"text\" name=\"InsCrsCod\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
" class=\"INPUT_INS_CODE\" />"
2014-12-01 23:55:08 +01:00
"</td>",
2017-03-07 11:03:05 +01:00
Crs_MAX_CHARS_INSTITUTIONAL_CRS_COD,
2017-05-11 20:04:38 +02:00
Gbl.Degs.EditingCrs.InstitutionalCrsCod);
2014-12-01 23:55:08 +01:00
/***** Year *****/
2015-07-28 11:27:16 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">"
2015-09-28 18:28:29 +02:00
"<select name=\"OthCrsYear\" style=\"width:50px;\">");
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++)
2016-02-29 18:53:26 +01:00
fprintf (Gbl.F.Out,"<option value=\"%u\"%s>%s</option>",
Year,
2017-05-11 20:04:38 +02:00
Year == Gbl.Degs.EditingCrs.Year ? " selected=\"selected\"" :
"",
2016-02-29 18:53:26 +01:00
Txt_YEAR_OF_DEGREE[Year]);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</select>"
"</td>");
/***** Course short name *****/
2016-10-20 20:29:15 +02:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE\">"
2015-10-23 01:31:08 +02:00
"<input type=\"text\" name=\"ShortName\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
2016-11-19 02:57:47 +01:00
" class=\"INPUT_SHORT_NAME\""
" required=\"required\" />"
2014-12-01 23:55:08 +01:00
"</td>",
2017-05-11 20:04:38 +02:00
Hie_MAX_CHARS_SHRT_NAME,Gbl.Degs.EditingCrs.ShrtName);
2014-12-01 23:55:08 +01:00
/***** Course full name *****/
2016-10-20 20:29:15 +02:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE\">"
2015-10-23 01:31:08 +02:00
"<input type=\"text\" name=\"FullName\""
2015-12-05 21:15:30 +01:00
" maxlength=\"%u\" value=\"%s\""
2016-11-19 02:57:47 +01:00
" class=\"INPUT_FULL_NAME\""
" required=\"required\" />"
2014-12-01 23:55:08 +01:00
"</td>",
2017-05-11 20:04:38 +02:00
Hie_MAX_CHARS_FULL_NAME,Gbl.Degs.EditingCrs.FullName);
2014-12-01 23:55:08 +01:00
2016-06-04 13:07:33 +02:00
/***** Current number of teachers in this course *****/
2015-07-28 11:27:16 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"0"
"</td>");
2014-12-01 23:55:08 +01:00
2016-06-04 13:07:33 +02:00
/***** Current number of students in this course *****/
2015-07-28 11:27:16 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE\">"
2014-12-22 19:59:27 +01:00
"0"
"</td>");
2014-12-01 23:55:08 +01:00
/***** Course requester *****/
2017-05-02 01:05:23 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT INPUT_REQUESTER LEFT_TOP\">");
2017-05-02 01:16:06 +02:00
Msg_WriteMsgAuthor (&Gbl.Usrs.Me.UsrDat,true,NULL);
2017-05-01 21:17:38 +02:00
fprintf (Gbl.F.Out,"</td>");
2017-03-17 00:46:28 +01:00
/***** Course status *****/
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_MIDDLE\">"
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>");
2015-04-11 23:46:21 +02:00
/***** Send button and end frame *****/
2015-04-12 18:01:06 +02:00
Lay_EndRoundFrameTableWithButton (Lay_CREATE_BUTTON,Txt_Create_course);
2014-12-01 23:55:08 +01:00
2015-04-11 23:46:21 +02:00
/***** End form *****/
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Write header with fields of a 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;
extern const char *Txt_Teachers_ABBREVIATION;
2016-06-04 13:07:33 +02:00
extern const char *Txt_Students_ABBREVIATION;
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<tr>"
"<th class=\"BM\"></th>"
2015-09-06 20:02:14 +02:00
"<th class=\"CENTER_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"CENTER_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"</th>"
2014-12-01 23:55:08 +01:00
"</tr>",
Txt_Institutional_BR_code,
Txt_Year_OF_A_DEGREE,
Txt_Course,
Txt_Teachers_ABBREVIATION,
2017-03-17 00:46:28 +01:00
Txt_Students_ABBREVIATION);
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;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Teachers_ABBREVIATION;
2016-06-04 13:07:33 +02:00
extern const char *Txt_Students_ABBREVIATION;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Requester;
fprintf (Gbl.F.Out,"<tr>"
"<th class=\"BM\"></th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"CENTER_MIDDLE\">"
2015-10-06 01:19:21 +02:00
"%s (%s)"
2014-12-26 22:11:03 +01:00
"</th>"
2015-12-05 21:15:30 +01:00
"<th class=\"CENTER_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"</th>"
2014-12-01 23:55:08 +01:00
"</tr>",
Txt_Code,
2015-10-06 01:19:21 +02:00
Txt_Institutional_code,Txt_optional,
2014-12-01 23:55:08 +01:00
Txt_Year_OF_A_DEGREE,
2016-03-02 20:29:31 +01:00
Txt_Short_name_of_the_course,
Txt_Full_name_of_the_course,
2014-12-01 23:55:08 +01:00
Txt_Teachers_ABBREVIATION,
2016-06-04 13:07:33 +02:00
Txt_Students_ABBREVIATION,
2014-12-01 23:55:08 +01:00
Txt_Requester);
}
/*****************************************************************************/
/****************** Receive form to request a new course *********************/
/*****************************************************************************/
void Crs_RecFormReqCrs (void)
{
Crs_RecFormRequestOrCreateCrs ((unsigned) Crs_STATUS_BIT_PENDING);
}
/*****************************************************************************/
/******************* Receive form to create a new course *********************/
/*****************************************************************************/
void Crs_RecFormNewCrs (void)
{
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;
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
struct Degree Deg;
/***** Get parameters from form *****/
/* Set course degree */
2017-05-11 20:04:38 +02:00
Deg.DegCod = Gbl.Degs.EditingCrs.DegCod = Gbl.CurrentDeg.Deg.DegCod;
2014-12-01 23:55:08 +01:00
/* Get parameters of the new course */
2017-05-11 20:04:38 +02:00
Crs_GetParamsNewCourse (&Gbl.Degs.EditingCrs);
2014-12-01 23:55:08 +01:00
/***** Check if year is correct *****/
Deg_GetDataOfDegreeByCod (&Deg);
2017-05-11 20:04:38 +02:00
if (Gbl.Degs.EditingCrs.Year <= Deg_MAX_YEARS_PER_DEGREE) // If year is valid
2014-12-01 23:55:08 +01:00
{
2017-05-11 20:04:38 +02:00
if (Gbl.Degs.EditingCrs.ShrtName[0] &&
Gbl.Degs.EditingCrs.FullName[0]) // If there's a course name
2014-12-01 23:55:08 +01:00
{
/***** If name of course was in database... *****/
2017-05-11 20:04:38 +02:00
if (Crs_CheckIfCrsNameExistsInYearOfDeg ("ShortName",Gbl.Degs.EditingCrs.ShrtName,-1L,
Gbl.Degs.EditingCrs.DegCod,Gbl.Degs.EditingCrs.Year))
2014-12-01 23:55:08 +01:00
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_WARNING;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_course_X_already_exists,
2017-05-11 20:04:38 +02:00
Gbl.Degs.EditingCrs.ShrtName);
2014-12-01 23:55:08 +01:00
}
2017-05-11 20:04:38 +02:00
else if (Crs_CheckIfCrsNameExistsInYearOfDeg ("FullName",Gbl.Degs.EditingCrs.FullName,-1L,
Gbl.Degs.EditingCrs.DegCod,Gbl.Degs.EditingCrs.Year))
2014-12-01 23:55:08 +01:00
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_WARNING;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_course_X_already_exists,
2017-05-11 20:04:38 +02:00
Gbl.Degs.EditingCrs.FullName);
2014-12-01 23:55:08 +01:00
}
else // Add new requested course to database
2017-05-11 20:04:38 +02:00
Crs_CreateCourse (Status);
2014-12-01 23:55:08 +01:00
}
else // If there is not a course name
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_WARNING;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,"%s",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
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_WARNING;
2017-05-11 20:04:38 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_year_X_is_not_allowed,
Gbl.Degs.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
// Gbl.Degs.EditingCrs must hold the course beeing edited
2014-12-01 23:55:08 +01:00
2017-05-11 20:04:38 +02:00
static void Crs_CreateCourse (unsigned Status)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_Created_new_course_X;
2016-10-22 18:06:53 +02:00
char Query[512 +
2017-03-08 14:12:33 +01:00
Hie_MAX_BYTES_SHRT_NAME +
Hie_MAX_BYTES_FULL_NAME];
2014-12-01 23:55:08 +01:00
/***** Insert new course into pending requests *****/
2017-03-13 13:17:53 +01:00
sprintf (Query,"INSERT INTO courses"
" (DegCod,Year,InsCrsCod,Status,RequesterUsrCod,ShortName,FullName)"
" VALUES"
2017-03-24 01:09:27 +01:00
" (%ld,%u,'%s',%u,%ld,'%s','%s')",
2017-05-11 20:04:38 +02:00
Gbl.Degs.EditingCrs.DegCod,Gbl.Degs.EditingCrs.Year,
Gbl.Degs.EditingCrs.InstitutionalCrsCod,
2015-12-06 00:26:49 +01:00
Status,
Gbl.Usrs.Me.UsrDat.UsrCod,
2017-05-11 20:04:38 +02:00
Gbl.Degs.EditingCrs.ShrtName,Gbl.Degs.EditingCrs.FullName);
Gbl.Degs.EditingCrs.CrsCod = DB_QueryINSERTandReturnCode (Query,"can not create a new course");
2014-12-01 23:55:08 +01:00
2016-03-24 20:13:42 +01:00
/***** Create success message *****/
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_SUCCESS;
2017-05-11 20:04:38 +02:00
sprintf (Gbl.Alert.Txt,Txt_Created_new_course_X,
Gbl.Degs.EditingCrs.FullName);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************ Request removing of a course ***********************/
/*****************************************************************************/
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;
extern const char *Txt_You_dont_have_permission_to_edit_this_course;
struct Course Crs;
/***** Get course code *****/
2016-10-23 19:40:14 +02:00
Crs.CrsCod = Crs_GetAndCheckParamOtherCrsCod ();
2014-12-01 23:55:08 +01:00
/***** Get data of the course from database *****/
Crs_GetDataOfCourseByCod (&Crs);
if (Crs_CheckIfICanEdit (&Crs))
{
/***** Check if this course has users *****/
if (Crs.NumUsrs) // Course has users ==> don't remove
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_To_remove_a_course_you_must_first_remove_all_users_in_the_course);
2017-04-30 12:44:53 +02:00
else // Course has no users ==> remove it
2014-12-01 23:55:08 +01:00
{
/***** Remove course *****/
Crs_RemoveCourseCompletely (Crs.CrsCod);
/***** Write message to show the change made *****/
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_Course_X_removed,
2014-12-01 23:55:08 +01:00
Crs.FullName);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
}
else
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_You_dont_have_permission_to_edit_this_course);
2014-12-01 23:55:08 +01:00
/***** Show the form again *****/
2017-04-30 12:44:53 +02:00
Crs_EditCourses ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Get data of a course from its code ********************/
/*****************************************************************************/
bool Crs_GetDataOfCourseByCod (struct Course *Crs)
{
char Query[1024];
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';
Crs->NumStds = 0;
Crs->NumTchs = 0;
Crs->NumUsrs = 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 *****/
sprintf (Query,"SELECT CrsCod,DegCod,Year,InsCrsCod,Status,RequesterUsrCod,ShortName,FullName"
2017-03-24 01:09:27 +01:00
" FROM courses WHERE CrsCod=%ld",
2016-12-28 02:40:15 +01:00
Crs->CrsCod);
2016-12-30 01:20:49 +01:00
if (DB_QuerySELECT (Query,&mysql_res,"can not get data of a course")) // 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 number of teachers *****/
2015-04-07 21:44:24 +02:00
Crs->NumTchs = Usr_GetNumUsrsInCrs (Rol_TEACHER,Crs->CrsCod);
2014-12-01 23:55:08 +01:00
2016-06-04 13:07:33 +02:00
/***** Get number of students *****/
Crs->NumStds = Usr_GetNumUsrsInCrs (Rol_STUDENT,Crs->CrsCod);
2016-07-04 09:54:36 +02:00
Crs->NumUsrs = Crs->NumStds +
Crs->NumTchs;
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
{
char Query[512];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
DegShortName[0] = CrsShortName[0] = '\0';
if (CrsCod > 0)
{
/***** Get the short name of a degree from database *****/
sprintf (Query,"SELECT courses.ShortName,degrees.ShortName"
" FROM courses,degrees"
2017-03-24 01:09:27 +01:00
" WHERE courses.CrsCod=%ld"
2014-12-01 23:55:08 +01:00
" AND courses.DegCod=degrees.DegCod",
CrsCod);
if (DB_QuerySELECT (Query,&mysql_res,"can not get the short name of a course") == 1)
{
/***** 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)
{
char Query[128];
/***** Empty course *****/
Crs_EmptyCourseCompletely (CrsCod);
/***** Remove course from table of last accesses to courses in database *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"DELETE FROM crs_last WHERE CrsCod=%ld",CrsCod);
2014-12-01 23:55:08 +01:00
DB_QueryDELETE (Query,"can not remove a course");
/***** Remove course from table of courses in database *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"DELETE FROM courses WHERE CrsCod=%ld",CrsCod);
2014-12-01 23:55:08 +01:00
DB_QueryDELETE (Query,"can not remove a course");
}
/*****************************************************************************/
/********** 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
char Query[512];
/***** Get course data *****/
Crs.CrsCod = CrsCod;
Crs_GetDataOfCourseByCod (&Crs);
/***** Remove all the students in the course *****/
2014-12-12 18:50:36 +01:00
Enr_RemAllStdsInCrs (&Crs);
2014-12-01 23:55:08 +01:00
/***** Set all the notifications from the course as removed,
except notifications about new messages *****/
2016-12-28 18:18:24 +01:00
Ntf_MarkNotifInCrsAsRemoved (-1L,CrsCod);
2014-12-01 23:55:08 +01:00
/***** Remove information of the course ****/
/* Remove timetable of the course */
2017-03-24 01:09:27 +01:00
sprintf (Query,"DELETE FROM timetable_crs WHERE CrsCod=%ld",CrsCod);
2014-12-01 23:55:08 +01:00
DB_QueryDELETE (Query,"can not remove the timetable of a course");
/* Remove other information of the course */
2017-03-24 01:09:27 +01:00
sprintf (Query,"DELETE FROM crs_info_src WHERE CrsCod=%ld",CrsCod);
2014-12-01 23:55:08 +01:00
DB_QueryDELETE (Query,"can not remove info sources of a course");
2017-03-24 01:09:27 +01:00
sprintf (Query,"DELETE FROM crs_info_txt WHERE CrsCod=%ld",CrsCod);
2014-12-01 23:55:08 +01:00
DB_QueryDELETE (Query,"can not remove info of a course");
/***** Remove exam announcements in the course *****/
/* Mark all exam announcements in the course as deleted */
2017-03-24 01:09:27 +01:00
sprintf (Query,"UPDATE exam_announcements SET Status=%u"
" WHERE CrsCod=%ld",
2014-12-01 23:55:08 +01:00
(unsigned) Exa_DELETED_EXAM_ANNOUNCEMENT,CrsCod);
DB_QueryUPDATE (Query,"can not remove exam announcements of a course");
/***** Remove course cards of the course *****/
/* Remove content of course cards */
sprintf (Query,"DELETE FROM crs_records USING crs_record_fields,crs_records"
2017-03-24 01:09:27 +01:00
" WHERE crs_record_fields.CrsCod=%ld"
2016-07-04 09:54:36 +02:00
" AND crs_record_fields.FieldCod=crs_records.FieldCod",
CrsCod);
2014-12-01 23:55:08 +01:00
DB_QueryDELETE (Query,"can not remove content of cards in a course");
/* Remove definition of fields in course cards */
2017-03-24 01:09:27 +01:00
sprintf (Query,"DELETE FROM crs_record_fields WHERE CrsCod=%ld",CrsCod);
2014-12-01 23:55:08 +01:00
DB_QueryDELETE (Query,"can not remove fields of cards in a course");
/***** Remove assignments of the course *****/
Asg_RemoveCrsAssignments (CrsCod);
/***** 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 */
2016-07-04 09:54:36 +02:00
sprintf (Query,"INSERT INTO notices_deleted"
" (NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif)"
2014-12-01 23:55:08 +01:00
" SELECT NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif FROM notices"
2017-03-24 01:09:27 +01:00
" WHERE CrsCod=%ld",
2016-07-04 09:54:36 +02:00
CrsCod);
2014-12-01 23:55:08 +01:00
DB_QueryINSERT (Query,"can not remove notices in a course");
/* Remove all notices from the course */
2017-03-24 01:09:27 +01:00
sprintf (Query,"DELETE FROM notices WHERE CrsCod=%ld",CrsCod);
2014-12-01 23:55:08 +01:00
DB_QueryDELETE (Query,"can not remove notices in a course");
2016-10-27 23:38:53 +02:00
/***** Remove all the threads and posts in forums of the course *****/
2016-10-28 00:23:02 +02:00
For_RemoveForums (Sco_SCOPE_CRS,CrsCod);
/***** Remove surveys of the course *****/
Svy_RemoveSurveys (Sco_SCOPE_CRS,CrsCod);
2014-12-01 23:55:08 +01:00
2016-04-03 14:13:20 +02:00
/***** Remove all test exams made in the course *****/
2016-11-21 13:15:08 +01:00
Tst_RemoveCrsTestResults (CrsCod);
2016-04-01 21:56:00 +02:00
2016-04-03 14:13:20 +02:00
/***** Remove all tests questions in the course *****/
Tst_RemoveCrsTests (CrsCod);
2014-12-01 23:55:08 +01:00
/***** Remove groups in the course *****/
/* Remove all the users in groups in the course */
sprintf (Query,"DELETE FROM crs_grp_usr"
" USING crs_grp_types,crs_grp,crs_grp_usr"
2017-03-24 01:09:27 +01:00
" WHERE crs_grp_types.CrsCod=%ld"
2014-12-01 23:55:08 +01:00
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod",
CrsCod);
DB_QueryDELETE (Query,"can not remove users from groups of a course");
/* Remove all the groups in the course */
sprintf (Query,"DELETE FROM crs_grp"
" USING crs_grp_types,crs_grp"
2017-03-24 01:09:27 +01:00
" WHERE crs_grp_types.CrsCod=%ld"
2014-12-01 23:55:08 +01:00
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod",
CrsCod);
DB_QueryDELETE (Query,"can not remove groups of a course");
/* Remove all the group types in the course */
sprintf (Query,"DELETE FROM crs_grp_types"
2017-03-24 01:09:27 +01:00
" WHERE CrsCod=%ld",
2014-12-01 23:55:08 +01:00
CrsCod);
DB_QueryDELETE (Query,"can not remove types of group of a course");
/***** Remove users' requests for inscription in the course *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"DELETE FROM crs_usr_requests WHERE CrsCod=%ld",
2014-12-01 23:55:08 +01:00
CrsCod);
DB_QueryDELETE (Query,"can not remove requests for inscription to a course");
/***** Remove possible users remaining in the course (teachers) *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"DELETE FROM crs_usr WHERE CrsCod=%ld",
2014-12-01 23:55:08 +01:00
CrsCod);
DB_QueryDELETE (Query,"can not remove users from a course");
/***** Remove information related to files in course *****/
2015-01-25 18:50:43 +01:00
Brw_RemoveCrsFilesFromDB (CrsCod);
2014-12-01 23:55:08 +01:00
/***** Remove directories of the course *****/
sprintf (PathRelCrs,"%s/%s/%ld",
Cfg_PATH_SWAD_PRIVATE,Cfg_FOLDER_CRS,CrsCod);
2016-10-06 22:18:33 +02:00
Fil_RemoveTree (PathRelCrs);
2014-12-01 23:55:08 +01:00
sprintf (PathRelCrs,"%s/%s/%ld",
Cfg_PATH_SWAD_PUBLIC,Cfg_FOLDER_CRS,CrsCod);
2016-10-06 22:18:33 +02:00
Fil_RemoveTree (PathRelCrs);
2014-12-01 23:55:08 +01:00
}
2016-06-12 01:18:35 +02:00
/*****************************************************************************/
/***** Change the institutional code of a course in course configuration *****/
/*****************************************************************************/
void Crs_ChangeInsCrsCodInConfig (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;
extern const char *Txt_You_dont_have_permission_to_edit_this_course;
2017-03-07 11:03:05 +01:00
char NewInstitutionalCrsCod[Crs_MAX_BYTES_INSTITUTIONAL_CRS_COD + 1];
2016-06-12 01:18:35 +02:00
/***** Get institutional code from form *****/
2017-03-07 11:03:05 +01:00
Par_GetParToText ("InsCrsCod",NewInstitutionalCrsCod,Crs_MAX_BYTES_INSTITUTIONAL_CRS_COD);
2016-06-12 01:18:35 +02:00
/***** Change the institutional course code *****/
if (strcmp (NewInstitutionalCrsCod,Gbl.CurrentCrs.Crs.InstitutionalCrsCod))
{
Crs_UpdateInstitutionalCrsCod (&Gbl.CurrentCrs.Crs,NewInstitutionalCrsCod);
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_institutional_code_of_the_course_X_has_changed_to_Y,
2016-10-28 10:03:37 +02:00
Gbl.CurrentCrs.Crs.ShrtName,NewInstitutionalCrsCod);
2016-06-12 01:18:35 +02:00
}
else // The same institutional code
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_institutional_code_of_the_course_X_has_not_changed,
2016-10-28 10:03:37 +02:00
Gbl.CurrentCrs.Crs.ShrtName);
2016-06-12 01:18:35 +02:00
}
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;
extern const char *Txt_You_dont_have_permission_to_edit_this_course;
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
/***** Get parameters from form *****/
/* Get course code */
2017-05-11 20:04:38 +02:00
Gbl.Degs.EditingCrs.CrsCod = Crs_GetAndCheckParamOtherCrsCod ();
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 */
2017-05-11 20:04:38 +02:00
Crs_GetDataOfCourseByCod (&Gbl.Degs.EditingCrs);
2014-12-01 23:55:08 +01:00
2017-05-11 20:04:38 +02:00
if (Crs_CheckIfICanEdit (&Gbl.Degs.EditingCrs))
2014-12-01 23:55:08 +01:00
{
/***** Change the institutional course code *****/
2017-05-11 20:04:38 +02:00
if (strcmp (NewInstitutionalCrsCod,Gbl.Degs.EditingCrs.InstitutionalCrsCod))
2014-12-01 23:55:08 +01:00
{
2017-05-11 20:04:38 +02:00
Crs_UpdateInstitutionalCrsCod (&Gbl.Degs.EditingCrs,NewInstitutionalCrsCod);
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_SUCCESS;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_institutional_code_of_the_course_X_has_changed_to_Y,
2017-05-11 20:04:38 +02:00
Gbl.Degs.EditingCrs.ShrtName,NewInstitutionalCrsCod);
2014-12-01 23:55:08 +01:00
}
else // The same institutional code
2017-03-26 03:36:48 +02:00
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_INFO;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_institutional_code_of_the_course_X_has_not_changed,
2017-05-11 20:04:38 +02:00
Gbl.Degs.EditingCrs.ShrtName);
2017-03-26 03:36:48 +02:00
}
2014-12-01 23:55:08 +01:00
}
else
2016-03-24 20:13:42 +01:00
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_WARNING;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,"%s",Txt_You_dont_have_permission_to_edit_this_course);
2016-03-24 20:13:42 +01:00
}
2014-12-01 23:55:08 +01:00
}
2016-10-19 01:46:40 +02:00
/*****************************************************************************/
/***************** Change the degree of the current course *******************/
/*****************************************************************************/
2016-10-20 16:49:42 +02:00
void Crs_ChangeCrsDegInConfig (void)
2016-10-19 01:46:40 +02:00
{
extern const char *Txt_In_the_year_X_of_the_degree_Y_already_existed_a_course_with_the_name_Z;
2017-01-28 15:58:46 +01:00
extern const char *Txt_YEAR_OF_DEGREE[1 + Deg_MAX_YEARS_PER_DEGREE];
2016-10-19 01:46:40 +02:00
extern const char *Txt_The_course_X_has_been_moved_to_the_degree_Y;
struct Degree NewDeg;
2016-10-23 18:39:04 +02:00
/***** Get parameter with degree code *****/
2016-10-23 19:40:14 +02:00
NewDeg.DegCod = Deg_GetAndCheckParamOtherDegCod ();
2016-10-19 20:43:26 +02:00
2016-10-20 20:02:59 +02:00
/***** Check if degree has changed *****/
if (NewDeg.DegCod != Gbl.CurrentCrs.Crs.DegCod)
2016-10-19 01:46:40 +02:00
{
2016-10-20 20:02:59 +02:00
/***** Get data of new degree *****/
Deg_GetDataOfDegreeByCod (&NewDeg);
2016-10-19 01:46:40 +02:00
/***** If name of course was in database in the new degree... *****/
2016-10-28 10:03:37 +02:00
if (Crs_CheckIfCrsNameExistsInYearOfDeg ("ShortName",Gbl.CurrentCrs.Crs.ShrtName,-1L,
2016-10-20 19:46:06 +02:00
NewDeg.DegCod,Gbl.CurrentCrs.Crs.Year))
2016-10-19 01:46:40 +02:00
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_WARNING;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_In_the_year_X_of_the_degree_Y_already_existed_a_course_with_the_name_Z,
2016-10-28 10:03:37 +02:00
Txt_YEAR_OF_DEGREE[Gbl.CurrentCrs.Crs.Year],NewDeg.FullName,Gbl.CurrentCrs.Crs.ShrtName);
2016-10-19 01:46:40 +02:00
}
2016-10-20 19:46:06 +02:00
else if (Crs_CheckIfCrsNameExistsInYearOfDeg ("FullName",Gbl.CurrentCrs.Crs.FullName,-1L,
NewDeg.DegCod,Gbl.CurrentCrs.Crs.Year))
2016-10-19 01:46:40 +02:00
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_WARNING;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_In_the_year_X_of_the_degree_Y_already_existed_a_course_with_the_name_Z,
2016-10-19 01:46:40 +02:00
Txt_YEAR_OF_DEGREE[Gbl.CurrentCrs.Crs.Year],NewDeg.FullName,Gbl.CurrentCrs.Crs.FullName);
}
else // Update degree in database
{
/***** Update degree in table of courses *****/
2016-10-20 16:49:42 +02:00
Crs_UpdateCrsDegDB (Gbl.CurrentCrs.Crs.CrsCod,NewDeg.DegCod);
2016-10-19 20:43:26 +02:00
Gbl.CurrentCrs.Crs.DegCod =
Gbl.CurrentDeg.Deg.DegCod = NewDeg.DegCod;
2016-10-19 01:46:40 +02:00
/***** Initialize again current course, degree, centre... *****/
2016-11-14 17:26:32 +01:00
Hie_InitHierarchy ();
2016-10-19 01:46:40 +02:00
/***** Create message to show the change made *****/
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_SUCCESS;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_course_X_has_been_moved_to_the_degree_Y,
2016-10-19 20:43:26 +02:00
Gbl.CurrentCrs.Crs.FullName,
Gbl.CurrentDeg.Deg.FullName);
2016-10-19 01:46:40 +02:00
}
}
}
2016-10-19 20:43:26 +02:00
/*****************************************************************************/
/** Show message of success after changing a course in course configuration **/
/*****************************************************************************/
void Crs_ContEditAfterChgCrsInConfig (void)
{
/***** Write error/success message *****/
2017-05-11 23:45:46 +02:00
Ale_ShowPendingAlert ();
2016-10-19 20:43:26 +02:00
/***** Show the form again *****/
Crs_ShowIntroduction ();
}
2016-10-19 23:21:53 +02:00
/*****************************************************************************/
/********************** Update degree in table of courses ********************/
/*****************************************************************************/
2016-10-20 16:49:42 +02:00
static void Crs_UpdateCrsDegDB (long CrsCod,long DegCod)
2016-10-19 23:21:53 +02:00
{
char Query[128];
/***** Update degree in table of courses *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"UPDATE courses SET DegCod=%ld WHERE CrsCod=%ld",
2016-10-19 23:21:53 +02:00
DegCod,CrsCod);
DB_QueryUPDATE (Query,"can not move course to another degree");
}
2016-06-12 01:18:35 +02:00
/*****************************************************************************/
/*********** Change the year of a course in course configuration *************/
/*****************************************************************************/
void Crs_ChangeCrsYearInConfig (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];
2016-06-12 01:18:35 +02:00
extern const char *Txt_The_year_of_the_course_X_has_changed;
extern const char *Txt_The_year_X_is_not_allowed;
2017-01-28 15:58:46 +01:00
char YearStr[2 + 1];
2016-06-12 01:18:35 +02:00
unsigned NewYear;
/***** Get parameter with year/semester *****/
Par_GetParToText ("OthCrsYear",YearStr,2);
NewYear = Deg_ConvStrToYear (YearStr);
if (NewYear <= Deg_MAX_YEARS_PER_DEGREE) // If year is valid
{
/***** If name of course was in database in the new year... *****/
2016-10-28 10:03:37 +02:00
if (Crs_CheckIfCrsNameExistsInYearOfDeg ("ShortName",Gbl.CurrentCrs.Crs.ShrtName,-1L,
2016-10-20 19:46:06 +02:00
Gbl.CurrentCrs.Crs.DegCod,NewYear))
2016-06-12 01:18:35 +02:00
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_WARNING;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_course_X_already_exists_in_year_Y,
2016-10-28 10:03:37 +02:00
Gbl.CurrentCrs.Crs.ShrtName,Txt_YEAR_OF_DEGREE[NewYear]);
2016-06-12 01:18:35 +02:00
}
2016-10-20 19:46:06 +02:00
else if (Crs_CheckIfCrsNameExistsInYearOfDeg ("FullName",Gbl.CurrentCrs.Crs.FullName,-1L,
Gbl.CurrentCrs.Crs.DegCod,NewYear))
2016-06-12 01:18:35 +02:00
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_WARNING;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_course_X_already_exists_in_year_Y,
2016-06-12 01:18:35 +02:00
Gbl.CurrentCrs.Crs.FullName,Txt_YEAR_OF_DEGREE[NewYear]);
}
else // Update year in database
{
/***** Update year in table of courses *****/
Crs_UpdateCrsYear (&Gbl.CurrentCrs.Crs,NewYear);
/***** Create message to show the change made *****/
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_SUCCESS;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_year_of_the_course_X_has_changed,
2016-10-28 10:03:37 +02:00
Gbl.CurrentCrs.Crs.ShrtName);
2016-06-12 01:18:35 +02:00
}
}
else // Year not valid
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_WARNING;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_year_X_is_not_allowed,NewYear);
2016-06-12 01:18:35 +02:00
}
}
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;
2014-12-01 23:55:08 +01:00
extern const char *Txt_You_dont_have_permission_to_edit_this_course;
struct Degree Deg;
2017-01-28 15:58:46 +01:00
char YearStr[2 + 1];
2014-12-01 23:55:08 +01:00
unsigned NewYear;
/***** Get parameters from form *****/
/* Get course code */
2017-05-11 20:04:38 +02:00
Gbl.Degs.EditingCrs.CrsCod = Crs_GetAndCheckParamOtherCrsCod ();
2014-12-01 23:55:08 +01:00
/* Get parameter with year */
Par_GetParToText ("OthCrsYear",YearStr,2);
NewYear = Deg_ConvStrToYear (YearStr);
2017-05-11 20:04:38 +02:00
Crs_GetDataOfCourseByCod (&Gbl.Degs.EditingCrs);
2014-12-01 23:55:08 +01:00
2017-05-11 20:04:38 +02:00
if (Crs_CheckIfICanEdit (&Gbl.Degs.EditingCrs))
2014-12-01 23:55:08 +01:00
{
2017-05-11 20:04:38 +02:00
Deg.DegCod = Gbl.Degs.EditingCrs.DegCod;
2014-12-01 23:55:08 +01:00
Deg_GetDataOfDegreeByCod (&Deg);
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... *****/
2017-05-11 20:04:38 +02:00
if (Crs_CheckIfCrsNameExistsInYearOfDeg ("ShortName",Gbl.Degs.EditingCrs.ShrtName,-1L,
Gbl.Degs.EditingCrs.DegCod,NewYear))
2014-12-01 23:55:08 +01:00
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_WARNING;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_course_X_already_exists_in_year_Y,
2017-05-11 20:04:38 +02:00
Gbl.Degs.EditingCrs.ShrtName,Txt_YEAR_OF_DEGREE[NewYear]);
2014-12-01 23:55:08 +01:00
}
2017-05-11 20:04:38 +02:00
else if (Crs_CheckIfCrsNameExistsInYearOfDeg ("FullName",Gbl.Degs.EditingCrs.FullName,-1L,
Gbl.Degs.EditingCrs.DegCod,NewYear))
2014-12-01 23:55:08 +01:00
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_WARNING;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_course_X_already_exists_in_year_Y,
2017-05-11 20:04:38 +02:00
Gbl.Degs.EditingCrs.FullName,Txt_YEAR_OF_DEGREE[NewYear]);
2014-12-01 23:55:08 +01:00
}
else // Update year in database
{
/***** Update year in table of courses *****/
2017-05-11 20:04:38 +02:00
Crs_UpdateCrsYear (&Gbl.Degs.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 *****/
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_SUCCESS;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_year_of_the_course_X_has_changed,
2017-05-11 20:04:38 +02:00
Gbl.Degs.EditingCrs.ShrtName);
2014-12-01 23:55:08 +01:00
}
}
else // Year not valid
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_WARNING;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_year_X_is_not_allowed,NewYear);
2014-12-01 23:55:08 +01:00
}
}
else
2016-03-24 20:13:42 +01:00
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_WARNING;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,"%s",Txt_You_dont_have_permission_to_edit_this_course);
2016-03-24 20:13:42 +01:00
}
2014-12-01 23:55:08 +01:00
}
2016-06-12 01:18:35 +02:00
/*****************************************************************************/
/****************** Change the year/semester of a course *********************/
/*****************************************************************************/
static void Crs_UpdateCrsYear (struct Course *Crs,unsigned NewYear)
{
char Query[128];
/***** Update year/semester in table of courses *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"UPDATE courses SET Year=%u WHERE CrsCod=%ld",
2016-07-02 11:26:08 +02:00
NewYear,Crs->CrsCod);
2016-06-12 01:18:35 +02:00
DB_QueryUPDATE (Query,"can not update the year of a course");
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
{
char Query[512];
/***** Update institutional course code in table of courses *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"UPDATE courses SET InsCrsCod='%s' WHERE CrsCod=%ld",
2014-12-01 23:55:08 +01:00
NewInstitutionalCrsCod,Crs->CrsCod);
DB_QueryUPDATE (Query,"can not update the institutional code of the current course");
/***** 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
}
/*****************************************************************************/
/********************* Change the short name of a course *********************/
/*****************************************************************************/
void Crs_RenameCourseShort (void)
{
2016-10-23 19:40:14 +02:00
Gbl.Degs.EditingCrs.CrsCod = Crs_GetAndCheckParamOtherCrsCod ();
2016-10-28 10:03:37 +02:00
Crs_RenameCourse (&Gbl.Degs.EditingCrs,Cns_SHRT_NAME);
2014-12-01 23:55:08 +01:00
}
2016-10-23 18:23:37 +02:00
void Crs_RenameCourseShortInConfig (void)
{
2016-10-28 10:03:37 +02:00
Crs_RenameCourse (&Gbl.CurrentCrs.Crs,Cns_SHRT_NAME);
2016-10-23 18:23:37 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************* Change the full name of a course **********************/
/*****************************************************************************/
void Crs_RenameCourseFull (void)
{
2016-10-23 19:40:14 +02:00
Gbl.Degs.EditingCrs.CrsCod = Crs_GetAndCheckParamOtherCrsCod ();
2016-10-23 17:20:06 +02:00
Crs_RenameCourse (&Gbl.Degs.EditingCrs,Cns_FULL_NAME);
}
2014-12-01 23:55:08 +01:00
2016-10-23 17:20:06 +02:00
void Crs_RenameCourseFullInConfig (void)
{
Crs_RenameCourse (&Gbl.CurrentCrs.Crs,Cns_FULL_NAME);
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************ Change the name of a course ************************/
/*****************************************************************************/
2016-10-28 10:03:37 +02:00
static void Crs_RenameCourse (struct Course *Crs,Cns_ShrtOrFullName_t ShrtOrFullName)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_You_can_not_leave_the_name_of_the_course_X_empty;
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;
extern const char *Txt_You_dont_have_permission_to_edit_this_course;
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 *****/
Crs_GetDataOfCourseByCod (Crs);
if (Crs_CheckIfICanEdit (Crs))
{
/***** Check if new name is empty *****/
if (!NewCrsName[0])
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_WARNING;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_You_can_not_leave_the_name_of_the_course_X_empty,
2014-12-01 23:55:08 +01:00
CurrentCrsName);
}
else
{
/***** Check if old and new names are the same (this happens when user press enter with no changes in the form) *****/
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))
2014-12-01 23:55:08 +01:00
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_WARNING;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_course_X_already_exists,
2014-12-01 23:55:08 +01:00
NewCrsName);
}
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
2016-03-24 20:13:42 +01:00
/* Create message to show the change made */
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_SUCCESS;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_name_of_the_course_X_has_changed_to_Y,
2014-12-01 23:55:08 +01:00
CurrentCrsName,NewCrsName);
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
2017-03-26 03:36:48 +02:00
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_INFO;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_name_of_the_course_X_has_not_changed,
2014-12-01 23:55:08 +01:00
CurrentCrsName);
2017-03-26 03:36:48 +02:00
}
2014-12-01 23:55:08 +01:00
}
}
else
2016-03-01 13:36:48 +01:00
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_WARNING;
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,"%s",Txt_You_dont_have_permission_to_edit_this_course);
2016-03-01 13:36:48 +01:00
}
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 ***********/
/*****************************************************************************/
static bool Crs_CheckIfCrsNameExistsInYearOfDeg (const char *FieldName,const char *Name,long CrsCod,
long DegCod,unsigned Year)
{
char Query[256 + Hie_MAX_BYTES_FULL_NAME];
/***** Get number of courses in a year of a degree and with a name from database *****/
sprintf (Query,"SELECT COUNT(*) FROM courses"
2017-03-24 01:09:27 +01:00
" WHERE DegCod=%ld AND Year=%u"
" AND %s='%s' AND CrsCod<>%ld",
2017-03-09 11:16:17 +01:00
DegCod,Year,FieldName,Name,CrsCod);
return (DB_QueryCOUNT (Query,"can not check if the name of a course already existed") != 0);
}
/*****************************************************************************/
/***************** Update course name in table of courses ********************/
/*****************************************************************************/
static void Crs_UpdateCrsNameDB (long CrsCod,const char *FieldName,const char *NewCrsName)
{
char Query[128 + Hie_MAX_BYTES_FULL_NAME];
/***** Update course changing old name by new name *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"UPDATE courses SET %s='%s' WHERE CrsCod=%ld",
2017-03-09 11:16:17 +01:00
FieldName,NewCrsName,CrsCod);
DB_QueryUPDATE (Query,"can not update the name of a course");
}
/*****************************************************************************/
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;
char Query[256];
Crs_Status_t Status;
Crs_StatusTxt_t StatusTxt;
/***** Get parameters from form *****/
/* Get course code */
2017-05-11 20:04:38 +02:00
Gbl.Degs.EditingCrs.CrsCod = Crs_GetAndCheckParamOtherCrsCod ();
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 *****/
2017-05-11 20:04:38 +02:00
Crs_GetDataOfCourseByCod (&Gbl.Degs.EditingCrs);
2014-12-01 23:55:08 +01:00
/***** Update status in table of courses *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"UPDATE courses SET Status=%u WHERE CrsCod=%ld",
2017-05-11 20:04:38 +02:00
(unsigned) Status,Gbl.Degs.EditingCrs.CrsCod);
2014-12-01 23:55:08 +01:00
DB_QueryUPDATE (Query,"can not update the status of a course");
2017-05-11 20:04:38 +02:00
Gbl.Degs.EditingCrs.Status = Status;
2014-12-01 23:55:08 +01:00
2016-03-24 20:13:42 +01:00
/***** Create message to show the change made *****/
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_status_of_the_course_X_has_changed,
2017-05-11 20:04:38 +02:00
Gbl.Degs.EditingCrs.ShrtName);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************* Show message of success after changing a course ***************/
/*****************************************************************************/
void Crs_ContEditAfterChgCrs (void)
{
2016-03-24 20:13:42 +01:00
bool PutButtonToRequestRegistration;
2017-05-11 20:04:38 +02:00
/***** Start alert *****/
2017-05-11 23:45:46 +02:00
Ale_ShowAlertAndButton1 (Gbl.Alert.Type,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
2017-05-11 23:45:46 +02:00
if (Gbl.Alert.Type == Ale_SUCCESS)
2017-03-26 03:36:48 +02:00
{
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;
switch (Gbl.Usrs.Me.LoggedRole)
{
case Rol__GUEST_: // I do not belong to any course
PutButtonToRequestRegistration = true;
break;
case Rol_VISITOR:
PutButtonToRequestRegistration = !Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Degs.EditingCrs.CrsCod,
false);
break;
case Rol_STUDENT:
case Rol_TEACHER:
if (Gbl.Degs.EditingCrs.CrsCod != Gbl.CurrentCrs.Crs.CrsCod)
PutButtonToRequestRegistration = !Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Degs.EditingCrs.CrsCod,
false);
break;
default:
break;
}
if (PutButtonToRequestRegistration)
2017-05-11 20:55:04 +02:00
Crs_PutButtonToRegisterInCrs ();
2016-03-01 13:36:48 +01:00
}
2014-12-01 23:55:08 +01:00
2017-05-11 20:04:38 +02:00
/***** End alert *****/
2017-05-11 23:45:46 +02:00
Ale_ShowAlertAndButton2 (ActUnk,NULL,NULL,Lay_NO_BUTTON,NULL);
2017-05-11 20:04:38 +02:00
2014-12-01 23:55:08 +01:00
/***** Show the form again *****/
2017-04-30 12:44:53 +02:00
Crs_EditCourses ();
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
// Gbl.Degs.EditingCrs is the course that is beeing edited
// Gbl.CurrentCrs.Crs is the current 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
{
extern const char *Txt_Go_to_X;
2017-05-11 20:55:04 +02:00
// If the course being edited is different to the current one...
if (Gbl.Degs.EditingCrs.CrsCod != Gbl.CurrentCrs.Crs.CrsCod)
2016-03-01 23:58:48 +01:00
{
Act_FormStart (ActSeeCrsInf);
2017-05-11 20:55:04 +02:00
Crs_PutParamCrsCod (Gbl.Degs.EditingCrs.CrsCod);
sprintf (Gbl.Title,Txt_Go_to_X,Gbl.Degs.EditingCrs.ShrtName);
2017-05-11 20:04:38 +02:00
Lay_PutConfirmButton (Gbl.Title);
2016-03-01 23:58:48 +01:00
Act_FormEnd ();
}
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
// Gbl.Degs.EditingCrs is the course that is beeing edited
// Gbl.CurrentCrs.Crs is the current course
2016-03-24 20:13:42 +01:00
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;
Act_FormStart (ActReqSignUp);
2017-05-11 20:55:04 +02:00
// If the course beeing edited is different to the current one...
if (Gbl.Degs.EditingCrs.CrsCod != Gbl.CurrentCrs.Crs.CrsCod)
Crs_PutParamCrsCod (Gbl.Degs.EditingCrs.CrsCod);
sprintf (Gbl.Title,Txt_Register_me_in_X,Gbl.Degs.EditingCrs.ShrtName);
2017-05-11 20:04:38 +02:00
Lay_PutCreateButton (Gbl.Title);
2016-03-24 20:13:42 +01:00
Act_FormEnd ();
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************* Select one of my courses **************************/
/*****************************************************************************/
void Crs_ReqSelectOneOfMyCourses (void)
{
/***** Search / select more courses *****/
2015-04-02 14:22:21 +02:00
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
2014-12-13 20:32:10 +01:00
Crs_PutLinkToSearchCourses ();
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</div>");
/***** Select one of my courses *****/
/* Fill the list with the courses I belong to, if not filled */
Usr_GetMyCourses ();
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
}
/*****************************************************************************/
/******************* Put a link (form) to search courses *********************/
/*****************************************************************************/
2014-12-13 20:32:10 +01:00
static void Crs_PutLinkToSearchCourses (void)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_Search_courses;
/***** Put form to search / select courses *****/
2015-12-13 18:32:37 +01:00
Lay_PutContextualLink ( Gbl.CurrentCrs.Crs.CrsCod > 0 ? ActCrsReqSch :
2015-04-02 18:39:49 +02:00
(Gbl.CurrentDeg.Deg.DegCod > 0 ? ActDegReqSch :
(Gbl.CurrentCtr.Ctr.CtrCod > 0 ? ActCtrReqSch :
(Gbl.CurrentIns.Ins.InsCod > 0 ? ActInsReqSch :
(Gbl.CurrentCty.Cty.CtyCod > 0 ? ActCtyReqSch :
ActSysReqSch)))),
2017-04-17 19:03:21 +02:00
NULL,Sch_PutLinkToSearchCoursesParams,
2015-12-13 19:02:06 +01:00
"search64x64.gif",
2016-07-01 16:32:42 +02:00
Txt_Search_courses,Txt_Search_courses,
NULL);
2015-04-02 18:39:49 +02:00
}
2016-06-24 20:34:58 +02:00
static void Sch_PutLinkToSearchCoursesParams (void) // TODO: Move to search module
2015-04-02 18:39:49 +02:00
{
2016-06-24 20:34:58 +02:00
Sco_PutParamScope ("ScopeSch",Sco_SCOPE_SYS);
2014-12-13 17:17:42 +01:00
Par_PutHiddenParamUnsigned ("WhatToSearch",(unsigned) Sch_SEARCH_COURSES);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2014-12-13 20:32:10 +01:00
/****************** Put a link (form) to select my courses *******************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2014-12-13 20:32:10 +01:00
void Crs_PutFormToSelectMyCourses (void)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_My_courses;
/***** Put form to search / select courses *****/
2017-04-17 19:03:21 +02:00
Lay_PutContextualLink (ActMyCrs,NULL,NULL,
2016-07-01 16:32:42 +02:00
"hierarchy64x64.gif",
Txt_My_courses,Txt_My_courses,
NULL);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Write parameter with code of course ********************/
/*****************************************************************************/
void Crs_PutParamCrsCod (long CrsCod)
{
2015-03-07 21:08:44 +01:00
Par_PutHiddenParamLong ("crs",CrsCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Write parameter with code of course ********************/
/*****************************************************************************/
static void Crs_PutParamOtherCrsCod (long CrsCod)
{
Par_PutHiddenParamLong ("OthCrsCod",CrsCod);
}
/*****************************************************************************/
/********************* Get parameter with code of course *********************/
/*****************************************************************************/
2016-10-23 19:40:14 +02:00
static long Crs_GetAndCheckParamOtherCrsCod (void)
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-01-28 20:32:50 +01:00
if ((CrsCod = Par_GetParToLong ("OthCrsCod")) <= 0)
2016-10-23 18:32:46 +02:00
Lay_ShowErrorAndExit ("Code of course is missing.");
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;
extern const char *Txt_Teachers_ABBREVIATION;
2016-06-04 13:07:33 +02:00
extern const char *Txt_Students_ABBREVIATION;
2016-09-08 21:40:31 +02:00
char SubQuery[32];
2014-12-01 23:55:08 +01:00
char Query[1024];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCrss;
unsigned NumCrs;
/***** Get courses of a user from database *****/
2016-09-08 21:40:31 +02:00
if (Role == Rol_UNKNOWN)
SubQuery[0] = '\0'; // Role == Rol_UNKNOWN ==> any role
else
2017-03-24 01:09:27 +01:00
sprintf (SubQuery," AND crs_usr.Role=%u",(unsigned) Role);
2015-01-17 19:31:21 +01:00
sprintf (Query,"SELECT degrees.DegCod,courses.CrsCod,degrees.ShortName,degrees.FullName,"
2015-12-06 01:02:47 +01:00
"courses.Year,courses.FullName,centres.ShortName,crs_usr.Accepted"
2014-12-01 23:55:08 +01:00
" FROM crs_usr,courses,degrees,centres"
2017-03-24 01:09:27 +01:00
" WHERE crs_usr.UsrCod=%ld%s"
2014-12-01 23:55:08 +01:00
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
2015-12-06 01:02:47 +01:00
" ORDER BY degrees.FullName,courses.Year,courses.FullName",
2016-09-08 21:40:31 +02:00
UsrDat->UsrCod,SubQuery);
2014-12-01 23:55:08 +01:00
/***** List the courses (one row per course) *****/
if ((NumCrss = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get courses of a user")))
{
2016-06-15 20:35:49 +02:00
/* Start frame and table */
2016-11-13 23:52:51 +01:00
Lay_StartRoundFrameTable ("100%",NULL,NULL,NULL,2);
2016-06-15 20:35:49 +02:00
2014-12-01 23:55:08 +01:00
/* Heading row */
2016-09-22 22:09:24 +02:00
sprintf (Gbl.Title,Txt_USER_in_COURSE,
Role == Rol_UNKNOWN ? Txt_User[Usr_SEX_UNKNOWN] : // Role == Rol_UNKNOWN ==> any role
Txt_ROLES_SINGUL_Abc[Role][UsrDat->Sex]);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<tr>"
2016-09-11 18:31:11 +02:00
"<th colspan=\"7\" class=\"LEFT_MIDDLE\">%s:</th>"
2016-06-16 11:28:20 +02:00
"</tr>"
"<tr>"
2014-12-01 23:55:08 +01:00
"<th class=\"BM\"></th>"
"<th class=\"BM\"></th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"CENTER_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2014-12-01 23:55:08 +01:00
"</tr>",
2016-06-16 11:28:20 +02:00
Gbl.Title,
2014-12-01 23:55:08 +01:00
Txt_Degree,
Txt_Year_OF_A_DEGREE,
Txt_Course,
2016-06-04 13:07:33 +02:00
Txt_Teachers_ABBREVIATION,
Txt_Students_ABBREVIATION);
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
/* End table and frame */
Lay_EndRoundFrameTable ();
2014-12-01 23:55:08 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/****************************** List courses found ***************************/
/*****************************************************************************/
// Returns number of courses found
unsigned Crs_ListCrssFound (const char *Query)
{
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;
extern const char *Txt_Students_ABBREVIATION;
extern const char *Txt_Teachers_ABBREVIATION;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCrss;
unsigned NumCrs;
/***** Query database *****/
NumCrss = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get courses");
/***** List the courses (one row per course) *****/
if (NumCrss)
{
/***** Write heading *****/
/* Number of courses found */
2016-04-17 23:43:55 +02:00
sprintf (Gbl.Title,"%u %s",
NumCrss,(NumCrss == 1) ? Txt_course :
Txt_courses);
2016-11-13 23:52:51 +01:00
Lay_StartRoundFrameTable (NULL,Gbl.Title,NULL,NULL,2);
2014-12-01 23:55:08 +01:00
/* Heading row */
fprintf (Gbl.F.Out,"<tr>"
"<th class=\"BM\"></th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"CENTER_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-26 22:11:03 +01:00
"%s"
"</th>"
2014-12-01 23:55:08 +01:00
"</tr>",
Txt_Degree,
Txt_Year_OF_A_DEGREE,
Txt_Course,
Txt_Students_ABBREVIATION,
Txt_Teachers_ABBREVIATION);
/* 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,false);
}
2016-03-20 13:47:46 +01:00
/***** End table *****/
2015-04-12 18:01:06 +02:00
Lay_EndRoundFrameTable ();
2014-12-01 23:55:08 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumCrss;
}
/*****************************************************************************/
/************** 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;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Go_to_X;
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;
2014-12-01 23:55:08 +01:00
const char *Style;
const char *StyleNoBR;
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.");
2015-01-17 19:31:21 +01:00
if (!Deg_GetDataOfDegreeByCod (&Deg))
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 *****/
2015-04-07 21:44:24 +02:00
NumTchs = Usr_GetNumUsrsInCrs (Rol_TEACHER,CrsCod);
2016-06-04 13:07:33 +02:00
NumStds = Usr_GetNumUsrsInCrs (Rol_STUDENT,CrsCod);
if (NumTchs + NumStds)
2014-12-01 23:55:08 +01:00
{
Style = "DAT_N";
2016-01-01 21:18:44 +01:00
StyleNoBR = "DAT_NOBR_N";
2014-12-01 23:55:08 +01:00
}
else
{
Style = "DAT";
StyleNoBR = "DAT_NOBR";
}
2015-09-04 19:26:08 +02:00
BgColor = (CrsCod == Gbl.CurrentCrs.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 *****/
fprintf (Gbl.F.Out,"<tr>");
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');
2015-09-04 17:10:27 +02:00
fprintf (Gbl.F.Out,"<td class=\"BT %s\">"
2014-12-01 23:55:08 +01:00
"<img src=\"%s/%s16x16.gif\""
2015-09-05 12:04:30 +02:00
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />"
2014-12-01 23:55:08 +01:00
"</td>",
BgColor,
Gbl.Prefs.IconsURL,
Accepted ? "ok_on" :
"tr",
2017-03-30 11:20:06 +02:00
Accepted ? Txt_Enrolment_confirmed :
Txt_Enrolment_not_confirmed,
Accepted ? Txt_Enrolment_confirmed :
Txt_Enrolment_not_confirmed);
2014-12-01 23:55:08 +01:00
}
/***** Write number of course in this search *****/
2015-09-04 17:10:27 +02:00
fprintf (Gbl.F.Out,"<td class=\"%s RIGHT_TOP %s\">"
2014-12-22 19:59:27 +01:00
"%u"
"</td>",
2014-12-01 23:55:08 +01:00
StyleNoBR,BgColor,NumCrs);
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]) *****/
2015-09-04 17:10:27 +02:00
fprintf (Gbl.F.Out,"<td class=\"%s LEFT_TOP %s\">",
2014-12-01 23:55:08 +01:00
StyleNoBR,BgColor);
Act_FormGoToStart (ActSeeDegInf);
2015-01-17 19:31:21 +01:00
Deg_PutParamDegCod (Deg.DegCod);
sprintf (Gbl.Title,Txt_Go_to_X,row[2]);
2016-07-01 17:13:41 +02:00
Act_LinkFormSubmit (Gbl.Title,StyleNoBR,NULL);
2016-10-28 10:03:37 +02:00
Log_DrawLogo (Sco_SCOPE_DEG,Deg.DegCod,Deg.ShrtName,20,"CENTER_TOP",true);
2015-01-17 19:31:21 +01:00
fprintf (Gbl.F.Out," %s (%s)"
2015-03-13 00:16:02 +01:00
"</a>",
2015-12-06 01:02:47 +01:00
row[2],row[6]);
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
2015-01-17 19:31:21 +01:00
/***** Write year (row[4]) *****/
2015-09-04 17:10:27 +02:00
fprintf (Gbl.F.Out,"<td class=\"%s CENTER_TOP %s\">"
2014-12-22 19:59:27 +01:00
"%s"
"</td>",
2015-01-17 19:31:21 +01:00
Style,BgColor,Txt_YEAR_OF_DEGREE[Deg_ConvStrToYear (row[4])]);
2014-12-01 23:55:08 +01:00
2015-12-06 01:02:47 +01:00
/***** Write course full name (row[5]) *****/
2015-09-04 17:10:27 +02:00
fprintf (Gbl.F.Out,"<td class=\"%s LEFT_TOP %s\">",
2014-12-01 23:55:08 +01:00
Style,BgColor);
Act_FormGoToStart (ActSeeCrsInf);
Crs_PutParamCrsCod (CrsCod);
2015-01-17 19:31:21 +01:00
sprintf (Gbl.Title,Txt_Go_to_X,row[6]);
2016-07-01 17:13:41 +02:00
Act_LinkFormSubmit (Gbl.Title,Style,NULL);
2015-12-06 01:02:47 +01:00
fprintf (Gbl.F.Out,"%s</a>",row[5]);
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
/***** Write number of teachers in course *****/
2015-09-04 17:10:27 +02:00
fprintf (Gbl.F.Out,"<td class=\"%s RIGHT_TOP %s\">"
2014-12-22 19:59:27 +01:00
"%u"
2016-06-11 21:02:36 +02:00
"</td>",
2014-12-01 23:55:08 +01:00
Style,BgColor,NumTchs);
2016-06-04 13:07:33 +02:00
/***** Write number of students in course *****/
fprintf (Gbl.F.Out,"<td class=\"%s RIGHT_TOP %s\">"
"%u"
2016-06-11 21:02:36 +02:00
"</td>"
"</tr>",
2016-06-04 13:07:33 +02:00
Style,BgColor,NumStds);
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)
{
char Query[256];
if (Gbl.CurrentCrs.Crs.CrsCod > 0 &&
2015-04-07 21:44:24 +02:00
Gbl.Usrs.Me.LoggedRole >= Rol_STUDENT)
2014-12-01 23:55:08 +01:00
{
/***** Update my last access to current course *****/
2017-03-13 13:17:53 +01:00
sprintf (Query,"REPLACE INTO crs_last"
" (CrsCod,LastTime)"
" VALUES"
2017-03-24 01:09:27 +01:00
" (%ld,NOW())",
2014-12-01 23:55:08 +01:00
Gbl.CurrentCrs.Crs.CrsCod);
DB_QueryUPDATE (Query,"can not update last access to current course");
}
}
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 *****/
2017-04-17 19:03:21 +02:00
Lay_PutContextualLink (ActReqRemOldCrs,NULL,NULL,
2017-03-27 01:14:38 +02:00
"remove-on64x64.png",
Txt_Eliminate_old_courses,Txt_Eliminate_old_courses,
NULL);
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************** Write form to remove old courses *********************/
/*****************************************************************************/
void Crs_AskRemoveOldCrss (void)
{
2017-03-27 13:38:10 +02:00
extern const char *Hlp_SYSTEM_Hierarchy_eliminate_old_courses;
2015-07-27 21:25:45 +02:00
extern const char *The_ClassForm[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;
2015-10-07 23:03:30 +02:00
/***** Start form *****/
2014-12-01 23:55:08 +01:00
Act_FormStart (ActRemOldCrs);
2015-10-07 23:03:30 +02:00
/***** Start frame *****/
2017-03-27 13:38:10 +02:00
Lay_StartRoundFrame (NULL,Txt_Eliminate_old_courses,NULL,Hlp_SYSTEM_Hierarchy_eliminate_old_courses);
2015-10-07 23:03:30 +02:00
/***** Form to request number of months without clicks *****/
2016-12-27 16:45:37 +01:00
fprintf (Gbl.F.Out,"<label class=\"%s\">%s&nbsp;"
"<select name=\"Months\">",
2015-07-27 21:25:45 +02:00
The_ClassForm[Gbl.Prefs.Theme],
2014-12-01 23:55:08 +01:00
Txt_Eliminate_all_courses_whithout_users_PART_1_OF_2);
for (i = Crs_MIN_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_CRSS;
i <= Crs_MAX_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_CRSS;
i++)
{
fprintf (Gbl.F.Out,"<option");
if (i == MonthsWithoutAccess)
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%u</option>",i);
}
2016-12-27 16:45:37 +01:00
fprintf (Gbl.F.Out,"</select>&nbsp;");
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,Txt_Eliminate_all_courses_whithout_users_PART_2_OF_2,
Cfg_PLATFORM_SHORT_NAME);
2016-12-27 16:45:37 +01:00
fprintf (Gbl.F.Out,"</label>");
2014-12-01 23:55:08 +01:00
2015-10-07 23:03:30 +02:00
/***** End frame *****/
Lay_EndRoundFrameWithButton (Lay_REMOVE_BUTTON,Txt_Eliminate);
/***** End form *****/
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
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;
char Query[1024];
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 *****/
sprintf (Query,"SELECT CrsCod FROM crs_last WHERE"
2015-11-11 03:00:22 +01:00
" LastTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')"
2014-12-01 23:55:08 +01:00
" AND CrsCod NOT IN (SELECT DISTINCT CrsCod FROM crs_usr)",
SecondsWithoutAccess);
if ((NumCrss = DB_QuerySELECT (Query,&mysql_res,"can not get old users")))
{
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_Eliminating_X_courses_whithout_users_and_with_more_than_Y_months_without_access,
2014-12-01 23:55:08 +01:00
NumCrss,
MonthsWithoutAccess,
Cfg_PLATFORM_SHORT_NAME);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_INFO,Gbl.Alert.Txt);
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 *****/
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_X_courses_have_been_eliminated,
2014-12-01 23:55:08 +01:00
NumCrssRemoved);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}