| 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/prathamtour.com/application/admin/controllers/ |
Upload File : |
<?php
/* * *************************************************************
* Catabatic Technology Pvt. Ltd.
* File Name : ContactusController.php
* File Desc. : Contactus controller managed all contact queries
* Created By : Piyush Tiwari <piyush@catpl.co.in>
* Created Date : 23 May 2018
* Updated Date : 23 May 2018
* ************************************************************* */
class Admin_PackController extends Zend_Controller_Action {
public $dbAdapter;
public $perPageLimit;
public $siteurl;
public $DIR_WRITE_MODE;
public $resultset;
public function init() {
/* Initialize db and session access */
$aConfig = $this->getInvokeArg('bootstrap')->getOptions();
$this->siteurl = $aConfig['bootstrap']['siteUrl'];
$this->appmode = $aConfig['bootstrap']['appmode'];
$this->per_page_record = 20;
$this->dbAdapter = Zend_Db_Table::getDefaultAdapter();
$BootStrap = $aConfig['bootstrap'];
$this->stylecss = $BootStrap['stylecss'];
$auth = Zend_Auth::getInstance();
$authStorage = $auth->getStorage()->read();
$this->username = $authStorage->username;
$this->admin_type = $authStorage->role;
$this->current_time = time();
$this->imageUrl = (($this->appmode == 'MODE_BETA') ? 'beta/' : '') . 'public/upload/'.$this->stylecss.'/pack/';
$options = $aConfig['bootstrap'];
$this->banner_large_image_width = $options['banner_large_image_width'];
$this->banner_large_image_height = $options['banner_large_image_height'];
$this->banner_medium_image_width = $options['banner_medium_image_width'];
$this->banner_medium_image_height = $options['banner_medium_image_height'];
$this->banner_small_image_width = $options['banner_small_image_width'];
$this->banner_small_image_height = $options['banner_small_image_height'];
$this->large_image_width = $options['large_image_width'];
$this->large_image_height = $options['large_image_height'];
$this->medium_image_width = $options['medium_image_width'];
$this->medium_image_height = $options['medium_image_height'];
$this->small_image_width = $options['small_image_width'];
$this->small_image_height = $options['small_image_height'];
$this->DIR_WRITE_MODE = 0777;
$this->table = "tbl_pack_type";
}
/**
* index() method is used to admin login for form call
* @param Null
* @return Array
*/
public function indexAction() {
$this->checklogin();
$this->view->messages = $this->_helper->flashMessenger->getMessages();
$crud = new Admin_Model_CRUD();
$getData = array();
if ($this->getRequest()->isPost()) {
$getData = $this->getRequest()->getPost();
$searchArr = array(
'Titles' => $getData['Title'],
'rows' => $getData['rows'],
'page' => $getData['page'],
);
$resulsetold = $crud->getCount($this->table, ['IsMarkForDel' => 0], 'packType');
$crud->searchArr = $searchArr;
$resultset = $crud->rv_select_static($this->table, ['Title', 'packType', 'DisplayOnFooter','displayOnHome'], ['IsMarkForDel' => 0], ['packType' => 'ASC']);
$result = Zend_Json::encode($resultset);
$newResult = Zend_Json::decode($result, false);
$finalResult["total"] = $resulsetold[0]['packType'];
$finalResult["rows"] = $newResult;
echo json_encode($finalResult);
exit;
}
}
public function editpackAction() {
//Check admin logedin or not
$this->checklogin();
$crud = new Admin_Model_CRUD();
$form = new Admin_Form_Editpack();
$packType = (int) $this->getRequest()->getParam("id");
$form->setMethod("POST");
$form->setAction("admin/pack/editpack/id/" . $packType);
$form->setName("edit_pack");
if ($this->getRequest()->isPost()) {
$getData = $this->getRequest()->getPost();
// echo"<pre>";print_r($getData);die;
// explode();
//-------Start Code for Approve and Publish content---------//
if (isset($getData['save']) == "Save") {
//Code for check page alias name already exists or not
$packType = (int) @$getData['packType'];
$fileName = $bannerfileName = '';
$images = $_FILES['image']['name'];
$banner_image = $_FILES['banner_image']['name'];
if (isset($images) && !empty($images)) {
$fileExt = $this->_helper->General->getFileExtension($images);
$allowedExtensions = ['jpg', 'jpeg', 'gif', 'png', 'webp'];
if(in_array($fileExt, $allowedExtensions, true)){
$orignalFolderName = $_SERVER["DOCUMENT_ROOT"] . "/" . $this->imageUrl .$packType.'/images' ;
//die($orignalFolderName);
$fileExt = $this->_helper->General->getFileExtension($images);
$fileName = 'image_' . $this->current_time . '.' . $fileExt;
$fileName1 = 'image_' . $this->current_time;
if (!file_exists($orignalFolderName)) {
mkdir($orignalFolderName, $this->DIR_WRITE_MODE, true);
}
$temp_file_name = $_FILES["image"]["tmp_name"]; // temprary file name
@move_uploaded_file($temp_file_name, $orignalFolderName . "/" . $fileName);
$originalLargeFolder = $orignalFolderName.'/large';
$originalMediumFolder = $orignalFolderName.'/medium';
$originalSmallFolder = $orignalFolderName.'/small';
$sourceFile = $orignalFolderName . "/" . $fileName;
$destinationFile = $orignalFolderName . "/" . $fileName1.'.webp';
$quality = 80;
if ($crud->convertToWebP($sourceFile, $destinationFile, $quality)) {
if (!file_exists($originalLargeFolder)) {
mkdir($originalLargeFolder, 0777, true);
}
if (!file_exists($originalMediumFolder)) {
mkdir($originalMediumFolder, 0777, true);
}
if (!file_exists($originalSmallFolder)) {
mkdir($originalSmallFolder, 0777, true);
}
@copy($destinationFile, $originalLargeFolder . "/" . $fileName1.'.webp');
@copy($destinationFile, $originalMediumFolder . "/" . $fileName1.'.webp');
@copy($destinationFile, $originalSmallFolder . "/" . $fileName1.'.webp');
$fileName = $fileName1.'.webp';
} else {
$this->view->errorMessage ="Only allow 'jpg', 'png', 'webp' ";
}
}else{
$this->view->errorMessage ="Only allow 'jpg', 'png', 'webp' ";
}
}
if (isset($banner_image) && !empty($banner_image)) {
$fileExt = $this->_helper->General->getFileExtension($banner_image);
$allowedExtensions = ['jpg', 'jpeg', 'gif', 'png', 'webp'];
if(in_array($fileExt, $allowedExtensions, true)){
$bannerorignalFolderName = $_SERVER["DOCUMENT_ROOT"] . "/" . $this->imageUrl .$packType.'/banner' ;
$fileExt1 = $this->_helper->General->getFileExtension($banner_image);
$bannerfileName = 'banner_' . $this->current_time . '.' . $fileExt1;
$bannerfileName1 = 'banner_' . $this->current_time;
if (!file_exists($bannerorignalFolderName)) {
mkdir($bannerorignalFolderName, $this->DIR_WRITE_MODE, true);
}
$temp_file_name1 = $_FILES["banner_image"]["tmp_name"]; // temprary file name
@move_uploaded_file($temp_file_name1, $bannerorignalFolderName . "/" . $bannerfileName);
$originalLargeFolder = $bannerorignalFolderName.'/large';
$originalMediumFolder = $bannerorignalFolderName.'/medium';
$originalSmallFolder = $bannerorignalFolderName.'/small';
$sourceFile = $bannerorignalFolderName . "/" . $bannerfileName;
$destinationFile = $bannerorignalFolderName . "/" . $bannerfileName1.'.webp';
$quality = 80;
if ($crud->convertToWebP($sourceFile, $destinationFile, $quality)) {
if (!file_exists($originalLargeFolder)) {
mkdir($originalLargeFolder, 0777, true);
}
if (!file_exists($originalMediumFolder)) {
mkdir($originalMediumFolder, 0777, true);
}
if (!file_exists($originalSmallFolder)) {
mkdir($originalSmallFolder, 0777, true);
}
@copy($destinationFile, $originalLargeFolder . "/" . $bannerfileName1.'.webp');
@copy($destinationFile, $originalMediumFolder . "/" . $bannerfileName1.'.webp');
@copy($destinationFile, $originalSmallFolder . "/" . $bannerfileName1.'.webp');
$bannerfileName = $bannerfileName1.'.webp';
} else {
$this->view->errorMessage ="Only allow 'jpg', 'png', 'webp' ";
}
}else{
$this->view->errorMessage ="Only allow 'jpg', 'png', 'webp' ";
}
}
$editPageData = [
'startingfrom'=>$getData['startingfrom'],
'treks'=>$getData['treks'],
'metaTitle'=>$getData['metaTitle'],
'metaKeyword'=>$getData['metaKeyword'],
'metaDescription'=>$getData['metaDescription'],
];
if ($fileName !='') {
$editPageData['image'] = $fileName;
}
if ($bannerfileName!='') {
$editPageData['banner_image'] = $bannerfileName;
}
if($editPageData){
$crud->rv_update($this->table, $editPageData, ['packType =?' => $packType]);
}
$this->view->successMessage = "Page content has been saved successfully.";
$this->_helper->flashMessenger->addMessage("Page content has been updated successfully.");
$this->_redirect("/admin/pack/index");
}
}
$result = $crud->getCmsdata($this->table, ['*'], ['packType' => $packType], ['packType' => 'DESC']);
// echo"<pre>";print_r($result);die;
$editdata["packType"] = @$result->packType;
$editdata["image"] = @$result->image;
$editdata["banner_image"] = @$result->banner_image;
$editdata["startingfrom"] = @$result->startingfrom;
$editdata["treks"] = @$result->treks;
$editdata["metaTitle"] = @$result->metaTitle;
$editdata["metaKeyword"] = @$result->metaKeyword;
$editdata["metaDescription"] = @$result->metaDescription;
$form->populate($editdata);
$this->view->form = $form;
$this->view->packType = @$result->packType;
$this->view->image = @$result->image;
$this->view->banner_image = @$result->banner_image;
}
public function displayAction() {
$this->checklogin();
$crud = new Admin_Model_CRUD();
$tId = (int) $this->getRequest()->getParam("id");
$val = (int) $this->getRequest()->getParam("val");
if ($tId) {
try {
$updatedata = [
'DisplayOnFooter' => $val
];
$result = $crud->rv_update($this->table, $updatedata, ['packType =?' => $tId]);
if (!$result) {
$result_message = ['status' => false, 'message' => 'Oops something wrong!!'];
echo Zend_Json::encode($result_message);
exit;
} else {
$result_message = ['status' => true, 'message' => 'Active successfully'];
echo Zend_Json::encode($result_message);
exit;
}
} catch (Exception $ex) {
$ex->getMessage();
}
}
}
public function displayHomeAction() {
$this->checklogin();
$crud = new Admin_Model_CRUD();
$tId = (int) $this->getRequest()->getParam("id");
$val = (int) $this->getRequest()->getParam("val");
if ($tId) {
try {
$updatedata = [
'DisplayOnHome' => $val
];
$result = $crud->rv_update($this->table, $updatedata, ['packType =?' => $tId]);
if (!$result) {
$result_message = ['status' => false, 'message' => 'Oops something wrong!!'];
echo Zend_Json::encode($result_message);
exit;
} else {
$result_message = ['status' => true, 'message' => 'Active successfully'];
echo Zend_Json::encode($result_message);
exit;
}
} catch (Exception $ex) {
$ex->getMessage();
}
}
}
public function sanitize_data($string) {
$searchArr = array("iframe", "script", "document", "write", "alert", "%", "@", "$", ";", "+", "|", "#", "<", ">", ")", "(", "'", "\'", ",", "and ", " &", "& ", "and", " and", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
$input_data = strtolower($string);
$input_data = str_replace($searchArr, "", $input_data);
$input_data = str_replace(" ", "-", $input_data);
//echo $input_data; die;
return $input_data;
}
/**
* checklogin() method is used to check admin logedin or not
* @param Null
* @return Array
*/
public function checklogin() {
if (($this->admin_type == "superadmin") || ($this->admin_type == "admin")) {
$auth = Zend_Auth::getInstance();
$hasIdentity = $auth->hasIdentity();
/* * ************* check admin identity *********** */
if (!$hasIdentity) {
$this->_redirect('admin/index/index');
}
} else {
$this->_redirect('admin/index/index');
}
}
}