objectManager: Fix lower-case letter in 'email Text'
[NewAppDB.git] / include / version.php
bloba7835f64eed4b85f208b3ccfe35bb71ec1e34037
1 <?php
2 /************************************/
3 /* this class represents an version */
4 /************************************/
6 require_once(BASE."include/note.php");
7 require_once(BASE."include/comment.php");
8 require_once(BASE."include/url.php");
9 require_once(BASE."include/screenshot.php");
10 require_once(BASE."include/bugs.php");
11 require_once(BASE."include/util.php");
12 require_once(BASE."include/testData.php");
13 require_once(BASE."include/downloadurl.php");
14 require_once(BASE."include/monitor.php");
15 require_once(BASE."include/vote.php");
17 define("LICENSE_OPENSOURCE", "Open Source");
18 define("LICENSE_SHAREWARE", "Shareware");
19 define("LICENSE_DEMO", "Demo");
20 define("LICENSE_RETAIL", "Retail");
21 define('LICENSE_FREETOUSE', 'Free to use');
22 define('LICENSE_FREETOSHARE', 'Free to use and share');
24 /**
25 * Version class for handling versions.
27 class version {
28 var $iVersionId;
29 var $iAppId;
30 var $oApp; /* Parento object */
31 var $sName;
32 var $sDescription;
33 var $sTestedRelease;
34 var $sTestedRating;
35 var $sSubmitTime;
36 var $iSubmitterId;
37 private $sState;
38 var $sLicense;
39 var $aTestResults; /* Array of test result objects. Especially useful when
40 we want to preview a version before submitting it;
41 in that case there is no data in the database */
42 var $iObsoleteBy; /* Whether this version is marked as obsolete, and if so which
43 version its votes should be moved to. */
44 var $iMaintainerRequest; /* Temporary variable for version submisson.
45 Indicates whether the user wants to become a
46 maintainer or monitor of the version being submitted.
47 Value denotes type of request. */
49 /**
50 * constructor, fetches the data.
52 public function Version($iVersionId = null, $oRow = null)
54 $this->aTestResults = array(); // should always be an array
55 // we are working on an existing version
56 if(!$iVersionId && !$oRow)
57 return;
60 * We fetch the data related to this version.
62 if(!$oRow)
64 $sQuery = "SELECT *
65 FROM appVersion
66 WHERE versionId = '?'";
67 if($hResult = query_parameters($sQuery, $iVersionId))
68 $oRow = query_fetch_object($hResult);
71 if($oRow)
73 $this->iVersionId = $oRow->versionId;
74 $this->iAppId = $oRow->appId;
75 $this->iSubmitterId = $oRow->submitterId;
76 $this->sSubmitTime = $oRow->submitTime;
77 $this->sName = $oRow->versionName;
78 $this->sDescription = $oRow->description;
79 $this->sTestedRelease = $oRow->ratingRelease;
80 $this->sTestedRating = $oRow->rating;
81 $this->sState = $oRow->state;
82 $this->sLicense = $oRow->license;
83 $this->iObsoleteBy = $oRow->obsoleteBy;
88 /**
89 * Creates a new version.
91 public function create()
93 if(!$_SESSION['current']->canCreateVersion())
94 return;
96 $oApp = new application($this->iAppId);
97 if($oApp->objectGetState() != 'accepted')
98 $this->sState = 'pending';
99 else
100 $this->sState = $this->mustBeQueued() ? 'queued' : 'accepted';
102 $hResult = query_parameters("INSERT INTO appVersion
103 (versionName, description, ratingRelease,
104 rating, appId, submitTime, submitterId,
105 state, license)
106 VALUES ('?', '?', '?', '?', '?', ?, '?', '?', '?')",
107 $this->sName, $this->sDescription, $this->sTestedRelease,
108 $this->sTestedRating, $this->iAppId, "NOW()",
109 $_SESSION['current']->iUserId, $this->sState,
110 $this->sLicense);
112 if($hResult)
114 $this->iVersionId = query_appdb_insert_id();
115 $this->Version($this->iVersionId);
116 $this->SendNotificationMail();
118 /* Submit maintainer request if asked to */
119 switch($this->iMaintainerRequest)
121 case MAINTAINER_REQUEST;
122 $oMaintainer = new Maintainer();
123 $oMaintainer->iAppId = $this->iAppId;
124 $oMaintainer->iVersionId = $this->iVersionId;
125 $oMaintainer->iUserId = $_SESSION['current']->iUserId;
126 $oMaintainer->sMaintainReason = "This user submitted the version;".
127 "auto-queued.";
128 $oMaintainer->bSuperMaintainer = 0;
129 $oMaintainer->create();
130 break;
132 case MONITOR_REQUEST:
133 $oMonitor = new Monitor();
134 $oMonitor->iVersionId = $this->iVersionId;
135 $oMonitor->iUserId = $_SESSION['current']->iUserId;
136 $oMonitor->iAppId = $this->iAppId;
137 $oMonitor->create();
138 break;
140 return true;
142 else
144 addmsg("Error while creating a new version", "red");
145 return false;
151 * Update version.
153 public function update($bSilent=false)
155 $sWhatChanged = "";
157 if(!$_SESSION['current']->hasAppVersionModifyPermission($this))
158 return;
160 $oVersion = new Version($this->iVersionId);
162 if ($this->sName && ($this->sName!=$oVersion->sName))
164 if (!query_parameters("UPDATE appVersion SET versionName = '?' WHERE versionId = '?'",
165 $this->sName, $this->iVersionId))
166 return false;
167 $sWhatChanged .= "Name was changed from:\n\t'".$oVersion->sName."'\nto:\n\t'".$this->sName."'\n\n";
170 if ($this->sDescription && ($this->sDescription!=$oVersion->sDescription))
172 if (!query_parameters("UPDATE appVersion SET description = '?' WHERE versionId = '?'",
173 $this->sDescription, $this->iVersionId))
174 return false;
176 if($oVersion->sDescription != "")
177 $sWhatChanged .= "Description was changed from\n ".$oVersion->sDescription."\n to \n".$this->sDescription.".\n\n";
178 else
179 $sWhatChanged .= "Description was changed to \n".$this->sDescription.".\n\n";
182 if ($this->sTestedRelease && ($this->sTestedRelease!=$oVersion->sTestedRelease))
184 if (!query_parameters("UPDATE appVersion SET ratingRelease = '?' WHERE versionId = '?'",
185 $this->sTestedRelease, $this->iVersionId))
186 return false;
188 if($oVersion->sTestedRelease != "")
189 $sWhatChanged .= "Last tested release was changed from ".$oVersion->sTestedRelease." to ".$this->sTestedRelease.".\n\n";
190 else
191 $sWhatChanged .= "Last tested release was changed to ".$this->sTestedRelease.".\n\n";
194 if ($this->sTestedRating && ($this->sTestedRating!=$oVersion->sTestedRating))
196 if (!query_parameters("UPDATE appVersion SET rating = '?' WHERE versionId = '?'",
197 $this->sTestedRating, $this->iVersionId))
198 return false;
200 if($this->sTestedRating != "")
201 $sWhatChanged .= "Rating was changed from ".$oVersion->sTestedRating." to ".$this->sTestedRating.".\n\n";
202 else
203 $sWhatChanged .= "Rating was changed to ".$this->sTestedRating.".\n\n";
206 if ($this->iAppId && ($this->iAppId!=$oVersion->iAppId))
208 $oAppBefore = new Application($oVersion->iAppId);
209 $oAppAfter = new Application($this->iAppId);
211 if($oAppAfter->objectGetState() == 'accepted' && $this->sState == 'pending')
212 $this->sState = 'queued';
214 if (!query_parameters("UPDATE appVersion SET appId = '?', state = '?' WHERE versionId = '?'",
215 $this->iAppId, $this->sState, $this->iVersionId))
216 return false;
218 $sWhatChanged .= "Version was moved from application ".$oAppBefore->sName." to application ".$oAppAfter->sName.".\n\n";
221 if ($this->sLicense && ($this->sLicense!=$oVersion->sLicense))
223 if(!query_parameters("UPDATE appVersion SET license = '?'
224 WHERE versionId = '?'",
225 $this->sLicense, $this->iVersionId))
226 return FALSE;
228 $sWhatChanged .= "License was changed from $oVersion->sLicense to ".
229 "$this->sLicense.\n\n";
232 if($this->iObsoleteBy != $oVersion->iObsoleteBy)
234 if(!query_parameters("UPDATE appVersion SET obsoleteBy = '?' WHERE versionId = '?'",
235 $this->iObsoleteBy, $this->iVersionId))
236 return FALSE;
238 if($this->iObsoleteBy)
239 $sWhatChanged .= "The version was marked as obsolete.\n\n";
240 else
241 $sWhatChanged .= "The version is no longer marked as obsolete.\n\n";
243 if($this->iObsoleteBy)
245 query_parameters("UPDATE appVotes SET versionId = '?' WHERE versionId = '?'",
246 $this->iObsoleteBy, $this->iVersionId);
250 if($sWhatChanged and !$bSilent)
251 $this->SendNotificationMail("edit",$sWhatChanged);
252 return true;
256 * Removes the version from the database and
257 * requests the same action for child entries
259 public function purge()
261 /* We need the versionId to continue */
262 if(!$this->iVersionId)
263 return;
265 /* is the current user allowed to delete this version? */
266 if(!$_SESSION['current']->canDeleteVersion($this))
267 return false;
269 $bSuccess = TRUE;
271 foreach($this->objectGetChildren(TRUE) as $oChild)
273 if(!$oChild->purge())
274 $bSuccess = FALSE;
277 /* now remove the version from the DB */
278 $hResult = query_parameters("DELETE FROM appVersion
279 WHERE versionId = '?'
280 LIMIT 1", $this->iVersionId);
281 if(!$hResult)
282 $bSuccess = FALSE;
284 return $bSuccess;
288 * Flags the version as deleted
289 * and request the deletion of linked elements.
291 public function delete()
293 /* We need the versionId to continue */
294 if(!$this->iVersionId)
295 return;
297 /* is the current user allowed to delete this version? */
298 if(!$_SESSION['current']->canDeleteVersion($this))
299 return false;
301 $bSuccess = TRUE;
303 foreach($this->objectGetChildren() as $oChild)
305 if(!$oChild->delete())
306 $bSuccess = FALSE;
309 /* now flag the version as deleted */
310 $hResult = query_parameters("UPDATE appVersion SET state = 'deleted'
311 WHERE versionId = '?'
312 LIMIT 1", $this->iVersionId);
313 if(!$hResult)
314 $bSuccess = FALSE;
316 return $bSuccess;
320 * Move version out of the queue.
322 public function unQueue()
324 if(!$_SESSION['current']->canUnQueueVersion($this))
325 return;
327 // If we are not in the queue, we can't move the version out of the queue.
328 if($this->sState == 'accepted')
329 return false;
331 if(query_parameters("UPDATE appVersion SET state = '?' WHERE versionId = '?'",
332 'accepted', $this->iVersionId))
334 $this->sState = 'accepted';
335 // we send an e-mail to interested people
336 $this->mailSubmitter("add");
337 $this->SendNotificationMail();
339 /* Unqueue matching maintainer request */
340 $hResultMaint = query_parameters("SELECT maintainerId FROM
341 appMaintainers WHERE userId = '?' AND versionId = '?'",
342 $this->iSubmitterId, $this->iVersionId);
344 if($hResultMaint && query_num_rows($hResultMaint))
346 $oMaintainerRow = query_fetch_object($hResultMaint);
347 $oMaintainer = new Maintainer($oMaintainerRow->maintainerId);
348 $oMaintainer->unQueue("OK");
353 public function Reject($bSilent=false)
355 if(!$_SESSION['current']->canRejectVersion($this))
356 return;
358 // If we are not in the queue, we can't move the version out of the queue.
359 if($this->sState != 'queued')
360 return false;
362 if(query_parameters("UPDATE appVersion SET state = '?' WHERE versionId = '?'",
363 'rejected', $this->iVersionId))
365 $this->sState = 'rejected';
366 // we send an e-mail to interested people
367 if(!$bSilent)
369 $this->mailSubmitter("reject");
370 $this->SendNotificationMail("reject");
372 // the version has been unqueued
373 addmsg("The version has been rejected.", "green");
377 public function ReQueue()
379 if(!$_SESSION['current']->canRequeueVersion($this))
380 return;
382 if(query_parameters("UPDATE appVersion SET state = '?' WHERE versionId = '?'",
383 'queued', $this->iVersionId))
385 $this->sState = 'queued';
386 // we send an e-mail to interested people
387 $this->SendNotificationMail();
389 // the version has been unqueued
390 addmsg("The version has been re-submitted", "green");
394 public function objectGetSubmitterId()
396 return $this->iSubmitterId;
399 public static function objectGetMailOptions($sAction, $bMailSubmitter,
400 $bParentAction)
402 return new mailOptions();
405 public function objectGetMail($sAction, $bMailSubmitter, $bParentAction)
407 $oApp = new application($this->iAppId);
409 if($bMailSubmitter)
411 switch($sAction)
413 case "delete":
414 $sSubject = "Submitted version deleted";
415 $sMsg = "The version you submitted (".$oApp->sName." ".$this->sName.
416 ") has been deleted.";
417 break;
419 $aMailTo = null;
420 } else
422 switch($sAction)
424 case "delete":
425 $sSubject = "Version '".$this->sName."' of '".$oApp->sName."' ".
426 "deleted";
427 $sMsg = "";
428 break;
430 $aMailTo = User::get_notify_email_address_list(null, $this->iVersionId);
432 return array($sSubject, $sMsg, $aMailTo);
435 private function mailSubmitter($sAction="add")
437 global $aClean; //FIXME: we should pass the sReplyText value in
439 // use 'sReplyText' if it is defined, otherwise define the value as an empty string
440 if(!isset($aClean['sReplyText']))
441 $aClean['sReplyText'] = "";
443 if($this->iSubmitterId)
445 $oApp = new Application($this->iAppId);
446 $oSubmitter = new User($this->iSubmitterId);
447 switch($sAction)
449 case "add":
450 $sSubject = "Submitted version accepted";
451 $sMsg = "The version you submitted (".$oApp->sName." ".$this->sName.") has been accepted by ".$_SESSION['current']->sRealname.".\n";
452 $sMsg .= "Administrators response:\n";
453 break;
454 case "reject":
455 $sSubject = "Submitted version rejected";
456 $sMsg = "The version you submitted (".$oApp->sName." ".$this->sName.") has been rejected by ".$_SESSION['current']->sRealname.".";
457 $sMsg .= "Clicking on the link in this email will allow you to modify and resubmit the version. ";
458 $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. ";
459 $sMsg .= APPDB_ROOT."objectManager.php?sClass=version_queue".
460 "&amp;bIsQueue=true&amp;bIsRejected=true&amp;iId=".$this->iVersionId."&amp;".
461 "sTitle=Edit+Version\n";
462 break;
464 $sMsg .= $aClean['sReplyText']."\n";
465 $sMsg .= "We appreciate your help in making the Version Database better for all users.";
467 mail_appdb($oSubmitter->sEmail, $sSubject ,$sMsg);
471 private function SendNotificationMail($sAction="add",$sMsg=null)
473 global $aClean;
475 // use 'sReplyText' if it is defined, otherwise define the value as an empty string
476 if(!isset($aClean['sReplyText']))
477 $aClean['sReplyText'] = "";
479 $oApp = new Application($this->iAppId);
480 switch($sAction)
482 case "add":
483 if($this->sState == 'accepted')
485 $sSubject = "Version ".$this->sName." of ".$oApp->sName." added by ".$_SESSION['current']->sRealname;
486 $sMsg = $this->objectMakeUrl()."\n";
487 if($this->iSubmitterId)
489 $oSubmitter = new User($this->iSubmitterId);
490 $sMsg .= "This version has been submitted by ".$oSubmitter->sRealname.".";
491 $sMsg .= "\n";
493 if($aClean['sReplyText'])
495 $sMsg .= "Appdb admin reply text:\n";
496 $sMsg .= $aClean['sReplyText']."\n"; // append the reply text, if there is any
499 addmsg("The version was successfully added into the database.", "green");
500 } else // Version queued.
502 $sSubject = "Version '".$this->sName."' of '".$oApp->sName."' submitted by ".$_SESSION['current']->sRealname;
503 $sMsg .= "This version has been queued.";
504 $sMsg .= "\n";
505 addmsg("The version you submitted will be added to the database after being reviewed.", "green");
507 break;
508 case "edit":
509 $sSubject = "'".$oApp->sName." ".$this->sName."' has been modified by ".$_SESSION['current']->sRealname;
510 $sMsg .= $this->objectMakeUrl()."\n";
511 addmsg("Version modified.", "green");
512 break;
513 case "delete":
515 // if sReplyText is set we should report the reason the application was deleted
516 if($aClean['sReplyText'])
518 $sMsg .= "Reason given:\n";
519 $sMsg .= $aClean['sReplyText']."\n"; // append the reply text, if there is any
522 addmsg("Version deleted.", "green");
523 break;
524 case "reject":
525 $sSubject = "Version '".$this->sName."' of '".$oApp->sName."' has been rejected by ".$_SESSION['current']->sRealname;
526 $sMsg .= APPDB_ROOT."objectManager.php?sClass=version_queue".
527 "&amp;bIsQueue=true&amp;bIsRejected=true&amp;iId=".$this->iVersionId."&amp;".
528 "sTitle=Edit+Version\n";
530 // if sReplyText is set we should report the reason the version was rejected
531 if($aClean['sReplyText'])
533 $sMsg .= "Reason given:\n";
534 $sMsg .= $aClean['sReplyText']."\n"; // append the reply text, if there is any
537 addmsg("Version rejected.", "green");
538 break;
540 $sEmail = User::get_notify_email_address_list(null, $this->iVersionId);
541 if($sEmail)
542 mail_appdb($sEmail, $sSubject ,$sMsg);
545 public function get_buglink_ids()
548 * We fetch Bug linkIds.
550 $aBuglinkIds = array();
551 $sQuery = "SELECT *
552 FROM buglinks
553 WHERE versionId = '?'
554 ORDER BY bug_id";
555 if($hResult = query_parameters($sQuery, $this->iVersionId))
557 while($oRow = query_fetch_object($hResult))
559 $aBuglinkIds[] = $oRow->linkId;
563 return $aBuglinkIds;
566 /* Makes a frame with title 'Mark as obsolete' and info about what it means, plus
567 caller-defined content */
568 private static function makeObsoleteFrame($sContent = "")
570 $sMsg = html_frame_start("Mark as obsolete", "90%", "", 0);
572 $sMsg .= "Some applications need to be updated from time to time in order to ";
573 $sMsg .= "be of any use. An example is online multi-player games, where you need ";
574 $sMsg .= "to be running a version compatible with the server. ";
575 $sMsg .= "If this is such an application, and this version is no longer usable, ";
576 $sMsg .= "you can mark it as obsolete and move its current votes to a usable ";
577 $sMsg .= "version instead.<br><br>";
579 $sMsg .= $sContent;
581 $sMsg .= html_frame_end();
583 return $sMsg;
586 /* output html and the current versions information for editing */
587 /* if $editParentApplication is true that means we need to display fields */
588 /* to let the user change the parent application of this version */
589 /* otherwise, if $editParentAppliation is false, we leave them out */
590 public function outputEditor()
592 HtmlAreaLoaderScript(array("version_editor"));
593 echo html_frame_start("Version Form", "90%", "", 0);
595 echo '<input type="hidden" name="iVersionId" value="'.$this->iVersionId.'">';
597 $oTable = new Table();
598 $oTable->SetClass("color0");
599 $oTable->SetWidth("100%");
600 $oTable->SetBorder(0);
601 $oTable->SetCellPadding(2);
602 $oTable->SetCellSpacing(0);
604 /* Fill in appId value */
605 global $aClean;
606 if(!$this->iAppId)
607 $this->iAppId = $aClean['iAppId'];
609 if($this->sState == 'accepted' && $this->iVersionId)
611 // app parent
612 $x = new TableVE("view");
613 $oTableRow = new TableRow();
614 $oTableRow->SetValign("top");
616 $oTableCell = new TableCell("Application");
617 $oTableCell->SetBold(true);
618 $oTableRow->AddCell($oTableCell);
620 $sOptionList = $x->make_option_list("iAppId", $this->iAppId,
621 "appFamily", "appId", "appName");
622 $oTableCell = new TableCell($sOptionList);
623 $oTableCell->SetClass("color0");
625 $oTableRow->AddCell($oTableCell);
627 $oTable->AddRow($oTableRow);
628 } else
630 echo '<input type="hidden" name="iAppId" value="'.$this->iAppId.'">';
633 // version name
634 $oTableRow = new TableRow();
635 $oTableRow->SetValign("top");
637 $oTableCell = new TableCell("Version Name");
638 $oTableCell->SetBold(true);
639 $oTableCell->SetClass("color0");
640 $oTableRow->AddCell($oTableCell);
642 $oTableRow->AddTextCell('<input size="20" type="text" name="sVersionName" value="'.$this->sName.'">');
644 $oTable->AddRow($oTableRow);
646 // version license
647 $oTableRow = new TableRow();
648 $oTableCell = new TableCell("License");
649 $oTableCell->SetBold(true);
650 $oTableCell->SetClass("color0");
651 $oTableRow->AddCell($oTableCell);
653 $oTableRow->AddTextCell($this->makeLicenseList());
655 $oTable->AddRow($oTableRow);
657 // version description
658 $oTableRow = new TableRow();
659 $oTableRow->SetValign("top");
661 $oTableCell = new TableCell("Version description");
662 $oTableCell->SetBold(true);
663 $oTableCell->SetClass("color0");
664 $oTableRow->AddCell($oTableCell);
666 $oTableRow->AddTextCell('<p><textarea cols="80" rows="20" id="version_editor" name="shVersionDescription">'.
667 $this->sDescription.'</textarea></p>');
669 $oTable->AddRow($oTableRow);
671 // output the table
672 echo $oTable->GetString();
674 echo html_frame_end();
676 if($this->sState == 'accepted' && $this->iVersionId)
678 /* Mark as obsolete */
679 $oApp = new application($this->iAppId);
680 $oVersionInDB = new version($this->iVersionId);
682 if($oVersionInDB->iObsoleteBy)
684 $sObsoleteTxt = "<input type=\"checkbox\" name=\"bObsolete\" value=\"true\" checked=\"checked\">";
685 $sObsoleteTxt .= " This version is obsolete";
686 echo $this->makeObsoleteFrame($sObsoleteTxt);
688 echo "<input type=\"hidden\" name=\"iObsoleteBy\" value=\"".
689 $oVersionInDB->iObsoleteBy."\" type=\"hidden\" >\n";
690 } else if(sizeof($oApp->getVersions(TRUE, FALSE)) > 1)
692 if($this->iObsoleteBy)
693 $sObsolete = "checked=\"checked\"";
694 else
695 $sObsolete = "";
697 $sObsoleteTxt = "<input type=\"checkbox\" name=\"bObsolete\" value=\"true\"$sObsolete >";
698 $sObsoleteTxt .= "Mark as obsolete and move votes to \n";
699 $sObsoleteTxt .= $oApp->makeVersionDropDownList("iObsoleteBy", $this->iObsoleteBy, $this->iVersionId, FALSE);
701 echo $this->makeObsoleteFrame($sObsoleteTxt);
703 } else
705 echo '<input type="hidden" name="sMaintainerRating" value="'.$this->sTestedRating.'">';
706 echo '<input type="hidden" name="sMaintainerRelease" value="'.$this->sTestedRelease.'">';
710 public function CheckOutputEditorInput($aValues)
712 $errors = "";
714 if (empty($aValues['sVersionName']))
715 $errors .= "<li>Please enter an application version.</li>\n";
717 if (empty($aValues['shVersionDescription']))
718 $errors .= "<li>Please enter a version description.</li>\n";
720 return $errors;
723 /* retrieves values from $aValues that were output by outputEditor() */
724 /* $aValues can be $_REQUEST or any array with the values from outputEditor() */
725 public function GetOutputEditorValues($aValues)
727 if($aValues['iAppId'])
728 $this->iAppId = $aValues['iAppId'];
730 if($aValues['iVersionId'])
731 $this->iVersionId = $aValues['iVersionId'];
733 $this->sName = $aValues['sVersionName'];
734 $this->sDescription = $aValues['shVersionDescription'];
735 $this->sLicense = $aValues['sLicense'];
736 $this->iMaintainerRequest = $aValues['iMaintainerRequest'];
738 if($aValues['bObsolete'] == "true")
739 $this->iObsoleteBy = $aValues['iObsoleteBy'];
740 else
741 $this->iObsoleteBy = 0;
744 public function objectGetCustomTitle($sAction)
746 switch($sAction)
748 case 'delete':
749 return 'Delete '.version::fullName($this->iVersionId);
750 case "view":
751 return version::fullName($this->iVersionId);
753 default:
754 return null;
758 public static function objectGetCustomVars($sAction)
760 switch($sAction)
762 case "view":
763 /* Allow the user to select which test report is
764 shown in the version view */
765 return array("iTestingId");
767 default:
768 return null;
772 public function objectShowPreview()
774 return TRUE;
777 /* Not standard OM function yet, but will be in the future */
778 public function objectGetParent()
780 /* No id so we can't query the DB, but perhaps an entry is cached? */
781 if(!$this->iAppId)
782 return $this->oApp;
784 return new application($this->iAppId);
787 public function getRatingInfo()
789 return testData::getRatingInfoForVersionId($this->iVersionId);
792 public function updateRatingInfo()
794 $aRatingInfo = $this->getRatingInfo();
796 $hResult = query_parameters("UPDATE appVersion SET
797 rating = '?',
798 ratingRelease = '?'
799 WHERE versionId = '?'",
800 $aRatingInfo[0],
801 $aRatingInfo[1],
802 $this->iVersionId);
804 if(!$hResult)
805 return false;
807 return true;
810 public function display($aVars = array())
812 /* is this user supposed to view this version? */
813 if(!$_SESSION['current']->canViewVersion($this))
814 util_show_error_page_and_exit("Something went wrong with the application or version id");
816 $iTestingId = $aVars['iTestingId'] ? $aVars['iTestingId'] : 0;
818 $oApp = $this->objectGetParent();
820 // cat
821 $oCategory = new Category($oApp->iCatId);
822 $oCategory->display($oApp->iAppId, $this->iVersionId);
824 // set URL
825 $appLinkURL = ($oApp->sWebpage) ? trimmed_link($oApp->sWebpage,30) : "&nbsp;";
827 // start version display
828 echo html_frame_start("","98%","",0);
829 echo '<tr><td class="color4" valign="top">',"\n";
830 echo '<table width="250" border="0" cellpadding="3" cellspacing="1">',"\n";
831 echo "<tr class=\"color0\" valign=\"top\"><td width=\"100\"> <b>Name</b></td><td width=\"100%\">".$oApp->sName."</td>\n";
832 echo "<tr class=\"color1\" valign=\"top\"><td><b>Version</b></td><td>".$this->sName."</td></tr>\n";
833 echo html_tr(array(
834 "<b>License</b>",
835 $this->sLicense),
836 "color0");
838 // main URL
839 echo " <tr class=\"color1\"><td><b>URL</b></td><td>".$appLinkURL."</td></tr>\n";
841 // Votes
842 if(!$this->iObsoleteBy)
844 $oM = new objectManager("voteManager", "Vote");
845 $oM->setReturnTo($this->objectMakeUrl());
847 if($_SESSION['current']->isLoggedIn())
848 $shVoteLink = ' &nbsp; <a href="'.$oM->makeUrl("edit", $_SESSION['current']->iUserId).'&amp;iVersionId='.$this->iVersionId.'">Vote</a>';
849 else
850 $shVoteLink = '';
852 $shVoteText = vote_count_version_total($this->iVersionId).$shVoteLink;
853 } else
855 $shVoteText = 'Marked as obsolete';
858 echo html_tr(array('<b>Votes</b>', $shVoteText), 'color0');
860 $sRating = $this->sTestedRating;
861 $sRelease = $this->sTestedRelease;
862 if($sRating != "/" && $sRating)
863 $sRatingColor = $sRating;
864 else
865 $sRatingColor = 'color0';
867 // URLs
868 if($sUrls = url::display($this->iVersionId))
870 echo $sUrls;
873 // rating Area
874 echo "<tr class=\"$sRatingColor\" valign=\"top\"><td><b>Rating</b></td><td>".$sRating."</td></tr>\n";
875 echo "<tr class=\"$sRatingColor\" valign=\"top\"><td><b>Wine Version</b></td><td>".$sRelease."</td></tr>\n";
877 // Download URLs
878 if($sDownloadurls = downloadurl::display($this->iVersionId))
879 echo $sDownloadurls;
881 // image
882 $img = Screenshot::get_random_screenshot_img($oApp->iAppId, $this->iVersionId, false);
883 echo "<tr><td align=\"center\" colspan=\"2\">$img</td></tr>\n";
885 // display all maintainers of this application
886 echo "<tr class=\"color0\"><td align=\"left\" colspan=\"2\"><b>Maintainers of this version:</b>\n";
887 echo "<table width=\"250\" border=\"0\">";
888 $aMaintainers = $this->getMaintainersUserIds();
889 if(sizeof($aMaintainers)>0)
891 echo "<tr class=\"color0\"><td align=\"left\" colspan=\"2\"><ul>";
892 while(list($index, $userIdValue) = each($aMaintainers))
894 $oUser = new User($userIdValue);
895 echo "<li>".$oUser->objectMakeLink()."</li>";
897 echo "</ul></td></tr>\n";
898 } else
900 echo "<tr class=color0><td align=right colspan=2>";
901 echo "No maintainers. Volunteer today!</td></tr>\n";
903 echo "</table></td></tr>\n";
905 // display the app maintainer button
906 echo '<tr><td colspan="2" align="center">'."\n";
907 if($_SESSION['current']->isLoggedIn())
909 /* is this user a maintainer of this version by virtue of being a super maintainer */
910 /* of this app family? */
911 if($_SESSION['current']->isSuperMaintainer($oApp->iAppId))
913 echo '<form method="post" name="sMessage" action="maintainerdelete.php">'."\n";
914 echo "\t".'<input type="submit" value="Remove yourself as a super maintainer" class="button">'."\n";
915 echo "\t".'<input type="hidden" name="iSuperMaintainer" value="1">'."\n";
916 echo "\t<input type=hidden name=\"iAppId\" value=\"".$oApp->iAppId."\">\n";
917 echo "\t<input type=hidden name=\"iVersionId\" value=\"".$this->iVersionId."\">\n";
918 echo "</form>\n";
919 } else
921 /* are we already a maintainer? */
922 if($_SESSION['current']->isMaintainer($this->iVersionId)) /* yep */
924 echo '<form method="post" name="sMessage" action="maintainerdelete.php">'."\n";
925 echo "\t".'<input type="submit" value="Remove yourself as a maintainer" class=button>'."\n";
926 echo "\t".'<input type="hidden" name="iSuperMaintainer" value="0">'."\n";
927 echo "\t"."<input type=hidden name=\"iAppId\" value=\"".$oApp->iAppId."\">\n";
928 echo "\t"."<input type=hidden name=\"iVersionId\" value=\"".$this->iVersionId."\">\n";
929 echo "</form>\n";
930 } else /* nope */
932 echo '<form method="post" name="sMessage" action="objectManager.php?sClass=maintainer&amp;sAction=add&amp;iVersionId='.$this->iVersionId.'&amp;sTitle='.urlencode("Be a Maintainer of ".version::fullName($this->iVersionId)).'&amp;sReturnTo='.urlencode($this->objectMakeUrl()).'">'."\n";
933 echo "\t".'<input type="submit" value="Be a Maintainer of This Version" class="button" title="Click here to know more about maintainers.">'."\n";
934 echo "\t"."<input type=hidden name=\"iAppId\" value=\"".$oApp->iAppId."\">\n";
935 echo "\t"."<input type=hidden name=\"iVersionId\" value=\"".$this->iVersionId."\">\n";
936 echo "</form>\n";
937 $oMonitor = new Monitor();
938 $oMonitor->find($_SESSION['current']->iUserId, $this->iVersionId);
939 if(!$oMonitor->iMonitorId)
941 echo '<form method="post" name="sMessage" action="'.
942 APPDB_ROOT."objectManager.php\">\n";
943 echo "\t<input type=\"hidden\" name=\"iAppId\" value=\"".
944 $this->iAppId."\" >\n";
945 echo "\t<input type=\"hidden\" name=\"iVersionId\" value=\"".
946 $this->iVersionId."\" >\n";
947 echo "\t<input type=\"hidden\" name=\"sSubmit\" value=\"Submit\" >\n";
948 echo "\t<input type=\"hidden\" name=\"sClass\" value=\"monitor\" >\n";
949 echo "\t<input type=\"hidden\" name=\"sReturnTo\" value=\"".
950 $this->objectMakeUrl()."\" >\n";
951 echo "\t".'<input type=submit value="Monitor Changes" class="button">'."\n";
952 echo "</form>\n";
957 } else
959 echo '<form method="post" name="sMessage" action="account.php">'."\n";
960 echo "\t".'<input type="hidden" name="sCmd" value="login">'."\n";
961 echo "\t".'<input type=submit value="Log in to become an app maintainer" class="button">'."\n";
962 echo '</form>'."\n";
965 echo "</td></tr>";
967 if ($_SESSION['current']->hasPriv("admin") || $_SESSION['current']->isMaintainer($this->iVersionId) || $_SESSION['current']->isSuperMaintainer($this->iAppId))
969 $shAdd = '<form method="post" name="sMessage" action="objectManager.php?sClass=note&amp;sAction=add&amp;iVersionId='.$this->iVersionId.'&amp;sReturnTo='.urlencode($this->objectMakeUrl());
970 echo '<tr><td colspan="2" align="center">'."\n";
971 echo '<form method="post" name="sMessage" action="admin/editAppVersion.php">'."\n";
972 echo "\t".'<input type="hidden" name="iAppId" value="'.$oApp->iAppId.'">'."\n";
973 echo "\t".'<input type="hidden" name="iVersionId" value="'.$this->iVersionId.'">'."\n";
974 echo "\t".'<input type=submit value="Edit Version" class="button">'."\n";
975 echo '</form>'."\n";
976 $url = BASE."objectManager.php?sClass=version&amp;sAction=delete&amp;bQueued=false&amp;iId=".$this->iVersionId;
977 echo "<form method=\"post\" name=\"sDelete\" action=\"javascript:self.location = '".$url."'\">\n";
978 echo "\t".'<input type=submit value="Delete Version" class="button">'."\n";
979 echo '</form>'."\n";
980 echo $shAdd.'" />';
981 echo "\t".'<input type="submit" value="Add Note" class="button">'."\n";
982 echo '</form>'."\n";
983 echo $shAdd.'&amp;sNoteTitle=HOWTO" />';
984 echo "\t".'<input type=submit value="Add How To" class="button">'."\n";
985 echo '</form>'."\n";
986 echo $shAdd.'&amp;sNoteTitle=WARNING" />';
987 echo "\t".'<input type=submit value="Add Warning" class="button">'."\n";
988 echo '</form>';
989 echo "</td></tr>";
991 $oMonitor = new Monitor();
992 $oMonitor->find($_SESSION['current']->iUserId, $this->iVersionId);
993 if($oMonitor->iMonitorId)
995 echo '<tr><td colspan="2" align="center">'."\n";
996 echo '</form>'."\n";
997 echo '<form method="post" name="sMessage" action="'.
998 APPDB_ROOT."objectManager.php\">\n";
999 echo "\t<input type=\"hidden\" name=\"iId\" value=\"".
1000 $oMonitor->iMonitorId."\">\n";
1001 echo "\t<input type=\"hidden\" name=\"sSubmit\" value=\"Delete\">\n";
1002 echo "\t<input type=\"hidden\" name=\"sClass\" value=\"monitor\">\n";
1003 echo "\t<input type=\"hidden\" name=\"sReturnTo\" value=\"".
1004 $this->objectMakeUrl()."\">\n";
1005 echo '<input type=submit value="Stop Monitoring Version" class="button" >'."\n";
1006 echo "</form>\n";
1007 echo "</td></tr>\n";
1009 echo "</table>\n";
1011 // start of the right hand pane in the version display
1012 echo "<td class=color2 valign=top width='100%'>\n";
1013 echo "<div class='version_info_pane'>\n";
1015 /////////////////////////
1016 // output the description
1017 echo "<div class='info_container'>\n";
1019 // output the description title
1020 echo "\t<div class='title_class'>\n";
1021 echo "\t\tDescription\n";
1022 echo "\t</div>\n";
1024 // output the description
1025 echo "\t<div class='info_contents'>\n";
1026 echo "\t\t".$this->sDescription."\n";
1027 echo "\t</div>\n";
1029 echo "</div>\n"; // end the 'info_container' div
1030 // end description
1031 /////////////////////////
1034 //////////////////////
1035 // Show test data
1037 $iNewestId = 0;
1038 $oTest = null;
1040 /* Set if the use chose to display a particular test report */
1041 if($iTestingId)
1043 $oTest = new testData($iTestingId);
1044 $oTestParent = $oTest->objectGetParent();
1046 /* Check that the test report doesn't belong to another version */
1047 if($oTestParent->objectGetId() && $oTestParent->objectGetId() != $this->objectGetId())
1048 $oTest = null;
1051 if(!$oTest && $this->iVersionId) /* Let's query for the latest rest report */
1053 $iNewestId = testData::getNewestTestIdFromVersionId($this->iVersionId);
1054 $iTestingId = $iNewestId;
1056 if($iTestingId) /* We want all entries to have test data, but old versions might lack
1057 it, or data may have been deleted */
1058 $oTest = new testData($iTestingId);
1059 } else if(!$oTest) /* Perhaps we have a cached entry? There should be */
1061 $aTests = $this->getTestResults();
1063 if(sizeof($aTests)) /* ... but we cannot be certain */
1064 $oTest = $aTests[0];
1067 if($oTest)
1069 if($oTest->isOld())
1071 if($iNewestId != $oTest->objectGetId())
1073 $sWarnOldText = 'The test results you have selected are very old and may not represent the current state of Wine.';
1074 } else
1076 $sWarnOldText = 'The test results for this version are very old, and as such they may not represent '.
1077 'the current state of Wine. Please consider submitting a new test report.';
1079 echo html_note('Old test results', $sWarnOldText);
1082 echo "<div class='info_container'>\n";
1084 echo "\t<div class='title_class'>\n";
1085 echo "\t\tSelected test results <small><small>(selected in 'Test Results' table below)</small></small>\n";
1086 echo "\t</div>\n";
1088 echo "<div class='info_contents'>\n";
1090 $oTest->ShowTestResult();
1092 echo "</div>\n";
1094 echo "</div>\n";
1095 } else /* Show a note saying that no test results are present,
1096 and encourage the user to take action */
1098 echo html_note('No Test Results',
1099 'This version has no test results, please consider submitting some.<br>'.
1100 'They may be part of the '.
1101 'version or application description. If they are, please '.
1102 'consider becoming a maintainer and remove them, submitting '.
1103 'a proper test report instead.');
1106 // end the 'info_container' div
1107 // end show test data
1108 /////////////////////
1111 //////////////////////////////
1112 // show the test results table
1113 if($oTest)
1115 if($oTest->iTestingId)
1117 $oTest->ShowVersionsTestingTable($this->objectMakeUrl()."&amp;iTestingId=", 5);
1118 } else /* We are previewing the version */
1120 $oTable = $oTest->CreateTestTable();
1121 $oTable->AddRow($oTest->CreateTestTableRow(0, ""));
1122 echo $oTable->GetString();
1126 if($_SESSION['current']->isLoggedIn())
1128 echo '<form method=post name=sMessage action=objectManager.php?'.
1129 'sClass=testData_queue&amp;sAction=add&amp;iVersionId='.$this->iVersionId.
1130 '&amp;sTitle=Add+Test+Data&amp;sReturnTo='.
1131 urlencode($this->objectMakeUrl()).'>'."\n";
1132 echo "\t".'<input type=submit value="Add Test Data" class="button" >'."\n";
1133 echo '</form>'."\n";
1134 } else
1136 echo '<form method="post" name="sMessage" action="'.login_url().'">'."\n";
1137 echo "\t".'<input type="hidden" name="sCmd" value="login">'."\n";
1138 echo "\t".'<input type=submit value="Log in to add test data" class="button">'."\n";
1139 echo '</form>'."\n";
1142 // end show test results table
1143 /////////////////////////////
1146 echo "</div>\n"; // end the version info pane, the right hand pane in the
1147 // version display
1149 echo html_frame_end();
1151 view_version_bugs($this->iVersionId, $this->get_buglink_ids());
1153 /* display the notes for the application */
1154 $hNotes = query_parameters("SELECT noteId FROM appNotes WHERE versionId = '?'",
1155 $this->iVersionId);
1157 while( $oRow = query_fetch_object($hNotes) )
1159 $oNote = new Note($oRow->noteId);
1160 $oNote->display();
1163 // Comments Section
1164 if($this->iVersionId)
1165 Comment::view_app_comments($this->iVersionId);
1168 public static function lookup_name($versionId)
1170 if(!$versionId) return null;
1171 $result = query_parameters("SELECT versionName FROM appVersion WHERE versionId = '?'",
1172 $versionId);
1173 if(!$result || query_num_rows($result) != 1)
1174 return null;
1175 $ob = query_fetch_object($result);
1176 return $ob->versionName;
1179 function fullName($iVersionId)
1181 if(!$iVersionId)
1182 return FALSE;
1184 $hResult = query_parameters(
1185 "SELECT appFamily.appName, appVersion.versionName
1186 FROM appVersion, appFamily WHERE appVersion.appId = appFamily.appId
1187 AND versionId = '?'",
1188 $iVersionId);
1190 if(!$hResult || !query_num_rows($hResult))
1191 return FALSE;
1193 $oRow = query_fetch_object($hResult);
1194 return "$oRow->appName $oRow->versionName";
1197 /* Creates a link to the version labelled with the full application name */
1198 public static function fullNameLink($iVersionId)
1200 $oVersion = new version($iVersionId);
1201 $sLink = "<a href=\"".$oVersion->objectMakeUrl()."\">".
1202 $oVersion->fullName($iVersionId)."</a>";
1203 return $sLink;
1206 // display the versions
1207 public static function displayList($aVersions)
1209 if ($aVersions)
1211 echo html_frame_start("","98%","",0);
1213 $oTable = new Table();
1214 $oTable->SetWidth("100%");
1215 $oTable->SetBorder(0);
1216 $oTable->SetCellPadding(3);
1217 $oTable->SetCellSpacing(1);
1219 $oTableRow = new TableRow();
1220 $oTableRow->SetClass("color4");
1222 $oTableCell = new TableCell("Version");
1223 $oTableCell->SetWidth("80");
1224 $oTableRow->AddCell($oTableCell);
1226 $oTableRow->AddTextCell("Description");
1228 $oTableCell = new TableCell("Rating");
1229 $oTableCell->SetWidth("80");
1230 $oTableRow->AddCell($oTableCell);
1232 $oTableCell = new TableCell("Wine version");
1233 $oTableCell->SetWidth("80");
1234 $oTableRow->AddCell($oTableCell);
1236 $oTableCell = new TableCell("Test results");
1237 $oTableCell->SetWidth("80");
1238 $oTableRow->AddCell($oTableCell);
1240 $oTableCell = new TableCell("Comments");
1241 $oTableCell->SetWidth("40");
1242 $oTableRow->AddCell($oTableCell);
1244 $oTable->SetHeader($oTableRow);
1246 $c = 0;
1247 foreach($aVersions as $oVersion)
1249 $oApp = new application($oVersion->iAppId);
1251 if ($oVersion->sState == $oApp->objectGetState())
1253 // set row color
1254 $bgcolor = ($c % 2 == 0) ? "color0" : "color1";
1256 $oTableRowHighlight = null;
1258 // if we have a valid tested rating
1259 if($oVersion->sTestedRating && ($oVersion->sTestedRating != "/") &&
1260 ($oVersion->sTestedRating != " "))
1262 $sClass = $oVersion->sTestedRating;
1264 $oInactiveColor = new Color();
1265 $oInactiveColor->SetColorByName($oVersion->sTestedRating);
1267 $oHighlightColor = GetHighlightColorFromInactiveColor($oInactiveColor);
1269 $oTableRowHighlight = new TableRowHighlight($oHighlightColor, $oInactiveColor);
1270 } else
1272 $sClass = $bgcolor;
1274 $oTableRowHighlight = GetStandardRowHighlight($c);
1277 //display row
1278 $oTableRowClick = new TableRowClick($oVersion->objectMakeUrl());
1279 $oTableRowClick->SetHighlight($oTableRowHighlight);
1281 $oTableRow = new TableRow();
1282 $oTableRow->SetRowClick($oTableRowClick); // make the row clickable
1283 $oTableRow->AddTextCell($oVersion->objectMakeLink());
1284 $oTableRow->SetClass($sClass);
1285 $oTableRow->AddTextCell(util_trim_description($oVersion->sDescription));
1287 $oTableCell = new TableCell($oVersion->sTestedRating);
1288 $oTableCell->SetAlign("center");
1289 $oTableRow->AddCell($oTableCell);
1291 $oTableCell = new TableCell($oVersion->sTestedRelease);
1292 $oTableCell->SetAlign("center");
1293 $oTableRow->AddCell($oTableCell);
1295 $oTableCell = new TableCell(testData::get_testdata_count_for_versionid($oVersion->iVersionId));
1296 $oTableCell->SetAlign("center");
1297 $oTableRow->AddCell($oTableCell);
1299 $oTableCell = new TableCell(Comment::get_comment_count_for_versionid($oVersion->iVersionId));
1300 $oTableCell->SetAlign("center");
1301 $oTableRow->AddCell($oTableCell);
1303 // add the row to the table
1304 $oTable->AddRow($oTableRow);
1306 $c++;
1310 // output the table
1311 echo $oTable->GetString();
1313 echo html_frame_end("Click the Version Name to view the details of that Version");
1317 /* returns the maintainers of this version in an array */
1318 public function getMaintainersUserIds()
1320 $aMaintainers = array();
1322 /* early out if the versionId isn't valid */
1323 if($this->iVersionId == 0)
1324 return $aMaintainers;
1326 $hResult = Maintainer::getMaintainersForAppIdVersionId(null, $this->iVersionId);
1327 $iCount = 0;
1328 while($oRow = query_fetch_object($hResult))
1330 $aMaintainers[$iCount] = $oRow->userId;
1331 $iCount++;
1334 return $aMaintainers;
1337 /* List the versions submitted by a user. Ignore versions for queued applications */
1338 public static function listSubmittedBy($iUserId, $bQueued = true)
1340 $hResult = query_parameters("SELECT appFamily.appName, appVersion.versionName, appVersion.description, appVersion.versionId, appVersion.submitTime FROM appFamily, appVersion WHERE appFamily.appId = appVersion.appId AND appVersion.submitterId = '?' AND appVersion.state = '?' AND appFamily.state = '?'", $iUserId, $bQueued ? 'queued' : 'accepted', 'accepted');
1342 if(!$hResult || !query_num_rows($hResult))
1343 return false;
1345 $oTable = new Table();
1346 $oTable->SetWidth("100%");
1347 $oTable->SetAlign("center");
1349 // setup the table header
1350 $oTableRow = new TableRow();
1351 $oTableRow->AddTextCell("Name");
1352 $oTableRow->AddTextCell("Description");
1353 $oTableRow->AddTextCell("Submission Date");
1354 $oTableRow->SetClass("color4");
1355 $oTable->SetHeader($oTableRow);
1357 if($bQueued)
1358 $oTableRow->addTextCell('Action');
1360 for($i = 1; $oRow = query_fetch_object($hResult); $i++)
1362 $oTableRow = new TableRow();
1363 $oTableRow->AddTextCell(version::fullNameLink($oRow->versionId));
1364 $oTableRow->AddTextCell($oRow->description);
1365 $oTableRow->AddTextCell(print_date(mysqldatetime_to_unixtimestamp($oRow->submitTime)));
1366 $oTableRow->SetClass(($i % 2) ? "color0" : "color1");
1368 if($bQueued)
1370 $oM = new objectManager('version_queue');
1371 $oM->setReturnTo(array_key_exists('REQUEST_URI', $_SERVER) ? $_SERVER['REQUEST_URI'] : "");
1372 $shDeleteLink = '<a href="'.$oM->makeUrl('delete', $oRow->versionId, 'Delete entry').'">delete</a>';
1373 $shEditLink = '<a href="'.$oM->makeUrl('edit', $oRow->versionId, 'Edit entry').'">edit</a>';
1374 $oTableRow->addTextCell("[ $shEditLink ] &nbsp; [ $shDeleteLink ]");
1377 $oTable->AddRow($oTableRow);
1380 return $oTable->GetString();
1383 /* Returns an array containg the different software licences */
1384 public function getLicenses()
1386 return array(LICENSE_RETAIL, LICENSE_OPENSOURCE, LICENSE_FREETOUSE,
1387 LICENSE_FREETOSHARE, LICENSE_DEMO, LICENSE_SHAREWARE);
1390 // returns a string containing the html for a selection list
1391 public function makeLicenseList($sLicense = NULL)
1393 if(!$sLicense)
1394 $sLicense = $this->sLicense;
1396 $sReturn = "<select name=\"sLicense\">\n";
1397 $sReturn .= "<option value=\"\">Choose . . .</option>\n";
1398 $aLicense = version::getLicenses();
1399 $iMax = count($aLicense);
1401 for($i = 0; $i < $iMax; $i++)
1403 if($aLicense[$i] == $sLicense)
1404 $sSelected = " selected=\"selected\"";
1405 else
1406 $sSelected = "";
1408 $sReturn .= "<option value=\"$aLicense[$i]\"$sSelected>".
1409 "$aLicense[$i]</option>\n";
1412 $sReturn .= "</select>\n";
1414 return $sReturn;
1417 /* In order to prevent MySQL injections. Returns matched license */
1418 public static function checkLicense($sLicense)
1420 $aLicense = array(LICENSE_RETAIL, LICENSE_OPENSOURCE, LICENSE_FREETOUSE,
1421 LICENSE_FREETOSHARE, LICENSE_DEMO, LICENSE_SHAREWARE);
1423 foreach($aLicense as $sElement)
1425 if($sLicense == $sElement)
1426 return $sElement;
1429 return FALSE;
1432 public function objectMakeUrl()
1434 return APPDB_ROOT."objectManager.php?sClass=version&amp;iId=$this->iVersionId";
1437 public function objectMakeLink()
1439 $sLink = "<a href=\"".$this->objectMakeUrl()."\">".
1440 $this->sName."</a>";
1441 return $sLink;
1444 public static function objectGetEntriesCount($sState)
1446 $oVersion = new version();
1447 if($sState != 'accepted' && !$oVersion->canEdit())
1449 /* Users should see their own rejected entries, but maintainers should
1450 not be able to see rejected entries for versions they maintain */
1451 if($sState == 'rejected')
1452 $sQuery = "SELECT COUNT(DISTINCT appVersion.versionId) as count FROM
1453 appVersion WHERE
1454 appVersion.submitterId = '?'
1456 appVersion.state = '?'";
1457 else
1458 $sQuery = "SELECT COUNT(DISTINCT appVersion.versionId) as count FROM
1459 appVersion, appMaintainers WHERE
1460 appMaintainers.appId = appVersion.appId
1462 superMaintainer = '1'
1464 appMaintainers.userId = '?'
1466 appMaintainers.state = 'accepted'
1468 appVersion.state = '?'";
1470 $hResult = query_parameters($sQuery, $_SESSION['current']->iUserId, $sState);
1471 } else
1473 $sQuery = "SELECT COUNT(DISTINCT versionId) as count
1474 FROM appVersion WHERE
1475 appVersion.state = '?'";
1476 $hResult = query_parameters($sQuery, $sState);
1479 if(!$hResult)
1480 return FALSE;
1482 if(!$oRow = query_fetch_object($hResult))
1483 return FALSE;
1485 return $oRow->count;
1488 public function objectGetState()
1490 return $this->sState;
1493 public function objectSetState($sState)
1495 $this->sState = $sState;
1498 public function canEdit()
1500 if($_SESSION['current']->hasPriv("admin"))
1501 return TRUE;
1503 if(isset($this) && is_object($this) && $this->iVersionId)
1505 if(maintainer::isUserMaintainer($_SESSION['current'], $this->iVersionId))
1506 return TRUE;
1508 if($this->sState != 'accepted' && $this->iSubmitterId == $_SESSION['current']->iUserId)
1509 return TRUE;
1511 return FALSE;
1512 } else
1514 return FALSE;
1518 public function mustBeQueued()
1520 if($_SESSION['current']->hasPriv("admin"))
1521 return FALSE;
1523 // if we have a valid iAppId or iVersionId we should
1524 // check the status of these objects to determine whether
1525 // we need to queue this version object
1526 if($this->iVersionId or $this->iAppId)
1528 // if the user is the super maintainer of the application then
1529 // they are authorized to unqueue versions of this application
1530 // so the version doesn't have to be queued
1531 if($this->iAppId &&
1532 maintainer::isUserSuperMaintainer($_SESSION['current'], $this->iAppId))
1533 return FALSE;
1535 // if the user is a maintainer of this version then
1536 // this version doesn't have to be queued
1537 if($this->iVersionId &&
1538 maintainer::isUserMaintainer($_SESSION['current'], $this->iVersionId))
1539 return FALSE;
1541 return TRUE;
1542 } else
1544 return TRUE;
1548 public static function objectGetHeader()
1550 $oTableRow = new TableRow();
1551 $oTableRow->AddTextCell("Submission Date");
1552 $oTableRow->AddTextCell("Submitter");
1553 $oTableRow->AddTextCell("Vendor");
1554 $oTableRow->AddTextCell("Application");
1555 $oTableRow->AddTextCell("Version");
1556 $oTableRow->AddTextCell("Has Maintainer");
1557 return $oTableRow;
1560 public static function objectGetItemsPerPage($sState = 'accepted')
1562 $aItemsPerPage = array(25, 50, 100, 200);
1563 $iDefaultPerPage = 25;
1564 return array($aItemsPerPage, $iDefaultPerPage);
1567 public static function objectGetDefaultSort()
1569 return 'versionId';
1572 public static function objectGetEntries($sState, $iRows = 0, $iStart = 0, $sOrderBy = "versionId", $bAscending = true)
1574 $sLimit = "";
1576 /* Should we add a limit clause to the query? */
1577 if($iRows || $iStart)
1579 $sLimit = " LIMIT ?,?";
1581 /* Selecting 0 rows makes no sense, so we assume the user wants to select all of them
1582 after an offset given by iStart */
1583 if(!$iRows)
1584 $iRows = version::objectGetEntriesCount($sState);
1587 if($sState != 'accepted' && !version::canEdit())
1589 /* Users should see their own rejected entries, but maintainers should
1590 not be able to see rejected entries for versions they maintain */
1591 if($sState == 'rejected')
1592 $sQuery = "SELECT * FROM appVersion WHERE
1593 appVersion.submitterId = '?'
1595 appVersion.state = '?' ORDER BY ?$sLimit";
1596 else
1597 $sQuery = "SELECT appVersion.* FROM
1598 appVersion, appMaintainers WHERE
1599 appMaintainers.appId = appVersion.appId
1601 superMaintainer = '1'
1603 appMaintainers.userId = '?'
1605 appMaintainers.state = 'accepted'
1607 appVersion.state = '?' ORDER BY ?$sLimit";
1609 if($sLimit)
1611 $hResult = query_parameters($sQuery, $_SESSION['current']->iUserId,
1612 $sState, $sOrderBy, $iStart, $iRows);
1613 } else
1615 $hResult = query_parameters($sQuery, $_SESSION['current']->iUserId,
1616 $sState, $sOrderBy);
1618 } else
1620 $sQuery = "SELECT * FROM appVersion WHERE
1621 appVersion.state = '?' ORDER BY ?$sLimit";
1623 if($sLimit)
1625 $hResult = query_parameters($sQuery, $sState, $sOrderBy,
1626 $iStart, $iRows);
1627 } else
1629 $hResult = query_parameters($sQuery, $sState, $sOrderBy);
1633 if(!$hResult)
1634 return FALSE;
1636 return $hResult;
1639 public function objectGetTableRow()
1641 $oUser = new user($this->iSubmitterId);
1642 $oApp = new application($this->iAppId);
1643 $oVendor = new vendor($oApp->iVendorId);
1645 $aMaintainers = Maintainer::getSuperMaintainersUserIdsFromAppId($this->iAppId);
1647 $oTableRow = new TableRow();
1648 $oTableRow->AddTextCell(print_date(mysqldatetime_to_unixtimestamp($this->sSubmitTime)));
1649 $oTableRow->AddTextCell($oUser->objectMakeLink());
1650 $oTableRow->AddTextCell($oVendor->objectMakeLink());
1651 $oTableRow->AddTextCell($oApp->objectMakeLink());
1652 $oTableRow->AddTextCell($this->sName);
1653 $oTableRow->AddTextCell(sizeof($aMaintainers) ? "YES" : "No");
1655 $oOMTableRow = new OMTableRow($oTableRow);
1656 return $oOMTableRow;
1659 public function objectDisplayQueueProcessingHelp()
1661 echo "<p>This is the list of version entries waiting to be processed.</p>\n";
1662 echo "<p>To view and process an entry, use the links under &#8216;Action&#8217;</p>";
1665 public function getTestResults($bIncludeDeleted = false)
1667 /* If we don't have an id we can't query the database, but perhaps we
1668 have some cached entries? */
1669 if(!$this->iVersionId)
1670 return $this->aTestResults;
1672 $aTests = array();
1674 if($bIncludeDeleted)
1675 $sExcludeDeleted = "";
1676 else
1677 $sExcludeDeleted = " AND state != 'deleted'";
1679 /* Find test results */
1680 $sQuery = "SELECT * FROM testResults WHERE versionId = '?'$sExcludeDeleted";
1681 $hResult = query_parameters($sQuery, $this->iVersionId);
1683 if(!$hResult)
1684 return FALSE;
1686 while($oRow = mysql_fetch_object($hResult))
1687 $aTests[] = new testData(0, $oRow);
1689 return $aTests;
1692 public function objectGetChildren($bIncludeDeleted = false)
1694 $aChildren = array();
1696 foreach($this->getTestResults($bIncludeDeleted) as $oTest)
1698 $aChildren += $oTest->objectGetChildren($bIncludeDeleted);
1699 $aChildren[] = $oTest;
1702 /* Find maintainers */
1703 $sQuery = "SELECT * FROM appMaintainers WHERE versionId = '?'";
1704 $hResult = query_parameters($sQuery, $this->iVersionId);
1706 if(!$hResult)
1707 return FALSE;
1709 while($oRow = mysql_fetch_object($hResult))
1711 $oMaintainer = new maintainer(0, $oRow);
1712 $aChildren += $oMaintainer->objectGetChildren($bIncludeDeleted);
1713 $aChildren[] = $oMaintainer;
1716 /* Find monitors */
1717 $sQuery = "SELECT * FROM appMonitors WHERE versionId = '?'";
1718 $hResult = query_parameters($sQuery, $this->iVersionId);
1720 if(!$hResult)
1721 return FALSE;
1723 while($oRow = mysql_fetch_object($hResult))
1725 $oMonitor = new monitor(0, $oRow);
1726 $aChildren += $oMonitor->objectGetChildren($bIncludeDeleted);
1727 $aChildren[] = $oMonitor;
1730 /* Find notes */
1731 $sQuery = "SELECT * FROM appNotes WHERE versionId = '?'";
1732 $hResult = query_parameters($sQuery, $this->iVersionId);
1734 if(!$hResult)
1735 return FALSE;
1737 while($oRow = mysql_fetch_object($hResult))
1739 $oNote = new note(0, $oRow);
1740 $aChildren += $oNote->objectGetChildren($bIncludeDeleted);
1741 $aChildren[] = $oNote;
1744 /* Find screenshots */
1745 $sQuery = "SELECT * FROM appData WHERE type = '?' AND versionId = '?'";
1746 $hResult = query_parameters($sQuery, "screenshot", $this->iVersionId);
1748 if(!$hResult)
1749 return FALSE;
1751 while($oRow = mysql_fetch_object($hResult))
1753 $oScreenshot = new screenshot(0, $oRow);
1754 $aChildren += $oScreenshot->objectGetChildren($bIncludeDeleted);
1755 $aChildren[] = $oScreenshot;
1758 /* Get bug links */
1759 foreach($this->get_buglink_ids() as $iBugId)
1761 $oBug = new bug($iBugId);
1762 $aChildren += $oBug->objectGetChildren($bIncludeDeleted);
1763 $aChildren[] = $oBug;
1766 /* Get comments */
1767 $sQuery = "SELECT * FROM appComments WHERE versionId = '?'";
1768 $hResult = query_parameters($sQuery, $this->iVersionId);
1770 if(!$hResult)
1771 return FALSE;
1773 while($oRow = mysql_fetch_object($hResult))
1775 $oComment = new comment(0, $oRow);
1776 $aChildren += $oComment->objectGetChildren($bIncludeDeleted);
1777 $aChildren[] = $oComment;
1780 /* Get urls */
1781 $sQuery = "SELECT * FROM appData WHERE type = '?' AND versionId = '?'";
1782 $hResult = query_parameters($sQuery, "url", $this->iVersionId);
1784 if(!$hResult)
1785 return FALSE;
1787 while($oRow = mysql_fetch_object($hResult))
1789 $oUrl = new url(0, $oRow);
1790 $aChildren += $oUrl->objectGetChildren($bIncludeDeleted);
1791 $aChildren[] = $oUrl;
1794 /* Get downloadurls */
1795 $sQuery = "SELECT * FROM appData WHERE type = '?' AND versionId = '?'";
1796 $hResult = query_parameters($sQuery, "downloadurl", $this->iVersionId);
1798 if(!$hResult)
1799 return FALSE;
1801 while($oRow = mysql_fetch_object($hResult))
1803 $oDownload = new downloadurl(0, $oRow);
1804 $aChildren += $oDownload->objectGetChildren($bIncludeDeleted);
1805 $aChildren[] = $oDownload;
1808 return $aChildren;
1811 public function objectMoveChildren($iNewId)
1813 /* Keep track of how many items we have updated */
1814 $iCount = 0;
1816 /* Move test results */
1817 $sQuery = "SELECT * FROM testResults WHERE versionId = '?'";
1818 $hResult = query_parameters($sQuery, $this->iVersionId);
1820 if(!$hResult)
1821 return FALSE;
1823 while($oRow = query_fetch_object($hResult))
1825 $oTestData = new testData($oRow->testingId);
1826 $oTestData->iVersionId = $iNewId;
1827 if($oTestData->update())
1828 $iCount++;
1829 else
1830 return FALSE;
1833 /* Move all app data */
1834 $sQuery = "SELECT * FROM appData WHERE versionId = '?'";
1835 $hResult = query_parameters($sQuery, $this->iVersionId);
1837 if(!$hResult)
1838 return FALSE;
1840 while($oRow = query_fetch_object($hResult))
1842 $oAppData = new appData($oRow->testingId);
1843 $oAppData->iVersionId = $iNewId;
1844 if($oAppData->update(TRUE))
1845 $iCount++;
1846 else
1847 return FALSE;
1850 /* Return the number of updated objects if everything was successful */
1851 return $iCount;
1854 public static function allowAnonymousSubmissions()
1856 return FALSE;
1859 function objectAllowPurgingRejected()
1861 return TRUE;
1864 public function objectGetSubmitTime()
1866 return mysqltimestamp_to_unixtimestamp($this->sSubmitTime);
1869 public function objectGetId()
1871 return $this->iVersionId;