+
+Für ältere Versionen liegen keine genauen Informationen vor.
+
+
diff --git a/img/16/mod_error-reporter.png b/img/16/mod_error-reporter.png
new file mode 100644
index 0000000000000000000000000000000000000000..b88c5844b8c671647d11f43de88a8643fe2e58d7
GIT binary patch
literal 860
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 0;
+}
+
+/**
+ * Retrieve all groups that have a privilege assigned
+ * @param $strPriv (string) Privilege to test
+ * @return array
+ */
+function erPrivilegedGroups($strPriv) {
+ $aReturn = array();
+ $h = db_query("SELECT act FROM privileges_assign WHERE privilege = $1 ".
+ "ORDER BY act;", $strPriv);
+ if(pg_num_rows($h) > 0) {
+ while($a = pg_fetch_array($h)) {
+ $aReturn[] = $a["act"];
+ }
+ }
+ return $aReturn;
+}
+
+define("ER_CONFIGFILE_HEADER", "setMailNotify(true);
+ $this->setMailNotifyAddr("admins, win-admins");
+ }
+
+ /**
+ * @}
+ * @name Operations
+ * @{
+ */
+
+ /**
+ * Write the current state of this instance to the config file.
+ * @return (bool) If the function fails, it returns false. Call getLastError() to get
+ * more information about the error.
+ */
+ public function writeConfig() {
+ // Open config file
+ $hFile = fopen("mod_error-reporter/config.inc", "w", true);
+ if(!is_resource($hFile)) {
+ setLastError(ER_ERROR_OPEN_FILE);
+ return false;
+ }
+ // Try to lock file repeatedly
+ for($n = 0; !flock($hFile, LOCK_EX); $n++) {
+ if($n > 10) {
+ setLastError(ER_ERROR_LOCK_FILE);
+ return false; // Give up
+ } else {
+ sleep(0.1); // Retry after 100 ms
+ }
+ }
+
+ // Create text for config file
+ $strFile = ER_CONFIGFILE_HEADER;
+
+ // Mail notification
+ $strFile .= sprintf("\$cfgErrors->setMailNotify(%s);\n",
+ $this->isMailNotify() ? "true" : "false");
+ $strFile .= sprintf("\$cfgErrors->setMailNotifyAddr('%s');\n", $this->getMailNotifyAddr());
+
+ $strFile .= "?>";
+
+ // Write to config file and unlock it
+ if(fwrite($hFile, $strFile) == false) {
+ setLastError(ER_ERROR_WRITE_FILE);
+ return false;
+ }
+ if(!flock($hFile, LOCK_UN)) {
+ setLastError(ER_ERROR_UNLOCK_FILE);
+ return false;
+ }
+ return true;
+ }
+
+ public function readConfig() {
+ global $cfgErrors;
+ require("error-reporter/config.inc");
+ }
+
+ /**
+ * @}
+ * @name Setting options
+ * @{
+ */
+
+ /**
+ * Enable or disable mail notification
+ * @param $b (bool) true to enable mail notification, false to disable it.
+ */
+ public function setMailNotify($b) { $this->bMailNotify = ($b == true); }
+
+ /**
+ * Set the mail address(es) for mail notification
+ * @param $str (string) The adresses to send the notofication mails to, comma-separated
+ */
+ public function setMailNotifyAddr($str) { $this->strMailNotifyAddr = $str; }
+
+ /**
+ * @}
+ * @name Retrieving options
+ * @{
+ */
+
+ /**
+ * Determine if mail notification is enabled
+ * @return (bool) true if mail notification is enabled, otherwise false
+ */
+ public function isMailNotify() { return $this->bMailNotify; }
+
+ /**
+ * Get the mail adress(es) for mail notification
+ * @return string
+ */
+ public function getMailNotifyAddr() { return $this->strMailNotifyAddr; }
+
+ /**
+ * Determine if the current user is allowed to see and report errors. This
+ * function tests if the user is member of a group which has the
+ * mod-errorreporter_access privilege.
+ * @return bool
+ */
+ public function userHasAccess() {
+ if($this->userIsAdmin() ||
+ !erPrivilegeAssigned("mod_errorreporter_access")) {
+ // user is admin or privilege is not assigned
+ return true;
+ } else {
+ return secure_privilege("mod_errorreporter_access");
+ }
+ }
+
+ /* legacy */
+ public function userIsAllowed() { return $this->userHasAccess(); }
+
+ /**
+ * Determine if the current user has admin rights. This function tests if
+ * the user is member of a group which has the
+ * mod-errorreporter_access privilege
+ * @return bool
+ */
+ public function userIsAdmin() {
+ return secure_privilege("mod_errorreporter_admin");
+ }
+
+ /** @} */
+}
+?>
\ No newline at end of file
diff --git a/inc/class_erErrorReport.inc b/inc/class_erErrorReport.inc
new file mode 100644
index 0000000..9a4da19
--- /dev/null
+++ b/inc/class_erErrorReport.inc
@@ -0,0 +1,178 @@
+nUid = null;
+ $this->tsDate = intval($tsDate);
+ $this->strOwner = $strOwner;
+ $this->strMachine = $strMachine;
+ $this->strText = $strText;
+ $this->strComment = null;
+ $this->strCommentOwner = null;
+ $this->bHidden = ($bHidden == true);
+ }
+
+ /////////////////////////////////////////// SETTER FUNCTIONS ///////////////////////////////////////////
+
+ /**
+ * @}
+ * @name Setter functions
+ * @{
+ */
+
+ /**
+ * Set the unique ID
+ * @param $value (int)
+ */
+ function setUid($value) { $this->nUid = $value; }
+ /**
+ * Set the date
+ * @param $value (timestamp)
+ */
+ function setDate($value) { $this->tsDate = intval($value); }
+ /**
+ * Set the account name of the owner
+ * @param $value (string)
+ */
+ function setOwner($value) { $this->strOwner = $value; }
+ /**
+ * Set the label of the machine to which the report refers
+ * @param $value (string)
+ */
+ function setMachine($value) { $this->strMachine = $value; }
+ /**
+ * Set the text of the report
+ * @param $value (string)
+ */
+ function setText($value) { $this->strText = $value; }
+
+ /**
+ * Set the comment of an adminstrator
+ * @param $strComment (string) Comment
+ * @param $strAct (string) Account name of the person who sets the comment
+ */
+ function setComment($strComment, $strAct) {
+ $this->strComment = $strComment;
+ $this->strCommentOwner = $strAct;
+ }
+ /**
+ * Set the visibility of the report
+ * @param $value (bool) true: the report is only visible for administrators
+ */
+ function setVisibility($value) { $this->bHidden = $value; }
+
+ /////////////////////////////////////////// GETTER FUNCTIONS ///////////////////////////////////////////
+
+ /**
+ * @}
+ * @name Getter functions
+ * @{
+ */
+
+ /**
+ * Get the unique ID in the database
+ * @return (int)
+ */
+ function getUid() { return intval($this->nUid); }
+ /**
+ * Get the date when the report was created
+ * @return (timestamp)
+ */
+ function getDate() { return intval($this->tsDate); }
+ /**
+ * Get the account name of the creator
+ * @return (string)
+ */
+ function getOwner() { return $this->strOwner; }
+ /**
+ * Get the label of the machine to which the report refers
+ * @return (string)
+ */
+ function getMachine() { return $this->strMachine; }
+ /**
+ * Get the tet of the report
+ * @return (string)
+ */
+ function getText() { return $this->strText; }
+ /**
+ * Get the comment from an administrator
+ * @return (string)
+ */
+ function getComment() { return $this->strComment; }
+ /**
+ * Get the account name of the one who wrote the comment
+ * @return (string)
+ */
+ function getCommentOwner() { return $this->strCommentOwner; }
+ /**
+ * Determine if the report can be seen by non-administrators
+ * @return (bool)
+ */
+ function isHidden() { return ($this->bHidden == true); }
+
+ /**@}*/
+}
+?>
\ No newline at end of file
diff --git a/inc/class_erErrorReportManager.inc b/inc/class_erErrorReportManager.inc
new file mode 100644
index 0000000..1536159
--- /dev/null
+++ b/inc/class_erErrorReportManager.inc
@@ -0,0 +1,414 @@
+null, writeErrorReport() will use the next ID which is not used in the
+ * table.
+ *
+ * @par
+ * An error report that has been written to the database can be changed using
+ * writeErrorReport(), setting the $nUid member of the erErrorReport parameter to the UID of the
+ * error report to be changed.
+ *
+ * @par
+ * To change the visibility of an error report to @e hidden, call setErrorReportDoneFlag() with
+ * the UID of the error report and set the second parameter to false.
+ *
+ * @par
+ * To delete an error report from the database, call deleteErrorReport() with the UID of the
+ * error report you want to delete.
+ *
+ * @par
+ * Error reports can be retrieved by their UID (getErrorReportByID()), by creation date
+ * (getErrorReportsByDate()), by owner (getErrorReportsByOwner()), by machine to which the
+ * report refers (getErrorReportsByMachine()) and by the person who wrote the comment
+ * (getErrorReportsByCommentOwner()). All error reports in the database can be retrieved using
+ * getErrorReports(). All of these functions return a object of type erErrorReport or an array
+ * of erErrorReport objects.
+ *
+ * @par Example
+ * The following example creates a new error report âThis doesnât workâ, written by the user
+ * âtestuserâ on February 5, 2007, which refers to the machine âClient-26â and is not visible for
+ * non-admin users. Then it adds a nice comment, makes the error report visible and writes it to
+ * the database.
+ * @code
+ * setComment("We know that already", "admin");
+ *
+ * $nNewID = $obj->writeErrorReport($em); // $em->nUid is null, so writeErrorReport()
+ * // calculates the UID by itself
+ * ?>
+ * @endcode
+ */
+
+class erErrorReportManager {
+
+
+ /**
+ * (object of type erConfig) pointer to the configuration class
+ */
+ protected $objcfg;
+
+ /**
+ * Constructor
+ * @param $objcfg (object of type erConfig) Pointer to the configuration class for retrieving the
+ * configuration data
+ * @return erErrorReportManager
+ */
+ public function __construct(&$objcfg) {
+ $this->objcfg = &$objcfg;
+ }
+
+ //////////////////////////////////////////// QUERYING ///////////////////////////////////////////
+
+ /**
+ * @name Quering
+ * @{ */
+
+ /**
+ * Get all error reports in the database.
+ * If this function fails, it returns null. Call getLastError() to get more information.
+ * @param $arcSort (array of constants) Defines the sorting of the returned array.
+ * See the documentation of the $arcSort parameter of buildOrderByClause() for more information.
+ * @return array of objects of type erErrorReport
+ */
+ public function getErrorReports($arcSort = array(ER_ERM_SORT_UID => ER_ERM_SORT_ASC)) {
+ return $this->readFromSQL("", $arcSort);
+ }
+
+ /**
+ * Get an error report by its unique ID in database.
+ * If this function fails, it returns null.
+ * @param $nID (int) ID of the error report
+ * @return erErrorReport
+ */
+ public function getErrorReportByID($nID) {
+ $arReturn = $this->readFromSQL("er_uid = ".qdb(intval($nID)));
+ if(is_array($arReturn) and count($arReturn) > 0) {
+ return $arReturn[0]; // return as scalar
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Get all error reports which have been created on the specified date.
+ * If this function fails, it returns null. Call getLastError() to get more information.
+ * @param $tsDate (timestamp) Date
+ * @param $arcSort (array of constants) Defines the sorting of the returned array.
+ * See the documentation of the $arcSort parameter of buildOrderByClause() for more information.
+ * @return array of objects of type erErrorReport
+ */
+ public function getErrorReportsByDate($tsDate, $arcSort = array(ER_ERM_SORT_UID => ER_ERM_SORT_ASC)) {
+ return $this->readFromSQL("er_date = ".qdb(date("Y\-m\-d", $tsDate)), $arcSort);
+ }
+
+ /**
+ * Get all error reports which have been created by the specified user.
+ * If this function fails, it returns null. Call getLastError() to get more information.
+ * @param $strAct (string) Account name
+ * @param $arcSort (array of constants) Defines the sorting of the returned array.
+ * See the documentation of the $arcSort parameter of buildOrderByClause() for more information.
+ * @return array of objects of type erErrorReport
+ */
+ public function getErrorReportsByOwner($strAct, $arcSort = array(ER_ERM_SORT_UID => ER_ERM_SORT_ASC)) {
+ return $this->readFromSQL("er_act = ".qdb($strAct), $arcSort);
+ }
+
+ /**
+ * Get all error reports which are related to a specified machine.
+ * If this function fails, it returns null. Call getLastError() to get more information.
+ * @param $strMachine (string) Machine name
+ * @param $arcSort (array of constants) Defines the sorting of the returned array.
+ * See the documentation of the $arcSort parameter of buildOrderByClause() for more information.
+ * @return array of objects of type erErrorReport
+ */
+ public function getErrorReportsByMachine($strMachine,
+ $arcSort = array(ER_ERM_SORT_UID => ER_ERM_SORT_ASC)) {
+ return $this->readFromSQL("er_machine = ".qdb($strMachine), $arcSort);
+ }
+
+ /**
+ * Get all error reports which have been commented by the specified user.
+ * If this function fails, it returns null. Call getLastError() to get more information.
+ * @param $strAct (string) Account name
+ * @param $arcSort (array of constants) Defines the sorting of the returned array.
+ * See the documentation of the $arcSort parameter of buildOrderByClause() for more information.
+ * @return array of objects of type erErrorReport
+ */
+ public function getErrorReportsByCommentOwner($strAct,
+ $arcSort = array(ER_ERM_SORT_UID => ER_ERM_SORT_ASC)) {
+ return $this->readFromSQL("er_commentact = ".qdb($strAct), $arcSort);
+ }
+
+ /*@}*/
+
+ /**
+ * Get datasets from the SQL tables.
+ * This function should not be called directly. Use the getBy* functions instead.
+ * If this function fails, it returns null. Call getLastError() to get more information.
+ * @internal
+ * @param $strWhere (string) Parameters for the SQL WHERE clause
+ * @param $arcSort (array of constants) Defines the sorting of the returned array.
+ * See the documentation of the $arcSort parameter of buildOrderByClause() for more information.
+ * @return array of objects of type erErrorReport
+ */
+ protected function readFromSQL($strWhere = "", $arcSort = array(ER_ERM_SORT_UID => ER_ERM_SORT_ASC)) {
+ $arReturn = array();
+
+ // only allow visible reports for non-admins, but all reports for admins and owners
+ if($this->objcfg->userIsAdmin()) {
+ $strWhereClause = (trim($strWhere) == "") ? "" : "WHERE $strWhere";
+ } else {
+ $strWhereClause = "WHERE ".((trim($strWhere) == "") ? "" : "$strWhere AND ").
+ sprintf("((er_act = '%s') or (er_hidden IS NULL OR NOT er_hidden))", $_SESSION["act"]);
+ }
+
+ $strSortClause = $this->buildOrderByClause($arcSort);
+
+ // fetch the error reports
+ $hQuery = db_query("SELECT * FROM mod_errorreporter $strWhereClause $strSortClause;");
+ if(!is_resource($hQuery)) {
+ setLastError(ER_ERROR_SQL);
+ return null;
+ }
+ while($arResult = pg_fetch_array($hQuery)) {
+ $er = new erErrorReport(strtotime($arResult["er_date"]), $arResult["er_act"],
+ $arResult["er_machine"], $arResult["er_text"], $arResult["er_hidden"] == "t");
+ $er->setUid($arResult["er_uid"]);
+ $er->setComment($arResult["er_comment"], $arResult["er_commentact"]);
+ $arReturn[] = $er;
+ }
+ return $arReturn;
+ }
+
+ /**
+ * Build a ORDER BY clause from an array.
+ * This helper function takes an array of sorting constants as input and returns an ORDER BY
+ * clause. The values in the clause are in the same order as the constants in the array.
+ * The function in the following example returns an ORDER BY clause where the datasets are first
+ * sorted ascending by visibility, then descending by the machine name to which they refer and
+ * finally ascending by their UID:
+ * @code
+ * $strOrder = buildOrderClause(array(
+ * ER_ERM_SORT_VISIBILITY => ER_ERM_SORT_ASC,
+ * ER_ERM_SORT_MACHINE => ER_ERM_SORT_DESC,
+ * ER_ERM_SORT_UID => ER_ERM_SORT_ASC));
+ * echo $strOrder;
+ * @endcode
+ * The output is: ORDER BY er_hidden ASC, er_machine DESC, er_uid ASC
+ * @internal
+ * @param $arcSort (array of constants) The array which declares the order of the SQL rows. Use
+ * @ref errorreportmanager_sorting as keys and @ref errorreportmanager_sorting_dir as values.
+ * @return string
+ */
+ protected function buildOrderByClause($arcSort) {
+ // build the sorting clause
+ $arstrSort = array();
+ foreach($arcSort as $cSort => $cDir) {
+ switch($cSort) {
+ case ER_ERM_SORT_UID:
+ $arstrSort[] = "er_uid ".($cDir == ER_ERM_SORT_DESC ? "DESC" : "ASC"); break;
+ case ER_ERM_SORT_DATE:
+ $arstrSort[] = "er_date ".($cDir == ER_ERM_SORT_DESC ? "DESC" : "ASC"); break;
+ case ER_ERM_SORT_OWNER:
+ $arstrSort[] = "er_act ".($cDir == ER_ERM_SORT_DESC ? "DESC" : "ASC"); break;
+ case ER_ERM_SORT_MACHINE:
+ $arstrSort[] = "er_machine ".($cDir == ER_ERM_SORT_DESC ? "DESC" : "ASC"); break;
+ case ER_ERM_SORT_TEXT:
+ $arstrSort[] = "er_text ".($cDir == ER_ERM_SORT_DESC ? "DESC" : "ASC"); break;
+ case ER_ERM_SORT_COMMENT:
+ $arstrSort[] = "er_comment ".($cDir == ER_ERM_SORT_DESC ? "DESC" : "ASC"); break;
+ case ER_ERM_SORT_COMMENTOWNER:
+ $arstrSort[] = "er_commentact ".($cDir == ER_ERM_SORT_DESC ? "DESC" : "ASC"); break;
+ case ER_ERM_SORT_VISIBILITY:
+ $arstrSort[] = "er_hidden ".($cDir == ER_ERM_SORT_DESC ? "DESC" : "ASC"); break;
+ }
+ }
+ return ("ORDER BY ".join(", ", $arstrSort));
+ }
+
+ //////////////////////////////////// ERROR MESSAGE MANAGEMENT ///////////////////////////////////
+
+ /**
+ * @name Error report management
+ * @{
+ */
+
+ /**
+ * Insert or update an error report in the database.
+ * When the $nUid member of the $erErrorReport object is null, a new unique ID is
+ * assigned and the error report is written to the database. Otherwise, the corresponding
+ * record in the table is updated.
+ * @param $er (erErrorReport)
+ * @return (int) The unique ID of the inserted or updated record.
+ * @throws Exception
+ */
+ public function writeErrorReport(erErrorReport $er) {
+ if(!$this->objcfg->userHasAccess() and (!$this->userIsOwner($er->nUid) or
+ ($er->getUid() == null and !($this->objcfg->userIsAdmin())))) {
+ throw new Exception(ER_ERROR_ACCESS_DENIED);
+ }
+
+ $strWhere = null;
+ $strLog = "";
+
+ // Update or insert?
+ $arPut = array();
+ if($er->getUid() == null) {
+ // er_uid is now serial
+ /*$hQuery = db_query("SELECT MAX(er_uid) AS id FROM mod_errorreporter;");
+ if(!is_resource($hQuery)) {
+ setLastError(ER_ERROR_SQL);
+ return -1;
+ }
+ $arResult = pg_fetch_array($hQuery);
+ $er->setUid(intval($arResult["id"]) + 1);*/
+ $strLog = sprintf("Fehlermeldung für Rechner â%sâ eingetragen.",
+ $er->getMachine());
+ } else {
+ $strWhere = "er_uid = ".qdb(intval($er->getUid()));
+ $oOldReport = $this->getErrorReportByID($er->getUid());
+ $strLog = sprintf("Fehlermeldung geändert, Rechner war â%sâ, Text war â%sâ. ".
+ "Neuer Rechner: â%sâ, neuer Text: â%sâ, Kommentar: %s",
+ $oOldReport->getMachine(), $oOldReport->getText(), $er->getMachine(),
+ $er->getText(), (strlen($er->getComment()) > 0) ? "â".$er->getComment()."â" : "(leer)");
+ }
+ $arPut["er_date"] = date("Y\-m\-d\ G\:i\:s", $er->getDate());
+ $arPut["er_act"] = $er->getOwner();
+ $arPut["er_machine"] = $er->getMachine();
+ $arPut["er_text"] = $er->getText();
+ $arPut["er_comment"] = $er->getComment();
+ $arPut["er_commentact"] = $er->getCommentOwner();
+ $arPut["er_hidden"] = $er->isHidden() ? "true" : "false";
+ db_store("mod_errorreporter", $arPut, $strWhere);
+
+ erInsertLog($strLog);
+
+ // send notification mail, but only if the message is new
+ if($this->objcfg->isMailNotify() and $er->getUid() == null) {
+ $strMailText = sprintf("\nEin Benutzer hat eine Fehlermeldung mit dem ".
+ "Fehlermeldungs-Assistenten abgeschickt. Nachfolgend finden sich Angaben über den ".
+ "Fehler.\n
\n
Fehler gemeldet von:
%s
\n".
+ "
Datum:
%s
\n
Betroffener Rechner:
%s
\n".
+ "
%s
\n
\n\nDiese Mail wurde automatisch ".
+ "generiert.\n", q(erGetRealUserName($er->getOwner())),
+ q(date("d\.m\.Y\ G\:i\:s", $er->getDate())), q($er->getMachine()), q($er->getText()));
+ $strMailSubject = sprintf("%s hat einen Fehler im System gemeldet",
+ q(erGetRealUserName($er->getOwner())));
+ $strMailHeader = sprintf("From: %s <%s>\nContent-Type: text/html; charset=utf-8",
+ q(erGetRealUserName($er->getOwner())), user_mail_addr($er->getOwner()));
+ mail($this->objcfg->getMailNotifyAddr(), $strMailSubject, $strMailText, $strMailHeader);
+ }
+
+ return $er->getUid();
+ }
+
+ /**
+ * Delete an error report from the database.
+ * @param $nErrorReportID (int) Unique ID of the error report to delete or -1 if an error
+ * occured. In this case, call getLastError() to get more information.
+ */
+ public function deleteErrorReport($nErrorReportID) {
+ if(!($this->objcfg->userIsAdmin() or $this->userIsOwner($nErrorReportID))) {
+ setLastError(ER_ERROR_ACCESS_DENIED);
+ return -1;
+ }
+
+ $oOldReport = $this->getErrorReportByID($nErrorReportID);
+ db_query(sprintf("DELETE FROM mod_errorreporter WHERE er_uid = '%d';", intval($nErrorReportID)));
+ erInsertLog(sprintf("Fehlermeldung gelöscht, Rechner war â%sâ, Text war â%sâ",
+ $oOldReport->getMachine(), $oOldReport->getText()));
+ }
+
+ /**
+ * Determine if the current user is the owner of a specified error report.
+ * If this function fails, call getLastError() to get more information.
+ * @param $nID (int) Unique ID of the error report
+ * @return bool
+ */
+ public function userIsOwner($nID) {
+ if(!$_SESSION["act"]) {
+ return false; // user is not logged in
+ } else {
+ $hQuery = db_query(sprintf("SELECT er_act FROM mod_errorreporter WHERE er_uid = %d;", intval($nID)));
+ if(!is_resource($hQuery)) {
+ setLastError(ER_ERROR_SQL);
+ return false;
+ }
+ $arResult = pg_fetch_array($hQuery);
+ return ($arResult["er_act"] == $_SESSION["act"]);
+ }
+ }
+}
+?>
\ No newline at end of file
diff --git a/inc/class_erErrorReportView.inc b/inc/class_erErrorReportView.inc
new file mode 100644
index 0000000..5a2cc7b
--- /dev/null
+++ b/inc/class_erErrorReportView.inc
@@ -0,0 +1,247 @@
+uid GET parameter, which contains the unique ID
+ * of the error report to be edited.
+ */
+ protected $strEditURL;
+ /**
+ * (string) URL to the page which allows deletion of an error report.
+ * The specified page must handle the uid GET parameter, which contains the unique ID
+ * of the error report to be deleted.
+ */
+ protected $strDeleteURL;
+
+ /**
+ * Constructor
+ * @param $objcfg (object of type erConfig) Pointer to an instance of the erConfig class for
+ * retrieving the configuration data
+ * @param $objemm (object of type erErrorReportManager) Pointer to a instance of the
+ * erErrorReportManager class for retrieving the document data
+ * @return erErrorReportView
+ */
+ public function __construct(erConfig &$objcfg, erErrorReportManager &$objemm) {
+ $this->objcfg = $objcfg;
+ $this->objManager = $objemm;
+ html_header("");
+ }
+
+ /**
+ * Print a single error report.
+ * Call this function to print a table or a compound of table rows with the information of the
+ * specified error report. The function determines if the current user is the owner of the
+ * specified report or if he has admin rights and in this case displays buttons for deletion and
+ * editing the error report.
+ * @param $objem (erErrorReport) Error report to print
+ * @param $bSingle (bool) Determines if you call this function once (true) or several
+ * times to get a compound table of reports (false).
+ * @param $bAdminButtons (bool) Explcitly determines whether to show the edit and delete buttons.
+ * This parameter overrides the userIsAdmin() and userIsOwner() functions.
+ */
+ public function printErrorReport(erErrorReport $objem, $bSingle = false, $bAdminButtons = true) {
+ global $colbox_state, $invtbl;
+ if($bSingle) {
+ bgcol("cb");
+ echo "<{$GLOBALS["invtbl"]} class='errors-view-table'>";
+ }
+ $nColor = bgcol_rgb();
+ $sColor = sprintf("rgb(%d,%d,%d)", ($nColor >> 16) % 256, ($nColor >> 8) % 256, $nColor % 256);
+ echo "
";
+ if($this->objcfg->userIsAdmin() or $this->objManager->userIsOwner($objem->getUid())) {
+ // user is admin or owner
+ echo "
\n";
+ }
+ if($bSingle) {
+ echo "\n";
+ _bgcol();
+ }
+ }
+
+ /**
+ * Print a table of error reports.
+ * Prints a table with several error reports by calling printErrorReport() for each report.
+ * @param $arobjem (array of errorReport objects) The reports to print
+ */
+ public public function printErrorReports($arobjem) {
+ echo "<{$GLOBALS["invtbl"]} class='errors-view-table'>";
+ bgcol("cb");
+ if(is_array($arobjem)) {
+ foreach($arobjem as $em) {
+ $this->printErrorReport($em);
+ if(_bgcol() == "bl") {
+ bgcol("cb");
+ } else {
+ bgcol("bl");
+ }
+ }
+ }
+ _bgcol();
+ echo "\n";
+ }
+
+ /**
+ * Set the link to the edit page.
+ * The specified page must handle the uid GET parameter, which contains the unique ID
+ * of the error report to be edited.
+ * @see getEditURL()
+ * @see getEditLink()
+ * @param $strUrl (string)
+ */
+ public function setEditURL($strUrl) { $this->strEditURL = $strUrl; }
+
+ /**
+ * Get the link to the edit page.
+ * @param $nUid (int) Unique ID of the error report to be edited
+ * @see setEditURL()
+ * @see getEditLink()
+ * @return (string)
+ */
+ public function getEditURL($nUid) {
+ if(preg_match("/\?/", $this->strEditURL) == 0) {
+ $strParam = "?uid=".intval($nUid);
+ } else {
+ $strParam = "&uid=".intval($nUid);
+ }
+ return q($this->strEditURL.$strParam);
+ }
+
+ /**
+ * Create a link to the edit page
+ * @param $nUid (int) Unique ID of the error report to be edited
+ * @see setEditURL()
+ * @see getEditURL()
+ * @return string
+ */
+ public function getEditLink($nUid) {
+ return sprintf("%s", pop($this->getEditURL($nUid), 500, 500),
+ _c("error-reporter:Edit this error report"), icon("write"));
+ }
+
+ /**
+ * Set the link to the delete page.
+ * The specified page must handle the uid GET parameter, which contains the unique ID
+ * of the error report to be deleted.
+ * @see getDeleteURL()
+ * @see getDeleteLink()
+ * @param $strUrl (string)
+ */
+ public function setDeleteURL($strUrl) { $this->strDeleteURL = $strUrl; }
+
+ /**
+ * Get the link to the delete page.
+ * @param $nUid (int) Unique ID of the error report to be deleted
+ * @see setDeleteURL()
+ * @see getDeleteLink()
+ * @return (string)
+ */
+ public function getDeleteURL($nUid) {
+ if(preg_match("/\?/", $this->strDeleteURL) == 0) {
+ $strParam = "?uid=".intval($nUid);
+ } else {
+ $strParam = "&uid=".intval($nUid);
+ }
+ return q($this->strDeleteURL.$strParam);
+ }
+
+ /**
+ * Create a link to the delete page
+ * @param $nUid (int) Unique ID of the error report to be deleted
+ * @see setDeleteURL()
+ * @see getDeleteURL()
+ * @return string
+ */
+ public function getDeleteLink($nUid) {
+ return sprintf("%s", $this->getDeleteURL($nUid),
+ _c("error-reporter:Delete this error report"), icon("trash"));
+ }
+}
+?>
\ No newline at end of file
diff --git a/inc/functions.inc b/inc/functions.inc
new file mode 100644
index 0000000..363ce5a
--- /dev/null
+++ b/inc/functions.inc
@@ -0,0 +1,169 @@
+%s %s
", _c("error-reporter:This is ".
+ "a short summary of the privileges related to the error report assistant ".
+ "and the groups which have them assigned."),
+ sprintf(_c("error-reporter:If one of these privileges is not assigned to ".
+ "any group, all users on this server are allowed to perform the specified ".
+ "action. Please use the %sgroup administration%s to assign and revoke ".
+ "privileges."), "", ""),
+ _c("error-reporter:Please note that every group with the administration ".
+ "privilege can also implicitly report errors and see the reported messages."));
+echo "
",
+ _c("error-reporter:The specified error report does not exist!"));
+ _PageBlue();
+ die();
+}
+
+// Only admins or owners can view this page
+if(!($cfgErrors->userIsAdmin() or $doc->userIsOwner($getUid))) {
+ echo sprintf("
%s", _c("error-reporter:You are not allowed to edit this report."));
+ _PageBlue();
+ die();
+}
+
+// Load old dataset
+$er = $doc->getErrorReportByID($getUid);
+$strOldComment = $er->getComment();
+
+// Probably we have to update an error report
+if($getAction == "update" and $postSubmit == _c("Change"))
+{
+ if($cfgErrors->userIsAdmin()) {
+ $postComment = stripslashes(@$_POST["comment"]);
+ $postCommentOld = stripslashes(@$_POST["comment_old"]);
+ }
+
+ // change the fields of the old dataset
+ $er->setMachine(stripslashes(@$_POST["machine"]));
+ $er->setText(stripslashes(@$_POST["text"]));
+ $er->setVisibility(isset($_POST["hidden"]) ? true : false);
+
+ // Do we have to change the comment and his owner?
+ if($cfgErrors->userIsAdmin()) {
+ if(@$_POST["comment_old"] != @$_POST["comment"]) {
+ $er->setComment(stripslashes(@$_POST["comment"]), $_SESSION["act"]);
+ }
+ }
+
+ // write into database, reload parent and close window
+ if($doc->writeErrorReport($er) != -1) {
+ js_try("opener.location.href = 'index.php';");
+ js_close(500);
+ } else {
+ printLastError();
+ _PageBlue();
+ die();
+ }
+}
+
+// output form
+$hidctrl = "input type='hidden'";
+Title(_c("error-reporter:Change an error report"));
+echo sprintf("
\n", ER_ERROR_ACCESS_DENIED);
+ _PageBlue();
+ exit();
+}
+
+// Probably we have to delete an error report
+if($getAction == "delete" and isset($getUid)) {
+ // Are you really sure?
+ if(@$_POST["surely_delete"] == _("Delete")) {
+ $doc->deleteErrorReport($getUid);
+ header("Location: {$_SERVER["PHP_SELF"]}"); // Reload to get rid of POST data
+ } elseif(@$_POST["surely_cancel"] == _("Cancel")) {
+ header("Location: {$_SERVER["PHP_SELF"]}");
+ } else {
+ // Ask the user to delete the message
+ Title(_c("error-reporter:Delete an error report"));
+ // Check if the specified report exists
+ if(!$doc->getErrorReportByID($getUid)) {
+ echo sprintf("
",
+ _c("error-reporter:You are not allowed to delete this report."));
+ Option(_("Back"), null, "href='".$_SERVER["PHP_SELF"]."'", "back");
+ }
+ }
+ _PageBlue();
+ exit();
+ }
+}
+
+// form for reloading the page via javascript
+echo sprintf("\n", $_SERVER["PHP_SELF"]);
+
+// probably we have to insert an error report
+if(($getAction == "submit" and $postSubmit == _("Insert")))
+{
+ // All fields must be filled out
+ if((trim($postMachine) == "") or (trim($postText) == "")) {
+ $strError = _c("error-reporter:You have to fill out all the fields in the form.");
+ } else {
+ // Write to database
+ $nNewUid = null;
+ $er = new erErrorReport(time(), $_SESSION["act"], $postMachine, $postText, $postHidden == "true");
+ try {
+ $nNewUid = $doc->writeErrorReport($er);
+ } catch(Exception $e) {
+ echo sprintf("
",
+ _c("error-reporter:The report was submitted. Thank you for your help."));
+ }
+
+ $postText = "";
+ $postMachine = "";
+ $postHidden = "false";
+ }
+}
+
+// Show already existent (and visible) error reports
+Title(_c("error-reporter:Reports that have already been submitted:"));
+echo sprintf("
%s
", _c("error-reporter:These errors should not be resubmitted."));
+$view->printErrorReports($doc->getErrorReports(array(ER_ERM_SORT_DATE => ER_ERM_SORT_DESC)));
+
+// Form for submitting a new error report
+echo "\n";
+Title(_c("error-reporter:Report an error"));
+Option(_c("error-reporter:Recommened reading"), _c("error-reporter:âHow to Report Bugs ".
+ "Effectivelyâ, by Simon G. Tatham"), "target='_blank' href='".
+ _c("error-reporter:http://www.chiark.greenend.org.uk/~sgtatham/bugs.html")."'");
+
+// Print the error here
+if($strError != "")
+ echo "
$strError
\n";
+
+echo sprintf("
%s
\n", _c("error-reporter:Please write your report as precise as possible to help ".
+ "us solve the problem. The more precise the report is, the faster the error can be fixed. ".
+ "Please include also any error messages you have recieved."));
+echo "\n";
+
+_PageBlue();
+?>
--
2.20.1