X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=group_delete.php;h=db24a44818cf368eb881ff59bcac10097f04eb4a;hb=45a530c33fdd7ab2ccd1905c24a371c94e17eac5;hp=6aa0d11d1e8d3ddf226d2fe081c795e99db29e7a;hpb=b262cc9f78e50e6910fefc1744782ddd64bbccda;p=timetracker.git diff --git a/group_delete.php b/group_delete.php index 6aa0d11d..db24a448 100644 --- a/group_delete.php +++ b/group_delete.php @@ -28,25 +28,21 @@ require_once('initialize.php'); import('form.Form'); -import('ttAdmin'); +import('ttGroupHelper'); // Access checks. if (!ttAccessAllowed('delete_group')) { - header('Location: access_denied.php'); + header('Location: access_denied.php'); // No rights. exit(); } -$group_id = (int)$request->getParameter('id'); -if ($user->group_id != $group_id) { - header('Location: access_denied.php'); +if (!$user->isGroupValid($request->getParameter('id'))) { + header('Location: access_denied.php'); // Wrong group id. exit(); } // End of access checks. -// Note: reuse ttAdmin class here, simply because deleting a group -// is a complicated task. -$admin = new ttAdmin(); -$group_details = $admin->getGroupDetails($group_id); -$group_name = $group_details['group_name']; +$group_id = (int)$request->getParameter('id'); +$group_name = ttGroupHelper::getGroupName($group_id); $form = new Form('groupForm'); $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$group_id)); @@ -55,18 +51,33 @@ $form->addInput(array('type'=>'submit','name'=>'btn_cancel','value'=>$i18n->get( if ($request->isPost()) { if ($request->getParameter('btn_delete')) { - if ($admin->markGroupDeleted($group_id)) { - $auth->doLogout(); - session_unset(); - header('Location: login.php'); - exit(); + $markedDeleted = ttGroupHelper::markGroupDeleted($group_id); + if ($markedDeleted) { + // TODO: conditional redirects don't look nice. Any better ideas? + if ($group_id == $user->group_id) { + // We marked deleted our own group. Logout and redirect to login page. + $auth->doLogout(); + session_unset(); + header('Location: login.php'); + exit(); + } else { + // We marked deleted a subgroup. Redirect to groups.pgp. + header('Location: groups.php'); + exit(); + } } else $err->add($i18n->get('error.db')); } if ($request->getParameter('btn_cancel')) { - header('Location: group_edit.php'); - exit(); + // TODO: conditional redirects don't look nice. Any better ideas? + if ($group_id == $user->group_id) { + header('Location: group_edit.php'); + exit(); + } else { + header('Location: groups.php'); + exit(); + } } } // isPost