function addmsg() { $idu = isset($_SESSION['idu']) ? $_SESSION['idu'] : 0; $iduser = isset($_POST['iduser']) ? $_POST['iduser'] : 0; $message = isset($_POST['message']) ? $_POST['message'] : 0; if ($idu > 0 && $iduser > 0 && !empty($message)) { $model = new Model_Message(); $model->createMessage($idu, $iduser, $message); } }
/** Check the number of unread messages a user have. * We show this info permanently when the user is logged in so we use an * action's helper postDispatch function to update the counter after every * action */ function postDispatch() { $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { $m_message = new Model_Message(); $n_unread = $m_message->getUnreadCount($auth->getIdentity()->id); $view = $this->getActionController()->view; $view->n_unread = $n_unread; } }
public function action_messages() { $receivedTotal = (int) $this->request->query('total'); $model = new Model_Message(); $currentTotal = $model->countMessages(); while ($receivedTotal == $currentTotal) { $currentTotal = $model->countMessages(); sleep(1); } $this->response->headers('Content-Type', 'application/json; charset=utf-8'); $messages = $model->getLastMessages(25); return $this->response->headers('Content-Type', 'application/json; charset=utf-8')->body(json_encode(['received' => $receivedTotal, 'messages' => $messages, 'total' => $currentTotal])); }
function action_message_story() { $authentification = new Authentification(); $model = new Model_Message(); if (isset($_GET['companion'])) { if ($_GET['recieve'] == 1) { $model->add_message($_GET['companion']); } $data = $model->get_message_story($_GET['companion']); $options['companion'] = $_GET['companion']; $this->view->generate('view_message_story.php', 'view_skeleton.php', $data, $auth_opt, $options); } else { } }
function all() { $idu = isset($_SESSION['idu']) ? $_SESSION['idu'] : 0; $this->stat->saveStat($idu, "msg/all"); if ($idu > 0) { $model = new Model_Message(); $model->getMessagesAll($idu, $unreadedMessage, $restMessage); $this->template->vars('unreadedMessage', $unreadedMessage); $this->template->vars('restMessage', $restMessage); $this->template->view('all', true); } else { unset($_SESSION['idu']); header('Location:' . WEB_APP); } }
function formatRow() { /* ------------------------------------- | | get additional data from DB | */ // Get data about sender if ($from_model = $this->config->getTypeModelClassName($this->current_row['from_type'])) { $from = $this->add($from_model)->tryLoad($this->current_row['from_id']); } else { $from['name'] = Model_Message::getFromTypes($this->current_row['from_type']); } // get data about receiver if ($to_model = $this->config->getTypeModelClassName($this->current_row['to_type'])) { $to = $this->add($to_model)->tryLoad($this->current_row['to_id']); } else { $to['name'] = Model_Message::getToTypes($this->current_row['to_type']); } /* ------------------------------------- | | compile HTML | */ $mixed_html = ''; $message_model = $this->config->getMessageModelClassName(); $mixed_html = $mixed_html . '<div class="' . $this->config->get('message-from-class') . '"><strong>From:</strong> ' . $from['name'] . ' (' . $message_model::getFromTypes($this->current_row['from_type']) . ') ' . ($this->current_row['from_is_deleted'] ? '*deleted*' : '') . '</div>'; $mixed_html = $mixed_html . '<div class="' . $this->config->get('message-to-class') . '"><strong>To:</strong> ' . $to['name'] . ' (' . $message_model::getToTypes($this->current_row['to_type']) . ') ' . ($this->current_row['to_is_deleted'] ? '*deleted*' : '') . '</div>'; $mixed_html = $mixed_html . '<div class="' . $this->config->get('message-text-class') . '">' . $this->current_row['text'] . '</div>'; $this->current_row_html['message'] = $mixed_html; parent::formatRow(); }
public function action_to($id = null) { // redirect if no id if ($id == null) { Response::redirect('message'); } // redirect if no right access if (!Sentry::user()->has_access('message_send')) { Session::set_flash('error', "You are not allowed to send message"); Response::redirect(''); } $data['user'] = Sentry::user(intval($id)); $data['messages'] = Model_Message::messageWith($data['user'], $this->current_user); if (Input::method() == 'POST') { $message = Model_Message::forge(array('subject' => Input::post('subject'), 'content' => Input::post('content'), 'to' => $data['user']->id, 'from' => $this->current_user->id, 'parent_id' => '', 'read' => 0, 'from_delete' => 0, 'to_delete' => 0)); if ($message and $message->save()) { Session::set_flash('success', 'Message successfuly sent to ' . $data['user']->username); Response::redirect('message'); } else { Session::set_flash('error', 'Could not send the message.'); } } $this->template->h2 = 'Send Message to ' . $data['user']->username; $this->template->title = 'Message » to'; $this->template->content = View::forge('message/to', $data); }
/** * отмечаем все сообщения пользователя прочитанными */ public function action_make_read() { $res = Model_Message::makeRead(['note_guid' => null]); if (empty($res)) { $this->jsonResult(false); } $this->jsonResult(true); }
public function action_message() { Controller::$full_width = TRUE; if ($this->request->param('id') !== NULL and is_numeric($id_msg_thread = $this->request->param('id'))) { $messages = Model_Message::get_thread($id_msg_thread, $this->user->id_user); if ($messages !== FALSE) { $msg_thread = new Model_Message(); $msg_thread = $msg_thread->where('id_message', '=', $this->request->param('id'))->find(); // send reply message if ($this->request->post() and Form::token('reply_message', TRUE)) { $validation = Validation::factory($this->request->post())->rule('message', 'not_empty'); if ($validation->check()) { $ret = Model_Message::reply(core::post('message'), $this->user->id_user, $id_msg_thread, NULL); if ($ret !== FALSE) { //who is who? if from is the same then send to TO, else to from if ($msg_thread->id_user_from == $this->user->id_user) { $user_to = $msg_thread->to; $user_from = $msg_thread->from; } else { $user_to = $msg_thread->from; $user_from = $msg_thread->to; } //email title if ($msg_thread->id_ad !== NULL) { $email_title = $msg_thread->ad->title; } else { $email_title = sprintf(__('Direct message from %s'), $user_from->name); } $user_to->email('messaging-reply', array('[TITLE]' => $email_title, '[DESCRIPTION]' => core::post('message'), '[URL.QL]' => $user_to->ql('oc-panel', array('controller' => 'messages', 'action' => 'message', 'id' => $this->request->param('id'))))); Alert::set(Alert::SUCCESS, __('Reply created.')); $this->redirect(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'message', 'id' => Request::current()->param('id')))); } else { Alert::set(Alert::ERROR, __('Message not sent')); } } else { $errors = $validation->errors('message'); } } Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Messaging'))->set_url(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'index')))); if ($msg_thread->id_ad !== NULL) { Breadcrumbs::add(Breadcrumb::factory()->set_title($msg_thread->ad->title)); } else { Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Direct Message'))); } $this->template->styles = array('css/jquery.sceditor.default.theme.min.css' => 'screen'); $this->template->scripts['footer'] = array('js/jquery.sceditor.bbcode.min.js', 'js/messages.js'); $this->template->content = View::factory('oc-panel/pages/messages/message', array('msg_thread' => $msg_thread, 'messages' => $messages, 'user' => $this->user)); } else { Alert::set(Alert::ERROR, __('Message not found')); $this->redirect(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'index'))); } } else { Alert::set(Alert::ERROR, __('Message not found')); $this->redirect(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'index'))); } }
public function action_delete($id = null) { is_null($id) and Response::redirect('messages'); if ($message = Model_Message::find($id)) { $message->delete(); Session::set_flash('success', 'Deleted message #' . $id); } else { Session::set_flash('error', 'Could not delete message #' . $id); } Response::redirect('messages'); }
public function action_status() { if ($this->request->param('id') !== NULL and is_numeric($id_msg_thread = $this->request->param('id')) and is_numeric(Core::get('status'))) { if (Model_Message::status_thread($id_msg_thread, $this->user, Core::get('status'))) { Alert::set(Alert::SUCCESS, __('Done')); } } else { Alert::set(Alert::ERROR, __('Message not found')); } $this->redirect(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'index'))); }
/** * прописываем глобальные конфиги * * @throws Kohana_Exception */ public function after() { $this->_appendFiles(); if (!$this->request->is_ajax()) { $this->_appendFilesAfter(); } View::set_global('user', Auth_Oracle::instance()->get_user()); $config = Kohana::$config->load('main')->as_array(); foreach ($config as $k => $v) { View::set_global($k, $v); } View::set_global('title', implode(" :: ", $this->title)); View::set_global('errors', $this->errors); if (Auth::instance()->logged_in()) { View::set_global('notices', Model_Message::getList(['not_read' => true])); } $this->template->content = $this->tpl; parent::after(); }
$now_time = time(); $n_time = $now_time - 48 * 3600; $filter['where'] = "customer_id = '{$customer_id}' and create_time > '{$n_time}' and fromuser !=''"; $filter['order'] = "id desc"; //$filter['order'] .= $status ? ',status asc' : ',status desc'; if ($_POST['search']) { $sea = str_inmysql($_POST['search']); $filter['where'] = "customer_id = '{$customer_id}' and msg_content like '%{$sea}%' and fromuser !=''"; //如果是ajax请求48小时外信息 } elseif (method_is('get') && $_GET['act'] == 'history') { $filter['where'] = "customer_id = '{$customer_id}' and create_time < '{$n_time}' and fromuser!=''"; //smarty $smarty->assign("val", true); } //result $msgModel = new Model_Message(); $result = $msgModel->paginate($filter, '*', $page); $pager = $result['pager']; //var_dump($_SESSION['customer_id']);die(); //pager if ($pager['count'] > $pager['size']) { $pagerhtml = new SubPages($pager['size'], $pager['count'], $pager['current'], $pager['range'], 2, ''); $smarty->assign("pagerhtml", $pagerhtml); } foreach ($result['data'] as $key => $row) { $result['data'][$key]['create_time'] = $msgModel->formatTime($row['create_time']); $result['data'][$key]['is_reply_str'] = $msgModel->is_reply($row['is_reply']); } $filte['where'] = " customer_id='{$customer_id}' and is_read='0' and create_time > {$n_time} and fromuser!=''"; $nums = $msgModel->count($filte); //smarty
/** * Delete a conversation */ public function deleteAction() { $this->_helper->viewRenderer->setNoRender(); $this->_helper->layout()->disableLayout(); $lang = $this->lang; $location = $this->location; $request = $this->getRequest(); /* User not logging, not allowed */ $auth = Zend_Auth::getInstance(); if (!$auth->hasIdentity()) { $this->_helper->_flashMessenger->addMessage($this->view->translate('You are not allowed to view this page')); $this->_redirect('/' . $lang . '/woeid/' . $location . '/give'); return; } $data['user_id'] = $auth->getIdentity()->id; $data['thread_id'] = (int) $request->getParam('id'); $modelM = new Model_Message(); $thread = $modelM->getThreadFromId($data['thread_id']); /* check current user is sender or recpient */ if ($data['user_id'] == $thread->user_to || $data['user_id'] == $thread->user_from) { $modelM->deleteThread($data); $this->_helper->_flashMessenger->addMessage($this->view->translate('Message succesfully deleted')); $aNamespace = new Zend_Session_Namespace('Nolotiro'); $this->_redirect('/' . $lang . '/message/list'); } else { $this->_helper->_flashMessenger->addMessage($this->view->translate('You are not allowed to view this page')); $this->_redirect('/' . $lang . '/woeid/' . $location . '/give'); return; } }
protected function addMessage() { $MessageModel = new Model_Message(); $row['customer_id'] = $this->customer_id; $row['fromuser'] = $this->post_data['FromUserName']; $row['touser'] = $this->post_data['ToUserName']; $row['msgtype'] = $this->post_data['FromMsgType']; $row['msg_content'] = $this->post_data['Keyword']; $row['create_time'] = $this->post_data['CreateTime']; $row['create_date'] = date("Y-m-d H:i:s"); $MessageModel->insert($row); if ($this->post_data['Event'] != 'subscribe' and $this->post_data['Event'] != 'unsubscribe') { /*更新会员表*/ $memberModel = new Model_Member(); $rowMem2 = $this->getMemDetail(); //获取用户详细信息 $rowMem2['customer_id'] = $this->customer_id; $rowMem2['fromuser'] = $this->post_data['FromUserName']; $rowMem2['timesign'] = $this->post_data['timesign']; $memberModel->upsert($rowMem2); } }
//echo $d=die(); $and = " and left(create_date,10)<='{$today}'"; $start_date = $today = $_POST['year'] . '-' . $_POST['month'] . '-01'; $smarty->assign('mon', $m); $smarty->assign('yea', $y); } else { $today = date("Y-m-d"); $start_date = date('Y-m-d', strtotime('-29 day')); /* $smarty->assign('mon',date('m')); $smarty->assign('yea',date('Y')); */ } $and = isset($and) ? $and : ''; $member = new Model_Member(); $data = $member->fetchRow("select * from member where customer_id={$customer_id} and fromuser='******'"); $smarty->assign("list", $data); $message = new Model_Message(); $result = $message->fetchAll("select msg_content,create_date from message where customer_id='{$customer_id}' and fromuser='******'"); if ($result) { //互动关键字和日期 $smarty->assign('Interactive_recording', $result); } //最近30天互动量 $filter['where'] = "customer_id='{$customer_id}' and fromuser='******' and left(create_date,10)>='{$start_date}'{$and}"; $filter['group'] = " left(create_date,10) "; $sql = $message->select($filter, 'count(id) as count_num,left(create_date,10) as count_date'); $messagearray = $message->fetchAll($sql); foreach ($messagearray as $key => $row) { $countinfoc[$row['count_date']] = $row['count_num']; if ($row['count_date'] == $today) { $count['today_message'] = $row['count_num']; }
<?php defined('SYSPATH') or die('No direct script access.'); ?> <?php if (Auth::instance()->logged_in()) { ?> <?php if (core::config('general.messaging') and $messages = Model_Message::get_unread_threads(Auth::instance()->get_user())) { ?> <div class="btn-group" role="group"> <?php if ($messages_count = $messages->count_all() > 0) { ?> <a class="btn btn-success" href="<?php echo Route::url('oc-panel', array('controller' => 'messages', 'action' => 'index')); ?> " data-toggle="dropdown" data-target="#" > <i class="fa fa-bell"></i> <span class="badge"><?php echo $messages_count; ?> </span> </a> <ul class="dropdown-menu"> <li class="dropdown-header"><?php echo sprintf(__('You have %s unread messages'), $messages_count);
<?php include_once "../../includes/config.inc.php"; include_once "../../includes/login_check.php"; //var $customer_id = (int) $_SESSION['customer_id']; $messageModel = new Model_Message(); $today = date("Y-m-d"); $yestoday = date('Y-m-d', strtotime('-1 day')); $start_date = date('Y-m-d', strtotime('-29 day')); //最近2天消息次数 $filter['where'] = "customer_id='{$customer_id}' and left(create_date,10)>='{$yestoday}'"; $filter['group'] = " left(create_date,10) "; $sql = $messageModel->select($filter, 'count(id) as count_num,left(create_date,10) as count_date'); $messagearray = $messageModel->fetchAll($sql); foreach ($messagearray as $key => $row) { if ($row['count_date'] == $today) { $count['today_sendnum'] = $row['count_num']; } elseif ($row['count_date'] == $yestoday) { $count['yestoday_sendnum'] = $row['count_num']; } } //最近2天消息人数 $filter['where'] = "customer_id='{$customer_id}' and left(create_date,10)>='{$yestoday}'"; $filter['group'] = " fromuser,left(create_date,10) "; $sql = $messageModel->select($filter, 'left(create_date,10) as count_date'); $memberarray = $messageModel->fetchAll($sql); foreach ($memberarray as $key => $row) { if ($row['count_date'] == $today) { $count['today_sendmember']++; } elseif ($row['count_date'] == $yestoday) {
<?php include_once "../../includes/config.inc.php"; include_once "../../includes/login_check.php"; //var $customer_id = (int) $_SESSION['customer_id']; $carerecordModel = new Model_CareRecord(); $messageModel = new Model_Message(); $today = date("Y-m-d"); $start_date = date('Y-m-d', strtotime('-29 day')); //最近30天关注量 $filter['where'] = "customer_id='{$customer_id}' and is_care='1' and left(create_date,10)>'{$start_date}'"; $filter['group'] = " left(create_date,10) "; $sql = $carerecordModel->select($filter, 'count(id) as count_num,left(create_date,10) as count_date'); $carearray = $carerecordModel->fetchAll($sql); foreach ($carearray as $key => $row) { $countinfo[$row['count_date']] = $row['count_num']; if ($row['count_date'] == $today) { $count['today_carenum'] = $row['count_num']; } } //取消量 $filter['where'] = "customer_id='{$customer_id}' and is_care='0' and left(create_date,10)>'{$start_date}'"; $filter['group'] = " left(create_date,10) "; $sql = $carerecordModel->select($filter, 'count(id) as count_num,left(create_date,10) as count_date'); $uncarearray = $carerecordModel->fetchAll($sql); foreach ($uncarearray as $key => $row) { $countinfob[$row['count_date']] = $row['count_num']; if ($row['count_date'] == $today) { $count['today_uncarenum'] = $row['count_num']; }
/** * returns all the unread threads for a user * @param Model_User $user * @return Model_Message */ public static function get_unread_threads($user) { return Model_Message::get_threads($user, Model_Message::STATUS_NOTREAD); }
public function noticeAction() { if ($this->_request->isPost()) { $data = $this->_request->getParams(); unset($data["action"]); unset($data["controller"]); unset($data["module"]); $data["sender"] = $this->admin->{"username"}; $data["user_id"] = -1; $data["type"] = 1; $data["message"] = "1|" . $data["message"]; $notice_modle = new Model_Message(); $notice_modle->save($data); echo "<h2>Created !!!</h2>"; } }
/** * returns all the unread threads for a user * @param integer $id_user * @return Model_Message */ public static function get_unread_threads($id_user) { //get the model ;) $messages = new Model_Message(); //I get first the last message grouped by parent. //we do this since I need to know if was written, the text and the creation date $query = DB::select('m1.id_message')->from(array('messages', 'm1'))->join(array('messages', 'm2'), 'LEFT')->on('m1.id_message', '<', 'm2.id_message')->on('m1.id_message_parent', '=', 'm2.id_message_parent')->where('m2.id_message', 'IS', NULL)->where('m1.id_user_to', '=', $id_user)->where('m1.status', '=', Model_Message::STATUS_NOTREAD)->execute(); $ids = $query->as_array(); //filter only if theres results if (count($ids) > 0) { $messages->where('id_message', 'IN', $ids); } else { $messages->where('id_message', '=', 0); } return $messages; }
/** * Handle POST requests for messages */ public function action_create() { try { $user = $this->user; //get message if (isset($this->_post_params['message'])) { $message = $this->_post_params['message']; } else { $this->_error(__('Message not sent')); } //price? $price = (isset($this->_post_params['price']) and is_numeric($this->_post_params['price'])) ? $this->_post_params['price'] : NULL; //message to the user if (isset($this->_post_params['id_user']) and is_numeric($id_user_to = $this->_post_params['id_user'])) { $ret = Model_Message::send_user($message, $user->id_user, $id_user_to); } elseif (isset($this->_post_params['id_ad']) and is_numeric($id_ad = $this->_post_params['id_ad'])) { $ret = Model_Message::send_ad($message, $user->id_user, $id_ad, $price); } elseif (isset($this->_post_params['id_message_parent']) and is_numeric($id_message_parent = $this->_post_params['id_message_parent'])) { $ret = Model_Message::reply($message, $user->id_user, $id_message_parent, $price); } //good response! if ($ret !== FALSE) { $this->rest_output(array('message' => $ret->as_array())); } else { $this->_error(__('Message not sent')); } } catch (Kohana_HTTP_Exception $khe) { $this->_error($khe); } }
public function action_userprofile_contact() { $user_to = new Model_User($this->request->param('id')); //message to user if ($user_to->loaded() and $this->request->post()) { if (captcha::check('contact')) { //check if user is loged in if (Auth::instance()->logged_in()) { $email_from = Auth::instance()->get_user()->email; $name_from = Auth::instance()->get_user()->name; } else { $email_from = core::post('email'); $name_from = core::post('name'); } //require login to contact if (core::config('general.messaging') == TRUE and !Auth::instance()->logged_in()) { Alert::set(Alert::INFO, __('Please, login before contacting')); HTTP::redirect(Route::url('oc-panel')); } //akismet spam filter if (!core::akismet($name_from, $email_from, core::post('message'))) { if (core::config('general.messaging')) { $ret = Model_Message::send_user(core::post('message'), $this->user, $user_to); } else { $ret = $user_to->email('user-profile-contact', array('[EMAIL.BODY]' => core::post('message'), '[EMAIL.SENDER]' => $name_from, '[EMAIL.SUBJECT]' => core::post('subject'), '[EMAIL.FROM]' => $email_from), $email_from, $name_from); } //if succesfully sent if ($ret) { Alert::set(Alert::SUCCESS, __('Your message has been sent')); } else { Alert::set(Alert::ERROR, __('Message not sent')); } } else { Alert::set(Alert::SUCCESS, __('This email has been considered as spam! We are sorry but we can not send this email.')); } } else { Alert::set(Alert::ERROR, __('Captcha is not correct')); } HTTP::redirect(Route::url('profile', array('seoname' => $user_to->seoname))); } }
public function action_userprofile_contact() { $user = new Model_User($this->request->param('id')); //message to user if ($user->loaded() and $this->request->post()) { if (captcha::check('contact')) { //check if user is loged in if (Auth::instance()->logged_in()) { $email_from = Auth::instance()->get_user()->email; $name_from = Auth::instance()->get_user()->name; } else { $email_from = core::post('email'); $name_from = core::post('name'); } //akismet spam filter if (!core::akismet($name_from, $email_from, core::post('message'))) { if (core::config('general.messaging')) { $ret = Model_Message::send_user(core::post('message'), $this->user->id_user, $user->id_user); if ($ret !== FALSE) { $user->email('messaging-user-contact', array('[FROM.NAME]' => $this->user->name, '[TO.NAME]' => $user->name, '[DESCRIPTION]' => core::post('message'), '[URL.QL]' => $user->ql('oc-panel', array('controller' => 'messages', 'action' => 'message', 'id' => $ret->id_message)))); } } else { $ret = $user->email('user-profile-contact', array('[EMAIL.BODY]' => core::post('message'), '[EMAIL.SENDER]' => $name_from, '[EMAIL.SUBJECT]' => core::post('subject'), '[EMAIL.FROM]' => $email_from), $email_from, core::post('name')); } //if succesfully sent if ($ret) { Alert::set(Alert::SUCCESS, __('Your message has been sent')); } else { Alert::set(Alert::ERROR, __('Message not sent')); } } else { Alert::set(Alert::SUCCESS, __('This email has been considered as spam! We are sorry but we can not send this email.')); } } else { Alert::set(Alert::ERROR, __('Captcha is not correct')); } HTTP::redirect(Route::url('profile', array('seoname' => $user->seoname))); } }