<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?php
  ///////////////////////////////////////////////////
  //2007 (C)
  //Карпухин Павел
  ///////////////////////////////////////////////////

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

  require_once "config.php";
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW" />
<title><?php echo $TEXT['global-title']; ?></title>
<link rel="StyleSheet" type="text/css" href="util/admin.css" />
<link rel="icon" href="favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
</head>
<body leftmargin="0" marginheight="0" marginwidth="0" rightmargin="0" bottommargin="0" topmargin="0" >
<?php
   if(! @mysql_select_db($dbname,$dbcnx))
    {
    echo("<p>At this moment the database is not accessible, therefore correct display of page is impossible.<br />If you do not install project previously, run script <a href=install.php>http://".$_SERVER['SERVER_ADDR']."/personal/install.php</a></p>");
    exit();
    }

  $query_srv = "SELECT * FROM `tbl_srv_param` LIMIT 1";
  $result_srv = mysql_query($query_srv);
  if(!$result_srv) puterror2($TEXT['error-tbl44']);
   $result_srv_set = mysql_fetch_array($result_srv,MYSQL_ASSOC);
   $ldp = $result_srv_set['ldp']; //1 - использовать, 0 - не использовать
   if($result_srv_set['prx_set'] == "") $int_proxy = "";
    else $int_proxy = "tcp://".$result_srv_set['prx_set'];

  $query = "SELECT * FROM `tbl_logins` WHERE `login`='".$_COOKIE['login']."' ";
  $result = mysql_query($query);
  if(!$result) puterror($TEXT['error-tbl20']);
      $result2 = mysql_fetch_array($result);
      $passw1 = $_COOKIE['passwrd'];
      $passw2 = $result2['pass'];

       if($passw1 !== $passw2) puterror($TEXT['error-loginform3']);
       if(empty($passw1)) puterror($TEXT['error-loginform3']);

      $query_cl = "SELECT * FROM `tbl_clear`";
      $result_cl = mysql_query($query_cl);
      if(!$result_cl) puterror($TEXT['error-tbl37']);
       if(mysql_num_rows($result_cl)>0);
         {
          while($result_cl2 = mysql_fetch_array($result_cl))
           {
           $tbl_name = $result_cl2['col_tbl_name'];
           $tbl_col = $result_cl2['col_name'];
           $tbl_day = $result_cl2['by_data'];
           $tbl_rows = $result_cl2['by_count'];

           $query_log_coun = mysql_query("SELECT COUNT($tbl_col) FROM $tbl_name");
           $coun_log = mysql_result($query_log_coun, 0);
            if($coun_log > 0)
           {
           $query10 = "SELECT ADDDATE((SELECT DATE((SELECT MAX($tbl_col) FROM $tbl_name))),-$tbl_day)";
           $result10_del_cl1 = mysql_query($query10);
            if(!$result10_del_cl1) puterror($TEXT['error-tbl37']);
             $r2 = mysql_fetch_array($result10_del_cl1);
             if($result_cl2['by_data'] > 0)
             {
              $clr_id = "";
             //удалить всё если отклонение в днях больше указанного
             $query_iskh_par = "SELECT * FROM `$tbl_name` WHERE `".$tbl_col."` < '".$r2['0']."'";
              $result_iskh_par = mysql_query($query_iskh_par);
               if(!$result_iskh_par) puterror($TEXT['error-tbl37']);
               while($iskh_par = mysql_fetch_array($result_iskh_par))
               {
               if($tbl_name == "tbl_supp_archive") $clr_id = "arch_id";
                else $clr_id = "log_id";

               //$query_del_cl1 = "DELETE FROM `$tbl_name` WHERE `".$tbl_col."` < '".$r2['0']."'";
               $query_del_cl1 = "DELETE FROM `$tbl_name` WHERE `".$clr_id."` = '".$iskh_par['0']."'";
               $result_del_cl1 = mysql_query($query_del_cl1);
               print $query_del_cl1;
                if(!$result_del_cl1) puterror($TEXT['error-tbl37']);
                if($iskh_par['pic_tr'] !== "" && is_file("../".$iskh_par['pic_tr'])) unlink("../".$iskh_par['pic_tr']);
               }
             }
             if($result_cl2['by_count'] > 0)
             {
             if($coun_log > $tbl_rows)
             {
             //удалить все если отклонение в количестве строк больше указанного
             $del_rows = $coun_log - $tbl_rows;
             $query_iskh_par = "SELECT * FROM `$tbl_name` ORDER BY $tbl_col LIMIT $del_rows";
              $result_iskh_par = mysql_query($query_iskh_par);
               if(!$result_iskh_par) puterror($TEXT['error-tbl37']);
               while($iskh_par = mysql_fetch_array($result_iskh_par))
               {
               //$query_del_cl2 = "DELETE FROM `$tbl_name` ORDER BY data LIMIT $del_rows";
                $query_del_cl2 = "DELETE FROM `$tbl_name` WHERE `".$tbl_col."` = '".$iskh_par['0']."'";
                $result_del_cl2 = mysql_query($query_del_cl2);
                if(!$result_del_cl2) puterror($TEXT['error-tbl37']);
                if($iskh_par['pic_tr'] !== "" && is_file("../".$iskh_par['pic_tr'])) unlink("../".$iskh_par['pic_tr']);
               }
              }
             }
           }
        }
      }

// проверка на наличие обновлений
if($result2['chk_upd'] == "yes"){
 $vis_upd = update_check("http://tel-spr.narod.ru/tel-spr-upd.txt",$int_proxy);
  if($vis_upd !== trim($TEXT['global-now-version'])) echo "<div id='formaupdate'>".$TEXT['global-new-version-yes']."<a href='http://tel-spr.narod.ru/changelog.html' target=_blank >".$vis_upd."</a></div>";
  if($vis_upd == "") echo "<div id='formaupdate'>".$TEXT['global-new-version-no']."</div>";
}

?>
<table width="100%" class="topadmin" border="0">
 <tr>
  <td class="nameusrl"><?php echo $TEXT['global-description']; ?><span class="nameusr"> <?php echo $TEXT['global-vertion']; ?></span></td>
  <td class="nameusr"><?php echo $TEXT['global-main-text'] ;?><span class="nameusrb"> <?php echo $result2['fullname'] ;?></span></td>
  <td width="7"><a href="logout.php" class=shut_img title="<?php echo $TEXT['global-logout-tit']; ?>"><img class="shut_logo" alt="<?php echo $TEXT['global-logout2']; ?>" src="../img/clr.png"></a></td>
 </tr>
</table>
<table width="100%" border="0" cellspacing="9">
    <tr align="center">
        <td class=help width="97%">
        <?php
           $dat = mysql_query("SELECT DATE(create_time) AS start_date, (SELECT DATEDIFF(CURDATE(),DATE(create_time))) AS working_days
               FROM information_schema.tables
               WHERE table_schema = 'personal' AND  table_name = 'tbl_house'
               ;");
             if($dat)
             {
               $date = mysql_fetch_array($dat);
               echo $TEXT['work1']."<b> ".$date['start_date']."</b>&nbsp;".$TEXT['work2']." <b>".$date['working_days']."</b> ".$TEXT['day'];
             }
           else puterror($TEXT['error-tbl11']);
	   $query1 = mysql_query("SELECT COUNT(user_id) FROM tbl_users");
	     $coun = mysql_result($query1, 0);
		$query_hide = mysql_query("SELECT COUNT(user_id) FROM tbl_users WHERE visible='hide'");
		$coun_hide = mysql_result($query_hide, 0);
	  echo "&nbsp;/&nbsp;".$TEXT['work3']."<b> ".$coun."</b> (".$TEXT['work4']."<b> ".$coun_hide."</b>)";
         ?>
        </td>
        <?php
             if(is_file("lang/".$lang."/docs/index.html"))
             {
              echo "<td align='right' width='3%'><a href='lang/".$lang."/docs/index.html' class='img' target=_blank title='". $TEXT['global-documents']."' ><img class='help_logo' alt='".$TEXT['global-documents']."' src= 'img/docs.gif' /></a></td>";
             }
             else echo "<td align='right' width='3%'><a href='lang/ru/docs/index.html' class='img' target=_blank title='". $TEXT['global-documents']."' ><img class='help_logo' alt='".$TEXT['global-documents']."' src= 'img/docs.gif' /></a></td>";
?>
</tr>
</table>
<table border="0" width="100%" align="center">
<tr>
<td width="33%">
    <fieldset>
    <legend align="left" title="<?php echo $TEXT['global-leg-tit2']; ?>"><?php echo $TEXT['global-tit2']; ?></legend>
    <table border="0" width="95%" align="center">
    <tr><td class="boxmenu"><a href="city/index.php" title="<?php echo $TEXT['menu-btn1-title']; ?>"><?php echo $TEXT['menu-btn1']; ?></a></td></tr>
    <tr><td class="boxmenu"><a href="street/index.php" title="<?php echo $TEXT['menu-btn2-title']; ?>"><?php echo $TEXT['menu-btn2']; ?></a></td></tr>
    <tr><td class="boxmenu"><a href="house/index.php" title="<?php echo $TEXT['menu-btn3-title']; ?>"><?php echo $TEXT['menu-btn3']; ?></a></td></tr>
    <tr><td class="boxmenu"><a href="organizaciya/index.php" title="<?php echo $TEXT['menu-btn4-title']; ?>"><?php echo $TEXT['menu-btn4']; ?></a></td></tr>
    <tr><td class="boxmenu"><a href="upravlenie/index.php" title="<?php echo $TEXT['menu-btn5-title']; ?>"><?php echo $TEXT['menu-btn5']; ?></a></td></tr>
    <tr><td class="boxmenu"><a href="otdel/index.php" title="<?php echo $TEXT['menu-btn6-title']; ?>"><?php echo $TEXT['menu-btn6']; ?></a></td></tr>
    <tr><td class="boxmenu"><a href="dolzhnost/index.php" title="<?php echo $TEXT['menu-btn7-title']; ?>"><?php echo $TEXT['menu-btn7']; ?></a></td></tr>
    <tr><td class="boxmenu"><a href="domain/index.php" title="<?php echo $TEXT['menu-btn8-title']; ?>"><?php echo $TEXT['menu-btn8']; ?></a></td></tr>
    <tr><td class="boxmenu"><a href="support/index.php" title="<?php echo $TEXT['menu-btn24-title']; ?>"><?php echo $TEXT['menu-btn24']; ?></a></td></tr>
    <tr><td class="boxmenu"><a href="size/index.php" title="<?php echo $TEXT['menu-btn29-title']; ?>"><?php echo $TEXT['menu-btn29']; ?></a></td></tr>
    <tr><td class="boxmenu"><a href="meeting/index.php" title="<?php echo $TEXT['meet-help']; ?>"><?php echo $TEXT['meet-title']; ?></a></td></tr>
    </table>
    </fieldset>
</td>
<td width="33%">
    <fieldset>
    <legend align="left" title="<?php echo $TEXT['global-leg-tit3']; ?>"><?php echo $TEXT['global-tit3']; ?></legend>
    <table border="0" width="95%" align="center">
    <tr><td class="boxmenusprav"><a href="users/index.php" title="<?php echo $TEXT['menu-btn9-title']; ?>"><?php echo $TEXT['menu-btn9']; ?></a></td></tr>
    <tr><td class="boxmenusprav"><a href="photoalbum/index.php" title="<?php echo $TEXT['menu-btn10-title']; ?>"><?php echo $TEXT['menu-btn10']; ?></a></td></tr>
    <tr><td class="boxmenusprav"><a href="normdoc/index.php" title="<?php echo $TEXT['menu-btn11-title']; ?>"><?php echo $TEXT['menu-btn11']; ?></a></td></tr>
    <tr><td class="boxmenusprav"><a href="instruction/index.php" title="<?php echo $TEXT['menu-btn17-title']; ?>"><?php echo $TEXT['menu-btn17']; ?></a></td></tr>
    <tr><td class="boxmenusprav"><a href="resources/index.php" title="<?php echo $TEXT['menu-btn12-title']; ?>"><?php echo $TEXT['menu-btn12']; ?></a></td></tr>
    <tr><td class="boxmenusprav"><a href="news/index.php" title="<?php echo $TEXT['menu-btn13-title']; ?>"><?php echo $TEXT['menu-btn13']; ?></a></td></tr>
    <tr><td class="boxmenusprav"><a href="forecast/index.php" title="<?php echo $TEXT['menu-btn16-title']; ?>"><?php echo $TEXT['menu-btn16']; ?></a></td></tr>
    </table>
    </fieldset>
</td>
<td width="33%">
    <fieldset>
    <legend align="left" title="<?php echo $TEXT['global-leg-tit1']; ?>"><?php echo $TEXT['global-tit1']; ?></legend>
    <table border="0" width="95%" align="center">
    <tr><td class="boxmenuadmin"><a href="logins/index.php" title="<?php echo $TEXT['menu-btn18-title']; ?>"><?php echo $TEXT['menu-btn18']; ?></a></td></tr>
    <tr><td class="boxmenuadmin"><a href="srvset/index.php" title="<?php echo $TEXT['global-srvset-title']; ?>"><?php echo $TEXT['global-srvset']; ?></a></td></tr>
    <tr><td class="boxmenuadmin"><a href="logs/index.php" title="<?php echo $TEXT['menu-btn14-title']; ?>"><?php echo $TEXT['menu-btn14']; ?></a></td></tr>
    <tr><td class="boxmenuadmin"><a href="ondisk/index.php" title="<?php echo $TEXT['menu-btn30-title']; ?>"><?php echo $TEXT['menu-btn30']; ?></a></td></tr>
    <tr><td class="boxmenuadmin"><a href="savepar/index.php" title="<?php echo $TEXT['param_tit']; ?>"><?php echo $TEXT['param_btn']; ?></a></td></tr>
    <tr><td class="boxmenuadmin"><a href="service/index.php" title="<?php echo $TEXT['menu-btn21-title']; ?>"><?php echo $TEXT['menu-btn21']; ?></a></td></tr>
    <tr><td class="boxmenuadmin"><a href="pochta/index.php" title="<?php echo $TEXT['pochta-title']; ?>"><?php echo $TEXT['pochta-title']; ?></a></td></tr>
    <tr><td class="boxmenuadmin"><a href="exim/index.php" title="<?php echo $TEXT['exim-help']; ?>"><?php echo $TEXT['exim-title']; ?></a></td></tr>
    <tr><td class="boxmenuadmin"><a href="zhurn_know/index.php" title="<?php echo $TEXT['menu-btn31-title']; ?>"><?php echo $TEXT['menu-btn31']; ?></a></td></tr>
    <tr><td class="boxmenuadmin"><a href="zhurn_know2/index.php" title="<?php echo $TEXT['menu-btn39-title']; ?>"><?php echo $TEXT['menu-btn39']; ?></a></td></tr>
    <tr><td class="boxmenuadmin"><a href="pass_tree/index.php" title="<?php echo $TEXT['pas-help']; ?>"><?php echo $TEXT['pas-title']; ?></a></td></tr>
    <tr><td class="boxmenuadmin"><a href="export/index.php" title="<?php echo $TEXT['menu-btn28-title']; ?>"><?php echo $TEXT['menu-btn28']; ?></a></td></tr>
    <?php
    if($ldp == 1) echo "<td class='boxmenuadmin'><a href='users/ldap-export-frm.php' title='".$TEXT['menu-btn37-tit']."'>".$TEXT['menu-btn37']."</a></td></tr>";
    ?>
    <tr><td class="boxmenuadmin"><a href="../update.php" title="<?php echo $TEXT['global-update-tit']; ?>"><?php echo $TEXT['global-update']; ?></a></td></tr>
    </table>
    </fieldset>
</td>
</tr>
</table>
<?php
  require_once "util/bottom_index.php";
?>