113 global
$conf, $langs, $user, $canvas;
114 global $form, $formcompany, $objsoc;
116 if ($action ==
'add' || $action ==
'update') {
120 foreach ($this->
object as $key => $value) {
121 $this->tpl[$key] = $value;
124 $this->tpl[
'error'] = $this->error;
125 $this->tpl[
'errors'] = $this->errors;
127 if ($action ==
'create' || $action ==
'edit') {
128 if (
$conf->use_javascript_ajax) {
129 $this->tpl[
'ajax_selectcountry'] =
"\n".
'<script type="text/javascript">
130 jQuery(document).ready(function () {
131 jQuery("#selectcountry_id").change(function() {
132 document.formsoc.action.value="'.$action.
'";
133 document.formsoc.canvas.value="'.$canvas.
'";
134 document.formsoc.submit();
140 if (is_object($objsoc) && $objsoc->id > 0) {
141 $this->tpl[
'company'] = $objsoc->getNomUrl(1);
142 $this->tpl[
'company_id'] = $objsoc->id;
144 $this->tpl[
'company'] = $form->select_company($this->object->socid,
'socid',
'', 1);
148 $this->tpl[
'select_civility'] = $formcompany->select_civility($this->object->civility_id);
151 if ((isset($objsoc->typent_code) && $objsoc->typent_code ==
'TE_PRIVATE') ||
getDolGlobalString(
'CONTACT_USE_COMPANY_ADDRESS')) {
152 if (
dol_strlen(trim($this->object->address)) == 0) {
153 $this->tpl[
'address'] = $objsoc->address;
155 if (
dol_strlen(trim($this->object->zip)) == 0) {
156 $this->
object->zip = $objsoc->zip;
158 if (
dol_strlen(trim($this->object->town)) == 0) {
159 $this->
object->town = $objsoc->town;
161 if (
dol_strlen(trim($this->object->phone_pro)) == 0) {
162 $this->
object->phone_pro = $objsoc->phone;
164 if (
dol_strlen(trim($this->object->fax)) == 0) {
165 $this->
object->fax = $objsoc->fax;
167 if (
dol_strlen(trim($this->object->email)) == 0) {
168 $this->
object->email = $objsoc->email;
173 $this->tpl[
'select_zip'] = $formcompany->select_ziptown($this->object->zip,
'zipcode', array(
'town',
'selectcountry_id',
'state_id'), 6);
176 $this->tpl[
'select_town'] = $formcompany->select_ziptown($this->object->town,
'town', array(
'zipcode',
'selectcountry_id',
'state_id'));
178 if (
dol_strlen(trim((
string) $this->object->country_id)) == 0) {
179 $this->
object->country_id = $objsoc->country_id;
183 $this->tpl[
'select_country'] = $form->select_country((
string) $this->object->country_id,
'country_id');
184 $countrynotdefined = $langs->trans(
"ErrorSetACountryFirst").
' ('.$langs->trans(
"SeeAbove").
')';
187 $this->tpl[
'info_admin'] =
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
191 if ($this->object->country_id) {
192 $this->tpl[
'select_state'] = $formcompany->select_state($this->object->state_id, $this->object->country_code);
194 $this->tpl[
'select_state'] = $countrynotdefined;
198 $selectarray = array(
'0' => $langs->trans(
"ContactPublic"),
'1' => $langs->trans(
"ContactPrivate"));
199 $this->tpl[
'select_visibility'] = $form->selectarray(
'priv', $selectarray, $this->object->priv, 0);
202 if ($action ==
'view' || $action ==
'edit' || $action ==
'delete') {
205 $langs->load(
"mails");
206 $this->tpl[
'nb_emailing'] = $this->
object->getNbOfEMailings();
210 $this->tpl[
'contact_element'] = array();
213 $this->
object->load_ref_elements();
216 $this->tpl[
'contact_element'][$i][
'linked_element_label'] = $langs->trans(
"ContactForOrders");
217 $this->tpl[
'contact_element'][$i][
'linked_element_value'] = $this->
object->ref_commande ? $this->
object->ref_commande : $langs->trans(
"NoContactForAnyOrder");
221 $this->tpl[
'contact_element'][$i][
'linked_element_label'] = $langs->trans(
"ContactForProposals");
222 $this->tpl[
'contact_element'][$i][
'linked_element_value'] = $this->
object->ref_propal ? $this->
object->ref_propal : $langs->trans(
"NoContactForAnyProposal");
226 $this->tpl[
'contact_element'][$i][
'linked_element_label'] = $langs->trans(
"ContactForContracts");
227 $this->tpl[
'contact_element'][$i][
'linked_element_value'] = $this->
object->ref_contrat ? $this->
object->ref_contrat : $langs->trans(
"NoContactForAnyContract");
231 $this->tpl[
'contact_element'][$i][
'linked_element_label'] = $langs->trans(
"ContactForInvoices");
232 $this->tpl[
'contact_element'][$i][
'linked_element_value'] = $this->
object->ref_facturation ? $this->
object->ref_facturation : $langs->trans(
"NoContactForAnyInvoice");
237 if ($this->object->user_id) {
238 $dolibarr_user =
new User($this->db);
239 $result = $dolibarr_user->fetch($this->object->user_id);
240 $this->tpl[
'dolibarr_user'] = $dolibarr_user->getLoginUrl(1);
242 $this->tpl[
'dolibarr_user'] = $langs->trans(
"NoDolibarrAccess");
246 if ($action ==
'view' || $action ==
'delete') {
247 $this->tpl[
'showrefnav'] = $form->showrefnav($this->
object,
'id');
249 if ($this->object->socid > 0) {
250 $objsoc =
new Societe($this->db);
252 $objsoc->fetch($this->object->socid);
253 $this->tpl[
'company'] = $objsoc->getNomUrl(1);
255 $this->tpl[
'company'] = $langs->trans(
"ContactNotLinkedToCompany");
258 $this->tpl[
'civility'] = $this->
object->getCivilityLabel();
260 $this->tpl[
'address'] =
dol_nl2br($this->object->address);
262 $this->tpl[
'zip'] = ($this->
object->zip ? $this->
object->zip.
' ' :
'');
265 $this->tpl[
'country'] = ($img ? $img.
' ' :
'').$this->object->country;
267 $this->tpl[
'phone_pro'] =
dol_print_phone($this->object->phone_pro, $this->object->country_code, 0, $this->object->id,
'AC_TEL');
268 $this->tpl[
'phone_perso'] =
dol_print_phone($this->object->phone_perso, $this->object->country_code, 0, $this->object->id,
'AC_TEL');
269 $this->tpl[
'phone_mobile'] =
dol_print_phone($this->object->phone_mobile, $this->object->country_code, 0, $this->object->id,
'AC_TEL');
270 $this->tpl[
'fax'] =
dol_print_phone($this->object->fax, $this->object->country_code, 0, $this->object->id,
'AC_FAX');
271 $this->tpl[
'email'] =
dol_print_email($this->object->email, 0, $this->object->id, 1);
273 $this->tpl[
'visibility'] = $this->
object->LibPubPriv($this->object->priv);
275 $this->tpl[
'note'] = $this->
object->note_private;
278 if ($action ==
'create_user') {
280 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
281 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
282 $login =
dol_buildlogin($this->object->lastname, $this->object->firstname);
285 $password = $generated_password;
288 $formquestion = array(
289 array(
'label' => $langs->trans(
"LoginToCreate"),
'type' =>
'text',
'name' =>
'login',
'value' => $login),
290 array(
'label' => $langs->trans(
"Password"),
'type' =>
'text',
'name' =>
'password',
'value' => $password));
292 $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');