From 30fb26296d46d865f09db539ea70751d61102ee4 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 24 Mar 2012 21:19:22 +0800 Subject: [PATCH] Fix: add check array in GETPOST New: update multiselect with a fork --- htdocs/core/lib/functions.lib.php | 14 +- .../multiselect/css/ui.multiselect.css | 14 +- .../plugins/multiselect/js/ui.multiselect.js | 242 ++++++++++++++---- 3 files changed, 211 insertions(+), 59 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index a077743dc92..46bc67cee43 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -275,7 +275,7 @@ function dol_shutdown() * Return value of a param into GET or POST supervariable * * @param string $paramname Name of parameter to found - * @param string $check Type of check (''=no check, 'int'=check it's numeric, 'alpha'=check it's alpha only) + * @param string $check Type of check (''=no check, 'int'=check it's numeric, 'alpha'=check it's alpha only, 'array'=check it's array) * @param int $method Type of method (0 = get then post, 1 = only get, 2 = only post, 3 = post then get) * @return string Value found or '' if check fails */ @@ -289,17 +289,25 @@ function GETPOST($paramname,$check='',$method=0) if (! empty($check)) { - $out=trim($out); // Check if numeric - if ($check == 'int' && ! preg_match('/^[-\.,0-9]+$/i',$out)) $out=''; + if ($check == 'int' && ! preg_match('/^[-\.,0-9]+$/i',$out)) + { + $out=trim($out); + $out=''; + } // Check if alpha elseif ($check == 'alpha') { + $out=trim($out); // '"' is dangerous because param in url can close the href= or src= and add javascript functions. // '../' is dangerous because it allows dir transversals if (preg_match('/"/',$out)) $out=''; else if (preg_match('/\.\.\//',$out)) $out=''; } + elseif ($check == 'array') + { + if (! is_array($out) || empty($out)) $out=array(); + } } return $out; diff --git a/htdocs/includes/jquery/plugins/multiselect/css/ui.multiselect.css b/htdocs/includes/jquery/plugins/multiselect/css/ui.multiselect.css index f4599f8fc6b..7d3a44801d2 100644 --- a/htdocs/includes/jquery/plugins/multiselect/css/ui.multiselect.css +++ b/htdocs/includes/jquery/plugins/multiselect/css/ui.multiselect.css @@ -1,25 +1,25 @@ /* Multiselect ----------------------------------*/ -.multiselect { width: 460px; height: 150px; } .ui-multiselect { border: solid 1px; font-size: 0.8em; } .ui-multiselect ul { -moz-user-select: none; } -.ui-multiselect li { margin: 0; padding: 0; cursor: default; line-height: 20px; height: 20px; font-size: 11px; list-style: none; } +.ui-multiselect li { margin: 0; padding: 0; cursor: default; line-height: 20px; height: 20px; font-size: 11px; list-style: none; padding-right: 18px; overflow: hidden; } .ui-multiselect li a { color: #999; text-decoration: none; padding: 0; display: block; float: left; cursor: pointer;} .ui-multiselect li.ui-draggable-dragging { padding-left: 10px; } .ui-multiselect div.selected { position: relative; padding: 0; margin: 0; border: 0; float:left; } .ui-multiselect ul.selected { position: relative; padding: 0; overflow: auto; overflow-x: hidden; background: #fff; margin: 0; list-style: none; border: 0; position: relative; width: 100%; } -.ui-multiselect ul.selected li { } -.ui-multiselect div.available { position: relative; padding: 0; margin: 0; border: 0; float:left; border-left: 1px solid; } +.ui-multiselect div.available { position: relative; padding: 0; margin: 0; border: 0; float:left; } .ui-multiselect ul.available { position: relative; padding: 0; overflow: auto; overflow-x: hidden; background: #fff; margin: 0; list-style: none; border: 0; width: 100%; } .ui-multiselect ul.available li { padding-left: 10px; } - + +.ui-multiselect div.right-column { border-left: 1px solid; } + .ui-multiselect .ui-state-default { border: none; margin-bottom: 1px; position: relative; padding-left: 20px;} .ui-multiselect .ui-state-hover { border: none; } .ui-multiselect .ui-widget-header {border: none; font-size: 11px; margin-bottom: 1px;} - + .ui-multiselect .add-all { float: right; padding: 7px;} .ui-multiselect .remove-all { float: right; padding: 7px;} .ui-multiselect .search { float: left; padding: 4px;} @@ -27,5 +27,5 @@ .ui-multiselect li span.ui-icon-arrowthick-2-n-s { position: absolute; left: 2px; } .ui-multiselect li a.action { position: absolute; right: 2px; top: 2px; } - + .ui-multiselect input.search { height: 14px; padding: 1px; opacity: 0.5; margin: 4px; width: 100px; } \ No newline at end of file diff --git a/htdocs/includes/jquery/plugins/multiselect/js/ui.multiselect.js b/htdocs/includes/jquery/plugins/multiselect/js/ui.multiselect.js index 1234fa7a957..eb4578fc782 100644 --- a/htdocs/includes/jquery/plugins/multiselect/js/ui.multiselect.js +++ b/htdocs/includes/jquery/plugins/multiselect/js/ui.multiselect.js @@ -4,13 +4,13 @@ * Authors: * Michael Aufreiter (quasipartikel.at) * Yanick Rochon (yanick.rochon[at]gmail[dot]com) - * + * * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. - * + * * http://www.quasipartikel.at/multiselect/ * - * + * * Depends: * ui.core.js * ui.sortable.js @@ -18,7 +18,7 @@ * Optional: * localization (http://plugins.jquery.com/project/localisation) * scrollTo (http://plugins.jquery.com/project/ScrollTo) - * + * * Todo: * Make batch actions faster * Implement dynamic insertion through remote calls @@ -30,49 +30,82 @@ $.widget("ui.multiselect", { options: { sortable: true, + dragToAdd: true, searchable: true, doubleClickable: true, animated: 'fast', show: 'slideDown', hide: 'slideUp', dividerLocation: 0.6, + selectedContainerOnLeft: true, + width: null, + height: null, nodeComparator: function(node1,node2) { var text1 = node1.text(), text2 = node2.text(); return text1 == text2 ? 0 : (text1 < text2 ? -1 : 1); - } + }, + includeRemoveAll: true, + includeAddAll: true, + pressEnterKeyToAddAll: false }, _create: function() { this.element.hide(); this.id = this.element.attr("id"); this.container = $('
').insertAfter(this.element); this.count = 0; // number of currently selected options - this.selectedContainer = $('
').appendTo(this.container); - this.availableContainer = $('
').appendTo(this.container); - this.selectedActions = $('
0 '+$.ui.multiselect.locale.itemsCount+''+$.ui.multiselect.locale.removeAll+'
').appendTo(this.selectedContainer); - this.availableActions = $('
'+$.ui.multiselect.locale.addAll+'
').appendTo(this.availableContainer); + this.selectedContainer = $('
'); + if (this.options.selectedContainerOnLeft) { + this.selectedContainer.appendTo(this.container); + this.availableContainer = $('
').appendTo(this.container); + this.availableContainer.addClass('right-column'); + } + else + { + this.availableContainer = $('
').appendTo(this.container); + this.selectedContainer.appendTo(this.container); + this.selectedContainer.addClass('right-column'); + } + this.selectedActions = $('
0 '+$.ui.multiselect.locale.itemsCount+''+(this.options.includeRemoveAll?''+$.ui.multiselect.locale.removeAll+'':' ')+'
').appendTo(this.selectedContainer); + this.availableActions = $('
'+(this.options.includeAddAll?''+$.ui.multiselect.locale.addAll+'':' ')+'
').appendTo(this.availableContainer); this.selectedList = $('').bind('selectstart', function(){return false;}).appendTo(this.selectedContainer); this.availableList = $('').bind('selectstart', function(){return false;}).appendTo(this.availableContainer); - + var that = this; + var width = this.options.width; + if (!width) { + width = this.element.width(); + } + var height = this.options.height; + if (!height) { + height = this.element.height(); + } + // set dimensions - this.container.width(this.element.width()+1); - this.selectedContainer.width(Math.floor(this.element.width()*this.options.dividerLocation)); - this.availableContainer.width(Math.floor(this.element.width()*(1-this.options.dividerLocation))); + this.container.width(width-2); + if (this.options.selectedContainerOnLeft) { + this.selectedContainer.width(Math.floor(width*this.options.dividerLocation)-1); + this.availableContainer.width(Math.floor(width*(1-this.options.dividerLocation))-2); + } + else + { + this.selectedContainer.width(Math.floor(width*this.options.dividerLocation)-2); + this.availableContainer.width(Math.floor(width*(1-this.options.dividerLocation))-1); + } // fix list height to match