| 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 June 2018
* Updated Date : 23 June 2018
* ************************************************************* */
class Admin_MastercategoryController extends Zend_Controller_Action {
public $dbAdapter;
public $perPageLimit;
public function init() {
/* Initialize db and session access */
$aConfig = $this->getInvokeArg('bootstrap')->getOptions();
$this->siteurl = $aConfig['bootstrap']['siteUrl'];
$this->stylecss = $aConfig['bootstrap']['stylecss'];
$this->per_page_record = 20;
$this->dbAdapter = Zend_Db_Table::getDefaultAdapter();
$auth = Zend_Auth::getInstance();
$authStorage = $auth->getStorage()->read();
$this->username = $authStorage->username;
$this->admin_type = $authStorage->role;
$this->current_time = time();
$_SERVER["DOCUMENT_ROOT"] = $_SERVER["DOCUMENT_ROOT"];
$this->catImgUrl = 'public/upload/'.$this->stylecss.'/CatThumb/';
$this->DIR_WRITE_MODE = 0777;
$this->large_image_width = $aConfig['bootstrap']['large_image_width'];
$this->large_image_height = $aConfig['bootstrap']['large_image_height'];
$this->medium_image_width = $aConfig['bootstrap']['medium_image_width'];
$this->medium_image_height = $aConfig['bootstrap']['medium_image_height'];
$this->small_image_width = $aConfig['bootstrap']['small_image_width'];
$this->small_image_height = $aConfig['bootstrap']['small_image_height'];
$this->table = 'tbl_mastercategary';
}
/**
* index() method is used to admin login for form call
* @param Null
* @return Array
*/
public function indexAction() {
//Check admin logedin or not
$this->checklogin();
$this->view->messages = $this->_helper->flashMessenger->getMessages();
$crud = new Admin_Model_CRUD();
$getData = array();
if ($this->getRequest()->isPost()) {
$getData = $this->getRequest()->getPost();
//print_r($getData);die;
/* $searchArr = array(
'Title' => $getData['Title'],
'rows' => $getData['rows'],
'page' => $getData['page'],
); */
$resultset = $crud->rv_select_all($this->table, ['*'], ['IsmarkForDel' => 0], ['Id' => 'DESC']);
//$crud->searchArrt = $searchArr;
//echo '<pre>';print_r($resultset);
$resulsetold = $crud->getCount($this->table, ['IsmarkForDel' => 0], 'Id');
if (count($resultset) > 0) {
foreach ($resultset as $resultkey => $resultval) {
$result1[] = [
'Id' => $resultval['Id'],
'categaryName' => $resultval['categaryName'],
'categaryImage' => $resultval['categaryImage'],
'IsActive' => $resultval['IsActive'] == 1 ? 'Active' : 'Deactive',
];
// print_r($result1);die;
}
}
$result = Zend_Json::encode($result1);
$newResult = Zend_Json::decode($result, false);
$finalResult["total"] = $resulsetold[0]['Id'];
$finalResult["rows"] = $newResult;
echo json_encode($finalResult);
exit;
}
}
public function editmastercategoryAction() {
//Check admin logedin or not
$this->checklogin();
$crud = new Admin_Model_CRUD();
// $form = new Admin_Form_Editcategory();
$pId = (int) $this->getRequest()->getParam("id");
// echo '<pre>'; print_r($pId);die;
// $form->setMethod("POST");
// $form->setAction("admin/mastercategory/mastereditcategory/Id/" . $pId);
// $form->setName("edit_category_page");
if ($this->getRequest()->isPost()) {
$getData = $this->getRequest()->getPost();
//echo '<pre>'; print_r($getData);die;
if ($getData) {
//-------Start Code for Approve and Publish content---------//
$images = $_FILES['Categary_img']['name'];
if (isset($getData['save']) == "Save") {
$Categary_img = $_FILES['Categary_img']['name'];
if (!empty($Categary_img)) {
$fileExt = $this->_helper->General->getFileExtension($images);
$allowedExtensions = ['jpg', 'jpeg', 'gif', 'png', 'webp'];
if(in_array($fileExt, $allowedExtensions, true)){
$orignalFolderName = $_SERVER["DOCUMENT_ROOT"] . "/" . $this->catImgUrl . $getData['cid'];
// echo $orignalFolderName; die;
$fileExtion = $this->_helper->General->getFileExtension($Categary_img);
$fileName = $getData['cid'].'_'.$this->current_time . '.' . $fileExtion;
$fileName1 = $getData['cid'].'_'.$this->current_time;
if (!file_exists($orignalFolderName)) {
mkdir($orignalFolderName, $this->DIR_WRITE_MODE, true);
}
$temp_file_name = $_FILES["Categary_img"]["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;
//echo "<pre>"; print_r($originalLargeFolder); die("chk");
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' ";
}
// echo "<pre>"; print_r($editPageData); die("chk");
$editPageData = [
// 'news_letter_id'=>($getData['news_letter_id']),
'categaryName' => ($getData['categaryName']),
'IsActive' => ($getData['IsActive']),
];
// echo $pId; die("chk");
if ($fileName != '') {
$editPageData['categaryImage'] = $fileName;
}
// echo "<pre>";print_r($editPageData);die;
$crud->rv_update($this->table, $editPageData, ['Id =?' => $getData['cid']]);
$this->_helper->flashMessenger->addMessage("Content has been updated successfully.");
$this->_redirect("/admin/mastercategory/index");
}
}
}
$result = $crud->getCmsdata($this->table, ['*'], ['Id' => $pId], ['Id' => 'DESC']);
// echo "<pre>"; print_r($result); die;
$editdata["Id"] = @$result->Id;
$editdata["categaryName"] = @$result->categaryName;
$editdata["categaryImage"] = @$result->categaryImage;
$editdata["IsActive"] = @$result->IsActive;
$this->view->editdata = $editdata;
// $form->populate($editdata);
$this->view->form = $form;
// echo '<pre>';print_r( $editdata);die;
//die('ok');
}
public function addmastercategoryAction() {
//Check admin logedin or not
$this->checklogin();
$crud = new Admin_Model_CRUD();
$form = new Admin_Form_Addcategory();
//echo '<pre>';print_r($form);die;
$pId = (int)$this->getRequest()->getParam("Id");
//echo '<pre>'; print_r($pId);die;
$form->setMethod("POST");
$form->setAction("admin/mastercategory/addmastercategory");
// $form->setName("add_category");
if ($this->getRequest()->isPost()) {
$getData = $this->getRequest()->getPost();
// echo $pId ;
// echo '<pre>'; print_r($getData);die;
if ($getData) {
$lastRow = $crud->getCmsdata($this->table, ['Id'], ['Id'], ['Id'=>'DESC']);
$page_id = $lastRow['Id'] +1;
//-------Start Code for Approve and Publish content---------//
$images = $_FILES['Categary_img']['name'];
if (isset($getData['save']) == "Save") {
$lastRow = $crud->getCmsdata($this->table, ['Id'], ['Id'], ['Id' => 'DESC']);
// echo "<pre>"; print_r($lastRow);die;
$lastInsertId = $lastRow['Id'] + 1;
// echo $lastInsertId; die;
$Categary_img = $_FILES['Categary_img']['name'];
$fileName = '';
if (!empty($Categary_img)) {
$fileExt = $this->_helper->General->getFileExtension($images);
$allowedExtensions = ['jpg', 'jpeg', 'gif', 'png', 'webp'];
if(in_array($fileExt, $allowedExtensions, true)){
$orignalFolderName = $_SERVER["DOCUMENT_ROOT"] . "/" . $this->catImgUrl . $lastInsertId;
// echo $_SERVER["DOCUMENT_ROOT"]; die();
$fileExtion = $this->_helper->General->getFileExtension($Categary_img);
$fileName = $page_id.'_'.$this->current_time . $fileExtion;
$fileName1 = $page_id.'_'.$this->current_time;
// echo $orignalFolderName ; die("kj");
if (!file_exists($orignalFolderName)) {
mkdir($orignalFolderName, $this->DIR_WRITE_MODE, true);
}
$temp_file_name = $_FILES["Categary_img"]["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' ";
}
}
$savePageData = [
// 'news_letter_id'=>($getData['news_letter_id']),
'categaryName' => ($getData['categaryName']),
'categaryImage' => $fileName,
'IsActive' => ($getData['IsActive']),
];
//echo "<pre>";print_r($editPageData);die;
$crud->rv_insert($this->table, $savePageData);
$this->view->successMessage = "Content has been saved successfully.";
$this->_helper->flashMessenger->addMessage("Content has been added successfully.");
$this->_redirect("/admin/mastercategory/index");
}
}
}
$this->view->form = $form;
}
public function deletemastercategoryAction() {
$this->checklogin();
$crud = new Admin_Model_CRUD();
$tId = (int) $this->getRequest()->getParam("id");
//echo $tId;die;
if ($tId) {
$checkdata = $crud->rv_select_row($this->table, ['Id'], ['Id' => $tId], ['Id' => 'asc']);
if (count($checkdata) > 0) {
$crud->rv_update($this->table, ['isMarkForDel'=> 1], ['Id =?'=>$tId]);
$this->_helper->flashMessenger->addMessage("Delete successfully.");
$this->_redirect("/admin/offers/index");
} else {
die('Oops some thing wrong!!.');
}
}
}
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');
}
}
}