public function build($runData) { $userId = $runData->getUserId(); $pl = $runData->getParameterList(); $messageId = $pl->getParameterValue("message_id"); $message = DB_PrivateMessagePeer::instance()->selectByPrimaryKey($messageId); if ($message->getFromUserId() != $userId) { throw new ProcessException(_("Error selecting message."), "no_message"); } $runData->contextAdd("message", $message); // get next & previous message $messageId = $message->getMessageId(); $c = new Criteria(); $c->add("from_user_id", $userId); $c->add("message_id", $messageId, ">"); $c->add("flag", 1); $c->addOrderAscending("message_id"); $newerMessage = DB_PrivateMessagePeer::instance()->selectOne($c); $c = new Criteria(); $c->add("from_user_id", $userId); $c->add("message_id", $messageId, "<"); $c->add("flag", 1); $c->addOrderDescending("message_id"); $olderMessage = DB_PrivateMessagePeer::instance()->selectOne($c); $runData->contextAdd("newerMessage", $newerMessage); $runData->contextAdd("olderMessage", $olderMessage); }
public function build($runData) { $userId = $runData->getUserId(); $pl = $runData->getParameterList(); $pageNo = $pl->getParameterValue("page"); if ($pageNo == null || $pageNo < 0) { $pageNo = 1; } // get inbox messages for the user $c = new Criteria(); $c->add("from_user_id", $userId); $c->add("flag", 1); // for sent // also count them all! $co = DB_PrivateMessagePeer::instance()->selectCount($c); $c->addOrderDescending("message_id"); $perPage = 30; // limits... $totalPages = ceil($co / $perPage); if ($pageNo > $totalPages) { $pageNo = $totalPages; } $offset = ($pageNo - 1) * $perPage; $c->setLimit($perPage, $offset); $runData->contextAdd("totalPages", $totalPages); $runData->contextAdd("currentPage", $pageNo); $messages = DB_PrivateMessagePeer::instance()->select($c); $runData->contextAdd("count", $co); $runData->contextAdd("totalPages", $totalPages); $runData->contextAdd("messages", $messages); }
public function build($runData) { $user = $runData->getUser(); $pl = $runData->getParameterList(); $replyMessageId = $pl->getParameterValue("replyMessageId", "AMODULE"); $continueMessageId = $pl->getParameterValue("continueMessageId", "AMODULE"); $toUserId = $pl->getParameterValue("toUserId"); if ($replyMessageId) { $message = DB_PrivateMessagePeer::instance()->selectByPrimaryKey($replyMessageId); if ($message == null || $message->getToUserId() != $user->getUserId()) { throw new ProcessException(_("Error getting orginal message."), "no_reply_message"); } $runData->ajaxResponseAdd("toUserId", $message->getFromUserId()); $runData->ajaxResponseAdd("toUserName", $message->getFromUser()->getNickName()); $subject = $message->getSubject(); $subject = preg_replace("/^Re: /", '', $subject); $runData->contextAdd("subject", "Re: " . $subject); } elseif ($continueMessageId) { $message = DB_PrivateMessagePeer::instance()->selectByPrimaryKey($continueMessageId); if ($message == null || $message->getFromUserId() != $user->getUserId()) { throw new ProcessException(_("Error getting orginal message."), "no_reply_message"); } if ($message->getToUserId() !== null) { $runData->ajaxResponseAdd("toUserId", $message->getToUserId()); $runData->ajaxResponseAdd("toUserName", $message->getToUser()->getNickName()); } $runData->contextAdd("body", $message->getBody()); $runData->contextAdd("subject", $message->getSubject()); } elseif ($toUserId !== null) { $toUser = DB_OzoneUserPeer::instance()->selectByPrimaryKey($toUserId); $runData->ajaxResponseAdd("toUserId", $toUser->getUserId()); $runData->ajaxResponseAdd("toUserName", $toUser->getNickName()); } $user = $runData->getUser(); $runData->contextAdd("user", $user); }
public function handleUser($user) { $db = Database::connection(); $db->begin(); $c = new Criteria(); $c->add("user_id", $user->getUserId()); $c->add("notify_email", true); $c->addOrderAscending("notification_id"); $nots = DB_NotificationPeer::instance()->select($c); if (count($nots) == 0) { $db->commit(); return; } if (count($nots) > 0) { $q = "UPDATE notification SET notify_email=FALSE " . "WHERE user_id='" . $user->getUserId() . "' AND " . "notify_email = TRUE"; $db->query($q); } // set language $lang = $user->getLanguage(); OZONE::getRunData()->setLanguage($lang); $GLOBALS['lang'] = $lang; // and for gettext too: switch ($lang) { case 'pl': $glang = "pl_PL"; break; case 'en': $glang = "en_US"; break; } putenv("LANG={$glang}"); putenv("LANGUAGE={$glang}"); setlocale(LC_ALL, $glang . '.UTF-8'); $nots2 = array(); foreach ($nots as &$not) { if ($not->getType() == "new_private_message") { // check if the message is read or still new $extra = $not->getExtra(); $pm = DB_PrivateMessagePeer::instance()->selectByPrimaryKey($extra['message_id']); if ($pm && $pm->getFlagNew()) { $body = $not->getBody(); $body = preg_replace('/<br\\/>Preview.*$/sm', '', $body); $body = preg_replace(';You have.*?<br/>;sm', '', $body); $not->setBody($body); $nots2[] = $not; } } else { $nots2[] = $not; } } $count = count($nots2); // now send an email $oe = new OzoneEmail(); $oe->addAddress($user->getName()); $oe->setSubject(sprintf(_("%s Account Notifications"), GlobalProperties::$SERVICE_NAME)); $oe->contextAdd('user', $user); $oe->contextAdd('notifications', $nots2); $oe->contextAdd('count', $count); $oe->setBodyTemplate('DigestEmail'); if (!$oe->send()) { throw new ProcessException("The email can not be sent to address " . $user->getName(), "email_failed"); } $db->commit(); }
public function removeSelectedDraftsEvent($runData) { $userId = $runData->getUserId(); $c = new Criteria(); $c->add("from_user_id", $userId); $c->add("flag", 2); $selected = $runData->getParameterList()->getParameterValue("selected"); $json = new JSONService(SERVICES_JSON_LOOSE_TYPE); $selected = $json->decode($selected); $db = Database::connection(); $db->begin(); $c2 = new Criteria(); foreach ($selected as $s) { $c2->addOr("message_id", $s); } $c->addCriteriaAnd($c2); DB_PrivateMessagePeer::instance()->delete($c); $db->commit(); }
private function handleNotifications($runData) { // check not earlier than 2 minutes after the previous check $user = $runData->getUser(); if ($user == null) { return; } // get last check date $lastCheck = $_COOKIE['lastncheck']; if ($lastCheck !== null && is_numeric($lastCheck) && time() - $lastCheck < 120) { return; } $cookieResult = setcookie('lastncheck', time(), time() + 10000000, "/", GlobalProperties::$SESSION_COOKIE_DOMAIN); // ok. go get the notifications now. $c = new Criteria(); $c->add("user_id", $user->getUserId()); $c->add("notify_online", true); $c->addOrderDescending("notification_id"); $nots = DB_NotificationPeer::instance()->select($c); if (count($nots) == 0) { return; } if (count($nots) > 0) { $q = "UPDATE notification SET notify_online=FALSE, notify_email=FALSE " . "WHERE user_id='" . $user->getUserId() . "' AND " . "notify_online = TRUE"; $db = Database::connection(); $db->query($q); } $nots2 = array(); foreach ($nots as &$not) { if ($not->getType() == "new_private_message") { // check if the message is read or still new $extra = $not->getExtra(); $pm = DB_PrivateMessagePeer::instance()->selectByPrimaryKey($extra['message_id']); if ($pm && $pm->getFlagNew()) { $body = $not->getBody(); $body = preg_replace('/<br\\/>Preview.*$/sm', '', $body); $body = preg_replace(';You have.*?<br/>;sm', '', $body); $not->setBody($body); $nots2[] = $not; } } else { $nots2[] = $not; } } if (count($nots2) == 0) { return; } $lang = $user->getLanguage(); switch ($lang) { case 'pl': $glang = "pl_PL"; $wp = "pl"; break; case 'en': $glang = "en_US"; $wp = "www"; break; } $runData->setLanguage($lang); putenv("LANG={$glang}"); putenv("LANGUAGE={$glang}"); setlocale(LC_ALL, $glang . '.UTF-8'); // get Smarty and render a dialog $smarty = Ozone::getSmartyPlain(); $dialogTemplateFile = PathManager::screenTemplate("NotificationDialog"); $count = count($nots2); if ($count > 3) { $nots2 = array_slice($nots2, 0, 3); $smarty->assign("more", $count - 3); } $smarty->assign("count", $count); $smarty->assign("notifications", $nots2); $out = $smarty->fetch($dialogTemplateFile); $this->vars['notificationsDialog'] = $out; $lang = $GLOBALS['lang']; switch ($lang) { case 'pl': $glang = "pl_PL"; break; case 'en': $glang = "en_US"; break; } $runData->setLanguage($lang); putenv("LANG={$glang}"); putenv("LANGUAGE={$glang}"); setlocale(LC_ALL, $glang . '.UTF-8'); }