Projekt

Obecné

Profil

« Předchozí | Další » 

Revize c1bdc1c4

Přidáno uživatelem Michal Kliment před asi 9 roky(ů)

Release 1.1.0

Zobrazit rozdíly:

AUTHORS
Tomáš Dulík <dulik@unart.cz>
Ondřej Fibich <ondrej.fibich@gmail.com>
Michal Kliment <kliment@freenetis.org>
David Raška <jeffraska@gmail.com>
Jiří Sviták <j.svitak@unart.cz>
Roman Ševčík <sevcik.roman@mail.unart.cz>
Copyright 2008-2013 Tomáš Dulík <dulik@unart.cz>
Copyright 2010-2013 Ondřej Fibich <ondrej.fibich@gmail.com>
Copyright 2018-2013 Michal Kliment <kliment@freenetis.org>
Copyright 2012-2013 David Raška <jeffraska@gmail.com>
Copyright 2008-2012 Jiří Sviták <j.svitak@unart.cz>
Copyright 2008-2012 Roman Ševčík <sevcik.roman@mail.unart.cz>
application/controllers/accounts.php
*/
class Accounts_Controller extends Controller
{
/**
* Constructor, only test if finance is enabled
*/
public function __construct()
{
parent::__construct();
if (!Settings::get('finance_enabled'))
Controller::error (ACCESS);
}
/**
* Index redirect to show all
*/
......
$arr_groups_help[Account_Model::PROJECT] = help::hint('project_subaccounts');
$arr_groups_help[Account_Model::OTHER] = help::hint('other_subaccounts');
// filtering
$filter = new Table_Form(url_lang::base() . "accounts/show_all/$group", "get", array
(
new Table_Form_Item('text', 'name', 'Account name'),
"tr",
new Table_Form_Item('text', 'datetime_from', 'Balance from date'),
"tr",
new Table_Form_Item('text', 'datetime_to', 'Balance to date'),
"tr",
"td", new Table_Form_Item('submit', 'submit', 'Filter'),
));
// Create filter form
$filter_form = new Filter_form();
$filter_form->add('id')
->table('aa')
->label('Account');
$filter_values = $filter->values();
$filter_form->add('name')
->table('aa')
->label('Account name');
$filter_form->add('datetime')
->label('Balance date')
->type('date');
// gets grid settings
if (is_numeric($this->input->get('record_per_page')))
$limit_results = (int) $this->input->get('record_per_page');
if (is_numeric($this->input->post('record_per_page')))
$limit_results = (int) $this->input->post('record_per_page');
// order by check
$allowed_order_type = array('id', 'aname', 'comment', 'mname', 'balance');
......
if ($group == Account_Model::ACCOUNTING_SYSTEM)
{
$account_attribute_model = new Account_attribute_Model();
$total_accounts = $account_attribute_model->get_accounting_system_count($filter_values);
$total_accounts = $account_attribute_model->get_accounting_system_count($filter_form->as_sql(array
(
'id', 'name'
)));
if (($sql_offset = ($page - 1) * $limit_results) > $total_accounts)
$sql_offset = 0;
$accounts = $account_attribute_model->get_accounting_system(
$sql_offset, (int) $limit_results, $order_by,
$order_by_direction, $filter_values
$order_by_direction, $filter_form->as_sql(array(
'id', 'name'
)),
$filter_form->as_sql(array('datetime'))
);
}
else
{
$account_model = new Account_Model();
$total_accounts = $account_model->get_accounts_count($filter_values, $group);
$total_accounts = $account_model->get_accounts_count($filter_form->as_sql(array
(
'id', 'name'
)),
$group);
if (($sql_offset = ($page - 1) * $limit_results) > $total_accounts)
$sql_offset = 0;
$accounts = $account_model->get_accounts(
$sql_offset, (int) $limit_results, $order_by,
$order_by_direction, $filter_values, $group
$order_by_direction, $filter_form->as_sql(array(
'id', 'name'
)),
$filter_form->as_sql(array('datetime')),
$group
);
}
// creates parameters of filter in url
$arr_gets = array();
foreach ($this->input->get() as $key => $value)
{
$arr_gets[] = $key . '=' . $value;
}
$query_string = '?' . implode('&', $arr_gets);
// set correct headline for chosen group
$headline = $arr_groups[$group];
......
'order_by' => $order_by,
'order_by_direction' => $order_by_direction,
'limit_results' => $limit_results,
'query_string' => $query_string,
'filter' => $filter->view,
'filter' => $filter_form,
'variables' => $group . '/',
'url_array_ofset' => 1
));
......
// redirection
url::redirect('accounts/show_all');
}
/**
* Recalculates all fees of account
*
* @author Michal Kliment
* @param type $account_id
*/
public function recalculate_fees ($account_id = NULL)
{
// bad parameter
if (!$account_id)
Controller::warning (PARAMETER);
$account = new Account_Model($account_id);
// account doesn't exist
if (!$account->id)
Controller::error (RECORD);
// acccess control
if (!$this->acl_check_edit('Accounts_Controller', 'accounts'))
Controller::error (ACCESS);
try
{
// recalculates entrance fees
$entrance_fee_stats = self::recalculate_entrance_fees($account->id);
// recalculates member fees
$member_fee_stats = self::recalculate_member_fees($account->id);
// recalculates device fees
$device_fee_stats = self::recalculate_device_fees($account->id);
$deleted_transfers_count = $entrance_fee_stats['deleted'] + $member_fee_stats['deleted'] + $device_fee_stats['deleted'];
$created_transfers_count = $entrance_fee_stats['created'] + $member_fee_stats['created'] + $device_fee_stats['created'];
status::success(
'Fees have been successfully recalculated, %d deleted '.
'transfers, %d created new transfers.',
TRUE, array
(
0 => $deleted_transfers_count,
1 => $created_transfers_count
)
);
}
catch (Exception $e)
{
status::error('Error - Cannot recalculate fees', $e);
Log::add_exception($e);
}
$this->redirect('transfers/show_by_account/'.$account->id);
}
/**
* Recalculates entrance fees of account
*
* @author Michal Kliment
* @param type $account_id
* @return type
* @throws Exception
*/
public static function recalculate_entrance_fees ($account_id = NULL)
{
$account = new Account_Model($account_id);
try
{
$account->transaction_start();
$transfer_model = new Transfer_Model();
$last_entrance_fee_transfer = substr($transfer_model->find_last_transfer_datetime_by_type(
Transfer_Model::DEDUCT_ENTRANCE_FEE
), 0,10);
// first of all is necessary to delete previous entrance fee transfers
// user can change debt payment rate, this means that existing transfers are useless
$deleted_transfers_count = $account->delete_entrance_deduct_transfers_of_account($account->id);
// preparation
$created_transfers_count = 0;
// not recalculate fees for applicant
if ($account->member->type != Member_Model::TYPE_APPLICANT)
{
$creation_datetime = date('Y-m-d H:i:s');
$infrastructure = ORM::factory('account')->where(
'account_attribute_id', Account_attribute_Model::INFRASTRUCTURE
)->find();
// debt payment rate is set
if ($account->member->debt_payment_rate)
$amount = $account->member->debt_payment_rate;
else
$amount = $account->member->entrance_fee;
$entrance_fee_left = $account->member->entrance_fee;
$date = date::get_closses_deduct_date_to($account->member->entrance_date);
while (true)
{
// whole entrance fee is deducted
if ($entrance_fee_left == 0)
break;
// stops on last deducted entrace fee's date in system
if ($date > $last_entrance_fee_transfer)
break;
if ($amount > $entrance_fee_left)
$amount = $entrance_fee_left;
$created_transfers_count++;
Transfer_Model::insert_transfer(
$account->id, $infrastructure->id, null, null,
Session::instance()->get('user_id'),
Transfer_Model::DEDUCT_ENTRANCE_FEE,
$date, $creation_datetime, __('Entrance fee'),
$amount
);
$entrance_fee_left -= $amount;
$date = date::arithmetic($date, 'month');
}
}
$account->transaction_commit();
return array
(
'deleted' => $deleted_transfers_count,
'created' => $created_transfers_count
);
}
catch (Exception $e)
{
$account->transaction_rollback();
throw $e;
}
}
/**
* Recalculates member fees of account
*
* @author Michal Kliment
* @param type $account_id
* @return type
* @throws Exception
*/
public static function recalculate_member_fees($account_id)
{
$account = new Account_Model($account_id);
try
{
$account->transaction_start();
$transfer_model = new Transfer_Model();
$last_member_fee_transfer = substr($transfer_model->find_last_transfer_datetime_by_type(
Transfer_Model::DEDUCT_MEMBER_FEE
), 0, 10);
// find leaving date of former member
if ($account->member->type == Member_Model::TYPE_FORMER)
{
$leaving_date = date::get_closses_deduct_date_to($account->member->leaving_date);
}
else
{
$leaving_date = '9999-12-31';
}
// first of all is necessary to delete previous entrance fee transfers
// user can change debt payment rate, this means that existing transfers are useless
$deleted_transfers_count = $account->delete_deduct_transfers_of_account($account->id);
// preparation
$created_transfers_count = 0;
// not recalculate fees for applicant
if ($account->member->type != Member_Model::TYPE_APPLICANT)
{
$creation_datetime = date('Y-m-d H:i:s');
$operating = ORM::factory('account')->where(
'account_attribute_id', Account_attribute_Model::OPERATING
)->find();
$date = date::get_closses_deduct_date_to($account->member->entrance_date);
$fee_model = new Fee_Model();
while (true)
{
if ($date == $leaving_date)
break;
if ($date > $last_member_fee_transfer)
break;
$amount = $fee_model->get_regular_member_fee_by_member_date(
$account->member_id, $date
);
$name = $fee_model->get_regular_member_fee_name_by_member_date(
$account->member_id, $date
);
if ($name === NULL)
$name = __('Member fee');
if ($amount)
{
$created_transfers_count++;
Transfer_Model::insert_transfer(
$account->id, $operating->id, null, null,
Session::instance()->get('user_id'),
Transfer_Model::DEDUCT_MEMBER_FEE,
$date, $creation_datetime, $name,
$amount
);
}
$date = date::arithmetic($date, 'month');
}
}
$account->transaction_commit();
return array
(
'deleted' => $deleted_transfers_count,
'created' => $created_transfers_count
);
}
catch (Exception $e)
{
$account->transaction_rollback();
throw $e;
}
}
/**
* Recalculates device fees of account
*
* @author Michal Kliment
* @param type $account_id
* @return type
* @throws Exception
*/
public static function recalculate_device_fees($account_id = NULL)
{
$account = new Account_Model($account_id);
try
{
$account->transaction_start();
$devices = ORM::factory('device')
->get_member_devices_with_debt_payments($account->member_id);
$payments = array();
$debt = 0;
$last_deduct_device_fees = Settings::get('last_deduct_device_fees');
// first of all is necessary to delete previous entrance fee transfers
// user can change debt payment rate, this means that existing transfers are useless
$deleted_transfers_count = $account->delete_device_deduct_transfers_of_account($account->id);
$created_transfers_count = 0;
if (count($devices))
{
$creation_datetime = date('Y-m-d H:i:s');
$operating = ORM::factory('account')->where(
'account_attribute_id', Account_attribute_Model::OPERATING
)->find();
foreach ($devices as $device)
{
// finds buy date of this device
$buy_date = date_parse(date::get_closses_deduct_date_to($device->buy_date));
$debt += $device->price;
// finds all debt payments of this device
money::find_debt_payments(
$payments, $buy_date['month'], $buy_date['year'],
$device->price, $device->payment_rate
);
}
$year = min(array_keys($payments));
$month = min(array_keys($payments[$year]));
$day = date::get_deduct_day_to($month, $year);
$date = date::create($day, $month, $year);
while (true)
{
// all device fees are deducted
if ($debt == 0)
break;
// stops on last deducted device fee's date in system
if ($date > $last_deduct_device_fees)
break;
$pd = date_parse($date);
if (isset($payments[$pd['year']][$pd['month']]))
{
$amount = $payments[$pd['year']][$pd['month']];
if ($amount > $debt)
$amount = $debt;
$debt -= $amount;
$created_transfers_count++;
Transfer_Model::insert_transfer(
$account->id, $operating->id, null, null,
Session::instance()->get('user_id'),
Transfer_Model::DEDUCT_DEVICE_FEE,
$date, $creation_datetime, __('Device repayments'),
$amount
);
}
$date = date::arithmetic($date, 'month');
}
}
$account->transaction_commit();
return array
(
'deleted' => $deleted_transfers_count,
'created' => $created_transfers_count
);
}
catch (Exception $e)
{
$account->transaction_rollback();
throw $e;
}
}
}
application/controllers/acl.php
* @author Michal Kliment
*/
class Acl_Controller extends Controller
{
{
/**
* Index function, only redirect to list of all access control rules
*
......
$page_word = 'page', $page = 1)
{
// check access
if (!$this->acl_check_view('Settings_Controller', 'access_rights'))
if (!$this->acl_check_view('Acl_Controller', 'acl'))
Controller::Error(ACCESS);
// gets new selector
if (is_numeric($this->input->get('record_per_page')))
$limit_results = (int) $this->input->get('record_per_page');
if (is_numeric($this->input->post('record_per_page')))
$limit_results = (int) $this->input->post('record_per_page');
// parameters control
$allowed_order_type = array
......
if (strtolower($order_by_direction) != 'desc')
$order_by_direction = 'asc';
$filter_form = new Filter_form('a');
$filter_form->add('note');
$filter_form->add('aco_value')
->label('ACO')
->type('select')
->values(Aco_Model::get_actions());
$filter_form->add('aro_group_id')
->label('ARO group')
->type('select')
->values(Aro_group_Model::get_groups());
$filter_form->add('axo_section_value')
->label('AXO section')
->type('select')
->values(Axo_Model::get_section_values());
$filter_form->add('axo_value')
->label('AXO value')
->type('select')
->values(Axo_Model::get_values());
$acl_model = new Acl_Model();
$total_rules = $acl_model->count_all_rules();
$total_rules = $acl_model->count_all_rules($filter_form->as_sql());
// limit check
if (($sql_offset = ($page - 1) * $limit_results) > $total_rules)
$sql_offset = 0;
$rules = $acl_model->get_all_rules(
$sql_offset, (int)$limit_results, $order_by, $order_by_direction
$sql_offset, (int)$limit_results, $order_by, $order_by_direction,
$filter_form->as_sql()
);
$headline = __('List of all rules for access control');
......
'order_by' => $order_by,
'order_by_direction' => $order_by_direction,
'limit_results' => $limit_results,
//'filter' => $filter_form
'filter' => $filter_form
));
$grid->add_new_button('acl/add', __('Add new rule'));
if ($this->acl_check_new('Acl_Controller', 'acl'))
{
$grid->add_new_button('acl/add', __('Add new rule'));
}
$grid->order_field('id')
->label(__('ID'));
$grid->order_callback_field('description')
$grid->order_callback_field('note')
->callback('callback::limited_text');
$grid->order_callback_field('aco_count')
......
->icon_action('show')
->url('acl/show');
$actions->add_action('id')
->icon_action('edit')
->url('acl/edit');
if ($this->acl_check_edit('Acl_Controller', 'acl'))
{
$actions->add_action('id')
->icon_action('edit')
->url('acl/edit');
}
$actions->add_action('id')
->icon_action('delete')
->url('acl/delete')
->class('delete_link');
if ($this->acl_check_delete('Acl_Controller', 'acl'))
{
$actions->add_action('id')
->icon_action('delete')
->url('acl/delete')
->class('delete_link');
}
$grid->datasource($rules);
$submenu = array();
$submenu[] = __('Access control rules');
$submenu[] = html::anchor('aro_groups/show_all', __('Access control groups of users'));
if ($this->acl_check_view('Aro_groups_Controller', 'aro_group'))
{
$submenu = array();
$submenu[] = html::anchor('acl/show_all', __('Access control rules'));
$submenu[] = html::anchor('aro_groups/show_all', __('Access control groups of users'));
}
else
{
$submenu = NULL;
}
$view = new View('main');
$view->breadcrumbs = __('Access control rules');
$view->title = $headline;
$view->content = new View('show_all');
$view->content->submenu = implode(' | ',$submenu);
$this->sections = $submenu;
$view->content->current = 'acl/show_all';
$view->content->headline = $headline;
$view->content->table = $grid;
$view->render(TRUE);
......
public function show ($acl_id = NULL)
{
// check access
if (!$this->acl_check_view('Settings_Controller', 'access_rights'))
if (!$this->acl_check_view('Acl_Controller', 'acl'))
Controller::Error(ACCESS);
// bad parameter
......
$axo_grid->field('name');
if ($this->acl_check_new('Acl_Controller', 'acl') ||
$this->acl_check_edit('Acl_Controller', 'acl'))
{
$axo_grid->callback_field('name')
->callback('callback::axodoc')
->label('Actions');
}
$axo_grid->datasource($axos);
$headline = __('Show access control rule');
$breadcrumbs = breadcrumbs::add()
->link('acl/show_all', 'Access control rules',
$this->acl_check_view('Settings_Controller', 'access_rights'))
$this->acl_check_view('Acl_Controller', 'acl'))
->text('ID '.$acl->id);
$view = new View('main');
......
public function add ()
{
// check access
if (!$this->acl_check_edit('Settings_Controller', 'access_rights'))
if (!$this->acl_check_new('Acl_Controller', 'acl'))
Controller::Error(ACCESS);
$form = new Forge(url::base(TRUE).url::current(TRUE));
......
->style('width:600px');
$form->dropdown('aco[]')
->label(__('ACO').': '.help::hint('aco'))
->label('ACO')
->help(help::hint('aco'))
->rules('required')
->options(Aco_Model::get_actions())
->multiple('multiple')
->size(20);
->size(10);
$aro_group_model = new Aro_group_Model();
$aro_groups = $aro_group_model->find_all();
$arr_aro_groups = array();
foreach ($aro_groups as $aro_group)
$arr_aro_groups[$aro_group->id] = $aro_group->name;
$arr_aro_groups = $aro_group_model->select_list('id', 'name', 'name');
$form->dropdown('aro_group[]')
->label(__('ARO groups').': '.help::hint('aro_groups'))
->label('ARO groups')
->help(help::hint('aro_groups'))
->rules('required')
->options($arr_aro_groups)
->multiple('multiple')
->size(20);
$axo_model = new Axo_Model();
$axos = $axo_model->find_all();
$arr_axos = array();
foreach ($axos as $axo)
$arr_axos[$axo->id] = $axo->name.' ('.$axo->section_value.')';
$arr_axos = $axo_model->select_list('id', 'CONCAT(section_value, \' - \', name)');
$form->dropdown('axo[]')
->label(__('AXO').': '.help::hint('axo'))
->label('AXO')
->help(help::hint('axo'))
->rules('required')
->options($arr_axos)
->multiple('multiple')
......
$breadcrumbs = breadcrumbs::add()
->link('acl/show_all', 'Access control rules',
$this->acl_check_view('Settings_Controller', 'access_rights'))
$this->acl_check_view('Acl_Controller', 'acl'))
->text('Add new rule');
$view = new View('main');
......
public function edit ($acl_id = NULL)
{
// check access
if (!$this->acl_check_edit('Settings_Controller', 'access_rights'))
if (!$this->acl_check_edit('Acl_Controller', 'acl'))
Controller::Error(ACCESS);
// bad parameter
......
$sel_acos[] = $aco->value;
$form->dropdown('aco[]')
->label(__('ACO').': '.help::hint('aco'))
->label('ACO')
->help(help::hint('aco'))
->rules('required')
->options(Aco_Model::get_actions())
->selected($sel_acos)
->multiple('multiple')
->size(20);
->size(10);
$aro_group_model = new Aro_group_Model();
$aro_groups = $aro_group_model->find_all();
$arr_aro_groups = array();
foreach ($aro_groups as $aro_group)
$arr_aro_groups[$aro_group->id] = $aro_group->name;
$arr_aro_groups = $aro_group_model->select_list('id', 'name', 'name');
$sel_aro_groups = array();
foreach ($acl->get_aro_groups() as $aro_group)
$sel_aro_groups[] = $aro_group->id;
$form->dropdown('aro_group[]')
->label(__('ARO groups').': '.help::hint('aro_groups'))
->label('ARO groups')
->help(help::hint('aro_groups'))
->rules('required')
->options($arr_aro_groups)
->selected($sel_aro_groups)
......
->size(20);
$axo_model = new Axo_Model();
$axos = $axo_model->find_all();
$arr_axos = array();
foreach ($axos as $axo)
$arr_axos[$axo->id] = $axo->name.' ('.$axo->section_value.')';
$arr_axos = $axo_model->select_list('id', 'CONCAT(section_value, \' - \', name)');
$sel_axos = array();
foreach ($acl->get_axos() as $axo)
$sel_axos[] = $axo->id;
$form->dropdown('axo[]')
->label(__('AXO').': '.help::hint('axo'))
->label('AXO')
->help(help::hint('axo'))
->rules('required')
->options($arr_axos)
->selected($sel_axos)
......
$breadcrumbs = breadcrumbs::add()
->link('acl/show_all', 'Access control rules',
$this->acl_check_view('Settings_Controller', 'access_rights'))
$this->acl_check_view('Acl_Controller', 'acl'))
->link('acl/show/'.$acl->id, 'ID '.$acl->id,
$this->acl_check_view('Settings_Controller', 'access_rights'))
$this->acl_check_view('Acl_Controller', 'acl'))
->text('Edit');
$view = new View('main');
......
public function delete ($acl_id = NULL)
{
// check access
if (!$this->acl_check_edit('Settings_Controller', 'access_rights'))
if (!$this->acl_check_delete('Acl_Controller', 'acl'))
Controller::Error(ACCESS);
// bad parameter
......
url::redirect('acl/show_all');
}
}
?>
application/controllers/address_points.php
Controller::error(ACCESS);
// gets new selector
if (is_numeric($this->input->get('record_per_page')))
$limit_results = (int) $this->input->get('record_per_page');
if (is_numeric($this->input->post('record_per_page')))
$limit_results = (int) $this->input->post('record_per_page');
// parameters control
$allowed_order_type = array
......
$members = array
(
NULL => '----- '.__('Select member').' -----'
) + arr::from_objects(ORM::factory('member')->get_all_members_to_dropdown());
) + Member_Model::select_list_grouped();
// form to group by type
$form = new Forge(url::base(TRUE).url::current(TRUE));
......
$form->submit('submit');
if ($form->validate())
if ($form->validate() && !isset($_POST['record_per_page']))
{
url::redirect('address_points/show_all/'.$form->member_id->value);
}
......
Controller::error(ACCESS);
// country
$arr_countries = ORM::factory('country')->select_list('id', 'country_name');
$arr_countries = ORM::factory('country')->where('enabled', 1)->select_list('id', 'country_name');
// streets
$arr_streets = array
......
Controller::error(ACCESS);
// country
$arr_countries = ORM::factory('country')->select_list('id', 'country_name');
$arr_countries = ORM::factory('country')->where('enabled', 1)->select_list('id', 'country_name');
$arr_countries = $arr_countries + ORM::factory('country')->where('id', $ap->country_id)->select_list('id', 'country_name');
// streets
$arr_streets = array
(
......
gps::real2degrees(num::decimal_point($data->results[0]->geometry->location->lng), FALSE);
}
/**
* Help AJAX function to fill GPS by street, town, district, zip and country
*
* @author David Raška
*/
public function get_gps_by_address_string()
{
$country_id = (int) $this->input->get('country_id');
$town = $this->input->get('town');
$district = $this->input->get('district');
$street = $this->input->get('street');
$zip = $this->input->get('zip');
$match = array();
if (preg_match('((ev\.č\.)?[0-9][0-9]*(/[0-9][0-9]*[a-zA-Z]*)*)', $street, $match))
{
// street
$street = trim(preg_replace(' ((ev\.č\.)?[0-9][0-9]*(/[0-9][0-9]*[a-zA-Z]*)*)', '', $street));
$number = $match[0];
// first try find in already exist address points
$address_point = ORM::factory('address_point')
->get_address_point_with_gps_by_country_id_town_district_street_zip
(
$country_id, $town, $district, $street, $number, $zip
);
// success, we end
if ($address_point && strlen($address_point->gps))
{
$gps = explode(' ', $address_point->gps);
echo gps::real2degrees($gps[0], FALSE) . ' ';
echo gps::real2degrees($gps[1], FALSE);
return;
}
// try find by google API
$country_model = new Country_Model($country_id);
$country = ($country_model) ? $country_model->country_name : '';
if ($district)
{
$town .= ", $district";
}
$town .= ", $zip";
if (!$number || $town == '' || $country == '')
return;
$data = self::get_geocode_from_google ($street, $number, $town, $country);
if (!$data)
return;
/* return only precise GPS coordinates
*
* Valid location types: ROOFTOP
*/
$type = $data->results[0]->geometry->location_type;
if ($type != "ROOFTOP")
return;
echo gps::real2degrees(num::decimal_point($data->results[0]->geometry->location->lat), FALSE)." ".
gps::real2degrees(num::decimal_point($data->results[0]->geometry->location->lng), FALSE);
}
}
/**
* Helper function to get geocode data from Google Map API
*
......
$view->content->aditional_info = $ai;
$view->render(TRUE);
}
/**
* Test if address point server is active
*
* @return boolean
*/
public static function is_address_point_server_active()
{
static $address_point_server_active = NULL;
if ($address_point_server_active === NULL)
{
if (Settings::get('address_point_url'))
{
$curl = new Curl_HTTP_Client();
$result = $curl->fetch_url(Settings::get('address_point_url').'?mode=test');
if ($curl->get_http_response_code() == 200 && $result !== FALSE)
{
// Address point server responses
$result = json_decode($result);
$address_point_server_active = ($result && $result->state);
}
else // Address point server is not active
{
Log_queue_Model::error(
'Error in address point validation: Server is not active'
);
$address_point_server_active = FALSE;
}
}
else // Address point server not set
{
$address_point_server_active = FALSE;
}
}
return $address_point_server_active;
}
/**
* Test if given address point is valid
*
* @return boolean
*/
public static function is_address_point_valid($country = NULL, $town = '', $district = '', $street = '', $zip = '')
{
$country = urlencode($country);
$town = urlencode($town);
$district = urlencode($district);
$street = urlencode($street);
$zip = urlencode($zip);
$curl = new Curl_HTTP_Client();
$result = $curl->fetch_url(Settings::get('address_point_url')."?country=$country&town=$town&street=$street&zip=$zip&district=$district&mode=validate");
if ($curl->get_http_response_code() == 200 && $result !== FALSE)
{
$result = json_decode($result);
return ($result && $result->state);
}
else
{
Log_queue_Model::error(
'Error in address point validation: Cannot validate'
);
return FALSE;
}
}
}
application/controllers/allowed_subnets.php
Controller::error(RECORD);
// access control
if (!$this->acl_check_view('Devices_Controller', 'allowed_subnet', $member->id))
if (!$this->acl_check_view('Allowed_subnets_Controller', 'allowed_subnet', $member->id))
Controller::error(ACCESS);
// finds all allowed subnets of member
......
Controller::error(RECORD);
// access control
if (!$this->acl_check_new('Devices_Controller', 'allowed_subnet', $member->id))
if (!$this->acl_check_new('Allowed_subnets_Controller', 'allowed_subnet', $member->id))
Controller::error(ACCESS);
$subnet_model = new Subnet_Model();
......
$member_id = $allowed_subnet->member_id;
// access control
if (!$this->acl_check_delete('Devices_Controller', 'allowed_subnet', $member_id))
if (!$this->acl_check_delete('Allowed_subnets_Controller', 'allowed_subnet', $member_id))
Controller::error(ACCESS);
// success
......
Controller::error(RECORD);
// access control
if (!$this->acl_check_edit('Devices_Controller', 'allowed_subnet', $allowed_subnet->member->id))
if (!$this->acl_check_edit('Allowed_subnets_Controller', 'allowed_subnet', $allowed_subnet->member->id))
Controller::error(ACCESS);
$allowed_subnet->enabled = !$allowed_subnet->enabled;
......
}
$allowed_subnet_model->transaction_commit();
return TRUE; // all OK
}
catch (Exception $e) // failed => rollback and wait 100ms before next attempt
{
$allowed_subnet_model->transaction_rollback();
if (++$transaction_attempt_counter >= $max_attempts) // this was last attempt?
{
Log::add_exception($e);
......
return FALSE;
}
}
usleep($timeout);
}
}
application/controllers/allowed_subnets_counts.php
Controller::error(RECORD);
// access control
if (!$this->acl_check_edit('Devices_Controller', 'allowed_subnet', $member_id))
if (!$this->acl_check_edit('Allowed_subnets_Controller', 'allowed_subnet', $member_id))
Controller::error(ACCESS);
$form = new Forge(url::base(TRUE) . url::current(TRUE));
......
{
$member->transaction_rollback();
Log::add_exception($e);
status::error('Error - Cannot update count of allowed subnets');
status::error('Error - Cannot update count of allowed subnets', $e);
}
$this->redirect('allowed_subnets/show_by_member/' . $member_id);
application/controllers/approval_template_items.php
private $approval_template = NULL;
/** @var Approval_template_item_Model */
private $ati = NULL;
/**
* Only checks whether approval are enabled
*
* @author Michal Kliment
*/
public function __construct()
{
parent::__construct();
// approval are not enabled
if (!Settings::get('approval_enabled'))
Controller::error (ACCESS);
}
/**
* Index redirects to show all
application/controllers/approval_templates.php
*/
class Approval_templates_Controller extends Controller
{
/**
* Only checks whether approval are enabled
*
* @author Michal Kliment
*/
public function __construct()
{
parent::__construct();
// approval are not enabled
if (!Settings::get('approval_enabled'))
Controller::error (ACCESS);
}
/**
* Index redirects to show all
*/
......
Controller::error(ACCESS);
// gets new selector
if (is_numeric($this->input->get('record_per_page')))
$limit_results = (int) $this->input->get('record_per_page');
if (is_numeric($this->input->post('record_per_page')))
$limit_results = (int) $this->input->post('record_per_page');
$approval_template_model = new Approval_template_Model();
$total_approval_templates = $approval_template_model->count_all();
......
->link('approval_types/show', 'name');
$items_grid->callback_field('group_id')
->label(__('Group'))
->label('Group')
->callback('Approval_types_Controller::group_field');
$items_grid->callback_field('type')
->callback('Approval_types_Controller::type_field');
/* TODO: #815
$items_grid->callback_field('interval')
->callback('Approval_types_Controller::interval_field');
->callback('Approval_types_Controller::interval_field');*/
$items_grid->callback_field('min_suggest_amount')
->label(__('Minimal suggest amount'))
->label('Minimal suggest amount')
->callback('Approval_types_Controller::min_suggest_amount_field');
$items_grid->callback_field('one_vote')
->label('Single vote is enough?')
->callback('callback::boolean');
$items_grid->callback_field('priority')
->callback('Approval_templates_Controller::priority_field')
->help(help::hint('approval_priority'));
application/controllers/approval_types.php
*/
class Approval_types_Controller extends Controller
{
public static $vote_options = array();
public static $types = array
(
1 => 'Simple majority',
2 => 'Absolute majority',
);
public function __construct()
{
parent::__construct();
self::$vote_options = array
(
NULL => __('None'),
1 => __('Agree'),
-1 => __('Disagree'),
0 => __('Abstain')
);
self::$types = array
(
1 => __('Simple majority'),
2 => __('Absolute majority')
);
// approval are not enabled
if (!Settings::get('approval_enabled'))
{
self::error(ACCESS);
}
}
/**
......
{
//access control
if (!$this->acl_check_view('approval', 'types'))
Controller::error(ACCESS);
self::error(ACCESS);
// gets new selector
if (is_numeric($this->input->get('record_per_page')))
$limit_results = (int) $this->input->get('record_per_page');
if (is_numeric($this->input->post('record_per_page')))
$limit_results = (int) $this->input->post('record_per_page');
$approval_type_model = new Approval_type_Model();
$total_approval_types = $approval_type_model->count_all();
......
->label('Percent for majority')
->callback('callback::percent');
/* TODO: #815
$grid->order_callback_field('interval')
->label('Interval')
->callback('Approval_types_Controller::interval_field');
$grid->order_callback_field('default_vote')
->label('Default vote')
->callback('Approval_types_Controller::default_vote_field');
->callback('Approval_types_Controller::default_vote_field');*/
$grid->order_callback_field('min_suggest_amount')
->label('Minimal suggest amount')
->callback('Approval_types_Controller::min_suggest_amount_field');
$actions = $grid->grouped_action_field();
if ($this->acl_check_new('approval', 'types'))
{
$actions->add_action('id')
->icon_action('show')
->url('approval_types/show');
}
$grid->datasource($approval_types);
// view
......
{
// access control
if (!$this->acl_check_view('approval', 'types'))
Controller::error('ACCESS');
self::error('ACCESS');
// bad parameter
if (!$approval_type_id || !is_numeric($approval_type_id))
Controller::warning(PARAMETER);
self::warning(PARAMETER);
$approval_type = new Approval_type_Model($approval_type_id);
// record doesn't exist
if (!$approval_type->id)
Controller::error(RECORD);
self::error(RECORD);
$state = $approval_type->get_state($approval_type->id);
......
{
// access control
if (!$this->acl_check_new('approval', 'types'))
Controller::error('ACCESS');
self::error('ACCESS');
$aro_group_model = new Aro_group_Model();
$aro_groups = $aro_group_model->get_traverz_tree();
......
->label('Group')
->options($arr_aro_groups)
->rules('required')
->style('width:500px');
->style('width:500px')
->help('Who votes');
$form->input('min_suggest_amount')
->label('Minimal suggest amount')
->rules('valid_numeric');
->rules('valid_numeric')
->help(help::hint('approval_type_min_suggested_amount'));
$form->checkbox('one_vote')
->label('Single vote is enough?')
->value('1')
->help(help::hint('approval_type_one_vote'));
$form->group('Type');
$form->dropdown('type')
->options(self::$types)
->options(Approval_type_Model::get_type_names())
->rules('required')
->style('width:200px');
......
->value('51')
->callback(array($this, 'valid_majority_percent'));
/* TODO: #815
$form->group('Time constraints');
$form->input('interval')
......
->callback(array($this, 'valid_interval'));
$form->dropdown('default_vote')
->options(self::$vote_options)
->callback(array($this, 'valid_default_vote'));
->options(Vote_Model::get_vote_options(NULL, NULL, TRUE))
->callback(array($this, 'valid_default_vote'));*/
$form->submit('Save');
......
$at->aro_group_id = $form_data['aro_group_id'];
$at->type = $form_data['type'];
$at->majority_percent = $form_data['majority_percent'];
$at->interval = date::from_interval($form_data['interval']);
/* TODO: #815
$at->interval = date::from_interval($form_data['interval']); */
$at->min_suggest_amount = $form_data['min_suggest_amount'];
$at->save();
status::success('Approval type has been successfully added.');
$at->one_vote = ($form_data['one_vote'] == 1);
$this->redirect('approval_types/show/', $at->id);
if ($at->save())
{
status::success('Approval type has been successfully added.');
$this->redirect('approval_types/show/', $at->id);
}
else
{
status::success('Approval type has not been added.');
}
}
// headline
......
{
// access control
if (!$this->acl_check_edit('approval', 'types'))
Controller::error('ACCESS');
self::error('ACCESS');
// bad parameter
if (!$approval_type_id || !is_numeric($approval_type_id))
Controller::warning(PARAMETER);
self::warning(PARAMETER);
$at = new Approval_type_Model($approval_type_id);
// record doesn't exist
if (!$at->id)
Controller::error(RECORD);
self::error(RECORD);
$state = $at->get_state($at->id);
......
$arr_aro_groups[$aro_group->id] = $ret.__(''.$aro_group->name);
}
$interval = date::interval($at->interval);
/* TODO: #815 $interval = date::interval($at->interval); */
// form
$form = new Forge(url_lang::base().'approval_types/edit/'.$at->id);
$form = new Forge('approval_types/edit/'.$at->id);
$form->group('Basic information');
......
->value($at->comment);
$form->dropdown('aro_group_id')
->label(__('Group').':')
->label('Group')
->options($arr_aro_groups)->rules('required')
->selected($at->aro_group_id);
->selected($at->aro_group_id)
->help('Who votes');
$form->input('min_suggest_amount')
->label(__('Minimal suggest amount').':')
->label('Minimal suggest amount')
->rules('valid_numeric')
->value($at->min_suggest_amount);
->value($at->min_suggest_amount)
->help(help::hint('approval_type_min_suggested_amount'));
$form->checkbox('one_vote')
->label('Single vote is enough?')
->value('1')
->help(help::hint('approval_type_one_vote'))
->checked($at->one_vote);
$form->group('Type');
$form->dropdown('type')
->options(self::$types)
->options(Approval_type_Model::get_type_names())
->rules('required')
->selected($at->type);
$form->input('majority_percent')
->label(__('Percent for majority').':')
->label('Percent for majority')
->rules('valid_numeric')
->value($at->majority_percent)
->callback(array($this,'valid_majority_percent'));
/* TODO: #815
$form->group('Time constraints');
$form->input('interval')
......
->callback(array($this,'valid_interval'));
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff