PageRenderTime 52ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/hrm/establishment/card.php

http://github.com/Dolibarr/dolibarr
PHP | 429 lines | 265 code | 75 blank | 89 comment | 44 complexity | f75c274934bf83e98c801369a987bd46 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-3.0, LGPL-2.0, CC-BY-SA-4.0, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, MIT
  1. <?php
  2. /* Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
  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. /**
  18. * \file htdocs/hrm/establishment/card.php
  19. * \brief Page to show an establishment
  20. */
  21. require '../../main.inc.php';
  22. require_once DOL_DOCUMENT_ROOT.'/core/lib/hrm.lib.php';
  23. require_once DOL_DOCUMENT_ROOT.'/hrm/class/establishment.class.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  26. // Load translation files required by the page
  27. $langs->loadLangs(array('admin', 'hrm'));
  28. $error = 0;
  29. $action = GETPOST('action', 'aZ09');
  30. $cancel = GETPOST('cancel', 'alpha');
  31. $confirm = GETPOST('confirm', 'alpha');
  32. $id = GETPOST('id', 'int');
  33. // List of status
  34. static $tmpstatus2label = array(
  35. '0'=>'CloseEtablishment',
  36. '1'=>'OpenEtablishment'
  37. );
  38. $status2label = array('');
  39. foreach ($tmpstatus2label as $key => $val) {
  40. $status2label[$key] = $langs->trans($val);
  41. }
  42. $object = new Establishment($db);
  43. // Load object
  44. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
  45. $permissiontoread = $user->admin;
  46. $permissiontoadd = $user->admin; // Used by the include of actions_addupdatedelete.inc.php
  47. $upload_dir = $conf->hrm->multidir_output[isset($object->entity) ? $object->entity : 1];
  48. // Security check - Protection if external user
  49. //if ($user->socid > 0) accessforbidden();
  50. //if ($user->socid > 0) $socid = $user->socid;
  51. //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  52. //restrictedArea($user, $object->element, $object->id, '', '', 'fk_soc', 'rowid', 0);
  53. if (empty($conf->hrm->enabled)) accessforbidden();
  54. if (empty($permissiontoread)) accessforbidden();
  55. /*
  56. * Actions
  57. */
  58. if ($action == 'confirm_delete' && $confirm == "yes") {
  59. $result = $object->delete($id);
  60. if ($result >= 0) {
  61. header("Location: ../admin/admin_establishment.php");
  62. exit;
  63. } else {
  64. setEventMessages($object->error, $object->errors, 'errors');
  65. }
  66. } elseif ($action == 'add') {
  67. if (!$cancel) {
  68. $error = 0;
  69. $object->label = GETPOST('label', 'alpha');
  70. if (empty($object->label)) {
  71. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
  72. $error++;
  73. }
  74. if (empty($error)) {
  75. $object->address = GETPOST('address', 'alpha');
  76. $object->zip = GETPOST('zipcode', 'alpha');
  77. $object->town = GETPOST('town', 'alpha');
  78. $object->country_id = GETPOST("country_id", 'int');
  79. $object->status = GETPOST('status', 'int');
  80. $object->fk_user_author = $user->id;
  81. $object->datec = dol_now();
  82. $object->entity = GETPOST('entity', 'int') > 0 ?GETPOST('entity', 'int') : $conf->entity;
  83. $id = $object->create($user);
  84. if ($id > 0) {
  85. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  86. exit;
  87. } else {
  88. setEventMessages($object->error, $object->errors, 'errors');
  89. }
  90. } else {
  91. $action = 'create';
  92. }
  93. } else {
  94. header("Location: ../admin/admin_establishment.php");
  95. exit;
  96. }
  97. } elseif ($action == 'update') {
  98. // Update record
  99. $error = 0;
  100. if (!$cancel) {
  101. $name = GETPOST('label', 'alpha');
  102. if (empty($name)) {
  103. setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Label')), null, 'errors');
  104. $error++;
  105. }
  106. if (empty($error)) {
  107. $object->label = GETPOST('label', 'alphanohtml');
  108. $object->address = GETPOST('address', 'alpha');
  109. $object->zip = GETPOST('zipcode', 'alpha');
  110. $object->town = GETPOST('town', 'alpha');
  111. $object->country_id = GETPOST('country_id', 'int');
  112. $object->fk_user_mod = $user->id;
  113. $object->status = GETPOST('status', 'int');
  114. $object->entity = GETPOST('entity', 'int') > 0 ?GETPOST('entity', 'int') : $conf->entity;
  115. $result = $object->update($user);
  116. if ($result > 0) {
  117. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_POST['id']);
  118. exit;
  119. } else {
  120. setEventMessages($object->error, $object->errors, 'errors');
  121. }
  122. }
  123. } else {
  124. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_POST['id']);
  125. exit;
  126. }
  127. }
  128. /*
  129. * View
  130. */
  131. llxHeader();
  132. $form = new Form($db);
  133. $formcompany = new FormCompany($db);
  134. /*
  135. * Action create
  136. */
  137. if ($action == 'create') {
  138. print load_fiche_titre($langs->trans("NewEstablishment"));
  139. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  140. print '<input type="hidden" name="token" value="'.newToken().'">';
  141. print '<input type="hidden" name="action" value="add">';
  142. print dol_get_fiche_head();
  143. print '<table class="border centpercent">';
  144. // Name
  145. print '<tr>';
  146. print '<td>'.$form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).'</td>';
  147. print '<td><input name="label" id="label" value="'.GETPOST("label", "alphanohtml").'" autofocus></td>';
  148. print '</tr>';
  149. // Entity
  150. /*
  151. if (! empty($conf->multicompany->enabled)) {
  152. print '<tr>';
  153. print '<td>'.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).'</td>';
  154. print '<td class="maxwidthonsmartphone">';
  155. print $form->selectEstablishments(GETPOST('entity', 'int') > 0 ?GETPOST('entity', 'int') : $conf->entity, 'entity', 1);
  156. print '</td>';
  157. print '</tr>';
  158. } */
  159. // Address
  160. print '<tr>';
  161. print '<td>'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
  162. print '<td>';
  163. print '<input name="address" id="address" class="qutrevingtpercent" value="'.GETPOST('address', 'alphanohtml').'">';
  164. print '</td>';
  165. print '</tr>';
  166. // Zipcode
  167. print '<tr>';
  168. print '<td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td>';
  169. print '<td>';
  170. print $formcompany->select_ziptown(
  171. GETPOST('zipcode', 'alpha'),
  172. 'zipcode',
  173. array(
  174. 'town',
  175. 'selectcountry_id'
  176. ),
  177. 6
  178. );
  179. print '</td>';
  180. print '</tr>';
  181. // Town
  182. print '<tr>';
  183. print '<td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td>';
  184. print '<td>';
  185. print $formcompany->select_ziptown(GETPOSTISSET('town') ? GETPOST('town', 'alpha') : $object->town, 'town', array(
  186. 'zipcode',
  187. 'selectcountry_id'
  188. ));
  189. print '</td>';
  190. print '</tr>';
  191. // Country
  192. print '<tr>';
  193. print '<td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td>';
  194. print '<td class="maxwidthonsmartphone">';
  195. print $form->select_country(GETPOSTISSET('country_id') ? GETPOST('country_id', 'int') : ($object->country_id ? $object->country_id : $mysoc->country_id), 'country_id');
  196. if ($user->admin) {
  197. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  198. }
  199. print '</td>';
  200. print '</tr>';
  201. // Status
  202. print '<tr>';
  203. print '<td>'.$form->editfieldkey('Status', 'status', '', $object, 0, 'string', '', 1).'</td>';
  204. print '<td>';
  205. print $form->selectarray('status', $status2label, GETPOSTISSET('status') ? GETPOST('status', 'alpha') : 1);
  206. print '</td></tr>';
  207. print '</table>';
  208. print dol_get_fiche_end();
  209. print '<div class="center">';
  210. print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
  211. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  212. print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
  213. print '</div>';
  214. print '</form>';
  215. }
  216. // Part to edit record
  217. if (($id || $ref) && $action == 'edit') {
  218. $result = $object->fetch($id);
  219. if ($result > 0) {
  220. $head = establishment_prepare_head($object);
  221. if ($action == 'edit') {
  222. print dol_get_fiche_head($head, 'card', $langs->trans("Establishment"), 0, $object->picto);
  223. print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
  224. print '<input type="hidden" name="token" value="'.newToken().'">';
  225. print '<input type="hidden" name="action" value="update">';
  226. print '<input type="hidden" name="id" value="'.$id.'">';
  227. print '<table class="border centpercent">';
  228. // Ref
  229. print "<tr>";
  230. print '<td class="titlefield">'.$langs->trans("Ref").'</td><td>';
  231. print $object->id;
  232. print '</td></tr>';
  233. // Name
  234. print '<tr><td>'.$form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).'</td><td>';
  235. print '<input name="label" id="label" class="flat" value="'.$object->label.'">';
  236. print '</td></tr>';
  237. // Entity
  238. /*
  239. if (! empty($conf->multicompany->enabled)) {
  240. print '<tr><td>'.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).'</td>';
  241. print '<td class="maxwidthonsmartphone">';
  242. print $object->entity > 0 ? $object->entity : $conf->entity;
  243. print '</td></tr>';
  244. }*/
  245. // Address
  246. print '<tr><td>'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
  247. print '<td>';
  248. print '<input name="address" id="address" value="'.$object->address.'">';
  249. print '</td></tr>';
  250. // Zipcode / Town
  251. print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td>';
  252. print $formcompany->select_ziptown($object->zip, 'zipcode', array(
  253. 'town',
  254. 'selectcountry_id'
  255. ), 6).'</tr>';
  256. print '<tr><td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td>';
  257. print $formcompany->select_ziptown($object->town, 'town', array(
  258. 'zipcode',
  259. 'selectcountry_id'
  260. )).'</td></tr>';
  261. // Country
  262. print '<tr><td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td>';
  263. print '<td class="maxwidthonsmartphone">';
  264. print $form->select_country($object->country_id, 'country_id');
  265. if ($user->admin) {
  266. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  267. }
  268. print '</td>';
  269. print '</tr>';
  270. // Status
  271. print '<tr><td>'.$form->editfieldkey('Status', 'status', '', $object, 0, 'string', '', 1).'</td><td>';
  272. print $form->selectarray('status', $status2label, $object->status);
  273. print '</td></tr>';
  274. print '</table>';
  275. print dol_get_fiche_end();
  276. print $form->buttonsSaveCancel();
  277. print '</form>';
  278. }
  279. } else {
  280. dol_print_error($db);
  281. }
  282. }
  283. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  284. $res = $object->fetch_optionals();
  285. $head = establishment_prepare_head($object);
  286. print dol_get_fiche_head($head, 'card', $langs->trans("Establishment"), -1, $object->picto);
  287. // Confirmation to delete
  288. if ($action == 'delete') {
  289. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("DeleteEstablishment"), $langs->trans("ConfirmDeleteEstablishment"), "confirm_delete");
  290. }
  291. // Object card
  292. // ------------------------------------------------------------
  293. $linkback = '<a href="'.DOL_URL_ROOT.'/hrm/admin/admin_establishment.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  294. $morehtmlref = '<div class="refidno">';
  295. $morehtmlref .= '</div>';
  296. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', $morehtmlref);
  297. print '<div class="fichecenter">';
  298. //print '<div class="fichehalfleft">';
  299. print '<div class="underbanner clearboth"></div>';
  300. print '<table class="border centpercent">'."\n";
  301. // Name
  302. print '<tr>';
  303. print '<td class="titlefield">'.$langs->trans("Label").'</td>';
  304. print '<td>'.$object->label.'</td>';
  305. print '</tr>';
  306. // Entity
  307. /*
  308. if ($conf->multicompany->enabled) {
  309. print '<tr>';
  310. print '<td class="titlefield">'.$langs->trans("Entity").'</td>';
  311. print '<td>'.$object->entity.'</td>';
  312. print '</tr>';
  313. }*/
  314. // Address
  315. print '<tr>';
  316. print '<td>'.$langs->trans("Address").'</td>';
  317. print '<td>'.$object->address.'</td>';
  318. print '</tr>';
  319. // Zipcode
  320. print '<tr>';
  321. print '<td>'.$langs->trans("Zip").'</td>';
  322. print '<td>'.$object->zip.'</td>';
  323. print '</tr>';
  324. // Town
  325. print '<tr>';
  326. print '<td>'.$langs->trans("Town").'</td>';
  327. print '<td>'.$object->town.'</td>';
  328. print '</tr>';
  329. // Country
  330. print '<tr>';
  331. print '<td>'.$langs->trans("Country").'</td>';
  332. print '<td>';
  333. if ($object->country_id > 0) {
  334. $img = picto_from_langcode($object->country_code);
  335. print $img ? $img.' ' : '';
  336. print getCountry($object->getCountryCode(), 0, $db);
  337. }
  338. print '</td>';
  339. print '</tr>';
  340. print '</table>';
  341. print '</div>';
  342. print '<div class="clearboth"></div><br>';
  343. print dol_get_fiche_end();
  344. /*
  345. * Action bar
  346. */
  347. print '<div class="tabsAction">';
  348. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$id.'">'.$langs->trans('Modify').'</a>';
  349. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$id.'">'.$langs->trans('Delete').'</a>';
  350. print '</div>';
  351. }
  352. // End of page
  353. llxFooter();
  354. $db->close();