Various small fixes for url class. Add silent parameters for create() and update(). Add and use

canEdit(). Fix queue status on create().
This commit is contained in:
Alexander Nicolaysen Sørnes
2007-01-19 01:40:17 +00:00
committed by WineHQ
parent dc963e6780
commit 55ba752151

View File

@@ -49,32 +49,35 @@ class Url {
/** /**
* Creates a new url. * Creates a new url.
*/ */
function create($sDescription = null, $sUrl = null, $iVersionId = null, $iAppId = null) function create($sDescription = null, $sUrl = null, $iVersionId = null, $iAppId = null, $bSilent = false)
{ {
global $aClean; global $aClean;
// Security, if we are not an administrator or a maintainer, the url must be queued. // Security, if we are not an administrator or a maintainer, the url must be queued.
if(!($_SESSION['current']->hasPriv("admin") || $_SESSION['current']->isMaintainer($aClean['iVersionId']) || $_SESSION['current']->isSupermaintainer($aClean['iAppId']))) if(($iAppId && !url::canEdit(NULL, $iAppId)) ||
{ ($iVersionId && !url::canEdit($iVersionId)))
$this->bQueued = true; $this->bQueued = true;
}
$hResult = query_parameters("INSERT INTO appData (appId, versionId, type, description,". $hResult = query_parameters("INSERT INTO appData (appId, versionId, type,
"queued, submitterId) VALUES ('?', '?', '?', '?', '?', '?')", description, queued, submitterId, url)
$iAppId, $iVersionId, "url", $sDescription, $this->bQueued, VALUES ('?', '?', '?', '?', '?', '?', '?')",
$_SESSION['current']->iUserId); $iAppId, $iVersionId, "url", $sDescription,
if($hResult) $this->bQueued ? "true" : "false",
{ $_SESSION['current']->iUserId, $sUrl);
$this->iUrlId = mysql_insert_id();
$this->url($this->iUrlId,$this->bQueued); if(!$hResult)
$this->SendNotificationMail();
return true;
}
else
{ {
addmsg("Error while creating a new url.", "red"); addmsg("Error while creating a new url.", "red");
return false; return false;
} }
$this->iUrlId = mysql_insert_id();
$this->url($this->iUrlId,$this->bQueued);
if(!$bSilent)
$this->SendNotificationMail();
return true;
} }
@@ -88,15 +91,19 @@ class Url {
WHERE id = '?' WHERE id = '?'
AND type = 'url' AND type = 'url'
LIMIT 1"; LIMIT 1";
if($hResult = query_parameters($sQuery, $this->iUrlId)) if(!$hResult = query_parameters($sQuery, $this->iUrlId))
{ return false;
if(!$bSilent)
$this->SendNotificationMail(true); if(!$bSilent)
} $this->SendNotificationMail(true);
if($this->iSubmitterId)
if($this->iSubmitterId &&
$this->iSubmitterId != $_SESSION['current']->iUserId)
{ {
$this->mailSubmitter(true); $this->mailSubmitter(true);
} }
return true;
} }
@@ -125,8 +132,12 @@ class Url {
* Update url. * Update url.
* Returns true on success and false on failure. * Returns true on success and false on failure.
*/ */
function update($sDescription = null, $sUrl = null, $iVersionId = null, $iAppId = null) function update($sDescription = null, $sUrl = null, $iVersionId = null, $iAppId = null, $bSilent = false)
{ {
if(!$this->iUrlId)
return FALSE;
$sWhatChanged = ""; $sWhatChanged = "";
if ($sDescription && $sDescription!=$this->sDescription) if ($sDescription && $sDescription!=$this->sDescription)
@@ -140,8 +151,8 @@ class Url {
if ($sUrl && $sUrl!=$this->sUrl) if ($sUrl && $sUrl!=$this->sUrl)
{ {
if (!query_parameters("UPDATE appData SET noteDesc = '?' WHERE id = '?'", if (!query_parameters("UPDATE appData SET url = '?' WHERE id = '?'",
$sDescription, $this->iUrlId)) $sUrl, $this->iUrlId))
return false; return false;
$sWhatChanged .= "Url was changed from ".$this->sUrl." to ".$sUrl.".\n\n"; $sWhatChanged .= "Url was changed from ".$this->sUrl." to ".$sUrl.".\n\n";
$this->sUrl = $sUrl; $this->sUrl = $sUrl;
@@ -169,7 +180,7 @@ class Url {
$sWhatChanged .= "Application was changed from ".$oAppBefore->sName." to ".$oAppAfter->sName.".\n\n"; $sWhatChanged .= "Application was changed from ".$oAppBefore->sName." to ".$oAppAfter->sName.".\n\n";
$this->iAppId = $iAppId; $this->iAppId = $iAppId;
} }
if($sWhatChanged) if($sWhatChanged && !$bSilent)
$this->SendNotificationMail("edit",$sWhatChanged); $this->SendNotificationMail("edit",$sWhatChanged);
return true; return true;
} }
@@ -181,7 +192,7 @@ class Url {
if($this->iSubmitterId) if($this->iSubmitterId)
{ {
$sAppName = Application::lookup_name($this->appId)." ".Version::lookup_name($this->versionId); $sAppName = Application::lookup_name($this->iAppId)." ".Version::lookup_name($this->iVersionId);
$oSubmitter = new User($this->iSubmitterId); $oSubmitter = new User($this->iSubmitterId);
if(!$bRejected) if(!$bRejected)
{ {
@@ -202,7 +213,7 @@ class Url {
function SendNotificationMail($bDeleted=false) function SendNotificationMail($bDeleted=false)
{ {
$sAppName = Application::lookup_name($this->appId)." ".Version::lookup_name($this->versionId); $sAppName = Application::lookup_name($this->iAppId)." ".Version::lookup_name($this->iVersionId);
if(!$bDeleted) if(!$bDeleted)
{ {
if(!$this->bQueued) if(!$this->bQueued)
@@ -236,6 +247,21 @@ class Url {
mail_appdb($sEmail, $sSubject ,$sMsg); mail_appdb($sEmail, $sSubject ,$sMsg);
} }
function canEdit($iVersionId, $iAppId = NULL)
{
$oUser = new User($_SESSION['current']->iUserId);
if($oUser->hasPriv("admin") || ($iVersionId &&
maintainer::isUserMaintainer($oUser, $iVersionId)) || ($iAppId &&
maintainer::isSuperMaintainer($oUser, $iAppId)))
{
return TRUE;
} else
{
return FALSE;
}
}
/* Display links for a given version/application */ /* Display links for a given version/application */
function display($iVersionId, $iAppId = NULL) function display($iVersionId, $iAppId = NULL)
{ {