contact.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. /* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  3. * Copyright (C) 2007-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/fichinter/contact.php
  21. * \ingroup fichinter
  22. * \brief Onglet de gestion des contacts de fiche d'intervention
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array('interventions', 'sendings', 'companies'));
  33. $id = GETPOST('id','int');
  34. $ref = GETPOST('ref', 'alpha');
  35. $action = GETPOST('action','alpha');
  36. // Security check
  37. if ($user->societe_id) $socid=$user->societe_id;
  38. $result = restrictedArea($user, 'ficheinter', $id, 'fichinter');
  39. $object = new Fichinter($db);
  40. $result = $object->fetch($id,$ref);
  41. if (! $result)
  42. {
  43. print 'Record not found';
  44. exit;
  45. }
  46. /*
  47. * Adding a new contact
  48. */
  49. if ($action == 'addcontact' && $user->rights->ficheinter->creer)
  50. {
  51. if ($result > 0 && $id > 0)
  52. {
  53. $contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int'));
  54. $result = $object->add_contact($contactid, GETPOST('type','int'), GETPOST('source','alpha'));
  55. }
  56. if ($result >= 0)
  57. {
  58. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  59. exit;
  60. }
  61. else
  62. {
  63. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  64. $langs->load("errors");
  65. $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
  66. } else {
  67. $mesg = $object->error;
  68. }
  69. setEventMessages($mesg, null, 'errors');
  70. }
  71. }
  72. // Toggle the status of a contact
  73. else if ($action == 'swapstatut' && $user->rights->ficheinter->creer)
  74. {
  75. $result=$object->swapContactStatus(GETPOST('ligne','int'));
  76. }
  77. // Deletes a contact
  78. else if ($action == 'deletecontact' && $user->rights->ficheinter->creer)
  79. {
  80. $result = $object->delete_contact(GETPOST('lineid','int'));
  81. if ($result >= 0)
  82. {
  83. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  84. exit;
  85. }
  86. else {
  87. dol_print_error($db);
  88. }
  89. }
  90. /*
  91. * View
  92. */
  93. $form = new Form($db);
  94. $formcompany = new FormCompany($db);
  95. $contactstatic=new Contact($db);
  96. $userstatic=new User($db);
  97. $formproject=new FormProjets($db);
  98. llxHeader('',$langs->trans("Intervention"));
  99. // Mode vue et edition
  100. if ($id > 0 || ! empty($ref))
  101. {
  102. $object->fetch_thirdparty();
  103. $head = fichinter_prepare_head($object);
  104. dol_fiche_head($head, 'contact', $langs->trans("InterventionCard"), -1, 'intervention');
  105. // Intervention card
  106. $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php?restore_lastsearch_values=1'.(! empty($socid)?'&socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  107. $morehtmlref='<div class="refidno">';
  108. // Ref customer
  109. //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  110. //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  111. // Thirdparty
  112. $morehtmlref.=$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
  113. // Project
  114. if (! empty($conf->projet->enabled))
  115. {
  116. $langs->load("projects");
  117. $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
  118. if ($user->rights->ficheinter->creer)
  119. {
  120. if ($action != 'classify')
  121. //$morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  122. $morehtmlref.=' : ';
  123. if ($action == 'classify') {
  124. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  125. $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  126. $morehtmlref.='<input type="hidden" name="action" value="classin">';
  127. $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  128. $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  129. $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  130. $morehtmlref.='</form>';
  131. } else {
  132. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  133. }
  134. } else {
  135. if (! empty($object->fk_project)) {
  136. $proj = new Project($db);
  137. $proj->fetch($object->fk_project);
  138. $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
  139. $morehtmlref.=$proj->ref;
  140. $morehtmlref.='</a>';
  141. } else {
  142. $morehtmlref.='';
  143. }
  144. }
  145. }
  146. $morehtmlref.='</div>';
  147. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
  148. dol_fiche_end();
  149. print '<br>';
  150. if (! empty($conf->global->FICHINTER_HIDE_ADD_CONTACT_USER)) $hideaddcontactforuser=1;
  151. if (! empty($conf->global->FICHINTER_HIDE_ADD_CONTACT_THIPARTY)) $hideaddcontactforthirdparty=1;
  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. {
  156. $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
  157. if ($res) break;
  158. }
  159. }
  160. llxFooter();
  161. $db->close();