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

require_once "utils/chlang_osn.php";

$title = $TEXT['menu-btn31-title'];

require_once "config.php";
require_once "utils/functions.php";
require_once "utils/top_film.php";

if($result2['administrator'] == 0) {puterror2($result2['skin'],$TEXT['error-loginform2']); require_once "utils/bottom_film.php"; exit();}

if(empty($_GET['film_id'])) {puterror2($result2['skin'],$TEXT['error-film5']); require_once "utils/bottom_film.php"; exit();}
if(strlen($_GET['film_id'])>255) {puterror2($result2['skin'],$TEXT['error-film6']); require_once "utils/bottom_film.php"; exit();}
$_GET['film_id'] = rep($_GET['film_id']);

$query_body = "SELECT
tbl_film.film_name,
tbl_film.film_id,
YEAR(tbl_film.data_vidachi) AS data_vidachi_year,
MONTH(tbl_film.data_vidachi) AS data_vidachi_month,
DAY(tbl_film.data_vidachi) AS data_vidachi_day,
YEAR(tbl_film.data_sdachi) AS data_sdachi_year,
MONTH(tbl_film.data_sdachi) AS data_sdachi_month,
DAY(tbl_film.data_sdachi) AS data_sdachi_day,
tbl_film.user_id,
tbl_biblioteka.name AS bibl_name,
tbl_logins.dom_id,
tbl_logins.e_mail,
tbl_logins.familiya,
tbl_logins.name,
tbl_logins.otchestvo,
tbl_domain.domain
FROM tbl_film
JOIN tbl_biblioteka ON tbl_film.bibl_id=tbl_biblioteka.bibl_id
JOIN tbl_logins ON tbl_film.user_id=tbl_logins.login_id
JOIN tbl_domain ON tbl_logins.dom_id=tbl_domain.dom_id
WHERE tbl_film.film_id = '".$_GET['film_id']."' ";
  $result_body = mysqli_query($dbcnx,$query_body);
    if(!$result_body) {puterror2($result2['skin'],$TEXT['error-tbl26']); require_once "utils/bottom_film.php"; exit();}
     $result_rows = mysqli_num_rows($result_body);
       if($result_rows  > 0)
         {
          while($result_body_film= mysqli_fetch_array($result_body))
               {

               $date_day = $result_body_film['data_sdachi_day'];
               $date_month = $result_body_film['data_sdachi_month'];
               $date_year = $result_body_film['data_sdachi_year'];
               $year = $TEXT['year2'];
               if($date_year == "0000" || $date_year == "1970") {$data_sd = "---";}
                else {$data_sd = (date("$date_day $month[$date_month] $date_year $year"));}

               $date_day2 = $result_body_film['data_vidachi_day'];
               $date_month2 = $result_body_film['data_vidachi_month'];
               $date_year2 = $result_body_film['data_vidachi_year'];
               if($date_year2 == "0000" || $date_year2 == "1970") {$data_vid = "---";}
                else {$data_vid = (date("$date_day2 $month[$date_month2] $date_year2 $year"));}

               $date_day3 = date("d", time());
               $date_month3 = date("m", time());
               $date_year3 = date("Y", time());
               $date_time = date("H:i:s", time());
               $data3 = (date("$date_day3 $month[$date_month3] $date_year3 $year"))." ".$date_time;

               $bibl = $result_body_film['bibl_name'];
               $film_name = rep_back($result_body_film['film_name']);
               $usr_name = $result_body_film['name'];
               $usr_fam = $result_body_film['familiya'];
               $usr_otch = $result_body_film['otchestvo'];

               $query_vlad = "SELECT
                tbl_logins.e_mail AS vl_em,
                tbl_domain.domain AS vl_dom
                FROM tbl_logins
                JOIN tbl_domain ON tbl_logins.dom_id=tbl_domain.dom_id
                WHERE `login_id`='".$_COOKIE['ident']."' ";
                $result_vlad = mysqli_query($dbcnx,$query_vlad);
                 if(!$result_vlad) {puterror2($result2['skin'],$TEXT['error-tbl7']); require_once "utils/bottom_film.php"; exit();}
                  $result2_vlad = mysqli_fetch_array($result_vlad);

               if($result_body_film['e_mail'] !== '') {$address = $result_body_film['e_mail']."@".$result_body_film['domain'];}
                else {puterror2($result2['skin'],$TEXT['error-film28']); require_once "utils/bottom_film.php"; exit();}

               $address_vlad = $result2_vlad['vl_em']."@".$result2_vlad['vl_dom'];

               $podpis = $TEXT['nap_podp'].$result2['familiya']." ".$result2['name']."<br />".$data3."<br /><a href=mailto:".$address_vlad.">".$address_vlad."</a>";
               $tema = $TEXT['nap_tema'];
               $msg = $TEXT['nap_head1'].$result_body_film['familiya']." ".$result_body_film['name']." ".$result_body_film['otchestvo'].".<br /><br />".$TEXT['nap_telo1'].$data_vid." ".$TEXT['nap_telo2'].rep_back($result_body_film['film_name']).$TEXT['nap_telo3'].$data_sd.$TEXT['nap_telo4']."<br />===============<br />".$podpis."<hr align='left' width='30%'/>";

               $tema = stripslashes($tema);
               $msg = nl2br(stripslashes($msg));

               mail($address, $tema, $msg, join("\r\n", array(
               "From: ".$address_vlad."",
               "MIME-Version: 1.0",
               "Content-type: text/html; charset=utf-8",
               "Content-Transfer-Encoding: 8bit",
               "Date: ".date("D, d-M-Y H:i:s", time())."",
               "X-Mailer: Home library",
               "X-Spam-Flag: NO"
               )));
               }
         }

  //*************************************
  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-mail'];
  $what = $TEXT['log-mail2'].$usr_fam." ".$usr_name." ".$usr_otch;
  $who = $result2['familiya']." ".$result2['name'];
  //*************************************
  $query2 = "INSERT INTO tbl_logs ( `log_id` , `data` , `ip` , `who` , `doing` , `what` ) VALUES ( NULL , NOW() , '$ip' , '$who' , '$doing' , '$what')";
        if(mysqli_query($dbcnx,$query2))
           {
             echo "<html><head>
                   <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=film-vidano-search.php' />
                   </head></html>";
           } else {puterror2($result2['skin'],$TEXT['error-log']); require_once "utils/bottom_film.php"; exit();}
  require_once "utils/bottom_film.php";
?>