job_contact.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  4. * Copyright (C) 2021 Greg Rastklan <greg.rastklan@atm-consulting.fr>
  5. * Copyright (C) 2021 Jean-Pascal BOUDET <jean-pascal.boudet@atm-consulting.fr>
  6. * Copyright (C) 2021 Grégory BLEMAND <gregory.blemand@atm-consulting.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file job_contact.php
  23. * \ingroup hrm
  24. * \brief Tab for contacts linked to Job
  25. */
  26. // Load Dolibarr environment
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  30. require_once DOL_DOCUMENT_ROOT . '/hrm/class/job.class.php';
  31. require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_job.lib.php';
  32. // Load translation files required by the page
  33. $langs->loadLangs(array("hrm", "companies", "other", "mails"));
  34. $id = (GETPOST('id') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
  35. $ref = GETPOST('ref', 'alpha');
  36. $lineid = GETPOST('lineid', 'int');
  37. $socid = GETPOST('socid', 'int');
  38. $action = GETPOST('action', 'aZ09');
  39. // Initialize technical objects
  40. $object = new Job($db);
  41. $extrafields = new ExtraFields($db);
  42. $diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id;
  43. $hookmanager->initHooks(array('jobcontact', 'globalcard')); // Note that conf->hooks_modules contains array
  44. // Fetch optionals attributes and labels
  45. $extrafields->fetch_name_optionals_label($object->table_element);
  46. // Load object
  47. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
  48. $permission = $user->rights->hrm->job->write;
  49. // Security check (enable the most restrictive one)
  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, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
  54. //if (empty($conf->hrm->enabled)) accessforbidden();
  55. //if (!$permissiontoread) accessforbidden();
  56. /*
  57. * Add a new contact
  58. */
  59. if ($action == 'addcontact' && $permission) {
  60. $contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
  61. $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
  62. $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
  63. if ($result >= 0) {
  64. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  65. exit;
  66. } else {
  67. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  68. $langs->load("errors");
  69. setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
  70. } else {
  71. setEventMessages($object->error, $object->errors, 'errors');
  72. }
  73. }
  74. } elseif ($action == 'swapstatut' && $permission) {
  75. // Toggle the status of a contact
  76. $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
  77. } elseif ($action == 'deletecontact' && $permission) {
  78. // Deletes a contact
  79. $result = $object->delete_contact($lineid);
  80. if ($result >= 0) {
  81. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  82. exit;
  83. } else {
  84. dol_print_error($db);
  85. }
  86. }
  87. /*
  88. * View
  89. */
  90. $title = $langs->trans('Job')." - ".$langs->trans('ContactsAddresses');
  91. $help_url = '';
  92. //$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  93. llxHeader('', $title, $help_url);
  94. $form = new Form($db);
  95. $formcompany = new FormCompany($db);
  96. $contactstatic = new Contact($db);
  97. $userstatic = new User($db);
  98. /* *************************************************************************** */
  99. /* */
  100. /* View and edit mode */
  101. /* */
  102. /* *************************************************************************** */
  103. if ($object->id) {
  104. /*
  105. * Show tabs
  106. */
  107. $head = jobPrepareHead($object);
  108. print dol_get_fiche_head($head, 'contact', '', -1, $object->picto);
  109. $linkback = '<a href="'.dol_buildpath('/hrm/job_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  110. $morehtmlref = '<div class="refidno">';
  111. /*
  112. // Ref customer
  113. $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  114. $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  115. // Thirdparty
  116. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
  117. // Project
  118. if (! empty($conf->projet->enabled))
  119. {
  120. $langs->load("projects");
  121. $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
  122. if ($permissiontoadd)
  123. {
  124. if ($action != 'classify')
  125. //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  126. $morehtmlref.=' : ';
  127. if ($action == 'classify') {
  128. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  129. $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  130. $morehtmlref.='<input type="hidden" name="action" value="classin">';
  131. $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
  132. $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  133. $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  134. $morehtmlref.='</form>';
  135. } else {
  136. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  137. }
  138. } else {
  139. if (! empty($object->fk_project)) {
  140. $proj = new Project($db);
  141. $proj->fetch($object->fk_project);
  142. $morehtmlref .= ': '.$proj->getNomUrl();
  143. } else {
  144. $morehtmlref .= '';
  145. }
  146. }
  147. }*/
  148. $morehtmlref .= '</div>';
  149. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
  150. print dol_get_fiche_end();
  151. print '<br>';
  152. // Contacts lines (modules that overwrite templates must declare this into descriptor)
  153. $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
  154. foreach ($dirtpls as $reldir) {
  155. $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
  156. if ($res) {
  157. break;
  158. }
  159. }
  160. }
  161. // End of page
  162. llxFooter();
  163. $db->close();