Location: PHPKode > projects > A-Dater Pro - Online Dating Script > a-dater-pro-online-dating-script/pildid.php
<center>

<?php
/*
  ******************************************************
  ***   A-Dater Pro        Version 2                 ***
  ***   File name          pildid.php                ***
  ***   Script Owner       Alfacom Systems           ***
  ***   Script Homepage    www.a-dater.com           ***
  ***   Licence Terms      www.a-dater.com/licence   ***
  ***                                                ***
  ***   You need to purchase a license if you want   ***
  ***   to use this script with ads or without the   ***
  ***   reference to www.a-dater.com                 ***
  ******************************************************
*/

  include('includes/include_check.php');

  include('includes/log_check.php');

  
  //Kirjelduse muutmine

  if(isset($_POST['submit_kirjeldus'])){

  	$select_test = mysql_query("SELECT id FROM pildid WHERE id='".(int)$_POST['id']."' && kasutaja_id='".(int)$_SESSION['id']."'");

  	if(mysql_num_rows($select_test) > 0){

  	  mysql_query("UPDATE pildid SET kirjeldus = '".safe_input($_POST['uus_kirjeldus'])."' WHERE id='".(int)$_POST['id']."'");

  	  print '<p>'.safe_display($word_226).'</p>';

  	}

  }
  

  //Kustutamine

  if(isset($_GET['kustuta'])){

    $select_test = mysql_query("SELECT id, pilt FROM pildid WHERE id='".(int)$_GET['kustuta']."' && kasutaja_id='".(int)$_SESSION['id']."'");

  	if(mysql_num_rows($select_test) > 0){

  	  $row_test = mysql_fetch_assoc($select_test);

  	  unlink('thumb/'.$row_test['pilt']);

  	  unlink('pilt/'.$row_test['pilt']);

  	  mysql_query("DELETE FROM hinded WHERE pildi_id='".(int)$row_test['id']."'");  	  

  	  mysql_query("DELETE FROM kommentaarid WHERE pildi_id='".(int)$row_test['id']."'");

  	  mysql_query("DELETE FROM pildid WHERE id='".(int)$row_test['id']."'");

  	  print '<p>'.safe_display($word_227).'</p>';

  	}	

  }
  

  //Pildi lisamine

  if(isset($_POST['submit']) && isset($_FILES['pilt'])){

  	$select_pilte = mysql_query("SELECT pilte, pilteVip, pic_width FROM seaded WHERE id=1");

  	$row_pilte = mysql_fetch_assoc($select_pilte);

  	if(isVip($_SESSION['id'])){

  	  $lubPilte = $row_pilte['pilteVip'];  

  	}

  	else{

  	  $lubPilte = $row_pilte['pilte'];

  	}

  	$select_pilte_kasutajal = mysql_query("SELECT id FROM pildid WHERE kasutaja_id = '".$_SESSION['id']."'");

  	if($lubPilte > mysql_num_rows($select_pilte_kasutajal)){


  	  //Kontroll kas tegu on jpg'ga	

  	  $laiend = mb_strtolower(strrchr($_FILES['pilt']['name'], '.'));

  	  if($laiend == '.jpg' || $laiend == '.jpeg'){

  	  	list($width_test, $height_test) = getimagesize($_FILES['pilt']['tmp_name']);

  	    if($width_test > 0 || $height_test > 0){ 

  	      $dir = $homedirectory;


  	      //Nimi ja selle kontroll

  	      $name = random(10).'.jpg';

          while(file_exists($dir.'/pilt/'.$name)){

  	        $name = random(10).'.jpg';

  	      }


  	      //Pildi ja thumbi tulevased asukohad

  	      $path = $dir.'/pilt/'.$name;

          $thumb_path = $dir.'/thumb/'.$name;


          //Upload

          $temp = $_FILES['pilt']['tmp_name'];

          move_uploaded_file($temp, $path);

          list($width, $height) = getimagesize($path);


          //Thumbi mõõtmete arvutamine     

          $thumb_width = 120;

          $x = $width / $thumb_width;

          $thumb_height = $height / $x;


          //Thumbi tegemine

          $thumb = imagecreatetruecolor($thumb_width, $thumb_height);

          $source = imagecreatefromjpeg($path);

          imagecopyresized($thumb, $source, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height);

          imagejpeg($thumb, $thumb_path, 100);

          list($width, $height) = getimagesize($path);


          //Kui pildi laius on suurem kui lubatud tehakse seda väiksemaks

          if($width > $row_pilte['pic_width']){


      	    //Uute mõõtmete arvutamine

      	    $image_width = $row_pilte['pic_width'];

      	    $x = $width / $image_width;

      	    $image_height = $height / $x;


      	    //Mõõtmete muutmine

      	    $image = imagecreatetruecolor($image_width, $image_height);

      	    $source = imagecreatefromjpeg($path);

      	    imagecopyresized($image, $source, 0, 0, 0, 0, $image_width, $image_height, $width, $height); 

      	    imagejpeg($image, $path, 100);	

          }

          $rowAccept = mysql_fetch_assoc(mysql_query("SELECT piltAccept FROM seaded"));

          $accept = $rowAccept['piltAccept'];

          mysql_insert('pildid', $_SESSION['id'], $name, $_POST['kirjeldus'], $accept, 0, 0);

          print '<p>'.safe_display($word_228).'</p>';

  	    }

  	    else{

  	      print '<p>'.safe_display($word_229).'</p>';

  	    }

  	  }

  	  else{

  	    print '<p>'.safe_display($word_230).'</p>';

  	  }

  	}

  	else{

  	  print '<p>'.safe_display($word_231).'<br>'.safe_display($word_233).'<br>'.safe_display($word_232).' '.$lubPilte;

  	}

  }

?>

<div class="sisu_paigutus2">

<form enctype="multipart/form-data" action="<?php $_SERVER['PHP_SELF'] ?>" method="post">

  <table cellspacing="5" id="tabel2" width="400">

    <tr>

      <td class="tavaline_text_bold"><?php print safe_display($word_234) ?></td>

      <td><input size="34" name="pilt" type="file"></td>

    </tr>

    <tr>

      <td class="tavaline_text_bold"><?php print safe_display($word_235) ?></td>

      <td><textarea cols="40" rows="4" name="kirjeldus"></textarea></td>

    </tr>

    <tr>

      <td></td>

      <td><input type="submit" name="submit" value="<?php print safe_display($word_236) ?>"></td>

    </tr>

  </table>  

</form> 

<?php

  $select_pilt = mysql_query("SELECT id, pilt, kirjeldus, olek FROM pildid WHERE kasutaja_id='".(int)$_SESSION['id']."' ORDER BY date DESC");

  $olek = $include_olek;

  while($row_pilt = mysql_fetch_assoc($select_pilt)){

  	print '<form action="index.php?leht=pildid" method="post">

  	       <table cellspacing="5" id="tabel1" width="400">

  	         <tr>

  	           <td><a href="index.php?leht=pilt&id='.(int)$row_pilt['id'].'"><img src="thumb/'.$row_pilt['pilt'].'"></img></a></td>

  	           <td>

                 <center>

  	               <textarea cols="30" rows="4" name="uus_kirjeldus">'.safe_display($row_pilt['kirjeldus']).'</textarea>

                   <input type="hidden" name="id" value="'.(int)$row_pilt['id'].'">

                   <br>

                   <input type="submit" name="submit_kirjeldus" value="'.safe_display($word_237).'">

                 </center>

               </td>

             </tr>

             <tr>

               <td><a href="index.php?leht=pildid&kustuta='.(int)$row_pilt['id'].'">'.safe_display($word_238).'</a></td>               

               <td class="tavaline_text_bold">'.safe_display($word_239).' '.$olek[$row_pilt['olek']].'</td>

  	         </tr>

  	       </table>

  	       </form>';

  }

?>

</div>

</center>
Return current item: A-Dater Pro - Online Dating Script