Refactor survey code, using entities, update from 1.11.x

- Remove php_excel code use export.lib.php instead
pull/2744/head
Julio Montoya 7 years ago
parent 5411926e80
commit cd308f01c8
  1. 127
      main/inc/lib/SurveyTree .php
  2. 126
      main/inc/lib/surveymanager.lib.php
  3. 336
      main/survey/survey.lib.php
  4. 108
      main/survey/survey.php
  5. 323
      main/survey/surveyUtil.class.php
  6. 14
      main/survey/survey_invitation.php
  7. 6
      main/survey/survey_invite.php
  8. 139
      main/survey/survey_list.php
  9. 1
      src/CoreBundle/Composer/ScriptHandler.php

@ -0,0 +1,127 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Manage the "versioning" of a conditional survey.
*
* @package chamilo.survey
*/
class SurveyTree
{
public $surveylist;
public $plainsurveylist;
public $numbersurveys;
/**
* Sets the surveylist and the plainsurveylist.
*/
public function __construct()
{
// Database table definitions
$table_survey = Database::get_course_table(TABLE_SURVEY);
$table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
$table_user = Database::get_main_table(TABLE_MAIN_USER);
// searching
$search_restriction = SurveyUtil::survey_search_restriction();
if ($search_restriction) {
$search_restriction = ' AND '.$search_restriction;
}
$course_id = api_get_course_int_id();
$sql = "SELECT
survey.survey_id,
survey.parent_id,
survey_version,
survey.code as name
FROM $table_survey survey
LEFT JOIN $table_survey_question survey_question
ON survey.survey_id = survey_question.survey_id , $table_user user
WHERE
survey.c_id = $course_id AND
survey_question.c_id = $course_id AND
survey.author = user.user_id
GROUP BY survey.survey_id";
$res = Database::query($sql);
$refs = [];
$list = [];
$plain_array = [];
while ($survey = Database::fetch_array($res, 'ASSOC')) {
$plain_array[$survey['survey_id']] = $survey;
$surveys_parents[] = $survey['survey_version'];
$thisref = &$refs[$survey['survey_id']];
$thisref['parent_id'] = $survey['parent_id'];
$thisref['name'] = $survey['name'];
$thisref['id'] = $survey['survey_id'];
$thisref['survey_version'] = $survey['survey_version'];
if ($survey['parent_id'] == 0) {
$list[$survey['survey_id']] = &$thisref;
} else {
$refs[$survey['parent_id']]['children'][$survey['survey_id']] = &$thisref;
}
}
$this->surveylist = $list;
$this->plainsurveylist = $plain_array;
}
/**
* This function gets the parent id of a survey.
*
* @param int $id survey id
*
* @return int survey parent id
*
* @author Julio Montoya <gugli100@gmail.com>, Dokeos
*
* @version September 2008
*/
public function getParentId($id)
{
$node = $this->plainsurveylist[$id];
if (is_array($node) && !empty($node['parent_id'])) {
return $node['parent_id'];
} else {
return -1;
}
}
/**
* This function creates a list of all surveys id.
*
* @param array $list of nodes
*
* @return array with the structure survey_id => survey_name
*
* @author Julio Montoya <gugli100@gmail.com>
*
* @version September 2008
*/
public function createList($list)
{
$result = [];
if (is_array($list)) {
foreach ($list as $key => $node) {
if (isset($node['children']) && is_array($node['children'])) {
$result[$key] = $node['name'];
$re = self::createList($node['children']);
if (!empty($re)) {
if (is_array($re)) {
foreach ($re as $key => $r) {
$result[$key] = ''.$r;
}
} else {
$result[] = $re;
}
}
} else {
$result[$key] = $node['name'];
}
}
}
return $result;
}
}

@ -1,127 +1 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Manage the "versioning" of a conditional survey.
*
* @package chamilo.survey
*/
class SurveyTree
{
public $surveylist;
public $plainsurveylist;
public $numbersurveys;
/**
* Sets the surveylist and the plainsurveylist.
*/
public function __construct()
{
// Database table definitions
$table_survey = Database::get_course_table(TABLE_SURVEY);
$table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
$table_user = Database::get_main_table(TABLE_MAIN_USER);
// searching
$search_restriction = SurveyUtil::survey_search_restriction();
if ($search_restriction) {
$search_restriction = ' AND '.$search_restriction;
}
$course_id = api_get_course_int_id();
$sql = "SELECT
survey.survey_id,
survey.parent_id,
survey_version,
survey.code as name
FROM $table_survey survey
LEFT JOIN $table_survey_question survey_question
ON survey.survey_id = survey_question.survey_id , $table_user user
WHERE
survey.c_id = $course_id AND
survey_question.c_id = $course_id AND
survey.author = user.user_id
GROUP BY survey.survey_id";
$res = Database::query($sql);
$refs = [];
$list = [];
$plain_array = [];
while ($survey = Database::fetch_array($res, 'ASSOC')) {
$plain_array[$survey['survey_id']] = $survey;
$surveys_parents[] = $survey['survey_version'];
$thisref = &$refs[$survey['survey_id']];
$thisref['parent_id'] = $survey['parent_id'];
$thisref['name'] = $survey['name'];
$thisref['id'] = $survey['survey_id'];
$thisref['survey_version'] = $survey['survey_version'];
if ($survey['parent_id'] == 0) {
$list[$survey['survey_id']] = &$thisref;
} else {
$refs[$survey['parent_id']]['children'][$survey['survey_id']] = &$thisref;
}
}
$this->surveylist = $list;
$this->plainsurveylist = $plain_array;
}
/**
* This function gets the parent id of a survey.
*
* @param int $id survey id
*
* @return int survey parent id
*
* @author Julio Montoya <gugli100@gmail.com>, Dokeos
*
* @version September 2008
*/
public function getParentId($id)
{
$node = $this->plainsurveylist[$id];
if (is_array($node) && !empty($node['parent_id'])) {
return $node['parent_id'];
} else {
return -1;
}
}
/**
* This function creates a list of all surveys id.
*
* @param array $list of nodes
*
* @return array with the structure survey_id => survey_name
*
* @author Julio Montoya <gugli100@gmail.com>
*
* @version September 2008
*/
public function createList($list)
{
$result = [];
if (is_array($list)) {
foreach ($list as $key => $node) {
if (isset($node['children']) && is_array($node['children'])) {
$result[$key] = $node['name'];
$re = self::createList($node['children']);
if (!empty($re)) {
if (is_array($re)) {
foreach ($re as $key => $r) {
$result[$key] = ''.$r;
}
} else {
$result[] = $re;
}
}
} else {
$result[$key] = $node['name'];
}
}
}
return $result;
}
}

@ -1,7 +1,10 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Entity\CSurvey;
use Chamilo\CourseBundle\Entity\CSurveyInvitation;
use Chamilo\CourseBundle\Entity\CSurveyQuestion;
use Chamilo\CourseBundle\Entity\CSurveyQuestionOption;
/**
* Class SurveyManager.
@ -251,12 +254,15 @@ class SurveyManager
$values['anonymous'] = 0;
}
$values['anonymous'] = intval($values['anonymous']);
$values['anonymous'] = (int) $values['anonymous'];
$survey = new CSurvey();
$extraParams = [];
if ($values['anonymous'] == 0) {
// Input_name_list
$values['show_form_profile'] = isset($values['show_form_profile']) ? $values['show_form_profile'] : 0;
$extraParams['show_form_profile'] = $values['show_form_profile'];
$survey->setShowFormProfile($values['show_form_profile']);
if ($values['show_form_profile'] == 1) {
// Input_name_list
@ -274,18 +280,19 @@ class SurveyManager
} else {
$extraParams['form_fields'] = '';
}
$survey->setFormFields($extraParams['form_fields']);
} else {
// Input_name_list
$extraParams['show_form_profile'] = 0;
$extraParams['form_fields'] = '';
$survey->setShowFormProfile(0);
$survey->setFormFields(0);
}
if ($values['survey_type'] == 1) {
$extraParams['survey_type'] = 1;
$extraParams['shuffle'] = $values['shuffle'];
$extraParams['one_question_per_page'] = $values['one_question_per_page'];
$extraParams['parent_id'] = $values['parent_id'];
$survey
->setSurveyType(1)
->setShuffle($values['shuffle'])
->setOneQuestionPerPage($values['one_question_per_page'])
->setParentId($values['parent_id'])
;
// Logic for versioning surveys
if (!empty($values['parent_id'])) {
$versionValue = '';
@ -328,35 +335,41 @@ class SurveyManager
$versionValue = $insertnewversion;
}
}
$extraParams['survey_version'] = $versionValue;
$survey->setSurveyVersion($versionValue);
}
}
$params = [
'c_id' => $course_id,
'code' => self::generateSurveyCode($values['survey_code']),
'title' => $values['survey_title'],
'subtitle' => $values['survey_subtitle'],
'author' => $_user['user_id'],
'lang' => $values['survey_language'],
'avail_from' => $allowSurveyAvailabilityDatetime
? api_get_utc_datetime($values['start_date'].':00')
: $values['start_date'],
'avail_till' => $allowSurveyAvailabilityDatetime
? api_get_utc_datetime($values['end_date'].':59')
: $values['end_date'],
'is_shared' => $shared_survey_id,
'template' => 'template',
'intro' => $values['survey_introduction'],
'surveythanks' => $values['survey_thanks'],
'creation_date' => api_get_utc_datetime(),
'anonymous' => $values['anonymous'],
'session_id' => api_get_session_id(),
'visible_results' => $values['visible_results'],
];
$params = array_merge($params, $extraParams);
$survey_id = Database::insert($table_survey, $params);
$from = api_get_utc_datetime($values['start_date'].'00:00:00', true, true);
$until = api_get_utc_datetime($values['end_date'].'23:59:59', true, true);
if ($allowSurveyAvailabilityDatetime) {
$from = api_get_utc_datetime($values['start_date'].':00', true, true);
$until = api_get_utc_datetime($values['end_date'].':59', true, true);
}
$survey
->setCId($course_id)
->setCode(self::generateSurveyCode($values['survey_code']))
->setTitle($values['survey_title'])
->setSubtitle($values['survey_title'])
->setAuthor($_user['user_id'])
->setLang($values['survey_language'])
->setAvailFrom($from)
->setAvailTill($until)
->setIsShared($shared_survey_id)
->setTemplate('template')
->setIntro($values['survey_introduction'])
->setSurveyThanks($values['survey_thanks'])
->setAnonymous($values['anonymous'])
->setSessionId(api_get_session_id())
->setVisibleResults($values['visible_results'])
;
$em = Database::getManager();
$em->persist($survey);
$em->flush();
$survey_id = $survey->getIid();
if ($survey_id > 0) {
$sql = "UPDATE $table_survey SET survey_id = $survey_id
WHERE iid = $survey_id";
@ -710,8 +723,7 @@ class SurveyManager
$params['session_id'] = api_get_session_id();
$params['title'] = $params['title'].' '.get_lang('Copy');
unset($params['iid']);
Database::insert($table_survey, $params);
$new_survey_id = Database::insert_id();
$new_survey_id = Database::insert($table_survey, $params);
if ($new_survey_id) {
$sql = "UPDATE $table_survey SET survey_id = $new_survey_id
@ -772,7 +784,6 @@ class SurveyManager
$insertId = Database::insert($table_survey_question, $params);
$sql = "UPDATE $table_survey_question SET question_id = iid WHERE iid = $insertId";
Database::query($sql);
$question_id[$row['question_id']] = $insertId;
}
@ -803,7 +814,7 @@ class SurveyManager
/**
* This function duplicates a survey (and also all the question in that survey.
*
* @param int $survey_id id of the survey that has to be duplicated
* @param int $surveyId id of the survey that has to be duplicated
* @param int $courseId id of the course which survey has to be duplicated
*
* @return true
@ -812,7 +823,7 @@ class SurveyManager
*
* @version October 2007
*/
public static function empty_survey($survey_id, $courseId = 0)
public static function empty_survey($surveyId, $courseId = 0)
{
// Database table definitions
$table_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
@ -821,8 +832,9 @@ class SurveyManager
$courseId = (int) $courseId;
$courseId = empty($courseId) ? api_get_course_int_id() : $courseId;
$surveyId = (int) $surveyId;
$datas = self::get_survey($survey_id);
$datas = self::get_survey($surveyId);
$session_where = '';
if (api_get_session_id() != 0) {
$session_where = ' AND session_id = "'.api_get_session_id().'" ';
@ -835,11 +847,11 @@ class SurveyManager
Database::query($sql);
$sql = 'DELETE FROM '.$table_survey_answer.'
WHERE c_id = '.$courseId.' AND survey_id='.intval($survey_id);
WHERE c_id = '.$courseId.' AND survey_id='.$surveyId;
Database::query($sql);
$sql = 'UPDATE '.$table_survey.' SET invited=0, answered=0
WHERE c_id = '.$courseId.' AND survey_id='.intval($survey_id);
WHERE c_id = '.$courseId.' AND survey_id='.$surveyId;
Database::query($sql);
return true;
@ -1032,8 +1044,8 @@ class SurveyManager
/**
* This function gets all the question of any given survey.
*
* @param int $survey_id the id of the survey
* @param int $course_id
* @param int $surveyId the id of the survey
* @param int $courseId
*
* @return array containing all the questions of the survey
*
@ -1043,20 +1055,21 @@ class SurveyManager
*
* @todo one sql call should do the trick
*/
public static function get_questions($survey_id, $course_id = 0)
public static function get_questions($surveyId, $courseId = 0)
{
// Table definitions
$tbl_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
$table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$course_id = (int) $course_id;
if (empty($course_id)) {
$course_id = api_get_course_int_id();
$courseId = (int) $courseId;
$surveyId = (int) $surveyId;
if (empty($courseId)) {
$courseId = api_get_course_int_id();
}
// Getting the information of the question
$sql = "SELECT * FROM $tbl_survey_question
WHERE c_id = $course_id AND survey_id='".intval($survey_id)."'";
WHERE c_id = $courseId AND survey_id='".$surveyId."'";
$result = Database::query($sql);
$return = [];
while ($row = Database::fetch_array($result, 'ASSOC')) {
@ -1067,11 +1080,12 @@ class SurveyManager
$return[$row['question_id']]['horizontalvertical'] = $row['display'];
$return[$row['question_id']]['maximum_score'] = $row['max_value'];
$return[$row['question_id']]['sort'] = $row['sort'];
$return[$row['question_id']]['survey_question_comment'] = $row['survey_question_comment'];
}
// Getting the information of the question options
$sql = "SELECT * FROM $table_survey_question_option
WHERE c_id = $course_id AND survey_id='".intval($survey_id)."'";
WHERE c_id = $courseId AND survey_id='".$surveyId."'";
$result = Database::query($sql);
while ($row = Database::fetch_array($result, 'ASSOC')) {
$return[$row['question_id']]['answers'][] = $row['option_text'];
@ -1133,7 +1147,6 @@ class SurveyManager
}
}
$course_id = api_get_course_int_id();
if (!$empty_answer) {
// Table definitions
$tbl_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
@ -1157,41 +1170,40 @@ class SurveyManager
$row = Database::fetch_array($result, 'ASSOC');
$max_sort = $row['max_sort'];
$question = new CSurveyQuestion();
// Some variables defined for survey-test type
$extraParams = [];
if (isset($_POST['choose'])) {
if ($_POST['choose'] == 1) {
$extraParams['survey_group_pri'] = $_POST['assigned'];
$question->setSurveyGroupPri($_POST['assigned']);
} elseif ($_POST['choose'] == 2) {
$extraParams['survey_group_sec1'] = $_POST['assigned1'];
$extraParams['survey_group_sec2'] = $_POST['assigned2'];
$question->setSurveyGroupSec1($_POST['assigned1']);
$question->setSurveyGroupSec2($_POST['assigned2']);
}
}
$questionComment = isset($form_content['question_comment'])
? $form_content['question_comment']
: '';
$maxScore = isset($form_content['maximum_score']) ? $form_content['maximum_score'] : '';
$display = isset($form_content['horizontalvertical']) ? $form_content['horizontalvertical'] : '';
$params = [
'c_id' => $course_id,
'survey_id' => $form_content['survey_id'],
'survey_question' => $form_content['question'],
'survey_question_comment' => $questionComment,
'type' => $form_content['type'],
'display' => $display,
'sort' => $max_sort + 1,
'shared_question_id' => $form_content['shared_question_id'],
'max_value' => $maxScore,
];
$question
->setSurveyQuestionComment($form_content['question_comment'] ?? '')
->setMaxValue($form_content['maximum_score'] ?? 0)
->setDisplay($form_content['horizontalvertical'] ?? '')
->setCId($course_id)
->setSurveyId($form_content['survey_id'])
->setSurveyQuestion($form_content['question'])
->setType($form_content['type'])
->setSort($max_sort + 1)
->setSharedQuestionId($form_content['shared_question_id'])
;
if (api_get_configuration_value('allow_required_survey_questions')) {
$params['is_required'] = isset($form_content['is_required']);
$question->setIsMandatory(isset($form_content['is_required']));
}
$params = array_merge($params, $extraParams);
$question_id = Database::insert($tbl_survey_question, $params);
$em = Database::getManager();
$em->persist($question);
$em->flush();
$question_id = $question->getIid();
if ($question_id) {
$sql = "UPDATE $tbl_survey_question SET question_id = $question_id
WHERE iid = $question_id";
@ -1510,7 +1522,7 @@ class SurveyManager
{
$course_id = api_get_course_int_id();
// A percentage question type has options 1 -> 100
if ($form_content['type'] == 'percentage') {
if ($form_content['type'] === 'percentage') {
for ($i = 1; $i < 101; $i++) {
$form_content['answers'][] = $i;
}
@ -1531,19 +1543,24 @@ class SurveyManager
}
$counter = 1;
$em = Database::getManager();
if (isset($form_content['answers']) && is_array($form_content['answers'])) {
for ($i = 0; $i < count($form_content['answers']); $i++) {
$values = isset($form_content['values']) ? $form_content['values'][$i] : '';
$params = [
'c_id' => $course_id,
'question_id' => $form_content['question_id'],
'survey_id' => $form_content['survey_id'],
'option_text' => $form_content['answers'][$i],
'value' => $values,
'sort' => $counter,
];
$insertId = Database::insert($table_survey_question_option, $params);
$values = isset($form_content['values']) ? $form_content['values'][$i] : 0;
$option = new CSurveyQuestionOption();
$option
->setCId($course_id)
->setQuestionId($form_content['question_id'])
->setSurveyId($form_content['survey_id'])
->setOptionText($form_content['answers'][$i])
->setValue($values)
->setSort($counter)
;
$em->persist($option);
$em->flush();
$insertId = $option->getIid();
if ($insertId) {
$sql = "UPDATE $table_survey_question_option
SET question_option_id = $insertId
@ -1648,14 +1665,14 @@ class SurveyManager
$course_condition = " c_id = $course_id AND ";
// Table definitions
$table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$table = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
if ($shared) {
$course_condition = '';
$table_survey_question_option = Database::get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION);
$table = Database::get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION);
}
// Deleting the options of the survey questions
$sql = "DELETE from $table_survey_question_option
$sql = "DELETE FROM $table
WHERE
$course_condition survey_id='".intval($survey_id)."' AND
question_id='".intval($question_id)."'";
@ -1887,13 +1904,15 @@ class SurveyManager
WITH (s.code = i.surveyCode AND s.cId = i.cId AND s.sessionId = i.sessionId)
INNER JOIN ChamiloCoreBundle:ExtraFieldValues efv WITH efv.itemId = s.iid
INNER JOIN ChamiloCoreBundle:ExtraField ef WITH efv.field = ef.id
WHERE i.answered = 0
AND i.cId = :course
AND i.user = :user
AND i.sessionId = :session
AND :now BETWEEN s.availFrom AND s.availTill
AND ef.variable = :variable
AND efv.value = 1
WHERE
i.answered = 0 AND
i.cId = :course AND
i.user = :user AND
i.sessionId = :session AND
:now BETWEEN s.availFrom AND s.availTill AND
ef.variable = :variable AND
efv.value = 1 AND
s.surveyType != 3
ORDER BY s.availTill ASC
")
->setMaxResults(1)
@ -2084,4 +2103,125 @@ class SurveyManager
return false;
}
public static function removeMultiplicateQuestions($surveyData)
{
if (empty($surveyData)) {
return false;
}
$surveyId = $surveyData['survey_id'];
$courseId = $surveyData['c_id'];
if (empty($surveyId) || empty($courseId)) {
return false;
}
$questions = self::get_questions($surveyId);
foreach ($questions as $question) {
// Questions marked with "geneated" were created using the "multiplicate" feature.
if ($question['survey_question_comment'] === 'generated') {
self::delete_survey_question($surveyId, $question['question_id']);
}
}
}
/**
* @param array $surveyData
*
* @return bool
*/
public static function multiplicateQuestions($surveyData)
{
if (empty($surveyData)) {
return false;
}
$surveyId = $surveyData['survey_id'];
$courseId = $surveyData['c_id'];
if (empty($surveyId) || empty($courseId)) {
return false;
}
$questions = self::get_questions($surveyId);
$obj = new UserGroup();
$options['where'] = [' usergroup.course_id = ? ' => $courseId];
$classList = $obj->getUserGroupInCourse($options);
$classTag = '{{class_name}}';
$studentTag = '{{student_full_name}}';
$classCounter = 0;
foreach ($classList as $class) {
$className = $class['name'];
foreach ($questions as $question) {
$users = $obj->get_users_by_usergroup($class['id']);
if (empty($users)) {
continue;
}
$text = $question['question'];
if (strpos($text, $classTag) !== false) {
$replacedText = str_replace($classTag, $className, $text);
$values = [
'c_id' => $courseId,
'question_comment' => 'generated',
'type' => $question['type'],
'display' => $question['horizontalvertical'],
'question' => $replacedText,
'survey_id' => $surveyId,
'question_id' => 0,
'shared_question_id' => 0,
];
self::save_question($surveyData, $values);
$classCounter++;
continue;
}
foreach ($users as $userId) {
$userInfo = api_get_user_info($userId);
if (strpos($text, $studentTag) !== false) {
$replacedText = str_replace($studentTag, $userInfo['complete_name'], $text);
$values = [
'c_id' => $courseId,
'question_comment' => 'generated',
'type' => $question['type'],
'display' => $question['horizontalvertical'],
'maximum_score' => $question['maximum_score'],
'question' => $replacedText,
'survey_id' => $surveyId,
'question_id' => 0,
'shared_question_id' => 0,
];
$answers = [];
if (!empty($question['answers'])) {
foreach ($question['answers'] as $answer) {
$replacedText = str_replace($studentTag, $userInfo['complete_name'], $answer);
$answers[] = $replacedText;
}
}
$values['answers'] = $answers;
self::save_question($surveyData, $values);
}
}
if ($classCounter < count($classList)) {
// Add end page
$values = [
'c_id' => $courseId,
'question_comment' => 'generated',
'type' => 'pagebreak',
'display' => 'horizontal',
'question' => get_lang('QuestionForNextClass'),
'survey_id' => $surveyId,
'question_id' => 0,
'shared_question_id' => 0,
];
self::save_question($surveyData, $values);
}
}
}
}
}

@ -44,7 +44,7 @@ $table_survey_question_group = Database::get_course_table(TABLE_SURVEY_QUESTION_
$table_course = Database::get_main_table(TABLE_MAIN_COURSE);
$table_user = Database::get_main_table(TABLE_MAIN_USER);
$survey_id = intval($_GET['survey_id']);
$survey_id = (int) $_GET['survey_id'];
$course_id = api_get_course_int_id();
$action = isset($_GET['action']) ? $_GET['action'] : null;
@ -89,7 +89,9 @@ if ($is_survey_type_1 && ($action == 'addgroup' || $action == 'deletegroup')) {
}
if ($action == 'deletegroup') {
Database::query('DELETE FROM '.$table_survey_question_group.' WHERE c_id = '.$course_id.' AND id = '.intval($_GET['gid']).' and survey_id = '.intval($survey_id));
$sql = 'DELETE FROM '.$table_survey_question_group.'
WHERE c_id = '.$course_id.' AND id = '.intval($_GET['gid']).' AND survey_id = '.intval($survey_id);
Database::query($sql);
$sendmsg = 'GroupDeletedSuccessfully';
}
header('Location: '.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&sendmsg='.$sendmsg);
@ -97,7 +99,6 @@ if ($is_survey_type_1 && ($action == 'addgroup' || $action == 'deletegroup')) {
}
// Displaying the header
Display::display_header($tool_name, 'Survey');
// Action handling
@ -132,26 +133,36 @@ if (!empty($survey_data['survey_version'])) {
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 = '';
if ($survey_data['survey_type'] != 3) {
$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/preview.php?'.api_get_cidreq().'&survey_id='.$survey_id.'">'.
Display::return_icon('preview_view.png', get_lang('Preview'), '', ICON_SIZE_MEDIUM).'</a>';
if ($survey_data['survey_type'] != 3) {
$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>';
if (!api_get_configuration_value('hide_survey_reporting_button')) {
$survey_actions .= Display::url(
Display::return_icon('stats.png', get_lang('Reporting'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'survey/reporting.php?'.api_get_cidreq().'&survey_id='.$survey_id
);
if ($survey_data['survey_type'] != 3) {
if (!api_get_configuration_value('hide_survey_reporting_button')) {
$survey_actions .= Display::url(
Display::return_icon('stats.png', get_lang('Reporting'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'survey/reporting.php?'.api_get_cidreq().'&survey_id='.$survey_id
);
}
}
echo '<div class="actions">'.$survey_actions.'</div>';
$urlQuestion = api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&action=add';
if ($survey_data['survey_type'] == 0) {
$urlQuestion = api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&action=add';
echo '<div class="well">';
echo Display::url(
Display::return_icon('yesno.png', get_lang('YesNo'), null, ICON_SIZE_BIG),
@ -191,12 +202,14 @@ if ($survey_data['survey_type'] == 0) {
);
echo '</div>';
} else {
echo '<div class="well">';
echo Display::url(
Display::return_icon('yesno.png', get_lang('YesNo'), null, ICON_SIZE_BIG),
$urlQuestion.'&type=personality&survey_id='.$survey_id
);
echo '</a></div>';
if ($survey_data['survey_type'] != 3) {
echo '<div class="well">';
echo Display::url(
Display::return_icon('yesno.png', get_lang('YesNo'), null, ICON_SIZE_BIG),
$urlQuestion.'&type=personality&survey_id='.$survey_id
);
echo '</a></div>';
}
}
// Displaying the table header with all the questions
@ -218,7 +231,7 @@ echo '</thead>';
// Displaying the table contents with all the questions
$question_counter = 1;
$sql = "SELECT * FROM $table_survey_question_group
WHERE c_id = '.$course_id.' AND survey_id = ".intval($survey_id)."
WHERE c_id = $course_id AND survey_id = $survey_id
ORDER BY id";
$result = Database::query($sql);
$groups = [];
@ -243,10 +256,16 @@ while ($row = Database::fetch_array($result, 'ASSOC')) {
echo '<tr>';
echo ' <td>'.$question_counter.'</td>';
echo ' <td>';
if (api_strlen($row['survey_question']) > 100) {
echo api_substr(strip_tags($row['survey_question']), 0, 100).' ... ';
if ($survey_data['survey_type'] != 3) {
if (api_strlen($row['survey_question']) > 100) {
echo api_substr(strip_tags($row['survey_question']), 0, 100).' ... ';
} else {
echo $row['survey_question'];
}
} else {
echo $row['survey_question'];
$parts = explode('@@', $row['survey_question']);
echo api_get_local_time($parts[0]).' - '.api_get_local_time($parts[1]);
}
if ($row['type'] == 'yesno') {
@ -261,21 +280,28 @@ while ($row = Database::fetch_array($result, 'ASSOC')) {
echo '<td>'.$tool_name.'</td>';
echo '<td>'.$row['number_of_options'].'</td>';
echo '<td>';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&action=edit&type='.$row['type'].'&survey_id='.$survey_id.'&question_id='.$row['question_id'].'">'.
Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>';
if ($survey_data['survey_type'] != 3) {
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&action=edit&type='.$row['type'].'&survey_id='.$survey_id.'&question_id='.$row['question_id'].'">'.
Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>';
}
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?'.api_get_cidreq().'&action=delete&survey_id='.$survey_id.'&question_id='.$row['question_id'].'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("DeleteSurveyQuestion").'?', ENT_QUOTES, $charset)).'\')) return false;">'.
Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>';
if ($question_counter > 1) {
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?'.api_get_cidreq().'&action=moveup&survey_id='.$survey_id.'&question_id='.$row['question_id'].'">'.
Display::return_icon('up.png', get_lang('MoveUp'), '', ICON_SIZE_SMALL).'</a>';
} else {
Display::display_icon('up_na.png', '&nbsp;', '', ICON_SIZE_SMALL);
}
if ($question_counter < $question_counter_max) {
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?'.api_get_cidreq().'&action=movedown&survey_id='.$survey_id.'&question_id='.$row['question_id'].'">'.
Display::return_icon('down.png', get_lang('MoveDown'), '', ICON_SIZE_SMALL).'</a>';
} else {
Display::display_icon('down_na.png', '&nbsp;', '', ICON_SIZE_SMALL);
if ($survey_data['survey_type'] != 3) {
if ($question_counter > 1) {
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?'.api_get_cidreq(
).'&action=moveup&survey_id='.$survey_id.'&question_id='.$row['question_id'].'">'.
Display::return_icon('up.png', get_lang('MoveUp'), '', ICON_SIZE_SMALL).'</a>';
} else {
Display::display_icon('up_na.png', '&nbsp;', '', ICON_SIZE_SMALL);
}
if ($question_counter < $question_counter_max) {
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?'.api_get_cidreq(
).'&action=movedown&survey_id='.$survey_id.'&question_id='.$row['question_id'].'">'.
Display::return_icon('down.png', get_lang('MoveDown'), '', ICON_SIZE_SMALL).'</a>';
} else {
Display::display_icon('down_na.png', '&nbsp;', '', ICON_SIZE_SMALL);
}
}
echo ' </td>';
$question_counter++;
@ -345,11 +371,11 @@ if ($is_survey_type_1) {
$rs = Database::query($sql);
while ($row = Database::fetch_array($rs, 'ASSOC')) {
$grouplist .= '<tr><td>'.$row['name'].'</td><td>'.$row['description'].'</td><td>'.
'<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&gid='.$row['id'].'&action=editgroup">'.
Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a> '.
'<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&gid='.$row['id'].'&action=deletegroup" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('DeleteSurveyGroup'), $row['name']).'?', ENT_QUOTES)).'\')) return false;">'.
Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>'.
'</td></tr>';
'<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&gid='.$row['id'].'&action=editgroup">'.
Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a> '.
'<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&gid='.$row['id'].'&action=deletegroup" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('DeleteSurveyGroup'), $row['name']).'?', ENT_QUOTES)).'\')) return false;">'.
Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>'.
'</td></tr>';
}
echo $grouplist.'</table>';
}

@ -2,6 +2,7 @@
/* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Entity\CSurvey;
use Chamilo\CourseBundle\Entity\CSurveyAnswer;
use ChamiloSession as Session;
/**
@ -106,6 +107,7 @@ class SurveyUtil
if (empty($question_id)) {
return false;
}
// Table definition
$table_survey_answer = Database::get_course_table(TABLE_SURVEY_ANSWER);
@ -120,22 +122,26 @@ class SurveyUtil
}
}
$course_id = $survey_data['c_id'];
$answer = new CSurveyAnswer();
$answer
->setCId($survey_data['c_id'])
->setUser($user)
->setSurveyId($survey_id)
->setQuestionId($question_id)
->setOptionId($option_id)
->setValue($option_value)
;
$sql = "INSERT INTO $table_survey_answer (c_id, user, survey_id, question_id, option_id, value) VALUES (
$course_id,
'".Database::escape_string($user)."',
'".Database::escape_string($survey_id)."',
'".Database::escape_string($question_id)."',
'".Database::escape_string($option_id)."',
'".Database::escape_string($option_value)."'
)";
Database::query($sql);
$insertId = Database::insert_id();
$em = Database::getManager();
$em->persist($answer);
$em->flush();
$sql = "UPDATE $table_survey_answer SET answer_id = $insertId
$insertId = $answer->getIid();
if ($insertId) {
$sql = "UPDATE $table_survey_answer SET answer_id = $insertId
WHERE iid = $insertId";
Database::query($sql);
Database::query($sql);
}
return true;
}
@ -480,16 +486,18 @@ class SurveyUtil
}
$ch_type = 'ch_'.$question['type'];
/** @var survey_question $display */
$display = new $ch_type();
$url = api_get_self();
$form = new FormValidator('question', 'post', $url);
$form->addHtml('<div class="survey_question_wrapper"><div class="survey_question">');
$form->addHtml($question['survey_question']);
$display->render($form, $question, $finalAnswer);
$form->addHtml('</div></div>');
$form->display();
if (class_exists($ch_type)) {
/** @var survey_question $display */
$display = new $ch_type();
$url = api_get_self();
$form = new FormValidator('question', 'post', $url);
$form->addHtml('<div class="survey_question_wrapper"><div class="survey_question">');
$form->addHtml($question['survey_question']);
$display->render($form, $question, $finalAnswer);
$form->addHtml('</div></div>');
$form->display();
}
}
}
}
@ -698,14 +706,20 @@ class SurveyUtil
echo ' </tr>';
}
}
// displaying the table: footer (totals)
$optionResult = '';
if (isset($option['question_id']) && isset($number_of_answers[$option['question_id']])) {
if ($number_of_answers[$option['question_id']] == 0) {
$optionResult = '0';
} else {
$optionResult = $number_of_answers[$option['question_id']];
}
}
// displaying the table: footer (totals)
echo ' <tr>';
echo ' <td class="total"><b>'.get_lang('Total').'</b></td>';
echo ' <td class="total"><b>'
.($number_of_answers[$option['question_id']] == 0
? '0'
: $number_of_answers[$option['question_id']])
.'</b></td>';
echo ' <td class="total"><b>'.$optionResult.'</b></td>';
echo ' <td class="total">&nbsp;</td>';
echo ' <td class="total">&nbsp;</td>';
echo ' </tr>';
@ -1484,18 +1498,13 @@ class SurveyUtil
public static function export_complete_report_xls($survey_data, $filename, $user_id = 0)
{
$course_id = api_get_course_int_id();
$user_id = (int) $user_id;
$surveyId = isset($_GET['survey_id']) ? (int) $_GET['survey_id'] : 0;
if (empty($course_id) || empty($surveyId)) {
return false;
}
$spreadsheet = new PHPExcel();
$spreadsheet->setActiveSheetIndex(0);
$worksheet = $spreadsheet->getActiveSheet();
$line = 1;
$column = 1; // Skip the first column (row titles)
// Show extra fields blank space (enough for extra fields on next line)
// Show user fields section with a big th colspan that spans over all fields
$extra_user_fields = UserManager::get_extra_fields(
@ -1506,10 +1515,10 @@ class SurveyUtil
false,
true
);
$list = [];
$num = count($extra_user_fields);
for ($i = 0; $i < $num; $i++) {
$worksheet->setCellValueByColumnAndRow($column, $line, '');
$column++;
$list[0][] = '';
}
$display_extra_user_fields = true;
@ -1534,6 +1543,8 @@ class SurveyUtil
GROUP BY questions.question_id
ORDER BY questions.sort ASC";
$result = Database::query($sql);
$line = 1;
$column = 1;
while ($row = Database::fetch_array($result)) {
// We show the questions if
// 1. there is no question filter and the export button has not been clicked
@ -1545,24 +1556,16 @@ class SurveyUtil
// We do not show comment and pagebreak question types
if ($row['type'] != 'pagebreak') {
if ($row['number_of_options'] == 0 && ($row['type'] == 'open' || $row['type'] == 'comment')) {
$worksheet->setCellValueByColumnAndRow(
$column,
$line,
api_html_entity_decode(
strip_tags($row['survey_question']),
ENT_QUOTES
)
$list[$line][$column] = api_html_entity_decode(
strip_tags($row['survey_question']),
ENT_QUOTES
);
$column++;
} else {
for ($ii = 0; $ii < $row['number_of_options']; $ii++) {
$worksheet->setCellValueByColumnAndRow(
$column,
$line,
api_html_entity_decode(
strip_tags($row['survey_question']),
ENT_QUOTES
)
$list[$line][$column] = api_html_entity_decode(
strip_tags($row['survey_question']),
ENT_QUOTES
);
$column++;
}
@ -1577,11 +1580,7 @@ class SurveyUtil
if ($display_extra_user_fields) {
// Show the fields names for user fields
foreach ($extra_user_fields as &$field) {
$worksheet->setCellValueByColumnAndRow(
$column,
$line,
api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES)
);
$list[$line][$column] = api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES);
$column++;
}
}
@ -1619,13 +1618,9 @@ class SurveyUtil
) {
// We do not show comment and pagebreak question types
if ($row['type'] != 'pagebreak') {
$worksheet->setCellValueByColumnAndRow(
$column,
$line,
api_html_entity_decode(
strip_tags($row['option_text']),
ENT_QUOTES
)
$list[$line][$column] = api_html_entity_decode(
strip_tags($row['option_text']),
ENT_QUOTES
);
$possible_answers[$row['question_id']][$row['question_option_id']] = $row['question_option_id'];
$possible_answers_type[$row['question_id']] = $row['type'];
@ -1642,7 +1637,7 @@ class SurveyUtil
$sql = "SELECT * FROM $table_survey_answer
WHERE c_id = $course_id AND survey_id = $surveyId";
if ($user_id != 0) {
$sql .= " AND user='".intval($user_id)."' ";
$sql .= " AND user='".$user_id."' ";
}
$sql .= " ORDER BY user ASC";
@ -1658,7 +1653,7 @@ class SurveyUtil
true
);
foreach ($return as $elem) {
$worksheet->setCellValueByColumnAndRow($column, $line, $elem);
$list[$line][$column] = $elem;
$column++;
}
$answers_of_user = [];
@ -1685,14 +1680,11 @@ class SurveyUtil
// this is to display the last user
foreach ($return as $elem) {
$worksheet->setCellValueByColumnAndRow($column, $line, $elem);
$list[$line][$column] = $elem;
$column++;
}
$file = api_get_path(SYS_ARCHIVE_PATH).api_replace_dangerous_char($filename);
$writer = new PHPExcel_Writer_Excel2007($spreadsheet);
$writer->save($file);
DocumentManager::file_send_for_download($file, true, $filename);
Export::arrayToXls($list, $filename);
return null;
}
@ -1837,7 +1829,6 @@ class SurveyUtil
foreach ($questions as $key => &$question) {
if (is_array($allowed_question_types)) {
if (in_array($question['type'], $allowed_question_types)) {
//echo '<option value="'.$question['question_id'].'"';
if (isset($_GET['xaxis']) && $_GET['xaxis'] == $question['question_id']) {
$defaults['xaxis'] = $question['question_id'];
}
@ -2115,75 +2106,6 @@ class SurveyUtil
return $counter;
}
/**
* Get all the information about the invitations of a certain survey.
*
* @return array Lines of invitation [user, code, date, empty element]
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*
* @version January 2007
*
* @todo use survey_id parameter instead of $_GET
*/
public static function get_survey_invitations_data()
{
$course_id = api_get_course_int_id();
// Database table definition
$table_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
$table_user = Database::get_main_table(TABLE_MAIN_USER);
$sql = "SELECT
survey_invitation.user as col1,
survey_invitation.invitation_code as col2,
survey_invitation.invitation_date as col3,
'' as col4
FROM $table_survey_invitation survey_invitation
LEFT JOIN $table_user user
ON survey_invitation.user = user.user_id
WHERE
survey_invitation.c_id = $course_id AND
survey_invitation.survey_id = '".intval($_GET['survey_id'])."' AND
session_id='".api_get_session_id()."' ";
$res = Database::query($sql);
$data = [];
while ($row = Database::fetch_array($res)) {
$data[] = $row;
}
return $data;
}
/**
* Get the total number of survey invitations for a given survey (through $_GET['survey_id']).
*
* @return int Total number of survey invitations
*
* @todo use survey_id parameter instead of $_GET
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*
* @version January 2007
*/
public static function get_number_of_survey_invitations()
{
$course_id = api_get_course_int_id();
// Database table definition
$table = Database::get_course_table(TABLE_SURVEY_INVITATION);
$sql = "SELECT count(user) AS total
FROM $table
WHERE
c_id = $course_id AND
survey_id='".intval($_GET['survey_id'])."' AND
session_id='".api_get_session_id()."' ";
$res = Database::query($sql);
$row = Database::fetch_array($res, 'ASSOC');
return $row['total'];
}
/**
* Save the invitation mail.
*
@ -2368,6 +2290,12 @@ class SurveyUtil
(!empty($params['user']) || !empty($params['group_id'])) &&
!empty($params['survey_code'])
) {
$params['survey_invitation_id'] = $params['survey_invitation_id'] ?? 0;
$params['reminder_date'] = $params['reminder_date'] ?? null;
$params['answered'] = $params['answered'] ?? 0;
$params['group_id'] = $params['group_id'] ?? 0;
$insertId = Database::insert($table, $params);
if ($insertId) {
$sql = "UPDATE $table
@ -2878,6 +2806,8 @@ class SurveyUtil
return $hideReportingButton ? '-' : $reportingLink;
}
$type = $survey->getSurveyType();
// 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)
@ -2887,46 +2817,70 @@ class SurveyUtil
$codePath.'survey/create_new_survey.php?'
.http_build_query($params + ['action' => 'edit', 'survey_id' => $survey_id])
);
if (SurveyManager::survey_generation_hash_available()) {
$actions[] = Display::url(
Display::return_icon('new_link.png', get_lang('GenerateSurveyAccessLink')),
$codePath.'survey/generate_link.php?'.http_build_query($params + ['survey_id' => $survey_id])
);
}
if ($type != 3) {
$actions[] = Display::url(
Display::return_icon('backup.png', get_lang('CopySurvey')),
$codePath.'survey/copy_survey.php?'.http_build_query($params + ['survey_id' => $survey_id])
);
$actions[] = Display::url(
Display::return_icon('copy.png', get_lang('DuplicateSurvey')),
$codePath.'survey/survey_list.php?'
.http_build_query($params + ['action' => 'copy_survey', 'survey_id' => $survey_id])
);
$actions[] = Display::url(
Display::return_icon('star.png', get_lang('MultiplicateSurvey')),
$codePath.'survey/survey_list.php?'
.http_build_query($params + ['action' => 'multiplicate', 'survey_id' => $survey_id])
);
$actions[] = Display::url(
Display::return_icon('star_na.png', get_lang('RemoveMultiplicateQuestions')),
$codePath.'survey/survey_list.php?'
.http_build_query($params + ['action' => 'remove_multiplicate', 'survey_id' => $survey_id])
);
$warning = addslashes(api_htmlentities(get_lang('EmptySurvey').'?', ENT_QUOTES));
$actions[] = Display::url(
Display::return_icon('clean.png', get_lang('EmptySurvey')),
$codePath.'survey/survey_list.php?'
.http_build_query($params + ['action' => 'empty', 'survey_id' => $survey_id]),
[
'onclick' => "javascript: if (!confirm('".$warning."')) return false;",
]
);
}
}
if ($type != 3) {
$actions[] = Display::url(
Display::return_icon('backup.png', get_lang('CopySurvey')),
$codePath.'survey/copy_survey.php?'.http_build_query($params + ['survey_id' => $survey_id])
);
$actions[] = Display::url(
Display::return_icon('copy.png', get_lang('DuplicateSurvey')),
$codePath.'survey/survey_list.php?'
.http_build_query($params + ['action' => 'copy_survey', 'survey_id' => $survey_id])
Display::return_icon('preview_view.png', get_lang('Preview')),
$codePath.'survey/preview.php?'.http_build_query($params + ['survey_id' => $survey_id])
);
}
$warning = addslashes(api_htmlentities(get_lang('EmptySurvey').'?', ENT_QUOTES));
$actions[] = Display::url(
Display::return_icon('clean.png', get_lang('EmptySurvey')),
$codePath.'survey/survey_list.php?'
.http_build_query($params + ['action' => 'empty', 'survey_id' => $survey_id]),
[
'onclick' => "javascript: if (!confirm('".$warning."')) return false;",
]
Display::return_icon('mail_send.png', get_lang('Publish')),
$codePath.'survey/survey_invite.php?'.http_build_query($params + ['survey_id' => $survey_id])
);
}
$actions[] = Display::url(
Display::return_icon('preview_view.png', get_lang('Preview')),
$codePath.'survey/preview.php?'.http_build_query($params + ['survey_id' => $survey_id])
);
$actions[] = Display::url(
Display::return_icon('mail_send.png', get_lang('Publish')),
$codePath.'survey/survey_invite.php?'.http_build_query($params + ['survey_id' => $survey_id])
);
$actions[] = $hideReportingButton ? null : $reportingLink;
if ($type != 3) {
$actions[] = $hideReportingButton ? null : $reportingLink;
}
if (api_is_allowed_to_edit() ||
api_is_element_in_the_session(TOOL_SURVEY, $survey_id)
) {
$warning = addslashes(api_htmlentities(get_lang("DeleteSurvey").'?', ENT_QUOTES));
$warning = addslashes(api_htmlentities(get_lang('DeleteSurvey').'?', ENT_QUOTES));
$actions[] = Display::url(
Display::return_icon('delete.png', get_lang('Delete')),
$codePath.'survey/survey_list.php?'
@ -3093,9 +3047,9 @@ class SurveyUtil
if ($search_restriction) {
$search_restriction = ' AND '.$search_restriction;
}
$from = intval($from);
$number_of_items = intval($number_of_items);
$column = intval($column);
$from = (int) $from;
$number_of_items = (int) $number_of_items;
$column = (int) $column;
if (!in_array(strtolower($direction), ['asc', 'desc'])) {
$direction = 'asc';
}
@ -3122,7 +3076,8 @@ class SurveyUtil
survey.iid AS col9,
survey.session_id AS session_id,
survey.answered,
survey.invited
survey.invited,
survey.survey_type
FROM $table_survey survey
LEFT JOIN $table_survey_question survey_question
ON (survey.survey_id = survey_question.survey_id AND survey_question.c_id = $course_id)
@ -3135,23 +3090,28 @@ class SurveyUtil
ORDER BY col$column $direction
LIMIT $from,$number_of_items
";
$res = Database::query($sql);
$surveys = [];
$array = [];
$efv = new ExtraFieldValue('survey');
while ($survey = Database::fetch_array($res)) {
$array[0] = $survey[0];
if (self::checkHideEditionToolsByCode($survey['col2'])) {
$array[1] = $survey[1];
} else {
// Doodle
if ($survey['survey_type'] == 3) {
$array[1] = Display::url(
$survey[1],
api_get_path(WEB_CODE_PATH).'survey/meeting.php?survey_id='.$survey[0].'&'.api_get_cidreq()
);
} else {
$array[1] = Display::url(
$survey[1],
api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey[0].'&'.api_get_cidreq()
);
}
}
// Validation when belonging to a session
$session_img = api_get_session_image($survey['session_id'], $_user['status']);
@ -3307,7 +3267,7 @@ class SurveyUtil
{
$_course = api_get_course_info();
$course_id = $_course['real_id'];
$user_id = intval($user_id);
$user_id = (int) $user_id;
$sessionId = api_get_session_id();
$mandatoryAllowed = api_get_configuration_value('allow_mandatory_survey');
$allowSurveyAvailabilityDatetime = api_get_configuration_value('allow_survey_availability_datetime');
@ -3317,16 +3277,6 @@ class SurveyUtil
$table_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
$table_survey = Database::get_course_table(TABLE_SURVEY);
$sql = "SELECT question_id
FROM $table_survey_question
WHERE c_id = $course_id";
$result = Database::query($sql);
$all_question_id = [];
while ($row = Database::fetch_array($result, 'ASSOC')) {
$all_question_id[] = $row;
}
echo '<table id="list-survey" class="table ">';
echo '<thead>';
echo '<tr>';
@ -3349,8 +3299,8 @@ class SurveyUtil
$table_survey_invitation survey_invitation
ON (
survey.code = survey_invitation.survey_code AND
survey.c_id = survey_invitation.c_id
AND survey.session_id = survey_invitation.session_id
survey.c_id = survey_invitation.c_id AND
survey.session_id = survey_invitation.session_id
)
WHERE
survey_invitation.user = $user_id AND
@ -3374,8 +3324,9 @@ class SurveyUtil
[],
ICON_SIZE_TINY
);
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/fillsurvey.php?course='.$_course['sysCode']
.'&invitationcode='.$row['invitation_code'].'&cidReq='.$_course['sysCode'].'&id_session='.$row['session_id'].'">
$url = api_get_path(WEB_CODE_PATH).'survey/fillsurvey.php?course='.$_course['sysCode']
.'&invitationcode='.$row['invitation_code'].'&cidReq='.$_course['sysCode'].'&id_session='.$row['session_id'];
echo '<a href="'.$url.'">
'.$row['title']
.'</a></td>';
} else {

@ -63,24 +63,25 @@ if ($survey_data['anonymous'] == 1) {
);
$answered_data = [];
}
$url = api_get_self().'?survey_id='.$survey_id.'&'.api_get_cidreq();
if (!isset($_GET['view']) || $_GET['view'] == 'invited') {
echo get_lang('ViewInvited').' | ';
} else {
echo ' <a href="'.api_get_self().'?survey_id='.$survey_id.'&view=invited">'.
echo ' <a href="'.$url.'&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">'.
echo ' <a href="'.$url.'&view=answered">'.
get_lang('ViewAnswered').'</a> |';
}
if ($_GET['view'] == 'unanswered') {
echo get_lang('ViewUnanswered');
} else {
echo ' <a href="'.api_get_self().'?survey_id='.$survey_id.'&view=unanswered">'.
echo ' <a href="'.$url.'&view=unanswered">'.
get_lang('ViewUnanswered').'</a>';
}
@ -118,11 +119,13 @@ while ($row = Database::fetch_assoc($res)) {
} else {
echo '<td>'.$row['user'].'</td>';
}
echo ' <td>'.api_get_local_time($row['invitation_date']).'</td>';
echo ' <td>'.Display::dateToStringAgoAndLongDate($row['invitation_date']).'</td>';
echo ' <td>';
if (in_array($row['user'], $answered_data) && !api_get_configuration_value('hide_survey_reporting_button')) {
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=userreport&survey_id='.$survey_id.'&user='.$row['user'].'">'.
echo '<a href="'.
api_get_path(WEB_CODE_PATH).
'survey/reporting.php?action=userreport&survey_id='.$survey_id.'&user='.$row['user'].'&'.api_get_cidreq().'">'.
get_lang('ViewAnswers').'</a>';
} else {
echo '-';
@ -135,6 +138,5 @@ while ($row = Database::fetch_assoc($res)) {
// Closing the table
echo '</table>';
// Footer
Display::display_footer();

@ -23,6 +23,7 @@ if (!api_is_allowed_to_edit(false, true)) {
}
$course_id = api_get_course_int_id();
$_course = api_get_course_info();
// Getting the survey information
$survey_id = Security::remove_XSS($_GET['survey_id']);
@ -237,11 +238,12 @@ if ($form->validate()) {
// Counting the number of people that are invited
$total_invited = SurveyUtil::update_count_invited($survey_data['code']);
$total_count = $count_course_users + $counter_additional_users;
$invitationUrl = api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?survey_id='.$survey_data['survey_id'].'&'.api_get_cidreq();
if ($total_invited > 0) {
$message = '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=answered&survey_id='.$survey_data['survey_id'].'">'.
$message = '<a href="'.$invitationUrl.'&view=answered">'.
$survey_data['answered'].'</a> ';
$message .= get_lang('HaveAnswered').' ';
$message .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=invited&survey_id='.$survey_data['survey_id'].'">'.
$message .= '<a href="'.$invitationUrl.'&view=invited">'.
$total_invited.'</a> ';
$message .= get_lang('WereInvited');
echo Display::return_message($message, 'normal', false);

@ -17,7 +17,6 @@ if (!isset($_GET['cidReq'])) {
$cidReset = true;
}
// Including the global initialization file
require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_COURSES;
$current_course_tool = TOOL_SURVEY;
@ -34,6 +33,7 @@ Event::event_access_tool(TOOL_SURVEY);
* of the code)
*/
$courseInfo = api_get_course_info();
$sessionId = api_get_session_id();
$isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
$currentUserId,
$courseInfo
@ -73,13 +73,85 @@ if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
$tool_name = get_lang('SurveyList');
}
if ($action == 'copy_survey') {
if (api_is_allowed_to_edit()) {
SurveyManager::copy_survey($_GET['survey_id']);
$message = get_lang('SurveyCopied');
header('Location: '.api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq());
$listUrl = api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq();
$surveyId = isset($_GET['survey_id']) ? $_GET['survey_id'] : 0;
switch ($action) {
case 'remove_multiplicate':
$surveyData = SurveyManager::get_survey($surveyId);
if (!empty($surveyData)) {
SurveyManager::removeMultiplicateQuestions($surveyData);
Display::addFlash(Display::return_message(get_lang('Updated'), 'confirmation', false));
}
header('Location: '.$listUrl);
exit;
}
break;
case 'multiplicate':
$surveyData = SurveyManager::get_survey($surveyId);
if (!empty($surveyData)) {
SurveyManager::multiplicateQuestions($surveyData);
Display::cleanFlashMessages();
Display::addFlash(Display::return_message(get_lang('Updated'), 'confirmation', false));
}
header('Location: '.$listUrl);
exit;
break;
case 'copy_survey':
if (!empty($surveyId) && api_is_allowed_to_edit()) {
SurveyManager::copy_survey($surveyId);
Display::addFlash(Display::return_message(get_lang('SurveyCopied'), 'confirmation', false));
header('Location: '.$listUrl);
exit;
}
break;
case 'delete':
if (!empty($surveyId)) {
// Getting the information of the survey (used for when the survey is shared)
$survey_data = SurveyManager::get_survey($surveyId);
if (api_is_session_general_coach() && $sessionId != $survey_data['session_id']) {
// The coach can't delete a survey not belonging to his session
api_not_allowed();
}
// 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);
}
$return = SurveyManager::delete_survey($surveyId);
if ($return) {
Display::addFlash(Display::return_message(get_lang('SurveyDeleted'), 'confirmation', false));
} else {
Display::addFlash(Display::return_message(get_lang('ErrorOccurred'), 'error', false));
}
header('Location: '.$listUrl);
exit;
}
break;
case 'empty':
$mysession = api_get_session_id();
if ($mysession != 0) {
if (!((api_is_session_general_coach() || api_is_platform_admin()) &&
api_is_element_in_the_session(TOOL_SURVEY, $surveyId))) {
// The coach can't empty a survey not belonging to his session
api_not_allowed();
}
} else {
if (!(api_is_course_admin() || api_is_platform_admin())) {
api_not_allowed();
}
}
$return = SurveyManager::empty_survey($surveyId);
if ($return) {
Display::addFlash(Display::return_message(get_lang('SurveyEmptied'), 'confirmation', false));
} else {
Display::addFlash(Display::return_message(get_lang('ErrorOccurred'), 'error', false));
}
header('Location: '.$listUrl);
exit;
break;
}
// Header
@ -92,56 +164,6 @@ if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
SurveyUtil::display_survey_search_form();
}
$sessionId = api_get_session_id();
// Action handling: deleting a survey
if ($action === 'delete' && isset($_GET['survey_id'])) {
// Getting the information of the survey (used for when the survey is shared)
$survey_data = SurveyManager::get_survey($_GET['survey_id']);
if (api_is_session_general_coach() && $sessionId != $survey_data['session_id']) {
// The coach can't delete a survey not belonging to his session
api_not_allowed();
exit;
}
// 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);
}
$return = SurveyManager::delete_survey($_GET['survey_id']);
if ($return) {
echo Display::return_message(get_lang('SurveyDeleted'), 'confirmation', false);
} else {
echo Display::return_message(get_lang('ErrorOccurred'), 'error', false);
}
}
if ($action == 'empty') {
$mysession = api_get_session_id();
if ($mysession != 0) {
if (!((api_is_session_general_coach() || api_is_platform_admin()) &&
api_is_element_in_the_session(TOOL_SURVEY, $_GET['survey_id']))) {
// The coach can't empty a survey not belonging to his session
api_not_allowed();
exit;
}
} else {
if (!(api_is_course_admin() || api_is_platform_admin())) {
api_not_allowed();
exit;
}
}
$return = SurveyManager::empty_survey(intval($_GET['survey_id']));
if ($return) {
echo Display::return_message(get_lang('SurveyEmptied'), 'confirmation', false);
} else {
echo Display::return_message(get_lang('ErrorOccurred'), 'error', false);
}
}
// Action handling: performing the same action on multiple surveys
if (isset($_POST['action']) && $_POST['action']) {
if (is_array($_POST['id'])) {
@ -166,11 +188,12 @@ if (!api_is_session_general_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> ';
$url = api_get_path(WEB_CODE_PATH).'survey/create_meeting.php?'.api_get_cidreq();
echo Display::url(Display::return_icon('add.png', get_lang('CreateNewSurvey'), '', ICON_SIZE_MEDIUM), $url);
}
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_session_general_coach() && $extend_rights_for_coachs == 'false') {
SurveyUtil::display_survey_list_for_coach();

@ -155,6 +155,7 @@ class ScriptHandler
__DIR__.'/../../../../main/inc/lib/phpmailer/test/phpmailerTest.php',
__DIR__.'/../../../../main/inc/lib/xht.lib.php',
__DIR__.'/../../../../main/inc/lib/xmd.lib.php',
__DIR__.'/../../../../main/inc/lib/surveymanager.lib.php',
__DIR__.'/../../../../main/inc/lib/entity.class.php',
__DIR__.'/../../../../main/inc/lib/entity_repository.class.php',
__DIR__.'/../../../../main/inc/lib/javascript.class.php',

Loading…
Cancel
Save