MTrackWeb/DataObjects/Reports.php
authorAlan Knowles <alan@akbkhome.com>
Wed, 16 Mar 2011 16:08:46 +0000 (00:08 +0800)
committerAlan Knowles <alan@akbkhome.com>
Wed, 16 Mar 2011 16:08:46 +0000 (00:08 +0800)
MTrackWeb/DataObjects/Reports.php [deleted file]

diff --git a/MTrackWeb/DataObjects/Reports.php b/MTrackWeb/DataObjects/Reports.php
deleted file mode 100755 (executable)
index f4b0113..0000000
+++ /dev/null
@@ -1,354 +0,0 @@
-<?php
-/**
- * Table Definition for reports
- */
-require_once 'DB/DataObject.php';
-
-class MTrackWeb_DataObjects_Reports extends DB_DataObject 
-{
-    ###START_AUTOCODE
-    /* the code below is auto generated do not remove the above tag */
-
-    public $__table = 'reports';                         // table name
-    public $rid;                             // int(11)  not_null primary_key auto_increment
-    public $summary;                         // string(128)  not_null
-    public $description;                     // string(128)  not_null
-    public $query;                           // string(128)  not_null
-    public $changed;                         // int(11)  not_null
-
-    /* Static get */
-    //  static public $link = null; /// LinkHandler!!
-
-    
-  
-
-    function save(MTrackWeb_DataObjects_Changes $cs) // changes dataobject..
-    {
-        $old = false;
-        if ($this->rid) {
-            $old = DB_DAtaObject::factory('reports');
-            $old->get($this->rid);
-            $this->update($old);
-        } else {
-            $this->insert();
-        }
-        $cs->add("report:" . $this->rid , $old, $new);
-       
-    }
-  
-    function render($params = array(), $format = 'html')
-    {
-        
-        $link = HTML_FlexyFramework::get()->page->link;
-         
-        
-        static $jquery_init = false; //???
-    
-        
-        /* process the report string; any $PARAM in there is recognized
-         * as a parameter and the query munged accordingly to pass in the data */
-    
-        
-        try {
-            $au = HTML_Flexyframework::get()->page->authUser;
-            
-            $params['USER'] = $au->id;
-            /* - controller is repsonsable for passing params...
-            foreach ($params as $p => $v) {
-                if (isset($_GET[$p])) {
-                   $params[$p] = $_GET[$p];
-                }
-            }
-            */
-            $query= $this->query;
-            $n = preg_match_all("/\\$([A-Z]+)/m", $this->query, $matches);
-            for ($i = 0; $i < $n; $i++) { // why start at 1???
-              
-                /* replace with query placeholder */
-                $val= isset($params[$matches[$i][0]]) ? $params[$matches[$i][0]] : '';
-                
-                 
-                $query = str_replace('$' . $matches[$i][0],
-                                    is_numeric($val) ? $val : $this->escape($val),
-                                    $this->query);
-            }
-            //DB_DataObject::debugLevel(1);
-            $x = DB_DataObject::factory('reports'); // not that helpfull...
-            //- perhaps we could extract the tablename from the query..
-            $err = $x->query($query);
-            $results = array();
-            while ($x->fetch()) {
-                //echo '<PRE>';print_r($x);exit;
-                $results[] =  $x->toArray('%s', true);
-            }
-            //echo '<PRE>'; print_r($results);
-            // DATAOBJECTS ERROR???
-        } catch (Exception $e) {
-              return "<div class='error'>" . $e->getMessage() . "<br>" . 
-                    htmlentities($this->query, ENT_QUOTES, 'utf-8') . "</div>";
-        }
-    
-        $out = '';
-    
-        if (count($results) == 0) {
-            return "No records matched";
-        }
-    
-        /* figure out the table headings */
-        $captions = array();
-        $span = array();
-        $rules = array();
-        foreach ($results[0] as $name => $value) {
-          if (preg_match("/^__.*__$/", $name)) {
-            if ($format == 'html') {
-              /* special meaning, not a column */
-              continue;
-            }
-          }
-          $captions[$name] = preg_replace("/^_(.*)_$/", "\\1", $name);
-        }
-        /* for spanning purposes, calculate the longest row */
-        // no idea what this is supposed to do...
-        // colspans???
-        $max_width = 0;
-        $width = 0;
-        foreach ($captions as $name => $caption) {
-            if ($name[0] == '_' && substr($name, -1) == '_') {
-              $width = 1;
-            } else {
-              $width++;
-            }
-            if ($width > $max_width) {
-              $max_width = $width;
-            }
-            if (substr($name, -1) == '_') {
-              $width = 1;
-            }
-        }
-    
-        $group = null;
-        foreach ($results as $nrow => $row) {
-            
-            $starting_new_group = false;
-            
-            if ($nrow == 0) {
-              $starting_new_group = true;
-              
-            } else if ($format == 'html' &&
-                (isset($row['__group__']) && $group !== $row['__group__'])) {
-              $starting_new_group = true;
-            }
-            
-            if ($starting_new_group) {
-              /* starting a new group */
-                if ($nrow) {
-                  /* close the old one */
-                    if ($format == 'html') {
-                         $out .= "</tbody></table>\n";
-                    }
-                }
-                if ($format == 'html' && isset($row['__group__'])) {
-                    $out .= "<h2 class='reportgroup'>" .
-                        htmlentities($row['__group__'], ENT_COMPAT, 'utf-8') .
-                        "</h2>\n";
-                    $group = $row['__group__'];
-                }
-            
-                if ($format == 'html') {
-                    $out .= "<table class='report'><thead><tr>";
-                }
-            
-                foreach ($captions as $name => $caption) {
-            
-                    /* figure out sort info for javascript bits */
-                    $sort = null;
-                    switch (strtolower($caption)) {
-                        case 'priority':
-                        case 'ticket':
-                        case 'severity':
-                            $sort = strtolower($caption);
-                            break;
-                        
-                        case 'created':
-                        case 'modified':
-                        case 'date':
-                        case 'due':
-                            $sort = 'mtrackdate';
-                            break;
-                        
-                        case 'remaining':
-                            $sort = 'digit';
-                            break;
-                        
-                        case 'updated':
-                        case 'time':
-                        case 'content':
-                        case 'summary':
-                        default:
-                            break;
-                    }
-            
-                    $caption = ucfirst($caption);
-                    if ($name[0] == '_' && substr($name,-1) == '_') {
-                        if ($format == 'html') {
-                            $out .= "</tr><tr><th colspan='$max_width'>$caption</th></tr><tr>";
-                        } else if ($format == 'tab') {
-                          $out .= "$caption\t";
-                        }
-                    } elseif ($name[0] == '_') {
-                        continue;
-                    } else {
-                        if ($format == 'html') {
-                            $out .= "<th";
-                            if ($sort !== null) {
-                                $out .= " class=\"{sorter: '$sort'}\"";
-                            }
-                            $out .= ">$caption</th>";
-                            if (substr($name, -1) == '_') {
-                                $out .= "</tr><tr>";
-                            }
-                        } else if ($format == 'tab') {
-                            $out .= "$caption\t";
-                        }
-                    }
-                }
-                if ($format == 'html') {
-                    $out .= "</tr></thead><tbody>\n";
-                } else if ($format == 'tab') {
-                    $out .= "\n";
-                }
-            }
-
-            // and now the column data itself 
-            if (isset($row['__style__'])) {
-              $style = " style=\"$row[__style__]\"";
-            } else {
-              $style = "";
-            }
-            $class = $nrow % 2 ? "even" : "odd";
-            if (isset($row['__color__'])) {
-              $class .= " color$row[__color__]";
-            }
-            if (isset($row['__status__'])) {
-              $class .= " status$row[__status__]";
-            }
-      
-            if ($format == 'html') {
-              $begin_row = "<tr class=\"$class\"$style>";
-              $out .= $begin_row;
-            }
-          //$href = null;
-    
-          /* determine if we should link to something for this row */
-          
-          //if (isset($row['ticket'])) {
-              
-            //    $href = $ABSWEB . "/Ticket.php/$row[ticket]";
-          //}
-        
-    
-          foreach ($captions as $name => $caption) {
-            $v = $row[$name];
-    
-            /* apply special formatting rules */
-            if ($format == 'html') {
-              switch (strtolower($caption)) {
-                case 'created':
-                case 'modified':
-                case 'date':
-                case 'due':
-                case 'updated':
-                case 'time':
-                  if ($v !== null) {
-                    $v = $link->date($v);
-                  }
-                  break;
-                case 'content':
-                  $v = MTrack_Wiki::format_to_html($v);
-                  break;
-                case 'owner':
-                  $v = $link->username($v, array('no_image' => true));
-                  break;
-                case 'docid':
-                case 'ticket':
-               // print_r($row);
-                  $v = $link->ticket($row['ticket']); // what about doc id?
-                  break;
-                case 'summary':
-                
-                  $v = isset($row['ticket']) ?
-                    $link->ticket($row['ticket'], array('display' => $v)) : 
-                    $v=  htmlspecialchars($v);
-                  break;
-                case 'milestone':
-                  $oldv = $v;
-                  $v = '';
-                  foreach (preg_split("/\s*,\s*/", $oldv) as $m) {
-                    if (!strlen($m)) continue;
-                    $v .= $link->milestone($m);
-                    /*
-                    $v .= "<span class='milestone'>" .
-                          "<a href=\"{$ABSWEB}milestone.php/" .
-                          urlencode($m) . "\">" .
-                          htmlentities($m, ENT_QUOTES, 'utf-8') .
-                          "</a></span> ";
-                          */
-                  }
-                  break;
-                case 'keyword':
-                  $oldv = $v;
-                  $v = '';
-                  foreach (preg_split("/\s*,\s*/", $oldv) as $m) {
-                    if (!strlen($m)) continue;
-                    $v .= $link->keyword($m) . ' ';
-                  }
-                  break;
-                default:
-                  $v = htmlentities($v, ENT_QUOTES, 'utf-8');
-              }
-            } else if ($format == 'tab') {
-              $v = trim(preg_replace("/[\t\n\r]+/sm", " ", $v));
-            }
-    
-            if ($name[0] == '_' && substr($name, -1) == '_') {
-              if ($format == 'html') {
-                $out .= "</tr>$begin_row<td class='$caption' colspan='$max_width'>$v</td></tr>$begin_row";
-              } else if ($format == 'tab') {
-                $out .= "$v\t";
-              }
-            } elseif ($name[0] == '_') {
-              if ($format == 'tab') {
-                $out .= "$v\t";
-              } else {
-                continue;
-              }
-            } else {
-              if ($format == 'html') {
-                $out .= "<td class='$caption'>$v</td>";
-                if (substr($name, -1) == '_') {
-                  $out .= "</tr>$begin_row";
-                }
-              } else if ($format == 'tab') {
-                $out .= "$v\t";
-              }
-            }
-          }
-          if ($format == 'html') {
-            $out .= "</tr>\n";
-          } else if ($format == 'tab') {
-            $out .= "\n";
-          }
-        }
-        if ($format == 'html') {
-          $out .= "</tbody></table>";
-        } else if ($format == 'tab') {
-          $out = str_replace("\t\n", "\n", $out);
-        }
-    
-        return $out;
-    }
-  
-
-    
-    
-}