コード例 #1
0
ファイル: forms.class.php プロジェクト: OptimalInternet/uCore
 public function ShowData()
 {
     //check pk and ptable are set up
     if (is_empty($this->GetTabledef())) {
         ErrorLog('Primary table not set up for ' . get_class($this));
         return;
     }
     echo '<h1>' . $this->GetTitle() . '</h1>';
     echo '{list.' . get_class($this) . '}';
     $row = null;
     $num_rows = 0;
     if (!isset($_GET['_n_' . $this->GetModuleId()])) {
         $this->GetLimit($limit, $page);
         $dataset = $this->GetDataset();
         $num_rows = $dataset->CountRecords();
         $row = $dataset->GetPage($page, $limit)->fetch();
     }
     $pagination = '';
     $this->GetLimit($limit);
     if ($limit) {
         $pages = max(ceil($num_rows / $limit), 1);
         ob_start();
         utopia::OutputPagination($pages, '_p_' . $this->GetModuleId());
         $pagination = ob_get_clean();
     }
     $records = $num_rows == 0 ? "There are no records to display." : 'Total Rows: ' . $num_rows;
     $pager = '<div class="right">' . $pagination . '</div>';
     uEvents::TriggerEvent('OnShowDataDetail', $this);
     if ($this->flag_is_set(ALLOW_DELETE) && $row) {
         $fltr =& $this->FindFilter($this->GetPrimaryKey(), ctEQ, itNONE);
         $delbtn = $this->GetDeleteButton($this->GetFilterValue($fltr['uid']), 'Delete Record');
         utopia::AppendVar('footer_left', $delbtn);
     }
     //		if (!$this->IsNewRecord()) { // records exist, lets get the first.
     // pagination?
     //			if (mysql_num_rows($result) > 1) {
     // multiple records exist in this set, sort out pagination
     //			}
     //		}
     $order = $this->GetSortOrder();
     $extraCount = 1;
     $secCount = count($this->layoutSections);
     foreach ($this->layoutSections as $sectionID => $sectionInfo) {
         $out = '';
         if ($secCount > 1) {
             $sectionName = $sectionInfo['title'];
             if ($sectionName === '') {
                 if ($sectionID === 0) {
                     $SN = 'General';
                 } else {
                     $SN = "Extra ({$extraCount})";
                     $extraCount++;
                 }
             } else {
                 $SN = ucwords($sectionName);
             }
             $out .= '<h2>' . $SN . '</h2>';
         }
         if (!$this->isAjax) {
             $out .= '<form class="uf" action="" onsubmit="this.action = window.location" method="post">';
         }
         $out .= "<div class=\"table-wrapper\"><table class=\"module-content layoutDetailSection\">";
         $fields = $this->GetFields(true, $sectionID);
         $hasFieldHeaders = false;
         foreach ($fields as $fieldName => $fieldData) {
             $hasFieldHeaders = $hasFieldHeaders || !empty($fieldData['visiblename']);
         }
         $fieldCount = count($fields);
         foreach ($fields as $fieldName => $fieldData) {
             $targetUrl = $this->GetTargetUrl($fieldName, $row);
             $out .= "<tr>";
             if ($hasFieldHeaders) {
                 $out .= "<td class=\"fld\">" . $fieldData['visiblename'] . "</td>";
             }
             $out .= '<td>' . $this->GetCell($fieldName, $row, $targetUrl) . '</td>';
             $out .= "</tr>";
         }
         $out .= "</table></div>";
         if (!$this->isAjax) {
             $out .= '</form>';
         }
         echo $out;
     }
     if ($num_rows > 1) {
         echo '<div class="oh"><b>' . $records . '</b>' . $pager . '</div>';
     }
 }
コード例 #2
0
ファイル: custom.php プロジェクト: OptimalInternet/uCore
 static function DrawData($rec)
 {
     if (!$rec['module'] || !class_exists($rec['module'])) {
         return $rec['no_rows'];
     }
     if (!($instance = utopia::GetInstance($rec['module'], false))) {
         return 'Could not load Data Source';
     }
     $instance->_SetupParents();
     $instance->_SetupFields();
     // clear filters
     $rec['clear_filter'] = (array) utopia::jsonTryDecode($rec['clear_filter']);
     foreach ($rec['clear_filter'] as $uid) {
         $instance->RemoveFilter($uid);
     }
     // add filters
     utopia::MergeVars($rec['filter']);
     if ($rec['filter']) {
         $instance->AddFilter($rec['filter'], ctCUSTOM);
     }
     // add Order
     utopia::MergeVars($rec['order']);
     if ($rec['order']) {
         $instance->ordering = NULL;
         $instance->AddOrderBy($rec['order']);
     }
     $dataset = $instance->GetDataset();
     // init limit
     utopia::MergeVars($rec['limit']);
     $rec['limit'] = trim($rec['limit']);
     $instance->GetLimit($limit, $page);
     // page is governed by a different query arg for widgets, below
     $page = stripos($rec['content'], '{pagination}') !== FALSE && isset($_GET['_p_' . $rec['block_id']]) ? $_GET['_p_' . $rec['block_id']] : 0;
     $offset = $limit * $page;
     if ($rec['limit']) {
         if (strpos($rec['limit'], ',') === FALSE) {
             $limit = $rec['limit'];
             $offset = $limit * $page;
         } else {
             list($offset, $limit) = explode(',', $rec['limit']);
             $offset = trim($offset);
             $limit = trim($limit);
         }
     }
     if (!($total = $dataset->CountRecords())) {
         return $rec['no_rows'];
     }
     // get rows
     if ($offset > $total) {
         return $rec['no_rows'];
     }
     // get content
     $content = $append = $prepend = '';
     $html = str_get_html($rec['content'], true, true, DEFAULT_TARGET_CHARSET, false);
     $ele = '';
     if ($html) {
         $ele = $html->find('._ri', 0);
         if ($ele) {
             $ele = $ele->innertext;
         } else {
             $ele = $html->find('._r', 0);
             if ($ele) {
                 $ele = $ele->outertext;
             } else {
                 $ele = '';
             }
         }
     } else {
         $html = $rec['content'];
     }
     $repeatable = $html;
     if ($ele) {
         // found a repeatable element
         // split content at this element. prepare for apend and prepend.
         list($append, $prepend) = explode($ele, $repeatable);
         $repeatable = $ele;
     }
     $dataset->GetOffset($offset, $limit);
     while ($row = $dataset->fetch()) {
         $c = $repeatable;
         $instance->MergeFields($c, $row);
         $content .= $c;
     }
     $ret = $append . $content . $prepend;
     // process full doc
     $ret = str_ireplace('{total}', $total, $ret);
     if ($page !== NULL && is_numeric($limit)) {
         $pages = max(ceil($total / $limit), 1);
         ob_start();
         $cPage = utopia::OutputPagination($pages, '_p_' . $rec['block_id']);
         $ret = str_ireplace('{pagination}', ob_get_clean(), $ret);
         $ret = str_ireplace('{pages}', $pages, $ret);
         $ret = str_ireplace('{current_page}', $cPage, $ret);
     }
     while (utopia::MergeVars($ret)) {
     }
     return $ret;
 }