Skip to content

Commit

Permalink
FIX Init of contact in combo list when thirdparty not yet known
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jul 16, 2018
1 parent c94437c commit 89cc048
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
14 changes: 8 additions & 6 deletions htdocs/core/class/html.form.class.php
Expand Up @@ -1287,7 +1287,7 @@ function select_remises($selected, $htmlname, $filter, $socid, $maxvalue=0)
* @param int $socid Id ot third party or 0 for all
* @param string $selected Id contact pre-selectionne
* @param string $htmlname Name of HTML field ('none' for a not editable field)
* @param int $showempty 0=no empty value, 1=add an empty value
* @param int $showempty 0=no empty value, 1=add an empty value, 2=add line 'Internal' (used by user edit), 3=add an empty value only if more than one record into list
* @param string $exclude List of contacts id to exclude
* @param string $limitto Disable answers that are not id in this array list
* @param integer $showfunction Add function into label
Expand All @@ -1311,10 +1311,10 @@ function select_contacts($socid,$selected='',$htmlname='contactid',$showempty=0,
* Return HTML code of the SELECT of list of all contacts (for a third party or all).
* This also set the number of contacts found into $this->num
*
* @param int $socid Id ot third party or 0 for all
* @param int $socid Id ot third party or 0 for all or -1 for empty list
* @param array|int $selected Array of ID of pre-selected contact id
* @param string $htmlname Name of HTML field ('none' for a not editable field)
* @param int $showempty 0=no empty value, 1=add an empty value, 2=add line 'Internal' (used by user edit)
* @param int $showempty 0=no empty value, 1=add an empty value, 2=add line 'Internal' (used by user edit), 3=add an empty value only if more than one record into list
* @param string $exclude List of contacts id to exclude
* @param string $limitto Disable answers that are not id in this array list
* @param integer $showfunction Add function into label
Expand Down Expand Up @@ -1342,7 +1342,7 @@ function selectcontacts($socid, $selected='', $htmlname='contactid', $showempty=
$sql.= " FROM ".MAIN_DB_PREFIX ."socpeople as sp";
if ($showsoc > 0) $sql.= " LEFT OUTER JOIN ".MAIN_DB_PREFIX ."societe as s ON s.rowid=sp.fk_soc";
$sql.= " WHERE sp.entity IN (".getEntity('socpeople').")";
if ($socid > 0) $sql.= " AND sp.fk_soc=".$socid;
if ($socid > 0 || $socid == -1) $sql.= " AND sp.fk_soc=".$socid;
if (! empty($conf->global->CONTACT_HIDE_INACTIVE_IN_COMBOBOX)) $sql.= " AND sp.statut <> 0";
$sql.= " ORDER BY sp.lastname ASC";

Expand All @@ -1359,7 +1359,7 @@ function selectcontacts($socid, $selected='', $htmlname='contactid', $showempty=
}

if ($htmlname != 'none' || $options_only) $out.= '<select class="flat'.($moreclass?' '.$moreclass:'').'" id="'.$htmlid.'" name="'.$htmlname.'" '.(!empty($moreparam) ? $moreparam : '').'>';
if ($showempty == 1) $out.= '<option value="0"'.($selected=='0'?' selected':'').'>&nbsp;</option>';
if ($showempty == 1 || ($showempty == 3 && $num > 1)) $out.= '<option value="0"'.($selected=='0'?' selected':'').'>&nbsp;</option>';
if ($showempty == 2) $out.= '<option value="0"'.($selected=='0'?' selected':'').'>'.$langs->trans("Internal").'</option>';
$num = $this->db->num_rows($resql);
$i = 0;
Expand Down Expand Up @@ -1418,7 +1418,9 @@ function selectcontacts($socid, $selected='', $htmlname='contactid', $showempty=
}
else
{
$out.= '<option value="-1"'.($showempty==2?'':' selected').' disabled>'.$langs->trans($socid?"NoContactDefinedForThirdParty":"NoContactDefined").'</option>';
$out.= '<option value="-1"'.($showempty==2?'':' selected').' disabled>';
$out.= ($socid != -1) ? ($langs->trans($socid?"NoContactDefinedForThirdParty":"NoContactDefined")) : $langs->trans('SelectAThirdPartyFirst');
$out.= '</option>';
}
if ($htmlname != 'none' || $options_only)
{
Expand Down
6 changes: 3 additions & 3 deletions htdocs/core/class/html.formticket.class.php
Expand Up @@ -239,9 +239,9 @@ function(response) {

// Contact and type
print '<tr><td>' . $langs->trans("Contact") . '</td><td>';
// If no socid, set to first one (id=1) to avoid full contacts list
$selectedCompany = $this->withfromsocid > 0 ? $this->withfromsocid : 1;
$nbofcontacts = $form->select_contacts($selectedCompany, $this->withfromcontactid, 'contactid', 0, '', '', 0, 'minwidth200');
// If no socid, set to -1 to avoid full contacts list
$selectedCompany = ($this->withfromsocid > 0) ? $this->withfromsocid : -1;
$nbofcontacts = $form->select_contacts($selectedCompany, $this->withfromcontactid, 'contactid', 3, '', '', 0, 'minwidth200');
$formcompany->selectTypeContact($ticketstatic, '', 'type', 'external', '', 0, 'maginleftonly');
print '</td></tr>';
} else {
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/tpl/contacts.tpl.php
Expand Up @@ -128,7 +128,7 @@
<?php $selectedCompany = $formcompany->selectCompaniesForNewContact($object, 'id', $selectedCompany, 'newcompany', '', 0, '', 'minwidth300imp'); ?>
</div>
<div class="tagtd maxwidthonsmartphone noborderbottom">
<?php $nbofcontacts=$form->select_contacts($selectedCompany, '', 'contactid', 0, '', '', 0, 'minwidth100imp'); ?>
<?php $nbofcontacts=$form->select_contacts(($selectedCompany > 0 ? $selectedCompany : -1), '', 'contactid', 3, '', '', 0, 'minwidth100imp'); ?>
</div>
<div class="tagtd maxwidthonsmartphone noborderbottom">
<?php
Expand Down
2 changes: 1 addition & 1 deletion htdocs/langs/en_US/main.lang
Expand Up @@ -947,4 +947,4 @@ AssignedTo=Assigned to
Deletedraft=Delete draft
ConfirmMassDraftDeletion=Draft Bulk delete confirmation
FileSharedViaALink=File shared via a link

SelectAThirdPartyFirst=Select a third party first...

0 comments on commit 89cc048

Please sign in to comment.