contact.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <?php
  2. /* Copyright (C) 2010 Regis Houssin <regis.houssin@inodbox.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. // Load translation files required by the page
  29. $langs->loadLangs(array('projects', '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. if(! empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($object, 'fetchComments') && empty($object->comments)) $object->fetchComments();
  40. // Security check
  41. $socid=0;
  42. //if ($user->societe_id > 0) $socid = $user->societe_id; // For external user, no check is done on company because readability is managed by public status of project and assignement.
  43. $result = restrictedArea($user, 'projet', $id,'projet&project');
  44. $hookmanager->initHooks(array('projectcontactcard','globalcard'));
  45. /*
  46. * Actions
  47. */
  48. // Add new contact
  49. if ($action == 'addcontact' && $user->rights->projet->creer)
  50. {
  51. $result = 0;
  52. $result = $object->fetch($id);
  53. if ($result > 0 && $id > 0)
  54. {
  55. $contactid = (GETPOST('userid') ? GETPOST('userid','int') : GETPOST('contactid','int'));
  56. $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
  57. }
  58. if ($result >= 0)
  59. {
  60. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  61. exit;
  62. }
  63. else
  64. {
  65. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  66. {
  67. $langs->load("errors");
  68. setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
  69. }
  70. else
  71. {
  72. setEventMessages($object->error, $object->errors, 'errors');
  73. }
  74. }
  75. }
  76. // bascule du statut d'un contact
  77. if ($action == 'swapstatut' && $user->rights->projet->creer)
  78. {
  79. if ($object->fetch($id))
  80. {
  81. $result=$object->swapContactStatus(GETPOST('ligne','int'));
  82. }
  83. else
  84. {
  85. dol_print_error($db);
  86. }
  87. }
  88. // Efface un contact
  89. if (($action == 'deleteline' || $action == 'deletecontact') && $user->rights->projet->creer)
  90. {
  91. $object->fetch($id);
  92. $result = $object->delete_contact(GETPOST("lineid"));
  93. if ($result >= 0)
  94. {
  95. header("Location: contact.php?id=".$object->id);
  96. exit;
  97. }
  98. else
  99. {
  100. dol_print_error($db);
  101. }
  102. }
  103. /*
  104. * View
  105. */
  106. $title=$langs->trans("ProjectContact").' - '.$object->ref.' '.$object->name;
  107. 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");
  108. $help_url="EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
  109. llxHeader('', $title, $help_url);
  110. $form = new Form($db);
  111. $formcompany= new FormCompany($db);
  112. $contactstatic=new Contact($db);
  113. $userstatic=new User($db);
  114. /* *************************************************************************** */
  115. /* */
  116. /* Mode vue et edition */
  117. /* */
  118. /* *************************************************************************** */
  119. if ($id > 0 || ! empty($ref))
  120. {
  121. if(! empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($object, 'fetchComments') && empty($object->comments)) $object->fetchComments();
  122. // To verify role of users
  123. //$userAccess = $object->restrictedProjectArea($user,'read');
  124. $userWrite = $object->restrictedProjectArea($user,'write');
  125. //$userDelete = $object->restrictedProjectArea($user,'delete');
  126. //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
  127. $head = project_prepare_head($object);
  128. dol_fiche_head($head, 'contact', $langs->trans("Project"), -1, ($object->public?'projectpub':'project'));
  129. // Project card
  130. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  131. $morehtmlref='<div class="refidno">';
  132. // Title
  133. $morehtmlref.=$object->title;
  134. // Thirdparty
  135. if ($object->thirdparty->id > 0)
  136. {
  137. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1, 'project');
  138. }
  139. $morehtmlref.='</div>';
  140. // Define a complementary filter for search of next/prev ref.
  141. if (! $user->rights->projet->all->lire)
  142. {
  143. $objectsListId = $object->getProjectsAuthorizedForUser($user,0,0);
  144. $object->next_prev_filter=" rowid in (".(count($objectsListId)?join(',',array_keys($objectsListId)):'0').")";
  145. }
  146. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  147. print '<div class="fichecenter">';
  148. print '<div class="fichehalfleft">';
  149. print '<div class="underbanner clearboth"></div>';
  150. print '<table class="border" width="100%">';
  151. // Visibility
  152. print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
  153. if ($object->public) print $langs->trans('SharedProject');
  154. else print $langs->trans('PrivateProject');
  155. print '</td></tr>';
  156. if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES))
  157. {
  158. // Opportunity status
  159. print '<tr><td>'.$langs->trans("OpportunityStatus").'</td><td>';
  160. $code = dol_getIdFromCode($db, $object->opp_status, 'c_lead_status', 'rowid', 'code');
  161. if ($code) print $langs->trans("OppStatus".$code);
  162. print '</td></tr>';
  163. // Opportunity percent
  164. print '<tr><td>'.$langs->trans("OpportunityProbability").'</td><td>';
  165. if (strcmp($object->opp_percent,'')) print price($object->opp_percent,'',$langs,1,0).' %';
  166. print '</td></tr>';
  167. // Opportunity Amount
  168. print '<tr><td>'.$langs->trans("OpportunityAmount").'</td><td>';
  169. if (strcmp($object->opp_amount,'')) print price($object->opp_amount,'',$langs,0,0,0,$conf->currency);
  170. print '</td></tr>';
  171. }
  172. // Date start - end
  173. print '<tr><td>'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
  174. $start = dol_print_date($object->date_start,'day');
  175. print ($start?$start:'?');
  176. $end = dol_print_date($object->date_end,'day');
  177. print ' - ';
  178. print ($end?$end:'?');
  179. if ($object->hasDelay()) print img_warning("Late");
  180. print '</td></tr>';
  181. // Budget
  182. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  183. if (strcmp($object->budget_amount, '')) print price($object->budget_amount,'',$langs,0,0,0,$conf->currency);
  184. print '</td></tr>';
  185. // Other attributes
  186. $cols = 2;
  187. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  188. print "</table>";
  189. print '</div>';
  190. print '<div class="fichehalfright">';
  191. print '<div class="ficheaddleft">';
  192. print '<div class="underbanner clearboth"></div>';
  193. print '<table class="border" width="100%">';
  194. // Description
  195. print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
  196. print nl2br($object->description);
  197. print '</td></tr>';
  198. // Bill time
  199. if (! empty($conf->global->PROJECT_BILL_TIME_SPENT))
  200. {
  201. print '<tr><td>'.$langs->trans("BillTime").'</td><td>';
  202. print yn($object->bill_time);
  203. print '</td></tr>';
  204. }
  205. // Categories
  206. if ($conf->categorie->enabled) {
  207. print '<tr><td valign="middle">'.$langs->trans("Categories").'</td><td>';
  208. print $form->showCategories($object->id,'project',1);
  209. print "</td></tr>";
  210. }
  211. print '</table>';
  212. print '</div>';
  213. print '</div>';
  214. print '</div>';
  215. print '<div class="clearboth"></div>';
  216. dol_fiche_end();
  217. print '<br>';
  218. // Contacts lines (modules that overwrite templates must declare this into descriptor)
  219. $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
  220. foreach($dirtpls as $reldir)
  221. {
  222. $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
  223. if ($res) break;
  224. }
  225. }
  226. // End of page
  227. llxFooter();
  228. $db->close();