Uniformize code for contacts forms.

This commit is contained in:
Laurent Destailleur 2014-02-04 20:49:07 +01:00
parent 8f3e9b1832
commit d8b8f8c646
12 changed files with 178 additions and 455 deletions

View File

@ -41,13 +41,15 @@ For developers:
- New: Add new hook function addMoreActionsButtons to allow a module to add/replace - New: Add new hook function addMoreActionsButtons to allow a module to add/replace
action buttons into an element. action buttons into an element.
- New: Normalize code for barcode generation to match other modules. - New: Normalize code for barcode generation to match other modules.
- New: Uniformize code for contacts forms.
WARNING: Following change may create regression for some external modules, but was necessary to make WARNING: Following change may create regression for some external modules, but was necessary to make
Dolibarr better: Dolibarr better:
- The deprecated way (with 4 parameters) to declare a new tab into a module descriptor file has been - The deprecated way (with 4 parameters) to declare a new tab into a module descriptor file has been
removed. You must now use the 6 parameters way. See file modMyModule.class.php for example. removed. You must now use the 6 parameters way. See file modMyModule.class.php for example.
- - Remove the javascrit function ac_delay() that is not used anymore by core code.
***** ChangeLog for 3.5 compared to 3.4.* ***** ***** ChangeLog for 3.5 compared to 3.4.* *****
For users: For users:

View File

@ -135,27 +135,6 @@ else
} }
print '</td></tr>'; print '</td></tr>';
/*
// USER_USE_SEARCH_TO_SELECT
$var=!$var;
print "<tr ".$bc[$var].">";
print '<td>'.$langs->trans("HideClosedUserComboBox").'</td>';
print '<td align="center" width="20">&nbsp;</td>';
if (! empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX))
{
print '<td align="center" width="100"><a href="'.$_SERVER['PHP_SELF'].'?action=sethideinactiveuser&status=0">';
print img_picto($langs->trans("Activated"),'switch_on');
print '</a></td>';
}
else
{
print '<td align="center" width="100"><a href="'.$_SERVER['PHP_SELF'].'?action=sethideinactiveuser&status=1">';
print img_picto($langs->trans("Disabled"),'switch_off');
print '</a></td>';
}
print '</tr>';
*/
print '</table>'; print '</table>';
dol_fiche_end(); dol_fiche_end();

View File

@ -60,8 +60,8 @@ $object = new ActionComm($db);
* Actions * Actions
*/ */
// Add new nouveau contact // Add new contact
if ($action == 'addcontact') if ($action == 'addcontact' && $user->rights->action->creer)
{ {
$result = $object->fetch($id); $result = $object->fetch($id);
@ -233,189 +233,20 @@ if ($id > 0 || ! empty($ref))
// Location // Location
print '<tr><td>'.$langs->trans("Location").'</td><td colspan="2">'.$object->location.'</td></tr>'; print '<tr><td>'.$langs->trans("Location").'</td><td colspan="2">'.$object->location.'</td></tr>';
print '</table>'; print '</table>';
print '</div>'; dol_fiche_end();
/*
* Lignes de contacts
*/
print '<br><table class="noborder" width="100%">';
/* print '<br>';
* Ajouter une ligne de contact
* Non affiche en mode modification de ligne // Contacts lines (modules that overwrite templates must declare this into descriptor)
*/ $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
if ($action != 'editline') foreach($dirtpls as $reldir)
{ {
print '<tr class="liste_titre">'; $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
print '<td>'.$langs->trans("Source").'</td>'; if ($res) break;
print '<td>'.$langs->trans("Company").'</td>';
print '<td>'.$langs->trans("Contacts").'</td>';
print '<td>'.$langs->trans("ContactType").'</td>';
print '<td colspan="3">&nbsp;</td>';
print "</tr>\n";
$var = false;
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="addcontact">';
print '<input type="hidden" name="source" value="internal">';
print '<input type="hidden" name="id" value="'.$id.'">';
// Ligne ajout pour contact interne
print "<tr ".$bc[$var].">";
print '<td class="nowrap">';
print img_object('','user').' '.$langs->trans("Users");
print '</td>';
print '<td colspan="1">';
print $conf->global->MAIN_INFO_SOCIETE_NOM;
print '</td>';
print '<td colspan="1">';
// On recupere les id des users deja selectionnes
$form->select_users($user->id,'contactid',0);
print '</td>';
print '<td>';
$formcompany->selectTypeContact($object, '', 'type','internal','rowid');
print '</td>';
print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
print '</tr>';
print '</form>';
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="addcontact">';
print '<input type="hidden" name="source" value="external">';
print '<input type="hidden" name="id" value="'.$id.'">';
// Line to add external contact. Only if project is linked to a third party.
if ($object->socid)
{
$var=!$var;
print "<tr $bc[$var]>";
print '<td class="nowrap">';
print img_object('','contact').' '.$langs->trans("ThirdPartyContacts");
print '</td>';
print '<td colspan="1">';
$selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$object->socid;
$selectedCompany = $formcompany->selectCompaniesForNewContact($object, 'id', $selectedCompany, 'newcompany');
print '</td>';
print '<td colspan="1">';
$nbofcontacts=$form->select_contacts($selectedCompany,'','contactid');
if ($nbofcontacts == 0) print $langs->trans("NoContactDefinedForThirdParty");
print '</td>';
print '<td>';
$formcompany->selectTypeContact($object,'','type','external','rowid');
print '</td>';
print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"';
if (! $nbofcontacts) print ' disabled="true"';
print '></td>';
print '</tr>';
}
print "</form>";
print '<tr><td colspan="6">&nbsp;</td></tr>';
} }
// Liste des contacts lies
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Source").'</td>';
print '<td>'.$langs->trans("Company").'</td>';
print '<td>'.$langs->trans("Contacts").'</td>';
print '<td>'.$langs->trans("ContactType").'</td>';
print '<td align="center">'.$langs->trans("Status").'</td>';
print '<td colspan="2">&nbsp;</td>';
print "</tr>\n";
$companystatic = new Societe($db);
$var = true;
foreach(array('internal','external') as $source)
{
$tab = $object->liste_contact(-1,$source);
$num=count($tab);
$i = 0;
while ($i < $num)
{
$var = !$var;
print '<tr '.$bc[$var].' valign="top">';
// Source
print '<td align="left">';
if ($tab[$i]['source']=='internal') print $langs->trans("User");
if ($tab[$i]['source']=='external') print $langs->trans("ThirdPartyContact");
print '</td>';
// Societe
print '<td align="left">';
if ($tab[$i]['socid'] > 0)
{
$companystatic->fetch($tab[$i]['socid']);
print $companystatic->getNomUrl(1);
}
if ($tab[$i]['socid'] < 0)
{
print $conf->global->MAIN_INFO_SOCIETE_NOM;
}
if (! $tab[$i]['socid'])
{
print '&nbsp;';
}
print '</td>';
// Contact
print '<td>';
if ($tab[$i]['source']=='internal')
{
print '<a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$tab[$i]['id'].'">';
print img_object($langs->trans("ShowUser"),"user").' '.$tab[$i]['nom'].'</a>';
}
if ($tab[$i]['source']=='external')
{
print '<a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$tab[$i]['id'].'">';
print img_object($langs->trans("ShowContact"),"contact").' '.$tab[$i]['nom'].'</a>';
}
print '</td>';
// Type de contact
print '<td>'.$tab[$i]['libelle'].'</td>';
// Statut
print '<td align="center">';
// Activation desativation du contact
if ($object->statut >= 0 ) print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=swapstatut&amp;line='.$tab[$i]['rowid'].'">';
print $contactstatic->LibStatut($tab[$i]['status'],3);
if ($object->statut >= 0 ) print '</a>';
print '</td>';
// Icon update et delete
print '<td align="center" nowrap>';
/*if ($user->rights->business->write && $userAccess)
{*/
print '&nbsp;';
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=deleteline&amp;line='.$tab[$i]['rowid'].'">';
print img_delete();
print '</a>';
//}
print '</td>';
print "</tr>\n";
$i ++;
}
}
print "</table>";
} }
else else
{ {

View File

@ -71,16 +71,16 @@ if ($action == 'addcontact' && $user->rights->facture->creer)
if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{ {
$langs->load("errors"); $langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>'; setEventMessage($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), 'errors');
} }
else else
{ {
$mesg = '<div class="error">'.$object->error.'</div>'; setEventMessage($object->error, 'errors');
} }
} }
} }
// bascule du statut d'un contact // Bascule du statut d'un contact
else if ($action == 'swapstatut' && $user->rights->facture->creer) else if ($action == 'swapstatut' && $user->rights->facture->creer)
{ {
if ($object->fetch($id)) if ($object->fetch($id))
@ -179,7 +179,7 @@ if ($id > 0 || ! empty($ref))
print '<td colspan="3">'.$object->client->getNomUrl(1,'compta').'</td></tr>'; print '<td colspan="3">'.$object->client->getNomUrl(1,'compta').'</td></tr>';
print "</table>"; print "</table>";
print '</div>'; dol_fiche_end();
print '<br>'; print '<br>';

View File

@ -345,7 +345,12 @@ class Conf
$this->use_javascript_ajax=1; $this->use_javascript_ajax=1;
if (isset($this->global->MAIN_DISABLE_JAVASCRIPT)) $this->use_javascript_ajax=! $this->global->MAIN_DISABLE_JAVASCRIPT; if (isset($this->global->MAIN_DISABLE_JAVASCRIPT)) $this->use_javascript_ajax=! $this->global->MAIN_DISABLE_JAVASCRIPT;
// If no javascript_ajax, Ajax features are disabled. // If no javascript_ajax, Ajax features are disabled.
if (! $this->use_javascript_ajax) $this->global->PRODUIT_USE_SEARCH_TO_SELECT=0; if (empty($this->use_javascript_ajax))
{
unset($this->global->PRODUIT_USE_SEARCH_TO_SELECT);
unset($this->global->COMPANY_USE_SEARCH_TO_SELECT);
unset($this->global->CONTACT_USE_SEARCH_TO_SELECT);
}
// conf->currency // conf->currency
if (empty($this->global->MAIN_MONNAIE)) $this->global->MAIN_MONNAIE='EUR'; if (empty($this->global->MAIN_MONNAIE)) $this->global->MAIN_MONNAIE='EUR';

View File

@ -673,7 +673,6 @@ class ExtraFields
$out = ''; $out = '';
if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo) if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo)
{ {
//$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2);
$out.= ajax_combobox('options_'.$key, $event, $conf->global->COMPANY_USE_SEARCH_TO_SELECT); $out.= ajax_combobox('options_'.$key, $event, $conf->global->COMPANY_USE_SEARCH_TO_SELECT);
} }
@ -693,7 +692,6 @@ class ExtraFields
$out = ''; $out = '';
if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo) if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo)
{ {
//$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2);
$out.= ajax_combobox('options_'.$key, $event, $conf->global->COMPANY_USE_SEARCH_TO_SELECT); $out.= ajax_combobox('options_'.$key, $event, $conf->global->COMPANY_USE_SEARCH_TO_SELECT);
} }

View File

@ -683,14 +683,14 @@ class Form
$out=''; $out='';
/* TODO Use ajax autocompletion (not finished) /* TODO Use ajax_autocompleter like for products (not finished)
if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT) && ! $forcecombo) if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT) && ! $forcecombo)
{ {
$placeholder=''; $placeholder='';
if ($selected && empty($selected_input_value)) if ($selected && empty($selected_input_value))
{ {
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/ajaxcompanies.php';
$societe = new Societe($this->db); $societe = new Societe($this->db);
$societe->fetch($selected); $societe->fetch($selected);
$selected_input_value=$societe->ref; $selected_input_value=$societe->ref;
@ -728,13 +728,13 @@ class Form
* @param int $showempty Add an empty field * @param int $showempty Add an empty field
* @param int $showtype Show third party type in combolist (customer, prospect or supplier) * @param int $showtype Show third party type in combolist (customer, prospect or supplier)
* @param int $forcecombo Force to use combo box * @param int $forcecombo Force to use combo box
* @param array $event Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
* @return string HTML string with * @return string HTML string with
* @deprecated Use select_thirdparty instead * @deprecated Use select_thirdparty instead
*/ */
function select_company($selected='', $htmlname='socid', $filter='', $showempty=0, $showtype=0, $forcecombo=0, $event=array()) function select_company($selected='', $htmlname='socid', $filter='', $showempty=0, $showtype=0, $forcecombo=0, $events=array())
{ {
return $this->select_thirdparty_list($selected,$htmlname, $filter, $showempty, $showtype, $forcecombo, $event); return $this->select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events);
} }
/** /**
@ -746,13 +746,13 @@ class Form
* @param int $showempty Add an empty field * @param int $showempty Add an empty field
* @param int $showtype Show third party type in combolist (customer, prospect or supplier) * @param int $showtype Show third party type in combolist (customer, prospect or supplier)
* @param int $forcecombo Force to use combo box * @param int $forcecombo Force to use combo box
* @param array $event Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
* @param string $filterkey Filter on key value * @param string $filterkey Filter on key value
* @param int $outputmode 0=HTML select string, 1=Array * @param int $outputmode 0=HTML select string, 1=Array
* @param int $limit Limit number of answers * @param int $limit Limit number of answers
* @return string HTML string with * @return string HTML string with
*/ */
function select_thirdparty_list($selected='',$htmlname='socid',$filter='',$showempty=0, $showtype=0, $forcecombo=0, $event=array(), $filterkey='', $outputmode=0, $limit=20) function select_thirdparty_list($selected='',$htmlname='socid',$filter='',$showempty=0, $showtype=0, $forcecombo=0, $events=array(), $filterkey='', $outputmode=0, $limit=20)
{ {
global $conf,$user,$langs; global $conf,$user,$langs;
@ -800,8 +800,7 @@ class Form
{ {
if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo) if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo)
{ {
//$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2); $out.= ajax_combobox($htmlname, $events, $conf->global->COMPANY_USE_SEARCH_TO_SELECT);
$out.= ajax_combobox($htmlname, $event, $conf->global->COMPANY_USE_SEARCH_TO_SELECT);
} }
// Construct $out and $outarray // Construct $out and $outarray
@ -943,13 +942,13 @@ class Form
* @param string $moreclass Add more class to class style * @param string $moreclass Add more class to class style
* @param string $showsoc Add company into label * @param string $showsoc Add company into label
* @param int $forcecombo Force to use combo box * @param int $forcecombo Force to use combo box
* @param array $event Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
* @param bool $options_only Return options only (for ajax treatment) * @param bool $options_only Return options only (for ajax treatment)
* @return int <0 if KO, Nb of contact in list if OK * @return int <0 if KO, Nb of contact in list if OK
*/ */
function select_contacts($socid,$selected='',$htmlname='contactid',$showempty=0,$exclude='',$limitto='',$showfunction=0, $moreclass='', $showsoc=0, $forcecombo=0, $event=array(), $options_only=false) function select_contacts($socid,$selected='',$htmlname='contactid',$showempty=0,$exclude='',$limitto='',$showfunction=0, $moreclass='', $showsoc=0, $forcecombo=0, $events=array(), $options_only=false)
{ {
print $this->selectcontacts($socid,$selected,$htmlname,$showempty,$exclude,$limitto,$showfunction, $moreclass, $options_only, $showsoc, $forcecombo, $event); print $this->selectcontacts($socid,$selected,$htmlname,$showempty,$exclude,$limitto,$showfunction, $moreclass, $options_only, $showsoc, $forcecombo, $events);
return $this->num; return $this->num;
} }
@ -967,10 +966,10 @@ class Form
* @param bool $options_only Return options only (for ajax treatment) * @param bool $options_only Return options only (for ajax treatment)
* @param string $showsoc Add company into label * @param string $showsoc Add company into label
* @param int $forcecombo Force to use combo box * @param int $forcecombo Force to use combo box
* @param array $event Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
* @return int <0 if KO, Nb of contact in list if OK * @return int <0 if KO, Nb of contact in list if OK
*/ */
function selectcontacts($socid,$selected='',$htmlname='contactid',$showempty=0,$exclude='',$limitto='',$showfunction=0, $moreclass='', $options_only=false, $showsoc=0, $forcecombo=0, $event=array()) function selectcontacts($socid,$selected='',$htmlname='contactid',$showempty=0,$exclude='',$limitto='',$showfunction=0, $moreclass='', $options_only=false, $showsoc=0, $forcecombo=0, $events=array())
{ {
global $conf,$langs; global $conf,$langs;
@ -1000,7 +999,7 @@ class Form
if ($conf->use_javascript_ajax && $conf->global->CONTACT_USE_SEARCH_TO_SELECT && ! $forcecombo && ! $options_only) if ($conf->use_javascript_ajax && $conf->global->CONTACT_USE_SEARCH_TO_SELECT && ! $forcecombo && ! $options_only)
{ {
$out.= ajax_combobox($htmlname, $event, $conf->global->CONTACT_USE_SEARCH_TO_SELECT); $out.= ajax_combobox($htmlname, $events, $conf->global->CONTACT_USE_SEARCH_TO_SELECT);
} }
if ($htmlname != 'none' || $options_only) $out.= '<select class="flat'.($moreclass?' '.$moreclass:'').'" id="'.$htmlname.'" name="'.$htmlname.'">'; if ($htmlname != 'none' || $options_only) $out.= '<select class="flat'.($moreclass?' '.$moreclass:'').'" id="'.$htmlname.'" name="'.$htmlname.'">';
@ -3160,10 +3159,10 @@ class Form
* @param int $showempty Add an empty field * @param int $showempty Add an empty field
* @param int $showtype Show third party type in combolist (customer, prospect or supplier) * @param int $showtype Show third party type in combolist (customer, prospect or supplier)
* @param int $forcecombo Force to use combo box * @param int $forcecombo Force to use combo box
* @param array $event Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
* @return void * @return void
*/ */
function form_thirdparty($page, $selected='', $htmlname='socid', $filter='',$showempty=0, $showtype=0, $forcecombo=0, $event=array()) function form_thirdparty($page, $selected='', $htmlname='socid', $filter='',$showempty=0, $showtype=0, $forcecombo=0, $events=array())
{ {
global $langs; global $langs;
@ -3174,7 +3173,7 @@ class Form
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">'; print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
print '<tr><td>'; print '<tr><td>';
print $this->select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $event); print $this->select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events);
print '</td>'; print '</td>';
print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>'; print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
print '</tr></table></form>'; print '</tr></table></form>';

View File

@ -501,7 +501,7 @@ class FormCompany
/** /**
* Return list of third parties * Output list of third parties.
* *
* @param object $object Object we try to find contacts * @param object $object Object we try to find contacts
* @param string $var_id Name of id field * @param string $var_id Name of id field
@ -509,12 +509,11 @@ class FormCompany
* @param string $htmlname Name of HTML form * @param string $htmlname Name of HTML form
* @param array $limitto Disable answers that are not id in this array list * @param array $limitto Disable answers that are not id in this array list
* @param int $forceid This is to force another object id than object->id * @param int $forceid This is to force another object id than object->id
* @return int The selected third party ID * @param array $event Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
* TODO obsolete ? * @param string $moreparam String with more param to add into url when noajax search is used.
* cette fonction doit utiliser du javascript quoi qu'il en soit ! * @return int The selected third party ID
* autant utiliser le système combobox sans rechargement de page non ?
*/ */
function selectCompaniesForNewContact($object, $var_id, $selected='', $htmlname='newcompany', $limitto='', $forceid=0) function selectCompaniesForNewContact($object, $var_id, $selected='', $htmlname='newcompany', $limitto='', $forceid=0, $events=array(), $moreparam='')
{ {
global $conf, $langs; global $conf, $langs;
@ -539,6 +538,7 @@ class FormCompany
{ {
if ($conf->use_javascript_ajax && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT)) if ($conf->use_javascript_ajax && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT))
{ {
// Use Ajax search
$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2); $minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2);
$socid=0; $socid=0;
@ -548,18 +548,63 @@ class FormCompany
$socid = $obj->rowid?$obj->rowid:''; $socid = $obj->rowid?$obj->rowid:'';
} }
// We call a page after a small delay when a new input has been selected // We recall a page after a small delay when a new input has been selected
$javaScript = "window.location=\'".$_SERVER['PHP_SELF']."?".$var_id."=".($forceid>0?$forceid:$object->id)."&amp;".$htmlname."=\' + document.getElementById(\'".$htmlname."\').value;"; $htmloption='';
$htmloption = 'onChange="ac_delay(\''.$javaScript.'\',\'500\');"'; // When we select with mouse //$javaScript = "window.location=\'".$_SERVER['PHP_SELF']."?".$var_id."=".($forceid>0?$forceid:$object->id)."&amp;".$htmlname."=\' + document.getElementById(\'".$htmlname."\').value;";
$htmloption.= 'onKeyUp="if (event.keyCode== 13) { ac_delay(\''.$javaScript.'\',\'500\'); }"'; // When we select with keyboard //$htmloption.= 'onChange="ac_delay(\''.$javaScript.'\',\'500\');"'; // When we select with mouse
//$htmloption.= 'onKeyUp="if (event.keyCode== 13) { ac_delay(\''.$javaScript.'\',\'500\'); }"'; // When we select with keyboard
if (count($events)) // If there is some ajax events to run once selection is done, we add code here to run events
{
print '<script type="text/javascript">
jQuery(document).ready(function() {
$("#search_'.$htmlname.'").change(function() {
var obj = '.json_encode($events).';
$.each(obj, function(key,values) {
if (values.method.length) {
getMethod'.$htmlname.'(values);
}
});
});
// Function used to execute events when search_htmlname change
function getMethod'.$htmlname.'(obj) {
var id = $("#'.$htmlname.'").val();
var method = obj.method;
var url = obj.url;
var htmlname = obj.htmlname;
$.getJSON(url,
{
action: method,
id: id,
htmlname: htmlname
},
function(response) {
if (response != null)
{
$.each(obj.params, function(key,action) {
if (key.length) {
var num = response.num;
if (num > 0) {
$("#" + key).removeAttr(action);
} else {
$("#" + key).attr(action, action);
}
}
});
$("select#" + htmlname).html(response.value);
}
});
};
});
</script>';
}
print "\n".'<!-- Input text for third party with Ajax.Autocompleter (selectCompaniesForNewContact) -->'."\n"; print "\n".'<!-- Input text for third party with Ajax.Autocompleter (selectCompaniesForNewContact) -->'."\n";
print '<table class="nobordernopadding"><tr class="nobordernopadding">'; print '<table class="nobordernopadding"><tr class="nobordernopadding">';
print '<td class="nobordernopadding">'; print '<td class="nobordernopadding">';
if ($obj->rowid == 0) if ($obj->rowid == 0)
{ {
//$langs->load("companies");
//print '<input type="text" size="30" id="'.$htmlname.'_label" name="'.$htmlname.'" value="'.$langs->trans("SelectCompany").'" '.$htmloption.' />';
print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="" '.$htmloption.' />'; print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="" '.$htmloption.' />';
} }
else else
@ -575,8 +620,14 @@ class FormCompany
} }
else else
{ {
$javaScript = "window.location='".$_SERVER['PHP_SELF']."?".$var_id."=".($forceid>0?$forceid:$object->id)."&amp;".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;"; // No Ajax search
print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'" onChange="'.$javaScript.'">'; print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"';
if ($conf->use_javascript_ajax)
{
$javaScript = "window.location='".$_SERVER['PHP_SELF']."?".$var_id."=".($forceid>0?$forceid:$object->id).$moreparam."&".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;";
print ' onChange="'.$javaScript.'"';
}
print '>';
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
$i = 0; $i = 0;
if ($num) if ($num)

View File

@ -25,7 +25,8 @@
/** /**
* Get value of an HTML field, do Ajax process and show result * Get value of an HTML field, do Ajax process and show result.
* The HTML field must be an input text with id=search_$htmlname.
* *
* @param string $selected Preselecte value * @param string $selected Preselecte value
* @param string $htmlname HTML name of input field * @param string $htmlname HTML name of input field
@ -54,11 +55,12 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt
$("#'.$htmlname.'").val(""); $("#'.$htmlname.'").val("");
}); });
$("input#search_'.$htmlname.'").change(function() { $("input#search_'.$htmlname.'").change(function() {
//console.log(\'keyup\'); //console.log(\'change\');
$("#'.$htmlname.'").trigger("change"); $("#'.$htmlname.'").trigger("change");
}); });
// Check when keyup // Check when keyup
$("input#search_'.$htmlname.'").onDelayedKeyup({ handler: function() { $("input#search_'.$htmlname.'").onDelayedKeyup({ handler: function() {
//console.log(\'keyup\');
if ($(this).val().length == 0) if ($(this).val().length == 0)
{ {
$("#search_'.$htmlname.'").val(""); $("#search_'.$htmlname.'").val("");
@ -120,9 +122,9 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt
}, },
dataType: "json", dataType: "json",
minLength: '.$minLength.', minLength: '.$minLength.',
select: function( event, ui ) { select: function( event, ui ) { // Function ran when new value is selected into javascript combo
//console.log(\'set value of id with \'+ui.item.id); //console.log(\'set value of id with \'+ui.item.id);
$("#'.$htmlname.'").val(ui.item.id).trigger("change"); $("#'.$htmlname.'").val(ui.item.id).trigger("change"); // Select new value
// Disable an element // Disable an element
if (options.option_disabled) { if (options.option_disabled) {
if (ui.item.disabled) { if (ui.item.disabled) {
@ -162,6 +164,7 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt
} }
}); });
} }
$("#search_'.$htmlname.'").trigger("change"); // To tell that input text field was modified
} }
}).data( "autocomplete" )._renderItem = function( ul, item ) { }).data( "autocomplete" )._renderItem = function( ul, item ) {
return $( "<li></li>" ) return $( "<li></li>" )
@ -169,6 +172,7 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt
.append( \'<a><span class="tag">\' + item.label + "</span></a>" ) .append( \'<a><span class="tag">\' + item.label + "</span></a>" )
.appendTo(ul); .appendTo(ul);
}; };
});'; });';
$script.= '</script>'; $script.= '</script>';
@ -293,14 +297,16 @@ function ajax_dialog($title,$message,$w=350,$h=150)
} }
/** /**
* Convert a html select field into an ajax combobox * Convert a html select field into an ajax combobox.
* Use ajax_combobox() only for small combo list! If not, use instead ajax_autocompleter().
* TODO: It is used when COMPANY_USE_SEARCH_TO_SELECT and CONTACT_USE_SEARCH_TO_SELECT are set by html.formcompany.class.php. Should use ajax_autocompleter instead like done by html.form.class.php for select_produits.
* *
* @param string $htmlname Name of html select field * @param string $htmlname Name of html select field
* @param array $event Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
* @param int $minLengthToAutocomplete Minimum length of input string to start autocomplete * @param int $minLengthToAutocomplete Minimum length of input string to start autocomplete
* @return string Return html string to convert a select field into a combo * @return string Return html string to convert a select field into a combo
*/ */
function ajax_combobox($htmlname, $event=array(), $minLengthToAutocomplete=0) function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0)
{ {
global $conf; global $conf;
@ -326,7 +332,7 @@ function ajax_combobox($htmlname, $event=array(), $minLengthToAutocomplete=0)
$("#'.$htmlname.'").combobox({ $("#'.$htmlname.'").combobox({
minLengthToAutocomplete : '.$minLengthToAutocomplete.', minLengthToAutocomplete : '.$minLengthToAutocomplete.',
selected : function(event,ui) { selected : function(event,ui) {
var obj = '.json_encode($event).'; var obj = '.json_encode($events).';
$.each(obj, function(key,values) { $.each(obj, function(key,values) {
if (values.method.length) { if (values.method.length) {
getMethod(values); getMethod(values);

View File

@ -17,6 +17,7 @@
* *
* This template needs: * This template needs:
* $object * $object
* $withproject (if we are on task contact)
*/ */
if (! class_exists('Contact')) { if (! class_exists('Contact')) {
@ -34,6 +35,9 @@ elseif ($module == 'fichinter') { $permission=$user->rights->ficheinter->creer
elseif ($module == 'invoice_supplier') { $permission=$user->rights->fournisseur->facture->creer; } elseif ($module == 'invoice_supplier') { $permission=$user->rights->fournisseur->facture->creer; }
elseif ($module == 'order_supplier') { $permission=$user->rights->fournisseur->commande->creer; } elseif ($module == 'order_supplier') { $permission=$user->rights->fournisseur->commande->creer; }
elseif ($module == 'project') { $permission=$user->rights->projet->creer; } elseif ($module == 'project') { $permission=$user->rights->projet->creer; }
elseif ($module == 'action') { $permission=$user->rights->agenda->myactions->create; }
elseif ($module == 'shipping') { $permission=$user->rights->expedition->creer; }
elseif ($module == 'project_task') { $permission=$user->rights->projet->creer; }
elseif (! isset($permission)) { $permission=$user->rights->$module->creer; } // If already defined by caller page elseif (! isset($permission)) { $permission=$user->rights->$module->creer; } // If already defined by caller page
$formcompany= new FormCompany($db); $formcompany= new FormCompany($db);
@ -64,6 +68,7 @@ $userstatic=new User($db);
<input type="hidden" name="id" value="<?php echo $object->id; ?>" /> <input type="hidden" name="id" value="<?php echo $object->id; ?>" />
<input type="hidden" name="action" value="addcontact" /> <input type="hidden" name="action" value="addcontact" />
<input type="hidden" name="source" value="internal" /> <input type="hidden" name="source" value="internal" />
<?php if ($withproject) print '<input type="hidden" name="withproject" value="'.$withproject.'">'; ?>
<div class="nowrap tagtd"><?php echo img_object('','user').' '.$langs->trans("Users"); ?></div> <div class="nowrap tagtd"><?php echo img_object('','user').' '.$langs->trans("Users"); ?></div>
<div class="tagtd"><?php echo $conf->global->MAIN_INFO_SOCIETE_NOM; ?></div> <div class="tagtd"><?php echo $conf->global->MAIN_INFO_SOCIETE_NOM; ?></div>
<div class="tagtd maxwidthonsmartphone"><?php echo $form->select_dolusers($user->id, 'userid', 0, (! empty($userAlreadySelected)?$userAlreadySelected:null), 0, null, null, 0, 56); ?></div> <div class="tagtd maxwidthonsmartphone"><?php echo $form->select_dolusers($user->id, 'userid', 0, (! empty($userAlreadySelected)?$userAlreadySelected:null), 0, null, null, 0, 56); ?></div>
@ -79,29 +84,24 @@ $userstatic=new User($db);
<input type="hidden" name="id" value="<?php echo $object->id; ?>" /> <input type="hidden" name="id" value="<?php echo $object->id; ?>" />
<input type="hidden" name="action" value="addcontact" /> <input type="hidden" name="action" value="addcontact" />
<input type="hidden" name="source" value="external" /> <input type="hidden" name="source" value="external" />
<?php if ($withproject) print '<input type="hidden" name="withproject" value="'.$withproject.'">'; ?>
<div class="tagtd nowrap"><?php echo img_object('','contact').' '.$langs->trans("ThirdPartyContacts"); ?></div> <div class="tagtd nowrap"><?php echo img_object('','contact').' '.$langs->trans("ThirdPartyContacts"); ?></div>
<?php if ($conf->use_javascript_ajax && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT)) { ?> <?php
$events=array();
$events[]=array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php',1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled'));
?>
<div class="tagtd nowrap maxwidthonsmartphone"> <div class="tagtd nowrap maxwidthonsmartphone">
<?php
$events=array();
$events[]=array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php',1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled'));
print $form->select_company($object->socid,'socid','',1,0,0,$events);
?>
</div>
<div class="tagtd maxwidthonsmartphone">
<?php $nbofcontacts=$form->select_contacts($object->socid, '', 'contactid'); ?>
</div>
<?php } else { ?>
<div class="tagtd maxwidthonsmartphone">
<?php $selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$object->socid; ?> <?php $selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$object->socid; ?>
<?php $selectedCompany = $formcompany->selectCompaniesForNewContact($object, 'id', $selectedCompany, 'newcompany'); ?> <?php $selectedCompany = $formcompany->selectCompaniesForNewContact($object, 'id', $selectedCompany, 'newcompany', '', 0, $events); ?>
</div> </div>
<div class="tagtd maxwidthonsmartphone"> <div class="tagtd maxwidthonsmartphone">
<?php $nbofcontacts=$form->select_contacts($selectedCompany, '', 'contactid'); ?> <?php $nbofcontacts=$form->select_contacts($selectedCompany, '', 'contactid'); ?>
</div> </div>
<?php } ?>
<div class="tagtd maxwidthonsmartphone"> <div class="tagtd maxwidthonsmartphone">
<?php $formcompany->selectTypeContact($object, '', 'type','external'); ?> <?php
$tmpobject=$object;
if ($object->element == 'shipping' && is_object($objectsrc)) $tmpobject=$objectsrc;
$formcompany->selectTypeContact($tmpobject, '', 'type','external'); ?>
</div> </div>
<div class="tagtd">&nbsp;</div> <div class="tagtd">&nbsp;</div>
<div class="tagtd" align="right"> <div class="tagtd" align="right">
@ -124,7 +124,11 @@ $userstatic=new User($db);
<?php <?php
foreach(array('internal','external') as $source) { foreach(array('internal','external') as $source) {
$tab = $object->liste_contact(-1,$source);
$tmpobject=$object;
if ($object->element == 'shipping' && is_object($objectsrc)) $tmpobject=$objectsrc;
$tab = $tmpobject->liste_contact(-1,$source);
$num=count($tab); $num=count($tab);
$i = 0; $i = 0;

View File

@ -106,9 +106,9 @@ else if ($action == 'swapstatut' && $user->rights->expedition->creer)
} }
// Efface un contact // Efface un contact
else if ($action == 'deleteline' && $user->rights->expedition->creer) else if ($action == 'deletecontact' && $user->rights->expedition->creer)
{ {
$result = $objectsrc->delete_contact($_GET["lineid"]); $result = $objectsrc->delete_contact(GETPOST("lineid"));
if ($result >= 0) if ($result >= 0)
{ {
@ -233,186 +233,20 @@ if ($id > 0 || ! empty($ref))
print "</table>"; print "</table>";
print '</div>'; dol_fiche_end();
// Lignes de contacts // Lignes de contacts
echo '<br><table class="noborder" width="100%">'; echo '<br>';
/*
* Ajouter une ligne de contact. Non affiche en mode modification de ligne // Contacts lines (modules that overwrite templates must declare this into descriptor)
*/ $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
if ($action != 'editline' && $user->rights->expedition->creer) foreach($dirtpls as $reldir)
{ {
print '<tr class="liste_titre">'; $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
print '<td>'.$langs->trans("Source").'</td>'; if ($res) break;
print '<td>'.$langs->trans("Company").'</td>';
print '<td>'.$langs->trans("Contacts").'</td>';
print '<td>'.$langs->trans("ContactType").'</td>';
print '<td>&nbsp;</td>';
print '<td colspan="2">&nbsp;</td>';
print "</tr>\n";
$var = false;
print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="addcontact">';
print '<input type="hidden" name="source" value="internal">';
print '<input type="hidden" name="id" value="'.$id.'">';
// Ligne ajout pour contact interne
print '<tr '.$bc[$var].'>';
print '<td class="nowrap">';
print img_object('','user').' '.$langs->trans("Users");
print '</td>';
print '<td colspan="1">';
print $conf->global->MAIN_INFO_SOCIETE_NOM;
print '</td>';
print '<td colspan="1">';
$form->select_users($user->id,'contactid');
print '</td>';
print '<td>';
$formcompany->selectTypeContact($objectsrc, '', 'type','internal');
print '</td>';
print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
print '</tr>';
print '</form>';
print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="addcontact">';
print '<input type="hidden" name="source" value="external">';
print '<input type="hidden" name="id" value="'.$id.'">';
// Ligne ajout pour contact externe
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td class="nowrap">';
print img_object('','contact').' '.$langs->trans("ThirdPartyContacts");
print '</td>';
print '<td colspan="1">';
$selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$object->client->id;
$selectedCompany = $formcompany->selectCompaniesForNewContact($objectsrc, 'id', $selectedCompany, 'newcompany', '', $object->id);
print '</td>';
print '<td colspan="1">';
$nbofcontacts=$form->select_contacts($selectedCompany, '', 'contactid');
if ($nbofcontacts == 0) print $langs->trans("NoContactDefined");
print '</td>';
print '<td>';
$formcompany->selectTypeContact($objectsrc, '', 'type','external');
print '</td>';
print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"';
if (! $nbofcontacts) print ' disabled="disabled"';
print '></td>';
print '</tr>';
print "</form>";
print '<tr><td colspan="7">&nbsp;</td></tr>';
} }
// List of linked contacts
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Source").'</td>';
print '<td>'.$langs->trans("Company").'</td>';
print '<td>'.$langs->trans("Contacts").'</td>';
print '<td>'.$langs->trans("ContactType").'</td>';
print '<td align="center">'.$langs->trans("Status").'</td>';
print '<td colspan="2">&nbsp;</td>';
print "</tr>\n";
$companystatic=new Societe($db);
$var = true;
foreach(array('internal','external') as $source)
{
$tab = $objectsrc->liste_contact(-1,$source);
$num=count($tab);
$i = 0;
while ($i < $num)
{
$var = !$var;
print '<tr '.$bc[$var].' valign="top">';
// Source
print '<td align="left">';
if ($tab[$i]['source']=='internal') print $langs->trans("User");
if ($tab[$i]['source']=='external') print $langs->trans("ThirdPartyContact");
print '</td>';
// Societe
print '<td align="left">';
if ($tab[$i]['socid'] > 0)
{
$companystatic->fetch($tab[$i]['socid']);
print $companystatic->getNomUrl(1);
}
if ($tab[$i]['socid'] < 0)
{
print $conf->global->MAIN_INFO_SOCIETE_NOM;
}
if (! $tab[$i]['socid'])
{
print '&nbsp;';
}
print '</td>';
// Contact
print '<td>';
if ($tab[$i]['source']=='internal')
{
$userstatic->id=$tab[$i]['id'];
$userstatic->lastname=$tab[$i]['lastname'];
$userstatic->firstname=$tab[$i]['firstname'];
print $userstatic->getNomUrl(1);
}
if ($tab[$i]['source']=='external')
{
$contactstatic->id=$tab[$i]['id'];
$contactstatic->lastname=$tab[$i]['lastname'];
$contactstatic->firstname=$tab[$i]['firstname'];
print $contactstatic->getNomUrl(1);
}
print '</td>';
// Type de contact
print '<td>'.$tab[$i]['libelle'].'</td>';
// Statut
print '<td align="center">';
// Activation desativation du contact
if ($object->statut >= 0) print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=swapstatut&amp;ligne='.$tab[$i]['rowid'].'">';
print $contactstatic->LibStatut($tab[$i]['status'],3);
if ($object->statut >= 0) print '</a>';
print '</td>';
// Icon update et delete
print '<td align="center" class="nowrap" colspan="2">';
if ($object->statut < 5 && $user->rights->expedition->creer)
{
print '&nbsp;';
print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=deleteline&amp;lineid='.$tab[$i]['rowid'].'">';
print img_delete();
print '</a>';
}
print '</td>';
print "</tr>\n";
$i ++;
}
}
print "</table>";
} }
llxFooter(); llxFooter();

View File

@ -260,7 +260,17 @@ if ($id > 0 || ! empty($ref))
/* /*
* Lignes de contacts * Lignes de contacts
*/ */
print '<br><table class="noborder" width="100%">'; print '<br>';
/*
// Contacts lines (modules that overwrite templates must declare this into descriptor)
$dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
foreach($dirtpls as $reldir)
{
$res=@include dol_buildpath($reldir.'/contacts.tpl.php');
if ($res) break;
}
*/
print '<table class="noborder" width="100%">';
/* /*
* Ajouter une ligne de contact * Ajouter une ligne de contact
@ -283,7 +293,7 @@ if ($id > 0 || ! empty($ref))
print '<input type="hidden" name="action" value="addcontact">'; print '<input type="hidden" name="action" value="addcontact">';
print '<input type="hidden" name="source" value="internal">'; print '<input type="hidden" name="source" value="internal">';
print '<input type="hidden" name="id" value="'.$id.'">'; print '<input type="hidden" name="id" value="'.$id.'">';
print '<input type="hidden" name="withproject" value="'.$withproject.'">'; if ($withproject) print '<input type="hidden" name="withproject" value="'.$withproject.'">';
// Ligne ajout pour contact interne // Ligne ajout pour contact interne
print "<tr ".$bc[$var].">"; print "<tr ".$bc[$var].">";
@ -299,7 +309,7 @@ if ($id > 0 || ! empty($ref))
print '<td colspan="1">'; print '<td colspan="1">';
// On recupere les id des users deja selectionnes // On recupere les id des users deja selectionnes
$contactsofproject=$projectstatic->getListContactId('internal'); $contactsofproject=$projectstatic->getListContactId('internal');
$form->select_users($user->id,'contactid',0,'',0,'',$contactsofproject); $form->select_users($user->id,'userid',0,'',0,'',$contactsofproject);
print '</td>'; print '</td>';
print '<td>'; print '<td>';
$formcompany->selectTypeContact($object, '', 'type','internal','rowid'); $formcompany->selectTypeContact($object, '', 'type','internal','rowid');
@ -317,6 +327,7 @@ if ($id > 0 || ! empty($ref))
print '<input type="hidden" name="action" value="addcontact">'; print '<input type="hidden" name="action" value="addcontact">';
print '<input type="hidden" name="source" value="external">'; print '<input type="hidden" name="source" value="external">';
print '<input type="hidden" name="id" value="'.$object->id.'">'; print '<input type="hidden" name="id" value="'.$object->id.'">';
if ($withproject) print '<input type="hidden" name="withproject" value="'.$withproject.'">';
$var=!$var; $var=!$var;
print "<tr ".$bc[$var].">"; print "<tr ".$bc[$var].">";
@ -326,20 +337,22 @@ if ($id > 0 || ! empty($ref))
print '</td>'; print '</td>';
print '<td colspan="1">'; print '<td colspan="1">';
$events=array();
$events[]=array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php',1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled'));
$thirdpartyofproject=$projectstatic->getListContactId('thirdparty'); $thirdpartyofproject=$projectstatic->getListContactId('thirdparty');
$selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$projectstatic->societe->id; $selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$projectstatic->societe->id;
$selectedCompany = $formcompany->selectCompaniesForNewContact($object, 'id', $selectedCompany, 'newcompany',$thirdpartyofproject); $selectedCompany = $formcompany->selectCompaniesForNewContact($object, 'id', $selectedCompany, 'newcompany', $thirdpartyofproject, 0, $events, '&withproject='.$withproject);
print '</td>'; print '</td>';
print '<td colspan="1">'; print '<td colspan="1">';
$contactofproject=$projectstatic->getListContactId('external'); $contactofproject=$projectstatic->getListContactId('external');
$nbofcontacts=$form->select_contacts($selectedCompany,'','contactid',0,'',$contactofproject); $nbofcontacts=$form->select_contacts($selectedCompany,'','contactid',0,'',$contactofproject);
if ($nbofcontacts == 0) print $langs->trans("NoContactDefined");
print '</td>'; print '</td>';
print '<td>'; print '<td>';
$formcompany->selectTypeContact($object, '', 'type','external','rowid'); $formcompany->selectTypeContact($object, '', 'type','external','rowid');
print '</td>'; print '</td>';
print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"'; print '<td align="right" colspan="3" ><input type="submit" class="button" id="add-customer-contact" value="'.$langs->trans("Add").'"';
if (! $nbofcontacts) print ' disabled="disabled"'; if (! $nbofcontacts) print ' disabled="disabled"';
print '></td>'; print '></td>';
print '</tr>'; print '</tr>';
@ -442,6 +455,7 @@ if ($id > 0 || ! empty($ref))
} }
} }
print "</table>"; print "</table>";
} }
else else
{ {