コード例 #1
0
 /**
  * Constructor (generates a connection to the API)
  * @param   string  Clockworksms API key required to use the plugin
  * @return  void
  */
 public function __construct($apiKey = null)
 {
     $plugin = ClockworksmsPlugin::create();
     $clockWorkSMSPlugin = $plugin->get('tool_enable');
     if (empty($apiKey)) {
         $clockWorkSMSApiKey = $plugin->get('api_key');
     } else {
         $clockWorkSMSApiKey = $apiKey;
     }
     $this->table = Database::get_main_table('user_field_values');
     if ($clockWorkSMSPlugin == true) {
         $this->apiKey = $clockWorkSMSApiKey;
         // Setting Clockworksms api
         if (!defined('CONFIG_SECURITY_API_KEY')) {
             define('CONFIG_SECURITY_API_KEY', $this->apiKey);
         }
         $trimmedApiKey = trim(CONFIG_SECURITY_API_KEY);
         if (!empty($trimmedApiKey)) {
             $this->api = new Clockwork(CONFIG_SECURITY_API_KEY);
         } else {
             $this->api = new Clockwork(' ');
             $recipient_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
             $email_form = api_get_setting('emailAdministrator');
             $emailsubject = 'Clockworksms error';
             $emailbody = 'Key cannot be blank';
             $sender_name = $recipient_name;
             $email_admin = $email_form;
             api_mail_html($recipient_name, $email_form, $emailsubject, $emailbody, $sender_name, $email_admin);
         }
         $this->plugin_enabled = true;
     }
 }
コード例 #2
0
$entityManager = Database::getManager();
$sessionRepo = $entityManager->getRepository('ChamiloCoreBundle:Session');
$accessUrlRepo = $entityManager->getRepository('ChamiloCoreBundle:AccessUrl');
$sessions = $sessionRepo->createQueryBuilder('s')->where('s.accessEndDate LIKE :date')->setParameter('date', "{$endDate}%")->getQuery()->getResult();
if (empty($sessions)) {
    echo "No sessions finishing today {$endDate}" . PHP_EOL;
    exit;
}
$administrator = ['complete_name' => api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS), 'email' => api_get_setting('emailAdministrator')];
foreach ($sessions as $session) {
    $sessionUsers = $session->getUsers();
    if (empty($sessionUsers)) {
        echo 'No users to send mail' . PHP_EOL;
        exit;
    }
    foreach ($sessionUsers as $sessionUser) {
        $user = $sessionUser->getUser();
        $subjectTemplate = new Template(null, false, false, false, false, false);
        $subjectTemplate->assign('session_name', $session->getName());
        $subjectLayout = $subjectTemplate->get_template('mail/cron_course_finished_subject.tpl');
        $bodyTemplate = new Template(null, false, false, false, false, false);
        $bodyTemplate->assign('complete_user_name', $user->getCompleteName());
        $bodyTemplate->assign('session_name', $session->getName());
        $bodyLayout = $bodyTemplate->get_template('mail/cron_course_finished_body.tpl');
        api_mail_html($user->getCompleteName(), $user->getEmail(), $subjectTemplate->fetch($subjectLayout), $bodyTemplate->fetch($bodyLayout), $administrator['complete_name'], $administrator['email']);
        echo '============' . PHP_EOL;
        echo "Email sent to: {$user->getCompleteName()} ({$user->getEmail()})" . PHP_EOL;
        echo "Session: {$session->getName()}" . PHP_EOL;
        echo "End date: {$session->getAccessEndDate()->format('Y-m-d h:i')}" . PHP_EOL;
    }
}
コード例 #3
0
 /**
  * Asks the author (through e-mail) for additional information about the given course request.
  * @param int/string $id            The database primary id of the given request.
  * @return bool                     Returns TRUE on success or FALSE on failure.
  */
 public static function ask_for_additional_info($id)
 {
     $id = (int) $id;
     // Retrieve request's data
     $course_request_info = self::get_course_request_info($id);
     if (!is_array($course_request_info)) {
         return false;
     }
     $user_id = intval($course_request_info['user_id']);
     if ($user_id <= 0) {
         return false;
     }
     $user_info = api_get_user_info($user_id);
     if (!is_array($user_info)) {
         return false;
     }
     $code = $course_request_info['code'];
     $info = intval($course_request_info['info']);
     // Error is to be returned on a repeated attempt for asking additional information.
     if (!empty($info)) {
         return false;
     }
     // E-mail notification.
     // E-mail language: The platform language seems to be the best choice.
     $email_language = api_get_setting('platformLanguage');
     $email_subject = sprintf(get_lang('CourseRequestAskInfoEmailSubject', null, $email_language), '[' . api_get_setting('siteName') . ']', $code);
     $email_body = get_lang('Dear', null, $email_language) . ' ';
     $email_body .= api_get_person_name($user_info['firstname'], $user_info['lastname'], null, null, $email_language) . ",\n\n";
     $email_body .= sprintf(get_lang('CourseRequestAskInfoEmailText', null, $email_language), $code) . "\n";
     $email_body .= "\n" . get_lang('Formula', null, $email_language) . "\n";
     $email_body .= api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname')) . "\n";
     $email_body .= get_lang('Manager', null, $email_language) . ' ' . api_get_setting('siteName') . "\n";
     $email_body .= get_lang('Phone', null, $email_language) . ': ' . api_get_setting('administratorTelephone') . "\n";
     $email_body .= get_lang('Email', null, $email_language) . ': ' . api_get_setting('emailAdministrator') . "\n";
     $email_body .= "\n" . get_lang('CourseRequestLegalNote', null, $email_language) . "\n";
     $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
     $sender_email = api_get_setting('emailAdministrator');
     $recipient_name = api_get_person_name($user_info['firstname'], $user_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS);
     $recipient_email = $user_info['mail'];
     $extra_headers = 'Bcc: ' . $sender_email;
     $additionalParameters = array('smsType' => SmsPlugin::COURSE_OPENING_REQUEST_CODE, 'userId' => $user_id, 'courseCode' => $code);
     $result = api_mail_html($recipient_name, $recipient_email, $email_subject, $email_body, $sender_name, $sender_email, null, null, null, $additionalParameters);
     if (!$result) {
         return false;
     }
     // Marking the fact that additional information about the request has been asked.
     $sql = "UPDATE " . Database::get_main_table(TABLE_MAIN_COURSE_REQUEST) . "\n                SET info = 1 WHERE id = " . $id;
     $result = Database::query($sql) !== false;
     return $result;
 }
コード例 #4
0
ファイル: user_edit.php プロジェクト: jloguercio/chamilo-lms
        $auth_source = $userInfo['auth_source'];
        $password = $user['password']['password_auto'] == '1' ? api_generate_password() : $user['password']['password'];
        UserManager::update_user($userId, $userInfo['firstname'], $userInfo['lastname'], $userInfo['username'], $password, $auth_source, $userInfo['email'], $userInfo['status'], $userInfo['official_code'], $userInfo['phone'], $userInfo['picture_uri'], $userInfo['expiration_date'], $userInfo['active'], $userInfo['creator_id'], $userInfo['hr_dept_id'], null, $userInfo['language'], null, false, $resetPassword);
        if (!empty($email) && $send_mail) {
            $emailsubject = '[' . api_get_setting('platform.site_name') . '] ' . get_lang('YourReg') . ' ' . api_get_setting('platform.site_name');
            $portal_url = api_get_path(WEB_PATH);
            if (api_is_multiple_url_enabled()) {
                $access_url_id = api_get_current_access_url_id();
                if ($access_url_id != -1) {
                    $url = api_get_access_url($access_url_id);
                    $portal_url = $url['url'];
                }
            }
            $emailbody = get_lang('Dear') . " " . stripslashes(api_get_person_name($userInfo['firstname'], $userInfo['lastname'])) . ",\n\n" . get_lang('YouAreReg') . " " . api_get_setting('platform.site_name') . " " . get_lang('WithTheFollowingSettings') . "\n\n" . get_lang('Username') . " : " . $username . "\n" . get_lang('Pass') . " : " . stripslashes($password) . "\n\n" . get_lang('Address') . " " . api_get_setting('platform.site_name') . " " . get_lang('Is') . " : " . $portal_url . "\n\n" . get_lang('Problem') . "\n\n" . get_lang('SignatureFormula') . ",\n\n" . api_get_person_name(api_get_setting('admin.administrator_name'), api_get_setting('admin.administrator_surname')) . "\n" . get_lang('Manager') . " " . api_get_setting('platform.site_name') . "\nT. " . api_get_setting('admin.administrator_phone') . "\n" . get_lang('Email') . " : " . api_get_setting('admin.administrator_email');
            $emailbody = nl2br($emailbody);
            api_mail_html(api_get_person_name($userInfo['firstname'], $userInfo['lastname'], null, PERSON_NAME_EMAIL_ADDRESS), $email, $emailsubject, $emailbody);
        }
        Security::clear_token();
        $tok = Security::get_token();
        header('Location: ' . $url . '&message=1');
        exit;
    }
} else {
    if (isset($_POST['submit'])) {
        Security::clear_token();
    }
    $token = Security::get_token();
    $form->addElement('hidden', 'sec_token');
    $form->setConstants(array('sec_token' => $token));
}
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH) . "mySpace/student.php", "name" => get_lang('UserList'));
コード例 #5
0
ファイル: login.lib.php プロジェクト: omaoibrahim/chamilo-lms
 /**
  * @param User $user
  */
 public static function sendResetEmail(User $user)
 {
     //if (null === $user->getConfirmationToken()) {
     $uniqueId = api_get_unique_id();
     $user->setConfirmationToken($uniqueId);
     $user->setPasswordRequestedAt(new \DateTime());
     Database::getManager()->persist($user);
     Database::getManager()->flush();
     $url = api_get_path(WEB_CODE_PATH) . 'auth/reset.php?token=' . $uniqueId;
     $mailTemplate = new Template(null, false, false, false, false, false);
     $mailTemplate->assign('complete_user_name', $user->getCompleteName());
     $mailTemplate->assign('link', $url);
     $mailLayout = $mailTemplate->get_template('mail/reset_password.tpl');
     $mailSubject = get_lang('ResetPasswordInstructions');
     $mailBody = $mailTemplate->fetch($mailLayout);
     api_mail_html($user->getCompleteName(), $user->getEmail(), $mailSubject, $mailBody);
     Display::addFlash(Display::return_message(get_lang('CheckYourEmailAndFollowInstructions')));
     //}
 }
コード例 #6
0
 $transferAccounts = $plugin->getTransferAccounts();
 $userInfo = api_get_user_info($sale['user_id']);
 $form = new FormValidator('success', 'POST', api_get_self(), null, null, FormValidator::LAYOUT_INLINE);
 if ($form->validate()) {
     $formValues = $form->getSubmitValues();
     if (isset($formValues['cancel'])) {
         $plugin->cancelSale($sale['id']);
         unset($_SESSION['bc_sale_id']);
         header('Location: ' . api_get_path(WEB_PLUGIN_PATH) . 'buycourses/index.php');
         exit;
     }
     $messageTemplate = new Template();
     $messageTemplate->assign('user', $userInfo);
     $messageTemplate->assign('sale', ['date' => api_format_date($sale['date'], DATE_FORMAT_LONG_NO_DAY), 'product' => $sale['product_name'], 'currency' => $currency['iso_code'], 'price' => $sale['price'], 'reference' => $sale['reference']]);
     $messageTemplate->assign('transfer_accounts', $transferAccounts);
     api_mail_html($userInfo['complete_name'], $userInfo['email'], $plugin->get_lang('bc_subject'), $messageTemplate->fetch('buycourses/view/message_transfer.tpl'));
     Display::addFlash(Display::return_message(sprintf($plugin->get_lang('PurchaseStatusX'), $plugin->get_lang('PendingReasonByTransfer')), 'success', false));
     unset($_SESSION['bc_sale_id']);
     header('Location: ' . api_get_path(WEB_PLUGIN_PATH) . 'buycourses/src/course_catalog.php');
     exit;
 }
 $form->addButton('confirm', $plugin->get_lang('ConfirmOrder'), 'check', 'success');
 $form->addButtonCancel($plugin->get_lang('CancelOrder'), 'cancel');
 $template = new Template();
 if ($buyingCourse) {
     $template->assign('course', $course);
 } elseif ($buyingSession) {
     $template->assign('session', $session);
 }
 $template->assign('buying_course', $buyingCourse);
 $template->assign('buying_session', $buyingSession);
コード例 #7
0
 /**
  * Send the invitation by mail.
  *
  * @param    invitedUser - the userId (course user) or emailaddress of additional user
  * $param       $invitation_code - the unique invitation code for the URL
  * @return    void
  */
 static function send_invitation_mail($invitedUser, $invitation_code, $invitation_title, $invitation_text)
 {
     global $_user, $_course, $_configuration;
     $portal_url = api_get_path(WEB_CODE_PATH);
     if (api_is_multiple_url_enabled()) {
         $access_url_id = api_get_current_access_url_id();
         if ($access_url_id != -1) {
             $url = api_get_access_url($access_url_id);
             $portal_url = $url['url'];
         }
     }
     // Replacing the **link** part with a valid link for the user
     $survey_link = api_get_path(WEB_CODE_PATH) . 'survey/fillsurvey.php?course=' . $_course['code'] . '&invitationcode=' . $invitation_code;
     $text_link = '<a href="' . $survey_link . '">' . get_lang('ClickHereToAnswerTheSurvey') . "</a><br />\r\n<br />\r\n" . get_lang('OrCopyPasteTheFollowingUrl') . " <br />\r\n " . $survey_link;
     $replace_count = 0;
     $full_invitation_text = api_str_ireplace('**link**', $text_link, $invitation_text, $replace_count);
     if ($replace_count < 1) {
         $full_invitation_text = $full_invitation_text . "<br />\r\n<br />\r\n" . $text_link;
     }
     // Sending the mail
     $sender_name = api_get_person_name($_user['firstName'], $_user['lastName'], null, PERSON_NAME_EMAIL_ADDRESS);
     $sender_email = $_user['mail'];
     $sender_user_id = api_get_user_id();
     $replyto = array();
     if (api_get_setting('survey_email_sender_noreply') == 'noreply') {
         $noReply = api_get_setting('noreply_email_address');
         if (!empty($noReply)) {
             $sender_name = $noReply;
             $sender_email = $noReply;
             $sender_user_id = null;
         }
     }
     // Optionally: finding the e-mail of the user
     if (is_numeric($invitedUser)) {
         MessageManager::send_message($invitedUser, $invitation_title, $full_invitation_text, null, null, null, null, null, null, $sender_user_id);
     } else {
         /** @todo check if the address is a valid email */
         $recipient_email = $invitedUser;
         @api_mail_html(null, $recipient_email, $invitation_title, $full_invitation_text, $sender_name, $sender_email);
     }
 }
コード例 #8
0
ファイル: course.lib.php プロジェクト: feroli1000/chamilo-lms
 /**
  * Send an email to tutor after the auth-suscription of a student in your course
  * @author Carlos Vargas <*****@*****.**>, Dokeos Latino
  * @param  int $user_id the id of the user
  * @param  string $course_code the course code
  * @param  bool $send_to_tutor_also
  * @return string we return the message that is displayed when the action is successful
  */
 public static function email_to_tutor($user_id, $courseId, $send_to_tutor_also = false)
 {
     if ($user_id != strval(intval($user_id))) {
         return false;
     }
     $courseId = intval($courseId);
     $information = api_get_course_info_by_id($courseId);
     $course_code = $information['code'];
     $student = api_get_user_info($user_id);
     $name_course = $information['title'];
     $sql = "SELECT * FROM " . Database::get_main_table(TABLE_MAIN_COURSE_USER) . " WHERE c_id ='" . $courseId . "'";
     // TODO: Ivan: This is a mistake, please, have a look at it. Intention here is diffcult to be guessed.
     //if ($send_to_tutor_also = true)
     // Proposed change:
     if ($send_to_tutor_also) {
         $sql .= " AND is_tutor=1";
     } else {
         $sql .= " AND status=1";
     }
     $result = Database::query($sql);
     while ($row = Database::fetch_array($result)) {
         $tutor = api_get_user_info($row['user_id']);
         $emailto = $tutor['email'];
         $emailsubject = get_lang('NewUserInTheCourse') . ': ' . $name_course;
         $emailbody = get_lang('Dear') . ': ' . api_get_person_name($tutor['firstname'], $tutor['lastname']) . "\n";
         $emailbody .= get_lang('MessageNewUserInTheCourse') . ': ' . $name_course . "\n";
         $emailbody .= get_lang('UserName') . ': ' . $student['username'] . "\n";
         if (api_is_western_name_order()) {
             $emailbody .= get_lang('FirstName') . ': ' . $student['firstname'] . "\n";
             $emailbody .= get_lang('LastName') . ': ' . $student['lastname'] . "\n";
         } else {
             $emailbody .= get_lang('LastName') . ': ' . $student['lastname'] . "\n";
             $emailbody .= get_lang('FirstName') . ': ' . $student['firstname'] . "\n";
         }
         $emailbody .= get_lang('Email') . ': <a href="mailto:' . $student['email'] . '">' . $student['email'] . "</a>\n\n";
         $recipient_name = api_get_person_name($tutor['firstname'], $tutor['lastname'], null, PERSON_NAME_EMAIL_ADDRESS);
         $sender_name = api_get_person_name(api_get_setting('admin.administrator_name'), api_get_setting('admin.administrator_surname'), null, PERSON_NAME_EMAIL_ADDRESS);
         $email_admin = api_get_setting('admin.administrator_email');
         $additionalParameters = array('smsType' => SmsPlugin::NEW_USER_SUBSCRIBED_COURSE, 'userId' => $tutor['user_id'], 'userUsername' => $student['username'], 'courseCode' => $course_code);
         api_mail_html($recipient_name, $emailto, $emailsubject, $emailbody, $sender_name, $email_admin, null, null, null, $additionalParameters);
     }
 }
コード例 #9
0
 /**
  * Save message notification
  * @param int	    $type message type
  * NOTIFICATION_TYPE_MESSAGE,
  * NOTIFICATION_TYPE_INVITATION,
  * NOTIFICATION_TYPE_GROUP
  * @param array	    $user_list recipients: user list of ids
  * @param string	$title
  * @param string	$content
  * @param array	    $sender_info
  * result of api_get_user_info() or GroupPortalManager:get_group_data()
  */
 public function save_notification($type, $user_list, $title, $content, $senderInfo = array())
 {
     $this->type = intval($type);
     $content = $this->formatContent($content, $senderInfo);
     $titleToNotification = $this->formatTitle($title, $senderInfo);
     $settingToCheck = '';
     $avoid_my_self = false;
     switch ($this->type) {
         case self::NOTIFICATION_TYPE_DIRECT_MESSAGE:
         case self::NOTIFICATION_TYPE_MESSAGE:
             $settingToCheck = 'mail_notify_message';
             $defaultStatus = self::NOTIFY_MESSAGE_AT_ONCE;
             break;
         case self::NOTIFICATION_TYPE_INVITATION:
             $settingToCheck = 'mail_notify_invitation';
             $defaultStatus = self::NOTIFY_INVITATION_AT_ONCE;
             break;
         case self::NOTIFICATION_TYPE_GROUP:
             $settingToCheck = 'mail_notify_group_message';
             $defaultStatus = self::NOTIFY_GROUP_AT_ONCE;
             $avoid_my_self = true;
             break;
         default:
             $defaultStatus = self::NOTIFY_MESSAGE_AT_ONCE;
             break;
     }
     $settingInfo = UserManager::get_extra_field_information_by_name($settingToCheck);
     if (!empty($user_list)) {
         foreach ($user_list as $user_id) {
             if ($avoid_my_self) {
                 if ($user_id == api_get_user_id()) {
                     continue;
                 }
             }
             $userInfo = api_get_user_info($user_id);
             // Extra field was deleted or removed? Use the default status.
             $userSetting = $defaultStatus;
             if (!empty($settingInfo)) {
                 $extra_data = UserManager::get_extra_user_data($user_id);
                 if (isset($extra_data[$settingToCheck]) && !empty($extra_data[$settingToCheck])) {
                     $userSetting = $extra_data[$settingToCheck];
                 }
             }
             $sendDate = null;
             switch ($userSetting) {
                 // No notifications
                 case self::NOTIFY_MESSAGE_NO:
                 case self::NOTIFY_INVITATION_NO:
                 case self::NOTIFY_GROUP_NO:
                     break;
                     // Send notification right now!
                 // Send notification right now!
                 case self::NOTIFY_MESSAGE_AT_ONCE:
                 case self::NOTIFY_INVITATION_AT_ONCE:
                 case self::NOTIFY_GROUP_AT_ONCE:
                     $extraHeaders = [];
                     if (isset($senderInfo['email'])) {
                         $extraHeaders = array('reply_to' => array('name' => $senderInfo['complete_name'], 'mail' => $senderInfo['email']));
                     }
                     if (!empty($userInfo['email'])) {
                         api_mail_html($userInfo['complete_name'], $userInfo['mail'], Security::filter_terms($titleToNotification), Security::filter_terms($content), $this->adminName, $this->adminEmail, $extraHeaders);
                     }
                     $sendDate = api_get_utc_datetime();
             }
             // Saving the notification to be sent some day.
             $params = array('sent_at' => $sendDate, 'dest_user_id' => $user_id, 'dest_mail' => $userInfo['email'], 'title' => $title, 'content' => cut($content, $this->max_content_length), 'send_freq' => $userSetting);
             $this->save($params);
         }
     }
 }
コード例 #10
0
ファイル: ticket.class.php プロジェクト: KRCM13/chamilo-lms
 /**
  * Assign ticket to admin
  * @param $ticket_id
  * @param $user_id
  */
 public static function assign_ticket_user($ticket_id, $user_id)
 {
     global $plugin;
     $ticket_id = intval($ticket_id);
     $user_id = intval($user_id);
     $table_support_tickets = Database::get_main_table(TABLE_TICKET_TICKET);
     $table_support_assigned_log = Database::get_main_table(TABLE_TICKET_ASSIGNED_LOG);
     $now = api_get_utc_datetime();
     $sql_update = "UPDATE {$table_support_tickets}\n                       SET assigned_last_user = '******'\n                       WHERE ticket_id = '{$ticket_id}'";
     $result = Database::query($sql_update);
     if (Database::affected_rows($result) > 0) {
         $insert_id = api_get_user_id();
         $sql = "INSERT INTO {$table_support_assigned_log} (\n                ticket_id,\n                user_id,\n                assigned_date,\n                sys_insert_user_id\n            ) VALUES (\n                '{$ticket_id}',\n                '{$user_id}',\n                '{$now}',\n                '{$insert_id}'\n            );";
         Database::query($sql);
         if ($insert_id != $user_id) {
             $info = api_get_user_info($user_id);
             $sender = api_get_user_info($insert_id);
             $href = api_get_path(WEB_PLUGIN_PATH) . PLUGIN_NAME . '/src/ticket_details.php?ticket_id=' . $ticket_id;
             $message = sprintf($plugin->get_lang('TicketAssignedMsg'), $info['complete_name'], $href, $ticket_id);
             $mailTitle = sprintf($plugin->get_lang('TicketAssignX'), $ticket_id);
             api_mail_html($info['complete_name'], $info['mail'], $mailTitle, $message, null, null, array('cc' => $sender['email']));
         }
     }
 }
コード例 #11
0
ファイル: api.lib.php プロジェクト: jloguercio/chamilo-lms
/**
 * Warns an user that the portal reach certain limit.
 * @param string $limitName
 */
function api_warn_hosting_contact($limitName, $limit)
{
    $email = api_get_configuration_value('hosting_contact_mail');
    if (!empty($email)) {
        $subject = get_lang('HostingWarningReached');
        $body = get_lang('PortalName') . ': ' . api_get_path(WEB_PATH) . " \n ";
        $body .= get_lang('PortalLimitType') . ': ' . $limitName . " \n ";
        $body .= get_lang('Value') . ': ' . $limit;
        api_mail_html(null, $email, $subject, $body);
    }
}
コード例 #12
0
ファイル: work.lib.php プロジェクト: annickvdp/Chamilo1.9.10
/**
 * Sends an email to the students of a course when a homework is created
 *
 * @param string course_id
 *
 * @author Guillaume Viguier <*****@*****.**>
 * @author Julio Montoya <*****@*****.**> Adding session support - 2011
 */
function send_email_on_homework_creation($course_id)
{
    // Get the students of the course
    $session_id = api_get_session_id();
    if (empty($session_id)) {
        $students = CourseManager::get_student_list_from_course_code($course_id);
    } else {
        $students = CourseManager::get_student_list_from_course_code($course_id, true, $session_id);
    }
    $emailsubject = '[' . api_get_setting('siteName') . '] '.get_lang('HomeworkCreated');
    $currentUser = api_get_user_info(api_get_user_id());
    if (!empty($students)) {
        foreach($students as $student) {
            $user_info = api_get_user_info($student["user_id"]);
            if(!empty($user_info["mail"])) {
                $name_user = api_get_person_name(
                    $user_info["firstname"],
                    $user_info["lastname"],
                    null,
                    PERSON_NAME_EMAIL_ADDRESS
                );
                $emailbody = get_lang('Dear')." ".$name_user.",\n\n";
                $emailbody .= get_lang('HomeworkHasBeenCreatedForTheCourse')." ".$course_id.". "."\n\n".get_lang('PleaseCheckHomeworkPage');
                $emailbody .= "\n\n".api_get_person_name($currentUser["firstname"], $currentUser["lastname"]);

                $additionalParameters = array(
                    'smsType' => ClockworksmsPlugin::ASSIGNMENT_BEEN_CREATED_COURSE,
                    'userId' => $student["user_id"],
                    'courseTitle' => $course_id
                );

                api_mail_html(
                    $name_user,
                    $user_info["mail"],
                    $emailsubject,
                    $emailbody,
                    api_get_person_name(
                        $currentUser["firstname"],
                        $currentUser["lastname"],
                        null,
                        PERSON_NAME_EMAIL_ADDRESS
                    ),
                    $currentUser["mail"],
                    null,
                    null,
                    null,
                    $additionalParameters
                );
            }
        }
    }
}
コード例 #13
0
        $emailDest = api_get_setting('emailAdministrator');
        $emailTitle = get_lang('SubscribeToSessionRequest');
        $emailText = $objTemplate->fetch($mailTemplate);
        break;
    default:
        $emailDest = Security::remove_XSS($_REQUEST['dest']);
        $emailTitle = Security::remove_XSS($_REQUEST['email_title']);
        $emailText = Security::remove_XSS($_REQUEST['email_text']);
}
$defaults = array('dest' => $emailDest, 'email_address' => $emailDest, 'email_title' => $emailTitle, 'email_text' => $emailText);
$form->setDefaults($defaults);
if ($form->validate()) {
    $text = Security::remove_XSS($_POST['email_text']) . "\n\n---\n" . get_lang('EmailSentFromDokeos') . " " . api_get_path(WEB_PATH);
    $email_administrator = Security::remove_XSS($_POST['dest']);
    $user_id = api_get_user_id();
    $title = Security::remove_XSS($_POST['email_title']);
    $content = Security::remove_XSS($_POST['email_text']);
    if (!empty($_user['mail'])) {
        api_mail_html('', $email_administrator, $title, $text, api_get_person_name($_user['firstname'], $_user['lastname']), $_user['mail']);
        UserManager::send_message_in_outbox($email_administrator, $user_id, $title, $content);
    } else {
        api_mail_html('', $email_administrator, $title, $text, get_lang('Anonymous'));
    }
    $orig = $_SESSION['origin_url'];
    Session::erase('origin_url');
    header('location:' . $orig);
    exit;
}
Display::display_header(get_lang('SendEmail'));
$form->display();
Display::display_footer();
コード例 #14
0
ファイル: wiki.inc.php プロジェクト: daffef/chamilo-lms
 /**
  * Sends pending e-mails
  */
 public function check_emailcue($id_or_ref, $type, $lastime = '', $lastuser = '')
 {
     $tbl_wiki_mailcue = $this->tbl_wiki_mailcue;
     $tbl_wiki = $this->tbl_wiki;
     $condition_session = $this->condition_session;
     $groupfilter = $this->groupfilter;
     $_course = $this->courseInfo;
     $groupId = api_get_group_id();
     $session_id = api_get_session_id();
     $course_id = api_get_course_int_id();
     $group_properties = GroupManager::get_group_properties($groupId);
     $group_name = $group_properties['name'];
     $allow_send_mail = false;
     //define the variable to below
     $email_assignment = null;
     if ($type == 'P') {
         //if modifying a wiki page
         //first, current author and time
         //Who is the author?
         $userinfo = api_get_user_info($lastuser);
         $email_user_author = get_lang('EditedBy') . ': ' . $userinfo['complete_name'];
         //When ?
         $year = substr($lastime, 0, 4);
         $month = substr($lastime, 5, 2);
         $day = substr($lastime, 8, 2);
         $hours = substr($lastime, 11, 2);
         $minutes = substr($lastime, 14, 2);
         $seconds = substr($lastime, 17, 2);
         $email_date_changes = $day . ' ' . $month . ' ' . $year . ' ' . $hours . ":" . $minutes . ":" . $seconds;
         //second, extract data from first reg
         $sql = 'SELECT * FROM ' . $tbl_wiki . '
                 WHERE  c_id = ' . $course_id . ' AND reflink="' . $id_or_ref . '" AND ' . $groupfilter . $condition_session . '
                 ORDER BY id ASC';
         $result = Database::query($sql);
         $row = Database::fetch_array($result);
         $id = $row['id'];
         $email_page_name = $row['title'];
         if ($row['visibility'] == 1) {
             $allow_send_mail = true;
             //if visibility off - notify off
             $sql = 'SELECT * FROM ' . $tbl_wiki_mailcue . '
                     WHERE
                         c_id = ' . $course_id . ' AND
                         id="' . $id . '" AND
                         type="' . $type . '" OR
                         type="F" AND
                         group_id="' . $groupId . '" AND
                         session_id="' . $session_id . '"';
             //type: P=page, D=discuss, F=full.
             $result = Database::query($sql);
             $emailtext = get_lang('EmailWikipageModified') . ' <strong>' . $email_page_name . '</strong> ' . get_lang('Wiki');
         }
     } elseif ($type == 'D') {
         //if added a post to discuss
         //first, current author and time
         //Who is the author of last message?
         $userinfo = api_get_user_info($lastuser);
         $email_user_author = get_lang('AddedBy') . ': ' . $userinfo['complete_name'];
         //When ?
         $year = substr($lastime, 0, 4);
         $month = substr($lastime, 5, 2);
         $day = substr($lastime, 8, 2);
         $hours = substr($lastime, 11, 2);
         $minutes = substr($lastime, 14, 2);
         $seconds = substr($lastime, 17, 2);
         $email_date_changes = $day . ' ' . $month . ' ' . $year . ' ' . $hours . ":" . $minutes . ":" . $seconds;
         //second, extract data from first reg
         $id = $id_or_ref;
         //$id_or_ref is id from tblwiki
         $sql = 'SELECT * FROM ' . $tbl_wiki . '
                 WHERE c_id = ' . $course_id . ' AND id="' . $id . '"
                 ORDER BY id ASC';
         $result = Database::query($sql);
         $row = Database::fetch_array($result);
         $email_page_name = $row['title'];
         if ($row['visibility_disc'] == 1) {
             $allow_send_mail = true;
             //if visibility off - notify off
             $sql = 'SELECT * FROM ' . $tbl_wiki_mailcue . '
                     WHERE
                         c_id = ' . $course_id . ' AND
                         id="' . $id . '" AND
                         type="' . $type . '" OR
                         type="F" AND
                         group_id="' . $groupId . '" AND
                         session_id="' . $session_id . '"';
             //type: P=page, D=discuss, F=full
             $result = Database::query($sql);
             $emailtext = get_lang('EmailWikiPageDiscAdded') . ' <strong>' . $email_page_name . '</strong> ' . get_lang('Wiki');
         }
     } elseif ($type == 'A') {
         //for added pages
         $id = 0;
         //for tbl_wiki_mailcue
         $sql = 'SELECT * FROM ' . $tbl_wiki . '
                 WHERE c_id = ' . $course_id . '
                 ORDER BY id DESC';
         //the added is always the last
         $result = Database::query($sql);
         $row = Database::fetch_array($result);
         $email_page_name = $row['title'];
         //Who is the author?
         $userinfo = api_get_user_info($row['user_id']);
         $email_user_author = get_lang('AddedBy') . ': ' . $userinfo['complete_name'];
         //When ?
         $year = substr($row['dtime'], 0, 4);
         $month = substr($row['dtime'], 5, 2);
         $day = substr($row['dtime'], 8, 2);
         $hours = substr($row['dtime'], 11, 2);
         $minutes = substr($row['dtime'], 14, 2);
         $seconds = substr($row['dtime'], 17, 2);
         $email_date_changes = $day . ' ' . $month . ' ' . $year . ' ' . $hours . ":" . $minutes . ":" . $seconds;
         if ($row['assignment'] == 0) {
             $allow_send_mail = true;
         } elseif ($row['assignment'] == 1) {
             $email_assignment = get_lang('AssignmentDescExtra') . ' (' . get_lang('AssignmentMode') . ')';
             $allow_send_mail = true;
         } elseif ($row['assignment'] == 2) {
             $allow_send_mail = false;
             //Mode tasks: avoids notifications to all users about all users
         }
         $sql = 'SELECT * FROM ' . $tbl_wiki_mailcue . '
                 WHERE c_id = ' . $course_id . ' AND  id="' . $id . '" AND type="F" AND group_id="' . $groupId . '" AND session_id="' . $session_id . '"';
         //type: P=page, D=discuss, F=full
         $result = Database::query($sql);
         $emailtext = get_lang('EmailWikiPageAdded') . ' <strong>' . $email_page_name . '</strong> ' . get_lang('In') . ' ' . get_lang('Wiki');
     } elseif ($type == 'E') {
         $id = 0;
         $allow_send_mail = true;
         //Who is the author?
         $userinfo = api_get_user_info(api_get_user_id());
         //current user
         $email_user_author = get_lang('DeletedBy') . ': ' . $userinfo['complete_name'];
         //When ?
         $today = date('r');
         //current time
         $email_date_changes = $today;
         $sql = 'SELECT * FROM ' . $tbl_wiki_mailcue . '
                 WHERE
                     c_id = ' . $course_id . ' AND
                     id="' . $id . '" AND type="F" AND
                     group_id="' . $groupId . '" AND
                     session_id="' . $session_id . '"';
         //type: P=page, D=discuss, F=wiki
         $result = Database::query($sql);
         $emailtext = get_lang('EmailWikipageDedeleted');
     }
     ///make and send email
     if ($allow_send_mail) {
         while ($row = Database::fetch_array($result)) {
             $userinfo = api_get_user_info($row['user_id']);
             //$row['user_id'] obtained from tbl_wiki_mailcue
             $name_to = $userinfo['complete_name'];
             $email_to = $userinfo['email'];
             $sender_name = api_get_setting('admin.administrator_email');
             $sender_email = api_get_setting('admin.administrator_email');
             $email_subject = get_lang('EmailWikiChanges') . ' - ' . $_course['official_code'];
             $email_body = get_lang('DearUser') . ' ' . api_get_person_name($userinfo['firstname'], $userinfo['lastname']) . ',<br /><br />';
             if ($session_id == 0) {
                 $email_body .= $emailtext . ' <strong>' . $_course['name'] . ' - ' . $group_name . '</strong><br /><br /><br />';
             } else {
                 $email_body .= $emailtext . ' <strong>' . $_course['name'] . ' (' . api_get_session_name(api_get_session_id()) . ') - ' . $group_name . '</strong><br /><br /><br />';
             }
             $email_body .= $email_user_author . ' (' . $email_date_changes . ')<br /><br /><br />';
             $email_body .= $email_assignment . '<br /><br /><br />';
             $email_body .= '<font size="-2">' . get_lang('EmailWikiChangesExt_1') . ': <strong>' . get_lang('NotifyChanges') . '</strong><br />';
             $email_body .= get_lang('EmailWikiChangesExt_2') . ': <strong>' . get_lang('NotNotifyChanges') . '</strong></font><br />';
             @api_mail_html($name_to, $email_to, $email_subject, $email_body, $sender_name, $sender_email);
         }
     }
 }
コード例 #15
0
/**
 * @return array|null|string
 */
function store_add_dropbox()
{
    $_course = api_get_course_info();
    $_user = api_get_user_info();
    $dropbox_cnf = getDropboxConf();
    // Validating the form data
    // there are no recipients selected
    if (!isset($_POST['recipients']) || count($_POST['recipients']) <= 0) {
        return get_lang('YouMustSelectAtLeastOneDestinee');
    } else {
        // Check if all the recipients are valid
        $thisIsAMailing = false;
        $thisIsJustUpload = false;
        foreach ($_POST['recipients'] as $rec) {
            if ($rec == 'mailing') {
                $thisIsAMailing = true;
            } elseif ($rec == 'upload') {
                $thisIsJustUpload = true;
            } elseif (strpos($rec, 'user_') === 0 && !isCourseMember(substr($rec, strlen('user_')))) {
                return get_lang('InvalideUserDetected');
            } elseif (strpos($rec, 'group_') !== 0 && strpos($rec, 'user_') !== 0) {
                return get_lang('InvalideGroupDetected');
            }
        }
    }
    // we are doing a mailing but an additional recipient is selected
    if ($thisIsAMailing && count($_POST['recipients']) != 1) {
        return get_lang('MailingSelectNoOther');
    }
    // we are doing a just upload but an additional recipient is selected.
    // note: why can't this be valid? It is like sending a document to yourself AND to a different person (I do this quite often with my e-mails)
    if ($thisIsJustUpload && count($_POST['recipients']) != 1) {
        return get_lang('MailingJustUploadSelectNoOther');
    }
    if (empty($_FILES['file']['name'])) {
        $error = true;
        return get_lang('NoFileSpecified');
    }
    // are we overwriting a previous file or sending a new one
    $dropbox_overwrite = false;
    if (isset($_POST['cb_overwrite']) && $_POST['cb_overwrite']) {
        $dropbox_overwrite = true;
    }
    // doing the upload
    $dropbox_filename = $_FILES['file']['name'];
    $dropbox_filesize = $_FILES['file']['size'];
    $dropbox_filetype = $_FILES['file']['type'];
    $dropbox_filetmpname = $_FILES['file']['tmp_name'];
    // check if the filesize does not exceed the allowed size.
    if ($dropbox_filesize <= 0 || $dropbox_filesize > $dropbox_cnf['maxFilesize']) {
        return get_lang('DropboxFileTooBig');
        // TODO: The "too big" message does not fit in the case of uploading zero-sized file.
    }
    // check if the file is actually uploaded
    if (!is_uploaded_file($dropbox_filetmpname)) {
        // check user fraud : no clean error msg.
        return get_lang('TheFileIsNotUploaded');
    }
    $upload_ok = process_uploaded_file($_FILES['file'], true);
    if (!$upload_ok) {
        return null;
    }
    // Try to add an extension to the file if it hasn't got one
    $dropbox_filename = add_ext_on_mime($dropbox_filename, $dropbox_filetype);
    // Replace dangerous characters
    $dropbox_filename = replace_dangerous_char($dropbox_filename);
    // Transform any .php file in .phps fo security
    $dropbox_filename = php2phps($dropbox_filename);
    //filter extension
    if (!filter_extension($dropbox_filename)) {
        return get_lang('UplUnableToSaveFileFilteredExtension');
    }
    // set title
    $dropbox_title = $dropbox_filename;
    // set author
    if (!isset($_POST['authors'])) {
        $_POST['authors'] = getUserNameFromId($_user['user_id']);
    }
    // note: I think we could better migrate everything from here on to separate functions: store_new_dropbox, store_new_mailing, store_just_upload
    if ($dropbox_overwrite) {
        $dropbox_person = new Dropbox_Person($_user['user_id'], api_is_course_admin(), api_is_course_tutor());
        foreach ($dropbox_person->sentWork as $w) {
            if ($w->title == $dropbox_filename) {
                if ($w->recipients[0]['id'] > dropbox_cnf('mailingIdBase') xor $thisIsAMailing) {
                    return get_lang('MailingNonMailingError');
                }
                if ($w->recipients[0]['id'] == $_user['user_id'] xor $thisIsJustUpload) {
                    return get_lang('MailingJustUploadSelectNoOther');
                }
                $dropbox_filename = $w->filename;
                $found = true;
                // note: do we still need this?
                break;
            }
        }
    } else {
        // rename file to login_filename_uniqueId format
        $dropbox_filename = getLoginFromId($_user['user_id']) . "_" . $dropbox_filename . "_" . uniqid('');
    }
    // creating the array that contains all the users who will receive the file
    $new_work_recipients = array();
    foreach ($_POST['recipients'] as $rec) {
        if (strpos($rec, 'user_') === 0) {
            $new_work_recipients[] = substr($rec, strlen('user_'));
        } elseif (strpos($rec, 'group_') === 0) {
            $userList = GroupManager::get_subscribed_users(substr($rec, strlen('group_')));
            foreach ($userList as $usr) {
                if (!in_array($usr['user_id'], $new_work_recipients) && $usr['user_id'] != $_user['user_id']) {
                    $new_work_recipients[] = $usr['user_id'];
                }
            }
        }
    }
    @move_uploaded_file($dropbox_filetmpname, dropbox_cnf('sysPath') . '/' . $dropbox_filename);
    $b_send_mail = api_get_course_setting('email_alert_on_new_doc_dropbox');
    if ($b_send_mail) {
        foreach ($new_work_recipients as $recipient_id) {
            $recipent_temp = UserManager::get_user_info_by_id($recipient_id);
            $additionalParameters = array('smsType' => ClockworksmsPlugin::NEW_FILE_SHARED_COURSE_BY, 'userId' => $recipient_id, 'courseTitle' => $_course['title'], 'userUsername' => $recipent_temp['username']);
            api_mail_html(api_get_person_name($recipent_temp['firstname'] . ' ' . $recipent_temp['lastname'], null, PERSON_NAME_EMAIL_ADDRESS), $recipent_temp['email'], get_lang('NewDropboxFileUploaded'), get_lang('NewDropboxFileUploadedContent') . ' ' . api_get_path(WEB_CODE_PATH) . 'dropbox/index.php?cidReq=' . $_course['sysCode'] . "\n\n" . api_get_person_name($_user['firstName'], $_user['lastName'], null, PERSON_NAME_EMAIL_ADDRESS) . "\n" . get_lang('Email') . " : " . $_user['mail'], api_get_person_name($_user['firstName'], $_user['lastName'], null, PERSON_NAME_EMAIL_ADDRESS), $_user['mail'], null, null, null, $additionalParameters);
        }
    }
    new Dropbox_SentWork($_user['user_id'], $dropbox_title, $_POST['description'], strip_tags($_POST['authors']), $dropbox_filename, $dropbox_filesize, $new_work_recipients);
    Security::clear_token();
    return get_lang('FileUploadSucces');
}
コード例 #16
0
                $sql = "UPDATE {$user_table} SET active='" . $status . "' WHERE user_id='" . $user_id . "'";
                $result = Database::query($sql);
                //Send and email if account is active
                if ($status == 1) {
                    $user_info = api_get_user_info($user_id);
                    $recipient_name = api_get_person_name($user_info['firstname'], $user_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS);
                    $emailsubject = '[' . api_get_setting('platform.site_name') . '] ' . get_lang('YourReg') . ' ' . api_get_setting('platform.site_name');
                    $email_admin = api_get_setting('admin.administrator_email');
                    $sender_name = api_get_person_name(api_get_setting('admin.administrator_name'), api_get_setting('admin.administrator_surname'), null, PERSON_NAME_EMAIL_ADDRESS);
                    $emailbody = get_lang('Dear') . " " . stripslashes($recipient_name) . ",\n\n";
                    $emailbody .= sprintf(get_lang('YourAccountOnXHasJustBeenApprovedByOneOfOurAdministrators'), api_get_setting('platform.site_name')) . "\n";
                    $emailbody .= sprintf(get_lang('YouCanNowLoginAtXUsingTheLoginAndThePasswordYouHaveProvided'), api_get_path(WEB_PATH)) . ",\n\n";
                    $emailbody .= get_lang('HaveFun') . "\n\n";
                    //$emailbody.=get_lang('Problem'). "\n\n". get_lang('SignatureFormula');
                    $emailbody .= api_get_person_name(api_get_setting('admin.administrator_name'), api_get_setting('admin.administrator_surname')) . "\n" . get_lang('Manager') . " " . api_get_setting('platform.site_name') . "\nT. " . api_get_setting('administratorTelephone') . "\n" . get_lang('Email') . " : " . api_get_setting('emailAdministrator');
                    $additionalParameters = array('smsType' => SmsPlugin::ACCOUNT_APPROVED_CONNECT, 'userId' => $user_id);
                    $result = api_mail_html($recipient_name, $user_info['mail'], $emailsubject, $emailbody, $sender_name, $email_admin, null, null, $additionalParameters);
                    Event::addEvent(LOG_USER_ENABLE, LOG_USER_ID, $user_id);
                } else {
                    Event::addEvent(LOG_USER_DISABLE, LOG_USER_ID, $user_id);
                }
                echo $status;
            }
        } else {
            echo '-1';
        }
        break;
    default:
        echo '';
}
exit;
コード例 #17
0
 /**
  * Function register_course to create a record in the course table of the main database
  * @param array Course details (see code for details)
  * @return int  Created course ID
  * @todo use an array called $params instead of lots of params
  * @assert (null) === false
  */
 public static function register_course($params)
 {
     global $error_msg, $firstExpirationDelay;
     $title = $params['title'];
     $code = $params['code'];
     $visual_code = $params['visual_code'];
     $directory = $params['directory'];
     $tutor_name = isset($params['tutor_name']) ? $params['tutor_name'] : null;
     //$description        = $params['description'];
     $category_code = isset($params['course_category']) ? $params['course_category'] : '';
     $course_language = isset($params['course_language']) && !empty($params['course_language']) ? $params['course_language'] : api_get_setting('language.platform_language');
     $user_id = empty($params['user_id']) ? api_get_user_id() : intval($params['user_id']);
     $department_name = isset($params['department_name']) ? $params['department_name'] : null;
     $department_url = isset($params['department_url']) ? $params['department_url'] : null;
     $disk_quota = isset($params['disk_quota']) ? $params['disk_quota'] : null;
     if (!isset($params['visibility'])) {
         $default_course_visibility = api_get_setting('course.courses_default_creation_visibility');
         if ($default_course_visibility != '') {
             $visibility = $default_course_visibility;
         } else {
             $visibility = COURSE_VISIBILITY_OPEN_PLATFORM;
         }
     } else {
         $visibility = $params['visibility'];
     }
     $subscribe = isset($params['subscribe']) ? intval($params['subscribe']) : ($visibility == COURSE_VISIBILITY_OPEN_PLATFORM ? 1 : 0);
     $unsubscribe = isset($params['unsubscribe']) ? intval($params['unsubscribe']) : 0;
     $expiration_date = isset($params['expiration_date']) ? $params['expiration_date'] : null;
     $teachers = isset($params['teachers']) ? $params['teachers'] : null;
     $status = isset($params['status']) ? $params['status'] : null;
     $TABLECOURSE = Database::get_main_table(TABLE_MAIN_COURSE);
     $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
     $ok_to_register_course = true;
     // Check whether all the needed parameters are present.
     if (empty($code)) {
         $error_msg[] = 'courseSysCode is missing';
         $ok_to_register_course = false;
     }
     if (empty($visual_code)) {
         $error_msg[] = 'courseScreenCode is missing';
         $ok_to_register_course = false;
     }
     if (empty($directory)) {
         $error_msg[] = 'courseRepository is missing';
         $ok_to_register_course = false;
     }
     if (empty($title)) {
         $error_msg[] = 'title is missing';
         $ok_to_register_course = false;
     }
     if (empty($expiration_date)) {
         $expiration_date = api_get_utc_datetime(time() + $firstExpirationDelay);
     } else {
         $expiration_date = api_get_utc_datetime($expiration_date);
     }
     if ($visibility < 0 || $visibility > 4) {
         $error_msg[] = 'visibility is invalid';
         $ok_to_register_course = false;
     }
     if (empty($disk_quota)) {
         $disk_quota = api_get_setting('document.default_document_quotum');
     }
     $time = api_get_utc_datetime();
     if (stripos($department_url, 'http://') === false && stripos($department_url, 'https://') === false) {
         $department_url = 'http://' . $department_url;
     }
     //just in case
     if ($department_url == 'http://') {
         $department_url = '';
     }
     $course_id = 0;
     if ($ok_to_register_course) {
         // Here we must add 2 fields.
         $sql = "INSERT INTO " . $TABLECOURSE . " SET\n                        code = '" . Database::escape_string($code) . "',\n                        directory = '" . Database::escape_string($directory) . "',\n                        course_language = '" . Database::escape_string($course_language) . "',\n                        title = '" . Database::escape_string($title) . "',\n                        description = '" . self::lang2db(get_lang('CourseDescription')) . "',\n                        category_code = '" . Database::escape_string($category_code) . "',\n                        visibility      = '" . $visibility . "',\n                        show_score      = '1',\n                        disk_quota      = '" . intval($disk_quota) . "',\n                        creation_date   = '{$time}',\n                        expiration_date = '" . $expiration_date . "',\n                        last_edit       = '{$time}',\n                        last_visit      = NULL,\n                        tutor_name = '" . Database::escape_string($tutor_name) . "',\n                        department_name = '" . Database::escape_string($department_name) . "',\n                        department_url = '" . Database::escape_string($department_url) . "',\n                        subscribe = '" . intval($subscribe) . "',\n                        unsubscribe = '" . intval($unsubscribe) . "',\n                        visual_code = '" . Database::escape_string($visual_code) . "'";
         Database::query($sql);
         $course_id = Database::insert_id();
         if ($course_id) {
             $sort = api_max_sort_value('0', api_get_user_id());
             // Default true
             $addTeacher = isset($params['add_user_as_teacher']) ? $params['add_user_as_teacher'] : true;
             if ($addTeacher) {
                 $i_course_sort = CourseManager::userCourseSort($user_id, $code);
                 if (!empty($user_id)) {
                     $sql = "INSERT INTO " . $TABLECOURSUSER . " SET\n                                c_id     = '" . $course_id . "',\n                                user_id         = '" . intval($user_id) . "',\n                                status          = '1',\n                                is_tutor        = '0',\n                                sort            = '" . $i_course_sort . "',\n                                user_course_cat = '0'";
                     Database::query($sql);
                 }
             }
             if (!empty($teachers)) {
                 if (!is_array($teachers)) {
                     $teachers = array($teachers);
                 }
                 foreach ($teachers as $key) {
                     //just in case
                     if ($key == $user_id) {
                         continue;
                     }
                     if (empty($key)) {
                         continue;
                     }
                     $sql = "INSERT INTO " . $TABLECOURSUSER . " SET\n                            c_id     = '" . Database::escape_string($course_id) . "',\n                            user_id         = '" . Database::escape_string($key) . "',\n                            status          = '1',\n                            is_tutor        = '0',\n                            sort            = '" . ($sort + 1) . "',\n                            user_course_cat = '0'";
                     Database::query($sql);
                 }
             }
             // Adding the course to an URL.
             if (api_is_multiple_url_enabled()) {
                 $url_id = 1;
                 if (api_get_current_access_url_id() != -1) {
                     $url_id = api_get_current_access_url_id();
                 }
                 UrlManager::add_course_to_url($course_id, $url_id);
             } else {
                 UrlManager::add_course_to_url($course_id, 1);
             }
             // Add event to the system log.
             $user_id = api_get_user_id();
             Event::addEvent(LOG_COURSE_CREATE, LOG_COURSE_CODE, $code, api_get_utc_datetime(), $user_id, $course_id);
             $send_mail_to_admin = api_get_setting('course.send_email_to_admin_when_create_course');
             // @todo Improve code to send to all current portal administrators.
             if ($send_mail_to_admin == 'true') {
                 $siteName = api_get_setting('platform.site_name');
                 $recipient_email = api_get_setting('admin.administrator_email');
                 $recipient_name = api_get_person_name(api_get_setting('admin.administrator_name'), api_get_setting('admin.administrator_surname'));
                 $iname = api_get_setting('platform.institution');
                 $subject = get_lang('NewCourseCreatedIn') . ' ' . $siteName . ' - ' . $iname;
                 $message = get_lang('Dear') . ' ' . $recipient_name . ",\n\n" . get_lang('MessageOfNewCourseToAdmin') . ' ' . $siteName . ' - ' . $iname . "\n";
                 $message .= get_lang('CourseName') . ' ' . $title . "\n";
                 $message .= get_lang('Category') . ' ' . $category_code . "\n";
                 $message .= get_lang('Tutor') . ' ' . $tutor_name . "\n";
                 $message .= get_lang('Language') . ' ' . $course_language;
                 $userInfo = api_get_user_info($user_id);
                 $additionalParameters = array('smsType' => SmsPlugin::NEW_COURSE_BEEN_CREATED, 'userId' => $user_id, 'courseName' => $title, 'creatorUsername' => $userInfo['username']);
                 api_mail_html($recipient_name, $recipient_email, $subject, $message, $siteName, $recipient_email, null, null, null, $additionalParameters);
             }
         }
     }
     return $course_id;
 }
コード例 #18
0
 /**
  * Save message notification
  * @param    array    message type NOTIFICATION_TYPE_MESSAGE, NOTIFICATION_TYPE_INVITATION, NOTIFICATION_TYPE_GROUP
  * @param    array    recipients: user list of ids
  * @param    string    title
  * @param    string    content of the message
  * @param    array    result of api_get_user_info() or UserGroup->get()
  */
 public function save_notification($type, $user_list, $title, $content, $sender_info = array(), $text_content = null)
 {
     $this->type = intval($type);
     $content = $this->format_content($content, $sender_info);
     $sender_id = 0;
     if (!empty($sender_info) && isset($sender_info['user_id'])) {
         $sender_id = $sender_info['user_id'];
         $this->set_sender_info($sender_id);
     }
     $setting_to_check = '';
     $avoid_my_self = false;
     $default_status = self::NOTIFY_MESSAGE_AT_ONCE;
     switch ($this->type) {
         case self::NOTIFICATION_TYPE_MESSAGE:
             $setting_to_check = 'mail_notify_message';
             $default_status = self::NOTIFY_MESSAGE_AT_ONCE;
             break;
         case self::NOTIFICATION_TYPE_INVITATION:
             $setting_to_check = 'mail_notify_invitation';
             $default_status = self::NOTIFY_INVITATION_AT_ONCE;
             break;
         case self::NOTIFICATION_TYPE_GROUP:
             $setting_to_check = 'mail_notify_group_message';
             $default_status = self::NOTIFY_GROUP_AT_ONCE;
             $avoid_my_self = true;
             break;
     }
     $setting_info = UserManager::get_extra_field_information_by_name($setting_to_check);
     if (!empty($user_list)) {
         foreach ($user_list as $user_id) {
             if ($avoid_my_self) {
                 if ($user_id == api_get_user_id()) {
                     continue;
                 }
             }
             $user_info = api_get_user_info($user_id);
             //Extra field was deleted or removed? Use the default status
             if (empty($setting_info)) {
                 $user_setting = $default_status;
             } else {
                 $extra_data = UserManager::get_extra_user_data($user_id);
                 $user_setting = $extra_data[$setting_to_check];
             }
             $params = array();
             switch ($user_setting) {
                 //No notifications
                 case self::NOTIFY_MESSAGE_NO:
                 case self::NOTIFY_INVITATION_NO:
                 case self::NOTIFY_GROUP_NO:
                     break;
                     //Send notification right now!
                 //Send notification right now!
                 case self::NOTIFY_MESSAGE_AT_ONCE:
                 case self::NOTIFY_INVITATION_AT_ONCE:
                 case self::NOTIFY_GROUP_AT_ONCE:
                     if (!empty($user_info['mail'])) {
                         $name = api_get_person_name($user_info['firstname'], $user_info['lastname']);
                         if (!empty($sender_info['complete_name']) && !empty($sender_info['email'])) {
                             $extra_headers = array();
                             $extra_headers['reply_to']['mail'] = $sender_info['email'];
                             $extra_headers['reply_to']['name'] = $sender_info['complete_name'];
                             api_mail_html($name, $user_info['mail'], Security::filter_terms($title), Security::filter_terms($content), $sender_info['complete_name'], $sender_info['email'], $extra_headers, array(), null, $text_content);
                         } else {
                             api_mail_html($name, $user_info['mail'], Security::filter_terms($title), Security::filter_terms($content), $sender_info['complete_name'], $sender_info['email'], array(), null, $text_content);
                         }
                     }
                     $params['sent_at'] = api_get_utc_datetime();
                     // Saving the notification to be sent some day.
                 // Saving the notification to be sent some day.
                 default:
                     $params['dest_user_id'] = $user_id;
                     $params['dest_mail'] = $user_info['mail'];
                     $params['title'] = $title;
                     $params['content'] = Text::cut($content, $this->max_content_length);
                     $params['send_freq'] = $user_setting;
                     $params['sender_id'] = $sender_id;
                     $this->save($params);
                     break;
             }
         }
     }
 }
コード例 #19
0
        echo 'Error in database with email ' . $mail . "\n";
    }
    if (Database::num_rows($res) == 0) {
        echo '[Error] Email not found in database: ' . $row['email'] . "\n";
    } else {
        $row = Database::fetch_assoc($res);
        $pass = api_substr($row['username'], 0, 4) . rand(0, 9) . rand(0, 9);
        if ($user) {
            /** @var User $user */
            $user = $repository->find($row['user_id']);
            $user->setPlainPassword($pass);
            $userManager->updateUser($user, true);
        } else {
            echo "[Error] Error updating password. Skipping {$mail}\n";
            continue;
        }
        $user = array('FirstName' => $row['firstname'], 'LastName' => $row['lastname'], 'UserName' => $row['username'], 'Password' => $pass, 'Email' => $mail);
        $l = api_get_interface_language();
        if (!empty($row['language'])) {
            $l = $row['language'];
        }
        //This comes from main/admin/user_import.php::save_data() slightly modified
        $recipient_name = api_get_person_name($user['FirstName'], $user['LastName'], null, PERSON_NAME_EMAIL_ADDRESS);
        $emailsubject = '[' . api_get_setting('siteName') . '] ' . get_lang('YourReg', null, $l) . ' ' . api_get_setting('siteName');
        $emailbody = get_lang('Dear', null, $l) . ' ' . api_get_person_name($user['FirstName'], $user['LastName']) . ",\n\n" . get_lang('YouAreReg', null, $l) . " " . api_get_setting('siteName') . " " . get_lang('WithTheFollowingSettings', null, $l) . "\n\n" . get_lang('Username', null, $l) . " : " . $user['UserName'] . "\n" . get_lang('Pass', null, $l) . " : " . $user['Password'] . "\n\n" . get_lang('Address', null, $l) . " " . api_get_setting('siteName') . " " . get_lang('Is', null, $l) . " : " . api_get_path(WEB_PATH) . " \n\n" . get_lang('Problem', null, $l) . "\n\n" . get_lang('Formula', null, $l) . ",\n\n" . api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname')) . "\n" . get_lang('Manager', null, $l) . " " . api_get_setting('siteName') . "\nT. " . api_get_setting('administratorTelephone') . "\n" . get_lang('Email', null, $l) . " : " . api_get_setting('emailAdministrator') . "";
        $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
        $email_admin = api_get_setting('emailAdministrator');
        @api_mail_html($recipient_name, $user['Email'], $emailsubject, $emailbody, $sender_name, $email_admin);
        echo "[OK] Sent to {$mail} with new password {$pass} (encrypted:{$crypass})... w/ subject: {$emailsubject}\n";
    }
}
コード例 #20
0
 /**
  * Sends email according to an event
  *
  * @param string $event_name the name of the event that was triggered
  * @param array $event_data what to put in the mail
  *
  * Possible key :
  * - $event_data["about_user"] (= $user_id)
  * - $event_data["prior_lang"]
  *
  * Warning :
  * - $event_data["send_to"] MUST BE an array
  */
 public static function send_mail($event_name, $event_data)
 {
     /**
      * Global explanation :
      * 1. we get information about the user that fired the event (in $event_data["about_user"])
      * 2. we send mail to people that are in the $event_data["send_to"]
      * 2b. if a language was specified, we use that one to send the mail, else we get the user's language, if there isn't any, we get the english one
      * 3. we do the same with the people associated to the event through the admin panel
      */
     global $event_config;
     // common variable for every mail sent
     $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
     $email_admin = api_get_setting('emailAdministrator');
     // basic  keys
     $event_data["sitename"] = api_get_setting('siteName');
     $event_data["administrator_name"] = api_get_setting('administratorName');
     $event_data["administrator_surname"] = api_get_setting('administratorSurname');
     $event_data["administrator_phone"] = api_get_setting('administratorTelephone');
     $event_data["administrator_email"] = api_get_setting('emailAdministrator');
     $event_data["portal"] = api_get_path(WEB_PATH);
     // Fill the array's cells with info regarding the user that fired the event
     // (for the keys in the template)
     if (isset($event_data["about_user"])) {
         $about_user = api_get_user_info($event_data["about_user"]);
         $event_data["firstname"] = $about_user["firstname"];
         $event_data["lastname"] = $about_user["lastname"];
         $event_data["username"] = $about_user["username"];
         $event_data["usermail"] = $about_user["mail"];
         $event_data["language"] = $about_user["language"];
         $event_data["user_id"] = $about_user["user_id"];
     }
     // First, we send the mail to people we put in the $event_data["send_to"]
     if ($event_data["send_to"] != null) {
         // the users we precised need to receive the mail
         foreach ($event_data["send_to"] as $id) {
             // for every member put in the array
             // get user's info (to know where to send)
             $user_info = api_get_user_info($id);
             // get the language the email will be in
             if ($event_data["prior_lang"] != null) {
                 // if $lang is not null, we use that lang
                 $language = $event_data["prior_lang"];
             } else {
                 // else we use the user's language
                 $sql = 'SELECT language FROM ' . Database::get_main_table(TABLE_MAIN_USER) . ' u
                 WHERE u.user_id = "' . $id . '"
                 ';
                 $language = Database::store_result(Database::query($sql), 'ASSOC');
                 $language = $language[0]["language"];
             }
             // we get the message in the correct language (or in english if doesn't exist)
             $result = self::getMessage($event_name, $language);
             $message = "";
             $subject = "";
             self::getCorrectMessage($message, $subject, $language, $result);
             // replace the keycodes used in the message
             self::formatMessage($message, $subject, $event_config, $event_name, $event_data);
             // sending email
             $recipient_name = api_get_person_name($user_info['firstname'], $user_info['lastname']);
             // checks if there's a file we need to join to the mail
             if (isset($values["certificate_pdf_file"])) {
                 $message = str_replace("\n", "<br />", $message);
                 @api_mail_html($recipient_name, $user_info["mail"], $subject, $message, $sender_name, $email_admin, null, array($values['certificate_pdf_file']));
             } else {
                 @api_mail_html($recipient_name, $user_info["mail"], $subject, $message, $sender_name, $email_admin);
             }
             // If the mail only need to be send once (we know that thanks to the events.conf), we log it in the table
             if ($event_config[$event_name]["sending_mail_once"]) {
                 $sql = 'INSERT INTO ' . Database::get_main_table(TABLE_EVENT_SENT) . '
                     (user_from, user_to, event_type_name)
                     VALUES (' . $event_data["user_id"] . ', ' . $id . ' ,"' . Database::escape_string($event_name) . '");
                     ';
                 Database::query($sql);
             }
         }
     }
     // Second, we send to people linked to the event
     // So, we get everyone
     $sql = 'SELECT u.user_id, u.language, u.email, u.firstname, u.lastname FROM ' . Database::get_main_table(TABLE_EVENT_TYPE_REL_USER) . ' ue
             INNER JOIN ' . Database::get_main_table(TABLE_MAIN_USER) . ' u ON u.user_id = ue.user_id
             WHERE event_type_name = "' . $event_name . '"';
     $result = Database::store_result(Database::query($sql), 'ASSOC');
     foreach ($result as $key => $value) {
         // for each of the linked users
         // we get the language
         if ($event_data["prior_lang"] != null) {
             // if $lang is not null, we use that lang
             $language = $event_data["prior_lang"];
         } else {
             // else we get the user's lang
             $sql = 'SELECT language FROM ' . Database::get_main_table(TABLE_MAIN_USER) . '
                 where user_id = ' . $value["user_id"] . ' ';
             $result = Database::store_result(Database::query($sql), 'ASSOC');
             $language = $result[0]["language"];
         }
         // we get the message in the correct language (or in english if doesn't exist)
         $result = self::getMessage($event_name, $language);
         $message = "";
         $subject = "";
         self::getCorrectMessage($message, $subject, $language, $result);
         // replace the keycodes used in the message
         self::formatMessage($message, $subject, $event_config, $event_name, $event_data);
         // we send the mail
         $recipient_name = api_get_person_name($value['firstname'], $value['lastname']);
         @api_mail($recipient_name, $value["email"], $subject, $message, $sender_name, $email_admin);
         // If the mail only need to be send once (we know that thanks to the events.conf, we log it in the table
         if ($event_config[$event_name]["sending_mail_once"]) {
             $sql = 'INSERT INTO ' . Database::get_main_table(TABLE_EVENT_SENT) . '
                 (user_from, user_to, event_type_name)
                 VALUES (' . $event_data["user_id"] . ', ' . $value["user_id"] . ' , "' . Database::escape_string($event_name) . '");
                 ';
             Database::query($sql);
         }
     }
 }
コード例 #21
0
ファイル: rsys.php プロジェクト: ilosada/chamilo-lms-icpna
 function black_out_notifier($item_id, $value)
 {
     $item_id = Database::escape_string($item_id);
     $value = Database::escape_string($value);
     $sql = "SELECT id, timepicker FROM " . Rsys::getTable('reservation') . "\n\t\t\t\tWHERE item_id='" . $item_id . "' AND subscribers > '0'";
     $value == 1 ? $sql .= " AND end_at >= (NOW()-7000000) " : ($sql .= " AND end_at >= NOW()");
     $reservations = Database::query($sql);
     while ($reservation = Database::fetch_array($reservations)) {
         $sql = "SELECT user_id FROM " . Rsys::getTable('subscription') . " WHERE reservation_id='" . $reservation[0] . "'";
         if ($reservation[1] == 1) {
             $sql .= " AND end_at >= NOW() ";
         }
         $subscriptions = Database::query($sql);
         while ($subscription = Database::fetch_array($subscriptions)) {
             $user_info = api_get_user_info($subscription[0]);
             $sql2 = "SELECT name FROM " . Rsys::getTable('item') . " WHERE id='" . $item_id . "'";
             $items = Database::query($sql2);
             $item = Database::fetch_array($items);
             $item_name = $item['name'];
             if ($reservation[1] == 0) {
                 //er wordt geen gebruik gemaakt van een timepicker dus begin en einddatum kan opgehaald worden uit reservation
                 $sql2 = "SELECT start_at,end_at FROM " . Rsys::getTable('reservation') . " WHERE id='" . $reservation[0] . "'";
             } else {
                 //er wordt gebruik gemaakt van een timepicker dus begin en einddatum kan opgehaald worden uit subscriptions
                 $sql2 = "SELECT start_at,end_at FROM " . Rsys::getTable('subscription') . " WHERE reservation_id='" . $reservation[0] . "'";
             }
             $items = Database::query($sql2);
             $item = Database::fetch_array($items);
             $begindatum = $item['start_at'];
             $einddatum = $item['end_at'];
             if ($value == 1) {
                 $inhoud = str_replace('#NAME#', $item_name, get_lang('ReservationActive'));
                 $inhoud = str_replace('#BEGIN#', $begindatum, $inhoud);
                 $inhoud = str_replace('#BEGIN#', $einddatum, $inhoud);
                 $titel = str_replace('#NAME#', $item_name, get_lang('ReservationAvailable'));
             } else {
                 $inhoud = str_replace('#NAME#', $item_name, get_lang('ReservationCancelled'));
                 $inhoud = str_replace('#BEGIN#', $begindatum, $inhoud);
                 $inhoud = str_replace('#BEGIN#', $einddatum, $inhoud);
                 $titel = str_replace('#NAME#', $item_name, get_lang('ReservationUnavailable'));
             }
             //api_send_mail($user_info['mail'], $titel, $inhoud);
             api_mail_html(null, $user_info['mail'], $titel, $inhoud);
         }
     }
 }
コード例 #22
0
 /**
  * Saves imported data.
  */
 public function save_data($users, $course_list, $id_session)
 {
     $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
     $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
     $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
     $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
     $id_session = intval($id_session);
     $sendMail = $_POST['sendMail'] ? 1 : 0;
     // Adding users to the platform.
     $new_users = array();
     foreach ($users as $index => $user) {
         $user = MySpace::complete_missing_data($user);
         // coach only will registered users
         $default_status = STUDENT;
         if ($user['create'] == COURSEMANAGER) {
             $user['id'] = UserManager::create_user($user['FirstName'], $user['LastName'], $default_status, $user['Email'], $user['UserName'], $user['Password'], $user['OfficialCode'], api_get_setting('language.platform_language'), $user['PhoneNumber'], '');
             $user['added_at_platform'] = 1;
         } else {
             $user['id'] = $user['create'];
             $user['added_at_platform'] = 0;
         }
         $new_users[] = $user;
     }
     // Update user list.
     $users = $new_users;
     // Inserting users.
     $super_list = array();
     foreach ($course_list as $enreg_course) {
         $nbr_users = 0;
         $new_users = array();
         $enreg_course = Database::escape_string($enreg_course);
         foreach ($users as $index => $user) {
             $userid = intval($user['id']);
             $sql = "INSERT IGNORE INTO {$tbl_session_rel_course_rel_user}(session_id, c_id, user_id)\n                        VALUES('{$id_session}','{$enreg_course}','{$userid}')";
             $course_session = array('course' => $enreg_course, 'added' => 1);
             $result = Database::query($sql);
             if (Database::affected_rows($result)) {
                 $nbr_users++;
             }
             $new_users[] = $user;
         }
         $super_list[] = $new_users;
         //update the nbr_users field
         $sql_select = "SELECT COUNT(user_id) as nbUsers FROM {$tbl_session_rel_course_rel_user}\n                           WHERE session_id='{$id_session}' AND c_id='{$enreg_course}'";
         $rs = Database::query($sql_select);
         list($nbr_users) = Database::fetch_array($rs);
         $sql_update = "UPDATE {$tbl_session_rel_course} SET nbr_users={$nbr_users}\n                           WHERE session_id='{$id_session}' AND c_id='{$enreg_course}'";
         Database::query($sql_update);
         $sql_update = "UPDATE {$tbl_session} SET nbr_users= '{$nbr_users}' WHERE id='{$id_session}'";
         Database::query($sql_update);
     }
     $new_users = array();
     foreach ($users as $index => $user) {
         $userid = $user['id'];
         $sql_insert = "INSERT IGNORE INTO {$tbl_session_rel_user}(session_id, user_id, registered_at)\n                           VALUES ('{$id_session}','{$userid}', '" . api_get_utc_datetime() . "')";
         Database::query($sql_insert);
         $user['added_at_session'] = 1;
         $new_users[] = $user;
     }
     $users = $new_users;
     $registered_users = get_lang('FileImported') . '<br /> Import file results : <br />';
     // Sending emails.
     $addedto = '';
     if ($sendMail) {
         $i = 0;
         foreach ($users as $index => $user) {
             $emailsubject = '[' . api_get_setting('platform.site_name') . '] ' . get_lang('YourReg') . ' ' . api_get_setting('platform.site_name');
             $emailbody = get_lang('Dear') . ' ' . api_get_person_name($user['FirstName'], $user['LastName']) . ",\n\n" . get_lang('YouAreReg') . " " . api_get_setting('platform.site_name') . " " . get_lang('WithTheFollowingSettings') . "\n\n" . get_lang('Username') . " : {$user['UserName']}\n" . get_lang('Pass') . " : {$user['Password']}\n\n" . get_lang('Address') . " " . api_get_setting('platform.site_name') . " " . get_lang('Is') . " : " . api_get_path(WEB_PATH) . " \n\n" . get_lang('Problem') . "\n\n" . get_lang('SignatureFormula') . ",\n\n" . api_get_person_name(api_get_setting('admin.administrator_name'), api_get_setting('admin.administrator_surname')) . "\n" . get_lang('Manager') . " " . api_get_setting('platform.site_name') . "\nT. " . api_get_setting('admin.administrator_phone') . "\n" . get_lang('Email') . " : " . api_get_setting('admin.administrator_email');
             api_mail_html(api_get_person_name($user['FirstName'], $user['LastName'], null, PERSON_NAME_EMAIL_ADDRESS), $user['Email'], $emailsubject, $emailbody);
             $userInfo = api_get_user_info($user['id']);
             if ($user['added_at_platform'] == 1 && $user['added_at_session'] == 1 || $user['added_at_session'] == 1) {
                 if ($user['added_at_platform'] == 1) {
                     $addedto = get_lang('UserCreatedPlatform');
                 } else {
                     $addedto = '          ';
                 }
                 if ($user['added_at_session'] == 1) {
                     $addedto .= get_lang('UserInSession');
                 }
             } else {
                 $addedto = get_lang('UserNotAdded');
             }
             $registered_users .= UserManager::getUserProfileLink($userInfo) . " - " . $addedto . '<br />';
         }
     } else {
         $i = 0;
         foreach ($users as $index => $user) {
             $userInfo = api_get_user_info($user['id']);
             if ($user['added_at_platform'] == 1 && $user['added_at_session'] == 1 || $user['added_at_session'] == 1) {
                 if ($user['added_at_platform'] == 1) {
                     $addedto = get_lang('UserCreatedPlatform');
                 } else {
                     $addedto = '          ';
                 }
                 if ($user['added_at_session'] == 1) {
                     $addedto .= ' ' . get_lang('UserInSession');
                 }
             } else {
                 $addedto = get_lang('UserNotAdded');
             }
             $registered_users .= "<a href=\"../user/userInfo.php?uInfo=" . $user['id'] . "\">" . api_get_person_name($user['FirstName'], $user['LastName']) . "</a> - " . $addedto . '<br />';
         }
     }
     header('Location: course.php?id_session=' . $id_session . '&action=show_message&message=' . urlencode($registered_users));
     exit;
 }
コード例 #23
0
ファイル: survey.lib.php プロジェクト: jloguercio/chamilo-lms
 /**
  * Send the invitation by mail.
  *
  * @param int invitedUser - the userId (course user) or emailaddress of additional user
  * $param string $invitation_code - the unique invitation code for the URL
  * @return	void
  */
 public static function send_invitation_mail($invitedUser, $invitation_code, $invitation_title, $invitation_text)
 {
     $_user = api_get_user_info();
     $_course = api_get_course_info();
     // Replacing the **link** part with a valid link for the user
     $survey_link = api_get_path(WEB_CODE_PATH) . 'survey/fillsurvey.php?course=' . $_course['code'] . '&invitationcode=' . $invitation_code;
     $text_link = '<a href="' . $survey_link . '">' . get_lang('ClickHereToAnswerTheSurvey') . "</a><br />\r\n<br />\r\n" . get_lang('OrCopyPasteTheFollowingUrl') . " <br />\r\n " . $survey_link;
     $replace_count = 0;
     $full_invitation_text = api_str_ireplace('**link**', $text_link, $invitation_text, $replace_count);
     if ($replace_count < 1) {
         $full_invitation_text = $full_invitation_text . "<br />\r\n<br />\r\n" . $text_link;
     }
     // Sending the mail
     $sender_name = api_get_person_name($_user['firstName'], $_user['lastName'], null, PERSON_NAME_EMAIL_ADDRESS);
     $sender_email = $_user['mail'];
     $sender_user_id = api_get_user_id();
     $replyto = array();
     if (api_get_setting('survey.survey_email_sender_noreply') == 'noreply') {
         $noreply = api_get_setting('mail.noreply_email_address');
         if (!empty($noreply)) {
             $replyto['Reply-to'] = $noreply;
             $sender_name = $noreply;
             $sender_email = $noreply;
             $sender_user_id = null;
         }
     }
     // Optionally: finding the e-mail of the course user
     if (is_numeric($invitedUser)) {
         $table_user = Database::get_main_table(TABLE_MAIN_USER);
         $sql = "SELECT firstname, lastname, email FROM {$table_user}\n                    WHERE user_id='" . Database::escape_string($invitedUser) . "'";
         $result = Database::query($sql);
         $row = Database::fetch_array($result);
         $recipient_email = $row['email'];
         $recipient_name = api_get_person_name($row['firstname'], $row['lastname'], null, PERSON_NAME_EMAIL_ADDRESS);
         MessageManager::send_message($invitedUser, $invitation_title, $full_invitation_text, [], [], null, null, null, null, $sender_user_id);
     } else {
         /** @todo check if the address is a valid email	 */
         $recipient_email = $invitedUser;
         @api_mail_html($recipient_name, $recipient_email, $invitation_title, $full_invitation_text, $sender_name, $sender_email, $replyto);
     }
 }
コード例 #24
0
 /**
  * Subscribes students to the given session and optionally (default) unsubscribes previous users
  *
  * @author Carlos Vargas from existing code
  * @author Julio Montoya. Cleaning code.
  * @param int $id_session
  * @param array $user_list
  * @param int $session_visibility
  * @param bool $empty_users
  * @return bool
  */
 public static function suscribe_users_to_session($id_session, $user_list, $session_visibility = SESSION_VISIBLE_READ_ONLY, $empty_users = true)
 {
     if ($id_session != strval(intval($id_session))) {
         return false;
     }
     foreach ($user_list as $intUser) {
         if ($intUser != strval(intval($intUser))) {
             return false;
         }
     }
     $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
     $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
     $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
     $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
     $entityManager = Database::getManager();
     $session = $entityManager->find('ChamiloCoreBundle:Session', $id_session);
     // from function parameter
     if (empty($session_visibility)) {
         $session_visibility = $session->getVisibility();
         //default status loaded if empty
         if (empty($session_visibility)) {
             $session_visibility = SESSION_VISIBLE_READ_ONLY;
         }
         // by default readonly 1
     } else {
         if (!in_array($session_visibility, array(SESSION_VISIBLE_READ_ONLY, SESSION_VISIBLE, SESSION_INVISIBLE))) {
             $session_visibility = SESSION_VISIBLE_READ_ONLY;
         }
     }
     $sql = "SELECT user_id FROM {$tbl_session_rel_course_rel_user}\n                WHERE session_id = {$id_session} AND status = 0";
     $result = Database::query($sql);
     $existingUsers = array();
     while ($row = Database::fetch_array($result)) {
         $existingUsers[] = $row['user_id'];
     }
     $sql = "SELECT c_id FROM {$tbl_session_rel_course}\n                WHERE session_id = {$id_session}";
     $result = Database::query($sql);
     $course_list = array();
     while ($row = Database::fetch_array($result)) {
         $course_list[] = $row['c_id'];
     }
     if ($session->getSendSubscriptionNotification() && is_array($user_list)) {
         // Sending emails only
         foreach ($user_list as $user_id) {
             if (in_array($user_id, $existingUsers)) {
                 continue;
             }
             $tplSubject = new Template(null, false, false, false, false, false);
             $layoutSubject = $tplSubject->get_template('mail/subject_subscription_to_session_confirmation.tpl');
             $subject = $tplSubject->fetch($layoutSubject);
             $user_info = api_get_user_info($user_id);
             $tplContent = new Template(null, false, false, false, false, false);
             // Variables for default template
             $tplContent->assign('complete_name', stripslashes($user_info['complete_name']));
             $tplContent->assign('session_name', $session->getName());
             $tplContent->assign('session_coach', $session->getGeneralCoach()->getCompleteName());
             $layoutContent = $tplContent->get_template('mail/content_subscription_to_session_confirmation.tpl');
             $content = $tplContent->fetch($layoutContent);
             api_mail_html($user_info['complete_name'], $user_info['mail'], $subject, $content, api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname')), api_get_setting('emailAdministrator'));
         }
     }
     foreach ($course_list as $courseId) {
         // for each course in the session
         $nbr_users = 0;
         $courseId = intval($courseId);
         $sql = "SELECT DISTINCT user_id\n                    FROM {$tbl_session_rel_course_rel_user}\n                    WHERE\n                        session_id = {$id_session} AND\n                        c_id = {$courseId} AND\n                        status = 0\n                    ";
         $result = Database::query($sql);
         $existingUsers = array();
         while ($row = Database::fetch_array($result)) {
             $existingUsers[] = $row['user_id'];
         }
         // Delete existing users
         if ($empty_users) {
             foreach ($existingUsers as $existing_user) {
                 if (!in_array($existing_user, $user_list)) {
                     $sql = "DELETE FROM {$tbl_session_rel_course_rel_user}\n                                WHERE\n                                    session_id = {$id_session} AND\n                                    c_id = {$courseId} AND\n                                    user_id = {$existing_user} AND\n                                    status = 0 ";
                     $result = Database::query($sql);
                     Event::addEvent(LOG_SESSION_DELETE_USER_COURSE, LOG_USER_ID, $existing_user, api_get_utc_datetime(), api_get_user_id(), $courseId, $id_session);
                     if (Database::affected_rows($result)) {
                         $nbr_users--;
                     }
                 }
             }
         }
         // Replace with this new function
         // insert new users into session_rel_course_rel_user and ignore if they already exist
         foreach ($user_list as $enreg_user) {
             if (!in_array($enreg_user, $existingUsers)) {
                 $enreg_user = Database::escape_string($enreg_user);
                 $sql = "INSERT IGNORE INTO {$tbl_session_rel_course_rel_user} (session_id, c_id, user_id, visibility, status)\n                            VALUES({$id_session}, {$courseId}, {$enreg_user}, {$session_visibility}, 0)";
                 $result = Database::query($sql);
                 Event::addEvent(LOG_SESSION_ADD_USER_COURSE, LOG_USER_ID, $enreg_user, api_get_utc_datetime(), api_get_user_id(), $courseId, $id_session);
                 if (Database::affected_rows($result)) {
                     $nbr_users++;
                 }
             }
         }
         // Count users in this session-course relation
         $sql = "SELECT COUNT(user_id) as nbUsers\n                    FROM {$tbl_session_rel_course_rel_user}\n                    WHERE session_id = {$id_session} AND c_id = {$courseId} AND status<>2";
         $rs = Database::query($sql);
         list($nbr_users) = Database::fetch_array($rs);
         // update the session-course relation to add the users total
         $sql = "UPDATE {$tbl_session_rel_course} SET nbr_users = {$nbr_users}\n                    WHERE session_id = {$id_session} AND c_id = {$courseId}";
         Database::query($sql);
     }
     // Delete users from the session
     if ($empty_users === true) {
         $sql = "DELETE FROM {$tbl_session_rel_user}\n                    WHERE session_id = {$id_session} AND relation_type<>" . SESSION_RELATION_TYPE_RRHH . "";
         Database::query($sql);
     }
     // Insert missing users into session
     $nbr_users = 0;
     foreach ($user_list as $enreg_user) {
         $enreg_user = Database::escape_string($enreg_user);
         $nbr_users++;
         $sql = "INSERT IGNORE INTO {$tbl_session_rel_user} (relation_type, session_id, user_id, registered_at)\n                    VALUES (0, {$id_session}, {$enreg_user}, '" . api_get_utc_datetime() . "')";
         Database::query($sql);
     }
     // update number of users in the session
     $nbr_users = count($user_list);
     if ($empty_users) {
         // update number of users in the session
         $sql = "UPDATE {$tbl_session} SET nbr_users= {$nbr_users}\n                    WHERE id = {$id_session} ";
         Database::query($sql);
     } else {
         $sql = "UPDATE {$tbl_session} SET nbr_users = nbr_users + {$nbr_users}\n                    WHERE id = {$id_session}";
         Database::query($sql);
     }
 }
コード例 #25
0
 /**
  * Update user information with all the parameters passed to this function
  * @param int The ID of the user to be updated
  * @param string The user's firstname
  * @param string The user's lastname
  * @param string The user's username (login)
  * @param string The user's password
  * @param string The authentication source (default: "platform")
  * @param string The user's e-mail address
  * @param int The user's status
  * @param string The user's official code (usually just an internal institutional code)
  * @param string The user's phone number
  * @param string The user's picture URL (internal to the Chamilo directory)
  * @param int The user ID of the person who registered this user (optional, defaults to null)
  * @param int The department of HR in which the user is registered (optional, defaults to 0)
  * @param array A series of additional fields to add to this user as extra fields (optional, defaults to null)
  * @return boolean true if the user information was updated
  * @assert (false, false, false, false, false, false, false, false, false, false, false, false, false) === false
  */
 public static function update_user($user_id, $firstname, $lastname, $username, $password = null, $auth_source = null, $email, $status, $official_code, $phone, $picture_uri, $expiration_date, $active, $creator_id = null, $hr_dept_id = 0, $extra = null, $language = 'english', $encrypt_method = '', $send_email = false, $reset_password = 0)
 {
     $hook = HookUpdateUser::create();
     if (!empty($hook)) {
         $hook->notifyUpdateUser(HOOK_EVENT_TYPE_PRE);
     }
     global $_configuration;
     $original_password = $password;
     if (empty($user_id)) {
         return false;
     }
     $user_info = api_get_user_info($user_id, false, true);
     if ($reset_password == 0) {
         $password = null;
         $auth_source = $user_info['auth_source'];
     } elseif ($reset_password == 1) {
         $original_password = $password = api_generate_password();
         $auth_source = PLATFORM_AUTH_SOURCE;
     } elseif ($reset_password == 2) {
         $password = $password;
         $auth_source = PLATFORM_AUTH_SOURCE;
     } elseif ($reset_password == 3) {
         $password = $password;
         $auth_source = $auth_source;
     }
     if ($user_id != strval(intval($user_id))) {
         return false;
     }
     if ($user_id === false) {
         return false;
     }
     //Checking the user language
     $languages = api_get_languages();
     if (!in_array($language, $languages['folder'])) {
         $language = api_get_setting('platformLanguage');
     }
     $change_active = 0;
     if ($user_info['active'] != $active) {
         $change_active = 1;
     }
     $userManager = self::getManager();
     /** @var Chamilo\UserBundle\Entity\User $user */
     $user = self::getRepository()->find($user_id);
     if (empty($user)) {
         return false;
     }
     if (!empty($expiration_date)) {
         $expiration_date = api_get_utc_datetime($expiration_date);
         $expiration_date = new \DateTime($expiration_date, new DateTimeZone('UTC'));
     }
     $user->setLastname($lastname)->setFirstname($firstname)->setUsername($username)->setStatus($status)->setAuthSource($auth_source)->setLanguage($language)->setEmail($email)->setOfficialCode($official_code)->setPhone($phone)->setPictureUri($picture_uri)->setExpirationDate($expiration_date)->setActive($active)->setHrDeptId($hr_dept_id);
     if (!is_null($password)) {
         $user->setPlainPassword($password);
     }
     $userManager->updateUser($user, true);
     if ($change_active == 1) {
         if ($active == 1) {
             $event_title = LOG_USER_ENABLE;
         } else {
             $event_title = LOG_USER_DISABLE;
         }
         Event::addEvent($event_title, LOG_USER_ID, $user_id);
     }
     if (is_array($extra) && count($extra) > 0) {
         $res = true;
         foreach ($extra as $fname => $fvalue) {
             $res = $res && self::update_extra_field_value($user_id, $fname, $fvalue);
         }
     }
     if (!empty($email) && $send_email) {
         $recipient_name = api_get_person_name($firstname, $lastname, null, PERSON_NAME_EMAIL_ADDRESS);
         $emailsubject = '[' . api_get_setting('siteName') . '] ' . get_lang('YourReg') . ' ' . api_get_setting('siteName');
         $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
         $email_admin = api_get_setting('emailAdministrator');
         if (api_is_multiple_url_enabled()) {
             $access_url_id = api_get_current_access_url_id();
             if ($access_url_id != -1) {
                 $url = api_get_access_url($access_url_id);
                 $emailbody = get_lang('Dear') . " " . stripslashes(api_get_person_name($firstname, $lastname)) . ",\n\n" . get_lang('YouAreReg') . " " . api_get_setting('siteName') . " " . get_lang('WithTheFollowingSettings') . "\n\n" . get_lang('Username') . " : " . $username . ($reset_password > 0 ? "\n" . get_lang('Pass') . " : " . stripslashes($original_password) : "") . "\n\n" . get_lang('Address') . " " . api_get_setting('siteName') . " " . get_lang('Is') . " : " . $url['url'] . "\n\n" . get_lang('Problem') . "\n\n" . get_lang('SignatureFormula') . ",\n\n" . api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname')) . "\n" . get_lang('Manager') . " " . api_get_setting('siteName') . "\nT. " . api_get_setting('administratorTelephone') . "\n" . get_lang('Email') . " : " . api_get_setting('emailAdministrator');
             }
         } else {
             $emailbody = get_lang('Dear') . " " . stripslashes(api_get_person_name($firstname, $lastname)) . ",\n\n" . get_lang('YouAreReg') . " " . api_get_setting('siteName') . " " . get_lang('WithTheFollowingSettings') . "\n\n" . get_lang('Username') . " : " . $username . ($reset_password > 0 ? "\n" . get_lang('Pass') . " : " . stripslashes($original_password) : "") . "\n\n" . get_lang('Address') . " " . api_get_setting('siteName') . " " . get_lang('Is') . " : " . $_configuration['root_web'] . "\n\n" . get_lang('Problem') . "\n\n" . get_lang('SignatureFormula') . ",\n\n" . api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname')) . "\n" . get_lang('Manager') . " " . api_get_setting('siteName') . "\nT. " . api_get_setting('administratorTelephone') . "\n" . get_lang('Email') . " : " . api_get_setting('emailAdministrator');
         }
         api_mail_html($recipient_name, $email, $emailsubject, $emailbody, $sender_name, $email_admin);
     }
     if (!empty($hook)) {
         $hook->notifyUpdateUser(HOOK_EVENT_TYPE_POST);
     }
     return $user->getId();
 }
コード例 #26
0
    /**
     * Assign ticket to admin
     * @param $ticket_id
     * @param $user_id
     */
    public static function assign_ticket_user($ticket_id, $user_id)
    {
        global $plugin;
        $ticket_id = intval($ticket_id);
        $user_id = intval($user_id);
        $table_support_tickets = Database::get_main_table(TABLE_TICKET_TICKET);
        $table_support_assigned_log = Database::get_main_table(TABLE_TICKET_ASSIGNED_LOG);
        $now = api_get_utc_datetime();

        $sql_update = "UPDATE $table_support_tickets
                       SET assigned_last_user = '******'
                       WHERE ticket_id = '$ticket_id'";
        Database::query($sql_update);
        if (Database::affected_rows() > 0) {
            $insert_id = api_get_user_id();
            $sql = "INSERT INTO $table_support_assigned_log (
                ticket_id,
                user_id,
                assigned_date,
                sys_insert_user_id
            ) VALUES (
                '$ticket_id',
                '$user_id',
                '$now',
                '$insert_id'
            );";
            Database::query($sql);

            if ($insert_id != $user_id) {
                $info = api_get_user_info($user_id);
                $sender = api_get_user_info($insert_id);
                $href = api_get_path(WEB_PLUGIN_PATH) . PLUGIN_NAME . '/src/ticket_details.php?ticket_id=' . $ticket_id;
                $message = sprintf($plugin->get_lang('TicketAssignedMsg'), $info['complete_name'], $href, $ticket_id);
                $mailTitle = sprintf($plugin->get_lang('TicketAssignX'), $ticket_id);
                api_mail_html(
                    $info['complete_name'],
                    $info['mail'],
                    $mailTitle,
                    $message,
                    null, // sender name
                    null, // sender e-mail
                    array(
                        'cc' => $sender['email']
                    ) // should be support e-mail (platform admin) here
                );
            }
        }
    }
コード例 #27
0
/**
 * Sends email using the phpmailer class
 * Sender name and email can be specified, if not specified
 * name and email of the platform admin are used
 *
 * @author Bert Vanderkimpen ICT&O UGent
 *
 * @param recipient_name    name of recipient
 * @param recipient_email   email of recipient
 * @param message           email body
 * @param subject           email subject
 * @return                  returns true if mail was sent
 * @see                     class.phpmailer.php
 * @deprecated use api_mail_html()
 */
function api_mail($recipient_name, $recipient_email, $subject, $message, $sender_name = '', $sender_email = '', $extra_headers = '', $additionalParameters = array())
{
    error_log("api_mail is deprecated. Using api_mail_html() on line " . __LINE__ . " of [" . __FILE__ . "]");
    return api_mail_html($recipient_name, $recipient_email, $subject, $message, $sender_name, $sender_email, $extra_headers, null, null, $additionalParameters);
}
コード例 #28
0
ファイル: api.lib.php プロジェクト: feroli1000/chamilo-lms
/**
 * Warns an user that the portal reach certain limit.
 * @param string $limitName
 */
function api_warn_hosting_contact($limitName)
{
    $hostingParams = api_get_configuration_value(1);
    $email = null;
    if (!empty($hostingParams)) {
        if (isset($hostingParams['hosting_contact_mail'])) {
            $email = $hostingParams['hosting_contact_mail'];
        }
    }
    if (!empty($email)) {
        $subject = get_lang('HostingWarningReached');
        $body = get_lang('PortalName') . ': ' . api_get_path(WEB_PATH) . " \n ";
        $body .= get_lang('PortalLimitType') . ': ' . $limitName . " \n ";
        if (isset($hostingParams[$limitName])) {
            $body .= get_lang('Value') . ': ' . $hostingParams[$limitName];
        }
        api_mail_html(null, $email, $subject, $body);
    }
}
コード例 #29
0
 /**
  * @param int    $courseId
  * @param int    $sessionId
  * @param string $filePath
  */
 public function warnUsersByEmail($courseId, $sessionId, $filePath = null)
 {
     $courseInfo = api_get_course_info_by_id($courseId);
     $courseCode = $courseInfo['code'];
     if (empty($sessionId)) {
         $students = CourseManager::get_student_list_from_course_code($courseCode, false);
     } else {
         $students = CourseManager::get_student_list_from_course_code($courseCode, true, $sessionId);
     }
     $url = api_get_course_url($courseCode, $sessionId);
     $url = Display::url($url, $url);
     $subject = $this->get_lang("AgreementUpdated");
     $message = sprintf($this->get_lang("AgreementWasUpdatedClickHere"), $url);
     $dataFile = array();
     if (!empty($filePath)) {
         $dataFile = array('path' => $filePath, 'filename' => basename($filePath));
         $message = sprintf($this->get_lang("AgreementWasUpdatedClickHere"), $url) . " \n";
         $message .= $this->get_lang("TheAgreementIsAttachedInThisEmail");
     }
     if (!empty($students)) {
         foreach ($students as $student) {
             $userInfo = api_get_user_info($student['user_id']);
             api_mail_html($userInfo['complete_name'], $userInfo['email'], $subject, $message, null, null, null, $dataFile);
             //MessageManager::send_message_simple($student['user_id'], $subject, $message);
         }
     }
 }
コード例 #30
0
ファイル: login.lib.php プロジェクト: annickvdp/Chamilo1.9.10
 /**
  * Handle encrypted password, send an email to a user with his password
  *
  * @param int	user id
  * @param bool	$by_username
  *
  * @author Olivier Cauberghe <*****@*****.**>, Ghent University
  */
 public static function handle_encrypted_password($user, $by_username = false)
 {
     $email_subject = "[" . api_get_setting('siteName') . "] " . get_lang('LoginRequest');
     // SUBJECT
     if ($by_username) {
         // Show only for lost password
         $user_account_list = self::get_user_account_list($user, true, $by_username);
         // BODY
         $email_to = $user['email'];
     } else {
         $user_account_list = self::get_user_account_list($user, true);
         // BODY
         $email_to = $user[0]['email'];
     }
     $email_body = get_lang('DearUser') . " :\n" . get_lang('password_request') . "\n";
     $email_body .= $user_account_list . "\n-----------------------------------------------\n\n";
     $email_body .= get_lang('PasswordEncryptedForSecurity');
     $email_body .= "\n\n" . get_lang('SignatureFormula') . ",\n" . api_get_setting('administratorName') . " " . api_get_setting('administratorSurname') . "\n" . get_lang('PlataformAdmin') . " - " . api_get_setting('siteName');
     $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
     $email_admin = api_get_setting('emailAdministrator');
     if (@api_mail_html('', $email_to, $email_subject, $email_body, $sender_name, $email_admin) == 1) {
         if (CustomPages::enabled()) {
             return get_lang('YourPasswordHasBeenEmailed');
         } else {
             Display::display_confirmation_message(get_lang('YourPasswordHasBeenEmailed'));
         }
     } else {
         $admin_email = Display::encrypted_mailto_link(api_get_setting('emailAdministrator'), api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname')));
         $message = sprintf(get_lang('ThisPlatformWasUnableToSendTheEmailPleaseContactXForMoreInformation'), $admin_email);
         if (CustomPages::enabled()) {
             return $message;
         } else {
             Display::display_error_message($message, false);
         }
     }
 }