php8
[web.mtrack] / MTrackWeb / Gitlive.php
1 <?php
2
3 /**
4  * JSON api for gitlive desktop application
5  */
6 require_once 'MTrackWeb.php';
7 class MTrackWeb_Gitlive extends MTrackWeb
8 {
9     function h401()
10     {
11         header('WWW-Authenticate: Basic realm="Gitlive"');
12         header('HTTP/1.0 401 Unauthorized');
13         echo 'Needs data!';
14         exit;
15     }
16     function getAuth()
17     {
18         if (!isset($_SERVER['PHP_AUTH_USER'])) {
19             $this->h401();
20         } 
21         $u = DB_DataObject::factory('core_person');
22         //$u->active = 1;
23         $u->whereAdd('LENGTH(passwd) > 1');
24         //$u->company_id = $this->company->id;
25          
26         $u->email = $_SERVER['PHP_AUTH_USER'];
27         if ($u->count() > 1 || !$u->find(true)) {
28             $this->h401();
29             
30         }
31         
32         //if (!$u->active) {
33         //    return $this->errmsg('disabled');
34         //}
35         
36         if ($u->checkPassword($_SERVER['PHP_AUTH_PW'])) {
37             $u->login();
38             $this->authUser = $u;
39             // we do not log automated???
40             return true;
41
42             //exit;
43         }    
44             
45             
46     }
47     
48     function get($pi) {
49         
50         $pi .= (strlen($pi) ? $this->bootLoader->ext : '');
51         $r = DB_DataObject::factory('mtrack_repos');
52         if (!$r->get('shortname', $pi)) {
53             $this->jerr("invalid repo");
54         }
55         // make sure it's a valid project..
56         if (!$this->projectPerm($r->project_id, 'MTrack.Issue', 'S')) {
57             $this->jerr("no perms");
58         }
59         //DB_DAtaObject::DebugLevel(1);
60         $t = DB_DataObject::Factory('mtrack_ticket');
61         $t->autoJoin();
62         $t->whereAdd("join_status_id.name IN ( 'open', 'new')");
63         $t->project_id = $r->project_id;
64         // only need id / name / status?
65         //$ar = $t->fetchAll('id', ');
66         $t->selectAdd();
67         $t->selectAdd('
68                 mtrack_ticket.id as id ,
69                 mtrack_ticket.summary as summary,
70                 mtrack_ticket.description as description
71         ');
72         
73         $t->find();
74         $ret = array();
75         while ($t->fetch()) {
76             $ret[] = $t->toArray('%s', 0);
77         }
78          
79     //    print_R($ar);
80         $this->jok($ret);
81         $this->jok("WORKED!");
82         
83     }
84     
85 }