");
Act_FormStart (ActAccEnrCrs);
Act_LinkFormSubmit (Txt_Confirm_my_enrollment,The_ClassFormul[Gbl.Prefs.Theme]);
Lay_PutSendIcon ("ok_green",Txt_Confirm_my_enrollment,Txt_Confirm_my_enrollment);
fprintf (Gbl.F.Out,"");
/***** Send button to refuse register in the current course *****/
Act_FormStart (ActRemMeCrs);
Act_LinkFormSubmit (Txt_Remove_me_from_this_course,The_ClassFormul[Gbl.Prefs.Theme]);
Lay_PutSendIcon ("delon",Txt_Remove_me_from_this_course,Txt_Remove_me_from_this_course);
fprintf (Gbl.F.Out,""
"
");
/***** Mark possible notification as seen *****/
Ntf_SetNotifAsSeen (Ntf_EVENT_ENROLLMENT,
-1L,
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
/****************** Put an enrollment into a notification ********************/
/*****************************************************************************/
// This function may be called inside a web service, so don't report error
void Enr_GetNotifEnrollment (char *SummaryStr,
long CrsCod,long UsrCod,
unsigned MaxChars)
{
extern const char *Txt_ROLES_SINGULAR_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
char Query[256];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
struct UsrData UsrDat;
Rol_Role_t Role;
SummaryStr[0] = '\0'; // Return nothing on error
/***** Get user's role in course from database *****/
sprintf (Query,"SELECT Role"
" FROM crs_usr"
" WHERE CrsCod='%ld' AND UsrCod='%ld'",
CrsCod,UsrCod);
if (!mysql_query (&Gbl.mysql,Query))
if ((mysql_res = mysql_store_result (&Gbl.mysql)) != NULL)
{
/***** Result should have a unique row *****/
if (mysql_num_rows (mysql_res) == 1)
{
/***** Get user's role in course *****/
row = mysql_fetch_row (mysql_res);
/* Initialize structure with user's data */
Usr_UsrDataConstructor (&UsrDat);
/* Get user's data */
UsrDat.UsrCod = UsrCod;
Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat);
/* Role (row[0]) */
Role = Rol_ConvertUnsignedStrToRole (row[0]);
strcpy (SummaryStr,Txt_ROLES_SINGULAR_Abc[Role][UsrDat.Sex]);
if (MaxChars)
Str_LimitLengthHTMLStr (SummaryStr,MaxChars);
/* Free memory used for user's data */
Usr_UsrDataDestructor (&UsrDat);
}
mysql_free_result (mysql_res);
}
}
/*****************************************************************************/
/***************************** Update user's data ****************************/
/*****************************************************************************/
// UsrDat->UsrCod must be > 0
void Enr_UpdateUsrData (struct UsrData *UsrDat)
{
extern const char *Ico_IconSetId[Ico_NUM_ICON_SETS];
extern const char *The_ThemeId[The_NUM_THEMES];
extern const char *Txt_STR_LANG_ID[Txt_NUM_LANGUAGES];
extern const char *Usr_StringsSexDB[Usr_NUM_SEXS];
char Query[2048];
/***** Check if user's code is initialized *****/
if (UsrDat->UsrCod <= 0)
Lay_ShowErrorAndExit ("Can not update user's data. Wrong user's code.");
/***** Filter some user's data before updating */
Enr_FilterUsrDat (UsrDat);
/***** Update user's common data *****/
sprintf (Query,"UPDATE usr_data"
" SET Password='%s',"
"Surname1='%s',Surname2='%s',FirstName='%s',Sex='%s',"
"Layout='%u',Theme='%s',IconSet='%s',Language='%s',PublicPhoto='%c',"
"CtyCod='%ld',"
"LocalAddress='%s',LocalPhone='%s',FamilyAddress='%s',FamilyPhone='%s',OriginPlace='%s',Birthday='%04u-%02u-%02u',Comments='%s'"
" WHERE UsrCod='%ld'",
UsrDat->Password,
UsrDat->Surname1,UsrDat->Surname2,UsrDat->FirstName,
Usr_StringsSexDB[UsrDat->Sex],
(unsigned) UsrDat->Prefs.Layout,
The_ThemeId[UsrDat->Prefs.Theme],
Ico_IconSetId[UsrDat->Prefs.IconSet],
Txt_STR_LANG_ID[UsrDat->Prefs.Language],
UsrDat->PublicPhoto ? 'Y' :
'N',
UsrDat->CtyCod,
UsrDat->LocalAddress,UsrDat->LocalPhone,
UsrDat->FamilyAddress,UsrDat->FamilyPhone,UsrDat->OriginPlace,
UsrDat->Birthday.Year,UsrDat->Birthday.Month,UsrDat->Birthday.Day,
UsrDat->Comments ? UsrDat->Comments :
"",
UsrDat->UsrCod);
DB_QueryUPDATE (Query,"can not update user's data");
}
/*****************************************************************************/
/************************* Filter some user's data ***************************/
/*****************************************************************************/
void Enr_FilterUsrDat (struct UsrData *UsrDat)
{
/***** Fix birthday *****/
if (UsrDat->Birthday.Year < Gbl.Now.Date.Year-99 ||
UsrDat->Birthday.Year > Gbl.Now.Date.Year-16)
UsrDat->Birthday.Year =
UsrDat->Birthday.Month =
UsrDat->Birthday.Day = 0;
}
/*****************************************************************************/
/**************** Update institution, centre and department ******************/
/*****************************************************************************/
void Enr_UpdateInstitutionCentreDepartment (void)
{
char Query[256];
sprintf (Query,"UPDATE usr_data"
" SET InsCtyCod='%ld',InsCod='%ld',CtrCod='%ld',DptCod='%ld'"
" WHERE UsrCod='%ld'",
Gbl.Usrs.Me.UsrDat.InsCtyCod,
Gbl.Usrs.Me.UsrDat.InsCod,
Gbl.Usrs.Me.UsrDat.Tch.CtrCod,
Gbl.Usrs.Me.UsrDat.Tch.DptCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryUPDATE (Query,"can not update institution, centre and department");
}
/*****************************************************************************/
/************** Form to request the user's ID of another user ****************/
/*****************************************************************************/
void Enr_ReqAdminUsrs (void)
{
extern const char *Txt_You_dont_have_permission_to_perform_this_action;
switch (Gbl.Usrs.Me.LoggedRole)
{
case Rol_ROLE_GUEST:
case Rol_ROLE_VISITOR:
case Rol_ROLE_STUDENT:
Enr_AskIfRegRemMe ();
break;
case Rol_ROLE_TEACHER:
if (Gbl.CurrentCrs.Crs.CrsCod > 0)
Enr_ShowFormRegRemSeveralUsrs ();
else
Enr_AskIfRegRemMe ();
break;
case Rol_ROLE_DEG_ADMIN:
if (Gbl.CurrentDeg.Deg.DegCod > 0)
Enr_ReqAnotherUsrIDToRegisterRemove ();
else
Enr_AskIfRegRemMe ();
break;
case Rol_ROLE_CTR_ADMIN:
if (Gbl.CurrentCtr.Ctr.CtrCod > 0)
Enr_ReqAnotherUsrIDToRegisterRemove ();
else
Enr_AskIfRegRemMe ();
break;
case Rol_ROLE_INS_ADMIN:
if (Gbl.CurrentIns.Ins.InsCod > 0)
Enr_ReqAnotherUsrIDToRegisterRemove ();
else
Enr_AskIfRegRemMe ();
break;
case Rol_ROLE_SUPERUSER:
if (Gbl.CurrentCrs.Crs.CrsCod > 0)
Enr_ShowFormRegRemSeveralUsrs ();
else
Enr_ReqAnotherUsrIDToRegisterRemove ();
break;
default:
Lay_ShowAlert (Lay_ERROR,Txt_You_dont_have_permission_to_perform_this_action);
break;
}
}
/*****************************************************************************/
/***** Register/remove users (taken from a list) in/from current course ******/
/*****************************************************************************/
static void Enr_ShowFormRegRemSeveralUsrs (void)
{
extern const char *The_ClassTitle[The_NUM_THEMES];
extern const char *Txt_Step_1_Provide_a_list_of_users;
extern const char *Txt_Option_a_Import_students_from_the_official_lists;
extern const char *Txt_There_is_no_external_service_for_authentication_and_official_lists;
extern const char *Txt_Select_the_groups_of_students_you_want_to_register_in_remove_from_this_course;
extern const char *Txt_Option_b_Type_or_paste_a_list_of_users;
extern const char *Txt_Type_or_paste_a_list_of_IDs_nicks_or_emails_;
extern const char *Txt_Step_2_Select_the_type_of_user_to_register_remove;
extern const char *Txt_Step_3_Select_the_desired_action;
extern const char *Txt_Step_4_Optionally_select_groups;
extern const char *Txt_Select_the_groups_in_from_which_you_want_to_register_remove_users_;
extern const char *Txt_No_groups_have_been_created_in_the_course_X_Therefore_;
extern const char *Txt_Step_5_Confirm_the_enrollment_removing;
extern const char *Txt_Confirm;
fprintf (Gbl.F.Out,"");
/***** Put form to go to admin one user *****/
Enr_PutFormToAdminOneUsr ();
/***** Put link to remove all the students in the current course *****/
if (Gbl.CurrentCrs.Crs.CrsCod > 0) // Course selected
Enr_PutFormToRemAllStdsThisCrs ();
/***** Put link to remove old users *****/
if (Gbl.Usrs.Me.LoggedRole == Rol_ROLE_SUPERUSER)
Enr_PutFormToRemOldUsrs ();
/***** Form to send students to be enrolled / removed *****/
Act_FormStart (ActRcvFrmMdfUsrCrs);
/***** Step 1: List of students to be enrolled / removed *****/
fprintf (Gbl.F.Out,"
"
"
%s"
"
",
The_ClassTitle[Gbl.Prefs.Theme],
Txt_Step_1_Provide_a_list_of_users);
/* Option a: get students from official lists */
fprintf (Gbl.F.Out,"
"
"
%s
"
"
",
The_ClassTitle[Gbl.Prefs.Theme],
Txt_Option_a_Import_students_from_the_official_lists);
if (Cfg_EXTERNAL_LOGIN_CLIENT_COMMAND[0] == '\0')
Lay_ShowAlert (Lay_INFO,Txt_There_is_no_external_service_for_authentication_and_official_lists);
else
{
Lay_ShowAlert (Lay_INFO,Txt_Select_the_groups_of_students_you_want_to_register_in_remove_from_this_course);
Imp_ListMyImpGrpsAndStdsForm ();
}
/* Option b: get students' IDs from pasted text */
fprintf (Gbl.F.Out,"
"
"
%s
"
"
",
The_ClassTitle[Gbl.Prefs.Theme],
Txt_Option_b_Type_or_paste_a_list_of_users);
Lay_ShowAlert (Lay_INFO,Txt_Type_or_paste_a_list_of_IDs_nicks_or_emails_);
Enr_PutAreaToEnterUsrsIDs ();
/***** Step 2: Select type of user to register/remove to/from current course *****/
fprintf (Gbl.F.Out,"
"
"
%s
"
"
",
The_ClassTitle[Gbl.Prefs.Theme],
Txt_Step_2_Select_the_type_of_user_to_register_remove);
if (Gbl.CurrentCrs.Crs.CrsCod > 0) // Course selected
Rol_PutAllRolesRegRemUsrsCrs ();
/***** Step 3: Put different actions to register/remove students to/from current course *****/
fprintf (Gbl.F.Out,"
"
"
%s
"
"
",
The_ClassTitle[Gbl.Prefs.Theme],
Txt_Step_3_Select_the_desired_action);
Enr_PutActionsRegRemSeveralUsrs ();
/***** Step 4: Select groups in which register / remove students *****/
fprintf (Gbl.F.Out,"
"
"
%s
"
"
",
The_ClassTitle[Gbl.Prefs.Theme],
Txt_Step_4_Optionally_select_groups);
if (Gbl.CurrentCrs.Crs.CrsCod > 0) // Course selected
{
if (Gbl.CurrentCrs.Grps.NumGrps) // This course has groups?
{
Lay_ShowAlert (Lay_INFO,Txt_Select_the_groups_in_from_which_you_want_to_register_remove_users_);
Grp_ShowLstGrpsToChgOtherUsrsGrps (-1L);
}
else
{
/* Write help message */
sprintf (Gbl.Message,Txt_No_groups_have_been_created_in_the_course_X_Therefore_,
Gbl.CurrentCrs.Crs.FullName);
Lay_ShowAlert (Lay_INFO,Gbl.Message);
}
}
/***** Step 5: Button to register / remove students *****/
fprintf (Gbl.F.Out,"
"
"
%s
"
"
",
The_ClassTitle[Gbl.Prefs.Theme],
Txt_Step_5_Confirm_the_enrollment_removing);
Pwd_AskForConfirmationOnDangerousAction ();
Lay_PutSendButton (Txt_Confirm);
/***** End of form *****/
fprintf (Gbl.F.Out,""
"
");
}
/*****************************************************************************/
/******************** Put a link (form) to remove old users ******************/
/*****************************************************************************/
static void Enr_PutFormToRemOldUsrs (void)
{
extern const char *The_ClassFormul[The_NUM_THEMES];
extern const char *Txt_Remove_old_users;
/***** Put form to remove old users *****/
Act_FormStart (ActReqRemOldUsr);
Act_LinkFormSubmit (Txt_Remove_old_users,The_ClassFormul[Gbl.Prefs.Theme]);
Lay_PutSendIcon ("delon",Txt_Remove_old_users,Txt_Remove_old_users);
fprintf (Gbl.F.Out,"");
}
/*****************************************************************************/
/*********************** Write form to remove old users **********************/
/*****************************************************************************/
void Enr_AskRemoveOldUsrs (void)
{
extern const char *The_ClassFormul[The_NUM_THEMES];
extern const char *Txt_Eliminate_all_users_who_are_not_enrolled_on_any_courses_PART_1_OF_2;
extern const char *Txt_Eliminate_all_users_who_are_not_enrolled_on_any_courses_PART_2_OF_2;
extern const char *Txt_Eliminate;
unsigned MonthsWithoutAccess = Usr_DEF_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_USRS;
unsigned Months;
/***** Form to request number of months without clicks *****/
fprintf (Gbl.F.Out,"