Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1865

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

Novinky:
- fixes #359: Tridy rychlosti

Upravy:
- #419: Optimalizace tablky SMS

Opravy:
- #488: Validator ceny zarizeni

Zobrazit rozdíly:

freenetis/branches/1.1/db_upgrades/upgrade_1.1.0~alpha12.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/
*
*/
/**
* This upgrade is not equal to any of previos upgrades
*
* @author Ondřej Fibich <ondrej.fibich@gmail.com>
*/
$upgrade_equal_to['1.1.0~alpha12'] = array();
/**
* Speed classes (#359) and SMS table optimalization (#412).
*
* @author Ondřej Fibich <ondrej.fibich@gmail.com>
*/
$upgrade_sql['1.1.0~alpha12'] = array
(
/* SMS table optimalization (#419) */
"ALTER TABLE `sms_messages` ADD INDEX (`sender`);",
"ALTER TABLE `sms_messages` ADD INDEX (`receiver`);",
/* Speed classes (#359) */
"CREATE TABLE `speed_classes` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`name` VARCHAR( 50 ) NOT NULL ,
`d_ceil` BIGINT( 11 ) NOT NULL COMMENT 'QoS download ceil in bytes',
`d_rate` BIGINT( 11 ) NOT NULL COMMENT 'QoS download rate in bytes',
`u_ceil` BIGINT( 11 ) NOT NULL COMMENT 'QoS upload ceil in bytes',
`u_rate` BIGINT( 11 ) NOT NULL COMMENT 'QoS upload rate in bytes',
`regular_member_default` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Is this class default for regular members?',
`applicant_default` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Is this class default for applicants?',
PRIMARY KEY ( `id` )
) ENGINE = INNODB COMMENT = 'Defines speed classes for QoS';",
// relation between members and speed classes
"ALTER TABLE `members` ADD `speed_class_id` INT( 11 ) DEFAULT NULL AFTER `qos_rate`",
"ALTER TABLE `members` ADD FOREIGN KEY `speed_class_id_fk` (`speed_class_id`)
REFERENCES `speed_classes` (`id`) ON DELETE SET NULL",
);
/**
* Transform old QoS data to speed classes and remove old columns
*
* @return boolean
*/
function upgrade_1_1_0_alpha12_after()
{
$db = Database::instance();
$member_model = new Member_Model();
$speed_classes = array();
try
{
$member_model->transaction_start();
// transform old data
$members = $member_model->find_all();
$speed_class = new Speed_class_Model();
foreach ($members as $member)
{
if (valid::speed_size($member->qos_ceil) &&
valid::speed_size($member->qos_rate))
{
$d_ceil = $u_ceil = $member->qos_ceil;
$d_rate = $u_rate = $member->qos_rate;
if (strpos($member->qos_ceil, '/'))
{
$u_ceil = substr($u_ceil, 0, strpos($u_ceil, '/'));
$d_ceil = substr($d_ceil, strpos($d_ceil, '/') + 1);
}
if (strpos($member->qos_rate, '/'))
{
$u_rate = substr($u_rate, 0, strpos($u_rate, '/'));
$d_rate = substr($d_rate, strpos($d_rate, '/') + 1);
}
$bu_ceil = network::str2bytes($u_ceil);
$bd_ceil = network::str2bytes($d_ceil);
$bu_rate = network::str2bytes($u_rate);
$bd_rate = network::str2bytes($d_rate);
$index = $bu_ceil . '_' - $bd_ceil . '_' . $bu_rate . '_' . $bd_rate;
if (!isset($speed_classes[$index]))
{
$speed_class->clear();
$speed_class->name = __('Speed class') . ' '
. $bd_ceil . '/' - $bu_ceil . ' - '
. $bd_rate . '_' . $bu_rate;
$speed_class->d_rate = $bd_rate;
$speed_class->d_ceil = $bd_ceil;
$speed_class->u_rate = $bu_rate;
$speed_class->u_ceil = $bu_ceil;
$speed_class->applicant_default = FALSE;
$speed_class->regular_member_default = FALSE;
$speed_class->save_throwable();
$speed_classes[$index] = $speed_class->id;
}
$member->speed_class_id = $speed_classes[$index];
}
$member->save_throwable();
}
// delete old columns
$db->query("ALTER TABLE `members` DROP `qos_ceil`, DROP `qos_rate`");
$member_model->transaction_commit();
}
catch (Exception $e)
{
$member_model->transaction_rollback();
throw $e;
}
return TRUE;
}
freenetis/branches/1.1/application/i18n/cs_CZ/texts.php
'add new rule' => 'Přidat nové pravidlo',
'add new link' => 'Přidat novou linku',
'add new request for connection' => 'Přidat nový požadavek o připojení',
'add new speed class' => 'Přidat novou třídu rychlosti',
'add new ssh key' => 'Přidat nový SSH klíč',
'add new ssh key to user' => 'Přidat nový SSH klíč uživateli',
'add new street' => 'Přidat novou ulici',
......
'default driver' => 'Výchozí ovladač',
'default e-mail' => 'Výchozí e-mail',
'default fee for date %s have not been set!' => 'Výchozí příspěvek pro datum %s není nastaven!',
'default for member' => 'Výchozí pro člena',
'default for membership applicant' => 'Výchozí pro čekatele na členství',
'default for this device type?' => 'Výchozí pro tento typ zařízení?',
'default iface is used as filled iface in permitting of the connection request' => 'Výchozí rozhraní, které je vyplněno při povolení žádosti o připojení',
'default interface' => 'Výchozí rozhraní',
......
'edit link' => 'Úprava linku',
'edit smokeping record' => 'Upravit záznam smokepingu',
'edit the work' => 'Upravit práci',
'edit speed class' => 'Upravit třídu rychlosti',
'edit ssh key' => 'Upravit SSH klíč',
'edit ssh key of user' => 'Upravit SSH klíč uživatele',
'edit street' => 'Upravit ulici',
......
'error - cannot add new filter query' => 'Chyba - nelze přidat nový dotaz filtru.',
'error - cannot add new group' => 'Chyba - nelze přidat novou skupinu',
'error - cannot add phone operator' => 'Chyba - nelze přidat telefonního operátora',
'error - cannot add speed class' => 'Chyba - nelze přidat třídu rychlosti',
'error - cannot assign transfer' => 'Chyba - nelze přiřadit převod.',
'error - cannot complete registration' => 'Chyba - Nelze dokončit registraci',
'error - cannot create %s file' => 'Chyba - Nelze vytvořit soubor %s',
'error - cannot delete access rule' => 'Chyba - Nelze smazat přístupové pravidlo.',
'error - cannot delete bank statement' => 'Chyba - nelze smazat bankovní výpis.',
'error - cannot delete filter query' => 'Chyba - nelze smazat dotaz filtru.',
'error - cannot delete speed class' => 'Chyba - nelze smazat třídu rychlosti',
'error - cannot discount private services' => 'Chyba - nemohu strhnout soukromé služby.',
'error - cannot edit interface' => 'Chyba - nemohu upravit rozhraní',
'error - cannot load intelligent selection' => 'Chyba - nelze načíst inteligentní výběr',
......
'error - cannot send email to applicant about deny of membership' => 'Chyba - nepodařilo se poslat email žadateli s nevyhověním jeho žádosti o členství',
'error - cannot save subnet' => 'Chyba - nelze přidat podsíť.',
'error - cannot set filter query as default' => 'Chyba - nelze nastavit dotaz filtru jako výchozí.',
'error - cannot set speed class as default' => 'Chyba - nelze nastavit třídu rychlosti jako výchozí.',
'error - cannot unset filter query as default' => 'Chyba - nelze zrušit dotaz filtru jako výchozí.',
'error - cannot unset speed class as default' => 'Chyba - nelze zrušit třídu rychlosti jako výchozí.',
'error - cannot update access control group' => 'Chyba - nelze aktualizovat přístupovou skupinu uživatelů',
'error - cannot update allowed subnets of member' => 'Chyba - nelze aktualizovat povolené podsítě člena.',
'error - cannot update count of allowed subnets' => 'Chyba - nelze aktualizovat počet povolených podsítí.',
'error - cannot update device admin' => 'Chyba - nelze aktualizovat správce zařízení.',
'error - cannot update speed class' => 'Chyba - nelze upravit třídu rychlosti',
'error - cant add contacts' => 'Chyba - nelze přidat kontakt.',
'error - cant add country to contact' => 'Chyba - nelze přidat relaci mezi zemí a kontaktem.',
'error - cant add new account' => 'Chyba - nelze vytvořit účet.',
......
'list of all rules for access control' => 'Seznam všech přístupových pravidel',
'list of all sent e-mails' => 'Seznam všech odeslaných e-mailů',
'list of all smokeping records' => 'Seznam všech záznamů smokepingu',
'list of all speed classes' => 'Seznam všech tříd rychlosti',
'list of all streets' => 'Seznam všech ulic',
'list of all towns' => 'Seznam všech měst',
'list of all transactions' => 'Seznam všech převodů',
......
'member_name' => 'Jméno člena (organizace)',
'members' => 'Členové',
'members account' => 'Účet člena',
'members count' => 'Počet členů',
'members on this address' => 'Členové na této adrese',
'membership can be ended only to former member' => 'Členství může být ukončeno jen bývalému členovi.',
'membership interrupt' => 'Přerušení členství',
......
'monthly payment rate of devices' => 'Měsíční splátka zařízení',
'more devices' => 'Více zařízení',
'multiple choice' => 'Vícenásobná volba',
'must be greater than zero' => 'Musí být větší než nula',
'must be logged in' => 'Musíte se přihlásit.',
'must pay regular fee' => 'Platí pravidelný příspěvek',
'my backups' => 'Moje zálohy',
......
'someone have already requested for the same connection' => 'O stejné připojení už zažádal jiný člen.',
'specific symbol' => 'Specifický symbol',
'specification of type' => 'Specifikace typu',
'speed class' => 'Třída rychlosti',
'speed class has been successfully added' => 'Třída rychlosti byla úspěšně přidána',
'speed class has been successfully deleted' => 'Třída rychlosti byla úspěšně smazána',
'speed class has been successfully set as default' => 'Třída rychlosti byla úspěšně nastavena jako výchozí.',
'speed class has been successfully updated' => 'Třída rychlosti byla úspěšně upravena',
'speed class has been successfully unset as default' => 'Třída rychlosti byla úspěšně zrušena jako výchozí.',
'speed classes' => 'Třídy rychlosti',
'speed for active members' => 'Rychlost pro aktivní členy',
'speed for high priority ip addresses' => 'Rychlost pro IP adresy s vysokou prioritou',
'ssh key' => 'SSH klíč',
freenetis/branches/1.1/application/helpers/network.php
}
/**
* Formats speed
*
* @author Michal Kliment
* @param integer $speed In B/s
* @return string
*/
public static function speed($speed)
{
// default unit is nothing
$unit = '';
if ($speed >= 1024)
{
$unit = 'k';
$speed = round($speed / 1024, 2);
// size is too big
if ($speed >= 1024)
{
// transforms to Mega
$unit = 'M';
$speed = round($speed / 1024, 2);
// size is still too big
if ($speed >= 1024)
{
// transforms to Giga
$unit = 'G';
$speed = round($speed / 1024, 2);
// size is still too big
if ($speed >= 1024)
{
// transforms to Giga
$unit = 'T';
$speed = round($speed / 1024, 2);
}
}
}
}
return ($speed) ? $speed . $unit : '0' . $unit;
}
/**
* Checks whether ip address belongs to default address ranges
*
* @author Michal Kliment
......
return true;
}
return false;
;
}
/**
* Converts speed string to integer
* Converts speed string to integer (bytes)
*
* @author Michal Kliment
* @param string $str
......
}
/**
* Converts integer to speed string
* Converts integer (bytes) to speed string
*
* @author Michal Kliment
* @param type $bytes
freenetis/branches/1.1/application/helpers/callback.php
echo round($item->$name, $precision);
}
/**
* Callback function to print count with title (column of thew title is
* stored in args)
*
* @param object $item
* @param string $name
* @param array $args
*/
public static function count_field($item, $name, $args = array())
{
$title = @$args[0];
if (!empty($args[0]) && isset($item->$title))
echo '<span class="help" title="' . $item->$title . '">' . $item->$name . "</span>";
else
echo $item->$name;
}
/************** Callbacks for using in special ocations *******************/
/**
......
}
/**
* Callback function to print rate of speed class
*
* @param object $item
* @param string $name
*/
public static function speed_class_ceil_field ($item, $name)
{
if ($item->d_ceil != $item->u_ceil)
{
echo network::speed($item->u_ceil) . '/';
echo network::speed($item->d_ceil);
}
else
{
echo network::speed($item->d_ceil);
}
}
/**
* Callback function to print ceil of speed class
*
* @param object $item
* @param string $name
*/
public static function speed_class_rate_field ($item, $name)
{
if ($item->d_rate != $item->u_rate)
{
echo network::speed($item->u_rate) . '/';
echo network::speed($item->d_rate);
}
else
{
echo network::speed($item->d_rate);
}
}
/**
* Callback function to print bitrate of link
*
* @author Michal Kliment
freenetis/branches/1.1/application/models/ip_address.php
LEFT JOIN devices d ON i.device_id = d.id
LEFT JOIN users u ON d.user_id = u.id
) ip
JOIN members m ON ip.member_id = m.id AND (m.qos_ceil OR m.qos_rate)
JOIN members m ON ip.member_id = m.id AND m.speed_class_id IS NOT NULL
ORDER BY m.id
");
}
freenetis/branches/1.1/application/models/members_traffic.php
(
SELECT id
FROM members
WHERE
(qos_rate IS NULL OR qos_rate = '') AND
(qos_ceil IS NULL OR qos_ceil = '')
WHERE speed_class_id IS NULL
)
ORDER BY $type DESC
LIMIT ?
freenetis/branches/1.1/application/models/member.php
* @property integer $type
* @property integer $external_type
* @property string $organization_identifier
* @property string $qos_ceil
* @property string $qos_rate
* @property double $entrance_fee
* @property double $debt_payment_rate
* @property date $entrance_date
......
* @property Allowed_subnets_count_Model $allowed_subnets_count
* @property Members_traffic_Model $members_traffic
* @property Members_domicile_Model $members_domicile
* @property integer $speed_class_id
* @property Speed_class_Model $speed_class
* @property ORM_Iterator $allowed_subnets
* @property ORM_Iterator $invoices
* @property ORM_Iterator $users
......
'connection_requests', 'members_whitelists'
);
protected $belongs_to = array('address_point', 'user');
protected $belongs_to = array('address_point', 'user', 'speed_class');
/**
* Returns type in string from integer
......
IF(mi.id IS NOT NULL, ?, ?) AS membership_interrupt,
IF(mi.id IS NOT NULL, 1, 0) AS interrupt,
m.organization_identifier, m.comment,
m.entrance_date, m.leaving_date, m.entrance_fee
m.entrance_date, m.leaving_date, m.entrance_fee,
m.speed_class_id
FROM members m
LEFT JOIN enum_types e ON m.type = e.id
LEFT JOIN translations t ON e.value = t.original_term AND lang = ?
......
IFNULL(t.translated_term, e.value) AS type,
IF(mi.id IS NOT NULL, ?, ?) AS membership_interrupt,
m.organization_identifier, m.comment,
m.entrance_date, m.leaving_date, m.entrance_fee
m.entrance_date, m.leaving_date, m.entrance_fee,
m.speed_class_id
FROM members m
LEFT JOIN enum_types e ON m.type = e.id
LEFT JOIN translations t ON e.value = t.original_term AND lang = ?
......
$result = $this->db->query("
SELECT COUNT(m.id) AS total
FROM members m
WHERE m.type <> ? AND
(m.qos_rate IS NULL OR m.qos_rate = 0 OR LENGTH(m.qos_rate) = 0) AND
WHERE m.type <> ? AND m.speed_class_id IS NULL AND
m.id NOT IN
(
SELECT mi.member_id
......
public function get_members_qos_ceil_rate ()
{
return $this->db->query("
SELECT id,
IF(qos_ceil IS NOT NULL AND qos_ceil <> '', qos_ceil, '0') AS qos_ceil,
IF(qos_rate IS NOT NULL AND qos_rate <> '', qos_rate, '0') AS qos_rate
SELECT m.id, sc.d_ceil, sc.d_rate, sc.u_ceil, sc.u_rate
FROM members m
WHERE (qos_ceil IS NOT NULL AND qos_ceil <> '') OR
(qos_rate IS NOT NULL AND qos_rate <> '')
JOIN speed_classes sc ON sc.id = m.speed_class_id
ORDER BY m.id
");
}
freenetis/branches/1.1/application/models/speed_class.php
<?php defined('SYSPATH') or die('No direct script access.');
/*
* This file is part of open source system FreenetIS
* and it is release 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/
*
*/
/**
* Speed class defines member download and upload ceil and rate speeds for QoS.
*
* @author Ondrej Fibich
* @package Model
*
* @property integer $id
* @property string $name
* @property integer $d_ceil
* @property integer $d_rate
* @property integer $u_ceil
* @property integer $u_rate
* @property boolean $regular_member_default
* @property boolean $applicant_default
* @property Member_Model $member
*/
class Speed_class_Model extends ORM
{
protected $has_many = array('members');
/**
* Gets all speed classes
*
* @return Mysql_Result
*/
public function get_all_speed_classes()
{
return $this->db->query("
SELECT
sc.*,
COUNT(m.id) AS members_count,
GROUP_CONCAT(m.name, '\n') AS members_names
FROM speed_classes sc
LEFT JOIN members m ON m.speed_class_id = sc.id
GROUP BY sc.id
ORDER BY members_count DESC
");
}
/**
* Get default speed class for members.
*
* @return Speed_class_Model|null
*/
public function get_members_default_class()
{
$classes = $this->where('regular_member_default', 1)->find_all();
if ($classes->count())
{
return $classes->current();
}
return NULL;
}
/**
* Get default speed class for applicants.
*
* @return Speed_class_Model|null
*/
public function get_applicants_default_class()
{
$classes = $this->where('applicant_default', 1)->find_all();
if ($classes->count())
{
return $classes->current();
}
return NULL;
}
/**
* Repair applicant default flag - disable it for other items
*
* @param integer $speed_class_id
*/
public function repair_applicant_default($speed_class_id = NULL)
{
// if id is not given, it uses current object
if (!$speed_class_id && $this->id)
{
$speed_class_id = $this->id;
}
$this->db->query("
UPDATE speed_classes
SET applicant_default = 0
WHERE id <> ?
", $speed_class_id);
}
/**
* Repair regular member default flag - disable it for other items
*
* @param integer $speed_class_id
*/
public function repair_regular_member_default($speed_class_id = NULL)
{
// if id is not given, it uses current object
if (!$speed_class_id && $this->id)
{
$speed_class_id = $this->id;
}
$this->db->query("
UPDATE speed_classes
SET regular_member_default = 0
WHERE id <> ?
", $speed_class_id);
}
}
freenetis/branches/1.1/application/controllers/web_interface.php
foreach ($members as $member)
{
$qos_ceil = network::speed_size($member->qos_ceil,"M");
$qos_rate = network::speed_size($member->qos_rate,"M");
$ceil = network::speed($member->u_ceil) . '/'
. network::speed($member->d_ceil);
$rate = network::speed($member->u_rate) . '/'
. network::speed($member->d_rate);
$qos_ceil = network::speed_size($ceil,"M");
$qos_rate = network::speed_size($rate,"M");
$total_upload_rate += $qos_rate['upload'];
$total_download_rate += $qos_rate['download'];
freenetis/branches/1.1/application/controllers/registration.php
$address_point->gps = '';
$address_point->save_throwable();
}
// speed class
$speed_class_model = new Speed_class_Model();
$default_speed_class = $speed_class_model->get_applicants_default_class();
if ($default_speed_class)
{
$member->speed_class_id = $default_speed_class->id;
}
$member->name = ($form_data['membername'] != '') ?
$form_data['membername'] : $user->name . ' ' . $user->surname;
freenetis/branches/1.1/application/controllers/members.php
$allowed_order_type = array
(
'id', 'registration', 'name', 'street','redirect', 'street_number',
'town', 'quarter', 'ZIP_code', 'qos_ceil', 'qos_rate', 'entrance_fee',
'town', 'quarter', 'ZIP_code', 'entrance_fee',
'debt_payment_rate', 'current_credit', 'entrance_date', 'comment',
'balance', 'type_name', 'redirect', 'whitelisted'
);
......
->callback('Variable_Symbols_Controller::valid_var_sym');
}
if ($this->acl_check_edit(get_class($this), 'qos_ceil') &&
$this->acl_check_edit(get_class($this), 'qos_rate'))
{
$speed_class = new Speed_class_Model();
$speed_classes = $speed_class->select_list();
$def_speed_class = $speed_class->get_members_default_class();
$form->dropdown('speed_class')
->options($speed_classes)
->selected($def_speed_class ? $def_speed_class->id : $member->id)
->add_button('speed_classes')
->style('width:200px');
}
if ($this->acl_check_edit(get_class($this), 'comment'))
{
$form->textarea('comment')
......
$member->comment = $form_data['comment'];
}
if ($this->acl_check_edit('Variable_Symbols_Controller', 'variable_symbols'))
if ($this->acl_check_edit('Variable_Symbols_Controller', 'variable_symbols') &&
!empty($form_data['variable_symbol']))
{
$account = ORM::factory('account')->where(array
(
......
$vs->save_throwable();
}
if ($this->acl_check_edit(get_class($this), 'qos_ceil') &&
$this->acl_check_edit(get_class($this), 'qos_rate'))
{
$member->speed_class_id = $form_data['speed_class'];
}
$member->type = Member_Model::TYPE_REGULAR;
$member->locked = 0;
......
$form->group('Additional information');
$form->input('qos_ceil')
->label(__('QoS ceil') . ':&nbsp;' . help::hint('qos_ceil'))
->rules('valid_speed_size');
$speed_class = new Speed_class_Model();
$speed_classes = $speed_class->select_list();
$default_speed_class = $speed_class->get_members_default_class();
$form->dropdown('speed_class')
->options($speed_classes)
->selected($default_speed_class ? $default_speed_class->id : NULL)
->add_button('speed_classes')
->style('width:200px');
$form->input('qos_rate')
->label(__('QoS rate') . ':&nbsp;' . help::hint('qos_rate'))
->rules('valid_speed_size');
$form->date('birthday')
->label('Birthday')
->years(date('Y')-100, date('Y'))
......
$member->type = $form_data['type'];
$member->organization_identifier = $form_data['organization_identifier'];
$member->qos_ceil = $form_data['qos_ceil'];
$member->qos_rate = $form_data['qos_rate'];
$member->speed_class_id = $form_data['speed_class'];
$member->entrance_fee = $form_data['entrance_fee'];
$member->debt_payment_rate = $form_data['debt_payment_rate'];
......
if ($this->acl_check_edit(get_class($this), 'en_fee', $member->id))
{
$form->input('entrance_fee')
->label(
__('Entrance fee').
':&nbsp;'.help::hint('entrance_fee')
)
->label('Entrance fee')
->help(help::hint('entrance_fee'))
->rules('valid_numeric')
->value($member->entrance_fee);
}
if ($this->acl_check_edit(get_class($this),'debit', $member->id))
{
$form->input('debt_payment_rate')
->label(__('Monthly instalment of entrance')
. ':&nbsp;'.help::hint('entrance_fee_instalment'))
->label('Monthly instalment of entrance')
->help(help::hint('entrance_fee_instalment'))
->rules('valid_numeric')
->value($member->debt_payment_rate);
}
// additional information
$form->group('Additional information');
if ($this->acl_check_edit(get_class($this), 'qos_ceil', $member->id))
if ($this->acl_check_edit(get_class($this), 'qos_ceil', $member->id) &&
$this->acl_check_edit(get_class($this), 'qos_rate', $member->id))
{
$form->input('qos_ceil')
->label(__('QOS ceil') . ':&nbsp;' . help::hint('qos_ceil'))
->rules('valid_speed_size')
->value($member->qos_ceil);
$speed_classes = array(NULL => '') + ORM::factory('speed_class')->select_list();
$form->dropdown('speed_class')
->options($speed_classes)
->selected($member->speed_class_id)
->add_button('speed_classes')
->style('width:200px');
}
if ($this->acl_check_edit(get_class($this),'qos_rate', $member->id))
{
$form->input('qos_rate')
->label(__('QOS rate') . ':&nbsp;' . help::hint('qos_rate'))
->rules('valid_speed_size')
->value($member->qos_rate);
}
$form->input('allowed_subnets_count')
->label(__('Count of allowed subnets')
. ': '.help::hint('allowed_subnets_count'))
->label('Count of allowed subnets')
->help(help::hint('allowed_subnets_count'))
->rules('valid_numeric')
->value($allowed_subnets_count);
......
if ($this->acl_check_edit(get_class($this),'name',$member->id))
$member->name = $form_data['membername'];
if ($this->acl_check_edit(get_class($this),'qos_ceil',$member->id))
$member->qos_ceil = $form_data['qos_ceil'];
if ($this->acl_check_edit(get_class($this), 'qos_ceil',$member->id) &&
$this->acl_check_edit(get_class($this), 'qos_rate',$member->id))
$member->speed_class_id = $form_data['speed_class'];
if ($this->acl_check_edit(get_class($this),'qos_rate',$member->id))
$member->qos_rate = $form_data['qos_rate'];
if ($this->acl_check_edit(get_class($this),'en_fee',$member->id))
$member->entrance_fee = $form_data['entrance_fee'];
......
->table('ip')
->values(Ip_address_Model::get_whitelist_types());
$filter_form->add('speed_class_id')
->table('m')
->label('Speed class')
->type('select')
->values(ORM::factory('speed_class')->select_list());
$filter_form->add('cloud')
->table('cl')
->type('select')
freenetis/branches/1.1/application/controllers/members_whitelists.php
$allowed_order_type = array
(
'id', 'registration', 'name', 'street','redirect', 'street_number',
'town', 'quarter', 'ZIP_code', 'qos_ceil', 'qos_rate', 'entrance_fee',
'debt_payment_rate', 'current_credit', 'entrance_date', 'comment',
'town', 'quarter', 'ZIP_code', 'entrance_fee', 'debt_payment_rate',
'current_credit', 'entrance_date', 'comment',
'balance', 'type_name', 'items_count'
);
freenetis/branches/1.1/application/controllers/speed_classes.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/
*
*/
/**
* Controller performs actions over speed classes.
*
* @author Ondřej Fibich
* @package Controller
*/
class Speed_classes_Controller extends Controller
{
/**
* Redirect to list of all speed classes
*/
public function index()
{
url::redirect('speed_classes/show_all');
}
/**
* Show all speedn classes
*
* @param integer $limit_results
* @param string $order_by
* @param string $order_by_direction
* @param string $page_word
* @param string $page
*/
public function show_all()
{
// access
if (!$this->acl_check_view('Settings_Controller', 'system'))
self::error(ACCESS);
$speed_class_model = new Speed_class_Model();
$speed_classes = $speed_class_model->get_all_speed_classes();
$title = __('List of all speed classes');
$grid = new Grid('speed_classes', null, array
(
'use_paginator' => false,
'use_selector' => false,
));
$grid->add_new_button(
'speed_classes/add', 'Add new speed class',
array('class' => 'popup_link')
);
$grid->field('id')
->label('ID');
$grid->field('name');
$grid->callback_field('ceil')
->label('QoS ceil')
->help(help::hint('qos_ceil'))
->callback('callback::speed_class_ceil_field');
$grid->callback_field('rate')
->label('QoS rate')
->help(help::hint('qos_rate'))
->callback('callback::speed_class_rate_field');
$grid->callback_field('members_count')
->callback('callback::count_field', 'members_names')
->class('center');
$grid->callback_field('regular_member_default')
->label('MD')
->help(help::hint(__('Default for member')))
->callback('callback::enabled_field', 'speed_classes/set_default/0/')
->class('center');
$grid->callback_field('applicant_default')
->label('AD')
->help(help::hint(__('Default for membership applicant')))
->callback('callback::enabled_field', 'speed_classes/set_default/1/')
->class('center');
$actions = $grid->grouped_action_field();
$actions->add_action('id')
->icon_action('edit')
->url('speed_classes/edit')
->label('Delete')
->class('popup_link');
$actions->add_action('id')
->icon_action('delete')
->url('speed_classes/delete')
->label('Delete')
->class('delete_link');
$grid->datasource($speed_classes);
$view = new View('main');
$view->breadcrumbs = __('Speed classes');
$view->title = $title;
$view->content = new View('show_all');
$view->content->headline = $title;
$view->content->table = $grid;
$view->render(TRUE);
}
/**
* Shows speed class - hack for popup adding
*
* @param integer $speed_class_id
*/
public function show($speed_class_id = NULL)
{
url::redirect('speed_classes/show_all');
}
/**
* Adds new speed class
*/
public function add()
{
// access
if (!$this->acl_check_view('Settings_Controller', 'system'))
self::error(ACCESS);
// form
$form = new Forge();
$form->group('Basic information');
$form->input('name')
->rules('required');
$form->input('qos_ceil')
->label('QoS ceil')
->help(help::hint('qos_ceil'))
->rules('required|valid_speed_size');
$form->input('qos_rate')
->label('QoS rate')
->help(help::hint('qos_rate'))
->rules('required|valid_speed_size');
$form->submit('Add');
// posted
if($form->validate())
{
$form_data = $form->as_array();
$speed_class = new Speed_class_Model();
// parse ceil and rate
$d_ceil = $u_ceil = $form_data['qos_ceil'];
$d_rate = $u_rate = $form_data['qos_rate'];
if (strpos($form_data['qos_ceil'], '/'))
{
$u_ceil = substr($u_ceil, 0, strpos($u_ceil, '/'));
$d_ceil = substr($d_ceil, strpos($d_ceil, '/') + 1);
}
if (strpos($form_data['qos_rate'], '/'))
{
$u_rate = substr($u_rate, 0, strpos($u_rate, '/'));
$d_rate = substr($d_rate, strpos($d_rate, '/') + 1);
}
try
{
$speed_class->transaction_start();
$speed_class->name = $form_data['name'];
$speed_class->d_ceil = network::str2bytes($d_ceil);
$speed_class->u_ceil = network::str2bytes($u_ceil);
$speed_class->d_rate = network::str2bytes($d_rate);
$speed_class->u_rate = network::str2bytes($u_rate);
$speed_class->save_throwable();
$speed_class->transaction_commit();
status::success('Speed class has been successfully added.');
$this->redirect('speed_classes/show', $speed_class->id);
}
catch (Exception $e)
{
$speed_class->transaction_rollback();
Log::add_exception($e);
status::error('Error - Cannot add speed class.');
$this->redirect('speed_classes/show_all');
}
}
else
{
$headline = __('Add new speed class');
// breadcrumbs navigation
$breadcrumbs = breadcrumbs::add()
->link('speed_classes/show_all', 'Speed classes')
->disable_translation()
->text($headline);
$view = new View('main');
$view->breadcrumbs = $breadcrumbs->html();
$view->title = $headline;
$view->content = new View('form');
$view->content->headline = $headline;
$view->content->form = $form->html();
$view->content->link_back = '';
$view->render(TRUE);
}
}
/**
* Edits new speed class
*
* @param integer $speed_class_id
*/
public function edit($speed_class_id)
{
// access
if (!$this->acl_check_view('Settings_Controller', 'system'))
self::error(ACCESS);
// bad paremeter
if (!$speed_class_id || !is_numeric($speed_class_id))
Controller::warning (PARAMETER);
$sc = new Speed_class_Model($speed_class_id);
// record doesn't exis
if (!$sc->id)
Controller::error(RECORD);
$ceil = network::speed($sc->d_ceil);
$rate = network::speed($sc->d_rate);
if ($sc->d_ceil != $sc->u_ceil)
{
$ceil = network::speed($sc->u_ceil) . '/' . network::speed($sc->d_ceil);
}
if ($sc->d_rate != $sc->u_rate)
{
$rate = network::speed($sc->u_rate) . '/' . network::speed($sc->d_rate);
}
// form
$form = new Forge();
$form->group('Basic information');
$form->input('name')
->rules('required')
->value($sc->name);
$form->input('qos_ceil')
->label('QoS ceil')
->help(help::hint('qos_ceil'))
->rules('required|valid_speed_size')
->value($ceil);
$form->input('qos_rate')
->label('QoS rate')
->help(help::hint('qos_rate'))
->rules('required|valid_speed_size')
->value($rate);
$form->submit('Update');
// posted
if($form->validate())
{
$form_data = $form->as_array();
// parse ceil and rate
$d_ceil = $u_ceil = $form_data['qos_ceil'];
$d_rate = $u_rate = $form_data['qos_rate'];
if (strpos($form_data['qos_ceil'], '/'))
{
$u_ceil = substr($u_ceil, 0, strpos($u_ceil, '/'));
$d_ceil = substr($d_ceil, strpos($d_ceil, '/') + 1);
}
if (strpos($form_data['qos_rate'], '/'))
{
$u_rate = substr($u_rate, 0, strpos($u_rate, '/'));
$d_rate = substr($d_rate, strpos($d_rate, '/') + 1);
}
try
{
$sc->transaction_start();
$sc->name = $form_data['name'];
$sc->d_ceil = network::str2bytes($d_ceil);
$sc->u_ceil = network::str2bytes($u_ceil);
$sc->d_rate = network::str2bytes($d_rate);
$sc->u_rate = network::str2bytes($u_rate);
$sc->save_throwable();
$sc->transaction_commit();
status::success('Speed class has been successfully updated.');
$this->redirect('speed_classes/show', $sc->id);
}
catch (Exception $e)
{
$sc->transaction_rollback();
Log::add_exception($e);
status::error('Error - Cannot update speed class.');
$this->redirect('speed_classes/show_all');
}
}
else
{
$headline = __('Edit speed class');
// breadcrumbs navigation
$breadcrumbs = breadcrumbs::add()
->link('speed_classes/show_all', 'Speed classes')
->disable_translation()
->text($sc->name)
->text($headline);
$view = new View('main');
$view->breadcrumbs = $breadcrumbs->html();
$view->title = $headline;
$view->content = new View('form');
$view->content->headline = $headline;
$view->content->form = $form->html();
$view->content->link_back = '';
$view->render(TRUE);
}
}
/**
* Update default regular member and applicant flag for speed class
*
* @param boolean $is_applicant TRUE on applicant FALSE on member
* @param integer $speed_class_id
*/
public function set_default($is_applicant = FALSE, $speed_class_id = NULL)
{
// access
if (!$this->acl_check_view('Settings_Controller', 'system'))
self::error(ACCESS);
// bad paremeter
if (!$speed_class_id || !is_numeric($speed_class_id))
Controller::warning (PARAMETER);
$speed_class = new Speed_class_Model($speed_class_id);
// record doesn't exis
if (!$speed_class->id)
Controller::error(RECORD);
if ($is_applicant)
{
$is_default = $speed_class->applicant_default;
}
else
{
$is_default = $speed_class->regular_member_default;
}
// prevent database exception
try
{
$speed_class->transaction_start();
if ($is_applicant)
{
$speed_class->applicant_default = !$is_default;
}
else
{
$speed_class->regular_member_default = !$is_default;
}
$speed_class->save_throwable();
if (!$is_default)
{
if ($is_applicant)
{
$speed_class->repair_applicant_default();
}
else
{
$speed_class->repair_regular_member_default();
}
}
$speed_class->transaction_commit();
if ($is_default)
{
status::success('Speed class has been successfully unset as default.');
}
else
{
status::success('Speed class has been successfully set as default.');
}
}
catch (Exception $e)
{
$speed_class->transaction_rollback();
Log::add_exception($e);
if ($is_default)
{
status::error('Error - Cannot unset speed class as default.');
}
else
{
status::error('Error - Cannot set speed class as default.');
}
}
url::redirect('speed_classes/show_all');
}
/**
* Delete speed class
*
* @param integer $speed_class_id
*/
public function delete($speed_class_id = NULL)
{
// bad paremeter
if (!$speed_class_id || !is_numeric($speed_class_id))
Controller::warning (PARAMETER);
$speed_class = new Speed_class_Model($speed_class_id);
// record doesn't exis
if (!$speed_class->id)
Controller::error(RECORD);
// prevent database exception
try
{
$speed_class->delete_throwable();
status::success('Speed class has been successfully deleted.');
}
catch (Exception $e)
{
Log::add_exception($e);
status::error('Error - Cannot delete speed class.');
}
url::redirect('speed_classes/show_all');
}
}
freenetis/branches/1.1/application/controllers/devices.php
$group_payment->input('payment_rate')
->label('Monthly payment rate')
->rules('valid_numeric');
->rules('valid_numeric')
->callback(array($this, 'valid_repayment'));
$group_payment->date('buy_date')
->label('Buy date')
......
$group_payment->input('payment_rate')
->label('Monthly payment rate')
->rules('valid_numeric');
->rules('valid_numeric')
->callback(array($this, 'valid_repayment'));
$group_payment->date('buy_date')
->label('Buy date')
......
$group_payment->input('payment_rate')
->label('Monthly payment rate')
->rules('valid_numeric')
->value($device->payment_rate ? $device->payment_rate : '');
->value($device->payment_rate ? $device->payment_rate : '')
->callback(array($this, 'valid_repayment'));
$group_payment->date('buy_date')
->label('Buy date')
......
return $filter_form;
}
/**
* Validate repayment of device
*
* @param Form_Field $input
*/
public function valid_repayment($input = NULL)
{
if (empty($input) || !is_object($input))
{
self::error(PAGE);
}
$price = $this->input->post('price');
$rate = $input->value;
if (!empty($price) && doubleval($rate) <= 0)
{
$input->add_error('required', __('Must be greater than zero'));
}
}
}
freenetis/branches/1.1/application/views/members/show.php
<td><?php echo '<b style="color:darkorange" title="'.__('Registration will be activated after midnight.').'">'.__('Waiting for registration').'</b>' ?></td>
</tr>
<?php } ?>
<?php if ($this->acl_check_view('Members_Controller', 'qos_ceil', $member->id) ||
$this->acl_check_view('Members_Controller', 'qos_rate', $member->id)
<?php if ($this->acl_check_view('Members_Controller', 'qos_ceil', $member->id) &&
$this->acl_check_view('Members_Controller', 'qos_rate', $member->id) &&
$member->speed_class_id
)
{ ?>
<tr>
<th colspan="2"><?php echo __('Traffic') ?> + <?php echo __('QoS') ?></th>
</tr>
<?php } ?>
<?php
if ($this->acl_check_view('Members_Controller', 'qos_ceil', $member->id))
{ ?>
<tr>
<th><?php echo __('Speed class') ?></th>
<td><?php echo $member->speed_class->name ?></td>
</tr>
<tr>
<th><?php echo __('QoS ceil') ?>&nbsp;<?php echo help::hint('qos_ceil') ?></th>
<td><?php echo $member->qos_ceil ?></td>
<td><?php callback::speed_class_ceil_field($member->speed_class, 'ceil') ?></td>
</tr>
<?php } ?>
<?php
if ($this->acl_check_view('Members_Controller', 'qos_rate', $member->id))
{ ?>
<tr>
<th><?php echo __('QoS rate') ?>&nbsp;<?php echo help::hint('qos_rate') ?></th>
<td><?php echo $member->qos_rate ?></td>
<td><?php callback::speed_class_rate_field($member->speed_class, 'rate') ?></td>
</tr>
<?php } ?>
<?php if (Settings::get('ulogd_enabled') && $this->acl_check_view('Ulogd_Controller', 'member', $member->id)) { ?>
freenetis/branches/1.1/application/views/menu.php
<?php endif ?>
<?php if ($this->acl_check_view('Settings_Controller', 'system')): ?>
<li><?php echo html::anchor('speed_classes/show_all', __('Speed classes')) ?></li>
<li><?php echo html::anchor('phone_operators/show_all', __('Phone operators')) ?></li>
<?php endif ?>
freenetis/branches/1.1/version.php
* The current version of FreenetIS.
* This value must be changed by developers in a new release of FreenetIS.
*/
define('FREENETIS_VERSION', '1.1.0~alpha11');
define('FREENETIS_VERSION', '1.1.0~alpha12');

Také k dispozici: Unified diff