chamilo-app-survey /php/lib/forms/survey_publication_mailer_form.class.php

Language PHP Lines 138
MD5 Hash 8a2eb293d61cb36060998d823116c3b4 Estimated Cost $2,636 (why?)
Repository https://bitbucket.org/chamilo/chamilo-app-survey/ View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
namespace application\survey;

use common\libraries\Utilities;
use common\libraries\Path;
use common\libraries\Translation;
use common\libraries\FormValidator;
use group\GroupDataManager;
use user\UserDataManager;

ini_set("memory_limit", "-1");
ini_set("max_execution_time", "0");

class SurveyPublicationMailerForm extends FormValidator
{
    
    const APPLICATION_NAME = 'survey';
    const PARAM_TARGET = 'target_users_and_groups';
    const PARAM_TARGET_OPTION = 'target_users_and_groups_option';
    const PARAM_RIGHTS = 'rights';
    
    const ALL_PARTICIPANTS = 'all_participants';
    const FROM_ADDRESS = 'from_address';
    const FROM_ADDRESS_NAME = 'from_address_name';
    const REPLY_ADDRESS = 'reply_address';
    const REPLY_ADDRESS_NAME = 'reply_address_name';
    const EMAIL_HEADER = 'email_header';
    const EMAIL_CONTENT = 'email_content';
    const USERS_NOT_SELECTED_COUNT = 'users_not_selected_count';
    
    const FORM_NAME = 'survey_publication_mailer';
    
    private $type;

    function __construct($parent, $user, $users, $type, $actions)
    {
        parent :: __construct(self :: FORM_NAME, 'post', $actions);
        
        $this->type = $type;
        
        $attributes = array();
        $attributes['search_url'] = Path :: get(WEB_PATH) . 'group/php/xml_feeds/xml_group_feed.php';
        $locale = array();
        $locale['Display'] = Translation :: get('ShareWith');
        $locale['Searching'] = Translation :: get('Searching');
        $locale['NoResults'] = Translation :: get('NoResults');
        $locale['Error'] = Translation :: get('Error');
        $attributes['locale'] = $locale;
        $attributes['defaults'] = array();
        $attributes['options'] = array('load_elements' => false);
        
        $this->add_receivers(self :: APPLICATION_NAME . '_opt_' . self :: PARAM_TARGET, Translation :: get('AddMailRecipientsFilter'), $attributes);

        $defaults[self :: APPLICATION_NAME . '_opt_forever'] = 1;
        $defaults[self :: APPLICATION_NAME . '_opt_' . self :: PARAM_TARGET_OPTION] = 0;
 
        $this->addElement('text', self :: FROM_ADDRESS_NAME, Translation :: get('SurveyFromEmailAddressName'), array(
                'size' => 80, 'value' => $user->get_firstname() . ' ' . $user->get_lastname()));
        $this->addRule(self :: FROM_ADDRESS_NAME, Translation :: get('ThisFieldIsRequired'), 'required');
        $this->addElement('text', self :: FROM_ADDRESS, Translation :: get('SurveyFromEmailAddress'), array(
                'size' => 80, 'value' => $user->get_email()));
        $this->addRule(self :: FROM_ADDRESS, Translation :: get('ThisFieldIsRequired'), 'required');
        $this->addElement('text', self :: REPLY_ADDRESS_NAME, Translation :: get('SurveyReplyEmailAddressName'), array(
                'size' => 80, 'value' => $user->get_firstname() . ' ' . $user->get_lastname()));
        $this->addRule(self :: REPLY_ADDRESS_NAME, Translation :: get('ThisFieldIsRequired'), 'required');
        $this->addElement('text', self :: REPLY_ADDRESS, Translation :: get('SurveyReplyEmailAddress'), array(
                'size' => 80, 'value' => $user->get_email()));
        $this->addRule(self :: REPLY_ADDRESS, Translation :: get('ThisFieldIsRequired'), 'required');
        $this->addElement('text', self :: EMAIL_HEADER, Translation :: get('SurveyEmailTitle'), array('size' => 80));
        $this->addRule(self :: EMAIL_HEADER, Translation :: get('ThisFieldIsRequired'), 'required');
        $this->add_html_editor(self :: EMAIL_CONTENT, Translation :: get('SurveyEmailContent'), true);
        
        $this->add_warning_message('attention', Translation :: get('SurveyMailAttention'), Translation :: get('SurveyAttentionSendMailInfo'), false);
       
        switch ($this->type)
        {
            case SurveyMailManager::MAIL_PARTICIPANT_TYPE :
                $this->addElement('checkbox', SurveyRights :: PARTICIPATE_RIGHT_NAME, Translation :: get('Invitees'), ' ' . $users[SurveyRights :: PARTICIPATE_RIGHT_NAME] . ' ' . Translation :: get('Invitees'));
                $this->addElement('checkbox', SurveyParticipantTracker :: STATUS_NOTSTARTED, Translation :: get('SurveyNotStarted'), ' ' . $users[SurveyParticipantTracker :: STATUS_NOTSTARTED] . ' ' . Translation :: get('Participants'));
                $this->addElement('checkbox', SurveyParticipantTracker :: STATUS_STARTED, Translation :: get('SurveyStarted'), ' ' . $users[SurveyParticipantTracker :: STATUS_STARTED] . ' ' . Translation :: get('Participants'));
                $this->addElement('checkbox', SurveyParticipantTracker :: STATUS_FINISHED, Translation :: get('SurveyFinished'), ' ' . $users[SurveyParticipantTracker :: STATUS_FINISHED] . ' ' . Translation :: get('Participants'));
                break;
            case SurveyMailManager :: MAIL_EXPORT_TYPE :
                $this->addElement('checkbox', SurveyRights :: EXPORT_RESULT_RIGHT_NAME, Translation :: get('Invitees'), ' ' . $users[SurveyRights :: EXPORT_RESULT_RIGHT_NAME] . ' ' . Translation :: get('Invitees'));
                break;
            
            case SurveyMailManager :: MAIL_REPORTING_TYPE :
                $this->addElement('checkbox', SurveyRights :: REPORTING_RIGHT_NAME, Translation :: get('Invitees'), ' ' . $users[SurveyRights :: REPORTING_RIGHT_NAME] . ' ' . Translation :: get('Invitees'));
                break;
        
        }

        $buttons[] = $this->createElement('style_submit_button', 'submit', Translation :: get('SendMail'), array(
                'class' => 'positive publish'));
        $buttons[] = $this->createElement('style_reset_button', 'reset', Translation :: get('Reset'), array(
                'class' => 'normal empty'));

        $this->addGroup($buttons, 'buttons', null, '&nbsp;', false);
        $this->setDefaults($defaults);
    }

    function get_seleted_group_user_ids()
    {
   
        $values = $this->exportValues();
        
        $user_ids = array();
        
        if ($values[self :: APPLICATION_NAME . '_opt_' . self :: PARAM_TARGET_OPTION] == 0)
        {
            //there is no user filter needed
        	$user_ids = null;
        }
        else
        {
            $group_ids = $values[self :: APPLICATION_NAME . '_opt_' . self :: PARAM_TARGET . '_elements']['group'];
            
            if (count($group_ids))
            {
                foreach ($group_ids as $group_id)
                {
                    $group_user_ids = array();
                    foreach ($group_ids as $group_id)
                    {
                        
                        $group = GroupDataManager :: get_instance()->retrieve_group($group_id);
                        $ids = $group->get_users(true, true);
                        $group_user_ids = array_merge($group_user_ids, $ids);
                    
                    }
                    $user_ids = array_unique($group_user_ids);
                }
            }
        }
        return $user_ids;
    }
}
?>
Back to Top