contact.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. /* Copyright (C) 2010 Regis Houssin <regis.houssin@capnetworks.com>
  3. * Copyright (C) 2012-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  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 <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/projet/contact.php
  20. * \ingroup project
  21. * \brief Onglet de gestion des contacts du projet
  22. */
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  28. $langs->load("projects");
  29. $langs->load("companies");
  30. $id = GETPOST('id','int');
  31. $ref = GETPOST('ref','alpha');
  32. $lineid = GETPOST('lineid','int');
  33. $socid = GETPOST('socid','int');
  34. $action = GETPOST('action','alpha');
  35. $mine = GETPOST('mode')=='mine' ? 1 : 0;
  36. //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
  37. $object = new Project($db);
  38. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
  39. // Security check
  40. $socid=0;
  41. if ($user->societe_id > 0) $socid=$user->societe_id;
  42. $result = restrictedArea($user, 'projet', $id,'projet&project');
  43. /*
  44. * Actions
  45. */
  46. // Add new contact
  47. if ($action == 'addcontact' && $user->rights->projet->creer)
  48. {
  49. $result = 0;
  50. $result = $object->fetch($id);
  51. if ($result > 0 && $id > 0)
  52. {
  53. $contactid = (GETPOST('userid') ? GETPOST('userid','int') : GETPOST('contactid','int'));
  54. $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
  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. {
  65. $langs->load("errors");
  66. setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
  67. }
  68. else
  69. {
  70. setEventMessages($object->error, $object->errors, 'errors');
  71. }
  72. }
  73. }
  74. // bascule du statut d'un contact
  75. if ($action == 'swapstatut' && $user->rights->projet->creer)
  76. {
  77. if ($object->fetch($id))
  78. {
  79. $result=$object->swapContactStatus(GETPOST('ligne','int'));
  80. }
  81. else
  82. {
  83. dol_print_error($db);
  84. }
  85. }
  86. // Efface un contact
  87. if (($action == 'deleteline' || $action == 'deletecontact') && $user->rights->projet->creer)
  88. {
  89. $object->fetch($id);
  90. $result = $object->delete_contact(GETPOST("lineid"));
  91. if ($result >= 0)
  92. {
  93. header("Location: contact.php?id=".$object->id);
  94. exit;
  95. }
  96. else
  97. {
  98. dol_print_error($db);
  99. }
  100. }
  101. /*
  102. * View
  103. */
  104. $title=$langs->trans("ProjectContact").' - '.$object->ref.' '.$object->name;
  105. if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/projectnameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->ref.' '.$object->name.' - '.$langs->trans("ProjectContact");
  106. $help_url="EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
  107. llxHeader('', $title, $help_url);
  108. $form = new Form($db);
  109. $formcompany= new FormCompany($db);
  110. $contactstatic=new Contact($db);
  111. $userstatic=new User($db);
  112. /* *************************************************************************** */
  113. /* */
  114. /* Mode vue et edition */
  115. /* */
  116. /* *************************************************************************** */
  117. if ($id > 0 || ! empty($ref))
  118. {
  119. // To verify role of users
  120. //$userAccess = $object->restrictedProjectArea($user,'read');
  121. $userWrite = $object->restrictedProjectArea($user,'write');
  122. //$userDelete = $object->restrictedProjectArea($user,'delete');
  123. //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
  124. $head = project_prepare_head($object);
  125. dol_fiche_head($head, 'contact', $langs->trans("Project"), 0, ($object->public?'projectpub':'project'));
  126. /*
  127. * Projet synthese pour rappel
  128. */
  129. print '<table class="border" width="100%">';
  130. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php">'.$langs->trans("BackToList").'</a>';
  131. // Ref
  132. print '<tr><td class="titlefield">'.$langs->trans('Ref').'</td><td colspan="3">';
  133. // Define a complementary filter for search of next/prev ref.
  134. if (! $user->rights->projet->all->lire)
  135. {
  136. $objectsListId = $object->getProjectsAuthorizedForUser($user,0,0);
  137. $object->next_prev_filter=" rowid in (".(count($objectsListId)?join(',',array_keys($objectsListId)):'0').")";
  138. }
  139. print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '');
  140. print '</td></tr>';
  141. // Label
  142. print '<tr><td>'.$langs->trans("Label").'</td><td>'.$object->title.'</td></tr>';
  143. // Customer
  144. print "<tr><td>".$langs->trans("ThirdParty")."</td>";
  145. print '<td colspan="3">';
  146. if ($object->thirdparty->id > 0) print $object->thirdparty->getNomUrl(1);
  147. else print '&nbsp;';
  148. print '</td></tr>';
  149. // Visibility
  150. print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
  151. if ($object->public) print $langs->trans('SharedProject');
  152. else print $langs->trans('PrivateProject');
  153. print '</td></tr>';
  154. // Status
  155. print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
  156. // Date start
  157. print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
  158. print dol_print_date($object->date_start,'day');
  159. print '</td></tr>';
  160. // Date end
  161. print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
  162. print dol_print_date($object->date_end,'day');
  163. print '</td></tr>';
  164. // Opportunity status
  165. print '<tr><td>'.$langs->trans("OpportunityStatus").'</td><td>';
  166. $code = dol_getIdFromCode($db, $object->opp_status, 'c_lead_status', 'rowid', 'code');
  167. if ($code) print $langs->trans("OppStatus".$code);
  168. print '</td></tr>';
  169. // Opportunity Amount
  170. print '<tr><td>'.$langs->trans("OpportunityAmount").'</td><td>';
  171. if (strcmp($object->opp_amount,'')) print price($object->opp_amount,'',$langs,0,0,0,$conf->currency);
  172. print '</td></tr>';
  173. // Budget
  174. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  175. if (strcmp($object->budget_amount, '')) print price($object->budget_amount,'',$langs,0,0,0,$conf->currency);
  176. print '</td></tr>';
  177. print "</table>";
  178. print '</div>';
  179. // Contacts lines (modules that overwrite templates must declare this into descriptor)
  180. $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
  181. foreach($dirtpls as $reldir)
  182. {
  183. $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
  184. if ($res) break;
  185. }
  186. }
  187. llxFooter();
  188. $db->close();