2010-05-03 10:22:35 +02:00
< ? php
2012-07-28 12:35:11 +02:00
/* Copyright ( C ) 2008 - 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-12-30 15:13:49 +01:00
* Copyright ( C ) 2008 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2010-05-03 10:22:35 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2010-05-03 10:22:35 +02:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2011-08-01 01:45:11 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2010-05-03 10:22:35 +02:00
*/
/**
2010-06-08 01:52:43 +02:00
* \file htdocs / core / class / html . formcompany . class . php
2010-11-22 10:18:53 +01:00
* \ingroup core
2010-05-03 10:22:35 +02:00
* \brief File of class to build HTML component for third parties management
*/
/**
2012-01-27 15:17:36 +01:00
* Class to build HTML component for third parties management
* Only common components are here .
2010-05-03 10:22:35 +02:00
*/
class FormCompany
{
var $db ;
var $error ;
/**
2011-12-29 23:23:31 +01:00
* Constructor
*
* @ param DoliDB $db Database handler
2010-05-03 10:22:35 +02:00
*/
2012-07-30 17:17:33 +02:00
function __construct ( $db )
2010-05-03 10:22:35 +02:00
{
2011-12-29 23:23:31 +01:00
$this -> db = $db ;
2010-05-03 10:22:35 +02:00
return 1 ;
}
/**
2011-06-08 00:05:07 +02:00
* Return list of labels ( translated ) of third parties type
2011-12-29 23:23:31 +01:00
*
* @ param int $mode 0 = Return id + label , 1 = Return code + label
* @ param string $filter Add a SQL filter to select
* @ return array Array of types
2010-05-03 10:22:35 +02:00
*/
2011-06-08 00:05:07 +02:00
function typent_array ( $mode = 0 , $filter = '' )
2010-05-03 10:22:35 +02:00
{
global $langs ;
$effs = array ();
$sql = " SELECT id, code, libelle " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_typent " ;
$sql .= " WHERE active = 1 " ;
2011-06-08 00:05:07 +02:00
if ( $filter ) $sql .= " " . $filter ;
2010-05-03 10:22:35 +02:00
$sql .= " ORDER by id " ;
2011-12-29 23:23:31 +01:00
dol_syslog ( get_class ( $this ) . '::typent_array sql=' . $sql , LOG_DEBUG );
2010-05-03 10:22:35 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num )
{
$objp = $this -> db -> fetch_object ( $resql );
if ( ! $mode ) $key = $objp -> id ;
else $key = $objp -> code ;
2011-06-11 16:14:27 +02:00
if ( $langs -> trans ( $objp -> code ) != $objp -> code ) $effs [ $key ] = $langs -> trans ( $objp -> code );
else $effs [ $key ] = $objp -> libelle ;
if ( $effs [ $key ] == '-' ) $effs [ $key ] = '' ;
2010-05-03 10:22:35 +02:00
$i ++ ;
}
$this -> db -> free ( $resql );
}
return $effs ;
}
/**
2011-12-29 23:23:31 +01:00
* Renvoie la liste des types d ' effectifs possibles ( pas de traduction car nombre )
*
* @ param int $mode 0 = renvoi id + libelle , 1 = renvoi code + libelle
* @ return array Array of types d ' effectifs
2010-05-03 10:22:35 +02:00
*/
function effectif_array ( $mode = 0 )
{
$effs = array ();
$sql = " SELECT id, code, libelle " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_effectif " ;
$sql .= " WHERE active = 1 " ;
$sql .= " ORDER BY id ASC " ;
2011-12-29 23:23:31 +01:00
dol_syslog ( get_class ( $this ) . '::effectif_array sql=' . $sql , LOG_DEBUG );
2010-05-03 10:22:35 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num )
{
$objp = $this -> db -> fetch_object ( $resql );
if ( ! $mode ) $key = $objp -> id ;
else $key = $objp -> code ;
$effs [ $key ] = $objp -> libelle != '-' ? $objp -> libelle : '' ;
$i ++ ;
}
$this -> db -> free ( $resql );
}
return $effs ;
}
/**
2011-12-29 23:23:31 +01:00
* Affiche formulaire de selection des modes de reglement
*
* @ param int $page Page
* @ param int $selected Id or code preselected
* @ param string $htmlname Nom du formulaire select
* @ param int $empty Add empty value in list
* @ return void
2010-05-03 10:22:35 +02:00
*/
function form_prospect_level ( $page , $selected = '' , $htmlname = 'prospect_level_id' , $empty = 0 )
{
global $langs ;
print '<form method="post" action="' . $page . '">' ;
print '<input type="hidden" name="action" value="setprospectlevel">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2010-07-11 14:44:49 +02:00
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
2010-05-03 10:22:35 +02:00
print '<tr><td>' ;
print '<select class="flat" name="' . $htmlname . '">' ;
if ( $empty ) print '<option value=""> </option>' ;
2011-12-29 23:23:31 +01:00
dol_syslog ( get_class ( $this ) . '::form_prospect_level' , LOG_DEBUG );
2010-05-03 10:22:35 +02:00
$sql = " SELECT code, label " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_prospectlevel " ;
$sql .= " WHERE active > 0 " ;
$sql .= " ORDER BY sortorder " ;
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
print '<option value="' . $obj -> code . '"' ;
2010-11-01 17:00:38 +01:00
if ( $selected == $obj -> code ) print ' selected="selected"' ;
2010-05-03 10:22:35 +02:00
print '>' ;
$level = $langs -> trans ( $obj -> code );
if ( $level == $obj -> code ) $level = $langs -> trans ( $obj -> label );
print $level ;
print '</option>' ;
$i ++ ;
}
}
else dol_print_error ( $this -> db );
print '</select>' ;
print '</td>' ;
print '<td align="left"><input type="submit" class="button" value="' . $langs -> trans ( " Modify " ) . '"></td>' ;
print '</tr></table></form>' ;
}
2010-10-31 21:09:50 +01:00
2010-05-03 10:22:35 +02:00
/**
2011-12-29 23:23:31 +01:00
* Retourne la liste deroulante des departements / province / cantons tout pays confondu ou pour un pays donne .
* Dans le cas d 'une liste tout pays confondus, l' affichage fait une rupture sur le pays .
* La cle de la liste est le code ( il peut y avoir plusieurs entree pour
* un code donnee mais dans ce cas , le champ pays differe ) .
* Ainsi les liens avec les departements se font sur un departement independemment de son nom .
*
* @ param string $selected Code state preselected
* @ param int $country_codeid 0 = list for all countries , otherwise country code or country rowid to show
* @ param string $htmlname Id of department
* @ return void
2010-05-03 10:22:35 +02:00
*/
2013-09-20 14:34:14 +02:00
function select_departement ( $selected = '' , $country_codeid = 0 , $htmlname = 'state_id' )
2010-09-01 22:51:10 +02:00
{
2011-12-29 23:23:31 +01:00
print $this -> select_state ( $selected , $country_codeid , $htmlname );
2010-09-01 22:51:10 +02:00
}
/**
2011-12-29 18:07:41 +01:00
* Retourne la liste deroulante des departements / province / cantons tout pays confondu ou pour un pays donne .
* Dans le cas d 'une liste tout pays confondus, l' affichage fait une rupture sur le pays .
* La cle de la liste est le code ( il peut y avoir plusieurs entree pour
* un code donnee mais dans ce cas , le champ pays differe ) .
* Ainsi les liens avec les departements se font sur un departement independemment de son nom .
2011-12-29 23:23:31 +01:00
*
2013-10-11 12:14:14 +02:00
* @ param string $selected Code state preselected ( mus be state id )
2011-12-29 18:07:41 +01:00
* @ param string $country_codeid Country code or id : 0 = list for all countries , otherwise country code or country rowid to show
2011-12-29 23:23:31 +01:00
* @ param string $htmlname Id of department
2013-06-09 18:29:06 +02:00
* @ return string String with HTML select
2010-09-01 22:51:10 +02:00
*/
2013-09-20 14:34:14 +02:00
function select_state ( $selected = '' , $country_codeid = 0 , $htmlname = 'state_id' )
2010-05-03 10:22:35 +02:00
{
global $conf , $langs , $user ;
2012-03-15 22:37:42 +01:00
dol_syslog ( get_class ( $this ) . " ::select_departement selected= " . $selected . " , country_codeid= " . $country_codeid , LOG_DEBUG );
2010-05-03 10:22:35 +02:00
$langs -> load ( " dict " );
2010-10-31 21:09:50 +01:00
2010-09-01 22:51:10 +02:00
$out = '' ;
2010-05-03 10:22:35 +02:00
2010-06-06 16:30:28 +02:00
// On recherche les departements/cantons/province active d'une region et pays actif
2011-12-29 23:23:31 +01:00
$sql = " SELECT d.rowid, d.code_departement as code , d.nom, d.active, p.libelle as country, p.code as country_code FROM " ;
2010-05-03 10:22:35 +02:00
$sql .= " " . MAIN_DB_PREFIX . " c_departements as d, " . MAIN_DB_PREFIX . " c_regions as r, " . MAIN_DB_PREFIX . " c_pays as p " ;
$sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=p.rowid " ;
$sql .= " AND d.active = 1 AND r.active = 1 AND p.active = 1 " ;
2011-12-29 23:23:31 +01:00
if ( $country_codeid && is_numeric ( $country_codeid )) $sql .= " AND p.rowid = ' " . $country_codeid . " ' " ;
2011-12-29 18:07:41 +01:00
if ( $country_codeid && ! is_numeric ( $country_codeid )) $sql .= " AND p.code = ' " . $country_codeid . " ' " ;
2010-05-03 10:22:35 +02:00
$sql .= " ORDER BY p.code, d.code_departement " ;
2012-03-15 22:37:42 +01:00
dol_syslog ( get_class ( $this ) . " ::select_departement sql= " . $sql );
2010-05-03 10:22:35 +02:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
2010-10-13 18:36:10 +02:00
if ( ! empty ( $htmlname )) $out .= '<select id="' . $htmlname . '" class="flat" name="' . $htmlname . '">' ;
2011-12-29 18:07:41 +01:00
if ( $country_codeid ) $out .= '<option value="0"> </option>' ;
2010-05-03 10:22:35 +02:00
$num = $this -> db -> num_rows ( $result );
$i = 0 ;
2011-12-29 23:23:31 +01:00
dol_syslog ( get_class ( $this ) . " ::select_departement num= " . $num , LOG_DEBUG );
2010-05-03 10:22:35 +02:00
if ( $num )
{
2013-02-25 17:56:41 +01:00
$country = '' ;
2010-05-03 10:22:35 +02:00
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $result );
if ( $obj -> code == '0' ) // Le code peut etre une chaine
{
2010-09-01 22:51:10 +02:00
$out .= '<option value="0"> </option>' ;
2010-05-03 10:22:35 +02:00
}
else {
2013-02-25 17:56:41 +01:00
if ( ! $country || $country != $obj -> country )
2010-05-03 10:22:35 +02:00
{
// Affiche la rupture si on est en mode liste multipays
2011-12-29 18:07:41 +01:00
if ( ! $country_codeid && $obj -> country_code )
2010-05-03 10:22:35 +02:00
{
2011-12-29 23:23:31 +01:00
$out .= '<option value="-1" disabled="disabled">----- ' . $obj -> country . " -----</option> \n " ;
2013-02-25 17:56:41 +01:00
$country = $obj -> country ;
2010-05-03 10:22:35 +02:00
}
}
2013-10-11 12:14:14 +02:00
if (( ! empty ( $selected ) && $selected == $obj -> rowid )
|| ( empty ( $selected ) && ! empty ( $conf -> global -> MAIN_FORCE_DEFAULT_STATE_ID ) && $conf -> global -> MAIN_FORCE_DEFAULT_STATE_ID == $obj -> rowid ))
2010-05-03 10:22:35 +02:00
{
2010-11-01 17:00:38 +01:00
$out .= '<option value="' . $obj -> rowid . '" selected="selected">' ;
2010-05-03 10:22:35 +02:00
}
else
{
2010-09-01 22:51:10 +02:00
$out .= '<option value="' . $obj -> rowid . '">' ;
2010-05-03 10:22:35 +02:00
}
2010-09-01 22:51:10 +02:00
// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
$out .= $obj -> code . ' - ' . ( $langs -> trans ( $obj -> code ) != $obj -> code ? $langs -> trans ( $obj -> code ) : ( $obj -> nom != '-' ? $obj -> nom : '' ));
$out .= '</option>' ;
2010-05-03 10:22:35 +02:00
}
$i ++ ;
}
}
2012-07-09 18:09:44 +02:00
if ( ! empty ( $htmlname )) $out .= '</select>' ;
if ( ! empty ( $htmlname ) && $user -> admin ) $out .= info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionnarySetup " ), 1 );
2010-05-03 10:22:35 +02:00
}
else
{
dol_print_error ( $this -> db );
}
2010-10-31 21:09:50 +01:00
2010-09-01 22:51:10 +02:00
return $out ;
2010-05-03 10:22:35 +02:00
}
/**
2011-12-29 23:23:31 +01:00
* Retourne la liste deroulante des regions actives dont le pays est actif
* La cle de la liste est le code ( il peut y avoir plusieurs entree pour
* un code donnee mais dans ce cas , le champ pays et lang differe ) .
* Ainsi les liens avec les regions se font sur une region independemment de son nom .
*
* @ param string $selected Preselected value
* @ param string $htmlname Name of HTML select field
* @ return void
2010-05-03 10:22:35 +02:00
*/
function select_region ( $selected = '' , $htmlname = 'region_id' )
{
global $conf , $langs ;
$langs -> load ( " dict " );
2011-12-29 18:07:41 +01:00
$sql = " SELECT r.rowid, r.code_region as code, r.nom as libelle, r.active, p.code as country_code, p.libelle as country FROM " . MAIN_DB_PREFIX . " c_regions as r, " . MAIN_DB_PREFIX . " c_pays as p " ;
2011-12-29 23:23:31 +01:00
$sql .= " WHERE r.fk_pays=p.rowid AND r.active = 1 and p.active = 1 " ;
$sql .= " ORDER BY p.code, p.libelle ASC " ;
2010-05-03 10:22:35 +02:00
2011-12-29 23:23:31 +01:00
dol_syslog ( get_class ( $this ) . " ::select_region sql= " . $sql );
2010-05-03 10:22:35 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
print '<select class="flat" name="' . $htmlname . '">' ;
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
if ( $num )
{
2013-02-25 17:56:41 +01:00
$country = '' ;
2010-05-03 10:22:35 +02:00
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
if ( $obj -> code == 0 ) {
print '<option value="0"> </option>' ;
}
else {
2013-02-25 17:56:41 +01:00
if ( $country == '' || $country != $obj -> country )
2010-05-03 10:22:35 +02:00
{
// Show break
2011-12-29 18:07:41 +01:00
$key = $langs -> trans ( " Country " . strtoupper ( $obj -> country_code ));
$valuetoshow = ( $key != " Country " . strtoupper ( $obj -> country_code )) ? $obj -> country_code . " - " . $key : $obj -> country ;
2010-05-03 10:22:35 +02:00
print '<option value="-1" disabled="disabled">----- ' . $valuetoshow . " -----</option> \n " ;
2013-02-25 17:56:41 +01:00
$country = $obj -> country ;
2010-05-03 10:22:35 +02:00
}
if ( $selected > 0 && $selected == $obj -> code )
{
2010-11-01 17:00:38 +01:00
print '<option value="' . $obj -> code . '" selected="selected">' . $obj -> libelle . '</option>' ;
2010-05-03 10:22:35 +02:00
}
else
{
print '<option value="' . $obj -> code . '">' . $obj -> libelle . '</option>' ;
}
}
$i ++ ;
}
}
print '</select>' ;
}
else
{
dol_print_error ( $this -> db );
}
}
2010-10-31 21:09:50 +01:00
2010-05-03 10:22:35 +02:00
/**
2011-10-22 15:55:08 +02:00
* Return combo list with people title
*
2013-06-09 18:29:06 +02:00
* @ param string $selected Title preselected
* @ param string $htmlname Name of HTML select combo field
* @ return string String with HTML select
2010-09-01 22:51:10 +02:00
*/
function select_civility ( $selected = '' , $htmlname = 'civilite_id' )
2010-05-03 10:22:35 +02:00
{
global $conf , $langs , $user ;
$langs -> load ( " dict " );
2010-10-31 21:09:50 +01:00
2010-09-01 22:51:10 +02:00
$out = '' ;
2010-05-03 10:22:35 +02:00
$sql = " SELECT rowid, code, civilite, active FROM " . MAIN_DB_PREFIX . " c_civilite " ;
$sql .= " WHERE active = 1 " ;
2011-10-22 15:55:08 +02:00
dol_syslog ( " Form::select_civility sql= " . $sql );
2010-05-03 10:22:35 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
2010-09-01 22:51:10 +02:00
$out .= '<select class="flat" name="' . $htmlname . '">' ;
$out .= '<option value=""> </option>' ;
2010-05-03 10:22:35 +02:00
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
if ( $num )
{
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
if ( $selected == $obj -> code )
{
2010-11-01 17:00:38 +01:00
$out .= '<option value="' . $obj -> code . '" selected="selected">' ;
2010-05-03 10:22:35 +02:00
}
else
{
2010-09-01 22:51:10 +02:00
$out .= '<option value="' . $obj -> code . '">' ;
2010-05-03 10:22:35 +02:00
}
// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
2010-09-01 22:51:10 +02:00
$out .= ( $langs -> trans ( " Civility " . $obj -> code ) != " Civility " . $obj -> code ? $langs -> trans ( " Civility " . $obj -> code ) : ( $obj -> civilite != '-' ? $obj -> civilite : '' ));
$out .= '</option>' ;
2010-05-03 10:22:35 +02:00
$i ++ ;
}
}
2010-09-01 22:51:10 +02:00
$out .= '</select>' ;
if ( $user -> admin ) $out .= info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionnarySetup " ), 1 );
2010-05-03 10:22:35 +02:00
}
else
{
dol_print_error ( $this -> db );
}
2010-10-31 21:09:50 +01:00
2010-09-01 22:51:10 +02:00
return $out ;
2010-05-03 10:22:35 +02:00
}
2010-10-31 21:09:50 +01:00
2010-05-03 10:22:35 +02:00
/**
2011-06-08 00:05:07 +02:00
* Retourne la liste deroulante des formes juridiques tous pays confondus ou pour un pays donne .
2011-12-29 23:23:31 +01:00
* Dans le cas d ' une liste tous pays confondu , on affiche une rupture sur le pays .
*
* @ param string $selected Code forme juridique a pre - selectionne
* @ param mixed $country_codeid 0 = liste tous pays confondus , sinon code du pays a afficher
* @ param string $filter Add a SQL filter on list
* @ return void
2010-05-03 10:22:35 +02:00
*/
2011-12-29 23:23:31 +01:00
function select_forme_juridique ( $selected = '' , $country_codeid = 0 , $filter = '' )
2010-09-01 22:51:10 +02:00
{
2011-12-29 23:23:31 +01:00
print $this -> select_juridicalstatus ( $selected , $country_codeid , $filter );
2010-09-01 22:51:10 +02:00
}
/**
2011-06-08 00:05:07 +02:00
* Retourne la liste deroulante des formes juridiques tous pays confondus ou pour un pays donne .
* Dans le cas d ' une liste tous pays confondu , on affiche une rupture sur le pays
2011-12-29 23:23:31 +01:00
*
* @ param string $selected Code forme juridique a pre - selectionne
* @ param int $country_codeid 0 = liste tous pays confondus , sinon code du pays a afficher
* @ param string $filter Add a SQL filter on list
* @ return string String with HTML select
2010-09-01 22:51:10 +02:00
*/
2011-12-29 23:23:31 +01:00
function select_juridicalstatus ( $selected = '' , $country_codeid = 0 , $filter = '' )
2010-05-03 10:22:35 +02:00
{
global $conf , $langs , $user ;
$langs -> load ( " dict " );
2010-10-31 21:09:50 +01:00
2010-09-01 22:51:10 +02:00
$out = '' ;
2010-05-03 10:22:35 +02:00
// On recherche les formes juridiques actives des pays actifs
2011-12-29 23:23:31 +01:00
$sql = " SELECT f.rowid, f.code as code , f.libelle as nom, f.active, p.libelle as country, p.code as country_code " ;
2011-11-23 21:25:02 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " c_forme_juridique as f, " . MAIN_DB_PREFIX . " c_pays as p " ;
2010-05-03 10:22:35 +02:00
$sql .= " WHERE f.fk_pays=p.rowid " ;
$sql .= " AND f.active = 1 AND p.active = 1 " ;
2011-12-29 23:23:31 +01:00
if ( $country_codeid ) $sql .= " AND p.code = ' " . $country_codeid . " ' " ;
2011-06-08 00:05:07 +02:00
if ( $filter ) $sql .= " " . $filter ;
2010-05-03 10:22:35 +02:00
$sql .= " ORDER BY p.code, f.code " ;
dol_syslog ( " Form::select_forme_juridique sql= " . $sql );
$result = $this -> db -> query ( $sql );
if ( $result )
{
2010-09-01 22:51:10 +02:00
$out .= '<div id="particulier2" class="visible">' ;
$out .= '<select class="flat" name="forme_juridique_code">' ;
2011-12-29 23:23:31 +01:00
if ( $country_codeid ) $out .= '<option value="0"> </option>' ;
2010-05-03 10:22:35 +02:00
$num = $this -> db -> num_rows ( $result );
$i = 0 ;
if ( $num )
{
2013-02-25 17:56:41 +01:00
$country = '' ;
2010-05-03 10:22:35 +02:00
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $result );
if ( $obj -> code == 0 ) {
2010-09-01 22:51:10 +02:00
$out .= '<option value="0"> </option>' ;
2010-05-03 10:22:35 +02:00
}
else {
2013-02-25 17:56:41 +01:00
if ( ! $country || $country != $obj -> country ) {
2010-05-03 10:22:35 +02:00
// Affiche la rupture si on est en mode liste multipays
2011-12-29 23:23:31 +01:00
if ( ! $country_codeid && $obj -> country_code ) {
$out .= '<option value="0">----- ' . $obj -> country . " -----</option> \n " ;
2013-02-25 17:56:41 +01:00
$country = $obj -> country ;
2010-05-03 10:22:35 +02:00
}
}
if ( $selected > 0 && $selected == $obj -> code )
{
2010-11-01 17:00:38 +01:00
$out .= '<option value="' . $obj -> code . '" selected="selected">' ;
2010-05-03 10:22:35 +02:00
}
else
{
2010-09-01 22:51:10 +02:00
$out .= '<option value="' . $obj -> code . '">' ;
2010-05-03 10:22:35 +02:00
}
// Si translation exists, we use it, otherwise we use default label in database
2010-09-01 22:51:10 +02:00
$out .= $obj -> code . ' - ' ;
$out .= ( $langs -> trans ( " JuridicalStatus " . $obj -> code ) != " JuridicalStatus " . $obj -> code ? $langs -> trans ( " JuridicalStatus " . $obj -> code ) : ( $obj -> nom != '-' ? $obj -> nom : '' )); // $obj->nom is alreay in output charset (converted by database driver)
$out .= '</option>' ;
2010-05-03 10:22:35 +02:00
}
$i ++ ;
}
}
2010-09-01 22:51:10 +02:00
$out .= '</select>' ;
if ( $user -> admin ) $out .= info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionnarySetup " ), 1 );
$out .= '</div>' ;
2010-05-03 10:22:35 +02:00
}
else
{
dol_print_error ( $this -> db );
}
2010-10-31 21:09:50 +01:00
2010-09-01 22:51:10 +02:00
return $out ;
2010-05-03 10:22:35 +02:00
}
/**
2011-12-29 23:23:31 +01:00
* Return list of third parties
*
2013-11-07 21:23:29 +01:00
* @ param object $object Object we try to find contacts
2012-03-14 14:00:20 +01:00
* @ param string $var_id Name of id field
* @ param string $selected Pre - selected third party
* @ param string $htmlname Name of HTML form
2012-04-21 19:44:05 +02:00
* @ param array $limitto Disable answers that are not id in this array list
2013-01-02 14:35:16 +01:00
* @ param int $forceid This is to force another object id than object -> id
2013-11-07 21:02:50 +01:00
* @ return int The selected third party ID
2012-03-18 15:30:01 +01:00
* TODO obsolete ?
* cette fonction doit utiliser du javascript quoi qu ' il en soit !
* autant utiliser le système combobox sans rechargement de page non ?
2010-05-03 10:22:35 +02:00
*/
2012-03-14 14:00:20 +01:00
function selectCompaniesForNewContact ( $object , $var_id , $selected = '' , $htmlname = 'newcompany' , $limitto = '' , $forceid = 0 )
2010-05-03 10:22:35 +02:00
{
global $conf , $langs ;
// On recherche les societes
$sql = " SELECT s.rowid, s.nom FROM " ;
$sql .= " " . MAIN_DB_PREFIX . " societe as s " ;
2012-02-03 19:06:37 +01:00
$sql .= " WHERE s.entity IN ( " . getEntity ( 'societe' , 1 ) . " ) " ;
2012-09-15 11:21:22 +02:00
if ( $selected && $conf -> use_javascript_ajax && ! empty ( $conf -> global -> COMPANY_USE_SEARCH_TO_SELECT )) $sql .= " AND rowid = " . $selected ;
2010-05-03 10:22:35 +02:00
else
{
// For ajax search we limit here. For combo list, we limit later
if ( $conf -> use_javascript_ajax && $conf -> global -> COMPANY_USE_SEARCH_TO_SELECT
2011-09-17 21:49:50 +02:00
&& is_array ( $limitto ) && count ( $limitto ))
2010-05-03 10:22:35 +02:00
{
2012-02-03 19:06:37 +01:00
$sql .= " AND rowid IN ( " . join ( ',' , $limitto ) . " ) " ;
2010-05-03 10:22:35 +02:00
}
}
2012-02-01 11:36:16 +01:00
$sql .= " ORDER BY nom ASC " ;
2012-02-25 01:34:05 +01:00
2011-06-13 16:17:44 +02:00
$resql = $this -> db -> query ( $sql );
2010-05-03 10:22:35 +02:00
if ( $resql )
{
2012-09-15 11:21:22 +02:00
if ( $conf -> use_javascript_ajax && ! empty ( $conf -> global -> COMPANY_USE_SEARCH_TO_SELECT ))
2010-05-03 10:22:35 +02:00
{
2010-10-27 11:00:37 +02:00
$minLength = ( is_numeric ( $conf -> global -> COMPANY_USE_SEARCH_TO_SELECT ) ? $conf -> global -> COMPANY_USE_SEARCH_TO_SELECT : 2 );
2010-10-31 21:09:50 +01:00
2010-05-03 10:22:35 +02:00
$socid = 0 ;
if ( $selected )
{
$obj = $this -> db -> fetch_object ( $resql );
$socid = $obj -> rowid ? $obj -> rowid : '' ;
}
// We call a page after a small delay when a new input has been selected
2012-03-17 16:05:58 +01:00
$javaScript = " window.location= \ ' " . $_SERVER [ 'PHP_SELF' ] . " ? " . $var_id . " = " . ( $forceid > 0 ? $forceid : $object -> id ) . " & " . $htmlname . " = \ ' + document.getElementById( \ ' " . $htmlname . " \ ').value; " ;
2011-02-05 03:29:35 +01:00
$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
2010-05-03 10:22:35 +02:00
print " \n " . '<!-- Input text for third party with Ajax.Autocompleter (selectCompaniesForNewContact) -->' . " \n " ;
print '<table class="nobordernopadding"><tr class="nobordernopadding">' ;
print '<td class="nobordernopadding">' ;
if ( $obj -> rowid == 0 )
{
//$langs->load("companies");
//print '<input type="text" size="30" id="'.$htmlname.'_label" name="'.$htmlname.'" value="'.$langs->trans("SelectCompany").'" '.$htmloption.' />';
2010-10-10 19:44:34 +02:00
print '<input type="text" size="30" id="search_' . $htmlname . '" name="search_' . $htmlname . '" value="" ' . $htmloption . ' />' ;
2010-05-03 10:22:35 +02:00
}
else
{
2010-10-10 19:44:34 +02:00
print '<input type="text" size="30" id="search_' . $htmlname . '" name="search_' . $htmlname . '" value="' . $obj -> nom . '" ' . $htmloption . ' />' ;
2010-05-03 10:22:35 +02:00
}
2010-10-27 11:00:37 +02:00
print ajax_autocompleter (( $socid ? $socid :- 1 ), $htmlname , DOL_URL_ROOT . '/societe/ajaxcompanies.php' , '' , $minLength );
2010-05-03 10:22:35 +02:00
print '</td>' ;
2010-10-10 19:44:34 +02:00
print '</tr>' ;
2010-05-03 10:22:35 +02:00
print '</table>' ;
print " \n " ;
return $socid ;
}
else
{
2012-03-17 16:05:58 +01:00
$javaScript = " window.location=' " . $_SERVER [ 'PHP_SELF' ] . " ? " . $var_id . " = " . ( $forceid > 0 ? $forceid : $object -> id ) . " & " . $htmlname . " =' + form. " . $htmlname . " .options[form. " . $htmlname . " .selectedIndex].value; " ;
2011-04-25 17:00:18 +02:00
print '<select class="flat" id="' . $htmlname . '" name="' . $htmlname . '" onChange="' . $javaScript . '">' ;
2011-06-13 16:17:44 +02:00
$num = $this -> db -> num_rows ( $resql );
2010-05-03 10:22:35 +02:00
$i = 0 ;
if ( $num )
{
while ( $i < $num )
{
2011-06-13 16:17:44 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2010-05-03 10:22:35 +02:00
if ( $i == 0 ) $firstCompany = $obj -> rowid ;
$disabled = 0 ;
2011-09-17 21:49:50 +02:00
if ( is_array ( $limitto ) && count ( $limitto ) && ! in_array ( $obj -> rowid , $limitto )) $disabled = 1 ;
2010-05-03 10:22:35 +02:00
if ( $selected > 0 && $selected == $obj -> rowid )
{
print '<option value="' . $obj -> rowid . '"' ;
2011-08-31 17:12:09 +02:00
if ( $disabled ) print ' disabled="disabled"' ;
2010-11-01 17:00:38 +01:00
print ' selected="selected">' . dol_trunc ( $obj -> nom , 24 ) . '</option>' ;
2010-05-03 10:22:35 +02:00
$firstCompany = $obj -> rowid ;
}
else
{
print '<option value="' . $obj -> rowid . '"' ;
2011-08-31 17:12:09 +02:00
if ( $disabled ) print ' disabled="disabled"' ;
2010-05-03 10:22:35 +02:00
print '>' . dol_trunc ( $obj -> nom , 24 ) . '</option>' ;
}
$i ++ ;
}
}
print " </select> \n " ;
return $firstCompany ;
}
}
else
{
2011-06-13 16:17:44 +02:00
dol_print_error ( $this -> db );
2010-05-03 10:22:35 +02:00
}
}
2011-02-14 17:49:04 +01:00
/**
* Return a select list with types of contacts
2011-12-29 23:23:31 +01:00
*
2013-11-07 21:23:29 +01:00
* @ param object $object Object to use to find type of contact
2011-12-29 23:23:31 +01:00
* @ param string $selected Default selected value
* @ param string $htmlname HTML select name
* @ param string $source Source ( 'internal' or 'external' )
* @ param string $order Sort criteria
* @ param int $showempty 1 = Add en empty line
* @ return void
2011-02-14 17:49:04 +01:00
*/
2011-12-29 23:23:31 +01:00
function selectTypeContact ( $object , $selected , $htmlname = 'type' , $source = 'internal' , $order = 'code' , $showempty = 0 )
2010-05-03 10:22:35 +02:00
{
2012-10-31 09:59:24 +01:00
if ( is_object ( $object ) && method_exists ( $object , 'liste_type_contact' ))
2010-05-03 10:22:35 +02:00
{
2013-09-25 10:17:27 +02:00
$lesTypes = $object -> liste_type_contact ( $source , $order , 0 , 1 );
2012-10-31 09:59:24 +01:00
print '<select class="flat" name="' . $htmlname . '" id="' . $htmlname . '">' ;
if ( $showempty ) print '<option value="0"></option>' ;
foreach ( $lesTypes as $key => $value )
{
print '<option value="' . $key . '"' ;
if ( $key == $selected )
print ' selected' ;
print '>' . $value . '</option>' ;
}
print " </select> \n " ;
2010-05-03 10:22:35 +02:00
}
}
2010-10-31 21:09:50 +01:00
2010-10-12 14:56:31 +02:00
/**
2011-02-14 17:49:04 +01:00
* Return a select list with zip codes and their town
2011-12-29 23:23:31 +01:00
*
* @ param string $selected Preselected value
* @ param string $htmlname HTML select name
* @ param string $fields Fields
* @ param int $fieldsize Field size
* @ param int $disableautocomplete 1 To disable autocomplete features
* @ return void
2010-10-12 14:56:31 +02:00
*/
2011-06-26 23:51:56 +02:00
function select_ziptown ( $selected = '' , $htmlname = 'zipcode' , $fields = '' , $fieldsize = 0 , $disableautocomplete = 0 )
2010-10-12 14:56:31 +02:00
{
2010-10-13 09:38:48 +02:00
global $conf ;
2010-10-31 21:09:50 +01:00
2010-10-13 15:54:30 +02:00
$out = '' ;
2010-10-31 21:09:50 +01:00
2010-10-13 09:38:48 +02:00
$size = '' ;
if ( ! empty ( $fieldsize )) $size = 'size="' . $fieldsize . '"' ;
2010-10-31 21:09:50 +01:00
2011-10-25 19:03:12 +02:00
if ( $conf -> use_javascript_ajax && empty ( $disableautocomplete )) $out .= ajax_multiautocompleter ( $htmlname , $fields , DOL_URL_ROOT . '/core/ajax/ziptown.php' ) . " \n " ;
2010-10-13 15:54:30 +02:00
$out .= '<input id="' . $htmlname . '" type="text" name="' . $htmlname . '" ' . $size . ' value="' . $selected . '">' . " \n " ;
2010-10-31 21:09:50 +01:00
2010-10-13 15:54:30 +02:00
return $out ;
2010-10-12 14:56:31 +02:00
}
2010-05-03 10:22:35 +02:00
2011-02-14 17:49:04 +01:00
/**
* Return HTML string to use as input of professional id into a HTML page ( siren , siret , etc ... )
2011-12-29 23:23:31 +01:00
*
* @ param int $idprof 1 , 2 , 3 , 4 ( Example : 1 = siren , 2 = siret , 3 = naf , 4 = rcs / rm )
* @ param string $htmlname Name of HTML select
* @ param string $preselected Default value to show
* @ param string $country_code FR , IT , ...
* @ return string HTML string with prof id
2011-02-14 17:49:04 +01:00
*/
function get_input_id_prof ( $idprof , $htmlname , $preselected , $country_code )
{
global $conf , $langs ;
2012-02-25 01:34:05 +01:00
$formlength = 0 ;
2012-07-28 12:35:11 +02:00
if ( empty ( $conf -> global -> MAIN_DISABLEPROFIDRULES )) {
2012-07-28 19:04:50 +02:00
if ( $country_code == 'FR' )
{
if ( isset ( $idprof )) {
if ( $idprof == 1 ) $formlength = 9 ;
else if ( $idprof == 2 ) $formlength = 14 ;
else if ( $idprof == 3 ) $formlength = 5 ; // 4 chiffres et 1 lettre depuis janvier
else if ( $idprof == 4 ) $formlength = 32 ; // No maximum as we need to include a town name in this id
}
}
else if ( $country_code == 'ES' )
{
if ( $idprof == 1 ) $formlength = 9 ; //CIF/NIF/NIE 9 digits
if ( $idprof == 2 ) $formlength = 12 ; //NASS 12 digits without /
if ( $idprof == 3 ) $formlength = 5 ; //CNAE 5 digits
if ( $idprof == 4 ) $formlength = 32 ; //depend of college
2012-07-28 12:35:11 +02:00
}
2011-02-14 17:49:04 +01:00
}
$selected = $preselected ;
2012-07-28 12:35:11 +02:00
if ( ! $selected && isset ( $idprof )) {
2012-07-28 19:04:50 +02:00
if ( $idprof == 1 && ! empty ( $this -> idprof1 )) $selected = $this -> idprof1 ;
else if ( $idprof == 2 && ! empty ( $this -> idprof2 )) $selected = $this -> idprof2 ;
else if ( $idprof == 3 && ! empty ( $this -> idprof3 )) $selected = $this -> idprof3 ;
2012-07-28 12:35:11 +02:00
else if ( $idprof == 4 && ! empty ( $this -> idprof4 )) $selected = $this -> idprof4 ;
}
2011-02-14 17:49:04 +01:00
2012-02-25 01:34:05 +01:00
$maxlength = $formlength ;
if ( empty ( $formlength )) { $formlength = 24 ; $maxlength = 128 ; }
$out = '<input type="text" name="' . $htmlname . '" size="' . ( $formlength + 1 ) . '" maxlength="' . $maxlength . '" value="' . $selected . '">' ;
2011-02-14 17:49:04 +01:00
return $out ;
}
2010-05-03 10:22:35 +02:00
}
?>