dolibarr  16.0.1
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 $result = restrictedArea($user, 'contrat', $id, '');
58 
59 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
60 $sortfield = GETPOST('sortfield', 'aZ09comma');
61 $sortorder = GETPOST('sortorder', 'aZ09comma');
62 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
63 if (empty($page) || $page == -1) {
64  $page = 0;
65 } // If $page is not defined, or '' or -1
66 $offset = $limit * $page;
67 $pageprev = $page - 1;
68 $pagenext = $page + 1;
69 if (!$sortfield) {
70  $sortfield = 'a.datep,a.id';
71 }
72 if (!$sortorder) {
73  $sortorder = 'DESC,DESC';
74 }
75 
76 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
77 $hookmanager->initHooks(array('agendacontract', 'globalcard'));
78 
79 
80 /*
81  * Actions
82  */
83 
84 $parameters = array('id'=>$id);
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  // Cancel
92  if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
93  header("Location: ".$backtopage);
94  exit;
95  }
96 
97  // Purge search criteria
98  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
99  $actioncode = '';
100  $search_agenda_label = '';
101  }
102 }
103 
104 
105 
106 
107 /*
108  * View
109  */
110 
111 $form = new Form($db);
112 $formfile = new FormFile($db);
113 if (!empty($conf->project->enabled)) {
114  $formproject = new FormProjets($db);
115 }
116 
117 if ($id > 0) {
118  // Load object modContract
119  $module = (!empty($conf->global->CONTRACT_ADDON) ? $conf->global->CONTRACT_ADDON : 'mod_contract_serpis');
120  if (substr($module, 0, 13) == 'mod_contract_' && substr($module, -3) == 'php') {
121  $module = substr($module, 0, dol_strlen($module) - 4);
122  }
123  $result = dol_include_once('/core/modules/contract/'.$module.'.php');
124  if ($result > 0) {
125  $modCodeContract = new $module();
126  }
127 
128  require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
129  require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
130 
131  $object = new Contrat($db);
132  $result = $object->fetch($id);
133  $object->fetch_thirdparty();
134 
135  $title = $langs->trans("Agenda");
136  if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contractrefonly/', $conf->global->MAIN_HTML_TITLE) && $object->ref) {
137  $title = $object->ref." - ".$title;
138  }
139  llxHeader('', $title);
140 
141  if (!empty($conf->notification->enabled)) {
142  $langs->load("mails");
143  }
144  $head = contract_prepare_head($object);
145 
146  print dol_get_fiche_head($head, 'agenda', $langs->trans("Contract"), -1, 'contract');
147 
148  $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
149 
150  $morehtmlref = '';
151  if (!empty($modCodeContract->code_auto)) {
152  $morehtmlref .= $object->ref;
153  } else {
154  $morehtmlref .= $form->editfieldkey("", 'ref', $object->ref, $object, $user->rights->contrat->creer, 'string', '', 0, 3);
155  $morehtmlref .= $form->editfieldval("", 'ref', $object->ref, $object, $user->rights->contrat->creer, 'string', '', 0, 2);
156  }
157 
158  $permtoedit = 0;
159 
160  $morehtmlref .= '<div class="refidno">';
161  // Ref customer
162  $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, $permtoedit, 'string', '', 0, 1);
163  $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, $permtoedit, 'string', '', null, null, '', 1, 'getFormatedCustomerRef');
164  // Ref supplier
165  $morehtmlref .= '<br>';
166  $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $permtoedit, 'string', '', 0, 1);
167  $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $permtoedit, 'string', '', null, null, '', 1, 'getFormatedSupplierRef');
168  // Thirdparty
169  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
170  if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
171  $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/contrat/list.php?socid='.$object->thirdparty->id.'&search_name='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherContracts").'</a>)';
172  }
173  // Project
174  if (!empty($conf->project->enabled)) {
175  $langs->load("projects");
176  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
177  if ($user->rights->contrat->creer) {
178  if ($action != 'classify') {
179  //$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a>';
180  $morehtmlref .= ' : ';
181  }
182  if ($action == 'classify') {
183  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
184  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
185  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
186  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
187  $morehtmlref .= $formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
188  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
189  $morehtmlref .= '</form>';
190  } else {
191  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1);
192  }
193  } else {
194  if (!empty($object->fk_project)) {
195  $proj = new Project($db);
196  $proj->fetch($object->fk_project);
197  $morehtmlref .= ' : '.$proj->getNomUrl(1);
198  if ($proj->title) {
199  $morehtmlref .= ' - '.$proj->title;
200  }
201  } else {
202  $morehtmlref .= '';
203  }
204  }
205  }
206  $morehtmlref .= '</div>';
207 
208  dol_banner_tab($object, 'id', $linkback, 1, 'ref', 'none', $morehtmlref);
209 
210  print '<div class="fichecenter">';
211 
212  print '<div class="underbanner clearboth"></div>';
213 
214  $object->info($id);
215  dol_print_object_info($object, 1);
216 
217  print '</div>';
218 
219  print dol_get_fiche_end();
220 
221 
222 
223  // Actions buttons
224 
225  /*$objthirdparty=$object;
226  $objcon=new stdClass();
227 
228  $out='';
229  $permok=$user->rights->agenda->myactions->create;
230  if ((! empty($objthirdparty->id) || ! empty($objcon->id)) && $permok)
231  {
232  //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
233  if (get_class($objthirdparty) == 'Societe') $out.='&amp;socid='.$objthirdparty->id;
234  $out.=(! empty($objcon->id)?'&amp;contactid='.$objcon->id:'').'&amp;backtopage=1&amp;percentage=-1';
235  //$out.=$langs->trans("AddAnAction").' ';
236  //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
237  //$out.="</a>";
238  }*/
239 
240 
241  //print '<div class="tabsAction">';
242  //print '</div>';
243 
244 
245  $newcardbutton = '';
246  if (isModEnabled('agenda')) {
247  if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create)) {
248  $backtopage = $_SERVER['PHP_SELF'].'?id='.$object->id;
249  $out = '&origin='.$object->element.'&originid='.$object->id.'&backtopage='.urlencode($backtopage);
250  $newcardbutton .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out);
251  }
252  }
253 
254  if (isModEnabled('agenda') && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
255  print '<br>';
256 
257  $param = '&id='.$id;
258  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
259  $param .= '&contextpage='.$contextpage;
260  }
261  if ($limit > 0 && $limit != $conf->liste_limit) {
262  $param .= '&limit='.$limit;
263  }
264 
265  print load_fiche_titre($langs->trans("ActionsOnContract"), $newcardbutton, '');
266  //print_barre_liste($langs->trans("ActionsOnCompany"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $newcardbutton, '', 0, 1, 1);
267 
268  // List of all actions
269  $filters = array();
270  $filters['search_agenda_label'] = $search_agenda_label;
271 
272  // TODO Replace this with same code than into list.php
273  show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder);
274  }
275 }
276 
277 llxFooter();
278 $db->close();
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
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.
dol_print_object_info($object, $usetable=0)
Show informations on an object TODO Move this into html.formother.
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
Class to manage contracts.
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).
contract_prepare_head(Contrat $object)
Prepare array with list of tabs.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form...
Class to manage projects.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
Class to manage building of HTML components.
Class to offer components to list and upload files.
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.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
isModEnabled($module)
Is Dolibarr module enabled.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:73