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 "$day/$month
$year
\n"; } else { echo "$month $year\n"; } } } ///////////////////////////////////////////////////////// // print flexitable function print_flexitable () { global $country; global $collected_dates; echo "\n\n"; echo ' "; } // end of flexitable function /////////////////////////////////////////////////////////////// // if user wants text file prompt to download. if ($output1 == "tsv") { // If no headers are sent, send one if (!headers_sent()) { //header('Location: http://www.example.com/'); header('Content-type: text/tab-separated-values'); header('Content-Disposition: attachment; filename="ir_records.tsv"'); } } elseif ($output1 == "csv") { // If no headers are sent, send one if (!headers_sent()) { header('Content-type: text/plain'); header('Content-Disposition: attachment; filename="ir_records.csv"'); } } $includeInHead = ' '; // only print the following html if we want html if ($output1=="html") { printhtmlhead ($pagetitle, $includeInHead); } //#################################################### // Connection to DB connectdb(); //################################################### // Print out title and top of page stuff if ($output1=="html") { echo "

$pagetitle

"; 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 "\n"; table_column($collected_dates, $freq); echo ""; echo "\n"; // go through each archive, print out the record totals in to the table foreach ($sortorder as $aname => $aobject) { echo "\n"; $name = $archivelist[$aname]->getName(); $identifier = urlencode ($archivelist[$aname]->getIdentifier()); echo " \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 "\n"; } else { echo "\n"; } // include this in the total for this date $date_totals[$cdate]+=$numrecord; } // print the archive name again echo "\n"; echo "\n"; } //Finally print out the column heads and grand totals echo ""; foreach ($date_totals as $cdate => $totcdate) { echo "\n"; } echo ""; echo "\n"; // this is an awful hack to make the repository name column // a decent size. echo ""; table_column($collected_dates); echo ""; echo "\n"; echo "
Respository Name "; $tmplink = linktome("order1", "archivename"); echo "[order by]Repository Name
"; $querystring = "id=$identifier&country=$country"; echo '' . $name . "" . number_format($numrecord) . "" . number_format($numrecord) . "$name
Total" . number_format($totcdate) . "$nbsp
"; echo "..................................................... "; echo ".....................................................
"; } //################################################## // Print txt/csv/tsv file // we can do either tab or comma seperated if ($output1=="csv" || $output1=="tsv") { // set these vars for tsv or csv if ($output1=="csv") { $precsv = "\""; $posttext = "\","; } else { $precsv = ""; $posttext = "\t"; } echo "$precsv" . "Archive Name$posttext"; foreach ($collected_dates as $cdate => $totcdate) { echo "$precsv$cdate$posttext"; } echo "\n"; // go through each archive, print out the record totals in to the table foreach ($archivelist as $aname => $aobject) { $name = $archivelist[$aname]->getName(); echo "$precsv$name$posttext"; //$archivelist[$aname]->printRecordList(); $records=$archivelist[$aname]->returnRecords(); foreach ($collected_dates as $cdate => $totalcdate) { $numrecord = $records[$cdate]; echo "$precsv$numrecord$posttext"; // include this in the total for this date $date_totals[$cdate]+=$numrecord; } echo "\n"; } //Finally print out grand totals echo "$precsv" . "Total$posttext"; foreach ($date_totals as $cdate => $totcdate) { echo "$precsv$totcdate$posttext"; } echo "\n"; } // end of text/csv output // ##################################################### //################################################## // Print json file if ($output1=="json") { echo ' { page: 1, total: 239, rows: [ '; echo "\n"; //echo "{id:'ZW',cell:['ZW','ZIMBABWE','Zimbabwe','ZWE','716']}"; // go through each archive, print out the record totals in to the table foreach ($archivelist as $aname => $aobject) { $name = $archivelist[$aname]->getName(); // name id has only a-z chars $nameid = trim(preg_replace('#[^\p{L}\p{N}]+#u', ' ', $name)); $thisrecord = "{id:'" . $nameid . "',cell:["; // column for the Name $thisrecord .= "'" . $nameid . "', "; $records=$archivelist[$aname]->returnRecords(); foreach ($collected_dates as $cdate => $totalcdate) { $numrecord = $records[$cdate]; $thisrecord .= "'$numrecord'"; $thisrecord .= ","; } // for the last item in this row, remove comma and add end of line stuff $thisrecord = rtrim($thisrecord, ","); $thisrecord .= "]}, "; echo $thisrecord; echo "\n"; } echo "]}"; } // end of json output // ##################################################### // only print footer if we are doing html if ($output1=="html") { echo "

Javascrip flexitable

"; print_flexitable(); printhtmlfooter(); } ?>