dolibarr  16.0.5
agenda.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 require "../main.inc.php";
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
30 if (!empty($conf->project->enabled)) {
31  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
32  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
33 }
34 
35 // Load translation files required by the page
36 $langs->loadLangs(array("companies", "contracts"));
37 
38 if (GETPOST('actioncode', 'array')) {
39  $actioncode = GETPOST('actioncode', 'array', 3);
40  if (!count($actioncode)) {
41  $actioncode = '0';
42  }
43 } else {
44  $actioncode = GETPOST("actioncode", "alpha", 3) ?GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT));
45 }
46 $search_agenda_label = GETPOST('search_agenda_label');
47 
48 $action = GETPOST('action', 'alpha');
49 $confirm = GETPOST('confirm', 'alpha');
50 $id = GETPOST('id', 'int');
51 $ref = GETPOST('ref', 'alpha');
52 
53 // Security check
54 if ($user->socid) {
55  $socid = $user->socid;
56 }
57 
58 // Security check
59 $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
60 $fieldtype = (!empty($id) ? 'rowid' : 'ref');
61 $result = restrictedArea($user, 'contrat', $fieldvalue, '', '', '', $fieldtype);
62 
63 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
64 $sortfield = GETPOST('sortfield', 'aZ09comma');
65 $sortorder = GETPOST('sortorder', 'aZ09comma');
66 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
67 if (empty($page) || $page == -1) {
68  $page = 0;
69 } // If $page is not defined, or '' or -1
70 $offset = $limit * $page;
71 $pageprev = $page - 1;
72 $pagenext = $page + 1;
73 if (!$sortfield) {
74  $sortfield = 'a.datep,a.id';
75 }
76 if (!$sortorder) {
77  $sortorder = 'DESC,DESC';
78 }
79 
80 
81 $object = new Contrat($db);
82 
83 if ($id > 0 || !empty($ref)) {
84  $result = $object->fetch($id, $ref);
85 }
86 
87 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
88 $hookmanager->initHooks(array('agendacontract', 'globalcard'));
89 
90 
91 /*
92  * Actions
93  */
94 
95 $parameters = array('id' => $id, 'ref' => $ref);
96 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
97 if ($reshook < 0) {
98  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
99 }
100 
101 if (empty($reshook)) {
102  // Cancel
103  if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
104  header("Location: ".$backtopage);
105  exit;
106  }
107 
108  // Purge search criteria
109  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
110  $actioncode = '';
111  $search_agenda_label = '';
112  }
113 }
114 
115 
116 /*
117  * View
118  */
119 
120 $form = new Form($db);
121 $formfile = new FormFile($db);
122 if (!empty($conf->project->enabled)) {
123  $formproject = new FormProjets($db);
124 }
125 
126 if ($object->id > 0) {
127  // Load object modContract
128  $module = (!empty($conf->global->CONTRACT_ADDON) ? $conf->global->CONTRACT_ADDON : 'mod_contract_serpis');
129  if (substr($module, 0, 13) == 'mod_contract_' && substr($module, -3) == 'php') {
130  $module = substr($module, 0, dol_strlen($module) - 4);
131  }
132  $result = dol_include_once('/core/modules/contract/'.$module.'.php');
133  if ($result > 0) {
134  $modCodeContract = new $module();
135  }
136 
137  require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
138  require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
139 
140  $object->fetch_thirdparty();
141 
142  $title = $langs->trans("Agenda");
143  if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contractrefonly/', $conf->global->MAIN_HTML_TITLE) && $object->ref) {
144  $title = $object->ref." - ".$title;
145  }
146  llxHeader('', $title);
147 
148  if (!empty($conf->notification->enabled)) {
149  $langs->load("mails");
150  }
151  $head = contract_prepare_head($object);
152 
153  print dol_get_fiche_head($head, 'agenda', $langs->trans("Contract"), -1, 'contract');
154 
155  $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
156 
157  $morehtmlref = '';
158  if (!empty($modCodeContract->code_auto)) {
159  $morehtmlref .= $object->ref;
160  } else {
161  $morehtmlref .= $form->editfieldkey("", 'ref', $object->ref, $object, $user->rights->contrat->creer, 'string', '', 0, 3);
162  $morehtmlref .= $form->editfieldval("", 'ref', $object->ref, $object, $user->rights->contrat->creer, 'string', '', 0, 2);
163  }
164 
165  $permtoedit = 0;
166 
167  $morehtmlref .= '<div class="refidno">';
168  // Ref customer
169  $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, $permtoedit, 'string', '', 0, 1);
170  $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, $permtoedit, 'string', '', null, null, '', 1, 'getFormatedCustomerRef');
171  // Ref supplier
172  $morehtmlref .= '<br>';
173  $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $permtoedit, 'string', '', 0, 1);
174  $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $permtoedit, 'string', '', null, null, '', 1, 'getFormatedSupplierRef');
175  // Thirdparty
176  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
177  if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
178  $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/contrat/list.php?socid='.$object->thirdparty->id.'&search_name='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherContracts").'</a>)';
179  }
180  // Project
181  if (!empty($conf->project->enabled)) {
182  $langs->load("projects");
183  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
184  if ($user->rights->contrat->creer) {
185  if ($action != 'classify') {
186  //$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a>';
187  $morehtmlref .= ' : ';
188  }
189  if ($action == 'classify') {
190  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
191  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
192  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
193  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
194  $morehtmlref .= $formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
195  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
196  $morehtmlref .= '</form>';
197  } else {
198  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1);
199  }
200  } else {
201  if (!empty($object->fk_project)) {
202  $proj = new Project($db);
203  $proj->fetch($object->fk_project);
204  $morehtmlref .= ' : '.$proj->getNomUrl(1);
205  if ($proj->title) {
206  $morehtmlref .= ' - '.$proj->title;
207  }
208  } else {
209  $morehtmlref .= '';
210  }
211  }
212  }
213  $morehtmlref .= '</div>';
214 
215  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref);
216 
217  print '<div class="fichecenter">';
218 
219  print '<div class="underbanner clearboth"></div>';
220 
221  $object->info($object->id);
222  dol_print_object_info($object, 1);
223 
224  print '</div>';
225 
226  print dol_get_fiche_end();
227 
228 
229 
230  // Actions buttons
231 
232  /*$objthirdparty=$object;
233  $objcon=new stdClass();
234 
235  $out='';
236  $permok=$user->rights->agenda->myactions->create;
237  if ((! empty($objthirdparty->id) || ! empty($objcon->id)) && $permok)
238  {
239  //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
240  if (get_class($objthirdparty) == 'Societe') $out.='&amp;socid='.$objthirdparty->id;
241  $out.=(! empty($objcon->id)?'&amp;contactid='.$objcon->id:'').'&amp;backtopage=1&amp;percentage=-1';
242  //$out.=$langs->trans("AddAnAction").' ';
243  //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
244  //$out.="</a>";
245  }*/
246 
247 
248  //print '<div class="tabsAction">';
249  //print '</div>';
250 
251 
252  $newcardbutton = '';
253  if (isModEnabled('agenda')) {
254  if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create)) {
255  $backtopage = $_SERVER['PHP_SELF'].'?id='.$object->id;
256  $out = '&origin='.$object->element.'&originid='.$object->id.'&backtopage='.urlencode($backtopage);
257  $newcardbutton .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out);
258  }
259  }
260 
261  if (isModEnabled('agenda') && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
262  print '<br>';
263 
264  $param = '&id='.$object->id;
265  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
266  $param .= '&contextpage='.$contextpage;
267  }
268  if ($limit > 0 && $limit != $conf->liste_limit) {
269  $param .= '&limit='.$limit;
270  }
271 
272  print load_fiche_titre($langs->trans("ActionsOnContract"), $newcardbutton, '');
273  //print_barre_liste($langs->trans("ActionsOnCompany"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $newcardbutton, '', 0, 1, 1);
274 
275  // List of all actions
276  $filters = array();
277  $filters['search_agenda_label'] = $search_agenda_label;
278 
279  // TODO Replace this with same code than into list.php
280  show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder);
281  }
282 }
283 
284 llxFooter();
285 $db->close();
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
Project
Class to manage projects.
Definition: project.class.php:35
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
dol_include_once
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
Definition: functions.lib.php:1033
FormProjets
Class to manage building of HTML components.
Definition: html.formprojet.class.php:30
$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
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
dolGetButtonTitle
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
Definition: functions.lib.php:10605
show_actions_done
show_actions_done($conf, $langs, $db, $filterobj, $objcon='', $noprint=0, $actioncode='', $donetodo='done', $filters=array(), $sortfield='a.datep, a.id', $sortorder='DESC', $module='')
Show html area with actions (done or not, ignore the name of function).
Definition: company.lib.php:1389
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
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
Contrat
Class to manage contracts.
Definition: contrat.class.php:43
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_print_object_info
dol_print_object_info($object, $usetable=0)
Show informations on an object TODO Move this into html.formother.
Definition: functions2.lib.php:205
contract_prepare_head
contract_prepare_head(Contrat $object)
Prepare array with list of tabs.
Definition: contract.lib.php:31
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