From 852404847d9c1e18f8c08c4b54d7835c9432bf94 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Thu, 14 Nov 2013 09:48:29 -0600
Subject: [PATCH] Fix fatal crash when adding a new page

Also add images on pages to the drop-down list for image choosing, and fix
display of images on the client portal.
---
 include/ajax.draft.php | 3 ++-
 include/class.page.php | 2 +-
 scp/pages.php          | 5 +++--
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/include/ajax.draft.php b/include/ajax.draft.php
index 37df05f77..0caaeeb7b 100644
--- a/include/ajax.draft.php
+++ b/include/ajax.draft.php
@@ -256,7 +256,7 @@ class DraftAjaxAPI extends AjaxController {
 
         $sql = 'SELECT distinct f.id, COALESCE(a.type, f.ft) FROM '.FILE_TABLE
             .' f LEFT JOIN '.ATTACHMENT_TABLE.' a ON (a.file_id = f.id)
-            WHERE (a.`type` IN (\'C\', \'F\', \'T\') OR f.ft = \'L\')
+            WHERE (a.`type` IN (\'C\', \'F\', \'T\', \'P\') OR f.ft = \'L\')
                 AND f.`type` LIKE \'image/%\'';
         if (!($res = db_query($sql)))
             Http::response(500, 'Unable to lookup files');
@@ -267,6 +267,7 @@ class DraftAjaxAPI extends AjaxController {
             'F' => 'FAQ Articles',
             'T' => 'Email Templates',
             'L' => 'Logos',
+            'P' => 'Pages',
         );
         while (list($id, $type) = db_fetch_row($res)) {
             $f = AttachmentFile::lookup($id);
diff --git a/include/class.page.php b/include/class.page.php
index c6e6329d5..f0ada9a6c 100644
--- a/include/class.page.php
+++ b/include/class.page.php
@@ -70,7 +70,7 @@ class Page {
         return $this->ht['body'];
     }
     function getBodyWithImages() {
-        return Format::viewableImages($this->getBody());
+        return Format::viewableImages($this->getBody(), ROOT_PATH.'image.php');
     }
 
     function getNotes() {
diff --git a/scp/pages.php b/scp/pages.php
index ee3af72db..87b260d23 100644
--- a/scp/pages.php
+++ b/scp/pages.php
@@ -28,8 +28,9 @@ if($_POST) {
                 $msg='Page added successfully';
                 // Attach inline attachments from the editor
                 if (isset($_POST['draft_id'])
-                        && ($draft = Draft::lookup($_POST['draft_id'])))
-                    $c->attachments->upload(
+                        && ($draft = Draft::lookup($_POST['draft_id']))
+                        && ($page = Page::lookup($pageId)))
+                    $page->attachments->upload(
                         $draft->getAttachmentIds($_POST['response']), true);
                 Draft::deleteForNamespace('page');
             } elseif(!$errors['err'])
-- 
GitLab