2005-02-11 01:33:25 +00:00
|
|
|
<?php
|
|
|
|
|
/***************************************/
|
|
|
|
|
/* url class and related functions */
|
|
|
|
|
/***************************************/
|
2006-06-17 06:10:10 +00:00
|
|
|
require_once(BASE."include/util.php");
|
2005-02-11 01:33:25 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Url class for handling urls
|
|
|
|
|
*/
|
|
|
|
|
class Url {
|
|
|
|
|
var $iUrlId;
|
|
|
|
|
var $iAppId;
|
|
|
|
|
var $iVersionId;
|
|
|
|
|
var $sDescription;
|
|
|
|
|
var $sUrl;
|
|
|
|
|
var $sSubmitTime;
|
|
|
|
|
var $sSubmitterId;
|
|
|
|
|
var $bQueued;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor, fetches the url $iUrlId is given.
|
|
|
|
|
*/
|
|
|
|
|
function Url($iUrlId = null)
|
|
|
|
|
{
|
|
|
|
|
// we are working on an existing url
|
|
|
|
|
if($iUrlId)
|
|
|
|
|
{
|
|
|
|
|
$sQuery = "SELECT appData.*
|
|
|
|
|
FROM appData
|
|
|
|
|
WHERE type = 'url'
|
2006-06-27 19:16:27 +00:00
|
|
|
AND id = '?'";
|
|
|
|
|
if($hResult = query_parameters($sQuery, $iUrlId))
|
2005-02-11 01:33:25 +00:00
|
|
|
{
|
|
|
|
|
$oRow = mysql_fetch_object($hResult);
|
|
|
|
|
$this->iUrlId = $iUrlId;
|
|
|
|
|
$this->sDescription = $oRow->description;
|
|
|
|
|
$this->iAppId = $oRow->appId;
|
|
|
|
|
$this->iVersionId = $oRow->versionId;
|
|
|
|
|
$this->sUrl = $oRow->url;
|
|
|
|
|
$this->bQueued = $oRow->queued;
|
|
|
|
|
$this->sSubmitTime = $oRow->submitTime;
|
|
|
|
|
$this->iSubmitterId = $oRow->submitterId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new url.
|
|
|
|
|
*/
|
2007-01-19 01:40:17 +00:00
|
|
|
function create($sDescription = null, $sUrl = null, $iVersionId = null, $iAppId = null, $bSilent = false)
|
2005-02-11 01:33:25 +00:00
|
|
|
{
|
2007-01-04 02:35:01 +00:00
|
|
|
global $aClean;
|
2006-06-17 06:10:10 +00:00
|
|
|
|
2005-02-11 01:33:25 +00:00
|
|
|
// Security, if we are not an administrator or a maintainer, the url must be queued.
|
2007-01-19 01:40:17 +00:00
|
|
|
if(($iAppId && !url::canEdit(NULL, $iAppId)) ||
|
|
|
|
|
($iVersionId && !url::canEdit($iVersionId)))
|
2005-02-11 01:33:25 +00:00
|
|
|
$this->bQueued = true;
|
|
|
|
|
|
2007-01-19 01:40:17 +00:00
|
|
|
$hResult = query_parameters("INSERT INTO appData (appId, versionId, type,
|
|
|
|
|
description, queued, submitterId, url)
|
|
|
|
|
VALUES ('?', '?', '?', '?', '?', '?', '?')",
|
|
|
|
|
$iAppId, $iVersionId, "url", $sDescription,
|
|
|
|
|
$this->bQueued ? "true" : "false",
|
|
|
|
|
$_SESSION['current']->iUserId, $sUrl);
|
|
|
|
|
|
|
|
|
|
if(!$hResult)
|
2006-06-24 04:20:32 +00:00
|
|
|
{
|
|
|
|
|
addmsg("Error while creating a new url.", "red");
|
2005-02-11 01:33:25 +00:00
|
|
|
return false;
|
2006-06-24 04:20:32 +00:00
|
|
|
}
|
2007-01-19 01:40:17 +00:00
|
|
|
|
|
|
|
|
$this->iUrlId = mysql_insert_id();
|
|
|
|
|
$this->url($this->iUrlId,$this->bQueued);
|
|
|
|
|
|
|
|
|
|
if(!$bSilent)
|
|
|
|
|
$this->SendNotificationMail();
|
|
|
|
|
|
|
|
|
|
return true;
|
2005-02-11 01:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Deletes the url from the database.
|
|
|
|
|
* and request its deletion from the filesystem (including the thumbnail).
|
|
|
|
|
*/
|
|
|
|
|
function delete($bSilent=false)
|
|
|
|
|
{
|
|
|
|
|
$sQuery = "DELETE FROM appData
|
2006-06-27 19:16:27 +00:00
|
|
|
WHERE id = '?'
|
2005-02-11 01:33:25 +00:00
|
|
|
AND type = 'url'
|
|
|
|
|
LIMIT 1";
|
2007-01-19 01:40:17 +00:00
|
|
|
if(!$hResult = query_parameters($sQuery, $this->iUrlId))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if(!$bSilent)
|
|
|
|
|
$this->SendNotificationMail(true);
|
|
|
|
|
|
|
|
|
|
if($this->iSubmitterId &&
|
|
|
|
|
$this->iSubmitterId != $_SESSION['current']->iUserId)
|
2005-02-11 01:33:25 +00:00
|
|
|
{
|
|
|
|
|
$this->mailSubmitter(true);
|
|
|
|
|
}
|
2007-01-19 01:40:17 +00:00
|
|
|
|
|
|
|
|
return true;
|
2005-02-11 01:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Move url out of the queue.
|
|
|
|
|
*/
|
|
|
|
|
function unQueue()
|
|
|
|
|
{
|
|
|
|
|
// If we are not in the queue, we can't move the url out of the queue.
|
|
|
|
|
if(!$this->bQueued)
|
|
|
|
|
return false;
|
|
|
|
|
|
2006-06-27 19:16:27 +00:00
|
|
|
if(query_parameters("UPDATE appData SET queued = '?' WHERE id='?'",
|
|
|
|
|
"false", $this->iUrlId))
|
2005-02-11 01:33:25 +00:00
|
|
|
{
|
2006-12-31 19:39:41 +00:00
|
|
|
// we send an e-mail to interested people
|
2005-02-11 01:33:25 +00:00
|
|
|
$this->mailSubmitter();
|
2005-09-30 01:55:51 +00:00
|
|
|
$this->SendNotificationMail();
|
2005-02-11 01:33:25 +00:00
|
|
|
// the url has been unqueued
|
|
|
|
|
addmsg("The url has been unqueued.", "green");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update url.
|
|
|
|
|
* Returns true on success and false on failure.
|
|
|
|
|
*/
|
2007-01-19 01:40:17 +00:00
|
|
|
function update($sDescription = null, $sUrl = null, $iVersionId = null, $iAppId = null, $bSilent = false)
|
2005-02-11 01:33:25 +00:00
|
|
|
{
|
2007-01-19 01:40:17 +00:00
|
|
|
if(!$this->iUrlId)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
|
2005-02-11 01:33:25 +00:00
|
|
|
$sWhatChanged = "";
|
|
|
|
|
|
|
|
|
|
if ($sDescription && $sDescription!=$this->sDescription)
|
|
|
|
|
{
|
2006-06-27 19:16:27 +00:00
|
|
|
if (!query_parameters("UPDATE appData SET description = '?' WHERE id = '?'",
|
|
|
|
|
$sDescription, $this->iUrlId))
|
2005-02-11 01:33:25 +00:00
|
|
|
return false;
|
|
|
|
|
$sWhatChanged .= "Description was changed from\n ".$this->sDescription."\n to \n".$sDescription.".\n\n";
|
|
|
|
|
$this->sDescription = $sDescription;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($sUrl && $sUrl!=$this->sUrl)
|
|
|
|
|
{
|
2007-01-19 01:40:17 +00:00
|
|
|
if (!query_parameters("UPDATE appData SET url = '?' WHERE id = '?'",
|
|
|
|
|
$sUrl, $this->iUrlId))
|
2005-02-11 01:33:25 +00:00
|
|
|
return false;
|
|
|
|
|
$sWhatChanged .= "Url was changed from ".$this->sUrl." to ".$sUrl.".\n\n";
|
|
|
|
|
$this->sUrl = $sUrl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($iVersionId && $iVersionId!=$this->iVersionId)
|
|
|
|
|
{
|
2006-06-27 19:16:27 +00:00
|
|
|
if (!query_parameters("UPDATE appData SET versionId = '?' WHERE id = '?'",
|
|
|
|
|
$iVersionId, $this->iUrlId))
|
2005-02-11 01:33:25 +00:00
|
|
|
return false;
|
|
|
|
|
$oVersionBefore = new Version($this->iVersionId);
|
|
|
|
|
$oVersionAfter = new Version($iVersionId);
|
|
|
|
|
$sWhatChanged .= "Version was changed from ".$oVersionBefore->sName." to ".$oVersionAfter->sName.".\n\n";
|
|
|
|
|
$this->iVersionId = $iVersionId;
|
|
|
|
|
$this->iAppId = $oVersionAfter->iAppId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($iAppId && $iAppId!=$this->iAppId)
|
|
|
|
|
{
|
2006-06-27 19:16:27 +00:00
|
|
|
if (!query_parameters("UPDATE appData SET appId = '?' WHERE id = '?'",
|
|
|
|
|
$iAppId, $this->iUrlId))
|
2005-02-11 01:33:25 +00:00
|
|
|
return false;
|
|
|
|
|
$oAppBefore = new Application($this->iAppId);
|
|
|
|
|
$oAppAfter = new Application($iAppId);
|
|
|
|
|
$sWhatChanged .= "Application was changed from ".$oAppBefore->sName." to ".$oAppAfter->sName.".\n\n";
|
|
|
|
|
$this->iAppId = $iAppId;
|
|
|
|
|
}
|
2007-01-19 01:40:17 +00:00
|
|
|
if($sWhatChanged && !$bSilent)
|
2005-09-30 01:55:51 +00:00
|
|
|
$this->SendNotificationMail("edit",$sWhatChanged);
|
2005-02-11 01:33:25 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function mailSubmitter($bRejected=false)
|
|
|
|
|
{
|
2007-01-04 02:35:01 +00:00
|
|
|
global $aClean;
|
2006-06-17 06:10:10 +00:00
|
|
|
|
2005-02-11 01:33:25 +00:00
|
|
|
if($this->iSubmitterId)
|
|
|
|
|
{
|
2007-01-19 01:40:17 +00:00
|
|
|
$sAppName = Application::lookup_name($this->iAppId)." ".Version::lookup_name($this->iVersionId);
|
2005-02-11 01:33:25 +00:00
|
|
|
$oSubmitter = new User($this->iSubmitterId);
|
|
|
|
|
if(!$bRejected)
|
|
|
|
|
{
|
|
|
|
|
$sSubject = "Submitted url accepted";
|
2006-06-29 16:07:19 +00:00
|
|
|
$sMsg = "The url you submitted for ".$sAppName." has been accepted.";
|
2005-02-11 01:33:25 +00:00
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
$sSubject = "Submitted url rejected";
|
2006-06-29 16:07:19 +00:00
|
|
|
$sMsg = "The url you submitted for ".$sAppName." has been rejected.";
|
2005-02-11 01:33:25 +00:00
|
|
|
}
|
2006-07-13 18:54:10 +00:00
|
|
|
$sMsg .= $aClean['sReplyText']."\n";
|
2005-02-11 01:33:25 +00:00
|
|
|
$sMsg .= "We appreciate your help in making the Application Database better for all users.";
|
|
|
|
|
|
|
|
|
|
mail_appdb($oSubmitter->sEmail, $sSubject ,$sMsg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-09-30 01:55:51 +00:00
|
|
|
function SendNotificationMail($bDeleted=false)
|
2005-02-11 01:33:25 +00:00
|
|
|
{
|
2007-01-19 01:40:17 +00:00
|
|
|
$sAppName = Application::lookup_name($this->iAppId)." ".Version::lookup_name($this->iVersionId);
|
2005-02-11 01:33:25 +00:00
|
|
|
if(!$bDeleted)
|
|
|
|
|
{
|
|
|
|
|
if(!$this->bQueued)
|
|
|
|
|
{
|
2006-06-29 16:07:19 +00:00
|
|
|
$sSubject = "Url for ".$sAppName." added by ".$_SESSION['current']->sRealname;
|
2006-07-06 17:27:54 +00:00
|
|
|
$sMsg = APPDB_ROOT."appview.php?iVersionId=".$this->iVersionId."\n";
|
2005-02-11 01:33:25 +00:00
|
|
|
if($this->iSubmitterId)
|
|
|
|
|
{
|
|
|
|
|
$oSubmitter = new User($this->iSubmitterId);
|
|
|
|
|
$sMsg .= "This url has been submitted by ".$oSubmitter->sRealname.".";
|
|
|
|
|
$sMsg .= "\n";
|
|
|
|
|
}
|
|
|
|
|
addmsg("The url was successfully added into the database.", "green");
|
|
|
|
|
} else // Url queued.
|
|
|
|
|
{
|
2006-06-29 16:07:19 +00:00
|
|
|
$sSubject = "Url for ".$sAppName." submitted by ".$_SESSION['current']->sRealname;
|
2006-07-06 17:27:54 +00:00
|
|
|
$sMsg = APPDB_ROOT."appview.php?iVersionId=".$this->iVersionId."\n";
|
2005-02-11 01:33:25 +00:00
|
|
|
$sMsg .= "This url has been queued.";
|
|
|
|
|
$sMsg .= "\n";
|
|
|
|
|
addmsg("The url you submitted will be added to the database database after being reviewed.", "green");
|
|
|
|
|
}
|
|
|
|
|
} else // Url deleted.
|
|
|
|
|
{
|
2006-06-29 16:07:19 +00:00
|
|
|
$sSubject = "Url for ".$sAppName." deleted by ".$_SESSION['current']->sRealname;
|
2006-07-06 17:27:54 +00:00
|
|
|
$sMsg = APPDB_ROOT."appview.php?iVersionId=".$this->iVersionId."\n";
|
2005-02-11 01:33:25 +00:00
|
|
|
addmsg("Url deleted.", "green");
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-29 15:54:29 +00:00
|
|
|
$sEmail = User::get_notify_email_address_list(null, $this->iVersionId);
|
2005-02-11 01:33:25 +00:00
|
|
|
if($sEmail)
|
|
|
|
|
mail_appdb($sEmail, $sSubject ,$sMsg);
|
2007-01-18 02:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
2007-01-19 01:40:17 +00:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-18 02:28:21 +00:00
|
|
|
/* Display links for a given version/application */
|
|
|
|
|
function display($iVersionId, $iAppId = NULL)
|
|
|
|
|
{
|
|
|
|
|
if($iVersionId)
|
|
|
|
|
{
|
|
|
|
|
if(!($hResult = appData::getData($iVersionId, "url")))
|
|
|
|
|
return FALSE;
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
if(!($hResult = appData::getData($iAppId, "url", FALSE)))
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for($i = 0; $oRow = mysql_fetch_object($hResult); $i++)
|
|
|
|
|
{
|
|
|
|
|
$sReturn .= html_tr(array(
|
|
|
|
|
"<b>Link</b>",
|
|
|
|
|
"<a href=\"$oRow->url\">$oRow->description</a>"),
|
|
|
|
|
"color1");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $sReturn;
|
|
|
|
|
}
|
2005-02-11 01:33:25 +00:00
|
|
|
}
|
|
|
|
|
?>
|