Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 2150

Přidáno uživatelem David Raška před asi 11 roky(ů)

Nove:
- ref #191: Upozorneni spravcu zarizeni, zatim se upozornuji vsichni uzivatele a IP adresy clena

Zobrazit rozdíly:

freenetis/branches/1.1/application/controllers/devices.php
'class' => 'popup_link'
));
}
if (module::e('notification') &&
$this->acl_check_new('Notifications_Controller', 'devices'))
{
$grid->add_new_button('notifications/devices'.server::query_string(), 'Notifications', array
(
'title' => __('Set notification to devices admins'),
));
}
$grid->order_field('device_id')
->label('ID')
freenetis/branches/1.1/application/controllers/js.php
$this->notification_activate();
}
private function _js_notifications_device()
{
$this->notification_activate();
}
private function _js_notifications_devices()
{
$this->notification_activate();
}
private function _js_notifications_member()
{
$this->notification_activate();
freenetis/branches/1.1/application/controllers/notifications.php
}
/**
* Notification setting for device admins
*
* @author David Raška
* @param integer $device_id
*/
public function device($device_id = NULL)
{
// add TinyMCE init to page
TextEditor::$instance_counter++;
// bad parameter
if (!$device_id || !is_numeric($device_id))
Controller::warning(PARAMETER);
$device = new Device_Model($device_id);
// record doesn't exist
if (!$device->id)
Controller::error(RECORD);
// access control
if (!$this->acl_check_new('Notifications_Controller', 'device'))
Controller::error(ACCESS);
$headline = __('Notification setting of device admins').' '.$device->name;
// gets all user messages
$arr_messages = array
(
NULL => '----- '.__('Select message').' -----'
) + ORM::factory('message')->where('type', Message_Model::USER_MESSAGE)->select_list();
$form = new Forge('notifications/device/'.$device->id);
$form->dropdown('message_id')
->label('Message')
->options($arr_messages)
->rules('required')
->add_button('messages');
$form->textarea('comment');
if (module::e('redirection'))
{
$form->dropdown('redirection')
->options(notification::redirection_form_array());
}
if (module::e('email'))
{
$form->dropdown('email')
->label('E-mail')
->options(notification::redirection_form_array(TRUE));
}
if (module::e('sms'))
{
$form->dropdown('sms')
->label('SMS message')
->options(notification::redirection_form_array(TRUE));
}
$form->submit('Send');
// form is validate
if ($form->validate())
{
$form_data = $form->as_array();
$message = new Message_Model($form_data['message_id']);
// check type
if ($message->type != Message_Model::USER_MESSAGE)
self::error(RECORD);
// params
$comment = $form_data['comment'];
$user_id = $this->user_id;
$redirection = $email = $sms = array();
$redirections = $emails = $smss = array();
// device admins
$da = ORM::factory('device_admin')->where('device_id', $device_id)->find_all();
if (isset($form_data['redirection']) && module::e('redirection'))
{
$redirection = $_POST['redirection'];
}
if (isset($form_data['email']) && module::e('email'))
{
$email = $form_data['email'];
}
if (isset($form_data['sms']) && module::e('sms'))
{
$sms = $form_data['sms'];
}
foreach ($da AS $admin)
{
if ($redirection)
{
$redirections[$admin->user->member->id] = $redirection;
}
if ($email)
{
$emails[$admin->user->member->id] = $email;
}
if ($sms)
{
$smss[$admin->user->member->id] = $sms;
}
}
// notify
$stats = Notifications_Controller::notify_from_form(
$message, $user_id, $comment,
$redirections, $emails, $smss
);
// info messages
$info_messages = notification::build_stats_string(
$stats, module::e('redirection'), module::e('email'),
module::e('sms'), module::e('redirection')
);
// log action
if (count($info_messages))
{
$un = ORM::factory('user', $user_id)->get_full_name();
$m = __('User "%s" has activated notification message "%s" on "%s"',
array($un, __($message->name), $device->name));
status::success(implode('<br />', $info_messages), FALSE);
Log_queue_Model::info($m, implode("\n", $info_messages));
}
// redirect
$this->redirect('devices/show/' . $device->id);
}
else
{
// breadcrumbs navigation
$breadcrumbs = breadcrumbs::add()
->link('members/show_all', 'Members',
$this->acl_check_view('Members_Controller','members'))
->disable_translation()
->link('members/show/' . $device->user->member->id,
'ID ' . $device->user->member->id . ' - ' . $device->user->member->name,
$this->acl_check_view('Members_Controller','members', $device->user->member->id))
->enable_translation()
->link('users/show_by_member/' . $device->user->member_id, 'Users',
$this->acl_check_view('Users_Controller', 'users', $device->user->member_id))
->disable_translation()
->link('users/show/' . $device->user->id,
$device->user->name . ' ' . $device->user->surname . ' (' . $device->user->login . ')',
$this->acl_check_view('Users_Controller', 'users', $device->user->member_id))
->enable_translation()
->link('devices/show_by_user/' . $device->user->id, 'Devices',
$this->acl_check_view('Devices_Controller', 'devices', $device->user->member_id))
->disable_translation()
->link('devices/show/' . $device->id, $device->name,
$this->acl_check_view('Devices_Controller', 'devices',$device->user->member_id))
->enable_translation()
->text('Notification setting');
$view = new View('main');
$view->breadcrumbs = $breadcrumbs;
$view->title = $headline;
$view->content = new View('form');
$view->content->headline = $headline;
$view->content->form = $form;
$view->render(TRUE);
}
}
/**
* Notification setting for devices admins
*
* @author David Raška
* @param integer $message_id
*/
public function devices($message_id = NULL)
{
// add TinyMCE init to page
TextEditor::$instance_counter++;
$headline = __('Notification setting of devices admins');
if (!$this->acl_check_new('Notifications_Controller', 'devices'))
Controller::error(ACCESS);
if (!$message_id)
{
// gets all user messages
$arr_messages = array
(
NULL => '----- '.__('Select message').' -----'
) + ORM::factory('message')->where('type', Message_Model::USER_MESSAGE)->select_list();
$form = new Forge(url::base().url::current(TRUE));
$form->dropdown('message_id')
->label('Message')
->options($arr_messages)
->rules('required')
->add_button('messages');
$form->submit('Next step');
if ($form->validate())
{
$form_data = $form->as_array();
$message_id = arr::remove('message_id', $form_data);
url::redirect('notifications/devices/'.$message_id.'/'.server::query_string());
}
$breadcrumbs = breadcrumbs::add()
->link('devices/show_all/'.server::query_string(), 'Devices',
$this->acl_check_view('Devices_Controller', 'devices'))
->text('Notification setting')
->html();
$view = new View('main');
$view->breadcrumbs = $breadcrumbs;
$view->title = $headline;
$view->content = new View('form');
$view->content->headline = $headline;
$view->content->form = $form;
$view->render(TRUE);
}
else
{
// bad message parameter
if (!is_numeric($message_id))
Controller::warning(PARAMETER);
$message = new Message_Model($message_id);
// message doesn't exist
if (!$message->id && $message->type != Message_Model::USER_MESSAGE)
Controller::error(RECORD);
if (!isset($_POST) || !isset($_POST['ids']))
{
$device_admin_model = new Device_admin_Model();
$filter_form = new Filter_form('d');
$filter_form->add('name')
->callback('json/device_name');
$filter_form->add('type')
->type('select')
->values(ORM::factory('Enum_type')
->get_values(Enum_type_model::DEVICE_TYPE_ID));
$filter_form->add('trade_name')
->callback('json/device_trade_name');
$filter_form->add('user_name')
->type('combo')
->label('Firstname of user')
->callback('json/user_name');
$filter_form->add('user_surname')
->type('combo')
->label('Surname of user')
->callback('json/user_surname');
$filter_form->add('device_member_name')
->callback('json/member_name');
$filter_form->add('login')
->label('Username')
->callback('json/device_login');
$filter_form->add('password')
->callback('json/device_password');
$filter_form->add('price')
->type('number');
$filter_form->add('payment_rate')
->label('Monthly payment rate')
->type('number');
$filter_form->add('buy_date')
->type('date');
$filter_form->add('town')
->type('combo')
->callback('json/town_name');
$filter_form->add('street')
->type('combo')
->callback('json/street_name');
$filter_form->add('street_number')
->type('number');
$filter_form->add('mac')
->label('MAC address')
->class('mac')
->callback('json/iface_mac');
$filter_form->add('comment');
$filter_form->add('cloud')
->type('select')
->values(ORM::factory('cloud')->select_list());
$total_devices_admins = $device_admin_model->count_all_devices_admins(
$filter_form->as_sql()
);
$devices_admins = $device_admin_model->get_all_devices_admins(array
(
'offset' => 0,
'limit' => (int) $total_devices_admins,
'order_by' => 'member_id',
'order_by_direction' => 'ASC',
'filter_sql' => $filter_form->as_sql()
));
$grid = new Grid('notifications/devices', '', array
(
'use_paginator' => false,
'use_selector' => false,
'total_items' => count($devices_admins)
));
$grid->callback_field('member_id')
->label('Name')
->callback('callback::member_field');
$grid->callback_field('member_type')
->callback('callback::member_type_field');
$grid->callback_field('whitelisted')
->label('Whitelist')
->callback('callback::whitelisted_field')
->class('center');
if (module::e('redirection') &&
Message_Model::has_redirection_content($message->type))
{
$grid->form_field('redirection')
->type('dropdown')
->options(notification::redirection_form_array())
->callback(
'callback::notification_form_field',
$message->type, $message->ignore_whitelist
)->class('center');
}
if (module::e('email') &&
Message_Model::has_email_content($message->type))
{
$grid->form_field('email')
->label('E-mail')
->type('dropdown')
->options(notification::redirection_form_array(TRUE))
->callback(
'callback::notification_form_field',
$message->type,
$message->ignore_whitelist
)->class('center');
}
if (module::e('sms') &&
Message_Model::has_sms_content($message->type))
{
$grid->form_field('sms')
->label('SMS')
->type('dropdown')
->options(notification::redirection_form_array(TRUE))
->callback(
'callback::notification_form_field',
$message->type, $message->ignore_whitelist
)->class('center');
}
$grid->form_extra_buttons = array
(
"position" => 'top',
form::label(
'comment',
"<b>".__('Comment').":</b>"
) . form::textarea('comment', '', 'style="margin-left: 30px"')."<br /><br />"
);
$breadcrumbs = breadcrumbs::add()
->link('devices/show_all/'.server::query_string(), 'Devices',
$this->acl_check_view('Devices_Controller', 'devices'))
->link('notifications/devices/'.server::query_string(), 'Notification setting')
->text($message->name)
->html();
$grid->datasource($devices_admins);
$view = new View('main');
$view->breadcrumbs = $breadcrumbs;
$view->title = $headline;
$view->content = new View('show_all');
$view->content->headline = $headline;
$view->content->table = $grid;
$view->content->status_message_info = url_lang::lang('help.notification_settings');
$view->render(TRUE);
}
else
{
// params
$comment = $_POST['comment'];
$user_id = $this->user_id;
$redirection = $email = $sms = array();
if (isset($_POST['redirection']) && module::e('redirection'))
{
$redirection = $_POST['redirection'];
}
if (isset($_POST['email']) && module::e('email'))
{
$email = $_POST['email'];
}
if (isset($_POST['sms']) && module::e('sms'))
{
$sms = $_POST['sms'];
}
// notify
$stats = Notifications_Controller::notify_from_form(
$message, $user_id, $comment,
$redirection, $email, $sms
);
// info messages
$info_messages = notification::build_stats_string(
$stats, module::e('redirection'), module::e('email'),
module::e('sms'), module::e('redirection')
);
// log action
if (count($info_messages))
{
$un = ORM::factory('user', $user_id)->get_full_name();
$m = __('User "%s" has activated notification message "%s" on "%s"',
array($un, __($message->name), __('filtered devices', array(), 1)));
status::success(implode('<br />', $info_messages), FALSE);
Log_queue_Model::info($m, implode("\n", $info_messages));
}
// redirect
$this->redirect('devices/show_all'.server::query_string());
}
}
}
/**
* Activate notification of message for the given memebers and given
* restrictions.
*
freenetis/branches/1.1/application/i18n/cs_CZ/texts.php
'filter query has been successfully deleted' => 'Dotaz filtru byl úspěšně smazán.',
'filter query has been successfully set as default' => 'Dotaz filtru byl úspěšně nastaven jako výchozí.',
'filter query has been successfully unset as default' => 'Dotaz filtru byl úspěšně zrušen jako výchozí.',
'filtered devices' => 'Vyfiltrované zařízení',
'filtered members' => 'Vyfiltrované členy',
'filters' => 'Filtry',
'finances' => 'Finance',
......
'notification message "%s" has been automatically activated' => 'Upozorňovací zpráva "%s" byla automaticky aktivována',
'notification setting' => 'Nastavení upozornění',
'notification setting of cloud' => 'Nastavení upozornění pro oblast',
'notification setting of device admins' => 'Nastavení upozornění pro správce zařízení',
'notification setting of devices admins' => 'Nastavení upozornění pro správce zařízení',
'notification setting of member' => 'Nastavení upozornění pro člena',
'notification setting of members' => 'Nastavení upozornění pro členy',
'notification setting of subnet' => 'Nastavení upozornění pro podsíť',
......
'service' => 'Služba',
'set variable key generator before approving applicants' => 'Nastavte generátor vyriabilních symbolů před tím než budete přijímat členy.',
'set as default for this url' => 'Nastavit jako výchozí pro tuto URL',
'set notification to device admins' => 'Nastavit notifikaci správcům zařízení',
'set notification to devices admins' => 'Nastavit notifikaci správcům zařízení',
'set notification to member' => 'Nastavit notifikace členovi',
'set votes to' => 'Nastavit hlasy na',
'set whitelist to member' => 'Nastavit bílou listinu členovi',
freenetis/branches/1.1/application/models/device_admin.php
ORDER BY d.name
", array($user_id));
}
/**
* Gets all devices admins from database. Database query returns member's device parameters (id, name, type),
* owner of device (user name and surname), MAC addresses of interfaces, names of segments and ip addresses.
*
* @param array $params
* @param integer $user_id
* @return Mysql_Result
*/
public function get_all_devices_admins($params = array(), $user_id = NULL)
{
// default params
$default_params = array
(
'order_by' => 'id',
'order_by_direction' => 'asc'
);
$params = array_merge($default_params, $params);
$conds = array();
// filter
if (isset($params['filter_sql']) && $params['filter_sql'] != '')
$conds[] = $params['filter_sql'];
// user id
if ($user_id)
$conds[] = "d.user_id = " . intval($user_id);
$where = count($conds) ? 'WHERE '.implode(' AND ', $conds) : '';
$order_by = $this->db->escape_column($params['order_by']);
// order by direction check
if (strtolower($params['order_by_direction']) != 'desc')
$order_by_direction = 'asc';
else
$order_by_direction = 'desc';
if (isset($params['limit']) && isset($params['offset']))
$limit = "LIMIT " . intval($params['offset']) . ", " . intval($params['limit']);
else
$limit = "";
// HACK FOR IMPROVING PERFORMANCE (fixes #362)
$select_cloud_iface = '';
$join_cloud_iface = '';
if (isset($params['filter_sql']) && $params['filter_sql'] != '' &&
(strpos($params['filter_sql'], '.`cloud` LIKE ') ||
strpos($params['filter_sql'], '.`mac` LIKE ')))
{
$select_cloud_iface = ', c.id AS cloud, i.mac';
$join_cloud_iface = "
LEFT JOIN ifaces i ON i.device_id = d.id
LEFT JOIN ip_addresses ip ON ip.iface_id = i.id
LEFT JOIN clouds_subnets cs ON cs.subnet_id = ip.subnet_id
LEFT JOIN clouds c ON cs.cloud_id = c.id";
}
// query
return $this->db->query("
SELECT * FROM
(
SELECT dam.id, d.id AS device_id, d.type,
IFNULL(f.translated_term, e.value) AS type_name,
d.name, d.name AS device_name, u.id AS user_id,
u.name AS user_name, u.surname AS user_surname, u.login AS user_login,
d.login, d.password, d.price, d.trade_name, d.payment_rate,
d.buy_date, m.name AS device_member_name, s.street, t.town,
ap.street_number, d.comment, 1 AS redirection, 1 AS email,
1 AS sms, dam.id AS member_id, dam.type as member_type,
whitelisted, IF(mi.id IS NOT NULL, 1, 0) AS interrupt,
dam.name AS member_name $select_cloud_iface
FROM devices d
JOIN users u ON d.user_id = u.id
JOIN members m ON u.member_id = m.id
JOIN device_admins da ON da.device_id = d.id
JOIN users dau ON da.user_id = dau.id
JOIN members dam ON dau.member_id = dam.id
LEFT JOIN address_points ap ON d.address_point_id = ap.id
LEFT JOIN streets s ON ap.street_id = s.id
LEFT JOIN towns t ON ap.town_id = t.id
LEFT JOIN enum_types e ON d.type = e.id
LEFT JOIN translations f ON lang = ? AND e.value = f.original_term
LEFT JOIN
(
SELECT mi.id, mi.member_id
FROM membership_interrupts mi
LEFT JOIN members_fees mf ON mi.members_fee_id = mf.id
WHERE mf.activation_date <= CURDATE() AND mf.deactivation_date >= CURDATE()
) mi ON mi.member_id = dam.id
LEFT JOIN
(
SELECT m2.id AS member_id, IF(mw.member_id IS NULL, 0, 2 - mw.permanent) AS whitelisted
FROM members m2
LEFT JOIN members_whitelists mw ON mw.member_id = m2.id
AND mw.since <= CURDATE() AND mw.until >= CURDATE()
) ip ON ip.member_id = dam.id
$join_cloud_iface
) d
$where
GROUP BY member_id
ORDER BY $order_by $order_by_direction
$limit
", Config::get('lang'));
} // end of get_all_devices_admins
/**
* Count of all devices admins
* @param array $filter_values
* @return integer
*/
public function count_all_devices_admins($filter_sql = '')
{
$where = '';
// filter
if ($filter_sql != '')
$where = "WHERE $filter_sql";
// HACK FOR IMPROVING PERFORMANCE (fixes #362)
$select_cloud_iface = '';
$join_cloud_iface = '';
if (strpos($filter_sql, '.`cloud` LIKE ') || strpos($filter_sql, '.`mac` LIKE '))
{
$select_cloud_iface = ', c.id AS cloud, i.mac';
$join_cloud_iface = "
LEFT JOIN ifaces i ON i.device_id = d.id
LEFT JOIN ip_addresses ip ON ip.iface_id = i.id
LEFT JOIN clouds_subnets cs ON cs.subnet_id = ip.subnet_id
LEFT JOIN clouds c ON cs.cloud_id = c.id";
}
// query
return $this->db->query("
SELECT COUNT(member_id) AS total FROM
(
SELECT member_id FROM
(
SELECT d.id AS device_id, d.type,
IFNULL(f.translated_term, e.value) AS type_name, d.name,
d.name AS device_name, u.id AS user_id, u.name AS user_name,
u.surname AS user_surname, u.login AS user_login,
d.login, d.password, d.price, d.trade_name, d.payment_rate,
d.buy_date, m.name AS member_name, s.street, t.town,
ap.street_number, d.comment, dam.id AS member_id $select_cloud_iface
FROM devices d
JOIN users u ON d.user_id = u.id
JOIN members m ON u.member_id = m.id
LEFT JOIN address_points ap ON d.address_point_id = ap.id
LEFT JOIN streets s ON ap.street_id = s.id
LEFT JOIN towns t ON ap.town_id = t.id
LEFT JOIN enum_types e ON d.type = e.id
LEFT JOIN translations f ON lang = ? AND e.value = f.original_term
JOIN device_admins da ON da.device_id = d.id
JOIN users dau ON da.user_id = dau.id
JOIN members dam ON dau.member_id = dam.id
$join_cloud_iface
) d
$where
GROUP BY member_id
) count
", Config::get('lang'))->current()->total;
} // end of count_all_devices_admins
}
freenetis/branches/1.1/application/views/devices/show.php
$links[] = html::anchor('device_logs/show_by_device/'.$device->id, __('Show logs'));
}
if (module::e('notification') &&
$this->acl_check_new('Notifications_Controller', 'device'))
{
$links[] = html::anchor(
'notifications/device/'.$device->id, __('Notifications'),
array('title' => __('Set notification to device admins'))
);
}
if ($this->acl_check_view('Devices_Controller', 'export', $device->user->member_id))
$links[] = html::anchor('devices/export/'.$device->id, __('Export'));
freenetis/branches/1.1/db_upgrades/upgrade_1.1.0~alpha53.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 previous upgrades
*
* @author David Raška
*/
$upgrade_equal_to['1.1.0~alpha53'] = array();
/**
* Adds AXO for accessing device admins notification and devices admins notification
*
* @author David Raška
*/
$upgrade_sql['1.1.0~alpha53'] = array
(
"INSERT INTO axo SELECT MAX(id)+1, 'Notifications_Controller', 'device', 'Device admins notification' FROM axo",
"INSERT INTO axo_map (acl_id, section_value, value) VALUES ('38', 'Notifications_Controller', 'device');",
"INSERT INTO axo SELECT MAX(id)+1, 'Notifications_Controller', 'devices', 'Devices admins notification' FROM axo",
"INSERT INTO axo_map (acl_id, section_value, value) VALUES ('38', 'Notifications_Controller', 'devices');"
);
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~alpha52');
define('FREENETIS_VERSION', '1.1.0~alpha53');

Také k dispozici: Unified diff