From 163c94e71f084edb2a30c74746c3025011fbfb6e Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 3 Oct 2012 17:03:04 +0200 Subject: [PATCH] Sending survey via the chamilo messaging tool + a fix in the URL survey code --- main/survey/survey.lib.php | 55 ++++++++++++++++++----------------- main/survey/survey_invite.php | 2 +- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/main/survey/survey.lib.php b/main/survey/survey.lib.php index aa608db448..b4fbafb433 100644 --- a/main/survey/survey.lib.php +++ b/main/survey/survey.lib.php @@ -68,6 +68,7 @@ class survey_manager { } $my_course_info = api_get_course_info($my_course_id); $table_survey = Database :: get_course_table(TABLE_SURVEY); + if ($shared != 0) { $table_survey = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION); $sql = "SELECT * FROM $table_survey WHERE survey_id='".Database::escape_string($survey_id)."' "; @@ -93,17 +94,13 @@ class survey_manager { $return['survey_thanks'] = $return['surveythanks']; $return['survey_type'] = $return['survey_type']; $return['one_question_per_page']= $return['one_question_per_page']; - $return['show_form_profile'] = $return['show_form_profile']; $return['input_name_list'] = $return['input_name_list']; - $return['shuffle'] = $return['shuffle']; $return['parent_id'] = $return['parent_id']; $return['survey_version'] = $return['survey_version']; - return $return; - } else { - return $return; - } + } + return $return; } /** @@ -3792,9 +3789,7 @@ class SurveyUtil { // Database table to store the invitations data $table_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION); - $survey_invitations = array(); - $survey_invitations = SurveyUtil::get_invitations($survey_data['survey_code']); - $already_invited = array(); + $survey_invitations = SurveyUtil::get_invitations($survey_data['survey_code']); $already_invited = SurveyUtil::get_invited_users($survey_data['code']); // Remind unanswered is a special version of remind all reminder @@ -3854,7 +3849,7 @@ class SurveyUtil { static function send_invitation_mail($invitedUser, $invitation_code, $invitation_title, $invitation_text) { global $_user, $_course, $_configuration; - $portal_url = api_get_path(WEB_PATH); + $portal_url = api_get_path(WEB_CODE_PATH); if ($_configuration['multiple_access_urls']) { $access_url_id = api_get_current_access_url_id(); if ($access_url_id != -1) { @@ -3862,8 +3857,9 @@ class SurveyUtil { $portal_url = $url['url']; } } + // Replacing the **link** part with a valid link for the user - $survey_link = $portal_url.'main/survey/fillsurvey.php?course='.$_course['sysCode'].'&invitationcode='.$invitation_code; + $survey_link = api_get_path(WEB_CODE_PATH).'survey/fillsurvey.php?course='.$_course['code'].'&invitationcode='.$invitation_code; $text_link = ''.get_lang('ClickHereToAnswerTheSurvey')."
\r\n
\r\n".get_lang('OrCopyPasteTheFollowingUrl')."
\r\n ".$survey_link; $replace_count = 0; @@ -3871,6 +3867,22 @@ class SurveyUtil { if ($replace_count < 1) { $full_invitation_text = $full_invitation_text."
\r\n
\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)) { + $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)) { @@ -3880,25 +3892,14 @@ class SurveyUtil { $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, null, null, $sender_user_id); + } else { /** @todo check if the address is a valid email */ - $recipient_email = $invitedUser; + $recipient_email = $invitedUser; + @api_mail_html($recipient_name, $recipient_email, $invitation_title, $full_invitation_text, $sender_name, $sender_email, $replyto); } - - // Sending the mail - $sender_name = api_get_person_name($_user['firstName'], $_user['lastName'], null, PERSON_NAME_EMAIL_ADDRESS); - $sender_email = $_user['mail']; - - $replyto = array(); - if (api_get_setting('survey_email_sender_noreply') == 'noreply') { - $noreply = api_get_setting('noreply_email_address'); - if (!empty($noreply)) { - $replyto['Reply-to'] = $noreply; - $sender_name = $noreply; - $sender_email = $noreply; - } - } - @api_mail_html($recipient_name, $recipient_email, $invitation_title, $full_invitation_text, $sender_name, $sender_email, $replyto); } /** diff --git a/main/survey/survey_invite.php b/main/survey/survey_invite.php index a8e0e20f2e..f02bb1f5a6 100644 --- a/main/survey/survey_invite.php +++ b/main/survey/survey_invite.php @@ -155,7 +155,7 @@ if ($form->validate()) { SurveyUtil::save_invite_mail($values['mail_text'], $values['mail_title'], !empty($survey_data['invite_mail'])); // Saving the invitations for the course users $count_course_users = SurveyUtil::save_invitations($values['course_users'], $values['mail_title'], - $values['mail_text'], $values['resend_to_all'], $values['send_mail'], $values['remindUnAnswered']); + $values['mail_text'], $values['resend_to_all'], $values['send_mail'], $values['remindUnAnswered']); // Saving the invitations for the additional users $values['additional_users'] = $values['additional_users'].';'; // This is for the case when you enter only one email $temp = str_replace(',', ';', $values['additional_users']); // This is to allow , and ; as email separators