Ejemplo n.º 1
0
    public function graph($opts = false)
    {
        $debug = false;
        if (is_array($opts)) {
            extract($opts);
        }
        if (!$view) {
            $view = "weekly";
        }
        if (!$this->tbl) {
            $this->tbl = $this->_loadTableInfo();
            // $this->tbl = self::$_tableInfo[$this->_table];
        }
        if (!$title) {
            $title = $this->_table;
        }
        if ($debug) {
            da($this->tbl);
        }
        if (!$this->_dateField) {
            // @todo, infer datefield from field info. JB  8/8/08 2:59 PM
            $errors[] = "We don't know the date field for {$this->_table}.";
        }
        if ($errors) {
            show_errors($errors);
        }
        $g = group_time($view, $this->_dateField, array("table" => $this->_table));
        $sql = $this->getTrendSql($opts);
        $trend = acqueryz($sql, $this->_db);
        $trend = $trend->fetchAll();
        $hidefields = array();
        $graphf = array($this->_dateField, 'count');
        $data = array();
        $i = 0;
        if (count($trend)) {
            ?>
            <div id="tableWrapper" style="display:none">
            <div>Showing <b><?php 
            echo $num;
            ?>
</b> records</div>
            <table class="list"><?php 
            foreach ($trend as $row) {
                $i++;
                $i % 2 ? $row_class = "odd" : ($row_class = "even");
                extract($row);
                if ($i == 1) {
                    // do header row
                    ?>
                      <tr class="reverse">
                        <td>Action</td>
                        <?php 
                    foreach ($row as $f => $v) {
                        if (!in_array($f, $hidefields)) {
                            ?>
                            <td><?php 
                            echo camelcap($f);
                            ?>
</td>
                       <?php 
                        }
                    }
                    ?>
                      </tr>
                <?php 
                }
                ?>
                <tr class="<?php 
                echo $row_class;
                ?>
">
                  <td> <a href="<?php 
                echo $this->_controller;
                ?>
?action=edit_<?php 
                echo $this->_table;
                ?>
&<?php 
                echo $this->_idField;
                ?>
=<?php 
                echo ${$this}->_idField;
                ?>
">Edit</a>
                  </td>
                  <?php 
                foreach ($row as $f => $v) {
                    if (!in_array($f, $hidefields)) {
                        if ($f == $graphf[0]) {
                            $v = date($g[dformat], strtotime($v));
                            $data[$i - 1][label] = $v;
                        }
                        if ($f == $graphf[1]) {
                            $data[$i - 1][point] = $v;
                        }
                        ?>
                            <td> <?php 
                        echo $v;
                        ?>
 </td>
                       <?php 
                    }
                    ?>
                  <?php 
                }
                ?>
                </tr>
                <?php 
            }
            ?>
</table>
            </div>
            <?php 
            if (count($data)) {
                $g = new ACGraph($data, $title . " " . $view);
                $g->render();
            }
        } else {
            ?>
<p>No <?php 
            echo $title;
            ?>
 records found</p><?php 
        }
    }
Ejemplo n.º 2
0
    function ajaxFieldEnum($name, $opts = false)
    {
        // http://wiki.script.aculo.us/scriptaculous/show/InPlaceSelect
        global $zdb_schema;
        if (is_array($name)) {
            $info =& $name;
        } else {
            $info =& $this->tbl[$name];
        }
        // Backwards compaitibility
        if ($this->indexField && !$this->_idField) {
            $this->_idField = $this->indexField;
        }
        switch ($info[type]) {
            case "enum":
                $select = $this->formEnum($info, array("get_array" => true));
                $keys = implode(",", array_keys($select));
                $labels = "'" . implode("','", $select) . "'";
                $keys = $labels;
                break;
            default:
                // Non-enums assume to be related key tables.
                // make $select array.
                if (class_exists($info['rel']['foreign_table'])) {
                    $foreign = new $info['rel']['foreign_table']($this->{$info}['field']);
                    $titleField = $foreign->_titleField;
                    $current = $foreign->{$titleField};
                } else {
                    // see if phpmyadmin knows the title fields.
                    $sql = "SELECT display_field FROM pma_table_info\n                        WHERE db_name = '{$rel['foreign_db']}' AND table_name = '{$info['rel']['foreign_table']}' ";
                    $foreign->_titleField = $zdb_schema->fetchOne($sql);
                    // @todo - Make this smarter.  JB  12/4/08 4:21 PM
                    $foreign->_idField = $info['rel']['foreign_table'] . "_id";
                }
                if (!$foreign->_titleField) {
                    $foreign->_titleField = $foreign->_idField;
                }
                $sql = "SELECT {$foreign->_idField} AS id, {$foreign->_titleField} AS title FROM {$info['rel']['foreign_table']} ORDER BY {$foreign->_titleField} ";
                $res = acqueryz($sql, $info['rel']['foreign_db']);
                $options = $res->fetchAll();
                foreach ($options as $op) {
                    $select[$op['id']] = $op['title'];
                }
                $keys = implode(",", array_keys($select));
                $labels = "'" . implode("','", $select) . "'";
        }
        if (!$current) {
            if ($current = $this->{$info}['field']) {
            } else {
                $current = "none";
            }
        }
        ?>
        <span id="<?php 
        echo $info[field];
        ?>
_<?php 
        echo $this->id;
        ?>
"><?php 
        echo $current;
        ?>
</span>
        <script type="text/javascript">

         new Ajax.InPlaceSelect('<?php 
        echo $info[field];
        ?>
_<?php 
        echo $this->id;
        ?>
', '<?php 
        echo $this->_controller;
        ?>
?&field=<?php 
        echo $info[field];
        ?>
&action=ajaxField&table=<?php 
        echo $this->_table;
        ?>
&<?php 
        echo $this->_idField;
        ?>
=<?php 
        echo $this->id;
        ?>
', ['0','0',<?php 
        echo $keys;
        ?>
], ['change','none',<?php 
        echo $labels;
        ?>
],
          { paramName: 'value', parameters: "field=<?php 
        echo $info[field];
        ?>
" } );
        </script>
        <?php 
    }