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"); } /** @} */ } ?>