php8
[web.mtrack] / MTrackWeb / Project.php
index a5f7476..a45ba48 100644 (file)
@@ -18,7 +18,7 @@ class MTrackWeb_Project extends MTrackWeb
         }
         $this->masterTemplate = 'project.html';
          
-        $p = DB_DataObject::factory('Projects');
+        $p = DB_DataObject::factory('core_project');
         $p->get( $this->currentProject());
         $this->project = $p;
         
@@ -37,7 +37,7 @@ class MTrackWeb_Project extends MTrackWeb
         }
         ///DB_DataObject::debugLevel(1);
         // fetch permissions.
-        $gr = DB_DataObject::factory('Group_Rights');
+        $gr = DB_DataObject::factory('core_group_right');
         $ar = $gr->defaultPermData();
         //echo '<PRE>';print_r($ar);
         $perms = array();
@@ -48,16 +48,16 @@ class MTrackWeb_Project extends MTrackWeb
             $perms[] = $nm; 
                 
         }
-        $gr = DB_DataObject::factory('Group_Rights');
+        $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);
+        //print_R($gids);
         
-        $g = DB_DataObject::Factory('groups');
+        $g = DB_DataObject::factory('core_group');
         $g->whereAddIn('id',$gids, 'int');
         $this->groups = $g->fetchAll( );
         
@@ -75,27 +75,109 @@ class MTrackWeb_Project extends MTrackWeb
         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('Group_Members');
+            $g = DB_DataObject::factory('core_group_member');
             $pd->person->groups  = $g->listGroupMembership($pd->person);
+            
+             
              
             $this->people[] = $pd;
+            
+            
         }
         
         
         
     }
     
-    function checkGroupPerson($g,$p)
+    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)) {
-            return 'checked';
+            $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");
+                
+            
+            
+            
         }
-        return '';
+        
+        
     }
     
 }
\ No newline at end of file