php8
[web.mtrack] / MTrackWeb / Project.php
index 6722a87..a45ba48 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+require_once 'MTrackWeb.php';
 
 class MTrackWeb_Project extends MTrackWeb
 {
@@ -12,7 +13,170 @@ class MTrackWeb_Project extends MTrackWeb
             return $this->jok($this->currentProject());
         }
         
-        die("TODO - what happens when you go to a project page..");
+        if (!isset($_REQUEST['ajax_body'])) {
+            return;
+        }
+        $this->masterTemplate = 'project.html';
+         
+        $p = DB_DataObject::factory('core_project');
+        $p->get( $this->currentProject());
+        $this->project = $p;
+        
+        /// milestones..
+        
+        $this->milestones = $this->project->milestones();
+        
+        
+        
+        // compoennts...
+        
+        
+        // permissions..
+        if (!$this->authUser) {
+            return;
+        }
+        ///DB_DataObject::debugLevel(1);
+        // fetch permissions.
+        $gr = DB_DataObject::factory('core_group_right');
+        $ar = $gr->defaultPermData();
+        //echo '<PRE>';print_r($ar);
+        $perms = array();
+        foreach($ar as $nm=>$data) {
+            if (!preg_match('/^MTrack\./', $nm)) {
+                continue;
+            }
+            $perms[] = $nm; 
+                
+        }
+        $gr = DB_DataObject::factory('core_group_right');
+        $gr->whereAddIn('rightname', $perms, 'string');
+        $gr->selectAdd();
+        
+        $gr->selectAdd('distinct(group_id) as group_id');
+        $gr->whereAdd("AccessMask != ''");
+        $gids = $gr->fetchAll('group_id');
+        //print_R($gids);
+        
+        $g = DB_DataObject::factory('core_group');
+        $g->whereAddIn('id',$gids, 'int');
+        $this->groups = $g->fetchAll( );
+        
+        
+        // find out which groups are using those perms... so that we can offer membership to people..
+        
+        
+        
+        
+        // members... (might be large one day)
+        $pr = DB_DataObject::Factory('ProjectDirectory');
+        $pr->project_id = $this->currentProject();
+        //$pr->autoJoin();
+        
+        if ($this->authUser->company()->comptype !='OWNER') {
+            $pr->whereAdd("role=''");
+        }
+        $pr->orderBY('role DESC');
+        $ar  = $pr->fetchAll();
+    
+        
+        foreach($ar as $pd) {
+            $pd->person = $pd->person();
+            $pd->person->perms = $pd->person->getPerms();
+            
+            $g = DB_DataObject::factory('core_group_member');
+            $pd->person->groups  = $g->listGroupMembership($pd->person);
+            
+             
+             
+            $this->people[] = $pd;
+            
+            
+        }
+        
+        
+        
+    }
+    
+    function checkGroupPerson($p,$g)
+    {
+        
+        $str = '<input class="mtrack-perm" type="checkbox" name="'. $p->id . '_'. $g->id. '" value="1"';
+            
+        if (in_array($g->id, $p->groups)) {
+            $str .= ' checked="checked"';
+        }
+        return $str. '>';
+    
+    }
+    /**
+     *
+     * Things that can change...
+     * - permission updates 
+     *
+     */
+    function post()
+    {
+        if (empty($_POST['action'])) {
+            $this->jerr("invalid action");
+            
+        }
+        
+        switch ($_POST['action']) {
+            case 'perm':
+                
+                //DB_DataObject::debugLevel(1);
+                if ($this->authUser->company()->comptype != 'OWNER') {
+                    $this->jerr("Owner company only");
+                }
+                if (!$this->hasPerm('Core.Groups', 'E')) {
+                    $this->jerr("permission denied");
+                }
+                
+                $p = DB_DataObject::factory('core_person');
+                if (empty($_POST['uid']) || !$p->get($_POST['uid'])) {
+                    $this->jerr("invalid user");
+                }
+                $g = DB_DataObject::factory('core_group');
+                if (empty($_POST['gid']) || !$g->get($_POST['gid'])) {
+                    $this->jerr("invalid group");
+                }
+                // verify group is a MTrack only??
+                
+                
+                $state = empty($_POST['value']) ? 0 : 1;
+                $gm = DB_DataObject::factory('core_group_member');
+                $gm->change($p, $g, $state);
+                $this->jok("updated");
+            
+            case 'role':
+                //DB_DataObject::debugLevel(1);
+                if ($this->authUser->company()->comptype != 'OWNER') {
+                    $this->jerr("Owner company only");
+                }
+                // which role ... this is not really correct.
+                if (!$this->hasPerm('Core.Groups', 'E')) {
+                    $this->jerr("permission denied");
+                }
+                
+                $pd = DB_DataObject::factory('ProjectDirectory');
+                if (empty($_POST['pdid']) || !$pd->get($_POST['pdid'])) {
+                    $this->jerr("invalid line");
+                }
+                $pd->role = $_POST['value'];
+                $pd->update();
+                
+                
+                
+            
+            
+            default:
+                $this->jerr("invalid action");
+                
+            
+            
+            
+        }
+        
         
     }