This repository has been archived on 2025-05-24. You can view files and clone it, but cannot push or open issues or pull requests.
Files
qemudb/include/user.php

1141 lines
35 KiB
PHP
Raw Normal View History

<?php
/************************************/
/* user class and related functions */
/************************************/
2004-03-15 16:22:00 +00:00
require_once(BASE."include/version.php");
2004-03-15 16:22:00 +00:00
/**
* User class for handling users
*/
class User {
var $iUserId;
var $sEmail;
var $sRealname;
var $sStamp;
var $sDateCreated;
var $sWineRelease;
var $bInactivityWarned;
2004-03-15 16:22:00 +00:00
/**
* Constructor.
* If $iUserId is provided, logs in user.
2004-03-15 16:22:00 +00:00
*/
function User($iUserId="")
2004-03-15 16:22:00 +00:00
{
$this->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();
2004-03-15 16:22:00 +00:00
}
/**
* Logs in an user using e-mail and password.
2004-03-15 16:22:00 +00:00
*/
function login($sEmail, $sPassword)
2004-03-15 16:22:00 +00:00
{
$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;
2004-03-15 16:22:00 +00:00
}
2004-03-15 16:22:00 +00:00
/*
* Creates a new user.
* returns true on success, false on failure
2004-03-15 16:22:00 +00:00
*/
function create($sEmail, $sPassword, $sRealname, $sWineRelease)
2004-03-15 16:22:00 +00:00
{
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 ));
2005-01-08 18:38:29 +00:00
$sFields = "({$aInsert['FIELDS']}, `password`, `stamp`, `created`)";
$sValues = "({$aInsert['VALUES']}, password('".$sPassword."'), NOW(), NOW() )";
2005-01-08 18:38:29 +00:00
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;
}
2004-03-15 16:22:00 +00:00
}
/**
* Update User Account;
*/
function update($sEmail = null, $sPassword = null, $sRealname = null, $sWineRelease = null)
2004-03-15 16:22:00 +00:00
{
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;
2004-03-15 16:22:00 +00:00
}
/**
* Removes the current, or specified user and preferences from the database.
* returns true on success and false on failure.
2004-03-15 16:22:00 +00:00
*/
function delete()
2004-03-15 16:22:00 +00:00
{
if(!$this->isLoggedIn()) return false;
2005-02-14 18:20:48 +00:00
$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."'");
2005-02-14 18:20:48 +00:00
return($hResult = query_appdb("DELETE FROM user_list WHERE userid = '".$this->iUserId."'"));
2004-03-15 16:22:00 +00:00
}
/**
* Get a preference for the current user.
*/
function getPref($sKey, $sDef = null)
2004-03-15 16:22:00 +00:00
{
if(!$this->isLoggedIn() || !$sKey)
return $sDef;
2004-03-15 16:22:00 +00:00
$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;
2004-03-15 16:22:00 +00:00
}
/**
* Set a preference for the current user.
*/
function setPref($sKey, $sValue)
2004-03-15 16:22:00 +00:00
{
if(!$this->isLoggedIn() || !$sKey || !$sValue)
return false;
2004-03-15 16:22:00 +00:00
$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;
2004-03-15 16:22:00 +00:00
}
/**
* Check if this user has $priv.
2004-03-15 16:22:00 +00:00
*/
function hasPriv($sPriv)
2004-03-15 16:22:00 +00:00
{
if(!$this->isLoggedIn() || !$sPriv)
return false;
2004-03-15 16:22:00 +00:00
$hResult = query_appdb("SELECT * FROM user_privs WHERE userid = ".$this->iUserId." AND priv = '".$sPriv."'");
if(!$hResult)
return false;
return mysql_num_rows($hResult);
2004-03-15 16:22:00 +00:00
}
/**
* 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 = "<p>The maintainer was successfully added into the database</p>\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 = "<p>User is already a super maintainer of this application</p>\n";
else
$statusMessage = "<p>User is already a maintainer/super maintainer of this application/version</p>\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)
2004-03-15 16:22:00 +00:00
{
if(!$this->isLoggedIn() || !$sPriv)
return false;
2004-03-15 16:22:00 +00:00
if($this->hasPriv($sPriv))
return true;
2004-03-15 16:22:00 +00:00
$hResult = query_appdb("INSERT INTO user_privs VALUES ($this->iUserId, '$sPriv')");
return $hResult;
2004-03-15 16:22:00 +00:00
}
function delPriv($sPriv)
2004-03-15 16:22:00 +00:00
{
if(!$this->isLoggedIn() || !$sPriv)
return false;
2004-03-15 16:22:00 +00:00
$hRresult = query_appdb("DELETE FROM user_privs WHERE userid = $this->iUserId AND priv = '$sPriv'");
return $hRresult;
2004-03-15 16:22:00 +00:00
}
/**
* Checks if the current user is valid.
*/
function isLoggedIn()
{
return $this->iUserId;
}
2004-03-15 16:22:00 +00:00
/**
* 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 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()
{
return $this->hasPriv("admin");
}
/* 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->hasPriv("admin"))
return true;
$sQuery = "SELECT appVersion.versionId FROM appVersion, appFamily, appMaintainers
WHERE appFamily.appId = appVersion.appId
AND appFamily.appId = appMaintainers.appId
AND appMaintainers.superMaintainer = '1'
AND appMaintainers.userId = '".$this->iUserId."'
AND appVersion.versionId = '".$oVersion->iVersionId."';";
$hResult = query_appdb($sQuery);
if(mysql_num_rows($hResult))
return true;
else
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->iVersionId))
return true;
return false;
}
/**
* Can the user reject this version?
*/
function canRejectVersion($oVersion)
{
if($this->hasPriv("admin"))
return true;
if($this->hasAppVersionModifyPermission($oVersion->iVersionId))
return true;
return false;
}
/**
* Can the user reject this version?
*/
function canRequeueVersion($oVersion)
{
if($this->hasPriv("admin"))
return true;
if($this->hasAppVersionModifyPermission($oVersion->iVersionId))
return true;
if(($this->iUserId == $oVersion->iSubmitterId) &&
($oVersion->sQueued != 'false'))
return true;
return false;
}
2004-03-15 16:22:00 +00:00
}
/*
* User functions that are not part of the class
*/
/**
* Creates a new random password.
*/
2004-03-15 16:22:00 +00:00
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.
2005-02-06 22:34:43 +00:00
* returns the userid if the user exists
*/
function user_exists($sEmail)
{
2005-02-06 22:34:43 +00:00
$result = query_appdb("SELECT userid FROM user_list WHERE email = '$sEmail'");
if(!$result || mysql_num_rows($result) != 1)
return 0;
2005-02-06 22:34:43 +00:00
else
{
$oRow = mysql_fetch_object($result);
return $oRow->userid;
}
}
2004-03-15 16:22:00 +00:00
?>