Created
January 5, 2017 17:04
-
-
Save anonymous/1b80bc072e9684eac5634b2048311df7 to your computer and use it in GitHub Desktop.
wieisroy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class WieisroyModel extends Model { | |
public function Index(){ | |
$this->query('SELECT * FROM roy ORDER BY id DESC '); | |
$rows = $this->resultSet(); | |
return $rows; | |
} | |
public function add(){ | |
//Sanitize POST | |
$post = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); | |
if($post['submit']){ | |
if($post['title'] == "" || $post['body'] == "" || $post['link'] == "" ){ | |
Messages::setMsg('Vul a.u.b alle velden in!', 'error'); | |
return; | |
} | |
$target_dir = "/usr/www/vanohosting/public_royvanoeteren/models/uploads/"; | |
$target_dir_Site = "http://www.royvanoeteren.nl/models/uploads/"; | |
$target_file_Site = $target_dir_Site . basename($_FILES["fileToUpload"]["name"]); | |
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); | |
$uploadOk = 1; | |
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); | |
// Check if image file is a actual image or fake image | |
if(isset($_POST["submit"])) { | |
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); | |
if($check !== false) { | |
Messages::setMsg("File is an image - " . $check["mime"] . ".",'succesMsg'); | |
$uploadOk = 1; | |
} else { | |
Messages::setMsg("File is not an image.",'error'); | |
$uploadOk = 0; | |
} | |
} | |
// Check if file already exists | |
if (file_exists($target_file)) { | |
Messages::setMsg("Sorry, file already exists.",'error'); | |
$uploadOk = 0; | |
} | |
// Check file size | |
if ($_FILES["fileToUpload"]["size"] > 500000) { | |
Messages::setMsg("Sorry, your file is too large.",'error'); | |
$uploadOk = 0; | |
} | |
// Allow certain file formats | |
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" | |
&& $imageFileType != "gif" ) { | |
Messages::setMsg("Sorry, only JPG, JPEG, PNG & GIF files are allowed.",'error'); | |
$uploadOk = 0; | |
} | |
// Check if $uploadOk is set to 0 by an error | |
if ($uploadOk == 0) { | |
Messages::setMsg("Sorry, your file was not uploaded.",'error'); | |
// if everything is ok, try to upload file | |
} else { | |
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { | |
Messages::setMsg("The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.", 'succesMsg'); | |
//INSERT IN SQL | |
$this->query('INSERT INTO roy (title, body, link, user_id, image) VALUES(:title, :body, :link, :user_id, :image)'); | |
$this->bind(':title', $post['title']); | |
$this->bind(':body', $post['body']); | |
$this->bind(':link', $post['link']); | |
$this->bind(':image', $target_file_Site); | |
$this->bind(':user_id', 1); | |
$this->execute(); | |
//Verify | |
if($this->lastInsertId()){ | |
//Redirect | |
header('location: '.ROOT_URL. 'wieisroy'); | |
Messages::setMsg("The file ". basename( $_FILES["image"]["name"]). " has been uploaded.", 'succesMsg'); | |
return; | |
} | |
}else{ | |
Messages::setMsg($errors[0], 'error'); | |
} | |
} | |
} | |
} | |
public function editdata(){ | |
if(isset($_GET['page_ID'])) | |
{ | |
$pageID = $_GET['page_ID']; | |
$this->query("SELECT * FROM roy WHERE id='$pageID'"); | |
$result = $this->resultSet(); | |
return $result; | |
} | |
} | |
public function saveEditedData(){ | |
$post = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); | |
if($post['submitSave']){ | |
if($post['titel'] == "" || $post['body'] == "" || $post['link'] == "" ){ | |
Messages::setMsg('Vul a.u.b alle velden in!', 'error'); | |
return; | |
} | |
if(!(isset($post['addedImage']))){ | |
$this->query('UPDATE roy SET title=:title, body=:body, link=:link, image=:image WHERE id=:pageID;'); | |
$this->bind(':title', $post['titel']); | |
$this->bind(':body', $post['body']); | |
$this->bind(':link', $post['link']); | |
$this->bind(':pageID', $_GET['page_ID']); | |
$this->bind(':image', $target_file_Site); | |
$this->execute(); | |
Messages::setMsg('Successvol bewerkt!','succesMsg'); | |
//Verify | |
if($this->lastInsertId()){ | |
//Redirect | |
header('location: '.ROOT_URL. 'wieisroy'); | |
} | |
} else { | |
$target_dir = "/usr/www/vanohosting/public_royvanoeteren/models/uploads/"; | |
$target_dir_Site = "http://www.royvanoeteren.nl/models/uploads/"; | |
$target_file_Site = $target_dir_Site . basename($_FILES["fileToUpload"]["name"]); | |
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); | |
$uploadOk = 1; | |
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); | |
// Check if image file is a actual image or fake image | |
if(isset($post["submitSave"]) && isset($post['addedImage'])) { | |
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); | |
if($check !== false) { | |
Messages::setMsg("File is an image - " . $check["mime"] . ".",'succesMsg'); | |
$uploadOk = 1; | |
} else { | |
Messages::setMsg("File is not an image.",'error'); | |
$uploadOk = 0; | |
} | |
} | |
// Check if file already exists | |
if (file_exists($target_file)) { | |
Messages::setMsg("Sorry, file already exists.",'error'); | |
$uploadOk = 0; | |
} | |
// Check file size | |
if ($_FILES["fileToUpload"]["size"] > 500000) { | |
Messages::setMsg("Sorry, your file is too large.",'error'); | |
$uploadOk = 0; | |
} | |
// Allow certain file formats | |
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" | |
&& $imageFileType != "gif" ) { | |
Messages::setMsg("Sorry, only JPG, JPEG, PNG & GIF files are allowed.",'error'); | |
$uploadOk = 0; | |
} | |
// Check if $uploadOk is set to 0 by an error | |
if ($uploadOk == 0) { | |
Messages::setMsg("Sorry, your file was not uploaded.",'error'); | |
// if everything is ok, try to upload file | |
} else { | |
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { | |
Messages::setMsg("The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.", 'succesMsg'); | |
//UPDATE DATA IN SQL | |
$this->query('UPDATE roy SET title=:title, body=:body, link=:link, image=:image WHERE id=:pageID;'); | |
$this->bind(':title', $post['titel']); | |
$this->bind(':body', $post['body']); | |
$this->bind(':link', $post['link']); | |
$this->bind(':pageID', $_GET['page_ID']); | |
$this->bind(':image', $target_file_Site); | |
$this->execute(); | |
Messages::setMsg('Successvol bewerkt!','succesMsg'); | |
//Verify | |
if($this->lastInsertId()){ | |
//Redirect | |
header('location: '.ROOT_URL. 'wieisroy'); | |
} | |
}else{ | |
Messages::setMsg($errors[0], 'error'); | |
} | |
} | |
} | |
} | |
} | |
public function checkdelete(){ | |
$post = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); | |
if(isset($_GET['page_ID'])) | |
{ | |
$pageID = $_GET['page_ID']; | |
$this->query("SELECT * FROM roy WHERE id='$pageID'"); | |
$result = $this->resultSet(); | |
return $result; | |
} | |
} | |
public function page(){ | |
if(isset($_GET['page_ID'])) | |
{ | |
$pageID = $_GET['page_ID']; | |
$this->query("SELECT * FROM roy WHERE id='$pageID'"); | |
$result = $this->resultSet(); | |
return $result; | |
} | |
} | |
public function deleteItem(){ | |
if($_GET['page_ID'] == "") | |
{ | |
Messages::setMsg('Page_ID is missing'); | |
return; | |
} | |
if($_POST['submitDelete']){ | |
//Delete IN SQL | |
$this->query('DELETE FROM roy WHERE id=:pageID'); | |
$this->bind(':pageID', $_GET['page_ID']); | |
$this->execute(); | |
Messages::setMsg('Succesvol verwijderd!','succesMsg'); | |
//Verify | |
if($this->lastInsertId()){ | |
//Redirect | |
header('location: '.ROOT_URL. 'wieisroy'); | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment