From e7d20033b87313cd2548b6333c84a1f51807e441 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Wed, 17 Dec 2014 14:29:29 -0600 Subject: [PATCH] staff: Ensure an active admin always exists --- include/class.staff.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/class.staff.php b/include/class.staff.php index da2473c0e..38c46b772 100644 --- a/include/class.staff.php +++ b/include/class.staff.php @@ -774,6 +774,20 @@ class Staff extends AuthenticatedUser { if(!$vars['timezone_id']) $errors['timezone_id']=__('Time zone selection is required'); + // Ensure we will still have an administrator with access + if ($vars['isadmin'] !== '1' || $vars['isactive'] !== '1') { + $sql = 'select count(*), max(staff_id) from '.STAFF_TABLE + .' WHERE isadmin=1 and isactive=1'; + if (($res = db_query($sql)) + && (list($count, $sid) = db_fetch_row($res))) { + if ($count == 1 && $sid = $id) { + $errors['isadmin'] = __( + 'Cowardly refusing to remove or lock out the only active administrator' + ); + } + } + } + if($errors) return false; -- GitLab