<?php
/**
* СодеÑÐ¶Ð¸Ñ ÐºÐ»Ð°ÑÑ Register
*
* @package energine
* @author 1m.dm
* @copyright ColoCall 2006
* @version $Id: Register.class.php,v 1.9 2008/04/03 14:11:16 pavka Exp $
*/
//require_once('core/modules/share/components/DBDataSet.class.php');
//require_once('core/framework/User.class.php');
//require_once('core/framework/Mail.class.php');
/**
* ФоÑма ÑегиÑÑÑаÑии
*
* @package energine
* @subpackage user
*/
class Register extends DBDataSet {
/**
* ÐкземплÑÑ ÐºÐ»Ð°ÑÑа User
*
* @var User
* @access private
*/
private $user;
/**
* ÐонÑÑÑÑкÑÐ¾Ñ ÐºÐ»Ð°ÑÑа
*
* @param string $name
* @param string $module
* @param Document $document
* @param array $params
* @access public
*/
public function __construct($name, $module, Document $document, array $params = null) {
parent::__construct($name, $module, $document, $params);
$this->setDataSetAction('save-user');
$this->setType(self::COMPONENT_TYPE_FORM_ADD);
$this->user = new User();
$this->setTableName(User::USER_TABLE_NAME);
}
/**
* ÐеÑеопÑеделен паÑамеÑÑ active
*
* @return int
* @access protected
*/
protected function defineParams() {
$result = array_merge(parent::defineParams(),
array(
'active'=>true,
));
return $result;
}
/**
* ÐбÑабоÑка возможнÑÑ
оÑибок ÑоÑ
ÑÐ°Ð½ÐµÐ½Ð¸Ñ + ÑедиÑÐµÐºÑ Ð½Ð° ÑÑÑаниÑÑ ÑезÑлÑÑаÑа
*
* @return void
* @access protected
*/
protected function save() {
try {
$this->saveData();
$_SESSION['saved'] = true;
$this->response->redirectToCurrentSection('success/');
}
catch (SystemException $e) {
$this->generateError(SystemException::ERR_NOTICE, $e->getMessage());
$this->setParam('action', 'main');
$this->prepare();
}
}
/**
* СоÑ
Ñанение даннÑÑ
.
*
* @return array
* @access protected
*/
protected function saveData() {
$password = $_POST[$this->getTableName()]['u_password'] = User::generatePassword();
try {
$result = $this->user->create($_POST[$this->getTableName()]);
$mailer = new Mail();
$mailer->setFrom($this->getConfigValue('mail.from'));
$mailer->setSubject($this->translate('TXT_SUBJ_REGISTER'));
$mailer->setText(sprintf($this->translate('TXT_BODY_REGISTER'),$this->user->getValue('u_name'), $password));
$mailer->addTo($this->user->getValue('u_name'));
$mailer->send();
}
catch (Exception $error) {
throw new SystemException($error->getMessage(), SystemException::ERR_WARNING);
}
}
/**
* ÐолÑÑÐ°ÐµÑ ÑпиÑок доÑÑÑпнÑÑ
полей из ÑаблиÑÑ Ð¿Ð¾Ð»ÑзоваÑелей и генеÑÐ¸Ñ ÑоÑмÑ
*
* @return void
* @access protected
*/
protected function prepare() {
parent::prepare();
//u_id и u_is_active нам не нÑÐ¶Ð½Ñ Ð½Ð¸ пÑи какиÑ
ÑаÑкладаÑ
if ($this->getDataDescription()->getFieldDescriptionByName('u_id')) {
$this->getDataDescription()->removeFieldDescription($this->getDataDescription()->getFieldDescriptionByName('u_id'));
}
if ($this->getDataDescription()->getFieldDescriptionByName('u_is_active')) {
$this->getDataDescription()->removeFieldDescription($this->getDataDescription()->getFieldDescriptionByName('u_is_active'));
}
//ТÑÑ Ñаки нÑжно веÑнÑÑÑÑÑ Ðº паÑамеÑÑÑ confirmationNeeded
if ($this->getDataDescription()->getFieldDescriptionByName('u_password')) {
$this->getDataDescription()->removeFieldDescription($this->getDataDescription()->getFieldDescriptionByName('u_password'));
}
$this->getDataDescription()->getFieldDescriptionByName('u_name')->setType(FieldDescription::FIELD_TYPE_EMAIL);
}
/**
* ÐÑÐ²Ð¾Ð´Ð¸Ñ ÑезÑлÑÑÐ°Ñ ÑегиÑÑÑаÑии.
*
* @return void
* @access protected
*/
protected function success() {
//еÑли в ÑеÑÑии Ð½ÐµÑ Ð¿ÐµÑеменной saved знаÑÐ¸Ñ ÑÑÐ¾Ñ Ð¼ÐµÑод пÑÑаÑÑÑÑ Ð²ÑзваÑÑ Ð½Ð°Ð¿ÑÑмÑÑ. Ðе вÑйдеÑ!
if (!isset($_SESSION['saved'])) {
throw new SystemException('ERR_404', SystemException::ERR_404);
}
//unset($_SESSION['saved']);
if ($textBlock = $this->document->componentManager->getComponentByName('RegTextBlock')) {
$textBlock->disable();
}
$this->setBuilder($this->createBuilder());
$dataDescription = new DataDescription();
$ddi = new FieldDescription('success_message');
$ddi->setType(FieldDescription::FIELD_TYPE_TEXT);
$ddi->setMode(FieldDescription::FIELD_MODE_READ);
$ddi->removeProperty('title');
$dataDescription->addFieldDescription($ddi);
$data = new Data();
$di = new Field('success_message');
$di->setData($this->translate('TXT_USER_REGISTRED'));
$data->addField($di);
$this->setDataDescription($dataDescription);
$this->setData($data);
}
}