54 public $errors = array();
92 global $conf, $langs, $user, $canvas;
93 global
$form, $formcompany, $objsoc;
95 if ($action ==
'add' || $action ==
'update') {
99 foreach ($this->
object as $key => $value) {
100 $this->tpl[$key] = $value;
103 $this->tpl[
'error'] = $this->error;
104 $this->tpl[
'errors'] = $this->errors;
106 if ($action ==
'create' || $action ==
'edit') {
107 if ($conf->use_javascript_ajax) {
108 $this->tpl[
'ajax_selectcountry'] =
"\n".
'<script type="text/javascript">
109 jQuery(document).ready(function () {
110 jQuery("#selectcountry_id").change(function() {
111 document.formsoc.action.value="'.$action.
'";
112 document.formsoc.canvas.value="'.$canvas.
'";
113 document.formsoc.submit();
119 if (is_object($objsoc) && $objsoc->id > 0) {
120 $this->tpl[
'company'] = $objsoc->getNomUrl(1);
121 $this->tpl[
'company_id'] = $objsoc->id;
123 $this->tpl[
'company'] =
$form->select_company($this->object->socid,
'socid',
'', 1);
127 $this->tpl[
'select_civility'] = $formcompany->select_civility($this->object->civility_id);
130 if ((isset($objsoc->typent_code) && $objsoc->typent_code ==
'TE_PRIVATE') || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) {
131 if (
dol_strlen(trim($this->object->address)) == 0) {
132 $this->tpl[
'address'] = $objsoc->address;
134 if (
dol_strlen(trim($this->object->zip)) == 0) {
135 $this->
object->zip = $objsoc->zip;
137 if (
dol_strlen(trim($this->object->town)) == 0) {
138 $this->
object->town = $objsoc->town;
140 if (
dol_strlen(trim($this->object->phone_pro)) == 0) {
141 $this->
object->phone_pro = $objsoc->phone;
143 if (
dol_strlen(trim($this->object->fax)) == 0) {
144 $this->
object->fax = $objsoc->fax;
146 if (
dol_strlen(trim($this->object->email)) == 0) {
147 $this->
object->email = $objsoc->email;
152 $this->tpl[
'select_zip'] = $formcompany->select_ziptown($this->object->zip,
'zipcode', array(
'town',
'selectcountry_id',
'state_id'), 6);
155 $this->tpl[
'select_town'] = $formcompany->select_ziptown($this->object->town,
'town', array(
'zipcode',
'selectcountry_id',
'state_id'));
157 if (
dol_strlen(trim($this->object->country_id)) == 0) {
158 $this->
object->country_id = $objsoc->country_id;
162 $this->tpl[
'select_country'] =
$form->select_country($this->object->country_id,
'country_id');
163 $countrynotdefined = $langs->trans(
"ErrorSetACountryFirst").
' ('.$langs->trans(
"SeeAbove").
')';
166 $this->tpl[
'info_admin'] =
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
170 if ($this->object->country_id) {
171 $this->tpl[
'select_state'] = $formcompany->select_state($this->object->state_id, $this->object->country_code);
173 $this->tpl[
'select_state'] = $countrynotdefined;
177 $selectarray = array(
'0'=>$langs->trans(
"ContactPublic"),
'1'=>$langs->trans(
"ContactPrivate"));
178 $this->tpl[
'select_visibility'] =
$form->selectarray(
'priv', $selectarray, $this->object->priv, 0);
181 if ($action ==
'view' || $action ==
'edit' || $action ==
'delete') {
183 if (!empty($conf->mailing->enabled)) {
184 $langs->load(
"mails");
185 $this->tpl[
'nb_emailing'] = $this->
object->getNbOfEMailings();
189 $this->tpl[
'contact_element'] = array();
192 $this->
object->load_ref_elements();
194 if (!empty($conf->commande->enabled)) {
195 $this->tpl[
'contact_element'][$i][
'linked_element_label'] = $langs->trans(
"ContactForOrders");
196 $this->tpl[
'contact_element'][$i][
'linked_element_value'] = $this->
object->ref_commande ? $this->
object->ref_commande : $langs->trans(
"NoContactForAnyOrder");
199 if (!empty($conf->propal->enabled)) {
200 $this->tpl[
'contact_element'][$i][
'linked_element_label'] = $langs->trans(
"ContactForProposals");
201 $this->tpl[
'contact_element'][$i][
'linked_element_value'] = $this->
object->ref_propal ? $this->
object->ref_propal : $langs->trans(
"NoContactForAnyProposal");
204 if (!empty($conf->contrat->enabled)) {
205 $this->tpl[
'contact_element'][$i][
'linked_element_label'] = $langs->trans(
"ContactForContracts");
206 $this->tpl[
'contact_element'][$i][
'linked_element_value'] = $this->
object->ref_contrat ? $this->
object->ref_contrat : $langs->trans(
"NoContactForAnyContract");
210 $this->tpl[
'contact_element'][$i][
'linked_element_label'] = $langs->trans(
"ContactForInvoices");
211 $this->tpl[
'contact_element'][$i][
'linked_element_value'] = $this->
object->ref_facturation ? $this->
object->ref_facturation : $langs->trans(
"NoContactForAnyInvoice");
216 if ($this->object->user_id) {
217 $dolibarr_user =
new User($this->
db);
218 $result = $dolibarr_user->fetch($this->object->user_id);
219 $this->tpl[
'dolibarr_user'] = $dolibarr_user->getLoginUrl(1);
221 $this->tpl[
'dolibarr_user'] = $langs->trans(
"NoDolibarrAccess");
225 if ($action ==
'view' || $action ==
'delete') {
226 $this->tpl[
'showrefnav'] =
$form->showrefnav($this->
object,
'id');
228 if ($this->object->socid > 0) {
231 $objsoc->fetch($this->object->socid);
232 $this->tpl[
'company'] = $objsoc->getNomUrl(1);
234 $this->tpl[
'company'] = $langs->trans(
"ContactNotLinkedToCompany");
237 $this->tpl[
'civility'] = $this->
object->getCivilityLabel();
239 $this->tpl[
'address'] =
dol_nl2br($this->object->address);
241 $this->tpl[
'zip'] = ($this->
object->zip ? $this->
object->zip.
' ' :
'');
244 $this->tpl[
'country'] = ($img ? $img.
' ' :
'').$this->object->country;
246 $this->tpl[
'phone_pro'] =
dol_print_phone($this->object->phone_pro, $this->object->country_code, 0, $this->object->id,
'AC_TEL');
247 $this->tpl[
'phone_perso'] =
dol_print_phone($this->object->phone_perso, $this->object->country_code, 0, $this->object->id,
'AC_TEL');
248 $this->tpl[
'phone_mobile'] =
dol_print_phone($this->object->phone_mobile, $this->object->country_code, 0, $this->object->id,
'AC_TEL');
249 $this->tpl[
'fax'] =
dol_print_phone($this->object->fax, $this->object->country_code, 0, $this->object->id,
'AC_FAX');
250 $this->tpl[
'email'] =
dol_print_email($this->object->email, 0, $this->object->id,
'AC_EMAIL');
252 $this->tpl[
'visibility'] = $this->
object->LibPubPriv($this->object->priv);
254 $this->tpl[
'note'] = nl2br($this->object->note);
257 if ($action ==
'create_user') {
259 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
260 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
261 $login =
dol_buildlogin($this->object->lastname, $this->object->firstname);
264 $password = $generated_password;
267 $formquestion = array(
268 array(
'label' => $langs->trans(
"LoginToCreate"),
'type' =>
'text',
'name' =>
'login',
'value' => $login),
269 array(
'label' => $langs->trans(
"Password"),
'type' =>
'text',
'name' =>
'password',
'value' => $password));
271 $this->tpl[
'action_create_user'] =
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$this->object->id, $langs->trans(
"CreateDolibarrLogin"), $langs->trans(
"ConfirmCreateContact"),
"confirm_create_user", $formquestion,
'no');
284 global $langs, $mysoc;
286 $this->
object->socid =
GETPOST(
"socid",
'int');
287 $this->
object->lastname =
GETPOST(
"name");
288 $this->
object->firstname =
GETPOST(
"firstname");
289 $this->
object->civility_id =
GETPOST(
"civility_id");
290 $this->
object->poste =
GETPOST(
"poste");
291 $this->
object->address =
GETPOST(
"address");
292 $this->
object->zip =
GETPOST(
"zipcode");
293 $this->
object->town =
GETPOST(
"town");
294 $this->
object->country_id =
GETPOST(
"country_id") ?
GETPOST(
"country_id") : $mysoc->country_id;
295 $this->
object->state_id =
GETPOST(
"state_id");
296 $this->
object->phone_pro =
GETPOST(
"phone_pro");
297 $this->
object->phone_perso =
GETPOST(
"phone_perso");
298 $this->
object->phone_mobile =
GETPOST(
"phone_mobile");
299 $this->
object->fax =
GETPOST(
"fax");
300 $this->
object->email =
GETPOST(
"email");
301 $this->
object->priv =
GETPOST(
"priv");
302 $this->
object->note =
GETPOST(
"note",
"restricthtml");
303 $this->
object->canvas =
GETPOST(
"canvas");
306 if ($this->object->country_id) {
307 $sql =
"SELECT code, label FROM ".MAIN_DB_PREFIX.
"c_country WHERE rowid = ".((int) $this->object->country_id);
310 $obj = $this->
db->fetch_object(
$resql);
314 $this->
object->country_id = $langs->trans(
"Country".$obj->code) ? $langs->trans(
"Country".$obj->code) : $obj->label;
315 $this->
object->country_code = $obj->code;
316 $this->
object->country = $langs->trans(
"Country".$obj->code) ? $langs->trans(
"Country".$obj->code) : $obj->label;