final move of files
[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     var $template = 'log.html';
9     function getAuth()
10     {
11         
12         parent::getAuth();
13         MTrackACL::requireAllRights('Browser', 'read');
14         return true;
15     }
16     
17     function get($pi)
18     {
19        // echo "STARGING";
20         if (!empty($_REQUEST['embed'])) {
21             $this->masterTemplate=$this->template;
22         }
23        
24         $this->pi = empty($pi) ? '' : ($pi . $this->bootLoader->ext);
25         $pi = '/' . $this->pi;
26         if (count(explode('/',$pi)) == 2) {
27             return HTML_FlexyFramework::run('Browse');  
28         };
29         
30         $crumbs = MTrackSCM::makeBreadcrumbs($pi);
31         if (!strlen($pi) || $pi == '/') {
32             $pi = '/';
33             $this->repo = null;
34         } else {
35             $this->repo = MTrackSCM::factory($pi);
36         }
37
38         if ($this->repo === null) {
39           throw new Exception("Cannot determine what to log from $pi");
40         }
41
42         $this->branches = $this->repo->getBranches();
43
44         MTrackACL::requireAllRights("repo:{$this->repo->repoid}", 'read');
45         $this->title = "Log $pi";
46         
47         $this->branches = $this->repo->getBranches();
48         
49         
50         $this->crumbs = array();
51         $location = '';
52         foreach($crumbs as $path) 
53         {
54             //if (count($this->crumbs) && !strlen($path)) {
55             //    continue;
56             //}
57             $c = new StdClass;
58             $c->name = strlen($path) ? $path : '[root]';
59             $c->root = strlen($path) ? 0 : 1;
60             $location .=  strlen($location) ? '/' : '';
61             $location .=  strlen($path)  ?  urlencode($path)  : '';
62             $c->location = $location;
63             $this->crumbs[] = $c;
64         } 
65           
66         $branches = $this->repo->getBranches();
67         $tags = $this->repo->getTags();
68         if (count($branches) + count($tags)) {
69             $this->showJump = 1;
70             $jumps = array("" => "- Select Branch / Tag - ");
71             if (is_array($branches)) {
72                 foreach ($branches as $name => $notcare) {
73                     $jumps["branch:$name"] = "Branch: $name";
74                 }
75             }
76             if (is_array($tags)) {
77                 foreach ($tags as $name => $notcare) {
78                     $jumps["tag:$name"] = "Tag: $name";
79                 }
80             }
81             
82             $this->elements['jump'] = new HTML_Template_Flexy_Element('select');
83             $this->elements['jump']->setOptions($jumps);  
84             $this->elements['jump']->setValue(empty($_GET['jump']) ? '' : $_GET['jump']);
85         }
86         $object = null;
87         $ident = null;
88         if (!empty($_GET['jump'])) {
89             list($object, $ident) = explode(':', $_GET['jump'], 2);
90         }
91             
92             
93         $last_day = null;
94         $even = 1;
95         $hist = $this->repo->history($pi, 100, $object, $ident);
96          
97         if (empty($hist)) {
98             return;
99         }
100         
101         // code here...
102         // repo has a 'release' branch, this should be used to track what needs 
103         // merging from 'HEAD' to update it
104         // (basically how far behind is the release from head..)
105                 
106  //         $need_review = ' style="background-color:#fdd;"';
107  //         $good_to_go = ' style="background-color:#585;"';
108  //         $live = ' style="background-color:#336;"';
109   
110         //$is_live = false;
111         $this->hist= array();
112         foreach($hist as $i=>$h) {
113             $h->cls = $i % 2 ? 'odd' : '';
114         
115             $ts = strtotime($h->ctime);
116             $day = date('D, M d Y', $ts);
117             $time = date('g:ia', $ts);
118             //print_r($ent);
119             if ($day !== $last_day) {
120                 $this->hist[] = (object) array(
121                     'isday' => 1,
122                     'day' => $day
123                 );
124             }
125             $h->time = $time;
126                 
127             $last_day = $day;
128             $M = array();
129             if (preg_match('/#([0-9]+)\s+/', $h->changelog, $M)) {
130                 
131                 $h->ticket = MTrackIssue::loadByNSIdent($M[1]) ;
132                 // ticket->status == closed == ok to commit to another branch...
133                // echo '<PRE>'; print_r($h->ticket);
134             }
135             
136              
137        
138     
139             $this->hist[] = $h;
140         }
141     }
142         
143 }
144