survey_invite.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2008 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
  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. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  39. if (!api_is_allowed_to_edit())
  40. {
  41. Display :: display_header(get_lang('Survey'));
  42. Display :: display_error_message(get_lang('NotAllowed'), false);
  43. Display :: display_footer();
  44. exit;
  45. }
  46. // Database table definitions
  47. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  48. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  49. $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  50. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  51. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  52. $user_info = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER);
  53. // getting the survey information
  54. $survey_data = survey_manager::get_survey($_GET['survey_id']);
  55. $urlname =substr(html_entity_decode($survey_data['title'],ENT_QUOTES,$charset), 0, 40);
  56. if (strlen(strip_tags($survey_data['title'])) > 40)
  57. {
  58. $urlname .= '...';
  59. }
  60. // breadcrumbs
  61. $interbreadcrumb[] = array ('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
  62. $interbreadcrumb[] = array ('url' => 'survey.php?survey_id='.$_GET['survey_id'], 'name' => $urlname);
  63. $tool_name = get_lang('SurveyPublication');
  64. // Displaying the header
  65. Display::display_header($tool_name,'Survey');
  66. // checking if there is another survey with this code.
  67. // If this is the case there will be a language choice
  68. $sql = "SELECT * FROM $table_survey WHERE code='".Database::escape_string($survey_data['code'])."'";
  69. $result = api_sql_query($sql, __FILE__, __LINE__);
  70. if (mysql_num_rows($result) > 1)
  71. {
  72. Display::display_warning_message(get_lang('IdenticalSurveycodeWarning'));
  73. }
  74. // invited / answered message
  75. if ($survey_data['invited'] > 0)
  76. {
  77. $message = '<a href="survey_invitation.php?view=answered&amp;survey_id='.$survey_data['survey_id'].'">'.$survey_data['answered'].'</a> ';
  78. $message .= get_lang('HaveAnswered').' ';
  79. $message .= '<a href="survey_invitation.php?view=invited&amp;survey_id='.$survey_data['survey_id'].'">'.$survey_data['invited'].'</a> ';
  80. $message .= get_lang('WereInvited');
  81. Display::display_normal_message($message, false);
  82. }
  83. // building the form for publishing the survey
  84. $form = new FormValidator('publish_form','post', api_get_self().'?survey_id='.$_GET['survey_id']);
  85. // Course users
  86. $complete_user_list = CourseManager :: get_user_list_from_course_code($_course['id'], true, $_SESSION['id_session']);
  87. $possible_users = array ();
  88. foreach ($complete_user_list as $index => $user)
  89. {
  90. $possible_users[$user['user_id']] = $user['lastname'].' '.$user['firstname'];
  91. }
  92. $users = $form->addElement('advmultiselect', 'course_users', get_lang('CourseUsers'), $possible_users, 'style="width: 250px; height: 200px;"');
  93. $users->setElementTemplate('
  94. {javascript}
  95. <table{class}>
  96. <!-- BEGIN label_2 --><tr><th>{label_2}</th><!-- END label_2 -->
  97. <!-- BEGIN label_3 --><th>&nbsp;</th><th>{label_3}</th></tr><!-- END label_3 -->
  98. <tr>
  99. <td valign="top">{unselected}</td>
  100. <td align="center">{add}<br /><br />{remove}</td>
  101. <td valign="top">{selected}</td>
  102. </tr>
  103. </table>
  104. ');
  105. // additional users
  106. $form->addElement('textarea', 'additional_users', get_lang('AdditonalUsers'), array ('cols' => 50, 'rows' => 2));
  107. // additional users comment
  108. $form->addElement('static', null, null, get_lang('AdditonalUsersComment'));
  109. // the title of the mail
  110. $form->addElement('text', 'mail_title', get_lang('MailTitle'),array('size' => '80'));
  111. // the text of the mail
  112. $fck_attribute['Width'] = '100%';
  113. $fck_attribute['Height'] = '150';
  114. $fck_attribute['ToolbarSet'] = 'Survey';
  115. $form->addElement('html_editor', 'mail_text', get_lang('MailText'));
  116. // some explanation of the mail
  117. $form->addElement('static', null, null, get_lang('UseLinkSyntax'));
  118. $form->addElement('checkbox', 'send_mail', '', get_lang('SendMail'));
  119. // allow resending to all selected users
  120. $form->addElement('checkbox', 'resend_to_all', '', get_lang('ReminderResendToAllUsers'));
  121. // submit button
  122. $form->addElement('submit', 'submit', get_lang('Ok'));
  123. // The rules (required fields)
  124. $form->addRule('mail_title', get_lang('ThisFieldIsRequired'), 'required');
  125. $form->addRule('mail_text', get_lang('ThisFieldIsRequired'), 'required');
  126. if ($form->validate())
  127. {
  128. $values = $form->exportValues();
  129. // save the invitation mail
  130. SurveyUtil::save_invite_mail($values['mail_text'], $values['mail_title'], !empty($survey_data['invite_mail']));
  131. // saving the invitations for the course users
  132. $count_course_users = SurveyUtil::save_invitations($values['course_users'], $values['mail_title'], $values['mail_text'], $values['resend_to_all'], $values['send_mail']);
  133. // saving the invitations for the additional users
  134. $values['additional_users'] = $values['additional_users'].';'; // this is for the case when you enter only one email
  135. $temp = str_replace(',',';',$values['additional_users']); // this is to allow , and ; as email separators
  136. $additional_users = explode(';',$temp);
  137. for($i=0; $i<count($additional_users); $i++)
  138. {
  139. $additional_users[$i] = trim($additional_users[$i]);
  140. }
  141. $counter_additional_users = SurveyUtil::save_invitations($additional_users, $values['mail_title'], $values['mail_text'], $values['resend_to_all'], $values['send_mail']);
  142. // updating the invited field in the survey table
  143. SurveyUtil::update_count_invited($survey_data['code']);
  144. $total_count = $count_course_users + $counter_additional_users;
  145. Display :: display_confirmation_message($total_count.' '.get_lang('InvitationsSend'), false);
  146. }
  147. else
  148. {
  149. // getting the invited users
  150. $defaults = SurveyUtil::get_invited_users($survey_data['code']);
  151. // getting the survey mail text
  152. if (!empty($survey_data['reminder_mail']))
  153. {
  154. $defaults['mail_text'] = $survey_data['reminder_mail'];
  155. }
  156. else
  157. {
  158. $defaults['mail_text'] = $survey_data['invite_mail'];
  159. }
  160. $defaults['mail_title'] = $survey_data['mail_subject'];
  161. $defaults['send_mail'] = 1;
  162. $form->setDefaults($defaults);
  163. $form->display();
  164. }
  165. // Footer
  166. Display :: display_footer();
  167. ?>