3 * @file class_erErrorReportView.inc
4 * Class for viewing error reports
5 * @author Roland Hieber (roland.hieber@wilhelm-gym.net)
8 * Copyright © 2007 Roland Hieber
10 * Permission is hereby granted, free of charge, to any person obtaining
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29 require_once("mod_error-reporter/class_erConfig.inc");
30 require_once("mod_error-reporter/class_erErrorReport.inc");
31 require_once("mod_error-reporter/class_erErrorReportManager.inc");
32 require_once("share.inc");
33 require_once("ctrl.inc");
34 require_once("format.inc");
37 class erErrorReportView {
38 /** (erConfig) pointer to the configuration class */
40 /** (erErrorReportManager) pointer to a erErrorReportManager instance */
41 protected $objManager;
43 * (string) URL to the page which allows editing of an error report.
44 * The specified page must handle the <tt>uid</tt> GET parameter, which
45 * contains the unique ID of the error report to be edited.
47 protected $strEditURL;
49 * (string) URL to the page which allows deletion of an error report.
50 * The specified page must handle the <tt>uid</tt> GET parameter, which
51 * contains the unique ID of the error report to be deleted.
53 protected $strDeleteURL;
57 * @param $objcfg (erConfig) Pointer to an instance of the erConfig class for
58 * retrieving the configuration data
59 * @param $objemm (erErrorReportManager) Pointer to a instance of the
60 * erErrorReportManager class for retrieving the document data
61 * @return erErrorReportView
63 public function __construct(erConfig &$objcfg, erErrorReportManager &$objemm) {
64 $this->objcfg = $objcfg;
65 $this->objManager = $objemm;
66 html_header("<style type='text/css'>
67 table.errors-view-table { width:100%; border:2px solid #5276AB; }
68 td.errors-view-description { width:12em; }
69 td.errors-view-comment-row { font-style:italic; }
70 td.errors-view-action-edit, td.errors-view-action-delete {
73 vertical-align:middle;
79 * Print a single error report.
80 * Call this function to print a table or a compound of table rows with the
81 * information of the specified error report. The function determines if the
82 * current user is the owner of the specified report or if he has admin
83 * rights and in this case displays buttons for deletion and editing the
85 * @param $objem (erErrorReport) Error report to print
86 * @param $bSingle (bool) Determines if you call this function once
87 * (<tt>true</tt>) or several times to get a compound table of reports
89 * @param $bAdminButtons (bool) Explicitly determines whether to show the
90 * edit and delete buttons. This parameter overrides the check for owner and
93 public function printErrorReport(erErrorReport $objem, $bSingle = false, $bAdminButtons = true) {
94 global $colbox_state, $invtbl;
97 echo "<{$GLOBALS["invtbl"]} class='errors-view-table'>";
99 $nColor = bgcol_rgb();
100 $sColor = sprintf("rgb(%d,%d,%d)", ($nColor >> 16) % 256,
101 ($nColor >> 8) % 256, $nColor % 256);
102 echo "<tr style='background-color:$sColor'>";
103 if($this->objcfg->userIsAdmin() or
104 $this->objManager->userIsOwner($objem->getUid())) {
105 // user is admin or owner
106 echo "<td style='padding:3px'><{$GLOBALS["invtbl"]} width='100%'>\n";
107 $sRow = "<tr><td class='errors-view-description'>%s</td><td>%s</td></tr>";
108 echo sprintf("$sRow\n", _c("error-reporter:Reported by:"),
109 erMailToUserLink($objem->getOwner()));
110 echo sprintf("$sRow\n", _c("error-reporter:Date:"),
111 SmartDate($objem->getDate()));
112 echo sprintf("$sRow\n", _c("error-reporter:Affected machine:"),
113 q($objem->getMachine()));
114 echo sprintf("$sRow\n", _c("error-reporter:Text:"), q($objem->getText()));
115 echo sprintf("$sRow\n", _c("error-reporter:Hidden:"), $objem->isHidden() ?
116 _c("error-reporter:yes") : _c("error-reporter:no"));
117 if(trim($objem->getComment()) != "") {
118 echo sprintf("<tr><td class='errors-view-description ".
119 "errors-view-comment-row'>%s</td><td ".
120 "class='errors-view-comment-row'>%s</td></tr>\n",
121 sprintf(_c("error-reporter:Comment by %s:"),
122 erMailToUserLink($objem->getCommentOwner())),
123 q($objem->getComment()));
125 echo "</table></td>\n";
128 echo sprintf("<td class='errors-view-action-edit'>%s</td>".
129 "<td class='errors-view-action-delete'>%s</td>",
130 $this->getEditLink($objem->getUid()),
131 $this->getDeleteLink($objem->getUid()));
135 // user can only read the report
136 echo "<td><{$GLOBALS["invtbl"]} width='100%'>\n";
137 $sRow = "<tr><td class='errors-view-description'>%s</td><td>%s</td></tr>";
138 echo sprintf("$sRow\n", _c("error-reporter:Affected machine:"),
139 $objem->getMachine());
140 echo sprintf("$sRow\n", _c("error-reporter:Text:"), $objem->getText());
141 if(trim($objem->getComment()) != "") {
142 echo sprintf("<tr><td class='errors-view-description ".
143 "errors-view-comment-row'>%s</td><td ".
144 "class='errors-view-comment-row'>%s</td></tr>\n",
145 sprintf(_c("error-reporter:Comment by %s:"),
146 erMailToUserLink($objem->getCommentOwner())),
147 q($objem->getComment()));
149 echo "</td></table><td /><td /></tr>\n";
158 * Print a table of error reports.
159 * Prints a table with several error reports by calling printErrorReport()
161 * @param $arobjem (array of errorReport objects) The reports to print
163 public public function printErrorReports($arobjem) {
164 echo "<{$GLOBALS["invtbl"]} class='errors-view-table'>";
166 if(is_array($arobjem)) {
167 foreach($arobjem as $em) {
168 $this->printErrorReport($em);
169 if(_bgcol() == "bl") {
181 * Set the link to the edit page.
182 * The specified page must handle the <tt>uid</tt> GET parameter, which
183 * contains the unique ID of the error report to be edited.
186 * @param $strUrl (string)
188 public function setEditURL($strUrl) { $this->strEditURL = $strUrl; }
191 * Get the link to the edit page.
192 * @param $nUid (int) Unique ID of the error report to be edited
197 public function getEditURL($nUid) {
198 if(preg_match("/\?/", $this->strEditURL) == 0) {
199 $strParam = "?uid=".intval($nUid);
201 $strParam = "&uid=".intval($nUid);
203 return q($this->strEditURL.$strParam);
207 * Create a link to the edit page
208 * @param $nUid (int) Unique ID of the error report to be edited
213 public function getEditLink($nUid) {
214 return sprintf("<a %s title='%s'>%s</a>", pop($this->getEditURL($nUid),
215 500, 500), _c("error-reporter:Edit this error report"), icon("write"));
219 * Set the link to the delete page.
220 * The specified page must handle the <tt>uid</tt> GET parameter, which
221 * contains the unique ID of the error report to be deleted.
222 * @see getDeleteURL()
223 * @see getDeleteLink()
224 * @param $strUrl (string)
226 public function setDeleteURL($strUrl) { $this->strDeleteURL = $strUrl; }
229 * Get the link to the delete page.
230 * @param $nUid (int) Unique ID of the error report to be deleted
231 * @see setDeleteURL()
232 * @see getDeleteLink()
235 public function getDeleteURL($nUid) {
236 if(preg_match("/\?/", $this->strDeleteURL) == 0) {
237 $strParam = "?uid=".intval($nUid);
239 $strParam = "&uid=".intval($nUid);
241 return q($this->strDeleteURL.$strParam);
245 * Create a link to the delete page
246 * @param $nUid (int) Unique ID of the error report to be deleted
247 * @see setDeleteURL()
248 * @see getDeleteURL()
251 public function getDeleteLink($nUid) {
252 return sprintf("<a href='%s' title='%s'>%s</a>", $this->getDeleteURL($nUid),
253 _c("error-reporter:Delete this error report"), icon("trash"));