Changeset 1132
- Timestamp:
- 04/24/10 14:13:20 (2 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
- 5 copied
-
common/db/round.php (modified) (7 diffs)
-
common/db/round_task.php (copied) (copied from branches/taskreordering/common/db/round_task.php)
-
common/db/task.php (modified) (4 diffs)
-
scripts/add-round-task-order (copied) (copied from branches/taskreordering/scripts/add-round-task-order)
-
www/controllers/round.php (modified) (2 diffs)
-
www/index.php (modified) (1 diff)
-
www/macros/macro_tasks.php (modified) (1 diff)
-
www/static/css/screen.css (modified) (1 diff)
-
www/static/js/foreach.js (copied) (copied from branches/taskreordering/www/static/js/foreach.js)
-
www/static/js/tablednd.js (copied) (copied from branches/taskreordering/www/static/js/tablednd.js)
-
www/url.php (modified) (1 diff)
-
www/views/header.php (modified) (1 diff)
-
www/views/round_edit_header.php (modified) (1 diff)
-
www/views/round_task_order.php (copied) (copied from branches/taskreordering/www/views/round_task_order.php)
Legend:
- Unmodified
- Added
- Removed
-
trunk/common/db/round.php
r1120 r1132 3 3 require_once(IA_ROOT_DIR."common/db/db.php"); 4 4 require_once(IA_ROOT_DIR."common/db/parameter.php"); 5 require_once(IA_ROOT_DIR."common/db/round_task.php"); 5 6 6 7 function _round_cache_add($round) { … … 111 112 } 112 113 $fields = "round_task.task_id AS id, ". 113 " task.`order` AS `order`, ".114 "round_task.`order_id` AS `order`, ". 114 115 "task.`title` AS `title`, ". 115 116 "task.`page_name` AS `page_name`, ". … … 125 126 LEFT JOIN ia_task as task ON task.id = round_task.task_id 126 127 WHERE `round_task`.`round_id` = '%s' 127 ORDER BY task.`order` LIMIT %d, %d",128 ORDER BY round_task.`order_id` LIMIT %d, %d", 128 129 db_escape($round_id), db_escape($first), db_escape($count)); 129 130 } else { … … 139 140 WHERE `round_task`.`round_id` = '%s' 140 141 AND %s 141 ORDER BY task.`order` LIMIT %d, %d",142 ORDER BY round_task.`order_id` LIMIT %d, %d", 142 143 db_escape($user_id), 143 144 db_escape($round_id), db_escape($filter_clause), … … 218 219 log_assert(is_round_id($round_id)); 219 220 220 // delete all round-task relations 221 $query = sprintf("DELETE FROM ia_round_task 222 WHERE round_id = '%s'", 223 db_escape($round_id)); 224 db_query($query); 221 $old_tasks_count = count($old_tasks); 222 223 // Do nothing with common tasks, be smart. 224 $common_tasks = array_intersect($old_tasks, $tasks); 225 $old_tasks = array_diff($old_tasks, $common_tasks); 226 $tasks = array_diff($tasks, $common_tasks); 227 228 // delete round-task relations 229 if (count($old_tasks) > 0) { 230 $query = sprintf("DELETE FROM ia_round_task 231 WHERE round_id = %s AND task_id IN (%s)", 232 db_quote($round_id), 233 implode(',', array_map("db_quote", $old_tasks))); 234 db_query($query); 235 } 236 225 237 foreach($old_tasks as $task) { 226 238 // Update parent round cache for old tasks … … 231 243 // insert new relations 232 244 $values = array(); 245 $order_id = $old_tasks_count; 233 246 foreach ($tasks as $task_id) { 234 $values[] = "('".db_escape($round_id)."', '".db_escape($task_id)."')"; 247 $order_id += 1; 248 $values[] = "('".db_escape($round_id)."', '". 249 db_escape($task_id)."', '".db_escape($order_id)."')"; 235 250 } 236 $query = "INSERT INTO ia_round_task (round_id, task_id )251 $query = "INSERT INTO ia_round_task (round_id, task_id, order_id) 237 252 VALUES ". implode(', ', $values); 238 253 db_query($query); … … 242 257 } 243 258 } 259 260 round_task_recompute_order($round_id); 244 261 } 245 262 -
trunk/common/db/task.php
r1120 r1132 4 4 require_once(IA_ROOT_DIR . "common/task.php"); 5 5 require_once(IA_ROOT_DIR . "common/db/parameter.php"); 6 require_once(IA_ROOT_DIR . "common/db/round_task.php"); 6 7 7 8 // Add $task to cache if not null, return $task. … … 55 56 } 56 57 58 // Deletes a task from ia_round_task 59 function task_delete_from_rounds($task_id) { 60 // Get all rounds for the task 61 $query = "SELECT DISTINCT round_id FROM ia_round_task 62 WHERE task_id = " . db_quote($task_id); 63 $res = db_fetch_all($query); 64 65 // Delete task 66 db_query("DELETE FROM ia_round_task WHERE task_id = ".db_quote($task_id)); 67 68 // Repair rounds order 69 foreach ($res as $row) { 70 round_task_recompute_order($row['round_id']); 71 } 72 } 73 57 74 // Delete a task, including scores, jobs and page 58 75 // WARNING: This is irreversible. … … 80 97 81 98 // Remove task from all rounds 82 db_query("DELETE FROM `ia_round_task` 83 WHERE `task_id` = " . db_quote($task["id"])); 99 task_delete_from_rounds($task['id']); 84 100 85 101 // Delete task jobs … … 247 263 return $tasks; 248 264 } 265 266 // Updates the forum topic associated with a task. 267 function task_update_forum_topic($task_id, $round_id = "arhiva") { 268 if (!is_task_id($task_id)) { 269 log_error("Invalid task id"); 270 } 271 272 // Get task info 273 $query = "SELECT title, page_name FROM ia_task 274 WHERE id = " . db_quote($task_id); 275 $task = db_fetch($query); 276 277 // Get the forum topic 278 $query = "SELECT forum_topic 279 FROM ia_textblock 280 WHERE name = " . db_quote($task['page_name']); 281 $res = db_fetch($query); 282 $topic_id = $res['forum_topic']; 283 284 // Check the textblock has an associated forum topic. 285 if (is_null($topic_id)) { 286 return; 287 } 288 289 // Get the first message from the topic 290 $query = "SELECT ID_FIRST_MSG AS `msg_id` 291 FROM ia_smf_topics 292 WHERE ID_TOPIC = " . db_quote($topic_id); 293 $res = db_fetch($query); 294 // Topic id doesn't exist 295 if (is_null($res)) { 296 return; 297 } 298 $message_id = $res['msg_id']; 299 300 // Get the subject and the body of the message 301 $query = "SELECT subject, body FROM ia_smf_messages 302 WHERE ID_MSG = " . db_quote($message_id); 303 $message = db_fetch($query); 304 305 // Find the number associated with the (task, round) pair. 306 $query = sprintf( 307 "SELECT order_id FROM ia_round_task 308 WHERE round_id = %s AND task_id = %s", 309 db_quote($round_id), db_quote($task_id)); 310 $res = db_fetch($query); 311 $task_number = sprintf("%03d", $res['order_id'] - 1); 312 313 // New info 314 $new_subject = $task_number . " " . $task['title']; 315 $body_start = mb_substr($message['body'], 0, 35); 316 if ($body_start != "Aici puteti discuta despre problema" && 317 $body_start != "Aici puteÈ›i discuta despre prob" && 318 $body_start != "Aici puteÅ£i discuta despre probl") { 319 $new_body = 'Aici puteÅ£i discuta despre problema ' . 320 '[url=http://infoarena.ro/problema/' . $task_id . ']' . 321 $task['title'] . '[/url].'; 322 } else { 323 $new_body = $message['body']; 324 } 325 326 // Finally, update the message 327 $query = sprintf( 328 "UPDATE ia_smf_messages 329 SET subject = %s, body = %s 330 WHERE ID_MSG = %s", 331 db_quote($new_subject), db_quote($new_body), db_quote($message_id)); 332 db_query($query); 333 334 // Not finished yet, must change replies too. 335 // This is extremely time consuming. 336 if ($new_subject != $message['subject']) { 337 $query = sprintf( 338 "UPDATE ia_smf_messages 339 SET subject = %s 340 WHERE subject LIKE %s", 341 db_quote("Răspuns: " . $new_subject), 342 db_quote("%" . $message['subject'])); 343 db_query($query); 344 } 345 } 346 249 347 ?> -
trunk/www/controllers/round.php
r1125 r1132 3 3 require_once(IA_ROOT_DIR."common/db/db.php"); 4 4 require_once(IA_ROOT_DIR."common/db/round.php"); 5 require_once(IA_ROOT_DIR."common/db/round_task.php"); 5 6 require_once(IA_ROOT_DIR."common/db/task.php"); 6 7 require_once(IA_ROOT_DIR."common/round.php"); … … 203 204 } 204 205 206 function controller_round_task_order($round_id) { 207 // Validate round_id 208 if (!is_round_id($round_id)) { 209 flash_error('Identificatorul rundei este invalid'); 210 redirect(url_home()); 211 } 212 213 // Get round 214 $round = round_get($round_id); 215 if (!$round) { 216 flash_error("Runda nu exista"); 217 redirect(url_home()); 218 } 219 220 // Security check 221 identity_require('round-edit', $round); 222 223 if (request_is_post()) { 224 // Request a list of ids with the new task order 225 $task_order_strings = explode(';', request('task_order', '')); 226 227 // Evil users, abort post. 228 foreach ($task_order_strings as $order_string) { 229 if (!is_numeric($order_string)) { 230 redirect(url_round_edit_task_order($round_id)); 231 } 232 } 233 234 // Parse the values 235 $task_order = array_map("intval", $task_order_strings); 236 237 // Increment by 1 238 foreach ($task_order as &$order_id) { 239 $order_id += 1; 240 } 241 unset($order_id); 242 243 // Get the tasks 244 $first = min($task_order) - 1; 245 $count = count($task_order); 246 $tasks = round_get_tasks($round_id, $first, $count); 247 248 $task_ids = array(); 249 foreach ($tasks as $task) { 250 $task_ids[$task['order']] = $task['id']; 251 } 252 253 // Check each order_id has an associated task_id 254 // Another evil users check 255 foreach ($task_order as $order_id) { 256 if (!getattr($task_ids, $order_id)) { 257 redirect(url_round_edit_task_order($round_id)); 258 } 259 } 260 261 $current_id = $first + 1; 262 foreach ($task_order as $order_id) { 263 $task_id = $task_ids[$order_id]; 264 265 if ($current_id != $order_id) { 266 round_task_update_order_id($round_id, $task_id, $current_id); 267 task_update_forum_topic($task_id); 268 } 269 270 $current_id += 1; 271 } 272 } 273 274 // Create view. 275 $view = array(); 276 $view['title'] = "Editare ordine probleme $round_id"; 277 $view['page_name'] = url_round_edit_task_order($round_id); 278 $view['round_id'] = $round_id; 279 $view['round'] = $round; 280 281 execute_view_die("views/round_task_order.php", $view); 282 } 283 205 284 // Creates a round. Minimalist 206 285 function controller_round_create() -
trunk/www/index.php
r1111 r1132 130 130 } 131 131 132 // Round detail editor and deleter133 else if ($urlstart == 'admin' && getattr($pagepath, 1) == 'runda' ) {134 $obj_id = implode("/", array_slice($pagepath, 2));132 // Round edit parameters 133 else if ($urlstart == 'admin' && getattr($pagepath, 1) == 'runda' && 134 $action == 'edit-params') { 135 135 require_once(IA_ROOT_DIR.'www/controllers/round.php'); 136 require_once(IA_ROOT_DIR.'www/controllers/textblock.php'); 137 if ($action == 'sterge-runda') { 138 if (request('delete-pages')) { 139 $v = request('textblocks'); 140 controller_textblock_delete_many($v, url_round_delete($obj_id)); 141 } elseif (request('delete-round')) { 142 controller_round_delete($obj_id); 143 } else { 144 controller_round_delete_view($obj_id); 145 } 136 $round_id = implode("/", array_slice($pagepath, 2)); 137 controller_round_details($round_id); 138 } 139 140 // Round edit task order 141 else if ($urlstart == 'admin' && getattr($pagepath, 1) == 'runda' && 142 $action == 'edit-task-order') { 143 require_once(IA_ROOT_DIR.'www/controllers/round.php'); 144 $round_id = implode("/", array_slice($pagepath, 2)); 145 controller_round_task_order($round_id); 146 } 147 148 // Round delete 149 else if ($urlstart == 'admin' && getattr($pagepath, 1) == 'runda' && 150 $action == 'sterge-runda') { 151 require_once(IA_ROOT_DIR.'www/controllers/round.php'); 152 require_once(IA_ROOT_DIR.'www/controllers/textblock.php'); 153 $round_id = implode("/", array_slice($pagepath, 2)); 154 if (request('delete-pages')) { 155 $v = request('textblocks'); 156 controller_textblock_delete_many($v, url_round_delete($round_id)); 157 } elseif (request('delete-round')) { 158 controller_round_delete($round_id); 146 159 } else { 147 controller_round_de tails($obj_id);160 controller_round_delete_view($round_id); 148 161 } 149 162 } -
trunk/www/macros/macro_tasks.php
r1128 r1132 153 153 154 154 // get round tasks 155 $tasks = round_get_tasks($round_id, 155 $tasks = round_get_tasks( 156 $round_id, 156 157 $options['first_entry'], 157 158 $options['display_entries'], 158 $user_id, $scores, 159 $filter, $show_progress); 159 $user_id, 160 $scores, 161 $filter, 162 $show_progress); 163 160 164 $options['total_entries'] = round_get_task_count( 161 165 $round_id, $user_id, $filter); 162 166 $options['row_style'] = 'task_row_style'; 167 $options['css_row_parity'] = true; 168 163 169 $options['css_class'] = 'tasks'; 164 $options['css_row_parity'] = true; 170 if (getattr($args, 'drag_and_drop', false)) 171 $options['css_class'] .= ' dragndrop'; 165 172 166 173 $column_infos = array(); -
trunk/www/static/css/screen.css
r1128 r1132 1044 1044 table { 1045 1045 border-collapse: collapse; 1046 line-height: 2em; 1047 margin: 0.5em; 1048 width: 99%; 1046 1049 } 1047 1050 -
trunk/www/url.php
r1125 r1132 308 308 function url_round_edit_params($round_id) { 309 309 log_assert(is_round_id($round_id)); 310 return url_complex("admin/runda/" . $round_id); 310 return url_complex("admin/runda/" . $round_id, 311 array('action' => 'edit-params')); 312 } 313 314 function url_round_edit_task_order($round_id) { 315 log_assert(is_round_id($round_id)); 316 return url_complex("admin/runda/" . $round_id, 317 array('action' => 'edit-task-order')); 311 318 } 312 319 -
trunk/www/views/header.php
r1121 r1132 69 69 <script type="text/javascript" src="<?= html_escape(url_static('js/tags.js')) ?>"></script> 70 70 <script type="text/javascript" src="<?= html_escape(url_static('js/roundtimer.js')) ?>"></script> 71 <script type="text/javascript" src="<?= html_escape(url_static('js/foreach.js')) ?>"></script> 72 <script type="text/javascript" src="<?= html_escape(url_static('js/tablednd.js')) ?>"></script> 71 73 72 74 <script type="text/javascript" src="http://summify.com/client/v1/249f00c6/client.js"></script> -
trunk/www/views/round_edit_header.php
r1125 r1132 10 10 $tab_names = array( 11 11 'edit' => 'Pagină', 12 'round-edit-params' => 'Parametri'); 12 'round-edit-params' => 'Parametri', 13 'round-edit-task-order' => 'Ordine probleme'); 13 14 14 15 $tab_urls = array( 15 16 'edit' => url_round_edit($round_id), 16 'round-edit-params' => url_round_edit_params($round_id)); 17 'round-edit-params' => url_round_edit_params($round_id), 18 'round-edit-task-order' => url_round_edit_task_order($round_id)); 17 19 18 20 $permissions = array( 19 21 'edit' => 'round-edit', 20 'round-edit-params' => 'round-edit'); 22 'round-edit-params' => 'round-edit', 23 'round-edit-task-order' => 'round-edit'); 21 24 22 25 $round = round_get($round_id);
Note: See TracChangeset
for help on using the changeset viewer.
![[infoarena] development](/chrome/site/logo.png)