added php5-cli to Depends
[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 /** (erErrorReportManager) pointer to a erErrorReportManager instance */
39 protected $objManager;
40 /**
41 * (string) URL to the page which allows editing of an error report.
42 * The specified page must handle the <tt>uid</tt> GET parameter, which
43 * contains the unique ID of the error report to be edited.
44 */
45 protected $strEditURL;
46 /**
47 * (string) URL to the page which allows deletion of an error report.
48 * The specified page must handle the <tt>uid</tt> GET parameter, which
49 * contains the unique ID of the error report to be deleted.
50 */
51 protected $strDeleteURL;
52
53 /**
54 * Constructor
55 * @param $objemm (erErrorReportManager) Pointer to a instance of the
56 * erErrorReportManager class for retrieving the document data
57 * @return erErrorReportView
58 */
59 public function __construct(erErrorReportManager &$objemm) {
60 $this->objManager = $objemm;
61 html_header("<style type='text/css'>
62 table.errors-view-table { width:100%; border:2px solid #5276AB; }
63 td.errors-view-description { width:12em; }
64 td.errors-view-comment-row { font-style:italic; }
65 td.errors-view-action-edit, td.errors-view-action-delete {
66 width: 16px;
67 padding:0 1em;
68 vertical-align:middle;
69 }
70 </style>");
71 }
72
73 /**
74 * Print a single error report.
75 * Call this function to print a table or a compound of table rows with the
76 * information of the specified error report. The function determines if the
77 * current user is the owner of the specified report or if he has admin
78 * rights and in this case displays buttons for deletion and editing the
79 * error report.
80 * @param $objem (erErrorReport) Error report to print
81 * @param $bSingle (bool) Determines if you call this function once
82 * (<tt>true</tt>) or several times to get a compound table of reports
83 * (<tt>false</tt>).
84 * @param $bAdminButtons (bool) Explicitly determines whether to show the
85 * edit and delete buttons. This parameter overrides the check for owner and
86 * admin rights.
87 */
88 public function printErrorReport(erErrorReport $objem, $bSingle = false, $bAdminButtons = true) {
89 global $colbox_state, $invtbl;
90 if($bSingle) {
91 bgcol("cb");
92 echo "<{$GLOBALS["invtbl"]} class='errors-view-table'>";
93 }
94 $nColor = bgcol_rgb();
95 $sColor = sprintf("rgb(%d,%d,%d)", ($nColor >> 16) % 256,
96 ($nColor >> 8) % 256, $nColor % 256);
97 echo "<tr style='background-color:$sColor'>";
98 if(erConfig::userIsAdmin() or
99 $this->objManager->userIsOwner($objem->getUid())) {
100 // user is admin or owner
101 echo "<td style='padding:3px'><{$GLOBALS["invtbl"]} width='100%'>\n";
102 $sRow = "<tr><td class='errors-view-description'>%s</td><td>%s</td></tr>";
103 echo sprintf("$sRow\n", _c("error-reporter:Reported by:"),
104 erMailToUserLink($objem->getOwner()));
105 echo sprintf("$sRow\n", _c("error-reporter:Date:"),
106 SmartDate($objem->getDate()));
107 echo sprintf("$sRow\n", _c("error-reporter:Affected machine:"),
108 q($objem->getMachine()));
109 echo sprintf("$sRow\n", _c("error-reporter:Text:"), q($objem->getText()));
110 echo sprintf("$sRow\n", _c("error-reporter:Hidden:"), $objem->isHidden() ?
111 _c("error-reporter:yes") : _c("error-reporter:no"));
112 if(trim($objem->getComment()) != "") {
113 echo sprintf("<tr><td class='errors-view-description ".
114 "errors-view-comment-row'>%s</td><td ".
115 "class='errors-view-comment-row'>%s</td></tr>\n",
116 sprintf(_c("error-reporter:Comment by %s:"),
117 erMailToUserLink($objem->getCommentOwner())),
118 q($objem->getComment()));
119 }
120 echo "</table></td>\n";
121 // admin buttons
122 if($bAdminButtons) {
123 echo sprintf("<td class='errors-view-action-edit'>%s</td>".
124 "<td class='errors-view-action-delete'>%s</td>",
125 $this->getEditLink($objem->getUid()),
126 $this->getDeleteLink($objem->getUid()));
127 }
128 echo "</tr>\n";
129 } else {
130 // user can only read the report
131 echo "<td><{$GLOBALS["invtbl"]} width='100%'>\n";
132 $sRow = "<tr><td class='errors-view-description'>%s</td><td>%s</td></tr>";
133 echo sprintf("$sRow\n", _c("error-reporter:Affected machine:"),
134 $objem->getMachine());
135 echo sprintf("$sRow\n", _c("error-reporter:Text:"), $objem->getText());
136 if(trim($objem->getComment()) != "") {
137 echo sprintf("<tr><td class='errors-view-description ".
138 "errors-view-comment-row'>%s</td><td ".
139 "class='errors-view-comment-row'>%s</td></tr>\n",
140 sprintf(_c("error-reporter:Comment by %s:"),
141 erMailToUserLink($objem->getCommentOwner())),
142 q($objem->getComment()));
143 }
144 echo "</td></table><td /><td /></tr>\n";
145 }
146 if($bSingle) {
147 echo "</table>\n";
148 _bgcol();
149 }
150 }
151
152 /**
153 * Print a table of error reports.
154 * Prints a table with several error reports by calling printErrorReport()
155 * for each report.
156 * @param $arobjem (array of errorReport objects) The reports to print
157 */
158 public public function printErrorReports($arobjem) {
159 echo "<{$GLOBALS["invtbl"]} class='errors-view-table'>";
160 bgcol("cb");
161 if(is_array($arobjem)) {
162 foreach($arobjem as $em) {
163 $this->printErrorReport($em);
164 if(_bgcol() == "bl") {
165 bgcol("cb");
166 } else {
167 bgcol("bl");
168 }
169 }
170 }
171 _bgcol();
172 echo "</table>\n";
173 }
174
175 /**
176 * Set the link to the edit page.
177 * The specified page must handle the <tt>uid</tt> GET parameter, which
178 * contains the unique ID of the error report to be edited.
179 * @see getEditURL()
180 * @see getEditLink()
181 * @param $strUrl (string)
182 */
183 public function setEditURL($strUrl) { $this->strEditURL = $strUrl; }
184
185 /**
186 * Get the link to the edit page.
187 * @param $nUid (int) Unique ID of the error report to be edited
188 * @see setEditURL()
189 * @see getEditLink()
190 * @return (string)
191 */
192 public function getEditURL($nUid) {
193 if(preg_match("/\?/", $this->strEditURL) == 0) {
194 $strParam = "?uid=".intval($nUid);
195 } else {
196 $strParam = "&uid=".intval($nUid);
197 }
198 return q($this->strEditURL.$strParam);
199 }
200
201 /**
202 * Create a link to the edit page
203 * @param $nUid (int) Unique ID of the error report to be edited
204 * @see setEditURL()
205 * @see getEditURL()
206 * @return string
207 */
208 public function getEditLink($nUid) {
209 return sprintf("<a %s title='%s'>%s</a>", pop($this->getEditURL($nUid),
210 500, 500), _c("error-reporter:Edit this error report"), icon("write"));
211 }
212
213 /**
214 * Set the link to the delete page.
215 * The specified page must handle the <tt>uid</tt> GET parameter, which
216 * contains the unique ID of the error report to be deleted.
217 * @see getDeleteURL()
218 * @see getDeleteLink()
219 * @param $strUrl (string)
220 */
221 public function setDeleteURL($strUrl) { $this->strDeleteURL = $strUrl; }
222
223 /**
224 * Get the link to the delete page.
225 * @param $nUid (int) Unique ID of the error report to be deleted
226 * @see setDeleteURL()
227 * @see getDeleteLink()
228 * @return (string)
229 */
230 public function getDeleteURL($nUid) {
231 if(preg_match("/\?/", $this->strDeleteURL) == 0) {
232 $strParam = "?uid=".intval($nUid);
233 } else {
234 $strParam = "&uid=".intval($nUid);
235 }
236 return q($this->strDeleteURL.$strParam);
237 }
238
239 /**
240 * Create a link to the delete page
241 * @param $nUid (int) Unique ID of the error report to be deleted
242 * @see setDeleteURL()
243 * @see getDeleteURL()
244 * @return string
245 */
246 public function getDeleteLink($nUid) {
247 return sprintf("<a href='%s' title='%s'>%s</a>", $this->getDeleteURL($nUid),
248 _c("error-reporter:Delete this error report"), icon("trash"));
249 }
250 }
251 ?>
This page took 0.055401 seconds and 5 git commands to generate.