1<?php
2/* Copyright (C) 2001-2007  Rodolphe Quiedeville    <rodolphe@quiedeville.org>
3 * Copyright (C) 2003       Brian Fraval            <brian@fraval.org>
4 * Copyright (C) 2004-2015  Laurent Destailleur     <eldy@users.sourceforge.net>
5 * Copyright (C) 2005       Eric Seigne             <eric.seigne@ryxeo.com>
6 * Copyright (C) 2005-2012  Regis Houssin           <regis.houssin@inodbox.com>
7 * Copyright (C) 2008       Patrick Raguin          <patrick.raguin@auguria.net>
8 * Copyright (C) 2010-2016  Juanjo Menent           <jmenent@2byte.es>
9 * Copyright (C) 2011-2013  Alexandre Spangaro      <aspangaro@open-dsi.fr>
10 * Copyright (C) 2015       Jean-François Ferry     <jfefe@aternatik.fr>
11 * Copyright (C) 2015       Marcos García           <marcosgdf@gmail.com>
12 * Copyright (C) 2015       Raphaël Doursenaud      <rdoursenaud@gpcsolutions.fr>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27
28/**
29 *  \file       htdocs/societe/contact.php
30 *  \ingroup    societe
31 *  \brief      Page of contacts of thirdparties
32 */
33
34require '../main.inc.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
43require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
44require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
45if (!empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
46
47$langs->loadLangs(array("companies", "commercial", "bills", "banks", "users"));
48if (!empty($conf->categorie->enabled)) $langs->load("categories");
49if (!empty($conf->incoterm->enabled)) $langs->load("incoterm");
50if (!empty($conf->notification->enabled)) $langs->load("mails");
51
52$mesg = ''; $error = 0; $errors = array();
53
54$action		= (GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view');
55$cancel     = GETPOST('cancel', 'alpha');
56$backtopage = GETPOST('backtopage', 'alpha');
57$confirm	= GETPOST('confirm');
58$socid = GETPOST('socid', 'int') ?GETPOST('socid', 'int') : GETPOST('id', 'int');
59if ($user->socid) $socid = $user->socid;
60if (empty($socid) && $action == 'view') $action = 'create';
61
62$object = new Societe($db);
63$extrafields = new ExtraFields($db);
64
65// fetch optionals attributes and labels
66$extrafields->fetch_name_optionals_label($object->table_element);
67
68// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
69$hookmanager->initHooks(array('thirdpartycontact', 'globalcard'));
70
71if ($object->fetch($socid) <= 0 && $action == 'view')
72{
73	$langs->load("errors");
74	print($langs->trans('ErrorRecordNotFound'));
75	exit;
76}
77
78// Get object canvas (By default, this is not defined, so standard usage of dolibarr)
79$canvas = $object->canvas ? $object->canvas : GETPOST("canvas");
80$objcanvas = null;
81if (!empty($canvas))
82{
83	require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
84	$objcanvas = new Canvas($db, $action);
85	$objcanvas->getCanvas('thirdparty', 'card', $canvas);
86}
87
88// Security check
89$result = restrictedArea($user, 'societe', $socid, '&societe', '', 'fk_soc', 'rowid', 0);
90if (empty($user->rights->societe->contact->lire)) accessforbidden();
91
92
93/*
94 * Actions
95 */
96
97$parameters = array('id'=>$socid, 'objcanvas'=>$objcanvas);
98$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
99if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
100
101if (empty($reshook))
102{
103	if ($cancel)
104	{
105		$action = '';
106		if (!empty($backtopage))
107		{
108			header("Location: ".$backtopage);
109			exit;
110		}
111	}
112
113	// Selection of new fields
114	include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
115}
116
117
118/*
119 *  View
120 */
121
122$form = new Form($db);
123$formfile = new FormFile($db);
124$formadmin = new FormAdmin($db);
125$formcompany = new FormCompany($db);
126
127if ($socid > 0 && empty($object->id))
128{
129	$result = $object->fetch($socid);
130	if ($result <= 0) dol_print_error('', $object->error);
131}
132
133$title = $langs->trans("ThirdParty");
134if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title = $object->name." - ".$langs->trans('Card');
135$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
136llxHeader('', $title, $help_url);
137
138$countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
139
140
141if (!empty($object->id)) $res = $object->fetch_optionals();
142//if ($res < 0) { dol_print_error($db); exit; }
143
144
145$head = societe_prepare_head($object);
146
147print dol_get_fiche_head($head, 'contact', $langs->trans("ThirdParty"), 0, 'company');
148
149$linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
150
151dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom', '', '', 0, '', '', 'arearefnobottom');
152
153print dol_get_fiche_end();
154
155print '<br>';
156
157if ($action != 'presend')
158{
159	// Contacts list
160	if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
161	{
162		$result = show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id);
163	}
164}
165
166// End of page
167llxFooter();
168$db->close();
169