diff --git a/htdocs/adherents/list.php b/htdocs/adherents/list.php index aea09f73124..1cc09394023 100644 --- a/htdocs/adherents/list.php +++ b/htdocs/adherents/list.php @@ -61,31 +61,22 @@ $pagenext = $page + 1; if (! $sortorder) { $sortorder=($filter=='outofdate'?"DESC":"ASC"); } if (! $sortfield) { $sortfield=($filter=='outofdate'?"d.datefin":"d.lastname"); } -if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers -{ - $search=""; - $search_ref=""; - $search_lastname=""; - $search_firstname=""; - $search_login=""; - $type=""; - $search_email=""; - $search_categ=""; - $catid=""; - $sall=""; -} - // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('memberlist')); $extrafields = new ExtraFields($db); +// fetch optionals attributes and labels +$extralabels = $extrafields->fetch_name_optionals_label('member'); +$search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_'); + // List of fields to search into when doing a "search in all" $fieldstosearchall = array( 'd.rowid'=>'Ref', //'d.ref'=>'Ref', 'd.lastname'=>'Lastname', 'd.firstname'=>'Firstname', - 'd.societe'=>"Company", + 'd.login'=>'Login', + 'd.societe'=>"Company", 'd.email'=>'EMail', 'd.address'=>'Address', 'd.zip'=>'Zip', @@ -93,7 +84,67 @@ $fieldstosearchall = array( 'd.note_public'=>'NotePublic', 'd.note_private'=>'NotePrivate', ); - +$arrayfields=array( + 'd.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1), + 'd.lastname'=>array('label'=>$langs->trans("Lastname"), 'checked'=>1), + 'd.firstname'=>array('label'=>$langs->trans("Firstname"), 'checked'=>1), + 'd.societe'=>array('label'=>$langs->trans("Company"), 'checked'=>1), + 'd.login'=>array('label'=>$langs->trans("Login"), 'checked'=>1), + 'd.morphy'=>array('label'=>$langs->trans("MorPhy"), 'checked'=>1), + 't.libelle'=>array('label'=>$langs->trans("Type"), 'checked'=>1), + 'd.email'=>array('label'=>$langs->trans("Email"), 'checked'=>1), + 'd.address'=>array('label'=>$langs->trans("Address"), 'checked'=>0), + 'd.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>0), + 'd.town'=>array('label'=>$langs->trans("Town"), 'checked'=>0), + 'd.note_public'=>array('label'=>$langs->trans("NotePublic"), 'checked'=>0), + 'd.note_private'=>array('label'=>$langs->trans("NotePrivate"), 'checked'=>0), + 'd.datefin'=>array('label'=>$langs->trans("EndSubscription"), 'checked'=>1, 'position'=>500), + 'd.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500), + 'd.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500), + 'd.statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000) +); +// Extra fields +if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) +{ + foreach($extrafields->attribute_label as $key => $val) + { + $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>$extrafields->attribute_list[$key], 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]); + } +} + +/* + * Actions + */ + +if (GETPOST('cancel')) { $action='list'; $massaction=''; } +if (! GETPOST('confirmmassaction')) { $massaction=''; } + +$parameters=array('socid'=>$socid); +$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + +include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; + +// Purge search criteria +if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers +{ + $search=""; + $search_ref=""; + $search_lastname=""; + $search_firstname=""; + $search_login=""; + $search_company=""; + $type=""; + $search_email=""; + $search_address=""; + $search_zip=""; + $search_town=""; + $search_morphy=""; + $search_categ=""; + $catid=""; + $sall=""; +} + /* * View @@ -140,10 +191,25 @@ if ($search_login) $sql.= natural_search("d.login", $search_login); if ($search_email) $sql.= natural_search("d.email", $search_email); if ($filter == 'uptodate') $sql.=" AND datefin >= '".$db->idate($now)."'"; if ($filter == 'outofdate') $sql.=" AND (datefin IS NULL OR datefin < '".$db->idate($now)."')"; + +// Add where from extra fields +foreach ($search_array_options as $key => $val) +{ + $crit=$val; + $tmpkey=preg_replace('/search_options_/','',$key); + $typ=$extrafields->attribute_type[$tmpkey]; + $mode=0; + if (in_array($typ, array('int','double'))) $mode=1; // Search on a numeric + if ($val && ( ($crit != '' && ! in_array($typ, array('select'))) || ! empty($crit))) + { + $sql .= natural_search('ef.'.$tmpkey, $crit, $mode); + } +} // Add where from hooks $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook $sql.=$hookmanager->resPrint; + $sql.= $db->order($sortfield,$sortorder); // Count total nb of records with no order and no limits @@ -190,11 +256,25 @@ if ($resql) if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; if ($statut != "") $param.="&statut=".$statut; if ($search_nom) $param.="&search_nom=".$search_nom; - if ($search_login) $param.="&search_login=".$search_login; - if ($search_email) $param.="&search_email=".$search_email; - if ($filter) $param.="&filter=".$filter; - if ($type > 0) $param.="&type=".$type; - if ($optioncss != '') $param.='&optioncss='.$optioncss; + if ($search_firstname) $param.="&search_firstname=".$search_firstname; + if ($search_lastname) $param.="&search_lastname=".$search_lastname; + if ($search_login) $param.="&search_login=".$search_login; + if ($search_email) $param.="&search_email=".$search_email; + if ($search_company) $param.="&search_company=".$search_company; + if ($search_zip) $param.="&search_zip=".$search_zip; + if ($search_town) $param.="&search_town=".$search_town; + if ($filter) $param.="&filter=".$filter; + if ($type > 0) $param.="&type=".$type; + if ($optioncss != '') $param.='&optioncss='.$optioncss; + // Add $param from extra fields + foreach ($search_array_options as $key => $val) + { + $crit=$val; + $tmpkey=preg_replace('/search_options_/','',$key); + if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val); + } + + //$massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge"))); print '