superedit-GRAPH.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <?php
  2. Lib::loadClass('PHPGraphLib');
  3. function GRAPH() {
  4. $type = V::get('type', '', $_GET);
  5. switch ($type) {
  6. case 'TABLE':
  7. GRAPH_table();
  8. break;
  9. case 'HOUR':
  10. GRAPH_hour();
  11. break;
  12. default:
  13. GRAPH_default();
  14. }
  15. }
  16. function GRAPH_RandomColorGenerator(){
  17. //global $red, $green, $blue, $color;
  18. $color = array(rand(50,255), rand(50,255), rand(50,255)); //generates random RGB color;
  19. $red = $color[0]; //red value;
  20. $green = $color[1]; //green value;
  21. $blue = $color[2]; //blue value;
  22. $ret=$red.",".$green.",".$blue;
  23. // $ret="255,5,5";
  24. return($ret);
  25. }
  26. function GRAPH_table() {
  27. //$ARR['DATE_CHART'][$DWA->C2][$DWA->C1_Y][$DWA->C1_M][$DWA->C1_D]++;
  28. foreach($_SESSION['CHART']['ARR']['DATE_CHART'] as $C2=>$C2V) {
  29. $i=0;
  30. // echo "\n wstawiam dla C2 ".$C2." dane ".$C2V;
  31. // $data_color[$C2]=GRAPH_RandomColorGenerator();
  32. foreach($C2V as $C1_Y=>$C1_YV) {
  33. // echo "\n wstawiam dla C1_Y ".$C1_Y." dane ".$C1_YV;
  34. foreach($C1_YV as $C1_M=>$C1_MV) {
  35. // echo "\n wstawiam dla C1_M ".$C1_M." dane ".$C1_MV;
  36. foreach($C1_MV as $C1_D=>$C1_DV) {
  37. // echo "\n wstawiam dla ".$C1_MV." dane ".$C1_DV;
  38. $data[$C2][substr($C1_Y,-2)."-".$C1_M."-".$C1_D]=$C1_DV['COUNT'];
  39. // $data_hrs[$C2][substr($C1_Y,-2)."-".$C1_M."-".$C1_D]=$C1_DV;
  40. $i+=$C1_DV['COUNT'];
  41. //if($i>14) break;
  42. //hours
  43. foreach($C1_DV['TABLE'] as $C1_H=>$C1_HV) {
  44. //echo "\n wstawiam dla C1_H ".$C1_H." dane ".$C1_HV;
  45. $data_table[$C2][$C1_H]+=$C1_HV;
  46. }
  47. }
  48. }
  49. }
  50. // break;
  51. }
  52. /*
  53. $data = array("1" => .0032, "2" => .0028, "3" => .0021, "4" => .0033,
  54. "5" => .0034, "6" => .0031, "7" => .0036, "8" => .0027, "9" => .0024,
  55. "10" => .0021, "11" => .0026, "12" => .0024, "13" => .0036,
  56. "14" => .0028, "15" => .0025);
  57. */
  58. foreach($data_table as $user_i=>$user) {
  59. foreach($user as $TABLEE_I=>$TABLE_V) {
  60. foreach($data_table as $test_user_i=>$test_user_v) {
  61. if(!isset($test_user_v[$TABLEE_I])) {
  62. //echo "\n W user ".$test_user_i." tabeli ".$TABLEE_I." brakuje!";
  63. $data_table[$test_user_i][$TABLEE_I]=0;
  64. }
  65. }
  66. }
  67. }
  68. foreach($data_table as $user_i=>$user) {
  69. //echo "\n data duuppa:\n".$user_i;
  70. ksort($data_table[$user_i]);
  71. }
  72. $graph=new PHPGraphLib(800,400);
  73. $graph->addData($data_table[$_GET['C2']]);
  74. // $graph->setBarColor(GRAPH_RandomColorGenerator());
  75. $graph->setBarColor("green");
  76. $graph->setLegendTitle($_GET['C2']);
  77. if ($_GET['C22']) {
  78. $graph->addData($data_table[$_GET['C22']]);
  79. //$graph->setBarColor(GRAPH_RandomColorGenerator());
  80. $graph->setBarColor("red");
  81. $graph->setLegendTitle($_GET['C22']);
  82. }
  83. $graph->setGoalLine(100,"green");
  84. $graph->setGoalLine(200,"red");
  85. //$graph->setGoalLineColor("red","green");
  86. //$graph->setTitle('Company Production');
  87. $graph->setupYAxis(12, 'blue');
  88. $graph->setupXAxis(20);
  89. $graph->setGrid(false);
  90. $graph->setLegend(true);
  91. $graph->setTitleLocation('left');
  92. $graph->setTitleColor('blue');
  93. $graph->setLegendOutlineColor('white');
  94. //$graph->setLegendTitle('Week-37', 'Week-38');
  95. $graph->setXValuesHorizontal(false);
  96. $graph->createGraph();
  97. }
  98. function GRAPH_hour() {
  99. //$ARR['DATE_CHART'][$DWA->C2][$DWA->C1_Y][$DWA->C1_M][$DWA->C1_D]++;
  100. foreach($_SESSION['CHART']['ARR']['DATE_CHART'] as $C2=>$C2V) {
  101. $i=0;
  102. // echo "\n wstawiam dla C2 ".$C2." dane ".$C2V;
  103. // $data_color[$C2]=RandomColorGenerator();
  104. foreach($C2V as $C1_Y=>$C1_YV) {
  105. // echo "\n wstawiam dla C1_Y ".$C1_Y." dane ".$C1_YV;
  106. foreach($C1_YV as $C1_M=>$C1_MV) {
  107. // echo "\n wstawiam dla C1_M ".$C1_M." dane ".$C1_MV;
  108. foreach($C1_MV as $C1_D=>$C1_DV) {
  109. // echo "\n wstawiam dla ".$C1_MV." dane ".$C1_DV;
  110. $data[$C2][substr($C1_Y,-2)."-".$C1_M."-".$C1_D]=$C1_DV['COUNT'];
  111. // $data_hrs[$C2][substr($C1_Y,-2)."-".$C1_M."-".$C1_D]=$C1_DV;
  112. $i+=$C1_DV['COUNT'];
  113. //if($i>14) break;
  114. //hours
  115. foreach($C1_DV['HOURS'] as $C1_H=>$C1_HV) {
  116. // echo "\n wstawiam dla C1_H ".$C1_H." dane ".$C1_HV;
  117. $data_hours[$C2][$C1_H]+=$C1_HV;
  118. }
  119. }
  120. }
  121. }
  122. // break;
  123. }
  124. /*
  125. $data = array("1" => .0032, "2" => .0028, "3" => .0021, "4" => .0033,
  126. "5" => .0034, "6" => .0031, "7" => .0036, "8" => .0027, "9" => .0024,
  127. "10" => .0021, "11" => .0026, "12" => .0024, "13" => .0036,
  128. "14" => .0028, "15" => .0025);
  129. */
  130. //tabela z godzinami pracy
  131. foreach($data_hours as $user_i=>$user) {
  132. foreach($user as $TABLEE_I=>$TABLE_V) {
  133. foreach($data_hours as $test_user_i=>$test_user_v) {
  134. if(!isset($test_user_v[$TABLEE_I])) {
  135. //echo "\n W user ".$test_user_i." tabeli ".$TABLEE_I." brakuje!";
  136. $data_hours[$test_user_i][$TABLEE_I]=0;
  137. }
  138. }
  139. }
  140. }
  141. foreach($data_hours as $user_i=>$user) {
  142. ksort($data_hours[$user_i]);
  143. }
  144. $graph=new PHPGraphLib(800,400);
  145. /*foreach($data as $data_add_i=>$data_add_v) {
  146. //$graph->addData($data['gubarewp']);
  147. if($data_size[$data_add_i]>50) {
  148. $graph->addData($data[$data_add_i]);
  149. $graph->setBarColor(RandomColorGenerator());
  150. // setLineColor("red");
  151. $graph->setLegendTitle(substr($data_add_i,0,5));
  152. }
  153. }
  154. */
  155. //$_GET['C2']=stripslashes($GET['C2']);
  156. $graph->addData($data_hours[$_GET['C2']]);
  157. //$graph->setBarColor(RandomColorGenerator());
  158. $graph->setBarColor('green');
  159. $graph->setLegendTitle($_GET['C2']);
  160. if($_GET['C22']) {
  161. $graph->addData($data_hours[$_GET['C22']]);
  162. // $graph->setBarColor(RandomColorGenerator());
  163. $graph->setBarColor('red');
  164. $graph->setLegendTitle($_GET['C22']);
  165. }
  166. $graph->setGoalLine(100,"green");
  167. $graph->setGoalLine(200,"red");
  168. //$graph->setGoalLineColor("red","green");
  169. //$graph->setTitle('Company Production');
  170. $graph->setupYAxis(12, 'blue');
  171. $graph->setupXAxis(20);
  172. $graph->setGrid(false);
  173. $graph->setLegend(true);
  174. $graph->setTitleLocation('left');
  175. $graph->setTitleColor('blue');
  176. $graph->setLegendOutlineColor('white');
  177. //$graph->setLegendTitle('Week-37', 'Week-38');
  178. $graph->setXValuesHorizontal(false);
  179. $graph->createGraph();
  180. }
  181. function GRAPH_default() {
  182. $_GET['C2'] = V::get('C2', '', $_GET);
  183. $_GET['C22'] = V::get('C22', '', $_GET);
  184. //$ARR['DATE_CHART'][$DWA->C2][$DWA->C1_Y][$DWA->C1_M][$DWA->C1_D]++;
  185. foreach($_SESSION['CHART']['ARR']['DATE_CHART'] as $C2=>$C2V) {
  186. $i=0;
  187. foreach($C2V as $C1_Y=>$C1_YV) {
  188. if (!is_array($C1_YV)) {
  189. continue;
  190. }
  191. foreach($C1_YV as $C1_M=>$C1_MV) {
  192. if (!is_array($C1_MV)) {
  193. continue;
  194. }
  195. foreach($C1_MV as $C1_D=>$C1_DV) {
  196. $data[$C2][substr($C1_Y,-2)."-".$C1_M."-".$C1_D]=$C1_DV['COUNT'];
  197. $i+=$C1_DV['COUNT'];
  198. }
  199. }
  200. }
  201. $_SESSION['CHART']['ARR']['DATE_CHART'][$C2]['SIZE']=$i;
  202. $data_size[$C2]=$i;
  203. }
  204. /*
  205. $data = array("1" => .0032, "2" => .0028, "3" => .0021, "4" => .0033,
  206. "5" => .0034, "6" => .0031, "7" => .0036, "8" => .0027, "9" => .0024,
  207. "10" => .0021, "11" => .0026, "12" => .0024, "13" => .0036,
  208. "14" => .0028, "15" => .0025);
  209. */
  210. //Sortujemy i uzupelniamy daty prac o brakujace indeksy
  211. foreach ($_SESSION['CHART']['ARR']['DATE_CHART'] as $user_i=>$user) { //lecimy ARR[User]
  212. if (!is_array($user)) {
  213. continue;
  214. }
  215. foreach ($user as $TABLEE_I=>$TABLE_V) { //Lecimy ARR[User][Rok]
  216. if (!is_array($TABLE_V)) {
  217. continue;
  218. }
  219. foreach ($TABLE_V as $TABLEE_II=>$TABLE_VV) { //Lecimy ARR[User][Rok][m-c]
  220. if (!is_array($TABLE_VV)) {
  221. continue;
  222. }
  223. foreach ($TABLE_VV as $TABLEE_III=>$TABLE_VVV) { //Lecimy ARR[User][Rok][m-c][day]
  224. if (!is_array($TABLE_VVV)) {
  225. continue;
  226. }
  227. foreach ($_SESSION['CHART']['ARR']['DATE_CHART'] as $test_user_i=>$test_user_v) { //arr[user]
  228. if (!isset($test_user_v[$TABLEE_I][$TABLEE_II][$TABLEE_III])) {
  229. echo "\n W user ".$test_user_i." tabeli ".$TABLEE_I."-".$TABLEE_II."-".$TABLEE_III." brakuje!";
  230. $_SESSION['CHART']['ARR']['DATE_CHART'][$test_user_i][$TABLEE_I][$TABLEE_II][$TABLEE_III]['COUNT']=0;
  231. }
  232. }
  233. }
  234. }
  235. }
  236. }
  237. foreach($_SESSION['CHART']['ARR']['DATE_CHART'] as $user_i=>$user) { //lecimy ARR[User]
  238. ksort($_SESSION['CHART']['ARR']['DATE_CHART'][$user_i]);
  239. foreach($user as $TABLEE_I=>$TABLE_V) { //Lecimy ARR[User][Rok]
  240. if (!is_array($TABLE_V)) {
  241. continue;
  242. }
  243. ksort($_SESSION['CHART']['ARR']['DATE_CHART'][$user_i][$TABLEE_I]);
  244. foreach($TABLE_V as $TABLEE_II=>$TABLE_VV) { //Lecimy ARR[User][Rok][m-c]
  245. if (!is_array($TABLE_VV)) {
  246. continue;
  247. }
  248. ksort($_SESSION['CHART']['ARR']['DATE_CHART'][$user_i][$TABLEE_I][$TABLEE_II]);
  249. foreach($TABLE_VV as $TABLEE_III=>$TABLE_VVV) { //Lecimy ARR[User][Rok][m-c][day]
  250. ksort($_SESSION['CHART']['ARR']['DATE_CHART'][$user_i][$TABLEE_I][$TABLEE_II][$TABLEE_III]);
  251. }
  252. }
  253. }
  254. }
  255. $graph = new PHPGraphLib(800,400);
  256. /*foreach($data as $data_add_i=>$data_add_v) {
  257. //$graph->addData($data['gubarewp']);
  258. if($data_size[$data_add_i]>50) {
  259. $graph->addData($data[$data_add_i]);
  260. $graph->setBarColor(RandomColorGenerator());
  261. // setLineColor("red");
  262. $graph->setLegendTitle(substr($data_add_i,0,5));
  263. }
  264. }
  265. */
  266. //$_GET['C2']=stripslashes($GET['C2']);
  267. $graph->addData($data[$_GET['C2']]);
  268. $graph->setBarColor('green');
  269. // $graph->setBarColor(RandomColorGenerator());
  270. // setLineColor("red");
  271. $graph->setLegendTitle($_GET['C2']);
  272. if ($_GET['C22']) {
  273. $graph->addData($data[$_GET['C22']]);
  274. // $graph->setBarColor(RandomColorGenerator());
  275. $graph->setBarColor('red');
  276. // setLineColor("red");
  277. $graph->setLegendTitle($_GET['C22']);
  278. }
  279. $graph->setGoalLine(100,"green");
  280. $graph->setGoalLine(200,"red");
  281. //$graph->setGoalLineColor("red","green");
  282. //$graph->setTitle('Company Production');
  283. $graph->setupYAxis(12, 'blue');
  284. $graph->setupXAxis(20);
  285. $graph->setGrid(false);
  286. $graph->setLegend(true);
  287. $graph->setTitleLocation('left');
  288. $graph->setTitleColor('blue');
  289. $graph->setLegendOutlineColor('white');
  290. //$graph->setLegendTitle('Week-37', 'Week-38');
  291. $graph->setXValuesHorizontal(false);
  292. $graph->createGraph();
  293. }
  294. ?>