php8
[web.mtrack] / MTrackWeb / Report.php
index 3574c6a..0a61fcc 100644 (file)
@@ -17,7 +17,9 @@ class MTrackWeb_Report extends MTrackWeb
     function get($pi=0)
     {
        
-       
+        if (isset($_REQUEST['ajax_body2'])) {
+            return $this->get2($pi);
+        }
         if (!isset($_REQUEST['ajax_body'])) {
             return;
         }
@@ -34,21 +36,37 @@ class MTrackWeb_Report extends MTrackWeb
         
         
         
-        if ($this->edit && !$pi) {
+        if ($this->edit || !$pi) {
             throw new Exception("no editing yet");
         }
         // only support id???
-        if ($pi) {
-            $rep = DB_DataObject::factory('mtrack_report');
-            // we do not have any reports yet... - so we have a dummy one..
-            //$rep->get($pi);
-            //MTrackACL::requireAllRights("report:" . $rep->rid, $this->edit ? 'modify' : 'read');
-        }
-    
+        $rep = DB_DataObject::factory('mtrack_report');
+        $rep->get($pi); // eventually GET..
         
     
     
     
+        // select boxes for quickly changing stuff..
+    
+       
+        foreach(array( 'classification', 'priority', 'severity', 'resolution' ) as $c)  {
+            $d = DB_DataObject::factory('core_enum');
+            $d->etype = $c;
+            $d->orderBy('seqid ASC, name ASC');
+            if (!$d->count()) {
+                $d->createBaseEntries();
+                
+            }
+            $ar = $d->fetchAll('id','name');
+            if (!$this->id) {
+                $ar = array_merge( array(0 => '-- Select --'),$ar);
+            }
+            $this->elements[$c.'_id'] = new HTML_Template_Flexy_Element('select');
+            $this->elements[$c.'_id']->setOptions($ar);
+            
+        }
+        
+       // DB_DataObject::debugLevel(1);
         ///$rep = MTrack_Report::loadBySummary($pi);
         ///MTrackACL::requireAllRights("report:" . $rep->rid, $edit ? 'modify' : 'read');
 
@@ -75,13 +93,42 @@ class MTrackWeb_Report extends MTrackWeb
                 '{' . $rep->id . '} ' . $rep->summary;
         }
         */
-        $this->canModify = MTrackACL::hasAllRights("report:" . $rep->rid, 'modify');
+       // $this->canModify = MTrackACL::hasAllRights("report:" . $rep->rid, 'modify');
         $this->rep = $rep;
         
          
 
     }
     
+    function get2($pi)
+    {
+        // the ajax version...
+        // just returns data which can be rendered using the jtemplate code..
+        
+    
+        $this->id = $pi ?  $pi: (isset($_GET['id']) ? $_GET['id'] : 0);
+        $this->id  = $this->id  == 'new' ? 0 : $this->id;
+        $this->id  = (int) $this->id;
+        
+       
+        $pi = (int) $pi;
+        
+        // only support id???
+        $rep = DB_DataObject::factory('mtrack_report');
+        
+        $rep->get($pi); // eventually GET..
+        
+        $this->jdata($rep->renderToJSON(), false,
+            array('report' => $rep->toArray())
+        );
+    
+        $this->rep = $rep;
+        
+         
+    }
+    
+    
+    
     function post($pi=0)
     {
         die("not yet");
@@ -106,8 +153,9 @@ class MTrackWeb_Report extends MTrackWeb
         }
         // in theory... everything else is a 'save'...
         try {
+            // this does not match api!??
             $cs = DB_DataObject::Factory('mtrack_change');
-            $cs->begin( "report:" . $rep->summary, $_POST['comment']);
+            $cs->beginChange( "report:" . $rep->summary, $_POST['comment']);
             $rep->save($cs);
             $cs->commit();
             return $this->get($pi);