--- /tmp/dsg/dolibarr/htdocs/contrat/github_19.0.3_agenda.php
+++ /tmp/dsg/dolibarr/htdocs/contrat/client_agenda.php
@@ -26 +25,0 @@
-require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';

@@ -31 +30 @@
-if (isModEnabled('project')) {

+if (!empty($conf->projet->enabled)) {

@@ -39 +38,2 @@
-if (GETPOST('actioncode', 'array')) {

+if (GETPOST('actioncode', 'array'))

+{

@@ -41,8 +41,6 @@
-	if (!count($actioncode)) {

-		$actioncode = '0';

-	}

-} else {

-	$actioncode = GETPOST("actioncode", "alpha", 3) ? GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT'));

-}

-

-$search_rowid = GETPOST('search_rowid');

+	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));

+}

@@ -57,12 +55,6 @@
-if ($user->socid) {

-	$socid = $user->socid;

-}

-

-// Security check

-$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));

-$fieldtype = (!empty($id) ? 'rowid' : 'ref');

-$result = restrictedArea($user, 'contrat', $fieldvalue, '', '', '', $fieldtype);

-

-$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;

-$sortfield = GETPOST('sortfield', 'aZ09comma');

-$sortorder = GETPOST('sortorder', 'aZ09comma');

+if ($user->socid) $socid = $user->socid;

+$result = restrictedArea($user, 'contrat', $id, '');

+

+$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;

+$sortfield = GETPOST("sortfield", 'alpha');

+$sortorder = GETPOST("sortorder", 'alpha');

@@ -70,3 +62 @@
-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

@@ -76,12 +66,2 @@
-if (!$sortfield) {

-	$sortfield = 'a.datep,a.id';

-}

-if (!$sortorder) {

-	$sortorder = 'DESC,DESC';

-}

-

-

-$object = new Contrat($db);

-if ($id > 0 || !empty($ref)) {

-	$result = $object->fetch($id, $ref);

-}

+if (!$sortfield) $sortfield = 'a.datep,a.id';

+if (!$sortorder) $sortorder = 'DESC,DESC';

@@ -92,4 +71,0 @@
-$permissiontoadd = $user->hasRight('contrat', 'creer');     //  Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php

-

-$result = restrictedArea($user, 'contrat', $object->id);

-

@@ -101 +77 @@
-$parameters = array('id' => $id, 'ref' => $ref);

+$parameters = array('id'=>$id);

@@ -103,5 +79,4 @@
-if ($reshook < 0) {

-	setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

-}

-

-if (empty($reshook)) {

+if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

+

+if (empty($reshook))

+{

@@ -109 +84,2 @@
-	if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {

+	if (GETPOST('cancel', 'alpha') && !empty($backtopage))

+	{

@@ -115 +91,2 @@
-	if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers

+	if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers

+	{

@@ -121,0 +99,2 @@
+

+

@@ -128,5 +107,4 @@
-if (isModEnabled('project')) {

-	$formproject = new FormProjets($db);

-}

-

-if ($object->id > 0) {

+if (!empty($conf->projet->enabled)) $formproject = new FormProjets($db);

+

+if ($id > 0)

+{

@@ -134,2 +112,3 @@
-	$module = (getDolGlobalString('CONTRACT_ADDON') ? $conf->global->CONTRACT_ADDON : 'mod_contract_serpis');

-	if (substr($module, 0, 13) == 'mod_contract_' && substr($module, -3) == 'php') {

+	$module = (!empty($conf->global->CONTRACT_ADDON) ? $conf->global->CONTRACT_ADDON : 'mod_contract_serpis');

+	if (substr($module, 0, 13) == 'mod_contract_' && substr($module, -3) == 'php')

+	{

@@ -139 +118,2 @@
-	if ($result > 0) {

+	if ($result > 0)

+	{

@@ -145,0 +126,2 @@
+	$object = new Contrat($db);

+	$result = $object->fetch($id);

@@ -149,10 +131,4 @@
-	if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/contractrefonly/', $conf->global->MAIN_HTML_TITLE) && $object->ref) {

-		$title = $object->ref." - ".$title;

-	}

-	$help_url = 'EN:Module_Contracts|FR:Module_Contrat';

-

-	llxHeader('', $title, $help_url);

-

-	if (isModEnabled('notification')) {

-		$langs->load("mails");

-	}

+	if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contractrefonly/', $conf->global->MAIN_HTML_TITLE) && $object->ref) $title = $object->ref." - ".$title;

+	llxHeader('', $title);

+

+	if (!empty($conf->notification->enabled)) $langs->load("mails");

@@ -161 +137 @@
-	print dol_get_fiche_head($head, 'agenda', $langs->trans("Contract"), -1, 'contract');

+	dol_fiche_head($head, 'agenda', $langs->trans("Contract"), -1, 'contract');

@@ -169,2 +145,2 @@
-		$morehtmlref .= $form->editfieldkey("", 'ref', $object->ref, $object, $user->hasRight('contrat', 'creer'), 'string', '', 0, 3);

-		$morehtmlref .= $form->editfieldval("", 'ref', $object->ref, $object, $user->hasRight('contrat', 'creer'), 'string', '', 0, 2);

+		$morehtmlref .= $form->editfieldkey("", 'ref', $object->ref, $object, $user->rights->contrat->creer, 'string', '', 0, 3);

+		$morehtmlref .= $form->editfieldval("", 'ref', $object->ref, $object, $user->rights->contrat->creer, 'string', '', 0, 2);

@@ -184,4 +160,2 @@
-	$morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);

-	if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {

-		$morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/contrat/list.php?socid='.$object->thirdparty->id.'&search_name='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherContracts").'</a>)';

-	}

+	$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);

+	if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/contrat/list.php?socid='.$object->thirdparty->id.'&search_name='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherContracts").'</a>)';

@@ -189 +163,2 @@
-	if (isModEnabled('project')) {

+	if (!empty($conf->projet->enabled))

+	{

@@ -191,3 +166,3 @@
-		$morehtmlref .= '<br>';

-		if (0) {

-			$morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');

+		$morehtmlref .= '<br>'.$langs->trans('Project').' ';

+		if ($user->rights->contrat->creer)

+		{

@@ -195 +170,2 @@
-				$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';

+				//$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a>';

+				$morehtmlref .= ' : ';

@@ -197 +173,11 @@
-			$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');

+			if ($action == 'classify') {

+				//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);

+				$morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';

+				$morehtmlref .= '<input type="hidden" name="action" value="classin">';

+				$morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';

+				$morehtmlref .= $formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);

+				$morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';

+				$morehtmlref .= '</form>';

+			} else {

+				$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1);

+			}

@@ -202,4 +188,5 @@
-				$morehtmlref .= $proj->getNomUrl(1);

-				if ($proj->title) {

-					$morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';

-				}

+				$morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';

+				$morehtmlref .= $proj->ref;

+				$morehtmlref .= '</a>';

+			} else {

+				$morehtmlref .= '';

@@ -211 +198 @@
-	dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref);

+	dol_banner_tab($object, 'id', $linkback, 1, 'ref', 'none', $morehtmlref);

@@ -217 +204 @@
-	$object->info($object->id);

+	$object->info($id);

@@ -222 +209 @@
-	print dol_get_fiche_end();

+	dol_fiche_end();

@@ -233 +220 @@
-	if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok)

+	if ((! empty($objthirdparty->id) || ! empty($objcon->id)) && $permok)

@@ -237 +224 @@
-		$out.=(!empty($objcon->id)?'&amp;contactid='.$objcon->id:'').'&amp;backtopage=1';

+		$out.=(! empty($objcon->id)?'&amp;contactid='.$objcon->id:'').'&amp;backtopage=1&amp;percentage=-1';

@@ -249,4 +236,4 @@
-	if (isModEnabled('agenda')) {

-		if ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')) {

-			$backtopage = $_SERVER['PHP_SELF'].'?id='.$object->id;

-			$out = '&origin='.$object->element.'&originid='.$object->id.'&backtopage='.urlencode($backtopage);

+	if (!empty($conf->agenda->enabled))

+	{

+		if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create))

+		{

@@ -257 +244,2 @@
-	if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {

+	if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read)))

+	{

@@ -260,14 +248,5 @@
-		$param = '&id='.$object->id;

-		if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {

-			$param .= '&contextpage='.$contextpage;

-		}

-		if ($limit > 0 && $limit != $conf->liste_limit) {

-			$param .= '&limit='.$limit;

-		}

-

-		// Try to know count of actioncomm from cache

-		require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';

-		$cachekey = 'count_events_thirdparty_'.$object->id;

-		$nbEvent = dol_getcache($cachekey);

-

-		print load_fiche_titre($langs->trans("ActionsOnContract").(is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">('.$nbEvent.')</span>' : ''), $newcardbutton, '');

+		$param = '&id='.$id;

+		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("ActionsOnContract"), $newcardbutton, '');

@@ -279 +257,0 @@
-		$filters['search_rowid'] = $search_rowid;

--- /tmp/dsg/dolibarr/htdocs/contrat/github_19.0.3_card.php
+++ /tmp/dsg/dolibarr/htdocs/contrat/client_card.php
@@ -9 +9 @@
- * Copyright (C) 2014-2020	Ferran Marcet		  	<fmarcet@2byte.es>

+ * Copyright (C) 2014-2018	Ferran Marcet		  	<fmarcet@2byte.es>

@@ -12,3 +12 @@
- * Copyright (C) 2018-2021  Frédéric France         <frederic.france@netlogic.fr>

- * Copyright (C) 2023       Charlene Benke     		<charlene@patas-monkey.com>

- * Copyright (C) 2023       Nick Fragoulis

+ * Copyright (C) 2018       Frédéric France         <frederic.france@netlogic.fr>

@@ -45,6 +43,2 @@
-require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';

-require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';

-if (isModEnabled("propal")) {

-	require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';

-}

-if (isModEnabled('project')) {

+if (!empty($conf->propal->enabled))  require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';

+if (!empty($conf->projet->enabled)) {

@@ -59 +53 @@
-$action = GETPOST('action', 'aZ09');

+$action = GETPOST('action', 'alpha');

@@ -61,3 +54,0 @@
-$cancel = GETPOST('cancel', 'alpha');

-$backtopage = GETPOST('backtopage', 'alpha');

-

@@ -70,6 +60,0 @@
-// PDF

-$hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0));

-$hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0));

-$hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0));

-

-

@@ -77 +62 @@
-$usehm = (getDolGlobalString('MAIN_USE_HOURMIN_IN_DATE_RANGE') ? $conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE : 0);

+$usehm = (!empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? $conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE : 0);

@@ -80,3 +65,2 @@
-if ($user->socid) {

-	$socid = $user->socid;

-}

+if ($user->socid) $socid = $user->socid;

+$result = restrictedArea($user, 'contrat', $id);

@@ -93 +77 @@
-	if ($ret > 0) {

+	if ($ret > 0)

@@ -95,2 +79 @@
-	}

-	if ($ret < 0) {

+	if ($ret < 0)

@@ -98 +80,0 @@
-	}

@@ -107,9 +89,3 @@
-$permissionnote = $user->hasRight('contrat', 'creer'); // Used by the include of actions_setnotes.inc.php

-$permissiondellink = $user->hasRight('contrat', 'creer'); // Used by the include of actions_dellink.inc.php

-$permissiontodelete = ($user->hasRight('contrat', 'creer') && $object->statut == $object::STATUS_DRAFT) || $user->hasRight('contrat', 'supprimer');

-$permissiontoadd   = $user->hasRight('contrat', 'creer');     //  Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php

-$permissiontoedit = $permissiontoadd;

-$permissiontoactivate = $user->hasRight('contrat', 'activer');

-$error = 0;

-

-$result = restrictedArea($user, 'contrat', $object->id);

+$permissionnote = $user->rights->contrat->creer; // Used by the include of actions_setnotes.inc.php

+$permissiondellink = $user->rights->contrat->creer; // Used by the include of actions_dellink.inc.php

+

@@ -124,19 +100,14 @@
-if ($reshook < 0) {

-	setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

-}

-if (empty($reshook)) {

-	$backurlforlist = DOL_URL_ROOT.'/contrat/list.php';

-

-	if (empty($backtopage) || ($cancel && empty($id))) {

-		if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {

-			if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {

-				$backtopage = $backurlforlist;

-			} else {

-				$backtopage = DOL_URL_ROOT.'/contrat/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');

-			}

-		}

-	}

-

-	if ($cancel) {

-		if (!empty($backtopageforcancel)) {

-			header("Location: ".$backtopageforcancel);

+if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

+if (empty($reshook))

+{

+	include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once

+

+	include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once

+

+	if ($action == 'confirm_active' && $confirm == 'yes' && $user->rights->contrat->activer)

+	{

+		$result = $object->active_line($user, GETPOST('ligne'), GETPOST('date'), GETPOST('dateend'), GETPOST('comment'));

+

+		if ($result > 0)

+		{

+			header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);

@@ -144,14 +115,31 @@
-		} elseif (!empty($backtopage)) {

-			header("Location: ".$backtopage);

-			exit;

-		}

-		$action = '';

-	}

-

-	include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once

-

-	include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once

-

-	include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';  // Must be include, not include_once

-

-	if ($action == 'confirm_active' && $confirm == 'yes' && $permissiontoactivate) {

+		}

+		else {

+			setEventMessages($object->error, $object->errors, 'errors');

+		}

+	}

+

+	elseif ($action == 'confirm_closeline' && $confirm == 'yes' && $user->rights->contrat->activer)

+	{

+		if (!GETPOST('dateend'))

+		{

+			$error++;

+			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateEnd")), null, 'errors');

+		}

+		if (!$error)

+		{

+			$result = $object->close_line($user, GETPOST('ligne'), GETPOST('dateend'), urldecode(GETPOST('comment')));

+			if ($result > 0)

+			{

+				header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);

+				exit;

+			}

+			else

+			{

+				setEventMessages($object->error, $object->errors, 'errors');

+			}

+		}

+	}

+

+	// Si ajout champ produit predefini

+	if (GETPOST('mode') == 'predefined')

+	{

@@ -160,39 +148,2 @@
-		if (GETPOST('startmonth') && GETPOST('startday') && GETPOST('startyear')) {

-			$date_start = dol_mktime(GETPOST('starthour'), GETPOST('startmin'), 0, GETPOST('startmonth'), GETPOST('startday'), GETPOST('startyear'));

-		}

-		if (GETPOST('endmonth') && GETPOST('endday') && GETPOST('endyear')) {

-			$date_end = dol_mktime(GETPOST('endhour'), GETPOST('endmin'), 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear'));

-		}

-

-		$result = $object->active_line($user, GETPOST('ligne', 'int'), $date_start, $date_end, GETPOST('comment'));

-

-		if ($result > 0) {

-			header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);

-			exit;

-		} else {

-			setEventMessages($object->error, $object->errors, 'errors');

-		}

-	} elseif ($action == 'confirm_closeline' && $confirm == 'yes' && $permissiontoactivate) {

-		$date_end = '';

-		if (GETPOST('endmonth') && GETPOST('endday') && GETPOST('endyear')) {

-			$date_end = dol_mktime(GETPOST('endhour'), GETPOST('endmin'), 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear'));

-		}

-		if (!$date_end) {

-			$error++;

-			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateEnd")), null, 'errors');

-		}

-		if (!$error) {

-			$result = $object->close_line($user, GETPOST('ligne', 'int'), $date_end, urldecode(GETPOST('comment')));

-			if ($result > 0) {

-				header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);

-				exit;

-			} else {

-				setEventMessages($object->error, $object->errors, 'errors');

-			}

-		}

-	}

-

-	if (GETPOST('mode') == 'predefined') {

-		$date_start = '';

-		$date_end = '';

-		if (GETPOST('date_startmonth') && GETPOST('date_startday') && GETPOST('date_startyear')) {

+		if (GETPOST('date_startmonth') && GETPOST('date_startday') && GETPOST('date_startyear'))

+		{

@@ -201 +152,2 @@
-		if (GETPOST('date_endmonth') && GETPOST('date_endday') && GETPOST('date_endyear')) {

+		if (GETPOST('date_endmonth') && GETPOST('date_endday') && GETPOST('date_endyear'))

+		{

@@ -211 +163,2 @@
-	if (GETPOST('date_start_updatemonth') && GETPOST('date_start_updateday') && GETPOST('date_start_updateyear')) {

+	if (GETPOST('date_start_updatemonth') && GETPOST('date_start_updateday') && GETPOST('date_start_updateyear'))

+	{

@@ -214 +167,2 @@
-	if (GETPOST('date_end_updatemonth') && GETPOST('date_end_updateday') && GETPOST('date_end_updateyear')) {

+	if (GETPOST('date_end_updatemonth') && GETPOST('date_end_updateday') && GETPOST('date_end_updateyear'))

+	{

@@ -217 +171,2 @@
-	if (GETPOST('date_start_real_updatemonth') && GETPOST('date_start_real_updateday') && GETPOST('date_start_real_updateyear')) {

+	if (GETPOST('date_start_real_updatemonth') && GETPOST('date_start_real_updateday') && GETPOST('date_start_real_updateyear'))

+	{

@@ -220 +175,2 @@
-	if (GETPOST('date_end_real_updatemonth') && GETPOST('date_end_real_updateday') && GETPOST('date_end_real_updateyear')) {

+	if (GETPOST('date_end_real_updatemonth') && GETPOST('date_end_real_updateday') && GETPOST('date_end_real_updateyear'))

+	{

@@ -223 +179,2 @@
-	if (GETPOST('remonth') && GETPOST('reday') && GETPOST('reyear')) {

+	if (GETPOST('remonth') && GETPOST('reday') && GETPOST('reyear'))

+	{

@@ -228 +185,2 @@
-	if ($action == 'add' && $user->hasRight('contrat', 'creer')) {

+	if ($action == 'add' && $user->rights->contrat->creer)

+	{

@@ -230 +188,2 @@
-		if (empty($datecontrat)) {

+		if (empty($datecontrat))

+		{

@@ -236 +195,2 @@
-		if ($socid < 1) {

+		if ($socid < 1)

+		{

@@ -249 +209,2 @@
-		if (!$error) {

+		if (!$error)

+		{

@@ -259 +220 @@
-			$object->remise_percent = price2num(GETPOST('remise_percent'), '', 2);

+			$object->remise_percent = GETPOST('remise_percent', 'alpha');

@@ -265 +226,2 @@
-			if (!empty($origin) && !empty($originid)) {

+			if (!empty($origin) && !empty($originid))

+			{

@@ -268 +230,2 @@
-				if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {

+				if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs))

+				{

@@ -274,11 +237,2 @@
-				if ($element == 'order') {

-					$element = $subelement = 'commande';

-				}

-				if ($element == 'propal') {

-					$element = 'comm/propal';

-					$subelement = 'propal';

-				}

-				if ($element == 'invoice' || $element == 'facture') {

-					$element = 'compta/facture';

-					$subelement = 'facture';

-				}

+				if ($element == 'order') { $element = $subelement = 'commande'; }

+				if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; }

@@ -291 +245,2 @@
-				if (is_array($_POST['other_linked_objects']) && !empty($_POST['other_linked_objects'])) {

+				if (is_array($_POST['other_linked_objects']) && !empty($_POST['other_linked_objects']))

+				{

@@ -296 +251,6 @@
-				if ($id > 0) {

+				if ($id < 0) {

+					setEventMessages($object->error, $object->errors, 'errors');

+				}

+

+				if ($id > 0)

+				{

@@ -304 +264,2 @@
-					if ($result > 0) {

+					if ($result > 0)

+					{

@@ -307 +268,2 @@
-						if (empty($lines) && method_exists($srcobject, 'fetch_lines')) {

+						if (empty($lines) && method_exists($srcobject, 'fetch_lines'))

+						{

@@ -315 +277,2 @@
-						for ($i = 0; $i < $num; $i++) {

+						for ($i = 0; $i < $num; $i++)

+						{

@@ -318 +281 @@
-							if ($product_type == 1 || (getDolGlobalString('CONTRACT_SUPPORT_PRODUCTS') && in_array($product_type, array(0, 1)))) { 	// TODO Exclude also deee

+							if ($product_type == 1 || (!empty($conf->global->CONTRACT_SUPPORT_PRODUCTS) && in_array($product_type, array(0, 1)))) { 	// TODO Exclude also deee

@@ -320 +283,2 @@
-								if ($lines[$i]->fk_product > 0) {

+								if ($lines[$i]->fk_product > 0)

+								{

@@ -324 +288,2 @@
-									if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {

+									if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))

+									{

@@ -331,7 +296,4 @@
-										if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {

-											$newlang = GETPOST('lang_id', 'aZ09');

-										}

-										if (empty($newlang)) {

-											$newlang = $srcobject->thirdparty->default_lang;

-										}

-										if (!empty($newlang)) {

+										if (empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');

+										if (empty($newlang)) $newlang = $srcobject->thirdparty->default_lang;

+										if (!empty($newlang))

+										{

@@ -343 +305,3 @@
-									} else {

+									}

+									else

+									{

@@ -346,2 +310,3 @@
-									$desc = ($lines[$i]->desc && $lines[$i]->desc != $lines[$i]->label) ? dol_htmlentitiesbr($lines[$i]->desc) : '';

-								} else {

+									$desc = ($lines[$i]->desc && $lines[$i]->desc != $lines[$i]->libelle) ?dol_htmlentitiesbr($lines[$i]->desc) : '';

+								}

+								else {

@@ -382,2 +347 @@
-									$lines[$i]->fk_unit,

-									$num+1

+									$lines[$i]->fk_unit

@@ -386 +350,2 @@
-								if ($result < 0) {

+								if ($result < 0)

+								{

@@ -392 +357,3 @@
-					} else {

+					}

+					else

+					{

@@ -401,2 +368 @@
-					if ($reshook < 0) {

-						setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

+					if ($reshook < 0)

@@ -404,2 +370,3 @@
-					}

-				} else {

+				}

+				else

+				{

@@ -409,4 +376,3 @@
-				if ($error) {

-					$action = 'create';

-				}

-			} else {

+			}

+			else

+			{

@@ -414 +380,2 @@
-				if ($result > 0) {

+				if ($result > 0)

+				{

@@ -417 +384,2 @@
-				} else {

+				}

+				else {

@@ -423 +391,4 @@
-	} elseif ($action == 'classin' && $user->hasRight('contrat', 'creer')) {

+	}

+

+	elseif ($action == 'classin' && $user->rights->contrat->creer)

+	{

@@ -425,2 +396,5 @@
-	} elseif ($action == 'addline' && $user->hasRight('contrat', 'creer')) {

-		// Add a new line

+	}

+

+	// Add a new line

+	elseif ($action == 'addline' && $user->rights->contrat->creer)

+	{

@@ -429,23 +403,5 @@
-		$product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');

-

-		$price_ht = '';

-		$price_ht_devise = '';

-		$price_ttc = '';

-		$price_ttc_devise = '';

-

-		$rang = count($object->lines) + 1;

-

-		if (GETPOST('price_ht') !== '') {

-			$price_ht = price2num(GETPOST('price_ht'), 'MU', 2);

-		}

-		if (GETPOST('multicurrency_price_ht') !== '') {

-			$price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2);

-		}

-		if (GETPOST('price_ttc') !== '') {

-			$price_ttc = price2num(GETPOST('price_ttc'), 'MU', 2);

-		}

-		if (GETPOST('multicurrency_price_ttc') !== '') {

-			$price_ttc_devise = price2num(GETPOST('multicurrency_price_ttc'), 'CU', 2);

-		}

-

-		if (GETPOST('prod_entry_mode', 'alpha') == 'free') {

+		$product_desc = (GETPOST('dp_desc') ?GETPOST('dp_desc') : '');

+		$price_ht = price2num(GETPOST('price_ht'));

+		$price_ht_devise = price2num(GETPOST('multicurrency_price_ht'));

+		if (GETPOST('prod_entry_mode', 'alpha') == 'free')

+		{

@@ -453 +409,4 @@
-		} else {

+			$tva_tx = (GETPOST('tva_tx', 'alpha') ? GETPOST('tva_tx', 'alpha') : 0);

+		}

+		else

+		{

@@ -455,16 +414,8 @@
-

-			if (getDolGlobalString('MAIN_DISABLE_FREE_LINES') && $idprod <= 0) {

-				setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProductOrService")), null, 'errors');

-				$error++;

-			}

-		}

-

-		$tva_tx = GETPOST('tva_tx', 'alpha');

-

-		$qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS');

-		$remise_percent = (GETPOSTISSET('remise_percent'.$predef) ? price2num(GETPOST('remise_percent'.$predef), '', 2) : 0);

-		if (empty($remise_percent)) {

-			$remise_percent = 0;

-		}

-

-		if ($qty == '') {

+			$tva_tx = '';

+		}

+

+		$qty = price2num(GETPOST('qty'.$predef));

+		$remise_percent = ((GETPOST('remise_percent'.$predef) != '') ? GETPOST('remise_percent'.$predef) : 0);

+

+		if ($qty == '')

+		{

@@ -474 +425,2 @@
-		if (GETPOST('prod_entry_mode', 'alpha') == 'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {

+		if (GETPOST('prod_entry_mode', 'alpha') == 'free' && empty($idprod) && empty($product_desc))

+		{

@@ -479,6 +431,7 @@
-		$date_start = dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year'));

-		$date_end = dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year'));

-		if (!empty($date_start) && !empty($date_end) && $date_start > $date_end) {

-			setEventMessages($langs->trans("Error").': '.$langs->trans("DateStartPlanned").' > '.$langs->trans("DateEndPlanned"), null, 'errors');

-			$error++;

-		}

+	    $date_start = dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year'));

+	    $date_end = dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year'));

+	    if (!empty($date_start) && !empty($date_end) && $date_start > $date_end)

+	    {

+		    setEventMessages($langs->trans("Error").': '.$langs->trans("DateStartPlanned").' > '.$langs->trans("DateEndPlanned"), null, 'errors');

+		    $error++;

+	    }

@@ -497 +450,2 @@
-		if (!$error) {

+		if (!$error)

+		{

@@ -501,4 +455,8 @@
-

-			// Ecrase $tva_tx par celui du produit. TODO Remove this once vat selection is open

-			// Get and check minimum price

-			if ($idprod > 0) {

+			$price_base_type = (GETPOST('price_base_type', 'alpha') ?GETPOST('price_base_type', 'alpha') : 'HT');

+

+			// Ecrase $pu par celui du produit

+			// Ecrase $desc par celui du produit

+			// Ecrase $tva_tx par celui du produit

+			// Ecrase $base_price_type par celui du produit

+			if ($idprod > 0)

+			{

@@ -509 +467 @@
-				/*$tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id);

+				$tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id);

@@ -511,4 +469,4 @@
-				if (empty($tva_tx)) {

-				}*/

-				$tva_npr = 0;

-

+				if (empty($tva_tx)) $tva_npr = 0;

+

+				$pu_ht = $prod->price;

+				$pu_ttc = $prod->price_ttc;

@@ -516 +474 @@
-				$price_min_ttc = $prod->price_min_ttc;

+				$price_base_type = $prod->price_base_type;

@@ -519 +477,4 @@
-				if (getDolGlobalString('PRODUIT_MULTIPRICES') && $object->thirdparty->price_level) {

+				if ($conf->global->PRODUIT_MULTIPRICES && $object->thirdparty->price_level)

+				{

+					$pu_ht = $prod->multiprices[$object->thirdparty->price_level];

+					$pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];

@@ -521,3 +482,4 @@
-					$price_min_ttc = $prod->multiprices_min_ttc[$object->thirdparty->price_level];

-				} elseif (getDolGlobalString('PRODUIT_CUSTOMER_PRICES')) {

-					// If price per customer

+					$price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];

+				}

+				elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES))

+				{

@@ -526 +488 @@
-					$prodcustprice = new ProductCustomerPrice($db);

+					$prodcustprice = new Productcustomerprice($db);

@@ -530 +492 @@
-					$result = $prodcustprice->fetchAll('', '', 0, 0, $filter);

+					$result = $prodcustprice->fetch_all('', '', 0, 0, $filter);

@@ -533,6 +495,5 @@
-							$price_min =  price($prodcustprice->lines[0]->price_min);

-							$price_min_ttc =  price($prodcustprice->lines[0]->price_min_ttc);

-							/*$tva_tx = $prodcustprice->lines[0]->tva_tx;

-							if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) {

-								$tva_tx .= ' ('.$prodcustprice->lines[0]->default_vat_code.')';

-							}

+							$pu_ht = price($prodcustprice->lines [0]->price);

+							$pu_ttc = price($prodcustprice->lines [0]->price_ttc);

+							$price_base_type = $prodcustprice->lines [0]->price_base_type;

+							$tva_tx = $prodcustprice->lines [0]->tva_tx;

+							if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) $tva_tx .= ' ('.$prodcustprice->lines[0]->default_vat_code.')';

@@ -540,3 +501 @@
-							if (empty($tva_tx)) {

-								$tva_npr = 0;

-							}*/

+							if (empty($tva_tx)) $tva_npr = 0;

@@ -550,23 +509,17 @@
-				// Set unit price to use

-				if (!empty($price_ht) || $price_ht === '0') {

-					$pu_ht = price2num($price_ht, 'MU');

-					$pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU');

-					$price_base_type = 'HT';

-				} elseif (!empty($price_ttc) || $price_ttc === '0') {

-					$pu_ttc = price2num($price_ttc, 'MU');

-					$pu_ht = price2num($pu_ttc / (1 + ($tmpvat / 100)), 'MU');

-					$price_base_type = 'TTC';

-				}

-

-				$desc = $prod->description;

-

-				//If text set in desc is the same as product descpription (as now it's preloaded) whe add it only one time

-				if ($product_desc == $desc && getDolGlobalString('PRODUIT_AUTOFILL_DESC')) {

-					$product_desc = '';

-				}

-

-				if (!empty($product_desc) && getDolGlobalString('MAIN_NO_CONCAT_DESCRIPTION')) {

-					$desc = $product_desc;

-				} else {

-					$desc = dol_concatdesc($desc, $product_desc, '', getDolGlobalString('MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION'));

-				}

+				// On reevalue prix selon taux tva car taux tva transaction peut etre different

+				// de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).

+				if ($tmpvat != $tmpprodvat)

+				{

+					if ($price_base_type != 'HT')

+					{

+						$pu_ht = price2num($pu_ttc / (1 + ($tmpvat / 100)), 'MU');

+					}

+					else

+				    {

+						$pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU');

+					}

+				}

+

+			   	$desc = $prod->description;

+			   	if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) $desc = $product_desc;

+				else $desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));

@@ -575,8 +528,7 @@
-			} else {

-				$pu_ht = price2num($price_ht, 'MU');

-				$pu_ttc = price2num($price_ttc, 'MU');

-				$tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);

-				if (empty($tva_tx)) {

-					$tva_npr = 0;

-				}

-				$tva_tx = str_replace('*', '', $tva_tx);

+			}

+			else

+			{

+				$pu_ht = GETPOST('price_ht');

+				$price_base_type = 'HT';

+				$tva_tx = GETPOST('tva_tx') ?str_replace('*', '', GETPOST('tva_tx')) : 0; // tva_tx field may be disabled, so we use vat rate 0

+				$tva_npr = preg_match('/\*/', GETPOST('tva_tx')) ? 1 : 0;

@@ -585,15 +536,0 @@
-				$pu_ht_devise = price2num($price_ht_devise, 'MU');

-				$pu_ttc_devise = price2num($price_ttc_devise, 'MU');

-

-				$tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $tva_tx));

-

-				// Set unit price to use

-				if (!empty($price_ht) || $price_ht === '0') {

-					$pu_ht = price2num($price_ht, 'MU');

-					$pu_ttc = price2num($pu_ht * (1 + ((float) $tmpvat / 100)), 'MU');

-					$price_base_type = 'HT';

-				} elseif (!empty($price_ttc) || $price_ttc === '0') {

-					$pu_ttc = price2num($price_ttc, 'MU');

-					$pu_ht = price2num($pu_ttc / (1 + ((float) $tmpvat / 100)), 'MU');

-					$price_base_type = 'TTC';

-				}

@@ -606,6 +543,5 @@
-			$fk_fournprice = GETPOST('fournprice');

-			if (GETPOST('buying_price')) {

-				$pa_ht = GETPOST('buying_price');

-			} else {

-				$pa_ht = null;

-			}

+			$fk_fournprice = $_POST['fournprice'];

+			if (!empty($_POST['buying_price']))

+			  $pa_ht = $_POST['buying_price'];

+			else

+			  $pa_ht = null;

@@ -614,6 +550,5 @@
-			if ($tva_npr) {

-				$info_bits |= 0x01;

-			}

-

-			if (((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('produit', 'ignore_price_min_advance'))

-				|| !getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) && ($price_min && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min)))) {

+			if ($tva_npr) $info_bits |= 0x01;

+

+			if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance))

+				|| empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && ($price_min && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min))))

+			{

@@ -622 +557,3 @@
-			} else {

+			}

+			else

+			{

@@ -638,2 +575,2 @@
-					$fk_fournprice,

-					$pa_ht,

+		  			$fk_fournprice,

+		  			$pa_ht,

@@ -641,2 +578 @@
-					$fk_unit,

-					$rang

+					$fk_unit

@@ -646 +582,2 @@
-			if ($result > 0) {

+			if ($result > 0)

+			{

@@ -648 +585,2 @@
-				if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE') && getDolGlobalString('CONTRACT_ADDON_PDF')) {    // No generation if default type not defined

+				if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE) && !empty($conf->global->CONTRACT_ADDON_PDF))    // No generation if default type not defined

+				{

@@ -651,6 +589,2 @@
-					if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {

-						$newlang = GETPOST('lang_id', 'aZ09');

-					}

-					if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {

-						$newlang = $object->thirdparty->default_lang;

-					}

+					if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');

+					if ($conf->global->MAIN_MULTILANGS && empty($newlang))	$newlang = $object->thirdparty->default_lang;

@@ -664 +598 @@
-					$object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);

+					$object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);

@@ -698 +632,3 @@
-			} else {

+			}

+			else

+			{

@@ -702 +638,3 @@
-	} elseif ($action == 'updateline' && $user->hasRight('contrat', 'creer') && !GETPOST('cancel', 'alpha')) {

+	}

+

+	elseif ($action == 'updateline' && $user->rights->contrat->creer && !GETPOST('cancel', 'alpha')) {

@@ -704,3 +642,3 @@
-		$predef = '';

-

-		if (!empty($date_start_update) && !empty($date_end_update) && $date_start_update > $date_end_update) {

+

+		if (!empty($date_start_update) && !empty($date_end_update) && $date_start_update > $date_end_update)

+		{

@@ -713 +651,2 @@
-		if (!$error) {

+		if (!$error)

+		{

@@ -715 +654,2 @@
-			if ($objectline->fetch(GETPOST('elrowid', 'int')) < 0) {

+			if ($objectline->fetch(GETPOST('elrowid', 'int')) < 0)

+			{

@@ -720,2 +659,0 @@
-

-			$objectline->oldcopy = dol_clone($objectline);

@@ -726,9 +664,6 @@
-		if (!$error) {

-			if ($date_start_real_update == '') {

-				$date_start_real_update = $objectline->date_start_real;

-			}

-			if ($date_end_real_update == '') {

-				$date_end_real_update = $objectline->date_end_real;

-			}

-

-			$vat_rate = GETPOST('eltva_tx', 'alpha');

+		if (!$error)

+		{

+			if ($date_start_real_update == '') $date_start_real_update = $objectline->date_ouverture;

+			if ($date_end_real_update == '')   $date_end_real_update = $objectline->date_cloture;

+

+			$vat_rate = GETPOST('eltva_tx');

@@ -737,3 +672,2 @@
-			if (preg_match('/\*/', $vat_rate)) {

-				$info_bits |= 0x01;

-			}

+			if (preg_match('/\*/', $vat_rate))

+				  $info_bits |= 0x01;

@@ -751,3 +685,4 @@
-			if (preg_match('/\((.*)\)/', $txtva, $reg)) {

-				$vat_src_code = $reg[1];

-				$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.

+			if (preg_match('/\((.*)\)/', $txtva, $reg))

+			{

+				  $vat_src_code = $reg[1];

+				  $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.

@@ -757,5 +692,5 @@
-			if (GETPOST('buying_price')) {

-				$pa_ht = price2num(GETPOST('buying_price'), '', 2);

-			} else {

-				$pa_ht = null;

-			}

+			$fk_fournprice = $_POST['fournprice'];

+			if (!empty($_POST['buying_price']))

+			  $pa_ht = $_POST['buying_price'];

+			else

+			  $pa_ht = null;

@@ -765,15 +700,5 @@
-			// update price_ht with discount

-			// TODO Use object->updateline instead objedtline->update

-

-			$price_ht =  price2num(GETPOST('elprice'), 'MU');

-			$remise_percent = price2num(GETPOST('elremise_percent'), '', 2);

-			if ($remise_percent > 0) {

-				$remise = round(($price_ht * $remise_percent / 100), 2);

-			}

-

-			$objectline->fk_product = GETPOST('idprod', 'int');

-			$objectline->description = GETPOST('product_desc', 'restricthtml');

-			$objectline->price_ht = $price_ht;

-			$objectline->subprice = price2num(GETPOST('elprice'), 'MU');

-			$objectline->qty = price2num(GETPOST('elqty'), 'MS');

-			$objectline->remise_percent = $remise_percent;

+			$objectline->description = GETPOST('product_desc', 'none');

+			$objectline->price_ht = GETPOST('elprice');

+			$objectline->subprice = GETPOST('elprice');

+			$objectline->qty = GETPOST('elqty');

+			$objectline->remise_percent = GETPOST('elremise_percent');

@@ -784,6 +709,6 @@
-			$objectline->date_start = $date_start_update;

-			$objectline->date_start_real = $date_start_real_update;

-			$objectline->date_end = $date_end_update;

-			$objectline->date_end_real = $date_end_real_update;

-			$objectline->user_closing_id = $user->id;

-			//$objectline->fk_fournprice = $fk_fournprice;

+			$objectline->date_ouverture_prevue = $date_start_update;

+			$objectline->date_ouverture = $date_start_real_update;

+			$objectline->date_fin_validite = $date_end_update;

+			$objectline->date_cloture = $date_end_real_update;

+			$objectline->fk_user_cloture = $user->id;

+			$objectline->fk_fournprice = $fk_fournprice;

@@ -791 +715,0 @@
-			$objectline->rang = $objectline->rang;

@@ -794 +718 @@
-				$objectline->fk_unit = GETPOST('unit');

+			    $objectline->fk_unit = GETPOST('unit');

@@ -796 +720 @@
-				$objectline->fk_unit = null;

+			    $objectline->fk_unit = null;

@@ -813 +737,2 @@
-			if ($result < 0) {

+			if ($result < 0)

+			{

@@ -815,2 +739,0 @@
-				$action = 'editline';

-				$_GET['rowid'] = GETPOST('elrowid');

@@ -821 +744,2 @@
-		if (!$error) {

+		if (!$error)

+		{

@@ -823 +747,3 @@
-		} else {

+		}

+		else

+		{

@@ -826,4 +752,8 @@
-	} elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->hasRight('contrat', 'creer')) {

-		$result = $object->deleteline(GETPOST('lineid', 'int'), $user);

-

-		if ($result >= 0) {

+	}

+

+	elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->contrat->creer)

+	{

+		$result = $object->deleteline(GETPOST('lineid'), $user);

+

+		if ($result >= 0)

+		{

@@ -832 +762,3 @@
-		} else {

+		}

+		else

+		{

@@ -835 +767,4 @@
-	} elseif ($action == 'confirm_valid' && $confirm == 'yes' && $user->hasRight('contrat', 'creer')) {

+	}

+

+	elseif ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->contrat->creer)

+	{

@@ -838 +773,2 @@
-		if ($result > 0) {

+		if ($result > 0)

+		{

@@ -840 +776,2 @@
-			if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {

+			if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))

+			{

@@ -843,6 +780,2 @@
-				if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {

-					$newlang = GETPOST('lang_id', 'aZ09');

-				}

-				if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {

-					$newlang = $object->thirdparty->default_lang;

-				}

+				if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');

+				if ($conf->global->MAIN_MULTILANGS && empty($newlang))	$newlang = $object->thirdparty->default_lang;

@@ -853 +786 @@
-				$model = $object->model_pdf;

+				$model = $object->modelpdf;

@@ -858 +791,3 @@
-		} else {

+		}

+		else

+		{

@@ -861 +796,4 @@
-	} elseif ($action == 'reopen' && $user->hasRight('contrat', 'creer')) {

+	}

+

+	elseif ($action == 'reopen' && $user->rights->contrat->creer)

+	{

@@ -863 +801,2 @@
-		if ($result < 0) {

+		if ($result < 0)

+		{

@@ -866,2 +805,5 @@
-	} elseif ($action == 'confirm_close' && $confirm == 'yes' && $user->hasRight('contrat', 'creer')) {

-		// Close all lines

+	}

+

+	// Close all lines

+	elseif ($action == 'confirm_close' && $confirm == 'yes' && $user->rights->contrat->creer)

+	{

@@ -869 +811,2 @@
-		if ($result < 0) {

+		if ($result < 0)

+		{

@@ -872,6 +815,8 @@
-	} elseif ($action == 'confirm_activate' && $confirm == 'yes' && $user->hasRight('contrat', 'creer')) {

-		$date_start = dol_mktime(12, 0, 0, GETPOST('d_startmonth'), GETPOST('d_startday'), GETPOST('d_startyear'));

-		$date_end   = dol_mktime(12, 0, 0, GETPOST('d_endmonth'), GETPOST('d_endday'), GETPOST('d_endyear'));

-		$comment      = GETPOST('comment', 'alpha');

-		$result = $object->activateAll($user, $date_start, 0, $comment, $date_end);

-		if ($result < 0) {

+	}

+

+	// Close all lines

+	elseif ($action == 'confirm_activate' && $confirm == 'yes' && $user->rights->contrat->creer)

+	{

+		$result = $object->activateAll($user);

+		if ($result < 0)

+		{

@@ -880 +825,4 @@
-	} elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('contrat', 'supprimer')) {

+	}

+

+	elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->contrat->supprimer)

+	{

@@ -882 +830,2 @@
-		if ($result >= 0) {

+		if ($result >= 0)

+		{

@@ -885 +834,3 @@
-		} else {

+		}

+		else

+		{

@@ -888,2 +839,6 @@
-	} elseif ($action == 'confirm_move' && $confirm == 'yes' && $user->hasRight('contrat', 'creer')) {

-		if (GETPOST('newcid') > 0) {

+	}

+

+	elseif ($action == 'confirm_move' && $confirm == 'yes' && $user->rights->contrat->creer)

+	{

+		if (GETPOST('newcid') > 0)

+		{

@@ -891,2 +846,2 @@
-			$result = $contractline->fetch(GETPOSTINT('lineid'));

-			$contractline->fk_contrat = GETPOSTINT('newcid');

+			$result = $contractline->fetch(GETPOST('lineid'));

+			$contractline->fk_contrat = GETPOST('newcid');

@@ -894 +849,2 @@
-			if ($result >= 0) {

+			if ($result >= 0)

+			{

@@ -897 +853,3 @@
-			} else {

+			}

+			else

+			{

@@ -900 +858,3 @@
-		} else {

+		}

+		else

+		{

@@ -903,4 +863,4 @@
-	} elseif ($action == 'update_extras' && $permissiontoadd) {

-		$object->oldcopy = dol_clone($object, 2);

-

-		$attribute = GETPOST('attribute', 'alphanohtml');

+	}

+	elseif ($action == 'update_extras')

+	{

+		$object->oldcopy = dol_clone($object);

@@ -909,5 +869,2 @@
-		$ret = $extrafields->setOptionalsFromPost(null, $object, $attribute);

-		if ($ret < 0) {

-			setEventMessages($extrafields->error, $object->errors, 'errors');

-			$error++;

-		}

+		$ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'none'));

+		if ($ret < 0) $error++;

@@ -916,2 +873,3 @@
-			$result = $object->updateExtraField($attribute, 'CONTRACT_MODIFY');

-			if ($result < 0) {

+			$result = $object->insertExtraFields('CONTRACT_MODIFY');

+			if ($result < 0)

+			{

@@ -926,3 +884,6 @@
-	} elseif ($action == 'setref_supplier' && $permissiontoadd) {

-		if (!$cancel) {

-			$object->oldcopy = dol_clone($object, 2);

+	}

+	elseif ($action == 'setref_supplier')

+	{

+		$cancelbutton = GETPOST('cancel', 'alpha');

+		if (!$cancelbutton) {

+			$object->oldcopy = dol_clone($object);

@@ -938 +899,2 @@
-		} else {

+		}

+		else {

@@ -942,3 +904,8 @@
-	} elseif ($action == 'setref_customer' && $permissiontoadd) {

-		if (!$cancel) {

-			$object->oldcopy = dol_clone($object, 2);

+	}

+	elseif ($action == 'setref_customer')

+	{

+		$cancelbutton = GETPOST('cancel', 'alpha');

+

+		if (!$cancelbutton)

+		{

+			$object->oldcopy = dol_clone($object);

@@ -954 +921,2 @@
-		} else {

+		}

+		else {

@@ -958,2 +926,6 @@
-	} elseif ($action == 'setref' && $permissiontoadd) {

-		if (!$cancel) {

+	}

+	elseif ($action == 'setref')

+	{

+		$cancelbutton = GETPOST('cancel', 'alpha');

+

+		if (!$cancelbutton) {

@@ -967,5 +939,5 @@
-			$result = $object->setValueFrom('ref', GETPOST('ref', 'alpha'), '', null, 'text', '', $user, 'CONTRACT_MODIFY');

-			if ($result < 0) {

-				setEventMessages($object->error, $object->errors, 'errors');

-				$action = 'editref';

-			} else {

+	        $result = $object->setValueFrom('ref', GETPOST('ref', 'alpha'), '', null, 'text', '', $user, 'CONTRACT_MODIFY');

+	        if ($result < 0) {

+	            setEventMessages($object->error, $object->errors, 'errors');

+	            $action = 'editref';

+	        } else {

@@ -973,15 +945,27 @@
-				$old_filedir = $conf->contrat->multidir_output[$object->entity].'/'.dol_sanitizeFileName($old_ref);

-				$new_filedir = $conf->contrat->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);

-

-				// Rename directory of contract with new name

-				dol_move_dir($old_filedir, $new_filedir);

-

-				header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);

-				exit;

-			}

-		} else {

-			header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);

-			exit;

-		}

-	} elseif ($action == 'setdate_contrat' && $permissiontoadd) {

-		if (!$cancel) {

+				$old_filedir = $conf->contrat->dir_output.'/'.dol_sanitizeFileName($old_ref);

+				$new_filedir = $conf->contrat->dir_output.'/'.dol_sanitizeFileName($object->ref);

+

+				$files = dol_dir_list($old_filedir);

+				if (!empty($files))

+				{

+					if (!is_dir($new_filedir)) dol_mkdir($new_filedir);

+					foreach ($files as $file)

+					{

+						dol_move($file['fullname'], $new_filedir.'/'.$file['name']);

+					}

+				}

+

+	            header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);

+	            exit;

+	        }

+	    }

+	    else {

+	        header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);

+	        exit;

+	    }

+	}

+	elseif ($action == 'setdate_contrat')

+	{

+		$cancelbutton = GETPOST('cancel', 'alpha');

+

+		if (!$cancelbutton) {

@@ -1001 +985,2 @@
-		} else {

+		}

+		else {

@@ -1007,2 +991,0 @@
-	// Actions when printing a doc from card

-	include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';

@@ -1011 +994,2 @@
-	$upload_dir = $conf->contrat->multidir_output[!empty($object->entity) ? $object->entity : $conf->entity];

+	$upload_dir = $conf->contrat->dir_output;

+	$permissiontoadd = $user->rights->contrat->creer;

@@ -1022,2 +1006,4 @@
-	if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB') && $user->hasRight('contrat', 'creer')) {

-		if ($action == 'addcontact') {

+	if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->contrat->creer)

+	{

+		if ($action == 'addcontact')

+		{

@@ -1025,4 +1011,4 @@
-			$typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));

-			$result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));

-

-			if ($result >= 0) {

+			$result = $object->add_contact($contactid, GETPOST('type'), GETPOST('source'));

+

+			if ($result >= 0)

+			{

@@ -1031,2 +1017,5 @@
-			} else {

-				if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {

+			}

+			else

+			{

+				if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')

+				{

@@ -1035 +1024,3 @@
-				} else {

+				}

+				else

+				{

@@ -1039,8 +1030,15 @@
-		} elseif ($action == 'swapstatut') {

-			// bascule du statut d'un contact

-			$result = $object->swapContactStatus(GETPOST('ligne', 'int'));

-		} elseif ($action == 'deletecontact') {

-			// Efface un contact

-			$result = $object->delete_contact(GETPOST('lineid', 'int'));

-

-			if ($result >= 0) {

+		}

+

+		// bascule du statut d'un contact

+		elseif ($action == 'swapstatut')

+		{

+			$result = $object->swapContactStatus(GETPOST('ligne'));

+		}

+

+		// Efface un contact

+		elseif ($action == 'deletecontact')

+		{

+			$result = $object->delete_contact(GETPOST('lineid'));

+

+			if ($result >= 0)

+			{

@@ -1049 +1047,2 @@
-			} else {

+			}

+			else {

@@ -1056,2 +1055,4 @@
-	if ($action == 'confirm_clone' && $confirm == 'yes') {

-		if (!GETPOST('socid', 3)) {

+	if ($action == 'confirm_clone' && $confirm == 'yes')

+	{

+		if (!GETPOST('socid', 3))

+		{

@@ -1059 +1060,3 @@
-		} else {

+		}

+		else

+		{

@@ -1066,3 +1069 @@
-					if (count($object->errors) > 0) {

-						setEventMessages($object->error, $object->errors, 'errors');

-					}

+					if (count($object->errors) > 0) setEventMessages($object->error, $object->errors, 'errors');

@@ -1081,8 +1082 @@
-$help_url = 'EN:Module_Contracts|FR:Module_Contrat';

-

-$title = $object->ref." - ".$langs->trans('Contract');

-if ($action == 'create') {

-	$title = $langs->trans("NewContract");

-}

-

-llxHeader('', $title, $help_url);

+llxHeader('', $langs->trans("Contract"), "");

@@ -1092,3 +1086 @@
-if (isModEnabled('project')) {

-	$formproject = new FormProjets($db);

-}

+if (!empty($conf->projet->enabled)) $formproject = new FormProjets($db);

@@ -1097,2 +1089,3 @@
-$module = (getDolGlobalString('CONTRACT_ADDON') ? $conf->global->CONTRACT_ADDON : 'mod_contract_serpis');

-if (substr($module, 0, 13) == 'mod_contract_' && substr($module, -3) == 'php') {

+$module = (!empty($conf->global->CONTRACT_ADDON) ? $conf->global->CONTRACT_ADDON : 'mod_contract_serpis');

+if (substr($module, 0, 13) == 'mod_contract_' && substr($module, -3) == 'php')

+{

@@ -1102 +1095,2 @@
-if ($result > 0) {

+if ($result > 0)

+{

@@ -1107,3 +1101,3 @@
-if ($action == 'create') {

-	$objectsrc = null;

-	print load_fiche_titre($langs->trans('NewContract'), '', 'contract');

+if ($action == 'create')

+{

+	print load_fiche_titre($langs->trans('AddContract'), '', 'contract');

@@ -1112,5 +1106,4 @@
-	if ($socid > 0) {

-		$soc->fetch($socid);

-	}

-

-	if (GETPOST('origin') && GETPOST('originid', 'int')) {

+	if ($socid > 0) $soc->fetch($socid);

+

+	if (GETPOST('origin') && GETPOST('originid'))

+	{

@@ -1120 +1113,2 @@
-		if (preg_match('/^([^_]+)_([^_]+)/i', GETPOST('origin'), $regs)) {

+		if (preg_match('/^([^_]+)_([^_]+)/i', GETPOST('origin'), $regs))

+		{

@@ -1125,3 +1119,6 @@
-		if ($element == 'project') {

-			$projectid = GETPOST('originid', 'int');

-		} else {

+		if ($element == 'project')

+		{

+			$projectid = GETPOST('originid');

+		}

+		else

+		{

@@ -1129,11 +1126,2 @@
-			if ($element == 'order' || $element == 'commande') {

-				$element = $subelement = 'commande';

-			}

-			if ($element == 'propal') {

-				$element = 'comm/propal';

-				$subelement = 'propal';

-			}

-			if ($element == 'invoice' || $element == 'facture') {

-				$element = 'compta/facture';

-				$subelement = 'facture';

-			}

+			if ($element == 'order' || $element == 'commande') { $element = $subelement = 'commande'; }

+			if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; }

@@ -1146,3 +1134 @@
-			if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) {

-				$objectsrc->fetch_lines();

-			}

+			if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines'))  $objectsrc->fetch_lines();

@@ -1165 +1151,2 @@
-	} else {

+	}

+	else {

@@ -1174,0 +1162 @@
+

@@ -1178,3 +1166,2 @@
-	print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';

-

-	print dol_get_fiche_head();

+

+	dol_fiche_head();

@@ -1189 +1176 @@
-		$tmpcode = '<input name="ref" class="maxwidth100" maxlength="128" value="'.dol_escape_htmltag(GETPOST('ref') ? GETPOST('ref') : $tmpcode).'">';

+		$tmpcode = '<input name="ref" class="maxwidth100" maxlength="128" value="'.dol_escape_htmltag(GETPOST('ref') ?GETPOST('ref') : $tmpcode).'">';

@@ -1205 +1192,2 @@
-	if ($socid > 0) {

+	if ($socid > 0)

+	{

@@ -1210 +1198,3 @@
-	} else {

+	}

+	else

+	{

@@ -1212,2 +1202 @@
-		print img_picto('', 'company', 'class="pictofixedwidth"');

-		print $form->select_company('', 'socid', '', 'SelectThirdParty', 1, 0, null, 0, 'minwidth300 widthcentpercentminusxx maxwidth500');

+		print $form->select_company('', 'socid', '', 'SelectThirdParty', 1, 0, null, 0, 'minwidth300');

@@ -1219 +1208,2 @@
-	if ($socid > 0) {

+	if ($socid > 0)

+	{

@@ -1222,5 +1212,3 @@
-		if ($soc->remise_percent) {

-			print $langs->trans("CompanyHasRelativeDiscount", $soc->remise_percent).' ';

-		} else {

-			print '<span class="hideonsmartphone">'.$langs->trans("CompanyHasNoRelativeDiscount").'. </span>';

-		}

+		if ($soc->remise_percent) print $langs->trans("CompanyHasRelativeDiscount", $soc->remise_percent);

+		else print $langs->trans("CompanyHasNoRelativeDiscount");

+		print '. ';

@@ -1228,5 +1216,3 @@
-		if ($absolute_discount) {

-			print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency)).'.';

-		} else {

-			print '<span class="hideonsmartphone">'.$langs->trans("CompanyHasNoAbsoluteDiscount").'.</span>';

-		}

+		if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency));

+		else print $langs->trans("CompanyHasNoAbsoluteDiscount");

+		print '.';

@@ -1238,2 +1224 @@
-	print img_picto('', 'user', 'class="pictofixedwidth"');

-	print $form->select_dolusers(GETPOST("commercial_suivi_id") ? GETPOST("commercial_suivi_id") : $user->id, 'commercial_suivi_id', 1, '');

+	print $form->select_dolusers(GETPOST("commercial_suivi_id") ?GETPOST("commercial_suivi_id") : $user->id, 'commercial_suivi_id', 1, '');

@@ -1244,2 +1229 @@
-	print img_picto('', 'user', 'class="pictofixedwidth"');

-	print $form->select_dolusers(GETPOST("commercial_signature_id") ? GETPOST("commercial_signature_id") : $user->id, 'commercial_signature_id', 1, '');

+	print $form->select_dolusers(GETPOST("commercial_signature_id") ?GETPOST("commercial_signature_id") : $user->id, 'commercial_signature_id', 1, '');

@@ -1249 +1232,0 @@
-	print img_picto('', 'action', 'class="pictofixedwidth"');

@@ -1254 +1237,2 @@
-	if (isModEnabled('project')) {

+	if (!empty($conf->projet->enabled))

+	{

@@ -1260 +1243,0 @@
-		print img_picto('', 'project', 'class="pictofixedwidth"');

@@ -1267 +1250 @@
-	$doleditor = new DolEditor('note_public', $note_public, '', '100', 'dolibarr_notes', 'In', 1, true, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3, '90%');

+	$doleditor = new DolEditor('note_public', $note_public, '', '100', 'dolibarr_notes', 'In', 1, true, true, ROWS_3, '90%');

@@ -1271 +1254,2 @@
-	if (empty($user->socid)) {

+	if (empty($user->socid))

+	{

@@ -1273 +1257 @@
-		$doleditor = new DolEditor('note_private', $note_private, '', '100', 'dolibarr_notes', 'In', 1, true, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3, '90%');

+		$doleditor = new DolEditor('note_private', $note_private, '', '100', 'dolibarr_notes', 'In', 1, true, true, ROWS_3, '90%');

@@ -1285 +1269 @@
-		print $object->showOptionals($extrafields, 'create', $parameters);

+		print $object->showOptionals($extrafields, 'edit', $parameters);

@@ -1290,5 +1274,10 @@
-	print dol_get_fiche_end();

-

-	print $form->buttonsSaveCancel("Create");

-

-	if (is_object($objectsrc)) {

+	dol_fiche_end();

+

+	print '<div class="center">';

+	print '<input type="submit" class="button" value="'.$langs->trans("Create").'">';

+	print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';

+	print '<input type="button" class="button" value="'.$langs->trans("Cancel").'" onClick="javascript:history.go(-1)">';

+	print '</div>';

+

+	if (is_object($objectsrc))

+	{

@@ -1298 +1287,2 @@
-		if (!getDolGlobalString('CONTRACT_SUPPORT_PRODUCTS')) {

+		if (empty($conf->global->CONTRACT_SUPPORT_PRODUCTS))

+		{

@@ -1304,2 +1294,8 @@
-} else {

-	// View and edit mode

+}

+else

+/* *************************************************************************** */

+/*                                                                             */

+/* Mode vue et edition                                                         */

+/*                                                                             */

+/* *************************************************************************** */

+{

@@ -1308 +1304,2 @@
-	if ($object->id > 0) {

+	if ($object->id > 0)

+	{

@@ -1315,2 +1312,2 @@
-			dol_print_error($db, $object->error);

-		}

+            dol_print_error($db, $object->error);

+        }

@@ -1331,57 +1328,53 @@
-		$hselected = 0;

-		$formconfirm = '';

-

-		print dol_get_fiche_head($head, $hselected, $langs->trans("Contract"), -1, 'contract');

-

-

-		if ($action == 'delete') {

-			//Confirmation de la suppression du contrat

-			$formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id, $langs->trans("DeleteAContract"), $langs->trans("ConfirmDeleteAContract"), "confirm_delete", '', 0, 1);

-		} elseif ($action == 'valid') {

-			//Confirmation de la validation

-			$ref = substr($object->ref, 1, 4);

-			if ($ref == 'PROV' && !empty($modCodeContract->code_auto)) {

-				$numref = $object->getNextNumRef($object->thirdparty);

-			} else {

-				$numref = $object->ref;

-			}

-			$text = $langs->trans('ConfirmValidateContract', $numref);

-			$formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id, $langs->trans("ValidateAContract"), $text, "confirm_valid", '', 0, 1);

-		} elseif ($action == 'close') {

-			// Confirmation de la fermeture

-			$formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id, $langs->trans("CloseAContract"), $langs->trans("ConfirmCloseContract"), "confirm_close", '', 0, 1);

-		} elseif ($action == 'activate') {

-			$formquestion = array(

-				array('type' => 'date', 'name' => 'd_start', 'label' => $langs->trans("DateServiceActivate"), 'value' => dol_now()),

-				array('type' => 'date', 'name' => 'd_end', 'label' => $langs->trans("DateEndPlanned"), /*'value' => $form->selectDate('', "end", $usehm, $usehm, '', "active", 1, 0),*/ '', ''),

-				array('type' => 'text', 'name' => 'comment', 'label' => $langs->trans("Comment"), 'value' => '', '', '', 'class' => 'minwidth300', 'moreattr'=>'autofocus')

-			);

-			$formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id, $langs->trans("ActivateAllOnContract"), $langs->trans("ConfirmActivateAllOnContract"), "confirm_activate", $formquestion, 'yes', 1, 280);

-		} elseif ($action == 'clone') {

-			$filter = '(s.client:IN:1,2,3)';

-			// Clone confirmation

-			$formquestion = array(array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $form->select_company(GETPOST('socid', 'int'), 'socid', $filter)));

-			$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneContract', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);

-		}

-

-

-		// Call Hook formConfirm

-		$parameters = array(

-			'formConfirm' => $formconfirm,

-			'id' => $id,

-			//'lineid' => $lineid,

-		);

-		// Note that $action and $object may have been modified by hook

-		$reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action);

-		if (empty($reshook)) {

-			$formconfirm .= $hookmanager->resPrint;

-		} elseif ($reshook > 0) {

-			$formconfirm = $hookmanager->resPrint;

-		}

-

-		// Print form confirm

-		print $formconfirm;

-

-

-		// Contract

-		if ($object->status == $object::STATUS_DRAFT && $user->hasRight('contrat', 'creer')) {

+        $hselected = 0;

+        $formconfirm = '';

+

+        dol_fiche_head($head, $hselected, $langs->trans("Contract"), -1, 'contract');

+

+

+        if ($action == 'delete') {

+            //Confirmation de la suppression du contrat

+            $formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id, $langs->trans("DeleteAContract"), $langs->trans("ConfirmDeleteAContract"), "confirm_delete", '', 0, 1);

+        } elseif ($action == 'valid') {

+            //Confirmation de la validation

+            $ref = substr($object->ref, 1, 4);

+            if ($ref == 'PROV' && !empty($modCodeContract->code_auto)) {

+                $numref = $object->getNextNumRef($object->thirdparty);

+            } else {

+                $numref = $object->ref;

+            }

+            $text = $langs->trans('ConfirmValidateContract', $numref);

+            $formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id, $langs->trans("ValidateAContract"), $text, "confirm_valid", '', 0, 1);

+        } elseif ($action == 'close') {

+            // Confirmation de la fermeture

+            $formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id, $langs->trans("CloseAContract"), $langs->trans("ConfirmCloseContract"), "confirm_close", '', 0, 1);

+        } elseif ($action == 'activate') {

+            $formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id, $langs->trans("ActivateAllOnContract"), $langs->trans("ConfirmActivateAllOnContract"), "confirm_activate", '', 0, 1);

+        } elseif ($action == 'clone') {

+            // Clone confirmation

+            $formquestion = array(array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $form->select_company(GETPOST('socid', 'int'), 'socid', '(s.client=1 OR s.client=2 OR s.client=3)')));

+            $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneContract', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);

+        }

+

+

+        // Call Hook formConfirm

+        $parameters = array(

+        	'formConfirm' => $formconfirm,

+            'id' => $id,

+            //'lineid' => $lineid,

+        );

+        // Note that $action and $object may have been modified by hook

+        $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action);

+        if (empty($reshook)) {

+            $formconfirm .= $hookmanager->resPrint;

+        } elseif ($reshook > 0) {

+            $formconfirm = $hookmanager->resPrint;

+        }

+

+        // Print form confirm

+        print $formconfirm;

+

+        /*

+         *   Contrat

+         */

+		if (!empty($object->brouillon) && $user->rights->contrat->creer)

+		{

@@ -1391 +1383,0 @@
-			print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';

@@ -1403,2 +1395,2 @@
-			$morehtmlref .= $form->editfieldkey("", 'ref', $object->ref, $object, $user->hasRight('contrat', 'creer'), 'string', '', 0, 3);

-			$morehtmlref .= $form->editfieldval("", 'ref', $object->ref, $object, $user->hasRight('contrat', 'creer'), 'string', '', 0, 2);

+			$morehtmlref .= $form->editfieldkey("", 'ref', $object->ref, $object, $user->rights->contrat->creer, 'string', '', 0, 3);

+			$morehtmlref .= $form->editfieldval("", 'ref', $object->ref, $object, $user->rights->contrat->creer, 'string', '', 0, 2);

@@ -1409,2 +1401,2 @@
-		$morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->hasRight('contrat', 'creer'), 'string', '', 0, 1);

-		$morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->hasRight('contrat', 'creer'), 'string'.(isset($conf->global->THIRDPARTY_REF_INPUT_SIZE) ? ':' . getDolGlobalString('THIRDPARTY_REF_INPUT_SIZE') : ''), '', null, null, '', 1, 'getFormatedCustomerRef');

+		$morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->rights->contrat->creer, 'string', '', 0, 1);

+		$morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->rights->contrat->creer, 'string', '', null, null, '', 1, 'getFormatedCustomerRef');

@@ -1413,2 +1405,2 @@
-		$morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->hasRight('contrat', 'creer'), 'string', '', 0, 1);

-		$morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->hasRight('contrat', 'creer'), 'string', '', null, null, '', 1, 'getFormatedSupplierRef');

+		$morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->contrat->creer, 'string', '', 0, 1);

+		$morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->contrat->creer, 'string', '', null, null, '', 1, 'getFormatedSupplierRef');

@@ -1416,4 +1408,2 @@
-		$morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);

-		if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {

-			$morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/contrat/list.php?socid='.$object->thirdparty->id.'&search_name='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherContracts").'</a>)';

-		}

+		$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);

+		if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/contrat/list.php?socid='.$object->thirdparty->id.'&search_name='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherContracts").'</a>)';

@@ -1421 +1411,2 @@
-		if (isModEnabled('project')) {

+		if (!empty($conf->projet->enabled))

+		{

@@ -1423,3 +1414,3 @@
-			$morehtmlref .= '<br>';

-			if ($permissiontoadd) {

-				$morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');

+			$morehtmlref .= '<br>'.$langs->trans('Project').' ';

+			if ($user->rights->contrat->creer)

+			{

@@ -1427,3 +1418,13 @@
-					$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';

-				}

-				$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');

+					$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';

+				}

+				if ($action == 'classify') {

+					//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);

+					$morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';

+					$morehtmlref .= '<input type="hidden" name="action" value="classin">';

+					$morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';

+					$morehtmlref .= $formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);

+					$morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';

+					$morehtmlref .= '</form>';

+				} else {

+					$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1);

+				}

@@ -1434,4 +1435,5 @@
-					$morehtmlref .= $proj->getNomUrl(1);

-					if ($proj->title) {

-						$morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';

-					}

+					$morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';

+					$morehtmlref .= $proj->ref;

+					$morehtmlref .= '</a>';

+				} else {

+					$morehtmlref .= '';

@@ -1455,5 +1457,2 @@
-		if ($object->thirdparty->remise_percent) {

-			print $langs->trans("CompanyHasRelativeDiscount", $object->thirdparty->remise_percent).'. ';

-		} else {

-			print '<span class="hideonsmartphone">'.$langs->trans("CompanyHasNoRelativeDiscount").'. </span>';

-		}

+		if ($object->thirdparty->remise_percent) print $langs->trans("CompanyHasRelativeDiscount", $object->thirdparty->remise_percent);

+		else print $langs->trans("CompanyHasNoRelativeDiscount");

@@ -1461,5 +1460,4 @@
-		if ($absolute_discount) {

-			print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency)).'.';

-		} else {

-			print '<span class="hideonsmartphone">'.$langs->trans("CompanyHasNoAbsoluteDiscount").'.</span>';

-		}

+		print '. ';

+		if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency));

+		else print $langs->trans("CompanyHasNoAbsoluteDiscount");

+		print '.';

@@ -1471 +1469 @@
-		print $form->editfieldkey("Date", 'date_contrat', $object->date_contrat, $object, $user->hasRight('contrat', 'creer'));

+		print $form->editfieldkey("Date", 'date_contrat', $object->date_contrat, $object, $user->rights->contrat->creer);

@@ -1473 +1471 @@
-		print $form->editfieldval("Date", 'date_contrat', $object->date_contrat, $object, $user->hasRight('contrat', 'creer'), 'datehourpicker');

+		print $form->editfieldval("Date", 'date_contrat', $object->date_contrat, $object, $user->rights->contrat->creer, 'datehourpicker');

@@ -1485 +1483,2 @@
-		if ($object->status == $object::STATUS_DRAFT && $user->hasRight('contrat', 'creer')) {

+		if (!empty($object->brouillon) && $user->rights->contrat->creer)

+		{

@@ -1491 +1490,2 @@
-		if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {

+		if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))

+		{

@@ -1497 +1497,2 @@
-		if (getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {

+		if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB))

+		{

@@ -1504 +1505 @@
-		$arrayothercontracts = $object->getListOfContracts('others');	// array or -1 if technical error

+		$arrayothercontracts = $object->getListOfContracts('others');

@@ -1507,7 +1508,2 @@
-		 * Lines of contracts

-		 */

-

-		// Add products/services form

-		//$forceall = 1;

-		global $inputalsopricewithtax;

-		$inputalsopricewithtax = 1;

+         * Lines of contracts

+         */

@@ -1518,3 +1514,3 @@
-		if (isModEnabled('margin') && !empty($object->element) && in_array($object->element, array('facture', 'propal', 'commande'))) {

-			$usemargins = 1;

-		}

+		if (!empty($conf->margin->enabled) && !empty($object->element) && in_array($object->element, array('facture', 'propal', 'commande'))) $usemargins = 1;

+

+		$var = false;

@@ -1524,4 +1520,3 @@
-

-

-		print '<div id="contrat-lines-container"  id="contractlines" data-contractid="'.$object->id.'"  data-element="'.$object->element.'" >';

-		while ($cursorline <= $nbofservices) {

+		print '<div id="contrat-lines-container" data-contractid="'.$object->id.'"  data-element="'.$object->element.'" >';

+		while ($cursorline <= $nbofservices)

+		{

@@ -1529 +1524 @@
-			print '<form name="update" id="addproduct" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="post">';

+			print '<form name="update" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="post">';

@@ -1532 +1526,0 @@
-			print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';

@@ -1533,0 +1528 @@
+			print '<input type="hidden" name="idprod" value="'.(!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0).'">';

@@ -1538 +1533 @@
-			print '<table class="notopnoleftnoright allwidth tableforservicepart1 centpercent">';

+			print '<table class="notopnoleftnoright allwidth tableforservicepart1" width="100%">';

@@ -1542,2 +1537,2 @@
-			$sql .= " cd.date_ouverture_prevue as date_start, cd.date_ouverture as date_start_real,";

-			$sql .= " cd.date_fin_validite as date_end, cd.date_cloture as date_end_real,";

+			$sql .= " cd.date_ouverture_prevue as date_debut, cd.date_ouverture as date_debut_reelle,";

+			$sql .= " cd.date_fin_validite as date_fin, cd.date_cloture as date_fin_reelle,";

@@ -1547 +1541,0 @@
-			$sql .= " ,cd.rang";

@@ -1550 +1544 @@
-			$sql .= " WHERE cd.rowid = ".((int) $object->lines[$cursorline - 1]->id);

+			$sql .= " WHERE cd.rowid = ".$object->lines[$cursorline - 1]->id;

@@ -1553 +1547,2 @@
-			if ($result) {

+			if ($result)

+			{

@@ -1556,3 +1550,0 @@
-				$objp = $db->fetch_object($result);

-

-				// Line title

@@ -1563 +1555 @@
-				//if (isModEnabled("multicurrency")) {

+				//if (!empty($conf->multicurrency->enabled)) {

@@ -1567,3 +1559 @@
-				if (getDolGlobalInt('PRODUCT_USE_UNITS')) {

-					print '<td width="30" class="left">'.$langs->trans("Unit").'</td>';

-				}

+				if ($conf->global->PRODUCT_USE_UNITS) print '<td width="30" class="left">'.$langs->trans("Unit").'</td>';

@@ -1571,22 +1561,2 @@
-				if (isModEnabled('margin') && getDolGlobalString('MARGIN_SHOW_ON_CONTRACT')) {

-					print '<td width="50" class="right">'.$langs->trans("BuyingPrice").'</td>';

-				}

-				//

-

-				if ($nbofservices > 1 && $conf->browser->layout != 'phone' && $user->hasRight('contrat', 'creer')) {

-					print '<td width="30" class="linecolmove tdlineupdown center">';

-					if ($cursorline > 1) {

-						print '<a class="lineupdown reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=up&token='.newToken().'&rowid='.$objp->rowid.'">';

-						echo img_up('default', 0, 'imgupforline');

-						print '</a>';

-					}

-					if ($cursorline < $nbofservices) {

-						print '<a class="lineupdown reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=down&token='.newToken().'&rowid='.$objp->rowid.'">';

-						echo img_down('default', 0, 'imgdownforline');

-						print '</a>';

-					}

-					print '</td>';

-				} else {

-					print '<td width="30">&nbsp;</td>';

-				}

-

+				if (!empty($conf->margin->enabled) && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) print '<td width="50" class="right">'.$langs->trans("BuyingPrice").'</td>';

+				print '<td width="30">&nbsp;</td>';

@@ -1595 +1565 @@
-

+				$objp = $db->fetch_object($result);

@@ -1598,8 +1568,3 @@
-				if ($action != 'editline' || GETPOST('rowid') != $objp->rowid) {

-					$moreparam = '';

-					if (getDolGlobalString('CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT') && $objp->statut == ContratLigne::STATUS_CLOSED && $action != 'showclosedlines') {

-						$moreparam = 'style="display: none;"';

-					}

-

-					print '<tr class="tdtop oddeven" '.$moreparam.'>';

-

+				if ($action != 'editline' || GETPOST('rowid') != $objp->rowid)

+				{

+					print '<tr class="tdtop oddeven">';

@@ -1607 +1572,2 @@
-					if ($objp->fk_product > 0) {

+					if ($objp->fk_product > 0)

+					{

@@ -1619 +1585,2 @@
-						if ($objp->plabel) {

+						if ($objp->plabel)

+						{

@@ -1626 +1593,2 @@
-						if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {

+						if (!empty($conf->global->PRODUIT_DESC_IN_FORM))

+						{

@@ -1631 +1599 @@
-						print $form->textwithtooltip($text, $description, 3, '', '', $cursorline, 3, (!empty($line->fk_parent_line) ? img_picto('', 'rightarrow') : ''));

+						echo $form->textwithtooltip($text, $description, 3, '', '', $cursorline, 0, (!empty($line->fk_parent_line) ?img_picto('', 'rightarrow') : ''));

@@ -1634 +1602,3 @@
-					} else {

+					}

+					else

+					{

@@ -1644 +1614 @@
-					/*if (isModEnabled("multicurrency")) {

+					/*if (!empty($conf->multicurrency->enabled)) {

@@ -1650,3 +1620 @@
-					if (getDolGlobalInt('PRODUCT_USE_UNITS')) {

-						print '<td class="left">'.$langs->trans($object->lines[$cursorline - 1]->getLabelOfUnit()).'</td>';

-					}

+					if ($conf->global->PRODUCT_USE_UNITS) print '<td class="left">'.$langs->trans($object->lines[$cursorline - 1]->getLabelOfUnit()).'</td>';

@@ -1654 +1622,2 @@
-					if ($objp->remise_percent > 0) {

+					if ($objp->remise_percent > 0)

+					{

@@ -1656 +1625,3 @@
-					} else {

+					}

+					else

+					{

@@ -1661,7 +1632,6 @@
-					if (isModEnabled('margin') && getDolGlobalString('MARGIN_SHOW_ON_CONTRACT')) {

-						print '<td class="right nowraponall">'.price($objp->pa_ht).'</td>';

-					}

-

-					// Icon move, update et delete (status contract 0=draft,1=validated,2=closed)

-					print '<td class="nowraponall right">';

-					if ($user->hasRight('contrat', 'creer') && is_array($arrayothercontracts) && count($arrayothercontracts) && ($object->statut >= 0)) {

+					if (!empty($conf->margin->enabled) && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) print '<td class="right nowrap">'.price($objp->pa_ht).'</td>';

+

+					// Icon move, update et delete (statut contrat 0=brouillon,1=valide,2=ferme)

+					print '<td class="nowrap right">';

+					if ($user->rights->contrat->creer && count($arrayothercontracts) && ($object->statut >= 0))

+					{

@@ -1669 +1639 @@
-						print '<a class="reposition marginrightonly" style="padding-left: 5px;" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=move&token='.newToken().'&rowid='.$objp->rowid.'">';

+						print '<a class="reposition" style="padding-left: 5px;" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=move&amp;rowid='.$objp->rowid.'">';

@@ -1673,2 +1643,3 @@
-					if ($user->hasRight('contrat', 'creer') && ($object->statut >= 0)) {

-						print '<a class="reposition marginrightonly editfielda" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=editline&token='.newToken().'&rowid='.$objp->rowid.'">';

+					if ($user->rights->contrat->creer && ($object->statut >= 0))

+					{

+						print '<a class="reposition marginrightonly editfielda" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=editline&amp;rowid='.$objp->rowid.'">';

@@ -1678,2 +1649,3 @@
-					if ($user->hasRight('contrat', 'creer') && ($object->statut >= 0)) {

-						print '<a class="reposition marginrightonly" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=deleteline&token='.newToken().'&rowid='.$objp->rowid.'">';

+					if ($user->rights->contrat->creer && ($object->statut >= 0))

+					{

+						print '<a class="reposition marginrightonly" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=deleteline&amp;rowid='.$objp->rowid.'">';

@@ -1687,8 +1658,0 @@
-					$colspan = 6;

-					if (getDolGlobalInt('PRODUCT_USE_UNITS')) {

-						$colspan++;

-					}

-					if (isModEnabled('margin') && getDolGlobalString('MARGIN_SHOW_ON_CONTRACT')) {

-						$colspan++;

-					}

-

@@ -1696,2 +1660,11 @@
-					if ($objp->subprice >= 0) {

-						print '<tr class="oddeven" '.$moreparam.'>';

+					if ($objp->subprice >= 0)

+					{

+						$colspan = 6;

+

+						if ($conf->margin->enabled && $conf->global->PRODUCT_USE_UNITS) {

+							$colspan = 8;

+						} elseif ($conf->margin->enabled || $conf->global->PRODUCT_USE_UNITS) {

+							$colspan = 7;

+						}

+

+						print '<tr class="oddeven">';

@@ -1702,2 +1675,3 @@
-						if ($objp->date_start) {

-							print dol_print_date($db->jdate($objp->date_start), 'day');

+						if ($objp->date_debut)

+						{

+							print dol_print_date($db->jdate($objp->date_debut), 'day');

@@ -1705 +1679 @@
-							if ($objp->statut == 0 && $db->jdate($objp->date_start) < ($now - $conf->contrat->services->inactifs->warning_delay)) {

+							if ($objp->statut == 0 && $db->jdate($objp->date_debut) < ($now - $conf->contrat->services->inactifs->warning_delay)) {

@@ -1710,2 +1683,0 @@
-						} else {

-							print $langs->trans("Unknown");

@@ -1712,0 +1685 @@
+						else print $langs->trans("Unknown");

@@ -1715,3 +1688,4 @@
-						if ($objp->date_end) {

-							print dol_print_date($db->jdate($objp->date_end), 'day');

-							if ($objp->statut == 4 && $db->jdate($objp->date_end) < ($now - $conf->contrat->services->expires->warning_delay)) {

+						if ($objp->date_fin)

+						{

+							print dol_print_date($db->jdate($objp->date_fin), 'day');

+							if ($objp->statut == 4 && $db->jdate($objp->date_fin) < ($now - $conf->contrat->services->expires->warning_delay)) {

@@ -1722,2 +1695,0 @@
-						} else {

-							print $langs->trans("Unknown");

@@ -1724,0 +1697 @@
+						else print $langs->trans("Unknown");

@@ -1735,4 +1708,6 @@
-						print $line->showOptionals($extrafields, 'view', array('class'=>'oddeven', 'style'=>$moreparam, 'colspan'=>$colspan), '', '', 1);

-					}

-				} else {

-					// Line in mode update

+						print $line->showOptionals($extrafields, 'view', array('style'=>'class="oddeven"', 'colspan'=>$colspan), '', '', 1);

+					}

+				}

+				// Line in mode update

+				else

+				{

@@ -1742,18 +1717,8 @@
-					if ($objp->fk_product > 0) {

-						$canchangeproduct = 1;

-						if (empty($canchangeproduct)) {

-							$productstatic->id = $objp->fk_product;

-							$productstatic->type = $objp->ptype;

-							$productstatic->ref = $objp->pref;

-							$productstatic->entity = $objp->pentity;

-							print $productstatic->getNomUrl(1, '', 32);

-							print $objp->label ? ' - '.dol_trunc($objp->label, 32) : '';

-							print '<input type="hidden" name="idprod" value="'.(!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0).'">';

-						} else {

-							$senderissupplier = 0;

-							if (empty($senderissupplier)) {

-								print $form->select_produits((!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0), 'idprod');

-							} else {

-								$form->select_produits_fournisseurs((!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0), 'idprod');

-							}

-						}

+					if ($objp->fk_product)

+					{

+						$productstatic->id = $objp->fk_product;

+						$productstatic->type = $objp->ptype;

+						$productstatic->ref = $objp->pref;

+						$productstatic->entity = $objp->pentity;

+						print $productstatic->getNomUrl(1, '', 32);

+						print $objp->label ? ' - '.dol_trunc($objp->label, 32) : '';

@@ -1761 +1726,3 @@
-					} else {

+					}

+					else

+					{

@@ -1763 +1729,0 @@
-						print '<input type="hidden" name="idprod" value="'.(!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0).'">';

@@ -1769,3 +1735 @@
-					if (getDolGlobalString('MAIN_INPUT_DESC_HEIGHT')) {

-						$nbrows = $conf->global->MAIN_INPUT_DESC_HEIGHT;

-					}

+					if (!empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows = $conf->global->MAIN_INPUT_DESC_HEIGHT;

@@ -1787 +1751 @@
-					/*if (isModEnabled("multicurrency")) {

+					/*if (!empty($conf->multicurrency->enabled)) {

@@ -1795 +1759,2 @@
-					if (getDolGlobalInt('PRODUCT_USE_UNITS')) {

+					if ($conf->global->PRODUCT_USE_UNITS)

+					{

@@ -1804 +1769,2 @@
-					if (!empty($usemargins)) {

+					if (!empty($usemargins))

+					{

@@ -1806,3 +1772 @@
-						if ($objp->fk_product) {

-							print '<select id="fournprice" name="fournprice"></select>';

-						}

+						if ($objp->fk_product) print '<select id="fournprice" name="fournprice"></select>';

@@ -1813 +1777 @@
-					print '<br><input type="submit" class="button margintoponly marginbottomonly button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';

+					print '<br><input type="submit" class="button margintoponly marginbottomonly" name="cancel" value="'.$langs->trans("Cancel").'">';

@@ -1818,8 +1782,4 @@
-					if (isModEnabled('margin') && getDolGlobalString('MARGIN_SHOW_ON_CONTRACT')) {

-						$colspan++;

-					}

-					if (getDolGlobalInt('PRODUCT_USE_UNITS')) {

-						$colspan++;

-					}

-

-					// Line dates planed

+					if (!empty($conf->margin->enabled) && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) $colspan++;

+					if ($conf->global->PRODUCT_USE_UNITS) $colspan++;

+

+					// Ligne dates prevues

@@ -1829 +1789 @@
-					print $form->selectDate($db->jdate($objp->date_start), "date_start_update", $usehm, $usehm, ($db->jdate($objp->date_start) > 0 ? 0 : 1), "update");

+					print $form->selectDate($db->jdate($objp->date_debut), "date_start_update", $usehm, $usehm, ($db->jdate($objp->date_debut) > 0 ? 0 : 1), "update");

@@ -1831 +1791 @@
-					print $form->selectDate($db->jdate($objp->date_end), "date_end_update", $usehm, $usehm, ($db->jdate($objp->date_end) > 0 ? 0 : 1), "update");

+					print $form->selectDate($db->jdate($objp->date_fin), "date_end_update", $usehm, $usehm, ($db->jdate($objp->date_fin) > 0 ? 0 : 1), "update");

@@ -1844 +1804,3 @@
-			} else {

+			}

+			else

+			{

@@ -1848,16 +1810,4 @@
-			if ($object->statut > 0) {

-				$moreparam = '';

-				if (getDolGlobalString('CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT') && $object->lines[$cursorline - 1]->statut == ContratLigne::STATUS_CLOSED && $action != 'showclosedlines') {

-					$moreparam = 'style="display: none;"';

-				}

-

-				$colspan = 6;

-				if (getDolGlobalInt('PRODUCT_USE_UNITS')) {

-					$colspan++;

-				}

-				if (isModEnabled('margin') && getDolGlobalString('MARGIN_SHOW_ON_CONTRACT')) {

-					$colspan++;

-				}

-

-				print '<tr class="oddeven" '.$moreparam.'>';

-				print '<td class="tdhrthin" colspan="'.$colspan.'"><hr class="opacitymedium tdhrthin"></td>';

+			if ($object->statut > 0)

+			{

+				print '<tr class="oddeven">';

+				print '<td class="tdhrthin" colspan="'.($conf->margin->enabled ? 7 : 6).'"><hr class="opacitymedium tdhrthin"></td>';

@@ -1874,3 +1824,4 @@
-			 * Confirmation to delete service line of contract

-			 */

-			if ($action == 'deleteline' && !$_REQUEST["cancel"] && $user->hasRight('contrat', 'creer') && $object->lines[$cursorline - 1]->id == GETPOST('rowid')) {

+             * Confirmation to delete service line of contract

+             */

+			if ($action == 'deleteline' && !$_REQUEST["cancel"] && $user->rights->contrat->creer && $object->lines[$cursorline - 1]->id == GETPOST('rowid'))

+			{

@@ -1878,3 +1829 @@
-				if ($ret == 'html') {

-					print '<table class="notopnoleftnoright" width="100%"><tr class="oddeven" height="6"><td></td></tr></table>';

-				}

+				if ($ret == 'html') print '<table class="notopnoleftnoright" width="100%"><tr class="oddeven" height="6"><td></td></tr></table>';

@@ -1884,3 +1833,4 @@
-			 * Confirmation to move service toward another contract

-			 */

-			if ($action == 'move' && !$_REQUEST["cancel"] && $user->hasRight('contrat', 'creer') && $object->lines[$cursorline - 1]->id == GETPOST('rowid')) {

+             * Confirmation to move service toward another contract

+             */

+			if ($action == 'move' && !$_REQUEST["cancel"] && $user->rights->contrat->creer && $object->lines[$cursorline - 1]->id == GETPOST('rowid'))

+			{

@@ -1888 +1838,2 @@
-				foreach ($arrayothercontracts as $contractcursor) {

+				foreach ($arrayothercontracts as $contractcursor)

+				{

@@ -1897 +1848 @@
-				print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&lineid=".GETPOST('rowid', 'int'), $langs->trans("MoveToAnotherContract"), $langs->trans("ConfirmMoveToAnotherContract"), "confirm_move", $formquestion);

+				print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&lineid=".GETPOST('rowid'), $langs->trans("MoveToAnotherContract"), $langs->trans("ConfirmMoveToAnotherContract"), "confirm_move", $formquestion);

@@ -1900,0 +1852,33 @@
+			/*

+             * Confirmation de la validation activation

+             */

+			if ($action == 'active' && !$_REQUEST["cancel"] && $user->rights->contrat->activer && $object->lines[$cursorline - 1]->id == GETPOST('ligne'))

+			{

+				$dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));

+				$dateactend   = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear'));

+				$comment      = GETPOST('comment', 'alpha');

+				print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&ligne=".GETPOST('ligne')."&date=".$dateactstart."&dateend=".$dateactend."&comment=".urlencode($comment), $langs->trans("ActivateService"), $langs->trans("ConfirmActivateService", dol_print_date($dateactstart, "%A %d %B %Y")), "confirm_active", '', 0, 1);

+				print '<table class="notopnoleftnoright" width="100%"><tr class="oddeven" height="6"><td></td></tr></table>';

+			}

+

+			/*

+             * Confirmation de la validation fermeture

+             */

+			if ($action == 'closeline' && !$_REQUEST["cancel"] && $user->rights->contrat->activer && $object->lines[$cursorline - 1]->id == GETPOST('ligne'))

+			{

+				$dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));

+				$dateactend   = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear'));

+				$comment      = GETPOST('comment', 'alpha');

+

+				if (empty($dateactend))

+				{

+					setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateEndReal")), null, 'errors');

+				}

+				else

+				{

+					print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&ligne=".GETPOST('ligne', 'int')."&date=".$dateactstart."&dateend=".$dateactend."&comment=".urlencode($comment), $langs->trans("CloseService"), $langs->trans("ConfirmCloseService", dol_print_date($dateactend, "%A %d %B %Y")), "confirm_closeline", '', 0, 1);

+				}

+				print '<table class="notopnoleftnoright" width="100%"><tr class="oddeven" height="6"><td></td></tr></table>';

+			}

+

+

@@ -1902,5 +1886,6 @@
-			if ($object->statut > 0) {

-				print '<table class="notopnoleftnoright tableforservicepart2'.($cursorline < $nbofservices ? ' boxtablenobottom' : '').' centpercent">';

-

-				print '<tr class="oddeven" '.$moreparam.'>';

-				print '<td><span class="valignmiddle hideonsmartphone">'.$langs->trans("ServiceStatus").':</span> '.$object->lines[$cursorline - 1]->getLibStatut(4).'</td>';

+			if ($object->statut > 0)

+			{

+				print '<table class="notopnoleftnoright tableforservicepart2'.($cursorline < $nbofservices ? ' boxtablenobottom' : '').'" width="100%">';

+

+				print '<tr class="oddeven">';

+				print '<td>'.$langs->trans("ServiceStatus").': '.$object->lines[$cursorline - 1]->getLibStatut(4).'</td>';

@@ -1908,2 +1893,4 @@
-				if ($user->socid == 0) {

-					if ($object->statut > 0 && $action != 'activateline' && $action != 'unactivateline') {

+				if ($user->socid == 0)

+				{

+					if ($object->statut > 0 && $action != 'activateline' && $action != 'unactivateline')

+					{

@@ -1913 +1900,2 @@
-						if ($objp->statut == 4) {

+						if ($objp->statut == 4)

+						{

@@ -1918 +1906,2 @@
-						if (($tmpaction == 'activateline' && $user->hasRight('contrat', 'activer')) || ($tmpaction == 'unactivateline' && $user->hasRight('contrat', 'desactiver'))) {

+						if (($tmpaction == 'activateline' && $user->rights->contrat->activer) || ($tmpaction == 'unactivateline' && $user->rights->contrat->desactiver))

+						{

@@ -1928 +1917 @@
-				print '<tr class="oddeven" '.$moreparam.'>';

+				print '<tr class="oddeven">';

@@ -1932 +1921 @@
-				if (!$objp->date_start_real) {

+				if (!$objp->date_debut_reelle) {

@@ -1934,5 +1923,2 @@
-					if ($objp->date_start_real) {

-						print dol_print_date($db->jdate($objp->date_start_real), 'day');

-					} else {

-						print $langs->trans("ContractStatusNotRunning");

-					}

+					if ($objp->date_debut_reelle) print dol_print_date($db->jdate($objp->date_debut_reelle), 'day');

+					else print $langs->trans("ContractStatusNotRunning");

@@ -1941 +1927 @@
-				if ($objp->date_start_real && !$objp->date_end_real) {

+				if ($objp->date_debut_reelle && !$objp->date_fin_reelle) {

@@ -1943 +1929 @@
-					print dol_print_date($db->jdate($objp->date_start_real), 'day');

+                    print dol_print_date($db->jdate($objp->date_debut_reelle), 'day');

@@ -1946 +1932 @@
-				if ($objp->date_start_real && $objp->date_end_real) {

+				if ($objp->date_debut_reelle && $objp->date_fin_reelle) {

@@ -1948 +1934 @@
-					print dol_print_date($db->jdate($objp->date_start_real), 'day');

+                    print dol_print_date($db->jdate($objp->date_debut_reelle), 'day');

@@ -1951,5 +1937,3 @@
-					print dol_print_date($db->jdate($objp->date_end_real), 'day');

-				}

-				if (!empty($objp->comment)) {

-					print " &nbsp;-&nbsp; ".$objp->comment;

-				}

+					print dol_print_date($db->jdate($objp->date_fin_reelle), 'day');

+				}

+				if (!empty($objp->comment)) print " &nbsp;-&nbsp; ".$objp->comment;

@@ -1965,2 +1949,3 @@
-			if ($user->hasRight('contrat', 'activer') && $action == 'activateline' && $object->lines[$cursorline - 1]->id == GETPOST('ligne', 'int')) {

-				print '<form name="active" action="'.$_SERVER["PHP_SELF"].'" method="POST">';

+			if ($user->rights->contrat->activer && $action == 'activateline' && $object->lines[$cursorline - 1]->id == GETPOST('ligne'))

+			{

+				print '<form name="active" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;ligne='.GETPOST('ligne').'&amp;action=active" method="post">';

@@ -1968,7 +1953,2 @@
-				print '<input type="hidden" name="action" value="confirm_active">';

-				print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';

-				print '<input type="hidden" name="id" value="'.$object->id.'">';

-				print '<input type="hidden" name="ligne" value="'.GETPOST('ligne', 'int').'">';

-				print '<input type="hidden" name="confirm" value="yes">';

-

-				print '<table class="noborder tableforservicepart2'.($cursorline < $nbofservices ? ' boxtablenobottom' : '').' centpercent">';

+

+				print '<table class="noborder tableforservicepart2'.($cursorline < $nbofservices ? ' boxtablenobottom' : '').'" width="100%">';

@@ -1977,12 +1957,10 @@
-				$dateactstart = $objp->date_start;

-				if (GETPOST('remonth')) {

-					$dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));

-				} elseif (!$dateactstart) {

-					$dateactstart = time();

-				}

-

-				$dateactend = $objp->date_end;

-				if (GETPOST('endmonth')) {

-					$dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear'));

-				} elseif (!$dateactend) {

-					if ($objp->fk_product > 0) {

+				$dateactstart = $objp->date_debut;

+				if (GETPOST('remonth')) $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));

+				elseif (!$dateactstart) $dateactstart = time();

+

+				$dateactend = $objp->date_fin;

+				if (GETPOST('endmonth')) $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear'));

+				elseif (!$dateactend)

+				{

+					if ($objp->fk_product > 0)

+					{

@@ -1997 +1975 @@
-				print $form->selectDate($dateactstart, 'start', $usehm, $usehm, '', "active", 1, 0);

+				print $form->selectDate($dateactstart, '', $usehm, $usehm, '', "active", 1, 0);

@@ -2008 +1986 @@
-				print '<td class="nohover">'.$langs->trans("Comment").'</td><td colspan="3" class="nohover" colspan="'.(isModEnabled('margin') ? 4 : 3).'"><input type="text" class="minwidth300" name="comment" value="'.dol_escape_htmltag(GETPOST("comment", 'alphanohtml')).'"></td>';

+				print '<td class="nohover">'.$langs->trans("Comment").'</td><td colspan="3" class="nohover" colspan="'.($conf->margin->enabled ? 4 : 3).'"><input size="80" type="text" name="comment" value="'.$_POST["comment"].'"></td>';

@@ -2011 +1989 @@
-				print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';

+				print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';

@@ -2020 +1998,2 @@
-			if ($user->hasRight('contrat', 'activer') && $action == 'unactivateline' && $object->lines[$cursorline - 1]->id == GETPOST('ligne', 'int')) {

+			if ($user->rights->contrat->activer && $action == 'unactivateline' && $object->lines[$cursorline - 1]->id == GETPOST('ligne'))

+			{

@@ -2025 +2004,2 @@
-				print '<form name="confirm_closeline" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;ligne='.$object->lines[$cursorline - 1]->id.'" method="post">';

+				print '<form name="closeline" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;ligne='.$object->lines[$cursorline - 1]->id.'" method="post">';

+

@@ -2027,5 +2007,3 @@
-				print '<input type="hidden" name="confirm" value="yes">';

-				print '<input type="hidden" name="action" value="confirm_closeline">';

-				print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';

-

-				print '<table class="noborder tableforservicepart2'.($cursorline < $nbofservices ? ' boxtablenobottom' : '').' centpercent">';

+				print '<input type="hidden" name="action" value="closeline">';

+

+				print '<table class="noborder tableforservicepart2'.($cursorline < $nbofservices ? ' boxtablenobottom' : '').'" width="100%">';

@@ -2034,12 +2012,10 @@
-				$dateactstart = $objp->date_start_real;

-				if (GETPOST('remonth')) {

-					$dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));

-				} elseif (!$dateactstart) {

-					$dateactstart = time();

-				}

-

-				$dateactend = $objp->date_end_real;

-				if (GETPOST('endmonth')) {

-					$dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear'));

-				} elseif (!$dateactend) {

-					if ($objp->fk_product > 0) {

+				$dateactstart = $objp->date_debut_reelle;

+				if (GETPOST('remonth')) $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));

+				elseif (!$dateactstart) $dateactstart = time();

+

+				$dateactend = $objp->date_fin_reelle;

+				if (GETPOST('endmonth')) $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear'));

+				elseif (!$dateactend)

+				{

+					if ($objp->fk_product > 0)

+					{

@@ -2052,3 +2028 @@
-				if ($dateactend > $now) {

-					$dateactend = $now;

-				}

+				if ($dateactend > $now) $dateactend = $now;

@@ -2057,2 +2031,4 @@
-				if ($objp->statut >= 4) {

-					if ($objp->statut == 4) {

+				if ($objp->statut >= 4)

+				{

+					if ($objp->statut == 4)

+					{

@@ -2060 +2036 @@
-						print $form->selectDate($dateactend, "end", $usehm, $usehm, ($objp->date_end_real > 0 ? 0 : 1), "closeline", 1, 1);

+						print $form->selectDate($dateactend, "end", $usehm, $usehm, ($objp->date_fin_reelle > 0 ? 0 : 1), "closeline", 1, 1);

@@ -2068 +2044 @@
-				print '<td class="nohover">'.$langs->trans("Comment").'</td><td class="nohover"><input class="quatrevingtpercent" type="text" class="flat" name="comment" value="'.dol_escape_htmltag(GETPOST('comment', 'alpha')).'"></td>';

+				print '<td class="nohover">'.$langs->trans("Comment").'</td><td class="nohover"><input size="70" type="text" class="flat" name="comment" value="'.dol_escape_htmltag(GETPOST('comment', 'alpha')).'"></td>';

@@ -2071 +2047 @@
-				print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';

+				print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';

@@ -2085 +2061,2 @@
-		if ($user->hasRight('contrat', 'creer') && ($object->statut == 0)) {

+		if ($user->rights->contrat->creer && ($object->statut == 0))

+		{

@@ -2089 +2066 @@
-			print '	<form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">

+			print '	<form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '#add' : '#line_'.GETPOST('lineid')).'" method="POST">

@@ -2094,2 +2070,0 @@
-			<input type="hidden" name="page_y" value="">

-			<input type="hidden" name="backtopage" value="'.$backtopage.'">

@@ -2102 +2077,2 @@
-			if ($action != 'editline') {

+	   		if ($action != 'editline')

+			{

@@ -2104,3 +2080 @@
-				if (empty($object->multicurrency_code)) {

-					$object->multicurrency_code = $conf->currency; // TODO Remove this when multicurrency supported on contracts

-				}

+				if (empty($object->multicurrency_code)) $object->multicurrency_code = $conf->currency; // TODO Remove this when multicurrency supported on contracts

@@ -2108,0 +2083 @@
+				$object->formAddObjectLine(1, $mysoc, $soc);

@@ -2112,6 +2086,0 @@
-				if ($reshook < 0) {

-					setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

-				}

-				if (empty($reshook)) {

-					$object->formAddObjectLine(1, $mysoc, $soc);

-				}

@@ -2125,6 +2094,2 @@
-		print dol_get_fiche_end();

-

-		// Select mail models is same action as presend

-		if (GETPOST('modelselected')) {

-			$action = 'presend';

-		}

+		dol_fiche_end();

+

@@ -2133,3 +2098,5 @@
-		 * Buttons

-		 */

-		if ($user->socid == 0 && $action != 'presend' && $action != 'editline') {

+         * Buttons

+         */

+

+		if ($user->socid == 0)

+		{

@@ -2141,8 +2108,2 @@
-			if (empty($reshook)) {

-				$params = array(

-					'attr' => array(

-						'title' => '',

-						'class' => 'classfortooltip'

-					)

-				);

-

+			if (empty($reshook))

+			{

@@ -2151,76 +2112,53 @@
-					if ($object->status == $object::STATUS_VALIDATED) {

-						if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || $user->hasRight('contrat', 'creer'))) {

-							print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&token='.newToken().'&mode=init#formmailbeforetitle', '', true, $params);

-						} else {

-							print dolGetButtonAction('', $langs->trans('SendMail'), 'default', '#', '', false, $params);

-						}

-					}

-				}

-

-				if ($object->status == $object::STATUS_DRAFT && $nbofservices) {

-					if ($user->hasRight('contrat', 'creer')) {

-						unset($params['attr']['title']);

-						print dolGetButtonAction($langs->trans('Validate'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=valid&token='.newToken(), '', true, $params);

-					} else {

-						$params['attr']['title'] = $langs->trans("NotEnoughPermissions");

-						print dolGetButtonAction($langs->trans('Validate'), '', 'default', '#', '', false, $params);

-					}

-				}

-				if ($object->status == $object::STATUS_VALIDATED) {

-					if ($user->hasRight('contrat', 'creer')) {

-						unset($params['attr']['title']);

-						print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken(), '', true, $params);

-					} else {

-						$params['attr']['title'] = $langs->trans("NotEnoughPermissions");

-						print dolGetButtonAction($langs->trans('Modify'), '', 'default', '#', '', false, $params);

-					}

-				}

-

-				// Create ... buttons

-				$arrayofcreatebutton = array();

-				if (isModEnabled('commande') && $object->status > 0 && $object->nbofservicesclosed < $nbofservices) {

-					$arrayofcreatebutton[] = array(

-						'url' => '/commande/card.php?action=create&token='.newToken().'&origin='.$object->element.'&originid='.$object->id.'&socid='.$object->thirdparty->id,

-						'label' => $langs->trans('AddOrder'),

-						'lang' => 'orders',

-						'perm' => $user->hasRight('commande', 'creer')

-					);

-				}

-				if (isModEnabled('facture') && $object->status > 0 && $soc->client > 0) {

-					$arrayofcreatebutton[] = array(

-						'url' => '/compta/facture/card.php?action=create&origin='.$object->element.'&originid='.$object->id.'&socid='.$object->thirdparty->id,

-						'label' => $langs->trans('CreateBill'),

-						'lang' => 'bills',

-						'perm' => $user->hasRight('facture', 'creer')

-					);

-				}

-				if (isModEnabled('supplier_invoice') && $object->status > 0 && $soc->fournisseur == 1) {

-					$langs->load("suppliers");

-					$arrayofcreatebutton[] = array(

-						'url' => '/fourn/facture/card.php?action=create&origin='.$object->element.'&originid='.$object->id.'&socid='.$object->thirdparty->id,

-						'label' => $langs->trans('AddSupplierInvoice'),

-						'lang' => 'bills',

-						'perm' => $user->hasRight('fournisseur', 'facture', 'creer')

-					);

-				}

-				if (count($arrayofcreatebutton)) {

-					unset($params['attr']['title']);

-					print dolGetButtonAction('', $langs->trans("Create"), 'default', $arrayofcreatebutton, '', true, $params);

-				}

-

-				if ($object->nbofservicesclosed > 0 || $object->nbofserviceswait > 0) {

-					if ($user->hasRight('contrat', 'activer')) {

-						unset($params['attr']['title']);

-						print dolGetButtonAction($langs->trans('ActivateAllContracts'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=activate&token='.newToken(), '', true, $params);

-					} else {

-						unset($params['attr']['title']);

-						print dolGetButtonAction($langs->trans('ActivateAllContracts'), '', 'default', '#', '', false, $params);

-					}

-				}

-				if ($object->nbofservicesclosed < $nbofservices) {

-					if ($user->hasRight('contrat', 'desactiver')) {

-						unset($params['attr']['title']);

-						print dolGetButtonAction($langs->trans('CloseAllContracts'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=close&token='.newToken(), '', true, $params);

-					} else {

-						unset($params['attr']['title']);

-						print dolGetButtonAction($langs->trans('CloseAllContracts'), '', 'default', '#', '', false, $params);

+					if ($object->statut == 1) {

+						if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->commande->order_advance->send)) {

+							print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>';

+						} else

+							print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans('SendMail').'</a></div>';

+					}

+				}

+

+				if ($object->statut == 0 && $nbofservices)

+				{

+					if ($user->rights->contrat->creer) print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=valid">'.$langs->trans("Validate").'</a></div>';

+					else print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("Validate").'</a></div>';

+				}

+				if ($object->statut == 1)

+				{

+					if ($user->rights->contrat->creer) print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans("Modify").'</a></div>';

+					else print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("Modify").'</a></div>';

+				}

+

+				if (!empty($conf->commande->enabled) && $object->statut > 0 && $object->nbofservicesclosed < $nbofservices)

+				{

+					$langs->load("orders");

+					if ($user->rights->commande->creer) print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/commande/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->thirdparty->id.'">'.$langs->trans("CreateOrder").'</a></div>';

+					else print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("CreateOrder").'</a></div>';

+				}

+

+				if (!empty($conf->facture->enabled) && $object->statut > 0)

+				{

+					$langs->load("bills");

+					if ($user->rights->facture->creer) print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->thirdparty->id.'">'.$langs->trans("CreateBill").'</a></div>';

+					else print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("CreateBill").'</a></div>';

+				}

+

+				if ($object->nbofservicesclosed > 0 || $object->nbofserviceswait > 0)

+				{

+					if ($user->rights->contrat->activer)

+					{

+						print '<div class="inline-block divButAction"><a class="butAction" id="btnactivateall" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=activate">'.$langs->trans("ActivateAllContracts").'</a></div>';

+					}

+					else

+					{

+						print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" id="btnactivateall" href="#">'.$langs->trans("ActivateAllContracts").'</a></div>';

+					}

+				}

+				if ($object->nbofservicesclosed < $nbofservices)

+				{

+					if ($user->rights->contrat->desactiver)

+					{

+						print '<div class="inline-block divButAction"><a class="butAction" id="btncloseall" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=close">'.$langs->trans("CloseAllContracts").'</a></div>';

+					}

+					else

+					{

+						print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" id="btncloseall" href="#">'.$langs->trans("CloseAllContracts").'</a></div>';

@@ -2238,8 +2175,0 @@
-				if (getDolGlobalString('CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT') && $object->nbofservicesclosed > 0) {

-					if ($action == 'showclosedlines') {

-						print '<div class="inline-block divButAction"><a class="butAction" id="btnhideclosedlines" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=hideclosedlines">'.$langs->trans("HideClosedServices").'</a></div>';

-					} else {

-						print '<div class="inline-block divButAction"><a class="butAction" id="btnshowclosedlines" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=showclosedlines">'.$langs->trans("ShowClosedServices").'</a></div>';

-					}

-				}

-

@@ -2247,3 +2177,2 @@
-				if ($user->hasRight('contrat', 'creer')) {

-					unset($params['attr']['title']);

-					print dolGetButtonAction($langs->trans('ToClone'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&token='.newToken(), '', true, $params);

+				if ($user->rights->contrat->creer) {

+					print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;socid='.$object->socid.'&amp;action=clone&amp;object='.$object->element.'">'.$langs->trans("ToClone").'</a></div>';

@@ -2253,2 +2182,8 @@
-				unset($params['attr']['title']);

-				print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), '', $permissiontodelete, $params);

+				if (($user->rights->contrat->creer && $object->statut == $object::STATUS_DRAFT) || $user->rights->contrat->supprimer)

+				{

+					print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans("Delete").'</a></div>';

+				}

+				else

+				{

+					print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans("Delete").'</a></div>';

+				}

@@ -2260 +2195,7 @@
-		if ($action != 'presend') {

+		// Select mail models is same action as presend

+		if (GETPOST('modelselected')) {

+			$action = 'presend';

+		}

+

+		if ($action != 'presend')

+		{

@@ -2264,2 +2205,2 @@
-			 * Generated documents

-			 */

+    		 * Documents generes

+    		*/

@@ -2267 +2208 @@
-			$filedir = $conf->contrat->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref);

+			$filedir = $conf->contrat->dir_output."/".dol_sanitizeFileName($object->ref);

@@ -2269,5 +2210,5 @@
-			$genallowed = $user->hasRight('contrat', 'lire');

-			$delallowed = $user->hasRight('contrat', 'creer');

-

-

-			print $formfile->showdocuments('contract', $filename, $filedir, $urlsource, $genallowed, $delallowed, ($object->model_pdf ? $object->model_pdf : getDolGlobalString('CONTRACT_ADDON_PDF')), 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang, '', $object);

+			$genallowed = $user->rights->contrat->lire;

+			$delallowed = $user->rights->contrat->creer;

+

+

+			print $formfile->showdocuments('contract', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang);

@@ -2280,9 +2221,2 @@
-			// Show online signature link

-			if ($object->statut != Contrat::STATUS_DRAFT && getDolGlobalString('CONTRACT_ALLOW_ONLINESIGN')) {

-				print '<br><!-- Link to sign -->';

-				require_once DOL_DOCUMENT_ROOT.'/core/lib/signature.lib.php';

-

-				print showOnlineSignatureUrl('contract', $object->ref).'<br>';

-			}

-

-			print '</div><div class="fichehalfright">';

+

+			print '</div><div class="fichehalfright"><div class="ficheaddleft">';

@@ -2292,2 +2226 @@
-			$morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/contrat/agenda.php?id='.$object->id);

-

+			$morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-list-alt imgforviewmode', DOL_URL_ROOT.'/contrat/agenda.php?id='.$object->id);

@@ -2300 +2233 @@
-			print '</div></div>';

+			print '</div></div></div>';

@@ -2306 +2239 @@
-		$diroutput = $conf->contrat->multidir_output[$object->entity];

+		$diroutput = $conf->contrat->dir_output;

@@ -2320,2 +2253,4 @@
-if (isModEnabled('margin') && $action == 'editline') {

-	// TODO Why this ? To manage margin on contracts ??>

+if (!empty($conf->margin->enabled) && $action == 'editline')

+{

+		// TODO Why this ? To manage margin on contracts ?

+	?>

@@ -2326 +2261 @@
-  var token = '<?php echo currentToken(); ?>';		// For AJAX Call we use old 'token' and not 'newtoken'

+  var token = '<?php echo $_SESSION["token"]; ?>';		// For AJAX Call we use old 'token' and not 'newtoken'

@@ -2332,35 +2267,35 @@
-		if (data.length > 0) {

-		  var options = '';

-		  var trouve=false;

-		  $(data).each(function() {

-			options += '<option value="'+this.id+'" price="'+this.price+'"';

-			if (fournprice > 0) {

-				if (this.id == fournprice) {

-				  options += ' selected';

-				  $("#buying_price").val(this.price);

-				  trouve = true;

-				}

-			}

-			options += '>'+this.label+'</option>';

-		  });

-		  options += '<option value=null'+(trouve?'':' selected')+'><?php echo $langs->trans("InputPrice"); ?></option>';

-		  $("#fournprice").html(options);

-		  if (trouve) {

-			$("#buying_price").hide();

-			$("#fournprice").show();

-		  }

-		  else {

-			$("#buying_price").show();

-		  }

-		  $("#fournprice").change(function() {

-			var selval = $(this).find('option:selected').attr("price");

-			if (selval)

-			  $("#buying_price").val(selval).hide();

-			else

-			  $('#buying_price').show();

-		  });

-		}

-		else {

-		  $("#fournprice").hide();

-		  $('#buying_price').show();

-		}

+	    if (data.length > 0) {

+	      var options = '';

+	      var trouve=false;

+	      $(data).each(function() {

+	        options += '<option value="'+this.id+'" price="'+this.price+'"';

+	        if (fournprice > 0) {

+		        if (this.id == fournprice) {

+		          options += ' selected';

+		          $("#buying_price").val(this.price);

+		          trouve = true;

+		        }

+	        }

+	        options += '>'+this.label+'</option>';

+	      });

+	      options += '<option value=null'+(trouve?'':' selected')+'><?php echo $langs->trans("InputPrice"); ?></option>';

+	      $("#fournprice").html(options);

+	      if (trouve) {

+	        $("#buying_price").hide();

+	        $("#fournprice").show();

+	      }

+	      else {

+	        $("#buying_price").show();

+	      }

+	      $("#fournprice").change(function() {

+	        var selval = $(this).find('option:selected').attr("price");

+	        if (selval)

+	          $("#buying_price").val(selval).hide();

+	        else

+	          $('#buying_price').show();

+	      });

+	    }

+	    else {

+	      $("#fournprice").hide();

+	      $('#buying_price').show();

+	    }

@@ -2370,4 +2305,4 @@
-	else {

-	  $("#fournprice").hide();

-	  $('#buying_price').show();

-	}

+    else {

+      $("#fournprice").hide();

+      $('#buying_price').show();

+    }

--- /tmp/dsg/dolibarr/htdocs/contrat/github_19.0.3_contact.php
+++ /tmp/dsg/dolibarr/htdocs/contrat/client_contact.php
@@ -6 +5,0 @@
- * Copyright (C) 2023       Christian Foellmann <christian@foellmann.de>

@@ -28 +26,0 @@
-// Load Dolibarr environment

@@ -34 +32 @@
-if (isModEnabled('project')) {

+if (!empty($conf->projet->enabled)) {

@@ -41 +39 @@
-$action = GETPOST('action', 'aZ09');

+$action = GETPOST('action', 'alpha');

@@ -48,3 +46,2 @@
-if ($user->socid) {

-	$socid = $user->socid;

-}

+if ($user->socid) $socid = $user->socid;

+$result = restrictedArea($user, 'contrat', $id);

@@ -55,5 +52 @@
-$hookmanager->initHooks(array('contractcontactcard', 'globalcard'));

-

-$permissiontoadd   = $user->hasRight('contrat', 'creer');     //  Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php

-

-$result = restrictedArea($user, 'contrat', $object->id);

+$hookmanager->initHooks(array('contractcard', 'globalcard'));

@@ -66,15 +59,22 @@
-$parameters = array('id'=>$id);

-$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);

-if ($reshook < 0) {

-	setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

-}

-

-if (empty($reshook)) {

-	// Add new contact

-	if ($action == 'addcontact' && $user->hasRight('contrat', 'creer')) {

-		$result = $object->fetch($id);

-

-		if ($result > 0 && $id > 0) {

-			$contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));

-			$typeid    = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));

-			$result    = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));

+if ($action == 'addcontact' && $user->rights->contrat->creer)

+{

+	$result = $object->fetch($id);

+

+    if ($result > 0 && $id > 0)

+    {

+    	$contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));

+  		$result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);

+    }

+

+	if ($result >= 0)

+	{

+		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);

+		exit;

+	}

+	else

+	{

+		if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {

+			$langs->load("errors");

+			$msg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");

+		} else {

+			$mesg = $object->error;

@@ -83,35 +83,30 @@
-		if ($result >= 0) {

-			header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);

-			exit;

-		} else {

-			if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {

-				$langs->load("errors");

-				$msg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");

-			} else {

-				$mesg = $object->error;

-			}

-

-			setEventMessages($mesg, null, 'errors');

-		}

-	}

-

-	// Toggle the status of a contact

-	if ($action == 'swapstatut' && $user->hasRight('contrat', 'creer')) {

-		if ($object->fetch($id)) {

-			$result = $object->swapContactStatus(GETPOST('ligne', 'int'));

-		} else {

-			dol_print_error($db, $object->error);

-		}

-	}

-

-	// Delete contact

-	if ($action == 'deletecontact' && $user->hasRight('contrat', 'creer')) {

-		$object->fetch($id);

-		$result = $object->delete_contact(GETPOST("lineid", 'int'));

-

-		if ($result >= 0) {

-			header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);

-			exit;

-		}

-	}

-}

+		setEventMessages($mesg, null, 'errors');

+	}

+}

+

+// bascule du statut d'un contact

+if ($action == 'swapstatut' && $user->rights->contrat->creer)

+{

+	if ($object->fetch($id))

+	{

+	    $result = $object->swapContactStatus(GETPOST('ligne'));

+	}

+	else

+	{

+		dol_print_error($db, $object->error);

+	}

+}

+

+// Delete contact

+if ($action == 'deletecontact' && $user->rights->contrat->creer)

+{

+	$object->fetch($id);

+	$result = $object->delete_contact($_GET["lineid"]);

+

+	if ($result >= 0)

+	{

+		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);

+		exit;

+	}

+}

+

@@ -123,4 +118 @@
-$title = $langs->trans("Contract");

-$help_url = 'EN:Module_Contracts|FR:Module_Contrat';

-

-llxHeader('', $title, $help_url);

+llxHeader('', $langs->trans("Contract"), "");

@@ -139,2 +131,4 @@
-if ($id > 0 || !empty($ref)) {

-	if ($object->fetch($id, $ref) > 0) {

+if ($id > 0 || !empty($ref))

+{

+	if ($object->fetch($id, $ref) > 0)

+	{

@@ -143 +137 @@
-		$head = contract_prepare_head($object);

+	    $head = contract_prepare_head($object);

@@ -147 +141 @@
-		print dol_get_fiche_head($head, $hselected, $langs->trans("Contract"), -1, 'contract');

+		dol_fiche_head($head, $hselected, $langs->trans("Contract"), -1, 'contract');

@@ -151,10 +145,10 @@
-		$linkback = '<a href="'.DOL_URL_ROOT.'/contrat/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';

-

-

-		$morehtmlref = '';

-		//if (!empty($modCodeContract->code_auto)) {

-		$morehtmlref .= $object->ref;

-		/*} else {

-			$morehtmlref.=$form->editfieldkey("",'ref',$object->ref,0,'string','',0,3);

-			$morehtmlref.=$form->editfieldval("",'ref',$object->ref,0,'string','',0,2);

-		}*/

+        $linkback = '<a href="'.DOL_URL_ROOT.'/contrat/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';

+

+

+        $morehtmlref = '';

+        //if (! empty($modCodeContract->code_auto)) {

+            $morehtmlref .= $object->ref;

+        /*} else {

+            $morehtmlref.=$form->editfieldkey("",'ref',$object->ref,0,'string','',0,3);

+            $morehtmlref.=$form->editfieldval("",'ref',$object->ref,0,'string','',0,2);

+        }*/

@@ -171,30 +165,41 @@
-		$morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);

-		// Project

-		if (isModEnabled('project')) {

-			$langs->load("projects");

-			$morehtmlref .= '<br>';

-			if (0) {

-				$morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');

-				if ($action != 'classify') {

-					$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';

-				}

-				$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');

-			} else {

-				if (!empty($object->fk_project)) {

-					$proj = new Project($db);

-					$proj->fetch($object->fk_project);

-					$morehtmlref .= $proj->getNomUrl(1);

-					if ($proj->title) {

-						$morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';

-					}

-				}

-			}

-		}

-		$morehtmlref .= '</div>';

-

-

-		dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref);

-

-

-		print '<div class="fichecenter">';

-		print '<div class="underbanner clearboth"></div>';

+	    $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);

+        // Project

+        if (!empty($conf->projet->enabled)) {

+            $langs->load("projects");

+            $morehtmlref .= '<br>'.$langs->trans('Project').' ';

+            if ($user->rights->contrat->creer) {

+                if ($action != 'classify') {

+                	//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';

+                    $morehtmlref .= ' : ';

+                }

+                if ($action == 'classify') {

+	                //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);

+	                $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';

+	                $morehtmlref .= '<input type="hidden" name="action" value="classin">';

+	                $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';

+	                $morehtmlref .= $formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);

+	                $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';

+	                $morehtmlref .= '</form>';

+	            } else {

+	                $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1);

+	            }

+	        } else {

+	            if (!empty($object->fk_project)) {

+	                $proj = new Project($db);

+	                $proj->fetch($object->fk_project);

+	                $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';

+	                $morehtmlref .= $proj->ref;

+	                $morehtmlref .= '</a>';

+	            } else {

+	                $morehtmlref .= '';

+	            }

+	        }

+	    }

+	    $morehtmlref .= '</div>';

+

+

+	    dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref);

+

+

+	    print '<div class="fichecenter">';

+	    print '<div class="underbanner clearboth"></div>';

@@ -205,19 +210,16 @@
-		// Ligne info remises tiers

-		print '<tr><td class="titlefield">'.$langs->trans('Discount').'</td><td colspan="3">';

-		if ($object->thirdparty->remise_percent) {

-			print $langs->trans("CompanyHasRelativeDiscount", $object->thirdparty->remise_percent);

-		} else {

-			print $langs->trans("CompanyHasNoRelativeDiscount");

-		}

-		$absolute_discount = $object->thirdparty->getAvailableDiscounts();

-		print '. ';

-		if ($absolute_discount) {

-			print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency));

-		} else {

-			print $langs->trans("CompanyHasNoAbsoluteDiscount");

-		}

-		print '.';

-		print '</td></tr>';

-

-		// Date

-		print '<tr>';

+        // Ligne info remises tiers

+        print '<tr><td class="titlefield">'.$langs->trans('Discount').'</td><td colspan="3">';

+        if ($object->thirdparty->remise_percent) {

+            print $langs->trans("CompanyHasRelativeDiscount", $object->thirdparty->remise_percent);

+        } else {

+            print $langs->trans("CompanyHasNoRelativeDiscount");

+        }

+        $absolute_discount = $object->thirdparty->getAvailableDiscounts();

+        print '. ';

+        if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency));

+        else print $langs->trans("CompanyHasNoAbsoluteDiscount");

+        print '.';

+        print '</td></tr>';

+

+        // Date

+        print '<tr>';

@@ -235 +237 @@
-		print dol_get_fiche_end();

+		dol_fiche_end();

--- /tmp/dsg/dolibarr/htdocs/contrat/github_19.0.3_document.php
+++ /tmp/dsg/dolibarr/htdocs/contrat/client_document.php
@@ -36 +36 @@
-if (isModEnabled('project')) {

+if (!empty($conf->projet->enabled)) {

@@ -49 +49,2 @@
-if ($user->socid > 0) {

+if ($user->socid > 0)

+{

@@ -53,0 +55 @@
+$result = restrictedArea($user, 'contrat', $id);

@@ -57,2 +59,2 @@
-$sortfield = GETPOST('sortfield', 'aZ09comma');

-$sortorder = GETPOST('sortorder', 'aZ09comma');

+$sortfield = GETPOST("sortfield", 'alpha');

+$sortorder = GETPOST("sortorder", 'alpha');

@@ -60,3 +62 @@
-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

@@ -66,6 +66,2 @@
-if (!$sortorder) {

-	$sortorder = "ASC";

-}

-if (!$sortfield) {

-	$sortfield = "name";

-}

+if (!$sortorder) $sortorder = "ASC";

+if (!$sortfield) $sortfield = "name";

@@ -76 +72,2 @@
-if ($object->id > 0) {

+if ($object->id > 0)

+{

@@ -80 +77 @@
-$upload_dir = $conf->contrat->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);

+$upload_dir = $conf->contrat->dir_output.'/'.dol_sanitizeFileName($object->ref);

@@ -86,4 +82,0 @@
-$permissiontoadd = $user->hasRight('contrat', 'creer');	// Used by the include of actions_dellink.inc.php

-

-$result = restrictedArea($user, 'contrat', $object->id);

-

@@ -95 +88 @@
-include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';

+include_once DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';

@@ -104,7 +97,5 @@
-$title = $langs->trans("Contract");

-$help_url = 'EN:Module_Contracts|FR:Module_Contrat';

-

-llxHeader('', $title, $help_url);

-

-

-if ($object->id) {

+llxHeader('', $langs->trans("Contract"), "");

+

+

+if ($object->id)

+{

@@ -113 +104 @@
-	print dol_get_fiche_head($head, 'documents', $langs->trans("Contract"), -1, 'contract');

+	dol_fiche_head($head, 'documents', $langs->trans("Contract"), -1, 'contract');

@@ -117 +108 @@
-	$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);

+	$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);

@@ -119 +110,2 @@
-	foreach ($filearray as $key => $file) {

+	foreach ($filearray as $key => $file)

+	{

@@ -130 +122 @@
-	//if (!empty($modCodeContract->code_auto)) {

+	//if (! empty($modCodeContract->code_auto)) {

@@ -146,4 +138,2 @@
-	$morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);

-	if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {

-		$morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/contrat/list.php?socid='.$object->thirdparty->id.'&search_name='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherContracts").'</a>)';

-	}

+	$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);

+	if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/contrat/list.php?socid='.$object->thirdparty->id.'&search_name='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherContracts").'</a>)';

@@ -151 +141,2 @@
-	if (isModEnabled('project')) {

+	if (!empty($conf->projet->enabled))

+	{

@@ -153,5 +144,16 @@
-		$morehtmlref .= '<br>';

-		if (0) {

-			$morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');

-			if ($action != 'classify') {

-				$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';

+		$morehtmlref .= '<br>'.$langs->trans('Project').' ';

+		if ($user->rights->contrat->creer)

+		{

+			if ($action != 'classify')

+				//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';

+				$morehtmlref .= ' : ';

+			if ($action == 'classify') {

+				//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);

+				$morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';

+				$morehtmlref .= '<input type="hidden" name="action" value="classin">';

+				$morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';

+				$morehtmlref .= $formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);

+				$morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';

+				$morehtmlref .= '</form>';

+			} else {

+				$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1);

@@ -159 +160,0 @@
-			$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');

@@ -164,4 +165,5 @@
-				$morehtmlref .= $proj->getNomUrl(1);

-				if ($proj->title) {

-					$morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';

-				}

+				$morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';

+				$morehtmlref .= $proj->ref;

+				$morehtmlref .= '</a>';

+			} else {

+				$morehtmlref .= '';

@@ -180,15 +182,17 @@
-	print '<table class="border tableforfield centpercent">';

-	print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';

-	print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';

-	print '</table>';

-

-	print '</div>';

-

-	print dol_get_fiche_end();

-

-	$modulepart = 'contract';

-	$permissiontoadd = $user->hasRight('contrat', 'creer');

-	$permtoedit = $user->hasRight('contrat', 'creer');

-	$param = '&id='.$object->id;

-	include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';

-} else {

+    print '<table class="border tableforfield centpercent">';

+    print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';

+    print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';

+    print '</table>';

+

+    print '</div>';

+

+    dol_fiche_end();

+

+    $modulepart = 'contract';

+    $permission = $user->rights->contrat->creer;

+    $permtoedit = $user->rights->contrat->creer;

+    $param = '&id='.$object->id;

+    include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';

+}

+else

+{

--- /tmp/dsg/dolibarr/htdocs/contrat/github_19.0.3_index.php
+++ /tmp/dsg/dolibarr/htdocs/contrat/client_index.php
@@ -40,2 +40,2 @@
-$sortfield = GETPOST('sortfield', 'aZ09comma');

-$sortorder = GETPOST('sortorder', 'aZ09comma');

+$sortfield = GETPOST('sortfield', 'alpha');

+$sortorder = GETPOST('sortorder', 'alpha');

@@ -44 +44 @@
-$statut = GETPOST('statut') ? GETPOST('statut') : 1;

+$statut = GETPOST('statut') ?GETPOST('statut') : 1;

@@ -49,3 +49 @@
-if (!empty($user->socid)) {

-	$socid = $user->socid;

-}

+if (!empty($user->socid)) $socid = $user->socid;

@@ -73,4 +71 @@
-$title = $langs->trans("ContractsArea");

-$help_url = '';

-

-llxHeader('', $title, $help_url);

+llxHeader();

@@ -80,0 +76,2 @@
+//print '<table border="0" width="100%" class="notopnoleftnoright">';

+//print '<tr><td valign="top" width="30%" class="notopnoleft">';

@@ -81,0 +79,20 @@
+

+

+if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS))     // This is useless due to the global search combo

+{

+    // Search contract

+    if (!empty($conf->contrat->enabled))

+    {

+    	print '<form method="post" action="'.DOL_URL_ROOT.'/contrat/list.php">';

+    	print '<input type="hidden" name="token" value="'.newToken().'">';

+

+		print '<div class="div-table-responsive-no-min">';

+    	print '<table class="noborder nohover centpercent">';

+    	print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';

+    	print '<tr class="oddeven">';

+    	print '<td class="nowrap">'.$langs->trans("Contract").':</td><td><input type="text" class="flat" name="sall" size="18"></td>';

+    	print '<td><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';

+    	print "</table></div></form>\n";

+    	print "<br>";

+    }

+}

@@ -98,3 +115 @@
-if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {

-	$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";

-}

+if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";

@@ -104,6 +119,2 @@
-if ($user->socid) {

-	$sql .= ' AND c.fk_soc = '.((int) $user->socid);

-}

-if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {

-	$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);

-}

+if ($user->socid) $sql .= ' AND c.fk_soc = '.$user->socid;

+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;

@@ -112 +123,2 @@
-if ($resql) {

+if ($resql)

+{

@@ -115 +127,2 @@
-	while ($i < $num) {

+	while ($i < $num)

+	{

@@ -117 +130,2 @@
-		if ($obj) {

+		if ($obj)

+		{

@@ -119,5 +133,6 @@
-			if ($obj->status != 5) {

-				$vals[$obj->status] = $obj->nb;

-				$totalinprocess += $obj->nb;

-			}

-			$total += $obj->nb;

+			if ($obj->status != 5)

+            {

+            	$vals[$obj->status] = $obj->nb;

+            	$totalinprocess += $obj->nb;

+            }

+            $total += $obj->nb;

@@ -128 +143,3 @@
-} else {

+}

+else

+{

@@ -135,3 +152 @@
-if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {

-	$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";

-}

+if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";

@@ -141,6 +156,2 @@
-if ($user->socid) {

-	$sql .= ' AND c.fk_soc = '.((int) $user->socid);

-}

-if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {

-	$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);

-}

+if ($user->socid) $sql .= ' AND c.fk_soc = '.$user->socid;

+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;

@@ -149 +160,2 @@
-if ($resql) {

+if ($resql)

+{

@@ -152,16 +164,21 @@
-	// 0 inactive, 4 active, 5 closed

-	$i = 0;

-	while ($i < $num) {

-		$obj = $db->fetch_object($resql);

-		if ($obj) {

-			$nb[$obj->status.true] = $obj->nb;

-			if ($obj->status != 5) {

-				$vals[$obj->status.true] = $obj->nb;

-				$totalinprocess += $obj->nb;

-			}

-			$total += $obj->nb;

-		}

-		$i++;

-	}

-	$db->free($resql);

-} else {

+    // 0 inactive, 4 active, 5 closed

+    $i = 0;

+    while ($i < $num)

+    {

+        $obj = $db->fetch_object($resql);

+        if ($obj)

+        {

+        	$nb[$obj->status.true] = $obj->nb;

+            if ($obj->status != 5)

+            {

+            	$vals[$obj->status.true] = $obj->nb;

+            	$totalinprocess += $obj->nb;

+            }

+            $total += $obj->nb;

+        }

+        $i++;

+    }

+    $db->free($resql);

+}

+else

+{

@@ -173 +190 @@
-include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';

+include_once DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';

@@ -179,42 +196,34 @@
-foreach ($listofstatus as $status) {

-	$dataseries[] = array($staticcontratligne->LibStatut($status, 1, ($bool ? 1 : 0)), (isset($nb[$status.$bool]) ? (int) $nb[$status.$bool] : 0));

-	if ($status == ContratLigne::STATUS_INITIAL) {

-		$colorseries[$status.$bool] = '-'.$badgeStatus0;

-	}

-	if ($status == ContratLigne::STATUS_OPEN && !$bool) {

-		$colorseries[$status.$bool] = $badgeStatus4;

-	}

-	if ($status == ContratLigne::STATUS_OPEN && $bool) {

-		$colorseries[$status.$bool] = $badgeStatus1;

-	}

-	if ($status == ContratLigne::STATUS_CLOSED) {

-		$colorseries[$status.$bool] = $badgeStatus6;

-	}

-

-	if (empty($conf->use_javascript_ajax)) {

-		print '<tr class="oddeven">';

-		print '<td>'.$staticcontratligne->LibStatut($status, 0, ($bool ? 1 : 0)).'</td>';

-		print '<td class="right"><a href="services_list.php?search_status='.((int) $status).($bool ? '&filter=expired' : '').'">'.($nb[$status.$bool] ? $nb[$status.$bool] : 0).' '.$staticcontratligne->LibStatut($status, 3, ($bool ? 1 : 0)).'</a></td>';

-		print "</tr>\n";

-	}

-	if ($status == 4 && !$bool) {

-		$bool = true;

-	} else {

-		$bool = false;

-	}

-}

-if (!empty($conf->use_javascript_ajax)) {

-	print '<tr class="impair"><td class="center" colspan="2">';

-

-	include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';

-	$dolgraph = new DolGraph();

-	$dolgraph->SetData($dataseries);

-	$dolgraph->SetDataColor(array_values($colorseries));

-	$dolgraph->setShowLegend(2);

-	$dolgraph->setShowPercent(1);

-	$dolgraph->SetType(array('pie'));

-	$dolgraph->setHeight('200');

-	$dolgraph->draw('idgraphstatus');

-	print $dolgraph->show($total ? 0 : 1);

-

-	print '</td></tr>';

+foreach ($listofstatus as $status)

+{

+    $dataseries[] = array($staticcontratligne->LibStatut($status, 1, ($bool ? 1 : 0)), (isset($nb[$status.$bool]) ? (int) $nb[$status.$bool] : 0));

+    if ($status == ContratLigne::STATUS_INITIAL) $colorseries[$status.$bool] = '-'.$badgeStatus0;

+    if ($status == ContratLigne::STATUS_OPEN && !$bool) $colorseries[$status.$bool] = $badgeStatus4;

+    if ($status == ContratLigne::STATUS_OPEN && $bool) $colorseries[$status.$bool] = $badgeStatus1;

+    if ($status == ContratLigne::STATUS_CLOSED) $colorseries[$status.$bool] = $badgeStatus6;

+

+    if (empty($conf->use_javascript_ajax))

+    {

+        print '<tr class="oddeven">';

+        print '<td>'.$staticcontratligne->LibStatut($status, 0, ($bool ? 1 : 0)).'</td>';

+        print '<td class="right"><a href="services_list.php?mode='.$status.($bool ? '&filter=expired' : '').'">'.($nb[$status.$bool] ? $nb[$status.$bool] : 0).' '.$staticcontratligne->LibStatut($status, 3, ($bool ? 1 : 0)).'</a></td>';

+        print "</tr>\n";

+    }

+    if ($status == 4 && !$bool) $bool = true;

+    else $bool = false;

+}

+if (!empty($conf->use_javascript_ajax))

+{

+    print '<tr class="impair"><td class="center" colspan="2">';

+

+    include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';

+    $dolgraph = new DolGraph();

+    $dolgraph->SetData($dataseries);

+    $dolgraph->SetDataColor(array_values($colorseries));

+    $dolgraph->setShowLegend(2);

+    $dolgraph->setShowPercent(1);

+    $dolgraph->SetType(array('pie'));

+    $dolgraph->setHeight('200');

+    $dolgraph->draw('idgraphstatus');

+    print $dolgraph->show($total ? 0 : 1);

+

+    print '</td></tr>';

@@ -223,13 +232,14 @@
-foreach ($listofstatus as $status) {

-	if (empty($conf->use_javascript_ajax)) {

-		print '<tr class="oddeven">';

-		print '<td>'.$staticcontratligne->LibStatut($status, 0, ($bool ? 1 : 0)).'</td>';

-		print '<td class="right"><a href="services_list.php?search_status='.((int) $status).($bool ? '&filter=expired' : '').'">'.($nb[$status.$bool] ? $nb[$status.$bool] : 0).' '.$staticcontratligne->LibStatut($status, 3, ($bool ? 1 : 0)).'</a></td>';

-		if ($status == 4 && !$bool) {

-			$bool = true;

-		} else {

-			$bool = false;

-		}

-		print "</tr>\n";

-	}

-}

+foreach ($listofstatus as $status)

+{

+    if (empty($conf->use_javascript_ajax))

+    {

+    	print '<tr class="oddeven">';

+    	print '<td>'.$staticcontratligne->LibStatut($status, 0, ($bool ? 1 : 0)).'</td>';

+    	print '<td class="right"><a href="services_list.php?mode='.$status.($bool ? '&filter=expired' : '').'">'.($nb[$status.$bool] ? $nb[$status.$bool] : 0).' '.$staticcontratligne->LibStatut($status, 3, ($bool ? 1 : 0)).'</a></td>';

+    	if ($status == 4 && !$bool) $bool = true;

+    	else $bool = false;

+        print "</tr>\n";

+    }

+}

+//if ($totalinprocess != $total)

+//print '<tr class="liste_total"><td>'.$langs->trans("Total").' ('.$langs->trans("ServicesRunning").')</td><td class="right">'.$totalinprocess.'</td></tr>';

@@ -242 +252,2 @@
-if (isModEnabled('contrat') && $user->hasRight('contrat', 'lire')) {

+if (!empty($conf->contrat->enabled) && $user->rights->contrat->lire)

+{

@@ -244 +255 @@
-	$sql .= " s.nom as name, s.name_alias, s.logo, s.rowid as socid, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";

+	$sql .= " s.nom as name, s.rowid as socid";

@@ -246,3 +257 @@
-	if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {

-		$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";

-	}

+	if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";

@@ -252,6 +261,2 @@
-	if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {

-		$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);

-	}

-	if ($socid) {

-		$sql .= " AND c.fk_soc = ".((int) $socid);

-	}

+	if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;

+	if ($socid) $sql .= " AND c.fk_soc = ".$socid;

@@ -261 +266,2 @@
-	if ($resql) {

+	if ($resql)

+	{

@@ -268 +274,4 @@
-		if ($num) {

+		if ($num)

+		{

+			$companystatic = new Societe($db);

+

@@ -271 +280,2 @@
-			while ($i < $num) {

+			while ($i < $num)

+			{

@@ -277,10 +287,3 @@
-				$staticcompany->id = $obj->socid;

-				$staticcompany->name = $obj->name;

-				$staticcompany->name_alias = $obj->name_alias;

-				$staticcompany->photo = 1;

-				$staticcompany->code_client = $obj->code_client;

-				$staticcompany->code_fournisseur = $obj->code_fournisseur;

-				$staticcompany->code_compta = $obj->code_compta;

-				$staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;

-				$staticcompany->client = $obj->client;

-				$staticcompany->fournisseur = $obj->fournisseur;

+				$companystatic->id = $obj->socid;

+				$companystatic->name = $obj->name;

+				$companystatic->client = 1;

@@ -292 +295 @@
-				print $staticcompany->getNomUrl(1, '', 16);

+				print $companystatic->getNomUrl(1, '', 16);

@@ -298,2 +301,4 @@
-		} else {

-			print '<tr class="oddeven"><td colspan="3"><span class="opacitymedium">'.$langs->trans("NoContracts").'</span></td></tr>';

+		}

+		else

+		{

+			print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoContracts").'</td></tr>';

@@ -303 +308,3 @@
-	} else {

+	}

+	else

+	{

@@ -309 +316,2 @@
-print '</div><div class="fichetwothirdright">';

+//print '</td><td valign="top" width="70%" class="notopnoleftnoright">';

+print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';

@@ -315,7 +323,6 @@
-$sql .= " sum(".$db->ifsql("cd.statut=0", 1, 0).') as nb_initial,';

-$sql .= " sum(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite >= '".$db->idate($now)."')", 1, 0).') as nb_running,';

-$sql .= " sum(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now)."')", 1, 0).') as nb_expired,';

-$sql .= " sum(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now - $conf->contrat->services->expires->warning_delay)."')", 1, 0).') as nb_late,';

-$sql .= " sum(".$db->ifsql("cd.statut=5", 1, 0).') as nb_closed,';

-$sql .= " c.rowid as cid, c.ref, c.datec, c.tms, c.statut,";

-$sql .= " s.nom as name, s.name_alias, s.logo, s.rowid as socid, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";

+$sql .= ' sum('.$db->ifsql("cd.statut=0", 1, 0).') as nb_initial,';

+$sql .= ' sum('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite >= '".$db->idate($now)."')", 1, 0).') as nb_running,';

+$sql .= ' sum('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now)."')", 1, 0).') as nb_expired,';

+$sql .= ' sum('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now - $conf->contrat->services->expires->warning_delay)."')", 1, 0).') as nb_late,';

+$sql .= ' sum('.$db->ifsql("cd.statut=5", 1, 0).') as nb_closed,';

+$sql .= " c.rowid as cid, c.ref, c.datec, c.tms, c.statut, s.nom as name, s.rowid as socid";

@@ -323,3 +330 @@
-if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {

-	$sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";

-}

+if (!$user->rights->societe->client->voir && !$socid) $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";

@@ -331,8 +336,3 @@
-if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {

-	$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);

-}

-if ($socid) {

-	$sql .= " AND s.rowid = ".((int) $socid);

-}

-$sql .= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.statut,";

-$sql .= " s.nom, s.name_alias, s.logo, s.rowid, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";

+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;

+if ($socid) $sql .= " AND s.rowid = ".$socid;

+$sql .= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.statut, s.nom, s.rowid";

@@ -340 +340 @@
-$sql .= $db->plimit($max);

+$sql .= " LIMIT ".$max;

@@ -344 +344,2 @@
-if ($result) {

+if ($result)

+{

@@ -357 +358,2 @@
-	while ($i < $num) {

+	while ($i < $num)

+	{

@@ -359,2 +361,3 @@
-		$datem = $db->jdate($obj->tms);

-

+

+		print '<tr class="oddeven">';

+		print '<td class="nowraponall">';

@@ -363 +366,4 @@
-

+		print $staticcontrat->getNomUrl(1, 16);

+		if ($obj->nb_late) print img_warning($langs->trans("Late"));

+		print '</td>';

+		print '<td>';

@@ -366,18 +371,0 @@
-		$staticcompany->name_alias = $obj->name_alias;

-		$staticcompany->photo = 1;

-		$staticcompany->code_client = $obj->code_client;

-		$staticcompany->code_fournisseur = $obj->code_fournisseur;

-		$staticcompany->code_compta = $obj->code_compta;

-		$staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;

-		$staticcompany->client = $obj->client;

-		$staticcompany->fournisseur = $obj->fournisseur;

-

-		print '<tr class="oddeven">';

-		print '<td class="nowraponall">';

-		print $staticcontrat->getNomUrl(1, 16);

-		if ($obj->nb_late) {

-			print img_warning($langs->trans("Late"));

-		}

-		print '</td>';

-

-		print '<td class="tdoverflowmax150">';

@@ -386,3 +374 @@
-		print '<td class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';

-		print dol_print_date($datem, 'dayhour');

-		print '</td>';

+		print '<td class="center">'.dol_print_date($db->jdate($obj->tms), 'dayhour').'</td>';

@@ -400 +386,3 @@
-} else {

+}

+else

+{

@@ -407 +395 @@
-$sql = "SELECT c.ref, c.fk_soc as socid,";

+$sql = "SELECT c.ref, c.fk_soc, ";

@@ -409 +397 @@
-$sql .= " s.nom as name, s.name_alias, s.logo, s.rowid as socid, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,";

+$sql .= " s.nom as name,";

@@ -413,3 +401 @@
-if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {

-	$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";

-}

+if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";

@@ -421,6 +407,2 @@
-if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {

-	$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);

-}

-if ($socid) {

-	$sql .= " AND s.rowid = ".((int) $socid);

-}

+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;

+if ($socid) $sql .= " AND s.rowid = ".$socid;

@@ -430 +412,2 @@
-if ($resql) {

+if ($resql)

+{

@@ -440 +423,2 @@
-	while ($i < min($num, $max)) {

+	while ($i < min($num, $max))

+	{

@@ -445 +428,0 @@
-

@@ -448,2 +431,21 @@
-

-		$staticcompany->id = $obj->socid;

+		print $staticcontrat->getNomUrl(1, 16);

+		//if (1 == 1) print img_warning($langs->trans("Late"));

+		print '</td>';

+		print '<td>';

+		if ($obj->fk_product > 0)

+		{

+    		$productstatic->id = $obj->fk_product;

+            $productstatic->type = $obj->ptype;

+            $productstatic->ref = $obj->pref;

+			$productstatic->entity = $obj->pentity;

+            print $productstatic->getNomUrl(1, '', 20);

+		}

+		else

+		{

+		    print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");

+            if ($obj->label) print ' '.dol_trunc($obj->label, 20).'</a>';

+            else print '</a> '.dol_trunc($obj->note, 20);

+		}

+		print '</td>';

+		print '<td>';

+		$staticcompany->id = $obj->fk_soc;

@@ -451,30 +452,0 @@
-		$staticcompany->name_alias = $obj->name_alias;

-		$staticcompany->photo = 1;

-		$staticcompany->code_client = $obj->code_client;

-		$staticcompany->code_fournisseur = $obj->code_fournisseur;

-		$staticcompany->code_compta = $obj->code_compta;

-		$staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;

-		$staticcompany->client = $obj->client;

-		$staticcompany->fournisseur = $obj->fournisseur;

-

-		print $staticcontrat->getNomUrl(1, 16);

-

-		//if (1 == 1) print img_warning($langs->trans("Late"));

-		print '</td>';

-		print '<td>';

-		if ($obj->fk_product > 0) {

-			$productstatic->id = $obj->fk_product;

-			$productstatic->type = $obj->ptype;

-			$productstatic->ref = $obj->pref;

-			$productstatic->entity = $obj->pentity;

-			print $productstatic->getNomUrl(1, '', 20);

-		} else {

-			print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");

-			if ($obj->label) {

-				print ' '.dol_trunc($obj->label, 20).'</a>';

-			} else {

-				print '</a> '.dol_trunc($obj->note, 20);

-			}

-		}

-		print '</td>';

-		print '<td class="tdoverflowmax125">';

@@ -490 +462 @@
-	$db->free($resql);

+	$db->free();

@@ -493 +465,3 @@
-} else {

+}

+else

+{

@@ -500,2 +474,2 @@
-$sql = "SELECT c.ref, c.fk_soc as thirdpartyid, cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat,";

-$sql .= " s.nom as name, s.name_alias, s.logo, s.rowid as socid, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,";

+$sql = "SELECT c.ref, c.fk_soc, cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat,";

+$sql .= " s.nom as name,";

@@ -505,3 +479 @@
-if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {

-	$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";

-}

+if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";

@@ -515,6 +487,2 @@
-if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {

-	$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);

-}

-if ($socid) {

-	$sql .= " AND s.rowid = ".((int) $socid);

-}

+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;

+if ($socid) $sql .= " AND s.rowid = ".$socid;

@@ -524 +492,2 @@
-if ($resql) {

+if ($resql)

+{

@@ -534 +503,2 @@
-	while ($i < $num) {

+	while ($i < $num)

+	{

@@ -537,11 +507,3 @@
-		$staticcompany->id = $obj->thirdpartyid;

-		$staticcompany->name = $obj->name;

-		$staticcompany->name_alias = $obj->name_alias;

-		$staticcompany->photo = 1;

-		$staticcompany->code_client = $obj->code_client;

-		$staticcompany->code_fournisseur = $obj->code_fournisseur;

-		$staticcompany->code_compta = $obj->code_compta;

-		$staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;

-		$staticcompany->client = $obj->client;

-		$staticcompany->fournisseur = $obj->fournisseur;

-

+		print '<tr class="oddeven">';

+

+		print '<td class="nowraponall">';

@@ -550,9 +511,0 @@
-

-		$productstatic->id = $obj->fk_product;

-		$productstatic->type = $obj->ptype;

-		$productstatic->ref = $obj->pref;

-		$productstatic->entity = $obj->pentity;

-

-		print '<tr class="oddeven">';

-

-		print '<td class="nowraponall">';

@@ -562,12 +515,18 @@
-		if ($obj->fk_product > 0) {

-			print $productstatic->getNomUrl(1, '', 20);

-		} else {

-			print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");

-			if ($obj->label) {

-				print ' '.dol_trunc($obj->label, 20).'</a>';

-			} else {

-				print '</a> '.dol_trunc($obj->note, 20);

-			}

-		}

-		print '</td>';

-		print '<td class="tdoverflowmax125">';

+		if ($obj->fk_product > 0)

+		{

+    		$productstatic->id = $obj->fk_product;

+            $productstatic->type = $obj->ptype;

+            $productstatic->ref = $obj->pref;

+			$productstatic->entity = $obj->pentity;

+            print $productstatic->getNomUrl(1, '', 20);

+		}

+		else

+		{

+		    print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");

+            if ($obj->label) print ' '.dol_trunc($obj->label, 20).'</a>';

+            else print '</a> '.dol_trunc($obj->note, 20);

+		}

+        print '</td>';

+		print '<td>';

+		$staticcompany->id = $obj->fk_soc;

+		$staticcompany->name = $obj->name;

@@ -582,2 +541 @@
-

-	$db->free($resql);

+	$db->free();

@@ -586 +544,3 @@
-} else {

+}

+else

+{

@@ -593,2 +553,2 @@
-$sql = "SELECT c.ref, c.fk_soc as thirdpartyid, cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat,";

-$sql .= " s.nom as name, s.name_alias, s.logo, s.rowid as socid, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,";

+$sql = "SELECT c.ref, c.fk_soc, cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat,";

+$sql .= " s.nom as name,";

@@ -598,3 +558 @@
-if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {

-	$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";

-}

+if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";

@@ -609,6 +567,2 @@
-if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {

-	$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);

-}

-if ($socid) {

-	$sql .= " AND s.rowid = ".((int) $socid);

-}

+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;

+if ($socid) $sql .= " AND s.rowid = ".$socid;

@@ -618 +572,2 @@
-if ($resql) {

+if ($resql)

+{

@@ -625 +580 @@
-	print '<tr class="liste_titre"><th colspan="4">'.$langs->trans("ListOfExpiredServices").' <a href="'.DOL_URL_ROOT.'/contrat/services_list.php?search_status=4&amp;filter=expired"><span class="badge">'.$num.'</span></a></th>';

+	print '<tr class="liste_titre"><th colspan="4">'.$langs->trans("ListOfExpiredServices").' <a href="'.DOL_URL_ROOT.'/contrat/services_list.php?mode=4&amp;filter=expired"><span class="badge">'.$num.'</span></a></th>';

@@ -628 +583,2 @@
-	while ($i < $num) {

+	while ($i < $num)

+	{

@@ -631,11 +587,3 @@
-		$staticcompany->id = $obj->thirdpartyid;

-		$staticcompany->name = $obj->name;

-		$staticcompany->name_alias = $obj->name_alias;

-		$staticcompany->photo = 1;

-		$staticcompany->code_client = $obj->code_client;

-		$staticcompany->code_fournisseur = $obj->code_fournisseur;

-		$staticcompany->code_compta = $obj->code_compta;

-		$staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;

-		$staticcompany->client = $obj->client;

-		$staticcompany->fournisseur = $obj->fournisseur;

-

+		print '<tr class="oddeven">';

+

+		print '<td class="nowraponall">';

@@ -644,9 +591,0 @@
-

-		$productstatic->id = $obj->fk_product;

-		$productstatic->type = $obj->ptype;

-		$productstatic->ref = $obj->pref;

-		$productstatic->entity = $obj->pentity;

-

-		print '<tr class="oddeven">';

-

-		print '<td class="nowraponall">';

@@ -656,12 +595,18 @@
-		if ($obj->fk_product > 0) {

-			print $productstatic->getNomUrl(1, '', 20);

-		} else {

-			print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");

-			if ($obj->label) {

-				print ' '.dol_trunc($obj->label, 20).'</a>';

-			} else {

-				print '</a> '.dol_trunc($obj->note, 20);

-			}

-		}

-		print '</td>';

-		print '<td class="tdoverflowmax125">';

+		if ($obj->fk_product > 0)

+		{

+    		$productstatic->id = $obj->fk_product;

+            $productstatic->type = $obj->ptype;

+            $productstatic->ref = $obj->pref;

+			$productstatic->entity = $obj->pentity;

+            print $productstatic->getNomUrl(1, '', 20);

+		}

+		else

+		{

+		    print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");

+            if ($obj->label) print ' '.dol_trunc($obj->label, 20).'</a>';

+            else print '</a> '.dol_trunc($obj->note, 20);

+		}

+		print '</td>';

+		print '<td>';

+		$staticcompany->id = $obj->fk_soc;

+		$staticcompany->name = $obj->name;

@@ -676 +621 @@
-	$db->free($resql);

+	$db->free();

@@ -679 +624,3 @@
-} else {

+}

+else

+{

@@ -684 +631,2 @@
-print '</div></div>';

+//print '</td></tr></table>';

+print '</div></div></div>';

--- /tmp/dsg/dolibarr/htdocs/contrat/github_19.0.3_list.php
+++ /tmp/dsg/dolibarr/htdocs/contrat/client_list.php
@@ -10,2 +10 @@
- * Copyright (C) 2019      Nicolas Zabouri      <info@inovea-conseil.com>

- * Copyright (C) 2021      Alexandre Spangaro	<aspangaro@open-dsi.fr>

+ * Copyright (C) 2019      Nicolas ZABOURI      <info@inovea-conseil.com>

@@ -33 +31,0 @@
-// Load Dolibarr environment

@@ -38 +35,0 @@
-require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';

@@ -41,3 +37,0 @@
-if (isModEnabled("categorie")) {

-	require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';

-}

@@ -48 +42 @@
-$action = GETPOST('action', 'aZ09');

+$action = GETPOST('action', 'alpha');

@@ -53,3 +47 @@
-$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'contractlist'; // To manage different context of search

-$optioncss = GETPOST('optioncss', 'alpha');

-$mode = GETPOST('mode', 'alpha');

+$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'contractlist'; // To manage different context of search

@@ -61 +53 @@
-$search_state = GETPOST("search_state", 'alpha');

+$search_state = trim(GETPOST("search_state", 'alpha'));

@@ -67 +59 @@
-$search_all = (GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');

+$sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));

@@ -76,38 +68,9 @@
-$search_date_startday = GETPOST('search_date_startday', 'int');

-$search_date_startmonth = GETPOST('search_date_startmonth', 'int');

-$search_date_startyear = GETPOST('search_date_startyear', 'int');

-$search_date_endday = GETPOST('search_date_endday', 'int');

-$search_date_endmonth = GETPOST('search_date_endmonth', 'int');

-$search_date_endyear = GETPOST('search_date_endyear', 'int');

-$search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear);	// Use tzserver

-$search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);

-$searchCategoryCustomerOperator = 0;

-if (GETPOSTISSET('formfilteraction')) {

-	$searchCategoryCustomerOperator = GETPOST('search_category_customer_operator', 'int');

-} elseif (getDolGlobalString('MAIN_SEARCH_CAT_OR_BY_DEFAULT')) {

-	$searchCategoryCustomerOperator = $conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT;

-}

-$searchCategoryCustomerList = GETPOST('search_category_customer_list', 'array');

-

-$search_date_creation_startmonth = GETPOST('search_date_creation_startmonth', 'int');

-$search_date_creation_startyear = GETPOST('search_date_creation_startyear', 'int');

-$search_date_creation_startday = GETPOST('search_date_creation_startday', 'int');

-$search_date_creation_start = dol_mktime(0, 0, 0, $search_date_creation_startmonth, $search_date_creation_startday, $search_date_creation_startyear);	// Use tzserver

-$search_date_creation_endmonth = GETPOST('search_date_creation_endmonth', 'int');

-$search_date_creation_endyear = GETPOST('search_date_creation_endyear', 'int');

-$search_date_creation_endday = GETPOST('search_date_creation_endday', 'int');

-$search_date_creation_end = dol_mktime(23, 59, 59, $search_date_creation_endmonth, $search_date_creation_endday, $search_date_creation_endyear);	// Use tzserver

-

-$search_date_modif_startmonth = GETPOST('search_date_modif_startmonth', 'int');

-$search_date_modif_startyear = GETPOST('search_date_modif_startyear', 'int');

-$search_date_modif_startday = GETPOST('search_date_modif_startday', 'int');

-$search_date_modif_start = dol_mktime(0, 0, 0, $search_date_modif_startmonth, $search_date_modif_startday, $search_date_modif_startyear);	// Use tzserver

-$search_date_modif_endmonth = GETPOST('search_date_modif_endmonth', 'int');

-$search_date_modif_endyear = GETPOST('search_date_modif_endyear', 'int');

-$search_date_modif_endday = GETPOST('search_date_modif_endday', 'int');

-$search_date_modif_end = dol_mktime(23, 59, 59, $search_date_modif_endmonth, $search_date_modif_endday, $search_date_modif_endyear);	// Use tzserver

-

-// Load variable for pagination

-$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;

-$sortfield = GETPOST('sortfield', 'aZ09comma');

-$sortorder = GETPOST('sortorder', 'aZ09comma');

+$day = GETPOST("day", "int");

+$year = GETPOST("year", "int");

+$month = GETPOST("month", "int");

+

+$optioncss = GETPOST('optioncss', 'alpha');

+

+$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;

+$sortfield = GETPOST("sortfield", 'alpha');

+$sortorder = GETPOST("sortorder", 'alpha');

@@ -115,4 +78 @@
-if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {

-	// If $page is not defined, or '' or -1 or if we click on clear filters

-	$page = 0;

-}

+if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1

@@ -122,6 +82,2 @@
-if (!$sortfield) {

-	$sortfield = 'c.ref';

-}

-if (!$sortorder) {

-	$sortorder = 'DESC';

-}

+if (!$sortfield) $sortfield = 'c.ref';

+if (!$sortorder) $sortorder = 'DESC';

@@ -131,3 +87 @@
-if ($user->socid) {

-	$socid = $user->socid;

-}

+if ($user->socid) $socid = $user->socid;

@@ -141,3 +95 @@
-if ($search_status == '') {

-	$search_status = 1;

-}

+if ($search_status == '') $search_status = 1;

@@ -151 +103 @@
-$extrafields->fetch_name_optionals_label($object->table_element);

+$extrafields->fetch_name_optionals_label('contrat');

@@ -155,19 +107,8 @@
-$fieldstosearchall = array();

-foreach ($object->fields as $key => $val) {

-	if (!empty($val['searchall'])) {

-		$fieldstosearchall['c.'.$key] = $val['label'];

-	}

-}

-$fieldstosearchall["s.nom"] = "ThirdParty";

-if (empty($user->socid)) {

-	$fieldstosearchall["c.note_private"] = "NotePrivate";

-}

-$parameters = array('fieldstosearchall'=>$fieldstosearchall);

-$reshook = $hookmanager->executeHooks('completeFieldsToSearchAll', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks

-if ($reshook > 0) {

-	$fieldstosearchall = $hookmanager->resArray['fieldstosearchall'];

-} elseif ($reshook == 0) {

-	if (!empty($hookmanager->resArray['fieldstosearchall'])) {

-		$fieldstosearchall = array_merge($fieldstosearchall, $hookmanager->resArray['fieldstosearchall']);

-	}

-}

+$fieldstosearchall = array(

+	'c.ref'=>'Ref',

+	'c.ref_customer'=>'RefCustomer',

+	'c.ref_supplier'=>'RefSupplier',

+	's.nom'=>"ThirdParty",

+	'c.note_public'=>'NotePublic',

+);

+if (empty($user->socid)) $fieldstosearchall["c.note_private"] = "NotePrivate";

@@ -176,11 +117,11 @@
-	'c.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1, 'position'=>10),

-	'c.ref_customer'=>array('label'=>$langs->trans("RefCustomer"), 'checked'=>1, 'position'=>12),

-	'c.ref_supplier'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1, 'position'=>14),

-	's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1, 'position'=>30),

-	's.email'=>array('label'=>$langs->trans("ThirdPartyEmail"), 'checked'=>0, 'position'=>30),

-	's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>0, 'position'=>31),

-	's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1, 'position'=>32),

-	'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0, 'position'=>33),

-	'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0, 'position'=>34),

-	'sale_representative'=>array('label'=>$langs->trans("SaleRepresentativesOfThirdParty"), 'checked'=>-1, 'position'=>80),

-	'c.date_contrat'=>array('label'=>$langs->trans("DateContract"), 'checked'=>1, 'position'=>45),

+	'c.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),

+	'c.ref_customer'=>array('label'=>$langs->trans("RefCustomer"), 'checked'=>1),

+	'c.ref_supplier'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1),

+	's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),

+	's.email'=>array('label'=>$langs->trans("ThirdPartyEmail"), 'checked'=>0),

+	's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>0),

+	's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>0),

+	'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0),

+	'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0),

+	'sale_representative'=>array('label'=>$langs->trans("SaleRepresentativesOfThirdParty"), 'checked'=>1),

+	'c.date_contrat'=>array('label'=>$langs->trans("DateContract"), 'checked'=>1),

@@ -193,2 +134,8 @@
-include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';

-

+if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0)

+{

+	foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val)

+	{

+		if (!empty($extrafields->attributes[$object->table_element]['list'][$key]))

+			$arrayfields["ef.".$key] = array('label'=>$extrafields->attributes[$object->table_element]['label'][$key], 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key] < 0) ? 0 : 1), 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3 && $extrafields->attributes[$object->table_element]['perms'][$key]));

+	}

+}

@@ -198,11 +144,0 @@
-if (!$user->hasRight('societe', 'client', 'voir')) {

-	$search_sale = $user->id;

-}

-

-$permissiontoread = $user->hasRight('contrat', 'lire');

-$permissiontoadd = $user->hasRight('contrat', 'creer');

-$permissiontodelete = $user->hasRight('contrat', 'supprimer');

-

-$result = restrictedArea($user, 'contrat', 0);

-

-

@@ -211 +147 @@
- * Actions

+ * Action

@@ -214,7 +150,2 @@
-if (GETPOST('cancel', 'alpha')) {

-	$action = 'list';

-	$massaction = '';

-}

-if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {

-	$massaction = '';

-}

+if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }

+if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }

@@ -224,3 +155 @@
-if ($reshook < 0) {

-	setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

-}

+if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

@@ -228,0 +158 @@
+

@@ -230 +160,5 @@
-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

+{

+	$day = '';

+	$month = '';

+	$year = '';

@@ -247,25 +181 @@
-	$search_date_startday = '';

-	$search_date_startmonth = '';

-	$search_date_startyear = '';

-	$search_date_endday = '';

-	$search_date_endmonth = '';

-	$search_date_endyear = '';

-	$search_date_start = '';

-	$search_date_end = '';

-	$search_all = "";

-	$search_date_creation_startmonth = "";

-	$search_date_creation_startyear = "";

-	$search_date_creation_startday = "";

-	$search_date_creation_start = "";

-	$search_date_creation_endmonth = "";

-	$search_date_creation_endyear = "";

-	$search_date_creation_endday = "";

-	$search_date_creation_end = "";

-	$search_date_modif_startmonth = "";

-	$search_date_modif_startyear = "";

-	$search_date_modif_startday = "";

-	$search_date_modif_start = "";

-	$search_date_modif_endmonth = "";

-	$search_date_modif_endyear = "";

-	$search_date_modif_endday = "";

-	$search_date_modif_end = "";

+	$sall = "";

@@ -273,3 +183 @@
-	$toselect = array();

-	$search_type_thirdparty = '';

-	$searchCategoryCustomerList = array();

+	$toselect = '';

@@ -279 +187,2 @@
-if (empty($reshook)) {

+if (empty($reshook))

+{

@@ -281,0 +191,2 @@
+	$permissiontoread = $user->rights->contrat->lire;

+	$permissiontodelete = $user->rights->contrat->supprimer;

@@ -290,0 +202 @@
+$now = dol_now();

@@ -295 +206,0 @@
-$formcompany = new FormCompany($db);

@@ -298,4 +208,0 @@
-$now = dol_now();

-

-$title = "";

-

@@ -303,2 +210,2 @@
-$sql .= " c.rowid, c.ref, c.datec as date_creation, c.tms as date_update, c.date_contrat, c.statut, c.ref_customer, c.ref_supplier, c.note_private, c.note_public, c.entity,";

-$sql .= ' s.rowid as socid, s.nom as name, s.name_alias, s.email, s.town, s.zip, s.fk_pays as country_id, s.client, s.code_client, s.status as company_status, s.logo as company_logo,';

+$sql .= " c.rowid, c.ref, c.datec as date_creation, c.tms as date_update, c.date_contrat, c.statut, c.ref_customer, c.ref_supplier, c.note_private, c.note_public,";

+$sql .= ' s.rowid as socid, s.nom as name, s.email, s.town, s.zip, s.fk_pays, s.client, s.code_client,';

@@ -308,5 +215,5 @@
-$sql .= " SUM(".$db->ifsql("cd.statut=0", 1, 0).') as nb_initial,';

-$sql .= " SUM(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite >= '".$db->idate($now)."')", 1, 0).') as nb_running,';

-$sql .= " SUM(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now)."')", 1, 0).') as nb_expired,';

-$sql .= " SUM(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now - $conf->contrat->services->expires->warning_delay)."')", 1, 0).') as nb_late,';

-$sql .= " SUM(".$db->ifsql("cd.statut=5", 1, 0).') as nb_closed';

+$sql .= ' SUM('.$db->ifsql("cd.statut=0", 1, 0).') as nb_initial,';

+$sql .= ' SUM('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite >= '".$db->idate($now)."')", 1, 0).') as nb_running,';

+$sql .= ' SUM('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now)."')", 1, 0).') as nb_expired,';

+$sql .= ' SUM('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now - $conf->contrat->services->expires->warning_delay)."')", 1, 0).') as nb_late,';

+$sql .= ' SUM('.$db->ifsql("cd.statut=5", 1, 0).') as nb_closed';

@@ -315,3 +222 @@
-	foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {

-		$sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');

-	}

+	foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');

@@ -321 +226 @@
-$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

+$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook

@@ -323,4 +227,0 @@
-$sql = preg_replace('/,\s*$/', '', $sql);

-

-$sqlfields = $sql; // $sql fields to remove for count total

-

@@ -330,0 +232 @@
+if ($search_sale > 0 || (!$user->rights->societe->client->voir && !$socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";

@@ -332,3 +234 @@
-if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {

-	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (c.rowid = ef.fk_object)";

-}

+if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (c.rowid = ef.fk_object)";

@@ -336 +236,3 @@
-if ($search_user > 0) {

+if ($search_product_category > 0) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product';

+if ($search_user > 0)

+{

@@ -342,142 +244,15 @@
-if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {

-	$sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')';

-}

-if ($socid > 0) {

-	$sql .= " AND s.rowid = ".((int) $socid);

-}

-if ($search_date_start) {

-	$sql .= " AND c.date_contrat >= '".$db->idate($search_date_start)."'";

-}

-if ($search_date_end) {

-	$sql .= " AND c.date_contrat <= '".$db->idate($search_date_end)."'";

-}

-if ($search_name) {

-	$sql .= natural_search('s.nom', $search_name);

-}

-if ($search_email) {

-	$sql .= natural_search('s.email', $search_email);

-}

-if ($search_contract) {

-	$sql .= natural_search(array('c.rowid', 'c.ref'), $search_contract);

-}

-if (!empty($search_ref_customer)) {

-	$sql .= natural_search(array('c.ref_customer'), $search_ref_customer);

-}

-if (!empty($search_ref_supplier)) {

-	$sql .= natural_search(array('c.ref_supplier'), $search_ref_supplier);

-}

-if ($search_zip) {

-	$sql .= natural_search(array('s.zip'), $search_zip);

-}

-if ($search_town) {

-	$sql .= natural_search(array('s.town'), $search_town);

-}

-if ($search_country && $search_country != '-1') {

-	$sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';

-}

-/*if ($search_sale > 0) {

-	$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);

-}*/

-if ($search_all) {

-	$sql .= natural_search(array_keys($fieldstosearchall), $search_all);

-}

-if ($search_user > 0) {

-	$sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='contrat' AND tc.source='internal' AND ec.element_id = c.rowid AND ec.fk_socpeople = ".((int) $search_user);

-}

-// Search on sale representative

-if ($search_sale && $search_sale != '-1') {

-	if ($search_sale == -2) {

-		$sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc)";

-	} elseif ($search_sale > 0) {

-		$sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc AND sc.fk_user = ".((int) $search_sale).")";

-	}

-}

-// Search for tag/category ($searchCategoryProductList is an array of ID)

-$searchCategoryProductOperator = -1;

-$searchCategoryProductList = array($search_product_category);

-if (!empty($searchCategoryProductList)) {

-	$searchCategoryProductSqlList = array();

-	$listofcategoryid = '';

-	foreach ($searchCategoryProductList as $searchCategoryProduct) {

-		if (intval($searchCategoryProduct) == -2) {

-			$searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."contratdet as cd WHERE cd.fk_contrat = c.rowid AND cd.fk_product = ck.fk_product)";

-		} elseif (intval($searchCategoryProduct) > 0) {

-			if ($searchCategoryProductOperator == 0) {

-				$searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."contratdet as cd WHERE cd.fk_contrat = c.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")";

-			} else {

-				$listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);

-			}

-		}

-	}

-	if ($listofcategoryid) {

-		$searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."contratdet as cd WHERE cd.fk_contrat = c.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";

-	}

-	if ($searchCategoryProductOperator == 1) {

-		if (!empty($searchCategoryProductSqlList)) {

-			$sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";

-		}

-	} else {

-		if (!empty($searchCategoryProductSqlList)) {

-			$sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";

-		}

-	}

-}

-$searchCategoryCustomerSqlList = array();

-if ($searchCategoryCustomerOperator == 1) {

-	$existsCategoryCustomerList = array();

-	foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {

-		if (intval($searchCategoryCustomer) == -2) {

-			$sqlCategoryCustomerNotExists  = " NOT EXISTS (";

-			$sqlCategoryCustomerNotExists .= " SELECT cat_cus.fk_soc";

-			$sqlCategoryCustomerNotExists .= " FROM ".$db->prefix()."categorie_societe AS cat_cus";

-			$sqlCategoryCustomerNotExists .= " WHERE cat_cus.fk_soc = s.rowid";

-			$sqlCategoryCustomerNotExists .= " )";

-			$searchCategoryCustomerSqlList[] = $sqlCategoryCustomerNotExists;

-		} elseif (intval($searchCategoryCustomer) > 0) {

-			$existsCategoryCustomerList[] = $db->escape($searchCategoryCustomer);

-		}

-	}

-	if (!empty($existsCategoryCustomerList)) {

-		$sqlCategoryCustomerExists = " EXISTS (";

-		$sqlCategoryCustomerExists .= " SELECT cat_cus.fk_soc";

-		$sqlCategoryCustomerExists .= " FROM ".$db->prefix()."categorie_societe AS cat_cus";

-		$sqlCategoryCustomerExists .= " WHERE cat_cus.fk_soc = s.rowid";

-		$sqlCategoryCustomerExists .= " AND cat_cus.fk_categorie IN (".$db->sanitize(implode(',', $existsCategoryCustomerList)).")";

-		$sqlCategoryCustomerExists .= " )";

-		$searchCategoryCustomerSqlList[] = $sqlCategoryCustomerExists;

-	}

-	if (!empty($searchCategoryCustomerSqlList)) {

-		$sql .= " AND (".implode(' OR ', $searchCategoryCustomerSqlList).")";

-	}

-} else {

-	foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {

-		if (intval($searchCategoryCustomer) == -2) {

-			$sqlCategoryCustomerNotExists = " NOT EXISTS (";

-			$sqlCategoryCustomerNotExists .= " SELECT cat_cus.fk_soc";

-			$sqlCategoryCustomerNotExists .= " FROM ".$db->prefix()."categorie_societe AS cat_cus";

-			$sqlCategoryCustomerNotExists .= " WHERE cat_cus.fk_soc = s.rowid";

-			$sqlCategoryCustomerNotExists .= " )";

-			$searchCategoryCustomerSqlList[] = $sqlCategoryCustomerNotExists;

-		} elseif (intval($searchCategoryCustomer) > 0) {

-			$searchCategoryCustomerSqlList[] = "s.rowid IN (SELECT fk_soc FROM ".$db->prefix()."categorie_societe WHERE fk_categorie = ".((int) $searchCategoryCustomer).")";

-		}

-	}

-	if (!empty($searchCategoryCustomerSqlList)) {

-		$sql .= " AND (".implode(' AND ', $searchCategoryCustomerSqlList).")";

-	}

-}

-

-if ($search_date_creation_start) {

-	$sql .= " AND c.datec >= '".$db->idate($search_date_creation_start)."'";

-}

-if ($search_date_creation_end) {

-	$sql .= " AND c.datec <= '".$db->idate($search_date_creation_end)."'";

-}

-

-if ($search_date_modif_start) {

-	$sql .= " AND c.tms >= '".$db->idate($search_date_modif_start)."'";

-}

-if ($search_date_modif_end) {

-	$sql .= " AND c.tms <= '".$db->idate($search_date_modif_end)."'";

-}

-

+if ($search_product_category > 0) $sql .= " AND cp.fk_categorie = ".$search_product_category;

+if ($socid) $sql .= " AND s.rowid = ".$db->escape($socid);

+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;

+$sql .= dolSqlDateFilter('c.date_contrat', $day, $month, $year);

+if ($search_name) $sql .= natural_search('s.nom', $search_name);

+if ($search_email) $sql .= natural_search('s.email', $search_email);

+if ($search_contract) $sql .= natural_search(array('c.rowid', 'c.ref'), $search_contract);

+if (!empty($search_ref_customer)) $sql .= natural_search(array('c.ref_customer'), $search_ref_customer);

+if (!empty($search_ref_supplier)) $sql .= natural_search(array('c.ref_supplier'), $search_ref_supplier);

+if ($search_sale > 0)

+{

+	$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$search_sale;

+}

+if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall);

+if ($search_user > 0) $sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='contrat' AND tc.source='internal' AND ec.element_id = c.rowid AND ec.fk_socpeople = ".$search_user;

@@ -488 +263 @@
-$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

+$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook

@@ -490,2 +265,2 @@
-$sql .= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.date_contrat, c.statut, c.ref_customer, c.ref_supplier, c.note_private, c.note_public, c.entity,";

-$sql .= ' s.rowid, s.nom, s.name_alias, s.email, s.town, s.zip, s.fk_pays, s.client, s.code_client, s.status, s.logo,';

+$sql .= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.date_contrat, c.statut, c.ref_customer, c.ref_supplier, c.note_private, c.note_public,";

+$sql .= ' s.rowid, s.nom, s.email, s.town, s.zip, s.fk_pays, s.client, s.code_client,';

@@ -496,3 +271 @@
-	foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {

-		$sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key : '');

-	}

+	foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key : '');

@@ -501,2 +274,2 @@
-$parameters = array('search_dfyear' => $search_dfyear, 'search_op2df'=>$search_op2df);

-$reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook

+$parameters = array();

+$reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters); // Note that $action and $object may have been modified by hook

@@ -504,17 +277,16 @@
-// Add HAVING from hooks

-$parameters = array('search_dfyear' => $search_dfyear, 'search_op2df'=>$search_op2df);

-$reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

-if (empty($reshook)) {

-	if ($search_dfyear > 0 && $search_op2df) {

-		if ($search_op2df == '<=') {

-			$sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear, $search_dfmonth, false))."'";

-		} elseif ($search_op2df == '>=') {

-			$sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear, $search_dfmonth, false))."'";

-		} else {

-			$sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear, $search_dfmonth, false))."' AND MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear, $search_dfmonth, false))."'";

-		}

-	}

-}

-$sql .= $hookmanager->resPrint;

-

-// Count total nb of records

+if ($search_dfyear > 0 && $search_op2df)

+{

+	if ($search_op2df == '<=') $sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear, $search_dfmonth, false))."'";

+	elseif ($search_op2df == '>=') $sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear, $search_dfmonth, false))."'";

+	else $sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear, $search_dfmonth, false))."' AND MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear, $search_dfmonth, false))."'";

+}

+$sql .= $db->order($sortfield, $sortorder);

+//print $sql;

+

+$totalnboflines = 0;

+$result = $db->query($sql);

+if ($result)

+{

+	$totalnboflines = $db->num_rows($result);

+}

+

@@ -522,29 +294,6 @@
-if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {

-	//$result = $db->query($sql);

-	//$nbtotalofrecords = $db->num_rows($result);

-

-	if ($search_dfyear > 0 && $search_op2df) {

-		$resql = $db->query($sql, 0, 'auto', 1);

-		while ($db->fetch_object($resql)) {

-			if (empty($nbtotalofrecords)) {

-				$nbtotalofrecords = 1;    // We can't make +1 because init value is ''

-			} else {

-				$nbtotalofrecords++;

-			}

-		}

-	} else {

-		/* The fast and low memory method to get and count full list converts the sql into a sql count */

-		$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);

-		$sqlforcount = preg_replace('/LEFT JOIN '.MAIN_DB_PREFIX.'contratdet as cd ON c.rowid = cd.fk_contrat /', '', $sqlforcount);

-		$sqlforcount = preg_replace('/GROUP BY.*$/', '', $sqlforcount);

-

-		$resql = $db->query($sqlforcount);

-		if ($resql) {

-			$objforcount = $db->fetch_object($resql);

-			$nbtotalofrecords = $objforcount->nbtotalofrecords;

-		} else {

-			dol_print_error($db);

-		}

-	}

-

-	if (($page * $limit) > $nbtotalofrecords) {	// if total resultset is smaller then paging size (filtering), goto and load page 0

+if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))

+{

+	$result = $db->query($sql);

+	$nbtotalofrecords = $db->num_rows($result);

+	if (($page * $limit) > $nbtotalofrecords)	// if total resultset is smaller then paging size (filtering), goto and load page 0

+	{

@@ -554,8 +303,3 @@
-	$db->free($resql);

-}

-

-// Complete request and execute it with limit

-$sql .= $db->order($sortfield, $sortorder);

-if ($limit) {

-	$sql .= $db->plimit($limit + 1, $offset);

-}

+}

+

+$sql .= $db->plimit($limit + 1, $offset);

@@ -564 +308,2 @@
-if (!$resql) {

+if (!$resql)

+{

@@ -572 +317,2 @@
-if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {

+if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall && !$page)

+{

@@ -589 +335,2 @@
-if ($socid > 0) {

+if ($socid > 0)

+{

@@ -592,3 +339 @@
-	if (empty($search_name)) {

-		$search_name = $soc->name;

-	}

+	if (empty($search_name)) $search_name = $soc->name;

@@ -598,126 +343,16 @@
-if (!empty($mode)) {

-	$param .= '&mode='.urlencode($mode);

-}

-if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {

-	$param .= '&contextpage='.urlencode($contextpage);

-}

-if ($limit > 0 && $limit != $conf->liste_limit) {

-	$param .= '&limit='.((int) $limit);

-}

-if ($search_all != '') {

-	$param .= '&search_all='.urlencode($search_all);

-}

-if ($search_contract != '') {

-	$param .= '&search_contract='.urlencode($search_contract);

-}

-if ($search_name != '') {

-	$param .= '&search_name='.urlencode($search_name);

-}

-if ($search_email != '') {

-	$param .= '&search_email='.urlencode($search_email);

-}

-if ($search_ref_customer != '') {

-	$param .= '&search_ref_customer='.urlencode($search_ref_customer);

-}

-if ($search_ref_supplier != '') {

-	$param .= '&search_ref_supplier='.urlencode($search_ref_supplier);

-}

-if ($search_op2df != '') {

-	$param .= '&search_op2df='.urlencode($search_op2df);

-}

-if ($search_date_creation_startmonth) {

-	$param .= '&search_date_creation_startmonth='.urlencode($search_date_creation_startmonth);

-}

-if ($search_date_creation_startyear) {

-	$param .= '&search_date_creation_startyear='.urlencode($search_date_creation_startyear);

-}

-if ($search_date_creation_startday) {

-	$param .= '&search_date_creation_startday='.urlencode($search_date_creation_startday);

-}

-if ($search_date_creation_start) {

-	$param .= '&search_date_creation_start='.urlencode($search_date_creation_start);

-}

-if ($search_date_creation_endmonth) {

-	$param .= '&search_date_creation_endmonth='.urlencode($search_date_creation_endmonth);

-}

-if ($search_date_creation_endyear) {

-	$param .= '&search_date_creation_endyear='.urlencode($search_date_creation_endyear);

-}

-if ($search_date_creation_endday) {

-	$param .= '&search_date_creation_endday='.urlencode($search_date_creation_endday);

-}

-if ($search_date_creation_end) {

-	$param .= '&search_date_creation_end='.urlencode($search_date_creation_end);

-}

-if ($search_date_modif_startmonth) {

-	$param .= '&search_date_modif_startmonth='.urlencode($search_date_modif_startmonth);

-}

-if ($search_date_modif_startyear) {

-	$param .= '&search_date_modif_startyear='.urlencode($search_date_modif_startyear);

-}

-if ($search_date_modif_startday) {

-	$param .= '&search_date_modif_startday='.urlencode($search_date_modif_startday);

-}

-if ($search_date_modif_start) {

-	$param .= '&search_date_modif_start='.urlencode($search_date_modif_start);

-}

-if ($search_date_modif_endmonth) {

-	$param .= '&search_date_modif_endmonth='.urlencode($search_date_modif_endmonth);

-}

-if ($search_date_modif_endyear) {

-	$param .= '&search_date_modif_endyear='.urlencode($search_date_modif_endyear);

-}

-if ($search_date_modif_endday) {

-	$param .= '&search_date_modif_endday='.urlencode($search_date_modif_endday);

-}

-if ($search_date_modif_end) {

-	$param .= '&search_date_modif_end=' . urlencode($search_date_modif_end);

-}

-if ($search_date_startday > 0) {

-	$param .= '&search_date_startday='.urlencode($search_date_startday);

-}

-if ($search_date_startmonth > 0) {

-	$param .= '&search_date_startmonth='.urlencode($search_date_startmonth);

-}

-if ($search_date_startyear > 0) {

-	$param .= '&search_date_startyear='.urlencode($search_date_startyear);

-}

-if ($search_date_endday > 0) {

-	$param .= '&search_date_endday='.urlencode($search_date_endday);

-}

-if ($search_date_endmonth > 0) {

-	$param .= '&search_date_endmonth='.urlencode($search_date_endmonth);

-}

-if ($search_date_endyear > 0) {

-	$param .= '&search_date_endyear='.urlencode($search_date_endyear);

-}

-if ($search_dfyear > 0) {

-	$param .= '&search_dfyear='.urlencode($search_dfyear);

-}

-if ($search_dfmonth > 0) {

-	$param .= '&search_dfmonth='.urlencode($search_dfmonth);

-}

-if ($search_sale > 0) {

-	$param .= '&search_sale='.urlencode($search_sale);

-}

-if ($search_user > 0) {

-	$param .= '&search_user='.urlencode($search_user);

-}

-if ($search_type_thirdparty > 0) {

-	$param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);

-}

-if ($search_country != '') {

-	$param .= "&search_country=".urlencode($search_country);

-}

-if ($search_product_category > 0) {

-	$param .= '&search_product_category='.urlencode($search_product_category);

-}

-if ($show_files) {

-	$param .= '&show_files='.urlencode($show_files);

-}

-if ($optioncss != '') {

-	$param .= '&optioncss='.urlencode($optioncss);

-}

-foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {

-	$param .= "&search_category_customer_list[]=".urlencode($searchCategoryCustomer);

-}

+if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);

+if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit;

+if ($sall != '')                $param .= '&sall='.urlencode($sall);

+if ($search_contract != '')     $param .= '&search_contract='.urlencode($search_contract);

+if ($search_name != '')         $param .= '&search_name='.urlencode($search_name);

+if ($search_email != '')        $param .= '&search_email='.urlencode($search_email);

+if ($search_ref_customer != '') $param .= '&search_ref_customer='.urlencode($search_ref_customer);

+if ($search_ref_supplier != '') $param .= '&search_ref_supplier='.urlencode($search_ref_supplier);

+if ($search_op2df != '') 		$param .= '&search_op2df='.urlencode($search_op2df);

+if ($search_dfyear != '')       $param .= '&search_dfyear='.urlencode($search_dfyear);

+if ($search_dfmonth != '')      $param .= '&search_dfmonth='.urlencode($search_dfmonth);

+if ($search_sale != '')         $param .= '&search_sale='.urlencode($search_sale);

+if ($search_user != '')			$param .= '&search_user='.urlencode($search_user);

+if ($search_product_category != '')	$param .= '&search_product_category='.urlencode($search_product_category);

+if ($show_files)                $param .= '&show_files='.urlencode($show_files);

+if ($optioncss != '')           $param .= '&optioncss='.urlencode($optioncss);

@@ -729,3 +364,3 @@
-	'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),

-	'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),

-	'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),

+	'generate_doc'=>$langs->trans("ReGeneratePDF"),

+	'builddoc'=>$langs->trans("PDFMerge"),

+    'presend'=>$langs->trans("SendByMail"),

@@ -733,6 +368,2 @@
-if (!empty($permissiontodelete)) {

-	$arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");

-}

-if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {

-	$arrayofmassactions = array();

-}

+if ($user->rights->contrat->supprimer) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");

+if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();

@@ -741,4 +371,0 @@
-$url = DOL_URL_ROOT.'/contrat/card.php?action=create';

-if (!empty($socid)) {

-	$url .= '&socid='.((int) $socid);

-}

@@ -746,9 +373,7 @@
-$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));

-$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition'));

-$newcardbutton .= dolGetButtonTitleSeparator();

-$newcardbutton .= dolGetButtonTitle($langs->trans('NewContractSubscription'), '', 'fa fa-plus-circle', $url, '', $user->hasRight('contrat', 'creer'));

-

-print '<form method="POST" id="searchFormList" action="'.$_SERVER['PHP_SELF'].'">'."\n";

-if ($optioncss != '') {

-	print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';

-}

+if ($user->rights->contrat->creer)

+{

+    $newcardbutton .= dolGetButtonTitle($langs->trans('NewContractSubscription'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/contrat/card.php?action=create');

+}

+

+print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';

+if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';

@@ -760 +384,0 @@
-print '<input type="hidden" name="page" value="'.$page.'">';

@@ -762,4 +386,2 @@
-print '<input type="hidden" name="page_y" value="">';

-print '<input type="hidden" name="mode" value="'.$mode.'">';

-

-print_barre_liste($langs->trans("Contracts"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'contract', 0, $newcardbutton, '', $limit, 0, 0, 1);

+

+print_barre_liste($langs->trans("ListOfContracts"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $totalnboflines, 'contract', 0, $newcardbutton, '', $limit, 0, 0, 1);

@@ -773,8 +395,4 @@
-if ($search_all) {

-	$setupstring = '';

-	foreach ($fieldstosearchall as $key => $val) {

-		$fieldstosearchall[$key] = $langs->trans($val);

-		$setupstring .= $key."=".$val.";";

-	}

-	print '<!-- Search done like if CONTRACT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";

-	print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>'."\n";

+if ($sall)

+{

+	foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);

+	print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';

@@ -786 +404,2 @@
-if ($user->hasRight('user', 'user', 'lire')) {

+if ($user->rights->societe->client->voir || $socid)

+{

@@ -789,2 +408,2 @@
-	$tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');

-	$moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'widthcentpercentminusx maxwidth300');

+	$moreforfilter .= $langs->trans('ThirdPartiesOfSaleRepresentative').': ';

+	$moreforfilter .= $formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth200');

@@ -794 +413,2 @@
-if ($user->hasRight('user', 'user', 'lire')) {

+if ($user->rights->user->user->lire)

+{

@@ -796,3 +416,3 @@
-	$tmptitle = $langs->trans('LinkedToSpecificUsers');

-	$moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');

-	$moreforfilter .= '</div>';

+	$moreforfilter .= $langs->trans('LinkedToSpecificUsers').': ';

+	$moreforfilter .= $form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');

+ 	$moreforfilter .= '</div>';

@@ -801 +421,2 @@
-if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire') && ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'))) {

+if ($conf->categorie->enabled && ($user->rights->produit->lire || $user->rights->service->lire))

+{

@@ -804 +425 @@
-	$tmptitle = $langs->trans('IncludingProductWithTag');

+	$moreforfilter .= $langs->trans('IncludingProductWithTag').': ';

@@ -806 +427 @@
-	$moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, 0, 'widthcentpercentminusx maxwidth300', 1);

+	$moreforfilter .= $form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1);

@@ -809,12 +429,0 @@
-// Filter on customer categories

-if (getDolGlobalString('MAIN_SEARCH_CATEGORY_CUSTOMER_ON_CONTRACT_LIST') && isModEnabled("categorie") && $user->hasRight('categorie', 'lire')) {

-	$moreforfilter .= '<div class="divsearchfield">';

-	$tmptitle = $langs->transnoentities('CustomersProspectsCategoriesShort');

-	$moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');

-	$categoriesArr = $form->select_all_categories(Categorie::TYPE_CUSTOMER, '', '', 64, 0, 1);

-	$categoriesArr[-2] = '- '.$langs->trans('NotCategorized').' -';

-	$moreforfilter .= Form::multiselectarray('search_category_customer_list', $categoriesArr, $searchCategoryCustomerList, 0, 0, 'minwidth300', 0, 0, '', 'category', $tmptitle);

-	$moreforfilter .= ' <input type="checkbox" class="valignmiddle" id="search_category_customer_operator" name="search_category_customer_operator" value="1"'.($searchCategoryCustomerOperator == 1 ? ' checked="checked"' : '').'/>';

-	$moreforfilter .= $form->textwithpicto('', $langs->trans('UseOrOperatorForCategories') . ' : ' . $tmptitle, 1, 'help', '', 0, 2, 'tooltip_cat_cus'); // Tooltip on click

-	$moreforfilter .= '</div>';

-}

@@ -823,8 +432,6 @@
-$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

-if (empty($reshook)) {

-	$moreforfilter .= $hookmanager->resPrint;

-} else {

-	$moreforfilter = $hookmanager->resPrint;

-}

-

-if (!empty($moreforfilter)) {

+$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook

+if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;

+else $moreforfilter = $hookmanager->resPrint;

+

+if (!empty($moreforfilter))

+{

@@ -837,4 +444,2 @@
-$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields

-if ($massactionbutton) {

-	$selectedfields .= $form->showCheckAddButtons('checkforselect', 1);

-}

+$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields

+if ($massactionbutton) $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);

@@ -845,2 +449,0 @@
-// Fields title search

-// --------------------------------------------------------------------

@@ -848,8 +451,2 @@
-// Action column

-if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {

-	print '<td class="liste_titre maxwidthsearch center">';

-	$searchpicto = $form->showFilterButtons('left');

-	print $searchpicto;

-	print '</td>';

-}

-if (!empty($arrayfields['c.ref']['checked'])) {

+if (!empty($arrayfields['c.ref']['checked']))

+{

@@ -860 +457,2 @@
-if (!empty($arrayfields['c.ref_customer']['checked'])) {

+if (!empty($arrayfields['c.ref_customer']['checked']))

+{

@@ -865 +463,2 @@
-if (!empty($arrayfields['c.ref_supplier']['checked'])) {

+if (!empty($arrayfields['c.ref_supplier']['checked']))

+{

@@ -870 +469,2 @@
-if (!empty($arrayfields['s.nom']['checked'])) {

+if (!empty($arrayfields['s.nom']['checked']))

+{

@@ -875 +475,2 @@
-if (!empty($arrayfields['s.email']['checked'])) {

+if (!empty($arrayfields['s.email']['checked']))

+{

@@ -881,3 +482 @@
-if (!empty($arrayfields['s.town']['checked'])) {

-	print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';

-}

+if (!empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';

@@ -885,3 +484 @@
-if (!empty($arrayfields['s.zip']['checked'])) {

-	print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';

-}

+if (!empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';

@@ -889 +486,2 @@
-if (!empty($arrayfields['state.nom']['checked'])) {

+if (!empty($arrayfields['state.nom']['checked']))

+{

@@ -895 +493,2 @@
-if (!empty($arrayfields['country.code_iso']['checked'])) {

+if (!empty($arrayfields['country.code_iso']['checked']))

+{

@@ -901 +500,2 @@
-if (!empty($arrayfields['typent.code']['checked'])) {

+if (!empty($arrayfields['typent.code']['checked']))

+{

@@ -903,4 +503,5 @@
-	print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (!getDolGlobalString('SOCIETE_SORT_ON_TYPEENT') ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1);

-	print '</td>';

-}

-if (!empty($arrayfields['sale_representative']['checked'])) {

+	print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT));

+	print '</td>';

+}

+if (!empty($arrayfields['sale_representative']['checked']))

+{

@@ -909,8 +510,10 @@
-if (!empty($arrayfields['c.date_contrat']['checked'])) {

-	print '<td class="liste_titre center">';

-	print '<div class="nowrapfordate">';

-	print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));

-	print '</div>';

-	print '<div class="nowrapfordate">';

-	print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));

-	print '</div>';

+if (!empty($arrayfields['c.date_contrat']['checked']))

+{

+	// Date contract

+	print '<td class="liste_titre center nowraponall">';

+	//print $langs->trans('Month').': ';

+	if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="day" value="'.$day.'">';

+	print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="month" value="'.$month.'">';

+	//print '&nbsp;'.$langs->trans('Year').': ';

+	$syear = $year;

+	print $formother->selectyear($syear, 'year', 1, 20, 5);

@@ -924 +527 @@
-$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

+$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook

@@ -926,20 +529,10 @@
-// Creation date

-if (!empty($arrayfields['c.datec']['checked'])) {

-	print '<td class="liste_titre center nowraponall">';

-	print '<div class="nowrapfordate">';

-	print $form->selectDate($search_date_creation_start ? $search_date_creation_start : -1, 'search_date_creation_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));

-	print '</div>';

-	print '<div class="nowrapfordate">';

-	print $form->selectDate($search_date_creation_end ? $search_date_creation_end : -1, 'search_date_creation_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));

-	print '</div>';

-	print '</td>';

-}

-// Modification date

-if (!empty($arrayfields['c.tms']['checked'])) {

-	print '<td class="liste_titre center nowraponall">';

-	print '<div class="nowrapfordate">';

-	print $form->selectDate($search_date_modif_start ? $search_date_modif_start : -1, 'search_date_modif_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));

-	print '</div>';

-	print '<div class="nowrapfordate">';

-	print $form->selectDate($search_date_modif_end ? $search_date_modif_end : -1, 'search_date_modif_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));

-	print '</div>';

+// Date creation

+if (!empty($arrayfields['c.datec']['checked']))

+{

+	print '<td class="liste_titre">';

+	print '</td>';

+}

+// Date modification

+if (!empty($arrayfields['c.tms']['checked']))

+{

+	print '<td class="liste_titre">';

@@ -949,9 +542,10 @@
-if (!empty($arrayfields['lower_planned_end_date']['checked'])) {

-	print '<td class="liste_titre nowraponall center">';

-	$arrayofoperators = array('0'=>'', '='=>'=', '<='=>'<=', '>='=>'>=');

-	print $form->selectarray('search_op2df', $arrayofoperators, $search_op2df, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth50imp');

-	print '</br>';

-	print $formother->select_month($search_dfmonth, 'search_dfmonth', 1, 0);

-	print ' ';

-	print $formother->selectyear($search_dfyear, 'search_dfyear', 1, 20, 5, 0, 0, '');

-	print '</td>';

+if (!empty($arrayfields['lower_planned_end_date']['checked']))

+{

+		print '<td class="liste_titre nowraponall center">';

+		$arrayofoperators = array('0'=>'', '='=>'=', '<='=>'<=', '>='=>'>=');

+		print $form->selectarray('search_op2df', $arrayofoperators, $search_op2df, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth50imp');

+		print '</br>';

+		print $formother->select_month($search_dfmonth, 'search_dfmonth', 1, 0);

+		print ' ';

+		$formother->select_year($search_dfyear, 'search_dfyear', 1, 20, 5, 0, 0, '');

+		print '</td>';

@@ -960 +554,2 @@
-if (!empty($arrayfields['status']['checked'])) {

+if (!empty($arrayfields['status']['checked']))

+{

@@ -963,15 +558,6 @@
-

-// Action column

-if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {

-	print '<td class="liste_titre center">';

-	$searchpicto = $form->showFilterButtons();

-	print $searchpicto;

-	print '</td>';

-}

-print '</tr>'."\n";

-

-$totalarray = array();

-$totalarray['nbfield'] = 0;

-

-// Fields title label

-// --------------------------------------------------------------------

+print '<td class="liste_titre center">';

+$searchpicto = $form->showFilterButtons();

+print $searchpicto;

+print '</td>';

+print "</tr>\n";

+

@@ -979,52 +565,12 @@
-if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {

-	print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');

-	$totalarray['nbfield']++;	// For the column action

-}

-if (!empty($arrayfields['c.ref']['checked'])) {

-	print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref", "", $param, '', $sortfield, $sortorder);

-	$totalarray['nbfield']++;	// For the column action

-}

-if (!empty($arrayfields['c.ref_customer']['checked'])) {

-	print_liste_field_titre($arrayfields['c.ref_customer']['label'], $_SERVER["PHP_SELF"], "c.ref_customer", "", $param, '', $sortfield, $sortorder);

-	$totalarray['nbfield']++;	// For the column action

-}

-if (!empty($arrayfields['c.ref_supplier']['checked'])) {

-	print_liste_field_titre($arrayfields['c.ref_supplier']['label'], $_SERVER["PHP_SELF"], "c.ref_supplier", "", $param, '', $sortfield, $sortorder);

-	$totalarray['nbfield']++;	// For the column action

-}

-if (!empty($arrayfields['s.nom']['checked'])) {

-	print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);

-	$totalarray['nbfield']++;	// For the column action

-}

-if (!empty($arrayfields['s.email']['checked'])) {

-	print_liste_field_titre($arrayfields['s.email']['label'], $_SERVER["PHP_SELF"], "s.email", "", $param, '', $sortfield, $sortorder);

-	$totalarray['nbfield']++;	// For the column action

-}

-if (!empty($arrayfields['s.town']['checked'])) {

-	print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);

-	$totalarray['nbfield']++;	// For the column action

-}

-if (!empty($arrayfields['s.zip']['checked'])) {

-	print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);

-	$totalarray['nbfield']++;	// For the column action

-}

-if (!empty($arrayfields['state.nom']['checked'])) {

-	print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);

-	$totalarray['nbfield']++;	// For the column action

-}

-if (!empty($arrayfields['country.code_iso']['checked'])) {

-	print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');

-	$totalarray['nbfield']++;	// For the column action

-}

-if (!empty($arrayfields['typent.code']['checked'])) {

-	print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');

-	$totalarray['nbfield']++;	// For the column action

-}

-if (!empty($arrayfields['sale_representative']['checked'])) {

-	print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);

-	$totalarray['nbfield']++;	// For the column action

-}

-if (!empty($arrayfields['c.date_contrat']['checked'])) {

-	print_liste_field_titre($arrayfields['c.date_contrat']['label'], $_SERVER["PHP_SELF"], "c.date_contrat", "", $param, '', $sortfield, $sortorder, 'center ');

-	$totalarray['nbfield']++;	// For the column action

-}

+if (!empty($arrayfields['c.ref']['checked']))               print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref", "", $param, '', $sortfield, $sortorder);

+if (!empty($arrayfields['c.ref_customer']['checked']))      print_liste_field_titre($arrayfields['c.ref_customer']['label'], $_SERVER["PHP_SELF"], "c.ref_customer", "", $param, '', $sortfield, $sortorder);

+if (!empty($arrayfields['c.ref_supplier']['checked']))      print_liste_field_titre($arrayfields['c.ref_supplier']['label'], $_SERVER["PHP_SELF"], "c.ref_supplier", "", $param, '', $sortfield, $sortorder);

+if (!empty($arrayfields['s.nom']['checked']))               print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);

+if (!empty($arrayfields['s.email']['checked']))             print_liste_field_titre($arrayfields['s.email']['label'], $_SERVER["PHP_SELF"], "s.email", "", $param, '', $sortfield, $sortorder);

+if (!empty($arrayfields['s.town']['checked']))              print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);

+if (!empty($arrayfields['s.zip']['checked']))               print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);

+if (!empty($arrayfields['state.nom']['checked']))           print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);

+if (!empty($arrayfields['country.code_iso']['checked']))    print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');

+if (!empty($arrayfields['typent.code']['checked']))         print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');

+if (!empty($arrayfields['sale_representative']['checked'])) print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);

+if (!empty($arrayfields['c.date_contrat']['checked']))      print_liste_field_titre($arrayfields['c.date_contrat']['label'], $_SERVER["PHP_SELF"], "c.date_contrat", "", $param, '', $sortfield, $sortorder, 'center ');

@@ -1034,2 +580,2 @@
-$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);

-$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

+$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);

+$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook

@@ -1038,2 +584 @@
-	print_liste_field_titre($arrayfields['c.datec']['label'], $_SERVER["PHP_SELF"], "c.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');

-	$totalarray['nbfield']++;	// For the column action

+    print_liste_field_titre($arrayfields['c.datec']['label'], $_SERVER["PHP_SELF"], "c.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');

@@ -1042,2 +587 @@
-	print_liste_field_titre($arrayfields['c.tms']['label'], $_SERVER["PHP_SELF"], "c.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');

-	$totalarray['nbfield']++;	// For the column action

+    print_liste_field_titre($arrayfields['c.tms']['label'], $_SERVER["PHP_SELF"], "c.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');

@@ -1046,2 +590 @@
-	print_liste_field_titre($arrayfields['lower_planned_end_date']['label'], $_SERVER["PHP_SELF"], "lower_planned_end_date", "", $param, '', $sortfield, $sortorder, 'center ');

-	$totalarray['nbfield']++;	// For the column action

+    print_liste_field_titre($arrayfields['lower_planned_end_date']['label'], $_SERVER["PHP_SELF"], "lower_planned_end_date", "", $param, '', $sortfield, $sortorder, 'center ');

@@ -1051 +593,0 @@
-	$totalarray['nbfield']++;	// For the column action

@@ -1053 +594,0 @@
-	$totalarray['nbfield']++;	// For the column action

@@ -1055 +595,0 @@
-	$totalarray['nbfield']++;	// For the column action

@@ -1057,6 +597,2 @@
-	$totalarray['nbfield']++;	// For the column action

-}

-if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {

-	print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');

-	$totalarray['nbfield']++;	// For the column action

-}

+}

+print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');

@@ -1065,10 +601,2 @@
-// Loop on record

-// --------------------------------------------------------------------

-$i = 0;

-$savnbfield = $totalarray['nbfield'];

-$totalarray = array();

-$totalarray['nbfield'] = 0;

-$typenArray = array();

-$cacheCountryIDCode = array();

-$imaxinloop = ($limit ? min($num, $limit) : $num);

-while ($i < $imaxinloop) {

+while ($i < min($num, $limit))

+{

@@ -1076,3 +603,0 @@
-	if (empty($obj)) {

-		break; // Should not happen

-	}

@@ -1085,19 +610,16 @@
-	$contracttmp->nbofserviceswait = $obj->nb_initial;

-	$contracttmp->nbofservicesopened = $obj->nb_running;

-	$contracttmp->nbofservicesexpired = $obj->nb_expired;

-	$contracttmp->nbofservicesclosed = $obj->nb_closed;

-

-	$socstatic->id = $obj->socid;

-	$socstatic->name = $obj->name;

-	$socstatic->name_alias = $obj->name_alias;

-	$socstatic->email = $obj->email;

-	$socstatic->status = $obj->company_status;

-	$socstatic->logo = $obj->company_logo;

-	$socstatic->country_id = $obj->country_id;

-	$socstatic->country_code = '';

-	$socstatic->country = '';

-

-	if ($obj->country_id > 0) {

-		if (!isset($cacheCountryIDCode[$obj->country_id]['code'])) {

-			$tmparray = getCountry($obj->country_id, 'all');

-			$cacheCountryIDCode[$obj->country_id] = array('code'=> empty($tmparray['code']) ? '' : $tmparray['code'], 'label' => empty($tmparray['label']) ? '' : $tmparray['label']);

+	if ($obj->socid > 0) {

+		$result = $socstatic->fetch($obj->socid);

+	}

+

+	print '<tr class="oddeven">';

+

+	// Ref

+	if (!empty($arrayfields['c.ref']['checked']))

+	{

+		print '<td class="nowraponall">';

+		print $contracttmp->getNomUrl(1);

+		if ($obj->nb_late) print img_warning($langs->trans("Late"));

+		if (!empty($obj->note_private) || !empty($obj->note_public)) {

+			print ' <span class="note">';

+			print '<a href="'.DOL_URL_ROOT.'/contrat/note.php?id='.$obj->rowid.'&save_lastsearch_values=1">'.img_picto($langs->trans("ViewPrivateNote"), 'note').'</a>';

+			print '</span>';

@@ -1105,8 +627,25 @@
-		$socstatic->country_code = $cacheCountryIDCode[$obj->country_id]['code'];

-		$socstatic->country = $cacheCountryIDCode[$obj->country_id]['label'];

-	}

-

-	if ($mode == 'kanban') {

-		if ($i == 0) {

-			print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';

-			print '<div class="box-flex-container kanban">';

+

+		$filename = dol_sanitizeFileName($obj->ref);

+		$filedir = $conf->contrat->dir_output.'/'.dol_sanitizeFileName($obj->ref);

+		$urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;

+		print $formfile->getDocumentsLink($contracttmp->element, $filename, $filedir);

+		print '</td>';

+

+		print '</td>';

+	}

+

+	if (!empty($arrayfields['c.ref_customer']['checked']))

+	{

+	    print '<td>'.$contracttmp->getFormatedCustomerRef($obj->ref_customer).'</td>';

+	}

+	if (!empty($arrayfields['c.ref_supplier']['checked']))

+	{

+		print '<td>'.$obj->ref_supplier.'</td>';

+	}

+	if (!empty($arrayfields['s.nom']['checked']))

+	{

+		print '<td>';

+		//print '<a href="../comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->name.'</a>';

+		if ($obj->socid > 0)

+		{

+			print $socstatic->getNomUrl(1, '');

@@ -1114,8 +653,81 @@
-		// Output Kanban

-		$arraydata['thirdparty'] = $socstatic;

-		$arraydata['selected'] = in_array($obj->rowid, $arrayofselected);

-		$contracttmp->date_contrat = $obj->date_contrat;

-		print $contracttmp->getKanbanView('', $arraydata);

-		if ($i == ($imaxinloop - 1)) {

-			print '</div>';

-			print '</td></tr>';

+		print '</td>';

+	}

+	if (!empty($arrayfields['s.email']['checked']))

+	{

+		print '<td>'.$obj->email.'</td>';

+	}

+	// Town

+	if (!empty($arrayfields['s.town']['checked']))

+	{

+		print '<td class="nocellnopadd">';

+		print $obj->town;

+		print '</td>';

+		if (!$i) $totalarray['nbfield']++;

+	}

+	// Zip

+	if (!empty($arrayfields['s.zip']['checked']))

+	{

+		print '<td class="nocellnopadd">';

+		print $obj->zip;

+		print '</td>';

+		if (!$i) $totalarray['nbfield']++;

+	}

+	// State

+	if (!empty($arrayfields['state.nom']['checked']))

+	{

+		print "<td>".$obj->state_name."</td>\n";

+		if (!$i) $totalarray['nbfield']++;

+	}

+	// Country

+	if (!empty($arrayfields['country.code_iso']['checked']))

+	{

+		print '<td class="center">';

+		$tmparray = getCountry($obj->fk_pays, 'all');

+		print $tmparray['label'];

+		print '</td>';

+		if (!$i) $totalarray['nbfield']++;

+	}

+	// Type ent

+	if (!empty($arrayfields['typent.code']['checked']))

+	{

+		print '<td class="center">';

+		if (count($typenArray) == 0) $typenArray = $formcompany->typent_array(1);

+		print $typenArray[$obj->typent_code];

+		print '</td>';

+		if (!$i) $totalarray['nbfield']++;

+	}

+	if (!empty($arrayfields['sale_representative']['checked']))

+	{

+		// Sales representatives

+		print '<td>';

+		if ($obj->socid > 0)

+		{

+			$listsalesrepresentatives = $socstatic->getSalesRepresentatives($user);

+			if ($listsalesrepresentatives < 0) dol_print_error($db);

+			$nbofsalesrepresentative = count($listsalesrepresentatives);

+			if ($nbofsalesrepresentative > 3) {

+				// We print only number

+				print $nbofsalesrepresentative;

+			}

+			elseif ($nbofsalesrepresentative > 0)

+			{

+				$userstatic = new User($db);

+				$j = 0;

+				foreach ($listsalesrepresentatives as $val)

+				{

+					$userstatic->id = $val['id'];

+					$userstatic->lastname = $val['lastname'];

+					$userstatic->firstname = $val['firstname'];

+					$userstatic->email = $val['email'];

+					$userstatic->statut = $val['statut'];

+					$userstatic->entity = $val['entity'];

+					$userstatic->photo = $val['photo'];

+

+					//print '<div class="float">':

+					print $userstatic->getNomUrl(-2);

+					$j++;

+					if ($j < $nbofsalesrepresentative) print ' ';

+					//print '</div>';

+				}

+			}

+			//else print $langs->trans("NoSalesRepresentativeAffected");

@@ -1123,17 +735,3 @@
-	} else {

-		// Show here line of result

-		print '<tr data-rowid="'.$object->id.'" class="oddeven">';

-		// Action column

-		if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {

-			print '<td class="nowrap center">';

-			if ($massactionbutton || $massaction) {   // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined

-				$selected = 0;

-				if (in_array($obj->rowid, $arrayofselected)) {

-					$selected = 1;

-				}

-				print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';

-			}

-			print '</td>';

-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

+		else

+		{

+			print '&nbsp';

@@ -1141,204 +739,57 @@
-		// Ref

-		if (!empty($arrayfields['c.ref']['checked'])) {

-			print '<td class="nowraponall">';

-			print $contracttmp->getNomUrl(1);

-			if ($obj->nb_late) {

-				print img_warning($langs->trans("Late"));

-			}

-			if (!empty($obj->note_private) || !empty($obj->note_public)) {

-				print ' <span class="note">';

-				print '<a href="'.DOL_URL_ROOT.'/contrat/note.php?id='.$obj->rowid.'&save_lastsearch_values=1">'.img_picto($langs->trans("ViewPrivateNote"), 'note').'</a>';

-				print '</span>';

-			}

-

-			$filename = dol_sanitizeFileName($obj->ref);

-			$filedir = $conf->contrat->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);

-			$urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;

-			print $formfile->getDocumentsLink($contracttmp->element, $filename, $filedir);

-			print '</td>';

-

-			print '</td>';

-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

-		}

-

-		// Ref thirdparty

-		if (!empty($arrayfields['c.ref_customer']['checked'])) {

-			print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag(dol_string_nohtmltag($contracttmp->getFormatedCustomerRef($obj->ref_customer))).'">'.$contracttmp->getFormatedCustomerRef($obj->ref_customer).'</td>';

-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

-		}

-		if (!empty($arrayfields['c.ref_supplier']['checked'])) {

-			print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->ref_supplier).'">'.dol_escape_htmltag($obj->ref_supplier).'</td>';

-		}

-		if (!empty($arrayfields['s.nom']['checked'])) {

-			print '<td class="tdoverflowmax150">';

-			if ($obj->socid > 0) {

-				// TODO Use a cache for this string

-				print $socstatic->getNomUrl(1, '');

-			}

-			print '</td>';

-		}

-		// Email

-		if (!empty($arrayfields['s.email']['checked'])) {

-			print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->email).'">'.dol_print_email($obj->email, 0, $obj->socid, 0, 0, 1, 1).'</td>';

-		}

-		// Town

-		if (!empty($arrayfields['s.town']['checked'])) {

-			print '<td class="nocellnopadd">';

-			print $obj->town;

-			print '</td>';

-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

-		}

-		// Zip

-		if (!empty($arrayfields['s.zip']['checked'])) {

-			print '<td class="nocellnopadd">';

-			print $obj->zip;

-			print '</td>';

-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

-		}

-		// State

-		if (!empty($arrayfields['state.nom']['checked'])) {

-			print "<td>".$obj->state_name."</td>\n";

-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

-		}

-		// Country

-		if (!empty($arrayfields['country.code_iso']['checked'])) {

-			print '<td class="center tdoverflowmax100" title="'.dol_escape_htmltag($socstatic->country).'">';

-			print dol_escape_htmltag($socstatic->country);

-			print '</td>';

-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

-		}

-		// Type ent

-		if (!empty($arrayfields['typent.code']['checked'])) {

-			print '<td class="center">';

-			if (count($typenArray) == 0) {

-				$typenArray = $formcompany->typent_array(1);

-			}

-			print $typenArray[$obj->typent_code];

-			print '</td>';

-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

-		}

-		if (!empty($arrayfields['sale_representative']['checked'])) {

-			// Sales representatives

-			print '<td>';

-			if ($obj->socid > 0) {

-				$listsalesrepresentatives = $socstatic->getSalesRepresentatives($user);

-				if ($listsalesrepresentatives < 0) {

-					dol_print_error($db);

-				}

-				$nbofsalesrepresentative = count($listsalesrepresentatives);

-				if ($nbofsalesrepresentative > 6) {

-					// We print only number

-					print $nbofsalesrepresentative;

-				} elseif ($nbofsalesrepresentative > 0) {

-					$userstatic = new User($db);

-					$j = 0;

-					foreach ($listsalesrepresentatives as $val) {

-						$userstatic->id = $val['id'];

-						$userstatic->lastname = $val['lastname'];

-						$userstatic->firstname = $val['firstname'];

-						$userstatic->email = $val['email'];

-						$userstatic->statut = $val['statut'];

-						$userstatic->entity = $val['entity'];

-						$userstatic->photo = $val['photo'];

-						$userstatic->login = $val['login'];

-						$userstatic->phone = $val['phone'];

-						$userstatic->job = $val['job'];

-						$userstatic->gender = $val['gender'];

-

-						//print '<div class="float">':

-						print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2);

-						$j++;

-						if ($j < $nbofsalesrepresentative) {

-							print ' ';

-						}

-						//print '</div>';

-					}

-				}

-				//else print $langs->trans("NoSalesRepresentativeAffected");

-			} else {

-				print '&nbsp;';

-			}

-			print '</td>';

-		}

-		// Date

-		if (!empty($arrayfields['c.date_contrat']['checked'])) {

-			print '<td class="center">'.dol_print_date($db->jdate($obj->date_contrat), 'day', 'tzserver').'</td>';

-		}

-		// Extra fields

-		include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';

-		// Fields from hook

-		$parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);

-		$reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

-		print $hookmanager->resPrint;

-		// Date creation

-		if (!empty($arrayfields['c.datec']['checked'])) {

-			print '<td class="center nowrap">';

-			print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');

-			print '</td>';

-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

-		}

-		// Date modification

-		if (!empty($arrayfields['c.tms']['checked'])) {

-			print '<td class="center nowrap">';

-			print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');

-			print '</td>';

-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

-		}

-		// Date lower end date

-		if (!empty($arrayfields['lower_planned_end_date']['checked'])) {

-			print '<td class="center nowrapforall">';

-			print dol_print_date($db->jdate($obj->lower_planned_end_date), 'day', 'tzuser');

-			print '</td>';

-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

-		}

-		// Status

-		if (!empty($arrayfields['status']['checked'])) {

-			print '<td class="center">'.($obj->nb_initial > 0 ? $obj->nb_initial : '').'</td>';

-			print '<td class="center">'.($obj->nb_running > 0 ? $obj->nb_running : '').'</td>';

-			print '<td class="center">'.($obj->nb_expired > 0 ? $obj->nb_expired : '').'</td>';

-			print '<td class="center">'.($obj->nb_closed > 0 ? $obj->nb_closed : '').'</td>';

-			if (!$i) {

-				$totalarray['nbfield']++;

-				$totalarray['nbfield']++;

-				$totalarray['nbfield']++;

-				$totalarray['nbfield']++;

-			}

-		}

-		// Action column

-		if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {

-			print '<td class="nowrap center">';

-			if ($massactionbutton || $massaction) {   // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined

-				$selected = 0;

-				if (in_array($obj->rowid, $arrayofselected)) {

-					$selected = 1;

-				}

-				print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';

-			}

-			print '</td>';

-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

-		}

-

-		print '</tr>'."\n";

-	}

+		print '</td>';

+	}

+	// Date

+	if (!empty($arrayfields['c.date_contrat']['checked']))

+	{

+		print '<td class="center">'.dol_print_date($db->jdate($obj->date_contrat), 'day', 'tzserver').'</td>';

+	}

+	// Extra fields

+	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';

+	// Fields from hook

+	$parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);

+	$reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook

+	print $hookmanager->resPrint;

+	// Date creation

+	if (!empty($arrayfields['c.datec']['checked']))

+	{

+		print '<td class="center nowrap">';

+		print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');

+		print '</td>';

+		if (!$i) $totalarray['nbfield']++;

+	}

+	// Date modification

+	if (!empty($arrayfields['c.tms']['checked']))

+	{

+		print '<td class="center nowrap">';

+		print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');

+		print '</td>';

+		if (!$i) $totalarray['nbfield']++;

+	}

+	// Date lower end date

+	if (!empty($arrayfields['lower_planned_end_date']['checked']))

+	{

+		print '<td class="center nowrapforall">';

+		print dol_print_date($db->jdate($obj->lower_planned_end_date), 'day', 'tzuser');

+		print '</td>';

+		if (!$i) $totalarray['nbfield']++;

+	}

+	// Status

+	if (!empty($arrayfields['status']['checked']))

+	{

+		print '<td class="center">'.($obj->nb_initial > 0 ? $obj->nb_initial : '').'</td>';

+		print '<td class="center">'.($obj->nb_running > 0 ? $obj->nb_running : '').'</td>';

+		print '<td class="center">'.($obj->nb_expired > 0 ? $obj->nb_expired : '').'</td>';

+		print '<td class="center">'.($obj->nb_closed > 0 ? $obj->nb_closed : '').'</td>';

+	}

+	// Action column

+	print '<td class="nowrap center">';

+	if ($massactionbutton || $massaction)   // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined

+	{

+		$selected = 0;

+		if (in_array($obj->rowid, $arrayofselected)) $selected = 1;

+		print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';

+	}

+	print '</td>';

+	if (!$i) $totalarray['nbfield']++;

+

+	print "</tr>\n";

@@ -1347,12 +797,0 @@
-

-// If no record found

-if ($num == 0) {

-	$colspan = 4;	// Include the 4 columns of status

-	foreach ($arrayfields as $key => $val) {

-		if (!empty($val['checked'])) {

-			$colspan++;

-		}

-	}

-	print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';

-}

-

@@ -1362 +801 @@
-$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

+$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook

@@ -1365,4 +804,4 @@
-print '</table>'."\n";

-print '</div>'."\n";

-

-print '</form>'."\n";

+print '</table>';

+print '</div>';

+

+print '</form>';

@@ -1371,3 +810 @@
-if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {

-	$hidegeneratedfilelistifempty = 0;

-}

+if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0;

@@ -1380,2 +817,2 @@
-$genallowed = $permissiontoread;

-$delallowed = $permissiontoadd;

+$genallowed = $user->rights->contrat->lire;

+$delallowed = $user->rights->contrat->lire;

--- /tmp/dsg/dolibarr/htdocs/contrat/github_19.0.3_note.php
+++ /tmp/dsg/dolibarr/htdocs/contrat/client_note.php
@@ -27 +26,0 @@
-// Load Dolibarr environment

@@ -31 +30 @@
-if (isModEnabled('project')) {

+if (!empty($conf->projet->enabled)) {

@@ -38 +37 @@
-$action = GETPOST('action', 'aZ09');

+$action = GETPOST('action', 'alpha');

@@ -45,6 +44,2 @@
-if ($user->socid) {

-	$socid = $user->socid;

-}

-// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context

-//$hookmanager->initHooks(array('contractcard', 'globalcard'));  -> Conflict with contrat\card.php

-$hookmanager->initHooks(array('contractnote'));

+if ($user->socid) $socid = $user->socid;

+$result = restrictedArea($user, 'contrat', $id);

@@ -55,2 +50 @@
-$permissiontoadd   = $user->hasRight('contrat', 'creer');     //  Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php

-$permissionnote = $user->hasRight('contrat', 'creer'); // Used by the include of actions_setnotes.inc.php

+$permissionnote = $user->rights->contrat->creer; // Used by the include of actions_setnotes.inc.php

@@ -58 +52,3 @@
-$result = restrictedArea($user, 'contrat', $object->id);

+// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context

+$hookmanager->initHooks(array('contractcard', 'globalcard'));

+

@@ -65,7 +61 @@
-$reshook = $hookmanager->executeHooks('doActions', array(), $object, $action); // Note that $action and $object may have been modified by some hooks

-if ($reshook < 0) {

-	setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

-}

-if (empty($reshook)) {

-	include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once

-}

+include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once

@@ -79,4 +69 @@
-$title = $langs->trans("Contract");

-$help_url = 'EN:Module_Contracts|FR:Module_Contrat';

-

-llxHeader('', $title, $help_url);

+llxHeader('', $langs->trans("Contract"), "");

@@ -86,2 +73,3 @@
-if ($id > 0 || !empty($ref)) {

-	$object->fetch_thirdparty();

+if ($id > 0 || !empty($ref))

+{

+    $object->fetch_thirdparty();

@@ -89 +77 @@
-	$head = contract_prepare_head($object);

+    $head = contract_prepare_head($object);

@@ -91 +79 @@
-	$hselected = 2;

+    $hselected = 2;

@@ -93 +81 @@
-	print dol_get_fiche_head($head, 'note', $langs->trans("Contract"), -1, 'contract');

+    dol_fiche_head($head, 'note', $langs->trans("Contract"), -1, 'contract');

@@ -95 +83 @@
-	// Contract card

+    // Contract card

@@ -97 +85 @@
-	$linkback = '<a href="'.DOL_URL_ROOT.'/contrat/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';

+    $linkback = '<a href="'.DOL_URL_ROOT.'/contrat/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';

@@ -100,7 +88,7 @@
-	$morehtmlref = '';

-	//if (!empty($modCodeContract->code_auto)) {

-	$morehtmlref .= $object->ref;

-	/*} else {

-	 $morehtmlref.=$form->editfieldkey("",'ref',$object->ref,0,'string','',0,3);

-	$morehtmlref.=$form->editfieldval("",'ref',$object->ref,0,'string','',0,2);

-	}*/

+    $morehtmlref = '';

+    //if (! empty($modCodeContract->code_auto)) {

+    $morehtmlref .= $object->ref;

+    /*} else {

+     $morehtmlref.=$form->editfieldkey("",'ref',$object->ref,0,'string','',0,3);

+    $morehtmlref.=$form->editfieldval("",'ref',$object->ref,0,'string','',0,2);

+    }*/

@@ -108,32 +96,44 @@
-	$morehtmlref .= '<div class="refidno">';

-	// Ref customer

-	$morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', 0, 1);

-	$morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', null, null, '', 1, 'getFormatedCustomerRef');

-	// Ref supplier

-	$morehtmlref .= '<br>';

-	$morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);

-	$morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1, 'getFormatedSupplierRef');

-	// Thirdparty

-	$morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);

-	// Project

-	if (isModEnabled('project')) {

-		$langs->load("projects");

-		$morehtmlref .= '<br>';

-		if (0) {

-			$morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');

-			if ($action != 'classify') {

-				$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';

-			}

-			$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');

-		} else {

-			if (!empty($object->fk_project)) {

-				$proj = new Project($db);

-				$proj->fetch($object->fk_project);

-				$morehtmlref .= $proj->getNomUrl(1);

-				if ($proj->title) {

-					$morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';

-				}

-			}

-		}

-	}

-	$morehtmlref .= '</div>';

+    $morehtmlref .= '<div class="refidno">';

+    // Ref customer

+    $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', 0, 1);

+    $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', null, null, '', 1, 'getFormatedCustomerRef');

+    // Ref supplier

+    $morehtmlref .= '<br>';

+    $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);

+    $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1, 'getFormatedSupplierRef');

+    // Thirdparty

+    $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);

+    // Project

+    if (!empty($conf->projet->enabled))

+    {

+    	$langs->load("projects");

+    	$morehtmlref .= '<br>'.$langs->trans('Project').' ';

+    	if ($user->rights->contrat->creer)

+    	{

+    		if ($action != 'classify')

+    			//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';

+    			$morehtmlref .= ' : ';

+    		if ($action == 'classify') {

+    			//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);

+    			$morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';

+    			$morehtmlref .= '<input type="hidden" name="action" value="classin">';

+    			$morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';

+    			$morehtmlref .= $formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);

+    			$morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';

+    			$morehtmlref .= '</form>';

+    		} else {

+    			$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1);

+    		}

+    	} else {

+    		if (!empty($object->fk_project)) {

+    			$proj = new Project($db);

+    			$proj->fetch($object->fk_project);

+    			$morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';

+    			$morehtmlref .= $proj->ref;

+    			$morehtmlref .= '</a>';

+    		} else {

+    			$morehtmlref .= '';

+    		}

+    	}

+    }

+    $morehtmlref .= '</div>';

@@ -142 +142 @@
-	dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref);

+    dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref);

@@ -145,2 +145,2 @@
-	print '<div class="fichecenter">';

-	print '<div class="underbanner clearboth"></div>';

+    print '<div class="fichecenter">';

+    print '<div class="underbanner clearboth"></div>';

@@ -148 +148 @@
-	print '<table class="border centpercent tableforfield">';

+    print '<table class="border centpercent tableforfield">';

@@ -151,16 +151,10 @@
-	// Ligne info remises tiers

-	print '<tr><td class="titlefield">'.$langs->trans('Discount').'</td><td colspan="3">';

-	if ($object->thirdparty->remise_percent) {

-		print $langs->trans("CompanyHasRelativeDiscount", $object->thirdparty->remise_percent);

-	} else {

-		print $langs->trans("CompanyHasNoRelativeDiscount");

-	}

-	$absolute_discount = $object->thirdparty->getAvailableDiscounts();

-	print '. ';

-	if ($absolute_discount) {

-		print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency));

-	} else {

-		print $langs->trans("CompanyHasNoAbsoluteDiscount");

-	}

-	print '.';

-	print '</td></tr>';

+    // Ligne info remises tiers

+    print '<tr><td class="titlefield">'.$langs->trans('Discount').'</td><td colspan="3">';

+    if ($object->thirdparty->remise_percent) print $langs->trans("CompanyHasRelativeDiscount", $object->thirdparty->remise_percent);

+    else print $langs->trans("CompanyHasNoRelativeDiscount");

+    $absolute_discount = $object->thirdparty->getAvailableDiscounts();

+    print '. ';

+    if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency));

+    else print $langs->trans("CompanyHasNoAbsoluteDiscount");

+    print '.';

+    print '</td></tr>';

@@ -168,8 +162,8 @@
-	// Date

-	print '<tr>';

-	print '<td class="titlefield">';

-	print $form->editfieldkey("Date", 'date_contrat', $object->date_contrat, $object, 0);

-	print '</td><td>';

-	print $form->editfieldval("Date", 'date_contrat', $object->date_contrat, $object, 0, 'datehourpicker');

-	print '</td>';

-	print '</tr>';

+    // Date

+    print '<tr>';

+    print '<td class="titlefield">';

+    print $form->editfieldkey("Date", 'date_contrat', $object->date_contrat, $object, 0);

+    print '</td><td>';

+    print $form->editfieldval("Date", 'date_contrat', $object->date_contrat, $object, 0, 'datehourpicker');

+    print '</td>';

+    print '</tr>';

@@ -183 +176,0 @@
-	$cssclass='titlefield';

@@ -186 +179 @@
-	print dol_get_fiche_end();

+	dol_fiche_end();

--- /tmp/dsg/dolibarr/htdocs/contrat/github_19.0.3_services_list.php
+++ /tmp/dsg/dolibarr/htdocs/contrat/client_services_list.php
@@ -9 +8,0 @@
- * Copyright (C) 2023-2024	William Mead			<william.mead@manchenumerique.fr>

@@ -39,11 +38,3 @@
-// Get parameters

-$massaction = GETPOST('massaction', 'alpha');

-$toselect   = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list

-$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search

-$optioncss  = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')

-$mode       = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...)

-

-// Load variable for pagination

-$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;

-$sortfield = GETPOST('sortfield', 'aZ09comma');

-$sortorder = GETPOST('sortorder', 'aZ09comma');

+$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;

+$sortfield = GETPOST("sortfield", 'alpha');

+$sortorder = GETPOST("sortorder", 'alpha');

@@ -51,4 +42 @@
-if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {

-	// If $page is not defined, or '' or -1 or if we click on clear filters

-	$page = 0;

-}

+if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1

@@ -58,7 +46,5 @@
-if (!$sortfield) {

-	$sortfield = "c.rowid";

-}

-if (!$sortorder) {

-	$sortorder = "ASC";

-}

-

+if (!$sortfield) $sortfield = "c.rowid";

+if (!$sortorder) $sortorder = "ASC";

+

+$mode = GETPOST("mode");

+$filter = GETPOST("filter");

@@ -66,5 +51,0 @@
-$search_subprice = GETPOST("search_subprice", 'alpha');

-$search_qty = GETPOST("search_qty", 'alpha');

-$search_total_ht = GETPOST("search_total_ht", 'alpha');

-$search_total_tva = GETPOST("search_total_tva", 'alpha');

-$search_total_ttc = GETPOST("search_total_ttc", 'alpha');

@@ -73,0 +55 @@
+$statut = GETPOST('statut', 'int') ?GETPOST('statut', 'int') : 1;

@@ -76 +58 @@
-$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'contractservicelist'.$mode;

+$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'contractservicelist'.$mode;

@@ -81 +63 @@
-$filter_opouvertureprevue = GETPOST('filter_opouvertureprevue', 'alphawithlgt');

+$filter_opouvertureprevue = GETPOST('filter_opouvertureprevue');

@@ -86 +68 @@
-$filter_op1 = GETPOST('filter_op1', 'alphawithlgt');

+$filter_op1 = GETPOST('filter_op1', 'alpha');

@@ -91 +73 @@
-$filter_op2 = GETPOST('filter_op2', 'alphawithlgt');

+$filter_op2 = GETPOST('filter_op2', 'alpha');

@@ -96 +78 @@
-$filter_opcloture = GETPOST('filter_opcloture', 'alphalgt');

+$filter_opcloture = GETPOST('filter_opcloture', 'alpha');

@@ -105 +87 @@
-$extrafields->fetch_name_optionals_label($object->table_element);

+$extrafields->fetch_name_optionals_label('contratdet');

@@ -111,3 +93 @@
-if (!empty($user->socid)) {

-	$socid = $user->socid;

-}

+if (!empty($user->socid)) $socid = $user->socid;

@@ -114,0 +95,18 @@
+

+if ($search_status != '')

+{

+	$tmp = explode('&', $search_status);

+	$mode = $tmp[0];

+	if (empty($tmp[1])) $filter = '';

+	else

+	{

+		if ($tmp[1] == 'filter=notexpired') $filter = 'notexpired';

+		if ($tmp[1] == 'filter=expired') $filter = 'expired';

+	}

+}

+else

+{

+	$search_status = $mode;

+	if ($filter == 'expired') $search_status .= '&filter=expired';

+	if ($filter == 'notexpired') $search_status .= '&filter=notexpired';

+}

@@ -121,12 +119,13 @@
-	'c.ref'=>array('label'=>"Contract", 'checked'=>1, 'position'=>80),

-	'p.description'=>array('label'=>"Service", 'checked'=>1, 'position'=>80),

-	's.nom'=>array('label'=>"ThirdParty", 'checked'=>1, 'position'=>90),

-	'cd.tva_tx'=>array('label'=>"VATRate", 'checked'=>-1, 'position'=>100),

-	'cd.subprice'=>array('label'=>"PriceUHT", 'checked'=>-1, 'position'=>105),

-	'cd.qty'=>array('label'=>"Qty", 'checked'=>1, 'position'=>108),

-	'cd.total_ht'=>array('label'=>"TotalHT", 'checked'=>-1, 'position'=>109, 'isameasure'=>1),

-	'cd.total_tva'=>array('label'=>"TotalVAT", 'checked'=>-1, 'position'=>110),

-	'cd.date_ouverture_prevue'=>array('label'=>"DateStartPlannedShort", 'checked'=>1, 'position'=>150),

-	'cd.date_ouverture'=>array('label'=>"DateStartRealShort", 'checked'=>1, 'position'=>160),

-	'cd.date_fin_validite'=>array('label'=>"DateEndPlannedShort", 'checked'=>1, 'position'=>170),

-	'cd.date_cloture'=>array('label'=>"DateEndRealShort", 'checked'=>1, 'position'=>180),

+	'c.ref'=>array('label'=>$langs->trans("Contract"), 'checked'=>1, 'position'=>80),

+	'p.description'=>array('label'=>$langs->trans("Service"), 'checked'=>1, 'position'=>80),

+	'cd.qty'=>array('label'=>$langs->trans("Qty"), 'checked'=>0, 'position'=>100),

+	'cd.total_ht'=>array('label'=>$langs->trans("TotalHT"), 'checked'=>0, 'position'=>100),

+	'cd.total_tva'=>array('label'=>$langs->trans("TotalVAT"), 'checked'=>0, 'position'=>100),

+	'cd.tva_tx'=>array('label'=>$langs->trans("VAT"), 'checked'=>0, 'position'=>100),

+	'cd.subprice'=>array('label'=>$langs->trans("PriceUHT"), 'checked'=>0, 'position'=>100),

+	's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1, 'position'=>100),

+	'cd.date_ouverture_prevue'=>array('label'=>$langs->trans("DateStartPlannedShort"), 'checked'=>(($mode == "" || $mode == -1) || $mode == "0")),

+	'cd.date_ouverture'=>array('label'=>$langs->trans("DateStartRealShort"), 'checked'=>(($mode == "" || $mode == -1) || $mode > 0)),

+	'cd.date_fin_validite'=>array('label'=>$langs->trans("DateEndPlannedShort"), 'checked'=>(($mode == "" || $mode == -1) || $mode < 5)),

+	'cd.date_cloture'=>array('label'=>$langs->trans("DateEndRealShort"), 'checked'=>(($mode == "" || $mode == -1) || $mode >= 5)),

+	'status'=>array('label'=>$langs->trans("Status"), 'checked'=>1),

@@ -134,2 +133 @@
-	'cd.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500),

-	'status'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000)

+	'cd.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500)

@@ -138,2 +136,8 @@
-include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';

-

+if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0)

+{

+	foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val)

+	{

+		if (!empty($extrafields->attributes[$object->table_element]['list'][$key]))

+			$arrayfields["ef.".$key] = array('label'=>$extrafields->attributes[$object->table_element]['label'][$key], 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key] < 0) ? 0 : 1), 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3 && $extrafields->attributes[$object->table_element]['perms'][$key]));

+	}

+}

@@ -143,5 +147 @@
-$permissiontoread = $user->hasRight('contrat', 'lire');

-$permissiontoadd = $user->hasRight('contrat', 'creer');

-$permissiontodelete = $user->hasRight('contrat', 'supprimer');

-

-$result = restrictedArea($user, 'contrat', 0);

+

@@ -154,7 +154,2 @@
-if (GETPOST('cancel', 'alpha')) {

-	$action = 'list';

-	$massaction = '';

-}

-if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {

-	$massaction = '';

-}

+if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }

+if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') { $massaction = ''; }

@@ -164,5 +159,4 @@
-if ($reshook < 0) {

-	setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

-}

-

-if (empty($reshook)) {

+if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

+

+if (empty($reshook))

+{

@@ -172,2 +166,3 @@
-	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

-		$search_product_category = 0;

+	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

+	{

+   		$search_product_category = 0;

@@ -175,5 +169,0 @@
-		$search_subprice = "";

-		$search_qty = "";

-		$search_total_ht = "";

-		$search_total_tva = "";

-		$search_total_ttc = "";

@@ -182 +172 @@
-		$search_status = "";

+		$search_status = -1;

@@ -199 +189,3 @@
-		$toselect = array();

+		$mode = '';

+		$filter = '';

+		$toselect = '';

@@ -208,0 +201,2 @@
+$now = dol_now();

+

@@ -211,20 +205 @@
-$now = dol_now();

-

-$title = $langs->trans("ListOfServices");

-if ($search_status == "0") {

-	$title = $langs->trans("ListOfInactiveServices"); // Must use == "0"

-}

-if ($search_status == "4" && $filter != "expired") {

-	$title = $langs->trans("ListOfRunningServices");

-}

-if ($search_status == "4" && $filter == "expired") {

-	$title = $langs->trans("ListOfExpiredServices");

-}

-if ($search_status == "5") {

-	$title = $langs->trans("ListOfClosedServices");

-}

-$help_url = '';

-

-// Build and execute select

-// --------------------------------------------------------------------

-$sql = "SELECT c.rowid as cid, c.ref, c.statut as cstatut, c.ref_customer, c.ref_supplier,";

+$sql = "SELECT c.rowid as cid, c.ref, c.statut as cstatut,";

@@ -232,5 +207,3 @@
-$sql .= " cd.rowid, cd.description, cd.statut, cd.product_type as type,";

-$sql .= " p.rowid as pid, p.ref as pref, p.label as label, p.fk_product_type as ptype, p.tobuy, p.tosell, p.barcode, p.entity as pentity,";

-if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {

-	$sql .= " sc.fk_soc, sc.fk_user,";

-}

+$sql .= " cd.rowid, cd.description, cd.statut,";

+$sql .= " p.rowid as pid, p.ref as pref, p.label as label, p.fk_product_type as ptype, p.entity as pentity,";

+if (!$user->rights->societe->client->voir && !$socid) $sql .= " sc.fk_soc, sc.fk_user,";

@@ -250,3 +223 @@
-	foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {

-		$sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');

-	}

+	foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');

@@ -256 +227 @@
-$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

+$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook

@@ -260,3 +231 @@
-if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {

-	$sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";

-}

+if (!$user->rights->societe->client->voir && !$socid) $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";

@@ -264,3 +233 @@
-if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {

-	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (cd.rowid = ef.fk_object)";

-}

+if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (cd.rowid = ef.fk_object)";

@@ -268,4 +235,2 @@
-if ($search_product_category > 0) {

-	$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product';

-}

-$sql .= " WHERE c.entity IN (".getEntity($object->element).")";

+if ($search_product_category > 0) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product';

+$sql .= " WHERE c.entity = ".$conf->entity;

@@ -273,3 +238 @@
-if ($search_product_category > 0) {

-	$sql .= " AND cp.fk_categorie = ".((int) $search_product_category);

-}

+if ($search_product_category > 0) $sql .= " AND cp.fk_categorie = ".$search_product_category;

@@ -277,99 +240,35 @@
-if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {

-	$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);

-}

-if ($search_status == "0") {

-	$sql .= " AND cd.statut = 0";

-}

-if ($search_status == "4") {

-	$sql .= " AND cd.statut = 4";

-}

-if ($search_status == "4&filter=expired") {

-	$sql .= " AND cd.statut = 4 AND cd.date_fin_validite < '".$db->idate($now)."'";

-}

-if ($search_status == "4&filter=notexpired") {

-	$sql .= " AND cd.statut = 4 AND cd.date_fin_validite >= '".$db->idate($now)."'";

-}

-if ($search_status == "5") {

-	$sql .= " AND cd.statut = 5";

-}

-if ($search_subprice) {

-	$sql .= natural_search("cd.subprice", $search_subprice, 1);

-}

-if ($search_qty) {

-	$sql .= natural_search("cd.qty", $search_qty, 1);

-}

-if ($search_total_ht) {

-	$sql .= natural_search("cd.total_ht", $search_total_ht, 1);

-}

-if ($search_total_tva) {

-	$sql .= natural_search("cd.total_tva", $search_total_tva, 1);

-}

-if ($search_total_ttc) {

-	$sql .= natural_search("cd.total_ttc", $search_total_ttc, 1);

-}

-if ($search_name) {

-	$sql .= natural_search("s.nom", $search_name);

-}

-if ($search_contract) {

-	$sql .= natural_search("c.ref", $search_contract);

-}

-if ($search_service) {

-	$sql .= natural_search(array("p.ref", "p.description", "cd.description"), $search_service);

-}

-if ($socid > 0) {

-	$sql .= " AND s.rowid = ".((int) $socid);

-}

-

-$filter_dateouvertureprevue = '';

-$filter_date1 = '';

-$filter_date2 = '';

-$filter_opcloture = '';

-

-$filter_dateouvertureprevue_start = dol_mktime(0, 0, 0, $opouvertureprevuemonth, $opouvertureprevueday, $opouvertureprevueyear);

-$filter_dateouvertureprevue_end = dol_mktime(23, 59, 59, $opouvertureprevuemonth, $opouvertureprevueday, $opouvertureprevueyear);

-if ($filter_dateouvertureprevue_start != '' && $filter_opouvertureprevue == -1) {

-	$filter_opouvertureprevue = ' BETWEEN ';

-}

-

-$filter_date1_start = dol_mktime(0, 0, 0, $op1month, $op1day, $op1year);

-$filter_date1_end = dol_mktime(23, 59, 59, $op1month, $op1day, $op1year);

-if ($filter_date1_start != '' && $filter_op1 == -1) {

-	$filter_op1 = ' BETWEEN ';

-}

-

-$filter_date2_start = dol_mktime(0, 0, 0, $op2month, $op2day, $op2year);

-$filter_date2_end = dol_mktime(23, 59, 59, $op2month, $op2day, $op2year);

-if ($filter_date2_start != '' && $filter_op2 == -1) {

-	$filter_op2 = ' BETWEEN ';

-}

-

-$filter_datecloture_start = dol_mktime(0, 0, 0, $opcloturemonth, $opclotureday, $opclotureyear);

-$filter_datecloture_end = dol_mktime(23, 59, 59, $opcloturemonth, $opclotureday, $opclotureyear);

-if ($filter_datecloture_start != '' && $filter_opcloture == -1) {

-	$filter_opcloture = ' BETWEEN ';

-}

-

-if (!empty($filter_opouvertureprevue) && $filter_opouvertureprevue != -1 && $filter_opouvertureprevue != ' BETWEEN ' && $filter_dateouvertureprevue_start != '') {

-	$sql .= " AND cd.date_ouverture_prevue ".$filter_opouvertureprevue." '".$db->idate($filter_dateouvertureprevue_start)."'";

-}

-if (!empty($filter_opouvertureprevue) && $filter_opouvertureprevue == ' BETWEEN ') {

-	$sql .= " AND cd.date_ouverture_prevue ".$filter_opouvertureprevue." '".$db->idate($filter_dateouvertureprevue_start)."' AND '".$db->idate($filter_dateouvertureprevue_end)."'";

-}

-if (!empty($filter_op1) && $filter_op1 != -1 && $filter_op1 != ' BETWEEN ' && $filter_date1_start != '') {

-	$sql .= " AND cd.date_ouverture ".$filter_op1." '".$db->idate($filter_date1_start)."'";

-}

-if (!empty($filter_op1) && $filter_op1 == ' BETWEEN ') {

-	$sql .= " AND cd.date_ouverture ".$filter_op1." '".$db->idate($filter_date1_start)."' AND '".$db->idate($filter_date1_end)."'";

-}

-if (!empty($filter_op2) && $filter_op2 != -1 && $filter_op2 != ' BETWEEN ' && $filter_date2_start != '') {

-	$sql .= " AND cd.date_fin_validite ".$filter_op2." '".$db->idate($filter_date2_start)."'";

-}

-if (!empty($filter_op2) && $filter_op2 == ' BETWEEN ') {

-	$sql .= " AND cd.date_fin_validite ".$filter_op2." '".$db->idate($filter_date2_start)."' AND '".$db->idate($filter_date2_end)."'";

-}

-if (!empty($filter_opcloture) && $filter_opcloture != ' BETWEEN ' && $filter_opcloture != -1 && $filter_datecloture_start != '') {

-	$sql .= " AND cd.date_cloture ".$filter_opcloture." '".$db->idate($filter_datecloture_start)."'";

-}

-if (!empty($filter_opcloture) && $filter_opcloture == ' BETWEEN ') {

-	$sql .= " AND cd.date_cloture ".$filter_opcloture." '".$db->idate($filter_datecloture_start)."' AND '".$db->idate($filter_datecloture_end)."'";

-}

+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;

+if ($mode == "0") $sql .= " AND cd.statut = 0";

+if ($mode == "4") $sql .= " AND cd.statut = 4";

+if ($mode == "5") $sql .= " AND cd.statut = 5";

+if ($filter == "expired") $sql .= " AND cd.date_fin_validite < '".$db->idate($now)."'";

+if ($filter == "notexpired") $sql .= " AND cd.date_fin_validite >= '".$db->idate($now)."'";

+if ($search_name)     $sql .= " AND s.nom LIKE '%".$db->escape($search_name)."%'";

+if ($search_contract) $sql .= " AND c.ref LIKE '%".$db->escape($search_contract)."%' ";

+if ($search_service)  $sql .= " AND (p.ref LIKE '%".$db->escape($search_service)."%' OR p.description LIKE '%".$db->escape($search_service)."%' OR cd.description LIKE '%".$db->escape($search_service)."%')";

+if ($socid > 0)       $sql .= " AND s.rowid = ".$socid;

+

+$filter_dateouvertureprevue_start=dol_mktime(0, 0, 0, $opouvertureprevuemonth, $opouvertureprevueday, $opouvertureprevueyear);

+$filter_dateouvertureprevue_end=dol_mktime(23, 59, 59, $opouvertureprevuemonth, $opouvertureprevueday, $opouvertureprevueyear);

+if ($filter_dateouvertureprevue_start != '' && $filter_opouvertureprevue == -1) $filter_opouvertureprevue = ' BETWEEN ';

+

+$filter_date1_start =dol_mktime(0, 0, 0, $op1month, $op1day, $op1year);

+$filter_date1_end =dol_mktime(23, 59, 59, $op1month, $op1day, $op1year);

+if ($filter_date1_start != '' && $filter_op1 == -1) $filter_op1 = ' BETWEEN ';

+

+$filter_date2_start=dol_mktime(0, 0, 0, $op2month, $op2day, $op2year);

+$filter_date2_end=dol_mktime(23, 59, 59, $op2month, $op2day, $op2year);

+if ($filter_date2_start != '' && $filter_op2 == -1) $filter_op2 = ' BETWEEN ';

+

+$filter_datecloture_start=dol_mktime(0, 0, 0, $opcloturemonth, $opclotureday, $opclotureyear);

+$filter_datecloture_end=dol_mktime(23, 59, 59, $opcloturemonth, $opclotureday, $opclotureyear);

+if ($filter_datecloture_start != '' && $filter_opcloture == -1) $filter_opcloture = ' BETWEEN ';

+

+if (! empty($filter_opouvertureprevue) && $filter_opouvertureprevue != -1 && $filter_opouvertureprevue != ' BETWEEN ' && $filter_dateouvertureprevue_start != '') $sql.= " AND cd.date_ouverture_prevue ".$filter_opouvertureprevue." '".$db->idate($filter_dateouvertureprevue_start)."'";

+if (! empty($filter_opouvertureprevue) && $filter_opouvertureprevue == ' BETWEEN ') $sql.= " AND '".$db->idate($filter_dateouvertureprevue_end)."'";

+if (! empty($filter_op1) && $filter_op1 != -1 && $filter_op1 != ' BETWEEN ' && $filter_date1_start != '') $sql.= " AND cd.date_ouverture ".$filter_op1." '".$db->idate($filter_date1_start)."'";

+if (! empty($filter_op1) && $filter_op1==' BETWEEN ')  $sql.= " AND '".$db->idate($filter_date1_end)."'";

+if (! empty($filter_op2) && $filter_op2 != -1 && $filter_op2 != ' BETWEEN ' && $filter_date2_start != '') $sql.= " AND cd.date_fin_validite ".$filter_op2." '".$db->idate($filter_date2_start)."'";

+if (! empty($filter_op2) && $filter_op2==' BETWEEN ')  $sql.= " AND '".$db->idate($filter_date2_end)."'";

+if (! empty($filter_opcloture) && $filter_opcloture != ' BETWEEN ' && $filter_opcloture != -1 && $filter_datecloture_start != '') $sql.= " AND cd.date_cloture ".$filter_opcloture." '".$db->idate($filter_datecloture_start)."'";

+if (! empty($filter_opcloture) && $filter_opcloture==' BETWEEN ')  $sql.= " AND '".$db->idate($filter_datecloture_end)."'";

@@ -377,0 +277 @@
+$sql .= $db->order($sortfield, $sortorder);

@@ -381 +280,0 @@
-// Count total nb of records

@@ -383 +282,2 @@
-if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {

+if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))

+{

@@ -386 +286,2 @@
-	if (($page * $limit) > $nbtotalofrecords) {	// if total resultset is smaller then paging size (filtering), goto and load page 0

+	if (($page * $limit) > $nbtotalofrecords)	// if total resultset is smaller then paging size (filtering), goto and load page 0

+	{

@@ -392,5 +293 @@
-// Complete request and execute it with limit

-$sql .= $db->order($sortfield, $sortorder);

-if ($limit) {

-	$sql .= $db->plimit($limit + 1, $offset);

-}

+$sql .= $db->plimit($limit + 1, $offset);

@@ -401 +298,2 @@
-if (!$resql) {

+if (!$resql)

+{

@@ -409,6 +307,6 @@
-// Direct jump if only one record found

-if ($num == 1 && getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {

-	$obj = $db->fetch_object($resql);

-	$id = $obj->id;

-	header("Location: ".DOL_URL_ROOT.'/projet/tasks/task.php?id='.$id.'&withprojet=1');

-	exit;

+if ($num == 1 && ! empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all)

+{

+    $obj = $db->fetch_object($resql);

+    $id = $obj->id;

+    header("Location: ".DOL_URL_ROOT.'/projet/tasks/task.php?id='.$id.'&withprojet=1');

+    exit;

@@ -417,7 +315 @@
-

-// Output page

-// --------------------------------------------------------------------

-

-llxHeader('', $title, $help_url);

-

-$arrayofselected = is_array($toselect) ? $toselect : array();

+llxHeader(null, $langs->trans("Services"));

@@ -426,63 +318,16 @@
-if (!empty($mode)) {

-	$param .= '&mode='.urlencode($mode);

-}

-if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {

-	$param .= '&contextpage='.urlencode($contextpage);

-}

-if ($limit > 0 && $limit != $conf->liste_limit) {

-	$param .= '&limit='.((int) $limit);

-}

-if ($optioncss != '') {

-	$param .= '&optioncss='.urlencode($optioncss);

-}

-if ($search_contract) {

-	$param .= '&amp;search_contract='.urlencode($search_contract);

-}

-if ($search_name) {

-	$param .= '&amp;search_name='.urlencode($search_name);

-}

-if ($search_subprice) {

-	$param .= '&amp;search_subprice='.urlencode($search_subprice);

-}

-if ($search_qty) {

-	$param .= '&amp;search_qty='.urlencode($search_qty);

-}

-if ($search_total_ht) {

-	$param .= '&amp;search_total_ht='.urlencode($search_total_ht);

-}

-if ($search_total_tva) {

-	$param .= '&amp;search_total_tva='.urlencode($search_total_tva);

-}

-if ($search_total_ttc) {

-	$param .= '&amp;search_total_ttc='.urlencode($search_total_ttc);

-}

-if ($search_service) {

-	$param .= '&amp;search_service='.urlencode($search_service);

-}

-if ($search_status) {

-	$param .= '&amp;search_status='.urlencode($search_status);

-}

-if (!empty($filter_opouvertureprevue) && $filter_opouvertureprevue != -1) {

-	$param .= '&amp;filter_opouvertureprevue='.urlencode($filter_opouvertureprevue);

-}

-if (!empty($filter_op1) && $filter_op1 != -1) {

-	$param .= '&amp;filter_op1='.urlencode($filter_op1);

-}

-if (!empty($filter_op2) && $filter_op2 != -1) {

-	$param .= '&amp;filter_op2='.urlencode($filter_op2);

-}

-if (!empty($filter_opcloture) && $filter_opcloture != -1) {

-	$param .= '&amp;filter_opcloture='.urlencode($filter_opcloture);

-}

-if ($filter_dateouvertureprevue_start != '') {

-	$param .= '&amp;opouvertureprevueday='.((int) $opouvertureprevueday).'&amp;opouvertureprevuemonth='.((int) $opouvertureprevuemonth).'&amp;opouvertureprevueyear='.((int) $opouvertureprevueyear);

-}

-if ($filter_date1_start != '') {

-	$param .= '&amp;op1day='.((int) $op1day).'&amp;op1month='.((int) $op1month).'&amp;op1year='.((int) $op1year);

-}

-if ($filter_date2_start != '') {

-	$param .= '&amp;op2day='.((int) $op2day).'&amp;op2month='.((int) $op2month).'&amp;op2year='.((int) $op2year);

-}

-if ($filter_datecloture_start != '') {

-	$param .= '&amp;opclotureday='.((int) $op2day).'&amp;opcloturemonth='.((int) $op2month).'&amp;opclotureyear='.((int) $op2year);

-}

+if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);

+if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit;

+if ($search_contract) $param .= '&amp;search_contract='.urlencode($search_contract);

+if ($search_name)      $param .= '&amp;search_name='.urlencode($search_name);

+if ($search_service)  $param .= '&amp;search_service='.urlencode($search_service);

+if ($mode)            $param .= '&amp;mode='.urlencode($mode);

+if ($filter)          $param .= '&amp;filter='.urlencode($filter);

+if (!empty($filter_opouvertureprevue) && $filter_opouvertureprevue != -1) $param .= '&amp;filter_opouvertureprevue='.urlencode($filter_opouvertureprevue);

+if (!empty($filter_op1) && $filter_op1 != -1) $param .= '&amp;filter_op1='.urlencode($filter_op1);

+if (!empty($filter_op2) && $filter_op2 != -1) $param .= '&amp;filter_op2='.urlencode($filter_op2);

+if (!empty($filter_opcloture) && $filter_opcloture != -1) $param .= '&amp;filter_opcloture='.urlencode($filter_opcloture);

+if ($filter_dateouvertureprevue != '') $param .= '&amp;opouvertureprevueday='.$opouvertureprevueday.'&amp;opouvertureprevuemonth='.$opouvertureprevuemonth.'&amp;opouvertureprevueyear='.$opouvertureprevueyear;

+if ($filter_date1 != '') $param .= '&amp;op1day='.$op1day.'&amp;op1month='.$op1month.'&amp;op1year='.$op1year;

+if ($filter_date2 != '') $param .= '&amp;op2day='.$op2day.'&amp;op2month='.$op2month.'&amp;op2year='.$op2year;

+if ($filter_datecloture != '') $param .= '&amp;opclotureday='.$op2day.'&amp;opcloturemonth='.$op2month.'&amp;opclotureyear='.$op2year;

+if ($optioncss != '') $param .= '&optioncss='.$optioncss;

@@ -494,2 +339,2 @@
-	//'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),

-	//'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),

+	//'presend'=>$langs->trans("SendByMail"),

+	//'builddoc'=>$langs->trans("PDFMerge"),

@@ -497 +342 @@
-//if ($user->hasRight('contrat', 'supprimer')) $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");

+//if ($user->rights->contrat->supprimer) $arrayofmassactions['predelete']='<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");

@@ -501,4 +346,2 @@
-print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";

-if ($optioncss != '') {

-	print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';

-}

+print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';

+if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';

@@ -512,5 +355,6 @@
-print '<input type="hidden" name="page_y" value="">';

-print '<input type="hidden" name="mode" value="'.$mode.'">';

-

-$newcardbutton = '';

-

+

+$title = $langs->trans("ListOfServices");

+if ($mode == "0") $title = $langs->trans("ListOfInactiveServices"); // Must use == "0"

+if ($mode == "4" && $filter != "expired") $title = $langs->trans("ListOfRunningServices");

+if ($mode == "4" && $filter == "expired") $title = $langs->trans("ListOfExpiredServices");

+if ($mode == "5") $title = $langs->trans("ListOfClosedServices");

@@ -520,4 +364,3 @@
-if (!empty($sall)) {

-	foreach ($fieldstosearchall as $key => $val) {

-		$fieldstosearchall[$key] = $langs->trans($val);

-	}

+if ($sall)

+{

+	foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);

@@ -528 +370,0 @@
-$moreforfilter = '';

@@ -531 +373,2 @@
-if (isModEnabled('categorie') && ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'))) {

+if ($conf->categorie->enabled && ($user->rights->produit->lire || $user->rights->service->lire))

+{

@@ -534 +377 @@
-	$tmptitle = $langs->trans('IncludingProductWithTag');

+	$moreforfilter .= $langs->trans('IncludingProductWithTag').': ';

@@ -536 +379 @@
-	$moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, 0, 'widthcentpercentminusx maxwidth300', 1);

+	$moreforfilter .= $form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1);

@@ -541,9 +384,7 @@
-$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

-if (empty($reshook)) {

-	$moreforfilter .= $hookmanager->resPrint;

-} else {

-	$moreforfilter = $hookmanager->resPrint;

-}

-

-

-if (!empty($moreforfilter)) {

+$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook

+if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;

+else $moreforfilter = $hookmanager->resPrint;

+

+

+if (!empty($moreforfilter))

+{

@@ -552,3 +392,0 @@
-	$parameters = array();

-	$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

-	print $hookmanager->resPrint;

@@ -559,2 +397 @@
-$selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields

-$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');

+$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields

@@ -566,12 +403,30 @@
-// Fields title search

-// --------------------------------------------------------------------

-print '<tr class="liste_titre_filter">';

-// Action column

-if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {

-	print '<td class="liste_titre center maxwidthsearch">';

-	$searchpicto = $form->showFilterButtons('left');

-	print $searchpicto;

-	print '</td>';

-}

-if (!empty($arrayfields['c.ref']['checked'])) {

-	print '<td class="liste_titre">';

+print '<tr class="liste_titre">';

+if (!empty($arrayfields['c.ref']['checked'])) print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref", "", $param, "", $sortfield, $sortorder);

+if (!empty($arrayfields['p.description']['checked'])) print_liste_field_titre($arrayfields['p.description']['label'], $_SERVER["PHP_SELF"], "p.description", "", $param, "", $sortfield, $sortorder);

+if (!empty($arrayfields['cd.qty']['checked']))  print_liste_field_titre($arrayfields['cd.qty']['label'], $_SERVER["PHP_SELF"], "cd.qty", "", $param, '', $sortfield, $sortorder, 'center nowrap ');

+if (!empty($arrayfields['cd.total_ht']['checked']))  print_liste_field_titre($arrayfields['cd.total_ht']['label'], $_SERVER["PHP_SELF"], "cd.total_ht", "", $param, '', $sortfield, $sortorder, 'center nowrap ');

+if (!empty($arrayfields['cd.total_tva']['checked']))  print_liste_field_titre($arrayfields['cd.total_tva']['label'], $_SERVER["PHP_SELF"], "cd.total_tva", "", $param, '', $sortfield, $sortorder, 'center nowrap ');

+if (!empty($arrayfields['cd.tva_tx']['checked']))  print_liste_field_titre($arrayfields['cd.tva_tx']['label'], $_SERVER["PHP_SELF"], "cd.tva_tx", "", $param, '', $sortfield, $sortorder, 'center nowrap ');

+if (!empty($arrayfields['cd.subprice']['checked']))  print_liste_field_titre($arrayfields['cd.subprice']['label'], $_SERVER["PHP_SELF"], "cd.subprice", "", $param, '', $sortfield, $sortorder, 'center nowrap ');

+if (!empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, "", $sortfield, $sortorder);

+if (!empty($arrayfields['cd.date_ouverture_prevue']['checked'])) print_liste_field_titre($arrayfields['cd.date_ouverture_prevue']['label'], $_SERVER["PHP_SELF"], "cd.date_ouverture_prevue", "", $param, '', $sortfield, $sortorder, 'center ');

+if (!empty($arrayfields['cd.date_ouverture']['checked'])) print_liste_field_titre($arrayfields['cd.date_ouverture']['label'], $_SERVER["PHP_SELF"], "cd.date_ouverture", "", $param, '', $sortfield, $sortorder, 'center ');

+if (!empty($arrayfields['cd.date_fin_validite']['checked'])) print_liste_field_titre($arrayfields['cd.date_fin_validite']['label'], $_SERVER["PHP_SELF"], "cd.date_fin_validite", "", $param, '', $sortfield, $sortorder, 'center ');

+if (!empty($arrayfields['cd.date_cloture']['checked'])) print_liste_field_titre($arrayfields['cd.date_cloture']['label'], $_SERVER["PHP_SELF"], "cd.date_cloture", "", $param, '', $sortfield, $sortorder, 'center ');

+// Extra fields

+include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';

+// Hook fields

+$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);

+$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook

+print $hookmanager->resPrint;

+if (!empty($arrayfields['cd.datec']['checked']))  print_liste_field_titre($arrayfields['cd.datec']['label'], $_SERVER["PHP_SELF"], "cd.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');

+if (!empty($arrayfields['cd.tms']['checked']))    print_liste_field_titre($arrayfields['cd.tms']['label'], $_SERVER["PHP_SELF"], "cd.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');

+if (!empty($arrayfields['status']['checked'])) print_liste_field_titre($arrayfields['status']['label'], $_SERVER["PHP_SELF"], "cd.statut,c.statut", "", $param, '', $sortfield, $sortorder, 'right ');

+print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');

+print "</tr>\n";

+

+print '<tr class="liste_titre">';

+if (!empty($arrayfields['c.ref']['checked']))

+{

+	print '<td class="liste_titre">';

+	print '<input type="hidden" name="filter" value="'.$filter.'">';

@@ -579 +434 @@
-	print '<input type="text" class="flat maxwidth75" name="search_contract" value="'.dol_escape_htmltag($search_contract).'">';

+	print '<input type="text" class="flat" size="3" name="search_contract" value="'.dol_escape_htmltag($search_contract).'">';

@@ -583 +438,2 @@
-if (!empty($arrayfields['p.description']['checked'])) {

+if (!empty($arrayfields['p.description']['checked']))

+{

@@ -589,22 +445,23 @@
-if (!empty($arrayfields['cd.tva_tx']['checked'])) {

-	print '<td class="liste_titre">';

-	print '</td>';

-}

-if (!empty($arrayfields['cd.subprice']['checked'])) {

-	print '<td class="liste_titre right">';

-	print '<input type="text" class="flat maxwidth50 right" name="search_subprice" value="'.dol_escape_htmltag($search_subprice).'">';

-	print '</td>';

-}

-if (!empty($arrayfields['cd.qty']['checked'])) {

-	print '<td class="liste_titre right">';

-	print '<input type="text" class="flat maxwidth50 right" name="search_qty" value="'.dol_escape_htmltag($search_qty).'">';

-	print '</td>';

-}

-if (!empty($arrayfields['cd.total_ht']['checked'])) {

-	print '<td class="liste_titre right">';

-	print '<input type="text" class="flat maxwidth50" name="search_total_ht" value="'.dol_escape_htmltag($search_total_ht).'">';

-	print '</td>';

-}

-if (!empty($arrayfields['cd.total_tva']['checked'])) {

-	print '<td class="liste_titre right">';

-	print '<input type="text" class="flat maxwidth50" name="search_total_tva" value="'.dol_escape_htmltag($search_total_tva).'">';

+if (!empty($arrayfields['cd.qty']['checked']))

+{

+	print '<td class="liste_titre">';

+	print '</td>';

+}

+if (!empty($arrayfields['cd.total_ht']['checked']))

+{

+	print '<td class="liste_titre">';

+	print '</td>';

+}

+if (!empty($arrayfields['cd.total_tva']['checked']))

+{

+	print '<td class="liste_titre">';

+	print '</td>';

+}

+if (!empty($arrayfields['cd.tva_tx']['checked']))

+{

+	print '<td class="liste_titre">';

+	print '</td>';

+}

+if (!empty($arrayfields['cd.subprice']['checked']))

+{

+	print '<td class="liste_titre">';

@@ -614 +471,2 @@
-if (!empty($arrayfields['s.nom']['checked'])) {

+if (!empty($arrayfields['s.nom']['checked']))

+{

@@ -620 +478,3 @@
-if (!empty($arrayfields['cd.date_ouverture_prevue']['checked'])) {

+

+if (!empty($arrayfields['cd.date_ouverture_prevue']['checked']))

+{

@@ -623 +483 @@
-	print $form->selectarray('filter_opouvertureprevue', $arrayofoperators, $filter_opouvertureprevue, 1, 0, 0, '', 0, 0, 0, '', 'width50');

+	print $form->selectarray('filter_opouvertureprevue', $arrayofoperators, $filter_opouvertureprevue, 1);

@@ -629 +489,2 @@
-if (!empty($arrayfields['cd.date_ouverture']['checked'])) {

+if (!empty($arrayfields['cd.date_ouverture']['checked']))

+{

@@ -632 +493 @@
-	print $form->selectarray('filter_op1', $arrayofoperators, $filter_op1, 1, 0, 0, '', 0, 0, 0, '', 'width50');

+	print $form->selectarray('filter_op1', $arrayofoperators, $filter_op1, 1);

@@ -638 +499,2 @@
-if (!empty($arrayfields['cd.date_fin_validite']['checked'])) {

+if (!empty($arrayfields['cd.date_fin_validite']['checked']))

+{

@@ -641 +503 @@
-	print $form->selectarray('filter_op2', $arrayofoperators, $filter_op2, 1, 0, 0, '', 0, 0, 0, '', 'width50');

+	print $form->selectarray('filter_op2', $arrayofoperators, $filter_op2, 1);

@@ -647 +509,2 @@
-if (!empty($arrayfields['cd.date_cloture']['checked'])) {

+if (!empty($arrayfields['cd.date_cloture']['checked']))

+{

@@ -650 +513 @@
-	print $form->selectarray('filter_opcloture', $arrayofoperators, $filter_opcloture, 1, 0, 0, '', 0, 0, 0, '', 'width50');

+	print $form->selectarray('filter_opcloture', $arrayofoperators, $filter_opcloture, 1);

@@ -661 +524 @@
-$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

+$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook

@@ -663 +526,2 @@
-if (!empty($arrayfields['cd.datec']['checked'])) {

+if (!empty($arrayfields['cd.datec']['checked']))

+{

@@ -668 +532,2 @@
-if (!empty($arrayfields['cd.tms']['checked'])) {

+if (!empty($arrayfields['cd.tms']['checked']))

+{

@@ -673 +538,2 @@
-if (!empty($arrayfields['status']['checked'])) {

+if (!empty($arrayfields['status']['checked']))

+{

@@ -675 +541 @@
-	print '<td class="liste_titre right parentonrightofpage">';

+	print '<td class="liste_titre right">';

@@ -683,5 +549 @@
-	$search_status_new = GETPOST('search_status', 'alpha');

-	if ($filter == 'expired' && !preg_match('/expired/', $search_status_new)) {

-		$search_status_new .= '&filter=expired';

-	}

-	print $form->selectarray('search_status', $arrayofstatus, (strstr($search_status_new, ',') ? -1 : $search_status_new), 1, 0, 0, '', 0, 0, 0, '', 'search_status width100 onrightofpage');

+	print $form->selectarray('search_status', $arrayofstatus, (strstr($search_status, ',') ?-1 : $search_status), 1, 0, '', 0, 0, 0, '', 'maxwidth100onsmartphone');

@@ -691,80 +553,5 @@
-if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {

-	print '<td class="liste_titre center maxwidthsearch">';

-	$searchpicto = $form->showFilterButtons();

-	print $searchpicto;

-	print '</td>';

-}

-print '</tr>'."\n";

-

-$totalarray = array();

-$totalarray['nbfield'] = 0;

-

-// Fields title label

-// --------------------------------------------------------------------

-print '<tr class="liste_titre">';

-// Action column

-if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {

-	print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";

-	$totalarray['nbfield']++;

-}

-if (!empty($arrayfields['c.ref']['checked'])) {

-	print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref", "", $param, "", $sortfield, $sortorder);

-}

-if (!empty($arrayfields['p.description']['checked'])) {

-	print_liste_field_titre($arrayfields['p.description']['label'], $_SERVER["PHP_SELF"], "p.description", "", $param, "", $sortfield, $sortorder);

-}

-if (!empty($arrayfields['cd.tva_tx']['checked'])) {

-	print_liste_field_titre($arrayfields['cd.tva_tx']['label'], $_SERVER["PHP_SELF"], "cd.tva_tx", "", $param, '', $sortfield, $sortorder, 'center nowrap ');

-}

-if (!empty($arrayfields['cd.subprice']['checked'])) {

-	print_liste_field_titre($arrayfields['cd.subprice']['label'], $_SERVER["PHP_SELF"], "cd.subprice", "", $param, '', $sortfield, $sortorder, 'center nowrap ');

-}

-if (!empty($arrayfields['cd.qty']['checked'])) {

-	print_liste_field_titre($arrayfields['cd.qty']['label'], $_SERVER["PHP_SELF"], "cd.qty", "", $param, '', $sortfield, $sortorder, 'right nowrap ');

-}

-if (!empty($arrayfields['cd.total_ht']['checked'])) {

-	print_liste_field_titre($arrayfields['cd.total_ht']['label'], $_SERVER["PHP_SELF"], "cd.total_ht", "", $param, '', $sortfield, $sortorder, 'right nowrap ');

-}

-if (!empty($arrayfields['cd.total_tva']['checked'])) {

-	print_liste_field_titre($arrayfields['cd.total_tva']['label'], $_SERVER["PHP_SELF"], "cd.total_tva", "", $param, '', $sortfield, $sortorder, 'right nowrap ');

-}

-if (!empty($arrayfields['s.nom']['checked'])) {

-	print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, "", $sortfield, $sortorder);

-}

-if (!empty($arrayfields['cd.date_ouverture_prevue']['checked'])) {

-	print_liste_field_titre($arrayfields['cd.date_ouverture_prevue']['label'], $_SERVER["PHP_SELF"], "cd.date_ouverture_prevue", "", $param, '', $sortfield, $sortorder, 'center ');

-}

-if (!empty($arrayfields['cd.date_ouverture']['checked'])) {

-	print_liste_field_titre($arrayfields['cd.date_ouverture']['label'], $_SERVER["PHP_SELF"], "cd.date_ouverture", "", $param, '', $sortfield, $sortorder, 'center ');

-}

-if (!empty($arrayfields['cd.date_fin_validite']['checked'])) {

-	print_liste_field_titre($arrayfields['cd.date_fin_validite']['label'], $_SERVER["PHP_SELF"], "cd.date_fin_validite", "", $param, '', $sortfield, $sortorder, 'center ');

-}

-if (!empty($arrayfields['cd.date_cloture']['checked'])) {

-	print_liste_field_titre($arrayfields['cd.date_cloture']['label'], $_SERVER["PHP_SELF"], "cd.date_cloture", "", $param, '', $sortfield, $sortorder, 'center ');

-}

-// Extra fields

-include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';

-// Hook fields

-$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);

-$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

-print $hookmanager->resPrint;

-if (!empty($arrayfields['cd.datec']['checked'])) {

-	print_liste_field_titre($arrayfields['cd.datec']['label'], $_SERVER["PHP_SELF"], "cd.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');

-}

-if (!empty($arrayfields['cd.tms']['checked'])) {

-	print_liste_field_titre($arrayfields['cd.tms']['label'], $_SERVER["PHP_SELF"], "cd.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');

-}

-if (!empty($arrayfields['status']['checked'])) {

-	print_liste_field_titre($arrayfields['status']['label'], $_SERVER["PHP_SELF"], "cd.statut,c.statut", "", $param, '', $sortfield, $sortorder, 'right ');

-}

-// Action column

-if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {

-	print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";

-	$totalarray['nbfield']++;

-}

-print '</tr>'."\n";

-

-

-// Loop on record

-// --------------------------------------------------------------------

+print '<td class="liste_titre maxwidthsearch">';

+$searchpicto = $form->showFilterAndCheckAddButtons(0);

+print $searchpicto;

+print '</td>';

+print "</tr>\n";

@@ -776,4 +563,3 @@
-$savnbfield = $totalarray['nbfield'];

-$totalarray = array('nbfield'=>0, 'cd.qty'=>0, 'cd.total_ht'=>0, 'cd.total_tva'=>0);

-$imaxinloop = ($limit ? min($num, $limit) : $num);

-while ($i < $imaxinloop) {

+$totalarray = array();

+while ($i < min($num, $limit))

+{

@@ -781,3 +566,0 @@
-	if (empty($obj)) {

-		break; // Should not happen

-	}

@@ -787,2 +569,0 @@
-	$contractstatic->ref_customer = $obj->ref_customer;

-	$contractstatic->ref_supplier = $obj->ref_supplier;

@@ -796,27 +577,2 @@
-	$productstatic->id = $obj->pid;

-	$productstatic->type = $obj->ptype;

-	$productstatic->ref = $obj->pref;

-	$productstatic->entity = $obj->pentity;

-	$productstatic->status = $obj->tosell;

-	$productstatic->status_buy = $obj->tobuy;

-	$productstatic->label = $obj->label;

-	$productstatic->description = $obj->description;

-	$productstatic->barcode = $obj->barcode;

-

-	print '<tr data-rowid="'.$object->id.'" class="oddeven">';

-

-	// Action column

-	if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {

-		print '<td class="nowrap center">';

-		if ($massactionbutton || $massaction) {   // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined

-			$selected = 0;

-			if (in_array($obj->rowid, $arrayofselected)) {

-				$selected = 1;

-			}

-			print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';

-		}

-		print '</td>';

-		if (!$i) {

-			$totalarray['nbfield']++;

-		}

-	}

+	print '<tr class="oddeven">';

+

@@ -824,2 +580,3 @@
-	if (!empty($arrayfields['c.ref']['checked'])) {

-		print '<td class="nowraponall">';

+	if (!empty($arrayfields['c.ref']['checked']))

+	{

+		print '<td>';

@@ -828,3 +585 @@
-		if (!$i) {

-			$totalarray['nbfield']++;

-		}

+        if (!$i) $totalarray['nbfield']++;

@@ -833,3 +588,9 @@
-	if (!empty($arrayfields['p.description']['checked'])) {

-		print '<td class="tdoverflowmax300">';

-		if ($obj->pid > 0) {

+	if (!empty($arrayfields['p.description']['checked']))

+	{

+		print '<td>';

+		if ($obj->pid > 0)

+		{

+			$productstatic->id = $obj->pid;

+			$productstatic->type = $obj->ptype;

+			$productstatic->ref = $obj->pref;

+			$productstatic->entity = $obj->pentity;

@@ -838,10 +599 @@
-			if (!empty($obj->description) && getDolGlobalString('PRODUCT_DESC_IN_LIST')) {

-				print '<br><span class="small">'.dol_nl2br($obj->description).'</span>';

-			}

-		} else {

-			if ($obj->type == 0) {

-				print img_object($obj->description, 'product').' '.dol_trunc($obj->description, 24);

-			}

-			if ($obj->type == 1) {

-				print img_object($obj->description, 'service').' '.dol_trunc($obj->description, 24);

-			}

+			if (!empty($obj->description) && !empty($conf->global->PRODUCT_DESC_IN_LIST)) print '<br>'.dol_nl2br($obj->description);

@@ -849,3 +601,4 @@
-		print '</td>';

-		if (!$i) {

-			$totalarray['nbfield']++;

+		else

+		{

+			if ($obj->type == 0) print img_object($obj->description, 'product').' '.dol_trunc($obj->description, 24);

+			if ($obj->type == 1) print img_object($obj->description, 'service').' '.dol_trunc($obj->description, 24);

@@ -853,4 +606,32 @@
-	}

-

-	if (!empty($arrayfields['cd.tva_tx']['checked'])) {

-		print '<td class="right nowraponall">';

+		print '</td>';

+        if (!$i) $totalarray['nbfield']++;

+	}

+

+	if (!empty($arrayfields['cd.qty']['checked']))

+	{

+		print '<td>';

+		print $obj->qty;

+		print '</td>';

+        if (!$i) $totalarray['nbfield']++;

+	}

+	if (!empty($arrayfields['cd.total_ht']['checked']))

+	{

+		print '<td class="right">';

+		print price($obj->total_ht);

+		print '</td>';

+        if (!$i) $totalarray['nbfield']++;

+        if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'cd.total_ht';

+        $totalarray['val']['cd.total_ht'] += $obj->total_ht;

+    }

+	if (!empty($arrayfields['cd.total_tva']['checked']))

+	{

+		print '<td class="right">';

+		print price($obj->total_tva);

+		print '</td>';

+        if (!$i) $totalarray['nbfield']++;

+        if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'cd.total_tva';

+        $totalarray['val']['cd.total_tva'] += $obj->total_tva;

+    }

+	if (!empty($arrayfields['cd.tva_tx']['checked']))

+	{

+		print '<td class="right">';

@@ -859,6 +640,5 @@
-		if (!$i) {

-			$totalarray['nbfield']++;

-		}

-	}

-	if (!empty($arrayfields['cd.subprice']['checked'])) {

-		print '<td class="right nowraponall">';

+        if (!$i) $totalarray['nbfield']++;

+	}

+	if (!empty($arrayfields['cd.subprice']['checked']))

+	{

+		print '<td class="right">';

@@ -867,40 +647,3 @@
-		if (!$i) {

-			$totalarray['nbfield']++;

-		}

-	}

-	if (!empty($arrayfields['cd.qty']['checked'])) {

-		print '<td class="right nowraponall">';

-		print $obj->qty;

-		print '</td>';

-		if (!$i) {

-			$totalarray['nbfield']++;

-		}

-		if (!$i) {

-			$totalarray['pos'][$totalarray['nbfield']] = 'cd.qty';

-		}

-		$totalarray['val']['cd.qty'] += $obj->qty;

-	}

-	if (!empty($arrayfields['cd.total_ht']['checked'])) {

-		print '<td class="right nowraponall">';

-		print '<span class="amount">'.price($obj->total_ht).'</span>';

-		print '</td>';

-		if (!$i) {

-			$totalarray['nbfield']++;

-		}

-		if (!$i) {

-			$totalarray['pos'][$totalarray['nbfield']] = 'cd.total_ht';

-		}

-		$totalarray['val']['cd.total_ht'] += $obj->total_ht;

-	}

-	if (!empty($arrayfields['cd.total_tva']['checked'])) {

-		print '<td class="right nowraponall">';

-		print '<span class="amount">'.price($obj->total_tva).'</span>';

-		print '</td>';

-		if (!$i) {

-			$totalarray['nbfield']++;

-		}

-		if (!$i) {

-			$totalarray['pos'][$totalarray['nbfield']] = 'cd.total_tva';

-		}

-		$totalarray['val']['cd.total_tva'] += $obj->total_tva;

-	}

+        if (!$i) $totalarray['nbfield']++;

+	}

+

@@ -909,2 +652,3 @@
-	if (!empty($arrayfields['s.nom']['checked'])) {

-		print '<td class="tdoverflowmax100">';

+	if (!empty($arrayfields['s.nom']['checked']))

+	{

+		print '<td>';

@@ -913,3 +657 @@
-		if (!$i) {

-			$totalarray['nbfield']++;

-		}

+        if (!$i) $totalarray['nbfield']++;

@@ -919,18 +661,14 @@
-	if (!empty($arrayfields['cd.date_ouverture_prevue']['checked'])) {

-		print '<td class="center nowraponall">';

-		print($obj->date_ouverture_prevue ? dol_print_date($db->jdate($obj->date_ouverture_prevue), 'dayhour') : '&nbsp;');

-		if ($db->jdate($obj->date_ouverture_prevue) && ($db->jdate($obj->date_ouverture_prevue) < ($now - $conf->contrat->services->inactifs->warning_delay)) && $obj->statut == 0) {

-			print ' '.img_picto($langs->trans("Late"), "warning");

-		} else {

-			print '&nbsp;&nbsp;&nbsp;&nbsp;';

-		}

-		print '</td>';

-		if (!$i) {

-			$totalarray['nbfield']++;

-		}

-	}

-	if (!empty($arrayfields['cd.date_ouverture']['checked'])) {

-		print '<td class="center nowraponall">'.($obj->date_ouverture ? dol_print_date($db->jdate($obj->date_ouverture), 'dayhour') : '&nbsp;').'</td>';

-		if (!$i) {

-			$totalarray['nbfield']++;

-		}

+	if (!empty($arrayfields['cd.date_ouverture_prevue']['checked']))

+	{

+		print '<td class="center">';

+		print ($obj->date_ouverture_prevue ?dol_print_date($db->jdate($obj->date_ouverture_prevue), 'dayhour') : '&nbsp;');

+		if ($db->jdate($obj->date_ouverture_prevue) && ($db->jdate($obj->date_ouverture_prevue) < ($now - $conf->contrat->services->inactifs->warning_delay)) && $obj->statut == 0)

+		print ' '.img_picto($langs->trans("Late"), "warning");

+		else print '&nbsp;&nbsp;&nbsp;&nbsp;';

+		print '</td>';

+        if (!$i) $totalarray['nbfield']++;

+	}

+	if (!empty($arrayfields['cd.date_ouverture']['checked']))

+	{

+		print '<td class="center">'.($obj->date_ouverture ?dol_print_date($db->jdate($obj->date_ouverture), 'dayhour') : '&nbsp;').'</td>';

+        if (!$i) $totalarray['nbfield']++;

@@ -939,3 +677,5 @@
-	if (!empty($arrayfields['cd.date_fin_validite']['checked'])) {

-		print '<td class="center nowraponall">'.($obj->date_fin_validite ? dol_print_date($db->jdate($obj->date_fin_validite), 'dayhour') : '&nbsp;');

-		if ($obj->date_fin_validite && $db->jdate($obj->date_fin_validite) < ($now - $conf->contrat->services->expires->warning_delay) && $obj->statut < 5) {

+	if (!empty($arrayfields['cd.date_fin_validite']['checked']))

+	{

+		print '<td class="center">'.($obj->date_fin_validite ?dol_print_date($db->jdate($obj->date_fin_validite), 'dayhour') : '&nbsp;');

+		if ($obj->date_fin_validite && $db->jdate($obj->date_fin_validite) < ($now - $conf->contrat->services->expires->warning_delay) && $obj->statut < 5)

+		{

@@ -945,2 +684,0 @@
-		} else {

-			print '&nbsp;&nbsp;&nbsp;&nbsp;';

@@ -948,4 +686,3 @@
-		print '</td>';

-		if (!$i) {

-			$totalarray['nbfield']++;

-		}

+		else print '&nbsp;&nbsp;&nbsp;&nbsp;';

+		print '</td>';

+        if (!$i) $totalarray['nbfield']++;

@@ -954,5 +691,4 @@
-	if (!empty($arrayfields['cd.date_cloture']['checked'])) {

-		print '<td class="center nowraponall">'.dol_print_date($db->jdate($obj->date_cloture), 'dayhour').'</td>';

-		if (!$i) {

-			$totalarray['nbfield']++;

-		}

+	if (!empty($arrayfields['cd.date_cloture']['checked']))

+	{

+		print '<td class="center">'.dol_print_date($db->jdate($obj->date_cloture), 'dayhour').'</td>';

+        if (!$i) $totalarray['nbfield']++;

@@ -968 +704,2 @@
-	if (!empty($arrayfields['cd.datec']['checked'])) {

+	if (!empty($arrayfields['cd.datec']['checked']))

+	{

@@ -972,3 +709 @@
-		if (!$i) {

-			$totalarray['nbfield']++;

-		}

+		if (!$i) $totalarray['nbfield']++;

@@ -977,2 +712,3 @@
-	if (!empty($arrayfields['cd.tms']['checked'])) {

-		print '<td class="center nowraponall">';

+	if (!empty($arrayfields['cd.tms']['checked']))

+	{

+		print '<td class="center">';

@@ -981,3 +717 @@
-		if (!$i) {

-			$totalarray['nbfield']++;

-		}

+		if (!$i) $totalarray['nbfield']++;

@@ -986,3 +720,5 @@
-	if (!empty($arrayfields['status']['checked'])) {

-		print '<td class="right">';

-		if ($obj->cstatut == 0) {

+	if (!empty($arrayfields['status']['checked']))

+	{

+	    print '<td class="right">';

+	    if ($obj->cstatut == 0)

+	    {

@@ -990,8 +726,8 @@
-			print $contractstatic->LibStatut(0, 5);

-		} else {

-			print $staticcontratligne->LibStatut($obj->statut, 5, ($obj->date_fin_validite && $db->jdate($obj->date_fin_validite) < $now) ? 1 : 0);

-		}

-		print '</td>';

-		if (!$i) {

-			$totalarray['nbfield']++;

-		}

+		    print $contractstatic->LibStatut(0, 5);

+	    }

+	    else

+	    {

+		    print $staticcontratligne->LibStatut($obj->statut, 5, ($obj->date_fin_validite && $db->jdate($obj->date_fin_validite) < $now) ? 1 : 0);

+	    }

+	    print '</td>';

+        if (!$i) $totalarray['nbfield']++;

@@ -1000,16 +736,11 @@
-	if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {

-		print '<td class="nowrap center">';

-		if ($massactionbutton || $massaction) {   // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined

-			$selected = 0;

-			if (in_array($obj->rowid, $arrayofselected)) {

-				$selected = 1;

-			}

-			print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';

-		}

-		print '</td>';

-		if (!$i) {

-			$totalarray['nbfield']++;

-		}

-	}

-

-	print '</tr>'."\n";

+	print '<td class="nowrap center">';

+	if ($massactionbutton || $massaction)   // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined

+	{

+		$selected = 0;

+		if (in_array($obj->rowid, $arrayofselected)) $selected = 1;

+		print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';

+	}

+	print '</td>';

+	if (!$i) $totalarray['nbfield']++;

+

+	print "</tr>\n";

@@ -1022,11 +752,0 @@
-// If no record found

-if ($num == 0) {

-	$colspan = 1;

-	foreach ($arrayfields as $key => $val) {

-		if (!empty($val['checked'])) {

-			$colspan++;

-		}

-	}

-	print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';

-}

-

@@ -1035,2 +755,2 @@
-$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);

-$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

+$parameters = array('sql' => $sql);

+$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook

@@ -1039,7 +759,7 @@
-print '</table>'."\n";

-print '</div>'."\n";

-

-print '</form>'."\n";

-

-

-// End of page

+print '</table>';

+print '</div>';

+

+print '</form>';

+

+

+

@@ -1046,0 +767 @@
+