Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 8d0578dc

Přidáno uživatelem Filip Miškařík před více než 4 roky(ů)

refs #1135: lBilling, voip, voip sip deleted. All relations for this controllers and models deleted.

Zobrazit rozdíly:

application/controllers/js.php
private function _js_users_show_work_report($work_id = NULL)
{
$this->views['users_show_work_report'] = View::factory('js/work_reports_show')->render();
}
private function _js_voip_show($user_id = NULL)
{
$this->voip_calculator($user_id);
}
private function _js_voip_calls_show_by_user($user_id = NULL)
{
$this->voip_calculator($user_id);
}
}
private function _js_work_reports_add()
{
......
View::factory('js/__pieces/time_activity_rule')->render();
}
/**
* Calculator for VoIP calls
*
* @param integer $user_id
*/
private function voip_calculator($user_id = NULL)
{
if ($user_id && is_numeric($user_id))
{
$user = new User_Model($user_id);
if ($user && $user->id)
{
$sip = ORM::factory('voip_sip')
->where('user_id', $user->id)
->find();
if ($sip && $sip->id)
{
$view = View::factory('js/__pieces/voip_calculator');
$view->sip_name = $sip->name;
$this->views['__pieces_voip_calculator'] = $view->render();
}
}
}
}
/**
* Adds javascript for work reports forms
*/
application/controllers/members.php
}
}
/******** VoIP ***********/
if (Settings::get('voip_enabled'))
{
// VoIP SIP model
$voip_sip = new Voip_sip_Model();
// Gets sips
$voip = $voip_sip->get_all_record_by_member_limited($member->id);
// Has driver?
$has_driver = Billing::instance()->has_driver();
// Account
$b_account = null;
// Check account only if have SIP
if ($voip->count())
{
$b_account = Billing::instance()->get_account($member->id);
}
$voip_grid = new Grid('members', null, array
(
'separator' => '<br /><br />',
'use_paginator' => false,
'use_selector' => false
));
$voip_grid->field('id')
->label('ID');
$voip_grid->field('callerid')
->label(__('Number'));
$actions = $voip_grid->grouped_action_field();
if ($this->acl_check_view('VoIP_Controller', 'voip', $member->id))
{
$actions->add_action('user_id')
->icon_action('phone')
->url('voip/show')
->label('Show VoIP account');
}
if ($this->acl_check_view('Users_Controller', 'users', $member->id))
{
$actions->add_action('user_id')
->icon_action('member')
->url('users/show')
->label('Show user who own this VoIP account');
}
$voip_grid->datasource($voip);
if ($has_driver && $b_account)
{
if ($this->acl_check_view('VoIP_Controller', 'voip', $member->id))
{
$voip_grid->add_new_button(
'voip_calls/show_by_member/'.$member->id,
__('List of all calls')
);
}
if (Settings::get('finance_enabled') &&
$this->acl_check_new('Accounts_Controller', 'transfers', $member->id) &&
!$is_association)
{
$voip_grid->add_new_button(
'transfers/add_voip/'.$account->id,
__('Recharge VoIP credit')
);
}
}
}
// finds date of expiration of member fee
$expiration_info = NULL;
......
$view->content->user_name = $user_name;
$view->content->users_grid = $users_grid;
$view->content->redir_grid = Settings::get('redirection_enabled') ? $redir_grid : '';
$view->content->voip_grid = (Settings::get('voip_enabled')) ? $voip_grid : '';
$view->content->membership_interrupts_grid = Settings::get('membership_interrupt_enabled') ?
$membership_interrupts_grid : '';
$view->content->contacts = $contacts;
......
$view->content->domicile_gps = $domicile_gps;
$view->content->town = (isset($town)) ? $town : '';
$view->content->country = (isset($country)) ? $country : '';
$view->content->billing_has_driver = (Settings::get('voip_enabled')) ? $has_driver : FALSE;
$view->content->billing_account = (Settings::get('voip_enabled')) ? $b_account : NULL;
$view->content->count_voip = (Settings::get('voip_enabled')) ? count($voip) : 0;
$view->content->total_traffic = @$total_traffic;
$view->content->today_traffic = @$today_traffic;
$view->content->month_traffic = @$month_traffic;
application/controllers/settings.php
'name' => 'users_enabled',
'dependencies' => array()
),
'voip' => array
(
'name' => 'voip_enabled',
'dependencies' => array()
),
'vtiger' => array
(
'name' => 'vtiger_integration',
......
$this->acl_check_edit('Settings_Controller', 'sms_settings'))
$this->sections['sms'] = __('SMS');
// is voip enabled
if (self::isModuleEnabled('voip') &&
$this->acl_check_edit('Settings_Controller', 'voip_settings'))
$this->sections['voip'] = __('VoIP');
// is notification enabled
if (self::isModuleEnabled('notification') &&
$this->acl_check_edit('Settings_Controller', 'notification_settings'))
......
$this->email();
else if ($this->acl_check_edit('Settings_Controller', 'sms_settings'))
$this->sms();
else if ($this->acl_check_edit('Settings_Controller', 'voip_settings'))
$this->voip();
else if ($this->acl_check_edit('Settings_Controller', 'notification_settings'))
$this->notifications();
else if ($this->acl_check_edit('Settings_Controller', 'qos_settings'))
......
->options(arr::bool())
->default(Settings::get('sms_enabled'));
// VoIP
$form_modules['voip'] = $this->form->radio('voip_enabled')
->label('VoIP')
->options(arr::bool())
->default(Settings::get('voip_enabled'));
// Network
$form_modules['networks'] = $this->form->radio('networks_enabled')
->label('Networks')
......
$view->render(TRUE);
}
/**
* VOIP settings
*/
public function voip()
{
// access control
if (!module::e('voip') ||
!$this->acl_check_edit(get_class($this), 'voip_settings'))
Controller::error(ACCESS);
// creating of new forge
$this->form = new Forge('settings/voip');
$this->form->group('VoIP settings');
// page title
$this->form->input('voip_number_interval')
->label('Number interval')
->rules('length[19,19]|required')
->value(addslashes(Settings::get('voip_number_interval')))
->callback(array($this, 'valid_voip_number_interval'));
$this->form->input('voip_number_exclude')
->label('Exclude numbers')
->rules('length[9,100]')
->value(addslashes(Settings::get('voip_number_exclude')))
->callback(array($this, 'valid_voip_number_exclude'));
$this->form->input('voip_sip_server')
->label('SIP server')
->rules('length[1,30]|required')
->value(addslashes(Settings::get('voip_sip_server')));
$this->form->group('Asterisk manager settings');
$this->form->input('voip_asterisk_hostname')
->label('Hostname')
->rules('length[1,50]')
->value(Settings::get('voip_asterisk_hostname'));
$this->form->input('voip_asterisk_user')
->label('User')
->rules('length[1,50]')
->value(Settings::get('voip_asterisk_user'));
$this->form->input('voip_asterisk_pass')
->label('Password')
->rules('length[1,50]')
->value(Settings::get('voip_asterisk_pass'));
$this->form->group('Billing settings');
$this->form->dropdown('voip_billing_driver')
->label('Driver')
->rules('required')
->options(array
(
Billing::INACTIVE => __('Inactive'),
Billing::NFX_LBILLING => 'lBilling - NFX'
))->selected(Settings::get('voip_billing_driver'));
$this->form->input('voip_billing_partner')
->label('Partner')
->rules('length[1,50]')
->value(Settings::get('voip_billing_partner'));
$this->form->input('voip_billing_password')
->label('Password')
->rules('length[1,50]')
->value(Settings::get('voip_billing_password'));
$this->form->group('Actual price of calls');
$this->form->input('voip_tariff_fixed')
->label('Fixed line number')
->rules('valid_numeric')
->value(Settings::get('voip_tariff_fixed'));
$this->form->input('voip_tariff_cellphone')
->label('Cellphone number')
->rules('valid_numeric')
->value(Settings::get('voip_tariff_cellphone'));
$this->form->input('voip_tariff_voip')
->label('VoIP number')
->rules('valid_numeric')
->value(Settings::get('voip_tariff_voip'));
$this->form->submit('Save');
// form validate
if ($this->form->validate())
{
$form_data = $this->form->as_array(FALSE);
$issaved = true;
$driver = true;
// enable VoIP driver
if ($form_data['voip_billing_driver'] != Billing::INACTIVE)
{
$voip_sip = new Voip_sip_Model();
// Check pre requirements of VoIP
if (!$voip_sip->check_pre_requirements())
{
// Make pre requirements
try
{
// creates helper functions
Voip_sip_Model::create_functions();
// create views
Voip_sip_Model::create_views();
}
catch (Exception $e)
{
// unset driver
Settings::set('voip_billing_driver', Billing::INACTIVE);
// don't change in next foreach
unset($form_data['voip_billing_driver']);
// error flad
$driver = false;
}
}
}
foreach ($form_data as $name => $value)
{
$issaved = $issaved && Settings::set($name, $value);
}
if (!$driver)
{ // driver error
status::error(__(
'Cannot enable VoIP driver, allow `%s` rights for MySQL user',
array('CREATE ROUTINE')
) . '.',NULL, FALSE);
}
else if ($issaved)
{
status::success('System variables have been successfully updated.');
}
else
{
status::success('System variables havent been successfully updated.');
}
url::redirect('settings/voip');
}
// drover informations
$ai = null;
if (Billing::instance()->has_driver())
{
if (Billing::instance()->test_conn())
{
$ai = __('Testing driver');
$ai .= ': lBilling - NFX......<span style="color:green">OK</span>';
}
else
{
$ai = __('Testing driver');
$ai .= ': lBilling - NFX......<span style="color:red">';
$ai .= __('Failed') . '</span>';
}
}
// create view for this template
$view = new View('main');
$view->title = __('Settings') . ' - ' . __('VoIP');
$view->content = new View('settings/main');
$view->content->current = 'voip';
$view->content->content = $this->form->html();
$view->content->headline = __('VoIP');
$view->content->additional_info = $ai;
$view->render(TRUE);
}
/**
* SMS settings
*/
......
$view->render(TRUE);
}
// start of validation function
/**
* Check if intervals of VoIP numbers are valid
*
* @author Michal Kliment
* @param object $input input to validation
*/
public function valid_voip_number_interval($input = NULL)
{
// validators cannot be accessed
if (empty($input) || !is_object($input))
{
self::error(PAGE);
}
// parse interval to array of VoIP numbers
$numbers = explode('-', $input->value);
// check if count of numbers is smaller or longer than 2
// (123456789, 987654321; NOT 123456,654321,987654)
if (count($numbers) != 2)
{
$input->add_error('required', __('Bad VoIP number interval format'));
}
else
{
// check if first and second number are 9 characters long (123456789, NOT 1234567890)
if (strlen($numbers[0]) != 9 || strlen($numbers[1]) != 9)
{
$input->add_error('required', __(
'VoIP number must be 9 characters long'
));
}
// check if first and second number are numbers :-) (123456789, NOT abcdefghi)
if (!is_numeric($numbers[0]) || !is_numeric($numbers[1]))
{
$input->add_error('required', __('VoIP number must be a number'));
}
// check if first number are not larger than second number
if ($numbers[0] > $numbers[1])
{
$input->add_error('required', __(
'First number mustn\'t be larger then second number'
));
}
}
}
/**
* Validator
*
* @param object $input
*/
public function valid_voip_number_exclude($input = NULL)
{
// validators cannot be accessed
if (empty($input) || !is_object($input))
{
self::error(PAGE);
}
$value = $input->value;
// do not check empty
if (empty($value)) {
return;
}
// parse interval to array of VoIP numbers
$numbers = explode(';', $input->value);
// check if count of numbers is smaller or longer than 2
// (123456789, 987654321; NOT 123456,654321,987654)
foreach ($numbers as $number)
{
// check if first and second number are 9 characters long (123456789, NOT 1234567890)
if (strlen($number) != 9)
{
$input->add_error('required', __('VoIP number must be 9 characters long'));
break;
}
// check if first and second number are numbers :-) (123456789, NOT abcdefghi)
if (!is_numeric($number))
{
$input->add_error('required', __('VoIP number must be a number'));
break;
}
}
}// end of validatation function
/**
* Validates suffix
*
application/controllers/transfers.php
);
$account = ORM::factory('account')->where('id', $account_id)->find();
if (Billing::instance()->has_driver() &&
Billing::instance()->get_account($account->member_id))
{
$transfers_grid->add_new_button(
'transfers/add_voip/' . $account_id,
__('Recharge VoIP credit')
);
}
}
if ($account->account_attribute_id == Account_attribute_Model::CREDIT)
{
......
$view->render(TRUE);
}
/**
* Function adds VoIP transfers.
*
* @author Roman Sevcik
* @param integer $origin_account
*/
public function add_voip($origin_account = NULL)
{
if (!isset($origin_account))
{
self::warning(PARAMETER);
}
$origin_acc = new Account_Model($origin_account);
if (!$origin_acc->id)
{
self::error(RECORD);
}
if (!$this->acl_check_new('Accounts_Controller', 'transfers', $origin_acc->member_id))
{ // does the user have rights for this?
self::error(ACCESS);
}
if (!Billing::instance()->has_driver() ||
!Billing::instance()->get_account($origin_acc->member_id))
{
self::error(RECORD);
}
$arr_orig_accounts[$origin_acc->id] =
$origin_acc->name . ' - ' . __('Account ID') . ' ' . $origin_acc->id .
' - ' . __('Member ID') . ' ' . $origin_acc->member_id;
// form
$form = new Forge('transfers/add_voip/' . $origin_account);
$form->group('Transfer');
$form->dropdown('oname')
->label('Origin account')
->options($arr_orig_accounts)
->style('width:450px');
$form->date('datetime')
->label('Date and time')
->years(date('Y') - 20, date('Y'))
->rules('required');
$form->input('amount')
->label('Amount')
->rules('required|valid_numeric')
->callback(array($this, 'valid_amount_to_send'));
$form->submit('Send');
if ($form->validate())
{
// default destination account
$operating = ORM::factory('account')->where(
'account_attribute_id', Account_attribute_Model::OPERATING
)->find();
$text = __('Recharging of VoIP credit');
$form_data = $form->as_array();
try
{
$db = new Transfer_Model();
$db->transaction_start();
Transfer_Model::insert_transfer(
$form_data['oname'], $operating->id, null, null,
$this->session->get('user_id'),
Transfer_Model::DEDUCT_VOIP_UNNACCOUNTED_FEE,
date('Y-m-d', $form_data['datetime']), date('Y-m-d H:i:s'),
$text, $form_data['amount']
);
$db->transaction_commit();
status::success('Transfer has been successfully added.');
}
catch (Exception $e)
{
$db->transaction_rollback();
Log::add_exception($e);
status::success('Transfer has not been successfully added');
}
url::redirect('transfers/show_by_account/' . $origin_account);
}
$headline = __('Add new VoIP transfer');
// breadcrumbs navigation
$breadcrumbs = breadcrumbs::add()
->link('members/show_all', 'Members',
$this->acl_check_view('Members_Controller', 'members')
)->disable_translation()
->link('members/show/' . $origin_acc->member->id,
'ID ' . $origin_acc->member->id . ' - ' . $origin_acc->member->name,
$this->acl_check_view(
'Members_Controller', 'members',
$origin_acc->member->id
)
)->enable_translation()
->link('transfers/show_by_account/' . $origin_account,
'Transfers', $origin_account)
->text($headline);
$info[] = __('Information') . ' : ' . __('Transfer will be effected within 15 minutes.');
$view = new View('main');
$view->title = $headline;
$view->content = new View('form');
$view->breadcrumbs = $breadcrumbs->html();
$view->content->headline = $headline;
$view->content->form = $form->html();
$view->content->aditional_info = $info;
$view->render(TRUE);
}
/**
* Function edits double-entry transfers. They should not be edited.
* Wrong transfer should be solved by new transfer.
application/controllers/users.php
$arr_contact_types[$i] = $enum_type_model->get_value($contact->type);
}
// voip is enabled
if (Settings::get('voip_enabled'))
{
$voip_sip = new Voip_sip_Model();
$voip = $voip_sip->get_record_by_user_limited($user_id);
if ($voip->count() == 0)
{
$voip = '<span style="color:red;">'.__('Nonactive').'</span> - '
.html::anchor('voip/add/'.$user_id, __('Activate'));
}
else
{
$voip = html::anchor(
'voip/show/'.$voip->current()->user_id,
$voip->current()->name
);
}
}
$aro_groups = $user->get_aro_groups_of_user($user_id);
......
$view->content->user_data = $user;
$view->content->contacts = $contacts;
$view->content->contact_types = $arr_contact_types;
$view->content->voip = Settings::get('voip_enabled') ? $voip : '';
$view->content->aro_groups = $aro_groups;
$view->content->admin_devices_grid = @$admin_devices_grid;
$view->content->engineer_devices_grid = @$engineer_devices_grid;
application/controllers/voip.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/
*
*/
/**
* VoIP controller.
* Accounts and calls are managed by lbilling from remote server.
*
* @see Billing
* @author Sevcik Roman
* @package Controller
*/
class VoIP_Controller extends Controller
{
/**
* Only check whether is VoIP enabled
*
* @author Michal Kliment
*/
public function __construct()
{
parent::__construct();
// voip is not enabled, quit
if (!Settings::get('voip_enabled'))
Controller::error(ACCESS);
}
/**
* Redirects to show all
*/
public function index()
{
url::redirect('voip/show_all');
}
/**
* Shows all VOIP
*
* @param type $limit_results
* @param string $order_by
* @param string $order_by_direction
* @param type $page_word
* @param type $page
*/
public function show_all(
$limit_results = 100, $order_by = 'user_id', $order_by_direction = 'asc',
$page_word = null, $page = 1)
{
if (!$this->acl_check_view('VoIP_Controller', 'voip'))
Controller::error(ACCESS);
// get new selector
if (is_numeric($this->input->post('record_per_page')))
$limit_results = (int) $this->input->post('record_per_page');
// parameters control
$allowed_order_type = array('id', 'name', 'user_id');
if (!in_array(strtolower($order_by), $allowed_order_type))
$order_by = 'user_id';
if (strtolower($order_by_direction) != 'desc')
$order_by_direction = 'asc';
$model_voip_sip = new Voip_sip_Model();
$total_voip_sip = $model_voip_sip->count_all_records();
if (($sql_offset = ($page - 1) * $limit_results) > $total_voip_sip)
$sql_offset = 0;
$all_voip_sip = $model_voip_sip->get_all_records(
$sql_offset, (int) $limit_results, $order_by, $order_by_direction
);
$headline = __('VoIP');
$grid = new Grid('voip', $headline, array
(
'use_paginator' => true,
'use_selector' => true,
'current' => $limit_results,
'selector_increace' => 100,
'selector_min' => 100,
'selector_max_multiplier' => 10,
'base_url' => Config::get('lang') . '/voip/show_all/'
. $limit_results . '/' . $order_by . '/'
. $order_by_direction,
'uri_segment' => 'page',
'total_items' => $total_voip_sip,
'items_per_page' => $limit_results,
'style' => 'classic',
'order_by' => $order_by,
'order_by_direction' => $order_by_direction,
'limit_results' => $limit_results
));
$grid->add_new_button('voip_calls/show_all', __('List of all calls'));
$grid->callback_field('locked')
->label('State')
->order(false)
->callback(array($this, 'locked'))
->class('center');
$grid->order_link_field('user_id')
->link('voip/show', 'name')
->label('Number');
$grid->order_link_field('user_id')
->link('users/show', 'ufname')
->label('User');
$grid->order_link_field('member_id')
->link('users/show', 'mname')
->label('User');
$grid->callback_field('regseconds')
->label('')
->order(false)
->callback(array($this, 'regseconds'))
->class('center');
$grid->datasource($all_voip_sip);
$view = new View('main');
$view->title = $headline;
$view->breadcrumbs = $headline;
$view->content = $grid;
$view->render(TRUE);
}
/**
* Show VOIP
*
* @param integer $user_id
*/
public function show($user_id = NULL)
{
if (!$user_id)
Controller::warning(PARAMETER);
$user = new User_Model($user_id);
if (!$user->id)
Controller::error(RECORD);
if (!$this->acl_check_view('VoIP_Controller', 'voip', $user->member_id))
Controller::error(ACCESS);
$voip_sip = new Voip_sip_Model();
//check existence of number
$voip = $voip_sip->get_record_by_user_limited($user_id);
if ($voip->count() == 0)
Controller::error(RECORD);
$voip = $voip_sip->get_record_by_user($user_id);
if ($voip->count() == 0)
Controller::error(RECORD);
$sip_server = Settings::get('voip_sip_server', FALSE);
$voip = $voip_sip->get_record_by_user($user_id);
$voip = $voip->current();
$voicemail_model = new Voip_voicemail_user_Model();
$voicemail = $voicemail_model->where('customer_id', $voip->mailbox)->find();
$link_status = (($voip->regseconds - time()) > 1);
$billing = Billing::instance();
$has_driver = $billing->has_driver();
$b_account = $billing->get_account($user->member_id);
$void_account_enabled = $has_driver && ($b_account != null);
$links[] = html::anchor(
'voip/edit_voicemail/' . $voip->user_id, __('Edit voicemail')
);
if ($void_account_enabled)
{
$links[] = html::anchor(
'voip_calls/show_by_user/' . $user_id, __('List of calls')
);
}
$regseconds = ($voip->regseconds - time() < 0 ) ? '0' : $voip->regseconds - time();
$links = implode(' | ', $links);
$breadcrumbs = breadcrumbs::add()
->link('voip/show_all', 'VoIP')
->disable_translation()
->text($voip->name);
// prices of calls
$fixed_price = null;
$cellphone_price = null;
$voip_price = null;
if ($void_account_enabled)
{
if (Settings::get('voip_tariff_fixed'))
{
$fixed_price = $billing->get_price_of_minute_call(
$voip->name, Settings::get('voip_tariff_fixed')
);
}
if (Settings::get('voip_tariff_cellphone'))
{
$cellphone_price = $billing->get_price_of_minute_call(
$voip->name, Settings::get('voip_tariff_cellphone')
);
}
if (Settings::get('voip_tariff_voip'))
{
$voip_price = $billing->get_price_of_minute_call(
$voip->name, Settings::get('voip_tariff_voip')
);
}
}
$view = new View('main');
$view->title = __('Show VoIP account');
$view->breadcrumbs = $breadcrumbs->html();
$view->content = new View('voip/show');
$view->content->headline = __('Show VoIP');
$view->content->links = $links;
$view->content->voip = $voip;
$view->content->sip_server = $sip_server;
$view->content->link_status = $link_status;
$view->content->ipaddr = $voip->ipaddr;
$view->content->port = $voip->port;
$view->content->regseconds = $regseconds;
$view->content->voice_email = $voicemail->email;
$view->content->voice_status = $voicemail->active;
$view->content->fixed_price = $fixed_price;
$view->content->cellphone_price = $cellphone_price;
$view->content->voip_price = $voip_price;
$view->content->void_account_enabled = $void_account_enabled;
$view->render(true);
}
/**
* Changes password
*
* @param integer $user_id
*/
public function change_password($user_id = NULL)
{
if (!$user_id)
Controller::warning(PARAMETER);
$user = new User_Model($user_id);
if (!$user->id)
Controller::error(RECORD);
if (!$this->acl_check_edit('VoIP_Controller', 'voip_password', $user->member_id))
Controller::error(ACCESS);
$voip = ORM::factory('voip_sip')->where('user_id', $user_id)->find();
if ($voip->id == null)
Controller::error(RECORD);
$form = new Forge('voip/change_password/' . $user_id);
$form->password('password')
->label(__('New password') . ':')
->rules('required|length[6,20]');
$form->password('confirm_password')
->label(__('Confirm new password') . ':')
->rules('required|length[6,20]')
->matches($form->password);
$form->submit('Change');
if ($form->validate())
{
$form_data = $form->as_array(FALSE);
$voip_sip = new Voip_sip_Model();
$voip = $voip_sip->where('user_id', $user_id)->find();
$user = ORM::factory('user')->where('id', $user_id)->find();
$username = text::cs_utf2ascii($user->name . ' ' . $user->surname);
$voip->callerid = $username . ' <' . $voip->name . '>';
$voip->secret = $form_data['password'];
if ($voip->save())
{
status::success('Password has been successfully changed.');
}
else
{
status::error('Error - cant change password.');
}
url::redirect('voip/change_password/' . $user_id);
}
else
{
$breadcrumbs = breadcrumbs::add()
->link('voip/show_all', 'VoIP',
$this->acl_check_view('VoIP_Controller', 'voip'))
->disable_translation()
->link('voip/show/' . $voip->user_id, $voip->name,
$this->acl_check_view(
'VoIP_Controller', 'voip', $user->member_id
)
)->enable_translation()
->text('Change password');
$view = new View('main');
$view->title = __('Change password');
$view->breadcrumbs = $breadcrumbs->html();
$view->content = new View('form');
$view->content->headline = __('Password for VoIP account');
$view->content->form = $form->html();
$view->render(TRUE);
}
}
/**
* Chenges voice mail password
*
* @param integer $user_id
*/
public function change_voicemail_password($user_id = NULL)
{
if (!isset($user_id))
Controller::warning(PARAMETER);
$user = new User_Model($user_id);
if (!$user->id)
Controller::error(RECORD);
if (!$this->acl_check_edit('VoIP_Controller', 'voip_password', $user->member_id))
Controller::error(ACCESS);
$voip = ORM::factory('voip_sip')->where('user_id', $user_id)->find();
if (!$voip->id)
Controller::error(RECORD);
$voicemail_model = new Voip_voicemail_user_Model();
$voicemail = $voicemail_model->where('customer_id', $voip->mailbox)->find();
$form = new Forge('voip/change_voicemail_password/' . $user_id);
$form->password('password')
->label(__('New password') . ':')
->rules('required|length[4,4]|valid_digit');
$form->password('confirm_password')
->label(__('Confirm new password') . ':')
->rules('required|length[4,4]|valid_digit')
->matches($form->password);
$form->submit('submit')->value(__('Change'));
if ($form->validate())
{
$form_data = $form->as_array(FALSE);
$voip_sip = new Voip_sip_Model();
$voip = $voip_sip->where('user_id', $user_id)->find();
$voicemail_model = new Voip_voicemail_user_Model();
$voicemail = $voicemail_model->where('customer_id', $voip->mailbox)->find();
$voicemail->password = $form_data['password'];
if ($voicemail->save())
{
status::success('Password has been successfully changed.');
}
else
{
status::error('Error - cant change password.');
}
url::redirect('voip/change_voicemail_password/' . $user_id);
}
else
{
$breadcrumbs = breadcrumbs::add()
->link('voip/show_all', 'VoIP',
$this->acl_check_view('VoIP_Controller', 'voip'))
->disable_translation()
->link('voip/show/' . $voip->user_id, $voip->name,
$this->acl_check_view(
'VoIP_Controller', 'voip', $user->member_id
)
)->enable_translation()
->text('Change voicemail password');
$view = new View('main');
$view->title = __('Change voicemail password');
$view->breadcrumbs = $breadcrumbs->html();
$view->content = new View('form');
$view->content->headline = __('Voicemail password for VoIP account');
$view->content->form = $form->html();
$view->render(TRUE);
}
}
/**
* Edits voice mail
*
* @param integer $user_id
*/
public function edit_voicemail($user_id = NULL)
{
if (!isset($user_id))
Controller::warning(PARAMETER);
$user = new User_Model($user_id);
if (!$user->id)
Controller::error(RECORD);
if (!$this->acl_check_edit('VoIP_Controller', 'voip_password', $user->member_id))
Controller::error(ACCESS);
$voip = ORM::factory('voip_sip')->where('user_id', $user_id)->find();
if ($voip->id == null)
Controller::error(RECORD);
$voicemail_model = new Voip_voicemail_user_Model();
$voicemail = $voicemail_model->where('customer_id', $voip->mailbox)->find();
$form = new Forge('voip/edit_voicemail/' . $user_id);
$form->dropdown('status')
->label(__('State'))
->options(array
(
'0' => __('Inactive'),
'1' => __('Active')
))->selected($voicemail->active);
$form->input('email')
->label(__('email') . ':')
->rules('length[6,50]|valid_email')
->value($voicemail->email);
$form->submit('Edit');
if ($form->validate())
{
$form_data = $form->as_array();
$voip_sip = new Voip_sip_Model();
$voip = $voip_sip->where('user_id', $user_id)->find();
$voicemail_model = new Voip_voicemail_user_Model();
$voicemail = $voicemail_model->where('customer_id', $voip->mailbox)->find();
$voicemail->email = $form_data['email'];
$voicemail->active = $form_data['status'];
if ($voicemail->save())
{
status::success('Voicemail has been successfully changed.');
}
else
{
status::error('Error - cant change voicemail.');
}
url::redirect('voip/edit_voicemail/' . $user_id);
}
else
{
$breadcrumbs = breadcrumbs::add()
->link('voip/show_all', 'VoIP',
$this->acl_check_view('VoIP_Controller', 'voip'))
->disable_translation()
->link('voip/show/' . $voip->user_id, $voip->name,
$this->acl_check_view(
'VoIP_Controller', 'voip', $user->member_id
)
)->enable_translation()
->text('Edit voicemail');
$view = new View('main');
$view->title = __('Edit voicemail');
$view->breadcrumbs = $breadcrumbs->html();
$view->content = new View('form');
$view->content->headline = __('Voicemail for VoIP account');
$view->content->form = $form->html();
$view->render(TRUE);
}
}
/**
* Changes member limit
*
* @param integer $member_id
*/
public function change_member_limit($member_id = NULL)
{
if (!isset($member_id))
Controller::warning(PARAMETER);
if (!is_numeric($member_id))
Controller::error(RECORD);
if (!$this->acl_check_edit('VoIP_Controller', 'voip_password', $member_id))
Controller::error(ACCESS);
$member = new Member_Model($member_id);
if (!$member->id)
Controller::error(RECORD);
$billing = Billing::instance();
$has_driver = $billing->has_driver();
$b_account = $billing->get_account($member_id);
if (!$has_driver || ($b_account == null))
Controller::error(RECORD);
$form = new Forge('voip/change_member_limit/' . $member_id);
$form->input('limit')
->rules('length[1,6]|valid_digit')
->value($member->voip_billing_limit)
->callback(array($this, 'valid_limit'));
$form->submit('Change');
if ($form->validate())
{
$form_data = $form->as_array();
$member->voip_billing_limit = $form_data['limit'];
if ($member->save())
{
status::success('Limit has been successfully changed.');
}
else
{
status::error('Error - cant change limit.');
}
url::redirect('voip/change_member_limit/' . $member_id);
}
else
{
// breadcrumbs navigation
$breadcrumbs = breadcrumbs::add()
->link('members/show_all', 'Members',
$this->acl_check_view('Members_Controller', 'members'))
->disable_translation()
->link('members/show/'.$member->id,
"ID $member->id - $member->name",
$this->acl_check_view(
'Members_Controller', 'members', $member->id
)
)
->enable_translation()
->text('Change member limit');
$view = new View('main');
$view->title = __('Change member limit');
$view->breadcrumbs = $breadcrumbs->html();
$view->content = new View('form');
$view->content->headline = 'VoIP' . __('Limit of member');
$view->content->form = $form->html();
$view->render(TRUE);
}
}
/**
* Adds VoIP for user
*
* @param integer $user_id
*/
public function add($user_id = NULL)
{
if (!isset($user_id))
Controller::warning(PARAMETER);
$user = new User_Model($user_id);
if (!$user->id)
Controller::error(RECORD);
if (!$this->acl_check_new('VoIP_Controller', 'voip', $user->member_id))
Controller::error(ACCESS);
if ($this->input->post('ranges') != NULL)
{
$number = $this->input->post('ranges');
$user = ORM::factory('user')->where('id', $user_id)->find();
$username = text::cs_utf2ascii($user->name . ' ' . $user->surname);
$voip_new = new Voip_sip_Model();
$voip_new->name = $number;
$voip_new->user_id = $user_id;
$voip_new->callerid = $username . ' <' . $number . '>';
$voip_new->mailbox = $number;
$voip_new->secret = security::generate_password();
$voip_new->username = $number;
$voip_new->save();
// get email
$emails = $user->get_user_emails($user->id);
$email = '';
if ($emails != false && $emails->current())
{
$email = $emails->current()->email;
}
$voicemail = new Voip_voicemail_user_Model();
$voicemail->customer_id = $number;
$voicemail->mailbox = $number;
$voicemail->password = security::generate_numeric_password(4);
$voicemail->fullname = $username;
$voicemail->email = $email;
$voicemail->save();
}
$voip_sip = new Voip_sip_Model();
//check existence of number
$voip = $voip_sip->get_record_by_user_limited($user_id);
if ($voip->count() != 0)
url::redirect('voip/show/' . $user_id);
$config_model = new Config_Model();
if ($config_model->check_exist_variable('voip_number_interval'))
{
$ranges = array();
$used_numbers = array();
$ranges = explode('-', $config_model->get_value_from_name('voip_number_interval'));
$exclude_numbers = explode(';', $config_model->get_value_from_name('voip_number_exclude'));
$exist_numbers = $voip_sip->select('name')->find_all();
$i = 0;
foreach ($exist_numbers as $exist_number)
{
$used_numbers[$i] = $exist_number->name;
$i++;
}
for ($i = $ranges[0]; $i <= $ranges[1]; $i++)
{
if (!in_array($i, $used_numbers) && !in_array($i, $exclude_numbers))
$selection[$i] = $i;
}
}
else
{
$selection[0] = '';
}
$ranges = form::dropdown('ranges', $selection, 'standard');
// breadcrumbs navigation
$breadcrumbs = breadcrumbs::add()
->link('members/show_all', 'Members',
$this->acl_check_view('Members_Controller', 'members'))
->disable_translation()
->link('members/show/'.$user->member->id,
'ID ' . $user->member->id . ' - ' . $user->member->name,
$this->acl_check_view(
'Members_Controller', 'members', $user->member->id
)
)
->enable_translation()
->text('Add VoIP account');
$view = new View('main');
$view->title = __('Add VoIP account');
$view->breadcrumbs = $breadcrumbs->html();
$view->content = new View('voip/add');
$view->content->user_id = $user_id;
$view->content->ranges = $ranges;
$view->render(TRUE);
}
///////////////////////////////////////////////////////////////////////////
/// Callbacks /////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
/**
* Function validates amount of limit.
*
* @param object $input
*/
public function valid_limit($input = NULL)
{
// validators cannot be accessed
if (empty($input) || !is_object($input))
{
self::error(PAGE);
}
if ($input->value < 0)
{
$input->add_error('required', __('Error - amount has to be positive.'));
}
}
/**
* Locked state
*
* @param object $item
* @param string $name
*/
protected static function locked($item, $name)
{
if ($item->locked == 1)
{
echo html::image(array
(
'src' => resource::state('locked'),
'alt' => __('Account locked'),
'title' => __('Account locked')
));
}
}
/**
* Phone registration status
*
* @param object $item
* @param string $name
*/
protected static function regseconds($item, $name)
{
if (( $item->regseconds - time()) > 1)
{
echo html::image(array
(
'src' => resource::state('active'),
'alt' => __('Phone registration status') . ' - ' . __('Registered'),
'title' => __('Phone registration status') . ' - ' . __('Registered')
));
}
else
{
echo html::image(array
(
'src' => resource::state('inactive'),
'alt' => __('Phone registration status') . ' - ' . __('Not registered'),
'title' => __('Phone registration status') . ' - ' . __('Not registered')
));
}
}
}
application/controllers/voip_calls.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/
*
*/
/**
* VoIP controller for calls.
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff