| Server IP : 172.67.178.83 / Your IP : 216.73.217.141 Web Server : Apache System : Linux hosting01.arsenalhost.com 4.18.0-425.13.1.lve.el8.x86_64 #1 SMP Mon Feb 27 15:23:24 EST 2023 x86_64 User : corbizre ( 1013) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/corbizre/gotofindhomes.com3/components/Company/Controllers/ |
Upload File : |
<?php
/**
* Company index controller
* @author keeper
* @category
* @package
* @subpackage
* @copyright Copyright (c) 2005-2012 ITCrimea Ukraine Inc. (http://www.itcrimea.com)
* @license
*/
class Company_IndexController extends System_Controller_Db_Table
{
/**
* Documentation
* @author
* @return mixed
*/
public function indexAction()
{
$this->shift('get');
}
/**
* Documentation
* @author
* @return mixed
*/
public function getAction()
{
$ID = $this->getRequest()->getParam('ID', $this->getRequest()->getParam('cid', $this->getRequest()->getParam('id')));
User::checkAccess($ID);
parent::getAction();
}
/**
*@author Timur
*/
public function addAction()
{
User::checkAccess();
$objCompany = $this->_model->createRow();
$strTemplate = $this->getRequest()->getParam('template');
//$arrCategories = array();
$FileLogo = '';
if ($this->getRequest()->isPost()) {
//get company data
$objCompany->Domain = strtolower(trim($this->getRequest()->getParam('Domain', '')));
$objCompany->Name = ucfirst(trim($this->getRequest()->getParam('Name', '')));
$objCompany->Email = trim($this->getRequest()->getParam('Email', ''));
$objCompany->Theme = trim($this->getRequest()->getParam('Theme', ''));
$objCompany->Style = trim($this->getRequest()->getParam('Style', ''));
$objCompany->ItemRoute = trim($this->getRequest()->getParam('ItemRoute', ''));
$objCompany->CategoryRoute = trim($this->getRequest()->getParam('CategoryRoute', ''));
$objCompany->Enabled = intval($this->getRequest()->getParam('Enabled', 0));
$objCompany->FacebookAppID = trim($this->getRequest()->getParam('FacebookAppID', ''));
$objCompany->FacebookSecret = trim($this->getRequest()->getParam('FacebookSecret', ''));
$objCompany->TwitterKey = trim($this->getRequest()->getParam('TwitterKey', ''));
$objCompany->TwitterSecret = trim($this->getRequest()->getParam('TwitterSecret', ''));
$objCompany->LinkedinKey = trim($this->getRequest()->getParam('LinkedinKey', ''));
$objCompany->LinkedinSecret = trim($this->getRequest()->getParam('LinkedinSecret', ''));
//$arrCategories = $this->getRequest()->getParam('Category', '');
//check company info
if (!$objCompany->Domain) {
$this->addErrorMessage('Please enter domain');
}
if (!$objCompany->Name) {
$this->addErrorMessage('Please enter name');
}
if (!$objCompany->Email) {
$this->addErrorMessage('Please enter email');
}
if (!$objCompany->Theme) {
$this->addErrorMessage('Please choose theme');
}
//check company logo
$DirnameTmp = Image::getPathTemp();
if (isset($_FILES['FileLogo']) && $_FILES['FileLogo']['name']) {
$FileLogo = $this->uploadFile('FileLogo', $DirnameTmp, 'Logo', array('jpeg', 'jpg', 'gif','png'));
} elseif ($this->getRequest()->getParam('FileLogoCache')) {
$FileLogo = $this->getRequest()->getParam('FileLogoCache');
$FileLogo = preg_replace('/([^a-zA-Z_0-9\-_.]+)/', '', $FileLogo); // for security
} else {
if (!$objCompany->Logo_ID) {
$this->addErrorMessage('Please upload logo');
}
}
if (!$this->isErrorMessages()) {
// check domain
$select = $this->_select->reset()->from('companies')->where('Domain = ?', $objCompany->Domain);
if (is_object($this->_model->fetchRow($select))) {
$this->addErrorMessage('Sorry, domain "' . $objCompany->Domain . '" already taken for other company');
}
// check email
$validator = new Zend_Validate_EmailAddress();
if (!$validator->isValid($objCompany->Email)) {
$this->addErrorMessage('Email "' . $objCompany->Email . '" is not valid');
}
// check name
$select = $this->_select->reset()
->from('companies')
->where('Name = ?', $objCompany->Name);
if (is_object($this->_model->fetchRow($select))) {
$this->addErrorMessage('Sorry, name "' . $objCompany->Name . '" already taken for other company');
}
}
// save
if (!$this->isErrorMessages()) {
$objCompany->Theme = strtolower($objCompany->Theme);
$objCompany->Style = strtolower($objCompany->Style);
$objCompany->ItemRoute = strtolower($objCompany->ItemRoute);
$objCompany->CategoryRoute = strtolower($objCompany->CategoryRoute);
$objCompany->save();
if ($FileLogo) {
$tblImage = new Image_Table();
$objImage = null;
if ($objCompany->Logo_ID) {
$objImage = $objCompany->findParentRow('Image_Table', 'Logo');
}
if (!is_object($objImage)) {
$objImage = $tblImage->createRow();
}
$objImage->Name = $objCompany->Name;
$objImage->Desc = $objCompany->Name;
$objImage->Assign = 'company';
$objImage->AssignID = $objCompany->ID;
$objImage->Group = 'logo';
$objImage->File = $FileLogo;
$objImage->Path = '';
$objImage->Primary = 1;
$objImage->Active = 1;
$objImage->save();
$objImage->Path = $objImage->getPath();
$objImage->File = Image::moveFile($objImage->File, $DirnameTmp, Zend_Registry::get('AppFolder').$objImage->Path);
if ($objImage->File) {
$Image = Image::create(Zend_Registry::get('AppFolder').$objImage->Path.$objImage->File);
$objImage->Width = imagesx($Image);
$objImage->Height = imagesy($Image);
$objImage->save();
$tblImage->update(array('Primary'=>0), '`Assign` = \'company\' AND `AssignID` = '.$objCompany->ID.' AND `Group` = \'logo\' AND ID<>'.$objImage->ID);
$objCompany->Logo_ID = $objImage->ID;
$objCompany->save();
} else {
$objImage->delete();
$this->addErrorMessage('An error occurred while saving the logo image. Please try again');
}
}
$this->view->row = $objCompany->toArray();
// create config
$FilenameConfig = Zend_Registry::get('AppFolder').DIRECTORY_SEPARATOR.'configs'.DIRECTORY_SEPARATOR.'System'.DIRECTORY_SEPARATOR.$objCompany->Domain.'_config.ini';
$FilenameConfig = str_replace('\\', '\\\\', $FilenameConfig);
$this->view->SystemConfig = System_Components::getComponentConfig('System')->toArray();
$strConfigData = $this->view->render('/company/index/generate-config.tpl');
try {
file_put_contents($FilenameConfig, $strConfigData);
chmod($FilenameConfig, 0777);
} catch (Exception $e) {
$this->addErrorMessage('Can\'t create config file');
}
$objCompany->save();
$this->addOkMessage('New company "' . $objCompany->Name . '" has been successfully added.');
$this->render('add' . (($strTemplate != '') ? '-' : '') . $strTemplate . '-success');
return;
}
}
$this->view->FileLogo = $FileLogo;
$this->view->row = $objCompany->toArray();
$this->render('add' . (($strTemplate != '') ? '-' : '') . $strTemplate);
}
/**
* Documentation
* @author
* @return mixed
*/
public function editAction()
{
$ID = $this->getRequest()->getParam('ID', $this->getRequest()->getParam('id'));
User::checkAccess($ID);
$strTemplate = $this->getRequest()->getParam('template');
$objCompany = $this->_model->find($ID)->current();
if (!is_object($objCompany)) {
throw new Zend_Exception('Can\'t find company by provided ID');
}
$Domain = $objCompany->Domain;
$FileLogo = '';
if ($this->getRequest()->isPost()) {
//get company data
$objCompany->Domain = trim($this->getRequest()->getParam('Domain', ''));
$objCompany->Name = ucfirst(trim($this->getRequest()->getParam('Name', '')));
$objCompany->Email = trim($this->getRequest()->getParam('Email', ''));
$objCompany->Theme = trim($this->getRequest()->getParam('Theme', ''));
$objCompany->Style = trim($this->getRequest()->getParam('Style', ''));
$objCompany->ItemRoute = trim($this->getRequest()->getParam('ItemRoute', ''));
$objCompany->CategoryRoute = trim($this->getRequest()->getParam('CategoryRoute', ''));
$objCompany->Enabled = intval($this->getRequest()->getParam('Enabled', 0));
$objCompany->FacebookAppID = trim($this->getRequest()->getParam('FacebookAppID', ''));
$objCompany->FacebookSecret = trim($this->getRequest()->getParam('FacebookSecret', ''));
$objCompany->TwitterKey = trim($this->getRequest()->getParam('TwitterKey', ''));
$objCompany->TwitterSecret = trim($this->getRequest()->getParam('TwitterSecret', ''));
$objCompany->LinkedinKey = trim($this->getRequest()->getParam('LinkedinKey', ''));
$objCompany->LinkedinSecret = trim($this->getRequest()->getParam('LinkedinSecret', ''));
$arrCategories = $this->getRequest()->getParam('Category', '');
//check company info
if (!$objCompany->Domain) {
$this->addErrorMessage('Please enter company domain');
}
if (!$objCompany->Name) {
$this->addErrorMessage('Please enter company name');
}
if (!$objCompany->Email) {
$this->addErrorMessage('Please enter company email');
}
// check company logo
$DirnameTmp = Image::getPathTemp();
if (isset($_FILES['FileLogo']) && $_FILES['FileLogo']['name']) {
$FileLogo = $this->uploadFile('FileLogo', $DirnameTmp, 'Company Logo', array('jpeg', 'jpg', 'gif', 'png'));
} elseif ($this->getRequest()->getParam('FileLogoCache')) {
$FileLogo = $this->getRequest()->getParam('FileLogoCache');
$FileLogo = preg_replace('/([^a-zA-Z_0-9\-_.]+)/', '', $FileLogo); // for security
} else {
if (!$objCompany->Logo_ID) {
$this->addErrorMessage('Please upload company\'s logo');
}
}
if (!$this->isErrorMessages()) {
// check domain
$select = $this->_select->reset()->from('companies')->where('Domain = ?', $objCompany->Domain)->where('ID <> ?', $ID);
if (is_object($this->_model->fetchRow($select))) {
$this->addErrorMessage('Sorry, domain "' . $objCompany->Domain . '" already taken for other company');
}
// check email
$validator = new Zend_Validate_EmailAddress();
if (!$validator->isValid($objCompany->Email)) {
$this->addErrorMessage('Email "' . $objCompany->Email . '" is not valid');
}
// check name
$select = $this->_select->reset()
->from('companies')
->where('Name = ?', $objCompany->Name)
->where('ID <> ?', $objCompany->ID);
if (is_object($this->_model->fetchRow($select))) {
$this->addErrorMessage('Sorry, name "' . $objCompany->Name . '" already taken for other company');
}
}
// save
if (!$this->isErrorMessages()) {
$objCompany->Theme = strtolower($objCompany->Theme);
$objCompany->Style = strtolower($objCompany->Style);
$objCompany->ItemRoute = strtolower($objCompany->ItemRoute);
$objCompany->CategoryRoute = strtolower($objCompany->CategoryRoute);
$objCompany->save();
if ($FileLogo) {
$tblImage = new Image_Table();
$objImage = null;
if ($objCompany->Logo_ID) {
$objImage = $objCompany->findParentRow('Image_Table', 'Logo');
}
if (!is_object($objImage)) {
$objImage = $tblImage->createRow();
}
$objImage->Name = $objCompany->Name;
$objImage->Desc = $objCompany->Name;
$objImage->Assign = 'company';
$objImage->AssignID = $objCompany->ID;
$objImage->Group = 'logo';
$objImage->File = $FileLogo;
$objImage->Path = '';
$objImage->Primary = 1;
$objImage->Active = 1;
$objImage->save();
$objImage->Path = $objImage->getPath();
$objImage->File = Image::moveFile($objImage->File, $DirnameTmp, Zend_Registry::get('AppFolder').$objImage->Path);
if ($objImage->File) {
$Image = Image::create(Zend_Registry::get('AppFolder').$objImage->Path.$objImage->File);
$objImage->Width = imagesx($Image);
$objImage->Height = imagesy($Image);
$objImage->save();
$tblImage->update(array('Primary'=>0), '`Assign` = \'company\' AND `AssignID` = '.$objCompany->ID.' AND `Group` = \'logo\' AND ID<>'.$objImage->ID);
$objCompany->Logo_ID = $objImage->ID;
$objCompany->save();
} else {
$objImage->delete();
$this->addErrorMessage('An error occurred while saving the logo image. Please try again');
}
}
$this->view->row = $objCompany->toArray();
// create config
if ($Domain != $objCompany->Domain) {
$OldFilenameConfig = Zend_Registry::get('AppFolder').DIRECTORY_SEPARATOR.'configs'.DIRECTORY_SEPARATOR.'System'.DIRECTORY_SEPARATOR.$Domain.'_config.ini';
$OldFilenameConfig = str_replace('\\', '\\\\', $OldFilenameConfig);
unlink($OldFilenameConfig);
}
$FilenameConfig = Zend_Registry::get('AppFolder').DIRECTORY_SEPARATOR.'configs'.DIRECTORY_SEPARATOR.'System'.DIRECTORY_SEPARATOR.$objCompany->Domain.'_config.ini';
$FilenameConfig = str_replace('\\', '\\\\', $FilenameConfig);
$this->view->SystemConfig = System_Components::getComponentConfig('System')->toArray();
$strConfigData = $this->view->render('/company/index/generate-config.tpl');
try {
file_put_contents($FilenameConfig, $strConfigData);
chmod($FilenameConfig, 0777);
} catch (Exception $e) {
$this->addErrorMessage('Can\'t create config file');
}
$this->addOkMessage('Company "' . $objCompany->Name . '" has been successfully updated.');
$this->render('edit' . (($strTemplate != '') ? '-' : '') . $strTemplate . '-success');
return;
}
}
$this->view->Categories = $arrCategories;
$this->view->FileLogo = $FileLogo;
$this->view->row = $objCompany->toArray();
$this->render('edit' . (($strTemplate != '') ? '-' : '') . $strTemplate);
}
/**
*@author
*/
public function getlistAction()
{
$strAccess = System_User::getUser()->Access;
$this->getRequest()->setParam('results', $this->getRequest()->getParam('results', 500));
$Filter = $this->getFilter();
$Filter->Blank = trim($this->getRequest()->getParam('Blank', $Filter->Blank));
if ($strAccess) {
$this->_select->where('ID IN (?)', unserialize($strAccess));
$this->_selectCount->where('ID IN (?)', unserialize($strAccess));
}
if ($Filter->Blank) {
switch ($Filter->Blank) {
case 'FFFFCC':
$this->_select->where('QBlankPOpt <> ?', 0)->where('QItems <> ?', 0);
$this->_selectCount->where('QBlankPOpt <> ?', 0)->where('QItems <> ?', 0);
break;
case 'FFBBBB':
$this->_select->where('QItems = ?', 0);
$this->_selectCount->where('QItems = ?', 0);
break;
}
}
$paramEmail = $this->getRequest()->getParam('Email',$Filter->Email);
if (!empty($paramEmail)) {
$this->_select->where('Email LIKE ?','%'.$paramEmail.'%');
$this->_selectCount->where('Email LIKE ?','%'.$paramEmail.'%');
$Filter->Email = $paramEmail;
}
$paramName = $this->getRequest()->getParam('Name',$this->Filter->Name);
if (!empty($paramName)) {
$this->_select->where('Name LIKE ?','%'.$paramName.'%');
$this->_selectCount->where('Name LIKE ?','%'.$paramName.'%');
$Filter->Name = $paramName;
}
$this->view->Request = $this->getRequest()->getParams();
parent::getlistAction();
}
/**
* action to activate the company (company will be chacked and created the config in the first run)
* @author keeper
*/
public function enableAction()
{
System_Company::Required();
$arrCompany = System_Company::get();
$this->view->row = $arrCompany;
if ($arrCompany['Status'] == Company::STATUS_ACTIVE) {
$this->addErrorMessage('Company "'.$arrCompany['Name'].'" already active');
$this->addOkMessage('enable-success');
} elseif ($arrCompany['Status'] == Company::STATUS_NEW) {
// check the domain
$IP = gethostbyname($arrCompany['Domain']);
if (!$IP) {
$this->addErrorMessage('Domain "'.$arrCompany['Domain'].'" does not works');
return;
}
if ($IP != $_SERVER['SERVER_ADDR']) {
$this->addErrorMessage('Please assign domain "'.$arrCompany['Domain'].'" to IP address "'.$_SERVER['SERVER_ADDR'].'" before continue');
return;
}
// create config
$FilenameConfig = Zend_Registry::get('AppFolder').DIRECTORY_SEPARATOR.'configs'.DIRECTORY_SEPARATOR.'System'.DIRECTORY_SEPARATOR.$arrCompany['Domain'].'_config.ini';
$FilenameConfig = str_replace('\\', '\\\\', $FilenameConfig);
if (!file_exists($FilenameConfig)) {
$strConfigData = $this->view->render('/company/index/generate-config.tpl');
try {
$f = fopen($FilenameConfig, 'w');
fwrite($f, $strConfigData);
fclose($f);
chmod($FilenameConfig, 0777);
} catch (Exception $e) {
$this->addErrorMessage('Can\'t create config file');
$objLog = Log::add('Company', 'Enable', $arrCompany['ID'], Log::SEVERITY_ERR, Log::IMPORTANCE_HIGH, 'Can\'t create config file when activate company "'.$arrCompany['Name'].'". Caught exception: ', $e->getMessage(), array('filename'=>$FilenameConfig));
$objLog->Company_ID = $arrCompany['ID'];
$objLog->save();
return;
}
}
}
System_Company::set('Status', Company::STATUS_ACTIVE);
$objLog = Log::add('Company', 'Enable', $arrCompany['ID'], Log::SEVERITY_INFO, Log::IMPORTANCE_MIDDLE, 'Company "'.$arrCompany['Name'].'" has been actived', $arrCompany);
$objLog->Company_ID = $arrCompany['ID'];
$objLog->save();
$this->addOkMessage('Company "'.$arrCompany['Name'].'" has been successfully actived');
$this->render('enable-success');
}
/**
* disable the company
* @author keeper
*/
public function disableAction()
{
System_Company::Required();
$arrCompany = System_Company::get();
$this->view->row = $arrCompany;
if ($arrCompany['Status'] == Company::STATUS_DISABLED) {
$this->addOkMessage('Company "'.$arrCompany['Name'].'" already disabled');
$this->render('disable-success');
} elseif ($arrCompany['Status'] == Company::STATUS_NEW) {
$this->addOkMessage('Company "'.$arrCompany['Name'].'" not activated yet');
$this->render('disable-success');
}
System_Company::set('Status', Company::STATUS_DISABLED);
$objLog = Log::add('Company', 'Disable', $arrCompany['ID'], Log::SEVERITY_INFO, Log::IMPORTANCE_MIDDLE, 'Company "'.$arrCompany['Name'].'" has been disabled', $arrCompany);
$objLog->Company_ID = $arrCompany['ID'];
$objLog->save();
$this->addOkMessage('Company "'.$arrCompany['Name'].'" has been disabled');
$this->render('disable-success');
}
public function getStylesAction()
{
$Theme = $this->getRequest()->getParam('Theme', '');
$strTemplate = $this->getRequest()->getParam('template');
$this->view->rows = Company::getStyles($Theme);
$this->render('get-styles' . (($strTemplate != '') ? '-' : '') . $strTemplate);
}
public function useTagsAction()
{
$strTemplate = $this->getRequest()->getParam('template');
$CompanyID = $this->getRequest()->getParam('companyid');
User::checkAccess($CompanyID);
$objCompany = $this->_model->find($CompanyID)->current();
if (!is_object($objCompany)) {
throw new Zend_Exception('Can\'t find company by provided CompanyID');
}
$UseTags = $this->getRequest()->getParam('usetags', '');
$objCompany->UseTags = ($UseTags) ? 1 : 0;
$objCompany->save();
$this->addOkMessage('Switching render have been successfull');
$this->render('use-tags' . (($strTemplate != '') ? '-' : '') . $strTemplate);
}
public function useBuynowAction()
{
$strTemplate = $this->getRequest()->getParam('template');
$CompanyID = $this->getRequest()->getParam('companyid');
User::checkAccess($CompanyID);
$objCompany = $this->_model->find($CompanyID)->current();
if (!is_object($objCompany)) {
throw new Zend_Exception('Can\'t find company by provided CompanyID');
}
$UseBuynow = $this->getRequest()->getParam('usebuynow', '');
$objCompany->UseBuynow = ($UseBuynow) ? 1 : 0;
$objCompany->save();
$this->addOkMessage('Switching buynow have been successfull');
$this->render('use-buynow' . (($strTemplate != '') ? '-' : '') . $strTemplate);
}
public function saveRobotsAction()
{
$ID = $this->getRequest()->getParam('companyid');
$strTemplate = $this->getRequest()->getParam('template');
User::checkAccess($ID);
$objCompany = $this->_model->find($ID)->current();
if (!is_object($objCompany)) {
throw new Zend_Exception('Can\'t find objCompany by provided ID');
}
if ($this->getRequest()->isPost()) {
$objCompany->Robots = $this->getRequest()->getParam('Text', '');
$objCompany->save();
$this->view->Robots = $objCompany->Robots;
$this->render('save-robots' . (($strTemplate != '') ? '-' : '') . $strTemplate . '-success');
return;
}
$this->view->Robots = $objCompany->Robots;
$this->view->CompanyID = $ID;
$this->render('save-robots' . (($strTemplate != '') ? '-' : '') . $strTemplate);
}
/**
* get the file from $_FILES and move to requested folder
* @author keeper
* @param string $FieldName
* @param string $Dirname
* @param string $FieldDesc
* @param array $Extensions
* @return string Name of uploaded file
*/
function uploadFile($FieldName, $Dirname, $FieldDesc, $Extensions=array('pdf','jpeg','jpg','tif','tiff','png','gif','doc','docx','xls','xlsx'))
{
if ($_FILES[$FieldName]['error']) {
if ($_FILES[$FieldName]['error'] == 4) {
$this->addErrorMessage('Please upload '.$FieldDesc);
} else {
$this->addErrorMessage('Can\'t upload '.$FieldDesc);
}
} else {
if (!is_dir($Dirname)) {
if (!mkdir($Dirname, 0777)) {
$this->addErrorMessage('Can\'t create dir for '.$FieldDesc);
}
}
$nameonly = substr($_FILES[$FieldName]['name'], 0, strrpos($_FILES[$FieldName]['name'], '.'));
$extension = substr($_FILES[$FieldName]['name'], strrpos($_FILES[$FieldName]['name'], '.')+1);
$nameonly = preg_replace('/([^a-zA-Z_0-9\-_.]+)/', '', $nameonly);
if (!$nameonly) {
$this->addErrorMessage($FieldDesc.' name is not valid');
} elseif (strpos($_FILES[$FieldName]['name'], '.') === false) {
$this->addErrorMessage($FieldDesc.' extension is undefined');
} else {
if (!in_array(strtolower($extension), $Extensions)) {
$this->addErrorMessage($FieldDesc.' extension is not valid');
} else {
$nameonly = substr($nameonly, 0, 40);
$Filename = $nameonly.'.'.$extension;
$i = 0;
while (file_exists($Dirname . $Filename)) {
$Filename = $nameonly.$i.'.'.$extension;
$i++;
}
if (!move_uploaded_file($_FILES[$FieldName]['tmp_name'], $Dirname.$Filename)) {
$this->addErrorMessage('Can\'t move '.$FieldDesc);
} else {
chmod($Dirname.$Filename, 0777);
}
return $Filename;
}
}
}
return;
}
}