Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 2054

Přidáno uživatelem Ondřej Fibich před asi 11 roky(ů)

Novinky:
- closes #635: Pretvorit aktivaci notifikaci pomoci Notification_Controller#notify
- closes #656: Optimalizace shlukovanim u Notifications_Controller#notify
- helper module s metodou e pro zjistovani zda je modul povolen (enabled)

Upravy:
- pridany filtry v SMS
- zrychleni web_interface vypnutim preprocesoru

Zobrazit rozdíly:

freenetis/branches/1.1/application/controllers/members.php
{
$member_links[] = html::anchor(
'notifications/member/'.$member->id, __('Notifications'),
array
(
'title' => __('Set notification to member'),
'class' => 'popup_link'
)
array('title' => __('Set notification to member'))
);
$member_links[] = html::anchor(
......
Message_Model::FORMER_MEMBER_MESSAGE
);
// create notification object
$member_notif = new stdClass();
$member_notif->member_id = $member->id;
$member_notif->whitelisted = $member->has_whitelist();
$member_notif = array
(
'member_id' => $member->id,
'whitelisted' => $member->has_whitelist()
);
// notify by email
Notifications_Controller::notify(
$message, array($member_notif), $this->user_id,
NULL, FALSE, TRUE, TRUE, FALSE, TRUE
NULL, FALSE, TRUE, TRUE, FALSE, FALSE, TRUE
);
}
freenetis/branches/1.1/application/controllers/membership_interrupts.php
Message_Model::INTERRUPTED_MEMBERSHIP_BEGIN_NOTIFY_MESSAGE
);
// create notification object
$member_notif = new stdClass();
$member_notif->member_id = $members_fee->member_id;
$member_notif->whitelisted = $members_fee->member->has_whitelist();
$member_notif = array
(
'member_id' => $members_fee->member->id,
'whitelisted' => $members_fee->member->has_whitelist()
);
// notify by email
Notifications_Controller::notify(
$message, array($member_notif), $this->user_id,
NULL, FALSE, TRUE, TRUE, FALSE, FALSE, TRUE
NULL, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, TRUE
);
}
......
}
catch (Exception $e)
{
$mi->transaction_rollback();
$membership_interrupt->transaction_rollback();
Log::add_exception($e);
status::success('Membership interrupt has not been succesfully added');
}
freenetis/branches/1.1/application/controllers/messages.php
->type('select')
->values(Message_Model::get_types());
$filter_form->add('text')
->label('Content of the message for redirection');
if (module::e('redirection'))
{
$filter_form->add('text')
->label('Content of the message for redirection');
}
if (Settings::get('email_enabled'))
if (module::e('email'))
{
$filter_form->add('email_text')
->label('Content of the message for e-mail');
}
if (Settings::get('sms_enabled'))
if (module::e('sms'))
{
$filter_form->add('sms_text')
->label('Content of the message for sms');
......
// model
$message_model = new Message_Model();
// hide grid on its first load (#442)
$hide_grid = Settings::get('grid_hide_on_first_load') && $filter_form->is_first_load();
if (!$hide_grid)
{
try
{
$total_messages = $message_model->count_all_messages($filter_form->as_sql());
if (($sql_offset = ($page - 1) * $limit_results) > $total_messages)
$sql_offset = 0;
$total_messages = $message_model->count_all_messages($filter_form->as_sql());
$messages = $message_model->get_all_messages(
$sql_offset, $limit_results, $order_by, $order_by_direction,
$filter_form->as_sql()
);
}
catch (Exception $e)
{
if ($filter_form->is_loaded_from_saved_query())
{
status::error('Invalid saved query', $e);
// disable default query (loop protection)
if ($filter_form->is_loaded_from_default_saved_query())
{
ORM::factory('filter_query')->remove_default($filter_form->get_base_url());
}
$this->redirect(url_lang::current());
}
throw $e;
}
}
if (($sql_offset = ($page - 1) * $limit_results) > $total_messages)
$sql_offset = 0;
$messages = $message_model->get_all_messages(
$sql_offset, $limit_results, $order_by, $order_by_direction,
$filter_form->as_sql()
);
$headline = __('Messages');
$grid = new Grid('messages', null, array
......
->class('delete_link');
}
if (!$hide_grid)
{
$grid->datasource($messages);
}
$grid->datasource($messages);
$view = new View('main');
$view->title = $headline;
......
->options(arr::rbool())
->selected(0);
if (Settings::get('redirection_enabled'))
if (module::e('redirection'))
{
$form->html_textarea('text')
->label('Content of the message')
......
->cols(100);
}
if (Settings::get('email_enabled'))
if (module::e('email'))
{
$form->html_textarea('email_text')
->label(__('Content of the message for E-mail').': '.
......
->cols(100);
}
if (Settings::get('sms_enabled'))
if (module::e('sms'))
{
$form->textarea('sms_text')
->label(__('Content of the message for SMS').': '.
......
$message->self_cancel = htmlspecialchars($form_data['self_cancel']);
$message->ignore_whitelist = htmlspecialchars($form_data['ignore_whitelist']);
if (Settings::get('email_enabled'))
if (module::e('email'))
{
// email text
$email_text = trim($form_data['email_text']);
......
}
// sms text
if (Settings::get('sms_enabled'))
if (module::e('sms'))
{
$sms_text = trim(text::cs_utf2ascii(strip_tags($form_data['sms_text'])));
$sms_text = empty($sms_text) ? NULL : $sms_text;
......
$message->email_text = @$email_text;
$message->sms_text = @$sms_text;
if (Settings::get('sms_enabled'))
if (module::e('sms'))
{
$message->text = Settings::get('redirection_enabled') ? $form_data['text'] : '';
$message->text = module::e('redirection') ? $form_data['text'] : '';
}
$message->save_throwable();
......
->style('width: 600px');
}
if (Message_Model::is_white_list_ignorable($message->type))
if (Message_Model::is_white_list_ignorable($message->type) &&
Message_Model::USER_MESSAGE == $message->type)
{
$form->dropdown('ignore_whitelist')
->label(__('Ignore whitelist').': '.help::hint('ignore_whitelist'))
......
->selected($message->ignore_whitelist);
}
if (Settings::get('redirection_enabled') &&
if (module::e('redirection') &&
Message_Model::has_redirection_content($message->type))
{
$form->html_textarea('text')
......
->value($message->text);
}
if (Settings::get('email_enabled') &&
if (module::e('email') &&
Message_Model::has_email_content($message->type))
{
$form->html_textarea('email_text')
......
->value($message->email_text);
}
if (Settings::get('sms_enabled') &&
if (module::e('sms') &&
Message_Model::has_sms_content($message->type))
{
$form->textarea('sms_text')
......
$message->self_cancel = htmlspecialchars($form_data['self_cancel']);
}
if (Message_Model::is_white_list_ignorable($message->type))
if (Message_Model::is_white_list_ignorable($message->type) &&
Message_Model::USER_MESSAGE == $message->type)
{
$message->ignore_whitelist = htmlspecialchars($form_data['ignore_whitelist']);
}
if (Settings::get('redirection_enabled') &&
if (module::e('redirection') &&
Message_Model::has_redirection_content($message->type))
{
$message->text = $form_data['text'];
}
if (Settings::get('email_enabled') &&
if (module::e('email') &&
Message_Model::has_email_content($message->type))
{
// email text
......
$message->email_text = empty($email_text) ? NULL : $email_text;
}
if (Settings::get('sms_enabled') &&
if (module::e('sms') &&
Message_Model::has_sms_content($message->type))
{
// sms text
......
// preparation
$message = new Message_Model($message_id);
if (!$message || !$message->id)
if (!$message || !$message->id ||
!Message_Model::can_be_activate_directly($message->type))
{
Controller::error(RECORD);
}
if (($message->id == Message_Model::PAYMENT_NOTICE_MESSAGE ||
$message->id == Message_Model::DEBTOR_MESSAGE ||
$message->id == Message_Model::RECEIVED_PAYMENT_NOTICE_MESSAGE) &&
$message->id == Message_Model::DEBTOR_MESSAGE) &&
!Settings::get('finance_enabled'))
{
Controller::error(ACCESS);
......
$this->message_id = $message->id;
// shows beetween page only for interrupt membership, payment notice and debtor
if ($message->type == Message_Model::INTERRUPTED_MEMBERSHIP_MESSAGE ||
$message->type == Message_Model::DEBTOR_MESSAGE ||
$message->type == Message_Model::PAYMENT_NOTICE_MESSAGE)
$member_model = new Member_Model();
// shows beetween page only for interrupt payment notice and debtor
if ($message->type == Message_Model::PAYMENT_NOTICE_MESSAGE ||
$message->type == Message_Model::DEBTOR_MESSAGE)
{
if (!isset($_POST) || !isset($_POST['ids']))
{
$member_model = new Member_Model();
$members = $member_model->get_members_to_messages($message->type);
$grid = new Grid('notifications/cloud', '', array
......
$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::USER_MESSAGE)
{
......
->callback('callback::whitelisted_field')
->class('center');
if (Settings::get('redirection_enabled') &&
if (module::e('redirection') &&
Message_Model::has_redirection_content($message->type))
{
$grid->form_field('redirection')
->label('Redirection')
->type('dropdown')
->options(array
(
Notifications_Controller::ACTIVATE => __('Activate'),
Notifications_Controller::KEEP => __('Without change'),
Notifications_Controller::DEACTIVATE => __('Deactivate')
))
->callback('callback::notification_form_field', $message->type, $message->ignore_whitelist);
->options(notification::redirection_form_array())
->callback(
'callback::notification_form_field',
$message->type, $message->ignore_whitelist
);
}
if (Settings::get('email_enabled') &&
if (module::e('email') &&
Message_Model::has_email_content($message->type))
{
$grid->form_field('email')
->label('E-Mail')
->type('dropdown')
->options(array
(
Notifications_Controller::ACTIVATE => __('Activate'),
Notifications_Controller::KEEP => __('Without change')
))
->callback('callback::notification_form_field', $message->type, $message->ignore_whitelist);
->options(notification::redirection_form_array(TRUE))
->callback(
'callback::notification_form_field',
$message->type, $message->ignore_whitelist
);
}
if (Settings::get('sms_enabled') &&
if (module::e('sms') &&
Message_Model::has_sms_content($message->type))
{
$grid->form_field('sms')
->label('SMS')
->type('dropdown')
->options(array
(
Notifications_Controller::ACTIVATE => __('Activate'),
Notifications_Controller::KEEP => __('Without change')
))
->options(notification::redirection_form_array(TRUE))
->callback(
'callback::notification_form_field',
$message->type,
$message->ignore_whitelist
$message->type, $message->ignore_whitelist
);
}
......
(
"position" => 'top',
form::label(
'comment',
"<b>".__('Comment').":</b>"
'comment', "<b>".__('Comment').":</b>"
) . form::textarea('comment', '', 'style="margin-left: 30px"')."<br /><br />"
);
......
)
);
if ($message->type > 0)
if ($message->type != Message_Model::USER_MESSAGE)
{
$breadcrumbs->text($message->name);
$breadcrumbs->text($message->name);
}
else
{
$breadcrumbs
->disable_translation()
$breadcrumbs->disable_translation()
->text($message->name . ' (' . $message->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 = Settings::get('redirection_enabled') ? $_POST["redirection"] : array();
$emails = (isset($_POST["email"]) && Settings::get('email_enabled')) ? $_POST["email"] : array();
$smss = (isset($_POST["sms"]) && Settings::get('sms_enabled')) ? $_POST["sms"] : array();
$user_id = $this->session->get('user_id');
$added_redr = 0;
$deleted_redr = 0;
$sent_emails = 0;
$sent_sms = 0;
// params
$comment = $_POST['comment'];
$user_id = $this->user_id;
$redirections = $emails = $smss = array();
$info_messages = array();
foreach ($redirections as $member_id => $redirection)
if (isset($_POST['redirection']) && module::e('redirection'))
{
if ($redirection == Notifications_Controller::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 == Notifications_Controller::ACTIVATE)
{
$added_redr += Message_Model::activate_redirection(
$message, $ips,
$user_id, $comment
);
}
$redirections = $_POST['redirection'];
}
if (Settings::get('redirection_enabled'))
if (isset($_POST['email']) && module::e('email'))
{
// 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).'.';
}
$emails = $_POST['email'];
}
foreach ($emails as $member_id => $email)
if (isset($_POST['sms']) && module::e('sms'))
{
if ($email == Notifications_Controller::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
);
$smss = $_POST['sms'];
}
// 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 ($sms == Notifications_Controller::KEEP)
continue;
// gets all contacts of member
$contacts = $uc_model->get_contacts_by_member_and_type(
$member_id, Contact_Model::TYPE_PHONE, TRUE
);
// send SMS
$sent_sms += Message_Model::send_sms_messages(
$message, $contacts,
$user_id, $comment
);
}
// 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"',
array($un, __($message->name)));
status::success(implode('<br />', $info_messages), FALSE);
Log_queue_Model::info($m, implode("\n", $info_messages));
}
// log action
$un = ORM::factory('user', $user_id)->get_full_name();
$m = __('User "%s" has activated notification message "%s"',
array($un, __($message->name)));
Log_queue_Model::info($m, implode("\n", $info_messages));
// redirect
url::redirect('messages/show_all');
}
}
// other messages will be activate right now
// user message will be activate right now
else
{
$dropdown_options = array
......
$form = new Forge(url::base(TRUE) . url::current(TRUE));
if (Settings::get('redirection_enabled'))
if (module::e('redirection'))
{
$form->dropdown('redirection')
->options($dropdown_options)
......
if ($message->type == Message_Model::USER_MESSAGE)
{
if (Settings::get('email_enabled'))
if (module::e('email'))
{
$form->dropdown('email')
->label('E-mail')
......
->callback(array($this, 'valid_email_or_sms'));
}
if (Settings::get('sms_enabled'))
if (module::e('sms'))
{
$form->dropdown('sms')
->label('SMS')
......
if ($form->validate())
{
$form_data = $form->as_array();
$user_id = $this->session->get('user_id');
$ip_count = 0;
$comment = @$form_data['comment'];
$redirection = Settings::get('redirection_enabled') ? $form_data['redirection'] : FALSE;
$redirection = module::e('redirection') &&
($form_data['redirection'] == Notifications_Controller::ACTIVATE);
$email = module::e('email') &&
($form_data['email'] == Notifications_Controller::ACTIVATE);
$sms = module::e('sms') &&
($form_data['sms'] == Notifications_Controller::ACTIVATE);
try
{
// choose which message to update
switch($message->type)
// get members
$members = $member_model->get_members_to_messages(
Message_Model::USER_MESSAGE
);
// notify
$stats = Notifications_Controller::notify(
$message, $members, $user_id, $comment,
$redirection, $email, $sms, $redirection
);
// 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))
{
case Message_Model::USER_MESSAGE:
$counts = $message->activate_user_message(
$message_id,
$user_id,
$redirection,
@$form_data['email'],
@$form_data['sms']
);
$ip_count = $counts['ip_count'];
$email_count = $counts['email_count'];
$sms_count = $counts['sms_count'];
break;
default:
Controller::warning(PARAMETER);
$un = ORM::factory('user', $user_id)->get_full_name();
$m = __('User "%s" has activated notification message "%s"',
array($un, __($message->name)));
status::success(implode('<br />', $info_messages), FALSE);
Log_queue_Model::info($m, implode("\n", $info_messages));
}
$info_messages = array();
if (Settings::get('redirection_enabled'))
{
$m = 'Redirection "%s" for %d IP addresses have been activated.';
$info_messages[] = __($m, array
(
0 => __($message->name),
1 => $ip_count
));
}
if (isset($email_count))
{
$m = 'E-mail "%s" has been sent for %d e-mail addresses.';
$info_messages[] = __($m, array
(
0 => __($message->name),
1 => $email_count
));
}
if (isset($sms_count))
{
$m = 'SMS message "%s" has been sent for %d phone numbers.';
$info_messages[] = __($m, array
(
0 => __($message->name),
1 => $sms_count
));
}
status::success(implode('<br>', $info_messages), FALSE);
// redirect
url::redirect('messages/show_all');
}
catch (Exception $e)
......
}
else
{
$breadcrumbs
->disable_translation()
$breadcrumbs->disable_translation()
->text($message->name . ' (' . $message->id . ')');
}
freenetis/branches/1.1/application/controllers/notifications.php
$form = new Forge('notifications/member/'.$member->id);
$form->dropdown('message_id')
->label(__('Message').':')
->label('Message')
->options($arr_messages)
->rules('required');
$form->textarea('comment');
if (Settings::get('redirection_enabled'))
if (module::e('redirection'))
{
$form->dropdown('redirection')
->options(array
(
self::ACTIVATE => __('Activate'),
self::KEEP => __('Without change'),
self::DEACTIVATE => __('Deactivate')
));
->options(notification::redirection_form_array());
}
if (Settings::get('email_enabled'))
if (module::e('email'))
{
$form->dropdown('email')
->label(__('E-mail').':')
->options(array
(
self::ACTIVATE => __('Activate'),
self::KEEP => __('Without change')
));
->label('E-mail')
->options(notification::redirection_form_array(TRUE));
}
if (Settings::get('sms_enabled'))
if (module::e('sms'))
{
$form->dropdown('sms')
->label(__('SMS message').':')
->options(array
(
self::ACTIVATE => __('Activate'),
self::KEEP => __('Without change')
));
->label('SMS message')
->options(notification::redirection_form_array(TRUE));
}
$form->submit('Send');
......
{
$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();
// check type
if ($message->type != Message_Model::USER_MESSAGE)
self::error(RECORD);
// needed data
$user_id = $this->session->get('user_id');
// params
$comment = $form_data['comment'];
$info_messages = array();
/* Redirection */
if (Settings::get('redirection_enabled') &&
Message_Model::has_redirection_content($message->type) &&
($form_data['redirection'] == self::ACTIVATE ||
$form_data['redirection'] == self::DEACTIVATE))
$user_id = $this->user_id;
$redirection = $email = $sms = array();
if (isset($form_data['redirection']) && module::e('redirection'))
{
// stats vars
$deleted_redr = 0;
$added_redr = 0;
$redirection = $_POST['redirection'];
}
// get all redirection
$ips = $ip_model->get_ip_addresses_of_member($member->id);
if (isset($form_data['email']) && module::e('email'))
{
$email = $form_data['email'];
}
// 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
);
}
// 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 (Settings::get('email_enabled') &&
Message_Model::has_email_content($message->type) &&
$form_data['email'] == self::ACTIVATE)
if (isset($form_data['sms']) && module::e('sms'))
{
// 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).'.';
$sms = $form_data['sms'];
}
/* SMS messages */
if (Settings::get('sms_enabled') &&
Message_Model::has_sms_content($message->type) &&
$form_data['sms'] == self::ACTIVATE)
{
// 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
);
// 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,
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
{
......
$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(
$members = $member_model->get_all_members(
0, $total_members, 'id', 'ASC',
$filter_form->as_sql()
);
);
$grid = new Grid('notifications/subnet', '', array
(
'use_paginator' => false,
'use_selector' => false,
'total_items' => count ($members)
'use_paginator' => false,
'use_selector' => false,
'total_items' => count($members)
));
$grid->callback_field('member_id')
->label(__('Name'))
->label('Name')
->callback('callback::member_field');
$grid->callback_field('type')
......
->callback('callback::balance_field');
$grid->callback_field('interrupt')
->label(__('Membership interrupt'))
->label('Membership interrupt')
->callback('callback::active_field')
->class('center');
$grid->callback_field('whitelisted')
->label(__('Whitelist'))
->label('Whitelist')
->callback('callback::whitelisted_field')
->class('center');
if (Settings::get('redirection_enabled') &&
Message_Model::has_redirection_content($message_id))
if (module::e('redirection') &&
Message_Model::has_redirection_content($message->type))
{
$grid->form_field('redirection')
->label(__('Redirection'))
->type('dropdown')
->options(array
(
self::ACTIVATE => __('Activate'),
self::KEEP => __('Without change'),
self::DEACTIVATE => __('Deactivate')
))
->options(notification::redirection_form_array())
->callback(
'callback::notification_form_field',
$message->type,
$message->ignore_whitelist
$message->type, $message->ignore_whitelist
)->class('center');
}
if (Settings::get('email_enabled') &&
Message_Model::has_email_content($message_id))
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,
......
)->class('center');
}
if (Settings::get('sms_enabled') &&
Message_Model::has_sms_content($message_id))
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
$message->type, $message->ignore_whitelist
)->class('center');
}
......
}
else
{
$ip_address_model = new Ip_address_Model();
$mia_model = new Messages_ip_addresses_Model();
$uc_model = new Users_contacts_Model();
// params
$comment = $_POST['comment'];
$user_id = $this->user_id;
$redirections = $emails = $smss = array();
$comment = $_POST["comment"];
$redirections = Settings::get('redirection_enabled') ? $_POST["redirection"] : 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 (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'];
}
if (Settings::get('redirection_enabled'))
if (isset($_POST['email']) && module::e('email'))
{
// 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).'.';
}
$emails = $_POST['email'];
}
// only if e-mail is enabled
if (Settings::get('email_enabled'))
if (isset($_POST['sms']) && module::e('sms'))
{
foreach ($emails as $member_id => $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
);
}
$smss = $_POST['sms'];
}
// info message
$m = 'E-mail has been sent for %s e-mail addresses';
$info_messages[] = __($m, $sent_emails).'.';
// only if SMS are enabled
if (Settings::get('sms_enabled'))
{
foreach ($smss as $member_id => $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
);
}
// 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');
}
}
}
......
));
$grid->callback_field('member_id')
->label(__('Name'))
->label('Name')
->callback('callback::member_field');
$grid->callback_field('type')
......
->callback('callback::balance_field');
$grid->callback_field('interrupt')
->label(__('Membership interrupt'))
->label('Membership interrupt')
->callback('callback::active_field')
->class('center');
$grid->callback_field('allowed')
->label(__('Allowed subnet'))
->label('Allowed subnet')
->callback('callback::active_field')
->class('center');
$grid->callback_field('whitelisted')
->label(__('Whitelist'))
->label('Whitelist')
->callback('callback::whitelisted_field')
->class('center');
if (Settings::get('redirection_enabled') &&
if (module::e('redirection') &&
Message_Model::has_redirection_content($message->type))
{
$grid->form_field('redirection')
->label(__('Redirection'))
->type('dropdown')
->options(array
(
self::ACTIVATE => __('Activate'),
self::KEEP => __('Without change'),
self::DEACTIVATE => __('Deactivate')
))
->options(notification::redirection_form_array())
->callback(
'callback::notification_form_field',
$message->type,
$message->ignore_whitelist
$message->type, $message->ignore_whitelist
)->class('center');
}
// only if e-mail is enabled
if (Settings::get('email_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
$message->type, $message->ignore_whitelist
)->class('center');
}
if (Settings::get('sms_enabled') &&
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
$message->type, $message->ignore_whitelist
)->class('center');
}
......
}
else
{
$ip_address_model = new Ip_address_Model();
$mia_model = new Messages_ip_addresses_Model();
$uc_model = new Users_contacts_Model();
// params
$comment = $_POST['comment'];
$user_id = $this->user_id;
$redirections = $emails = $smss = array();
$comment = $_POST["comment"];
$redirections = Settings::get('redirection_enabled') ? $_POST["redirection"] : 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 (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, $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
);
}
$redirections = $_POST['redirection'];
}
if (Settings::get('redirection_enabled'))
if (isset($_POST['email']) && module::e('email'))
{
// 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).'.';
}
$emails = $_POST['email'];
}
// only if e-mail is enabled
if (Settings::get('email_enabled'))
if (isset($_POST['sms']) && module::e('sms'))
{
foreach ($emails as $member_id => $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
);
}
$smss = $_POST['sms'];
}
// info message
$m = 'E-mail has been sent for %s e-mail addresses';
$info_messages[] = __($m, $sent_emails).'.';
// only if SMS are enabled
if (Settings::get('sms_enabled'))
{
foreach ($smss as $member_id => $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
);
}
// 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);
}
......
$form = new Forge('notifications/cloud/'.$cloud->id);
$form->dropdown('message_id')
->label(__('Message').':')
->label('Message')
->options($arr_messages)
->rules('required');
......
$grid = new Grid('notifications/cloud', '', array
(
'use_paginator' => false,
'use_selector' => false,
'use_paginator' => FALSE,
'use_selector' => FALSE,
'total_items' => count($members)
));
......
->callback('callback::balance_field');
$grid->callback_field('interrupt')
->label(__('Membership interrupt'))
->callback('callback::active_field')
->class('center');
->label('Membership interrupt')
->callback('callback::active_field')
->class('center');
$grid->callback_field('allowed')
->label('Allowed subnet')
->callback('callback::active_field')
->class('center');
->label('Allowed subnet')
->callback('callback::active_field')
->class('center');
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff