objectManager: Fix lower-case letter in 'email Text'
[NewAppDB.git] / screenshots.php
blobfdb1d0b48aa48a32990c08d780c3a49f1b861988
1 <?php
2 /**
3 * Shows a page with several screenshot thumbnails.
5 * Mandatory parameters:
6 * - iAppId, application identifier
7 * AND/OR
8 * - iVersionId, version identifier
9 *
10 * Optional parameters:
11 * - iImageId, image identifier (for deletion)
12 * - sScreenshotDesc, screenshot description (for insertion)
13 * - sCmd, action to perform ("screenshot_upload", "delete")
15 * TODO:
16 * - replace iImageId with iScreenshotId
17 * - replace sCmd with iAction and replace "delete", "screenshot_upload", etc. with integer constants DELETE, UPLOAD, etc.
18 * - replace require_once with require after checking that it won't break anything
21 // application environment
22 require("path.php");
23 require(BASE."include/incl.php");
24 require_once(BASE."include/screenshot.php");
25 require_once(BASE."include/application.php");
26 require_once(BASE."include/version.php");
28 // we issued a command
29 if($aClean['sCmd'])
31 // process screenshot upload
32 if($aClean['sCmd'] == "screenshot_upload")
34 //FIXME: use a defined value here instead of just 600000
35 if($_FILES['sImageFile']['size']>600000)
37 addmsg("Your screenshot was not accepted because it is too big. Please try to keep your screenshots under 600KB by saving games/video screenshots to jpeg and normal applications to png you might be able to achieve very good results with less bytes", "red");
38 } else
40 $oScreenshot = new Screenshot();
41 $oScreenshot->iVersionId = $aClean['iVersionId'];
42 $oScreenshot->sDescription = $aClean['sScreenshotDesc'];
43 $oScreenshot->hFile = $_FILES['sImageFile'];
44 $oScreenshot->create();
45 $oScreenshot->free();
47 } elseif($aClean['sCmd'] == "delete" && is_numeric($aClean['iImageId'])) // process screenshot deletion
49 $oScreenshot = new Screenshot($aClean['iImageId']);
50 $oScreenshot->delete();
51 $oScreenshot->free();
53 util_redirect_and_exit(apidb_fullurl("screenshots.php?iAppId=".$aClean['iAppId']."&iVersionId=".$aClean['iVersionId']));
57 // we didn't issued any command
58 $hResult = Screenshot::get_screenshots($aClean['iAppId'], $aClean['iVersionId']);
59 apidb_header("Screenshots");
60 $oApp = new Application($aClean['iAppId']);
61 $oVersion = new Version($aClean['iVersionId']);
63 if($hResult && query_num_rows($hResult))
65 echo '&nbsp'; // Add some space between title bars
66 echo html_frame_start("Screenshot Gallery for ".$oApp->sName, 500);
68 // display thumbnails
69 $c = 1;
71 // optimization so we don't have to perform as many database queries
72 // only update this variable when $iCurrentVersionId changes
73 $bUserIsMaintainerOfVersion = false;
75 echo "<div align=center><table><tr>\n";
76 echo '&nbsp'; // Add some space between title bars
78 while($oRow = query_fetch_object($hResult))
80 // if the current version changed then update the current version
81 // and close the previous html frame if this isn't the
82 // first frame
83 if($oRow->versionId != $iCurrentVersionId)
85 if($iCurrentVersionId)
87 echo "</tr></table></div>\n";
88 echo html_frame_end();
89 $c=1;
91 $iCurrentVersionId = $oRow->versionId;
92 $bUserIsMaintainerOfVersion = $_SESSION['current']->isMaintainer($iCurrentVersionId);
94 echo html_frame_start("Version ".Version::lookup_name($iCurrentVersionId));
95 echo "<div align=center><table><tr>\n";
97 $oScreenshot = new Screenshot($oRow->id);
98 $img = $oScreenshot->get_thumbnail_img();
100 // display image
101 echo "<td>\n";
102 echo $img;
103 echo "<div align=center>". substr($oRow->description,0,20). "\n";
105 //show admin delete link
106 if($_SESSION['current']->isLoggedIn() &&
108 $_SESSION['current']->hasPriv("admin") ||
109 $bUserIsMaintainerOfVersion
113 $oM = new objectManager("screenshot");
114 $oM->setReturnTo("screenshots.php?iAppId=".$oScreenshot->iAppId."&amp;iVersionId=".$oScreenshot->iVersionId);
115 echo '<br>[<a href="'.$oM->makeUrl("delete", $oScreenshot->iScreenshotId, "Delete Screenshot").'">Delete</a>]';
118 echo "</div></td>\n";
120 // end row if counter of 3
121 if ($c % 3 == 0) echo "</tr><tr>\n";
123 $c++;
125 echo "</tr></table></div><br>\n";
127 echo html_frame_end(); // close the current version we are displaying
128 echo html_frame_end(); // close the "Screenshot Gallary..." html frame
129 } else
131 echo "<p align=\"center\">There are currently no screenshots for the selected version of this application.";
132 echo "<br>Please consider submitting a screenshot for the selected version yourself.</p>";
135 // let's show the screenshot uploading box, but only
136 // if the user is logged in
137 if($aClean['iVersionId'] && $_SESSION['current']->isLoggedIn())
139 echo "<p align=\"center\">";
140 echo "<table><tr><th>Please follow these simple rules</th></tr>";
141 echo "<tr><td><ul>";
142 echo "<li>Do not upload screenshots of error messages, installers, game menus etc.</li>";
143 echo "<li>Crop the image so that only the application is shown and not your desktop.</li>";
144 echo "</ul></td></tr></table></p>";
146 echo '<form enctype="multipart/form-data" action="screenshots.php" name="sImageForm" method="post">',"\n";
147 echo html_frame_start("Upload Screenshot","400","",0);
148 echo '<table border=0 cellpadding=6 cellspacing=0 width="100%">',"\n";
150 echo '<tr><td class=color1>Image</td><td class=color0><input name="sImageFile" type="file" size="24"></td></tr>',"\n";
151 echo '<tr><td class="color1">Description</td><td class="color0"><input type="text" name="sScreenshotDesc" maxlength="20" size="24"></td></tr>',"\n";
153 echo '<tr><td colspan=2 align=center class=color3><input type="submit" value="Send File"></td></tr>',"\n";
154 echo '</table>',"\n";
155 echo html_frame_end();
156 echo '<input type="hidden" name="MAX_FILE_SIZE" value="4000000">',"\n";
157 echo '<input type="hidden" name="sCmd" value="screenshot_upload">',"\n";
158 echo '<input type="hidden" name="iVersionId" value="'.$aClean['iVersionId'].'"></form>',"\n";
159 } else if(!$_SESSION['current']->isLoggedIn()) // else let the person know that if they log in they can submit screenshots
161 echo '<div align="center"><a href="'.login_url().'">';
162 echo "Log in</a> to submit screenshots</div>\n";
163 } else
165 echo html_frame_start("Upload Screenshot", "30%");
166 echo 'If you would like to submit screenshots, please select an application version below.<br>';
167 echo '<ul>';
168 foreach($oApp->getVersions(true) as $oVersion)
169 echo '<li><a href="'.BASE.'screenshots.php?iVersionId='.$oVersion->objectGetId().'">'.$oVersion->sName.'</a></li>';
171 echo '</ul>';
172 echo html_frame_end();
175 echo html_back_link(1);
177 apidb_footer();