| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | include 'include.php'; |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | $debug=1; |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | process_args(); |
|---|
| 11 | |
|---|
| 12 | $pagetitle = "$currentCountryName Respositories : table of record totals"; |
|---|
| 13 | |
|---|
| 14 | $ircount_table = "ircount"; |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | $order1 = $_GET['order']; |
|---|
| 19 | $freq = $_GET['frequency']; |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | if ($order1 == "") { |
|---|
| 23 | $order1 = "archivename"; |
|---|
| 24 | } |
|---|
| 25 | if ($freq == "") { |
|---|
| 26 | $freq = "weekly"; |
|---|
| 27 | } |
|---|
| 28 | $output1 = $output; |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | $tablename = $ircount_table; |
|---|
| 32 | $pagefilename = $_SERVER['SCRIPT_NAME']; |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | $warningmsg; |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | function linktome ($varname, $varvalue) { |
|---|
| 50 | $pagefilename = $_SERVER['SCRIPT_NAME']; |
|---|
| 51 | global $pagefilename, $order1, $output1, $freq, $warningmsg, $country; |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | $tmpvar = $$varname; |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | $$varname = $varvalue; |
|---|
| 59 | |
|---|
| 60 | $tmpreturn = "$pagefilename?order=$order1&output=$output1&frequency=$freq&country=$country"; |
|---|
| 61 | |
|---|
| 62 | $$varname = $tmpvar; |
|---|
| 63 | |
|---|
| 64 | return "$tmpreturn"; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | function table_column ($collected_dates, $freq="monthly") { |
|---|
| 73 | foreach ($collected_dates as $cdate => $totcdate) { |
|---|
| 74 | list($year, $month, $day) = split('[/.-]', $cdate); |
|---|
| 75 | $tmpurl = linktome("order1", "$cdate"); |
|---|
| 76 | if ($freq == "weekly") { |
|---|
| 77 | echo "<th><a href=\"$tmpurl\">$day/$month<br />$year</a></th>\n"; |
|---|
| 78 | } else { |
|---|
| 79 | echo "<th><a href=\"$tmpurl\">$month $year</a></th>\n"; |
|---|
| 80 | } |
|---|
| 81 | } |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | if ($output1 == "tsv") { |
|---|
| 87 | |
|---|
| 88 | if (!headers_sent()) { |
|---|
| 89 | |
|---|
| 90 | header('Content-type: text/tab-separated-values'); |
|---|
| 91 | header('Content-Disposition: attachment; filename="ir_records.tsv"'); |
|---|
| 92 | } |
|---|
| 93 | } |
|---|
| 94 | elseif ($output1 == "csv") { |
|---|
| 95 | |
|---|
| 96 | if (!headers_sent()) { |
|---|
| 97 | header('Content-type: text/plain'); |
|---|
| 98 | header('Content-Disposition: attachment; filename="ir_records.csv"'); |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | if ($output1=="html") { |
|---|
| 105 | printhtmlhead ($pagetitle); |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | connectdb(); |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | if ($output1=="html") { |
|---|
| 124 | echo "<h1>$pagetitle</h1>"; |
|---|
| 125 | echo "<p>Ordered by: <em>$order1</em>. \n"; |
|---|
| 126 | echo "Frequency: <em>$freq</em> change to:"; |
|---|
| 127 | if ($freq != "weekly") { |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | echo " [<a href=\"?frequency=weekly&country=$country\">weekly</a>] \n"; |
|---|
| 133 | } |
|---|
| 134 | if ($freq != "monthly") { |
|---|
| 135 | |
|---|
| 136 | echo " [<a href=\"?frequency=monthly&country=$country\">monthly</a>] \n"; |
|---|
| 137 | } |
|---|
| 138 | echo "</p>\n"; |
|---|
| 139 | |
|---|
| 140 | $tmpurl = linktome("output1", "tsv"); |
|---|
| 141 | $tmpurl2 = linktome("output1", "csv"); |
|---|
| 142 | echo "<p><strong>Export to text</strong>: <a href=\"$tmpurl\">tab seperated</a> or <a href=\"$tmpurl2\">comma seperate fields enclosed by doublequotes</a>.</p>\n"; |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | $query = " |
|---|
| 152 | SELECT DISTINCT archivename, identifier, country |
|---|
| 153 | FROM $ircount_table |
|---|
| 154 | WHERE country = '$country' |
|---|
| 155 | "; |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | $result_sussex = mysql_query($query) or die("Query failed : " . mysql_error()); |
|---|
| 159 | $fields=mysql_num_rows($result_sussex); |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | if ($output1=="html") { |
|---|
| 167 | echo "<!-- \n\n Debug info \n"; |
|---|
| 168 | echo "Order1: \t $order1 \noutput1:\t $output1\n"; |
|---|
| 169 | echo "-->\n"; |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | $archivelist; |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | while ($line = mysql_fetch_array($result_sussex, MYSQL_ASSOC)) { |
|---|
| 184 | $archivename1 = $line[archivename]; |
|---|
| 185 | $identifier = $line[identifier]; |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | $archivename1 = trim($archivename1); |
|---|
| 189 | |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | $archivelist[$archivename1] = new ArchiveClass(); |
|---|
| 193 | |
|---|
| 194 | |
|---|
| 195 | $archivelist[$archivename1]->setName($archivename1); |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | $archivelist[$archivename1]->setIdentifier($identifier); |
|---|
| 199 | |
|---|
| 200 | |
|---|
| 201 | $justnames[$archivename1]="$archivename1"; |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | $query2 = " |
|---|
| 215 | SELECT archivename, records, DATE(collected_date) as dateonly, country |
|---|
| 216 | FROM ircount |
|---|
| 217 | WHERE country = '$country' |
|---|
| 218 | "; |
|---|
| 219 | |
|---|
| 220 | |
|---|
| 221 | $dbresult_list = mysql_query($query2) or die("Query failed : " . mysql_error()); |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | $collected_dates; |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | $sortorder; |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | |
|---|
| 232 | |
|---|
| 233 | |
|---|
| 234 | while ($line2 = mysql_fetch_array($dbresult_list, MYSQL_ASSOC)) { |
|---|
| 235 | $datestamp2 = $line2["dateonly"]; |
|---|
| 236 | $archivename2 = $line2["archivename"]; |
|---|
| 237 | $archivename2 = trim($archivename2); |
|---|
| 238 | $records2 = $line2["records"]; |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | if ($datestamp2 == "" || |
|---|
| 242 | $archivename2 == "" || |
|---|
| 243 | $records2 == "") { |
|---|
| 244 | echo "ERROR $datestamp2 $records2 $archivename2 \n <p>"; |
|---|
| 245 | } |
|---|
| 246 | if ($records2 == "0") { |
|---|
| 247 | continue; |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | |
|---|
| 251 | |
|---|
| 252 | |
|---|
| 253 | |
|---|
| 254 | |
|---|
| 255 | |
|---|
| 256 | |
|---|
| 257 | if ($freq == "monthly") { |
|---|
| 258 | list($year, $month, $day) = split('[/.-]', $datestamp2); |
|---|
| 259 | $datestamp2 = "$year-$month"; |
|---|
| 260 | } |
|---|
| 261 | |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | $archivelist[$archivename2]->addToRecordslist($datestamp2,$records2); |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | $collected_dates[$datestamp2]++; |
|---|
| 268 | |
|---|
| 269 | |
|---|
| 270 | if ($order1==$datestamp2) { |
|---|
| 271 | $sortorder[$archivename2]=$records2; |
|---|
| 272 | } |
|---|
| 273 | } |
|---|
| 274 | |
|---|
| 275 | |
|---|
| 276 | |
|---|
| 277 | |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | if ($order1=="archivename") { |
|---|
| 289 | $sortorder = $justnames; |
|---|
| 290 | } |
|---|
| 291 | if ($sortorder =="") { |
|---|
| 292 | $sortorder = $justnames; |
|---|
| 293 | } |
|---|
| 294 | |
|---|
| 295 | |
|---|
| 296 | |
|---|
| 297 | asort($sortorder); |
|---|
| 298 | |
|---|
| 299 | |
|---|
| 300 | |
|---|
| 301 | |
|---|
| 302 | |
|---|
| 303 | |
|---|
| 304 | ksort($collected_dates); |
|---|
| 305 | |
|---|
| 306 | |
|---|
| 307 | |
|---|
| 308 | |
|---|
| 309 | |
|---|
| 310 | |
|---|
| 311 | |
|---|
| 312 | |
|---|
| 313 | if ($output1=="html") { |
|---|
| 314 | |
|---|
| 315 | |
|---|
| 316 | echo "<table><tr><th class=\"repname\">Respository Name "; |
|---|
| 317 | $tmplink = linktome("order1", "archivename"); |
|---|
| 318 | echo "[<a href=\"$tmplink\">order by</a>]</th>\n"; |
|---|
| 319 | table_column($collected_dates, $freq); |
|---|
| 320 | echo "<th>Repository Name</th>"; |
|---|
| 321 | echo "</tr>\n"; |
|---|
| 322 | |
|---|
| 323 | |
|---|
| 324 | |
|---|
| 325 | foreach ($sortorder as $aname => $aobject) { |
|---|
| 326 | |
|---|
| 327 | echo "<tr>\n"; |
|---|
| 328 | |
|---|
| 329 | $name = $archivelist[$aname]->getName(); |
|---|
| 330 | $identifier = urlencode ($archivelist[$aname]->getIdentifier()); |
|---|
| 331 | |
|---|
| 332 | echo "<td class=\"repname\">"; |
|---|
| 333 | |
|---|
| 334 | $querystring = "id=$identifier&country=$country"; |
|---|
| 335 | echo '<a href="archive.php?' . htmlentities($querystring) . '">' . $name . "</a></td> \n"; |
|---|
| 336 | |
|---|
| 337 | |
|---|
| 338 | |
|---|
| 339 | |
|---|
| 340 | $records=$archivelist[$aname]->returnRecords(); |
|---|
| 341 | |
|---|
| 342 | foreach ($collected_dates as $cdate => $totalcdate) { |
|---|
| 343 | $numrecord = $records[$cdate]; |
|---|
| 344 | if ($numrecord == "") { |
|---|
| 345 | $numrecord = " "; |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | if ($cdate==$order1) { |
|---|
| 349 | echo "<td><strong><abbr title=\"$aname\">$numrecord</abbr></strong></td>\n"; |
|---|
| 350 | } |
|---|
| 351 | else { |
|---|
| 352 | echo "<td>$numrecord</td>\n"; |
|---|
| 353 | } |
|---|
| 354 | |
|---|
| 355 | $date_totals[$cdate]+=$numrecord; |
|---|
| 356 | } |
|---|
| 357 | |
|---|
| 358 | |
|---|
| 359 | echo "<td>$name</td>\n"; |
|---|
| 360 | |
|---|
| 361 | echo "</tr>\n"; |
|---|
| 362 | |
|---|
| 363 | } |
|---|
| 364 | |
|---|
| 365 | |
|---|
| 366 | echo "<tr><td>Total</td>"; |
|---|
| 367 | foreach ($date_totals as $cdate => $totcdate) { |
|---|
| 368 | echo "<td>$totcdate</td>\n"; |
|---|
| 369 | } |
|---|
| 370 | echo "<td>$nbsp</td>"; |
|---|
| 371 | echo "</tr>\n"; |
|---|
| 372 | |
|---|
| 373 | |
|---|
| 374 | |
|---|
| 375 | echo "<tr><th style=\"color:#FFF\">"; |
|---|
| 376 | echo "..................................................... </th>"; |
|---|
| 377 | table_column($collected_dates); |
|---|
| 378 | echo "<td style=\"color:#FFF\">"; |
|---|
| 379 | echo "..................................................... </td>"; |
|---|
| 380 | echo "</tr>\n"; |
|---|
| 381 | |
|---|
| 382 | |
|---|
| 383 | echo "</table>"; |
|---|
| 384 | } |
|---|
| 385 | |
|---|
| 386 | |
|---|
| 387 | |
|---|
| 388 | |
|---|
| 389 | |
|---|
| 390 | |
|---|
| 391 | |
|---|
| 392 | if ($output1=="csv" || $output1=="tsv") { |
|---|
| 393 | |
|---|
| 394 | |
|---|
| 395 | if ($output1=="csv") { |
|---|
| 396 | $precsv = "\""; |
|---|
| 397 | $posttext = "\","; |
|---|
| 398 | } else { |
|---|
| 399 | $precsv = ""; |
|---|
| 400 | $posttext = "\t"; |
|---|
| 401 | } |
|---|
| 402 | |
|---|
| 403 | |
|---|
| 404 | echo "$precsv" . "Archive Name$posttext"; |
|---|
| 405 | foreach ($collected_dates as $cdate => $totcdate) { |
|---|
| 406 | echo "$precsv$cdate$posttext"; |
|---|
| 407 | } |
|---|
| 408 | echo "\n"; |
|---|
| 409 | |
|---|
| 410 | |
|---|
| 411 | foreach ($archivelist as $aname => $aobject) { |
|---|
| 412 | |
|---|
| 413 | $name = $archivelist[$aname]->getName(); |
|---|
| 414 | echo "$precsv$name$posttext"; |
|---|
| 415 | |
|---|
| 416 | |
|---|
| 417 | $records=$archivelist[$aname]->returnRecords(); |
|---|
| 418 | |
|---|
| 419 | foreach ($collected_dates as $cdate => $totalcdate) { |
|---|
| 420 | $numrecord = $records[$cdate]; |
|---|
| 421 | echo "$precsv$numrecord$posttext"; |
|---|
| 422 | |
|---|
| 423 | $date_totals[$cdate]+=$numrecord; |
|---|
| 424 | } |
|---|
| 425 | echo "\n"; |
|---|
| 426 | |
|---|
| 427 | } |
|---|
| 428 | |
|---|
| 429 | |
|---|
| 430 | echo "$precsv" . "Total$posttext"; |
|---|
| 431 | foreach ($date_totals as $cdate => $totcdate) { |
|---|
| 432 | echo "$precsv$totcdate$posttext"; |
|---|
| 433 | } |
|---|
| 434 | echo "\n"; |
|---|
| 435 | } |
|---|
| 436 | |
|---|
| 437 | |
|---|
| 438 | |
|---|
| 439 | |
|---|
| 440 | |
|---|
| 441 | |
|---|
| 442 | if ($output1=="html") { |
|---|
| 443 | printhtmlfooter(); |
|---|
| 444 | } |
|---|
| 445 | ?> |
|---|