myobject_contact.php 7.2 KB

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