dolibarr  19.0.0-dev
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 // Load object
67 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
68 
69 // Security check
70 //if ($user->socid > 0) accessforbidden();
71 //if ($user->socid > 0) $socid = $user->socid;
72 //$result = restrictedArea($user, 'website', $id);
73 if (!$user->hasRight('website', 'read')) {
74  accessforbidden('NotAllowed');
75 }
76 
77 // Permissions
78 $permissionnote = $user->hasRight('website', 'write'); // Used by the include of actions_setnotes.inc.php
79 $permissiondellink = $user->hasRight('website', 'write'); // Used by the include of actions_dellink.inc.php
80 $permissiontoadd = $user->hasRight('website', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
81 $permissiontodelete = $user->hasRight('website', 'delete');
82 
83 
84 /*
85  * Actions
86  */
87 
88 $parameters = array();
89 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
90 if ($reshook < 0) {
91  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
92 }
93 
94 if (empty($reshook)) {
95  $error = 0;
96 
97  $permissiontoadd = $user->hasRight('website', 'write');
98  $permissiontodelete = $user->hasRight('website', 'delete');
99  $backurlforlist = dol_buildpath('/website/websiteaccount_list.php', 1);
100 
101  // Actions cancel, add, update or delete
102  include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
103 
104  // Actions when printing a doc from card
105  include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
106 
107  // Actions to send emails
108  $triggersendname = 'WEBSITEACCOUNT_SENTBYMAIL';
109  $autocopy = 'MAIN_MAIL_AUTOCOPY_WEBSITEACCOUNT_TO';
110  $trackid = 'websiteaccount'.$object->id;
111  include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
112 }
113 
114 
115 /*
116  * View
117  */
118 
119 $form = new Form($db);
120 $formfile = new FormFile($db);
121 
122 llxHeader('', 'WebsiteAccount', '');
123 
124 // Part to create
125 if ($action == 'create') {
126  print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("WebsiteAccount")));
127 
128  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
129  print '<input type="hidden" name="token" value="'.newToken().'">';
130  print '<input type="hidden" name="action" value="add">';
131  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
132 
133  print dol_get_fiche_head();
134 
135  print '<table class="border centpercent">'."\n";
136 
137  // Common attributes
138  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
139 
140  // Other attributes
141  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
142 
143  print '</table>'."\n";
144 
145  print dol_get_fiche_end();
146 
147  print $form->buttonsSaveCancel("Create");
148 
149  print '</form>';
150 }
151 
152 // Part to edit record
153 if (($id || $ref) && $action == 'edit') {
154  print load_fiche_titre($langs->trans("WebsiteAccount"));
155 
156  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
157  print '<input type="hidden" name="action" value="update">';
158  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
159  print '<input type="hidden" name="id" value="'.$object->id.'">';
160 
161  print dol_get_fiche_head();
162 
163  print '<table class="border centpercent">'."\n";
164 
165  // Common attributes
166  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
167 
168  // Other attributes
169  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
170 
171  print '</table>';
172 
173  print dol_get_fiche_end();
174 
175  print $form->buttonsSaveCancel();
176 
177  print '</form>';
178 }
179 
180 // Part to show record
181 if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
182  if ($object->fk_soc > 0 && empty($socid)) {
183  $socid = $object->fk_soc;
184  }
185 
186  $res = $object->fetch_optionals();
187 
188  $head = websiteaccountPrepareHead($object);
189  print dol_get_fiche_head($head, 'card', $langs->trans("WebsiteAccount"), -1, 'websiteaccount@website');
190 
191  $formconfirm = '';
192 
193  // Confirmation to delete
194  if ($action == 'delete') {
195  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteWebsiteAccount'), $langs->trans('ConfirmDeleteWebsiteAccount'), 'confirm_delete', '', 0, 1);
196  }
197 
198  // Call Hook formConfirm
199  $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
200  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
201  if (empty($reshook)) {
202  $formconfirm .= $hookmanager->resPrint;
203  } elseif ($reshook > 0) {
204  $formconfirm = $hookmanager->resPrint;
205  }
206 
207  // Print form confirm
208  print $formconfirm;
209 
210 
211  // Object card
212  // ------------------------------------------------------------
213  $linkback = '';
214  if ($socid) {
215  $linkback = '<a href="'.DOL_URL_ROOT.'/societe/website.php?socid='.$socid.'&restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToListForThirdParty").'</a>';
216  }
217  if ($fk_website) {
218  $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>';
219  }
220 
221  $morehtmlref = '<div class="refidno">';
222  /*
223  // Ref bis
224  $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->hasRight('website', 'write'), 'string', '', 0, 1);
225  $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->hasRight('website', 'write'), 'string', '', null, null, '', 1);
226  // Thirdparty
227  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
228  // Project
229  if (isModEnabled('project'))
230  {
231  $langs->load("projects");
232  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
233  if ($user->hasRight('website', 'write'))
234  {
235  if ($action != 'classify')
236  {
237  $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
238  if ($action == 'classify') {
239  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
240  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
241  $morehtmlref.='<input type="hidden" name="action" value="classin">';
242  $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
243  $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
244  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
245  $morehtmlref.='</form>';
246  } else {
247  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
248  }
249  }
250  } else {
251  if (!empty($object->fk_project)) {
252  $proj = new Project($db);
253  $proj->fetch($object->fk_project);
254  $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
255  $morehtmlref.=$proj->ref;
256  $morehtmlref.='</a>';
257  } else {
258  $morehtmlref.='';
259  }
260  }
261  }
262  */
263  $morehtmlref .= '</div>';
264 
265  if ($socid > 0) {
266  $object->next_prev_filter = 'te.fk_soc = '.((int) $socid);
267  }
268 
269  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
270 
271 
272  print '<div class="fichecenter">';
273  print '<div class="fichehalfleft">';
274  print '<div class="underbanner clearboth"></div>';
275  print '<table class="border centpercent">'."\n";
276 
277  // Common attributes
278  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
279 
280  // Other attributes
281  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
282 
283  print '</table>';
284  print '</div>';
285  print '</div>';
286  print '</div>';
287 
288  print '<div class="clearboth"></div><br>';
289 
290  print dol_get_fiche_end();
291 
292 
293  // Buttons for actions
294  if ($action != 'presend' && $action != 'editline') {
295  print '<div class="tabsAction">'."\n";
296  $parameters = array();
297  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
298  if ($reshook < 0) {
299  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
300  }
301 
302  if (empty($reshook)) {
303  // Send
304  if (empty($user->socid)) {
305  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";
306  }
307 
308  if ($user->hasRight('website', 'write')) {
309  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";
310  }
311 
312  /*
313  if ($user->rights->sellyoursaas->create)
314  {
315  if ($object->status == 1)
316  {
317  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";
318  }
319  else
320  {
321  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";
322  }
323  }
324  */
325 
326  if ($permissiontodelete) {
327  print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
328  }
329  }
330  print '</div>'."\n";
331  }
332 
333 
334  // Select mail models is same action as presend
335  if (GETPOST('modelselected')) {
336  $action = 'presend';
337  }
338 
339  if ($action != 'presend') {
340  print '<div class="fichecenter"><div class="fichehalfleft">';
341  print '<a name="builddoc"></a>'; // ancre
342 
343  print '</div><div class="fichehalfright">';
344 
345  /*
346  $MAXEVENT = 10;
347 
348  // List of actions on element
349  include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
350  $formactions = new FormActions($db);
351  $somethingshown = $formactions->showactions($object, $object->element, $socid, 1, '', $MAXEVENT);
352  */
353 
354  print '</div></div>';
355  }
356 
357  // Presend form
358  $modelmail = 'websiteaccount';
359  $defaulttopic = 'Information';
360  $diroutput = $conf->website->dir_output;
361  $trackid = 'websiteaccount'.$object->id;
362 
363  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
364 }
365 
366 // End of page
367 llxFooter();
368 $db->close();
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage standard extra fields.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class for SocieteAccount.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
$formconfirm
if ($action == 'delbookkeepingyear') {
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
websiteaccountPrepareHead($object)
Prepare array of tabs for SocieteAccount.