MTrackWeb/Project.php
[web.mtrack] / MTrackWeb / Project.php
1 <?php
2 require_once 'MTrackWeb.php';
3
4 class MTrackWeb_Project extends MTrackWeb
5 {
6     
7     //function getAuth-- inherit
8     
9     function get($code='') {
10         
11         if (isset($_REQUEST['active_project_id'])) {
12             $this->currentProject($_REQUEST['active_project_id']);
13             return $this->jok($this->currentProject());
14         }
15         
16         if (!isset($_REQUEST['ajax_body'])) {
17             return;
18         }
19         $this->masterTemplate = 'project.html';
20          
21         $p = DB_DataObject::factory('Projects');
22         $p->get( $this->currentProject());
23         $this->project = $p;
24         
25         /// milestones..
26         
27         $this->milestones = $this->project->milestones();
28         
29         
30         
31         // compoennts...
32         
33         
34         // permissions..
35         if (!$this->authUser) {
36             return;
37         }
38         ///DB_DataObject::debugLevel(1);
39         // fetch permissions.
40         $gr = DB_DataObject::factory('Group_Rights');
41         $ar = $gr->defaultPermData();
42         //echo '<PRE>';print_r($ar);
43         $perms = array();
44         foreach($ar as $nm=>$data) {
45             if (!preg_match('/^MTrack\./', $nm)) {
46                 continue;
47             }
48             $perms[] = $nm; 
49                 
50         }
51         $gr = DB_DataObject::factory('Group_Rights');
52         $gr->whereAddIn('rightname', $perms, 'string');
53         $gr->selectAdd();
54         
55         $gr->selectAdd('distinct(group_id) as group_id');
56         $gr->whereAdd("AccessMask != ''");
57         $gids = $gr->fetchAll('group_id');
58         //print_R($gids);
59         
60         $g = DB_DataObject::Factory('groups');
61         $g->whereAddIn('id',$gids, 'int');
62         $this->groups = $g->fetchAll( );
63         
64         
65         // find out which groups are using those perms... so that we can offer membership to people..
66         
67         
68         
69         
70         // members... (might be large one day)
71         $pr = DB_DataObject::Factory('ProjectDirectory');
72         $pr->project_id = $this->currentProject();
73         //$pr->autoJoin();
74         
75         if ($this->authUser->company()->comptype !='OWNER') {
76             $pr->whereAdd("role=''");
77         }
78         $ar  = $pr->fetchAll();
79         $e = new HTML_Template_Flexy_Element('input',
80                                              array('type'=>'checkbox', 'value'=>"1"));
81         foreach($ar as $pd) {
82             $pd->person = $pd->person();
83             $pd->person->perms = $pd->person->getPerms();
84             
85             $g = DB_DataObject::Factory('Group_Members');
86             $pd->person->groups  = $g->listGroupMembership($pd->person);
87             
88             foreach($this->groups as $g) {
89                 $ee = clone($e);
90                 $ee->name = $pd->person->id .'_'. $g->id;
91                 
92                 //print_r($pd);
93                 if (in_array($g->id, $pd->person->groups)) {
94                     $ee->setValue(1);   
95                 }
96                 $this->elements[$ee->name] = $ee;
97                     
98             }
99             
100             
101              
102             $this->people[] = $pd;
103             
104             
105         }
106         
107         
108         
109     }
110     
111     function checkGroupPerson($p,$g)
112     {
113         
114         $str = '<input class="mtrack-perm" type="checkbox" name="'. $p->id . '_'. $g->id. '" value="1"';
115             
116         if (in_array($g->id, $p->person->groups)) {
117             $str .= ' checked="checked"';
118         }
119         return $str. '>';
120     }
121     /**
122      *
123      * Things that can change...
124      * - permission updates 
125      *
126      */
127     function post()
128     {
129         
130         
131     }
132     
133 }