Commit 5ff745dbbaca8f46d72e8583c8fbd176882c85bd
1 parent
ad7612b3
Use dispatcher and new helpentity to simplify code.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3480 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
113 additions
and
41 deletions
presentation/lookAndFeel/knowledgeTree/administration/help/manageHelp.php
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | require_once("../../../../../config/dmsDefaults.php"); |
| 3 | 4 | |
| 4 | 5 | require_once(KT_DIR . "/presentation/Html.inc"); |
| 5 | 6 | |
| 6 | 7 | require_once(KT_LIB_DIR . "/templating/templating.inc.php"); |
| 7 | 8 | require_once(KT_LIB_DIR . "/help/helpreplacement.inc.php"); |
| 9 | +require_once(KT_LIB_DIR . "/help/helpentity.inc.php"); | |
| 8 | 10 | require_once(KT_LIB_DIR . "/help/help.inc.php"); |
| 9 | 11 | |
| 12 | +require_once(KT_LIB_DIR . "/dispatcher.inc.php"); | |
| 13 | +$sectionName = "Administration"; | |
| 14 | +require_once(KT_DIR . "/presentation/webpageTemplate.inc"); | |
| 15 | + | |
| 10 | 16 | // require_once(KT_DIR . "/FCKeditor/fckeditor.php"); |
| 11 | 17 | |
| 12 | -function getItemData($iId) { | |
| 13 | - $oTemplating = new KTTemplating; | |
| 14 | - $oHelp =& KTHelpReplacement::get($iId); | |
| 15 | - if (PEAR::isError($oHelp)) { | |
| 16 | - $_SESSION['KTErrorMessage'][] = "Help for that item not found"; | |
| 17 | - exit(controllerRedirect('helpAdmin')); | |
| 18 | +class ManageHelpDispatcher extends KTAdminDispatcher { | |
| 19 | + function do_main() { | |
| 20 | + return $this->getData(); | |
| 18 | 21 | } |
| 19 | 22 | |
| 20 | - // $oEditor = new FCKEditor("description"); | |
| 21 | - // $oEditor->Value = $oHelp->getDescription(); | |
| 22 | - // $oEditor->Height = 400; | |
| 23 | + function getData() { | |
| 24 | + $oTemplating = new KTTemplating; | |
| 25 | + $aHelpReplacements =& KTHelpReplacement::getList(); | |
| 26 | + $aHelps =& KTHelpEntity::getList(); | |
| 27 | + $oTemplate = $oTemplating->loadTemplate("ktcore/manage_help"); | |
| 28 | + $aTemplateData = array( | |
| 29 | + "helps" => $aHelps, | |
| 30 | + "helpreplacements" => $aHelpReplacements, | |
| 31 | + ); | |
| 23 | 32 | |
| 24 | - $oTemplate = $oTemplating->loadTemplate("ktcore/manage_help_item"); | |
| 25 | - $aTemplateData = array( | |
| 26 | - "help" => $oHelp, | |
| 27 | - // "fck" => $oEditor, | |
| 28 | - ); | |
| 29 | - return $oTemplate->render($aTemplateData); | |
| 30 | -} | |
| 33 | + return $oTemplate->render($aTemplateData); | |
| 34 | + } | |
| 35 | + | |
| 36 | + function getReplacementItemData($oHelpReplacement) { | |
| 37 | + $oTemplating = new KTTemplating; | |
| 38 | + $oTemplate = $oTemplating->loadTemplate("ktcore/manage_help_item"); | |
| 39 | + $aTemplateData = array( | |
| 40 | + "help" => $oHelpReplacement, | |
| 41 | + ); | |
| 42 | + return $oTemplate->render($aTemplateData); | |
| 43 | + } | |
| 31 | 44 | |
| 32 | -function getData() { | |
| 33 | - $oTemplating = new KTTemplating; | |
| 34 | - $aHelps = KTHelpReplacement::getList(); | |
| 35 | - $oTemplate = $oTemplating->loadTemplate("ktcore/manage_help"); | |
| 36 | - $aTemplateData = array( | |
| 37 | - "helps" => $aHelps, | |
| 38 | - ); | |
| 45 | + function handleOutput($data) { | |
| 46 | + global $main; | |
| 47 | + $main->bFormDisabled = true; | |
| 48 | + $main->setCentralPayload($data); | |
| 49 | + $main->render(); | |
| 50 | + } | |
| 39 | 51 | |
| 40 | - return $oTemplate->render($aTemplateData); | |
| 52 | + function do_editReplacement() { | |
| 53 | + $id = KTUtil::arrayGet($_REQUEST, 'id'); | |
| 54 | + $oHelpReplacement = KTHelpReplacement::get($id); | |
| 55 | + if (PEAR::isError($oHelpReplacement)) { | |
| 56 | + return $this->errorRedirectToMain("Could not find specified item"); | |
| 57 | + } | |
| 58 | + return $this->getReplacementItemData($oHelpReplacement); | |
| 59 | + } | |
| 60 | + | |
| 61 | + function do_deleteReplacement() { | |
| 62 | + $id = KTUtil::arrayGet($_REQUEST, 'id'); | |
| 63 | + $oHelpReplacement = KTHelpReplacement::get($id); | |
| 64 | + if (PEAR::isError($oHelpReplacement)) { | |
| 65 | + return $this->errorRedirectToMain("Could not find specified item"); | |
| 66 | + } | |
| 67 | + $res = $oHelpReplacement->delete(); | |
| 68 | + if (PEAR::isError($res)) { | |
| 69 | + return $this->errorRedirectToMain("Could not delete specified item"); | |
| 70 | + } | |
| 71 | + return $this->errorRedirectToMain("Item deleted"); | |
| 72 | + } | |
| 73 | + | |
| 74 | + function do_updateReplacement() { | |
| 75 | + $id = KTUtil::arrayGet($_REQUEST, 'id'); | |
| 76 | + $oHelpReplacement = KTHelpReplacement::get($id); | |
| 77 | + if (PEAR::isError($oHelpReplacement)) { | |
| 78 | + return $this->errorRedirectToMain("Could not find specified item"); | |
| 79 | + } | |
| 80 | + $description = KTUtil::arrayGet($_REQUEST, 'description'); | |
| 81 | + if (empty($description)) { | |
| 82 | + return $this->errorRedirectToMain("No description given"); | |
| 83 | + } | |
| 84 | + $oHelpReplacement->setDescription($description); | |
| 85 | + $res = $oHelpReplacement->update(); | |
| 86 | + if (PEAR::isError($res)) { | |
| 87 | + return $this->errorRedirectToMain("Error updating item"); | |
| 88 | + } | |
| 89 | + return $this->errorRedirectToMain("Item updated"); | |
| 90 | + } | |
| 91 | + | |
| 92 | + function do_customise() { | |
| 93 | + $name = KTUtil::arrayGet($_REQUEST, 'name'); | |
| 94 | + $oHelpReplacement = KTHelpReplacement::getByName($name); | |
| 95 | + // XXX: Check against "already exists" | |
| 96 | + if (!PEAR::isError($oHelpReplacement)) { | |
| 97 | + // Already exists... | |
| 98 | + return $this->redirectTo('editReplacement', 'id=' . $oHelpReplacement->getId()); | |
| 99 | + } | |
| 100 | + $description = KTHelp::getHelpFromFile($name); | |
| 101 | + $oHelpReplacement = KTHelpReplacement::createFromArray(array( | |
| 102 | + 'name' => $name, | |
| 103 | + 'description' => $description, | |
| 104 | + )); | |
| 105 | + if (PEAR::isError($oHelpReplacement)) { | |
| 106 | + return $this->errorRedirectToMain("Unable to create replacement"); | |
| 107 | + } | |
| 108 | + return $this->redirectTo('editReplacement', 'id=' . $oHelpReplacement->getId()); | |
| 109 | + } | |
| 41 | 110 | } |
| 42 | 111 | |
| 112 | +/* | |
| 43 | 113 | $id = KTUtil::arrayGet($_REQUEST, 'id'); |
| 44 | 114 | if ($id) { |
| 45 | 115 | $action = KTUtil::arrayGet($_REQUEST, 'action'); |
| 46 | - if ($action === "update") { | |
| 47 | - $oHelp =& KTHelpReplacement::get($id); | |
| 48 | - if (PEAR::isError($oHelp)) { | |
| 116 | + if ($action === "updateReplacement") { | |
| 117 | + $oHelpReplacement =& KTHelpReplacement::get($id); | |
| 118 | + if (PEAR::isError($oHelpReplacement)) { | |
| 49 | 119 | $_SESSION['KTErrorMessage'][] = "Help for that item not found"; |
| 50 | - exit(controllerRedirect('helpAdmin')); | |
| 120 | + exit(controllerRedirect('manageHelp')); | |
| 51 | 121 | } |
| 52 | 122 | $description = KTUtil::arrayGet($_REQUEST, 'description'); |
| 53 | 123 | if ($description) { |
| 54 | - $oHelp->setDescription($description); | |
| 55 | - $res = $oHelp->update(); | |
| 124 | + $oHelpReplacement->setDescription($description); | |
| 125 | + $res = $oHelpReplacement->update(); | |
| 56 | 126 | if (PEAR::isError($res)) { |
| 57 | 127 | $_SESSION['KTErrorMessage'][] = "Error updating |
| 58 | 128 | object"; |
| 59 | - $data = getItemData($id); | |
| 129 | + $data = getReplacementItemData($id); | |
| 60 | 130 | } else { |
| 61 | 131 | $_SESSION['KTErrorMessage'][] = "Updated"; |
| 62 | - exit(controllerRedirect('helpAdmin')); | |
| 132 | + exit(controllerRedirect('manageHelp')); | |
| 63 | 133 | } |
| 64 | 134 | } else { |
| 65 | 135 | $_SESSION['KTErrorMessage'][] = "No description given"; |
| 66 | - var_dump($_REQUEST); | |
| 67 | - exit(0); | |
| 68 | - $data = getItemData($id); | |
| 136 | + $data = getReplacementItemData($id); | |
| 69 | 137 | } |
| 70 | 138 | } else { |
| 71 | - $data = getItemData($id); | |
| 139 | + $data = getReplacementItemData($id); | |
| 72 | 140 | } |
| 73 | 141 | } else { |
| 74 | 142 | $data = getData(); |
| 75 | 143 | } |
| 76 | 144 | |
| 77 | -$sectionName = "Administration"; | |
| 145 | +// $sectionName = "Administration"; | |
| 78 | 146 | |
| 79 | -require_once(KT_DIR . "/presentation/webpageTemplate.inc"); | |
| 80 | -$main->bFormDisabled = true; | |
| 81 | -$main->setCentralPayload($data); | |
| 82 | -$main->render(); | |
| 147 | +// require_once(KT_DIR . "/presentation/webpageTemplate.inc"); | |
| 148 | +// $main->bFormDisabled = true; | |
| 149 | +// $main->setCentralPayload($data); | |
| 150 | +// $main->render(); | |
| 151 | +*/ | |
| 152 | + | |
| 153 | +$oDispatcher = new ManageHelpDispatcher(); | |
| 154 | +$oDispatcher->dispatch(); | |
| 83 | 155 | |
| 84 | 156 | ?> | ... | ... |