/** * Sets the specified account settings to the current user. * A table with | Setting label | value | is expected. * * @Given /^I set the following account settings values:$/ * @param TableNode $table */ public function i_set_account_settings(TableNode $table) { global $USER; $prefs = array(); foreach ($table->getHash() as $accountpref) { $prefs[$accountpref['field']] = $accountpref['value']; } // Validate the settings if (isset($prefs['urlid']) && get_config('cleanurls') && $prefs['urlid'] != $USER->get('urlid')) { if (strlen($prefs['urlid']) < 3) { throw new Exception("Invalid urlid: " . get_string('rule.minlength.minlength', 'pieforms', 3)); } else { if (record_exists('usr', 'urlid', $prefs['urlid'])) { throw new Exception("Invalid urlid: " . get_string('urlalreadytaken', 'account')); } } } if (get_config('allowmobileuploads')) { foreach ($prefs['mobileuploadtoken'] as $k => $text) { if (strlen($text) > 0 && !preg_match('/^[a-zA-Z0-9 !@#$%^&*()\\-_=+\\[{\\]};:\'",<\\.>\\/?]{6,}$/', $text)) { throw new Exception("Invalid mobileuploadtoken: " . get_string('badmobileuploadtoken', 'account')); } } } // Update user's account settings db_begin(); // use this as looping through values is not safe. $expectedprefs = expected_account_preferences(); if (isset($prefs['maildisabled']) && $prefs['maildisabled'] == 0 && get_account_preference($USER->get('id'), 'maildisabled') == 1) { // Reset the sent and bounce counts otherwise mail will be disabled // on the next send attempt $u = new StdClass(); $u->email = $USER->get('email'); $u->id = $USER->get('id'); update_bounce_count($u, true); update_send_count($u, true); } // Remember the user's language & theme prefs, so we can reload the page if they change them $oldlang = $USER->get_account_preference('lang'); $oldtheme = $USER->get_account_preference('theme'); $oldgroupsideblockmaxgroups = $USER->get_account_preference('groupsideblockmaxgroups'); $oldgroupsideblocksortby = $USER->get_account_preference('groupsideblocksortby'); if (get_config('allowmobileuploads') && isset($prefs['mobileuploadtoken'])) { // Make sure the mobile token is formatted / saved correctly $prefs['mobileuploadtoken'] = array_filter($prefs['mobileuploadtoken']); $new_token_pref = '|' . join('|', $prefs['mobileuploadtoken']) . '|'; $USER->set_account_preference('mobileuploadtoken', $new_token_pref); unset($prefs['mobileuploadtoken']); } // Set user account preferences foreach ($expectedprefs as $eprefkey => $epref) { if (isset($prefs[$eprefkey]) && $prefs[$eprefkey] !== get_account_preference($USER->get('id'), $eprefkey)) { $USER->set_account_preference($eprefkey, $prefs[$eprefkey]); } } db_commit(); }
function edituser_site_submit(Pieform $form, $values) { global $USER, $authobj, $SESSION; if (!($user = get_record('usr', 'id', $values['id']))) { return false; } if (is_using_probation()) { // Value should be between 0 and 10 inclusive $user->probation = ensure_valid_probation_points($values['probationpoints']); } if ($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride')) { $user->quota = $values['quota']; // check if the user has gone over the quota notify limit $quotanotifylimit = get_config_plugin('artefact', 'file', 'quotanotifylimit'); if ($quotanotifylimit <= 0 || $quotanotifylimit >= 100) { $quotanotifylimit = 100; } $user->quotausedpercent = $user->quotaused / $user->quota * 100; $overlimit = false; if ($quotanotifylimit <= $user->quotausedpercent) { $overlimit = true; } $notified = get_field('usr_account_preference', 'value', 'field', 'quota_exceeded_notified', 'usr', $user->id); if ($overlimit && '1' !== $notified) { require_once get_config('docroot') . 'artefact/file/lib.php'; ArtefactTypeFile::notify_users_threshold_exceeded(array($user), false); // no need to email admin as we can alert them right now $SESSION->add_error_msg(get_string('useroverquotathreshold', 'artefact.file', display_name($user))); } else { if ($notified && !$overlimit) { set_account_preference($user->id, 'quota_exceeded_notified', false); } } } $unexpire = $user->expiry && strtotime($user->expiry) < time() && (empty($values['expiry']) || $values['expiry'] > time()); $newexpiry = db_format_timestamp($values['expiry']); if ($user->expiry != $newexpiry) { $user->expiry = $newexpiry; if ($unexpire) { $user->expirymailsent = 0; $user->lastaccess = db_format_timestamp(time()); } } // Try to kick the user from any active login sessions, before saving data. require_once get_config('docroot') . 'auth/session.php'; remove_user_sessions($user->id); if ($USER->get('admin')) { // Not editable by institutional admins $user->staff = (int) ($values['staff'] == 'on'); $user->admin = (int) ($values['admin'] == 'on'); if ($user->admin) { activity_add_admin_defaults(array($user->id)); } } if ($values['maildisabled'] == 0 && get_account_preference($user->id, 'maildisabled') == 1) { // Reset the sent and bounce counts otherwise mail will be disabled // on the next send attempt $u = new StdClass(); $u->email = $user->email; $u->id = $user->id; update_bounce_count($u, true); update_send_count($u, true); } set_account_preference($user->id, 'maildisabled', $values['maildisabled']); // process the change of the authinstance and or the remoteuser if (isset($values['authinstance']) && isset($values['remoteusername'])) { // Authinstance can be changed by institutional admins if both the // old and new authinstances belong to the admin's institutions $authinst = get_records_select_assoc('auth_instance', 'id = ? OR id = ?', array($values['authinstance'], $user->authinstance)); // But don't bother if the auth instance doesn't take a remote username $authobj = AuthFactory::create($values['authinstance']); if ($USER->get('admin') || $USER->is_institutional_admin($authinst[$values['authinstance']]->institution) && ($USER->is_institutional_admin($authinst[$user->authinstance]->institution) || $user->authinstance == 1)) { if ($authobj->needs_remote_username()) { // determine the current remoteuser $current_remotename = get_field('auth_remote_user', 'remoteusername', 'authinstance', $user->authinstance, 'localusr', $user->id); if (!$current_remotename) { $current_remotename = $user->username; } // if the remoteuser is empty if (strlen(trim($values['remoteusername'])) == 0) { delete_records('auth_remote_user', 'authinstance', $user->authinstance, 'localusr', $user->id); } // what should the new remoteuser be $new_remoteuser = get_field('auth_remote_user', 'remoteusername', 'authinstance', $values['authinstance'], 'localusr', $user->id); // save the remotename for the target existence check $target_remotename = $new_remoteuser; if (!$new_remoteuser) { $new_remoteuser = $user->username; } if (strlen(trim($values['remoteusername'])) > 0) { // value changed on page - use it if ($values['remoteusername'] != $current_remotename) { $new_remoteuser = $values['remoteusername']; } } // only update remote name if the input actually changed on the page or it doesn't yet exist if ($current_remotename != $new_remoteuser || !$target_remotename) { // only remove the ones related to this traget authinstance as we now allow multiple // for dual login mechanisms delete_records('auth_remote_user', 'authinstance', $values['authinstance'], 'localusr', $user->id); insert_record('auth_remote_user', (object) array('authinstance' => $values['authinstance'], 'remoteusername' => $new_remoteuser, 'localusr' => $user->id)); } } // update the ai on the user master $user->authinstance = $values['authinstance']; // update the global $authobj to match the new authinstance // this is used by the password/username change methods // if either/both has been requested at the same time $authobj = AuthFactory::create($user->authinstance); } } // Only change the pw if the new auth instance allows for it if (method_exists($authobj, 'change_password')) { $user->passwordchange = (int) (isset($values['passwordchange']) && $values['passwordchange'] == 'on' ? 1 : 0); if (isset($values['password']) && $values['password'] !== '') { $userobj = new User(); $userobj = $userobj->find_by_id($user->id); $user->password = $authobj->change_password($userobj, $values['password']); $user->salt = $userobj->salt; unset($userobj); } } else { // inform the user that the chosen auth instance doesn't allow password changes // but only if they tried changing it if (isset($values['password']) && $values['password'] !== '') { $SESSION->add_error_msg(get_string('passwordchangenotallowed', 'admin')); // Set empty pw with salt $user->password = ''; $user->salt = auth_get_random_salt(); } } if (isset($values['username']) && $values['username'] !== '') { $userobj = new User(); $userobj = $userobj->find_by_id($user->id); if ($userobj->username != $values['username']) { // Only change the username if the auth instance allows for it if (method_exists($authobj, 'change_username')) { // check the existence of the chosen username try { if ($authobj->user_exists($values['username'])) { // set an error message if it is already in use $SESSION->add_error_msg(get_string('usernameexists', 'account')); } } catch (AuthUnknownUserException $e) { // update the username otherwise $user->username = $authobj->change_username($userobj, $values['username']); } } else { // inform the user that the chosen auth instance doesn't allow username changes $SESSION->add_error_msg(get_string('usernamechangenotallowed', 'admin')); } } unset($userobj); } // OVERWRITE 4: insert if (isset($values['email']) && !empty($values['email']) && $values['email'] != $user->email) { global $CFG; $user->email = $values['email']; $mhr_user = $CFG->current_app->getUserById($user->id); $mhr_user->setEmailAddress($values['email']); } // END OVERWRITE 4 db_begin(); update_record('usr', $user); delete_records('usr_tag', 'usr', $user->id); if (is_array($values['tags'])) { $values['tags'] = check_case_sensitive($values['tags'], 'usr_tag'); foreach (array_unique($values['tags']) as $tag) { if (empty($tag)) { continue; } insert_record('usr_tag', (object) array('usr' => $user->id, 'tag' => strtolower($tag))); } } db_commit(); $SESSION->add_ok_msg(get_string('usersitesettingschanged', 'admin')); redirect('/admin/users/edit.php?id=' . $user->id); }
/** * Always use this function for all emails to users * * @param object $userto user object to send email to. must contain firstname,lastname,preferredname,email * @param object $userfrom user object to send email from. If null, email will come from mahara * @param string $subject email subject * @param string $messagetext text version of email * @param string $messagehtml html version of email (will send both html and text) * @param array $customheaders email headers * @throws EmailException * @throws EmailDisabledException */ function email_user($userto, $userfrom, $subject, $messagetext, $messagehtml = '', $customheaders = null) { global $IDPJUMPURL; static $mnetjumps = array(); if (!get_config('sendemail')) { // You can entirely disable Mahara from sending any e-mail via the // 'sendemail' configuration variable return true; } if (empty($userto)) { throw new InvalidArgumentException("empty user given to email_user"); } if (!($mailinfo = can_receive_email($userto))) { throw new EmailDisabledException("email for this user has been disabled"); } // If the user is a remote xmlrpc user, trawl through the email text for URLs // to our wwwroot and modify the url to direct the user's browser to login at // their home site before hitting the link on this site if (!empty($userto->mnethostwwwroot) && !empty($userto->mnethostapp)) { require_once get_config('docroot') . 'auth/xmlrpc/lib.php'; // Form the request url to hit the idp's jump.php if (isset($mnetjumps[$userto->mnethostwwwroot])) { $IDPJUMPURL = $mnetjumps[$userto->mnethostwwwroot]; } else { $mnetjumps[$userto->mnethostwwwroot] = $IDPJUMPURL = PluginAuthXmlrpc::get_jump_url_prefix($userto->mnethostwwwroot, $userto->mnethostapp); } $wwwroot = get_config('wwwroot'); $messagetext = preg_replace_callback('%(' . $wwwroot . '([\\w_:\\?=#&@/;.~-]*))%', 'localurl_to_jumpurl', $messagetext); $messagehtml = preg_replace_callback('%href=["\'`](' . $wwwroot . '([\\w_:\\?=#&@/;.~-]*))["\'`]%', 'localurl_to_jumpurl', $messagehtml); } require_once 'phpmailer/class.phpmailer.php'; $mail = new phpmailer(); // Leaving this commented out - there's no reason for people to know this //$mail->Version = 'Mahara ' . get_config('release'); $mail->PluginDir = get_config('libroot') . 'phpmailer/'; $mail->CharSet = 'UTF-8'; $smtphosts = get_config('smtphosts'); if ($smtphosts == 'qmail') { // use Qmail system $mail->IsQmail(); } else { if (empty($smtphosts)) { // use PHP mail() = sendmail $mail->IsMail(); } else { $mail->IsSMTP(); // use SMTP directly $mail->Host = get_config('smtphosts'); if (get_config('smtpuser')) { // Use SMTP authentication $mail->SMTPAuth = true; $mail->Username = get_config('smtpuser'); $mail->Password = get_config('smtppass'); } } } if (get_config('bounces_handle') && isset($mailinfo->owner)) { $mail->Sender = generate_email_processing_address($mailinfo->owner, $userto); } if (empty($userfrom) || $userfrom->email == get_config('noreplyaddress')) { if (empty($mail->Sender)) { $mail->Sender = get_config('noreplyaddress'); } $mail->From = get_config('noreplyaddress'); $mail->FromName = isset($userfrom->id) ? display_name($userfrom, $userto) : get_config('sitename'); $customheaders[] = 'Precedence: Bulk'; // Try to avoid pesky out of office responses $messagetext .= "\n\n" . get_string('pleasedonotreplytothismessage') . "\n"; if ($messagehtml) { $messagehtml .= "\n\n<p>" . get_string('pleasedonotreplytothismessage') . "</p>\n"; } } else { if (empty($mail->Sender)) { $mail->Sender = $userfrom->email; } $mail->From = $userfrom->email; $mail->FromName = display_name($userfrom, $userto); } $replytoset = false; if (!empty($customheaders) && is_array($customheaders)) { foreach ($customheaders as $customheader) { $mail->AddCustomHeader($customheader); if (0 === stripos($customheader, 'reply-to')) { $replytoset = true; } } } if (!$replytoset) { $mail->AddReplyTo($mail->From, $mail->FromName); } $mail->Subject = substr(stripslashes($subject), 0, 900); if ($to = get_config('sendallemailto')) { // Admins can configure the system to send all email to a given address // instead of whoever would receive it, useful for debugging. $mail->addAddress($to); $notice = get_string('debugemail', 'mahara', display_name($userto, $userto), $userto->email); $messagetext = $notice . "\n\n" . $messagetext; if ($messagehtml) { $messagehtml = '<p>' . hsc($notice) . '</p>' . $messagehtml; } $usertoname = display_name($userto, $userto, true) . ' (' . get_string('divertingemailto', 'mahara', $to) . ')'; } else { $usertoname = display_name($userto, $userto); if (empty($userto->email)) { throw new EmailException("Cannot send email to {$usertoname} with subject {$subject}. User has no primary email address set."); } $mail->AddAddress($userto->email, $usertoname); $to = $userto->email; } $mail->WordWrap = 79; if ($messagehtml) { $mail->IsHTML(true); $mail->Encoding = 'quoted-printable'; $mail->Body = $messagehtml; $mail->AltBody = $messagetext; } else { $mail->IsHTML(false); $mail->Body = $messagetext; } if ($mail->Send()) { if ($logfile = get_config('emaillog')) { $docroot = get_config('docroot'); @($client = (string) $_SERVER['REMOTE_ADDR']); @($script = (string) $_SERVER['SCRIPT_FILENAME']); if (strpos($script, $docroot) === 0) { $script = substr($script, strlen($docroot)); } $line = "{$to} <- {$mail->From} - " . str_shorten_text($mail->Subject, 200); @error_log('[' . date("Y-m-d h:i:s") . "] [{$client}] [{$script}] {$line}\n", 3, $logfile); } // Update the count of sent mail update_send_count($userto); return true; } throw new EmailException("Couldn't send email to {$usertoname} with subject {$subject}. " . "Error from phpmailer was: " . $mail->ErrorInfo); }
function edituser_site_submit(Pieform $form, $values) { if (!($user = get_record('usr', 'id', $values['id']))) { return false; } if (isset($values['password']) && $values['password'] !== '') { $user->password = $values['password']; $user->salt = ''; } $user->passwordchange = (int) ($values['passwordchange'] == 'on'); $user->quota = $values['quota']; $user->expiry = db_format_timestamp($values['expiry']); global $USER; if ($USER->get('admin')) { // Not editable by institutional admins $user->staff = (int) ($values['staff'] == 'on'); $user->admin = (int) ($values['admin'] == 'on'); if ($user->admin) { activity_add_admin_defaults(array($user->id)); } } if ($values['maildisabled'] == 0 && get_account_preference($user->id, 'maildisabled') == 1) { // Reset the sent and bounce counts otherwise mail will be disabled // on the next send attempt $u = new StdClass(); $u->email = $user->email; $u->id = $user->id; update_bounce_count($u, true); update_send_count($u, true); } set_account_preference($user->id, 'maildisabled', $values['maildisabled']); // Authinstance can be changed by institutional admins if both the // old and new authinstances belong to the admin's institutions $remotename = get_field('auth_remote_user', 'remoteusername', 'authinstance', $user->authinstance, 'localusr', $user->id); if (!$remotename) { $remotename = $user->username; } if (isset($values['authinstance']) && ($values['authinstance'] != $user->authinstance || isset($values['remoteusername']) && $values['remoteusername'] != $remotename)) { $authinst = get_records_select_assoc('auth_instance', 'id = ? OR id = ?', array($values['authinstance'], $user->authinstance)); if ($USER->get('admin') || $USER->is_institutional_admin($authinst[$values['authinstance']]->institution) && $USER->is_institutional_admin($authinst[$user->authinstance]->institution)) { delete_records('auth_remote_user', 'localusr', $user->id); if ($authinst[$values['authinstance']]->authname != 'internal') { if (isset($values['remoteusername']) && strlen($values['remoteusername']) > 0) { $un = $values['remoteusername']; } else { $un = $remotename; } insert_record('auth_remote_user', (object) array('authinstance' => $values['authinstance'], 'remoteusername' => $un, 'localusr' => $user->id)); } $user->authinstance = $values['authinstance']; } } update_record('usr', $user); redirect('/admin/users/edit.php?id=' . $user->id); }
/** * Always use this function for all emails to users * * @param object $userto user object to send email to. must contain firstname,lastname,preferredname,email * @param object $userfrom user object to send email from. If null, email will come from mahara * @param string $subject email subject * @param string $messagetext text version of email * @param string $messagehtml html version of email (will send both html and text) * @param array $customheaders email headers * @throws EmailException * @throws EmailDisabledException */ function email_user($userto, $userfrom, $subject, $messagetext, $messagehtml = '', $customheaders = null) { global $IDPJUMPURL; static $mnetjumps = array(); if (!get_config('sendemail')) { // You can entirely disable Mahara from sending any e-mail via the // 'sendemail' configuration variable return true; } if (empty($userto)) { throw new InvalidArgumentException("empty user given to email_user"); } if (isset($userto->id) && empty($userto->ignoredisabled)) { $maildisabled = property_exists($userto, 'maildisabled') ? $userto->maildisabled : get_account_preference($userto->id, 'maildisabled') == 1; if ($maildisabled) { throw new EmailDisabledException("email for this user has been disabled"); } } // If the user is a remote xmlrpc user, trawl through the email text for URLs // to our wwwroot and modify the url to direct the user's browser to login at // their home site before hitting the link on this site if (!empty($userto->mnethostwwwroot) && !empty($userto->mnethostapp)) { require_once get_config('docroot') . 'auth/xmlrpc/lib.php'; // Form the request url to hit the idp's jump.php if (isset($mnetjumps[$userto->mnethostwwwroot])) { $IDPJUMPURL = $mnetjumps[$userto->mnethostwwwroot]; } else { $mnetjumps[$userto->mnethostwwwroot] = $IDPJUMPURL = PluginAuthXmlrpc::get_jump_url_prefix($userto->mnethostwwwroot, $userto->mnethostapp); } $wwwroot = get_config('wwwroot'); $messagetext = preg_replace_callback('%(' . $wwwroot . '([\\w_:\\?=#&@/;.~-]*))%', 'localurl_to_jumpurl', $messagetext); $messagehtml = preg_replace_callback('%href=["\'`](' . $wwwroot . '([\\w_:\\?=#&@/;.~-]*))["\'`]%', 'localurl_to_jumpurl', $messagehtml); } require_once 'phpmailer/PHPMailerAutoload.php'; $mail = new PHPMailer(true); $mail->CharSet = 'UTF-8'; $smtphosts = get_config('smtphosts'); if ($smtphosts == 'qmail') { // use Qmail system $mail->IsQmail(); } else { if (empty($smtphosts)) { // use PHP mail() = sendmail $mail->IsMail(); } else { $mail->IsSMTP(); // use SMTP directly $mail->Host = get_config('smtphosts'); if (get_config('smtpuser')) { // Use SMTP authentication $mail->SMTPAuth = true; $mail->Username = get_config('smtpuser'); $mail->Password = get_config('smtppass'); $mail->SMTPSecure = get_config('smtpsecure'); $mail->Port = get_config('smtpport'); if (get_config('smtpsecure') && !get_config('smtpport')) { // Encrypted connection with no port. Use default one. if (get_config('smtpsecure') == 'ssl') { $mail->Port = 465; } elseif (get_config('smtpsecure') == 'tls') { $mail->Port = 587; } } } } } if (get_config('bounces_handle') && !empty($userto->id) && empty($maildisabled)) { $mail->Sender = generate_email_processing_address($userto->id, $userto); } if (empty($userfrom) || $userfrom->email == get_config('noreplyaddress')) { if (empty($mail->Sender)) { $mail->Sender = get_config('noreplyaddress'); } $mail->From = get_config('noreplyaddress'); $mail->FromName = isset($userfrom->id) ? display_name($userfrom, $userto) : get_config('sitename'); $customheaders[] = 'Precedence: Bulk'; // Try to avoid pesky out of office responses $messagetext .= "\n\n" . get_string('pleasedonotreplytothismessage') . "\n"; if ($messagehtml) { $messagehtml .= "\n\n<p>" . get_string('pleasedonotreplytothismessage') . "</p>\n"; } } else { if (empty($mail->Sender)) { $mail->Sender = $userfrom->email; } $mail->From = $userfrom->email; $mail->FromName = display_name($userfrom, $userto); } $replytoset = false; if (!empty($customheaders) && is_array($customheaders)) { foreach ($customheaders as $customheader) { // To prevent duplicated declaration of the field "Message-ID", // don't add it into the $mail->CustomHeader[]. if (false === stripos($customheader, 'message-id')) { // Hack the fields "In-Reply-To" and "References": // add touser<userID> if (0 === stripos($customheader, 'in-reply-to') || 0 === stripos($customheader, 'references')) { $customheader = preg_replace('/<forumpost(\\d+)/', '<forumpost${1}touser' . $userto->id, $customheader); } $mail->AddCustomHeader($customheader); } else { list($h, $msgid) = explode(':', $customheader, 2); // Hack the "Message-ID": add touser<userID> to make sure // the "Message-ID" is unique $msgid = preg_replace('/<forumpost(\\d+)/', '<forumpost${1}touser' . $userto->id, $msgid); $mail->MessageID = trim($msgid); } if (0 === stripos($customheader, 'reply-to')) { $replytoset = true; } } } $mail->Subject = substr(stripslashes($subject), 0, 900); try { if ($to = get_config('sendallemailto')) { // Admins can configure the system to send all email to a given address // instead of whoever would receive it, useful for debugging. $usertoname = display_name($userto, $userto, true) . ' (' . get_string('divertingemailto', 'mahara', $to) . ')'; $mail->addAddress($to); $notice = get_string('debugemail', 'mahara', display_name($userto, $userto), $userto->email); $messagetext = $notice . "\n\n" . $messagetext; if ($messagehtml) { $messagehtml = '<p>' . hsc($notice) . '</p>' . $messagehtml; } } else { $usertoname = display_name($userto, $userto); $mail->AddAddress($userto->email, $usertoname); $to = $userto->email; } if (!$replytoset) { $mail->AddReplyTo($mail->From, $mail->FromName); } } catch (phpmailerException $e) { // If there's a phpmailer error already, assume it's an invalid address throw new InvalidEmailException("Cannot send email to {$usertoname} with subject {$subject}. Error from phpmailer was: " . $mail->ErrorInfo); } $mail->WordWrap = 79; if ($messagehtml) { $mail->IsHTML(true); $mail->Encoding = 'quoted-printable'; $mail->Body = $messagehtml; $mail->AltBody = $messagetext; } else { $mail->IsHTML(false); $mail->Body = $messagetext; } try { $sent = $mail->Send(); } catch (phpmailerException $e) { $sent = false; } if ($sent) { if ($logfile = get_config('emaillog')) { $docroot = get_config('docroot'); @($client = (string) $_SERVER['REMOTE_ADDR']); @($script = (string) $_SERVER['SCRIPT_FILENAME']); if (strpos($script, $docroot) === 0) { $script = substr($script, strlen($docroot)); } $line = "{$to} <- {$mail->From} - " . str_shorten_text($mail->Subject, 200); @error_log('[' . date("Y-m-d h:i:s") . "] [{$client}] [{$script}] {$line}\n", 3, $logfile); } if (get_config('bounces_handle')) { // Update the count of sent mail update_send_count($userto); } return true; } throw new EmailException("Couldn't send email to {$usertoname} with subject {$subject}. " . "Error from phpmailer was: " . $mail->ErrorInfo); }
function accountprefs_submit(Pieform $form, $values) { global $USER, $SESSION; $authobj = AuthFactory::create($USER->authinstance); db_begin(); $ispasswordchanged = false; if (isset($values['password1']) && $values['password1'] !== '') { global $authclass; $password = $authobj->change_password($USER, $values['password1']); $USER->password = $password; $USER->passwordchange = 0; $USER->commit(); $ispasswordchanged = true; } // use this as looping through values is not safe. $expectedprefs = expected_account_preferences(); if ($values['maildisabled'] == 0 && get_account_preference($USER->get('id'), 'maildisabled') == 1) { // Reset the sent and bounce counts otherwise mail will be disabled // on the next send attempt $u = new StdClass(); $u->email = $USER->get('email'); $u->id = $USER->get('id'); update_bounce_count($u, true); update_send_count($u, true); } // Remember the user's language & theme prefs, so we can reload the page if they change them $oldlang = $USER->get_account_preference('lang'); $oldtheme = $USER->get_account_preference('theme'); $oldgroupsideblockmaxgroups = $USER->get_account_preference('groupsideblockmaxgroups'); $oldgroupsideblocksortby = $USER->get_account_preference('groupsideblocksortby'); if (get_config('allowmobileuploads')) { // Make sure the mobile token is formatted / saved correctly $values['mobileuploadtoken'] = array_filter($values['mobileuploadtoken']); $new_token_pref = empty($values['mobileuploadtoken']) ? null : '|' . join('|', $values['mobileuploadtoken']) . '|'; $USER->set_account_preference('mobileuploadtoken', $new_token_pref); unset($values['mobileuploadtoken']); } // Set user account preferences foreach ($expectedprefs as $eprefkey => $epref) { if (isset($values[$eprefkey]) && $values[$eprefkey] !== get_account_preference($USER->get('id'), $eprefkey)) { $USER->set_account_preference($eprefkey, $values[$eprefkey]); } } $returndata = array(); if (isset($values['username']) && $values['username'] != $USER->get('username')) { $USER->username = $values['username']; $USER->commit(); $returndata['username'] = $values['username']; } $reload = false; if (get_config('cleanurls') && isset($values['urlid']) && $values['urlid'] != $USER->get('urlid')) { $USER->urlid = $values['urlid']; $USER->commit(); $reload = true; } if ($ispasswordchanged) { // Destroy other sessions of the user require_once get_config('docroot') . 'auth/session.php'; remove_user_sessions($USER->get('id')); } db_commit(); $returndata['message'] = get_string('prefssaved', 'account'); if (isset($values['theme']) && $values['theme'] != $oldtheme) { $USER->update_theme(); $reload = true; } if (isset($values['lang']) && $values['lang'] != $oldlang) { // The session language pref is used when the user has no user pref, // and when logged out. $SESSION->set('lang', $values['lang']); $returndata['message'] = get_string_from_language($values['lang'], 'prefssaved', 'account'); $reload = true; } if (isset($values['groupsideblockmaxgroups']) && $values['groupsideblockmaxgroups'] != $oldgroupsideblockmaxgroups) { $reload = true; } if ($values['groupsideblocksortby'] != $oldgroupsideblocksortby) { $reload = true; } $reload = plugin_account_prefs_submit($form, $values) || $reload; if (!empty($reload)) { // Use PIEFORM_CANCEL here to force a page reload and show the new language. $returndata['location'] = get_config('wwwroot') . 'account/index.php'; $SESSION->add_ok_msg($returndata['message']); $form->json_reply(PIEFORM_CANCEL, $returndata); } $form->json_reply(PIEFORM_OK, $returndata); }
update_error_count($email["id"], $email["error_count"] + 1); $incidence_text = "Error while sending email: [" . $mail->ErrorInfo . "] Cancelled: No more sending attempts allowed"; add_incidence($email["id"], $incidence_text); cancel($email["id"]); $logger->add_log_incidence(array($email["id"], $email["to"], "Email cancelled", "No more sending attempts allowed")); echo "No more attempts allowed, cancelled"; } else { update_error_count($email["id"], $email["error_count"] + 1); $incidence_text = "Error while sending email: [" . $mail->ErrorInfo . "] Scheduled for one more try"; add_incidence($email["id"], $incidence_text); $logger->add_log_incidence(array($email["id"], $email["to"], "Email rescheduled", $incidence_text)); echo "Scheduled for one more try"; } } else { mark_as_sent($email["id"]); update_send_count($email["id"], $email["send_count"] + 1); update_sentdate($email["id"], $now); $logger->add_log_delivery(array($email["id"], "Email delivered", $email["from"], $email["to"], $email["subject"])); echo "Email delivered"; // Sleeping usleep(DELIVERY_INTERVAL / 100); } echo "\n"; unsetsendingnow($email["id"]); // Check if maximum delivery timeout have been reached if (mktime() - $timecontrol_start > MAXIMUM_DELIVERY_TIMEOUT) { echo "Delivery proccess automatically stopped before it finished because of too many time spent on delivering. Time spent: " . (mktime() - $timecontrol_start) . " seconds. Maximum time allowed: " . MAXIMUM_DELIVERY_TIMEOUT . " seconds\n"; $logger->add_log_incidence(array(0, "", "Maximum delivery timeout reached", "The delivery proccess have been automatically stopped before it finishes because of too many time spent on delivering. Time spent: " . (mktime() - $timecontrol_start) . " seconds. Maximum time allowed: " . MAXIMUM_DELIVERY_TIMEOUT . " seconds")); break; } }
function accountprefs_submit(Pieform $form, $values) { global $USER; $authobj = AuthFactory::create($USER->authinstance); db_begin(); if (isset($values['password1']) && $values['password1'] !== '') { global $authclass; $password = $authobj->change_password($USER, $values['password1']); $USER->password = $password; $USER->passwordchange = 0; $USER->commit(); } // use this as looping through values is not safe. $expectedprefs = expected_account_preferences(); if ($values['maildisabled'] == 0 && get_account_preference($USER->get('id'), 'maildisabled') == 1) { // Reset the sent and bounce counts otherwise mail will be disabled // on the next send attempt $u = new StdClass(); $u->email = $USER->get('email'); $u->id = $USER->get('id'); update_bounce_count($u, true); update_send_count($u, true); } foreach (array_keys($expectedprefs) as $pref) { if (isset($values[$pref])) { $USER->set_account_preference($pref, $values[$pref]); } } $returndata = array(); if (isset($values['username']) && $values['username'] != $USER->get('username')) { $USER->username = $values['username']; $USER->commit(); $returndata['username'] = $values['username']; } db_commit(); $returndata['message'] = get_string('prefssaved', 'account'); $form->json_reply(PIEFORM_OK, $returndata); }