");
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** Get email addresses of the selected users *****/
StrAddresses[0] = '\0';
Ptr = Gbl.Usrs.Selected.List[Rol_UNK];
while (*Ptr)
{
/* Get next user */
Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EncryptedUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat);
/* Get user's email */
Mai_GetEmailFromUsrCod (&UsrDat);
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)
{
fprintf (Gbl.F.Out,", ");
LengthStrAddr ++;
if (LengthStrAddr > Mai_MAX_BYTES_STR_ADDR)
Lay_ShowErrorAndExit ("The space allocated to store email addresses is full.");
Str_Concat (StrAddresses,",",
Mai_MAX_BYTES_STR_ADDR);
}
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,
Mai_MAX_BYTES_STR_ADDR);
fprintf (Gbl.F.Out,"
%s",
UsrDat.Email,Gbl.Hierarchy.Crs.FullName,UsrDat.Email);
NumAcceptedUsrsWithEmail++;
}
}
}
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
/***** End list with users' email addresses *****/
fprintf (Gbl.F.Out,"
");
/***** Show a message with the number of users with email ****/
fprintf (Gbl.F.Out,"");
fprintf (Gbl.F.Out,Txt_X_users_who_have_email,
NumUsrsWithEmail);
fprintf (Gbl.F.Out,"
");
/***** Show a message with the number of users who have accepted and have email ****/
fprintf (Gbl.F.Out,"");
fprintf (Gbl.F.Out,Txt_X_users_who_have_accepted_and_who_have_email,
NumAcceptedUsrsWithEmail);
fprintf (Gbl.F.Out,"
");
/***** Icon to open the client email program *****/
fprintf (Gbl.F.Out,"");
/***** End the box used to list the emails *****/
Box_EndBox ();
}
/*****************************************************************************/
/**************** Check whether an email address if valid ********************/
/*****************************************************************************/
bool Mai_CheckIfEmailIsValid (const char *Email)
{
unsigned Length = strlen (Email);
unsigned LastPosArroba = Length - 4;
const char *Ptr;
unsigned Pos;
bool ArrobaFound = false;
/***** An email address must have a number of characters
5 <= Length <= Cns_MAX_BYTES_EMAIL_ADDRESS *****/
if (Length < 5 ||
Length > Cns_MAX_BYTES_EMAIL_ADDRESS)
return false;
/***** An email address can have digits, letters, '.', '-' and '_';
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;
}
/*****************************************************************************/
/********** Get email address of a user from his/her user's code *************/
/*****************************************************************************/
bool Mai_GetEmailFromUsrCod (struct UsrData *UsrDat)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
bool Found;
/***** Get current (last updated) user's nickname from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get email address",
"SELECT E_mail,Confirmed FROM usr_emails"
" WHERE UsrCod=%ld"
" ORDER BY CreatTime DESC LIMIT 1",
UsrDat->UsrCod);
if (NumRows == 0)
{
UsrDat->Email[0] = '\0';
UsrDat->EmailConfirmed = false;
Found = false;
}
else
{
/* Get email */
row = mysql_fetch_row (mysql_res);
Str_Copy (UsrDat->Email,row[0],
Cns_MAX_BYTES_EMAIL_ADDRESS);
UsrDat->EmailConfirmed = (row[1][0] == 'Y');
Found = true;
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return Found;
}
/*****************************************************************************/
/************* Get user's code of a user from his/her email ******************/
/*****************************************************************************/
// Returns -1L if email not found
long Mai_GetUsrCodFromEmail (const char Email[Cns_MAX_BYTES_EMAIL_ADDRESS + 1])
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumUsrs;
long UsrCod = -1L;
if (Email)
if (Email[0])
{
/***** Get user's code from database *****/
/* Check if user code from table usr_emails is also in table usr_data */
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"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);
if (NumUsrs == 0)
/* User not found for this email ==> set user's code to void */
UsrCod = -1L;
else if (NumUsrs == 1) // One user found
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get user's code */
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
}
else // NumRows > 1 ==> impossible, an email can not be reapeated
Lay_ShowErrorAndExit ("Internal error: email is repeated in database.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
return UsrCod;
}
/*****************************************************************************/
/*********************** Show form to change my email ************************/
/*****************************************************************************/
void Mai_ShowFormChangeMyEmail (bool IMustFillInEmail,bool IShouldConfirmEmail)
{
extern const char *Hlp_PROFILE_Account;
extern const char *Txt_Email;
char StrRecordWidth[10 + 1];
/***** Start section *****/
Lay_StartSection (Mai_EMAIL_SECTION_ID);
/***** Start box *****/
snprintf (StrRecordWidth,sizeof (StrRecordWidth),
"%upx",
Rec_RECORD_WIDTH);
Box_StartBox (StrRecordWidth,Txt_Email,Acc_PutLinkToRemoveMyAccount,
Hlp_PROFILE_Account,Box_NOT_CLOSABLE);
/***** Show form to change email *****/
Mai_ShowFormChangeUsrEmail (&Gbl.Usrs.Me.UsrDat,
true, // ItsMe
IMustFillInEmail,IShouldConfirmEmail);
/***** End box *****/
Box_EndBox ();
/***** End section *****/
Lay_EndSection ();
}
/*****************************************************************************/
/****************** Show form to change another user's email *****************/
/*****************************************************************************/
void Mai_ShowFormChangeOtherUsrEmail (void)
{
extern const char *Hlp_PROFILE_Account;
extern const char *Txt_Email;
char StrRecordWidth[10 + 1];
/***** Start section *****/
Lay_StartSection (Mai_EMAIL_SECTION_ID);
/***** Start box *****/
snprintf (StrRecordWidth,sizeof (StrRecordWidth),
"%upx",
Rec_RECORD_WIDTH);
Box_StartBox (StrRecordWidth,Txt_Email,NULL,
Hlp_PROFILE_Account,Box_NOT_CLOSABLE);
/***** Show form to change email *****/
Mai_ShowFormChangeUsrEmail (&Gbl.Usrs.Other.UsrDat,
false, // ItsMe
false, // IMustFillInEmail
false); // IShouldConfirmEmail
/***** End box *****/
Box_EndBox ();
/***** End section *****/
Lay_EndSection ();
}
/*****************************************************************************/
/********************** Show form to change user's email *********************/
/*****************************************************************************/
static void Mai_ShowFormChangeUsrEmail (const struct UsrData *UsrDat,bool ItsMe,
bool IMustFillInEmail,bool IShouldConfirmEmail)
{
extern const char *The_ClassFormInBox[The_NUM_THEMES];
extern const char *Txt_Before_going_to_any_other_option_you_must_fill_in_your_email_address;
extern const char *Txt_Please_confirm_your_email_address;
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;
extern const char *Txt_Save_changes;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumEmails;
unsigned NumEmail;
bool Confirmed;
Act_Action_t NextAction;
/***** Show possible alerts *****/
Ale_ShowAlerts (Mai_EMAIL_SECTION_ID);
/***** Help message *****/
if (IMustFillInEmail)
Ale_ShowAlert (Ale_WARNING,Txt_Before_going_to_any_other_option_you_must_fill_in_your_email_address);
else if (IShouldConfirmEmail)
Ale_ShowAlert (Ale_WARNING,Txt_Please_confirm_your_email_address);
/***** Get my emails *****/
NumEmails = (unsigned) DB_QuerySELECT (&mysql_res,"can not get"
" old email addresses"
" of a user",
"SELECT E_mail,Confirmed"
" FROM usr_emails"
" WHERE UsrCod=%ld"
" ORDER BY CreatTime DESC",
UsrDat->UsrCod);
/***** Start table *****/
Tbl_TABLE_BeginWidePadding (2);
/***** List emails *****/
for (NumEmail = 1;
NumEmail <= NumEmails;
NumEmail++)
{
/* Get email */
row = mysql_fetch_row (mysql_res);
Confirmed = (row[1][0] == 'Y');
Tbl_TR_Begin (NULL);
if (NumEmail == 1)
{
/* The first mail is the current one */
Tbl_TD_Begin ("class=\"REC_C1_BOT RIGHT_TOP\"");
fprintf (Gbl.F.Out,"