PageRenderTime 272ms CodeModel.GetById 120ms app.highlight 10ms RepoModel.GetById 131ms app.codeStats 7ms

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