fixed lintian complaints and cleaned up debian/rules
[iserv-mod-error-reporter.git] / inc / class_erErrorReportView.inc
1 <?php
2 /**
3 * @file class_erErrorReportView.inc
4 * Class for viewing error reports
5 * @author Roland Hieber (roland.hieber@wilhelm-gym.net)
6 * @date 21.10.2007
7 *
8 * Copyright © 2007 Roland Hieber
9 *
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:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19 *
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
26 * THE SOFTWARE.
27 */
28
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");
35
36 /** @todo document */
37 class erErrorReportView {
38 /** (erConfig) pointer to the configuration class */
39 protected $objcfg;
40 /** (erErrorReportManager) pointer to a erErrorReportManager instance */
41 protected $objManager;
42 /**
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.
46 */
47 protected $strEditURL;
48 /**
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.
52 */
53 protected $strDeleteURL;
54
55 /**
56 * Constructor
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
62 */
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 {
71 width: 16px;
72 padding:0 1em;
73 vertical-align:middle;
74 }
75 </style>");
76 }
77
78 /**
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
84 * error report.
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
88 * (<tt>false</tt>).
89 * @param $bAdminButtons (bool) Explicitly determines whether to show the
90 * edit and delete buttons. This parameter overrides the check for owner and
91 * admin rights.
92 */
93 public function printErrorReport(erErrorReport $objem, $bSingle = false, $bAdminButtons = true) {
94 global $colbox_state, $invtbl;
95 if($bSingle) {
96 bgcol("cb");
97 echo "<{$GLOBALS["invtbl"]} class='errors-view-table'>";
98 }
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()));
124 }
125 echo "</table></td>\n";
126 // admin buttons
127 if($bAdminButtons) {
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()));
132 }
133 echo "</tr>\n";
134 } else {
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()));
148 }
149 echo "</td></table><td /><td /></tr>\n";
150 }
151 if($bSingle) {
152 echo "</table>\n";
153 _bgcol();
154 }
155 }
156
157 /**
158 * Print a table of error reports.
159 * Prints a table with several error reports by calling printErrorReport()
160 * for each report.
161 * @param $arobjem (array of errorReport objects) The reports to print
162 */
163 public public function printErrorReports($arobjem) {
164 echo "<{$GLOBALS["invtbl"]} class='errors-view-table'>";
165 bgcol("cb");
166 if(is_array($arobjem)) {
167 foreach($arobjem as $em) {
168 $this->printErrorReport($em);
169 if(_bgcol() == "bl") {
170 bgcol("cb");
171 } else {
172 bgcol("bl");
173 }
174 }
175 }
176 _bgcol();
177 echo "</table>\n";
178 }
179
180 /**
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.
184 * @see getEditURL()
185 * @see getEditLink()
186 * @param $strUrl (string)
187 */
188 public function setEditURL($strUrl) { $this->strEditURL = $strUrl; }
189
190 /**
191 * Get the link to the edit page.
192 * @param $nUid (int) Unique ID of the error report to be edited
193 * @see setEditURL()
194 * @see getEditLink()
195 * @return (string)
196 */
197 public function getEditURL($nUid) {
198 if(preg_match("/\?/", $this->strEditURL) == 0) {
199 $strParam = "?uid=".intval($nUid);
200 } else {
201 $strParam = "&uid=".intval($nUid);
202 }
203 return q($this->strEditURL.$strParam);
204 }
205
206 /**
207 * Create a link to the edit page
208 * @param $nUid (int) Unique ID of the error report to be edited
209 * @see setEditURL()
210 * @see getEditURL()
211 * @return string
212 */
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"));
216 }
217
218 /**
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)
225 */
226 public function setDeleteURL($strUrl) { $this->strDeleteURL = $strUrl; }
227
228 /**
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()
233 * @return (string)
234 */
235 public function getDeleteURL($nUid) {
236 if(preg_match("/\?/", $this->strDeleteURL) == 0) {
237 $strParam = "?uid=".intval($nUid);
238 } else {
239 $strParam = "&uid=".intval($nUid);
240 }
241 return q($this->strDeleteURL.$strParam);
242 }
243
244 /**
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()
249 * @return string
250 */
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"));
254 }
255 }
256 ?>
This page took 0.049394 seconds and 5 git commands to generate.