static function showNewPostForm($data = null, $error = null) { $user = Session::getUser(); require_once 'manager/AuthorizationManager.php'; if (!isset($_GET["type"])) { $_GET["type"] = Post::NEWS; } if (!AuthorizationManager::canUserDo(AuthorizationManager::CREATE, $_GET["type"])) { return; } //TODO redirect verso pagina di errore. $logger = Logger::getLogger(); $logger->debug("ResourceDao", $_GET["type"]); if (isset($_GET["phase"]) && $_GET["phase"] == 3) { if ($_GET["type"] == "photoreportage" && isset($_POST["numResources"])) { $data = array(); for ($i = 0; $i < $_POST["numResources"]; $i++) { $resourceID = $_POST["resourceID" . $i]; if (isset($_POST[$resourceID]) && $_POST[$resourceID] != '') { //$_POST[$resourceID] is the description $data['description'] = $_POST[$resourceID]; $rsUpdated = ResourceManager::editResource($resourceID, $data); } } Page::redirect("Edit"); } } else { if (is_null($error) && count($_POST) > 0) { $data = array(); if (isset($_POST["title"]) && trim($_POST["title"]) != "") { $data["title"] = $_POST["title"]; } else { $error = array("Inserire un titolo."); } if (isset($_POST["type"])) { $data["type"] = $_POST["type"]; } else { $error[] = "Scegliere il tipo di post da pubblicare."; } if ($data["type"] == "news") { //carico il testo del post if (isset($_POST["content"]) && trim($_POST["content"]) != "") { $data["content"] = $_POST["content"]; } else { $error[] = "Inserire un contenuto."; } //check if ther's not valid files $notvalid = 0; if (trim($_FILES["upfile"]["name"]) != "") { if ($_FILES["upfile"]["type"] == "image/gif" || $_FILES["upfile"]["type"] == "image/jpeg" || $_FILES["upfile"]["type"] == "image/png") { } else { $notvalid++; } } if ($notvalid == 0) { if (trim($_FILES["upfile"]["name"]) != "") { if ($_FILES["upfile"]["type"] == "image/gif" || $_FILES["upfile"]["type"] == "image/jpeg" || $_FILES["upfile"]["type"] == "image/png") { $fname = ResourceManager::editFileName($_FILES["upfile"]["name"]); $newsPhoto = ResourceManager::uploadPhoto($fname, $user->getNickname(), $user->getID(), $_FILES["upfile"]["tmp_name"], $_FILES["upfile"]["type"]); //prelevo l'id della risorsa appena salvata $data["photo"] = $newsPhoto->getID(); } } } else { $error[] = "Devi inserire un formato valido: .jpeg .jpg .gif oppure .png"; } } else { if ($data["type"] == "photoreportage") { $photo = array(); //check if ther's not valid files for ($i = 0, $notvalid = 0; $i < 10; $i++) { if (trim($_FILES["upfile{$i}"]["name"]) != "") { if ($_FILES["upfile{$i}"]["type"] == "image/gif" || $_FILES["upfile{$i}"]["type"] == "image/jpeg" || $_FILES["upfile{$i}"]["type"] == "image/png") { } else { $notvalid++; } } } if ($notvalid == 0) { for ($i = 0, $numphoto = 0; $i < 10; $i++) { if (trim($_FILES["upfile{$i}"]["name"]) != "") { if ($_FILES["upfile{$i}"]["type"] == "image/gif" || $_FILES["upfile{$i}"]["type"] == "image/jpeg" || $_FILES["upfile{$i}"]["type"] == "image/png") { $fname = ResourceManager::editFileName($_FILES["upfile{$i}"]["name"]); $photo[] = ResourceManager::uploadPhoto($fname, $user->getNickname(), $user->getID(), $_FILES["upfile{$i}"]["tmp_name"], $_FILES["upfile{$i}"]["type"]); $numphoto++; } } } if ($numphoto > 0) { $data["content"] = $photo; } else { $error[] = "Devi inserire almeno un'immagine"; } } else { $error[] = "Devi inserire un formato valido: .jpeg .jpg .gif oppure .png"; } } else { if ($data["type"] == "videoreportage") { if (isset($_POST["userUrl"]) && $_POST["userUrl"] != '') { $rs = ResourceManager::createResource($user->getID(), youtubeManager::getVideoID($_POST["userUrl"]), 'video'); $data['content'] = youtubeManager::getVideoID($_POST["userUrl"]); } } } } if (isset($_POST["cat"]) && is_array($_POST["cat"]) && count($_POST["cat"]) > 0) { $cat = ""; $first = true; foreach ($_POST["cat"] as $k => $c) { if ($first) { $first = false; } else { $cat .= ", "; } $cat .= $c; } $data["categories"] = $cat; } if (isset($_POST["place"]) && trim($_POST["place"]) != "") { $data["place"] = $_POST["place"]; } //if(isset($_POST["headline"]) && trim($_POST["headline"]) != "") // $data["headline"] = $_POST["headline"]; if (isset($_POST["subtitle"]) && trim($_POST["subtitle"]) != "") { $data["subtitle"] = $_POST["subtitle"]; } if (isset($_POST["tags"]) && trim($_POST["tags"]) != "") { $data["tags"] = $_POST["tags"]; } if (is_null($error) || is_array($error) && count($error) == 0) { $data["author"] = $user->getID(); //se photoreportage creo una collection if ($data["type"] == "news") { $post = PostManager::createPost($data); //se vi è una foto aggiorno la tabella PostResource if (isset($data['photo']) && $data['photo'] != "") { PostManager::setPostResource($post->getID(), $data['photo']); } } else { if ($data["type"] == "videoreportage") { $post = PostManager::createPost($data); } else { if ($data["type"] == "photoreportage" && $_GET["phase"] == 2) { //save only the resource ID not the whole object foreach ($data["content"] as &$resource) { $resource = $resource->getID(); } $post = CollectionManager::createCollection($data); } else { $post = false; } } } if ($post !== false) { echo ' <div class="message"> Notizia salvata: <a href="' . FileManager::appendToRootPath($post->getPermalink()) . '">Visualizza</a> </div>'; } } else { self::showNewPostForm($data, $error); return; } } } //echo serialize(isset($_GET["type"])) . "<br/>"; //DEBUG switch ($_GET["type"]) { case Post::COLLECTION: case Post::PHOTOREP: case Post::VIDEOREP: case Post::ALBUM: case Post::MAGAZINE: case Post::PLAYLIST: call_user_func(array("PostPage", "showNew" . $_GET["type"] . "Form"), $data, $error); break; case "videoreportage3": break; case Post::NEWS: default: self::showNewNewsForm($data, $error); } }