BB varname $varname tmpvalue $tmpvar
\n"; return "$tmpreturn"; } ////////////////////////////////////////////////////// // table_column // we do show this at top and bottom so may as well make // it a function function table_column ($collected_dates, $freq="monthly") { foreach ($collected_dates as $cdate => $totcdate) { list($year, $month, $day) = split('[/.-]', $cdate); $tmpurl = linktome("order1", "$cdate"); if ($freq == "weekly") { echo "Ordered by: $order1. \n"; echo "Frequency: $freq change to:"; if ($freq != "weekly") { // not using linktome function as we don't // want to use the current order date if changing from // weekly to monthly //$tmpurl = linktome("freq", "weekly"); echo " [weekly] \n"; } if ($freq != "monthly") { //$tmpurl = linktome("freq", "monthly"); echo " [monthly] \n"; } echo "
\n"; $tmpurl = linktome("output1", "tsv"); $tmpurl2 = linktome("output1", "csv"); echo "Export to text: tab seperated or comma seperate fields enclosed by doublequotes.
\n"; } //################################################### // Database connection and SQL // get a list of uniqure archive names $query = " SELECT DISTINCT archivename, identifier, country FROM $ircount_table WHERE country = '$country' "; $result_sussex = mysql_query($query) or die("Query failed : " . mysql_error()); $fields=mysql_num_rows($result_sussex); //##################################################### // Debug info // before we do much, print out some html comment debug if ($output1=="html") { echo "\n"; } // an array to hold names of archives $archivelist; // ########################################################## // loop for each record returned. while ($line = mysql_fetch_array($result_sussex, MYSQL_ASSOC)) { $archivename1 = $line[archivename]; $identifier = $line[identifier]; // remove spaces $archivename1 = trim($archivename1); // // add an entry to the array, the key being the archive name, // the value being a new object created at the same time. $archivelist[$archivename1] = new ArchiveClass(); // tell the object it's name $archivelist[$archivename1]->setName($archivename1); // tell the object it's IR identifier $archivelist[$archivename1]->setIdentifier($identifier); // for sorting later on, add this name to a hash $justnames[$archivename1]="$archivename1"; } // ####################################################################### // We now have an array - archivelist - which is a list of all archives. // Each key is an archive name, each value is an archive object. // SQL to get archives and dates $query2 = " SELECT archivename, records, DATE(collected_date) as dateonly, country FROM ircount WHERE country = '$country' "; $dbresult_list = mysql_query($query2) or die("Query failed : " . mysql_error()); // an array to hold the dates we collected data from $collected_dates; // an array to sort the results later $sortorder; // for each row returned - which will be an archive, date, and num of records etc // - add it to the object for that archive. // also... add the date to collected_dates if not already there while ($line2 = mysql_fetch_array($dbresult_list, MYSQL_ASSOC)) { $datestamp2 = $line2["dateonly"]; $archivename2 = $line2["archivename"]; $archivename2 = trim($archivename2); $records2 = $line2["records"]; // // lets do some error checking... if ($datestamp2 == "" || $archivename2 == "" || $records2 == "") { echo "ERROR $datestamp2 $records2 $archivename2 \n"; } if ($records2 == "0") { continue; } // Processing monthly is a little bit of a hack. // We go through each row (one for each archive each week) // but simply over write any entry we already have // for the month in question, creating one a month. // if we only want monthly, remove day from datestamp // the mmyy record for this repository will be overwritten // with the last record for this month if ($freq == "monthly") { list($year, $month, $day) = split('[/.-]', $datestamp2); $datestamp2 = "$year-$month"; } // add this date (and num of records) to the object for this // archive. $archivelist[$archivename2]->addToRecordslist($datestamp2,$records2); // record that we have come aross a line which was collected on this date $collected_dates[$datestamp2]++; // are we planning to sort the list based on *this* date? if so lets remember // the number of records for this archive in the sort order if ($order1==$datestamp2) { $sortorder[$archivename2]=$records2; } } // we have now added each line of data to the repository object it is associated with, // we have each archive which has a list of dates, attached to each date is the // number of records it had at the time. // We also now have collected_dates, a list of dates (as keys in the array, the // actual value being the number of times we saw that date). // we also have sortorder, which will already be complete if the sort order // was a date column. we need to populate it now if not // if user wants the order to be alphabetic by name (default) just make sort order // the same as justnames (which maps name to name (itself)) if ($order1=="archivename") { $sortorder = $justnames; } if ($sortorder =="") { $sortorder = $justnames; } // sort by the value in sort order. // the key is the archive name asort($sortorder); // sort archives alphabetically //ksort($archivelist); // sort the list of dates, earliest first. ksort($collected_dates); //##################################################### // print out html // first print table header, which includes all the collected dates if ($output1=="html") { # print the top row echo "
| Respository Name "; $tmplink = linktome("order1", "archivename"); echo "[order by] | \n"; table_column($collected_dates, $freq); echo "Repository Name | "; echo "||
|---|---|---|---|
| "; $querystring = "id=$identifier&country=$country"; echo '' . $name . " | \n"; //echo '$name\n'; //$archivelist[$aname]->printRecordList(); $records=$archivelist[$aname]->returnRecords(); foreach ($collected_dates as $cdate => $totalcdate) { $numrecord = $records[$cdate]; if ($numrecord == "") { $numrecord = " "; } // if we are sorted by this col make it bold if ($cdate==$order1) { echo "" . number_format($numrecord) . " | \n"; } else { echo "" . number_format($numrecord) . " | \n"; } // include this in the total for this date $date_totals[$cdate]+=$numrecord; } // print the archive name again echo "$name | \n"; echo "
| Total | "; foreach ($date_totals as $cdate => $totcdate) { echo "" . number_format($totcdate) . " | \n"; } echo "$nbsp | "; echo "|
| "; echo "..................................................... | "; table_column($collected_dates); echo ""; echo "..................................................... | "; echo "
Javascrip flexitable
"; print_flexitable(); printhtmlfooter(); } ?>