Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1318

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

Dalsi vylepseni mezistranky a filtru.

Zobrazit rozdíly:

freenetis/branches/testing/application/helpers/html.php
*/
public static function specialchars($str, $double_encode = TRUE)
{
if (is_array($str))
return array_map ("html::specialchars", $str);
// Do encode existing HTML entities (default)
if ($double_encode == TRUE)
{
freenetis/branches/testing/application/helpers/form.php
return html::attributes($sorted);
}
/**
* Creates hidden input names and values from input array
*
* @author Michal Kliment
* @param type $array
* @param type $input
* @param type $prefix
*/
public static function create_hiddens (&$array, $input, $prefix)
{
foreach ($input as $key => $val)
{
$name = $prefix !='' ? $prefix."[".$key."]" : $key;
if (!is_array($val))
{
$array[] = array
(
'name' => $name,
'value' => $val
);
}
else
self::create_hiddens ($array, $val, $name);
}
}
} // End form
freenetis/branches/testing/application/models/member.php
", __('Yes'), __('No'), User_Model::MAIN_USER, Config::get('lang'));
}
public function get_members($order_by = 'id', $order_by_direction = 'asc')
/**
* Returns all members
*
* @author Michal Kliment
* @param string $order_by
* @param string $order_by_direction
* @return MySQL Result
*/
public function get_members_to_messages($type)
{
switch ($type)
{
case Message_Model::INTERRUPTED_MEMBERSHIP_MESSAGE:
$where = "WHERE mf.id IS NOT NULL";
$order_by = 'whitelisted ASC, interrupt DESC';
break;
case Message_Model::DEBTOR_MESSAGE:
$where = "WHERE a.balance < ".intval(Settings::get('debtor_boundary'));
$order_by = "whitelisted ASC, balance ASC";
break;
case Message_Model::PAYMENT_NOTICE_MESSAGE:
$where = "WHERE a.balance >= ".intval(Settings::get('debtor_boundary'))
." AND a.balance < ".intval(Settings::get('payment_notice_boundary'));
$order_by = "whitelisted ASC, balance ASC";
break;
default:
$where = "";
$order_by = 'm.id';
break;
}
return $this->db->query("
SELECT
m.*, m.id AS member_id, m.name AS member_name,
......
SELECT *
FROM
(
SELECT IFNULL(ip.whitelisted,0) AS whitelisted, IFNULL(ip.member_id,u.member_id) AS member_id
SELECT
IFNULL(ip.whitelisted,0) AS whitelisted,
IFNULL(ip.member_id,u.member_id) AS member_id
FROM
(
SELECT ip.*, IFNULL(i1.device_id,i2.device_id) AS device_id
......
) w
GROUP BY member_id
) w ON w.member_id = m.id
LEFT JOIN
(
SELECT ip.member_id, COUNT(*) AS unallowed_count
FROM
(
SELECT *
FROM
(
SELECT ip.subnet_id,
IFNULL(ip.member_id, u.member_id) AS member_id
FROM
(
SELECT ip.*,
IFNULL(i1.device_id,i2.device_id) AS device_id
FROM ip_addresses ip
LEFT JOIN ifaces i1 ON ip.iface_id = i1.id
LEFT JOIN vlan_ifaces vi ON ip.vlan_iface_id = vi.id
LEFT JOIN ifaces i2 ON vi.iface_id = i2.id
) ip
LEFT JOIN devices d ON ip.device_id = d.id
LEFT JOIN users u ON d.user_id = u.id
) ip
GROUP BY ip.member_id, ip.subnet_id
) ip
LEFT JOIN allowed_subnets als ON ip.subnet_id = als.subnet_id
AND ip.member_id = als.member_id
WHERE ip.member_id <> ? AND IFNULL(als.enabled, 0) = 0
GROUP BY ip.member_id
) un ON un.member_id = m.id
$where
GROUP BY m.id
ORDER BY $order_by
", Account_attribute_Model::CREDIT);
", array(Account_attribute_Model::CREDIT, Member_Model::ASSOCIATION));
}
/**
freenetis/branches/testing/application/controllers/notifications.php
->options($arr_messages)
->rules('required');
foreach ($input as $key => $value)
$hiddens = array();
form::create_hiddens($hiddens, $input, '');
foreach ($hiddens as $hidden)
{
$name = $key;
if (is_array($value))
{
foreach ($value as $key => $value)
{
$form->hidden($name."[".$key."]")
->value($value);
}
}
$form->hidden($hidden['name'])
->value($hidden['value']);
}
$form->submit('Next step');
......
$order_by_direction = 'ASC';
break;
}
$member_model = new Member_Model();
$filter_form = new Filter_form('m');
......
if ($redirection == self::ACTIVATE)
{
$added_redr += Message_Model::activate_redirection(
$message, $ips,
$message, $ips, TRUE,
$user_id, $comment
);
}
freenetis/branches/testing/application/controllers/messages.php
$this->message_id = $message->id;
if (!isset($_POST) || !isset($_POST["ids"]))
// 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)
{
switch ($message->type)
if (!isset($_POST) || !isset($_POST["ids"]))
{
case Message_Model::DEBTOR_MESSAGE:
case Message_Model::PAYMENT_NOTICE_MESSAGE:
$order_by = 'whitelisted DESC, balance ASC';
break;
switch ($message->type)
{
case Message_Model::UNALLOWED_CONNECTING_PLACE_MESSAGE:
$order_by = 'whitelisted DESC, allowed ASC';
break;
case Message_Model::INTERRUPTED_MEMBERSHIP_MESSAGE:
$order_by = 'whitelisted DESC, interrupt DESC';
break;
default:
$order_by = 'whitelisted DESC, id ASC';
break;
}
case Message_Model::UNALLOWED_CONNECTING_PLACE_MESSAGE:
$order_by = 'whitelisted DESC, allowed ASC';
break;
$member_model = new Member_Model();
default:
$order_by = 'whitelisted DESC, id ASC';
break;
$members = $member_model->get_members_to_messages($message->type);
$grid = new Grid(url_lang::base().'notifications/cloud', '', array
(
'use_paginator' => false,
'use_selector' => false,
'total_items' => count ($members)
));
$grid->callback_field('member_id')
->label(__('Name'))
->callback('callback::member_field');
$grid->callback_field('type')
->callback('callback::member_type_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'))
->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('whitelisted')
->label(__('Whitelist'))
->callback('callback::whitelisted_field')
->class('center');
$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);
if ($message->type == Message_Model::DEBTOR_MESSAGE ||
$message->type == Message_Model::PAYMENT_NOTICE_MESSAGE ||
$message->type == Message_Model::USER_MESSAGE)
{
$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);
$grid->form_field('sms')
->label(__('SMS'))
->type('dropdown')
->options(array
(
Notifications_Controller::ACTIVATE => __('Activate'),
Notifications_Controller::KEEP => __('Without change')
))
->callback(
'callback::notification_form_field',
$message->type,
$message->ignore_whitelist
);
}
$grid->form_extra_buttons = array
(
"position" => 'top',
form::label(
'comment',
"<b>".__('Comment').":</b>"
) . form::textarea('comment', '', 'style="margin-left: 30px"')."<br /><br />"
);
$grid->datasource($members);
$headline = __('Activate message for all members');
if ($message->type > 0)
{
$breadcrumbs = breadcrumbs::add()
->link('messages/show_all', 'Messages',
$this->acl_check_view(
'Redirection_Controller', 'redirection'
)
)
->text($message->name)
->text($headline);
}
else
{
$breadcrumbs = breadcrumbs::add()
->link('messages/show_all', 'Messages',
$this->acl_check_view(
'Redirection_Controller', 'redirection'
)
)
->disable_translation()
->text($message->name . ' (' . $message->id . ')')
->text($headline);
}
$view = new View('main');
$view->breadcrumbs = $breadcrumbs->html();
$view->title = $headline;
$view->content = new View('show_all');
$view->content->headline = $headline;
$view->content->table = $grid;
$view->render(TRUE);
}
else
{
$ip_address_model = new Ip_address_Model();
$mia_model = new Messages_ip_addresses_Model();
$uc_model = new Users_contacts_Model();
$member_model = new Member_Model();
$comment = $_POST["comment"];
$redirections = $_POST["redirection"];
$members = $member_model->get_members($order_by);
$emails = (isset($_POST["email"])) ? $_POST["email"] : array();
$smss = (isset($_POST["sms"])) ? $_POST["sms"] : array();
$grid = new Grid(url_lang::base().'notifications/cloud', '', 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 == 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
);
}
}
// 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 ($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
);
}
// 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 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
if (count($info_messages))
{
status::success(implode('<br />', $info_messages), FALSE);
}
// redirect
url::redirect('messages/show_all');
}
}
// other messages will be activate right now
else
{
$dropdown_options = array
(
'use_paginator' => false,
'use_selector' => false,
'total_items' => count ($members)
));
Notifications_Controller::ACTIVATE => __('Activate'),
Notifications_Controller::KEEP => __('Without change')
);
$form = new Forge(url::base(TRUE) . url::current(TRUE));
$form->dropdown('redirection')
->label(__('Redirection').':')
->options($dropdown_options)
->selected(Notifications_Controller::KEEP);
$grid->callback_field('member_id')
->label(__('Name'))
->callback('callback::member_field');
if ($message->type == Message_Model::USER_MESSAGE)
{
$form->dropdown('email')
->label(__('E-mail').':')
->options($dropdown_options)
->selected(Notifications_Controller::KEEP)
->callback(array($this, 'valid_email_or_sms'));
$grid->callback_field('type')
->callback('callback::member_type_field');
$form->dropdown('sms')
->label(__('SMS').':')
->options($dropdown_options)
->selected(Notifications_Controller::KEEP)
->callback(array($this, 'valid_email_or_sms'));
}
$grid->callback_field('balance')
->callback('callback::balance_field');
$form->submit('Send');
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)
if ($form->validate())
{
$grid->callback_field('interrupt')
->label(__('Membership interrupt'))
->callback('callback::active_field')
->class('center');
}
$grid->callback_field('whitelisted')
->label(__('Whitelist'))
->callback('callback::whitelisted_field')
->class('center');
$form_data = $form->as_array();
$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);
$user_id = $this->session->get('user_id');
$ip_count = 0;
if ($message->type == Message_Model::DEBTOR_MESSAGE ||
$message->type == Message_Model::PAYMENT_NOTICE_MESSAGE ||
$message->type == Message_Model::USER_MESSAGE)
{
$grid->form_field('email')
->label(__('E-Mail'))
->type('dropdown')
->options(array
try
{
// choose which message to update
switch($message->type)
{
case Message_Model::UNALLOWED_CONNECTING_PLACE_MESSAGE:
if ($form_data['redirection'] == Notifications_Controller::ACTIVATE)
{
$ip_count = $message->activate_unallowed_connecting_place_message($user_id);
}
break;
case Message_Model::USER_MESSAGE:
$counts = $message->activate_user_message(
$message_id,
$user_id,
$form_data['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);
}
$m = 'Redirection "%s" for %d IP addresses have been activated.';
$info_message = __($m, array
(
Notifications_Controller::ACTIVATE => __('Activate'),
Notifications_Controller::KEEP => __('Without change')
))
->callback('callback::notification_form_field', $message->type, $message->ignore_whitelist);
0 => __($message->name),
1 => $ip_count
));
$grid->form_field('sms')
->label(__('SMS'))
->type('dropdown')
->options(array
(
Notifications_Controller::ACTIVATE => __('Activate'),
Notifications_Controller::KEEP => __('Without change')
))
->callback(
'callback::notification_form_field',
$message->type,
$message->ignore_whitelist
);
if (isset($email_count))
{
$m = 'E-mail "%s" has been sent for %d e-mail addresses.';
$info_message .= '<br />'.__($m, array
(
0 => __($message->name),
1 => $email_count
));
}
if (isset($sms_count))
{
$m = 'SMS message "%s" has been sent for %d phone numbers.';
$info_message .= '<br />'.__($m, array
(
0 => __($message->name),
1 => $sms_count
));
}
status::success($info_message, FALSE);
url::redirect('messages/show_all');
}
catch (Exception $e)
{
$em = __('Error - cant set redirection.') . '<br>' . $e->getMessage();
status::error($em, FALSE);
url::redirect('messages/show_all');
}
}
$grid->form_extra_buttons = array
(
"position" => 'top',
form::label(
'comment',
"<b>".__('Comment').":</b>"
) . form::textarea('comment', '', 'style="margin-left: 30px"')."<br /><br />"
);
$grid->datasource($members);
$headline = __('Activate message for all members');
if ($message->type > 0)
......
$view = new View('main');
$view->breadcrumbs = $breadcrumbs->html();
$view->title = $headline;
$view->content = new View('show_all');
$view->content = new View('form');
$view->content->headline = $headline;
$view->content->table = $grid;
$view->content->form = $form;
$view->render(TRUE);
}
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();
foreach ($redirections as $member_id => $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
);
}
}
// 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 ($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
);
}
// 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 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
if (count($info_messages))
{
status::success(implode('<br />', $info_messages), FALSE);
}
// redirect
url::redirect('messages/show_all');
}
}
/**
freenetis/branches/testing/application/libraries/Filter_form.php
$values = Input::instance()->get('values');
$tables = Input::instance()->get('tables');
$default = Input::instance()->get('default');
$this->keys = Input::instance()->get('keys');
$this->vals = Input::instance()->get('vals');
if (count($values))
{
......
* @return int
*/
public function autoload()
{
{
$loaded = 0;
foreach ($this->types as $i => $type)
{
$loaded++;
$filter = new Filter($type, $this->tables[$i]);
if (isset($this->keys[$filter->name]))
{
$this->values[$i] = $this->keys[$filter->name][array_search($this->values[$i], $this->vals[$filter->name])];
}
$this->filters[$type] = $filter;
}
......
$withouts = array();
$tables = array();
$classes = array();
$keys = array();
foreach ($this->filters as $filter)
{
if ($this->returns[$filter->type] == 'key')
{
foreach ($filter->values as $key => $value)
{
$keys[$filter->name][] = array
(
'value' => $value,
'key' => $key
);
}
}
$types[$filter->name] = $filter->label;
foreach ($this->operation_types[$filter->type] as $operation_type)
......
$this->template->withouts = $withouts;
$this->template->tables = $tables;
$this->template->classes = $classes;
$this->template->keys = $keys;
$this->template->default = $this->default;
$this->template->default_count = $this->default_count;
freenetis/branches/testing/application/views/filter_form_template.php
<img src='<?php echo url::base() ?>media/images/icons/delete.png' class='delete_button' title="<?php echo __('Delete this filter') ?>">
</div>
<?php foreach ($keys as $name => $keys): ?>
<?php foreach ($keys as $key => $val): ?>
<?php echo form::hidden("keys[$name][]", $val['key']) ?>
<?php echo form::hidden("vals[$name][]", $val['value']) ?>
<?php endforeach ?>
<?php endforeach ?>
<?php echo form::button(array('type' => 'submit', 'class' => 'submit', 'value' => __('Filter'))) ?>
<?php echo form::close() ?>

Také k dispozici: Unified diff