public static function create(array $input) { /** * Creates a new coach. * * Input: name, realname, passwd, mail, phone, ring, settings, def_leagues (array of LIDs) **/ global $settings; if (empty($input['name']) || empty($input['passwd']) || get_alt_col('coaches', 'name', $input['name'], 'coach_id') || !in_array($input['ring'], self::$RINGS[self::T_RING_GROUP_GLOBAL])) { return false; } $query = "INSERT INTO coaches (name, realname, passwd, mail, phone, ring, settings) \r\n VALUES ('" . mysql_real_escape_string($input['name']) . "',\r\n '" . mysql_real_escape_string($input['realname']) . "', \r\n '" . md5($input['passwd']) . "', \r\n '" . mysql_real_escape_string($input['mail']) . "', \r\n '" . mysql_real_escape_string($input['phone']) . "', \r\n " . $input['ring'] . ",\r\n '" . array_strpack_assoc('%k=%v', $input['settings'], ',') . "')"; if (($status = mysql_query($query)) && is_numeric($cid = mysql_insert_id())) { // Set default memberships $newCoach = new Coach($cid); foreach (array_merge($settings['default_leagues'], $input['def_leagues']) as $lid) { $status &= $newCoach->setRing(self::T_RING_GROUP_LOCAL, self::T_RING_LOCAL_REGULAR, $lid); } } return $status ? $cid : false; }
break 2; } } // Single? if (isset($c)) { status($c->setRing(Coach::T_RING_GROUP_LOCAL, (int) $_POST['ring'], (int) $_POST['lid'])); } elseif (isset($_POST['massuser']) && $_POST['massuser']) { $changed = 0; foreach (get_rows('coaches', array('coach_id', 'name')) as $subm_coach) { if (isset($_POST["cid{$subm_coach->coach_id}"]) && $_POST["cid{$subm_coach->coach_id}"]) { $c = new Coach($subm_coach->coach_id); # Needed later. if (!$coach->mayManageObj(T_OBJ_COACH, $c->coach_id)) { status(false, 'You do not have permissions to manage the selected coach "' . $c->name . '".'); } $c->setRing(Coach::T_RING_GROUP_LOCAL, (int) $_POST['ring'], (int) $_POST['lid']); $changed++; } } status(true, "Changed {$changed} local access levels"); } break; case 'ch_passwd': $errors = array('Please use a password of at least 5 characters.' => strlen($_POST['passwd']) < 5); foreach ($errors as $msg => $halt) { if ($halt) { status(false, $msg); break 2; } } status($c->setPasswd($_POST['passwd']));