* * 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 3 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/hrm/establishment/card.php * \brief Page to show an establishment */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/hrm.lib.php'; require_once DOL_DOCUMENT_ROOT.'/hrm/class/establishment.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; // Load translation files required by the page $langs->loadLangs(array('admin', 'hrm')); // Security check if (! $user->admin) accessforbidden(); $error=0; $action = GETPOST('action', 'alpha'); $cancel = GETPOST('cancel', 'alpha'); $confirm = GETPOST('confirm', 'alpha'); $id = GETPOST('id', 'int'); // List of status static $tmpstatus2label=array( '0'=>'CloseEtablishment', '1'=>'OpenEtablishment' ); $status2label=array(''); foreach ($tmpstatus2label as $key => $val) $status2label[$key]=$langs->trans($val); $object = new Establishment($db); // Load object include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once /* * Actions */ if ($action == 'confirm_delete' && $confirm == "yes") { $result=$object->delete($id); if ($result >= 0) { header("Location: ../admin/admin_establishment.php"); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); } } elseif ($action == 'add') { if (! $cancel) { $error=0; $object->name = GETPOST('name', 'alpha'); if (empty($object->name)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Name")), null, 'errors'); $error++; } if (empty($error)) { $object->address = GETPOST('address', 'alpha'); $object->zip = GETPOST('zipcode', 'alpha'); $object->town = GETPOST('town', 'alpha'); $object->country_id = $_POST["country_id"]; $object->status = GETPOST('status', 'int'); $object->fk_user_author = $user->id; $object->datec = dol_now(); $object->entity = GETPOST('entity', 'int')>0?GETPOST('entity', 'int'):$conf->entity; $id = $object->create($user); if ($id > 0) { header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); } } else { $action='create'; } } else { header("Location: ../admin/admin_establishment.php"); exit; } } // Update record elseif ($action == 'update') { $error = 0; if (! $cancel) { $name = GETPOST('name', 'alpha'); if (empty($name)) { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Name')), null, 'errors'); $error ++; } if (empty($error)) { $object->name = GETPOST('name', 'alpha'); $object->address = GETPOST('address', 'alpha'); $object->zip = GETPOST('zipcode', 'alpha'); $object->town = GETPOST('town', 'alpha'); $object->country_id = GETPOST('country_id', 'int'); $object->fk_user_mod = $user->id; $object->status = GETPOST('status', 'int'); $object->entity = GETPOST('entity', 'int')>0?GETPOST('entity', 'int'):$conf->entity; $result = $object->update($user); if ($result > 0) { header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $_POST['id']); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); } } } else { header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $_POST['id']); exit; } } /* * View */ llxHeader(); $form = new Form($db); $formcompany = new FormCompany($db); /* * Action create */ if ($action == 'create') { print load_fiche_titre($langs->trans("NewEstablishment")); print '
'; print ''; print ''; dol_fiche_head(); print ''; // Name print ''; print ''; print ''; print ''; // Parent print ''; print ''; print ''; print ''; // Address print ''; print ''; print ''; print ''; // Zipcode print ''; print ''; print ''; print ''; // Town print ''; print ''; print ''; print ''; // Country print ''; print ''; print ''; print ''; // Status print ''; print ''; print ''; print '
'. $form->editfieldkey('Name', 'name', '', $object, 0, 'string', '', 1).'
'.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).''; print $form->selectEstablishments(GETPOST('entity', 'int')>0?GETPOST('entity', 'int'):$conf->entity, 'entity', 1); print '
'.$form->editfieldkey('Address', 'address', '', $object, 0).''; print ''; print '
'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).''; print $formcompany->select_ziptown( GETPOST('zipcode', 'alpha'), 'zipcode', array ( 'town', 'selectcountry_id' ), 6 ); print '
'.$form->editfieldkey('Town', 'town', '', $object, 0).''; print $formcompany->select_ziptown(GETPOST('town', 'alpha'), 'town', array ( 'zipcode', 'selectcountry_id' )); print '
'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).''; print $form->select_country(GETPOST('country_id', 'int')>0?GETPOST('country_id', 'int'):$mysoc->country_id, 'country_id'); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); print '
'.$form->editfieldkey('Status', 'status', '', $object, 0, 'string', '', 1).''; print $form->selectarray('status', $status2label, GETPOST('status', 'alpha')); print '
'; dol_fiche_end(); print '
'; print ''; print '     '; print ''; print '
'; print '
'; } // Part to edit record if (($id || $ref) && $action == 'edit') { $result = $object->fetch($id); if ($result > 0) { $head = establishment_prepare_head($object); if ($action == 'edit') { dol_fiche_head($head, 'card', $langs->trans("Establishment"), 0, 'building'); print '
' . "\n"; print ''; print ''; print ''; print ''; // Ref print ""; print ''; // Name print ''; // Parent print ''; print ''; // Address print ''; print ''; // Zipcode / Town print ''; print ''; // Country print ''; print ''; print ''; // Status print ''; print '
'.$langs->trans("Ref").''; print $object->id; print '
'.$form->editfieldkey('Name', 'name', '', $object, 0, 'string', '', 1).''; print ''; print '
'.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).''; print $form->selectEstablishments($object->entity>0?$object->entity:$conf->entity, 'entity', 1); print '
'.$form->editfieldkey('Address', 'address', '', $object, 0).''; print ''; print '
'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).''; print $formcompany->select_ziptown($object->zip, 'zipcode', array ( 'town', 'selectcountry_id' ), 6) . '
'.$form->editfieldkey('Town', 'town', '', $object, 0).''; print $formcompany->select_ziptown($object->town, 'town', array ( 'zipcode', 'selectcountry_id' )) . '
'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).''; print $form->select_country($object->fk_country, 'country_id'); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); print '
'.$form->editfieldkey('Status', 'status', '', $object, 0, 'string', '', 1).''; print $form->selectarray('status', $status2label, $object->status); print '
'; dol_fiche_end(); print '
'; print ''; print '     '; print ''; print '
'; print '
'; } } else dol_print_error($db); } if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) { $res = $object->fetch_optionals(); $head = establishment_prepare_head($object); dol_fiche_head($head, 'card', $langs->trans("Establishment"), -1, 'building'); // Confirmation to delete if ($action == 'delete') { print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("DeleteEstablishment"), $langs->trans("ConfirmDeleteEstablishment"), "confirm_delete"); } // Object card // ------------------------------------------------------------ $linkback = '' . $langs->trans("BackToList") . ''; $morehtmlref='
'; $morehtmlref.='
'; dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', $morehtmlref); print '
'; //print '
'; print '
'; print ''."\n"; // Name print ''; print ''; print ''; print ''; // Parent print ''; print ''; print ''; print ''; // Address print ''; print ''; print ''; print ''; // Zipcode print ''; print ''; print ''; print ''; // Town print ''; print ''; print ''; print ''; // Country print ''; print ''; print ''; print ''; print '
'.$langs->trans("Name").''.$object->name.'
'.$langs->trans("Parent").''.$object->getNomUrlParent($object->entity).'
'.$langs->trans("Address").''.$object->address.'
'.$langs->trans("Zipcode").''.$object->zip.'
'.$langs->trans("Town").''.$object->town.'
'.$langs->trans("Country").''; if ($object->country_id > 0) { $img=picto_from_langcode($object->country_code); print $img?$img.' ':''; print getCountry($object->getCountryCode(), 0, $db); } print '
'; print '
'; print '

'; dol_fiche_end(); /* * Barre d'actions */ print ''; } // End of page llxFooter(); $db->close();