From 62de966023779b439eb6682efba149be8cacca0f Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Thu, 25 Sep 2014 11:46:19 -0500 Subject: [PATCH] oops: Fix page lookup equipment --- account.php | 4 ++-- include/ajax.content.php | 2 +- include/class.client.php | 2 +- include/class.page.php | 20 +++++++++++++++----- include/class.staff.php | 2 +- include/class.user.php | 2 +- include/client/login.inc.php | 2 +- scp/login.php | 2 +- 8 files changed, 23 insertions(+), 13 deletions(-) diff --git a/account.php b/account.php index e8bcaf07a..97c8b5efd 100644 --- a/account.php +++ b/account.php @@ -37,7 +37,7 @@ elseif ($thisclient) { // Existing client (with an account) updating profile else { $user = User::lookup($thisclient->getId()); - $content = Page::lookup(Page::getIdByType('registration-thanks')); + $content = Page::lookupByType('registration-thanks'); $inc = isset($_GET['confirmed']) ? 'register.confirmed.inc.php' : 'profile.inc.php'; } @@ -94,7 +94,7 @@ elseif ($_POST) { if (!$errors) { switch ($_POST['do']) { case 'create': - $content = Page::lookup(Page::getIdByType('registration-confirm')); + $content = Page::lookupByType('registration-confirm'); $inc = 'register.confirm.inc.php'; $acct->sendConfirmEmail(); break; diff --git a/include/ajax.content.php b/include/ajax.content.php index 68297e991..39eda3e6d 100644 --- a/include/ajax.content.php +++ b/include/ajax.content.php @@ -157,7 +157,7 @@ class ContentAjaxAPI extends AjaxController { $langs = $cfg->getSecondaryLanguages(); - $content = Page::lookup(Page::getIdByType($type, $lang)); + $content = Page::lookupByType($type, $lang); include STAFFINC_DIR . 'templates/content-manage.tmpl.php'; } diff --git a/include/class.client.php b/include/class.client.php index 84b69f257..e29f570b7 100644 --- a/include/class.client.php +++ b/include/class.client.php @@ -55,7 +55,7 @@ abstract class TicketUser { if (!($ticket = $this->getTicket()) || !($email = $ost->getConfig()->getDefaultEmail()) - || !($content = Page::lookup(Page::getIdByType('access-link')))) + || !($content = Page::lookupByType('access-link'))) return; $vars = array( diff --git a/include/class.page.php b/include/class.page.php index 641832b66..e843a15aa 100644 --- a/include/class.page.php +++ b/include/class.page.php @@ -196,6 +196,18 @@ class Page extends VerySimpleModel { return self::getActivePages(array('type' => 'thank-you')); } + static function lookup($id, $lang=false) { + try { + $qs = self::objects()->filter(array('id'=>$id)); + if ($lang) + $qs = $qs->filter(array('lang'=>$lang)); + return $qs->one(); + } + catch (DoesNotExist $ex) { + return null; + } + } + static function getIdByName($name, $lang=false) { try { $qs = self::objects()->filter(array('name'=>$name)) @@ -210,14 +222,12 @@ class Page extends VerySimpleModel { } } - static function getIdByType($type, $lang=false) { + static function lookupByType($type, $lang=false) { try { - $qs = self::objects()->filter(array('type'=>$type)) - ->values_flat('id'); + $qs = self::objects()->filter(array('type'=>$type)); if ($lang) $qs = $qs->filter(array('lang'=>$lang)); - list($id) = $qs->one(); - return $id; + return $qs->one(); } catch (DoesNotExist $ex) { return null; diff --git a/include/class.staff.php b/include/class.staff.php index e20e3c03c..dd3444bea 100644 --- a/include/class.staff.php +++ b/include/class.staff.php @@ -687,7 +687,7 @@ class Staff extends AuthenticatedUser { function sendResetEmail($template='pwreset-staff') { global $ost, $cfg; - $content = Page::lookup(Page::getIdByType($template)); + $content = Page::lookupByType($template); $token = Misc::randCode(48); // 290-bits if (!$content) diff --git a/include/class.user.php b/include/class.user.php index 08b54cce6..382c66f80 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -941,7 +941,7 @@ class UserAccount extends UserAccountModel { $token = Misc::randCode(48); // 290-bits $email = $cfg->getDefaultEmail(); - $content = Page::lookup(Page::getIdByType($template)); + $content = Page::lookupByType($template); if (!$email || !$content) return new Error(sprintf(_S('%s: Unable to retrieve template'), diff --git a/include/client/login.inc.php b/include/client/login.inc.php index 2eb28a227..2b688ee2d 100644 --- a/include/client/login.inc.php +++ b/include/client/login.inc.php @@ -4,7 +4,7 @@ if(!defined('OSTCLIENTINC')) die('Access Denied'); $email=Format::input($_POST['luser']?:$_GET['e']); $passwd=Format::input($_POST['lpasswd']?:$_GET['t']); -$content = Page::lookup(Page::getIdByType('banner-client')); +$content = Page::lookupByType('banner-client'); if ($content) { list($title, $body) = $ost->replaceTemplateVariables( diff --git a/scp/login.php b/scp/login.php index c4947918b..609a0c5ec 100644 --- a/scp/login.php +++ b/scp/login.php @@ -23,7 +23,7 @@ TextDomain::configureForUser(); require_once(INCLUDE_DIR.'class.staff.php'); require_once(INCLUDE_DIR.'class.csrf.php'); -$content = Page::lookup(Page::getIdByType('banner-staff')); +$content = Page::lookupByType('banner-staff'); $dest = $_SESSION['_staff']['auth']['dest']; $msg = $_SESSION['_staff']['auth']['msg']; -- GitLab