- add version and vendor classes

- much improved application class (same model as the other new classes I made)
- modified category class
- modified some files to use the new classes and methods
- deletes linked elements on cascade
This commit is contained in:
Jonathan Ernst
2005-02-06 17:49:48 +00:00
committed by WineHQ
parent b171c02c94
commit 792151c574
6 changed files with 733 additions and 171 deletions

View File

@@ -32,22 +32,26 @@ if($_REQUEST['what'])
switch($_REQUEST['what'])
{
case "comment":
// TODO: delete a comment
$oComment = new Comment($_REQUEST['commentId']);
$oComment->delete();
redirect(BASE."appview.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']);
break;
case "category":
// delete category and the apps in it
deleteCategory($_REQUEST['catId']);
$oCategory = new Category($_REQUEST['catId']);
$oCategory->delete();
redirect(BASE."appbrowse.php");
break;
case "appFamily":
// delete app family & all its versions
deleteAppFamily($_REQUEST['appId']);
$oApp = new Application($_REQUEST['appId']);
$oApp->delete();
redirect(BASE."appbrowse.php");
break;
case "appVersion":
// delete a version
deleteAppVersion($_REQUEST['versionId']);
$oVersion = new Application($_REQUEST['versionId']);
$oVersion->delete();
redirect(BASE."appview.php?appId=".$_REQUEST['appId']);
break;
}

View File

@@ -121,9 +121,9 @@ function show_note($sType,$oData){
/**
* display the versions
*/
function display_versions($appId, $versions)
function display_versions($iAppId, $aVersionsIds)
{
if ($versions)
if ($aVersionsIds)
{
echo html_frame_start("","98%","",0);
echo "<table width='100%' border=0 cellpadding=3 cellspacing=1>\n\n";
@@ -137,41 +137,37 @@ function display_versions($appId, $versions)
echo "</tr>\n\n";
$c = 0;
while(list($idx, $ver) = each($versions))
foreach($aVersionsIds as $iVersionId)
{
//set row color
$oVersion = new Version($iVersionId);
// set row color
$bgcolor = ($c % 2 == 0) ? "color0" : "color1";
// Description
$desc = trim_description($ver->description);
if(strlen($desc) == 75)
$desc .= " ...";
//count comments
$r_count = count_comments($appId,$ver->versionId);
// description
$desc = trim_description($oVersion->sDescription);
// count comments
$r_count = count_comments($iAppId,$iVersionId);
//display row
echo "<tr class=$bgcolor>\n";
echo " <td><a href='appview.php?versionId=$ver->versionId'>".$ver->versionName."</a></td>\n";
echo " <td><a href=\"appview.php?versionId=".$iVersionId."\">".$oVersion->sName."</a></td>\n";
echo " <td>$desc &nbsp;</td>\n";
echo " <td align=center>$ver->maintainer_rating</td>\n";
echo " <td align=center>$ver->maintainer_release</td>\n";
echo " <td align=center>".$oVersion->sTestedRating."</td>\n";
echo " <td align=center>".$oVersion->sTestedVersion."</td>\n";
echo " <td align=center>$r_count</td>\n";
echo "</tr>\n\n";
$c++;
}
echo "</table>\n";
echo html_frame_end("Click the Version Name to view the details of that Version");
}
echo "</table>\n";
echo html_frame_end("Click the Version Name to view the details of that Version");
}
}
/**
* We want to see an application family (=no version).
*/
if(!is_numeric($_REQUEST['appId']) && !is_numeric($_REQUEST['versionId']))
{
errorpage("Something went wrong with the application or version id");
@@ -179,32 +175,29 @@ if(!is_numeric($_REQUEST['appId']) && !is_numeric($_REQUEST['versionId']))
}
/**
* We want to see an application family (=no version).
*/
if($_REQUEST['appId'])
{
$app = new Application($_REQUEST['appId']);
$data = $app->data;
if(!$data)
{
// oops! application not found or other error. do something
errorpage('Internal Database Access Error');
exit;
}
$oApp = new Application($_REQUEST['appId']);
// show Vote Menu
if($_SESSION['current']->isLoggedIn())
apidb_sidebar_add("vote_menu");
// header
apidb_header("Viewing App - ".$data->appName);
apidb_header("Viewing App - ".$oApp->sName);
// cat display
display_catpath($app->data->catId, $_REQUEST['appId']);
display_catpath($oApp->iCatId, $oApp->iAppId);
// set Vendor
$vendor = $app->getVendor();
$vendor = $oApp->iVendorId;
// set URL
$appLinkURL = ($data->webPage) ? "<a href='$data->webPage'>".substr(stripslashes($data->webPage),0,30)."</a>": "&nbsp;";
$appLinkURL = ($oApp->sWebpage) ? "<a href=\"$data->webPage\">".substr(stripslashes($oApp->sWebpage),0,30)."</a>": "&nbsp;";
// start display application
echo html_frame_start("","98%","",0);
@@ -214,21 +207,21 @@ if($_REQUEST['appId'])
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%'> ".stripslashes($data->appName)." </td>\n";
echo " <tr class=color0 valign=top><td width=\"100\"><b>Name</b></td><td width='100%'> ".$oApp->sName." </td>\n";
echo " <tr class=\"color1\"><td><b>Vendor</b></td><td> ".
" <a href='vendorview.php?vendorId=$vendor->vendorId'> ".stripslashes($vendor->vendorName)." </a> &nbsp;\n";
echo " <tr class=\"color0\"><td><b>BUGS</b></td><td> ".
" <a href='bugs.php?appId=$data->appId.'>Check for bugs in bugzilla </a> &nbsp;\n";
" <a href=\"bugs.php?appId=".$oApp->iAppId."\">Check for bugs in bugzilla </a> &nbsp;\n";
echo " </td></tr>\n";
echo " <tr class=\"color0\"><td><b>Votes</b></td><td> ";
echo vote_count_app_total($data->appId);
echo vote_count_app_total($oApp->iAppId);
echo " </td></tr>\n";
// main URL
echo " <tr class=\"color1\"><td><b>URL</b></td><td>".$appLinkURL."</td></tr>\n";
// image
$img = get_screenshot_img($_REQUEST['appId']);
$img = get_screenshot_img($oApp->iAppId);
echo "<tr><td align=center colspan=2>$img</td></tr>\n";
echo " </table>\n"; /* close of name/vendor/bugs/url table */
@@ -239,7 +232,7 @@ if($_REQUEST['appId'])
// 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($_REQUEST['appId']);
$other_maintainers = getSuperMaintainersUserIdsFromAppId($oApp->iAppId);
if($other_maintainers)
{
while(list($index, list($userIdValue)) = each($other_maintainers))
@@ -258,7 +251,7 @@ if($_REQUEST['appId'])
if($_SESSION['current']->isLoggedIn())
{
/* are we already a maintainer? */
if($_SESSION['current']->isSuperMaintainer($_REQUEST['appId'])) /* yep */
if($_SESSION['current']->isSuperMaintainer($oApp->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 */
@@ -266,22 +259,22 @@ if($_REQUEST['appId'])
echo ' <form method=post name=message action="maintainersubmit.php"><input type=submit value="Be a super maintainer of this app" class=button>';
}
echo " <input type=\"hidden\" name=\"appId\" value=\"".$_REQUEST['appId']."\">";
echo " <input type=\"hidden\" name=\"appId\" value=\"".$oApp->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($_REQUEST['appId']) || $_SESSION['current']->hasPriv("admin"))
if($_SESSION['current']->isSuperMaintainer($oApp->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 App" class="button"></form>';
echo '<form method="post" name="message" action="appsubmit.php?appId='.$_REQUEST['appId'].'&apptype=2">';
echo '<form method="post" name="message" action="appsubmit.php?appId='.$oApp->iAppId.'&apptype=2">';
echo '<input type=submit value="Add Version" class="button">';
echo '</form>';
}
if($_SESSION['current']->hasPriv("admin"))
{
$url = BASE."admin/deleteAny.php?what=appFamily&appId=".$_REQUEST['appId']."&confirmed=yes";
$url = BASE."admin/deleteAny.php?what=appFamily&appId=".$oApp->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="'.$_REQUEST['appId'].'"><input type="submit" value="Edit Bundle" class="button"></form>';
echo ' <form method="post" name="edit" action="admin/editBundle.php"><input type="hidden" name="bundleId" value="'.$oApp->iAppId.'"><input type="submit" value="Edit Bundle" class="button"></form>';
}
} else
{
@@ -299,18 +292,18 @@ if($_REQUEST['appId'])
// 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 $data->description;
echo $oApp->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_versions($_REQUEST['appId'],$app->getAppVersionList());
display_versions($oApp->iAppId,$oApp->aVersionsIds);
// display bundle
display_bundle($_REQUEST['appId']);
display_bundle($oApp->iAppId);
// disabled for now
//log_application_visit($_REQUEST['appId']);
//log_application_visit($oApp->iAppId);
}
@@ -319,23 +312,16 @@ if($_REQUEST['appId'])
*/
else if($_REQUEST['versionId'])
{
//FIXME: get rid of appId references everywhere, as version is enough.
$sQuery = "SELECT appId FROM appVersion WHERE versionId = '".$_REQUEST['versionId']."'";
$hResult = query_appdb($sQuery);
$oRow = mysql_fetch_object($hResult);
$appId = $oRow->appId;
$app = new Application($oRow->appId);
$data = $app->data;
if(!$data)
$oVersion = new Version($_REQUEST['versionId']);
$oApp = new Application($oVersion->iAppId);
if(!$oApp->iAppId)
{
// Oops! application not found or other error. do something
errorpage('Internal Database Access Error. No App found.');
exit;
}
$ver = $app->getAppVersion($_REQUEST['versionId']);
if(!$ver)
if(!$oVersion->iVersionId)
{
// Oops! Version not found or other error. do something
errorpage('Internal Database Access Error. No Version Found.');
@@ -343,24 +329,24 @@ else if($_REQUEST['versionId'])
}
// header
apidb_header("Viewing App Version - ".$data->appName);
apidb_header("Viewing App Version - ".$oVersion->sName);
// cat
display_catpath($app->data->catId, $appId, $_REQUEST['versionId']);
display_catpath($oApp->iCatId, $oApp->iAppId, $oVersion->iVersionId);
// set URL
$appLinkURL = ($ver->webPage) ? "<a href='$ver->webPage'>".substr(stripslashes($ver->webPage),0,30)."</a>": "&nbsp;";
$appLinkURL = ($oApp->sWebpage) ? "<a href='$oApp->sWebpage'>".substr(stripslashes($oApp->sWebpage),0,30)."</a>": "&nbsp;";
// start version display
echo html_frame_start("","98%","",0);
echo "<link rel=\"stylesheet\" href=\"./application.css\" type=\"text/css\">";
echo '<tr><td class=color4 valign=top>',"\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%'>".stripslashes($data->appName)."</td>\n";
echo "<tr class=color1 valign=top><td> <b>Version</b></td><td>".stripslashes($ver->versionName)."</td></tr>\n";
echo "<tr class=color0 valign=top><td width=100> <b>Name</b></td><td width='100%'>".$oApp->sName."</td>\n";
echo "<tr class=color1 valign=top><td> <b>Version</b></td><td>".$oVersion->sName."</td></tr>\n";
// links
$result = query_appdb("SELECT * FROM appData WHERE versionID = ".$_REQUEST['versionId']." AND type = 'url'");
$result = query_appdb("SELECT * FROM appData WHERE versionID = ".$oVersion->iVersionId." AND type = 'url'");
if($result && mysql_num_rows($result) > 0)
{
echo " <tr class=\"color1\"><td><b>Links</b></td><td>\n";
@@ -372,17 +358,17 @@ else if($_REQUEST['versionId'])
}
// rating Area
echo "<tr class=\"color1\" valign=\"top\"><td> <b>Maintainer Rating</b></td><td>".stripslashes($ver->maintainer_rating)."</td></tr>\n";
echo "<tr class=\"color0\" valign=\"top\"><td> <b>Maintainers Version</b></td><td>".stripslashes($ver->maintainer_release)."</td></tr>\n";
echo "<tr class=\"color1\" valign=\"top\"><td> <b>Maintainer Rating</b></td><td>".$oVersion->sTestedRating."</td></tr>\n";
echo "<tr class=\"color0\" valign=\"top\"><td> <b>Maintainers Version</b></td><td>".$oVersion->sTestedRelease."</td></tr>\n";
// image
$img = get_screenshot_img($appId, $_REQUEST['versionId']);
$img = get_screenshot_img($oApp->iAppId, $oVersion->iVersionId);
echo "<tr><td align=center colspan=2>$img</td></tr>\n";
// display all maintainers of this application
echo "<tr class=color0><td align=left colspan=2><b>Maintainers of this application:</b>\n";
echo "<table width=250 border=0>";
$other_maintainers = getMaintainersUserIdsFromAppIdVersionId($appId, $_REQUEST['versionId']);
$other_maintainers = getMaintainersUserIdsFromAppIdVersionId($oApp->iAppId, $oVersion->iVersionId);
if($other_maintainers)
{
while(list($index, list($userIdValue)) = each($other_maintainers))
@@ -404,14 +390,14 @@ else if($_REQUEST['versionId'])
{
/* is this user a maintainer of this version by virtue of being a super maintainer */
/* of this app family? */
if($_SESSION['current']->isSuperMaintainer($appId))
if($_SESSION['current']->isSuperMaintainer($oApp->iAppId))
{
echo '<form method=post name=message action="maintainerdelete.php"><input type=submit value="Remove yourself as a supermaintainer" class=button>';
echo "<input type=hidden name='superMaintainer' value=1>";
} else
{
/* are we already a maintainer? */
if($_SESSION['current']->isMaintainer($_REQUEST['versionId'])) /* yep */
if($_SESSION['current']->isMaintainer($oVersion->iVersionId)) /* yep */
{
echo '<form method=post name=message action="maintainerdelete.php"><input type=submit value="Remove yourself as a maintainer" class=button>';
echo "<input type=hidden name='superMaintainer' value=0>";
@@ -421,8 +407,8 @@ else if($_REQUEST['versionId'])
}
}
echo "<input type=hidden name=\"appId\" value=\"".$appId."\">";
echo "<input type=hidden name=\"versionId\" value=\"".$_REQUEST['versionId']."\">";
echo "<input type=hidden name=\"appId\" value=\"".$oApp->iAppId."\">";
echo "<input type=hidden name=\"versionId\" value=\"".$oVersion->iVersionId."\">";
echo "</form>";
} else
{
@@ -433,26 +419,26 @@ else if($_REQUEST['versionId'])
echo "</center></td></tr>";
if ($_SESSION['current']->hasPriv("admin") || $_SESSION['current']->isMaintainer($_REQUEST['versionId']))
if ($_SESSION['current']->hasPriv("admin") || $_SESSION['current']->isMaintainer($oVersion->iVersionId))
{
echo "<tr><td colspan = 2><center>";
echo '<form method=post name=message action=admin/editAppVersion.php?appId='.$appId.'&versionId='.$_REQUEST['versionId'].'>';
echo '<form method=post name=message action=admin/editAppVersion.php?appId='.$oApp->iAppId.'&versionId='.$oVersion->iVersionId.'>';
echo '<input type=submit value="Edit Version Info" class=button>';
echo '</form>';
$url = BASE."admin/deleteAny.php?what=appVersion&appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']."&confirmed=yes";
$url = BASE."admin/deleteAny.php?what=appVersion&appId=".$oApp->iAppId."&versionId=".$oVersion->iVersionId."&confirmed=yes";
echo "<form method=\"post\" name=\"delete\" action=\"javascript:deleteURL('Are you sure?', '".$url."')\">";
echo '<input type=submit value="Delete Version" class="button">';
echo '</form>';
echo '<form method=post name=message action=admin/addAppNote.php?versionId='.$_REQUEST['versionId'].'>';
echo '<form method=post name=message action=admin/addAppNote.php?versionId='.$oVersion->iVersionId.'>';
echo '<input type=submit value="Add Note" class=button>';
echo '</form>';
echo '</form>';
echo '<form method=post name=message action=admin/addAppNote.php?versionId='.$_REQUEST['versionId'].'>';
echo '<form method=post name=message action=admin/addAppNote.php?versionId='.$oVersion->iVersionId.'>';
echo '<input type=hidden name="noteTitle" value="HOWTO">';
echo '<input type=submit value="Add How To" class=button>';
echo '</form>';
echo '</form>';
echo '<form method=post name=message action=admin/addAppNote.php?versionId='.$versionId.'>';
echo '<form method=post name=message action=admin/addAppNote.php?versionId='.$oVersion->iVersionId.'>';
echo '<input type=hidden name="noteTitle" value="WARNING">';
echo '<input type=submit value="Add Warning" class=button>';
echo '</form>';
@@ -463,7 +449,7 @@ else if($_REQUEST['versionId'])
// description
echo "<table width='100%' border=0><tr><td width='100%' valign=top> <b>Description</b><br />\n";
echo $ver->description;
echo $oVersion->sDescription;
echo "</td></tr>";
/* close the table */
@@ -471,7 +457,7 @@ else if($_REQUEST['versionId'])
echo html_frame_end();
$rNotes = query_appdb("SELECT * FROM appNotes WHERE versionId = ".$_REQUEST['versionId']);
$rNotes = query_appdb("SELECT * FROM appNotes WHERE versionId = ".$oVersion->iVersionId);
while( $oNote = mysql_fetch_object($rNotes) )
{
@@ -479,7 +465,7 @@ else if($_REQUEST['versionId'])
}
// Comments Section
view_app_comments($_REQUEST['versionId']);
view_app_comments($oVersion->iVersionId);
} else
{

View File

@@ -3,99 +3,273 @@
/* this class represents an application incl. all versions */
/***********************************************************/
require(BASE."include/version.php");
require(BASE."include/vendor.php");
/**
* Application class for handling applications.
*/
class Application {
var $data;
var $iAppId;
var $iVendorId;
var $iCatId;
var $sName;
var $sKeywords;
var $sDescription;
var $sWebpage;
var $bQueued;
var $iSubmitterId;
var $aVersionsIds; // an array that contains the versionId of every version linked to this app.
function Application($id)
/**
* constructor, fetches the data.
*/
function Application($iAppId = null)
{
$result = query_appdb("SELECT * FROM appFamily WHERE appId = $id");
if(!$result)
return; // Oops
if(mysql_num_rows($result) != 1)
return; // Not found
// we are working on an existing application
if($iAppId)
{
/*
* We fetch application data and versionsIds.
*/
$sQuery = "SELECT appFamily.*, appVersion.versionId AS versionId
FROM appFamily, appVersion
WHERE appFamily.appId = appVersion.appId
AND appFamily.appId = ".$iAppId;
if($hResult = query_appdb($sQuery))
{
while($oRow = mysql_fetch_object($hResult))
{
if(!$this->iAppId)
{
$this->iAppId = $iAppId;
$this->iVendorId = $oRow->vendorId;
$this->iCatId = $oRow->catId;
$this->iSubmitterId = $oRow->submitterId;
$this->sDate = $oRow->submitTime;
$this->sName = $oRow->appName;
$this->sKeywords = $oRow->keywords;
$this->sDescription = $oRow->description;
$this->sWebpage = $oRow->webPage;
$this->bQueued = $oRow->queued;
}
$this->aVersionsIds[] = $oRow->versionId;
}
}
$this->data = mysql_fetch_object($result);
/*
* Then we fetch the data related to this application if the first query didn't return anything.
* This can happen if an application has no version linked to it.
*/
if(!$this->appId)
{
$sQuery = "SELECT *
FROM appFamily
WHERE appId = ".$iAppId;
if($hResult = query_appdb($sQuery))
{
$oRow = mysql_fetch_object($hResult);
$this->iAppId = $iAppId;
$this->iVendorId = $oRow->vendorId;
$this->iCatId = $oRow->catId;
$this->iSubmitterId = $oRow->submitterId;
$this->sDate = $oRow->submitTime;
$this->sName = $oRow->appName;
$this->sKeywords = $oRow->keywords;
$this->sDescription = $oRow->description;
$this->sWebpage = $oRow->webPage;
$this->bQueued = $oRow->queued;
}
}
}
}
function getAppVersionList()
/**
* Creates a new application.
*/
function create($sName=null, $sDescription=null, $sKeywords=null, $sWebpage=null, $iVendorId=null, $iCatId=null)
{
$list = array();
$result = query_appdb("SELECT * FROM appVersion ".
"WHERE appId = ". $this->data->appId . " " .
"ORDER BY versionName");
if(!$result)
return $list;
// Security, if we are not an administrator the application must be queued.
if(!($_SESSION['current']->hasPriv("admin")))
$this->bQueued = true;
else
$this->bQueued = false;
while($row = mysql_fetch_object($result))
{
if($row->versionName == "NONAME")
continue;
$list[] = $row;
}
$aInsert = compile_insert_string(array( 'appName' => $sName,
'description'=> $sDescription,
'keywords' => $sKeywords,
'webPage' => $sWebpage,
'vendorId' => $iVendorId,
'catId' => $iCatId,
'queued' => $this->bQueued ));
$sFields = "({$aInsert['FIELDS']})";
$sValues = "({$aInsert['VALUES']})";
return $list;
if(query_appdb("INSERT INTO appFamily $sFields VALUES $sValues", "Error while creating a new application."))
{
$this->iAppId = mysql_insert_id();
$this->mailSupermaintainers(); // Only administrators will be mailed as no supermaintainers exist for this app.
$this->application($this->iAppId);
return true;
}
else
return false;
}
function getAppVersion($versionId)
{
$result = query_appdb("SELECT * FROM appVersion ".
"WHERE appId = ". $this->data->appId ." AND ".
"versionId = $versionId");
if(!$result || mysql_num_rows($result) != 1)
return 0;
return mysql_fetch_object($result);
/**
* Update application.
* FIXME: Informs interested people about the modification.
* Returns true on success and false on failure.
*/
function update($sName=null, $sDescription=null, $sKeywords=null, $sWebpage=null, $iVendorId=null, $iCatId=null)
{
if ($sName)
{
if (!query_appdb("UPDATE appFamily SET appName = '".$sName."' WHERE appId = ".$this->iAppId))
return false;
$this->sName = $sName;
}
if ($sDescription)
{
if (!query_appdb("UPDATE appFamily SET description = '".$sDescription."' WHERE appId = ".$this->iAppId))
return false;
$this->sDescription = $sDescription;
}
if ($sKeywords)
{
if (!query_appdb("UPDATE appFamily SET keywords = '".$sKeywords."' WHERE appId = ".$this->iAppId))
return false;
$this->sKeywords = $sKeywords;
}
if ($sWebpage)
{
if (!query_appdb("UPDATE appFamily SET webPage = '".$sWebpage."' WHERE appId = ".$this->iAppId))
return false;
$this->sWebpage = $sWebpage;
}
if ($iVendorId)
{
if (!query_appdb("UPDATE appFamily SET vendorId = '".$iVendorId."' WHERE appId = ".$this->iAppId))
return false;
$this->iVendorId = $iVendorId;
}
return true;
}
function getVendor()
{
$result = query_appdb("SELECT * FROM vendor ".
"WHERE vendorId = ". $this->data->vendorId);
if(!$result || mysql_num_rows($result) != 1)
return array("vendorName" => "Unknown");
$vendor = mysql_fetch_object($result);
return $vendor;
/**
* Deletes the application from the database.
* and request the deletion of linked elements.
*/
function delete($bSilent=false)
{
$sQuery = "DELETE FROM appFamily
WHERE appId = ".$this->iAppId."
LIMIT 1";
if($hResult = query_appdb($sQuery))
{
foreach($aVersionsIds as $iVersionId)
{
$oVersion = new Version($iVersionId);
$oVersion->delete($bSilent);
}
}
if(!$bSilent)
$this->mailSupermaintainers(true);
}
function getComments($versionId = 0)
{
$list = array();
$result = query_appdb("SELECT * FROM appComments ".
"WHERE appId = ". $this->data->appId . " AND " .
"versionId = $versionId " .
"ORDER BY time");
if(!$result)
return $list;
while($row = mysql_fetch_object($result))
$list[] = $row;
return $list;
/**
* Move application out of the queue.
*/
function unQueue()
{
// If we are not in the queue, we can't move the application out of the queue.
if(!$this->bQueued)
return false;
$sUpdate = compile_insert_string(array('queued' => "false"));
if(query_appdb("UPDATE appFamily ".$sUpdate))
{
// we send an e-mail to intersted people
$this->mailSubmitter();
$this->mailSupermaintainers();
// the application has been unqueued
addmsg("The application has been unqueued.", "green");
}
}
function mailSubmitter($bRejected=false)
{
if($this->iSubmitterId)
{
$oSubmitter = new User($this->iSubmitterId);
if(!$bRejected)
{
$sSubject = "Submitted application accepted";
$sMsg = "The application you submitted (".$this->sName.") has been accepted.";
} else
{
$sSubject = "Submitted application rejected";
$sMsg = "The application you submitted (".$this->sName.") has been rejected.";
}
$sMsg .= $_REQUEST['replyText']."\n";
$sMsg .= "We appreciate your help in making the Application Database better for all users.";
mail_appdb($oSubmitter->sEmail, $sSubject ,$sMsg);
}
}
function mailSupermaintainers($bDeleted=false)
{
if(!$bDeleted)
{
if(!$this->bQueued)
{
$sSubject = "Application ".$this->sName." 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";
}
addmsg("The application was successfully added into the database.", "green");
} else // Application queued.
{
$sSubject = "Application ".$this->sName." submitted by ".$_SESSION['current']->sRealname;
$sMsg .= "This application has been queued.";
$sMsg .= "\n";
addmsg("The application you submitted will be added to the database database after being reviewed.", "green");
}
} else // Application deleted.
{
$sSubject = "Application ".$this->sName." deleted by ".$_SESSION['current']->sRealname;
addmsg("Application deleted.", "green");
}
$sEmail = get_notify_email_address_list(null, $this->iVersionId);
if($sEmail)
mail_appdb($sEmail, $sSubject ,$sMsg);
}
}
function deleteAppFamily($appId)
{
$r = query_appdb("DELETE FROM appFamily WHERE appId = $appId", "Failed to delete appFamily $appId");
if($r)
{
$r = query_appdb("DELETE FROM appVersion WHERE appId = $appId", "Failed to delete appVersions");
if($r)
addmsg("Application and versions deleted", "green");
}
}
function deleteAppVersion($versionId)
{
$r = query_appdb("DELETE FROM appVersion WHERE versionId = $versionId","Failed to delete appVersion $versionId");
if($r)
addmsg("Application Version $versionId deleted", "green");
}
/*
* Application functions that are not part of the class
*/
function lookup_version_name($versionId)
{

View File

@@ -15,10 +15,31 @@ class Category {
*/
function Category($id = 0)
{
$this->id = $id;
$this->load($id);
}
/**
* Deletes the category from the database.
* and request the deletion of linked elements.
*/
function delete()
{
$r = query_appdb("SELECT appId FROM appFamily WHERE catId = ".$this->id,"Failed to delete category ".$this->id);
if($r)
{
while($ob = mysql_fetch_object($r))
{
$oApp = new Application($ob->appId);
$oApp->delete();
}
$r = query_appdb("DELETE FROM appCategory WHERE catId = $catId","Failed to delete category $catId");
if($r)
addmsg("Category $catId deleted.", "green");
}
}
/**
* load the category data into this class
*/
@@ -196,21 +217,7 @@ function make_cat_path($path, $appId = '', $versionId = '')
return $str;
}
function deleteCategory($catId)
{
$r = query_appdb("SELECT appId FROM appFamily WHERE catId = $catId","Failed to delete category $catId");
if($r)
{
while($ob = mysql_fetch_object($r))
deleteAppFamily($ob->appId);
$r = query_appdb("DELETE FROM appCategory WHERE catId = $catId","Failed to delete category $catId");
if($r)
addmsg("Category $catId deleted", "green");
}
}
Function lookupCategoryName($catId)
function lookupCategoryName($catId)
{
$sResult = query_appdb("SELECT * FROM appCategory ".
"WHERE catId = ".$catId);

112
include/vendor.php Normal file
View File

@@ -0,0 +1,112 @@
<?php
/**********************************/
/* this class represents a vendor */
/**********************************/
/**
* Vendor class for handling vendors.
*/
class Vendor {
var $iVendorId;
var $sName;
var $sWebpage;
var $aApplicationsIds; // an array that contains the appId of every application linked to this vendor
/**
* constructor, fetches the data.
*/
function Vendor($iVendorId = null)
{
// we are working on an existing vendor
if($iVendorId)
{
/*
* We fetch the data related to this vendor.
*/
if(!$this->vendorId)
{
$sQuery = "SELECT *
FROM vendor
WHERE vendorId = ".$iVendorId;
if($hResult = query_appdb($sQuery))
{
$oRow = mysql_fetch_object($hResult);
$this->iVendorId = $iVendorId;
$this->sName = $oRow->vendorName;
$this->sWebpage = $oRow->vendorURL;
}
}
/*
* We fetch applicationsIds.
*/
$sQuery = "SELECT appId
FROM appFamily
WHERE vendorId = ".$iVendorId;
if($hResult = query_appdb($sQuery))
{
while($oRow = mysql_fetch_object($hResult))
{
$this->aApplicationsIds[] = $oRow->appId;
}
}
}
}
/**
* Creates a new vendor.
*/
function create($sName=null, $sWebpage=null)
{
$aInsert = compile_insert_string(array( 'vendorName'=> $sName,
'vendorURL' => $sWebpage ));
$sFields = "({$aInsert['FIELDS']})";
$sValues = "({$aInsert['VALUES']})";
if(query_appdb("INSERT INTO vendor $sFields VALUES $sValues", "Error while creating a new vendor."))
{
$this->iVendorId = mysql_insert_id();
$this->vendor($this->iVendorId);
return true;
}
else
return false;
}
/**
* Update vendor.
* Returns true on success and false on failure.
*/
function update($sName=null, $sWebpage=null)
{
if ($sName)
{
if (!query_appdb("UPDATE vendor SET vendorName = '".$sName."' WHERE vendorId = ".$this->iVendorId))
return false;
$this->sName = $sName;
}
if ($sWebpage)
{
if (!query_appdb("UPDATE vendor SET vendorURL = '".$sWebpage."' WHERE vendorId = ".$this->iVendorId))
return false;
$this->sWebpage = $sWebpage;
}
return true;
}
/**
* Deletes the vendor from the database.
* FIXME: What should happen if sizeof($aApplicationsIds)>0 ?
*/
function delete($bSilent=false)
{
$sQuery = "DELETE FROM vendor
WHERE vendorId = ".$this->iVendorId."
LIMIT 1";
}
}
?>

279
include/version.php Normal file
View File

@@ -0,0 +1,279 @@
<?php
/************************************/
/* this class represents an version */
/************************************/
/**
* Version class for handling versions.
*/
class Version {
var $iVersionId;
var $iAppId;
var $sName;
var $sDescription;
var $sTestedRelease;
var $sTestedRating;
var $iSubmitterId;
var $aNotesIds; // an array that contains the noteId of every note linked to this version
var $aScreenshotsIds; // an array that contains the screenshotId of every screenshot linked to this version
var $aUrlsIds; // an array that contains the screenshotId of every url linked to this version
/**
* constructor, fetches the data.
*/
function Version($iVersionId = null)
{
// we are working on an existing version
if($iVersionId)
{
/*
* We fetch the data related to this version.
*/
if(!$this->versionId)
{
$sQuery = "SELECT *
FROM appVersion
WHERE versionId = ".$iVersionId;
if($hResult = query_appdb($sQuery))
{
$oRow = mysql_fetch_object($hResult);
$this->iVersionId = $iVersionId;
$this->iAppId = $oRow->appId;
$this->iVendorId = $oRow->vendorId;
$this->iCatId = $oRow->catId;
$this->iSubmitterId = $oRow->submitterId;
$this->sDate = $oRow->submitTime;
$this->sName = $oRow->versionName;
$this->sKeywords = $oRow->keywords;
$this->sDescription = $oRow->description;
$this->sWebpage = $oRow->webPage;
$this->bQueued = $oRow->queued;
}
}
/*
* We fetch notesIds.
*/
$sQuery = "SELECT noteId
FROM appNotes
WHERE versionId = ".$iVersionId;
if($hResult = query_appdb($sQuery))
{
while($oRow = mysql_fetch_object($hResult))
{
$this->aNotesIds[] = $oRow->versionId;
}
}
/*
* We fetch screenshotsIds and urlsIds.
*/
$sQuery = "SELECT id, type
FROM appData
WHERE versionId = ".$iVersionId;
if($hResult = query_appdb($sQuery))
{
while($oRow = mysql_fetch_object($hResult))
{
if($oRow->type="image")
$this->aScreenshotsIds[] = $oRow->id;
else
$this->aNotesIds[] = $oRow->id;
}
}
}
}
/**
* Creates a new version.
*/
function create($sName=null, $sDescription=null, $sTestedRelease=null, $sTestedRating=null, $iAppId=null)
{
// Security, if we are not an administrator or an appmaintainer the version must be queued.
if(!($_SESSION['current']->hasPriv("admin") || $_SESSION['current']->isSupermaintainer($iAppId)))
$this->bQueued = true;
else
$this->bQueued = false;
$aInsert = compile_insert_string(array( 'versionName' => $sName,
'description' => $sDescription,
'maintainer_release'=> $sTestedRelease,
'maintainer_rating' => $sTestedRating,
'appId' => $iAppId,
'queued' => $this->bQueued ));
$sFields = "({$aInsert['FIELDS']})";
$sValues = "({$aInsert['VALUES']})";
if(query_appdb("INSERT INTO appVersion $sFields VALUES $sValues", "Error while creating a new version."))
{
$this->iVersionId = mysql_insert_id();
$this->mailMaintainers();
$this->version($this->iVersionId);
return true;
}
else
return false;
}
/**
* Update version.
* FIXME: Informs interested people about the modification.
* Returns true on success and false on failure.
*/
function update($sName=null, $sDescription=null, $sTestedRelease=null, $sTestedRating=null, $iAppId=null)
{
if ($sName)
{
if (!query_appdb("UPDATE appVersion SET versionName = '".$sName."' WHERE versionId = ".$this->iVersionId))
return false;
$this->sName = $sName;
}
if ($sDescription)
{
if (!query_appdb("UPDATE appVersion SET description = '".$sDescription."' WHERE versionId = ".$this->iVersionId))
return false;
$this->sDescription = $sDescription;
}
if ($sTestedRelease)
{
if (!query_appdb("UPDATE appVersion SET maintainer_release = '".$sTestedRelease."' WHERE versionId = ".$this->iVersionId))
return false;
$this->sKeywords = $sTestedRelease;
}
if ($sTestedRating)
{
if (!query_appdb("UPDATE appVersion SET maintainer_rating = '".$sTestedRating."' WHERE versionId = ".$this->iVersionId))
return false;
$this->sWebpage = $sTestedRating;
}
if ($iAppId)
{
if (!query_appdb("UPDATE appVersion SET vendorId = '".$iAppId."' WHERE appId = ".$this->iAppId))
return false;
$this->iVendorId = $iAppId;
}
return true;
}
/**
* Deletes the version from the database.
* and request the deletion of linked elements.
* FIXME: DELETE COMMENTS AS WELL !
*/
function delete($bSilent=false)
{
$sQuery = "DELETE FROM appVersion
WHERE versionId = ".$this->iVersionId."
LIMIT 1";
if($hResult = query_appdb($sQuery))
{
foreach($aNotesIds as $iNoteId)
{
#FIXME: NOT IMPLEMENTED $oNote = new Note($iNoteId);
#FIXME: NOT IMPLEMENTED $oNote->delete($bSilent);
}
foreach($aScreenshotsIds as $iScreenshotId)
{
$oScreenshot = new Screenshot($iScreenshotId);
$oScreenshot->delete($bSilent);
}
foreach($aUrlsIds as $iUrlId)
{
#FIXME: NOT IMPLEMENTED $oUrl = new Note($iUrlId);
#FIXME: NOT IMPLEMENTED $oUrl->delete($bSilent);
}
}
if(!$bSilent)
$this->mailMaintainers(true);
}
/**
* Move version out of the queue.
*/
function unQueue()
{
// If we are not in the queue, we can't move the version out of the queue.
if(!$this->bQueued)
return false;
$sUpdate = compile_insert_string(array('queued' => "false"));
if(query_appdb("UPDATE appVersion ".$sUpdate))
{
// we send an e-mail to intersted people
$this->mailSubmitter();
$this->mailMaintainers();
// the version has been unqueued
addmsg("The version has been unqueued.", "green");
}
}
function mailSubmitter($bRejected=false)
{
if($this->iSubmitterId)
{
$oApp = new Application($this->appId);
$oSubmitter = new User($this->iSubmitterId);
if(!$bRejected)
{
$sSubject = "Submitted version accepted";
$sMsg = "The version you submitted (".$oApp->sName." ".$this->sName.") has been accepted.";
} else
{
$sSubject = "Submitted version rejected";
$sMsg = "The version you submitted (".$oApp->sName." ".$this->sName.") has been rejected.";
}
$sMsg .= $_REQUEST['replyText']."\n";
$sMsg .= "We appreciate your help in making the Version Database better for all users.";
mail_appdb($oSubmitter->sEmail, $sSubject ,$sMsg);
}
}
function mailMaintainers($bDeleted=false)
{
if(!$bDeleted)
{
if(!$this->bQueued)
{
$sSubject = "Version ".$this->sName." added by ".$_SESSION['current']->sRealname;
$sMsg = APPDB_ROOT."appview.php?versionId=".$this->iVersionId."\n";
if($this->iSubmitterId)
{
$oSubmitter = new User($this->iSubmitterId);
$sMsg .= "This version has been submitted by ".$oSubmitter->sRealname.".";
$sMsg .= "\n";
}
addmsg("The version was successfully added into the database.", "green");
} else // Version queued.
{
$sSubject = "Version ".$this->sName." submitted by ".$_SESSION['current']->sRealname;
$sMsg .= "This version has been queued.";
$sMsg .= "\n";
addmsg("The version you submitted will be added to the database database after being reviewed.", "green");
}
} else // Version deleted.
{
$sSubject = "Version ".$this->sName." deleted by ".$_SESSION['current']->sRealname;
addmsg("Version deleted.", "green");
}
$sEmail = get_notify_email_address_list(null, $this->iVersionId);
if($sEmail)
mail_appdb($sEmail, $sSubject ,$sMsg);
}
}
?>