function api_forum_create_new_thread($user_id, $is_admin, $category_id, $thread_title, $post_id, $post_count) { $category_id = intval($category_id); $post_count = intval($post_count); $post_id = intval($post_id); $category_info = null; if ($category_id > 0) { $category_info = api_forum_get_category_info($user_id, $is_admin, $cateogry_id, true); } $thread_id = sql_insert('forum_threads', array('category_id' => $category_id, 'title' => $thread_title . '', 'first_post_id' => $post_id, 'last_post_id' => $post_id, 'post_count' => $post_count)); if ($category_info != null) { $last_post_id = intval($category_info['last_post_id']); if ($post_id > $last_post_id) { $last_post_id = $post_id; } sql_query("\n\t\t\t\tUPDATE `forum_categories`\n\t\t\t\tSET\n\t\t\t\t\t`thread_count` = `thread_count` + 1,\n\t\t\t\t\t`post_count` = `post_count` + {$post_count},\n\t\t\t\t\t`last_post_id` = {$last_post_id}\n\t\t\t\tWHERE\n\t\t\t\t\t`category_id` = {$category_id}\n\t\t\t\tLIMIT 1"); } return api_success(array('thread_id' => $thread_id, 'category_id' => $category_id)); }
function api_account_change_password($name, $old_password, $new_password1, $new_password2) { // TODO: send an email $user_info = api_account_lookup_user_by_name($name); if (strlen($new_password1) == 0) { return api_error("INVALID"); } if (api_account_hash_password($old_password) != $user_info['pass_hash']) { return api_error('WRONG_OLD_PASSWORD'); } $pw_check = api_account_validate_password($name, $new_password1, $new_password2); if ($pw_check['status'] == 'ERROR') { return $pw_check; } $password = $pw_check['password']; $pass_hash = api_account_hash_password($password); sql_query("UPDATE `users` SET `pass_hash` = '{$pass_hash}' WHERE `user_id` = " . $user_info['user_id'] . " LIMIT 1"); return api_success(); }
function api_autograder_menu_get_problems($user_id, $is_admin, $type, $competition_id, $show_golf_scores) { $user_id = intval($user_id); $language_id = intval($language_id); if ($type != 'golf' && $type != 'practice' && $type != 'competition') { return api_error("INVALID_TYPE"); } if ($type == 'competition') { $competition_id = intval($competition_id); $where = "`competition_id` = {$competition_id}"; } else { $where = "`type` = '{$type}'"; } if ($type == 'golf') { $order_by = "`golf_end_time` DESC"; } else { $order_by = "`problem_id` DESC"; } $query = "\n\t\t\tSELECT\n\t\t\t\t`problem_id`,\n\t\t\t\t`title`,\n\t\t\t\t`metadata`,\n\t\t\t\t`golf_start_time`,\n\t\t\t\t`golf_end_time`\n\t\t\tFROM `code_problems`\n\t\t\tWHERE {$where}\n\t\t\tORDER BY\n\t\t\t\t{$order_by} "; $problems = sql_query($query); $output = array(); $ordered_problem_ids = array(); $user_ids = array(); for ($i = 0; $i < $problems->num_rows; ++$i) { $problem = api_autograder_canonicalize_problem($problems->fetch_assoc()); $id = $problem['problem_id']; array_push($ordered_problem_ids, $id); $output['problem_' . $id] = $problem; } $output['ordered_problem_ids'] = $ordered_problem_ids; if (count($user_ids) > 0) { $user_infos = api_account_fetch_mini_profiles($user_ids); $output = array_merge($output, $user_infos); } if ($show_golf_scores && count($ordered_problem_ids) > 0 && $user_id > 0) { $scores = sql_query("SELECT `problem_id`,`language_id`,`code_size`,`integer_rank` FROM `code_solutions` WHERE `user_id` = " . $user_id . " AND `problem_id` IN (" . implode(', ', $ordered_problem_ids) . ")"); for ($i = 0; $i < $scores->num_rows; ++$i) { $score = $scores->fetch_assoc(); $output['score_' . $score['problem_id'] . '_' . $score['language_id']] = $score; } } return api_success($output); }