Example #1
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);
     }
 }
Example #2
0
 /**
  * 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);
     }
 }
/**
 * This function returns a string or an array with all occurrences of search in subject (ignoring case) replaced with the given replace value.
 * @param mixed $search					String or array of strings to be found.
 * @param mixed $replace				String or array of strings used for replacement.
 * @param mixed $subject				String or array of strings being searced.
 * @param int $count (optional)			The number of matched and replaced needles will be returned in count, which is passed by reference.
 * @param string $encoding (optional)	The used internally by this function character encoding. If it is omitted, the platform character set will be used by default.
 * @return mixed						String or array as a result.
 * Notes:
 * If $subject is an array, then the search and replace is performed with every entry of subject, the return value is an array.
 * If $search and $replace are arrays, then the function takes a value from each array and uses it to do search and replace on subject.
 * If $replace has fewer values than search, then an empty string is used for the rest of replacement values.
 * If $search is an array and $replace is a string, then this replacement string is used for every value of search.
 * This function is aimed at replacing the function str_ireplace() for human-language strings.
 * @link http://php.net/manual/en/function.str-ireplace
 * @author Henri Sivonen, mailto:hsivonen@iki.fi
 * @link http://hsivonen.iki.fi/php-utf8/
 * Adaptation for Chamilo 1.8.7, 2010
 * Initial implementation Dokeos LMS, August 2009
 * @author Ivan Tcholakov
 */
function api_str_ireplace($search, $replace, $subject, &$count = null, $encoding = null)
{
    if (empty($encoding)) {
        $encoding = _api_mb_internal_encoding();
    }
    if (api_is_encoding_supported($encoding)) {
        if (!is_array($search) && !is_array($replace)) {
            if (!api_is_utf8($encoding)) {
                $search = api_utf8_encode($search, $encoding);
            }
            $slen = api_byte_count($search);
            if ($slen == 0) {
                return $subject;
            }
            if (!api_is_utf8($encoding)) {
                $replace = api_utf8_encode($replace, $encoding);
                $subject = api_utf8_encode($subject, $encoding);
            }
            $lendif = api_byte_count($replace) - api_byte_count($search);
            $search = api_strtolower($search, 'UTF-8');
            $search = preg_quote($search);
            $lstr = api_strtolower($subject, 'UTF-8');
            $i = 0;
            $matched = 0;
            while (preg_match('/(.*)' . $search . '/Us', $lstr, $matches)) {
                if ($i === $count) {
                    break;
                }
                $mlen = api_byte_count($matches[0]);
                $lstr = substr($lstr, $mlen);
                $subject = substr_replace($subject, $replace, $matched + api_byte_count($matches[1]), $slen);
                $matched += $mlen + $lendif;
                $i++;
            }
            if (!api_is_utf8($encoding)) {
                $subject = api_utf8_decode($subject, $encoding);
            }
            return $subject;
        } else {
            foreach (array_keys($search) as $k) {
                if (is_array($replace)) {
                    if (array_key_exists($k, $replace)) {
                        $subject = api_str_ireplace($search[$k], $replace[$k], $subject, $count);
                    } else {
                        $subject = api_str_ireplace($search[$k], '', $subject, $count);
                    }
                } else {
                    $subject = api_str_ireplace($search[$k], $replace, $subject, $count);
                }
            }
            return $subject;
        }
    }
    if (is_null($count)) {
        return str_ireplace($search, $replace, $subject);
    }
    return str_ireplace($search, $replace, $subject, $count);
}