Пример #1
0
 /**
  * This function saves all the invitations of course users and additional users in the database
  * and sends the invitations by email
  *
  * @param	array	Users array can be both a list of course uids AND a list of additional emailaddresses
  * @param 	string	Title of the invitation, used as the title of the mail
  * @param 	string	Text of the invitation, used as the text of the mail.
  * 				 The text has to contain a **link** string or this will automatically be added to the end
  *
  * @author Patrick Cool <*****@*****.**>, Ghent University
  * @author Julio Montoya - Adding auto-generated link support
  * @version January 2007
  *
  */
 public static function saveInvitations($users_array, $invitation_title, $invitation_text, $reminder = 0, $sendmail = 0, $remindUnAnswered = 0)
 {
     if (!is_array($users_array)) {
         // Should not happen
         return 0;
     }
     // Getting the survey information
     $survey_data = SurveyManager::get_survey($_GET['survey_id']);
     $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
     $exclude_users = array();
     if ($remindUnAnswered == 1) {
         // Remind only unanswered users
         $reminder = 1;
         $exclude_users = SurveyManager::get_people_who_filled_survey($_GET['survey_id']);
     }
     $counter = 0;
     // Nr of invitations "sent" (if sendmail option)
     $course_id = api_get_course_int_id();
     $session_id = api_get_session_id();
     $result = CourseManager::separateUsersGroups($users_array);
     $groupList = $result['groups'];
     $users_array = $result['users'];
     foreach ($groupList as $groupId) {
         $userGroupList = GroupManager::getStudents($groupId);
         $userGroupIdList = array_column($userGroupList, 'user_id');
         $users_array = array_merge($users_array, $userGroupIdList);
         $params = array('c_id' => $course_id, 'session_id' => $session_id, 'group_id' => $groupId, 'survey_code' => $survey_data['code']);
         $invitationExists = self::invitationExists($course_id, $session_id, $groupId, $survey_data['code']);
         if (empty($invitationExists)) {
             self::save_invitation($params);
         }
     }
     $users_array = array_unique($users_array);
     foreach ($users_array as $key => $value) {
         if (!isset($value) || $value == '') {
             continue;
         }
         // Skip user if reminding only unanswered people
         if (in_array($value, $exclude_users)) {
             continue;
         }
         // Get the unique invitation code if we already have it
         if ($reminder == 1 && array_key_exists($value, $survey_invitations)) {
             $invitation_code = $survey_invitations[$value]['invitation_code'];
         } else {
             $invitation_code = md5($value . microtime());
         }
         $new_user = false;
         // User not already invited
         // Store the invitation if user_id not in $already_invited['course_users'] OR email is not in $already_invited['additional_users']
         $addit_users_array = isset($already_invited['additional_users']) && !empty($already_invited['additional_users']) ? explode(';', $already_invited['additional_users']) : array();
         $my_alredy_invited = $already_invited['course_users'] == null ? array() : $already_invited['course_users'];
         if (is_numeric($value) && !in_array($value, $my_alredy_invited) || !is_numeric($value) && !in_array($value, $addit_users_array)) {
             $new_user = true;
             if (!array_key_exists($value, $survey_invitations)) {
                 $params = array('c_id' => $course_id, 'session_id' => $session_id, 'user' => $value, 'survey_code' => $survey_data['code'], 'invitation_code' => $invitation_code, 'invitation_date' => api_get_utc_datetime());
                 self::save_invitation($params);
             }
         }
         // Send the email if checkboxed
         if (($new_user || $reminder == 1) && $sendmail != 0) {
             // Make a change for absolute url
             if (isset($invitation_text)) {
                 $invitation_text = api_html_entity_decode($invitation_text, ENT_QUOTES);
                 $invitation_text = str_replace('src="../../', 'src="' . api_get_path(WEB_PATH), $invitation_text);
                 $invitation_text = trim(stripslashes($invitation_text));
             }
             SurveyUtil::send_invitation_mail($value, $invitation_code, $invitation_title, $invitation_text);
             $counter++;
         }
     }
     return $counter;
     // Number of invitations sent
 }
Пример #2
0
    SurveyUtil::update_count_invited($survey_data['code']);
    $total_count = $count_course_users + $counter_additional_users;
    $table_survey = Database::get_course_table(TABLE_SURVEY);
    // Counting the number of people that are invited
    $sql = "SELECT * FROM {$table_survey} WHERE c_id = {$course_id} AND code = '" . Database::escape_string($survey_data['code']) . "'";
    $result = Database::query($sql);
    $row = Database::fetch_array($result);
    $total_invited = $row['invited'];
    if ($total_invited > 0) {
        $message = '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/survey_invitation.php?view=answered&amp;survey_id=' . $survey_data['survey_id'] . '">' . $survey_data['answered'] . '</a> ';
        $message .= get_lang('HaveAnswered') . ' ';
        $message .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/survey_invitation.php?view=invited&amp;survey_id=' . $survey_data['survey_id'] . '">' . $total_invited . '</a> ';
        $message .= get_lang('WereInvited');
        Display::display_normal_message($message, false);
        Display::display_confirmation_message($total_count . ' ' . get_lang('InvitationsSend'));
    }
} else {
    // Getting the invited users
    $defaults = SurveyUtil::get_invited_users($survey_data['code']);
    // Getting the survey mail text
    if (!empty($survey_data['reminder_mail'])) {
        $defaults['mail_text'] = $survey_data['reminder_mail'];
    } else {
        $defaults['mail_text'] = $survey_data['invite_mail'];
    }
    $defaults['mail_title'] = $survey_data['mail_subject'];
    $defaults['send_mail'] = 1;
    $form->setDefaults($defaults);
    $form->display();
}
Display::display_footer();
Пример #3
0
 /**
  * Returns the "what's new" icon notifications
  *
  * The general logic of this function is to track the last time the user
  * entered the course and compare to what has changed inside this course
  * since then, based on the item_property table inside this course. Note that,
  * if the user never entered the course before, he will not see notification
  * icons. This function takes session ID into account (if any) and only shows
  * the corresponding notifications.
  * @param array     Course information array, containing at least elements 'db' and 'k'
  * @return string   The HTML link to be shown next to the course
  */
 public static function show_notification($course_info)
 {
     $t_track_e_access = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
     $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
     $tool_edit_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
     $course_code = Database::escape_string($course_info['code']);
     $user_id = api_get_user_id();
     $course_id = $course_info['real_id'];
     $course_info['id_session'] = intval($course_info['id_session']);
     // Get the user's last access dates to all tools of this course
     $sql = "SELECT *\n                FROM {$t_track_e_access} USE INDEX (access_cours_code, access_user_id)\n                WHERE\n                    access_cours_code = '" . $course_code . "' AND\n                    access_user_id = '{$user_id}' AND\n                    access_session_id ='" . $course_info['id_session'] . "'";
     $resLastTrackInCourse = Database::query($sql);
     $oldestTrackDate = $oldestTrackDateOrig = '3000-01-01 00:00:00';
     while ($lastTrackInCourse = Database::fetch_array($resLastTrackInCourse)) {
         $lastTrackInCourseDate[$lastTrackInCourse['access_tool']] = $lastTrackInCourse['access_date'];
         if ($oldestTrackDate > $lastTrackInCourse['access_date']) {
             $oldestTrackDate = $lastTrackInCourse['access_date'];
         }
     }
     if ($oldestTrackDate == $oldestTrackDateOrig) {
         //if there was no connexion to the course ever, then take the
         // course creation date as a reference
         $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
         $sql = "SELECT course.creation_date " . "FROM {$course_table} course " . "WHERE course.code = '" . $course_code . "'";
         $res = Database::query($sql);
         if ($res && Database::num_rows($res) > 0) {
             $row = Database::fetch_array($res);
         }
         $oldestTrackDate = $row['creation_date'];
     }
     // Get the last edits of all tools of this course.
     $sql = "SELECT\n                    tet.*,\n                    tet.lastedit_date last_date,\n                    tet.tool tool,\n                    tet.ref ref,\n                    tet.lastedit_type type,\n                    tet.to_group_id group_id,\n                    ctt.image image,\n                    ctt.link link\n                FROM {$tool_edit_table} tet, {$course_tool_table} ctt\n                WHERE\n                    tet.c_id = {$course_id} AND\n                    ctt.c_id = {$course_id} AND\n                    tet.lastedit_date > '{$oldestTrackDate}' " . " AND (ctt.name = tet.tool OR (ctt.name = 'student_publication' AND tet.tool = 'work')) " . " AND ctt.visibility = '1' " . " AND tet.lastedit_user_id != {$user_id} AND tet.id_session = '" . $course_info['id_session'] . "'\n                 ORDER BY tet.lastedit_date";
     $res = Database::query($sql);
     // Get the group_id's with user membership.
     $group_ids = GroupManager::get_group_ids($course_info['real_id'], $user_id);
     $group_ids[] = 0;
     //add group 'everyone'
     $notifications = array();
     // Filter all last edits of all tools of the course
     while ($res && ($item_property = Database::fetch_array($res))) {
         // First thing to check is if the user never entered the tool
         // or if his last visit was earlier than the last modification.
         if ((!isset($lastTrackInCourseDate[$item_property['tool']]) || $lastTrackInCourseDate[$item_property['tool']] < $item_property['lastedit_date']) && (in_array($item_property['to_group_id'], $group_ids) && ($item_property['tool'] != TOOL_DROPBOX && $item_property['tool'] != TOOL_NOTEBOOK && $item_property['tool'] != TOOL_CHAT)) && ($item_property['visibility'] == '1' || $course_info['status'] == '1' && $item_property['visibility'] == '0' || !isset($item_property['visibility']))) {
             if ($course_info['real_id'] == 1) {
                 //  var_dump($item_property);
             }
             // Also drop announcements and events that are not for the user or his group.
             if (($item_property['tool'] == TOOL_ANNOUNCEMENT || $item_property['tool'] == TOOL_CALENDAR_EVENT) && ($item_property['to_user_id'] != $user_id && (!isset($item_property['to_group_id']) || !in_array($item_property['to_group_id'], $group_ids)))) {
                 continue;
             }
             // If it's a survey, make sure the user's invited. Otherwise drop it.
             if ($item_property['tool'] == TOOL_SURVEY) {
                 $survey_info = survey_manager::get_survey($item_property['ref'], 0, $course_code);
                 if (!empty($survey_info)) {
                     $invited_users = SurveyUtil::get_invited_users($survey_info['code'], $course_code);
                     if (!in_array($user_id, $invited_users['course_users'])) {
                         continue;
                     }
                 }
             }
             // If it's a learning path, ensure it is currently visible to the user
             if ($item_property['tool'] == TOOL_LEARNPATH) {
                 require_once api_get_path(SYS_CODE_PATH) . 'newscorm/learnpath.class.php';
                 if (!learnpath::is_lp_visible_for_student($item_property['ref'], $user_id, $course_code)) {
                     continue;
                 }
             }
             if ($item_property['tool'] == 'work' && $item_property['type'] == 'DirectoryCreated') {
                 $item_property['lastedit_type'] = 'WorkAdded';
             }
             $notifications[$item_property['tool']] = $item_property;
         }
     }
     // Show all tool icons where there is something new.
     $retvalue = '&nbsp;';
     while (list($key, $notification) = each($notifications)) {
         $lastDate = date('d/m/Y H:i', convert_sql_date($notification['lastedit_date']));
         $type = $notification['lastedit_type'];
         if (empty($course_info['id_session'])) {
             $my_course['id_session'] = 0;
         } else {
             $my_course['id_session'] = $course_info['id_session'];
         }
         $label = get_lang('TitleNotification') . ": " . get_lang($type) . " ({$lastDate})";
         $retvalue .= '<a href="' . api_get_path(WEB_CODE_PATH) . $notification['link'] . '?cidReq=' . $course_code . '&amp;ref=' . $notification['ref'] . '&amp;gidReq=' . $notification['to_group_id'] . '&amp;id_session=' . $my_course['id_session'] . '">' . Display::return_icon($notification['image'], $label) . '</a>&nbsp;';
     }
     return $retvalue;
 }
Пример #4
0
 /**
  * Returns the "what's new" icon notifications
  *
  * The general logic of this function is to track the last time the user
  * entered the course and compare to what has changed inside this course
  * since then, based on the item_property table inside this course. Note that,
  * if the user never entered the course before, he will not see notification
  * icons. This function takes session ID into account (if any) and only shows
  * the corresponding notifications.
  * @param array     Course information array, containing at least elements 'db' and 'k'
  * @return string   The HTML link to be shown next to the course
  */
 public static function show_notification($course_info)
 {
     if (empty($course_info)) {
         return '';
     }
     $t_track_e_access = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
     $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
     $tool_edit_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
     $course_code = Database::escape_string($course_info['code']);
     $user_id = api_get_user_id();
     $course_id = intval($course_info['real_id']);
     $sessionId = intval($course_info['id_session']);
     // Get the user's last access dates to all tools of this course
     $sql = "SELECT *\n                FROM {$t_track_e_access}\n                WHERE\n                    c_id = {$course_id} AND\n                    access_user_id = '{$user_id}' AND\n                    access_session_id ='" . $sessionId . "'";
     $resLastTrackInCourse = Database::query($sql);
     $oldestTrackDate = $oldestTrackDateOrig = '3000-01-01 00:00:00';
     while ($lastTrackInCourse = Database::fetch_array($resLastTrackInCourse)) {
         $lastTrackInCourseDate[$lastTrackInCourse['access_tool']] = $lastTrackInCourse['access_date'];
         if ($oldestTrackDate > $lastTrackInCourse['access_date']) {
             $oldestTrackDate = $lastTrackInCourse['access_date'];
         }
     }
     if ($oldestTrackDate == $oldestTrackDateOrig) {
         //if there was no connexion to the course ever, then take the
         // course creation date as a reference
         $oldestTrackDate = $course_info['creation_date'];
     }
     $sessionCondition = api_get_session_condition($sessionId, true, false, 'tet.session_id');
     // Get the last edits of all tools of this course.
     $sql = "SELECT\n                    tet.*,\n                    tet.lastedit_date last_date,\n                    tet.tool tool,\n                    tet.ref ref,\n                    tet.lastedit_type type,\n                    tet.to_group_id group_id,\n                    ctt.image image,\n                    ctt.link link\n                FROM {$tool_edit_table} tet\n                INNER JOIN {$course_tool_table} ctt\n                ON tet.c_id = ctt.c_id\n                WHERE\n                    tet.c_id = {$course_id} AND\n                    tet.lastedit_date > '{$oldestTrackDate}' " . " AND (ctt.name = tet.tool OR (ctt.name = 'student_publication' AND tet.tool = 'work'))\n                    AND ctt.visibility = '1'\n                    AND tet.lastedit_user_id != {$user_id} {$sessionCondition}\n                 ORDER BY tet.lastedit_date";
     $res = Database::query($sql);
     // Get the group_id's with user membership.
     $group_ids = GroupManager::get_group_ids($course_info['real_id'], $user_id);
     $group_ids[] = 0;
     //add group 'everyone'
     $notifications = array();
     // Filter all last edits of all tools of the course
     while ($res && ($item_property = Database::fetch_array($res, 'ASSOC'))) {
         // First thing to check is if the user never entered the tool
         // or if his last visit was earlier than the last modification.
         if ((!isset($lastTrackInCourseDate[$item_property['tool']]) || $lastTrackInCourseDate[$item_property['tool']] < $item_property['lastedit_date']) && (in_array($item_property['to_group_id'], $group_ids) && ($item_property['tool'] != TOOL_NOTEBOOK && $item_property['tool'] != TOOL_CHAT)) && ($item_property['visibility'] == '1' || $course_info['status'] == '1' && $item_property['visibility'] == '0' || !isset($item_property['visibility']))) {
             // Also drop announcements and events that are not for the user or his group.
             if (($item_property['tool'] == TOOL_ANNOUNCEMENT || $item_property['tool'] == TOOL_CALENDAR_EVENT) && ($item_property['to_user_id'] != $user_id && (!isset($item_property['to_group_id']) || !in_array($item_property['to_group_id'], $group_ids)))) {
                 continue;
             }
             // If it's a survey, make sure the user's invited. Otherwise drop it.
             if ($item_property['tool'] == TOOL_SURVEY) {
                 $survey_info = SurveyManager::get_survey($item_property['ref'], 0, $course_code);
                 if (!empty($survey_info)) {
                     $invited_users = SurveyUtil::get_invited_users($survey_info['code'], $course_code);
                     if (!in_array($user_id, $invited_users['course_users'])) {
                         continue;
                     }
                 }
             }
             // If it's a learning path, ensure it is currently visible to the user
             if ($item_property['tool'] == TOOL_LEARNPATH) {
                 if (!learnpath::is_lp_visible_for_student($item_property['ref'], $user_id, $course_code)) {
                     continue;
                 }
             }
             if ($item_property['tool'] == TOOL_DROPBOX) {
                 $item_property['link'] = 'dropbox/dropbox_download.php?id=' . $item_property['ref'];
             }
             if ($item_property['tool'] == 'work' && $item_property['type'] == 'DirectoryCreated') {
                 $item_property['lastedit_type'] = 'WorkAdded';
             }
             $notifications[$item_property['tool']] = $item_property;
         }
     }
     // Show all tool icons where there is something new.
     $return = '&nbsp;';
     foreach ($notifications as $notification) {
         $lastDate = date('d/m/Y H:i', convert_sql_date($notification['lastedit_date']));
         $type = $notification['lastedit_type'];
         $label = get_lang('TitleNotification') . ": " . get_lang($type) . " ({$lastDate})";
         if (strpos($notification['link'], '?') === false) {
             $notification['link'] = $notification['link'] . '?notification=1';
         } else {
             $notification['link'] = $notification['link'] . '&notification=1';
         }
         $return .= Display::url(Display::return_icon($notification['image'], $label), api_get_path(WEB_CODE_PATH) . $notification['link'] . '&cidReq=' . $course_code . '&ref=' . $notification['ref'] . '&gidReq=' . $notification['to_group_id'] . '&id_session=' . $sessionId) . '&nbsp;';
     }
     return $return;
 }