dolibarr  16.0.5
websiteaccount_card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
24 // Load Dolibarr environment
25 require '../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/website/lib/websiteaccount.lib.php';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array("website", "other"));
33 
34 // Get parameters
35 $id = GETPOST('id', 'int');
36 $ref = GETPOST('ref', 'alpha');
37 $action = GETPOST('action', 'aZ09');
38 $confirm = GETPOST('confirm', 'alpha');
39 $cancel = GETPOST('cancel', 'aZ09');
40 $backtopage = GETPOST('backtopage', 'alpha');
41 
42 // Initialize technical objects
43 $object = new SocieteAccount($db);
44 $extrafields = new ExtraFields($db);
45 $diroutputmassaction = $conf->website->dir_output.'/temp/massgeneration/'.$user->id;
46 $hookmanager->initHooks(array('websiteaccountcard')); // Note that conf->hooks_modules contains array
47 
48 // Fetch optionals attributes and labels
49 $extrafields->fetch_name_optionals_label($object->table_element);
50 
51 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
52 
53 // Initialize array of search criterias
54 $search_all = GETPOST("search_all", 'alpha');
55 $search = array();
56 foreach ($object->fields as $key => $val) {
57  if (GETPOST('search_'.$key, 'alpha')) {
58  $search[$key] = GETPOST('search_'.$key, 'alpha');
59  }
60 }
61 
62 if (empty($action) && empty($id) && empty($ref)) {
63  $action = 'view';
64 }
65 
66 // Security check - Protection if external user
67 //if ($user->socid > 0) accessforbidden();
68 //if ($user->socid > 0) $socid = $user->socid;
69 //$result = restrictedArea($user, 'website', $id);
70 
71 $permissionnote = $user->rights->websiteaccount->write; // Used by the include of actions_setnotes.inc.php
72 $permissiondellink = $user->rights->websiteaccount->write; // Used by the include of actions_dellink.inc.php
73 $permissiontoadd = $user->rights->websiteaccount->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
74 
75 // Load object
76 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
77 
78 
79 
80 /*
81  * Actions
82  */
83 
84 $parameters = array();
85 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
86 if ($reshook < 0) {
87  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
88 }
89 
90 if (empty($reshook)) {
91  $error = 0;
92 
93  $permissiontoadd = $user->rights->website->write;
94  $permissiontodelete = $user->rights->website->delete;
95  $backurlforlist = dol_buildpath('/website/websiteaccount_list.php', 1);
96 
97  // Actions cancel, add, update or delete
98  include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
99 
100  // Actions when printing a doc from card
101  include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
102 
103  // Actions to send emails
104  $triggersendname = 'WEBSITEACCOUNT_SENTBYMAIL';
105  $autocopy = 'MAIN_MAIL_AUTOCOPY_WEBSITEACCOUNT_TO';
106  $trackid = 'websiteaccount'.$object->id;
107  include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
108 }
109 
110 
111 /*
112  * View
113  */
114 
115 $form = new Form($db);
116 $formfile = new FormFile($db);
117 
118 llxHeader('', 'WebsiteAccount', '');
119 
120 // Part to create
121 if ($action == 'create') {
122  print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("WebsiteAccount")));
123 
124  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
125  print '<input type="hidden" name="token" value="'.newToken().'">';
126  print '<input type="hidden" name="action" value="add">';
127  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
128 
129  print dol_get_fiche_head();
130 
131  print '<table class="border centpercent">'."\n";
132 
133  // Common attributes
134  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
135 
136  // Other attributes
137  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
138 
139  print '</table>'."\n";
140 
141  print dol_get_fiche_end();
142 
143  print $form->buttonsSaveCancel("Create");
144 
145  print '</form>';
146 }
147 
148 // Part to edit record
149 if (($id || $ref) && $action == 'edit') {
150  print load_fiche_titre($langs->trans("WebsiteAccount"));
151 
152  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
153  print '<input type="hidden" name="action" value="update">';
154  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
155  print '<input type="hidden" name="id" value="'.$object->id.'">';
156 
157  print dol_get_fiche_head();
158 
159  print '<table class="border centpercent">'."\n";
160 
161  // Common attributes
162  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
163 
164  // Other attributes
165  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
166 
167  print '</table>';
168 
169  print dol_get_fiche_end();
170 
171  print $form->buttonsSaveCancel();
172 
173  print '</form>';
174 }
175 
176 // Part to show record
177 if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
178  if ($object->fk_soc > 0 && empty($socid)) {
179  $socid = $object->fk_soc;
180  }
181 
182  $res = $object->fetch_optionals();
183 
184  $head = websiteaccountPrepareHead($object);
185  print dol_get_fiche_head($head, 'card', $langs->trans("WebsiteAccount"), -1, 'websiteaccount@website');
186 
187  $formconfirm = '';
188 
189  // Confirmation to delete
190  if ($action == 'delete') {
191  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteWebsiteAccount'), $langs->trans('ConfirmDeleteWebsiteAccount'), 'confirm_delete', '', 0, 1);
192  }
193 
194  // Call Hook formConfirm
195  $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
196  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
197  if (empty($reshook)) {
198  $formconfirm .= $hookmanager->resPrint;
199  } elseif ($reshook > 0) {
200  $formconfirm = $hookmanager->resPrint;
201  }
202 
203  // Print form confirm
204  print $formconfirm;
205 
206 
207  // Object card
208  // ------------------------------------------------------------
209  $linkback = '';
210  if ($socid) {
211  $linkback = '<a href="'.DOL_URL_ROOT.'/societe/website.php?socid='.$socid.'&restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToListForThirdParty").'</a>';
212  }
213  if ($fk_website) {
214  $linkback = '<a href="'.DOL_URL_ROOT.'/website/website_card.php?fk_website='.$fk_website.'&restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
215  }
216 
217  $morehtmlref = '<div class="refidno">';
218  /*
219  // Ref bis
220  $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->website->creer, 'string', '', 0, 1);
221  $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->website->creer, 'string', '', null, null, '', 1);
222  // Thirdparty
223  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
224  // Project
225  if (! empty($conf->project->enabled))
226  {
227  $langs->load("projects");
228  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
229  if ($user->rights->website->creer)
230  {
231  if ($action != 'classify')
232  {
233  $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
234  if ($action == 'classify') {
235  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
236  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
237  $morehtmlref.='<input type="hidden" name="action" value="classin">';
238  $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
239  $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
240  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
241  $morehtmlref.='</form>';
242  } else {
243  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
244  }
245  }
246  } else {
247  if (! empty($object->fk_project)) {
248  $proj = new Project($db);
249  $proj->fetch($object->fk_project);
250  $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
251  $morehtmlref.=$proj->ref;
252  $morehtmlref.='</a>';
253  } else {
254  $morehtmlref.='';
255  }
256  }
257  }
258  */
259  $morehtmlref .= '</div>';
260 
261  if ($socid > 0) {
262  $object->next_prev_filter = 'te.fk_soc = '.((int) $socid);
263  }
264 
265  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
266 
267 
268  print '<div class="fichecenter">';
269  print '<div class="fichehalfleft">';
270  print '<div class="underbanner clearboth"></div>';
271  print '<table class="border centpercent">'."\n";
272 
273  // Common attributes
274  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
275 
276  // Other attributes
277  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
278 
279  print '</table>';
280  print '</div>';
281  print '</div>';
282  print '</div>';
283 
284  print '<div class="clearboth"></div><br>';
285 
286  print dol_get_fiche_end();
287 
288 
289  // Buttons for actions
290  if ($action != 'presend' && $action != 'editline') {
291  print '<div class="tabsAction">'."\n";
292  $parameters = array();
293  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
294  if ($reshook < 0) {
295  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
296  }
297 
298  if (empty($reshook)) {
299  // Send
300  if (empty($user->socid)) {
301  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>'."\n";
302  }
303 
304  if ($user->rights->website->write) {
305  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a></div>'."\n";
306  }
307 
308  /*
309  if ($user->rights->sellyoursaas->create)
310  {
311  if ($object->status == 1)
312  {
313  print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=disable&token='.newToken().'">'.$langs->trans("Disable").'</a></div>'."\n";
314  }
315  else
316  {
317  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=enable&token='.newToken().'">'.$langs->trans("Enable").'</a></div>'."\n";
318  }
319  }
320  */
321 
322  if ($user->rights->website->delete) {
323  print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans('Delete').'</a></div>'."\n";
324  }
325  }
326  print '</div>'."\n";
327  }
328 
329 
330  // Select mail models is same action as presend
331  if (GETPOST('modelselected')) {
332  $action = 'presend';
333  }
334 
335  if ($action != 'presend') {
336  print '<div class="fichecenter"><div class="fichehalfleft">';
337  print '<a name="builddoc"></a>'; // ancre
338 
339  print '</div><div class="fichehalfright">';
340 
341  /*
342  $MAXEVENT = 10;
343 
344  // List of actions on element
345  include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
346  $formactions = new FormActions($db);
347  $somethingshown = $formactions->showactions($object, $object->element, $socid, 1, '', $MAXEVENT);
348  */
349 
350  print '</div></div>';
351  }
352 
353  // Presend form
354  $modelmail = 'websiteaccount';
355  $defaulttopic = 'Information';
356  $diroutput = $conf->website->dir_output;
357  $trackid = 'websiteaccount'.$object->id;
358 
359  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
360 }
361 
362 // End of page
363 llxFooter();
364 $db->close();
websiteaccountPrepareHead
websiteaccountPrepareHead($object)
Prepare array of tabs for SocieteAccount.
Definition: websiteaccount.lib.php:30
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
SocieteAccount
Class for SocieteAccount.
Definition: societeaccount.class.php:35
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
$formconfirm
$formconfirm
if ($action == 'delbookkeepingyear') {
Definition: listbyaccount.php:576
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59