DPRINT->DPRINT1 in key places (when something fails we shouldn't keep silence).
[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="4">
113 <input type="submit" name="getnextiso" value="Next ISO" tabindex="4" style="border: 1px solid #000000"></input>
114 </td>
115 <td colspan="3" align="right">
116 <input type="submit" name="getlatestiso" value="Latest ISO" tabindex="5" style="border: 1px solid #000000"></input>
117 </td>
118 </tr>
119 </table>
120
121 </td>
122 </tr>
123 <tr>
124 <td height="2px">
125 </td>
126 </tr>
127 </table>
128 <?php
129 }
130
131 function printFooter()
132 {
133 ?>
134 </form>
135
136 <script>
137 var revision = document.getElementById('revision');
138 if (revision) revision.focus();
139 </script>
140 </body>
141 </html>
142 <?php
143 }
144
145 function locateRevisionISO($branch, $revision, $latest)
146 {
147 $revision = intval($revision);
148 $path = ISO_PATH . "\\" . $branch;
149 $d = dir($path);
150 $i = 0;
151 $filelist = array();
152 while (false !== ($entry = $d->read())) {
153 if (is_dir($path . "\\" . $entry) != "dir")
154 $filelist[$i++] = $entry;
155 }
156 $d->close();
157
158 if (is_array($filelist)) {
159 $sortFunction = $latest ? "dm_usort_cmp" : "dm_usort_cmp_desc";
160 usort($filelist, $sortFunction);
161 reset($filelist);
162 while (list($key, $filename) = each($filelist)) {
163 if (ereg('ReactOS-' . $branch . '-r([0-9]*).iso', $filename, $regs))
164 {
165 $thisRevision = intval($regs[1]);
166 if (($latest) && ($thisRevision < $revision))
167 return $regs[1];
168 else if ($thisRevision > $revision)
169 return $regs[1];
170 $lastRevision = $thisRevision;
171 }
172 }
173 }
174
175 return "";
176 }
177
178 function getNextRevisionISO($branch, $revision)
179 {
180 return locateRevisionISO($branch, $revision, false);
181 }
182
183 function getLatestRevisionISO($branch)
184 {
185 return locateRevisionISO($branch, 999999, true);
186 }
187
188 function main()
189 {
190 $branch = $_POST["branch"];
191 $revision = $_POST["revision"];
192
193 $filename = "ReactOS-" . $branch . "-r" . $revision . ".iso";
194 if (file_exists(ISO_PATH . $branch . "\\" . $filename))
195 {
196 $location = ISO_BASE_URL . $branch . "/" . $filename;
197 header("Location: $location");
198 return;
199 }
200 else
201 {
202 printHeader();
203 printMenu($_POST["revision"]);
204 echo "<br><b>No ISO exist for branch '" . $branch . "' and revision " . $revision . ".</b><br><br>";
205 printFooter();
206 }
207 }
208
209 if (!empty($_POST["getiso"]) && !empty($_POST["branch"]) && !empty($_POST["revision"]) && is_numeric($_POST["revision"]))
210 main();
211 else if (!empty($_POST["getnextiso"]) && !empty($_POST["branch"]) && !empty($_POST["revision"]) && is_numeric($_POST["revision"]))
212 {
213 printHeader();
214 printMenu(getNextRevisionISO($_POST["branch"], $_POST["revision"]));
215 printFooter();
216 }
217 else if (!empty($_POST["getlatestiso"]) && !empty($_POST["branch"]))
218 {
219 printHeader();
220 printMenu(getLatestRevisionISO($_POST["branch"]));
221 printFooter();
222 }
223 else
224 {
225 printHeader();
226 printMenu($_POST["revision"]);
227 printFooter();
228 }
229
230 ?>