/**
  * Show / process email template form
  *
  * @param void
  * @return null
  */
 function edit()
 {
     if ($this->active_template->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     $locale = $this->request->get('locale', null);
     $template_data = $this->request->post('template');
     if (!is_array($template_data)) {
         $template_data = array('subject' => $this->active_template->getSubject($locale), 'body' => $this->active_template->getBody($locale));
     }
     // if
     $template_variables = $this->active_template->getVariables() ? explode("\n", $this->active_template->getVariables()) : null;
     $this->smarty->assign(array('template_data' => $template_data, 'template_variables' => $template_variables, 'locale' => $locale));
     if ($this->request->isSubmitted()) {
         if ($locale) {
             $this->active_template->writeLocaleProperties(array_var($template_data, 'subject'), array_var($template_data, 'body'), $locale);
         } else {
             $this->active_template->setAttributes($template_data);
         }
         // if
         $save = $this->active_template->save();
         if ($save && !is_error($save)) {
             flash_success('Email template has been updated');
             $this->redirectToUrl($this->active_template->getUrl());
         } else {
             $this->smarty->assign('errors', $save);
         }
         // if
     }
     // if
 }
예제 #2
0
 function delete($oDocument, $sReason, $iDestFolderId = null)
 {
     // use the deleteSymbolicLink function is this is a symlink
     if ($oDocument->isSymbolicLink()) {
         return KTDocumentUtil::deleteSymbolicLink($oDocument);
     }
     $oDocument =& KTUtil::getObject('Document', $oDocument);
     if (is_null($iDestFolderId)) {
         $iDestFolderId = $oDocument->getFolderID();
     }
     $oStorageManager =& KTStorageManagerUtil::getSingleton();
     global $default;
     if (count(trim($sReason)) == 0) {
         return PEAR::raiseError(_kt('Deletion requires a reason'));
     }
     if (PEAR::isError($oDocument) || $oDocument == false) {
         return PEAR::raiseError(_kt('Invalid document object.'));
     }
     if ($oDocument->getIsCheckedOut() == true) {
         return PEAR::raiseError(sprintf(_kt('The document is checked out and cannot be deleted: %s'), $oDocument->getName()));
     }
     if (!KTWorkflowUtil::actionEnabledForDocument($oDocument, 'ktcore.actions.document.delete')) {
         return PEAR::raiseError(_kt('Document cannot be deleted as it is restricted by the workflow.'));
     }
     // IF we're deleted ...
     if ($oDocument->getStatusID() == DELETED) {
         return true;
     }
     $oOrigFolder = Folder::get($oDocument->getFolderId());
     DBUtil::startTransaction();
     // flip the status id
     $oDocument->setStatusID(DELETED);
     // $iDestFolderId is DEPRECATED.
     $oDocument->setFolderID(null);
     $oDocument->setRestoreFolderId($oOrigFolder->getId());
     $oDocument->setRestoreFolderPath(Folder::generateFolderIDs($oOrigFolder->getId()));
     $res = $oDocument->update();
     if (PEAR::isError($res) || $res == false) {
         DBUtil::rollback();
         return PEAR::raiseError(_kt('There was a problem deleting the document from the database.'));
     }
     // now move the document to the delete folder
     $res = $oStorageManager->delete($oDocument);
     if (PEAR::isError($res) || $res == false) {
         //could not delete the document from the file system
         $default->log->error('Deletion: Filesystem error deleting document ' . $oDocument->getFileName() . ' from folder ' . Folder::getFolderPath($oDocument->getFolderID()) . ' id=' . $oDocument->getFolderID());
         // we use a _real_ transaction here ...
         DBUtil::rollback();
         /*
         //reverse the document deletion
         $oDocument->setStatusID(LIVE);
         $oDocument->update();
         */
         return PEAR::raiseError(_kt('There was a problem deleting the document from storage.'));
     }
     // get the user object
     $oUser = User::get($_SESSION['userID']);
     //delete all shortcuts linking to this document
     $aSymlinks = $oDocument->getSymbolicLinks();
     foreach ($aSymlinks as $aSymlink) {
         $oShortcutDocument = Document::get($aSymlink['id']);
         $oOwnerUser = User::get($oShortcutDocument->getOwnerID());
         KTDocumentUtil::deleteSymbolicLink($aSymlink['id']);
         //send an email to the owner of the shortcut
         if ($oOwnerUser->getEmail() != null && $oOwnerUser->getEmailNotification() == true) {
             $emailTemplate = new EmailTemplate("kt3/notifications/notification.SymbolicLinkDeleted", array('user_name' => $oUser->getName(), 'url' => KTUtil::ktLink(KTBrowseUtil::getUrlForDocument($oShortcutDocument)), 'title' => $oShortcutDocument->getName()));
             $email = new EmailAlert($oOwnerUser->getEmail(), _kt("KnowledgeTree Notification"), $emailTemplate->getBody());
             $email->send();
         }
     }
     $oDocumentTransaction = new DocumentTransaction($oDocument, _kt('Document deleted: ') . $sReason, 'ktcore.transactions.delete');
     $oDocumentTransaction->create();
     $oDocument->setFolderID(1);
     DBUtil::commit();
     // we weren't doing notifications on this one
     $oSubscriptionEvent = new SubscriptionEvent();
     $oSubscriptionEvent->RemoveDocument($oDocument, $oOrigFolder);
     // document is now deleted:  triggers are best-effort.
     $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
     $aTriggers = $oKTTriggerRegistry->getTriggers('delete', 'postValidate');
     foreach ($aTriggers as $aTrigger) {
         $sTrigger = $aTrigger[0];
         $oTrigger = new $sTrigger();
         $aInfo = array('document' => $oDocument);
         $oTrigger->setInfo($aInfo);
         $ret = $oTrigger->postValidate();
         if (PEAR::isError($ret)) {
             $oDocument->delete();
             // FIXME nbm: review that on-fail => delete is correct ?!
             return $ret;
         }
     }
 }