Skip to content

Commit

Permalink
Work on the feature to select which field to show
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Oct 14, 2015
1 parent 225313d commit e9aed15
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 40 deletions.
48 changes: 48 additions & 0 deletions htdocs/core/actions_changeselectedfields.inc.php
@@ -0,0 +1,48 @@
<?php
/* Copyright (C) 2014 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/

/**
* \file htdocs/core/actions_changeselectedfields.inc.php
* \brief Code for actions when we change list of fields on a list page
*/


// $action must be defined
// $db must be defined
// $conf must be defined
// $object must be defined (object is loaded in this file with fetch)

// Save selection
if (GETPOST('formfilteraction') == 'listafterchangingselectedfields')
{
$tabparam=array();

$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;

if (GETPOST("selectedfields")) $tabparam["MAIN_SELECTEDFIELDS_".$varpage]=GETPOST("selectedfields");
else $tabparam["MAIN_SELECTEDFIELDS_".$varpage]='';

include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';

$result=dol_set_user_param($db, $conf, $user, $tabparam);

//$action='list';
//var_dump($tabparam);exit;
}


38 changes: 26 additions & 12 deletions htdocs/core/class/html.form.class.php
Expand Up @@ -4671,37 +4671,51 @@ function formatSelection(record) {'."\n";
* Show a multiselect form from an array.
*
* @param string $htmlname Name of select
* @param array $array Array with array to show
* @param array $array Array with array of fields we could show
* @param string $varpage Id of context for page. Can be set with $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
* @return string HTML multiselect string
* @see selectarray
*/
static function multiSelectArrayWithCheckbox($htmlname, $array)
static function multiSelectArrayWithCheckbox($htmlname, $array, $varpage)
{
global $user;

$tmpvar="MAIN_SELECTEDFIELDS_".$varpage;
if (! empty($user->conf->$tmpvar))
{
$tmparray=explode(',', $user->conf->$tmpvar);
foreach($array as $key => $val)
{
//var_dump($key);
//var_dump($tmparray);
if (in_array($key, $tmparray)) $array[$key]['checked']=1;
else $array[$key]['checked']=0;
}
}
//var_dump($array);

$lis='';
$liststring='';
$listcheckedstring='';

foreach($array as $key => $val)
{
if (isset($val['cond']) && ! $val['cond']) continue;
if ($val['label'])
if ($val['label'])
{
$lis.='<li><input type="checkbox" value="'.$key.'"'.($val['checked']?' checked="checked"':'').'/>'.dol_escape_htmltag($val['label']).'</li>';
$liststring.=$key.',';
$lis.='<li><input type="checkbox" value="'.$key.'"'.(empty($val['checked'])?'':' checked="checked"').'/>'.dol_escape_htmltag($val['label']).'</li>';
$listcheckedstring.=(empty($val['checked'])?'':$key.',');
}
}


$out ='<!-- Component multiSelectArrayWithCheckbox '.$htmlname.' -->
<dl class="dropdown">
<dt>
<a href="#">
'.img_picto('','list').'
<input type="hidden" class="'.$htmlname.'" name="'.$htmlname.'" value="'.$liststring.'">
<input type="hidden" class="'.$htmlname.'" name="'.$htmlname.'" value="'.$listcheckedstring.'">
</a>
</dt>
<dd>
<div class="multiselectcheckbox'.$htmlname.'">
<ul>
Expand Down Expand Up @@ -4730,9 +4744,9 @@ function getSelectedValue(id) {
});
$(\'.multiselectcheckbox'.$htmlname.' input[type="checkbox"]\').on(\'click\', function () {
console.log("A new field was added/removed")
$("input:hidden[name=formfilteraction]").val(\'listafterchangingselectedfields\')
var title = $(this).val() + ",";
if ($(this).is(\':checked\')) {
$(\'.'.$htmlname.'\').val(title + $(\'.'.$htmlname.'\').val());
}
Expand Down
2 changes: 2 additions & 0 deletions htdocs/install/mysql/migration/3.8.0-3.9.0.sql
Expand Up @@ -55,3 +55,5 @@ ALTER TABLE llx_adherent ADD COLUMN pass_crypted varchar(128) after pass;
ALTER TABLE llx_paiement ADD COLUMN ref varchar(30) NOT NULL AFTER rowid;

ALTER TABLE llx_socpeople ADD COLUMN photo varchar(255) AFTER skype;

ALTER TABLE llx_user_param MODIFY COLUMN value text NOT NULL;
2 changes: 1 addition & 1 deletion htdocs/install/mysql/tables/llx_user_param.sql
Expand Up @@ -23,7 +23,7 @@ create table llx_user_param
fk_user integer NOT NULL,
entity integer DEFAULT 1 NOT NULL, -- multi company id
param varchar(64) NOT NULL,
value varchar(255) NOT NULL
value text NOT NULL
)ENGINE=innodb;

--
Expand Down
2 changes: 1 addition & 1 deletion htdocs/product/list.php
Expand Up @@ -89,7 +89,7 @@
* Actions
*/

if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers
if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers
{
$sref="";
$sbarcode="";
Expand Down
59 changes: 33 additions & 26 deletions htdocs/societe/list.php
Expand Up @@ -75,14 +75,17 @@
$pagenext = $page + 1;

// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('thirdpartylist'));
$contextpage='thirdpartylist';
$hookmanager->initHooks(array($contextpage));
$extrafields = new ExtraFields($db);


/*
* Actions
*/

include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';

// special search
if ($mode == 'search')
{
Expand All @@ -95,25 +98,25 @@
if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_societe as cs";
$sql.= " WHERE s.entity IN (".getEntity('societe', 1).")";

// For natural search
$scrit = explode(' ', $socname);
// For natural search
$scrit = explode(' ', $socname);

$fields = array(
's.nom',
's.code_client',
's.email',
's.url',
's.siren',
's.name_alias'
);
$fields = array(
's.nom',
's.code_client',
's.email',
's.url',
's.siren',
's.name_alias'
);

if (!empty($conf->barcode->enabled)) {
$fields[] = 's.barcode';
}
if (!empty($conf->barcode->enabled)) {
$fields[] = 's.barcode';
}

foreach ($scrit as $crit) {
$sql.= natural_search($fields, $crit);
}
foreach ($scrit as $crit) {
$sql.= natural_search($fields, $crit);
}

if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid) $sql.= " AND s.rowid = ".$socid;
Expand Down Expand Up @@ -168,7 +171,7 @@


// Do we click on purge search criteria ?
if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers
if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers
{
$search_categ='';
$search_sale='';
Expand Down Expand Up @@ -197,12 +200,14 @@
/*
* Mode List
*/

/*
REM: Regle sur droits "Voir tous les clients"
Utilisateur interne socid=0 + Droits voir tous clients => Voit toute societe
Utilisateur interne socid=0 + Pas de droits voir tous clients => Ne voit que les societes liees comme commercial
Utilisateur externe socid=x + Droits voir tous clients => Ne voit que lui meme
Utilisateur externe socid=x + Pas de droits voir tous clients => Ne voit que lui meme
REM: Rules on permissions to see thirdparties
Internal or External user + No permission to see customers => See nothing
Internal user socid=0 + Permission to see ALL customers => See all thirdparties
Internal user socid=0 + No permission to see ALL customers => See only thirdparties linked to user that are sale representative
External user socid=x + Permission to see ALL customers => Can see only himself
External user socid=x + No permission to see ALL customers => Can see only himself
*/
$title=$langs->trans("ListOfThirdParties");

Expand Down Expand Up @@ -315,7 +320,8 @@
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';

print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';

// Filter on categories
/* Not possible in this page because list is for ALL third parties type
$moreforfilter='';
Expand Down Expand Up @@ -362,7 +368,8 @@
);
if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
{
$selectotherfields=$form->multiSelectArrayWithCheckbox('selectotherfields', $arrayfields);
$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage);
}

print '<table class="liste '.($moreforfilter?"listwithfilterbefore":"").'">';
Expand All @@ -382,7 +389,7 @@
$reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"s.status","",$param,'align="right"',$sortfield,$sortorder);
print_liste_field_titre($selectotherfields, $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,'maxwidthsearch ');
print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,'maxwidthsearch ');
print "</tr>\n";

// Fields title search
Expand Down

0 comments on commit e9aed15

Please sign in to comment.