card.tpl.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <?php
  2. /* Copyright (C) 2009-2022 Regis Houssin <regis.houssin@inodbox.com>
  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, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. *
  18. */
  19. // Protection to avoid direct call of template
  20. if (empty($conf) || !is_object($conf)) {
  21. print "Error, template page can't be called as URL";
  22. exit;
  23. }
  24. ?>
  25. <!-- BEGIN PHP TEMPLATE -->
  26. <script type="text/javascript">
  27. $(document).ready(function () {
  28. $("#selectcountry_id").change(function() {
  29. document.form_entity.action.value="<?php echo $this->tpl['action']; ?>";
  30. document.form_entity.submit();
  31. });
  32. <?php if (!empty($conf->global->MULTICOMPANY_TEMPLATE_MANAGEMENT)) { ?>
  33. $("#template").change(function() {
  34. var template = $(this).val();
  35. if (template == '1') {
  36. $('#usetemplate').val(null).trigger('change');
  37. $("#usetemplate").prop('disabled', true);
  38. } else {
  39. $("#usetemplate").prop('disabled', false);
  40. }
  41. });
  42. $("#form_entity").on('change', '#template, #usetemplate', function() {
  43. var fieldvalue = $(this).val();
  44. if (fieldvalue > '0') {
  45. $("tr.template-field").show();
  46. } else {
  47. $("tr.template-field").hide();
  48. }
  49. });
  50. $("#form_entity").on('change', '#usetemplate', function() {
  51. var id = $(this).val();
  52. if (id > '0') {
  53. <?php
  54. // reset before change values
  55. foreach($this->sharingelements as $element => $params) {
  56. if (!empty($this->tpl['multiselect_from_' . $element])) { ?>
  57. var element = '<?php echo $element; ?>';
  58. $('#multiselect_shared_' + element + '_rightAll').click();
  59. <?php } } ?>
  60. $.post( "<?php echo dol_buildpath('/multicompany/core/ajax/functions.php',1); ?>", {
  61. 'action': 'getEntityOptions',
  62. 'id': id,
  63. 'token': '<?php echo currentToken(); ?>'
  64. },
  65. function (result) {
  66. if (result.status == "success") {
  67. $.each(result.options.sharings, function( element, entities ) {
  68. if (entities != null) {
  69. $.each(entities, function( key, entity ) {
  70. //console.log(element);
  71. //console.log(entity);
  72. $('#multiselect_shared_' + element + ' option[value=' + entity + ']').remove();
  73. $('#multiselect_shared_' + element + '_to').append( $("<option></option>").attr("value", entity).text(result.labels[entity]) );
  74. $('#multiselect_shared_' + element + '_to option').addClass( "multiselect-option" );
  75. $('#multiselect_shared_' + element + '_to').html( $('#multiselect_shared_' + element + '_to option').sort(function(x, y) {
  76. return $(x).val() < $(y).val() ? -1 : 1;
  77. }));
  78. });
  79. if (result.options.addtoallother) {
  80. $.each(result.options.addtoallother, function( element, value ) {
  81. $('#addtoallother_' + element).val(value).change();
  82. })
  83. }
  84. }
  85. });
  86. } else {
  87. $.jnotify("<?php echo $langs->transnoentities("ErrorGetEntitySharings"); ?>", "error", true);
  88. }
  89. }
  90. );
  91. } else {
  92. <?php
  93. foreach($this->sharingelements as $element => $params) {
  94. if (!empty($this->tpl['multiselect_from_' . $element])) {
  95. ?>
  96. var element = '<?php echo $element; ?>';
  97. $('#multiselect_shared_' + element + '_rightAll').click();
  98. <?php } } ?>
  99. }
  100. });
  101. <?php } ?>
  102. <?php
  103. if (!empty($conf->global->MULTICOMPANY_SHARINGS_ENABLED)) {
  104. foreach($this->sharingelements as $element => $params) {
  105. if ($params['type'] === 'element' && !empty($this->tpl['multiselect_from_' . $element])) {
  106. ?>
  107. $('#multiselect_shared_<?php echo $element; ?>').multiselect({
  108. keepRenderingSort: true,
  109. right: '#multiselect_to_<?php echo $element; ?>',
  110. rightAll: '#multiselect_shared_<?php echo $element; ?>_leftAll',
  111. rightSelected: '#multiselect_shared_<?php echo $element; ?>_leftSelected',
  112. leftSelected: '#multiselect_shared_<?php echo $element; ?>_rightSelected',
  113. leftAll: '#multiselect_shared_<?php echo $element; ?>_rightAll',
  114. search: {
  115. left: '<input type="text" name="q" class="form-control" placeholder="<?php echo $langs->trans("Search").'...'; ?>" />',
  116. right: '<input type="text" name="q" class="form-control" placeholder="<?php echo $langs->trans("Search").'...'; ?>" />',
  117. },
  118. fireSearch: function(value) {
  119. return value.length > 2;
  120. },
  121. <?php if ($element == 'thirdparty') { ?>
  122. afterMoveToLeft: function($left, $right, $options) {
  123. var sharingobjects = <?php echo json_encode($object->sharingelements); ?>;
  124. $.each(sharingobjects, function( element, param ) {
  125. if (! param.disable && param.type === 'object') {
  126. var elements = $('#multiselect_shared_' + element + '_to option');
  127. if (elements && elements.length) {
  128. $.each(elements, function( key, share) {
  129. $.each($options, function( index, entity ) {
  130. if (entity.value == share.value) {
  131. $('#multiselect_shared_' + element + '_to option[value=' + entity.value + ']').remove();
  132. $('#multiselect_shared_' + element).append($("<option></option>").attr("value", entity.value).text(entity.text));
  133. $('#multiselect_shared_' + element).html($('#multiselect_shared_' + element + ' option').sort(function(x, y) {
  134. return $(x).val() < $(y).val() ? -1 : 1;
  135. }));
  136. }
  137. });
  138. });
  139. }
  140. }
  141. });
  142. },
  143. afterMoveToRight: function($left, $right, $options) {
  144. $('#multiselect_shared_<?php echo $element; ?>_to').html($('#multiselect_shared_<?php echo $element; ?>_to option').sort(function(x, y) {
  145. return $(x).val() < $(y).val() ? -1 : 1;
  146. }));
  147. }
  148. <?php } ?>
  149. });
  150. <?php } } ?>
  151. <?php
  152. foreach($this->sharingelements as $element => $params) {
  153. if ($params['type'] !== 'element' && !empty($this->tpl['multiselect_from_' . $element])) {
  154. $mandatory = (!empty($params['mandatory']) ? $params['mandatory'] : '');
  155. ?>
  156. $('#multiselect_shared_<?php echo $element; ?>').multiselect({
  157. keepRenderingSort: true,
  158. right: '#multiselect_to_<?php echo $element; ?>',
  159. rightAll: '#multiselect_shared_<?php echo $element; ?>_leftAll',
  160. rightSelected: '#multiselect_shared_<?php echo $element; ?>_leftSelected',
  161. leftSelected: '#multiselect_shared_<?php echo $element; ?>_rightSelected',
  162. leftAll: '#multiselect_shared_<?php echo $element; ?>_rightAll',
  163. search: {
  164. left: '<input type="text" name="q" class="form-control" placeholder="<?php echo $langs->trans("Search").'...'; ?>" />',
  165. right: '<input type="text" name="q" class="form-control" placeholder="<?php echo $langs->trans("Search").'...'; ?>" />',
  166. },
  167. fireSearch: function(value) {
  168. return value.length > 2;
  169. },
  170. afterMoveToRight: function($left, $right, $options) {
  171. <?php if (!empty($mandatory)) { ?>
  172. var mandatory = '<?php echo $mandatory; ?>';
  173. var elements = $('#multiselect_shared_' + mandatory + ' option');
  174. if (elements && elements.length) {
  175. $.each(elements, function( key, share) {
  176. $.each($options, function( index, entity ) {
  177. if (entity.value == share.value) {
  178. $('#multiselect_shared_' + mandatory + ' option[value=' + entity.value + ']').remove();
  179. $('#multiselect_shared_' + mandatory + '_to').append($("<option></option>").attr("value", entity.value).text(entity.text));
  180. $('#multiselect_shared_' + mandatory + '_to').html($('#multiselect_shared_' + mandatory + '_to option').sort(function(x, y) {
  181. return $(x).val() < $(y).val() ? -1 : 1;
  182. }));
  183. }
  184. });
  185. });
  186. }
  187. <?php } else { ?>
  188. $('#multiselect_shared_<?php echo $element; ?>_to').html($('#multiselect_shared_<?php echo $element; ?>_to option').sort(function(x, y) {
  189. return $(x).val() < $(y).val() ? -1 : 1;
  190. }));
  191. <?php } ?>
  192. },
  193. afterMoveToLeft: function($left, $right, $options) {
  194. $('#multiselect_shared_<?php echo $element; ?>').html($('#multiselect_shared_<?php echo $element; ?> option').sort(function(x, y) {
  195. return $(x).val() < $(y).val() ? -1 : 1;
  196. }));
  197. }
  198. });
  199. <?php } } } ?>
  200. });
  201. </script>
  202. <form id="form_entity" name="form_entity" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="POST">
  203. <input type="hidden" name="token" value="<?php echo newToken(); ?>" />
  204. <?php if ($this->tpl['action'] === 'create') { ?>
  205. <input type="hidden" name="action" value="add" />
  206. <?php } else { ?>
  207. <input type="hidden" name="action" value="update" />
  208. <input type="hidden" name="id" value="<?php echo $this->tpl['id']; ?>" />
  209. <?php } ?>
  210. <table class="noborder">
  211. <tr class="liste_titre">
  212. <td width="35%"><span class="fa fa-edit"></span><span class="multiselect-title"><?php echo $langs->trans("CompanyInfo"); ?></span></td>
  213. <td><?php echo $langs->trans("Value"); ?></td>
  214. </tr>
  215. <tr class="oddeven">
  216. <td><span class="fieldrequired"><?php echo $langs->trans("Label"); ?></span></td>
  217. <td><input name="label" size="40" value="<?php echo $this->tpl['label']; ?>" /></td>
  218. </tr>
  219. <tr class="oddeven">
  220. <td><span class="fieldrequired"><?php echo $langs->trans("CompanyName"); ?></span></td>
  221. <td><input name="name" size="40" value="<?php echo $this->tpl['name']; ?>" /></td>
  222. </tr>
  223. <?php
  224. if (!empty($conf->global->MULTICOMPANY_TEMPLATE_MANAGEMENT)) {
  225. if ($this->tpl['action'] === 'create') { ?>
  226. <tr class="oddeven">
  227. <td><?php echo $langs->trans("TemplateOfCompany"); ?></td>
  228. <td><?php echo $this->tpl['template']; ?></td>
  229. </tr>
  230. <tr class="oddeven">
  231. <td><?php echo $langs->trans("SelectTemplateOfCompany"); ?></td>
  232. <td><?php echo $this->tpl['select_template']; ?></td>
  233. </tr>
  234. <?php } elseif (!empty($this->tpl['template']) && $this->tpl['template'] === 1) { ?>
  235. <tr class="oddeven">
  236. <td colspan="2" class="error"><?php echo $langs->trans("WarningThisIsATemplate"); ?></td>
  237. </tr>
  238. <?php } } ?>
  239. <tr class="oddeven">
  240. <td><?php echo $langs->trans("CompanyAddress"); ?></td>
  241. <td><textarea name="address" cols="80" rows="<?php echo ROWS_3; ?>"><?php echo $this->tpl['address']; ?></textarea></td>
  242. </tr>
  243. <tr class="oddeven">
  244. <td><?php echo $langs->trans("CompanyZip"); ?></td>
  245. <td><?php echo $this->tpl['select_zip']; ?></td>
  246. </tr>
  247. <tr class="oddeven">
  248. <td><?php echo $langs->trans("CompanyTown"); ?></td>
  249. <td><?php echo $this->tpl['select_town']; ?></td>
  250. </tr>
  251. <tr class="oddeven">
  252. <td><?php echo $langs->trans("Country"); ?></td>
  253. <td><?php echo $this->tpl['select_country'].$this->tpl['info_admin']; ?></td>
  254. </tr>
  255. <tr class="oddeven">
  256. <td><?php echo $langs->trans("State"); ?></td>
  257. <td><?php echo $this->tpl['select_state']; ?></td>
  258. </tr>
  259. <tr class="oddeven">
  260. <td><?php echo $langs->trans("CompanyCurrency"); ?></td>
  261. <td><?php echo $this->tpl['select_currency']; ?></td>
  262. </tr>
  263. <tr class="oddeven">
  264. <td><?php echo $langs->trans("DefaultLanguage"); ?></td>
  265. <td><?php echo $this->tpl['select_language']; ?></td>
  266. </tr>
  267. <tr class="oddeven">
  268. <td class="tdtop"><?php echo $langs->trans("Description"); ?></td>
  269. <td><textarea class="flat" name="description" cols="80" rows="<?php echo ROWS_3; ?>"><?php echo $this->tpl['description']; ?></textarea></td>
  270. </tr>
  271. <?php
  272. if (!empty($this->tpl['cloneaccountingaccount'])) {
  273. ?>
  274. <tr class="oddeven">
  275. <td class="tdtop"><?php echo $langs->trans("CloneAccountingAccountFromOtherEntity"); ?></td>
  276. <td><?php echo $this->tpl['cloneaccountingaccount']; ?></td>
  277. </tr>
  278. <?php
  279. }
  280. if (!empty($this->tpl['extrafields']->attribute_label)) {
  281. print $this->dao->showOptionals($this->tpl['extrafields'], 'edit');
  282. }
  283. if (!empty($conf->global->MULTICOMPANY_SHARINGS_ENABLED)) {
  284. foreach($this->sharingelements as $element => $params) {
  285. if ($params['type'] === 'element' && !empty($this->tpl['multiselect_from_' . $element])) {
  286. $uppername = strtoupper($element);
  287. $icon = (!empty($params['icon'])?$params['icon']:'edit');
  288. ?>
  289. <tr class="liste_titre">
  290. <td colspan="2"><span class="fa fa-<?php echo $icon; ?>"></span><span class="multiselect-title"><?php echo $langs->trans($uppername . "Sharing"); ?></span></td>
  291. </tr>
  292. <tr class="oddeven">
  293. <td class="tdtop"><?php echo $langs->trans($uppername . "SharingDescription"); ?></td>
  294. <td>
  295. <div class="row">
  296. <div class="col-sm-5">
  297. <div class="multiselect-selected-title"><span class="fa fa-globe"></span><span class="multiselect-selected-title-text"><?php echo $langs->trans("EntitiesSelected"); ?></span></div>
  298. <?php echo $this->tpl['multiselect_to_' . $element]; ?>
  299. </div>
  300. <div class="col-xs-2 multiselect-menu">
  301. <!-- <button type="button" id="multiselect_shared_<?php //echo $element; ?>_undo" class="btn btn-primary btn-block"><?php //echo $langs->trans("Undo"); ?></button> -->
  302. <button type="button" id="multiselect_shared_<?php echo $element; ?>_leftAll" class="btn btn-block multiselect-menu-btn-color"><i class="glyphicon glyphicon-backward"></i></button>
  303. <button type="button" id="multiselect_shared_<?php echo $element; ?>_leftSelected" class="btn btn-block multiselect-menu-btn-color"><i class="glyphicon glyphicon-chevron-left"></i></button>
  304. <button type="button" id="multiselect_shared_<?php echo $element; ?>_rightSelected" class="btn btn-block multiselect-menu-btn-color"><i class="glyphicon glyphicon-chevron-right"></i></button>
  305. <button type="button" id="multiselect_shared_<?php echo $element; ?>_rightAll" class="btn btn-block multiselect-menu-btn-color"><i class="glyphicon glyphicon-forward"></i></button>
  306. <!-- <button type="button" id="multiselect_shared_<?php //echo $element; ?>_redo" class="btn btn-warning btn-block"><?php //echo $langs->trans("Redo"); ?></button> -->
  307. </div>
  308. <div class="col-xs-5">
  309. <div class="multiselect-available-title"><span class="fa fa-globe"></span><span class="multiselect-available-title-text"><?php echo $langs->trans("EntitiesAvailable"); ?></span></div>
  310. <?php echo $this->tpl['multiselect_from_' . $element]; ?>
  311. </div>
  312. </div>
  313. </td>
  314. </tr>
  315. <?php if (!empty($conf->global->MULTICOMPANY_TEMPLATE_MANAGEMENT)) { ?>
  316. <tr class="oddeven template-field<?php echo (!empty($this->tpl['template']) && $this->tpl['template'] === 1 ? '' : ' hideobject') ?>">
  317. <td class="tdtop"><?php echo $langs->trans("AddNewEntityInAllOtherEntities"); ?></td>
  318. <td><?php echo $this->tpl['addtoallother_' . $element]; ?></td>
  319. </tr>
  320. <tr class="multiselect-separator template-field<?php echo (!empty($this->tpl['template']) && $this->tpl['template'] === 1 ? '' : ' hideobject') ?>"><td colspan="2">&nbsp;</td></tr>
  321. <?php } ?>
  322. <?php } } ?>
  323. <?php
  324. foreach($this->sharingelements as $element => $params) {
  325. if ($params['type'] !== 'element' && !empty($this->tpl['multiselect_from_' . $element])) {
  326. $uppername = strtoupper($element);
  327. $icon = (!empty($params['icon'])?$params['icon']:'edit');
  328. ?>
  329. <tr class="liste_titre">
  330. <td colspan="2"><span class="fa fa-<?php echo $icon; ?>"></span><span class="multiselect-title"><?php echo $langs->trans($uppername . "Sharing"); ?></span></td>
  331. </tr>
  332. <tr class="oddeven">
  333. <td class="tdtop"><?php echo $langs->trans($uppername . "SharingDescription"); ?></td>
  334. <td>
  335. <div class="row">
  336. <div class="col-sm-5">
  337. <div class="multiselect-selected-title"><span class="fa fa-globe"></span><span class="multiselect-selected-title-text"><?php echo $langs->trans("EntitiesSelected"); ?></span></div>
  338. <?php echo $this->tpl['multiselect_to_' . $element]; ?>
  339. </div>
  340. <div class="col-xs-2 multiselect-menu">
  341. <!-- <button type="button" id="multiselect_shared_<?php //echo $element; ?>_undo" class="btn btn-primary btn-block"><?php //echo $langs->trans("Undo"); ?></button> -->
  342. <button type="button" id="multiselect_shared_<?php echo $element; ?>_leftAll" class="btn btn-block multiselect-menu-btn-color"><i class="glyphicon glyphicon-backward"></i></button>
  343. <button type="button" id="multiselect_shared_<?php echo $element; ?>_leftSelected" class="btn btn-block multiselect-menu-btn-color"><i class="glyphicon glyphicon-chevron-left"></i></button>
  344. <button type="button" id="multiselect_shared_<?php echo $element; ?>_rightSelected" class="btn btn-block multiselect-menu-btn-color"><i class="glyphicon glyphicon-chevron-right"></i></button>
  345. <button type="button" id="multiselect_shared_<?php echo $element; ?>_rightAll" class="btn btn-block multiselect-menu-btn-color"><i class="glyphicon glyphicon-forward"></i></button>
  346. <!-- <button type="button" id="multiselect_shared_<?php //echo $element; ?>_redo" class="btn btn-warning btn-block"><?php //echo $langs->trans("Redo"); ?></button> -->
  347. </div>
  348. <div class="col-xs-5">
  349. <div class="multiselect-available-title"><span class="fa fa-globe"></span><span class="multiselect-available-title-text"><?php echo $langs->trans("EntitiesAvailable"); ?></span></div>
  350. <?php echo $this->tpl['multiselect_from_' . $element]; ?>
  351. </div>
  352. </div>
  353. </td>
  354. </tr>
  355. <?php
  356. if ($params['type'] === 'objectnumber') {
  357. $constname = 'MULTICOMPANY_'.strtoupper($element).'_SHARING_ENABLED';
  358. if (!empty($conf->global->$constname)) {
  359. ?>
  360. <tr class="oddeven">
  361. <td class="tdtop"><?php echo $langs->trans("ReferringEntityForElementNumber"); ?></td>
  362. <td><?php echo $this->tpl['select_'.$element.'_entity']; ?></td>
  363. </tr>
  364. <tr class="multiselect-separator"><td colspan="2">&nbsp;</td></tr>
  365. <?php } } ?>
  366. <?php if (!empty($conf->global->MULTICOMPANY_TEMPLATE_MANAGEMENT)) { ?>
  367. <tr class="oddeven template-field<?php echo (!empty($this->tpl['template']) && $this->tpl['template'] === 1 ? '' : ' hideobject') ?>">
  368. <td class="tdtop"><?php echo $langs->trans("AddNewEntityInAllOtherEntities"); ?></td>
  369. <td><?php echo $this->tpl['addtoallother_' . $element]; ?></td>
  370. </tr>
  371. <tr class="multiselect-separator template-field<?php echo (!empty($this->tpl['template']) && $this->tpl['template'] === 1 ? '' : ' hideobject') ?>"><td colspan="2">&nbsp;</td></tr>
  372. <?php } ?>
  373. <?php } } } ?>
  374. </table>
  375. </div>
  376. <div class="tabsAction">
  377. <?php if ($this->tpl['action'] === 'create') { ?>
  378. <input type="submit" class="butAction linkobject" name="add" value="<?php echo $langs->trans('Add'); ?>" />
  379. <input type="submit" class="butAction linkobject" name="addandstay" value="<?php echo $langs->trans("AddAndStay"); ?>" />
  380. <?php } else { ?>
  381. <input type="submit" class="butAction linkobject" name="updateandstay" value="<?php echo $langs->trans('UpdateAndStay'); ?>" />
  382. <input type="submit" class="butAction linkobject" name="update" value="<?php echo $langs->trans('Update'); ?>" />
  383. <input type="submit" class="butAction linkobject" name="cancelandstay" value="<?php echo $langs->trans("CancelAndStay"); ?>" />
  384. <?php } ?>
  385. <input type="submit" class="butAction linkobject" name="cancel" value="<?php echo $langs->trans("Cancel"); ?>" />
  386. </div>
  387. </form>
  388. <!-- END PHP TEMPLATE -->