[svn r17572] FS#3403 - New Survey Feature: Surveys without invitation mail.

skala
Jan Derriks 17 years ago
parent 1c96bdcf3f
commit c726c73eb9
  1. 1
      main/lang/english/survey.inc.php
  2. 76
      main/survey/fillsurvey.php
  3. 6
      main/survey/survey_invite.php
  4. 9
      main/survey/survey_list.php

@ -203,4 +203,5 @@ $ChooseDifferentCategories = "Choose different categories";
$Version = "Version";
$Normal = "Normal";
$NoLogOfDuration = "No log of duration";
$AutoInviteLink = "Users who are not invited can use this link to do the survey:";
?>

@ -56,7 +56,7 @@ require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php');
// breadcrumbs
if (!empty ($_user))
{
$interbreadcrumb[] = array ("url" => 'survey_list.php','name' => get_lang('SurveyList'));
$interbreadcrumb[] = array ("url" => 'survey_list.php?cidReq='.$_GET['course'],'name' => get_lang('SurveyList'));
}
// Header
@ -81,10 +81,42 @@ if ((!isset ($_GET['course']) || !isset ($_GET['invitationcode']))&& !isset($_GE
Display :: display_footer();
exit;
}
$invitationcode = $_GET['invitationcode'];
// start auto-invitation feature FS#3403 (all-users-can-do-the-survey-URL handling)
if ($invitationcode == "auto" && isset($_GET['scode'])){
// not intended for anonymous users
if (!(isset ($_user['user_id']) && $_user['user_id']) || api_is_anonymous($_user['user_id'],true)) {
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
$sql = "SELECT * FROM $table_survey WHERE code='" . $scode . "'";
$result = api_sql_query($sql, __FILE__, __LINE__);
if (Database :: num_rows($result) > 0){ // ok
// check availability
$row = Database :: fetch_array($result, 'ASSOC'); //
$tempdata = survey_manager :: get_survey($row['survey_id']);
check_time_availability($tempdata); //exit if survey not available anymore
// check for double invitation records (insert should be done once)
$sql = "select user from $table_survey_invitation where invitation_code = '".Database::escape_string($autoInvitationcode)."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
if (Database :: num_rows($result) == 0){ // ok
$sql = "insert into $table_survey_invitation (survey_code,user, invitation_code, invitation_date) ";
$sql .= " values (\"$scode\", \"$userid\", \"$autoInvitationcode\", now())";
api_sql_query($sql, __FILE__, __LINE__);
}
// from here we use the new invitationcode auto-userid-surveycode string
$_GET['invitationcode'] = $autoInvitationcode;
$invitationcode = $autoInvitationcode;
}
}
// end auto-invitation feature
// now we check if the invitationcode is valid
$sql = "SELECT * FROM $table_survey_invitation WHERE invitation_code = '" . Database :: escape_string($_GET['invitationcode']) . "'";
$result = api_sql_query($sql, __FILE__, __LINE__);
$sql = "SELECT * FROM $table_survey_invitation WHERE invitation_code = '" . Database :: escape_string($invitationcode) . "'";
$result = api_sql_query($sql, __FILE__, false); // false=suppress errors
if (Database :: num_rows($result) < 1)
{
Display :: display_error_message(get_lang('WrongInvitationCode'), false);
@ -261,21 +293,7 @@ echo '<div id="survey_title">' . $survey_data['survey_title'] . '</div>';
echo '<div id="survey_subtitle">' . $survey_data['survey_subtitle'] . '</div>';
// checking time availability
$start_date = mktime(0, 0, 0, substr($survey_data['start_date'], 5, 2), substr($survey_data['start_date'], 8, 2), substr($survey_data['start_date'], 0, 4));
$end_date = mktime(0, 0, 0, substr($survey_data['end_date'], 5, 2), substr($survey_data['end_date'], 8, 2), substr($survey_data['end_date'], 0, 4));
$cur_date = time();
if ($cur_date < $start_date) {
Display :: display_warning_message(get_lang('SurveyNotAvailableYet'), false);
Display :: display_footer();
exit;
}
if ($cur_date > $end_date)
{
Display :: display_warning_message(get_lang('SurveyNotAvailableAnymore'), false);
Display :: display_footer();
exit;
}
check_time_availability($survey_data);
// displaying the survey introduction
if (!isset ($_GET['show']))
@ -1290,4 +1308,26 @@ echo '</form>';
// Footer
Display :: display_footer();
/**
* Check if this survey has ended. If so, display message and exit rhis script
*/
function check_time_availability($surv_data){
$start_date = mktime(0, 0, 0, substr($surv_data['start_date'], 5, 2), substr($surv_data['start_date'], 8, 2), substr($surv_data['start_date'], 0, 4));
$end_date = mktime(0, 0, 0, substr($surv_data['end_date'], 5, 2), substr($surv_data['end_date'], 8, 2), substr($surv_data['end_date'], 0, 4));
$cur_date = time();
if ($cur_date < $start_date) {
Display :: display_warning_message(get_lang('SurveyNotAvailableYet'), false);
Display :: display_footer();
exit;
}
if ($cur_date > $end_date)
{
Display :: display_warning_message(get_lang('SurveyNotAvailableAnymore'), false);
Display :: display_footer();
exit;
}
}
?>

@ -143,6 +143,12 @@ $form->addElement('submit', 'submit', get_lang('Ok'));
// The rules (required fields)
$form->addRule('mail_title', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('mail_text', get_lang('ThisFieldIsRequired'), 'required');
// show the URL that can be used by users to fill a survey without invitation
$auto_survey_link = $_configuration['root_web'].$_configuration['code_append'].
'survey/'.'fillsurvey.php?course='.$_course['sysCode'].
'&invitationcode=auto&scode='.$survey_data['survey_code'];
$form->addElement('static',null, null, '<br \><br \>' . get_lang('AutoInviteLink'));
$form->addElement('static',null, null, $auto_survey_link);
if ($form->validate())
{
$values = $form->exportValues();

@ -1,4 +1,4 @@
<?php // $Id: survey_list.php 16890 2008-11-24 20:22:56Z yannoo $
<?php // $Id: survey_list.php 17572 2009-01-07 18:01:58Z derrj $
/*
==============================================================================
Dokeos - elearning and course management software
@ -27,14 +27,17 @@
* @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 of the code
* @author Julio Montoya Armas <gugli100@gmail.com>, Dokeos: Personality Test modification and rewriting large parts of the code
* @version $Id: survey_list.php 16890 2008-11-24 20:22:56Z yannoo $
* @version $Id: survey_list.php 17572 2009-01-07 18:01:58Z derrj $
*
* @todo use quickforms for the forms
*/
// name of the language file that needs to be included
$language_file = 'survey';
if (!isset ($_GET['cidReq'])){
$_GET['cidReq']='none'; // prevent sql errors
$cidReset = true;
}
// including the global dokeos file
require ('../inc/global.inc.php');

Loading…
Cancel
Save