<?

	session_start();
	include $_SERVER['DOCUMENT_ROOT']."/include/baza_danych.php";
	include $_SERVER['DOCUMENT_ROOT']."/include/check_login.php";
	include $_SERVER['DOCUMENT_ROOT']."/include/functions.php";

	if($_GET['alias']==NULL){
		$_GET['alias']=$_POST['alias'];
	}

   if($logged_in==1){

      if(isset($_POST['tresc']) or isset($_POST['zapisz']) or isset($_POST['zapisz_i'])){

         $wykonaj = mysql_query ("SELECT * FROM ".$db_pref."tresc WHERE  alias='".$_GET['alias']."' and id='".$id_tresci."' and id_serwisu='".$_SESSION['ID_serwisu']."';");
      	$ile = mysql_num_rows($wykonaj);

      	if($ile!=0){
	      	$update_tresci = mysql_query("UPDATE ".$db_pref."tresc SET tresc='".$_POST['tresc']."' WHERE alias='".$_GET['alias']."' and id='".$id_tresci."' and id_serwisu='".$_SESSION['ID_serwisu']."';");
    		}

      	if($ile==0){
	         $zapytanie = "INSERT INTO ".$db_pref."tresc (id_strony,subgo,alias,tresc,id_serwisu,przez_kogo) VALUES ('".$id_strony."','".$_POST['subgo']."','".$alias."','".$_POST['tresc']."','".$_SESSION['ID_serwisu']."','".$_SESSION['u_id']."')";
	         $wykonaj = mysql_query($zapytanie);
    		}

   		if (isset($_GET{close})){
				echo'<script type="text/javascript">parent.Odswiez_strone();</script>';
			}

      }

		if(isset($edycja_html)){
			if($alias!=NULL and $id_tresci==NULL){
				$do_zamkniecia_okienko = $alias."_html";
			}else{
				$do_zamkniecia_okienko = $id_tresci."_html";
			}
		}

		$wykonaj = mysql_query ("SELECT tresc FROM ".$db_pref."tresc WHERE alias='".$_GET['alias']."' and id='".$id_tresci."' and id_serwisu='".$_SESSION['ID_serwisu']."';");
		$ile = mysql_num_rows($wykonaj);
		if($ile!=0){
			while($wiersz=mysql_fetch_array ($wykonaj)){
				$_POST['tresc'] = $wiersz['tresc'];
			}
		}

    	if(!isset($go)){
    		$go = 'strona-glowna';
    	}

	}


echo'
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
	<link rel="stylesheet" media="all" type="text/css" href="cms_style.css">
	';

	if(!isset($edycja_html)){
		echo'
			<!-- TinyMCE -->
			<script type="text/javascript" src="tiny_mce/tiny_mce.js"></script>
			<script type="text/javascript" src="tiny_mce/config.js"></script>
			<!-- /TinyMCE -->
		';
	}

	echo'</head><body>';

if($logged_in==1){

	$id_strony = mysql_result(mysql_query("SELECT id FROM ".$db_pref."strona WHERE alias='".$go."' and id_serwisu='".$_SESSION['ID_serwisu']."' LIMIT 1;"),0);

	if(isset($edycja_html)){
		$jesli_edycja_html = "&edycja_html=true";
	}

   echo'<form method="post" action="edycja_tresci.php?close=true'.$jesli_edycja_html.'" style="margin-top: 0px; margin-bottom: 0px" ACCEPT-CHARSET="iso-8859-2">';

   if($_POST['tresc']==null){ $_POST['tresc'] = 'Wpisz treść pola.'; }

	if(isset($edycja_html)){
		echo'
		   <div align="left" style="margin: 6px 0 4px 6px;">
				<input name="zapisz_i" type="image" value="zapisz zmiany" src="../include/cms/images/disk.png">
				<img src="../include/cms/images/cancel.png" alt="" onclick="javascript:parent.Windows.getWindow(\''.$do_zamkniecia_okienko.'\').close()" style="cursor: pointer;">
			</div>
		';
		echo'<textarea name="tresc" style="width: 100%; height: 420px">'.$_POST['tresc'].'</textarea>';
	}else{
		echo'<textarea name="tresc" style="width: 100%; height: 100%">'.$_POST['tresc'].'</textarea>';
	}

	echo'
	  	<input type="hidden" name="id_tresci" value="'.$id_tresci.'">
	  	<input type="hidden" name="id_strony" value="'.$id_strony.'">
	  	<input type="hidden" name="alias" value="'.$alias.'">
	  	<input type="hidden" name="go" value="'.$go.'">
	  	<input type="hidden" name="subgo" value="'.$subgo.'">
	</form>
	';

}else{ echo'<h2><font face="Tahoma">BRAK DOSTĘPU</h2>'; }
echo'</body></html>';
?>