<?php 

//zobrazi objednavky adminovy vybavene
function ZobrazFormular1()
{
?>
</div><!--end welcome--> 
				<div id="content">
</br>
<p>
<?php if (isset($_SESSION['admin']) && ($_SESSION['admin']==1) )
{
	$link = mysql_connect();
		if ($link) 
		{
			if (mysql_select_db()) 
			{
				$sql = "SELECT * FROM form WHERE done='1' ";
				//	$sql = "SELECT * FROM forum ORDER BY datum ASC, cas ASC WHERE workid='".$id."' ";
						mysql_query("SET NAMES utf8");
						$result = mysql_query($sql, $link);
					if ($result) 
				    {
						while ($row = mysql_fetch_assoc($result))
						{
							$id=$row['id'];
              $meno = $row['name']; 
							$priezvisko = $row['surname'];
              $popis = $row['text'];
              $mail = $row['email'];
							$cislo = $row['cislo'];
							$vybavene=$row['done'];
							?>
                <div class="vypis_fora">
								<span ><?php echo "$meno"; echo "  ";echo"$priezvisko"; ?><br/></span>
								<span>Popis:<?php echo"<b>$popis</b> "; ?><br/><br/></span>
								<span>tel. c.:<?php echo"<b>$cislo</b> "; ?><br/><br/></span>
								<span>email:<?php echo"<b>$mail</b> "; ?><br/><br/></span>
                <span><?php if($vybavene)echo "<i>vybavene</i>";
                            else echo "<i>nevybavene</i>"; ?></span><br/><br/><br/>
					<table>
          <tr><td>	<form  action="system.php" name="form2" method="post">
						<p><input type="hidden" name="akce" value="zmazFormular"/></p>
            <p><input type="hidden" name="id_formular" value="<?php echo "$id";?>"></p>
	  				<input class="button" name="zmaz_formular" type="submit" value="Zmaž" />
	       </form></td>
	       	
						</tr>
            </table>		
							</div>
							<?php
						}
						if (mysql_num_rows($result)==0){
							echo 'Nie su ziadne objednavky</br>';
						}
						mysql_free_result($result);
					}
					else 
				{
					echo '<p style="color: #FF0000;">Nastal problém pri spojení s databázou - ' . mysql_errno($link) . ': ' . mysql_error($link) . '</p>';
				}
		
		} // end vyber db
		mysql_close($link);

}
?>
<span class="linka"><?php echo "<a href=\"system.php?akce=formular&vybavene=1\">Zobraz vybavene</a>";?></span>
	<span class="linka"><?php echo "<a href=\"system.php?akce=formular&vybavene=0\">Zobraz nevybavene</a>";?></span><br/>
<?php  
}
else{//alebo zobrazi objednavkovy formular
?>

<h1>Objednavkovy formular: </h1>
<form action="system.php" name="form1" id="form1" method="post">
<p><input type="hidden" name="akce" value="addForm" /></p>

<br/><br/>
	<table cellspacing="20px">
     <tr>
        <th class="lavy">Meno: &nbsp &nbsp</th>
        <td class="pravy"><input class="register" type="text" name="meno" size="47" value="<?php if (isset($_POST['meno'])) {echo $_POST['meno'];}?>" alt="Nazov hry" /><br/></td>
      </tr><tr>  <th class="lavy">Priezvisko: &nbsp &nbsp</th>
        <td class="pravy"><input class="register" type="text" name="priezvisko" size="47" value="<?php if (isset($_POST['priezvisko'])) {echo $_POST['priezvisko'];}?>" alt="Nazov hry" /><br/></td>    
     </tr><tr>
        <th class="lavy">Popis prace: &nbsp &nbsp</th>
        <td class="pravy"><textarea class="register" cols="40" rows="10" name="popis"><?php if (isset($_POST['popis'])) {echo $_POST['popis'];}?></textarea><br/></td>	
     </tr><tr>
        <th class="lavy">email: &nbsp &nbsp</th>
        <td class="pravy"><input class="register" type="text" name="mail" size="47" value="<?php if (isset($_POST['mail'])) {echo $_POST['mail'];}?>" alt="Nazov hry" /><br/></td>
     </tr><tr>   <th class="lavy">tel. c.: &nbsp &nbsp</th>
        <td class="pravy"><input class="register" type="text" name="cislo" size="47" value="<?php if (isset($_POST['cislo'])) {echo $_POST['cislo'];}?>" alt="Nazov hry" /><br/></td>
        
        </tr>
        
        <tr>
        <th colspan="2" class="pravy"><input class="button" name="submit" type="submit" id="submit" value="Odosli formular" /></th>
     </tr>
	
    </table>
</form>	
	
<?php
}
?>

</p>

				</div>
				<div class="clear"></div>





<?php
}

//zobrazi objednavky adminovy vsetky
function ZobrazFormular()
{
?>
</div><!--end welcome--> 
				<div id="content">
</br>
<p>
<?php if (isset($_SESSION['admin']) && ($_SESSION['admin']==1) ) 
{
	$link = mysql_connect();
		if ($link) 
		{
			if (mysql_select_db()) 
			{
				$sql = "SELECT * FROM form ";
				//	$sql = "SELECT * FROM forum ORDER BY datum ASC, cas ASC WHERE workid='".$id."' ";
						mysql_query("SET NAMES utf8");
						$result = mysql_query($sql, $link);
					if ($result) 
				    {
						while ($row = mysql_fetch_assoc($result))
						{
							$id=$row['id'];
              $meno = $row['name']; 
							$priezvisko = $row['surname'];
              $popis = $row['text'];
              $mail = $row['email'];
							$cislo = $row['cislo'];
							$vybavene=$row['done'];
							?>
<div class="vypis_fora">
								<span ><?php echo "$meno"; echo "  ";echo"$priezvisko"; ?><br/></span>
								<span>Popis:<?php echo"<b>$popis</b> "; ?><br/><br/></span>
								<span>tel. c.:<?php echo"<b>$cislo</b> "; ?><br/><br/></span>
								<span>email:<?php echo"<b>$mail</b> "; ?><br/><br/></span>
                <span><?php if($vybavene)echo "<i>vybavene</i>";
                            else echo "<i>nevybavene</i>"; ?></span><br/><br/><br/>
					<table>
          <tr><td>	<form  action="system.php" name="form2" method="post">
						<p><input type="hidden" name="akce" value="zmazFormular"/></p>
            <p><input type="hidden" name="id_formular" value="<?php echo "$id";?>"></p>
	  				<input class="button" name="zmaz_formular" type="submit" value="Zmaž" />
	       </form></td>
	       	<td><form action="system.php" name="form3" method="post">
						<p><input type="hidden" name="akce" value="vybavFormular"/></p>
            <p><input type="hidden" name="id_formular" value="<?php echo "$id";?>"></p>
	  				<input class="button" name="vybav" type="submit" value="Vybavený" />
	       </form></td>
						</tr>
            </table>		
							</div>
							<?php
						}
						if (mysql_num_rows($result)==0){
							echo 'Nie su ziadne objednavky</br>';
						}
						mysql_free_result($result);
					}
					else 
				{
					echo '<p style="color: #FF0000;">Nastal problém pri spojení s databázou - ' . mysql_errno($link) . ': ' . mysql_error($link) . '</p>';
				}
		
		} // end vyber db
		mysql_close($link);


}
?>

	<span class="linka"><?php echo "<a href=\"system.php?akce=formular&vybavene=1\">Zobraz vybavene</a>";?></span>
	<span class="linka"><?php echo "<a href=\"system.php?akce=formular&vybavene=0\">Zobraz nevybavene</a>";?></span><br/>
<?php  
}
else{//tu som pridala isset
?>

<h1>Objednavkovy formular: </h1>
<form action="system.php" name="form1" id="form1" method="post">
<p><input type="hidden" name="akce" value="addForm" /></p>

<br/><br/>
	<table cellspacing="20px">
     <tr>
        <th class="lavy">Meno: &nbsp &nbsp</th>
        <td class="pravy"><input class="register" type="text" name="meno" size="47" value="<?php if (isset($_POST['meno'])) {echo $_POST['meno'];}?>" alt="Nazov hry" /><br/></td>
      </tr><tr>  <th class="lavy">Priezvisko: &nbsp &nbsp</th>
        <td class="pravy"><input class="register" type="text" name="priezvisko" size="47" value="<?php if (isset($_POST['priezvisko'])) {echo $_POST['priezvisko'];}?>" alt="Nazov hry" /><br/></td>    
     </tr><tr>
        <th class="lavy">Popis prace: &nbsp &nbsp</th>
        <td class="pravy"><textarea class="register" cols="40" rows="10" name="popis"><?php if (isset($_POST['popis'])) {echo $_POST['popis'];}?></textarea><br/></td>	
     </tr><tr>
        <th class="lavy">email: &nbsp &nbsp</th>
        <td class="pravy"><input class="register" type="text" name="mail" size="47" value="<?php if (isset($_POST['mail'])) {echo $_POST['mail'];}?>" alt="Nazov hry" /><br/></td>
     </tr><tr>   <th class="lavy">tel. c.: &nbsp &nbsp</th>
        <td class="pravy"><input class="register" type="text" name="cislo" size="47" value="<?php if (isset($_POST['cislo'])) {echo $_POST['cislo'];}?>" alt="Nazov hry" /><br/></td>
        
        </tr>
        
        <tr>
        <th colspan="2" class="pravy"><input class="button" name="submit" type="submit" id="submit" value="Odosli formular" /></th>
     </tr>
	
    </table>
</form>	
	
<?php
}
?>

</p>

				</div>
				<div class="clear"></div>





<?php
}


//zobrazi objednavky adminovy nevybavene
function ZobrazFormular0()
{
?>
</div><!--end welcome--> 
				<div id="content">
</br>
<p>
<?php if ($_SESSION['admin']) 
{
	$link = mysql_connect();
		if ($link) 
		{
			if (mysql_select_db()) 
			{
				$sql = "SELECT * FROM form WHERE done='0' ";
				//	$sql = "SELECT * FROM forum ORDER BY datum ASC, cas ASC WHERE workid='".$id."' ";
						mysql_query("SET NAMES utf8");
						$result = mysql_query($sql, $link);
					if ($result) 
				    {
						while ($row = mysql_fetch_assoc($result))
						{
							$id=$row['id'];
              $meno = $row['name']; 
							$priezvisko = $row['surname'];
              $popis = $row['text'];
              $mail = $row['email'];
							$cislo = $row['cislo'];
							$vybavene=$row['done'];
							?>
<div class="vypis_fora">
								<span ><?php echo "$meno"; echo "  ";echo"$priezvisko"; ?><br/></span>
								<span>Popis:<?php echo"<b>$popis</b> "; ?><br/><br/></span>
								<span>tel. c.:<?php echo"<b>$cislo</b> "; ?><br/><br/></span>
								<span>email:<?php echo"<b>$mail</b> "; ?><br/><br/></span>
                <span><?php if($vybavene)echo "<i>vybavene</i>";
                            else echo "<i>nevybavene</i>"; ?></span><br/><br/><br/>
					<table>
          <tr><td>	<form  action="system.php" name="form2" method="post">
						<p><input type="hidden" name="akce" value="zmazFormular"/></p>
            <p><input type="hidden" name="id_formular" value="<?php echo "$id";?>"></p>
	  				<input class="button" name="zmaz_formular" type="submit" value="Zmaž" />
	       </form></td>
	       	<td><form action="system.php" name="form3" method="post">
						<p><input type="hidden" name="akce" value="vybavFormular"/></p>
            <p><input type="hidden" name="id_formular" value="<?php echo "$id";?>"></p>
	  				<input class="button" name="vybav" type="submit" value="Vybavený" />
	       </form></td>
						</tr>
            </table>		
							</div>
							<?php
						}
						if (mysql_num_rows($result)==0){
							echo 'Nie su ziadne objednavky</br>';
						}
						mysql_free_result($result);
					}
					else 
				{
					echo '<p style="color: #FF0000;">Nastal problém pri spojení s databázou - ' . mysql_errno($link) . ': ' . mysql_error($link) . '</p>';
				}
		
		} // end vyber db
		mysql_close($link);

}
?>

<span class="linka"><?php echo "<a href=\"system.php?akce=formular&vybavene=1\">Zobraz vybavene</a>";?></span>
	<span class="linka"><?php echo "<a href=\"system.php?akce=formular&vybavene=0\">Zobraz nevybavene</a>";?></span><br/>
<?php  
}
else{//tu som pridala isset
?>

<h1>Objednavkovy formular: </h1>
<form action="system.php" name="form1" id="form1" method="post">
<p><input type="hidden" name="akce" value="addForm" /></p>

<br/><br/>
	<table cellspacing="20px">
     <tr>
        <th class="lavy">Meno: &nbsp &nbsp</th>
        <td class="pravy"><input class="register" type="text" name="meno" size="47" value="<?php if (isset($_POST['meno'])) {echo $_POST['meno'];}?>" alt="Nazov hry" /><br/></td>
      </tr><tr>  <th class="lavy">Priezvisko: &nbsp &nbsp</th>
        <td class="pravy"><input class="register" type="text" name="priezvisko" size="47" value="<?php if (isset($_POST['priezvisko'])) {echo $_POST['priezvisko'];}?>" alt="Nazov hry" /><br/></td>    
     </tr><tr>
        <th class="lavy">Popis prace: &nbsp &nbsp</th>
        <td class="pravy"><textarea class="register" cols="40" rows="10" name="popis"><?php if (isset($_POST['popis'])) {echo $_POST['popis'];}?></textarea><br/></td>	
     </tr><tr>
        <th class="lavy">email: &nbsp &nbsp</th>
        <td class="pravy"><input class="register" type="text" name="mail" size="47" value="<?php if (isset($_POST['mail'])) {echo $_POST['mail'];}?>" alt="Nazov hry" /><br/></td>
     </tr><tr>   <th class="lavy">tel. c.: &nbsp &nbsp</th>
        <td class="pravy"><input class="register" type="text" name="cislo" size="47" value="<?php if (isset($_POST['cislo'])) {echo $_POST['cislo'];}?>" alt="Nazov hry" /><br/></td>
        
        </tr>
        
        <tr>
        <th colspan="2" class="pravy"><input class="button" name="submit" type="submit" id="submit" value="Odosli formular" /></th>
     </tr>
	
    </table>
</form>	
	
<?php
}
?>

</p>

				</div>
				<div class="clear"></div>





<?php
}

function ZobrazPridanyFormular(){
?>
</div><!--end welcome--> 
				<div id="content">
</br>
<p>
</br></br></br></br></br></br>
<h1>Vas formular bol uspesne pridany! </h1>
</br></br></br></br></br></br></br></br></br></br></br></br>
</p>

				</div>
				<div class="clear"></div>





<?php
}

//zobrazi kontakt

function ZobrazKontakt(){
?>
</div> <!--end welcome-->
				<div id="content">
</br>
<p >
<img src="fotoMartin.jpg" alt="Pic 1" style="margin-left: 150px;" />
 <p style="text-align: center;"><b>Martin Capek</b></p>
 <p style="text-align: center;"> <b>ČADEČKA U KRÁLOV 2193</br> O22 O1 ČADCA</b></p>
  <p style="text-align: center;"><b>IČO-43 489 079</b></p>           

 <p style="text-align: center;">tel. c : <b> 0908 815 270</b></p>
 <p style="text-align: center;">email:<b> martascask@gmail.com</b></p>


</p>

				</div>
				<div class="clear"></div>

<?php
}
//========================
// formular na registraciu
function ZobrazRegistraciu()
{
?>

</div> <!--end welcome-->
				<div id="content">
</br>
<p>
<h1>Registracia: </h1>
<form action="system.php" name="form1" id="form1" method="post">
<p><input type="hidden" name="akce" value="insert" /></p>
<br/><br/>
	<table cellspacing="20px">
     <tr>
        <th class="lavy">Meno: &nbsp &nbsp</th>
        <td class="pravy"><input class="register" type="text" name="meno" size="47" value="<?php if (isset($_POST['meno'])) {echo $_POST['meno'];}?>" alt="meno" /><br/></td>
      </tr><tr>  <th class="lavy">Priezvisko: &nbsp &nbsp</th>
        <td class="pravy"><input class="register" type="text" name="priezvisko" size="47" value="<?php if (isset($_POST['priezvisko'])) {echo $_POST['priezvisko'];}?>" alt="priezvisko" /><br/></td>    
     </tr><tr>
        <th class="lavy">login: &nbsp &nbsp</th>
        <td class="pravy"><input class="register" type="text" name="username" size="47" value="<?php if (isset($_POST['username'])) {echo $_POST['username'];}?>" alt="username" /><br/></td>
      </tr><tr>
        <th class="lavy">heslo: &nbsp &nbsp</th>
        <td class="pravy"><input class="register" type="password" name="heslo" size="47" value="" alt="heslo" /><br/></td>
      </tr><tr>
        <th class="lavy">overenie hesla: &nbsp &nbsp</th>
        <td class="pravy"><input class="register" type="password" name="overheslo" size="47" value="" alt="overenie hesla" /><br/></td>
      </tr><tr>
        <th class="lavy">email: &nbsp &nbsp</th>
        <td class="pravy"><input class="register" type="text" name="email" size="47" value="<?php if (isset($_POST['email'])) {echo $_POST['email'];}?>" alt="email" /><br/></td>
     </tr>
        
        <tr>
        <th colspan="2" class="pravy"><input class="button" name="submit" type="submit" id="submit" value="Potvrd" /></th>
     </tr>
     <tr>
        <th class="lavy"><a href="index.php">Prihlásenie</a></th>
        
     </tr>
	
    </table>
</form>	

</p>

				</div>
				<div class="clear"></div>
		
<?php
}

//========================
//formular na prihlasenie

function ZobrazPrihlasenie()
{
if (isset($_SESSION['logged'])) {ZobrazOdhlasenie();}else{//tu som pridala isset
?>


		
<p><!-- Start of User Login -->

		<div class="box_container">
		<div id="userlogin">

			<h2><span>User Login</span></h2>

			<form action="system.php" name="form2" id="form2" method="post">
<p><input type="hidden" name="akce" value="naloguj" /></p>
				<div class="form_field">
				<strong>Username</strong>
				<input  type="text" name="username" size="30" value="<?php if (isset($_POST['username'])) {echo $_POST['username'];}?>" alt="Username"  />
				</div>

				<div class="clearthis">&nbsp;</div>

				<div class="form_field">
				<strong>Password</strong>
				<input name="password" type="password" size="20" maxlength="20" value="" alt="Heslo" />
				</div>

				<div class="clearthis">&nbsp;</div>

				<div class="form_field">
				<input class="button" name="submit" type="submit" id="submit" value="Prihlás" />
				</div>

			</form>

			<div id="link-password">
			<?php echo "<a href=\"system.php?akce=showresetpw\">Zabudol som heslo</a>";?>
			</div>
			<div id="link-password">
			<?php echo "<a href=\"system.php?akce=new\">Chcem sa registrovať</a>";?>
			</div>

		</div>
		</div>

		
</p>
		

<?php
	}//end else
  
  } 



function ZobrazOdhlaseniePridanie()
{
//ZobrazPrihlasenie();
if (isset($_SESSION['logged'])) {ZobrazOdhlasenie();}

if (isset($_SESSION['admin']) && ($_SESSION['admin']==1) ){//tu som pridala isset
?>


		
<p><!-- Start of User Login -->

		<div class="box_container">
		<div id="userlogin">

			<div id="link-password">
			<?php echo "<a href=\"system.php?akce=pridanie\">Pridat pracu</a>";?>
			</div>
			
		</div>
		</div>

		
</p>
		

<?php
	}//end else
  
  } 
  
  function ZobrazOdhlaseniePridanieFoto()
{
if (isset($_SESSION['logged'])) {ZobrazOdhlasenie();}

if (isset($_SESSION['admin']) && ($_SESSION['admin']==1) ){//tu som pridala isset
?>


		
<p><!-- Start of User Login -->

		<div class="box_container">
		<div id="userlogin">

			<div id="link-password">
			<?php echo "<a href=\"system.php?akce=pridanieFoto\">Pridat foto</a>";?>
			</div>
			
		</div>
		</div>

		
</p>
		

<?php
	}//end else
  
  } 

  
  
  function ZobrazOdhlaseniePridanieCertifikatu()
{
if (isset($_SESSION['logged'])) {ZobrazOdhlasenie();}


if (isset($_SESSION['admin']) && ($_SESSION['admin']==1) ){//tu som pridala isset
?>


		
<p><!-- Start of User Login -->

		<div class="box_container">
		<div id="userlogin">

			<div id="link-password">
			<?php echo "<a href=\"system.php?akce=pridanie_certifikatu\">Pridat certifikat</a>";?>
			</div>
			
		</div>
		</div>

		
</p>
		

<?php
	}//end else
  
  }
function ZobrazPridaniePrace()
{if ($_SESSION['admin']) {
?>

</div> <!--end welcome-->
				<div id="content">
</br>
<p>
<h1>Pridanie prace: </h1>
<form name="form1" id="form1" enctype="multipart/form-data" action="system.php" method="POST">
<p><input type="hidden" name="akce" value="addwork" /></p>
<br/><br/>
	<table cellspacing="20px">
     <tr>
        <th class="lavy">Nazov: &nbsp &nbsp</th>
        <td class="pravy"><input class="register" type="text" name="nazov" size="47" value="<?php if (isset($_POST['nazov'])) {echo $_POST['nazov'];}?>" alt="nazov" /><br/></td>
      </tr><tr>  <th class="lavy">Popis kratky: &nbsp &nbsp</th>
        <td class="pravy"><textarea class="register" cols="40" rows="10" name="text1" alt="text1"><?php if (isset($_POST['text1'])) {echo $_POST['text1'];}?>  </textarea><br/></td>    
     </tr><tr>
        <th class="lavy">Popis dlhy: &nbsp &nbsp</th>
        <td class="pravy"><textarea class="register" cols="40" rows="10" name="text2" alt="text2"><?php if (isset($_POST['text2'])) {echo $_POST['text2'];}?>  </textarea><br/></td>
      </tr><tr>
        <th class="lavy">Obrazok 1: &nbsp &nbsp</th>
        <td class="pravy"><input class="register" type="file" name="obr1"  /><br/></td>
      </tr><tr>
        <th class="lavy">Obrazok 2: &nbsp &nbsp</th>
        <td class="pravy"><input class="register" type="file" name="obr2"  /><br/></td>
      </tr><tr>
        <th class="lavy">Obrazok 3: &nbsp &nbsp</th>
        <td class="pravy"><input class="register" type="file" name="obr3"  /><br/></td>
     </tr>
        
        <tr>
        <th colspan="2" class="pravy"><input class="button" name="submit" type="submit" id="submit" value="Pridaj" /></th>
     </tr>
     
    </table>
</form>	

</p>

				</div>
				<div class="clear"></div>
		
<?php
}//end if

}


//======================================formular pri zabudnuti hesla
function ZobrazObnovenie()
{
?>
</div> <!--end welcome-->
				<div id="content">
</br>
<p>
<h1>Obnovenie hesla:</h1>
Zadaj prosím svoj login a email pre kontrolu - príde Ti nové heslo.<br/><br/>
<form action="system.php" method="post">
    <p><input type="hidden" name="akce" value="resetpw" /></p>
<br/><br/>
	<table cellspacing="20px">
     <tr>
        <th class="lavy">login: &nbsp &nbsp</th>
        <td class="pravy"><input class="register" type="text" name="username" size="47" value="<?php if (isset($_POST['username'])) {echo $_POST['username'];}?>" alt="username" /><br/></td>
      </tr><tr>
        <th class="lavy">email: &nbsp &nbsp</th>
        <td class="pravy"><input class="register" type="text" name="email" size="47" value="<?php if (isset($_POST['email'])) {echo $_POST['email'];}?>" alt="email" /><br/></td>
     </tr>
        
        <tr>
        <th colspan="2" class="pravy"><input class="button" name="submit" type="submit" id="submit" value="Resetuj" /></th>
     </tr>
     
	
    </table>
</form>	

</p>

				</div>
				<div class="clear"></div>
			

<?php
}
//========================
// zmena hesla
function ZobrazZmena()
{
ZobrazOdhlasenie();
?>

</div> <!--end welcome-->
				<div id="content">
        <h1>Zmena hesla:</h1><br/>
<script src="scripty/registracia.js" type="text/javascript"></script>
<form action="system.php" method="post">
    <p><input type="hidden" name="akce" value="changepw" /></p>
    <table>
		<tr>
			<th class="lavy">Súčasné heslo: &nbsp &nbsp</th>
			<td class="pravy"><input class="register" name="hesloold" type="password" size="20" maxlength="20" value="" alt="Heslo"/></td>
		</tr><tr>
			<td colspan="2">&nbsp;</td>
	     </tr><tr>
			<th class="lavy">Nové heslo: &nbsp &nbsp</th>
			<td class="pravy"><input class="register" name="heslonew1" type="password" size="20" maxlength="20" value="" alt="Heslo"/></td>
		</tr><tr>
	        <th class="lavy">Kontrola hesla: &nbsp &nbsp</th>
	        <td class="pravy"><input class="register" name="heslonew2" type="password" size="20" maxlength="20" value="" alt="Heslo"/></td>
		</tr><tr>
			 <td colspan="2" class="pravy"><input name="submit3" class="button" type="submit" value="Zmeň heslo" alt="zmeniť heslo" /></td>
		</tr>
	</table>
</form>
</br>
</br>
</br>
</br>
</br>
</br>
</br>
</br>
</br>
</br>
</br>
</div>
	<div class="clear"></div>
<?php
}





//formular na odhlasenie

function ZobrazOdhlasenie()
{
?>
	
  <p><!-- Start of User Logout -->
<div class="box_container">
<div id="userlogin"><?php echo'Prihlaseny ako :  ' . $_SESSION['username'] ;?>
	    
		 <div id="link-password">
			<?php echo "<a href=\"system.php?akce=showchangepw\">Zmenit heslo</a>";?>
			</div>
				
		<form action="system.php" name="form2" method="post">
    <p><input type="hidden" name="akce" value="odloguj"/></p>
    <input class="button" name="submit2" type="submit" id="submit2" value="Odhlás" />
	</form>
</div>

		<!-- End of User Logout -->
		</div>
</p>


<?php
}

//prida uzivatela pri registracii

function PridajUser()
{

// bezp. kontrola
    $_POST["username"]=addslashes(htmlspecialchars($_POST["username"]));
    $_POST["meno"]=addslashes(htmlspecialchars($_POST["meno"]));
    $_POST["priezvisko"]=addslashes(htmlspecialchars($_POST["priezvisko"]));
	if ($_POST["heslo"]!=""){$_POST["heslo"]=MD5($_POST["heslo"]);}
	if ($_POST["overheslo"]!=""){$_POST["overheslo"]=MD5($_POST["overheslo"]);}
    $_POST["heslo"]=addslashes(htmlspecialchars($_POST["heslo"]));
    $_POST["overheslo"]=addslashes(htmlspecialchars($_POST["overheslo"]));
    $_POST["email"]=addslashes(htmlspecialchars($_POST["email"]));
    $v_poradku = 1;

    if (!eregi("^[a-zA-Z_][a-zA-Z0-9_]{1,}$",$_POST['username'])) //kontrolujem  username
    {
    	  $CHYBA .= "<li>Login - musí obsahovať aspoň dva znaky -> len písmena, čísla a podtržník, nezačína číslom</li><br />";
    	  $v_poradku = 0;
    }
    else
    {
    	  $_username = strtolower($_POST['username']);
    }
    if (!eregi("^[a-zA-Z][a-zA-Z]{1,}$",$_POST['meno'])) //kontrolujem  username
    {
    	  $CHYBA .= "<li>Meno - musí obsahovať aspoň dva znaky -> len písmena</li><br />";
    	  $v_poradku = 0;
    }
    else
    {
    	  $_meno = strtolower($_POST['meno']);
    }
if (!eregi("^[a-zA-Z][a-zA-Z]{1,}$",$_POST['priezvisko'])) //kontrolujem  username
    {
    	  $CHYBA .= "<li>Priezvisko - musí obsahovať aspoň dva znaky -> len písmena</li><br />";
    	  $v_poradku = 0;
    }
    else
    {
    	  $_priezvisko = strtolower($_POST['priezvisko']);
    }


    if (($_POST['email'] == "") || (!ereg("^[a-zA-Z0-9\._]{2,}@[a-zA-Z0-9\._]+\.([a-z]{2}|aero|arpa|asia|biz|cat|com|coop|edu|gov|info|int|jobs|mobi|mil|museum|name|net|org|pro|root|tel|travel)$",$_POST['email'])))  // kontrolujem e-mail -> znak znak@znak. koncovka
    {
    	  $CHYBA .= "<li>Email - nesprávny tvar adresy</li><br />";
     	  $v_poradku = 0;
    }
    else
    {
    	  $_email = $_POST['email'];
    }

    $is_new_ok = ( (strcmp($_POST['heslo'],$_POST['overheslo']) == 0) && (eregi("^[a-f0-9]{32,32}$",$_POST['overheslo'])) );  //kontrolujem heslo
	if (($_POST['heslo'] =="") || (!$is_new_ok))
    {
        $CHYBA .= "<li>Heslo - heslá se nezhodujú, alebo nie sú zadané<br />";
    	  $v_poradku = 0;
    }
    else
    {
        $_password = $_POST['heslo'];
    }

    if ($v_poradku == 1)  // test na pritomnost vsetkych povinnych poli
    {
        $link = mysql_connect();
		if ($link) 
		{
			if (mysql_select_db()) 
	{
				$sql = "SELECT userid FROM users WHERE username='$_username'";
					$result = mysql_query($sql, $link);
					if (mysql_num_rows($result)==0)   //user s takym menom este neexistuje = OK
					{
						$sql="INSERT INTO users (username, meno, priezvisko ,userid,  password, email, admin) VALUES ('$_username','$_meno' ,'$_priezvisko', NULL,  '$_password', '$_email', '0')";
						mysql_query("SET CHARACTER SET utf8");
						mysql_query("SET NAMES utf8");
						mysql_query($sql, $link);
						mail_registracia($_email, $_username);

                echo '<div class="obsah">Registrácia prebehla úspešne.</div><br />';
						
					}
					else echo'<div class="obsah" style="color: #FF0000;"> Tebou zvolená prezývka - '. $_username.' - je už obsadená! Zvoľ si inú.</div>';
					ZobrazRegistraciu(); // vratit, ->iny login
			}
			else 
				{
					echo '<div class="obsah" style="color: #FF0000;">Užívateľ NEbol pridaný, lebo nastal problém pri zápise do databázy- ' . mysql_errno($link) . ': ' . mysql_error($link) . 'Skús to prosím znovu</div>';
					ZobrazRegistraciu(); //vratit ->chyba pri vkladany
				}
		
		} // end vyber db
		mysql_close($link);
	} elseif (isset($_POST['submit'])) {
		echo '<div class="obsah" style="color: #FF0000;">Vo formuláry sa našli chyby!<br />Opravte nasledujúce položky:<br /><br />'.$CHYBA.'</div>';
		ZobrazRegistraciu();//vratit ->nespravne vyplnene
	}
	
}

//========================
// nalogovanie uzivatela -> spracovanie prihlasenia
function Naloguj()
{

if (isset($_POST['username']) && ($_POST['username'] != "") && isset($_POST['password']) && ($_POST['password'] != "")) 
	{ 
	$link = mysql_connect();
		if ($link) 
		{
			if (mysql_select_db()) 
			{   
			    if ($_POST["password"]!=""){$_POST["password"]=MD5($_POST["password"]);}
				$_POST['password']=addslashes(htmlspecialchars($_POST['password']));
				$_POST["username"]=addslashes(htmlspecialchars($_POST["username"]));
				$_POST["username"] = strtolower($_POST["username"]);
				$sql ="SELECT * FROM users WHERE username='" . $_POST['username'] . "' AND password='" . $_POST['password'] . "' LIMIT 1;";
				$result = mysql_query($sql, $link);
				if ($result) 
				{
					if ($row = mysql_fetch_assoc($result))
					{
						$_SESSION['username'] = $row['username']; 
						$_SESSION['admin'] = $row['admin']; 
						$_SESSION['logged'] = true;
						ZobrazOdhlasenie();
					}
					else
						{
						echo '<p style="color: #FF0000;">Zadal si nesprávne meno alebo heslo. Skús sa prihlásiť znova</p>';
						ZobrazPrihlasenie();
						}
					mysql_free_result($result);
				}
				else
					{
					echo '<p style="color: #FF0000;">Chyba pri zadávaní údajov z databázy - ' . mysql_errno($link) . ': ' . mysql_error($link) . '</p>';
					ZobrazPrihlasenie();
					}
			} 
			else 
				{ 
				echo '<p style="color: #FF0000;">Nepodarilo sa vybrať databázu</p>';
				ZobrazPrihlasenie();
				} // end vyber db
			mysql_close($link);
		}
			else
			{ 
			echo '<p style="color: #FF0000;">Nepodarilo sa spojiť s databázou</p>';
			ZobrazPrihlasenie();
			} // end spojenie s db 
	}
}

function Odloguj()
{
    unset($_SESSION["logged"]);
     unset($_SESSION["username"]);
    unset($_SESSION["admin"]);
	$_SESSION = array();
	//session_destroy();
	ZobrazPrihlasenie();
}

//========================
//vegeneruje nahodny retazec
function RandStr($n)
{
    $znaky = 'abcdefghijklmnoprstuvxwyzABCDEFGHIJKLMNOPRSTUVXWYZ0123456789';
    $max = strlen($znaky)-1;
    $slovo = null;
    for($i=0; $i < $n; $i++) {
        $slovo .= $znaky{mt_rand(0, $max)};  }
    return $slovo;
}
// resetuje uzivatelovi heslo
function ResetHeslo()
{
	$_POST["username"]=addslashes(htmlspecialchars($_POST["username"]));
	$_POST['username']= strtolower($_POST['username']);
    $_POST["email"]=addslashes(htmlspecialchars($_POST["email"])); 
    
	$link = mysql_connect();
		if ($link) 
		{
			if (mysql_select_db()) 
			{   
				$sql ="SELECT * 
				       FROM users 
                       WHERE username='" . $_POST['username'] . "' AND email='" . $_POST['email'] . "' LIMIT 1;";
				$result = mysql_query($sql, $link);
				if ($result) 
				{
					$new_pw = RandStr(8);
    	            $hash_pw = MD5($new_pw);
					$sql1 ="UPDATE users 
				       SET password='$hash_pw' 
                       WHERE username='" . $_POST['username'] . "'";
					mysql_query("SET CHARACTER SET utf8");
					mysql_query("SET NAMES utf8");   
					$result1 = mysql_query($sql1, $link);
					if ($result1)
					{
						 mail_reset($_POST["email"], $_POST["username"], $new_pw);
                         echo '<p>Nové heslo ti bolo zaslané na mail.</p>';
                         ZobrazPrihlasenie();
					}
					else{
						  echo '<p style="color: #FF0000;">Chyba, heslo sa nepodarilo resetovať, skús to prosím znovu</p>';
                          ZobrazObnovenie();
					}
				}
				else
					{
					echo '<p style="color: #FF0000;">Bola zadaná neplatná kombinácia užívateľa a emailu</p>';
					ZobrazObnovenie();
					}
			} 
			else 
				{ 
				echo '<p style="color: #FF0000;">Nepodarilo sa vybrať databázu</p>';
				ZobrazObnovenie();
				} // end vyber db
			mysql_close($link);
		}
}

// zmena hesla na ziadost uzivatela
function ZmenaHeslo()
{
    // bezp. kontrola
	if ($_POST["hesloold"]!=""){$_POST["hesloold"]=MD5($_POST["hesloold"]);}
	if ($_POST["heslonew1"]!=""){$_POST["heslonew1"]=MD5($_POST["heslonew1"]);}
	if ($_POST["heslonew2"]!=""){$_POST["heslonew2"]=MD5($_POST["heslonew2"]);}
    $_POST["hesloold"]=addslashes(htmlspecialchars($_POST["hesloold"]));
    $_POST["heslonew1"]=addslashes(htmlspecialchars($_POST["heslonew1"]));
	$_POST["heslonew2"]=addslashes(htmlspecialchars($_POST["heslonew2"]));
	$v_poradku = 1;
   
	$is_new_ok = ( (strcmp($_POST['heslonew1'],$_POST['heslonew2']) == 0) && (eregi("^[a-f0-9]{32,32}$",$_POST['heslonew2'])) );  //kontrolujem heslo
	if (($_POST['heslonew1'] =="")|| (!$is_new_ok))
    {
        $CHYBA .= "<li>Heslá se nezhodujú, alebo nie sú zadané<br />";
    	  $v_poradku = 0;
    }
	
	if (($_POST["hesloold"]==""))
	{
		$CHYBA .= "<li>Nezadal si staré heslo. <br />";
        $v_poradku = 0;
	}

	if ($v_poradku == 1)  // test na pritomnost vsetkych povinnych poli
    {
  $link = mysql_connect();
		if ($link) 
		{
			if (mysql_select_db()) 
			{
			    $sql ="SELECT * 
				       FROM users 
                       WHERE username='" . $_SESSION['username'] . "' AND password='" . $_POST['hesloold'] . "' LIMIT 1;";
				$result = mysql_query($sql, $link);
				if ($result) 
				{
					$sql1 ="UPDATE users
							SET password = '".$_POST['heslonew1']."'
							WHERE username = '".$_SESSION["username"]."'";
					mysql_query("SET CHARACTER SET utf8");
					mysql_query("SET NAMES utf8");		
					$result1 = mysql_query($sql1, $link);
					if ($result1)
					{
                         echo '<p>Heslo bolo úspešne zmenené</p>';
                         ZobrazPrihlasenie();
					}
					else{
						  echo '<p style="color: #FF0000;">Chyba, heslo sa nepodarilo zmeniť, skús to prosím znovu</p>';
                          ZobrazZmena();
					}
				}	
				else
					{
					echo '<p style="color: #FF0000;">Bolo zadané neplatné staré heslo</p>';
					ZobrazZmena();
					}
			}
			else 
				{
					echo '<div class="obsah" style="color: #FF0000;">Nastal problém pri zápise do databázy- ' . mysql_errno($link) . ': ' . mysql_error($link) . 'Skús to prosím znovu</div>';
					ZobrazZmena(); //vratit ->chyba pri vkladany
				}
		} 
		else 
		{ 
			echo '<p style="color: #FF0000;">Nepodarilo sa vybrať databázu</p>';
			ZobrazZmena();
		} // end vyber db
	mysql_close($link);
	}
	elseif (isset($_POST['submit3'])) {
		echo '<div class="obsah" style="color: #FF0000;">Vo formuláry sa našli chyby!<br />Oprav ich prosím:<br /><br />'.$CHYBA.'</div>';
         ZobrazZmena(); // vratit dotaznik
	}
}		
	
	
    


// posielanie mailu
function odosli_mail($komu, $predmet, $telo)
{
    $hlavicka = "From: admin www.castav.yw.sk <castav.yw.sk>\n";
    $hlavicka.= "MIME-Version: 1.0\n";
    $hlavicka.= "Content-Type: text/plain; charset=\"utf-8\"\n";
    $hlavicka.= "Content-Transfer-Encoding: base64\n";
    $hlavicka.= "Reply-To: iramka@gmail.com\n";
    $telo = Base64_Encode($telo);
    //$predmet = "?utf-8?B?".Base64_Encode($predmet)."?=";
    if(mail($komu, $predmet, $telo, $hlavicka))
        return TRUE;
    else
        return FALSE;
}
// posielanie mailu pri registracii
function mail_registracia($mail, $username)
{
$telo = "Ahoj,
úspešne si sa zaregistroval na stránkach www.castav.yw.sk pod menom $username. 
Teraz ti už nič nebráni prispievať do fóra.

Verím, že budeš so stránkami spokojný/á. 
admin - Marika Mitrengova";

    odosli_mail($mail, "Castav - registrácia", $telo);
}

// resetuje uzivatelovi heslo


function mail_reset($mail, $username, $heslo)
{
$telo = "Ahoj,
resetovanie tvojho hesla prebehlo úspešne. Nové heslo k loginu $username je

$heslo

pomocou tohto hesla sa teraz môžeš prihlásiť a v systéme si ho potom zmeniť.

S pozdravom admin = Marika Mitrengova"; 

    odosli_mail($mail, "Castav - Reset hesla", $telo);
}


?>


