survey_invite.php 7.5 KB

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