lib/client lib/kolab_client_task.php
Aleksander Machniak
machniak at kolabsys.com
Fri Aug 9 12:30:37 CEST 2013
lib/client/kolab_client_task_domain.php | 166 +----------------
lib/client/kolab_client_task_group.php | 161 -----------------
lib/client/kolab_client_task_resource.php | 163 -----------------
lib/client/kolab_client_task_role.php | 160 -----------------
lib/client/kolab_client_task_sharedfolder.php | 163 -----------------
lib/client/kolab_client_task_user.php | 159 -----------------
lib/kolab_client_task.php | 242 +++++++++++++++++++++++++-
7 files changed, 263 insertions(+), 951 deletions(-)
New commits:
commit fbb7f37f8506e5e9c991ad9e9d05bafb71f800b1
Author: Aleksander Machniak <alec at alec.pl>
Date: Fri Aug 9 12:29:51 2013 +0200
Generalized list/search handling. Fixed searching users by email/name (Bug #2057)
diff --git a/lib/client/kolab_client_task_domain.php b/lib/client/kolab_client_task_domain.php
index e50ba3c..dce73f9 100644
--- a/lib/client/kolab_client_task_domain.php
+++ b/lib/client/kolab_client_task_domain.php
@@ -30,6 +30,12 @@ class kolab_client_task_domain extends kolab_client_task
'add' => 'domain.add',
);
+ protected $search_attribs = array(
+ 'name' => array('associateddomain'),
+ );
+
+ protected $list_attribs = array('associateddomain');
+
/**
* Default action.
*/
@@ -63,130 +69,7 @@ class kolab_client_task_domain extends kolab_client_task
}
}
- $page_size = 20;
- $page = (int) self::get_input('page', 'POST');
- if (!$page || $page < 1) {
- $page = 1;
- }
-
- // request parameters
- $post = array(
- 'attributes' => array('associateddomain'),
-// 'sort_order' => 'ASC',
- 'sort_by' => 'associateddomain',
- 'page_size' => $page_size,
- 'page' => $page,
- );
-
- // search parameters
- if (!empty($_POST['search'])) {
- $search = self::get_input('search', 'POST', true);
- $field = self::get_input('field', 'POST');
- $method = self::get_input('method', 'POST');
-
- $search_request = array(
- $field => array(
- 'value' => $search,
- 'type' => $method,
- ),
- );
- }
- else if (!empty($_POST['search_request'])) {
- $search_request = self::get_input('search_request', 'POST');
- $search_request = @unserialize(base64_decode($search_request));
- }
-
- if (!empty($search_request)) {
- $post['search'] = $search_request;
- $post['search_operator'] = 'OR';
- }
-
- // get domains list
- $result = $this->api_post('domains.list', null, $post);
- $count = (int) $result->get('count');
- $result = (array) $result->get('list');
-
- // calculate records
- if ($count) {
- $start = 1 + max(0, $page - 1) * $page_size;
- $end = min($start + $page_size - 1, $count);
- }
-
- $rows = $head = $foot = array();
- $cols = array('name');
- $i = 0;
-
- // table header
- $head[0]['cells'][] = array('class' => 'name', 'body' => $this->translate('domain.list'));
-
- // table footer (navigation)
- if ($count) {
- $pages = ceil($count / $page_size);
- $prev = max(0, $page - 1);
- $next = $page < $pages ? $page + 1 : 0;
-
- $count_str = kolab_html::span(array(
- 'content' => $this->translate('list.records', $start, $end, $count)), true);
- $prev = kolab_html::a(array(
- 'class' => 'prev' . ($prev ? '' : ' disabled'),
- 'href' => '#',
- 'onclick' => $prev ? "kadm.command('domain.list', {page: $prev})" : "return false",
- ));
- $next = kolab_html::a(array(
- 'class' => 'next' . ($next ? '' : ' disabled'),
- 'href' => '#',
- 'onclick' => $next ? "kadm.command('domain.list', {page: $next})" : "return false",
- ));
-
- $foot_body = kolab_html::span(array('content' => $prev . $count_str . $next));
- }
- $foot[0]['cells'][] = array('class' => 'listnav', 'body' => $foot_body);
-
- // table body
- if (!empty($result)) {
- foreach ($result as $idx => $item) {
- //console($idx);
- if (!is_array($item) || empty($item['associateddomain'])) {
- continue;
- }
-
- $i++;
- $cells = array();
-
- if (is_array($item['associateddomain'])) {
- $domain_name = $item['associateddomain'][0];
- } else {
- $domain_name = $item['associateddomain'];
- }
-
- $cells[] = array('class' => 'name', 'body' => kolab_html::escape($domain_name),
- 'onclick' => "kadm.command('domain.info', '$idx')");
- $rows[] = array('id' => $i, 'class' => 'selectable', 'cells' => $cells);
- }
- }
- else {
- $rows[] = array('cells' => array(
- 0 => array('class' => 'empty-body', 'body' => $this->translate('domain.norecords')
- )));
- }
-
- $table = kolab_html::table(array(
- 'id' => 'domainlist',
- 'class' => 'list',
- 'head' => $head,
- 'body' => $rows,
- 'foot' => $foot,
- ));
-
- if ($this->action == 'list') {
- $this->output->command('set_watermark', 'taskcontent');
- }
-
- $this->output->set_env('search_request', $search_request ? base64_encode(serialize($search_request)) : null);
- $this->output->set_env('list_page', $page);
- $this->output->set_env('list_count', $count);
- $this->output->set_env('list_size', $i);
- $this->output->set_object('domainlist', $table);
+ parent::action_list();
}
/**
@@ -305,37 +188,14 @@ class kolab_client_task_domain extends kolab_client_task
}
/**
- * Users search form.
- *
- * @return string HTML output of the form
+ * List item handler
*/
- public function search_form()
+ protected function list_item_handler($item)
{
- $form = new kolab_form(array('id' => 'search-form'));
-
- $form->add_section('criteria', kolab_html::escape($this->translate('search.criteria')));
- $form->add_element(array(
- 'section' => 'criteria',
- 'label' => $this->translate('search.field'),
- 'name' => 'field',
- 'type' => kolab_form::INPUT_SELECT,
- 'options' => array(
- 'associateddomain' => kolab_html::escape($this->translate('search.name')),
- ),
- ));
- $form->add_element(array(
- 'section' => 'criteria',
- 'label' => $this->translate('search.method'),
- 'name' => 'method',
- 'type' => kolab_form::INPUT_SELECT,
- 'options' => array(
- 'both' => kolab_html::escape($this->translate('search.contains')),
- 'exact' => kolab_html::escape($this->translate('search.is')),
- 'prefix' => kolab_html::escape($this->translate('search.prefix')),
- ),
- ));
+ if (is_array($item['associateddomain'])) {
+ return $item['associateddomain'][0];
+ }
- return $form->output();
+ return $item['associateddomain'];
}
-
}
diff --git a/lib/client/kolab_client_task_group.php b/lib/client/kolab_client_task_group.php
index 2367efa..b442a4c 100644
--- a/lib/client/kolab_client_task_group.php
+++ b/lib/client/kolab_client_task_group.php
@@ -30,6 +30,8 @@ class kolab_client_task_group extends kolab_client_task
'add' => 'group.add',
);
+ protected $list_attribs = array('cn');
+
/**
* Default action.
*/
@@ -51,129 +53,6 @@ class kolab_client_task_group extends kolab_client_task
}
/**
- * Groups list action.
- */
- public function action_list()
- {
- $page_size = 20;
- $page = (int) self::get_input('page', 'POST');
- if (!$page || $page < 1) {
- $page = 1;
- }
-
- // request parameters
- $post = array(
- 'attributes' => array('cn'),
-// 'sort_order' => 'ASC',
- 'sort_by' => 'cn',
- 'page_size' => $page_size,
- 'page' => $page,
- );
-
- // search parameters
- if (!empty($_POST['search'])) {
- $search = self::get_input('search', 'POST', true);
- $field = self::get_input('field', 'POST');
- $method = self::get_input('method', 'POST');
-
- $search_request = array(
- $field => array(
- 'value' => $search,
- 'type' => $method,
- ),
- );
- }
- else if (!empty($_POST['search_request'])) {
- $search_request = self::get_input('search_request', 'POST');
- $search_request = @unserialize(base64_decode($search_request));
- }
-
- if (!empty($search_request)) {
- $post['search'] = $search_request;
- $post['search_operator'] = 'OR';
- }
-
- // get groups list
- $result = $this->api_post('groups.list', null, $post);
- $count = (int) $result->get('count');
- $result = (array) $result->get('list');
-
- // calculate records
- if ($count) {
- $start = 1 + max(0, $page - 1) * $page_size;
- $end = min($start + $page_size - 1, $count);
- }
-
- $rows = $head = $foot = array();
- $cols = array('name');
- $i = 0;
-
- // table header
- $head[0]['cells'][] = array('class' => 'name', 'body' => $this->translate('group.list'));
-
- // table footer (navigation)
- if ($count) {
- $pages = ceil($count / $page_size);
- $prev = max(0, $page - 1);
- $next = $page < $pages ? $page + 1 : 0;
-
- $count_str = kolab_html::span(array(
- 'content' => $this->translate('list.records', $start, $end, $count)), true);
- $prev = kolab_html::a(array(
- 'class' => 'prev' . ($prev ? '' : ' disabled'),
- 'href' => '#',
- 'onclick' => $prev ? "kadm.command('group.list', {page: $prev})" : "return false",
- ));
- $next = kolab_html::a(array(
- 'class' => 'next' . ($next ? '' : ' disabled'),
- 'href' => '#',
- 'onclick' => $next ? "kadm.command('group.list', {page: $next})" : "return false",
- ));
-
- $foot_body = kolab_html::span(array('content' => $prev . $count_str . $next));
- }
- $foot[0]['cells'][] = array('class' => 'listnav', 'body' => $foot_body);
-
- // table body
- if (!empty($result)) {
- foreach ($result as $idx => $item) {
- if (!is_array($item) || empty($item['cn'])) {
- continue;
- }
-
- $i++;
- $cells = array();
- $cells[] = array('class' => 'name', 'body' => kolab_html::escape($item['cn']),
- 'onclick' => "kadm.command('group.info', '$idx')");
- $rows[] = array('id' => $i, 'class' => 'selectable', 'cells' => $cells);
- }
- }
- else {
- $rows[] = array('cells' => array(
- 0 => array('class' => 'empty-body', 'body' => $this->translate('group.norecords')
- )));
- }
-
- $table = kolab_html::table(array(
- 'id' => 'grouplist',
- 'class' => 'list',
- 'head' => $head,
- 'body' => $rows,
- 'foot' => $foot,
- ));
-
- if ($this->action == 'list') {
- $this->output->command('set_watermark', 'taskcontent');
- }
-
- $this->output->set_env('search_request', $search_request ? base64_encode(serialize($search_request)) : null);
- $this->output->set_env('list_page', $page);
- $this->output->set_env('list_count', $count);
- $this->output->set_env('list_size', count($result));
- $this->output->set_object('grouplist', $table);
- }
-
- /**
* Group information (form) action.
*/
public function action_info()
@@ -291,40 +170,4 @@ class kolab_client_task_group extends kolab_client_task
return $list;
}
-
- /**
- * Users search form.
- *
- * @return string HTML output of the form
- */
- public function search_form()
- {
- $form = new kolab_form(array('id' => 'search-form'));
-
- $form->add_section('criteria', kolab_html::escape($this->translate('search.criteria')));
- $form->add_element(array(
- 'section' => 'criteria',
- 'label' => $this->translate('search.field'),
- 'name' => 'field',
- 'type' => kolab_form::INPUT_SELECT,
- 'options' => array(
- 'cn' => kolab_html::escape($this->translate('search.name')),
- 'mail' => kolab_html::escape($this->translate('search.email')),
- ),
- ));
- $form->add_element(array(
- 'section' => 'criteria',
- 'label' => $this->translate('search.method'),
- 'name' => 'method',
- 'type' => kolab_form::INPUT_SELECT,
- 'options' => array(
- 'both' => kolab_html::escape($this->translate('search.contains')),
- 'exact' => kolab_html::escape($this->translate('search.is')),
- 'prefix' => kolab_html::escape($this->translate('search.prefix')),
- ),
- ));
-
- return $form->output();
- }
-
}
diff --git a/lib/client/kolab_client_task_resource.php b/lib/client/kolab_client_task_resource.php
index 94be4c1..cfea9bd 100644
--- a/lib/client/kolab_client_task_resource.php
+++ b/lib/client/kolab_client_task_resource.php
@@ -30,6 +30,8 @@ class kolab_client_task_resource extends kolab_client_task
'add' => 'resource.add',
);
+ protected $list_attribs = array('cn');
+
/**
* Default action.
*/
@@ -51,131 +53,6 @@ class kolab_client_task_resource extends kolab_client_task
}
/**
- * Users list action.
- */
- public function action_list()
- {
- $page_size = 20;
- $page = (int) self::get_input('page', 'POST');
- if (!$page || $page < 1) {
- $page = 1;
- }
-
- // request parameters
- $post = array(
- 'attributes' => array('cn'),
-// 'sort_order' => 'ASC',
- 'sort_by' => array('cn'),
- 'page_size' => $page_size,
- 'page' => $page,
- );
-
- // search parameters
- if (!empty($_POST['search'])) {
- $search = self::get_input('search', 'POST', true);
- $field = self::get_input('field', 'POST');
- $method = self::get_input('method', 'POST');
-
- $search_request = array(
- $field => array(
- 'value' => $search,
- 'type' => $method,
- ),
- );
- }
- else if (!empty($_POST['search_request'])) {
- $search_request = self::get_input('search_request', 'POST');
- $search_request = @unserialize(base64_decode($search_request));
- }
-
- if (!empty($search_request)) {
- $post['search'] = $search_request;
- $post['search_operator'] = 'OR';
- }
-
- // get resources list
- $result = $this->api_post('resources.list', null, $post);
- $count = $result->get('count');
- $result = (array) $result->get('list');
-
- //console($result);
-
- // calculate records
- if ($count) {
- $start = 1 + max(0, $page - 1) * $page_size;
- $end = min($start + $page_size - 1, $count);
- }
-
- $rows = $head = $foot = array();
- $cols = array('name');
- $i = 0;
-
- // table header
- $head[0]['cells'][] = array('class' => 'name', 'body' => $this->translate('resource.list'));
-
- // table footer (navigation)
- if ($count) {
- $pages = ceil($count / $page_size);
- $prev = max(0, $page - 1);
- $next = $page < $pages ? $page + 1 : 0;
-
- $count_str = kolab_html::span(array(
- 'content' => $this->translate('list.records', $start, $end, $count)), true);
- $prev = kolab_html::a(array(
- 'class' => 'prev' . ($prev ? '' : ' disabled'),
- 'href' => '#',
- 'onclick' => $prev ? "kadm.command('resource.list', {page: $prev})" : "return false",
- ));
- $next = kolab_html::a(array(
- 'class' => 'next' . ($next ? '' : ' disabled'),
- 'href' => '#',
- 'onclick' => $next ? "kadm.command('resource.list', {page: $next})" : "return false",
- ));
-
- $foot_body = kolab_html::span(array('content' => $prev . $count_str . $next));
- }
- $foot[0]['cells'][] = array('class' => 'listnav', 'body' => $foot_body);
-
- // table body
- if (!empty($result)) {
- foreach ($result as $idx => $item) {
- if (!is_array($item) || empty($item['cn'])) {
- continue;
- }
-
- $i++;
- $cells = array();
- $cells[] = array('class' => 'name', 'body' => kolab_html::escape($item['cn']),
- 'onclick' => "kadm.command('resource.info', '$idx')");
- $rows[] = array('id' => $i, 'class' => 'selectable', 'cells' => $cells);
- }
- }
- else {
- $rows[] = array('cells' => array(
- 0 => array('class' => 'empty-body', 'body' => $this->translate('resource.norecords')
- )));
- }
-
- $table = kolab_html::table(array(
- 'id' => 'resourcelist',
- 'class' => 'list',
- 'head' => $head,
- 'body' => $rows,
- 'foot' => $foot,
- ));
-
- if ($this->action == 'list') {
- $this->output->command('set_watermark', 'taskcontent');
- }
-
- $this->output->set_env('search_request', $search_request ? base64_encode(serialize($search_request)) : null);
- $this->output->set_env('list_page', $page);
- $this->output->set_env('list_count', $count);
- $this->output->set_env('list_size', count($result));
- $this->output->set_object('resourcelist', $table);
- }
-
- /**
* Resource adding (form) action.
*/
public function action_add()
@@ -299,40 +176,4 @@ class kolab_client_task_resource extends kolab_client_task
return $form->output();
}
-
- /**
- * Users search form.
- *
- * @return string HTML output of the form
- */
- public function search_form()
- {
- $form = new kolab_form(array('id' => 'search-form'));
-
- $form->add_section('criteria', kolab_html::escape($this->translate('search.criteria')));
- $form->add_element(array(
- 'section' => 'criteria',
- 'label' => $this->translate('search.field'),
- 'name' => 'field',
- 'type' => kolab_form::INPUT_SELECT,
- 'options' => array(
- 'cn' => kolab_html::escape($this->translate('search.name')),
- 'email' => kolab_html::escape($this->translate('search.email')),
- 'uid' => kolab_html::escape($this->translate('search.uid')),
- ),
- ));
- $form->add_element(array(
- 'section' => 'criteria',
- 'label' => $this->translate('search.method'),
- 'name' => 'method',
- 'type' => kolab_form::INPUT_SELECT,
- 'options' => array(
- 'both' => kolab_html::escape($this->translate('search.contains')),
- 'exact' => kolab_html::escape($this->translate('search.is')),
- 'prefix' => kolab_html::escape($this->translate('search.prefix')),
- ),
- ));
-
- return $form->output();
- }
}
diff --git a/lib/client/kolab_client_task_role.php b/lib/client/kolab_client_task_role.php
index 46772a8..7ff4256 100644
--- a/lib/client/kolab_client_task_role.php
+++ b/lib/client/kolab_client_task_role.php
@@ -30,6 +30,8 @@ class kolab_client_task_role extends kolab_client_task
'add' => 'role.add',
);
+ protected $list_attribs = array('cn');
+
/**
* Default action.
*/
@@ -51,129 +53,6 @@ class kolab_client_task_role extends kolab_client_task
}
/**
- * Roles list action.
- */
- public function action_list()
- {
- $page_size = 20;
- $page = (int) self::get_input('page', 'POST');
- if (!$page || $page < 1) {
- $page = 1;
- }
-
- // request parameters
- $post = array(
- 'attributes' => array('cn'),
-// 'sort_order' => 'ASC',
- 'sort_by' => 'cn',
- 'page_size' => $page_size,
- 'page' => $page,
- );
-
- // search parameters
- if (!empty($_POST['search'])) {
- $search = self::get_input('search', 'POST', true);
- $field = self::get_input('field', 'POST');
- $method = self::get_input('method', 'POST');
-
- $search_request = array(
- $field => array(
- 'value' => $search,
- 'type' => $method,
- ),
- );
- }
- else if (!empty($_POST['search_request'])) {
- $search_request = self::get_input('search_request', 'POST');
- $search_request = @unserialize(base64_decode($search_request));
- }
-
- if (!empty($search_request)) {
- $post['search'] = $search_request;
- $post['search_operator'] = 'OR';
- }
-
- // get roles list
- $result = $this->api_post('roles.list', null, $post);
- $count = (int) $result->get('count');
- $result = (array) $result->get('list');
-
- // calculate records
- if ($count) {
- $start = 1 + max(0, $page - 1) * $page_size;
- $end = min($start + $page_size - 1, $count);
- }
-
- $rows = $head = $foot = array();
- $cols = array('name');
- $i = 0;
-
- // table header
- $head[0]['cells'][] = array('class' => 'name', 'body' => $this->translate('role.list'));
-
- // table footer (navigation)
- if ($count) {
- $pages = ceil($count / $page_size);
- $prev = max(0, $page - 1);
- $next = $page < $pages ? $page + 1 : 0;
-
- $count_str = kolab_html::span(array(
- 'content' => $this->translate('list.records', $start, $end, $count)), true);
- $prev = kolab_html::a(array(
- 'class' => 'prev' . ($prev ? '' : ' disabled'),
- 'href' => '#',
- 'onclick' => $prev ? "kadm.command('role.list', {page: $prev})" : "return false",
- ));
- $next = kolab_html::a(array(
- 'class' => 'next' . ($next ? '' : ' disabled'),
- 'href' => '#',
- 'onclick' => $next ? "kadm.command('role.list', {page: $next})" : "return false",
- ));
-
- $foot_body = kolab_html::span(array('content' => $prev . $count_str . $next));
- }
- $foot[0]['cells'][] = array('class' => 'listnav', 'body' => $foot_body);
-
- // table body
- if (!empty($result)) {
- foreach ($result as $idx => $item) {
- if (!is_array($item) || empty($item['cn'])) {
- continue;
- }
-
- $i++;
- $cells = array();
- $cells[] = array('class' => 'name', 'body' => kolab_html::escape($item['cn']),
- 'onclick' => "kadm.command('role.info', '$idx')");
- $rows[] = array('id' => $i, 'class' => 'selectable', 'cells' => $cells);
- }
- }
- else {
- $rows[] = array('cells' => array(
- 0 => array('class' => 'empty-body', 'body' => $this->translate('role.norecords')
- )));
- }
-
- $table = kolab_html::table(array(
- 'id' => 'rolelist',
- 'class' => 'list',
- 'head' => $head,
- 'body' => $rows,
- 'foot' => $foot,
- ));
-
- if ($this->action == 'list') {
- $this->output->command('set_watermark', 'taskcontent');
- }
-
- $this->output->set_env('search_request', $search_request ? base64_encode(serialize($search_request)) : null);
- $this->output->set_env('list_page', $page);
- $this->output->set_env('list_count', $count);
- $this->output->set_env('list_size', count($result));
- $this->output->set_object('rolelist', $table);
- }
-
- /**
* Role information (form) action.
*/
public function action_info()
@@ -292,39 +171,4 @@ class kolab_client_task_role extends kolab_client_task
return $list;
}
- /**
- * Users search form.
- *
- * @return string HTML output of the form
- */
- public function search_form()
- {
- $form = new kolab_form(array('id' => 'search-form'));
-
- $form->add_section('criteria', kolab_html::escape($this->translate('search.criteria')));
- $form->add_element(array(
- 'section' => 'criteria',
- 'label' => $this->translate('search.field'),
- 'name' => 'field',
- 'type' => kolab_form::INPUT_SELECT,
- 'options' => array(
- 'cn' => kolab_html::escape($this->translate('search.name')),
- 'mail' => kolab_html::escape($this->translate('search.email')),
- ),
- ));
- $form->add_element(array(
- 'section' => 'criteria',
- 'label' => $this->translate('search.method'),
- 'name' => 'method',
- 'type' => kolab_form::INPUT_SELECT,
- 'options' => array(
- 'both' => kolab_html::escape($this->translate('search.contains')),
- 'exact' => kolab_html::escape($this->translate('search.is')),
- 'prefix' => kolab_html::escape($this->translate('search.prefix')),
- ),
- ));
-
- return $form->output();
- }
-
}
diff --git a/lib/client/kolab_client_task_sharedfolder.php b/lib/client/kolab_client_task_sharedfolder.php
index b277410..441e11a 100644
--- a/lib/client/kolab_client_task_sharedfolder.php
+++ b/lib/client/kolab_client_task_sharedfolder.php
@@ -30,6 +30,8 @@ class kolab_client_task_sharedfolder extends kolab_client_task
'add' => 'sharedfolder.add',
);
+ protected $list_attribs = array('cn');
+
/**
* Default action.
*/
@@ -51,131 +53,6 @@ class kolab_client_task_sharedfolder extends kolab_client_task
}
/**
- * Users list action.
- */
- public function action_list()
- {
- $page_size = 20;
- $page = (int) self::get_input('page', 'POST');
- if (!$page || $page < 1) {
- $page = 1;
- }
-
- // request parameters
- $post = array(
- 'attributes' => array('cn'),
-// 'sort_order' => 'ASC',
- 'sort_by' => array('cn'),
- 'page_size' => $page_size,
- 'page' => $page,
- );
-
- // search parameters
- if (!empty($_POST['search'])) {
- $search = self::get_input('search', 'POST', true);
- $field = self::get_input('field', 'POST');
- $method = self::get_input('method', 'POST');
-
- $search_request = array(
- $field => array(
- 'value' => $search,
- 'type' => $method,
- ),
- );
- }
- else if (!empty($_POST['search_request'])) {
- $search_request = self::get_input('search_request', 'POST');
- $search_request = @unserialize(base64_decode($search_request));
- }
-
- if (!empty($search_request)) {
- $post['search'] = $search_request;
- $post['search_operator'] = 'OR';
- }
-
- // get shared folders list
- $result = $this->api_post('sharedfolders.list', null, $post);
- $count = $result->get('count');
- $result = (array) $result->get('list');
-
- //console($result);
-
- // calculate records
- if ($count) {
- $start = 1 + max(0, $page - 1) * $page_size;
- $end = min($start + $page_size - 1, $count);
- }
-
- $rows = $head = $foot = array();
- $cols = array('name');
- $i = 0;
-
- // table header
- $head[0]['cells'][] = array('class' => 'name', 'body' => $this->translate('sharedfolder.list'));
-
- // table footer (navigation)
- if ($count) {
- $pages = ceil($count / $page_size);
- $prev = max(0, $page - 1);
- $next = $page < $pages ? $page + 1 : 0;
-
- $count_str = kolab_html::span(array(
- 'content' => $this->translate('list.records', $start, $end, $count)), true);
- $prev = kolab_html::a(array(
- 'class' => 'prev' . ($prev ? '' : ' disabled'),
- 'href' => '#',
- 'onclick' => $prev ? "kadm.command('sharedfolder.list', {page: $prev})" : "return false",
- ));
- $next = kolab_html::a(array(
- 'class' => 'next' . ($next ? '' : ' disabled'),
- 'href' => '#',
- 'onclick' => $next ? "kadm.command('sharedfolder.list', {page: $next})" : "return false",
- ));
-
- $foot_body = kolab_html::span(array('content' => $prev . $count_str . $next));
- }
- $foot[0]['cells'][] = array('class' => 'listnav', 'body' => $foot_body);
-
- // table body
- if (!empty($result)) {
- foreach ($result as $idx => $item) {
- if (!is_array($item) || empty($item['cn'])) {
- continue;
- }
-
- $i++;
- $cells = array();
- $cells[] = array('class' => 'name', 'body' => kolab_html::escape($item['cn']),
- 'onclick' => "kadm.command('sharedfolder.info', '$idx')");
- $rows[] = array('id' => $i, 'class' => 'selectable', 'cells' => $cells);
- }
- }
- else {
- $rows[] = array('cells' => array(
- 0 => array('class' => 'empty-body', 'body' => $this->translate('sharedfolder.norecords')
- )));
- }
-
- $table = kolab_html::table(array(
- 'id' => 'sharedfolderlist',
- 'class' => 'list',
- 'head' => $head,
- 'body' => $rows,
- 'foot' => $foot,
- ));
-
- if ($this->action == 'list') {
- $this->output->command('set_watermark', 'taskcontent');
- }
-
- $this->output->set_env('search_request', $search_request ? base64_encode(serialize($search_request)) : null);
- $this->output->set_env('list_page', $page);
- $this->output->set_env('list_count', $count);
- $this->output->set_env('list_size', count($result));
- $this->output->set_object('sharedfolderlist', $table);
- }
-
- /**
* Resource adding (form) action.
*/
public function action_add()
@@ -299,40 +176,4 @@ class kolab_client_task_sharedfolder extends kolab_client_task
return $form->output();
}
-
- /**
- * Users search form.
- *
- * @return string HTML output of the form
- */
- public function search_form()
- {
- $form = new kolab_form(array('id' => 'search-form'));
-
- $form->add_section('criteria', kolab_html::escape($this->translate('search.criteria')));
- $form->add_element(array(
- 'section' => 'criteria',
- 'label' => $this->translate('search.field'),
- 'name' => 'field',
- 'type' => kolab_form::INPUT_SELECT,
- 'options' => array(
- 'cn' => kolab_html::escape($this->translate('search.name')),
- 'email' => kolab_html::escape($this->translate('search.email')),
- 'uid' => kolab_html::escape($this->translate('search.uid')),
- ),
- ));
- $form->add_element(array(
- 'section' => 'criteria',
- 'label' => $this->translate('search.method'),
- 'name' => 'method',
- 'type' => kolab_form::INPUT_SELECT,
- 'options' => array(
- 'both' => kolab_html::escape($this->translate('search.contains')),
- 'exact' => kolab_html::escape($this->translate('search.is')),
- 'prefix' => kolab_html::escape($this->translate('search.prefix')),
- ),
- ));
-
- return $form->output();
- }
}
diff --git a/lib/client/kolab_client_task_user.php b/lib/client/kolab_client_task_user.php
index d9a2227..40c2fcc 100644
--- a/lib/client/kolab_client_task_user.php
+++ b/lib/client/kolab_client_task_user.php
@@ -30,6 +30,8 @@ class kolab_client_task_user extends kolab_client_task
'add' => 'user.add',
);
+ protected $list_attribs = array('displayname', 'cn');
+
/**
* Default action.
*/
@@ -51,129 +53,6 @@ class kolab_client_task_user extends kolab_client_task
}
/**
- * Users list action.
- */
- public function action_list()
- {
- $page_size = 20;
- $page = (int) self::get_input('page', 'POST');
- if (!$page || $page < 1) {
- $page = 1;
- }
-
- // request parameters
- $post = array(
- 'attributes' => array('displayname', 'cn'),
-// 'sort_order' => 'ASC',
- 'sort_by' => array('displayname', 'cn'),
- 'page_size' => $page_size,
- 'page' => $page,
- );
-
- // search parameters
- if (!empty($_POST['search'])) {
- $search = self::get_input('search', 'POST', true);
- $field = self::get_input('field', 'POST');
- $method = self::get_input('method', 'POST');
-
- $search_request = array(
- $field => array(
- 'value' => $search,
- 'type' => $method,
- ),
- );
- }
- else if (!empty($_POST['search_request'])) {
- $search_request = self::get_input('search_request', 'POST');
- $search_request = @unserialize(base64_decode($search_request));
- }
-
- if (!empty($search_request)) {
- $post['search'] = $search_request;
- $post['search_operator'] = 'OR';
- }
-
- // get users list
- $result = $this->api_post('users.list', null, $post);
- $count = $result->get('count');
- $result = (array) $result->get('list');
-
- // calculate records
- if ($count) {
- $start = 1 + max(0, $page - 1) * $page_size;
- $end = min($start + $page_size - 1, $count);
- }
-
- $rows = $head = $foot = array();
- $cols = array('name');
- $i = 0;
-
- // table header
- $head[0]['cells'][] = array('class' => 'name', 'body' => $this->translate('user.list'));
-
- // table footer (navigation)
- if ($count) {
- $pages = ceil($count / $page_size);
- $prev = max(0, $page - 1);
- $next = $page < $pages ? $page + 1 : 0;
-
- $count_str = kolab_html::span(array(
- 'content' => $this->translate('list.records', $start, $end, $count)), true);
- $prev = kolab_html::a(array(
- 'class' => 'prev' . ($prev ? '' : ' disabled'),
- 'href' => '#',
- 'onclick' => $prev ? "kadm.command('user.list', {page: $prev})" : "return false",
- ));
- $next = kolab_html::a(array(
- 'class' => 'next' . ($next ? '' : ' disabled'),
- 'href' => '#',
- 'onclick' => $next ? "kadm.command('user.list', {page: $next})" : "return false",
- ));
-
- $foot_body = kolab_html::span(array('content' => $prev . $count_str . $next));
- }
- $foot[0]['cells'][] = array('class' => 'listnav', 'body' => $foot_body);
-
- // table body
- if (!empty($result)) {
- foreach ($result as $idx => $item) {
- if (!is_array($item) || (empty($item['displayname']) && empty($item['cn']))) {
- continue;
- }
-
- $i++;
- $cells = array();
- $cells[] = array('class' => 'name', 'body' => kolab_html::escape(empty($item['displayname']) ? $item['cn'] : $item['displayname']),
- 'onclick' => "kadm.command('user.info', '$idx')");
- $rows[] = array('id' => $i, 'class' => 'selectable', 'cells' => $cells);
- }
- }
- else {
- $rows[] = array('cells' => array(
- 0 => array('class' => 'empty-body', 'body' => $this->translate('user.norecords')
- )));
- }
-
- $table = kolab_html::table(array(
- 'id' => 'userlist',
- 'class' => 'list',
- 'head' => $head,
- 'body' => $rows,
- 'foot' => $foot,
- ));
-
- if ($this->action == 'list') {
- $this->output->command('set_watermark', 'taskcontent');
- }
-
- $this->output->set_env('search_request', $search_request ? base64_encode(serialize($search_request)) : null);
- $this->output->set_env('list_page', $page);
- $this->output->set_env('list_count', $count);
- $this->output->set_env('list_size', count($result));
- $this->output->set_object('userlist', $table);
- }
-
- /**
* User information (form) action.
*/
public function action_info()
@@ -369,39 +248,11 @@ class kolab_client_task_user extends kolab_client_task
}
/**
- * Users search form.
- *
- * @return string HTML output of the form
+ * List item handler
*/
- public function search_form()
+ protected function list_item_handler($item)
{
- $form = new kolab_form(array('id' => 'search-form'));
-
- $form->add_section('criteria', kolab_html::escape($this->translate('search.criteria')));
- $form->add_element(array(
- 'section' => 'criteria',
- 'label' => $this->translate('search.field'),
- 'name' => 'field',
- 'type' => kolab_form::INPUT_SELECT,
- 'options' => array(
- 'displayname' => kolab_html::escape($this->translate('search.name')),
- 'email' => kolab_html::escape($this->translate('search.email')),
- 'uid' => kolab_html::escape($this->translate('search.uid')),
- ),
- ));
- $form->add_element(array(
- 'section' => 'criteria',
- 'label' => $this->translate('search.method'),
- 'name' => 'method',
- 'type' => kolab_form::INPUT_SELECT,
- 'options' => array(
- 'both' => kolab_html::escape($this->translate('search.contains')),
- 'exact' => kolab_html::escape($this->translate('search.is')),
- 'prefix' => kolab_html::escape($this->translate('search.prefix')),
- ),
- ));
-
- return $form->output();
+ return empty($item['displayname']) ? $item['cn'] : $item['displayname'];
}
}
diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php
index 3f50b9d..3936dac 100644
--- a/lib/kolab_client_task.php
+++ b/lib/kolab_client_task.php
@@ -41,12 +41,21 @@ class kolab_client_task
*/
protected $config;
- protected $ajax_only = false;
- protected $page_title = 'Kolab Web Admin Panel';
- protected $menu = array();
- protected $cache = array();
- protected $devel_mode = false;
+ protected $ajax_only = false;
+ protected $page_title = 'Kolab Web Admin Panel';
+ protected $menu = array();
+ protected $cache = array();
+ protected $devel_mode = false;
protected $object_types = array('user', 'group', 'role', 'resource', 'sharedfolder', 'domain');
+ protected $page_size = 20;
+ protected $list_attribs = array();
+ protected $list_module;
+
+ protected $search_attribs = array(
+ 'name' => array('cn', 'displayname'),
+ 'email' => array('mail', 'alias', 'mailalternateaddress'),
+ 'uid' => array('uid'),
+ );
protected static $translation = array();
@@ -1345,4 +1354,227 @@ class kolab_client_task
return $form;
}
+ /**
+ * Search form.
+ *
+ * @return string HTML output of the form
+ */
+ public function search_form()
+ {
+ $attribs = $this->get_search_attribs();
+
+ if (empty($attribs)) {
+ return '';
+ }
+
+ $options = array();
+ foreach (array_keys($attribs) as $key) {
+ $options[$key] = kolab_html::escape($this->translate('search.' . $key));
+ }
+
+ $form = new kolab_form(array('id' => 'search-form'));
+
+ $form->add_section('criteria', kolab_html::escape($this->translate('search.criteria')));
+ $form->add_element(array(
+ 'section' => 'criteria',
+ 'label' => $this->translate('search.field'),
+ 'name' => 'field',
+ 'type' => kolab_form::INPUT_SELECT,
+ 'options' => $options,
+ ));
+ $form->add_element(array(
+ 'section' => 'criteria',
+ 'label' => $this->translate('search.method'),
+ 'name' => 'method',
+ 'type' => kolab_form::INPUT_SELECT,
+ 'options' => array(
+ 'both' => kolab_html::escape($this->translate('search.contains')),
+ 'exact' => kolab_html::escape($this->translate('search.is')),
+ 'prefix' => kolab_html::escape($this->translate('search.prefix')),
+ ),
+ ));
+
+ return $form->output();
+ }
+
+ /**
+ * Returns list of attributes assigned to search field(s)
+ *
+ * @param string $name Optional search field name
+ *
+ * @return array List of attributes
+ */
+ protected function get_search_attribs($name = null)
+ {
+ $task = $this->get_task();
+ $types = $this->object_types($task);
+ $attribs = array();
+
+ foreach ($this->search_attribs as $key => $value) {
+ foreach ((array)$value as $idx => $attr) {
+ $found = false;
+ foreach ($types as $type) {
+ if (array_key_exists($attr, (array)$type['attributes']['auto_form_fields'])
+ || array_key_exists($attr, (array)$type['attributes']['form_fields'])
+ || array_key_exists($attr, (array)$type['attributes']['fields'])
+ ) {
+ $found = true;
+ break;
+ }
+ }
+
+ if (!$found) {
+ unset($value[$idx]);
+ }
+ }
+
+ if (!empty($value)) {
+ $attribs[$key] = $value;
+ }
+ }
+
+ return $name ? $attribs[$name] : $attribs;
+ }
+
+ /**
+ * Object list (and search handler)
+ */
+ public function action_list()
+ {
+ if (empty($this->list_attribs)) {
+ return;
+ }
+
+ $task = $this->get_task();
+ $page = (int) self::get_input('page', 'POST');
+
+ if (!$page || $page < 1) {
+ $page = 1;
+ }
+
+ // request parameters
+ $post = array(
+ 'attributes' => $this->list_attribs,
+ 'sort_by' => $this->list_attribs,
+// 'sort_order' => 'ASC',
+ 'page_size' => $this->page_size,
+ 'page' => $page,
+ );
+
+ // search parameters
+ if (!empty($_POST['search'])) {
+ $search = self::get_input('search', 'POST', true);
+ $field = self::get_input('field', 'POST');
+ $method = self::get_input('method', 'POST');
+ $attrs = $this->get_search_attribs($field);
+ $search_request = array();
+
+ foreach ($attrs as $attr) {
+ $search_request[$attr] = array(
+ 'value' => $search,
+ 'type' => $method,
+ );
+ }
+ }
+ else if (!empty($_POST['search_request'])) {
+ $search_request = self::get_input('search_request', 'POST');
+ $search_request = @unserialize(base64_decode($search_request));
+ }
+
+ if (!empty($search_request)) {
+ $post['search'] = $search_request;
+ $post['search_operator'] = 'OR';
+ }
+
+ // get users list
+ $module = $this->list_module ? $this->list_module : $task . 's';
+ $result = $this->api_post($module . '.list', null, $post);
+ $count = $result->get('count');
+ $result = (array) $result->get('list');
+
+ // calculate records
+ if ($count) {
+ $start = 1 + max(0, $page - 1) * $page_size;
+ $end = min($start + $page_size - 1, $count);
+ }
+
+ $rows = $head = $foot = array();
+ $cols = array('name');
+ $i = 0;
+
+ // table header
+ $head[0]['cells'][] = array('class' => 'name', 'body' => $this->translate($task . '.list'));
+
+ // table footer (navigation)
+ if ($count) {
+ $pages = ceil($count / $this->page_size);
+ $prev = max(0, $page - 1);
+ $next = $page < $pages ? $page + 1 : 0;
+
+ $count_str = kolab_html::span(array(
+ 'content' => $this->translate('list.records', $start, $end, $count)), true);
+ $prev = kolab_html::a(array(
+ 'class' => 'prev' . ($prev ? '' : ' disabled'),
+ 'href' => '#',
+ 'onclick' => $prev ? "kadm.command('$task.list', {page: $prev})" : "return false",
+ ));
+ $next = kolab_html::a(array(
+ 'class' => 'next' . ($next ? '' : ' disabled'),
+ 'href' => '#',
+ 'onclick' => $next ? "kadm.command('$task.list', {page: $next})" : "return false",
+ ));
+
+ $foot_body = kolab_html::span(array('content' => $prev . $count_str . $next));
+ }
+ $foot[0]['cells'][] = array('class' => 'listnav', 'body' => $foot_body);
+
+ // table body
+ if (!empty($result)) {
+ foreach ($result as $idx => $item) {
+ if (!is_array($item)) {
+ continue;
+ }
+
+ if (method_exists($this, 'list_item_handler')) {
+ $item = $this->list_item_handler($item);
+ }
+ else {
+ $item = array_shift($item);
+ }
+
+ if (empty($item)) {
+ continue;
+ }
+
+ $i++;
+ $cells = array();
+ $cells[] = array('class' => 'name', 'body' => kolab_html::escape($item),
+ 'onclick' => "kadm.command('$task.info', '$idx')");
+ $rows[] = array('id' => $i, 'class' => 'selectable', 'cells' => $cells);
+ }
+ }
+ else {
+ $rows[] = array('cells' => array(
+ 0 => array('class' => 'empty-body', 'body' => $this->translate($task . '.norecords')
+ )));
+ }
+
+ $table = kolab_html::table(array(
+ 'id' => $task . 'list',
+ 'class' => 'list',
+ 'head' => $head,
+ 'body' => $rows,
+ 'foot' => $foot,
+ ));
+
+ if ($this->action == 'list') {
+ $this->output->command('set_watermark', 'taskcontent');
+ }
+
+ $this->output->set_env('search_request', $search_request ? base64_encode(serialize($search_request)) : null);
+ $this->output->set_env('list_page', $page);
+ $this->output->set_env('list_count', $count);
+ $this->output->set_env('list_size', count($result));
+ $this->output->set_object($task . 'list', $table);
+ }
}
More information about the commits
mailing list