/** * Remove mreporting notifications from GLPI. * * @return array 'success' => true on success */ static function uninstall() { global $DB; $queries = array(); // Remove NotificationTargets and Notifications $notification = new Notification(); $result = $notification->find("itemtype = 'PluginMreportingNotification'"); foreach ($result as $row) { $notification_id = $row['id']; $queries[] = "DELETE FROM glpi_notificationtargets \n WHERE notifications_id = " . $notification_id; $queries[] = "DELETE FROM glpi_notifications \n WHERE id = " . $notification_id; } // Remove NotificationTemplateTranslations and NotificationTemplates $template = new NotificationTemplate(); $result = $template->find("itemtype = 'PluginMreportingNotification'"); foreach ($result as $row) { $template_id = $row['id']; $queries[] = "DELETE FROM glpi_notificationtemplatetranslations \n WHERE notificationtemplates_id = " . $template_id; $queries[] = "DELETE FROM glpi_notificationtemplates \n WHERE id = " . $template_id; } foreach ($queries as $query) { $DB->query($query); } return array('success' => true); }
public static function add($params = array()) { $uid = zmf::uid(); $data = array('uid' => $params['uid'], 'authorid' => $uid, 'content' => $params['content'], 'new' => 1, 'type' => $params['type'], 'cTime' => zmf::now(), 'from_id' => $params['from_id'], 'from_idtype' => $params['from_idtype'], 'from_num' => 1); if ($uid == $params['uid']) { return false; } $model = new Notification(); $info = $model->find("uid=:uid AND authorid=:authorid AND from_id=:from AND type=:type", array(':uid' => $params['uid'], ':authorid' => $uid, ':from' => $params['from_id'], ':type' => $params['type'])); if ($info) { //存在则更新最新操作时间 if ($model->updateByPk($info['id'], array('cTime' => time(), 'new' => 1, 'from_num' => $info['from_num'] + 1))) { return true; } else { return false; } } else { //不存在则新增 $model->attributes = $data; if ($model->save()) { return true; } else { return false; } } }
public function action($app, $id, $action) { if (!$app->user->isLoggedIn()) { $app->output->redirect('/'); } if (!in_array($action, ['read', 'unread', 'delete'])) { $app->output->redirect('/'); } try { $id_dec = $app->hashids->decrypt($id); $notification = Notification::find('first', ['conditions' => ['id = ? AND receiver_id = ? AND deleted = ?', $id_dec, $app->user->id, 0], 'include' => ['user']]); if (!$notification) { $app->logger->log('No such Notification found', 'ERROR', array('object' => 'Notification', 'id' => $id, 'id_decrypted' => $id_dec, 'pathway' => 'notifications_action'), 'user'); $app->output->notFound(); } if ($action == 'read' or $action == 'unread') { $notification->seen = $action == 'read' ? 1 : 0; } if ($action == 'delete') { $notification->deleted = 1; } $notification->save(); $app->output->redirect('/notifications'); } catch (Hashids_Invalid $e) { $app->logger->log('Notification ID given was invalid', 'ERROR', array('object' => 'Notification', 'id' => $id, 'pathway' => 'notifications_action'), 'user'); $app->output->notFound(); } }
public function getNot($id) { $u_id = Input::get('u_id', 0); $token = Input::get('token', ''); try { $user = User::chkUserByToken($token, $u_id); $not = Notification::find($id); if (empty($not)) { throw new Exception("没有找到请求的数据", 2001); } $data = $not->showDetail(); $read = NotificationRead::where('u_id', '=', $u_id)->where('n_id', '=', $id)->first(); if (empty($read)) { $read = new NotificationRead(); $read->n_id = $id; $read->u_id = $u_id; $read->is_read = 1; $read->is_del = 0; } else { $read->is_read = 1; } $read->save(); $re = Tools::reTrue('获取消息成功', $data); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '获取消息失败:' . $e->getMessage()); } return Response::json($re); }
public function deleteNotify($id) { if (Notification::where('user_id', Auth::user()->id)->where('id', $id)->exists()) { $noty = Notification::find($id); $noty->delete(); } }
public function banned($app) { $app->output->addBreadcrumb('', 'CSGOShop'); $app->output->addBreadcrumb('/banned', 'Banned Notice'); $notification = Notification::find('first', array('conditions' => array('receiver_id = ? AND title = "BAN"', $app->user->id))); if (!empty($notification)) { $app->output->alert($notification->body, 'danger'); } $app->output->setTitle('Banned'); $app->output->render('about.banned'); }
public static function install() { $notifications = array('plugin_formcreator_form_created' => array('name' => __('A form has been created', 'formcreator'), 'subject' => __('Your request have been saved', 'formcreator'), 'content' => __('Hi,\\nYour request from GLPI have been successfully saved with number ##formcreator.request_id## and transmetted to the helpdesk team.\\nYou can see your answers onto the following link:\\n##formcreator.validation_link##', 'formcreator'), 'notified' => self::AUTHOR), 'plugin_formcreator_need_validation' => array('name' => __('A form need to be validate', 'formcreator'), 'subject' => __('A form from GLPI need to be validate', 'formcreator'), 'content' => __('Hi,\\nA form from GLPI need to be validate and you have been choosen as the validator.\\nYou can access it by clicking onto this link:\\n##formcreator.validation_link##', 'formcreator'), 'notified' => self::APPROVER), 'plugin_formcreator_refused' => array('name' => __('The form is refused', 'formcreator'), 'subject' => __('Your form have been refused by the validator', 'formcreator'), 'content' => __('Hi,\\nWe are sorry to inform you that your form have been refused by the validator for the reason below:\\n##formcreator.validation_comment##\\n\\nYou can still modify and resubmit it by clicking onto this link:\\n##formcreator.validation_link##', 'formcreator'), 'notified' => self::AUTHOR), 'plugin_formcreator_accepted' => array('name' => __('The form is accepted', 'formcreator'), 'subject' => __('Your form have been accepted by the validator', 'formcreator'), 'content' => __('Hi,\\nWe are pleased to inform you that your form have been accepted by the validator.\\nYour request will be considered soon.', 'formcreator'), 'notified' => self::AUTHOR), 'plugin_formcreator_deleted' => array('name' => __('The form is deleted', 'formcreator'), 'subject' => __('Your form have been deleted by an administrator', 'formcreator'), 'content' => __('Hi,\\nWe are sorry to inform you that your request cannot be considered and have been deleted by an administrator.', 'formcreator'), 'notified' => self::AUTHOR)); // Create the notification template $notification = new Notification(); $notification_target = new NotificationTarget(); $template = new NotificationTemplate(); $translation = new NotificationTemplateTranslation(); foreach ($notifications as $event => $datas) { // Check if notification allready exists $exists = $notification->find("itemtype = 'PluginFormcreatorFormanswer' AND event = '{$event}'"); // If it doesn't exists, create it if (count($exists) == 0) { $template_id = $template->add(array('name' => addslashes($datas['name']), 'comment' => '', 'itemtype' => 'PluginFormcreatorFormanswer')); // Add a default translation for the template $translation->add(array('notificationtemplates_id' => $template_id, 'language' => '', 'subject' => addslashes($datas['subject']), 'content_text' => addslashes($datas['content']), 'content_html' => '<p>' . str_replace('\\n', '<br />', $datas['content']) . '</p>')); // Create the notification $notification_id = $notification->add(array('name' => addslashes($datas['name']), 'comment' => '', 'entities_id' => 0, 'is_recursive' => 1, 'is_active' => 1, 'itemtype' => 'PluginFormcreatorFormanswer', 'notificationtemplates_id' => $template_id, 'event' => $event, 'mode' => 'mail')); // Add default notification targets $notification_target->add(array("items_id" => $datas['notified'], "type" => Notification::USER_TYPE, "notifications_id" => $notification_id)); } } }
<?php include '../../inc/init.inc'; if (isset($notification)) { $notification = Notification::find($notification); if (isset($type) && $type == "updateStatus") { if ($notification->to_user_id != $res->user->id) { throw new Exception("user is not autorized", 504, $res->user->id); } $notification->status = 1; $notification->save(); } } isset($redirect) ? $res->load($notification->action) : "";
/** * CLOSE NOTIFICATION (no destroy) * * @param int $id * @return Response */ public static function fechar($id) { if (!isset($id)) { return Response::json(array('error' => 'ID não informado')); } if ($notification = Notification::find($id)) { if ($notification->status) { $notification->status = 0; $notification->save(); $alert[] = ['class' => 'alert-success', 'message' => '<strong><i class="fa fa-check"></i></strong> Notificação marcada como não lida!']; Session::flash('alerts', $alert); return Redirect::to(URL::previous()); } $notification->close(); } return Response::json(array('success' => true)); }
$view = View::make('notifications.index'); $view->notifications = Auth::user()->notifications_received()->order_by('created_at', 'desc')->paginate(10); $this->layout->content = $view; } public function action_mark_as_read() { $notification = Config::get('notification'); if (Input::get('action') == '1') { $notification->mark_as_read(); } else { $notification->mark_as_unread(); } return Response::json(array("status" => "success", "unread_count" => Auth::user()->unread_notification_count(), "html" => View::make('notifications.partials.notification')->with('notification', $notification)->render())); } public function action_json() { $return_array = array(); foreach (Auth::user()->notifications_received()->order_by('read')->order_by('created_at', 'desc')->take(3)->get() as $notification) { $return_array[] = array('object' => $notification->to_array(), 'parsed' => NotificationParser::parse($notification)); } return Response::json(array('status' => 'success', 'results' => $return_array, 'count' => Auth::user()->notifications_received()->count())); } } Route::filter('i_am_notification_target', function () { $id = Request::$route->parameters[0]; $notification = Notification::find($id); if (!Auth::user() || Auth::user()->id != $notification->target_id) { return Redirect::to('/'); } Config::set('notification', $notification); });
function sendEmail($toEmail, $notification_title, $data = null) { $sent = false; if (!empty($toEmail)) { $config = $this->getConfiguration(); $this->Email->from = $config['domain_name'] . '<' . $config['donotreplay_email'] . '>'; $this->Email->to = $toEmail; $this->Email->sendAs = 'html'; App::import('Model', 'Notification'); $objNotification = new Notification(); $options = array('conditions' => array('title' => $notification_title)); $notification = $objNotification->find('first', $options); if (!empty($notification)) { $this->Email->subject = $notification['Notification']['subject']; $this->Email->cc = $notification['Notification']['cc']; $this->Email->bcc = $notification['Notification']['bcc']; $message = $this->_getMessage($notification, $data); $sent = $this->Email->send($message); } return $sent; } }
private function preRenderSetup() { $app =& $this->app; $page = ['alerts' => $this->alerts, 'title' => $this->title, 'activeTab' => $this->activeTab, 'breadcrumbs' => $this->breadcrumbs]; if ($app->user->isSiteDeveloper()) { $page['profiler'] = $app->profiler->fetch(); } $this->twig->addGlobal('page', $page); $this->twig->addFunction(new Twig_SimpleFunction('config', function ($key) use(&$app) { return $app->config->get($key); })); $this->twig->addFunction(new Twig_SimpleFunction('relative_time', function ($time = false, $limit = 86400, $format = 'g:i A M jS') { if (is_object($time)) { $time = $time->format('db'); } if (is_string($time)) { $time = strtotime($time); } $now = time(); $relative = ''; if ($time === $now) { $relative = 'now'; } elseif ($time > $now) { //$relative = 'in the future'; $diff = $time - $now; if ($diff >= $limit) { $relative = date($format, $time); } elseif ($diff < 60) { $relative = 'less than one minute'; } elseif (($minutes = ceil($diff / 60)) < 60) { $relative = $minutes . ' minute' . ((int) $minutes === 1 ? '' : 's'); } else { $hours = ceil($diff / 3600); $relative = 'about ' . $hours . ' hour' . ((int) $hours === 1 ? '' : 's'); } } else { $diff = $now - $time; if ($diff >= $limit) { $relative = date($format, $time); } elseif ($diff < 60) { $relative = 'less than one minute ago'; } elseif (($minutes = ceil($diff / 60)) < 60) { $relative = $minutes . ' minute' . ((int) $minutes === 1 ? '' : 's') . ' ago'; } else { $hours = ceil($diff / 3600); $relative = 'about ' . $hours . ' hour' . ((int) $hours === 1 ? '' : 's') . ' ago'; } } return $relative; })); $this->twig->addFunction(new Twig_SimpleFunction('markdown', function ($data) { return $this->markdown->text($data); })); $this->twig->addFunction(new Twig_SimpleFunction('hashid', function ($id) use(&$app) { return $app->hashids->encrypt($id); })); $this->twig->addFunction(new Twig_SimpleFunction('truncate', function ($text, $limit = 40) { if (strlen($text) < $limit) { return $text; } $text = $text . " "; $text = substr($text, 0, $limit); $text = substr($text, 0, strrpos($text, ' ')); $text = $text . "..."; return $text; })); $this->twig->addFunction(new Twig_SimpleFunction('money_format', function ($amount) { if (!function_exists('money_format')) { sprintf('$%.2f', $amount); } // require_once('./libs/utils/money_format.php'); return money_format('$%.2n', $amount); })); $this->twig->addFunction(new Twig_SimpleFunction('imgur_thumb', function ($link, $type = 'm') { return preg_replace('/(\\.gif|\\.jpg|\\.png)/', $type . '$1', $link); })); $this->twig->addGlobal('user', $app->user); $this->twig->addGlobal('total_users', count(User::find('all'))); $this->twig->addGlobal('total_stock', count(Listing::find('all', array('conditions' => array('stage = ?', Listing::STAGE_LIST))))); $this->twig->addGlobal('total_ordered', count(Listing::find('all', array('conditions' => array('stage IN (?)', array(Listing::STAGE_COMPLETE, Listing::STAGE_ARCHIVE)))))); if ($app->user->isLoggedIn()) { $notification_count = count(Notification::find('all', ['conditions' => ['receiver_id = ? AND seen = ? AND deleted = ?', $app->user->id, 0, 0]])); $this->twig->addGlobal('notification_count', $notification_count); } if (!empty($_SESSION['cart'])) { $cart_count = array_reduce(array_merge($_SESSION['cart']['listings'], $_SESSION['cart']['bulk']), function ($carry, $item) { $carry += $item['qty']; return $carry; }) ?: 0; } else { $cart_count = 0; } $this->twig->addGlobal('cart_count', $cart_count); }
public function viewNotification($id) { try { $notification = Notification::find($id); if ($notification) { $notification->seen = 2; if ($notification->type == 1) { $notification->like = Like::wherePostId($notification->post_id)->get()->count(); $notification->dislike = Dislike::wherePostId($notification->post_id)->get()->count(); } elseif ($notification->type == 2) { $notification->comment = Comment::wherePostId($notification->post_id)->get()->count(); //$notification->save(); } $notification->save(); return Redirect::to('/singlepost/' . $notification->post_id); } return "Unauthorized Access Of Notification"; } catch (Exception $e) { } return "Unauthorized Access Of Notification"; }