set_focus('tab', 'users', null); if (!can_perform('canadminusers')) { admin_login(); } // ################################################################### /** * Generate an inline checkbox * * @access public * * @param string Name * @param bool Checked? * * @return string HTML checkbxo */ function draw_checkbox($name, $checked) { return ""; } // ################################################################### if (empty($_REQUEST['do'])) { $_REQUEST['do'] = 'modify'; } // ################################################################### if ($_REQUEST['do'] == 'kill') { $user = new UserAPI(); $user->set('userid', $input->in['userid']); $user->set_condition(); $user->delete(); $admin->redirect('user.php'); } // ################################################################### if ($_REQUEST['do'] == 'delete') { $admin->page_confirm(T('Are you sure you want to delete this user?'), 'user.php', 'kill', array('userid' => $input->inputClean('userid', TYPE_UINT))); } // ################################################################### if ($_POST['do'] == 'insert') { $user = new UserAPI(); $user->set('displayname', $input->in['displayname']); $user->set('email', $input->in['email']); $user->set('showemail', $input->in['showemail']); $user->set('showcolors', $input->in['showcolors']); $user->set('usergroupid', $input->in['usergroupid']); $user->set('groupids', $input->in['groupids']); $user->set('languageid', $input->in['languageid']); $user->set('timezone', $input->in['timezone']); $user->set('usedst', $input->in['usedst']); $user->set('password', $input->in['password']); $user->set('hidestatuses', $input->in['hidestatuses']); $user->set('defaultsortkey', $input->in['defaultsortkey']); $user->set('defaultsortas', $input->in['defaultsortas']); $user->insert(); // post_insert will set the email options... so we now have to dump them $db->query("DELETE FROM " . TABLE_PREFIX . "useremail WHERE userid = " . $user->insertid); $input->inputClean('emailopts', TYPE_INT); if (is_array($input->in['emailopts'])) { foreach ($input->in['emailopts'] AS $relation => $bitarr) { $bitmask = 0; foreach ($bitarr AS $option => $yes) { $bitmask += $option * $yes; } $db->query("INSERT INTO " . TABLE_PREFIX . "useremail (userid, relation, mask) VALUES (" . $user->insertid . ", $relation, $bitmask)"); } } $admin->redirect('user.php?do=edit&userid=' . $user->insertid); } // ################################################################### if ($_POST['do'] == 'update') { $user = new UserAPI(); $user->set('userid', $input->in['userid']); $user->set_condition(); $user->set('displayname', $input->in['displayname']); $user->set('email', $input->in['email']); $user->set('showemail', $input->in['showemail']); $user->set('showcolors', $input->in['showcolors']); $user->set('usergroupid', $input->in['usergroupid']); $user->set('groupids', $input->in['groupids']); $user->set('languageid', $input->in['languageid']); $user->set('timezone', $input->in['timezone']); $user->set('usedst', $input->in['usedst']); $user->set('password', $input->in['password']); $user->set('hidestatuses', $input->in['hidestatuses']); $user->set('defaultsortkey', $input->in['defaultsortkey']); $user->set('defaultsortas', $input->in['defaultsortas']); $user->update(); $db->query("DELETE FROM " . TABLE_PREFIX . "useremail WHERE userid = " . $user->values['userid']); $input->inputClean('emailopts', TYPE_INT); if (is_array($input->in['emailopts'])) { foreach ($input->in['emailopts'] AS $relation => $bitarr) { $bitmask = 0; foreach ($bitarr AS $option => $yes) { $bitmask += $option * $yes; } $db->query("INSERT INTO " . TABLE_PREFIX . "useremail (userid, relation, mask) VALUES (" . $user->values['userid'] . ", $relation, $bitmask)"); } } $admin->redirect('user.php?do=edit&userid=' . $user->record['userid']); } // ################################################################### if ($_REQUEST['do'] == 'edit' OR $_REQUEST['do'] == 'add') { $add = ($_REQUEST['do'] == 'add'); $edit = (!$add); if ($edit) { NavLinks::usersEdit($input->in['userid']); $navigator->set_focus('link', 'users-pages-users', 'users-pages'); $user = new UserAPI(); $user->set('userid', $input->in['userid']); $user->set_condition(); $user->fetch(); } else { NavLinks::usersAdd(); $navigator->set_focus('link', 'users-add', 'users'); } $admin->page_start(($add ? T('Add User') : T('Edit User'))); $admin->form_start('user.php', ($add ? 'insert' : 'update')); if ($edit) { $admin->form_hidden_field('userid', $user->record['userid']); } $admin->table_start(); $admin->table_head(($add ? T('Add User') : sprintf(T('Edit User (userid: %1$s)'), $user->record['userid']))); $admin->row_input(T('Display Name'), 'displayname', $user->record['displayname']); $admin->row_input(T('Email'), 'email', $user->record['email']); $admin->row_input(($add ? T('Password') : T('Password (Leave blank for no change)')), 'password'); foreach (bugdar::$datastore['usergroup'] AS $group) { $admin->list_item($group['title'], $group['usergroupid'], ($user->record['usergroupid'] == $group['usergroupid'])); } $admin->row_list(T('Primary Usergroup'), 'usergroupid'); $ids = explode(',', $user->record['groupids']); foreach (bugdar::$datastore['usergroup'] AS $id => $group) { if ($id == $user->record['usergroupid']) { continue; } $admin->list_item($group['title'], $group['usergroupid'], in_array($id, $ids)); } $admin->row_checkbox(T('Secondary Usergroups'), 'groupids'); $admin->row_yesno(T('Show Email Publicly'), 'showemail', $user->record['showemail']); $admin->row_yesno(T('Show Status Colors on Bug Listings'), 'showcolors', $user->record['showcolors']); foreach (bugdar::$datastore['language'] AS $language) { $admin->list_item($language['title'], $language['languageid'], ($user->record['languageid'] == $language['languageid'])); } $admin->row_list(T('Language'), 'languageid'); foreach ($datef->fetch_timezone_list() AS $value => $string) { $admin->list_item($string, $value, ($user->record['timezone'] == $value)); } $admin->row_list(T('Timezone'), 'timezone'); $admin->row_yesno(T('Observe Daylight Savings Time (DST)'), 'usedst', $user->record['usedst']); $admin->row_text(T('Hidden Statuses on Bug Listing'), construct_option_select('hidestatuses', bugdar::$datastore['status'], $user->record['hidestatuses'], 'statusid', 'status', 0, true)); $admin->row_text(T('Default Sort Order Column'), construct_option_select('defaultsortkey', ListSorter::fetch_by_text(false), $user->record['defaultsortkey'])); $admin->row_text(T('Default Sort Order Direction'), construct_option_select('defaultsortas', ListSorter::fetch_as_text(false), $user->record['defaultsortas'])); $admin->table_end(); // ------------------------------------------------------------------- $admin->table_start(false); $admin->table_head(T('Email Options'), 6); if ($user->record['userid']) { $options = $db->query("SELECT * FROM " . TABLE_PREFIX . "useremail WHERE userid = " . $user->record['userid']); foreach ($options as $opt) { foreach ($bugsys->emailoptions['notifications'] AS $name => $notif) { foreach ($bugsys->emailoptions['relations'] AS $name => $relation) { if ($opt['mask'] & $notif AND $opt['relation'] == $relation) { $checked["$relation"]["$notif"] = HTML_CHECKED; } } } } } $admin->table_column_head(array('', T('Reporter'), T('Assignee'), T('Favorite'), T('Voter'), T('Commenter'))); // ------------------------------------------------------------------- $admin->row_text(T('New bug is added'), '