survey_invite.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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); // TODO: To be checked. TABLE_MAIN_SURVEY_REMINDER has not been defined.
  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(api_substr(api_html_entity_decode($survey_data['title'],ENT_QUOTES,$charset), 0, 40));
  62. if (api_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'], '', api_sort_by_first_name() ? 'ORDER BY firstname' : 'ORDER BY lastname');
  98. $possible_users = array ();
  99. foreach ($complete_user_list as $index => $user)
  100. {
  101. $possible_users[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']);
  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. $form->addElement('html_editor', 'mail_text', get_lang('MailText'), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '150'));
  124. // some explanation of the mail
  125. $form->addElement('static', null, null, get_lang('UseLinkSyntax'));
  126. $form->addElement('checkbox', 'send_mail', '', get_lang('SendMail'));
  127. // you cab send a reminder to unanswered people if the survey is not anonymous
  128. if ($survey_data['anonymous'] != 1) {
  129. $form->addElement('checkbox', 'remindUnAnswered', '', get_lang('RemindUnanswered'));
  130. }
  131. // allow resending to all selected users
  132. $form->addElement('checkbox', 'resend_to_all', '', get_lang('ReminderResendToAllUsers'));
  133. // submit button
  134. $form->addElement('style_submit_button', 'submit', get_lang('PublishSurvey'), 'class="save"');
  135. // The rules (required fields)
  136. $form->addRule('mail_title', get_lang('ThisFieldIsRequired'), 'required');
  137. $form->addRule('mail_text', get_lang('ThisFieldIsRequired'), 'required');
  138. $portal_url = $_configuration['root_web'];
  139. if ($_configuration['multiple_access_urls']==true) {
  140. $access_url_id = api_get_current_access_url_id();
  141. if ($access_url_id != -1 ){
  142. $url = api_get_access_url($access_url_id);
  143. $portal_url = $url['url'];
  144. }
  145. }
  146. // show the URL that can be used by users to fill a survey without invitation
  147. $auto_survey_link = $portal_url.$_configuration['code_append'].
  148. 'survey/'.'fillsurvey.php?course='.$_course['sysCode'].
  149. '&invitationcode=auto&scode='.$survey_data['survey_code'];
  150. $form->addElement('static',null, null, '<br \><br \>' . get_lang('AutoInviteLink'));
  151. $form->addElement('static',null, null, $auto_survey_link);
  152. if ($form->validate())
  153. {
  154. $values = $form->exportValues();
  155. // save the invitation mail
  156. SurveyUtil::save_invite_mail($values['mail_text'], $values['mail_title'], !empty($survey_data['invite_mail']));
  157. // saving the invitations for the course users
  158. $count_course_users = SurveyUtil::save_invitations($values['course_users'], $values['mail_title'],
  159. $values['mail_text'], $values['resend_to_all'], $values['send_mail'], $values['remindUnAnswered']);
  160. // saving the invitations for the additional users
  161. $values['additional_users'] = $values['additional_users'].';'; // this is for the case when you enter only one email
  162. $temp = str_replace(',',';',$values['additional_users']); // this is to allow , and ; as email separators
  163. $additional_users = explode(';',$temp);
  164. for($i=0; $i<count($additional_users); $i++)
  165. {
  166. $additional_users[$i] = trim($additional_users[$i]);
  167. }
  168. $counter_additional_users = SurveyUtil::save_invitations($additional_users, $values['mail_title'],
  169. $values['mail_text'], $values['resend_to_all'], $values['send_mail'], $values['remindUnAnswered']);
  170. // updating the invited field in the survey table
  171. SurveyUtil::update_count_invited($survey_data['code']);
  172. $total_count = $count_course_users + $counter_additional_users;
  173. Display :: display_confirmation_message($total_count.' '.get_lang('InvitationsSend'));
  174. }
  175. else
  176. {
  177. // getting the invited users
  178. $defaults = SurveyUtil::get_invited_users($survey_data['code']);
  179. // getting the survey mail text
  180. if (!empty($survey_data['reminder_mail']))
  181. {
  182. $defaults['mail_text'] = $survey_data['reminder_mail'];
  183. }
  184. else
  185. {
  186. $defaults['mail_text'] = $survey_data['invite_mail'];
  187. }
  188. $defaults['mail_title'] = $survey_data['mail_subject'];
  189. $defaults['send_mail'] = 1;
  190. $form->setDefaults($defaults);
  191. $form->display();
  192. }
  193. // Footer
  194. Display :: display_footer();
  195. ?>