Adding anonymous survey link generation see #5851

skala
Julio Montoya 13 years ago
parent c3120a97b3
commit 5c1cd3bbcf
  1. 7
      main/inc/lib/main_api.lib.php
  2. 316
      main/survey/create_new_survey.php
  3. 3
      main/survey/fillsurvey.php
  4. 34
      main/survey/generate_link.php
  5. 49
      main/survey/link.php
  6. 68
      main/survey/survey.lib.php
  7. 8
      main/survey/survey.php

@ -5067,7 +5067,6 @@ function api_get_encrypted_password($password, $salt = '') {
* @return boolean - true if secret key is valid, false otherwise
*/
function api_is_valid_secret_key($original_key_secret, $security_key) {
global $_configuration;
return $original_key_secret == sha1($security_key);
}
@ -6176,3 +6175,9 @@ function api_set_default_visibility($item_id, $tool_id, $group_id = null) {
}
}
}
function api_get_security_key() {
global $_configuration;
return $_configuration['security_key'];
}

@ -1,16 +1,16 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @package chamilo.survey
* @package chamilo.survey
* @author unknown, the initial survey that did not make it in 1.8 because of bad code
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts (if not all) of the code
* @author Julio Montoya Armas <gugli100@gmail.com>, Chamilo: Personality Test modification and rewriting large parts of the code
* @author Julio Montoya Armas <gugli100@gmail.com>, Chamilo: Personality Test modification and rewriting large parts of the code
* @version $Id: create_new_survey.php 22297 2009-07-22 22:08:30Z cfasanando $
*
* @todo only the available platform languages should be used => need an api get_languages and and api_get_available_languages (or a parameter)
*/
// Language file that needs to be included
$language_file = 'survey';
@ -47,18 +47,18 @@ $htmlHeadXtra[] = '<script type="text/javascript">
</script>';
// Database table definitions
$table_survey = Database :: get_course_table(TABLE_SURVEY);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
$table_gradebook_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
$table_survey = Database :: get_course_table(TABLE_SURVEY);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
$table_gradebook_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
/** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
/** @todo this has to be moved to a more appropriate place (after the display_header of the code) */
// If user is not teacher or if he's a coach trying to access an element out of his session
if (!api_is_allowed_to_edit()) {
if (!api_is_course_coach() || (!empty($_GET['survey_id']) && !api_is_element_in_the_session(TOOL_SURVEY, intval($_GET['survey_id'])))) {
api_not_allowed(true);
exit;
}
if (!api_is_course_coach() || (!empty($_GET['survey_id']) && !api_is_element_in_the_session(TOOL_SURVEY, intval($_GET['survey_id'])))) {
api_not_allowed(true);
exit;
}
}
// Getting the survey information
@ -70,48 +70,47 @@ $course_id = api_get_course_id();
$session_id = api_get_session_id();
$gradebook_link_type = 8; // LINK_SURVEY
/*$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 .= '...';
}*/
/* $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 .= '...';
} */
$urlname = $survey_data['title'];
// Breadcrumbs
if ($_GET['action'] == 'add') {
$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
$tool_name = get_lang('CreateNewSurvey');
$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
$tool_name = get_lang('CreateNewSurvey');
}
if ($_GET['action'] == 'edit' && is_numeric($survey_id))
{
$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
$interbreadcrumb[] = array('url' => 'survey.php?survey_id='.$survey_id, 'name' => strip_tags($urlname));
$tool_name = get_lang('EditSurvey');
if ($_GET['action'] == 'edit' && is_numeric($survey_id)) {
$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
$interbreadcrumb[] = array('url' => 'survey.php?survey_id='.$survey_id, 'name' => strip_tags($urlname));
$tool_name = get_lang('EditSurvey');
}
// Getting the default values
if ($_GET['action'] == 'edit' && isset($survey_id) && is_numeric($survey_id)) {
$defaults = $survey_data;
$defaults['survey_id'] = $survey_id;
$defaults['anonymous'] = $survey_data['anonymous'];
$defaults = $survey_data;
$defaults['survey_id'] = $survey_id;
$defaults['anonymous'] = $survey_data['anonymous'];
$link_info = is_resource_in_course_gradebook($course_id, $gradebook_link_type, $survey_id, $session_id);
$link_info = is_resource_in_course_gradebook($course_id, $gradebook_link_type, $survey_id, $session_id);
$gradebook_link_id = $link_info['id'];
if ($link_info) {
if ($sql_result_array = Database::fetch_array(Database::query('SELECT weight FROM '.$table_gradebook_link.' WHERE id='.$gradebook_link_id))) {
$defaults['survey_qualify_gradebook'] = $gradebook_link_id;
$defaults['survey_weight'] = number_format($sql_result_array['weight'], 2, '.', '');
}
}
if ($link_info) {
if ($sql_result_array = Database::fetch_array(Database::query('SELECT weight FROM '.$table_gradebook_link.' WHERE id='.$gradebook_link_id))) {
$defaults['survey_qualify_gradebook'] = $gradebook_link_id;
$defaults['survey_weight'] = number_format($sql_result_array['weight'], 2, '.', '');
}
}
} else {
$defaults['survey_language'] = $_course['language'];
$defaults['start_date'] = date('d-F-Y H:i');
$startdateandxdays = time() + 864000; // today + 10 days
$defaults['end_date'] = date('d-F-Y H:i', $startdateandxdays);
//$defaults['survey_share']['survey_share'] = 0;
//$form_share_value = 1;
$defaults['anonymous'] = 0;
$defaults['survey_language'] = $_course['language'];
$defaults['start_date'] = date('d-F-Y H:i');
$startdateandxdays = time() + 864000; // today + 10 days
$defaults['end_date'] = date('d-F-Y H:i', $startdateandxdays);
//$defaults['survey_share']['survey_share'] = 0;
//$form_share_value = 1;
$defaults['anonymous'] = 0;
}
// Initialize the object
@ -121,50 +120,49 @@ $form->addElement('header', '', $tool_name);
// Settting the form elements
if ($_GET['action'] == 'edit' && isset($survey_id) && is_numeric($survey_id)) {
$form->addElement('hidden', 'survey_id');
$form->addElement('hidden', 'survey_id');
}
$survey_code = $form->addElement('text', 'survey_code', get_lang('SurveyCode'), array('size' => '20', 'maxlength' => '20', 'id' => 'surveycode_title'));
//$form->applyFilter('survey_code', 'html_filter');
if ($_GET['action'] == 'edit') {
$survey_code->freeze();
$form->applyFilter('survey_code', 'api_strtoupper');
$survey_code->freeze();
$form->applyFilter('survey_code', 'api_strtoupper');
}
$form->addElement('html_editor', 'survey_title', get_lang('SurveyTitle'), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '200'));
$form->addElement('html_editor', 'survey_subtitle', get_lang('SurveySubTitle'), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '100', 'ToolbarStartExpanded' => false));
/*
//Language selection has been disabled. If you want to re-enable, please
//disable the following line (hidden language field).
$lang_array = api_get_languages();
foreach ($lang_array['name'] as $key => $value) {
$languages[$lang_array['folder'][$key]] = $value;
}
$form->addElement('select', 'survey_language', get_lang('Language'), $languages);
*/
//Language selection has been disabled. If you want to re-enable, please
//disable the following line (hidden language field).
$lang_array = api_get_languages();
foreach ($lang_array['name'] as $key => $value) {
$languages[$lang_array['folder'][$key]] = $value;
}
$form->addElement('select', 'survey_language', get_lang('Language'), $languages);
*/
// Pass the language of the survey in the form
$form->addElement('hidden', 'survey_language');
$form->addElement('datepickerdate', 'start_date', get_lang('StartDate'), array('form_name'=>'survey'));
$form->addElement('datepickerdate', 'end_date', get_lang('EndDate'), array('form_name'=>'survey'));
$form->addElement('datepickerdate', 'start_date', get_lang('StartDate'), array('form_name' => 'survey'));
$form->addElement('datepickerdate', 'end_date', get_lang('EndDate'), array('form_name' => 'survey'));
//$group = '';
//$group[] =& HTML_QuickForm::createElement('radio', 'survey_share', null, get_lang('Yes'), $form_share_value);
/** TODO Maybe it is better to change this into false instead see line 95 in survey.lib.php */
//$group[] =& HTML_QuickForm::createElement('radio', 'survey_share', null, get_lang('No'), 0);
//$form->addGroup($group, 'survey_share', get_lang('ShareSurvey'), '&nbsp;');
$form->addElement('checkbox', 'anonymous', null, get_lang('Anonymous'));
$form->addElement('html_editor', 'survey_introduction', get_lang('SurveyIntroduction'), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '130', 'ToolbarStartExpanded' => false));
$form->addElement('html_editor', 'survey_thanks', get_lang('SurveyThanks'), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '130', 'ToolbarStartExpanded' => false));
// Aditional Parameters
$form->addElement('advanced_settings','<a href="javascript: void(0);" onclick="javascript: advanced_parameters();" >
<span id="plus_minus">&nbsp;'.Display::return_icon('div_show.gif',null,array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'</span></a>');
$form->addElement('advanced_settings', '<a href="javascript: void(0);" onclick="javascript: advanced_parameters();" >
<span id="plus_minus">&nbsp;'.Display::return_icon('div_show.gif', null, array('style' => 'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'</span></a>');
$form -> addElement('html', '<div id="options" style="display: none;">');
$form->addElement('html', '<div id="options" style="display: none;">');
if (Gradebook::is_active()) {
// An option: Qualify the fact that survey has been answered in the gradebook
@ -180,74 +178,74 @@ $surveytypes[0] = get_lang('Normal');
$surveytypes[1] = get_lang('Conditional');
if ($_GET['action'] == 'add') {
$form->addElement('hidden', 'survey_type', 0);
require_once api_get_path(LIBRARY_PATH).'surveymanager.lib.php';
$survey_tree = new SurveyTree();
$list_surveys = $survey_tree->createList($survey_tree->surveylist);
$list_surveys[0] = '';
$form->addElement('select', 'parent_id', get_lang('ParentSurvey'), $list_surveys);
$defaults['parent_id'] = 0;
$form->addElement('hidden', 'survey_type', 0);
require_once api_get_path(LIBRARY_PATH).'surveymanager.lib.php';
$survey_tree = new SurveyTree();
$list_surveys = $survey_tree->createList($survey_tree->surveylist);
$list_surveys[0] = '';
$form->addElement('select', 'parent_id', get_lang('ParentSurvey'), $list_surveys);
$defaults['parent_id'] = 0;
}
if ($survey_data['survey_type'] == 1 || $_GET['action'] == 'add') {
$form->addElement('checkbox', 'one_question_per_page', null, get_lang('OneQuestionPerPage'));
$form->addElement('checkbox', 'shuffle', null, get_lang('ActivateShuffle'));
$form->addElement('checkbox', 'one_question_per_page', null, get_lang('OneQuestionPerPage'));
$form->addElement('checkbox', 'shuffle', null, get_lang('ActivateShuffle'));
}
if ((isset($_GET['action']) && $_GET['action'] == 'edit') && !empty($survey_id)) {
if ($survey_data['anonymous'] == 0) {
$form->addElement('checkbox', 'show_form_profile', null, get_lang('ShowFormProfile'), 'onclick="javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}"');
if ($survey_data['show_form_profile'] == 1) {
$form -> addElement('html', '<div id="options_field" style="display:block">');
} else {
$form -> addElement('html', '<div id="options_field" style="display:none">');
}
$field_list = SurveyUtil::make_field_list();
if (is_array($field_list)) {
// TODO hide and show the list in a fancy DIV
foreach ($field_list as $key => & $field) {
if ($field['visibility'] == 1) {
$form->addElement('checkbox', 'profile_'.$key, ' ','&nbsp;&nbsp;'.$field['name'] );
$input_name_list.= 'profile_'.$key.',';
}
}
// Necesary to know the fields
$form->addElement('hidden', 'input_name_list', $input_name_list );
// Set defaults form fields
if ($survey_data['form_fields']) {
$form_fields = explode('@', $survey_data['form_fields']);
foreach ($form_fields as & $field) {
$field_value = explode(':', $field);
if ($field_value[0] != '' && $field_value[1] != '') {
$defaults[$field_value[0]] = $field_value[1];
}
}
}
}
$form->addElement('html', '</div>');
}
if ($survey_data['anonymous'] == 0) {
$form->addElement('checkbox', 'show_form_profile', null, get_lang('ShowFormProfile'), 'onclick="javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}"');
if ($survey_data['show_form_profile'] == 1) {
$form->addElement('html', '<div id="options_field" style="display:block">');
} else {
$form->addElement('html', '<div id="options_field" style="display:none">');
}
$field_list = SurveyUtil::make_field_list();
if (is_array($field_list)) {
// TODO hide and show the list in a fancy DIV
foreach ($field_list as $key => & $field) {
if ($field['visibility'] == 1) {
$form->addElement('checkbox', 'profile_'.$key, ' ', '&nbsp;&nbsp;'.$field['name']);
$input_name_list.= 'profile_'.$key.',';
}
}
// Necesary to know the fields
$form->addElement('hidden', 'input_name_list', $input_name_list);
// Set defaults form fields
if ($survey_data['form_fields']) {
$form_fields = explode('@', $survey_data['form_fields']);
foreach ($form_fields as & $field) {
$field_value = explode(':', $field);
if ($field_value[0] != '' && $field_value[1] != '') {
$defaults[$field_value[0]] = $field_value[1];
}
}
}
}
$form->addElement('html', '</div>');
}
}
$form -> addElement('html', '</div><br />');
$form->addElement('html', '</div><br />');
if (isset($_GET['survey_id']) && $_GET['action'] == 'edit') {
$class = 'save';
$text = get_lang('ModifySurvey');
$class = 'save';
$text = get_lang('ModifySurvey');
} else {
$class = 'add';
$text = get_lang('CreateSurvey');
$class = 'add';
$text = get_lang('CreateSurvey');
}
$form->addElement('style_submit_button', 'submit_survey', $text, 'class="'.$class.'"');
// Setting the rules
if ($_GET['action'] == 'add') {
$form->addRule('survey_code', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('survey_code', '', 'maxlength', 20);
$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');
@ -259,66 +257,66 @@ $form->setDefaults($defaults);
// The validation or display
if ($form->validate()) {
// Exporting the values
$values = $form->exportValues();
// Storing the survey
$return = survey_manager::store_survey($values);
/*// Deleting the shared survey if the survey is getting unshared (this only happens when editing)
if (is_numeric($survey_data['survey_share']) && $values['survey_share']['survey_share'] == 0 && $values['survey_id'] != '') {
survey_manager::delete_survey($survey_data['survey_share'], true);
}
// Storing the already existing questions and options of a survey that gets shared (this only happens when editing)
if ($survey_data['survey_share'] == 0 && $values['survey_share']['survey_share'] !== 0 && $values['survey_id'] != '') {
survey_manager::get_complete_survey_structure($return['id']);
}
*/
if ($return['type'] == 'error') {
// Display the error
Display::display_error_message(get_lang($return['message']), false);
// Exporting the values
$values = $form->exportValues();
// Storing the survey
$return = survey_manager::store_survey($values);
/* // Deleting the shared survey if the survey is getting unshared (this only happens when editing)
if (is_numeric($survey_data['survey_share']) && $values['survey_share']['survey_share'] == 0 && $values['survey_id'] != '') {
survey_manager::delete_survey($survey_data['survey_share'], true);
}
// Storing the already existing questions and options of a survey that gets shared (this only happens when editing)
if ($survey_data['survey_share'] == 0 && $values['survey_share']['survey_share'] !== 0 && $values['survey_id'] != '') {
survey_manager::get_complete_survey_structure($return['id']);
}
*/
if ($return['type'] == 'error') {
// Display the error
Display::display_error_message(get_lang($return['message']), false);
// Displaying the header
Display::display_header($tool_name);
// Display the form
$form->display();
} else {
$gradebook_option = $values['survey_qualify_gradebook'] > 0;
if ($gradebook_option) {
$survey_id = intval($return['id']);
if ($survey_id > 0) {
$title_gradebook = ''; // Not needed here.
$description_gradebook = ''; // Not needed here.
$survey_weight = floatval($_POST['survey_weight']);
$max_score = 1;
$date = time(); // TODO: Maybe time zones implementation is needed here.
$visible = 1; // 1 = visible
$link_info = is_resource_in_course_gradebook($course_id, $gradebook_link_type, $survey_id, $session_id);
// Display the form
$form->display();
} else {
$gradebook_option = $values['survey_qualify_gradebook'] > 0;
if ($gradebook_option) {
$survey_id = intval($return['id']);
if ($survey_id > 0) {
$title_gradebook = ''; // Not needed here.
$description_gradebook = ''; // Not needed here.
$survey_weight = floatval($_POST['survey_weight']);
$max_score = 1;
$date = time(); // TODO: Maybe time zones implementation is needed here.
$visible = 1; // 1 = visible
$link_info = is_resource_in_course_gradebook($course_id, $gradebook_link_type, $survey_id, $session_id);
$gradebook_link_id = $link_info['id'];
if (!$gradebook_link_id) {
add_resource_to_course_gradebook($course_id, $gradebook_link_type, $survey_id, $title_gradebook, $survey_weight, $max_score, $description_gradebook, 1, $session_id);
} else {
Database::query('UPDATE '.$table_gradebook_link.' SET weight='.$survey_weight.' WHERE id='.$gradebook_link_id);
}
}
}
}
if ($config['survey']['debug']) {
// Displaying a feedback message
Display::display_confirmation_message($return['message'], false);
} else {
// Redirecting to the survey page (whilst showing the return message)
header('location:survey.php?survey_id='.$return['id'].'&message='.$return['message']);
if (!$gradebook_link_id) {
add_resource_to_course_gradebook($course_id, $gradebook_link_type, $survey_id, $title_gradebook, $survey_weight, $max_score, $description_gradebook, 1, $session_id);
} else {
Database::query('UPDATE '.$table_gradebook_link.' SET weight='.$survey_weight.' WHERE id='.$gradebook_link_id);
}
}
}
}
if ($config['survey']['debug']) {
// Displaying a feedback message
Display::display_confirmation_message($return['message'], false);
} else {
// Redirecting to the survey page (whilst showing the return message)
header('location:survey.php?survey_id='.$return['id'].'&message='.$return['message']);
exit;
}
}
} else {
// Displaying the header
Display::display_header($tool_name);
$form->display();
$form->display();
}
// Footer

@ -77,6 +77,7 @@ if ($invitationcode == 'auto' && isset($_GET['scode'])) {
api_not_allowed();
}
$userid = $_user['user_id'];
$scode = Database::escape_string($_GET['scode']); // Survey_code of the survey
$autoInvitationcode = "auto-$userid-$scode"; // New invitation code from userid
// The survey code must exist in this course, or the URL is invalid
@ -374,7 +375,7 @@ if ($survey_data['form_fields'] != '' && $survey_data['anonymous'] == 0 && is_ar
}
if ($list['language'] == 1) {
// LANGUAGE
//LANGUAGE
$form->addElement('select_language', 'language', get_lang('Language'));
if (api_get_setting('profile', 'language') !== 'true') {
$form->freeze('language');

@ -0,0 +1,34 @@
<?php
$language_file = 'survey';
require_once '../inc/global.inc.php';
if (!api_is_allowed_to_edit(false, true)) {
api_not_allowed(true);
}
$survey_id = isset($_REQUEST['survey_id']) ? intval($_REQUEST['survey_id']) : null;
if (empty($survey_id)) {
api_not_allowed(true);
}
$survey_data = survey_manager::get_survey($survey_id);
$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
$interbreadcrumb[] = array('url' => 'survey.php?survey_id='.$survey_id, 'name' => strip_tags($survey_data['title']));
Display::display_header(get_lang('Survey'), 'Survey');
if (!survey_manager::survey_generation_hash_available()) {
api_not_allowed(true);
}
$link = survey_manager::generate_survey_link($survey_id, api_get_course_int_id(), api_get_session_id(), api_get_group_id());
echo '<div class="row">';
echo '<div class="span12" style="text-align:center">';
echo Display::url(get_lang('GenerateSurveyLink'), $link, array('class' => 'btn btn-primary btn-large'));
echo '</div>';
echo '<div class="span12">';
echo get_lang('GenerateSurveyLinkExplanation');
echo '</div>';
echo '</div>';

@ -0,0 +1,49 @@
<?php
require_once '../inc/global.inc.php';
if (!api_is_allowed_to_edit(false, true)) {
api_not_allowed(true);
}
$survey_id = isset($_REQUEST['l']) ? intval($_REQUEST['l']) : null;
if (empty($survey_id)) {
api_not_allowed(true);
}
//Display::display_header(get_lang('Survey'), 'Survey');
if (!survey_manager::survey_generation_hash_available()) {
api_not_allowed(true);
}
$course_info = api_get_course_info_by_id($_REQUEST['c']);
$hash_is_valid = survey_manager::validate_survey_hash($_REQUEST['l'], $_REQUEST['c'], $_REQUEST['s'], $_REQUEST['g'], $_REQUEST['h']);
if ($hash_is_valid && $course_info) {
$survey_data = survey_manager::get_survey($survey_id, null, $course_info['code']);
$invitation_code = api_get_unique_id();
$params = array(
'c_id' => $_REQUEST['c'],
'session_id' => $_REQUEST['s'],
'user' => $invitation_code,
'survey_code' => $survey_data['code'],
'invitation_code' => $invitation_code,
'invitation_date' => api_get_utc_datetime()
);
$invitation_id = SurveyUtil::save_invitation($params);
if ($invitation_id) {
$link = api_get_path(WEB_CODE_PATH).'survey/fillsurvey.php?invitationcode='.$invitation_code.'&course='.$course_info['code'];
header('Location: '.$link);
exit;
//echo Display::url(get_lang('Go'), $link, array('class' => 'btn btn-primary btn-large'));
//echo ' '.Display::url(get_lang('Regenerate'), $link, array('class' => 'btn btn-primary btn-large'));
//echo "<pre>$link</pre>";
}
} else {
api_not_allowed(true);
}

@ -1256,6 +1256,35 @@ class survey_manager {
}
return $return;
}
static function survey_generation_hash_available() {
if (extension_loaded('mcrypt')) {
return true;
}
return false;
}
static function generate_survey_hash($survey_id, $course_id, $session_id, $group_id) {
$hash = hash('sha512', api_get_security_key().'_'.$course_id.'_'.$session_id.'_'.$group_id.'_'.$survey_id);
return $hash;
}
static function validate_survey_hash($survey_id, $course_id, $session_id, $group_id, $hash) {
$survey_generated_hash = self::generate_survey_hash($survey_id, $course_id, $session_id, $group_id);
if ($survey_generated_hash == $hash) {
return true;
}
return false;
}
static function generate_survey_link($survey_id, $course_id, $session_id, $group_id) {
$code = self::generate_survey_hash($survey_id, $course_id, $session_id, $group_id);
return api_get_path(WEB_CODE_PATH).'survey/link.php?h='.$code.'&l='.$survey_id.'&c='.intval($course_id).'&s='.intval($session_id).'&g='.$group_id;
}
static function hash_is_valid($hash) {
}
}
@ -3767,7 +3796,7 @@ class SurveyUtil {
$sql = "UPDATE $table_survey SET mail_subject='".Database::escape_string($mail_subject)."', $mail_field = '".Database::escape_string($mailtext)."'
WHERE c_id = $course_id AND survey_id = '".Database::escape_string($_GET['survey_id'])."'";
$result = Database::query($sql);
Database::query($sql);
}
/**
@ -3780,6 +3809,7 @@ class SurveyUtil {
* The text has to contain a **link** string or this will automatically be added to the end
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @author Julio Montoya - Adding auto-generated link support
* @version January 2007
*
*/
@ -3788,8 +3818,7 @@ class SurveyUtil {
if (!is_array($users_array)) return 0; // Should not happen
// Getting the survey information
$survey_data = survey_manager::get_survey($_GET['survey_id']);
// Database table to store the invitations data
$table_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
$survey_invitations = SurveyUtil::get_invitations($survey_data['survey_code']);
$already_invited = SurveyUtil::get_invited_users($survey_data['code']);
@ -3804,6 +3833,8 @@ class SurveyUtil {
$counter = 0; // Nr of invitations "sent" (if sendmail option)
$course_id = api_get_course_int_id();
$session_id = api_get_session_id();
foreach ($users_array as $key=>$value) {
if (!isset($value) || $value == '') continue;
// Skip user if reminding only unanswered people
@ -3822,9 +3853,15 @@ class SurveyUtil {
if ((is_numeric($value) && !in_array($value, $my_alredy_invited)) || (!is_numeric($value) && !in_array($value, $addit_users_array))) {
$new_user = true;
if (!array_key_exists($value, $survey_invitations)) {
$sql = "INSERT INTO $table_survey_invitation (c_id, user, survey_code, invitation_code, invitation_date) VALUES
($course_id, '".Database::escape_string($value)."','".Database::escape_string($survey_data['code'])."','".Database::escape_string($invitation_code)."','".Database::escape_string(date('Y-m-d H:i:s'))."')";
Database::query($sql);
$params = array(
'c_id' => $course_id,
'session_id' => $session_id,
'user' => $value,
'survey_code' => $survey_data['code'],
'invitation_code' => $invitation_code,
'invitation_date' => api_get_utc_datetime()
);
self::save_invitation($params);
}
}
// Send the email if checkboxed
@ -3842,6 +3879,16 @@ class SurveyUtil {
return $counter; // Number of invitations sent
}
static function save_invitation($params) {
// Database table to store the invitations data
$table_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
if (!empty($params['c_id']) && !empty($params['user']) && !empty($params['survey_code'])) {
return Database::insert($table_survey_invitation, $params);
}
return false;
}
/**
* Send the invitation by mail.
*
@ -4163,7 +4210,11 @@ class SurveyUtil {
// Coach can see that only if the survey is in his session
if (api_is_allowed_to_edit() || api_is_element_in_the_session(TOOL_SURVEY, $survey_id)) {
$return .= '<a href="create_new_survey.php?'.api_get_cidreq().'&amp;action=edit&amp;survey_id='.$survey_id.'">'.Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>';
$return .= '<a href="survey_list.php?'.api_get_cidreq().'&amp;action=empty&amp;survey_id='.$survey_id.'" onclick="javascript: if(!confirm(\''.addslashes(api_htmlentities(get_lang("EmptySurvey").'?')).'\')) return false;">'.Display::return_icon('clean.png', get_lang('EmptySurvey'),'',ICON_SIZE_SMALL).'</a>&nbsp;';
if (survey_manager::survey_generation_hash_available()) {
$return .= Display::url(Display::return_icon('new_link.png', get_lang('Newlink'),'',ICON_SIZE_SMALL), 'generate_link.php?survey_id='.$survey_id.'&'.api_get_cidreq());
}
$return .= ' <a href="survey_list.php?'.api_get_cidreq().'&amp;action=empty&amp;survey_id='.$survey_id.'" onclick="javascript: if(!confirm(\''.addslashes(api_htmlentities(get_lang("EmptySurvey").'?')).'\')) return false;">'.Display::return_icon('clean.png', get_lang('EmptySurvey'),'',ICON_SIZE_SMALL).'</a>&nbsp;';
}
//$return .= '<a href="create_survey_in_another_language.php?id_survey='.$survey_id.'">'.Display::return_icon('copy.gif', get_lang('Copy')).'</a>';
//$return .= '<a href="survey.php?survey_id='.$survey_id.'">'.Display::return_icon('add.gif', get_lang('Add')).'</a>';
@ -4727,5 +4778,4 @@ class SurveyUtil {
return false;
}
}
}
}

@ -63,14 +63,6 @@ if (isset($_GET['survey_id'])) {
$tool_name = strip_tags($survey_data['title']);
/*
if (api_substr($survey_data['title'], 0, 3) != '<p>') {
$tool_name = strip_tags(api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40));
} else {
$tool_name = strip_tags(api_substr(api_html_entity_decode(api_substr($survey_data['title'], 3, -4), ENT_QUOTES), 0, 40));
}*/
$is_survey_type_1 = $survey_data['survey_type'] == 1;
if (api_strlen(strip_tags($survey_data['title'])) > 40) {

Loading…
Cancel
Save