<?php
  ///////////////////////////////////////////////////
  //2011 (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";

  $title=$titlepage = $TEXT['know-foto'];
  $helppage = $TEXT['know-foto-help'];

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

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

  if(strlen($_POST['photo_obr'])>1) puterror2($TEXT['error-pho-obr']);
  if(strlen($_POST['photo_obt'])>8) puterror2($TEXT['error-pho-obt']);
  if(strlen($_POST['descrip'])>255) puterror2($TEXT['error-new10']);
  $_POST['photo_obr'] = rep($_POST['photo_obr']);
  $_POST['descrip'] = rep($_POST['descrip']);
  
  if($_FILES['image']['size'] > 1024*20*1024) puterror2($TEXT['error-pic3']);

  $sm = "small";
  $bg = "big";

  if(!empty($_FILES['image']['tmp_name']))
  {
    $ext = strrchr($_FILES['image']['name'], ".");
    $image = "../../photo-news/$bg".date("YmdHis",time())."$ext";
    $smallimage = "../../photo-news/$sm".date("YmdHis",time())."$ext";
    if(copy($_FILES['image']['tmp_name'], $image) && copy($_FILES['image']['tmp_name'], $smallimage))
    {
      unlink($_FILES['image']['tmp_name']);
      chmod($image, 0644);
    }
  } else puterror2($TEXT['error-photo-no']);

  if($_POST['photo_obr'] == '1') {
//	$image = $image;
		if(!empty($_FILES['image']['tmp_name']))
                  {
                   $ext = strrchr($_FILES['image']['name'], ".");
                   $smallimage2 = "../../photo-news/$sm".date("YmdHis",time())."$ext";
                  if(copy($_FILES['image']['tmp_name'], $smallimage2))
                 {
                 unlink($smallimage);
                 unlink($_FILES['image']['tmp_name']);
                 chmod($smallimage2, 0644);
                 }
                 } else puterror2($TEXT['error-photo-no']);
		$smallimage = $smallimage2;
            }
            if($_POST['photo_obr'] == '2') {
                 if(!resizeimg_simple($image, $smallimage, 400, 600))
                {
                  puterror2($TEXT['error-gdlib']);
                }
            }
            if($_POST['photo_obr'] == '3') {
                 if(!resizeimg_simple($image, $smallimage, 600, 400))
                {
                  puterror2($TEXT['error-gdlib']);
                }
            }
             if($_POST['photo_obr'] == '4') {
                 if(!resizeimg($image, $smallimage, 400, 600))
                {
                  puterror2($TEXT['error-gdlib']);
                }
            }
             if($_POST['photo_obr'] == '5') {
                 if(!resizeimg($image, $smallimage, 600, 400))
                {
                  puterror2($TEXT['error-gdlib']);
                }
            }
          echo "<html><head>
                   <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=know_add_photoform.php?pic=".$smallimage."&amp;pic_big=".$image."&amp;descr=".$_POST['descrip']."&amp;photo_obt=".$_POST['photo_obt']."' />
                   </head></html>";

  require_once "../util/bottom.php";
?>