public function testSurveyName() { $survey = new Survey(); $survey->setSurveyName("yesno"); $survey->setDescription('stuff'); $q = new SurveyQuestion(); $q->setType(QuestionType::YesNo()); $q->setQuestion("A question"); $survey->addQuestion($q); //add another question $q2 = new SurveyQuestion(); $q2->setType(QuestionType::StarRating()); $secondQuestion = "Second question"; $q2->setQuestion($secondQuestion); $survey->addQuestion($q2); $this->surveyManager->createSurvey($survey); SurveyEntityManager::testClear(); $service = $this->newSurveyService(); $this->request['Body'] = "yesno"; $this->request['From'] = "1234"; $serviced = $service->service(); $this->assertTrue($serviced); $this->request['Body'] = "no"; $this->request['From'] = "1234"; $serviced = $service->service(); $this->assertTrue($serviced); $this->assertContains($secondQuestion, $service->getResponse()->getContent()); }
/** * @param string $from * @param SurveyQuestion $question * @param string $answerString */ private function persistAnswer($from, SurveyQuestion $question, $answerString) { $answer = new SurveyAnswer(); $answer->setAnswer($answerString); $answer->setAnsweredBy($from); //Persist the answer $this->surveyManager->addAnswer($question->getId(), $answer); }
/** * Load your component. * * @param \Cx\Core\ContentManager\Model\Entity\Page $page The resolved page */ public function load(\Cx\Core\ContentManager\Model\Entity\Page $page) { global $_CORELANG, $subMenuTitle, $objTemplate; switch ($this->cx->getMode()) { case \Cx\Core\Core\Controller\Cx::MODE_FRONTEND: $objSurvey = new Survey(\Env::get('cx')->getPage()->getContent()); \Env::get('cx')->getPage()->setContent($objSurvey->getPage()); break; case \Cx\Core\Core\Controller\Cx::MODE_BACKEND: $this->cx->getTemplate()->addBlockfile('CONTENT_OUTPUT', 'content_master', 'LegacyContentMaster.html'); $objTemplate = $this->cx->getTemplate(); \Permission::checkAccess(111, 'static'); $subMenuTitle = $_CORELANG['TXT_SURVEY']; $objSurvey = new SurveyManager(); $objSurvey->getPage(); break; default: break; } }
public function testDeleteQuestionFromSurvey() { $survey = new Survey(); $survey->setSurveyName("hi"); $survey->setDescription('stuff'); $qtypes = QuestionType::toArray(); $max = rand(4, 5); for ($i = 0; $i < $max; ++$i) { $q = new SurveyQuestion(); $q->setType(new QuestionType(rand(1, count($qtypes)))); $q->setQuestion("q" . $i); $survey->addQuestion($q); } $this->manager->createSurvey($survey); $toDelete = $survey->getQuestions()[rand(0, $max - 1)]; $idToDelete = $toDelete->getId(); $survey->deleteQuestion($idToDelete); $this->manager->updateSurvey($survey); $this->assertEquals($max - 1, count($survey->getQuestions())); }
public function testTagCloud() { $survey = new Survey(); $survey->setSurveyName("hi"); $survey->setDescription('stuff'); $q = new SurveyQuestion(); $q->setType(QuestionType::Text()); $q->setQuestion("Your Suggestions"); $survey->addQuestion($q); $this->manager->createSurvey($survey); $max = rand(1, 20); for ($i = 0; $i < $max; ++$i) { $val = $this->getRandomString(); $ans = new SurveyAnswer(); $ans->setAnswer($val); $ans->setAnsweredBy("+12064122496"); $this->manager->addAnswer($q->getId(), $ans); } $answers = $this->manager->getAnswers($survey->getId()); $strArr = ReportChartFormatter::getChartData($answers->getAnswers($q->getId()), ChartFormats::TagCloud()); $this->assertNotNull($strArr); //TODO: how the heck do i test this? I guess that it just works? }
/** * @param array $surveyData * @param array $formData * * @return mixed */ public function save($surveyData, $formData) { // Saving a question if (isset($_POST['buttons']) && isset($_POST['buttons']['save'])) { Session::erase('answer_count'); Session::erase('answer_list'); $message = SurveyManager::save_question($surveyData, $formData); if ($message == 'QuestionAdded' || $message == 'QuestionUpdated') { header('Location: ' . api_get_path(WEB_CODE_PATH) . 'survey/survey.php?survey_id=' . intval($_GET['survey_id']) . '&message=' . $message . '&' . api_get_cidreq()); exit; } } return $formData; }
/** * Restore surveys * @param int $sessionId Optional. The session id */ public function restore_surveys($sessionId = 0) { $sessionId = intval($sessionId); 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 = '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 resources inside html from ckeditor 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']); $params = ['c_id' => $this->destination_course_id, 'code' => self::DBUTF8($survey->code), 'title' => self::DBUTF8($survey->title), 'subtitle' => self::DBUTF8($survey->subtitle), 'author' => self::DBUTF8($survey->author), 'lang' => self::DBUTF8($survey->lang), 'avail_from' => self::DBUTF8($survey->avail_from), 'avail_till' => self::DBUTF8($survey->avail_till), 'is_shared' => self::DBUTF8($survey->is_shared), 'template' => self::DBUTF8($survey->template), 'intro' => self::DBUTF8($survey->intro), 'surveythanks' => self::DBUTF8($survey->surveythanks), 'creation_date' => self::DBUTF8($survey->creation_date), 'invited' => '0', 'answered' => '0', 'invite_mail' => self::DBUTF8($survey->invite_mail), 'reminder_mail' => self::DBUTF8($survey->reminder_mail), 'session_id' => $sessionId]; //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; $params['code'] = $survey_code; $new_id = Database::insert($table_sur, $params); if ($new_id) { $sql = "UPDATE {$table_sur} SET survey_id = iid WHERE iid = {$new_id}"; Database::query($sql); $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 . "\n\t\t\t\t\t\t\t\t WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}"; Database::query($sql); $sql = "UPDATE " . $table_ans . " SET survey_id = " . $new_id . "\n\t\t\t\t\t\t\t\t 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) $sql = "SELECT * FROM {$table_sur}\n\t\t\t\t\t\t\t WHERE\n\t\t\t\t\t\t\t c_id = " . $this->destination_course_id . " AND\n\t\t\t\t\t\t\t survey_id='" . self::DBUTF8escapestring(Database::result($result_check, 0, 0)) . "'"; $result = Database::query($sql); $survey_data = Database::fetch_array($result, 'ASSOC'); // if the survey is shared => also delete the shared content if (isset($survey_data['survey_share']) && is_numeric($survey_data['survey_share'])) { SurveyManager::delete_survey($survey_data['survey_share'], true, $this->destination_course_id); } SurveyManager::delete_survey($survey_data['survey_id'], false, $this->destination_course_id); // Insert the new source survey $new_id = Database::insert($table_sur, $params); if ($new_id) { $sql = "UPDATE {$table_sur} SET survey_id = iid WHERE iid = {$new_id}"; Database::query($sql); $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}\n WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}"; Database::query($sql); $sql = "UPDATE {$table_ans} SET survey_id = {$new_id}\n WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}"; Database::query($sql); } } break; default: break; } } else { // No existing survey with the same language and the same code, we just copy the survey $new_id = Database::insert($table_sur, $params); if ($new_id) { $sql = "UPDATE {$table_sur} SET survey_id = iid WHERE iid = {$new_id}"; Database::query($sql); $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}\n WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}"; Database::query($sql); $sql = "UPDATE {$table_ans} SET survey_id = {$new_id}\n WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}"; Database::query($sql); } } } } } }
$surveyId = $_REQUEST["surveyid"]; $action = array_key_exists("action", $_REQUEST) ? $_REQUEST["action"] : ""; $pageNumber = array_key_exists("pagenumber", $_REQUEST) ? $_REQUEST["pagenumber"] : 0; $proj = array_key_exists("proj", $_REQUEST) ? $_REQUEST["proj"] : ""; //Display option $showAuthors = array_key_exists("showauthors", $_REQUEST) ? $_REQUEST["showauthors"] : 0; $showCommon = array_key_exists("showcommon", $_REQUEST) ? $_REQUEST["showcommon"] : 0; $showImages = array_key_exists("showimages", $_REQUEST) ? $_REQUEST["showimages"] : 0; $showVouchers = array_key_exists("showvouchers", $_REQUEST) ? $_REQUEST["showvouchers"] : 0; $thesFilter = array_key_exists("thesfilter", $_REQUEST) ? $_REQUEST["thesfilter"] : 0; //Search options $taxonFilter = array_key_exists("taxonfilter", $_REQUEST) ? $_REQUEST["taxonfilter"] : ""; $searchCommon = array_key_exists("searchcommon", $_REQUEST) ? $_REQUEST["searchcommon"] : 0; $searchSynonyms = array_key_exists("searchsynonyms", $_REQUEST) ? $_REQUEST["searchsynonyms"] : 0; $editMode = array_key_exists("emode", $_REQUEST) ? $_REQUEST["emode"] : ""; $clManager = new SurveyManager($surveyId); if ($proj) { $clManager->setProj($proj); } if ($thesFilter) { $clManager->setThesFilter($thesFilter); } if ($taxonFilter) { $clManager->setTaxonFilter($taxonFilter); } if ($searchCommon) { $clManager->setSearchCommon(); } if ($searchSynonyms) { $clManager->setSearchSynonyms(); }
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 = SurveyManager::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, null, null, array('where' => $whereCondition, 'order' => "{$sidx} {$sord}", 'limit' => "{$start} , {$limit}")); break; case 'get_session_access_overview':
/** * 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 = SurveyManager::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; }
$data_exercices[$i][] = $score_percentage . '%'; $data_exercices[$i][] = $count_attempts; $csv_content[] = array($exercices['title'], $lp_name, $score_percentage, $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($sessionId)) { $survey_list = SurveyManager::get_surveys($course_code, $sessionId); $survey_data = array(); foreach ($survey_list as $survey) { $user_list = SurveyManager::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); $column++;
<?php /* For licensing terms, see /license.txt */ 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 = SurveyManager::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 (!SurveyManager::survey_generation_hash_available()) { api_not_allowed(true); } $link = SurveyManager::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>';
<?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 (!SurveyManager::survey_generation_hash_available()) { api_not_allowed(true); } $course_info = api_get_course_info_by_id($_REQUEST['c']); $hash_is_valid = SurveyManager::validate_survey_hash($survey_id, $_REQUEST['c'], $_REQUEST['s'], $_REQUEST['g'], $_REQUEST['h']); if ($hash_is_valid && $course_info) { $survey_data = SurveyManager::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'] . 'cidReq=' . $course_info['code']; header('Location: ' . $link); exit; } } else { api_not_allowed(true); }
unset($_SESSION['page_questions_sec']); $paged_questions_sec = array(); } else { echo '<div id="survey_content" class="survey_content">' . get_lang('UpdateInformation') . '</div>'; // 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']; SurveyManager::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'])) { // Getting all the questions for this page and add them to a // multidimensional array where the first index is the page. // As long as there is no pagebreak fount we keep adding questions to the page $questions_displayed = array();
public function call() { try { $pw = $this->getArgument('pw'); if (!$pw || $pw != 'thedoor') { return new Answer('error', "Access denied"); } $survey_code = $this->getArgument('survey'); $survey_manager = new SurveyManager(); if (!$survey_manager->isSurvey($survey_code)) { return new Answer('error', "Survey not found"); } $survey_result_mng = new SurveyResultManager(); $a_result = $survey_result_mng->getReport($survey_code); $answer = new Answer('ok', $a_result, 'csv', 'results_' . $survey_code . '.csv'); return $answer; } catch (Exception $e) { return new Answer('error', $e->getMessage()); } }
Display::display_header(get_lang('CopySurvey')); echo Display::page_header(get_lang('CopySurvey')); /* MAIN CODE */ // If a CourseSelectForm is posted or we should copy all resources, then copy them if (Security::check_token('post')) { // Clear token Security::clear_token(); $surveyId = intval($_POST['surveys']); $courseId = Security::remove_XSS($_POST['destination_course']); $surveyCopyId = SurveyManager::copy_survey($surveyId, null, $courseId); // Copy the survey to the target course SurveyManager::empty_survey($surveyCopyId, $courseId); // Empty the copied survey Display::display_confirmation_message(get_lang('SurveyCopied')); } $surveys = SurveyManager::get_surveys(api_get_course_id(), api_get_session_id()); $courses = CourseManager::get_courses_list(); $form = new FormValidator('copy_survey', 'post', 'copy_survey.php?' . api_get_cidreq()); if (!$surveys) { Display::display_error_message(get_lang('NoSurveyAvailable')); } if (count($courses) <= 1) { Display::display_error_message(get_lang('CourseListNotAvailable')); } if ($surveys && count($courses) > 1) { // Surveys select $options = array(); foreach ($surveys as $survey) { $options[$survey['survey_id']] = $survey['title']; } $form->addElement('select', 'surveys', get_lang('SelectSurvey'), $options);
public function call() { try { $survey_code = strtoupper($this->getArgument('survey')); $survey_manager = new SurveyManager(); if (!session_id()) { session_start(); } $hex_data = $this->getArgument('h'); if ($hex_data) { $_SESSION['h'] = $hex_data; } if ($survey_manager->isSurvey($survey_code, true)) { $survey = $survey_manager->getSurvey($survey_code); $_SESSION['survey_code'] = strtolower($survey_code); $_SESSION['start_time'] = time(); unset($_SESSION['result_id']); unset($_SESSION['user_data_id']); $survey_tpl = new Template('widget/survey_body.php'); return new Answer('ok', $survey_tpl->process(array('survey' => $survey, 'not_welcome' => true)), 'html'); } else { $survey_tpl = new Template('widget/not_found.php'); return new Answer('ok', $survey_tpl->process(array()), 'html'); } } catch (Exception $e) { return new Answer('error', $e->getMessage(), 'html'); } }
public function getReport($survey_code) { $survey_manager = new SurveyManager(); $survey_obj = $survey_manager->getSurvey($_REQUEST['survey']); $sql = "SELECT *,CONVERT_TZ(start_time,'+00:00','-7:00') AS start_time_mst,CONVERT_TZ(end_time,'+00:00','-7:00') AS end_time_mst " . " FROM survey_result LEFT JOIN survey_user_data USING(survey_result_id) where is_removed=0 AND code = '" . mysql_real_escape_string($survey_code) . "'"; $db = new DB(); $rows = $db->runQuery($sql); $db = new DB(); $a_question_id = $survey_obj->listQuestionsId(); $a_header = array('Start', 'End', 'IP', 'Emotion', 'Intensity', 'Verbatim', 'Name', 'Email', 'Phone'); $a_header = array_merge($a_header, $a_question_id); $a_result = array(); foreach ($rows as $row) { $verbatim = $row['verbatim']; $a_verbatim = preg_split('/[\\n\\r\\s]+/', $verbatim); $verbatim = implode(" ", $a_verbatim); $result = array($row['start_time_mst'], $row['end_time_mst'], $row['ip'], $row['emote'], $row['intensity_level'], $verbatim, $row['name'], $row['email'], $row['phone']); foreach ($a_question_id as $question_id) { $select_question = "SELECT * FROM survey_demo_result where survey_result_id='" . mysql_real_escape_string($row['survey_result_id']) . "' " . " AND question_field = '" . mysql_real_escape_string($question_id) . "' LIMIT 1"; $q_rows = $db->runQuery($select_question); if ($q_rows) { $q_row = $q_rows[0]; $val = array_key_exists('answer', $q_row) ? $q_row['answer'] : ''; array_push($result, $val); } else { array_push($result, ''); } } array_push($a_result, $result); } array_unshift($a_result, $a_header); return $a_result; }
$survey_id = intval($_GET['survey_id']); $survey_data = SurveyManager::get_survey($survey_id); 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 = SurveyManager::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 /* if (!api_is_allowed_to_edit(false, true)) {
} 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 = SurveyManager::get_survey($value); // if the survey is shared => also delete the shared content if (is_numeric($survey_data['survey_share'])) { SurveyManager::delete_survey($survey_data['survey_share'], true); } // delete the actual survey SurveyManager::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() . '&action=add">' . Display::return_icon('new_survey.png', get_lang('CreateNewSurvey'), '', ICON_SIZE_MEDIUM) . '</a> '; } echo '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&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') {
$class = 'add'; $text = get_lang('CreateSurvey'); $form->addButtonCreate(get_lang('CreateSurvey'), 'submit_survey'); } // Setting the rules if ($_GET['action'] == 'add') { $form->addRule('survey_code', get_lang('ThisFieldIsRequired'), 'required'); $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->getSubmitValues(); // Storing the survey $return = SurveyManager::store_survey($values); // Redirecting to the survey page (whilst showing the return message) header('location: ' . api_get_path(WEB_CODE_PATH) . 'survey/survey.php?survey_id=' . $return['id'] . '&' . api_get_cidreq()); exit; } else { // Displaying the header Display::display_header($tool_name); $form->display(); } // Footer Display::display_footer();
if ($_GET['type'] == 'yesno') { $formData['answers'][0] = get_lang('Yes'); $formData['answers'][1] = get_lang('No'); } if ($_GET['type'] == 'personality') { $formData['answers'][0] = 1; $formData['answers'][1] = 2; $formData['answers'][2] = 3; $formData['answers'][3] = 4; $formData['answers'][4] = 5; $formData['values'][0] = 0; $formData['values'][1] = 0; $formData['values'][2] = 1; $formData['values'][3] = 2; $formData['values'][4] = 3; } // We are editing a question if (isset($_GET['question_id']) && !empty($_GET['question_id'])) { $formData = SurveyManager::get_question($_GET['question_id']); } $formData = $surveyQuestion->preSave($formData); $surveyQuestion->createForm($surveyData, $formData); $surveyQuestion->getForm()->setDefaults($formData); $surveyQuestion->renderForm(); if ($surveyQuestion->getForm()->validate()) { $values = $surveyQuestion->getForm()->getSubmitValues(); $surveyQuestion->save($surveyData, $values); } Display::display_header($tool_name, 'Survey'); echo $surveyQuestion->getForm()->returnForm(); Display::display_footer();
/** * 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); $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_main_table(TABLE_STATISTIC_TRACK_E_DEFAULT); $table_stats_access = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS); $course = api_get_course_info_by_id($courseId); $where = " WHERE c_id = '%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['real_id']); if (!empty($sessionId)) { $where .= ' AND session_id = %s'; $queryVariables[] = $sessionId; $sql = "SELECT\n u.user_id, u.lastname, u.firstname, u.username,\n u.email, s.c_id, s.session_id\n FROM {$session_course_user} s\n INNER JOIN {$user} u\n ON u.user_id = s.user_id\n {$where} {$order} {$limit}"; } else { $sql = "SELECT\n u.user_id, u.lastname, u.firstname, u.username,\n u.email, s.c_id, s.session_id\n FROM {$session_course_user} s\n INNER JOIN {$user} u ON u.user_id = s.user_id\n {$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 (empty($arrLesson[$row['session_id']]['lessons_total'])) { $arrLesson[$row['session_id']]['lessons_total'] = 1; } else { $arrLesson[$row['session_id']]['lessons_total']++; } } /** * Exercises */ $exercises = ExerciseLib::get_all_exercises($course, $sessionId, false, '', $getAllSessions); $exercises_total = count($exercises); /** * Assignments */ //total if ($getAllSessions) { $sql = "SELECT count(w.id) as count\n FROM {$workTable} w\n LEFT JOIN {$workTableAssignment} a\n ON (a.publication_id = w.id AND a.c_id = w.c_id)\n WHERE w.c_id = %s\n AND parent_id = 0\n AND active IN (1, 0)"; } else { $sql = "SELECT count(w.id) as count\n FROM {$workTable} w\n LEFT JOIN {$workTableAssignment} a\n ON (a.publication_id = w.id AND a.c_id = w.c_id)\n WHERE w.c_id = %s\n AND parent_id = 0\n AND active IN (1, 0)\n 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}\n WHERE c_id = %s"; } else { $sql = "SELECT count(distinct page_id) as count FROM {$wiki}\n 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 = SurveyManager::get_surveys($course['code'], $sessionId); $surveys_total = count($survey_list); foreach ($survey_list as $survey) { $user_list = SurveyManager::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\n FROM {$table_stats_access}\n WHERE access_tool = 'course_description'\n AND c_id = '%s'\n AND access_session_id = %s\n AND access_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); $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['real_id'], $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\n FROM {$wiki}\n 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\n FROM {$table_stats_default}\n WHERE\n default_user_id = %s AND\n default_event_type = 'wiki_page_view' AND\n default_value_type = 'wiki_page_id' AND\n c_id = %s\n "; $sql_query = sprintf($sql, $user['user_id'], $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], '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_progress' => $course_description_progress . '%', '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_total' => sprintf($link, $exercises_total), 'exercises_done' => sprintf($link, $exercises_done), 'exercises_left' => sprintf($link, $exercises_left), 'exercises_progress' => sprintf($link, $exercises_progress . '%'), '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_total' => sprintf($linkWork, $assignments_total), 'assignments_done' => sprintf($linkWork, $assignments_done), 'assignments_left' => sprintf($linkWork, $assignments_left), 'assignments_progress' => sprintf($linkWork, $assignments_progress . '%'), '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 . '%'), '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; }
/** * 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 successfully 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; } $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_session = Database::get_main_table(TABLE_MAIN_SESSION); $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\n cu.user_id = '" . $user_id . "' AND\n relation_type<>" . COURSE_RELATION_TYPE_RRHH . " AND\n c.id = cu.c_id"; $res = Database::query($sql); while ($course = Database::fetch_object($res)) { $sql = "DELETE FROM {$table_group}\n 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 user_id = '" . $user_id . "'"; Database::query($sql); // If the user was added as a id_coach then set the current admin as coach see BT# $currentUserId = api_get_user_id(); $sql = "UPDATE {$table_session} SET id_coach = {$currentUserId} WHERE id_coach = '" . $user_id . "'"; Database::query($sql); $sql = "UPDATE {$table_session} SET id_coach = {$currentUserId} WHERE session_admin_id = '" . $user_id . "'"; Database::query($sql); // Unsubscribe user from all sessions $sql = "DELETE FROM {$table_session_user} WHERE user_id = '" . $user_id . "'"; Database::query($sql); // Delete user picture /* TODO: Logic about api_get_setting('split_users_upload_directory') == 'true' a user has 4 different sized photos to be deleted. */ $user_info = api_get_user_info($user_id); if (strlen($user_info['picture_uri']) > 0) { $path = self::getUserPathById($user_id, 'system'); $img_path = $path . $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 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); $extraFieldValue = new ExtraFieldValue('user'); $extraFieldValue->deleteValuesByItem($user_id); 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); } // Removing survey invitation SurveyManager::delete_all_survey_invitations_by_user($user_id); // Delete students works $sql = "DELETE FROM {$table_work} WHERE user_id = {$user_id} AND c_id <> 0"; Database::query($sql); // Add event to system log $user_id_manager = api_get_user_id(); Event::addEvent(LOG_USER_DELETE, LOG_USER_ID, $user_id, api_get_utc_datetime(), $user_id_manager); Event::addEvent(LOG_USER_DELETE, LOG_USER_OBJECT, $user_info, api_get_utc_datetime(), $user_id_manager); return true; }
/** * This function changes the modify column of the sortable table * * @param integer $survey_id the id of the survey * @param bool $drh * @return string 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, $drh = false) { $survey_id = Security::remove_XSS($survey_id); $return = ''; if ($drh) { return '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/reporting.php?' . api_get_cidreq() . '&survey_id=' . $survey_id . '">' . Display::return_icon('stats.png', get_lang('Reporting'), '', ICON_SIZE_SMALL) . '</a>'; } // 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="' . api_get_path(WEB_CODE_PATH) . 'survey/create_new_survey.php?' . api_get_cidreq() . '&action=edit&survey_id=' . $survey_id . '">' . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . '</a>'; if (SurveyManager::survey_generation_hash_available()) { $return .= Display::url(Display::return_icon('new_link.png', get_lang('GenerateSurveyAccessLink'), '', ICON_SIZE_SMALL), api_get_path(WEB_CODE_PATH) . 'survey/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="' . api_get_path(WEB_CODE_PATH) . 'survey/survey_list.php?' . api_get_cidreq() . '&action=empty&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> '; } $return .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/preview.php?' . api_get_cidreq() . '&survey_id=' . $survey_id . '">' . Display::return_icon('preview_view.png', get_lang('Preview'), '', ICON_SIZE_SMALL) . '</a> '; $return .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/survey_invite.php?' . api_get_cidreq() . '&survey_id=' . $survey_id . '">' . Display::return_icon('mail_send.png', get_lang('Publish'), '', ICON_SIZE_SMALL) . '</a> '; $return .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/reporting.php?' . api_get_cidreq() . '&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="' . api_get_path(WEB_CODE_PATH) . 'survey/survey_list.php?' . api_get_cidreq() . '&action=delete&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> '; } return $return; }
*/ //require_once '../inc/global.inc.php'; $this_section = SECTION_COURSES; if (!api_is_allowed_to_edit(false, true)) { api_not_allowed(true); } // 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_id = Security::remove_XSS($_GET['survey_id']); $survey_data = SurveyManager::get_survey($survey_id); if (empty($survey_data)) { api_not_allowed(true, get_lang('InvallidSurvey')); } $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?' . api_get_cidreq(), 'name' => get_lang('SurveyList')); if (api_is_course_admin()) { $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH) . 'survey/survey.php?survey_id=' . $survey_id . '&' . api_get_cidreq(), 'name' => $urlname); } else { $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH) . 'survey/survey_invite.php?survey_id=' . $survey_id . '&' . api_get_cidreq(), 'name' => $urlname); } $tool_name = get_lang('SurveyPublication');
/** * Get data for users list in sortable with pagination * @param $from * @param $number_of_items * @param $column * @param $direction * @param $includeInvitedUsers boolean Whether include the invited users * @return array */ public static function get_user_data($from, $number_of_items, $column, $direction, $includeInvitedUsers = false) { 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 (\n user.firstname LIKE '%" . $keyword . "%' OR\n user.lastname LIKE '%" . $keyword . "%' OR\n user.username LIKE '%" . $keyword . "%' OR\n user.email LIKE '%" . $keyword . "%'\n ) "; } $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}'"; } $invitedUsersCondition = ''; if (!$includeInvitedUsers) { $invitedUsersCondition = " AND user.status != " . INVITEE; } $sql = "SELECT user.user_id as user_id,\n user.official_code as col0,\n user.lastname as col1,\n user.firstname as col2,\n user.username as col3\n FROM {$tbl_user} as user {$url_table}\n \t {$condition_user} {$url_condition} {$invitedUsersCondition}"; 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 = ExerciseLib::get_all_exercises($course_info, $session_id, false, null, false, 3); if (empty($session_id)) { $survey_user_list = array(); $survey_list = SurveyManager::get_surveys($course_code, $session_id); $total_surveys = count($survey_list); if (!empty($survey_list)) { foreach ($survey_list as $survey) { $user_list = SurveyManager::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')) { $courseInfo = api_get_course_info($course_code); $courseId = $courseInfo['real_id']; $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'], $courseId, $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'], $courseId, $session_id); $user['exercise_progress'] = $total_user_exercise; $total_user_exercise = Tracking::get_exercise_student_average_best_attempt($total_exercises, $user['user_id'], $courseId, $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'], $courseId, $session_id); $user['last_connection'] = Tracking::get_last_connection_date_on_the_course($user['user_id'], $courseInfo, $session_id); // we need to display an additional profile field $user['additional'] = ''; if (isset($_GET['additional_profile_field']) && 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) . 'icons/22/2rightarrow.png" 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']) && 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; }
/** * 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 = ' '; 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'] . '¬ification=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) . ' '; } return $return; }
exit; } // Displaying the header Display::display_header($tool_name, 'Survey'); // Action handling $my_action_survey = Security::remove_XSS($action); $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($action)) { if (($action == 'moveup' || $action == 'movedown') && isset($_GET['question_id'])) { SurveyManager::move_survey_question($my_action_survey, $my_question_id_survey, $my_survey_id_survey); Display::display_confirmation_message(get_lang('SurveyQuestionMoved')); } if ($action == 'delete' and is_numeric($_GET['question_id'])) { SurveyManager::delete_survey_question($my_survey_id_survey, $my_question_id_survey, $survey_data['is_shared']); } } if (!empty($survey_data['survey_version'])) { echo '<b>' . get_lang('Version') . ': ' . $survey_data['survey_version'] . '</b>'; } // We exit here is the first or last question is a pagebreak (which causes errors) SurveyUtil::check_first_last_question($_GET['survey_id']); // Action links $survey_actions = '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/create_new_survey.php?' . api_get_cidreq() . '&action=edit&survey_id=' . $survey_id . '">' . Display::return_icon('edit.png', get_lang('EditSurvey'), '', ICON_SIZE_MEDIUM) . '</a>'; $survey_actions .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/survey_list.php?' . api_get_cidreq() . '&action=delete&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('DeleteSurvey'), '', ICON_SIZE_MEDIUM) . '</a>'; //$survey_actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/create_survey_in_another_language.php?id_survey='.$survey_id.'">'.Display::return_icon('copy.gif', get_lang('Copy')).'</a>'; $survey_actions .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/preview.php?' . api_get_cidreq() . '&survey_id=' . $survey_id . '">' . Display::return_icon('preview_view.png', get_lang('Preview'), '', ICON_SIZE_MEDIUM) . '</a>'; $survey_actions .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/survey_invite.php?' . api_get_cidreq() . '&survey_id=' . $survey_id . '">' . Display::return_icon('mail_send.png', get_lang('Publish'), '', ICON_SIZE_MEDIUM) . '</a>'; $survey_actions .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/reporting.php?' . api_get_cidreq() . '&survey_id=' . $survey_id . '">' . Display::return_icon('stats.png', get_lang('Reporting'), '', ICON_SIZE_MEDIUM) . '</a>'; echo '<div class="actions">' . $survey_actions . '</div>';
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); // 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 = SurveyManager::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 . '&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 . '&view=answered">' . get_lang('ViewAnswered') . '</a> |'; } if ($_GET['view'] == 'unanswered') {