浏览代码

Merge remote-tracking branch 'origin/3.6' into 3.7

Conflicts:
	ChangeLog
	htdocs/adherents/fiche.php
	htdocs/comm/fiche.php
	htdocs/comm/mailing/fiche.php
	htdocs/comm/propal.php
	htdocs/comm/propal/class/propal.class.php
	htdocs/commande/class/commande.class.php
	htdocs/commande/fiche.php
	htdocs/compta/facture.php
	htdocs/compta/paiement.php
	htdocs/core/class/html.formcompany.class.php
	htdocs/core/tpl/login.tpl.php
	htdocs/expedition/fiche.php
	htdocs/fourn/commande/fiche.php
	htdocs/fourn/facture/fiche.php
	htdocs/fourn/facture/paiement.php
	htdocs/fourn/fiche.php
	htdocs/main.inc.php
	htdocs/product/fournisseurs.php
	htdocs/resource/card.php
Laurent Destailleur 10 年之前
父节点
当前提交
5c5ff72ecd
共有 36 个文件被更改,包括 4538 次插入4048 次删除
  1. 3 0
      COPYRIGHT
  2. 14 0
      ChangeLog
  3. 435 433
      htdocs/adherents/card.php
  4. 60 59
      htdocs/comm/card.php
  5. 420 419
      htdocs/comm/mailing/card.php
  6. 678 548
      htdocs/comm/propal.php
  7. 13 16
      htdocs/comm/propal/class/propal.class.php
  8. 7 5
      htdocs/comm/prospect/list.php
  9. 622 496
      htdocs/commande/card.php
  10. 16 17
      htdocs/commande/class/commande.class.php
  11. 1157 1018
      htdocs/compta/facture.php
  12. 46 34
      htdocs/compta/facture/class/facture.class.php
  13. 1 1
      htdocs/compta/facture/impayees.php
  14. 155 152
      htdocs/compta/paiement.php
  15. 24 14
      htdocs/contrat/class/contrat.class.php
  16. 4 6
      htdocs/core/class/html.formcompany.class.php
  17. 1 1
      htdocs/core/class/menubase.class.php
  18. 4 0
      htdocs/core/modules/DolibarrModules.class.php
  19. 2 1
      htdocs/core/modules/supplier_invoice/mod_facture_fournisseur_tulip.php
  20. 8 4
      htdocs/cron/card.php
  21. 433 442
      htdocs/expedition/card.php
  22. 26 17
      htdocs/expedition/class/expedition.class.php
  23. 21 12
      htdocs/fichinter/class/fichinter.class.php
  24. 28 25
      htdocs/fourn/card.php
  25. 30 26
      htdocs/fourn/class/fournisseur.commande.class.php
  26. 7 3
      htdocs/fourn/class/fournisseur.facture.class.php
  27. 150 147
      htdocs/fourn/facture/paiement.php
  28. 2 2
      htdocs/langs/en_US/admin.lang
  29. 1 0
      htdocs/langs/en_US/main.lang
  30. 1 1
      htdocs/main.inc.php
  31. 12 1
      htdocs/margin/index.php
  32. 14 9
      htdocs/margin/lib/margins.lib.php
  33. 10 6
      htdocs/product/document.php
  34. 100 99
      htdocs/product/fournisseurs.php
  35. 2 2
      htdocs/projet/element.php
  36. 31 32
      htdocs/resource/card.php

+ 3 - 0
COPYRIGHT

@@ -52,6 +52,9 @@ http://www.fsf.org/licensing/licenses/index_html
 Copyright
 ---------
 
+Copyright (C) 2015
+- Marcos García <marcosgdf@gmail.com>
+
 Copyright (C) 2014
 - Laurent Destailleur <eldy@users.sourceforge.net>
 - Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>

+ 14 - 0
ChangeLog

@@ -174,6 +174,18 @@ Dolibarr better:
 - Fix: ref_ext was not saved when recording a customer order from web service
 - Fix: amarok is a bugged theme making dolidroid failed. We swith to eldy automatically with dolidroid.
 - Fix: withdrawal create error if in the same month are deleted previus withdrawals.
+- Fix: [ bug #1788 ] Duplicated doActions hook in product/fournisseurs.php
+- Fix: withdrawal create error if in the same month are deleted previus withdrawals.
+- Fix: [ bug #1801 ] FAC_FORCE_DATE_VALIDATION constant alters supplier invoice date given to numeration modules
+- Fix: [ bug #1802 ] SQL error when updating a task with PostgreSQL database
+- Fix: [ bug #1785 ] Start date is lost in Project > Linked objects
+- Fix: [ bug #1804 ] SQL error when sending email without addresee
+- Fix: [ bug #1803 ] AJAX company contact input is not aligned
+- Fix: [ bug #1787 ] Incorrect behaviour of doActions hook
+- Fix: [ bug #1796 ] Unable to use numeration modules from an external module
+- Fix: [ bug #1783 ] SQL error when enabling 3rd party module with PostgreSQL and MySQL strict mode ON
+- Fix: [ bug #1717 ] Sorting unpaid invoices by amount received brings due amount
+- Fix: [ bug #1784 ] MOTD doesn't show up in Amarok theme
 
 ***** ChangeLog for 3.6.2 compared to 3.6.1 *****
 - Fix: fix ErrorBadValueForParamNotAString error message in price customer multiprice.
@@ -338,6 +350,8 @@ Fix: Paypal link were broken dur to SSL v3 closed.
 Fix: [ bug #1769 ] Error when installing to a PostgreSQL DB that contains numbers
 Fix: [ bug #1752 ] Date filter of margins module, filters since 12H instead of 00H
 Fix: [ bug #1757 ] Sorting breaks product/service statistics
+Fix: [ bug #1797 ] Tulip supplier invoice module takes creation date instead of invoice date
+Fix: [ bug #1792 ] Users are not allowed to see margins module index page when no product view permission is enabled
 
 ***** ChangeLog for 3.5.6 compared to 3.5.5 *****
 Fix: Avoid missing class error for fetch_thirdparty method #1973

+ 435 - 433
htdocs/adherents/card.php

@@ -119,572 +119,574 @@ $parameters=array('rowid'=>$rowid, 'objcanvas'=>$objcanvas);
 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
 
-if ($action == 'setuserid' && ($user->rights->user->self->creer || $user->rights->user->user->creer))
+if (empty($reshook))
 {
-	$error=0;
-	if (empty($user->rights->user->user->creer))	// If can edit only itself user, we can link to itself only
+	if ($action == 'setuserid' && ($user->rights->user->self->creer || $user->rights->user->user->creer))
 	{
-		if ($userid != $user->id && $userid != $object->user_id)
+		$error=0;
+		if (empty($user->rights->user->user->creer))	// If can edit only itself user, we can link to itself only
 		{
-			$error++;
-			setEventMessage($langs->trans("ErrorUserPermissionAllowsToLinksToItselfOnly"), 'errors');
+			if ($userid != $user->id && $userid != $object->user_id)
+			{
+				$error++;
+				setEventMessage($langs->trans("ErrorUserPermissionAllowsToLinksToItselfOnly"), 'errors');
+			}
 		}
-	}
 
-	if (! $error)
-	{
-		if ($userid != $object->user_id)	// If link differs from currently in database
+		if (! $error)
 		{
-			$result=$object->setUserId($userid);
-			if ($result < 0) dol_print_error($object->db,$object->error);
-			$action='';
+			if ($userid != $object->user_id)	// If link differs from currently in database
+			{
+				$result=$object->setUserId($userid);
+				if ($result < 0) dol_print_error($object->db,$object->error);
+				$action='';
+			}
 		}
 	}
-}
 
-if ($action == 'setsocid')
-{
-	$error=0;
-	if (! $error)
+	if ($action == 'setsocid')
 	{
-		if ($socid != $object->fk_soc)	// If link differs from currently in database
+		$error=0;
+		if (! $error)
 		{
-			$sql ="SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
-			$sql.=" WHERE fk_soc = '".$socid."'";
-			$sql.=" AND entity = ".$conf->entity;
-			$resql = $db->query($sql);
-			if ($resql)
+			if ($socid != $object->fk_soc)	// If link differs from currently in database
 			{
-				$obj = $db->fetch_object($resql);
-				if ($obj && $obj->rowid > 0)
+				$sql ="SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
+				$sql.=" WHERE fk_soc = '".$socid."'";
+				$sql.=" AND entity = ".$conf->entity;
+				$resql = $db->query($sql);
+				if ($resql)
 				{
-					$othermember=new Adherent($db);
-					$othermember->fetch($obj->rowid);
-					$thirdparty=new Societe($db);
-					$thirdparty->fetch($socid);
-					$error++;
-					setEventMessage($langs->trans("ErrorMemberIsAlreadyLinkedToThisThirdParty",$othermember->getFullName($langs),$othermember->login,$thirdparty->name), 'errors');
+					$obj = $db->fetch_object($resql);
+					if ($obj && $obj->rowid > 0)
+					{
+						$othermember=new Adherent($db);
+						$othermember->fetch($obj->rowid);
+						$thirdparty=new Societe($db);
+						$thirdparty->fetch($socid);
+						$error++;
+						setEventMessage($langs->trans("ErrorMemberIsAlreadyLinkedToThisThirdParty",$othermember->getFullName($langs),$othermember->login,$thirdparty->name), 'errors');
+					}
 				}
-			}
 
-			if (! $error)
-			{
-				$result=$object->setThirdPartyId($socid);
-				if ($result < 0) dol_print_error($object->db,$object->error);
-				$action='';
+				if (! $error)
+				{
+					$result=$object->setThirdPartyId($socid);
+					if ($result < 0) dol_print_error($object->db,$object->error);
+					$action='';
+				}
 			}
 		}
 	}
-}
 
-// Create user from a member
-if ($action == 'confirm_create_user' && $confirm == 'yes' && $user->rights->user->user->creer)
-{
-	if ($result > 0)
+	// Create user from a member
+	if ($action == 'confirm_create_user' && $confirm == 'yes' && $user->rights->user->user->creer)
 	{
-		// Creation user
-		$nuser = new User($db);
-		$result=$nuser->create_from_member($object,GETPOST('login'));
+		if ($result > 0)
+		{
+			// Creation user
+			$nuser = new User($db);
+			$result=$nuser->create_from_member($object,GETPOST('login'));
 
-		if ($result < 0)
+			if ($result < 0)
+			{
+				$langs->load("errors");
+				setEventMessage($langs->trans($nuser->error), 'errors');
+			}
+		}
+		else
 		{
-			$langs->load("errors");
-			setEventMessage($langs->trans($nuser->error), 'errors');
+			setEventMessage($object->error, 'errors');
 		}
 	}
-	else
-	{
-		setEventMessage($object->error, 'errors');
-	}
-}
 
-// Create third party from a member
-if ($action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->rights->societe->creer)
-{
-	if ($result > 0)
+	// Create third party from a member
+	if ($action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->rights->societe->creer)
 	{
-		// Creation user
-		$company = new Societe($db);
-		$result=$company->create_from_member($object,GETPOST('companyname'));
+		if ($result > 0)
+		{
+			// Creation user
+			$company = new Societe($db);
+			$result=$company->create_from_member($object,GETPOST('companyname'));
 
-		if ($result < 0)
+			if ($result < 0)
+			{
+				$langs->load("errors");
+				setEventMessage($langs->trans($company->error), 'errors');
+				setEventMessage($company->errors, 'errors');
+			}
+		}
+		else
 		{
-			$langs->load("errors");
-			setEventMessage($langs->trans($company->error), 'errors');
-			setEventMessage($company->errors, 'errors');
+			setEventMessage($object->error, 'errors');
 		}
 	}
-	else
-	{
-		setEventMessage($object->error, 'errors');
-	}
-}
 
-if ($action == 'confirm_sendinfo' && $confirm == 'yes')
-{
-	if ($object->email)
+	if ($action == 'confirm_sendinfo' && $confirm == 'yes')
 	{
-		$from=$conf->email_from;
-		if (! empty($conf->global->ADHERENT_MAIL_FROM)) $from=$conf->global->ADHERENT_MAIL_FROM;
-
-		$result=$object->send_an_email($langs->transnoentitiesnoconv("ThisIsContentOfYourCard")."\n\n%INFOS%\n\n",$langs->transnoentitiesnoconv("CardContent"));
-
-		$langs->load("mails");
-		setEventMessage($langs->trans("MailSuccessfulySent", $from, $object->email));
-	}
-}
+		if ($object->email)
+		{
+			$from=$conf->email_from;
+			if (! empty($conf->global->ADHERENT_MAIL_FROM)) $from=$conf->global->ADHERENT_MAIL_FROM;
 
-if ($action == 'update' && ! $_POST["cancel"] && $user->rights->adherent->creer)
-{
-	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+			$result=$object->send_an_email($langs->transnoentitiesnoconv("ThisIsContentOfYourCard")."\n\n%INFOS%\n\n",$langs->transnoentitiesnoconv("CardContent"));
 
-	$birthdate='';
-	if (isset($_POST["birthday"]) && $_POST["birthday"]
-			&& isset($_POST["birthmonth"]) && $_POST["birthmonth"]
-			&& isset($_POST["birthyear"]) && $_POST["birthyear"])
-	{
-		$birthdate=dol_mktime(12, 0, 0, $_POST["birthmonth"], $_POST["birthday"], $_POST["birthyear"]);
-	}
-	$lastname=$_POST["lastname"];
-	$firstname=$_POST["firstname"];
-	$morphy=$morphy=$_POST["morphy"];;
-	if ($morphy != 'mor' && empty($lastname)) {
-		$error++;
-		$langs->load("errors");
-		setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname")), 'errors');
-	}
-	if ($morphy != 'mor' && (!isset($firstname) || $firstname=='')) {
-		$error++;
-		$langs->load("errors");
-		setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Firstname")), 'errors');
+			$langs->load("mails");
+			setEventMessage($langs->trans("MailSuccessfulySent", $from, $object->email));
+		}
 	}
 
-	// Create new object
-	if ($result > 0 && ! $error)
+	if ($action == 'update' && ! $_POST["cancel"] && $user->rights->adherent->creer)
 	{
-		$object->oldcopy=dol_clone($object);
-
-		// Change values
-		$object->civility_id = trim($_POST["civility_id"]);
-		$object->firstname   = trim($_POST["firstname"]);
-		$object->lastname    = trim($_POST["lastname"]);
-		$object->login       = trim($_POST["login"]);
-		$object->pass        = trim($_POST["pass"]);
-
-		$object->societe     = trim($_POST["societe"]);
-		$object->company     = trim($_POST["societe"]);
-
-		$object->address     = trim($_POST["address"]);
-		$object->zip         = trim($_POST["zipcode"]);
-		$object->town        = trim($_POST["town"]);
-		$object->state_id    = $_POST["state_id"];
-		$object->country_id  = $_POST["country_id"];
-
-		$object->phone       = trim($_POST["phone"]);
-		$object->phone_perso = trim($_POST["phone_perso"]);
-		$object->phone_mobile= trim($_POST["phone_mobile"]);
-		$object->email       = trim($_POST["email"]);
-		$object->skype       = trim($_POST["skype"]);
-		$object->birth       = $birthdate;
-
-		$object->typeid      = $_POST["typeid"];
-		//$object->note        = trim($_POST["comment"]);
-		$object->morphy      = $_POST["morphy"];
-
-		if (GETPOST('deletephoto')) $object->photo='';
-		elseif (! empty($_FILES['photo']['name'])) $object->photo  = dol_sanitizeFileName($_FILES['photo']['name']);
-
-		// Get status and public property
-		$object->statut      = $_POST["statut"];
-		$object->public      = $_POST["public"];
-
-		// Fill array 'array_options' with data from add form
-		$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
 
-		// Check if we need to also synchronize user information
-		$nosyncuser=0;
-		if ($object->user_id)	// If linked to a user
+		$birthdate='';
+		if (isset($_POST["birthday"]) && $_POST["birthday"]
+				&& isset($_POST["birthmonth"]) && $_POST["birthmonth"]
+				&& isset($_POST["birthyear"]) && $_POST["birthyear"])
 		{
-			if ($user->id != $object->user_id && empty($user->rights->user->user->creer)) $nosyncuser=1;		// Disable synchronizing
+			$birthdate=dol_mktime(12, 0, 0, $_POST["birthmonth"], $_POST["birthday"], $_POST["birthyear"]);
 		}
-
-		// Check if we need to also synchronize password information
-		$nosyncuserpass=0;
-		if ($object->user_id)	// If linked to a user
-		{
-			if ($user->id != $object->user_id && empty($user->rights->user->user->password)) $nosyncuserpass=1;	// Disable synchronizing
+		$lastname=$_POST["lastname"];
+		$firstname=$_POST["firstname"];
+		$morphy=$morphy=$_POST["morphy"];;
+		if ($morphy != 'mor' && empty($lastname)) {
+			$error++;
+			$langs->load("errors");
+			setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname")), 'errors');
+		}
+		if ($morphy != 'mor' && (!isset($firstname) || $firstname=='')) {
+			$error++;
+			$langs->load("errors");
+			setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Firstname")), 'errors');
 		}
 
-		$result=$object->update($user,0,$nosyncuser,$nosyncuserpass);
-		if ($result >= 0 && ! count($object->errors))
+		// Create new object
+		if ($result > 0 && ! $error)
 		{
-			// Logo/Photo save
-			$dir= $conf->adherent->dir_output . '/' . get_exdir($object->id,2,0,1).'/photos';
-			$file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
-			if ($file_OK)
+			$object->oldcopy=dol_clone($object);
+
+			// Change values
+			$object->civility_id = trim($_POST["civility_id"]);
+			$object->firstname   = trim($_POST["firstname"]);
+			$object->lastname    = trim($_POST["lastname"]);
+			$object->login       = trim($_POST["login"]);
+			$object->pass        = trim($_POST["pass"]);
+
+			$object->societe     = trim($_POST["societe"]);
+			$object->company     = trim($_POST["societe"]);
+
+			$object->address     = trim($_POST["address"]);
+			$object->zip         = trim($_POST["zipcode"]);
+			$object->town        = trim($_POST["town"]);
+			$object->state_id    = $_POST["state_id"];
+			$object->country_id  = $_POST["country_id"];
+
+			$object->phone       = trim($_POST["phone"]);
+			$object->phone_perso = trim($_POST["phone_perso"]);
+			$object->phone_mobile= trim($_POST["phone_mobile"]);
+			$object->email       = trim($_POST["email"]);
+			$object->skype       = trim($_POST["skype"]);
+			$object->birth       = $birthdate;
+
+			$object->typeid      = $_POST["typeid"];
+			//$object->note        = trim($_POST["comment"]);
+			$object->morphy      = $_POST["morphy"];
+
+			if (GETPOST('deletephoto')) $object->photo='';
+			elseif (! empty($_FILES['photo']['name'])) $object->photo  = dol_sanitizeFileName($_FILES['photo']['name']);
+
+			// Get status and public property
+			$object->statut      = $_POST["statut"];
+			$object->public      = $_POST["public"];
+
+			// Fill array 'array_options' with data from add form
+			$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+
+			// Check if we need to also synchronize user information
+			$nosyncuser=0;
+			if ($object->user_id)	// If linked to a user
 			{
-				if (GETPOST('deletephoto'))
-				{
-					require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
-					$fileimg=$conf->adherent->dir_output.'/'.get_exdir($object->id,2,0,1).'/photos/'.$object->photo;
-					$dirthumbs=$conf->adherent->dir_output.'/'.get_exdir($object->id,2,0,1).'/photos/thumbs';
-					dol_delete_file($fileimg);
-					dol_delete_dir_recursive($dirthumbs);
-				}
+				if ($user->id != $object->user_id && empty($user->rights->user->user->creer)) $nosyncuser=1;		// Disable synchronizing
+			}
 
-				if (image_format_supported($_FILES['photo']['name']) > 0)
+			// Check if we need to also synchronize password information
+			$nosyncuserpass=0;
+			if ($object->user_id)	// If linked to a user
+			{
+				if ($user->id != $object->user_id && empty($user->rights->user->user->password)) $nosyncuserpass=1;	// Disable synchronizing
+			}
+
+			$result=$object->update($user,0,$nosyncuser,$nosyncuserpass);
+			if ($result >= 0 && ! count($object->errors))
+			{
+				// Logo/Photo save
+				$dir= $conf->adherent->dir_output . '/' . get_exdir($object->id,2,0,1).'/photos';
+				$file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
+				if ($file_OK)
 				{
-					dol_mkdir($dir);
+					if (GETPOST('deletephoto'))
+					{
+						require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
+						$fileimg=$conf->adherent->dir_output.'/'.get_exdir($object->id,2,0,1).'/photos/'.$object->photo;
+						$dirthumbs=$conf->adherent->dir_output.'/'.get_exdir($object->id,2,0,1).'/photos/thumbs';
+						dol_delete_file($fileimg);
+						dol_delete_dir_recursive($dirthumbs);
+					}
 
-					if (@is_dir($dir))
+					if (image_format_supported($_FILES['photo']['name']) > 0)
 					{
-						$newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
-						if (! dol_move_uploaded_file($_FILES['photo']['tmp_name'],$newfile,1,0,$_FILES['photo']['error']) > 0)
-						{
-							setEventMessage($langs->trans("ErrorFailedToSaveFile"), 'errors');
-						}
-						else
+						dol_mkdir($dir);
+
+						if (@is_dir($dir))
 						{
-							// Create small thumbs for company (Ratio is near 16/9)
-							// Used on logon for example
-							$imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality);
+							$newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
+							if (! dol_move_uploaded_file($_FILES['photo']['tmp_name'],$newfile,1,0,$_FILES['photo']['error']) > 0)
+							{
+								setEventMessage($langs->trans("ErrorFailedToSaveFile"), 'errors');
+							}
+							else
+							{
+								// Create small thumbs for company (Ratio is near 16/9)
+								// Used on logon for example
+								$imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality);
 
-							// Create mini thumbs for company (Ratio is near 16/9)
-							// Used on menu or for setup page for example
-							$imgThumbMini = vignette($newfile, $maxwidthmini, $maxheightmini, '_mini', $quality);
+								// Create mini thumbs for company (Ratio is near 16/9)
+								// Used on menu or for setup page for example
+								$imgThumbMini = vignette($newfile, $maxwidthmini, $maxheightmini, '_mini', $quality);
+							}
 						}
 					}
+					else
+					{
+						setEventMessage("ErrorBadImageFormat", 'errors');
+					}
 				}
 				else
 				{
-					setEventMessage("ErrorBadImageFormat", 'errors');
+					switch($_FILES['photo']['error'])
+					{
+						case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
+						case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
+							$errors[] = "ErrorFileSizeTooLarge";
+							break;
+						case 3: //uploaded file was only partially uploaded
+							$errors[] = "ErrorFilePartiallyUploaded";
+							break;
+					}
 				}
-			}
-			else
-			{
-				switch($_FILES['photo']['error'])
+
+	            $rowid=$object->id;
+				$action='';
+
+				if (! empty($backtopage))
 				{
-					case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
-					case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
-						$errors[] = "ErrorFileSizeTooLarge";
-						break;
-					case 3: //uploaded file was only partially uploaded
-						$errors[] = "ErrorFilePartiallyUploaded";
-						break;
+					header("Location: ".$backtopage);
+					exit;
 				}
 			}
-
-            $rowid=$object->id;
-			$action='';
-
-			if (! empty($backtopage))
+			else
 			{
-				header("Location: ".$backtopage);
-				exit;
+				if ($object->error) {
+					setEventMessage($object->error, 'errors');
+				} else {
+					setEventMessage($object->errors, 'errors');
+				}
+				$action='';
 			}
 		}
 		else
 		{
-			if ($object->error) {
-				setEventMessage($object->error, 'errors');
-			} else {
-				setEventMessage($object->errors, 'errors');
-			}
-			$action='';
+			$action='edit';
 		}
 	}
-	else
-	{
-		$action='edit';
-	}
-}
 
-if ($action == 'add' && $user->rights->adherent->creer)
-{
-	if ($canvas) $object->canvas=$canvas;
-	$birthdate='';
-	if (isset($_POST["birthday"]) && $_POST["birthday"]
-			&& isset($_POST["birthmonth"]) && $_POST["birthmonth"]
-			&& isset($_POST["birthyear"]) && $_POST["birthyear"])
-	{
-		$birthdate=dol_mktime(12, 0, 0, $_POST["birthmonth"], $_POST["birthday"], $_POST["birthyear"]);
-	}
-	$datecotisation='';
-	if (isset($_POST["reday"]) && isset($_POST["remonth"]) && isset($_POST["reyear"]))
+	if ($action == 'add' && $user->rights->adherent->creer)
 	{
-		$datecotisation=dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
-	}
+		if ($canvas) $object->canvas=$canvas;
+		$birthdate='';
+		if (isset($_POST["birthday"]) && $_POST["birthday"]
+				&& isset($_POST["birthmonth"]) && $_POST["birthmonth"]
+				&& isset($_POST["birthyear"]) && $_POST["birthyear"])
+		{
+			$birthdate=dol_mktime(12, 0, 0, $_POST["birthmonth"], $_POST["birthday"], $_POST["birthyear"]);
+		}
+		$datecotisation='';
+		if (isset($_POST["reday"]) && isset($_POST["remonth"]) && isset($_POST["reyear"]))
+		{
+			$datecotisation=dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
+		}
+
+		$typeid=$_POST["typeid"];
+		$civility_id=$_POST["civility_id"];
+		$lastname=$_POST["lastname"];
+		$firstname=$_POST["firstname"];
+		$societe=$_POST["societe"];
+		$address=$_POST["address"];
+		$zip=$_POST["zipcode"];
+		$town=$_POST["town"];
+		$state_id=$_POST["state_id"];
+		$country_id=$_POST["country_id"];
+
+		$phone=$_POST["phone"];
+		$phone_perso=$_POST["phone_perso"];
+		$phone_mobile=$_POST["phone_mobile"];
+		$skype=$_POST["member_skype"];
+		$email=$_POST["member_email"];
+		$login=$_POST["member_login"];
+		$pass=$_POST["password"];
+		$photo=$_POST["photo"];
+		//$comment=$_POST["comment"];
+		$morphy=$_POST["morphy"];
+		$cotisation=$_POST["cotisation"];
+		$public=$_POST["public"];
+
+		$userid=$_POST["userid"];
+		$socid=$_POST["socid"];
+
+		$object->civility_id = $civility_id;
+		$object->firstname   = $firstname;
+		$object->lastname    = $lastname;
+		$object->societe     = $societe;
+		$object->address     = $address;
+		$object->zip         = $zip;
+		$object->town        = $town;
+		$object->state_id    = $state_id;
+		$object->country_id  = $country_id;
+		$object->phone       = $phone;
+		$object->phone_perso = $phone_perso;
+		$object->phone_mobile= $phone_mobile;
+		$object->skype       = $skype;
+		$object->email       = $email;
+		$object->login       = $login;
+		$object->pass        = $pass;
+		$object->birth       = $birthdate;
+		$object->photo       = $photo;
+		$object->typeid      = $typeid;
+		//$object->note        = $comment;
+		$object->morphy      = $morphy;
+		$object->user_id     = $userid;
+		$object->fk_soc      = $socid;
+		$object->public      = $public;
 
-	$typeid=$_POST["typeid"];
-	$civility_id=$_POST["civility_id"];
-	$lastname=$_POST["lastname"];
-	$firstname=$_POST["firstname"];
-	$societe=$_POST["societe"];
-	$address=$_POST["address"];
-	$zip=$_POST["zipcode"];
-	$town=$_POST["town"];
-	$state_id=$_POST["state_id"];
-	$country_id=$_POST["country_id"];
-
-	$phone=$_POST["phone"];
-	$phone_perso=$_POST["phone_perso"];
-	$phone_mobile=$_POST["phone_mobile"];
-	$skype=$_POST["member_skype"];
-	$email=$_POST["member_email"];
-	$login=$_POST["member_login"];
-	$pass=$_POST["password"];
-	$photo=$_POST["photo"];
-	//$comment=$_POST["comment"];
-	$morphy=$_POST["morphy"];
-	$cotisation=$_POST["cotisation"];
-	$public=$_POST["public"];
-
-	$userid=$_POST["userid"];
-	$socid=$_POST["socid"];
-
-	$object->civility_id = $civility_id;
-	$object->firstname   = $firstname;
-	$object->lastname    = $lastname;
-	$object->societe     = $societe;
-	$object->address     = $address;
-	$object->zip         = $zip;
-	$object->town        = $town;
-	$object->state_id    = $state_id;
-	$object->country_id  = $country_id;
-	$object->phone       = $phone;
-	$object->phone_perso = $phone_perso;
-	$object->phone_mobile= $phone_mobile;
-	$object->skype       = $skype;
-	$object->email       = $email;
-	$object->login       = $login;
-	$object->pass        = $pass;
-	$object->birth       = $birthdate;
-	$object->photo       = $photo;
-	$object->typeid      = $typeid;
-	//$object->note        = $comment;
-	$object->morphy      = $morphy;
-	$object->user_id     = $userid;
-	$object->fk_soc      = $socid;
-	$object->public      = $public;
-
-	// Fill array 'array_options' with data from add form
-	$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
-
-	// Check parameters
-	if (empty($morphy) || $morphy == "-1") {
-		$error++;
-		setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Nature")), 'errors');
-	}
-	// Test si le login existe deja
-	if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
-	{
-		if (empty($login)) {
+		// Fill array 'array_options' with data from add form
+		$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+
+		// Check parameters
+		if (empty($morphy) || $morphy == "-1") {
 			$error++;
-			setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Login")), 'errors');
+			setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Nature")), 'errors');
 		}
-		else {
-			$sql = "SELECT login FROM ".MAIN_DB_PREFIX."adherent WHERE login='".$db->escape($login)."'";
-			$result = $db->query($sql);
-			if ($result) {
-				$num = $db->num_rows($result);
+		// Test si le login existe deja
+		if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
+		{
+			if (empty($login)) {
+				$error++;
+				setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Login")), 'errors');
 			}
-			if ($num) {
+			else {
+				$sql = "SELECT login FROM ".MAIN_DB_PREFIX."adherent WHERE login='".$db->escape($login)."'";
+				$result = $db->query($sql);
+				if ($result) {
+					$num = $db->num_rows($result);
+				}
+				if ($num) {
+					$error++;
+					$langs->load("errors");
+					setEventMessage($langs->trans("ErrorLoginAlreadyExists",$login), 'errors');
+				}
+			}
+			if (empty($pass)) {
 				$error++;
-				$langs->load("errors");
-				setEventMessage($langs->trans("ErrorLoginAlreadyExists",$login), 'errors');
+				setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Password")), 'errors');
 			}
 		}
-		if (empty($pass)) {
+		if ($morphy != 'mor' && empty($lastname)) {
 			$error++;
-			setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Password")), 'errors');
+			$langs->load("errors");
+			setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname")), 'errors');
 		}
-	}
-	if ($morphy != 'mor' && empty($lastname)) {
-		$error++;
-		$langs->load("errors");
-		setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname")), 'errors');
-	}
-	if ($morphy != 'mor' && (!isset($firstname) || $firstname=='')) {
-		$error++;
-		$langs->load("errors");
-		setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Firstname")), 'errors');
-	}
-	if (! ($typeid > 0)) {	// Keep () before !
-		$error++;
-		setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")), 'errors');
-	}
-	if ($conf->global->ADHERENT_MAIL_REQUIRED && ! isValidEMail($email)) {
-		$error++;
-		$langs->load("errors");
-		setEventMessage($langs->trans("ErrorBadEMail",$email), 'errors');
-	}
-	$public=0;
-	if (isset($public)) $public=1;
-
-	if (! $error)
-	{
-		$db->begin();
-
-		// Email a peu pres correct et le login n'existe pas
-		$result=$object->create($user);
-		if ($result > 0)
-		{
-			$db->commit();
-			$rowid=$object->id;
-			$action='';
+		if ($morphy != 'mor' && (!isset($firstname) || $firstname=='')) {
+			$error++;
+			$langs->load("errors");
+			setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Firstname")), 'errors');
 		}
-		else
+		if (! ($typeid > 0)) {	// Keep () before !
+			$error++;
+			setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")), 'errors');
+		}
+		if ($conf->global->ADHERENT_MAIL_REQUIRED && ! isValidEMail($email)) {
+			$error++;
+			$langs->load("errors");
+			setEventMessage($langs->trans("ErrorBadEMail",$email), 'errors');
+		}
+		$public=0;
+		if (isset($public)) $public=1;
+
+		if (! $error)
 		{
-			$db->rollback();
+			$db->begin();
 
-			if ($object->error) {
-				setEventMessage($object->error, 'errors');
-			} else {
-				setEventMessage($object->errors, 'errors');
+			// Email a peu pres correct et le login n'existe pas
+			$result=$object->create($user);
+			if ($result > 0)
+			{
+				$db->commit();
+				$rowid=$object->id;
+				$action='';
 			}
+			else
+			{
+				$db->rollback();
 
-			$action = 'create';
-		}
-	}
-	else {
-		$action = 'create';
-	}
-}
+				if ($object->error) {
+					setEventMessage($object->error, 'errors');
+				} else {
+					setEventMessage($object->errors, 'errors');
+				}
 
-if ($user->rights->adherent->supprimer && $action == 'confirm_delete' && $confirm == 'yes')
-{
-	$result=$object->delete($rowid);
-	if ($result > 0)
-	{
-		if (! empty($backtopage))
-		{
-			header("Location: ".$backtopage);
-			exit;
+				$action = 'create';
+			}
 		}
-		else
-		{
-			header("Location: list.php");
-			exit;
+		else {
+			$action = 'create';
 		}
 	}
-	else
-	{
-		$errmesg=$object->error;
-	}
-}
-
-if ($user->rights->adherent->creer && $action == 'confirm_valid' && $confirm == 'yes')
-{
-	$error=0;
-
-	$db->begin();
-
-	$adht = new AdherentType($db);
-	$adht->fetch($object->typeid);
-
-	$result=$object->validate($user);
 
-	if ($result >= 0 && ! count($object->errors))
+	if ($user->rights->adherent->supprimer && $action == 'confirm_delete' && $confirm == 'yes')
 	{
-		// Send confirmation Email (selon param du type adherent sinon generique)
-		if ($object->email && GETPOST("send_mail"))
+		$result=$object->delete($rowid);
+		if ($result > 0)
 		{
-			$result=$object->send_an_email($adht->getMailOnValid(),$conf->global->ADHERENT_MAIL_VALID_SUBJECT,array(),array(),array(),"","",0,2);
-			if ($result < 0)
+			if (! empty($backtopage))
 			{
-				$error++;
-				setEventMessage($object->error, 'errors');
+				header("Location: ".$backtopage);
+				exit;
+			}
+			else
+			{
+				header("Location: list.php");
+				exit;
 			}
 		}
-	}
-	else
-	{
-		$error++;
-		if ($object->error) {
-			setEventMessage($object->error, 'errors');
-		} else {
-			setEventMessage($object->errors, 'errors');
+		else
+		{
+			$errmesg=$object->error;
 		}
 	}
 
-	if (! $error)
+	if ($user->rights->adherent->creer && $action == 'confirm_valid' && $confirm == 'yes')
 	{
-		$db->commit();
-	}
-	else
-	{
-		$db->rollback();
-	}
-	$action='';
-}
+		$error=0;
 
-if ($user->rights->adherent->supprimer && $action == 'confirm_resign')
-{
-	$error = 0;
+		$db->begin();
 
-	if ($confirm == 'yes')
-	{
 		$adht = new AdherentType($db);
 		$adht->fetch($object->typeid);
 
-		$result=$object->resiliate($user);
+		$result=$object->validate($user);
 
 		if ($result >= 0 && ! count($object->errors))
 		{
+			// Send confirmation Email (selon param du type adherent sinon generique)
 			if ($object->email && GETPOST("send_mail"))
 			{
-				$result=$object->send_an_email($adht->getMailOnResiliate(),$conf->global->ADHERENT_MAIL_RESIL_SUBJECT,array(),array(),array(),"","",0,-1);
-			}
-			if ($result < 0)
-			{
-				$error++;
-				setEventMessage($object->error, 'errors');
+				$result=$object->send_an_email($adht->getMailOnValid(),$conf->global->ADHERENT_MAIL_VALID_SUBJECT,array(),array(),array(),"","",0,2);
+				if ($result < 0)
+				{
+					$error++;
+					setEventMessage($object->error, 'errors');
+				}
 			}
 		}
 		else
 		{
 			$error++;
-
 			if ($object->error) {
 				setEventMessage($object->error, 'errors');
 			} else {
 				setEventMessage($object->errors, 'errors');
 			}
-			$action='';
 		}
+
+		if (! $error)
+		{
+			$db->commit();
+		}
+		else
+		{
+			$db->rollback();
+		}
+		$action='';
 	}
-	if (! empty($backtopage) && ! $error)
+
+	if ($user->rights->adherent->supprimer && $action == 'confirm_resign')
 	{
-		header("Location: ".$backtopage);
-		exit;
+		$error = 0;
+
+		if ($confirm == 'yes')
+		{
+			$adht = new AdherentType($db);
+			$adht->fetch($object->typeid);
+
+			$result=$object->resiliate($user);
+
+			if ($result >= 0 && ! count($object->errors))
+			{
+				if ($object->email && GETPOST("send_mail"))
+				{
+					$result=$object->send_an_email($adht->getMailOnResiliate(),$conf->global->ADHERENT_MAIL_RESIL_SUBJECT,array(),array(),array(),"","",0,-1);
+				}
+				if ($result < 0)
+				{
+					$error++;
+					setEventMessage($object->error, 'errors');
+				}
+			}
+			else
+			{
+				$error++;
+
+				if ($object->error) {
+					setEventMessage($object->error, 'errors');
+				} else {
+					setEventMessage($object->errors, 'errors');
+				}
+				$action='';
+			}
+		}
+		if (! empty($backtopage) && ! $error)
+		{
+			header("Location: ".$backtopage);
+			exit;
+		}
 	}
-}
 
-// SPIP Management
-if ($user->rights->adherent->supprimer && $action == 'confirm_del_spip' && $confirm == 'yes')
-{
-	if (! count($object->errors))
+	// SPIP Management
+	if ($user->rights->adherent->supprimer && $action == 'confirm_del_spip' && $confirm == 'yes')
 	{
-		if (!$mailmanspip->del_to_spip($object))
+		if (! count($object->errors))
 		{
-			setEventMessage($langs->trans('DeleteIntoSpipError').': '.$mailmanspip->error, 'errors');
+			if (!$mailmanspip->del_to_spip($object))
+			{
+				setEventMessage($langs->trans('DeleteIntoSpipError').': '.$mailmanspip->error, 'errors');
+			}
 		}
 	}
-}
 
-if ($user->rights->adherent->creer && $action == 'confirm_add_spip' && $confirm == 'yes')
-{
-	if (! count($object->errors))
+	if ($user->rights->adherent->creer && $action == 'confirm_add_spip' && $confirm == 'yes')
 	{
-		if (!$mailmanspip->add_to_spip($object))
+		if (! count($object->errors))
 		{
-			setEventMessage($langs->trans('AddIntoSpipError').': '.$mailmanspip->error, 'errors');
+			if (!$mailmanspip->add_to_spip($object))
+			{
+				setEventMessage($langs->trans('AddIntoSpipError').': '.$mailmanspip->error, 'errors');
+			}
 		}
 	}
 }
 
 
-
 /*
  * View
  */

+ 60 - 59
htdocs/comm/card.php

@@ -66,6 +66,7 @@ $pageprev = $page - 1;
 $pagenext = $page + 1;
 if (! $sortorder) $sortorder="ASC";
 if (! $sortfield) $sortfield="nom";
+$cancelbutton = GETPOST('cancel');
 
 // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
 $hookmanager->initHooks(array('commcard','globalcard'));
@@ -80,78 +81,78 @@ $parameters = array('socid' => $id);
 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some
 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
 
-//Some actions show a "cancel" input submit button with name="cancel"
-$cancelbutton = GETPOST('cancel');
-
-if ($action == 'setcustomeraccountancycode')
+if (empty($reshook))
 {
-	if (! $cancelbutton) 
+	if ($action == 'setcustomeraccountancycode')
 	{
-		$result=$object->fetch($id);
-		$object->code_compta=$_POST["customeraccountancycode"];
-		$result=$object->update($object->id,$user,1,1,0);
-		if ($result < 0)
+		if (! $cancelbutton)
 		{
-			setEventMessage($object->errors, 'errors');
+			$result=$object->fetch($id);
+			$object->code_compta=$_POST["customeraccountancycode"];
+			$result=$object->update($object->id,$user,1,1,0);
+			if ($result < 0)
+			{
+				setEventMessage($object->errors, 'errors');
+			}
 		}
+		$action="";
 	}
-	$action="";
-}
 
-// conditions de reglement
-if ($action == 'setconditions' && $user->rights->societe->creer)
-{
-	$object->fetch($id);
-	$result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int'));
-	if ($result < 0) dol_print_error($db,$object->error);
-}
-// mode de reglement
-if ($action == 'setmode' && $user->rights->societe->creer)
-{
-	$object->fetch($id);
-	$result=$object->setPaymentMethods(GETPOST('mode_reglement_id','int'));
-	if ($result < 0) dol_print_error($db,$object->error);
-}
-// assujetissement a la TVA
-if ($action == 'setassujtva' && $user->rights->societe->creer)
-{
-	$object->fetch($id);
-	$object->tva_assuj=$_POST['assujtva_value'];
-
-	// TODO move to DAO class
-	$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET tva_assuj='".$_POST['assujtva_value']."' WHERE rowid='".$id."'";
-	$result = $db->query($sql);
-	if (! $result) dol_print_error($result);
-}
+	// conditions de reglement
+	if ($action == 'setconditions' && $user->rights->societe->creer)
+	{
+		$object->fetch($id);
+		$result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int'));
+		if ($result < 0) dol_print_error($db,$object->error);
+	}
+	// mode de reglement
+	if ($action == 'setmode' && $user->rights->societe->creer)
+	{
+		$object->fetch($id);
+		$result=$object->setPaymentMethods(GETPOST('mode_reglement_id','int'));
+		if ($result < 0) dol_print_error($db,$object->error);
+	}
+	// assujetissement a la TVA
+	if ($action == 'setassujtva' && $user->rights->societe->creer)
+	{
+		$object->fetch($id);
+		$object->tva_assuj=$_POST['assujtva_value'];
 
-// set prospect level
-if ($action == 'setprospectlevel' && $user->rights->societe->creer)
-{
-	$object->fetch($id);
-	$object->fk_prospectlevel=GETPOST('prospect_level_id','alpha');
-	$result=$object->set_prospect_level($user);
-	if ($result < 0) setEventMessage($object->error,'errors');
-}
+		// TODO move to DAO class
+		$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET tva_assuj='".$_POST['assujtva_value']."' WHERE rowid='".$id."'";
+		$result = $db->query($sql);
+		if (! $result) dol_print_error($result);
+	}
 
-// Update communication level
-if ($action == 'cstc')
-{
-	$object->fetch($id);
-	$object->stcomm_id=GETPOST('stcomm','int');
-	$result=$object->set_commnucation_level($user);
-	if ($result < 0) setEventMessage($object->error,'errors');
-}
+	// set prospect level
+	if ($action == 'setprospectlevel' && $user->rights->societe->creer)
+	{
+		$object->fetch($id);
+		$object->fk_prospectlevel=GETPOST('prospect_level_id','alpha');
+		$result=$object->set_prospect_level($user);
+		if ($result < 0) setEventMessage($object->error,'errors');
+	}
 
-// Update communication level
-if ($action == 'setOutstandingBill')
-{
-	if (!$cancelbutton) 
+	// Update communication level
+	if ($action == 'cstc')
 	{
 		$object->fetch($id);
-		$object->outstanding_limit=GETPOST('OutstandingBill');
-		$result=$object->set_OutstandingBill($user);
+		$object->stcomm_id=GETPOST('stcomm','int');
+		$result=$object->set_commnucation_level($user);
 		if ($result < 0) setEventMessage($object->error,'errors');
 	}
+
+	// Update communication level
+	if ($action == 'setOutstandingBill')
+	{
+		if (!$cancelbutton)
+		{
+			$object->fetch($id);
+			$object->outstanding_limit=GETPOST('OutstandingBill');
+			$result=$object->set_OutstandingBill($user);
+			if ($result < 0) setEventMessage($object->error,'errors');
+		}
+	}
 }
 
 

+ 420 - 419
htdocs/comm/mailing/card.php

@@ -110,559 +110,560 @@ $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');
 
-// Action clone object
-if ($action == 'confirm_clone' && $confirm == 'yes')
+if (empty($reshook))
 {
-	if (empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"]))
+	// Action clone object
+	if ($action == 'confirm_clone' && $confirm == 'yes')
 	{
-		setEventMessage($langs->trans("NoCloneOptionsSpecified"), 'errors');
-	}
-	else
-	{
-		$result=$object->createFromClone($object->id,$_REQUEST["clone_content"],$_REQUEST["clone_receivers"]);
-		if ($result > 0)
+		if (empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"]))
 		{
-			header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
-			exit;
+			setEventMessage($langs->trans("NoCloneOptionsSpecified"), 'errors');
 		}
 		else
 		{
-			setEventMessage($object->error, 'errors');
+			$result=$object->createFromClone($object->id,$_REQUEST["clone_content"],$_REQUEST["clone_receivers"]);
+			if ($result > 0)
+			{
+				header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
+				exit;
+			}
+			else
+			{
+				setEventMessage($object->error, 'errors');
+			}
 		}
+	    $action='';
 	}
-    $action='';
-}
 
-// Action send emailing for everybody
-if ($action == 'sendallconfirmed' && $confirm == 'yes')
-{
-	if (empty($conf->global->MAILING_LIMIT_SENDBYWEB))
-	{
-		//TODO: What is this for?
-		// Pour des raisons de securite, on ne permet pas cette fonction via l'IHM,
-		// on affiche donc juste un message
-		setEventMessage($langs->trans("MailingNeedCommand"), 'warnings');
-		setEventMessage('<textarea cols="70" rows="'.ROWS_2.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.'</textarea>', 'warnings');
-		setEventMessage($langs->trans("MailingNeedCommand2"), 'warnings');
-		$action='';
-	}
-	else if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0)
-	{
-		setEventMessage($langs->trans("NotEnoughPermissions"), 'warnings');
-		$action='';
-	}
-	else
+	// Action send emailing for everybody
+	if ($action == 'sendallconfirmed' && $confirm == 'yes')
 	{
-		$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1);
-
-		if ($object->statut == 0)
+		if (empty($conf->global->MAILING_LIMIT_SENDBYWEB))
 		{
-			dol_print_error('','ErrorMailIsNotValidated');
-			exit;
+			//TODO: What is this for?
+			// Pour des raisons de securite, on ne permet pas cette fonction via l'IHM,
+			// on affiche donc juste un message
+			setEventMessage($langs->trans("MailingNeedCommand"), 'warnings');
+			setEventMessage('<textarea cols="70" rows="'.ROWS_2.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.'</textarea>', 'warnings');
+			setEventMessage($langs->trans("MailingNeedCommand2"), 'warnings');
+			$action='';
 		}
-
-		$id       = $object->id;
-		$subject  = $object->sujet;
-		$message  = $object->body;
-		$from     = $object->email_from;
-		$replyto  = $object->email_replyto;
-		$errorsto = $object->email_errorsto;
-		// Le message est-il en html
-		$msgishtml=-1;	// Unknown by default
-		if (preg_match('/[\s\t]*<html>/i',$message)) $msgishtml=1;
-
-		// Warning, we must not use begin-commit transaction here
-		// because we want to save update for each mail sent.
-
-		$nbok=0; $nbko=0;
-
-		// On choisit les mails non deja envoyes pour ce mailing (statut=0)
-		// ou envoyes en erreur (statut=-1)
-		$sql = "SELECT mc.rowid, mc.lastname, mc.firstname, mc.email, mc.other, mc.source_url, mc.source_id, mc.source_type, mc.tag";
-		$sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
-		$sql .= " WHERE mc.statut < 1 AND mc.fk_mailing = ".$object->id;
-
-		dol_syslog("card.php: select targets", LOG_DEBUG);
-		$resql=$db->query($sql);
-		if ($resql)
+		else if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0)
 		{
-			$num = $db->num_rows($resql);	// nb of possible recipients
+			setEventMessage($langs->trans("NotEnoughPermissions"), 'warnings');
+			$action='';
+		}
+		else
+		{
+			$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1);
 
-			if ($num)
+			if ($object->statut == 0)
 			{
-				dol_syslog("comm/mailing/card.php: nb of targets = ".$num, LOG_DEBUG);
+				dol_print_error('','ErrorMailIsNotValidated');
+				exit;
+			}
 
-				$now=dol_now();
+			$id       = $object->id;
+			$subject  = $object->sujet;
+			$message  = $object->body;
+			$from     = $object->email_from;
+			$replyto  = $object->email_replyto;
+			$errorsto = $object->email_errorsto;
+			// Le message est-il en html
+			$msgishtml=-1;	// Unknown by default
+			if (preg_match('/[\s\t]*<html>/i',$message)) $msgishtml=1;
+
+			// Warning, we must not use begin-commit transaction here
+			// because we want to save update for each mail sent.
+
+			$nbok=0; $nbko=0;
+
+			// On choisit les mails non deja envoyes pour ce mailing (statut=0)
+			// ou envoyes en erreur (statut=-1)
+			$sql = "SELECT mc.rowid, mc.lastname, mc.firstname, mc.email, mc.other, mc.source_url, mc.source_id, mc.source_type, mc.tag";
+			$sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
+			$sql .= " WHERE mc.statut < 1 AND mc.fk_mailing = ".$object->id;
+
+			dol_syslog("card.php: select targets", LOG_DEBUG);
+			$resql=$db->query($sql);
+			if ($resql)
+			{
+				$num = $db->num_rows($resql);	// nb of possible recipients
 
-				// Positionne date debut envoi
-				$sql="UPDATE ".MAIN_DB_PREFIX."mailing SET date_envoi=".$db->idate($now)." WHERE rowid=".$object->id;
-				$resql2=$db->query($sql);
-				if (! $resql2)
+				if ($num)
 				{
-					dol_print_error($db);
-				}
+					dol_syslog("comm/mailing/card.php: nb of targets = ".$num, LOG_DEBUG);
 
-				// Loop on each email and send it
-				$i = 0;
-
-				while ($i < $num && $i < $conf->global->MAILING_LIMIT_SENDBYWEB)
-				{
+					$now=dol_now();
 
-					$res=1;
-
-					$obj = $db->fetch_object($resql);
-
-					// sendto en RFC2822
-					$sendto = str_replace(',',' ',dolGetFirstLastname($obj->firstname, $obj->lastname))." <".$obj->email.">";
-
-					// Make substitutions on topic and body. From (AA=YY;BB=CC;...) we keep YY, CC, ...
-					$other=explode(';',$obj->other);
-					$tmpfield=explode('=',$other[0],2); $other1=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
-                    $tmpfield=explode('=',$other[1],2); $other2=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
-                    $tmpfield=explode('=',$other[2],2); $other3=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
-                    $tmpfield=explode('=',$other[3],2); $other4=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
-                    $tmpfield=explode('=',$other[4],2); $other5=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
-                    // Array of possible substitutions (See also fie mailing-send.php that should manage same substitutions)
-					$substitutionarray=array(
-							'__ID__' => $obj->source_id,
-							'__EMAIL__' => $obj->email,
-							'__LASTNAME__' => $obj->lastname,
-							'__FIRSTNAME__' => $obj->firstname,
-							'__MAILTOEMAIL__' => '<a href="mailto:'.$obj->email.'">'.$obj->email.'</a>',
-							'__OTHER1__' => $other1,
-							'__OTHER2__' => $other2,
-							'__OTHER3__' => $other3,
-							'__OTHER4__' => $other4,
-							'__OTHER5__' => $other5,
-							'__CHECK_READ__' => '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$obj->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>',
-							'__UNSUBSCRIBE__' => '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.$obj->tag.'&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" target="_blank">'.$langs->trans("MailUnsubcribe").'</a>'
-					);
-					if (! empty($conf->paypal->enabled) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN))
+					// Positionne date debut envoi
+					$sql="UPDATE ".MAIN_DB_PREFIX."mailing SET date_envoi=".$db->idate($now)." WHERE rowid=".$object->id;
+					$resql2=$db->query($sql);
+					if (! $resql2)
 					{
-						$substitutionarray['__SECUREKEYPAYPAL__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
-						if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
-						else $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
-					}
-					$substitutionisok=true;
-                    complete_substitutions_array($substitutionarray, $langs);
-					$newsubject=make_substitutions($subject,$substitutionarray);
-					$newmessage=make_substitutions($message,$substitutionarray);
-
-					$arr_file = array();
-					$arr_mime = array();
-					$arr_name = array();
-					$arr_css  = array();
-
-					$listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
-					if (count($listofpaths))
-					{
-						foreach($listofpaths as $key => $val)
-						{
-							$arr_file[]=$listofpaths[$key]['fullname'];
-							$arr_mime[]=dol_mimetype($listofpaths[$key]['name']);
-							$arr_name[]=$listofpaths[$key]['name'];
-						}
+						dol_print_error($db);
 					}
 
-					// Fabrication du mail
-					$mail = new CMailFile($newsubject, $sendto, $from, $newmessage, $arr_file, $arr_mime, $arr_name, '', '', 0, $msgishtml, $errorsto, $arr_css);
+					// Loop on each email and send it
+					$i = 0;
 
-					if ($mail->error)
+					while ($i < $num && $i < $conf->global->MAILING_LIMIT_SENDBYWEB)
 					{
-						$res=0;
-					}
-					if (! $substitutionisok)
-					{
-						$mail->error='Some substitution failed';
-						$res=0;
-					}
 
-					// Send mail
-					if ($res)
-					{
-						$res=$mail->sendfile();
-					}
+						$res=1;
+
+						$obj = $db->fetch_object($resql);
+
+						// sendto en RFC2822
+						$sendto = str_replace(',',' ',dolGetFirstLastname($obj->firstname, $obj->lastname))." <".$obj->email.">";
+
+						// Make substitutions on topic and body. From (AA=YY;BB=CC;...) we keep YY, CC, ...
+						$other=explode(';',$obj->other);
+						$tmpfield=explode('=',$other[0],2); $other1=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
+	                    $tmpfield=explode('=',$other[1],2); $other2=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
+	                    $tmpfield=explode('=',$other[2],2); $other3=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
+	                    $tmpfield=explode('=',$other[3],2); $other4=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
+	                    $tmpfield=explode('=',$other[4],2); $other5=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
+	                    // Array of possible substitutions (See also fie mailing-send.php that should manage same substitutions)
+						$substitutionarray=array(
+								'__ID__' => $obj->source_id,
+								'__EMAIL__' => $obj->email,
+								'__LASTNAME__' => $obj->lastname,
+								'__FIRSTNAME__' => $obj->firstname,
+								'__MAILTOEMAIL__' => '<a href="mailto:'.$obj->email.'">'.$obj->email.'</a>',
+								'__OTHER1__' => $other1,
+								'__OTHER2__' => $other2,
+								'__OTHER3__' => $other3,
+								'__OTHER4__' => $other4,
+								'__OTHER5__' => $other5,
+								'__CHECK_READ__' => '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$obj->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>',
+								'__UNSUBSCRIBE__' => '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.$obj->tag.'&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" target="_blank">'.$langs->trans("MailUnsubcribe").'</a>'
+						);
+						if (! empty($conf->paypal->enabled) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN))
+						{
+							$substitutionarray['__SECUREKEYPAYPAL__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
+							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
+							else $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
+						}
+						$substitutionisok=true;
+	                    complete_substitutions_array($substitutionarray, $langs);
+						$newsubject=make_substitutions($subject,$substitutionarray);
+						$newmessage=make_substitutions($message,$substitutionarray);
+
+						$arr_file = array();
+						$arr_mime = array();
+						$arr_name = array();
+						$arr_css  = array();
+
+						$listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
+						if (count($listofpaths))
+						{
+							foreach($listofpaths as $key => $val)
+							{
+								$arr_file[]=$listofpaths[$key]['fullname'];
+								$arr_mime[]=dol_mimetype($listofpaths[$key]['name']);
+								$arr_name[]=$listofpaths[$key]['name'];
+							}
+						}
 
-					if ($res)
-					{
-						// Mail successful
-						$nbok++;
+						// Fabrication du mail
+						$mail = new CMailFile($newsubject, $sendto, $from, $newmessage, $arr_file, $arr_mime, $arr_name, '', '', 0, $msgishtml, $errorsto, $arr_css);
 
-						dol_syslog("comm/mailing/card.php: ok for #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);
+						if ($mail->error)
+						{
+							$res=0;
+						}
+						if (! $substitutionisok)
+						{
+							$mail->error='Some substitution failed';
+							$res=0;
+						}
 
-						$sql="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
-						$sql.=" SET statut=1, date_envoi=".$db->idate($now)." WHERE rowid=".$obj->rowid;
-						$resql2=$db->query($sql);
-						if (! $resql2)
+						// Send mail
+						if ($res)
 						{
-							dol_print_error($db);
+							$res=$mail->sendfile();
 						}
-						else
+
+						if ($res)
 						{
-							//if cheack read is use then update prospect contact status
-							if (strpos($message, '__CHECK_READ__') !== false)
-							{
-								//Update status communication of thirdparty prospect
-								$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT source_id FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE rowid=".$obj->rowid.")";
-								dol_syslog("card.php: set prospect thirdparty status", LOG_DEBUG);
-								$resql2=$db->query($sql);
-								if (! $resql2)
-								{
-									dol_print_error($db);
-								}
+							// Mail successful
+							$nbok++;
 
-							    //Update status communication of contact prospect
-								$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."socpeople AS sc INNER JOIN ".MAIN_DB_PREFIX."mailing_cibles AS mc ON mc.rowid=".$obj->rowid." AND mc.source_type = 'contact' AND mc.source_id = sc.rowid)";
-								dol_syslog("card.php: set prospect contact status", LOG_DEBUG);
+							dol_syslog("comm/mailing/card.php: ok for #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);
 
-								$resql2=$db->query($sql);
-								if (! $resql2)
+							$sql="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
+							$sql.=" SET statut=1, date_envoi=".$db->idate($now)." WHERE rowid=".$obj->rowid;
+							$resql2=$db->query($sql);
+							if (! $resql2)
+							{
+								dol_print_error($db);
+							}
+							else
+							{
+								//if cheack read is use then update prospect contact status
+								if (strpos($message, '__CHECK_READ__') !== false)
 								{
-									dol_print_error($db);
+									//Update status communication of thirdparty prospect
+									$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT source_id FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE rowid=".$obj->rowid.")";
+									dol_syslog("card.php: set prospect thirdparty status", LOG_DEBUG);
+									$resql2=$db->query($sql);
+									if (! $resql2)
+									{
+										dol_print_error($db);
+									}
+
+								    //Update status communication of contact prospect
+									$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."socpeople AS sc INNER JOIN ".MAIN_DB_PREFIX."mailing_cibles AS mc ON mc.rowid=".$obj->rowid." AND mc.source_type = 'contact' AND mc.source_id = sc.rowid)";
+									dol_syslog("card.php: set prospect contact status", LOG_DEBUG);
+
+									$resql2=$db->query($sql);
+									if (! $resql2)
+									{
+										dol_print_error($db);
+									}
 								}
 							}
-						}
 
 
-						//test if CHECK READ change statut prospect contact
-					}
-					else
-					{
-						// Mail failed
-						$nbko++;
+							//test if CHECK READ change statut prospect contact
+						}
+						else
+						{
+							// Mail failed
+							$nbko++;
 
-						dol_syslog("comm/mailing/card.php: error for #".$i.($mail->error?' - '.$mail->error:''), LOG_WARNING);
+							dol_syslog("comm/mailing/card.php: error for #".$i.($mail->error?' - '.$mail->error:''), LOG_WARNING);
 
-						$sql="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
-						$sql.=" SET statut=-1, date_envoi=".$db->idate($now)." WHERE rowid=".$obj->rowid;
-						$resql2=$db->query($sql);
-						if (! $resql2)
-						{
-							dol_print_error($db);
+							$sql="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
+							$sql.=" SET statut=-1, date_envoi=".$db->idate($now)." WHERE rowid=".$obj->rowid;
+							$resql2=$db->query($sql);
+							if (! $resql2)
+							{
+								dol_print_error($db);
+							}
 						}
-					}
 
-					$i++;
+						$i++;
+					}
+				}
+				else
+				{
+					setEventMessage($langs->transnoentitiesnoconv("NoMoreRecipientToSendTo"));
 				}
-			}
-			else
-			{
-				setEventMessage($langs->transnoentitiesnoconv("NoMoreRecipientToSendTo"));
-			}
 
-			// Loop finished, set global statut of mail
-			if ($nbko > 0)
-			{
-				$statut=2;	// Status 'sent partially' (because at least one error)
-				if ($nbok > 0) 	setEventMessage($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok));
-				else setEventMessage($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok));
-			}
-			else
-			{
-				if ($nbok >= $num)
+				// Loop finished, set global statut of mail
+				if ($nbko > 0)
 				{
-					$statut=3;	// Send to everybody
-					setEventMessage($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok));
+					$statut=2;	// Status 'sent partially' (because at least one error)
+					if ($nbok > 0) 	setEventMessage($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok));
+					else setEventMessage($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok));
 				}
 				else
 				{
-					$statut=2;	// Status 'sent partially' (because not send to everybody)
-					setEventMessage($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok));
+					if ($nbok >= $num)
+					{
+						$statut=3;	// Send to everybody
+						setEventMessage($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok));
+					}
+					else
+					{
+						$statut=2;	// Status 'sent partially' (because not send to everybody)
+						setEventMessage($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok));
+					}
 				}
-			}
 
-			$sql="UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".$statut." WHERE rowid=".$object->id;
-			dol_syslog("comm/mailing/card.php: update global status", LOG_DEBUG);
-			$resql2=$db->query($sql);
-			if (! $resql2)
-			{
-				dol_print_error($db);
+				$sql="UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".$statut." WHERE rowid=".$object->id;
+				dol_syslog("comm/mailing/card.php: update global status", LOG_DEBUG);
+				$resql2=$db->query($sql);
+				if (! $resql2)
+				{
+					dol_print_error($db);
+				}
 			}
-		}
-		else
-		{
-			dol_syslog($db->error());
-			dol_print_error($db);
-		}
-
-		$action = '';
-	}
-}
-
-// Action send test emailing
-if ($action == 'send' && empty($_POST["cancel"]))
-{
-	$error=0;
-
-	$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1);
-
-	$object->sendto = $_POST["sendto"];
-	if (! $object->sendto)
-	{
-		setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("MailTo")), 'errors');
-		$error++;
-	}
-
-	if (! $error)
-	{
-		// Le message est-il en html
-		$msgishtml=-1;	// Inconnu par defaut
-		if (preg_match('/[\s\t]*<html>/i',$object->body)) $msgishtml=1;
-
-		// Pratique les substitutions sur le sujet et message
-		$tmpsujet=make_substitutions($object->sujet,$object->substitutionarrayfortest);
-		$tmpbody=make_substitutions($object->body,$object->substitutionarrayfortest);
-
-		$arr_file = array();
-		$arr_mime = array();
-		$arr_name = array();
-		$arr_css  = array();
-
-        // Ajout CSS
-        if (!empty($object->bgcolor)) $arr_css['bgcolor'] = (preg_match('/^#/',$object->bgcolor)?'':'#').$object->bgcolor;
-        if (!empty($object->bgimage)) $arr_css['bgimage'] = $object->bgimage;
-
-        // Attached files
-		$listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
-		if (count($listofpaths))
-		{
-			foreach($listofpaths as $key => $val)
+			else
 			{
-				$arr_file[]=$listofpaths[$key]['fullname'];
-				$arr_mime[]=dol_mimetype($listofpaths[$key]['name']);
-				$arr_name[]=$listofpaths[$key]['name'];
+				dol_syslog($db->error());
+				dol_print_error($db);
 			}
-		}
 
-		$mailfile = new CMailFile($tmpsujet,$object->sendto,$object->email_from,$tmpbody, $arr_file,$arr_mime,$arr_name,'', '', 0, $msgishtml,$object->email_errorsto,$arr_css);
-
-		$result=$mailfile->sendfile();
-		if ($result)
-		{
-			setEventMessage($langs->trans("MailSuccessfulySent",$mailfile->getValidAddress($object->email_from,2),$mailfile->getValidAddress($object->sendto,2)));
-		}
-		else
-		{
-			setEventMessage($langs->trans("ResultKo").'<br>'.$mailfile->error.' '.$result, 'errors');
+			$action = '';
 		}
-
-		$action='';
-	}
-}
-
-// Action add emailing
-if ($action == 'add')
-{
-	$mesgs = array();
-
-	$object->email_from     = trim($_POST["from"]);
-	$object->email_replyto  = trim($_POST["replyto"]);
-	$object->email_errorsto = trim($_POST["errorsto"]);
-	$object->titre          = trim($_POST["titre"]);
-	$object->sujet          = trim($_POST["sujet"]);
-	$object->body           = trim($_POST["body"]);
-	$object->bgcolor        = trim($_POST["bgcolor"]);
-	$object->bgimage        = trim($_POST["bgimage"]);
-
-	if (! $object->titre) {
-		$mesgs[] = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTitle"));
-	}
-	if (! $object->sujet) {
-		$mesgs[] = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTopic"));
-	}
-	if (! $object->body)  {
-		$mesgs[] = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailMessage"));
 	}
 
-	if (!count($mesgs))
+	// Action send test emailing
+	if ($action == 'send' && empty($_POST["cancel"]))
 	{
-		if ($object->create($user) >= 0)
-		{
-			header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
-			exit;
-		}
-		$mesgs[] = $object->error;
-	}
+		$error=0;
 
-	setEventMessage($mesgs, 'errors');
-	$action="create";
-}
-
-// Action update description of emailing
-if ($action == 'settitre' || $action == 'setemail_from' || $action == 'setreplyto' || $action == 'setemail_errorsto')
-{
-	$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1);
-
-	if ($action == 'settitre')					$object->titre          = trim(GETPOST('titre','alpha'));
-	else if ($action == 'setemail_from')		$object->email_from     = trim(GETPOST('email_from','alpha'));
-	else if ($action == 'setemail_replyto')		$object->email_replyto  = trim(GETPOST('email_replyto','alpha'));
-	else if ($action == 'setemail_errorsto')	$object->email_errorsto = trim(GETPOST('email_errorsto','alpha'));
-	else if ($action == 'settitre' && empty($object->titre)) {
-		$mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTitle"));
-	}
-	else if ($action == 'setfrom' && empty($object->email_from)) {
-		$mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailFrom"));
-	}
+		$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1);
 
-	if (! $mesg)
-	{
-		if ($object->update($user) >= 0)
+		$object->sendto = $_POST["sendto"];
+		if (! $object->sendto)
 		{
-			header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
-			exit;
+			setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("MailTo")), 'errors');
+			$error++;
 		}
-		$mesg = $object->error;
-	}
-
-	setEventMessage($mesg, 'errors');
-	$action="";
-}
 
-/*
- * Add file in email form
- */
-if (! empty($_POST['addfile']))
-{
-	$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1);
-
-	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-
-    // Set tmp user directory
-    dol_add_file_process($upload_dir,0,0);
+		if (! $error)
+		{
+			// Le message est-il en html
+			$msgishtml=-1;	// Inconnu par defaut
+			if (preg_match('/[\s\t]*<html>/i',$object->body)) $msgishtml=1;
 
-	$action="edit";
-}
+			// Pratique les substitutions sur le sujet et message
+			$tmpsujet=make_substitutions($object->sujet,$object->substitutionarrayfortest);
+			$tmpbody=make_substitutions($object->body,$object->substitutionarrayfortest);
 
-// Action remove file
-if (! empty($_POST["removedfile"]))
-{
-	$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1);
+			$arr_file = array();
+			$arr_mime = array();
+			$arr_name = array();
+			$arr_css  = array();
 
-	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+	        // Ajout CSS
+	        if (!empty($object->bgcolor)) $arr_css['bgcolor'] = (preg_match('/^#/',$object->bgcolor)?'':'#').$object->bgcolor;
+	        if (!empty($object->bgimage)) $arr_css['bgimage'] = $object->bgimage;
 
-    dol_remove_file_process($_POST['removedfile'],0);
+	        // Attached files
+			$listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
+			if (count($listofpaths))
+			{
+				foreach($listofpaths as $key => $val)
+				{
+					$arr_file[]=$listofpaths[$key]['fullname'];
+					$arr_mime[]=dol_mimetype($listofpaths[$key]['name']);
+					$arr_name[]=$listofpaths[$key]['name'];
+				}
+			}
 
-	$action="edit";
-}
+			$mailfile = new CMailFile($tmpsujet,$object->sendto,$object->email_from,$tmpbody, $arr_file,$arr_mime,$arr_name,'', '', 0, $msgishtml,$object->email_errorsto,$arr_css);
 
-// Action update emailing
-if ($action == 'update' && empty($_POST["removedfile"]) && empty($_POST["cancel"]))
-{
-	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+			$result=$mailfile->sendfile();
+			if ($result)
+			{
+				setEventMessage($langs->trans("MailSuccessfulySent",$mailfile->getValidAddress($object->email_from,2),$mailfile->getValidAddress($object->sendto,2)));
+			}
+			else
+			{
+				setEventMessage($langs->trans("ResultKo").'<br>'.$mailfile->error.' '.$result, 'errors');
+			}
 
-	$isupload=0;
+			$action='';
+		}
+	}
 
-	if (! $isupload)
+	// Action add emailing
+	if ($action == 'add')
 	{
 		$mesgs = array();
 
+		$object->email_from     = trim($_POST["from"]);
+		$object->email_replyto  = trim($_POST["replyto"]);
+		$object->email_errorsto = trim($_POST["errorsto"]);
+		$object->titre          = trim($_POST["titre"]);
 		$object->sujet          = trim($_POST["sujet"]);
 		$object->body           = trim($_POST["body"]);
 		$object->bgcolor        = trim($_POST["bgcolor"]);
 		$object->bgimage        = trim($_POST["bgimage"]);
 
+		if (! $object->titre) {
+			$mesgs[] = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTitle"));
+		}
 		if (! $object->sujet) {
 			$mesgs[] = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTopic"));
 		}
-		if (! $object->body) {
+		if (! $object->body)  {
 			$mesgs[] = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailMessage"));
 		}
 
 		if (!count($mesgs))
 		{
-			if ($object->update($user) >= 0)
+			if ($object->create($user) >= 0)
 			{
 				header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
 				exit;
 			}
-			$mesgs[] =$object->error;
+			$mesgs[] = $object->error;
 		}
 
 		setEventMessage($mesgs, 'errors');
-		$action="edit";
+		$action="create";
 	}
-	else
+
+	// Action update description of emailing
+	if ($action == 'settitre' || $action == 'setemail_from' || $action == 'setreplyto' || $action == 'setemail_errorsto')
 	{
-		$action="edit";
+		$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1);
+
+		if ($action == 'settitre')					$object->titre          = trim(GETPOST('titre','alpha'));
+		else if ($action == 'setemail_from')		$object->email_from     = trim(GETPOST('email_from','alpha'));
+		else if ($action == 'setemail_replyto')		$object->email_replyto  = trim(GETPOST('email_replyto','alpha'));
+		else if ($action == 'setemail_errorsto')	$object->email_errorsto = trim(GETPOST('email_errorsto','alpha'));
+		else if ($action == 'settitre' && empty($object->titre)) {
+			$mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTitle"));
+		}
+		else if ($action == 'setfrom' && empty($object->email_from)) {
+			$mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailFrom"));
+		}
+
+		if (! $mesg)
+		{
+			if ($object->update($user) >= 0)
+			{
+				header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
+				exit;
+			}
+			$mesg = $object->error;
+		}
+
+		setEventMessage($mesg, 'errors');
+		$action="";
 	}
-}
 
-// Action confirmation validation
-if ($action == 'confirm_valid' && $confirm == 'yes')
-{
-	if ($object->id > 0)
+	/*
+	 * Add file in email form
+	 */
+	if (! empty($_POST['addfile']))
 	{
-		$object->valid($user);
-		setEventMessage($langs->trans("MailingSuccessfullyValidated"));
-		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
-		exit;
+		$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1);
+
+		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+
+	    // Set tmp user directory
+	    dol_add_file_process($upload_dir,0,0);
+
+		$action="edit";
 	}
-	else
+
+	// Action remove file
+	if (! empty($_POST["removedfile"]))
 	{
-		dol_print_error($db);
+		$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1);
+
+		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+
+	    dol_remove_file_process($_POST['removedfile'],0);
+
+		$action="edit";
 	}
-}
 
-// Resend
-if ($action == 'confirm_reset' && $confirm == 'yes')
-{
-	if ($object->id > 0)
+	// Action update emailing
+	if ($action == 'update' && empty($_POST["removedfile"]) && empty($_POST["cancel"]))
 	{
-		$db->begin();
+		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
 
-		$result=$object->valid($user);
-		if ($result > 0)
+		$isupload=0;
+
+		if (! $isupload)
 		{
-			$result=$object->reset_targets_status($user);
+			$mesgs = array();
+
+			$object->sujet          = trim($_POST["sujet"]);
+			$object->body           = trim($_POST["body"]);
+			$object->bgcolor        = trim($_POST["bgcolor"]);
+			$object->bgimage        = trim($_POST["bgimage"]);
+
+			if (! $object->sujet) {
+				$mesgs[] = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTopic"));
+			}
+			if (! $object->body) {
+				$mesgs[] = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailMessage"));
+			}
+
+			if (!count($mesgs))
+			{
+				if ($object->update($user) >= 0)
+				{
+					header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
+					exit;
+				}
+				$mesgs[] =$object->error;
+			}
+
+			setEventMessage($mesgs, 'errors');
+			$action="edit";
+		}
+		else
+		{
+			$action="edit";
 		}
+	}
 
-		if ($result > 0)
+	// Action confirmation validation
+	if ($action == 'confirm_valid' && $confirm == 'yes')
+	{
+		if ($object->id > 0)
 		{
-			$db->commit();
+			$object->valid($user);
+			setEventMessage($langs->trans("MailingSuccessfullyValidated"));
 			header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
 			exit;
 		}
 		else
 		{
-			setEventMessage($object->error, 'errors');
-			$db->rollback();
+			dol_print_error($db);
 		}
 	}
-	else
+
+	// Resend
+	if ($action == 'confirm_reset' && $confirm == 'yes')
 	{
-		dol_print_error($db);
+		if ($object->id > 0)
+		{
+			$db->begin();
+
+			$result=$object->valid($user);
+			if ($result > 0)
+			{
+				$result=$object->reset_targets_status($user);
+			}
+
+			if ($result > 0)
+			{
+				$db->commit();
+				header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
+				exit;
+			}
+			else
+			{
+				setEventMessage($object->error, 'errors');
+				$db->rollback();
+			}
+		}
+		else
+		{
+			dol_print_error($db);
+		}
 	}
-}
 
-// Action confirmation suppression
-if ($action == 'confirm_delete' && $confirm == 'yes')
-{
-	if ($object->delete($object->id))
+	// Action confirmation suppression
+	if ($action == 'confirm_delete' && $confirm == 'yes')
 	{
-		$url= (! empty($urlfrom) ? $urlfrom : 'list.php');
-		header("Location: ".$url);
-		exit;
+		if ($object->delete($object->id))
+		{
+			$url= (! empty($urlfrom) ? $urlfrom : 'list.php');
+			header("Location: ".$url);
+			exit;
+		}
 	}
-}
 
-if (! empty($_POST["cancel"]))
-{
-	$action = '';
+	if (! empty($_POST["cancel"]))
+	{
+		$action = '';
+	}
 }
 
 
-
 /*
  * View
  */
 
+$form = new Form($db);
+$htmlother = new FormOther($db);
 
 $help_url='EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing';
 llxHeader('',$langs->trans("Mailing"),$help_url);
 
-$form = new Form($db);
-$htmlother = new FormOther($db);
-
 if ($action == 'create')
 {
 	// EMailing in creation mode

文件差异内容过多而无法显示
+ 678 - 548
htdocs/comm/propal.php


+ 13 - 16
htdocs/comm/propal/class/propal.class.php

@@ -2550,21 +2550,18 @@ class Propal extends CommonObject
         {
         	$mybool=false;
 
-		$dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
-		foreach ($dirmodels as $reldir)
-		{
-	            $file = $conf->global->PROPALE_ADDON.".php";
-	            $classname = $conf->global->PROPALE_ADDON;
-
-	            // Include file with class
-	            foreach ($conf->file->dol_document_root as $dirroot)
-	            {
-	            	$dir = $dirroot.$reldir."/core/modules/propale/";
-	            	// Load file with numbering class (if found)
-	            	$mybool|=@include_once $dir.$file;
-	            }
-		}
+            $file = $conf->global->PROPALE_ADDON.".php";
+            $classname = $conf->global->PROPALE_ADDON;
+
+            // Include file with class
+            $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
+            foreach ($dirmodels as $reldir) {
 
+                $dir = dol_buildpath($reldir."core/modules/propale/");
+
+                // Load file with numbering class (if found)
+                $mybool|=@include_once $dir.$file;
+            }
 
             if (! $mybool)
             {
@@ -2581,14 +2578,14 @@ class Propal extends CommonObject
                 return $numref;
             }
             else
-            {
+			{
                 $this->error=$obj->error;
                 //dol_print_error($db,"Propale::getNextNumRef ".$obj->error);
                 return "";
             }
         }
         else
-        {
+		{
             $langs->load("errors");
             print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete");
             return "";

+ 7 - 5
htdocs/comm/prospect/list.php

@@ -177,11 +177,13 @@ $parameters=array();
 $reshook=$hookmanager->executeHooks('doActions',$parameters);    // Note that $action and $object may have been modified by some hooks
 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
 
-if ($action == 'cstc')
-{
-	$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm = ".$_GET["pstcomm"];
-	$sql .= " WHERE rowid = ".$_GET["socid"];
-	$result=$db->query($sql);
+if (empty($reshook)) {
+	if ($action == 'cstc')
+	{
+		$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm = ".$_GET["pstcomm"];
+		$sql .= " WHERE rowid = ".$_GET["socid"];
+		$result=$db->query($sql);
+	}
 }
 
 

文件差异内容过多而无法显示
+ 622 - 496
htdocs/commande/card.php


+ 16 - 17
htdocs/commande/class/commande.class.php

@@ -140,26 +140,25 @@ class Commande extends CommonOrder
 
         if (! empty($conf->global->COMMANDE_ADDON))
         {
-		$mybool=false;
-		$dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
-		foreach ($dirmodels as $reldir)
-		{
-	            $file = $conf->global->COMMANDE_ADDON.".php";
-	            $classname = $conf->global->COMMANDE_ADDON;
-
-	            // Include file with class
-	            foreach ($conf->file->dol_document_root as $dirroot)
-	            {
-	            	$dir = $dirroot.$reldir."/core/modules/commande/";
-	            	// Load file with numbering class (if found)
-	            	$mybool|=@include_once $dir.$file;
-	            }
-		}
+        	$mybool=false;
+
+        	$file = $conf->global->COMMANDE_ADDON.".php";
+			$classname = $conf->global->COMMANDE_ADDON;
+
+			// Include file with class
+			$dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
+			foreach ($dirmodels as $reldir)
+			{
+                $dir = dol_buildpath($reldir."core/modules/commande/");
+
+                // Load file with numbering class (if found)
+                $mybool|=@include_once $dir.$file;
+            }
 
             if (! $mybool)
             {
-            	dol_print_error('',"Failed to include file ".$file);
-            	return '';
+                dol_print_error('',"Failed to include file ".$file);
+                return '';
             }
 
             $obj = new $classname();

文件差异内容过多而无法显示
+ 1157 - 1018
htdocs/compta/facture.php


+ 46 - 34
htdocs/compta/facture/class/facture.class.php

@@ -2497,52 +2497,64 @@ class Facture extends CommonInvoice
 		else if ($conf->global->FACTURE_ADDON=='terre') $conf->global->FACTURE_ADDON='mod_facture_terre';
 		else if ($conf->global->FACTURE_ADDON=='mercure') $conf->global->FACTURE_ADDON='mod_facture_mercure';
 
-		$mybool=false;
-
-		$file = $conf->global->FACTURE_ADDON.".php";
-		$classname = $conf->global->FACTURE_ADDON;
-		// Include file with class
-		foreach ($conf->file->dol_document_root as $dirroot)
+		if (! empty($conf->global->FACTURE_ADDON))
 		{
-			$dir = $dirroot."/core/modules/facture/";
-			// Load file with numbering class (if found)
-			$mybool|=@include_once $dir.$file;
-		}
+			$mybool=false;
+
+			$file = $conf->global->FACTURE_ADDON.".php";
+			$classname = $conf->global->FACTURE_ADDON;
 
-		// For compatibility
-		if (! $mybool)
-		{
-			$file = $conf->global->FACTURE_ADDON."/".$conf->global->FACTURE_ADDON.".modules.php";
-			$classname = "mod_facture_".$conf->global->FACTURE_ADDON;
-			$classname = preg_replace('/\-.*$/','',$classname);
 			// Include file with class
-			foreach ($conf->file->dol_document_root as $dirroot)
-			{
-				$dir = $dirroot."/core/modules/facture/";
+			$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
+
+			foreach ($dirmodels as $reldir) {
+
+				$dir = dol_buildpath($reldir."core/modules/facture/");
+
 				// Load file with numbering class (if found)
 				$mybool|=@include_once $dir.$file;
 			}
-		}
-		//print "xx".$mybool.$dir.$file."-".$classname;
 
-		if (! $mybool)
-		{
-			dol_print_error('',"Failed to include file ".$file);
-			return '';
-		}
+			// For compatibility
+			if (! $mybool)
+			{
+				$file = $conf->global->FACTURE_ADDON."/".$conf->global->FACTURE_ADDON.".modules.php";
+				$classname = "mod_facture_".$conf->global->FACTURE_ADDON;
+				$classname = preg_replace('/\-.*$/','',$classname);
+				// Include file with class
+				foreach ($conf->file->dol_document_root as $dirroot)
+				{
+					$dir = $dirroot."/core/modules/facture/";
+					// Load file with numbering class (if found)
+					$mybool|=@include_once $dir.$file;
+				}
+			}
 
-		$obj = new $classname();
-		$numref = "";
-		$numref = $obj->getNumRef($soc,$this,$mode);
+			if (! $mybool)
+			{
+				dol_print_error('',"Failed to include file ".$file);
+				return '';
+			}
 
-		if ($numref != "")
-		{
-			return $numref;
+			$obj = new $classname();
+			$numref = "";
+			$numref = $obj->getNextValue($soc,$this,$mode);
+
+			if ($numref != "")
+			{
+				return $numref;
+			}
+			else
+			{
+				dol_print_error($db,"Facture::getNextNumRef ".$obj->error);
+				return "";
+			}
 		}
 		else
 		{
-			//dol_print_error($db,get_class($this)."::getNextNumRef ".$obj->error);
-			return false;
+			$langs->load("errors");
+			print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete");
+			return "";
 		}
 	}
 

+ 1 - 1
htdocs/compta/facture/impayees.php

@@ -551,7 +551,7 @@ if ($resql)
 	print_liste_field_titre($langs->trans("Taxes"),$_SERVER["PHP_SELF"],"f.tva","",$param,'align="right"',$sortfield,$sortorder);
 	print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER["PHP_SELF"],"f.total_ttc","",$param,'align="right"',$sortfield,$sortorder);
 	print_liste_field_titre($langs->trans("Received"),$_SERVER["PHP_SELF"],"am","",$param,'align="right"',$sortfield,$sortorder);
-	print_liste_field_titre($langs->trans("Rest"),$_SERVER["PHP_SELF"],"am","",$param,'align="right"',$sortfield,$sortorder);
+	print_liste_field_titre($langs->trans("Rest"),$_SERVER["PHP_SELF"],"","",$param,'align="right"',$sortfield,$sortorder);
 	print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"fk_statut,paye,am","",$param,'align="right"',$sortfield,$sortorder);
 	if (empty($mode))
 	{

+ 155 - 152
htdocs/compta/paiement.php

@@ -69,185 +69,188 @@ if ($facid > 0)
 // Initialize technical object to manage hooks of paiements. Note that conf->hooks_modules contains array array
 $hookmanager->initHooks(array('paiementcard','globalcard'));
 
-$parameters=array('socid'=>$socid);
-$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');
-
 
 /*
  * Actions
  */
 
-if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='yes'))
+$parameters=array('socid'=>$socid);
+$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
+if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+
+if (empty($reshook))
 {
-    $error = 0;
+	if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='yes'))
+	{
+	    $error = 0;
 
-    $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
-    $paiement_id = 0;
-    $totalpayment = 0;
-    $atleastonepaymentnotnull = 0;
+	    $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
+	    $paiement_id = 0;
+	    $totalpayment = 0;
+	    $atleastonepaymentnotnull = 0;
 
-    // Generate payment array and check if there is payment higher than invoice and payment date before invoice date
-    $tmpinvoice=new Facture($db);
-    foreach ($_POST as $key => $value)
-    {
-        if (substr($key,0,7) == 'amount_')
-        {
-            $cursorfacid = substr($key,7);
-            $amounts[$cursorfacid] = price2num(trim(GETPOST($key)));
-            $totalpayment = $totalpayment + $amounts[$cursorfacid];
-            if (! empty($amounts[$cursorfacid])) $atleastonepaymentnotnull++;
-            $result=$tmpinvoice->fetch($cursorfacid);
-            if ($result <= 0) dol_print_error($db);
-            $amountsresttopay[$cursorfacid]=price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement());
-            if ($amounts[$cursorfacid])
-            {
-	            // Check amount
-	            if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid])))
-	            {
-	                $addwarning=1;
-	                $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPay")).' '.$langs->trans("HelpPaymentHigherThanReminderToPay");
-	            }
-	            // Check date
-	            if ($datepaye && ($datepaye < $tmpinvoice->date))
+	    // Generate payment array and check if there is payment higher than invoice and payment date before invoice date
+	    $tmpinvoice=new Facture($db);
+	    foreach ($_POST as $key => $value)
+	    {
+	        if (substr($key,0,7) == 'amount_')
+	        {
+	            $cursorfacid = substr($key,7);
+	            $amounts[$cursorfacid] = price2num(trim(GETPOST($key)));
+	            $totalpayment = $totalpayment + $amounts[$cursorfacid];
+	            if (! empty($amounts[$cursorfacid])) $atleastonepaymentnotnull++;
+	            $result=$tmpinvoice->fetch($cursorfacid);
+	            if ($result <= 0) dol_print_error($db);
+	            $amountsresttopay[$cursorfacid]=price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement());
+	            if ($amounts[$cursorfacid])
 	            {
-	            	$langs->load("errors");
-	                //$error++;
-	                setEventMessage($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye,'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), 'warnings');
+		            // Check amount
+		            if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid])))
+		            {
+		                $addwarning=1;
+		                $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPay")).' '.$langs->trans("HelpPaymentHigherThanReminderToPay");
+		            }
+		            // Check date
+		            if ($datepaye && ($datepaye < $tmpinvoice->date))
+		            {
+		            	$langs->load("errors");
+		                //$error++;
+		                setEventMessage($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye,'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), 'warnings');
+		            }
 	            }
-            }
 
-            $formquestion[$i++]=array('type' => 'hidden','name' => $key,  'value' => $_POST[$key]);
-        }
-    }
+	            $formquestion[$i++]=array('type' => 'hidden','name' => $key,  'value' => $_POST[$key]);
+	        }
+	    }
 
-    // Check parameters
-    if (! GETPOST('paiementcode'))
-    {
-        setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('PaymentMode')), 'errors');
-        $error++;
-    }
+	    // Check parameters
+	    if (! GETPOST('paiementcode'))
+	    {
+	        setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('PaymentMode')), 'errors');
+	        $error++;
+	    }
 
-    if (! empty($conf->banque->enabled))
-    {
-        // If bank module is on, account is required to enter a payment
-        if (GETPOST('accountid') <= 0)
-        {
-            setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), 'errors');
-            $error++;
-        }
-    }
+	    if (! empty($conf->banque->enabled))
+	    {
+	        // If bank module is on, account is required to enter a payment
+	        if (GETPOST('accountid') <= 0)
+	        {
+	            setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), 'errors');
+	            $error++;
+	        }
+	    }
 
-    if (empty($totalpayment) && empty($atleastonepaymentnotnull))
-    {
-        setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->trans('PaymentAmount')), 'errors');
-        $error++;
-    }
+	    if (empty($totalpayment) && empty($atleastonepaymentnotnull))
+	    {
+	        setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->trans('PaymentAmount')), 'errors');
+	        $error++;
+	    }
 
-    if (empty($datepaye))
-    {
-        setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('Date')), 'errors');
-        $error++;
-    }
-}
+	    if (empty($datepaye))
+	    {
+	        setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('Date')), 'errors');
+	        $error++;
+	    }
+	}
 
-/*
- * Action add_paiement
- */
-if ($action == 'add_paiement')
-{
-    if ($error)
-    {
-        $action = 'create';
-    }
-    // Le reste propre a cette action s'affiche en bas de page.
-}
+	/*
+	 * Action add_paiement
+	 */
+	if ($action == 'add_paiement')
+	{
+	    if ($error)
+	    {
+	        $action = 'create';
+	    }
+	    // Le reste propre a cette action s'affiche en bas de page.
+	}
 
-/*
- * Action confirm_paiement
- */
-if ($action == 'confirm_paiement' && $confirm == 'yes')
-{
-    $error=0;
+	/*
+	 * Action confirm_paiement
+	 */
+	if ($action == 'confirm_paiement' && $confirm == 'yes')
+	{
+	    $error=0;
 
-    $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
+	    $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
 
-    $db->begin();
+	    $db->begin();
 
-    // Clean parameters amount if payment is for a credit note
-    if (GETPOST('type') == 2)
-    {
-	    foreach ($amounts as $key => $value)	// How payment is dispatch
+	    // Clean parameters amount if payment is for a credit note
+	    if (GETPOST('type') == 2)
 	    {
-	    	$newvalue = price2num($value,'MT');
-	    	$amounts[$key] = -$newvalue;
+		    foreach ($amounts as $key => $value)	// How payment is dispatch
+		    {
+		    	$newvalue = price2num($value,'MT');
+		    	$amounts[$key] = -$newvalue;
+		    }
 	    }
-    }
 
-    if (! empty($conf->banque->enabled))
-    {
-    	// Si module bank actif, un compte est obligatoire lors de la saisie d'un paiement
-    	if (GETPOST('accountid') <= 0)
-    	{
-    		setEventMessage($langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), 'errors');
-    		$error++;
-    	}
-    }
-
-    // Creation of payment line
-    $paiement = new Paiement($db);
-    $paiement->datepaye     = $datepaye;
-    $paiement->amounts      = $amounts;   // Array with all payments dispatching
-    $paiement->paiementid   = dol_getIdFromCode($db,$_POST['paiementcode'],'c_paiement');
-    $paiement->num_paiement = $_POST['num_paiement'];
-    $paiement->note         = $_POST['comment'];
+	    if (! empty($conf->banque->enabled))
+	    {
+	    	// Si module bank actif, un compte est obligatoire lors de la saisie d'un paiement
+	    	if (GETPOST('accountid') <= 0)
+	    	{
+	    		setEventMessage($langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), 'errors');
+	    		$error++;
+	    	}
+	    }
 
-    if (! $error)
-    {
-    	$paiement_id = $paiement->create($user, (GETPOST('closepaidinvoices')=='on'?1:0));
-    	if ($paiement_id < 0)
-        {
-            setEventMessage($paiement->error, 'errors');
-            $error++;
-        }
-    }
+	    // Creation of payment line
+	    $paiement = new Paiement($db);
+	    $paiement->datepaye     = $datepaye;
+	    $paiement->amounts      = $amounts;   // Array with all payments dispatching
+	    $paiement->paiementid   = dol_getIdFromCode($db,$_POST['paiementcode'],'c_paiement');
+	    $paiement->num_paiement = $_POST['num_paiement'];
+	    $paiement->note         = $_POST['comment'];
 
-    if (! $error)
-    {
-    	$label='(CustomerInvoicePayment)';
-    	if (GETPOST('type') == 2) $label='(CustomerInvoicePaymentBack)';
-        $result=$paiement->addPaymentToBank($user,'payment',$label,GETPOST('accountid'),GETPOST('chqemetteur'),GETPOST('chqbank'));
-        if ($result < 0)
-        {
-            setEventMessage($paiement->error, 'errors');
-            $error++;
-        }
-    }
+	    if (! $error)
+	    {
+	    	$paiement_id = $paiement->create($user, (GETPOST('closepaidinvoices')=='on'?1:0));
+	    	if ($paiement_id < 0)
+	        {
+	            setEventMessage($paiement->error, 'errors');
+	            $error++;
+	        }
+	    }
 
-    if (! $error)
-    {
-        $db->commit();
+	    if (! $error)
+	    {
+	    	$label='(CustomerInvoicePayment)';
+	    	if (GETPOST('type') == 2) $label='(CustomerInvoicePaymentBack)';
+	        $result=$paiement->addPaymentToBank($user,'payment',$label,GETPOST('accountid'),GETPOST('chqemetteur'),GETPOST('chqbank'));
+	        if ($result < 0)
+	        {
+	            setEventMessage($paiement->error, 'errors');
+	            $error++;
+	        }
+	    }
 
-        // If payment dispatching on more than one invoice, we keep on summary page, otherwise go on invoice card
-        $invoiceid=0;
-        foreach ($paiement->amounts as $key => $amount)
-        {
-            $facid = $key;
-            if (is_numeric($amount) && $amount <> 0)
-            {
-                if ($invoiceid != 0) $invoiceid=-1; // There is more than one invoice payed by this payment
-                else $invoiceid=$facid;
-            }
-        }
-        if ($invoiceid > 0) $loc = DOL_URL_ROOT.'/compta/facture.php?facid='.$invoiceid;
-        else $loc = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$paiement_id;
-        header('Location: '.$loc);
-        exit;
-    }
-    else
-    {
-        $db->rollback();
-    }
+	    if (! $error)
+	    {
+	        $db->commit();
+
+	        // If payment dispatching on more than one invoice, we keep on summary page, otherwise go on invoice card
+	        $invoiceid=0;
+	        foreach ($paiement->amounts as $key => $amount)
+	        {
+	            $facid = $key;
+	            if (is_numeric($amount) && $amount <> 0)
+	            {
+	                if ($invoiceid != 0) $invoiceid=-1; // There is more than one invoice payed by this payment
+	                else $invoiceid=$facid;
+	            }
+	        }
+	        if ($invoiceid > 0) $loc = DOL_URL_ROOT.'/compta/facture.php?facid='.$invoiceid;
+	        else $loc = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$paiement_id;
+	        header('Location: '.$loc);
+	        exit;
+	    }
+	    else
+	    {
+	        $db->rollback();
+	    }
+	}
 }
 
 

+ 24 - 14
htdocs/contrat/class/contrat.class.php

@@ -211,23 +211,31 @@ class Contrat extends CommonObject
 		global $db, $langs, $conf;
 		$langs->load("contracts");
 
-		$dir = DOL_DOCUMENT_ROOT . "/core/modules/contract";
-
-		if (empty($conf->global->CONTRACT_ADDON))
+		if (!empty($conf->global->CONTRACT_ADDON))
 		{
-		    $conf->global->CONTRACT_ADDON='mod_contract_serpis';
-		}
+			$mybool = false;
 
-		$file = $conf->global->CONTRACT_ADDON.".php";
+			$file = $conf->global->CONTRACT_ADDON.".php";
+			$classname = $conf->global->CONTRACT_ADDON;
 
-		// Chargement de la classe de numerotation
-		$classname = $conf->global->CONTRACT_ADDON;
+			// Include file with class
+			$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
 
-		$result=include_once $dir.'/'.$file;
-		if ($result)
-		{
-			$obj = new $classname();
+			foreach ($dirmodels as $reldir) {
+
+				$dir = dol_buildpath($reldir."core/modules/contract/");
+
+				// Load file with numbering class (if found)
+				$mybool|=@include_once $dir.$file;
+			}
+
+			if (! $mybool)
+			{
+				dol_print_error('',"Failed to include file ".$file);
+				return '';
+			}
 
+			$obj = new $classname();
 			$numref = "";
 			$numref = $obj->getNextValue($soc,$this);
 
@@ -237,15 +245,17 @@ class Contrat extends CommonObject
 			}
 			else
 			{
+				$this->error = $obj->error;
 				dol_print_error($db,get_class($this)."::getNextValue ".$obj->error);
 				return "";
 			}
 		}
 		else
 		{
-			print $langs->trans("Error")." ".$langs->trans("Error_CONTRACT_ADDON_NotDefined");
+			$langs->load("errors");
+			print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete");
 			return "";
-			}
+		}
 	}
 
 	/**

+ 4 - 6
htdocs/core/class/html.formcompany.class.php

@@ -612,8 +612,7 @@ class FormCompany
                 }
 
 				print "\n".'<!-- Input text for third party with Ajax.Autocompleter (selectCompaniesForNewContact) -->'."\n";
-				//print '<table class="nobordernopadding"><tr class="nobordernopadding">';
-				//print '<td class="nobordernopadding">';
+
 				if ($obj->rowid == 0)
 				{
 					print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="" '.$htmloption.' />';
@@ -623,10 +622,9 @@ class FormCompany
 					print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="'.$obj->name.'" '.$htmloption.' />';
 				}
 				print ajax_autocompleter(($socid?$socid:-1),$htmlname,DOL_URL_ROOT.'/societe/ajaxcompanies.php','',$minLength);
-				//print '</td>';
-				//print '</tr>';
-				//print '</table>';
-				//print "\n";
+
+				print "\n";
+
 				return $socid;
 			}
 			else

+ 1 - 1
htdocs/core/class/menubase.class.php

@@ -152,7 +152,7 @@ class Menubase
         $sql.= " '".$this->fk_menu."',";
         $sql.= " ".($this->fk_mainmenu?"'".$this->fk_mainmenu."'":"null").",";
         $sql.= " ".($this->fk_leftmenu?"'".$this->fk_leftmenu."'":"null").",";
-        $sql.= " '".$this->position."',";
+        $sql.= " '".(int) $this->position."',";
         $sql.= " '".$this->db->escape($this->url)."',";
         $sql.= " '".$this->db->escape($this->target)."',";
         $sql.= " '".$this->db->escape($this->titre)."',";

+ 4 - 0
htdocs/core/modules/DolibarrModules.class.php

@@ -883,6 +883,8 @@ abstract class DolibarrModules
 
         $err=0;
 
+        if (empty($this->const)) return 0;
+
         foreach ($this->const as $key => $value)
         {
             $name      = $this->const[$key][0];
@@ -950,6 +952,8 @@ abstract class DolibarrModules
 
         $err=0;
 
+        if (empty($this->const)) return 0;
+
         foreach ($this->const as $key => $value)
         {
             $name      = $this->const[$key][0];

+ 2 - 1
htdocs/core/modules/supplier_invoice/mod_facture_fournisseur_tulip.php

@@ -125,7 +125,8 @@ class mod_facture_fournisseur_tulip extends ModeleNumRefSuppliersInvoices
 			return 0;
 		}
 
-		$numFinal=get_next_value($db,$mask,'facture_fourn','ref','',$objsoc->code_fournisseur,$object->datef);
+	    //Supplier invoices take invoice date instead of creation date for the mask
+		$numFinal=get_next_value($db,$mask,'facture_fourn','ref','',$objsoc->code_fournisseur,$object->date);
 
 		return  $numFinal;
 	}

+ 8 - 4
htdocs/cron/card.php

@@ -353,16 +353,20 @@ if (($action=="create") || ($action=="edit"))
 	print "<tr><td>";
 	print $langs->trans('CronEvery')."</td>";
 	print "<td><select name=\"nbfrequency\">";
-	for($i=1; $i<=60; $i++){
-		if(($object->frequency/$object->unitfrequency) == $i){
+	for($i=1; $i<=60; $i++)
+	{
+		if (! empty($object->unitfrequency) && ($object->frequency/$object->unitfrequency) == $i)
+		{
 			print "<option value='".$i."' selected='selected'>".$i."</option>";
 		}
-		else{
+		else
+		{
 			print "<option value='".$i."'>".$i."</option>";
 		}
 	}
 	$input = "<input type=\"radio\" name=\"unitfrequency\" value=\"60\" id=\"frequency_minute\" ";
-	if($object->unitfrequency=="60"){
+	if($object->unitfrequency=="60")
+	{
 		$input .= ' checked="checked" />';
 	}
 	else{

+ 433 - 442
htdocs/expedition/card.php

@@ -108,477 +108,468 @@ $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');
 
-if ($action == 'add')
+if (empty($reshook))
 {
-    $error=0;
-
-    $db->begin();
-
-    $object->note				= GETPOST('note','alpha');
-    $object->origin				= $origin;
-    $object->origin_id			= $origin_id;
-    $object->weight				= GETPOST('weight','int')==''?"NULL":GETPOST('weight','int');
-    $object->sizeH				= GETPOST('sizeH','int')==''?"NULL":GETPOST('sizeH','int');
-    $object->sizeW				= GETPOST('sizeW','int')==''?"NULL":GETPOST('sizeW','int');
-    $object->sizeS				= GETPOST('sizeS','int')==''?"NULL":GETPOST('sizeS','int');
-    $object->size_units			= GETPOST('size_units','int');
-    $object->weight_units		= GETPOST('weight_units','int');
-
-    $date_delivery = dol_mktime(GETPOST('date_deliveryhour','int'), GETPOST('date_deliverymin','int'), 0, GETPOST('date_deliverymonth','int'), GETPOST('date_deliveryday','int'), GETPOST('date_deliveryyear','int'));
-
-    // On va boucler sur chaque ligne du document d'origine pour completer objet expedition
-    // avec info diverses + qte a livrer
-    $classname = ucfirst($object->origin);
-    $objectsrc = new $classname($db);
-    $objectsrc->fetch($object->origin_id);
-
-    $object->socid					= $objectsrc->socid;
-    $object->ref_customer			= $objectsrc->ref_client;
-    $object->date_delivery			= $date_delivery;	// Date delivery planed
-    $object->fk_delivery_address	= $objectsrc->fk_delivery_address;
-    $object->shipping_method_id		= GETPOST('shipping_method_id','int');
-    $object->tracking_number		= GETPOST('tracking_number','alpha');
-    $object->ref_int				= GETPOST('ref_int','alpha');
-    $object->note_private			= GETPOST('note_private');
-    $object->note_public			= GETPOST('note_public');
-
-    $num=count($objectsrc->lines);
-    $totalqty=0;
-    for ($i = 0; $i < $num; $i++)
-    {
-        $qty = "qtyl".$i;
-		$j=0;
-		$sub_qty=array();
-		$subtotalqty=0;
-		$idl="idl".$i;
-		$batch="batchl".$i."_0";
-		if (isset($_POST[$batch])) {
-			//shipment line with batch-enable product
-			$qty .= '_'.$j;
-			while (isset($_POST[$batch])) {
-				$sub_qty[$j]['q']=GETPOST($qty,'int');
-				$sub_qty[$j]['id_batch']=GETPOST($batch,'int');
-				$subtotalqty+=$sub_qty[$j]['q'];
-				$j++;
-				$batch="batchl".$i."_".$j;
-				$qty = "qtyl".$i.'_'.$j;
-
-			}
-			$batch_line[$i]['detail']=$sub_qty;
-			$batch_line[$i]['qty']=$subtotalqty;
-			$batch_line[$i]['ix_l']=GETPOST($idl,'int');
-			$totalqty+=$subtotalqty;
-		} else {
-			//Standard product
-			if (GETPOST($qty,'int') > 0) $totalqty+=GETPOST($qty,'int');
-		}
-    }
-
-    if ($totalqty > 0)
-    {
-        //var_dump($_POST);exit;
-        for ($i = 0; $i < $num; $i++)
-        {
-            $qty = "qtyl".$i;
-			if (! isset($batch_line[$i])) {
-				if (GETPOST($qty,'int') > 0 || (GETPOST($qty,'int') == 0 && $conf->global->SHIPMENT_GETS_ALL_ORDER_PRODUCTS))
-				{
-					$ent = "entl".$i;
-					$idl = "idl".$i;
-					$entrepot_id = is_numeric(GETPOST($ent,'int'))?GETPOST($ent,'int'):GETPOST('entrepot_id','int');
-					if ($entrepot_id < 0) $entrepot_id='';
+	if ($action == 'add')
+	{
+	    $error=0;
+
+	    $db->begin();
+
+	    $object->note				= GETPOST('note','alpha');
+	    $object->origin				= $origin;
+	    $object->origin_id			= $origin_id;
+	    $object->weight				= GETPOST('weight','int')==''?"NULL":GETPOST('weight','int');
+	    $object->sizeH				= GETPOST('sizeH','int')==''?"NULL":GETPOST('sizeH','int');
+	    $object->sizeW				= GETPOST('sizeW','int')==''?"NULL":GETPOST('sizeW','int');
+	    $object->sizeS				= GETPOST('sizeS','int')==''?"NULL":GETPOST('sizeS','int');
+	    $object->size_units			= GETPOST('size_units','int');
+	    $object->weight_units		= GETPOST('weight_units','int');
+
+	    $date_delivery = dol_mktime(GETPOST('date_deliveryhour','int'), GETPOST('date_deliverymin','int'), 0, GETPOST('date_deliverymonth','int'), GETPOST('date_deliveryday','int'), GETPOST('date_deliveryyear','int'));
+
+	    // On va boucler sur chaque ligne du document d'origine pour completer objet expedition
+	    // avec info diverses + qte a livrer
+	    $classname = ucfirst($object->origin);
+	    $objectsrc = new $classname($db);
+	    $objectsrc->fetch($object->origin_id);
+
+	    $object->socid					= $objectsrc->socid;
+	    $object->ref_customer			= $objectsrc->ref_client;
+	    $object->date_delivery			= $date_delivery;	// Date delivery planed
+	    $object->fk_delivery_address	= $objectsrc->fk_delivery_address;
+	    $object->shipping_method_id		= GETPOST('shipping_method_id','int');
+	    $object->tracking_number		= GETPOST('tracking_number','alpha');
+	    $object->ref_int				= GETPOST('ref_int','alpha');
+	    $object->note_private			= GETPOST('note_private');
+	    $object->note_public			= GETPOST('note_public');
+
+	    $num=count($objectsrc->lines);
+	    $totalqty=0;
+	    for ($i = 0; $i < $num; $i++)
+	    {
+	        $qty = "qtyl".$i;
+			$j=0;
+			$sub_qty=array();
+			$subtotalqty=0;
+			$idl="idl".$i;
+			$batch="batchl".$i."_0";
+			if (isset($_POST[$batch])) {
+				//shipment line with batch-enable product
+				$qty .= '_'.$j;
+				while (isset($_POST[$batch])) {
+					$sub_qty[$j]['q']=GETPOST($qty,'int');
+					$sub_qty[$j]['id_batch']=GETPOST($batch,'int');
+					$subtotalqty+=$sub_qty[$j]['q'];
+					$j++;
+					$batch="batchl".$i."_".$j;
+					$qty = "qtyl".$i.'_'.$j;
 
-					$ret=$object->addline($entrepot_id,GETPOST($idl,'int'),GETPOST($qty,'int'));
-					if ($ret < 0)
-					{
-						$mesg='<div class="error">'.$object->error.'</div>';
-						$error++;
-					}
 				}
+				$batch_line[$i]['detail']=$sub_qty;
+				$batch_line[$i]['qty']=$subtotalqty;
+				$batch_line[$i]['ix_l']=GETPOST($idl,'int');
+				$totalqty+=$subtotalqty;
 			} else {
-				if ($batch_line[$i]['qty']>0) {
-					$ret=$object->addline_batch($batch_line[$i]);
-					if ($ret < 0)
+				//Standard product
+				if (GETPOST($qty,'int') > 0) $totalqty+=GETPOST($qty,'int');
+			}
+	    }
+
+	    if ($totalqty > 0)
+	    {
+	        //var_dump($_POST);exit;
+	        for ($i = 0; $i < $num; $i++)
+	        {
+	            $qty = "qtyl".$i;
+				if (! isset($batch_line[$i])) {
+					if (GETPOST($qty,'int') > 0 || (GETPOST($qty,'int') == 0 && $conf->global->SHIPMENT_GETS_ALL_ORDER_PRODUCTS))
 					{
-						$mesg='<div class="error">'.$object->error.'</div>';
-						$error++;
+						$ent = "entl".$i;
+						$idl = "idl".$i;
+						$entrepot_id = is_numeric(GETPOST($ent,'int'))?GETPOST($ent,'int'):GETPOST('entrepot_id','int');
+						if ($entrepot_id < 0) $entrepot_id='';
+
+						$ret=$object->addline($entrepot_id,GETPOST($idl,'int'),GETPOST($qty,'int'));
+						if ($ret < 0)
+						{
+							$mesg='<div class="error">'.$object->error.'</div>';
+							$error++;
+						}
+					}
+				} else {
+					if ($batch_line[$i]['qty']>0) {
+						$ret=$object->addline_batch($batch_line[$i]);
+						if ($ret < 0)
+						{
+							$mesg='<div class="error">'.$object->error.'</div>';
+							$error++;
+						}
 					}
 				}
-			}
-        }
-
-        if (! $error)
-        {
-            $ret=$object->create($user);
-            if ($ret <= 0)
-            {
-                $mesg='<div class="error">'.$object->error.'</div>';
-                $error++;
-            }
-        }
-    }
-    else
-    {
-        $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Qty")).'</div>';
-        $error++;
-    }
-
-    if (! $error)
-    {
-        $db->commit();
-        header("Location: card.php?id=".$object->id);
-        exit;
-    }
-    else
-    {
-        $db->rollback();
-        $_GET["commande_id"]=GETPOST('commande_id','int');
-        $action='create';
-    }
-}
-
-/*
- * Build a receiving receipt
- */
-else if ($action == 'create_delivery' && $conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer)
-{
-    $result = $object->create_delivery($user);
-    if ($result > 0)
-    {
-        header("Location: ".DOL_URL_ROOT.'/livraison/card.php?id='.$result);
-        exit;
-    }
-    else
-    {
-        $mesg=$object->error;
-    }
-}
-
-else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->expedition->valider)
-{
-    $object->fetch_thirdparty();
-
-    $result = $object->valid($user);
-
-    if ($result < 0)
-    {
-		$langs->load("errors");
-        setEventMessage($langs->trans($object->error),'errors');
-    }
-    else
-    {
-    	// Define output language
-    	if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
-    	{
-    		$outputlangs = $langs;
-    		$newlang = '';
-    		if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha');
-    		if ($conf->global->MAIN_MULTILANGS && empty($newlang))	$newlang = $object->thirdparty->default_lang;
-    		if (! empty($newlang)) {
-    			$outputlangs = new Translate("", $conf);
-    			$outputlangs->setDefaultLang($newlang);
-    		}
-    		$model=$object->modelpdf;
-    		$ret = $object->fetch($id); // Reload to get new records
-
-    		$result=$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
-    		if ($result < 0) dol_print_error($db,$result);
-    	}
-    }
-}
+	        }
+
+	        if (! $error)
+	        {
+	            $ret=$object->create($user);
+	            if ($ret <= 0)
+	            {
+	                $mesg='<div class="error">'.$object->error.'</div>';
+	                $error++;
+	            }
+	        }
+	    }
+	    else
+	    {
+	        $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Qty")).'</div>';
+	        $error++;
+	    }
+
+	    if (! $error)
+	    {
+	        $db->commit();
+	        header("Location: card.php?id=".$object->id);
+	        exit;
+	    }
+	    else
+	    {
+	        $db->rollback();
+	        $_GET["commande_id"]=GETPOST('commande_id','int');
+	        $action='create';
+	    }
+	}
 
-else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expedition->supprimer)
-{
-    $result = $object->delete();
-    if ($result > 0)
-    {
-        header("Location: ".DOL_URL_ROOT.'/expedition/index.php');
-        exit;
-    }
-    else
+	/*
+	 * Build a receiving receipt
+	 */
+	else if ($action == 'create_delivery' && $conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer)
 	{
-		$langs->load("errors");
-        setEventMessage($langs->trans($object->error),'errors');
-    }
-}
-
-else if ($action == 'reopen' && $user->rights->expedition->valider)
-{
-    $result = $object->setStatut(0);
-    if ($result < 0)
-    {
-        $mesg = $object->error;
-    }
-}
-
-else if ($action == 'setdate_livraison' && $user->rights->expedition->creer)
-{
-    //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
-    $datedelivery=dol_mktime(GETPOST('liv_hour','int'), GETPOST('liv_min','int'), 0, GETPOST('liv_month','int'), GETPOST('liv_day','int'), GETPOST('liv_year','int'));
-
-    $object->fetch($id);
-    $result=$object->set_date_livraison($user,$datedelivery);
-    if ($result < 0)
-    {
-        $mesg='<div class="error">'.$object->error.'</div>';
-    }
-}
-
-// Action update description of emailing
-else if ($action == 'settrackingnumber' || $action == 'settrackingurl'
-|| $action == 'settrueWeight'
-|| $action == 'settrueWidth'
-|| $action == 'settrueHeight'
-|| $action == 'settrueDepth'
-|| $action == 'setshipping_method_id')
-{
-    $error=0;
-
-    if ($action == 'settrackingnumber')		$object->tracking_number = trim(GETPOST('trackingnumber','alpha'));
-    if ($action == 'settrackingurl')		$object->tracking_url = trim(GETPOST('trackingurl','int'));
-    if ($action == 'settrueWeight')	{
-    	$object->trueWeight = trim(GETPOST('trueWeight','int'));
-		$object->weight_units = GETPOST('weight_units','int');
-    }
-    if ($action == 'settrueWidth')			$object->trueWidth = trim(GETPOST('trueWidth','int'));
-    if ($action == 'settrueHeight'){
-    				$object->trueHeight = trim(GETPOST('trueHeight','int'));
-					$object->size_units = GETPOST('size_units','int');
+	    $result = $object->create_delivery($user);
+	    if ($result > 0)
+	    {
+	        header("Location: ".DOL_URL_ROOT.'/livraison/card.php?id='.$result);
+	        exit;
+	    }
+	    else
+	    {
+	        $mesg=$object->error;
+	    }
 	}
-    if ($action == 'settrueDepth')			$object->trueDepth = trim(GETPOST('trueDepth','int'));
-    if ($action == 'setshipping_method_id')	$object->shipping_method_id = trim(GETPOST('shipping_method_id','int'));
-
-    if (! $error)
-    {
-        if ($object->update($user) >= 0)
-        {
-            header("Location: card.php?id=".$object->id);
-            exit;
-        }
-        setEventMessage($object->error,'errors');
-    }
 
-    $action="";
-}
-
-// Build document
-else if ($action == 'builddoc')	// En get ou en post
-{
+	else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->expedition->valider)
+	{
+	    $object->fetch_thirdparty();
 
-	// Save last template used to generate document
-	if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
+	    $result = $object->valid($user);
 
-    // Define output language
-    $outputlangs = $langs;
-    $newlang='';
-    if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id','alpha');
-    if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$shipment->client->default_lang;
-    if (! empty($newlang))
-    {
-        $outputlangs = new Translate("",$conf);
-        $outputlangs->setDefaultLang($newlang);
-    }
-	$result = $object->generateDocument($object->modelpdf, $outputlangs);
-    if ($result <= 0)
-    {
-        dol_print_error($db,$result);
-        exit;
-    }
-}
-
-// Delete file in doc form
-elseif ($action == 'remove_file')
-{
-	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-
-	$upload_dir =	$conf->expedition->dir_output . "/sending";
-	$file =	$upload_dir	. '/' .	GETPOST('file');
-	$ret=dol_delete_file($file,0,0,0,$object);
-	if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
-	else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
-}
+	    if ($result < 0)
+	    {
+			$langs->load("errors");
+	        setEventMessage($langs->trans($object->error),'errors');
+	    }
+	    else
+	    {
+	    	// Define output language
+	    	if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
+	    	{
+	    		$outputlangs = $langs;
+	    		$newlang = '';
+	    		if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha');
+	    		if ($conf->global->MAIN_MULTILANGS && empty($newlang))	$newlang = $object->thirdparty->default_lang;
+	    		if (! empty($newlang)) {
+	    			$outputlangs = new Translate("", $conf);
+	    			$outputlangs->setDefaultLang($newlang);
+	    		}
+	    		$model=$object->modelpdf;
+	    		$ret = $object->fetch($id); // Reload to get new records
+
+	    		$result=$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
+	    		if ($result < 0) dol_print_error($db,$result);
+	    	}
+	    }
+	}
 
-/*
- * Add file in email form
-*/
-if (GETPOST('addfile','alpha'))
-{
-    require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+	else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expedition->supprimer)
+	{
+	    $result = $object->delete();
+	    if ($result > 0)
+	    {
+	        header("Location: ".DOL_URL_ROOT.'/expedition/index.php');
+	        exit;
+	    }
+	    else
+		{
+			$langs->load("errors");
+	        setEventMessage($langs->trans($object->error),'errors');
+	    }
+	}
 
-    // Set tmp user directory TODO Use a dedicated directory for temp mails files
-    $vardir=$conf->user->dir_output."/".$user->id;
-    $upload_dir_tmp = $vardir.'/temp';
+	else if ($action == 'reopen' && $user->rights->expedition->valider)
+	{
+	    $result = $object->setStatut(0);
+	    if ($result < 0)
+	    {
+	        $mesg = $object->error;
+	    }
+	}
 
-    dol_add_file_process($upload_dir_tmp,0,0);
-    $action ='presend';
-}
+	else if ($action == 'setdate_livraison' && $user->rights->expedition->creer)
+	{
+	    //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
+	    $datedelivery=dol_mktime(GETPOST('liv_hour','int'), GETPOST('liv_min','int'), 0, GETPOST('liv_month','int'), GETPOST('liv_day','int'), GETPOST('liv_year','int'));
+
+	    $object->fetch($id);
+	    $result=$object->set_date_livraison($user,$datedelivery);
+	    if ($result < 0)
+	    {
+	        $mesg='<div class="error">'.$object->error.'</div>';
+	    }
+	}
 
-/*
- * Remove file in email form
-*/
-if (GETPOST('removedfile','alpha'))
-{
-    require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+	// Action update description of emailing
+	else if ($action == 'settrackingnumber' || $action == 'settrackingurl'
+	|| $action == 'settrueWeight'
+	|| $action == 'settrueWidth'
+	|| $action == 'settrueHeight'
+	|| $action == 'settrueDepth'
+	|| $action == 'setshipping_method_id')
+	{
+	    $error=0;
+
+	    if ($action == 'settrackingnumber')		$object->tracking_number = trim(GETPOST('trackingnumber','alpha'));
+	    if ($action == 'settrackingurl')		$object->tracking_url = trim(GETPOST('trackingurl','int'));
+	    if ($action == 'settrueWeight')	{
+	    	$object->trueWeight = trim(GETPOST('trueWeight','int'));
+			$object->weight_units = GETPOST('weight_units','int');
+	    }
+	    if ($action == 'settrueWidth')			$object->trueWidth = trim(GETPOST('trueWidth','int'));
+	    if ($action == 'settrueHeight'){
+	    				$object->trueHeight = trim(GETPOST('trueHeight','int'));
+						$object->size_units = GETPOST('size_units','int');
+		}
+	    if ($action == 'settrueDepth')			$object->trueDepth = trim(GETPOST('trueDepth','int'));
+	    if ($action == 'setshipping_method_id')	$object->shipping_method_id = trim(GETPOST('shipping_method_id','int'));
+
+	    if (! $error)
+	    {
+	        if ($object->update($user) >= 0)
+	        {
+	            header("Location: card.php?id=".$object->id);
+	            exit;
+	        }
+	        setEventMessage($object->error,'errors');
+	    }
+
+	    $action="";
+	}
 
-    // Set tmp user directory
-    $vardir=$conf->user->dir_output."/".$user->id;
-    $upload_dir_tmp = $vardir.'/temp';
+	// Build document
+	else if ($action == 'builddoc')	// En get ou en post
+	{
 
-    // TODO Delete only files that was uploaded from email form
-    dol_remove_file_process(GETPOST('removedfile','int'),0);
-    $action ='presend';
-}
+		// Save last template used to generate document
+		if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
+
+	    // Define output language
+	    $outputlangs = $langs;
+	    $newlang='';
+	    if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id','alpha');
+	    if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$shipment->client->default_lang;
+	    if (! empty($newlang))
+	    {
+	        $outputlangs = new Translate("",$conf);
+	        $outputlangs->setDefaultLang($newlang);
+	    }
+		$result = $object->generateDocument($object->modelpdf, $outputlangs);
+	    if ($result <= 0)
+	    {
+	        dol_print_error($db,$result);
+	        exit;
+	    }
+	}
 
-/*
- * Send mail
-*/
-if ($action == 'send' && ! GETPOST('addfile','alpha') && ! GETPOST('removedfile','alpha') && ! GETPOST('cancel','alpha'))
-{
-    $langs->load('mails');
+	// Delete file in doc form
+	elseif ($action == 'remove_file')
+	{
+		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
 
-//        $ref = dol_sanitizeFileName($object->ref);
-//        $file = $conf->expedition->dir_output . '/sending/' . $ref . '/' . $ref . '.pdf';
+		$upload_dir =	$conf->expedition->dir_output . "/sending";
+		$file =	$upload_dir	. '/' .	GETPOST('file');
+		$ret=dol_delete_file($file,0,0,0,$object);
+		if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
+		else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
+	}
 
-//        if (is_readable($file))
-//        {
-            if (GETPOST('sendto','alpha'))
-            {
-                // Le destinataire a ete fourni via le champ libre
-                $sendto = GETPOST('sendto','alpha');
-                $sendtoid = 0;
-            }
-            elseif (GETPOST('receiver','alpha') != '-1')
-            {
-                // Recipient was provided from combo list
-                if (GETPOST('receiver','alpha') == 'thirdparty') // Id of third party
-                {
-                    $sendto = $object->client->email;
-                    $sendtoid = 0;
-                }
-                else	// Id du contact
-                {
-                    $sendto = $object->client->contact_get_property(GETPOST('receiver','alpha'),'email');
-                    $sendtoid = GETPOST('receiver','alpha');
-                }
-            }
+	/*
+	 * Add file in email form
+	*/
+	if (GETPOST('addfile','alpha'))
+	{
+	    require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
 
-            if (dol_strlen($sendto))
-            {
-                $langs->load("commercial");
+	    // Set tmp user directory TODO Use a dedicated directory for temp mails files
+	    $vardir=$conf->user->dir_output."/".$user->id;
+	    $upload_dir_tmp = $vardir.'/temp';
 
-                $from = GETPOST('fromname','alpha') . ' <' . GETPOST('frommail','alpha') .'>';
-                $replyto = GETPOST('replytoname','alpha'). ' <' . GETPOST('replytomail','alpha').'>';
-                $message = GETPOST('message');
-                $sendtocc = GETPOST('sendtocc','alpha');
-                $deliveryreceipt = GETPOST('deliveryreceipt','alpha');
+	    dol_add_file_process($upload_dir_tmp,0,0);
+	    $action ='presend';
+	}
 
-                if ($action == 'send')
-                {
-                    if (dol_strlen(GETPOST('subject','alpha'))) $subject=GETPOST('subject','alpha');
-                    else $subject = $langs->transnoentities('Shipping').' '.$object->ref;
-                    $actiontypecode='AC_SHIP';
-                    $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
-                    if ($message)
-                    {
-						if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc);
-						$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject);
-						$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":");
-						$actionmsg = dol_concatdesc($actionmsg, $message);
-                    }
-                    $actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
-                }
+	/*
+	 * Remove file in email form
+	*/
+	if (GETPOST('removedfile','alpha'))
+	{
+	    require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
 
-                // Create form object
-                include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
-                $formmail = new FormMail($db);
+	    // Set tmp user directory
+	    $vardir=$conf->user->dir_output."/".$user->id;
+	    $upload_dir_tmp = $vardir.'/temp';
 
-                $attachedfiles=$formmail->get_attached_files();
-                $filepath = $attachedfiles['paths'];
-                $filename = $attachedfiles['names'];
-                $mimetype = $attachedfiles['mimes'];
+	    // TODO Delete only files that was uploaded from email form
+	    dol_remove_file_process(GETPOST('removedfile','int'),0);
+	    $action ='presend';
+	}
 
-                // Send mail
-                require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
-                $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt,-1);
-                if ($mailfile->error)
-                {
-                    $mesg='<div class="error">'.$mailfile->error.'</div>';
-                }
-                else
-                {
-                    $result=$mailfile->sendfile();
-                    if ($result)
-                    {
-                        $error=0;
-
-                        // Initialisation donnees
-                        $object->sendtoid		= $sendtoid;
-                        $object->actiontypecode	= $actiontypecode;
-                        $object->actionmsg		= $actionmsg;
-                        $object->actionmsg2		= $actionmsg2;
-                        $object->fk_element		= $object->id;
-                        $object->elementtype	= $object->element;
-
-                        // Appel des triggers
-                        include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
-                        $interface=new Interfaces($db);
-                        $result=$interface->run_triggers('SHIPPING_SENTBYMAIL',$object,$user,$langs,$conf);
-                        if ($result < 0) {
-                            $error++; $object->errors=$interface->errors;
-                        }
-                        // Fin appel triggers
-
-                        if ($error)
-                        {
-                            dol_print_error($db);
-                        }
-                        else
-                        {
-                            // Redirect here
-                            // This avoid sending mail twice if going out and then back to page
-                        	$mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2));
-                            setEventMessage($mesg);
-                            header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
-                            exit;
-                        }
-                    }
-                    else
-                    {
-                        $langs->load("other");
-                        $mesg='<div class="error">';
-                        if ($mailfile->error)
-                        {
-                            $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
-                            $mesg.='<br>'.$mailfile->error;
-                        }
-                        else
-                        {
-                            $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
-                        }
-                        $mesg.='</div>';
-                    }
-                }
-            }
-            else
-            {
-                $langs->load("other");
-                $mesg='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').' !</div>';
-                $action='presend';
-                dol_syslog('Recipient email is empty');
-            }
-/*        }
-        else
-        {
-            $langs->load("errors");
-            $mesg='<div class="error">'.$langs->trans('ErrorCantReadFile',$file).'</div>';
-            dol_syslog('Failed to read file: '.$file);
-        }*/
-}
+	/*
+	 * Send mail
+	*/
+	if ($action == 'send' && ! GETPOST('addfile','alpha') && ! GETPOST('removedfile','alpha') && ! GETPOST('cancel','alpha'))
+	{
+	    $langs->load('mails');
+
+	    if (GETPOST('sendto','alpha'))
+	    {
+	    	// Le destinataire a ete fourni via le champ libre
+	    	$sendto = GETPOST('sendto','alpha');
+	    	$sendtoid = 0;
+	    }
+	    elseif (GETPOST('receiver','alpha') != '-1')
+	    {
+	    	// Recipient was provided from combo list
+	    	if (GETPOST('receiver','alpha') == 'thirdparty') // Id of third party
+	    	{
+	    		$sendto = $object->client->email;
+	    		$sendtoid = 0;
+	    	}
+	    	else	// Id du contact
+	    	{
+	    		$sendto = $object->client->contact_get_property(GETPOST('receiver','alpha'),'email');
+	    		$sendtoid = GETPOST('receiver','alpha');
+	    	}
+	    }
+
+	    if (dol_strlen($sendto))
+	    {
+	    	$langs->load("commercial");
+
+	    	$from = GETPOST('fromname','alpha') . ' <' . GETPOST('frommail','alpha') .'>';
+	    	$replyto = GETPOST('replytoname','alpha'). ' <' . GETPOST('replytomail','alpha').'>';
+	    	$message = GETPOST('message');
+	    	$sendtocc = GETPOST('sendtocc','alpha');
+	    	$deliveryreceipt = GETPOST('deliveryreceipt','alpha');
+
+	    	if ($action == 'send')
+	    	{
+	    		if (dol_strlen(GETPOST('subject','alpha'))) $subject=GETPOST('subject','alpha');
+	    		else $subject = $langs->transnoentities('Shipping').' '.$object->ref;
+	    		$actiontypecode='AC_SHIP';
+	    		$actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
+	    		if ($message)
+	    		{
+	    			if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc);
+	    			$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject);
+	    			$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":");
+	    			$actionmsg = dol_concatdesc($actionmsg, $message);
+	    		}
+	    		$actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
+	    	}
+
+	    	// Create form object
+	    	include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
+	    	$formmail = new FormMail($db);
+
+	    	$attachedfiles=$formmail->get_attached_files();
+	    	$filepath = $attachedfiles['paths'];
+	    	$filename = $attachedfiles['names'];
+	    	$mimetype = $attachedfiles['mimes'];
+
+	    	// Send mail
+	    	require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
+	    	$mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt,-1);
+	    	if ($mailfile->error)
+	    	{
+	    		$mesg='<div class="error">'.$mailfile->error.'</div>';
+	    	}
+	    	else
+	    	{
+	    		$result=$mailfile->sendfile();
+	    		if ($result)
+	    		{
+	    			$error=0;
+
+	    			// Initialisation donnees
+	    			$object->sendtoid		= $sendtoid;
+	    			$object->actiontypecode	= $actiontypecode;
+	    			$object->actionmsg		= $actionmsg;
+	    			$object->actionmsg2		= $actionmsg2;
+	    			$object->fk_element		= $object->id;
+	    			$object->elementtype	= $object->element;
+
+	    			// Appel des triggers
+	    			include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
+	    			$interface=new Interfaces($db);
+	    			$result=$interface->run_triggers('SHIPPING_SENTBYMAIL',$object,$user,$langs,$conf);
+	    			if ($result < 0) {
+	    				$error++; $object->errors=$interface->errors;
+	    			}
+	    			// Fin appel triggers
+
+	    			if ($error)
+	    			{
+	    				dol_print_error($db);
+	    			}
+	    			else
+	    			{
+	    				// Redirect here
+	    				// This avoid sending mail twice if going out and then back to page
+	    				$mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2));
+	    				setEventMessage($mesg);
+	    				header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
+	    				exit;
+	    			}
+	    		}
+	    		else
+	    		{
+	    			$langs->load("other");
+	    			$mesg='<div class="error">';
+	    			if ($mailfile->error)
+	    			{
+	    				$mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
+	    				$mesg.='<br>'.$mailfile->error;
+	    			}
+	    			else
+	    			{
+	    				$mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
+	    			}
+	    			$mesg.='</div>';
+	    		}
+	    	}
+	    }
+	    else
+	    {
+	    	$langs->load("other");
+	    	$mesg='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').' !</div>';
+	    	$action='presend';
+	    	dol_syslog('Recipient email is empty');
+	    }
+	}
 
-else if ($action == 'classifybilled')
-{
-    $object->fetch($id);
-    $object->set_billed();
+	else if ($action == 'classifybilled')
+	{
+	    $object->fetch($id);
+	    $object->set_billed();
+	}
 }
 
 

+ 26 - 17
htdocs/expedition/class/expedition.class.php

@@ -121,21 +121,30 @@ class Expedition extends CommonObject
 		global $db, $langs, $conf;
 		$langs->load("sendings");
 
-		$dir = DOL_DOCUMENT_ROOT . "/core/modules/expedition";
-
-	    if (empty($conf->global->EXPEDITION_ADDON_NUMBER))
+	    if (!empty($conf->global->EXPEDITION_ADDON_NUMBER))
         {
-            $conf->global->EXPEDITION_ADDON_NUMBER='mod_expedition_safor';
-        }
+			$mybool = false;
 
-		$file = $conf->global->EXPEDITION_ADDON_NUMBER.".php";
+			$file = $conf->global->EXPEDITION_ADDON_NUMBER.".php";
+			$classname = $conf->global->EXPEDITION_ADDON_NUMBER;
 
-		// Chargement de la classe de numerotation
-		$classname = $conf->global->EXPEDITION_ADDON_NUMBER;
+	        // Include file with class
+	        $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
+
+	        foreach ($dirmodels as $reldir) {
+
+		        $dir = dol_buildpath($reldir."core/modules/expedition/");
+
+		        // Load file with numbering class (if found)
+		        $mybool|=@include_once $dir.$file;
+	        }
+
+	        if (! $mybool)
+	        {
+		        dol_print_error('',"Failed to include file ".$file);
+		        return '';
+	        }
 
-		$result=include_once $dir.'/'.$file;
-		if ($result)
-		{
 			$obj = new $classname();
 			$numref = "";
 			$numref = $obj->getNextValue($soc,$this);
@@ -149,12 +158,12 @@ class Expedition extends CommonObject
 				dol_print_error($db,get_class($this)."::getNextNumRef ".$obj->error);
 				return "";
 			}
-		}
-		else
-		{
-			print $langs->trans("Error")." ".$langs->trans("Error_EXPEDITION_ADDON_NUMBER_NotDefined");
-			return "";
-		}
+        }
+	    else
+	    {
+		    print $langs->trans("Error")." ".$langs->trans("Error_EXPEDITION_ADDON_NUMBER_NotDefined");
+		    return "";
+	    }
 	}
 
 	/**

+ 21 - 12
htdocs/fichinter/class/fichinter.class.php

@@ -585,25 +585,33 @@ class Fichinter extends CommonObject
 		global $conf, $db, $langs;
 		$langs->load("interventions");
 
-		$dir = DOL_DOCUMENT_ROOT . "/core/modules/fichinter/";
-
 		if (! empty($conf->global->FICHEINTER_ADDON))
 		{
-			$file = $conf->global->FICHEINTER_ADDON.".php";
-			$classname = $conf->global->FICHEINTER_ADDON;
-			if (! file_exists($dir.$file))
-			{
-				$file='mod_'.$file;
-				$classname='mod_'.$classname;
+			$mybool = false;
+
+			$file = "mod_".$conf->global->FICHEINTER_ADDON.".php";
+			$classname = "mod_".$conf->global->FICHEINTER_ADDON;
+
+			// Include file with class
+			$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
+
+			foreach ($dirmodels as $reldir) {
+
+				$dir = dol_buildpath($reldir."core/modules/fichinter/");
+
+				// Load file with numbering class (if found)
+				$mybool|=@include_once $dir.$file;
 			}
 
-			// Chargement de la classe de numerotation
-			require_once $dir.$file;
+			if (! $mybool)
+			{
+				dol_print_error('',"Failed to include file ".$file);
+				return '';
+			}
 
 			$obj = new $classname();
-
 			$numref = "";
-			$numref = $obj->getNumRef($soc,$this);
+			$numref = $obj->getNextValue($soc,$this);
 
 			if ( $numref != "")
 			{
@@ -617,6 +625,7 @@ class Fichinter extends CommonObject
 		}
 		else
 		{
+			$langs->load("errors");
 			print $langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined");
 			return "";
 		}

+ 28 - 25
htdocs/fourn/card.php

@@ -60,34 +60,37 @@ $parameters=array('socid'=>$socid);
 $reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action);    // Note that $action and $object may have been modified by some hooks
 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
 
-if ($action == 'setsupplieraccountancycode')
+if (empty($reshook))
 {
-	$cancelbutton = GETPOST('cancel');
-	if (! $cancelbutton) 
+	if ($action == 'setsupplieraccountancycode')
 	{
-		$result=$object->fetch($id);
-   		$object->code_compta_fournisseur=$_POST["supplieraccountancycode"];
-	    $result=$object->update($object->id,$user,1,0,1);
-	    if ($result < 0)
-	    {
-	        $mesg=join(',',$object->errors);
-	    }
+		$cancelbutton = GETPOST('cancel');
+		if (! $cancelbutton)
+		{
+			$result=$object->fetch($id);
+	   		$object->code_compta_fournisseur=$_POST["supplieraccountancycode"];
+		    $result=$object->update($object->id,$user,1,0,1);
+		    if ($result < 0)
+		    {
+		        $mesg=join(',',$object->errors);
+		    }
+		}
+	    $action="";
+	}
+	// conditions de reglement
+	if ($action == 'setconditions' && $user->rights->societe->creer)
+	{
+		$object->fetch($id);
+		$result=$object->setPaymentTerms(GETPOST('cond_reglement_supplier_id','int'));
+		if ($result < 0) dol_print_error($db,$object->error);
+	}
+	// mode de reglement
+	if ($action == 'setmode' && $user->rights->societe->creer)
+	{
+		$object->fetch($id);
+		$result=$object->setPaymentMethods(GETPOST('mode_reglement_supplier_id','int'));
+		if ($result < 0) dol_print_error($db,$object->error);
 	}
-    $action="";
-}
-// conditions de reglement
-if ($action == 'setconditions' && $user->rights->societe->creer)
-{
-	$object->fetch($id);
-	$result=$object->setPaymentTerms(GETPOST('cond_reglement_supplier_id','int'));
-	if ($result < 0) dol_print_error($db,$object->error);
-}
-// mode de reglement
-if ($action == 'setmode' && $user->rights->societe->creer)
-{
-	$object->fetch($id);
-	$result=$object->setPaymentMethods(GETPOST('mode_reglement_supplier_id','int'));
-	if ($result < 0) dol_print_error($db,$object->error);
 }
 
 

+ 30 - 26
htdocs/fourn/class/fournisseur.commande.class.php

@@ -557,44 +557,48 @@ class CommandeFournisseur extends CommonOrder
         global $db, $langs, $conf;
         $langs->load("orders");
 
-        $dir = DOL_DOCUMENT_ROOT .'/core/modules/supplier_order/';
-
         if (! empty($conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER))
         {
+            $mybool = false;
+
             $file = $conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER.'.php';
+            $classname=$conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER;
 
-            if (is_readable($dir.'/'.$file))
-            {
-                // Definition du nom de modele de numerotation de commande fournisseur
-                $modName=$conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER;
-                require_once $dir.'/'.$file;
+            // Include file with class
+            $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
 
-                // Recuperation de la nouvelle reference
-                $objMod = new $modName($this->db);
+            foreach ($dirmodels as $reldir) {
 
-                $numref = "";
-                $numref = $objMod->commande_get_num($soc,$this);
+                $dir = dol_buildpath($reldir."core/modules/supplier_order/");
 
-                if ( $numref != "")
-                {
-                    return $numref;
-                }
-                else
-                {
-                    dol_print_error($db, get_class($this)."::getNextNumRef ".$obj->error);
-                    return -1;
-                }
+                // Load file with numbering class (if found)
+                $mybool|=@include_once $dir.$file;
             }
-            else
+
+            if (! $mybool)
             {
-                print $langs->trans("Error")." ".$langs->trans("Error_FailedToLoad_COMMANDE_SUPPLIER_ADDON_File",$conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER);
-                return -2;
+                dol_print_error('',"Failed to include file ".$file);
+                return '';
+            }
+
+            $obj = new $classname();
+            $numref = $obj->getNextValue($soc,$this);
+
+            if ( $numref != "")
+            {
+                return $numref;
+            }
+            else
+			{
+                $this->error = $obj->error;
+                dol_print_error($db, get_class($this)."::getNextNumRef ".$obj->error);
+                return -1;
             }
         }
         else
-        {
-            print $langs->trans("Error")." ".$langs->trans("Error_COMMANDE_SUPPLIER_ADDON_NotDefined");
-            return -3;
+		{
+            $this->error = "Error_COMMANDE_SUPPLIER_ADDON_NotDefined";
+            return -2;
         }
     }
 

+ 7 - 3
htdocs/fourn/class/fournisseur.facture.class.php

@@ -1514,10 +1514,14 @@ class FactureFournisseur extends CommonInvoice
 
         $file = $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER.".php";
         $classname = $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER;
+
         // Include file with class
-        foreach ($conf->file->dol_document_root as $dirroot)
-        {
-            $dir = $dirroot."/core/modules/supplier_invoice/";
+        $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
+
+        foreach ($dirmodels as $reldir) {
+
+            $dir = dol_buildpath($reldir."core/modules/supplier_invoice/");
+
             // Load file with numbering class (if found)
             $mybool|=@include_once $dir.$file;
         }

+ 150 - 147
htdocs/fourn/facture/paiement.php

@@ -66,170 +66,173 @@ if ($user->societe_id > 0)
 // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
 $hookmanager->initHooks(array('paymentsupplier'));
 
-$parameters=array('socid'=>$socid);
-$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');
 
 
 /*
  * Actions
  */
 
-if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='yes'))
-{
-    $error = 0;
-
-    $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
-    $paiement_id = 0;
-    $totalpayment = 0;
-    $atleastonepaymentnotnull = 0;
+$parameters=array('socid'=>$socid);
+$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');
 
-    // Generate payment array and check if there is payment higher than invoice and payment date before invoice date
-    $tmpinvoice=new FactureFournisseur($db);
-    foreach ($_POST as $key => $value)
-    {
-        if (substr($key,0,7) == 'amount_')
-        {
-            $cursorfacid = substr($key,7);
-            $amounts[$cursorfacid] = price2num(trim(GETPOST($key)));
-            $totalpayment = $totalpayment + $amounts[$cursorfacid];
-            if (! empty($amounts[$cursorfacid])) $atleastonepaymentnotnull++;
-            $result=$tmpinvoice->fetch($cursorfacid);
-            if ($result <= 0) dol_print_error($db);
-            $amountsresttopay[$cursorfacid]=price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement());
-            if ($amounts[$cursorfacid])
-            {
-	            // Check amount
-	            if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid])))
-	            {
-	                $addwarning=1;
-	                $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPaySupplier")).' '.$langs->trans("HelpPaymentHigherThanReminderToPaySupplier");
-	            }
-	            // Check date
-	            if ($datepaye && ($datepaye < $tmpinvoice->date))
+if (empty($reshook))
+{
+	if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='yes'))
+	{
+	    $error = 0;
+
+	    $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
+	    $paiement_id = 0;
+	    $totalpayment = 0;
+	    $atleastonepaymentnotnull = 0;
+
+	    // Generate payment array and check if there is payment higher than invoice and payment date before invoice date
+	    $tmpinvoice=new FactureFournisseur($db);
+	    foreach ($_POST as $key => $value)
+	    {
+	        if (substr($key,0,7) == 'amount_')
+	        {
+	            $cursorfacid = substr($key,7);
+	            $amounts[$cursorfacid] = price2num(trim(GETPOST($key)));
+	            $totalpayment = $totalpayment + $amounts[$cursorfacid];
+	            if (! empty($amounts[$cursorfacid])) $atleastonepaymentnotnull++;
+	            $result=$tmpinvoice->fetch($cursorfacid);
+	            if ($result <= 0) dol_print_error($db);
+	            $amountsresttopay[$cursorfacid]=price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement());
+	            if ($amounts[$cursorfacid])
 	            {
-	            	$langs->load("errors");
-	                //$error++;
-	                setEventMessage($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye,'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), 'warnings');
+		            // Check amount
+		            if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid])))
+		            {
+		                $addwarning=1;
+		                $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPaySupplier")).' '.$langs->trans("HelpPaymentHigherThanReminderToPaySupplier");
+		            }
+		            // Check date
+		            if ($datepaye && ($datepaye < $tmpinvoice->date))
+		            {
+		            	$langs->load("errors");
+		                //$error++;
+		                setEventMessage($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye,'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), 'warnings');
+		            }
 	            }
-            }
-
-            $formquestion[$i++]=array('type' => 'hidden','name' => $key,  'value' => $_POST[$key]);
-        }
-    }
-
-    // Check parameters
-    if ($_POST['paiementid'] <= 0)
-    {
-    	setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('PaymentMode')), 'errors');
-        $error++;
-    }
-
-    if (! empty($conf->banque->enabled))
-    {
-        // If bank module is on, account is required to enter a payment
-        if (GETPOST('accountid') <= 0)
-        {
-        	setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), 'errors');
-            $error++;
-        }
-    }
-
-    if (empty($totalpayment) && empty($atleastonepaymentnotnull))
-    {
-    	setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->trans('PaymentAmount')), 'errors');
-        $error++;
-    }
-
-    if (empty($datepaye))
-    {
-    	setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('Date')), 'errors');
-        $error++;
-    }
-}
-
-/*
- * Action add_paiement
- */
-if ($action == 'add_paiement')
-{
-    if ($error)
-    {
-        $action = 'create';
-    }
-    // Le reste propre a cette action s'affiche en bas de page.
-}
 
+	            $formquestion[$i++]=array('type' => 'hidden','name' => $key,  'value' => $_POST[$key]);
+	        }
+	    }
+
+	    // Check parameters
+	    if ($_POST['paiementid'] <= 0)
+	    {
+	    	setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('PaymentMode')), 'errors');
+	        $error++;
+	    }
+
+	    if (! empty($conf->banque->enabled))
+	    {
+	        // If bank module is on, account is required to enter a payment
+	        if (GETPOST('accountid') <= 0)
+	        {
+	        	setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), 'errors');
+	            $error++;
+	        }
+	    }
+
+	    if (empty($totalpayment) && empty($atleastonepaymentnotnull))
+	    {
+	    	setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->trans('PaymentAmount')), 'errors');
+	        $error++;
+	    }
+
+	    if (empty($datepaye))
+	    {
+	    	setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('Date')), 'errors');
+	        $error++;
+	    }
+	}
 
-/*
- * Action confirm_paiement
- */
-if ($action == 'confirm_paiement' && $confirm == 'yes')
-{
-    $error=0;
+	/*
+	 * Action add_paiement
+	 */
+	if ($action == 'add_paiement')
+	{
+	    if ($error)
+	    {
+	        $action = 'create';
+	    }
+	    // Le reste propre a cette action s'affiche en bas de page.
+	}
 
-    $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
 
-    if (! $error)
-    {
-        $db->begin();
-
-        // Creation de la ligne paiement
-        $paiement = new PaiementFourn($db);
-        $paiement->datepaye     = $datepaye;
-        $paiement->amounts      = $amounts;   // Array of amounts
-        $paiement->paiementid   = $_POST['paiementid'];
-        $paiement->num_paiement = $_POST['num_paiement'];
-        $paiement->note         = $_POST['comment'];
-        if (! $error)
-        {
-            $paiement_id = $paiement->create($user,(GETPOST('closepaidinvoices')=='on'?1:0));
-            if ($paiement_id < 0)
-            {
-            	setEventMessage($paiement->error, 'errors');
-                $error++;
-            }
-        }
+	/*
+	 * Action confirm_paiement
+	 */
+	if ($action == 'confirm_paiement' && $confirm == 'yes')
+	{
+	    $error=0;
+
+	    $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
+
+	    if (! $error)
+	    {
+	        $db->begin();
+
+	        // Creation de la ligne paiement
+	        $paiement = new PaiementFourn($db);
+	        $paiement->datepaye     = $datepaye;
+	        $paiement->amounts      = $amounts;   // Array of amounts
+	        $paiement->paiementid   = $_POST['paiementid'];
+	        $paiement->num_paiement = $_POST['num_paiement'];
+	        $paiement->note         = $_POST['comment'];
+	        if (! $error)
+	        {
+	            $paiement_id = $paiement->create($user,(GETPOST('closepaidinvoices')=='on'?1:0));
+	            if ($paiement_id < 0)
+	            {
+	            	setEventMessage($paiement->error, 'errors');
+	                $error++;
+	            }
+	        }
 
-        if (! $error)
-        {
-            $result=$paiement->addPaymentToBank($user,'payment_supplier','(SupplierInvoicePayment)',$_POST['accountid'],'','');
-            if ($result < 0)
-            {
-            	setEventMessage($paiement->error, 'errors');
-                $error++;
-            }
-        }
+	        if (! $error)
+	        {
+	            $result=$paiement->addPaymentToBank($user,'payment_supplier','(SupplierInvoicePayment)',$_POST['accountid'],'','');
+	            if ($result < 0)
+	            {
+	            	setEventMessage($paiement->error, 'errors');
+	                $error++;
+	            }
+	        }
 
-        if (! $error)
-        {
-            $db->commit();
+	        if (! $error)
+	        {
+	            $db->commit();
 
-            // If payment dispatching on more than one invoice, we keep on summary page, otherwise go on invoice card
-            $invoiceid=0;
-            foreach ($paiement->amounts as $key => $amount)
-            {
-                $facid = $key;
-                if (is_numeric($amount) && $amount <> 0)
-                {
-                    if ($invoiceid != 0) $invoiceid=-1; // There is more than one invoice payed by this payment
-                    else $invoiceid=$facid;
-                }
-            }
-            if ($invoiceid > 0) $loc = DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$invoiceid;
-            else $loc = DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$paiement_id;
-            header('Location: '.$loc);
-            exit;
-        }
-        else
-        {
-            $db->rollback();
-        }
-    }
+	            // If payment dispatching on more than one invoice, we keep on summary page, otherwise go on invoice card
+	            $invoiceid=0;
+	            foreach ($paiement->amounts as $key => $amount)
+	            {
+	                $facid = $key;
+	                if (is_numeric($amount) && $amount <> 0)
+	                {
+	                    if ($invoiceid != 0) $invoiceid=-1; // There is more than one invoice payed by this payment
+	                    else $invoiceid=$facid;
+	                }
+	            }
+	            if ($invoiceid > 0) $loc = DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$invoiceid;
+	            else $loc = DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$paiement_id;
+	            header('Location: '.$loc);
+	            exit;
+	        }
+	        else
+	        {
+	            $db->rollback();
+	        }
+	    }
+	}
 }
 
 
-
 /*
  * View
  */
@@ -458,7 +461,7 @@ if (empty($action))
     $search_paymenttype=GETPOST('search_paymenttype');
     $search_amount=GETPOST('search_amount');
     $search_company=GETPOST('search_company');
-	
+
 	if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers
 	{
 		$search_ref="";
@@ -596,7 +599,7 @@ if (empty($action))
             print '<td class="nowrap">';
             print $invoicesupplierstatic->getNomUrl(1);
             print '</td>';*/
-			
+
 			print '<td>&nbsp;</td>';
             print '</tr>';
             $i++;

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

@@ -1033,7 +1033,7 @@ SendingMailSetup=Setup of sendings by email
 SendmailOptionNotComplete=Warning, on some Linux systems, to send email from your email, sendmail execution setup must contains option -ba (parameter mail.force_extra_parameters into your php.ini file). If some recipients never receive emails, try to edit this PHP parameter with mail.force_extra_parameters = -ba).
 PathToDocuments=Path to documents
 PathDirectory=Directory
-SendmailOptionMayHurtBuggedMTA=Feature to send mails using method "PHP mail direct" will generate a mail message that might be not correctly parsed by some receiving mail servers. Result is that some mails can't be read by people hosted by thoose bugged platforms. It's case for some Internet providers (Ex: Orange in France). This is not a problem into Dolibarr nor into PHP but onto receiving mail server. You can however add option MAIN_FIX_FOR_BUGGED_MTA to 1 into setup - other to modify Dolibarr to avoid this. However, you may experience problem with other servers that respect strictly the SMTP standard. The other solution (recommanded) is to use the method "SMTP socket library" that has no disadvantages.
+SendmailOptionMayHurtBuggedMTA=Feature to send mails using method "PHP mail direct" will generate a mail message that might be not correctly parsed by some receiving mail servers. Result is that some mails can't be read by people hosted by those bugged platforms. It's case for some Internet providers (Ex: Orange in France). This is not a problem into Dolibarr nor into PHP but onto receiving mail server. You can however add option MAIN_FIX_FOR_BUGGED_MTA to 1 into setup - other to modify Dolibarr to avoid this. However, you may experience problem with other servers that respect strictly the SMTP standard. The other solution (recommended) is to use the method "SMTP socket library" that has no disadvantages.
 TranslationSetup=Configuration de la traduction
 TranslationDesc=Choice of language visible on screen can be modified:<br>* Globally from menu <strong>Home - Setup - Display</strong><br>* For user only from tab <strong>User display</strong> of user card (click on login on top of screen). 
 TotalNumberOfActivatedModules=Total number of activated feature modules: <b>%s</b>
@@ -1410,7 +1410,7 @@ AdvancedEditor=Advanced editor
 ActivateFCKeditor=Activate advanced editor for:
 FCKeditorForCompany=WYSIWIG creation/edition of elements description and note (except products/services)
 FCKeditorForProduct=WYSIWIG creation/edition of products/services description and note
-FCKeditorForProductDetails=WYSIWIG creation/edition of products details lines for all entities (proposals, orders, invoices, etc...). <font class="warning">Warning: Using this option for this case is seriously not recommanded as it can create problems with special characters and page formating when building PDF files.</font>
+FCKeditorForProductDetails=WYSIWIG creation/edition of products details lines for all entities (proposals, orders, invoices, etc...). <font class="warning">Warning: Using this option for this case is seriously not recommended as it can create problems with special characters and page formating when building PDF files.</font>
 FCKeditorForMailing= WYSIWIG creation/edition for mass eMailings (Tools->eMailing)
 FCKeditorForUserSignature=WYSIWIG creation/edition of user signature
 FCKeditorForMail=WYSIWIG creation/edition for all mail (except Outils->eMailing)

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

@@ -260,6 +260,7 @@ days=days
 Hours=Hours
 Minutes=Minutes
 Seconds=Seconds
+Weeks=Weeks
 Today=Today
 Yesterday=Yesterday
 Tomorrow=Tomorrow

+ 1 - 1
htdocs/main.inc.php

@@ -736,7 +736,7 @@ if ((! empty($conf->browser->layout) && $conf->browser->layout == 'phone')
 // If we force to use jmobile, then we reenable javascript
 if (! empty($conf->dol_use_jmobile)) $conf->use_javascript_ajax=1;
 // Replace themes bugged with jmobile with eldy
-if (! empty($conf->dol_use_jmobile) && in_array($conf->theme,array('bureau2crea','cameleo')))
+if (! empty($conf->dol_use_jmobile) && in_array($conf->theme,array('bureau2crea','cameleo','amarok')))
 {
 	$conf->theme='eldy';
 	$conf->css  =  "/theme/".$conf->theme."/style.css.php";

+ 12 - 1
htdocs/margin/index.php

@@ -1,5 +1,6 @@
 <?php
 /* Copyright (C) 2012	Christophe Battarel	<christophe.battarel@altairis.fr>
+ * Copyright (C) 2014   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
@@ -21,5 +22,15 @@
  *	\brief      Page d'index du module margin
  */
 
-require 'productMargins.php';
+require '../main.inc.php';
+
+if ($user->rights->produit->lire) {
+	$page = 'productMargins';
+} elseif ($user->rights->societe->lire) {
+	$page = 'customerMargins';
+} else {
+	$page = 'agentMargins';
+}
+
+header('Location: '.dol_buildpath('/margin/'.$page.'.php', 1));
 

+ 14 - 9
htdocs/margin/lib/margins.lib.php

@@ -1,5 +1,6 @@
 <?php
 /* Copyright (C) 2012	Christophe Battarel	<christophe.battarel@altairis.fr>
+ * Copyright (C) 2014   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
@@ -56,21 +57,25 @@ function marges_admin_prepare_head()
  */
 function marges_prepare_head()
 {
-	global $langs, $conf;
+	global $langs, $conf, $user;
 	$langs->load("marges@marges");
 
 	$h = 0;
 	$head = array();
 
-	$head[$h][0] = DOL_URL_ROOT."/margin/productMargins.php";
-	$head[$h][1] = $langs->trans("ProductMargins");
-	$head[$h][2] = 'productMargins';
-	$h++;
+	if ($user->rights->produit->lire) {
+		$head[$h][0] = DOL_URL_ROOT."/margin/productMargins.php";
+		$head[$h][1] = $langs->trans("ProductMargins");
+		$head[$h][2] = 'productMargins';
+		$h++;
+	}
 
-	$head[$h][0] = DOL_URL_ROOT."/margin/customerMargins.php";
-	$head[$h][1] = $langs->trans("CustomerMargins");
-	$head[$h][2] = 'customerMargins';
-	$h++;
+	if ($user->rights->societe->lire) {
+		$head[$h][0] = DOL_URL_ROOT."/margin/customerMargins.php";
+		$head[$h][1] = $langs->trans("CustomerMargins");
+		$head[$h][2] = 'customerMargins';
+		$h++;
+	}
 
 	$head[$h][0] = DOL_URL_ROOT."/margin/agentMargins.php";
 	$head[$h][1] = $langs->trans("SalesRepresentativeMargins");

+ 10 - 6
htdocs/product/document.php

@@ -73,16 +73,20 @@ if ($id > 0 || ! empty($ref))
 }
 $modulepart='produit';
 
-$parameters=array('id'=>$id);
-$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');
-
 
 /*
- * Action envoie fichier
+ * Actions
  */
 
-include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php';
+$parameters=array('id'=>$id);
+$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
+if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+
+if (empty($reshook))
+{
+	// Action sending file
+	include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_pre_headers.tpl.php';
+}
 
 
 /*

+ 100 - 99
htdocs/product/fournisseurs.php

@@ -78,125 +78,126 @@ $parameters=array('socid'=>$socid, 'id_prod'=>$id);
 $reshook=$hookmanager->executeHooks('doActions',$parameters,$product,$action);    // Note that $action and $object may have been modified by some hooks
 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
 
-if ($action == 'remove_pf')
-{
-	$product = new ProductFournisseur($db);
-	if ($product->fetch($id) > 0)
+if (empty($reshook)) {
+	if ($action == 'remove_pf')
 	{
-		if ($rowid)
+		$product = new ProductFournisseur($db);
+		if ($product->fetch($id) > 0)
 		{
-			$result=$product->remove_product_fournisseur_price($rowid);
-			$action = '';
-			setEventMessage($langs->trans("PriceRemoved"));
+			if ($rowid)
+			{
+				$result=$product->remove_product_fournisseur_price($rowid);
+				$action = '';
+				setEventMessage($langs->trans("PriceRemoved"));
+			}
 		}
 	}
-}
-
-if ($action == 'updateprice' && GETPOST('cancel') <> $langs->trans("Cancel"))
-{
-    $id_fourn=GETPOST("id_fourn");
-    if (empty($id_fourn)) $id_fourn=GETPOST("search_id_fourn");
-    $ref_fourn=GETPOST("ref_fourn");
-    if (empty($ref_fourn)) $ref_fourn=GETPOST("search_ref_fourn");
-    $quantity=GETPOST("qty");
-	$remise_percent=price2num(GETPOST('remise_percent','alpha'));
-    $npr = preg_match('/\*/', $_POST['tva_tx']) ? 1 : 0 ;
-    $tva_tx = str_replace('*','', GETPOST('tva_tx','alpha'));
-    $tva_tx = price2num($tva_tx);
-
-    if ($tva_tx == '')
-    {
-		$error++;
-	    setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("VATRateForSupplierProduct")), 'errors');
-    }
-	if (empty($quantity))
-	{
-		$error++;
-		setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Qty")), 'errors');
-	}
-	if (empty($ref_fourn))
-	{
-		$error++;
-		setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("RefSupplier")), 'errors');
-	}
-	if ($id_fourn <= 0)
-	{
-		$error++;
-		setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Supplier")), 'errors');
-	}
-	if ($_POST["price"] < 0 || $_POST["price"] == '')
-	{
-		$error++;
-		setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Price")), 'errors');
-	}
 
-	$product = new ProductFournisseur($db);
-	$result=$product->fetch($id);
-	if ($result <= 0)
+	if ($action == 'updateprice' && GETPOST('cancel') <> $langs->trans("Cancel"))
 	{
-	    $error++;
-		setEventMessage($product->error, 'errors');
-	}
+		$id_fourn=GETPOST("id_fourn");
+		if (empty($id_fourn)) $id_fourn=GETPOST("search_id_fourn");
+		$ref_fourn=GETPOST("ref_fourn");
+		if (empty($ref_fourn)) $ref_fourn=GETPOST("search_ref_fourn");
+		$quantity=GETPOST("qty");
+		$remise_percent=price2num(GETPOST('remise_percent','alpha'));
+		$npr = preg_match('/\*/', $_POST['tva_tx']) ? 1 : 0 ;
+		$tva_tx = str_replace('*','', GETPOST('tva_tx','alpha'));
+		$tva_tx = price2num($tva_tx);
+
+		if ($tva_tx == '')
+		{
+			$error++;
+			setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("VATRateForSupplierProduct")), 'errors');
+		}
+		if (empty($quantity))
+		{
+			$error++;
+			setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Qty")), 'errors');
+		}
+		if (empty($ref_fourn))
+		{
+			$error++;
+			setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("RefSupplier")), 'errors');
+		}
+		if ($id_fourn <= 0)
+		{
+			$error++;
+			setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Supplier")), 'errors');
+		}
+		if ($_POST["price"] < 0 || $_POST["price"] == '')
+		{
+			$error++;
+			setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Price")), 'errors');
+		}
 
-	if (! $error)
-    {
-    	$db->begin();
+		$product = new ProductFournisseur($db);
+		$result=$product->fetch($id);
+		if ($result <= 0)
+		{
+			$error++;
+			setEventMessage($product->error, 'errors');
+		}
 
 		if (! $error)
 		{
-			$ret=$product->add_fournisseur($user, $id_fourn, $ref_fourn, $quantity);    // This insert record with no value for price. Values are update later with update_buyprice
-			if ($ret == -3)
+			$db->begin();
+
+			if (! $error)
 			{
-				$error++;
+				$ret=$product->add_fournisseur($user, $id_fourn, $ref_fourn, $quantity);    // This insert record with no value for price. Values are update later with update_buyprice
+				if ($ret == -3)
+				{
+					$error++;
 
-				$product->fetch($product->product_id_already_linked);
-				$productLink = $product->getNomUrl(1,'supplier');
+					$product->fetch($product->product_id_already_linked);
+					$productLink = $product->getNomUrl(1,'supplier');
 
-				setEventMessage($langs->trans("ReferenceSupplierIsAlreadyAssociatedWithAProduct",$productLink), 'errors');
+					setEventMessage($langs->trans("ReferenceSupplierIsAlreadyAssociatedWithAProduct",$productLink), 'errors');
+				}
+				else if ($ret < 0)
+				{
+					$error++;
+					setEventMessage($product->error, 'errors');
+				}
 			}
-			else if ($ret < 0)
+
+			if (! $error)
 			{
-				$error++;
-				setEventMessage($product->error, 'errors');
-			}
-		}
+				$supplier=new Fournisseur($db);
+				$result=$supplier->fetch($id_fourn);
+				if (isset($_POST['ref_fourn_price_id']))
+					$product->fetch_product_fournisseur_price($_POST['ref_fourn_price_id']);
 
-		if (! $error)
-		{
-			$supplier=new Fournisseur($db);
-			$result=$supplier->fetch($id_fourn);
-			if (isset($_POST['ref_fourn_price_id']))
-				$product->fetch_product_fournisseur_price($_POST['ref_fourn_price_id']);
+				$ret=$product->update_buyprice($quantity, $_POST["price"], $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn, $tva_tx, $_POST["charges"], $remise_percent, $npr);
+				if ($ret < 0)
+				{
+					$error++;
+					setEventMessage($product->error, 'errors');
+				}
+			}
 
-			$ret=$product->update_buyprice($quantity, $_POST["price"], $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn, $tva_tx, $_POST["charges"], $remise_percent, $npr);
-			if ($ret < 0)
+			if (! $error)
 			{
-				$error++;
-				setEventMessage($product->error, 'errors');
+				$db->commit();
+				$action='';
+			}
+			else
+			{
+				$db->rollback();
 			}
 		}
+	}
 
-		if (! $error)
-		{
-			$db->commit();
-			$action='';
-		}
-		else
-		{
-			$db->rollback();
-		}
-    }
-}
-
-if (GETPOST('cancel') == $langs->trans("Cancel"))
-{
-	$action = '';
-	header("Location: fournisseurs.php?id=".$_GET["id"]);
-	exit;
+	if (GETPOST('cancel') == $langs->trans("Cancel"))
+	{
+		$action = '';
+		header("Location: fournisseurs.php?id=".$_GET["id"]);
+		exit;
+	}
 }
 
 
-
 /*
  * view
  */
@@ -393,7 +394,7 @@ if ($id || $ref)
 						print '</tr>';
 					}
 				}
-				
+
 				if (is_object($hookmanager))
 				{
 					$parameters=array('id_fourn'=>$id_fourn,'prod_id'=>$product->id);
@@ -503,7 +504,7 @@ if ($id || $ref)
 
 						// Charges ????
 						if ($conf->global->PRODUCT_CHARGES)
-						{	
+						{
 							if (! empty($conf->margin->enabled))
 							{
 								print '<td align="right">';
@@ -511,7 +512,7 @@ if ($id || $ref)
 								print '</td>';
 							}
 						}
-						
+
 						// Unit price
 						print '<td align="right">';
 						print price($productfourn->fourn_unitprice);
@@ -533,7 +534,7 @@ if ($id || $ref)
 								print '</td>';
 							}
 						}
-						
+
 						if (is_object($hookmanager))
 						{
 							$parameters=array('id_pfp'=>$productfourn->product_fourn_price_id,'id_fourn'=>$id_fourn,'prod_id'=>$product->id);

+ 2 - 2
htdocs/projet/element.php

@@ -145,12 +145,12 @@ print '<tr><td>'.$langs->trans("Status").'</td><td>'.$project->getLibStatut(4).'
 
 // Date start
 print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
-print dol_print_date($object->date_start,'day');
+print dol_print_date($project->date_start,'day');
 print '</td></tr>';
 
 // Date end
 print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
-print dol_print_date($object->date_end,'day');
+print dol_print_date($project->date_end,'day');
 print '</td></tr>';
 
 print '</table>';

+ 31 - 32
htdocs/resource/card.php

@@ -62,58 +62,57 @@ $parameters=array('resource_id'=>$id);
 $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');
 
-
-/*******************************************************************
-* ACTIONS
-*
-* Put here all code to do according to value of "action" parameter
-********************************************************************/
-
-if ($action == 'update' && ! $_POST["cancel"]  && $user->rights->resource->write )
+if (empty($reshook))
 {
-	$error=0;
+	/*******************************************************************
+	* ACTIONS
+	********************************************************************/
 
-	if (empty($ref))
+	if ($action == 'update' && ! $_POST["cancel"]  && $user->rights->resource->write )
 	{
-		$error++;
-		$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")).'</div>';
-	}
+		$error=0;
 
-	if (! $error)
-	{
-		$res = $object->fetch($id);
-		if ( $res > 0 )
+		if (empty($ref))
 		{
-			$object->ref          			= $ref;
-			$object->description  			= $description;
-			$object->fk_code_type_resource  = $fk_code_type_resource;
+			$error++;
+			setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")), 'errors');
+		}
 
-			$result=$object->update($user);
-			if ($result > 0)
+		if (! $error)
+		{
+			$res = $object->fetch($id);
+			if ( $res > 0 )
 			{
-				Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
-				exit;
+				$object->ref          			= $ref;
+				$object->description  			= $description;
+				$object->fk_code_type_resource  = $fk_code_type_resource;
+
+				$result=$object->update($user);
+				if ($result > 0)
+				{
+					Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
+					exit;
+				}
+				else
+				{
+					setEventMessage($object->error, 'errors');
+					$action='edit';
+				}
+
 			}
 			else
 			{
-				setEventMessage('<div class="error">'.$object->error.'</div>');
+				setEventMessage($object->error,'errors');
 				$action='edit';
 			}
-
 		}
 		else
 		{
-			setEventMessage($object->error,'errors');
 			$action='edit';
 		}
 	}
-	else
-	{
-		$action='edit';
-	}
 }
 
-
 /***************************************************
 * VIEW
 *

部分文件因为文件数量过多而无法显示