PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/php/lib/forms/survey_publication_mailer_form.class.php

https://bitbucket.org/chamilo/chamilo-app-survey-dev/
PHP | 144 lines | 117 code | 26 blank | 1 comment | 4 complexity | e2cc8dbba49f72d2b50e7c6ac658d097 MD5 | raw file
  1. <?php
  2. namespace application\survey;
  3. use common\libraries\Utilities;
  4. use common\libraries\Path;
  5. use common\libraries\Translation;
  6. use common\libraries\FormValidator;
  7. use group\GroupDataManager;
  8. use user\UserDataManager;
  9. ini_set("memory_limit", "-1");
  10. ini_set("max_execution_time", "0");
  11. class SurveyPublicationMailerForm extends FormValidator
  12. {
  13. const APPLICATION_NAME = 'survey';
  14. const PARAM_TARGET = 'target_users_and_groups';
  15. const PARAM_TARGET_OPTION = 'target_users_and_groups_option';
  16. const PARAM_RIGHTS = 'rights';
  17. const ALL_PARTICIPANTS = 'all_participants';
  18. const FROM_ADDRESS = 'from_address';
  19. const FROM_ADDRESS_NAME = 'from_address_name';
  20. const REPLY_ADDRESS = 'reply_address';
  21. const REPLY_ADDRESS_NAME = 'reply_address_name';
  22. const EMAIL_HEADER = 'email_header';
  23. const EMAIL_CONTENT = 'email_content';
  24. const USERS_NOT_SELECTED_COUNT = 'users_not_selected_count';
  25. const FORM_NAME = 'survey_publication_mailer';
  26. private $type;
  27. function __construct($parent, $user, $users, $type, $actions)
  28. {
  29. parent :: __construct(self :: FORM_NAME, 'post', $actions);
  30. $this->type = $type;
  31. $attributes = array();
  32. $attributes['search_url'] = Path :: get(WEB_PATH) . 'group/php/xml_feeds/xml_group_feed.php';
  33. $locale = array();
  34. $locale['Display'] = Translation :: get('ShareWith');
  35. $locale['Searching'] = Translation :: get('Searching');
  36. $locale['NoResults'] = Translation :: get('NoResults');
  37. $locale['Error'] = Translation :: get('Error');
  38. $attributes['locale'] = $locale;
  39. $attributes['defaults'] = array();
  40. $attributes['options'] = array('load_elements' => false);
  41. $this->add_receivers(self :: APPLICATION_NAME . '_opt_' . self :: PARAM_TARGET, Translation :: get('AddMailRecipientsFilter'), $attributes);
  42. $defaults[self :: APPLICATION_NAME . '_opt_forever'] = 1;
  43. $defaults[self :: APPLICATION_NAME . '_opt_' . self :: PARAM_TARGET_OPTION] = 0;
  44. $this->addElement('text', self :: FROM_ADDRESS_NAME, Translation :: get('SurveyFromEmailAddressName'), array(
  45. 'size' => 80, 'value' => $user->get_firstname() . ' ' . $user->get_lastname()));
  46. $this->addRule(self :: FROM_ADDRESS_NAME, Translation :: get('ThisFieldIsRequired'), 'required');
  47. $this->addElement('text', self :: FROM_ADDRESS, Translation :: get('SurveyFromEmailAddress'), array(
  48. 'size' => 80, 'value' => $user->get_email()));
  49. $this->addRule(self :: FROM_ADDRESS, Translation :: get('ThisFieldIsRequired'), 'required');
  50. $this->addElement('text', self :: REPLY_ADDRESS_NAME, Translation :: get('SurveyReplyEmailAddressName'), array(
  51. 'size' => 80, 'value' => $user->get_firstname() . ' ' . $user->get_lastname()));
  52. $this->addRule(self :: REPLY_ADDRESS_NAME, Translation :: get('ThisFieldIsRequired'), 'required');
  53. $this->addElement('text', self :: REPLY_ADDRESS, Translation :: get('SurveyReplyEmailAddress'), array(
  54. 'size' => 80, 'value' => $user->get_email()));
  55. $this->addRule(self :: REPLY_ADDRESS, Translation :: get('ThisFieldIsRequired'), 'required');
  56. $this->addElement('text', self :: EMAIL_HEADER, Translation :: get('SurveyEmailTitle'), array('size' => 80));
  57. $this->addRule(self :: EMAIL_HEADER, Translation :: get('ThisFieldIsRequired'), 'required');
  58. $this->add_html_editor(self :: EMAIL_CONTENT, Translation :: get('SurveyEmailContent'), true);
  59. $this->add_warning_message('attention', Translation :: get('SurveyMailAttention'), Translation :: get('SurveyAttentionSendMailInfo'), false);
  60. switch ($this->type)
  61. {
  62. case SurveyMailManager :: MAIL_PARTICIPANT_TYPE :
  63. $invitees = (count($users[SurveyRights :: PARTICIPATE_RIGHT_NAME]) > 1) ? Translation :: get('Invitees') : Translation :: get('Invitee');
  64. $this->addElement('checkbox', SurveyRights :: PARTICIPATE_RIGHT_NAME, Translation :: get('AllInvitees'), ' ' . $users[SurveyRights :: PARTICIPATE_RIGHT_NAME] . ' ' . $invitees);
  65. $not_started = (count($users[SurveyParticipantTracker :: STATUS_NOTSTARTED]) > 1) ? Translation :: get('Invitees') : Translation :: get('Invitee');
  66. $this->addElement('checkbox', SurveyParticipantTracker :: STATUS_NOTSTARTED, Translation :: get('SurveyNotStarted'), ' ' . $users[SurveyParticipantTracker :: STATUS_NOTSTARTED] . ' ' . $not_started);
  67. $started = (count($users[SurveyParticipantTracker :: STATUS_STARTED]) > 1) ? Translation :: get('Participants') : Translation :: get('Participant');
  68. $this->addElement('checkbox', SurveyParticipantTracker :: STATUS_STARTED, Translation :: get('SurveyStarted'), ' ' . $users[SurveyParticipantTracker :: STATUS_STARTED] . ' ' . $started);
  69. $finished = (count($users[SurveyParticipantTracker :: STATUS_FINISHED]) > 1) ? Translation :: get('Participants') : Translation :: get('Participant');
  70. $this->addElement('checkbox', SurveyParticipantTracker :: STATUS_FINISHED, Translation :: get('SurveyFinished'), ' ' . $users[SurveyParticipantTracker :: STATUS_FINISHED] . ' ' . $finished);
  71. break;
  72. case SurveyMailManager :: MAIL_EXPORT_TYPE :
  73. $exporters = (count($users[SurveyRights :: EXPORT_RESULT_RIGHT_NAME]) > 1) ? Translation :: get('Exporters') : Translation :: get('Exporter');
  74. $this->addElement('checkbox', SurveyRights :: EXPORT_RESULT_RIGHT_NAME, Translation :: get('SurveyExporters'), ' ' . $users[SurveyRights :: EXPORT_RESULT_RIGHT_NAME] . ' ' . $exporters);
  75. break;
  76. case SurveyMailManager :: MAIL_REPORTING_TYPE :
  77. $rapporteurs = (count($users[SurveyRights :: REPORTING_RIGHT_NAME]) > 1) ? Translation :: get('Rapporteurs') : Translation :: get('Rapporteur');
  78. $this->addElement('checkbox', SurveyRights :: REPORTING_RIGHT_NAME, Translation :: get('SurveyRapporters'), ' ' . $users[SurveyRights :: REPORTING_RIGHT_NAME] . ' ' . $rapporteurs);
  79. break;
  80. }
  81. $buttons[] = $this->createElement('style_submit_button', 'submit', Translation :: get('SendMail', null, Utilities :: COMMON_LIBRARIES), array(
  82. 'class' => 'positive publish'));
  83. $buttons[] = $this->createElement('style_reset_button', 'reset', Translation :: get('Reset', null, Utilities :: COMMON_LIBRARIES), array(
  84. 'class' => 'normal empty'));
  85. $this->addGroup($buttons, 'buttons', null, '&nbsp;', false);
  86. $this->setDefaults($defaults);
  87. }
  88. function get_seleted_group_user_ids()
  89. {
  90. $values = $this->exportValues();
  91. $user_ids = array();
  92. if ($values[self :: APPLICATION_NAME . '_opt_' . self :: PARAM_TARGET_OPTION] == 0)
  93. {
  94. //there is no user filter needed
  95. $user_ids = null;
  96. }
  97. else
  98. {
  99. $group_ids = $values[self :: APPLICATION_NAME . '_opt_' . self :: PARAM_TARGET . '_elements']['group'];
  100. if (count($group_ids))
  101. {
  102. foreach ($group_ids as $group_id)
  103. {
  104. $group_user_ids = array();
  105. foreach ($group_ids as $group_id)
  106. {
  107. $group = GroupDataManager :: get_instance()->retrieve_group($group_id);
  108. $ids = $group->get_users(true, true);
  109. $group_user_ids = array_merge($group_user_ids, $ids);
  110. }
  111. $user_ids = array_unique($group_user_ids);
  112. }
  113. }
  114. }
  115. return $user_ids;
  116. }
  117. }
  118. ?>