php8
[web.mtrack] / MTrackWeb / Log.php
1 <?php # vim:ts=2:sw=2:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
3
4 require_once 'MTrackWeb.php';
5
6 class MTrackWeb_Log extends MTrackWeb
7 {
8      
9     function getAuth()
10     {
11         
12         parent::getAuth();
13        
14         return true;
15     }
16     
17     function get($pi)
18     {
19        // echo "STARGING";
20         if (!isset($_REQUEST['ajax_body'])) {
21             return;
22         }
23         $this->masterTemplate = 'log.html';
24          
25        
26         $this->pi = empty($pi) ? '' : ($pi . $this->bootLoader->ext);
27        
28         $this->repo = DB_DataObject::factory('mtrack_repos');
29         $this->filename = $this->repo->loadFromPath($this->pi);
30         
31        
32         if (!$this->repo->id) {
33             return HTML_FlexyFramework::run('Browse');  
34         };
35           
36         if (!$this->projectPerm($this->repo->project_id, 'MTrack.Repos', 'S')) {
37             return HTML_FlexyFramework::run('Noperm');  // noperm = loggedin -> need more perms / not.. try loggin in..
38         }
39         
40          
41         
42         $this->branches = $this->repo->getBranches();
43
44         
45         
46         $this->title = "Log $this->filename";
47         
48         $this->branches = $this->repo->getBranches();
49         
50         
51         $this->crumbs = array();
52         $location = '';
53         $this->basename = basename($this->filename);
54         $crumbs = dirname($this->filename) == '.'  || !strlen(dirname($this->filename)) ?
55             array() : explode('/', dirname($this->filename));
56       
57         foreach($crumbs as $path) 
58         {
59             
60             $c = new StdClass;
61             $c->name = strlen($path) ? $path : '[root]';
62             $c->root = strlen($path) ? 0 : 1;
63             $location .=  strlen($location) ? '/' : '';
64             $location .=  strlen($path)  ?  urlencode($path)  : '';
65             $c->location = $location;
66             $this->crumbs[] = $c;
67         } 
68           
69         $branches = $this->repo->getBranches();
70         $tags = $this->repo->getTags();
71         if (count($branches) + count($tags)) {
72             $this->showJump = 1;
73             $jumps = array("" => "- Select Branch / Tag - ");
74             if (is_array($branches)) {
75                 foreach ($branches as $name => $notcare) {
76                     $jumps["branch:$name"] = "Branch: $name";
77                 }
78             }
79             if (is_array($tags)) {
80                 foreach ($tags as $name => $notcare) {
81                     $jumps["tag:$name"] = "Tag: $name";
82                 }
83             }
84             
85             $this->elements['jump'] = new HTML_Template_Flexy_Element('select');
86             $this->elements['jump']->setOptions($jumps);  
87             $this->elements['jump']->setValue(empty($_GET['jump']) ? '' : $_GET['jump']);
88         }
89         $object = null;
90         $ident = null;
91         if (!empty($_GET['jump'])) {
92             list($object, $ident) = explode(':', $_GET['jump'], 2);
93         }
94             
95             
96         $last_day = null;
97         $even = 1;
98         
99         $offset= empty($_GET['offset']) ? 0 : (int) $_GET['offset'];
100         $this->offset = $offset+100;
101         $hist = $this->repo->history($this->filename, array($offset,100), $object, $ident);
102         
103         if (empty($hist)) {
104             return; // an error conditon!?!
105         }
106         $this->rev = $hist[0]->rev;
107         if (count($hist) < 100) {
108             $this->offset = 0;
109         }
110         // code here...
111         // repo has a 'release' branch, this should be used to track what needs 
112         // merging from 'HEAD' to update it
113         // (basically how far behind is the release from head..)
114                 
115  //         $need_review = ' style="background-color:#fdd;"';
116  //         $good_to_go = ' style="background-color:#585;"';
117  //         $live = ' style="background-color:#336;"';
118   
119         //$is_live = false;
120         $this->hist= array();
121         foreach($hist as $i=>$h) {
122             $h->cls = $i % 2 ? 'odd' : '';
123         
124             $ts = strtotime($h->ctime);
125             $day = date('D, M d Y', $ts);
126             $time = date('g:ia', $ts);
127             //print_r($ent);
128             if ($day !== $last_day) {
129                 $this->hist[] = (object) array(
130                     'isday' => 1,
131                     'day' => $day
132                 );
133             }
134             $h->time = $time;
135                 
136             $last_day = $day;
137             $M = array();
138            // if (preg_match('/#([0-9]+)\s+/', $h->changelog, $M)) {
139                 
140            //     $h->ticket = MTrackIssue::loadByNSIdent($M[1]) ;
141                 // ticket->status == closed == ok to commit to another branch...
142                // echo '<PRE>'; print_r($h->ticket);
143            // }
144             
145              
146        
147     
148             $this->hist[] = $h;
149         }
150     }
151         
152 }
153