Location: PHPKode > projects > A-Dater Pro - Online Dating Script > a-dater-pro-online-dating-script/avaleht.php
<?php
/*
  ******************************************************
  ***   A-Dater Pro        Version 2                 ***
  ***   File name          avaleht.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');


  //Hääletamine

  if(isset($_POST['submit']) && isset($_SESSION['id'])){

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

    if(mysql_num_rows($select_test) == 0){

      mysql_insert('haaled', $_SESSION['id'], $_POST['variant']);

      mysql_query("UPDATE haaletus SET haali = haali+1 WHERE id='".(int)$_POST['variant']."'");

    }

  }


  //Kogume 3 top naist massiivi

  $select_n = mysql_query("SELECT pildid.id AS id, pildid.kasutaja_id AS kasutaja_id,  pildid.pilt AS pilt,  pildid.hinne AS hinne,  kasutajad.kasutaja AS kasutaja FROM kasutajad, pildid WHERE pildid.olek = 1 && kasutajad.id = pildid.kasutaja_id && kasutajad.sugu = 2 ORDER BY hinne DESC LIMIT 4");

  $n = array();

  while($row_n = mysql_fetch_assoc($select_n)){

    $n[] = $row_n;

  }


  //Kogume 3 top meest massiivi

  $select_m = mysql_query("SELECT pildid.id AS id, pildid.kasutaja_id AS kasutaja_id,  pildid.pilt AS pilt,  pildid.hinne AS hinne,  kasutajad.kasutaja AS kasutaja FROM kasutajad, pildid WHERE pildid.olek = 1 && kasutajad.id = pildid.kasutaja_id && kasutajad.sugu = 1 ORDER BY hinne DESC LIMIT 4");

  $m = array();

  while($row_m = mysql_fetch_assoc($select_m)){

    $m[] = $row_m;

  }


  //Kogume 3 viimati lisatud naist massiivi

$select_vn = mysql_query("SELECT pildid.id AS id, pildid.kasutaja_id AS kasutaja_id,  pildid.pilt AS pilt,  pildid.hinne AS hinne,  kasutajad.kasutaja AS kasutaja FROM kasutajad, pildid WHERE pildid.olek = 1 && kasutajad.id = pildid.kasutaja_id && kasutajad.sugu = 2 ORDER BY pildid.date DESC LIMIT 4");

  $vn = array();

  while($row_vn = mysql_fetch_assoc($select_vn)){

    $vn[] = $row_vn;

  }


  //Kogume 3 viimati lisatud meest massiivi

$select_vm = mysql_query("SELECT pildid.id AS id, pildid.kasutaja_id AS kasutaja_id,  pildid.pilt AS pilt,  pildid.hinne AS hinne,  kasutajad.kasutaja AS kasutaja FROM kasutajad, pildid WHERE pildid.olek = 1 && kasutajad.id = pildid.kasutaja_id && kasutajad.sugu = 1 ORDER BY pildid.date DESC LIMIT 4");

  $vm = array();

  while($row_vm = mysql_fetch_assoc($select_vm)){

    $vm[] = $row_vm;

  }


  //3 viimast kümmet

  $select_ten = mysql_query("SELECT pildi_id, kasutaja_id, kommentaar FROM hinded WHERE hinne='10' ORDER BY date DESC LIMIT 3");  


    //Statistika

    $stat_sugu_men = mysql_query("SELECT id FROM kasutajad WHERE sugu = 1");

    $stat_sugu_woman = mysql_query("SELECT id FROM kasutajad WHERE sugu = 2");

    $stat_users = mysql_query("SELECT id FROM kasutajad");

    $stat_pictures = mysql_query("SELECT id FROM pildid");

    $stat_comments = mysql_query("SELECT id FROM kommentaarid");

?>


<table cellpadding="0" cellspacing="0">

	<tr>

	  <td class="text" colspan="2" align="right">

	<table cellpadding="0" cellspacing="0">
	  <tr>
	    <td id="a_searchbar_bg"></td>
	    <td id="a_searchbar_bgcolor" height="22" style="padding-top: 2px; padding-right: 5px;">
	  <form action="index.php" method="GET">

	    <b><?php print safe_display($word_1) ?></b> 

	    <select name="sugu">

          <option value="2"><?php print safe_display($word_4) ?></option>

	      <option value="1"><?php print safe_display($word_3) ?></option>

	      <option value="0"><?php print safe_display($word_2) ?></option>
	      

	    </select>

	    <b><?php print safe_display($word_5) ?></b>

	    <?php

	      $perekonnaseis = $include_useris;

        ?>

	    <select name="perekonnaseis">

	     <?php

	       foreach ($perekonnaseis AS $i => $perekon)

	       {

	         print '<option value="'.$i.'">'.$perekon.'</option>';

	       }

	     ?>

	    </select>
	    
	    <input type="hidden" name="sorteeri" value="0">
	    
	    <input type="hidden" name="jarjesta" value="0">

	    <input type="hidden" name="leht" value="otsing">

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

	  </form>
	     </td>
	  </tr>
	</table>

	  </td>

	</tr>

  <tr>

    <td valign="top" style="padding-left: 1px;">

<table cellpadding="0" cellspacing="0" width="292">

  <tr>

    <td class="avaleht_text_p" colspan="2" height="31"><?php print safe_display($word_7) ?></td>

  </tr>

  <tr id="a_bg_blue">

    <td class="avaleht_text_b"><?php print safe_display($word_8) ?></td>

    <td class="avaleht_text_b"><?php print safe_display($word_9) ?></td>

  </tr>

<?php


  //TOP 4

  if(count($m) > 0 && count($n) > 0){

    for($i=0; $i<4; $i++){

  	  print'<tr id="a_bg_blue">

  	          <td align="center" style="padding-top: 10px;">';

if(isset($m[$i])){
print'
                <a href="index.php?leht=pilt&id='.$m[$i]['id'].'"><img src="thumb/'.safe_display($m[$i]['pilt']).'" style="border: 2px #BDCBD3 solid;"></img></a>

<br>

                <a href="index.php?leht=kasutaja&id='.$m[$i]['kasutaja_id'].'">'.$m[$i]['kasutaja'].'</a>   	
';
}
print'

  	          </td>

  	          <td align="center">';

if(isset($n[$i])){
print'

  	            <a href="index.php?leht=pilt&id='.$n[$i]['id'].'"><img src="thumb/'.safe_display($n[$i]['pilt']).'" style="border: 2px #BDCBD3 solid;"></img></a>

<br>

                <a href="index.php?leht=kasutaja&id='.$n[$i]['kasutaja_id'].'">'.$n[$i]['kasutaja'].'</a> 	            
';}
print '

  	          </td>

  	       </tr>';

    }

  }

?>

  <tr>

    <td colspan="2" height="8" id="a_top_bg_a"></td>

  </tr>

  <tr>

    <td colspan="2" style="padding-left: 10px;" id="a_bg_dblue">

      <?php


      //Hääletus

      $select_kusimus = mysql_query("SELECT kusimus FROM seaded WHERE id=1");

      $row_kusimus = mysql_fetch_assoc($select_kusimus);

      print'<table cellpadding="0" cellspacing="0">

             <tr>

               <td colspan="2">

		  <table cellpadding="0" cellspacing="0">

		    <tr>

			<td id="a_poll_icon"></td>

			<td class="avaleht_text_p2">&nbsp;'.$row_kusimus['kusimus'].'</td>

		    </tr>

		  </table>

	       </td>

             </tr>';

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

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

      }

      if(isset($_SESSION['id']) && mysql_num_rows($select_test) == 0){


      	//Hääletamine

      	$select_variandid = mysql_query("SELECT id, variant, haali FROM haaletus");

      	print '<form method="POST" action="index.php?leht=avaleht">';

      	while($row_variandid = mysql_fetch_assoc($select_variandid)){

      	  print '<tr>

      	          <td width="30" style="padding-top: 5px;"><input type="radio" value="'.(int)$row_variandid['id'].'" name="variant"></td>

      	          <td class="kysitlus_text">'.safe_display($row_variandid['variant']).'</td>       

      	        </tr>';

      	}

      	print '<tr>

      	         <td></td>

      	         <td><input type="submit" name="submit" value="'.safe_display($word_10).'"></td>

      	       </tr>

      	       </form>';

      }

      else{

      	$select_variandid = mysql_query("SELECT variant, haali FROM haaletus");


      	//Häälte kogumine massiivi

      	$haaled = array();

      	while($row_variandid = mysql_fetch_assoc($select_variandid)){

      	  $haaled[] = $row_variandid;

      	}


      	//Kõikide häälte summa

      	$koik = 0;

      	foreach($haaled AS $haal){

      	  $koik = $koik + $haal['haali'];

      	}


      	//Protsent

      	foreach($haaled AS $i => $haal){

      	  if($koik > 0){

      	    $haaled[$i]['protsent'] = $haal['haali'] /$koik * 100;	

      	  }

      	  else{

      	  	$haaled[$i]['protsent'] = 0;

      	  }

      	}


      	//Väljastus

      	foreach($haaled AS $haal){

          $laius = $haal['protsent'] * 1.7;

      	  print '<tr>

      	          <td colspan="2" class="kysitlus_text" style="padding-top: 5px;">'.$haal['variant'].'</td>

      	        </tr>

      	        <tr>

      	          <td style="padding-top: 5px;">

      	            <table cellpadding="0" cellspacing="0">

      	              <tr>

      	                <td id="a_poll_v"></td>

      	                <td width="'.(int)$laius.'" id="a_poll_k"></td>

      	                <td id="a_poll_p"></td>

    	                <td class="kysitlus_text">&nbsp;'.(int)$haal['protsent'].'% ('.(int)$haal['haali'].')</td>

      	              </tr>

      	            </table>

                   </td>

      	        </tr>';

      	}

      }

      print'</table>';

      ?>

    </td>

  </tr>

  <tr>

    <td colspan="2" height="5" width="291" id="a_poll_bg_a"></td>

  </tr>

</table>

    </td>

    <td id="a_border1" valign="top">

<table cellpadding="0" cellspacing="0">

  <tr>

    <td colspan="2" id="a_lpic_top" width="333">

      <table cellpadding="0" cellspacing="0">

	<tr>

	  <td height="24" style="padding-left: 5px; padding-right: 3px;"><div id="a_lpic_icon"></div></td>

	  <td class="avaleht_text_p2"><?php print safe_display($word_11) ?></td>

	</tr>

      </table>

    </td>

  </tr>

  <tr id="a_bg_blue">

    <td class="avaleht_text_b" style="padding-top: 4px;"><?php print safe_display($word_12) ?></td>

    <td class="avaleht_text_b" style="padding-top: 4px;"><?php print safe_display($word_13) ?></td>

  </tr>

  <tr id="a_bg_blue">

<?php


  //Viimati lisatud

  if(count($vm) > 0 && count($vn) > 0){

    for($i=0; $i<4; $i++){

  	  print'<tr id="a_bg_blue">

  	          <td align="center" style="padding-top: 10px;">';

if(isset($vm[$i])){
print'
                <a href="index.php?leht=pilt&id='.$vm[$i]['id'].'"><img src="thumb/'.safe_display($vm[$i]['pilt']).'" style="border: 2px #BDCBD3 solid;"></img></a>

<br>

                <a href="index.php?leht=kasutaja&id='.$vm[$i]['kasutaja_id'].'">'.$vm[$i]['kasutaja'].'</a>   	
';
}
print'

  	          </td>

  	          <td align="center">
';
if(isset($vn[$i])){
print'

  	            <a href="index.php?leht=pilt&id='.$vn[$i]['id'].'"><img src="thumb/'.safe_display($vn[$i]['pilt']).'" style="border: 2px #BDCBD3 solid;"></img></a>

<br>

                <a href="index.php?leht=kasutaja&id='.$vn[$i]['kasutaja_id'].'">'.$vn[$i]['kasutaja'].'</a> 	            
';}
print '

  	          </td>

  	       </tr>';

    }

  }

?>

  </tr>

  <tr>

    <td height="6" colspan="2" id="a_lpic_bg_a"></td>

  </tr>

</table>

    </td>

  </tr>

</table>

<?php

  $select_online = mysql_query("

    SELECT SQL_CALC_FOUND_ROWS

      online.kasutaja_id AS kasutaja_id,

      kasutajad.id AS id,

      kasutajad.kasutaja AS kasutaja 

    FROM 

      online,

      kasutajad

    WHERE 

      DATE_SUB(NOW(),INTERVAL 15 MINUTE) <= online.date

      &&

      online.online = 1

      &&

      kasutajad.id = online.kasutaja_id

    LIMIT 50

  ");

  $select_found_online = mysql_query("SELECT FOUND_ROWS()");

  $found_online = mysql_fetch_assoc($select_found_online);

?>

<table cellpadding="3" cellspacing="0">

    <td class="text_online_p">

              <?php print safe_display($word_15e) ?> (<?php print mysql_num_rows($stat_users) ?>)&nbsp;

              <?php print safe_display($word_15g) ?> (<?php print mysql_num_rows($stat_comments) ?>)&nbsp;

              <?php print safe_display($word_15f) ?> (<?php print mysql_num_rows($stat_pictures) ?>)&nbsp;
                              
              <?php print safe_display($word_15c) ?> (<?php print mysql_num_rows($stat_sugu_men) ?>)&nbsp;

              <?php print safe_display($word_15d) ?> (<?php print mysql_num_rows($stat_sugu_woman) ?>)

    </td>

  <tr>

    <td class="text_online_p"><?php print safe_display($word_14) ?> (<?php print $found_online['FOUND_ROWS()'] ?>)</td>

  </tr>

  <tr>

    <td class="text_online">

      <?php

        if($found_online['FOUND_ROWS()'] > 0){

          $i = 0;

          while($row_online = mysql_fetch_assoc($select_online)){

            print ($i > 0 ? ', ' : '').'<a href="index.php?leht=kasutaja&id='.$row_online['id'].'">'.$row_online['kasutaja'].'</a>';

            $i++;

          }

          if($found_online['FOUND_ROWS()'] > 50){

          	print ' <a href="index.php?leht=otsing">Veel</a>';

          }

        }

      ?>

    </td>

  </tr>

</table>

<?php

  $select_sunnipaev=mysql_query("SELECT id, kasutaja FROM kasutajad WHERE date_format(now(),'%d%m') = date_format( sunniaeg,'%d%m') LIMIT 50");

  $select_found_sunnipaev = mysql_query("SELECT FOUND_ROWS()");

  $found_sunnipaev = mysql_fetch_assoc($select_found_sunnipaev);

?>

<table cellpadding="3" cellspacing="0">

  <tr>

    <td class="text_online_p"><?php print safe_display($word_15) ?> (<?php print $found_sunnipaev['FOUND_ROWS()'] ?>)</td>

  </tr>

  <tr>

    <td class="text_online">

      <?php

        if($found_sunnipaev['FOUND_ROWS()'] > 0){

          $i=0;

          while($row_sunnipaev = mysql_fetch_assoc($select_sunnipaev)){

          	print ($i > 0 ? ', ' : '').'<a href="index.php?leht=kasutaja&id='.$row_sunnipaev['id'].'">'.$row_sunnipaev['kasutaja'].'</a>';

            $i++;

          }

          if($found_sunnipaev['FOUND_ROWS()'] > 50){

          	print ' <a href="index.php?leht=otsing">'.safe_display($word_15b).'</a>';

          }

        } 

      ?>

    <td>

  </tr>

<tr>


  </tr>

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