Browse Source

Merge branch 'develop' into develop

Laurent Destailleur 8 năm trước cách đây
mục cha
commit
e4a2e42caf
86 tập tin đã thay đổi với 3608 bổ sung2921 xóa
  1. 3 0
      ChangeLog
  2. 0 1
      htdocs/accountancy/admin/account.php
  3. 4 4
      htdocs/accountancy/admin/accountmodel.php
  4. 45 54
      htdocs/accountancy/admin/card.php
  5. 3 3
      htdocs/accountancy/admin/categories_list.php
  6. 3 3
      htdocs/accountancy/admin/defaultaccounts.php
  7. 26 28
      htdocs/accountancy/admin/importaccounts.php
  8. 6 9
      htdocs/accountancy/admin/index.php
  9. 0 207
      htdocs/accountancy/admin/journal.php
  10. 2 2
      htdocs/accountancy/admin/productaccount.php
  11. 4 4
      htdocs/accountancy/bookkeeping/balance.php
  12. 5 7
      htdocs/accountancy/bookkeeping/card.php
  13. 9 10
      htdocs/accountancy/bookkeeping/list.php
  14. 3 3
      htdocs/accountancy/bookkeeping/listbyaccount.php
  15. 6 6
      htdocs/accountancy/bookkeeping/listbyyear.php
  16. 57 57
      htdocs/accountancy/class/bookkeeping.class.php
  17. 0 383
      htdocs/accountancy/class/html.formventilation.class.php
  18. 18 20
      htdocs/accountancy/customer/card.php
  19. 17 17
      htdocs/accountancy/customer/lines.php
  20. 21 22
      htdocs/accountancy/customer/list.php
  21. 3 3
      htdocs/accountancy/expensereport/card.php
  22. 3 3
      htdocs/accountancy/expensereport/lines.php
  23. 3 3
      htdocs/accountancy/expensereport/list.php
  24. 18 18
      htdocs/accountancy/supplier/card.php
  25. 5 5
      htdocs/accountancy/supplier/lines.php
  26. 19 20
      htdocs/accountancy/supplier/list.php
  27. 16 9
      htdocs/adherents/class/adherent_type.class.php
  28. 5 4
      htdocs/adherents/class/api_members.class.php
  29. 322 0
      htdocs/adherents/class/api_memberstypes.class.php
  30. 34 34
      htdocs/adherents/type.php
  31. 3 3
      htdocs/admin/dict.php
  32. 4 4
      htdocs/admin/loan.php
  33. 2 2
      htdocs/admin/mails_templates.php
  34. 3 3
      htdocs/admin/salaries.php
  35. 3 3
      htdocs/admin/taxes.php
  36. 100 0
      htdocs/api/class/api_dictionaryevents.class.php
  37. 3 3
      htdocs/api/index.php
  38. 9 24
      htdocs/bookmarks/bookmarks.lib.php
  39. 45 45
      htdocs/comm/action/class/api_agendaevents.class.php
  40. 14 17
      htdocs/compta/bank/card.php
  41. 4 4
      htdocs/compta/bank/various_payment/card.php
  42. 1 1
      htdocs/core/ajax/check_notifications.php
  43. 29 25
      htdocs/core/class/html.form.class.php
  44. 223 2
      htdocs/core/class/html.formaccounting.class.php
  45. 7 41
      htdocs/core/lib/accounting.lib.php
  46. 3 1
      htdocs/core/lib/files.lib.php
  47. 54 54
      htdocs/core/lib/functions.lib.php
  48. 9 9
      htdocs/don/admin/donation.php
  49. 19 10
      htdocs/install/default.css
  50. 26 26
      htdocs/install/fileconf.php
  51. 10 9
      htdocs/install/mysql/migration/5.0.0-6.0.0.sql
  52. 1 0
      htdocs/langs/en_US/errors.lang
  53. 1 0
      htdocs/langs/en_US/modulebuilder.lang
  54. 9 9
      htdocs/loan/card.php
  55. 221 0
      htdocs/modulebuilder/README.md
  56. 46 18
      htdocs/modulebuilder/index.php
  57. 4 219
      htdocs/modulebuilder/template/README.md
  58. 1 1
      htdocs/modulebuilder/template/admin/about.php
  59. 3 3
      htdocs/modulebuilder/template/admin/setup.php
  60. 0 51
      htdocs/modulebuilder/template/class/MyTrigger.php
  61. 1 1
      htdocs/modulebuilder/template/class/actions_mymodule.class.php
  62. 0 361
      htdocs/modulebuilder/template/class/myclass.class.php
  63. 607 0
      htdocs/modulebuilder/template/class/myobject.class.php
  64. 292 0
      htdocs/modulebuilder/template/class/myobject_api_class.class.php
  65. 201 626
      htdocs/modulebuilder/template/core/modules/modMyModule.class.php
  66. 13 56
      htdocs/modulebuilder/template/core/triggers/interface_99_modMyModule_Triggers.class.php
  67. 0 0
      htdocs/modulebuilder/template/img/myobject_mymodule.png
  68. 1 1
      htdocs/modulebuilder/template/js/mymodule.js.php
  69. 317 59
      htdocs/modulebuilder/template/myobject_card.php
  70. 442 48
      htdocs/modulebuilder/template/myobject_list.php
  71. 165 0
      htdocs/modulebuilder/template/scripts/myobject.php
  72. 0 203
      htdocs/modulebuilder/template/scripts/myscript.php
  73. 1 1
      htdocs/modulebuilder/template/sql/data.sql
  74. 1 1
      htdocs/modulebuilder/template/sql/llx_myobject.key.sql
  75. 1 1
      htdocs/modulebuilder/template/sql/llx_myobject.sql
  76. 0 0
      htdocs/modulebuilder/template/test/phpunit/MyModuleFunctionalTest.php
  77. 4 6
      htdocs/modulebuilder/template/test/phpunit/MyObjectTest.php
  78. 28 19
      htdocs/product/card.php
  79. 14 10
      htdocs/public/stripe/newpayment.php
  80. BIN
      htdocs/theme/common/ical.gif
  81. BIN
      htdocs/theme/common/information.png
  82. BIN
      htdocs/theme/common/rss.gif
  83. BIN
      htdocs/theme/common/vcal.gif
  84. 2 1
      htdocs/theme/eldy/style.css.php
  85. BIN
      htdocs/theme/login_background.png
  86. 1 1
      htdocs/theme/md/style.css.php

+ 3 - 0
ChangeLog

@@ -4,6 +4,9 @@ English Dolibarr ChangeLog
 
 ***** ChangeLog for 6.0.0 compared to 5.0.* *****
 
+For developers:
+NEW: Add a lot of API REST: dictionaryevents, memberstypes, ...
+
 WARNING: 
 
 Following changes may create regression for some external modules, but were necessary to make Dolibarr better:

+ 0 - 1
htdocs/accountancy/admin/account.php

@@ -27,7 +27,6 @@ require '../../main.inc.php';
 require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
-require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
 
 // Langs
 $langs->load("compta");

+ 4 - 4
htdocs/accountancy/admin/accountmodel.php

@@ -39,7 +39,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
 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';
+if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 
 $langs->load("errors");
 $langs->load("admin");
@@ -1258,8 +1258,8 @@ function fieldListAccountModel($fieldlist, $obj='', $tabname='', $context='')
 
 	$formadmin = new FormAdmin($db);
 	$formcompany = new FormCompany($db);
-	$formaccountancy = new FormVentilation($db);
-	
+	$formaccounting = new FormAccounting($db);
+
 	foreach ($fieldlist as $field => $value)
 	{
 		if ($fieldlist[$field] == 'country')
@@ -1400,7 +1400,7 @@ function fieldListAccountModel($fieldlist, $obj='', $tabname='', $context='')
 			if (! empty($conf->accounting->enabled))
 			{
 				$accountancy_account = (! empty($obj->$fieldlist[$field]) ? $obj->$fieldlist[$field] : 0);
-				print $formaccountancy->select_account($accountancy_account, $fieldlist[$field], 1, '', 1, 1, 'maxwidth200 maxwidthonsmartphone');
+				print $formaccounting->select_account($accountancy_account, $fieldlist[$field], 1, '', 1, 1, 'maxwidth200 maxwidthonsmartphone');
 			}
 			else
 			{

+ 45 - 54
htdocs/accountancy/admin/card.php

@@ -1,7 +1,7 @@
 <?php
 /* Copyright (C) 2013-2014 Olivier Geffroy      <jeff@jeffinfo.com>
- * Copyright (C) 2013-2016 Alexandre Spangaro   <aspangaro.dolibarr@gmail.com>
- * Copyright (C) 2014	   Florian Henry		<florian.henry@open-concept.pro>
+ * Copyright (C) 2013-2017 Alexandre Spangaro   <aspangaro.dolibarr@gmail.com>
+ * Copyright (C) 2014      Florian Henry        <florian.henry@open-concept.pro>
  *
  * 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
@@ -19,7 +19,7 @@
 
 /**
  * \file 		htdocs/accountancy/admin/card.php
- * \ingroup     Advanced accountancy
+ * \ingroup		Advanced accountancy
  * \brief 		Card of accounting account
  */
 
@@ -27,7 +27,6 @@ require '../../main.inc.php';
 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountancysystem.class.php';
-require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 
 $error = 0;
@@ -59,7 +58,7 @@ if (GETPOST('cancel'))
 	header("Location: ".$urltogo);
 	exit;
 }
-		
+
 if ($action == 'add' && $user->rights->accounting->chartofaccount)
 {
 	if (! $cancel) {
@@ -86,7 +85,7 @@ if ($action == 'add' && $user->rights->accounting->chartofaccount)
 		} else {
 			$account_parent = GETPOST('account_parent','int');
 		}
-		
+
 		$object->fk_pcg_version = $obj->pcg_version;
 		$object->pcg_type = GETPOST('pcg_type');
 		$object->pcg_subtype = GETPOST('pcg_subtype');
@@ -95,7 +94,7 @@ if ($action == 'add' && $user->rights->accounting->chartofaccount)
 		$object->account_category = GETPOST('account_category');
 		$object->label = GETPOST('label', 'alpha');
 		$object->active = 1;
-		
+
 		$res = $object->create($user);
 		if ($res == - 3) {
 			$error = 1;
@@ -124,9 +123,9 @@ if ($action == 'add' && $user->rights->accounting->chartofaccount)
 } else if ($action == 'edit' && $user->rights->accounting->chartofaccount) {
 	if (! $cancel) {
 		$result = $object->fetch($id);
-		
+
 		$sql = 'SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS;
-		
+
 		dol_syslog('accountancy/admin/card.php:: $sql=' . $sql);
 		$result2 = $db->query($sql);
 		$obj = $db->fetch_object($result2);
@@ -156,9 +155,9 @@ if ($action == 'add' && $user->rights->accounting->chartofaccount)
 		$object->account_parent = $account_parent;
 		$object->account_category = GETPOST('account_category');
 		$object->label = GETPOST('label', 'alpha');
-		
+
 		$result = $object->update($user);
-		
+
 		if ($result > 0) {
 		    $urltogo=$backtopage?$backtopage:($_SERVER["PHP_SELF"]."?id=".$id);
 		    header("Location: " . $urltogo);
@@ -196,7 +195,6 @@ $helpurl = '';
 llxheader('', $title, $helpurl);
 
 $form = new Form($db);
-$htmlacc = new FormVentilation($db);
 $formaccounting = new FormAccounting($db);
 
 $accountsystem = new AccountancySystem($db);
@@ -205,13 +203,13 @@ $accountsystem->fetch($conf->global->CHARTOFACCOUNTS);
 // Create mode
 if ($action == 'create') {
 	print load_fiche_titre($langs->trans('NewAccountingAccount'));
-	
+
 	print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
 	print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
 	print '<input type="hidden" name="action" value="add">';
-	
+
 	dol_fiche_head();
-	
+
 	print '<table class="border" width="100%">';
 
 	// Chart of account
@@ -219,8 +217,7 @@ if ($action == 'create') {
 	print '<td>';
 	print $accountsystem->ref;
 	print '</td></tr>';
-	
-	
+
 	// Account number
 	print '<tr><td class="titlefieldcreate"><span class="fieldrequired">' . $langs->trans("AccountNumber") . '</span></td>';
 	print '<td><input name="account_number" size="30" value="' . $object->account_number . '"></td></tr>';
@@ -232,7 +229,7 @@ if ($action == 'create') {
 	// Account parent
 	print '<tr><td>' . $langs->trans("Accountparent") . '</td>';
 	print '<td>';
-	print $htmlacc->select_account($object->account_parent, 'account_parent', 1, null, 0, 0, 'minwidth200');
+	print $formaccounting->select_account($object->account_parent, 'account_parent', 1, null, 0, 0, 'minwidth200');
 	print '</td></tr>';
 
 	// Category
@@ -245,72 +242,69 @@ if ($action == 'create') {
 	print '<tr><td>' . $langs->trans("Pcgtype") . '</td>';
 	print '<td>';
 	print '<input type="text" name="pcg_type" value="'.dol_escape_htmltag(isset($_POST['pcg_type'])?GETPOST('pcg_type','alpha'):$object->pcg_type).'">';
-	//print $htmlacc->select_pcgtype($object->pcg_type, 'pcg_type', 1);
 	print '</td></tr>';
 
 	// Chart of acounts subtype
 	print '<tr><td>' . $langs->trans("Pcgsubtype") . '</td>';
 	print '<td>';
 	print '<input type="text" name="pcg_subtype" value="'.dol_escape_htmltag(isset($_POST['pcg_subtype'])?GETPOST('pcg_subtype','alpha'):$object->pcg_subtype).'">';
-	//print $htmlacc->select_pcgsubtype($object->pcg_subtype, 'pcg_subtype', 1);
 	print '</td></tr>';
-	
+
 	print '</table>';
-	
+
 	dol_fiche_end();
-	
+
 	print '<div class="center">';
 	print '<input class="button" type="submit" value="' . $langs->trans("Save") . '">';
 	print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
 	print '<input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '">';
 	print '</div>';
-	
+
 	print '</form>';
 } else if ($id) {
 	$result = $object->fetch($id);
-	
+
 	if ($result > 0) {
 		dol_htmloutput_mesg($mesg);
-		
+
 		$head = accounting_prepare_head($object);
-		
+
 		// Edit mode
 		if ($action == 'update') 
 		{
 			dol_fiche_head($head, 'card', $langs->trans('AccountAccounting'), 0, 'billr');
-			
+
 			print '<form name="update" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
 			print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
 			print '<input type="hidden" name="action" value="edit">';
 			print '<input type="hidden" name="id" value="' . $id . '">';
 			print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
-				
+
 			print '<table class="border" width="100%">';
-			
+
 			// Account number
 			print '<tr><td class="titlefieldcreate"><span class="fieldrequired">' . $langs->trans("AccountNumber") . '</span></td>';
 			print '<td><input name="account_number" size="30" value="' . $object->account_number . '"</td></tr>';
-			
+
 			// Label
 			print '<tr><td><span class="fieldrequired">' . $langs->trans("Label") . '</span></td>';
 			print '<td><input name="label" size="70" value="' . $object->label . '"</td></tr>';
-			
+
 			// Account parent
 			print '<tr><td>' . $langs->trans("Accountparent") . '</td>';
 			print '<td>';
-			print $htmlacc->select_account($object->account_parent, 'account_parent', 1);
+			print $formaccounting->select_account($object->account_parent, 'account_parent', 1);
 			print '</td></tr>';
 
 			// Category
-            print '<tr><td>'.$langs->trans("AccountingCategory").'</td>';
+			print '<tr><td>'.$langs->trans("AccountingCategory").'</td>';
 			print '<td>';
-            $formaccounting->select_accounting_category($object->account_category, 'account_category', 1);
-            print '</td></tr>';
+			$formaccounting->select_accounting_category($object->account_category, 'account_category', 1);
+			print '</td></tr>';
 
 			// Chart of accounts type
 			print '<tr><td>' . $langs->trans("Pcgtype") . '</td>';
 			print '<td>';
-			//print $htmlacc->select_pcgtype($object->pcg_type, 'pcg_type', 1);
 			print '<input type="text" name="pcg_type" value="'.dol_escape_htmltag(isset($_POST['pcg_type'])?GETPOST('pcg_type','alpha'):$object->pcg_type).'">';
 			print '</td></tr>';
 
@@ -318,29 +312,27 @@ if ($action == 'create') {
 			print '<tr><td>' . $langs->trans("Pcgsubtype") . '</td>';
 			print '<td>';
 			print '<input type="text" name="pcg_subtype" value="'.dol_escape_htmltag(isset($_POST['pcg_subtype'])?GETPOST('pcg_subtype','alpha'):$object->pcg_subtype).'">';
-			//print $htmlacc->select_pcgsubtype($object->pcg_subtype, 'pcg_subtype', 1);
 			print '</td></tr>';
-			
+
 			print '</table>';
-			
+
 			dol_fiche_end();
-			
+
 			print '<div class="center">';
 			print '<input type="submit" class="button" value="' . $langs->trans("Save") . '">';
 			print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
 			print '<input type="submit" name="cancel" class="button" value="' . $langs->trans("Cancel") . '">';
 			print '</div>';
-			
+
 			print '</form>';
 		} else {
-			
 			// View mode
 			$linkback = '<a href="../admin/account.php">' . $langs->trans("BackToChartofaccounts") . '</a>';
-			
+
 			dol_fiche_head($head, 'card', $langs->trans('AccountAccounting'), 0, 'billr');
-			
+
 			print '<table class="border" width="100%">';
-			
+
 			// Account number
 			print '<tr><td class="titlefield">' . $langs->trans("AccountNumber") . '</td>';
 			print '<td>' . $object->account_number . '</td>';
@@ -378,31 +370,30 @@ if ($action == 'create') {
 			} else {
 				print img_picto($langs->trans("Activated"), 'switch_on');
 			}*/
-			
+
 			print '</td></tr>';
-			
+
 			print '</table>';
-			
+
 			dol_fiche_end();
-			
+
 			/*
 			 * Actions buttons
 			 */
-			
 			print '<div class="tabsAction">';
-			
+
 			if (! empty($user->rights->accounting->chartofaccount)) {
 				print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?action=update&id=' . $id . '">' . $langs->trans('Modify') . '</a>';
 			} else {
 				print '<a class="butActionRefused" href="#" title="' . dol_escape_htmltag($langs->trans("NotAllowed")) . '">' . $langs->trans('Modify') . '</a>';
 			}
-			
+
 			if (! empty($user->rights->accounting->chartofaccount)) {
 				print '<a class="butActionDelete" href="' . $_SERVER["PHP_SELF"] . '?action=delete&id=' . $id . '">' . $langs->trans('Delete') . '</a>';
 			} else {
 				print '<a class="butActionRefused" href="#" title="' . dol_escape_htmltag($langs->trans("NotAllowed")) . '">' . $langs->trans('Delete') . '</a>';
 			}
-			
+
 			print '</div>';
 		}
 	} else {

+ 3 - 3
htdocs/accountancy/admin/categories_list.php

@@ -39,7 +39,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
-require_once DOL_DOCUMENT_ROOT.'/accountancy/class/html.formventilation.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
 
 $langs->load("errors");
 $langs->load("admin");
@@ -982,7 +982,7 @@ function fieldListAccountingCategories($fieldlist, $obj='', $tabname='', $contex
 
 	$formadmin = new FormAdmin($db);
 	$formcompany = new FormCompany($db);
-	if (! empty($conf->accounting->enabled)) $formaccountancy = new FormVentilation($db);
+	if (! empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db);
 
 	foreach ($fieldlist as $field => $value)
 	{
@@ -1125,7 +1125,7 @@ function fieldListAccountingCategories($fieldlist, $obj='', $tabname='', $contex
 			{
 			    $fieldname = $fieldlist[$field];
 				$accountancy_account = (! empty($obj->$fieldname) ? $obj->$fieldname : 0);
-				print $formaccountancy->select_account($accountancy_account, $fieldlist[$field], 1, '', 1, 1, 'maxwidth200 maxwidthonsmartphone');
+				print $formaccounting->select_account($accountancy_account, $fieldlist[$field], 1, '', 1, 1, 'maxwidth200 maxwidthonsmartphone');
 			}
 			else
 			{

+ 3 - 3
htdocs/accountancy/admin/defaultaccounts.php

@@ -32,7 +32,7 @@ require '../../main.inc.php';
 // Class
 require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
-require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 
 $langs->load("compta");
 $langs->load("bills");
@@ -117,7 +117,7 @@ if ($action == 'update') {
 llxHeader();
 
 $form = new Form($db);
-$formaccountancy = new FormVentilation($db);
+$formaccounting = new FormAccounting($db);
 
 $linkback = '';
 print load_fiche_titre($langs->trans('MenuDefaultAccounts'), $linkback, 'title_accountancy');
@@ -142,7 +142,7 @@ foreach ( $list_account as $key ) {
 	print '<td>' . $label . '</td>';
 	// Value
 	print '<td>';  // Do not force align=right, or it align also the content of the select box 
-	print $formaccountancy->select_account($conf->global->$key, $key, 1, '', 1, 1);
+	print $formaccounting->select_account($conf->global->$key, $key, 1, '', 1, 1);
 	print '</td>';
 	print '</tr>';
 }

+ 26 - 28
htdocs/accountancy/admin/importaccounts.php

@@ -1,8 +1,7 @@
 <?php
-/* 
- * Copyright (C) 2013-2014 Olivier Geffroy      <jeff@jeffinfo.com>
- * Copyright (C) 2013-2014 Alexandre Spangaro   <aspangaro.dolibarr@gmail.com> 
- * Copyright (C) 2014	   Florian Henry		<florian.henry@open-concept.pro>
+/* Copyright (C) 2013-2014 Olivier Geffroy      <jeff@jeffinfo.com>
+ * Copyright (C) 2013-2017 Alexandre Spangaro   <aspangaro.dolibarr@gmail.com> 
+ * Copyright (C) 2014      Florian Henry        <florian.henry@open-concept.pro>
  *
  * 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
@@ -28,7 +27,7 @@ require '../../main.inc.php';
 // Class
 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
-require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 
 // langs
 $langs->load("compta");
@@ -65,22 +64,22 @@ if ($_POST["action"] == 'import') {
 	if (is_array($to_import) && count($to_import) > 0) {
 		print '<div><font color="red">' . count($to_import) . ' ' . $langs->trans("SelectedLines") . '</font></div>';
 		$sql = 'SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS;
-		
+
 		$result = $db->query($sql);
 		if ($result && ($db->num_rows($result) > 0)) {
-			
+
 			$obj = $db->fetch_object($result);
-			
+
 			$cpt = 0;
 			foreach ( $to_import as $maLigneCochee ) {
-				
+
 				$accounting = new AccountingAccount($db);
-				
+
 				$monLabel = GETPOST('label' . $maLigneCochee);
 				$monParentAccount = GETPOST('AccountParent' . $maLigneCochee);
 				$monType = GETPOST('pcgType' . $maLigneCochee);
 				$monSubType = GETPOST('pcgSubType' . $maLigneCochee);
-				
+
 				$accounting->fk_pcg_version = $obj->pcg_version;
 				$accounting->account_number = $maLigneCochee;
 				$accounting->label = $monLabel;
@@ -126,10 +125,10 @@ if ($result) {
 	$num_lines = $db->num_rows($result);
 	$i = 0;
 	print_barre_liste($langs->trans("ImportAccount"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num_lines);
-	
+
 	print '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
 	print '<input type="hidden" name="action" value="import">';
-	
+
 	print '<table class="noborder" width="100%">';
 	print '<tr class="liste_titre"><td>' . $langs->trans("AccountAccouting") . '</td>';
 	print '<td>' . $langs->trans("label") . '</td>';
@@ -138,44 +137,43 @@ if ($result) {
 	print '<td>' . $langs->trans("Pcgsubtype") . '</td>';
 	print '<td align="center">' . $langs->trans("Import") . '</td>';
 	print '</tr>';
-	
+
 	$form = new Form($db);
-	$htmlacc = new FormVentilation($db);
-	
+	$formaccounting = new FormAccounting($db);
+
 	$var = true;
 	while ( $i < min($num_lines, $limit) ) {
 		$objp = $db->fetch_object($result);
 		print '<tr class="oddeven">';
-		
+
 		print '<td align="left">';
 		print $objp->accounting;
 		print '</td>';
-		
+
 		print '<td align="left">';
 		print '<input name="label" size="30" value="">';
 		print '</td>';
-		
+
 		// Colonne choix du compte
 		print '<td>';
-		print $htmlacc->select_account($accounting->account_parent, 'AccountParent');
+		print $formaccounting->select_account($accounting->account_parent, 'AccountParent');
 		print '</td>';
-		
+
 		print '<td>';
-		print $htmlacc->select_pcgtype($accounting->pcg_type, 'pcgType');
+		print '<input type="text" name="pcgType" value="'.dol_escape_htmltag(isset($_POST['pcg_subtype'])?GETPOST('pcg_subtype','alpha'):$accounting->pcg_type).'">';
 		print '</td>';
-		
+
 		print '<td>';
-		print $htmlacc->select_pcgsubtype($accounting->pcg_subtype, 'pcgSubType');
+		print '<input type="text" name="pcgSubType" value="'.dol_escape_htmltag(isset($_POST['pcg_subtype'])?GETPOST('pcg_subtype','alpha'):$accounting->pcg_subtype).'">';
 		print '</td>';
-		
+
 		// Colonne choix ligne a ventiler
-		
 		$checked = ('label' == 'O') ? ' checked' : '';
-		
+
 		print '<td align="center">';
 		print '<input type="checkbox" name="mesCasesCochees[]" ' . $checked . ' value="' . $objp->accounting . '"/>';
 		print '</td>';
-		
+
 		print '</tr>';
 		$i ++;
 	}

+ 6 - 9
htdocs/accountancy/admin/index.php

@@ -1,11 +1,11 @@
 <?php
-/* Copyright (C) 2013-2014 Olivier Geffroy		<jeff@jeffinfo.com>
- * Copyright (C) 2013-2014 Florian Henry		<florian.henry@open-concept.pro>
- * Copyright (C) 2013-2017 Alexandre Spangaro	<aspangaro@zendsi.com>
- * Copyright (C) 2014-2015 Ari Elbaz (elarifr)	<github@accedinfo.com>
+/* Copyright (C) 2013-2014 Olivier Geffroy      <jeff@jeffinfo.com>
+ * Copyright (C) 2013-2014 Florian Henry        <florian.henry@open-concept.pro>
+ * Copyright (C) 2013-2017 Alexandre Spangaro   <aspangaro@zendsi.com>
+ * Copyright (C) 2014-2015 Ari Elbaz (elarifr)  <github@accedinfo.com>
  * Copyright (C) 2014      Marcos García        <marcosgdf@gmail.com>
- * Copyright (C) 2014	   Juanjo Menent		<jmenent@2byte.es>
- * Copyright (C) 2015      Jean-François Ferry	<jfefe@aternatik.fr>
+ * Copyright (C) 2014      Juanjo Menent        <jmenent@2byte.es>
+ * Copyright (C) 2015      Jean-François Ferry  <jfefe@aternatik.fr>
  *
  * 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
@@ -31,8 +31,6 @@ require '../../main.inc.php';
 
 // Class
 require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
-require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
-require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
 
 $langs->load("compta");
 $langs->load("bills");
@@ -160,7 +158,6 @@ if ($action == 'setdisabledirectinput') {
 llxHeader();
 
 $form = new Form($db);
-$formaccountancy = new FormVentilation($db);
 
 $linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php">' . $langs->trans("BackToModuleList") . '</a>';
 print load_fiche_titre($langs->trans('ConfigAccountingExpert'), $linkback, 'title_setup');

+ 0 - 207
htdocs/accountancy/admin/journal.php

@@ -1,207 +0,0 @@
-<?php
-/* Copyright (C) 2013-2014 Olivier Geffroy      <jeff@jeffinfo.com>
- * Copyright (C) 2013-2017 Alexandre Spangaro	<aspangaro@zendsi.com>
- * Copyright (C) 2014 	   Florian Henry		<florian.henry@open-concept.pro>
- * Copyright (C) 2014      Marcos García        <marcosgdf@gmail.com>
- * Copyright (C) 2014	   Juanjo Menent		<jmenent@2byte.es>
- * Copyright (C) 2015      Jean-François Ferry  <jfefe@aternatik.fr>
- * Copyright (C) 2016      Laurent Destailleur 	<eldy@users.sourceforge.net>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-/**
- * \file		htdocs/accountancy/admin/journal.php
-* \ingroup		Advanced accountancy
-* \brief		Setup page to configure accounting expert module
-*/
-require '../../main.inc.php';
-
-// Class
-require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
-require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
-require_once DOL_DOCUMENT_ROOT . '/core/lib/bank.lib.php';
-require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
-
-$langs->load("compta");
-$langs->load("bills");
-$langs->load("admin");
-$langs->load("accountancy");
-$langs->load("salaries");
-
-// Security check
-if (empty($user->admin) || ! empty($user->rights->accountancy->chartofaccount))
-{
-    accessforbidden();
-}
-
-$action = GETPOST('action', 'alpha');
-
-// Other parameters ACCOUNTING_*
-$list = array (
-		'ACCOUNTING_SELL_JOURNAL',
-		'ACCOUNTING_PURCHASE_JOURNAL',
-		'ACCOUNTING_SOCIAL_JOURNAL',
-		'ACCOUNTING_MISCELLANEOUS_JOURNAL',
-		'ACCOUNTING_EXPENSEREPORT_JOURNAL'
-);
-
-/*
- * Actions
-*/
-
-if ($action == 'update') {
-	$error = 0;
-
-	// Save vars
-	foreach ($list as $constname)
-	{
-		$constvalue = GETPOST($constname, 'alpha');
-
-		if (! dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
-			$error ++;
-		}
-	}
-
-	// Save bank account journals
-	$arrayofbankaccount = GETPOST('bank_account', 'array');
-	foreach($arrayofbankaccount as $key => $code)
-	{
-		$bankaccount = new Account($db);
-		$res = $bankaccount->fetch($key);
-		if ($res > 0)
-		{
-			$bankaccount->accountancy_journal = $code;
-			$bankaccount->update($user);
-		}
-		else
-		{
-			$error++;
-			break;
-		}
-	}
-
-	if (! $error) {
-		setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
-	} else {
-		setEventMessages($langs->trans("Error"), null, 'errors');
-	}
-}
-
-/*
- * View
-*/
-
-llxHeader();
-
-$form = new Form($db);
-
-$linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php">' . $langs->trans("BackToModuleList") . '</a>';
-print load_fiche_titre($langs->trans('ConfigAccountingExpert'), $linkback, 'title_setup');
-
-$head = admin_accounting_prepare_head(null);
-
-print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">';
-print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
-print '<input type="hidden" name="action" value="update">';
-
-dol_fiche_head($head, 'journal', $langs->trans("Configuration"), 0, 'cron');
-
-print '<table class="noborder" width="100%">';
-print '<tr class="liste_titre">';
-print '<td colspan="2">' . $langs->trans('Journaux') . '</td>';
-print "</tr>\n";
-
-foreach ( $list as $key ) {
-
-	print '<tr class="oddeven value">';
-
-	// Param
-	$label = $langs->trans($key);
-	print '<td width="50%"><label for="' . $key . '">' . $label . '</label></td>';
-
-	// Value
-	print '<td>';
-	print '<input type="text" size="20" id="' . $key . '" name="' . $key . '" value="' . $conf->global->$key . '">';
-	print '</td></tr>';
-}
-
-print "</table>\n";
-
-print '<br>';
-
-print '<table class="noborder" width="100%">';
-print '<tr class="liste_titre">';
-print '<td colspan="2">' . $langs->trans('JournalFinancial') . ' ('.$langs->trans('Opened').')</td>';
-print "</tr>\n";
-
-// Bank account
-$sql = "SELECT rowid, ref, label, number, account_number, accountancy_journal";
-$sql .= " FROM " . MAIN_DB_PREFIX . "bank_account";
-$sql .= " WHERE entity = " . $conf->entity;
-$sql .= " AND clos = 0";
-$sql .= " ORDER BY label";
-
-$resql = $db->query($sql);
-if ($resql) {
-	$numr = $db->num_rows($resql);
-	$i = 0;
-
-	if ($numr > 0)
-
-		$bankaccountstatic = new Account($db);
-
-	while ( $i < $numr ) {
-		$objp = $db->fetch_object($resql);
-
-		$bankaccountstatic->rowid = $objp->rowid;
-		$bankaccountstatic->id = $objp->rowid;
-		$bankaccountstatic->ref = $objp->ref;
-		$bankaccountstatic->label = $objp->label;
-		$bankaccountstatic->number = $objp->number;
-		$bankaccountstatic->account_number = $objp->account_number;
-		$bankaccountstatic->accountancy_journal = $objp->accountancy_journal;
-
-		print '<tr class="oddeven value">';
-
-		// Param
-		print '<td width="50%"><label for="' . $objp->rowid . '">' . $langs->trans("Journal");
-		print ' - '.$bankaccountstatic->getNomUrl(1);
-		print '</label></td>';
-
-		// Value
-		print '<td>';
-		print '<input type="text" size="20" id="' . $objp->rowid . '" name="bank_account['.$objp->rowid.']" value="' . $objp->accountancy_journal . '">';
-		print '</td></tr>';
-
-		$i ++;
-	}
-	$db->free($resql);
-}
-else
-{
-	dol_print_error($db);
-}
-
-print "</table>\n";
-
-dol_fiche_end();
-
-print '<div class="center"><input type="submit" class="button" value="' . $langs->trans('Modify') . '" name="button"></div>';
-
-print '</form>';
-
-llxFooter();
-$db->close();

+ 2 - 2
htdocs/accountancy/admin/productaccount.php

@@ -31,7 +31,7 @@ require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
 require_once DOL_DOCUMENT_ROOT . '/core/lib/report.lib.php';
 require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
-require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
 require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
 
@@ -184,7 +184,7 @@ if ($action == 'update') {
  * View
  */
 
-$form = new FormVentilation($db);
+$form = new FormAccounting($db);
 
 // Defaut AccountingAccount RowId Product / Service
 // at this time ACCOUNTING_SERVICE_SOLD_ACCOUNT & ACCOUNTING_PRODUCT_SOLD_ACCOUNT are account number not accountingacount rowid

+ 4 - 4
htdocs/accountancy/bookkeeping/balance.php

@@ -28,8 +28,8 @@ require '../../main.inc.php';
 
 // Class
 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
-require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
 
 // Langs
@@ -61,7 +61,7 @@ $offset = $limit * $page;
 
 $object = new BookKeeping($db);
 
-$formventilation = new FormVentilation($db);
+$formaccounting = new FormAccounting($db);
 $formother = new FormOther($db);
 $form = new Form($db);
 
@@ -186,10 +186,10 @@ else {
     print '<tr class="liste_titre_filter">';
     print '<td class="liste_titre" colspan="5">';
     print $langs->trans('From');
-    print $formventilation->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array(), 1, 1, '');
+    print $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array(), 1, 1, '');
     print ' ';
     print $langs->trans('to');
-    print $formventilation->select_account($search_accountancy_code_end, 'search_accountancy_code_end', 1, array(), 1, 1, '');
+    print $formaccounting->select_account($search_accountancy_code_end, 'search_accountancy_code_end', 1, array(), 1, 1, '');
     print '</td>';
     print '<td align="right" class="liste_titre">';
 	$searchpicto=$form->showFilterAndCheckAddButtons(0);

+ 5 - 7
htdocs/accountancy/bookkeeping/card.php

@@ -27,9 +27,8 @@ require '../../main.inc.php';
 // Class
 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
-require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
-require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 
 // Langs
 $langs->load("accountancy");
@@ -215,7 +214,6 @@ else if ($action == "confirm_create") {
 llxHeader();
 
 $html = new Form($db);
-$formventilation = new FormVentilation($db);
 $formaccountancy = new FormAccounting($db);
 
 /*
@@ -389,10 +387,10 @@ if ($action == 'create') {
 					if ($action == 'update' && $line->id == $id) {
 
 						print '<td>';
-						print $formventilation->select_account($line->numero_compte, 'account_number', 0, array (), 1, 1, '');
+						print $formaccounting->select_account($line->numero_compte, 'account_number', 0, array (), 1, 1, '');
 						print '</td>';
 						print '<td>';
-						print $formventilation->select_auxaccount($line->code_tiers, 'code_tiers', 1);
+						print $formaccounting->select_auxaccount($line->code_tiers, 'code_tiers', 1);
 						print '</td>';
 						print '<td><input type="text" size="15" name="label_compte" value="' . $line->label_compte . '"/></td>';
 						print '<td align="right"><input type="text" size="6" name="debit" value="' . price($line->debit) . '"/></td>';
@@ -433,10 +431,10 @@ if ($action == 'create') {
 				if ($action == "" || $action == 'add') {
 					print '<tr class="oddeven">';
 					print '<td>';
-					print $formventilation->select_account($account_number, 'account_number', 0, array (), 1, 1, '');
+					print $formaccounting->select_account($account_number, 'account_number', 0, array (), 1, 1, '');
 					print '</td>';
 					print '<td>';
-					print $formventilation->select_auxaccount($code_tiers, 'code_tiers', 1);
+					print $formaccounting->select_auxaccount($code_tiers, 'code_tiers', 1);
 					print '</td>';
 					print '<td><input type="text" size="15" name="label_compte" value="' . $label_compte . '"/></td>';
 					print '<td align="right"><input type="text" class="right maxwidth50" name="debit" value="' . price($debit) . '"/></td>';

+ 9 - 10
htdocs/accountancy/bookkeeping/list.php

@@ -28,10 +28,10 @@ require '../../main.inc.php';
 
 // Class
 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
-require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
-require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 
 // Langs
 $langs->load("accountancy");
@@ -94,7 +94,7 @@ if ($sortfield == "") $sortfield = "t.rowid";
 
 $object = new BookKeeping($db);
 
-$formventilation = new FormVentilation($db);
+$formaccounting = new FormAccounting($db);
 $formother = new FormOther($db);
 $form = new Form($db);
 
@@ -292,7 +292,6 @@ $title_page = $langs->trans("Bookkeeping");
 llxHeader('', $title_page);
 
 // List
-
 $nbtotalofrecords = '';
 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
 	$nbtotalofrecords = $object->fetchAll($sortorder, $sortfield, 0, 0, $filter);
@@ -322,8 +321,8 @@ if ($action == 'delbookkeepingyear') {
 	if (empty($delyear)) {
 		$delyear = dol_print_date(dol_now(), '%Y');
 	}
-	$year_array = $formventilation->selectyear_accountancy_bookkepping($delyear, 'delyear', 0, 'array');
-	$journal_array = $formventilation->selectjournal_accountancy_bookkepping($deljournal, 'deljournal', 0, 'array');
+	$year_array = $formaccounting->selectyear_accountancy_bookkepping($delyear, 'delyear', 0, 'array');
+	$journal_array = $formaccounting->selectjournal($deljournal, 'deljournal', '', 1, 'array', 1, 1);
 
 	$form_question['delyear'] = array (
 			'name' => 'delyear',
@@ -386,17 +385,17 @@ print '</td>';
 print '<td class="liste_titre"><input type="text" name="search_doc_ref" size="8" value="' . dol_escape_htmltag($search_doc_ref) . '"></td>';
 print '<td class="liste_titre">';
 print $langs->trans('From');
-print $formventilation->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array (), 1, 1, '');
+print $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array (), 1, 1, '');
 print '<br>';
 print $langs->trans('to');
-print $formventilation->select_account($search_accountancy_code_end, 'search_accountancy_code_end', 1, array (), 1, 1, '');
+print $formaccounting->select_account($search_accountancy_code_end, 'search_accountancy_code_end', 1, array (), 1, 1, '');
 print '</td>';
 print '<td class="liste_titre">';
 print $langs->trans('From');
-print $formventilation->select_auxaccount($search_accountancy_aux_code_start, 'search_accountancy_aux_code_start', 1);
+print $formaccounting->select_auxaccount($search_accountancy_aux_code_start, 'search_accountancy_aux_code_start', 1);
 print '<br>';
 print $langs->trans('to');
-print $formventilation->select_auxaccount($search_accountancy_aux_code_end, 'search_accountancy_aux_code_end', 1);
+print $formaccounting->select_auxaccount($search_accountancy_aux_code_end, 'search_accountancy_aux_code_end', 1);
 print '</td>';
 print '<td class="liste_titre">';
 print '<input type="text" size="7" class="flat" name="search_mvt_label" value="' . $search_mvt_label . '"/>';

+ 3 - 3
htdocs/accountancy/bookkeeping/listbyaccount.php

@@ -29,8 +29,8 @@ require '../../main.inc.php';
 
 // Class
 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
-require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
 
 // Langs
@@ -75,7 +75,7 @@ if (empty($search_date_end)) $search_date_end = dol_mktime(0, 0, 0, 12, 31, dol_
 
 $object = new BookKeeping($db);
 
-$formventilation = new FormVentilation($db);
+$formaccounting = new FormAccounting($db);
 $formother = new FormOther($db);
 $form = new Form($db);
 
@@ -188,7 +188,7 @@ if ($action == 'delbookkeepingyear') {
 	if (empty($delyear)) {
 		$delyear = dol_print_date(dol_now(), '%Y');
 	}
-	$year_array = $formventilation->selectyear_accountancy_bookkepping($delyear, 'delyear', 0, 'array');
+	$year_array = $formaccounting->selectyear_accountancy_bookkepping($delyear, 'delyear', 0, 'array');
 
 	$form_question['delyear'] = array (
 			'name' => 'delyear',

+ 6 - 6
htdocs/accountancy/bookkeeping/listbyyear.php

@@ -29,7 +29,7 @@ require '../../main.inc.php';
 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
-require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 
 // Langs
 $langs->load("accountancy");
@@ -67,7 +67,7 @@ $search_code_journal = GETPOST('search_code_journal', 'alpha');
 
 $object = new BookKeeping($db);
 $form = new Form($db);
-$formventilation = new FormVentilation($db);
+$formaccounting = new FormAccounting($db);
 
 // Filter
 if (empty($search_date_start)) {
@@ -182,15 +182,15 @@ print $form->select_date($search_date_end, 'date_end');
 print '</div>';
 print '<div class="liste_titre">';
 print $langs->trans('From') . ' ' . $langs->trans('AccountAccounting') . ': ';
-print $formventilation->select_account($search_numero_compte_start, 'search_numero_compte_start', 1, array (), 1, 1, '');
+print $formaccounting->select_account($search_numero_compte_start, 'search_numero_compte_start', 1, array (), 1, 1, '');
 print $langs->trans('To') . ' ' . $langs->trans('AccountAccounting') . ': ';
-print $formventilation->select_account($search_numero_compte_end, 'search_numero_compte_end', 1, array (), 1, 1, '');
+print $formaccounting->select_account($search_numero_compte_end, 'search_numero_compte_end', 1, array (), 1, 1, '');
 print '</div>';
 print '<div class="liste_titre">';
 print $langs->trans('From') . ' ' . $langs->trans('ThirdPartyAccount') . ': ';
-print $formventilation->select_auxaccount($search_code_tiers_start, 'search_code_tiers_start', 1);
+print $formaccounting->select_auxaccount($search_code_tiers_start, 'search_code_tiers_start', 1);
 print $langs->trans('To') . ' ' . $langs->trans('ThirdPartyAccount') . ': ';
-print $formventilation->select_auxaccount($search_code_tiers_end, 'searchcode_tiers_end', 1);
+print $formaccounting->select_auxaccount($search_code_tiers_end, 'searchcode_tiers_end', 1);
 print '</div>';
 print "<table class=\"noborder\" width=\"100%\">";
 

+ 57 - 57
htdocs/accountancy/class/bookkeeping.class.php

@@ -1053,23 +1053,23 @@ class BookKeeping extends CommonObject
 	 */
 	function deleteByYearAndJournal($delyear='', $journal='') {
 	    global $conf;
-	    
+
 	    if (empty($delyear) && empty($journal)) 
 	    {
 	        return -1;
 	    }
-	    
+
 		$this->db->begin();
-		
+
 		// first check if line not yet in bookkeeping
 		$sql = "DELETE";
 		$sql.= " FROM " . MAIN_DB_PREFIX . $this->table_element;
 		$sql.= " WHERE 1 = 1";
 		if (! empty($delyear)) $sql.= " AND YEAR(doc_date) = " . $delyear;         // FIXME Must use between
 		if (! empty($journal)) $sql.= " AND code_journal = '".$journal."'";
-	    $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
+		$sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
 		$resql = $this->db->query($sql);
-		
+
 		if (! $resql) {
 			$this->errors[] = "Error " . $this->db->lasterror();
 			foreach ( $this->errors as $errmsg ) {
@@ -1083,7 +1083,7 @@ class BookKeeping extends CommonObject
 		$this->db->commit();
 		return 1;
 	}
-	
+
 	/**
 	 * Delete bookkepping by piece number
 	 *
@@ -1092,17 +1092,17 @@ class BookKeeping extends CommonObject
 	 */
 	function deleteMvtNum($piecenum) {
 	    global $conf;
-	    
+
 		$this->db->begin();
 		
 		// first check if line not yet in bookkeeping
 		$sql = "DELETE";
 		$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
 		$sql .= " WHERE piece_num = " . $piecenum;
-	    $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
-		
+		$sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
+
 		$resql = $this->db->query($sql);
-		
+
 		if (! $resql) {
 			$this->errors[] = "Error " . $this->db->lasterror();
 			foreach ( $this->errors as $errmsg ) {
@@ -1116,7 +1116,7 @@ class BookKeeping extends CommonObject
 		$this->db->commit();
 		return 1;
 	}
-	
+
 	/**
 	 * Load an object from its id and create a new one in database
 	 *
@@ -1130,27 +1130,27 @@ class BookKeeping extends CommonObject
 		global $user;
 		$error = 0;
 		$object = new Accountingbookkeeping($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__ . ' ' . join(',', $this->errors), LOG_ERR);
 		}
-		
+
 		// End
 		if (! $error) {
 			$this->db->commit();
@@ -1158,11 +1158,11 @@ class BookKeeping extends CommonObject
 			return $object->id;
 		} else {
 			$this->db->rollback();
-			
+
 			return - 1;
 		}
 	}
-	
+
 	/**
 	 * Initialise object with example values
 	 * Id must be 0 if object instance is a specimen
@@ -1171,9 +1171,9 @@ class BookKeeping extends CommonObject
 	 */
 	public function initAsSpecimen() {
 		global $user;
-		
+
 		$now=dol_now();
-		
+
 		$this->id = 0;
 		$this->doc_date = $now;
 		$this->doc_type = '';
@@ -1192,7 +1192,7 @@ class BookKeeping extends CommonObject
 		$this->code_journal = '';
 		$this->piece_num = '';
 	}
-	
+
 	/**
 	 * Load an accounting document into memory from database
 	 *
@@ -1201,17 +1201,17 @@ class BookKeeping extends CommonObject
 	 */
 	public function fetchPerMvt($piecenum) {
 		global $conf;
-		
-	    $sql = "SELECT piece_num,doc_date,code_journal,doc_ref,doc_type";
+
+		$sql = "SELECT piece_num,doc_date,code_journal,doc_ref,doc_type";
 		$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
 		$sql .= " WHERE piece_num = " . $piecenum;
-	    $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
-		
+		$sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
+
 		dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG);
 		$result = $this->db->query($sql);
 		if ($result) {
 			$obj = $this->db->fetch_object($result);
-			
+
 			$this->piece_num = $obj->piece_num;
 			$this->code_journal = $obj->code_journal;
 			$this->doc_date = $this->db->jdate($obj->doc_date);
@@ -1222,10 +1222,10 @@ class BookKeeping extends CommonObject
 			dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR);
 			return - 1;
 		}
-		
+
 		return 1;
 	}
-	
+
 	/**
 	 * Return next number movement
 	 *
@@ -1233,8 +1233,8 @@ class BookKeeping extends CommonObject
 	 */
 	public function getNextNumMvt() 
 	{
-	    global $conf;
-	    
+		global $conf;
+
 		$sql = "SELECT MAX(piece_num)+1 as max FROM " . MAIN_DB_PREFIX . $this->table_element;
 	    $sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")";
 		
@@ -1243,16 +1243,16 @@ class BookKeeping extends CommonObject
 
 		if ($result) {
 			$obj = $this->db->fetch_object($result);
-	        if ($obj) $result = $obj->max;
-	        if (empty($result)) $result = 1;
-	        return $result;
+			if ($obj) $result = $obj->max;
+			if (empty($result)) $result = 1;
+			return $result;
 		} else {
 			$this->error = "Error " . $this->db->lasterror();
 			dol_syslog(get_class($this) . "::getNextNumMvt " . $this->error, LOG_ERR);
 			return - 1;
 		}
 	}
-	
+
 	/**
 	 * Load all informations of accountancy document
 	 *
@@ -1260,26 +1260,26 @@ class BookKeeping extends CommonObject
 	 * @return int <0 if KO, >0 if OK
 	 */
 	function fetch_all_per_mvt($piecenum) {
-	    global $conf;
-	    
+		global $conf;
+
 		$sql = "SELECT rowid, doc_date, doc_type,";
 		$sql .= " doc_ref, fk_doc, fk_docdet, code_tiers,";
 		$sql .= " numero_compte, label_compte, debit, credit,";
 		$sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num";
 		$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
 		$sql .= " WHERE piece_num = " . $piecenum;
-	    $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
-		
+		$sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
+
 		dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG);
 		$result = $this->db->query($sql);
 		if ($result) {
-			
+
 			while ( $obj = $this->db->fetch_object($result) ) {
-				
+
 				$line = new BookKeepingLine();
-				
+
 				$line->id = $obj->rowid;
-				
+
 				$line->doc_date = $this->db->jdate($obj->doc_date);
 				$line->doc_type = $obj->doc_type;
 				$line->doc_ref = $obj->doc_ref;
@@ -1294,7 +1294,7 @@ class BookKeeping extends CommonObject
 				$line->sens = $obj->sens;
 				$line->code_journal = $obj->code_journal;
 				$line->piece_num = $obj->piece_num;
-				
+
 				$this->linesmvt[] = $line;
 			}
 		} else {
@@ -1302,10 +1302,10 @@ class BookKeeping extends CommonObject
 			dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR);
 			return - 1;
 		}
-		
+
 		return 1;
 	}
-	
+
 	/**
 	 * Export bookkeping
 	 *
@@ -1313,28 +1313,28 @@ class BookKeeping extends CommonObject
 	 * @return int Result
 	 */
 	function export_bookkeping($model = 'ebp') {
-	    global $conf;
-	    
+		global $conf;
+
 		$sql = "SELECT rowid, doc_date, doc_type,";
 		$sql .= " doc_ref, fk_doc, fk_docdet, code_tiers,";
 		$sql .= " numero_compte, label_compte, debit, credit,";
 		$sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num";
 		$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
-	    $sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")";
-		
+		$sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")";
+
 		dol_syslog(get_class($this) . "::export_bookkeping", LOG_DEBUG);
-		
+
 		$resql = $this->db->query($sql);
-		
+
 		if ($resql) {
 			$this->linesexport = array ();
-			
+
 			$num = $this->db->num_rows($resql);
 			while ( $obj = $this->db->fetch_object($resql) ) {
 				$line = new BookKeepingLine();
-				
+
 				$line->id = $obj->rowid;
-				
+
 				$line->doc_date = $this->db->jdate($obj->doc_date);
 				$line->doc_type = $obj->doc_type;
 				$line->doc_ref = $obj->doc_ref;
@@ -1349,11 +1349,11 @@ class BookKeeping extends CommonObject
 				$line->sens = $obj->sens;
 				$line->code_journal = $obj->code_journal;
 				$line->piece_num = $obj->piece_num;
-				
+
 				$this->linesexport[] = $line;
 			}
 			$this->db->free($resql);
-			
+
 			return $num;
 		} else {
 			$this->error = "Error " . $this->db->lasterror();

+ 0 - 383
htdocs/accountancy/class/html.formventilation.class.php

@@ -1,383 +0,0 @@
-<?php
-/* Copyright (C) 2013-2016 Florian Henry        <florian.henry@open-concept.pro>
- * Copyright (C) 2013-2014 Olivier Geffroy      <jeff@jeffinfo.com>
- * Copyright (C) 2013-2016 Alexandre Spangaro   <aspangaro.dolibarr@gmail.com>
- * Copyright (C) 2015      Ari Elbaz (elarifr)  <github@accedinfo.com>
- * Copyright (C) 2016      Marcos García        <marcosgdf@gmail.com>
- *
- * 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		htdocs/accountancy/class/html.formventilation.class.php
- * \ingroup		Advanced accountancy
- * \brief		File of class with all html predefined components
- */
-
-/**
- * Class to manage generation of HTML components for bank module
- */
-class FormVentilation extends Form
-{
-
-    private $options_cache = array();
-
-
-	/**
-	 * Return select filter with date of transaction
-	 *
-	 * @param string $htmlname Name of select field
-	 * @param string $selectedkey Value
-	 * @return string HTML edit field
-	 */
-	function select_bookkeeping_importkey($htmlname = 'importkey', $selectedkey = '') {
-		$options = array();
-
-		$sql = 'SELECT DISTINCT import_key from ' . MAIN_DB_PREFIX . 'accounting_bookkeeping';
-	    $sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")";
-		$sql .= ' ORDER BY import_key DESC';
-
-		dol_syslog(get_class($this) . "::select_bookkeeping_importkey", LOG_DEBUG);
-		$resql = $this->db->query($sql);
-
-		if (!$resql) {
-			$this->error = "Error " . $this->db->lasterror();
-			dol_syslog(get_class($this) . "::select_bookkeeping_importkey " . $this->error, LOG_ERR);
-			return - 1;
-		}
-
-		while ($obj = $this->db->fetch_object($resql)) {
-			$options[$obj->import_key] = dol_print_date($obj->import_key, 'dayhourtext');
-		}
-
-		return Form::selectarray($htmlname, $options, $selectedkey);
-	}
-
-	/**
-	 * Return list of accounts with label by chart of accounts
-	 *
-	 * @param string   $selectid           Preselected id or code of accounting accounts (depends on $select_in)
-	 * @param string   $htmlname           Name of field in html form
-	 * @param int      $showempty          Add an empty field
-	 * @param array    $event              Event options
-	 * @param int      $select_in          0=selectid value is a aa.rowid (default) or 1=selectid is aa.account_number
-	 * @param int      $select_out         Set value returned by select. 0=rowid (default), 1=account_number
-	 * @param string   $morecss            More css non HTML object
-	 * @param string   $usecache           Key to use to store result into a cache. Next call with same key will reuse the cache.
-	 * @return string                      String with HTML select
-	 */
-	function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $morecss='maxwidth300 maxwidthonsmartphone', $usecache='')
-	{
-		global $conf;
-
-		require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
-
-		$out = '';
-		
-    	$options = array();
-		if ($usecache && ! empty($this->options_cache[$usecache]))
-		{
-		    $options = $this->options_cache[$usecache];
-		    $selected=$selectid;
-		}
-		else
-		{
-    		$trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT') ? $conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT : 50;
-
-    		$sql = "SELECT DISTINCT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version";
-    		$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa";
-    		$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
-    		$sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS;
-    		$sql .= " AND aa.active = 1";
-    		$sql .= " ORDER BY aa.account_number";
-
-    		dol_syslog(get_class($this) . "::select_account", LOG_DEBUG);
-    		$resql = $this->db->query($sql);
-
-    		if (!$resql) {
-    			$this->error = "Error " . $this->db->lasterror();
-    			dol_syslog(get_class($this) . "::select_account " . $this->error, LOG_ERR);
-    			return -1;
-    		}
-
-    		$out .= ajax_combobox($htmlname, $event);
-
-    		$selected = 0;
-    		while ($obj = $this->db->fetch_object($resql))
-    		{
-    			$label = length_accountg($obj->account_number) . ' - ' . $obj->label;
-    			$label = dol_trunc($label, $trunclength);
-
-    			$select_value_in = $obj->rowid;
-    			$select_value_out = $obj->rowid;
-
-    			// Try to guess if we have found default value
-    			if ($select_in == 1) {
-    				$select_value_in = $obj->account_number;
-    			}
-    			if ($select_out == 1) {
-    				$select_value_out = $obj->account_number;
-    			}
-    			// Remember guy's we store in database llx_facturedet the rowid of accounting_account and not the account_number
-    			// Because same account_number can be share between different accounting_system and do have the same meaning
-    			if ($selectid != '' && $selectid == $select_value_in) {
-    			    //var_dump("Found ".$selectid." ".$select_value_in);
-    				$selected = $select_value_out;
-    			}
-
-    			$options[$select_value_out] = $label;
-    		}
-    		$this->db->free($resql);
-
-    		if ($usecache)
-    		{
-                $this->options_cache[$usecache] = $options;
-    		}
-		}
-
-		$out .= Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
-
-		return $out;
-	}
-
-	/**
-	 * Return list of accounts with label by class of accounts
-	 *
-	 * @param string $selectid Preselected pcg_type
-	 * @param string $htmlname Name of field in html form
-	 * @param int $showempty Add an empty field
-	 * @param array $event Event options
-	 *
-	 * @return string String with HTML select
-	 */
-	function select_pcgtype($selectid, $htmlname = 'pcg_type', $showempty = 0, $event = array()) {
-		global $conf;
-
-		$sql = "SELECT DISTINCT pcg_type ";
-		$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa";
-		$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
-		$sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS;
-		$sql .= " ORDER BY pcg_type";
-
-		dol_syslog(get_class($this) . "::select_pcgtype", LOG_DEBUG);
-		$resql = $this->db->query($sql);
-
-		if (!$resql) {
-			$this->error = "Error ".$this->db->lasterror();
-			dol_syslog(get_class($this)."::select_pcgtype ".$this->error, LOG_ERR);
-			return -1;
-		}
-
-		$options = array();
-		$out = ajax_combobox($htmlname, $event);
-
-		while ($obj = $this->db->fetch_object($resql)) 
-		{
-		    if ($obj->pcg_type != '-1')
-		    {
-                $options[$obj->pcg_type] = $obj->pcg_type;
-		    }
-		}
-
-		$out .= Form::selectarray($htmlname, $options, $selectid, $showempty, 0, 0, '', 0, 0, 0, '', 'minwidth200');
-
-		$this->db->free($resql);
-		return $out;
-	}
-
-	/**
-	 * Return list of accounts with label by sub_class of accounts
-	 *
-	 * @param string $selectid Preselected pcg_type
-	 * @param string $htmlname Name of field in html form
-	 * @param int $showempty Add an empty field
-	 * @param array $event Event options
-	 *
-	 * @return string String with HTML select
-	 */
-	function select_pcgsubtype($selectid, $htmlname = 'pcg_subtype', $showempty = 0, $event = array()) 
-	{
-		global $conf;
-
-		$sql = "SELECT DISTINCT pcg_subtype ";
-		$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa";
-		$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
-		$sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS;
-		$sql .= " ORDER BY pcg_subtype";
-
-		dol_syslog(get_class($this) . "::select_pcgsubtype", LOG_DEBUG);
-		$resql = $this->db->query($sql);
-
-		if (!$resql) {
-			$this->error = "Error ".$this->db->lasterror();
-			dol_syslog(get_class($this)."::select_pcgsubtype ".$this->error, LOG_ERR);
-			return -1;
-		}
-
-		$options = array();
-		$out = ajax_combobox($htmlname, $event);
-
-		while ($obj = $this->db->fetch_object($resql)) 
-		{
-		    if ($obj->pcg_type != '-1')
-		    {
-                $options[$obj->pcg_subtype] = $obj->pcg_subtype;
-		    }
-		}
-
-		$out .= Form::selectarray($htmlname, $options, $selectid, $showempty, 0, 0, '', 0, 0, 0, '', 'minwidth200');
-
-		$this->db->free($resql);
-		return $out;
-	}
-
-	/**
-	 * Return list of auxilary thirdparty accounts
-	 *
-	 * @param string $selectid Preselected pcg_type
-	 * @param string $htmlname Name of field in html form
-	 * @param int $showempty Add an empty field
-	 * @param array $event Event options
-	 *
-	 * @return string String with HTML select
-	 */
-	function select_auxaccount($selectid, $htmlname = 'account_num_aux', $showempty = 0, $event = array()) {
-
-		$aux_account = array();
-
-		// Auxiliary customer account
-		$sql = "SELECT DISTINCT code_compta, nom ";
-		$sql .= " FROM ".MAIN_DB_PREFIX."societe";
-	    $sql .= " WHERE entity IN (" . getEntity("societe", 1) . ")";
-		$sql .= " ORDER BY code_compta";
-		dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG);
-		$resql = $this->db->query($sql);
-		if ($resql) {
-			while ($obj = $this->db->fetch_object($resql)) {
-				if (!empty($obj->code_compta)) {
-					$aux_account[$obj->code_compta] = $obj->code_compta.' ('.$obj->nom.')';
-				}
-			}
-		} else {
-			$this->error = "Error ".$this->db->lasterror();
-			dol_syslog(get_class($this)."::select_pcgsubtype ".$this->error, LOG_ERR);
-			return -1;
-		}
-		$this->db->free($resql);
-
-		// Auxiliary supplier account
-		$sql = "SELECT DISTINCT code_compta_fournisseur, nom ";
-		$sql .= " FROM ".MAIN_DB_PREFIX."societe";
-	    $sql .= " WHERE entity IN (" . getEntity("societe", 1) . ")";
-		$sql .= " ORDER BY code_compta_fournisseur";
-		dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG);
-		$resql = $this->db->query($sql);
-		if ($resql) {
-			while ($obj = $this->db->fetch_object($resql)) {
-				if (!empty($obj->code_compta_fournisseur)) {
-					$aux_account[$obj->code_compta_fournisseur] = $obj->code_compta_fournisseur.' ('.$obj->nom.')';
-				}
-			}
-		} else {
-			$this->error = "Error ".$this->db->lasterror();
-			dol_syslog(get_class($this)."::select_pcgsubtype ".$this->error, LOG_ERR);
-			return -1;
-		}
-		$this->db->free($resql);
-
-		// Build select
-		$out = ajax_combobox($htmlname, $event);
-		$out .= Form::selectarray($htmlname, $aux_account, $selectid, $showempty, 0, 0, '', 0, 0, 0, '', 'maxwidth300');
-
-		return $out;
-	}
-
-	/**
-	 * Return HTML combo list of years existing into book keepping
-	 *
-	 * @param string $selected Preselected value
-	 * @param string $htmlname Name of HTML select object
-	 * @param int $useempty Affiche valeur vide dans liste
-	 * @param string $output_format (html/opton (for option html only)/array (to return options arrays
-	 * @return string/array
-	 */
-	function selectyear_accountancy_bookkepping($selected = '', $htmlname = 'yearid', $useempty = 0, $output_format = 'html')
-	{
-	    global $conf;
-
-		$out_array = array();
-
-		$sql = "SELECT DISTINCT date_format(doc_date,'%Y') as dtyear";
-		$sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping";
-	    $sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")";
-		$sql .= " ORDER BY date_format(doc_date,'%Y')";
-		dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG);
-		$resql = $this->db->query($sql);
-
-		if (!$resql) {
-			$this->error = "Error ".$this->db->lasterror();
-			dol_syslog(get_class($this)."::".__METHOD__.$this->error, LOG_ERR);
-			return -1;
-		}
-		while ($obj = $this->db->fetch_object($resql)) {
-			$out_array[$obj->dtyear] = $obj->dtyear;
-		}
-		$this->db->free($resql);
-
-		if ($output_format == 'html') {
-			return Form::selectarray($htmlname, $out_array, $selected, $useempty, 0, 0, 'placeholder="aa"');
-		} else {
-			return $out_array;
-		}
-	}
-
-	/**
-	 * Return HTML combo list of years existing into book keepping
-	 *
-	 * @param  string          $selected       Preselected value
-	 * @param  string          $htmlname       Name of HTML select object
-	 * @param  int             $useempty       Affiche valeur vide dans liste
-	 * @param  string          $output_format  Html/option (for option html only)/array (to return options arrays
-	 * @return string/array
-	 */
-	function selectjournal_accountancy_bookkepping($selected = '', $htmlname = 'journalid', $useempty = 0, $output_format = 'html')
-	{
-	    global $conf,$langs;
-
-		$out_array = array();
-
-		$sql = "SELECT DISTINCT code_journal";
-		$sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping";
-	    $sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")";
-		$sql .= " ORDER BY code_journal";
-		dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG);
-		$resql = $this->db->query($sql);
-
-		if (!$resql) {
-			$this->error = "Error ".$this->db->lasterror();
-			dol_syslog(get_class($this)."::".__METHOD__.$this->error, LOG_ERR);
-			return -1;
-		}
-		while ($obj = $this->db->fetch_object($resql)) {
-			$out_array[$obj->code_journal] = $obj->code_journal?$obj->code_journal:$langs->trans("NotDefined");  // TODO Not defined is accepted ? We should avoid this, shouldn't we ?
-		}
-		$this->db->free($resql);
-
-		if ($output_format == 'html') {
-			return Form::selectarray($htmlname, $out_array, $selected, $useempty, 0, 0, 'placeholder="aa"');
-		} else {
-			return $out_array;
-		}
-	}
-}

+ 18 - 20
htdocs/accountancy/customer/card.php

@@ -1,7 +1,7 @@
 <?php
 /* Copyright (C) 2013-2014 Olivier Geffroy		<jeff@jeffinfo.com>
  * Copyright (C) 2013-2014 Florian Henry		<florian.henry@open-concept.pro>
- * Copyright (C) 2013-2015 Alexandre Spangaro	<aspangaro.dolibarr@gmail.com>
+ * Copyright (C) 2013-2017 Alexandre Spangaro	<aspangaro.dolibarr@gmail.com>
  *
  * 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
@@ -26,7 +26,7 @@ require '../../main.inc.php';
 
 // Class
 require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
-require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 
 // Langs
 $langs->load("bills");
@@ -39,9 +39,7 @@ $id = GETPOST('id');
 // Security check
 if ($user->societe_id > 0)
 	accessforbidden();
-	
-	
-	
+
 /*
  * Actions
  */
@@ -84,7 +82,7 @@ if ($cancel == $langs->trans("Cancel")) {
  */
 $form = new Form($db);
 $facture_static = new Facture($db);
-$formventilation = new FormVentilation($db);
+$formaccounting = new FormAccounting($db);
 
 if (! empty($id)) {
 	$sql = "SELECT f.facnumber, f.rowid as facid, l.fk_product, l.description, l.price,";
@@ -96,50 +94,50 @@ if (! empty($id)) {
 	$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = l.fk_facture";
 	$sql .= " WHERE f.fk_statut > 0 AND l.rowid = " . $id;
 	$sql .= " AND f.entity IN (" . getEntity("facture", 0) . ")"; // We don't share object for accountancy
-	
+
 	dol_syslog("/accounting/customer/card.php sql=" . $sql, LOG_DEBUG);
 	$result = $db->query($sql);
-	
+
 	if ($result) {
 		$num_lines = $db->num_rows($result);
 		$i = 0;
-		
+
 		if ($num_lines) {
-			
+
 			$objp = $db->fetch_object($result);
-			
+
 			print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $id . '" method="post">' . "\n";
 			print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
 			print '<input type="hidden" name="action" value="ventil">';
-			
+
 			print load_fiche_titre($langs->trans('CustomersVentilation'), '', 'title_setup');
-			
+
 			dol_fiche_head();
-			
+
 			print '<table class="border" width="100%">';
-			
+
 			// Ref facture
 			print '<tr><td>' . $langs->trans("Invoice") . '</td>';
 			$facture_static->ref = $objp->facnumber;
 			$facture_static->id = $objp->facid;
 			print '<td>' . $facture_static->getNomUrl(1) . '</td>';
 			print '</tr>';
-			
+
 			print '<tr><td width="20%">' . $langs->trans("Line") . '</td>';
 			print '<td>' . nl2br($objp->description) . '</td></tr>';
 			print '<tr><td width="20%">' . $langs->trans("Account") . '</td><td>';
-			print $formventilation->select_account($objp->fk_code_ventilation, 'codeventil', 1);
+			print $formaccounting->select_account($objp->fk_code_ventilation, 'codeventil', 1);
 			print '</td></tr>';
 			print '</table>';
-			
+
 			dol_fiche_end();
-			
+
 			print '<div class="center">';
 			print '<input class="button" type="submit" value="' . $langs->trans("Save") . '">';
 			print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
 			print '<input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '">';
 			print '</div>';
-			
+
 			print '</form>';
 		} else {
 			print "Error";

+ 17 - 17
htdocs/accountancy/customer/lines.php

@@ -28,7 +28,7 @@
 require '../../main.inc.php';
 
 // Class
-require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
 require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
@@ -77,7 +77,7 @@ if ($user->societe_id > 0)
 if (! $user->rights->accounting->bind->write)
 	accessforbidden();
 
-$formventilation = new FormVentilation($db);
+$formaccounting = new FormAccounting($db);
 
 
 /*
@@ -254,14 +254,14 @@ if ($result) {
 	print $langs->trans("DescVentilDoneCustomer") . '<br>';
 
 	print '<br><div class="inline-block divButAction">' . $langs->trans("ChangeAccount") . '<br>';
-	print $formventilation->select_account($account_parent, 'account_parent', 1);
+	print $formaccounting->select_account($account_parent, 'account_parent', 1);
 	print '<input type="submit" class="button valignmiddle" value="' . $langs->trans("ChangeBinding") . '"/></div>';
 
 	$moreforfilter = '';
-	
-    print '<div class="div-table-responsive">';
+
+	print '<div class="div-table-responsive">';
 	print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
-	
+
 	print '<tr class="liste_titre_filter">';
 	print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_lineid" value="' . dol_escape_htmltag($search_lineid) . '""></td>';
 	print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="' . dol_escape_htmltag($search_invoice) . '"></td>';
@@ -278,7 +278,7 @@ if ($result) {
 	$searchpicto=$form->showFilterButtons();
 	print $searchpicto;
 	print "</td></tr>\n";
-	
+
 	print '<tr class="liste_titre">';
 	print_liste_field_titre($langs->trans("LineId"), $_SERVER["PHP_SELF"], "fd.rowid", "", $param, '', $sortfield, $sortorder);
 	print_liste_field_titre($langs->trans("Invoice"), $_SERVER["PHP_SELF"], "f.facnumber", "", $param, '', $sortfield, $sortorder);
@@ -303,16 +303,16 @@ if ($result) {
 
 		$facture_static->ref = $objp->facnumber;
 		$facture_static->id = $objp->rowid;
-		
+
 		$product_static->ref = $objp->product_ref;
 		$product_static->id = $objp->product_id;
 		$product_static->type = $objp->product_type;
 		$product_static->label = $objp->product_label;
-		
+
 		print '<tr class="oddeven">';
 
 		print '<td>' . $objp->rowid . '</td>';
-		
+
 		// Ref Invoice
 		print '<td>' . $facture_static->getNomUrl(1) . '</td>';
 
@@ -324,13 +324,13 @@ if ($result) {
 			print $product_static->getNomUrl(1);
 		if ($objp->product_label) print '<br>'.$objp->product_label;
 		print '</td>';
-		
+
 		print '<td>';
 		$text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->description));
 		$trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION') ? ACCOUNTING_LENGTH_DESCRIPTION : 32;
 		print $form->textwithtooltip(dol_trunc($text,$trunclength), $objp->description);
 		print '</td>';
-		
+
 		print '<td align="right">' . price($objp->total_ht) . '</td>';
 		print '<td align="center">' . price($objp->tva_tx) . '</td>';
 		print '<td>';
@@ -338,20 +338,20 @@ if ($result) {
 		print img_edit();
 		print '</a>';
 		print '</td>';
-		
+
 		print '<td>' . $objp->country .'</td>';
-		
+
 		print '<td>' . $objp->tva_intra . '</td>';
-		
+
 		print '<td class="center"><input type="checkbox" class="checkforaction" name="changeaccount[]" value="' . $objp->rowid . '"/></td>';
 
 		print "</tr>";
 		$i ++;
 	}
-	
+
 	print "</table>";
 	print "</div>";
-	
+
     if ($nbtotalofrecords > $limit) {
         print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, '', 0, '', '', $limit, 1);
     }

+ 21 - 22
htdocs/accountancy/customer/list.php

@@ -30,7 +30,7 @@ require '../../main.inc.php';
 // Class
 require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
 require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
-require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
 
@@ -85,7 +85,7 @@ if ($user->societe_id > 0)
 if (! $user->rights->accounting->bind->write)
 	accessforbidden();
 
-$formventilation = new FormVentilation($db);
+$formaccounting = new FormAccounting($db);
 $accounting = new AccountingAccount($db);
 $aarowid_s = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT, 1);
 $aarowid_p = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT, 1);
@@ -101,7 +101,7 @@ if (! GETPOST('confirmmassaction') && $massaction != 'presend' && $massaction !=
 // Purge search criteria
 if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All test are required to be compatible with all browsers
 {
-    $search_lineid = '';
+	$search_lineid = '';
 	$search_ref = '';
 	$search_invoice = '';
 	$search_label = '';
@@ -241,7 +241,7 @@ if ($result) {
 	$i = 0;
 
 	$arrayofselected=is_array($toselect)?$toselect:array();
-	
+
 	$param='';
 	if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
 	if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
@@ -254,8 +254,7 @@ if ($result) {
 	//if ($user->rights->mymodule->supprimer) $arrayofmassactions['delete']=$langs->trans("Delete");
 	//if ($massaction == 'presend') $arrayofmassactions=array();
 	$massactionbutton=$form->selectMassAction('ventil', $arrayofmassactions, 1);
-	
-	
+
 	print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">' . "\n";
 	print '<input type="hidden" name="action" value="ventil">';
 	if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
@@ -264,16 +263,16 @@ if ($result) {
 	print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
 	print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
 	print '<input type="hidden" name="page" value="'.$page.'">';
-	
+
 	print_barre_liste($langs->trans("InvoiceLines"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit);
 
 	print $langs->trans("DescVentilTodoCustomer") . '</br><br>';
 
 	if ($msg) print $msg.'<br>';
-	
+
 	$moreforfilter = '';
-	
-    print '<div class="div-table-responsive">';
+
+	print '<div class="div-table-responsive">';
 	print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
 
 	// We add search filter
@@ -309,7 +308,7 @@ if ($result) {
 	if ($massactionbutton) $checkpicto=$form->showCheckAddButtons('checkforselect', 1);
 	print_liste_field_titre($checkpicto, '', '', '', '', 'align="center"');
 	print "</tr>\n";
-	
+
 	$facture_static = new Facture($db);
 	$product_static = new Product($db);
 	$form = new Form($db);
@@ -330,7 +329,7 @@ if ($result) {
 		$facture_static->ref = $objp->facnumber;
 		$facture_static->id = $objp->facid;
 		$facture_static->type = $objp->ftype;
-		
+
 		$code_sell_p_notset = '';
 		$objp->aarowid_suggest = $objp->aarowid;
 
@@ -350,30 +349,30 @@ if ($result) {
 		if (! empty($objp->code_sell)) {
 			$objp->code_sell_p = $objp->code_sell;       // Code on product
 		} else {
-    	    $code_sell_p_notset = 'color:orange';
+			$code_sell_p_notset = 'color:orange';
 		}
 		if (empty($objp->code_sell_l) && empty($objp->code_sell_p)) $code_sell_p_notset = 'color:red';
-		
+
 		// $objp->code_sell_p is now code of product/service
 		// $objp->code_sell_l is now default code of product/service
-					
+
 		print '<tr class="oddeven">';
 
 		// Line id
 		print '<td>' . $objp->rowid . '</td>';
-		
+
 		// Ref Invoice
 		print '<td>' . $facture_static->getNomUrl(1) . '</td>';
 
 		print '<td align="center">' . dol_print_date($db->jdate($objp->datef), 'day') . '</td>';
-		
+
 		// Ref Product
 		print '<td>';
 		if ($product_static->id)
 			print $product_static->getNomUrl(1);
 		if ($objp->product_label) print '<br>'.$objp->product_label;
 		print '</td>';
-		
+
 		print '<td class="tdoverflowonsmartphone">';
 		$text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->description));
 		$trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION') ? ACCOUNTING_LENGTH_DESCRIPTION : 32;
@@ -383,14 +382,14 @@ if ($result) {
 		print '<td align="right">';
 		print price($objp->total_ht);
 		print '</td>';
-		
+
 		// Vat rate
 		if ($objp->vat_tx_l != $objp->vat_tx_p)
 			$code_vat_differ = 'font-weight:bold; text-decoration:blink; color:red';
 		print '<td style="' . $code_vat_differ . '" align="right">';
 		print price($objp->tva_tx_line);
 		print '</td>';
-		
+
 		// Current account
 		print '<td align="center" style="' . $code_sell_p_notset . '">';
 	    print (($objp->type_l == 1)?$langs->trans("DefaultForService"):$langs->trans("DefaultForProduct")) . ' = ' . ($objp->code_sell_l > 0 ? length_accountg($objp->code_sell_l) : $langs->trans("Unknown"));
@@ -403,7 +402,7 @@ if ($result) {
 
 		// Suggested accounting account
 		print '<td align="center">';
-		print $formventilation->select_account($objp->aarowid_suggest, 'codeventil'.$objp->rowid, 1, array(), 0, 0, 'maxwidth300 maxwidthonsmartphone', 'cachewithshowemptyone');
+		print $formaccounting->select_account($objp->aarowid_suggest, 'codeventil'.$objp->rowid, 1, array(), 0, 0, 'maxwidth300 maxwidthonsmartphone', 'cachewithshowemptyone');
 		print '</td>';
 		
 		print '<td align="center">';
@@ -414,7 +413,7 @@ if ($result) {
 	}
 	print '</table>';
 	print "</div>";
-	
+
 	print '</form>';
 } else {
 	print $db->error();

+ 3 - 3
htdocs/accountancy/expensereport/card.php

@@ -30,7 +30,7 @@ require '../../main.inc.php';
 
 // Class
 require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php';
-require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 
 // Langs
 $langs->load("bills");
@@ -85,7 +85,7 @@ if ($cancel == $langs->trans("Cancel")) {
 // Create
 $form = new Form($db);
 $expensereport_static = new ExpenseReport($db);
-$formventilation = new FormVentilation($db);
+$formaccounting = new FormAccounting($db);
 
 if (! empty($id)) {
 	$sql = "SELECT er.ref, er.rowid as facid, erd.fk_c_type_fees, erd.comments, erd.rowid, erd.fk_code_ventilation,";
@@ -135,7 +135,7 @@ if (! empty($id)) {
 			print '<td>' . ($langs->trans($objp->type_fees_code) == $objp->type_fees_code ? $objp->type_fees_label : $langs->trans(($objp->type_fees_code))) . '</td>';
 
 			print '<tr><td>' . $langs->trans("Account") . '</td><td>';
-			print $formventilation->select_account($objp->fk_code_ventilation, 'codeventil', 1);
+			print $formaccounting->select_account($objp->fk_code_ventilation, 'codeventil', 1);
 			print '</td></tr>';
 			print '</table>';
 

+ 3 - 3
htdocs/accountancy/expensereport/lines.php

@@ -27,7 +27,7 @@
 require '../../main.inc.php';
 
 // Class
-require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php';
 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
@@ -74,7 +74,7 @@ if ($user->societe_id > 0)
 if (! $user->rights->accounting->bind->write)
 	accessforbidden();
 
-$formventilation = new FormVentilation($db);
+$formaccounting = new FormAccounting($db);
 
 
 /*
@@ -226,7 +226,7 @@ if ($result) {
 	print $langs->trans("DescVentilDoneExpenseReport") . '<br>';
 
 	print '<br><div class="inline-block divButAction">' . $langs->trans("ChangeAccount") . '<br>';
-	print $formventilation->select_account(GETPOST('account_parent'), 'account_parent', 1);
+	print $formaccounting->select_account(GETPOST('account_parent'), 'account_parent', 1);
 	print '<input type="submit" class="button valignmiddle" value="' . $langs->trans("ChangeBinding") . '" /></div>';
 
 	$moreforfilter = '';

+ 3 - 3
htdocs/accountancy/expensereport/list.php

@@ -29,7 +29,7 @@ require '../../main.inc.php';
 
 // Class
 require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php';
-require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
 
@@ -83,7 +83,7 @@ if ($user->societe_id > 0)
 if (! $user->rights->accounting->bind->write)
 	accessforbidden();
 
-$formventilation = new FormVentilation($db);
+$formaccounting = new FormAccounting($db);
 $accounting = new AccountingAccount($db);
 
 
@@ -343,7 +343,7 @@ if ($result) {
 
 		// Suggested accounting account
 		print '<td align="center">';
-		print $formventilation->select_account($objp->aarowid_suggest, 'codeventil'.$objp->rowid, 1, array(), 0, 0, 'maxwidth300 maxwidthonsmartphone', 'cachewithshowemptyone');
+		print $formaccounting->select_account($objp->aarowid_suggest, 'codeventil'.$objp->rowid, 1, array(), 0, 0, 'maxwidth300 maxwidthonsmartphone', 'cachewithshowemptyone');
 		print '</td>';
 
 		print '<td align="center">';

+ 18 - 18
htdocs/accountancy/supplier/card.php

@@ -1,11 +1,11 @@
 <?php
 /* Copyright (C) 2004       Rodolphe Quiedeville  <rodolphe@quiedeville.org>
  * Copyright (C) 2005       Simon TOSSER          <simon@kornog-computing.com>
- * Copyright (C) 2013-2015  Alexandre Spangaro    <aspangaro.dolibarr@gmail.com>
+ * Copyright (C) 2013-2017  Alexandre Spangaro    <aspangaro.dolibarr@gmail.com>
  * Copyright (C) 2013-2014  Olivier Geffroy       <jeff@jeffinfo.com>
- * Copyright (C) 2013-2014	Florian Henry	      <florian.henry@open-concept.pro>
- * Copyright (C) 2014	    Juanjo Menent		  <jmenent@2byte.es>
- * Copyright (C) 2015       Jean-François Ferry	  <jfefe@aternatik.fr>
+ * Copyright (C) 2013-2014  Florian Henry         <florian.henry@open-concept.pro>
+ * Copyright (C) 2014       Juanjo Menent         <jmenent@2byte.es>
+ * Copyright (C) 2015       Jean-François Ferry   <jfefe@aternatik.fr>
  *
  * 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
@@ -30,7 +30,7 @@ require '../../main.inc.php';
 
 // Class
 require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
-require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 
 // Langs
 $langs->load("bills");
@@ -52,11 +52,11 @@ if ($user->societe_id > 0)
 if ($action == 'ventil' && $user->rights->accounting->bind->write) {
 	if (! GETPOST('cancel', 'alpha')) {
 	    if ($codeventil < 0) $codeventil = 0;
-	    
+
 		$sql = " UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det";
 		$sql .= " SET fk_code_ventilation = " . $codeventil;
 		$sql .= " WHERE rowid = " . $id;
-		
+
 		$resql = $db->query($sql);
 		if (! $resql) {
 			setEventMessages($db->lasterror(), null, 'errors');
@@ -85,7 +85,7 @@ if ($cancel == $langs->trans("Cancel")) {
 // Create
 $form = new Form($db);
 $facturefournisseur_static = new FactureFournisseur($db);
-$formventilation = new FormVentilation($db);
+$formaccounting = new FormAccounting($db);
 
 if (! empty($id)) {
 	$sql = "SELECT f.ref as facnumber, f.rowid as facid, l.fk_product, l.description, l.rowid, l.fk_code_ventilation, ";
@@ -107,41 +107,41 @@ if (! empty($id)) {
 		
 		if ($num_lines) {
 			$objp = $db->fetch_object($result);
-			
+
 			print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $id . '" method="post">' . "\n";
 			print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
 			print '<input type="hidden" name="action" value="ventil">';
-			
+
 			print load_fiche_titre($langs->trans('SuppliersVentilation'), '', 'title_setup');
-			
+
 			dol_fiche_head();
-			
+
 			print '<table class="border" width="100%">';
-			
+
 			// ref invoice
 			print '<tr><td>' . $langs->trans("BillsSuppliers") . '</td>';
 			$facturefournisseur_static->ref = $objp->facnumber;
 			$facturefournisseur_static->id = $objp->facid;
 			print '<td>' . $facturefournisseur_static->getNomUrl(1) . '</td>';
 			print '</tr>';
-			
+
 			print '<tr><td width="20%">' . $langs->trans("Line") . '</td>';
 			print '<td>' . stripslashes(nl2br($objp->description)) . '</td></tr>';
 			print '<tr><td width="20%">' . $langs->trans("ProductLabel") . '</td>';
 			print '<td>' . dol_trunc($objp->product_label, 24) . '</td>';
 			print '<tr><td width="20%">' . $langs->trans("Account") . '</td><td>';
-			print $formventilation->select_account($objp->fk_code_ventilation, 'codeventil', 1);
+			print $formaccounting->select_account($objp->fk_code_ventilation, 'codeventil', 1);
 			print '</td></tr>';
 			print '</table>';
-			
+
 			dol_fiche_end();
-			
+
 			print '<div class="center">';
 			print '<input class="button" type="submit" value="' . $langs->trans("Save") . '">';
 			print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
 			print '<input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '">';
 			print '</div>';
-			
+
 			print '</form>';
 		} else {
 			print "Error";

+ 5 - 5
htdocs/accountancy/supplier/lines.php

@@ -1,9 +1,9 @@
 <?php
 /* Copyright (C) 2013-2016 Olivier Geffroy		<jeff@jeffinfo.com>
- * Copyright (C) 2013-2016 Alexandre Spangaro	<aspangaro.dolibarr@gmail.com>
+ * Copyright (C) 2013-2017 Alexandre Spangaro	<aspangaro.dolibarr@gmail.com>
  * Copyright (C) 2014-2015 Ari Elbaz (elarifr)	<github@accedinfo.com>  
  * Copyright (C) 2013-2016 Florian Henry		<florian.henry@open-concept.pro>
- * Copyright (C) 2014	   Juanjo Menent		<jmenent@2byte.es>
+ * Copyright (C) 2014      Juanjo Menent		<jmenent@2byte.es>
  *   
  * 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
@@ -27,7 +27,7 @@
 require '../../main.inc.php';
 
 // Class
-require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
 require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
@@ -76,7 +76,7 @@ if ($user->societe_id > 0)
 if (! $user->rights->accounting->bind->write)
 	accessforbidden();
 
-$formventilation = new FormVentilation($db);
+$formaccounting = new FormAccounting($db);
 
 
 /*
@@ -237,7 +237,7 @@ if ($result) {
 	print $langs->trans("DescVentilDoneSupplier") . '<br>';
 	
 	print '<br><div class="inline-block divButAction">' . $langs->trans("ChangeAccount") . '<br>';
-	print $formventilation->select_account(GETPOST('account_parent'), 'account_parent', 1);
+	print $formaccounting->select_account(GETPOST('account_parent'), 'account_parent', 1);
 	print '<input type="submit" class="button valignmiddle" value="' . $langs->trans("ChangeBinding") . '" /></div>';
 	
 	$moreforfilter = '';

+ 19 - 20
htdocs/accountancy/supplier/list.php

@@ -1,10 +1,10 @@
 <?php
 /* Copyright (C) 2013-2014	Olivier Geffroy			<jeff@jeffinfo.com>
- * Copyright (C) 2013-2016	Alexandre Spangaro		<aspangaro.dolibarr@gmail.com>
+ * Copyright (C) 2013-2017	Alexandre Spangaro		<aspangaro.dolibarr@gmail.com>
  * Copyright (C) 2014-2015	Ari Elbaz (elarifr)		<github@accedinfo.com>
  * Copyright (C) 2013-2014	Florian Henry			<florian.henry@open-concept.pro>
  * Copyright (C) 2014		Juanjo Menent			<jmenent@2byte.es>s
- * Copyright (C) 2016	  	Laurent Destailleur     <eldy@users.sourceforge.net>
+ * Copyright (C) 2016		Laurent Destailleur		<eldy@users.sourceforge.net>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -30,7 +30,7 @@ require '../../main.inc.php';
 // Class
 require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
 require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php';
-require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
 
@@ -85,7 +85,7 @@ if ($user->societe_id > 0)
 if (! $user->rights->accounting->bind->write)
 	accessforbidden();
 
-$formventilation = new FormVentilation($db);
+$formaccounting = new FormAccounting($db);
 $accounting = new AccountingAccount($db);
 // TODO: we should need to check if result is a really exist accountaccount rowid.....
 $aarowid_s = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT, 1);
@@ -238,11 +238,11 @@ if ($result) {
 	$i = 0;
 
 	$arrayofselected=is_array($toselect)?$toselect:array();
-	
+
 	$param='';
 	if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
 	if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
-	
+
 	$arrayofmassactions =  array(
 	    'ventil'=>$langs->trans("Ventilate")
 	    //'presend'=>$langs->trans("SendByMail"),
@@ -251,8 +251,7 @@ if ($result) {
 	//if ($user->rights->mymodule->supprimer) $arrayofmassactions['delete']=$langs->trans("Delete");
 	//if ($massaction == 'presend') $arrayofmassactions=array();
 	$massactionbutton=$form->selectMassAction('ventil', $arrayofmassactions, 1);
-	
-	
+
 	print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">' . "\n";
 	print '<input type="hidden" name="action" value="ventil">';
 	if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
@@ -261,15 +260,15 @@ if ($result) {
 	print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
 	print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
 	print '<input type="hidden" name="page" value="'.$page.'">';
-	
+
 	print_barre_liste($langs->trans("InvoiceLines"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit);
 
 	print $langs->trans("DescVentilTodoCustomer") . '</br><br>';
 
 	if ($msg) print $msg.'<br>';
-	
+
 	$moreforfilter = '';
-	
+
     print '<div class="div-table-responsive">';
 
     print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
@@ -329,7 +328,7 @@ if ($result) {
 		$productfourn_static->id = $objp->product_id;
 		$productfourn_static->type = $objp->type;
 		$productfourn_static->label = $objp->product_label;
-		
+
 		$facturefourn_static->ref = $objp->ref;
 		$facturefourn_static->id = $objp->facid;
 		$facturefourn_static->type = $objp->type;
@@ -347,14 +346,14 @@ if ($result) {
 				$objp->aarowid_suggest = $aarowid_p;
 		}
 		if ($objp->code_buy_l == -1) $objp->code_buy_l='';
-		
+
 		if (! empty($objp->code_buy)) {
 			$objp->code_buy_p = $objp->code_buy;       // Code on product
 		} else {
 			$code_buy_p_notset = 'color:orange';
 		}
 		if (empty($objp->code_buy_l) && empty($objp->code_buy_p)) $code_buy_p_notset = 'color:red';
-		
+
 		// $objp->code_buy_p is now code of product/service
 		// $objp->code_buy_l is now default code of product/service
 					
@@ -362,23 +361,23 @@ if ($result) {
 
 		// Line id
 		print '<td>' . $objp->rowid . '</td>';
-		
+
 		// Ref Invoice
 		print '<td>' . $facturefourn_static->getNomUrl(1) . '</td>';
 
 		print '<td class="tdoverflowonsmartphone">';
 		print $objp->invoice_label;
 		print '</td>';
-		
+
 		print '<td align="center">' . dol_print_date($db->jdate($objp->datef), 'day') . '</td>';
-		
+
 		// Ref product
 		print '<td>';
 		if ($productfourn_static->id)
 			print $productfourn_static->getNomUrl(1);
 		if ($objp->product_label) print '<br>'.$objp->product_label;
         print '</td>';
-        
+
         // Description
 		print '<td>';
 		$text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->description));
@@ -409,9 +408,9 @@ if ($result) {
 
 		// Suggested accounting account
 		print '<td align="center">';
-		print $formventilation->select_account($objp->aarowid_suggest, 'codeventil'.$objp->rowid, 1, array(), 0, 0, 'maxwidth300 maxwidthonsmartphone', 'cachewithshowemptyone');
+		print $formaccounting->select_account($objp->aarowid_suggest, 'codeventil'.$objp->rowid, 1, array(), 0, 0, 'maxwidth300 maxwidthonsmartphone', 'cachewithshowemptyone');
 		print '</td>';
-		
+
 		// Colonne choix ligne a ventiler
 		print '<td align="center">';
 		print '<input type="checkbox" class="flat checkforselect" name="toselect[]" value="' . $objp->rowid . "_" . $i . '"' . ($objp->aarowid ? "checked" : "") . '/>';

+ 16 - 9
htdocs/adherents/class/adherent_type.class.php

@@ -1,8 +1,8 @@
 <?php
-/* Copyright (C) 2002      Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2004-2008 Laurent Destailleur  <eldy@users.sourceforge.net>
- * Copyright (C) 2009      Regis Houssin        <regis.houssin@capnetworks.com>
- * Copyright (C) 2016      Charlie Benke        <charlie@patas-monkey.com>
+/* Copyright (C) 2002		Rodolphe Quiedeville	<rodolphe@quiedeville.org>
+ * Copyright (C) 2004-2008	Laurent Destailleur		<eldy@users.sourceforge.net>
+ * Copyright (C) 2009-2017	Regis Houssin			<regis.houssin@capnetworks.com>
+ * Copyright (C) 2016		Charlie Benke			<charlie@patas-monkey.com>
  *
  * 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
@@ -36,7 +36,13 @@ class AdherentType extends CommonObject
 	public $table_element = 'adherent_type';
 	public $element = 'adherent_type';
 	public $picto = 'group';
-	
+
+	/**
+	 * @var string
+	 * @deprecated Use label
+	 * @see label
+	 */
+	public $libelle;
 	/** @var string Label */
 	public $label;
 	/**
@@ -81,12 +87,13 @@ class AdherentType extends CommonObject
         global $conf;
 
         $this->statut=(int) $this->statut;
+        $this->label=(!empty($this->libelle)?trim($this->libelle):trim($this->label));
 
         $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type (";
         $sql.= "libelle";
         $sql.= ", entity";
         $sql.= ") VALUES (";
-        $sql.= "'".$this->db->escape($this->libelle)."'";
+        $sql.= "'".$this->db->escape($this->label)."'";
         $sql.= ", ".$conf->entity;
         $sql.= ")";
 
@@ -117,12 +124,12 @@ class AdherentType extends CommonObject
 
     	$error=0;
 
-        $this->libelle=trim($this->libelle);
+    	$this->label=(!empty($this->libelle)?trim($this->libelle):trim($this->label));
 
         $sql = "UPDATE ".MAIN_DB_PREFIX."adherent_type ";
         $sql.= "SET ";
         $sql.= "statut = ".$this->statut.",";
-        $sql.= "libelle = '".$this->db->escape($this->libelle) ."',";
+        $sql.= "libelle = '".$this->db->escape($this->label) ."',";
         $sql.= "subscription = '".$this->db->escape($this->subscription)."',";
         $sql.= "note = '".$this->db->escape($this->note)."',";
         $sql.= "vote = '".$this->db->escape($this->vote)."',";
@@ -307,7 +314,7 @@ class AdherentType extends CommonObject
     {
     	return '';
     }
-    
+
     /**
      *     getMailOnValid
      *

+ 5 - 4
htdocs/adherents/class/api_members.class.php

@@ -106,7 +106,7 @@ class Members extends DolibarrApi
             $sql.= ' AND t.fk_adherent_type='.$typeid;
         }
         // Add sql filters
-        if ($sqlfilters) 
+        if ($sqlfilters)
         {
             if (! DolibarrApi::_checkFilters($sqlfilters))
             {
@@ -115,7 +115,7 @@ class Members extends DolibarrApi
 	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
             $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
         }
-        
+
         $sql.= $db->order($sortfield, $sortorder);
         if ($limit)    {
             if ($page < 0)
@@ -132,9 +132,10 @@ class Members extends DolibarrApi
         {
             $i=0;
             $num = $db->num_rows($result);
-            while ($i < min($limit, $num))
+            $min = min($num, ($limit <= 0 ? $num : $limit));
+            while ($i < $min)
             {
-                $obj = $db->fetch_object($result);
+            	$obj = $db->fetch_object($result);
                 $member = new Adherent($this->db);
                 if($member->fetch($obj->rowid)) {
                     $obj_ret[] = $this->_cleanObjectDatas($member);

+ 322 - 0
htdocs/adherents/class/api_memberstypes.class.php

@@ -0,0 +1,322 @@
+<?php
+/* Copyright (C) 2017	Regis Houssin	<regis.houssin@capnetworks.com>
+ *
+ * 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/>.
+ */
+
+use Luracast\Restler\RestException;
+
+require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
+
+/**
+ * API class for members types
+ *
+ * @access protected
+ * @class  DolibarrApiAccess {@requires user,external}
+ */
+class MembersTypes extends DolibarrApi
+{
+    /**
+     * @var array   $FIELDS     Mandatory fields, checked when create and update object
+     */
+    static $FIELDS = array(
+        'label'
+    );
+
+    /**
+     * Constructor
+     */
+    function __construct()
+    {
+        global $db, $conf;
+        $this->db = $db;
+    }
+
+    /**
+     * Get properties of a member type object
+     *
+     * Return an array with member type informations
+     *
+     * @param     int     $id ID of member type
+     * @return    array|mixed data without useless information
+     *
+     * @throws    RestException
+     */
+    function get($id)
+    {
+        if(! DolibarrApiAccess::$user->rights->adherent->lire) {
+            throw new RestException(401);
+        }
+
+        $membertype = new AdherentType($this->db);
+        $result = $membertype->fetch($id);
+        if( ! $result ) {
+            throw new RestException(404, 'member type not found');
+        }
+
+        if( ! DolibarrApi::_checkAccessToResource('member',$membertype->id,'adherent_type')) {
+            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+        }
+
+        return $this->_cleanObjectDatas($membertype);
+    }
+
+    /**
+     * List members types
+     *
+     * Get a list of members types
+     *
+     * @param string    $sortfield  Sort field
+     * @param string    $sortorder  Sort order
+     * @param int       $limit      Limit for list
+     * @param int       $page       Page number
+     * @param string    $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.libelle:like:'SO-%') and (t.subscription:=:'1')"
+     * @return array                Array of member type objects
+     *
+     * @throws RestException
+     */
+    function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $sqlfilters = '') {
+        global $db, $conf;
+
+        $obj_ret = array();
+
+        if(! DolibarrApiAccess::$user->rights->adherent->lire) {
+            throw new RestException(401);
+        }
+
+        $sql = "SELECT t.rowid";
+        $sql.= " FROM ".MAIN_DB_PREFIX."adherent_type as t";
+        $sql.= ' WHERE t.entity IN ('.getEntity('adherent', 1).')';
+
+        // Add sql filters
+        if ($sqlfilters)
+        {
+            if (! DolibarrApi::_checkFilters($sqlfilters))
+            {
+                throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
+            }
+	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
+            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
+        }
+
+        $sql.= $db->order($sortfield, $sortorder);
+        if ($limit)    {
+            if ($page < 0)
+            {
+                $page = 0;
+            }
+            $offset = $limit * $page;
+
+            $sql.= $db->plimit($limit + 1, $offset);
+        }
+
+        $result = $db->query($sql);
+        if ($result)
+        {
+            $i=0;
+            $num = $db->num_rows($result);
+            $min = min($num, ($limit <= 0 ? $num : $limit));
+            while ($i < $min)
+            {
+            	$obj = $db->fetch_object($result);
+                $membertype = new AdherentType($this->db);
+                if ($membertype->fetch($obj->rowid)) {
+                    $obj_ret[] = $this->_cleanObjectDatas($membertype);
+                }
+                $i++;
+            }
+        }
+        else {
+            throw new RestException(503, 'Error when retrieve member type list : '.$db->lasterror());
+        }
+        if ( ! count($obj_ret)) {
+            throw new RestException(404, 'No member type found');
+        }
+
+        return $obj_ret;
+    }
+
+    /**
+     * Create member type object
+     *
+     * @param array $request_data   Request data
+     * @return int  ID of member type
+     */
+    function post($request_data = null)
+    {
+        if (! DolibarrApiAccess::$user->rights->adherent->configurer) {
+            throw new RestException(401);
+        }
+        // Check mandatory fields
+        $result = $this->_validate($request_data);
+
+        $membertype = new AdherentType($this->db);
+        foreach($request_data as $field => $value) {
+            $membertype->$field = $value;
+        }
+        if ($membertype->create(DolibarrApiAccess::$user) < 0) {
+            throw new RestException(500, 'Error creating member type', array_merge(array($membertype->error), $membertype->errors));
+        }
+        return $membertype->id;
+    }
+
+    /**
+     * Update member type
+     *
+     * @param int   $id             ID of member type to update
+     * @param array $request_data   Datas
+     * @return int
+     */
+    function put($id, $request_data = null)
+    {
+        if (! DolibarrApiAccess::$user->rights->adherent->configurer) {
+            throw new RestException(401);
+        }
+
+        $membertype = new AdherentType($this->db);
+        $result = $membertype->fetch($id);
+        if( ! $result ) {
+            throw new RestException(404, 'member type not found');
+        }
+
+        if( ! DolibarrApi::_checkAccessToResource('member',$membertype->id,'adherent_type')) {
+            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+        }
+
+        foreach($request_data as $field => $value) {
+            if ($field == 'id') continue;
+            // Process the status separately because it must be updated using
+            // the validate() and resiliate() methods of the class AdherentType.
+            $membertype->$field = $value;
+        }
+
+        // If there is no error, update() returns the number of affected rows
+        // so if the update is a no op, the return value is zero.
+        if ($membertype->update(DolibarrApiAccess::$user) >= 0)
+            return $this->get($id);
+
+        return false;
+    }
+
+    /**
+     * Delete member type
+     *
+     * @param int $id   member type ID
+     * @return array
+     */
+    function delete($id)
+    {
+        if (! DolibarrApiAccess::$user->rights->adherent->configurer) {
+            throw new RestException(401);
+        }
+        $membertype = new AdherentType($this->db);
+        $result = $membertype->fetch($id);
+        if( ! $result ) {
+            throw new RestException(404, 'member type not found');
+        }
+
+        if ( ! DolibarrApi::_checkAccessToResource('member',$membertype->id,'adherent_type')) {
+            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+        }
+
+        if (! $membertype->delete($membertype->id)) {
+            throw new RestException(401,'error when deleting member type');
+        }
+
+        return array(
+            'success' => array(
+                'code' => 200,
+                'message' => 'member type deleted'
+            )
+        );
+    }
+
+    /**
+     * Validate fields before creating an object
+     *
+     * @param array|null    $data   Data to validate
+     * @return array
+     *
+     * @throws RestException
+     */
+    function _validate($data)
+    {
+        $membertype = array();
+        foreach (MembersTypes::$FIELDS as $field) {
+            if (!isset($data[$field]))
+                throw new RestException(400, "$field field missing");
+            $membertype[$field] = $data[$field];
+        }
+        return $membertype;
+    }
+
+    /**
+     * Clean sensible object datas
+     *
+     * @param   object  $object    Object to clean
+     * @return    array    Array of cleaned object properties
+     */
+    function _cleanObjectDatas($object) {
+
+        $object = parent::_cleanObjectDatas($object);
+
+        unset($object->cotisation);
+        unset($object->libelle);
+
+        unset($object->import_key);
+        unset($object->array_options);
+        unset($object->linkedObjectsIds);
+        unset($object->context);
+        unset($object->canvas);
+        unset($object->fk_project);
+        unset($object->contact);
+        unset($object->contact_id);
+        unset($object->thirdparty);
+        unset($object->user);
+        unset($object->origin);
+        unset($object->origin_id);
+        unset($object->ref_ext);
+        unset($object->country);
+        unset($object->country_id);
+        unset($object->country_code);
+        unset($object->barcode_type);
+        unset($object->barcode_type_code);
+        unset($object->barcode_type_label);
+        unset($object->barcode_type_coder);
+        unset($object->mode_reglement_id);
+        unset($object->cond_reglement_id);
+        unset($object->cond_reglement);
+        unset($object->fk_delivery_address);
+        unset($object->shipping_method_id);
+        unset($object->modelpdf);
+        unset($object->fk_account);
+        unset($object->note_public);
+        unset($object->note_private);
+        unset($object->fk_incoterms);
+        unset($object->libelle_incoterms);
+        unset($object->location_incoterms);
+        unset($object->name);
+        unset($object->lastname);
+        unset($object->firstname);
+        unset($object->civility_id);
+        unset($object->total_ht);
+        unset($object->total_tva);
+        unset($object->total_localtax1);
+        unset($object->total_localtax2);
+        unset($object->total_ttc);
+
+        return $object;
+    }
+
+}

+ 34 - 34
htdocs/adherents/type.php

@@ -1,10 +1,10 @@
 <?php
-/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2003      Jean-Louis Bergamo   <jlb@j1b.org>
- * Copyright (C) 2004-2011 Laurent Destailleur  <eldy@users.sourceforge.net>
- * Copyright (C) 2005-2012 Regis Houssin        <regis.houssin@capnetworks.com>
- * Copyright (C) 2013      Florian Henry        <florian.henry@open-concept.pro>
- * Copyright (C) 2015      Alexandre Spangaro   <aspangaro.dolibarr@gmail.com>
+/* Copyright (C) 2001-2002	Rodolphe Quiedeville	<rodolphe@quiedeville.org>
+ * Copyright (C) 2003		Jean-Louis Bergamo		<jlb@j1b.org>
+ * Copyright (C) 2004-2011	Laurent Destailleur		<eldy@users.sourceforge.net>
+ * Copyright (C) 2005-2017	Regis Houssin			<regis.houssin@capnetworks.com>
+ * Copyright (C) 2013		Florian Henry			<florian.henry@open-concept.pro>
+ * Copyright (C) 2015		Alexandre Spangaro		<aspangaro.dolibarr@gmail.com>
  *
  * 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
@@ -55,7 +55,7 @@ $pagenext = $page + 1;
 if (! $sortorder) {  $sortorder="DESC"; }
 if (! $sortfield) {  $sortfield="d.lastname"; }
 
-$label=GETPOST("libelle","alpha");
+$label=GETPOST("label","alpha");
 $subscription=GETPOST("subscription","int");
 $vote=GETPOST("vote","int");
 $comment=GETPOST("comment");
@@ -93,17 +93,17 @@ if ($action == 'add' && $user->rights->adherent->configurer)
 	{
 		$object = new AdherentType($db);
 
-		$object->libelle        = trim($label);
-		$object->subscription   = (int) trim($subscription);
-		$object->note           = trim($comment);
-		$object->mail_valid     = (boolean) trim($mail_valid);
-		$object->vote           = (boolean) trim($vote);
+		$object->label			= trim($label);
+		$object->subscription	= (int) trim($subscription);
+		$object->note			= trim($comment);
+		$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);
 		if ($ret < 0) $error++;
 
-		if ($object->libelle)
+		if ($object->label)
 		{
 			$id=$object->create($user);
 			if ($id > 0)
@@ -131,7 +131,7 @@ if ($action == 'update' && $user->rights->adherent->configurer)
 	{
 		$object = new AdherentType($db);
 		$object->id             = $rowid;
-		$object->libelle        = trim($label);
+		$object->label        = trim($label);
 		$object->subscription   = (int) trim($subscription);
 		$object->note           = trim($comment);
 		$object->mail_valid     = (boolean) trim($mail_valid);
@@ -171,7 +171,7 @@ if (! $rowid && $action != 'create' && $action != 'edit')
 {
 	//dol_fiche_head('');
 
-	$sql = "SELECT d.rowid, d.libelle, d.subscription, d.vote";
+	$sql = "SELECT d.rowid, d.libelle as label, d.subscription, d.vote";
 	$sql.= " FROM ".MAIN_DB_PREFIX."adherent_type as d";
 	$sql.= " WHERE d.entity IN (".getEntity().")";
 
@@ -180,11 +180,11 @@ if (! $rowid && $action != 'create' && $action != 'edit')
 	{
 		$num = $db->num_rows($result);
 		$nbtotalofrecords = $num;
-		
+
 		$i = 0;
 
 		$param = '';
-		
+
 		print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
 		if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
 		print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@@ -193,14 +193,14 @@ if (! $rowid && $action != 'create' && $action != 'edit')
 		print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
         print '<input type="hidden" name="page" value="'.$page.'">';
 		print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
-		
+
 	    print_barre_liste($langs->trans("MembersTypes"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_generic.png', 0, '', '', $limit);
-	   
+
 		$moreforfilter = '';
-		
+
 		print '<div class="div-table-responsive">';
 		print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
-		
+
 		print '<tr class="liste_titre">';
 		print '<th>'.$langs->trans("Ref").'</th>';
 		print '<th>'.$langs->trans("Label").'</th>';
@@ -214,7 +214,7 @@ if (! $rowid && $action != 'create' && $action != 'edit')
 			$objp = $db->fetch_object($result);
 			print '<tr class="oddeven">';
 			print '<td><a href="'.$_SERVER["PHP_SELF"].'?rowid='.$objp->rowid.'">'.img_object($langs->trans("ShowType"),'group').' '.$objp->rowid.'</a></td>';
-			print '<td>'.dol_escape_htmltag($objp->libelle).'</td>';
+			print '<td>'.dol_escape_htmltag($objp->label).'</td>';
 			print '<td align="center">'.yn($objp->subscription).'</td>';
 			print '<td align="center">'.yn($objp->vote).'</td>';
 			if ($user->rights->adherent->configurer)
@@ -226,7 +226,7 @@ if (! $rowid && $action != 'create' && $action != 'edit')
 		}
 		print "</table>";
 		print '</div>';
-		
+
 		print '</form>';
 	}
 	else
@@ -256,7 +256,7 @@ if ($action == 'create')
 	print '<table class="border" width="100%">';
 	print '<tbody>';
 
-	print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td><input type="text" name="libelle" size="40"></td></tr>';
+	print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td><input type="text" name="label" size="40"></td></tr>';
 
 	print '<tr><td>'.$langs->trans("SubscriptionRequired").'</td><td>';
 	print $form->selectyesno("subscription",1,1);
@@ -316,10 +316,10 @@ if ($rowid > 0)
 		$linkback = '<a href="'.DOL_URL_ROOT.'/adherents/type.php">'.$langs->trans("BackToList").'</a>';
 
 		dol_banner_tab($object, 'rowid', $linkback);
-		
+
 		print '<div class="fichecenter">';
 		print '<div class="underbanner clearboth"></div>';
-		
+
 		print '<table class="border" width="100%">';
 
 		print '<tr><td class="titlefield">'.$langs->trans("SubscriptionRequired").'</td><td>';
@@ -347,7 +347,7 @@ if ($rowid > 0)
 
 		print '</table>';
         print '</div>';
-        
+
 		dol_fiche_end();
 
 
@@ -460,7 +460,7 @@ if ($rowid > 0)
 		    {
 				$membertype=new AdherentType($db);
 		        $result=$membertype->fetch($type);
-				$titre.=" (".$membertype->libelle.")";
+				$titre.=" (".$membertype->label.")";
 		    }
 
 		    $param="&rowid=".$rowid;
@@ -478,12 +478,12 @@ if ($rowid > 0)
 
 			print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
 			print '<input class="flat" type="hidden" name="rowid" value="'.$rowid.'" size="12"></td>';
-				
+
 			print '<br>';
             print_barre_liste('',$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords);
-		    
+
             $moreforfilter = '';
-            
+
             print '<div class="div-table-responsive">';
             print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
 
@@ -548,7 +548,7 @@ if ($rowid > 0)
 		        // Type
 		        /*print '<td class="nowrap">';
 		        $membertypestatic->id=$objp->type_id;
-		        $membertypestatic->libelle=$objp->type;
+		        $membertypestatic->label=$objp->type;
 		        print $membertypestatic->getNomUrl(1,12);
 		        print '</td>';
 				*/
@@ -613,7 +613,7 @@ if ($rowid > 0)
 		    print "</table>\n";
             print '</div>';
             print '</form>';
-            
+
 			if ($num > $conf->liste_limit)
 			{
 			    print_barre_liste('',$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords,'');
@@ -652,7 +652,7 @@ if ($rowid > 0)
 
 		print '<tr><td width="15%">'.$langs->trans("Ref").'</td><td>'.$object->id.'</td></tr>';
 
-		print '<tr><td>'.$langs->trans("Label").'</td><td><input type="text" name="libelle" size="40" value="'.dol_escape_htmltag($object->libelle).'"></td></tr>';
+		print '<tr><td>'.$langs->trans("Label").'</td><td><input type="text" name="label" size="40" value="'.dol_escape_htmltag($object->label).'"></td></tr>';
 
 		print '<tr><td>'.$langs->trans("SubscriptionRequired").'</td><td>';
 		print $form->selectyesno("subscription",$object->subscription,1);

+ 3 - 3
htdocs/admin/dict.php

@@ -39,7 +39,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
 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';
+if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 
 $langs->load("errors");
 $langs->load("admin");
@@ -1662,7 +1662,7 @@ function fieldList($fieldlist, $obj='', $tabname='', $context='')
 
 	$formadmin = new FormAdmin($db);
 	$formcompany = new FormCompany($db);
-	if (! empty($conf->accounting->enabled)) $formaccountancy = new FormVentilation($db);
+	if (! empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db);
 
 	foreach ($fieldlist as $field => $value)
 	{
@@ -1811,7 +1811,7 @@ function fieldList($fieldlist, $obj='', $tabname='', $context='')
 			{
 			    $fieldname = $fieldlist[$field];
 				$accountancy_account = (! empty($obj->$fieldname) ? $obj->$fieldname : 0);
-				print $formaccountancy->select_account($accountancy_account, $fieldlist[$field], 1, '', 1, 1, 'maxwidth200 maxwidthonsmartphone');
+				print $formaccounting->select_account($accountancy_account, $fieldlist[$field], 1, '', 1, 1, 'maxwidth200 maxwidthonsmartphone');
 			}
 			else
 			{

+ 4 - 4
htdocs/admin/loan.php

@@ -1,5 +1,5 @@
 <?php
-/* Copyright (C) 2014-2016	Alexandre Spangaro	<aspangaro.dolibarr@gmail.com>
+/* Copyright (C) 2014-2017  Alexandre Spangaro	<aspangaro.dolibarr@gmail.com>
  *
  * 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
@@ -26,7 +26,7 @@ require '../main.inc.php';
 	
 // Class
 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
-if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
+if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 
 $langs->load("admin");
 $langs->load("loan");
@@ -77,7 +77,7 @@ if ($action == 'update')
 llxHeader();
 
 $form = new Form($db);
-if (! empty($conf->accounting->enabled)) $formaccountancy = New FormVentilation($db);
+if (! empty($conf->accounting->enabled)) $formaccounting = New FormAccounting($db);
 
 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
 print load_fiche_titre($langs->trans('ConfigLoan'),$linkback,'title_setup');
@@ -106,7 +106,7 @@ foreach ($list as $key)
 	print '<td>';
 	if (! empty($conf->accounting->enabled))
 	{
-		print $formaccountancy->select_account($conf->global->$key, $key, 1, '', 1, 1);
+		print $formaccounting->select_account($conf->global->$key, $key, 1, '', 1, 1);
 	}
 	else
 	{

+ 2 - 2
htdocs/admin/mails_templates.php

@@ -39,7 +39,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
 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';
+if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 
 $langs->load("errors");
 $langs->load("admin");
@@ -841,7 +841,7 @@ function fieldList($fieldlist, $obj='', $tabname='', $context='')
 
 	$formadmin = new FormAdmin($db);
 	$formcompany = new FormCompany($db);
-	if (! empty($conf->accounting->enabled)) $formaccountancy = new FormVentilation($db);
+	if (! empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db);
 
 	foreach ($fieldlist as $field => $value)
 	{

+ 3 - 3
htdocs/admin/salaries.php

@@ -26,7 +26,7 @@ require '../main.inc.php';
 
 // Class
 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
-if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
+if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 
 $langs->load("admin");
 $langs->load("salaries");
@@ -76,7 +76,7 @@ if ($action == 'update')
 llxHeader('',$langs->trans('SalariesSetup'));
 
 $form = new Form($db);
-if (! empty($conf->accounting->enabled)) $formaccountancy = New FormVentilation($db);
+if (! empty($conf->accounting->enabled)) $formaccounting = New FormAccounting($db);
 
 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
 print load_fiche_titre($langs->trans('SalariesSetup'),$linkback,'title_setup');
@@ -109,7 +109,7 @@ foreach ($list as $key)
 	print '<td>';
 	if (! empty($conf->accounting->enabled))
 	{
-		print $formaccountancy->select_account($conf->global->$key, $key, 1, '', 1, 1);
+		print $formaccounting->select_account($conf->global->$key, $key, 1, '', 1, 1);
 	}
 	else
 	{

+ 3 - 3
htdocs/admin/taxes.php

@@ -27,7 +27,7 @@
 
 require '../main.inc.php';
 require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
-if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
+if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 
 $langs->load('admin');
 
@@ -113,7 +113,7 @@ if ($action == 'update') {
 
 llxHeader();
 $form=new Form($db);
-if (! empty($conf->accounting->enabled)) $formaccountancy = New FormVentilation($db);
+if (! empty($conf->accounting->enabled)) $formaccounting = New FormAccounting($db);
 
 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
 print load_fiche_titre($langs->trans('TaxSetup'),$linkback,'title_setup');
@@ -216,7 +216,7 @@ foreach ($list as $key)
 	print '<td>';
 	if (! empty($conf->accounting->enabled))
 	{
-		print $formaccountancy->select_account($conf->global->$key, $key, 1, '', 1, 1);
+		print $formaccounting->select_account($conf->global->$key, $key, 1, '', 1, 1);
 	}
 	else
 	{

+ 100 - 0
htdocs/api/class/api_dictionaryevents.class.php

@@ -0,0 +1,100 @@
+<?php
+/* Copyright (C) 2017	Regis Houssin	<regis.houssin@capnetworks.com>
+ *
+ * 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/>.
+ */
+
+use Luracast\Restler\RestException;
+
+require_once DOL_DOCUMENT_ROOT.'/main.inc.php';
+
+/**
+ * API class for events type (content of the actioncomm dictionary)
+ *
+ * @access protected
+ * @class DolibarrApiAccess {@requires user,external}
+ */
+class DictionaryEvents extends DolibarrApi
+{
+    /**
+     * Constructor
+     */
+    function __construct()
+    {
+        global $db;
+        $this->db = $db;
+    }
+
+    /**
+     * Get the list of events types.
+     *
+     * @param string    $sortfield  Sort field
+     * @param string    $sortorder  Sort order
+     * @param int       $limit      Number of items per page
+     * @param int       $page       Page number (starting from zero)
+     * @param string    $type       To filter on type of event
+     * @param string    $module     To filter on module events
+     * @param string    $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
+     * @return List of events types
+     *
+     * @throws RestException
+     */
+    function index($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $type = '', $module = '', $sqlfilters = '')
+    {
+        $list = array();
+
+        $sql = "SELECT id, code, type, libelle as label, module";
+        $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as t";
+        $sql.= " WHERE t.active = 1";
+        if ($type) $sql.=" AND t.type LIKE '%" . $this->db->escape($type) . "%'";
+        if ($module)    $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'";
+        // Add sql filters
+        if ($sqlfilters)
+        {
+            if (! DolibarrApi::_checkFilters($sqlfilters))
+            {
+                throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
+            }
+	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
+            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
+        }
+
+
+        $sql.= $this->db->order($sortfield, $sortorder);
+
+        if ($limit) {
+            if ($page < 0) {
+                $page = 0;
+            }
+            $offset = $limit * $page;
+
+            $sql .= $this->db->plimit($limit, $offset);
+        }
+
+        $result = $this->db->query($sql);
+
+        if ($result) {
+            $num = $this->db->num_rows($result);
+            $min = min($num, ($limit <= 0 ? $num : $limit));
+            for ($i = 0; $i < $min; $i++) {
+                $list[] = $this->db->fetch_object($result);
+            }
+        } else {
+            throw new RestException(503, 'Error when retrieving list of events types : '.$this->db->lasterror());
+        }
+
+        return $list;
+    }
+
+}

+ 3 - 3
htdocs/api/index.php

@@ -1,6 +1,7 @@
 <?php
-/* Copyright (C) 2015   Jean-François Ferry     <jfefe@aternatik.fr>
+/* Copyright (C) 2015	Jean-François Ferry		<jfefe@aternatik.fr>
  * Copyright (C) 2016	Laurent Destailleur		<eldy@users.sourceforge.net>
+ * Copyright (C) 2017	Regis Houssin			<regis.houssin@capnetworks.com>
  *
  * 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
@@ -143,10 +144,9 @@ foreach ($modulesdir as $dir)
                      *
                      * Search files named api_<object>.class.php into /htdocs/<module>/class directory
                      *
-                     * @todo : take care of externals module!
                      * @todo : use getElementProperties() function ?
                      */
-                    $dir_part = DOL_DOCUMENT_ROOT.'/'.$moduledirforclass.'/class/';
+                    $dir_part = dol_buildpath('/'.$moduledirforclass.'/class/');
 
                     $handle_part=@opendir(dol_osencode($dir_part));
                     if (is_resource($handle_part))

+ 9 - 24
htdocs/bookmarks/bookmarks.lib.php

@@ -41,29 +41,15 @@ function printBookmarksList($aDb, $aLangs)
 	$langs->load("bookmarks");
 
 	$url= $_SERVER["PHP_SELF"].(! empty($_SERVER["QUERY_STRING"])?'?'.$_SERVER["QUERY_STRING"]:'');
-    // TODO Add post param to $url
     
 	$ret = '';
 	
 	// Menu bookmark
-	/*
-	$ret.= '<div class="menu_titre">';
-	$ret.= '<table class="nobordernopadding" width="100%" summary="bookmarkstable"><tr><td>';
-	$ret.= '<a class="vmenu" href="'.DOL_URL_ROOT.'/bookmarks/list.php">'.$langs->trans('Bookmarks').'</a>';
-	$ret.= '</td><td align="right">';
-	if ($user->rights->bookmark->creer)
-	{
-		$ret.= '<a class="vsmenu addbookmarkpicto" href="'.DOL_URL_ROOT.'/bookmarks/card.php?action=create&amp;urlsource='.urlencode($url).'&amp;url='.urlencode($url).'">';
-		$ret.=img_object($langs->trans('AddThisPageToBookmarks'),'bookmark');
-		$ret.= '</a>';
-	}
-	$ret.= '</td></tr></table>';
-	$ret.= '</div>';
-    */
 	$ret.= '<div class="menu_top"></div>'."\n";
 
-	$ret.= '<!-- form with POST method by default --><form id="actionbookmark" name="actionbookmark" method="POST" action="">';
-	$ret.= '<select name="bookmark" id="boxbookmark" class="flat boxcombo vmenusearchselectcombo">';
+	$ret.= '<!-- form with POST method by default, will be replaced with GET for external link by js -->'."\n";
+	$ret.= '<form id="actionbookmark" name="actionbookmark" method="POST" action="">';
+	$ret.= '<select name="bookmark" id="boxbookmark" class="flat boxcombo vmenusearchselectcombo" alt="Bookmarks">';
 	$ret.= '<option hidden value="listbookmarks" class="optiongrey" selected rel="'.DOL_URL_ROOT.'/bookmarks/list.php">'.$langs->trans('Bookmarks').'</option>';
     $ret.= '<option value="listbookmark" class="optionblue" rel="'.dol_escape_htmltag(DOL_URL_ROOT.'/bookmarks/list.php').'">'.dol_escape_htmltag($user->rights->bookmark->creer ? $langs->trans('EditBookmarks') : $langs->trans('ListOfBookmarks')).'...</option>';
 	// Url to go on create new bookmark page
@@ -77,19 +63,18 @@ function printBookmarksList($aDb, $aLangs)
 	{
 		$sql = "SELECT rowid, title, url, target FROM ".MAIN_DB_PREFIX."bookmark";
 		$sql.= " WHERE (fk_user = ".$user->id." OR fk_user is NULL OR fk_user = 0)";
-        $sql.= " AND entity = ".$conf->entity;
+        $sql.= " AND entity IN (".getEntity('bookmarks',1).")";
 		$sql.= " ORDER BY position";
 		if ($resql = $db->query($sql) )
 		{
 			$i=0;
 			while ($i < $conf->global->BOOKMARKS_SHOW_IN_MENU && $obj = $db->fetch_object($resql))
 			{
-				//$ret.='<div class="menu_contenu">';
-			    $ret.='<option name="bookmark'.$obj->rowid.'" value="'.$obj->rowid.'" '.($obj->target == 1?' target="_blank"':'').' rel="'.dol_escape_htmltag($obj->url).'">'.img_picto('','object_bookmark').' '.$obj->title.'</option>';
-				/*$ret.='<a class="vsmenu" title="'.$obj->title.'" href="'.$obj->url.'"'.($obj->target == 1?' target="_blank"':'').'>';
-				if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) $ret.=' '.img_object('','bookmark').' ';
-				$ret.= dol_trunc($obj->title, 20).'</a><br>';*/
-				//$ret.='</div>';
+			    $ret.='<option name="bookmark'.$obj->rowid.'" value="'.$obj->rowid.'" '.($obj->target == 1?' target="_blank"':'').' rel="'.dol_escape_htmltag($obj->url).'">';
+			    //$ret.='<span class="fa fa-print">aa</span>';
+			    $ret.=img_picto('','object_bookmark').' ';
+			    $ret.=$obj->title;
+			    $ret.='</option>';
 				$i++;
 			}
 		}

+ 45 - 45
htdocs/comm/action/class/api_agendaevents.class.php

@@ -1,7 +1,7 @@
 <?php
 /* Copyright (C) 2015   Jean-François Ferry     <jfefe@aternatik.fr>
  * Copyright (C) 2016   Laurent Destailleur     <eldy@users.sourceforge.net>
- * 
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 3 of the License, or
@@ -23,14 +23,14 @@
 /**
  * API class for Agenda Events
  *
- * @access protected 
+ * @access protected
  * @class  DolibarrApiAccess {@requires user,external}
  */
 class AgendaEvents extends DolibarrApi
 {
 
     /**
-     * @var array   $FIELDS     Mandatory fields, checked when create and update object 
+     * @var array   $FIELDS     Mandatory fields, checked when create and update object
      */
     static $FIELDS = array(
     );
@@ -40,7 +40,7 @@ class AgendaEvents extends DolibarrApi
      */
     public $actioncomm;
 
-    
+
     /**
      * Constructor
      */
@@ -55,61 +55,61 @@ class AgendaEvents extends DolibarrApi
      * Get properties of a Agenda Events object
      *
      * Return an array with Agenda Events informations
-     * 
+     *
      * @param       int         $id         ID of Agenda Events
      * @return 	    array|mixed             Data without useless information
 	 *
      * @throws 	RestException
      */
     function get($id)
-    {		
+    {
         if(! DolibarrApiAccess::$user->rights->agenda->myactions->read) {
             throw new RestException(401, "Insuffisant rights to read an event");
         }
-        
+
         $result = $this->actioncomm->fetch($id);
         if( ! $result ) {
             throw new RestException(404, 'Agenda Events not found');
         }
-		
+
         if(! DolibarrApiAccess::$user->rights->agenda->allactions->read && $this->actioncomm->ownerid != DolibarrApiAccess::$user->id) {
             throw new RestException(401, "Insuffisant rights to read event for owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id);
         }
-        
+
 		if( ! DolibarrApi::_checkAccessToResource('agenda',$this->actioncomm->id)) {
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
 		}
-        
+
         $this->actioncomm->fetchObjectLinked();
 		return $this->_cleanObjectDatas($this->actioncomm);
     }
 
     /**
      * List Agenda Events
-     * 
+     *
      * Get a list of Agenda Events
-     * 
+     *
      * @param string	$sortfield	Sort field
      * @param string	$sortorder	Sort order
      * @param int		$limit		Limit for list
      * @param int		$page		Page number
      * @param string   	$user_ids   User ids filter field (owners of event). Example: '1' or '1,2,3'          {@pattern /^[0-9,]*$/i}
-     * @param string    $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.label:like:'%dol%') and (t.date_creation:<:'20160101')"
+     * @param string    $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.label:like:'%dol%') and (t.datec:<:'20160101')"
      * @return  array               Array of Agenda Events objects
      */
-    function index($sortfield = "t.id", $sortorder = 'ASC', $limit = 0, $page = 0, $user_ids = 0, $sqlfilters = '') {
+    function index($sortfield = "t.id", $sortorder = 'ASC', $limit = 100, $page = 0, $user_ids = 0, $sqlfilters = '') {
         global $db, $conf;
-        
+
         $obj_ret = array();
 
         // case of external user
         $socid = 0;
-        if (! empty(DolibarrApiAccess::$user->societe_id)) $socid = DolibarrApiAccess::$user->societe_id;
-        
+        if (! empty(DolibarrApiAccess::$user->socid)) $socid = DolibarrApiAccess::$user->socid;
+
         // If the internal user must only see his customers, force searching by him
         $search_sale = 0;
         if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
-        
+
         $sql = "SELECT t.id as rowid";
         $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as t";
         $sql.= ' WHERE t.entity IN ('.getEntity('agenda', 1).')';
@@ -121,7 +121,7 @@ class AgendaEvents extends DolibarrApi
             $sql .= " AND sc.fk_user = ".$search_sale;
         }
         // Add sql filters
-        if ($sqlfilters) 
+        if ($sqlfilters)
         {
             if (! DolibarrApi::_checkFilters($sqlfilters))
             {
@@ -130,7 +130,7 @@ class AgendaEvents extends DolibarrApi
 	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
             $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
         }
-        
+
         $sql.= $db->order($sortfield, $sortorder);
         if ($limit)	{
             if ($page < 0)
@@ -143,7 +143,7 @@ class AgendaEvents extends DolibarrApi
         }
 
         $result = $db->query($sql);
-        
+
         if ($result)
         {
             $num = $db->num_rows($result);
@@ -181,7 +181,7 @@ class AgendaEvents extends DolibarrApi
       if(! DolibarrApiAccess::$user->rights->agenda->allactions->create && DolibarrApiAccess::$user->id != $request_data['userownerid']) {
 		      throw new RestException(401, "Insuffisant rights to create an Agenda Event for owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id);
 		  }
-		  
+
         // Check mandatory fields
         $result = $this->_validate($request_data);
 
@@ -198,18 +198,18 @@ class AgendaEvents extends DolibarrApi
         if ($this->actioncomm->create(DolibarrApiAccess::$user) < 0) {
             throw new RestException(500, "Error creating event", array_merge(array($this->actioncomm->error), $this->actioncomm->errors));
         }
-        
+
         return $this->actioncomm->id;
     }
 
-    
+
     /**
      * Update Agenda Event general fields (won't touch lines of expensereport)
      *
      * @param int   $id             Id of Agenda Event to update
-     * @param array $request_data   Datas   
-     * 
-     * @return int 
+     * @param array $request_data   Datas
+     *
+     * @return int
      */
     /*
     function put($id, $request_data = NULL) {
@@ -219,12 +219,12 @@ class AgendaEvents extends DolibarrApi
       if(! DolibarrApiAccess::$user->rights->agenda->allactions->create && DolibarrApiAccess::$user->id != $request_data['userownerid']) {
 		      throw new RestException(401, "Insuffisant rights to create an Agenda Event for owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id);
 		  }
-        
+
         $result = $this->expensereport->fetch($id);
         if( ! $result ) {
             throw new RestException(404, 'expensereport not found');
         }
-		
+
 		if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) {
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
 		}
@@ -232,19 +232,19 @@ class AgendaEvents extends DolibarrApi
             if ($field == 'id') continue;
             $this->expensereport->$field = $value;
         }
-        
+
         if($this->expensereport->update($id, DolibarrApiAccess::$user,1,'','','update'))
             return $this->get($id);
-        
+
         return false;
     }
     */
-        
+
     /**
      * Delete Agenda Event
      *
      * @param   int     $id         Agenda Event ID
-     * 
+     *
      * @return  array
      */
     function delete($id)
@@ -252,49 +252,49 @@ class AgendaEvents extends DolibarrApi
         if(! DolibarrApiAccess::$user->rights->agenda->myactions->delete) {
 			  throw new RestException(401, "Insuffisant rights to delete your Agenda Event");
 		}
-        
+
 		$result = $this->actioncomm->fetch($id);
-		  
+
         if(! DolibarrApiAccess::$user->rights->agenda->allactions->delete && DolibarrApiAccess::$user->id != $this->actioncomm->userownerid) {
 		      throw new RestException(401, "Insuffisant rights to delete an Agenda Event of owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id);
 		}
-		
+
 		if( ! $result ) {
             throw new RestException(404, 'Agenda Event not found');
         }
-		
+
 		if( ! DolibarrApi::_checkAccessToResource('actioncomm',$this->actioncomm->id)) {
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
 		}
-        
+
         if( ! $this->actioncomm->delete(DolibarrApiAccess::$user)) {
             throw new RestException(500, 'Error when delete Agenda Event : '.$this->actioncomm->error);
         }
-        
+
         return array(
             'success' => array(
                 'code' => 200,
                 'message' => 'Agenda Event deleted'
             )
         );
-        
+
     }
-    
+
     /**
      * Validate fields before create or update object
-     * 
+     *
      * @param   array           $data   Array with data to verify
-     * @return  array           
+     * @return  array
      * @throws  RestException
      */
     function _validate($data)
     {
         $event = array();
-        foreach (Events::$FIELDS as $field) {
+        foreach (AgendaEvents::$FIELDS as $field) {
             if (!isset($data[$field]))
                 throw new RestException(400, "$field field missing");
             $event[$field] = $data[$field];
-            
+
         }
         return $event;
     }

+ 14 - 17
htdocs/compta/bank/card.php

@@ -35,7 +35,6 @@ require_once DOL_DOCUMENT_ROOT . '/core/class/html.formbank.class.php';
 require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
 require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
 if (! empty($conf->categorie->enabled)) require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
-if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
 if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
 if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
@@ -281,8 +280,7 @@ if ($action == 'confirm_delete' && $_POST["confirm"] == "yes" && $user->rights->
 $form = new Form($db);
 $formbank = new FormBank($db);
 $formcompany = new FormCompany($db);
-if (! empty($conf->accounting->enabled)) $formaccountancy = New FormVentilation($db);
-if (! empty($conf->accounting->enabled)) $formaccountancy2 = New FormAccounting($db);
+if (! empty($conf->accounting->enabled)) $formaccounting = New FormAccounting($db);
 
 $countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
 
@@ -511,7 +509,7 @@ if ($action == 'create')
 	{
 		print '<tr><td class="'.$fieldrequired.'titlefieldcreate">'.$langs->trans("AccountancyCode").'</td>';
 		print '<td>';
-		print $formaccountancy->select_account($object->account_number, 'account_number', 1, '', 1, 1);
+		print $formaccounting->select_account($object->account_number, 'account_number', 1, '', 1, 1);
 		print '</td></tr>';
 	}
 	else
@@ -525,7 +523,7 @@ if ($action == 'create')
 	{
 		print '<tr><td>'.$langs->trans("AccountancyJournal").'</td>';
 	    print '<td>';
-		print $formaccountancy2->select_journal($object->fk_accountancy_journal, 'fk_accountancy_journal', 4, 1, '', 0, 0);
+		print $formaccounting->select_journal($object->fk_accountancy_journal, 'fk_accountancy_journal', 4, 1, '', 0, 0);
 		print '</td></tr>';
 	}
 
@@ -957,43 +955,42 @@ else
 
 
 		//print '<div class="underbanner clearboth"></div>';
-		
+
 		print '<table class="border" width="100%">';
-		
+
 		// Accountancy code
 		$tdextra = ' class="titlefieldcreate"';
-		
+
 		if (!empty($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED)) {
 		    $tdextra = ' class="fieldrequired titlefieldcreate"';
 		}
-		
+
 		print '<tr class="liste_titre_add"><td'.$tdextra.'>'.$langs->trans("AccountancyCode").'</td>';
 		print '<td>';
 		if (!empty($conf->accounting->enabled)) {
-		    print $formaccountancy->select_account($object->account_number, 'account_number', 1, '', 1, 1);
+		    print $formaccounting->select_account($object->account_number, 'account_number', 1, '', 1, 1);
 		} else {
 		    print '<input type="text" name="account_number" value="'.(GETPOST("account_number") ? GETPOST("account_number") : $object->account_number).'">';
 		}
 		print '</td></tr>';
-		
+
 		// Accountancy journal
 		if (! empty($conf->accounting->enabled))
 		{
 			print '<tr><td>'.$langs->trans("AccountancyJournal").'</td>';
 			print '<td>';
-			print $formaccountancy2->select_journal($object->fk_accountancy_journal, 'fk_accountancy_journal', 4, 1, '', 0, 0);
+			print $formaccounting->select_journal($object->fk_accountancy_journal, 'fk_accountancy_journal', 4, 1, '', 0, 0);
 			print '</td></tr>';
 		}
-		
+
 		print '</table>';
-		
-		
+
 		if ($_POST["type"] == Account::TYPE_SAVINGS || $_POST["type"] == Account::TYPE_CURRENT)
 		{
 		    print '<br>';
-		    
+
 		    //print '<div class="underbanner clearboth"></div>';
-		    
+
 			print '<table class="border" width="100%">';
 
 			// If bank account

+ 4 - 4
htdocs/compta/bank/various_payment/card.php

@@ -26,7 +26,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
-if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/html.formventilation.class.php';
+if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
 if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
 
 $langs->load("compta");
@@ -180,7 +180,7 @@ if ($action == 'delete')
 llxHeader("",$langs->trans("VariousPayment"));
 
 $form = new Form($db);
-if (! empty($conf->accounting->enabled)) $formaccountancy = New FormVentilation($db);
+if (! empty($conf->accounting->enabled)) $formaccounting = New FormAccounting($db);
 
 if ($id)
 {
@@ -271,9 +271,9 @@ if ($action == 'create')
 	{
 		print '<tr><td>'.$langs->trans("AccountAccounting").'</td>';
         print '<td>';
-		print $formaccountancy->select_account($accountancy_code, 'accountancy_code', 1, null, 1, 1, '');
+		print $formaccounting->select_account($accountancy_code, 'accountancy_code', 1, null, 1, 1, '');
         print '</td></tr>';
-	}			
+	}
 	else // For external software 
 	{
 		print '<tr><td>'.$langs->trans("AccountAccounting").'</td>';

+ 1 - 1
htdocs/core/ajax/check_notifications.php

@@ -33,7 +33,7 @@ top_httphead('text/html');  // TODO Use a json mime type
 
 global $user, $db, $langs, $conf;
 
-$time = (int) GETPOST('time');    // Use the time parameter that is always increased by time_update, even if call is late
+$time = (int) GETPOST('time','int');    // Use the time parameter that is always increased by time_update, even if call is late
 //$time=dol_now();
 
 

+ 29 - 25
htdocs/core/class/html.form.class.php

@@ -429,23 +429,23 @@ class Form
         if ($direction > 0) { $extracss=($extracss?$extracss.' ':'').'inline-block'; $extrastyle='padding: 0px; padding-right: 3px !important;'; }
 
         $classfortooltip='classfortooltip';
-        
+
         $s='';$textfordialog='';
-        
+
         $htmltext=str_replace('"',"&quot;",$htmltext);
-        if ($tooltiptrigger != '') 
+        if ($tooltiptrigger != '')
         {
             $classfortooltip='classfortooltiponclick';
             $textfordialog.='<div style="display: none;" id="idfortooltiponclick_'.$tooltiptrigger.'" class="classfortooltiponclicktext">'.$htmltext.'</div>';
         }
-        if ($tooltipon == 2 || $tooltipon == 3) 
+        if ($tooltipon == 2 || $tooltipon == 3)
         {
             $paramfortooltipimg=' class="'.$classfortooltip.' inline-block'.($extracss?' '.$extracss:'').'" style="padding: 0px;'.($extrastyle?' '.$extrastyle:'').'"';
             if ($tooltiptrigger == '') $paramfortooltipimg.=' title="'.($noencodehtmltext?$htmltext:dol_escape_htmltag($htmltext,1)).'"'; // Attribut to put on img tag to store tooltip
             else $paramfortooltipimg.=' dolid="'.$tooltiptrigger.'"';
         }
         else $paramfortooltipimg =($extracss?' class="'.$extracss.'"':'').($extrastyle?' style="'.$extrastyle.'"':''); // Attribut to put on td text tag
-        if ($tooltipon == 1 || $tooltipon == 3) 
+        if ($tooltipon == 1 || $tooltipon == 3)
         {
             $paramfortooltiptd=' class="'.($tooltipon == 3 ? 'cursorpointer ' : '').$classfortooltip.' inline-block'.($extracss?' '.$extracss:'').'" style="padding: 0px;'.($extrastyle?' '.$extrastyle:'').'" ';
             if ($tooltiptrigger == '') $paramfortooltiptd.=' title="'.($noencodehtmltext?$htmltext:dol_escape_htmltag($htmltext,1)).'"'; // Attribut to put on td tag to store tooltip
@@ -496,7 +496,7 @@ class Form
 
         $alt = '';
         if ($tooltiptrigger) $alt=$langs->trans("ClickToShowHelp");
-        
+
         //For backwards compatibility
         if ($type == '0') $type = 'info';
         elseif ($type == '1') $type = 'help';
@@ -577,16 +577,16 @@ class Form
     	  				jQuery(".massaction").hide();
     	            }
         		}
-    
+
         	jQuery(document).ready(function () {
         		initCheckForSelect();
         		jQuery(".checkforselect").click(function() {
         			initCheckForSelect();
     	  		});
     	  		jQuery(".massactionselect").change(function() {
-        			var massaction = $( this ).val();  
+        			var massaction = $( this ).val();
         			var urlform = $( this ).closest("form").attr("action").replace("#show_files","");
-        			if (massaction == "builddoc") 
+        			if (massaction == "builddoc")
                     {
                         urlform = urlform + "#show_files";
     	            }
@@ -1034,7 +1034,7 @@ class Form
     {
         global $conf,$user,$langs;
 
-        $out=''; 
+        $out='';
         $num=0;
         $outarray=array();
 
@@ -1077,7 +1077,7 @@ class Form
         if ($resql)
         {
 			$events = null;
-			
+
            	if ($conf->use_javascript_ajax && ! $forcecombo)
             {
 				include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
@@ -3450,7 +3450,7 @@ class Form
             $cat = new Categorie($this->db);
             $cate_arbo = $cat->get_full_arbo($type,$excludeafterid);
 		}
-		
+
         $output = '<select class="flat" name="'.$htmlname.'">';
 		$outarray=array();
         if (is_array($cate_arbo))
@@ -4178,7 +4178,7 @@ class Form
                 }
                 print '</div>';
             }
-            if ($more) 
+            if ($more)
             {
                 print '<div class="inline-block">';
                 print $more;
@@ -4923,7 +4923,7 @@ class Form
      *	@param  int	$iSecond  		    Default preselected duration (number of seconds or '')
      * 	@param	int	$disabled           Disable the combo box
      * 	@param	string	$typehour		If 'select' then input hour and input min is a combo,
-     *						            if 'text' input hour is in text and input min is a text, 
+     *						            if 'text' input hour is in text and input min is a text,
      *						            if 'textselect' input hour is in text and input min is a combo
      *  @param	integer	$minunderhours	If 1, show minutes selection under the hours
      * 	@param	int	$nooutput		    Do not output html string but return it
@@ -4968,7 +4968,7 @@ class Form
 
         if ($typehour!='text') $retstring.=' '.$langs->trans('HourShort');
         else $retstring.=':';
-        
+
         // Minutes
         if ($minunderhours) $retstring.='<br>';
         else $retstring.="&nbsp;";
@@ -4988,7 +4988,7 @@ class Form
         {
         	$retstring.='<input placeholder="'.$langs->trans('MinuteShort').'" type="number" min="0" size="1" name="'.$prefix.'min"'.($disabled?' disabled':'').' class="flat maxwidth50" value="'.(($minSelected != '')?((int) $minSelected):'').'">';
         }
-        
+
         if ($typehour!='text') $retstring.=' '.$langs->trans('MinuteShort');
 
         //$retstring.="&nbsp;";
@@ -5594,7 +5594,7 @@ class Form
 		{
     		$listofidcompanytoscan=$object->thirdparty->id;
     		if (($object->thirdparty->parent > 0) && ! empty($conf->global->THIRDPARTY_INCLUDE_PARENT_IN_LINKTO)) $listofidcompanytoscan.=','.$object->thirdparty->parent;
-    		
+
     		$possiblelinks=array(
     		    'propal'=>array('enabled'=>$conf->propal->enabled, 'perms'=>1, 'label'=>'LinkToProposal', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('propal',1).')'),
     		    'order'=>array('enabled'=>$conf->commande->enabled, 'perms'=>1, 'label'=>'LinkToOrder', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('commande',1).')'),
@@ -5606,7 +5606,7 @@ class Form
     		    'invoice_supplier'=>array('enabled'=>$conf->fournisseur->facture->enabled , 'perms'=>1, 'label'=>'LinkToSupplierInvoice', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('facture_fourn',1).')')
     		);
 		}
-		
+
 		global $action;
 
 		// Can complete the possiblelink array
@@ -5845,7 +5845,7 @@ class Form
 
         //print "paramid=$paramid,morehtml=$morehtml,shownav=$shownav,$fieldid,$fieldref,$morehtmlref,$moreparam";
         $object->load_previous_next_ref((isset($object->next_prev_filter)?$object->next_prev_filter:''),$fieldid,$nodbprefix);
-        
+
         $navurl = $_SERVER["PHP_SELF"];
         // Special case for project/task page
         if ($paramid == 'project_ref')
@@ -5902,11 +5902,15 @@ class Form
 		}
 		else if (in_array($object->element, array('action', 'agenda')))
 		{
-		    $ret.=$object->ref.'<br>'.$object->label;    
+		    $ret.=$object->ref.'<br>'.$object->label;
+		}
+		else if (in_array($object->element, array('adherent_type')))
+		{
+			$ret.=$object->label;
 		}
 		else if ($fieldref != 'none') $ret.=dol_htmlentities($object->$fieldref);
-		
-		
+
+
 		if ($morehtmlref)
 		{
 		    $ret.=' '.$morehtmlref;
@@ -6207,7 +6211,7 @@ class Form
         return $out;
     }
 
-    
+
     /**
      *	Return HTML to show the search and clear seach button
      *
@@ -6216,7 +6220,7 @@ class Form
     function showFilterButtons()
     {
         global $conf, $langs;
-    
+
         $out='<div class="nowrap">';
         $out.='<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans("Search"),'search.png','','',1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
         $out.='<input type="image" class="liste_titre" name="button_removefilter" src="'.img_picto($langs->trans("Search"),'searchclear.png','','',1).'" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
@@ -6235,7 +6239,7 @@ class Form
     function showCheckAddButtons($cssclass='checkforaction', $calljsfunction=0)
     {
         global $conf, $langs;
-    
+
         $out='';
         if (! empty($conf->use_javascript_ajax)) $out.='<div class="inline-block checkallactions"><input type="checkbox" id="checkallactions" name="checkallactions" class="checkallactions"></div>';
         $out.='<script type="text/javascript">

+ 223 - 2
htdocs/core/class/html.formaccounting.class.php

@@ -1,5 +1,9 @@
 <?php
-/* Copyright (C) 2016-2017	Alexandre Spangaro	<aspangaro@zendsi.com>
+/* Copyright (C) 2013-2016 Florian Henry        <florian.henry@open-concept.pro>
+ * Copyright (C) 2013-2014 Olivier Geffroy      <jeff@jeffinfo.com>
+ * Copyright (C) 2015      Ari Elbaz (elarifr)  <github@accedinfo.com>
+ * Copyright (C) 2016      Marcos García        <marcosgdf@gmail.com>
+ * Copyright (C) 2016-2017 Alexandre Spangaro   <aspangaro@zendsi.com>
  *
  * 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
@@ -28,7 +32,7 @@
 class FormAccounting extends Form
 {
 
-    private $options_cache = array();
+	private $options_cache = array();
 
 	var $db;
 	var $error;
@@ -205,5 +209,222 @@ class FormAccounting extends Form
         
         print $out;
     }
+
+	/**
+	 * Return select filter with date of transaction
+	 *
+	 * @param string $htmlname Name of select field
+	 * @param string $selectedkey Value
+	 * @return string HTML edit field
+	 */
+	function select_bookkeeping_importkey($htmlname = 'importkey', $selectedkey = '') {
+		$options = array();
+
+		$sql = 'SELECT DISTINCT import_key from ' . MAIN_DB_PREFIX . 'accounting_bookkeeping';
+	    $sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")";
+		$sql .= ' ORDER BY import_key DESC';
+
+		dol_syslog(get_class($this) . "::select_bookkeeping_importkey", LOG_DEBUG);
+		$resql = $this->db->query($sql);
+
+		if (!$resql) {
+			$this->error = "Error " . $this->db->lasterror();
+			dol_syslog(get_class($this) . "::select_bookkeeping_importkey " . $this->error, LOG_ERR);
+			return - 1;
+		}
+
+		while ($obj = $this->db->fetch_object($resql)) {
+			$options[$obj->import_key] = dol_print_date($obj->import_key, 'dayhourtext');
+		}
+
+		return Form::selectarray($htmlname, $options, $selectedkey);
+	}
+
+	/**
+	 * Return list of accounts with label by chart of accounts
+	 *
+	 * @param string   $selectid           Preselected id or code of accounting accounts (depends on $select_in)
+	 * @param string   $htmlname           Name of field in html form
+	 * @param int      $showempty          Add an empty field
+	 * @param array    $event              Event options
+	 * @param int      $select_in          0=selectid value is a aa.rowid (default) or 1=selectid is aa.account_number
+	 * @param int      $select_out         Set value returned by select. 0=rowid (default), 1=account_number
+	 * @param string   $morecss            More css non HTML object
+	 * @param string   $usecache           Key to use to store result into a cache. Next call with same key will reuse the cache.
+	 * @return string                      String with HTML select
+	 */
+	function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $morecss='maxwidth300 maxwidthonsmartphone', $usecache='')
+	{
+		global $conf;
+
+		require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
+
+		$out = '';
+		
+    	$options = array();
+		if ($usecache && ! empty($this->options_cache[$usecache]))
+		{
+		    $options = $this->options_cache[$usecache];
+		    $selected=$selectid;
+		}
+		else
+		{
+    		$trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT') ? $conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT : 50;
+
+    		$sql = "SELECT DISTINCT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version";
+    		$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa";
+    		$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
+    		$sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS;
+    		$sql .= " AND aa.active = 1";
+    		$sql .= " ORDER BY aa.account_number";
+
+    		dol_syslog(get_class($this) . "::select_account", LOG_DEBUG);
+    		$resql = $this->db->query($sql);
+
+    		if (!$resql) {
+    			$this->error = "Error " . $this->db->lasterror();
+    			dol_syslog(get_class($this) . "::select_account " . $this->error, LOG_ERR);
+    			return -1;
+    		}
+
+    		$out .= ajax_combobox($htmlname, $event);
+
+    		$selected = 0;
+    		while ($obj = $this->db->fetch_object($resql))
+    		{
+    			$label = length_accountg($obj->account_number) . ' - ' . $obj->label;
+    			$label = dol_trunc($label, $trunclength);
+
+    			$select_value_in = $obj->rowid;
+    			$select_value_out = $obj->rowid;
+
+    			// Try to guess if we have found default value
+    			if ($select_in == 1) {
+    				$select_value_in = $obj->account_number;
+    			}
+    			if ($select_out == 1) {
+    				$select_value_out = $obj->account_number;
+    			}
+    			// Remember guy's we store in database llx_facturedet the rowid of accounting_account and not the account_number
+    			// Because same account_number can be share between different accounting_system and do have the same meaning
+    			if ($selectid != '' && $selectid == $select_value_in) {
+    			    //var_dump("Found ".$selectid." ".$select_value_in);
+    				$selected = $select_value_out;
+    			}
+
+    			$options[$select_value_out] = $label;
+    		}
+    		$this->db->free($resql);
+
+    		if ($usecache)
+    		{
+                $this->options_cache[$usecache] = $options;
+    		}
+		}
+
+		$out .= Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
+
+		return $out;
+	}
+
+	/**
+	 * Return list of auxilary thirdparty accounts
+	 *
+	 * @param string $selectid Preselected pcg_type
+	 * @param string $htmlname Name of field in html form
+	 * @param int $showempty Add an empty field
+	 * @param array $event Event options
+	 *
+	 * @return string String with HTML select
+	 */
+	function select_auxaccount($selectid, $htmlname = 'account_num_aux', $showempty = 0, $event = array()) {
+
+		$aux_account = array();
+
+		// Auxiliary customer account
+		$sql = "SELECT DISTINCT code_compta, nom ";
+		$sql .= " FROM ".MAIN_DB_PREFIX."societe";
+	    $sql .= " WHERE entity IN (" . getEntity("societe", 1) . ")";
+		$sql .= " ORDER BY code_compta";
+		dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG);
+		$resql = $this->db->query($sql);
+		if ($resql) {
+			while ($obj = $this->db->fetch_object($resql)) {
+				if (!empty($obj->code_compta)) {
+					$aux_account[$obj->code_compta] = $obj->code_compta.' ('.$obj->nom.')';
+				}
+			}
+		} else {
+			$this->error = "Error ".$this->db->lasterror();
+			dol_syslog(get_class($this)."::select_pcgsubtype ".$this->error, LOG_ERR);
+			return -1;
+		}
+		$this->db->free($resql);
+
+		// Auxiliary supplier account
+		$sql = "SELECT DISTINCT code_compta_fournisseur, nom ";
+		$sql .= " FROM ".MAIN_DB_PREFIX."societe";
+		$sql .= " WHERE entity IN (" . getEntity("societe", 1) . ")";
+		$sql .= " ORDER BY code_compta_fournisseur";
+		dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG);
+		$resql = $this->db->query($sql);
+		if ($resql) {
+			while ($obj = $this->db->fetch_object($resql)) {
+				if (!empty($obj->code_compta_fournisseur)) {
+					$aux_account[$obj->code_compta_fournisseur] = $obj->code_compta_fournisseur.' ('.$obj->nom.')';
+				}
+			}
+		} else {
+			$this->error = "Error ".$this->db->lasterror();
+			dol_syslog(get_class($this)."::select_pcgsubtype ".$this->error, LOG_ERR);
+			return -1;
+		}
+		$this->db->free($resql);
+
+		// Build select
+		$out = ajax_combobox($htmlname, $event);
+		$out .= Form::selectarray($htmlname, $aux_account, $selectid, $showempty, 0, 0, '', 0, 0, 0, '', 'maxwidth300');
+
+		return $out;
+	}
+
+	/**
+	 * Return HTML combo list of years existing into book keepping
+	 *
+	 * @param string $selected Preselected value
+	 * @param string $htmlname Name of HTML select object
+	 * @param int $useempty Affiche valeur vide dans liste
+	 * @param string $output_format (html/opton (for option html only)/array (to return options arrays
+	 * @return string/array
+	 */
+	function selectyear_accountancy_bookkepping($selected = '', $htmlname = 'yearid', $useempty = 0, $output_format = 'html')
+	{
+	    global $conf;
+
+		$out_array = array();
+
+		$sql = "SELECT DISTINCT date_format(doc_date,'%Y') as dtyear";
+		$sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping";
+	    $sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")";
+		$sql .= " ORDER BY date_format(doc_date,'%Y')";
+		dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG);
+		$resql = $this->db->query($sql);
+
+		if (!$resql) {
+			$this->error = "Error ".$this->db->lasterror();
+			dol_syslog(get_class($this)."::".__METHOD__.$this->error, LOG_ERR);
+			return -1;
+		}
+		while ($obj = $this->db->fetch_object($resql)) {
+			$out_array[$obj->dtyear] = $obj->dtyear;
+		}
+		$this->db->free($resql);
+
+		if ($output_format == 'html') {
+			return Form::selectarray($htmlname, $out_array, $selected, $useempty, 0, 0, 'placeholder="aa"');
+		} else {
+			return $out_array;
+		}
+	}
 }
 

+ 7 - 41
htdocs/core/lib/accounting.lib.php

@@ -1,7 +1,7 @@
 <?php
 /* Copyright (C) 2013-2014 Olivier Geffroy      <jeff@jeffinfo.com>
  * Copyright (C) 2013-2017 Alexandre Spangaro   <aspangaro.dolibarr@gmail.com>
- * Copyright (C) 2014 	   Florian Henry        <florian.henry@open-concept.pro>
+ * Copyright (C) 2014      Florian Henry        <florian.henry@open-concept.pro>
  *
  * 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
@@ -27,7 +27,7 @@
  *	Prepare array with list of admin tabs
  *
  *	@param	AccountingAccount	$object		Object instance we show card
- *	@return	array				Array of tabs to show
+ *	@return	array							Array of tabs to show
  */
 function admin_accounting_prepare_head(AccountingAccount $object=null)
 {
@@ -41,11 +41,6 @@ function admin_accounting_prepare_head(AccountingAccount $object=null)
 	$head[$h][2] = 'general';
 	$h ++;
 
-	$head[$h][0] = DOL_URL_ROOT.'/accountancy/admin/journal.php';
-	$head[$h][1] = $langs->trans("Journaux");
-	$head[$h][2] = 'journal';
-	$h ++;
-
 	$head[$h][0] = DOL_URL_ROOT.'/accountancy/admin/export.php';
 	$head[$h][1] = $langs->trans("ExportOptions");
 	$head[$h][2] = 'export';
@@ -91,35 +86,6 @@ function accounting_prepare_head(AccountingAccount $object)
 	return $head;
 }
 
-/**
- *	Prepare array with list of tabs
- *
- *	@param	AccountingAccount	$object		Accounting account
- *	@return	array				Array of tabs to show
- */
-function accounting_journal_prepare_head(AccountingJournal $object)
-{
-	global $langs, $conf;
-
-	$h = 0;
-	$head = array ();
-
-	$head[$h][0] = DOL_URL_ROOT.'/accountancy/admin/journals_card.php?id=' . $object->id;
-	$head[$h][1] = $langs->trans("Card");
-	$head[$h][2] = 'card';
-	$h ++;
-
-	// Show more tabs from modules
-	// Entries must be declared in modules descriptor with line
-	// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
-	// $this->tabs = array('entity:-tabname); to remove a tab
-	complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_journal');
-
-	complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_journal', 'remove');
-
-	return $head;
-}
-
 /**
  * Return accounting account without zero on the right
  *
@@ -129,7 +95,7 @@ function accounting_journal_prepare_head(AccountingJournal $object)
 function clean_account($account)
 {
 	$account = rtrim($account,"0");
-	
+
 	return $account;
 }
 
@@ -144,9 +110,9 @@ function length_accountg($account)
 	global $conf;
 
 	if ($account < 0 || empty($account)) return '';
-	
+
 	if (! empty($conf->global->ACCOUNTING_MANAGE_ZERO)) return $account;
-	
+
 	$g = $conf->global->ACCOUNTING_LENGTH_GACCOUNT;
 	if (! empty($g)) {
 		// Clean parameters
@@ -179,9 +145,9 @@ function length_accounta($accounta)
 	global $conf, $langs;
 
 	if ($accounta < 0 || empty($accounta)) return '';
-	
+
 	if (! empty($conf->global->ACCOUNTING_MANAGE_ZERO)) return $accounta;
-	
+
 	$a = $conf->global->ACCOUNTING_LENGTH_AACCOUNT;
 	if (! empty($a)) {
 		// Clean parameters

+ 3 - 1
htdocs/core/lib/files.lib.php

@@ -54,7 +54,7 @@ function dol_basename($pathfile)
  *  @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)
+function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter="", $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0)
 {
 	global $db, $hookmanager;
 	global $object;
@@ -483,6 +483,8 @@ function dolReplaceInFile($srcfile, $arrayreplacement, $destfile='', $newmask=0)
    
     dol_delete_file($tmpdestfile);
     
+    // Create $newpathoftmpdestfile from $newpathofsrcfile
+    
     
     
     

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

@@ -102,14 +102,14 @@ function getDoliDBInstance($type, $host, $user, $pass, $name, $port)
 /**
  * 	Get list of entity id to use
  *
- * 	@param	string	$element	Current element 
- *                              'societe', 'socpeople', 'actioncomm', 'agenda', 'resource', 
+ * 	@param	string	$element	Current element
+ *                              'societe', 'socpeople', 'actioncomm', 'agenda', 'resource',
  *                              'product', 'productprice', 'stock',
  *                              'propal', 'supplier_proposal', 'facture', 'facture_fourn',
- *                              'categorie', 'bank_account', 'bank_account', 'adherent', 'user',  
+ *                              'categorie', 'bank_account', 'bank_account', 'adherent', 'user',
  *                              'commande', 'commande_fournisseur', 'expedition', 'intervention', 'survey',
  *                              'contract', 'tax', 'expensereport', 'holiday', 'multicurrency', 'project',
- *                              'email_template', 'event',  
+ *                              'email_template', 'event',
  * 	@param	int		$shared		0=Return id of entity, 1=Return id entity + shared entities
  * 	@return	mixed				Entity id(s) to use
  */
@@ -121,7 +121,7 @@ function getEntity($element=false, $shared=0)
 	if ($element == 'actioncomm') $element='agenda';
 	if ($element == 'fichinter')  $element='intervention';
 	if ($element == 'categorie')  $element='category';
-	
+
 	if (is_object($mc))
 	{
 		return $mc->getEntity($element, $shared);
@@ -240,7 +240,7 @@ function dol_shutdown()
  *  Return value of a param into GET or POST supervariable.
  *  Use the property $user->default_values[path]['creatform'] and/or $user->default_values[path]['filters'] and/or $user->default_values[path]['sortorder']
  *  Note: The property $user->default_values is loaded by the main when loading the user.
- *  
+ *
  *  @param	string	$paramname   Name of parameter to found
  *  @param	string	$check	     Type of check
  *                                  ''=no check (deprecated)
@@ -257,29 +257,29 @@ function dol_shutdown()
  *  @param  int     $filter      Filter to apply when $check is set to 'custom'. (See http://php.net/manual/en/filter.filters.php for détails)
  *  @param  mixed   $options     Options to pass to filter_var when $check is set to 'custom'.
  *  @return string|string[]      Value found (string or array), or '' if check fails
- *  
+ *
  *  @TODO Set default value for check to alpha. Check all WYSIWYG edition (email and description...) is still ok with rich text.
  */
 function GETPOST($paramname, $check='', $method=0, $filter=NULL, $options=NULL)
 {
     global $mysoc,$user,$conf;
-    
+
     if (empty($paramname)) return 'BadFirstParameterForGETPOST';
-        
+
     if (empty($method)) $out = isset($_GET[$paramname])?$_GET[$paramname]:(isset($_POST[$paramname])?$_POST[$paramname]:'');
 	elseif ($method==1) $out = isset($_GET[$paramname])?$_GET[$paramname]:'';
 	elseif ($method==2) $out = isset($_POST[$paramname])?$_POST[$paramname]:'';
 	elseif ($method==3) $out = isset($_POST[$paramname])?$_POST[$paramname]:(isset($_GET[$paramname])?$_GET[$paramname]:'');
 	elseif ($method==4) $out = isset($_POST[$paramname])?$_POST[$paramname]:(isset($_GET[$paramname])?$_GET[$paramname]:(isset($_COOKIE[$paramname])?$_COOKIE[$paramname]:''));
 	else return 'BadThirdParameterForGETPOST';
-	
+
 	if (empty($method) || $method == 3 || $method == 4)
 	{
     	$relativepathstring = $_SERVER["PHP_SELF"];
     	if (constant('DOL_URL_ROOT')) $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'),'/').'/', '', $relativepathstring);
     	$relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
     	$relativepathstring = preg_replace('/^\//', '', $relativepathstring);
-	
+
         // Code for search criteria persistence.
     	// Retrieve values if restore_lastsearch_values is set and there is saved values
     	if (! empty($_GET['restore_lastsearch_values']) && ! empty($_SESSION['lastsearch_values_'.$relativepathstring]))        // Keep $_GET here
@@ -347,16 +347,16 @@ function GETPOST($paramname, $check='', $method=0, $filter=NULL, $options=NULL)
 	            }
 	        }
 	    }
-	    
-	}	
-	
+
+	}
+
 	if (empty($check) && ! empty($conf->global->MAIN_FEATURES_LEVEL) && $conf->global->MAIN_FEATURES_LEVEL >= 2)
 	{
-	   dol_syslog("Deprecated use of GETPOST, called with 1st param = ".$paramname." and 2nd param not defined, when calling page ".$_SERVER["PHP_SELF"], LOG_WARNING);    
+	   dol_syslog("Deprecated use of GETPOST, called with 1st param = ".$paramname." and 2nd param not defined, when calling page ".$_SERVER["PHP_SELF"], LOG_WARNING);
 	   // Enable this line to know who call the GETPOST with empty $check parameter.
 	   //var_dump(debug_backtrace()[0]);
 	}
-	
+
 	if (! empty($check))
 	{
 	    // Replace vars like __DAY__, __MONTH__, __YEAR__, __MYCOUNTRYID__, __USERID__, __ENTITYID__, ...
@@ -457,7 +457,7 @@ function GETPOST($paramname, $check='', $method=0, $filter=NULL, $options=NULL)
 	        // We save search key only if:
 	        // - not empty, or
 	        // - if value is empty and a default value exists that is not empty (it means we did a filter to an empty value when default was not).
-	        
+
 	        //if (! empty($out) || ! empty($user->default_values[$relativepathstring]['filters'][$paramname]))
 	        if (! empty($out))
 	        {
@@ -465,7 +465,7 @@ function GETPOST($paramname, $check='', $method=0, $filter=NULL, $options=NULL)
 	        }
 	    }
 	}
-	
+
 	return $out;
 }
 
@@ -475,13 +475,13 @@ function GETPOST($paramname, $check='', $method=0, $filter=NULL, $options=NULL)
  *  This prefix is unique for instance and avoid conflict between multi-instances,
  *  even when having two instances with one root dir or two instances in virtual servers.
  *
- *  @param  string  $mode       '' (prefix for session name) or 'email' (prefix for email id)              
+ *  @param  string  $mode       '' (prefix for session name) or 'email' (prefix for email id)
  *  @return	string      		A calculated prefix
  */
 function dol_getprefix($mode='')
 {
     global $conf;
-    
+
     // If MAIL_PREFIX_FOR_EMAIL_ID is set and prefix is for email
     if ($mode == 'email' && ! empty($conf->global->MAIL_PREFIX_FOR_EMAIL_ID))
     {
@@ -629,7 +629,7 @@ function dol_clone($object)
 
 	//$myclone = clone $object;                    // PHP clone is a shallow copy only, not a real clone, so properties of references will keep references (refer to the same target/variable
 	$myclone=unserialize(serialize($object));
-	    
+
 	return $myclone;
 }
 
@@ -1134,7 +1134,7 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r
 	global $conf, $form, $user, $langs;
 
 	$error = 0;
-	
+
 	$maxvisiblephotos=1;
 	$showimage=1;
 	$showbarcode=empty($conf->barcode->enabled)?0:($object->barcode?1:0);
@@ -1206,7 +1206,7 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r
                     $fileimage = $file.'_preview.png';              // If PDF has 1 page
                     $fileimagebis = $file.'_preview-0.png';         // If PDF has more than one page
                     $relativepathimage = $relativepath.'_preview.png';
-                    
+
                     // Si fichier PDF existe
                     if (file_exists($file))
                     {
@@ -1249,7 +1249,7 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r
                     $morehtmlleft.='</div>';
                 }
             }
-            
+
             if (! $phototoshow && $conf->browser->layout != 'phone')      // Show No photo link (picto of pbject)
             {
                 $morehtmlleft.='<div class="floatleft inline-block valignmiddle divphotoref">';
@@ -1271,12 +1271,12 @@ 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')
 	{
-	    if (! empty($conf->use_javascript_ajax) && $user->rights->societe->creer && ! empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) 
+	    if (! 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');
     	}
@@ -1303,7 +1303,7 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r
 	    if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout=='phone') $tmptxt=$object->getLibStatut(5, $object->totalpaye);
 		$morehtmlstatus.=$tmptxt;
 	}
-	elseif ($object->element == 'contrat' || $object->element == 'contract') 
+	elseif ($object->element == 'contrat' || $object->element == 'contract')
 	{
         if ($object->statut==0) $morehtmlstatus.=$object->getLibStatut(2);
         else $morehtmlstatus.=$object->getLibStatut(4);
@@ -1314,14 +1314,14 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r
 		$morehtmlstatus.=$tmptxt;
 	}
 	if (! empty($object->name_alias)) $morehtmlref.='<div class="refidno">'.$object->name_alias.'</div>';      // For thirdparty
-	
+
 	// Add label
 	if ($object->element == 'product' || $object->element == 'bank_account' || $object->element == 'project_task')
 	{
 		if (! empty($object->label)) $morehtmlref.='<div class="refidno">'.$object->label.'</div>';
 	}
-	
-	if ($object->element != 'product' && $object->element != 'bookmark') 
+
+	if ($object->element != 'product' && $object->element != 'bookmark')
 	{
     	$morehtmlref.='<div class="refidno">';
     	$morehtmlref.=$object->getBannerAddress('refaddress',$object);
@@ -1333,7 +1333,7 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r
 		$morehtmlref.=$langs->trans("TechnicalID").': '.$object->id;
 		$morehtmlref.='</div>';
 	}
-	
+
 	print '<div class="'.($onlybanner?'arearefnobottom ':'arearef ').'heightref valignmiddle" width="100%">';
 	print $form->showrefnav($object, $paramid, $morehtml, $shownav, $fieldid, $fieldref, $morehtmlref, $moreparam, $nodbprefix, $morehtmlleft, $morehtmlstatus, $morehtmlright);
 	print '</div>';
@@ -3095,7 +3095,7 @@ function info_admin($text, $infoonimgalt = 0, $nodiv=0, $admin='1')
 	{
 		return img_picto($text, 'info', 'class="hideonsmartphone"');
 	}
-	
+
 	return ($nodiv?'':'<div class="'.(empty($admin)?'':($admin=='1'?'info':$admin)).' hideonsmartphone">').'<span class="fa fa-info-circle" title="'.dol_escape_htmltag($admin?$langs->trans('InfoAdmin'):$langs->trans('Note')).'"></span> '.$text.($nodiv?'':'</div>');
 }
 
@@ -3293,7 +3293,7 @@ function getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $m
 	$field1=trim($tmpfield[0]);            // If $field is 'd.datep,d.id', it becomes 'd.datep'
 
 	//var_dump('field='.$field.' field1='.$field1.' sortfield='.$sortfield.' sortfield1='.$sortfield1);
-	
+
 	// If field is used as sort criteria we use a specific css class liste_titre_sel
 	// Example if (sortfield,field)=("nom","xxx.nom") or (sortfield,field)=("nom","nom")
 	if ($field1 && ($sortfield1 == $field1 || $sortfield1 == preg_replace("/^[^\.]+\./","",$field1))) $out.= '<'.$tag.' class="'.$prefix.'liste_titre_sel" '. $moreattrib.'>';
@@ -3441,7 +3441,7 @@ function load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png',
  *	@param	string	    $options         	More parameters for links ('' by default, does not include sortfield neither sortorder)
  *	@param	string    	$sortfield       	Field to sort on ('' by default)
  *	@param	string	    $sortorder       	Order to sort ('' by default)
- *	@param	string	    $center          	String in the middle ('' by default). We often find here string $massaction comming from $form->selectMassAction() 
+ *	@param	string	    $center          	String in the middle ('' by default). We often find here string $massaction comming from $form->selectMassAction()
  *	@param	int		    $num				Number of records found by select with limit+1
  *	@param	int|string  $totalnboflines		Total number of records/lines for all pages (if known). Use a negative value of number to not show number. Use '' if unknown.
  *	@param	string	    $picto				Icon to use before title (should be a 32x32 transparent png file)
@@ -3965,7 +3965,7 @@ function get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller
 	{
 	    $conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY = 1;
 	}
-	    
+
 	// Search local taxes
 	if (! empty($conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY))
 	{
@@ -4210,7 +4210,7 @@ function getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisi
 /**
  *	Return vat rate of a product in a particular selling country or default country vat if product is unknown
  *  Function called by get_default_tva
- *  
+ *
  *  @param	int			$idprod          	Id of product or 0 if not a predefined product
  *  @param  Societe		$thirdparty_seller  Thirdparty with a ->country_code defined (FR, US, IT, ...)
  *	@param	int			$idprodfournprice	Id product_fournisseur_price (for "supplier" order/invoice)
@@ -4248,7 +4248,7 @@ function get_product_vat_for_country($idprod, $thirdparty_seller, $idprodfournpr
 		}
 		else
 		{
-			// TODO Read default product vat according to countrycode and product. Vat for couple countrycode/product is a feature not implemeted yet. 
+			// TODO Read default product vat according to countrycode and product. Vat for couple countrycode/product is a feature not implemeted yet.
 			// May be usefull/required if hidden option SERVICE_ARE_ECOMMERCE_200238EC is on
 		}
 	}
@@ -5020,9 +5020,9 @@ function make_substitutions($text, $substitutionarray, $outputlangs=null)
 	global $conf, $langs;
 
 	if (! is_array($substitutionarray)) return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions';
-	
+
 	if (empty($outputlangs)) $outputlangs=$langs;
-	
+
 	// Make substitution for language keys
 	if (is_object($outputlangs))
 	{
@@ -5030,10 +5030,10 @@ function make_substitutions($text, $substitutionarray, $outputlangs=null)
 		{
 			$msgishtml = 0;
 			if (dol_textishtml($text,1)) $msgishtml = 1;
-			$text = preg_replace('/__\('.preg_quote($reg[1]).'\)__/', $msgishtml?dol_htmlentitiesbr($outputlangs->transnoentitiesnoconv($reg[1])):$outputlangs->transnoentitiesnoconv($reg[1]), $text);	
+			$text = preg_replace('/__\('.preg_quote($reg[1]).'\)__/', $msgishtml?dol_htmlentitiesbr($outputlangs->transnoentitiesnoconv($reg[1])):$outputlangs->transnoentitiesnoconv($reg[1]), $text);
 		}
 	}
-		
+
 	// Make substitition for array $substitutionarray
 	foreach ($substitutionarray as $key => $value)
 	{
@@ -5046,7 +5046,7 @@ function make_substitutions($text, $substitutionarray, $outputlangs=null)
 
 /**
  *  Complete the $substitutionarray with more entries.
- *  Can also add substitution keys coming from external module that had set the "substitutions=1" into module_part array. In this case, method completesubstitutionarray provided by module is called. 
+ *  Can also add substitution keys coming from external module that had set the "substitutions=1" into module_part array. In this case, method completesubstitutionarray provided by module is called.
  *
  *  @param  array		$substitutionarray		Array substitution old value => new value value
  *  @param  Translate	$outputlangs            Output language
@@ -5067,7 +5067,7 @@ function complete_substitutions_array(&$substitutionarray, $outputlangs, $object
 	{
 		// TODO
 	}
-	
+
 	// Add a substitution key for each extrafields, using key __EXTRA_XXX__
 	if (is_object($object) && is_array($object->array_options))
 	{
@@ -5079,7 +5079,7 @@ function complete_substitutions_array(&$substitutionarray, $outputlangs, $object
 			$substitutionarray['%EXTRA_'.$keyshort.'%']=$val;
 		}
 	}
-	
+
 	// Check if there is external substitution to do, requested by plugins
 	$dirsubstitutions=array_merge(array(),(array) $conf->modules_parts['substitutions']);
 
@@ -5615,8 +5615,8 @@ function dol_eval($s, $returnvalue=0, $hideerrors=1)
 	global $rights;
 	global $object;
 	global $mysoc;
-	
-	global $obj;       // To get $obj used into list when dol_eval is used for computed fields and $obj is not yet $object      
+
+	global $obj;       // To get $obj used into list when dol_eval is used for computed fields and $obj is not yet $object
 	global $soc;       // For backward compatibility
 
 	//print $s."<br>\n";
@@ -5827,7 +5827,7 @@ function printCommonFooter($zone='private')
     	           this.href=this.href+\'&page_y=\'+page_y;
     	           });'."\n";
     	print '});'."\n";
-    	
+
     	if (empty($conf->dol_use_jmobile))
     	{
         	print '<!-- Set handler to switch left menu page (menuhider) -->'."\n";
@@ -5837,7 +5837,7 @@ function printCommonFooter($zone='private')
         	print "  $('.login_block').toggle();";
         	print '});'."\n";
     	}
-    	
+
     	print '</script>'."\n";
 	}
 
@@ -6000,9 +6000,9 @@ function natural_search($fields, $value, $mode=0, $nofirstand=0)
     {
     	$value=preg_replace('/([<>=]+)\s+([0-9'.preg_quote($langs->trans("DecimalSeparator"),'/').'\-])/','\1\2',$value);	// Clean string '< 10' into '<10' so we can the explode on space to get all tests to do
     }
-    
+
     $value = preg_replace('/\s*\|\s*/','|', $value);
-    
+
     $crits = explode(' ', $value);
     $res = '';
     if (! is_array($fields)) $fields = array($fields);
@@ -6125,7 +6125,7 @@ function getImageFileNameForSize($file, $extName, $extImgTarget='')
  *
  * @param   string    $modulepart     propal, facture, facture_fourn, ...
  * @param   string    $relativepath   Relative path of docs.
- * @param	int		  $alldata		  Return array with all components (1 is recommended, then use a simple a href link with the class, target and mime attribute added. 'documentpreview' css class is handled by jquery code into main.inc.php)  
+ * @param	int		  $alldata		  Return array with all components (1 is recommended, then use a simple a href link with the class, target and mime attribute added. 'documentpreview' css class is handled by jquery code into main.inc.php)
  * @param	string	  $param		  More param on http links
  * @return  string|array              Output string with href link or array with all components of link
  */
@@ -6139,8 +6139,8 @@ function getAdvancedPreviewUrl($modulepart, $relativepath, $alldata=0, $param=''
     //$mime_preview[]='vnd.oasis.opendocument.presentation';
     //$mime_preview[]='archive';
     $num_mime = array_search(dol_mimetype($relativepath, '', 1), $mime_preview);
- 
-    if ($alldata == 1) 
+
+    if ($alldata == 1)
     {
     	if ($num_mime !== false) return array('target'=>'_blank', 'css'=>'documentpreview', 'url'=>DOL_URL_ROOT.'/document.php?modulepart='.$modulepart.'&attachment=0&file='.urlencode($relativepath), 'mime'=>dol_mimetype($relativepath), );
     	else return array();

+ 9 - 9
htdocs/don/admin/donation.php

@@ -1,9 +1,9 @@
 <?php
 /* Copyright (C) 2005-2010  Laurent Destailleur  	<eldy@users.sourceforge.net>
- * Copyright (C) 2012-2015	Juanjo Menent			<jmenent@2byte.es>
+ * Copyright (C) 2012-2015  Juanjo Menent			<jmenent@2byte.es>
  * Copyright (C) 2013-2017  Philippe Grand			<philippe.grand@atoo-net.com>
- * Copyright (C) 2015       Alexandre Spangaro		<aspangaro.dolibarr@gmail.com>
- * Copyright (C) 2015  		Benoit Bruchard			<benoitb21@gmail.com>
+ * Copyright (C) 2015-2017  Alexandre Spangaro		<aspangaro.dolibarr@gmail.com>
+ * Copyright (C) 2015       Benoit Bruchard			<benoitb21@gmail.com>
  *
  * 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
@@ -29,7 +29,7 @@ require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
 require_once DOL_DOCUMENT_ROOT . '/core/lib/donation.lib.php';
 require_once DOL_DOCUMENT_ROOT . '/don/class/don.class.php';
 require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
-if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
+if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
 
 $langs->load("admin");
 $langs->load("donations");
@@ -199,7 +199,7 @@ else if ($action == 'setart885') {
 
 $dir = "../../core/modules/dons/";
 $form=new Form($db);
-if (! empty($conf->accounting->enabled)) $formaccountancy = New FormVentilation($db);
+if (! empty($conf->accounting->enabled)) $formaccounting = New FormAccounting($db);
 
 llxHeader('',$langs->trans("DonationsSetup"),'DonConfiguration');
 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
@@ -364,7 +364,7 @@ print '<label for="DONATION_ACCOUNTINGACCOUNT">' . $label . '</label></td>';
 print '<td>';
 if (! empty($conf->accounting->enabled))
 {
-	print $formaccountancy->select_account($conf->global->DONATION_ACCOUNTINGACCOUNT, 'DONATION_ACCOUNTINGACCOUNT', 1, '', 1, 1);
+	print $formaccounting->select_account($conf->global->DONATION_ACCOUNTINGACCOUNT, 'DONATION_ACCOUNTINGACCOUNT', 1, '', 1, 1);
 }
 else
 {
@@ -401,7 +401,7 @@ if (preg_match('/fr/i',$conf->global->MAIN_INFO_SOCIETE_COUNTRY))
 	print '<tr class="liste_titre">';
 	print '<td colspan="3">' . $langs->trans('Parameters') . '</td>';
 	print "</tr>\n";
-	
+
 	print '<tr class="oddeven">';
 	print '<td width="80%">' . $langs->trans("DONATION_ART200") . '</td>';
 	if (! empty($conf->global->DONATION_ART200)) {
@@ -414,7 +414,7 @@ if (preg_match('/fr/i',$conf->global->MAIN_INFO_SOCIETE_COUNTRY))
 		print '</a></td>';
 	}
 	print '</tr>';
-	
+
 	print '<tr class="oddeven">';
 	print '<td width="80%">' . $langs->trans("DONATION_ART238") . '</td>';
 	if (! empty($conf->global->DONATION_ART238)) {
@@ -427,7 +427,7 @@ if (preg_match('/fr/i',$conf->global->MAIN_INFO_SOCIETE_COUNTRY))
 		print '</a></td>';
 	}
 	print '</tr>';
-	
+
 	print '<tr class="oddeven">';
 	print '<td width="80%">' . $langs->trans("DONATION_ART885") . '</td>';
 	if (! empty($conf->global->DONATION_ART885)) {

+ 19 - 10
htdocs/install/default.css

@@ -289,11 +289,11 @@ div.comment {
 }
 
 h3 {
-	margin-top: 10px;
+	margin-top: 20px;
 	font-size:16px;
 	font-weight: normal;
-	color: #4965B3;
-	text-shadow: 1px 1px 1px #c0c0c0;
+	color: rgb(100,60,20);
+	/* text-shadow: 1px 1px 1px #c0c0c0; */
 }
 
 tr.bg1 {
@@ -345,15 +345,15 @@ ul {
 
 .button {
     background: #fcfcfc;
-    border: 1px solid #d0d0d0;
+    border: 1px solid #e0e0e0;
     padding: 0.3em 0.7em;
     margin: 0 0.5em;
-    -moz-border-radius:0 5px 0 5px;
-    -webkit-border-radius:0 5px 0 5px;
-    border-radius:0 5px 0 5px;
-    -moz-box-shadow: 2px 2px 3px #CCC;
-    -webkit-box-shadow: 2px 2px 3px #CCC;
-    box-shadow: 2px 2px 3px #CCC;
+    -moz-border-radius: 5px 5px 5px 5px;
+    -webkit-border-radius: 5px 5px 5px 5px;
+    border-radius: 5px 5px 5px 5px;
+    -moz-box-shadow: 2px 2px 3px #ddd;
+    -webkit-box-shadow: 2px 2px 3px #ddd;
+    box-shadow: 2px 2px 3px #ddd;
 }
 a.button:hover {
     text-decoration:none;
@@ -368,3 +368,12 @@ a.button:hover {
 .center {
     text-align: center;
 }
+
+.valignmiddle {
+	vertical-align: middle;
+}
+
+.valigntextbottom {
+	vertical-align: text-bottom;
+}
+

+ 26 - 26
htdocs/install/fileconf.php

@@ -86,7 +86,7 @@ if (! is_writable($conffile))
 
 if (! empty($force_install_message))
 {
-    print '<div><table><tr><td valign="middle"><img src="../theme/common/information.png" style="height:40px;"></td><td valign="middle">'.$langs->trans($force_install_message).'</td></tr></table>';
+    print '<div><br>'.$langs->trans($force_install_message).'</div>';
 
     /*print '<script type="text/javascript">';
     print '	jQuery(document).ready(function() {
@@ -109,8 +109,8 @@ if (! empty($force_install_message))
 <table class="nobordernopadding<?php if ($force_install_noedit) print ' hidewhennoedit'; ?>">
 
 	<tr>
-		<td colspan="3" class="label" align="center">
-		<h3><?php echo $langs->trans("WebServer"); ?></h3>
+		<td colspan="3" class="label">
+		<h3><img class="valigntextbottom" src="../theme/common/octicons/lib/svg/globe.svg" width="20" alt="webserver"> <?php echo $langs->trans("WebServer"); ?></h3>
 		</td>
 	</tr>
 
@@ -125,7 +125,7 @@ if (! empty($force_install_message))
 		$dolibarr_main_document_root = detect_dolibarr_main_document_root();
 	}
 	?>
-		<td class="label" valign="top">
+		<td class="label tdtop">
 			<input type="text"
 			       class="minwidth300"
 			       value="<?php print $dolibarr_main_document_root ?>"
@@ -156,7 +156,7 @@ if (! empty($force_install_message))
 			$dolibarr_main_data_root = detect_dolibarr_main_data_root($dolibarr_main_document_root);
 		}
 		?>
-		<td class="label" valign="top">
+		<td class="label tdtop">
 			<input type="text"
 			       class="minwidth300"
 			       value="<?php print $dolibarr_main_data_root ?>"
@@ -210,7 +210,7 @@ if (! empty($force_install_message))
 	    ?>
 	<tr>
 		<td class="tdtop label"><?php echo $langs->trans("ForceHttps"); ?></td>
-		<td class="label" valign="top">
+		<td class="label tdtop">
 			<input type="checkbox"
 			       name="main_force_https"
 				<?php if (!empty($force_install_mainforcehttps)) {
@@ -232,15 +232,15 @@ if (! empty($force_install_message))
 	<!-- Dolibarr database -->
 
 	<tr>
-		<td colspan="3" class="label" align="center"><br>
-		<h3><?php echo $langs->trans("DolibarrDatabase"); ?></h3>
+		<td colspan="3" class="label"><br>
+		<h3><img class="valigntextbottom" src="../theme/common/octicons/lib/svg/database.svg" width="20" alt="webserver"> <?php echo $langs->trans("DolibarrDatabase"); ?></h3>
 		</td>
 	</tr>
 
 	<tr>
-		<td class="label" valign="top"><b> <?php echo $langs->trans("DatabaseName"); ?>
+		<td class="label tdtop"><b> <?php echo $langs->trans("DatabaseName"); ?>
 		</b></td>
-		<td class="label" valign="top">
+		<td class="label tdtop">
 			<input type="text" id="db_name"
 			       name="db_name"
 			       value="<?php echo (!empty($dolibarr_main_db_name)) ? $dolibarr_main_db_name : ($force_install_database ? $force_install_database : 'dolibarr'); ?>"
@@ -371,9 +371,9 @@ if (! empty($force_install_message))
 	</tr>
 
 	<tr class="hidesqlite">
-		<td class="label" valign="top"><?php echo $langs->trans("DatabasePrefix"); ?>
+		<td class="label tdtop"><?php echo $langs->trans("DatabasePrefix"); ?>
 		</td>
-		<td class="label" valign="top">
+		<td class="label tdtop">
 			<input type="text" id="db_prefix"
 			       name="db_prefix"
 			       value="<?php echo(!empty($force_install_prefix) ? $force_install_prefix : (!empty($dolibarr_main_db_prefix) ? $dolibarr_main_db_prefix : 'llx_')); ?>"
@@ -386,9 +386,9 @@ if (! empty($force_install_message))
 	</tr>
 
 	<tr class="hidesqlite">
-		<td class="label" valign="top"><?php echo $langs->trans("CreateDatabase"); ?>
+		<td class="label tdtop"><?php echo $langs->trans("CreateDatabase"); ?>
 		</td>
-		<td class="label" valign="top">
+		<td class="label tdtop">
 			<input type="checkbox"
 			       id="db_create_database"
 			       name="db_create_database"
@@ -405,9 +405,9 @@ if (! empty($force_install_message))
 	</tr>
 
 	<tr class="hidesqlite">
-		<td class="label" valign="top"><b><?php echo $langs->trans("Login"); ?></b>
+		<td class="label tdtop"><b><?php echo $langs->trans("Login"); ?></b>
 		</td>
-		<td class="label" valign="top">
+		<td class="label tdtop">
 			<input type="text" id="db_user"
 			       name="db_user"
 			       value="<?php print (!empty($force_install_databaselogin)) ? $force_install_databaselogin : $dolibarr_main_db_user; ?>"
@@ -420,9 +420,9 @@ if (! empty($force_install_message))
 	</tr>
 
 	<tr class="hidesqlite">
-		<td class="label" valign="top"><b><?php echo $langs->trans("Password"); ?></b>
+		<td class="label tdtop"><b><?php echo $langs->trans("Password"); ?></b>
 		</td>
-		<td class="label" valign="top">
+		<td class="label tdtop">
 			<input type="password" id="db_pass" autocomplete="off"
 			       name="db_pass"
 			       value="<?php
@@ -442,9 +442,9 @@ if (! empty($force_install_message))
 	</tr>
 
 	<tr class="hidesqlite">
-		<td class="label" valign="top"><?php echo $langs->trans("CreateUser"); ?>
+		<td class="label tdtop"><?php echo $langs->trans("CreateUser"); ?>
 		</td>
-		<td class="label" valign="top">
+		<td class="label tdtop">
 			<input type="checkbox"
 			       id="db_create_user" name="db_create_user"
 				<?php if (!empty($force_install_createuser)) {
@@ -466,14 +466,14 @@ if (! empty($force_install_message))
 	$force_install_databaserootpass = parse_database_pass($force_install_databaserootpass);
 	?>
 	<tr class="hidesqlite hideroot">
-		<td colspan="3" class="label" align="center"><br>
-		<h3><?php echo $langs->trans("DatabaseSuperUserAccess"); ?></h3>
+		<td colspan="3" class="label"><br>
+		<h3><img class="valigntextbottom" src="../theme/common/octicons/lib/svg/shield.svg" width="20" alt="webserver"> <?php echo $langs->trans("DatabaseSuperUserAccess"); ?></h3>
 		</td>
 	</tr>
 
 	<tr class="hidesqlite hideroot">
-		<td class="label" valign="top"><b><?php echo $langs->trans("Login"); ?></b></td>
-		<td class="label" valign="top">
+		<td class="label tdtop"><b><?php echo $langs->trans("Login"); ?></b></td>
+		<td class="label tdtop">
 			<input type="text"
 			       id="db_user_root"
 			       name="db_user_root"
@@ -496,9 +496,9 @@ if (! empty($force_install_message))
 
 	</tr>
 	<tr class="hidesqlite hideroot">
-		<td class="label" valign="top"><b><?php echo $langs->trans("Password"); ?></b>
+		<td class="label tdtop"><b><?php echo $langs->trans("Password"); ?></b>
 		</td>
-		<td class="label" valign="top">
+		<td class="label tdtop">
 			<input type="password"
 			       autocomplete="off"
 			       id="db_pass_root"

+ 10 - 9
htdocs/install/mysql/migration/5.0.0-6.0.0.sql

@@ -214,22 +214,22 @@ ALTER TABLE llx_societe_remise_except ADD CONSTRAINT fk_societe_remise_fk_invoic
 
 ALTER TABLE llx_facture_rec ADD COLUMN vat_src_code	varchar(10) DEFAULT '';
 
-DELETE FROM llx_const where name = 'ADHERENT_BANK_USE_AUTO';
+DELETE FROM llx_const WHERE name = __ENCRYPT('ADHERENT_BANK_USE_AUTO')__;
 
-UPDATE llx_const set value='moono-lisa' where value = 'moono' AND name = 'FCKEDITOR_SKIN';
+UPDATE llx_const SET value = __ENCRYPT('moono-lisa')__ WHERE value = __ENCRYPT('moono')__ AND name = __ENCRYPT('FCKEDITOR_SKIN')__;
 
-ALTER TABLE llx_product_price ADD COLUMN default_vat_code	varchar(10) after tva_tx;
-ALTER TABLE llx_product_fournisseur_price ADD COLUMN default_vat_code	varchar(10) after tva_tx;
+ALTER TABLE llx_product_price ADD COLUMN default_vat_code	varchar(10) AFTER tva_tx;
+ALTER TABLE llx_product_fournisseur_price ADD COLUMN default_vat_code	varchar(10) AFTER tva_tx;
 
 ALTER TABLE llx_user ADD COLUMN model_pdf varchar(255);
 ALTER TABLE llx_usergroup ADD COLUMN model_pdf varchar(255);
 
-INSERT INTO llx_const (name, entity, value, type, visible, note) VALUES ('PRODUCT_ADDON_PDF_ODT_PATH', 1, 'DOL_DATA_ROOT/doctemplates/products', 'chaine', 0, '');
-INSERT INTO llx_const (name, entity, value, type, visible, note) VALUES ('CONTRACT_ADDON_PDF_ODT_PATH', 1, 'DOL_DATA_ROOT/doctemplates/contracts', 'chaine', 0, '');
-INSERT INTO llx_const (name, entity, value, type, visible, note) VALUES ('USERGROUP_ADDON_PDF_ODT_PATH', 1, 'DOL_DATA_ROOT/doctemplates/usergroups', 'chaine', 0, '');
-INSERT INTO llx_const (name, entity, value, type, visible, note) VALUES ('USER_ADDON_PDF_ODT_PATH', 1, 'DOL_DATA_ROOT/doctemplates/users', 'chaine', 0, '');
+INSERT INTO llx_const (name, entity, value, type, visible, note) VALUES (__ENCRYPT('PRODUCT_ADDON_PDF_ODT_PATH')__, 1, __ENCRYPT('DOL_DATA_ROOT/doctemplates/products')__, 'chaine', 0, '');
+INSERT INTO llx_const (name, entity, value, type, visible, note) VALUES (__ENCRYPT('CONTRACT_ADDON_PDF_ODT_PATH')__, 1, __ENCRYPT('DOL_DATA_ROOT/doctemplates/contracts')__, 'chaine', 0, '');
+INSERT INTO llx_const (name, entity, value, type, visible, note) VALUES (__ENCRYPT('USERGROUP_ADDON_PDF_ODT_PATH')__, 1, __ENCRYPT('DOL_DATA_ROOT/doctemplates/usergroups')__, 'chaine', 0, '');
+INSERT INTO llx_const (name, entity, value, type, visible, note) VALUES (__ENCRYPT('USER_ADDON_PDF_ODT_PATH')__, 1, __ENCRYPT('DOL_DATA_ROOT/doctemplates/users')__, 'chaine', 0, '');
 
-INSERT INTO llx_const (name, entity, value, type, visible, note) VALUES ('MAIN_ENABLE_OVERWRITE_TRANSLATION', 1, '1', 'chaine', 0, 'Enable overwrote of translation');
+INSERT INTO llx_const (name, entity, value, type, visible, note) VALUES (__ENCRYPT('MAIN_ENABLE_OVERWRITE_TRANSLATION')__, 1, __ENCRYPT('1')__, 'chaine', 0, 'Enable overwrote of translation');
 
 ALTER TABLE llx_chargesociales ADD COLUMN ref varchar(16);
 ALTER TABLE llx_chargesociales ADD COLUMN fk_projet integer DEFAULT NULL;
@@ -348,3 +348,4 @@ ALTER TABLE llx_facture ADD COLUMN fk_fac_rec_source integer;
 DELETE from llx_c_actioncomm where code in ('AC_PROP','AC_COM','AC_FAC','AC_SHIP','AC_SUP_ORD','AC_SUP_INV') AND id NOT IN (SELECT DISTINCT fk_action FROM llx_actioncomm);
 
 
+ALTER TABLE llx_inventory ADD COLUMN ref varchar(48);

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

@@ -18,6 +18,7 @@ ErrorFailToCreateFile=Failed to create file '<b>%s</b>'.
 ErrorFailToRenameDir=Failed to rename directory '<b>%s</b>' into '<b>%s</b>'.
 ErrorFailToCreateDir=Failed to create directory '<b>%s</b>'.
 ErrorFailToDeleteDir=Failed to delete directory '<b>%s</b>'.
+ErrorFailToMakeReplacementInto=Failed to make replacement into file '<b>%s</b>'.
 ErrorThisContactIsAlreadyDefinedAsThisType=This contact is already defined as contact for this type.
 ErrorCashAccountAcceptsOnlyCashMoney=This bank account is a cash account, so it accepts payments of type cash only.
 ErrorFromToAccountsMustDiffers=Source and targets bank accounts must be different.

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

@@ -1,5 +1,6 @@
 # Dolibarr language file - Source file is en_US - loan
 ModuleBuilderDesc=This tools give you utilites to build or edit your own module.
+EnterNameOfModuleDesc=Enter name of the module to create with no spaces. Use uppercase to separate words (For example: MyModule, EcommerceForShop, SyncWithMySystem...)
 ModuleBuilderDesc2=Path were modules are generated/edited (first alternative directory defined into %s): <strong>%s</strong>
 ModuleBuilderDesc3=Generated/editable modules found: <strong>%s</strong> (they are detected as editable when the file <strong>%s</strong> exists in root of module directory). 
 NewModule=New module

+ 9 - 9
htdocs/loan/card.php

@@ -1,5 +1,5 @@
 <?php
-/* Copyright (C) 2014-2016	Alexandre Spangaro   <aspangaro@zendsi.com>
+/* Copyright (C) 2014-2017	Alexandre Spangaro   <aspangaro@zendsi.com>
  * Copyright (C) 2015       Frederic France      <frederic.france@free.fr>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -27,7 +27,7 @@ require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
 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';
+if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
 
@@ -235,7 +235,7 @@ if (empty($reshook))
 
 $form = new Form($db);
 $formproject = new FormProjets($db);
-if (! empty($conf->accounting->enabled)) $formaccountancy = New FormVentilation($db);
+if (! empty($conf->accounting->enabled)) $formaccounting = New FormAccounting($db);
 
 $title = $langs->trans("Loan") . ' - ' . $langs->trans("Card");
 $help_url = 'EN:Module_Loan|FR:Module_Emprunt';
@@ -337,19 +337,19 @@ if ($action == 'create')
 		// Accountancy_account_capital
         print '<tr><td class="titlefieldcreate">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
         print '<td>';
-		print $formaccountancy->select_account($object->accountancy_account_capital, 'accountancy_account_capital', 1, '', 0, 1);
+		print $formaccounting->select_account($object->accountancy_account_capital, 'accountancy_account_capital', 1, '', 0, 1);
         print '</td></tr>';
 
 		// Accountancy_account_insurance
         print '<tr><td>'.$langs->trans("LoanAccountancyInsuranceCode").'</td>';
         print '<td>';
-		print $formaccountancy->select_account($object->accountancy_account_insurance, 'accountancy_account_insurance', 1, '', 0, 1);
+		print $formaccounting->select_account($object->accountancy_account_insurance, 'accountancy_account_insurance', 1, '', 0, 1);
         print '</td></tr>';
 
 		// Accountancy_account_interest
         print '<tr><td>'.$langs->trans("LoanAccountancyInterestCode").'</td>';
         print '<td>';
-		print $formaccountancy->select_account($object->accountancy_account_interest, 'accountancy_account_interest', 1, '', 0, 1);
+		print $formaccounting->select_account($object->accountancy_account_interest, 'accountancy_account_interest', 1, '', 0, 1);
         print '</td></tr>';
 	}
 	else // For external software 
@@ -541,7 +541,7 @@ if ($id > 0)
 		{
 			if (! empty($conf->accounting->enabled))
 			{
-				print $formaccountancy->select_account($object->account_capital, 'accountancy_account_capital', 1, '', 0, 1);
+				print $formaccounting->select_account($object->account_capital, 'accountancy_account_capital', 1, '', 0, 1);
 			}
 			else
 			{
@@ -566,7 +566,7 @@ if ($id > 0)
 		{
 			if (! empty($conf->accounting->enabled))
 			{
-				print $formaccountancy->select_account($object->account_insurance, 'accountancy_account_insurance', 1, '', 0, 1);
+				print $formaccounting->select_account($object->account_insurance, 'accountancy_account_insurance', 1, '', 0, 1);
 			}
 			else
 			{
@@ -591,7 +591,7 @@ if ($id > 0)
 		{
 			if (! empty($conf->accounting->enabled))
 			{
-				print $formaccountancy->select_account($object->account_interest, 'accountancy_account_interest', 1, '', 0, 1);
+				print $formaccounting->select_account($object->account_interest, 'accountancy_account_interest', 1, '', 0, 1);
 			}
 			else
 			{

+ 221 - 0
htdocs/modulebuilder/README.md

@@ -0,0 +1,221 @@
+Dolibarr Module Template (aka My Module)
+========================================
+
+This is a full featured module template for Dolibarr.
+It's a tool for module developers to kickstart their project and give an hands-on sample of which features Dolibarr has to offer for module development.
+
+If you're not a module developer you have no use for this.
+
+Documentation
+-------------
+
+[Module tutorial](http://wiki.dolibarr.org/index.php/Module_development)
+
+[Dolibarr development](http://wiki.dolibarr.org/index.php/Developer_documentation)
+
+### Translations
+
+Dolibarr uses [Transifex](http://transifex.com) to manage it's translations.
+
+This template also contains a sample configuration for Transifex managed translations under the hidden [.tx](.tx) directory.
+
+For more informations, see the [translator's documentation](http://wiki.dolibarr.org/index.php/Translator_documentation).
+
+There is a [Transifex project](http://transifex.com/projects/p/dolibarr-module-template) for this module.
+
+Install
+-------
+
+### Manually
+
+- Make sure Dolibarr (>= 3.3.x) is already installed and configured on your workstation or development server.
+
+- In your Dolibarr installation directory, edit the ```htdocs/conf/conf.php``` file
+
+- Find the following lines:
+    ```php
+    //$dolibarr_main_url_root_alt ...
+    //$dolibarr_main_document_root_alt ...
+    ```
+
+- Uncomment these lines (delete the leading ```//```) and assign a sensible value according to your Dolibarr installation
+
+    For example :
+
+    - UNIX:
+        ```php
+        $dolibarr_main_url_root = 'http://localhost/Dolibarr/htdocs';
+        $dolibarr_main_document_root = '/var/www/Dolibarr/htdocs';
+        $dolibarr_main_url_root_alt = '/custom';
+        $dolibarr_main_document_root_alt = '/var/www/Dolibarr/htdocs/custom';
+        ```
+
+    - Windows:
+        ```php
+        $dolibarr_main_url_root = 'http://localhost/Dolibarr/htdocs';
+        $dolibarr_main_document_root = 'C:/My Web Sites/Dolibarr/htdocs';
+        $dolibarr_main_url_root_alt = '/custom';
+        $dolibarr_main_document_root_alt = 'C:/My Web Sites/Dolibarr/htdocs/custom';
+        ```
+
+    For more information about the ```conf.php``` file take a look at the conf.php.example file.
+
+*Note that for Dolibarr versions before 3.5, the ```$dolibarr_main_url_root_alt``` has to be an absolute path*
+
+- Clone the repository in ```$dolibarr_main_document_root_alt/mymodule```
+
+*(You may have to create the ```htdocs/custom``` directory first if it doesn't exist yet.)*
+```sh
+git clone git@github.com:Dolibarr/dolibarr-module-template.git mymodule
+```
+
+- Install [Composer](https://getcomposer.org) dependencies:
+```sh
+composer install
+```
+
+Follow the [final steps](#final_steps).
+
+### Using [Composer](https://getcomposer.org)
+Require this repository from Dolibarr's composer:
+```json
+{
+  "repositories": [
+    {
+      "type": "vcs",
+      "url": "https://github.com/dolibarr/dolibarr-module-template"
+    }
+  ],
+  "require": {
+    "dolibarr/mymodule": "dev-master"
+  }
+}
+```
+
+Run
+```sh
+composer update
+```
+
+Follow the [final steps](#final_steps).
+
+### <a name="final_steps"></a>Final steps
+
+From your browser:
+
+  - Log into Dolibarr as a super-administrator
+  - Under "Setup" -> "Other setup", set ```MAIN_FEATURES_LEVEL``` to ```2```
+  - Go to "Setup" -> "Modules"
+  - The module is under one of the tabs
+  - You should now be able to enable the new module and start coding ;)
+
+Provided tools
+--------------
+
+### Starting a new module
+
+A [script](dev/newmodule.sh) allows you to rename most of the code to your own module name.  
+It requires ```find```, ```sed``` and ```rename``` commands on your system.  
+Just make sure you provide a CamelCase name.
+```sh
+./dev/newmodule.sh [NewName]
+```
+
+Some work still has to be done manually:
+- Rename the directory holding the code
+- Maybe rename some other bits (Search for 'my' in filenames and code)
+- Update your module ID in the module descriptor
+- Update your language files
+    - Keywords based on the module ID
+    - String referencing the template
+- Remove the features you don't plan to use
+- Fill the copyright notices at the top of each file
+- Add your logo: see [images README](dev/img/README.md) for specifications
+- Start a new GIT history 
+```
+git checkout --orphan [new_branch_name]
+```
+- Build an awesome module ;)
+
+### Composer scripts
+
+Only the main commands are listed here.  
+See the [composer comments](composer-comments.md) or the [composer.json](composer.json) itself for more informations.
+
+#### Check
+
+Run a linter, a PHP compatibility version checker and checks coding style.
+```sh
+composer check
+```
+
+#### Test
+  
+Run unit and functional tests.
+```sh
+composer test
+```
+
+#### Doc
+Build code and user documentation.
+
+#### Release
+
+Run the checks and tests then build a distribution ZIP.
+```sh
+composer release
+```
+
+#### Git hooks
+
+Optional [GIT hooks](https://git-scm.com/book/it/v2/Customizing-Git-Git-Hooks) are provided.
+These are just wrappers calling composer scripts.  
+They ensure best practices are followed during module development.  
+
+Install:
+```sh
+composer git_hooks_install
+```
+
+Remove:
+```sh
+composer git_hooks_remove
+```
+
+## Publishing the module
+The de-facto standard for publishing and marketing modules for Dolibarr is the [Dolistore](https://www.dolistore.com).  
+Templates for required images and texts are [provided](dev/dolistore).  
+Check the dedicated [README](dev/dolistore/README.md) for more informations.
+
+Contributions
+-------------
+
+Feel free to contribute and report defects on our [issue tracker](http://github.com/Dolibarr/dolibarr-module-template/issues).
+
+Licenses
+--------
+
+### Main code
+
+![GPLv3 logo](img/gplv3.png)
+
+GPLv3 or (at your option) any later version.
+
+See [COPYING](COPYING) for more information.
+
+### Other Licenses
+
+#### [Parsedown](http://parsedown.org/)
+
+Used to display this README in the module's about page.  
+Licensed under MIT.
+
+#### [GNU Licenses logos](https://www.gnu.org/graphics/license-logos.html)
+
+Public domain
+
+#### Documentation
+
+All texts and readmes.
+
+![GFDL logo](img/gfdl.png)

+ 46 - 18
htdocs/modulebuilder/index.php

@@ -32,15 +32,15 @@ $langs->load("other");
 $action=GETPOST('action','alpha');
 $confirm=GETPOST('confirm','alpha');
 $module=GETPOST('module');
-$tab=GETPOST('tab');
 if (empty($module)) $module='initmodule';
 if (empty($tab)) $tab='description';
 
+$modulename=dol_sanitizeFileName(GETPOST('modulename','alpha'));
+
 
 // Security check
 if (! $user->admin && empty($conf->global->MODULEBUILDER_FOREVERYONE)) accessforbidden('ModuleBuilderNotAllowed');
 
-$modulename=dol_sanitizeFileName(GETPOST('modulename','alpha'));
 
 // Dir for custom dirs
 $tmp=explode(',', $dolibarr_main_document_root_alt);
@@ -55,35 +55,59 @@ $FILEFLAG='modulebuilder.txt';
 
 if ($dircustom && $action == 'initmodule' && $modulename)
 {
-    $srcfile = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
-    $destfile = $dircustom.'/'.$modulename;
-    $result = dolCopyDir($srcfile, $destfile, 0, 0);
+    $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
+    $destdir = $dircustom.'/'.$modulename;
+
+    $arrayreplacement=array(
+        'mymodule'=>strtolower($modulename),
+     	'MyModule'=>$modulename
+    );
+    
+    $result = dolCopyDir($srcdir, $destdir, 0, 0);
     //dol_mkdir($destfile);
     if ($result <= 0)
     {
         $error++;
-        setEventMessages($langs->trans("ErrorFailedToCopyDir"), null, 'errors');
+        $langs->load("errors");
+        setEventMessages($langs->trans("ErrorFailToCopyDir", $srcdir, $destdir), null, 'errors');
     }
 
     // Edit PHP files
-    $listofphpfilestoedit = dol_dir_list($destfile, 'files', 1, '\.php$', 'fullname', SORT_ASC, 0, true);
-    foreach($listofphpfilestoedit as $phpfileval)
+    if (! $error)
     {
-        $arrayreplacement=array(
-            'mymodule'=>$modulename
-        );
-        $result=dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
-        var_dump($phpfileval);
-        var_dump($result);
-    }    
-    
+	    $listofphpfilestoedit = dol_dir_list($destdir, 'files', 1, '\.php$', '', 'fullname', SORT_ASC, 0, 1);
+	    foreach($listofphpfilestoedit as $phpfileval)
+	    {
+	        var_dump($phpfileval['fullname']);
+	    	
+	    	$arrayreplacement=array(
+	            'mymodule'=>strtolower($modulename),
+	        	'MyModule'=>$modulename,
+	        	'MYMODULE'=>strtoupper($modulename),
+	        	'My module'=>$modulename,
+	        	'htdocs/modulebuilder/template/'=>'',
+	        );
+	        
+	        
+	        $result=dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
+	        //var_dump($result);
+	        if ($result < 0)
+	        {
+	        	setEventMessages($langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname']), null, 'errors');
+	        }
+	    }    
+    }
+        
     if (! $error)
     {
         setEventMessages('ModuleInitialized', null);
+        $module=$modulename;
+        $modulename = '';
     }
 }
 
 
+
 /*
  * View
  */
@@ -96,6 +120,7 @@ $text=$langs->trans("ModuleBuilder");
 print load_fiche_titre($text, '', 'title_setup');
 
 $listofmodules=array();
+
 /*
 if (!empty($conf->modulebuilder->enabled) && $mainmenu == 'modulebuilder')	// Entry for Module builder
 {
@@ -124,7 +149,7 @@ if (!empty($conf->modulebuilder->enabled) && $mainmenu == 'modulebuilder')	// En
         $newmenu->add('', 'NoGeneratedModuleFound', 0, 0);
     }*/
 
-            
+
 // Show description of content
 print $langs->trans("ModuleBuilderDesc").'<br>';
 print $langs->trans("ModuleBuilderDesc2", 'conf/conf.php', $dircustom).'<br>';
@@ -161,7 +186,10 @@ if ($module == 'initmodule')
     print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
     print '<input type="hidden" name="action" value="initmodule">';
     print '<input type="hidden" name="module" value="initmodule">';
-    print '<input type="text" name="modulename" value="" placeholder="'.dol_escape_htmltag($langs->trans("ModuleKey")).'">';
+    
+    print $langs->trans("EnterNameOfModuleDesc").'<br><br>';
+    
+    print '<input type="text" name="modulename" value="'.dol_escape_htmltag($modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("ModuleKey")).'">';
     print '<input type="submit" class="button" name="create" value="'.dol_escape_htmltag($langs->trans("Create")).'">';
     print '</form>';
 }

+ 4 - 219
htdocs/modulebuilder/template/README.md

@@ -1,221 +1,6 @@
-Dolibarr Module Template (aka My Module)
-========================================
+# MYMODULE FOR DOLIBARR ERP CRM
 
-This is a full featured module template for Dolibarr.
-It's a tool for module developers to kickstart their project and give an hands-on sample of which features Dolibarr has to offer for module development.
+## Features
+MyModuleDescription
 
-If you're not a module developer you have no use for this.
-
-Documentation
--------------
-
-[Module tutorial](http://wiki.dolibarr.org/index.php/Module_development)
-
-[Dolibarr development](http://wiki.dolibarr.org/index.php/Developer_documentation)
-
-### Translations
-
-Dolibarr uses [Transifex](http://transifex.com) to manage it's translations.
-
-This template also contains a sample configuration for Transifex managed translations under the hidden [.tx](.tx) directory.
-
-For more informations, see the [translator's documentation](http://wiki.dolibarr.org/index.php/Translator_documentation).
-
-There is a [Transifex project](http://transifex.com/projects/p/dolibarr-module-template) for this module.
-
-Install
--------
-
-### Manually
-
-- Make sure Dolibarr (>= 3.3.x) is already installed and configured on your workstation or development server.
-
-- In your Dolibarr installation directory, edit the ```htdocs/conf/conf.php``` file
-
-- Find the following lines:
-    ```php
-    //$dolibarr_main_url_root_alt ...
-    //$dolibarr_main_document_root_alt ...
-    ```
-
-- Uncomment these lines (delete the leading ```//```) and assign a sensible value according to your Dolibarr installation
-
-    For example :
-
-    - UNIX:
-        ```php
-        $dolibarr_main_url_root = 'http://localhost/Dolibarr/htdocs';
-        $dolibarr_main_document_root = '/var/www/Dolibarr/htdocs';
-        $dolibarr_main_url_root_alt = '/custom';
-        $dolibarr_main_document_root_alt = '/var/www/Dolibarr/htdocs/custom';
-        ```
-
-    - Windows:
-        ```php
-        $dolibarr_main_url_root = 'http://localhost/Dolibarr/htdocs';
-        $dolibarr_main_document_root = 'C:/My Web Sites/Dolibarr/htdocs';
-        $dolibarr_main_url_root_alt = '/custom';
-        $dolibarr_main_document_root_alt = 'C:/My Web Sites/Dolibarr/htdocs/custom';
-        ```
-
-    For more information about the ```conf.php``` file take a look at the conf.php.example file.
-
-*Note that for Dolibarr versions before 3.5, the ```$dolibarr_main_url_root_alt``` has to be an absolute path*
-
-- Clone the repository in ```$dolibarr_main_document_root_alt/mymodule```
-
-*(You may have to create the ```htdocs/custom``` directory first if it doesn't exist yet.)*
-```sh
-git clone git@github.com:Dolibarr/dolibarr-module-template.git mymodule
-```
-
-- Install [Composer](https://getcomposer.org) dependencies:
-```sh
-composer install
-```
-
-Follow the [final steps](#final_steps).
-
-### Using [Composer](https://getcomposer.org)
-Require this repository from Dolibarr's composer:
-```json
-{
-  "repositories": [
-    {
-      "type": "vcs",
-      "url": "https://github.com/dolibarr/dolibarr-module-template"
-    }
-  ],
-  "require": {
-    "dolibarr/mymodule": "dev-master"
-  }
-}
-```
-
-Run
-```sh
-composer update
-```
-
-Follow the [final steps](#final_steps).
-
-### <a name="final_steps"></a>Final steps
-
-From your browser:
-
-  - Log into Dolibarr as a super-administrator
-  - Under "Setup" -> "Other setup", set ```MAIN_FEATURES_LEVEL``` to ```2```
-  - Go to "Setup" -> "Modules"
-  - The module is under one of the tabs
-  - You should now be able to enable the new module and start coding ;)
-
-Provided tools
---------------
-
-### Starting a new module
-
-A [script](dev/newmodule.sh) allows you to rename most of the code to your own module name.  
-It requires ```find```, ```sed``` and ```rename``` commands on your system.  
-Just make sure you provide a CamelCase name.
-```sh
-./dev/newmodule.sh [NewName]
-```
-
-Some work still has to be done manually:
-- Rename the directory holding the code
-- Maybe rename some other bits (Search for 'my' in filenames and code)
-- Update your module ID in the module descriptor
-- Update your language files
-    - Keywords based on the module ID
-    - String referencing the template
-- Remove the features you don't plan to use
-- Fill the copyright notices at the top of each file
-- Add your logo: see [images README](dev/img/README.md) for specifications
-- Start a new GIT history 
-```
-git checkout --orphan [new_branch_name]
-```
-- Build an awesome module ;)
-
-### Composer scripts
-
-Only the main commands are listed here.  
-See the [composer comments](composer-comments.md) or the [composer.json](composer.json) itself for more informations.
-
-#### Check
-
-Run a linter, a PHP compatibility version checker and checks coding style.
-```sh
-composer check
-```
-
-#### Test
-  
-Run unit and functional tests.
-```sh
-composer test
-```
-
-#### Doc
-Build code and user documentation.
-
-#### Release
-
-Run the checks and tests then build a distribution ZIP.
-```sh
-composer release
-```
-
-#### Git hooks
-
-Optional [GIT hooks](https://git-scm.com/book/it/v2/Customizing-Git-Git-Hooks) are provided.
-These are just wrappers calling composer scripts.  
-They ensure best practices are followed during module development.  
-
-Install:
-```sh
-composer git_hooks_install
-```
-
-Remove:
-```sh
-composer git_hooks_remove
-```
-
-## Publishing the module
-The de-facto standard for publishing and marketing modules for Dolibarr is the [Dolistore](https://www.dolistore.com).  
-Templates for required images and texts are [provided](dev/dolistore).  
-Check the dedicated [README](dev/dolistore/README.md) for more informations.
-
-Contributions
--------------
-
-Feel free to contribute and report defects on our [issue tracker](http://github.com/Dolibarr/dolibarr-module-template/issues).
-
-Licenses
---------
-
-### Main code
-
-![GPLv3 logo](img/gplv3.png)
-
-GPLv3 or (at your option) any later version.
-
-See [COPYING](COPYING) for more information.
-
-### Other Licenses
-
-#### [Parsedown](http://parsedown.org/)
-
-Used to display this README in the module's about page.  
-Licensed under MIT.
-
-#### [GNU Licenses logos](https://www.gnu.org/graphics/license-logos.html)
-
-Public domain
-
-#### Documentation
-
-All texts and readmes.
-
-![GFDL logo](img/gfdl.png)
+Other modules are available on <a href="https://www.dolistore.com target="_new">Dolistore.com</a>.

+ 1 - 1
htdocs/modulebuilder/template/admin/about.php

@@ -17,7 +17,7 @@
  */
 
 /**
- * \file    admin/about.php
+ * \file    htdocs/modulebuilder/template/admin/about.php
  * \ingroup mymodule
  * \brief   About page of module MyModule.
  *

+ 3 - 3
htdocs/modulebuilder/template/admin/setup.php

@@ -17,7 +17,7 @@
  */
 
 /**
- * \file    admin/setup.php
+ * \file    htdocs/modulebuilder/template/admin/setup.php
  * \ingroup mymodule
  * \brief   Example module setup page.
  *
@@ -57,8 +57,8 @@ $page_name = "MyModuleSetup";
 llxHeader('', $langs->trans($page_name));
 
 // Subheader
-$linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php">'
-	. $langs->trans("BackToModuleList") . '</a>';
+$linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php">' . $langs->trans("BackToModuleList") . '</a>';
+
 print load_fiche_titre($langs->trans($page_name), $linkback);
 
 // Configuration header

+ 0 - 51
htdocs/modulebuilder/template/class/MyTrigger.php

@@ -1,51 +0,0 @@
-<?php
-/* <one line to give the program's name and a brief idea of what it does.>
- * Copyright (C) <year>  <name of author>
- *
- * 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    class/MyTrigger.php
- * \ingroup mymodule
- * \brief   Compatibility class for triggers in Dolibarr < 3.7.
- *
- * Hack for compatibility with Dolibarr versions < 3.7.
- * Remove this and extend DolibarrTriggers directly from interface_99_modMyModule_MyTrigger.class.php
- * if you don't intend to support these versions.
- */
-
-// We ignore the PSR1.Classes.ClassDeclaration.MultipleClasses rule.
-// @codingStandardsIgnoreStart
-$dolibarr_version = versiondolibarrarray();
-if ($dolibarr_version[0] < 3 || ($dolibarr_version[0] == 3 && $dolibarr_version[1] < 7)) { // DOL_VERSION < 3.7
-	/**
-	 * Class MyTrigger
-	 *
-	 * For Dolibarr < 3.7.
-	 */
-	abstract class MyTrigger
-	{
-	}
-} else {
-	/**
-	 * Class MyTrigger
-	 *
-	 * For Dolibarr >= 3.7
-	 */
-	abstract class MyTrigger extends DolibarrTriggers
-	{
-	}
-}
-// @codingStandardsIgnoreEnd

+ 1 - 1
htdocs/modulebuilder/template/class/actions_mymodule.class.php

@@ -17,7 +17,7 @@
  */
 
 /**
- * \file    class/actions_mymodule.class.php
+ * \file    htdocs/modulebuilder/template/class/actions_mymodule.class.php
  * \ingroup mymodule
  * \brief   Example hook overload.
  *

+ 0 - 361
htdocs/modulebuilder/template/class/myclass.class.php

@@ -1,361 +0,0 @@
-<?php
-/* <one line to give the program's name and a brief idea of what it does.>
- * Copyright (C) <year>  <name of author>
- *
- * 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    class/myclass.class.php
- * \ingroup mymodule
- * \brief   Example CRUD (Create/Read/Update/Delete) class.
- *
- * Put detailed description here.
- */
-
-/** Includes */
-//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";
-
-/**
- * Put your class' description here
- */
-class MyClass // extends CommonObject
-{
-
-    /** @var DoliDb Database handler */
-	private $db;
-    /** @var string Error code or message */
-	public $error;
-    /** @var array Several error codes or messages */
-	public $errors = array();
-    /** @var string Id to identify managed object */
-	//public $element='myelement';
-    /** @var string Name of table without prefix where object is stored */
-	//public $table_element='mytable';
-    /** @var int An example ID */
-	public $id;
-    /** @var mixed An example property */
-	public $prop1;
-    /** @var mixed An example property */
-	public $prop2;
-
-	/**
-	 * Constructor
-	 *
-	 * @param DoliDb $db Database handler
-	 */
-	public function __construct($db)
-	{
-		$this->db = $db;
-
-		return 1;
-	}
-
-	/**
-	 * Create object into database
-	 *
-	 * @param User $user User that create
-	 * @param int $notrigger 0=launch triggers after, 1=disable triggers
-	 * @return int <0 if KO, Id of created object if OK
-	 */
-	public function create($user, $notrigger = 0)
-	{
-		global $conf, $langs;
-		$error = 0;
-
-		// Clean parameters
-		if (isset($this->prop1)) {
-			$this->prop1 = trim($this->prop1);
-		}
-		if (isset($this->prop2)) {
-			$this->prop2 = trim($this->prop2);
-		}
-
-		// Check parameters
-		// Put here code to add control on parameters values
-		// Insert request
-		$sql = "INSERT INTO " . MAIN_DB_PREFIX . "mytable(";
-		$sql.= " field1,";
-		$sql.= " field2";
-
-		$sql.= ") VALUES (";
-		$sql.= " '" . $this->prop1 . "',";
-		$sql.= " '" . $this->prop2 . "'";
-
-		$sql.= ")";
-
-		$this->db->begin();
-
-		dol_syslog(__METHOD__ . " sql=" . $sql, LOG_DEBUG);
-		$resql = $this->db->query($sql);
-		if (! $resql) {
-			$error ++;
-			$this->errors[] = "Error " . $this->db->lasterror();
-		}
-
-		if (! $error) {
-			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "mytable");
-
-			if (! $notrigger) {
-				// Uncomment this and change MYOBJECT to your own tag if you
-				// want this action call a trigger.
-				//// Call triggers
-				//include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php";
-				//$interface=new Interfaces($this->db);
-				//$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf);
-				//if ($result < 0) { $error++; $this->errors=$interface->errors; }
-				//// End call triggers
-			}
-		}
-
-		// Commit or rollback
-		if ($error) {
-			foreach ($this->errors as $errmsg) {
-				dol_syslog(__METHOD__ . " " . $errmsg, LOG_ERR);
-				$this->error.=($this->error ? ', ' . $errmsg : $errmsg);
-			}
-			$this->db->rollback();
-
-			return -1 * $error;
-		} else {
-			$this->db->commit();
-
-			return $this->id;
-		}
-	}
-
-	/**
-	 * Load object in memory from database
-	 *
-	 * @param int $id Id object
-	 * @return int <0 if KO, >0 if OK
-	 */
-	public function fetch($id)
-	{
-		global $langs;
-		$sql = "SELECT";
-		$sql.= " t.rowid,";
-		$sql.= " t.field1,";
-		$sql.= " t.field2";
-		//...
-		$sql.= " FROM " . MAIN_DB_PREFIX . "mytable as t";
-		$sql.= " WHERE t.rowid = " . $id;
-
-		dol_syslog(__METHOD__ . " sql=" . $sql, LOG_DEBUG);
-		$resql = $this->db->query($sql);
-		if ($resql) {
-			if ($this->db->num_rows($resql)) {
-				$obj = $this->db->fetch_object($resql);
-
-				$this->id = $obj->rowid;
-				$this->prop1 = $obj->field1;
-				$this->prop2 = $obj->field2;
-				//...
-			}
-			$this->db->free($resql);
-
-			return 1;
-		} else {
-			$this->error = "Error " . $this->db->lasterror();
-			dol_syslog(__METHOD__ . " " . $this->error, LOG_ERR);
-
-			return -1;
-		}
-	}
-
-	/**
-	 * Update object into database
-	 *
-	 * @param User $user User that modify
-	 * @param int $notrigger 0=launch triggers after, 1=disable triggers
-	 * @return int <0 if KO, >0 if OK
-	 */
-	public function update($user = 0, $notrigger = 0)
-	{
-		global $conf, $langs;
-		$error = 0;
-
-		// Clean parameters
-		if (isset($this->prop1)) {
-			$this->prop1 = trim($this->prop1);
-		}
-		if (isset($this->prop2)) {
-			$this->prop2 = trim($this->prop2);
-		}
-
-		// Check parameters
-		// Put here code to add control on parameters values
-		// Update request
-		$sql = "UPDATE " . MAIN_DB_PREFIX . "mytable SET";
-		$sql.= " field1=" . (isset($this->field1) ? "'" . $this->db->escape($this->field1) . "'" : "null") . ",";
-		$sql.= " field2=" . (isset($this->field2) ? "'" . $this->db->escape($this->field2) . "'" : "null") . "";
-
-		$sql.= " WHERE rowid=" . $this->id;
-
-		$this->db->begin();
-
-		dol_syslog(__METHOD__ . " sql=" . $sql, LOG_DEBUG);
-		$resql = $this->db->query($sql);
-		if (! $resql) {
-			$error ++;
-			$this->errors[] = "Error " . $this->db->lasterror();
-		}
-
-		if (! $error) {
-			if (! $notrigger) {
-				// Uncomment this and change MYOBJECT to your own tag if you
-				// want this action call a trigger.
-				//// Call triggers
-				//include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php";
-				//$interface=new Interfaces($this->db);
-				//$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf);
-				//if ($result < 0) { $error++; $this->errors=$interface->errors; }
-				//// End call triggers
-			}
-		}
-
-		// Commit or rollback
-		if ($error) {
-			foreach ($this->errors as $errmsg) {
-				dol_syslog(__METHOD__ . " " . $errmsg, LOG_ERR);
-				$this->error.=($this->error ? ', ' . $errmsg : $errmsg);
-			}
-			$this->db->rollback();
-
-			return -1 * $error;
-		} else {
-			$this->db->commit();
-
-			return 1;
-		}
-	}
-
-	/**
-	 * Delete object in database
-	 *
-	 * @param User $user User that delete
-	 * @param int $notrigger 0=launch triggers after, 1=disable triggers
-	 * @return int <0 if KO, >0 if OK
-	 */
-	public function delete($user, $notrigger = 0)
-	{
-		global $conf, $langs;
-		$error = 0;
-
-		$this->db->begin();
-
-		if (! $error) {
-			if (! $notrigger) {
-				// Uncomment this and change MYOBJECT to your own tag if you
-				// want this action call a trigger.
-				//// Call triggers
-				//include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php";
-				//$interface=new Interfaces($this->db);
-				//$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf);
-				//if ($result < 0) { $error++; $this->errors=$interface->errors; }
-				//// End call triggers
-			}
-		}
-
-		if (! $error) {
-			$sql = "DELETE FROM " . MAIN_DB_PREFIX . "mytable";
-			$sql.= " WHERE rowid=" . $this->id;
-
-			dol_syslog(__METHOD__ . " sql=" . $sql);
-			$resql = $this->db->query($sql);
-			if (! $resql) {
-				$error ++;
-				$this->errors[] = "Error " . $this->db->lasterror();
-			}
-		}
-
-		// Commit or rollback
-		if ($error) {
-			foreach ($this->errors as $errmsg) {
-				dol_syslog(__METHOD__ . " " . $errmsg, LOG_ERR);
-				$this->error.=($this->error ? ', ' . $errmsg : $errmsg);
-			}
-			$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)
-	{
-		global $user, $langs;
-
-		$error = 0;
-
-		$object = new SkeletonClass($this->db);
-
-		$this->db->begin();
-
-		// Load source object
-		$object->fetch($fromid);
-		$object->id = 0;
-		$object->statut = 0;
-
-		// Clear fields
-		// ...
-		// Create clone
-		$result = $object->create($user);
-
-		// Other options
-		if ($result < 0) {
-			$this->error = $object->error;
-			$error ++;
-		}
-
-		if (! $error) {
-			// Do something
-		}
-
-		// End
-		if (! $error) {
-			$this->db->commit();
-
-			return $object->id;
-		} else {
-			$this->db->rollback();
-
-			return -1;
-		}
-	}
-
-	/**
-	 * Initialise object with example values
-	 * Id must be 0 if object instance is a specimen
-	 *
-	 * @return void
-	 */
-	public function initAsSpecimen()
-	{
-		$this->id = 0;
-		$this->prop1 = 'prop1';
-		$this->prop2 = 'prop2';
-	}
-}

+ 607 - 0
htdocs/modulebuilder/template/class/myobject.class.php

@@ -0,0 +1,607 @@
+<?php
+/* Copyright (C) 2007-2017  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        htdocs/modulebuilder/template/class/myobject.class.php
+ * \ingroup     mymodule othermodule1 othermodule2
+ * \brief       This file is an example for a CRUD class file (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 MyModuleObject
+ *
+ * Put here description of your class.
+ */
+class MyModuleObject extends CommonObject
+{
+	/**
+	 * @var string Id to identify managed object
+	 */
+	public $element = 'mymoduleobject';
+	/**
+	 * @var string Name of table without prefix where object is stored
+	 */
+	public $table_element = 'mymoduleobject';
+    /**
+     * @var array Array with all fields and their property
+     */
+	public $picto = 'generic';
+    /**
+     * @var array Array with all fields and their property
+     */
+	public $fields;
+	
+	/**
+	 * @var mixed Sample property 1
+	 */
+	public $prop1;
+	/**
+	 * @var mixed Sample property 2
+	 */
+	public $prop2;
+	
+	//...
+	
+	protected $ismultientitymanaged = 1;	// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
+	
+	public $table_element_line = 'mymoduleobjectdet';
+    public $class_element_line = 'MyModuleObjectline';
+    public $fk_element = 'fk_mymoduleobject';
+
+    /**
+	 * @var MyModuleObjectLine[] Lines
+	 */
+	public $lines = array();
+	
+	
+	
+	/**
+	 * 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)
+	{
+		dol_syslog(__METHOD__, LOG_DEBUG);
+
+		$error = 0;
+
+		// Clean parameters
+		if (isset($this->prop1)) {
+			$this->prop1 = trim($this->prop1);
+		}
+		if (isset($this->prop2)) {
+			$this->prop2 = trim($this->prop2);
+		}
+		//...
+
+		// Check parameters
+		// Put here code to add control on parameters values
+
+		// Insert request
+		$sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '(';
+		$sql .= ' field1,';
+		$sql .= ' field2';
+		//...
+		$sql .= ') VALUES (';
+		$sql .= ' \'' . $this->prop1 . '\',';
+		$sql .= ' \'' . $this->prop2 . '\'';
+		//...
+		$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);
+
+			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 Ref
+	 *
+	 * @return int <0 if KO, 0 if not found, >0 if OK
+	 */
+	public function fetch($id, $ref = null)
+	{
+		dol_syslog(__METHOD__, LOG_DEBUG);
+
+		$sql = 'SELECT';
+		$sql .= ' t.rowid,';
+		$sql .= ' t.field1,';
+		$sql .= ' t.field2';
+		//...
+		$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
+		$sql.= ' WHERE 1 = 1';
+		if (! empty($conf->multicompany->enabled)) {
+		    $sql .= " AND entity IN (" . getEntity("mymoduleobject", 1) . ")";
+		}
+		if (null !== $ref) {
+			$sql .= ' AND t.ref = ' . '\'' . $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->prop1 = $obj->field1;
+				$this->prop2 = $obj->field2;
+				//...
+			}
+			
+			// 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.field1,';
+		$sql .= ' t.field2';
+		//...
+		$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';
+		if (! empty($conf->multicompany->enabled)) {
+		    $sql .= " AND entity IN (" . getEntity("mymoduleobject", 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);
+		}
+
+		$resql = $this->db->query($sql);
+		if ($resql) {
+			$num = $this->db->num_rows($resql);
+
+			while ($obj = $this->db->fetch_object($resql)) {
+				$line = new self($this->db);
+
+				$line->id = $obj->rowid;
+				$line->prop1 = $obj->field1;
+				$line->prop2 = $obj->field2;
+				//...
+			}
+			$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)
+	{
+		dol_syslog(__METHOD__, LOG_DEBUG);
+
+		$error = 0;
+		
+		// Clean parameters
+		if (isset($this->prop1)) {
+			$this->prop1 = trim($this->prop1);
+		}
+		if (isset($this->prop2)) {
+			$this->prop2 = trim($this->prop2);
+		}
+		//...
+
+		// Check parameters
+		// Put here code to add a control on parameters values
+
+		// Update request
+		$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET';
+		$sql .= " field1=".(isset($this->field1)?"'".$this->db->escape($this->field1)."'":"null").",";
+        $sql .= " field2=".(isset($this->field2)?"'".$this->db->escape($this->field2)."'":"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 MyModuleObject($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.'/mymodule/'.$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()
+	{
+		$this->id = 0;
+		$this->prop1 = 'prop1';
+		$this->prop2 = 'prop2';
+	}
+
+}
+
+/**
+ * Class MyModuleObjectLine
+ */
+class MyModuleObjectLine
+{
+	/**
+	 * @var int ID
+	 */
+	public $id;
+	/**
+	 * @var mixed Sample line property 1
+	 */
+	public $prop1;
+	/**
+	 * @var mixed Sample line property 2
+	 */
+	public $prop2;
+}

+ 292 - 0
htdocs/modulebuilder/template/class/myobject_api_class.class.php

@@ -0,0 +1,292 @@
+<?php
+/* Copyright (C) 2015   Jean-François Ferry     <jfefe@aternatik.fr>
+ *
+ * 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/>.
+ */
+
+use Luracast\Restler\RestException;
+
+/**
+ * \file    htdocs/modulebuilder/template/class/myobject_api_class.class.php
+ * \ingroup mymodule
+ * \brief   File for API management of myobject.
+ */
+ 
+/**
+ * API class for mymodule myobject
+ *
+ * @smart-auto-routing false
+ * @access protected 
+ * @class  DolibarrApiAccess {@requires user,external}
+ */
+class MyObjectApi extends DolibarrApi
+{
+    /**
+     * @var array   $FIELDS     Mandatory fields, checked when create and update object 
+     */
+    static $FIELDS = array(
+        'name'
+    );
+
+    /**
+     * @var MyObject $myobject {@type MyObject}
+     */
+    public $myobject;
+
+    /**
+     * Constructor
+     *
+     * @url     GET myobject/
+     * 
+     */
+    function __construct()
+    {
+		global $db, $conf;
+		$this->db = $db;
+        $this->myobject = new MyObject($this->db);
+    }
+
+    /**
+     * Get properties of a myobject object
+     *
+     * Return an array with myobject informations
+     *
+     * @param 	int 	$id ID of myobject
+     * @return 	array|mixed data without useless information
+	 * 
+     * @url	GET myobject/{id}
+     * @throws 	RestException
+     */
+    function get($id)
+    {		
+		if(! DolibarrApiAccess::$user->rights->myobject->read) {
+			throw new RestException(401);
+		}
+			
+        $result = $this->myobject->fetch($id);
+        if( ! $result ) {
+            throw new RestException(404, 'MyObject not found');
+        }
+		
+		if( ! DolibarrApi::_checkAccessToResource('myobject',$this->myobject->id)) {
+			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+		}
+
+		return $this->_cleanObjectDatas($this->myobject);
+    }
+
+    /**
+     * List myobjects
+     * 
+     * Get a list of myobjects
+     * 
+     * @param int		$mode		Use this param to filter list
+     * @param string	$sortfield	Sort field
+     * @param string	$sortorder	Sort order
+     * @param int		$limit		Limit for list
+     * @param int		$page		Page number
+     * @param string    $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101') or (t.import_key:=:'20160101')"
+     * @return array Array of myobject objects
+     *
+     * @url	GET /myobjects/
+     */
+    function index($mode, $sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $sqlfilters = '') {
+        global $db, $conf;
+        
+        $obj_ret = array();
+        
+        $socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : '';
+            
+        // If the internal user must only see his customers, force searching by him
+        if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
+
+        $sql = "SELECT s.rowid";
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
+        $sql.= " FROM ".MAIN_DB_PREFIX."myobject as s";
+        
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
+        $sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st";
+        $sql.= " WHERE s.fk_stcomm = st.id";
+        
+		// Example of use $mode
+        //if ($mode == 1) $sql.= " AND s.client IN (1, 3)";
+        //if ($mode == 2) $sql.= " AND s.client IN (2, 3)";
+
+        $sql.= ' AND s.entity IN ('.getEntity('myobject', 1).')';
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND s.fk_soc = sc.fk_soc";
+        if ($socid) $sql.= " AND s.fk_soc = ".$socid;
+        if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc";		// Join for the needed table to filter by sale
+        // Insert sale filter
+        if ($search_sale > 0)
+        {
+            $sql .= " AND sc.fk_user = ".$search_sale;
+        }
+        if ($sqlfilters)
+        {
+            if (! DolibarrApi::_checkFilters($sqlfilters))
+            {
+                throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
+            }
+	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
+            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
+        }
+
+        $sql.= $db->order($sortfield, $sortorder);
+        if ($limit)	{
+            if ($page < 0)
+            {
+                $page = 0;
+            }
+            $offset = $limit * $page;
+
+            $sql.= $db->plimit($limit + 1, $offset);
+        }
+
+        $result = $db->query($sql);
+        if ($result)
+        {
+            $num = $db->num_rows($result);
+            while ($i < $num)
+            {
+                $obj = $db->fetch_object($result);
+                $myobject_static = new MyObject($db);
+                if($myobject_static->fetch($obj->rowid)) {
+                    $obj_ret[] = parent::_cleanObjectDatas($myobject_static);
+                }
+                $i++;
+            }
+        }
+        else {
+            throw new RestException(503, 'Error when retrieve myobject list');
+        }
+        if( ! count($obj_ret)) {
+            throw new RestException(404, 'No myobject found');
+        }
+		return $obj_ret;
+    }
+    
+    /**
+     * Create myobject object
+     *
+     * @param array $request_data   Request datas
+     * @return int  ID of myobject
+     * 
+     * @url	POST myobject/
+     */
+    function post($request_data = NULL)
+    {
+        if(! DolibarrApiAccess::$user->rights->myobject->create) {
+			throw new RestException(401);
+		}
+        // Check mandatory fields
+        $result = $this->_validate($request_data);
+        
+        foreach($request_data as $field => $value) {
+            $this->myobject->$field = $value;
+        }
+        if( ! $this->myobject->create(DolibarrApiAccess::$user)) {
+            throw new RestException(500);
+        }
+        return $this->myobject->id;
+    }
+
+    /**
+     * Update myobject
+     *
+     * @param int   $id             Id of myobject to update
+     * @param array $request_data   Datas   
+     * @return int 
+     * 
+     * @url	PUT myobject/{id}
+     */
+    function put($id, $request_data = NULL)
+    {
+        if(! DolibarrApiAccess::$user->rights->myobject->create) {
+			throw new RestException(401);
+		}
+        
+        $result = $this->myobject->fetch($id);
+        if( ! $result ) {
+            throw new RestException(404, 'MyObject not found');
+        }
+		
+		if( ! DolibarrApi::_checkAccessToResource('myobject',$this->myobject->id)) {
+			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+		}
+
+        foreach($request_data as $field => $value) {
+            $this->myobject->$field = $value;
+        }
+        
+        if($this->myobject->update($id, DolibarrApiAccess::$user))
+            return $this->get ($id);
+        
+        return false;
+    }
+    
+    /**
+     * Delete myobject
+     *
+     * @param   int     $id   MyObject ID
+     * @return  array
+     * 
+     * @url	DELETE myobject/{id}
+     */
+    function delete($id)
+    {
+        if(! DolibarrApiAccess::$user->rights->myobject->supprimer) {
+			throw new RestException(401);
+		}
+        $result = $this->myobject->fetch($id);
+        if( ! $result ) {
+            throw new RestException(404, 'MyObject not found');
+        }
+		
+		if( ! DolibarrApi::_checkAccessToResource('myobject',$this->myobject->id)) {
+			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+		}
+        
+        if( !$this->myobject->delete($id))
+        {
+            throw new RestException(500);
+        }
+        
+         return array(
+            'success' => array(
+                'code' => 200,
+                'message' => 'MyObject deleted'
+            )
+        );
+        
+    }
+    
+    /**
+     * Validate fields before create or update object
+     * 
+     * @param array $data   Data to validate
+     * @return array
+     * 
+     * @throws RestException
+     */
+    function _validate($data)
+    {
+        $myobject = array();
+        foreach (MyObjectApi::$FIELDS as $field) {
+            if (!isset($data[$field]))
+                throw new RestException(400, "$field field missing");
+            $myobject[$field] = $data[$field];
+        }
+        return $myobject;
+    }
+}

+ 201 - 626
htdocs/modulebuilder/template/core/modules/modMyModule.class.php

@@ -1,10 +1,11 @@
 <?php
-/* <one line to give the program's name and a brief idea of what it does.>
- * Copyright (C) <year>  <name of author>
+/* Copyright (C) 2003      Rodolphe Quiedeville <rodolphe@quiedeville.org>
+ * Copyright (C) 2004-2015 Laurent Destailleur  <eldy@users.sourceforge.net>
+ * Copyright (C) 2005-2016 Regis Houssin        <regis.houssin@capnetworks.com>
  *
- * This program is free software: you can redistribute it and/or modify
+ * 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
+ * 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,
@@ -13,309 +14,28 @@
  * 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/>.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
 /**
- * \defgroup    mymodule    MyModule module
- * \brief       MyModule module descriptor.
+ * 	\defgroup   mymodule     Module MyModule
+ *  \brief      MyModule module descriptor.
  *
- * Put detailed description here.
+ *  \file       htdocs/mymodule/core/modules/modMyModule.class.php
+ *  \ingroup    mymodule
+ *  \brief      Description and activation file for module MyModule
  */
+include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
 
-/**
- * \file        core/modules/modMyModule.class.php
- * \ingroup     mymodule
- * \brief       Example module description and activation file.
- *
- * Put detailed description here.
- */
-
-include_once DOL_DOCUMENT_ROOT . "/core/modules/DolibarrModules.class.php";
 
 // The class name should start with a lower case mod for Dolibarr to pick it up
 // so we ignore the Squiz.Classes.ValidClassName.NotCamelCaps rule.
 // @codingStandardsIgnoreStart
 /**
- * Description and activation class for module MyModule
+ *  Description and activation class for module MyModule
  */
 class modMyModule extends DolibarrModules
 {
-	/** @var DoliDB Database handler */
-	public $db;
-
-	/**
-	 * @var int numero Module unique ID
-	 * @see http://wiki.dolibarr.org/index.php/List_of_modules_id Available ranges
-	 */
-	public $numero = 500000;
-
-	/** @var string Text key to reference module (for permissions, menus, etc.) */
-	public $rights_class = 'mymodule';
-
-	/**
-	 * @var string Module family.
-	 * Used to group modules in module setup page.
-	 * Can be one of 'crm', 'financial', 'hr', 'projects', 'products', 'ecm', 'technic', 'other'
-	 */
-	public $family = 'other';
-
-	/** @var int Module position in the family */
-	public $module_position = 500;
-
-	/** @var array Provide a custom family and options */
-	public $familyinfo = array(
-//        'myownfamily' => array(
-//            'position' => '001',
-//            'label' => 'MyOwnFamily'
-//        )
-	);
-
-	/** @var string Module name */
-	public $name = "My Module";
-
-	/** @var string Module short description */
-	public $description = "Description of module MyModule";
-
-	/** @var string Module long description */
-	public $descriptionlong = "A very long description. Can be a full HTML content";
-
-	/**
-	 * @var string Module editor name
-	 * @since 4.0
-	 */
-	public $editor_name = "My Company";
-
-	/**
-	 * @var string Module editor website
-	 * @since 4.0
-	 */
-	public $editor_url = "http://www.example.com";
-
-	/**
-	 * @var string Module version string
-	 * Special values to hide the module behind MAIN_FEATURES_LEVEL: development, experimental
-	 * @see https://semver.org
-	 */
-	public $version = 'development';
-
-	/** @var string Key used in llx_const table to save module status enabled/disabled */
-	public $const_name = 'MAIN_MODULE_MYMODULE';
-
-	/**
-	 * @var string Module logo
-	 * Should be named object_mymodule.png and store under mymodule/img
-	 */
-	public $picto = 'mymodule@mymodule';
-
-	/** @var array Define module parts */
-	public $module_parts = array(
-		/** @var bool Module ships triggers in mymodule/core/triggers */
-		'triggers' => true,
-		/**
-		 * @var bool Module ships login in mymodule/core/login
-		 * @todo: example
-		 */
-		'login' => false,
-		/**
-		 * @var bool Module ships substitution functions
-		 * @todo example
-		 */
-		'substitutions' => false,
-		/**
-		 * @var bool Module ships menu handlers
-		 * @todo example
-		 */
-		'menus' => false,
-		/**
-		 * @var bool Module ships theme in mymodule/theme
-		 * @todo example
-		 */
-		'theme' => false,
-		/**
-		 * @var bool Module shipped templates in mymodule/core/tpl overload core ones
-		 * @todo example
-		 */
-		'tpl' => false,
-		/**
-		 * @var bool Module ships barcode functions
-		 * @todo example
-		 */
-		'barcode' => false,
-		/**
-		 * @var bool Module ships models
-		 * @todo example
-		 */
-		'models' => false,
-		/** @var string[] List of module shipped custom CSS relative file paths */
-		'css' => array(
-			'mymodule/css/mycss.css.php'
-		),
-		/** @var string[] List of module shipped custom JavaScript relative file paths */
-		'js' => array(
-			'mymodule/js/myjs.js.php'
-		),
-		/**
-		 * @var string[] List of hook contexts managed by the module
-		 * @ todo example
-		 */
-		'hooks' => array(),
-		/**
-		 * @var array List of default directory names to force
-		 * @todo example
-		 */
-		'dir' => array(),
-		/**
-		 * @var array List of workflow contexts managed by the module
-		 */
-		'workflow' => array(),
-	);
-
-	/** @var string Data directories to create when module is enabled */
-	public $dirs = array(
-		'/mymodule/temp'
-	);
-
-	/** @var array Configuration page declaration */
-	public $config_page_url = 'setup.php@mymodule';
-
-	/** @var bool Control module visibility */
-	public $hidden = false;
-
-	/** @var string[] List of class names of modules to enable when this one is enabled */
-	public $depends = array();
-
-	/** @var string[] List of class names of modules to disable when this one is disabled */
-	public $requiredby = array();
-
-	/** @var string List of class names of modules this module conflicts with */
-	public $conflictwith = array();
-
-	/** @var int[] Minimum PHP version required by this module */
-	public $phpmin = array(5, 3);
-
-	/** @var int[] Minimum Dolibarr version required by this module */
-	public $need_dolibarr_version = array(3, 2);
-
-	/** @var string[] List of language files */
-	public $langfiles = array('mymodule@mymodule');
-
-	/** @var array Indexed list of constants options */
-	public $const = array(
-		0 => array(
-			/** @var string Constant name */
-			'MYMODULE_MYNEWCONST1',
-			/**
-			 * @var string Constant type
-			 * @todo Are there other types than 'chaine'?
-			 */
-			'chaine',
-			/** @var string Constant initial value */
-			'myvalue',
-			/** @var string Constant description */
-			'This is a configuration constant',
-			/** @var bool Constant visibility */
-			true,
-			/**
-			 * @var string Multi-company entities
-			 * 'current' or 'allentities'
-			 */
-			'current',
-			/** @var bool Delete constant when module is disabled */
-			true
-		)
-	);
-
-	/**
-	 * @var string List of pages to add as tab in a specific view
-	 * @todo example
-	 */
-	public $tabs = array();
-
-	/**
-	 * @var array Dictionaries declared by the module
-	 *@todo example
-	 */
-	public $dictionaries = array();
-
-	/** @var array Indexed list of boxes options */
-	public $boxes = array(
-		0 => array(
-			'file' => 'mybox@mymodule',
-			'note' => '',
-			'enabledbydefaulton' => 'Home'
-		)
-	);
-
-	/**
-	 * @var array Indexed list of cronjobs options
-	 * @todo: example
-	 */
-	public $cronjobs = array();
-
-	/**
-	 * @var array Indexed list of permissions options
-	 * @todo example
-	 */
-	public $rights = array();
-
-	/**
-	 * @var array Indexed list of menu options
-	 * @todo example
-	 */
-	public $menu = array();
-
-	/**
-	 * @var array Indexed list of export IDs
-	 * @todo example
-	 */
-	public $export_code = array();
-
-	/**
-	 * @var array Indexed list of export names
-	 * @todo example
-	 */
-	public $export_label = array();
-
-	/**
-	 * @var array Indexed list of export enabling conditions
-	 * @todo example
-	 */
-	public $export_enabled = array();
-
-	/**
-	 * @var array Indexed list of export required permissions
-	 * @todo example
-	 */
-	public $export_permission = array();
-
-	/**
-	 * @var array Indexed list of export fields
-	 * @todo example
-	 */
-	public $export_fields_array = array();
-
-	/**
-	 * @var array Indexed list of export entities
-	 * @todo example
-	 */
-	public $export_entities_array = array();
-
-	/**
-	 * @var array Indexed list of export SQL queries start
-	 * @todo example
-	 */
-	public $export_sql_start = array();
-
-	/**
-	 * @var array Indexed list of export SQL queries end
-	 * @todo example
-	 */
-	public $export_sql_end = array();
-
-	/** @var bool Module only enabled / disabled in main company when multi-company is in use */
-	public $core_enabled = false;
-
 	// @codingStandardsIgnoreEnd
 	/**
 	 * Constructor. Define names, constants, directories, boxes, permissions
@@ -324,61 +44,90 @@ class modMyModule extends DolibarrModules
 	 */
 	public function __construct($db)
 	{
-		global $langs, $conf;
-
-		// DolibarrModules is abstract in Dolibarr < 3.8
-		if (is_callable('parent::__construct')) {
-			parent::__construct($db);
-		} else {
-			global $db;
-			$this->db = $db;
-		}
-
-		// Declare custom family with translated label
-		//$this->familyinfo = array(
-		//	'myownfamily' => array(
-		//		'position' => '001',
-		//		'label' => $langs->trans("MyOwnFamily")
-		//	)
-		//);
-
-		// Lazy automatic module naming from class names
-		//$this->name = preg_replace('/^mod/i', '', get_class($this));
-
-		// Lazy automatic constant naming from module name
-		//$this->const_name = 'MAIN_MODULE_' . strtoupper($this->name);
-
-		// Examples for complex types
+        global $langs,$conf;
+
+        $this->db = $db;
+
+		// Id for module (must be unique).
+		// Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
+		$this->numero = 500000;		// TODO Go on page http://wiki.dolibarr.org/index.php/List_of_modules_id to reserve id number for your module
+		// Key text used to identify module (for permissions, menus, etc...)
+		$this->rights_class = 'mymodule';
+
+		// Family can be 'crm','financial','hr','projects','products','ecm','technic','interface','other'
+		// It is used to group modules by family in module setup page
+		$this->family = "other";
+		// Module position in the family
+		$this->module_position = 500;
+		// Gives the possibility to the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this)
+		//$this->familyinfo = array('myownfamily' => array('position' => '001', 'label' => $langs->trans("MyOwnFamily")));
+
+		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
+		$this->name = preg_replace('/^mod/i','',get_class($this));
+		// Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
+		$this->description = "MyModuleDescription";
+		$this->descriptionlong = "MyModuleDescription (Long)";
+		$this->editor_name = 'Editor name';
+		$this->editor_url = 'https://www.example.com';
+		
+		// Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z'
+		$this->version = '1.0';
+		// Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
+		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
+		// Name of image file used for this module.
+		// If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
+		// If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
+		$this->picto='generic';
+
+		// Defined all module parts (triggers, login, substitutions, menus, css, etc...)
+		// for default path (eg: /mymodule/core/xxxxx) (0=disable, 1=enable)
+		// for specific path of parts (eg: /mymodule/core/modules/barcode)
+		// for specific css file (eg: /mymodule/css/mymodule.css.php)
 		//$this->module_parts = array(
-			// Set here all hooks context managed by module
-			// 'hooks' => array('hookcontext1','hookcontext2'),
-			// To force the default directories names
-			// 'dir' => array('output' => 'othermodulename'),
-			// Set here all workflow context managed by module
-			// Don't forget to depend on modWorkflow!
-			// The description translation key will be descWORKFLOW_MODULE1_YOURACTIONTYPE_MODULE2
-			// You will be able to check if it is enabled with the $conf->global->WORKFLOW_MODULE1_YOURACTIONTYPE_MODULE2 constant
-			// Implementation is up to you and is usually done in a trigger.
-			// 'workflow' => array(
-			//     'WORKFLOW_MODULE1_YOURACTIONTYPE_MODULE2' => array(
-			//         'enabled' => '! empty($conf->module1->enabled) && ! empty($conf->module2->enabled)',
-			//         'picto' => 'yourpicto@mymodule',
-			//         'warning' => 'WarningTextTranslationKey',
-			//      ),
-			// ),
-		//);
-
+		//                        	'triggers' => 0,                                 	// Set this to 1 if module has its own trigger directory (core/triggers)
+		//							'login' => 0,                                    	// Set this to 1 if module has its own login method directory (core/login)
+		//							'substitutions' => 0,                            	// Set this to 1 if module has its own substitution function file (core/substitutions)
+		//							'menus' => 0,                                    	// Set this to 1 if module has its own menus handler directory (core/menus)
+		//							'theme' => 0,                                    	// Set this to 1 if module has its own theme directory (theme)
+		//                        	'tpl' => 0,                                      	// Set this to 1 if module overwrite template dir (core/tpl)
+		//							'barcode' => 0,                                  	// Set this to 1 if module has its own barcode directory (core/modules/barcode)
+		//							'models' => 0,                                   	// Set this to 1 if module has its own models directory (core/modules/xxx)
+		//							'css' => array('/mymodule/css/mymodule.css.php'),	// Set this to relative path of css file if module has its own css file
+	 	//							'js' => array('/mymodule/js/mymodule.js'),          // Set this to relative path of js file if module must load a js on all pages
+		//							'hooks' => array('hookcontext1','hookcontext2',...) // Set here all hooks context managed by module. You can also set hook context 'all'
+		//							'dir' => array('output' => 'othermodulename'),      // To force the default directories names
+		//							'workflow' => array('WORKFLOW_MODULE1_YOURACTIONTYPE_MODULE2'=>array('enabled'=>'! empty($conf->module1->enabled) && ! empty($conf->module2->enabled)', 'picto'=>'yourpicto@mymodule')) // Set here all workflow context managed by module
+		//                        );
+		$this->module_parts = array();
+
+		// Data directories to create when module is enabled.
+		// Example: this->dirs = array("/mymodule/temp");
+		$this->dirs = array();
+
+		// Config pages. Put here list of php page, stored into mymodule/admin directory, to use to setup module.
+		$this->config_page_url = array("setup.php@mymodule");
+
+		// Dependencies
+		$this->hidden = false;			// A condition to hide module
+		$this->depends = array();		// List of module class names as string that must be enabled if this module is enabled
+		$this->requiredby = array();	// List of module ids to disable if this one is disabled
+		$this->conflictwith = array();	// List of module class names as string this module is in conflict with
+		$this->phpmin = array(5,0);					// Minimum version of PHP required by module
+		$this->need_dolibarr_version = array(3,0);	// Minimum version of Dolibarr required by module
+		$this->langfiles = array("mymodule@mymodule");
+
+		// Constants
+		// List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
+		// Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
+		//                             1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1)
+		// );
+		$this->const = array();
 
 		// Array to add new pages in new tabs
-		// Example:
-		//$this->tabs = array(
-			//	// To add a new tab identified by code tabname1
-			//	'objecttype:+tabname1:Title1:langfile@mymodule:$user->rights->mymodule->read:/mymodule/mynewtab1.php?id=__ID__',
-			//	// To add another new tab identified by code tabname2
-			//	'objecttype:+tabname2:Title2:langfile@mymodule:$user->rights->othermodule->read:/mymodule/mynewtab2.php?id=__ID__',
-			//	// To remove an existing tab identified by code tabname
-			//	'objecttype:-tabname'
-		//);
+		// Example: $this->tabs = array('objecttype:+tabname1:Title1:mylangfile@mymodule:$user->rights->mymodule->read:/mymodule/mynewtab1.php?id=__ID__',  					// To add a new tab identified by code tabname1
+        //                              'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@mymodule:$user->rights->othermodule->read:/mymodule/mynewtab2.php?id=__ID__',  	// To add another new tab identified by code tabname2. Label will be result of calling all substitution functions on 'Title2' key.
+        //                              'objecttype:-tabname:NU:conditiontoremove');                                                     										// To remove an existing tab identified by code tabname
+		// where objecttype can be
 		// 'categories_x'	  to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
 		// 'contact'          to add a tab in contact view
 		// 'contract'         to add a tab in contract view
@@ -398,317 +147,142 @@ class modMyModule extends DolibarrModules
 		// 'stock'            to add a tab in stock view
 		// 'thirdparty'       to add a tab in third party view
 		// 'user'             to add a tab in user view
-
-		// Dictionaries
-		if (! isset($conf->mymodule->enabled)) {
-			$conf->mymodule=new stdClass();
-			$conf->mymodule->enabled = 0;
-		}
-		//$this->dictionaries = array();
-		/* Example:
-		  $this->dictionaries=array(
-			  'langs'=>'mymodule@mymodule',
-			  // List of tables we want to see into dictonary editor
-			  'tabname'=>array(
-				  MAIN_DB_PREFIX."table1",
-				  MAIN_DB_PREFIX."table2",
-				  MAIN_DB_PREFIX."table3"
-			  ),
-			  // Label of tables
-			  'tablib'=>array("Table1","Table2","Table3"),
-			  // Query to select fields
-			  'tabsql'=>array(
-				  'SELECT f.rowid as rowid, f.code, f.label, f.active'
-				  . ' FROM ' . MAIN_DB_PREFIX . 'table1 as f',
-				  'SELECT f.rowid as rowid, f.code, f.label, f.active'
-				  . ' FROM ' . MAIN_DB_PREFIX . 'table2 as f',
-				  'SELECT f.rowid as rowid, f.code, f.label, f.active'
-				  . ' FROM ' . MAIN_DB_PREFIX . 'table3 as f'
-			  ),
-			  // Sort order
-			  'tabsqlsort'=>array("label ASC","label ASC","label ASC"),
-			  // List of fields (result of select to show dictionary)
-			  'tabfield'=>array("code,label","code,label","code,label"),
-			  // List of fields (list of fields to edit a record)
-			  'tabfieldvalue'=>array("code,label","code,label","code,label"),
-			  // List of fields (list of fields for insert)
-			  'tabfieldinsert'=>array("code,label","code,label","code,label"),
-			  // Name of columns with primary key (try to always name it 'rowid')
-			  'tabrowid'=>array("rowid","rowid","rowid"),
-			  // Condition to show each dictionary
-			  'tabcond'=>array(
-				  $conf->mymodule->enabled,
-				  $conf->mymodule->enabled,
-				  $conf->mymodule->enabled
-			  )
-		  );
-		 */
+        $this->tabs = array();
+
+		if (! isset($conf->mymodule) || ! isset($conf->mymodule->enabled))
+        {
+        	$conf->mymodule=new stdClass();
+        	$conf->mymodule->enabled=0;
+        }
+        
+        // Dictionaries
+		$this->dictionaries=array();
+        /* Example:
+        $this->dictionaries=array(
+            'langs'=>'mylangfile@mymodule',
+            'tabname'=>array(MAIN_DB_PREFIX."table1",MAIN_DB_PREFIX."table2",MAIN_DB_PREFIX."table3"),		// List of tables we want to see into dictonnary editor
+            'tablib'=>array("Table1","Table2","Table3"),													// Label of tables
+            'tabsql'=>array('SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table1 as f','SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table2 as f','SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table3 as f'),	// Request to select fields
+            'tabsqlsort'=>array("label ASC","label ASC","label ASC"),																					// Sort order
+            'tabfield'=>array("code,label","code,label","code,label"),																					// List of fields (result of select to show dictionary)
+            'tabfieldvalue'=>array("code,label","code,label","code,label"),																				// List of fields (list of fields to edit a record)
+            'tabfieldinsert'=>array("code,label","code,label","code,label"),																			// List of fields (list of fields for insert)
+            'tabrowid'=>array("rowid","rowid","rowid"),																									// Name of columns with primary key (try to always name it 'rowid')
+            'tabcond'=>array($conf->mymodule->enabled,$conf->mymodule->enabled,$conf->mymodule->enabled)												// Condition to show each dictionary
+        );
+        */
+
+        // Boxes
+		// Add here list of php file(s) stored in core/boxes that contains class to show a box.
+        $this->boxes = array();			// List of boxes
+		// Example:
+		//$this->boxes=array(
+		//    0=>array('file'=>'myboxa.php@mymodule','note'=>'','enabledbydefaulton'=>'Home'),
+		//    1=>array('file'=>'myboxb.php@mymodule','note'=>''),
+		//    2=>array('file'=>'myboxc.php@mymodule','note'=>'')
+		//);
 
 		// Cronjobs
-		// List of cron jobs entries to add
-		//$this->cronjobs = array();
-		// Example:
-		//		$this->cronjobs = array(
-		//			0 => array(
-		//				'label' => 'My label',
-		//				'jobtype' => 'method',
-		//				'class' => '/dir/class/file.class.php',
-		//				'objectname' => 'MyClass',
-		//				'method' => 'myMethod',
-		//				'parameters' => '',
-		//				'comment' => 'Comment',
-		//				'frequency' => 2,
-		//				'unitfrequency' => 3600,
-		//				'test' => true
-		//			),
-		//			1 => array(
-		//				'label' => 'My label',
-		//				'jobtype' => 'command',
-		//				'command' => '',
-		//				'parameters' => '',
-		//				'comment' => 'Comment',
-		//				'frequency' => 1,
-		//				'unitfrequency' => 3600 * 24,
-		//				'test' => true
-		//			)
-		//		);
+		$this->cronjobs = array();			// List of cron jobs entries to add
+		// Example: $this->cronjobs=array(0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'/dir/class/file.class.php', 'objectname'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>2, 'unitfrequency'=>3600, 'test'=>true),
+		//                                1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24, 'test'=>true)
+		// );
 
 		// Permissions
-		//$r = 0;
-		// Add here list of permission defined by
-		// an id, a label, a boolean and two constant strings.
+		$this->rights = array();		// Permission array used by this module
+		$r=0;
+
+		// Add here list of permission defined by an id, a label, a boolean and two constant strings.
 		// Example:
-		//// Permission id (must not be already used)
-		//$this->rights[$r][0] = 2000;
-		//// Permission label
-		//$this->rights[$r][1] = 'Permision label';
-		//// Permission by default for new user (0/1)
-		//$this->rights[$r][3] = 1;
-		//// In php code, permission will be checked by test
-		//// if ($user->rights->permkey->level1->level2)
-		//$this->rights[$r][4] = 'level1';
-		//// In php code, permission will be checked by test
-		//// if ($user->rights->permkey->level1->level2)
-		//$this->rights[$r][5] = 'level2';
-		//$r++;
+		// $this->rights[$r][0] = $this->numero + $r;	// Permission id (must not be already used)
+		// $this->rights[$r][1] = 'Permision label';	// Permission label
+		// $this->rights[$r][3] = 1; 					// Permission by default for new user (0/1)
+		// $this->rights[$r][4] = 'level1';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
+		// $this->rights[$r][5] = 'level2';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
+		// $r++;
+
 		// Main menu entries
+		$this->menu = array();			// List of menus to add
+		$r=0;
 
-		// Menu entries
+		// Add here entries to declare new menus
+		//
 		// Example to declare a new Top Menu entry and its Left menu entry:
-		//$this->menu[]=array(
-		//	// Put 0 if this is a top menu
-		//	'fk_menu'=>0,
-		//	// This is a Top menu entry
-		//	'type'=>'top',
-		// Menu's title. FIXME: use a translation key
-		//	'titre'=>'MyModule top menu',
-		// This menu's mainmenu ID
-		//	'mainmenu'=>'mymodule',
-		// This menu's leftmenu ID
-		//	'leftmenu'=>'mymodule',
-		//	'url'=>'/mymodule/pagetop.php',
-		//	// Lang file to use (without .lang) by module.
-		//	// File must be in langs/code_CODE/ directory.
-		//	'langs'=>'mylangfile',
-		//	'position'=>100,
-		//	// Define condition to show or hide menu entry.
-		//	// Use '$conf->mymodule->enabled' if entry must be visible if module is enabled.
-		//	'enabled'=>'$conf->mymodule->enabled',
-		//	// Use 'perms'=>'$user->rights->mymodule->level1->level2'
-		//	// if you want your menu with a permission rules
-		//	'perms'=>'1',
-		//	'target'=>'',
-		//	// 0=Menu for internal users, 1=external users, 2=both
-		//	'user'=>2
-		//);
-		//$this->menu[]=array(
-		//	// Use r=value where r is index key used for the parent menu entry
-		//	// (higher parent must be a top menu entry)
-		//	'fk_menu'=>'r=0',
-		//	// This is a Left menu entry
-		//	'type'=>'left',
-		// Menu's title. FIXME: use a translation key
-		//	'titre'=>'MyModule left menu',
-		// This menu's mainmenu ID
-		//	'mainmenu'=>'mymodule',
-		// This menu's leftmenu ID
-		//	'leftmenu'=>'mymodule',
-		//	'url'=>'/mymodule/pagelevel1.php',
-		//	// Lang file to use (without .lang) by module.
-		//	// File must be in langs/code_CODE/ directory.
-		//	'langs'=>'mylangfile',
-		//	'position'=>100,
-		//	// Define condition to show or hide menu entry.
-		//	// Use '$conf->mymodule->enabled' if entry must be visible if module is enabled.
-		//	'enabled'=>'$conf->mymodule->enabled',
-		//	// Use 'perms'=>'$user->rights->mymodule->level1->level2'
-		//	// if you want your menu with a permission rules
-		//	'perms'=>'1',
-		//	'target'=>'',
-		//	// 0=Menu for internal users, 1=external users, 2=both
-		//	'user'=>2
-		//);
+		// $this->menu[$r]=array(	'fk_menu'=>'',			                // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
+		//							'type'=>'top',			                // This is a Top menu entry
+		//							'titre'=>'MyModule top menu',
+		//							'mainmenu'=>'mymodule',
+		//							'leftmenu'=>'mymodule',
+		//							'url'=>'/mymodule/pagetop.php',
+		//							'langs'=>'mylangfile@mymodule',	        // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
+		//							'position'=>100,
+		//							'enabled'=>'$conf->mymodule->enabled',	// Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled.
+		//							'perms'=>'1',			                // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
+		//							'target'=>'',
+		//							'user'=>2);				                // 0=Menu for internal users, 1=external users, 2=both
+		// $r++;
 		//
 		// Example to declare a Left Menu entry into an existing Top menu entry:
-		//$this->menu[]=array(
-		//	// Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy'
-		//	'fk_menu'=>'fk_mainmenu=mainmenucode',
-		//	// This is a Left menu entry
-		//	'type'=>'left',
-		// Menu's title. FIXME: use a translation key
-		//	'titre'=>'MyModule left menu',
-		// This menu's mainmenu ID
-		//	'mainmenu'=>'mainmenucode',
-		// This menu's leftmenu ID
-		//	'leftmenu'=>'mymodule',
-		//	'url'=>'/mymodule/pagelevel2.php',
-		//	// Lang file to use (without .lang) by module.
-		//	// File must be in langs/code_CODE/ directory.
-		//	'langs'=>'mylangfile',
-		//	'position'=>100,
-		//	// Define condition to show or hide menu entry.
-		//	// Use '$conf->mymodule->enabled' if entry must be visible if module is enabled.
-		//	// Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
-		//	'enabled'=>'$conf->mymodule->enabled',
-		//	// Use 'perms'=>'$user->rights->mymodule->level1->level2'
-		//	// if you want your menu with a permission rules
-		//	'perms'=>'1',
-		//	'target'=>'',
-		//	// 0=Menu for internal users, 1=external users, 2=both
-		//	'user'=>2
-		//);
+		// $this->menu[$r]=array(	'fk_menu'=>'fk_mainmenu=xxx',		    // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
+		//							'type'=>'left',			                // This is a Left menu entry
+		//							'titre'=>'MyModule left menu',
+		//							'mainmenu'=>'xxx',
+		//							'leftmenu'=>'mymodule',
+		//							'url'=>'/mymodule/pagelevel2.php',
+		//							'langs'=>'mylangfile@mymodule',	        // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
+		//							'position'=>100,
+		//							'enabled'=>'$conf->mymodule->enabled',  // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
+		//							'perms'=>'1',			                // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
+		//							'target'=>'',
+		//							'user'=>2);				                // 0=Menu for internal users, 1=external users, 2=both
+		// $r++;
+
 
 		// Exports
-		//$r = 0;
+		$r=1;
+
 		// Example:
-		//$this->export_code[$r]=$this->rights_class.'_'.$r;
-		//// Translation key (used only if key ExportDataset_xxx_z not found)
-		//$this->export_label[$r]='CustomersInvoicesAndInvoiceLines';
-		//// Condition to show export in list (ie: '$user->id==3').
-		//// Set to 1 to always show when module is enabled.
-		//$this->export_enabled[$r]='1';
-		//$this->export_permission[$r]=array(array("facture","facture","export"));
-		//$this->export_fields_array[$r]=array(
-		//	's.rowid'=>"IdCompany",
-		//	's.nom'=>'CompanyName',
-		//	's.address'=>'Address',
-		//	's.cp'=>'Zip',
-		//	's.ville'=>'Town',
-		//	's.fk_pays'=>'Country',
-		//	's.tel'=>'Phone',
-		//	's.siren'=>'ProfId1',
-		//	's.siret'=>'ProfId2',
-		//	's.ape'=>'ProfId3',
-		//	's.idprof4'=>'ProfId4',
-		//	's.code_compta'=>'CustomerAccountancyCode',
-		//	's.code_compta_fournisseur'=>'SupplierAccountancyCode',
-		//	'f.rowid'=>"InvoiceId",
-		//	'f.facnumber'=>"InvoiceRef",
-		//	'f.datec'=>"InvoiceDateCreation",
-		//	'f.datef'=>"DateInvoice",
-		//	'f.total'=>"TotalHT",
-		//	'f.total_ttc'=>"TotalTTC",
-		//	'f.tva'=>"TotalVAT",
-		//	'f.paye'=>"InvoicePaid",
-		//	'f.fk_statut'=>'InvoiceStatus',
-		//	'f.note'=>"InvoiceNote",
-		//	'fd.rowid'=>'LineId',
-		//	'fd.description'=>"LineDescription",
-		//	'fd.price'=>"LineUnitPrice",
-		//	'fd.tva_tx'=>"LineVATRate",
-		//	'fd.qty'=>"LineQty",
-		//	'fd.total_ht'=>"LineTotalHT",
-		//	'fd.total_tva'=>"LineTotalTVA",
-		//	'fd.total_ttc'=>"LineTotalTTC",
-		//	'fd.date_start'=>"DateStart",
-		//	'fd.date_end'=>"DateEnd",
-		//	'fd.fk_product'=>'ProductId',
-		//	'p.ref'=>'ProductRef'
-		//);
-		//$this->export_entities_array[$r]=array('s.rowid'=>"company",
-		//	's.nom'=>'company',
-		//	's.address'=>'company',
-		//	's.cp'=>'company',
-		//	's.ville'=>'company',
-		//	's.fk_pays'=>'company',
-		//	's.tel'=>'company',
-		//	's.siren'=>'company',
-		//	's.siret'=>'company',
-		//	's.ape'=>'company',
-		//	's.idprof4'=>'company',
-		//	's.code_compta'=>'company',
-		//	's.code_compta_fournisseur'=>'company',
-		//	'f.rowid'=>"invoice",
-		//	'f.facnumber'=>"invoice",
-		//	'f.datec'=>"invoice",
-		//	'f.datef'=>"invoice",
-		//	'f.total'=>"invoice",
-		//	'f.total_ttc'=>"invoice",
-		//	'f.tva'=>"invoice",
-		//	'f.paye'=>"invoice",
-		//	'f.fk_statut'=>'invoice',
-		//	'f.note'=>"invoice",
-		//	'fd.rowid'=>'invoice_line',
-		//	'fd.description'=>"invoice_line",
-		//	'fd.price'=>"invoice_line",
-		//	'fd.total_ht'=>"invoice_line",
-		//	'fd.total_tva'=>"invoice_line",
-		//	'fd.total_ttc'=>"invoice_line",
-		//	'fd.tva_tx'=>"invoice_line",
-		//	'fd.qty'=>"invoice_line",
-		//	'fd.date_start'=>"invoice_line",
-		//	'fd.date_end'=>"invoice_line",
-		//	'fd.fk_product'=>'product',
-		//	'p.ref'=>'product'
-		//);
-		//$this->export_sql_start[$r] = 'SELECT DISTINCT ';
-		//$this->export_sql_end[$r] = ' FROM (' . MAIN_DB_PREFIX . 'facture as f, '
-		//	. MAIN_DB_PREFIX . 'facturedet as fd, ' . MAIN_DB_PREFIX . 'societe as s)';
-		//$this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX
-		//	. 'product as p on (fd.fk_product = p.rowid)';
-		//$this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid '
-		//	. 'AND f.rowid = fd.fk_facture';
-		//$r++;
+		// $this->export_code[$r]=$this->rights_class.'_'.$r;
+		// $this->export_label[$r]='MyModule';	// Translation key (used only if key ExportDataset_xxx_z not found)
+        // $this->export_enabled[$r]='1';                               // Condition to show export in list (ie: '$user->id==3'). Set to 1 to always show when module is enabled.
+        // $this->export_icon[$r]='generic:MyModule';					// Put here code of icon then string for translation key of module name
+		// $this->export_permission[$r]=array(array("mymodule","level1","level2"));
+		// $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','s.fk_pays'=>'Country','s.phone'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode','s.code_compta_fournisseur'=>'SupplierAccountancyCode','f.rowid'=>"InvoiceId",'f.facnumber'=>"InvoiceRef",'f.datec'=>"InvoiceDateCreation",'f.datef'=>"DateInvoice",'f.total'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus','f.note'=>"InvoiceNote",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.price'=>"LineUnitPrice",'fd.tva_tx'=>"LineVATRate",'fd.qty'=>"LineQty",'fd.total_ht'=>"LineTotalHT",'fd.total_tva'=>"LineTotalTVA",'fd.total_ttc'=>"LineTotalTTC",'fd.date_start'=>"DateStart",'fd.date_end'=>"DateEnd",'fd.fk_product'=>'ProductId','p.ref'=>'ProductRef');
+		// $this->export_TypeFields_array[$r]=array('t.date'=>'Date', 't.qte'=>'Numeric', 't.poids'=>'Numeric', 't.fad'=>'Numeric', 't.paq'=>'Numeric', 't.stockage'=>'Numeric', 't.fadparliv'=>'Numeric', 't.livau100'=>'Numeric', 't.forfait'=>'Numeric', 's.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.code_compta'=>'Text','s.code_compta_fournisseur'=>'Text','s.tva_intra'=>'Text','f.facnumber'=>"Text",'f.datec'=>"Date",'f.datef'=>"Date",'f.date_lim_reglement'=>"Date",'f.total'=>"Numeric",'f.total_ttc'=>"Numeric",'f.tva'=>"Numeric",'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_private'=>"Text",'f.note_public'=>"Text",'fd.description'=>"Text",'fd.subprice'=>"Numeric",'fd.tva_tx'=>"Numeric",'fd.qty'=>"Numeric",'fd.total_ht'=>"Numeric",'fd.total_tva'=>"Numeric",'fd.total_ttc'=>"Numeric",'fd.date_start'=>"Date",'fd.date_end'=>"Date",'fd.special_code'=>'Numeric','fd.product_type'=>"Numeric",'fd.fk_product'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text','p.accountancy_code_sell'=>'Text');
+		// $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','s.fk_pays'=>'company','s.phone'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company','f.rowid'=>"invoice",'f.facnumber'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total'=>"invoice",'f.total_ttc'=>"invoice",'f.tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line",'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line",'fd.fk_product'=>'product','p.ref'=>'product');
+		// $this->export_dependencies_array[$r]=array('invoice_line'=>'fd.rowid','product'=>'fd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
+		// $this->export_sql_start[$r]='SELECT DISTINCT ';
+		// $this->export_sql_end[$r]  =' FROM ('.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'facturedet as fd, '.MAIN_DB_PREFIX.'societe as s)';
+		// $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
+		// $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture';
+		// $this->export_sql_order[$r] .=' ORDER BY s.nom';
+		// $r++;
 	}
 
 	/**
-	 * Function called when module is enabled.
-	 * The init function add constants, boxes, permissions and menus
-	 * (defined in constructor) into Dolibarr database.
-	 * It also creates data directories
+	 *		Function called when module is enabled.
+	 *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
+	 *		It also creates data directories
 	 *
-	 * @param string $options Options when enabling module ('', 'noboxes')
-	 * @return int 1 if OK, 0 if KO
+     *      @param      string	$options    Options when enabling module ('', 'noboxes')
+	 *      @return     int             	1 if OK, 0 if KO
 	 */
-	public function init($options = '')
+	public function init($options='')
 	{
 		$sql = array();
 
-		$result = $this->loadTables();
+		$this->_load_tables('/mymodule/sql/');
 
 		return $this->_init($sql, $options);
 	}
 
-	/**
-	 * Create tables, keys and data required by module
-	 * Files llx_table1.sql, llx_table1.key.sql llx_data.sql with create table, create keys
-	 * and create data commands must be stored in directory /mymodule/sql/
-	 * This function is called by this->init
-	 *
-	 * @return int <=0 if KO, >0 if OK
-	 */
-	private function loadTables()
-	{
-		return $this->_load_tables('/mymodule/sql/');
-	}
-
 	/**
 	 * Function called when module is disabled.
 	 * Remove from database constants, boxes and permissions from Dolibarr database.
 	 * Data directories are not deleted
 	 *
-	 * @param string $options Options when enabling module ('', 'noboxes')
-	 * @return int 1 if OK, 0 if KO
+	 * @param      string	$options    Options when enabling module ('', 'noboxes')
+	 * @return     int             	1 if OK, 0 if KO
 	 */
 	public function remove($options = '')
 	{
@@ -716,4 +290,5 @@ class modMyModule extends DolibarrModules
 
 		return $this->_remove($sql, $options);
 	}
+
 }

+ 13 - 56
htdocs/modulebuilder/template/core/triggers/interface_99_modMyModule_MyTrigger.class.php → htdocs/modulebuilder/template/core/triggers/interface_99_modMyModule_Triggers.class.php

@@ -17,7 +17,7 @@
  */
 
 /**
- * \file    core/triggers/interface_99_modMyModule_MyTrigger.class.php
+ * \file    core/triggers/interface_99_modMyModule_Triggers.class.php
  * \ingroup mymodule
  * \brief   Example trigger.
  *
@@ -30,17 +30,16 @@
  * - The file must stay in core/triggers
  * - The class name must be InterfaceMytrigger
  * - The constructor method must be named InterfaceMytrigger
- * - The name property name must be Mytrigger
+ * - The name property name must be MyTrigger
  */
 
-/** Includes */
-require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
-require_once DOL_DOCUMENT_ROOT . dol_buildpath('/mymodule/class/MyTrigger.php', 1);
+require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
+
 
 /**
- * Class InterfaceMytrigger
+ *  Class of triggers for MyModule module
  */
-class InterfaceMytrigger extends MyTrigger
+class InterfaceMyModuleTrigger extends DolibarrTriggers
 {
 	/**
 	 * @var DoliDB Database handler
@@ -58,9 +57,7 @@ class InterfaceMytrigger extends MyTrigger
 
 		$this->name = preg_replace('/^Interface/i', '', get_class($this));
 		$this->family = "demo";
-		$this->description = "Triggers of this module are empty functions."
-			. "They have no effect."
-			. "They are provided for tutorial purpose only.";
+		$this->description = "MyModule triggers.";
 		// 'development', 'experimental', 'dolibarr' or version
 		$this->version = 'development';
 		$this->picto = 'mymodule@mymodule';
@@ -86,58 +83,18 @@ class InterfaceMytrigger extends MyTrigger
 		return $this->description;
 	}
 
-	/**
-	 * Trigger version
-	 *
-	 * @return string Version of trigger file
-	 */
-	public function getVersion()
-	{
-		global $langs;
-		$langs->load("admin");
-
-		if ($this->version == 'development') {
-			return $langs->trans("Development");
-		} elseif ($this->version == 'experimental') {
-			return $langs->trans("Experimental");
-		} elseif ($this->version == 'dolibarr') {
-			return DOL_VERSION;
-		} elseif ($this->version) {
-			return $this->version;
-		} else {
-			return $langs->trans("Unknown");
-		}
-	}
-
-    // @codingStandardsIgnoreStart
-	/**
-	 * Compatibility trigger function for Dolibarr < 3.7
-	 *
-	 * @param int $action Trigger action
-	 * @param CommonObject $object Object trigged from
-	 * @param User $user User that trigged
-	 * @param Translate $langs Translations handler
-	 * @param Conf $conf Configuration
-	 * @return int                  <0 if KO, 0 if no triggered ran, >0 if OK
-	 * @deprecated Replaced by DolibarrTriggers::runTrigger()
-	 */
-	public function run_trigger($action, $object, $user, $langs, $conf)
-	{
-		return $this->runTrigger($action, $object, $user, $langs, $conf);
-	}
-	// @codingStandardsIgnoreEnd
 
 	/**
 	 * Function called when a Dolibarrr business event is done.
 	 * All functions "runTrigger" are triggered if file
 	 * is inside directory core/triggers
 	 *
-	 * @param string $action Event action code
-	 * @param CommonObject $object Object
-	 * @param User $user Object user
-	 * @param Translate $langs Object langs
-	 * @param Conf $conf Object conf
-	 * @return int              <0 if KO, 0 if no triggered ran, >0 if OK
+	 * @param string 		$action 	Event action code
+	 * @param CommonObject 	$object 	Object
+	 * @param User 			$user 		Object user
+	 * @param Translate 	$langs 		Object langs
+	 * @param Conf 			$conf 		Object conf
+	 * @return int              		<0 if KO, 0 if no triggered ran, >0 if OK
 	 */
 	public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
 	{

+ 0 - 0
htdocs/modulebuilder/template/img/object_mymodule.png → htdocs/modulebuilder/template/img/myobject_mymodule.png


+ 1 - 1
htdocs/modulebuilder/template/js/mymodule.js.php

@@ -17,7 +17,7 @@
  */
 
 /**
- * \file    js/mymodule.js.php
+ * \file    htdocs/modulebuilder/template/js/mymodule.js.php
  * \ingroup mymodule
  * \brief   Example JavaScript.
  *

+ 317 - 59
htdocs/modulebuilder/template/myobject_card.php

@@ -1,10 +1,10 @@
 <?php
-/* <one line to give the program's name and a brief idea of what it does.>
- * Copyright (C) <year>  <name of author>
+/* Copyright (C) 2007-2015 Laurent Destailleur  <eldy@users.sourceforge.net>
+ * Copyright (C) ---Put here your own copyright and developer email---
  *
- * This program is free software: you can redistribute it and/or modify
+ * 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
+ * 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,
@@ -13,21 +13,20 @@
  * 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/>.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
 /**
- * \file    myobject_list.php
- * \ingroup mymodule
- * \brief   Page with list of myobject.
- *
- * List of myobject
+ *   	\file       htdocs/modulebuilder/template/myobject_card.php
+ *		\ingroup    mymodule othermodule1 othermodule2
+ *		\brief      This file is an example of a php page
+ *					Put here some comments
  */
 
-//if (! defined('NOREQUIREUSER'))	define('NOREQUIREUSER','1');
-//if (! defined('NOREQUIREDB'))		define('NOREQUIREDB','1');
-//if (! defined('NOREQUIRESOC'))	define('NOREQUIRESOC','1');
-//if (! defined('NOREQUIRETRAN'))	define('NOREQUIRETRAN','1');
+//if (! defined('NOREQUIREUSER'))  define('NOREQUIREUSER','1');
+//if (! defined('NOREQUIREDB'))    define('NOREQUIREDB','1');
+//if (! defined('NOREQUIRESOC'))   define('NOREQUIRESOC','1');
+//if (! defined('NOREQUIRETRAN'))  define('NOREQUIRETRAN','1');
 //if (! defined('NOCSRFCHECK'))    define('NOCSRFCHECK','1');			// Do not check anti CSRF attack test
 //if (! defined('NOSTYLECHECK'))   define('NOSTYLECHECK','1');			// Do not check style html tag into posted data
 //if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1');		// Do not check anti POST attack test
@@ -36,28 +35,31 @@
 //if (! defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX','1');
 //if (! defined("NOLOGIN"))        define("NOLOGIN",'1');				// If this page is public (can be called outside logged session)
 
-// Change the following lines to use the correct relative path (../, ../../, etc)
-
-// Load Dolibarr environment
-if (false === (@include '../../main.inc.php')) {  // From htdocs directory
-	require '../../../main.inc.php'; // From "custom" directory
-}
-
-require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
-dol_include_once('/mymodule/class/myclass.class.php');
-
-// Load translation files required by the page
-$langs->load("mymodule@mymodule");
+// Change this following line to use the correct relative path (../, ../../, etc)
+$res=0;
+if (! $res && file_exists("../main.inc.php")) $res=@include '../main.inc.php';					// to work if your module directory is into dolibarr root htdocs directory
+if (! $res && file_exists("../../main.inc.php")) $res=@include '../../main.inc.php';			// to work if your module directory is into a subdir of root htdocs directory
+if (! $res && file_exists("../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../dolibarr/htdocs/main.inc.php';     // Used on dev env only
+if (! $res && file_exists("../../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../../dolibarr/htdocs/main.inc.php';   // Used on dev env only
+if (! $res) die("Include of main fails");
+// Change this following line to use the correct relative path from htdocs
+include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php');
+dol_include_once('/mymodule/class/myobject_class.class.php');
+
+// Load traductions files requiredby by page
+$langs->load("mymodule");
+$langs->load("other");
 
 // Get parameters
-$action     = GETPOST('action','alpha');
-$confirm    = GETPOST('confirm','alpha');
-
 $id			= GETPOST('id','int');
+$action		= GETPOST('action','alpha');
+$cancel     = GETPOST('cancel');
 $backtopage = GETPOST('backtopage');
-// TODO Add here list of search params
 $myparam	= GETPOST('myparam','alpha');
 
+$search_field1=GETPOST("search_field1");
+$search_field2=GETPOST("search_field2");
+
 if (empty($action) && empty($id) && empty($ref)) $action='view';
 
 // Protection if external user
@@ -67,7 +69,8 @@ if ($user->societe_id > 0)
 }
 //$result = restrictedArea($user, 'mymodule', $id);
 
-$object = new Skeleton_Class($db);
+
+$object = new MyObject_Class($db);
 $extrafields = new ExtraFields($db);
 
 // fetch optionals attributes and labels
@@ -77,7 +80,8 @@ $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php';  // Must be include, not include_once  // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
 
 // Initialize technical object to manage hooks of modules. Note that conf->hooks_modules contains array array
-$hookmanager->initHooks(array('skeleton'));
+$hookmanager->initHooks(array('mymodule'));
+
 
 
 /*
@@ -86,7 +90,6 @@ $hookmanager->initHooks(array('skeleton'));
  * Put here all code to do according to value of "action" parameter
  */
 
-
 $parameters=array();
 $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');
@@ -206,15 +209,16 @@ if (empty($reshook))
 
 
 
+
 /*
  * VIEW
  *
  * Put here all code to build page
  */
 
-$form = new Form($db);
+$form=new Form($db);
 
-llxHeader('', $langs->trans('MyPageName'), '');
+llxHeader('','MyPageName','');
 
 
 // Put here content of your page
@@ -293,54 +297,308 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
 {
     $res = $object->fetch_optionals($object->id, $extralabels);
 
-	$head = commande_prepare_head($object);
-	dol_fiche_head($head, 'order', $langs->trans("CustomerOrder"), 0, 'order');
+	$head = mymodule_prepare_head($object);
+	dol_fiche_head($head, 'order', $langs->trans("CustomerOrder"), -1, 'order');
 		
-	print load_fiche_titre($langs->trans("MyModule"));
-    
-	dol_fiche_head();
-
+	$formconfirm = '';
+	
+	// Confirmation to delete
 	if ($action == 'delete') {
-		$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteMyOjbect'), $langs->trans('ConfirmDeleteMyObject'), 'confirm_delete', '', 0, 1);
-		print $formconfirm;
+	    $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 1);
 	}
 	
+	// Confirmation of action xxxx
+	if ($action == 'xxx')
+	{
+	    $formquestion=array();
+	    /*
+	        $formquestion = array(
+	            // 'text' => $langs->trans("ConfirmClone"),
+	            // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
+	            // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
+	            // array('type' => 'other',    'name' => 'idwarehouse',   'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1)));
+	    }*/	
+	    $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220);
+	}
+	
+	if (! $formconfirm) {
+	    $parameters = array('lineid' => $lineid);
+	    $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
+	    if (empty($reshook)) $formconfirm.=$hookmanager->resPrint;
+	    elseif ($reshook > 0) $formconfirm=$hookmanager->resPrint;
+	}
+	
+	// Print form confirm
+	print $formconfirm;
+	
+	
+	
+	// Object card
+	// ------------------------------------------------------------
+	
+	$linkback = '<a href="' . DOL_URL_ROOT . '/mymodule/list.php' . (! empty($socid) ? '?socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
+	
+	
+	$morehtmlref='<div class="refidno">';
+	/*
+	// Ref bis
+	$morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mymodule->creer, 'string', '', 0, 1);
+	$morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mymodule->creer, 'string', '', null, null, '', 1);
+	// Thirdparty
+	$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
+	// Project
+	if (! empty($conf->projet->enabled))
+	{
+	    $langs->load("projects");
+	    $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
+	    if ($user->rights->mymodule->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>';
+	
+	
+	dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
+	
+	
+	print '<div class="fichecenter">';
+	print '<div class="fichehalfleft">';
+	print '<div class="underbanner clearboth"></div>';
 	print '<table class="border centpercent">'."\n";
 	// print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
 	// LIST_OF_TD_LABEL_FIELDS_VIEW
+
+
+	// Other attributes
+	$cols = 2;
+	include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
+
+	print '</table>';
+	print '</div>';
+	print '<div class="fichehalfright">';
+	print '<div class="ficheaddleft">';
+	print '<div class="underbanner clearboth"></div>';
+	print '<table class="border centpercent">';
+	
+	
+
 	print '</table>';
+	print '</div>';
+	print '</div>';
+	print '</div>';
+	
+	print '<div class="clearboth"></div><br>';
 	
 	dol_fiche_end();
 
 
-	// Buttons
-	print '<div class="tabsAction">'."\n";
-	$parameters=array();
-	$reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
-	if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+	// Buttons for actions
+	if ($action != 'presend' && $action != 'editline') {
+    	print '<div class="tabsAction">'."\n";
+    	$parameters=array();
+    	$reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
+    	if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+    
+    	if (empty($reshook))
+    	{
+    		if ($user->rights->mymodule->write)
+    		{
+    			print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a></div>'."\n";
+    		}
+    
+    		if ($user->rights->mymodule->delete)
+    		{
+    			print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a></div>'."\n";
+    		}
+    	}
+    	print '</div>'."\n";
+	}
 
-	if (empty($reshook))
+	
+	// Select mail models is same action as presend
+	if (GETPOST('modelselected')) {
+	    $action = 'presend';
+	}
+	
+	if ($action != 'presend')
 	{
-		if ($user->rights->mymodule->write)
+	    print '<div class="fichecenter"><div class="fichehalfleft">';
+	    print '<a name="builddoc"></a>'; // ancre
+	    // Documents
+	    $comref = dol_sanitizeFileName($object->ref);
+	    $relativepath = $comref . '/' . $comref . '.pdf';
+	    $filedir = $conf->mymodule->dir_output . '/' . $comref;
+	    $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
+	    $genallowed = $user->rights->mymodule->creer;
+	    $delallowed = $user->rights->mymodule->supprimer;
+	    print $formfile->showdocuments('mymodule', $comref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
+	
+	
+	    // Show links to link elements
+	    $linktoelem = $form->showLinkToObjectBlock($object, null, array('order'));
+	    $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
+	
+	
+	    print '</div><div class="fichehalfright"><div class="ficheaddleft">';
+	
+	    // List of actions on element
+	    include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
+	    $formactions = new FormActions($db);
+	    $somethingshown = $formactions->showactions($object, 'order', $socid);
+	
+	    print '</div></div></div>';
+	}
+	
+
+	/*
+	 * Action presend
+	 */
+    /*
+	if ($action == 'presend')
+	{
+		$object->fetch_projet();
+
+		$ref = dol_sanitizeFileName($object->ref);
+		include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
+		$fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
+		$file = $fileparams['fullname'];
+
+		// Define output language
+		$outputlangs = $langs;
+		$newlang = '';
+		if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
+			$newlang = $_REQUEST['lang_id'];
+		if ($conf->global->MAIN_MULTILANGS && empty($newlang))
+			$newlang = $object->thirdparty->default_lang;
+
+		if (!empty($newlang))
 		{
-			print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a></div>'."\n";
+			$outputlangs = new Translate('', $conf);
+			$outputlangs->setDefaultLang($newlang);
+			$outputlangs->load('commercial');
+		}
+
+		// Build document if it not exists
+		if (! $file || ! is_readable($file)) {
+			$result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
+			if ($result <= 0) {
+				dol_print_error($db, $object->error, $object->errors);
+				exit();
+			}
+			$fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
+			$file = $fileparams['fullname'];
 		}
 
-		if ($user->rights->mymodule->delete)
+		print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
+		print '<div class="clearboth"></div>';
+		print '<br>';
+		print load_fiche_titre($langs->trans('SendOrderByMail'));
+
+		dol_fiche_head('');
+
+		// Cree l'objet formulaire mail
+		include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
+		$formmail = new FormMail($db);
+		$formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang);
+        $formmail->fromtype = (GETPOST('fromtype')?GETPOST('fromtype'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user'));
+
+        if($formmail->fromtype === 'user'){
+            $formmail->fromid = $user->id;
+
+        }
+		$formmail->trackid='ord'.$object->id;
+		if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2))	// If bit 2 is set
 		{
-			print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a></div>'."\n";
+			include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
+			$formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'ord'.$object->id);
 		}
-	}
-	print '</div>'."\n";
+		$formmail->withfrom = 1;
+		$liste = array();
+		foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value)
+			$liste [$key] = $value;
+		$formmail->withto = GETPOST('sendto') ? GETPOST('sendto') : $liste;
+		$formmail->withtocc = $liste;
+		$formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
+		if (empty($object->ref_client)) {
+			$formmail->withtopic = $outputlangs->trans('SendOrderRef', '__ORDERREF__');
+		} else if (! empty($object->ref_client)) {
+			$formmail->withtopic = $outputlangs->trans('SendOrderRef', '__ORDERREF__ (__REFCLIENT__)');
+		}
+		$formmail->withfile = 2;
+		$formmail->withbody = 1;
+		$formmail->withdeliveryreceipt = 1;
+		$formmail->withcancel = 1;
+		// Tableau des substitutions
+		$formmail->setSubstitFromObject($object);
+		$formmail->substit ['__ORDERREF__'] = $object->ref;
+
+		$custcontact = '';
+		$contactarr = array();
+		$contactarr = $object->liste_contact(- 1, 'external');
+
+		if (is_array($contactarr) && count($contactarr) > 0)
+		{
+			foreach ($contactarr as $contact)
+			{
+				if ($contact['libelle'] == $langs->trans('TypeContact_commande_external_CUSTOMER')) {	// TODO Use code and not label
+					$contactstatic = new Contact($db);
+					$contactstatic->fetch($contact ['id']);
+					$custcontact = $contactstatic->getFullName($langs, 1);
+				}
+			}
 
+			if (! empty($custcontact)) {
+				$formmail->substit['__CONTACTCIVNAME__'] = $custcontact;
+			}
+		}
+
+		// Tableau des parametres complementaires
+		$formmail->param['action'] = 'send';
+		$formmail->param['models'] = 'order_send';
+		$formmail->param['models_id']=GETPOST('modelmailselected','int');
+		$formmail->param['orderid'] = $object->id;
+		$formmail->param['returnurl'] = $_SERVER["PHP_SELF"] . '?id=' . $object->id;
+
+		// Init list of files
+		if (GETPOST("mode") == 'init') {
+			$formmail->clear_attached_files();
+			$formmail->add_attached_files($file, basename($file), dol_mimetype($file));
+		}
 
-	// Example 2 : Adding links to objects
-	// Show links to link elements
-	//$linktoelem = $form->showLinkToObjectBlock($object, null, array('skeleton'));
-	//$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
+		// Show form
+		print $formmail->get_form();
 
+		dol_fiche_end();
+	}*/
 }
 
+
 // End of page
 llxFooter();
 $db->close();

+ 442 - 48
htdocs/modulebuilder/template/myobject_list.php

@@ -1,10 +1,10 @@
 <?php
-/* <one line to give the program's name and a brief idea of what it does.>
- * Copyright (C) <year>  <name of author>
+/* Copyright (C) 2007-2016 Laurent Destailleur  <eldy@users.sourceforge.net>
+ * Copyright (C) ---Put here your own copyright and developer email---
  *
- * This program is free software: you can redistribute it and/or modify
+ * 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
+ * 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,
@@ -13,21 +13,20 @@
  * 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/>.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
 /**
- * \file    myobject_list.php
- * \ingroup mymodule
- * \brief   Page with list of myobject.
- *
- * List of myobject
+ *   	\file       htdocs/modulebuilder/template/myobject_list.php
+ *		\ingroup    mymodule othermodule1 othermodule2
+ *		\brief      This file is an example of a php page
+ *					Put here some comments
  */
 
-//if (! defined('NOREQUIREUSER'))	define('NOREQUIREUSER','1');
-//if (! defined('NOREQUIREDB'))		define('NOREQUIREDB','1');
-//if (! defined('NOREQUIRESOC'))	define('NOREQUIRESOC','1');
-//if (! defined('NOREQUIRETRAN'))	define('NOREQUIRETRAN','1');
+//if (! defined('NOREQUIREUSER'))  define('NOREQUIREUSER','1');
+//if (! defined('NOREQUIREDB'))    define('NOREQUIREDB','1');
+//if (! defined('NOREQUIRESOC'))   define('NOREQUIRESOC','1');
+//if (! defined('NOREQUIRETRAN'))  define('NOREQUIRETRAN','1');
 //if (! defined('NOCSRFCHECK'))    define('NOCSRFCHECK','1');			// Do not check anti CSRF attack test
 //if (! defined('NOSTYLECHECK'))   define('NOSTYLECHECK','1');			// Do not check style html tag into posted data
 //if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1');		// Do not check anti POST attack test
@@ -36,31 +35,39 @@
 //if (! defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX','1');
 //if (! defined("NOLOGIN"))        define("NOLOGIN",'1');				// If this page is public (can be called outside logged session)
 
-// Change the following lines to use the correct relative path (../, ../../, etc)
-
-// Load Dolibarr environment
-if (false === (@include '../../main.inc.php')) {  // From htdocs directory
-	require '../../../main.inc.php'; // From "custom" directory
-}
-
+// Change this following line to use the correct relative path (../, ../../, etc)
+$res=0;
+if (! $res && file_exists("../main.inc.php")) $res=@include '../main.inc.php';					// to work if your module directory is into dolibarr root htdocs directory
+if (! $res && file_exists("../../main.inc.php")) $res=@include '../../main.inc.php';			// to work if your module directory is into a subdir of root htdocs directory
+if (! $res && file_exists("../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../dolibarr/htdocs/main.inc.php';     // Used on dev env only
+if (! $res && file_exists("../../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../../dolibarr/htdocs/main.inc.php';   // Used on dev env only
+if (! $res) die("Include of main fails");
+// Change this following line to use the correct relative path from htdocs
+require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php');
 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
-dol_include_once('/mymodule/class/myclass.class.php');
+require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
+dol_include_once('/mymodule/class/skeleton_class.class.php');
 
-// Load translation files required by the page
-$langs->load("mymodule@mymodule");
+// Load traductions files requiredby by page
+$langs->load("mymodule");
+$langs->load("other");
 
-// Get parameters
-$action     = GETPOST('action','alpha');
-$massaction = GETPOST('massaction','alpha');
-$show_files = GETPOST('show_files','int');
-$confirm    = GETPOST('confirm','alpha');
-$toselect   = GETPOST('toselect', 'array');
+$action=GETPOST('action','alpha');
+$massaction=GETPOST('massaction','alpha');
+$show_files=GETPOST('show_files','int');
+$confirm=GETPOST('confirm','alpha');
+$toselect = GETPOST('toselect', 'array');
 
 $id			= GETPOST('id','int');
 $backtopage = GETPOST('backtopage');
-// TODO Add here list of search params
 $myparam	= GETPOST('myparam','alpha');
 
+$search_all=trim(GETPOST("sall"));
+$search_field1=GETPOST("search_field1");
+$search_field2=GETPOST("search_field2");
+$search_myfield=GETPOST('search_myfield');
+$optioncss = GETPOST('optioncss','alpha');
+
 // Load variable for pagination
 $limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit;
 $sortfield = GETPOST('sortfield','alpha');
@@ -74,11 +81,12 @@ if (! $sortfield) $sortfield="t.rowid"; // Set here default search field
 if (! $sortorder) $sortorder="ASC";
 
 // Protection if external user
+$socid=0;
 if ($user->societe_id > 0)
 {
+    $socid = $user->societe_id;
 	//accessforbidden();
 }
-//$result = restrictedArea($user, 'mymodule', $id);
 
 // Initialize technical object to manage context to save list fields
 $contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'mymodulelist';
@@ -87,14 +95,41 @@ $contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'mymoduleli
 $hookmanager->initHooks(array('mymodulelist'));
 $extrafields = new ExtraFields($db);
 
-// Load object if id or ref is provided as parameter
-$object = new MyClass($db);
-if (($id > 0 || ! empty($ref)) && $action != 'add') {
-	$result = $object->fetch($id, $ref);
-	if ($result < 0) dol_print_error($db);
+// fetch optionals attributes and labels
+$extralabels = $extrafields->fetch_name_optionals_label('mymodule');
+$search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
+
+// List of fields to search into when doing a "search in all"
+$fieldstosearchall = array(
+    't.ref'=>'Ref',
+    't.note_public'=>'NotePublic',
+);
+if (empty($user->socid)) $fieldstosearchall["t.note_private"]="NotePrivate";
+
+// Definition of fields for list
+$arrayfields=array(
+    't.field1'=>array('label'=>"Field1", 'checked'=>1),
+    't.field2'=>array('label'=>"Field2", 'checked'=>1),
+    //'t.entity'=>array('label'=>"Entity", 'checked'=>1, 'enabled'=>(! empty($conf->multicompany->enabled) && empty($conf->multicompany->transverse_mode))),
+    't.datec'=>array('label'=>"DateCreationShort", 'checked'=>0, 'position'=>500),
+    't.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500),
+    //'t.statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000),
+);
+// Extra fields
+if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
+{
+    foreach($extrafields->attribute_label as $key => $val)
+    {
+        $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>$extrafields->attribute_list[$key], 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]);
+    }
 }
 
 
+$object=new Skeleton_Class($db);
+
+
+
+
 /*
  * ACTIONS
  *
@@ -116,10 +151,10 @@ if (empty($reshook))
     // Purge search criteria
     if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") ||GETPOST("button_removefilter")) // All tests are required to be compatible with all browsers
     {
-        $search_field1='';
-        $search_field2='';
-        $search_date_creation='';
-        $search_date_update='';
+    	$search_field1='';
+    	$search_field2='';
+    	$search_date_creation='';
+    	$search_date_update='';
         $toselect='';
         $search_array_options=array();
     }
@@ -134,18 +169,24 @@ if (empty($reshook))
 }
 
 
+
 /*
  * VIEW
  *
  * Put here all code to build page
  */
 
-llxHeader('', $langs->trans('MyPageName'), '');
+$now=dol_now();
 
-$form = new Form($db);
+$form=new Form($db);
+
+//$help_url="EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes";
+$help_url='';
+$title = $langs->trans('MyModuleListTitle');
 
 // Put here content of your page
-// Example 1: Adding jquery code
+
+// Example : Adding jquery code
 print '<script type="text/javascript" language="javascript">
 jQuery(document).ready(function() {
 	function init_myfunc()
@@ -161,15 +202,368 @@ jQuery(document).ready(function() {
 </script>';
 
 
+$sql = "SELECT";
+$sql.= " t.rowid,";
+$sql.= " t.field1,";
+$sql.= " t.field2";
+// Add fields from extrafields
+foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
+// Add fields from hooks
+$parameters=array();
+$reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters);    // Note that $action and $object may have been modified by hook
+$sql.=$hookmanager->resPrint;
+$sql.= " FROM ".MAIN_DB_PREFIX."mytable as t";
+if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."mytable_extrafields as ef on (t.rowid = ef.fk_object)";
+$sql.= " WHERE 1 = 1";
+//$sql.= " WHERE u.entity IN (".getEntity('mytable',1).")";
+if ($search_field1) $sql.= natural_search("field1",$search_field1);
+if ($search_field2) $sql.= natural_search("field2",$search_field2);
+if ($sall)          $sql.= natural_search(array_keys($fieldstosearchall), $sall);
+// Add where from extra fields
+foreach ($search_array_options as $key => $val)
+{
+    $crit=$val;
+    $tmpkey=preg_replace('/search_options_/','',$key);
+    $typ=$extrafields->attribute_type[$tmpkey];
+    $mode=0;
+    if (in_array($typ, array('int','double'))) $mode=1;    // Search on a numeric
+    if ($val && ( ($crit != '' && ! in_array($typ, array('select'))) || ! empty($crit))) 
+    {
+        $sql .= natural_search('ef.'.$tmpkey, $crit, $mode);
+    }
+}
+// Add where from hooks
+$parameters=array();
+$reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters);    // Note that $action and $object may have been modified by hook
+$sql.=$hookmanager->resPrint;
+$sql.=$db->order($sortfield,$sortorder);
+
+// Count total nb of records
+$nbtotalofrecords = '';
+if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
+{
+	$result = $db->query($sql);
+	$nbtotalofrecords = $db->num_rows($result);
+}	
+
+$sql.= $db->plimit($limit+1, $offset);
+
+dol_syslog($script_file, LOG_DEBUG);
+$resql=$db->query($sql);
+if (! $resql)
+{
+    dol_print_error($db);
+    exit;
+}
+
+$num = $db->num_rows($resql);
+
+// Direct jump if only one record found
+if ($num == 1 && ! empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all)
+{
+    $obj = $db->fetch_object($resql);
+    $id = $obj->rowid;
+    header("Location: ".DOL_URL_ROOT.'/skeleton/card.php?id='.$id);
+    exit;
+}
+
+llxHeader('', $title, $help_url);
+
+$arrayofselected=is_array($toselect)?$toselect:array();
+
+$param='';
+if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
+if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
+if ($search_field1 != '') $param.= '&amp;search_field1='.urlencode($search_field1);
+if ($search_field2 != '') $param.= '&amp;search_field2='.urlencode($search_field2);
+if ($optioncss != '') $param.='&optioncss='.$optioncss;
+// Add $param from extra fields
+foreach ($search_array_options as $key => $val)
+{
+    $crit=$val;
+    $tmpkey=preg_replace('/search_options_/','',$key);
+    if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
+} 
+
+$arrayofmassactions =  array(
+    'presend'=>$langs->trans("SendByMail"),
+    'builddoc'=>$langs->trans("PDFMerge"),
+);
+if ($user->rights->mymodule->supprimer) $arrayofmassactions['delete']=$langs->trans("Delete");
+if ($massaction == 'presend') $arrayofmassactions=array();
+$massactionbutton=$form->selectMassAction('', $arrayofmassactions);
+
+print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
+if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
+print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
+print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
+print '<input type="hidden" name="action" value="list">';
+print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
+print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
+print '<input type="hidden" name="page" value="'.$page.'">';
+print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
+
+print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_companies', 0, '', '', $limit);
+
+if ($sall)
+{
+    foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
+    print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall);
+}
+
+$moreforfilter = '';
+$moreforfilter.='<div class="divsearchfield">';
+$moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
+$moreforfilter.= '</div>';
+
+$parameters=array();
+$reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters);    // Note that $action and $object may have been modified by hook
+if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
+else $moreforfilter = $hookmanager->resPrint;
+
+if (! empty($moreforfilter))
+{
+	print '<div class="liste_titre liste_titre_bydiv centpercent">';
+	print $moreforfilter;
+    print '</div>';
+}
+
+$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
+$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage);	// This also change content of $arrayfields
 
-// TODO
+print '<div class="div-table-responsive">';
+print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
 
+// Fields title
+print '<tr class="liste_titre">';
+// LIST_OF_TD_TITLE_FIELDS
+//if (! empty($arrayfields['t.field1']['checked'])) print_liste_field_titre($arrayfields['t.field1']['label'],$_SERVER['PHP_SELF'],'t.field1','',$param,'',$sortfield,$sortorder);
+//if (! empty($arrayfields['t.field2']['checked'])) print_liste_field_titre($arrayfields['t.field2']['label'],$_SERVER['PHP_SELF'],'t.field2','',$param,'',$sortfield,$sortorder);
+// Extra fields
+if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
+{
+   foreach($extrafields->attribute_label as $key => $val) 
+   {
+       if (! empty($arrayfields["ef.".$key]['checked'])) 
+       {
+			$align=$extrafields->getAlignFlag($key);
+			$sortonfield = "ef.".$key;
+			if (! empty($extrafields->attribute_computed[$key])) $sortonfield='';
+			print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
+       }
+   }
+}
+// Hook fields
+$parameters=array('arrayfields'=>$arrayfields);
+$reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters);    // Note that $action and $object may have been modified by hook
+print $hookmanager->resPrint;
+if (! empty($arrayfields['t.datec']['checked']))  print_liste_field_titre($arrayfields['t.datec']['label'],$_SERVER["PHP_SELF"],"t.datec","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
+if (! empty($arrayfields['t.tms']['checked']))    print_liste_field_titre($arrayfields['t.tms']['label'],$_SERVER["PHP_SELF"],"t.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
+//if (! empty($arrayfields['t.status']['checked'])) print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"t.status","",$param,'align="center"',$sortfield,$sortorder);
+print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
+print '</tr>'."\n";
+
+// Fields title search
+print '<tr class="liste_titre">';
+// LIST_OF_TD_TITLE_SEARCH
+//if (! empty($arrayfields['t.field1']['checked'])) print '<td class="liste_titre"><input type="text" class="flat" name="search_field1" value="'.$search_field1.'" size="10"></td>';
+//if (! empty($arrayfields['t.field2']['checked'])) print '<td class="liste_titre"><input type="text" class="flat" name="search_field2" value="'.$search_field2.'" size="10"></td>';
+// Extra fields
+if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
+{
+    foreach($extrafields->attribute_label as $key => $val) 
+    {
+        if (! empty($arrayfields["ef.".$key]['checked']))
+        {
+            $align=$extrafields->getAlignFlag($key);
+            $typeofextrafield=$extrafields->attribute_type[$key];
+            print '<td class="liste_titre'.($align?' '.$align:'').'">';
+        	if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')) && empty($extrafields->attribute_computed[$key]))
+			{
+			    $crit=$val;
+				$tmpkey=preg_replace('/search_options_/','',$key);
+				$searchclass='';
+				if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring';
+				if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum';
+				print '<input class="flat'.($searchclass?' '.$searchclass:'').'" size="4" type="text" name="search_options_'.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options['search_options_'.$tmpkey]).'">';
+			}
+            print '</td>';
+        }
+    }
+}
+// Fields from hook
+$parameters=array('arrayfields'=>$arrayfields);
+$reshook=$hookmanager->executeHooks('printFieldListOption',$parameters);    // Note that $action and $object may have been modified by hook
+print $hookmanager->resPrint;
+if (! empty($arrayfields['t.datec']['checked']))
+{
+    // Date creation
+    print '<td class="liste_titre">';
+    print '</td>';
+}
+if (! empty($arrayfields['t.tms']['checked']))
+{
+    // Date modification
+    print '<td class="liste_titre">';
+    print '</td>';
+}
+/*if (! empty($arrayfields['u.statut']['checked']))
+{
+    // Status
+    print '<td class="liste_titre" align="center">';
+    print $form->selectarray('search_statut', array('-1'=>'','0'=>$langs->trans('Disabled'),'1'=>$langs->trans('Enabled')),$search_statut);
+    print '</td>';
+}*/
+// Action column
+print '<td class="liste_titre" align="right">';
+$searchpicto=$form->showFilterAndCheckAddButtons($massactionbutton?1:0, 'checkforselect', 1);
+print $searchpicto;
+print '</td>';
+print '</tr>'."\n";
+    
+
+// Detect if we need a fetch on each output line
+$needToFetchEachLine=0;
+foreach ($extrafields->attribute_computed as $key => $val)
+{
+    if (preg_match('/\$object/',$val)) $needToFetchEachLine++;  // There is at least one compute field that use $object
+}
 
 
+$i=0;
+$totalarray=array();
+while ($i < min($num, $limit))
+{
+    $obj = $db->fetch_object($resql);
+    if ($obj)
+    {
+        // Show here line of result
+        print '<tr class="oddeven">';
+        // LIST_OF_TD_FIELDS_LIST
+        /*
+        if (! empty($arrayfields['t.field1']['checked'])) 
+        {
+            print '<td>'.$obj->field1.'</td>';
+		    if (! $i) $totalarray['nbfield']++;
+        }
+        if (! empty($arrayfields['t.field2']['checked'])) 
+        {
+            print '<td>'.$obj->field2.'</td>';
+		    if (! $i) $totalarray['nbfield']++;
+        }*/
+    	// Extra fields
+		if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
+		{
+		   foreach($extrafields->attribute_label as $key => $val) 
+		   {
+				if (! empty($arrayfields["ef.".$key]['checked'])) 
+				{
+					print '<td';
+					$align=$extrafields->getAlignFlag($key);
+					if ($align) print ' align="'.$align.'"';
+					print '>';
+					$tmpkey='options_'.$key;
+					print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1);
+					print '</td>';
+		            if (! $i) $totalarray['nbfield']++;
+				}
+		   }
+		}
+        // Fields from hook
+	    $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
+		$reshook=$hookmanager->executeHooks('printFieldListValue',$parameters);    // Note that $action and $object may have been modified by hook
+        print $hookmanager->resPrint;
+    	// Date creation
+        if (! empty($arrayfields['t.datec']['checked']))
+        {
+            print '<td align="center">';
+            print dol_print_date($db->jdate($obj->date_creation), 'dayhour');
+            print '</td>';
+		    if (! $i) $totalarray['nbfield']++;
+        }
+        // Date modification
+        if (! empty($arrayfields['t.tms']['checked']))
+        {
+            print '<td align="center">';
+            print dol_print_date($db->jdate($obj->date_update), 'dayhour');
+            print '</td>';
+		    if (! $i) $totalarray['nbfield']++;
+        }
+        // Status
+        /*
+        if (! empty($arrayfields['u.statut']['checked']))
+        {
+		  $userstatic->statut=$obj->statut;
+          print '<td align="center">'.$userstatic->getLibStatut(3).'</td>';
+        }*/
+
+        // Action column
+        print '<td class="nowrap" align="center">';
+	    if ($massactionbutton || $massaction)   // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
+        {
+	        $selected=0;
+			if (in_array($obj->rowid, $arrayofselected)) $selected=1;
+			print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
+        }
+	    print '</td>';
+        if (! $i) $totalarray['nbfield']++;
+
+        print '</tr>';
+    }
+    $i++;
+}
+
+// Show total line
+if (isset($totalarray['totalhtfield']))
+{
+    print '<tr class="liste_total">';
+    $i=0;
+    while ($i < $totalarray['nbfield'])
+    {
+        $i++;
+        if ($i == 1)
+        {
+            if ($num < $limit) print '<td align="left">'.$langs->trans("Total").'</td>';
+            else print '<td align="left">'.$langs->trans("Totalforthispage").'</td>';
+        }
+        elseif ($totalarray['totalhtfield'] == $i) print '<td align="right">'.price($totalarray['totalht']).'</td>';
+        elseif ($totalarray['totalvatfield'] == $i) print '<td align="right">'.price($totalarray['totalvat']).'</td>';
+        elseif ($totalarray['totalttcfield'] == $i) print '<td align="right">'.price($totalarray['totalttc']).'</td>';
+        else print '<td></td>';
+    }
+    print '</tr>';
+}
+
+$db->free($resql);
+
+$parameters=array('arrayfields'=>$arrayfields, 'sql'=>$sql);
+$reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters);    // Note that $action and $object may have been modified by hook
+print $hookmanager->resPrint;
+
+print '</table>'."\n";
+print '</div>'."\n";
+
+print '</form>'."\n";
+
+
+if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files)
+{
+    // Show list of available documents
+    $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
+    $urlsource.=str_replace('&amp;','&',$param);
+
+    $filedir=$diroutputmassaction;
+    $genallowed=$user->rights->facture->lire;
+    $delallowed=$user->rights->facture->lire;
+
+    print $formfile->showdocuments('massfilesarea_mymodule','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,'');
+}
+else
+{
+    print '<br><a name="show_files"></a><a href="'.$_SERVER["PHP_SELF"].'?show_files=1'.$param.'#show_files">'.$langs->trans("ShowTempMassFilesArea").'</a>';
+}
 
-// Example 2: Adding links to objects
-// The class must extend CommonObject for this method to be available
-$somethingshown = $form->showLinkedObjectBlock($myobject);
 
 // End of page
 llxFooter();
+$db->close();

+ 165 - 0
htdocs/modulebuilder/template/scripts/myobject.php

@@ -0,0 +1,165 @@
+#!/usr/bin/env php
+<?php
+/* Copyright (C) 2007-2013 Laurent Destailleur  <eldy@users.sourceforge.net>
+ * 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       htdocs/modulebuilder/template/scripts/myobject.php
+ *		\ingroup    mymodule
+ *      \brief      This file is an example for a command line script to work on MyObject
+ */
+
+$sapi_type = php_sapi_name();
+$script_file = basename(__FILE__);
+$path=dirname(__FILE__).'/';
+
+// Test if batch mode
+if (substr($sapi_type, 0, 3) == 'cgi') {
+    echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
+	exit(-1);
+}
+
+// Global variables
+$version='1.0';
+$error=0;
+
+
+// -------------------- START OF YOUR CODE HERE --------------------
+@set_time_limit(0);							// No timeout for this script
+define('EVEN_IF_ONLY_LOGIN_ALLOWED',1);		// Set this define to 0 if you want to lock your script when dolibarr setup is "locked to admin user only".
+
+// Include and load Dolibarr environment variables
+require_once($path."../../htdocs/master.inc.php");
+// After this $db, $mysoc, $langs, $conf and $hookmanager are defined (Opened $db handler to database will be closed at end of file).
+// $user is created but empty.
+
+//$langs->setDefaultLang('en_US'); 	// To change default language of $langs
+$langs->load("main");				// To load language file for default language
+
+// Load user and its permissions
+$result=$user->fetch('','admin');	// Load user for login 'admin'. Comment line to run as anonymous user.
+if (! $result > 0) { dol_print_error('',$user->error); exit; }
+$user->getrights();
+
+
+print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
+if (! isset($argv[1])) {	// Check parameters
+    print "Usage: ".$script_file." param1 param2 ...\n";
+	exit(-1);
+}
+print '--- start'."\n";
+print 'Argument 1='.$argv[1]."\n";
+print 'Argument 2='.$argv[2]."\n";
+
+
+// Start of transaction
+$db->begin();
+
+
+// Examples for manipulating class MyObject
+dol_include_once("/mymodule/class/myobject.class.php");
+$myobject=new MyObject($db);
+
+// Example for inserting creating object in database
+/*
+dol_syslog($script_file." CREATE", LOG_DEBUG);
+$myobject->prop1='value_prop1';
+$myobject->prop2='value_prop2';
+$id=$myobject->create($user);
+if ($id < 0) { $error++; dol_print_error($db,$myobject->error); }
+else print "Object created with id=".$id."\n";
+*/
+
+// Example for reading object from database
+/*
+dol_syslog($script_file." FETCH", LOG_DEBUG);
+$result=$myobject->fetch($id);
+if ($result < 0) { $error; dol_print_error($db,$myobject->error); }
+else print "Object with id=".$id." loaded\n";
+*/
+
+// Example for updating object in database ($myobject must have been loaded by a fetch before)
+/*
+dol_syslog($script_file." UPDATE", LOG_DEBUG);
+$myobject->prop1='newvalue_prop1';
+$myobject->prop2='newvalue_prop2';
+$result=$myobject->update($user);
+if ($result < 0) { $error++; dol_print_error($db,$myobject->error); }
+else print "Object with id ".$myobject->id." updated\n";
+*/
+
+// Example for deleting object in database ($myobject must have been loaded by a fetch before)
+/*
+dol_syslog($script_file." DELETE", LOG_DEBUG);
+$result=$myobject->delete($user);
+if ($result < 0) { $error++; dol_print_error($db,$myobject->error); }
+else print "Object with id ".$myobject->id." deleted\n";
+*/
+
+
+// An example of a direct SQL read without using the fetch method
+/*
+$sql = "SELECT field1, field2";
+$sql.= " FROM ".MAIN_DB_PREFIX."myobject";
+$sql.= " WHERE field3 = 'xxx'";
+$sql.= " ORDER BY field1 ASC";
+
+dol_syslog($script_file, LOG_DEBUG);
+$resql=$db->query($sql);
+if ($resql)
+{
+	$num = $db->num_rows($resql);
+	$i = 0;
+	if ($num)
+	{
+		while ($i < $num)
+		{
+			$obj = $db->fetch_object($resql);
+			if ($obj)
+			{
+				// You can use here results
+				print $obj->field1;
+				print $obj->field2;
+			}
+			$i++;
+		}
+	}
+}
+else
+{
+	$error++;
+	dol_print_error($db);
+}
+*/
+
+
+// -------------------- END OF YOUR CODE --------------------
+
+if (! $error)
+{
+	$db->commit();
+	print '--- end ok'."\n";
+}
+else
+{
+	print '--- end error code='.$error."\n";
+	$db->rollback();
+}
+
+$db->close();	// Close $db database opened handler
+
+exit($error);

+ 0 - 203
htdocs/modulebuilder/template/scripts/myscript.php

@@ -1,203 +0,0 @@
-#!/usr/bin/env php
-<?php
-/* <one line to give the program's name and a brief idea of what it does.>
- * Copyright (C) <year>  <name of author>
- *
- * 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    scripts/myscript.php
- * \ingroup mymodule
- * \brief   Example command line script.
- *
- * Put detailed description here.
- */
-
-$sapi_type = php_sapi_name();
-$script_file = basename(__FILE__);
-$path = dirname(__FILE__) . '/';
-
-// Test if batch mode
-if (substr($sapi_type, 0, 3) == 'cgi') {
-	echo "Error: You are using PHP for CGI. To execute ";
-	echo $script_file;
-	echo " from command line, you must use PHP for CLI mode.\n";
-	exit;
-}
-
-// Global variables
-$version = '1.0.0';
-$error = 0;
-
-
-/*
- * -------------------- YOUR CODE STARTS HERE --------------------
- */
-/* Set this define to 0 if you want to allow execution of your script
- * even if dolibarr setup is "locked to admin user only". */
-define('EVEN_IF_ONLY_LOGIN_ALLOWED', 0);
-
-/* Include Dolibarr environment
- * Customize to your needs
- */
-require_once $path . '../../../master.inc.php';
-/* After this $db, $conf, $langs, $mysoc, $user and other Dolibarr utility variables should be defined.
- * Warning: this still requires a valid htdocs/conf.php file
- */
-
-global $conf, $db, $langs, $mysoc, $user;
-
-// No timeout for this script
-@set_time_limit(0);
-
-// Set the default language
-//$langs->setDefaultLang('en_US');
-
-// Load translations for the default language
-$langs->load("main");
-
-/* User and permissions loading
- * Loads user for login 'admin'.
- * Comment out to run as anonymous user. */
-$result = $user->fetch('', 'admin');
-if (! $result > 0) {
-	dol_print_error('', $user->error);
-	exit;
-}
-$user->getrights();
-
-// Display banner and help
-echo "***** " . $script_file . " (" . $version . ") pid=" . getmypid() . " *****\n";
-dol_syslog($script_file . " launched with arg " . join(',', $argv));
-if (! isset($argv[1])) {
-	// Check parameters
-	echo "Usage: " . $script_file . " param1 param2 ...\n";
-	exit;
-}
-echo '--- start' . "\n";
-echo 'Argument 1=' . $argv[1] . "\n";
-echo 'Argument 2=' . $argv[2] . "\n";
-
-// Start database transaction
-$db->begin();
-
-// Examples for manipulating a class
-require_once '../class/myclass.class.php';
-$myobject = new MyClass($db);
-
-// Example for inserting creating object in database
-/*
-	dol_syslog($script_file . " CREATE", LOG_DEBUG);
-	$myobject->prop1 = 'value_prop1';
-	$myobject->prop2 = 'value_prop2';
-	$id = $myobject->create($user);
-	if ($id < 0) {
-		$error++;
-		dol_print_error($db, $myobject->error);
-	} else {
-		 echo "Object created with id=" . $id . "\n";
-	}
- */
-
-// Example for reading object from database
-/*
-	dol_syslog($script_file . " FETCH", LOG_DEBUG);
-	$result = $myobject->fetch($id);
-	if ($result < 0) {
-		$error;
-		dol_print_error($db, $myobject->error);
-	} else {
-		echo "Object with id=" . $id . " loaded\n";
-	}
- */
-
-// Example for updating object in database
-// ($myobject must have been loaded by a fetch before)
-/*
-	dol_syslog($script_file . " UPDATE", LOG_DEBUG);
-	$myobject->prop1 = 'newvalue_prop1';
-	$myobject->prop2 = 'newvalue_prop2';
-	$result = $myobject->update($user);
-	if ($result < 0) {
-		$error++;
-		dol_print_error($db, $myobject->error);
-	} else {
-		echo "Object with id " . $myobject->id . " updated\n";
-	}
- */
-
-// Example for deleting object in database
-// ($myobject must have been loaded by a fetch before)
-/*
-	dol_syslog($script_file . " DELETE", LOG_DEBUG);
-	$result = $myobject->delete($user);
-	if ($result < 0) {
-		$error++;
-		dol_print_error($db, $myobject->error);
-	} else {
-		echo "Object with id " . $myobject->id . " deleted\n";
-	}
- */
-
-// An example of a direct SQL read without using the fetch method
-/*
-	$sql = "SELECT field1, field2";
-	$sql.= " FROM " . MAIN_DB_PREFIX . "c_pays";
-	$sql.= " WHERE field3 = 'xxx'";
-	$sql.= " ORDER BY field1 ASC";
-
-	dol_syslog($script_file . " sql=" . $sql, LOG_DEBUG);
-	$resql=$db->query($sql);
-	if ($resql) {
-		$num = $db->num_rows($resql);
-		$i = 0;
-		if ($num) {
-			while ($i < $num) {
-				$obj = $db->fetch_object($resql);
-				if ($obj) {
-					// You can use here results
-					echo $obj->field1;
-					echo $obj->field2;
-				}
-				$i++;
-			}
-		}
-	} else {
-		$error++;
-		dol_print_error($db);
-	}
- */
-
-
-/*
- * --------------------- YOUR CODE ENDS HERE ----------------------
- */
-
-// Error management
-if (! $error) {
-	$db->commit();
-	echo '--- end ok' . "\n";
-	$exit_status = 0; // UNIX no errors exit status
-} else {
-	echo '--- end error code=' . $error . "\n";
-	$db->rollback();
-	$exit_status = 1; // UNIX general error exit status
-}
-
-// Close database handler
-$db->close();
-
-// Return exit status code
-return $exit_status;

+ 1 - 1
htdocs/modulebuilder/template/sql/data.sql

@@ -14,6 +14,6 @@
 -- You should have received a copy of the GNU General Public License
 -- along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-INSERT INTO llx_mytable VALUES (
+INSERT INTO llx_myobject VALUES (
 	1, 1, 'mydata'
 );

+ 1 - 1
htdocs/modulebuilder/template/sql/llx_mytable.key.sql → htdocs/modulebuilder/template/sql/llx_myobject.key.sql

@@ -14,4 +14,4 @@
 -- You should have received a copy of the GNU General Public License
 -- along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-ALTER TABLE llx_mytable ADD UNIQUE INDEX uk_fk_othertable (fk_othertable);
+ALTER TABLE llx_myobject ADD UNIQUE INDEX uk_fk_othertable (fk_othertable);

+ 1 - 1
htdocs/modulebuilder/template/sql/llx_mytable.sql → htdocs/modulebuilder/template/sql/llx_myobject.sql

@@ -14,7 +14,7 @@
 -- You should have received a copy of the GNU General Public License
 -- along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-CREATE TABLE llx_mytable(
+CREATE TABLE llx_myobject(
 	rowid INTEGER AUTO_INCREMENT PRIMARY KEY,
 	entity INTEGER DEFAULT 1 NOT NULL,
 	fk_othertable INTEGER NOT NULL,

+ 0 - 0
htdocs/modulebuilder/template/test/functional/MyModuleFunctionalTest.php → htdocs/modulebuilder/template/test/phpunit/MyModuleFunctionalTest.php


+ 4 - 6
htdocs/modulebuilder/template/test/unit/MyClassTest.php → htdocs/modulebuilder/template/test/phpunit/MyObjectTest.php

@@ -17,20 +17,18 @@
  */
 
 /**
- * \file    test/unit/MyClassTest.php
+ * \file    test/unit/MyObjectTest.php
  * \ingroup mymodule
- * \brief   Example PHPUnit test.
- *
- * Put detailed description here.
+ * \brief   PHPUnit test for MyObject class.
  */
 
 namespace test\unit;
 
 /**
- * Class MyClassTest
+ * Class MyObjectTest
  * @package Testmymodule
  */
-class MyClassTest extends \PHPUnit_Framework_TestCase
+class MyObjectTest extends \PHPUnit_Framework_TestCase
 {
 	/**
 	 * Global test setup

+ 28 - 19
htdocs/product/card.php

@@ -1,20 +1,20 @@
 <?php
-/* Copyright (C) 2001-2007	Rodolphe Quiedeville		<rodolphe@quiedeville.org>
+/* Copyright (C) 2001-2007	Rodolphe Quiedeville	<rodolphe@quiedeville.org>
  * Copyright (C) 2004-2016	Laurent Destailleur		<eldy@users.sourceforge.net>
- * Copyright (C) 2005		Eric Seigne			<eric.seigne@ryxeo.com>
+ * Copyright (C) 2005		Eric Seigne				<eric.seigne@ryxeo.com>
  * Copyright (C) 2005-2015	Regis Houssin			<regis.houssin@capnetworks.com>
  * Copyright (C) 2006		Andre Cianfarani		<acianfa@free.fr>
  * Copyright (C) 2006		Auguria SARL			<info@auguria.org>
  * Copyright (C) 2010-2015	Juanjo Menent			<jmenent@2byte.es>
  * Copyright (C) 2013-2016	Marcos García			<marcosgdf@gmail.com>
  * Copyright (C) 2012-2013	Cédric Salvador			<csalvador@gpcsolutions.fr>
- * Copyright (C) 2011-2016	Alexandre Spangaro		<aspangaro.dolibarr@gmail.com>
+ * Copyright (C) 2011-2017	Alexandre Spangaro		<aspangaro.dolibarr@gmail.com>
  * Copyright (C) 2014		Cédric Gross			<c.gross@kreiz-it.fr>
  * Copyright (C) 2014-2015	Ferran Marcet			<fmarcet@2byte.es>
  * Copyright (C) 2015		Jean-François Ferry		<jfefe@aternatik.fr>
  * Copyright (C) 2015		Raphaël Doursenaud		<rdoursenaud@gpcsolutions.fr>
  * Copyright (C) 2016		Charlie Benke			<charlie@patas-monkey.com>
- * Copyright (C) 2016		Meziane Sof			<virtualsof@yahoo.fr>
+ * Copyright (C) 2016		Meziane Sof				<virtualsof@yahoo.fr>
  *
  * 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
@@ -52,7 +52,8 @@ if (! empty($conf->propal->enabled))     require_once DOL_DOCUMENT_ROOT.'/comm/p
 if (! empty($conf->facture->enabled))    require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
 if (! empty($conf->commande->enabled))   require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.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';
+if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
+if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
 
 $langs->load("products");
 $langs->load("other");
@@ -272,7 +273,7 @@ if (empty($reshook))
             $object->volume_units       	 = GETPOST('volume_units');
             $object->finished           	 = GETPOST('finished');
 	        $object->fk_unit                 = GETPOST('units');
-			
+
 			$accountancy_code_sell 			 = GETPOST('accountancy_code_sell');
 			$accountancy_code_buy 			 = GETPOST('accountancy_code_buy');
 
@@ -399,7 +400,7 @@ if (empty($reshook))
 
 				$accountancy_code_sell 			 = GETPOST('accountancy_code_sell');
 				$accountancy_code_buy 			 = GETPOST('accountancy_code_buy');
-				
+
 				if ($accountancy_code_sell <= 0) { $object->accountancy_code_sell = ''; } else { $object->accountancy_code_sell = $accountancy_code_sell; }
 				if ($accountancy_code_buy <= 0) { $object->accountancy_code_buy = ''; } else { $object->accountancy_code_buy = $accountancy_code_buy; }
 
@@ -808,7 +809,7 @@ llxHeader('', $title, $helpurl);
 $form = new Form($db);
 $formfile = new FormFile($db);
 $formproduct = new FormProduct($db);
-if (! empty($conf->accounting->enabled)) $formaccountancy = New FormVentilation($db);
+if (! empty($conf->accounting->enabled)) $formaccounting = New FormAccounting($db);
 
 // Load object modBarCodeProduct
 $res=0;
@@ -1107,21 +1108,21 @@ else
 
         // Accountancy codes
         print '<table class="border" width="100%">';
-		
+
 		if (! empty($conf->accounting->enabled))
 		{
             // Accountancy_code_sell
             print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
             print '<td>';
-		    print $formaccountancy->select_account(GETPOST('accountancy_code_sell'), 'accountancy_code_sell', 1, null, 1, 1, '');
+		    print $formaccounting->select_account(GETPOST('accountancy_code_sell'), 'accountancy_code_sell', 1, null, 1, 1, '');
             print '</td></tr>';
 
             // Accountancy_code_buy
             print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
             print '<td>';
-			print $formaccountancy->select_account(GETPOST('accountancy_code_buy'), 'accountancy_code_buy', 1, null, 1, 1, '');
+			print $formaccounting->select_account(GETPOST('accountancy_code_buy'), 'accountancy_code_buy', 1, null, 1, 1, '');
             print '</td></tr>';
-		}			
+		}
 		else // For external software 
 		{
             // Accountancy_code_sell
@@ -1406,15 +1407,15 @@ else
                 // Accountancy_code_sell
                 print '<tr><td class="titlefield">'.$langs->trans("ProductAccountancySellCode").'</td>';
                 print '<td>';
-				print $formaccountancy->select_account($object->accountancy_code_sell, 'accountancy_code_sell', 1, '', 1, 1);
+				print $formaccounting->select_account($object->accountancy_code_sell, 'accountancy_code_sell', 1, '', 1, 1);
                 print '</td></tr>';
 
                 // Accountancy_code_buy
                 print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
                 print '<td>';
-				print $formaccountancy->select_account($object->accountancy_code_buy, 'accountancy_code_buy', 1, '', 1, 1);
+				print $formaccounting->select_account($object->accountancy_code_buy, 'accountancy_code_buy', 1, '', 1, 1);
                 print '</td></tr>';
-			}			
+			}
 			else // For external software 
 			{
                 // Accountancy_code_sell
@@ -1531,8 +1532,12 @@ else
 			print '<tr><td class="nowrap">';
             print $langs->trans("ProductAccountancySellCode");
             print '</td><td colspan="2">';
-			if (! empty($conf->accounting->enabled)) {
-				print length_accountg($object->accountancy_code_sell);
+			if (! empty($conf->accounting->enabled))
+			{
+				$accountingaccount = new AccountingAccount($db);
+				$accountingaccount->fetch('',$object->accountancy_code_sell);
+
+				print $accountingaccount->getNomUrl(0,1,1,'',1);
             } else {
 				print $object->accountancy_code_sell;
 			}
@@ -1542,8 +1547,12 @@ else
 			print '<tr><td class="nowrap">';
             print $langs->trans("ProductAccountancyBuyCode");
             print '</td><td colspan="2">';
-			if (! empty($conf->accounting->enabled)) {
-				print length_accountg($object->accountancy_code_buy);
+			if (! empty($conf->accounting->enabled))
+			{
+				$accountingaccount2 = new AccountingAccount($db);
+				$accountingaccount2->fetch('',$object->accountancy_code_buy);
+
+				print $accountingaccount2->getNomUrl(0,1,1,'',1);
             } else {
 				print $object->accountancy_code_buy;
 			}

+ 14 - 10
htdocs/public/stripe/newpayment.php

@@ -181,6 +181,13 @@ if (! empty($conf->global->STRIPE_SECURITY_TOKEN))
     }
 }
 
+// Common variables
+$creditor=$mysoc->name;
+$paramcreditor='STRIPE_CREDITOR_'.$suffix;
+if (! empty($conf->global->$paramcreditor)) $creditor=$conf->global->$paramcreditor;
+else if (! empty($conf->global->STRIPE_CREDITOR)) $creditor=$conf->global->STRIPE_CREDITOR;
+
+
 
 /*
  * Actions
@@ -218,17 +225,20 @@ if ($action == 'charge')
         dol_syslog("Create customer", LOG_DEBUG, 0, '_stripe');
         $customer = \Stripe\Customer::create(array(
             'email' => $email,
-            'card'  => $stripeToken
-            // TODO
+            'description' => ($email?'Customer for '.$email:null),
+            'metadata' => array('ipaddress'=>$_SERVER['REMOTE_ADDR']),
+            'source'  => $stripeToken           // source can be a token OR array('object'=>'card', 'exp_month'=>xx, 'exp_year'=>xxxx, 'number'=>xxxxxxx, 'cvc'=>xxx, 'name'=>'Cardholder's full name', zip ?)
         ));
-         
+        // TODO Add 'business_vat_id' ?
+        
         dol_syslog("Create charge", LOG_DEBUG, 0, '_stripe');
         $charge = \Stripe\Charge::create(array(
             'customer' => $customer->id,
             'amount'   => price2num($amount, 'MU'),
             'currency' => $currency,
             'description' => 'Stripe payment: '.$FULLTAG,
-            'statement_descriptor' => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 6, 'right', 'UTF-8', 1).' '.$FULLTAG, 22, 'right', 'UTF-8', 1)     // 22 chars
+            'metadata' => array("FULLTAG" => $FULLTAG, 'Recipient' => $mysoc->name),
+            'statement_descriptor' => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 6, 'right', 'UTF-8', 1).' '.$FULLTAG, 22, 'right', 'UTF-8', 1)     // 22 chars that appears on bank receipt
         ));
     } catch(\Stripe\Error\Card $e) {
         // Since it's a decline, \Stripe\Error\Card will be caught
@@ -330,12 +340,6 @@ if (empty($conf->global->STRIPE_LIVE))
     dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode'),'','warning');
 }
 
-// Common variables
-$creditor=$mysoc->name;
-$paramcreditor='STRIPE_CREDITOR_'.$suffix;
-if (! empty($conf->global->$paramcreditor)) $creditor=$conf->global->$paramcreditor;
-else if (! empty($conf->global->STRIPE_CREDITOR)) $creditor=$conf->global->STRIPE_CREDITOR;
-
 print '<span id="dolpaymentspan"></span>'."\n";
 print '<div class="center">'."\n";
 print '<form id="dolpaymentform" class="center" name="paymentform" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";

BIN
htdocs/theme/common/ical.gif


BIN
htdocs/theme/common/information.png


BIN
htdocs/theme/common/rss.gif


BIN
htdocs/theme/common/vcal.gif


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

@@ -1782,7 +1782,7 @@ font.vsmenudisabled { font-size:<?php print $fontsize ?>px; font-family: <?php p
 a.vsmenu:link, a.vsmenu:visited { color: #<?php echo $colortextbackvmenu; ?>; white-space: nowrap; }
 font.vsmenudisabledmargin { margin: 1px 1px 1px 6px; }
 
-a.help:link, a.help:visited, a.help:hover, a.help:active, span.help { font-size:<?php print $fontsizesmaller ?>px; font-family: <?php print $fontlist ?>; text-align: <?php print $left; ?>; font-weight: normal; color: #666666; text-decoration: none; }
+a.help:link, a.help:visited, a.help:hover, a.help:active, span.help { font-size:<?php print $fontsizesmaller ?>px; font-family: <?php print $fontlist ?>; text-align: <?php print $left; ?>; font-weight: normal; color: #aaa; text-decoration: none; }
 
 .vmenu div.blockvmenufirst, .vmenu div.blockvmenulogo, .vmenu div.blockvmenusearchphone, .vmenu div.blockvmenubookmarks
 {
@@ -1815,6 +1815,7 @@ div.blockvmenusearchphone
 }
 div.blockvmenubookmarks
 {
+	padding-top: 10px !important;
 	padding-bottom: 16px !important;
 }
 div.blockvmenupair, div.blockvmenuimpair, div.blockvmenubookmarks, div.blockvmenuend

BIN
htdocs/theme/login_background.png


+ 1 - 1
htdocs/theme/md/style.css.php

@@ -1805,7 +1805,7 @@ font.vsmenudisabled { font-size:<?php print $fontsize ?>px; font-family: <?php p
 a.vsmenu:link, a.vsmenu:visited { color: #<?php echo $colortextbackvmenu; ?>; white-space: nowrap; }
 font.vsmenudisabledmargin { margin: 1px 1px 1px 8px; }
 
-a.help:link, a.help:visited, a.help:hover, a.help:active, span.help { font-size:<?php print $fontsizesmaller ?>px; font-family: <?php print $fontlist ?>; text-align: <?php print $left; ?>; font-weight: normal; color: #666666; text-decoration: none; }
+a.help:link, a.help:visited, a.help:hover, a.help:active, span.help { font-size:<?php print $fontsizesmaller ?>px; font-family: <?php print $fontlist ?>; text-align: <?php print $left; ?>; font-weight: normal; color: #999; text-decoration: none; }
 
 div.blockvmenulogo
 {