public function docmanwatermark_toggle_item() { $itemId = $this->_controler->request->getValidated('item_id', 'UInt'); if ($itemId != null && $this->_controler->userCanManage($itemId) && $this->_controler->request->isPost()) { $itemFactory = new Docman_ItemFactory(); $dwItemFactory = new DocmanWatermark_ItemFactory(); $dwLog = new DocmanWatermark_Log(); $item = $itemFactory->getItemFromDb($itemId); $user = $this->_controler->getUser(); if ($this->_controler->request->existAndNonEmpty('disable_watermarking')) { if ($dwItemFactory->disableWatermarking($itemId)) { $dwLog->disableWatermarking($item, $user); $dwItemFactory->notifyOnDisable($item, $user, $this->_controler->getDefaultUrl()); $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_docmanwatermark', 'action_watermarking_disabled')); } else { $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_docmanwatermark', 'action_watermarking_disable_error')); } } else { if ($dwItemFactory->enableWatermarking($itemId)) { $dwLog->enableWatermarking($item, $user); $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_docmanwatermark', 'action_watermarking_enabled')); } else { $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_docmanwatermark', 'action_watermarking_enable_error')); } } $this->_controler->view = 'RedirectAfterCrud'; $this->_controler->_viewParams['redirect_to'] = $this->_controler->getDefaultUrl() . '&action=details&id=' . $itemId . '§ion=watermarking'; } else { // Bad Item Id or attempt to fake the server, redirect to root // @todo: log those kind of attempt. $this->_controler->view = 'RedirectAfterCrud'; $this->_controler->_viewParams['redirect_to'] = $this->_controler->getDefaultUrl(); } }