Location: PHPKode > projects > HikaShop > back/controllers/config.php
<?php
/**
 * @package		HikaShop for Joomla!
 * @version		1.4.3
 * @author		hikashop.com
 * @copyright	(C) 2010 HIKARI SOFTWARE. All rights reserved.
 * @license		GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?>
<?php
class ConfigController extends hikashopController{
	function __construct($config = array())
	{
		parent::__construct($config);
		$this->registerDefaultTask('config');
	}
	function save(){
		$this->store();
		return $this->cancel();
	}
	function apply(){
		$this->store();
		return $this->display();
	}
	function store(){
		$app =& JFactory::getApplication();
		JRequest::checkToken() or die( 'Invalid Token' );
		$image = hikashop::get('class.file');
		$formData = JRequest::getVar( 'config', array(), '', 'array' );
		$ids = $image->storeFiles('default_image',0);
		if(!empty($ids)){
			$data = $image->get($ids[0]);
			$formData['default_image']=$data->file_path;
		}
		if(hikashop::level(2)){
			$ids = $image->storeFiles('watermark',0,'watermark');
			if(!empty($ids)){
				$data = $image->get($ids[0]);
				$formData['watermark']=$data->file_path;
			}
		}
		$formData['store_address']=JRequest::getVar( 'config_store_address','','','string',JREQUEST_ALLOWRAW);
		if(!empty($formData['cart_item_limit']) && !is_numeric($formData['cart_item_limit'])){
			$formData['cart_item_limit']=0;
		}
		if(!$this->_checkWorkflow($formData)){
			$app->enqueueMessage('Checkout workflow invalid. The modification is ignored. See <a style="font-size:1.2em;text-decoration:underline" href="http://www.hikashop.com/support/documentation/integrated-documentation/54-hikashop-config.html#main" target="_blank" >the documentation</a> for more information on how to configure that option');
			unset($formData['checkout']);
			return true;
		}
		if(!empty($formData['weight_symbols'])){
			$symbols = explode(',',$formData['weight_symbols']);
			$weightHelper = hikashop::get('helper.weight');
			$possibleSymbols = array_keys($weightHelper->conversion);
			$okSymbols = array();
			foreach($symbols as $k => $symbol){
				if(!in_array($symbol,$possibleSymbols)){
					$app->enqueueMessage('The weight unit "'.$symbol.'" is not in the list of possible units : '.implode(',',$possibleSymbols));
				}else{
					$okSymbols[]=$symbol;
				}
			}
			$formData['weight_symbols'] = implode(',',$okSymbols);
		}
		if(empty($formData['weight_symbols'])){
			$app->enqueueMessage('No valid weight unit entered. The system put back the default units.');
			$formData['weight_symbols']='kg,g';
		}
		if(!empty($formData['volume_symbols'])){
			$symbols = explode(',',$formData['volume_symbols']);
			$weightHelper = hikashop::get('helper.volume');
			$possibleSymbols = array_keys($weightHelper->conversion);
			$okSymbols = array();
			foreach($symbols as $k => $symbol){
				if(!in_array($symbol,$possibleSymbols)){
					$app->enqueueMessage('The dimension unit "'.$symbol.'" is not in the list of possible units : '.implode(',',$possibleSymbols));
				}else{
					$okSymbols[]=$symbol;
				}
			}
			$formData['volume_symbols'] = implode(',',$okSymbols);
		}
		if(empty($formData['volume_symbols'])){
			$app->enqueueMessage('No valid dimension unit entered. The system put back the default units.');
			$formData['volume_symbols']='m,dm,cm,mm';
		}
		$config =& hikashop::config();
		$status = $config->save($formData);
		if($status){
			$app->enqueueMessage(JText::_( 'HIKASHOP_SUCC_SAVED' ), 'message');
		}else{
			$app->enqueueMessage(JText::_( 'ERROR_SAVING' ), 'error');
		}
		$pluginsClass = hikashop::get('class.plugins');
		$paramsPlugins = JRequest::getVar('params',array(),'','array');
		foreach($paramsPlugins as $group => $paramsPluginsOneGroup){
			foreach($paramsPluginsOneGroup as $name => $paramsPlugin){
				$plugin = $pluginsClass->getByName($group,$name);
				if(!empty($plugin)){
					$plugin->params = $paramsPlugin;
					$pluginsClass->save($plugin);
				}
			}
		}
		$config->load();
	}
	function _checkWorkflow(&$formData){
		if(empty($formData['checkout'])){
			return false;
		}
		$formData['checkout'] = trim($formData['checkout']);
		$steps = explode(',',$formData['checkout']);
		foreach($steps as $step){
			if(empty($step)){
				return false;
			}
			$views = explode('_',$step);
			foreach($views as $view){
				if(!in_array($view,array('login','address','shipping','payment','confirm','coupon','cart','status','fields','terms','end'))){
					return false;
				}
			}
		}
		return true;
	}
	function display(){
		JRequest::setVar( 'layout', 'config'  );
		return parent::display();
	}
	function test(){
		$app =& JFactory::getApplication();
		$this->store();
		$config =& hikashop::config();
		$user = hikashop::loadUser(true);
		$mailClass = hikashop::get('class.mail');
		$addedName = $config->get('add_names',true) ? $mailClass->cleanText(@$user->name) : '';
		$true = true;
		$mail = $mailClass->get('test',$true);
		$mailClass->mailer->AddAddress($user->user_email,$addedName);
		$mail->subject = 'Test e-mail from '.HIKASHOP_LIVE;
		$mail->altbody = 'This test email confirms that your configuration enables HikaShop to send emails normally.';
		$mail->html=0;
		$mail->debug = 1;
		$result = $mailClass->sendMail($mail);
		if(!$result){
			$bounce = $config->get('bounce_email');
			if(!empty($bounce)){
				$app->enqueueMessage(JText::sprintf('ADVICE_BOUNCE',$bounce),'notice');
			}
		}
		return $this->display();
	}
	function seereport(){
		$config =& hikashop::config();
		$reportPath = JPath::clean(HIKASHOP_ROOT.trim(html_entity_decode($config->get('cron_savepath'))));
		$logFile = file_get_contents($reportPath);
		if(empty($logFile)){
			hikashop::display(JText::_('EMPTY_LOG'),'info');
		}else{
			echo nl2br($logFile);
		}
	}
	function cleanreport(){
		jimport('joomla.filesystem.file');
		$config =& hikashop::config();
		$reportPath = JPath::clean(HIKASHOP_ROOT.trim(html_entity_decode($config->get('cron_savepath'))));
		if(is_file($reportPath)){
			$result = JFile::delete($reportPath);
			if($result){
				hikashop::display(JText::_('SUCC_DELETE_LOG'),'success');
			}else{
				hikashop::display(JText::_('ERROR_DELETE_LOG'),'error');
			}
		}else{
			hikashop::display(JText::_('EXIST_LOG'),'info');
		}
	}
	function cancel(){
		$this->setRedirect( hikashop::completeLink('dashboard',false,true) );
	}
	function language(){
		JRequest::setVar( 'layout', 'language'  );
		return parent::display();
	}
	function savelanguage(){
		JRequest::checkToken() or die( 'Invalid Token' );
		$this->_savelanguage();
		return $this->language();
	}
	function latest(){
		return $this->language();
	}
	function savecss(){
		JRequest::checkToken() or die( 'Invalid Token' );
		$file = JRequest::getCmd('file');
		if(!preg_match('#^([-_a-z0-9]*)_([-_a-z0-9]*)$#i',$file,$result)){
			hikashop::display('Could not load the file '.$file.' properly');
			exit;
		}
		$type = $result[1];
		$fileName = $result[2];
		jimport('joomla.filesystem.file');
		$path = HIKASHOP_MEDIA.'css'.DS.$type.'_'.$fileName.'.css';
		$csscontent = JRequest::getString('csscontent');
		$alreadyExists = file_exists($path);
		if(JFile::write($path, $csscontent)){
			hikashop::display(JText::_('HIKASHOP_SUCC_SAVED'),'success');
			if(!$alreadyExists){
				$js = "var optn = document.createElement(\"OPTION\");
						optn.text = '$fileName'; optn.value = '$fileName';
						mydrop = window.top.document.getElementById('".JRequest::getCmd('var')."_choice');
						mydrop.options.add(optn);
						lastid = 0; while(mydrop.options[lastid+1]){lastid = lastid+1;} mydrop.selectedIndex = lastid;
						window.top.updateCSSLink('".JRequest::getCmd('var')."','$type','$fileName');";
				$doc =& JFactory::getDocument();
				$doc->addScriptDeclaration( $js );
			}
		}else{
			hikashop::display(JText::sprintf('FAIL_SAVE',$path),'error');
		}
		return $this->css();
	}
	function css(){
		JRequest::setVar( 'layout', 'css'  );
		return parent::display();
	}
	function send(){
		JRequest::checkToken() or die( 'Invalid Token' );
		$bodyEmail = JRequest::getString('mailbody');
		$code = JRequest::getString('code');
		JRequest::setVar('code',$code);
		if(empty($code)) return;
		$config =& hikashop::config();
		$user = hikashop::loadUser(true);
		$mailClass = hikashop::get('class.mail');
		$addedName = $config->get('add_names',true) ? $mailClass->cleanText(@$user->name) : '';
		$true = true;
		$mail = $mailClass->get('language',$true);
		$mailClass->mailer->AddAddress($user->user_email,$addedName);
		$mailClass->mailer->AddAddress('hide@address.com','Hikashop Translation Team');
		$mail->subject = '[HIKASHOP LANGUAGE FILE] '.$code;
		$mail->altbody = 'The website '.HIKASHOP_LIVE.' using HikaShop '.$config->get('level').$config->get('version').' sent a language file : '.$code;
		$mail->altbody .= "\n"."\n"."\n".$bodyEmail;
		$mail->html=0;
		jimport('joomla.filesystem.file');
		$path = JPath::clean(JLanguage::getLanguagePath(JPATH_ROOT).DS.$code.DS.$code.'.com_hikashop.ini');
		$mailClass->mailer->AddAttachment($path);
		$result = $mailClass->sendMail($mail);
		if($result){
			hikashop::display(JText::_('THANK_YOU_SHARING'),'success');
		}else{
		}
	}
	function share(){
		JRequest::checkToken() or die( 'Invalid Token' );
		if($this->_savelanguage()){
			JRequest::setVar( 'layout', 'share' );
			return parent::display();
		}else{
			return $this->language();
		}
	}
	function _savelanguage(){
		jimport('joomla.filesystem.file');
		$code = JRequest::getString('code');
		JRequest::setVar('code',$code);
		$content = JRequest::getVar('content','','','string',JREQUEST_ALLOWRAW);
		if(empty($code)) return;
		$content_override = JRequest::getVar('content_override','','','string',JREQUEST_ALLOWRAW);
		if(!empty($content_override)){
			$path = JLanguage::getLanguagePath(JPATH_ROOT).DS.'overrides'.DS.$code.'.override.ini';
			$result = JFile::write($path, $content_override);
			if(!$result){
				hikashop::display(JText::sprintf('FAIL_SAVE',$path),'error');
			}
		}
		if(empty($content)) return;
		$path = JLanguage::getLanguagePath(JPATH_ROOT).DS.$code.DS.$code.'.com_hikashop.ini';
		$result = JFile::write($path, $content);
		if($result){
			hikashop::display(JText::_('HIKASHOP_SUCC_SAVED'),'success');
			$updateHelper =& hikashop::get('helper.update');
			$updateHelper->installMenu($code);
			$js = "window.top.document.getElementById('image$code').src = '".HIKASHOP_IMAGES."icons/icon-16-edit.png'";
			$doc =& JFactory::getDocument();
			$doc->addScriptDeclaration( $js );
		}else{
			hikashop::display(JText::sprintf('FAIL_SAVE',$path),'error');
		}
		return $result;
	}
}
Return current item: HikaShop