Messages::compose PHP Method

compose() public method

public compose ( )
    public function compose()
    {
        $this->user->restrict('Admin.Messages');
        $this->user->restrict('Admin.Messages.Add');
        $message_info = $this->Messages_model->getDraftMessage((int) $this->input->get('id'));
        if ($message_info) {
            $message_id = $message_info['message_id'];
            $data['_action'] = site_url('messages/compose?id=' . $message_id);
        } else {
            $message_id = 0;
            $data['_action'] = site_url('messages/compose');
        }
        if ($this->input->get('id') and !$message_info) {
            redirect('messages');
        }
        $this->template->setTitle($this->lang->line('text_title'));
        $this->template->setHeading(sprintf($this->lang->line('text_edit_heading'), 'Compose'));
        $this->template->setButton($this->lang->line('button_send'), array('class' => 'btn btn-success', 'onclick' => '$(\'#compose-form\').submit();'));
        $this->template->setButton($this->lang->line('button_save_draft'), array('class' => 'btn btn-default', 'onclick' => 'saveAsDraft();'));
        $this->template->setButton($this->lang->line('button_icon_back'), array('class' => 'btn btn-default', 'href' => site_url('messages')));
        $this->template->setStyleTag(assets_url('js/summernote/summernote.css'), 'summernote-css', '111');
        $this->template->setScriptTag(assets_url('js/summernote/summernote.min.js'), 'summernote-js', '111');
        if ($this->input->post() and $message_id = $this->_saveMessage()) {
            if ($this->input->post('save_as_draft') === '1') {
                redirect('messages/compose?id=' . $message_id);
            }
            redirect('messages');
        }
        $data['sub_menu_back'] = site_url('messages');
        if ($this->input->post('recipient')) {
            $data['recipient'] = $this->input->post('recipient');
        } else {
            $data['recipient'] = $message_info['recipient'];
        }
        if ($this->input->post('send_type')) {
            $data['send_type'] = $this->input->post('send_type');
        } else {
            $data['send_type'] = $message_info['send_type'];
        }
        $data['subject'] = $message_info['subject'];
        $data['body'] = $message_info['body'];
        $data['recipients'] = array('all_newsletters' => $this->lang->line('text_all_newsletters'), 'all_customers' => $this->lang->line('text_all_customers'), 'customer_group' => $this->lang->line('text_customer_group'), 'customers' => $this->lang->line('text_customers'), 'all_staffs' => $this->lang->line('text_all_staff'), 'staff_group' => $this->lang->line('text_staff_group'), 'staffs' => $this->lang->line('text_staff'));
        $this->load->model('Customer_groups_model');
        $data['customer_groups'] = array();
        $results = $this->Customer_groups_model->getCustomerGroups();
        foreach ($results as $result) {
            $data['customer_groups'][] = array('customer_group_id' => $result['customer_group_id'], 'group_name' => $result['group_name']);
        }
        $this->load->model('Staff_groups_model');
        $data['staff_groups'] = array();
        $results = $this->Staff_groups_model->getStaffGroups();
        foreach ($results as $result) {
            $data['staff_groups'][] = array('staff_group_id' => $result['staff_group_id'], 'staff_group_name' => $result['staff_group_name']);
        }
        $message_unread = $this->user->unreadMessageTotal();
        $data['folders'] = array('inbox' => array('title' => $this->lang->line('text_inbox'), 'icon' => 'fa-inbox', 'badge' => $message_unread, 'url' => site_url('messages')), 'draft' => array('title' => $this->lang->line('text_draft'), 'icon' => 'fa-file-text-o', 'badge' => '', 'url' => site_url('messages/draft')), 'sent' => array('title' => $this->lang->line('text_sent'), 'icon' => 'fa-paper-plane-o', 'badge' => '', 'url' => site_url('messages/sent')), 'all' => array('title' => $this->lang->line('text_all'), 'icon' => 'fa-briefcase', 'badge' => '', 'url' => site_url('messages/all')), 'archive' => array('title' => $this->lang->line('text_archive'), 'icon' => 'fa-archive', 'badge' => '', 'url' => site_url('messages/archive')));
        $data['labels'] = array('account' => array('title' => $this->lang->line('text_account'), 'icon' => 'fa-user', 'url' => page_url() . '?filter_type=account'), 'email' => array('title' => $this->lang->line('text_email'), 'icon' => 'fa-at', 'url' => page_url() . '?filter_type=email'));
        $this->template->render('messages_compose', $data);
    }