Commit b653eae2b6b8163eb3a20d548f04f1397778f496
1 parent
819e369a
(#2760) fixed delete unit business logic
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@2390 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
56 additions
and
115 deletions
presentation/lookAndFeel/knowledgeTree/administration/unitmanagement/removeUnitBL.php
| ... | ... | @@ -25,42 +25,55 @@ if (checkSession()) { |
| 25 | 25 | |
| 26 | 26 | $oPatternCustom = & new PatternCustom(); |
| 27 | 27 | |
| 28 | - // get main page | |
| 29 | - if (isset($fUnitID)) { | |
| 30 | - $fOrgID = UnitOrganisationLink::unitBelongsToOrg($fUnitID); | |
| 31 | - | |
| 32 | - if(!$fOrgID) { $fOrgID = null;} | |
| 33 | - | |
| 34 | - $oPatternCustom->setHtml(getDeleteConfirmedPage($fUnitID,$fOrgID)); | |
| 35 | - $main->setFormAction($_SERVER["PHP_SELF"] . "?fForDeleteConfirmed=1"); | |
| 36 | - } else { | |
| 37 | - $oPatternCustom->setHtml(getDeletePage(null)); | |
| 38 | - $main->setFormAction($_SERVER["PHP_SELF"]); | |
| 39 | - } | |
| 40 | - | |
| 41 | - if (isset($fForDeleteConfirmed)) { | |
| 42 | - // get unitorg object | |
| 43 | - if ($fOrgID > 0) { | |
| 44 | - $oUnitOrg = new UnitOrganisationLink($fUnitID,$fOrgID); | |
| 45 | - $oUnitOrg->setUnitOrgID($fUnitID); | |
| 46 | - | |
| 47 | - //delete unitorgobject | |
| 48 | - $oUnitOrg->delete(); | |
| 49 | - } | |
| 50 | - //get unit object | |
| 28 | + if ($fUnitID) { | |
| 29 | + // retrieve unit object | |
| 51 | 30 | $oUnit = Unit::get($fUnitID); |
| 52 | - $oUnit->setName($fUnitName); | |
| 53 | - | |
| 54 | - | |
| 55 | - //delete unit object | |
| 56 | - if ($oUnit->delete()) { | |
| 57 | - $oPatternCustom->setHtml(getDeleteSuccessPage()); | |
| 58 | - } else { | |
| 59 | - $oPatternCustom->setHtml(getDeleteFailPage()); | |
| 60 | - } | |
| 31 | + if ($oUnit) { | |
| 32 | + | |
| 33 | + // if the unit has groups linked to it, then it can't be deleted | |
| 34 | + if ($oUnit->hasGroups()) { | |
| 35 | + // display error message | |
| 36 | + $oPatternCustom->setHtml(getStatusPage("Can't delete Unit '" . $oUnit->getName() . "'", "Please remove all groups belonging to this Unit before attempting to delete it")); | |
| 37 | + } else { | |
| 38 | + // retrieve organisation link (for later deletion or to get the organisation id) | |
| 39 | + $oUnitOrg = UnitOrganisationLink::getByUnitID($fUnitID); | |
| 40 | + | |
| 41 | + // we've received confirmation, so delete | |
| 42 | + if (isset($fForDeleteConfirmed)) { | |
| 43 | + //delete unit object | |
| 44 | + if ($oUnit->delete()) { | |
| 45 | + // delete the link between this unit and its organisation if there is one | |
| 46 | + if ($oUnitOrg) { | |
| 47 | + if ($oUnitOrg->delete()) { | |
| 48 | + $oPatternCustom->setHtml(getStatusPage("Unit SuccessFully Removed!")); | |
| 49 | + } else { | |
| 50 | + // couldn't delete the link to the organisation | |
| 51 | + $oPatternCustom->setHtml(getStatusPage("Deletion of Unit Organisation Link Failed!", "The Unit was deleted, but the link to the Organisation could not be deleted")); | |
| 52 | + } | |
| 53 | + } else { | |
| 54 | + // no organisation mapped | |
| 55 | + $oPatternCustom->setHtml(getStatusPage("Unit SuccessFully Removed!")); | |
| 56 | + } | |
| 57 | + } else { | |
| 58 | + $oPatternCustom->setHtml(getStatusPage("Deletion of Unit '" . $oUnit->getName() . "' Failed!")); | |
| 59 | + } | |
| 60 | + // ask for confirmation before deleting | |
| 61 | + } else { | |
| 62 | + $oOrganisation = Organisation::get($oUnitOrg->getOrgID()); | |
| 63 | + $oPatternCustom->setHtml(getConfirmDeletePage($oUnit, $oOrganisation)); | |
| 64 | + $main->setFormAction($_SERVER["PHP_SELF"] . "?fForDeleteConfirmed=1"); | |
| 65 | + } | |
| 66 | + } | |
| 67 | + } else { | |
| 68 | + // couldn't retrieve unit from db | |
| 69 | + $oPatternCustom->setHtml(getStatusPage("No Unit selected for deletion.")); | |
| 70 | + } | |
| 71 | + } else { | |
| 72 | + // no params received, error | |
| 73 | + $oPatternCustom->setHtml(getStatusPage("No Unit selected for deletion.")); | |
| 61 | 74 | } |
| 62 | 75 | |
| 63 | 76 | $main->setCentralPayload($oPatternCustom); |
| 64 | 77 | $main->render(); |
| 65 | 78 | } |
| 66 | 79 | -?> |
| 80 | +?> | |
| 67 | 81 | \ No newline at end of file | ... | ... |
presentation/lookAndFeel/knowledgeTree/administration/unitmanagement/removeUnitUI.inc
| ... | ... | @@ -8,26 +8,20 @@ |
| 8 | 8 | * @package presentation.lookAndFeel.knowledgeTree. |
| 9 | 9 | * |
| 10 | 10 | */ |
| 11 | -// gets the delete stuff | |
| 12 | -function getDeletePage($iUnitID) { | |
| 11 | + | |
| 12 | +function getConfirmDeletePage($oUnit, $oOrg) { | |
| 13 | 13 | global $default; |
| 14 | - $oUnit = null; | |
| 15 | - if (isset($iUnitID)) { | |
| 16 | - $oUnit = Unit::get($iUnitID); | |
| 17 | - $sHeading .= "<b>Are you sure you wish to Remove this Unit?:</b>\n"; | |
| 18 | - } else { | |
| 19 | - $sHeading .= "Please select a Unit: "; | |
| 20 | - } | |
| 21 | 14 | |
| 22 | 15 | $sToRender .= renderHeading("Remove Unit"); |
| 23 | 16 | $sToRender .= "<table>\n"; |
| 24 | - $sToRender .= "<tr><td>$sHeading</td></tr>\n"; | |
| 17 | + $sToRender .= "<tr><td><b>Are you sure you wish to Remove this Unit:</b></td></tr>\n"; | |
| 25 | 18 | $sToRender .= "<tr>\n"; |
| 26 | - $sToRender .= "<td>Unit Name: </td>" . getUnitDisplay($oUnit) . "\n"; | |
| 19 | + $sToRender .= "<td>Unit Name: " . getUnitDisplay($oUnit) . "</td>\n"; | |
| 27 | 20 | $sToRender .= "</tr>\n"; |
| 28 | 21 | $sToRender .= "<tr>\n"; |
| 29 | 22 | $sToRender .= "</tr>\n"; |
| 30 | 23 | $sToRender .= "<tr>\n"; |
| 24 | + $sToRender .= "<td>Organisation Name: " . getOrgDisplay($oOrg) . "</td>\n"; | |
| 31 | 25 | $sToRender .= "</tr>\n"; |
| 32 | 26 | $sToRender .= "<tr>\n"; |
| 33 | 27 | $sToRender .= "</tr>\n"; |
| ... | ... | @@ -36,93 +30,25 @@ function getDeletePage($iUnitID) { |
| 36 | 30 | $sToRender .= "</tr>\n"; |
| 37 | 31 | $sToRender .= "</table>\n"; |
| 38 | 32 | |
| 39 | - | |
| 40 | - return $sToRender; | |
| 41 | -} | |
| 42 | - | |
| 43 | -// get successfully deletion page | |
| 44 | -function getDeleteSuccessPage() { | |
| 45 | - | |
| 46 | - global $default; | |
| 47 | - | |
| 48 | - $sToRender .= renderHeading("Remove Unit"); | |
| 49 | - $sToRender .= "<table>\n"; | |
| 50 | - $sToRender .= "<tr>\n"; | |
| 51 | - $sToRender .= "<td><b>Unit SuccessFully Removed!</b></td>\n"; | |
| 52 | - $sToRender .= "</tr>\n"; | |
| 53 | - $sToRender .= "<tr></tr>\n"; | |
| 54 | - $sToRender .= "<tr></tr>\n"; | |
| 55 | - $sToRender .= "<tr></tr>\n"; | |
| 56 | - $sToRender .= "<tr></tr>\n"; | |
| 57 | - $sToRender .= "<tr>\n"; | |
| 58 | - $sToRender .= "<td align = right><a href=\"$default->rootUrl/control.php?action=listUnits\"><img src =\"$default->graphicsUrl/widgets/back.gif\" border = \"0\" /></a></td>\n"; | |
| 59 | - $sToRender .= "</tr>\n"; | |
| 60 | - $sToRender .= "</table>\n"; | |
| 61 | - | |
| 62 | 33 | return $sToRender; |
| 63 | 34 | } |
| 64 | 35 | |
| 65 | -// get deletion failed page | |
| 66 | -function getDeleteFailPage() { | |
| 36 | +function getStatusPage($sHeading, $sText = "") { | |
| 67 | 37 | |
| 68 | 38 | global $default; |
| 69 | 39 | |
| 70 | 40 | $sToRender .= renderHeading("Remove Unit"); |
| 71 | 41 | $sToRender .= "<table>\n"; |
| 72 | 42 | $sToRender .= "<tr>\n"; |
| 73 | - $sToRender .= "<td><b>Deletion Failed!</b></td>\n"; | |
| 74 | - $sToRender .= "</tr>\n"; | |
| 75 | - $sToRender .= "<tr></tr>\n"; | |
| 76 | - $sToRender .= "<tr></tr>\n"; | |
| 77 | - $sToRender .= "<tr><td>Please Ensure that the unit has no groups belonging to it</td></tr>\n"; | |
| 78 | - $sToRender .= "<tr></tr>\n"; | |
| 43 | + $sToRender .= "<td><b>$sHeading</b></td>\n"; | |
| 79 | 44 | $sToRender .= "</tr>\n"; |
| 45 | + $sToRender .= "<tr><td>$sText</td></tr>\n"; | |
| 80 | 46 | $sToRender .= "<tr><td align = right><a href=\"$default->rootUrl/control.php?action=listUnits\"><img src =\"$default->graphicsUrl/widgets/back.gif\" border = \"0\" /></a></td></tr>\n"; |
| 81 | 47 | $sToRender .= "</table>\n"; |
| 82 | 48 | |
| 83 | 49 | return $sToRender; |
| 84 | 50 | } |
| 85 | 51 | |
| 86 | - | |
| 87 | -function getDeleteConfirmedPage($iUnitID,$iOrgID) { | |
| 88 | - global $default; | |
| 89 | - $oUnit = null; | |
| 90 | - if (isset($iUnitID)) { | |
| 91 | - $oUnit = Unit::get($iUnitID); | |
| 92 | - } | |
| 93 | - | |
| 94 | - if (isset($iOrgID)) { | |
| 95 | - $oOrg = Organisation::get($iOrgID); | |
| 96 | - } | |
| 97 | - | |
| 98 | - if($oOrg){ | |
| 99 | - $sOrgValue = getOrgDisplay($oOrg); | |
| 100 | - } else { | |
| 101 | - $sOrgValue = "<b>* Not Assigned to an Organisation<b>"; | |
| 102 | - } | |
| 103 | - | |
| 104 | - $sToRender .= renderHeading("Remove Unit"); | |
| 105 | - $sToRender .= "<table>\n"; | |
| 106 | - $sToRender .= "<tr><td><b>Are you sure you wish to Remove this Unit?:</b></td></tr>\n"; | |
| 107 | - $sToRender .= "<tr>\n"; | |
| 108 | - $sToRender .= "<td>Unit Name: " . getUnitDisplay($oUnit) . "</td>\n"; | |
| 109 | - $sToRender .= "</tr>\n"; | |
| 110 | - $sToRender .= "<tr>\n"; | |
| 111 | - $sToRender .= "</tr>\n"; | |
| 112 | - $sToRender .= "<tr>\n"; | |
| 113 | - $sToRender .= "<td>Organisation Name: " . $sOrgValue . "</td>\n"; | |
| 114 | - $sToRender .= "</tr>\n"; | |
| 115 | - $sToRender .= "<tr>\n"; | |
| 116 | - $sToRender .= "</tr>\n"; | |
| 117 | - $sToRender .= "<tr>\n"; | |
| 118 | - $sToRender .= getDeleteButton($oUnit); | |
| 119 | - $sToRender .= "</tr>\n"; | |
| 120 | - $sToRender .= "</table>\n"; | |
| 121 | - | |
| 122 | - return $sToRender; | |
| 123 | -} | |
| 124 | - | |
| 125 | - | |
| 126 | 52 | // show listbox...or the text name |
| 127 | 53 | function getUnitDisplay($oUnit) { |
| 128 | 54 | global $default; |
| ... | ... | @@ -144,6 +70,8 @@ function getOrgDisplay($oOrg) { |
| 144 | 70 | if (isset($oOrg)) { |
| 145 | 71 | return "<input type=\"hidden\" name=\"fOrgID\" value=\"" . $oOrg->iId . "\">\n" . |
| 146 | 72 | "<b>" . $oOrg->getName() . "</b>"; |
| 73 | + } else { | |
| 74 | + return "<b>* Not Assigned to an Organisation<b>"; | |
| 147 | 75 | } |
| 148 | 76 | } |
| 149 | 77 | ... | ... |