Commit 3d234db59d3147cb11aa441f94ae41a82f10d4d6
1 parent
de1e43bd
fix for KTS-491: group is unitadmin without having a unit.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5940 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
387 additions
and
305 deletions
plugins/ktcore/admin/groupManagement.php
| ... | ... | @@ -33,6 +33,7 @@ require_once(KT_LIB_DIR . "/templating/templating.inc.php"); |
| 33 | 33 | require_once(KT_LIB_DIR . "/dispatcher.inc.php"); |
| 34 | 34 | require_once(KT_LIB_DIR . "/templating/kt3template.inc.php"); |
| 35 | 35 | require_once(KT_LIB_DIR . "/widgets/fieldWidgets.php"); |
| 36 | +require_once(KT_LIB_DIR . "/widgets/forms.inc.php"); | |
| 36 | 37 | |
| 37 | 38 | require_once(KT_LIB_DIR . "/authentication/authenticationsource.inc.php"); |
| 38 | 39 | require_once(KT_LIB_DIR . "/authentication/authenticationproviderregistry.inc.php"); |
| ... | ... | @@ -41,18 +42,24 @@ require_once(KT_LIB_DIR . "/authentication/builtinauthenticationprovider.inc.php |
| 41 | 42 | class KTGroupAdminDispatcher extends KTAdminDispatcher { |
| 42 | 43 | // {{{ do_main |
| 43 | 44 | var $sHelpPage = 'ktcore/admin/manage groups.html'; |
| 45 | + | |
| 46 | + function predispatch() { | |
| 47 | + $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('Group Management')); | |
| 48 | + $this->persistParams(array('old_search')); | |
| 49 | + } | |
| 50 | + | |
| 44 | 51 | function do_main() { |
| 45 | - $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('Group Management')); | |
| 46 | - $this->oPage->setBreadcrumbDetails(_kt('select a group')); | |
| 47 | - $this->oPage->setTitle(_kt("Group Management")); | |
| 48 | - | |
| 49 | - $KTConfig =& KTConfig::getSingleton(); | |
| 52 | + | |
| 53 | + $this->oPage->setBreadcrumbDetails(_kt('select a group')); | |
| 54 | + $this->oPage->setTitle(_kt("Group Management")); | |
| 55 | + | |
| 56 | + $KTConfig =& KTConfig::getSingleton(); | |
| 50 | 57 | $alwaysAll = $KTConfig->get("alwaysShowAll"); |
| 51 | - | |
| 52 | - $name = KTUtil::arrayGet($_REQUEST, 'search_name', KTUtil::arrayGet($_REQUEST, 'old_search')); | |
| 53 | - $show_all = KTUtil::arrayGet($_REQUEST, 'show_all', $alwaysAll); | |
| 54 | - $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); | |
| 55 | - | |
| 58 | + | |
| 59 | + $name = KTUtil::arrayGet($_REQUEST, 'search_name', KTUtil::arrayGet($_REQUEST, 'old_search')); | |
| 60 | + $show_all = KTUtil::arrayGet($_REQUEST, 'show_all', $alwaysAll); | |
| 61 | + $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); | |
| 62 | + | |
| 56 | 63 | $no_search = true; |
| 57 | 64 | |
| 58 | 65 | if (KTUtil::arrayGet($_REQUEST, 'do_search', false) != false) { |
| ... | ... | @@ -62,30 +69,30 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { |
| 62 | 69 | if ($name == '*') { |
| 63 | 70 | $show_all = true; |
| 64 | 71 | $name = ''; |
| 65 | - } | |
| 66 | - | |
| 67 | - $search_fields = array(); | |
| 68 | - $search_fields[] = new KTStringWidget(_kt('Group Name'), _kt("Enter part of the group's name. e.g. <strong>ad</strong> will match <strong>administrators</strong>."), 'search_name', $name, $this->oPage, true); | |
| 69 | - | |
| 70 | - if (!empty($name)) { | |
| 71 | - $search_results =& Group::getList('WHERE name LIKE \'%' . DBUtil::escapeSimple($name) . '%\' AND id > 0'); | |
| 72 | - } else if ($show_all !== false) { | |
| 73 | - $search_results =& Group::getList('id > 0'); | |
| 74 | - $no_search = false; | |
| 75 | - $name = '*'; | |
| 76 | - } | |
| 77 | - | |
| 78 | - | |
| 79 | - $oTemplating =& KTTemplating::getSingleton(); | |
| 80 | - $oTemplate = $oTemplating->loadTemplate("ktcore/principals/groupadmin"); | |
| 81 | - $aTemplateData = array( | |
| 82 | - "context" => $this, | |
| 83 | - "search_fields" => $search_fields, | |
| 84 | - "search_results" => $search_results, | |
| 85 | - 'no_search' => $no_search, | |
| 86 | - 'old_search' => $name, | |
| 87 | - ); | |
| 88 | - return $oTemplate->render($aTemplateData); | |
| 72 | + } | |
| 73 | + | |
| 74 | + $search_fields = array(); | |
| 75 | + $search_fields[] = new KTStringWidget(_kt('Group Name'), _kt("Enter part of the group's name. e.g. <strong>ad</strong> will match <strong>administrators</strong>."), 'search_name', $name, $this->oPage, true); | |
| 76 | + | |
| 77 | + if (!empty($name)) { | |
| 78 | + $search_results =& Group::getList('WHERE name LIKE \'%' . DBUtil::escapeSimple($name) . '%\' AND id > 0'); | |
| 79 | + } else if ($show_all !== false) { | |
| 80 | + $search_results =& Group::getList('id > 0'); | |
| 81 | + $no_search = false; | |
| 82 | + $name = '*'; | |
| 83 | + } | |
| 84 | + | |
| 85 | + | |
| 86 | + $oTemplating =& KTTemplating::getSingleton(); | |
| 87 | + $oTemplate = $oTemplating->loadTemplate("ktcore/principals/groupadmin"); | |
| 88 | + $aTemplateData = array( | |
| 89 | + "context" => $this, | |
| 90 | + "search_fields" => $search_fields, | |
| 91 | + "search_results" => $search_results, | |
| 92 | + 'no_search' => $no_search, | |
| 93 | + 'old_search' => $name, | |
| 94 | + ); | |
| 95 | + return $oTemplate->render($aTemplateData); | |
| 89 | 96 | } |
| 90 | 97 | // }}} |
| 91 | 98 | |
| ... | ... | @@ -93,92 +100,92 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { |
| 93 | 100 | function do_editGroup() { |
| 94 | 101 | $old_search = KTUtil::arrayGet($_REQUEST, 'old_search'); |
| 95 | 102 | |
| 96 | - $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('Group Management')); | |
| 97 | - $this->oPage->setBreadcrumbDetails(_kt('edit group')); | |
| 98 | - | |
| 99 | - $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); | |
| 100 | - $oGroup = Group::get($group_id); | |
| 101 | - if (PEAR::isError($oGroup) || $oGroup == false) { | |
| 102 | - $this->errorRedirectToMain(_kt('Please select a valid group.'), sprintf("old_search=%s&do_search=1", $old_search)); | |
| 103 | - } | |
| 104 | - | |
| 105 | - $this->oPage->setTitle(sprintf(_kt("Edit Group (%s)"), $oGroup->getName())); | |
| 106 | - | |
| 107 | - $edit_fields = array(); | |
| 108 | - $edit_fields[] = new KTStringWidget(_kt('Group Name'), _kt('A short name for the group. e.g. <strong>administrators</strong>.'), 'group_name', $oGroup->getName(), $this->oPage, true); | |
| 109 | - $edit_fields[] = new KTCheckboxWidget(_kt('Unit Administrators'), _kt('Should all the members of this group be given <strong>unit</strong> administration privileges?'), 'is_unitadmin', $oGroup->getUnitAdmin(), $this->oPage, false); | |
| 110 | - $edit_fields[] = new KTCheckboxWidget(_kt('System Administrators'), _kt('Should all the members of this group be given <strong>system</strong> administration privileges?'), 'is_sysadmin', $oGroup->getSysAdmin(), $this->oPage, false); | |
| 111 | - | |
| 112 | - // grab all units. | |
| 113 | - $unitId = $oGroup->getUnitId(); | |
| 114 | - if ($unitId == null) { $unitId = 0; } | |
| 115 | - | |
| 116 | - $oUnits = Unit::getList(); | |
| 117 | - $vocab = array(); | |
| 118 | - $vocab[0] = _kt('No Unit'); | |
| 119 | - foreach ($oUnits as $oUnit) { $vocab[$oUnit->getID()] = $oUnit->getName(); } | |
| 120 | - $aOptions = array('vocab' => $vocab); | |
| 121 | - | |
| 122 | - $edit_fields[] = new KTLookupWidget(_kt('Unit'), _kt('Which Unit is this group part of?'), 'unit_id', $unitId, $this->oPage, false, null, null, $aOptions); | |
| 123 | - | |
| 124 | - $oTemplating =& KTTemplating::getSingleton(); | |
| 125 | - $oTemplate = $oTemplating->loadTemplate("ktcore/principals/editgroup"); | |
| 126 | - $aTemplateData = array( | |
| 127 | - "context" => $this, | |
| 128 | - "edit_fields" => $edit_fields, | |
| 129 | - "edit_group" => $oGroup, | |
| 103 | + | |
| 104 | + $this->oPage->setBreadcrumbDetails(_kt('edit group')); | |
| 105 | + | |
| 106 | + $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); | |
| 107 | + $oGroup = Group::get($group_id); | |
| 108 | + if (PEAR::isError($oGroup) || $oGroup == false) { | |
| 109 | + $this->errorRedirectToMain(_kt('Please select a valid group.'), sprintf("old_search=%s&do_search=1", $old_search)); | |
| 110 | + } | |
| 111 | + | |
| 112 | + $this->oPage->setTitle(sprintf(_kt("Edit Group (%s)"), $oGroup->getName())); | |
| 113 | + | |
| 114 | + $edit_fields = array(); | |
| 115 | + $edit_fields[] = new KTStringWidget(_kt('Group Name'), _kt('A short name for the group. e.g. <strong>administrators</strong>.'), 'group_name', $oGroup->getName(), $this->oPage, true); | |
| 116 | + $edit_fields[] = new KTCheckboxWidget(_kt('Unit Administrators'), _kt('Should all the members of this group be given <strong>unit</strong> administration privileges?'), 'is_unitadmin', $oGroup->getUnitAdmin(), $this->oPage, false); | |
| 117 | + $edit_fields[] = new KTCheckboxWidget(_kt('System Administrators'), _kt('Should all the members of this group be given <strong>system</strong> administration privileges?'), 'is_sysadmin', $oGroup->getSysAdmin(), $this->oPage, false); | |
| 118 | + | |
| 119 | + // grab all units. | |
| 120 | + $unitId = $oGroup->getUnitId(); | |
| 121 | + if ($unitId == null) { $unitId = 0; } | |
| 122 | + | |
| 123 | + $oUnits = Unit::getList(); | |
| 124 | + $vocab = array(); | |
| 125 | + $vocab[0] = _kt('No Unit'); | |
| 126 | + foreach ($oUnits as $oUnit) { $vocab[$oUnit->getID()] = $oUnit->getName(); } | |
| 127 | + $aOptions = array('vocab' => $vocab); | |
| 128 | + | |
| 129 | + $edit_fields[] = new KTLookupWidget(_kt('Unit'), _kt('Which Unit is this group part of?'), 'unit_id', $unitId, $this->oPage, false, null, null, $aOptions); | |
| 130 | + | |
| 131 | + $oTemplating =& KTTemplating::getSingleton(); | |
| 132 | + $oTemplate = $oTemplating->loadTemplate("ktcore/principals/editgroup"); | |
| 133 | + $aTemplateData = array( | |
| 134 | + "context" => $this, | |
| 135 | + "edit_fields" => $edit_fields, | |
| 136 | + "edit_group" => $oGroup, | |
| 130 | 137 | "old_search" => $old_search, |
| 131 | - ); | |
| 132 | - return $oTemplate->render($aTemplateData); | |
| 138 | + ); | |
| 139 | + return $oTemplate->render($aTemplateData); | |
| 133 | 140 | } |
| 134 | 141 | // }}} |
| 135 | 142 | |
| 136 | 143 | // {{{ do_saveGroup |
| 137 | - function do_saveGroup() { | |
| 144 | + function do_saveGroup() { | |
| 138 | 145 | $old_search = KTUtil::arrayGet($_REQUEST, 'old_search'); |
| 139 | 146 | |
| 140 | - $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); | |
| 141 | - $oGroup = Group::get($group_id); | |
| 142 | - if (PEAR::isError($oGroup) || $oGroup == false) { | |
| 143 | - $this->errorRedirectToMain(_kt('Please select a valid group.'), sprintf("old_search=%s&do_search=1", $old_search)); | |
| 144 | - } | |
| 145 | - $group_name = KTUtil::arrayGet($_REQUEST, 'group_name'); | |
| 146 | - if (empty($group_name)) { $this->errorRedirectToMain(_kt('Please specify a name for the group.')); } | |
| 147 | - $is_unitadmin = KTUtil::arrayGet($_REQUEST, 'is_unitadmin', false); | |
| 148 | - if ($is_unitadmin !== false) { $is_unitadmin = true; } | |
| 149 | - $is_sysadmin = KTUtil::arrayGet($_REQUEST, 'is_sysadmin', false); | |
| 150 | - if ($is_sysadmin !== false) { $is_sysadmin = true; } | |
| 151 | - | |
| 152 | - $this->startTransaction(); | |
| 153 | - | |
| 154 | - $oGroup->setName($group_name); | |
| 155 | - $oGroup->setUnitAdmin($is_unitadmin); | |
| 156 | - $oGroup->setSysAdmin($is_sysadmin); | |
| 157 | - | |
| 158 | - $unit_id = KTUtil::arrayGet($_REQUEST, 'unit_id', 0); | |
| 159 | - if ($unit_id == 0) { // not set, or set to 0. | |
| 160 | - $oGroup->setUnitId(null); // safe. | |
| 161 | - } else { | |
| 162 | - $oGroup->setUnitId($unit_id); | |
| 163 | - } | |
| 164 | - | |
| 165 | - $res = $oGroup->update(); | |
| 166 | - if (($res == false) || (PEAR::isError($res))) { return $this->errorRedirectToMain(_kt('Failed to set group details.'), sprintf("old_search=%s&do_search=1", $old_search)); } | |
| 167 | - | |
| 168 | - if (!Permission::userIsSystemAdministrator($_SESSION['userID'])) { | |
| 169 | - $this->rollbackTransaction(); | |
| 170 | - $this->errorRedirectTo('editGroup', _kt('For security purposes, you cannot remove your own administration priviledges.'), sprintf('group_id=%d', $oGroup->getId()), sprintf("old_search=%s&do_search=1", $old_search)); | |
| 171 | - exit(0); | |
| 172 | - } | |
| 173 | - | |
| 174 | - | |
| 175 | - $this->commitTransaction(); | |
| 176 | - if($unit_id == 0 && $is_unitadmin) { | |
| 177 | - $this->successRedirectToMain(_kt('Group details updated.') . _kt(' Note: group is set as unit administrator, but is not assigned to a unit.'), sprintf("old_search=%s&do_search=1", $old_search)); | |
| 178 | - } else { | |
| 179 | - $this->successRedirectToMain(_kt('Group details updated.'), sprintf("old_search=%s&do_search=1", $old_search)); | |
| 180 | - } | |
| 181 | - } | |
| 147 | + $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); | |
| 148 | + $oGroup = Group::get($group_id); | |
| 149 | + if (PEAR::isError($oGroup) || $oGroup == false) { | |
| 150 | + $this->errorRedirectToMain(_kt('Please select a valid group.'), sprintf("old_search=%s&do_search=1", $old_search)); | |
| 151 | + } | |
| 152 | + $group_name = KTUtil::arrayGet($_REQUEST, 'group_name'); | |
| 153 | + if (empty($group_name)) { $this->errorRedirectToMain(_kt('Please specify a name for the group.')); } | |
| 154 | + $is_unitadmin = KTUtil::arrayGet($_REQUEST, 'is_unitadmin', false); | |
| 155 | + if ($is_unitadmin !== false) { $is_unitadmin = true; } | |
| 156 | + $is_sysadmin = KTUtil::arrayGet($_REQUEST, 'is_sysadmin', false); | |
| 157 | + if ($is_sysadmin !== false) { $is_sysadmin = true; } | |
| 158 | + | |
| 159 | + $this->startTransaction(); | |
| 160 | + | |
| 161 | + $oGroup->setName($group_name); | |
| 162 | + $oGroup->setUnitAdmin($is_unitadmin); | |
| 163 | + $oGroup->setSysAdmin($is_sysadmin); | |
| 164 | + | |
| 165 | + $unit_id = KTUtil::arrayGet($_REQUEST, 'unit_id', 0); | |
| 166 | + if ($unit_id == 0) { // not set, or set to 0. | |
| 167 | + $oGroup->setUnitId(null); // safe. | |
| 168 | + } else { | |
| 169 | + $oGroup->setUnitId($unit_id); | |
| 170 | + } | |
| 171 | + | |
| 172 | + $res = $oGroup->update(); | |
| 173 | + if (($res == false) || (PEAR::isError($res))) { return $this->errorRedirectToMain(_kt('Failed to set group details.'), sprintf("old_search=%s&do_search=1", $old_search)); } | |
| 174 | + | |
| 175 | + if (!Permission::userIsSystemAdministrator($_SESSION['userID'])) { | |
| 176 | + $this->rollbackTransaction(); | |
| 177 | + $this->errorRedirectTo('editGroup', _kt('For security purposes, you cannot remove your own administration priviledges.'), sprintf('group_id=%d', $oGroup->getId()), sprintf("old_search=%s&do_search=1", $old_search)); | |
| 178 | + exit(0); | |
| 179 | + } | |
| 180 | + | |
| 181 | + | |
| 182 | + $this->commitTransaction(); | |
| 183 | + if($unit_id == 0 && $is_unitadmin) { | |
| 184 | + $this->successRedirectToMain(_kt('Group details updated.') . _kt(' Note: group is set as unit administrator, but is not assigned to a unit.'), sprintf("old_search=%s&do_search=1", $old_search)); | |
| 185 | + } else { | |
| 186 | + $this->successRedirectToMain(_kt('Group details updated.'), sprintf("old_search=%s&do_search=1", $old_search)); | |
| 187 | + } | |
| 188 | + } | |
| 182 | 189 | // }}} |
| 183 | 190 | |
| 184 | 191 | function _do_manageUsers_source() { |
| ... | ... | @@ -191,9 +198,9 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { |
| 191 | 198 | $oTemplate = $this->oValidator->validateTemplate("ktcore/principals/groups_sourceusers"); |
| 192 | 199 | $aTemplateData = array( |
| 193 | 200 | "context" => $this, |
| 194 | - 'group_users' => $aGroupUsers, | |
| 195 | - 'group' => $oGroup, | |
| 196 | - "old_search" => $old_search, | |
| 201 | + 'group_users' => $aGroupUsers, | |
| 202 | + 'group' => $oGroup, | |
| 203 | + "old_search" => $old_search, | |
| 197 | 204 | ); |
| 198 | 205 | return $oTemplate->render($aTemplateData); |
| 199 | 206 | } |
| ... | ... | @@ -218,7 +225,7 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { |
| 218 | 225 | $this->errorRedirectToMain(_kt('No such group.')); |
| 219 | 226 | } |
| 220 | 227 | |
| 221 | - $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('Group Management')); | |
| 228 | + | |
| 222 | 229 | $this->aBreadcrumbs[] = array('name' => $oGroup->getName()); |
| 223 | 230 | $this->oPage->setBreadcrumbDetails(_kt('manage members')); |
| 224 | 231 | $this->oPage->setTitle(sprintf(_kt('Manage members of group %s'), $oGroup->getName())); |
| ... | ... | @@ -244,21 +251,21 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { |
| 244 | 251 | } |
| 245 | 252 | } |
| 246 | 253 | |
| 247 | - $oJSONWidget = new KTJSONLookupWidget(_kt('Users'), | |
| 248 | - _kt('Select the users which should be part of this group from the left-hand list and then click the <strong>right pointing arrows</strong>. Once you have added all the users that you require, press <strong>save changes</strong>.'), | |
| 249 | - 'users', '', $this->oPage, false, null, null, | |
| 250 | - array('action'=>'getUsers', | |
| 251 | - 'assigned' => $aGroupUsers, | |
| 252 | - 'multi'=>'true', | |
| 253 | - 'size'=>'8')); | |
| 254 | + $oJSONWidget = new KTJSONLookupWidget(_kt('Users'), | |
| 255 | + _kt('Select the users which should be part of this group from the left-hand list and then click the <strong>right pointing arrows</strong>. Once you have added all the users that you require, press <strong>save changes</strong>.'), | |
| 256 | + 'users', '', $this->oPage, false, null, null, | |
| 257 | + array('action'=>'getUsers', | |
| 258 | + 'assigned' => $aGroupUsers, | |
| 259 | + 'multi'=>'true', | |
| 260 | + 'size'=>'8')); | |
| 254 | 261 | |
| 255 | 262 | $oTemplating =& KTTemplating::getSingleton(); |
| 256 | 263 | $oTemplate = $oTemplating->loadTemplate("ktcore/principals/groups_manageusers"); |
| 257 | 264 | $aTemplateData = array( |
| 258 | 265 | "context" => $this, |
| 259 | 266 | "edit_group" => $oGroup, |
| 260 | - 'widget' => $oJSONWidget, | |
| 261 | - "old_search" => $old_search, | |
| 267 | + 'widget' => $oJSONWidget, | |
| 268 | + "old_search" => $old_search, | |
| 262 | 269 | ); |
| 263 | 270 | return $oTemplate->render($aTemplateData); |
| 264 | 271 | } |
| ... | ... | @@ -266,17 +273,17 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { |
| 266 | 273 | |
| 267 | 274 | |
| 268 | 275 | function json_getUsers() { |
| 269 | - $sFilter = KTUtil::arrayGet($_REQUEST, 'filter', false); | |
| 270 | - $aUserList = array('off'=>'-- Please filter --'); | |
| 271 | - | |
| 272 | - if($sFilter && trim($sFilter)) { | |
| 273 | - $aUsers = User::getList(sprintf('name like "%%%s%%"', $sFilter)); | |
| 274 | - $aUserList = array(); | |
| 275 | - foreach($aUsers as $oUser) { | |
| 276 | - $aUserList[$oUser->getId()] = $oUser->getName(); | |
| 277 | - } | |
| 278 | - } | |
| 279 | - return $aUserList; | |
| 276 | + $sFilter = KTUtil::arrayGet($_REQUEST, 'filter', false); | |
| 277 | + $aUserList = array('off'=>'-- Please filter --'); | |
| 278 | + | |
| 279 | + if($sFilter && trim($sFilter)) { | |
| 280 | + $aUsers = User::getList(sprintf('name like "%%%s%%"', $sFilter)); | |
| 281 | + $aUserList = array(); | |
| 282 | + foreach($aUsers as $oUser) { | |
| 283 | + $aUserList[$oUser->getId()] = $oUser->getName(); | |
| 284 | + } | |
| 285 | + } | |
| 286 | + return $aUserList; | |
| 280 | 287 | } |
| 281 | 288 | |
| 282 | 289 | |
| ... | ... | @@ -301,24 +308,24 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { |
| 301 | 308 | $usersAdded = array(); |
| 302 | 309 | $usersRemoved = array(); |
| 303 | 310 | |
| 304 | - $addWarnings = array(); | |
| 305 | - $removeWarnings = array(); | |
| 311 | + $addWarnings = array(); | |
| 312 | + $removeWarnings = array(); | |
| 306 | 313 | |
| 307 | - foreach ($aUserToAddIDs as $iUserId ) { | |
| 314 | + foreach ($aUserToAddIDs as $iUserId ) { | |
| 308 | 315 | if ($iUserId > 0) { |
| 309 | 316 | $oUser= User::Get($iUserId); |
| 310 | - $memberReason = GroupUtil::getMembershipReason($oUser, $oGroup); | |
| 311 | - //var_dump($memberReason); | |
| 312 | - if (!(PEAR::isError($memberReason) || is_null($memberReason))) { | |
| 313 | - $addWarnings[] = $memberReason; | |
| 314 | - } | |
| 317 | + $memberReason = GroupUtil::getMembershipReason($oUser, $oGroup); | |
| 318 | + //var_dump($memberReason); | |
| 319 | + if (!(PEAR::isError($memberReason) || is_null($memberReason))) { | |
| 320 | + $addWarnings[] = $memberReason; | |
| 321 | + } | |
| 315 | 322 | $res = $oGroup->addMember($oUser); |
| 316 | 323 | if (PEAR::isError($res) || $res == false) { |
| 317 | 324 | $this->errorRedirectToMain(sprintf(_kt('Unable to add user "%s" to group "%s"'), $oUser->getName(), $oGroup->getName()), sprintf("old_search=%s&do_search=1", $old_search)); |
| 318 | 325 | } else { $usersAdded[] = $oUser->getName(); } |
| 319 | 326 | } |
| 320 | 327 | } |
| 321 | - | |
| 328 | + | |
| 322 | 329 | // Remove groups |
| 323 | 330 | foreach ($aUserToRemoveIDs as $iUserId ) { |
| 324 | 331 | if ($iUserId > 0) { |
| ... | ... | @@ -327,32 +334,32 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { |
| 327 | 334 | if (PEAR::isError($res) || $res == false) { |
| 328 | 335 | $this->errorRedirectToMain(sprintf(_kt('Unable to remove user "%s" from group "%s"'), $oUser->getName(), $oGroup->getName()), sprintf("old_search=%s&do_search=1", $old_search)); |
| 329 | 336 | } else { |
| 330 | - $usersRemoved[] = $oUser->getName(); | |
| 331 | - $memberReason = GroupUtil::getMembershipReason($oUser, $oGroup); | |
| 332 | - //var_dump($memberReason); | |
| 333 | - if (!(PEAR::isError($memberReason) || is_null($memberReason))) { | |
| 334 | - $removeWarnings[] = $memberReason; | |
| 335 | - } | |
| 336 | - } | |
| 337 | + $usersRemoved[] = $oUser->getName(); | |
| 338 | + $memberReason = GroupUtil::getMembershipReason($oUser, $oGroup); | |
| 339 | + //var_dump($memberReason); | |
| 340 | + if (!(PEAR::isError($memberReason) || is_null($memberReason))) { | |
| 341 | + $removeWarnings[] = $memberReason; | |
| 342 | + } | |
| 343 | + } | |
| 337 | 344 | } |
| 338 | 345 | } |
| 339 | 346 | |
| 340 | - if (!empty($addWarnings)) { | |
| 341 | - $sWarnStr = _kt('Warning: some users were already members of some subgroups') . ' — '; | |
| 342 | - $sWarnStr .= implode(', ', $addWarnings); | |
| 343 | - $_SESSION['KTInfoMessage'][] = $sWarnStr; | |
| 344 | - } | |
| 345 | - | |
| 346 | - if (!empty($removeWarnings)) { | |
| 347 | - $sWarnStr = _kt('Warning: some users are still members of some subgroups') . ' — '; | |
| 348 | - $sWarnStr .= implode(', ', $removeWarnings); | |
| 349 | - $_SESSION['KTInfoMessage'][] = $sWarnStr; | |
| 350 | - } | |
| 347 | + if (!empty($addWarnings)) { | |
| 348 | + $sWarnStr = _kt('Warning: some users were already members of some subgroups') . ' — '; | |
| 349 | + $sWarnStr .= implode(', ', $addWarnings); | |
| 350 | + $_SESSION['KTInfoMessage'][] = $sWarnStr; | |
| 351 | + } | |
| 352 | + | |
| 353 | + if (!empty($removeWarnings)) { | |
| 354 | + $sWarnStr = _kt('Warning: some users are still members of some subgroups') . ' — '; | |
| 355 | + $sWarnStr .= implode(', ', $removeWarnings); | |
| 356 | + $_SESSION['KTInfoMessage'][] = $sWarnStr; | |
| 357 | + } | |
| 351 | 358 | |
| 352 | 359 | $msg = ''; |
| 353 | 360 | if (!empty($usersAdded)) { $msg .= ' ' . _kt('Added') . ': ' . implode(', ', $usersAdded) . '. <br />'; } |
| 354 | 361 | if (!empty($usersRemoved)) { $msg .= ' ' . _kt('Removed') . ': ' . implode(', ',$usersRemoved) . '.'; } |
| 355 | - | |
| 362 | + | |
| 356 | 363 | if (!Permission::userIsSystemAdministrator($_SESSION['userID'])) { |
| 357 | 364 | $this->rollbackTransaction(); |
| 358 | 365 | $this->errorRedirectTo('manageUsers', _kt('For security purposes, you cannot remove your own administration priviledges.'), sprintf('group_id=%d', $oGroup->getId()), sprintf("old_search=%s&do_search=1", $old_search)); |
| ... | ... | @@ -363,8 +370,8 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { |
| 363 | 370 | $this->successRedirectToMain($msg, sprintf("old_search=%s&do_search=1", $old_search)); |
| 364 | 371 | } |
| 365 | 372 | // }}} |
| 366 | - | |
| 367 | - // FIXME copy-paste ... | |
| 373 | + | |
| 374 | + // FIXME copy-paste ... | |
| 368 | 375 | // {{{ do_manageSubgroups |
| 369 | 376 | function do_manageSubgroups() { |
| 370 | 377 | $old_search = KTUtil::arrayGet($_REQUEST, 'old_search'); |
| ... | ... | @@ -381,27 +388,27 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { |
| 381 | 388 | |
| 382 | 389 | |
| 383 | 390 | $aMemberGroupsUnkeyed = $oGroup->getMemberGroups(); |
| 384 | - $aMemberGroups = array(); | |
| 391 | + $aMemberGroups = array(); | |
| 385 | 392 | $aMemberIDs = array(); |
| 386 | 393 | foreach ($aMemberGroupsUnkeyed as $oMemberGroup) { |
| 387 | 394 | $aMemberIDs[] = $oMemberGroup->getID(); |
| 388 | - $aMemberGroups[$oMemberGroup->getID()] = $oMemberGroup; | |
| 389 | - } | |
| 390 | - | |
| 391 | - $oJSONWidget = new KTJSONLookupWidget(_kt('Groups'), | |
| 392 | - _kt('Select the groups from the left-hand list that you would like to add to this group and then click the <b>right pointing arrows</b>. Once you have added all the groups that you require, press <b>save changes</b>. Only groups that are logically capable of being included in this group will be available to be added.'), | |
| 393 | - 'groups', '', $this->oPage, false, null, null, | |
| 394 | - array('action' => sprintf('getSubGroups&group_id=%d', $oGroup->getID()), | |
| 395 | - 'assigned' => $aMemberGroups, | |
| 396 | - 'multi' => 'true', | |
| 397 | - 'size' => '8')); | |
| 395 | + $aMemberGroups[$oMemberGroup->getID()] = $oMemberGroup; | |
| 396 | + } | |
| 397 | + | |
| 398 | + $oJSONWidget = new KTJSONLookupWidget(_kt('Groups'), | |
| 399 | + _kt('Select the groups from the left-hand list that you would like to add to this group and then click the <b>right pointing arrows</b>. Once you have added all the groups that you require, press <b>save changes</b>. Only groups that are logically capable of being included in this group will be available to be added.'), | |
| 400 | + 'groups', '', $this->oPage, false, null, null, | |
| 401 | + array('action' => sprintf('getSubGroups&group_id=%d', $oGroup->getID()), | |
| 402 | + 'assigned' => $aMemberGroups, | |
| 403 | + 'multi' => 'true', | |
| 404 | + 'size' => '8')); | |
| 398 | 405 | |
| 399 | 406 | $oTemplating =& KTTemplating::getSingleton(); |
| 400 | 407 | $oTemplate = $oTemplating->loadTemplate("ktcore/principals/groups_managesubgroups"); |
| 401 | 408 | $aTemplateData = array("context" => $this, |
| 402 | - "edit_group" => $oGroup, | |
| 403 | - 'widget'=>$oJSONWidget, | |
| 404 | - "old_search" => $old_search, | |
| 409 | + "edit_group" => $oGroup, | |
| 410 | + 'widget'=>$oJSONWidget, | |
| 411 | + "old_search" => $old_search, | |
| 405 | 412 | ); |
| 406 | 413 | return $oTemplate->render($aTemplateData); |
| 407 | 414 | } |
| ... | ... | @@ -409,57 +416,57 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { |
| 409 | 416 | |
| 410 | 417 | |
| 411 | 418 | function json_getSubGroups() { |
| 412 | - $sFilter = KTUtil::arrayGet($_REQUEST, 'filter', false); | |
| 413 | - $aAllowedGroups = array('off'=>'-- Please filter --'); | |
| 414 | - | |
| 415 | - if($sFilter && trim($sFilter)) { | |
| 416 | - $iGroupID = KTUtil::arrayGet($_REQUEST, 'group_id', false); | |
| 417 | - if(!$iGroupID) { | |
| 418 | - return array('error'=>true, 'type'=>'kt.invalid_entity', 'message'=>_kt('An invalid group was selected')); | |
| 419 | - } | |
| 420 | - | |
| 421 | - $oGroup = Group::get($iGroupID); | |
| 422 | - $aMemberGroupsUnkeyed = $oGroup->getMemberGroups(); | |
| 423 | - $aMemberGroups = array(); | |
| 424 | - $aMemberIDs = array(); | |
| 425 | - foreach ($aMemberGroupsUnkeyed as $oMemberGroup) { | |
| 426 | - $aMemberIDs[] = $oMemberGroup->getID(); | |
| 427 | - $aMemberGroups[$oMemberGroup->getID()] = $oMemberGroup; | |
| 428 | - } | |
| 429 | - | |
| 430 | - $aGroupArray = GroupUtil::buildGroupArray(); | |
| 431 | - $aAllowedGroupIDs = GroupUtil::filterCyclicalGroups($oGroup->getID(), $aGroupArray); | |
| 432 | - $aAllowedGroupIDs = array_diff($aAllowedGroupIDs, $aMemberIDs); | |
| 433 | - $aAllowedGroups = array(); | |
| 434 | - foreach ($aAllowedGroupIDs as $iAllowedGroupID) { | |
| 435 | - $g = Group::get($iAllowedGroupID); | |
| 436 | - if (!PEAR::isError($g) && ($g != false)) { | |
| 437 | - $aAllowedGroups[$iAllowedGroupID] = $g->getName(); | |
| 438 | - } | |
| 439 | - } | |
| 440 | - } | |
| 441 | - | |
| 442 | - return $aAllowedGroups; | |
| 419 | + $sFilter = KTUtil::arrayGet($_REQUEST, 'filter', false); | |
| 420 | + $aAllowedGroups = array('off'=>'-- Please filter --'); | |
| 421 | + | |
| 422 | + if($sFilter && trim($sFilter)) { | |
| 423 | + $iGroupID = KTUtil::arrayGet($_REQUEST, 'group_id', false); | |
| 424 | + if(!$iGroupID) { | |
| 425 | + return array('error'=>true, 'type'=>'kt.invalid_entity', 'message'=>_kt('An invalid group was selected')); | |
| 426 | + } | |
| 427 | + | |
| 428 | + $oGroup = Group::get($iGroupID); | |
| 429 | + $aMemberGroupsUnkeyed = $oGroup->getMemberGroups(); | |
| 430 | + $aMemberGroups = array(); | |
| 431 | + $aMemberIDs = array(); | |
| 432 | + foreach ($aMemberGroupsUnkeyed as $oMemberGroup) { | |
| 433 | + $aMemberIDs[] = $oMemberGroup->getID(); | |
| 434 | + $aMemberGroups[$oMemberGroup->getID()] = $oMemberGroup; | |
| 435 | + } | |
| 436 | + | |
| 437 | + $aGroupArray = GroupUtil::buildGroupArray(); | |
| 438 | + $aAllowedGroupIDs = GroupUtil::filterCyclicalGroups($oGroup->getID(), $aGroupArray); | |
| 439 | + $aAllowedGroupIDs = array_diff($aAllowedGroupIDs, $aMemberIDs); | |
| 440 | + $aAllowedGroups = array(); | |
| 441 | + foreach ($aAllowedGroupIDs as $iAllowedGroupID) { | |
| 442 | + $g = Group::get($iAllowedGroupID); | |
| 443 | + if (!PEAR::isError($g) && ($g != false)) { | |
| 444 | + $aAllowedGroups[$iAllowedGroupID] = $g->getName(); | |
| 445 | + } | |
| 446 | + } | |
| 447 | + } | |
| 448 | + | |
| 449 | + return $aAllowedGroups; | |
| 443 | 450 | } |
| 444 | 451 | |
| 445 | 452 | |
| 446 | 453 | |
| 447 | 454 | // {{{ _getUnitName |
| 448 | - function _getUnitName($oGroup) { | |
| 455 | + function _getUnitName($oGroup) { | |
| 449 | 456 | $iUnitId = $oGroup->getUnitId(); |
| 450 | 457 | if (empty($iUnitId)) { |
| 451 | 458 | return null; |
| 452 | 459 | } |
| 453 | - $u = Unit::get($iUnitId); | |
| 454 | - if (PEAR::isError($u)) { | |
| 455 | - return null; // XXX: prevent failure if the $u is a PEAR::error | |
| 456 | - } | |
| 457 | - | |
| 458 | - return $u->getName(); | |
| 459 | - } | |
| 460 | + $u = Unit::get($iUnitId); | |
| 461 | + if (PEAR::isError($u)) { | |
| 462 | + return null; // XXX: prevent failure if the $u is a PEAR::error | |
| 463 | + } | |
| 464 | + | |
| 465 | + return $u->getName(); | |
| 466 | + } | |
| 460 | 467 | // }}} |
| 461 | 468 | |
| 462 | - // FIXME copy-paste ... | |
| 469 | + // FIXME copy-paste ... | |
| 463 | 470 | // {{{ do_updateGroupMembers |
| 464 | 471 | function do_updateGroupMembers() { |
| 465 | 472 | $old_search = KTUtil::arrayGet($_REQUEST, 'old_search'); |
| ... | ... | @@ -488,7 +495,7 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { |
| 488 | 495 | $res = $oGroup->addMemberGroup($oMemberGroup); |
| 489 | 496 | if (PEAR::isError($res)) { |
| 490 | 497 | $this->errorRedirectToMain(sprintf(_kt("Failed to add %s to %s"), $oMemberGroup->getName(), $oGroup->getName()), sprintf("old_search=%s&do_search=1", $old_search)); |
| 491 | - exit(0); | |
| 498 | + exit(0); | |
| 492 | 499 | } else { $groupsAdded[] = $oMemberGroup->getName(); } |
| 493 | 500 | } |
| 494 | 501 | } |
| ... | ... | @@ -499,7 +506,7 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { |
| 499 | 506 | $res = $oGroup->removeMemberGroup($oMemberGroup); |
| 500 | 507 | if (PEAR::isError($res)) { |
| 501 | 508 | $this->errorRedirectToMain(sprintf(_kt("Failed to remove %s from %s"), $oMemberGroup->getName(), $oGroup->getName()), sprintf("old_search=%s&do_search=1", $old_search)); |
| 502 | - exit(0); | |
| 509 | + exit(0); | |
| 503 | 510 | } else { $groupsRemoved[] = $oMemberGroup->getName(); } |
| 504 | 511 | } |
| 505 | 512 | } |
| ... | ... | @@ -509,33 +516,94 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { |
| 509 | 516 | if (!empty($groupsRemoved)) { $msg .= ' '. _kt('Removed'). ': ' . implode(', ',$groupsRemoved) . '.'; } |
| 510 | 517 | |
| 511 | 518 | $this->commitTransaction(); |
| 512 | - | |
| 519 | + | |
| 513 | 520 | $this->successRedirectToMain($msg, sprintf("old_search=%s&do_search=1", $old_search)); |
| 514 | - } | |
| 521 | + } | |
| 515 | 522 | // }}} |
| 516 | - | |
| 523 | + | |
| 524 | + // overloaded because i'm lazy | |
| 525 | + // FIXME we probably want some way to generalise this | |
| 526 | + // FIXME (its a common entity-problem) | |
| 527 | + function form_addgroup() { | |
| 528 | + $oForm = new KTForm; | |
| 529 | + $oForm->setOptions(array( | |
| 530 | + 'identifier' => 'ktcore.groups.add', | |
| 531 | + 'label' => _kt("Create a new group"), | |
| 532 | + 'submit_label' => _kt("Create group"), | |
| 533 | + 'action' => 'creategroup', | |
| 534 | + 'fail_action' => 'addgroup', | |
| 535 | + 'cancel_action' => 'main', | |
| 536 | + 'context' => $this, | |
| 537 | + )); | |
| 538 | + $oForm->setWidgets(array( | |
| 539 | + array('ktcore.widgets.string',array( | |
| 540 | + 'name' => 'group_name', | |
| 541 | + 'label' => _kt("Group Name"), | |
| 542 | + 'description' => _kt('A short name for the group. e.g. <strong>administrators</strong>.'), | |
| 543 | + 'value' => null, | |
| 544 | + 'required' => true, | |
| 545 | + )), | |
| 546 | + array('ktcore.widgets.boolean',array( | |
| 547 | + 'name' => 'sysadmin', | |
| 548 | + 'label' => _kt("System Administrators"), | |
| 549 | + 'description' => _kt('Should all the members of this group be given <strong>system</strong> administration privileges?'), | |
| 550 | + 'value' => null, | |
| 551 | + )), | |
| 552 | + )); | |
| 553 | + | |
| 554 | + $oForm->setValidators(array( | |
| 555 | + array('ktcore.validators.string', array( | |
| 556 | + 'test' => 'group_name', | |
| 557 | + 'output' => 'group_name', | |
| 558 | + )), | |
| 559 | + array('ktcore.validators.boolean', array( | |
| 560 | + 'test' => 'sysadmin', | |
| 561 | + 'output' => 'sysadmin', | |
| 562 | + )), | |
| 563 | + )); | |
| 564 | + | |
| 565 | + // if we have any units. | |
| 566 | + $aUnits = Unit::getList(); | |
| 567 | + if (!PEAR::isError($aUnits) && !empty($aUnits)) { | |
| 568 | + $oForm->addWidgets(array( | |
| 569 | + array('ktcore.widgets.entityselection', array( | |
| 570 | + 'name' => 'unit', | |
| 571 | + 'label' => _kt('Unit'), | |
| 572 | + 'description' => _kt('Which Unit is this group part of?'), | |
| 573 | + 'vocab' => $aUnits, | |
| 574 | + 'label_method' => 'getName', | |
| 575 | + 'simple_select' => false, | |
| 576 | + 'unselected_label' => _kt("No unit"), | |
| 577 | + )), | |
| 578 | + array('ktcore.widgets.boolean',array( | |
| 579 | + 'name' => 'unitadmin', | |
| 580 | + 'label' => _kt("Unit Administrators"), | |
| 581 | + 'description' => _kt('Should all the members of this group be given <strong>unit</strong> administration privileges?'), | |
| 582 | + 'important_description' => _kt("Note that its not possible to set a group without a unit as as having unit administration privileges."), | |
| 583 | + 'value' => null, | |
| 584 | + )), | |
| 585 | + )); | |
| 586 | + | |
| 587 | + $oForm->addValidators(array( | |
| 588 | + array('ktcore.validators.entity', array( | |
| 589 | + 'test' => 'unit', | |
| 590 | + 'class' => 'Unit', | |
| 591 | + 'output' => 'unit', | |
| 592 | + )), | |
| 593 | + array('ktcore.validators.boolean', array( | |
| 594 | + 'test' => 'unitadmin', | |
| 595 | + 'output' => 'unitadmin', | |
| 596 | + )), | |
| 597 | + )); | |
| 598 | + } | |
| 599 | + | |
| 600 | + return $oForm; | |
| 601 | + } | |
| 602 | + | |
| 517 | 603 | // {{{ do_addGroup |
| 518 | 604 | function do_addGroup() { |
| 519 | - $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('Group Management')); | |
| 520 | - $this->oPage->setBreadcrumbDetails(_kt('Add a new group')); | |
| 521 | - | |
| 522 | - | |
| 523 | - $this->oPage->setTitle(_kt("Add a new group")); | |
| 524 | - | |
| 525 | - $edit_fields = array(); | |
| 526 | - $add_fields[] = new KTStringWidget(_kt('Group Name'), _kt('A short name for the group. e.g. <strong>administrators</strong>.'), 'group_name', null, $this->oPage, true); | |
| 527 | - $add_fields[] = new KTCheckboxWidget(_kt('Unit Administrators'), _kt('Should all the members of this group be given <strong>unit</strong> administration privileges?'), 'is_unitadmin', false, $this->oPage, false); | |
| 528 | - $add_fields[] = new KTCheckboxWidget(_kt('System Administrators'), _kt('Should all the members of this group be given <strong>system</strong> administration privileges?'), 'is_sysadmin', false, $this->oPage, false); | |
| 529 | - // grab all units. | |
| 530 | - | |
| 531 | - $oUnits = Unit::getList(); | |
| 532 | - $vocab = array(); | |
| 533 | - $vocab[0] = _kt('No Unit'); | |
| 534 | - foreach ($oUnits as $oUnit) { $vocab[$oUnit->getID()] = $oUnit->getName(); } | |
| 535 | - $aOptions = array('vocab' => $vocab); | |
| 536 | - | |
| 537 | - $add_fields[] = new KTLookupWidget(_kt('Unit'), _kt('Which Unit is this group part of?'), 'unit_id', 0, $this->oPage, false, null, null, $aOptions); | |
| 538 | - | |
| 605 | + $this->oPage->setBreadcrumbDetails(_kt('Add a new group')); | |
| 606 | + | |
| 539 | 607 | $aAuthenticationSources = array(); |
| 540 | 608 | $aAllAuthenticationSources =& KTAuthenticationSource::getList(); |
| 541 | 609 | foreach ($aAllAuthenticationSources as $oSource) { |
| ... | ... | @@ -546,48 +614,60 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { |
| 546 | 614 | $aAuthenticationSources[] = $oSource; |
| 547 | 615 | } |
| 548 | 616 | } |
| 549 | - | |
| 550 | - $oTemplating =& KTTemplating::getSingleton(); | |
| 551 | - $oTemplate = $oTemplating->loadTemplate("ktcore/principals/addgroup"); | |
| 552 | - $aTemplateData = array( | |
| 553 | - "context" => $this, | |
| 554 | - "add_fields" => $add_fields, | |
| 555 | - "authentication_sources" => $aAuthenticationSources, | |
| 556 | - ); | |
| 557 | - return $oTemplate->render($aTemplateData); | |
| 617 | + | |
| 618 | + $oTemplating =& KTTemplating::getSingleton(); | |
| 619 | + $oTemplate = $oTemplating->loadTemplate("ktcore/principals/addgroup"); | |
| 620 | + $aTemplateData = array( | |
| 621 | + "context" => $this, | |
| 622 | + "add_fields" => $add_fields, | |
| 623 | + "authentication_sources" => $aAuthenticationSources, | |
| 624 | + 'form' => $this->form_addgroup(), | |
| 625 | + ); | |
| 626 | + return $oTemplate->render($aTemplateData); | |
| 558 | 627 | } |
| 559 | 628 | // }}} |
| 560 | 629 | |
| 561 | 630 | // {{{ do_createGroup |
| 562 | - function do_createGroup() { | |
| 563 | - | |
| 564 | - $group_name = KTUtil::arrayGet($_REQUEST, 'group_name'); | |
| 565 | - if (empty($group_name)) { $this->errorRedirectToMain(_kt('Please specify a name for the group.')); } | |
| 566 | - $is_unitadmin = KTUtil::arrayGet($_REQUEST, 'is_unitadmin', false); | |
| 567 | - if ($is_unitadmin !== false) { $is_unitadmin = true; } | |
| 568 | - $is_sysadmin = KTUtil::arrayGet($_REQUEST, 'is_sysadmin', false); | |
| 569 | - if ($is_sysadmin !== false) { $is_sysadmin = true; } | |
| 570 | - $unit_id = KTUtil::arrayGet($_REQUEST, 'unit_id', null); | |
| 571 | - | |
| 572 | - $this->startTransaction(); | |
| 573 | - | |
| 574 | - $oGroup =& Group::createFromArray(array( | |
| 575 | - 'sName' => $group_name, | |
| 576 | - 'bIsUnitAdmin' => $is_unitadmin, | |
| 577 | - 'bIsSysAdmin' => $is_sysadmin, | |
| 578 | - 'UnitId' => $unit_id, | |
| 579 | - )); | |
| 580 | - //$res = $oGroup->create(); | |
| 581 | - //if (($res == false) || (PEAR::isError($res))) { return $this->errorRedirectToMain('Failed to create group "' . $group_name . '"'); } | |
| 582 | - // do i need to "create" | |
| 583 | - $this->commitTransaction(); | |
| 584 | - | |
| 585 | - if($unit_id == 0 && $is_unitadmin) { | |
| 586 | - $this->successRedirectToMain(sprintf(_kt('Group "%s" created.'), $group_name) . _kt(' Note: group is set as unit administrator, but is not assigned to a unit.')); | |
| 587 | - } else { | |
| 588 | - $this->successRedirectToMain(sprintf(_kt('Group "%s" created.'), $group_name)); | |
| 589 | - } | |
| 590 | - } | |
| 631 | + function do_creategroup() { | |
| 632 | + $oForm = $this->form_addgroup(); | |
| 633 | + $res = $oForm->validate(); | |
| 634 | + $data = $res['results']; | |
| 635 | + $errors = $res['errors']; | |
| 636 | + $extra_errors = array(); | |
| 637 | + | |
| 638 | + if (is_null($data['unit']) && $data['unitadmin']) { | |
| 639 | + $extra_errors['unitadmin'] = _kt("Groups without units cannot be Unit Administrators."); | |
| 640 | + } | |
| 641 | + | |
| 642 | + $oGroup = Group::getByName($data['group_name']); | |
| 643 | + if (!PEAR::isError($oGroup)) { | |
| 644 | + $extra_errors['group_name'][] = _kt("There is already a group with that name."); | |
| 645 | + } | |
| 646 | + | |
| 647 | + if (!empty($errors) || !empty($extra_errors)) { | |
| 648 | + return $oForm->handleError(null, $extra_errors); | |
| 649 | + } | |
| 650 | + | |
| 651 | + $this->startTransaction(); | |
| 652 | + | |
| 653 | + $unit = null; | |
| 654 | + if (!is_null($data['unit'])) { | |
| 655 | + $unit = $data['unit']->getId(); | |
| 656 | + } | |
| 657 | + | |
| 658 | + $oGroup =& Group::createFromArray(array( | |
| 659 | + 'sName' => $data['group_name'], | |
| 660 | + 'bIsUnitAdmin' => $data['unitadmin'], | |
| 661 | + 'bIsSysAdmin' => $data['sysadmin'], | |
| 662 | + 'UnitId' => $unit, | |
| 663 | + )); | |
| 664 | + if (PEAR::isError($oGroup)) { | |
| 665 | + return $oForm->handleError(sprintf(_kt("Unable to create group: %s"), $oGroup->getMessage())); | |
| 666 | + } | |
| 667 | + $this->commitTransaction(); | |
| 668 | + | |
| 669 | + $this->successRedirectToMain(sprintf(_kt('Group "%s" created.'), $data['group_name'])); | |
| 670 | + } | |
| 591 | 671 | // }}} |
| 592 | 672 | |
| 593 | 673 | // {{{ do_deleteGroup |
| ... | ... | @@ -603,7 +683,7 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { |
| 603 | 683 | $this->startTransaction(); |
| 604 | 684 | |
| 605 | 685 | foreach($oGroup->getParentGroups() as $oParentGroup) { |
| 606 | - $res = $oParentGroup->removeMemberGroup($oGroup); | |
| 686 | + $res = $oParentGroup->removeMemberGroup($oGroup); | |
| 607 | 687 | } |
| 608 | 688 | |
| 609 | 689 | $res = $oGroup->delete(); |
| ... | ... | @@ -639,25 +719,25 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { |
| 639 | 719 | } |
| 640 | 720 | // }}} |
| 641 | 721 | |
| 642 | - function getGroupStringForGroup($oGroup) { | |
| 643 | - $aGroupNames = array(); | |
| 644 | - $aGroups = $oGroup->getMemberGroups(); | |
| 645 | - $MAX_GROUPS = 6; | |
| 646 | - $add_elipsis = false; | |
| 647 | - if (count($aGroups) == 0) { return _kt('Group currently has no subgroups.'); } | |
| 648 | - if (count($aGroups) > $MAX_GROUPS) { | |
| 649 | - $aGroups = array_slice($aGroups, 0, $MAX_GROUPS); | |
| 650 | - $add_elipsis = true; | |
| 651 | - } | |
| 652 | - foreach ($aGroups as $oGroup) { | |
| 653 | - $aGroupNames[] = $oGroup->getName(); | |
| 654 | - } | |
| 655 | - if ($add_elipsis) { | |
| 656 | - $aGroupNames[] = '…'; | |
| 657 | - } | |
| 658 | - | |
| 659 | - return implode(', ', $aGroupNames); | |
| 660 | - } | |
| 722 | + function getGroupStringForGroup($oGroup) { | |
| 723 | + $aGroupNames = array(); | |
| 724 | + $aGroups = $oGroup->getMemberGroups(); | |
| 725 | + $MAX_GROUPS = 6; | |
| 726 | + $add_elipsis = false; | |
| 727 | + if (count($aGroups) == 0) { return _kt('Group currently has no subgroups.'); } | |
| 728 | + if (count($aGroups) > $MAX_GROUPS) { | |
| 729 | + $aGroups = array_slice($aGroups, 0, $MAX_GROUPS); | |
| 730 | + $add_elipsis = true; | |
| 731 | + } | |
| 732 | + foreach ($aGroups as $oGroup) { | |
| 733 | + $aGroupNames[] = $oGroup->getName(); | |
| 734 | + } | |
| 735 | + if ($add_elipsis) { | |
| 736 | + $aGroupNames[] = '…'; | |
| 737 | + } | |
| 738 | + | |
| 739 | + return implode(', ', $aGroupNames); | |
| 740 | + } | |
| 661 | 741 | // }}} |
| 662 | 742 | } |
| 663 | 743 | ... | ... |
templates/ktcore/principals/addgroup.smarty
| ... | ... | @@ -25,7 +25,7 @@ will be maintained as it is in the authentication source.{/i18n}</p> |
| 25 | 25 | <p class="descriptiveText">{i18n}Alternatively, you can manually create a user |
| 26 | 26 | within KnowledgeTree below.{/i18n}</p> |
| 27 | 27 | {/if} |
| 28 | - | |
| 28 | +{* | |
| 29 | 29 | <form action="{$smarty.server.PHP_SELF}" method="POST"> |
| 30 | 30 | <input type="hidden" name="action" value="createGroup" /> |
| 31 | 31 | |
| ... | ... | @@ -41,3 +41,5 @@ within KnowledgeTree below.{/i18n}</p> |
| 41 | 41 | </div> |
| 42 | 42 | </fieldset> |
| 43 | 43 | </form> |
| 44 | +*} | |
| 45 | +{$form->render()} | ... | ... |