2004-12-12 03:51:51 +00:00
< ? php
/***********************************************************/
2004-03-15 16:22:00 +00:00
/* this class represents an application incl. all versions */
2004-12-12 03:51:51 +00:00
/***********************************************************/
2005-02-07 23:21:33 +00:00
require_once ( BASE . " include/version.php " );
require_once ( BASE . " include/vendor.php " );
2005-02-11 01:34:16 +00:00
require_once ( BASE . " include/url.php " );
2005-02-06 17:49:48 +00:00
/**
* Application class for handling applications .
*/
2004-03-15 16:22:00 +00:00
class Application {
2005-02-06 17:49:48 +00:00
var $iAppId ;
var $iVendorId ;
var $iCatId ;
var $sName ;
var $sKeywords ;
var $sDescription ;
var $sWebpage ;
2005-08-15 03:44:03 +00:00
var $sQueued ;
2005-02-07 23:21:33 +00:00
var $sSubmitTime ;
2005-02-06 17:49:48 +00:00
var $iSubmitterId ;
var $aVersionsIds ; // an array that contains the versionId of every version linked to this app.
2005-02-11 01:34:16 +00:00
var $aUrlsIds ; // an array that contains the screenshotId of every url linked to this version
2004-03-15 16:22:00 +00:00
2005-02-06 17:49:48 +00:00
/**
* constructor , fetches the data .
*/
function Application ( $iAppId = null )
2004-03-15 16:22:00 +00:00
{
2005-02-06 17:49:48 +00:00
// we are working on an existing application
2005-03-23 23:56:38 +00:00
if ( is_numeric ( $iAppId ))
2005-02-06 17:49:48 +00:00
{
2005-10-26 02:09:49 +00:00
/* fetch this applications information */
$sQuery = " SELECT *
FROM appFamily
WHERE appId = " . $iAppId ;
2005-02-06 17:49:48 +00:00
if ( $hResult = query_appdb ( $sQuery ))
{
2005-10-26 02:09:49 +00:00
$oRow = mysql_fetch_object ( $hResult );
$this -> iAppId = $iAppId ;
$this -> iVendorId = $oRow -> vendorId ;
$this -> iCatId = $oRow -> catId ;
$this -> iSubmitterId = $oRow -> submitterId ;
$this -> sSubmitTime = $oRow -> submitTime ;
$this -> sDate = $oRow -> submitTime ;
$this -> sName = $oRow -> appName ;
$this -> sKeywords = $oRow -> keywords ;
$this -> sDescription = $oRow -> description ;
$this -> sWebpage = $oRow -> webPage ;
$this -> sQueued = $oRow -> queued ;
2005-02-06 17:49:48 +00:00
}
2004-03-15 16:22:00 +00:00
2005-10-26 02:09:49 +00:00
/* fetch versions of this application, if there are any */
$this -> aVersionsIds = array ();
2005-10-26 23:54:43 +00:00
/* only admins can view all versions */
//FIXME: it would be nice to move this permission into the user class as well as keep it generic
if ( $_SESSION [ 'current' ] -> hasPriv ( " admin " ))
{
$sQuery = " SELECT versionId FROM appVersion WHERE
appId = " . $this->iAppId ;
} else
{
$sQuery = " SELECT versionId FROM appVersion WHERE
queued = 'false' AND
appId = " . $this->iAppId ;
}
2005-10-26 02:09:49 +00:00
if ( $hResult = query_appdb ( $sQuery ))
2005-02-06 17:49:48 +00:00
{
2005-10-26 02:09:49 +00:00
while ( $oRow = mysql_fetch_object ( $hResult ))
2005-02-06 17:49:48 +00:00
{
2005-10-26 02:09:49 +00:00
$this -> aVersionsIds [] = $oRow -> versionId ;
2005-02-06 17:49:48 +00:00
}
}
2005-02-11 01:34:16 +00:00
2005-10-26 02:09:49 +00:00
2005-02-11 01:34:16 +00:00
/*
* We fetch urlsIds .
*/
$this -> aUrlsIds = array ();
$sQuery = " SELECT id
FROM appData
WHERE type = 'url'
AND appId = " . $iAppId ;
if ( $hResult = query_appdb ( $sQuery ))
{
while ( $oRow = mysql_fetch_object ( $hResult ))
{
$this -> aUrlsIds [] = $oRow -> id ;
}
}
2005-02-06 17:49:48 +00:00
}
2004-03-15 16:22:00 +00:00
}
2005-02-06 17:49:48 +00:00
/**
* Creates a new application .
*/
2005-10-10 02:37:55 +00:00
function create ()
2004-03-15 16:22:00 +00:00
{
2005-10-26 02:09:49 +00:00
if ( ! $_SESSION [ 'current' ] -> canCreateApplication ())
return ;
if ( $_SESSION [ 'current' ] -> appCreatedMustBeQueued ())
2005-08-15 03:44:03 +00:00
$this -> sQueued = 'true' ;
2005-02-06 17:49:48 +00:00
else
2005-08-15 03:44:03 +00:00
$this -> sQueued = 'false' ;
2005-02-06 17:49:48 +00:00
2005-10-10 02:37:55 +00:00
$aInsert = compile_insert_string ( array ( 'appName' => $this -> sName ,
'description' => $this -> sDescription ,
'keywords' => $this -> sKeywords ,
'webPage' => $this -> sWebpage ,
'vendorId' => $this -> iVendorId ,
'catId' => $this -> iCatId ,
2005-02-17 01:18:13 +00:00
'submitterId' => $_SESSION [ 'current' ] -> iUserId ,
2005-08-15 03:44:03 +00:00
'queued' => $this -> sQueued ));
2005-02-06 17:49:48 +00:00
$sFields = " ( { $aInsert [ 'FIELDS' ] } ) " ;
$sValues = " ( { $aInsert [ 'VALUES' ] } ) " ;
if ( query_appdb ( " INSERT INTO appFamily $sFields VALUES $sValues " , " Error while creating a new application. " ))
{
$this -> iAppId = mysql_insert_id ();
$this -> application ( $this -> iAppId );
2005-09-30 01:55:51 +00:00
$this -> SendNotificationMail (); // Only administrators will be mailed as no supermaintainers exist for this app.
2005-02-06 17:49:48 +00:00
return true ;
2005-10-26 02:09:49 +00:00
} else
{
2005-02-06 17:49:48 +00:00
return false ;
2005-10-26 02:09:49 +00:00
}
2004-03-15 16:22:00 +00:00
}
2005-02-06 17:49:48 +00:00
/**
* Update application .
* Returns true on success and false on failure .
*/
2006-01-28 23:04:21 +00:00
function update ( $bSilent = false )
2004-03-15 16:22:00 +00:00
{
2005-02-09 23:49:56 +00:00
$sWhatChanged = " " ;
2005-10-26 02:09:49 +00:00
/* if the user doesn't have permission to modify this application, don't let them */
if ( ! $_SESSION [ 'current' ] -> canModifyApplication ( $this ))
return ;
2005-10-10 02:37:55 +00:00
/* create an instance of ourselves so we can see what has changed */
$oApp = new Application ( $this -> iAppId );
if ( $this -> sName && ( $this -> sName != $oApp -> sName ))
2005-02-06 17:49:48 +00:00
{
2005-10-10 02:37:55 +00:00
$sUpdate = compile_update_string ( array ( 'appName' => $this -> sName ));
2005-02-09 23:49:56 +00:00
if ( ! query_appdb ( " UPDATE appFamily SET " . $sUpdate . " WHERE appId = " . $this -> iAppId ))
2005-02-06 17:49:48 +00:00
return false ;
2005-10-10 02:37:55 +00:00
$sWhatChanged .= " Name was changed from " . $oApp -> sName . " to " . $this -> sName . " . \n \n " ;
2005-02-06 17:49:48 +00:00
}
2005-10-10 02:37:55 +00:00
if ( $this -> sDescription && ( $this -> sDescription != $oApp -> sDescription ))
2005-02-06 17:49:48 +00:00
{
2005-10-10 02:37:55 +00:00
$sUpdate = compile_update_string ( array ( 'description' => $this -> sDescription ));
2005-02-09 23:49:56 +00:00
if ( ! query_appdb ( " UPDATE appFamily SET " . $sUpdate . " WHERE appId = " . $this -> iAppId ))
2005-02-06 17:49:48 +00:00
return false ;
2005-10-10 02:37:55 +00:00
$sWhatChanged .= " Description was changed from \n " . $oApp -> sDescription . " \n to \n " . $this -> sDescription . " . \n \n " ;
2005-02-06 17:49:48 +00:00
}
2004-03-15 16:22:00 +00:00
2005-10-10 02:37:55 +00:00
if ( $this -> sKeywords && ( $this -> sKeywords != $oApp -> sKeywords ))
2005-02-06 17:49:48 +00:00
{
2005-10-10 02:37:55 +00:00
$sUpdate = compile_update_string ( array ( 'keywords' => $this -> sKeywords ));
2005-02-09 23:49:56 +00:00
if ( ! query_appdb ( " UPDATE appFamily SET " . $sUpdate . " WHERE appId = " . $this -> iAppId ))
2005-02-06 17:49:48 +00:00
return false ;
2005-10-10 02:37:55 +00:00
$sWhatChanged .= " Keywords were changed from \n " . $oApp -> sKeywords . " \n to \n " . $this -> sKeywords . " . \n \n " ;
2005-02-06 17:49:48 +00:00
}
2005-10-10 02:37:55 +00:00
if ( $this -> sWebpage && ( $this -> sWebpage != $oApp -> sWebpage ))
2005-02-06 17:49:48 +00:00
{
2005-10-10 02:37:55 +00:00
$sUpdate = compile_update_string ( array ( 'webPage' => $this -> sWebpage ));
2005-02-09 23:49:56 +00:00
if ( ! query_appdb ( " UPDATE appFamily SET " . $sUpdate . " WHERE appId = " . $this -> iAppId ))
2005-02-06 17:49:48 +00:00
return false ;
2005-10-10 02:37:55 +00:00
$sWhatChanged .= " Web page was changed from " . $oApp -> sWebpage . " to " . $this -> sWebpage . " . \n \n " ;
2005-02-06 17:49:48 +00:00
}
2005-10-10 02:37:55 +00:00
if ( $this -> iVendorId && ( $this -> iVendorId != $oApp -> iVendorId ))
2005-02-06 17:49:48 +00:00
{
2005-10-10 02:37:55 +00:00
$sUpdate = compile_update_string ( array ( 'vendorId' => $this -> iVendorId ));
2005-02-09 23:49:56 +00:00
if ( ! query_appdb ( " UPDATE appFamily SET " . $sUpdate . " WHERE appId = " . $this -> iAppId ))
2005-02-06 17:49:48 +00:00
return false ;
2005-10-10 02:37:55 +00:00
$oVendorBefore = new Vendor ( $oApp -> iVendorId );
$oVendorAfter = new Vendor ( $this -> iVendorId );
2005-02-09 23:49:56 +00:00
$sWhatChanged .= " Vendor was changed from " . $oVendorBefore -> sName . " to " . $oVendorBefore -> sName . " . \n \n " ;
2005-02-06 17:49:48 +00:00
}
2005-02-07 23:21:33 +00:00
2005-10-10 02:37:55 +00:00
if ( $this -> iCatId && ( $this -> iCatId != $oApp -> iCatId ))
2005-02-07 23:21:33 +00:00
{
2005-10-10 02:37:55 +00:00
$sUpdate = compile_update_string ( array ( 'catId' => $this -> iCatId ));
2005-02-09 23:49:56 +00:00
if ( ! query_appdb ( " UPDATE appFamily SET " . $sUpdate . " WHERE appId = " . $this -> iAppId ))
2005-02-07 23:21:33 +00:00
return false ;
2005-10-10 02:37:55 +00:00
$oCatBefore = new Category ( $oApp -> iCatId );
$oCatAfter = new Category ( $this -> iCatId );
2005-02-09 23:49:56 +00:00
$sWhatChanged .= " Vendor was changed from " . $oCatBefore -> sName . " to " . $oCatAfter -> sName . " . \n \n " ;
2005-02-07 23:21:33 +00:00
}
2006-01-28 23:04:21 +00:00
if ( $sWhatChanged and ! $bSilent )
2005-09-30 01:55:51 +00:00
$this -> SendNotificationMail ( " edit " , $sWhatChanged );
2005-02-06 17:49:48 +00:00
return true ;
2004-03-15 16:22:00 +00:00
}
2005-02-06 17:49:48 +00:00
/**
* Deletes the application from the database .
* and request the deletion of linked elements .
*/
function delete ( $bSilent = false )
2004-03-15 16:22:00 +00:00
{
2005-10-26 02:09:49 +00:00
/* make sure the current user has the appropriate permission to delete
this application */
if ( ! $_SESSION [ 'current' ] -> canDeleteApplication ( $this ))
return false ;
2005-08-05 22:07:41 +00:00
2005-06-30 01:59:32 +00:00
foreach ( $this -> aVersionsIds as $iVersionId )
{
$oVersion = new Version ( $iVersionId );
$oVersion -> delete ( $bSilent );
}
foreach ( $this -> aUrlsIds as $iUrlId )
{
$oUrl = new Url ( $iUrlId );
$oUrl -> delete ( $bSilent );
}
// remove any supermaintainers for this application so we don't orphan them
$sQuery = " DELETE from appMaintainers WHERE appId=' " . $this -> iAppId . " '; " ;
if ( ! ( $hResult = query_appdb ( $sQuery )))
{
addmsg ( " Error removing app maintainers for the deleted application! " , " red " );
}
2005-02-06 17:49:48 +00:00
$sQuery = " DELETE FROM appFamily
WHERE appId = " . $this->iAppId . "
LIMIT 1 " ;
2005-06-30 01:59:32 +00:00
if ( ! ( $hResult = query_appdb ( $sQuery )))
2005-02-06 17:49:48 +00:00
{
2005-06-30 01:59:32 +00:00
addmsg ( " Error deleting application! " , " red " );
2005-02-06 17:49:48 +00:00
}
2005-06-30 01:59:32 +00:00
2005-02-06 17:49:48 +00:00
if ( ! $bSilent )
2005-09-30 01:55:51 +00:00
$this -> SendNotificationMail ( " delete " );
2005-10-26 02:09:49 +00:00
return true ;
2005-02-06 17:49:48 +00:00
}
2004-03-15 16:22:00 +00:00
2005-02-06 17:49:48 +00:00
/**
* Move application out of the queue .
*/
function unQueue ()
{
2005-10-26 02:09:49 +00:00
if ( ! $_SESSION [ 'current' ] -> canUnQueueApplication ())
return ;
2005-02-07 23:21:33 +00:00
$sUpdate = compile_update_string ( array ( 'queued' => " false " ,
'keywords' => str_replace ( " *** " , " " , $this -> sKeywords ) ));
if ( query_appdb ( " UPDATE appFamily SET " . $sUpdate . " WHERE appId = " . $this -> iAppId ))
2005-02-06 17:49:48 +00:00
{
2005-08-15 03:44:03 +00:00
$this -> sQueued = 'false' ;
2005-02-06 17:49:48 +00:00
// we send an e-mail to intersted people
$this -> mailSubmitter ();
2005-09-30 01:55:51 +00:00
$this -> SendNotificationMail ();
2005-02-06 17:49:48 +00:00
}
2004-03-15 16:22:00 +00:00
}
2005-08-15 03:44:03 +00:00
function Reject ()
{
2005-10-26 02:09:49 +00:00
if ( ! $_SESSION [ 'current' ] -> canRejectApplication ( $this ))
return ;
2005-08-15 03:44:03 +00:00
// If we are not in the queue, we can't move the application out of the queue.
if ( ! $this -> sQueued == 'true' )
return false ;
$sUpdate = compile_update_string ( array ( 'queued' => " rejected " ));
if ( query_appdb ( " UPDATE appFamily SET " . $sUpdate . " WHERE appId = " . $this -> iAppId ))
{
$this -> sQueued = 'rejected' ;
// we send an e-mail to intersted people
$this -> mailSubmitter ( " reject " );
2005-09-30 01:55:51 +00:00
$this -> SendNotificationMail ( " reject " );
2005-02-06 17:49:48 +00:00
2005-08-15 03:44:03 +00:00
// the application has been rejectedd
addmsg ( " The application has been rejected. " , " green " );
}
}
function ReQueue ()
{
2005-10-28 00:11:35 +00:00
if ( ! $_SESSION [ 'current' ] -> canRequeueApplication ( $this ))
2005-08-15 03:44:03 +00:00
return false ;
$sUpdate = compile_update_string ( array ( 'queued' => " true " ));
if ( query_appdb ( " UPDATE appFamily SET " . $sUpdate . " WHERE appId = " . $this -> iAppId ))
{
$this -> sQueued = 'true' ;
// we send an e-mail to intersted people
2005-09-30 01:55:51 +00:00
$this -> SendNotificationMail ();
2005-08-15 03:44:03 +00:00
// the application has been re-queued
addmsg ( " The application has been re-queued. " , " green " );
}
}
function mailSubmitter ( $sAction = " add " )
2004-03-15 16:22:00 +00:00
{
2005-02-06 17:49:48 +00:00
if ( $this -> iSubmitterId )
{
$oSubmitter = new User ( $this -> iSubmitterId );
2005-08-15 03:44:03 +00:00
switch ( $sAction )
2005-02-06 17:49:48 +00:00
{
2005-08-15 03:44:03 +00:00
case " add " :
2006-02-22 02:20:02 +00:00
$sSubject = " Submitted application accepted " ;
$sMsg = " The application you submitted ( " . $oApp -> sName . " " . $this -> sName . " ) has been accepted. " ;
$sMsg .= " Administrators Responce: \n " ;
2005-08-15 03:44:03 +00:00
break ;
case " reject " :
2006-02-22 02:20:02 +00:00
$sSubject = " Submitted application rejected " ;
$sMsg = " The application you submitted ( " . $oApp -> sName . " " . $this -> sName . " ) has been rejected. " ;
$sMsg .= " Clicking on the link in this email will allow you to modify and resubmit the application. " ;
$sMsg .= " A link to your queue of applications and versions will also show up on the left hand side of the Appdb site once you have logged in. " ;
$sMsg .= APPDB_ROOT . " appsubmit.php?sub=view&apptype=applicationappId= " . $this -> iAppId . " \n " ;
$sMsg .= " Reason given: \n " ;
2005-08-15 03:44:03 +00:00
break ;
case " delete " :
2006-02-22 02:20:02 +00:00
$sSubject = " Submitted application deleted " ;
$sMsg = " The application you submitted ( " . $oApp -> sName . " " . $this -> sName . " ) has been deleted. " ;
$sMsg .= " Reason given: \n " ;
2005-08-15 03:44:03 +00:00
break ;
2005-02-06 17:49:48 +00:00
$sMsg .= $_REQUEST [ 'replyText' ] . " \n " ;
$sMsg .= " We appreciate your help in making the Application Database better for all users. " ;
2005-08-15 03:44:03 +00:00
}
2005-02-06 17:49:48 +00:00
mail_appdb ( $oSubmitter -> sEmail , $sSubject , $sMsg );
}
2004-03-15 16:22:00 +00:00
}
2004-11-09 22:42:12 +00:00
2005-02-06 17:49:48 +00:00
2005-09-30 01:55:51 +00:00
function SendNotificationMail ( $sAction = " add " , $sMsg = null )
2004-12-25 20:03:34 +00:00
{
2005-02-09 23:49:56 +00:00
switch ( $sAction )
2005-02-06 17:49:48 +00:00
{
2005-02-09 23:49:56 +00:00
case " add " :
2006-01-28 23:04:21 +00:00
if ( $this -> sQueued == 'false' ) // Has been accepted.
2005-02-09 23:49:56 +00:00
{
$sSubject = $this -> sName . " has been added by " . $_SESSION [ 'current' ] -> sRealname ;
$sMsg = APPDB_ROOT . " appview.php?appId= " . $this -> iAppId . " \n " ;
if ( $this -> iSubmitterId )
{
$oSubmitter = new User ( $this -> iSubmitterId );
$sMsg .= " This application has been submitted by " . $oSubmitter -> sRealname . " . " ;
$sMsg .= " \n " ;
}
2006-02-22 02:20:02 +00:00
if ( $_REQUEST [ 'replyText' ])
{
$sMsg .= " Appdb admin reply text: \n " ;
$sMsg .= $_REQUEST [ 'replyText' ] . " \n " ; // append the reply text, if there is any
}
2005-02-09 23:49:56 +00:00
addmsg ( " The application was successfully added into the database. " , " green " );
2006-01-28 23:04:21 +00:00
} else
2005-02-06 17:49:48 +00:00
{
2005-02-09 23:49:56 +00:00
$sSubject = $this -> sName . " has been submitted by " . $_SESSION [ 'current' ] -> sRealname ;
$sMsg .= " This application has been queued. " ;
2005-02-06 17:49:48 +00:00
$sMsg .= " \n " ;
2005-08-15 03:44:03 +00:00
addmsg ( " The application you submitted will be added to the database after being reviewed. " , " green " );
2005-02-06 17:49:48 +00:00
}
2005-02-09 23:49:56 +00:00
break ;
case " edit " :
$sSubject = $this -> sName . " has been modified by " . $_SESSION [ 'current' ] -> sRealname ;
2005-12-05 04:19:14 +00:00
$sMsg .= APPDB_ROOT . " appview.php?appId= " . $this -> iAppId . " \n " ;
2005-02-09 23:49:56 +00:00
addmsg ( " Application modified. " , " green " );
break ;
case " delete " :
$sSubject = $this -> sName . " has been deleted by " . $_SESSION [ 'current' ] -> sRealname ;
2005-05-09 22:12:19 +00:00
2006-02-22 02:20:02 +00:00
// if replyText is set we should report the reason the application was deleted
2005-05-09 22:12:19 +00:00
if ( $_REQUEST [ 'replyText' ])
{
$sMsg .= " Reason given: \n " ;
2006-02-22 02:20:02 +00:00
$sMsg .= $_REQUEST [ 'replyText' ] . " \n " ; // append the reply text, if there is any
2005-05-09 22:12:19 +00:00
}
2005-02-09 23:49:56 +00:00
addmsg ( " Application deleted. " , " green " );
break ;
2005-08-15 03:44:03 +00:00
case " reject " :
$sSubject = $this -> sName . " has been rejected by " . $_SESSION [ 'current' ] -> sRealname ;
2006-01-18 04:32:28 +00:00
$sMsg .= APPDB_ROOT . " appsubmit.php?apptype=application&sub=view&appId= " . $this -> iAppId . " \n " ;
2005-08-15 03:44:03 +00:00
2006-02-22 02:20:02 +00:00
// if replyText is set we should report the reason the application was rejected
2005-08-15 03:44:03 +00:00
if ( $_REQUEST [ 'replyText' ])
{
$sMsg .= " Reason given: \n " ;
2006-02-22 02:20:02 +00:00
$sMsg .= $_REQUEST [ 'replyText' ] . " \n " ; // append the reply text, if there is any
2005-08-15 03:44:03 +00:00
}
addmsg ( " Application rejected. " , " green " );
break ;
2005-02-06 17:49:48 +00:00
}
2005-02-07 23:21:33 +00:00
$sEmail = get_notify_email_address_list ( $this -> iAppId );
2005-02-06 17:49:48 +00:00
if ( $sEmail )
mail_appdb ( $sEmail , $sSubject , $sMsg );
}
2005-10-10 02:37:55 +00:00
/* output a html table and this applications values to the fields for editing */
function OutputEditor ( $sVendorName )
{
HtmlAreaLoaderScript ( array ( " app_editor " ));
2005-10-16 04:24:37 +00:00
echo '<input type="hidden" name="appId" value="' . $this -> iAppId . '">' ;
2005-10-10 02:37:55 +00:00
echo html_frame_start ( " Application Form " , " 90% " , " " , 0 );
echo " <table width='100%' border=0 cellpadding=2 cellspacing=0> \n " ;
echo '<tr valign=top><td class="color0"><b>Application name</b></td>' , " \n " ;
echo '<td><input size="20" type="text" name="appName" value="' . $this -> sName . '"></td></tr>' , " \n " ;
// app Category
$w = new TableVE ( " view " );
echo '<tr valign=top><td class="color0"><b>Category</b></td><td>' , " \n " ;
$w -> make_option_list ( " appCatId " , $this -> iCatId , " appCategory " , " catId " , " catName " );
echo '</td></tr>' , " \n " ;
// vendor name
echo '<tr valign=top><td class="color0"><b>Vendor</b></td>' , " \n " ;
echo '<td><input size="20" type=text name="appVendorName" value="' . $sVendorName . '"></td></tr>' , " \n " ;
// alt vendor
$x = new TableVE ( " view " );
echo '<tr valign=top><td class="color0"> </td><td>' , " \n " ;
$x -> make_option_list ( " appVendorId " , $this -> iVendorId , " vendor " , " vendorId " , " vendorName " );
echo '</td></tr>' , " \n " ;
// url
echo '<tr valign=top><td class="color0"><b>URL</b></td>' , " \n " ;
echo '<td><input size="20" type=text name="appWebpage" value="' . $this -> sWebpage . '"></td></tr>' , " \n " ;
echo '<tr valign=top><td class="color0"><b>Keywords</b></td>' , " \n " ;
echo '<td><input size="90%" type="text" name="appKeywords" value="' . $this -> sKeywords . '"></td></tr>' , " \n " ;
echo '<tr valign=top><td class="color0"><b>Application Description</b></td>' , " \n " ;
echo '<td><p><textarea cols="80" rows="20" id="app_editor" name="appDescription">' ;
if ( get_magic_quotes_gpc ())
echo stripslashes ( $this -> sDescription ) . '</textarea></p></td></tr>' , " \n " ;
else
echo $this -> sDescription . '</textarea></p></td></tr>' , " \n " ;
echo " </table> \n " ;
echo html_frame_end ();
}
function CheckOutputEditorInput ()
{
$errors = " " ;
2005-10-16 04:24:37 +00:00
if ( empty ( $_REQUEST [ 'appCatId' ]))
2005-10-10 02:37:55 +00:00
$errors .= " <li>Please enter a category for your application.</li> \n " ;
if ( strlen ( $_REQUEST [ 'appName' ]) > 200 )
$errors .= " <li>Your application name is too long.</li> \n " ;
2005-10-16 04:24:37 +00:00
if ( empty ( $_REQUEST [ 'appName' ]))
2005-10-10 02:37:55 +00:00
$errors .= " <li>Please enter an application name.</li> \n " ;
// No vendor entered, and nothing in the list is selected
2005-10-16 04:24:37 +00:00
if ( empty ( $_REQUEST [ 'appVendorName' ]) && ! $_REQUEST [ 'appVendorId' ])
2005-10-10 02:37:55 +00:00
$errors .= " <li>Please enter a vendor.</li> \n " ;
2005-10-16 04:24:37 +00:00
if ( empty ( $_REQUEST [ 'appDescription' ]))
2005-10-10 02:37:55 +00:00
$errors .= " <li>Please enter a description of your application.</li> \n " ;
return $errors ;
}
/* retrieves values from $_REQUEST that were output by OutputEditor() */
function GetOutputEditorValues ()
{
if ( get_magic_quotes_gpc ())
{
2005-10-16 04:24:37 +00:00
$this -> iAppId = stripslashes ( $_REQUEST [ 'appId' ]);
2005-10-10 02:37:55 +00:00
$this -> sName = stripslashes ( $_REQUEST [ 'appName' ]);
$this -> sDescription = stripslashes ( $_REQUEST [ 'appDescription' ]);
$this -> iCatId = stripslashes ( $_REQUEST [ 'appCatId' ]);
$this -> iVendorId = stripslashes ( $_REQUEST [ 'appVendorId' ]);
$this -> sWebpage = stripslashes ( $_REQUEST [ 'appWebpage' ]);
$this -> sKeywords = stripslashes ( $_REQUEST [ 'appKeywords' ]);
} else
{
2005-10-16 04:24:37 +00:00
$this -> iAppId = $_REQUEST [ 'appId' ];
2005-10-10 02:37:55 +00:00
$this -> sName = $_REQUEST [ 'appName' ];
$this -> sDescription = $_REQUEST [ 'appDescription' ];
$this -> iCatId = $_REQUEST [ 'appCatId' ];
$this -> iVendorId = $_REQUEST [ 'appVendorId' ];
$this -> sWebpage = $_REQUEST [ 'appWebpage' ];
$this -> sKeywords = $_REQUEST [ 'appKeywords' ];
}
}
2006-01-29 04:04:46 +00:00
/* display this application */
function display ()
{
/* is this user supposed to view this version? */
if ( ! $_SESSION [ 'current' ] -> canViewApplication ( $this ))
{
errorpage ( " Something went wrong with the application or version id " );
exit ;
}
// show Vote Menu
if ( $_SESSION [ 'current' ] -> isLoggedIn ())
apidb_sidebar_add ( " vote_menu " );
// header
apidb_header ( " Viewing App - " . $this -> sName );
// cat display
display_catpath ( $this -> iCatId , $this -> iAppId );
// set Vendor
$oVendor = new Vendor ( $this -> iVendorId );
// set URL
$appLinkURL = ( $this -> sWebpage ) ? " <a href= \" " . $this -> sWebpage . " \" > " . substr ( stripslashes ( $this -> sWebpage ), 0 , 30 ) . " </a> " : " " ;
// start display application
echo html_frame_start ( " " , " 98% " , " " , 0 );
echo " <tr><td class=color4 valign=top> \n " ;
echo " <table> \n " ;
echo " <tr><td> \n " ;
echo ' <table width="250" border="0" cellpadding="3" cellspacing="1">' , " \n " ;
echo " <tr class=color0 valign=top><td width= \" 100 \" ><b>Name</b></td><td width='100%'> " . $this -> sName . " </td> \n " ;
echo " <tr class= \" color1 \" ><td><b>Vendor</b></td><td> " .
" <a href='vendorview.php?vendorId= $oVendor->iVendorId '> " . $oVendor -> sName . " </a> \n " ;
echo " <tr class= \" color0 \" ><td><b>Votes</b></td><td> " ;
echo vote_count_app_total ( $this -> iAppId );
echo " </td></tr> \n " ;
// main URL
echo " <tr class= \" color1 \" ><td><b>URL</b></td><td> " . $appLinkURL . " </td></tr> \n " ;
// optional links
$result = query_appdb ( " SELECT * FROM appData WHERE appId = " . $_REQUEST [ 'appId' ] . " AND versionID = 0 AND type = 'url' " );
if ( $result && mysql_num_rows ( $result ) > 0 )
{
echo " <tr class= \" color1 \" ><td> <b>Links</b></td><td> \n " ;
while ( $ob = mysql_fetch_object ( $result ))
{
echo " <a href=' $ob->url '> " . substr ( stripslashes ( $ob -> description ), 0 , 30 ) . " </a> <br /> \n " ;
}
echo " </td></tr> \n " ;
}
// image
$img = get_screenshot_img ( $this -> iAppId );
echo " <tr><td align= \" center \" colspan= \" 2 \" > $img </td></tr> \n " ;
echo " </table> \n " ; /* close of name/vendor/bugs/url table */
echo " </td></tr> \n " ;
echo " <tr><td> \n " ;
// Display all supermaintainers maintainers of this application
echo " <table class= \" color4 \" width= \" 250 \" border= \" 1 \" > \n " ;
echo " <tr><td align= \" left \" ><b>Super maintainers:</b></td></tr> \n " ;
$other_maintainers = getSuperMaintainersUserIdsFromAppId ( $this -> iAppId );
if ( $other_maintainers )
{
echo " <tr><td align= \" left \" ><ul> \n " ;
while ( list ( $index , $userIdValue ) = each ( $other_maintainers ))
{
$oUser = new User ( $userIdValue );
echo " <li> " . $oUser -> sRealname . " </li> \n " ;
}
echo " </ul></td></tr> \n " ;
} else
{
echo " <tr><td align=right>No maintainers.Volunteer today!</td></tr> \n " ;
}
// Display the app maintainer button
echo ' <tr><td align="center">' ;
if ( $_SESSION [ 'current' ] -> isLoggedIn ())
{
/* are we already a maintainer? */
if ( $_SESSION [ 'current' ] -> isSuperMaintainer ( $this -> iAppId )) /* yep */
{
echo ' <form method="post" name="message" action="maintainerdelete.php"><input type=submit value="Remove yourself as a super maintainer" class="button">' ;
} else /* nope */
{
echo ' <form method="post" name="message" action="maintainersubmit.php"><input type="submit" value="Be a super maintainer of this app" class="button" title="Click here to know more about super maintainers.">' ;
}
echo " <input type= \" hidden \" name= \" appId \" value= \" " . $this -> iAppId . " \" > " ;
echo " <input type= \" hidden \" name= \" superMaintainer \" value= \" 1 \" > " ; /* set superMaintainer to 1 because we are at the appFamily level */
echo " </form> " ;
if ( $_SESSION [ 'current' ] -> isSuperMaintainer ( $this -> iAppId ) || $_SESSION [ 'current' ] -> hasPriv ( " admin " ))
{
echo ' <form method="post" name="edit" action="admin/editAppFamily.php"><input type="hidden" name="appId" value="' . $_REQUEST [ 'appId' ] . '"><input type="submit" value="Edit Application" class="button"></form>' ;
}
if ( $_SESSION [ 'current' ] -> isLoggedIn ())
{
echo '<form method="post" name="message" action="appsubmit.php?appId=' . $this -> iAppId . '&apptype=version&sub=view">' ;
echo '<input type=submit value="Submit new version" class="button">' ;
echo '</form>' ;
}
if ( $_SESSION [ 'current' ] -> hasPriv ( " admin " ))
{
$url = BASE . " admin/deleteAny.php?what=appFamily&appId= " . $this -> iAppId . " &confirmed=yes " ;
echo " <form method= \" post \" name= \" edit \" action= \" javascript:deleteURL('Are you sure?', ' " . $url . " ') \" ><input type= \" submit \" value= \" Delete App \" class= \" button \" ></form> " ;
echo ' <form method="post" name="edit" action="admin/editBundle.php"><input type="hidden" name="bundleId" value="' . $this -> iAppId . '"><input type="submit" value="Edit Bundle" class="button"></form>' ;
}
} else
{
echo '<form method="post" action="account.php?cmd=login"><input type="submit" value="Log in to become a super maintainer" class="button"></form>' ;
}
echo " </td></tr> \n " ;
echo " </table> \n " ; /* close of super maintainers table */
echo " </td></tr> \n " ;
echo " </table> \n " ; /* close the table that contains the whole left hand side of the upper table */
// description
echo " <td class=color2 valign=top width='100%'> \n " ;
echo " <table width='100%' border=0><tr><td width='100%' valign=top><span class= \" title \" >Description</span> \n " ;
echo $this -> sDescription ;
echo " </td></tr></table> \n " ;
echo html_frame_end ( " For more details and user comments, view the versions of this application. " );
// display versions
display_approved_versions ( $this -> aVersionsIds );
// display bundle
display_bundle ( $this -> iAppId );
}
2004-12-25 20:03:34 +00:00
}
2005-02-06 17:49:48 +00:00
/*
* Application functions that are not part of the class
*/
2005-02-04 02:59:05 +00:00
function lookup_version_name ( $versionId )
2004-11-09 22:42:12 +00:00
{
2005-02-04 02:59:05 +00:00
if ( ! $versionId ) return null ;
2005-02-02 02:39:40 +00:00
$result = query_appdb ( " SELECT versionName FROM appVersion WHERE versionId = $versionId " );
2004-11-09 22:42:12 +00:00
if ( ! $result || mysql_num_rows ( $result ) != 1 )
return null ;
$ob = mysql_fetch_object ( $result );
return $ob -> versionName ;
}
2005-02-04 02:59:05 +00:00
function lookup_app_name ( $appId )
2004-11-09 22:42:12 +00:00
{
2005-02-04 02:59:05 +00:00
if ( ! $appId ) return null ;
2005-01-11 00:26:05 +00:00
$result = query_appdb ( " SELECT appName FROM appFamily WHERE appId = $appId " );
2004-11-09 22:42:12 +00:00
if ( ! $result || mysql_num_rows ( $result ) != 1 )
return null ;
$ob = mysql_fetch_object ( $result );
return $ob -> appName ;
}
2005-02-02 02:38:20 +00:00
/**
* Remove html formatting from description and extract the first part of the description only .
* This is to be used for search results , application summary tables , etc .
*/
function trim_description ( $sDescription )
{
// 1) let's take the first line of the description:
$aDesc = explode ( " \n " , trim ( $sDescription ), 2 );
// 2) maybe it's an html description and lines are separated with <br> or </p><p>
$aDesc = explode ( " <br> " , $aDesc [ 0 ], 2 );
$aDesc = explode ( " <br /> " , $aDesc [ 0 ], 2 );
$aDesc = explode ( " </p><p> " , $aDesc [ 0 ], 2 );
$aDesc = explode ( " </p><p /><p> " , $aDesc [ 0 ], 2 );
return trim ( strip_tags ( $aDesc [ 0 ]));
}
2005-10-10 02:37:55 +00:00
function GetDefaultApplicationDescription ()
{
return " <p>Enter a description of the application here</p> " ;
}
2005-10-28 00:11:35 +00:00
function showAppList ( $hResult )
{
//show applist
echo html_frame_start ( " " , " 90% " , " " , 0 );
echo " <table width= \" 100% \" border= \" 0 \" cellpadding= \" 3 \" cellspacing= \" 0 \" >
< tr class = color4 >
< td > Submission Date </ td >
< td > Submitter </ td >
< td > Vendor </ td >
< td > Application </ td >
< td align = \ " center \" >Action</td>
</ tr > " ;
$c = 1 ;
while ( $oRow = mysql_fetch_object ( $hResult ))
{
$oApp = new Application ( $oRow -> appId );
$oSubmitter = new User ( $oApp -> iSubmitterId );
if ( $oApp -> iVendorId )
{
$oVendor = new Vendor ( $oApp -> iVendorId );
$sVendor = $oVendor -> sName ;
} else
{
$sVendor = get_vendor_from_keywords ( $oApp -> sKeywords );
}
if ( $c % 2 == 1 ) { $bgcolor = 'color0' ; } else { $bgcolor = 'color1' ; }
echo " <tr class= \" $bgcolor\ " > \n " ;
echo " <td> " . print_date ( mysqltimestamp_to_unixtimestamp ( $oApp -> sSubmitTime )) . " </td> \n " ;
echo " <td> \n " ;
echo $oSubmitter -> sEmail ? " <a href= \" mailto: " . $oSubmitter -> sEmail . " \" > " : " " ;
echo $oSubmitter -> sRealname ;
echo $oSubmitter -> sEmail ? " </a> " : " " ;
echo " </td> \n " ;
echo " <td> " . $sVendor . " </td> \n " ;
echo " <td> " . $oApp -> sName . " </td> \n " ;
echo " <td align= \" center \" >[<a href= " . $_SERVER [ 'PHP_SELF' ] . " ?apptype=application&sub=view&appId= " . $oApp -> iAppId . " >process</a>]</td> \n " ;
echo " </tr> \n \n " ;
$c ++ ;
}
echo " </table> \n \n " ;
echo html_frame_end ( " " );
}
2004-11-09 22:42:12 +00:00
?>