diff --git a/account.php b/account.php
index 4f93af9..dbb1ed1 100644
--- a/account.php
+++ b/account.php
@@ -152,8 +152,8 @@ function cmd_send_passwd()
$note = '(Note: accounts for appdb.winehq.org and bugs.winehq.org '
.'are separated, so You might need to create second account for appdb.)';
- $userid = user_exists($aClean['ext_email']);
- $passwd = generate_passwd();
+ $userid = User::exists($aClean['ext_email']);
+ $passwd = User::generate_passwd();
$user = new User($userid);
if ($userid)
{
diff --git a/admin/adminAppDataQueue.php b/admin/adminAppDataQueue.php
index 1a3ee23..06b4802 100644
--- a/admin/adminAppDataQueue.php
+++ b/admin/adminAppDataQueue.php
@@ -123,7 +123,7 @@ if (!$aClean['id'])
echo '
';
$imgSRC = ' ';
// generate random tag for popup window
- $randName = generate_passwd(5);
+ $randName = User::generate_passwd(5);
// set image link based on user pref
$img = ''.$imgSRC.'';
if ($_SESSION['current']->isLoggedIn())
diff --git a/appdbStats.php b/appdbStats.php
index 26e1849..ece938d 100644
--- a/appdbStats.php
+++ b/appdbStats.php
@@ -15,37 +15,37 @@ echo "\n\n";
/* Display the number of users */
echo "\n";
echo " | Users: | \n";
-echo " ".get_number_of_users()." | \n";
+echo " ".User::count()." | \n";
echo " \n\n";
/* Display the active users in the last 30 days */
echo "\n";
echo " | Users active within the last 30 days: | \n";
-echo " ".get_active_users_within_days(30)." | \n";
+echo " ".User::active_users_within_days(30)." | \n";
echo " \n\n";
/* Display the active users in the last 60 days */
echo "\n";
echo " | Users active within the last 60 days: | \n";
-echo " ".get_active_users_within_days(60)." | \n";
+echo " ".User::active_users_within_days(60)." | \n";
echo " \n\n";
/* Display the active users in the last 90 days */
echo "\n";
echo " | Users active within the last 90 days: | \n";
-echo " ".get_active_users_within_days(90)." | \n";
+echo " ".User::active_users_within_days(90)." | \n";
echo " \n\n";
/* Display the inactive users */
echo "\n";
echo " | Inactive users (not logged in since six months): | \n";
-echo " ".(get_number_of_users()-get_active_users_within_days(183))." | \n";
+echo " ".(User::count()-User::active_users_within_days(183))." | \n";
echo " \n\n";
/* Display the users who were warned and pending deletion */
echo "\n";
echo " | Inactive users pending deletion: | \n";
-echo " ".get_inactive_users_pending_deletion()." | \n";
+echo " ".User::get_inactive_users_pending_deletion()." | \n";
echo " \n\n";
/* Display the number of comments */
diff --git a/cron/cleanup.php b/cron/cleanup.php
index 1754b82..d5ea492 100644
--- a/cron/cleanup.php
+++ b/cron/cleanup.php
@@ -114,7 +114,7 @@ function notifyAdminsOfCleanupStart()
{
$sSubject = "Cleanup script starting\r\n";
$sMsg = "Appdb cleanup cron script started.\r\n";
- $sEmail = get_notify_email_address_list(null, null); /* get list admins */
+ $sEmail = User::get_notify_email_address_list(null, null); /* get list admins */
if($sEmail)
mail_appdb($sEmail, $sSubject, $sMsg);
}
@@ -124,7 +124,7 @@ function notifyAdminsOfCleanupStart()
/* events of the appdb */
function notifyAdminsOfCleanupExecution($usersWarned, $usersUnwarnedWithData, $usersDeleted, $usersWithData)
{
- $warnedUsers = get_inactive_users_pending_deletion();
+ $warnedUsers = User::get_inactive_users_pending_deletion();
$sSubject = "Cleanup script summary\r\n";
$sMsg = "Appdb cleanup cron script executed.\r\n";
@@ -135,7 +135,7 @@ function notifyAdminsOfCleanupExecution($usersWarned, $usersUnwarnedWithData, $u
$sMsg .= "Warned users pending deletion:".$warnedUsers."\r\n";
$sMsg .= "Users deleted:".$usersDeleted."\r\n";
$sMsg .= "Users pending deletion but have appdb data:".$usersWithData."\r\n";
- $sEmail = get_notify_email_address_list(null, null); /* get list admins */
+ $sEmail = User::get_notify_email_address_list(null, null); /* get list admins */
if($sEmail)
mail_appdb($sEmail, $sSubject, $sMsg);
}
@@ -163,7 +163,7 @@ function orphanVersionCheck()
$sSubject = "Versions orphaned in the database\r\n";
- $sEmail = get_notify_email_address_list(null, null); /* get list admins */
+ $sEmail = User::get_notify_email_address_list(null, null); /* get list admins */
if($sEmail)
mail_appdb($sEmail, $sSubject, $sMsg);
}
diff --git a/include/application.php b/include/application.php
index 10e0632..7193dd3 100644
--- a/include/application.php
+++ b/include/application.php
@@ -415,7 +415,7 @@ class Application {
addmsg("Application rejected.", "green");
break;
}
- $sEmail = get_notify_email_address_list($this->iAppId);
+ $sEmail = User::get_notify_email_address_list($this->iAppId);
if($sEmail)
mail_appdb($sEmail, $sSubject ,$sMsg);
}
diff --git a/include/bugs.php b/include/bugs.php
index 82df236..0b82036 100644
--- a/include/bugs.php
+++ b/include/bugs.php
@@ -245,7 +245,7 @@ class Bug {
addmsg("Bug Link deleted.", "green");
}
- $sEmail = get_notify_email_address_list(null, $this->iVersionId);
+ $sEmail = User::get_notify_email_address_list(null, $this->iVersionId);
if($sEmail)
{
mail_appdb($sEmail, $sSubject ,$sMsg);
diff --git a/include/comment.php b/include/comment.php
index 2fc511e..373910a 100644
--- a/include/comment.php
+++ b/include/comment.php
@@ -61,7 +61,7 @@ class Comment {
if($hResult)
{
$this->comment(mysql_insert_id());
- $sEmail = get_notify_email_address_list($this->iAppId, $this->iVersionId);
+ $sEmail = User::get_notify_email_address_list($this->iAppId, $this->iVersionId);
$sEmail .= $this->oOwner->sEmail." ";
// fetches e-mails from parent comments, all parents are notified that a
@@ -161,7 +161,7 @@ class Comment {
/* fixup the child comments so the parentId points to a valid parent comment */
$hResult = query_parameters("UPDATE appComments set parentId = '?' WHERE parentId = '?'",
$this->iParentId, $this->iCommentId);
- $sEmail = get_notify_email_address_list($this->iAppId, $this->iVersionId);
+ $sEmail = User::get_notify_email_address_list($this->iAppId, $this->iVersionId);
$sEmail .= $this->oOwner->sEmail;
if($sEmail)
{
diff --git a/include/distributions.php b/include/distributions.php
index 28f429b..81422ac 100644
--- a/include/distributions.php
+++ b/include/distributions.php
@@ -356,7 +356,7 @@ class distribution{
addmsg("Distribution rejected.", "green");
break;
}
- $sEmail = get_notify_email_address_list(null, null);
+ $sEmail = User::get_notify_email_address_list(null, null);
if($sEmail)
mail_appdb($sEmail, $sSubject ,$sMsg);
}
diff --git a/include/monitor.php b/include/monitor.php
index 4c9ede9..23f6880 100644
--- a/include/monitor.php
+++ b/include/monitor.php
@@ -126,7 +126,7 @@ class Monitor {
}
break;
}
- $sEmail = get_notify_email_address_list(null, $this->iVersionId);
+ $sEmail = User::get_notify_email_address_list(null, $this->iVersionId);
if($sEmail)
mail_appdb($sEmail, $sSubject ,$sMsg);
}
diff --git a/include/note.php b/include/note.php
index 51d3001..4511dff 100644
--- a/include/note.php
+++ b/include/note.php
@@ -153,7 +153,7 @@ class Note {
addmsg("Note deleted.", "green");
break;
}
- $sEmail = get_notify_email_address_list(null, $this->iVersionId);
+ $sEmail = User::get_notify_email_address_list(null, $this->iVersionId);
if($sEmail)
mail_appdb($sEmail, $sSubject ,$sMsg);
}
diff --git a/include/screenshot.php b/include/screenshot.php
index 622c067..b12c05b 100644
--- a/include/screenshot.php
+++ b/include/screenshot.php
@@ -288,7 +288,7 @@ class Screenshot {
addmsg("Screenshot deleted.", "green");
}
- $sEmail = get_notify_email_address_list(null, $this->iVersionId);
+ $sEmail = User::get_notify_email_address_list(null, $this->iVersionId);
if($sEmail)
mail_appdb($sEmail, $sSubject ,$sMsg);
}
@@ -404,7 +404,7 @@ function get_thumbnail($id)
$oScreenshot = new Screenshot($id);
// generate random tag for popup window
- $randName = generate_passwd(5);
+ $randName = User::generate_passwd(5);
// set img tag
$imgSRC = ' iVersionId);
+ $sEmail = User::get_notify_email_address_list(null, $this->iVersionId);
if($sEmail)
mail_appdb($sEmail, $sSubject ,$sMsg);
}
diff --git a/include/url.php b/include/url.php
index e2ddd26..9e3ab18 100644
--- a/include/url.php
+++ b/include/url.php
@@ -233,7 +233,7 @@ class Url {
addmsg("Url deleted.", "green");
}
- $sEmail = get_notify_email_address_list(null, $this->iVersionId);
+ $sEmail = User::get_notify_email_address_list(null, $this->iVersionId);
if($sEmail)
mail_appdb($sEmail, $sSubject ,$sMsg);
}
diff --git a/include/user.php b/include/user.php
index 373b02c..06f0e76 100644
--- a/include/user.php
+++ b/include/user.php
@@ -87,7 +87,7 @@ class User {
*/
function create($sEmail, $sPassword, $sRealname, $sWineRelease)
{
- if(user_exists($sEmail))
+ if(User::exists($sEmail))
{
return USER_CREATE_EXISTS;
} else
@@ -120,7 +120,7 @@ class User {
if($this->sEmail && ($this->sEmail != $oUser->sEmail))
{
/* make sure this email isn't already in use */
- if(user_exists($this->sEmail))
+ if(User::exists($this->sEmail))
{
addMsg("An account with this e-mail exists already.","red");
return USER_UPDATE_FAILED_EMAIL_EXISTS;
@@ -725,8 +725,181 @@ class User {
}
+ /**
+ * 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);
+ }
+ /**
+ * Check if a user exists.
+ * returns the userid if the user exists
+ */
+ function exists($sEmail)
+ {
+ $hResult = query_parameters("SELECT userid FROM user_list WHERE email = '?'",
+ $sEmail);
+ if(!$hResult || mysql_num_rows($hResult) != 1)
+ {
+ return 0;
+ } else
+ {
+ $oRow = mysql_fetch_object($hResult);
+ return $oRow->userid;
+ }
+ }
+ /**
+ * Get the number of users in the database
+ */
+ function count()
+ {
+ $hResult = query_parameters("SELECT count(*) as num_users FROM user_list;");
+ $oRow = mysql_fetch_object($hResult);
+ return $oRow->num_users;
+ }
+
+ /**
+ * Get the number of active users within $days of the current day
+ */
+ function active_users_within_days($days)
+ {
+ $hResult = query_parameters("SELECT count(*) as num_users FROM user_list WHERE stamp >= DATE_SUB(CURDATE(), interval '?' day);",
+ $days);
+ $oRow = mysql_fetch_object($hResult);
+ return $oRow->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 */
+ $hResult = query_parameters("select count(*) as count from user_list where inactivity_warned = 'true'");
+ $oRow = mysql_fetch_object($hResult);
+ return $oRow->count;
+ }
+
+ /**
+ * 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)
+ {
+ $hResult = query_parameters("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)
+ {
+ $hResult = query_parameters("SELECT userId
+ FROM appMaintainers
+ WHERE appId = '?'",
+ $iAppId);
+ }
+
+ if($hResult)
+ {
+ 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)
+ {
+ $hResult = query_parameters("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)
+ {
+ $hResult = query_parameters("SELECT userId
+ FROM appMonitors
+ WHERE appId = '?'",
+ $iAppId);
+ }
+ if($hResult)
+ {
+ if(mysql_num_rows($hResult) > 0)
+ {
+ while($oRow = mysql_fetch_object($hResult))
+ {
+ $aUserId[$c] = array($oRow->userId);
+ $c++;
+ }
+ }
+ }
+
+ /*
+ * Retrieve administrators.
+ */
+ $hResult = query_parameters("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;
+ }
/************************/
@@ -1019,188 +1192,4 @@ class User {
}
}
-
-/*
- * 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)
- {
- $hResult = query_parameters("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)
- {
- $hResult = query_parameters("SELECT userId
- FROM appMaintainers
- WHERE appId = '?'",
- $iAppId);
- }
-
- if($hResult)
- {
- 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)
- {
- $hResult = query_parameters("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)
- {
- $hResult = query_parameters("SELECT userId
- FROM appMonitors
- WHERE appId = '?'",
- $iAppId);
- }
- if($hResult)
- {
- if(mysql_num_rows($hResult) > 0)
- {
- while($oRow = mysql_fetch_object($hResult))
- {
- $aUserId[$c] = array($oRow->userId);
- $c++;
- }
- }
- }
-
- /*
- * Retrieve administrators.
- */
- $hResult = query_parameters("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()
-{
- $hResult = query_parameters("SELECT count(*) as num_users FROM user_list;");
- $oRow = mysql_fetch_object($hResult);
- return $oRow->num_users;
-}
-
-
-/**
- * Get the number of active users within $days of the current day
- */
-function get_active_users_within_days($days)
-{
- $hResult = query_parameters("SELECT count(*) as num_users FROM user_list WHERE stamp >= DATE_SUB(CURDATE(), interval '?' day);",
- $days);
- $oRow = mysql_fetch_object($hResult);
- return $oRow->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 */
- $hResult = query_parameters("select count(*) as count from user_list where inactivity_warned = 'true'");
- $oRow = mysql_fetch_object($hResult);
- return $oRow->count;
-}
-
-/**
- * Check if a user exists.
- * returns the userid if the user exists
- */
-function user_exists($sEmail)
-{
- $hResult = query_parameters("SELECT userid FROM user_list WHERE email = '?'",
- $sEmail);
- if(!$hResult || mysql_num_rows($hResult) != 1)
- {
- return 0;
- } else
- {
- $oRow = mysql_fetch_object($hResult);
- return $oRow->userid;
- }
-}
?>
diff --git a/include/util.php b/include/util.php
index db98c90..e9c6881 100644
--- a/include/util.php
+++ b/include/util.php
@@ -649,8 +649,8 @@ function process_app_version_changes($isVersion)
}
if ($bAppChanged)
{
- $sEmail = get_notify_email_address_list($_REQUEST['appId']);
- $oApp = new Application($_REQUEST['appId']);
+ $sEmail = User::get_notify_email_address_list($_REQUEST['appId']);
+ $oApp = new Application($_REQUEST['appId']);
if($sEmail)
{
if($isVersion)
diff --git a/include/version.php b/include/version.php
index 009b64b..229be4e 100644
--- a/include/version.php
+++ b/include/version.php
@@ -514,7 +514,7 @@ class Version {
addmsg("Version rejected.", "green");
break;
}
- $sEmail = get_notify_email_address_list(null, $this->iVersionId);
+ $sEmail = User::get_notify_email_address_list(null, $this->iVersionId);
if($sEmail)
mail_appdb($sEmail, $sSubject ,$sMsg);
}
|