dolibarr  17.0.0
target_agenda.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.'/contact/class/contact.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/webhook/class/target.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/webhook/lib/webhook_target.lib.php';
31 
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array('other'));
35 
36 // Get parameters
37 $id = GETPOST('id', 'int');
38 $ref = GETPOST('ref', 'alpha');
39 $action = GETPOST('action', 'aZ09');
40 $cancel = GETPOST('cancel', 'aZ09');
41 $backtopage = GETPOST('backtopage', 'alpha');
42 
43 if (GETPOST('actioncode', 'array')) {
44  $actioncode = GETPOST('actioncode', 'array', 3);
45  if (!count($actioncode)) {
46  $actioncode = '0';
47  }
48 } else {
49  $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));
50 }
51 
52 $search_agenda_label = GETPOST('search_agenda_label');
53 
54 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
55 $sortfield = GETPOST('sortfield', 'aZ09comma');
56 $sortorder = GETPOST('sortorder', 'aZ09comma');
57 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
58 if (empty($page) || $page == -1) {
59  // If $page is not defined, or '' or -1
60  $page = 0;
61 }
62 $offset = $limit * $page;
63 $pageprev = $page - 1;
64 $pagenext = $page + 1;
65 if (!$sortfield) {
66  $sortfield = 'a.datep,a.id';
67 }
68 if (!$sortorder) {
69  $sortorder = 'DESC,DESC';
70 }
71 
72 // Initialize technical objects
73 $object = new Target($db);
74 $extrafields = new ExtraFields($db);
75 $diroutputmassaction = $conf->webhook->dir_output.'/temp/massgeneration/'.$user->id;
76 $hookmanager->initHooks(array('targetagenda', 'globalcard')); // Note that conf->hooks_modules contains array
77 
78 // Fetch optionals attributes and labels
79 $extrafields->fetch_name_optionals_label($object->table_element);
80 
81 // Load object
82 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
83 if ($id > 0 || !empty($ref)) {
84  $upload_dir = $conf->webhook->multidir_output[!empty($object->entity) ? $object->entity : $conf->entity]."/".$object->id;
85 }
86 
87 // There is several ways to check permission.
88 // Set $enablepermissioncheck to 1 to enable a minimum low level of checks
89 $enablepermissioncheck = 0;
90 if ($enablepermissioncheck) {
91  $permissiontoread = $user->rights->webhook->target->read;
92  $permissiontoadd = $user->rights->webhook->target->write;
93 } else {
94  $permissiontoread = 1;
95  $permissiontoadd = 1;
96 }
97 
98 // Security check (enable the most restrictive one)
99 //if ($user->socid > 0) accessforbidden();
100 //if ($user->socid > 0) $socid = $user->socid;
101 //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
102 //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
103 if (!isModEnabled('webhook') || !$permissiontoread) {
104  accessforbidden();
105 }
106 
107 
108 /*
109  * Actions
110  */
111 
112 $parameters = array('id'=>$id);
113 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
114 if ($reshook < 0) {
115  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
116 }
117 
118 if (empty($reshook)) {
119  // Cancel
120  if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
121  header("Location: ".$backtopage);
122  exit;
123  }
124 
125  // Purge search criteria
126  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
127  $actioncode = '';
128  $search_agenda_label = '';
129  }
130 }
131 
132 
133 
134 /*
135  * View
136  */
137 
138 $form = new Form($db);
139 
140 if ($object->id > 0) {
141  $title = $langs->trans("Agenda");
142  //if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title;
143  $help_url = 'EN:Module_Agenda_En';
144  llxHeader('', $title, $help_url);
145 
146  if (isModEnabled('notification')) {
147  $langs->load("mails");
148  }
149  $head = targetPrepareHead($object);
150 
151 
152  print dol_get_fiche_head($head, 'agenda', $langs->trans("Target"), -1, $object->picto);
153 
154  // Object card
155  // ------------------------------------------------------------
156  $linkback = '<a href="'.dol_buildpath('/webhook/target_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
157 
158  $morehtmlref = '<div class="refidno">';
159  /*
160  // Ref customer
161  $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
162  $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
163  // Thirdparty
164  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
165  // Project
166  if (isModEnabled('projet')) {
167  $langs->load("projects");
168  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
169  if ($permissiontoadd) {
170  if ($action != 'classify') {
171  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
172  }
173  $morehtmlref.=' : ';
174  if ($action == 'classify') {
175  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
176  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
177  $morehtmlref.='<input type="hidden" name="action" value="classin">';
178  $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
179  $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
180  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
181  $morehtmlref.='</form>';
182  } else {
183  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
184  }
185  } else {
186  if (!empty($object->fk_project)) {
187  $proj = new Project($db);
188  $proj->fetch($object->fk_project);
189  $morehtmlref .= ': '.$proj->getNomUrl();
190  } else {
191  $morehtmlref .= '';
192  }
193  }
194  }*/
195  $morehtmlref .= '</div>';
196 
197 
198  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
199 
200  print '<div class="fichecenter">';
201  print '<div class="underbanner clearboth"></div>';
202 
203  $object->info($object->id);
204  dol_print_object_info($object, 1);
205 
206  print '</div>';
207 
208  print dol_get_fiche_end();
209 
210 
211 
212  // Actions buttons
213 
214  $objthirdparty = $object;
215  $objcon = new stdClass();
216 
217  $out = '&origin='.urlencode($object->element.'@'.$object->module).'&originid='.urlencode($object->id);
218  $urlbacktopage = $_SERVER['PHP_SELF'].'?id='.$object->id;
219  $out .= '&backtopage='.urlencode($urlbacktopage);
220  $permok = $user->rights->agenda->myactions->create;
221  if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
222  //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
223  if (get_class($objthirdparty) == 'Societe') {
224  $out .= '&socid='.urlencode($objthirdparty->id);
225  }
226  $out .= (!empty($objcon->id) ? '&contactid='.urlencode($objcon->id) : '').'&percentage=-1';
227  //$out.=$langs->trans("AddAnAction").' ';
228  //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
229  //$out.="</a>";
230  }
231 
232 
233  print '<div class="tabsAction">';
234 
235  if (isModEnabled('agenda')) {
236  if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create)) {
237  print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'">'.$langs->trans("AddAction").'</a>';
238  } else {
239  print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans("AddAction").'</a>';
240  }
241  }
242 
243  print '</div>';
244 
245  if (isModEnabled('agenda') && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
246  $param = '&id='.$object->id.'&socid='.$socid;
247  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
248  $param .= '&contextpage='.urlencode($contextpage);
249  }
250  if ($limit > 0 && $limit != $conf->liste_limit) {
251  $param .= '&limit='.urlencode($limit);
252  }
253 
254 
255  //print load_fiche_titre($langs->trans("ActionsOnTarget"), '', '');
256 
257  // List of all actions
258  $filters = array();
259  $filters['search_agenda_label'] = $search_agenda_label;
260 
261  // TODO Replace this with same code than into list.php
262  show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder, $object->module);
263  }
264 }
265 
266 // End of page
267 llxFooter();
268 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
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:517
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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:2073
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
targetPrepareHead
targetPrepareHead($object)
Prepare array of tabs for Target.
Definition: webhook_target.lib.php:29
llxHeader
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
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:1445
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:1849
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2045
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
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:418
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Target
Class for Target.
Definition: target.class.php:33
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
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8443
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
Definition: security.lib.php:1086