Example #1
0
 function _generateTable($caption)
 {
     if (count($this->_sortby) > 0) {
         $this->_sortPages();
     }
     $rows = array();
     $i = 0;
     foreach ($this->_pages as $pagenum => $page) {
         $rows[] = $this->_renderPageRow($page, $i++);
     }
     $table = HTML::table(array('cellpadding' => 0, 'cellspacing' => 1, 'border' => 0, 'class' => 'pagelist'));
     if ($caption) {
         $table->pushContent(HTML::caption(array('align' => 'top'), $caption));
     }
     //Warning: This is quite fragile. It depends solely on a private variable
     //         in ->_addColumn()
     if (!empty($this->_columns_seen['checkbox'])) {
         $table->pushContent($this->_jsFlipAll());
     }
     $do_paging = (isset($this->_options['paging']) and !empty($this->_options['limit']) and $this->getTotal() and $this->_options['paging'] != 'none');
     $row = HTML::tr();
     $table_summary = array();
     $i = 1;
     // start with 1!
     foreach ($this->_columns as $col) {
         $heading = $col->button_heading($this, $i);
         if ($do_paging and isset($col->_field) and $col->_field == 'pagename' and $maxlen = $this->maxLen()) {
             $heading->setAttr('width', $maxlen * 7);
         }
         $row->pushContent($heading);
         if (is_string($col->getHeading())) {
             $table_summary[] = $col->getHeading();
         }
         $i++;
     }
     // Table summary for non-visual browsers.
     $table->setAttr('summary', sprintf(_("Columns: %s."), join(", ", $table_summary)));
     $table->pushContent(HTML::colgroup(array('span' => count($this->_columns))));
     if ($do_paging) {
         $tokens = $this->pagingTokens($this->getTotal(), count($this->_columns), $this->_options['limit']);
         if ($tokens === false) {
             $table->pushContent(HTML::thead($row), HTML::tbody(false, $rows));
             return $table;
         }
         $paging = Template("pagelink", $tokens);
         if ($this->_options['paging'] != 'bottom') {
             $table->pushContent(HTML::thead($paging));
         }
         $table->pushContent(HTML::tbody(false, HTML($row, $rows)));
         if ($this->_options['paging'] != 'top') {
             $table->pushContent(HTML::tfoot($paging));
         }
         return $table;
     } else {
         $table->pushContent(HTML::thead($row), HTML::tbody(false, $rows));
         return $table;
     }
 }
Example #2
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     global $DBParams;
     //$request->setArg('nocache','1');
     extract($this->getArgs($argstr, $request));
     if (!$alias) {
         return $this->error(_("No DSN alias for SqlResult.ini specified"));
     }
     $sql = $this->_sql;
     // apply custom filters
     if ($where and strstr($sql, "%%where%%")) {
         $sql = str_replace("%%where%%", $where, $sql);
     }
     // TODO: use a SQL construction library?
     if ($limit) {
         $pagelist = new PageList();
         $limit = $pagelist->limit($limit);
         if (strstr($sql, "%%limit%%")) {
             $sql = str_replace("%%limit%%", $limit, $sql);
         } else {
             if (strstr($sql, "LIMIT")) {
                 $sql = preg_replace("/LIMIT\\s+[\\d,]+\\s+/m", "LIMIT " . $limit . " ", $sql);
             }
         }
     }
     if (strstr($sql, "%%sortby%%")) {
         if (!$sortby) {
             $sql = preg_replace("/ORDER BY .*%%sortby%%\\s/m", "", $sql);
         } else {
             $sql = str_replace("%%sortby%%", $sortby, $sql);
         }
     } elseif (PageList::sortby($sortby, 'db')) {
         // add sorting: support paging sortby links
         if (preg_match("/\\sORDER\\s/", $sql)) {
             $sql = preg_replace("/ORDER BY\\s\\S+\\s/m", "ORDER BY " . PageList::sortby($sortby, 'db'), $sql);
         } else {
             $sql .= " ORDER BY " . PageList::sortby($sortby, 'db');
         }
     }
     $inidsn = $this->getDsn($alias);
     if (!$inidsn) {
         return $this->error(sprintf(_("No DSN for alias %s in SqlResult.ini found"), $alias));
     }
     // adodb or pear? adodb as default, since we distribute per default it.
     // for pear there may be overrides.
     // TODO: native PDO support (for now we use ADODB)
     if ($DBParams['dbtype'] == 'SQL') {
         $dbh = DB::connect($inidsn);
         $all = $dbh->getAll($sql);
         if (DB::isError($all)) {
             return $this->error($all->getMessage() . ' ' . $all->userinfo);
         }
     } else {
         // unless PearDB use the included ADODB, regardless if dba, file or PDO, ...
         if ($DBParams['dbtype'] != 'ADODB') {
             // require_once('lib/WikiDB/adodb/adodb-errorhandler.inc.php');
             require_once 'lib/WikiDB/adodb/adodb.inc.php';
         }
         $parsed = parseDSN($inidsn);
         $dbh =& ADONewConnection($parsed['phptype']);
         $conn = $dbh->Connect($parsed['hostspec'], $parsed['username'], $parsed['password'], $parsed['database']);
         if (!$conn) {
             return $this->error($dbh->errorMsg());
         }
         $GLOBALS['ADODB_FETCH_MODE'] = ADODB_FETCH_ASSOC;
         $dbh->SetFetchMode(ADODB_FETCH_ASSOC);
         $all = $dbh->getAll($sql);
         $GLOBALS['ADODB_FETCH_MODE'] = ADODB_FETCH_NUM;
         $dbh->SetFetchMode(ADODB_FETCH_NUM);
         if (!$all) {
             return $this->error($dbh->errorMsg());
         }
     }
     $args = array();
     if ($limit) {
         // fill paging vars (see PageList)
         $args = $pagelist->pagingTokens(count($all), count($all[0]), $limit);
         if (!$args) {
             $args = array();
         }
     }
     if ($template) {
         $args = array_merge(array('SqlResult' => $all, 'ordered' => $ordered, 'where' => $where, 'sortby' => $sortby, 'limit' => $limit), $args);
         // paging params override given params
         return Template($template, $args);
     } else {
         if ($ordered) {
             $html = HTML::ol(array('class' => 'sqlresult'));
             if ($all) {
                 foreach ($all as $row) {
                     $html->pushContent(HTML::li(array('class' => $i++ % 2 ? 'evenrow' : 'oddrow'), $row[0]));
                 }
             }
         } else {
             $html = HTML::table(array('class' => 'sqlresult'));
             $i = 0;
             if ($all) {
                 foreach ($all as $row) {
                     $tr = HTML::tr(array('class' => $i++ % 2 ? 'evenrow' : 'oddrow'));
                     if ($row) {
                         foreach ($row as $col) {
                             $tr->pushContent(HTML::td($col));
                         }
                     }
                     $html->pushContent($tr);
                 }
             }
         }
     }
     // do paging via pagelink template
     if (!empty($args['NUMPAGES'])) {
         $paging = Template("pagelink", $args);
         $html = $table->pushContent(HTML::thead($paging), HTML::tbody($html), HTML::tfoot($paging));
     }
     if (0 and DEBUG) {
         // test deferred error/warning/notice collapsing
         trigger_error("test notice", E_USER_NOTICE);
         trigger_error("test warning", E_USER_WARNING);
     }
     return $html;
 }
Example #3
0
 function _generateTable($caption)
 {
     if (count($this->_sortby) > 0) {
         $this->_sortPages();
     }
     // wikiadminutils hack. that's a way to pagelist non-pages
     $rows = isset($this->_rows) ? $this->_rows : array();
     $i = 0;
     $count = $this->getTotal();
     $do_paging = (isset($this->_options['paging']) and !empty($this->_options['limit']) and $count and $this->_options['paging'] != 'none');
     if ($do_paging) {
         $tokens = $this->pagingTokens($count, count($this->_columns), $this->_options['limit']);
         if ($tokens and !empty($this->_options['slice'])) {
             $this->_pages = array_slice($this->_pages, $tokens['OFFSET'], $tokens['SIZE']);
         }
     }
     foreach ($this->_pages as $pagenum => $page) {
         $one_row = $this->_renderPageRow($page, $i++);
         $rows[] = $one_row;
     }
     $table = HTML::table(array('cellpadding' => 0, 'cellspacing' => 1, 'border' => 0, 'width' => '100%', 'class' => 'pagelist'));
     if ($caption) {
         $table->pushContent(HTML::caption(array('align' => 'top'), $caption));
     }
     $row = HTML::tr();
     $table_summary = array();
     $i = 1;
     // start with 1!
     foreach ($this->_columns as $col) {
         $heading = $col->button_heading($this, $i);
         if ($do_paging and isset($col->_field) and $col->_field == 'pagename' and $maxlen = $this->maxLen()) {
         }
         $row->pushContent($heading);
         if (is_string($col->getHeading())) {
             $table_summary[] = $col->getHeading();
         }
         $i++;
     }
     // Table summary for non-visual browsers.
     $table->setAttr('summary', sprintf(_("Columns: %s."), join(", ", $table_summary)));
     $table->pushContent(HTML::colgroup(array('span' => count($this->_columns))));
     if ($do_paging) {
         if ($tokens === false) {
             $table->pushContent(HTML::thead($row), HTML::tbody(false, $rows));
             return $table;
         }
         $paging = Template("pagelink", $tokens);
         if ($this->_options['paging'] != 'bottom') {
             $table->pushContent(HTML::thead($paging));
         }
         if ($this->_options['paging'] != 'top') {
             $table->pushContent(HTML::tfoot($paging));
         }
         $table->pushContent(HTML::tbody(false, HTML($row, $rows)));
         return $table;
     } else {
         $table->pushContent(HTML::thead($row), HTML::tbody(false, $rows));
         return $table;
     }
 }