posaune
[timetracker.git] / user_delete.php
index a88454b..38d4f54 100644 (file)
 
 require_once('initialize.php');
 import('form.Form');
-import('ttUserHelper');
+import('ttUser');
 
-// Access check.
+// Access checks.
 if (!ttAccessAllowed('manage_users')) {
   header('Location: access_denied.php');
   exit();
 }
-
-// Get user id we are deleting from the request.
-// A cast to int is for safety against manipulation of request parameter (sql injection). 
-$user_id = (int) $request->getParameter('id');
-// We need user name and login to display.
-$user_details = ttUserHelper::getUserDetails($user_id);
-
-// Security checks.
-if (!$user_details || // No details.
-     $user_details['team_id'] <> $user->team_id || // User not in team.
-     $user_details['rank'] > $user->rank || // User has a bigger rank.
-     ($user_details['rank'] == $user->rank && $user_details['id'] <> $user->id) // Same rank but not us.
-   ) {
+$user_id = (int)$request->getParameter('id');
+$user_details = $user->getUserDetails($user_id);
+if (!$user_details) {
   header('Location: access_denied.php');
   exit();
 }
+// End of access checks.
 
 $smarty->assign('user_to_delete', $user_details['name']." (".$user_details['login'].")");
 
@@ -62,7 +53,7 @@ $form->addInput(array('type'=>'submit','name'=>'btn_cancel','value'=>$i18n->get(
 
 if ($request->isPost()) {
   if ($request->getParameter('btn_delete')) {
-    if (ttUserHelper::markDeleted($user_id)) {
+    if ($user->markUserDeleted($user_id)) {
       // If we deleted the "on behalf" user reset its info in session.
       if ($user_id == $user->behalf_id) {
         unset($_SESSION['behalf_id']);