| Server IP : 103.234.187.230 / Your IP : 216.73.216.216 Web Server : Apache System : Linux lserver42043-ind.megavelocity.net 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/b2bzend/application/admin/controllers/ |
Upload File : |
<?php
/**
* Class TipsForYou
*
* @name TipsForYou
* @author Neeraj Prajapati
* @editor Neeraj Prajapati
* @created 4 Oct 2023
* @version 1.0
* @copyright Catabatic India Pvt Ltd
*
*/
class Admin_TipsForYouController extends Catabatic_ValidateAdmin {
public $baseUrl = '';
public $objAgency = '';
public function init() {
parent::init();
$request = Zend_Controller_Front::getInstance()->getRequest();
$this->baseUrl = $request->getScheme() . '://' . $request->getHttpHost();
$sessionLogin_user = new Zend_Session_Namespace('sessionLogin_user');
$this->objAgency = new Travel_Model_TblAgency();
$this->intLoggedinUserId = $sessionLogin_user->intLoggedinUserId;
$this->intLoggedinUserAgencySysId = $sessionLogin_user->intLoggedinUserAgencySysId;
}
public function indexAction()
{
$this->view->getTipsForYouList = $this->objAgency->getTipsForYouList();
$this->view->messages = $this->_helper->flashMessenger->getMessages();
}
public function addTipsforyouAction()
{
$maxWidth = 332;
$maxHeight = 206;
$this->view->maxWidth = $maxWidth;
$this->view->maxHeight = $maxHeight;
if ($this->getRequest()->isPost()) {
$getData = $this->getRequest()->getPost();
// print_r($getData); die();
$orignalFolderName = "public/tipsforyou_";
$orignalFileName = $_FILES['Image']['name'];
$fileExt = strtolower(pathinfo($orignalFileName, PATHINFO_EXTENSION));
$fileName = "tipsforyou_" . time() . '.' . $fileExt;
$tempFileName = $_FILES["Image"]["tmp_name"];
// Validate the uploaded file
$allowedExtensions = ['jpg', 'jpeg', 'png', 'gif']; // Add more if needed
$maxFileSize = 2097152; // 2MB
if (!in_array($fileExt, $allowedExtensions) || $_FILES['Image']['size'] > $maxFileSize) {
$this->_helper->flashMessenger->addMessage("Invalid image file or file size exceeds the limit.");
} else {
list($width, $height) = getimagesize($tempFileName);
if ($width > $maxWidth || $height > $maxHeight) {
$this->_helper->flashMessenger->addMessage("Image dimensions exceed the maximum allowed dimensions.");
} else {
// Move the uploaded file to the destination folder
if (move_uploaded_file($tempFileName, $orignalFolderName . "/" . $fileName)) {
$addData = array(
'AgencySysId' => null,
'Title' => trim($getData['Title']),
'description' => trim($getData['description']),
'IsActive' => 1,
'IsMarkForDelete' => 0,
'IsMaster' => 0,
'DisplayOnHome' => 0,
'CreateDate' => date('Y-m-d H:i:s'),
'Image' => $fileName
);
try {
$this->objAgency->insertData("TB_Agency_Master_Tips_For_You", $addData);
$this->_helper->flashMessenger->addMessage("Tipsforyou content has been added successfully.");
} catch (Exception $e) {
$this->_helper->flashMessenger->addMessage("An error occurred while adding the Tipsforyou content.");
}
} else {
$this->_helper->flashMessenger->addMessage("Failed to move the uploaded file.");
}
}
}
$this->view->messages = $this->_helper->flashMessenger->getMessages();
// Redirect or display messages as needed
$this->_redirect("/admin/tips-for-you"); // Redirect to a success page or replace with your logic
}
$this->view->messages = $this->_helper->flashMessenger->getMessages();
}
public function editTipsforyouAction()
{
$AgencySysId = $this->intLoggedinUserAgencySysId;
$offerID = $this->getRequest()->getParam('id');
$getTipsForYou = $this->objAgency->getTipsForYouDataByID($offerID);
if ($getTipsForYou) {
$maxWidth = 332; // Adjust maximum width as needed
$maxHeight = 206;
$this->view->maxWidth = $maxWidth;
$this->view->maxHeight = $maxHeight;
$this->view->getTipsForYou = $getTipsForYou;
if ($this->getRequest()->isPost()) {
$getData = $this->getRequest()->getPost();
$image = $getTipsForYou['Image'];
$orignalFolderName = "public/tipsforyou_";
$orignalFileName = $_FILES['Image']['name'];
if (!empty($orignalFileName)) {
$fileExt = strtolower(pathinfo($orignalFileName, PATHINFO_EXTENSION));
$fileName = "tipsforyou_" . time() . '.' . $fileExt;
$tempFileName = $_FILES["Image"]["tmp_name"];
$allowedExtensions = ['jpg', 'jpeg', 'png', 'gif'];
$maxFileSize = 2097152; // 2MB
if (!in_array($fileExt, $allowedExtensions) || $_FILES['Image']['size'] > $maxFileSize) {
$this->_helper->flashMessenger->addMessage("Invalid image file or file size exceeds the limit.");
} else {
list($width, $height) = getimagesize($tempFileName);
if ($width > $maxWidth || $height > $maxHeight) {
$this->_helper->flashMessenger->addMessage("Image dimensions exceed the maximum allowed dimensions.");
} else {
if (move_uploaded_file($tempFileName, $orignalFolderName . "/" . $fileName)) {
if (!empty($image)) {
unlink($orignalFolderName . "/" . $image);
}
$uploadimg = $fileName;
} else {
$uploadimg = $image;
}
}
}
} else {
$uploadimg = $image;
}
$postData = array(
'Title' => trim($getData['Title']),
'description' => trim($getData['description']),
'CreateDate' => date('Y-m-d H:i:s'),
'Image' => $uploadimg
);
try {
$this->objAgency->updateData("TB_Agency_Master_Tips_For_You", $postData, [
"TipsForYouSysId = ?" => $offerID,
]);
$this->view->message = "Tipsforyou content has been updated successfully.";
$this->_redirect("/admin/tips-for-you");
} catch (Exception $e) {
$this->_helper->flashMessenger->addMessage("An error occurred while updating the Tipsforyou content.");
}
}
$this->view->messages = $this->_helper->flashMessenger->getMessages();
} else {
$this->view->message = "Invalid offer ID provided.";
$this->_redirect("/admin/tips-for-you");
}
}
public function changeDisplayOnHomeAction(){
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
if ($this->getRequest()->isXmlHttpRequest()) {
$getData = $this->getRequest()->getParams();
$val = (int) $getData['val'];
$TipsForYouSysId = (int) $getData['TipsForYouSysId'];
$updatearray = array('DisplayOnHome' => $val);
$whereCond = array("TipsForYouSysId = ?" => $TipsForYouSysId);
$this->objAgency->updateData("TB_Agency_Master_Tips_For_You", $updatearray, $whereCond);
echo json_encode(array('status' => true, 'val' => $val, 'TipsForYouSysId' => $TipsForYouSysId));
exit;
}
}
// public function isActiveAction(){
// $this->_helper->layout->disableLayout();
// $this->_helper->viewRenderer->setNoRender(true);
// if ($this->getRequest()->isXmlHttpRequest()) {
// $getData = $this->getRequest()->getParams();
// $val = (int) $getData['val'];
// $TipsForYouSysId = (int) $getData['TipsForYouSysId'];
// $updatearray = array('IsActive' => $val);
// $whereCond = array("TipsForYouSysId = ?" => $TipsForYouSysId);
// $this->objAgency->updateData("TB_Agency_Master_Tips_For_You", $updatearray, $whereCond);
// echo json_encode(array('status' => true, 'val' => $val, 'TipsForYouSysId' => $TipsForYouSysId));
// exit;
// }
// }
public function isDeleteAction(){
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
if ($this->getRequest()->isXmlHttpRequest()) {
$getData = $this->getRequest()->getParams();
$val = (int) $getData['val'];
$TipsForYouSysId = (int) $getData['TipsForYouSysId'];
$updatearray = array('IsMarkForDelete' => $val);
$whereCond = array("TipsForYouSysId = ?" => $TipsForYouSysId);
$this->objAgency->updateData("TB_Agency_Master_Tips_For_You", $updatearray, $whereCond);
echo json_encode(array('status' => true, 'val' => $val, 'TipsForYouSysId' => $TipsForYouSysId));
exit;
}
}
}