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; } /* fetch versions of this application, if there are any */ $this->aVersionsIds = array(); /* 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; } if($hResult = query_appdb($sQuery)) { while($oRow = mysql_fetch_object($hResult)) { $this->aVersionsIds[] = $oRow->versionId; } } /* * 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; } } } } /** * Creates a new application. */ function create() { if(!$_SESSION['current']->canCreateApplication()) return; if($_SESSION['current']->appCreatedMustBeQueued()) $this->sQueued = 'true'; else $this->sQueued = 'false'; $aInsert = compile_insert_string(array( 'appName' => $this->sName, 'description'=> $this->sDescription, 'keywords' => $this->sKeywords, 'webPage' => $this->sWebpage, 'vendorId' => $this->iVendorId, 'catId' => $this->iCatId, 'submitterId'=> $_SESSION['current']->iUserId, 'queued' => $this->sQueued)); $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); $this->SendNotificationMail(); // Only administrators will be mailed as no supermaintainers exist for this app. return true; } else { return false; } } /** * Update application. * Returns true on success and false on failure. */ function update($bSilent=false) { $sWhatChanged = ""; /* if the user doesn't have permission to modify this application, don't let them */ if(!$_SESSION['current']->canModifyApplication($this)) return; /* create an instance of ourselves so we can see what has changed */ $oApp = new Application($this->iAppId); if ($this->sName && ($this->sName!=$oApp->sName)) { $sUpdate = compile_update_string(array('appName' => $this->sName)); if (!query_appdb("UPDATE appFamily SET ".$sUpdate." WHERE appId = ".$this->iAppId)) return false; $sWhatChanged .= "Name was changed from ".$oApp->sName." to ".$this->sName.".\n\n"; } if ($this->sDescription && ($this->sDescription!=$oApp->sDescription)) { $sUpdate = compile_update_string(array('description' => $this->sDescription)); if (!query_appdb("UPDATE appFamily SET ".$sUpdate." WHERE appId = ".$this->iAppId)) return false; $sWhatChanged .= "Description was changed from\n ".$oApp->sDescription."\n to \n".$this->sDescription.".\n\n"; } if ($this->sKeywords && ($this->sKeywords!=$oApp->sKeywords)) { $sUpdate = compile_update_string(array('keywords' => $this->sKeywords)); if (!query_appdb("UPDATE appFamily SET ".$sUpdate." WHERE appId = ".$this->iAppId)) return false; $sWhatChanged .= "Keywords were changed from\n ".$oApp->sKeywords."\n to \n".$this->sKeywords.".\n\n"; } if ($this->sWebpage && ($this->sWebpage!=$oApp->sWebpage)) { $sUpdate = compile_update_string(array('webPage' => $this->sWebpage)); if (!query_appdb("UPDATE appFamily SET ".$sUpdate." WHERE appId = ".$this->iAppId)) return false; $sWhatChanged .= "Web page was changed from ".$oApp->sWebpage." to ".$this->sWebpage.".\n\n"; } if ($this->iVendorId && ($this->iVendorId!=$oApp->iVendorId)) { $sUpdate = compile_update_string(array('vendorId' => $this->iVendorId)); if (!query_appdb("UPDATE appFamily SET ".$sUpdate." WHERE appId = ".$this->iAppId)) return false; $oVendorBefore = new Vendor($oApp->iVendorId); $oVendorAfter = new Vendor($this->iVendorId); $sWhatChanged .= "Vendor was changed from ".$oVendorBefore->sName." to ".$oVendorAfter->sName.".\n\n"; } if ($this->iCatId && ($this->iCatId!=$oApp->iCatId)) { $sUpdate = compile_update_string(array('catId' => $this->iCatId)); if (!query_appdb("UPDATE appFamily SET ".$sUpdate." WHERE appId = ".$this->iAppId)) return false; $oCatBefore = new Category($oApp->iCatId); $oCatAfter = new Category($this->iCatId); $sWhatChanged .= "Vendor was changed from ".$oCatBefore->sName." to ".$oCatAfter->sName.".\n\n"; } if($sWhatChanged and !$bSilent) $this->SendNotificationMail("edit",$sWhatChanged); return true; } /** * Deletes the application from the database. * and request the deletion of linked elements. */ function delete($bSilent=false) { /* make sure the current user has the appropriate permission to delete this application */ if(!$_SESSION['current']->canDeleteApplication($this)) return false; 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"); } $sQuery = "DELETE FROM appFamily WHERE appId = ".$this->iAppId." LIMIT 1"; if(!($hResult = query_appdb($sQuery))) { addmsg("Error deleting application!", "red"); } if(!$bSilent) $this->SendNotificationMail("delete"); return true; } /** * Move application out of the queue. */ function unQueue() { if(!$_SESSION['current']->canUnQueueApplication()) return; $sUpdate = compile_update_string(array('queued' => "false", 'keywords'=> str_replace(" *** ","",$this->sKeywords) )); if(query_appdb("UPDATE appFamily SET ".$sUpdate." WHERE appId = ".$this->iAppId)) { $this->sQueued = 'false'; // we send an e-mail to intersted people $this->mailSubmitter(); $this->SendNotificationMail(); } } function Reject() { if(!$_SESSION['current']->canRejectApplication($this)) return; // 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"); $this->SendNotificationMail("reject"); // the application has been rejectedd addmsg("The application has been rejected.", "green"); } } function ReQueue() { if(!$_SESSION['current']->canRequeueApplication($this)) 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 $this->SendNotificationMail(); // the application has been re-queued addmsg("The application has been re-queued.", "green"); } } function mailSubmitter($sAction="add") { $aClean = array(); //array of filtered user input $aClean['replyText'] = makeSafe($_REQUEST['replyText']); if($this->iSubmitterId) { $oSubmitter = new User($this->iSubmitterId); switch($sAction) { case "add": $sSubject = "Submitted application accepted"; $sMsg = "The application you submitted (".$oApp->sName." ".$this->sName.") has been accepted."; $sMsg .= "Administrators Responce:\n"; break; case "reject": $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"; break; case "delete": $sSubject = "Submitted application deleted"; $sMsg = "The application you submitted (".$oApp->sName." ".$this->sName.") has been deleted."; $sMsg .= "Reason given:\n"; break; $sMsg .= $aClean['replyText']."\n"; $sMsg .= "We appreciate your help in making the Application Database better for all users."; } mail_appdb($oSubmitter->sEmail, $sSubject ,$sMsg); } } function SendNotificationMail($sAction="add",$sMsg=null) { $aClean = array(); //array of filtered user input $aClean['replyText'] = makeSafe($_REQUEST['replyText']); switch($sAction) { case "add": if($this->sQueued == 'false') // Has been accepted. { $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"; } if($aClean['replyText']) { $sMsg .= "Appdb admin reply text:\n"; $sMsg .= $aClean['replyText']."\n"; // append the reply text, if there is any } addmsg("The application was successfully added into the database.", "green"); } else { $sSubject = $this->sName." has been submitted by ".$_SESSION['current']->sRealname; $sMsg .= "This application has been queued."; $sMsg .= "\n"; addmsg("The application you submitted will be added to the database after being reviewed.", "green"); } break; case "edit": $sSubject = $this->sName." has been modified by ".$_SESSION['current']->sRealname; $sMsg .= APPDB_ROOT."appview.php?appId=".$this->iAppId."\n"; addmsg("Application modified.", "green"); break; case "delete": $sSubject = $this->sName." has been deleted by ".$_SESSION['current']->sRealname; // if replyText is set we should report the reason the application was deleted if($aClean['replyText']) { $sMsg .= "Reason given:\n"; $sMsg .= $aClean['replyText']."\n"; // append the reply text, if there is any } addmsg("Application deleted.", "green"); break; case "reject": $sSubject = $this->sName." has been rejected by ".$_SESSION['current']->sRealname; $sMsg .= APPDB_ROOT."appsubmit.php?apptype=application&sub=view&appId=".$this->iAppId."\n"; // if replyText is set we should report the reason the application was rejected if($aClean['replyText']) { $sMsg .= "Reason given:\n"; $sMsg .= $aClean['replyText']."\n"; // append the reply text, if there is any } addmsg("Application rejected.", "green"); break; } $sEmail = get_notify_email_address_list($this->iAppId); if($sEmail) mail_appdb($sEmail, $sSubject ,$sMsg); } /* output a html table and this applications values to the fields for editing */ function OutputEditor($sVendorName) { HtmlAreaLoaderScript(array("app_editor")); echo ''; echo html_frame_start("Application Form", "90%", "", 0); echo "\n"; echo '',"\n"; echo '',"\n"; // app Category $w = new TableVE("view"); echo '',"\n"; // vendor name echo '',"\n"; echo '',"\n"; // alt vendor $x = new TableVE("view"); echo '',"\n"; // url echo '',"\n"; echo '',"\n"; echo '',"\n"; echo '',"\n"; echo '',"\n"; echo '',"\n"; else echo $this->sDescription.'

',"\n"; echo "
Application name
Category',"\n"; $w->make_option_list("appCatId", $this->iCatId,"appCategory","catId","catName"); echo '
Vendor
 ',"\n"; $x->make_option_list("appVendorId", $this->iVendorId,"vendor","vendorId","vendorName"); echo '
URL
Keywords
Application description

\n"; echo html_frame_end(); } function CheckOutputEditorInput() { $aClean = array(); //array of filtered user input $aClean['appCatId'] = makeSafe($_REQUEST['appCatId']); $aClean['appName'] = makeSafe($_REQUEST['appName']); $aClean['appVendorName'] = makeSafe($_REQUEST['appVendorName']); $aClean['appVendorId'] = makeSafe($_REQUEST['appVendorId']); $aClean['appDescription'] = makeSafe($_REQUEST['appDescription']); $errors = ""; if (empty($aClean['appCatId'])) $errors .= "
  • Please enter a category for your application.
  • \n"; if (strlen($aClean['appName']) > 200 ) $errors .= "
  • Your application name is too long.
  • \n"; if (empty($aClean['appName'])) $errors .= "
  • Please enter an application name.
  • \n"; // No vendor entered, and nothing in the list is selected if (empty($aClean['appVendorName']) && !$aClean['appVendorId']) $errors .= "
  • Please enter a vendor.
  • \n"; if (empty($aClean['appDescription'])) $errors .= "
  • Please enter a description of your application.
  • \n"; return $errors; } /* retrieves values from $_REQUEST that were output by OutputEditor() */ function GetOutputEditorValues() { $aClean = array(); //array of filtered user input $aClean['appId'] = makeSafe($_REQUEST['appId']); $aClean['appVendorId'] = makeSafe($_REQUEST['appVendorId']); $aClean['appName'] = makeSafe($_REQUEST['appName']); $aClean['appDescription'] = makeSafe($_REQUEST['appDescription']); $aClean['appCatId'] = makeSafe($_REQUEST['appCatId']); $aClean['appWebpage'] = makeSafe($_REQUEST['appWebpage']); $aClean['appKeywords'] = makeSafe($_REQUEST['appKeywords']); if(get_magic_quotes_gpc()) { $this->iAppId = stripslashes($aClean['appId']); $this->sName = stripslashes($aClean['appName']); $this->sDescription = stripslashes($aClean['appDescription']); $this->iCatId = stripslashes($aClean['appCatId']); $this->iVendorId = stripslashes($aClean['appVendorId']); $this->sWebpage = stripslashes($aClean['appWebpage']); $this->sKeywords = stripslashes($aClean['appKeywords']); } else { $this->iAppId = $aClean['appId']; $this->sName = $aClean['appName']; $this->sDescription = $aClean['appDescription']; $this->iCatId = $aClean['appCatId']; $this->iVendorId = $aClean['appVendorId']; $this->sWebpage = $aClean['appWebpage']; $this->sKeywords = $aClean['appKeywords']; } } /* display this application */ function display() { $aClean = array(); //array of filtered user input $aClean['appId'] = makeSafe($_REQUEST['appId']); /* 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) ? "sWebpage."\">".substr(stripslashes($this->sWebpage),0,30)."": " "; // start display application echo html_frame_start("","98%","",0); echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo "
    \n"; echo ' ',"\n"; echo " \n"; echo " \n"; // main URL echo " \n"; // optional links $result = query_appdb("SELECT * FROM appData WHERE appId = ".$aClean['appId']." AND versionID = 0 AND type = 'url'"); if($result && mysql_num_rows($result) > 0) { echo " \n"; } // image $img = get_screenshot_img($this->iAppId); echo "\n"; echo "
    Name ".$this->sName."
    Vendor ". " ".$oVendor->sName."  \n"; echo "
    Votes "; echo vote_count_app_total($this->iAppId); echo "
    URL".$appLinkURL."
    Links\n"; while($ob = mysql_fetch_object($result)) { echo " ".substr(stripslashes($ob->description),0,30)."
    \n"; } echo "
    $img
    \n"; /* close of name/vendor/bugs/url table */ echo "
    \n"; // Display all supermaintainers maintainers of this application echo " \n"; echo " \n"; $other_maintainers = getSuperMaintainersUserIdsFromAppId($this->iAppId); if($other_maintainers) { echo " \n"; } else { echo " \n"; } // Display the app maintainer button echo ' \n"; echo "
    Super maintainers:
      \n"; while(list($index, $userIdValue) = each($other_maintainers)) { $oUser = new User($userIdValue); echo "
    • ".$oUser->sRealname."
    • \n"; } echo "
    No maintainers.Volunteer today!
    '; if($_SESSION['current']->isLoggedIn()) { /* are we already a maintainer? */ if($_SESSION['current']->isSuperMaintainer($this->iAppId)) /* yep */ { echo '
    '; } else /* nope */ { echo ' '; } echo " iAppId."\">"; echo " "; /* set superMaintainer to 1 because we are at the appFamily level */ echo "
    "; if($_SESSION['current']->isSuperMaintainer($this->iAppId) || $_SESSION['current']->hasPriv("admin")) { echo '
    '; } if($_SESSION['current']->isLoggedIn()) { echo '
    '; echo ''; echo '
    '; } if($_SESSION['current']->hasPriv("admin")) { $url = BASE."admin/deleteAny.php?what=appFamily&appId=".$this->iAppId."&confirmed=yes"; echo "
    "; echo '
    '; } } else { echo '
    '; } echo "
    \n"; /* close of super maintainers table */ echo "
    \n"; /* close the table that contains the whole left hand side of the upper table */ // description echo " \n"; echo "
    Description\n"; echo $this->sDescription; echo "
    \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); } } /* * Application functions that are not part of the class */ function lookup_version_name($versionId) { if(!$versionId) return null; $result = query_appdb("SELECT versionName FROM appVersion WHERE versionId = $versionId"); if(!$result || mysql_num_rows($result) != 1) return null; $ob = mysql_fetch_object($result); return $ob->versionName; } function lookup_app_name($appId) { if(!$appId) return null; $result = query_appdb("SELECT appName FROM appFamily WHERE appId = $appId"); if(!$result || mysql_num_rows($result) != 1) return null; $ob = mysql_fetch_object($result); return $ob->appName; } /** * 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
    or

    $aDesc = explode("
    ",$aDesc[0],2); $aDesc = explode("
    ",$aDesc[0],2); $aDesc = explode("

    ",$aDesc[0],2); $aDesc = explode("

    ",$aDesc[0],2); return trim(strip_tags($aDesc[0])); } function GetDefaultApplicationDescription() { return "

    Enter a description of the application here

    "; } function showAppList($hResult) { //show applist echo html_frame_start("","90%","",0); echo ""; $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 "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "\n\n"; $c++; } echo "
    Submission Date Submitter Vendor Application Action
    ".print_date(mysqltimestamp_to_unixtimestamp($oApp->sSubmitTime))."\n"; echo $oSubmitter->sEmail ? "sEmail."\">":""; echo $oSubmitter->sRealname; echo $oSubmitter->sEmail ? "":""; echo " ".$sVendor."".$oApp->sName."[iAppId.">process]
    \n\n"; echo html_frame_end(" "); } ?>