card.php 13 KB

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