Projekt

Obecné

Profil

« Předchozí | Další » 

Revize c1bdc1c4

Přidáno uživatelem Michal Kliment před více než 9 roky(ů)

Release 1.1.0

Zobrazit rozdíly:

application/controllers/notifications.php
*/
class Notifications_Controller extends Controller
{
// activation type
/** activate notification */
const ACTIVATE = 1;
......
/** deactivate notification */
const DEACTIVATE = 3;
// type
/** Notification is applicated on members (all its users) */
const TYPE_MEMBER = 1;
/** Notification is applicated on users */
const TYPE_USER = 2;
/**
* Only enable if notification enabled
*/
public function __construct()
{
parent::__construct();
if (!module::e('notification'))
self::error(ACCESS);
}
/**
* Notification setting for member
*
......
*/
public function member($member_id = NULL)
{
// add TinyMCE init to page
TextEditor::$instance_counter++;
// bad parameter
if (!$member_id || !is_numeric($member_id))
Controller::warning(PARAMETER);
......
Controller::error(RECORD);
// access control
if (!$this->acl_check_new('Messages_Controller', 'member', $member->id))
if (!$this->acl_check_new('Notifications_Controller', 'member', $member->id))
Controller::error(ACCESS);
$headline = __('Notification setting of member').' '.$member->name;
// gets all user messages
$messages = ORM::factory('message')->find_all();
$arr_messages = array();
foreach ($messages as $message)
{
if ($message->type == Message_Model::INTERRUPTED_MEMBERSHIP_MESSAGE ||
$message->type == Message_Model::DEBTOR_MESSAGE ||
$message->type == Message_Model::PAYMENT_NOTICE_MESSAGE ||
$message->type == Message_Model::UNALLOWED_CONNECTING_PLACE_MESSAGE)
{
$arr_messages[$message->id] = __($message->name);
}
else if ($message->type == Message_Model::USER_MESSAGE)
{
$arr_messages[$message->id] = $message->name;
}
}
$arr_messages = array
(
NULL => '----- '.__('select message').' -----'
) + $arr_messages;
NULL => '----- '.__('Select message').' -----'
) + ORM::factory('message')->where('type', Message_Model::USER_MESSAGE)->select_list();
$form = new Forge('notifications/member/'.$member->id);
$form->dropdown('message_id')
->label(__('Message').':')
->label('Message')
->options($arr_messages)
->rules('required');
->rules('required')
->add_button('messages');
$form->textarea('comment');
$form->dropdown('redirection')
->options(array
(
self::ACTIVATE => __('Activate'),
self::KEEP => __('Without change'),
self::DEACTIVATE => __('Deactivate')
));
if (module::e('redirection'))
{
$selected = Notifications_Controller::ACTIVATE;
if (!$member->notification_by_redirection)
{
$selected = Notifications_Controller::KEEP;
}
$form->dropdown('redirection')
->options(notification::redirection_form_array())
->selected($selected);
}
$form->dropdown('email')
->label(__('E-mail').':')
->options(array
(
self::ACTIVATE => __('Activate'),
self::KEEP => __('Without change')
));
if (module::e('email'))
{
$selected = Notifications_Controller::ACTIVATE;
if (!$member->notification_by_email)
{
$selected = Notifications_Controller::KEEP;
}
$form->dropdown('email')
->label('E-mail')
->options(notification::redirection_form_array(TRUE))
->selected($selected);
}
$form->dropdown('sms')
->label(__('SMS message').':')
->options(array
(
self::ACTIVATE => __('Activate'),
self::KEEP => __('Without change')
));
if (module::e('sms'))
{
$selected = Notifications_Controller::ACTIVATE;
if (!$member->notification_by_sms)
{
$selected = Notifications_Controller::KEEP;
}
$form->dropdown('sms')
->label('SMS message')
->options(notification::redirection_form_array(TRUE))
->selected($selected);
}
$form->submit('Send');
$form->submit('Activate');
// form is validate
if ($form->validate())
{
$form_data = $form->as_array();
// needed class
$message = new Message_Model($form_data['message_id']);
$ip_model = new Ip_address_Model();
$mia_model = new Messages_ip_addresses_Model();
$uc_model = new Users_contacts_Model();
// needed data
$user_id = $this->session->get('user_id');
$comment = $form_data['comment'];
$info_messages = array();
// check type
if ($message->type != Message_Model::USER_MESSAGE)
self::error(RECORD);
/* Redirection */
if ($form_data['redirection'] == self::ACTIVATE ||
$form_data['redirection'] == self::DEACTIVATE)
{
// stats vars
$deleted_redr = 0;
$added_redr = 0;
// get all redirection
$ips = $ip_model->get_ip_addresses_of_member($member->id);
// delete redirection of these IP address
foreach ($ips as $ip)
{
$mia_model->delete_redirection_of_ip_address(
$message->id, $ip->id
);
$deleted_redr++;
}
// set new redirection?
if ($form_data['redirection'] == self::ACTIVATE)
{
$added_redr = Message_Model::activate_redirection(
$message, $ips,
$user_id, $comment
);
}
// params
$comment = $form_data['comment'];
$user_id = $this->user_id;
$redirection = $email = $sms = array();
// info messages
if ($added_redr)
{
$m = 'Redirection has been activated for %s IP addresses';
$info_messages[] = __($m, $added_redr).'.';
}
else
{
$m = 'Redirection has been deactivated for %s IP addresses';
$info_messages[] = __($m, $deleted_redr).'.';
}
}
/* Email */
if ($form_data['email'] == self::ACTIVATE)
if (isset($form_data['redirection']) && module::e('redirection'))
{
// gets all contacts of member
$contacts = $uc_model->get_contacts_by_member_and_type(
$member->id, Contact_Model::TYPE_EMAIL,
$message->ignore_whitelist
);
// send email
$sent_emails = Message_Model::send_emails(
$message, $contacts, $comment
);
// info message
$m = 'E-mail has been sent for %s e-mail addresses';
$info_messages[] = __($m, $sent_emails).'.';
$redirection = $_POST['redirection'];
}
/* SMS messages */
if ($form_data['sms'] == self::ACTIVATE)
if (isset($form_data['email']) && module::e('email'))
{
// gets all contacts of member
$contacts = $uc_model->get_contacts_by_member_and_type(
$member->id, Contact_Model::TYPE_PHONE,
$message->ignore_whitelist
);
// send email
$sent_sms = Message_Model::send_sms_messages(
$message, $contacts,
$user_id, $comment
);
$email = $form_data['email'];
}
// info message
$m = 'SMS message has been sent for %d phone numbers.';
$info_messages[] = __($m, $sent_sms);
if (isset($form_data['sms']) && module::e('sms'))
{
$sms = $form_data['sms'];
}
// user notification
// notify
$stats = Notifications_Controller::notify_from_form(
$message, $user_id, $comment,
array($member->id => $redirection),
array($member->id => $email),
array($member->id => $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), $member->name));
status::success(implode('<br />', $info_messages), FALSE);
Log_queue_Model::info($m, implode("\n", $info_messages));
}
// redirect
$this->redirect('members/show/'.$member->id);
url::redirect('members/show/' . $member->id);
}
else
{
......
->enable_translation()
->text('Notification setting');
// member settings properties info
$mediums = array();
if (!$member->notification_by_redirection && module::e('redirection'))
{
$mediums[] = __('redirection', array(), 1);
}
if (!$member->notification_by_email && module::e('email'))
{
$mediums[] = 'e-mail';
}
if (!$member->notification_by_sms && module::e('sms'))
{
$mediums[] = 'SMS';
}
if (count($mediums))
{
status::info('This member do not want to be notified by: %s',
TRUE, implode(', ', $mediums));
}
// view
$view = new View('main');
$view->breadcrumbs = $breadcrumbs;
$view->title = $headline;
......
*/
public function members($message_id = NULL)
{
// add TinyMCE init to page
TextEditor::$instance_counter++;
$headline = __('Notification setting of members');
if (!$this->acl_check_new('Notifications_Controller', 'members'))
Controller::error(ACCESS);
if (!$message_id)
{
$input = $_REQUEST;
{
// gets all user messages
$messages = ORM::factory('message')
->find_all();
$arr_messages = array();
foreach ($messages as $message)
{
// handled by cron
if ($message->type == Message_Model::UNALLOWED_CONNECTING_PLACE_MESSAGE)
{
continue;
}
if ($message->type == Message_Model::INTERRUPTED_MEMBERSHIP_MESSAGE ||
$message->type == Message_Model::DEBTOR_MESSAGE ||
$message->type == Message_Model::PAYMENT_NOTICE_MESSAGE)
{
$arr_messages[$message->id] = __($message->name);
}
else if ($message->type == Message_Model::USER_MESSAGE)
{
$arr_messages[$message->id] = $message->name;
}
}
$arr_messages = array
(
NULL => '----- '.__('Select message').' -----'
) + $arr_messages;
) + 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');
->rules('required')
->add_button('messages');
$form->submit('Next step');
......
$form_data = $form->as_array();
$message_id = arr::remove('message_id', $form_data);
url::redirect(url_lang::base().'notifications/members/'.$message_id.'/'.server::query_string());
url::redirect('notifications/members/'.$message_id.'/'.server::query_string());
}
$breadcrumbs = breadcrumbs::add()
......
$message = new Message_Model($message_id);
// message doesn't exist
if (!$message->id)
if (!$message->id && $message->type != Message_Model::USER_MESSAGE)
Controller::error(RECORD);
if (!isset($_POST) || !isset($_POST["ids"]))
{
switch ($message->type)
{
case Message_Model::DEBTOR_MESSAGE:
case Message_Model::PAYMENT_NOTICE_MESSAGE:
$order_by = 'balance';
$order_by_direction = 'ASC';
break;
case Message_Model::INTERRUPTED_MEMBERSHIP_MESSAGE:
$order_by = 'interrupt';
$order_by_direction = 'DESC';
break;
default:
$order_by = 'id';
$order_by_direction = 'ASC';
break;
}
if (!isset($_POST) || !isset($_POST['ids']))
{
$member_model = new Member_Model();
$filter_form = Members_Controller::create_filter_form();
$total_members = $member_model
->count_all_members(
$total_members = $member_model->count_all_members(
$filter_form->as_sql()
);
);
$members = $member_model
->get_all_members(
0, $total_members,
$order_by, $order_by_direction,
$members = $member_model->get_all_members(
0, $total_members, 'id', 'ASC',
$filter_form->as_sql()
);
);
$grid = new Grid(url_lang::base().'notifications/subnet', '', array
$grid = new Grid('notifications/members', '', array
(
'use_paginator' => false,
'use_selector' => false,
'total_items' => count ($members)
'use_paginator' => false,
'use_selector' => false,
'total_items' => count($members)
));
//$grid->field('id')
// ->label(__('ID'));
$grid->callback_field('member_id')
->label(__('Name'))
->label('Name')
->callback('callback::member_field');
$grid->callback_field('type')
......
$grid->callback_field('balance')
->callback('callback::balance_field');
if ($message->type == Message_Model::INTERRUPTED_MEMBERSHIP_MESSAGE ||
$message->type == Message_Model::DEBTOR_MESSAGE ||
$message->type == Message_Model::PAYMENT_NOTICE_MESSAGE ||
$message->type == Message_Model::USER_MESSAGE)
{
$grid->callback_field('interrupt')
->label(__('Membership interrupt'))
->callback('callback::active_field')
->class('center');
}
$grid->callback_field('interrupt')
->label('Membership interrupt')
->callback('callback::active_field')
->class('center');
$grid->callback_field('whitelisted')
->label(__('Whitelist'))
->label('Whitelist')
->callback('callback::whitelisted_field')
->class('center');
$grid->form_field('redirection')
->label(__('Redirection'))
->type('dropdown')
->options(array
(
self::ACTIVATE => __('Activate'),
self::KEEP => __('Without change'),
self::DEACTIVATE => __('Deactivate')
))
->callback(
'callback::notification_form_field',
$message->type,
$message->ignore_whitelist
)->class('center');
if ($message->type == Message_Model::DEBTOR_MESSAGE ||
$message->type == Message_Model::PAYMENT_NOTICE_MESSAGE ||
$message->type == Message_Model::USER_MESSAGE)
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
)->class('center');
}
if (module::e('email') &&
Message_Model::has_email_content($message->type))
{
$grid->form_field('email')
->label(__('E-Mail'))
->label('E-mail')
->type('dropdown')
->options(array
(
self::ACTIVATE => __('Activate'),
self::KEEP => __('Without change')
))
->options(notification::redirection_form_array(TRUE))
->callback(
'callback::notification_form_field',
$message->type,
$message->ignore_whitelist
'callback::notification_form_field', $message
)->class('center');
}
if (module::e('sms') &&
Message_Model::has_sms_content($message->type))
{
$grid->form_field('sms')
->label(__('SMS'))
->label('SMS')
->type('dropdown')
->options(array
(
self::ACTIVATE => __('Activate'),
self::KEEP => __('Without change')
))
->options(notification::redirection_form_array(TRUE))
->callback(
'callback::notification_form_field',
$message->type,
$message->ignore_whitelist
'callback::notification_form_field', $message
)->class('center');
}
......
"<b>".__('Comment').":</b>"
) . form::textarea('comment', '', 'style="margin-left: 30px"')."<br /><br />"
);
$grid->form_submit_value = __('Activate');
$breadcrumbs = breadcrumbs::add()
->link('members/show_all/'.server::query_string(), 'Members',
......
}
else
{
$ip_address_model = new Ip_address_Model();
$mia_model = new Messages_ip_addresses_Model();
$uc_model = new Users_contacts_Model();
$comment = $_POST["comment"];
$redirections = $_POST["redirection"];
$emails = (isset($_POST["email"])) ? $_POST["email"] : array();
$smss = (isset($_POST["sms"])) ? $_POST["sms"] : array();
$user_id = $this->session->get('user_id');
$added_redr = 0;
$deleted_redr = 0;
$sent_emails = 0;
$sent_sms = 0;
$info_messages = array();
// params
$comment = $_POST['comment'];
$user_id = $this->user_id;
$redirections = $emails = $smss = array();
foreach ($redirections as $member_id => $redirection)
if (isset($_POST['redirection']) && module::e('redirection'))
{
if ($redirection == self::KEEP)
continue;
// get all redirection
$ips = $ip_address_model->get_ip_addresses_of_member($member_id);
// delete redirection of these IP address
foreach ($ips as $ip)
{
$mia_model->delete_redirection_of_ip_address(
$message->id, $ip->id
);
$deleted_redr++;
}
// set new redirection?
if ($redirection == self::ACTIVATE)
{
$added_redr += Message_Model::activate_redirection(
$message, $ips,
$user_id, $comment
);
}
$redirections = $_POST['redirection'];
}
// info messages
if ($added_redr)
{
$m = 'Redirection has been activated for %s IP addresses';
$info_messages[] = __($m, $added_redr).'.';
}
else
{
$m = 'Redirection has been deactivated for %s IP addresses';
$info_messages[] = __($m, $deleted_redr).'.';
}
foreach ($emails as $member_id => $email)
if (isset($_POST['email']) && module::e('email'))
{
if ($email == self::KEEP)
continue;
// gets all contacts of member
$contacts = $uc_model->get_contacts_by_member_and_type(
$member_id, Contact_Model::TYPE_EMAIL, TRUE
);
// send email
$sent_emails += Message_Model::send_emails(
$message, $contacts, $comment
);
$emails = $_POST['email'];
}
// info message
$m = 'E-mail has been sent for %s e-mail addresses';
$info_messages[] = __($m, $sent_emails).'.';
foreach ($smss as $member_id => $sms)
if (isset($_POST['sms']) && module::e('sms'))
{
if ($sms == self::KEEP)
continue;
// gets all contacts of member
$contacts = $uc_model->get_contacts_by_member_and_type(
$member_id, Contact_Model::TYPE_PHONE, TRUE
);
// send email
$sent_sms += Message_Model::send_sms_messages(
$message, $contacts,
$user_id, $comment
);
$smss = $_POST['sms'];
}
// info message
$m = 'SMS message has been sent for %d phone numbers.';
$info_messages[] = __($m, $sent_sms);
// user notification
// 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), __('filtered members', array(), 1)));
status::success(implode('<br />', $info_messages), FALSE);
Log_queue_Model::info($m, implode("\n", $info_messages));
}
// redirect
url::redirect('members/show_all/');
url::redirect('members/show_all/'.server::query_string());
}
}
}
......
*/
public function subnet($subnet_id = NULL, $message_id = NULL)
{
// add TinyMCE init to page
TextEditor::$instance_counter++;
// access control
if (!Settings::get('networks_enabled'))
Controller::error (ACCESS);
if (!$this->acl_check_new('Notifications_Controller', 'subnet'))
Controller::error(ACCESS);
// bad parameter
if (!$subnet_id || !is_numeric($subnet_id))
Controller::warning(PARAMETER);
......
if (!$message_id)
{
// gets all user messages
$messages = ORM::factory('message')
->find_all();
$arr_messages = array();
foreach ($messages as $message)
{
if ($message->type == Message_Model::INTERRUPTED_MEMBERSHIP_MESSAGE ||
$message->type == Message_Model::DEBTOR_MESSAGE ||
$message->type == Message_Model::PAYMENT_NOTICE_MESSAGE ||
$message->type == Message_Model::UNALLOWED_CONNECTING_PLACE_MESSAGE)
{
$arr_messages[$message->id] = __($message->name);
}
else if ($message->type == Message_Model::USER_MESSAGE)
{
$arr_messages[$message->id] = $message->name;
}
}
$arr_messages = array
(
NULL => '----- '.__('select message').' -----'
) + $arr_messages;
) + ORM::factory('message')->where('type', Message_Model::USER_MESSAGE)->select_list();
$form = new Forge('notifications/subnet/'.$subnet->id);
$form->dropdown('message_id')
->label(__('Message').':')
->label('Message')
->options($arr_messages)
->rules('required');
->rules('required')
->add_button('messages');
$form->submit('Next step');
if ($form->validate())
{
$form_data = $form->as_array();
url::redirect(url_lang::base().'notifications/subnet/'.$subnet_id.'/'.$form_data["message_id"]);
url::redirect('notifications/subnet/'.$subnet_id.'/'.$form_data['message_id']);
}
$subnet_text = $subnet->name." ($subnet->network_address/"
......
$breadcrumbs = breadcrumbs::add()
->link('subnets/show_all', __('Subnets'),
$this->acl_check_view('Devices_Controller','subnet'))
$this->acl_check_view('Subnets_Controller','subnet'))
->disable_translation()
->link('subnets/show/'.$subnet->id, $subnet_text,
$this->acl_check_view('Devices_Controller','subnet'))
$this->acl_check_view('Subnets_Controller','subnet'))
->enable_translation()
->text('Notification setting')
->html();
......
$message = new Message_Model($message_id);
// message doesn't exist
if (!$message->id)
if (!$message->id || $message->type != Message_Model::USER_MESSAGE)
Controller::error(RECORD);
if (!isset($_POST) || !isset($_POST["ids"]))
{
switch ($message->type)
{
case Message_Model::DEBTOR_MESSAGE:
case Message_Model::PAYMENT_NOTICE_MESSAGE:
$order_by = 'whitelisted DESC, balance ASC';
break;
case Message_Model::INTERRUPTED_MEMBERSHIP_MESSAGE:
$order_by = 'whitelisted DESC, interrupt DESC';
break;
case Message_Model::UNALLOWED_CONNECTING_PLACE_MESSAGE:
$order_by = 'whitelisted DESC, allowed ASC';
break;
default:
$order_by = 'whitelisted DESC, id ASC';
break;
}
$order_by = 'whitelisted DESC, id ASC';
$member_model = new Member_Model();
......
'total_items' => count ($members)
));
//$grid->field('id')
// ->label(__('ID'));
$grid->callback_field('member_id')
->label(__('Name'))
->label('Name')
->callback('callback::member_field');
$grid->callback_field('type')
......
$grid->callback_field('balance')
->callback('callback::balance_field');
if ($message->type == Message_Model::INTERRUPTED_MEMBERSHIP_MESSAGE ||
$message->type == Message_Model::DEBTOR_MESSAGE ||
$message->type == Message_Model::PAYMENT_NOTICE_MESSAGE ||
$message->type == Message_Model::USER_MESSAGE)
{
$grid->callback_field('interrupt')
->label(__('Membership interrupt'))
->callback('callback::active_field')
->class('center');
}
$grid->callback_field('interrupt')
->label('Membership interrupt')
->callback('callback::active_field')
->class('center');
if ($message->type == Message_Model::UNALLOWED_CONNECTING_PLACE_MESSAGE ||
$message->type == Message_Model::USER_MESSAGE)
{
$grid->callback_field('allowed')
->label(__('Allowed subnet'))
->callback('callback::active_field')
->class('center');
}
$grid->callback_field('allowed')
->label('Allowed subnet')
->callback('callback::active_field')
->class('center');
$grid->callback_field('whitelisted')
->label(__('Whitelist'))
->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
)->class('center');
}
$grid->form_field('redirection')
->label(__('Redirection'))
->type('dropdown')
->options(array
(
self::ACTIVATE => __('Activate'),
self::KEEP => __('Without change'),
self::DEACTIVATE => __('Deactivate')
))
->callback(
'callback::notification_form_field',
$message->type,
$message->ignore_whitelist
)->class('center');
if ($message->type == Message_Model::DEBTOR_MESSAGE ||
$message->type == Message_Model::PAYMENT_NOTICE_MESSAGE ||
$message->type == Message_Model::USER_MESSAGE)
// only if E-mail is enabled
if (module::e('email') &&
Message_Model::has_email_content($message->type))
{
$grid->form_field('email')
->label(__('E-Mail'))
->label('E-mail')
->type('dropdown')
->options(array
(
self::ACTIVATE => __('Activate'),
self::KEEP => __('Without change')
))
->options(notification::redirection_form_array(TRUE))
->callback(
'callback::notification_form_field',
$message->type,
$message->ignore_whitelist
'callback::notification_form_field', $message
)->class('center');
}
if (module::e('sms') &&
Message_Model::has_sms_content($message->type))
{
$grid->form_field('sms')
->label(__('SMS'))
->label('SMS')
->type('dropdown')
->options(array
(
self::ACTIVATE => __('Activate'),
self::KEEP => __('Without change')
))
->options(notification::redirection_form_array(TRUE))
->callback(
'callback::notification_form_field',
$message->type,
$message->ignore_whitelist
'callback::notification_form_field', $message
)->class('center');
}
......
"<b>".__('Comment').":</b>"
) . form::textarea('comment', '', 'style="margin-left: 30px"')."<br /><br />"
);
$grid->form_submit_value = __('Activate');
$subnet_text = $subnet->name." ($subnet->network_address/"
.network::netmask2cidr($subnet->netmask) .")";
$breadcrumbs = breadcrumbs::add()
->link('subnets/show_all', __('Subnets'),
$this->acl_check_view('Devices_Controller','subnet'))
$this->acl_check_view('Subnets_Controller','subnet'))
->disable_translation()
->link('subnets/show/'.$subnet->id, $subnet_text,
$this->acl_check_view('Devices_Controller','subnet'))
$this->acl_check_view('Subnets_Controller','subnet'))
->enable_translation()
->link('notifications/subnet/'.$subnet->id, 'Notification setting')
->text($message->name)
......
}
else
{
$ip_address_model = new Ip_address_Model();
$mia_model = new Messages_ip_addresses_Model();
$uc_model = new Users_contacts_Model();
$comment = $_POST["comment"];
$redirections = $_POST["redirection"];
// params
$comment = $_POST['comment'];
$user_id = $this->user_id;
$redirections = $emails = $smss = array();
$emails = (isset($_POST["email"])) ? $_POST["email"] : array();
$smss = (isset($_POST["sms"])) ? $_POST["sms"] : array();
$user_id = $this->session->get('user_id');
$added_redr = 0;
$deleted_redr = 0;
$sent_emails = 0;
$sent_sms = 0;
$info_messages = array();
foreach ($redirections as $member_id => $redirection)
{
if ($redirection == self::KEEP)
continue;
// get all redirection
$ips = $ip_address_model->get_ip_addresses_of_member($member_id, $subnet->id);
// delete redirection of these IP address
foreach ($ips as $ip)
{
$mia_model->delete_redirection_of_ip_address(
$message->id, $ip->id
);
$deleted_redr++;
}
// set new redirection?
if ($redirection == self::ACTIVATE)
{
$added_redr += Message_Model::activate_redirection(
$message, $ips, TRUE,
$user_id, $comment
);
}
}
// info messages
if ($added_redr)
if (isset($_POST['redirection']) && module::e('redirection'))
{
$m = 'Redirection has been activated for %s IP addresses';
$info_messages[] = __($m, $added_redr).'.';
$redirections = $_POST['redirection'];
}
else
{
$m = 'Redirection has been deactivated for %s IP addresses';
$info_messages[] = __($m, $deleted_redr).'.';
}
foreach ($emails as $member_id => $email)
if (isset($_POST['email']) && module::e('email'))
{
if ($email == self::KEEP)
continue;
// gets all contacts of member
$contacts = $uc_model->get_contacts_by_member_and_type(
$member_id, Contact_Model::TYPE_EMAIL, TRUE
);
// send email
$sent_emails += Message_Model::send_emails(
$message, $contacts, $comment
);
$emails = $_POST['email'];
}
// info message
$m = 'E-mail has been sent for %s e-mail addresses';
$info_messages[] = __($m, $sent_emails).'.';
foreach ($smss as $member_id => $sms)
if (isset($_POST['sms']) && module::e('sms'))
{
if ($sms == self::KEEP)
continue;
// gets all contacts of member
$contacts = $uc_model->get_contacts_by_member_and_type(
$member_id, Contact_Model::TYPE_PHONE, TRUE
);
// send email
$sent_sms += Message_Model::send_sms_messages(
$message, $contacts,
$user_id, $comment
);
$smss = $_POST['sms'];
}
// info message
$m = 'SMS message has been sent for %d phone numbers.';
$info_messages[] = __($m, $sent_sms);
// user notification
// 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), $subnet->name));
status::success(implode('<br />', $info_messages), FALSE);
Log_queue_Model::info($m, implode("\n", $info_messages));
}
// redirect
url::redirect('subnets/show/'.$subnet->id);
}
......
*/
public function cloud($cloud_id = NULL, $message_id = NULL)
{
// add TinyMCE init to page
TextEditor::$instance_counter++;
// bad parameter
if (!$cloud_id || !is_numeric($cloud_id))
Controller::warning(PARAMETER);
if (!$this->acl_check_new('Notifications_Controller', 'cloud'))
Controller::error(ACCESS);
$cloud = new Cloud_Model($cloud_id);
// record doesn't exist
......
if (!$message_id)
{
// gets all user messages
$messages = ORM::factory('message')->find_all();
$arr_messages = array();
foreach ($messages as $message)
{
if ($message->type == Message_Model::INTERRUPTED_MEMBERSHIP_MESSAGE ||
$message->type == Message_Model::DEBTOR_MESSAGE ||
$message->type == Message_Model::PAYMENT_NOTICE_MESSAGE ||
$message->type == Message_Model::UNALLOWED_CONNECTING_PLACE_MESSAGE)
{
$arr_messages[$message->id] = __($message->name);
}
else if ($message->type == Message_Model::USER_MESSAGE)
{
$arr_messages[$message->id] = $message->name;
}
}
$arr_messages = array
(
NULL => '----- '.__('select message').' -----'
) + $arr_messages;
) + ORM::factory('message')->where('type', Message_Model::USER_MESSAGE)->select_list();
$form = new Forge('notifications/cloud/'.$cloud->id);
$form->dropdown('message_id')
->label(__('Message').':')
->label('Message')
->options($arr_messages)
->rules('required');
->rules('required')
->add_button('messages');
$form->submit('Next step');
if ($form->validate())
{
$form_data = $form->as_array();
url::redirect(url_lang::base().'notifications/cloud/'.$cloud_id.'/'.$form_data["message_id"]);
url::redirect('notifications/cloud/'.$cloud_id.'/'.$form_data['message_id']);
}
$name = $cloud->name . ' (' . $cloud_id . ')';
......
$message = new Message_Model($message_id);
// message doesn't exist
if (!$message->id)
if (!$message->id || $message->type != Message_Model::USER_MESSAGE)
Controller::error(RECORD);
if (!isset($_POST) || !isset($_POST["ids"]))
if (!isset($_POST) || !isset($_POST['ids']))
{
switch ($message->type)
{
case Message_Model::DEBTOR_MESSAGE:
case Message_Model::PAYMENT_NOTICE_MESSAGE:
$order_by = 'whitelisted DESC, balance ASC';
break;
case Message_Model::INTERRUPTED_MEMBERSHIP_MESSAGE:
$order_by = 'whitelisted DESC, interrupt DESC';
break;
case Message_Model::UNALLOWED_CONNECTING_PLACE_MESSAGE:
$order_by = 'whitelisted DESC, allowed ASC';
break;
default:
$order_by = 'whitelisted DESC, id ASC';
break;
}
$order_by = 'whitelisted DESC, id ASC';
$member_model = new Member_Model();
......
$grid = new Grid('notifications/cloud', '', array
(
'use_paginator' => false,
'use_selector' => false,
'use_paginator' => FALSE,
'use_selector' => FALSE,
'total_items' => count($members)
));
//$grid->field('id')
// ->label(__('ID'));
$grid->callback_field('member_id')
->label('Name')
->callback('callback::member_field');
......
$grid->callback_field('balance')
->callback('callback::balance_field');
if ($message->type == Message_Model::INTERRUPTED_MEMBERSHIP_MESSAGE ||
$message->type == Message_Model::DEBTOR_MESSAGE ||
$message->type == Message_Model::PAYMENT_NOTICE_MESSAGE ||
$message->type == Message_Model::USER_MESSAGE)
{
$grid->callback_field('interrupt')
->label(__('Membership interrupt'))
$grid->callback_field('interrupt')
->label('Membership interrupt')
->callback('callback::active_field')
->class('center');
}
if ($message->type == Message_Model::UNALLOWED_CONNECTING_PLACE_MESSAGE ||
$message->type == Message_Model::USER_MESSAGE)
{
$grid->callback_field('allowed')
$grid->callback_field('allowed')
->label('Allowed subnet')
->callback('callback::active_field')
->class('center');
}
$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')
->label('Redirection')
->type('dropdown')
->options(notification::redirection_form_array())
->callback(
'callback::notification_form_field', $message
);
}
$grid->form_field('redirection')
->label('Redirection')
->type('dropdown')
->options(array
(
self::ACTIVATE => __('Activate'),
self::KEEP => __('Without change'),
self::DEACTIVATE => __('Deactivate')
))
->callback('callback::notification_form_field', $message->type, $message->ignore_whitelist);
if ($message->type == Message_Model::DEBTOR_MESSAGE ||
$message->type == Message_Model::PAYMENT_NOTICE_MESSAGE ||
$message->type == Message_Model::USER_MESSAGE)
// only if E-mail is enabled
if (module::e('email') &&
Message_Model::has_email_content($message->type))
{
$grid->form_field('email')
->label('E-Mail')
->type('dropdown')
->options(array
(
self::ACTIVATE => __('Activate'),
self::KEEP => __('Without change')
))
->callback('callback::notification_form_field', $message->type, $message->ignore_whitelist);
->label('E-mail')
->type('dropdown')
->options(notification::redirection_form_array(TRUE))
->callback(
'callback::notification_form_field', $message
);
}
if (module::e('sms') &&
Message_Model::has_sms_content($message->type))
{
$grid->form_field('sms')
->label('SMS')
->type('dropdown')
->options(array
(
self::ACTIVATE => __('Activate'),
self::KEEP => __('Without change')
))
->callback(
'callback::notification_form_field',
$message->type,
$message->ignore_whitelist
);
->label('SMS')
->type('dropdown')
->options(notification::redirection_form_array(TRUE))
->callback(
'callback::notification_form_field', $message
);
}
$grid->form_extra_buttons = array
......
"<b>".__('Comment').":</b>"
) . form::textarea('comment', '', 'style="margin-left: 30px"')."<br /><br />"
);
$grid->form_submit_value = __('Activate');
$name = $cloud->name . ' (' . $cloud_id . ')';
......
}
else
{
$ip_address_model = new Ip_address_Model();
$mia_model = new Messages_ip_addresses_Model();
$uc_model = new Users_contacts_Model();
$comment = $_POST["comment"];
$redirections = $_POST["redirection"];
$emails = (isset($_POST["email"])) ? $_POST["email"] : array();
$smss = (isset($_POST["sms"])) ? $_POST["sms"] : array();
$user_id = $this->session->get('user_id');
// params
$comment = $_POST['comment'];
$user_id = $this->user_id;
$redirections = $emails = $smss = array();
$added_redr = 0;
$deleted_redr = 0;
$sent_emails = 0;
$sent_sms = 0;
$info_messages = array();
foreach ($redirections as $member_id => $redirection)
{
if ($redirection == self::KEEP)
continue;
// get all redirection
$ips = $ip_address_model->get_ip_addresses_of_member(
$member_id,
NULL,
$cloud->id
);
// delete redirection of these IP address
foreach ($ips as $ip)
{
$mia_model->delete_redirection_of_ip_address(
$message->id, $ip->id
);
$deleted_redr++;
}
// set new redirection?
if ($redirection == self::ACTIVATE)
{
$added_redr += Message_Model::activate_redirection(
$message, $ips,
$user_id, $comment
);
}
}
// info messages
if ($added_redr)
if (isset($_POST['redirection']) && module::e('redirection'))
{
$m = 'Redirection has been activated for %s IP addresses';
$info_messages[] = __($m, $added_redr).'.';
$redirections = $_POST['redirection'];
}
else
{
$m = 'Redirection has been deactivated for %s IP addresses';
$info_messages[] = __($m, $deleted_redr).'.';
}
foreach ($emails as $member_id => $email)
if (isset($_POST['email']) && module::e('email'))
{
if ($email == self::KEEP)
continue;
// gets all contacts of member
$contacts = $uc_model->get_contacts_by_member_and_type(
$member_id, Contact_Model::TYPE_EMAIL, TRUE
);
// send email
$sent_emails += Message_Model::send_emails(
$message, $contacts, $comment
);
$emails = $_POST['email'];
}
// info message
$m = 'E-mail has been sent for %s e-mail addresses';
$info_messages[] = __($m, $sent_emails).'.';
foreach ($smss as $member_id => $sms)
if (isset($_POST['sms']) && module::e('sms'))
{
if ($sms == self::KEEP)
continue;
// gets all contacts of member
$contacts = $uc_model->get_contacts_by_member_and_type(
$member_id, Contact_Model::TYPE_PHONE, TRUE
);
// send email
$sent_sms += Message_Model::send_sms_messages(
$message, $contacts,
$user_id, $comment
);
$smss = $_POST['sms'];
}
// info message
$m = 'SMS message has been sent for %d phone numbers.';
$info_messages[] = __($m, $sent_sms);
// user notification
// 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), $cloud->name));
status::success(implode('<br />', $info_messages), FALSE);
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff