Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1885

Přidáno uživatelem Ondřej Fibich před více než 11 roky(ů)

Novinky:

- refs #200: Podpora pro automaticke generovani variabilnich symbolu s drivery pro jednoduche pridavani novych generatoru.

Zobrazit rozdíly:

freenetis/branches/1.1/application/i18n/cs_CZ/texts.php
'after you\'ve done that, you can continue' => 'Poté, co tak učiníte, můžete pokračovat.',
'agree' => 'Souhlas',
'air' => 'vzduch',
'algorithm for generation of variable symbols' => 'Algoritmus pro generování variabilních symbolů',
'all' => 'Všichni',
'all accounts now have correct balances, %d accounts had incorrect balances, list of ids of corrected accounts: %s' => 'Všechny účty teď mají správné zůstatky, %d účtů mělo chybné zůstatky, seznam ID opravených účtů: %s',
'all devices' => 'Všechna zařízení',
......
'general settings' => 'Obecná nastavení',
'generate' => 'Generovat',
'generate address book' => 'Vytvořit telefonní adresář',
'generate automatically' => 'Generovat automaticky',
'generate dhcp files' => 'Generovat soubory DHCP',
'generate forward dns files' => 'Generovat dopředné soubory DNS',
'generate htaccess' => 'Vygenerovat htaccess',
freenetis/branches/1.1/application/models/variable_symbol.php
public function get_variable_symbol_id($variable_symbol)
{
$query = $this->db->query("
SELECT id
SELECT *
FROM variable_symbols
WHERE variable_symbol = ?
", $variable_symbol);
freenetis/branches/1.1/application/controllers/variable_symbols.php
$form = new Forge();
$form->input('variable_symbol')
->label(__('Variable symbol') . ':')
->rules('required|length[1,10]')
->rules('length[1,10]')
->callback(array($this,'valid_var_sym'));
if (Variable_Key_Generator::get_active_driver())
{
$form->checkbox('variable_symbol_generate')
->label('Generate automatically');
}
else
{
$form->variable_symbol->rules('required|length[1,10]');
}
$form->submit('Add');
......
{
$form_data = $form->as_array();
$variable_symbol_model = new Variable_Symbol_Model();
if ($variable_symbol_model->get_variable_symbol_id($form_data['variable_symbol']))
if (isset($form_data['variable_symbol_generate']) &&
$form_data['variable_symbol_generate'])
{
$var_sym = Variable_Key_Generator::factory()->generate($account->member_id);
}
else
{
$var_sym = $form_data['variable_symbol'];
}
if (empty($var_sym))
{
status::warning('Empty variable symbol.');
}
else if ($variable_symbol_model->get_variable_symbol_id($var_sym))
{
status::warning('Variable symbol already exists in database.');
}
else
{
$variable_symbol_model->variable_symbol = $form_data['variable_symbol'];
$variable_symbol_model->variable_symbol = $var_sym;
$variable_symbol_model->account_id = $account_id;
$issaved = $variable_symbol_model->save();
if ($issaved)
{
status::success('Variable symbol has been successfully added');
status::success('Variable symbol has been successfully added');
}
else
{
status::error('Error - cant update variable symbols');
status::error('Error - cant update variable symbols');
}
}
freenetis/branches/1.1/application/controllers/members.php
{
$form->input('variable_symbol')
->rules('length[1,10]')
->callback('Variable_Symbols_Controller::valid_var_sym');
->class('join1')
->callback('Variable_Symbols_Controller::valid_var_sym')
->style('width:120px');
if (Variable_Key_Generator::get_active_driver())
{
$form->checkbox('variable_symbol_generate')
->label('Generate automatically')
->checked(TRUE)
->class('join2')
->style('width:auto;margin-left:5px');
}
}
if ($this->acl_check_edit(get_class($this), 'qos_ceil') &&
......
}
if ($this->acl_check_edit('Variable_Symbols_Controller', 'variable_symbols') &&
!empty($form_data['variable_symbol']))
(!empty($form_data['variable_symbol']) || (
isset($form_data['variable_symbol_generate']) &&
$form_data['variable_symbol_generate']
)))
{
$account = ORM::factory('account')->where(array
(
......
'account_attribute_id' => Account_attribute_Model::CREDIT
))->find();
if (!isset($form_data['variable_symbol_generate']) ||
!$form_data['variable_symbol_generate'])
{
$var_sym = $form_data['variable_symbol'];
}
else
{
$var_sym = Variable_Key_Generator::factory()->generate($member->id);
}
$vs = new Variable_Symbol_Model();
$vs->account_id = $account->id;
$vs->variable_symbol = $form_data['variable_symbol'];
$vs->save_throwable();
$vs_not_unique = $vs->get_variable_symbol_id($var_sym);
if ($vs_not_unique && $vs_not_unique->id)
{
if ($vs_not_unique->account_id != $account->id)
{
throw new Exception(__('Variable symbol already exists in database.'));
}
}
else
{
$vs->account_id = $account->id;
$vs->variable_symbol = $var_sym;
$vs->save_throwable();
}
}
if ($this->acl_check_edit(get_class($this), 'qos_ceil') &&
......
$form->input('variable_symbol')
->label(__('Variable symbol').': '.help::hint('variable_symbol'))
->rules('required|length[1,10]')
->callback(array($this, 'valid_var_sym'));
->rules('length[1,10]')
->class('join1')
->callback('Variable_Symbols_Controller::valid_var_sym');
if (Variable_Key_Generator::get_active_driver())
{
$form->checkbox('variable_symbol_generate')
->label('Generate automatically')
->checked(TRUE)
->class('join2')
->style('width:auto;margin-left:5px');
}
else
{
$form->variable_symbol->rules('required|length[1,10]');
}
$form->input('entrance_fee')
->label(__('Entrance fee').': '.help::hint('entrance_fee'))
......
$account->save_throwable();
// saving variable symbol
if (!isset($form_data['variable_symbol_generate']) ||
!$form_data['variable_symbol_generate'])
{
$var_sym = $form_data['variable_symbol'];
}
else
{
$var_sym = Variable_Key_Generator::factory()->generate($member->id);
}
if (empty($var_sym))
{
throw new Exception(__('Empty variable symbol.'));
}
$variable_symbol_model = new Variable_Symbol_Model();
$variable_symbol_model->account_id = $account->id;
$variable_symbol_model->variable_symbol = $form_data['variable_symbol'];
$variable_symbol_model->variable_symbol = $var_sym;
$variable_symbol_model->save_throwable();
// save allowed subnets count of member
......
}
/**
* Check validity of variable symbol
*
* @param object $input
*/
public function valid_var_sym($input = NULL)
{
// validators cannot be accessed
if (empty($input) || !is_object($input))
{
self::error(PAGE);
}
$value = trim($input->value);
$variable_symbol_model = new Variable_Symbol_Model();
$total = $variable_symbol_model->get_variable_symbol_id($value);
if (!preg_match("/^[0-9]{1,10}$/", $value))
{
$input->add_error('required', __('Bad variable symbol format.'));
}
else if ($total)
{
$input->add_error('required', __(
'Variable symbol already exists in database.'
));
}
}
/**
* Entrance has to be before current date.
*
* @param object $input
freenetis/branches/1.1/application/controllers/settings.php
->options(arr::bool())
->default(Settings::get('works_enabled'));
$this->form->group('Module settings');
$timeout = Settings::get('module_status_timeout');
$this->form->input('module_status_timeout')
->rules('required|valid_numeric')
->class('increase_decrease_buttons')
->value($timeout)
->style('width:30px')
->help('Time threshold in minutes, before module is shown as inactive');
$this->form->group('E-mail settings');
$this->form->input('email_default_email')
......
$this->form->group(__('URL settings') . ' ' . help::hint('url_settings'));
$this->form->dropdown('protocol')
->rules('length[3,100]')
->rules('required|length[3,100]')
->options(array
(
'http' => 'http',
......
->style('width:50px')
->help('dhcp_server_reload_timeout');
$this->form->group('Module settings');
$timeout = Settings::get('module_status_timeout');
$this->form->input('module_status_timeout')
->rules('required|valid_numeric')
->class('increase_decrease_buttons')
->value($timeout)
->style('width:30px')
->help('Time threshold in minutes, before module is shown as inactive');
$this->form->group('Security');
$this->form->input('security_password_length')
......
->label('Minimal password level')
->rules('required')
->selected(Settings::get('security_password_level'));
$this->form->group('Finance');
$this->form->dropdown('variable_key_generator_id')
->options(array(NULL => '') + Variable_Key_Generator::get_drivers_for_dropdown())
->label('Algorithm for generation of variable symbols')
->selected(Variable_Key_Generator::get_active_driver())
->style('width:200px');
$this->form->submit('Save');
// form validate
freenetis/branches/1.1/application/libraries/variable_key_generators/Pvfree_Variable_Key_Generator.php
<?php defined('SYSPATH') or die('No direct script access.');
/*
* This file is part of open source system FreenetIS
* and it is released under GPLv3 licence.
*
* More info about licence can be found:
* http://www.gnu.org/licenses/gpl-3.0.html
*
* More info about project can be found:
* http://www.freenetis.org/
*
*/
/**
* Generates variable keys for need of PVFREE.
* To a given ID (member ID) is appended a hashed version of this ID.
*
* @author David Kuba, Ondrej Fibich
*/
class Pvfree_Variable_Key_Generator
{
/**
* Generated variable key from given member ID.
*
* @param mixed $identificator Indentificator for generate from
* @return integer Variable key
*/
public function generate($identificator)
{
return $identificator . sprintf('%02d', substr(hexdec(substr(md5($identificator), -2)), -2));
}
}
freenetis/branches/1.1/application/libraries/Variable_Key_Generator.php
<?php defined('SYSPATH') or die('No direct script access.');
/*
* This file is part of open source system FreenetIS
* and it is released under GPLv3 licence.
*
* More info about licence can be found:
* http://www.gnu.org/licenses/gpl-3.0.html
*
* More info about project can be found:
* http://www.freenetis.org/
*
*/
/**
* Abstract class for variable key drivers.
*
* @author Ondrej Fibich
*/
abstract class Variable_Key_Generator
{
/**
* Dir with classes
*/
const DIR = 'variable_key_generators';
/**
* Array of availables drivers for factory method.
* Keys:
*
* id ID used in database
* name Name
* class Class name in Varaible keys folder
*
* @var array
*/
private static $DRIVERS = array
(
'pvfree' => array
(
'id' => 'pvfree',
'name' => 'Pvfree variable key generator',
'class' => 'Pvfree_Variable_Key_Generator',
),
);
/**
* Factory for Variable key drivers
*
* @param mixed $driver String index of driver or integer ID of driver or NUL
* if current should be selected.
* @return Variable_Key_Generator Generator instance or NULL
* if driver name or ID is incorect.
*/
public static function factory($driver = NULL)
{
if ($driver === NULL)
{
$selected_driver = self::get_active_driver();
}
else
{
$selected_driver = self::_get_driver_index($driver);
}
if ($selected_driver)
{
$driver = self::$DRIVERS[$selected_driver];
$class_name = $driver['class'];
$class_path = dirname(__FILE__) . '/' . self::DIR
. '/' . $class_name . '.php';
require_once $class_path;
return new $class_name;
}
return NULL;
}
/**
* Gets index of driver
*
* @param mixed $driver String index of driver or integer ID of driver.
* @return mixed String key on success FALSE on error.
*/
private static function _get_driver_index($driver)
{
if (array_key_exists($driver, self::$DRIVERS))
{
return $driver;
}
else
{
foreach (self::$DRIVERS as $key => $available_driver)
{
if ($available_driver['id'] == $driver)
{
return $key;
}
}
}
return FALSE;
}
/**
* Gets name of driver
*
* @param integer $driver String index of driver or integer ID of driver.
* @return string
*/
public static function get_driver_name($driver)
{
$selected_driver = self::_get_driver_index($driver);
if ($selected_driver)
{
$d = self::$DRIVERS[$selected_driver];
return __($d['name']);
}
return NULL;
}
/**
* Gets drivers array
*
* @return array
*/
public static function get_drivers()
{
return self::$DRIVERS;
}
/**
* Gets drivers array for dropdown
*
* @return array
*/
public static function get_drivers_for_dropdown()
{
$options = array();
foreach (self::$DRIVERS as $d)
{
$options[$d['id']] = __($d['name']);
}
return $options;
}
/**
* Gets list of active drivers for selectboxes.
* Key is id of driver and value is name.
*
* @return string ID of driver
*/
public static function get_active_driver()
{
return Settings::get('variable_key_generator_id');
}
/**
* Generated variable key from given identificator.
*
* @param mixed $identificator Indentificator for generate from
* @return integer Variable key
*/
abstract public function generate($identificator);
}
freenetis/branches/1.1/application/views/js/members.php
<?php
/**
* Members add.
*
* @author Ondřej Fibich
*/
// IDE complementation
if (FALSE): ?><script type="text/javascript"><?php endif
?>
// on enable of VS generation, disable VS field
$('#variable_symbol_generate', context).change(function ()
{
if ($(this).is(':checked'))
{
$('#variable_symbol', context).attr('disabled', true);
}
else
{
$('#variable_symbol', context).removeAttr('disabled').focus();
}
}).trigger('change');
freenetis/branches/1.1/application/views/js/variable_symbols_add.php
<?php
/**
* Variable symbols - adding.
*
* @author Ondřej Fibich
*/
// IDE complementation
if (FALSE): ?><script type="text/javascript"><?php endif
?>
// on enable of VS generation, disable VS field
$('#variable_symbol_generate', context).change(function ()
{
if ($(this).is(':checked'))
$('#variable_symbol', context).attr('disabled', true);
else
$('#variable_symbol', context).removeAttr('disabled');
}).trigger('change');

Také k dispozici: Unified diff