Fix filters on surveys

This commit is contained in:
Laurent Destailleur 2017-11-24 10:00:46 +01:00
parent f0d0969a3b
commit 6d5f2b2f21
3 changed files with 25 additions and 21 deletions

View File

@ -132,7 +132,7 @@ if ($object->id > 0)
dol_fiche_head($head, 'supplier', $langs->trans("ThirdParty"), -1, 'company');
$linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php">'.$langs->trans("BackToList").'</a>';
$linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');

View File

@ -216,7 +216,7 @@ dol_fiche_head($head,'general',$langs->trans("Survey"), -1, DOL_URL_ROOT.'/opens
$morehtmlref = '';
$linkback = '<a href="'.DOL_URL_ROOT.'/opensurvey/list.php">'.$langs->trans("BackToList").'</a>';
$linkback = '<a href="'.DOL_URL_ROOT.'/opensurvey/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
dol_banner_tab($object, 'id', $linkback, 1, 'id_sondage', 'id_sondage', $morehtmlref);

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2013-2015 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2013-2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
@ -34,9 +34,8 @@ $action=GETPOST('action','aZ09');
$id=GETPOST('id','alpha');
$numsondage= $id;
$search_ref = GETPOST('search_ref', 'alpha');
$surveytitle=GETPOST('surveytitle', 'alpha');
$status=GETPOST('status', 'int');
//if (! isset($_POST['status']) && ! isset($_GET['status'])) $status='opened'; // If filter unknown, we choose 'opened'
$search_title = GETPOST('search_title', 'alpha');
$search_status = GETPOST('search_status', 'alpha');
$sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha');
@ -58,10 +57,10 @@ $langs->load("opensurvey");
* Actions
*/
if (GETPOST('button_removefilter'))
if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
{
$status='';
$surveytitle='';
$search_status='';
$search_title='';
$search_ref='';
}
@ -75,7 +74,7 @@ $opensurvey_static = new Opensurveysondage($db);
$now = dol_now();
llxHeader();
llxHeader('', $langs->trans("OpenSurveyArea"));
$param='';
$fieldtosortuser=empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)?'firstname':'lastname';
@ -98,13 +97,13 @@ print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"")
print '<tr class="liste_titre_filter">';
print '<td class="liste_titre"><input type="text" class="maxwidth100" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>';
print '<td class="liste_titre"><input type="text" class="maxwidth100onsmartphone" name="surveytitle" value="'.dol_escape_htmltag($surveytitle).'"></td>';
print '<td class="liste_titre"><input type="text" class="maxwidth100onsmartphone" name="search_title" value="'.dol_escape_htmltag($search_title).'"></td>';
print '<td class="liste_titre"></td>';
print '<td class="liste_titre"></td>';
print '<td class="liste_titre"></td>';
$arraystatus=array(''=>'&nbsp;','expired'=>$langs->trans("Expired"),'opened'=>$langs->trans("Opened"));
print '<td class="liste_titre" align="center">'. $form->selectarray('status', $arraystatus, $status).'</td>';
print '<td class="liste_titre"></td>';
$arraystatus=array('-1'=>'&nbsp;','0'=>$langs->trans("Draft"),'1'=>$langs->trans("Opened"),'2'=>$langs->trans("Closed"));
print '<td class="liste_titre" align="center">'. $form->selectarray('search_status', $arraystatus, $search_status).'</td>';
print '<td class="liste_titre" align="right">';
$searchpicto=$form->showFilterAndCheckAddButtons(0);
print $searchpicto;
@ -114,7 +113,7 @@ print '</tr>'."\n";
print '<tr class="liste_titre">';
print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "p.id_sondage", $param,"","",$sortfield,$sortorder);
print_liste_field_titre("Title", $_SERVER["PHP_SELF"], "p.titre", $param,"","",$sortfield,$sortorder);
print_liste_field_titre("Type");
print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "p.format", $param,"","",$sortfield,$sortorder);
print_liste_field_titre("Author", $_SERVER["PHP_SELF"], "u.".$fieldtosortuser, $param,"","",$sortfield,$sortorder);
print_liste_field_titre("NbOfVoters", $_SERVER["PHP_SELF"], "", $param,"",'align="right"',$sortfield,$sortorder);
print_liste_field_titre("ExpireDate", $_SERVER["PHP_SELF"], "p.date_fin", $param,"",'align="center"',$sortfield,$sortorder);
@ -125,7 +124,7 @@ print '</tr>'."\n";
$sql = "SELECT p.id_sondage, p.fk_user_creat, p.format, p.date_fin, p.status, p.titre, p.nom_admin,";
$sql.= " u.login, u.firstname, u.lastname";
$sql.= " FROM ".MAIN_DB_PREFIX."opensurvey_sondage as p";
$sql.= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."user u ON u.rowid = p.fk_user_creat";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user u ON u.rowid = p.fk_user_creat";
// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
@ -134,11 +133,11 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
$nbtotalofrecords = $db->num_rows($result);
}
$sql.= " WHERE p.entity = ".getEntity('survey');
if ($status == 'expired') $sql.=" AND date_fin < '".$db->idate($now)."'";
if ($status == 'opened') $sql.=" AND date_fin >= '".$db->idate($now)."'";
if ($search_status != '-1' && $search_status != '') $sql.=natural_search("p.status", $search_status, 2);
if ($search_expired == 'expired') $sql.=" AND p.date_fin < '".$db->idate($now)."'";
if ($search_expired == 'opened') $sql.=" AND p.date_fin >= '".$db->idate($now)."'";
if ($search_ref) $sql.=natural_search("p.id_sondage", $search_ref);
if ($surveytitle) $sql.=natural_search("p.titre", $surveytitle);
if ($search_title) $sql.=natural_search("p.titre", $search_title);
$sql.= $db->order($sortfield,$sortorder);
// Count total nb of records
@ -149,7 +148,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
$nbtotalofrecords = $db->num_rows($result);
}
$sql.= $db->plimit($limit + 1,$offset);
$sql.= $db->plimit($limit+1, $offset);
$resql=$db->query($sql);
if (! $resql) dol_print_error($db);
@ -174,6 +173,7 @@ while ($i < min($num,$limit))
$opensurvey_static->ref=$obj->id_sondage;
$opensurvey_static->title=$obj->titre;
$opensurvey_static->status=$obj->status;
$opensurvey_static->date_fin=$db->jdate($obj->date_fin);
print '<tr>';
@ -183,7 +183,10 @@ while ($i < min($num,$limit))
print '</td>';
// Title
print '<td>'.dol_htmlentities($obj->titre).'</td><td>';
print '<td>'.dol_htmlentities($obj->titre).'</td>';
// Type
print '<td>';
$type=($obj->format=='A')?'classic':'date';
print img_picto('',dol_buildpath('/opensurvey/img/'.($type == 'classic'?'chart-32.png':'calendar-32.png'),1),'width="16"',1);
print ' '.$langs->trans($type=='classic'?"TypeClassic":"TypeDate");
@ -204,6 +207,7 @@ while ($i < min($num,$limit))
print '</td>';
// Nb of voters
print'<td align="right">'.$nbuser.'</td>'."\n";
print '<td align="center">'.dol_print_date($db->jdate($obj->date_fin),'day');