PageRenderTime 56ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/chamilo/chamilo-app-survey/
PHP | 138 lines | 111 code | 26 blank | 1 comment | 4 complexity | 8a2eb293d61cb36060998d823116c3b4 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. $this->addElement('checkbox', SurveyRights :: PARTICIPATE_RIGHT_NAME, Translation :: get('Invitees'), ' ' . $users[SurveyRights :: PARTICIPATE_RIGHT_NAME] . ' ' . Translation :: get('Invitees'));
  64. $this->addElement('checkbox', SurveyParticipantTracker :: STATUS_NOTSTARTED, Translation :: get('SurveyNotStarted'), ' ' . $users[SurveyParticipantTracker :: STATUS_NOTSTARTED] . ' ' . Translation :: get('Participants'));
  65. $this->addElement('checkbox', SurveyParticipantTracker :: STATUS_STARTED, Translation :: get('SurveyStarted'), ' ' . $users[SurveyParticipantTracker :: STATUS_STARTED] . ' ' . Translation :: get('Participants'));
  66. $this->addElement('checkbox', SurveyParticipantTracker :: STATUS_FINISHED, Translation :: get('SurveyFinished'), ' ' . $users[SurveyParticipantTracker :: STATUS_FINISHED] . ' ' . Translation :: get('Participants'));
  67. break;
  68. case SurveyMailManager :: MAIL_EXPORT_TYPE :
  69. $this->addElement('checkbox', SurveyRights :: EXPORT_RESULT_RIGHT_NAME, Translation :: get('Invitees'), ' ' . $users[SurveyRights :: EXPORT_RESULT_RIGHT_NAME] . ' ' . Translation :: get('Invitees'));
  70. break;
  71. case SurveyMailManager :: MAIL_REPORTING_TYPE :
  72. $this->addElement('checkbox', SurveyRights :: REPORTING_RIGHT_NAME, Translation :: get('Invitees'), ' ' . $users[SurveyRights :: REPORTING_RIGHT_NAME] . ' ' . Translation :: get('Invitees'));
  73. break;
  74. }
  75. $buttons[] = $this->createElement('style_submit_button', 'submit', Translation :: get('SendMail'), array(
  76. 'class' => 'positive publish'));
  77. $buttons[] = $this->createElement('style_reset_button', 'reset', Translation :: get('Reset'), array(
  78. 'class' => 'normal empty'));
  79. $this->addGroup($buttons, 'buttons', null, '&nbsp;', false);
  80. $this->setDefaults($defaults);
  81. }
  82. function get_seleted_group_user_ids()
  83. {
  84. $values = $this->exportValues();
  85. $user_ids = array();
  86. if ($values[self :: APPLICATION_NAME . '_opt_' . self :: PARAM_TARGET_OPTION] == 0)
  87. {
  88. //there is no user filter needed
  89. $user_ids = null;
  90. }
  91. else
  92. {
  93. $group_ids = $values[self :: APPLICATION_NAME . '_opt_' . self :: PARAM_TARGET . '_elements']['group'];
  94. if (count($group_ids))
  95. {
  96. foreach ($group_ids as $group_id)
  97. {
  98. $group_user_ids = array();
  99. foreach ($group_ids as $group_id)
  100. {
  101. $group = GroupDataManager :: get_instance()->retrieve_group($group_id);
  102. $ids = $group->get_users(true, true);
  103. $group_user_ids = array_merge($group_user_ids, $ids);
  104. }
  105. $user_ids = array_unique($group_user_ids);
  106. }
  107. }
  108. }
  109. return $user_ids;
  110. }
  111. }
  112. ?>