4) { echo "country value not right, sorry"; exit; } // not currently used global $output; $output = $_GET['output']; if ($output == "") { $output = "html"; } // use i18n library, if we have set to use this above... if ($use_i18n) { // Dreamhost wiki tells us to use PEAR like this... ini_set( 'include_path', ini_get( 'include_path' ) . PATH_SEPARATOR . "/home/ckeene/pear/php" ); require_once 'I18N/Country.php'; // now look up the current selected country name global $currentCountryName; $currentCountryName = getCountryName($country); } // archive object used for most funcionality require_once("class.archive.php"); } //############################################ // check_args - checks the args from processed args, // but has to be run after a mysql connection is made function check_args () { //echo "check ags countryr\`n"; $country = mysql_real_escape_string ($country); $output = mysql_real_escape_string ($output); } // ########################################### // some sql statements // list of IRs for a country with current/highest // record count. function sql_irlist1 ($ircount_table, $country) { global $sql_irlist1; $sql_irlist1 = " SELECT i.identifier, r.title, max( i.records ) as highrecords FROM $ircount_table i, repositories r WHERE DATE_SUB(CURDATE(),INTERVAL 2 WEEK) <= i.collected_date AND r.location_country = \"$country\" AND i.identifier = r.eprintid GROUP BY i.identifier ORDER BY r.title"; return $sql_irlist1; } // ############################################# // function to try and record processing time function getmicrotime() { list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } // ############################################ // print processing time so far function printprocessingtime($msg="") { global $scriptStartTime, $debug; if ($debug) { echo "

$msg Time elapsed: ",getmicrotime() - $scriptStartTime, " seconds

"; } } //############################ // print countries // a list of links of each country function printCountries ($ircount_table, $use_i18n) { $sql_country = "SELECT location_country FROM repositories GROUP BY location_country;"; $result = mysql_query($sql_country); //or die("Query failed : " . mysql_error()); // only try and print if we have result if ($result) { echo "\n \n"; } } // ############################################## // getCountryName($country) // return an English name for a given two digit country code // eg de->Germany // only call this function if use_i18n flag set. function getCountryName($code) { //Create an instance of the I18N_Country class // this is used to find the real country names from the two digits code. if (!$code) { $code = "gb"; } // have been configured to not use country lookup // just return country code. global $use_i18n; if (!$use_i18n) { return $code; } if (!$countrylist) { global $countrylist; $countrylist = new I18N_Country (); } if($countrylist->isValidCode($code)) { // country name is returned in all caps // so we change it to lower case and then // use ucwords to start each word with a capital $tmp = ucwords(strtolower($countrylist->getName($code))); return $tmp; } else { //if no match found, it may be edu or mil if ($code == "edu") { return "USA edu"; } elseif ($code == "mil") { return "USA military"; } elseif ($code == "gov") { return "USA Government"; } else { // give up return "code " . $code; } } // end of ifvalid } // end of function // ############################################ // getRepositoryFacts($repositories) // looks at all reposities for a page, and finds a few facts about the group. // eg. start/end date, and the highest count amongst all of them function getRepositoryFacts($repositories) { global $allDates; $highestRecordCount; $firstCollectedDate = "2020-01-01"; // some date in the future, will be over-written below $lastCollectedDate; $numOfDates; $numOfDates = count($allDates); foreach ($repositories as $repoid => $repository) { // get some facts, which includes the highest count for this IR $thisRepositoryFacts = $repository->returnIRFacts(); // if this is higher than the overall highestcount, set a new highest count if ($thisRepositoryFacts['highestNumRecords'] > $highestRecordCount) { $highestRecordCount = $thisRepositoryFacts['highestNumRecords']; } // if the last (more recent) collected date for this IR is later than our current // last date, use this as the new last collected date if ($thisRepositoryFacts['lastCollectedDate'] > $lastCollectedDate) { $lastCollectedDate = $thisRepositoryFacts['lastCollectedDate']; } // same as above but for first collected date if ($thisRepositoryFacts['firstCollectedDate'] < $firstCollectedDate) { $firstCollectedDate = $thisRepositoryFacts['firstCollectedDate']; } } // end of loop for each repository $facts = array( firstCollectedDate => $firstCollectedDate, lastCollectedDate => $lastCollectedDate, num_of_weeks => $numOfDates, highestNumRecords => $highestRecordCount, ); return $facts; } //############################################### // RepositoryListMenu(Country) // return the html to display a list of repositories. // if country passed, limit to that country. function repositoryListMenu ($ircount_table, $static_querystring, $country="all", $endquerystring="") { $returnstring = ""; // use the array of repository objects global $repositories; // build up the GET string we will use for each IR in the drop down list, foreach ($repositories as $num => $repository) { $id = $repository->getIdentifier(); $idname = "id" . $num; $static_querystring .= "&$idname=$id"; } // num of the last IR in the loop above, plus 1, gives us the id // of the new IR we will add with this link $newidnum = $num + 1; // add the new id number to the query string, the id will be added for each ir below $static_querystring .= "&id$newidnum="; // select list of IRs (all, or for a given country), only select a recent record, so to use // an uptodate name. $IRlistSQL = " SELECT identifier, SUBSTRING(archivename,1,80) as archivename, max( records ) as highrecords FROM $ircount_table WHERE records > 0"; // add country line to sql if country specified if ($country !="all") { $IRlistSQL .= " AND country = '$country' "; } $IRlistSQL .= " AND DATE_SUB(CURDATE(),INTERVAL 2 WEEK) <= collected_date GROUP BY identifier ORDER BY archivename "; // note selecting only lines with a recent date (2 week) ensures the name is fairly up to date // if it has been changed on roar etc // connect to mysql and do query $IRlistDB = mysql_query($IRlistSQL) or die("RepositoryListMenu $country Query failed : " . mysql_error()); $returnstring = "
\n"; $returnstring .= '
\n\n"; return $returnstring; } // ########################################################## // createAllDateList ($dateRecordList, $allDates); // take a array of dates for one IR, and possible an array of already // and merge the former in to the latter. function createAllDateList ($dateRecordList, $allDates) { foreach ($dateRecordList as $date => $count) { // for each date for this ir, add it to the array for all IRs $allDates[$date]++; } return $allDates; } // ###################################################### // getCoverageFacts($repository); // return stuff like first/last collection dates (i.e. first collection date // of the IR that started first), number of weeks we have overall // Why does this function exist?????? why can't we just use returnIRfacts??? function getCoverageFacts($repository) { // this function shouldn't have to do much, the IR objects do all the work :) $irCoverage = array(); $irCoverage = $repository->returnIRFacts(); if ($debug) { echo ""; } return $irCoverage; } // ########################################################## // removeIRurl($repository, $repositories); // create a link but without the repository passed, but with all other repositories function removeIRurl($repository, $repositories) { global $country; $i=0; $url = "?"; foreach ($repositories as $id => $repo) { $i++; if ($repository->getIdentifier() == $repo->getIdentifier()) { // this is the repository we want to remove // so don't do any more, but remove 1 from i, for the id numbers of remaining IRs $i = $i - 1; continue; } $repoid = $repo->getIdentifier(); $url .= "id" . $i . "=" . $repoid . "&"; } $url .= "country=$country"; return $url; } // ###################################################### // printWeeklyTable( ListOfIRObjects) // html table of repositories. columns=repositories, rows=dates, most recent date first function printWeeklyTable ($repositories, $allDates, $dateRecordLists, $numOfRepositories) { // table header $table_out .= "
\n \n\n"; foreach ($repositories as $idnum => $repository) { $irname = $repository->getName(); $table_out .= "\n"; } echo "\n"; // main loop for each date, showing number of records, if any, for each IR foreach ($allDates as $oneWeek => $numOfTimesSeen) { $table_out .= "\n"; $table_out .= ""; // print out record cound for this week for each repository for ($i = 1; $i <= $numOfRepositories; $i++) { $recordcount = $dateRecordLists[$i][$oneWeek]; $table_out .= ""; } $table_out .= "\n"; } // print out last row, which has links to raw data $table_out .= "\n"; foreach ($repositories as $idnum => $repository) { $table_out .= "'; } $table_out .= "
Date $irname
$oneWeek" . number_format($recordcount) . "
show getIdentifier(); $table_out .= '">all data

Note: Weeks with no records are not included.

\n"; echo $table_out; } // ########################################### // returnGoogleChartURL($repositories, $allDates, $numOfRepositories) // provided a url to use for googlecharts, based on the repositories passed function returnGoogleChartURL($repositories, $allDates, $numOfRepositories) { $doMonthly=0; // if set to 1 below, will plot by month, not week ksort($allDates); // order allDates $urlStart = "http://chart.apis.google.com/chart?cht=lc"; $size = "800x200"; $lastCollectedDate = "2009-10-25"; $firstCollectedDate = "2009-10-25"; $highestRecordCount = "10"; global $debug; global $debugText; $numOfDates = count($allDates); // how many weeks are we dealing with? // roughly speaking, string we use for google chart depends on num of repositories, // multiplied by number of dates, multiplied by 5 (for each entry, we will need ~4 digit number // plus a comma = 5. $ChartDataAproxSize = $numOfDates * $numOfRepositories * 5; if ($debug) { $debugText .= "$ChartDataAproxSize equals $numOfDates x $numOfRepositories * 5 \n"; } // we're going to say any predicted string length of 2,000 or more is too long, // and there is a chance the chart will not show. // So instead we need to get monthly data instead of weekly... if ($ChartDataAproxSize > 2000) { $doMonthly=1; } // for each IR get data and see if it had the highest count foreach ($repositories as $repoid => $repository) { // each repository produces it's own data ready for googleChart to used // either per week or per month, as set above. $RepoChartData .= $repository->getGoogleChartData ($allDates, $doMonthly); if ($debug) { $debugText .= "

data starts: $RepoChartData

"; } $RepoChartData .= "|"; // get some facts, which includes the highest count for this IR $thisRepositoryFacts = $repository->returnIRFacts(); // if this is higher than the overall highestcount, set a new highest count if ($thisRepositoryFacts['highestNumRecords'] > $highestRecordCount) { $highestRecordCount = $thisRepositoryFacts['highestNumRecords']; } // if the last (more recent) collected date for this IR is later than our current // last date, use this as the new last collected date if ($thisRepositoryFacts['lastCollectedDate'] > $lastCollectedDate) { $lastCollectedDate = $thisRepositoryFacts['lastCollectedDate']; } // same as above but for first collected date if ($thisRepositoryFacts['firstCollectedDate'] < $firstCollectedDate) { $firstCollectedDate = $thisRepositoryFacts['firstCollectedDate']; } // add this IRs name to the list of names $nameList .= $repository->getName() . "|"; } // end of loop for each repository // a hack... remove the pipe for the last repository $RepoChartData = rtrim($RepoChartData, "|"); $nameList = rtrim($nameList, "|"); // build the google chart url............ // chs=250x100 is the chart's size in pixels. // chd=t:60,40 is the chart's data. // cht=p3 is the chart's type. // chl=Hello|World is the chart's label // chds data scaling . // chart labels... // chxt=x,y // chxl= // 0:|Jan|July|Jan|July|Jan| // 1:|0|50|100| $url = $urlStart . "&chs=" . $size . "&chd=t:" . $RepoChartData . "&chds=1,$highestRecordCount" . "&chco=ff0000,00ff00,0000ff,00ffff,cc9900,990066,ffff33,006600" . "&chdl=" . $nameList . "&chxt=x,y" . "&chxr=1,0," . $highestRecordCount . "&chxl=0:|" . $firstCollectedDate . "|" . $lastCollectedDate; return $url; } // ################################################# // function IS_ODD // can be used to check odd/even for table blue/white function IS_ODD($number) { return($number & 1); } // ################################################ // print page header function printhtmlhead($title2, $extrahead=" ") { // extra head just sounds sooo wrong echo ' ' . $title2 . ' : ircount ' . $extrahead . '
Home | Full table | Info & help | nostuff.org |
'; } // end of print header /////////////////////////////////////////////////// ////////////////////////////////////////////////// // printhtmlfooter function printhtmlfooter () { global $debug, $scriptStartTime; ?>

Contact: Chris Keene chriskeene@gmail.com | Using data from Registry of Open Access Repositories (ROAR) | Part of the content-free nostuff.org.