array(1, '', 'Username'), 'email' => array(1, '', 'Email address'), 'admin' => array(0, 0, 'Administrator'), 'active' => array(0, PHORUM_USER_ACTIVE, 'Active'), 'pass1' => array(1, '', 'Password'), 'pass2' => array(1, '', 'Password (again)'), ); function getvalue($id) { global $error, $val_data; if ($error && isset($_POST[$id])) return $_POST[$id]; elseif (isset($val_data[$id])) return $val_data[$id][1]; else return ''; } function getname($id) { global $val_data; if (isset($val_data[$id])) { $title = $val_data[$id][2]; return $val_data[$id][0] ? $title.' *' : $title; } else return $id.' [no title!]'; } $userdata = array(); $error = false; if(count($_POST)) { // we want to add a new user to the database foreach($val_data as $k => $v) { if (!isset($_POST[$k]) || trim($_POST[$k]) == '') { if ($v[0]) $error = true; else $userdata[$k] = $v[1]; } else { $userdata[$k] = $_POST[$k]; } if ($error) break; } if ($error) phorum_admin_error('Form validation failed, a required field was not set or empty.'); else { if ($_POST['pass1'] != $_POST['pass2']) { phorum_admin_error('Passwords don\'t match.'); $error = true; } elseif(phorum_api_user_search('username', $_POST['username']) != 0) { phorum_admin_error('Username has to be unique!'); $error = true; } else { $userdata['user_id'] = NULL; $userdata['password'] = $_POST['pass1']; $userdata['password_temp'] = $_POST['pass2']; unset($userdata['pass1'], $userdata['pass2']); $uid = phorum_api_user_save($userdata); if ($uid === NULL) phorum_admin_error('Could not save user data!'); else { $uid = htmlspecialchars($uid); phorum_admin_okmsg('User added (UID '.$uid.'). Click here to edit.'); } } } } include_once('./include/admin/PhorumInputForm.php'); $frm = new PhorumInputForm('', 'post', 'Add User'); $frm->hidden('module', 'useradd'); $frm->addbreak('Add User'); $row = $frm->addrow(getname('username'), $frm->text_box('username', getvalue('username'))); $frm->addhelp($row, getname('username'), 'Has to be unique.'); $frm->addrow(getname('pass1'), $frm->text_box('pass1', '', 0, 0, true)); $frm->addrow(getname('pass2'), $frm->text_box('pass2', '', 0, 0, true)); $frm->addrow(getname('email'), $frm->text_box('email', getvalue('email'))); $frm->addrow(getname('admin'), $frm->select_tag('admin', array('No', 'Yes'), getvalue('admin'))); $frm->addrow(getname('active'), $frm->select_tag('active', array(PHORUM_USER_INACTIVE => 'No', PHORUM_USER_ACTIVE => 'Yes'), getvalue('active'))); $frm->show(); ?>