php8
[web.mtrack] / MTrackWeb / Report.php
index 0fa3282..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,28 +36,44 @@ 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');
 
-        if ($pi) {
+        if (!empty($_GET['format']) && $pi) {
           // targeted report format; omit decoration <<< ??? tab delimited only at present?
             $params = $_GET;
-            $params['format'] = isset($params['format']) ? $_GET['format'] : '' ;
+            $params['format'] = isset($params['format']) ? $_GET['format'] : 'html' ;
             $format = $params['format'];
             
             unset($params['format']);
@@ -64,27 +82,56 @@ class MTrackWeb_Report extends MTrackWeb
                     header('Content-Type: text/plain');
                     break;
             }
-            echo $rep->renderReport($rep->query, $params, $format);
+            echo $rep->render( $params, $format);
             exit;
         }
-        
-        die("not yet")
+        /*
         $this->title = "Create Report";
         if ($pi) {
             $this->title = $this->edit ? 
-                ('{' . $rep->rid . '} ' . $rep->summary . " (edit)") : 
-                '{' . $rep->rid . '} ' . $rep->summary;
+                ('{' . $rep->id . '} ' . $rep->summary . " (edit)") : 
+                '{' . $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")
+        die("not yet");
         $pi = (int) $pi;
         if (!$pi) {
             MTrackACL::requireAllRights('Reports', 'create');
@@ -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);