From 0f567f55105b18afd0451b5b554768edb86a14ca Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Tue, 28 Dec 2010 17:05:09 +0100 Subject: [PATCH] Adds 'by AX id' advanced search for admins (Closes #1366) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This field is only available for X.org admins and AX secretaries. Signed-off-by: Raphaël Barrois --- include/ufbuilder.inc.php | 54 ++++++++++++++++++++++++++++++++++++++++++- include/userset.inc.php | 6 +++-- modules/search.php | 5 +++- templates/search/adv.form.tpl | 9 ++++++++ 4 files changed, 70 insertions(+), 4 deletions(-) diff --git a/include/ufbuilder.inc.php b/include/ufbuilder.inc.php index 2eacd43..f189ca3 100644 --- a/include/ufbuilder.inc.php +++ b/include/ufbuilder.inc.php @@ -176,7 +176,12 @@ class UFB_QuickSearch extends UserFilterBuilder // {{{ class UFB_AdvancedSearch class UFB_AdvancedSearch extends UserFilterBuilder { - public function __construct($envprefix = '') + /** Create a UFB_AdvancedSearch. + * @param $include_admin Whether to include 'admin-only' fields + * @param $include_ax Whether to include 'ax-only' fields + * @param $envprefix Optional prefix for form field names. + */ + public function __construct($include_admin = false, $include_ax = false, $envprefix = '') { $fields = array( new UFBF_Name('name', 'Nom'), @@ -210,6 +215,11 @@ class UFB_AdvancedSearch extends UserFilterBuilder new UFBF_Mentor('only_referent', 'Référent'), ); + + if ($include_admin || $include_ax) { + $fields[] = new UFBF_SchoolIds('schoolid_ax', 'Matricule AX', UFC_SchoolId::AX); + } + parent::__construct($fields, $envprefix); } } @@ -564,6 +574,48 @@ class UFBF_Quick extends UFB_Field } // }}} +// {{{ class UFBF_SchoolIds +class UFBF_SchoolIds extends UFB_Field +{ + // One of UFC_SchoolId types + protected $type; + + public function __construct($envfield, $formtext, $type = UFC_SchoolId::AX) + { + parent::__construct($envfield, $formtext); + $this->type = $type; + } + + protected function check(UserFilterBuilder &$ufb) + { + if ($ufb->blank($this->envfield)) { + $this->empty = true; + return true; + } + + $value = $ufb->t($this->envfield); + $values = explode("\n", $value); + $ids = array(); + foreach ($values as $val) { + if (preg_match('/^[0-9A-Z]{0,8}$/', $val)) { + $ids[] = $val; + } + } + if (count($ids) == 0) { + return $this->raise("Le champ %s ne contient aucune valeur valide."); + } + + $this->val = $ids; + return true; + } + + protected function buildUFC(UserFilterBuilder &$ufb) + { + return new UFC_SchoolId($this->type, $this->val); + } +} +// }}} + // {{{ class UFBF_Name class UFBF_Name extends UFBF_Text { diff --git a/include/userset.inc.php b/include/userset.inc.php index d2e1823..21ad42d 100644 --- a/include/userset.inc.php +++ b/include/userset.inc.php @@ -115,9 +115,11 @@ class QuickSearchSet extends SearchSet // Specialized SearchSet for advanced search. class AdvancedSearchSet extends SearchSet { - public function __construct(PlFilterCondition $cond = null) + public function __construct($xorg_admin_fields, $ax_admin_fields, + PlFilterCondition $cond = null) { - parent::__construct(new UFB_AdvancedSearch(), $cond); + parent::__construct(new UFB_AdvancedSearch($xorg_admin_fields, $ax_admin_fields), + $cond); } } diff --git a/modules/search.php b/modules/search.php index 21d9870..86ccc55 100644 --- a/modules/search.php +++ b/modules/search.php @@ -169,7 +169,10 @@ class SearchModule extends PLModule } require_once 'userset.inc.php'; - $view = new AdvancedSearchSet(); + // Enable X.org fields for X.org admins, and AX fields for AX secretaries. + $view = new AdvancedSearchSet(S::admin(), + S::user()->checkPerms(User::PERM_EDIT_DIRECTORY)); + if (!$view->isValid()) { $this->form_prepare(); $page->trigError('Recherche invalide.'); diff --git a/templates/search/adv.form.tpl b/templates/search/adv.form.tpl index 167f8d4..b239e4e 100644 --- a/templates/search/adv.form.tpl +++ b/templates/search/adv.form.tpl @@ -487,6 +487,15 @@ function cleanForm(f) { + {if hasPerm('admin,edit_directory')} + + Matricule AX + + +
+ Entrer une liste de matricules AX (un par ligne) + + {/if} {if $smarty.session.auth ge AUTH_COOKIE} -- 2.1.4