
<tr>
	
<?
		
	$query5 = "select   wr_3 from ".$table."    ";
		$result5 = sql_query($query5);
		while($row  = sql_fetch_array($result5)) {
		
			$year[$i] = substr($row[wr_3], 6, 4);
	
			$i++;
		}
		/// 년도 뽑아오기
			if($year[0] != "") { $year = array_unique($year); 
	foreach($year as $v) {
		if( date("Y") == $v) 		echo "<td align=center> <b><a href=".$g4[path]."/bbs/board.php?bo_table=static&wr_id=".$view[wr_id]."&want_year=$v>".$v."</b> </td>";
		else echo "<td align=center> ".$v." </td>";
	
		}}
?>


</tr>
</table>



    </td>
</tr>
<tr>
    <td height=30 style="color:#888;">
<?

//월별 고장 내역
if($want_year == "") $want_year = date("Y");
$temp ="";
$i=0;
$k=0;
		$query8 = "select  wr_subject, wr_3, count(*)  from $table where right(wr_3,4) = '$want_year'  group by  wr_subject, right(wr_3,7)  ";
		$result8 = sql_query($query8);
		while($row  = sql_fetch_array($result8)) {
			$abreak_total[$i] = $row['count(*)'];
			$apart[$i] = $row[wr_subject];			
			$adate[$i] = substr($row[wr_3], 3,2);	
			//echo $date[$i];
			//echo $atemp."//".$apart[$i]."<br>";
			if(trim($temp) != trim($apart[$i]))
			{
				
				$aall .= "##".$apart[$i]."#/".$adate[$i]."//".$abreak_total[$i]."#/";
				//if($k == 1) $all[$i] .= "&&"; 
				//$k =0;
			}
			else				{ 	$aall .=  $adate[$i]."//".$abreak_total[$i]."#/"; $k = 1;}



				$temp = $apart[$i];
				
				$i++;

			
		}
		//echo $aall;


?>
<?
	
	$abypart = explode("##", $aall); 
		
	
	array_splice($abypart, 0, 1);
	
	for($i=0; $i < count($abypart); $i++) { //항목별로 분류
		$abypart[$i] = substr($abypart[$i], 0, -2);
	

		$abypart_sep[$i] = explode("#/", $abypart[$i]); 
		
	

		for($j=1; $j < count($abypart_sep[$i]); $j++) {  // 항목별로 분류
		
			$afield = explode("//", $abypart_sep[$i][$j]);
		

			$afileld[$i][0] .= $afield[0].",";
			$afileld[$i][1] .= $afield[1].",";;
//echo $afileld[$i][1]."<br>";
//$afileld[$i][1] = substr($afileld[$i][1], 0,-1);
			
		}

		//echo $fileld[$i][0]."<br>";
		//echo $fileld[$i][1]."<br>";
			//${"fileld".$j} .= "(".$field[0].",".$field[1]."),"; 
		$afield_sep1[$i] = explode(",",$afileld[$i][0]);
		$afield_sep2[$i] = explode(",",$afileld[$i][1]);
		//$bypart = "";
//var_dump($afield_sep2[$i])."<br>";

		
					//echo count($fileld[$l])."<br>";
//$aa = "0";
					$m =0;
					for($j=0; $j < 12; $j++) {   // 없는 날짜 0로 채우기
						$m++;

						if($j < 9) $aday = "0".$m;
						else $aday = $m;
						 $aa = "0";
						 //echo 
						for($k=0; $k < count($afield_sep1[$i]); $k++) {  // 항목별로 분류

							if(trim($aday) == trim($afield_sep1[$i][$k])) $aa = $afield_sep2[$i][$k];
							//$a[$i] .= "[".$m.", ".$afield_sep2[$i][$k]."],";
						//echo $aday."//".$afield_sep1[$i][$k]."//".$aa."<br>"; }
							//else $aa = "0";
						}

						$ab[$i] .= "[".$m.", ".$aa."],";
					}
						$ab[$i] = substr($ab[$i], 0, -1);
						$ab[$i] = "{ label: \"".$abypart_sep[$i][0]."\", data: [".$ab[$i]."]},";
						$d .= $ab[$i]; 
						
	}
	$d = substr($d, 0, -1);
						
						//echo $d."<br>";
		
?>
<?
//현재 재고
$i=0;


	$query4 = "select  wr_10, wr_link1, wr_subject  from g4_write_dsetup     ";
		$result4 = sql_query($query4);
		while($row  = sql_fetch_array($result4)) {

			$device[$i] = $row[wr_subject];
			$solved[$i] = $row[wr_link1];
			$break[$i] = $row[wr_10];
			$unsolved[$i] = $break[$i] - $solved[$i]; 
		
			$i++;
		}
?>

<?
		if($want_year =="" && $want_month == "")  $here =  date("m-Y");  
		else  {

			if($want_year =="") $want_year = date("Y");
			if($want_month == "") { $want_month=date("m"); $here =$want_month."-".$want_year; }
			else $here =$want_month."-".$want_year; 
			}

		$end_day = date("t", mktime(0, 0, 0, substr($here, 0,2), 1, substr($here, 3,4)));
		//echo $end_day;
?>
<?

//월별 고장 내역

$temp ="";
$i=0;
$k=0;
		$query6 = "select  wr_subject, wr_3, count(*)  from $table where right(wr_3,7) = '$here'  group by  wr_subject, right(wr_3,10)  ";
		$result6 = sql_query($query6);
		while($row  = sql_fetch_array($result6)) {
			$break_total[$i] = $row['count(*)'];
			$part[$i] = $row[wr_subject];			
			$date[$i] = substr($row[wr_3], 0,2);	
			//echo $date[$i];
			if(trim($temp) != trim($part[$i]))
			{
				
				$all .= "##".$part[$i]."#/".$date[$i]."//".$break_total[$i]."#/";
				//if($k == 1) $all[$i] .= "&&"; 
				//$k =0;
			}
			else				{ 	$all .=  $date[$i]."//".$break_total[$i]."#/"; $k = 1;}



				$temp = $part[$i];
				
				$i++;

			
		}
		//echo $all;


?>
<?
	
	$bypart = explode("##", $all); 
		
	
	array_splice($bypart, 0, 1);
	
	for($i=0; $i < count($bypart); $i++) { //항목별로 분류
		$bypart[$i] = substr($bypart[$i], 0, -2);
	

		$bypart_sep[$i] = explode("#/", $bypart[$i]); 
		
	
		$m=0;
		for($j=1; $j < count($bypart_sep[$i]); $j++) {  // 항목별로 분류
		
			$field = explode("//", $bypart_sep[$i][$j]);
		

			$fileld[$i][0] .= $field[0].",";
			$fileld[$i][1] .= $field[1].",";;
			$m++;
		}

		//echo $fileld[$i][0]."<br>";
		//echo $fileld[$i][1]."<br>";
			//${"fileld".$j} .= "(".$field[0].",".$field[1]."),"; 
		$field_sep1[$i] = explode(",",$fileld[$i][0]);
		$field_sep2[$i] = explode(",",$fileld[$i][1]);
		//$bypart = "";
	//var_dump($field_sep[$i])."<br>";

		
					//echo count($fileld[$l])."<br>";

					$m =0;
					for($j=0; $j < $end_day; $j++) {   // 없는 날짜 0로 채우기
						$m++;

						if($j < 9) $day = "0".$m;
						else $day = $m;
						 $a = "0";
						for($k=0; $k < count($field_sep1[$i]); $k++) {  // 항목별로 분류
						
							if(trim($day) == trim($field_sep1[$i][$k])) $a = $field_sep2[$i][$k];
							//$a[$i] .= "[".$m.", ".$field_sep2[$i][$k]."],";
							//else $a = "0";
						}

						$b[$i] .= "[".$m.", ".$a."],";
					}
						$b[$i] = substr($b[$i], 0, -1);
						$b[$i] = "{ label: \"".$bypart_sep[$i][0]."\", data: [".$b[$i]."]},";
						$c .= $b[$i]; 
						
	}
	$c = substr($c, 0, -1);
						
					//	echo $c."<br>";
		
?>



<table class="t_ex2">
<tr ><td  colspan=<? $cc =  count($device)+1; echo $cc;?>  align=center bgcolor=white>&nbsp;<font size="4" color=""><b>수리중 장비 (<?=date("d-m-Y")?>)</b></font>&nbsp;</td>
	<tr><th  class='c1'  >&nbsp;장비&nbsp;</th>
		<?

	for($i=0; $i < count($device); $i++) {

		echo "<th class='c1' width=7% align=center> ".$device[$i]." </th>";
	}
?>

</tr>
<tr ><td   class='c1'>&nbsp;수리중&nbsp;</td>
<?
	for($i=0; $i <count($device); $i++) {
	
		
if($unsolved[$i] == "") $unsolved[$i] =0;
		echo "<td  class='c4' width=7% align=right> <font  color='red'>".number_format($unsolved[$i])."</font>&nbsp;</td>";
			}
?>
</tr>
</table>



    </td>
</tr>


<tr ><td height=40 align=center valign=bottom>

	<font size="5" color="red"><?=$here?> </font>
 </td>
</tr>
<tr ><td height=30 align=center valign=bottom>

<? for($i=1; $i < 13; $i++) {
		if(strlen($i) < 2) $q = "0".$i;
		else $q = $i;
		$want_month = $q;
		echo "<a href='".$g4[path]."/bbs/board.php?bo_table=static&wr_id=".$view[wr_id]."&want_year=".$want_year."&want_month=".$want_month."'>".$i."</a>&nbsp;&nbsp;&nbsp;";
	}
?> 

 </td>
</tr>


<tr><td>
		

<script type="text/javascript">

	$(function() {

		
	var data = [

		<?=$c?>

		// A null signifies separate line segments

	];

var data1 = [

		<?=$d?>

		// A null signifies separate line segments

	];
			var options = {
			series: {
				lines: {
					show: true
				},
				points: {
					show: true
				}
			},
			legend: {
				noColumns: 2
			},
			xaxis: {
				tickDecimals: 0
			},
			yaxis: {
				min: 0
			},
			selection: {
				mode: "x"
			}
		};
		
		

		var placeholder = $("#placeholder");

		$.plot(placeholder, data, options);

	var placeholder = $("#placeholder1");
		$.plot(placeholder, data1, options);



		// Add the Flot version string to the footer

		$("#footer").prepend("Flot " + $.plot.version + " &ndash; ");
	});

		// A custom label formatter used by several of the plots

	function labelFormatter(label, series) {
		return "<div style='font-size:8pt; text-align:center; padding:2px; color:white;'>" + label + "<br/>" + Math.round(series.percent) + "%</div>";
	}
	</script>
		<div class="bar">
			<div id="placeholder" class="bar-holder"></div>
			</div>

<div class="bar1">
			<div id="placeholder1" class="bar-holder"></div>
			</div>
			 </td>
</tr>
			