home/islapiiu/sites/forbes/control-panel/post-and-get/pages.php 0000644 00000006252 15076643235 0020631 0 ustar 00 <?php
include_once(dirname(__FILE__) . '/../../class/include.php');
if (isset($_POST['create'])) {
$PAGES = new Page(NULL);
$VALID = new Validator();
$PAGES->title = mysql_real_escape_string($_POST['title']);
$PAGES->description = mysql_real_escape_string($_POST['description']);
$dir_dest = '../../upload/page/';
$handle = new Upload($_FILES['image']);
$imgName = null;
if ($handle->uploaded) {
$handle->image_resize = true;
$handle->file_new_name_ext = 'jpg';
$handle->image_ratio_crop = 'C';
$handle->file_new_name_body = Helper::randamId();
$handle->image_x = 422;
$handle->image_y = 513;
$handle->Process($dir_dest);
if ($handle->processed) {
$info = getimagesize($handle->file_dst_pathname);
$imgName = $handle->file_dst_name;
}
}
$PAGES->image_name = $imgName;
$VALID->check($PAGES, [
'title' => ['required' => TRUE],
'description' => ['required' => TRUE],
'image_name' => ['required' => TRUE]
]);
if ($VALID->passed()) {
$PAGES->create();
if (!isset($_SESSION)) {
session_start();
}
$VALID->addError("Your data was saved successfully", 'success');
$_SESSION['ERRORS'] = $VALID->errors();
header('Location: ' . $_SERVER['HTTP_REFERER']);
} else {
if (!isset($_SESSION)) {
session_start();
}
$_SESSION['ERRORS'] = $VALID->errors();
header('Location: ' . $_SERVER['HTTP_REFERER']);
}
}
if (isset($_POST['update'])) {
$dir_dest = '../../upload/page/';
$handle = new Upload($_FILES['image']);
$imgName = null;
if ($handle->uploaded) {
$handle->image_resize = true;
$handle->file_new_name_body = TRUE;
$handle->file_overwrite = TRUE;
$handle->file_new_name_ext = FALSE;
$handle->image_ratio_crop = 'C';
$handle->file_new_name_body = $_POST ["oldImageName"];
$handle->image_x = 422;
$handle->image_y = 513;
$handle->Process($dir_dest);
if ($handle->processed) {
$info = getimagesize($handle->file_dst_pathname);
$imgName = $handle->file_dst_name;
}
}
$PAGES = new Page($_POST['id']);
$PAGES->image_name = $_POST['oldImageName'];
$PAGES->title = mysql_real_escape_string($_POST['title']);
$PAGES->description = mysql_real_escape_string($_POST['description']);
$VALID = new Validator();
$VALID->check($PAGES, [
'title' => ['required' => TRUE],
'description' => ['required' => TRUE],
'image_name' => ['required' => TRUE]
]);
if ($VALID->passed()) {
$PAGES->update();
if (!isset($_SESSION)) {
session_start();
}
$VALID->addError("Your changes saved successfully", 'success');
$_SESSION['ERRORS'] = $VALID->errors();
header('Location: ' . $_SERVER['HTTP_REFERER']);
} else {
if (!isset($_SESSION)) {
session_start();
}
$_SESSION['ERRORS'] = $VALID->errors();
header('Location: ' . $_SERVER['HTTP_REFERER']);
}
dd($PAGES);
} |