PageRenderTime 119ms CodeModel.GetById 73ms app.highlight 39ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/compta/deplacement/fiche.php

https://bitbucket.org/speedealing/speedealing
PHP | 582 lines | 390 code | 95 blank | 97 comment | 91 complexity | 4073a22df004ed4882add4fde030306b MD5 | raw file
  1<?php
  2/* Copyright (C) 2003		Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3 * Copyright (C) 2004-2012	Laurent Destailleur  <eldy@users.sourceforge.net>
  4 * Copyright (C) 2005-2012	Regis Houssin        <regis.houssin@capnetworks.com>
  5 * Copyright (C) 2012		Juanjo Menent        <jmenent@2byte.es>
  6 *
  7 * This program is free software; you can redistribute it and/or modify
  8 * it under the terms of the GNU General Public License as published by
  9 * the Free Software Foundation; either version 3 of the License, or
 10 * (at your option) any later version.
 11 *
 12 * This program is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15 * GNU General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU General Public License
 18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 19 */
 20
 21/**
 22 *  \file       	htdocs/compta/deplacement/fiche.php
 23 *  \brief      	Page to show a trip card
 24 */
 25
 26require '../../main.inc.php';
 27require_once DOL_DOCUMENT_ROOT.'/core/lib/trip.lib.php';
 28require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
 29require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
 30if (! empty($conf->projet->enabled))
 31{
 32    require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
 33    require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
 34}
 35
 36$langs->load("trips");
 37
 38
 39// Security check
 40$id = GETPOST('id','int');
 41if ($user->societe_id) $socid=$user->societe_id;
 42$result = restrictedArea($user, 'deplacement', $id,'');
 43
 44$action = GETPOST('action','alpha');
 45$confirm = GETPOST('confirm','alpha');
 46
 47$mesg = '';
 48
 49$object = new Deplacement($db);
 50
 51// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
 52$hookmanager->initHooks(array('tripsandexpensescard'));
 53
 54
 55/*
 56 * Actions
 57*/
 58if ($action == 'validate' && $user->rights->deplacement->creer)
 59{
 60    $object->fetch($id);
 61    if ($object->statut == 0)
 62    {
 63        $result = $object->setStatut(1);
 64        if ($result > 0)
 65        {
 66            header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
 67            exit;
 68        }
 69        else
 70        {
 71            $mesg=$object->error;
 72        }
 73    }
 74}
 75
 76/*
 77else if ($action == 'unblock' && $user->rights->deplacement->unvalidate)
 78{
 79    $object->fetch($id);
 80    if ($object->fk_statut == '1') 	// Not blocked...
 81    {
 82        $mesg='<div class="error">'.$langs->trans("Error").'</div>';
 83        $action='';
 84        $error++;
 85    }
 86    else
 87    {
 88        $result = $object->fetch($id);
 89
 90        $object->fk_statut	= '1';
 91
 92        $result = $object->update($user);
 93
 94        if ($result > 0)
 95        {
 96            header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
 97            exit;
 98        }
 99        else
100        {
101            $mesg=$object->error;
102        }
103    }
104}*/
105
106else if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->deplacement->supprimer)
107{
108    $result=$object->delete($id);
109    if ($result >= 0)
110    {
111        header("Location: index.php");
112        exit;
113    }
114    else
115    {
116        $mesg=$object->error;
117    }
118}
119
120else if ($action == 'add' && $user->rights->deplacement->creer)
121{
122    if (! GETPOST('cancel','alpha'))
123    {
124        $error=0;
125
126        $object->date			= dol_mktime(12, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int'));
127        $object->km				= GETPOST('km','int');
128        $object->type			= GETPOST('type','alpha');
129        $object->socid			= GETPOST('socid','int');
130        $object->fk_user		= GETPOST('fk_user','int');
131        $object->note_private	= GETPOST('note_private','alpha');
132        $object->note_public	= GETPOST('note_public','alpha');
133        $object->statut     	= 0;
134
135        if (! $object->date)
136        {
137            $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date"));
138            $error++;
139        }
140        if ($object->type == '-1') 	// Otherwise it is TF_LUNCH,...
141        {
142            $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")).'</div>';
143            $error++;
144        }
145        if (! ($object->fk_user > 0))
146        {
147            $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Person")).'</div>';
148            $error++;
149        }
150
151        if (! $error)
152        {
153            $id = $object->create($user);
154
155            if ($id > 0)
156            {
157                header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
158                exit;
159            }
160            else
161            {
162                $mesg=$object->error;
163                $action='create';
164            }
165        }
166        else
167        {
168            $action='create';
169        }
170    }
171    else
172    {
173        header("Location: index.php");
174        exit;
175    }
176}
177
178// Update record
179else if ($action == 'update' && $user->rights->deplacement->creer)
180{
181    if (! GETPOST('cancel','alpha'))
182    {
183        $result = $object->fetch($id);
184
185        $object->date			= dol_mktime(12, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int'));
186        $object->km				= GETPOST('km','int');
187        $object->type			= GETPOST('type','alpha');
188        $object->socid			= GETPOST('socid','int');
189        $object->fk_user		= GETPOST('fk_user','int');
190        $object->note_private	= GETPOST('note_private','alpha');
191        $object->note_public	= GETPOST('note_public','alpha');
192
193        $result = $object->update($user);
194
195        if ($result > 0)
196        {
197            header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
198            exit;
199        }
200        else
201        {
202            $mesg=$object->error;
203        }
204    }
205    else
206    {
207        header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
208        exit;
209    }
210}
211
212// Set into a project
213else if ($action == 'classin' && $user->rights->deplacement->creer)
214{
215    $object->fetch($id);
216    $result=$object->setProject(GETPOST('projectid','int'));
217    if ($result < 0) dol_print_error($db, $object->error);
218}
219
220// Set fields
221else if ($action == 'setdated' && $user->rights->deplacement->creer)
222{
223    $dated=dol_mktime(GETPOST('datedhour','int'), GETPOST('datedmin','int'), GETPOST('datedsec','int'), GETPOST('datedmonth','int'), GETPOST('datedday','int'), GETPOST('datedyear','int'));
224    $object->fetch($id);
225    $result=$object->setValueFrom('dated',$dated,'','','date');
226    if ($result < 0) dol_print_error($db, $object->error);
227}
228else if ($action == 'setkm' && $user->rights->deplacement->creer)
229{
230    $object->fetch($id);
231    $result=$object->setValueFrom('km',GETPOST('km','int'));
232    if ($result < 0) dol_print_error($db, $object->error);
233}
234else if ($action == 'setnote_public' && $user->rights->deplacement->creer)
235{
236    $object->fetch($id);
237    $result=$object->setValueFrom('note_public',GETPOST('note_public','alpha'));
238    if ($result < 0) dol_print_error($db, $object->error);
239}
240else if ($action == 'setnote' && $user->rights->deplacement->creer)
241{
242    $object->fetch($id);
243    $result=$object->setValueFrom('note',GETPOST('note','alpha'));
244    if ($result < 0) dol_print_error($db, $object->error);
245}
246
247
248/*
249 * View
250*/
251
252llxHeader();
253
254$form = new Form($db);
255
256/*
257 * Action create
258*/
259if ($action == 'create')
260{
261    //WYSIWYG Editor
262    require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
263
264    print_fiche_titre($langs->trans("NewTrip"));
265
266    dol_htmloutput_errors($mesg);
267
268    $datec = dol_mktime(12, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int'));
269
270    print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
271    print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
272    print '<input type="hidden" name="action" value="add">';
273
274    print '<table class="border" width="100%">';
275
276    print "<tr>";
277    print '<td width="25%" class="fieldrequired">'.$langs->trans("Type").'</td><td>';
278    print $form->select_type_fees(GETPOST('type','int'),'type',1);
279    print '</td></tr>';
280
281    print "<tr>";
282    print '<td class="fieldrequired">'.$langs->trans("Person").'</td><td>';
283    print $form->select_users(GETPOST('fk_user','int'),'fk_user',1);
284    print '</td></tr>';
285
286    print "<tr>";
287    print '<td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
288    print $form->select_date($datec?$datec:-1,'','','','','add',1,1);
289    print '</td></tr>';
290
291    // Km
292    print '<tr><td class="fieldrequired">'.$langs->trans("FeesKilometersOrAmout").'</td><td><input name="km" size="10" value="' . GETPOST("km") . '"></td></tr>';
293
294    // Company
295    print "<tr>";
296    print '<td>'.$langs->trans("CompanyVisited").'</td><td>';
297    print $form->select_company(GETPOST('socid','int'),'socid','',1);
298    print '</td></tr>';
299
300    // Public note
301    print '<tr>';
302    print '<td class="border" valign="top">'.$langs->trans('NotePublic').'</td>';
303    print '<td valign="top" colspan="2">';
304
305    $doleditor = new DolEditor('note_public', GETPOST('note_public', 'alpha'), 600, 200, 'dolibarr_notes', 'In', false, true, true, ROWS_8, 100);
306    print $doleditor->Create(1);
307
308    print '</td></tr>';
309
310    // Private note
311    if (! $user->societe_id)
312    {
313        print '<tr>';
314        print '<td class="border" valign="top">'.$langs->trans('NotePrivate').'</td>';
315        print '<td valign="top" colspan="2">';
316
317        $doleditor = new DolEditor('note_private', GETPOST('note_private', 'alpha'), 600, 200, 'dolibarr_notes', 'In', false, true, true, ROWS_8, 100);
318        print $doleditor->Create(1);
319
320        print '</td></tr>';
321    }
322
323    // Other attributes
324    $parameters=array('colspan' => ' colspan="2"');
325    $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
326
327    print '</table>';
328
329    print '<br><center><input class="button" type="submit" value="'.$langs->trans("Save").'"> &nbsp; &nbsp; ';
330    print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"></center';
331
332    print '</form>';
333}
334else if ($id)
335{
336    $result = $object->fetch($id);
337    if ($result > 0)
338    {
339        dol_htmloutput_mesg($mesg);
340
341        $head = trip_prepare_head($object);
342
343        dol_fiche_head($head, 'card', $langs->trans("TripCard"), 0, 'trip');
344
345        if ($action == 'edit' && $user->rights->deplacement->creer)
346        {
347            //WYSIWYG Editor
348            require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
349
350            $soc = new Societe($db);
351            if ($object->socid)
352            {
353                $soc->fetch($object->socid);
354            }
355
356            print '<form name="update" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
357            print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
358            print '<input type="hidden" name="action" value="update">';
359            print '<input type="hidden" name="id" value="'.$id.'">';
360
361            print '<table class="border" width="100%">';
362
363            // Ref
364            print "<tr>";
365            print '<td width="20%">'.$langs->trans("Ref").'</td><td>';
366            print $object->ref;
367            print '</td></tr>';
368
369            // Type
370            print "<tr>";
371            print '<td class="fieldrequired">'.$langs->trans("Type").'</td><td>';
372            print $form->select_type_fees(GETPOST('type','int')?GETPOST('type','int'):$object->type,'type',0);
373            print '</td></tr>';
374
375            // Who
376            print "<tr>";
377            print '<td class="fieldrequired">'.$langs->trans("Person").'</td><td>';
378            print $form->select_users(GETPOST('fk_user','int')?GETPOST('fk_user','int'):$object->fk_user,'fk_user',0);
379            print '</td></tr>';
380
381            // Date
382            print '<tr><td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
383            print $form->select_date($object->date,'','','','','update');
384            print '</td></tr>';
385
386            // Km
387            print '<tr><td class="fieldrequired">'.$langs->trans("FeesKilometersOrAmout").'</td><td>';
388            print '<input name="km" class="flat" size="10" value="'.$object->km.'">';
389            print '</td></tr>';
390
391            // Where
392            print "<tr>";
393            print '<td>'.$langs->trans("CompanyVisited").'</td><td>';
394            print $form->select_company($soc->id,'socid','',1);
395            print '</td></tr>';
396
397            // Public note
398            print '<tr><td valign="top">'.$langs->trans("NotePublic").'</td>';
399            print '<td valign="top" colspan="3">';
400
401            $doleditor = new DolEditor('note_public', $object->note_public, 600, 200, 'dolibarr_notes', 'In', false, true, true, ROWS_8, '100');
402            print $doleditor->Create(1);
403
404            print "</td></tr>";
405
406            // Private note
407            if (! $user->societe_id)
408            {
409                print '<tr><td valign="top">'.$langs->trans("NotePrivate").'</td>';
410                print '<td valign="top" colspan="3">';
411
412                $doleditor = new DolEditor('note_private', $object->note_private, 600, 200, 'dolibarr_notes', 'In', false, true, true, ROWS_8, '100');
413                print $doleditor->Create(1);
414
415                print "</td></tr>";
416            }
417
418            // Other attributes
419            $parameters=array('colspan' => ' colspan="3"');
420            $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
421
422            print '</table>';
423
424            print '<br><center><input type="submit" class="button" value="'.$langs->trans("Save").'"> &nbsp; ';
425            print '<input type="submit" name="cancel" class="button" value="'.$langs->trans("Cancel").'">';
426            print '</center>';
427
428            print '</form>';
429
430            print '</div>';
431        }
432        else
433        {
434            /*
435             * Confirmation de la suppression du deplacement
436            */
437            if ($action == 'delete')
438            {
439                $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("DeleteTrip"),$langs->trans("ConfirmDeleteTrip"),"confirm_delete");
440                if ($ret == 'html') print '<br>';
441            }
442
443            $soc = new Societe($db);
444            if ($object->socid) $soc->fetch($object->socid);
445
446            print '<table class="border" width="100%">';
447
448            $linkback = '<a href="'.DOL_URL_ROOT.'/compta/deplacement/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
449
450            // Ref
451            print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td>';
452            print $form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'ref', '');
453            print '</td></tr>';
454
455            // Type
456            print '<tr><td>';
457            print $form->editfieldkey("Type",'type',$langs->trans($object->type),$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'select:types_fees');
458            print '</td><td>';
459            print $form->editfieldval("Type",'type',$langs->trans($object->type),$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'select:types_fees');
460            print '</td></tr>';
461
462            // Who
463            print '<tr><td>'.$langs->trans("Person").'</td><td>';
464            $userfee=new User($db);
465            $userfee->fetch($object->fk_user);
466            print $userfee->getNomUrl(1);
467            print '</td></tr>';
468
469            // Date
470            print '<tr><td>';
471            print $form->editfieldkey("Date",'dated',$object->date,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'datepicker');
472            print '</td><td>';
473            print $form->editfieldval("Date",'dated',$object->date,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'datepicker');
474            print '</td></tr>';
475
476            // Km/Price
477            print '<tr><td valign="top">';
478            print $form->editfieldkey("FeesKilometersOrAmout",'km',$object->km,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'numeric:6');
479            print '</td><td>';
480            print $form->editfieldval("FeesKilometersOrAmout",'km',$object->km,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'numeric:6');
481            print "</td></tr>";
482
483            // Where
484            print '<tr><td>'.$langs->trans("CompanyVisited").'</td>';
485            print '<td>';
486            if ($soc->id) print $soc->getNomUrl(1);
487            print '</td></tr>';
488
489            // Project
490            if (! empty($conf->projet->enabled))
491            {
492                $langs->load('projects');
493                print '<tr>';
494                print '<td>';
495
496                print '<table class="nobordernopadding" width="100%"><tr><td>';
497                print $langs->trans('Project');
498                print '</td>';
499                if ($action != 'classify' && $user->rights->deplacement->creer)
500                {
501                    print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=classify&amp;id='.$object->id.'">';
502                    print img_edit($langs->trans('SetProject'),1);
503                    print '</a></td>';
504                }
505                print '</tr></table>';
506                print '</td><td colspan="3">';
507                if ($action == 'classify')
508                {
509                    $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'projectid');
510                }
511                else
512                {
513                    $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'none');
514                }
515                print '</td>';
516                print '</tr>';
517            }
518
519            // Statut
520            print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
521
522            // Other attributes
523            $parameters=array('colspan' => ' colspan="3"');
524            $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
525
526            print "</table><br>";
527
528            // Notes
529            $blocname = 'notes';
530            $title = $langs->trans('Notes');
531            include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
532
533            print '</div>';
534
535            /*
536             * Barre d'actions
537            */
538
539            print '<div class="tabsAction">';
540
541            if ($object->statut == 0) 	// if blocked...
542            {
543                if ($user->rights->deplacement->creer)
544                {
545                    print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=validate&id='.$id.'">'.$langs->trans('Validate').'</a>';
546                }
547                else
548                {
549                    print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Validate').'</a>';
550                }
551            }
552
553            if ($user->rights->deplacement->creer)
554            {
555                print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&id='.$id.'">'.$langs->trans('Modify').'</a>';
556            }
557            else
558            {
559                print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Modify').'</a>';
560            }
561            if ($user->rights->deplacement->supprimer)
562            {
563                print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&id='.$id.'">'.$langs->trans('Delete').'</a>';
564            }
565            else
566            {
567                print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Delete').'</a>';
568            }
569
570            print '</div>';
571        }
572    }
573    else
574    {
575        dol_print_error($db);
576    }
577}
578
579$db->close();
580
581llxFooter();
582?>