Locate next revision ISO
[reactos.git] / cis / ReactOS.RevisionISO / index.php
1 <?php
2
3 include ('config.php');
4
5 function dm_usort_cmp ($a, $b) {
6 if ($a == $b) return 0;
7 return ($a > $b) ? -1 : 1;
8 }
9
10 function dm_usort_cmp_desc ($a, $b) {
11 if ($a == $b) return 0;
12 return ($a > $b) ? 1 : -1;
13 }
14
15 function printHeader()
16 {
17 ?>
18 <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
19 <html>
20 <head>
21 <title>ReactOS Revison ISOs</title>
22 <meta name="generator" content="Editpad">
23 <meta name="keywords" content="OS, ReactOS, operating system">
24 <meta name="author" content="ReactOS Project (ros-dev@reactos.com)">
25 <style>
26 .box
27 {
28 padding: 0px;
29 background-color: #88aadd;
30 border-left: 1px solid #f0f0f0;
31 border-right: 1px solid #000000;
32 border-top: 1px solid #f0f0f0;
33 border-bottom: 1px solid #000000;
34 }
35 </style>
36 </head>
37 <body bgcolor="#88aadd">
38 <form method="post" action="">
39 <?php
40 }
41
42 function printMenu($revision)
43 {
44 ?>
45 <table border="0" class="box" cellpadding="5">
46 <tr>
47 <td height="2px">
48 </td>
49 </tr>
50 <tr>
51 <td>
52
53 <table border="0" cellpadding="0" cellspacing="0">
54 <tr>
55 <td>
56 <b>Branch:</b>
57 </td>
58 <td>
59 <select name="branch" tabindex="1">
60 <?php
61
62 $d = dir(ISO_PATH);
63 $i = 0;
64 $dirlist = array();
65 while (false !== ($entry = $d->read())) {
66 if ((strcasecmp($entry, ".") != 0) && (strcasecmp($entry, "..") != 0) && is_dir(ISO_PATH . "\\" . $entry) == "dir") {
67 $dirlist[$i++] = $entry;
68 }
69 }
70 $d->close();
71
72 if (is_array($dirlist)) {
73 usort($dirlist, "dm_usort_cmp");
74 reset($dirlist);
75 while (list($key, $val) = each($dirlist)) {
76 $branch = $val;
77 if ($branch == $_POST["branch"] || (!isset($_POST["branch"]) && $branch == "trunk"))
78 $selected = " selected";
79 else
80 $selected = "";
81 echo "<option$selected>$branch</option>";
82 }
83 }
84
85 ?>
86 </select>
87 </td>
88 <td>
89 &nbsp;
90 </td>
91 <td>
92 <b>Revision:</b>
93 </td>
94 <td>
95 <?php
96 echo "<input type=\"text\" name=\"revision\" size=\"10\" maxlength=\"10\" tabindex=\"2\" value=\"" . $revision . "\"></input>";
97 ?>
98 </td>
99 <td>
100 &nbsp;
101 </td>
102 <td>
103 <input type="submit" name="getiso" value="Download" tabindex="3" style="border: 1px solid #000000"></input>
104 </td>
105 </tr>
106 <tr>
107 <td colspan="7">
108 <hr size="2" width="100%" />
109 </td>
110 </tr>
111 <tr>
112 <td colspan="7">
113 <input type="submit" name="getnextiso" value="Next ISO" tabindex="4" style="border: 1px solid #000000"></input>
114 </td>
115 </tr>
116 </table>
117
118 </td>
119 </tr>
120 <tr>
121 <td height="2px">
122 </td>
123 </tr>
124 </table>
125 <?php
126 }
127
128 function printFooter()
129 {
130 ?>
131 </form>
132
133 <script>
134 var revision = document.getElementById('revision');
135 if (revision) revision.focus();
136 </script>
137 </body>
138 </html>
139 <?php
140 }
141
142 function getNextRevisionISO($branch, $revision)
143 {
144 $revision = intval($revision);
145 $path = ISO_PATH . "\\" . $branch;
146 $d = dir($path);
147 $i = 0;
148 $filelist = array();
149 while (false !== ($entry = $d->read())) {
150 if (is_dir($path . "\\" . $entry) != "dir")
151 $filelist[$i++] = $entry;
152 }
153 $d->close();
154
155 if (is_array($filelist)) {
156 usort($filelist, "dm_usort_cmp_desc");
157 reset($filelist);
158 while (list($key, $filename) = each($filelist)) {
159 if (ereg('ReactOS-' . $branch . '-r([0-9]*).iso', $filename, $regs))
160 {
161 $thisRevision = intval($regs[1]);
162 if ($thisRevision > $revision)
163 return $regs[1];
164 $lastRevision = $thisRevision;
165 }
166 }
167 }
168
169 return "";
170 }
171
172
173 function main()
174 {
175 $branch = $_POST["branch"];
176 $revision = $_POST["revision"];
177
178 $filename = "ReactOS-" . $branch . "-r" . $revision . ".iso";
179 if (file_exists(ISO_PATH . $branch . "\\" . $filename))
180 {
181 $location = ISO_BASE_URL . $branch . "/" . $filename;
182 header("Location: $location");
183 return;
184 }
185 else
186 {
187 printHeader();
188 printMenu($_POST["revision"]);
189 echo "<br><b>No ISO exist for branch '" . $branch . "' and revision " . $revision . ".</b><br><br>";
190 printFooter();
191 }
192 }
193
194 if (!empty($_POST["getiso"]) && !empty($_POST["branch"]) && !empty($_POST["revision"]) && is_numeric($_POST["revision"]))
195 main();
196 else if (!empty($_POST["getnextiso"]) && !empty($_POST["branch"]) && !empty($_POST["revision"]) && is_numeric($_POST["revision"]))
197 {
198 printHeader();
199 printMenu(getNextRevisionISO($_POST["branch"], $_POST["revision"]));
200 printFooter();
201 }
202 else
203 {
204 printHeader();
205 printMenu($_POST["revision"]);
206 printFooter();
207 }
208
209 ?>