<?php
  ///////////////////////////////////////////////////
  //2007 (C)
  //Карпухин Павел
  ///////////////////////////////////////////////////

  $lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0,2);
  if(is_file ("../lang/".$lang.".php")) include "../lang/".$lang.".php";
     else include "../lang/ru.php";

  $title=$titlepage=$TEXT['support36'];

  require_once "../config.php";
  require_once "top.php";

  ?>
  <title><?php echo $title; ?></title>
  <link rel="StyleSheet" type="text/css" href="../utils/reader.css" />
  <script type="text/javascript" src="../js/swfobject.js"></script>
 
  </head>
  <body leftmargin="0" marginheight="0" marginwidth="0" rightmargin="0" bottommargin="0" topmargin="0" >
  <?php

  if($result2['user'] == 1) puterror2($TEXT['error-supp11']);
  if($result2['master'] == 1) puterror2($TEXT['error-supp11']);

  if(empty($_GET['yea'])) $_GET['yea'] = "";
  if(empty($_GET['mon'])) $_GET['mon'] = "";
  if(empty($_GET['dy'])) $_GET['dy'] = "";

  if(strlen($_GET['yea'])>4) puterror2($TEXT['error-supp28']);
  if(strlen($_GET['mon'])>2) puterror2($TEXT['error-supp29']);
  if(strlen($_GET['dy'])>2) puterror2($TEXT['error-supp30']);
  $_GET['yea'] = rep($_GET['yea']);
  $_GET['mon'] = rep($_GET['mon']);
  $_GET['dy'] = rep($_GET['dy']);

  if($_GET['mon'] == 1) $month2 = $TEXT['month01r'];
  if($_GET['mon'] == 2) $month2 = $TEXT['month02r'];
  if($_GET['mon'] == 3) $month2 = $TEXT['month03r'];
  if($_GET['mon'] == 4) $month2 = $TEXT['month04r'];
  if($_GET['mon'] == 5) $month2 = $TEXT['month05r'];
  if($_GET['mon'] == 6) $month2 = $TEXT['month06r'];
  if($_GET['mon'] == 7) $month2 = $TEXT['month07r'];
  if($_GET['mon'] == 8) $month2 = $TEXT['month08r'];
  if($_GET['mon'] == 9) $month2 = $TEXT['month09r'];
  if($_GET['mon'] == 10) $month2 = $TEXT['month10r'];
  if($_GET['mon'] == 11) $month2 = $TEXT['month11r'];
  if($_GET['mon'] == 12) $month2 = $TEXT['month12r'];

  if(empty($_GET['yea']) && empty($_GET['mon']) && empty($_GET['dy']))
  {
  $query_tmp_ofc_sel = mysql_query("SELECT `tmp_ofc_id` FROM `tbl_tmp_ofc` WHERE `user`='".$result2['login']."' ");
   if(!$query_tmp_ofc_sel) puterror2(mysql_error());
    if(mysql_num_rows($query_tmp_ofc_sel) > 0)
     {
      $sost_ofc = mysql_fetch_array($query_tmp_ofc_sel,MYSQL_ASSOC);
      $query_tmp_ofc = mysql_query("UPDATE `tbl_tmp_ofc` SET `yea`=0, `mon`=0, `dy`=0 WHERE `tmp_ofc_id`=".$sost_ofc['tmp_ofc_id']." ");
      if(!$query_tmp_ofc) puterror2(mysql_error());
     }
    else
     {
      $query_tmp_ofc = mysql_query("INSERT INTO tbl_tmp_ofc ( `tmp_ofc_id` , `user` , `yea` , `mon` , `dy` ) VALUES ( NULL , '".$result2['login']."', 0, 0, 0)");
      if(!$query_tmp_ofc) puterror2(mysql_error());
     }
?>
 <script type="text/javascript">

swfobject.embedSWF(
  "../open-flash-chart.swf", "by_year",
  "250", "250", "9.0.0", "expressInstall.swf",
  {"data-file":"by-year.php"}, {"wmode" : "transparent"} );

swfobject.embedSWF(
  "../open-flash-chart.swf", "by-time-isp",
  "250", "250", "9.0.0", "expressInstall.swf",
  {"data-file":"by-time-isp.php"}, {"wmode" : "transparent"} );

swfobject.embedSWF(
  "../open-flash-chart.swf", "by-this-year",
  "600", "250", "9.0.0", "expressInstall.swf",
  {"data-file":"by-this-year.php"}, {"wmode" : "transparent"} );

</script>
<table border="0" cellpadding="0" cellspacing="0" width="100%" bordercolordark="white" bordercolorlight="white">
<tr align="center"><td class="supp_iniz2"><?php echo $TEXT['support90']; ?></td></tr>
<tr>
   <td align="center">
     <div id='by_year'></div>
     <div id='by-time-isp'></div>
     <div id='by-this-year'></div><hr width='97%' align='center'/>
  </td>
</tr>
<tr>
   <td align="center">
      <table class="table" border="1" width="40%" cellpadding="1" cellspacing="1" bordercolordark="white" bordercolorlight="black">
       <tr class="tableheadercat">
        <td><?php echo $TEXT['support86']; ?></td>
        <td><?php echo $TEXT['support66']; ?></td>
       </tr>
       <?php
       $query_total = "SELECT DISTINCT `yea` FROM `tbl_supp_archive` ORDER BY yea ";
        $tot_tmp = mysql_query($query_total);
         if(!$tot_tmp) puterror2($TEXT['error-tbl25']);
           while($sost2 = mysql_fetch_array($tot_tmp,MYSQL_ASSOC))
           {
             $query_total2 = "SELECT COUNT(arch_id) AS work FROM `tbl_supp_archive` WHERE `yea` = '".$sost2['yea']."' ";
              $tot_tmp2 = mysql_query($query_total2);
               if(!$tot_tmp2) puterror2($TEXT['error-tbl25']);
                $work = mysql_fetch_array($tot_tmp2,MYSQL_ASSOC);
                $work_res = $work['work'];

            echo "<tr class='texttable'>
              <td><a href='rpt_date.php?yea=".$sost2['yea']."' title='".$TEXT['support14']."'>".$sost2['yea']."</a></td>
              <td>".$work_res."</td>
            </tr>";

            }
            ?>
        </table>
      </td>
   </tr>
</table>
<?php
}
if(!empty($_GET['yea']) && empty($_GET['mon']) && empty($_GET['dy']))
{
$query_tmp_ofc_sel = mysql_query("SELECT `tmp_ofc_id` FROM `tbl_tmp_ofc` WHERE `user`='".$result2['login']."' ");
   if(!$query_tmp_ofc_sel) puterror2(mysql_error());
    if(mysql_num_rows($query_tmp_ofc_sel) > 0)
     {
      $sost_ofc = mysql_fetch_array($query_tmp_ofc_sel,MYSQL_ASSOC);
      $query_tmp_ofc = mysql_query("UPDATE `tbl_tmp_ofc` SET `yea`=".$_GET['yea'].", `mon`=0, `dy`=0 WHERE `tmp_ofc_id`=".$sost_ofc['tmp_ofc_id']." ");
      if(!$query_tmp_ofc) puterror2(mysql_error());
     }
    else
     {
      $query_tmp_ofc = mysql_query("INSERT INTO tbl_tmp_ofc ( `tmp_ofc_id` , `user` , `yea` , `mon` , `dy` ) VALUES ( NULL , '".$result2['login']."', ".$_GET['yea'].", 0, 0)");
      if(!$query_tmp_ofc) puterror2(mysql_error());
     }
?>
 <script type="text/javascript">

swfobject.embedSWF(
  "../open-flash-chart.swf", "by-time-isp",
  "250", "250", "9.0.0", "expressInstall.swf",
  {"data-file":"by-time-isp.php"} );

swfobject.embedSWF(
  "../open-flash-chart.swf", "by-this-year",
  "850", "250", "9.0.0", "expressInstall.swf",
  {"data-file":"by-this-year.php"} );

</script>
<table border="0" cellpadding="0" cellspacing="0" width="100%" bordercolordark="white" bordercolorlight="white">
<tr align="center"><td class="supp_iniz2"><?php echo $TEXT['support91']; ?>&nbsp;<span class="grn"><?php echo $_GET['yea']; ?></span>&nbsp;<?php echo $TEXT['support95']; ?></td></tr>
<tr>
   <td align="center">
    <div id='by-time-isp'></div>
    <div id='by-this-year'></div><hr width='97%' align='center'/>
  </td>
</tr>
<tr>
    <td align="center">
      <table class="table" border="1" width="40%" cellpadding="1" cellspacing="1" bordercolordark="white" bordercolorlight="black">
       <tr class="tableheadercat">
        <td><?php echo $TEXT['support87']; ?></td>
        <td><?php echo $TEXT['support66']; ?></td>
       </tr>
       <?php
       $query_total3 = "SELECT DISTINCT `mon` FROM `tbl_supp_archive` WHERE `yea` = '".$_GET['yea']."' ORDER BY mon ";
        $tot_tmp3 = mysql_query($query_total3);
         if(!$tot_tmp3) puterror2($TEXT['error-tbl25']);
           while($sost3 = mysql_fetch_array($tot_tmp3,MYSQL_ASSOC))
           {
             if($sost3['mon'] == 1) $month = $TEXT['month01r'];
             if($sost3['mon'] == 2) $month = $TEXT['month02r'];
             if($sost3['mon'] == 3) $month = $TEXT['month03r'];
             if($sost3['mon'] == 4) $month = $TEXT['month04r'];
             if($sost3['mon'] == 5) $month = $TEXT['month05r'];
             if($sost3['mon'] == 6) $month = $TEXT['month06r'];
             if($sost3['mon'] == 7) $month = $TEXT['month07r'];
             if($sost3['mon'] == 8) $month = $TEXT['month08r'];
             if($sost3['mon'] == 9) $month = $TEXT['month09r'];
             if($sost3['mon'] == 10) $month = $TEXT['month10r'];
             if($sost3['mon'] == 11) $month = $TEXT['month11r'];
             if($sost3['mon'] == 12) $month = $TEXT['month12r'];

             $query_total4 = "SELECT COUNT(arch_id) AS work FROM `tbl_supp_archive` WHERE `yea` = '".$_GET['yea']."' AND `mon` = '".$sost3['mon']."' ";
              $tot_tmp4 = mysql_query($query_total4);
               if(!$tot_tmp4) puterror2($TEXT['error-tbl25']);
                $work2 = mysql_fetch_array($tot_tmp4,MYSQL_ASSOC);
                $work_res2 = $work2['work'];

            echo "<tr class='texttable'>
              <td><a href='rpt_date.php?yea=".$_GET['yea']."&mon=".$sost3['mon']."' title='".$TEXT['support14']."'>".$month."</a></td>
              <td>".$work_res2."</td>
            </tr>";

            }
            ?>
        </table>
      </td>
   </tr>
</table>
<?php
}
if(!empty($_GET['yea']) && !empty($_GET['mon']) && empty($_GET['dy']))
{
if($_GET['mon'] == 1) $month4 = $TEXT['month01r'];
if($_GET['mon'] == 2) $month4 = $TEXT['month02r'];
if($_GET['mon'] == 3) $month4 = $TEXT['month03r'];
if($_GET['mon'] == 4) $month4 = $TEXT['month04r'];
if($_GET['mon'] == 5) $month4 = $TEXT['month05r'];
if($_GET['mon'] == 6) $month4 = $TEXT['month06r'];
if($_GET['mon'] == 7) $month4 = $TEXT['month07r'];
if($_GET['mon'] == 8) $month4 = $TEXT['month08r'];
if($_GET['mon'] == 9) $month4 = $TEXT['month09r'];
if($_GET['mon'] == 10) $month4 = $TEXT['month10r'];
if($_GET['mon'] == 11) $month4 = $TEXT['month11r'];
if($_GET['mon'] == 12) $month4 = $TEXT['month12r'];

$query_tmp_ofc_sel = mysql_query("SELECT `tmp_ofc_id` FROM `tbl_tmp_ofc` WHERE `user`='".$result2['login']."' ");
   if(!$query_tmp_ofc_sel) puterror2(mysql_error());
    if(mysql_num_rows($query_tmp_ofc_sel) > 0)
     {
      $sost_ofc = mysql_fetch_array($query_tmp_ofc_sel,MYSQL_ASSOC);
      $query_tmp_ofc = mysql_query("UPDATE `tbl_tmp_ofc` SET `yea`=".$_GET['yea'].", `mon`=".$_GET['mon'].", `dy`=0 WHERE `tmp_ofc_id`=".$sost_ofc['tmp_ofc_id']." ");
      if(!$query_tmp_ofc) puterror2(mysql_error());
     }
    else
     {
      $query_tmp_ofc = mysql_query("INSERT INTO tbl_tmp_ofc ( `tmp_ofc_id` , `user` , `yea` , `mon` , `dy` ) VALUES ( NULL , '".$result2['login']."', ".$_GET['yea'].", ".$_GET['mon'].", 0)");
      if(!$query_tmp_ofc) puterror2(mysql_error());
     }
?>
 <script type="text/javascript">

swfobject.embedSWF(
  "../open-flash-chart.swf", "by-time-isp",
  "250", "250", "9.0.0", "expressInstall.swf",
  {"data-file":"by-time-isp.php"} );

swfobject.embedSWF(
  "../open-flash-chart.swf", "by-this-month",
  "850", "250", "9.0.0", "expressInstall.swf",
  {"data-file":"by-this-month.php"} );

</script>
<table border="0" cellpadding="0" cellspacing="0" width="100%" bordercolordark="white" bordercolorlight="white">
<tr align="center"><td class="supp_iniz2"><?php echo $TEXT['support92']; ?>&nbsp;<span class="grn"><?php echo $month4; ?></span>&nbsp;<?php echo $TEXT['support94']; ?>&nbsp;<span class="grn"><?php echo $_GET['yea']; ?></span>&nbsp;<?php echo $TEXT['year']; ?></td></tr>
<tr>
   <td align="center">
    <div id='by-time-isp'></div>
    <div id='by-this-month'></div><hr width='97%' align='center'/>
  </td>
</tr>
<tr>
    <td align="center">
      <table class="table" border="1" width="40%" cellpadding="1" cellspacing="1" bordercolordark="white" bordercolorlight="black">
       <tr class="tableheadercat">
        <td><?php echo $TEXT['support88']; ?></td>
        <td><?php echo $TEXT['support66']; ?></td>
       </tr>
       <?php
       $query_total5 = "SELECT DISTINCT `dy` FROM `tbl_supp_archive` WHERE `yea` = '".$_GET['yea']."' AND `mon` = '".$_GET['mon']."' ORDER BY dy ";
        $tot_tmp5 = mysql_query($query_total5);
         if(!$tot_tmp5) puterror2($TEXT['error-tbl25']);
           while($sost5 = mysql_fetch_array($tot_tmp5,MYSQL_ASSOC))
           {
             $query_total6 = "SELECT COUNT(arch_id) AS work FROM `tbl_supp_archive` WHERE `yea` = '".$_GET['yea']."' AND `mon` = '".$_GET['mon']."' AND `dy` = '".$sost5['dy']."' ";
              $tot_tmp6 = mysql_query($query_total6);
               if(!$tot_tmp6) puterror2($TEXT['error-tbl25']);
                $work3 = mysql_fetch_array($tot_tmp6,MYSQL_ASSOC);
                $work_res3 = $work3['work'];

            echo "<tr class='texttable'>
              <td><a href='rpt_date.php?yea=".$_GET['yea']."&mon=".$_GET['mon']."&dy=".$sost5['dy']."' title='".$TEXT['support14']."'>".$sost5['dy']."</a></td>
              <td>".$work_res3."</td>
            </tr>";

            }
            ?>
        </table>
      </td>
   </tr>
</table>
<?php
}
if(!empty($_GET['yea']) && !empty($_GET['mon']) && !empty($_GET['dy']))
{
if($_GET['mon'] == 1) $month3 = $TEXT['month01'];
if($_GET['mon'] == 2) $month3 = $TEXT['month02'];
if($_GET['mon'] == 3) $month3 = $TEXT['month03'];
if($_GET['mon'] == 4) $month3 = $TEXT['month04'];
if($_GET['mon'] == 5) $month3 = $TEXT['month05'];
if($_GET['mon'] == 6) $month3 = $TEXT['month06'];
if($_GET['mon'] == 7) $month3 = $TEXT['month07'];
if($_GET['mon'] == 8) $month3 = $TEXT['month08'];
if($_GET['mon'] == 9) $month3 = $TEXT['month09'];
if($_GET['mon'] == 10) $month3 = $TEXT['month10'];
if($_GET['mon'] == 11) $month3 = $TEXT['month11'];
if($_GET['mon'] == 12) $month3 = $TEXT['month12'];

$query_tmp_ofc_sel = mysql_query("SELECT `tmp_ofc_id` FROM `tbl_tmp_ofc` WHERE `user`='".$result2['login']."' ");
   if(!$query_tmp_ofc_sel) puterror2(mysql_error());
    if(mysql_num_rows($query_tmp_ofc_sel) > 0)
     {
      $sost_ofc = mysql_fetch_array($query_tmp_ofc_sel,MYSQL_ASSOC);
      $query_tmp_ofc = mysql_query("UPDATE `tbl_tmp_ofc` SET `yea`=".$_GET['yea'].", `mon`=".$_GET['mon'].", `dy`=".$_GET['dy']." WHERE `tmp_ofc_id`=".$sost_ofc['tmp_ofc_id']." ");
      if(!$query_tmp_ofc) puterror2(mysql_error());
     }
    else
     {
      $query_tmp_ofc = mysql_query("INSERT INTO tbl_tmp_ofc ( `tmp_ofc_id` , `user` , `yea` , `mon` , `dy` ) VALUES ( NULL , '".$result2['login']."', ".$_GET['yea'].", ".$_GET['mon'].", ".$_GET['dy'].")");
      if(!$query_tmp_ofc) puterror2(mysql_error());
     }

$d_header = $_GET['dy']." ".$month3." ".$_GET['yea']." ".$TEXT['year'];
?>
 <script type="text/javascript">

swfobject.embedSWF(
  "../open-flash-chart.swf", "by_this_month_user_rpt",
  "1100", "300", "9.0.0", "expressInstall.swf",
  {"data-file":"by-this-month-user-rpt.php"} );

swfobject.embedSWF(
  "../open-flash-chart.swf", "by_probl_rpt",
  "1100", "300", "9.0.0", "expressInstall.swf",
  {"data-file":"by-probl-rpt.php"} );

</script>
<table border="0" cellpadding="0" cellspacing="0" width="100%" bordercolordark="white" bordercolorlight="white">
<tr align="center"><td class="supp_iniz2"><?php echo $TEXT['support93']; ?>&nbsp;<span class="grn"><?php echo $d_header; ?></span></td></tr>
<tr>
   <td align="center">
     <div id='by_this_month_user_rpt'></div>
     <div id='by_probl_rpt'></div><hr width='97%' align='center'/>
  </td>
</tr>
<tr>
    <td align="center">
      <table class="table" border="1" width="100%" cellpadding="1" cellspacing="1" bordercolordark="white" bordercolorlight="black">
       <tr class="tableheadercat">
        <td><img alt='picture' src='../img/show.png' /></td>
        <td><?php echo $TEXT['support1']; ?></td>
        <td><?php echo $TEXT['support42']; ?></td>
        <td><?php echo $TEXT['support43']; ?></td>
        <td><?php echo $TEXT['support30']; ?></td>
        <td><?php echo $TEXT['support13']; ?></td>
        <td><?php echo $TEXT['support47']; ?></td>
        <td><?php echo $TEXT['support89']; ?></td>
       </tr>
       <?php
         $d = $_GET['yea']."-".$_GET['mon']."-".$_GET['dy'];

       $query_total5 = "SELECT `zay_id`, `manager`, `master`, `user`, `tema`, `time_isp`, `organizaciya`, `arch_id`, `problema` FROM `tbl_supp_archive` WHERE `data` = '".$d."' ORDER BY organizaciya ";
        $tot_tmp5 = mysql_query($query_total5);
         if(!$tot_tmp5) puterror2($TEXT['error-tbl25']);
           while($sost5 = mysql_fetch_array($tot_tmp5,MYSQL_ASSOC))
           {
            if($sost5['problema'] !== "") $file_image = "<a href='zayavka_rep.php?arch_id=".$sost5['arch_id']."' target=_blank title='".$TEXT['support14']."'><img alt='picture' src='../img/show.png' /></a>";
            else $file_image = "---";

            echo "<tr class='texttable'>
              <td class='support_ob4'>".$file_image."</td>
              <td class='support_ob4'>".$sost5['zay_id']."</td>
              <td>".$sost5['manager']."</td>
              <td>".$sost5['master']."</td>
              <td>".$sost5['user']."</td>
              <td>".$sost5['tema']."</td>
              <td>".$sost5['time_isp']." ".$TEXT['support48']."</td>
              <td>".$sost5['organizaciya']."</td>
            </tr>";
            }
            ?>
        </table>
      </td>
   </tr>
</table>
<?php
}
?>
</body>
</html>