<?php
  ///////////////////////////////////////////////////
  //2012 (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['meet-help2'];
  $address_url = "http://".$_SERVER['SERVER_ADDR']."/personal/meet_detail.php?";

  require_once "config.php";
  require_once "utils/top_meet_otv.php";


  if(empty($_GET['evnt_id'])) puterror($TEXT['meet-err-edit2']);
  if(strlen($_GET['evnt_id'])>11) puterror($TEXT['meet-err-edit3']);

  if(!empty($_GET['org_id']))
  {
  $old_org_id = $_GET['org_id'];
  }
   else {
         $query_org_no = "SELECT `org_id` FROM `tbl_organizaciya` WHERE `organizaciya` = '-' ";
           $org_no = mysql_query($query_org_no);
            if(!$org_no) puterror($TEXT['error-tbl7']);
              $result_org_no = mysql_fetch_array($org_no,MYSQL_ASSOC);
              $old_org_id = $result_org_no['org_id'];
        }

  $_GET['evnt_id'] = rep($_GET['evnt_id']);
  $_GET['org_id'] = rep($_GET['org_id']);

$query_z1 = "SELECT
          tbl_meet_event.evnt_id,
          tbl_meet_event.room_id,
          tbl_meet_event.usr_id,
          tbl_meet_event.meet_name,
          tbl_meet_event.meet_visible,
          UNIX_TIMESTAMP(tbl_meet_event.meet_data) as meet_dt,
          tbl_meet_event.time_start,
          tbl_meet_event.time_stop,
          tbl_meet_event.time_start_min,
          tbl_meet_event.time_stop_min,
          tbl_meet_event.meet_descr,
          tbl_meet_room.room_name
          FROM tbl_meet_event
          JOIN tbl_meet_room ON tbl_meet_event.room_id=tbl_meet_room.room_id
          WHERE tbl_meet_event.evnt_id = '".$_GET['evnt_id']."' ";
      $zayavka1 = mysql_query($query_z1);
       if(!$zayavka1) puterror($TEXT['error-tbl49']);
        if(mysql_num_rows($zayavka1) > 0)
        {
         while($zay1 = mysql_fetch_array($zayavka1,MYSQL_ASSOC))
         {
          $m_name = $zay1['meet_name'];
          $message = $zay1['meet_descr'];
          $m_data = $zay1['meet_data'];
          $s_time= $zay1['time_start'];
          $e_time = $zay1['time_stop'];
          $s_time_m= $zay1['time_start_min'];
          $e_time_m = $zay1['time_stop_min'];
          $evt_id = $zay1['evnt_id'];
          $rm_id = $zay1['room_id'];
          $rm_name = $zay1['room_name'];

           $date_day = date("d",$zay1['meet_dt']);
           $date_month = date("m",$zay1['meet_dt']);
           $date_year = date("Y",$zay1['meet_dt']);
           $year = $TEXT['year'];
           if($zay1['meet_dt'] == "" || $zay1['meet_dt'] == "0") $data_r = "---";
            else $data_r = (date("$date_day $month[$date_month] $date_year $year "));

            $date_day2 = date("d");
            $date_week2 = date("w");
            $date_month2 = date("m");
            $date_year2 = date("Y");
            $data_podp = date("$week[$date_week2], $date_day2 $month[$date_month2] $date_year2 $year H:i:s");
         }
       }
            ////////////////////////////////////////////////////////
            // mail
            ////////////////////////////////////////////////////////
                $query5 = "SELECT * FROM `tbl_organizaciya` WHERE `org_id` = '".$old_org_id."'";
                  $result_query5 = mysql_query($query5);
                     if(!$result_query5) puterror($TEXT['error-tbl7']);
                      {
                       $result_organizaciya = mysql_fetch_array($result_query5,MYSQL_ASSOC);
                       $user_org = $result_organizaciya['organizaciya'];
                      }
                      if($user_org=="-")
                      {
                       $query7 = "SELECT
                        tbl_meet_users.*,
                        tbl_users.familiya,
                        tbl_users.name,
                        tbl_users.otchestvo,
                        tbl_users.mail,
                        tbl_users.dom_id
                        FROM `tbl_meet_users`
                        JOIN tbl_users ON tbl_meet_users.usr_id=tbl_users.user_id
                        WHERE tbl_meet_users.evnt_id = '".$_GET['evnt_id']."'";
                      $result_query7 = mysql_query($query7);
                       if(!$result_query7) puterror($TEXT['error-tbl50']);
                       {
                        while($result_mail2 = mysql_fetch_array($result_query7,MYSQL_ASSOC))
                         {
                          $user_mail2 = $result_mail2['mail'];
                          $full_name = $result_mail2['familiya']." ".$result_mail2['name']." ".$result_mail2['otchestvo'];

                          $query8 = "SELECT * FROM `tbl_domain` WHERE `dom_id` = '".$result_mail2['dom_id']."'";
                            $result_query8 = mysql_query($query8);
                             if(!$result_query8) puterror($TEXT['error-tbl5']);
                             {
                              $result_domain2 = mysql_fetch_array($result_query8,MYSQL_ASSOC);
                              $user_dom2 = $result_domain2['domain'];

                              $url = "<a href='".$address_url."evnt_id=".$evt_id."&amp;room_id=".$rm_id."&amp;org_id=".$_GET['org_id']."' target=_blank>".$TEXT['new-tag14']."</a>";

                              $organizaciya = $TEXT['new-glob1'];
                              $address = $user_mail2."@".$user_dom2;
                              $podpis = $organizaciya." ".$data_podp;
                              $tema = $TEXT['meet-invite4'];
                              $msg = "<b>".$m_name."</b><br /><br />".$TEXT['search-date']." - <i>".$data_r."</i><br />".$TEXT['meet-time1']." - <i>".$s_time.":".$s_time_m."</i><br />".$TEXT['meet-time2']." - <i>".$e_time.":".$e_time_m."</i><br />".$TEXT['meet-title2']." - <i>".$rm_name."</i><br />".$TEXT['support30']." - <i>".$full_name."</i><br /><br /><b>".$TEXT['meet-text'].":</b><br />".$message."<br /><br />".$url."<br /><hr />".$podpis."";

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

                              @mail($address, $tema, $msg, join("\r\n", array(
                              "From: phonebook@".$_SERVER['SERVER_NAME']."",
                              "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: Phone Book, version 2.3.5"
                              )));
                             }
                         }
                       }
                  }
                  else
                   {
                    $query3 = "SELECT
                        tbl_meet_users.*,
                        tbl_users.familiya,
                        tbl_users.name,
                        tbl_users.otchestvo,
                        tbl_users.mail,
                        tbl_users.dom_id
                        FROM `tbl_meet_users`
                        JOIN tbl_users ON tbl_meet_users.usr_id=tbl_users.user_id
                        WHERE tbl_meet_users.evnt_id = '".$_GET['evnt_id']."'";
                     $result_query3 = mysql_query($query3);
                       if(!$result_query3) puterror($TEXT['error-tbl50']);
                        {
                         while($result_mail = mysql_fetch_array($result_query3,MYSQL_ASSOC))
                         {
                          $user_mail2 = $result_mail['mail'];
                          $full_name = $result_mail['familiya']." ".$result_mail['name']." ".$result_mail['otchestvo'];

                          $query4 = "SELECT * FROM `tbl_domain` WHERE `dom_id` = '".$result_mail['dom_id']."'";
                            $result_query4 = mysql_query($query4);
                              if(!$result_query4) puterror($TEXT['error-tbl5']);
                               {
                                $result_domain = mysql_fetch_array($result_query4,MYSQL_ASSOC);
                                $user_dom2 = $result_domain['domain'];

                                $url = "<a href='".$address_url."evnt_id=".$evt_id."&amp;room_id=".$rm_id."&amp;org_id=".$_GET['org_id']."' target=_blank>".$TEXT['new-tag14']."</a>";

                                $organizaciya = $TEXT['new-glob21'].$user_org.$TEXT['new-glob22'];
                                $address = $user_mail2."@".$user_dom2;
                                $podpis = $organizaciya." ".$data_podp;
                                $tema = $TEXT['meet-invite4'];
                                $msg = "<b>".$m_name."</b><br /><br />".$TEXT['search-date']." - <i>".$data_r."</i><br />".$TEXT['meet-time1']." - <i>".$s_time.":".$s_time_m."</i><br />".$TEXT['meet-time2']." - <i>".$e_time.":".$e_time_m."</i><br />".$TEXT['meet-title2']." - <i>".$rm_name."</i><br />".$TEXT['support30']." - <i>".$full_name."</i><br /><br /><b>".$TEXT['meet-text'].":</b><br />".$message."<br /><br />".$url."<br /><hr />".$podpis."";

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

                                @mail($address, $tema, $msg, join("\r\n", array(
                                "From: phonebook@".$_SERVER['SERVER_NAME']."",
                                "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: Phone Book"
                                )));
                               }
                         }
                        }
                   }
            ////////////////////////////////////////////////////////
            // end mail
            ////////////////////////////////////////////////////////

  //*************************************
  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-new1'];
  $what = $_POST['header'];
  $who = $result2['fullname'];
  //*************************************
    $query2 = "INSERT INTO tbl_logs ( `log_id` , `data` , `ip` , `who` , `doing` , `what` ) VALUES ( NULL , NOW() , '$ip' , '$who' , '$doing' , '$what')";
        if(mysql_query($query2))
           {
             echo "<html><head>
                   <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=meet_otv.php' />
                   </head></html>";
           } else puterror($TEXT['error-log']);
  require_once "../util/bottom.php";
?>