Пример #1
0
		unset($_POST[$request_index]);
	}
}

// Database table definitions
$table_survey 					= Database :: get_course_table(TABLE_SURVEY);
$table_survey_question 			= Database :: get_course_table(TABLE_SURVEY_QUESTION);
$table_survey_question_option 	= Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);

$table_course 					= Database :: get_main_table(TABLE_MAIN_COURSE);
$table_user 					= Database :: get_main_table(TABLE_MAIN_USER);

$course_id = api_get_course_int_id();

// Getting the survey information
$survey_data = survey_manager::get_survey($_GET['survey_id']);
if (empty($survey_data)) {
	Display :: display_header(get_lang('ToolSurvey'));
	Display :: display_error_message(get_lang('InvallidSurvey'), false);
	Display :: display_footer();
	exit;
}

$urlname = api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40);
if (api_strlen(strip_tags($survey_data['title'])) > 40) {
	$urlname .= '...';
}

if ($survey_data['survey_type'] == 1) {
	$sql = 'SELECT id FROM '.Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP).'
	        WHERE
Пример #2
0
// Database table definitions
$table_survey = Database::get_course_table(TABLE_SURVEY);
$table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
$table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$table_survey_question_group = Database::get_course_table(TABLE_SURVEY_QUESTION_GROUP);
$table_course = Database::get_main_table(TABLE_MAIN_COURSE);
$table_user = Database::get_main_table(TABLE_MAIN_USER);
$survey_id = intval($_GET['survey_id']);
$course_id = api_get_course_int_id();
// Breadcrumbs
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH) . 'survey/survey_list.php', 'name' => get_lang('SurveyList'));
// Getting the survey information
if (isset($_GET['survey_id'])) {
    $course_code = api_get_course_id();
    if ($course_code != -1) {
        $survey_data = survey_manager::get_survey($survey_id);
    } else {
        Display::display_header(get_lang('ToolSurvey'));
        Display::display_error_message(get_lang('NotAllowed'), false);
        Display::display_footer();
        exit;
    }
}
$tool_name = strip_tags($survey_data['title']);
$is_survey_type_1 = $survey_data['survey_type'] == 1;
if (api_strlen(strip_tags($survey_data['title'])) > 40) {
    $tool_name .= '...';
}
if ($is_survey_type_1 && isset($_GET['action']) && ($_GET['action'] == 'addgroup' || $_GET['action'] == 'deletegroup')) {
    $_POST['name'] = trim($_POST['name']);
    if ($_GET['action'] == 'addgroup') {
Пример #3
0
        while ($row = Database::fetch_array($result, 'ASSOC')) {
            echo '<option value="'.$row['survey_id'].'">'.$row['lang'].'</option>';
        }
        echo '</select>';
        echo '<button type="submit" name="Submit" class="next">'.get_lang('Ok').'</button>';
        echo '</form>';
        Display::display_footer();
        exit();
    }
} else {
    $row = Database::fetch_array($result, 'ASSOC');
    $survey_invitation['survey_id'] = $row['survey_id'];
}

// Getting the survey information
$survey_data = survey_manager::get_survey($survey_invitation['survey_id']);
$survey_data['survey_id'] = $survey_invitation['survey_id'];

// Storing the answers
if (count($_POST) > 0) {
    if ($survey_data['survey_type'] === '0') {
        // Getting all the types of the question
        // (because of the special treatment of the score question type
        $sql = "SELECT * FROM $table_survey_question
                WHERE
                    c_id = $course_id AND
                    survey_id = '".intval($survey_invitation['survey_id'])."'";
        $result = Database::query($sql);

        while ($row = Database::fetch_array($result, 'ASSOC')) {
            $types[$row['question_id']] = $row['type'];
Пример #4
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
  *
  */
 static function save_invitations($users_array, $invitation_title, $invitation_text, $reminder = 0, $sendmail = 0, $remindUnAnswered = 0)
 {
     if (!is_array($users_array)) {
         return 0;
         // Should not happen
     }
     // Getting the survey information
     $survey_data = survey_manager::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 = survey_manager::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();
     $send_to = UserManager::separate_users_groups_array($users_array, true);
     $users_array = $send_to['users'];
     $group_list_added = self::get_group_invitations($survey_data['code']);
     if (!empty($send_to['groups'])) {
         foreach ($send_to['groups'] as $group_id) {
             if (!in_array($group_id, $group_list_added)) {
                 $params = array('c_id' => $course_id, 'session_id' => $session_id, 'group_id' => $group_id, 'survey_code' => $survey_data['code'], 'invitation_date' => api_get_utc_datetime());
                 self::save_invitation($params);
             }
         }
     }
     foreach ($users_array as $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
 }
Пример #5
0
<?php

/* For licensing terms, see /license.txt */
//require_once '../inc/global.inc.php';
$survey_id = isset($_REQUEST['i']) ? intval($_REQUEST['i']) : null;
if (empty($survey_id)) {
    api_not_allowed(true);
}
if (!survey_manager::survey_generation_hash_available()) {
    api_not_allowed(true);
}
$course_info = api_get_course_info_by_id($_REQUEST['c']);
$hash_is_valid = survey_manager::validate_survey_hash($survey_id, $_REQUEST['c'], $_REQUEST['s'], $_REQUEST['g'], $_REQUEST['h']);
if ($hash_is_valid && $course_info) {
    $survey_data = survey_manager::get_survey($survey_id, null, $course_info['code']);
    $invitation_code = api_get_unique_id();
    $params = array('c_id' => $_REQUEST['c'], 'session_id' => $_REQUEST['s'], 'user' => $invitation_code, 'survey_code' => $survey_data['code'], 'invitation_code' => $invitation_code, 'invitation_date' => api_get_utc_datetime());
    $invitation_id = SurveyUtil::save_invitation($params);
    if ($invitation_id) {
        $link = api_get_path(WEB_CODE_PATH) . 'survey/fillsurvey.php?invitationcode=' . $invitation_code . '&course=' . $course_info['code'];
        header('Location: ' . $link);
        exit;
    }
} else {
    api_not_allowed(true);
}
Пример #6
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;
 }
Пример #7
0
            exit;
        }
    }
    $return = survey_manager::empty_survey(intval($_GET['survey_id']));
    if ($return) {
        Display::display_confirmation_message(get_lang('SurveyEmptied'), false);
    } else {
        Display::display_error_message(get_lang('ErrorOccurred'), false);
    }
}
// Action handling: performing the same action on multiple surveys
if (isset($_POST['action']) && $_POST['action']) {
    if (is_array($_POST['id'])) {
        foreach ($_POST['id'] as $key => &$value) {
            // getting the information of the survey (used for when the survey is shared)
            $survey_data = survey_manager::get_survey($value);
            // if the survey is shared => also delete the shared content
            if (is_numeric($survey_data['survey_share'])) {
                survey_manager::delete_survey($survey_data['survey_share'], true);
            }
            // delete the actual survey
            survey_manager::delete_survey($value);
        }
        Display::display_confirmation_message(get_lang('SurveysDeleted'), false);
    } else {
        Display::display_error_message(get_lang('NoSurveysSelected'), false);
    }
}
echo '<div class="actions">';
if (!api_is_course_coach() || $extend_rights_for_coachs == 'true') {
    // Action links
Пример #8
0
if (empty($survey_data)) {
	Display::display_header(get_lang('SurveyPreview'));
	Display::display_error_message(get_lang('InvallidSurvey'), false);
	Display::display_footer();
	exit;
}

$urlname = strip_tags($survey_data['title']);
if (api_is_allowed_to_edit()) {
        // Breadcrumbs
	$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
	$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id, 'name' => $urlname);
}
$courseCode = isset($_GET['cidReq']) ? $_GET['cidReq'] : null;
$surveyAnonymous = survey_manager::get_survey($survey_id, 0, $courseCode);
$surveyAnonymous = $surveyAnonymous['anonymous'];
if ($surveyAnonymous == 0 && api_is_anonymous()) {
    api_not_allowed(true);
} elseif ($surveyAnonymous == 0 && $userInvited == 0) {
    if (!api_is_allowed_to_edit()) {
        api_not_allowed(true);
    }
}
// Header
Display :: display_header(get_lang('SurveyPreview'));

// We exit here is the first or last question is a pagebreak (which causes errors)
SurveyUtil::check_first_last_question($survey_id, false);

// Only a course admin is allowed to preview a survey: you are NOT a course admin => error message