PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/Prohits/msManager/ms_storage_raw_info_pop.php

http://prohits.googlecode.com/
PHP | 362 lines | 320 code | 18 blank | 24 comment | 62 complexity | acbcb9de12a7b9fe11e7106733ec274f MD5 | raw file
  1. <?
  2. /***********************************************************************
  3. Copyright 2010 Gingras and Tyers labs,
  4. Samuel Lunenfeld Research Institute, Mount Sinai Hospital.
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. *************************************************************************/
  15. $bgcolordark = '#858585';
  16. $bodycolor = '#ffffff';
  17. $bgHitcolor="#e1e1e1";
  18. $bgDatecolor = "#cecece";
  19. $bigest_size = 0;
  20. $bigest_num_file = 0;
  21. include("./ms_permission.inc.php");
  22. /*echo "<pre>";
  23. print_r($request_arr);
  24. echo "</pre>";*/
  25. $start_date = $start_date_static = '3000-01-00';
  26. $end_date = $end_date_static = '1900-01-00';
  27. $time_arr = array();
  28. $table_arr = $managerDB->list_tables();
  29. $tableName_arr = array();
  30. $colorArr = get_color_arr();
  31. $matrix_arr = array();
  32. if($tableName){
  33. $bar_color = array_pop($colorArr);
  34. $tableName_arr[$tableName] = $bar_color;
  35. }else{
  36. foreach($BACKUP_SOURCE_FOLDERS as $baseTable => $var_arr){
  37. if(array_key_exists($baseTable, $table_arr)) continue;
  38. $bar_color = array_pop($colorArr);
  39. $tableName_arr[$baseTable] = $bar_color;
  40. }
  41. }
  42. $subSQL = get_subSql_for_file_types();
  43. foreach($tableName_arr as $tableName_key => $tableName_val){
  44. $matrix_arr[$tableName_key] = get_sub_total($tableName_key, $frm_date1, $frm_date2,$subSQL);
  45. }
  46. get_time_interval_array($start_date,$end_date);
  47. /*echo "<pre>";
  48. print_r($time_arr);
  49. print_r($tableName_arr);
  50. print_r($matrix_arr);
  51. echo "</pre>";*/
  52. if(!$time_arr){
  53. $tmp_date1_arr = explode("-",$frm_date1);
  54. $tmp_date2_arr = explode("-",$frm_date2);
  55. if($interval == 'yearly'){
  56. $frm_date1_tmp = $tmp_date1_arr[0];
  57. $frm_date2_tmp = $tmp_date2_arr[0];
  58. }else{
  59. $frm_date1_tmp = $tmp_date1_arr[0]."-".$tmp_date1_arr[1];
  60. $frm_date2_tmp = $tmp_date2_arr[0]."-".$tmp_date2_arr[1];
  61. }
  62. if($frm_date1_tmp == $frm_date2_tmp){
  63. $on_data_str = "There is no any data in $frm_date1_tmp";
  64. }else{
  65. $on_data_str = "There is no any data between $frm_date1_tmp and $frm_date2_tmp";
  66. }
  67. ?>
  68. <center>
  69. <font face="Arial" size="5" color="#804040">&nbsp;<b>Raw Files Statistics</font><br><br>
  70. <?=$on_data_str?>
  71. </center>
  72. <?
  73. exit;
  74. }
  75. $_SESSION["time_arr"] = $time_arr;
  76. $_SESSION["tableName_arr"] = $tableName_arr;
  77. $_SESSION["matrix_arr"] = $matrix_arr;
  78. ?>
  79. <html>
  80. <head>
  81. <title>Prohits</title>
  82. <link rel="stylesheet" type="text/css" href="../analyst/site_style.css">
  83. <script language="Javascript" src="ms.js"></script>
  84. <script language="javascript">
  85. </script>
  86. </script>
  87. </head>
  88. <body>
  89. <font face="Arial" size="5" color="#804040">&nbsp;<b>Raw Files Statistics</font>
  90. <?
  91. if(!$tableName && $show_single && $show_all){
  92. $show_single = '';
  93. if($file_size) display_info($file_size);
  94. if($num_file) display_info($num_file);
  95. $show_single = 'single';
  96. $show_all = '';
  97. if($file_size) display_info($file_size);
  98. if($num_file) display_info($num_file);
  99. }else{
  100. if($file_size) display_info($file_size);
  101. if($num_file) display_info($num_file);
  102. }
  103. ?>
  104. </body>
  105. </html>
  106. <?
  107. exit;
  108. function display_info($content){
  109. global $tableName,$file_type,$theaction,$frm_date1,$frm_date2,$interval,$show_all,$show_single;
  110. global $table_style,$bar_style,$line_style,$pare_style,$size_unit,$bigest_size,$bigest_num_file;
  111. global $tableName_arr,$time_arr,$matrix_arr,$tableWidth,$bgDatecolor;
  112. $bgcolordark = '#858585';
  113. $bodycolor = '#ffffff';
  114. $bgHitcolor="#e8e8e8";
  115. $sub_title = '';
  116. if($content == 'size'){
  117. $main_title = 'Files size';
  118. $sub_title = '('.$size_unit.')';
  119. if($show_all) $sub_title .= " [All Machines]";
  120. }else{
  121. $main_title = 'Number of Files';
  122. if($show_all) $main_title .= " </b><font face='Arial' size='2' color='#FFFFFF'>[All Machines]</font>";
  123. }
  124. $imageWidth = 400;
  125. $tital = "tmp titles";
  126. $border = '1';
  127. $orientation = 'H';
  128. ?>
  129. <table border="0" cellpadding="1" cellspacing="1" width="700">
  130. <tr><td><hr></td></tr>
  131. <tr bgcolor="">
  132. <td colspan="3" bgcolor="#0080c0" >
  133. <font face="Arial" size="3" color="#FFFFFF">&nbsp;<b><?=$main_title?></b></font>&nbsp;<font face="Arial" size="2" color="#FFFFFF"><?=$sub_title?></font>
  134. </td>
  135. </tr>
  136. <?if($table_style){?>
  137. <tr>
  138. <td>
  139. <table border="0" cellpadding="1" cellspacing="1" >
  140. <?if(!$tableName && $show_all == "all"){?>
  141. <tr><td bgcolor="<?echo $bgDatecolor;?>" width="10">&nbsp;</td>
  142. <?foreach($time_arr as $time_val){?>
  143. <td bgcolor="<?echo $bgDatecolor;?>" align=center><span class=maintext><b><?=$time_val?></b></span></td>
  144. <?}?>
  145. </tr>
  146. <tr>
  147. <td bgcolor="<?echo $bgHitcolor;?>" nowrap><span class=maintext>&nbsp;<b>All Machines</b>&nbsp;</span></td>
  148. <?foreach($time_arr as $time_val){
  149. $sub_total_val = 0;
  150. foreach($tableName_arr as $tmp_table_key => $tmp_table_name){
  151. if(isset($matrix_arr[$tmp_table_key][ $time_val][$content])){
  152. $sub_total_val += $matrix_arr[$tmp_table_key][ $time_val][$content];
  153. }
  154. }
  155. ?>
  156. <td bgcolor="<?echo $bgHitcolor;?>" align=right nora><span class=maintext><?=$sub_total_val?></span></td>
  157. <?
  158. }
  159. ?>
  160. </tr>
  161. <?}else{?>
  162. <tr><td bgcolor="<?echo $bgDatecolor;?>" width="10">&nbsp;</td>
  163. <?foreach($time_arr as $time_val){?>
  164. <td bgcolor="<?echo $bgDatecolor;?>" align=center><span class=maintext><b><?=$time_val?></b></span></td>
  165. <?}?>
  166. </tr>
  167. <?foreach($tableName_arr as $tableName_key => $tableName_val){?>
  168. <tr>
  169. <td bgcolor="<?echo $bgHitcolor;?>"><span class=maintext>&nbsp;<b><?=$tableName_key?></b>&nbsp;</span></td>
  170. <?foreach($time_arr as $time_val){
  171. $file_size = 0;
  172. if(isset($matrix_arr[$tableName_key][$time_val])) $file_size = $matrix_arr[$tableName_key][$time_val][$content];
  173. ?>
  174. <td bgcolor="<?echo $bgHitcolor;?>" align=right><span class=maintext><?=$file_size?></span></td>
  175. <?}?>
  176. </tr>
  177. <?}
  178. }
  179. }
  180. ?>
  181. </table>
  182. </td>
  183. </tr>
  184. <?
  185. if($line_style){
  186. $tmp_file = "./line_status_gif.php?tital=$tital&imageWidth=$tableWidth&border=$border&size_unit=$size_unit&tableName=$tableName&file_type=$file_type&bigest_size=$bigest_size&bigest_num_file=$bigest_num_file&show_single=$show_single&show_all=$show_all&content=$content&interval=$interval";
  187. ?>
  188. <tr><td>
  189. <table border="0" cellpadding="1" cellspacing="1" width="100%">
  190. <tr>
  191. <td width="100">
  192. <img src="./line_status_gif.php?tital=<?=$tital?>&imageWidth=<?=$tableWidth?>&border=<?=$border?>&size_unit=<?=$size_unit?>&tableName=<?=$tableName?>&file_type=<?=$file_type?>&bigest_size=<?=$bigest_size?>&bigest_num_file=<?=$bigest_num_file?>&show_single=<?=$show_single?>&show_all=<?=$show_all?>&content=<?=$content?>&interval=<?=$interval?>">
  193. <!--a href="javascript: newpopwin('<?=$tmp_file?>',850,1000);">table</a-->
  194. </td>
  195. </tr>
  196. </table>
  197. </td></tr>
  198. <?}
  199. if($bar_style){
  200. ?>
  201. <tr><td>
  202. <table border="0" cellpadding="1" cellspacing="1" width="100%">
  203. <?
  204. if(!$tableName && $show_single == "single"){
  205. $time_counter = 0;
  206. foreach($time_arr as $time_key => $time_val){
  207. if(!($time_key%2)) echo "<tr>";
  208. ?>
  209. <td width="100">
  210. <img src="./bar_status_gif.php?tital=<?=$tital?>&imageWidth=<?=$imageWidth?>&border=<?=$border?>&orientation=<?=$orientation?>&size_unit=<?=$size_unit?>&tableName=<?=$tableName?>&file_type=<?=$file_type?>&date_time=<?=$time_val?>&bigest_size=<?=$bigest_size?>&bigest_num_file=<?=$bigest_num_file?>&show_single=<?=$show_single?>&content=<?=$content?>">
  211. <!--a href="./bar_status_gif.php?tital=<?=$tital?>&imageWidth=<?=$imageWidth?>&border=<?=$border?>&orientation=<?=$orientation?>&size_unit=<?=$size_unit?>&tableName=<?=$tableName?>&file_type=<?=$file_type?>&date_time=<?=$time_val?>&bigest_size=<?=$bigest_size?>&bigest_num_file=<?=$bigest_num_file?>&show_single=<?=$show_single?>&content=<?=$content?>" class=button>[test]</a-->
  212. </td>
  213. <?
  214. if($time_key>=2 && ($time_key%2)) echo "</tr>";
  215. $time_counter++;
  216. }
  217. }else{
  218. ?>
  219. <td width="100">
  220. <img src="./bar_status_gif.php?tital=<?=$tital?>&imageWidth=<?=$imageWidth?>&border=<?=$border?>&orientation=<?=$orientation?>&size_unit=<?=$size_unit?>&tableName=<?=$tableName?>&file_type=<?=$file_type?>&date_time=<?=$time_val?>&bigest_size=<?=$bigest_size?>&bigest_num_file=<?=$bigest_num_file?>&show_single=<?=$show_single?>&show_all=<?=$show_all?>&content=<?=$content?>">
  221. <!--a href="./bar_status_gif.php?tital=<?=$tital?>&imageWidth=<?=$imageWidth?>&border=<?=$border?>&orientation=<?=$orientation?>&size_unit=<?=$size_unit?>&tableName=<?=$tableName?>&file_type=<?=$file_type?>&date_time=<?=$time_val?>&bigest_size=<?=$bigest_size?>&bigest_num_file=<?=$bigest_num_file?>&show_single=<?=$show_single?>&show_all=<?=$show_all?>&content=<?=$content?>" class=button>[test]</a-->
  222. </td>
  223. <?
  224. }
  225. ?>
  226. </table>
  227. </td>
  228. </tr>
  229. <?}?>
  230. </table>
  231. </td>
  232. </tr>
  233. <?
  234. }
  235. function get_subSql_for_file_types(){
  236. global $file_type,$RAW_FILES;
  237. if($file_type == 'all'){
  238. $formal_type_arr = explode(',',$RAW_FILES);
  239. for($i=0; $i<count($formal_type_arr); $i++){
  240. $formal_type_arr[$i] = trim($formal_type_arr[$i]);
  241. }
  242. $formal_type_str = implode("','", $formal_type_arr);
  243. $formal_type_str = "'".$formal_type_str."'";
  244. $subSQL = " AND FileType IN ($formal_type_str)";
  245. }else{
  246. $subSQL = " AND FileType='$file_type'";
  247. }
  248. return $subSQL;
  249. }
  250. function get_time_interval_array($frm_date1,$frm_date2){
  251. global $interval,$time_arr,$start_date_static,$end_date_static;
  252. if($frm_date1 == $start_date_static && $frm_date2 == $end_date_static) return $time_arr = array();
  253. $tmpArr1 = explode('-',$frm_date1);
  254. $tmpArr2 = explode('-',$frm_date2);
  255. if($interval == 'yearly'){
  256. for($i=$tmpArr1[0]; $i<=$tmpArr2[0]; $i++){
  257. array_push($time_arr, $i);
  258. }
  259. }elseif($interval == 'monthly'){
  260. if($tmpArr1[0] == $tmpArr2[0]){
  261. $start_month = $tmpArr1[1];
  262. $end_month = $tmpArr2[1];
  263. $year = $tmpArr1[0];
  264. time_for_month($start_month,$end_month,$year);
  265. }else{
  266. $start_month = $tmpArr1[1];
  267. $end_month = 12;
  268. $year = $tmpArr1[0];
  269. time_for_month($start_month,$end_month,$year);
  270. for($i=$tmpArr1[0]; $i<$tmpArr2[0]-1; $i++){
  271. $start_month = 1;
  272. $end_month = 12;
  273. $year = $i + 1;
  274. time_for_month($start_month,$end_month,$year);
  275. }
  276. $start_month = 1;
  277. $end_month = $tmpArr2[1];
  278. $year = $tmpArr2[0];
  279. time_for_month($start_month,$end_month,$year);
  280. }
  281. }
  282. }
  283. function time_for_month($start_month,$end_month,$year){
  284. global $time_arr;
  285. for($j=$start_month; $j<=$end_month; $j++){
  286. $month = $j;
  287. if(strlen($j) == 1) $month = '0'.$j;
  288. $month_key = $year.'-'.$month;
  289. array_push($time_arr,$month_key);
  290. }
  291. }
  292. function get_sub_total($tableName, $time1, $time2,$subSQL){
  293. global $managerDB,$start_date,$end_date,$bigest_size,$bigest_num_file,$interval,$size_unit;
  294. $sub_total = array();
  295. if(!$tableName || !$time1 || !$time2) return $sub_total;
  296. $SQL = "SELECT `ID`,`Size`,`FileType`,`Date` FROM $tableName WHERE `Date`>='$time1' AND `Date`<='$time2'".$subSQL."ORDER BY `Date`";
  297. $tmpArr = $managerDB->fetchAll($SQL);
  298. if(!$tmpArr) return $sub_total;
  299. foreach($tmpArr as $tmpVal){
  300. $tmp_size = ($tmpVal['Size'])?$tmpVal['Size']:0;
  301. $tmp_time = explode('-',$tmpVal['Date']);
  302. if($interval == 'monthly'){
  303. $date_key = $tmp_time[0].'-'.$tmp_time[1];
  304. }else{
  305. $date_key = $tmp_time[0];
  306. }
  307. if(!array_key_exists($date_key, $sub_total)){
  308. $sub_total[$date_key]['size'] = $tmp_size;
  309. $sub_total[$date_key]['num_files'] = 1;
  310. }else{
  311. $sub_total[$date_key]['size'] += $tmp_size;
  312. $sub_total[$date_key]['num_files']++;
  313. }
  314. if($tmpVal['Date'] < $start_date) $start_date = $tmpVal['Date'];
  315. if($tmpVal['Date'] > $end_date) $end_date = $tmpVal['Date'];
  316. }
  317. foreach($sub_total as $key => $sub_val){
  318. if($size_unit == 'GB'){
  319. $sub_total[$key]['size'] = round(($sub_total[$key]['size']/1024)/1024/1024,2);
  320. }else{
  321. $sub_total[$key]['size'] = round(($sub_total[$key]['size']/1024)/1024,1);
  322. }
  323. if($sub_total[$key]['size'] > $bigest_size) $bigest_size = $sub_total[$key]['size'];
  324. if($sub_total[$key]['num_files'] > $bigest_num_file) $bigest_num_file = $sub_total[$key]['num_files'];
  325. }
  326. return $sub_total;
  327. }
  328. function get_color_arr(){
  329. $colorArr = array('C5CBF7','A9A850','99ffcc','AC9A72','F6B2A9','DF9DF7','884D9E','798AF9','687CFA','AE15E7',
  330. 'D5CCCD','586EFA','8ED0F5','69B0D8','4C90B7','54F4F6','82ACAD','909595','A0F4B8','7BBC8D',
  331. '43CB69','E9E86F','A7B2F6','ffff99','99ffff','99cc00','999900','ffccff','006600','6666ff',
  332. '663399','0000ff','cc3300','0099ff','9999ff','99ccff','996600','cc99ff','ff3300','ff66ff',
  333. 'ff00ff','99ccff','996600','00ff00','990000','993333','99cc33','9999ff','ccccff','9933cc',
  334. 'ffffcc','ccffff','ccff99','ccff33','E6B751','99ff00','ff00ff','6633ff','6633ff','6600ff',
  335. 'ffffff','66ffcc','ffcccc','66cccc','ff99cc','6699cc','ff66cc','6666cc','ff33cc','6633cc',
  336. 'ffff66','66ff66','ffcc66','66cc66','ff9966','669966','ff6666','666666','ff3366','663366',
  337. '99ff33','00ff33','99cc33','00cc33','999933','009933','996633','006633','993333','003333',
  338. '99ffcc','00ffcc','99cccc','00cccc','9999cc','0099cc','9966cc','0066cc','9933cc','0033cc');
  339. return $colorArr;
  340. }
  341. ?>