	<?php if(@$error): ?>

		<div class="alert alert-dismissible alert-danger">

			<button type="button" class="close" data-dismiss="alert">×</button>

			<strong>Hata!</strong> <?=$errorText?>

		</div>

	<?php endif; ?>

	<?php if(@$success): ?>

		<div class="alert alert-dismissible alert-success">

			<button type="button" class="close" data-dismiss="alert">×</button>

			<strong>Başarılı!</strong> <?=$success?>

		</div>

	<?php endif; ?>



	<?php if(!route(3)): ?>


		<a href="<?=admin_url('appearence/pages/add')?>" class="btn btn-default" style="margin-bottom:20px;">Yeni Sayfa Oluştur</a>
		<div class="panel panel-default">

			<div class="panel-body" style="padding:0;">

				<table class="table" style="margin-bottom:0;">

					<thead>

						<tr>

							<th class="p-l" width="45%">Sayfa Başlığı</th>

							<th>Son Güncellenme Tarihi</th>

							<th></th>

						</tr>

					</thead>

					<tbody>

						<?php foreach($pages as $page): ?>

							<tr>

								<td><?=$page["page_title"]?></td>

								<td><?=str_date($page["page_date"])?></td>

								<td>

									<div class="pull-right">

										<a class="btn btn-xs btn-default" href="<?=admin_url('appearence/pages/edit/'. $page["id"])?>">Düzenle</a>
										<a class="btn btn-xs btn-default" onclick="delete_sayfa(<?=$page["id"];?>)" href="javascript:;" <?= ($page['page_lock'] == 1) ? "disabled" : null ?>>Sil</a>

									</div>

								</td>

							</tr>

						<?php endforeach; ?>

					</tbody>

				</table>

			</div>

		</div>
	<?php elseif(route(3) == "add"): ?>

		<div class="panel panel-default">
			<div class="panel-body">
				<form id="add_page" onsubmit="return false;" data-reset="1">
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon"><b>Sayfa Başlığı</b></span>
							<input type="text" class="form-control" name="page_title" id="blog_title">
						</div>
					</div>
					<div class="form-group">
						<textarea type="text" name="page_content" class="form-control" id="editor"></textarea>
					</div>
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon"><b>Sayfa Görünürlüğü</b></span>
							<select class="form-control" name="page_visibility">
								<option value="1">Herkese Açık</option>
								<option value="2">Sadece Üyeler</option>
								<option value="3">Herkese Kapalı</option>
							</select>
						</div>
					</div>
					<div class="form-group">
						<span class="input-group-addon"><b>SEO Önizleme</b></span>
					</div>
					<div class="google-preview">
					  	<div class="google-preview-title" id="google_preview_title">Burası SEO Sayfa Başlığınız</div>
					 	<div class="google-preview-link"><?=site('blog/')?><b id="google_preview_url">burasi_linkiniz</b></div>
					  	<div class="google-preview-description" id="google_preview_desc">...</div>
					</div>
					<div class="form-group">
						<span class="input-group-addon"><b>SEO Ayarları</b></span>
					</div>
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon"><b>URL</b></span>
							<input type="text" name="page_url"  id="blog_url" class="form-control">
						</div>
					</div>
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon"><b>SEO Başlık</b></span>
							<input type="text" name="seo[title]"  id="seo_title" class="form-control">
						</div>
					</div>
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon"><b>SEO Açıklaması</b></span>
							<textarea class="form-control"  id="seo_desc" name="seo[desc]"></textarea>
						</div>
					</div>
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon"><b>SEO Anahtar Kelimeler</b></span>
							<input type="text" name="seo[keyw]"  id="seo_keyw" class="form-control">
						</div>
					</div>

					<div class="form-group text-right">

						<a href="<?=admin_url('appearence/pages')?>" class="btn btn-warning">Sayfalara Geri Dön</a>

						<button type="submit" class="btn btn-success">Güncelle</button>

					</div>

				</form>

			</div>

		</div>

	<?php elseif(route(3) == "edit"): ?>

		<div class="panel panel-default">
			<div class="panel-body">
				<form id="update_page" onsubmit="return false;" data-reset="0">
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon"><b>Sayfa Başlığı</b></span>
							<input type="text" class="form-control" name="page_title" id="blog_title" value="<?=$page['page_title']?>" <?= ($page['page_lock'] == 1) ? "readonly=''" : null ?>>
						</div>
					</div>
					<div class="form-group">
						<textarea type="text" name="page_content" class="form-control" id="editor"><?=$page['page_content']?></textarea>
					</div>
					<?php if($page['page_lock'] != 1): ?>
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon"><b>Sayfa Görünürlüğü</b></span>
							<select class="form-control" name="page_visibility">
								<option <?= ($page['page_visibility'] == 1) ? "selected" : null ?> value="1">Herkese Açık</option>
								<option <?= ($page['page_visibility'] == 2) ? "selected" : null ?> value="2">Sadece Üyeler</option>
								<option <?= ($page['page_visibility'] == 3) ? "selected" : null ?> value="3">Herkese Kapalı</option>
							</select>
						</div>
					</div>
					<?php endif; ?>
					<div class="form-group">
						<span class="input-group-addon"><b>SEO Önizleme</b></span>
					</div>
					<div class="google-preview">
					  	<div class="google-preview-title" id="google_preview_title"><?=$page['page_title']?></div>
					 	<div class="google-preview-link"><?=site($siteLinks['page']['url'].'/')?><b id="google_preview_url"><?=$page['page_url']?></b></div>
					  	<div class="google-preview-description" id="google_preview_desc"><?=$seo['desc']?></div>
					</div>
					<div class="form-group">
						<span class="input-group-addon"><b>SEO Ayarları</b></span>
					</div>
					<div class="form-group"> 
						<div class="input-group">
							<span class="input-group-addon"><b>URL</b></span>
							<input type="text" name="page_url"  id="page_url" class="form-control" value="<?=$page['page_url']?>"  <?=($page['page_lock'] == 1) ? "readonly=''" : null ?>>
						</div>
					</div>
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon"><b>SEO Başlık</b></span>
							<input type="text" name="seo[title]"  id="seo_title" class="form-control" value="<?=$seo['title']?>">
						</div>
					</div>
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon"><b>SEO Açıklaması</b></span>
							<textarea class="form-control"  id="seo_desc" name="seo[desc]"><?=$seo['desc']?></textarea>
						</div>
					</div>
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon"><b>SEO Anahtar Kelimeler</b></span>
							<input type="text" name="seo[keyw]"  id="seo_keyw" class="form-control" value="<?=$seo['keyw']?>">
						</div>
					</div>

					<input type="text" name="id" value="<?=$page['id']?>" style="display: none;">

					<div class="form-group text-right">

						<a href="<?=admin_url('appearence/pages')?>" class="btn btn-warning">Sayfalara Geri Dön</a>

						<button type="submit" class="btn btn-success">Güncelle</button>

					</div>

				</form>

			</div>

		</div>



	<?php endif; ?>

	<script src="<?=admin_public_url('assets/js/jquery.min.js')?>?v=<?=time()?>"></script>
		<script>

			$("#seo_title").change(function(){
				var seo_title 	= document.getElementById("seo_title");
				$('#google_preview_title').html(seo_title.value);
			});

			$("#blog_url").change(function(){
				var blog_url 	= document.getElementById("blog_url");
				$('#google_preview_url').html(blog_url.value);
			});

			$("#seo_desc").change(function(){
				var seo_desc 	= document.getElementById("seo_desc");
				$('#google_preview_desc').html(seo_desc.value);
			});

			function createSEOLink (link) {
			    var trMap = {
			        'çÇ':'c',
			        'ğĞ':'g',
			        'şŞ':'s',
			        'üÜ':'u',
			        'ıİ':'i',
			        'öÖ':'o'
			    };

			    for(var key in trMap) {
			        link = link.replace(new RegExp('['+key+']','g'), trMap[key]);
			    }
			    return  link.replace(/[^-a-zA-Z0-9\s]+/ig, '')
			                .replace(/\s/gi, "-")
			                .replace(/[-]+/gi, "-")
			                .toLowerCase();
			}

			$("#blog_title").change(function(){
				var blog_title 	= document.getElementById("blog_title");
				$('#blog_url').val(createSEOLink(blog_title.value));
				$('#google_preview_url').html(createSEOLink(blog_title.value));
			});

		</script>