swad-core/swad_mail.c

1966 lines
67 KiB
C
Raw Normal View History

2016-11-16 23:19:52 +01:00
// swad_mail.c: all the stuff related to email
2014-12-01 23:55:08 +01:00
/*
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.
2021-02-09 12:43:45 +01:00
Copyright (C) 1999-2021 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 ***********************************/
/*****************************************************************************/
2019-12-29 12:39:00 +01:00
#include <stddef.h> // For NULL
2014-12-01 23:55:08 +01:00
#include <stdlib.h> // For calloc
#include <string.h> // For string functions
#include <sys/wait.h> // For the macro WEXITSTATUS
#include <unistd.h> // For access, lstat, getpid, chdir, symlink, unlink
2014-12-12 22:39:55 +01:00
#include "swad_account.h"
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
2014-12-01 23:55:08 +01:00
#include "swad_database.h"
2018-11-09 20:47:39 +01:00
#include "swad_form.h"
2014-12-01 23:55:08 +01:00
#include "swad_global.h"
2019-10-23 19:05:05 +02:00
#include "swad_HTML.h"
2018-12-08 16:43:13 +01:00
#include "swad_language.h"
2014-12-01 23:55:08 +01:00
#include "swad_mail.h"
#include "swad_parameter.h"
#include "swad_QR.h"
2016-10-12 14:02:56 +02:00
#include "swad_tab.h"
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
2017-03-07 01:56:41 +01:00
#define Mai_LENGTH_EMAIL_CONFIRM_KEY Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
2019-04-09 14:04:04 +02:00
static const char *Mai_EMAIL_SECTION_ID = "email_section";
static struct Mail *Mai_EditingMai = NULL; // Static variable to keep the mail domain being edited
2018-10-16 01:36:13 +02:00
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2017-01-29 12:42:19 +01:00
static void Mai_GetParamMaiOrder (void);
2020-04-08 19:42:03 +02:00
static void Mai_PutIconToEditMailDomains (__attribute__((unused)) void *Args);
2019-04-09 14:04:04 +02:00
static void Mai_EditMailDomainsInternal (void);
2014-12-01 23:55:08 +01:00
static void Mai_GetListMailDomainsAllowedForNotif (void);
static void Mai_GetMailDomain (const char *Email,
char MailDomain[Cns_MAX_BYTES_EMAIL_ADDRESS + 1]);
2017-03-13 13:17:53 +01:00
static bool Mai_CheckIfMailDomainIsAllowedForNotif (const char MailDomain[Cns_MAX_BYTES_EMAIL_ADDRESS + 1]);
2016-10-12 14:02:56 +02:00
2014-12-01 23:55:08 +01:00
static void Mai_ListMailDomainsForEdition (void);
2020-10-13 22:34:31 +02:00
static void Mai_PutParamMaiCod (void *MaiCod);
2017-03-09 11:16:17 +01:00
2016-10-28 10:03:37 +02:00
static void Mai_RenameMailDomain (Cns_ShrtOrFullName_t ShrtOrFullName);
2014-12-01 23:55:08 +01:00
static bool Mai_CheckIfMailDomainNameExists (const char *FieldName,const char *Name,long MaiCod);
2017-03-09 11:16:17 +01:00
static void Mai_UpdateMailDomainNameDB (long MaiCod,const char *FieldName,const char *NewMaiName);
2014-12-01 23:55:08 +01:00
static void Mai_PutFormToCreateMailDomain (void);
static void Mai_PutHeadMailDomains (void);
static void Mai_CreateMailDomain (struct Mail *Mai);
2020-04-08 19:42:03 +02:00
static void Mai_PutFormToSelectUsrsToListEmails (__attribute__((unused)) void *Args);
static void Mai_ListEmails (__attribute__((unused)) void *Args);
2019-04-11 21:37:11 +02:00
2020-10-14 00:59:24 +02:00
static void Mai_ShowFormChangeUsrEmail (bool ItsMe,
bool IMustFillInEmail,
bool IShouldConfirmEmail);
static void Mai_PutParamsRemoveMyEmail (void *Email);
static void Mai_PutParamsRemoveOtherEmail (void *Email);
2018-10-15 14:07:12 +02:00
2015-11-16 17:39:59 +01:00
static void Mai_RemoveEmail (struct UsrData *UsrDat);
2017-03-13 13:17:53 +01:00
static void Mai_RemoveEmailFromDB (long UsrCod,const char Email[Cns_MAX_BYTES_EMAIL_ADDRESS + 1]);
2015-11-16 14:54:12 +01:00
static void Mai_NewUsrEmail (struct UsrData *UsrDat,bool ItsMe);
2017-03-13 13:17:53 +01:00
static void Mai_InsertMailKey (const char Email[Cns_MAX_BYTES_EMAIL_ADDRESS + 1],
2017-01-28 15:58:46 +01:00
const char MailKey[Mai_LENGTH_EMAIL_CONFIRM_KEY + 1]);
2014-12-01 23:55:08 +01:00
2019-04-09 14:04:04 +02:00
static void Mai_EditingMailDomainConstructor (void);
static void Mai_EditingMailDomainDestructor (void);
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************* List all the mail domains *************************/
/*****************************************************************************/
void Mai_SeeMailDomains (void)
{
2019-03-12 21:25:55 +01:00
extern const char *Hlp_START_Domains;
2016-11-16 23:19:52 +01:00
extern const char *Txt_Email_domains_allowed_for_notifications;
extern const char *Txt_EMAIL_DOMAIN_HELP_ORDER[3];
extern const char *Txt_EMAIL_DOMAIN_ORDER[3];
2017-01-29 12:42:19 +01:00
Mai_DomainsOrder_t Order;
2014-12-01 23:55:08 +01:00
unsigned NumMai;
/***** Get parameter with the type of order in the list of mail domains *****/
2017-01-29 12:42:19 +01:00
Mai_GetParamMaiOrder ();
2014-12-01 23:55:08 +01:00
/***** Get list of mail domains *****/
Mai_GetListMailDomainsAllowedForNotif ();
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
2020-03-26 02:54:30 +01:00
if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)
Box_BoxTableBegin (NULL,Txt_Email_domains_allowed_for_notifications,
2020-04-08 19:42:03 +02:00
Mai_PutIconToEditMailDomains,NULL,
2020-03-26 02:54:30 +01:00
Hlp_START_Domains,Box_NOT_CLOSABLE,2);
else
Box_BoxTableBegin (NULL,Txt_Email_domains_allowed_for_notifications,
NULL,NULL,
Hlp_START_Domains,Box_NOT_CLOSABLE,2);
2017-06-12 14:16:33 +02:00
/***** Write heading *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2014-12-01 23:55:08 +01:00
for (Order = Mai_ORDER_BY_DOMAIN;
Order <= Mai_ORDER_BY_USERS;
Order++)
{
2019-10-23 19:05:05 +02:00
HTM_TH_Begin (1,1,"LM");
2019-10-13 16:21:05 +02:00
Frm_BeginForm (ActSeeMai);
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) Order);
2019-11-20 10:17:42 +01:00
HTM_BUTTON_SUBMIT_Begin (Txt_EMAIL_DOMAIN_HELP_ORDER[Order],"BT_LINK TIT_TBL",NULL);
2017-01-29 12:42:19 +01:00
if (Order == Gbl.Mails.SelectedOrder)
2019-11-10 16:41:47 +01:00
HTM_U_Begin ();
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_EMAIL_DOMAIN_ORDER[Order]);
2017-01-29 12:42:19 +01:00
if (Order == Gbl.Mails.SelectedOrder)
2019-11-10 16:41:47 +01:00
HTM_U_End ();
2019-11-18 15:48:46 +01:00
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-13 16:21:05 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH_End ();
2014-12-01 23:55:08 +01:00
}
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/***** Write all the mail domains *****/
for (NumMai = 0;
NumMai < Gbl.Mails.Num;
NumMai++)
2019-10-04 14:42:59 +02:00
{
2014-12-01 23:55:08 +01:00
/* Write data of this mail domain */
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 17:36:41 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT LT\"");
2019-11-10 12:36:37 +01:00
HTM_Txt (Gbl.Mails.Lst[NumMai].Domain);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 17:36:41 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT LT\"");
2019-11-10 12:36:37 +01:00
HTM_Txt (Gbl.Mails.Lst[NumMai].Info);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 17:36:41 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RT\"");
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Gbl.Mails.Lst[NumMai].NumUsrs);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 17:36:41 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-10-04 14:42:59 +02:00
}
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableEnd ();
2014-12-01 23:55:08 +01:00
/***** Free list of mail domains *****/
Mai_FreeListMailDomains ();
}
/*****************************************************************************/
/******* Get parameter with the type or order in list of mail domains ********/
/*****************************************************************************/
2017-01-29 12:42:19 +01:00
static void Mai_GetParamMaiOrder (void)
2014-12-01 23:55:08 +01:00
{
2017-01-29 12:42:19 +01:00
Gbl.Mails.SelectedOrder = (Mai_DomainsOrder_t)
2017-01-29 21:41:08 +01:00
Par_GetParToUnsignedLong ("Order",
0,
Mai_NUM_ORDERS - 1,
(unsigned long) Mai_ORDER_DEFAULT);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2016-03-19 00:40:20 +01:00
/************************ Put icon to edit mail domains **********************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2020-04-08 19:42:03 +02:00
static void Mai_PutIconToEditMailDomains (__attribute__((unused)) void *Args)
2014-12-01 23:55:08 +01:00
{
2020-04-08 19:42:03 +02:00
Ico_PutContextualIconToEdit (ActEdiMai,NULL,
NULL,NULL);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********************** Put forms to edit mail domains **********************/
/*****************************************************************************/
void Mai_EditMailDomains (void)
2019-04-09 14:04:04 +02:00
{
/***** Mail domain constructor *****/
Mai_EditingMailDomainConstructor ();
/***** Edit mail domains *****/
Mai_EditMailDomainsInternal ();
/***** Mail domain destructor *****/
Mai_EditingMailDomainDestructor ();
}
static void Mai_EditMailDomainsInternal (void)
2014-12-01 23:55:08 +01:00
{
/***** Get list of mail domains *****/
Mai_GetListMailDomainsAllowedForNotif ();
/***** Put a form to create a new mail *****/
Mai_PutFormToCreateMailDomain ();
/***** Forms to edit current mail domains *****/
if (Gbl.Mails.Num)
Mai_ListMailDomainsForEdition ();
/***** Free list of mail domains *****/
Mai_FreeListMailDomains ();
}
/*****************************************************************************/
/************************* List all the mail domains *************************/
/*****************************************************************************/
static void Mai_GetListMailDomainsAllowedForNotif (void)
{
2019-01-03 15:25:18 +01:00
static const char *OrderBySubQuery[Mai_NUM_ORDERS] =
{
[Mai_ORDER_BY_DOMAIN] = "Domain,"
"Info,"
"N DESC",
[Mai_ORDER_BY_INFO ] = "Info,"
"Domain,"
"N DESC",
[Mai_ORDER_BY_USERS ] = "N DESC,"
"Info,"
"Domain",
2019-01-03 15:25:18 +01:00
};
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumMai;
struct Mail *Mai;
// Query uses temporary tables for speed
// Query uses two identical temporary tables...
// ...because a unique temporary table can not be used twice in the same query
/***** Create temporary table with all the mail domains present in users' emails table *****/
2018-11-02 22:41:02 +01:00
DB_Query ("can not remove temporary tables",
"DROP TEMPORARY TABLE IF EXISTS T1,T2");
2014-12-01 23:55:08 +01:00
2018-11-02 22:41:02 +01:00
DB_Query ("can not create temporary table",
"CREATE TEMPORARY TABLE T1 ENGINE=MEMORY"
" SELECT SUBSTRING_INDEX(E_mail,'@',-1) AS Domain,COUNT(*) as N"
" FROM usr_emails"
" GROUP BY Domain");
2014-12-01 23:55:08 +01:00
2018-11-02 22:41:02 +01:00
DB_Query ("can not create temporary table",
"CREATE TEMPORARY TABLE T2 ENGINE=MEMORY"
" SELECT *"
" FROM T1");
2014-12-01 23:55:08 +01:00
/***** Get mail domains from database *****/
Gbl.Mails.Num = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get mail domains",
"(SELECT ntf_mail_domains.MaiCod," // row[0]
"ntf_mail_domains.Domain AS Domain," // row[1]
"ntf_mail_domains.Info AS Info," // row[2]
"T1.N AS N" // row[3]
" FROM ntf_mail_domains,T1"
" WHERE ntf_mail_domains.Domain=T1.Domain COLLATE 'latin1_bin')"
" UNION "
"(SELECT MaiCod," // row[0]
"Domain," // row[1]
"Info," // row[2]
"0 AS N" // row[3]
" FROM ntf_mail_domains"
" WHERE Domain NOT IN"
" (SELECT Domain COLLATE 'latin1_bin'"
" FROM T2))"
" ORDER BY %s", // COLLATE necessary to avoid error in comparisons
OrderBySubQuery[Gbl.Mails.SelectedOrder]);
if (Gbl.Mails.Num) // Mail domains found...
2014-12-01 23:55:08 +01:00
{
/***** Create list with places *****/
if ((Gbl.Mails.Lst = calloc ((size_t) Gbl.Mails.Num,
sizeof (*Gbl.Mails.Lst))) == NULL)
2018-10-18 20:06:54 +02:00
Lay_NotEnoughMemoryExit ();
2014-12-01 23:55:08 +01:00
/***** Get the mail domains *****/
for (NumMai = 0;
NumMai < Gbl.Mails.Num;
NumMai++)
{
Mai = &(Gbl.Mails.Lst[NumMai]);
/* Get next mail */
row = mysql_fetch_row (mysql_res);
/* Get mail code (row[0]) */
if ((Mai->MaiCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
Lay_WrongMailDomainExit ();
2014-12-01 23:55:08 +01:00
/* Get the mail domain (row[1]) and the mail domain info (row[2]) */
Str_Copy (Mai->Domain,row[1],sizeof (Mai->Domain) - 1);
Str_Copy (Mai->Info ,row[2],sizeof (Mai->Info ) - 1);
2014-12-01 23:55:08 +01:00
/* Get number of users (row[3]) */
if (sscanf (row[3],"%u",&(Mai->NumUsrs)) != 1)
Mai->NumUsrs = 0;
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** Drop temporary table *****/
2018-11-02 22:41:02 +01:00
DB_Query ("can not remove temporary tables",
"DROP TEMPORARY TABLE IF EXISTS T1,"
"T2");
2014-12-01 23:55:08 +01:00
}
2016-10-12 14:02:56 +02:00
/*****************************************************************************/
2016-11-16 23:19:52 +01:00
/************ Check if user can receive notifications via email **************/
2016-10-12 14:02:56 +02:00
/*****************************************************************************/
bool Mai_CheckIfUsrCanReceiveEmailNotif (const struct UsrData *UsrDat)
{
2017-03-13 13:17:53 +01:00
char MailDomain[Cns_MAX_BYTES_EMAIL_ADDRESS + 1];
2016-10-12 14:02:56 +02:00
2016-11-16 23:19:52 +01:00
/***** Check #1: is my email address confirmed? *****/
2016-10-12 14:02:56 +02:00
if (!UsrDat->EmailConfirmed)
return false;
/***** Check #2: if my mail domain allowed? *****/
2017-03-07 11:03:05 +01:00
Mai_GetMailDomain (UsrDat->Email,MailDomain);
2016-10-12 14:02:56 +02:00
return Mai_CheckIfMailDomainIsAllowedForNotif (MailDomain);
}
2017-01-17 03:10:43 +01:00
/*****************************************************************************/
/********************** Get mailbox from email address ***********************/
/*****************************************************************************/
static void Mai_GetMailDomain (const char *Email,
char MailDomain[Cns_MAX_BYTES_EMAIL_ADDRESS + 1])
2017-01-17 03:10:43 +01:00
{
const char *Ptr;
2017-03-07 11:03:05 +01:00
MailDomain[0] = '\0'; // Return empty mailbox on error
2017-01-17 03:10:43 +01:00
if ((Ptr = strchr (Email,(int) '@'))) // Find first '@' in address
if (Ptr != Email) // '@' is not the first character in Email
{
Ptr++; // Skip '@'
if (strchr (Ptr,(int) '@') == NULL) // No more '@' found
Str_Copy (MailDomain,Ptr,Cns_MAX_BYTES_EMAIL_ADDRESS);
2017-01-17 03:10:43 +01:00
}
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************ Check if a mail domain is allowed for notifications ************/
/*****************************************************************************/
2017-03-13 13:17:53 +01:00
static bool Mai_CheckIfMailDomainIsAllowedForNotif (const char MailDomain[Cns_MAX_BYTES_EMAIL_ADDRESS + 1])
2014-12-01 23:55:08 +01:00
{
/***** Get number of mail_domains with a name from database *****/
2018-11-03 20:52:00 +01:00
return (DB_QueryCOUNT ("can not check if a mail domain"
" is allowed for notifications",
"SELECT COUNT(*)"
" FROM ntf_mail_domains"
2018-11-03 20:52:00 +01:00
" WHERE Domain='%s'",
MailDomain) != 0);
2014-12-01 23:55:08 +01:00
}
2016-10-12 14:02:56 +02:00
/*****************************************************************************/
2016-11-16 23:19:52 +01:00
/***************** Show warning about notifications via email ****************/
2016-10-12 14:02:56 +02:00
/*****************************************************************************/
void Mai_WriteWarningEmailNotifications (void)
{
extern const char *Txt_You_can_only_receive_email_notifications_if_;
2016-12-28 17:22:25 +01:00
extern const char *Txt_TABS_TXT[Tab_NUM_TABS];
2016-10-12 14:02:56 +02:00
extern const char *Txt_MENU_TITLE[Tab_NUM_TABS][Act_MAX_OPTIONS_IN_MENU_PER_TAB];
2017-03-24 20:07:29 +01:00
extern const char *Txt_Domains;
2018-04-24 13:21:53 +02:00
Tab_Tab_t TabMyAccount = Act_GetTab (ActFrmMyAcc );
Tab_Tab_t TabMailDomains = Act_GetTab (ActSeeMai);
2016-10-12 14:02:56 +02:00
2019-02-16 17:20:05 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_can_only_receive_email_notifications_if_,
Txt_TABS_TXT [TabMyAccount ],
Txt_MENU_TITLE[TabMyAccount ][Act_GetIndexInMenu (ActFrmMyAcc)],
Txt_TABS_TXT [TabMailDomains],
Txt_MENU_TITLE[TabMailDomains][Act_GetIndexInMenu (ActSeeMai )],
Txt_Domains);
2016-10-12 14:02:56 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/**************************** Get mail domain data ***************************/
/*****************************************************************************/
void Mai_GetDataOfMailDomainByCod (struct Mail *Mai)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
/***** Clear data *****/
Mai->Domain[0] = Mai->Info[0] = '\0';
/***** Check if mail code is correct *****/
if (Mai->MaiCod > 0)
{
/***** Get data of a mail domain from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get data of a mail domain",
"SELECT Domain," // row[0]
"Info" // row[1]
" FROM ntf_mail_domains"
" WHERE MaiCod=%ld",
Mai->MaiCod)) // Mail found...
2014-12-01 23:55:08 +01:00
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get the short & full name of the mail (row[0], row[1]) */
Str_Copy (Mai->Domain,row[0],sizeof (Mai->Domain) - 1);
Str_Copy (Mai->Info ,row[1],sizeof (Mai->Info ) - 1);
2014-12-01 23:55:08 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
}
/*****************************************************************************/
/************************** Free list of mail domains ************************/
/*****************************************************************************/
void Mai_FreeListMailDomains (void)
{
if (Gbl.Mails.Lst)
{
/***** Free memory used by the list of mail domains *****/
2019-11-06 19:45:20 +01:00
free (Gbl.Mails.Lst);
2014-12-01 23:55:08 +01:00
Gbl.Mails.Lst = NULL;
Gbl.Mails.Num = 0;
}
}
/*****************************************************************************/
/************************ List all the mail domains **************************/
/*****************************************************************************/
static void Mai_ListMailDomainsForEdition (void)
{
2019-03-12 21:25:55 +01:00
extern const char *Hlp_START_Domains_edit;
2016-11-16 23:19:52 +01:00
extern const char *Txt_Email_domains_allowed_for_notifications;
2014-12-01 23:55:08 +01:00
unsigned NumMai;
struct Mail *Mai;
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
2020-03-26 02:54:30 +01:00
Box_BoxTableBegin (NULL,Txt_Email_domains_allowed_for_notifications,
NULL,NULL,
2019-03-12 21:25:55 +01:00
Hlp_START_Domains_edit,Box_NOT_CLOSABLE,2);
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** Write heading *****/
2014-12-01 23:55:08 +01:00
Mai_PutHeadMailDomains ();
/***** Write all the mail domains *****/
for (NumMai = 0;
NumMai < Gbl.Mails.Num;
NumMai++)
{
Mai = &Gbl.Mails.Lst[NumMai];
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-09 15:09:42 +02:00
/* Put icon to remove mail */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"BM\"");
2020-10-13 22:34:31 +02:00
Ico_PutContextualIconToRemove (ActRemMai,NULL,
Mai_PutParamMaiCod,&Mai->MaiCod);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Mail code */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2019-11-10 13:38:17 +01:00
HTM_Long (Mai->MaiCod);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Mail domain */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"CM\"");
Frm_BeginForm (ActRenMaiSho);
2020-10-13 22:34:31 +02:00
Mai_PutParamMaiCod (&Mai->MaiCod);
2020-04-27 03:16:55 +02:00
HTM_INPUT_TEXT ("Domain",Cns_MAX_CHARS_EMAIL_ADDRESS,Mai->Domain,
HTM_SUBMIT_ON_CHANGE,
2019-11-04 12:25:48 +01:00
"size=\"15\"");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Mail domain info */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"CM\"");
Frm_BeginForm (ActRenMaiFul);
2020-10-13 22:34:31 +02:00
Mai_PutParamMaiCod (&Mai->MaiCod);
2020-04-27 03:16:55 +02:00
HTM_INPUT_TEXT ("Info",Mai_MAX_CHARS_MAIL_INFO,Mai->Info,
HTM_SUBMIT_ON_CHANGE,
2019-11-04 12:25:48 +01:00
"size=\"40\"");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Number of users */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Mai->NumUsrs);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 17:36:41 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableEnd ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Write parameter with code of mail **********************/
/*****************************************************************************/
2020-10-13 22:34:31 +02:00
static void Mai_PutParamMaiCod (void *MaiCod)
2014-12-01 23:55:08 +01:00
{
2020-10-13 22:34:31 +02:00
if (MaiCod)
Par_PutHiddenParamLong (NULL,"MaiCod",*((long *) MaiCod));
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********************** Get parameter with code of mail *********************/
/*****************************************************************************/
long Mai_GetParamMaiCod (void)
{
2017-01-28 20:32:50 +01:00
/***** Get code of mail *****/
return Par_GetParToLong ("MaiCod");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************************* Remove a mail *******************************/
/*****************************************************************************/
void Mai_RemoveMailDomain (void)
{
2016-11-16 23:19:52 +01:00
extern const char *Txt_Email_domain_X_removed;
2019-04-09 14:04:04 +02:00
/***** Mail domain constructor *****/
Mai_EditingMailDomainConstructor ();
2014-12-01 23:55:08 +01:00
/***** Get mail code *****/
if ((Mai_EditingMai->MaiCod = Mai_GetParamMaiCod ()) <= 0)
Lay_WrongMailDomainExit ();
2014-12-01 23:55:08 +01:00
/***** Get data of the mail from database *****/
2019-04-09 14:04:04 +02:00
Mai_GetDataOfMailDomainByCod (Mai_EditingMai);
2014-12-01 23:55:08 +01:00
/***** Remove mail *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove a mail domain",
"DELETE FROM ntf_mail_domains"
" WHERE MaiCod=%ld",
2019-04-09 14:04:04 +02:00
Mai_EditingMai->MaiCod);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2019-04-09 14:04:04 +02:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_Email_domain_X_removed,
Mai_EditingMai->Domain);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Change the short name of a mail ***********************/
/*****************************************************************************/
void Mai_RenameMailDomainShort (void)
{
2019-04-09 14:04:04 +02:00
/***** Mail domain constructor *****/
Mai_EditingMailDomainConstructor ();
/***** Rename mail domain *****/
2016-10-28 10:03:37 +02:00
Mai_RenameMailDomain (Cns_SHRT_NAME);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Change the full name of a mail ************************/
/*****************************************************************************/
void Mai_RenameMailDomainFull (void)
{
2019-04-09 14:04:04 +02:00
/***** Mail domain constructor *****/
Mai_EditingMailDomainConstructor ();
/***** Rename mail domain *****/
2014-12-01 23:55:08 +01:00
Mai_RenameMailDomain (Cns_FULL_NAME);
}
/*****************************************************************************/
2016-10-28 10:03:37 +02:00
/************************* Change the name of a mail *************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-10-28 10:03:37 +02:00
static void Mai_RenameMailDomain (Cns_ShrtOrFullName_t ShrtOrFullName)
2014-12-01 23:55:08 +01:00
{
2016-11-16 23:19:52 +01:00
extern const char *Txt_The_email_domain_X_already_exists;
extern const char *Txt_The_email_domain_X_has_been_renamed_as_Y;
extern const char *Txt_The_email_domain_X_has_not_changed;
2014-12-01 23:55:08 +01:00
const char *ParamName = NULL; // Initialized to avoid warning
const char *FieldName = NULL; // Initialized to avoid warning
2017-03-07 19:55:29 +01:00
unsigned MaxBytes = 0; // Initialized to avoid warning
2014-12-01 23:55:08 +01:00
char *CurrentMaiName = NULL; // Initialized to avoid warning
2017-03-07 19:55:29 +01:00
char NewMaiName[Mai_MAX_BYTES_MAIL_INFO + 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 = "Domain";
FieldName = "Domain";
2017-03-13 13:17:53 +01:00
MaxBytes = Cns_MAX_BYTES_EMAIL_ADDRESS;
2019-04-09 14:04:04 +02:00
CurrentMaiName = Mai_EditingMai->Domain;
2014-12-01 23:55:08 +01:00
break;
case Cns_FULL_NAME:
ParamName = "Info";
FieldName = "Info";
2017-03-07 19:55:29 +01:00
MaxBytes = Mai_MAX_BYTES_MAIL_INFO;
2019-04-09 14:04:04 +02:00
CurrentMaiName = Mai_EditingMai->Info;
2014-12-01 23:55:08 +01:00
break;
}
/***** Get parameters from form *****/
/* Get the code of the mail */
if ((Mai_EditingMai->MaiCod = Mai_GetParamMaiCod ()) <= 0)
Lay_WrongMailDomainExit ();
2014-12-01 23:55:08 +01:00
/* Get the new name for the mail */
2017-03-07 19:55:29 +01:00
Par_GetParToText (ParamName,NewMaiName,MaxBytes);
2014-12-01 23:55:08 +01:00
/***** Get from the database the old names of the mail *****/
2019-04-09 14:04:04 +02:00
Mai_GetDataOfMailDomainByCod (Mai_EditingMai);
2014-12-01 23:55:08 +01:00
/***** Check if new name is empty *****/
2019-12-20 00:30:54 +01:00
if (NewMaiName[0])
2014-12-01 23:55:08 +01:00
{
2019-01-02 15:10:51 +01:00
/***** Check if old and new names are the same
(this happens when return is pressed without changes) *****/
2014-12-01 23:55:08 +01:00
if (strcmp (CurrentMaiName,NewMaiName)) // Different names
{
/***** If mail was in database... *****/
2019-04-09 14:04:04 +02:00
if (Mai_CheckIfMailDomainNameExists (ParamName,NewMaiName,Mai_EditingMai->MaiCod))
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_WARNING,Mai_EMAIL_SECTION_ID,
Txt_The_email_domain_X_already_exists,
NewMaiName);
2014-12-01 23:55:08 +01:00
else
{
/* Update the table changing old name by new name */
2019-04-09 14:04:04 +02:00
Mai_UpdateMailDomainNameDB (Mai_EditingMai->MaiCod,FieldName,NewMaiName);
2014-12-01 23:55:08 +01:00
2017-03-09 11:16:17 +01:00
/* Write message to show the change made */
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_SUCCESS,Mai_EMAIL_SECTION_ID,
Txt_The_email_domain_X_has_been_renamed_as_Y,
CurrentMaiName,NewMaiName);
2014-12-01 23:55:08 +01:00
}
}
else // The same name
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_INFO,Mai_EMAIL_SECTION_ID,
Txt_The_email_domain_X_has_not_changed,
CurrentMaiName);
2014-12-01 23:55:08 +01:00
}
2019-12-20 00:30:54 +01:00
else
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
2014-12-01 23:55:08 +01:00
2019-04-09 14:04:04 +02:00
/***** Update name *****/
Str_Copy (CurrentMaiName,NewMaiName,MaxBytes);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************** Check if the name of mail exists *********************/
/*****************************************************************************/
static bool Mai_CheckIfMailDomainNameExists (const char *FieldName,const char *Name,long MaiCod)
{
/***** Get number of mail_domains with a name from database *****/
2018-11-03 20:52:00 +01:00
return (DB_QueryCOUNT ("can not check if the name"
" of a mail domain already existed",
"SELECT COUNT(*)"
" FROM ntf_mail_domains"
" WHERE %s='%s'"
" AND MaiCod<>%ld",
2018-11-03 20:52:00 +01:00
FieldName,Name,MaiCod) != 0);
2014-12-01 23:55:08 +01:00
}
2017-03-09 11:16:17 +01:00
/*****************************************************************************/
/****************** Update name in table of mail domains *********************/
/*****************************************************************************/
static void Mai_UpdateMailDomainNameDB (long MaiCod,const char *FieldName,const char *NewMaiName)
{
/***** Update mail domain changing old name by new name */
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the name of a mail domain",
"UPDATE ntf_mail_domains"
" SET %s='%s'"
" WHERE MaiCod=%ld",
FieldName,NewMaiName,
MaiCod);
2017-03-09 11:16:17 +01:00
}
2019-04-09 14:04:04 +02:00
/*****************************************************************************/
/******* Show alerts after changing a mail domain and continue editing *******/
/*****************************************************************************/
void Mai_ContEditAfterChgMai (void)
{
/***** Write message to show the change made *****/
Ale_ShowAlerts (NULL);
/***** Show the form again *****/
Mai_EditMailDomainsInternal ();
/***** Mail domain destructor *****/
Mai_EditingMailDomainDestructor ();
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/*********************** Put a form to create a new mail *********************/
/*****************************************************************************/
static void Mai_PutFormToCreateMailDomain (void)
{
2019-03-12 21:25:55 +01:00
extern const char *Hlp_START_Domains_edit;
2016-11-16 23:19:52 +01:00
extern const char *Txt_New_email_domain;
extern const char *Txt_EMAIL_DOMAIN_ORDER[3];
extern const char *Txt_Create_email_domain;
2014-12-01 23:55:08 +01:00
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
Frm_BeginForm (ActNewMai);
2014-12-01 23:55:08 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
2020-03-26 02:54:30 +01:00
Box_BoxTableBegin (NULL,Txt_New_email_domain,
NULL,NULL,
2019-03-12 21:25:55 +01:00
Hlp_START_Domains_edit,Box_NOT_CLOSABLE,2);
2014-12-01 23:55:08 +01:00
/***** Write heading *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-12 00:07:52 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH (1,1,"LM",Txt_EMAIL_DOMAIN_ORDER[Mai_ORDER_BY_DOMAIN]);
HTM_TH (1,1,"LM",Txt_EMAIL_DOMAIN_ORDER[Mai_ORDER_BY_INFO]);
2019-10-12 00:07:52 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-05 13:27:58 +02:00
/***** Mail domain *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"CM\"");
2020-04-27 03:16:55 +02:00
HTM_INPUT_TEXT ("Domain",Cns_MAX_CHARS_EMAIL_ADDRESS,Mai_EditingMai->Domain,
HTM_DONT_SUBMIT_ON_CHANGE,
2019-11-04 09:45:57 +01:00
"size=\"15\" required=\"required\"");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Mail domain info *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"CM\"");
2020-04-27 03:16:55 +02:00
HTM_INPUT_TEXT ("Info",Mai_MAX_CHARS_MAIL_INFO,Mai_EditingMai->Info,
HTM_DONT_SUBMIT_ON_CHANGE,
2019-11-04 09:45:57 +01:00
"size=\"40\" required=\"required\"");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TD_Empty (1);
2019-10-05 13:27:58 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End table, send button and end box *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create_email_domain);
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Write header with fields of a mail ********************/
/*****************************************************************************/
static void Mai_PutHeadMailDomains (void)
{
extern const char *Txt_Code;
2016-11-16 23:19:52 +01:00
extern const char *Txt_EMAIL_DOMAIN_ORDER[3];
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-12 00:07:52 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH (1,1,"BM",NULL);
HTM_TH (1,1,"RM",Txt_Code);
HTM_TH (1,1,"LM",Txt_EMAIL_DOMAIN_ORDER[Mai_ORDER_BY_DOMAIN]);
HTM_TH (1,1,"LM",Txt_EMAIL_DOMAIN_ORDER[Mai_ORDER_BY_INFO ]);
HTM_TH (1,1,"RM",Txt_EMAIL_DOMAIN_ORDER[Mai_ORDER_BY_USERS ]);
2019-10-12 00:07:52 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Receive form to create a new mail ***********************/
/*****************************************************************************/
2020-05-05 21:49:00 +02:00
void Mai_ReceiveFormNewMailDomain (void)
2014-12-01 23:55:08 +01:00
{
2016-11-16 23:19:52 +01:00
extern const char *Txt_The_email_domain_X_already_exists;
2019-04-09 14:04:04 +02:00
extern const char *Txt_Created_new_email_domain_X;
2016-11-16 23:19:52 +01:00
extern const char *Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_email_domain;
2014-12-01 23:55:08 +01:00
2019-04-09 14:04:04 +02:00
/***** Mail domain constructor *****/
Mai_EditingMailDomainConstructor ();
2014-12-01 23:55:08 +01:00
/***** Get parameters from form *****/
/* Get mail short name */
2019-04-09 14:04:04 +02:00
Par_GetParToText ("Domain",Mai_EditingMai->Domain,Cns_MAX_BYTES_EMAIL_ADDRESS);
2014-12-01 23:55:08 +01:00
/* Get mail full name */
2019-04-09 14:04:04 +02:00
Par_GetParToText ("Info",Mai_EditingMai->Info,Mai_MAX_BYTES_MAIL_INFO);
2014-12-01 23:55:08 +01:00
2019-04-09 14:04:04 +02:00
if (Mai_EditingMai->Domain[0] &&
Mai_EditingMai->Info[0]) // If there's a mail name
2014-12-01 23:55:08 +01:00
{
/***** If name of mail was in database... *****/
2019-04-09 14:04:04 +02:00
if (Mai_CheckIfMailDomainNameExists ("Domain",Mai_EditingMai->Domain,-1L))
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_email_domain_X_already_exists,
Mai_EditingMai->Domain);
else if (Mai_CheckIfMailDomainNameExists ("Info",Mai_EditingMai->Info,-1L))
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_email_domain_X_already_exists,
Mai_EditingMai->Info);
2014-12-01 23:55:08 +01:00
else // Add new mail to database
2019-04-09 14:04:04 +02:00
{
Mai_CreateMailDomain (Mai_EditingMai);
Ale_ShowAlert (Ale_SUCCESS,Txt_Created_new_email_domain_X,
Mai_EditingMai->Domain);
}
2014-12-01 23:55:08 +01:00
}
else // If there is not a mail name
2019-04-09 14:04:04 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_email_domain);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************** Create a new mail domain *************************/
/*****************************************************************************/
static void Mai_CreateMailDomain (struct Mail *Mai)
{
/***** Create a new mail *****/
2018-11-02 19:37:11 +01:00
DB_QueryINSERT ("can not create mail domain",
"INSERT INTO ntf_mail_domains"
2018-11-02 19:37:11 +01:00
" (Domain,Info)"
" VALUES"
" ('%s','%s')",
Mai->Domain,
Mai->Info);
2014-12-01 23:55:08 +01:00
}
2019-04-11 21:37:11 +02:00
/*****************************************************************************/
2020-04-08 19:42:03 +02:00
/************************ Request users to list emails ***********************/
2019-04-11 21:37:11 +02:00
/*****************************************************************************/
2020-04-08 19:42:03 +02:00
void Mai_ReqUsrsToListEmails (void)
{
Mai_PutFormToSelectUsrsToListEmails (NULL);
}
static void Mai_PutFormToSelectUsrsToListEmails (__attribute__((unused)) void *Args)
2019-04-11 21:37:11 +02:00
{
2020-09-26 17:20:01 +02:00
extern const char *Hlp_COMMUNICATION_Email;
2019-04-11 23:15:40 +02:00
extern const char *Txt_Email;
2019-04-11 21:37:11 +02:00
extern const char *Txt_View_email_addresses;
2020-04-08 19:42:03 +02:00
/***** List users to select some of them *****/
Usr_PutFormToSelectUsrsToGoToAct (&Gbl.Usrs.Selected,
ActMaiUsr,
NULL,NULL,
Txt_Email,
2020-09-26 17:20:01 +02:00
Hlp_COMMUNICATION_Email,
2020-04-08 19:42:03 +02:00
Txt_View_email_addresses,
false); // Do not put form with date range
2019-04-11 21:37:11 +02:00
}
/*****************************************************************************/
/****** Get and check list of selected users, and show users' emails ********/
/*****************************************************************************/
void Mai_GetSelUsrsAndListEmails (void)
2019-04-11 21:37:11 +02:00
{
2019-11-15 03:34:48 +01:00
Usr_GetSelectedUsrsAndGoToAct (&Gbl.Usrs.Selected,
2020-04-08 19:42:03 +02:00
Mai_ListEmails,NULL, // when user(s) selected
Mai_PutFormToSelectUsrsToListEmails,NULL); // when no user selected
2019-04-11 21:37:11 +02:00
}
2016-07-01 11:38:53 +02:00
/*****************************************************************************/
2016-11-16 23:19:52 +01:00
/****** List the emails of all the students to creates an email message ******/
2016-07-01 11:38:53 +02:00
/*****************************************************************************/
2017-03-07 19:55:29 +01:00
#define Mai_MAX_BYTES_STR_ADDR (256 * 1024 - 1)
2016-07-01 11:38:53 +02:00
2020-04-08 19:42:03 +02:00
static void Mai_ListEmails (__attribute__((unused)) void *Args)
2016-07-01 11:38:53 +02:00
{
2020-09-26 17:20:01 +02:00
extern const char *Hlp_COMMUNICATION_Email;
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormOutBoxBold[The_NUM_THEMES];
2019-04-11 21:37:11 +02:00
extern const char *Txt_Email_addresses;
extern const char *Txt_X_users_who_have_email;
extern const char *Txt_X_users_who_have_accepted_and_who_have_email;
2016-11-16 23:19:52 +01:00
extern const char *Txt_Create_email_message;
2019-04-11 21:37:11 +02:00
unsigned NumUsrsWithEmail = 0;
unsigned NumAcceptedUsrsWithEmail = 0;
2017-03-07 19:55:29 +01:00
char StrAddresses[Mai_MAX_BYTES_STR_ADDR + 1]; // TODO: Use malloc depending on the number of students
2016-07-01 11:38:53 +02:00
unsigned int LengthStrAddr = 0;
struct UsrData UsrDat;
2019-04-11 21:37:11 +02:00
const char *Ptr;
2016-07-01 11:38:53 +02:00
2017-06-12 14:16:33 +02:00
/***** Start the box used to list the emails *****/
2020-03-26 02:54:30 +01:00
Box_BoxBegin (NULL,Txt_Email_addresses,
NULL,NULL,
2020-09-26 17:20:01 +02:00
Hlp_COMMUNICATION_Email,Box_NOT_CLOSABLE);
2016-11-25 03:21:02 +01:00
2019-04-11 21:37:11 +02:00
/***** Start list with users' email addresses *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"DAT_SMALL CM\"");
2017-05-25 11:04:38 +02:00
2019-04-11 21:37:11 +02:00
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
2016-11-25 03:21:02 +01:00
2019-04-11 21:37:11 +02:00
/***** Get email addresses of the selected users *****/
StrAddresses[0] = '\0';
Ptr = Gbl.Usrs.Selected.List[Rol_UNK];
while (*Ptr)
2016-07-01 11:38:53 +02:00
{
2019-04-11 21:37:11 +02:00
/* Get next user */
Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EnUsrCod,
2019-04-11 21:37:11 +02:00
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat);
2016-07-26 02:41:31 +02:00
2019-04-11 21:37:11 +02:00
/* Get user's email */
Mai_GetEmailFromUsrCod (&UsrDat);
2016-07-26 02:41:31 +02:00
2019-04-11 21:37:11 +02:00
if (UsrDat.Email[0])
{
NumUsrsWithEmail++;
/* Check if users has accepted inscription in current course */
UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&UsrDat);
if (UsrDat.Accepted) // If student has email and has accepted
{
if (NumAcceptedUsrsWithEmail > 0)
2016-07-26 02:41:31 +02:00
{
2019-11-10 16:41:47 +01:00
HTM_Txt (", ");
2019-04-11 21:37:11 +02:00
LengthStrAddr ++;
if (LengthStrAddr > Mai_MAX_BYTES_STR_ADDR)
Lay_ShowErrorAndExit ("The space allocated to store email addresses is full.");
Str_Concat (StrAddresses,",",sizeof (StrAddresses) - 1);
2016-07-26 02:41:31 +02:00
}
2019-04-11 21:37:11 +02:00
LengthStrAddr += strlen (UsrDat.Email);
if (LengthStrAddr > Mai_MAX_BYTES_STR_ADDR)
Lay_ShowErrorAndExit ("The space allocated to store email addresses is full.");
Str_Concat (StrAddresses,UsrDat.Email,sizeof (StrAddresses) - 1);
2019-10-28 20:38:29 +01:00
HTM_A_Begin ("href=\"mailto:%s?subject=%s\"",
UsrDat.Email,Gbl.Hierarchy.Crs.FullName);
2019-11-10 12:36:37 +01:00
HTM_Txt (UsrDat.Email);
2019-10-28 13:56:04 +01:00
HTM_A_End ();
2019-04-11 21:37:11 +02:00
NumAcceptedUsrsWithEmail++;
}
}
2016-07-01 11:38:53 +02:00
}
2019-04-11 21:37:11 +02:00
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
/***** End list with users' email addresses *****/
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-04-11 21:37:11 +02:00
/***** Show a message with the number of users with email ****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"DAT CM\"");
2019-11-11 00:15:44 +01:00
HTM_TxtF (Txt_X_users_who_have_email,NumUsrsWithEmail);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-04-11 21:37:11 +02:00
/***** Show a message with the number of users who have accepted and have email ****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"DAT CM\"");
2019-11-11 00:15:44 +01:00
HTM_TxtF (Txt_X_users_who_have_accepted_and_who_have_email,
NumAcceptedUsrsWithEmail);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-04-11 21:37:11 +02:00
2019-10-24 09:46:20 +02:00
/***** Contextual menu *****/
Mnu_ContextMenuBegin ();
/* Open the client email program */
2019-10-28 20:38:29 +01:00
HTM_A_Begin ("href=\"mailto:%s?subject=%s&cc=%s&bcc=%s\""
" title=\"%s\" class=\"%s\"",
Gbl.Usrs.Me.UsrDat.Email,
Gbl.Hierarchy.Crs.FullName,
Gbl.Usrs.Me.UsrDat.Email,
StrAddresses,
Txt_Create_email_message,
The_ClassFormOutBoxBold[Gbl.Prefs.Theme]);
2019-04-11 21:37:11 +02:00
Ico_PutIconTextLink ("marker.svg",
Txt_Create_email_message);
2019-10-28 13:56:04 +01:00
HTM_A_End ();
2019-10-24 09:46:20 +02:00
Mnu_ContextMenuEnd ();
2017-05-25 11:04:38 +02:00
2017-06-12 14:16:33 +02:00
/***** End the box used to list the emails *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2016-07-01 11:38:53 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-11-16 23:19:52 +01:00
/**************** Check whether an email address if valid ********************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
bool Mai_CheckIfEmailIsValid (const char *Email)
{
unsigned Length = strlen (Email);
unsigned LastPosArroba = Length - 4;
const char *Ptr;
unsigned Pos;
bool ArrobaFound = false;
2016-11-16 23:19:52 +01:00
/***** An email address must have a number of characters
2017-03-13 13:17:53 +01:00
5 <= Length <= Cns_MAX_BYTES_EMAIL_ADDRESS *****/
2014-12-01 23:55:08 +01:00
if (Length < 5 ||
2017-03-13 13:17:53 +01:00
Length > Cns_MAX_BYTES_EMAIL_ADDRESS)
2014-12-01 23:55:08 +01:00
return false;
2016-11-16 23:19:52 +01:00
/***** An email address can have digits, letters, '.', '-' and '_';
2014-12-01 23:55:08 +01:00
and must have one and only '@' (not in any position) *****/
for (Ptr = Email, Pos = 0;
*Ptr;
Ptr++)
if ((*Ptr >= 'a' && *Ptr <= 'z') ||
(*Ptr >= 'A' && *Ptr <= 'Z') ||
(*Ptr >= '0' && *Ptr <= '9') ||
*Ptr == '.' ||
*Ptr == '-' ||
*Ptr == '_')
Pos++;
else if (*Ptr == '@')
{
if (ArrobaFound)
return false;
/* Example: a@b.c
01234
Length = 5
LastPosArroba = 5 - 4 = 1 */
if (Pos == 0 || Pos > LastPosArroba)
return false;
ArrobaFound = true;
}
else
return false;
return ArrobaFound;
}
/*****************************************************************************/
2016-11-16 23:19:52 +01:00
/********** Get email address of a user from his/her user's code *************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2015-11-16 14:54:12 +01:00
bool Mai_GetEmailFromUsrCod (struct UsrData *UsrDat)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
bool Found;
/***** Get current (last updated) user's nickname from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get email address",
"SELECT E_mail," // row[0]
"Confirmed" // row[1]
" FROM usr_emails"
" WHERE UsrCod=%ld"
" ORDER BY CreatTime DESC"
" LIMIT 1",
UsrDat->UsrCod) == 0)
2014-12-01 23:55:08 +01:00
{
2015-11-16 14:54:12 +01:00
UsrDat->Email[0] = '\0';
UsrDat->EmailConfirmed = false;
2014-12-01 23:55:08 +01:00
Found = false;
}
else
{
2016-11-16 23:19:52 +01:00
/* Get email */
2017-01-15 18:02:52 +01:00
row = mysql_fetch_row (mysql_res);
Str_Copy (UsrDat->Email,row[0],sizeof (UsrDat->Email) - 1);
2016-09-07 18:48:10 +02:00
UsrDat->EmailConfirmed = (row[1][0] == 'Y');
2014-12-01 23:55:08 +01:00
Found = true;
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return Found;
}
/*****************************************************************************/
2016-11-16 23:19:52 +01:00
/************* Get user's code of a user from his/her email ******************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-11-16 23:19:52 +01:00
// Returns -1L if email not found
2014-12-01 23:55:08 +01:00
2017-03-13 13:17:53 +01:00
long Mai_GetUsrCodFromEmail (const char Email[Cns_MAX_BYTES_EMAIL_ADDRESS + 1])
2014-12-01 23:55:08 +01:00
{
/***** Trivial check 1: email should be not null ******/
if (!Email)
return -1L;
/***** Trivial check 2: email should be not empty ******/
if (!Email[0])
return -1L;
/***** Get user's code from database *****/
return DB_QuerySELECTCode ("can not get user's code",
"SELECT usr_emails.UsrCod"
" FROM usr_emails,"
"usr_data"
" WHERE usr_emails.E_mail='%s'"
" AND usr_emails.UsrCod=usr_data.UsrCod",
Email);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2016-11-16 23:19:52 +01:00
/*********************** Show form to change my email ************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2019-02-15 21:09:18 +01:00
void Mai_ShowFormChangeMyEmail (bool IMustFillInEmail,bool IShouldConfirmEmail)
2018-10-15 14:07:12 +02:00
{
extern const char *Hlp_PROFILE_Account;
extern const char *Txt_Email;
2019-11-08 01:10:32 +01:00
char StrRecordWidth[Cns_MAX_DECIMAL_DIGITS_UINT + 2 + 1];
2018-10-15 14:07:12 +02:00
/***** Begin section *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_Begin (Mai_EMAIL_SECTION_ID);
2018-10-15 14:07:12 +02:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
snprintf (StrRecordWidth,sizeof (StrRecordWidth),"%upx",Rec_RECORD_WIDTH);
2020-03-26 02:54:30 +01:00
Box_BoxBegin (StrRecordWidth,Txt_Email,
2020-04-08 13:40:21 +02:00
Acc_PutLinkToRemoveMyAccount,NULL,
2018-10-15 14:07:12 +02:00
Hlp_PROFILE_Account,Box_NOT_CLOSABLE);
/***** Show form to change email *****/
2020-10-14 00:59:24 +02:00
Mai_ShowFormChangeUsrEmail (true, // ItsMe
IMustFillInEmail,
IShouldConfirmEmail);
2018-10-15 14:07:12 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2018-10-15 14:07:12 +02:00
/***** End section *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_End ();
2018-10-15 14:07:12 +02:00
}
/*****************************************************************************/
/****************** Show form to change another user's email *****************/
/*****************************************************************************/
void Mai_ShowFormChangeOtherUsrEmail (void)
{
2018-10-16 01:36:13 +02:00
extern const char *Hlp_PROFILE_Account;
extern const char *Txt_Email;
2019-11-08 01:10:32 +01:00
char StrRecordWidth[Cns_MAX_DECIMAL_DIGITS_UINT + 2 + 1];
2018-10-16 01:36:13 +02:00
/***** Begin section *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_Begin (Mai_EMAIL_SECTION_ID);
2018-10-15 14:07:12 +02:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
snprintf (StrRecordWidth,sizeof (StrRecordWidth),"%upx",Rec_RECORD_WIDTH);
2020-03-26 02:54:30 +01:00
Box_BoxBegin (StrRecordWidth,Txt_Email,
NULL,NULL,
2018-10-16 01:36:13 +02:00
Hlp_PROFILE_Account,Box_NOT_CLOSABLE);
2018-10-15 14:07:12 +02:00
/***** Show form to change email *****/
2020-10-14 00:59:24 +02:00
Mai_ShowFormChangeUsrEmail (false, // ItsMe
2019-02-15 21:09:18 +01:00
false, // IMustFillInEmail
2018-10-15 14:07:12 +02:00
false); // IShouldConfirmEmail
2018-10-16 01:36:13 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2018-10-16 01:36:13 +02:00
2018-10-15 14:07:12 +02:00
/***** End section *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_End ();
2018-10-15 14:07:12 +02:00
}
/*****************************************************************************/
/********************** Show form to change user's email *********************/
/*****************************************************************************/
2020-10-14 00:59:24 +02:00
static void Mai_ShowFormChangeUsrEmail (bool ItsMe,
bool IMustFillInEmail,
bool IShouldConfirmEmail)
2014-12-01 23:55:08 +01:00
{
2019-02-15 21:09:18 +01:00
extern const char *Txt_Before_going_to_any_other_option_you_must_fill_in_your_email_address;
2018-10-16 15:16:32 +02:00
extern const char *Txt_Please_confirm_your_email_address;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Current_email;
extern const char *Txt_Other_emails;
extern const char *Txt_Email_X_confirmed;
extern const char *Txt_Confirm_email;
extern const char *Txt_Use_this_email;
extern const char *Txt_New_email;
extern const char *Txt_Email;
extern const char *Txt_Change_email;
2019-02-18 18:27:45 +01:00
extern const char *Txt_Save_changes;
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumEmails;
unsigned NumEmail;
bool Confirmed;
2017-05-22 14:52:11 +02:00
Act_Action_t NextAction;
2020-10-14 00:59:24 +02:00
const struct UsrData *UsrDat = (ItsMe ? &Gbl.Usrs.Me.UsrDat :
&Gbl.Usrs.Other.UsrDat);
2014-12-01 23:55:08 +01:00
2019-03-09 20:12:44 +01:00
/***** Show possible alerts *****/
Ale_ShowAlerts (Mai_EMAIL_SECTION_ID);
2018-10-15 14:07:12 +02:00
/***** Help message *****/
2019-02-15 21:09:18 +01:00
if (IMustFillInEmail)
2019-02-16 17:20:05 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_Before_going_to_any_other_option_you_must_fill_in_your_email_address);
2018-10-15 14:07:12 +02:00
else if (IShouldConfirmEmail)
2019-02-16 17:20:05 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_Please_confirm_your_email_address);
2018-10-15 14:07:12 +02:00
2016-11-16 23:19:52 +01:00
/***** Get my emails *****/
NumEmails = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get old email addresses of a user",
"SELECT E_mail," // row[0]
"Confirmed" // row[1]
" FROM usr_emails"
" WHERE UsrCod=%ld"
" ORDER BY CreatTime DESC",
UsrDat->UsrCod);
2014-12-01 23:55:08 +01:00
2019-10-20 22:00:28 +02:00
/***** Begin table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWidePadding (2);
2018-10-15 14:07:12 +02:00
/***** List emails *****/
2019-12-27 15:45:19 +01:00
for (NumEmail = 1;
2014-12-01 23:55:08 +01:00
NumEmail <= NumEmails;
NumEmail++)
{
2016-11-16 23:19:52 +01:00
/* Get email */
2014-12-01 23:55:08 +01:00
row = mysql_fetch_row (mysql_res);
2016-09-07 18:48:10 +02:00
Confirmed = (row[1][0] == 'Y');
2014-12-01 23:55:08 +01:00
if (NumEmail == 1)
2019-10-04 14:42:59 +02:00
{
2019-12-27 15:45:19 +01:00
HTM_TR_Begin (NULL);
2014-12-01 23:55:08 +01:00
/* The first mail is the current one */
2019-12-27 21:10:39 +01:00
/* Label */
2019-12-27 15:45:19 +01:00
Frm_LabelColumn ("REC_C1_BOT RT",NULL,Txt_Current_email);
2019-10-07 17:36:41 +02:00
2019-12-27 21:10:39 +01:00
/* Data */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"REC_C2_BOT LT USR_ID\"");
2019-10-04 14:42:59 +02:00
}
2019-12-27 15:45:19 +01:00
else if (NumEmail == 2)
2014-12-01 23:55:08 +01:00
{
2019-12-27 15:45:19 +01:00
HTM_TR_Begin (NULL);
2019-12-27 21:10:39 +01:00
/* Label */
2019-12-27 15:45:19 +01:00
Frm_LabelColumn ("REC_C1_BOT RT",NULL,Txt_Other_emails);
2019-10-07 17:36:41 +02:00
2019-12-27 21:10:39 +01:00
/* Data */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"REC_C2_BOT LT DAT\"");
2015-11-16 17:39:59 +01:00
}
2014-12-01 23:55:08 +01:00
2016-11-16 23:19:52 +01:00
/* Form to remove email */
2015-11-16 17:39:59 +01:00
if (ItsMe)
2020-10-14 00:59:24 +02:00
Ico_PutContextualIconToRemove (ActRemMyMai,Mai_EMAIL_SECTION_ID,
Mai_PutParamsRemoveMyEmail,row[0]);
2015-11-16 17:39:59 +01:00
else
{
switch (UsrDat->Roles.InCurrentCrs)
2017-05-22 14:52:11 +02:00
{
case Rol_STD:
NextAction = ActRemMaiStd;
break;
case Rol_NET:
case Rol_TCH:
NextAction = ActRemMaiTch;
break;
default: // Guest, user or admin
NextAction = ActRemMaiOth;
break;
}
2020-10-14 00:59:24 +02:00
Ico_PutContextualIconToRemove (NextAction,Mai_EMAIL_SECTION_ID,
Mai_PutParamsRemoveOtherEmail,row[0]);
2014-12-01 23:55:08 +01:00
}
2016-11-16 23:19:52 +01:00
/* Email */
2019-11-10 12:36:37 +01:00
HTM_Txt (row[0]);
2014-12-01 23:55:08 +01:00
2016-11-16 23:19:52 +01:00
/* Email confirmed? */
2014-12-01 23:55:08 +01:00
if (Confirmed)
{
2019-12-30 18:08:31 +01:00
Ico_PutIcon ("check-circle.svg",
2019-12-30 21:47:07 +01:00
Str_BuildStringStr (Txt_Email_X_confirmed,row[0]),
2019-12-30 18:08:31 +01:00
"ICO16x16");
2019-12-30 21:47:07 +01:00
Str_FreeString ();
2014-12-01 23:55:08 +01:00
}
2016-11-16 23:19:52 +01:00
/* Form to change user's email */
2015-11-16 14:54:12 +01:00
if (NumEmail > 1 || (ItsMe && !Confirmed))
2014-12-01 23:55:08 +01:00
{
2019-11-09 21:08:20 +01:00
HTM_BR ();
2015-11-16 14:54:12 +01:00
if (ItsMe)
2019-02-15 21:09:18 +01:00
Frm_StartFormAnchor (ActChgMyMai,Mai_EMAIL_SECTION_ID);
2015-11-16 14:54:12 +01:00
else
{
switch (UsrDat->Roles.InCurrentCrs)
2017-05-22 14:52:11 +02:00
{
case Rol_STD:
NextAction = ActNewMaiStd;
break;
case Rol_NET:
case Rol_TCH:
NextAction = ActNewMaiTch;
break;
default: // Guest, user or admin
NextAction = ActNewMaiOth;
break;
}
2018-11-09 20:47:39 +01:00
Frm_StartFormAnchor (NextAction,Mai_EMAIL_SECTION_ID);
Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
2015-11-16 14:54:12 +01:00
}
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamString (NULL,"NewEmail",row[0]);
2017-06-11 19:02:40 +02:00
Btn_PutConfirmButtonInline ((ItsMe && NumEmail == 1) ? Txt_Confirm_email :
2015-11-16 14:54:12 +01:00
Txt_Use_this_email);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
2019-12-27 15:45:19 +01:00
if (NumEmail == 1 ||
NumEmail == NumEmails)
{
HTM_TD_End ();
HTM_TR_End ();
}
else
HTM_BR ();
2014-12-01 23:55:08 +01:00
}
2016-11-16 23:19:52 +01:00
/***** Form to enter new email *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 17:36:41 +02:00
2019-12-27 21:10:39 +01:00
/* Label */
2019-12-27 15:45:19 +01:00
Frm_LabelColumn ("REC_C1_BOT RT","NewEmail",
NumEmails ? Txt_New_email : // A new email
Txt_Email); // The first email
2019-10-07 17:36:41 +02:00
2019-12-27 21:10:39 +01:00
/* Data */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"REC_C2_BOT LT DAT\"");
2015-11-16 14:54:12 +01:00
if (ItsMe)
2019-02-15 21:09:18 +01:00
Frm_StartFormAnchor (ActChgMyMai,Mai_EMAIL_SECTION_ID);
2015-11-16 14:54:12 +01:00
else
{
switch (UsrDat->Roles.InCurrentCrs)
2017-05-22 14:52:11 +02:00
{
case Rol_STD:
NextAction = ActNewMaiStd;
break;
case Rol_NET:
case Rol_TCH:
NextAction = ActNewMaiTch;
break;
default: // Guest, user or admin
NextAction = ActNewMaiOth;
break;
}
2018-11-09 20:47:39 +01:00
Frm_StartFormAnchor (NextAction,Mai_EMAIL_SECTION_ID);
Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
2015-11-16 14:54:12 +01:00
}
2019-11-04 09:45:57 +01:00
HTM_INPUT_EMAIL ("NewEmail",Cns_MAX_CHARS_EMAIL_ADDRESS,Gbl.Usrs.Me.UsrDat.Email,
2019-11-12 15:41:58 +01:00
"id=\"NewEmail\" size=\"18\"");
2019-11-09 21:08:20 +01:00
HTM_BR ();
2017-06-11 19:02:40 +02:00
Btn_PutCreateButtonInline (NumEmails ? Txt_Change_email : // User already has an email address
2019-02-18 18:27:45 +01:00
Txt_Save_changes); // User has no email address yet
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 17:36:41 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2018-10-15 14:07:12 +02:00
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2014-12-01 23:55:08 +01:00
}
2020-10-14 00:59:24 +02:00
static void Mai_PutParamsRemoveMyEmail (void *Email)
{
if (Email)
Par_PutHiddenParamString (NULL,"Email",Email);
}
static void Mai_PutParamsRemoveOtherEmail (void *Email)
{
if (Email)
{
Usr_PutParamUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
2020-10-14 00:59:24 +02:00
Par_PutHiddenParamString (NULL,"Email",Email);
}
}
2015-11-16 14:54:12 +01:00
/*****************************************************************************/
2016-11-16 23:19:52 +01:00
/******************** Remove one of my user's emails *************************/
2015-11-16 14:54:12 +01:00
/*****************************************************************************/
void Mai_RemoveMyUsrEmail (void)
{
2016-11-16 23:19:52 +01:00
/***** Remove user's email *****/
2015-11-16 14:54:12 +01:00
Mai_RemoveEmail (&Gbl.Usrs.Me.UsrDat);
/***** Show my account again *****/
2018-10-15 14:07:12 +02:00
Acc_ShowFormChgMyAccount ();
2015-11-16 14:54:12 +01:00
}
/*****************************************************************************/
/**************** Remove one of the user's IDs of another user ***************/
/*****************************************************************************/
void Mai_RemoveOtherUsrEmail (void)
{
/***** Get other user's code from form and get user's data *****/
if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ())
{
2018-10-16 08:48:51 +02:00
if (Usr_ICanEditOtherUsr (&Gbl.Usrs.Other.UsrDat))
{
/***** Remove user's email *****/
Mai_RemoveEmail (&Gbl.Usrs.Other.UsrDat);
2015-11-16 14:54:12 +01:00
2018-10-16 08:48:51 +02:00
/***** Show form again *****/
Acc_ShowFormChgOtherUsrAccount ();
}
else
2019-03-09 20:12:44 +01:00
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
2015-11-16 14:54:12 +01:00
}
else // User not found
2019-03-09 20:12:44 +01:00
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
2015-11-16 14:54:12 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-11-16 23:19:52 +01:00
/************************** Remove email address *****************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2015-11-16 17:39:59 +01:00
static void Mai_RemoveEmail (struct UsrData *UsrDat)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_Email_X_removed;
2017-03-13 13:17:53 +01:00
char Email[Cns_MAX_BYTES_EMAIL_ADDRESS + 1];
2014-12-01 23:55:08 +01:00
2017-01-28 18:08:06 +01:00
if (Usr_ICanEditOtherUsr (UsrDat))
2014-12-01 23:55:08 +01:00
{
2016-11-16 23:19:52 +01:00
/***** Get new email from form *****/
2017-03-13 13:17:53 +01:00
Par_GetParToText ("Email",Email,Cns_MAX_BYTES_EMAIL_ADDRESS);
2015-11-16 14:54:12 +01:00
2016-11-16 23:19:52 +01:00
/***** Remove one of user's old email addresses *****/
2015-11-16 17:39:59 +01:00
Mai_RemoveEmailFromDB (UsrDat->UsrCod,Email);
2014-12-01 23:55:08 +01:00
2019-03-09 20:12:44 +01:00
/***** Create alert *****/
Ale_CreateAlert (Ale_SUCCESS,Mai_EMAIL_SECTION_ID,
Txt_Email_X_removed,
Email);
2015-11-16 17:39:59 +01:00
2016-11-16 23:19:52 +01:00
/***** Update list of emails *****/
2015-11-16 17:39:59 +01:00
Mai_GetEmailFromUsrCod (UsrDat);
2014-12-01 23:55:08 +01:00
}
else
2019-03-09 20:12:44 +01:00
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2016-11-16 23:19:52 +01:00
/*************** Remove an old email address from database *******************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2017-03-13 13:17:53 +01:00
static void Mai_RemoveEmailFromDB (long UsrCod,const char Email[Cns_MAX_BYTES_EMAIL_ADDRESS + 1])
2014-12-01 23:55:08 +01:00
{
2016-11-16 23:19:52 +01:00
/***** Remove an old email address *****/
2018-11-02 16:39:35 +01:00
DB_QueryREPLACE ("can not remove an old email address",
"DELETE FROM usr_emails"
" WHERE UsrCod=%ld"
" AND E_mail='%s'",
UsrCod,
Email);
2014-12-01 23:55:08 +01:00
}
2015-11-16 14:54:12 +01:00
/*****************************************************************************/
2016-11-16 23:19:52 +01:00
/************************* New user's email for me ***************************/
2015-11-16 14:54:12 +01:00
/*****************************************************************************/
void May_NewMyUsrEmail (void)
{
2016-11-16 23:19:52 +01:00
/***** Remove user's email *****/
2018-10-10 14:03:06 +02:00
Mai_NewUsrEmail (&Gbl.Usrs.Me.UsrDat,
true); // It's me
2015-11-16 14:54:12 +01:00
/***** Show my account again *****/
2018-10-15 14:07:12 +02:00
Acc_ShowFormChgMyAccount ();
2015-11-16 14:54:12 +01:00
}
/*****************************************************************************/
2016-11-16 23:19:52 +01:00
/********************* New user's email for another user *********************/
2015-11-16 14:54:12 +01:00
/*****************************************************************************/
void Mai_NewOtherUsrEmail (void)
{
2018-10-10 14:03:06 +02:00
bool ItsMe;
2015-11-16 14:54:12 +01:00
/***** Get other user's code from form and get user's data *****/
if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ())
{
2018-10-16 08:48:51 +02:00
if (Usr_ICanEditOtherUsr (&Gbl.Usrs.Other.UsrDat))
{
/***** New user's ID *****/
ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod);
Mai_NewUsrEmail (&Gbl.Usrs.Other.UsrDat,ItsMe);
2015-11-16 14:54:12 +01:00
2018-10-16 08:48:51 +02:00
/***** Show form again *****/
Acc_ShowFormChgOtherUsrAccount ();
}
else
2019-03-09 20:12:44 +01:00
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
2015-11-16 14:54:12 +01:00
}
else // User not found
2019-03-09 20:12:44 +01:00
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
2015-11-16 14:54:12 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-11-16 23:19:52 +01:00
/************************* Update my email address ***************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2015-11-16 14:54:12 +01:00
static void Mai_NewUsrEmail (struct UsrData *UsrDat,bool ItsMe)
2014-12-01 23:55:08 +01:00
{
2015-11-16 14:54:12 +01:00
extern const char *Txt_The_email_address_X_matches_one_previously_registered;
extern const char *Txt_The_email_address_X_has_been_registered_successfully;
2014-12-01 23:55:08 +01:00
extern const char *Txt_The_email_address_X_had_been_registered_by_another_user;
extern const char *Txt_The_email_address_entered_X_is_not_valid;
2017-03-13 13:17:53 +01:00
char NewEmail[Cns_MAX_BYTES_EMAIL_ADDRESS + 1];
2014-12-01 23:55:08 +01:00
2017-01-28 18:08:06 +01:00
if (Usr_ICanEditOtherUsr (UsrDat))
2014-12-01 23:55:08 +01:00
{
2016-11-16 23:19:52 +01:00
/***** Get new email from form *****/
2017-03-13 13:17:53 +01:00
Par_GetParToText ("NewEmail",NewEmail,Cns_MAX_BYTES_EMAIL_ADDRESS);
2015-11-16 14:54:12 +01:00
2016-11-16 23:19:52 +01:00
if (Mai_CheckIfEmailIsValid (NewEmail)) // New email is valid
2014-12-01 23:55:08 +01:00
{
2016-11-16 23:19:52 +01:00
/***** Check if new email exists in database *****/
2015-11-16 14:54:12 +01:00
if (UsrDat->EmailConfirmed &&
!strcmp (UsrDat->Email,NewEmail)) // User's current confirmed email match exactly the new email
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_WARNING,Mai_EMAIL_SECTION_ID,
Txt_The_email_address_X_matches_one_previously_registered,
NewEmail);
2014-12-01 23:55:08 +01:00
else
2015-11-16 14:54:12 +01:00
{
if (Mai_UpdateEmailInDB (UsrDat,NewEmail))
{
2016-11-16 23:19:52 +01:00
/***** Email updated sucessfully *****/
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_SUCCESS,Mai_EMAIL_SECTION_ID,
Txt_The_email_address_X_has_been_registered_successfully,
NewEmail);
2015-11-16 14:54:12 +01:00
2016-11-16 23:19:52 +01:00
/***** Update list of emails *****/
2015-11-16 17:39:59 +01:00
Mai_GetEmailFromUsrCod (UsrDat);
/***** Send message via email
to confirm the new email address *****/
2015-11-16 14:54:12 +01:00
if (ItsMe)
2016-10-10 20:02:47 +02:00
Mai_SendMailMsgToConfirmEmail ();
2015-11-16 14:54:12 +01:00
}
else
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_WARNING,Mai_EMAIL_SECTION_ID,
Txt_The_email_address_X_had_been_registered_by_another_user,
NewEmail);
2014-12-01 23:55:08 +01:00
}
2015-11-16 14:54:12 +01:00
}
2016-11-16 23:19:52 +01:00
else // New email is not valid
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_WARNING,Mai_EMAIL_SECTION_ID,
Txt_The_email_address_entered_X_is_not_valid,
NewEmail);
2014-12-01 23:55:08 +01:00
}
2015-11-16 14:54:12 +01:00
else
2019-03-09 20:12:44 +01:00
Ale_CreateAlertUserNotFoundOrYouDoNotHavePermission ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2016-11-16 23:19:52 +01:00
/************************ Update email in database ***************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-11-16 23:19:52 +01:00
// Return true if email is successfully updated
// Return false if email can not be updated beacuse it is registered by another user
2014-12-01 23:55:08 +01:00
2017-03-13 13:17:53 +01:00
bool Mai_UpdateEmailInDB (const struct UsrData *UsrDat,const char NewEmail[Cns_MAX_BYTES_EMAIL_ADDRESS + 1])
2014-12-01 23:55:08 +01:00
{
2016-11-16 23:19:52 +01:00
/***** Check if the new email matches any of the confirmed emails of other users *****/
2018-11-03 20:52:00 +01:00
if (DB_QueryCOUNT ("can not check if email already existed",
"SELECT COUNT(*)"
" FROM usr_emails"
" WHERE E_mail='%s'"
" AND Confirmed='Y'"
" AND UsrCod<>%ld",
NewEmail,
UsrDat->UsrCod)) // An email of another user is the same that my email
2014-12-01 23:55:08 +01:00
return false; // Don't update
2016-11-16 23:19:52 +01:00
/***** Delete email (not confirmed) for other users *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove pending email for other users",
"DELETE FROM usr_pending_emails"
" WHERE E_mail='%s'"
" AND UsrCod<>%ld",
NewEmail,
UsrDat->UsrCod);
2018-10-22 19:15:56 +02:00
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove not confirmed email for other users",
"DELETE FROM usr_emails"
" WHERE E_mail='%s'"
" AND Confirmed='N'"
" AND UsrCod<>%ld",
NewEmail,
UsrDat->UsrCod);
2014-12-01 23:55:08 +01:00
2016-11-16 23:19:52 +01:00
/***** Update email in database *****/
2018-11-02 16:39:35 +01:00
DB_QueryREPLACE ("can not update email",
"REPLACE INTO usr_emails"
" (UsrCod,E_mail,CreatTime)"
" VALUES"
" (%ld,'%s',NOW())",
UsrDat->UsrCod,
NewEmail);
2014-12-01 23:55:08 +01:00
return true; // Successfully updated
}
2016-10-10 19:25:25 +02:00
/*****************************************************************************/
2016-11-16 23:19:52 +01:00
/************** Send mail message to confirm my email address ****************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
// Return true on success
// Return false on error
bool Mai_SendMailMsgToConfirmEmail (void)
{
extern const char *Txt_If_you_just_request_from_X_the_confirmation_of_your_email_Y_NO_HTML;
extern const char *Txt_Confirmation_of_your_email_NO_HTML;
2018-10-15 14:07:12 +02:00
extern const char *Txt_A_message_has_been_sent_to_email_address_X_to_confirm_that_address;
2014-12-01 23:55:08 +01:00
extern const char *Txt_There_was_a_problem_sending_an_email_automatically;
2020-04-11 15:21:30 +02:00
char FileNameMail[PATH_MAX + 1];
FILE *FileMail;
2018-10-04 21:57:25 +02:00
char Command[2048 +
Cfg_MAX_BYTES_SMTP_PASSWORD +
Cns_MAX_BYTES_EMAIL_ADDRESS +
PATH_MAX]; // Command to execute for sending an email
2014-12-01 23:55:08 +01:00
int ReturnCode;
/***** Create temporary file for mail content *****/
2020-04-11 15:21:30 +02:00
Mai_CreateFileNameMail (FileNameMail,&FileMail);
2014-12-01 23:55:08 +01:00
/***** Write mail content into file and close file *****/
/* Welcome note */
2020-04-11 15:21:30 +02:00
Mai_WriteWelcomeNoteEMail (FileMail,&Gbl.Usrs.Me.UsrDat);
2014-12-01 23:55:08 +01:00
/* Store encrypted key in database */
Mai_InsertMailKey (Gbl.Usrs.Me.UsrDat.Email,Gbl.UniqueNameEncrypted);
/* Message body */
2020-04-11 15:21:30 +02:00
fprintf (FileMail,
2014-12-01 23:55:08 +01:00
Txt_If_you_just_request_from_X_the_confirmation_of_your_email_Y_NO_HTML,
2016-07-08 12:43:48 +02:00
Cfg_URL_SWAD_CGI,Gbl.Usrs.Me.UsrDat.Email,
2018-04-24 13:21:53 +02:00
Cfg_URL_SWAD_CGI,Act_GetActCod (ActCnfMai),Gbl.UniqueNameEncrypted,
2016-07-08 12:43:48 +02:00
Cfg_URL_SWAD_CGI);
2014-12-01 23:55:08 +01:00
/* Footer note */
2020-04-11 15:21:30 +02:00
Mai_WriteFootNoteEMail (FileMail,Gbl.Prefs.Language);
2014-12-01 23:55:08 +01:00
2020-04-11 15:21:30 +02:00
fclose (FileMail);
2014-12-01 23:55:08 +01:00
2016-11-16 23:19:52 +01:00
/***** Call the script to send an email *****/
2018-10-18 02:02:32 +02:00
snprintf (Command,sizeof (Command),
"%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"[%s] %s\" \"%s\"",
Cfg_COMMAND_SEND_AUTOMATIC_EMAIL,
Cfg_AUTOMATIC_EMAIL_SMTP_SERVER,
Cfg_AUTOMATIC_EMAIL_SMTP_PORT,
Cfg_AUTOMATIC_EMAIL_FROM,
Gbl.Config.SMTPPassword,
Gbl.Usrs.Me.UsrDat.Email,
Cfg_PLATFORM_SHORT_NAME,Txt_Confirmation_of_your_email_NO_HTML,
2020-04-11 15:21:30 +02:00
FileNameMail);
2014-12-01 23:55:08 +01:00
ReturnCode = system (Command);
if (ReturnCode == -1)
2016-11-16 23:19:52 +01:00
Lay_ShowErrorAndExit ("Error when running script to send email.");
2014-12-01 23:55:08 +01:00
/***** Remove temporary file *****/
2020-04-11 15:21:30 +02:00
unlink (FileNameMail);
2014-12-01 23:55:08 +01:00
/***** Write message depending on return code *****/
ReturnCode = WEXITSTATUS(ReturnCode);
switch (ReturnCode)
{
case 0: // Message sent successfully
2016-10-10 19:50:24 +02:00
Gbl.Usrs.Me.ConfirmEmailJustSent = true;
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_SUCCESS,Mai_EMAIL_SECTION_ID,
Txt_A_message_has_been_sent_to_email_address_X_to_confirm_that_address,
Gbl.Usrs.Me.UsrDat.Email);
2014-12-01 23:55:08 +01:00
return true;
case 1:
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_ERROR,Mai_EMAIL_SECTION_ID,
Txt_There_was_a_problem_sending_an_email_automatically);
2014-12-01 23:55:08 +01:00
return false;
default:
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_ERROR,Mai_EMAIL_SECTION_ID,
"Internal error: an email message has not been sent successfully."
" Error code returned by the script: %d",
ReturnCode);
2014-12-01 23:55:08 +01:00
return false;
}
}
2016-10-10 19:50:24 +02:00
/*****************************************************************************/
/************************* Insert mail hey in database ***********************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2017-03-13 13:17:53 +01:00
static void Mai_InsertMailKey (const char Email[Cns_MAX_BYTES_EMAIL_ADDRESS + 1],
2017-01-28 15:58:46 +01:00
const char MailKey[Mai_LENGTH_EMAIL_CONFIRM_KEY + 1])
2014-12-01 23:55:08 +01:00
{
2016-11-16 23:19:52 +01:00
/***** Remove expired pending emails from database *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove old pending mail keys",
"DELETE LOW_PRIORITY FROM usr_pending_emails"
2019-02-13 13:32:11 +01:00
" WHERE DateAndTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)",
2018-11-02 22:00:31 +01:00
Cfg_TIME_TO_DELETE_OLD_PENDING_EMAILS);
2014-12-01 23:55:08 +01:00
/***** Insert mail key in database *****/
2018-11-02 16:39:35 +01:00
DB_QueryREPLACE ("can not create pending password",
"INSERT INTO usr_pending_emails"
2018-11-02 16:39:35 +01:00
" (UsrCod,E_mail,MailKey,DateAndTime)"
" VALUES"
" (%ld,'%s','%s',NOW())",
Gbl.Usrs.Me.UsrDat.UsrCod,
Email,
MailKey);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2016-11-16 23:19:52 +01:00
/************************* Confirm my email address **************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
void Mai_ConfirmEmail (void)
{
extern const char *Txt_Failed_email_confirmation_key;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Email_X_has_already_been_confirmed_before;
extern const char *Txt_The_email_X_has_been_confirmed;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2017-01-28 15:58:46 +01:00
char MailKey[Mai_LENGTH_EMAIL_CONFIRM_KEY + 1];
2014-12-01 23:55:08 +01:00
long UsrCod;
2017-03-13 13:17:53 +01:00
char Email[Cns_MAX_BYTES_EMAIL_ADDRESS + 1];
2018-11-09 21:02:52 +01:00
bool KeyIsCorrect;
char StrConfirmed[1 + 1];
2014-12-01 23:55:08 +01:00
/***** Get parameter Key *****/
2015-03-07 21:08:44 +01:00
Par_GetParToText ("key",MailKey,Mai_LENGTH_EMAIL_CONFIRM_KEY);
2014-12-01 23:55:08 +01:00
2016-11-16 23:19:52 +01:00
/***** Get user's code and email from key *****/
2018-10-31 16:16:57 +01:00
if (DB_QuerySELECT (&mysql_res,"can not get user's code and email from key",
"SELECT UsrCod," // row[0]
"E_mail" // row[1]
" FROM usr_pending_emails"
2018-10-31 16:16:57 +01:00
" WHERE MailKey='%s'",
MailKey))
2014-12-01 23:55:08 +01:00
{
row = mysql_fetch_row (mysql_res);
/* Get user's code */
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
2016-11-16 23:19:52 +01:00
/* Get user's email */
Str_Copy (Email,row[1],sizeof (Email) - 1);
2014-12-01 23:55:08 +01:00
KeyIsCorrect = true;
}
2018-11-09 21:02:52 +01:00
else
{
row = NULL;
UsrCod = -1L;
KeyIsCorrect = false;
}
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
if (KeyIsCorrect)
{
/***** Delete this key *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove an email key",
"DELETE FROM usr_pending_emails"
" WHERE MailKey='%s'",
2018-11-02 22:00:31 +01:00
MailKey);
2014-12-01 23:55:08 +01:00
2016-11-16 23:19:52 +01:00
/***** Check user's code and email
and get if email is already confirmed *****/
DB_QuerySELECTString (StrConfirmed,1,"can not check if email is confirmed",
"SELECT Confirmed"
" FROM usr_emails"
" WHERE UsrCod=%ld"
" AND E_mail='%s'",
UsrCod,
Email);
switch (StrConfirmed[0])
{
case '\0':
Ale_ShowAlert (Ale_WARNING,Txt_Failed_email_confirmation_key);
break;
case 'Y':
2019-02-16 17:20:05 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Email_X_has_already_been_confirmed_before,
Email);
break;
default:
/***** Confirm email *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not confirm email",
"UPDATE usr_emails"
" SET Confirmed='Y'"
2018-11-03 12:16:40 +01:00
" WHERE usr_emails.UsrCod=%ld"
" AND usr_emails.E_mail='%s'",
UsrCod,
Email);
2019-02-16 17:20:05 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_The_email_X_has_been_confirmed,
Email);
break;
}
2014-12-01 23:55:08 +01:00
}
/***** Form to log in *****/
2016-12-05 13:26:12 +01:00
Usr_WriteFormLogin (ActLogIn,NULL);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************** Create temporary file for mail content *******************/
/*****************************************************************************/
2020-04-11 15:21:30 +02:00
void Mai_CreateFileNameMail (char FileNameMail[PATH_MAX + 1],FILE **FileMail)
2014-12-01 23:55:08 +01:00
{
snprintf (FileNameMail,PATH_MAX + 1,"%s/%s_mail.txt",
2019-03-20 01:36:36 +01:00
Cfg_PATH_OUT_PRIVATE,Gbl.UniqueNameEncrypted);
2020-04-11 15:21:30 +02:00
if ((*FileMail = fopen (FileNameMail,"wb")) == NULL)
2016-11-16 23:19:52 +01:00
Lay_ShowErrorAndExit ("Can not open file to send email.");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2016-11-16 23:19:52 +01:00
/************ Write a welcome note heading the automatic email ***************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2020-04-11 15:21:30 +02:00
void Mai_WriteWelcomeNoteEMail (FILE *FileMail,struct UsrData *UsrDat)
2014-12-01 23:55:08 +01:00
{
2018-12-08 16:43:13 +01:00
extern const char *Txt_Dear_NO_HTML[Usr_NUM_SEXS][1 + Lan_NUM_LANGUAGES];
extern const char *Txt_user_NO_HTML[Usr_NUM_SEXS][1 + Lan_NUM_LANGUAGES];
2014-12-01 23:55:08 +01:00
2020-04-11 15:21:30 +02:00
fprintf (FileMail,"%s %s:\n",
2014-12-01 23:55:08 +01:00
Txt_Dear_NO_HTML[UsrDat->Sex][UsrDat->Prefs.Language],
UsrDat->FrstName[0] ? UsrDat->FrstName :
2014-12-01 23:55:08 +01:00
Txt_user_NO_HTML[UsrDat->Sex][UsrDat->Prefs.Language]);
}
/*****************************************************************************/
2016-11-16 23:19:52 +01:00
/****************** Write a foot note in the automatic email *****************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2020-04-11 15:21:30 +02:00
void Mai_WriteFootNoteEMail (FILE *FileMail,Lan_Language_t Language)
2014-12-01 23:55:08 +01:00
{
2018-12-08 16:43:13 +01:00
extern const char *Txt_Please_do_not_reply_to_this_automatically_generated_email_NO_HTML[1 + Lan_NUM_LANGUAGES];
2014-12-01 23:55:08 +01:00
2020-04-11 15:21:30 +02:00
fprintf (FileMail,"%s\n"
"%s\n"
"%s\n",
2014-12-01 23:55:08 +01:00
Txt_Please_do_not_reply_to_this_automatically_generated_email_NO_HTML[Language],
2015-07-24 11:34:39 +02:00
Cfg_PLATFORM_SHORT_NAME,
2016-07-08 12:43:48 +02:00
Cfg_URL_SWAD_CGI);
2014-12-01 23:55:08 +01:00
}
2016-04-23 13:23:09 +02:00
/*****************************************************************************/
2016-11-16 23:19:52 +01:00
/**************** Check if I can see another user's email ********************/
2016-04-23 13:23:09 +02:00
/*****************************************************************************/
2017-01-27 15:21:01 +01:00
bool Mai_ICanSeeOtherUsrEmail (const struct UsrData *UsrDat)
2016-04-23 13:23:09 +02:00
{
2018-10-10 23:56:42 +02:00
bool ItsMe = Usr_ItsMe (UsrDat->UsrCod);
2018-10-10 14:03:06 +02:00
if (ItsMe)
2016-04-23 13:23:09 +02:00
return true;
2017-05-22 14:52:11 +02:00
/***** Check if I have permission to see another user's email *****/
2017-06-04 18:18:54 +02:00
switch (Gbl.Usrs.Me.Role.Logged)
2016-04-23 13:23:09 +02:00
{
2017-05-18 19:13:41 +02:00
case Rol_STD:
2017-01-27 18:45:38 +01:00
/* If I am a student in the current course,
I can see the email of confirmed teachers */
return (UsrDat->Roles.InCurrentCrs == Rol_NET || // A non-editing teacher
UsrDat->Roles.InCurrentCrs == Rol_TCH) && // or a teacher
2017-05-22 14:52:11 +02:00
UsrDat->Accepted; // who accepted registration
case Rol_NET:
2017-05-18 19:13:41 +02:00
case Rol_TCH:
2017-01-27 18:45:38 +01:00
/* If I am a teacher in the current course,
I can see the email of confirmed students and teachers */
2017-06-08 15:32:33 +02:00
return Usr_CheckIfUsrBelongsToCurrentCrs (UsrDat) && // A user belonging to the current course
UsrDat->Accepted; // who accepted registration
2016-04-23 13:23:09 +02:00
case Rol_DEG_ADM:
/* If I am an administrator of current degree,
2016-11-16 23:19:52 +01:00
I only can see the user's email of users from current degree */
2017-01-27 01:02:52 +01:00
return Usr_CheckIfUsrBelongsToDeg (UsrDat->UsrCod,
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Deg.DegCod);
2016-04-23 13:23:09 +02:00
case Rol_CTR_ADM:
/* If I am an administrator of current center,
I only can see the user's email of users from current center */
2017-01-27 01:02:52 +01:00
return Usr_CheckIfUsrBelongsToCtr (UsrDat->UsrCod,
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ctr.CtrCod);
2016-04-23 13:23:09 +02:00
case Rol_INS_ADM:
/* If I am an administrator of current institution,
2016-11-16 23:19:52 +01:00
I only can see the user's email of users from current institution */
2017-01-27 01:02:52 +01:00
return Usr_CheckIfUsrBelongsToIns (UsrDat->UsrCod,
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod);
2016-04-23 13:23:09 +02:00
case Rol_SYS_ADM:
return true;
default:
return false;
}
}
2019-04-09 14:04:04 +02:00
/*****************************************************************************/
/********************** Mail domain constructor/destructor *******************/
/*****************************************************************************/
static void Mai_EditingMailDomainConstructor (void)
{
/***** Pointer must be NULL *****/
if (Mai_EditingMai != NULL)
Lay_WrongMailDomainExit ();
2019-04-09 14:04:04 +02:00
/***** Allocate memory for mail domain *****/
if ((Mai_EditingMai = malloc (sizeof (*Mai_EditingMai))) == NULL)
Lay_NotEnoughMemoryExit ();
2019-04-09 14:04:04 +02:00
/***** Reset place *****/
Mai_EditingMai->MaiCod = -1L;
Mai_EditingMai->Domain[0] = '\0';
Mai_EditingMai->Info[0] = '\0';
Mai_EditingMai->NumUsrs = 0;
}
static void Mai_EditingMailDomainDestructor (void)
{
/***** Free memory used for mail domain *****/
if (Mai_EditingMai != NULL)
{
2019-11-06 19:45:20 +01:00
free (Mai_EditingMai);
2019-04-09 14:04:04 +02:00
Mai_EditingMai = NULL;
}
}