235 lines
6.1 KiB
PHP
235 lines
6.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* SOTESHOP/stShopInfoPlugin
|
|
*
|
|
* Ten plik należy do aplikacji stShopInfoPlugin opartej na licencji (Professional License SOTE).
|
|
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
|
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
|
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
|
*
|
|
* @package stShopInfoPlugin
|
|
* @subpackage actions
|
|
* @copyright SOTE (www.sote.pl)
|
|
* @license http://www.sote.pl/license/sote (Professional License SOTE)
|
|
* @version $Id: actions.class.php 4651 2009-02-04 12:51:04Z pawel $
|
|
* @author Paweł Byszewski <pawel.byszewski@sote.pl>
|
|
* @author Michal Prochowski <michal.prochowski@sote.pl>
|
|
*/
|
|
|
|
/**
|
|
* Klasa stShopInfoBackendActions
|
|
*
|
|
* @package stShopInfoPlugin
|
|
* @subpackage actions
|
|
*/
|
|
class stShopInfoBackendActions extends autoStShopInfoBackendActions
|
|
{
|
|
/**
|
|
* Wyświetlanie formularza danych sklepu
|
|
*/
|
|
public function executeIndex()
|
|
{
|
|
return $this->redirect('@stShopInfoPlugin?action=config');
|
|
}
|
|
|
|
public function validateConfig()
|
|
{
|
|
$request = $this->getRequest();
|
|
$i18n = $this->getContext()->getI18N();
|
|
|
|
if ($request->getMethod() == sfRequest::POST)
|
|
{
|
|
$data = $this->getRequestParameter('config');
|
|
|
|
if ($request->hasError('config{town}') || $request->hasError('config{code}'))
|
|
{
|
|
$request->setError('config{code_town}', $i18n->__('Proszę uzupełnić pole.'));
|
|
$request->removeError('config{town}');
|
|
$request->removeError('config{code}');
|
|
}
|
|
|
|
if ($request->hasError('config{street}') || $request->hasError('config{house}'))
|
|
{
|
|
$request->setError('config{address}', $i18n->__('Proszę uzupełnić pole.'));
|
|
$request->removeError('config{street}');
|
|
$request->removeError('config{house}');
|
|
}
|
|
}
|
|
|
|
return !$request->hasErrors();
|
|
}
|
|
|
|
/**
|
|
* Wyświetlanie informacji o licencji
|
|
*/
|
|
public function executeRegister()
|
|
{
|
|
$this->config = stConfig::getInstance($this->getContext(), 'stRegister');
|
|
|
|
$this->menu_items = $this->getMenuItems();
|
|
|
|
$this->showChangeLicenseButton = false;
|
|
|
|
if (stLicense::isOpen()) $this->showChangeLicenseButton = true;
|
|
|
|
$i18n = $this->getContext()->getI18N();
|
|
|
|
$this->getBreadcrumbsBuilder()->getDefaultBreadcrumbs()->add($i18n->__('Informacje o licencji'));
|
|
}
|
|
|
|
/**
|
|
* Wyświetlanie zmiany numeru licencji
|
|
*/
|
|
public function executeChangeLicense()
|
|
{
|
|
$this->config = stConfig::getInstance($this->getContext(), 'stRegister');
|
|
|
|
$this->menu_items = $this->getMenuItems();
|
|
|
|
if ($this->getRequest()->getMethod() == sfRequest::POST)
|
|
{
|
|
$license = $this->getRequest()->getParameter('license_number');
|
|
|
|
$this->config->set('license', trim($license));
|
|
|
|
$this->config->save();
|
|
|
|
$stLicense = new stLicense($license);
|
|
|
|
$stLicense->activateInSote();
|
|
|
|
$this->setFlash('notice', 'Twoje zmiany zostały zapisane');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Walidacja numeru licencji
|
|
*/
|
|
public function validateChangeLicense()
|
|
{
|
|
if ($this->getRequest()->getMethod() == sfRequest::POST)
|
|
{
|
|
$i18n = $this->getContext()->getI18N();
|
|
|
|
$license = $this->getRequest()->getParameter('license_number');
|
|
|
|
if (!$license)
|
|
{
|
|
$this->getRequest()->setError('license_number', $i18n->__('Proszę uzupełnić pole.'));
|
|
return false;
|
|
}
|
|
|
|
$params = array(
|
|
'min' => 29,
|
|
'min_error' => $i18n->__('Proszę sprawdzić czy numer licencji oraz jego format są poprawne.<br/>Numer licencji powinien zawierać 29 znaków w formacie xxxx-xxxx-xxxx-xxxx-xxxx-xxxx.'),
|
|
'max' => 29,
|
|
'max_error' => $i18n->__('Proszę sprawdzić czy numer licencji oraz jego format są poprawne.<br/>Numer licencji powinien zawierać 29 znaków w formacie xxxx-xxxx-xxxx-xxxx-xxxx-xxxx.'),
|
|
);
|
|
|
|
$sfStringValidator = new sfStringValidator();
|
|
$sfStringValidator->initialize($this->getContext(), $params);
|
|
if (!$sfStringValidator->execute($license, $error))
|
|
{
|
|
$this->getRequest()->setError('license_number', $error);
|
|
return false;
|
|
}
|
|
|
|
if (stLicense::isCommercial())
|
|
{
|
|
$this->getRequest()->setError('license_number', $i18n->__('Nie można zmienić numeru licencji wersji komercyjnej.'));
|
|
return false;
|
|
}
|
|
|
|
$stLicense = new stLicense($license);
|
|
|
|
if ($stLicense->getType() !== stLicense::LICENSE_TYPE_COMMERCIAL)
|
|
{
|
|
$this->getRequest()->setError('license_number', $i18n->__('Numer licencji wersji Open może zostać zmieniony tylko na numer licencji wersji komercyjnej.'));
|
|
return false;
|
|
}
|
|
|
|
if (!$stLicense->checkInSote())
|
|
{
|
|
$this->getRequest()->setError('license_number', $i18n->__('Numer licencji jest nieprawidłowy.'));
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Akcja w przypadku błędu w uzupełnianiu pól
|
|
*/
|
|
public function handleErrorChangeLicense()
|
|
{
|
|
$this->config = stConfig::getInstance($this->getContext(), 'stRegister');
|
|
|
|
$this->menu_items = $this->getMenuItems();
|
|
|
|
$this->labels = array('license_number' => $this->getContext()->getI18n()->__('Numer licencji'));
|
|
|
|
return sfView::SUCCESS;
|
|
}
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
protected function getConfigLabels()
|
|
{
|
|
$labels = parent::getConfigLabels();
|
|
|
|
$i18n = $this->getContext()->getI18N();
|
|
|
|
$labels['config{code}'] = $i18n->__('Kod pocztowy');
|
|
$labels['config{town}'] = $i18n->__('Miasto');
|
|
$labels['config{street}'] = $i18n->__('Ulica');
|
|
$labels['config{house}'] = $i18n->__('Numer domu');
|
|
|
|
return $labels;
|
|
}
|
|
|
|
protected function getMenuItems()
|
|
{
|
|
$i18n = $this->getContext()->getI18N();
|
|
|
|
return array(
|
|
'stShopInfoBackend/index' => $i18n->__('Informacje o sklepie'),
|
|
'stShopInfoBackend/register' => $i18n->__('Informacje o licencji')
|
|
);
|
|
}
|
|
|
|
protected function updateConfigFromRequest()
|
|
{
|
|
parent::updateConfigFromRequest();
|
|
|
|
$data = $this->getRequestParameter('config');
|
|
|
|
if (isset($data['code']))
|
|
{
|
|
$this->config->set('code', $data['code']);
|
|
}
|
|
|
|
if (isset($data['town']))
|
|
{
|
|
$this->config->set('town', $data['town']);
|
|
}
|
|
|
|
if (isset($data['street']))
|
|
{
|
|
$this->config->set('street', $data['street']);
|
|
}
|
|
|
|
if (isset($data['house']))
|
|
{
|
|
$this->config->set('house', $data['house']);
|
|
}
|
|
|
|
if (isset($data['flat']))
|
|
{
|
|
$this->config->set('flat', $data['flat']);
|
|
}
|
|
}
|
|
}
|