dolibarr  13.0.2
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->projet->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 {
40  $actioncode = GETPOST('actioncode', 'array', 3);
41  if (!count($actioncode)) $actioncode = '0';
42 } else {
43  $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));
44 }
45 $search_agenda_label = GETPOST('search_agenda_label');
46 
47 $action = GETPOST('action', 'alpha');
48 $confirm = GETPOST('confirm', 'alpha');
49 $id = GETPOST('id', 'int');
50 $ref = GETPOST('ref', 'alpha');
51 
52 // Security check
53 if ($user->socid) $socid = $user->socid;
54 $result = restrictedArea($user, 'contrat', $id, '');
55 
56 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
57 $sortfield = GETPOST("sortfield", 'alpha');
58 $sortorder = GETPOST("sortorder", 'alpha');
59 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
60 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
61 $offset = $limit * $page;
62 $pageprev = $page - 1;
63 $pagenext = $page + 1;
64 if (!$sortfield) $sortfield = 'a.datep,a.id';
65 if (!$sortorder) $sortorder = 'DESC,DESC';
66 
67 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
68 $hookmanager->initHooks(array('agendacontract', 'globalcard'));
69 
70 
71 /*
72  * Actions
73  */
74 
75 $parameters = array('id'=>$id);
76 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
77 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
78 
79 if (empty($reshook))
80 {
81  // Cancel
82  if (GETPOST('cancel', 'alpha') && !empty($backtopage))
83  {
84  header("Location: ".$backtopage);
85  exit;
86  }
87 
88  // Purge search criteria
89  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
90  {
91  $actioncode = '';
92  $search_agenda_label = '';
93  }
94 }
95 
96 
97 
98 
99 /*
100  * View
101  */
102 
103 $form = new Form($db);
104 $formfile = new FormFile($db);
105 if (!empty($conf->projet->enabled)) $formproject = new FormProjets($db);
106 
107 if ($id > 0)
108 {
109  // Load object modContract
110  $module = (!empty($conf->global->CONTRACT_ADDON) ? $conf->global->CONTRACT_ADDON : 'mod_contract_serpis');
111  if (substr($module, 0, 13) == 'mod_contract_' && substr($module, -3) == 'php')
112  {
113  $module = substr($module, 0, dol_strlen($module) - 4);
114  }
115  $result = dol_include_once('/core/modules/contract/'.$module.'.php');
116  if ($result > 0)
117  {
118  $modCodeContract = new $module();
119  }
120 
121  require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
122  require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
123 
124  $object = new Contrat($db);
125  $result = $object->fetch($id);
126  $object->fetch_thirdparty();
127 
128  $title = $langs->trans("Agenda");
129  if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contractrefonly/', $conf->global->MAIN_HTML_TITLE) && $object->ref) $title = $object->ref." - ".$title;
130  llxHeader('', $title);
131 
132  if (!empty($conf->notification->enabled)) $langs->load("mails");
133  $head = contract_prepare_head($object);
134 
135  print dol_get_fiche_head($head, 'agenda', $langs->trans("Contract"), -1, 'contract');
136 
137  $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
138 
139  $morehtmlref = '';
140  if (!empty($modCodeContract->code_auto)) {
141  $morehtmlref .= $object->ref;
142  } else {
143  $morehtmlref .= $form->editfieldkey("", 'ref', $object->ref, $object, $user->rights->contrat->creer, 'string', '', 0, 3);
144  $morehtmlref .= $form->editfieldval("", 'ref', $object->ref, $object, $user->rights->contrat->creer, 'string', '', 0, 2);
145  }
146 
147  $permtoedit = 0;
148 
149  $morehtmlref .= '<div class="refidno">';
150  // Ref customer
151  $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, $permtoedit, 'string', '', 0, 1);
152  $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, $permtoedit, 'string', '', null, null, '', 1, 'getFormatedCustomerRef');
153  // Ref supplier
154  $morehtmlref .= '<br>';
155  $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $permtoedit, 'string', '', 0, 1);
156  $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $permtoedit, 'string', '', null, null, '', 1, 'getFormatedSupplierRef');
157  // Thirdparty
158  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
159  if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/contrat/list.php?socid='.$object->thirdparty->id.'&search_name='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherContracts").'</a>)';
160  // Project
161  if (!empty($conf->projet->enabled))
162  {
163  $langs->load("projects");
164  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
165  if ($user->rights->contrat->creer)
166  {
167  if ($action != 'classify') {
168  //$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a>';
169  $morehtmlref .= ' : ';
170  }
171  if ($action == 'classify') {
172  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
173  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
174  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
175  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
176  $morehtmlref .= $formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
177  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
178  $morehtmlref .= '</form>';
179  } else {
180  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1);
181  }
182  } else {
183  if (!empty($object->fk_project)) {
184  $proj = new Project($db);
185  $proj->fetch($object->fk_project);
186  $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
187  $morehtmlref .= $proj->ref;
188  $morehtmlref .= '</a>';
189  } else {
190  $morehtmlref .= '';
191  }
192  }
193  }
194  $morehtmlref .= '</div>';
195 
196  dol_banner_tab($object, 'id', $linkback, 1, 'ref', 'none', $morehtmlref);
197 
198  print '<div class="fichecenter">';
199 
200  print '<div class="underbanner clearboth"></div>';
201 
202  $object->info($id);
203  dol_print_object_info($object, 1);
204 
205  print '</div>';
206 
208 
209 
210 
211  // Actions buttons
212 
213  /*$objthirdparty=$object;
214  $objcon=new stdClass();
215 
216  $out='';
217  $permok=$user->rights->agenda->myactions->create;
218  if ((! empty($objthirdparty->id) || ! empty($objcon->id)) && $permok)
219  {
220  //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
221  if (get_class($objthirdparty) == 'Societe') $out.='&amp;socid='.$objthirdparty->id;
222  $out.=(! empty($objcon->id)?'&amp;contactid='.$objcon->id:'').'&amp;backtopage=1&amp;percentage=-1';
223  //$out.=$langs->trans("AddAnAction").' ';
224  //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
225  //$out.="</a>";
226  }*/
227 
228 
229  //print '<div class="tabsAction">';
230  //print '</div>';
231 
232 
233  $newcardbutton = '';
234  if (!empty($conf->agenda->enabled))
235  {
236  if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create))
237  {
238  $newcardbutton .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out);
239  }
240  }
241 
242  if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read)))
243  {
244  print '<br>';
245 
246  $param = '&id='.$id;
247  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage;
248  if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit;
249 
250  print load_fiche_titre($langs->trans("ActionsOnContract"), $newcardbutton, '');
251  //print_barre_liste($langs->trans("ActionsOnCompany"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $newcardbutton, '', 0, 1, 1);
252 
253  // List of all actions
254  $filters = array();
255  $filters['search_agenda_label'] = $search_agenda_label;
256 
257  // TODO Replace this with same code than into list.php
258  show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder);
259  }
260 }
261 
262 llxFooter();
263 $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.
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.
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.
llxHeader()
Empty header.
Definition: wrapper.php:45
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.
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.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
Class to offer components to list and upload files.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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:59