sRealname = "an anonymous user"; if(is_numeric($iUserId)) { $sQuery = "SELECT * FROM user_list WHERE userId = '".$iUserId."'"; $hResult = query_appdb($sQuery); $oRow = mysql_fetch_object($hResult); $this->iUserId = $oRow->userid; $this->sEmail = $oRow->email; $this->sRealname = $oRow->realname; $this->sStamp = $oRow->stamp; $this->sDateCreated = $oRow->created; $this->sWineRelease = $oRow->CVSrelease; $this->bInactivityWarned = $oRow->inactivity_warned; } return $this->isLoggedIn(); } /** * Logs in an user using e-mail and password. */ function login($sEmail, $sPassword) { $sQuery = "SELECT * FROM user_list WHERE email = '".addslashes($sEmail)."' AND password = password('".addslashes($sPassword)."')"; $hResult = query_appdb($sQuery); $oRow = mysql_fetch_object($hResult); $this->iUserId = $oRow->userid; $this->sEmail = $oRow->email; $this->sRealname = $oRow->realname; $this->sStamp = $oRow->stamp; $this->sDateCreated = $oRow->created; $this->sWineRelease = $oRow->CVSrelease; if($this->isLoggedIn()) { // Update timestamp and clear the inactivity flag if it was set query_appdb("UPDATE user_list SET stamp=NOW(), inactivity_warned='false' WHERE userid=".$this->iUserId); return true; } return false; } /* * Creates a new user. * returns true on success, false on failure */ function create($sEmail, $sPassword, $sRealname, $sWineRelease) { if(user_exists($sEmail)) { addMsg("An account with this e-mail exists already.","red"); return false; } else { $aInsert = compile_insert_string(array( 'realname' => $sRealname, 'email' => $sEmail, 'CVSrelease' => $sWineRelease )); $sFields = "({$aInsert['FIELDS']}, `password`, `stamp`, `created`)"; $sValues = "({$aInsert['VALUES']}, password('".$sPassword."'), NOW(), NOW() )"; query_appdb("INSERT INTO user_list $sFields VALUES $sValues", "Error while creating a new user."); $retval = $this->login($sEmail, $sPassword); $this->setPref("comments:mode", "threaded"); /* set the users default comments:mode to threaded */ return $retval; } } /** * Update User Account; */ function update($sEmail = null, $sPassword = null, $sRealname = null, $sWineRelease = null) { if(!$this->isLoggedIn()) return false; if ($sEmail) { if(user_exists($sEmail) && $sEmail != $this->sEmail) { addMsg("An account with this e-mail exists already.","red"); return false; } if (!query_appdb("UPDATE user_list SET email = '".addslashes($sEmail)."' WHERE userid = ".$this->iUserId)) return false; $this->sEmail = $sEmail; } if ($sPassword) { if (!query_appdb("UPDATE user_list SET password = password('$sPassword') WHERE userid = ".$this->iUserId)) return false; } if ($sRealname) { if (!query_appdb("UPDATE user_list SET realname = '".addslashes($sRealname)."' WHERE userid = ".$this->iUserId)) return false; $this->sRealname = $sRealname; } if ($sWineRelease) { if (!query_appdb("UPDATE user_list SET CVSrelease = '".addslashes($sWineRelease)."' WHERE userid = ".$this->iUserId)) return false; $this->sWineRelease = $sWineRelease; } return true; } /** * Removes the current, or specified user and preferences from the database. * returns true on success and false on failure. */ function delete() { if(!$this->isLoggedIn()) return false; $hResult2 = query_appdb("DELETE FROM user_privs WHERE userid = '".$this->iUserId."'"); $hResult3 = query_appdb("DELETE FROM user_prefs WHERE userid = '".$this->iUserId."'"); $hResult4 = query_appdb("DELETE FROM appVotes WHERE userid = '".$this->iUserId."'"); $hResult5 = query_appdb("DELETE FROM appMaintainers WHERE userid = '".$this->iUserId."'"); $hResult6 = query_appdb("DELETE FROM appComments WHERE userId = '".$this->iUserId."'"); return($hResult = query_appdb("DELETE FROM user_list WHERE userid = '".$this->iUserId."'")); } /** * Get a preference for the current user. */ function getPref($sKey, $sDef = null) { if(!$this->isLoggedIn() || !$sKey) return $sDef; $hResult = query_appdb("SELECT * FROM user_prefs WHERE userid = ".$this->iUserId." AND name = '$sKey'"); if(!$hResult || mysql_num_rows($hResult) == 0) return $sDef; $ob = mysql_fetch_object($hResult); return $ob->value; } /** * Set a preference for the current user. */ function setPref($sKey, $sValue) { if(!$this->isLoggedIn() || !$sKey || !$sValue) return false; $hResult = query_appdb("DELETE FROM user_prefs WHERE userid = ".$this->iUserId." AND name = '$sKey'"); $hResult = query_appdb("INSERT INTO user_prefs VALUES(".$this->iUserId.", '$sKey', '$sValue')"); return $hResult; } /** * Check if this user has $priv. */ function hasPriv($sPriv) { if(!$this->isLoggedIn() || !$sPriv) return false; $hResult = query_appdb("SELECT * FROM user_privs WHERE userid = ".$this->iUserId." AND priv = '".$sPriv."'"); if(!$hResult) return false; return mysql_num_rows($hResult); } /** * Check if this user is a maintainer of a given appId/versionId. */ function isMaintainer($iVersionId=null) { if(!$this->isLoggedIn()) return false; /* if we are a super maintainer, we are a maintainer of this version as well */ $oVersion = new Version($iVersionId); if($this->isSuperMaintainer($oVersion->iAppId)) return true; /* otherwise check if we maintain this specific version */ if($iVersionId) { $sQuery = "SELECT * FROM appMaintainers WHERE userid = '".$this->iUserId."' AND versionId = '$iVersionId'"; } else // are we maintaining any version ? { $sQuery = "SELECT * FROM appMaintainers WHERE userid = '".$this->iUserId."'"; } $hResult = query_appdb($sQuery); if(!$hResult) return false; return mysql_num_rows($hResult); } /* * Check if this user is a maintainer of a given appId/versionId. */ function isSuperMaintainer($iAppId=null) { if(!$this->isLoggedIn()) return false; if($iAppId) { $sQuery = "SELECT * FROM appMaintainers WHERE userid = '$this->iUserId' AND appId = '$iAppId' AND superMaintainer = '1'"; } else /* are we super maintainer of any applications? */ { $sQuery = "SELECT * FROM appMaintainers WHERE userid = '$this->iUserId' AND superMaintainer = '1'"; } $hResult = query_appdb($sQuery); if(!$hResult) return false; return mysql_num_rows($hResult); } function getMaintainerCount($bSuperMaintainer) { if(!$this->isLoggedIn()) return 0; $sQuery = "SELECT count(*) as cnt from appMaintainers WHERE userid = '$this->iUserId' AND superMaintainer = '$bSuperMaintainer'"; $hResult = query_appdb($sQuery); if(!$hResult) return 0; $ob = mysql_fetch_object($hResult); return $ob->cnt; } /** * Add the user as a maintainer */ function addAsMaintainer($iAppId, $iVersionId, $bSuperMaintainer, $iQueueId) { /* if the user isn't already a supermaintainer of the application and */ /* if they are trying to become a maintainer and aren't already a maintainer of */ /* the version, then continue processing the request */ if(!$this->isSuperMaintainer($iAppId) && ((!$bSuperMaintainer && !$this->isMaintainer($iVersionId)) | $bSuperMaintainer)) { // insert the new entry into the maintainers list $sQuery = "INSERT into appMaintainers VALUES(null,". "$iAppId,". "$iVersionId,". "$this->iUserId,". "$bSuperMaintainer,". "NOW());"; if (query_appdb($sQuery)) { $statusMessage = "

The maintainer was successfully added into the database

\n"; //delete the item from the queue query_appdb("DELETE from appMaintainerQueue where queueId = ".$iQueueId.";"); $oApp = new Application($iAppId); $oVersion = new Version($iVersionId); //Send Status Email $sEmail = $oUser->sEmail; if ($sEmail) { $sSubject = "Application Maintainer Request Report"; $sMsg = "Your application to be the maintainer of ".$oApp->sName." ".$oVersion->sName." has been accepted. "; $sMsg .= $_REQUEST['replyText']; $sMsg .= "We appreciate your help in making the Application Database better for all users.\n\n"; mail_appdb($sEmail, $sSubject ,$sMsg); } } } else { //delete the item from the queue query_appdb("DELETE from appMaintainerQueue where queueId = ".$iQueueId.";"); if($this->isSuperMaintainer($iAppId) && !$bSuperMaintainer) $statusMessage = "

User is already a super maintainer of this application

\n"; else $statusMessage = "

User is already a maintainer/super maintainer of this application/version

\n"; } return $statusMessage; } /* remove maintainership */ /* if $iAppId and $iVersionId are null, delete all maintainership for this user */ function deleteMaintainer($iAppId = null, $iVersionId = null) { /* remove supermaintainer */ if($iAppId && ($iVersionId == null)) { $superMaintainer = 1; $sQuery = "DELETE FROM appMaintainers WHERE userId = ".$this->iUserId. " AND appId = ".$iAppId." AND superMaintainer = ".$superMaintainer.";"; } else if($iAppId && $iVersionId) /* remove a normal maintainer */ { $superMaintainer = 0; $sQuery = "DELETE FROM appMaintainers WHERE userId = ".$this->iUserId. " AND appId = ".$iAppId." AND versionId = ".$iVersionId." AND superMaintainer = ".$superMaintainer.";"; } else if(($iAppId == null) && ($iVersionId == null)) /* remove all maintainership by this user */ { $sQuery = "DELETE FROM appMaintainers WHERE userId = ".$this->iUserId.";"; } if($sQuery) { if($result = query_appdb($sQuery)) return true; } return false; } /* get the number of queued applications */ function getQueuedAppCount() { /* return 0 because non-admins have no way to process new apps */ if(!$this->hasPriv("admin")) return 0; $qstring = "SELECT count(*) as queued_apps FROM appFamily WHERE queued='true'"; $result = query_appdb($qstring); $ob = mysql_fetch_object($result); return $ob->queued_apps; } function getQueuedVersionCount() { if($this->hasPriv("admin")) { $qstring = "SELECT count(*) as queued_versions FROM appVersion WHERE queued='true'"; } else { /* find all queued versions of applications that the user is a super maintainer of */ $qstring = "SELECT count(*) as queued_versions FROM appVersion, appMaintainers WHERE queued='true' AND appMaintainers.superMaintainer ='1' AND appVersion.appId = appMaintainers.appId AND appMaintainers.userId ='".$this->iUserId."';"; } $result = query_appdb($qstring); $ob = mysql_fetch_object($result); /* we don't want to count the versions that are implicit in the applications */ /* that are in the queue */ return $ob->queued_versions - $this->getQueuedAppCount(); } /* get the number of queued appdata */ function getQueuedAppDataCount() { $hResult = $this->getAppDataQuery(0, true, false); $ob = mysql_fetch_object($hResult); return $ob->queued_appdata; } function addPriv($sPriv) { if(!$this->isLoggedIn() || !$sPriv) return false; if($this->hasPriv($sPriv)) return true; $hResult = query_appdb("INSERT INTO user_privs VALUES ($this->iUserId, '$sPriv')"); return $hResult; } function delPriv($sPriv) { if(!$this->isLoggedIn() || !$sPriv) return false; $hRresult = query_appdb("DELETE FROM user_privs WHERE userid = $this->iUserId AND priv = '$sPriv'"); return $hRresult; } /** * Checks if the current user is valid. */ function isLoggedIn() { return $this->iUserId; } /** * Checks if user should see debugging infos. */ function showDebuggingInfos() { return (($this->isLoggedIn() && $this->getPref("debug") == "yes") || APPDB_DEBUG == 1); } /** * Checks if user wants to get e-mails. */ function wantsEmail() { return ($this->isLoggedIn() && $this->getPref("send_email","yes")=="yes"); } /** * Return an app query based on the user permissions and an iAppDataId * Used to display appropriate appdata entries based upon admin vs. maintainer * as well as to determine if the maintainer has permission to delete an appdata entry */ function getAppDataQuery($iAppDataId, $queryQueuedCount, $queryQueued) { /* either look for queued app data entries */ /* or ones that match the given id */ if($queryQueuedCount) { $selectTerms = "count(*) as queued_appdata"; $additionalTerms = "AND appData.queued='true'"; } else if($queryQueued) { $selectTerms = "appData.*, appVersion.appId AS appId"; $additionalTerms = "AND appData.queued='true'"; } else { $selectTerms = "appData.*, appVersion.appId AS appId"; $additionalTerms = "AND id='".$iAppDataId."'"; } if($this->hasPriv("admin")) { $sQuery = "SELECT ".$selectTerms." FROM appData,appVersion WHERE appVersion.versionId = appData.versionId ".$additionalTerms.";"; } else { /* select versions where we supermaintain the application or where */ /* we maintain the appliation, and where the versions we supermaintain */ /* or maintain are in the appData list */ /* then apply some additional terms */ $sQuery = "select ".$selectTerms." from appMaintainers, appVersion, appData where ( ((appMaintainers.appId = appVersion.appId) AND (appMaintainers.superMaintainer = '1')) OR ((appMaintainers.versionId = appVersion.versionId) AND (appMaintainers.superMaintainer = '0')) ) AND appData.versionId = appVersion.versionId AND appMaintainers.userId = '".$this->iUserId."' ".$additionalTerms.";"; } return query_appdb($sQuery); } /** * Delete appData */ function deleteAppData($iAppDataId) { if(!$_SESSION['current']->canDeleteAppDataId($iAppDataId)) return false; $sQuery = "DELETE from appData where id = ".$iAppDataId." LIMIT 1;"; $hResult = query_appdb($sQuery); if($hResult) return true; return false; } /** * Retrieve the list of applications in the app queue that this user can see */ function getAppQueueQuery($queryAppFamily) { if($this->hasPriv("admin")) { if($queryAppFamily) { $sQuery = "SELECT appFamily.appId FROM appFamily WHERE queued = 'true'"; } else { $sQuery = "SELECT appVersion.versionId FROM appVersion, appFamily WHERE appFamily.appId = appVersion.appId AND appFamily.queued = 'false' AND appVersion.queued = 'true'"; } } else { if($queryAppFamily) { $sQuery = "SELECT appFamily.appId FROM appFamily, appMaintainers WHERE queued = 'true' AND appFamily.appId = appMaintainers.appId AND appMaintainers.superMaintainer = '1' AND appMaintainers.userId = '".$this->iUserId."';"; } else { $sQuery = "SELECT appVersion.versionId FROM appVersion, appFamily, appMaintainers WHERE appFamily.appId = appVersion.appId AND appFamily.queued = 'false' AND appVersion.queued = 'true' AND appFamily.appId = appMaintainers.appId AND appMaintainers.superMaintainer = '1' AND appMaintainers.userId = '".$this->iUserId."';"; } } return query_appdb($sQuery); } function getAppRejectQueueQuery($queryAppFamily) { if($this->hasPriv("admin")) { if($queryAppFamily) { $sQuery = "SELECT appFamily.appId FROM appFamily WHERE queued = 'rejected'"; } else { $sQuery = "SELECT appVersion.versionId FROM appVersion, appFamily WHERE appFamily.appId = appVersion.appId AND appFamily.queued = 'false' AND appVersion.queued = 'rejected'"; } } else { if($queryAppFamily) { $sQuery = "SELECT appFamily.appId FROM appFamily WHERE queued = 'rejected' AND appFamily.submitterId = '".$this->iUserId."';"; } else { $sQuery = "SELECT appVersion.versionId FROM appVersion, appFamily WHERE appFamily.appId = appVersion.appId AND appFamily.queued = 'false' AND appVersion.queued = 'rejected' AND appVersion.submitterId = '".$this->iUserId."';"; } } return query_appdb($sQuery); } function getAllRejectedApps() { $result = query_appdb("SELECT appVersion.versionId, appFamily.appId FROM appVersion, appFamily WHERE appFamily.appId = appVersion.appId AND (appFamily.queued = 'rejected' OR appVersion.queued = 'rejected') AND appVersion.submitterId = '".$this->iUserId."';"); if(!$result || mysql_num_rows($result) == 0) return; $retval = array(); $c = 0; while($row = mysql_fetch_object($result)) { $retval[$c] = array($row->appId, $row->versionId); $c++; } return $retval; } function isAppSubmitter($iAppId) { $sQuery = "SELECT appId FROM appFamily WHERE submitterId = '".$this->iUserId."' AND appId = '".$iAppId."';"; $hResult = query_appdb($sQuery); if(mysql_num_rows($hResult)) return true; else return false; } function isVersionSubmitter($iVersionId) { $sQuery = "SELECT appVersion.versionId FROM appVersion, appFamily WHERE appFamily.appId = appVersion.appId AND appVersion.submitterId = '".$this->iUserId."' AND appVersion.versionId = '".$iVersionId."';"; $hResult = query_appdb($sQuery); if(mysql_num_rows($hResult)) return true; else return false; } /* if this user has data associated with them we will return true */ /* otherwise we return false */ function hasDataAssociated() { $sQuery = "SELECT count(userId) as c FROM appComments WHERE userId = $this->iUserId"; $hResult = query_appdb($sQuery); $ob = mysql_fetch_object($hResult); if($ob->c != 0) return true; $sQuery = "SELECT count(userId) as c FROM appMaintainers WHERE userId = $this->iUserId"; $hResult = query_appdb($sQuery); $ob = mysql_fetch_object($hResult); if($ob->c != 0) return true; $sQuery = "SELECT count(userId) as c FROM appVotes WHERE userId = $this->iUserId"; $hResult = query_appdb($sQuery); $ob = mysql_fetch_object($hResult); if($ob->c != 0) return true; return false; } /* warn the user that their account has been marked as inactive */ function warnForInactivity() { /* we don't want to warn users that have data associated with them */ if($this->hasDataAssociated()) { return false; } if($this->isMaintainer()) { $sSubject = "Warning: inactivity detected"; $sMsg = "You didn't log in in the past six month to the AppDB.\r\n"; $sMsg .= "As a maintainer we would be pleased to see you once in a while.\r\n"; $sMsg .= "Please log in or you will lose your maintainer's abilities in one month.\r\n"; } else { $sSubject = "Warning: inactivity detected"; $sMsg = "You didn't log in in the past six month to the AppDB.\r\n"; $sMsg .= "Please log in or your account will automatically be deleted in one month.\r\n"; } mail_appdb($this->sEmail, $sSubject, $sMsg); /* mark this user as being inactive and set the appropriate timestamp */ $sQuery = "update user_list set inactivity_warned='true', inactivity_warn_stamp=NOW() where userid=".$this->iUserId; query_appdb($sQuery); return true; } /************************/ /* Permission functions */ /************************/ function canDeleteCategory($oCategory) { if($this->hasPriv("admin")) return true; return false; } /** * Returns true or false depending on whether the user can view the image */ function canViewImage($iImageId) { $oScreenshot = new Screenshot($iImageId); if(!$oScreenshot->bQueued || ($oScreenshot->bQueued && ($this->hasPriv("admin") || $this->isMaintainer($oScreenshot->iVersionId) || $this->isSuperMaintainer($oScreenshot->iAppId)))) return true; return false; } function canDeleteAppDataId($iAppDataId) { /* admins can delete anything */ if($this->hasPriv("admin")) return true; $isMaintainer = false; /* if we aren't an admin we should see if we can find any results */ /* for a query based on this appDataId, if we can then */ /* we have permission to delete the entry */ $hResult = $this->getAppDataQuery($iAppDataId, false, false); if(!$hResult) return false; if(mysql_num_rows($hResult) > 0) $isMaintainer = true; /* if this user maintains the app data, they can delete it */ if($isMaintainer) return true; return false; } /***************************/ /* application permissions */ function canViewApplication($oApp) { /* if the application isn't queued */ if($oApp->sQueued == 'false') return true; if($this->hasPriv("admin")) return true; /* if this user is the submitter and the application is queued */ if(($this->iUserId == $oApp->iSubmitterId) && ($oApp->sQueued != 'false')) return true; return false; } /** * Does the user have permission to modify this application? */ function canModifyApplication($oApp) { if($this->hasPriv("admin")) return true; /* is this user a super maintainer of this app? */ if($this->isSuperMaintainer($oApp->iAppId)) return true; /* if the user is the submitter of the application */ /* and the application is still queued */ /* the user can modify the app */ if(($this->iUserId == $oApp->iSubmitterId) && ($oApp->sQueued != 'false')) return true; return false; } /** * Can this user create applications? */ function canCreateApplication() { return $this->isLoggedIn(); } /** * Returns 'true' if the current user has the permission to delete * this application, 'false' otherwise */ function canDeleteApplication($oApp) { if($this->hasPriv("admin")) return true; /* is this the user that submitted the application and is still queued */ if(($oApp->sQueued != 'false') && ($oApp->iSubmitterId == $this->iUserId)) return true; return false; } /* Can this user unQueue applications? */ function canUnQueueApplication() { return $this->hasPriv("admin"); } /* Can this user Requeue an application? */ function canRequeueApplication($oApp) { if($oApp->sQueued == 'false') return false; if($this->hasPriv("admin")) return true; if(($oApp->sQueued != 'false') && ($oApp->iSubmitterId == $this->iUserId)) return true; return false; } /* Can the user reject application? */ function canRejectApplication() { return $this->hasPriv("admin"); } /** * Does the created application have to be queued for admin processing? */ function appCreatedMustBeQueued() { return !$this->hasPriv("admin"); } /***********************/ /* version permissions */ function canViewVersion($oVersion) { /* if the version isn't queued */ if($oVersion->sQueued == 'false') return true; if($this->hasPriv("admin")) return true; /* if the user is the submitter and the version is still queued */ if(($this->iUserId == $oVersion->iSubmitterId) && ($oVersion->sQueued != 'false')) return true; /* if this user supermaintains the application this version belongs to */ if($this->isSupermaintainer($oVersion->iAppId)) return true; return false; } /** * Does the user have permission to modify on this version? */ function hasAppVersionModifyPermission($oVersion) { if(!$this->isLoggedIn()) return false; if($this->hasPriv("admin")) return true; if($this->isSuperMaintainer($oVersion->iAppId)) return true; if($this->isMaintainer($oVersion->iVersionId)) return true; /* the version is queued and the user is the submitter */ if(($oVersion->sQueued != 'false') && ($this->iUserId == $oVersion->iSubmitterId)) return true; return false; } /** * Can this user create a version? */ function canCreateVersion() { return $this->isLoggedIn(); } function versionCreatedMustBeQueued($oVersion) { if($this->hasPriv("admin")) return false; if($this->isSupermaintainer($oVersion->iAppId)) return false; return true; } /** * Returns 'true' if the current user has the permission to delete * this version, 'false' otherwise */ function canDeleteVersion($oVersion) { if($this->hasPriv("admin")) return true; /* if the app is anything other than not queued and if the user is the submitter */ /* then allow the user to delete the app */ if(($oVersion->sQueued != 'false') && ($oVersion->iSubmitterId == $this->iUserId)) return true; /* is this user a supermaintainer of the application this version is under? */ if($this->isSuperMaintainer($oVersion->iAppId)) return true; return false; } /** * Can the user unqueue this version? */ function canUnQueueVersion($oVersion) { if($this->hasPriv("admin")) return true; if($this->hasAppVersionModifyPermission($oVersion)) return true; return false; } /** * Can the user reject this version? */ function canRejectVersion($oVersion) { if($this->hasPriv("admin")) return true; if($this->hasAppVersionModifyPermission($oVersion)) return true; return false; } /** * Can the user reject this version? */ function canRequeueVersion($oVersion) { if($this->hasPriv("admin")) return true; if($this->hasAppVersionModifyPermission($oVersion)) return true; if(($this->iUserId == $oVersion->iSubmitterId) && ($oVersion->sQueued != 'false')) return true; return false; } } /* * User functions that are not part of the class */ /** * Creates a new random password. */ function generate_passwd($pass_len = 10) { $nps = ""; mt_srand ((double) microtime() * 1000000); while (strlen($nps)<$pass_len) { $c = chr(mt_rand (0,255)); if (eregi("^[a-z0-9]$", $c)) $nps = $nps.$c; } return ($nps); } /** * Get the email address of people to notify for this appId and versionId. */ function get_notify_email_address_list($iAppId = null, $iVersionId = null) { $aUserId = array(); $c = 0; $retval = ""; /* * Retrieve version maintainers. */ /* * If versionId was supplied we fetch supermaintainers of application and maintainer of version. */ if($iVersionId) { $sQuery = "SELECT appMaintainers.userId FROM appMaintainers, appVersion WHERE appVersion.appId = appMaintainers.appId AND appVersion.versionId = '".$iVersionId."'"; } /* * If versionId was not supplied we fetch supermaintainers of application and maintainer of all versions. */ elseif($iAppId) { $sQuery = "SELECT userId FROM appMaintainers WHERE appId = '".$iAppId."'"; } if($sQuery) { $hResult = query_appdb($sQuery); if(mysql_num_rows($hResult) > 0) { while($oRow = mysql_fetch_object($hResult)) { $aUserId[$c] = array($oRow->userId); $c++; } } } /* * Retrieve version Monitors. */ /* * If versionId was supplied we fetch superMonitors of application and Monitors of version. */ if($iVersionId) { $sQuery = "SELECT appMonitors.userId FROM appMonitors, appVersion WHERE appVersion.appId = appMonitors.appId AND appVersion.versionId = '".$iVersionId."'"; } /* * If versionId was not supplied we fetch superMonitors of application and Monitors of all versions. */ elseif($iAppId) { $sQuery = "SELECT userId FROM appMonitors WHERE appId = '".$iAppId."'"; } if($sQuery) { $hResult = query_appdb($sQuery); if(mysql_num_rows($hResult) > 0) { while($oRow = mysql_fetch_object($hResult)) { $aUserId[$c] = array($oRow->userId); $c++; } } } /* * Retrieve administrators. */ $hResult = query_appdb("SELECT * FROM user_privs WHERE priv = 'admin'"); if(mysql_num_rows($hResult) > 0) { while($oRow = mysql_fetch_object($hResult)) { $i = array_search($oRow->userid, $aUserId); if ($aUserId[$i] != array($oRow->userid)) { $aUserId[$c] = array($oRow->userid); $c++; } } } if ($c > 0) { while(list($index, list($userIdValue)) = each($aUserId)) { $oUser = new User($userIdValue); if ($oUser->wantsEmail()) $retval .= $oUser->sEmail." "; } } return $retval; } /** * Get the number of users in the database */ function get_number_of_users() { $result = query_appdb("SELECT count(*) as num_users FROM user_list;"); $row = mysql_fetch_object($result); return $row->num_users; } /** * Get the number of active users within $days of the current day */ function get_active_users_within_days($days) { $result = query_appdb("SELECT count(*) as num_users FROM user_list WHERE stamp >= DATE_SUB(CURDATE(), interval $days day);"); $row = mysql_fetch_object($result); return $row->num_users; } /** * Get the count of users who have been warned for inactivity and are * pending deletion after the X month grace period */ function get_inactive_users_pending_deletion() { /* retrieve the number of users that have been warned and are pending deletion */ $sQuery = "select count(*) as count from user_list where inactivity_warned = 'true'"; $hResult = query_appdb($sQuery); $oRow = mysql_fetch_object($hResult); return $oRow->count; } /** * Check if a user exists. * returns the userid if the user exists */ function user_exists($sEmail) { $result = query_appdb("SELECT userid FROM user_list WHERE email = '$sEmail'"); if(!$result || mysql_num_rows($result) != 1) return 0; else { $oRow = mysql_fetch_object($result); return $oRow->userid; } } ?>