function write($ajax = FALSE) { if ($_POST) { unset($_POST['send']); unset($_POST['_wysihtml5_mode']); $message = $_POST['message']; $receiverart = substr($_POST['recipient'], 0, 1); $receiverid = substr($_POST['recipient'], 1, 9999); if ($receiverart == "u") { $receiver = User::find($receiverid); $receiveremail = $receiver->email; } else { $receiver = Client::find($receiverid); $receiveremail = $receiver->email; } $_POST = array_map('htmlspecialchars', $_POST); $_POST['message'] = $message; $_POST['time'] = date('Y-m-d H:i', time()); $_POST['sender'] = "u" . $this->user->id; $_POST['status'] = "New"; if (!isset($_POST['conversation'])) { $_POST['conversation'] = random_string('sha1'); } $message = Privatemessage::create($_POST); if (!$message) { $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_write_message_error')); } else { $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_write_message_success')); $this->load->helper('notification'); send_notification($receiveremail, $this->lang->line('application_notification_new_message_subject'), $this->lang->line('application_notification_new_message') . '<br><hr style="border-top: 1px solid #CCCCCC; border-left: 1px solid whitesmoke; border-bottom: 1px solid whitesmoke;"/>' . $_POST['message'] . '<hr style="border-top: 1px solid #CCCCCC; border-left: 1px solid whitesmoke; border-bottom: 1px solid whitesmoke;"/>'); } if ($ajax != "reply") { redirect('messages'); } else { $this->theme_view = 'ajax'; } } else { $this->view_data['clients'] = Client::find('all', array('conditions' => array('inactive=?', '0'))); $this->view_data['users'] = User::find('all', array('conditions' => array('status=?', 'active'))); $this->theme_view = 'modal'; $this->view_data['title'] = $this->lang->line('application_write_message'); $this->view_data['form_action'] = 'messages/write'; $this->content_view = 'messages/_messages'; } }
function write($ajax = FALSE) { if ($_POST) { $config['upload_path'] = './files/media/'; $config['encrypt_name'] = TRUE; $config['allowed_types'] = '*'; $this->load->library('upload', $config); $this->load->helper('notification'); unset($_POST['userfile']); unset($_POST['file-name']); unset($_POST['send']); unset($_POST['note-codable']); unset($_POST['files']); $message = $_POST['message']; $receiverart = substr($_POST['recipient'], 0, 1); $receiverid = substr($_POST['recipient'], 1, 9999); if ($receiverart == "u") { $receiver = User::find($receiverid); $receiveremail = $receiver->email; } else { $receiver = Client::find($receiverid); $receiveremail = $receiver->email; } if (!$this->upload->do_upload()) { $error = $this->upload->display_errors('', ' '); if ($error != "You did not select a file to upload.") { //$this->session->set_flashdata('message', 'error:'.$error); } } else { $data = array('upload_data' => $this->upload->data()); $_POST['attachment'] = $data['upload_data']['orig_name']; $_POST['attachment_link'] = $data['upload_data']['file_name']; } $_POST = array_map('htmlspecialchars', $_POST); $_POST['message'] = $message; $_POST['time'] = date('Y-m-d H:i', time()); $_POST['sender'] = "u" . $this->user->id; $_POST['status'] = "New"; if (!isset($_POST['conversation'])) { $_POST['conversation'] = random_string('sha1'); } if (isset($_POST['previousmessage'])) { $status = Privatemessage::find_by_id($_POST['previousmessage']); if ($receiveremail == $this->user->email) { $receiverart = substr($status->recipient, 0, 1); $receiverid = substr($status->recipient, 1, 9999); $_POST['recipient'] = $status->recipient; if ($receiverart == "u") { $receiver = User::find($receiverid); $receiveremail = $receiver->email; } else { $receiver = Client::find($receiverid); $receiveremail = $receiver->email; } } $status->status = 'Replied'; $status->save(); unset($_POST['previousmessage']); } $message = Privatemessage::create($_POST); if (!$message) { $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_write_message_error')); } else { $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_write_message_success')); $this->load->helper('notification'); send_notification($receiveremail, $this->lang->line('application_notification_new_message_subject'), $this->lang->line('application_notification_new_message') . '<br><hr style="border-top: 1px solid #CCCCCC; border-left: 1px solid whitesmoke; border-bottom: 1px solid whitesmoke;"/>' . $_POST['message'] . '<hr style="border-top: 1px solid #CCCCCC; border-left: 1px solid whitesmoke; border-bottom: 1px solid whitesmoke;"/>'); } if ($ajax != "reply") { redirect('messages'); } else { $this->theme_view = 'ajax'; } } else { $this->view_data['clients'] = Client::find('all', array('conditions' => array('inactive=?', '0'))); $this->view_data['users'] = User::find('all', array('conditions' => array('status=?', 'active'))); $this->theme_view = 'modal'; $this->view_data['title'] = $this->lang->line('application_write_message'); $this->view_data['form_action'] = 'messages/write'; $this->content_view = 'messages/_messages'; } }