From fe9c880984c4c4c63c4f659c972d772e1278e0a7 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Thu, 10 Nov 2016 14:24:29 +0100
Subject: [PATCH] NEW Add missing unique key on table llx_links

---
 htdocs/core/class/html.form.class.php         |  9 +++++++-
 htdocs/core/class/html.formfile.class.php     | 13 ++++++-----
 htdocs/core/tpl/notes.tpl.php                 |  4 ++--
 .../install/mysql/migration/4.0.0-5.0.0.sql   | 14 ++++++++++++
 htdocs/install/mysql/migration/repair.sql     | 12 +++++++++-
 htdocs/install/mysql/tables/llx_links.key.sql | 22 +++++++++++++++++++
 6 files changed, 64 insertions(+), 10 deletions(-)
 create mode 100644 htdocs/install/mysql/tables/llx_links.key.sql

diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 8ca311af082..62bd4cde742 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -181,7 +181,14 @@ class Form
                 else if (preg_match('/^text/',$typeofdata) || preg_match('/^note/',$typeofdata))
                 {
                     $tmp=explode(':',$typeofdata);
-                    $ret.='<textarea id="'.$htmlname.'" name="'.$htmlname.'" wrap="soft" rows="'.($tmp[1]?$tmp[1]:'20').'" cols="'.($tmp[2]?$tmp[2]:'100').'">'.($editvalue?$editvalue:$value).'</textarea>';
+                    $cols=$tmp[2];
+                    $morealt='';
+                    if (preg_match('/%/',$cols))
+                    {
+                        $morealt=' style="width: '.$cols.'"';
+                        $cols='';
+                    }
+                    $ret.='<textarea id="'.$htmlname.'" name="'.$htmlname.'" wrap="soft" rows="'.($tmp[1]?$tmp[1]:'20').'"'.($cols?' cols="'.$cols.'"':'').$morealt.'">'.($editvalue?$editvalue:$value).'</textarea>';
                 }
                 else if ($typeofdata == 'day' || $typeofdata == 'datepicker')
                 {
diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php
index a05d8b27c5e..d79eaae65f0 100644
--- a/htdocs/core/class/html.formfile.class.php
+++ b/htdocs/core/class/html.formfile.class.php
@@ -62,7 +62,7 @@ class FormFile
      *  @param  int		$addcancel		1=Add 'Cancel' button
      *	@param	int		$sectionid		If upload must be done inside a particular ECM section
      * 	@param	int		$perm			Value of permission to allow upload
-     *  @param  int		$size           Length of input file area
+     *  @param  int		$size           Length of input file area. Deprecated.
      *  @param	Object	$object			Object to use (when attachment is done on an element)
      *  @param	string	$options		Add an option column
      *  @param	integer	$useajax		Use fileupload ajax (0=never, 1=if enabled, 2=always whatever is option). 2 should never be used.
@@ -106,7 +106,7 @@ class FormFile
 
             if (! empty($options)) $out .= '<td>'.$options.'</td>';
 
-            $out .= '<td valign="middle" class="nowrap">';
+            $out .= '<td valign="middle">';
 
             $max=$conf->global->MAIN_UPLOAD_DOC;		// En Kb
             $maxphp=@ini_get('upload_max_filesize');	// En inconnu
@@ -121,10 +121,10 @@ class FormFile
             {
                 $out .= '<input type="hidden" name="max_file_size" value="'.($max*1024).'">';
             }
-            $out .= '<input class="flat" type="file" name="userfile" size="'.$maxlength.'"';
+            $out .= '<input class="flat minwidth400" type="file" name="userfile"';
             $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':'');
             $out .= '>';
-            $out .= '&nbsp;';
+            $out .= ' ';
             $out .= '<input type="submit" class="button" name="sendit" value="'.$langs->trans("Upload").'"';
             $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':'');
             $out .= '>';
@@ -183,11 +183,11 @@ class FormFile
 	            $out .= '<div class="valignmiddle" >';
 	            $out .= '<div class="inline-block" style="padding-right: 10px;">';
 	            if (! empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= '<label for="link">'.$langs->trans("URLToLink") . ':</label> ';
-	            $out .= '<input type="text" name="link" size="'.$maxlength.'" id="link" placeholder="'.dol_escape_htmltag($langs->trans("URLToLink")).'">';
+	            $out .= '<input type="text" name="link" class="flat minwidth400imp" id="link" placeholder="'.dol_escape_htmltag($langs->trans("URLToLink")).'">';
 	            $out .= '</div>';
 	            $out .= '<div class="inline-block" style="padding-right: 10px;">';
 	            if (! empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= '<label for="label">'.$langs->trans("Label") . ':</label> ';
-	            $out .= '<input type="text" name="label" id="label" placeholder="'.dol_escape_htmltag($langs->trans("Label")).'">';
+	            $out .= '<input type="text" class="flat" name="label" id="label" placeholder="'.dol_escape_htmltag($langs->trans("Label")).'">';
 	            $out .= '<input type="hidden" name="objecttype" value="' . $object->element . '">';
 	            $out .= '<input type="hidden" name="objectid" value="' . $object->id . '">';
 	            $out .= '</div>';
@@ -1451,6 +1451,7 @@ class FormFile
             else
 			{
                 print '<td>';
+                print img_picto('', 'object_globe').' ';
                 print '<a data-ajax="false" href="' . $link->url . '" target="_blank">';
                 print $link->label;
                 print '</a>';
diff --git a/htdocs/core/tpl/notes.tpl.php b/htdocs/core/tpl/notes.tpl.php
index f0e69b01b81..c971a49148f 100644
--- a/htdocs/core/tpl/notes.tpl.php
+++ b/htdocs/core/tpl/notes.tpl.php
@@ -63,8 +63,8 @@ elseif ($module == 'shipping')    		 { $permission=$user->rights->expedition->cr
 elseif ($module == 'product')    		 { $permission=$user->rights->produit->creer;}
 //else dol_print_error('','Bad value '.$module.' for param module');
 
-if (! empty($conf->global->FCKEDITOR_ENABLE_SOCIETE)) $typeofdata='ckeditor:dolibarr_notes:100%:200::1:12:100';	// Rem: This var is for all notes, not only thirdparties note.
-else $typeofdata='textarea:12:100';
+if (! empty($conf->global->FCKEDITOR_ENABLE_SOCIETE)) $typeofdata='ckeditor:dolibarr_notes:100%:200::1:12:95%';	// Rem: This var is for all notes, not only thirdparties note.
+else $typeofdata='textarea:12:95%';
 
 ?>
 
diff --git a/htdocs/install/mysql/migration/4.0.0-5.0.0.sql b/htdocs/install/mysql/migration/4.0.0-5.0.0.sql
index 1e0f92a1cac..faffe9e53f5 100644
--- a/htdocs/install/mysql/migration/4.0.0-5.0.0.sql
+++ b/htdocs/install/mysql/migration/4.0.0-5.0.0.sql
@@ -202,3 +202,17 @@ create table llx_user_employment
 )ENGINE=innodb;
 
 
+
+
+-- Sequence to removed duplicated values of llx_links. Use serveral times if you still have duplicate.
+drop table tmp_links_double;
+--select objectid, label, max(rowid) as max_rowid, count(rowid) as count_rowid from llx_links where label is not null group by objectid, label having count(rowid) >= 2;
+create table tmp_links_double as (select objectid, label, max(rowid) as max_rowid, count(rowid) as count_rowid from llx_links where label is not null group by objectid, label having count(rowid) >= 2);
+--select * from tmp_links_double;
+delete from llx_links where (rowid, label) in (select max_rowid, label from tmp_links_double);	--update to avoid duplicate, delete to delete
+drop table tmp_links_double;
+
+ALTER TABLE llx_links ADD UNIQUE INDEX uk_links (objectid,label);
+
+
+
diff --git a/htdocs/install/mysql/migration/repair.sql b/htdocs/install/mysql/migration/repair.sql
index 99e4a7c556c..3ba06daabce 100755
--- a/htdocs/install/mysql/migration/repair.sql
+++ b/htdocs/install/mysql/migration/repair.sql
@@ -176,6 +176,7 @@ update llx_opensurvey_sondage set format = 'D' where format = 'D+';
 update llx_opensurvey_sondage set format = 'A' where format = 'A+';
 update llx_opensurvey_sondage set tms = now();
 
+
 -- ALTER TABLE llx_facture_fourn ALTER COLUMN fk_cond_reglement DROP NOT NULL;
 
 
@@ -183,12 +184,21 @@ update llx_product set barcode = null where barcode in ('', '-1', '0');
 update llx_societe set barcode = null where barcode in ('', '-1', '0');
 
 
+-- Sequence to removed duplicated values of llx_links. Use serveral times if you still have duplicate.
+drop table tmp_links_double;
+--select objectid, label, max(rowid) as max_rowid, count(rowid) as count_rowid from llx_links where label is not null group by objectid, label having count(rowid) >= 2;
+create table tmp_links_double as (select objectid, label, max(rowid) as max_rowid, count(rowid) as count_rowid from llx_links where label is not null group by objectid, label having count(rowid) >= 2);
+--select * from tmp_links_double;
+delete from llx_links where (rowid, label) in (select max_rowid, label from tmp_links_double);	--update to avoid duplicate, delete to delete
+drop table tmp_links_double;
+
+
 -- Sequence to removed duplicated values of barcode in llx_product. Use serveral times if you still have duplicate.
 drop table tmp_product_double;
 --select barcode, max(rowid) as max_rowid, count(rowid) as count_rowid from llx_product where barcode is not null group by barcode having count(rowid) >= 2;
 create table tmp_product_double as (select barcode, max(rowid) as max_rowid, count(rowid) as count_rowid from llx_product where barcode is not null group by barcode having count(rowid) >= 2);
 --select * from tmp_product_double;
-update llx_product set barcode = null where (rowid, barcode) in (select max_rowid, barcode from tmp_product_double);
+update llx_product set barcode = null where (rowid, barcode) in (select max_rowid, barcode from tmp_product_double);	--update to avoid duplicate, delete to delete
 drop table tmp_product_double;
 
 
diff --git a/htdocs/install/mysql/tables/llx_links.key.sql b/htdocs/install/mysql/tables/llx_links.key.sql
new file mode 100644
index 00000000000..7ba509e9d58
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_links.key.sql
@@ -0,0 +1,22 @@
+-- ========================================================================
+-- Copyright (C) 2016      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/>.
+--
+--
+-- Linked files
+-- ========================================================================
+
+ALTER TABLE llx_links ADD UNIQUE INDEX uk_links (objectid,label);
+
-- 
GitLab