diff --git a/include/ajax.draft.php b/include/ajax.draft.php index 5795b24e3f00e562059819db2c5369522416251b..b01054ed8b9d6bf8c193e8420e4d54769c1cfce2 100644 --- a/include/ajax.draft.php +++ b/include/ajax.draft.php @@ -146,7 +146,6 @@ class DraftAjaxAPI extends AjaxController { Http::response(403, "Valid session required"); $vars = array( - 'staff_id' => ($thisclient) ? $thisclient->getId() : 1<<31, 'namespace' => $namespace, ); @@ -238,7 +237,6 @@ class DraftAjaxAPI extends AjaxController { Http::response(403, "Valid session required"); $draft = Draft::create(array( - 'staff_id' => ($thisclient) ? $thisclient->getId() : 1<<31, 'namespace' => $namespace, )); if (!$draft->save()) @@ -255,7 +253,6 @@ class DraftAjaxAPI extends AjaxController { Http::response(403, "Login required for draft creation"); $vars = array( - 'staff_id' => $thisstaff->getId(), 'namespace' => $namespace, ); @@ -311,7 +308,6 @@ class DraftAjaxAPI extends AjaxController { Http::response(403, "Login required for image upload"); $draft = Draft::create(array( - 'staff_id' => $thisstaff->getId(), 'namespace' => $namespace )); if (!$draft->save()) diff --git a/include/class.draft.php b/include/class.draft.php index 659325ede98dd6281a83857f92d5b4f989f9df96..8af88335e7a4412dd81d2c49b2182a3097df84ba 100644 --- a/include/class.draft.php +++ b/include/class.draft.php @@ -36,10 +36,23 @@ class Draft extends VerySimpleModel { function getStaffId() { return $this->staff_id; } function getNamespace() { return $this->namespace; } + static protected function getCurrentUserId() { + global $thisstaff, $thisclient; + + $user = $thisstaff ?: $thisclient; + if ($user) + return $user->getId(); + + return 1 << 31; + } + static function getDraftAndDataAttrs($namespace, $id=0, $original='') { $draft_body = null; $attrs = array(sprintf('data-draft-namespace="%s"', Format::htmlchars($namespace))); - $criteria = array('namespace'=>$namespace); + $criteria = array( + 'namespace' => $namespace, + 'staff_id' => self::getCurrentUserId(), + ); if ($id) { $attrs[] = sprintf('data-draft-object-id="%s"', Format::htmlchars($id)); $criteria['namespace'] .= '.' . $id; @@ -129,6 +142,7 @@ class Draft extends VerySimpleModel { unset($vars['attachments']); $vars['created'] = SqlFunction::NOW(); + $vars['staff_id'] = self::getCurrentUserId(); $draft = parent::create($vars); // Cloned attachments ... diff --git a/js/redactor-osticket.js b/js/redactor-osticket.js index 39ffaad3051debd0098e3c67400ebe5a8e405222..011535f6e19c3434c0ea760aff59fefd95a190ba 100644 --- a/js/redactor-osticket.js +++ b/js/redactor-osticket.js @@ -32,7 +32,6 @@ RedactorPlugins.draft = function() { this.opts.clipboardUploadUrl = this.opts.imageUpload = 'ajax.php/draft/'+this.opts.draftId+'/attach'; - this.autosave.enable(); } else { // Just upload the file. A draft will be created automatically @@ -41,6 +40,8 @@ RedactorPlugins.draft = function() { this.opts.imageUpload = this.opts.autoCreateUrl + '/attach'; this.opts.imageUploadCallback = this.afterUpdateDraft; } + if (autosave_url) + this.autosave.enable(); this.$draft_saved = $('<span>') .addClass("pull-right draft-saved")