94 global $conf, $langs, $user, $canvas;
95 global $form, $formcompany, $objsoc;
97 if ($action ==
'add' || $action ==
'update') {
101 foreach ($this->
object as $key => $value) {
102 $this->tpl[$key] = $value;
105 $this->tpl[
'error'] = $this->error;
106 $this->tpl[
'errors'] = $this->errors;
108 if ($action ==
'create' || $action ==
'edit') {
109 if ($conf->use_javascript_ajax) {
110 $this->tpl[
'ajax_selectcountry'] =
"\n".
'<script type="text/javascript">
111 jQuery(document).ready(function () {
112 jQuery("#selectcountry_id").change(function() {
113 document.formsoc.action.value="'.$action.
'";
114 document.formsoc.canvas.value="'.$canvas.
'";
115 document.formsoc.submit();
121 if (is_object($objsoc) && $objsoc->id > 0) {
122 $this->tpl[
'company'] = $objsoc->getNomUrl(1);
123 $this->tpl[
'company_id'] = $objsoc->id;
125 $this->tpl[
'company'] = $form->select_company($this->object->socid,
'socid',
'', 1);
129 $this->tpl[
'select_civility'] = $formcompany->select_civility($this->object->civility_id);
132 if ((isset($objsoc->typent_code) && $objsoc->typent_code ==
'TE_PRIVATE') || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) {
133 if (
dol_strlen(trim($this->object->address)) == 0) {
134 $this->tpl[
'address'] = $objsoc->address;
136 if (
dol_strlen(trim($this->object->zip)) == 0) {
137 $this->
object->zip = $objsoc->zip;
139 if (
dol_strlen(trim($this->object->town)) == 0) {
140 $this->
object->town = $objsoc->town;
142 if (
dol_strlen(trim($this->object->phone_pro)) == 0) {
143 $this->
object->phone_pro = $objsoc->phone;
145 if (
dol_strlen(trim($this->object->fax)) == 0) {
146 $this->
object->fax = $objsoc->fax;
148 if (
dol_strlen(trim($this->object->email)) == 0) {
149 $this->
object->email = $objsoc->email;
154 $this->tpl[
'select_zip'] = $formcompany->select_ziptown($this->object->zip,
'zipcode', array(
'town',
'selectcountry_id',
'state_id'), 6);
157 $this->tpl[
'select_town'] = $formcompany->select_ziptown($this->object->town,
'town', array(
'zipcode',
'selectcountry_id',
'state_id'));
159 if (
dol_strlen(trim($this->object->country_id)) == 0) {
160 $this->
object->country_id = $objsoc->country_id;
164 $this->tpl[
'select_country'] = $form->select_country($this->object->country_id,
'country_id');
165 $countrynotdefined = $langs->trans(
"ErrorSetACountryFirst").
' ('.$langs->trans(
"SeeAbove").
')';
168 $this->tpl[
'info_admin'] =
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
172 if ($this->object->country_id) {
173 $this->tpl[
'select_state'] = $formcompany->select_state($this->object->state_id, $this->object->country_code);
175 $this->tpl[
'select_state'] = $countrynotdefined;
179 $selectarray = array(
'0'=>$langs->trans(
"ContactPublic"),
'1'=>$langs->trans(
"ContactPrivate"));
180 $this->tpl[
'select_visibility'] = $form->selectarray(
'priv', $selectarray, $this->object->priv, 0);
183 if ($action ==
'view' || $action ==
'edit' || $action ==
'delete') {
185 if (isModEnabled(
'mailing')) {
186 $langs->load(
"mails");
187 $this->tpl[
'nb_emailing'] = $this->
object->getNbOfEMailings();
191 $this->tpl[
'contact_element'] = array();
194 $this->
object->load_ref_elements();
196 if (isModEnabled(
'commande')) {
197 $this->tpl[
'contact_element'][$i][
'linked_element_label'] = $langs->trans(
"ContactForOrders");
198 $this->tpl[
'contact_element'][$i][
'linked_element_value'] = $this->
object->ref_commande ? $this->
object->ref_commande : $langs->trans(
"NoContactForAnyOrder");
201 if (isModEnabled(
"propal")) {
202 $this->tpl[
'contact_element'][$i][
'linked_element_label'] = $langs->trans(
"ContactForProposals");
203 $this->tpl[
'contact_element'][$i][
'linked_element_value'] = $this->
object->ref_propal ? $this->
object->ref_propal : $langs->trans(
"NoContactForAnyProposal");
206 if (isModEnabled(
'contrat')) {
207 $this->tpl[
'contact_element'][$i][
'linked_element_label'] = $langs->trans(
"ContactForContracts");
208 $this->tpl[
'contact_element'][$i][
'linked_element_value'] = $this->
object->ref_contrat ? $this->
object->ref_contrat : $langs->trans(
"NoContactForAnyContract");
211 if (isModEnabled(
'facture')) {
212 $this->tpl[
'contact_element'][$i][
'linked_element_label'] = $langs->trans(
"ContactForInvoices");
213 $this->tpl[
'contact_element'][$i][
'linked_element_value'] = $this->
object->ref_facturation ? $this->
object->ref_facturation : $langs->trans(
"NoContactForAnyInvoice");
218 if ($this->object->user_id) {
219 $dolibarr_user =
new User($this->db);
220 $result = $dolibarr_user->fetch($this->object->user_id);
221 $this->tpl[
'dolibarr_user'] = $dolibarr_user->getLoginUrl(1);
223 $this->tpl[
'dolibarr_user'] = $langs->trans(
"NoDolibarrAccess");
227 if ($action ==
'view' || $action ==
'delete') {
228 $this->tpl[
'showrefnav'] = $form->showrefnav($this->
object,
'id');
230 if ($this->object->socid > 0) {
231 $objsoc =
new Societe($this->db);
233 $objsoc->fetch($this->object->socid);
234 $this->tpl[
'company'] = $objsoc->getNomUrl(1);
236 $this->tpl[
'company'] = $langs->trans(
"ContactNotLinkedToCompany");
239 $this->tpl[
'civility'] = $this->
object->getCivilityLabel();
241 $this->tpl[
'address'] =
dol_nl2br($this->object->address);
243 $this->tpl[
'zip'] = ($this->
object->zip ? $this->
object->zip.
' ' :
'');
246 $this->tpl[
'country'] = ($img ? $img.
' ' :
'').$this->object->country;
248 $this->tpl[
'phone_pro'] =
dol_print_phone($this->object->phone_pro, $this->object->country_code, 0, $this->object->id,
'AC_TEL');
249 $this->tpl[
'phone_perso'] =
dol_print_phone($this->object->phone_perso, $this->object->country_code, 0, $this->object->id,
'AC_TEL');
250 $this->tpl[
'phone_mobile'] =
dol_print_phone($this->object->phone_mobile, $this->object->country_code, 0, $this->object->id,
'AC_TEL');
251 $this->tpl[
'fax'] =
dol_print_phone($this->object->fax, $this->object->country_code, 0, $this->object->id,
'AC_FAX');
252 $this->tpl[
'email'] =
dol_print_email($this->object->email, 0, $this->object->id,
'AC_EMAIL');
254 $this->tpl[
'visibility'] = $this->
object->LibPubPriv($this->object->priv);
256 $this->tpl[
'note'] = $this->
object->note_private;
259 if ($action ==
'create_user') {
261 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
262 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
263 $login =
dol_buildlogin($this->object->lastname, $this->object->firstname);
266 $password = $generated_password;
269 $formquestion = array(
270 array(
'label' => $langs->trans(
"LoginToCreate"),
'type' =>
'text',
'name' =>
'login',
'value' => $login),
271 array(
'label' => $langs->trans(
"Password"),
'type' =>
'text',
'name' =>
'password',
'value' => $password));
273 $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');