Browse Source

code syntax contact directory

Frédéric FRANCE 4 years ago
parent
commit
3b6d01ffae

+ 70 - 58
htdocs/contact/agenda.php

@@ -65,36 +65,44 @@ $extrafields->fetch_name_optionals_label($object->table_element);
 $object->getCanvas($id);
 $objcanvas = null;
 $canvas = (!empty($object->canvas) ? $object->canvas : GETPOST("canvas"));
-if (!empty($canvas))
-{
+if (!empty($canvas)) {
 	require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
 	$objcanvas = new Canvas($db, $action);
 	$objcanvas->getCanvas('contact', 'contactcard', $canvas);
 }
 
-if (GETPOST('actioncode', 'array'))
-{
+if (GETPOST('actioncode', 'array')) {
 	$actioncode = GETPOST('actioncode', 'array', 3);
-	if (!count($actioncode)) $actioncode = '0';
+	if (!count($actioncode)) {
+		$actioncode = '0';
+	}
 } else {
 	$actioncode = GETPOST("actioncode", "alpha", 3) ?GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT));
 }
 $search_agenda_label = GETPOST('search_agenda_label');
 
 // Security check
-if ($user->socid) $socid = $user->socid;
+if ($user->socid) {
+	$socid = $user->socid;
+}
 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe', '', '', 'rowid', 0); // If we create a contact with no company (shared contacts), no check on write permission
 
 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
 $sortfield = GETPOST("sortfield", 'alpha');
 $sortorder = GETPOST("sortorder", 'alpha');
 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
-if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
+if (empty($page) || $page == -1) {
+	$page = 0;
+}     // If $page is not defined, or '' or -1
 $offset = $limit * $page;
 $pageprev = $page - 1;
 $pagenext = $page + 1;
-if (!$sortfield) $sortfield = 'a.datep, a.id';
-if (!$sortorder) $sortorder = 'DESC';
+if (!$sortfield) {
+	$sortfield = 'a.datep, a.id';
+}
+if (!$sortorder) {
+	$sortorder = 'DESC';
+}
 
 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
 $hookmanager->initHooks(array('contactagenda', 'globalcard'));
@@ -106,20 +114,19 @@ $hookmanager->initHooks(array('contactagenda', 'globalcard'));
 
 $parameters = array('id'=>$id, '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 ($reshook < 0) {
+	setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+}
 
-if (empty($reshook))
-{
+if (empty($reshook)) {
 	// Cancel
-	if (GETPOST('cancel', 'alpha') && !empty($backtopage))
-	{
+	if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
 		header("Location: ".$backtopage);
 		exit;
 	}
 
 	// Purge search criteria
-	if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All test are required to be compatible with all browsers
-	{
+	if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers
 		$actioncode = '';
 		$search_agenda_label = '';
 	}
@@ -133,29 +140,30 @@ if (empty($reshook))
 $form = new Form($db);
 
 $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
-if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->lastname) $title = $object->lastname;
+if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->lastname) {
+	$title = $object->lastname;
+}
 $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
 llxHeader('', $title, $help_url);
 
 
-if ($socid > 0)
-{
+if ($socid > 0) {
 	$objsoc = new Societe($db);
 	$objsoc->fetch($socid);
 }
 
-if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
-{
+if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
 	// -----------------------------------------
 	// When used with CANVAS
 	// -----------------------------------------
-	if (empty($object->error) && $id)
- 	{
- 		$object = new Contact($db);
- 		$result = $object->fetch($id);
-		if ($result <= 0) dol_print_error('', $object->error);
- 	}
-   	$objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
+	if (empty($object->error) && $id) {
+		$object = new Contact($db);
+		$result = $object->fetch($id);
+		if ($result <= 0) {
+			dol_print_error('', $object->error);
+		}
+	}
+	$objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
 	$objcanvas->display_canvas($action); // Show template
 } else {
 	// -----------------------------------------
@@ -163,26 +171,27 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
 	// -----------------------------------------
 
 	// Confirm deleting contact
-	if ($user->rights->societe->contact->supprimer)
-	{
-		if ($action == 'delete')
-		{
+	if ($user->rights->societe->contact->supprimer) {
+		if ($action == 'delete') {
 			print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id.($backtopage ? '&backtopage='.$backtopage : ''), $langs->trans("DeleteContact"), $langs->trans("ConfirmDeleteContact"), "confirm_delete", '', 0, 1);
 		}
 	}
 
 	/*
-     * Onglets
-     */
+	 * Onglets
+	 */
 	$head = array();
-	if ($id > 0)
-	{
+	if ($id > 0) {
 		// Si edition contact deja existant
 		$object = new Contact($db);
 		$res = $object->fetch($id, $user);
-		if ($res < 0) { dol_print_error($db, $object->error); exit; }
+		if ($res < 0) {
+			dol_print_error($db, $object->error); exit;
+		}
 		$res = $object->fetch_optionals();
-		if ($res < 0) { dol_print_error($db, $object->error); exit; }
+		if ($res < 0) {
+			dol_print_error($db, $object->error); exit;
+		}
 
 		// Show tabs
 		$head = contact_prepare_head($object);
@@ -190,13 +199,12 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
 		$title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
 	}
 
-	if (!empty($id) && $action != 'edit' && $action != 'create')
-	{
+	if (!empty($id) && $action != 'edit' && $action != 'create') {
 		$objsoc = new Societe($db);
 
 		/*
-         * Fiche en mode visualisation
-         */
+		 * Fiche en mode visualisation
+		 */
 
 		dol_htmloutput_errors($error, $errors);
 
@@ -205,14 +213,16 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
 		$linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
 
 		$morehtmlref = '<div class="refidno">';
-		if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
-		{
+		if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
 			$objsoc = new Societe($db);
 			$objsoc->fetch($object->socid);
 			// Thirdparty
 			$morehtmlref .= $langs->trans('ThirdParty').' : ';
-			if ($objsoc->id > 0) $morehtmlref .= $objsoc->getNomUrl(1);
-			else $morehtmlref .= $langs->trans("ContactNotLinkedToCompany");
+			if ($objsoc->id > 0) {
+				$morehtmlref .= $objsoc->getNomUrl(1);
+			} else {
+				$morehtmlref .= $langs->trans("ContactNotLinkedToCompany");
+			}
 		}
 		$morehtmlref .= '</div>';
 
@@ -238,29 +248,31 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
 
 		$out = '';
 		$permok = $user->rights->agenda->myactions->create;
-		if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok)
-		{
-			if (is_object($objthirdparty) && get_class($objthirdparty) == 'Societe') $out .= '&amp;originid='.$objthirdparty->id.($objthirdparty->id > 0 ? '&amp;socid='.$objthirdparty->id : '');
+		if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
+			if (is_object($objthirdparty) && get_class($objthirdparty) == 'Societe') {
+				$out .= '&amp;originid='.$objthirdparty->id.($objthirdparty->id > 0 ? '&amp;socid='.$objthirdparty->id : '');
+			}
 			$out .= (!empty($objcon->id) ? '&amp;contactid='.$objcon->id : '').'&amp;origin=contact&amp;originid='.$object->id.'&amp;percentage=-1&amp;backtopage='.urlencode($_SERVER['PHP_SELF'].($objcon->id > 0 ? '?id='.$objcon->id : ''));
 			$out .= '&amp;datep='.urlencode(dol_print_date(dol_now(), 'dayhourlog'));
 		}
 
 		$newcardbutton = '';
-		if (!empty($conf->agenda->enabled))
-		{
-			if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create))
-			{
+		if (!empty($conf->agenda->enabled)) {
+			if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create)) {
 				$newcardbutton .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out);
 			}
 		}
 
-		if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read)))
-	   	{
-	   		print '<br>';
+		if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
+			print '<br>';
 
 			$param = '&id='.$id;
-			if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage;
-			if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit;
+			if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
+				$param .= '&contextpage='.$contextpage;
+			}
+			if ($limit > 0 && $limit != $conf->liste_limit) {
+				$param .= '&limit='.$limit;
+			}
 
 			print load_fiche_titre($langs->trans("ActionsOnContact"), $newcardbutton, '');
 			//print_barre_liste($langs->trans("ActionsOnCompany"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $morehtmlcenter, 0, -1, '', '', '', '', 0, 1, 1);

+ 62 - 54
htdocs/contact/canvas/actions_contactcard_common.class.php

@@ -64,14 +64,16 @@ abstract class ActionsContactCardCommon
 	{
 		/*$ret = $this->getInstanceDao();
 
-    	if (is_object($this->object) && method_exists($this->object,'fetch'))
-    	{
-    		if (! empty($id)) $this->object->fetch($id);
-    	}
-    	else
-    	{*/
+		if (is_object($this->object) && method_exists($this->object,'fetch'))
+		{
+			if (! empty($id)) $this->object->fetch($id);
+		}
+		else
+		{*/
 			$object = new Contact($this->db);
-			if (!empty($id)) $object->fetch($id);
+		if (!empty($id)) {
+			$object->fetch($id);
+		}
 			$this->object = $object;
 		//}
 	}
@@ -90,20 +92,19 @@ abstract class ActionsContactCardCommon
 		global $conf, $langs, $user, $canvas;
 		global $form, $formcompany, $objsoc;
 
-		if ($action == 'add' || $action == 'update') $this->assign_post();
+		if ($action == 'add' || $action == 'update') {
+			$this->assign_post();
+		}
 
-		foreach ($this->object as $key => $value)
-		{
+		foreach ($this->object as $key => $value) {
 			$this->tpl[$key] = $value;
 		}
 
 		$this->tpl['error'] = $this->error;
 		$this->tpl['errors'] = $this->errors;
 
-		if ($action == 'create' || $action == 'edit')
-		{
-			if ($conf->use_javascript_ajax)
-			{
+		if ($action == 'create' || $action == 'edit') {
+			if ($conf->use_javascript_ajax) {
 				$this->tpl['ajax_selectcountry'] = "\n".'<script type="text/javascript" language="javascript">
 				jQuery(document).ready(function () {
 						jQuery("#selectcountry_id").change(function() {
@@ -115,8 +116,7 @@ abstract class ActionsContactCardCommon
 				</script>'."\n";
 			}
 
-			if (is_object($objsoc) && $objsoc->id > 0)
-			{
+			if (is_object($objsoc) && $objsoc->id > 0) {
 				$this->tpl['company'] = $objsoc->getNomUrl(1);
 				$this->tpl['company_id'] = $objsoc->id;
 			} else {
@@ -127,14 +127,25 @@ abstract class ActionsContactCardCommon
 			$this->tpl['select_civility'] = $formcompany->select_civility($this->object->civility_id);
 
 			// Predefined with third party
-			if ((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS))
-			{
-				if (dol_strlen(trim($this->object->address)) == 0) $this->tpl['address'] = $objsoc->address;
-				if (dol_strlen(trim($this->object->zip)) == 0) $this->object->zip = $objsoc->zip;
-				if (dol_strlen(trim($this->object->town)) == 0) $this->object->town = $objsoc->town;
-				if (dol_strlen(trim($this->object->phone_pro)) == 0) $this->object->phone_pro = $objsoc->phone;
-				if (dol_strlen(trim($this->object->fax)) == 0) $this->object->fax = $objsoc->fax;
-				if (dol_strlen(trim($this->object->email)) == 0) $this->object->email = $objsoc->email;
+			if ((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) {
+				if (dol_strlen(trim($this->object->address)) == 0) {
+					$this->tpl['address'] = $objsoc->address;
+				}
+				if (dol_strlen(trim($this->object->zip)) == 0) {
+					$this->object->zip = $objsoc->zip;
+				}
+				if (dol_strlen(trim($this->object->town)) == 0) {
+					$this->object->town = $objsoc->town;
+				}
+				if (dol_strlen(trim($this->object->phone_pro)) == 0) {
+					$this->object->phone_pro = $objsoc->phone;
+				}
+				if (dol_strlen(trim($this->object->fax)) == 0) {
+					$this->object->fax = $objsoc->fax;
+				}
+				if (dol_strlen(trim($this->object->email)) == 0) {
+					$this->object->email = $objsoc->email;
+				}
 			}
 
 			// Zip
@@ -143,28 +154,33 @@ abstract class ActionsContactCardCommon
 			// Town
 			$this->tpl['select_town'] = $formcompany->select_ziptown($this->object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
 
-			if (dol_strlen(trim($this->object->country_id)) == 0) $this->object->country_id = $objsoc->country_id;
+			if (dol_strlen(trim($this->object->country_id)) == 0) {
+				$this->object->country_id = $objsoc->country_id;
+			}
 
 			// Country
 			$this->tpl['select_country'] = $form->select_country($this->object->country_id, 'country_id');
 			$countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
 
-			if ($user->admin) $this->tpl['info_admin'] = info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
+			if ($user->admin) {
+				$this->tpl['info_admin'] = info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
+			}
 
 			// State
-			if ($this->object->country_id) $this->tpl['select_state'] = $formcompany->select_state($this->object->state_id, $this->object->country_code);
-			else $this->tpl['select_state'] = $countrynotdefined;
+			if ($this->object->country_id) {
+				$this->tpl['select_state'] = $formcompany->select_state($this->object->state_id, $this->object->country_code);
+			} else {
+				$this->tpl['select_state'] = $countrynotdefined;
+			}
 
 			// Public or private
 			$selectarray = array('0'=>$langs->trans("ContactPublic"), '1'=>$langs->trans("ContactPrivate"));
 			$this->tpl['select_visibility'] = $form->selectarray('priv', $selectarray, $this->object->priv, 0);
 		}
 
-		if ($action == 'view' || $action == 'edit' || $action == 'delete')
-		{
+		if ($action == 'view' || $action == 'edit' || $action == 'delete') {
 			// Emailing
-			if (!empty($conf->mailing->enabled))
-			{
+			if (!empty($conf->mailing->enabled)) {
 				$langs->load("mails");
 				$this->tpl['nb_emailing'] = $this->object->getNbOfEMailings();
 			}
@@ -175,46 +191,41 @@ abstract class ActionsContactCardCommon
 
 			$this->object->load_ref_elements();
 
-			if (!empty($conf->commande->enabled))
-			{
+			if (!empty($conf->commande->enabled)) {
 				$this->tpl['contact_element'][$i]['linked_element_label'] = $langs->trans("ContactForOrders");
 				$this->tpl['contact_element'][$i]['linked_element_value'] = $this->object->ref_commande ? $this->object->ref_commande : $langs->trans("NoContactForAnyOrder");
 				$i++;
 			}
-			if (!empty($conf->propal->enabled))
-			{
+			if (!empty($conf->propal->enabled)) {
 				$this->tpl['contact_element'][$i]['linked_element_label'] = $langs->trans("ContactForProposals");
 				$this->tpl['contact_element'][$i]['linked_element_value'] = $this->object->ref_propal ? $this->object->ref_propal : $langs->trans("NoContactForAnyProposal");
 				$i++;
 			}
-			if (!empty($conf->contrat->enabled))
-			{
+			if (!empty($conf->contrat->enabled)) {
 				$this->tpl['contact_element'][$i]['linked_element_label'] = $langs->trans("ContactForContracts");
 				$this->tpl['contact_element'][$i]['linked_element_value'] = $this->object->ref_contrat ? $this->object->ref_contrat : $langs->trans("NoContactForAnyContract");
 				$i++;
 			}
-			if (!empty($conf->facture->enabled))
-			{
+			if (!empty($conf->facture->enabled)) {
 				$this->tpl['contact_element'][$i]['linked_element_label'] = $langs->trans("ContactForInvoices");
 				$this->tpl['contact_element'][$i]['linked_element_value'] = $this->object->ref_facturation ? $this->object->ref_facturation : $langs->trans("NoContactForAnyInvoice");
 				$i++;
 			}
 
 			// Dolibarr user
-			if ($this->object->user_id)
-			{
+			if ($this->object->user_id) {
 				$dolibarr_user = new User($this->db);
 				$result = $dolibarr_user->fetch($this->object->user_id);
 				$this->tpl['dolibarr_user'] = $dolibarr_user->getLoginUrl(1);
-			} else $this->tpl['dolibarr_user'] = $langs->trans("NoDolibarrAccess");
+			} else {
+				$this->tpl['dolibarr_user'] = $langs->trans("NoDolibarrAccess");
+			}
 		}
 
-		if ($action == 'view' || $action == 'delete')
-		{
+		if ($action == 'view' || $action == 'delete') {
 			$this->tpl['showrefnav'] = $form->showrefnav($this->object, 'id');
 
-			if ($this->object->socid > 0)
-			{
+			if ($this->object->socid > 0) {
 				$objsoc = new Societe($this->db);
 
 				$objsoc->fetch($this->object->socid);
@@ -243,14 +254,13 @@ abstract class ActionsContactCardCommon
 			$this->tpl['note'] = nl2br($this->object->note);
 		}
 
-		if ($action == 'create_user')
-		{
+		if ($action == 'create_user') {
 			// Full firstname and lastname separated with a dot : firstname.lastname
 			include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
 			require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
 			$login = dol_buildlogin($this->object->lastname, $this->object->firstname);
 
-	   		$generated_password = getRandomPassword(false);
+			$generated_password = getRandomPassword(false);
 			$password = $generated_password;
 
 			// Create a form array
@@ -297,12 +307,10 @@ abstract class ActionsContactCardCommon
 		$this->object->canvas = $_POST["canvas"];
 
 		// We set country_id, and country_code label of the chosen country
-		if ($this->object->country_id)
-		{
+		if ($this->object->country_id) {
 			$sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_country WHERE rowid = ".$this->object->country_id;
 			$resql = $this->db->query($sql);
-			if ($resql)
-			{
+			if ($resql) {
 				$obj = $this->db->fetch_object($resql);
 			} else {
 				dol_print_error($this->db);

+ 1 - 2
htdocs/contact/canvas/default/tpl/contactcard_create.tpl.php

@@ -16,8 +16,7 @@
  */
 
 // Protection to avoid direct call of template
-if (empty($conf) || !is_object($conf))
-{
+if (empty($conf) || !is_object($conf)) {
 	print "Error, template page can't be called as URL";
 	exit;
 }

+ 1 - 2
htdocs/contact/canvas/default/tpl/contactcard_edit.tpl.php

@@ -16,8 +16,7 @@
  */
 
 // Protection to avoid direct call of template
-if (empty($conf) || !is_object($conf))
-{
+if (empty($conf) || !is_object($conf)) {
 	print "Error, template page can't be called as URL";
 	exit;
 }

+ 7 - 4
htdocs/contact/canvas/default/tpl/contactcard_view.tpl.php

@@ -16,8 +16,7 @@
  */
 
 // Protection to avoid direct call of template
-if (empty($conf) || !is_object($conf))
-{
+if (empty($conf) || !is_object($conf)) {
 	print "Error, template page can't be called as URL";
 	exit;
 }
@@ -30,8 +29,12 @@ echo $this->control->tpl['showhead'];
 
 dol_htmloutput_errors($this->control->tpl['error'], $this->control->tpl['errors']);
 
-if (!empty($this->control->tpl['action_create_user'])) echo $this->control->tpl['action_create_user'];
-if (!empty($this->control->tpl['action_delete'])) echo $this->control->tpl['action_delete']; ?>
+if (!empty($this->control->tpl['action_create_user'])) {
+	echo $this->control->tpl['action_create_user'];
+}
+if (!empty($this->control->tpl['action_delete'])) {
+	echo $this->control->tpl['action_delete'];
+} ?>
 
 <table class="border allwidth">
 

File diff suppressed because it is too large
+ 211 - 225
htdocs/contact/card.php


+ 272 - 220
htdocs/contact/class/contact.class.php

@@ -473,40 +473,35 @@ class Contact extends CommonObject
 
 		dol_syslog(get_class($this)."::create", LOG_DEBUG);
 		$resql = $this->db->query($sql);
-		if ($resql)
-		{
+		if ($resql) {
 			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."socpeople");
 
-			if (!$error)
-			{
+			if (!$error) {
 				$result = $this->update($this->id, $user, 1, 'add'); // This include updateRoles(), ...
-				if ($result < 0)
-				{
+				if ($result < 0) {
 					$error++;
 					$this->error = $this->db->lasterror();
 				}
 			}
 
-			if (!$error)
-			{
+			if (!$error) {
 				$result = $this->update_perso($this->id, $user, 1); // TODO Remove function update_perso, should be same than update
-				if ($result < 0)
-				{
+				if ($result < 0) {
 					$error++;
 					$this->error = $this->db->lasterror();
 				}
 			}
 
-			if (!$error)
-			{
+			if (!$error) {
 				// Call trigger
 				$result = $this->call_trigger('CONTACT_CREATE', $user);
-				if ($result < 0) { $error++; }
+				if ($result < 0) {
+					$error++;
+				}
 				// End call triggers
 			}
 
-			if (!$error)
-			{
+			if (!$error) {
 				$this->db->commit();
 				return $this->id;
 			} else {
@@ -558,13 +553,20 @@ class Contact extends CommonObject
 		$this->town = (empty($this->town) ? '' : trim($this->town));
 		$this->setUpperOrLowerCase();
 		$this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
-		if (empty($this->statut)) $this->statut = 0;
-		if (empty($this->civility_code) && !is_numeric($this->civility_id)) $this->civility_code = $this->civility_id; // For backward compatibility
+		if (empty($this->statut)) {
+			$this->statut = 0;
+		}
+		if (empty($this->civility_code) && !is_numeric($this->civility_id)) {
+			$this->civility_code = $this->civility_id; // For backward compatibility
+		}
 		$this->db->begin();
 
 		$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET ";
-		if ($this->socid > 0) $sql .= " fk_soc='".$this->db->escape($this->socid)."',";
-		elseif ($this->socid == -1) $sql .= " fk_soc=null,";
+		if ($this->socid > 0) {
+			$sql .= " fk_soc='".$this->db->escape($this->socid)."',";
+		} elseif ($this->socid == -1) {
+			$sql .= " fk_soc=null,";
+		}
 		$sql .= "  civility='".$this->db->escape($this->civility_code)."'";
 		$sql .= ", lastname='".$this->db->escape($this->lastname)."'";
 		$sql .= ", firstname='".$this->db->escape($this->firstname)."'";
@@ -586,8 +588,7 @@ class Contact extends CommonObject
 		$sql .= ", phone_mobile = ".(isset($this->phone_mobile) ? "'".$this->db->escape($this->phone_mobile)."'" : "null");
 		$sql .= ", priv = '".$this->db->escape($this->priv)."'";
 		$sql .= ", fk_prospectcontactlevel = '".$this->db->escape($this->fk_prospectlevel)."'";
-		if (isset($this->stcomm_id))
-		{
+		if (isset($this->stcomm_id)) {
 			$sql .= ", fk_stcommcontact = ".($this->stcomm_id > 0 || $this->stcomm_id == -1 ? $this->stcomm_id : "0");
 		}
 		$sql .= ", statut = ".$this->db->escape($this->statut);
@@ -598,8 +599,7 @@ class Contact extends CommonObject
 
 		dol_syslog(get_class($this)."::update", LOG_DEBUG);
 		$result = $this->db->query($sql);
-		if ($result)
-		{
+		if ($result) {
 			unset($this->country_code);
 			unset($this->country);
 			unset($this->state_code);
@@ -608,25 +608,21 @@ class Contact extends CommonObject
 			$action = 'update';
 
 			// Actions on extra fields
-			if (!$error)
-			{
+			if (!$error) {
 				$result = $this->insertExtraFields();
-				if ($result < 0)
-				{
+				if ($result < 0) {
 					$error++;
 				}
 			}
 
 			if (!$error) {
 				$result = $this->updateRoles();
-				if ($result < 0)
-				{
+				if ($result < 0) {
 					$error++;
 				}
 			}
 
-			if (!$error && $this->user_id > 0)
-			{
+			if (!$error && $this->user_id > 0) {
 				// If contact is linked to a user
 				$tmpobj = new User($this->db);
 				$tmpobj->fetch($this->user_id);
@@ -685,14 +681,18 @@ class Contact extends CommonObject
 				// }
 				if ($usermustbemodified) {
 					$result = $tmpobj->update($user, 0, 1, 1, 1);
-					if ($result < 0) { $error++; }
+					if ($result < 0) {
+						$error++;
+					}
 				}
 			}
 
 			if (!$error && !$notrigger) {
 				// Call trigger
 				$result = $this->call_trigger('CONTACT_MODIFY', $user);
-				if ($result < 0) { $error++; }
+				if ($result < 0) {
+					$error++;
+				}
 				// End call triggers
 			}
 
@@ -759,34 +759,69 @@ class Contact extends CommonObject
 		$this->fullname = $this->getFullName($langs);
 
 		// Fields
-		if ($this->fullname && !empty($conf->global->LDAP_CONTACT_FIELD_FULLNAME)) $info[$conf->global->LDAP_CONTACT_FIELD_FULLNAME] = $this->fullname;
-		if ($this->lastname && !empty($conf->global->LDAP_CONTACT_FIELD_NAME)) $info[$conf->global->LDAP_CONTACT_FIELD_NAME] = $this->lastname;
-		if ($this->firstname && !empty($conf->global->LDAP_CONTACT_FIELD_FIRSTNAME)) $info[$conf->global->LDAP_CONTACT_FIELD_FIRSTNAME] = $this->firstname;
+		if ($this->fullname && !empty($conf->global->LDAP_CONTACT_FIELD_FULLNAME)) {
+			$info[$conf->global->LDAP_CONTACT_FIELD_FULLNAME] = $this->fullname;
+		}
+		if ($this->lastname && !empty($conf->global->LDAP_CONTACT_FIELD_NAME)) {
+			$info[$conf->global->LDAP_CONTACT_FIELD_NAME] = $this->lastname;
+		}
+		if ($this->firstname && !empty($conf->global->LDAP_CONTACT_FIELD_FIRSTNAME)) {
+			$info[$conf->global->LDAP_CONTACT_FIELD_FIRSTNAME] = $this->firstname;
+		}
 
-		if ($this->poste) $info["title"] = $this->poste;
+		if ($this->poste) {
+			$info["title"] = $this->poste;
+		}
 		if ($this->socid > 0) {
 			$soc = new Societe($this->db);
 			$soc->fetch($this->socid);
 
 			$info[$conf->global->LDAP_CONTACT_FIELD_COMPANY] = $soc->name;
-			if ($soc->client == 1)      $info["businessCategory"] = "Customers";
-			if ($soc->client == 2)      $info["businessCategory"] = "Prospects";
-			if ($soc->fournisseur == 1) $info["businessCategory"] = "Suppliers";
-		}
-		if ($this->address && !empty($conf->global->LDAP_CONTACT_FIELD_ADDRESS)) $info[$conf->global->LDAP_CONTACT_FIELD_ADDRESS] = $this->address;
-		if ($this->zip && !empty($conf->global->LDAP_CONTACT_FIELD_ZIP))          $info[$conf->global->LDAP_CONTACT_FIELD_ZIP] = $this->zip;
-		if ($this->town && !empty($conf->global->LDAP_CONTACT_FIELD_TOWN))      $info[$conf->global->LDAP_CONTACT_FIELD_TOWN] = $this->town;
-		if ($this->country_code && !empty($conf->global->LDAP_CONTACT_FIELD_COUNTRY))      $info[$conf->global->LDAP_CONTACT_FIELD_COUNTRY] = $this->country_code;
-		if ($this->phone_pro && !empty($conf->global->LDAP_CONTACT_FIELD_PHONE)) $info[$conf->global->LDAP_CONTACT_FIELD_PHONE] = $this->phone_pro;
-		if ($this->phone_perso && !empty($conf->global->LDAP_CONTACT_FIELD_HOMEPHONE)) $info[$conf->global->LDAP_CONTACT_FIELD_HOMEPHONE] = $this->phone_perso;
-		if ($this->phone_mobile && !empty($conf->global->LDAP_CONTACT_FIELD_MOBILE)) $info[$conf->global->LDAP_CONTACT_FIELD_MOBILE] = $this->phone_mobile;
-		if ($this->fax && !empty($conf->global->LDAP_CONTACT_FIELD_FAX))	    $info[$conf->global->LDAP_CONTACT_FIELD_FAX] = $this->fax;
-		if ($this->skype && !empty($conf->global->LDAP_CONTACT_FIELD_SKYPE))	    $info[$conf->global->LDAP_CONTACT_FIELD_SKYPE] = $this->skype;
-		if ($this->note_private && !empty($conf->global->LDAP_CONTACT_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_CONTACT_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_private, 2);
-		if ($this->email && !empty($conf->global->LDAP_CONTACT_FIELD_MAIL))     $info[$conf->global->LDAP_CONTACT_FIELD_MAIL] = $this->email;
-
-		if ($conf->global->LDAP_SERVER_TYPE == 'egroupware')
-		{
+			if ($soc->client == 1) {
+				$info["businessCategory"] = "Customers";
+			}
+			if ($soc->client == 2) {
+				$info["businessCategory"] = "Prospects";
+			}
+			if ($soc->fournisseur == 1) {
+				$info["businessCategory"] = "Suppliers";
+			}
+		}
+		if ($this->address && !empty($conf->global->LDAP_CONTACT_FIELD_ADDRESS)) {
+			$info[$conf->global->LDAP_CONTACT_FIELD_ADDRESS] = $this->address;
+		}
+		if ($this->zip && !empty($conf->global->LDAP_CONTACT_FIELD_ZIP)) {
+			$info[$conf->global->LDAP_CONTACT_FIELD_ZIP] = $this->zip;
+		}
+		if ($this->town && !empty($conf->global->LDAP_CONTACT_FIELD_TOWN)) {
+			$info[$conf->global->LDAP_CONTACT_FIELD_TOWN] = $this->town;
+		}
+		if ($this->country_code && !empty($conf->global->LDAP_CONTACT_FIELD_COUNTRY)) {
+			$info[$conf->global->LDAP_CONTACT_FIELD_COUNTRY] = $this->country_code;
+		}
+		if ($this->phone_pro && !empty($conf->global->LDAP_CONTACT_FIELD_PHONE)) {
+			$info[$conf->global->LDAP_CONTACT_FIELD_PHONE] = $this->phone_pro;
+		}
+		if ($this->phone_perso && !empty($conf->global->LDAP_CONTACT_FIELD_HOMEPHONE)) {
+			$info[$conf->global->LDAP_CONTACT_FIELD_HOMEPHONE] = $this->phone_perso;
+		}
+		if ($this->phone_mobile && !empty($conf->global->LDAP_CONTACT_FIELD_MOBILE)) {
+			$info[$conf->global->LDAP_CONTACT_FIELD_MOBILE] = $this->phone_mobile;
+		}
+		if ($this->fax && !empty($conf->global->LDAP_CONTACT_FIELD_FAX)) {
+			$info[$conf->global->LDAP_CONTACT_FIELD_FAX] = $this->fax;
+		}
+		if ($this->skype && !empty($conf->global->LDAP_CONTACT_FIELD_SKYPE)) {
+			$info[$conf->global->LDAP_CONTACT_FIELD_SKYPE] = $this->skype;
+		}
+		if ($this->note_private && !empty($conf->global->LDAP_CONTACT_FIELD_DESCRIPTION)) {
+			$info[$conf->global->LDAP_CONTACT_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_private, 2);
+		}
+		if ($this->email && !empty($conf->global->LDAP_CONTACT_FIELD_MAIL)) {
+			$info[$conf->global->LDAP_CONTACT_FIELD_MAIL] = $this->email;
+		}
+
+		if ($conf->global->LDAP_SERVER_TYPE == 'egroupware') {
 			$info["objectclass"][4] = "phpgwContact"; // compatibilite egroupware
 
 			$info['uidnumber'] = $this->id;
@@ -805,8 +840,12 @@ class Contact extends CommonObject
 
 			$info["phpgwContactOwner"] = $this->egroupware_id;
 
-			if ($this->email) $info["rfc822Mailbox"] = $this->email;
-			if ($this->phone_mobile) $info["phpgwCellTelephoneNumber"] = $this->phone_mobile;
+			if ($this->email) {
+				$info["rfc822Mailbox"] = $this->email;
+			}
+			if ($this->phone_mobile) {
+				$info["phpgwCellTelephoneNumber"] = $this->phone_mobile;
+			}
 		}
 
 		return $info;
@@ -834,13 +873,14 @@ class Contact extends CommonObject
 		$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET";
 		$sql .= " birthday=".($this->birthday ? "'".$this->db->idate($this->birthday)."'" : "null");
 		$sql .= ", photo = ".($this->photo ? "'".$this->db->escape($this->photo)."'" : "null");
-		if ($user) $sql .= ", fk_user_modif=".$user->id;
+		if ($user) {
+			$sql .= ", fk_user_modif=".$user->id;
+		}
 		$sql .= " WHERE rowid=".$this->db->escape($id);
 
 		dol_syslog(get_class($this)."::update_perso this->birthday=".$this->birthday." -", LOG_DEBUG);
 		$resql = $this->db->query($sql);
-		if (!$resql)
-		{
+		if (!$resql) {
 			$error++;
 			$this->error = $this->db->lasterror();
 		}
@@ -875,7 +915,9 @@ class Contact extends CommonObject
 		if (!$error && !$notrigger) {
 			// Call trigger
 			$result = $this->call_trigger('CONTACT_MODIFY', $user);
-			if ($result < 0) { $error++; }
+			if ($result < 0) {
+				$error++;
+			}
 			// End call triggers
 		}
 
@@ -906,8 +948,7 @@ class Contact extends CommonObject
 
 		dol_syslog(get_class($this)."::fetch id=".$id." ref_ext=".$ref_ext." email=".$email, LOG_DEBUG);
 
-		if (empty($id) && empty($ref_ext) && empty($email))
-		{
+		if (empty($id) && empty($ref_ext) && empty($email)) {
 			$this->error = 'BadParameter';
 			return -1;
 		}
@@ -936,8 +977,9 @@ class Contact extends CommonObject
 		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON c.rowid = u.fk_socpeople";
 		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid";
 		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcommcontact as st ON c.fk_stcommcontact = st.id';
-		if ($id) $sql .= " WHERE c.rowid = ".((int) $id);
-		else {
+		if ($id) {
+			$sql .= " WHERE c.rowid = ".((int) $id);
+		} else {
 			$sql .= " WHERE c.entity IN (".getEntity($this->element).")";
 			if ($ref_ext) {
 				$sql .= " AND c.ref_ext = '".$this->db->escape($ref_ext)."'";
@@ -948,17 +990,14 @@ class Contact extends CommonObject
 		}
 
 		$resql = $this->db->query($sql);
-		if ($resql)
-		{
+		if ($resql) {
 			$num = $this->db->num_rows($resql);
-			if ($num > 1)
-			{
+			if ($num > 1) {
 				$this->error = 'Fetch found several records. Rename one of contact to avoid duplicate.';
 				dol_syslog($this->error, LOG_ERR);
 
 				return 2;
-			} elseif ($num)   // $num = 1
-			{
+			} elseif ($num) {   // $num = 1
 				$obj = $this->db->fetch_object($resql);
 
 				$this->id = $obj->rowid;
@@ -1030,10 +1069,8 @@ class Contact extends CommonObject
 				$sql .= " WHERE u.fk_socpeople = ".$this->id;
 
 				$resql = $this->db->query($sql);
-				if ($resql)
-				{
-					if ($this->db->num_rows($resql))
-					{
+				if ($resql) {
+					if ($this->db->num_rows($resql)) {
 						$uobj = $this->db->fetch_object($resql);
 
 						$this->user_id = $uobj->rowid;
@@ -1049,17 +1086,14 @@ class Contact extends CommonObject
 				$this->fetch_optionals();
 
 				// Load also alerts of this user
-				if ($user)
-				{
+				if ($user) {
 					$sql = "SELECT fk_user";
 					$sql .= " FROM ".MAIN_DB_PREFIX."user_alert";
 					$sql .= " WHERE fk_user = ".$user->id." AND fk_contact = ".$this->db->escape($id);
 
 					$resql = $this->db->query($sql);
-					if ($resql)
-					{
-						if ($this->db->num_rows($resql))
-						{
+					if ($resql) {
+						if ($this->db->num_rows($resql)) {
 							$obj = $this->db->fetch_object($resql);
 
 							$this->birthday_alert = 1;
@@ -1102,11 +1136,9 @@ class Contact extends CommonObject
 	{
 		unset($this->gender);
 
-		if (in_array($this->civility_id, array('MR')) || in_array($this->civility_code, array('MR')))
-		{
+		if (in_array($this->civility_id, array('MR')) || in_array($this->civility_code, array('MR'))) {
 			$this->gender = 'man';
-		} elseif (in_array($this->civility_id, array('MME', 'MLE')) || in_array($this->civility_code, array('MME', 'MLE')))
-		{
+		} elseif (in_array($this->civility_id, array('MME', 'MLE')) || in_array($this->civility_code, array('MME', 'MLE'))) {
 			$this->gender = 'woman';
 		}
 	}
@@ -1135,16 +1167,18 @@ class Contact extends CommonObject
 		dol_syslog(get_class($this)."::load_ref_elements", LOG_DEBUG);
 
 		$resql = $this->db->query($sql);
-		if ($resql)
-		{
-			while ($obj = $this->db->fetch_object($resql))
-			{
-				if ($obj->nb)
-				{
-					if ($obj->element == 'facture')  $this->ref_facturation = $obj->nb;
-					elseif ($obj->element == 'contrat')  $this->ref_contrat = $obj->nb;
-					elseif ($obj->element == 'commande') $this->ref_commande = $obj->nb;
-					elseif ($obj->element == 'propal')   $this->ref_propal = $obj->nb;
+		if ($resql) {
+			while ($obj = $this->db->fetch_object($resql)) {
+				if ($obj->nb) {
+					if ($obj->element == 'facture') {
+						$this->ref_facturation = $obj->nb;
+					} elseif ($obj->element == 'contrat') {
+						$this->ref_contrat = $obj->nb;
+					} elseif ($obj->element == 'commande') {
+						$this->ref_commande = $obj->nb;
+					} elseif ($obj->element == 'propal') {
+						$this->ref_propal = $obj->nb;
+					}
 				}
 			}
 			$this->db->free($resql);
@@ -1169,8 +1203,7 @@ class Contact extends CommonObject
 
 		$this->db->begin();
 
-		if (!$error)
-		{
+		if (!$error) {
 			// Get all rowid of element_contact linked to a type that is link to llx_socpeople
 			$sql = "SELECT ec.rowid";
 			$sql .= " FROM ".MAIN_DB_PREFIX."element_contact ec,";
@@ -1180,21 +1213,18 @@ class Contact extends CommonObject
 			$sql .= " AND tc.source='external'";
 			dol_syslog(__METHOD__, LOG_DEBUG);
 			$resql = $this->db->query($sql);
-			if ($resql)
-			{
+			if ($resql) {
 				$num = $this->db->num_rows($resql);
 
 				$i = 0;
-				while ($i < $num && !$error)
-				{
+				while ($i < $num && !$error) {
 					$obj = $this->db->fetch_object($resql);
 
 					$sqldel = "DELETE FROM ".MAIN_DB_PREFIX."element_contact";
 					$sqldel .= " WHERE rowid = ".$obj->rowid;
 					dol_syslog(__METHOD__, LOG_DEBUG);
 					$result = $this->db->query($sqldel);
-					if (!$result)
-					{
+					if (!$result) {
 						$error++;
 						$this->error = $this->db->error().' sql='.$sqldel;
 					}
@@ -1207,56 +1237,48 @@ class Contact extends CommonObject
 			}
 		}
 
-		if (!$error)
-		{
+		if (!$error) {
 			// Remove Roles
 			$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_contacts WHERE fk_socpeople = ".$this->id;
 			dol_syslog(__METHOD__, LOG_DEBUG);
 			$resql = $this->db->query($sql);
-			if (!$resql)
-			{
+			if (!$resql) {
 				$error++;
 				$this->error .= $this->db->lasterror();
 				$errorflag = -1;
 			}
 		}
 
-		if (!$error)
-		{
+		if (!$error) {
 			// Remove Roles
 			$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_contacts WHERE fk_socpeople = ".$this->id;
 			dol_syslog(__METHOD__, LOG_DEBUG);
 			$resql = $this->db->query($sql);
-			if (!$resql)
-			{
+			if (!$resql) {
 				$error++;
 				$this->error .= $this->db->lasterror();
 				$errorflag = -1;
 			}
 		}
 
-		if (!$error)
-		{
+		if (!$error) {
 			// Remove category
 			$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_contact WHERE fk_socpeople = ".$this->id;
 			dol_syslog(__METHOD__, LOG_DEBUG);
 			$resql = $this->db->query($sql);
-			if (!$resql)
-			{
+			if (!$resql) {
 				$error++;
 				$this->error .= $this->db->lasterror();
 				$errorflag = -1;
 			}
 		}
 
-		if (!$error)
-		{
+		if (!$error) {
 			$sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople";
 			$sql .= " WHERE rowid=".$this->id;
 			dol_syslog(__METHOD__, LOG_DEBUG);
 			$result = $this->db->query($sql);
-			if (!$result)
-			{
+			if (!$result) {
 				$error++;
 				$this->error = $this->db->error().' sql='.$sql;
 			}
@@ -1266,19 +1288,21 @@ class Contact extends CommonObject
 		if (!$error) {
 			// For avoid conflicts if trigger used
 			$result = $this->deleteExtraFields();
-			if ($result < 0) $error++;
+			if ($result < 0) {
+				$error++;
+			}
 		}
 
-		if (!$error && !$notrigger)
-		{
+		if (!$error && !$notrigger) {
 			// Call trigger
 			$result = $this->call_trigger('CONTACT_DELETE', $user);
-			if ($result < 0) { $error++; }
+			if ($result < 0) {
+				$error++;
+			}
 			// End call triggers
 		}
 
-		if (!$error)
-		{
+		if (!$error) {
 			$this->db->commit();
 			return 1;
 		} else {
@@ -1303,10 +1327,8 @@ class Contact extends CommonObject
 		$sql .= " WHERE c.rowid = ".$this->db->escape($id);
 
 		$resql = $this->db->query($sql);
-		if ($resql)
-		{
-			if ($this->db->num_rows($resql))
-			{
+		if ($resql) {
+			if ($this->db->num_rows($resql)) {
 				$obj = $this->db->fetch_object($resql);
 
 				$this->id = $obj->rowid;
@@ -1346,8 +1368,7 @@ class Contact extends CommonObject
 		$sql .= " AND m.entity IN (".getEntity($this->element).") AND mc.statut NOT IN (-1,0)"; // -1 error, 0 not sent, 1 sent with success
 
 		$resql = $this->db->query($sql);
-		if ($resql)
-		{
+		if ($resql) {
 			$obj = $this->db->fetch_object($resql);
 			$nb = $obj->nb;
 
@@ -1377,8 +1398,7 @@ class Contact extends CommonObject
 
 		$result = ''; $label = '';
 
-		if (!empty($this->photo) && class_exists('Form'))
-		{
+		if (!empty($this->photo) && class_exists('Form')) {
 			$label .= '<div class="photointooltip">';
 			$label .= Form::showphoto('contact', $this, 0, 40, 0, '', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
 			$label .= '</div><div style="clear: both;"></div>';
@@ -1388,67 +1408,83 @@ class Contact extends CommonObject
 		$label .= ' '.$this->getLibStatut(4);
 		$label .= '<br><b>'.$langs->trans("Name").':</b> '.$this->getFullName($langs);
 		//if ($this->civility_id) $label.= '<br><b>' . $langs->trans("Civility") . ':</b> '.$this->civility_id;		// TODO Translate cibilty_id code
-		if (!empty($this->poste)) $label .= '<br><b>'.$langs->trans("Poste").':</b> '.$this->poste;
+		if (!empty($this->poste)) {
+			$label .= '<br><b>'.$langs->trans("Poste").':</b> '.$this->poste;
+		}
 		$label .= '<br><b>'.$langs->trans("EMail").':</b> '.$this->email;
 		$phonelist = array();
 		$country_code = empty($this->country_code) ? '': $this->country_code;
-		if ($this->phone_pro) $phonelist[] = dol_print_phone($this->phone_pro, $country_code, $this->id, 0, '', '&nbsp;', 'phone');
-		if ($this->phone_mobile) $phonelist[] = dol_print_phone($this->phone_mobile, $country_code, $this->id, 0, '', '&nbsp;', 'mobile');
-		if ($this->phone_perso) $phonelist[] = dol_print_phone($this->phone_perso, $country_code, $this->id, 0, '', '&nbsp;', 'phone');
+		if ($this->phone_pro) {
+			$phonelist[] = dol_print_phone($this->phone_pro, $country_code, $this->id, 0, '', '&nbsp;', 'phone');
+		}
+		if ($this->phone_mobile) {
+			$phonelist[] = dol_print_phone($this->phone_mobile, $country_code, $this->id, 0, '', '&nbsp;', 'mobile');
+		}
+		if ($this->phone_perso) {
+			$phonelist[] = dol_print_phone($this->phone_perso, $country_code, $this->id, 0, '', '&nbsp;', 'phone');
+		}
 		$label .= '<br><b>'.$langs->trans("Phone").':</b> '.implode('&nbsp;', $phonelist);
 		$label .= '<br><b>'.$langs->trans("Address").':</b> '.dol_format_address($this, 1, ' ', $langs);
 
 		$url = DOL_URL_ROOT.'/contact/card.php?id='.$this->id;
 
-		if ($option !== 'nolink')
-		{
+		if ($option !== 'nolink') {
 			// Add param to save lastsearch_values or not
 			$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
-			if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
-			if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
+			if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
+				$add_save_lastsearch_values = 1;
+			}
+			if ($add_save_lastsearch_values) {
+				$url .= '&save_lastsearch_values=1';
+			}
 		}
 
 		$url .= $moreparam;
 
 		$linkclose = "";
 		if (empty($notooltip)) {
-			if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
-			{
+			if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
 				$label = $langs->trans("ShowContact");
 				$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
 			}
-		   	$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
-		   	$linkclose .= ' class="classfortooltip"';
-
-		   	/*
-    	   	 $hookmanager->initHooks(array('contactdao'));
-    	   	 $parameters=array('id'=>$this->id);
-    	   	 $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
-    	   	 if ($reshook > 0) $linkclose = $hookmanager->resPrint;
-    	   	 */
+			$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
+			$linkclose .= ' class="classfortooltip"';
+
+			/*
+				$hookmanager->initHooks(array('contactdao'));
+				$parameters=array('id'=>$this->id);
+				$reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
+				if ($reshook > 0) $linkclose = $hookmanager->resPrint;
+				*/
 		}
 
 		$linkstart = '<a href="'.$url.'"';
 		$linkstart .= $linkclose.'>';
 		$linkend = '</a>';
 
-		if ($option == 'xxx')
-		{
+		if ($option == 'xxx') {
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$this->id.$moreparam.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
 			$linkend = '</a>';
 		}
 
 		$result .= $linkstart;
-		if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
-		if ($withpicto != 2) $result .= ($maxlen ?dol_trunc($this->getFullName($langs), $maxlen) : $this->getFullName($langs));
+		if ($withpicto) {
+			$result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
+		}
+		if ($withpicto != 2) {
+			$result .= ($maxlen ?dol_trunc($this->getFullName($langs), $maxlen) : $this->getFullName($langs));
+		}
 		$result .= $linkend;
 
 		global $action;
 		$hookmanager->initHooks(array('contactdao'));
 		$parameters = array('id'=>$this->id, 'getnomurl'=>$result);
 		$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
-		if ($reshook > 0) $result = $hookmanager->resPrint;
-		else $result .= $hookmanager->resPrint;
+		if ($reshook > 0) {
+			$result = $hookmanager->resPrint;
+		} else {
+			$result .= $hookmanager->resPrint;
+		}
 
 		return $result;
 	}
@@ -1463,7 +1499,9 @@ class Contact extends CommonObject
 		global $langs;
 
 		$code = ($this->civility_code ? $this->civility_code : (!empty($this->civility_id) ? $this->civility : (!empty($this->civilite) ? $this->civilite : '')));
-		if (empty($code)) return '';
+		if (empty($code)) {
+			return '';
+		}
 
 		$langs->load("dict");
 		return $langs->getLabelFromKey($this->db, "Civility".$code, "c_civility", "code", "label", $code);
@@ -1507,7 +1545,9 @@ class Contact extends CommonObject
 		);
 
 		$statusType = 'status4';
-		if ($status == 0 || $status == 5) $statusType = 'status5';
+		if ($status == 0 || $status == 5) {
+			$statusType = 'status5';
+		}
 
 		$label = $langs->trans($labelStatus[$status]);
 		$labelshort = $langs->trans($labelStatusShort[$status]);
@@ -1527,8 +1567,11 @@ class Contact extends CommonObject
 	{
 		// phpcs:enable
 		global $langs;
-		if ($status == '1') return $langs->trans('ContactPrivate');
-		else return $langs->trans('ContactPublic');
+		if ($status == '1') {
+			return $langs->trans('ContactPrivate');
+		} else {
+			return $langs->trans('ContactPublic');
+		}
 	}
 
 
@@ -1547,7 +1590,9 @@ class Contact extends CommonObject
 		$resql = $this->db->query($sql);
 		if ($resql) {
 			$obj = $this->db->fetch_object($resql);
-			if ($obj) $socid = $obj->rowid;
+			if ($obj) {
+				$socid = $obj->rowid;
+			}
 		}
 
 		// Initialise parameters
@@ -1592,8 +1637,11 @@ class Contact extends CommonObject
 		$error = 0;
 
 		// Check parameters
-		if ($this->statut == $status) return 0;
-		else $this->statut = $status;
+		if ($this->statut == $status) {
+			return 0;
+		} else {
+			$this->statut = $status;
+		}
 
 		$this->db->begin();
 
@@ -1604,16 +1652,16 @@ class Contact extends CommonObject
 		$result = $this->db->query($sql);
 
 		dol_syslog(get_class($this)."::setstatus", LOG_DEBUG);
-		if ($result)
-		{
+		if ($result) {
 			// Call trigger
 			$result = $this->call_trigger('CONTACT_ENABLEDISABLE', $user);
-			if ($result < 0) { $error++; }
+			if ($result < 0) {
+				$error++;
+			}
 			// End call triggers
 		}
 
-		if ($error)
-		{
+		if ($error) {
 			$this->db->rollback();
 			return -$error;
 		} else {
@@ -1725,12 +1773,10 @@ class Contact extends CommonObject
 
 		dol_syslog(__METHOD__, LOG_DEBUG);
 		$resql = $this->db->query($sql);
-		if ($resql)
-		{
+		if ($resql) {
 			$num = $this->db->num_rows($resql);
 			$i = 0;
-			while ($i < $num)
-			{
+			while ($i < $num) {
 				$obj = $this->db->fetch_object($resql);
 				$tab[] = array('fk_socpeople'=>$obj->id, 'type_contact'=>$obj->fk_c_type_contact);
 
@@ -1758,7 +1804,9 @@ class Contact extends CommonObject
 
 		$error = 0;
 
-		if (!isset($this->roles)) return;	// Avoid to loose roles when property not set
+		if (!isset($this->roles)) {
+			return;	// Avoid to loose roles when property not set
+		}
 
 		$this->db->begin();
 
@@ -1800,8 +1848,7 @@ class Contact extends CommonObject
 						$sql .= ")";
 
 						$result = $this->db->query($sql);
-						if (!$result)
-						{
+						if (!$result) {
 							$this->errors[] = $this->db->lasterror().' sql='.$sql;
 							$error++;
 						}
@@ -1830,12 +1877,13 @@ class Contact extends CommonObject
 		global $langs;
 
 		$sql = "SELECT id, code, libelle as label, picto FROM ".MAIN_DB_PREFIX."c_stcommcontact";
-		if ($active >= 0) $sql .= " WHERE active = ".$active;
+		if ($active >= 0) {
+			$sql .= " WHERE active = ".$active;
+		}
 		$resql = $this->db->query($sql);
 		$num = $this->db->num_rows($resql);
 		$i = 0;
-		while ($i < $num)
-		{
+		while ($i < $num) {
 			$obj = $this->db->fetch_object($resql);
 			$this->cacheprospectstatus[$obj->id] = array('id' => $obj->id, 'code' => $obj->code, 'label' => ($langs->trans("ST_".strtoupper($obj->code)) == "ST_".strtoupper($obj->code)) ? $obj->label : $langs->trans("ST_".strtoupper($obj->code)), 'picto' => $obj->picto);
 			$i++;
@@ -1865,8 +1913,7 @@ class Contact extends CommonObject
 
 		$lib = $langs->trans("ProspectLevel".$fk_prospectlevel);
 		// If lib not found in language file, we get label from cache/databse
-		if ($lib == $langs->trans("ProspectLevel".$fk_prospectlevel))
-		{
+		if ($lib == $langs->trans("ProspectLevel".$fk_prospectlevel)) {
 			$lib = $langs->getLabelFromKey($this->db, $fk_prospectlevel, 'c_prospectlevel', 'code', 'label');
 		}
 		return $lib;
@@ -1915,36 +1962,48 @@ class Contact extends CommonObject
 		global $langs;
 		$langs->load('customers');
 
-		if ($mode == 2)
-		{
-			if ($statut == '-1' || $statut == 'ST_NO') return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1");
-			elseif ($statut == '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0");
-			elseif ($statut == '1' || $statut == 'ST_TODO') return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1");
-			elseif ($statut == '2' || $statut == 'ST_PEND') return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2");
-			elseif ($statut == '3' || $statut == 'ST_DONE') return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3");
-			else {
+		if ($mode == 2) {
+			if ($statut == '-1' || $statut == 'ST_NO') {
+				return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1");
+			} elseif ($statut == '0' || $statut == 'ST_NEVER') {
+				return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0");
+			} elseif ($statut == '1' || $statut == 'ST_TODO') {
+				return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1");
+			} elseif ($statut == '2' || $statut == 'ST_PEND') {
+				return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2");
+			} elseif ($statut == '3' || $statut == 'ST_DONE') {
+				return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3");
+			} else {
 				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0, $picto).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
 			}
 		}
-		if ($mode == 3)
-		{
-			if ($statut == '-1' || $statut == 'ST_NO') return img_action($langs->trans("StatusProspect-1"), -1, $picto);
-			elseif ($statut == '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0, $picto);
-			elseif ($statut == '1' || $statut == 'ST_TODO') return img_action($langs->trans("StatusProspect1"), 1, $picto);
-			elseif ($statut == '2' || $statut == 'ST_PEND') return img_action($langs->trans("StatusProspect2"), 2, $picto);
-			elseif ($statut == '3' || $statut == 'ST_DONE') return img_action($langs->trans("StatusProspect3"), 3, $picto);
-			else {
+		if ($mode == 3) {
+			if ($statut == '-1' || $statut == 'ST_NO') {
+				return img_action($langs->trans("StatusProspect-1"), -1, $picto);
+			} elseif ($statut == '0' || $statut == 'ST_NEVER') {
+				return img_action($langs->trans("StatusProspect0"), 0, $picto);
+			} elseif ($statut == '1' || $statut == 'ST_TODO') {
+				return img_action($langs->trans("StatusProspect1"), 1, $picto);
+			} elseif ($statut == '2' || $statut == 'ST_PEND') {
+				return img_action($langs->trans("StatusProspect2"), 2, $picto);
+			} elseif ($statut == '3' || $statut == 'ST_DONE') {
+				return img_action($langs->trans("StatusProspect3"), 3, $picto);
+			} else {
 				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0, $picto);
 			}
 		}
-		if ($mode == 4)
-		{
-			if ($statut == '-1' || $statut == 'ST_NO') return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1");
-			elseif ($statut == '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0");
-			elseif ($statut == '1' || $statut == 'ST_TODO') return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1");
-			elseif ($statut == '2' || $statut == 'ST_PEND') return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2");
-			elseif ($statut == '3' || $statut == 'ST_DONE') return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3");
-			else {
+		if ($mode == 4) {
+			if ($statut == '-1' || $statut == 'ST_NO') {
+				return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1");
+			} elseif ($statut == '0' || $statut == 'ST_NEVER') {
+				return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0");
+			} elseif ($statut == '1' || $statut == 'ST_TODO') {
+				return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1");
+			} elseif ($statut == '2' || $statut == 'ST_PEND') {
+				return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2");
+			} elseif ($statut == '3' || $statut == 'ST_DONE') {
+				return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3");
+			} else {
 				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0, $picto).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
 			}
 		}
@@ -1964,24 +2023,19 @@ class Contact extends CommonObject
 		$error = 0;
 
 		// Update mass emailing flag into table mailing_unsubscribe
-		if ($this->email)
-		{
+		if ($this->email) {
 			$this->db->begin();
 
-			if ($no_email)
-			{
+			if ($no_email) {
 				$sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE entity IN (".getEntity('mailing', 0).") AND email = '".$this->db->escape($this->email)."'";
 				$resql = $this->db->query($sql);
-				if ($resql)
-				{
+				if ($resql) {
 					$obj = $this->db->fetch_object($resql);
 					$noemail = $obj->nb;
-					if (empty($noemail))
-					{
+					if (empty($noemail)) {
 						$sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_unsubscribe(email, entity, date_creat) VALUES ('".$this->db->escape($this->email)."', ".$this->db->escape(getEntity('mailing', 0)).", '".$this->db->idate(dol_now())."')";
 						$resql = $this->db->query($sql);
-						if (!$resql)
-						{
+						if (!$resql) {
 							$error++;
 							$this->error = $this->db->lasterror();
 							$this->errors[] = $this->error;
@@ -1995,8 +2049,7 @@ class Contact extends CommonObject
 			} else {
 				$sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = '".$this->db->escape($this->email)."' AND entity = ".$this->db->escape(getEntity('mailing', 0));
 				$resql = $this->db->query($sql);
-				if (!$resql)
-				{
+				if (!$resql) {
 					$error++;
 					$this->error = $this->db->lasterror();
 					$this->errors[] = $this->error;
@@ -2024,8 +2077,7 @@ class Contact extends CommonObject
 	 */
 	public function getNoEmail()
 	{
-		if ($this->email)
-		{
+		if ($this->email) {
 			$sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE entity IN (".getEntity('mailing').") AND email = '".$this->db->escape($this->email)."'";
 			$resql = $this->db->query($sql);
 			if ($resql) {

+ 157 - 112
htdocs/contact/consumption.php

@@ -37,8 +37,12 @@ $id = GETPOST('id', 'int');
 
 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
 $object = new Contact($db);
-if ($id > 0) $object->fetch($id);
-if (empty($object->thirdparty)) $object->fetch_thirdparty();
+if ($id > 0) {
+	$object->fetch($id);
+}
+if (empty($object->thirdparty)) {
+	$object->fetch_thirdparty();
+}
 $socid = $object->thirdparty->id;
 
 // Sort & Order fields
@@ -46,12 +50,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
 $sortfield = GETPOST("sortfield", 'alpha');
 $sortorder = GETPOST("sortorder", 'alpha');
 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
-if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
+if (empty($page) || $page == -1) {
+	$page = 0;
+}     // If $page is not defined, or '' or -1
 $offset = $limit * $page;
 $pageprev = $page - 1;
 $pagenext = $page + 1;
-if (!$sortorder) $sortorder = 'DESC';
-if (!$sortfield) $sortfield = 'dateprint';
+if (!$sortorder) {
+	$sortorder = 'DESC';
+}
+if (!$sortfield) {
+	$sortfield = 'dateprint';
+}
 
 // Search fields
 $sref = GETPOST("sref");
@@ -60,8 +70,7 @@ $month = GETPOST('month', 'int');
 $year = GETPOST('year', 'int');
 
 // Clean up on purge search criteria ?
-if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // Both test are required to be compatible with all browsers
-{
+if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
 	$sref = '';
 	$sprod_fulldescr = '';
 	$year = '';
@@ -84,7 +93,9 @@ $hookmanager->initHooks(array('consumptioncontact'));
 
 $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 ($reshook < 0) {
+	setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+}
 
 
 /*
@@ -99,8 +110,7 @@ $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("C
 $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
 llxHeader('', $title, $help_url);
 
-if (empty($id))
-{
+if (empty($id)) {
 	dol_print_error($db);
 	exit;
 }
@@ -111,13 +121,15 @@ print dol_get_fiche_head($head, 'consumption', $langs->trans("ContactsAddresses"
 $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
 
 $morehtmlref = '<div class="refidno">';
-if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
-{
+if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
 	$objsoc->fetch($socid);
 	// Thirdparty
 	$morehtmlref .= $langs->trans('ThirdParty').' : ';
-	if ($objsoc->id > 0) $morehtmlref .= $objsoc->getNomUrl(1, 'contact');
-	else $morehtmlref .= $langs->trans("ContactNotLinkedToCompany");
+	if ($objsoc->id > 0) {
+		$morehtmlref .= $objsoc->getNomUrl(1, 'contact');
+	} else {
+		$morehtmlref .= $langs->trans("ContactNotLinkedToCompany");
+	}
 }
 $morehtmlref .= '</div>';
 
@@ -133,22 +145,34 @@ print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td>';
 print $object->getCivilityLabel();
 print '</td></tr>';
 
-if ($object->thirdparty->client)
-{
+if ($object->thirdparty->client) {
 	$thirdTypeArray['customer'] = $langs->trans("customer");
-	if ($conf->propal->enabled && $user->rights->propal->lire) $elementTypeArray['propal'] = $langs->transnoentitiesnoconv('Proposals');
-	if ($conf->commande->enabled && $user->rights->commande->lire) $elementTypeArray['order'] = $langs->transnoentitiesnoconv('Orders');
-	if ($conf->facture->enabled && $user->rights->facture->lire) $elementTypeArray['invoice'] = $langs->transnoentitiesnoconv('Invoices');
-	if ($conf->contrat->enabled && $user->rights->contrat->lire) $elementTypeArray['contract'] = $langs->transnoentitiesnoconv('Contracts');
+	if ($conf->propal->enabled && $user->rights->propal->lire) {
+		$elementTypeArray['propal'] = $langs->transnoentitiesnoconv('Proposals');
+	}
+	if ($conf->commande->enabled && $user->rights->commande->lire) {
+		$elementTypeArray['order'] = $langs->transnoentitiesnoconv('Orders');
+	}
+	if ($conf->facture->enabled && $user->rights->facture->lire) {
+		$elementTypeArray['invoice'] = $langs->transnoentitiesnoconv('Invoices');
+	}
+	if ($conf->contrat->enabled && $user->rights->contrat->lire) {
+		$elementTypeArray['contract'] = $langs->transnoentitiesnoconv('Contracts');
+	}
 }
 
-if ($conf->ficheinter->enabled && $user->rights->ficheinter->lire) $elementTypeArray['fichinter'] = $langs->transnoentitiesnoconv('Interventions');
+if ($conf->ficheinter->enabled && $user->rights->ficheinter->lire) {
+	$elementTypeArray['fichinter'] = $langs->transnoentitiesnoconv('Interventions');
+}
 
-if ($object->thirdparty->fournisseur)
-{
+if ($object->thirdparty->fournisseur) {
 	$thirdTypeArray['supplier'] = $langs->trans("supplier");
-	if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->facture->lire) $elementTypeArray['supplier_invoice'] = $langs->transnoentitiesnoconv('SuppliersInvoices');
-	if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled)) && $user->rights->fournisseur->commande->lire) $elementTypeArray['supplier_order'] = $langs->transnoentitiesnoconv('SuppliersOrders');
+	if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->facture->lire) {
+		$elementTypeArray['supplier_invoice'] = $langs->transnoentitiesnoconv('SuppliersInvoices');
+	}
+	if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled)) && $user->rights->fournisseur->commande->lire) {
+		$elementTypeArray['supplier_order'] = $langs->transnoentitiesnoconv('SuppliersOrders');
+	}
 
 	// There no contact type for supplier proposals
 	// if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) && $user->rights->supplier_proposal->lire) $elementTypeArray['supplier_proposal']=$langs->transnoentitiesnoconv('SupplierProposals');
@@ -166,8 +190,7 @@ print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?id='.$id.'">';
 print '<input type="hidden" name="token" value="'.newToken().'">';
 
 $sql_select = '';
-if ($type_element == 'fichinter')
-{ 	// Customer : show products from invoices
+if ($type_element == 'fichinter') { 	// Customer : show products from invoices
 	require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
 	$documentstatic = new Fichinter($db);
 	$sql_select = 'SELECT f.rowid as doc_id, f.ref as doc_number, \'1\' as doc_type, f.datec as dateprint, f.fk_statut as status, tc.libelle as type_contact_label, ';
@@ -178,8 +201,7 @@ if ($type_element == 'fichinter')
 	$where = ' WHERE f.entity IN ('.getEntity('ficheinter').')';
 	$dateprint = 'f.datec';
 	$doc_number = 'f.ref';
-} elseif ($type_element == 'invoice')
-{ 	// Customer : show products from invoices
+} elseif ($type_element == 'invoice') { 	// Customer : show products from invoices
 	require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
 	$documentstatic = new Facture($db);
 	$sql_select = 'SELECT f.rowid as doc_id, f.ref as doc_number, f.type as doc_type, f.datef as dateprint, f.fk_statut as status, f.paye as paid, tc.libelle as type_contact_label, ';
@@ -192,8 +214,7 @@ if ($type_element == 'fichinter')
 	$dateprint = 'f.datef';
 	$doc_number = 'f.ref';
 	$thirdTypeSelect = 'customer';
-} elseif ($type_element == 'propal')
-{
+} elseif ($type_element == 'propal') {
 	require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
 	$documentstatic = new Propal($db);
 	$sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.datep as dateprint, c.fk_statut as status, tc.libelle as type_contact_label, ';
@@ -206,8 +227,7 @@ if ($type_element == 'fichinter')
 	$datePrint = 'c.datep';
 	$doc_number = 'c.ref';
 	$thirdTypeSelect = 'customer';
-} elseif ($type_element == 'order')
-{
+} elseif ($type_element == 'order') {
 	require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
 	$documentstatic = new Commande($db);
 	$sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.date_commande as dateprint, c.fk_statut as status, tc.libelle as type_contact_label, ';
@@ -220,8 +240,7 @@ if ($type_element == 'fichinter')
 	$dateprint = 'c.date_commande';
 	$doc_number = 'c.ref';
 	$thirdTypeSelect = 'customer';
-} elseif ($type_element == 'supplier_invoice')
-{ 	// Supplier : Show products from invoices.
+} elseif ($type_element == 'supplier_invoice') { 	// Supplier : Show products from invoices.
 	require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
 	$documentstatic = new FactureFournisseur($db);
 	$sql_select = 'SELECT f.rowid as doc_id, f.ref as doc_number, \'1\' as doc_type, f.datef as dateprint, f.fk_statut as status, f.paye as paid, tc.libelle as type_contact_label, ';
@@ -234,22 +253,19 @@ if ($type_element == 'fichinter')
 	$dateprint = 'f.datef';
 	$doc_number = 'f.ref';
 	$thirdTypeSelect = 'supplier';
-}
-//elseif ($type_element == 'supplier_proposal')
-//{
-//    require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
-//    $documentstatic=new SupplierProposal($db);
-//    $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.date_valid as dateprint, c.fk_statut as status, ';
-//    $tables_from = MAIN_DB_PREFIX."supplier_proposal as c,".MAIN_DB_PREFIX."supplier_proposaldet as d";
-//    $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".$socid;
-//    $where.= " AND d.fk_supplier_proposal = c.rowid";
-//    $where.= " AND c.entity = ".$conf->entity;
-//    $dateprint = 'c.date_valid';
-//    $doc_number='c.ref';
-//    $thirdTypeSelect='supplier';
-//}
-elseif ($type_element == 'supplier_order')
-{ 	// Supplier : Show products from orders.
+	//} elseif ($type_element == 'supplier_proposal') {
+	//    require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
+	//    $documentstatic=new SupplierProposal($db);
+	//    $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.date_valid as dateprint, c.fk_statut as status, ';
+	//    $tables_from = MAIN_DB_PREFIX."supplier_proposal as c,".MAIN_DB_PREFIX."supplier_proposaldet as d";
+	//    $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".$socid;
+	//    $where.= " AND d.fk_supplier_proposal = c.rowid";
+	//    $where.= " AND c.entity = ".$conf->entity;
+	//    $dateprint = 'c.date_valid';
+	//    $doc_number='c.ref';
+	//    $thirdTypeSelect='supplier';
+	//}
+} elseif ($type_element == 'supplier_order') { 	// Supplier : Show products from orders.
 	require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
 	$documentstatic = new CommandeFournisseur($db);
 	$sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.date_valid as dateprint, c.fk_statut as status, tc.libelle as type_contact_label, ';
@@ -262,8 +278,7 @@ elseif ($type_element == 'supplier_order')
 	$dateprint = 'c.date_valid';
 	$doc_number = 'c.ref';
 	$thirdTypeSelect = 'supplier';
-} elseif ($type_element == 'contract')
-{ 	// Order
+} elseif ($type_element == 'contract') { 	// Order
 	require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
 	$documentstatic = new Contrat($db);
 	$documentstaticline = new ContratLigne($db);
@@ -282,26 +297,40 @@ elseif ($type_element == 'supplier_order')
 $parameters = array();
 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
 
-if (!empty($sql_select))
-{
+if (!empty($sql_select)) {
 	$sql = $sql_select;
 	$sql .= ' d.description as description';
-	if ($type_element != 'fichinter' && $type_element != 'contract' && $type_element != 'supplier_proposal') $sql .= ', d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_start, d.date_end, d.qty, d.qty as prod_qty, d.total_ht as total_ht, ';
-	if ($type_element == 'supplier_proposal') $sql .= ', d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.qty, d.qty as prod_qty, d.total_ht as total_ht, ';
-	if ($type_element == 'contract') $sql .= ', d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_ouverture as date_start, d.date_cloture as date_end, d.qty, d.qty as prod_qty, d.total_ht as total_ht, ';
-	if ($type_element != 'fichinter') $sql .= ' p.ref as ref, p.rowid as prod_id, p.rowid as fk_product, p.fk_product_type as prod_type, p.fk_product_type as fk_product_type, p.entity as pentity';
+	if ($type_element != 'fichinter' && $type_element != 'contract' && $type_element != 'supplier_proposal') {
+		$sql .= ', d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_start, d.date_end, d.qty, d.qty as prod_qty, d.total_ht as total_ht, ';
+	}
+	if ($type_element == 'supplier_proposal') {
+		$sql .= ', d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.qty, d.qty as prod_qty, d.total_ht as total_ht, ';
+	}
+	if ($type_element == 'contract') {
+		$sql .= ', d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_ouverture as date_start, d.date_cloture as date_end, d.qty, d.qty as prod_qty, d.total_ht as total_ht, ';
+	}
+	if ($type_element != 'fichinter') {
+		$sql .= ' p.ref as ref, p.rowid as prod_id, p.rowid as fk_product, p.fk_product_type as prod_type, p.fk_product_type as fk_product_type, p.entity as pentity';
+	}
 	$sql .= " ";
-	if ($type_element != 'fichinter') $sql .= ", p.ref as prod_ref, p.label as product_label";
+	if ($type_element != 'fichinter') {
+		$sql .= ", p.ref as prod_ref, p.label as product_label";
+	}
 	$sql .= " FROM "/*.MAIN_DB_PREFIX."societe as s, "*/.$tables_from;
 	// if ($type_element != 'fichinter') $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON d.fk_product = p.rowid ';
 	$sql .= $where;
 	$sql .= dolSqlDateFilter($dateprint, 0, $month, $year);
-	if ($sref) $sql .= " AND ".$doc_number." LIKE '%".$db->escape($sref)."%'";
-	if ($sprod_fulldescr)
-	{
+	if ($sref) {
+		$sql .= " AND ".$doc_number." LIKE '%".$db->escape($sref)."%'";
+	}
+	if ($sprod_fulldescr) {
 		$sql .= " AND (d.description LIKE '%".$db->escape($sprod_fulldescr)."%'";
-		if (GETPOST('type_element') != 'fichinter') $sql .= " OR p.ref LIKE '%".$db->escape($sprod_fulldescr)."%'";
-		if (GETPOST('type_element') != 'fichinter') $sql .= " OR p.label LIKE '%".$db->escape($sprod_fulldescr)."%'";
+		if (GETPOST('type_element') != 'fichinter') {
+			$sql .= " OR p.ref LIKE '%".$db->escape($sprod_fulldescr)."%'";
+		}
+		if (GETPOST('type_element') != 'fichinter') {
+			$sql .= " OR p.label LIKE '%".$db->escape($sprod_fulldescr)."%'";
+		}
 		$sql .= ")";
 	}
 	$sql .= $db->order($sortfield, $sortorder);
@@ -332,21 +361,36 @@ $param .= "&type_element=".urlencode($type_element);
 
 $total_qty = 0;
 
-if ($sql_select)
-{
+if ($sql_select) {
 	$resql = $db->query($sql);
-	if (!$resql) dol_print_error($db);
+	if (!$resql) {
+		dol_print_error($db);
+	}
 
 	$num = $db->num_rows($resql);
 
 	$param = "&socid=".urlencode($socid)."&type_element=".urlencode($type_element);
-	if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
-	if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
-	if ($sprod_fulldescr) $param .= "&sprod_fulldescr=".urlencode($sprod_fulldescr);
-	if ($sref) $param .= "&sref=".urlencode($sref);
-	if ($month) $param .= "&month=".urlencode($month);
-	if ($year) $param .= "&year=".urlencode($year);
-	if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
+	if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
+		$param .= '&contextpage='.urlencode($contextpage);
+	}
+	if ($limit > 0 && $limit != $conf->liste_limit) {
+		$param .= '&limit='.urlencode($limit);
+	}
+	if ($sprod_fulldescr) {
+		$param .= "&sprod_fulldescr=".urlencode($sprod_fulldescr);
+	}
+	if ($sref) {
+		$param .= "&sref=".urlencode($sref);
+	}
+	if ($month) {
+		$param .= "&month=".urlencode($month);
+	}
+	if ($year) {
+		$param .= "&year=".urlencode($year);
+	}
+	if ($optioncss != '') {
+		$param .= '&optioncss='.urlencode($optioncss);
+	}
 
 	print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, '', 0, '', '', $limit);
 
@@ -393,8 +437,7 @@ if ($sql_select)
 
 
 	$i = 0;
-	while (($objp = $db->fetch_object($resql)) && $i < min($num, $limit))
-	{
+	while (($objp = $db->fetch_object($resql)) && $i < min($num, $limit)) {
 		$documentstatic->id = $objp->doc_id;
 		$documentstatic->ref = $objp->doc_number;
 		$documentstatic->type = $objp->doc_type;
@@ -405,7 +448,9 @@ if ($sql_select)
 		$documentstatic->paye = $objp->paid;
 		$documentstatic->paid = $objp->paid;
 
-		if (is_object($documentstaticline)) $documentstaticline->statut = $objp->status;
+		if (is_object($documentstaticline)) {
+			$documentstaticline->statut = $objp->status;
+		}
 
 		print '<tr class="oddeven">';
 		print '<td class="nobordernopadding nowrap" width="100">';
@@ -415,8 +460,7 @@ if ($sql_select)
 
 		// Status
 		print '<td class="center">';
-		if ($type_element == 'contract')
-		{
+		if ($type_element == 'contract') {
 			print $documentstaticline->getLibStatut(2);
 		} else {
 			print $documentstatic->getLibStatut(2);
@@ -429,8 +473,7 @@ if ($sql_select)
 		$text = ''; $description = ''; $type = 0;
 
 		// Code to show product duplicated from commonobject->printObjectLine
-		if ($objp->fk_product > 0)
-		{
+		if ($objp->fk_product > 0) {
 			$product_static = new Product($db);
 
 			$product_static->type = $objp->fk_product_type;
@@ -441,20 +484,21 @@ if ($sql_select)
 		}
 
 		// Product
-		if ($objp->fk_product > 0)
-		{
+		if ($objp->fk_product > 0) {
 			// Define output language
-			if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
-			{
+			if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
 				$prod = new Product($db);
 				$prod->fetch($objp->fk_product);
 
 				$outputlangs = $langs;
 				$newlang = '';
-				if (empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
-				if (empty($newlang)) $newlang = $object->default_lang;
-				if (!empty($newlang))
-				{
+				if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
+					$newlang = GETPOST('lang_id', 'aZ09');
+				}
+				if (empty($newlang)) {
+					$newlang = $object->default_lang;
+				}
+				if (!empty($newlang)) {
 					$outputlangs = new Translate("", $conf);
 					$outputlangs->setDefaultLang($newlang);
 				}
@@ -468,42 +512,42 @@ if ($sql_select)
 			$description = (!empty($conf->global->PRODUIT_DESC_IN_FORM) ? '' : dol_htmlentitiesbr($objp->description));
 		}
 
-		if (($objp->info_bits & 2) == 2)
-		{
+		if (($objp->info_bits & 2) == 2) {
 			print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$object->id.'">';
 			$txt = '';
 			print img_object($langs->trans("ShowReduc"), 'reduc').' ';
-			if ($objp->description == '(DEPOSIT)') $txt = $langs->trans("Deposit");
-			elseif ($objp->description == '(EXCESS RECEIVED)') $txt = $langs->trans("ExcessReceived");
-			elseif ($objp->description == '(EXCESS PAID)') $txt = $langs->trans("ExcessPaid");
+			if ($objp->description == '(DEPOSIT)') {
+				$txt = $langs->trans("Deposit");
+			} elseif ($objp->description == '(EXCESS RECEIVED)') {
+				$txt = $langs->trans("ExcessReceived");
+			} elseif ($objp->description == '(EXCESS PAID)') {
+				$txt = $langs->trans("ExcessPaid");
+			}
 			//else $txt=$langs->trans("Discount");
 			print $txt;
 			print '</a>';
-			if ($objp->description)
-			{
-				if ($objp->description == '(CREDIT_NOTE)' && $objp->fk_remise_except > 0)
-				{
+			if ($objp->description) {
+				if ($objp->description == '(CREDIT_NOTE)' && $objp->fk_remise_except > 0) {
 					$discount = new DiscountAbsolute($db);
 					$discount->fetch($objp->fk_remise_except);
 					echo ($txt ? ' - ' : '').$langs->transnoentities("DiscountFromCreditNote", $discount->getNomUrl(0));
 				}
-				if ($objp->description == '(EXCESS RECEIVED)' && $objp->fk_remise_except > 0)
-				{
+				if ($objp->description == '(EXCESS RECEIVED)' && $objp->fk_remise_except > 0) {
 					$discount = new DiscountAbsolute($db);
 					$discount->fetch($objp->fk_remise_except);
 					echo ($txt ? ' - ' : '').$langs->transnoentities("DiscountFromExcessReceived", $discount->getNomUrl(0));
-				} elseif ($objp->description == '(EXCESS PAID)' && $objp->fk_remise_except > 0)
-				{
+				} elseif ($objp->description == '(EXCESS PAID)' && $objp->fk_remise_except > 0) {
 					$discount = new DiscountAbsolute($db);
 					$discount->fetch($objp->fk_remise_except);
 					echo ($txt ? ' - ' : '').$langs->transnoentities("DiscountFromExcessPaid", $discount->getNomUrl(0));
-				} elseif ($objp->description == '(DEPOSIT)' && $objp->fk_remise_except > 0)
-				{
+				} elseif ($objp->description == '(DEPOSIT)' && $objp->fk_remise_except > 0) {
 					$discount = new DiscountAbsolute($db);
 					$discount->fetch($objp->fk_remise_except);
 					echo ($txt ? ' - ' : '').$langs->transnoentities("DiscountFromDeposit", $discount->getNomUrl(0));
 					// Add date of deposit
-					if (!empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) echo ' ('.dol_print_date($discount->datec).')';
+					if (!empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) {
+						echo ' ('.dol_print_date($discount->datec).')';
+					}
 				} else {
 					echo ($txt ? ' - ' : '').dol_htmlentitiesbr($objp->description);
 				}
@@ -516,15 +560,16 @@ if ($sql_select)
 				echo get_date_range($objp->date_start, $objp->date_end);
 
 				// Add description in form
-				if (!empty($conf->global->PRODUIT_DESC_IN_FORM))
-				{
+				if (!empty($conf->global->PRODUIT_DESC_IN_FORM)) {
 					print (!empty($objp->description) && $objp->description != $objp->product_label) ? '<br>'.dol_htmlentitiesbr($objp->description) : '';
 				}
 			} else {
-				if (!empty($objp->label) || !empty($objp->description))
-				{
-					if ($type == 1) $text = img_object($langs->trans('Service'), 'service');
-					else $text = img_object($langs->trans('Product'), 'product');
+				if (!empty($objp->label) || !empty($objp->description)) {
+					if ($type == 1) {
+						$text = img_object($langs->trans('Service'), 'service');
+					} else {
+						$text = img_object($langs->trans('Product'), 'product');
+					}
 
 					if (!empty($objp->label)) {
 						$text .= ' <strong>'.$objp->label.'</strong>';

+ 50 - 35
htdocs/contact/document.php

@@ -43,15 +43,16 @@ $object = new Contact($db);
 $object->getCanvas($id);
 $objcanvas = null;
 $canvas = (!empty($object->canvas) ? $object->canvas : GETPOST("canvas"));
-if (!empty($canvas))
-{
+if (!empty($canvas)) {
 	require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
 	$objcanvas = new Canvas($db, $action);
 	$objcanvas->getCanvas('contact', 'contactcard', $canvas);
 }
 
 // Security check
-if ($user->socid) $socid = $user->socid;
+if ($user->socid) {
+	$socid = $user->socid;
+}
 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe', '', '', 'rowid', 0); // If we create a contact with no company (shared contacts), no check on write permission
 
 // Get parameters
@@ -59,18 +60,30 @@ $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
 $sortfield = GETPOST("sortfield", 'alpha');
 $sortorder = GETPOST("sortorder", 'alpha');
 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
-if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
+if (empty($page) || $page == -1) {
+	$page = 0;
+}     // If $page is not defined, or '' or -1
 $offset = $limit * $page;
 $pageprev = $page - 1;
 $pagenext = $page + 1;
 
-if (!empty($conf->global->MAIN_DOC_SORT_FIELD)) { $sortfield = $conf->global->MAIN_DOC_SORT_FIELD; }
-if (!empty($conf->global->MAIN_DOC_SORT_ORDER)) { $sortorder = $conf->global->MAIN_DOC_SORT_ORDER; }
+if (!empty($conf->global->MAIN_DOC_SORT_FIELD)) {
+	$sortfield = $conf->global->MAIN_DOC_SORT_FIELD;
+}
+if (!empty($conf->global->MAIN_DOC_SORT_ORDER)) {
+	$sortorder = $conf->global->MAIN_DOC_SORT_ORDER;
+}
 
-if (!$sortorder) $sortorder = "ASC";
-if (!$sortfield) $sortfield = "name";
+if (!$sortorder) {
+	$sortorder = "ASC";
+}
+if (!$sortfield) {
+	$sortfield = "name";
+}
 
-if ($id > 0) $object->fetch($id);
+if ($id > 0) {
+	$object->fetch($id);
+}
 
 $upload_dir = $conf->societe->multidir_output[$object->entity].'/contact/'.dol_sanitizeFileName($object->ref);
 $modulepart = 'contact';
@@ -90,12 +103,13 @@ include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
 $form = new Form($db);
 
 $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
-if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->lastname) $title = $object->lastname;
+if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->lastname) {
+	$title = $object->lastname;
+}
 $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
 llxHeader('', $title, $helpurl);
 
-if ($object->id)
-{
+if ($object->id) {
 	$head = contact_prepare_head($object);
 	$title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
 
@@ -105,22 +119,23 @@ if ($object->id)
 	// Build file list
 	$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
 	$totalsize = 0;
-	foreach ($filearray as $key => $file)
-	{
+	foreach ($filearray as $key => $file) {
 		$totalsize += $file['size'];
 	}
 
 	$linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
 
 	$morehtmlref = '<div class="refidno">';
-	if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
-	{
+	if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
 		$objsoc = new Societe($db);
 		$objsoc->fetch($object->socid);
 		// Thirdparty
 		$morehtmlref .= $langs->trans('ThirdParty').' : ';
-		if ($objsoc->id > 0) $morehtmlref .= $objsoc->getNomUrl(1);
-		else $morehtmlref .= $langs->trans("ContactNotLinkedToCompany");
+		if ($objsoc->id > 0) {
+			$morehtmlref .= $objsoc->getNomUrl(1);
+		} else {
+			$morehtmlref .= $langs->trans("ContactNotLinkedToCompany");
+		}
 	}
 	$morehtmlref .= '</div>';
 
@@ -133,23 +148,23 @@ if ($object->id)
 
 	// Company
 	/*
-    if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
-    {
-    	if ($object->socid > 0)
-    	{
-    		$objsoc = new Societe($db);
-    		$objsoc->fetch($object->socid);
-
-    		print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
-    	}
-
-    	else
-    	{
-    		print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
-    		print $langs->trans("ContactNotLinkedToCompany");
-    		print '</td></tr>';
-    	}
-    }*/
+	if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
+	{
+		if ($object->socid > 0)
+		{
+			$objsoc = new Societe($db);
+			$objsoc->fetch($object->socid);
+
+			print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
+		}
+
+		else
+		{
+			print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
+			print $langs->trans("ContactNotLinkedToCompany");
+			print '</td></tr>';
+		}
+	}*/
 
 	// Civility
 	print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td colspan="3">';

+ 4 - 3
htdocs/contact/info.php

@@ -34,7 +34,9 @@ $langs->load("companies");
 
 // Security check
 $id = GETPOST("id", 'int');
-if ($user->socid) $socid = $user->socid;
+if ($user->socid) {
+	$socid = $user->socid;
+}
 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
 
 $object = new Contact($db);
@@ -51,8 +53,7 @@ $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("C
 
 llxHeader('', $title, 'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas');
 
-if ($id > 0)
-{
+if ($id > 0) {
 	$result = $object->fetch($id, $user);
 
 	$object->info($id);

+ 14 - 18
htdocs/contact/ldap.php

@@ -36,12 +36,13 @@ $action = GETPOST('action', 'aZ09');
 
 // Security check
 $id = GETPOST('id', 'int');
-if ($user->socid) $socid = $user->socid;
+if ($user->socid) {
+	$socid = $user->socid;
+}
 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
 
 $object = new Contact($db);
-if ($id > 0)
-{
+if ($id > 0) {
 	$object->fetch($id, $user);
 }
 
@@ -50,8 +51,7 @@ if ($id > 0)
  * Actions
  */
 
-if ($action == 'dolibarr2ldap')
-{
+if ($action == 'dolibarr2ldap') {
 	$db->begin();
 
 	$ldap = new Ldap();
@@ -63,8 +63,7 @@ if ($action == 'dolibarr2ldap')
 
 	$result = $ldap->update($dn, $info, $user, $olddn);
 
-	if ($result >= 0)
-	{
+	if ($result >= 0) {
 		setEventMessages($langs->trans("ContactSynchronized"), null, 'mesgs');
 		$db->commit();
 	} else {
@@ -98,8 +97,7 @@ print '<div class="underbanner clearboth"></div>';
 print '<table class="border centpercent">';
 
 // Company
-if ($object->socid > 0)
-{
+if ($object->socid > 0) {
 	$thirdparty = new Societe($db);
 	$thirdparty->fetch($object->socid);
 
@@ -139,14 +137,15 @@ print dol_get_fiche_end();
 
 print '<div class="tabsAction">';
 
-if (!empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr')
-{
+if (!empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr') {
 	print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
 }
 
 print "</div>\n";
 
-if (!empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr') print "<br>\n";
+if (!empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr') {
+	print "<br>\n";
+}
 
 
 
@@ -163,8 +162,7 @@ print '</tr>';
 // Lecture LDAP
 $ldap = new Ldap();
 $result = $ldap->connect_bind();
-if ($result > 0)
-{
+if ($result > 0) {
 	$info = $object->_load_ldap_info();
 	$dn = $object->_load_ldap_dn($info, 1);
 	$search = "(".$object->_load_ldap_dn($info, 2).")";
@@ -174,10 +172,8 @@ if ($result > 0)
 	//var_dump($records);
 
 	// Show tree
-	if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0))
-	{
-		if (!is_array($records))
-		{
+	if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0)) {
+		if (!is_array($records)) {
 			print '<tr class="oddeven"><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';
 		} else {
 			$result = show_ldap_content($records, 0, $records['count'], true);

File diff suppressed because it is too large
+ 393 - 233
htdocs/contact/list.php


+ 18 - 11
htdocs/contact/note.php

@@ -36,11 +36,15 @@ $langs->load("companies");
 
 // Security check
 $id = GETPOST('id', 'int');
-if ($user->socid) $id = $user->socid;
+if ($user->socid) {
+	$id = $user->socid;
+}
 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
 
 $object = new Contact($db);
-if ($id > 0) $object->fetch($id);
+if ($id > 0) {
+	$object->fetch($id);
+}
 
 $permissionnote = $user->rights->societe->creer; // Used by the include of actions_setnotes.inc.php
 
@@ -65,12 +69,13 @@ $form = new Form($db);
 $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
 llxHeader('', $title, $help_url);
 
-if ($id > 0)
-{
+if ($id > 0) {
 	/*
-     * Affichage onglets
-     */
-	if (!empty($conf->notification->enabled)) $langs->load("mails");
+	 * Affichage onglets
+	 */
+	if (!empty($conf->notification->enabled)) {
+		$langs->load("mails");
+	}
 
 	$head = contact_prepare_head($object);
 
@@ -79,14 +84,16 @@ if ($id > 0)
 	$linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
 
 	$morehtmlref = '<div class="refidno">';
-	if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
-	{
+	if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
 		$objsoc = new Societe($db);
 		$objsoc->fetch($object->socid);
 		// Thirdparty
 		$morehtmlref .= $langs->trans('ThirdParty').' : ';
-		if ($objsoc->id > 0) $morehtmlref .= $objsoc->getNomUrl(1);
-		else $morehtmlref .= $langs->trans("ContactNotLinkedToCompany");
+		if ($objsoc->id > 0) {
+			$morehtmlref .= $objsoc->getNomUrl(1);
+		} else {
+			$morehtmlref .= $langs->trans("ContactNotLinkedToCompany");
+		}
 	}
 	$morehtmlref .= '</div>';
 

+ 68 - 64
htdocs/contact/perso.php

@@ -35,7 +35,9 @@ $id = GETPOST('id', 'int');
 $action = GETPOST('action', 'aZ09');
 
 // Security check
-if ($user->socid) $socid = $user->socid;
+if ($user->socid) {
+	$socid = $user->socid;
+}
 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
 $object = new Contact($db);
 
@@ -43,47 +45,43 @@ $object = new Contact($db);
  * Action
  */
 
-if ($action == 'update' && !$_POST["cancel"] && $user->rights->societe->contact->creer)
-{
+if ($action == 'update' && !$_POST["cancel"] && $user->rights->societe->contact->creer) {
 	$ret = $object->fetch($id);
 
 	// Note: Correct date should be completed with location to have exact GM time of birth.
 	$object->birthday = dol_mktime(0, 0, 0, $_POST["birthdaymonth"], $_POST["birthdayday"], $_POST["birthdayyear"]);
 	$object->birthday_alert = $_POST["birthday_alert"];
 
-	if (GETPOST('deletephoto')) $object->photo = '';
-	elseif (!empty($_FILES['photo']['name'])) $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
+	if (GETPOST('deletephoto')) {
+		$object->photo = '';
+	} elseif (!empty($_FILES['photo']['name'])) {
+		$object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
+	}
 
 	$result = $object->update_perso($id, $user);
-	if ($result > 0)
-	{
+	if ($result > 0) {
 		$object->old_name = '';
 		$object->old_firstname = '';
 		// Logo/Photo save
 		$dir = $conf->societe->dir_output.'/contact/'.get_exdir($object->id, 0, 0, 1, $object, 'contact').'/photos';
 
 		$file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
-		if ($file_OK)
-		{
+		if ($file_OK) {
 			require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
 			require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
-			if (GETPOST('deletephoto'))
-			{
+			if (GETPOST('deletephoto')) {
 				$fileimg = $conf->societe->dir_output.'/contact/'.get_exdir($object->id, 0, 0, 1, $object, 'contact').'/photos/'.$object->photo;
 				$dirthumbs = $conf->societe->dir_output.'/contact/'.get_exdir($object->id, 0, 0, 1, $object, 'contact').'/photos/thumbs';
 				dol_delete_file($fileimg);
 				dol_delete_dir_recursive($dirthumbs);
 			}
 
-			if (image_format_supported($_FILES['photo']['name']) > 0)
-			{
+			if (image_format_supported($_FILES['photo']['name']) > 0) {
 				dol_mkdir($dir);
 
-				if (@is_dir($dir))
-				{
+				if (@is_dir($dir)) {
 					$newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
-					if (!dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1, 0, $_FILES['photo']['error']) > 0)
-					{
+					if (!dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1, 0, $_FILES['photo']['error']) > 0) {
 						setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
 					} else {
 						// Create thumbs
@@ -94,8 +92,7 @@ if ($action == 'update' && !$_POST["cancel"] && $user->rights->societe->contact-
 				setEventMessages("ErrorBadImageFormat", null, 'errors');
 			}
 		} else {
-			switch ($_FILES['photo']['error'])
-			{
+			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";
@@ -118,7 +115,9 @@ if ($action == 'update' && !$_POST["cancel"] && $user->rights->societe->contact-
 $now = dol_now();
 
 $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
-if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->lastname) $title = $object->lastname;
+if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->lastname) {
+	$title = $object->lastname;
+}
 $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
 llxHeader('', $title, $helpurl);
 
@@ -128,8 +127,7 @@ $object->fetch($id, $user);
 
 $head = contact_prepare_head($object);
 
-if ($action == 'edit')
-{
+if ($action == 'edit') {
 	/*
 	 * Fiche en mode edition
 	 */
@@ -151,11 +149,15 @@ if ($action == 'edit')
 	// Photo
 	print '<td class="center hideonsmartphone valignmiddle" rowspan="6">';
 	print $form->showphoto('contact', $object)."\n";
-	if ($object->photo) print "<br>\n";
+	if ($object->photo) {
+		print "<br>\n";
+	}
 
 	print '<table class="nobordernopadding">';
 
-	if ($object->photo) print '<tr><td class="center"><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
+	if ($object->photo) {
+		print '<tr><td class="center"><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
+	}
 	print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
 	print '<tr><td><input type="file" class="flat" name="photo" id="photoinput"></td></tr>';
 	print '</table>';
@@ -167,10 +169,8 @@ if ($action == 'edit')
 	print '<tr><td>'.$langs->trans("Firstname").'</td><td colspan="3">'.$object->firstname.'</td>';
 
 	// Company
-	if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
-	{
-		if ($object->socid > 0)
-		{
+	if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
+		if ($object->socid > 0) {
 			$objsoc = new Societe($db);
 			$objsoc->fetch($object->socid);
 
@@ -194,8 +194,7 @@ if ($action == 'edit')
 	print '</td>';
 
 	print '<td colspan="2">'.$langs->trans("Alert").': ';
-	if (!empty($object->birthday_alert))
-	{
+	if (!empty($object->birthday_alert)) {
 		print '<input type="checkbox" name="birthday_alert" checked></td>';
 	} else {
 		print '<input type="checkbox" name="birthday_alert"></td>';
@@ -221,14 +220,16 @@ if ($action == 'edit')
 	$linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
 
 	$morehtmlref = '<div class="refidno">';
-	if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
-	{
+	if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
 		$objsoc = new Societe($db);
 		$objsoc->fetch($object->socid);
 		// Thirdparty
 		$morehtmlref .= $langs->trans('ThirdParty').' : ';
-		if ($objsoc->id > 0) $morehtmlref .= $objsoc->getNomUrl(1);
-		else $morehtmlref .= $langs->trans("ContactNotLinkedToCompany");
+		if ($objsoc->id > 0) {
+			$morehtmlref .= $objsoc->getNomUrl(1);
+		} else {
+			$morehtmlref .= $langs->trans("ContactNotLinkedToCompany");
+		}
 	}
 	$morehtmlref .= '</div>';
 
@@ -243,23 +244,23 @@ if ($action == 'edit')
 
 	// Company
 	/*
-    if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
-    {
-        if ($object->socid > 0)
-        {
-            $objsoc = new Societe($db);
-            $objsoc->fetch($object->socid);
-
-            print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
-        }
-
-        else
-        {
-            print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
-            print $langs->trans("ContactNotLinkedToCompany");
-            print '</td></tr>';
-        }
-    }*/
+	if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
+	{
+		if ($object->socid > 0)
+		{
+			$objsoc = new Societe($db);
+			$objsoc->fetch($object->socid);
+
+			print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
+		}
+
+		else
+		{
+			print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
+			print $langs->trans("ContactNotLinkedToCompany");
+			print '</td></tr>';
+		}
+	}*/
 
 	// Civility
 	print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td colspan="3">';
@@ -268,8 +269,7 @@ if ($action == 'edit')
 
 	// Date To Birth
 	print '<tr>';
-	if (!empty($object->birthday))
-	{
+	if (!empty($object->birthday)) {
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
 
 		print '<td>'.$langs->trans("DateOfBirth").'</td><td colspan="3">'.dol_print_date($object->birthday, "day");
@@ -278,14 +278,21 @@ if ($action == 'edit')
 		//var_dump($birthdatearray);
 		$ageyear = convertSecondToTime($now - $object->birthday, 'year') - 1970;
 		$agemonth = convertSecondToTime($now - $object->birthday, 'month') - 1;
-		if ($ageyear >= 2) print '('.$ageyear.' '.$langs->trans("DurationYears").')';
-		elseif ($agemonth >= 2) print '('.$agemonth.' '.$langs->trans("DurationMonths").')';
-		else print '('.$agemonth.' '.$langs->trans("DurationMonth").')';
+		if ($ageyear >= 2) {
+			print '('.$ageyear.' '.$langs->trans("DurationYears").')';
+		} elseif ($agemonth >= 2) {
+			print '('.$agemonth.' '.$langs->trans("DurationMonths").')';
+		} else {
+			print '('.$agemonth.' '.$langs->trans("DurationMonth").')';
+		}
 
 
 		print ' &nbsp; - &nbsp; ';
-		if ($object->birthday_alert) print $langs->trans("BirthdayAlertOn");
-		else print $langs->trans("BirthdayAlertOff");
+		if ($object->birthday_alert) {
+			print $langs->trans("BirthdayAlertOn");
+		} else {
+			print $langs->trans("BirthdayAlertOff");
+		}
 		print '</td>';
 	} else {
 		print '<td>'.$langs->trans("DateOfBirth").'</td><td colspan="3"></td>';
@@ -300,15 +307,12 @@ if ($action == 'edit')
 }
 
 
-if ($action != 'edit')
-{
+if ($action != 'edit') {
 	// Barre d'actions
-	if ($user->socid == 0)
-	{
+	if ($user->socid == 0) {
 		print '<div class="tabsAction">';
 
-		if ($user->rights->societe->contact->creer)
-		{
+		if ($user->rights->societe->contact->creer) {
 			print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit">'.$langs->trans('Modify').'</a>';
 		}
 

+ 25 - 24
htdocs/contact/vcard.php

@@ -39,8 +39,7 @@ $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
 
 
 $result = $contact->fetch($id);
-if ($result <= 0)
-{
+if ($result <= 0) {
 	dol_print_error($contact->error);
 	exit;
 }
@@ -48,8 +47,7 @@ if ($result <= 0)
 $physicalperson = 1;
 
 $company = new Societe($db);
-if ($contact->socid)
-{
+if ($contact->socid) {
 	$result = $company->fetch($contact->socid);
 }
 
@@ -76,33 +74,32 @@ $v->setNote($contact->note);
 $v->setTitle($contact->poste);
 
 // Data from linked company
-if ($company->id)
-{
+if ($company->id) {
 	$v->setURL($company->url, "TYPE=WORK");
-	if (!$contact->phone_pro) $v->setPhoneNumber($company->phone, "TYPE=WORK;VOICE");
-	if (!$contact->fax)       $v->setPhoneNumber($company->fax, "TYPE=WORK;FAX");
-	if (!$contact->zip)       $v->setAddress("", "", $company->address, $company->town, $company->state, $company->zip, $company->country, "TYPE=WORK;POSTAL");
+	if (!$contact->phone_pro) {
+		$v->setPhoneNumber($company->phone, "TYPE=WORK;VOICE");
+	}
+	if (!$contact->fax) {
+		$v->setPhoneNumber($company->fax, "TYPE=WORK;FAX");
+	}
+	if (!$contact->zip) {
+		$v->setAddress("", "", $company->address, $company->town, $company->state, $company->zip, $company->country, "TYPE=WORK;POSTAL");
+	}
 
 	// when company e-mail is empty, use only contact e-mail
-	if (empty(trim($company->email)))
-	{
+	if (empty(trim($company->email))) {
 		// was set before, don't set twice
-	}
-	// when contact e-mail is empty, use only company e-mail
-	elseif (empty(trim($contact->email)))
-	{
+	} elseif (empty(trim($contact->email))) {
+		// when contact e-mail is empty, use only company e-mail
 		$v->setEmail($company->email);
-	}
-	// when e-mail domain of contact and company are the same, use contact e-mail at first (and company e-mail at second)
-	elseif (strtolower(end(explode("@", $contact->email))) == strtolower(end(explode("@", $company->email))))
-	{
+	} elseif (strtolower(end(explode("@", $contact->email))) == strtolower(end(explode("@", $company->email)))) {
+		// when e-mail domain of contact and company are the same, use contact e-mail at first (and company e-mail at second)
 		$v->setEmail($contact->email);
 
 		// support by Microsoft Outlook (2019 and possible earlier)
 		$v->setEmail($company->email, 'INTERNET');
-	}
-	// when e-mail of contact and company complete different use company e-mail at first (and contact e-mail at second)
-	else {
+	} else {
+		// when e-mail of contact and company complete different use company e-mail at first (and contact e-mail at second)
 		$v->setEmail($company->email);
 
 		// support by Microsoft Outlook (2019 and possible earlier)
@@ -110,12 +107,16 @@ if ($company->id)
 	}
 
 	// Si contact lie a un tiers non de type "particulier"
-	if ($contact->typent_code != 'TE_PRIVATE') $v->setOrg($company->name);
+	if ($contact->typent_code != 'TE_PRIVATE') {
+		$v->setOrg($company->name);
+	}
 }
 
 // Personal informations
 $v->setPhoneNumber($contact->phone_perso, "TYPE=HOME;VOICE");
-if ($contact->birthday) $v->setBirthday($contact->birthday);
+if ($contact->birthday) {
+	$v->setBirthday($contact->birthday);
+}
 
 $db->close();
 

Some files were not shown because too many files changed in this diff