Sfoglia il codice sorgente

Merge remote-tracking branch 'Upstream/develop' into 5.0-24

Conflicts:
	htdocs/loan/card.php
aspangaro 8 anni fa
parent
commit
9154843c1b
65 ha cambiato i file con 2130 aggiunte e 990 eliminazioni
  1. 2 2
      dev/skeletons/build_class_from_table.php
  2. 5 7
      dev/skeletons/skeleton_class.class.php
  3. 8 0
      dev/tools/github_authors_peryear.sh
  4. 15 0
      dev/tools/github_commits_perversion.sh
  5. 3 1
      htdocs/accountancy/class/html.formventilation.class.php
  6. 6 6
      htdocs/adherents/type.php
  7. 1 1
      htdocs/cashdesk/class/Facturation.class.php
  8. 4 1
      htdocs/cashdesk/css/style.css
  9. 9 9
      htdocs/cashdesk/tpl/facturation1.tpl.php
  10. 5 1
      htdocs/cashdesk/tpl/validation2.tpl.php
  11. 2 2
      htdocs/comm/action/pertype.php
  12. 1 1
      htdocs/commande/card.php
  13. 0 82
      htdocs/compta/paiement/class/cpaiement.class.php
  14. 0 82
      htdocs/compta/sociales/class/cchargesociales.class.php
  15. 8 2
      htdocs/core/actions_linkedfiles.inc.php
  16. 84 75
      htdocs/core/class/commonobject.class.php
  17. 3 2
      htdocs/core/class/hookmanager.class.php
  18. 163 33
      htdocs/core/class/html.formfile.class.php
  19. 5 2
      htdocs/core/class/html.formprojet.class.php
  20. 35 22
      htdocs/core/class/notify.class.php
  21. 233 34
      htdocs/core/lib/files.lib.php
  22. 65 65
      htdocs/core/lib/functions.lib.php
  23. 5 1
      htdocs/core/lib/images.lib.php
  24. 4 4
      htdocs/core/menus/standard/eldy.lib.php
  25. 1 1
      htdocs/core/modules/modAgenda.class.php
  26. 81 2
      htdocs/core/photos_resize.php
  27. 9 5
      htdocs/core/tpl/ajaxrow.tpl.php
  28. 9 2
      htdocs/core/tpl/document_actions_post_headers.tpl.php
  29. 1 1
      htdocs/document.php
  30. 1 2
      htdocs/ecm/class/ecmdirectory.class.php
  31. 782 0
      htdocs/ecm/class/ecmfiles.class.php
  32. 1 1
      htdocs/filefunc.inc.php
  33. 1 1
      htdocs/fourn/class/fournisseur.commande.dispatch.class.php
  34. 11 11
      htdocs/hrm/class/establishment.class.php
  35. 2 1
      htdocs/install/check.php
  36. 3 0
      htdocs/install/mysql/data/llx_c_action_trigger.sql
  37. 48 0
      htdocs/install/mysql/migration/5.0.0-6.0.0.sql
  38. 6 2
      htdocs/install/mysql/tables/llx_ecm_files.key.sql
  39. 5 3
      htdocs/install/mysql/tables/llx_ecm_files.sql
  40. 3 1
      htdocs/install/mysql/tables/llx_loan.sql
  41. 0 1
      htdocs/install/mysql/tables/llx_website_pages.sql
  42. 1 1
      htdocs/langs/en_US/admin.lang
  43. 1 0
      htdocs/langs/en_US/agenda.lang
  44. 1 0
      htdocs/langs/en_US/loan.lang
  45. 2 2
      htdocs/langs/en_US/main.lang
  46. 1 0
      htdocs/langs/en_US/other.lang
  47. 2 0
      htdocs/langs/en_US/products.lang
  48. 233 159
      htdocs/loan/card.php
  49. 15 9
      htdocs/loan/class/loan.class.php
  50. 1 1
      htdocs/loan/index.php
  51. 1 1
      htdocs/loan/payment/card.php
  52. 1 1
      htdocs/main.inc.php
  53. 177 130
      htdocs/product/class/product.class.php
  54. 7 7
      htdocs/product/class/service.class.php
  55. 2 2
      htdocs/product/document.php
  56. 0 115
      htdocs/product/stock/class/productlot.class.php
  57. 1 1
      htdocs/product/stock/class/productstockentrepot.class.php
  58. 2 1
      htdocs/projet/ajax/projects.php
  59. 23 8
      htdocs/projet/element.php
  60. 3 1
      htdocs/theme/eldy/style.css.php
  61. 2 0
      htdocs/theme/md/style.css.php
  62. 2 1
      htdocs/user/class/user.class.php
  63. 7 7
      htdocs/user/class/usergroup.class.php
  64. 2 51
      htdocs/websites/class/website.class.php
  65. 13 23
      htdocs/websites/class/websitepage.class.php

+ 2 - 2
dev/skeletons/build_class_from_table.php

@@ -303,7 +303,7 @@ foreach($property as $key => $prop)
 			$varprop.="\$this->db->escape(\$this->".$prop['field'].")";
 			$varprop.=".\"'\")";
 		}
-		elseif ($prop['field']=='fk_user_mod' || $prop['field']=='fk_user_author')
+		elseif ($prop['field']=='fk_user_mod' || $prop['field']=='fk_user_m' ||  $prop['field']=='fk_user_author')
 		{
 			$varprop.="'.\$user->id";
 		}
@@ -367,7 +367,7 @@ foreach($property as $key => $prop)
 			$varprop.=')."\'" : \'null\')';
 		}
 		
-		elseif ($prop['field']=='fk_user_mod') {
+		elseif ($prop['field']=='fk_user_mod' || $prop['field']=='fk_user_m') {
 			$varprop.="'.\$user->id";
 		}
 		else

+ 5 - 7
dev/skeletons/skeleton_class.class.php

@@ -188,11 +188,13 @@ class Skeleton_Class extends CommonObject
 			
 			// Retrieve all extrafields for invoice
 			// fetch optionals attributes and labels
+			/*
 			require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
 			$extrafields=new ExtraFields($this->db);
 			$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
 			$this->fetch_optionals($this->id,$extralabels);
-
+            */
+			
 			// $this->fetch_lines();
 			
 			$this->db->free($resql);
@@ -251,23 +253,19 @@ class Skeleton_Class extends CommonObject
 			$sql .= $this->db->order($sortfield,$sortorder);
 		}
 		if (!empty($limit)) {
-		 $sql .=  ' ' . $this->db->plimit($limit + 1, $offset);
+		 $sql .=  ' ' . $this->db->plimit($limit, $offset);
 		}
 
-		$this->lines = array();
-
 		$resql = $this->db->query($sql);
 		if ($resql) {
 			$num = $this->db->num_rows($resql);
 
 			while ($obj = $this->db->fetch_object($resql)) {
-				$line = new Skeleton_ClassLine();
+				$line = new self($this->db);
 
 				$line->id = $obj->rowid;
 				$line->prop1 = $obj->field1;
 				$line->prop2 = $obj->field2;
-
-				$this->lines[$line->id] = $line;
 				//...
 			}
 			$this->db->free($resql);

+ 8 - 0
dev/tools/github_authors_peryear.sh

@@ -0,0 +1,8 @@
+#!/bin/sh
+
+FROM=2016-01-01
+TO=2016-12-31
+
+echo "git log --since $FROM --before $TO | grep ^Author | sort -u -f -i -b | wc -l"
+git log --since $FROM --before $TO | grep ^Author | sort -u -f -i -b | wc -l
+

+ 15 - 0
dev/tools/github_commits_perversion.sh

@@ -0,0 +1,15 @@
+#/bin/bash
+Releases=("3.8" "3.9" "4.0" "5.0", "develop")
+Dates=("2010-01-01", "2011-01-01", "2012-01-01", "2013-01-01", "2014-01-01", "2015-01-01", "2016-07-01")
+let "counter = 1"
+
+for i in "${Releases[@]}"
+do
+  git shortlog -s -n  --after=${Dates[counter-1]} --before=${Dates[counter]}
+  echo -n "Total $i: " 
+  git log --pretty=oneline --after=${Dates[counter-1]} --before=${Dates[counter]} | wc -l
+  echo "=======================" 
+  echo
+  let "counter +=1"
+done
+

+ 3 - 1
htdocs/accountancy/class/html.formventilation.class.php

@@ -83,6 +83,8 @@ class FormVentilation extends Form
 
 		require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
 
+		$out = '';
+		
     	$options = array();
 		if ($usecache && ! empty($this->options_cache[$usecache]))
 		{
@@ -109,7 +111,7 @@ class FormVentilation extends Form
     			return -1;
     		}
 
-    		$out = ajax_combobox($htmlname, $event);
+    		$out .= ajax_combobox($htmlname, $event);
 
     		$selected = 0;
     		while ($obj = $this->db->fetch_object($resql))

+ 6 - 6
htdocs/adherents/type.php

@@ -91,10 +91,10 @@ if ($action == 'add' && $user->rights->adherent->configurer)
 		$object = new AdherentType($db);
 
 		$object->libelle        = trim($label);
-		$object->subscription   = trim($subscription);
+		$object->subscription   = (int) trim($subscription);
 		$object->note           = trim($comment);
-		$object->mail_valid     = trim($mail_valid);
-		$object->vote           = trim($vote);
+		$object->mail_valid     = (boolean) trim($mail_valid);
+		$object->vote           = (boolean) trim($vote);
 
 		// Fill array 'array_options' with data from add form
 		$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
@@ -129,10 +129,10 @@ if ($action == 'update' && $user->rights->adherent->configurer)
 		$object = new AdherentType($db);
 		$object->id             = $rowid;
 		$object->libelle        = trim($label);
-		$object->subscription   = trim($subscription);
+		$object->subscription   = (int) trim($subscription);
 		$object->note           = trim($comment);
-		$object->mail_valid     = trim($mail_valid);
-		$object->vote           = trim($vote);
+		$object->mail_valid     = (boolean) trim($mail_valid);
+		$object->vote           = (boolean) trim($vote);
 
 		// Fill array 'array_options' with data from add form
 		$ret = $extrafields->setOptionalsFromPost($extralabels,$object);

+ 1 - 1
htdocs/cashdesk/class/Facturation.class.php

@@ -37,7 +37,7 @@ class Facturation
      * int $prix		=> Prix HT du produit en cours
      * int $tva			=> 'rowid' du taux de tva dans llx_c_tva
      */
-    var $id;
+    public $id;
     protected $ref;
     protected $qte;
     protected $stock;

+ 4 - 1
htdocs/cashdesk/css/style.css

@@ -115,7 +115,7 @@ li.menu_choix0 {
 		float: right;
 }
 
-/* ------------------- R�capitulatif des articles ------------------- */
+/* ------------------- Remind of products ------------------- */
 .liste_articles {
 	min-width: 215px;
 	float: right;
@@ -212,6 +212,9 @@ p.titre {
 	max-width: 900px;
 }
 
+.blocksellfinished {
+	min-width: 215px;
+}
 .titre1 {
 	font-weight: bold;
 	color: #ff9900;

+ 9 - 9
htdocs/cashdesk/tpl/facturation1.tpl.php

@@ -106,23 +106,23 @@ $langs->load("cashdesk");
             <th><?php echo $langs->trans("VATRate"); ?></th>
             </tr>
 			<tr>
-				<td><input class="texte1" type="text" id="txtQte" name="txtQte" value="1" onkeyup="javascript: modif();" onfocus="javascript: this.select();" />
+				<td><input class="texte1 maxwidth50onsmartphone" type="text" id="txtQte" name="txtQte" value="1" onkeyup="javascript: modif();" onfocus="javascript: this.select();" />
 <?php print genkeypad("txtQte", "frmQte");?>
 				</td>
 				<!-- Affichage du stock pour l'article courant -->
 				<td>
-				<input class="texte1_off" type="text" name="txtStock" value="<?php echo $obj_facturation->stock() ?>" disabled />
+				<input class="texte1_off maxwidth50onsmartphone" type="text" name="txtStock" value="<?php echo $obj_facturation->stock() ?>" disabled />
 				</td>
 				<!-- Show unit price -->
 				<?php // TODO Remove the disabled and use this value when adding product into cart ?>
-				<td><input class="texte1_off" type="text" name="txtPrixUnit" value="<?php echo price2num($obj_facturation->prix(), 'MU'); ?>" onchange="javascript: modif();" disabled /></td>
+				<td><input class="texte1_off maxwidth50onsmartphone" type="text" name="txtPrixUnit" value="<?php echo price2num($obj_facturation->prix(), 'MU'); ?>" onchange="javascript: modif();" disabled /></td>
 				<td></td>
     			<!-- Choix de la remise -->
-    			<td><input class="texte1" type="text" id="txtRemise" name="txtRemise" value="0" onkeyup="javascript: modif();" onfocus="javascript: this.select();"/>
+    			<td><input class="texte1 maxwidth50onsmartphone" type="text" id="txtRemise" name="txtRemise" value="0" onkeyup="javascript: modif();" onfocus="javascript: this.select();"/>
 					<?php print genkeypad("txtRemise", "frmQte");?>
     			</td>
     			<!-- Affichage du total HT -->
-    			<td><input class="texte1_off" type="text" name="txtTotal" value="" disabled /></td><td></td>
+    			<td><input class="texte1_off maxwidth50onsmartphone" type="text" name="txtTotal" value="" disabled /></td><td></td>
                 <!-- Choix du taux de TVA -->
                 <td class="select_tva">
                 <?php //var_dump($tab_tva); ?>
@@ -155,17 +155,17 @@ $langs->load("cashdesk");
 	<input type="hidden" name="hdnChoix" value="" />
 	<input type="hidden" name="token" value="<?php echo $_SESSION['newtoken']; ?>" />
 <fieldset class="cadre_facturation"><legend class="titre1"><?php echo $langs->trans("Amount"); ?></legend>
-		<table>
+		<table class="centpercent">
 			<tr><th class="label1"><?php echo $langs->trans("TotalTicket"); ?></th><th class="label1"><?php echo $langs->trans("Received"); ?></th><th class="label1"><?php echo $langs->trans("Change"); ?></th></tr>
 			<tr>
 			<!-- Affichage du montant du -->
-			<td><input class="texte2_off" type="text" name="txtDu" value="<?php echo price2num($obj_facturation->prixTotalTtc(), 'MT'); ?>" disabled /></td>
+			<td><input class="texte2_off maxwidthonsmartphone" type="text" name="txtDu" value="<?php echo price2num($obj_facturation->prixTotalTtc(), 'MT'); ?>" disabled /></td>
 			<!-- Choix du montant encaisse -->
-			<td><input class="texte2" type="text" id="txtEncaisse" name="txtEncaisse" value="" onkeyup="javascript: verifDifference();" onfocus="javascript: this.select();" />
+			<td><input class="texte2 maxwidthonsmartphone" type="text" id="txtEncaisse" name="txtEncaisse" value="" onkeyup="javascript: verifDifference();" onfocus="javascript: this.select();" />
 <?php print genkeypad("txtEncaisse", "frmDifference");?>
 			</td>
 			<!-- Affichage du montant rendu -->
-			<td><input class="texte2_off" type="text" name="txtRendu" value="0" disabled /></td>
+			<td><input class="texte2_off maxwidthonsmartphone" type="text" name="txtRendu" value="0" disabled /></td>
 			</tr>
 			<tr>
 		</table>

+ 5 - 1
htdocs/cashdesk/tpl/validation2.tpl.php

@@ -22,9 +22,10 @@ $langs->load("bills");
 
 ?>
 
-<h3 class="titre1"><?php echo $langs->trans("SellFinished"); ?></h3><br>
+<div class="blocksellfinished">
 
 <div class="cadre_facturation">
+<h3 class="titre1"><?php echo $langs->trans("SellFinished"); ?></h3><br>
 
 <script type="text/javascript">
 
@@ -45,3 +46,6 @@ $langs->load("bills");
 <p><a class="lien1" href="#" onclick="Javascript: popupTicket(); return(false);"><?php echo $langs->trans("PrintTicket"); ?></a></p>
 
 </div>
+</div>
+<br>
+

+ 2 - 2
htdocs/comm/action/pertype.php

@@ -656,7 +656,7 @@ foreach ($typeofevents as $typeofevent)
 		if ($todayarray['mday']==$tmpday && $todayarray['mon']==$tmpmonth && $todayarray['year']==$tmpyear) $today=1;
 		if ($today) $style='cal_today_peruser';
 
-		show_day_events2($username, $tmpday, $tmpmonth, $tmpyear, $monthshown, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, $showheader, $colorsbytype, $var);
+		show_day_events_pertype($username, $tmpday, $tmpmonth, $tmpyear, $monthshown, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, $showheader, $colorsbytype, $var);
 
 		$i++;
 	}
@@ -756,7 +756,7 @@ $db->close();
  * @param	bool	$var			true or false for alternat style on tr/td
  * @return	void
  */
-function show_day_events2($username, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint=0, $maxnbofchar=16, $newparam='', $showinfo=0, $minheight=60, $showheader=false, $colorsbytype=array(), $var=false)
+function show_day_events_pertype($username, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint=0, $maxnbofchar=16, $newparam='', $showinfo=0, $minheight=60, $showheader=false, $colorsbytype=array(), $var=false)
 {
 	global $db;
 	global $user, $conf, $langs, $hookmanager, $action;

+ 1 - 1
htdocs/commande/card.php

@@ -223,7 +223,7 @@ if (empty($reshook))
 		}
 	}
 
-	// Categorisation dans projet
+	// Link to a project
 	else if ($action == 'classin' && $user->rights->commande->creer)
 	{
 		$object->setProject(GETPOST('projectid'));

+ 0 - 82
htdocs/compta/paiement/class/cpaiement.class.php

@@ -39,10 +39,6 @@ class Cpaiement
 	 */
 	public $table_element = 'c_paiement';
 
-	/**
-	 * @var CpaiementLine[] Lines
-	 */
-	public $lines = array();
 
 	/**
 	 */
@@ -227,84 +223,6 @@ class Cpaiement
 		}
 	}
 
-	/**
-	 * Load object in memory from the database
-	 *
-	 * @param string $sortorder Sort Order
-	 * @param string $sortfield Sort field
-	 * @param int    $limit     offset limit
-	 * @param int    $offset    offset limit
-	 * @param array  $filter    filter array
-	 * @param string $filtermode filter mode (AND or OR)
-	 *
-	 * @return int <0 if KO, >0 if OK
-	 */
-	public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND')
-	{
-		dol_syslog(__METHOD__, LOG_DEBUG);
-
-		$sql = 'SELECT';
-		$sql .= ' t.id,';
-		$sql .= " t.code,";
-		$sql .= " t.libelle,";
-		$sql .= " t.type,";
-		$sql .= " t.active,";
-		$sql .= " t.accountancy_code,";
-		$sql .= " t.module";
-
-		
-		$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
-
-		// Manage filter
-		$sqlwhere = array();
-		if (count($filter) > 0) {
-			foreach ($filter as $key => $value) {
-				$sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
-			}
-		}
-		if (count($sqlwhere) > 0) {
-			$sql .= ' WHERE ' . implode(' '.$filtermode.' ', $sqlwhere);
-		}
-		
-		if (!empty($sortfield)) {
-			$sql .= $this->db->order($sortfield,$sortorder);
-		}
-		if (!empty($limit)) {
-		 $sql .=  ' ' . $this->db->plimit($limit + 1, $offset);
-		}
-		$this->lines = array();
-
-		$resql = $this->db->query($sql);
-		if ($resql) {
-			$num = $this->db->num_rows($resql);
-
-			while ($obj = $this->db->fetch_object($resql)) {
-				$line = new CpaiementLine();
-
-				$line->id = $obj->id;
-				
-				$line->code = $obj->code;
-				$line->libelle = $obj->libelle;
-				$line->type = $obj->type;
-				$line->active = $obj->active;
-				$line->accountancy_code = $obj->accountancy_code;
-				$line->module = $obj->module;
-
-				
-
-				$this->lines[$line->id] = $line;
-			}
-			$this->db->free($resql);
-
-			return $num;
-		} else {
-			$this->errors[] = 'Error ' . $this->db->lasterror();
-			dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
-
-			return - 1;
-		}
-	}
-
 	/**
 	 * Update object into database
 	 *

+ 0 - 82
htdocs/compta/sociales/class/cchargesociales.class.php

@@ -43,11 +43,6 @@ class Cchargesociales
 	 */
 	public $table_element = 'c_chargesociales';
 
-	/**
-	 * @var CchargesocialesLine[] Lines
-	 */
-	public $lines = array();
-
 	/**
 	 */
 	
@@ -237,83 +232,6 @@ class Cchargesociales
 		}
 	}
 
-	/**
-	 * Load object in memory from the database
-	 *
-	 * @param string $sortorder Sort Order
-	 * @param string $sortfield Sort field
-	 * @param int    $limit     offset limit
-	 * @param int    $offset    offset limit
-	 * @param array  $filter    filter array
-	 * @param string $filtermode filter mode (AND or OR)
-	 *
-	 * @return int <0 if KO, >0 if OK
-	 */
-	public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND')
-	{
-		dol_syslog(__METHOD__, LOG_DEBUG);
-
-		$sql = 'SELECT';
-		$sql .= " t.id,";
-		$sql .= " t.libelle,";
-		$sql .= " t.deductible,";
-		$sql .= " t.active,";
-		$sql .= " t.code,";
-		$sql .= " t.fk_pays,";
-		$sql .= " t.module,";
-		$sql .= " t.accountancy_code";
-
-		
-		$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
-
-		// Manage filter
-		$sqlwhere = array();
-		if (count($filter) > 0) {
-			foreach ($filter as $key => $value) {
-				$sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
-			}
-		}
-		if (count($sqlwhere) > 0) {
-			$sql .= ' WHERE ' . implode(' '.$filtermode.' ', $sqlwhere);
-		}
-		
-		if (!empty($sortfield)) {
-			$sql .= $this->db->order($sortfield,$sortorder);
-		}
-		if (!empty($limit)) {
-		 $sql .=  ' ' . $this->db->plimit($limit + 1, $offset);
-		}
-		$this->lines = array();
-
-		$resql = $this->db->query($sql);
-		if ($resql) {
-			$num = $this->db->num_rows($resql);
-
-			while ($obj = $this->db->fetch_object($resql)) {
-				$line = new CchargesocialesLine();
-
-				$line->id = $obj->id;
-				$line->libelle = $obj->libelle;
-				$line->deductible = $obj->deductible;
-				$line->active = $obj->active;
-				$line->code = $obj->code;
-				$line->fk_pays = $obj->fk_pays;
-				$line->module = $obj->module;
-				$line->accountancy_code = $obj->accountancy_code;
-
-				$this->lines[$line->id] = $line;
-			}
-			$this->db->free($resql);
-
-			return $num;
-		} else {
-			$this->errors[] = 'Error ' . $this->db->lasterror();
-			dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
-
-			return - 1;
-		}
-	}
-
 	/**
 	 * Update object into database
 	 *

+ 8 - 2
htdocs/core/actions_linkedfiles.inc.php

@@ -18,10 +18,12 @@
  * or see http://www.gnu.org/
  */
 
-
 // Variable $upload_dir must be defined when entering here
 // Variable $upload_dirold may also exists.
 
+//var_dump($upload_dir);
+//var_dump($upload_dirold);
+
 // Submit file/link
 if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
 {
@@ -165,7 +167,11 @@ elseif ($action == 'renamefile' && GETPOST('renamefilesave'))
                     
                     setEventMessages($langs->trans("FileRenamed"), null);
                 }
-                else setEventMessages($langs->trans("ErrorFailToRenameFile", $filenamefrom, $filenameto), null, 'errors');
+                else 
+                {
+                    $langs->load("errors"); // key must be loaded because we can't rely on loading during output, we need var substitution to be done now.
+                    setEventMessages($langs->trans("ErrorFailToRenameFile", $filenamefrom, $filenameto), null, 'errors');
+                }
             }
         }
     }

+ 84 - 75
htdocs/core/class/commonobject.class.php

@@ -1929,7 +1929,10 @@ abstract class CommonObject
 	 */
 	function updateRangOfLine($rowid,$rang)
 	{
-		$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET rang  = '.$rang;
+	    $fieldposition = 'rang';
+	    if ($this->table_element_line == 'ecm_files') $fieldposition = 'position';
+	    
+		$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang;
 		$sql.= ' WHERE rowid = '.$rowid;
 
 		dol_syslog(get_class($this)."::updateRangOfLine", LOG_DEBUG);
@@ -3296,84 +3299,90 @@ abstract class CommonObject
 		$usemargins=0;
 		if (! empty($conf->margin->enabled) && ! empty($this->element) && in_array($this->element,array('facture','propal','commande'))) $usemargins=1;
 
-		print '<tr class="liste_titre nodrag nodrop">';
-
-		if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print '<td class="linecolnum" align="center" width="5">&nbsp;</td>';
-
-		// Description
-		print '<td class="linecoldescription">'.$langs->trans('Description').'</td>';
-
-		if ($this->element == 'supplier_proposal')
-		{
-			print '<td class="linerefsupplier" align="right"><span id="title_fourn_ref">'.$langs->trans("SupplierProposalRefFourn").'</span></td>';
-		}
-
-		// VAT
-		print '<td class="linecolvat" align="right" width="80">'.$langs->trans('VAT').'</td>';
-
-		// Price HT
-		print '<td class="linecoluht" align="right" width="80">'.$langs->trans('PriceUHT').'</td>';
-
-		// Multicurrency
-		if (!empty($conf->multicurrency->enabled)) print '<td class="linecoluht_currency" align="right" width="80">'.$langs->trans('PriceUHTCurrency', $this->multicurrency_code).'</td>';
-
-		if ($inputalsopricewithtax) print '<td align="right" width="80">'.$langs->trans('PriceUTTC').'</td>';
-
-		// Qty
-		print '<td class="linecolqty" align="right">'.$langs->trans('Qty').'</td>';
-
-		if($conf->global->PRODUCT_USE_UNITS)
-		{
-			print '<td class="linecoluseunit" align="left">'.$langs->trans('Unit').'</td>';
-		}
-
-		// Reduction short
-		print '<td class="linecoldiscount" align="right">'.$langs->trans('ReductionShort').'</td>';
-
-		if ($this->situation_cycle_ref) {
-			print '<td class="linecolcycleref" align="right">' . $langs->trans('Progress') . '</td>';
-		}
-
-		if ($usemargins && ! empty($conf->margin->enabled) && empty($user->societe_id))
-		{
-			if (!empty($user->rights->margins->creer))
-			{
-				if ($conf->global->MARGIN_TYPE == "1")
-					print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('BuyingPrice').'</td>';
-				else
-					print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('CostPrice').'</td>';	
-			}
-			
-			if (! empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous)
-				print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarginRate').'</td>';
-			if (! empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous)
-				print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarkRate').'</td>';
-		}
-
-		// Total HT
-		print '<td class="linecolht" align="right">'.$langs->trans('TotalHTShort').'</td>';
-
-		// Multicurrency
-		if (!empty($conf->multicurrency->enabled)) print '<td class="linecoltotalht_currency" align="right">'.$langs->trans('TotalHTShortCurrency', $this->multicurrency_code).'</td>';
-
-        if ($outputalsopricetotalwithtax) print '<td align="right" width="80">'.$langs->trans('TotalTTCShort').'</td>';
-
-		print '<td class="linecoledit"></td>';  // No width to allow autodim
-
-		print '<td class="linecoldelete" width="10"></td>';
-
-		print '<td class="linecolmove" width="10"></td>';
-
-		print "</tr>\n";
-
 		$num = count($this->lines);
-		$var = true;
-		$i	 = 0;
-
+		
 		//Line extrafield
 		require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
 		$extrafieldsline = new ExtraFields($this->db);
 		$extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line);
+		
+		$parameters = array('num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline);
+		$reshook = $hookmanager->executeHooks('printObjectLineTitle', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
+		if (empty($reshook))
+		{
+    		print '<tr class="liste_titre nodrag nodrop">';
+    
+    		if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print '<td class="linecolnum" align="center" width="5">&nbsp;</td>';
+    
+    		// Description
+    		print '<td class="linecoldescription">'.$langs->trans('Description').'</td>';
+    
+    		if ($this->element == 'supplier_proposal')
+    		{
+    			print '<td class="linerefsupplier" align="right"><span id="title_fourn_ref">'.$langs->trans("SupplierProposalRefFourn").'</span></td>';
+    		}
+    
+    		// VAT
+    		print '<td class="linecolvat" align="right" width="80">'.$langs->trans('VAT').'</td>';
+    
+    		// Price HT
+    		print '<td class="linecoluht" align="right" width="80">'.$langs->trans('PriceUHT').'</td>';
+    
+    		// Multicurrency
+    		if (!empty($conf->multicurrency->enabled)) print '<td class="linecoluht_currency" align="right" width="80">'.$langs->trans('PriceUHTCurrency', $this->multicurrency_code).'</td>';
+    
+    		if ($inputalsopricewithtax) print '<td align="right" width="80">'.$langs->trans('PriceUTTC').'</td>';
+    
+    		// Qty
+    		print '<td class="linecolqty" align="right">'.$langs->trans('Qty').'</td>';
+    
+    		if($conf->global->PRODUCT_USE_UNITS)
+    		{
+    			print '<td class="linecoluseunit" align="left">'.$langs->trans('Unit').'</td>';
+    		}
+    
+    		// Reduction short
+    		print '<td class="linecoldiscount" align="right">'.$langs->trans('ReductionShort').'</td>';
+    
+    		if ($this->situation_cycle_ref) {
+    			print '<td class="linecolcycleref" align="right">' . $langs->trans('Progress') . '</td>';
+    		}
+    
+    		if ($usemargins && ! empty($conf->margin->enabled) && empty($user->societe_id))
+    		{
+    			if (!empty($user->rights->margins->creer))
+    			{
+    				if ($conf->global->MARGIN_TYPE == "1")
+    					print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('BuyingPrice').'</td>';
+    				else
+    					print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('CostPrice').'</td>';	
+    			}
+    			
+    			if (! empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous)
+    				print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarginRate').'</td>';
+    			if (! empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous)
+    				print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarkRate').'</td>';
+    		}
+    
+    		// Total HT
+    		print '<td class="linecolht" align="right">'.$langs->trans('TotalHTShort').'</td>';
+    
+    		// Multicurrency
+    		if (!empty($conf->multicurrency->enabled)) print '<td class="linecoltotalht_currency" align="right">'.$langs->trans('TotalHTShortCurrency', $this->multicurrency_code).'</td>';
+    
+            if ($outputalsopricetotalwithtax) print '<td align="right" width="80">'.$langs->trans('TotalTTCShort').'</td>';
+    
+    		print '<td class="linecoledit"></td>';  // No width to allow autodim
+    
+    		print '<td class="linecoldelete" width="10"></td>';
+    
+    		print '<td class="linecolmove" width="10"></td>';
+    
+    		print "</tr>\n";
+		}
+		
+		$var = true;
+		$i	 = 0;
 
 		foreach ($this->lines as $line)
 		{
@@ -3392,7 +3401,7 @@ abstract class CommonObject
 				}
 				else
 				{
-					$parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline);
+					$parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline, 'fk_parent_line'=>$line->fk_parent_line);
                     $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action);    // Note that $action and $object may have been modified by some hooks
 				}
 			}

+ 3 - 2
htdocs/core/class/hookmanager.class.php

@@ -116,8 +116,8 @@ class HookManager
      * 	    @param		array	$parameters		Array of parameters
      * 		@param		Object	$object			Object to use hooks on
      * 	    @param		string	$action			Action code on calling page ('create', 'edit', 'view', 'add', 'update', 'delete'...)
-     * 		@return		mixed					For 'addreplace hooks (doActions,formObjectOptions,pdf_xxx,...):  					Return 0 if we want to keep standard actions, >0 if we want to stop standard actions, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results and set into ->resArray.
-     * 											For 'output' hooks (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...):	Return 0, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results and set into ->resArray.
+     * 		@return		mixed					For 'addreplace' hooks (doActions,formObjectOptions,pdf_xxx,...):  					Return 0 if we want to keep standard actions, >0 if we want to stop standard actions, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results by hook and set into ->resArray for caller.
+     * 											For 'output' hooks (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...):	Return 0, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results bu hook and set into ->resArray for caller.
      *                                          All types can also return some values into an array ->results.
      * 											$this->error or this->errors are also defined by class called by this function if error.
      */
@@ -142,6 +142,7 @@ class HookManager
 				'formObjectOptions',
 				'formattachOptions',
 				'formBuilddocLineOptions',
+			    'formatNotificationMessage',
 			    'getFormMail',
 			    'getIdProfUrl',
 				'moveUploadedFile',

+ 163 - 33
htdocs/core/class/html.formfile.class.php

@@ -856,38 +856,62 @@ class FormFile
 
 
     /**
-     *  Show list of documents in a directory
+     *  Show list of documents in $filearray (may be they are all in same directory but may not)
      *
-     *  @param	 array	$filearray          Array of files loaded by dol_dir_list('files') function before calling this
-     * 	@param	 Object	$object				Object on which document is linked to
-     * 	@param	 string	$modulepart			Value for modulepart used by download or viewimage wrapper
+     *  @param	 array	$filearray          Array of files loaded by dol_dir_list('files') function before calling this.
+     * 	@param	 Object	$object				Object on which document is linked to.
+     * 	@param	 string	$modulepart			Value for modulepart used by download or viewimage wrapper.
      * 	@param	 string	$param				Parameters on sort links (param must start with &, example &aaa=bbb&ccc=ddd)
-     * 	@param	 int	$forcedownload		Force to open dialog box "Save As" when clicking on file
-     * 	@param	 string	$relativepath		Relative path of docs (autodefined if not provided)
+     * 	@param	 int	$forcedownload		Force to open dialog box "Save As" when clicking on file.
+     * 	@param	 string	$relativepath		Relative path of docs (autodefined if not provided), relative to module dir, not to MAIN_DATA_ROOT.
      * 	@param	 int	$permonobject		Permission on object (so permission to delete or crop document)
      * 	@param	 int	$useinecm			Change output for use in ecm module
      * 	@param	 string	$textifempty		Text to show if filearray is empty ('NoFileFound' if not defined)
-     *  @param   int	$maxlength          Maximum length of file name shown
+     *  @param   int	$maxlength          Maximum length of file name shown.
      *  @param	 string	$title				Title before list
      *  @param	 string $url				Full url to use for click links ('' = autodetect)
 	 *  @param	 int	$showrelpart		0=Show only filename (default), 1=Show first level 1 dir
-	 *  @param   int    $permtoeditline     Permission to edit document line (-1 is deprecated)
+	 *  @param   int    $permtoeditline     Permission to edit document line (You must provide a value, -1 is deprecated and must not be used any more)
+     *  @param   string $upload_dir         Full path directory so we can know dir relative to MAIN_DATA_ROOT. Fill this if you want to complete file data with database indexes.
+     *  @param   string $sortfield          Sort field ('name', 'size', 'position', ...)
+     *  @param   string $sortorder          Sort order ('ASC' or 'DESC')
+     *  @param   int    $disablemove        1=Disable move button, 0=Position move is possible.
      * 	@return	 int						<0 if KO, nb of files shown if OK
      */
-	function list_of_documents($filearray,$object,$modulepart,$param='',$forcedownload=0,$relativepath='',$permonobject=1,$useinecm=0,$textifempty='',$maxlength=0,$title='',$url='', $showrelpart=0, $permtoeditline=-1)
+	function list_of_documents($filearray,$object,$modulepart,$param='',$forcedownload=0,$relativepath='',$permonobject=1,$useinecm=0,$textifempty='',$maxlength=0,$title='',$url='', $showrelpart=0, $permtoeditline=-1,$upload_dir='',$sortfield='',$sortorder='ASC', $disablemove=1)
 	{
 		global $user, $conf, $langs, $hookmanager;
-		global $bc;
+		global $bc,$bcdd;
 		global $sortfield, $sortorder, $maxheightmini;
 
-		$hookmanager->initHooks(array('formfile'));
+		// Define relative path used to store the file
+		if (empty($relativepath))
+		{
+		    $relativepath=(! empty($object->ref)?dol_sanitizeFileName($object->ref):'').'/';
+		    if ($object->element == 'invoice_supplier') $relativepath=get_exdir($object->id,2,0,0,$object,'invoice_supplier').$relativepath;	// TODO Call using a defined value for $relativepath
+		    if ($object->element == 'project_task') $relativepath='Call_not_supported_._Call_function_using_a_defined_relative_path_.';
+		}
+		// For backward compatiblity, we detect file is stored into an old path
+		if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO) && $file['level1name'] == 'photos')
+		{
+		    $relativepath=preg_replace('/^.*\/produit\//','',$file['path']).'/';
+		}
+		// Defined relative dir to DOL_DATA_ROOT
+		$relativedir = '';
+		if ($upload_dir)
+		{
+    		$relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir);
+    		$relativedir = preg_replace('/^[\\/]/','',$relativedir); 
+		}
 
+		$hookmanager->initHooks(array('formfile'));
 		$parameters=array(
 				'filearray' => $filearray,
 				'modulepart'=> $modulepart,
 				'param' => $param,
 				'forcedownload' => $forcedownload,
-				'relativepath' => $relativepath,
+				'relativepath' => $relativepath,    // relative filename to module dir
+				'relativedir' => $relativedir,      // relative dirname to DOL_DATA_ROOT
 				'permtodelete' => $permonobject,
 				'useinecm' => $useinecm,
 				'textifempty' => $textifempty,
@@ -932,45 +956,119 @@ class FormFile
 			    print '<input type="hidden" name="id" value="'.$object->id.'">';
 			    print '<input type="hidden" name="modulepart" value="'.$modulepart.'">';
 			}
-			print '<table width="100%" class="'.($useinecm?'liste noborderbottom':'liste').'">'."\n";
+			print '<table width="100%" id="tablelines" class="'.($useinecm?'liste noborderbottom':'liste').'">'."\n";
 			
-			print '<tr class="liste_titre">';
+			print '<tr class="liste_titre nodrag nodrop">';
 			print_liste_field_titre($langs->trans("Documents2"),$url,"name","",$param,'align="left"',$sortfield,$sortorder);
 			print_liste_field_titre($langs->trans("Size"),$url,"size","",$param,'align="right"',$sortfield,$sortorder);
 			print_liste_field_titre($langs->trans("Date"),$url,"date","",$param,'align="center"',$sortfield,$sortorder);
 			if (empty($useinecm)) print_liste_field_titre('',$url,"","",$param,'align="center"');
 			print_liste_field_titre('');
+			if (! $disablemove) print_liste_field_titre('');
 			print "</tr>\n";
 
+			// Get list of files stored into database for same relative directory
+			if ($relativedir)
+			{
+                $filearrayindatabase = dol_dir_list_in_database($relativedir, '', null, 'name', SORT_ASC);
+    
+                //var_dump($filearray);
+                //var_dump($filearrayindatabase);
+                
+                // Complete filearray with properties found into $filearrayindatabase
+    			foreach($filearray as $key => $val)
+    			{
+    			    $found=0;
+    			    // Search if it exists into $filearrayindatabase
+    			    foreach($filearrayindatabase as $key2 => $val2)
+    			    {
+    			        if ($filearrayindatabase[$key2]['name'] == $filearray[$key]['name'])
+    			        {
+    			            $filearray[$key]['position_name']=($filearrayindatabase[$key2]['position']?$filearrayindatabase[$key2]['position']:'0').'_'.$filearrayindatabase[$key2]['name'];
+    			            $filearray[$key]['position']=$filearrayindatabase[$key2]['position'];
+    			            $filearray[$key]['cover']=$filearrayindatabase[$key2]['cover'];
+    			            $filearray[$key]['acl']=$filearrayindatabase[$key2]['acl'];
+    			            $filearray[$key]['rowid']=$filearrayindatabase[$key2]['rowid'];
+    			            $filearray[$key]['label']=$filearrayindatabase[$key2]['label'];
+    			            $found=1;
+    			            break;
+    			        }
+    			    }
+    			    
+    			    if (! $found)    // This happen in transition towerd version 6, or if files were added manually into os dir.
+    			    {
+    			        $filearray[$key]['position']='999999';     // File not indexed are at end. So if we add a file, it will not replace an existing position
+    			        $filearray[$key]['cover']=0;
+    			        $filearray[$key]['acl']='';
+
+    			        $rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $filearray[$key]['fullname']);
+    			        if (! preg_match('/(\/temp\/|\/thumbs|\.meta$)/', $rel_filetorenameafter))     // If not a tmp file
+    			        {
+        			        dol_syslog("list_of_documents We found a file called '".$filearray[$key]['name']."' not indexed into database. We add it");
+        			        include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
+        			        $ecmfile=new EcmFiles($this->db);
+        			        	
+        			        // Add entry into database
+        			        $filename = basename($rel_filename);
+        			        $rel_dir = dirname($rel_filename);
+        			        $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
+        			        $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
+        			         
+        			        $ecmfile->filepath = $rel_dir;
+        			        $ecmfile->filename = $filename;
+        			        $ecmfile->label = md5_file(dol_osencode($filearray[$key]['fullname']));        // $destfile is a full path to file
+        			        $ecmfile->fullpath_orig = $filearray[$key]['fullname'];
+        			        $ecmfile->gen_or_uploaded = 'unknown';
+        			        $ecmfile->description = '';    // indexed content
+        			        $ecmfile->keyword = '';        // keyword content
+        			        $result = $ecmfile->create($user);
+        			        if ($result < 0)
+        			        {
+        			            setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
+        			        }
+    			            else
+    			            {
+    			                $filearray[$key]['rowid']=$result;
+    			            }
+    			        }
+    			        else
+    			        {
+    			            $filearray[$key]['rowid']=0;     // Should not happened
+    			        }
+    			    }
+    			}
+    
+    			/*var_dump($filearray);
+    			var_dump($sortfield);
+    			var_dump($sortorder);*/
+    			 
+    			if ($sortfield && $sortorder)
+    			{
+        			$filearray=dol_sort_array($filearray, $sortfield, $sortorder);
+    			}
+    			//var_dump($filearray);
+			}
+			
 			$nboffiles=count($filearray);
-
 			if ($nboffiles > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
-
-			$var=true;
+				
+			$var=true; $i=0; $nboflines = 0; $lastrowid=0;
 			foreach($filearray as $key => $file)      // filearray must be only files here
 			{
 				if ($file['name'] != '.'
 						&& $file['name'] != '..'
 						&& ! preg_match('/\.meta$/i',$file['name']))
 				{
-					// Define relative path used to store the file
-					if (empty($relativepath))
-					{
-						$relativepath=(! empty($object->ref)?dol_sanitizeFileName($object->ref):'').'/';
-						if ($object->element == 'invoice_supplier') $relativepath=get_exdir($object->id,2,0,0,$object,'invoice_supplier').$relativepath;	// TODO Call using a defined value for $relativepath
-						if ($object->element == 'project_task') $relativepath='Call_not_supported_._Call_function_using_a_defined_relative_path_.';
-					}
-					// For backward compatiblity, we detect file is stored into an old path
-					if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO) && $file['level1name'] == 'photos')
-	                {
-	                    $relativepath=preg_replace('/^.*\/produit\//','',$file['path']).'/';
-	                }
 					$var=!$var;
 					
-					$editline=0;
+					if ($filearray[$key]['rowid'] > 0) $lastrowid = $filearray[$key]['rowid'];
 					
-			        print '<!-- Line list_of_documents '.$key.' -->'."\n";
-					print '<tr '.$bc[$var].'>';
+					$editline=0;
+					$nboflines++;
+			        print '<!-- Line list_of_documents '.$key.' relativepath = '.$relativepath.' -->'."\n";
+			        // Do we have entry into database ?
+			        print '<!-- In database: position='.$filearray[$key]['position'].' -->'."\n";
+					print '<tr id="row-'.($filearray[$key]['rowid']>0?$filearray[$key]['rowid']:'-AFTER'.$lastrowid.'POS'.($i+1)).'" '.$bcdd[$var].'>';
 					print '<td class="tdoverflow">';
 					
 					//print "XX".$file['name'];	//$file['name'] must be utf8
@@ -1074,6 +1172,24 @@ class FormFile
     						print '<a href="'.(($useinecm && $useajax)?'#':$url.'?action=delete&urlfile='.urlencode($filepath).$param).'" class="deletefilelink" rel="'.$filepath.'">'.img_delete().'</a>';
     					}
 					    print "</td>";
+
+					    if (empty($disablemove))
+					    {
+    					    if ($nboffiles > 1 && empty($conf->browser->phone)) { 
+    					    	print '<td align="center" class="linecolmove tdlineupdown">'; 
+    					    	if ($i > 0) {
+    					    		print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=up&amp;rowid='.$line->id.'">'.img_up('default',0,'imgupforline').'</a>';
+    					    	}
+    					        if ($i < $nboffiles-1) {
+    					    		print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=down&amp;rowid='.$line->id.'">'.img_down('default',0,'imgdownforline').'</a>';
+    				    		}
+    					    	print '</td>';
+    					    }
+    					    else {
+    					       	print '<td align="center"'.((empty($conf->browser->phone) && empty($disablemove)) ?' class="linecolmove tdlineupdown"':' class="linecolmove"').'>';
+    					       	print '</td>';
+    					    }
+					   }
 					}
 					else
 					{
@@ -1081,18 +1197,32 @@ class FormFile
 					    print '<input type="submit" class="button" name="renamefilesave" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
 					    print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
 					    print '</td>';
+					    if (empty($disablemove)) print '<td class="right"></td>';
 					}
 					print "</tr>\n";
+					
+					$i++;
 				}
 			}
 			if ($nboffiles == 0)
 			{
-				print '<tr '.$bc[false].'><td colspan="'.(empty($useinecm)?'5':'5').'" class="opacitymedium">';
+			    $colspan=(empty($useinecm)?'5':'5');
+			    if (empty($disablemove)) $colspan++;
+				print '<tr '.$bc[false].'><td colspan="'.$colspan.'" class="opacitymedium">';
 				if (empty($textifempty)) print $langs->trans("NoFileFound");
 				else print $textifempty;
 				print '</td></tr>';
 			}
 			print "</table>";
+			
+			
+			if (! $editline && $nboflines > 1) { 
+				if (! empty($conf->use_javascript_ajax) && $permtoeditline) {
+				    $table_element_line = 'ecm_files';
+				    include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
+				}
+			}				
+			
 			if (GETPOST('action') == 'editfile' && $permtoeditline)
 			{
 			    print '</form>';

+ 5 - 2
htdocs/core/class/html.formprojet.class.php

@@ -79,7 +79,7 @@ class FormProjets
 				$project->fetch($selected);
 				$selected_input_value=$project->ref;
 			}
-			$urloption='socid='.$socid.'&htmlname='.$htmlname;
+			$urloption='socid='.$socid.'&htmlname='.$htmlname.'&discardclosed='.$discard_closed;
 			$out.=ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/projet/ajax/projects.php', $urloption, $conf->global->PROJECT_USE_SEARCH_TO_SELECT, 0, array(
 //				'update' => array(
 //					'projectid' => 'id'
@@ -458,13 +458,16 @@ class FormProjets
 		if ($table_element == 'projet_task') return '';		// Special cas of element we never link to a project (already always done)
 
 		$linkedtothirdparty=false;
-		if (! in_array($table_element, array('don','expensereport_det','expensereport'))) $linkedtothirdparty=true;
+		if (! in_array($table_element, array('don','expensereport_det','expensereport','loan'))) $linkedtothirdparty=true;
 
 		$sqlfilter='';
 		$projectkey="fk_projet";
 		//print $table_element;
 		switch ($table_element)
 		{
+			case "loan":
+				$sql = "SELECT t.rowid, t.label as ref";
+				break;
 			case "facture":
 				$sql = "SELECT t.rowid, t.facnumber as ref";
 				break;

+ 35 - 22
htdocs/core/class/notify.class.php

@@ -278,12 +278,20 @@ class Notify
      */
     function send($notifcode, $object)
     {
-        global $user,$conf,$langs,$mysoc,$dolibarr_main_url_root;
+        global $user,$conf,$langs,$mysoc;
+        global $hookmanager;
+        global $dolibarr_main_url_root;
 
 		if (! in_array($notifcode, $this->arrayofnotifsupported)) return 0;
 
 	    include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-		
+	    if (! is_object($hookmanager))
+	    {
+	        include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
+	        $hookmanager=new HookManager($this->db);
+	    }
+	    $hookmanager->initHooks(array('notification'));
+	    
 	    dol_syslog(get_class($this)."::send notifcode=".$notifcode.", object=".$object->id);
 
     	$langs->load("other");
@@ -294,8 +302,8 @@ class Notify
 		//$urlwithroot=DOL_MAIN_URL_ROOT;						// This is to use same domain name than current
 
 		// Define some vars
-	    $application = $mysoc->name;
-	    //if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $application = $conf->global->MAIN_APPLICATION_TITLE;
+	    $application = 'Dolibarr';
+	    if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $application = $conf->global->MAIN_APPLICATION_TITLE;
 	    $replyto = $conf->notification->email_from;
 	    $filename = basename($file);
         $mimefile = dol_mimetype($file);
@@ -321,18 +329,7 @@ class Notify
 
 		// Check notification per user
         $sql.= "\nUNION\n";
-        /*
-		$sql.= "SELECT  1 as user, c.email, c.rowid as cid, c.lastname, c.firstname, '$langs->defaultlang' as default_lang,";
-		$sql.= " a.rowid as adid, a.label, a.code, n.rowid, n.type";
-        $sql.= " FROM ".MAIN_DB_PREFIX."user as c,";
-        $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
-        $sql.= " ".MAIN_DB_PREFIX."notify_def as n,";
-        $sql.= " ".MAIN_DB_PREFIX."element_contact as ec";
-        $sql.= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action";
-        $sql.= " AND n.fk_user = ec.fk_socpeople";
-        if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode;	// Old usage
-        else $sql.= " AND a.code = '".$notifcode."'";	// New usage
-        $sql .= " AND ec.element_id = ".$object->id;*/
+
         $sql.= "SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,";
         $sql.= " a.rowid as adid, a.label, a.code, n.rowid, n.type";
         $sql.= " FROM ".MAIN_DB_PREFIX."user as c,";
@@ -367,6 +364,8 @@ class Notify
 	                		$outputlangs->setDefaultLang($obj->default_lang);
 	                	}
 
+	                	$subject = '['.$mysoc->name.'] '.$outputlangs->transnoentitiesnoconv("DolibarrNotification");
+	                	
 	                    switch ($notifcode) {
 							case 'BILL_VALIDATE':
 								$link='/compta/facture.php?facid='.$object->id;
@@ -446,14 +445,20 @@ class Notify
 							$filepdf = $pdf_path;
 						}
 
-	    				$subject = '['.$application.'] '.$outputlangs->transnoentitiesnoconv("DolibarrNotification");
-
 	                	$message = $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n";
 	                	$message.= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n";
 	                	$message.= "\n";
 	                    $message.= $mesg;
 	                    if ($link) $message=dol_concatdesc($message,$urlwithroot.$link);
 
+	                    $parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$file, 'mimefile'=>$mimefile, 'filename'=>$filename);
+	                    $reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
+	                    if (empty($reshook))
+	                    {
+	                        if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject'];
+	                        if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message'];
+	                    }
+	                     
 	                    $mailfile = new CMailFile(
 	                        $subject,
 	                        $sendto,
@@ -535,7 +540,9 @@ class Notify
 		        $link = '';
 		        $num++;
 
-				switch ($notifcode) {
+		        $subject = '['.$mysoc->name.'] '.$langs->transnoentitiesnoconv("DolibarrNotification");
+
+		        switch ($notifcode) {
 					case 'BILL_VALIDATE':
 						$link='/compta/facture.php?facid='.$object->id;
 						$dir_output = $conf->facture->dir_output;
@@ -622,8 +629,6 @@ class Notify
 					$filepdf = $pdf_path;
 				}
 
-		        $subject = '['.$application.'] '.$langs->transnoentitiesnoconv("DolibarrNotification");
-
 		        $message = $langs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n";
 		        $message.= $langs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n";
 		        $message.= "\n";
@@ -648,7 +653,15 @@ class Notify
 
 		        if ($sendto)
 		        {
-		        	$mailfile = new CMailFile(
+       		        $parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$file, 'mimefile'=>$mimefile, 'filename'=>$filename);
+			        $reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
+			        if (empty($reshook))
+			        {
+		    	        if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject'];
+		        	    if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message'];
+			        }
+		        
+		            $mailfile = new CMailFile(
 		        		$subject,
 		        		$sendto,
 		        		$replyto,

+ 233 - 34
htdocs/core/lib/files.lib.php

@@ -41,7 +41,7 @@ function dol_basename($pathfile)
  *  Scan a directory and return a list of files/directories.
  *  Content for string is UTF8 and dir separator is "/".
  *
- *  @param	string		$path        	Starting path from which to search
+ *  @param	string		$path        	Starting path from which to search. This is a full path.
  *  @param	string		$types        	Can be "directories", "files", or "all"
  *  @param	int			$recursive		Determines whether subdirectories are searched
  *  @param	string		$filter        	Regex filter to restrict list. This regex value must be escaped for '/', since this char is used for preg_match function
@@ -50,7 +50,8 @@ function dol_basename($pathfile)
  *  @param	string		$sortorder		Sort order (SORT_ASC, SORT_DESC)
  *	@param	int			$mode			0=Return array minimum keys loaded (faster), 1=Force all keys like date and size to be loaded (slower), 2=Force load of date only, 3=Force load of size only
  *  @param	int			$nohook			Disable all hooks
- *  @return	array						Array of array('name'=>'xxx','fullname'=>'/abc/xxx','date'=>'yyy','size'=>99,'type'=>'dir|file')
+ *  @return	array						Array of array('name'=>'xxx','fullname'=>'/abc/xxx','date'=>'yyy','size'=>99,'type'=>'dir|file',...)
+ *  @see dol_dir_list_indatabase
  */
 function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter="", $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=false)
 {
@@ -87,7 +88,7 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil
 	}
 
 	// $reshook may contain returns stacked by other modules
-	// $reshook is always empty with an array for can not lose returns stacked with other modules
+	// $reshook is always empty with an array to not lose returns stacked with other modules
 	// $hookmanager->resArray may contain array stacked by other modules
 	if (! $nohook && ! empty($hookmanager->resArray)) // forced to use $hookmanager->resArray even if $hookmanager->resArray['nodes'] is empty
 	{
@@ -205,6 +206,84 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil
 }
 
 
+/**
+ *  Scan a directory and return a list of files/directories.
+ *  Content for string is UTF8 and dir separator is "/".
+ *
+ *  @param	string		$path        	Starting path from which to search. Example: 'produit/MYPROD'
+ *  @param	string		$filter        	Regex filter to restrict list. This regex value must be escaped for '/', since this char is used for preg_match function
+ *  @param	array|null	$excludefilter  Array of Regex for exclude filter (example: array('(\.meta|_preview\.png)$','^\.'))
+ *  @param	string		$sortcriteria	Sort criteria ("","fullname","name","date","size")
+ *  @param	string		$sortorder		Sort order (SORT_ASC, SORT_DESC)
+ *	@param	int			$mode			0=Return array minimum keys loaded (faster), 1=Force all keys like description
+ *  @return	array						Array of array('name'=>'xxx','fullname'=>'/abc/xxx','type'=>'dir|file',...)
+ *  @see dol_dir_list
+ */
+function dol_dir_list_in_database($path, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0)
+{
+    global $conf, $db;
+    
+    $sql=" SELECT rowid, label, entity, filename, filepath, fullpath_orig, keywords, cover, gen_or_uploaded, extraparams, date_c, date_m, fk_user_c, fk_user_m, acl, position";
+    if ($mode) $sql.=", description";
+    $sql.=" FROM ".MAIN_DB_PREFIX."ecm_files";
+    $sql.=" WHERE filepath = '".$db->escape($path)."'";
+    $sql.=" AND entity = ".$conf->entity;
+
+    $resql = $db->query($sql);
+    if ($resql)
+    {
+        $file_list=array();
+        $num = $db->num_rows($resql);
+        $i = 0;
+        while ($i < $num)
+        {
+            $obj = $db->fetch_object($resql);            
+            if ($obj)
+            {
+                preg_match('/([^\/]+)\/[^\/]+$/',DOL_DATA_ROOT.'/'.$obj->filepath.'/'.$obj->filename,$reg);
+                $level1name=(isset($reg[1])?$reg[1]:'');
+                $file_list[] = array(
+                    "rowid" => $obj->rowid,
+                    "label" => $obj->label,         // md5
+    				"name" => $obj->filename,
+    				"path" => DOL_DATA_ROOT.'/'.$obj->filepath,
+                    "level1name" => $level1name,
+    				"fullname" => DOL_DATA_ROOT.'/'.$obj->filepath.'/'.$obj->filename,
+    				"fullpath_orig" => $obj->fullpath_orig,
+                    "date_c" => $db->jdate($obj->date_c),
+                    "date_m" => $db->jdate($obj->date_m),
+    				"type" => 'file',
+                    "keywords" => $obj->keywords,
+                    "cover" => $obj->cover,
+                    "position" => (int) $obj->position,
+                    "acl" => $obj->acl
+                );
+            }
+            $i++;
+        }
+        
+        // Obtain a list of columns
+        if (! empty($sortcriteria))
+        {
+            $myarray=array();
+            foreach ($file_list as $key => $row)
+            {
+                $myarray[$key] = (isset($row[$sortcriteria])?$row[$sortcriteria]:'');
+            }
+            // Sort the data
+            if ($sortorder) array_multisort($myarray, $sortorder, $file_list);
+        }
+        
+        return $file_list;
+    }
+    else
+    {
+        dol_print_error($db);
+        return array();
+    }
+}
+    
+
 /**
  * Fast compare of 2 files identified by their properties ->name, ->date and ->size
  *
@@ -497,11 +576,19 @@ function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists)
  */
 function dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
 {
-    global $conf;
+    global $user, $db, $conf;
     $result=false;
 
     dol_syslog("files.lib.php::dol_move srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." overwritifexists=".$overwriteifexists);
+    $srcexists=dol_is_file($srcfile);
     $destexists=dol_is_file($destfile);
+
+    if (! $srcexists) 
+    {
+        dol_syslog("files.lib.php::dol_move srcfile does not exists. we ignore the move request.");
+        return false;
+    }
+    
     if ($overwriteifexists || ! $destexists)
     {
         $newpathofsrcfile=dol_osencode($srcfile);
@@ -512,13 +599,68 @@ function dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
         {
         	if ($destexists)
         	{
-        		dol_syslog("files.lib.php::dol_move failed. We try to delete first and move after.", LOG_WARNING);
+        		dol_syslog("files.lib.php::dol_move Failed. We try to delete target first and move after.", LOG_WARNING);
         		// We force delete and try again. Rename function sometimes fails to replace dest file with some windows NTFS partitions.
         		dol_delete_file($destfile);
         		$result=@rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @
         	}
-        	else dol_syslog("files.lib.php::dol_move failed", LOG_WARNING);
+        	else dol_syslog("files.lib.php::dol_move Failed.", LOG_WARNING);
+        }
+
+        // Move ok
+        if ($result)
+        {
+            // Rename entry into ecm database
+            $rel_filetorenamebefore = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $srcfile);
+            $rel_filetorenameafter = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $destfile);
+            if (! preg_match('/(\/temp\/|\/thumbs|\.meta$)/', $rel_filetorenameafter))     // If not a tmp file
+            {
+                $rel_filetorenamebefore = preg_replace('/^[\\/]/', '', $rel_filetorenamebefore);
+                $rel_filetorenameafter = preg_replace('/^[\\/]/', '', $rel_filetorenameafter);
+                //var_dump($rel_filetorenamebefore.' - '.$rel_filetorenameafter);
+
+                dol_syslog("Try to rename also entries in database for full relative path before = ".$rel_filetorenamebefore." after = ".$rel_filetorenameafter, LOG_DEBUG);
+                include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
+                $ecmfile=new EcmFiles($db);
+                $result = $ecmfile->fetch(0, '', $rel_filetorenamebefore);
+                if ($result > 0)   // If found
+                {
+                    $filename = basename($rel_filetorenameafter);
+                    $rel_dir = dirname($rel_filetorenameafter);
+                    $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
+                    $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
+                    
+                    $ecmfile->filepath = $rel_dir;
+                    $ecmfile->filename = $filename;
+                    $result = $ecmfile->update($user);
+                }
+                elseif ($result == 0)   // If not found
+                {
+                    $filename = basename($rel_filetorenameafter);
+                    $rel_dir = dirname($rel_filetorenameafter);
+                    $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
+                    $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
+                    	
+                    $ecmfile->filepath = $rel_dir;
+                    $ecmfile->filename = $filename;
+                    $ecmfile->label = md5_file(dol_osencode($destfile));        // $destfile is a full path to file
+                    $ecmfile->fullpath_orig = $srcfile;
+                    $ecmfile->gen_or_uploaded = 'unknown';
+                    $ecmfile->description = '';    // indexed content
+                    $ecmfile->keyword = '';        // keyword content
+                    $result = $ecmfile->create($user);
+                    if ($result < 0)
+                    {
+                        setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
+                    }                    
+                }
+                elseif ($result < 0)
+                {
+                    setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
+                }
+            }        
         }
+        
         if (empty($newmask)) $newmask=empty($conf->global->MAIN_UMASK)?'0755':$conf->global->MAIN_UMASK;
         $newmaskdec=octdec($newmask);
         // Currently method is restricted to files (dol_delete_files previously used is for files, and mask usage if for files too)
@@ -743,10 +885,33 @@ function dol_delete_file($file,$disableglob=0,$nophperrors=0,$nohook=0,$object=n
 				{
 					if ($nophperrors) $ok=@unlink($filename);
 					else $ok=unlink($filename);
-					if ($ok) dol_syslog("Removed file ".$filename, LOG_DEBUG);
+					if ($ok) 
+					{
+					    dol_syslog("Removed file ".$filename, LOG_DEBUG);
+					    
+	                    // Delete entry into ecm database
+    				    $rel_filetodelete = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $filename);
+    				    if (! preg_match('/(\/temp\/|\/thumbs\/|\.meta$)/', $rel_filetodelete))     // If not a tmp file
+    				    {
+    				        $rel_filetodelete = preg_replace('/^[\\/]/', '', $rel_filetodelete);
+    				        
+    				        dol_syslog("Try to remove also entries in database for full relative path = ".$rel_filetodelete, LOG_DEBUG);
+        				    include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
+        				    $ecmfile=new EcmFiles($db);
+        				    $result = $ecmfile->fetch(0, '', $rel_filetodelete);
+        				    if ($result >= 0)
+        				    {
+        				        $result = $ecmfile->delete($user);
+        				    }
+        				    if ($result < 0)
+        				    {
+        				        setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
+        				    }
+    				    }
+					}
 					else dol_syslog("Failed to remove file ".$filename, LOG_WARNING);
 					// TODO Failure to remove can be because file was already removed or because of permission
-					// If error because of not exists, we must can return true but we should return false if this is a permission problem
+					// If error because of not exists, we must should return true and we should return false if this is a permission problem
 				}
 			}
 			else dol_syslog("No files to delete found", LOG_WARNING);
@@ -995,12 +1160,12 @@ function dol_init_file_process($pathtoscan='', $trackid='')
  * All information used are in db, conf, langs, user and _FILES.
  * Note: This function can be used only into a HTML page context.
  *
- * @param	string	$upload_dir				Directory where to store uploaded file (note: also find in first part of dest_file)
+ * @param	string	$upload_dir				Directory where to store uploaded file (note: used to forge $destpath = $upload_dir + filename)
  * @param	int		$allowoverwrite			1=Allow overwrite existing file
  * @param	int		$donotupdatesession		1=Do no edit _SESSION variable
  * @param	string	$varfiles				_FILES var name
  * @param	string	$savingdocmask			Mask to use to define output filename. For example 'XXXXX-__YYYYMMDD__-__file__'
- * @param	string	$link					Link to add
+ * @param	string	$link					Link to add (to add a link instead of a file)
  * @param   string  $trackid                Track id (used to prefix name of session vars to avoid conflict)
  * @return	void
  */
@@ -1026,49 +1191,82 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio
 			
 			for ($i = 0; $i < $nbfile; $i++)
 			{
-				// Define $destpath (path to file including filename) and $destfile (only filename)
-				$destpath=$upload_dir . "/" . $TFile['name'][$i];
+				// Define $destfull (path to file including filename) and $destfile (only filename)
+				$destfull=$upload_dir . "/" . $TFile['name'][$i];
 				$destfile=$TFile['name'][$i];
 	
 				$savingdocmask = dol_sanitizeFileName($savingdocmask);
 	
 				if ($savingdocmask)
 				{
-					$destpath=$upload_dir . "/" . preg_replace('/__file__/',$TFile['name'][$i],$savingdocmask);
+					$destfull=$upload_dir . "/" . preg_replace('/__file__/',$TFile['name'][$i],$savingdocmask);
 					$destfile=preg_replace('/__file__/',$TFile['name'][$i],$savingdocmask);
 				}
 
 				// lowercase extension
-				$info = pathinfo($destpath);
-				$destpath = $info['dirname'].'/'.$info['filename'].'.'.strtolower($info['extension']);
+				$info = pathinfo($destfull);
+				$destfull = $info['dirname'].'/'.$info['filename'].'.'.strtolower($info['extension']);
 				$info = pathinfo($destfile);
 				$destfile = $info['filename'].'.'.strtolower($info['extension']);
-				    
-				$resupload = dol_move_uploaded_file($TFile['tmp_name'][$i], $destpath, $allowoverwrite, 0, $TFile['error'][$i], 0, $varfiles);
-				if (is_numeric($resupload) && $resupload > 0)
+
+				$resupload = dol_move_uploaded_file($TFile['tmp_name'][$i], $destfull, $allowoverwrite, 0, $TFile['error'][$i], 0, $varfiles);
+				
+				if (is_numeric($resupload) && $resupload > 0)   // $resupload can be 'ErrorFileAlreadyExists'
 				{
 					global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini;
 				
 					include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
+					
+					// Generate thumbs.
+					if (image_format_supported($destfull) == 1)
+					{
+					    // Create thumbs
+					    // We can't use $object->addThumbs here because there is no $object known
+					
+					    // Used on logon for example
+					    $imgThumbSmall = vignette($destfull, $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs");
+					    // Create mini thumbs for image (Ratio is near 16/9)
+					    // Used on menu or for setup page for example
+					    $imgThumbMini = vignette($destfull, $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs");
+					}
+					
+					// Update session
 					if (empty($donotupdatesession))
 					{
 						include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
 						$formmail = new FormMail($db);
 						$formmail->trackid = $trackid;
-						$formmail->add_attached_files($destpath, $destfile, $TFile['type'][$i]);
+						$formmail->add_attached_files($destfull, $destfile, $TFile['type'][$i]);
 					}
-					if (image_format_supported($destpath) == 1)
+					
+					// Update table of files
+					if ($donotupdatesession) 
 					{
-						// Create thumbs
-						// We can't use $object->addThumbs here because there is no $object known
-						
-						// Used on logon for example
-						$imgThumbSmall = vignette($destpath, $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs");
-						// Create mini thumbs for image (Ratio is near 16/9)
-						// Used on menu or for setup page for example
-						$imgThumbMini = vignette($destpath, $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs");
+					    $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir);
+				    
+					    if (! preg_match('/[\\/]temp[\\/]/', $rel_dir))     // If not a tmp dir
+					    {
+					        $filename = basename($destfile);
+					        $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
+					        $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
+    					    
+    					    include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
+    					    $ecmfile=new EcmFiles($db);
+    					    $ecmfile->filepath = $rel_dir;
+    					    $ecmfile->filename = $filename;
+    					    $ecmfile->label = md5_file(dol_osencode($destfull));
+    					    $ecmfile->fullpath_orig = $TFile['name'][$i];
+    					    $ecmfile->gen_or_uploaded = 'uploaded';
+    					    $ecmfile->description = '';    // indexed content
+    					    $ecmfile->keyword = '';        // keyword content
+    					    $result = $ecmfile->create($user);
+                            if ($result < 0)
+                            {
+                                setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
+                            }
+					    }
 					}
-	
+
 					setEventMessages($langs->trans("FileTransferComplete"), null, 'mesgs');
 				}
 				else
@@ -1145,7 +1343,7 @@ function dol_remove_file_process($filenb,$donotupdatesession=0,$donotdeletefile=
 	{
 		$pathtodelete=$listofpaths[$keytodelete];
 		$filetodelete=$listofnames[$keytodelete];
-		if (empty($donotdeletefile)) $result = dol_delete_file($pathtodelete,1);
+		if (empty($donotdeletefile)) $result = dol_delete_file($pathtodelete,1);  // The delete of ecm database is inside the function dol_delete_file
 		else $result=0;
 		if ($result >= 0)
 		{
@@ -1337,11 +1535,11 @@ function dol_most_recent_file($dir,$regexfilter='',$excludefilter=array('(\.meta
  * Security check when accessing to a document (used by document.php, viewimage.php and webservices)
  *
  * @param	string	$modulepart			Module of document ('module', 'module_user_temp', 'module_user' or 'module_temp')
- * @param	string	$original_file		Relative path with filename
+ * @param	string	$original_file		Relative path with filename, relative to modulepart.
  * @param	string	$entity				Restrict onto entity
  * @param  	User	$fuser				User object (forced)
  * @param	string	$refname			Ref of object to check permission for external users (autodetect if not provided)
- * @return	mixed						Array with access information : accessallowed & sqlprotectagainstexternals & original_file (as full path name)
+ * @return	mixed						Array with access information : 'accessallowed' & 'sqlprotectagainstexternals' & 'original_file' (as a full path name)
  */
 function dol_check_secure_access_document($modulepart,$original_file,$entity,$fuser='',$refname='')
 {
@@ -1635,7 +1833,7 @@ function dol_check_secure_access_document($modulepart,$original_file,$entity,$fu
 			$accessallowed=1;
 		}
 		$original_file=$conf->projet->dir_output.'/'.$original_file;
-		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."projet WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity;
+		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."projet WHERE ref='".$db->escape($refname)."' AND entity IN (".getEntity('project', 1).")";
 	}
 	else if ($modulepart == 'project_task')
 	{
@@ -1644,7 +1842,7 @@ function dol_check_secure_access_document($modulepart,$original_file,$entity,$fu
 			$accessallowed=1;
 		}
 		$original_file=$conf->projet->dir_output.'/'.$original_file;
-		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."projet WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity;
+		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."projet WHERE ref='".$db->escape($refname)."' AND entity IN (".getEntity('project', 1).")";
 	}
 	// Wrapping for interventions
 	else if ($modulepart == 'fichinter')
@@ -1759,6 +1957,7 @@ function dol_check_secure_access_document($modulepart,$original_file,$entity,$fu
 			$accessallowed=1;
 		}
 		$original_file=$conf->contrat->dir_output.'/'.$original_file;
+		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."contrat WHERE ref='".$db->escape($refname)."' AND entity IN (".getEntity('contract', 1).")";
 	}
 
 	// Wrapping pour les dons

+ 65 - 65
htdocs/core/lib/functions.lib.php

@@ -203,7 +203,7 @@ function getBrowserInfo($user_agent)
 	elseif (preg_match('/opera(\/|\s)([\d\.]*)/i', $user_agent, $reg))    { $name='opera';     $version=$reg[2]; }
 	elseif (preg_match('/(MSIE\s([0-9]+\.[0-9]))|.*(Trident\/[0-9]+.[0-9];\srv:([0-9]+\.[0-9]+))/i', $user_agent, $reg))  { $name='ie'; $version=end($reg); }    // MS products at end
 	elseif (preg_match('/l(i|y)n(x|ks)(\(|\/|\s)*([\d\.]+)/i', $user_agent, $reg)) { $name='lynxlinks'; $version=$reg[4]; }
-	
+
 	if ($tablet) {
 		$layout = 'tablet';
 	} elseif ($phone) {
@@ -268,14 +268,14 @@ function GETPOST($paramname,$check='',$method=0,$filter=NULL,$options=NULL)
 	        {
     	        $tmp=dol_getdate(dol_now(), true);
     	        $out = $tmp['mon'];
-	        }	         
+	        }
 	        elseif ($reg[1] == 'YEAR')
 	        {
 	           $tmp=dol_getdate(dol_now(), true);
 	           $out = $tmp['year'];
 	        }
 	    }
-	     
+
 	    switch ($check)
 	    {
 	        case 'int':
@@ -409,15 +409,15 @@ function dol_buildpath($path, $type=0)
 		if ($type == 1) $res = DOL_URL_ROOT.'/'.$path;			// Standard value
 		if ($type == 2) $res = DOL_MAIN_URL_ROOT.'/'.$path;		// Standard value
 		if ($type == 3) $res = DOL_URL_ROOT.'/'.$path;
-		
+
 		foreach ($conf->file->dol_document_root as $key => $dirroot)	// ex: array(["main"]=>"/home/main/htdocs", ["alt0"]=>"/home/dirmod/htdocs", ...)
 		{
-			if ($key == 'main') 
+			if ($key == 'main')
 			{
 			    if ($type == 3)
 			    {
 			        global $dolibarr_main_url_root;
-			        	
+
 			        // Define $urlwithroot
 			        $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
 			        $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
@@ -444,12 +444,12 @@ function dol_buildpath($path, $type=0)
 					if ($type == 3)
 					{
 					    global $dolibarr_main_url_root;
-					    
+
 					    // Define $urlwithroot
 					    $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
 					    $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
 					    //$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
-					    					
+
 					    $res=(preg_match('/^http/i',$conf->file->dol_url_root[$key])?'':$urlwithroot).$conf->file->dol_url_root[$key].'/'.$path;     // Test on start with http is for old conf syntax
 					}
 					break;
@@ -716,13 +716,13 @@ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename='
     		throw new Exception('Incorrect log level');
     	}
     	if ($level > $conf->global->SYSLOG_LEVEL) return;
-    
+
     	// If adding log inside HTML page is required
     	if (! empty($_REQUEST['logtohtml']) && (! empty($conf->global->MAIN_ENABLE_LOG_TO_HTML) || ! empty($conf->global->MAIN_LOGTOHTML)))   // MAIN_LOGTOHTML kept for backward compatibility
     	{
     		$conf->logbuffer[] = dol_print_date(time(),"%Y-%m-%d %H:%M:%S")." ".$message;
     	}
-    
+
     	//TODO: Remove this. MAIN_ENABLE_LOG_INLINE_HTML should be deprecated and use a log handler dedicated to HTML output
     	// If enable html log tag enabled and url parameter log defined, we show output log on HTML comments
     	if (! empty($conf->global->MAIN_ENABLE_LOG_INLINE_HTML) && ! empty($_GET["log"]))
@@ -731,7 +731,7 @@ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename='
     		print $message."\n";
     		print "Log end -->\n";
     	}
-    
+
     	$data = array(
     		'message' => $message,
     		'script' => (isset($_SERVER['PHP_SELF'])? basename($_SERVER['PHP_SELF'],'.php') : false),
@@ -739,7 +739,7 @@ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename='
     		'user' => ((is_object($user) && $user->id) ? $user->login : false),
     		'ip' => false
     	);
-    
+
     	if (! empty($_SERVER["REMOTE_ADDR"])) $data['ip'] = $_SERVER['REMOTE_ADDR'];
     	// This is when PHP session is ran inside a web server but not inside a client request (example: init code of apache)
     	else if (! empty($_SERVER['SERVER_ADDR'])) $data['ip'] = $_SERVER['SERVER_ADDR'];
@@ -926,7 +926,7 @@ function dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $pi
 	{
 		$out = $hookmanager->resPrint;
 	}
-	
+
 	return $out;
 }
 
@@ -985,7 +985,7 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r
 	if ($object->element == 'member')  $modulepart='memberphoto';
 	if ($object->element == 'user')    $modulepart='userphoto';
 	if ($object->element == 'product') $modulepart='product';
-	
+
 	if ($object->element == 'product')
 	{
 	    $width=80; $cssclass='photoref';
@@ -993,7 +993,7 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r
 	    $maxvisiblephotos=(isset($conf->global->PRODUCT_MAX_VISIBLE_PHOTO)?$conf->global->PRODUCT_MAX_VISIBLE_PHOTO:5);
 		if ($conf->browser->phone) $maxvisiblephotos=1;
 		if ($showimage) $morehtmlleft.='<div class="floatleft inline-block valignmiddle divphotoref">'.$object->show_photos($conf->product->multidir_output[$object->entity],'small',$maxvisiblephotos,0,0,0,$width,0).'</div>';
-        else 
+        else
         {
 			if (!empty($conf->global->PRODUCT_NODISPLAYIFNOPHOTO)) {
 				$nophoto='';
@@ -1003,14 +1003,14 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r
 				$nophoto='/public/theme/common/nophoto.png';
 				$morehtmlleft.='<div class="floatleft inline-block valignmiddle divphotoref"><img class="photo'.$modulepart.($cssclass?' '.$cssclass:'').'" alt="No photo" border="0"'.($width?' width="'.$width.'"':'').($height?' height="'.$height.'"':'').' src="'.DOL_URL_ROOT.$nophoto.'"></div>';
 			}
-            
+
         }
 	}
-	else 
+	else
 	{
-        if ($showimage) 
+        if ($showimage)
         {
-            if ($modulepart != 'unknown') 
+            if ($modulepart != 'unknown')
             {
                 $phototoshow = $form->showphoto($modulepart,$object,0,0,0,'photoref','small',1,0,$maxvisiblephotos);
                 if ($phototoshow)
@@ -1023,7 +1023,7 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r
             elseif ($conf->browser->layout != 'phone')      // Show no photo link
             {
                 $morehtmlleft.='<div class="floatleft inline-block valignmiddle divphotoref">';
-                if ($object->element == 'action') 
+                if ($object->element == 'action')
                 {
                     $cssclass='photorefcenter';
                     $nophoto=img_picto('', 'title_agenda', '', false, 1);
@@ -1042,7 +1042,7 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r
 	if ($showbarcode) $morehtmlleft.='<div class="floatleft inline-block valignmiddle divphotoref">'.$form->showbarcode($object).'</div>';
 	if ($object->element == 'societe' && ! empty($conf->use_javascript_ajax) && $user->rights->societe->creer && ! empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
 		$morehtmlstatus.=ajax_object_onoff($object, 'status', 'status', 'InActivity', 'ActivityCeased');
-	} 
+	}
 	elseif ($object->element == 'product')
 	{
 	    //$morehtmlstatus.=$langs->trans("Status").' ('.$langs->trans("Sell").') ';
@@ -1062,7 +1062,7 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r
 	elseif ($object->element == 'facture' || $object->element == 'invoice' || $object->element == 'invoice_supplier')
 	{
 	    $tmptxt=$object->getLibStatut(6, $object->totalpaye);
-	    if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout=='phone') $tmptxt=$object->getLibStatut(5, $object->totalpaye); 
+	    if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout=='phone') $tmptxt=$object->getLibStatut(5, $object->totalpaye);
 		$morehtmlstatus.=$tmptxt;
 	}
 	elseif ($object->element == 'chargesociales')
@@ -1084,7 +1084,7 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r
 	}
 	else { // Generic case
 	    $tmptxt=$object->getLibStatut(6);
-	    if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout=='phone') $tmptxt=$object->getLibStatut(5); 
+	    if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout=='phone') $tmptxt=$object->getLibStatut(5);
 		$morehtmlstatus.=$tmptxt;
 	}
 	if (! empty($object->name_alias)) $morehtmlref.='<div class="refidno">'.$object->name_alias.'</div>';      // For thirdparty
@@ -1278,9 +1278,9 @@ function dol_print_date($time,$format='',$tzoutput='tzserver',$outputlangs='',$e
 	$reduceformat=(! empty($conf->dol_optimize_smallscreen) && in_array($format,array('day','dayhour')))?1:0;
 	$formatwithoutreduce = preg_replace('/reduceformat/','',$format);
 	if ($formatwithoutreduce != $format) { $format = $formatwithoutreduce; $reduceformat=1; }  // so format 'dayreduceformat' is processed like day
-    
+
 	// Change predefined format into computer format. If found translation in lang file we use it, otherwise we use default.
-	// TODO Add format daysmallyear and dayhoursmallyear 
+	// TODO Add format daysmallyear and dayhoursmallyear
 	if ($format == 'day')				$format=($outputlangs->trans("FormatDateShort")!="FormatDateShort"?$outputlangs->trans("FormatDateShort"):$conf->format_date_short);
 	else if ($format == 'hour')			$format=($outputlangs->trans("FormatHourShort")!="FormatHourShort"?$outputlangs->trans("FormatHourShort"):$conf->format_hour_short);
 	else if ($format == 'hourduration')	$format=($outputlangs->trans("FormatHourShortDuration")!="FormatHourShortDuration"?$outputlangs->trans("FormatHourShortDuration"):$conf->format_hour_short_duration);
@@ -1782,7 +1782,7 @@ function dol_print_phone($phone,$countrycode='',$cid=0,$socid=0,$addlink='',$sep
 	        $newphone=($separ!=''?'(':'').substr($newphone,0,3).($separ!=''?')':'').$separ.substr($newphone,3,3).($separ!=''?'-':'').substr($newphone,6,4);
 	    }
 	}
-	
+
 	if (! empty($addlink))	// Link on phone number (+ link to add action if conf->global->AGENDA_ADDACTIONFORPHONE set)
 	{
 		if (! empty($conf->browser->phone) || (! empty($conf->clicktodial->enabled) && ! empty($conf->global->CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS)))	// If phone or option for, we use link of phone
@@ -1912,7 +1912,7 @@ function dol_user_country()
  *  @param  int		$mode       thirdparty|contact|member|other
  *  @param  int		$id         Id of object
  *  @param	int		$noprint	No output. Result is the function return
- *  @param  string  $charfornl  Char to use instead of nl2br. '' means we use a standad nl2br.  
+ *  @param  string  $charfornl  Char to use instead of nl2br. '' means we use a standad nl2br.
  *  @return string|void			Nothing if noprint is 0, formatted address if noprint is 1
  *  @see dol_format_address
  */
@@ -1933,7 +1933,7 @@ function dol_print_address($address, $htmlid, $mode, $id, $noprint=0, $charfornl
         {
             if (empty($charfornl)) $out.=nl2br($address);
             else $out.=preg_replace('/[\r\n]+/', $charfornl, $address);
-            
+
             $showgmap=$showomap=0;
 
             // TODO Add a hook here
@@ -2061,7 +2061,7 @@ function dol_print_graph($htmlid,$width,$height,$data,$showlegend=0,$type='pie',
 	    print '<div class="nographyettext">'.$langs->trans("NotEnoughDataYet").'</div>';
 	    return;
 	}
-	
+
 	if (empty($conf->use_javascript_ajax)) return;
 	$jsgraphlib='flot';
 	$datacolor=array();
@@ -2230,7 +2230,7 @@ function dol_trunc($string,$size=40,$trunc='right',$stringencoding='UTF-8',$nodo
 	global $conf;
 
 	if ($size==0 || ! empty($conf->global->MAIN_DISABLE_TRUNC)) return $string;
-	
+
 	if (empty($stringencoding)) $stringencoding='UTF-8';
 	// reduce for small screen
 	if ($conf->dol_optimize_smallscreen==1 && $display==1) $size = round($size/3);
@@ -3196,11 +3196,11 @@ function load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png',
 function print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $center='', $num=-1, $totalnboflines=-1, $picto='title_generic.png', $pictoisfullpath=0, $morehtml='', $morecss='', $limit=-1, $hideselectlimit=0)
 {
 	global $conf,$langs;
-	
+
 	$savlimit = $limit;
     $savtotalnboflines = $totalnboflines;
     $totalnboflines=abs($totalnboflines);
-    
+
 	if ($picto == 'setup') $picto='title_setup.png';
 	if (($conf->browser->name == 'ie') && $picto=='title_generic.png') $picto='title.gif';
 	if ($limit < 0) $limit = $conf->liste_limit;
@@ -3213,7 +3213,7 @@ function print_barre_liste($titre, $page, $file, $options='', $sortfield='', $so
 		$nextpage = 0;
 	}
 	//print 'totalnboflines='.$totalnboflines.'-savlimit='.$savlimit.'-limit='.$limit.'-num='.$num.'-nextpage='.$nextpage;
-	
+
 	print "\n";
 	print "<!-- Begin title '".$titre."' -->\n";
 	print '<table width="100%" border="0" class="notopnoleftnoright'.($morecss?' '.$morecss:'').'" style="margin-bottom: 6px;"><tr>';
@@ -3314,7 +3314,7 @@ function print_fleche_navigation($page, $file, $options='', $nextpage=0, $betwee
 	    //$pagesizechoices.=',0:'.$langs->trans("All");     // Not yet supported
 	    //$pagesizechoices.=',2:2';
 	    if (! empty($conf->global->MAIN_PAGESIZE_CHOICES)) $pagesizechoices=$conf->global->MAIN_PAGESIZE_CHOICES;
-	     
+
         print '<li class="pagination">';
         print '<select class="flat selectlimit" name="limit">';
         $tmpchoice=explode(',',$pagesizechoices);
@@ -3354,7 +3354,7 @@ function print_fleche_navigation($page, $file, $options='', $nextpage=0, $betwee
             		</script>
                 ';
         }
-        print '</li>';	    
+        print '</li>';
 	}
 	if ($page > 0)
 	{
@@ -3393,7 +3393,7 @@ function print_fleche_navigation($page, $file, $options='', $nextpage=0, $betwee
 function vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0)
 {
     $morelabel='';
-    
+
     if (preg_match('/%/',$rate))
 	{
 		$rate=str_replace('%','',$rate);
@@ -3596,7 +3596,7 @@ function price2num($amount,$rounding='',$alreadysqlnb=0)
 
 /**
  * Output a dimension with best unit
- *  
+ *
  * @param   float       $dimension      Dimension
  * @param   int         $unit           Unit of dimension (0, -3, ...)
  * @param   string      $type           'weight', 'volume', ...
@@ -3608,16 +3608,16 @@ function price2num($amount,$rounding='',$alreadysqlnb=0)
 function showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no')
 {
     require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
-    
-    if (($forceunitoutput == 'no' && $dimension < 1/10000) || (is_numeric($forceunitoutput) && $forceunitoutput == -6)) 
+
+    if (($forceunitoutput == 'no' && $dimension < 1/10000) || (is_numeric($forceunitoutput) && $forceunitoutput == -6))
     {
         $dimension = $dimension * 1000000;
-        $unit = $unit - 6; 
+        $unit = $unit - 6;
     }
     elseif (($forceunitoutput == 'no' && $dimension < 1/10) || (is_numeric($forceunitoutput) && $forceunitoutput == -3))
     {
         $dimension = $dimension * 1000;
-        $unit = $unit - 3; 
+        $unit = $unit - 3;
     }
     elseif (($forceunitoutput == 'no' && $dimension > 100000000) || (is_numeric($forceunitoutput) && $forceunitoutput == 6))
     {
@@ -3629,9 +3629,9 @@ function showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=
         $dimension = $dimension / 1000;
         $unit = $unit + 3;
     }
-    
+
     $ret=price($dimension, 0, $outputlangs, 0, 0, $round).' '.measuring_units_string($unit, $type);
-    
+
     return $ret;
 }
 
@@ -3662,12 +3662,12 @@ function get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller
         $vatratecleaned = trim($reg[1]);
 	    $vatratecode = $reg[2];
 	}
-	
+
 	/*if ($thirdparty_buyer->country_code != $thirdparty_seller->country_code)
 	{
 		return 0;
 	}*/
-	
+
 	// Some test to guess with no need to make database access
 	if ($mysoc->country_code == 'ES') // For spain localtaxes 1 and 2, tax is qualified if buyer use local taxe
 	{
@@ -3765,7 +3765,7 @@ function get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller
    		if ($local==1) return $obj->localtax1;
    		elseif ($local==2) return $obj->localtax2;
 	}
-	
+
 	return 0;
 }
 
@@ -3825,7 +3825,7 @@ function get_localtax_by_third($local)
 
 /**
  *  Get vat rate and npr from id.
- *  You can call getLocalTaxesFromRate after to get other fields 
+ *  You can call getLocalTaxesFromRate after to get other fields
  *
  *  @param	int      $vatrowid			Line ID into vat rate table.
  *  @return	array    	  				array(localtax_type1(1-6 / 0 if not found), rate of localtax1, ...)
@@ -3879,7 +3879,7 @@ function getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisi
 	    $vatratecleaned = $reg[1];
 	    $vatratecode = $reg[2];
 	}
-	
+
 	// Search local taxes
 	$sql  = "SELECT t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.accountancy_code_sell, t.accountancy_code_buy";
 	$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t";
@@ -3892,7 +3892,7 @@ function getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisi
     	$sql.= " AND t.taux = ".((float) $vatratecleaned)." AND t.active = 1";
     	if ($vatratecode) $sql.= " AND t.code ='".$vatratecode."'";
 	}
-	
+
 	$resql=$db->query($sql);
 	if ($resql)
 	{
@@ -4299,7 +4299,7 @@ function yn($yesno, $case=1, $color=0)
 /**
  *	Return a path to have a directory according to object.
  *  New usage:       $conf->product->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, 'modulepart')
- *  Old usage:       '015' with level 3->"0/1/5/", '015' with level 1->"5/", 'ABC-1' with level 3 ->"0/0/1/" 
+ *  Old usage:       '015' with level 3->"0/1/5/", '015' with level 1->"5/", 'ABC-1' with level 3 ->"0/0/1/"
  *
  *	@param	string	$num            Id of object (deprecated, $object will be used in future)
  *	@param  int		$level		    Level of subdirs to return (1, 2 or 3 levels). (deprecated, global option will be used in future)
@@ -4316,7 +4316,7 @@ function get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart)
 	$path = '';
 
 	$arrayforoldpath=array('cheque','user','category','holiday','shipment','supplier_invoice','invoice_supplier','mailing');
-	if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) $arrayforoldpath[]='product';	
+	if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) $arrayforoldpath[]='product';
 	if (! empty($level) && in_array($modulepart, $arrayforoldpath))
 	{
 		// This part should be removed once all code is using "get_exdir" to forge path, with all parameters provided
@@ -4469,7 +4469,7 @@ function dolGetFirstLineOfText($text)
 	{
 		$firstline=preg_replace('/<br[^>]*>.*$/s','',$text);		// The s pattern modifier means the . can match newline characters
 		$firstline=preg_replace('/<div[^>]*>.*$/s','',$firstline);	// The s pattern modifier means the . can match newline characters
-		
+
 	}
 	else
 	{
@@ -5375,7 +5375,7 @@ function picto_from_langcode($codelang)
 }
 
 /**
- *  Complete or removed entries into a head array (used to build tabs). 
+ *  Complete or removed entries into a head array (used to build tabs).
  *  For example, with value added by external modules. Such values are declared into $conf->modules_parts['tab'].
  *  Or by change using hook completeTabsHead
  *
@@ -5405,7 +5405,7 @@ function picto_from_langcode($codelang)
 function complete_head_from_modules($conf,$langs,$object,&$head,&$h,$type,$mode='add')
 {
 	global $hookmanager;
-	
+
 	if (isset($conf->modules_parts['tabs'][$type]) && is_array($conf->modules_parts['tabs'][$type]))
 	{
 		foreach ($conf->modules_parts['tabs'][$type] as $value)
@@ -5471,7 +5471,7 @@ function complete_head_from_modules($conf,$langs,$object,&$head,&$h,$type,$mode=
 			}
 		}
 	}
-	
+
 	// No need to make a return $head. Var is modified as a reference
 	if (! empty($hookmanager))
 	{
@@ -5509,11 +5509,11 @@ function printCommonFooter($zone='private')
 	{
 		print '<!-- Reposition management (does not work if a redirect is done after action of submission) -->'."\n";
     	print '<script type="text/javascript" language="javascript">jQuery(document).ready(function() {'."\n";
-    	
+
     	print '<!-- If page_y set, we set scollbar with it -->'."\n";
     	print "page_y=getParameterByName('page_y', 0);";
     	print "if (page_y > 0) $('html, body').scrollTop(page_y);\n";
-    	
+
     	print '<!-- Set handler to add page_y param on some a href links -->'."\n";
     	print 'jQuery(".reposition").click(function() {
     	           var page_y = $(document).scrollTop();
@@ -5533,7 +5533,7 @@ function printCommonFooter($zone='private')
     	
     	print '</script>'."\n";
 	}
-	
+
 	// Google Analytics (need Google module)
 	if (! empty($conf->google->enabled) && ! empty($conf->global->MAIN_GOOGLE_AN_ID))
 	{
@@ -5749,15 +5749,15 @@ function natural_search($fields, $value, $mode=0, $nofirstand=0)
 	            	$tmpcrit=trim($tmpcrit);
 	            	$tmpcrit2=$tmpcrit;
 	            	$tmpbefore='%'; $tmpafter='%';
-	            	if (preg_match('/^[\^\$]/', $tmpcrit)) 
-	            	{ 
+	            	if (preg_match('/^[\^\$]/', $tmpcrit))
+	            	{
 	            	    $tmpbefore='';
-	            	    $tmpcrit2 = preg_replace('/^[\^\$]/', '', $tmpcrit2); 
+	            	    $tmpcrit2 = preg_replace('/^[\^\$]/', '', $tmpcrit2);
 	            	}
-					if (preg_match('/[\^\$]$/', $tmpcrit)) 
-	            	{ 
+					if (preg_match('/[\^\$]$/', $tmpcrit))
+	            	{
 	            	    $tmpafter='';
-	            	    $tmpcrit2 = preg_replace('/[\^\$]$/', '', $tmpcrit2); 
+	            	    $tmpcrit2 = preg_replace('/[\^\$]$/', '', $tmpcrit2);
 	            	}
 	            	$newres .= $tmpbefore;
 	            	$newres .= $db->escape($tmpcrit2);
@@ -5822,7 +5822,7 @@ function getImageFileNameForSize($file, $extName, $extImgTarget='')
 function getAdvancedPreviewUrl($modulepart, $relativepath)
 {
     global $conf;
-    
+
     if (empty($conf->use_javascript_ajax)) return '';
 
     $mime_preview = array('bmp', 'jpeg', 'png', 'gif', 'tiff', 'pdf', 'plain', 'css');

+ 5 - 1
htdocs/core/lib/images.lib.php

@@ -37,8 +37,10 @@ $quality = 80;
  */
 function image_format_supported($file)
 {
+    $regeximgext='\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.xpm|\.xbm';   // See also into product.class.php
+    
     // Case filename is not a format image
-    if (! preg_match('/(\.gif|\.jpg|\.jpeg|\.png|\.bmp)$/i',$file,$reg)) return -1;
+    if (! preg_match('/('.$regeximgext.')$/i',$file,$reg)) return -1;
 
     // Case filename is a format image but not supported by this PHP
     $imgfonction='';
@@ -47,6 +49,8 @@ function image_format_supported($file)
     if (strtolower($reg[1]) == '.jpg')  $imgfonction = 'imagecreatefromjpeg';
     if (strtolower($reg[1]) == '.jpeg') $imgfonction = 'imagecreatefromjpeg';
     if (strtolower($reg[1]) == '.bmp')  $imgfonction = 'imagecreatefromwbmp';
+    if (strtolower($reg[1]) == '.xpm')  $imgfonction = 'imagecreatefromxpm';
+    if (strtolower($reg[1]) == '.xbm')  $imgfonction = 'imagecreatefromxbm';
     if ($imgfonction)
     {
         if (! function_exists($imgfonction))

+ 4 - 4
htdocs/core/menus/standard/eldy.lib.php

@@ -111,13 +111,13 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$mode
 
 		$chaine="";
 		if (! empty($conf->product->enabled)) {
-			$chaine.=$langs->trans("Products");
+			$chaine.=$langs->trans("TMenuProducts");
 		}
 		if (! empty($conf->product->enabled) && ! empty($conf->service->enabled)) {
-			$chaine.="/";
+			$chaine.=" | ";
 		}
 		if (! empty($conf->service->enabled)) {
-			$chaine.=$langs->trans("Services");
+			$chaine.=$langs->trans("TMenuServices");
 		}
 
 		if (empty($noout)) print_start_menu_entry($idsel,$classname,$showmode);
@@ -261,7 +261,7 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$mode
 		$idsel='tools';
 
 		if (empty($noout)) print_start_menu_entry($idsel,$classname,$showmode);
-		if (empty($noout)) print_text_menu_entry($langs->trans("Tools"), $showmode, DOL_URL_ROOT.'/core/tools.php?mainmenu=tools&amp;leftmenu=', $id, $idsel, $classname, $atarget);
+		if (empty($noout)) print_text_menu_entry($langs->trans("TMenuTools"), $showmode, DOL_URL_ROOT.'/core/tools.php?mainmenu=tools&amp;leftmenu=', $id, $idsel, $classname, $atarget);
 		if (empty($noout)) print_end_menu_entry($showmode);
 		$menu->add('/core/tools.php?mainmenu=tools&amp;leftmenu=', $langs->trans("Tools"), 0, $showmode, $atarget, "tools", '');
 	}

+ 1 - 1
htdocs/core/modules/modAgenda.class.php

@@ -189,7 +189,7 @@ class modAgenda extends DolibarrModules
 		// $r++;
 		$this->menu[$r]=array('fk_menu'=>0,
 													'type'=>'top',
-													'titre'=>'Agenda',
+													'titre'=>'TMenuAgenda',
 													'mainmenu'=>'agenda',
 													'url'=>'/comm/action/index.php',
 													'langs'=>'agenda',

+ 81 - 2
htdocs/core/photos_resize.php

@@ -134,11 +134,50 @@ if ($action == 'confirm_resize' && (isset($_POST["file"]) != "") && (isset($_POS
 {
 	$fullpath=$dir."/".$original_file;
 	$result=dol_imageResizeOrCrop($fullpath,0,$_POST['sizex'],$_POST['sizey']);
-
+	
 	if ($result == $fullpath)
 	{
 		$object->addThumbs($fullpath);
 
+		// Update/create database for file $fullpath
+		$rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $fullpath);
+		$rel_filename = preg_replace('/^[\\/]/','',$rel_filename);
+		
+		include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
+		$ecmfile=new EcmFiles($db);
+		$result = $ecmfile->fetch(0, '', $rel_filename);
+		if ($result > 0)   // If found
+		{
+		    $filename = basename($rel_filename);
+		    $rel_dir = dirname($rel_filename);
+		    $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
+		    $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
+		
+		    $ecmfile->label = md5_file(dol_osencode($fullpath));
+		    $result = $ecmfile->update($user);
+		}
+		elseif ($result == 0)   // If not found
+		{
+		    $filename = basename($rel_filename);
+		    $rel_dir = dirname($rel_filename);
+		    $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
+		    $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
+		     
+		    $ecmfile->filepath = $rel_dir;
+		    $ecmfile->filename = $filename;
+		    $ecmfile->label = md5_file(dol_osencode($fullpath));        // $fullpath is a full path to file
+		    $ecmfile->fullpath_orig = $fullpath;
+		    $ecmfile->gen_or_uploaded = 'unknown';
+		    $ecmfile->description = '';    // indexed content
+		    $ecmfile->keyword = '';        // keyword content
+		    $result = $ecmfile->create($user);
+		    if ($result < 0)
+		    {
+		        setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
+		    }
+		    $result = $ecmfile->create($user);
+		}
+		
 		if ($backtourl)
 		{
 			header("Location: ".$backtourl);
@@ -168,6 +207,45 @@ if ($action == 'confirm_crop')
 	{
 		$object->addThumbs($fullpath);
 
+		// Update/create database for file $fullpath
+		$rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $fullpath);
+		$rel_filename = preg_replace('/^[\\/]/','',$rel_filename);
+		
+		include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
+		$ecmfile=new EcmFiles($db);
+		$result = $ecmfile->fetch(0, '', $rel_filename);
+		if ($result > 0)   // If found
+		{
+		    $filename = basename($rel_filename);
+		    $rel_dir = dirname($rel_filename);
+		    $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
+		    $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
+		
+		    $ecmfile->label = md5_file(dol_osencode($fullpath));
+		    $result = $ecmfile->update($user);
+		}
+		elseif ($result == 0)   // If not found
+		{
+		    $filename = basename($rel_filename);
+		    $rel_dir = dirname($rel_filename);
+		    $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
+		    $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
+		     
+		    $ecmfile->filepath = $rel_dir;
+		    $ecmfile->filename = $filename;
+		    $ecmfile->label = md5_file(dol_osencode($fullpath));        // $fullpath is a full path to file
+		    $ecmfile->fullpath_orig = $fullpath;
+		    $ecmfile->gen_or_uploaded = 'unknown';
+		    $ecmfile->description = '';    // indexed content
+		    $ecmfile->keyword = '';        // keyword content
+		    $result = $ecmfile->create($user);
+		    if ($result < 0)
+		    {
+		        setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
+		    }
+		    $result = $ecmfile->create($user);
+		}
+		
 		if ($backtourl)
 		{
 			header("Location: ".$backtourl);
@@ -218,10 +296,11 @@ print '<legend>'.$langs->trans("Resize").'</legend>';
 print $langs->trans("ResizeDesc").'<br>';
 print $langs->trans("NewLength").': <input class="flat" name="sizex" size="10" type="text" > px  &nbsp; '.$langs->trans("or").' &nbsp; ';
 print $langs->trans("NewHeight").': <input class="flat" name="sizey" size="10" type="text" > px &nbsp; <br>';
+
 print '<input type="hidden" name="file" value="'.dol_escape_htmltag(GETPOST('file')).'" />';
 print '<input type="hidden" name="action" value="confirm_resize" />';
 print '<input type="hidden" name="product" value="'.$id.'" />';
-print '<input type="hidden" name="modulepart" value="'.$modulepart.'" />';
+print '<input type="hidden" name="modulepart" value="'.dol_escape_htmltag($modulepart).'" />';
 print '<input type="hidden" name="id" value="'.$id.'" />';
 print '<br>';
 print '<input class="button" id="submitresize" name="sendit" value="'.dol_escape_htmltag($langs->trans("Resize")).'" type="submit" />';

+ 9 - 5
htdocs/core/tpl/ajaxrow.tpl.php

@@ -17,18 +17,19 @@
  *
  * Javascript code to activate drag and drop on lines
  * You can use this if you want to be abale to drag and drop rows of a table.
- * You must add id="tablelines" on table level tag and have count($object->lines) or count($taskarray) > 0
+ * You must add id="tablelines" on table level tag and have ($nboflines or count($object->lines) or count($taskarray) > 0)
  */
 ?>
 
-<!-- BEGIN PHP TEMPLATE AJAXROW.TPL.PHP -->
+<!-- BEGIN PHP TEMPLATE AJAXROW.TPL.PHP - Script to enable drag and drop on tables -->
 <?php
 $id=$object->id;
 $fk_element=$object->fk_element;
-$table_element_line=$object->table_element_line;
-$nboflines=(isset($object->lines)?count($object->lines):(isset($tasksarray)?count($tasksarray):0));
+$table_element_line=(empty($table_element_line)?$object->table_element_line:$table_element_line);
+$nboflines=(isset($object->lines)?count($object->lines):(isset($tasksarray)?count($tasksarray):(empty($nboflines)?0:$nboflines)));
 $forcereloadpage=empty($conf->global->MAIN_FORCE_RELOAD_PAGE)?0:1;
 $tagidfortablednd=(empty($tagidfortablednd)?'tablelines':$tagidfortablednd);
+$filepath=(empty($filepath)?'':$filepath);
 
 if (GETPOST('action') != 'editline' && $nboflines > 1) { ?>
 <script type="text/javascript">
@@ -43,16 +44,19 @@ $(document).ready(function(){
     $("#<?php echo $tagidfortablednd; ?>").tableDnD({
 		onDrop: function(table, row) {
 			var reloadpage = "<?php echo $forcereloadpage; ?>";
+			console.log($("#<?php echo $tagidfortablednd; ?>").tableDnDSerialize());
 			var roworder = cleanSerialize($("#<?php echo $tagidfortablednd; ?>").tableDnDSerialize());
 			var table_element_line = "<?php echo $table_element_line; ?>";
 			var fk_element = "<?php echo $fk_element; ?>";
 			var element_id = "<?php echo $id; ?>";
+			var filepath = "<?php echo urlencode($filepath); ?>";
 			$.post("<?php echo DOL_URL_ROOT; ?>/core/ajax/row.php",
 					{
 						roworder: roworder,
 						table_element_line: table_element_line,
 						fk_element: fk_element,
-						element_id: element_id
+						element_id: element_id,
+						filepath: filepath
 					},
 					function() {
 						if (reloadpage == 1) {

+ 9 - 2
htdocs/core/tpl/document_actions_post_headers.tpl.php

@@ -72,6 +72,9 @@ $formfile->form_attach_new_file(
 	$savingdocmask
 );
 
+$disablemove=1;
+if ($modulepart == 'produit') $disablemove=0;
+    
 // List of document
 $formfile->list_of_documents(
     $filearray,
@@ -79,7 +82,7 @@ $formfile->list_of_documents(
     $modulepart,
     $param,
     0,
-    $relativepathwithnofile,		// relative path with no file. For example "moduledir/0/1"
+    $relativepathwithnofile,		// relative path with no file. For example "0/1"
     $permission,
     0,
     '',
@@ -87,7 +90,11 @@ $formfile->list_of_documents(
     '',
     '',
     0,
-    $permtoedit
+    $permtoedit,
+    $upload_dir,
+    $sortfield,
+    $sortorder,
+    $disablemove
 );
 
 print "<br>";

+ 1 - 1
htdocs/document.php

@@ -109,7 +109,7 @@ if (empty($modulepart)) accessforbidden('Bad value for parameter modulepart');
 $check_access = dol_check_secure_access_document($modulepart,$original_file,$entity,$refname);
 $accessallowed              = $check_access['accessallowed'];
 $sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals'];
-$original_file              = $check_access['original_file'];
+$original_file              = $check_access['original_file'];               // original_file is now a full path name
 
 // Basic protection (against external users only)
 if ($user->societe_id > 0)

+ 1 - 2
htdocs/ecm/class/ecmdirectory.class.php

@@ -23,8 +23,7 @@
  */
 
 /**
- *  \class      EcmDirectory
- *  \brief      Class to manage ECM directories
+ *  Class to manage ECM directories
  */
 class EcmDirectory // extends CommonObject
 {

+ 782 - 0
htdocs/ecm/class/ecmfiles.class.php

@@ -0,0 +1,782 @@
+<?php
+/* Copyright (C) 2007-2012  Laurent Destailleur <eldy@users.sourceforge.net>
+ * Copyright (C) 2014-2016  Juanjo Menent       <jmenent@2byte.es>
+ * Copyright (C) 2015       Florian Henry       <florian.henry@open-concept.pro>
+ * Copyright (C) 2015       Raphaël Doursenaud  <rdoursenaud@gpcsolutions.fr>
+ * Copyright (C) ---Put here your own copyright and developer email---
+ *
+ * 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/>.
+ */
+
+/**
+ * \file    ecm/ecmfiles.class.php
+ * \ingroup ecm
+ * \brief   Class to manage ECM Files (Create/Read/Update/Delete)
+ */
+
+// Put here all includes required by your class file
+require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
+//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
+//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
+
+/**
+ * Class to manage ECM files
+ */
+class EcmFiles //extends CommonObject
+{
+	/**
+	 * @var string Id to identify managed objects
+	 */
+	public $element = 'ecmfiles';
+	/**
+	 * @var string Name of table without prefix where object is stored
+	 */
+	public $table_element = 'ecm_files';
+
+	/**
+	 */
+	public $label;
+	public $entity;
+	public $filename;
+	public $filepath;
+	public $fullpath_orig;
+	public $description;
+	public $keywords;
+	public $cover;
+	public $position;
+	public $gen_or_uploaded;       // can be 'generated', 'uploaded', 'unknown'
+	public $extraparams;
+	public $date_c = '';
+	public $date_m = '';
+	public $fk_user_c;
+	public $fk_user_m;
+	public $acl;
+
+	/**
+	 */
+	
+
+	/**
+	 * Constructor
+	 *
+	 * @param DoliDb $db Database handler
+	 */
+	public function __construct(DoliDB $db)
+	{
+		$this->db = $db;
+	}
+
+	/**
+	 * Create object into database
+	 *
+	 * @param  User $user      User that creates
+	 * @param  bool $notrigger false=launch triggers after, true=disable triggers
+	 *
+	 * @return int <0 if KO, Id of created object if OK
+	 */
+	public function create(User $user, $notrigger = false)
+	{
+	    global $conf;
+	    
+		dol_syslog(__METHOD__, LOG_DEBUG);
+
+		$error = 0;
+
+		// Clean parameters
+		
+		if (isset($this->label)) {
+			 $this->label = trim($this->label);
+		}
+		if (isset($this->entity)) {
+			 $this->entity = trim($this->entity);
+		}
+		if (isset($this->filename)) {
+			 $this->filename = trim($this->filename);
+		}
+		if (isset($this->filepath)) {
+			 $this->filepath = trim($this->filepath);
+		}
+		if (isset($this->fullpath_orig)) {
+			 $this->fullpath_orig = trim($this->fullpath_orig);
+		}
+		if (isset($this->description)) {
+			 $this->description = trim($this->description);
+		}
+		if (isset($this->keywords)) {
+			 $this->keywords = trim($this->keywords);
+		}
+		if (isset($this->cover)) {
+			 $this->cover = trim($this->cover);
+		}
+		if (isset($this->gen_or_uploaded)) {
+			 $this->gen_or_uploaded = trim($this->gen_or_uploaded);
+		}
+		if (isset($this->extraparams)) {
+			 $this->extraparams = trim($this->extraparams);
+		}
+		if (isset($this->fk_user_c)) {
+			 $this->fk_user_c = trim($this->fk_user_c);
+		}
+		if (isset($this->fk_user_m)) {
+			 $this->fk_user_m = trim($this->fk_user_m);
+		}
+		if (isset($this->acl)) {
+			 $this->acl = trim($this->acl);
+		}
+        if (empty($this->date_c)) $this->date_c = dol_now();
+		
+        $maxposition=0;
+		if (empty($this->position))   // Get max used
+		{
+		    $sql = "SELECT MAX(position) as maxposition FROM " . MAIN_DB_PREFIX . $this->table_element;
+		    $sql.= " WHERE filepath ='".$this->filepath."'";
+		    
+		    $resql = $this->db->query($sql);
+		    if ($resql)
+		    {
+		        $obj = $this->db->fetch_object($resql);
+		        $maxposition = (int) $obj->maxposition;
+		    }
+		    else dol_print_error($this->db);
+		}
+		$maxposition=$maxposition+1;
+
+		// Check parameters
+		// Put here code to add control on parameters values
+
+		// Insert request
+		$sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '(';
+		$sql.= 'label,';
+		$sql.= 'entity,';
+		$sql.= 'filename,';
+		$sql.= 'filepath,';
+		$sql.= 'fullpath_orig,';
+		$sql.= 'description,';
+		$sql.= 'keywords,';
+		$sql.= 'cover,';
+		$sql.= 'position,';
+		$sql.= 'gen_or_uploaded,';
+		$sql.= 'extraparams,';
+		$sql.= 'date_c,';
+		$sql.= 'date_m,';
+		$sql.= 'fk_user_c,';
+		$sql.= 'fk_user_m,';
+		$sql.= 'acl';
+		$sql .= ') VALUES (';
+		$sql .= ' '.(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").',';
+		$sql .= ' '.(! isset($this->entity)?$conf->entity:$this->entity).',';
+		$sql .= ' '.(! isset($this->filename)?'NULL':"'".$this->db->escape($this->filename)."'").',';
+		$sql .= ' '.(! isset($this->filepath)?'NULL':"'".$this->db->escape($this->filepath)."'").',';
+		$sql .= ' '.(! isset($this->fullpath_orig)?'NULL':"'".$this->db->escape($this->fullpath_orig)."'").',';
+		$sql .= ' '.(! isset($this->description)?'NULL':"'".$this->db->escape($this->description)."'").',';
+		$sql .= ' '.(! isset($this->keywords)?'NULL':"'".$this->db->escape($this->keywords)."'").',';
+		$sql .= ' '.(! isset($this->cover)?'NULL':"'".$this->db->escape($this->cover)."'").',';
+		$sql .= ' '.$maxposition.',';
+		$sql .= ' '.(! isset($this->gen_or_uploaded)?'NULL':"'".$this->db->escape($this->gen_or_uploaded)."'").',';
+		$sql .= ' '.(! isset($this->extraparams)?'NULL':"'".$this->db->escape($this->extraparams)."'").',';
+		$sql .= ' '."'".$this->db->idate($this->date_c)."'".',';
+		$sql .= ' '.(! isset($this->date_m) || dol_strlen($this->date_m)==0?'NULL':"'".$this->db->idate($this->date_m)."'").',';
+		$sql .= ' '.(! isset($this->fk_user_c)?$user->id:$this->fk_user_c).',';
+		$sql .= ' '.(! isset($this->fk_user_m)?'NULL':$this->fk_user_m).',';
+		$sql .= ' '.(! isset($this->acl)?'NULL':"'".$this->db->escape($this->acl)."'");
+		$sql .= ')';
+
+		$this->db->begin();
+
+		$resql = $this->db->query($sql);
+		if (!$resql) {
+			$error ++;
+			$this->errors[] = 'Error ' . $this->db->lasterror();
+			dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
+		}
+
+		if (!$error) {
+			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
+            $this->position = $maxposition;
+            
+			if (!$notrigger) {
+				// Uncomment this and change MYOBJECT to your own tag if you
+				// want this action to call a trigger.
+
+				//// Call triggers
+				//$result=$this->call_trigger('MYOBJECT_CREATE',$user);
+				//if ($result < 0) $error++;
+				//// End call triggers
+			}
+		}
+
+		// Commit or rollback
+		if ($error) {
+			$this->db->rollback();
+
+			return - 1 * $error;
+		} else {
+			$this->db->commit();
+
+			return $this->id;
+		}
+	}
+
+	/**
+	 * Load object in memory from the database
+	 *
+	 * @param  int    $id          Id object
+	 * @param  string $ref         Not used yet. Will contains a hash id from filename+filepath
+	 * @param  string $fullpath    Full path of file (relative path to document directory)
+	 * @return int                 <0 if KO, 0 if not found, >0 if OK
+	 */
+	public function fetch($id, $ref = null, $fullpath = '')
+	{
+		dol_syslog(__METHOD__, LOG_DEBUG);
+
+		$sql = 'SELECT';
+		$sql .= ' t.rowid,';
+		$sql .= " t.ref,";
+		$sql .= " t.label,";
+		$sql .= " t.entity,";
+		$sql .= " t.filename,";
+		$sql .= " t.filepath,";
+		$sql .= " t.fullpath_orig,";
+		$sql .= " t.description,";
+		$sql .= " t.keywords,";
+		$sql .= " t.cover,";
+		$sql .= " t.position,";
+		$sql .= " t.gen_or_uploaded,";
+		$sql .= " t.extraparams,";
+		$sql .= " t.date_c,";
+		$sql .= " t.date_m,";
+		$sql .= " t.fk_user_c,";
+		$sql .= " t.fk_user_m,";
+		$sql .= " t.acl";
+		$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
+		$sql.= ' WHERE 1 = 1';
+		/* Fetching this table depends on filepath+filename, it must not depends on entity
+		if (! empty($conf->multicompany->enabled)) {
+		    $sql .= " AND entity IN (" . getEntity("ecmfiles", 1) . ")";
+		}*/
+		if ($fullpath) {
+			$sql .= " AND t.filepath = '" . $this->db->escape(dirname($fullpath)) . "' AND t.filename = '".$this->db->escape(basename($fullpath))."'";
+		}
+		elseif (null !== $ref) {
+			$sql .= " AND t.ref = '".$this->db->escape($ref)."'";
+		} else {
+			$sql .= ' AND t.rowid = ' . $id;
+		}
+
+		$resql = $this->db->query($sql);
+		if ($resql) {
+			$numrows = $this->db->num_rows($resql);
+			if ($numrows) {
+				$obj = $this->db->fetch_object($resql);
+
+				$this->id = $obj->rowid;
+				$this->ref = $obj->ref;
+				$this->label = $obj->label;
+				$this->entity = $obj->entity;
+				$this->filename = $obj->filename;
+				$this->filepath = $obj->filepath;
+				$this->fullpath_orig = $obj->fullpath_orig;
+				$this->description = $obj->description;
+				$this->keywords = $obj->keywords;
+				$this->cover = $obj->cover;
+				$this->position = $obj->position;
+				$this->gen_or_uploaded = $obj->gen_or_uploaded;
+				$this->extraparams = $obj->extraparams;
+				$this->date_c = $this->db->jdate($obj->date_c);
+				$this->date_m = $this->db->jdate($obj->date_m);
+				$this->fk_user_c = $obj->fk_user_c;
+				$this->fk_user_m = $obj->fk_user_m;
+				$this->acl = $obj->acl;
+			}
+			
+			// Retrieve all extrafields for invoice
+			// fetch optionals attributes and labels
+			/*
+			require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
+			$extrafields=new ExtraFields($this->db);
+			$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
+			$this->fetch_optionals($this->id,$extralabels);
+            */
+			// $this->fetch_lines();
+			
+			$this->db->free($resql);
+
+			if ($numrows) {
+				return 1;
+			} else {
+				return 0;
+			}
+		} else {
+			$this->errors[] = 'Error ' . $this->db->lasterror();
+			dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
+
+			return - 1;
+		}
+	}
+
+	/**
+	 * Load object in memory from the database
+	 *
+	 * @param string $sortorder Sort Order
+	 * @param string $sortfield Sort field
+	 * @param int    $limit     offset limit
+	 * @param int    $offset    offset limit
+	 * @param array  $filter    filter array
+	 * @param string $filtermode filter mode (AND or OR)
+	 *
+	 * @return int <0 if KO, >0 if OK
+	 */
+	public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND')
+	{
+		dol_syslog(__METHOD__, LOG_DEBUG);
+
+		$sql = 'SELECT';
+		$sql .= ' t.rowid,';
+		$sql .= " t.label,";
+		$sql .= " t.entity,";
+		$sql .= " t.filename,";
+		$sql .= " t.filepath,";
+		$sql .= " t.fullpath_orig,";
+		$sql .= " t.description,";
+		$sql .= " t.keywords,";
+		$sql .= " t.cover,";
+		$sql .= " t.position,";
+		$sql .= " t.gen_or_uploaded,";
+		$sql .= " t.extraparams,";
+		$sql .= " t.date_c,";
+		$sql .= " t.date_m,";
+		$sql .= " t.fk_user_c,";
+		$sql .= " t.fk_user_m,";
+		$sql .= " t.acl";
+		$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
+
+		// Manage filter
+		$sqlwhere = array();
+		if (count($filter) > 0) {
+			foreach ($filter as $key => $value) {
+				$sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
+			}
+		}
+		$sql.= ' WHERE 1 = 1';
+		/* Fetching this table depends on filepath+filename, it must not depends on entity
+		if (! empty($conf->multicompany->enabled)) {
+		    $sql .= " AND entity IN (" . getEntity("ecmfiles", 1) . ")";
+		}*/
+		if (count($sqlwhere) > 0) {
+			$sql .= ' AND ' . implode(' '.$filtermode.' ', $sqlwhere);
+		}
+		if (!empty($sortfield)) {
+			$sql .= $this->db->order($sortfield,$sortorder);
+		}
+		if (!empty($limit)) {
+            $sql .=  ' ' . $this->db->plimit($limit, $offset);
+		}
+
+		$this->lines = array();
+
+		$resql = $this->db->query($sql);
+		if ($resql) {
+			$num = $this->db->num_rows($resql);
+
+			while ($obj = $this->db->fetch_object($resql)) {
+				$line = new EcmfilesLine();
+
+				$line->id = $obj->rowid;
+				
+				$line->label = $obj->label;
+				$line->entity = $obj->entity;
+				$line->filename = $obj->filename;
+				$line->filepath = $obj->filepath;
+				$line->fullpath_orig = $obj->fullpath_orig;
+				$line->description = $obj->description;
+				$line->keywords = $obj->keywords;
+				$line->cover = $obj->cover;
+				$line->position = $obj->position;
+				$line->gen_or_uploaded = $obj->gen_or_uploaded;
+				$line->extraparams = $obj->extraparams;
+				$line->date_c = $this->db->jdate($obj->date_c);
+				$line->date_m = $this->db->jdate($obj->date_m);
+				$line->fk_user_c = $obj->fk_user_c;
+				$line->fk_user_m = $obj->fk_user_m;
+				$line->acl = $obj->acl;
+			}
+			$this->db->free($resql);
+
+			return $num;
+		} else {
+			$this->errors[] = 'Error ' . $this->db->lasterror();
+			dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
+
+			return - 1;
+		}
+	}
+
+	/**
+	 * Update object into database
+	 *
+	 * @param  User $user      User that modifies
+	 * @param  bool $notrigger false=launch triggers after, true=disable triggers
+	 *
+	 * @return int <0 if KO, >0 if OK
+	 */
+	public function update(User $user, $notrigger = false)
+	{
+		$error = 0;
+
+		dol_syslog(__METHOD__, LOG_DEBUG);
+
+		// Clean parameters
+		
+		if (isset($this->label)) {
+			 $this->label = trim($this->label);
+		}
+		if (isset($this->entity)) {
+			 $this->entity = trim($this->entity);
+		}
+		if (isset($this->filename)) {
+			 $this->filename = trim($this->filename);
+		}
+		if (isset($this->filepath)) {
+			 $this->filepath = trim($this->filepath);
+		}
+		if (isset($this->fullpath_orig)) {
+			 $this->fullpath_orig = trim($this->fullpath_orig);
+		}
+		if (isset($this->description)) {
+			 $this->description = trim($this->description);
+		}
+		if (isset($this->keywords)) {
+			 $this->keywords = trim($this->keywords);
+		}
+		if (isset($this->cover)) {
+			 $this->cover = trim($this->cover);
+		}
+		if (isset($this->gen_or_uploaded)) {
+			 $this->gen_or_uploaded = trim($this->gen_or_uploaded);
+		}
+		if (isset($this->extraparams)) {
+			 $this->extraparams = trim($this->extraparams);
+		}
+		if (isset($this->fk_user_c)) {
+			 $this->fk_user_c = trim($this->fk_user_c);
+		}
+		if (isset($this->fk_user_m)) {
+			 $this->fk_user_m = trim($this->fk_user_m);
+		}
+		if (isset($this->acl)) {
+			 $this->acl = trim($this->acl);
+		}
+
+
+		// Check parameters
+		// Put here code to add a control on parameters values
+
+		// Update request
+		$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET';
+		$sql .= ' label = '.(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").',';
+		$sql .= ' entity = '.(isset($this->entity)?$this->entity:$conf->entity).',';
+		$sql .= ' filename = '.(isset($this->filename)?"'".$this->db->escape($this->filename)."'":"null").',';
+		$sql .= ' filepath = '.(isset($this->filepath)?"'".$this->db->escape($this->filepath)."'":"null").',';
+		$sql .= ' fullpath_orig = '.(isset($this->fullpath_orig)?"'".$this->db->escape($this->fullpath_orig)."'":"null").',';
+		$sql .= ' description = '.(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").',';
+		$sql .= ' keywords = '.(isset($this->keywords)?"'".$this->db->escape($this->keywords)."'":"null").',';
+		$sql .= ' cover = '.(isset($this->cover)?"'".$this->db->escape($this->cover)."'":"null").',';
+		$sql .= ' position = '.(isset($this->position)?$this->db->escape($this->position):"0").',';
+		$sql .= ' gen_or_uploaded = '.(isset($this->gen_or_uploaded)?"'".$this->db->escape($this->gen_or_uploaded)."'":"null").',';
+		$sql .= ' extraparams = '.(isset($this->extraparams)?"'".$this->db->escape($this->extraparams)."'":"null").',';
+		$sql .= ' date_c = '.(! isset($this->date_c) || dol_strlen($this->date_c) != 0 ? "'".$this->db->idate($this->date_c)."'" : 'null').',';
+		//$sql .= ' date_m = '.(! isset($this->date_m) || dol_strlen($this->date_m) != 0 ? "'".$this->db->idate($this->date_m)."'" : 'null').','; // Field automatically updated
+		$sql .= ' fk_user_c = '.(isset($this->fk_user_c)?$this->fk_user_c:"null").',';
+		$sql .= ' fk_user_m = '.($this->fk_user_m > 0?$this->fk_user_m:$user->id).',';
+		$sql .= ' acl = '.(isset($this->acl)?"'".$this->db->escape($this->acl)."'":"null");
+		$sql .= ' WHERE rowid=' . $this->id;
+
+		$this->db->begin();
+
+		$resql = $this->db->query($sql);
+		if (!$resql) {
+			$error ++;
+			$this->errors[] = 'Error ' . $this->db->lasterror();
+			dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
+		}
+
+		if (!$error && !$notrigger) {
+			// Uncomment this and change MYOBJECT to your own tag if you
+			// want this action calls a trigger.
+
+			//// Call triggers
+			//$result=$this->call_trigger('MYOBJECT_MODIFY',$user);
+			//if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
+			//// End call triggers
+		}
+
+		// Commit or rollback
+		if ($error) {
+			$this->db->rollback();
+
+			return - 1 * $error;
+		} else {
+			$this->db->commit();
+
+			return 1;
+		}
+	}
+
+	/**
+	 * Delete object in database
+	 *
+	 * @param User $user      User that deletes
+	 * @param bool $notrigger false=launch triggers after, true=disable triggers
+	 *
+	 * @return int <0 if KO, >0 if OK
+	 */
+	public function delete(User $user, $notrigger = false)
+	{
+		dol_syslog(__METHOD__, LOG_DEBUG);
+
+		$error = 0;
+
+		$this->db->begin();
+
+		if (!$error) {
+			if (!$notrigger) {
+				// Uncomment this and change MYOBJECT to your own tag if you
+				// want this action calls a trigger.
+
+				//// Call triggers
+				//$result=$this->call_trigger('MYOBJECT_DELETE',$user);
+				//if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
+				//// End call triggers
+			}
+		}
+
+		// If you need to delete child tables to, you can insert them here
+		
+		if (!$error) {
+			$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
+			$sql .= ' WHERE rowid=' . $this->id;
+
+			$resql = $this->db->query($sql);
+			if (!$resql) {
+				$error ++;
+				$this->errors[] = 'Error ' . $this->db->lasterror();
+				dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
+			}
+		}
+
+		// Commit or rollback
+		if ($error) {
+			$this->db->rollback();
+
+			return - 1 * $error;
+		} else {
+			$this->db->commit();
+
+			return 1;
+		}
+	}
+
+	/**
+	 * Load an object from its id and create a new one in database
+	 *
+	 * @param int $fromid Id of object to clone
+	 *
+	 * @return int New id of clone
+	 */
+	public function createFromClone($fromid)
+	{
+		dol_syslog(__METHOD__, LOG_DEBUG);
+
+		global $user;
+		$error = 0;
+		$object = new Ecmfiles($this->db);
+
+		$this->db->begin();
+
+		// Load source object
+		$object->fetch($fromid);
+		// Reset object
+		$object->id = 0;
+
+		// Clear fields
+		// ...
+
+		// Create clone
+		$result = $object->create($user);
+
+		// Other options
+		if ($result < 0) {
+			$error ++;
+			$this->errors = $object->errors;
+			dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
+		}
+
+		// End
+		if (!$error) {
+			$this->db->commit();
+
+			return $object->id;
+		} else {
+			$this->db->rollback();
+
+			return - 1;
+		}
+	}
+
+	/**
+	 *  Return a link to the object card (with optionaly the picto)
+	 *
+	 *	@param	int		$withpicto			Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
+	 *	@param	string	$option				On what the link point to
+     *  @param	int  	$notooltip			1=Disable tooltip
+     *  @param	int		$maxlen				Max length of visible user name
+     *  @param  string  $morecss            Add more css on link
+	 *	@return	string						String with URL
+	 */
+	function getNomUrl($withpicto=0, $option='', $notooltip=0, $maxlen=24, $morecss='')
+	{
+		global $db, $conf, $langs;
+        global $dolibarr_main_authentication, $dolibarr_main_demo;
+        global $menumanager;
+
+        if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
+        
+        $result = '';
+        $companylink = '';
+
+        $label = '<u>' . $langs->trans("MyModule") . '</u>';
+        $label.= '<br>';
+        $label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
+
+        $url = DOL_URL_ROOT.'/ecm/'.$this->table_name.'_card.php?id='.$this->id;
+        
+        $linkclose='';
+        if (empty($notooltip))
+        {
+            if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
+            {
+                $label=$langs->trans("ShowProject");
+                $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
+            }
+            $linkclose.=' title="'.dol_escape_htmltag($label, 1).'"';
+            $linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"';
+        }
+        else $linkclose = ($morecss?' class="'.$morecss.'"':'');
+        
+		$linkstart = '<a href="'.$url.'"';
+		$linkstart.=$linkclose.'>';
+		$linkend='</a>';
+
+        if ($withpicto)
+        {
+            $result.=($linkstart.img_object(($notooltip?'':$label), 'label', ($notooltip?'':'class="classfortooltip"')).$linkend);
+            if ($withpicto != 2) $result.=' ';
+		}
+		$result.= $linkstart . $this->ref . $linkend;
+		return $result;
+	}
+
+	/**
+	 *  Retourne le libelle du status d'un user (actif, inactif)
+	 *
+	 *  @param	int		$mode          0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
+	 *  @return	string 			       Label of status
+	 */
+	function getLibStatut($mode=0)
+	{
+		return $this->LibStatut($this->status,$mode);
+	}
+
+	/**
+	 *  Return the status
+	 *
+	 *  @param	int		$status        	Id status
+	 *  @param  int		$mode          	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 5=Long label + Picto
+	 *  @return string 			       	Label of status
+	 */
+	static function LibStatut($status,$mode=0)
+	{
+		global $langs;
+
+		if ($mode == 0)
+		{
+			$prefix='';
+			if ($status == 1) return $langs->trans('Enabled');
+			if ($status == 0) return $langs->trans('Disabled');
+		}
+		if ($mode == 1)
+		{
+			if ($status == 1) return $langs->trans('Enabled');
+			if ($status == 0) return $langs->trans('Disabled');
+		}
+		if ($mode == 2)
+		{
+			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
+			if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
+		}
+		if ($mode == 3)
+		{
+			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4');
+			if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5');
+		}
+		if ($mode == 4)
+		{
+			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
+			if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
+		}
+		if ($mode == 5)
+		{
+			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
+			if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
+		}
+		if ($mode == 6)
+		{
+			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
+			if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
+		}
+	}
+
+
+	/**
+	 * Initialise object with example values
+	 * Id must be 0 if object instance is a specimen
+	 *
+	 * @return void
+	 */
+	public function initAsSpecimen()
+	{
+	    global $conf,$user;
+	    
+		$this->id = 0;
+		
+		$this->label = '0a1b2c3e4f59999999';
+		$this->entity = '1';
+		$this->filename = 'myspecimenfilefile.pdf';
+		$this->filepath = '/aaa/bbb';
+		$this->fullpath_orig = 'c:/file on my disk.pdf';
+		$this->description = 'This is a long description of file';
+		$this->keywords = 'key1,key2';
+		$this->cover = '1';
+		$this->position = '5';
+		$this->gen_or_uploaded = 'uploaded';
+		$this->extraparams = '';
+		$this->date_c = (dol_now() - 3600 * 24 * 10);
+		$this->date_m = '';
+		$this->fk_user_c = $user->id;
+		$this->fk_user_m = '';
+		$this->acl = '';
+	}
+
+}
+

+ 1 - 1
htdocs/filefunc.inc.php

@@ -31,7 +31,7 @@
  */
 
 if (! defined('DOL_APPLICATION_TITLE')) define('DOL_APPLICATION_TITLE','Dolibarr');
-if (! defined('DOL_VERSION')) define('DOL_VERSION','5.0.0-rc1');                         // a.b.c-alpha, a.b.c-beta, a.b.c-rcX or a.b.c
+if (! defined('DOL_VERSION')) define('DOL_VERSION','6.0.0-alpha');
 
 if (! defined('EURO')) define('EURO',chr(128));
 

+ 1 - 1
htdocs/fourn/class/fournisseur.commande.dispatch.class.php

@@ -596,7 +596,7 @@ class CommandeFournisseurDispatch extends CommonObject
 			$sql .= $this->db->order($sortfield,$sortorder);
 		}
 		if (!empty($limit)) {
-			$sql .=  ' ' . $this->db->plimit($limit + 1, $offset);
+			$sql .=  ' ' . $this->db->plimit($limit, $offset);
 		}
 		$this->lines = array();
 

+ 11 - 11
htdocs/hrm/class/establishment.class.php

@@ -34,20 +34,20 @@ class Establishment extends CommonObject
 	public $fk_element = 'fk_establishment';
 	protected $ismultientitymanaged = 1;	// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
 
-	var $id;
-	var $rowid;
+	public $id;
+	public $rowid;
 
-	var $name;
-	var $address;
-	var $zip;
-	var $town;
-	var $status;		// 0=open, 1=closed
-	var $entity;
+	public $name;
+	public $address;
+	public $zip;
+	public $town;
+	public $status;		// 0=open, 1=closed
+	public $entity;
 
-	var $country_id;
+	public $country_id;
 
-	var $statuts=array();
-	var $statuts_short=array();
+	public $statuts=array();
+	public $statuts_short=array();
 
 	/**
 	 * Constructor

+ 2 - 1
htdocs/install/check.php

@@ -411,7 +411,8 @@ else
 								array('from'=>'3.7.0', 'to'=>'3.8.0'),
 		                        array('from'=>'3.8.0', 'to'=>'3.9.0'),
 		                        array('from'=>'3.9.0', 'to'=>'4.0.0'),
-		                        array('from'=>'4.0.0', 'to'=>'5.0.0')
+		                        array('from'=>'4.0.0', 'to'=>'5.0.0'),
+		                        array('from'=>'5.0.0', 'to'=>'6.0.0')
 		);
 
 		$count=0;

+ 3 - 0
htdocs/install/mysql/data/llx_c_action_trigger.sql

@@ -77,6 +77,9 @@ insert into llx_c_action_trigger (code,label,description,elementtype,rang) value
 insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('FICHINTER_CLASSIFY_UNBILLED','Intervention set unbilled','Executed when a intervention is set to unbilled (when option FICHINTER_CLASSIFY_BILLED is set)','ficheinter',19);
 insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('FICHINTER_REOPEN','Intervention opened','Executed when a intervention is re-opened','ficheinter',19);
 insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('FICHINTER_SENTBYMAIL','Intervention sent by mail','Executed when a intervention is sent by mail','ficheinter',19);
+insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PRODUCT_CREATE','Product or service created','Executed when a product or sevice is created','product',30);
+insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PRODUCT_MODIFY','Product or service modified','Executed when a product or sevice is modified','product',30);
+insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PRODUCT_DELETE','Product or service deleted','Executed when a product or sevice is deleted','product',30);
 -- actions not enabled by default (no constant created for that) when we enable module agenda 
 insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PROJECT_CREATE','Project creation','Executed when a project is created','project',140);
 insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PROJECT_MODIFY','Project modified','Executed when a project is modified','project',141);

+ 48 - 0
htdocs/install/mysql/migration/5.0.0-6.0.0.sql

@@ -0,0 +1,48 @@
+--
+-- Be carefull to requests order.
+-- This file must be loaded by calling /install/index.php page
+-- when current version is 5.0.0 or higher.
+--
+-- To rename a table:       ALTER TABLE llx_table RENAME TO llx_table_new;
+-- To add a column:         ALTER TABLE llx_table ADD COLUMN newcol varchar(60) NOT NULL DEFAULT '0' AFTER existingcol;
+-- To rename a column:      ALTER TABLE llx_table CHANGE COLUMN oldname newname varchar(60);
+-- To drop a column:        ALTER TABLE llx_table DROP COLUMN oldname;
+-- To change type of field: ALTER TABLE llx_table MODIFY COLUMN name varchar(60);
+-- To drop a foreign key:   ALTER TABLE llx_table DROP FOREIGN KEY fk_name;
+-- To drop an index:        -- VMYSQL4.0 DROP INDEX nomindex on llx_table
+-- To drop an index:        -- VPGSQL8.0 DROP INDEX nomindex
+-- To restrict request to Mysql version x.y minimum use -- VMYSQLx.y
+-- To restrict request to Pgsql version x.y minimum use -- VPGSQLx.y
+-- To make pk to be auto increment (mysql):    -- VMYSQL4.3 ALTER TABLE llx_c_shipment_mode CHANGE COLUMN rowid rowid INTEGER NOT NULL AUTO_INCREMENT;
+-- To make pk to be auto increment (postgres): -- VPGSQL8.2 NOT POSSIBLE. MUST DELETE/CREATE TABLE
+-- To set a field as NULL:                     -- VMYSQL4.3 ALTER TABLE llx_table MODIFY COLUMN name varchar(60) NULL;
+-- To set a field as NULL:                     -- VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name DROP NOT NULL;
+-- To set a field as NOT NULL:                 -- VMYSQL4.3 ALTER TABLE llx_table MODIFY COLUMN name varchar(60) NOT NULL;
+-- To set a field as NOT NULL:                 -- VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name SET NOT NULL;
+-- To set a field as default NULL:             -- VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name SET DEFAULT NULL;
+-- Note: fields with type BLOB/TEXT can't have default value.
+-- -- VPGSQL8.2 DELETE FROM llx_usergroup_user      WHERE fk_user      NOT IN (SELECT rowid from llx_user);
+-- -- VMYSQL4.1 DELETE FROM llx_usergroup_user      WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup);
+
+
+ALTER TABLE llx_ecm_files ADD COLUMN ref varchar(128) AFTER rowid;
+ALTER TABLE llx_ecm_files CHANGE COLUMN fullpath filepath varchar(255);
+ALTER TABLE llx_ecm_files CHANGE COLUMN filepath filepath varchar(255);
+ALTER TABLE llx_ecm_files ADD COLUMN position integer;
+ALTER TABLE llx_ecm_files ADD COLUMN keyword varchar(750);
+ALTER TABLE llx_ecm_files CHANGE COLUMN keyword keyword varchar(750);
+ALTER TABLE llx_ecm_files ADD COLUMN gen_or_uploaded varchar(12);
+
+ALTER TABLE llx_ecm_files DROP INDEX uk_ecm_files;
+ALTER TABLE llx_ecm_files ADD UNIQUE INDEX uk_ecm_files (filepath, filename, entity);
+
+ALTER TABLE llx_ecm_files ADD INDEX idx_ecm_files_label (label);
+
+
+insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PRODUCT_CREATE','Product or service created','Executed when a product or sevice is created','product',30);
+insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PRODUCT_MODIFY','Product or service modified','Executed when a product or sevice is modified','product',30);
+insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PRODUCT_DELETE','Product or service deleted','Executed when a product or sevice is deleted','product',30);
+
+
+ALTER TABLE llx_loan ADD COLUMN fk_projet integer DEFAULT NULL;
+

+ 6 - 2
htdocs/install/mysql/tables/llx_ecm_files.key.sql

@@ -1,5 +1,5 @@
 -- ============================================================================
--- Copyright (C) 2015	Laurent Destailleur	<eldy@users.sourceforge.net>
+-- Copyright (C) 2017	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
@@ -17,5 +17,9 @@
 -- ============================================================================
 
 
-ALTER TABLE llx_ecm_files ADD UNIQUE INDEX uk_ecm_files (label, entity);
+ALTER TABLE llx_ecm_files ADD UNIQUE INDEX uk_ecm_files (filepath, filename);
+ALTER TABLE llx_ecm_files ADD INDEX idx_ecm_files_label (label);
+
 --ALTER TABLE llx_ecm_files ADD UNIQUE INDEX uk_ecm_files_fullpath(fullpath); Disabled, mysql limits size of index
+
+

+ 5 - 3
htdocs/install/mysql/tables/llx_ecm_files.sql

@@ -19,14 +19,16 @@
 CREATE TABLE llx_ecm_files
 (
   rowid				integer AUTO_INCREMENT PRIMARY KEY,
-  label				varchar(64) NOT NULL,
+  ref				varchar(128),					-- Not used yet. Will contains a hash id from filename+filepath
+  label				varchar(64) NOT NULL,			-- label contains a md5
   entity			integer DEFAULT 1 NOT NULL,		-- multi company id
+  filepath    		varchar(255) NOT NULL,   	    -- relative to dolibarr document dir. Example module/def
   filename          varchar(255) NOT NULL,			-- file name only without any directory
-  fullpath    		varchar(750) NOT NULL,   	    -- relative to dolibarr document dir. example abc/def/myfile
   fullpath_orig		varchar(750),	                -- full path of original filename, when file is uploaded from a local computer
   description		text,
-  keywords          text,                           -- list of keywords, separated with comma
+  keywords          varchar(750),                   -- list of keywords, separated with comma. Must be limited to most important keywords.
   cover             text,                           -- is this file a file to use for a cover
+  position          integer,                        -- position of file among others
   gen_or_uploaded   varchar(12),                    -- 'generated' or 'uploaded' 
   extraparams		varchar(255),					-- for stocking other parameters with json format
   date_c			datetime,

+ 3 - 1
htdocs/install/mysql/tables/llx_loan.sql

@@ -45,7 +45,9 @@ create table llx_loan
   accountancy_account_insurance	varchar(32),
   accountancy_account_interest	varchar(32),
   
+  fk_projet						integer DEFAULT NULL,
+  
   fk_user_author				integer DEFAULT NULL,
-  fk_user_modif					integer DEFAULT NULL,
+  fk_user_modif					integer DEFAULT NULL
   active						tinyint DEFAULT 1  NOT NULL
 )ENGINE=innodb;

+ 0 - 1
htdocs/install/mysql/tables/llx_website_pages.sql

@@ -28,6 +28,5 @@ CREATE TABLE llx_website_page
 	content		  mediumtext,		-- text is not enough in size
     status        integer,
     date_creation     datetime,
-    date_modification datetime,
 	tms           timestamp
 ) ENGINE=innodb;

+ 1 - 1
htdocs/langs/en_US/admin.lang

@@ -998,7 +998,7 @@ TriggerAlwaysActive=Triggers in this file are always active, whatever are the ac
 TriggerActiveAsModuleActive=Triggers in this file are active as module <b>%s</b> is enabled.
 GeneratedPasswordDesc=Define here which rule you want to use to generate new password if you ask to have auto generated password
 DictionaryDesc=Insert all reference data. You can add your values to the default.
-ConstDesc=This page allows you to edit all other parameters not available in previous pages. These are mostly reserved parameters for developers or advanced troubleshooting.
+ConstDesc=This page allows you to edit all other parameters not available in previous pages. These are mostly reserved parameters for developers or advanced troubleshooting. For a list of options <a href="https://wiki.dolibarr.org/index.php/Setup_Other#List_of_known_hidden_options" title="External Site - opens in a new window" target="_blank">check here</a>.
 MiscellaneousDesc=All other security related parameters are defined here.
 LimitsSetup=Limits/Precision setup
 LimitsDesc=You can define limits, precisions and optimisations used by Dolibarr here

+ 1 - 0
htdocs/langs/en_US/agenda.lang

@@ -2,6 +2,7 @@
 IdAgenda=ID event
 Actions=Events
 Agenda=Agenda
+TMenuAgenda=Agenda
 Agendas=Agendas
 LocalAgenda=Internal calendar
 ActionsOwnedBy=Event owned by 

+ 1 - 0
htdocs/langs/en_US/loan.lang

@@ -43,6 +43,7 @@ LoanCalcDesc=This <b>mortgage calculator</b> can be used to figure out monthly p
 GoToInterest=%s will go towards INTEREST
 GoToPrincipal=%s will go towards PRINCIPAL
 YouWillSpend=You will spend %s in year %s
+ListLoanAssociatedProject=List of loan associated with the project
 # Admin
 ConfigLoan=Configuration of the module loan
 LOAN_ACCOUNTING_ACCOUNT_CAPITAL=Accounting account capital by default

+ 2 - 2
htdocs/langs/en_US/main.lang

@@ -788,8 +788,8 @@ SetRef=Set ref
 Select2ResultFoundUseArrows=Some results found. Use arrows to select.
 Select2NotFound=No result found
 Select2Enter=Enter
-Select2MoreCharacter=or more character
-Select2MoreCharacters=or more characters
+Select2MoreCharacter=or more characters<br /><br /><strong>Search syntax:</strong><br /><kbd><strong> |</strong></kbd><kbd> OR</kbd> (a|b)<br /><kbd><strong>*</strong></kbd><kbd> Any character</kbd> (a*b)<br /><kbd><strong>^</strong></kbd><kbd> Start with</kbd> (^ab)<br /><kbd><strong>$</strong></kbd><kbd> End with</kbd> (ab$)<br />
+Select2MoreCharacters=or more characters<br /><br /><strong>Search syntax:</strong><br /><kbd><strong> |</strong></kbd><kbd> OR</kbd> (a|b)<br /><kbd><strong>*</strong></kbd><kbd> Any character</kbd> (a*b)<br /><kbd><strong>^</strong></kbd><kbd> Start with</kbd> (^ab)<br /><kbd><strong>$</strong></kbd><kbd> End with</kbd> (ab$)<br />
 Select2LoadingMoreResults=Loading more results...
 Select2SearchInProgress=Search in progress...
 SearchIntoThirdparties=Thirdparties

+ 1 - 0
htdocs/langs/en_US/other.lang

@@ -2,6 +2,7 @@
 SecurityCode=Security code
 NumberingShort=N°
 Tools=Tools
+TMenuTools=Tools
 ToolsDesc=All miscellaneous tools not included in other menu entries are collected here.<br /><br />All the tools can be reached in the left menu.
 Birthday=Birthday
 BirthdayDate=Birthday date

+ 2 - 0
htdocs/langs/en_US/products.lang

@@ -5,6 +5,8 @@ ProductLabelTranslated=Translated product label
 ProductDescriptionTranslated=Translated product description
 ProductNoteTranslated=Translated product note
 ProductServiceCard=Products/Services card
+TMenuProducts=Products
+TMenuServices=Services
 Products=Products
 Services=Services
 Product=Product

+ 233 - 159
htdocs/loan/card.php

@@ -28,6 +28,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
 if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
 if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/html.formventilation.class.php';
+require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
 
 $langs->load("compta");
 $langs->load("bills");
@@ -45,156 +47,175 @@ $result = restrictedArea($user, 'loan', $id, '','');
 
 $object = new Loan($db);
 
+$hookmanager->initHooks(array('loancard','globalcard'));
+
+
 /*
  * Actions
  */
 
-// Classify paid
-if ($action == 'confirm_paid' && $confirm == 'yes')
+$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');
+if (empty($reshook))
 {
-	$object->fetch($id);
-	$result = $object->set_paid($user);
-    if ($result > 0)
+    // Classify paid
+    if ($action == 'confirm_paid' && $confirm == 'yes')
     {
-        setEventMessages($langs->trans('LoanPaid'), null, 'mesgs');
+    	$object->fetch($id);
+    	$result = $object->set_paid($user);
+        if ($result > 0)
+        {
+            setEventMessages($langs->trans('LoanPaid'), null, 'mesgs');
+        }
+        else
+        {
+            setEventMessages($loan->error, null, 'errors');
+        }
     }
-    else
+    
+    // Delete loan
+    if ($action == 'confirm_delete' && $confirm == 'yes')
     {
-        setEventMessages($loan->error, null, 'errors');
+    	$object->fetch($id);
+    	$result=$object->delete($user);
+    	if ($result > 0)
+    	{
+    		setEventMessages($langs->trans('LoanDeleted'), null, 'mesgs');
+    		header("Location: index.php");
+    		exit;
+    	}
+    	else
+    	{
+    		setEventMessages($loan->error, null, 'errors');
+    	}
     }
-}
-
-// Delete loan
-if ($action == 'confirm_delete' && $confirm == 'yes')
-{
-	$object->fetch($id);
-	$result=$object->delete($user);
-	if ($result > 0)
-	{
-		setEventMessages($langs->trans('LoanDeleted'), null, 'mesgs');
-		header("Location: index.php");
-		exit;
-	}
-	else
-	{
-		setEventMessages($loan->error, null, 'errors');
-	}
-}
-
-// Add loan
-if ($action == 'add' && $user->rights->loan->write)
-{
-	if (! $cancel)
-	{
-		$datestart	= dol_mktime(12, 0, 0, GETPOST('startmonth','int'), GETPOST('startday','int'), GETPOST('startyear','int'));
-		$dateend	= dol_mktime(12, 0, 0, GETPOST('endmonth','int'), GETPOST('endday','int'), GETPOST('endyear','int'));
-		$capital 	= price2num(GETPOST('capital'));
-
-		if (! $capital)
-		{
-			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("LoanCapital")), null, 'errors');
-			$action = 'create';
-		}
-		else
-		{
-			$object->label					= GETPOST('label');
-			$object->fk_bank				= GETPOST('accountid');
-			$object->capital				= $capital;
-			$object->datestart				= $datestart;
-			$object->dateend				= $dateend;
-			$object->nbterm					= GETPOST('nbterm');
-			$object->rate					= GETPOST('rate');
-			$object->note_private 			= GETPOST('note_private');
-			$object->note_public 			= GETPOST('note_public');
-
-			$accountancy_account_capital	= GETPOST('accountancy_account_capital');
-			$accountancy_account_insurance	= GETPOST('accountancy_account_insurance');
-			$accountancy_account_interest	= GETPOST('accountancy_account_interest');
-
-			if ($accountancy_account_capital <= 0) { $object->account_capital = ''; } else { $object->account_capital = $accountancy_account_capital; }
-			if ($accountancy_account_insurance <= 0) { $object->account_insurance = ''; } else { $object->account_insurance = $accountancy_account_insurance; }
-			if ($accountancy_account_interest <= 0) { $object->account_interest = ''; } else { $object->account_interest = $accountancy_account_interest; }
-
-			$id=$object->create($user);
-			if ($id <= 0)
-			{
-				setEventMessages($object->error, $object->errors, 'errors');
-			}
-		}
-	}
-	else
-	{
-		header("Location: index.php");
-		exit();
-	}
-}
-
-// Update record
-else if ($action == 'update' && $user->rights->loan->write)
-{
-	if (! $cancel)
-	{
-		$result = $object->fetch($id);
-		$object->fetch($id);
-
-		$datestart	= dol_mktime(12, 0, 0, GETPOST('startmonth','int'), GETPOST('startday','int'), GETPOST('startyear','int'));
-		$dateend	= dol_mktime(12, 0, 0, GETPOST('endmonth','int'), GETPOST('endday','int'), GETPOST('endyear','int'));
-		$capital 	= price2num(GETPOST('capital'));
-
-		if (! $capital)
-		{
-			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("LoanCapital")), null, 'errors');
-			$action = 'edit';
-		}
-		else
-		{
-			$object->datestart	= $datestart;
-			$object->dateend	= $dateend;
-			$object->capital	= $capital;
-			$object->nbterm		= GETPOST("nbterm");
-			$object->rate		= GETPOST("rate");
-
-			$accountancy_account_capital	= GETPOST('accountancy_account_capital');
-			$accountancy_account_insurance	= GETPOST('accountancy_account_insurance');
-			$accountancy_account_interest	= GETPOST('accountancy_account_interest');
-
-			if ($accountancy_account_capital <= 0) { $object->account_capital = ''; } else { $object->account_capital = $accountancy_account_capital; }
-			if ($accountancy_account_insurance <= 0) { $object->account_insurance = ''; } else { $object->account_insurance = $accountancy_account_insurance; }
-			if ($accountancy_account_interest <= 0) { $object->account_interest = ''; } else { $object->account_interest = $accountancy_account_interest; }
-		}
-
-        $result = $object->update($user);
-
-        if ($result > 0)
-        {
-            header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
-            exit;
+    
+    // Add loan
+    if ($action == 'add' && $user->rights->loan->write)
+    {
+    	if (! $cancel)
+    	{
+    		$datestart	= dol_mktime(12, 0, 0, GETPOST('startmonth','int'), GETPOST('startday','int'), GETPOST('startyear','int'));
+    		$dateend	= dol_mktime(12, 0, 0, GETPOST('endmonth','int'), GETPOST('endday','int'), GETPOST('endyear','int'));
+    		$capital 	= price2num(GETPOST('capital'));
+    
+    		if (! $capital)
+    		{
+    			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("LoanCapital")), null, 'errors');
+    			$action = 'create';
+    		}
+    		else
+    		{
+    			$object->label					= GETPOST('label');
+    			$object->fk_bank				= GETPOST('accountid');
+    			$object->capital				= $capital;
+    			$object->datestart				= $datestart;
+    			$object->dateend				= $dateend;
+    			$object->nbterm					= GETPOST('nbterm');
+    			$object->rate					= GETPOST('rate');
+    			$object->note_private 			= GETPOST('note_private');
+    			$object->note_public 			= GETPOST('note_public');
+    			$object->fk_project 			= GETPOST('fk_project');
+    			
+    			$accountancy_account_capital	= GETPOST('accountancy_account_capital');
+    			$accountancy_account_insurance	= GETPOST('accountancy_account_insurance');
+    			$accountancy_account_interest	= GETPOST('accountancy_account_interest');
+    
+    			if ($accountancy_account_capital <= 0) { $object->account_capital = ''; } else { $object->account_capital = $accountancy_account_capital; }
+    			if ($accountancy_account_insurance <= 0) { $object->account_insurance = ''; } else { $object->account_insurance = $accountancy_account_insurance; }
+    			if ($accountancy_account_interest <= 0) { $object->account_interest = ''; } else { $object->account_interest = $accountancy_account_interest; }
+    
+    			$id=$object->create($user);
+    			if ($id <= 0)
+    			{
+    				setEventMessages($object->error, $object->errors, 'errors');
+    			}
+    		}
+    	}
+    	else
+    	{
+    		header("Location: index.php");
+    		exit();
+    	}
+    }
+    
+    // Update record
+    else if ($action == 'update' && $user->rights->loan->write)
+    {
+    	if (! $cancel)
+    	{
+    		$result = $object->fetch($id);
+
+    		$datestart	= dol_mktime(12, 0, 0, GETPOST('startmonth','int'), GETPOST('startday','int'), GETPOST('startyear','int'));
+    		$dateend	= dol_mktime(12, 0, 0, GETPOST('endmonth','int'), GETPOST('endday','int'), GETPOST('endyear','int'));
+    		$capital 	= price2num(GETPOST('capital'));
+    
+    		if (! $capital)
+    		{
+    			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("LoanCapital")), null, 'errors');
+    			$action = 'edit';
+    		}
+    		else
+    		{
+				$object->datestart	= $datestart;
+				$object->dateend	= $dateend;
+				$object->capital	= $capital;
+    			$object->nbterm		= GETPOST("nbterm");
+    			$object->rate		= GETPOST("rate");
+
+				$accountancy_account_capital	= GETPOST('accountancy_account_capital');
+				$accountancy_account_insurance	= GETPOST('accountancy_account_insurance');
+				$accountancy_account_interest	= GETPOST('accountancy_account_interest');
+	
+				if ($accountancy_account_capital <= 0) { $object->account_capital = ''; } else { $object->account_capital = $accountancy_account_capital; }
+				if ($accountancy_account_insurance <= 0) { $object->account_insurance = ''; } else { $object->account_insurance = $accountancy_account_insurance; }
+				if ($accountancy_account_interest <= 0) { $object->account_interest = ''; } else { $object->account_interest = $accountancy_account_interest; }
+    		}
+    
+            $result = $object->update($user);
+    
+            if ($result > 0)
+            {
+                header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
+                exit;
+            }
+            else
+            {
+    	        setEventMessages($object->error, $object->errors, 'errors');
+            }
         }
         else
         {
-	        setEventMessages($object->error, $object->errors, 'errors');
+            header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
+            exit;
         }
     }
-    else
+    
+	// Link to a project
+	if ($action == 'classin' && $user->rights->loan->write)
+	{
+    	$object->fetch($id);
+	    $result = $object->setProject(GETPOST('projectid'));
+		if ($result < 0)
+		    setEventMessages($object->error, $object->errors, 'errors');
+	}
+
+    if ($action == 'setlabel' && $user->rights->loan->write)
     {
-        header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
-        exit;
+    	$object->fetch($id);
+    	$result = $object->setValueFrom('label', GETPOST('label'), '', '', 'text', '', $user, 'LOAN_MODIFY');
+    	if ($result < 0)
+    	setEventMessages($object->error, $object->errors, 'errors');
     }
 }
 
-if ($action == 'setlabel' && $user->rights->loan->write)
-{
-	$object->fetch($id);
-	$result = $object->setValueFrom('label', GETPOST('label'), '', '', 'text', '', $user, 'LOAN_MODIFY');
-	if ($result < 0)
-	setEventMessages($object->error, $object->errors, 'errors');
-}
 
 /*
  * View
  */
 
 $form = new Form($db);
+$formproject = new FormProjets($db);
 if (! empty($conf->accounting->enabled)) $formaccountancy = New FormVentilation($db);
 
 $title = $langs->trans("Loan") . ' - ' . $langs->trans("Card");
@@ -258,6 +279,21 @@ if ($action == 'create')
 	// Rate
     print '<tr><td>'.$langs->trans("Rate").'</td><td><input name="rate" size="5" value="' . GETPOST("rate") . '"> %</td></tr>';
 
+    // Project
+    if (! empty($conf->projet->enabled))
+    {
+		$formproject=new FormProjets($db);
+
+		// Projet associe
+		$langs->load("projects");
+
+    	print '<tr><td>'.$langs->trans("Project").'</td><td>';
+        
+        $numproject=$formproject->select_projects(-1,GETPOST("fk_project"),'fk_project',16,0,1,1);
+        
+        print '</td></tr>';
+    }
+    
     // Note Private
     print '<tr>';
     print '<td class="border" valign="top">'.$langs->trans('NotePrivate').'</td>';
@@ -362,14 +398,48 @@ if ($id > 0)
 
 		dol_fiche_head($head, 'card', $langs->trans("Loan"), 0, 'bill');
 
+		// Loan card
+		
+		$linkback = '<a href="' . DOL_URL_ROOT . '/loan/index.php">' . $langs->trans("BackToList") . '</a>';
+		
 		$morehtmlref='<div class="refidno">';
 		// Ref loan
 		$morehtmlref.=$form->editfieldkey("Label", 'label', $object->label, $object, $user->rights->loan->write, 'string', '', 0, 1);
 		$morehtmlref.=$form->editfieldval("Label", 'label', $object->label, $object, $user->rights->loan->write, 'string', '', null, null, '', 1);
-		$morehtmlref.='</div>';
-
-		$linkback = '<a href="' . DOL_URL_ROOT . '/loan/index.php">' . $langs->trans("BackToList") . '</a>';
-
+		// Project
+	    if (! empty($conf->projet->enabled))
+	    {
+	        $langs->load("projects");
+	        $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
+	        if ($user->rights->commande->creer)
+	        {
+	            if ($action != 'classify')
+	                $morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
+	                if ($action == 'classify') {
+	                    //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
+	                    $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
+	                    $morehtmlref.='<input type="hidden" name="action" value="classin">';
+	                    $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
+	                    $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
+	                    $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
+	                    $morehtmlref.='</form>';
+	                } else {
+	                    $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
+	                }
+	        } else {
+	            if (! empty($object->fk_project)) {
+	                $proj = new Project($db);
+	                $proj->fetch($object->fk_project);
+	                $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
+	                $morehtmlref.=$proj->ref;
+	                $morehtmlref.='</a>';
+	            } else {
+	                $morehtmlref.='';
+	            }
+	        }
+	    }
+	    $morehtmlref.='</div>';
+		
 		$object->totalpaid = $totalpaid;   // To give a chance to dol_banner_tab to use already paid amount to show correct status
 
 		dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
@@ -419,7 +489,7 @@ if ($id > 0)
 		print "</td></tr>";
 
 		// Nbterms
-		print '<tr><td class="titlefield">'.$langs->trans("Nbterms").'</td>';
+		print '<tr><td">'.$langs->trans("Nbterms").'</td>';
 		print '<td>';
 		if ($action == 'edit')
 		{
@@ -432,7 +502,7 @@ if ($id > 0)
 		print '</td></tr>';
 
 		// Rate
-		print '<tr><td class="titlefield">'.$langs->trans("Rate").'</td>';
+		print '<tr><td">'.$langs->trans("Rate").'</td>';
 		print '<td>';
 		if ($action == 'edit')
 		{
@@ -620,33 +690,37 @@ if ($id > 0)
 		 */
 		if ($action != 'edit')
 		{
-			print '<div class="tabsAction">';
-
-			// Edit
-			if ($user->rights->loan->write)
-			{
-				print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a>';
-			}
-
-			// Emit payment
-			if ($object->paid == 0 && ((price2num($object->capital) > 0 && round($staytopay) < 0) || (price2num($object->capital) > 0 && round($staytopay) > 0)) && $user->rights->loan->write)
-			{
-				print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/payment/payment.php?id='.$object->id.'&amp;action=create">'.$langs->trans("DoPayment").'</a>';
-			}
-
-			// Classify 'paid'
-			if ($object->paid == 0 && round($staytopay) <=0 && $user->rights->loan->write)
-			{
-				print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&amp;action=paid">'.$langs->trans("ClassifyPaid").'</a>';
-			}
-
-			// Delete
-			if ($user->rights->loan->delete)
-			{
-				print '<a class="butActionDelete" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
-			}
-
-			print "</div>";
+			$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
+ 			if (empty($reshook))
+            {
+                print '<div class="tabsAction">';
+    
+    			// Edit
+    			if ($user->rights->loan->write)
+    			{
+    				print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a>';
+    			}
+    
+    			// Emit payment
+    			if ($object->paid == 0 && ((price2num($object->capital) > 0 && round($staytopay) < 0) || (price2num($object->capital) > 0 && round($staytopay) > 0)) && $user->rights->loan->write)
+    			{
+    				print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/payment/payment.php?id='.$object->id.'&amp;action=create">'.$langs->trans("DoPayment").'</a>';
+    			}
+    
+    			// Classify 'paid'
+    			if ($object->paid == 0 && round($staytopay) <=0 && $user->rights->loan->write)
+    			{
+    				print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&amp;action=paid">'.$langs->trans("ClassifyPaid").'</a>';
+    			}
+    
+    			// Delete
+    			if ($user->rights->loan->delete)
+    			{
+    				print '<a class="butActionDelete" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
+    			}
+    
+    			print "</div>";
+            }
 		}
 	}
 	else

+ 15 - 9
htdocs/loan/class/loan.class.php

@@ -24,14 +24,15 @@
 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
 
 
-/**     \class      Loan
- *		\brief      Class to manage loan
+/**
+ *      Loan
  */
 class Loan extends CommonObject
 {
     public $element='loan';
     public $table='loan';
     public $table_element='loan';
+
     public $picto = 'bill';
 
     public $rowid;
@@ -51,6 +52,7 @@ class Loan extends CommonObject
     public $fk_bank;
     public $fk_user_creat;
     public $fk_user_modif;
+    public $fk_project;
 
 
     /**
@@ -73,7 +75,7 @@ class Loan extends CommonObject
     function fetch($id)
     {
         $sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend, l.nbterm, l.rate, l.note_private, l.note_public,";
-		$sql.= " l.paid, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest";
+		$sql.= " l.paid, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest, l.fk_projet as fk_project";
         $sql.= " FROM ".MAIN_DB_PREFIX."loan as l";
         $sql.= " WHERE l.rowid = ".$id;
 
@@ -100,6 +102,7 @@ class Loan extends CommonObject
 				$this->account_capital		= $obj->accountancy_account_capital;
 				$this->account_insurance	= $obj->accountancy_account_insurance;
 				$this->account_interest		= $obj->accountancy_account_interest;
+				$this->fk_project			= $obj->fk_project;
 
                 $this->db->free($resql);
 				return 1;
@@ -127,7 +130,7 @@ class Loan extends CommonObject
     function create($user)
     {
     	global $conf;
-		
+
 		$error=0;
 
         $now=dol_now();
@@ -142,6 +145,7 @@ class Loan extends CommonObject
 		if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank);
 		if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat);
 		if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif);
+		if (isset($this->fk_project)) $this->fk_project=trim($this->fk_project);
 
         // Check parameters
         if (! $newcapital > 0 || empty($this->datestart) || empty($this->dateend))
@@ -157,9 +161,9 @@ class Loan extends CommonObject
 
         $this->db->begin();
 
-        $sql = "INSERT INTO ".MAIN_DB_PREFIX."loan (label, fk_bank, capital, datestart, dateend, nbterm, rate, note_private, note_public";
-		$sql.= " ,accountancy_account_capital, accountancy_account_insurance, accountancy_account_interest, entity";
-		$sql.= " ,datec, fk_user_author)";
+        $sql = "INSERT INTO ".MAIN_DB_PREFIX."loan (label, fk_bank, capital, datestart, dateend, nbterm, rate, note_private, note_public,";
+		$sql.= " accountancy_account_capital, accountancy_account_insurance, accountancy_account_interest, entity,";
+		$sql.= " datec, fk_projet, fk_user_author)";
 		$sql.= " VALUES ('".$this->db->escape($this->label)."',";
 		$sql.= " '".$this->db->escape($this->fk_bank)."',";
         $sql.= " '".price2num($newcapital)."',";
@@ -174,6 +178,7 @@ class Loan extends CommonObject
 		$sql.= " '".$this->db->escape($this->account_interest)."',";
         $sql.= " ".$conf->entity.",";
 		$sql.= " '".$this->db->idate($now)."',";
+		$sql.= " ".(empty($this->fk_project)?'NULL':$this->fk_project).",";
 		$sql.= " ".$user->id;
         $sql.= ")";
 
@@ -282,6 +287,7 @@ class Loan extends CommonObject
 		$sql.= " capital='".price2num($this->db->escape($this->capital))."',";
         $sql.= " datestart='".$this->db->idate($this->datestart)."',";
         $sql.= " dateend='".$this->db->idate($this->dateend)."',";
+        $sql.= " fk_projet=".(empty($this->fk_project)?'NULL':$this->fk_project).",";
 		$sql.= " fk_user_modif = ".$user->id;
         $sql.= " WHERE rowid=".$this->id;
 
@@ -345,7 +351,7 @@ class Loan extends CommonObject
         global $langs;
         $langs->load('customers');
         $langs->load('bills');
-        
+
         if ($mode == 0)
         {
             if ($statut ==  0) return $langs->trans("Unpaid");
@@ -398,7 +404,7 @@ class Loan extends CommonObject
      * 	@param	int		$maxlen			Label max length
      *	@return	string					Chaine with URL
      */
-    function getLinkUrl($withpicto=0,$maxlen=0)
+    function getNomUrl($withpicto=0,$maxlen=0)
     {
         global $langs;
 

+ 1 - 1
htdocs/loan/index.php

@@ -157,7 +157,7 @@ if ($resql)
 		print "<tr ".$bc[$var].">";
 
 		// Ref
-		print '<td>'.$loan_static->getLinkUrl(1, 42).'</td>';
+		print '<td>'.$loan_static->getNomUrl(1, 42).'</td>';
 
 		// Label
 		print '<td>'.dol_trunc($obj->label,42).'</td>';

+ 1 - 1
htdocs/loan/payment/card.php

@@ -231,7 +231,7 @@ if ($resql)
 			// Ref
 			print '<td>';
 			$loan->fetch($objp->id);
-			print $loan->getLinkUrl(1);
+			print $loan->getNomUrl(1);
 			print "</td>\n";
 			// Label
 			print '<td>'.$objp->label.'</td>';

+ 1 - 1
htdocs/main.inc.php

@@ -1025,7 +1025,7 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs
         print '<link rel="shortcut icon" type="image/x-icon" href="'.$favicon.'"/>'."\n";
         if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && ! GETPOST('textbrowser')) print '<link rel="top" title="'.$langs->trans("Home").'" href="'.(DOL_URL_ROOT?DOL_URL_ROOT:'/').'">'."\n";
         if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && ! GETPOST('textbrowser')) print '<link rel="copyright" title="GNU General Public License" href="http://www.gnu.org/copyleft/gpl.html#SEC1">'."\n";
-        if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && ! GETPOST('textbrowser')) print '<link rel="author" title="Dolibarr Development Team" href="http://www.dolibarr.org">'."\n";
+        if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && ! GETPOST('textbrowser')) print '<link rel="author" title="Dolibarr Development Team" href="https://www.dolibarr.org">'."\n";
 
         // Displays title
         $appli=constant('DOL_APPLICATION_TITLE');

+ 177 - 130
htdocs/product/class/product.class.php

@@ -54,7 +54,7 @@ class Product extends CommonObject
 	 */
 	protected $table_ref_field = 'ref';
 
-	var $regeximgext='\.jpg|\.jpeg|\.bmp|\.gif|\.png|\.tiff';
+	var $regeximgext='\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.xpm|\.xbm'; // See also into images.lib.php
 
 	/*
 	 * @deprecated
@@ -3691,15 +3691,16 @@ class Product extends CommonObject
 	}
 
 	/**
-	 *  Affiche la premiere photo du produit
+	 *  Return if at least one photo is available
 	 *
-	 *  @param      string		$sdir       Repertoire a scanner
-	 *  @return     boolean     			true si photo dispo, false sinon
+	 *  @param      string		$sdir       Directory to scan
+	 *  @return     boolean     			True if at least one photo is available, False if not
 	 */
 	function is_photo_available($sdir)
 	{
-		include_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php';
-
+	    include_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php';
+	    include_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php';
+	     
 		global $conf;
 
 		$dir = $sdir;
@@ -3717,7 +3718,7 @@ class Product extends CommonObject
 			    while (($file = readdir($handle)) !== false)
     			{
     				if (! utf8_check($file)) $file=utf8_encode($file);	// To be sure data is stored in UTF8 in memory
-    				if (dol_is_file($dir.$file)) return true;
+    				if (dol_is_file($dir.$file) && image_format_supported($file) > 0) return true;
     			}
 			}
 		}
@@ -3729,7 +3730,7 @@ class Product extends CommonObject
 	 *  Show photos of a product (nbmax maximum), into several columns
 	 *	TODO Move this into html.formproduct.class.php
 	 *
-	 *  @param      string	$sdir        	Directory to scan
+	 *  @param      string	$sdir        	Directory to scan (full absolute path)
 	 *  @param      int		$size        	0=original size, 1='small' use thumbnail if possible
 	 *  @param      int		$nbmax       	Nombre maximum de photos (0=pas de max)
 	 *  @param      int		$nbbyrow     	Number of image per line or -1 to use div. Used only if size=1.
@@ -3747,140 +3748,186 @@ class Product extends CommonObject
 		include_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php';
 		include_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php';
 
+		$sortfield='position_name';
+		$sortorder='asc';
+		
 		$dir = $sdir . '/';
 		$pdir = '/';
+		$dir .= get_exdir(0,0,0,0,$this,'product').$this->ref.'/';
+		$pdir .= get_exdir(0,0,0,0,$this,'product').$this->ref.'/';
+
 		if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
 		{
-			$dir .= get_exdir($this->id,2,0,0,$this,'product') . $this->id ."/photos/";
-			$pdir .= get_exdir($this->id,2,0,0,$this,'product') . $this->id ."/photos/";
+			$dirold .= get_exdir($this->id,2,0,0,$this,'product') . $this->id ."/photos/";
+			$pdirold .= get_exdir($this->id,2,0,0,$this,'product') . $this->id ."/photos/";
 		}
-		else
+
+		// Defined relative dir to DOL_DATA_ROOT
+		$relativedir = '';
+		if ($dir)
 		{
-			$dir .= get_exdir(0,0,0,0,$this,'product').$this->ref.'/';
-			$pdir .= get_exdir(0,0,0,0,$this,'product').$this->ref.'/';
+		    $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $dir);
+		    $relativedir = preg_replace('/^[\\/]/','',$relativedir);
+		    $relativedir = preg_replace('/[\\/]$/','',$relativedir);
 		}
-
+		
 		$dirthumb = $dir.'thumbs/';
 		$pdirthumb = $pdir.'thumbs/';
 
 		$return ='<!-- Photo -->'."\n";
 		$nbphoto=0;
 
-		$dir_osencoded=dol_osencode($dir);
-		if (file_exists($dir_osencoded))
+		$filearray=dol_dir_list($dir,"files",0,'','(\.meta|_preview\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
+		
+		if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))    // For backward compatiblity, we scan also old dirs
 		{
-			$handle=opendir($dir_osencoded);
-            if (is_resource($handle))
+		    $filearrayold=dol_dir_list($dirold,"files",0,'','(\.meta|_preview\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
+		    $filearray=array_merge($filearray, $filearrayold);
+		}
+
+        $filearrayindatabase = dol_dir_list_in_database($relativedir, '', null, 'name', SORT_ASC);
+            
+        //var_dump($filearray);
+        //var_dump($filearrayindatabase);
+        
+        // Complete filearray with properties found into $filearrayindatabase
+        foreach($filearray as $key => $val)
+        {
+            $found=0;
+            // Search if it exists into $filearrayindatabase
+            foreach($filearrayindatabase as $key2 => $val2)
             {
-    			while (($file = readdir($handle)) !== false)
-    			{
-    				$photo='';
+                if ($filearrayindatabase[$key2]['name'] == $filearray[$key]['name'])
+                {
+                    $filearray[$key]['position_name']=($filearrayindatabase[$key2]['position']?$filearrayindatabase[$key2]['position']:'0').'_'.$filearrayindatabase[$key2]['name'];
+                    $filearray[$key]['position']=$filearrayindatabase[$key2]['position'];
+                    $filearray[$key]['cover']=$filearrayindatabase[$key2]['cover'];
+                    $filearray[$key]['acl']=$filearrayindatabase[$key2]['acl'];
+                    $filearray[$key]['rowid']=$filearrayindatabase[$key2]['rowid'];
+                    $filearray[$key]['label']=$filearrayindatabase[$key2]['label'];
+                    $found=1;
+                    break;
+                }
+            }
+        }
+        
+        if (count($filearray))
+        {
+            if ($sortfield && $sortorder)
+            {
+                $filearray=dol_sort_array($filearray, $sortfield, $sortorder);
+            }
+            
+            foreach($filearray as $key => $val)
+            {
+				$photo='';
+                $file = $val['name'];
+                
+				//if (! utf8_check($file)) $file=utf8_encode($file);	// To be sure file is stored in UTF8 in memory
 
-    				if (! utf8_check($file)) $file=utf8_encode($file);	// To be sure file is stored in UTF8 in memory
+				//if (dol_is_file($dir.$file) && image_format_supported($file) >= 0)
+				if (image_format_supported($file) >= 0)
+				{
+					$nbphoto++;
+					$photo = $file;
+					$viewfilename = $file;
 
-    				if (dol_is_file($dir.$file) && preg_match('/('.$this->regeximgext.')$/i', $dir.$file))
-    				{
-    					$nbphoto++;
-    					$photo = $file;
-    					$viewfilename = $file;
-
-    					if ($size == 1 || $size == 'small') {   // Format vignette
-
-    						// Find name of thumb file
-    						$photo_vignette=basename(getImageFileNameForSize($dir.$file, '_small'));
-    						if (! dol_is_file($dirthumb.$photo_vignette)) $photo_vignette='';
-    						
-    						// Get filesize of original file
-    						$imgarray=dol_getImageSize($dir.$photo);
-
-    						if ($nbbyrow > 0)
-    						{
-    							if ($nbphoto == 1) $return.= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">';
-
-    							if ($nbphoto % $nbbyrow == 1) $return.= '<tr align=center valign=middle border=1>';
-    							$return.= '<td width="'.ceil(100/$nbbyrow).'%" class="photo">';
-    						}
-    						else if ($nbbyrow < 0) $return .= '<div class="inline-block">';
-
-    						$return.= "\n";
-    						
-    						$relativefile=preg_replace('/^\//', '', $pdir.$photo);
-    						if (empty($nolink)) 
-    						{
-    						    $urladvanced=getAdvancedPreviewUrl('product', $relativefile);
-    						    if ($urladvanced) $return.='<a href="'.$urladvanced.'">';
-    						    else $return.= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">';
-    						}
-
-    						// Show image (width height=$maxHeight)
-    						// Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine
-    						$alt=$langs->transnoentitiesnoconv('File').': '.$relativefile;
-    						$alt.=' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height'];
-    						
-    						if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight)
-    						{
-    							$return.= '<!-- Show thumb -->';
-    							$return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&entity='.$this->entity.'&file='.urlencode($pdirthumb.$photo_vignette).'" title="'.dol_escape_htmltag($alt).'">';
-    						}
-    						else {
-    							$return.= '<!-- Show original file -->';
-    							$return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" title="'.dol_escape_htmltag($alt).'">';
-    						}
-
-    						if (empty($nolink)) $return.= '</a>';
-    						$return.="\n";
-
-    						if ($showfilename) $return.= '<br>'.$viewfilename;
-    						if ($showaction)
-    						{
-    							$return.= '<br>';
-    							// On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites
-    							if ($photo_vignette && preg_match('/('.$this->regeximgext.')$/i', $photo) && ($this->imgWidth > $maxWidth || $this->imgHeight > $maxHeight))
-    							{
-    								$return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=addthumb&amp;file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'),'refresh').'&nbsp;&nbsp;</a>';
-    							}
-    							if ($user->rights->produit->creer || $user->rights->service->creer)
-    							{
-    								// Link to resize
-    			               		$return.= '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode('produit|service').'&id='.$this->id.'&amp;file='.urlencode($pdir.$viewfilename).'" title="'.dol_escape_htmltag($langs->trans("Resize")).'">'.img_picto($langs->trans("Resize"),DOL_URL_ROOT.'/theme/common/transform-crop-and-resize','',1).'</a> &nbsp; ';
-
-    			               		// Link to delete
-    								$return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=delete&amp;file='.urlencode($pdir.$viewfilename).'">';
-    								$return.= img_delete().'</a>';
-    							}
-    						}
-    						$return.= "\n";
-
-    						if ($nbbyrow > 0)
-    						{
-    							$return.= '</td>';
-    							if (($nbphoto % $nbbyrow) == 0) $return.= '</tr>';
-    						}
-    						else if ($nbbyrow < 0) $return.='</div>';
-    					}
+					if ($size == 1 || $size == 'small') {   // Format vignette
 
-    					if (empty($size)) {     // Format origine
-    						$return.= '<img class="photo photowithmargin" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'">';
-
-    						if ($showfilename) $return.= '<br>'.$viewfilename;
-    						if ($showaction)
-    						{
-    							if ($user->rights->produit->creer || $user->rights->service->creer)
-    							{
-    								// Link to resize
-    			               		$return.= '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode('produit|service').'&id='.$this->id.'&amp;file='.urlencode($pdir.$viewfilename).'" title="'.dol_escape_htmltag($langs->trans("Resize")).'">'.img_picto($langs->trans("Resize"),DOL_URL_ROOT.'/theme/common/transform-crop-and-resize','',1).'</a> &nbsp; ';
-
-    			               		// Link to delete
-    			               		$return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=delete&amp;file='.urlencode($pdir.$viewfilename).'">';
-    								$return.= img_delete().'</a>';
-    							}
-    						}
-    					}
+						// Find name of thumb file
+						$photo_vignette=basename(getImageFileNameForSize($dir.$file, '_small'));
+						if (! dol_is_file($dirthumb.$photo_vignette)) $photo_vignette='';
+						
+						// Get filesize of original file
+						$imgarray=dol_getImageSize($dir.$photo);
 
-    					// On continue ou on arrete de boucler ?
-    					if ($nbmax && $nbphoto >= $nbmax) break;
-    				}
-    			}
+						if ($nbbyrow > 0)
+						{
+							if ($nbphoto == 1) $return.= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">';
+
+							if ($nbphoto % $nbbyrow == 1) $return.= '<tr align=center valign=middle border=1>';
+							$return.= '<td width="'.ceil(100/$nbbyrow).'%" class="photo">';
+						}
+						else if ($nbbyrow < 0) $return .= '<div class="inline-block">';
+
+						$return.= "\n";
+						
+						$relativefile=preg_replace('/^\//', '', $pdir.$photo);
+						if (empty($nolink)) 
+						{
+						    $urladvanced=getAdvancedPreviewUrl('product', $relativefile);
+						    if ($urladvanced) $return.='<a href="'.$urladvanced.'">';
+						    else $return.= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">';
+						}
+
+						// Show image (width height=$maxHeight)
+						// Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine
+						$alt=$langs->transnoentitiesnoconv('File').': '.$relativefile;
+						$alt.=' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height'];
+						
+						if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight)
+						{
+							$return.= '<!-- Show thumb -->';
+							$return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&entity='.$this->entity.'&file='.urlencode($pdirthumb.$photo_vignette).'" title="'.dol_escape_htmltag($alt).'">';
+						}
+						else {
+							$return.= '<!-- Show original file -->';
+							$return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" title="'.dol_escape_htmltag($alt).'">';
+						}
+
+						if (empty($nolink)) $return.= '</a>';
+						$return.="\n";
+
+						if ($showfilename) $return.= '<br>'.$viewfilename;
+						if ($showaction)
+						{
+							$return.= '<br>';
+							// On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites
+							if ($photo_vignette && (image_format_supported($photo) > 0) && ($this->imgWidth > $maxWidth || $this->imgHeight > $maxHeight))
+							{
+								$return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=addthumb&amp;file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'),'refresh').'&nbsp;&nbsp;</a>';
+							}
+							if ($user->rights->produit->creer || $user->rights->service->creer)
+							{
+								// Link to resize
+			               		$return.= '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode('produit|service').'&id='.$this->id.'&amp;file='.urlencode($pdir.$viewfilename).'" title="'.dol_escape_htmltag($langs->trans("Resize")).'">'.img_picto($langs->trans("Resize"),DOL_URL_ROOT.'/theme/common/transform-crop-and-resize','',1).'</a> &nbsp; ';
+
+			               		// Link to delete
+								$return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=delete&amp;file='.urlencode($pdir.$viewfilename).'">';
+								$return.= img_delete().'</a>';
+							}
+						}
+						$return.= "\n";
+
+						if ($nbbyrow > 0)
+						{
+							$return.= '</td>';
+							if (($nbphoto % $nbbyrow) == 0) $return.= '</tr>';
+						}
+						else if ($nbbyrow < 0) $return.='</div>';
+					}
+
+					if (empty($size)) {     // Format origine
+						$return.= '<img class="photo photowithmargin" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'">';
+
+						if ($showfilename) $return.= '<br>'.$viewfilename;
+						if ($showaction)
+						{
+							if ($user->rights->produit->creer || $user->rights->service->creer)
+							{
+								// Link to resize
+			               		$return.= '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode('produit|service').'&id='.$this->id.'&amp;file='.urlencode($pdir.$viewfilename).'" title="'.dol_escape_htmltag($langs->trans("Resize")).'">'.img_picto($langs->trans("Resize"),DOL_URL_ROOT.'/theme/common/transform-crop-and-resize','',1).'</a> &nbsp; ';
+
+			               		// Link to delete
+			               		$return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=delete&amp;file='.urlencode($pdir.$viewfilename).'">';
+								$return.= img_delete().'</a>';
+							}
+						}
+					}
+
+					// On continue ou on arrete de boucler ?
+					if ($nbmax && $nbphoto >= $nbmax) break;
+				}
             }
 
 			if ($size==1 || $size=='small')
@@ -3897,8 +3944,6 @@ class Product extends CommonObject
 					if ($nbphoto) $return.= '</table>';
 				}
 			}
-
-			closedir($handle);
 		}
 
 		$this->nbphoto = $nbphoto;
@@ -3916,8 +3961,9 @@ class Product extends CommonObject
 	 */
 	function liste_photos($dir,$nbmax=0)
 	{
-		include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-
+	    include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+	    include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
+	     
 		$nbphoto=0;
 		$tabobj=array();
 
@@ -3928,7 +3974,7 @@ class Product extends CommonObject
 			while (($file = readdir($handle)) !== false)
 			{
 				if (! utf8_check($file)) $file=utf8_encode($file);	// readdir returns ISO
-				if (dol_is_file($dir.$file) && preg_match('/('.$this->regeximgext.')$/i', $dir.$file))
+				if (dol_is_file($dir.$file) && image_format_supported($file) >= 0)
 				{
 					$nbphoto++;
 
@@ -3969,8 +4015,9 @@ class Product extends CommonObject
 	 */
 	function delete_photo($file)
 	{
-        require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-
+	    require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+	    require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
+	     
         $dir = dirname($file).'/'; // Chemin du dossier contenant l'image d'origine
 		$dirthumb = $dir.'/thumbs/'; // Chemin du dossier contenant la vignette
 		$filename = preg_replace('/'.preg_quote($dir,'/').'/i','',$file); // Nom du fichier

+ 7 - 7
htdocs/product/class/service.class.php

@@ -29,14 +29,14 @@ require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php';
  */
 class Service extends CommonObject
 {
-	var $libelle;
-	var $price;
-	var $tms;
-	var $debut;
-	var $fin;
+	public $libelle;
+	public $price;
+	public $tms;
+	public $debut;
+	public $fin;
 
-	var $debut_epoch;
-	var $fin_epoch;
+	public $debut_epoch;
+	public $fin_epoch;
 
 	/**
 	*  Constructor

+ 2 - 2
htdocs/product/document.php

@@ -62,7 +62,7 @@ $offset = $conf->liste_limit * $page;
 $pageprev = $page - 1;
 $pagenext = $page + 1;
 if (! $sortorder) $sortorder="ASC";
-if (! $sortfield) $sortfield="name";
+if (! $sortfield) $sortfield="position_name";
 
 
 $object = new Product($db);
@@ -192,7 +192,7 @@ if ($object->id)
 
 	$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
 	if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
-
+	
 	// Construit liste des fichiers
 	$filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
 

+ 0 - 115
htdocs/product/stock/class/productlot.class.php

@@ -256,92 +256,6 @@ class Productlot extends CommonObject
 		}
 	}
 
-	/**
-	 * Load object in memory from the database
-	 *
-	 * @param string $sortorder Sort Order
-	 * @param string $sortfield Sort field
-	 * @param int    $limit     offset limit
-	 * @param int    $offset    offset limit
-	 * @param array  $filter    filter array
-	 * @param string $filtermode filter mode (AND or OR)
-	 *
-	 * @return int <0 if KO, >0 if OK
-	 */
-	public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND')
-	{
-		dol_syslog(__METHOD__, LOG_DEBUG);
-
-		$sql = 'SELECT';
-		$sql .= ' t.rowid,';
-		
-		$sql .= " t.entity,";
-		$sql .= " t.fk_product,";
-		$sql .= " t.batch,";
-		$sql .= " t.eatby,";
-		$sql .= " t.sellby,";
-		$sql .= " t.datec,";
-		$sql .= " t.tms,";
-		$sql .= " t.fk_user_creat,";
-		$sql .= " t.fk_user_modif,";
-		$sql .= " t.import_key";
-
-		
-		$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
-
-		// Manage filter
-		$sqlwhere = array();
-		if (count($filter) > 0) {
-			foreach ($filter as $key => $value) {
-				$sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
-			}
-		}
-		if (count($sqlwhere) > 0) {
-			$sql .= ' WHERE ' . implode(' '.$filtermode.' ', $sqlwhere);
-		}
-		
-		if (!empty($sortfield)) {
-			$sql .= $this->db->order($sortfield,$sortorder);
-		}
-		if (!empty($limit)) {
-		 $sql .=  ' ' . $this->db->plimit($limit + 1, $offset);
-		}
-		$this->lines = array();
-
-		$resql = $this->db->query($sql);
-		if ($resql) {
-			$num = $this->db->num_rows($resql);
-
-			while ($obj = $this->db->fetch_object($resql)) 
-			{
-				$line = new ProductlotLine();
-
-				$line->id = $obj->rowid;
-				
-				$line->entity = $obj->entity;
-				$line->fk_product = $obj->fk_product;
-				$line->batch = $obj->batch;
-				$line->eatby = $this->db->jdate($obj->eatby);
-				$line->sellby = $this->db->jdate($obj->sellby);
-				$line->datec = $this->db->jdate($obj->datec);
-				$line->tms = $this->db->jdate($obj->tms);
-				$line->fk_user_creat = $obj->fk_user_creat;
-				$line->fk_user_modif = $obj->fk_user_modif;
-				$line->import_key = $obj->import_key;
-
-				$this->lines[$line->id] = $line;
-			}
-			$this->db->free($resql);
-
-			return $num;
-		} else {
-			$this->errors[] = 'Error ' . $this->db->lasterror();
-			dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
-
-			return - 1;
-		}
-	}
-
 	/**
 	 * Update object into database
 	 *
@@ -595,32 +509,3 @@ class Productlot extends CommonObject
 
 }
 
-/**
- * Class ProductlotLine
- */
-class ProductlotLine
-{
-	/**
-	 * @var int ID
-	 */
-	public $id;
-	/**
-	 * @var mixed Sample line property 1
-	 */
-	
-	public $entity;
-	public $fk_product;
-	public $batch;
-	public $eatby = '';
-	public $sellby = '';
-	public $datec = '';
-	public $tms = '';
-	public $fk_user_creat;
-	public $fk_user_modif;
-	public $import_key;
-
-	/**
-	 * @var mixed Sample line property 2
-	 */
-	
-}

+ 1 - 1
htdocs/product/stock/class/productstockentrepot.class.php

@@ -273,7 +273,7 @@ class ProductStockEntrepot extends CommonObject
 		// "elseif" used instead of "if" because getting list with specified fk_product and specified fk_entrepot would be the same as doing a fetch
 		
 		if (!empty($sortfield)) $sql .= $this->db->order($sortfield,$sortorder);
-		if (!empty($limit)) $sql .=  ' ' . $this->db->plimit($limit + 1, $offset);
+		if (!empty($limit)) $sql .=  ' ' . $this->db->plimit($limit, $offset);
 		
 		$lines = array();
 

+ 2 - 1
htdocs/projet/ajax/projects.php

@@ -37,6 +37,7 @@ $htmlname=GETPOST('htmlname','alpha');
 $socid=GETPOST('socid','int');
 $action=GETPOST('action', 'alpha');
 $id=GETPOST('id', 'int');
+$discard_closed =GETPOST('discardclosed','int');
 
 
 /*
@@ -63,7 +64,7 @@ if (! GETPOST($htmlname) && ! GETPOST($idprod)) return;
 $searchkey=(GETPOST($idprod)?GETPOST($idprod):(GETPOST($htmlname)?GETPOST($htmlname):''));
 
 $form = new FormProjets($db);
-$arrayresult=$form->select_projects_list($socid, '', $htmlname, 0, 0, 1, 0, 0, 0, 1, $searchkey);
+$arrayresult=$form->select_projects_list($socid, '', $htmlname, 0, 0, 1, $discard_closed, 0, 0, 1, $searchkey);
 
 $db->close();
 

+ 23 - 8
htdocs/projet/element.php

@@ -47,6 +47,7 @@ if (! empty($conf->deplacement->enabled)) require_once DOL_DOCUMENT_ROOT.'/compt
 if (! empty($conf->expensereport->enabled)) require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
 if (! empty($conf->agenda->enabled))      require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
 if (! empty($conf->don->enabled))         require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
+if (! empty($conf->loan->enabled))        require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
 
 $langs->load("projects");
 $langs->load("companies");
@@ -58,6 +59,7 @@ if (! empty($conf->ficheinter->enabled))	$langs->load("interventions");
 if (! empty($conf->deplacement->enabled))	$langs->load("trips");
 if (! empty($conf->expensereport->enabled)) $langs->load("trips");
 if (! empty($conf->don->enabled))			$langs->load("donations");
+if (! empty($conf->loan->enabled))			$langs->load("loan");
 
 $id=GETPOST('id','int');
 $ref=GETPOST('ref','alpha');
@@ -370,6 +372,19 @@ $listofreferent=array(
     'buttonnew'=>'AddDonation',
     'testnew'=>$user->rights->don->creer,
     'test'=>$conf->don->enabled && $user->rights->don->lire),
+'loan'=>array(
+	'name'=>"Loan",
+	'title'=>"ListLoanAssociatedProject",
+	'class'=>'Loan',
+	'margin'=>'add',
+	'table'=>'loan',
+	'datefieldname'=>'datestart',
+	'disableamount'=>0,
+    'urlnew'=>DOL_URL_ROOT.'/loan/card.php?action=create&projectid='.$id.'&socid='.$socid,
+    'lang'=>'loan',
+    'buttonnew'=>'AddLoan',
+    'testnew'=>$user->rights->loan->write,
+    'test'=>$conf->loan->enabled && $user->rights->loan->read),
 'project_task'=>array(
 	'name'=>"TaskTimeValorised",
 	'title'=>"ListTaskTimeUserProject",
@@ -402,9 +417,9 @@ $parameters=array('listofreferent'=>$listofreferent);
 $resHook = $hookmanager->executeHooks('completeListOfReferent',$parameters,$object,$action);
 
 if(!empty($hookmanager->resArray)) {
-	
+
 	$listofreferent = array_merge($listofreferent, $hookmanager->resArray);
-	
+
 }
 
 if ($action=="addelement")
@@ -495,7 +510,7 @@ foreach ($listofreferent as $key => $value)
 		$element = new $classname($db);
 
 		$elementarray = $object->get_element_list($key, $tablename, $datefieldname, $dates, $datee);
-		
+
 		if (count($elementarray)>0 && is_array($elementarray))
 		{
 			$total_ht = 0;
@@ -511,7 +526,7 @@ foreach ($listofreferent as $key => $value)
 				$element->fetch($idofelement);
 				if ($idofelementuser) $elementuser->fetch($idofelementuser);
 
-                // Special cases				
+                // Special cases
 				if ($tablename != 'expensereport_det' && method_exists($element, 'fetch_thirdparty')) $element->fetch_thirdparty();
 				if ($tablename == 'don') $total_ht_by_line=$element->amount;
 				elseif ($tablename == 'projet_task')
@@ -534,7 +549,7 @@ foreach ($listofreferent as $key => $value)
 				{
 					if (! empty($element->close_code) && $element->close_code == 'replaced') $qualifiedfortotal=false;	// Replacement invoice, do not include into total
 				}
-				
+
 				if ($qualifiedfortotal) $total_ht = $total_ht + $total_ht_by_line;
 
 				if ($tablename == 'don') $total_ttc_by_line=$element->amount;
@@ -806,7 +821,7 @@ foreach ($listofreferent as $key => $value)
 						print ' - '.dol_trunc($element->label, 48);
 					}
 					else print $element->getNomUrl(1);
-						
+
 					$element_doc = $element->element;
 					$filename=dol_sanitizeFileName($element->ref);
 					$filedir=$conf->{$element_doc}->dir_output . '/' . dol_sanitizeFileName($element->ref);
@@ -822,7 +837,7 @@ foreach ($listofreferent as $key => $value)
 					}
 
 					print '<div class="inline-block valignmiddle">'.$formfile->getDocumentsLink($element_doc, $filename, $filedir).'</div>';
-					
+
 					// Show supplier ref
 					if (! empty($element->ref_supplier)) print ' - '.$element->ref_supplier;
 					// Show customer ref
@@ -836,7 +851,7 @@ foreach ($listofreferent as $key => $value)
 				elseif (! empty($element->status) || ! empty($element->statut) || ! empty($element->fk_status))
 				{
 				    if ($tablename=='don') $date = $element->datedon;
-				    if ($tablename == 'commande_fournisseur' || $tablename == 'supplier_order') 
+				    if ($tablename == 'commande_fournisseur' || $tablename == 'supplier_order')
     				{
     				    $date=($element->date_commande?$element->date_commande:$element->date_valid);
     				}

+ 3 - 1
htdocs/theme/eldy/style.css.php

@@ -241,6 +241,7 @@ body {
 <?php } ?>
 	color: rgb(<?php echo $colortext; ?>);
 	font-size: <?php print $fontsize ?>px;
+	line-height: 130%;
 	font-family: <?php print $fontlist ?>;
     margin-top: 0;
     margin-bottom: 0;
@@ -594,6 +595,7 @@ div.myavailability {
 .div-table-responsive {
     overflow-x: auto;
     min-height: 0.01%;
+    line-height: 100%;
 }
 /* Style used for full page tables with field selector and no content after table (priority before previous for such tables) */ 
 div.fiche>form>div.div-table-responsive {
@@ -4463,7 +4465,7 @@ border-top-right-radius: 6px;
 	color: #fff;
 	text-decoration: none;
 	padding-top: 18px;
-	: 54px;
+	padding-left: 54px;
 	font-size: 14px;
 	height: 38px;
 }

+ 2 - 0
htdocs/theme/md/style.css.php

@@ -242,6 +242,7 @@ body {
 	color: rgb(<?php echo $colortext; ?>);
 	font-size: <?php print $fontsize ?>px;
 	font-family: <?php print $fontlist ?>;
+	line-height: 130%;
     margin-top: 0;
     margin-bottom: 0;
     margin-right: 0;
@@ -599,6 +600,7 @@ div.myavailability {
 .div-table-responsive {
     overflow-x: auto;
     min-height: 0.01%;
+    line-height: 100%;
 }
 /* Style used for full page tables with field selector and no content after table (priority before previous for such tables) */ 
 div.fiche>form>div.div-table-responsive {

+ 2 - 1
htdocs/user/class/user.class.php

@@ -2600,8 +2600,9 @@ class User extends CommonObject
 
 	/**
 	 * 	Return list of all child users id in herarchy (all sublevels).
+	 *  Note: Calling this function also reste full list of users into $this->users.
 	 *
-	 *	@return		array		      		  	Array of user id lower than user. This overwrite this->users.
+	 *	@return		array		      		  	Array of user id lower than user (all levels under user).
 	 *  @see get_children
 	 */
 	function getAllChildIds()

+ 7 - 7
htdocs/user/class/usergroup.class.php

@@ -38,20 +38,20 @@ class UserGroup extends CommonObject
 	public $table_element='usergroup';
 	protected $ismultientitymanaged = 1;	// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
 
-	var $entity;		// Entity of group
+	public $entity;		// Entity of group
 	/**
 	 * @deprecated
 	 * @see name
 	 */
-	var $nom;			// Name of group
-	var $globalgroup;	// Global group
-	var $datec;			// Creation date of group
-	var $datem;			// Modification date of group
-	var $members=array();	// Array of users
+	public $nom;			// Name of group
+	public $globalgroup;	// Global group
+	public $datec;			// Creation date of group
+	public $datem;			// Modification date of group
+	public $members=array();	// Array of users
 
 	private $_tab_loaded=array();		// Array of cache of already loaded permissions
 
-	var $oldcopy;		// To contains a clone of this when we need to save old properties of object
+	public $oldcopy;		// To contains a clone of this when we need to save old properties of object
 
 
 	/**

+ 2 - 51
htdocs/websites/class/website.class.php

@@ -286,7 +286,6 @@ class Website extends CommonObject
 
 		$sql = 'SELECT';
 		$sql .= ' t.rowid,';
-		
 		$sql .= " t.entity,";
 		$sql .= " t.ref,";
 		$sql .= " t.description,";
@@ -296,7 +295,6 @@ class Website extends CommonObject
 		$sql .= " t.date_creation,";
 		$sql .= " t.date_modification,";
 		$sql .= " t.tms";
-		
 		$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
 
 		// Manage filter
@@ -314,7 +312,7 @@ class Website extends CommonObject
 			$sql .= $this->db->order($sortfield,$sortorder);
 		}
 		if (!empty($limit)) {
-		 $sql .=  ' ' . $this->db->plimit($limit + 1, $offset);
+		 $sql .=  ' ' . $this->db->plimit($limit, $offset);
 		}
 		$this->records = array();
 
@@ -323,7 +321,7 @@ class Website extends CommonObject
 			$num = $this->db->num_rows($resql);
 
 			while ($obj = $this->db->fetch_object($resql)) {
-				$line = new WebsiteLine();
+				$line = new self($this->db);
 
 				$line->id = $obj->rowid;
 				
@@ -650,50 +648,3 @@ class Website extends CommonObject
 
 }
 
-/**
- * Class WebsiteLine
- */
-class WebsiteLine
-{
-	/**
-	 * @var int ID
-	 */
-	public $id;
-	/**
-	 * @var int
-	 */
-	public $entity;
-	/**
-	 * @var string
-	 */
-	public $ref;
-	/**
-	 * @var string
-	 */
-	public $description;
-	/**
-	 * @var int
-	 */
-	public $status;
-	/**
-	 * @var int
-	 */
-	public $fk_default_home;
-	/**
-	 * @var string
-	 */
-	public $virtualhost;
-	/**
-	 * @var mixed
-	 */
-	public $date_creation;
-	/**
-	 * @var mixed
-	 */
-	public $date_modification;
-	/**
-	 * @var mixed
-	 */
-	public $tms = '';
-	
-}

+ 13 - 23
htdocs/websites/class/websitepage.class.php

@@ -57,7 +57,6 @@ class WebsitePage extends CommonObject
 	public $status;
 	public $date_creation;
 	public $date_modification;
-	public $tms;
 
 	/**
 	 */
@@ -203,8 +202,7 @@ class WebsitePage extends CommonObject
 		$sql .= " t.content,";
 		$sql .= " t.status,";
 		$sql .= " t.date_creation,";
-		$sql .= " t.date_modification,";
-		$sql .= " t.tms";
+		$sql .= " t.tms as date_modification";
 
 		$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
 		if (null !== $website_id) {
@@ -231,9 +229,6 @@ class WebsitePage extends CommonObject
 				$this->status = $obj->status;
 				$this->date_creation = $this->db->jdate($obj->date_creation);
 				$this->date_modification = $this->db->jdate($obj->date_modification);
-				$this->tms = $this->db->jdate($obj->tms);
-
-
 			}
 			$this->db->free($resql);
 
@@ -278,8 +273,7 @@ class WebsitePage extends CommonObject
 		$sql .= " t.content,";
 		$sql .= " t.status,";
 		$sql .= " t.date_creation,";
-		$sql .= " t.date_modification,";
-		$sql .= " t.tms";
+		$sql .= " t.tms as date_modification";
 		$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
 		$sql .= ' WHERE t.fk_website = '.$websiteid; 
 		// Manage filter
@@ -301,9 +295,8 @@ class WebsitePage extends CommonObject
 			$sql .= $this->db->order($sortfield,$sortorder);
 		}
 		if (!empty($limit)) {
-		 $sql .=  ' ' . $this->db->plimit($limit + 1, $offset);
+            $sql .=  ' ' . $this->db->plimit($limit, $offset);
 		}
-		$this->lines = array();
 
 		$resql = $this->db->query($sql);
 		if ($resql) {
@@ -311,7 +304,7 @@ class WebsitePage extends CommonObject
 
 			while ($obj = $this->db->fetch_object($resql))
 			{
-				$record = new WebsitePage($this->db);
+				$record = new self($this->db);
 
 				$record->id = $obj->rowid;
 				$record->fk_website = $obj->fk_website;
@@ -323,7 +316,6 @@ class WebsitePage extends CommonObject
 				$record->status = $obj->status;
 				$record->date_creation = $this->db->jdate($obj->date_creation);
 				$record->date_modification = $this->db->jdate($obj->date_modification);
-				$record->tms = $this->db->jdate($obj->tms);
 				//var_dump($record->id);
 				$records[$record->id] = $record;
 			}
@@ -389,8 +381,7 @@ class WebsitePage extends CommonObject
 		$sql .= ' content = '.(isset($this->content)?"'".$this->db->escape($this->content)."'":"null").',';
 		$sql .= ' status = '.(isset($this->status)?$this->status:"null").',';
 		$sql .= ' date_creation = '.(! isset($this->date_creation) || dol_strlen($this->date_creation) != 0 ? "'".$this->db->idate($this->date_creation)."'" : 'null').',';
-		$sql .= ' date_modification = '.(! isset($this->date_modification) || dol_strlen($this->date_modification) != 0 ? "'".$this->db->idate($this->date_modification)."'" : 'null').',';
-		$sql .= ' tms = '.(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : "'".$this->db->idate(dol_now())."'");
+		$sql .= ' tms = '.(dol_strlen($this->date_modification) != 0 ? "'".$this->db->idate($this->date_modification)."'" : "'".$this->db->idate(dol_now())."'");
 		$sql .= ' WHERE rowid=' . $this->id;
 
 		$this->db->begin();
@@ -633,18 +624,17 @@ class WebsitePage extends CommonObject
 	{
 		$this->id = 0;
 
+		$now=dol_now();
+		
 		$this->fk_website = '';
 		$this->pageurl = '';
-		$this->title = '';
-		$this->description = '';
-		$this->keywords = '';
-		$this->content = '';
+		$this->title = 'My Page';
+		$this->description = 'This is my page';
+		$this->keywords = 'keyword1, keyword2';
+		$this->content = '<html><body>This is a html content</body></html>';
 		$this->status = '';
-		$this->date_creation = '';
-		$this->date_modification = '';
-		$this->tms = '';
-
-
+		$this->date_creation = $now - (24 * 30 * 3600);
+		$this->date_modification = $now - (24 * 7 * 3600);
 	}
 
 }