improved group handling

This commit is contained in:
SJ 2012-06-27 11:17:23 +02:00
parent a631595e5f
commit ee910e7735
14 changed files with 221 additions and 16 deletions

View File

@ -177,6 +177,9 @@ $themes = array(
);
$letters = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
define('ACTION_ALL', 0);
define('ACTION_UNKNOWN', 1);
define('ACTION_LOGIN', 2);

View File

@ -0,0 +1,16 @@
<?php
class ControllerCommonLayoutemail extends Controller {
protected function index() {
$this->template = "common/layout-email.tpl";
$this->render();
}
}
?>

View File

@ -0,0 +1,26 @@
<?php
class ControllerCommonLayoutMinimal extends Controller {
protected function index() {
$this->data['title'] = $this->document->title;
$this->template = "common/layout-minimal.tpl";
$this->children = array(
"common/menu",
"common/footer"
);
$this->render();
}
}
?>

View File

@ -7,8 +7,8 @@ class ControllerGroupEmail extends Controller {
public function index(){
$this->id = "content";
$this->template = "user/list.tpl";
$this->layout = "common/layout-empty";
$this->template = "group/email.tpl";
$this->layout = "common/layout-email";
$request = Registry::get('request');
@ -17,28 +17,60 @@ class ControllerGroupEmail extends Controller {
$this->load->model('group/group');
$this->data['page'] = 0;
$this->data['page_len'] = get_page_length();
$this->data['total'] = 0;
$this->data['sort'] = 'email';
$this->data['term'] = '';
if(!isset($this->request->get['term']) || strlen($this->request->get['term']) < 2) { die("no data"); }
if(!isset($this->request->get['term']) || strlen($this->request->get['term']) < 1) { die("no data"); }
if(isset($this->request->get['page']) && is_numeric($this->request->get['page']) && $this->request->get['page'] > 0) {
$this->data['page'] = $this->request->get['page'];
}
$this->data['search'] = $this->request->get['term'];
/* check if we are admin */
if(Registry::get('admin_user') == 1) {
$emails = $this->model_group_group->get_emails_by_string($this->request->get['term']);
$i = 0;
$s = '[ ';
// for autocomplete
foreach($emails as $email) {
$i++;
$s .= '{ "id": "' . $i . '", "value": "' . $email['email'] . '" },';
if(strlen($this->request->get['term']) >= 2) {
$emails = $this->model_group_group->get_emails_by_string($this->request->get['term']);
$i = 0;
$s = '[ ';
foreach($emails as $email) {
$i++;
$s .= '{ "id": "' . $i . '", "value": "' . $email['email'] . '" },';
}
$s = preg_replace("/,$/", "", $s) . " ]";
print $s;
}
$s = preg_replace("/,$/", "", $s) . " ]";
// for email list
if(strlen($this->request->get['term']) == 1) {
$this->data['emails'] = $this->model_group_group->get_emails_by_string($this->request->get['term'], $this->data['page'], $this->data['page_len']);
$this->data['total'] = $this->model_group_group->count_emails($this->request->get['term']);
$this->data['prev_page'] = $this->data['page'] - 1;
$this->data['next_page'] = $this->data['page'] + 1;
$this->data['total_pages'] = floor($this->data['total'] / $this->data['page_len']);
$this->render();
}
print $s;
}
}

View File

@ -8,7 +8,7 @@ class ControllerLoginLogout extends Controller {
$this->id = "content";
$this->template = "login/logout.tpl";
$this->layout = "common/layout";
$this->layout = "common/layout-minimal";
$request = Registry::get('request');

View File

@ -63,6 +63,7 @@ if(MEMCACHED_ENABLED) {
Registry::set('counters', $counters);
Registry::set('langs', $langs);
Registry::set('themes', $themes);
Registry::set('letters', $letters);
Registry::set('health_smtp_servers', $health_smtp_servers);
Registry::set('partitions_to_monitor', $partitions_to_monitor);

View File

@ -140,10 +140,12 @@ class ModelGroupGroup extends Model {
}
public function get_emails_by_string($s = '') {
if(strlen($s) < 2) { return array(); }
public function get_emails_by_string($s = '', $page = 0, $page_len = PAGE_LEN) {
$from = (int)$page * (int)$page_len;
$query = $this->db->query("SELECT email FROM `" . TABLE_EMAIL . "` WHERE email LIKE ? ORDER BY email ASC", array($s . "%") );
if(strlen($s) < 1) { return array(); }
$query = $this->db->query("SELECT email FROM `" . TABLE_EMAIL . "` WHERE email LIKE ? ORDER BY email ASC LIMIT " . (int)$from . ", " . (int)$page_len, array($s . "%") );
if(isset($query->rows)) { return $query->rows; }
@ -151,6 +153,15 @@ class ModelGroupGroup extends Model {
}
public function count_emails($s = '') {
if(strlen($s) < 1) { return 0; }
$query = $this->db->query("SELECT COUNT(*) AS num FROM `" . TABLE_EMAIL . "` WHERE email LIKE ?", array($s . "%") );
return $query->row['num'];
}
public function get_groups_by_string($s = '') {
if(strlen($s) < 2) { return array(); }

View File

@ -380,6 +380,7 @@ class ModelUserUser extends Model {
private function update_group_settings($uid = -1, $group = '') {
$__g = array();
if($uid <= 0 || $group == '') { return 0; }
@ -398,7 +399,10 @@ class ModelUserUser extends Model {
foreach($group as $g) {
$g = rtrim($g);
$query = $this->db->query("INSERT INTO `" . TABLE_GROUP_USER . "` (id, uid) VALUES(?,?)", array($groups[$g], (int)$uid));
if(!isset($__g[$groups[$g]])) {
$query = $this->db->query("INSERT INTO `" . TABLE_GROUP_USER . "` (id, uid) VALUES(?,?)", array($groups[$g], (int)$uid));
$__g[$groups[$g]] = 1;
}
}
return 1;

View File

@ -511,6 +511,16 @@ function toggle_bulk_check() {
}
function append_email_from_slider(id, value) {
var prefix = '\n';
a = opener.document.getElementById('email');
if(a && a.value == '') prefix = '';
a.value += prefix + value;
}
$(document).ready(function() {
$.datepicker.setDefaults($.datepicker.regional[piler_ui_lang]);
$("#date1").datepicker( { dateFormat: 'yy-mm-dd' } );

View File

@ -0,0 +1,29 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="hu" lang="hu">
<head>
<title>piler | <?php print $title; ?></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="en" />
<meta name="keywords" content="piler email archiver" />
<meta name="description" content="piler email archiver" />
<meta name="rating" content="general" />
<meta name="robots" content="all" />
<link rel="stylesheet" type="text/css" href="/view/theme/default/stylesheet/style-<?php print THEME; ?>.css" />
<script type="text/javascript" src="/view/javascript/piler.js"></script>
</head>
<body style="background-color: white;">
<div id="wrap" style="width:200px; height: 300px; border: 0px;">
<?php if($title) { ?><h3><?php print $title; ?></h3><?php } ?>
<?php print $content; ?>
</div> <!-- wrap -->
</body>
</html>

View File

@ -0,0 +1,47 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="hu" lang="hu">
<head>
<title>piler | <?php print $title; ?></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="en" />
<meta name="keywords" content="piler email archiver" />
<meta name="description" content="piler email archiver" />
<meta name="rating" content="general" />
<meta name="robots" content="all" />
<link rel="stylesheet" type="text/css" href="/view/theme/default/stylesheet/style-<?php print THEME; ?>.css" />
<script type="text/javascript">
var piler_ui_lang = '<?php if(LANG == 'en') { ?>en-GB<?php } else { print LANG; } ?>';
</script>
</head>
<body>
<div id="wrap">
<div id="menu">
<?php print $menu; ?>
</div> <!-- menu -->
<div id="main">
<?php if($title) { ?><h3><?php print $title; ?></h3><?php } ?>
<?php print $content; ?>
</div> <!-- main -->
<div id="footer">
<?php print $footer; ?>
</div>
</div> <!-- wrap -->
</body>
</html>

View File

@ -19,6 +19,11 @@
<div class="domainrow">
<div class="domaincell"><?php print $text_email_addresses; ?>**:</div>
<div class="domaincell"><textarea style="height:280px;" name="email" id="email" class="domain"><?php if(isset($post['email'])){ print $post['email']; } ?></textarea></div>
<div class="domaincell">
<?php foreach(Registry::get('letters') as $letter) { ?>
<a href="#" onclick="window.open('<?php print SITE_URL; ?>index.php?route=group/email&term=<?php print $letter; ?>', 'aaa', 'width=300,height=400');" ><?php print $letter; ?></a>
<?php } ?>
</div>
</div>
<div class="domainrow">

View File

@ -21,6 +21,11 @@
<div class="domainrow">
<div class="domaincell"><?php print $text_email_addresses; ?>**:</div>
<div class="domaincell"><textarea style="height:280px;" name="email" id="email" class="domain"><?php if(isset($email)){ print $email; } ?></textarea></div>
<div class="domaincell">
<?php foreach(Registry::get('letters') as $letter) { ?>
<a href="#" onclick="window.open('<?php print SITE_URL; ?>index.php?route=group/email&term=<?php print $letter; ?>', 'aaa', 'width=300,height=400');" ><?php print $letter; ?></a>
<?php } ?>
</div>
</div>
<div class="domainrow">

View File

@ -0,0 +1,16 @@
<?php foreach($emails as $email) { ?>
<a href="#" onclick="javascript:append_email_from_slider('email', '<?php print $email['email']; ?>');"><?php print $email['email']; ?></a><br />
<?php } ?>
<div id="pagenav">
<?php if($page > 0){ ?><a href="index.php?route=group/email&amp;page=0&amp;term=<?php print $search; ?>&amp;sort=<?php print $sort; ?>&amp;order=<?php print $order; ?>" class="navlink"><?php } ?> &laquo; <?php if($page > 0){ ?></a><?php } ?>
<?php if($page > 0){ ?><a href="index.php?route=group/email&amp;page=<?php print $prev_page; ?>&amp;term=<?php print $search; ?>&amp;sort=<?php print $sort; ?>&amp;order=<?php print $order; ?>" class="navlink"><?php } ?> &lsaquo; <?php if($page > 0){ ?></a><?php } ?>
<?php print $emails[0][$sort]; ?> - <?php print $emails[count($emails)-1][$sort]; ?>
<?php if($total >= $page_len*($page+1) && $total > $page_len){ ?><a href="index.php?route=group/email&amp;page=<?php print $next_page; ?>&amp;term=<?php print $search; ?>&amp;sort=<?php print $sort; ?>&amp;order=<?php print $order; ?>" class="navlink"><?php } ?> &rsaquo; <?php if($total >= $page_len*($page+1) && $total > $page_len){ ?></a><?php } ?>
<?php if($page < $total_pages){ ?><a href="index.php?route=group/email&amp;page=<?php print $total_pages; ?>&amp;term=<?php print $search; ?>&amp;sort=<?php print $sort; ?>&amp;order=<?php print $order; ?>" class="navlink"><?php } ?> &raquo; <?php if($page < $total_pages){ ?></a><?php } ?>
</div>
<div style="margin-top: 20px;"><a href="#" onclick="javascript: window.close();">close</a></div>