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