+// Constants for wrReportTableRender2
+define(WRREPORT_COMPACT_PAGE, 1); ///< includes the page name
+define(WRREPORT_COMPACT, 2); ///< shown on a single page
+define(WRREPORT_DETAIL, 3); ///< more columns
+
+/// \brief Renders a table header ("private" sub-function of wrReportTableRender2)
+///
+/// \param $format row format like WRREPORT_COMPACT
+/// \param $showActions boolean to indicate whether an actions column should be created
+/// \return UTF-8 encoded titles of HTML table
+function wrReportTableTitleRender2($format, $showActions) {
+ $out = '<tr>';
+ if ($format == WRREPORT_DETAIL) $out .= '<th>ID</th>';
+ if ($format != WRREPORT_COMPACT) $out .= '<th>Bahn</th>';
+ $out .= '<th>Datum</th>';
+ if ($format == WRREPORT_DETAIL) $out .= '<th>Datum Eintrag</th>';
+ if ($format == WRREPORT_DETAIL) $out .= '<th>Datum Ungültig</th>';
+ $out .= '<th>Zustand</th>';
+ $out .= '<th>Beschreibung</th>';
+ $out .= '<th>Autor</th>';
+ if ($showActions) $out .= '<th>Aktion</th>';
+ return utf8_encode($out . "</tr>\n");
+}
+
+
+/// \brief Renders a table row ("private" sub-function of wrReportTableRender2)
+///
+/// \param $row associative array of table columns like one row in the wrreport table
+/// \param $format row format like WRREPORT_COMPACT
+/// \param $showActions boolean to indicate whether an actions column should be created
+/// \return UTF-8 encoded titles of HTML table
+function wrReportTableRowRender2($row, $format, $showActions) {
+ extract($row);
+
+ $out = '<tr>';
+ // $id
+ if ($format == WRREPORT_DETAIL) $out .= '<td>' . $id . '</td>';
+ // $page_title
+ if ($format != WRREPORT_COMPACT) $out .= '<td>' . wrReportSandboxParse('[[' . $page_title . ']]') . '</td>';
+ // $date_report
+ $dayOfWeek = array('Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So');
+ $date_report = strtotime($date_report);
+ $date_report = $dayOfWeek[strftime('%u', $date_report)-1] . strftime(', %d.%m.', $date_report);
+ $out .= '<td>' . $date_report . '</td>';
+ // $date_entry
+ if ($format == WRREPORT_DETAIL) $out .= '<td>' . date('Y-m-d, H:i', strtotime($date_entry)) . '</td>';
+ // $date_invalid
+ if ($format == WRREPORT_DETAIL) $out .= '<td>' . date('Y-m-d, H:i', strtotime($date_invalid)) . '</td>';
+ // $condition
+ global $wrConditions;
+ $condition_text = '---';
+ if (isset($wrConditions[$condition])) $condition_text = $wrConditions[$condition];
+ $out .= '<td>';
+ if ($delete_date) $out .= utf8_encode('<em>Gelöscht</em>');
+ else $out .= htmlspecialchars($condition_text);
+ $out .= '</td>';
+ // $description
+ $out .= '<td class="wrreportdescription">';
+ if ($delete_date) $out .= utf8_encode('<em>Gelöscht</em>');
+ else $out .= wrReportSandboxParse($description);
+ $out .= '</td>';
+ // $author_name
+ $out .= '<td>';
+ if ($delete_date) $out .= utf8_encode('<em>Gelöscht</em>');
+ else $out .= htmlspecialchars($author_name);
+ $out .= '</td>';
+ // actions
+ if ($showActions) $out .= '<td>' . utf8_encode('(Löschen)') . '</td>';
+ return $out . "</tr>\n";
+}
+
+
+/// \brief Renders the report table. Call wrReportGetReports for the $rows parameter.
+///
+/// \param $rows array of associative row arrays
+/// \param $format row format like WRREPORT_TABLE_SHORT
+function wrReportTableRender2($rows, $format, $showActions) {
+ $out = "<table class=\"wrreporttable\">\n" . wrReportTableTitleRender2($format, $showActions);
+ foreach ($rows as $key => $row) $out .= wrReportTableRowRender2($row, $format, $showActions);
+ return $out . "</table>\n";
+}
+
+
+/// Returns an array with column names
+function wrReportGetColumnNames() {
+ return array('id', 'page_id', 'page_title', 'date_report', 'date_entry', 'date_invalid', 'condition', 'description', 'author_name', 'author_username', 'delete_date', 'delete_person_name', 'delete_person_ip', 'delete_person_userid', 'delete_person_username', 'delete_reason_public', 'delete_invisible');
+}
+
+
+/// \brief Returns reports as associative array.
+///
+/// Examples:
+/// $conditions = array('page_title' => 'Birgitzer Alm', 'date_invalid > now()');
+/// $order = 'date_report desc, date_entry desc';
+function wrReportGetReports($conditions, $order) {
+ $dbr = wfGetDB(DB_SLAVE);
+ $res = $dbr->select('wrreport', wrReportGetColumnNames(), $conditions, $fname = 'Database::select', $options = array('ORDER BY' => 'date_report desc, date_entry desc'));
+ $result = array();
+ while ($row = $dbr->fetchRow($res)) $result[] = $row;
+ $dbr->freeResult($res);
+ return $result;
+}
+
+
+