From 792151c574b4c1bf9beacf97ff7a7fea886e9ce4 Mon Sep 17 00:00:00 2001 From: Jonathan Ernst Date: Sun, 6 Feb 2005 17:49:48 +0000 Subject: [PATCH] - 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 --- admin/deleteAny.php | 12 +- appview.php | 154 +++++++++----------- include/application.php | 310 +++++++++++++++++++++++++++++++--------- include/category.php | 37 +++-- include/vendor.php | 112 +++++++++++++++ include/version.php | 279 ++++++++++++++++++++++++++++++++++++ 6 files changed, 733 insertions(+), 171 deletions(-) create mode 100644 include/vendor.php create mode 100644 include/version.php diff --git a/admin/deleteAny.php b/admin/deleteAny.php index ddb5848..2edde26 100644 --- a/admin/deleteAny.php +++ b/admin/deleteAny.php @@ -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; } diff --git a/appview.php b/appview.php index 49bc98b..8d04b98 100644 --- a/appview.php +++ b/appview.php @@ -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 "\n\n"; @@ -137,41 +137,37 @@ function display_versions($appId, $versions) echo "\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 "\n"; - echo " \n"; + echo " \n"; echo " \n"; - echo " \n"; - echo " \n"; + echo " \n"; + echo " \n"; echo " \n"; echo "\n\n"; $c++; - } - - echo "
".$ver->versionName."".$oVersion->sName."$desc  $ver->maintainer_rating$ver->maintainer_release".$oVersion->sTestedRating."".$oVersion->sTestedVersion."$r_count
\n"; - echo html_frame_end("Click the Version Name to view the details of that Version"); + + } + echo "\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) ? "".substr(stripslashes($data->webPage),0,30)."": " "; + $appLinkURL = ($oApp->sWebpage) ? "webPage\">".substr(stripslashes($oApp->sWebpage),0,30)."": " "; // start display application echo html_frame_start("","98%","",0); @@ -214,21 +207,21 @@ if($_REQUEST['appId']) echo " \n"; echo ' ',"\n"; - echo " \n"; + echo " \n"; echo " \n"; echo " \n"; // main URL echo " \n"; // image - $img = get_screenshot_img($_REQUEST['appId']); + $img = get_screenshot_img($oApp->iAppId); echo "\n"; echo "
Name ".stripslashes($data->appName)."
Name ".$oApp->sName."
Vendor ". " ".stripslashes($vendor->vendorName)."  \n"; echo "
BUGS ". - " Check for bugs in bugzilla  \n"; + " iAppId."\">Check for bugs in bugzilla  \n"; echo "
Votes "; - echo vote_count_app_total($data->appId); + echo vote_count_app_total($oApp->iAppId); echo "
URL".$appLinkURL."
$img
\n"; /* close of name/vendor/bugs/url table */ @@ -239,7 +232,7 @@ if($_REQUEST['appId']) // Display all supermaintainers maintainers of this application echo " \n"; echo " \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 ' '; } else /* nope */ @@ -266,22 +259,22 @@ if($_REQUEST['appId']) echo ' '; } - echo " "; + echo " iAppId."\">"; echo " "; /* set superMaintainer to 1 because we are at the appFamily level */ echo " "; - if($_SESSION['current']->isSuperMaintainer($_REQUEST['appId']) || $_SESSION['current']->hasPriv("admin")) + if($_SESSION['current']->isSuperMaintainer($oApp->iAppId) || $_SESSION['current']->hasPriv("admin")) { echo ' '; - echo ''; + echo ''; echo ''; echo ''; } 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 " "; - echo ' '; + echo ' '; } } else { @@ -299,18 +292,18 @@ if($_REQUEST['appId']) // description echo "
Super maintainers:
\n"; echo "
Description\n"; - echo $data->description; + echo $oApp->sDescription; echo "
\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) ? "".substr(stripslashes($ver->webPage),0,30)."": " "; + $appLinkURL = ($oApp->sWebpage) ? "".substr(stripslashes($oApp->sWebpage),0,30)."": " "; // start version display echo html_frame_start("","98%","",0); echo ""; echo '
',"\n"; echo '',"\n"; - echo "\n"; - echo "\n"; + echo "\n"; + echo "\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 " \n"; - echo "\n"; + echo "\n"; + echo "\n"; // image - $img = get_screenshot_img($appId, $_REQUEST['versionId']); + $img = get_screenshot_img($oApp->iAppId, $oVersion->iVersionId); echo "\n"; // display all maintainers of this application echo "
Name".stripslashes($data->appName)."
Version".stripslashes($ver->versionName)."
Name".$oApp->sName."
Version".$oVersion->sName."
Links\n"; @@ -372,17 +358,17 @@ else if($_REQUEST['versionId']) } // rating Area - echo "
Maintainer Rating".stripslashes($ver->maintainer_rating)."
Maintainers Version".stripslashes($ver->maintainer_release)."
Maintainer Rating".$oVersion->sTestedRating."
Maintainers Version".$oVersion->sTestedRelease."
$img
Maintainers of this application:\n"; echo ""; - $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 ''; echo ""; } else { /* are we already a maintainer? */ - if($_SESSION['current']->isMaintainer($_REQUEST['versionId'])) /* yep */ + if($_SESSION['current']->isMaintainer($oVersion->iVersionId)) /* yep */ { echo ''; echo ""; @@ -421,8 +407,8 @@ else if($_REQUEST['versionId']) } } - echo ""; - echo ""; + echo "iAppId."\">"; + echo "iVersionId."\">"; echo ""; } else { @@ -433,26 +419,26 @@ else if($_REQUEST['versionId']) echo ""; - if ($_SESSION['current']->hasPriv("admin") || $_SESSION['current']->isMaintainer($_REQUEST['versionId'])) + if ($_SESSION['current']->hasPriv("admin") || $_SESSION['current']->isMaintainer($oVersion->iVersionId)) { echo "
"; - echo '
'; + echo 'iAppId.'&versionId='.$oVersion->iVersionId.'>'; echo ''; echo '
'; - $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 "
"; echo ''; echo '
'; - echo '
'; + echo 'iVersionId.'>'; echo ''; echo '
'; echo ''; - echo '
'; + echo 'iVersionId.'>'; echo ''; echo ''; echo '
'; echo ''; - echo '
'; + echo 'iVersionId.'>'; echo ''; echo ''; echo '
'; @@ -463,7 +449,7 @@ else if($_REQUEST['versionId']) // description echo ""; /* 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 { diff --git a/include/application.php b/include/application.php index 0df7202..a390a46 100644 --- a/include/application.php +++ b/include/application.php @@ -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) { diff --git a/include/category.php b/include/category.php index 38b0a38..33446de 100644 --- a/include/category.php +++ b/include/category.php @@ -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); diff --git a/include/vendor.php b/include/vendor.php new file mode 100644 index 0000000..08bcfa0 --- /dev/null +++ b/include/vendor.php @@ -0,0 +1,112 @@ +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"; + } +} +?> diff --git a/include/version.php b/include/version.php new file mode 100644 index 0000000..cab3bf2 --- /dev/null +++ b/include/version.php @@ -0,0 +1,279 @@ +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); + } + +} +?>
Description
\n"; - echo $ver->description; + echo $oVersion->sDescription; echo "