Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //kontrola opravnenia
- if(empty($_SESSION['user_isAdmin'])){
- die("Uživatel nemá administrátorská práva <br /><a class=\"center\" href=\"index.php\">zpět</a>");
- }
- //zalozenie asociativneho pola
- $article = array (
- 'article_id' => '',
- 'user_id' => '',
- 'section' => '',
- 'title' => '',
- 'url' => '',
- 'description' => '',
- 'keywords' => '',
- 'content' => '',
- );
- //ak bolo nieco odoslané
- if($_POST){
- //ak článok nemá id tzn. je nový, tak ho pridám do DB
- if(!$_POST['article_id']){
- Db::query("
- INSERT INTO clanky(users_id, section, title, url, description, keywords, content)
- VALUES (?, ?, ?, ?, ?, ?, ?)
- ", $_POST['users_id'], $_POST['section'], $_POST['title'], $_POST['url'], $_POST['description'], $_POST['keywords'], $_POST['content']);
- }
- //ak má id, tak iba upravím v DB článok s daným id
- else{
- Db::query("
- UPDATE clanky
- SET title=?, url=?, description=?, keywords=?, content=?
- WHERE article_id=?
- ", $_POST['title'], $_POST['url'], $_POST['description'], $_POST['keywords'], $_POST['content'], $_POST['article_id']);
- }
- //ak mám nahratú titulku, tak ju uložím do súboru
- if(strlen($_FILES['file']['name'])>0){
- //povolene koncovky
- $allowedExts = array("gif", "jpeg", "jpg", "png");
- $temp = explode(".", $_FILES["file"]["name"]);
- $extension = end($temp);
- die('leziem kam nemam');
- //zistim ci je subor obrazok
- if ((($_FILES["file"]["type"] == "image/gif")
- || ($_FILES["file"]["type"] == "image/jpeg")
- || ($_FILES["file"]["type"] == "image/jpg")
- || ($_FILES["file"]["type"] == "image/pjpeg")
- || ($_FILES["file"]["type"] == "image/x-png")
- || ($_FILES["file"]["type"] == "image/png"))
- && in_array($extension, $allowedExts)) {
- //ak mam chybu, tak ju vypisem
- if ($_FILES["file"]["error"] > 0) {
- die ("Error: " . $_FILES["file"]["error"] . "<br>");
- //inak pokracujem v uploade
- } else {
- //premenujem si ho aby sa volal ako url clanku
- $_FILES['file']['name']=$_POST['url'].'.jpg';
- //ak uz existuje, tak oplujem
- if (file_exists("images/title/" . $_FILES["file"]["name"])) {
- die ($_FILES["file"]["name"] . " already exists. ");}
- //inak ho ulozim
- else {
- move_uploaded_file($_FILES["file"]["tmp_name"],
- "images/title/" . $_FILES["file"]["name"]);
- echo ("Stored in: " . "images/title/" . $_FILES["file"]["name"]);
- }
- }
- //ak subor neni obrazok, tak oplujem
- } else {
- die ("Invalid file");
- }
- }
- //ak mam nahrate nieco do galerie tak ju uploadnem
- if(isset($_FILES['gallery'])){
- //kontrola ci uz zlozka existuje
- if (!is_dir("galerie/".$_POST['url'])){
- //ak nie tak ju zalozim
- mkdir("galerie/".$_POST['url']);
- }
- //otvorim subor s metadatami
- $fr = fopen("galerie/".$_POST['url']."/meta.html", "a");
- //prejdem vsetky nahrate veci
- for($i = count($_FILES['gallery']['name'])-2; $i>=0; $i--){
- //ulozim fotku
- move_uploaded_file($_FILES['gallery']['tmp_name'][$i], "galerie/".$_POST['url']."/".$_FILES['gallery']['name'][$i]);
- //pripravim si link
- $text='<li><a href="galerie/'.$_POST["url"].'/'.$_FILES["gallery"]["name"][$i].'" rel="prettyPhoto[pp_gal]" title="'.$_POST["imgdesc"][$i].'"><img src="galerie/'.$_POST["url"].'/'.$_FILES["gallery"]["name"][$i].'" height="120" alt="'.$_POST["imgname"][$i].'"/></a></li>';
- //ulozim si metadata
- fprintf($fr, "%s\n", $text);
- }
- }
- //po uploadnutí presmerujem na článok
- header('Location: index.php?section='.$_POST['section'].'&url='.$_POST['url']);
- exit();
- }
- //ak ma sem presmerovalo z článku, ktorý chcem upraviť tak si načítam do pola údaje z DB
- else if(isset($_GET['url'])){
- $articleToEdit=Db::queryOne("
- SELECT *
- FROM clanky
- WHERE url=?
- ", $_GET['url']);
- if($articleToEdit){
- $article=$articleToEdit;
- }
- else{
- $message = "Hledaný článek neexistuje!";
- }
- }
- ?>
- <?php
- if (isset($message)){
- printf("<p class=\"error\">%s</p>\n", $message);
- }
- ?>
- <form method="post" enctype="multipart/form-data">
- <input type="number" hidden="" name="article_id" value="<?= htmlspecialchars($article['article_id']) ?>"/><br />
- <input type="number" hidden="" name="users_id" value="<?= $_SESSION['user_id'] ?>"/>
- <p>Zvolte sekci do které chcete přidat článek:
- <select id="select" name="section">
- <option value="bylinky">Bylinky</option>
- <option value="pripravky">Přípravky</option>
- </select></p>
- <script>
- //ak modifikujem home-page, tak zmenim options zo selectu
- function getUrlVars() {
- var vars = {};
- var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
- vars[key] = value;
- });
- return vars;
- }
- parts=getUrlVars();
- //ak chceme editovat home-page, tak zmenim ponuku v selecte
- if(parts["url"]==="home-page"){
- select = document.getElementById("select");
- select.innerHTML="<option value=\"domov\">Domov</option>";
- }
- </script>
- <p>Zadejte titulek:
- <input type="text" name="title" value="<?= htmlspecialchars($article['title']) ?>"/></p>
- <p>Zadejte URL (titulek-bez-diakritiky-s-pomlckami):
- <input type="text" name="url" value="<?= htmlspecialchars($article['url']) ?>"/></p>
- <p>Zadejte krátký popis (max. 255 znaků):
- <input type="text" name="description" value="<?= htmlspecialchars($article['description']) ?>"/></p>
- <p>Zadejte klíčová slova (max. 255 znaků):
- <input type="text" name="keywords" value="<?= htmlspecialchars($article['keywords']) ?>"/></p>
- <label for="file">Titulní obrázek:</label>
- <input type="file" name="file"/>
- <div id="upgal">
- <p>Zde můžete nahrát obrázky do galerie</p>
- <input type="file" name="gallery[]" onclick="pridaj()"/>
- <input type="text" name="imgname[]" placeholder="Jméno obrázku"/>
- <input type="text" name="imgdesc[]" placeholder="Popisek obrázku"/>
- </div>
- <p>Zde můžete vložit článek</p>
- <textarea name="content"><?= htmlspecialchars($article['content']) ?></textarea>
- <input type="submit" value="uložit"/>
- </form>
- <script type="text/javascript" src="//tinymce.cachefly.net/4.0/tinymce.min.js"></script>
- <script type="text/javascript">
- tinymce.init({
- selector: "textarea[name=content]",
- plugins: [
- "advlist autolink lists link image charmap print preview anchor",
- "searchreplace visualblocks code fullscreen",
- "insertdatetime media table contextmenu paste"
- ],
- toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
- entities: "160,nbsp",
- entity_encoding: "named",
- entity_encoding: "raw"
- });
- function pridaj(){
- var parent = document.getElementById("upgal");
- //pridaj file
- var child = document.createElement("input");
- child.type="file";
- child.name="gallery[]";
- child.setAttribute("onclick", "pridaj()");
- parent.appendChild(child);
- //pridaj meno
- var child = document.createElement("input");
- child.type="text";
- child.name="imgname[]";
- child.placeholder="Jméno obrázku";
- parent.appendChild(child);
- //pridaj popis
- var child = document.createElement("input");
- child.type="text";
- child.name="imgdesc[]";
- child.placeholder="Popis obrázku";
- parent.appendChild(child);
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement