<!DOCTYPE html>
<html lang="fr">

	<? include('blocks/d.head.html'); ?>

	<body>

		<? include('blocks/d.nav.html'); ?>

		<section>
			<? if(isset($new) AND $new==1) { ?>
				<form class="form" action="<?=$config['rel_root_folder']?>blog/new" method="post">
			<? } 
			else { ?>
				<form class="form" action="<?=$config['rel_root_folder']?>blog/<?=$blogArticle->permalink?>/edit" method="post">
			<? } ?>
			
				<h1>
					<select name="locale" id="locale">
						<? foreach($locales->objs as $locale) { ?>
							<option <?=$blogArticle->locale==$locale->name?'selected':''?> value="<?=$locale->name?>"><?=$locale->display_name?></option>
						<? } ?>
					</select>
					<input type="text" value="<?=$blogArticle->name?>" name="name" id="name" placeholder="Titre">
				</h1>

				<? if(isset($error) AND $error=="permalink") { ?>
					<p style="color: red;">L'URL sélectionnée est déjà prise.</p>
				<? } ?>

				<textarea rows="30" name="content" id="content" placeholder="Contenu de l'article"><?=$blogArticle->content?></textarea>

				<? if(isset($new) AND $new==1) { ?>
					<input type="text" value="<?=$blogArticle->permalink?>" name="permalink" id="permalink" placeholder="URL">
				<? } ?>

				<label for="is_commentable">
					<input type="checkbox" name="is_commentable" id="is_commentable"
					<? if($blogArticle->is_commentable == 't') { ?>
						checked
					<? } ?>
					/>
					<span>Autoriser les commentaires</span>
				</label>

				<input name="submit" id="submit" type="submit" value="Envoyer">
			</form>
		</section>

		<script type="text/javascript">
$( "#name" ).keyup(function() {
  permalink = $( "#name" ).val();
  permalink = permalink.replace(/ /g,'_');
  permalink = permalink.toLowerCase();
  permalink = permalink.replace(/[^a-z0-9_]/g,'-');
  permalink = permalink.replace(/[_-]+$/g,'');
  $( "#permalink" ).val(permalink);
});
$( "#name" ).change(function() {
  permalink = $( "#name" ).val();
  permalink = permalink.replace(/ /g,'_');
  permalink = permalink.toLowerCase();
  permalink = permalink.replace(/[^a-z0-9_]/g,'-');
  permalink = permalink.replace(/[_-]+$/g,'');
  $( "#permalink" ).val(permalink);
});
		</script>

		<? include('blocks/d.footer.html'); ?>

	</body>
</html>