Пример #1
0
 /**
  * This function changes the modify column of the sortable table
  *
  * @param integer $survey_id the id of the survey
  * @return html code that are the actions that can be performed on any survey
  *
  * @author Patrick Cool <*****@*****.**>, Ghent University
  * @version January 2007
  */
 static function modify_filter($survey_id)
 {
     $survey_id = Security::remove_XSS($survey_id);
     $return = '';
     // Coach can see that only if the survey is in his session
     if (api_is_allowed_to_edit() || api_is_element_in_the_session(TOOL_SURVEY, $survey_id)) {
         $return .= '<a href="create_new_survey.php?' . api_get_cidreq() . '&amp;action=edit&amp;survey_id=' . $survey_id . '">' . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . '</a>';
         if (survey_manager::survey_generation_hash_available()) {
             $return .= Display::url(Display::return_icon('new_link.png', get_lang('GenerateSurveyAccessLink'), '', ICON_SIZE_SMALL), 'generate_link.php?survey_id=' . $survey_id . '&' . api_get_cidreq());
         }
         $return .= Display::url(Display::return_icon('copy.png', get_lang('DuplicateSurvey'), '', ICON_SIZE_SMALL), 'survey_list.php?action=copy_survey&survey_id=' . $survey_id . '&' . api_get_cidreq());
         $return .= ' <a href="survey_list.php?' . api_get_cidreq() . '&amp;action=empty&amp;survey_id=' . $survey_id . '" onclick="javascript: if(!confirm(\'' . addslashes(api_htmlentities(get_lang("EmptySurvey") . '?')) . '\')) return false;">' . Display::return_icon('clean.png', get_lang('EmptySurvey'), '', ICON_SIZE_SMALL) . '</a>&nbsp;';
     }
     $return .= '<a href="preview.php?' . api_get_cidreq() . '&amp;survey_id=' . $survey_id . '">' . Display::return_icon('preview_view.png', get_lang('Preview'), '', ICON_SIZE_SMALL) . '</a>&nbsp;';
     $return .= '<a href="survey_invite.php?' . api_get_cidreq() . '&amp;survey_id=' . $survey_id . '">' . Display::return_icon('mail_send.png', get_lang('Publish'), '', ICON_SIZE_SMALL) . '</a>&nbsp;';
     $return .= '<a href="reporting.php?' . api_get_cidreq() . '&amp;survey_id=' . $survey_id . '">' . Display::return_icon('stats.png', get_lang('Reporting'), '', ICON_SIZE_SMALL) . '</a>';
     if (api_is_allowed_to_edit() || api_is_element_in_the_session(TOOL_SURVEY, $survey_id)) {
         $return .= '<a href="survey_list.php?' . api_get_cidreq() . '&amp;action=delete&amp;survey_id=' . $survey_id . '" onclick="javascript: if(!confirm(\'' . addslashes(api_htmlentities(get_lang("DeleteSurvey") . '?', ENT_QUOTES)) . '\')) return false;">' . Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . '</a>&nbsp;';
     }
     return $return;
 }
Пример #2
0
<?php

/* For licensing terms, see /license.txt */
$language_file = 'survey';
//require_once '../inc/global.inc.php';
if (!api_is_allowed_to_edit(false, true)) {
    api_not_allowed(true);
}
$survey_id = isset($_REQUEST['survey_id']) ? intval($_REQUEST['survey_id']) : null;
if (empty($survey_id)) {
    api_not_allowed(true);
}
$survey_data = survey_manager::get_survey($survey_id);
$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' => strip_tags($survey_data['title']));
Display::display_header(get_lang('Survey'), 'Survey');
if (!survey_manager::survey_generation_hash_available()) {
    api_not_allowed(true);
}
$link = survey_manager::generate_survey_link($survey_id, api_get_course_int_id(), api_get_session_id(), api_get_group_id());
echo '<div class="row">';
echo '<div class="span12" style="text-align:center">';
echo Display::url(get_lang('GenerateSurveyAccessLink'), $link, array('class' => 'btn btn-primary btn-large'));
echo '</div>';
echo '<div class="span12">';
echo get_lang('GenerateSurveyAccessLinkExplanation');
echo '<pre>';
echo $link;
echo '</pre>';
echo '</div>';
echo '</div>';
Пример #3
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);
}
    /**
     * Gets the progress of the given session
     * @param int   session id
     * @param array options order and limit keys
     * @return array table with user name, lp name, progress
     */
    public static function get_session_progress($sessionId, $courseId, $date_from, $date_to, $options)
    {
        $sessionId = intval($sessionId);

        $getAllSessions = false;
        if (empty($sessionId)) {
            $sessionId = 0;
            $getAllSessions = true;
        }

        //tables
        $session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
        $user = Database::get_main_table(TABLE_MAIN_USER);
        $course_rel_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
        $workTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
        $workTableAssignment = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
        $forum = Database::get_course_table(TABLE_FORUM);
        $forum_post = Database::get_course_table(TABLE_FORUM_POST);
        $tbl_course_lp = Database::get_course_table(TABLE_LP_MAIN);
        $wiki = Database::get_course_table(TABLE_WIKI);
        $table_stats_default = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DEFAULT);
        $table_stats_access = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);

        $course = api_get_course_info_by_id($courseId);

        //getting all the students of the course
        //we are not using this because it only returns user ids
        /* if (empty($sessionId)
          {
          // Registered students in a course outside session.
          $users = CourseManager :: get_student_list_from_course_code($course_code);
          } else {
          // Registered students in session.
          $users = CourseManager :: get_student_list_from_course_code($course_code, true, $sessionId);
          } */
        $where = " WHERE course_code = '%s' AND s.status <> 2 ";

        $limit = null;
        if (!empty($options['limit'])) {
            $limit = " LIMIT " . $options['limit'];
        }

        if (!empty($options['where'])) {
            $where .= ' '.$options['where'];
        }

        $order = null;
        if (!empty($options['order'])) {
            $order = " ORDER BY " . $options['order'];
        }

        //TODO, fix create report without session
        $queryVariables = array($course['code']);
        if (!empty($sessionId)) {
            $where .= ' AND id_session = %s';
            $queryVariables[] = $sessionId;
            $sql = "SELECT
                      u.user_id, u.lastname, u.firstname, u.username,
                      u.email, s.course_code, s.id_session
                    FROM $session_course_user s
                    INNER JOIN $user u
                    ON u.user_id = s.id_user
                    $where $order $limit";
        } else {
            $sql = "SELECT
                        u.user_id, u.lastname, u.firstname, u.username,
                        u.email, s.course_code, s.id_session
                    FROM $session_course_user s
                    INNER JOIN $user u ON u.user_id = s.id_user
                    $where $order $limit";
        }

        $sql_query = vsprintf($sql, $queryVariables);
        $rs = Database::query($sql_query);
        while ($user = Database::fetch_array($rs)) {
            $users[$user['user_id']] = $user;
        }

        /**
         *  Lessons
         */
        $sql = "SELECT * FROM $tbl_course_lp WHERE c_id = %s ";  //AND session_id = %s
        $sql_query = sprintf($sql, $course['real_id']);
        $result = Database::query($sql_query);
        $arrLesson = array(array());
        while ($row = Database::fetch_array($result)) {
//            if (api_get_item_visibility(api_get_course_info($course['code']), 'learnpath', $row['id'], $row['session_id']))
//            {
            if (empty($arrLesson[$row['session_id']]['lessons_total'])) {
                $arrLesson[$row['session_id']]['lessons_total'] = 1;
            } else {
                $arrLesson[$row['session_id']]['lessons_total'] ++;
            }
//            }
        }

        /**
         *  Exercises
         */
        require_once api_get_path(SYS_CODE_PATH) . 'exercice/exercise.lib.php';
        $exercises = get_all_exercises($course, $sessionId, false, '', $getAllSessions);
        $exercises_total = count($exercises);

        /**
         *  Assignments
         */
        //total
        if ($getAllSessions) {
            $sql = "SELECT count(w.id) as count
                    FROM $workTable w
                    LEFT JOIN  $workTableAssignment a
                    ON (a.publication_id = w.id AND a.c_id = w.c_id)
                    WHERE w.c_id = %s
                    AND parent_id = 0
                    AND active IN (1, 0)";
        } else {
            $sql = "SELECT count(w.id) as count
                    FROM $workTable w
                    LEFT JOIN  $workTableAssignment a
                    ON (a.publication_id = w.id AND a.c_id = w.c_id)
                    WHERE w.c_id = %s
                    AND parent_id = 0
                    AND active IN (1, 0)
                    AND  session_id = %s";
        }

        $sql_query = sprintf($sql, $course['real_id'], $sessionId);
        $result = Database::query($sql_query);
        $row = Database::fetch_array($result);
        $assignments_total = $row['count'];

        /**
         * Wiki
         */
        if ($getAllSessions) {
            $sql = "SELECT count(distinct page_id)  as count FROM $wiki
                    WHERE c_id = %s";
        } else {
            $sql = "SELECT count(distinct page_id)  as count FROM $wiki
                    WHERE c_id = %s and session_id = %s";
        }
        $sql_query = sprintf($sql, $course['real_id'], $sessionId);
        $result = Database::query($sql_query);
        $row = Database::fetch_array($result);
        $wiki_total = $row['count'];

        /**
         * Surveys
         */
        $survey_user_list = array();
        $survey_list = survey_manager::get_surveys($course['code'], $sessionId);

        $surveys_total = count($survey_list);
        foreach ($survey_list as $survey) {
            $user_list = survey_manager::get_people_who_filled_survey(
                $survey['survey_id'],
                false,
                $course['real_id']
            );
            foreach ($user_list as $user_id) {
                isset($survey_user_list[$user_id]) ? $survey_user_list[$user_id] ++ : $survey_user_list[$user_id] = 1;
            }
        }

        /**
         * Forums
         */
        $forums_total = CourseManager::getCountForum(
            $course['real_id'],
            $sessionId,
            $getAllSessions
        );

        //process table info
        foreach ($users as $user) {
            //Course description
            $sql = "SELECT count(*) as count
                    FROM $table_stats_access
                    WHERE access_tool = 'course_description'
                    AND access_cours_code = '%s'
                    AND access_session_id = %s
                    AND access_user_id = %s ";
            $sql_query = sprintf($sql, $course['code'], $user['id_session'], $user['user_id']);

            $result = Database::query($sql_query);
            $row = Database::fetch_array($result);
            $course_description_progress = ($row['count'] > 0) ? 100 : 0;

            if (!empty($arrLesson[$user['id_session']]['lessons_total'])) {
                $lessons_total = $arrLesson[$user['id_session']]['lessons_total'];
            } else {
                $lessons_total = !empty($arrLesson[0]['lessons_total']) ? $arrLesson[0]['lessons_total'] : 0;
            }

            //Lessons
            //TODO: Lessons done and left is calculated by progress per item in lesson, maybe we should calculate it only per completed lesson?
            $lessons_progress = Tracking::get_avg_student_progress($user['user_id'], $course['code'], array(), $user['id_session']);
            $lessons_done = ($lessons_progress * $lessons_total) / 100;
            $lessons_left = $lessons_total - $lessons_done;

            //Exercises
            $exercises_progress = str_replace('%', '', Tracking::get_exercise_student_progress($exercises, $user['user_id'], $course['code'], $user['id_session']));
            $exercises_done = round(($exercises_progress * $exercises_total) / 100);
            $exercises_left = $exercises_total - $exercises_done;

            //Assignments
            $assignments_done = Tracking::count_student_assignments($user['user_id'], $course['code'], $user['id_session']);
            $assignments_left = $assignments_total - $assignments_done;
            if (!empty($assignments_total)) {
                $assignments_progress = round((( $assignments_done * 100 ) / $assignments_total), 2);
            } else {
                $assignments_progress = 0;
            }

            //Wiki
            //total revisions per user
            $sql = "SELECT count(*) as count
            FROM $wiki
            where c_id = %s and session_id = %s and user_id = %s";
            $sql_query = sprintf($sql, $course['real_id'], $user['id_session'], $user['user_id']);
            $result = Database::query($sql_query);
            $row = Database::fetch_array($result);
            $wiki_revisions = $row['count'];
            //count visited wiki pages
            $sql = "SELECT count(distinct default_value) as count
                    FROM $table_stats_default
                    WHERE default_user_id = %s
                    AND default_cours_code = '%s'
                    AND default_event_type = 'wiki_page_view'
                    AND default_value_type = 'wiki_page_id'
                    AND c_id = %s";
            $sql_query = sprintf($sql, $user['user_id'], $course['code'], $course['real_id']);
            $result = Database::query($sql_query);
            $row = Database::fetch_array($result);

            $wiki_read = $row['count'];
            $wiki_unread = $wiki_total - $wiki_read;
            if (!empty($wiki_total)) {
                $wiki_progress = round((( $wiki_read * 100 ) / $wiki_total), 2);
            } else {
                $wiki_progress = 0;
            }

            //Surveys
            $surveys_done = (isset($survey_user_list[$user['user_id']]) ? $survey_user_list[$user['user_id']] : 0);
            $surveys_left = $surveys_total - $surveys_done;
            if (!empty($surveys_total)) {
                $surveys_progress = round((( $surveys_done * 100 ) / $surveys_total), 2);
            } else {
                $surveys_progress = 0;
            }

            //Forums
            $forums_done = CourseManager::getCountForumPerUser(
                $user['user_id'],
                $course['real_id'],
                $user['id_session']
            );
            $forums_left = $forums_total - $forums_done;
            if (!empty($forums_total)) {
                $forums_progress = round((( $forums_done * 100 ) / $forums_total), 2);
            } else {
                $forums_progress = 0;
            }

            //Overall Total
            $overall_total = ($course_description_progress + $exercises_progress + $forums_progress + $assignments_progress + $wiki_progress + $surveys_progress) / 6;

            $link = '<a href="' . api_get_path(WEB_CODE_PATH) . 'mySpace/myStudents.php?student=' . $user[0] . '&details=true&course=' . $course['code'] . '&id_session=' . $user['id_session'] . '"> %s </a>';
            $linkForum = '<a href="' . api_get_path(WEB_CODE_PATH) . 'forum/index.php?cidReq=' . $course['code'] . '&id_session=' . $user['id_session'] . '"> %s </a>';
            $linkWork = '<a href="' . api_get_path(WEB_CODE_PATH) . 'work/work.php?cidReq=' . $course['code'] . '&id_session=' . $user['id_session'] . '"> %s </a>';
            $linkWiki = '<a href="' . api_get_path(WEB_CODE_PATH) . 'wiki/index.php?cidReq=' . $course['code'] . '&session_id=' . $user['id_session'] . '&action=statistics"> %s </a>';
            $linkSurvey = '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/survey_list.php?cidReq=' . $course['code'] . '&id_session=' . $user['id_session'] . '"> %s </a>';

            $table[] = array(
                'lastname' => $user[1],
                'firstname' => $user[2],
                'username' => $user[3],
                #'profile'   => '',
                'total' => round($overall_total, 2) . '%',
                'courses' => sprintf($link, $course_description_progress . '%'),
                'lessons' => sprintf($link, $lessons_progress . '%'),
                'exercises' => sprintf($link, $exercises_progress . '%'),
                'forums' => sprintf($link, $forums_progress . '%'),
                'homeworks' => sprintf($link, $assignments_progress . '%'),
                'wikis' => sprintf($link, $wiki_progress . '%'),
                'surveys' => sprintf($link, $surveys_progress . '%'),
                //course description
                'course_description_progress' => $course_description_progress . '%',
                //lessons
                'lessons_total' => sprintf($link, $lessons_total),
                'lessons_done' => sprintf($link, $lessons_done),
                'lessons_left' => sprintf($link, $lessons_left),
                'lessons_progress' => sprintf($link, $lessons_progress . '%'),
                //exercises
                'exercises_total' => sprintf($link, $exercises_total),
                'exercises_done' => sprintf($link, $exercises_done),
                'exercises_left' => sprintf($link, $exercises_left),
                'exercises_progress' => sprintf($link, $exercises_progress . '%'),
                //forums
                'forums_total' => sprintf($linkForum, $forums_total),
                'forums_done' => sprintf($linkForum, $forums_done),
                'forums_left' => sprintf($linkForum, $forums_left),
                'forums_progress' => sprintf($linkForum, $forums_progress . '%'),
                //assignments
                'assignments_total' => sprintf($linkWork, $assignments_total),
                'assignments_done' => sprintf($linkWork, $assignments_done),
                'assignments_left' => sprintf($linkWork, $assignments_left),
                'assignments_progress' => sprintf($linkWork, $assignments_progress . '%'),
                //wiki
                'wiki_total' => sprintf($linkWiki, $wiki_total),
                'wiki_revisions' => sprintf($linkWiki, $wiki_revisions),
                'wiki_read' => sprintf($linkWiki, $wiki_read),
                'wiki_unread' => sprintf($linkWiki, $wiki_unread),
                'wiki_progress' => sprintf($linkWiki, $wiki_progress . '%'),
                //survey
                'surveys_total' => sprintf($linkSurvey, $surveys_total),
                'surveys_done' => sprintf($linkSurvey, $surveys_done),
                'surveys_left' => sprintf($linkSurvey, $surveys_left),
                'surveys_progress' => sprintf($linkSurvey, $surveys_progress . '%'),
            );
        }

        return $table;
    }
Пример #5
0
    /**
     * Get data for users list in sortable with pagination
     * @param $from
     * @param $number_of_items
     * @param $column
     * @param $direction
     * @return array
     */
    public static function get_user_data($from, $number_of_items, $column, $direction)
    {
        global $user_ids, $course_code, $additional_user_profile_info, $export_csv, $is_western_name_order, $csv_content, $session_id;

    	$course_code        = Database::escape_string($course_code);
    	$tbl_user           = Database::get_main_table(TABLE_MAIN_USER);
    	$tbl_url_rel_user   = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);

    	$access_url_id      = api_get_current_access_url_id();

    	// get all users data from a course for sortable with limit
    	if (is_array($user_ids)) {
    		$user_ids = array_map('intval', $user_ids);
    		$condition_user = "******".implode(',',$user_ids).") ";
    	} else {
    		$user_ids = intval($user_ids);
    		$condition_user = "******";
    	}

    	if (!empty($_GET['user_keyword'])) {
    		$keyword = trim(Database::escape_string($_GET['user_keyword']));
    		$condition_user .=  " AND (
                user.firstname LIKE '%".$keyword."%' OR
                user.lastname LIKE '%".$keyword."%'  OR
                user.username LIKE '%".$keyword."%'  OR
                user.email LIKE '%".$keyword."%'
             ) ";
    	}

        $url_table = null;
        $url_condition = null;
    	if (api_is_multiple_url_enabled()) {
    		$url_table = ", ".$tbl_url_rel_user."as url_users";
    		$url_condition = " AND user.user_id = url_users.user_id AND access_url_id='$access_url_id'";
    	}

    	$sql = "SELECT  user.user_id as user_id,
                    user.official_code  as col0,
                    user.lastname       as col1,
                    user.firstname      as col2,
                    user.username       as col3
                FROM $tbl_user as user $url_table
    	        $condition_user $url_condition";

    	if (!in_array($direction, array('ASC','DESC'))) {
    		$direction = 'ASC';
    	}

    	$column = intval($column);

    	$from = intval($from);
    	$number_of_items = intval($number_of_items);

    	$sql .= " ORDER BY col$column $direction ";
    	$sql .= " LIMIT $from,$number_of_items";

    	$res      = Database::query($sql);
    	$users    = array();

        $course_info = api_get_course_info($course_code);
        $total_surveys = 0;
        $total_exercises = get_all_exercises(
            $course_info,
            $session_id,
            false,
            null,
            false,
            3
        );

        if (empty($session_id)) {
            $survey_user_list = array();
            $survey_list = survey_manager::get_surveys($course_code, $session_id);

            $total_surveys = count($survey_list);
            foreach ($survey_list as $survey) {
                $user_list = survey_manager::get_people_who_filled_survey(
                    $survey['survey_id'],
                    false,
                    $course_info['real_id']
                );

                foreach ($user_list as $user_id) {
                    isset($survey_user_list[$user_id]) ? $survey_user_list[$user_id]++ : $survey_user_list[$user_id] = 1;
                }
            }
        }

    	while ($user = Database::fetch_array($res, 'ASSOC')) {
    		$user['official_code']  = $user['col0'];
            $user['lastname']       = $user['col1'];
            $user['firstname']      = $user['col2'];
    		$user['username']       = $user['col3'];
    		$user['time'] = api_time_to_hms(Tracking::get_time_spent_on_the_course($user['user_id'], $course_code, $session_id));

            $avg_student_score = Tracking::get_avg_student_score(
                $user['user_id'],
                $course_code,
                array(),
                $session_id
            );

            $avg_student_progress = Tracking::get_avg_student_progress(
                $user['user_id'],
                $course_code,
                array(),
                $session_id
            );
    		if (empty($avg_student_progress)) {
    			$avg_student_progress=0;
    		}
    		$user['average_progress']   = $avg_student_progress.'%';

            $total_user_exercise = Tracking::get_exercise_student_progress(
                $total_exercises,
                $user['user_id'],
                $course_code,
                $session_id
            );

            $user['exercise_progress']  = $total_user_exercise;

            $total_user_exercise = Tracking::get_exercise_student_average_best_attempt(
                $total_exercises,
                $user['user_id'],
                $course_code,
                $session_id
            );

            $user['exercise_average_best_attempt']  = $total_user_exercise;

    		if (is_numeric($avg_student_score)) {
    			$user['student_score']  = $avg_student_score.'%';
    		} else {
    			$user['student_score']  = $avg_student_score;
    		}

    		$user['count_assignments']  = Tracking::count_student_assignments($user['user_id'], $course_code, $session_id);
    		$user['count_messages']     = Tracking::count_student_messages($user['user_id'], $course_code, $session_id);
    		$user['first_connection']   = Tracking::get_first_connection_date_on_the_course($user['user_id'], $course_code, $session_id);
    		$user['last_connection']    = Tracking::get_last_connection_date_on_the_course($user['user_id'], $course_code, $session_id);

    		// we need to display an additional profile field
    		$user['additional'] = '';

    		if (isset($_GET['additional_profile_field']) AND is_numeric($_GET['additional_profile_field'])) {
    			if (isset($additional_user_profile_info[$user['user_id']]) &&
                    is_array($additional_user_profile_info[$user['user_id']])
                ) {
    				$user['additional'] = implode(', ', $additional_user_profile_info[$user['user_id']]);
    			}
    		}

            if (empty($session_id)) {
                $user['survey'] = (isset($survey_user_list[$user['user_id']]) ? $survey_user_list[$user['user_id']] : 0) .' / '.$total_surveys;
            }

    		$user['link'] = '<center><a href="../mySpace/myStudents.php?student='.$user['user_id'].'&details=true&course='.$course_code.'&origin=tracking_course&id_session='.$session_id.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></center>';

    		// store columns in array $users

    		$is_western_name_order = api_is_western_name_order();
            $user_row = array();

            $user_row[]= $user['official_code']; //0

            if ($is_western_name_order) {
                $user_row[]= $user['firstname'];
                $user_row[]= $user['lastname'];
            } else {
                $user_row[]= $user['lastname'];
                $user_row[]= $user['firstname'];
            }
            $user_row[]= $user['username'];
            $user_row[]= $user['time'];
            $user_row[]= $user['average_progress'];
            $user_row[]= $user['exercise_progress'];
            $user_row[]= $user['exercise_average_best_attempt'];
            $user_row[]= $user['student_score'];
            $user_row[]= $user['count_assignments'];
            $user_row[]= $user['count_messages'];

            if (empty($session_id)) {
                $user_row[]= $user['survey'];
            }

            $user_row[]= $user['first_connection'];
            $user_row[]= $user['last_connection'];
            if (isset($_GET['additional_profile_field']) AND is_numeric($_GET['additional_profile_field'])) {
                $user_row[]= $user['additional'];
            }

            $user_row[]= $user['link'];

            $users[] = $user_row;

    		if ($export_csv) {
    		    if (empty($session_id)) {
                    $user_row = array_map('strip_tags', $user_row);
    			    unset($user_row[14]);
    			    unset($user_row[15]);
                } else {
                    $user_row = array_map('strip_tags', $user_row);
                    unset($user_row[13]);
                    unset($user_row[14]);
                }

    			$csv_content[] = $user_row;
    		}
    	}
    	return $users;
    }
Пример #6
0
        // We unset the sessions
        unset($_SESSION['paged_questions']);
        unset($_SESSION['page_questions_sec']);
        $paged_questions_sec = array();
        $form->display();
    }
}

// Displaying the survey thanks message
if (isset($_POST['finish_survey'])) {
    Display::display_confirmation_message(get_lang('SurveyFinished'));
    echo $survey_data['survey_thanks'];

    survey_manager::update_survey_answered(
        $survey_data,
        $survey_invitation['user'],
        $survey_invitation['survey_code']
    );
    unset($_SESSION['paged_questions']);
    unset($_SESSION['page_questions_sec']);
    Display :: display_footer();
    exit();
}

// Sets the random questions
$shuffle = '';
if ($survey_data['shuffle'] == 1) {
    $shuffle = ' BY RAND() ';
}

if (isset($_GET['show']) || isset($_POST['personality'])) {
Пример #7
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
Пример #8
0
    } 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
    echo '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/create_new_survey.php?' . api_get_cidreq() . '&amp;action=add">' . Display::return_icon('new_survey.png', get_lang('CreateNewSurvey'), '', ICON_SIZE_MEDIUM) . '</a> ';
}
echo '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;search=advanced">' . Display::return_icon('search.png', get_lang('Search'), '', ICON_SIZE_MEDIUM) . '</a>';
echo '</div>';
// Load main content
if (api_is_course_coach() && $extend_rights_for_coachs == 'false') {
Пример #9
0
     break;
 case 'get_survey_overview':
     $sessionId = 0;
     if (!empty($_GET['session_id']) && !empty($_GET['course_id']) && !empty($_GET['survey_id'])) {
         $sessionId = intval($_GET['session_id']);
         $courseId = intval($_GET['course_id']);
         $surveyId = intval($_GET['survey_id']);
         $date_from = $_GET['date_from'];
         $date_to = $_GET['date_to'];
         //$course    = api_get_course_info_by_id($courseId);
     }
     /**
      * Add lessons of course
      */
     $columns = array('username', 'firstname', 'lastname');
     $questions = survey_manager::get_questions($surveyId, $courseId);
     foreach ($questions as $question_id => $question) {
         $columns[] = $question_id;
     }
     $result = SessionManager::get_survey_overview($sessionId, $courseId, $surveyId, $date_from, $date_to, array('where' => $whereCondition, 'order' => "{$sidx} {$sord}", 'limit' => "{$start} , {$limit}"));
     break;
 case 'get_session_progress':
     $columns = array('lastname', 'firstname', 'username', 'total', 'courses', 'lessons', 'exercises', 'forums', 'homeworks', 'wikis', 'surveys', 'lessons_total', 'lessons_done', 'lessons_left', 'lessons_progress', 'exercises_total', 'exercises_done', 'exercises_left', 'exercises_progress', 'forums_total', 'forums_done', 'forums_left', 'forums_progress', 'assignments_total', 'assignments_done', 'assignments_left', 'assignments_progress', 'wiki_total', 'wiki_revisions', 'wiki_read', 'wiki_unread', 'wiki_progress', 'surveys_total', 'surveys_done', 'surveys_left', 'surveys_progress');
     $sessionId = 0;
     if (!empty($_GET['course_id']) && !empty($_GET['session_id'])) {
         $sessionId = intval($_GET['session_id']);
         $courseId = intval($_GET['course_id']);
     }
     $result = SessionManager::get_session_progress($sessionId, $courseId, array('where' => $whereCondition, 'order' => "{$sidx} {$sord}", 'limit' => "{$start} , {$limit}"));
     break;
 case 'get_session_access_overview':
Пример #10
0
    /**
     * Display a sortable table that contains an overview off all the progress of the user in a session
     * @author César Perales <*****@*****.**>, Beeznest Team
     */
    function display_survey_overview($sessionId = 0, $courseId = 0, $surveyId = 0, $date_from, $date_to)
    {
        /**
         * Column name
         * The order is important you need to check the $column variable in the model.ajax.php file
         */
        $columns = array(
            get_lang('Username'),
            get_lang('FirstName'),
            get_lang('LastName'),
        );
        //add lessons of course
        $questions = survey_manager::get_questions($surveyId, $courseId);

        foreach ($questions as $question) {
            $columns[] = $question['question'];
        }

        /**
         * Column config
         */
        $column_model   = array(
            array('name'=>'username',   'index'=>'username',    'align'=>'left', 'search' => 'true', 'wrap_cell' => "true"),
            array('name'=>'firstname',  'index'=>'firstname',   'align'=>'left', 'search' => 'true'),
            array('name'=>'lastname',   'index'=>'lastname',    'align'=>'left', 'search' => 'true'),
        );
        //get dinamic column names
        foreach ($questions as $question_id => $question) {
            $column_model[] = array(
                'name'=> $question_id,
                'index'=>$question_id,
                'width'=>'70',
                'align'=>'left',
                'search' => 'true'
            );
        }

        $action_links = '';

        // jqgrid will use this URL to do the selects
        $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_survey_overview&session_id=' . $sessionId . '&course_id=' . $courseId . '&survey_id=' . $surveyId . '&date_to=' . $date_to . '&date_from=' . $date_from;

        //Table Id
        $tableId = 'lpProgress';

        //Autowidth
        $extra_params['autowidth'] = 'true';

        //height auto
        $extra_params['height'] = 'auto';

        $table = Display::grid_js($tableId, $url, $columns, $column_model, $extra_params, array(), $action_links, true);

        $return = '<script>$(function() {'. $table .
            'jQuery("#'.$tableId.'").jqGrid("navGrid","#'.$tableId.'_pager",{view:false, edit:false, add:false, del:false, search:false, excel:true});
                jQuery("#'.$tableId.'").jqGrid("navButtonAdd","#'.$tableId.'_pager",{
                       caption:"",
                       title:"' . get_lang('ExportExcel') . '",
                       onClickButton : function () {
                           jQuery("#'.$tableId.'").jqGrid("excelExport",{"url":"'.$url.'&export_format=xls"});
                       }
                });
            });</script>';
        $return .= Display::grid_html($tableId);

        return $return;
    }
Пример #11
0
    $form->addRule('survey_code', '', 'maxlength', 20);
}
$form->addRule('survey_title', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('start_date', get_lang('InvalidDate'), 'date');
$form->addRule('end_date', get_lang('InvalidDate'), 'date');
$form->addRule(array('start_date', 'end_date'), get_lang('StartDateShouldBeBeforeEndDate'), 'date_compare', 'lte');

// Setting the default values
$form->setDefaults($defaults);

// The validation or display
if ($form->validate()) {
    // Exporting the values
    $values = $form->exportValues();
    // Storing the survey
    $return = survey_manager::store_survey($values);

    /* // Deleting the shared survey if the survey is getting unshared (this only happens when editing)
      if (is_numeric($survey_data['survey_share']) && $values['survey_share']['survey_share'] == 0 && $values['survey_id'] != '') {
      survey_manager::delete_survey($survey_data['survey_share'], true);
      }
      // Storing the already existing questions and options of a survey that gets shared (this only happens when editing)
      if ($survey_data['survey_share'] == 0 && $values['survey_share']['survey_share'] !== 0 && $values['survey_id'] != '') {
      survey_manager::get_complete_survey_structure($return['id']);
      }
     */
    if ($return['type'] == 'error') {
        // Display the error
        Display::display_error_message(get_lang($return['message']), false);

        // Displaying the header
if (api_strlen(strip_tags($survey_data['title'])) > 40) {
    $urlname .= '...';
}
// Breadcrumbs
$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
$interbreadcrumb[] = array('url' => 'survey.php?survey_id=' . $survey_id, 'name' => $urlname);
// Displaying the header
Display::display_header($tool_name);
// Checking the parameters
if (!is_numeric($survey_id)) {
    Display::display_error_message(get_lang('Error'), false);
    Display::display_footer();
    exit;
}
// Getting all the people who have filled this survey
$answered_data = survey_manager::get_people_who_filled_survey($survey_id);
if ($survey_data['anonymous'] == 1) {
    Display::display_normal_message(get_lang('AnonymousSurveyCannotKnowWhoAnswered') . ' ' . count($answered_data) . ' ' . get_lang('PeopleAnswered'));
    $answered_data = array();
}
if (!isset($_GET['view']) or $_GET['view'] == 'invited') {
    echo get_lang('ViewInvited') . ' | ';
} else {
    echo '	<a href="' . api_get_self() . '?survey_id=' . $survey_id . '&amp;view=invited">' . get_lang('ViewInvited') . '</a> |';
}
if ($_GET['view'] == 'answered') {
    echo get_lang('ViewAnswered') . ' | ';
} else {
    echo '	<a href="' . api_get_self() . '?survey_id=' . $survey_id . '&amp;view=answered">' . get_lang('ViewAnswered') . '</a> |';
}
if ($_GET['view'] == 'unanswered') {
Пример #13
0
         echo '</td></tr>';
         $data_exercices[$i][] = $exercices['title'];
         $data_exercices[$i][] = $score_percentage . '%';
         $data_exercices[$i][] = $count_attempts;
         $i++;
     }
 } else {
     echo '<tr><td colspan="6">' . get_lang('NoExercise') . '</td></tr>';
 }
 echo '</table>';
 //@when using sessions we do not show the survey list
 if (empty($session_id)) {
     $survey_list = survey_manager::get_surveys($courseInfo['code'], $session_id);
     $survey_data = array();
     foreach ($survey_list as $survey) {
         $user_list = survey_manager::get_people_who_filled_survey($survey['survey_id'], false, $courseId);
         $survey_done = Display::return_icon("accept_na.png", get_lang('NoAnswer'), array(), ICON_SIZE_SMALL);
         if (in_array($student_id, $user_list)) {
             $survey_done = Display::return_icon("accept.png", get_lang('Answered'), array(), ICON_SIZE_SMALL);
         }
         $data = array('title' => $survey['title'], 'done' => $survey_done);
         $survey_data[] = $data;
     }
     if (!empty($survey_list)) {
         $table = new HTML_Table(array('class' => 'data_table'));
         $header_names = array(get_lang('Survey'), get_lang('Answered'));
         $row = 0;
         $column = 0;
         foreach ($header_names as $item) {
             $table->setHeaderContents($row, $column, $item);
             $column++;
Пример #14
0
                $i++;

            }
        } else {
            echo '<tr><td colspan="6">'.get_lang('NoExercise').'</td></tr>';
        }
        echo '</table>';

        //@when using sessions we do not show the survey list
        if (empty($session_id)) {
            $survey_list = survey_manager::get_surveys($course_code, $session_id);

            $survey_data = array();
            foreach($survey_list as $survey) {
                $user_list = survey_manager::get_people_who_filled_survey($survey['survey_id'], false, $info_course['real_id']);
                $survey_done = Display::return_icon("accept_na.png", get_lang('NoAnswer'), array(), ICON_SIZE_SMALL);
                if (in_array($student_id, $user_list)) {
                    $survey_done = Display::return_icon("accept.png", get_lang('Answered'), array(), ICON_SIZE_SMALL);
                }
                $data = array('title' => $survey['title'], 'done' => $survey_done);
                $survey_data[] = $data;
            }

            if (!empty($survey_list)) {
                $table = new HTML_Table(array('class' => 'data_table'));
                $header_names = array(get_lang('Survey'), get_lang('Answered'));
                $row = 0;
                $column = 0;
                foreach ($header_names as $item) {
                    $table->setHeaderContents($row, $column, $item);
Пример #15
0
    exit;
}
// Displaying the header
Display::display_header($tool_name, 'Survey');
// Action handling
$my_action_survey = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
$my_question_id_survey = isset($_GET['question_id']) ? Security::remove_XSS($_GET['question_id']) : null;
$my_survey_id_survey = Security::remove_XSS($_GET['survey_id']);
$message_information = isset($_GET['message']) ? Security::remove_XSS($_GET['message']) : null;
if (isset($_GET['action'])) {
    if (($_GET['action'] == 'moveup' || $_GET['action'] == 'movedown') && isset($_GET['question_id'])) {
        survey_manager::move_survey_question($my_action_survey, $my_question_id_survey, $my_survey_id_survey);
        Display::display_confirmation_message(get_lang('SurveyQuestionMoved'));
    }
    if ($_GET['action'] == 'delete' and is_numeric($_GET['question_id'])) {
        survey_manager::delete_survey_question($my_survey_id_survey, $my_question_id_survey, $survey_data['is_shared']);
    }
}
if (isset($_GET['message'])) {
    // We have created the survey or updated the survey
    if (in_array($_GET['message'], array('SurveyUpdatedSuccesfully', 'SurveyCreatedSuccesfully'))) {
        Display::display_confirmation_message(get_lang($message_information) . ', ' . PHP_EOL . api_strtolower(get_lang('YouCanNowAddQuestionToYourSurvey')));
    }
    // We have added a question
    if (in_array($_GET['message'], array('QuestionAdded', 'QuestionUpdated'))) {
        Display::display_confirmation_message(get_lang($message_information));
    }
    if (in_array($_GET['message'], array('YouNeedToCreateGroups'))) {
        Display::display_warning_message(get_lang($message_information), false);
    }
}
Пример #16
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;
 }
    /**
     * Restore surveys
     */
    function restore_surveys()
    {
        if ($this->course->has_resources(RESOURCE_SURVEY)) {
            $table_sur = Database::get_course_table(TABLE_SURVEY);
            $table_que = Database::get_course_table(TABLE_SURVEY_QUESTION);
            $table_ans = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
            $resources = $this->course->resources;
            foreach ($resources[RESOURCE_SURVEY] as $id => $survey) {
                $sql_check = 'SELECT survey_id FROM ' . $table_sur . '
							WHERE 	c_id = ' . $this->destination_course_id . ' AND
									code = "' . self::DBUTF8escapestring($survey->code) . '" AND
									lang = "' . self::DBUTF8escapestring($survey->lang) . '" ';
                $result_check = Database::query($sql_check);
                // check resources inside html from fckeditor tool and copy correct urls into recipient course
                $survey->title = DocumentManager::replace_urls_inside_content_html_from_copy_course($survey->title, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
                $survey->subtitle = DocumentManager::replace_urls_inside_content_html_from_copy_course($survey->subtitle, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
                $survey->intro = DocumentManager::replace_urls_inside_content_html_from_copy_course($survey->intro, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
                $survey->surveythanks = DocumentManager::replace_urls_inside_content_html_from_copy_course($survey->surveythanks, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
                $sql = "INSERT INTO " . $table_sur . " " . "SET\n\t\t\t\t\t\tc_id = " . $this->destination_course_id . " ,\n\t\t\t\t\t\tcode = '" . self::DBUTF8escapestring($survey->code) . "', " . "title = '" . self::DBUTF8escapestring($survey->title) . "', " . "subtitle = '" . self::DBUTF8escapestring($survey->subtitle) . "', " . "author = '" . self::DBUTF8escapestring($survey->author) . "', " . "lang = '" . self::DBUTF8escapestring($survey->lang) . "', " . "avail_from = '" . self::DBUTF8escapestring($survey->avail_from) . "', " . "avail_till = '" . self::DBUTF8escapestring($survey->avail_till) . "', " . "is_shared = '" . self::DBUTF8escapestring($survey->is_shared) . "', " . "template = '" . self::DBUTF8escapestring($survey->template) . "', " . "intro = '" . self::DBUTF8escapestring($survey->intro) . "', " . "surveythanks = '" . self::DBUTF8escapestring($survey->surveythanks) . "', " . "creation_date = '" . self::DBUTF8escapestring($survey->creation_date) . "', " . "invited = '0', " . "answered = '0', " . "invite_mail = '" . self::DBUTF8escapestring($survey->invite_mail) . "', " . "reminder_mail = '" . self::DBUTF8escapestring($survey->reminder_mail) . "'";
                //An existing survey exists with the same code and the same language
                if (Database::num_rows($result_check) == 1) {
                    switch ($this->file_option) {
                        case FILE_SKIP:
                            //Do nothing
                            break;
                        case FILE_RENAME:
                            $survey_code = $survey->code . '_';
                            $i = 1;
                            $temp_survey_code = $survey_code . $i;
                            while (!$this->is_survey_code_available($temp_survey_code)) {
                                $temp_survey_code = $survey_code . ++$i;
                            }
                            $survey_code = $temp_survey_code;
                            $sql = "INSERT INTO " . $table_sur . " " . "SET\n\t\t\t\t\t\t\t\t\tc_id = " . $this->destination_course_id . " ,\n\t\t\t\t\t\t\t\t\tcode = '" . self::DBUTF8escapestring($survey_code) . "', " . "title = '" . self::DBUTF8escapestring($survey->title) . "', " . "subtitle = '" . self::DBUTF8escapestring($survey->subtitle) . "', " . "author = '" . self::DBUTF8escapestring($survey->author) . "', " . "lang = '" . self::DBUTF8escapestring($survey->lang) . "', " . "avail_from = '" . self::DBUTF8escapestring($survey->avail_from) . "', " . "avail_till = '" . self::DBUTF8escapestring($survey->avail_till) . "', " . "is_shared = '" . self::DBUTF8escapestring($survey->is_shared) . "', " . "template = '" . self::DBUTF8escapestring($survey->template) . "', " . "intro = '" . self::DBUTF8escapestring($survey->intro) . "', " . "surveythanks = '" . self::DBUTF8escapestring($survey->surveythanks) . "', " . "creation_date = '" . self::DBUTF8escapestring($survey->creation_date) . "', " . "invited = '0', " . "answered = '0', " . "invite_mail = '" . self::DBUTF8escapestring($survey->invite_mail) . "', " . "reminder_mail = '" . self::DBUTF8escapestring($survey->reminder_mail) . "'";
                            //Insert the new source survey
                            Database::query($sql);
                            $new_id = Database::insert_id();
                            $this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id;
                            foreach ($survey->question_ids as $index => $question_id) {
                                $qid = $this->restore_survey_question($question_id, $new_id);
                                $sql = "UPDATE " . $table_que . " SET survey_id = " . $new_id . " WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}";
                                Database::query($sql);
                                $sql = "UPDATE " . $table_ans . " SET survey_id = " . $new_id . " WHERE  c_id = " . $this->destination_course_id . " AND  question_id = {$qid}";
                                Database::query($sql);
                            }
                            break;
                        case FILE_OVERWRITE:
                            // Delete the existing survey with the same code and language and import the one of the source course
                            // getting the information of the survey (used for when the survey is shared)
                            require_once api_get_path(SYS_CODE_PATH) . 'survey/survey.lib.php';
                            $sql_select_existing_survey = "SELECT * FROM {$table_sur} WHERE c_id = " . $this->destination_course_id . " AND survey_id='" . self::DBUTF8escapestring(Database::result($result_check, 0, 0)) . "'";
                            $result = Database::query($sql_select_existing_survey);
                            $survey_data = Database::fetch_array($result, 'ASSOC');
                            // 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, $this->destination_course_id);
                            }
                            $return = survey_manager::delete_survey($survey_data['survey_id'], false, $this->destination_course_id);
                            //Insert the new source survey
                            Database::query($sql);
                            $new_id = Database::insert_id();
                            $this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id;
                            foreach ($survey->question_ids as $index => $question_id) {
                                $qid = $this->restore_survey_question($question_id, $new_id);
                                $sql = "UPDATE {$table_que} SET survey_id = {$new_id} WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}";
                                Database::query($sql);
                                $sql = "UPDATE {$table_ans} SET survey_id = {$new_id} WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}";
                                Database::query($sql);
                            }
                            break;
                        default:
                            break;
                    }
                } else {
                    Database::query($sql);
                    $new_id = Database::insert_id();
                    $this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id;
                    foreach ($survey->question_ids as $index => $question_id) {
                        $qid = $this->restore_survey_question($question_id, $new_id);
                        $sql = "UPDATE {$table_que} SET survey_id = {$new_id} WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}";
                        Database::query($sql);
                        $sql = "UPDATE {$table_ans} SET survey_id = {$new_id} WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}";
                        Database::query($sql);
                    }
                }
            }
        }
    }
Пример #18
0
/** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
if (!(api_is_allowed_to_edit(false, true) || $isDrhOfCourse)) {
    Display :: display_header(get_lang('ToolSurvey'));
    Display :: display_error_message(get_lang('NotAllowed'), false);
    Display :: display_footer();
    exit;
}

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

// Getting the survey information

$survey_data = survey_manager::get_survey($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 = strip_tags(api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40));
if (api_strlen(strip_tags($survey_data['title'])) > 40) {
    $urlname .= '...';
}

// 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);
Пример #19
0
		$form_content['answers'][0] = 1;
		$form_content['answers'][1] = 2;
		$form_content['answers'][2] = 3;
		$form_content['answers'][3] = 4;
		$form_content['answers'][4] = 5;

		$form_content['values'][0] = 0;
		$form_content['values'][1] = 0;
		$form_content['values'][2] = 1;
		$form_content['values'][3] = 2;
		$form_content['values'][4] = 3;
	}

	// We are editing a question
	if (isset($_GET['question_id']) && !empty($_GET['question_id'])) {
		$form_content = survey_manager::get_question($_GET['question_id']);
	}

	// An action has been performed (for instance adding a possible answer, moving an answer, ...)
	if ($_POST) {
		$form_content = $_POST;
		$form_content = $form->handle_action(
            $survey_data,
            $form_content
        );
	}

	if ($error_message != '') {
		$form_content['question'] = $_SESSION['temp_user_message'];
		$form_content['answers'] = $_SESSION['temp_answers'];
		$form_content['values'] = $_SESSION['temp_values'];
Пример #20
0
 /**
  * Delete a user from the platform, and all its belongings. This is a
  * very dangerous function that should only be accessible by
  * super-admins. Other roles should only be able to disable a user,
  * which removes access to the platform but doesn't delete anything.
  * @param int The ID of th user to be deleted
  * @return boolean true if user is succesfully deleted, false otherwise
  * @assert (null) === false
  * @assert ('abc') === false
  */
 public static function delete_user($user_id)
 {
     if ($user_id != strval(intval($user_id))) {
         return false;
     }
     if ($user_id === false) {
         return false;
     }
     if (!self::can_delete_user($user_id)) {
         return false;
     }
     $user_info = api_get_user_info($user_id);
     $table_user = Database::get_main_table(TABLE_MAIN_USER);
     $usergroup_rel_user = Database::get_main_table(TABLE_USERGROUP_REL_USER);
     $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
     $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
     $table_admin = Database::get_main_table(TABLE_MAIN_ADMIN);
     $table_session_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
     $table_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
     $table_group = Database::get_course_table(TABLE_GROUP_USER);
     $table_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
     // Unsubscribe the user from all groups in all his courses
     $sql = "SELECT c.id FROM {$table_course} c, {$table_course_user} cu\n                WHERE cu.user_id = '" . $user_id . "' AND relation_type<>" . COURSE_RELATION_TYPE_RRHH . " AND c.id = cu.c_id";
     $res = Database::query($sql);
     while ($course = Database::fetch_object($res)) {
         $sql = "DELETE FROM {$table_group} WHERE c_id = {$course->id} AND user_id = {$user_id}";
         Database::query($sql);
     }
     // Unsubscribe user from all classes
     //Classes are not longer supported
     /*$sql = "DELETE FROM $table_class_user WHERE user_id = '".$user_id."'";
       Database::query($sql);*/
     // Unsubscribe user from usergroup_rel_user
     $sql = "DELETE FROM {$usergroup_rel_user} WHERE user_id = '" . $user_id . "'";
     Database::query($sql);
     // Unsubscribe user from all courses
     $sql = "DELETE FROM {$table_course_user} WHERE user_id = '" . $user_id . "'";
     Database::query($sql);
     // Unsubscribe user from all courses in sessions
     $sql = "DELETE FROM {$table_session_course_user} WHERE id_user = '******'";
     Database::query($sql);
     // Unsubscribe user from all sessions
     $sql = "DELETE FROM {$table_session_user} WHERE id_user = '******'";
     Database::query($sql);
     // Delete user picture
     // TODO: Logic about api_get_setting('split_users_upload_directory') === 'true' , a user has 4 differnt sized photos to be deleted.
     if (strlen($user_info['picture_uri']) > 0) {
         $img_path = api_get_path(SYS_DATA_PATH) . 'upload/users/' . $user_id . '/' . $user_info['picture_uri'];
         if (file_exists($img_path)) {
             unlink($img_path);
         }
     }
     // Delete the personal course categories
     $course_cat_table = Database::get_main_table(TABLE_USER_COURSE_CATEGORY);
     $sql = "DELETE FROM {$course_cat_table} WHERE user_id = '" . $user_id . "'";
     Database::query($sql);
     // Delete user from database
     $sql = "DELETE FROM {$table_user} WHERE user_id = '" . $user_id . "'";
     Database::query($sql);
     // Delete user from the admin table
     $sql = "DELETE FROM {$table_admin} WHERE user_id = '" . $user_id . "'";
     Database::query($sql);
     // Delete the personal agenda-items from this user
     $agenda_table = Database::get_main_table(TABLE_PERSONAL_AGENDA);
     $sql = "DELETE FROM {$agenda_table} WHERE user = '******'";
     Database::query($sql);
     $gradebook_results_table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
     $sql = 'DELETE FROM ' . $gradebook_results_table . ' WHERE user_id = ' . $user_id;
     Database::query($sql);
     $t_ufv = Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
     $sqlv = "DELETE FROM {$t_ufv} WHERE user_id = {$user_id}";
     Database::query($sqlv);
     if (api_get_multiple_access_url()) {
         $url_id = api_get_current_access_url_id();
         UrlManager::delete_url_rel_user($user_id, $url_id);
     } else {
         //we delete the user from the url_id =1
         UrlManager::delete_url_rel_user($user_id, 1);
     }
     if (api_get_setting('allow_social_tool') == 'true') {
         $usergroup = new UserGroup();
         //Delete user from portal groups
         $group_list = $usergroup->get_groups_by_user($user_id);
         if (!empty($group_list)) {
             foreach ($group_list as $group_id => $data) {
                 $usergroup->delete_user_rel_group($user_id, $group_id);
             }
         }
         // Delete user from friend lists
         SocialManager::remove_user_rel_user($user_id, true);
     }
     survey_manager::delete_all_survey_invitations_by_user($user_id);
     // Delete students works
     $sqlw = "DELETE FROM {$table_work} WHERE user_id = {$user_id} AND c_id <> 0";
     Database::query($sqlw);
     unset($sqlw);
     // Add event to system log
     $user_id_manager = api_get_user_id();
     event_system(LOG_USER_DELETE, LOG_USER_ID, $user_id, api_get_utc_datetime(), $user_id_manager, null, $user_info);
     event_system(LOG_USER_DELETE, LOG_USER_OBJECT, implode(';', $user_info), api_get_utc_datetime(), $user_id_manager, null, $user_info);
     return true;
 }