| 1 |
yamaji |
1.1 |
<?php |
| 2 |
|
|
// $Revision: 1.11 $ // |
| 3 |
|
|
// ------------------------------------------------------------------------ // |
| 4 |
|
|
// // |
| 5 |
|
|
// OAI-PMH based Institutional Repository Introduction Module // |
| 6 |
|
|
// Copyright (C) 2005 Kazutsuna YAMAJI. All rights reserved. // |
| 7 |
|
|
// // |
| 8 |
|
|
// ------------------------------------------------------------------------ // |
| 9 |
|
|
// This program is free software; you can redistribute it and/or modify // |
| 10 |
|
|
// it under the terms of the GNU General Public License as published by // |
| 11 |
|
|
// the Free Software Foundation; either version 2 of the License, or // |
| 12 |
|
|
// (at your option) any later version. // |
| 13 |
|
|
// // |
| 14 |
|
|
// You may not change or alter any portion of this comment or credits // |
| 15 |
|
|
// of supporting developers from this source code or any supporting // |
| 16 |
|
|
// source code which is considered copyrighted (c) material of the // |
| 17 |
|
|
// original comment or credit authors. // |
| 18 |
|
|
// // |
| 19 |
|
|
// This program is distributed in the hope that it will be useful, // |
| 20 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
| 21 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
| 22 |
|
|
// GNU General Public License for more details. // |
| 23 |
|
|
// // |
| 24 |
|
|
// You should have received a copy of the GNU General Public License // |
| 25 |
|
|
// along with this program; if not, write to the Free Software // |
| 26 |
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
| 27 |
|
|
// ------------------------------------------------------------------------ // |
| 28 |
|
|
|
| 29 |
|
|
define( 'GRAPH_PERIOD', 60*60*24*364*1 ); |
| 30 |
|
|
# |
| 31 |
|
|
$mhandler =& xoops_gethandler('module'); |
| 32 |
|
|
$module = $mhandler->getByDirname( 'irview' ); |
| 33 |
|
|
$chandler = & xoops_gethandler('config'); |
| 34 |
|
|
$assoc = $chandler->getConfigsByCat(false, $module->mid()); |
| 35 |
|
|
$jpgraph_location = $assoc['jpgraph_location']; |
| 36 |
|
|
$tmpfile_location = $assoc['tmpfile_location']; |
| 37 |
|
|
|
| 38 |
|
|
|
| 39 |
|
|
include($jpgraph_location."jpgraph.php"); |
| 40 |
|
|
include($jpgraph_location."jpgraph_line.php"); |
| 41 |
|
|
include($jpgraph_location."jpgraph_bar.php"); |
| 42 |
|
|
include($jpgraph_location."jpgraph_date.php"); |
| 43 |
|
|
|
| 44 |
|
|
$table_meta = $xoopsDB->prefix( 'irview_metadata' ); |
| 45 |
|
|
$table_repo = $xoopsDB->prefix( 'irview_repositories' ); |
| 46 |
|
|
// |
| 47 |
|
|
// Count the active repository from the irview_repositories table |
| 48 |
|
|
$sql = "SELECT repo.repository_id, repo.repository_name, repo.URL, repo.metadata_formats FROM ${table_repo} AS repo WHERE repo.enabled=1 AND repo.deleted!=1 ORDER BY repo.repository_id"; |
| 49 |
|
|
$result = $xoopsDB->query( $sql ); |
| 50 |
|
|
while($row = $xoopsDB->fetchRow( $result )){ |
| 51 |
|
|
$repo_id[] = (int)$row[0]; |
| 52 |
|
|
$repo_name[] = $row[1]; |
| 53 |
|
|
$repo_url[] = $row[2]; |
| 54 |
|
|
$repo_formats[] = $row[3]; |
| 55 |
|
|
$graph_filename[] = tempnam( $tmpfile_location, "IRview_" ); |
| 56 |
|
|
} |
| 57 |
|
|
// |
| 58 |
|
|
// |
| 59 |
|
|
$endTime = strtotime(date('Y/m/d', time())) + 60*60*24; |
| 60 |
|
|
foreach ($repo_id as $repo_id_key => $repo_id_val) { |
| 61 |
|
|
// Data obraining |
| 62 |
|
|
$sql = "SELECT meta.datestamp FROM ${table_meta} AS meta WHERE meta.repository_id=${repo_id_val}"; |
| 63 |
|
|
$result = $xoopsDB->query( $sql ); |
| 64 |
|
|
|
| 65 |
|
|
if($result){ |
| 66 |
|
|
while($row = $xoopsDB->fetchRow( $result )){ |
| 67 |
|
|
$graph_data[$repo_id_key][] = (int)$row[0]; |
| 68 |
|
|
} |
| 69 |
|
|
// |
| 70 |
|
|
sort($graph_data[$repo_id_key]); |
| 71 |
|
|
|
| 72 |
|
|
$total_data = array(); |
| 73 |
|
|
$each_data = array(); |
| 74 |
|
|
$timestamp = array(); |
| 75 |
|
|
$startTime = $graph_data[$repo_id_key][0]; |
| 76 |
|
|
$date_count = 0; |
| 77 |
|
|
$total_data[$date_count] = 0; |
| 78 |
|
|
|
| 79 |
|
|
for ( $i = $startTime; $i <= $endTime; $i = $i + (60*60*24) ) { |
| 80 |
|
|
$each_data[$date_count] = 0; |
| 81 |
|
|
foreach ( $graph_data[$repo_id_key] as $data_tmp ) { |
| 82 |
|
|
if (($i <= $data_tmp) && ($data_tmp < ($i + (60*60*24)))) { |
| 83 |
|
|
$each_data[$date_count]++; |
| 84 |
|
|
$total_data[$date_count]++; |
| 85 |
|
|
} |
| 86 |
|
|
} |
| 87 |
|
|
$timestamp[$date_count] = $i; |
| 88 |
|
|
if( $i <= $endTime-(60*60*24) ){ |
| 89 |
|
|
$total_data[$date_count+1] = $total_data[$date_count]; |
| 90 |
|
|
} |
| 91 |
|
|
$date_count++; |
| 92 |
|
|
} |
| 93 |
|
|
$total_data_final = array(); |
| 94 |
|
|
$each_data_final = array(); |
| 95 |
|
|
$timestamp_final = array(); |
| 96 |
|
|
|
| 97 |
|
|
// Extracting 1 year data for drawing |
| 98 |
|
|
// Data will be stored reversely |
| 99 |
|
|
if(sizeof($timestamp) < GRAPH_PERIOD) { |
| 100 |
|
|
for ( $i = sizeof($timestamp)-1, $count = 0; 0 <= $i; $i--, $count++) { |
| 101 |
|
|
$total_data_final[$count] = $total_data[$i]; |
| 102 |
|
|
$each_data_final[$count] = $each_data[$i]; |
| 103 |
|
|
$timestamp_final[$count] = $timestamp[$i]; |
| 104 |
|
|
} |
| 105 |
|
|
} else { |
| 106 |
|
|
for ( $i = sizeof($timestamp)-1, $count = 0; $endTime-GRAPH_PERIOD < $timestamp[$i]; $i--, $count++) { |
| 107 |
|
|
$total_data_final[$count] = $total_data[$i]; |
| 108 |
|
|
$each_data_final[$count] = $each_data[$i]; |
| 109 |
|
|
$timestamp_final[$count] = $timestamp[$i]; |
| 110 |
|
|
} |
| 111 |
|
|
} |
| 112 |
|
|
//var_dump($total_data_final); |
| 113 |
|
|
//var_dump($each_data_final); |
| 114 |
|
|
//var_dump($timestamp_final); |
| 115 |
|
|
// Setup for drawing graph |
| 116 |
|
|
$graph = new Graph(200,100); |
| 117 |
|
|
$graph->img->SetMargin(40,45,15,35); |
| 118 |
|
|
$graph->SetScale("datint", 0, "auto", $endTime-GRAPH_PERIOD, $endTime); |
| 119 |
|
|
// X axis configuration |
| 120 |
|
|
$graph->xaxis->SetTitleMargin(0); |
| 121 |
|
|
$graph->xaxis->title->SetFont(FF_VERA, FS_NORMAL,8); |
| 122 |
|
|
$graph->xaxis->SetFont(FF_VERA, FS_NORMAL,6); |
| 123 |
|
|
$graph->xaxis->HideTicks(true, false); |
| 124 |
|
|
$graph->xaxis->SetTextLabelInterval(2); |
| 125 |
|
|
$graph->xaxis->SetLabelAngle(45); |
| 126 |
|
|
$graph->xaxis->scale->SetDateFormat("y-M"); |
| 127 |
|
|
$graph->xaxis->scale->SetTimeAlign(MINADJ_1); |
| 128 |
|
|
$graph->xgrid->Show(true,false); |
| 129 |
|
|
// Y axis configuration |
| 130 |
|
|
$graph->yaxis->SetTitle("Items/day ", "middle"); |
| 131 |
|
|
$graph->yaxis->SetTitleMargin(28); |
| 132 |
|
|
$graph->yaxis->title->SetFont(FF_VERA, FS_NORMAL, 8); |
| 133 |
|
|
$graph->yaxis->title->SetColor("deepskyblue3"); |
| 134 |
|
|
$graph->yaxis->SetFont(FF_VERA, FS_NORMAL, 6); |
| 135 |
|
|
$graph->ygrid->Show(true,true); |
| 136 |
|
|
// Y2 axis configuration |
| 137 |
|
|
$graph->SetY2Scale("int"); |
| 138 |
|
|
$graph->y2axis->SetTitle("Total items ", "middle"); |
| 139 |
|
|
$graph->y2axis->SetTitleMargin(27); |
| 140 |
|
|
$graph->y2axis->title->SetFont(FF_VERA,FS_NORMAL,8); |
| 141 |
|
|
$graph->y2axis->title->SetColor("darkorange"); |
| 142 |
|
|
$graph->y2axis->SetFont(FF_VERA,FS_NORMAL,6); |
| 143 |
|
|
// |
| 144 |
|
|
$bplot = new BarPlot($each_data_final, $timestamp_final); |
| 145 |
|
|
$bplot->SetAbsWidth(1); |
| 146 |
|
|
$bplot->SetColor("deepskyblue3"); |
| 147 |
|
|
$lplot = new LinePlot($total_data_final, $timestamp_final); |
| 148 |
|
|
$lplot->SetColor("darkorange"); |
| 149 |
|
|
|
| 150 |
|
|
$graph->Add($bplot); |
| 151 |
|
|
$graph->AddY2($lplot); |
| 152 |
|
|
$graph->img->SetImgFormat('png'); |
| 153 |
|
|
$graph->SetColor("lightyellow"); |
| 154 |
|
|
$graph->SetMarginColor("azure2"); |
| 155 |
|
|
$graph->SetBox(true,'black',2); |
| 156 |
|
|
//$graph->SetTickDensity(TICKD_VERYSPARSE); |
| 157 |
|
|
$graph->SetTickDensity(TICKD_SPARSE); |
| 158 |
|
|
$graph->SetFrameBevel(2,true,"azure4"); |
| 159 |
|
|
// |
| 160 |
|
|
// Temporary saved image in $tmpfile_location |
| 161 |
|
|
//$graph->Stroke( ); |
| 162 |
|
|
$graph->Stroke($graph_filename[$repo_id_key]); |
| 163 |
|
|
|
| 164 |
|
|
//var_dump($graph_filename); |
| 165 |
|
|
// Saved image from $tmpfile_location to Database |
| 166 |
|
|
$fp = fopen($graph_filename[$repo_id_key],'rb'); |
| 167 |
|
|
if($fp){ |
| 168 |
|
|
$graph_image = base64_encode(fread($fp, filesize($graph_filename[$repo_id_key]))); |
| 169 |
|
|
$sql = "UPDATE ${table_repo} SET record_graph='".$graph_image. |
| 170 |
|
|
"' WHERE repository_id='".$repo_id_val."'"; |
| 171 |
|
|
$result = $xoopsDB->queryF( $sql ); |
| 172 |
|
|
if(!$result){ |
| 173 |
|
|
echo "ERROR : "._MD_IRVIEW_GRAPH_MYSQL_QUERY_ERROR; |
| 174 |
|
|
} |
| 175 |
|
|
}else{ |
| 176 |
|
|
echo "ERROR : "._MD_IRVIEW_GRAPH_FILE_OPEN_ERROR; |
| 177 |
|
|
} |
| 178 |
|
|
fclose($fp); |
| 179 |
|
|
unlink($graph_filename[$repo_id_key]); |
| 180 |
|
|
}else{ |
| 181 |
|
|
echo "ERROR : "._MD_IRVIEW_GRAPH_MYSQL_QUERY_ERROR; |
| 182 |
|
|
} |
| 183 |
|
|
} |
| 184 |
|
|
?> |