* Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2005-2011 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/compta/deplacement/fiche.php * \brief Page to show a trip card */ require("../../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/core/lib/trip.lib.php"); require_once(DOL_DOCUMENT_ROOT."/compta/deplacement/class/deplacement.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php"); if ($conf->projet->enabled) { require_once(DOL_DOCUMENT_ROOT."/core/lib/project.lib.php"); require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php"); } $langs->load("trips"); // Security check $id = GETPOST('id'); if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'deplacement', $id,''); $action = GETPOST('action'); $confirm = GETPOST('confirm'); $mesg = ''; $object = new Deplacement($db); /* * Actions */ if ($action == 'validate' && $user->rights->deplacement->creer) { $object->fetch($id); if ($object->statut == 0) { $result = $object->setStatut(1); if ($result > 0) { Header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); exit; } else { $mesg=$object->error; } } } /* if ($action == 'unblock' && $user->rights->deplacement->unvalidate) { $object->fetch($id); if ($object->fk_statut == '1') // Not blocked... { $mesg='
'.$langs->trans("Error").'
'; $action=''; $error++; } else { $result = $object->fetch($id); $object->fk_statut = '1'; $result = $object->update($user); if ($result > 0) { Header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); exit; } else { $mesg=$object->error; } } }*/ if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->deplacement->supprimer) { $result=$object->delete($id); if ($result >= 0) { Header("Location: index.php"); exit; } else { $mesg=$object->error; } } if ($action == 'add' && $user->rights->deplacement->creer) { if (! $_POST["cancel"]) { $error=0; $object->date = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); $object->km = $_POST["km"]; $object->type = $_POST["type"]; $object->socid = $_POST["socid"]; $object->fk_user = $_POST["fk_user"]; $object->note_private = $_POST["note_private"]; $object->note_public = $_POST["note_public"]; $object->statut = 0; if (! $object->date) { $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")); $error++; } if ($object->type == '-1') // Otherwise it is TF_LUNCH,... { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")).'
'; $error++; } if (! ($object->fk_user > 0)) { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Person")).'
'; $error++; } if (! $error) { $id = $object->create($user); if ($id > 0) { Header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); exit; } else { $mesg=$object->error; $action='create'; } } else { $action='create'; } } else { Header("Location: index.php"); exit; } } // Update record if ($action == 'update' && $user->rights->deplacement->creer) { if (empty($_POST["cancel"])) { $result = $object->fetch($id); $object->date = dol_mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); $object->km = $_POST["km"]; $object->type = $_POST["type"]; $object->fk_user = $_POST["fk_user"]; $object->socid = $_POST["socid"]; $object->note_private = $_POST["note_private"]; $object->note_public = $_POST["note_public"]; $result = $object->update($user); if ($result > 0) { Header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); exit; } else { $mesg=$object->error; } } else { Header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); exit; } } // Set into a project if ($action == 'classin') { $object->fetch($id); $result=$object->setProject($_POST['projectid']); if ($result < 0) dol_print_error($db, $object->error); } // Set fields if ($action == 'setdated') { $dated=dol_mktime($_POST['datedhour'], $_POST['datedmin'], $_POST['datedsec'], $_POST['datedmonth'], $_POST['datedday'], $_POST['datedyear']); $object->fetch($id); $result=$object->setValueFrom('dated',$dated,'','','date'); if ($result < 0) dol_print_error($db, $object->error); } if ($action == 'setkm') { $object->fetch($id); $result=$object->setValueFrom('km',GETPOST('km')); if ($result < 0) dol_print_error($db, $object->error); } if ($action == 'setnote_public') { $object->fetch($id); $result=$object->setValueFrom('note_public',GETPOST('note_public')); if ($result < 0) dol_print_error($db, $object->error); } if ($action == 'setnote') { $object->fetch($id); $result=$object->setValueFrom('note',GETPOST('note')); if ($result < 0) dol_print_error($db, $object->error); } /* * View */ llxHeader(); $form = new Form($db); /* * Action create */ if ($action == 'create') { print_fiche_titre($langs->trans("NewTrip")); dol_htmloutput_errors($mesg); $datec = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); print '
' . "\n"; print ''; print ''; print ''; print ""; print ''; print ""; print ''; print ""; print ''; // Km print ''; // Company print ""; print ''; // Public note print ''; print ''; print ''; // Private note if (! $user->societe_id) { print ''; print ''; print ''; } print '
'.$langs->trans("Type").''; print $form->select_type_fees(GETPOST("type"),'type',1); print '
'.$langs->trans("Person").''; print $form->select_users(GETPOST("fk_user"),'fk_user',1); print '
'.$langs->trans("Date").''; print $form->select_date($datec?$datec:-1,'','','','','add',1,1); print '
'.$langs->trans("FeesKilometersOrAmout").'
'.$langs->trans("CompanyVisited").''; print $form->select_societes(GETPOST("socid"),'socid','',1); print '
'.$langs->trans('NotePublic').''; require_once(DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php"); $doleditor=new DolEditor('note_public',GETPOST('note_public'),600,200,'dolibarr_notes','In',false,true,true,ROWS_8,100); print $doleditor->Create(1); print '
'.$langs->trans('NotePrivate').''; require_once(DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php"); $doleditor=new DolEditor('note_private',GETPOST('note_private'),600,200,'dolibarr_notes','In',false,true,true,ROWS_8,100); print $doleditor->Create(1); print '
'; print '
    '; print ''; } else if ($id) { $result = $object->fetch($id); if ($result > 0) { dol_htmloutput_mesg($mesg); $head = trip_prepare_head($object); dol_fiche_head($head, 'card', $langs->trans("TripCard"), 0, 'trip'); if ($action == 'edit' && $user->rights->deplacement->creer) { $soc = new Societe($db); if ($object->socid) { $soc->fetch($object->socid); } print '' . "\n"; print ''; print ''; print ''; print ''; // Ref print ""; print ''; // Type print ""; print ''; // Who print ""; print ''; // Date print ''; // Km print ''; // Where print ""; print ''; // Public note print ''; print '"; // Private note if (! $user->societe_id) { print ''; print '"; } print '
'.$langs->trans("Ref").''; print $object->ref; print '
'.$langs->trans("Type").''; print $form->select_type_fees($_POST["type"]?$_POST["type"]:$object->type,'type',0); print '
'.$langs->trans("Person").''; print $form->select_users($_POST["fk_user"]?$_POST["fk_user"]:$object->fk_user,'fk_user',0); print '
'.$langs->trans("Date").''; print $form->select_date($object->date,'','','','','update'); print '
'.$langs->trans("FeesKilometersOrAmout").''; print ''; print '
'.$langs->trans("CompanyVisited").''; print $form->select_societes($soc->id,'socid','',1); print '
'.$langs->trans("NotePublic").''; require_once(DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php"); $doleditor=new DolEditor('note_public',$object->note_public,600,200,'dolibarr_notes','In',false,true,true,ROWS_8,'100'); print $doleditor->Create(1); print "
'.$langs->trans("NotePrivate").''; require_once(DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php"); $doleditor=new DolEditor('note_private',$object->note_private,600,200,'dolibarr_notes','In',false,true,true,ROWS_8,'100'); print $doleditor->Create(1); print "
'; print '
  '; print ''; print '
'; print ''; print ''; } else { /* * Confirmation de la suppression du deplacement */ if ($action == 'delete') { $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("DeleteTrip"),$langs->trans("ConfirmDeleteTrip"),"confirm_delete"); if ($ret == 'html') print '
'; } $soc = new Societe($db); if ($object->socid) $soc->fetch($object->socid); print ''; // Ref print ''; // Type print ''; // Who print ''; // Date print ''; // Km/Price print '"; // Where print ''; print ''; // Project if ($conf->projet->enabled) { $langs->load('projects'); print ''; print ''; print ''; } // Statut print ''; // Public note print '"; // Private note if (! $user->societe_id) { print '"; } print "
'.$langs->trans("Ref").''; print $form->showrefnav($object,'id','',1,'rowid','ref',''); print '
'; print $form->editfieldkey("Type",'type',$langs->trans($object->type),$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'select:types_fees'); print ''; print $form->editfieldval("Type",'type',$langs->trans($object->type),$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'select:types_fees'); print '
'.$langs->trans("Person").''; $userfee=new User($db); $userfee->fetch($object->fk_user); print $userfee->getNomUrl(1); print '
'; print $form->editfieldkey("Date",'dated',$object->date,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'datepicker'); print ''; print $form->editfieldval("Date",'dated',$object->date,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'datepicker'); print '
'; print $form->editfieldkey("FeesKilometersOrAmout",'km',$object->km,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'numeric:6'); print ''; print $form->editfieldval("FeesKilometersOrAmout",'km',$object->km,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'numeric:6'); print "
'.$langs->trans("CompanyVisited").''; if ($soc->id) print $soc->getNomUrl(1); print '
'; print ''; if ($action != 'classify' && $user->rights->deplacement->creer) { print ''; } print '
'; print $langs->trans('Project'); print 'id.'">'; print img_edit($langs->trans('SetProject'),1); print '
'; print '
'; if ($action == 'classify') { $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'projectid'); } else { $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'none'); } print '
'.$langs->trans("Status").''.$object->getLibStatut(4).'
'; print $form->editfieldkey("NotePublic",'note_public',$object->note_public,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'ckeditor:dolibarr_notes:600:180'); print ''; print $form->editfieldval("NotePublic",'note_public',$object->note_public,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'ckeditor:dolibarr_notes:600:180'); print "
'; print $form->editfieldkey("NotePrivate",'note',$object->note_private,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'ckeditor:dolibarr_notes:600:180'); print ''; print $form->editfieldval("NotePrivate",'note',$object->note_private,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'ckeditor:dolibarr_notes:600:180'); print "
"; print ''; /* * Barre d'actions */ print '
'; if ($object->statut == 0) // if blocked... { if ($user->rights->deplacement->creer) { print ''.$langs->trans('Validate').''; } else { print ''.$langs->trans('Validate').''; } } if ($user->rights->deplacement->creer) { print ''.$langs->trans('Modify').''; } else { print ''.$langs->trans('Modify').''; } if ($user->rights->deplacement->supprimer) { print ''.$langs->trans('Delete').''; } else { print ''.$langs->trans('Delete').''; } print '
'; } } else { dol_print_error($db); } } $db->close(); llxFooter(); ?>