survey_invite.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2009 Dokeos SPRL
  6. For a full list of contributors, see "credits.txt".
  7. The full license can be read in "license.txt".
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License
  10. as published by the Free Software Foundation; either version 2
  11. of the License, or (at your option) any later version.
  12. See the GNU General Public License for more details.
  13. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  14. Mail: info@dokeos.com
  15. ==============================================================================
  16. */
  17. /**
  18. * @package dokeos.survey
  19. * @author unknown, the initial survey that did not make it in 1.8 because of bad code
  20. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
  21. * @author Julio Montoya Dokeos: cleanup, refactoring, security improvements
  22. * @version $Id: survey_invite.php 10680 2007-01-11 21:26:23Z pcool $
  23. *
  24. * @todo checking if the additional emails are valid (or add a rule for this)
  25. * @todo check if the mailtext contains the **link** part, if not, add the link to the end
  26. * @todo add rules: title and text cannot be empty
  27. */
  28. // name of the language file that needs to be included
  29. $language_file = 'survey';
  30. // including the global dokeos file
  31. require ('../inc/global.inc.php');
  32. // including additional libraries
  33. //require_once (api_get_path(LIBRARY_PATH)."/survey.lib.php");
  34. require_once('survey.lib.php');
  35. require_once (api_get_path(LIBRARY_PATH)."course.lib.php");
  36. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  37. require_once (api_get_path(LIBRARY_PATH)."mail.lib.inc.php");
  38. if (!api_is_allowed_to_edit(false,true))
  39. {
  40. Display :: display_header(get_lang('Survey'));
  41. Display :: display_error_message(get_lang('NotAllowed'), false);
  42. Display :: display_footer();
  43. exit;
  44. }
  45. // Database table definitions
  46. $table_survey = Database::get_course_table(TABLE_SURVEY);
  47. $table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
  48. $table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  49. $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
  50. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  51. $user_info = Database::get_main_table(TABLE_MAIN_SURVEY_REMINDER);
  52. // getting the survey information
  53. $survey_id = Security::remove_XSS($_GET['survey_id']);
  54. $survey_data = survey_manager::get_survey($survey_id);
  55. if (empty($survey_data)) {
  56. Display :: display_header(get_lang('Survey'));
  57. Display :: display_error_message(get_lang('InvallidSurvey'), false);
  58. Display :: display_footer();
  59. exit;
  60. }
  61. $urlname =strip_tags(substr(html_entity_decode($survey_data['title'],ENT_QUOTES,$charset), 0, 40));
  62. if (strlen(strip_tags($survey_data['title'])) > 40)
  63. {
  64. $urlname .= '...';
  65. }
  66. // breadcrumbs
  67. $interbreadcrumb[] = array ('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
  68. if (api_is_course_admin()) {
  69. $interbreadcrumb[] = array ('url' => 'survey.php?survey_id='.$survey_id, 'name' => $urlname);
  70. } else {
  71. $interbreadcrumb[] = array ('url' => 'survey_invite.php?survey_id='.$survey_id, 'name' => $urlname);
  72. }
  73. $tool_name = get_lang('SurveyPublication');
  74. // Displaying the header
  75. Display::display_header($tool_name,'Survey');
  76. // checking if there is another survey with this code.
  77. // If this is the case there will be a language choice
  78. $sql = "SELECT * FROM $table_survey WHERE code='".Database::escape_string($survey_data['code'])."'";
  79. $result = api_sql_query($sql, __FILE__, __LINE__);
  80. if (Database::num_rows($result) > 1)
  81. {
  82. Display::display_warning_message(get_lang('IdenticalSurveycodeWarning'));
  83. }
  84. // invited / answered message
  85. if ($survey_data['invited'] > 0)
  86. {
  87. $message = '<a href="survey_invitation.php?view=answered&amp;survey_id='.$survey_data['survey_id'].'">'.$survey_data['answered'].'</a> ';
  88. $message .= get_lang('HaveAnswered').' ';
  89. $message .= '<a href="survey_invitation.php?view=invited&amp;survey_id='.$survey_data['survey_id'].'">'.$survey_data['invited'].'</a> ';
  90. $message .= get_lang('WereInvited');
  91. Display::display_normal_message($message, false);
  92. }
  93. // building the form for publishing the survey
  94. $form = new FormValidator('publish_form','post', api_get_self().'?survey_id='.$survey_id);
  95. $form->addElement('header', '', $tool_name);
  96. // Course users
  97. $complete_user_list = CourseManager :: get_user_list_from_course_code($_course['id'], true, $_SESSION['id_session'], '', 'ORDER BY lastname');
  98. $possible_users = array ();
  99. foreach ($complete_user_list as $index => $user)
  100. {
  101. $possible_users[$user['user_id']] = $user['lastname'].' '.$user['firstname'];
  102. }
  103. $users = $form->addElement('advmultiselect', 'course_users', get_lang('CourseUsers'), $possible_users, 'style="width: 250px; height: 200px;"');
  104. $users->setElementTemplate('
  105. {javascript}
  106. <table{class}>
  107. <!-- BEGIN label_2 --><tr><th>{label_2}</th><!-- END label_2 -->
  108. <!-- BEGIN label_3 --><th>&nbsp;</th><th>{label_3}</th></tr><!-- END label_3 -->
  109. <tr>
  110. <td valign="top">{unselected}</td>
  111. <td align="center">{add}<br /><br />{remove}</td>
  112. <td valign="top">{selected}</td>
  113. </tr>
  114. </table>
  115. ');
  116. // additional users
  117. $form->addElement('textarea', 'additional_users', get_lang('AdditonalUsers'), array ('cols' => 50, 'rows' => 2));
  118. // additional users comment
  119. $form->addElement('static', null, null, get_lang('AdditonalUsersComment'));
  120. // the title of the mail
  121. $form->addElement('text', 'mail_title', get_lang('MailTitle'),array('size' => '80'));
  122. // the text of the mail
  123. $fck_attribute['Width'] = '100%';
  124. $fck_attribute['Height'] = '150';
  125. $fck_attribute['ToolbarSet'] = 'Survey';
  126. $form->addElement('html_editor', 'mail_text', get_lang('MailText'));
  127. // some explanation of the mail
  128. $form->addElement('static', null, null, get_lang('UseLinkSyntax'));
  129. $form->addElement('checkbox', 'send_mail', '', get_lang('SendMail'));
  130. // you cab send a reminder to unanswered people if the survey is not anonymous
  131. if ($survey_data['anonymous'] != 1) {
  132. $form->addElement('checkbox', 'remindUnAnswered', '', get_lang('RemindUnanswered'));
  133. }
  134. // allow resending to all selected users
  135. $form->addElement('checkbox', 'resend_to_all', '', get_lang('ReminderResendToAllUsers'));
  136. // submit button
  137. $form->addElement('style_submit_button', 'submit', get_lang('PublishSurvey'), 'class="save"');
  138. // The rules (required fields)
  139. $form->addRule('mail_title', get_lang('ThisFieldIsRequired'), 'required');
  140. $form->addRule('mail_text', get_lang('ThisFieldIsRequired'), 'required');
  141. $portal_url = $_configuration['root_web'];
  142. if ($_configuration['multiple_access_urls']==true) {
  143. $access_url_id = api_get_current_access_url_id();
  144. if ($access_url_id != -1 ){
  145. $url = api_get_access_url($access_url_id);
  146. $portal_url = $url['url'];
  147. }
  148. }
  149. // show the URL that can be used by users to fill a survey without invitation
  150. $auto_survey_link = $portal_url.$_configuration['code_append'].
  151. 'survey/'.'fillsurvey.php?course='.$_course['sysCode'].
  152. '&invitationcode=auto&scode='.$survey_data['survey_code'];
  153. $form->addElement('static',null, null, '<br \><br \>' . get_lang('AutoInviteLink'));
  154. $form->addElement('static',null, null, $auto_survey_link);
  155. if ($form->validate())
  156. {
  157. $values = $form->exportValues();
  158. // save the invitation mail
  159. SurveyUtil::save_invite_mail($values['mail_text'], $values['mail_title'], !empty($survey_data['invite_mail']));
  160. // saving the invitations for the course users
  161. $count_course_users = SurveyUtil::save_invitations($values['course_users'], $values['mail_title'],
  162. $values['mail_text'], $values['resend_to_all'], $values['send_mail'], $values['remindUnAnswered']);
  163. // saving the invitations for the additional users
  164. $values['additional_users'] = $values['additional_users'].';'; // this is for the case when you enter only one email
  165. $temp = str_replace(',',';',$values['additional_users']); // this is to allow , and ; as email separators
  166. $additional_users = explode(';',$temp);
  167. for($i=0; $i<count($additional_users); $i++)
  168. {
  169. $additional_users[$i] = trim($additional_users[$i]);
  170. }
  171. $counter_additional_users = SurveyUtil::save_invitations($additional_users, $values['mail_title'],
  172. $values['mail_text'], $values['resend_to_all'], $values['send_mail'], $values['remindUnAnswered']);
  173. // updating the invited field in the survey table
  174. SurveyUtil::update_count_invited($survey_data['code']);
  175. $total_count = $count_course_users + $counter_additional_users;
  176. Display :: display_confirmation_message($total_count.' '.get_lang('InvitationsSend'));
  177. }
  178. else
  179. {
  180. // getting the invited users
  181. $defaults = SurveyUtil::get_invited_users($survey_data['code']);
  182. // getting the survey mail text
  183. if (!empty($survey_data['reminder_mail']))
  184. {
  185. $defaults['mail_text'] = $survey_data['reminder_mail'];
  186. }
  187. else
  188. {
  189. $defaults['mail_text'] = $survey_data['invite_mail'];
  190. }
  191. $defaults['mail_title'] = $survey_data['mail_subject'];
  192. $defaults['send_mail'] = 1;
  193. $form->setDefaults($defaults);
  194. $form->display();
  195. }
  196. // Footer
  197. Display :: display_footer();
  198. ?>