+
+ public function getEnvFieldNames()
+ {
+ return array($this->envfieldindex, $this->envfield);
+ }
+}
+// }}}
+
+// {{{ class UFBF_Quick
+class UFBF_Quick extends UFB_Field
+{
+ protected function check(UserFilterBuilder $ufb)
+ {
+ if ($ufb->blank($this->envfield)) {
+ $this->empty = true;
+ return true;
+ }
+
+ $this->val = str_replace('*', '%', replace_accent($ufb->t($this->envfield)));
+
+ return true;
+ }
+
+ protected function buildUFC(UserFilterBuilder $ufb)
+ {
+
+ $r = $s = $this->val;
+
+ /** Admin: Email, IP
+ */
+ if (S::admin() && strpos($s, '@') !== false) {
+ return new UFC_Email($s);
+ } else if (S::admin() && preg_match('/[0-9]+\.([0-9]+|%)\.([0-9]+|%)\.([0-9]+|%)/', $s)) {
+ return new UFC_Ip($s);
+ }
+
+ $conds = new PFC_And();
+
+ /** Name
+ */
+ $s = preg_replace('!\d+!', ' ', $s);
+ $strings = preg_split("![^a-zA-Z%]+!",$s, -1, PREG_SPLIT_NO_EMPTY);
+ if (count($strings) > 5) {
+ Platal::page()->trigWarning("Tu as indiqué trop d'éléments dans ta recherche, seuls les 5 premiers seront pris en compte");
+ $strings = array_slice($strings, 0, 5);
+ }
+
+ if (count($strings)) {
+ if (S::user() != null && S::user()->checkPerms('directory_private')) {
+ $flags = array();
+ } else {
+ $flags = array('public');
+ }
+ $exact =$ufb->b('exact');
+ $conds->addChild(new UFC_NameTokens($strings, $flags, $ufb->b('with_soundex'), $exact));
+
+ $ufb->addOrder(new UFO_Score());
+ }
+
+ /** Promo ranges
+ */
+ $s = preg_replace('! *- *!', '-', $r);
+ $s = preg_replace('!([<>]) *!', ' \1', $s);
+ $s = preg_replace('![^0-9\-><]!', ' ', $s);
+ $s = preg_replace('![<>\-] !', '', $s);
+ $ranges = preg_split('! +!', $s, -1, PREG_SPLIT_NO_EMPTY);
+ foreach ($ranges as $r) {
+ if (preg_match('!^\d{4}$!', $r)) {
+ $conds->addChild(new UFC_Promo('=', UserFilter::DISPLAY, 'X' . $r));
+ } elseif (preg_match('!^(\d{4})-(\d{4})$!', $r, $matches)) {
+ $p1=min(intval($matches[1]), intval($matches[2]));
+ $p2=max(intval($matches[1]), intval($matches[2]));
+ $conds->addChild(new PFC_And(
+ new UFC_Promo('>=', UserFilter::DISPLAY, 'X' . $p1),
+ new UFC_Promo('<=', UserFilter::DISPLAY, 'X' . $p2)
+ ));
+ } elseif (preg_match('!^<(\d{4})!', $r, $matches)) {
+ $conds->addChild(new UFC_Promo('<=', UserFilter::DISPLAY, 'X' . $matches[1]));
+ } elseif (preg_match('!^>(\d{4})!', $r, $matches)) {
+ $conds->addChild(new UFC_Promo('>=', UserFilter::DISPLAY, 'X' . $matches[1]));
+ }
+ }
+
+ /** Phone number
+ */
+ $t = preg_replace('!(\d{4}-\d{4}|>\d{4}|<\d{4})!', '', $s);
+ $t = preg_replace('![<>\- ]!', '', $t);
+ if (strlen($t) > 4) {
+ $conds->addChild(new UFC_Phone($t));
+ }
+
+ return $conds;
+ }
+}
+// }}}
+
+// {{{ class UFBF_SchoolIds
+class UFBF_SchoolIds extends UFB_Field
+{
+ // One of UFC_SchoolId types
+ protected $type;
+ protected $reversed_envfield;
+ protected $reversed = false;
+
+ public function __construct($envfield, $formtext, $type = UFC_SchoolId::AX, $reversed_envfield = '')
+ {
+ parent::__construct($envfield, $formtext);
+ $this->type = $type;
+ if ($reversed_envfield == '') {
+ $reversed_envfield = $envfield . '_reversed';
+ }
+ $this->reversed_envfield = $reversed_envfield;
+ }
+
+ protected function check(UserFilterBuilder $ufb)
+ {
+ if ($ufb->blank($this->envfield)) {
+ $this->empty = true;
+ return true;
+ }
+
+ $value = $ufb->t($this->envfield);
+ $values = explode("\r\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->reversed = $ufb->b($this->reversed_envfield);
+ $this->val = $ids;
+ return true;
+ }
+
+ protected function buildUFC(UserFilterBuilder $ufb)
+ {
+ $ufc = new UFC_SchoolId($this->type, $this->val);
+ if ($this->reversed) {
+ return new PFC_Not($ufc);
+ } else {
+ return $ufc;
+ }
+ }