<?php header("Content-type: text/html; charset=utf-8"); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ro">
  <head>
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  <title>Verificare comentarii noi</title>
  <link href="../style_c.css" rel="stylesheet" type="text/css" />
  <style type="text/css">
	.rosu {
	  color:red;
	}
	#fnew {
	  background-color:#f8f8fc;
	  font-family:Calibri, sans-serif;
	  font-size:16px;
	  padding:3px;
	}
  </style>
</head>
<body>

<center>

<?php
$new = 'new_reset.txt';	// Fisierul ce contine timpul ultimei resetari
include("admin.php");

// Resetare data ultimei verificari
// Daca sunt trimise datele din formular
 if(isset($_POST['pass_new']) && isset($_POST['timp_reset'])) {
  if ($_POST['pass_new']==$p_admin) {
	if ((int)$_POST['timp_reset']>11111111) {
	  // Modificarea timpului ultimei verificari
	  $fnew2 = @fopen($new, "w+b");
	  $new_v = $_POST['timp_reset'];
	  if (@fwrite($fnew2, $new_v) == -1) {
		print('<h3 class="rosu">Resetarea datei ultimei verificari esuata!</h3>.');
	  }
	  fclose($fnew2);
	}
	else {
	  print '<h4 class="rosu"><u>De la ultima resetare nu au fost adaugate comentarii,<br /> resetarea nu a fost efectuata.</u></h4>';
	}
  }
  else {
	print '<h4 class="rosu"><u>Parola administrator incorecta, resetarea nu a fost efectuata.</u></h4>';
  }
}

// Preia timpul ultimei resetari, din new.txt
$fnew = @fopen($new, "r+b");

// Citirea liniei din fisier
$s = fgets($fnew, 50);
$s = (int)$s;
$data_reset = date('j-F-Y, G:i ', $s);
fclose($fnew);
?>

<h2 id="coments_t">Ultimele comentarii adaugate pe site</h2>

<!-- Afisarea comentariilor -->
<div id="coments">
  <?php
	echo '<p class="rosu"><u>Ultima resetare a fost facuta de la comentariu adaugat in data</u> : &nbsp; <b>'.$data_reset.'</b><br />
	- <font color="blue">De atunci au fost adaugate urmatoarele comentarii:</font></p>';
	
	$nr = 0;	// Numarul de comentarii
	
	// Selecteaza din BD comentarii noi adaugate
	$sql = "SELECT * FROM `comentarii` WHERE `data`>'$s'";
	$result = mysql_query($sql, $conn) or trigger_error(E_USER_ERROR);

	// obtinerea separata a datelor din campurile BD
	while ($list = mysql_fetch_assoc($result)) {
	  $nr++;
	  $nume = stripslashes($list['nume']);
	  $email = stripslashes($list['email']);
	  $coment = stripslashes($list['coment']);
	    $coment = str_replace('<img src="icos/', '<img src="../icos/', $coment);	// Coreleaza src-ul cu pozitia in care se afla 'icos'
	  $site = stripslashes($list['site']);
	  $data1 = $list['data'];
	  $data = date('j-F-Y, &\n\b\sp; G:i ', $data1);
	  $link_pag = stripslashes($list['pagina']);
	  $link_pag = urldecode($link_pag);
	  $ad_link = '<span><a href="'.$link_pag.'#mp" target="_blank">Link pagina</a></span> &nbsp;'.$nr;
	  // Adauga la nume link-ul pt. site, daca utilizatorul a adaugat un site
	  if (strlen($site)>15) {
		$nume = '<a href="'.$site.'" id="n'.$nr.'">'.$nume.'</a>';
	  }

	  // afiseaza rezultatele, ordonate
	  echo "\r\n".'<div class="coms'.($nr%2).'"><div class="n_coms"> &#1440; '.$nume.' </div> <div class="nr_coms"> '.$ad_link.' </div><span class="e_coms">'. $email. '</span><em class="d_coms">'. $data. '</em> &nbsp; &nbsp; &nbsp; ';
	  echo '<br /><div class="c_coms">'. $coment. '</div></div><hr class="linie_coms"/>'."\r\n";
	}
  ?>
</div>

<br />
<form action="" method="post" id="fnew">
  <h4><u>Resetati data ultimei verificari</u></h4>
  <input type="hidden" name="timp_reset" value="<?php echo $data1; ?>" />
  <b><i>Parola Admin</i></b> : <input type="text" name="pass_new" size="15" maxlength="40" /> &nbsp; 
  <input type="submit" value="Reseteaza" />
</form><br />
</center>

</body>
</html>