Fixed XML parsing error
[speedfreak] / Server / application / controllers / results.php
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
2 /*
3  * API controller for managing and viewing results and categories
4  * 
5  * @author      Artem Daniliants <artem@daniliants.com>
6  * @copyright   (c) 2010 Speed Freak team
7  * @license     http://opensource.org/licenses/gpl-license.php GNU Public License
8  */
9
10 class Results_Controller extends Controller{
11         
12         /*
13      * Get categories list and output it as XML
14      *
15      */
16     public function categories(){
17         if (apiler::is_authorized()){
18                 $view = new View('api/categories');
19                 $cat = new Category_Model();
20                 $view->categories=$cat->get_all();
21                 $view->render(true);
22         }
23         else
24            apiler::not_authorized();
25     }
26
27     /*
28      * Get results
29      *
30      */
31     public function list_results($category, $limit, $show_unit=false){
32         $results = New Result_Model();
33         $cat = New Category_Model();
34         if ($cat->category_exists($category) AND apiler::is_authorized() AND isset($limit)){
35                 $view = new View('api/results');
36                 $view->results = $results->get_results($category, $limit);
37                 $view->show_unit=$show_unit;
38                 $view->render(true);
39             }
40         else
41             apiler::not_authorized();
42     }
43
44     /*
45      * Submit results to selected category
46      *
47      * @param string $category Category to which results are submitted
48      */
49     public function update($category){
50         $cat = New Category_Model();
51         if ($cat->category_exists($category) AND apiler::is_authorized()){
52                 $xml = apiler::get_xml();
53                 $result = New Result_Model();
54                 if ($result->insert($category,$_SERVER['PHP_AUTH_USER'], $xml['value'])){
55                         print "OK";
56                         die;
57                 }
58                 else {
59                         header("HTTP/1.1 400 Bad Request");
60                     echo "Invalid request";
61                     die;
62                 }
63         }
64         else {
65             header("HTTP/1.0 404 Not Found");
66             die('Category not found or not authorized');
67         }
68
69     }
70     
71 }