societecontact.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <?php
  2. /* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net>
  3. * Copyright (C) 2005-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2011-2015 Philippe Grand <philippe.grand@atoo-net.com>
  6. * Copyright (C) 2014 Charles-Fr Benke <charles.fr@benke.fr>
  7. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/societe/societecontact.php
  24. * \ingroup societe
  25. * \brief Onglet de gestion des contacts additionnel d'une société
  26. */
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  32. $langs->loadLangs(array("orders", "companies"));
  33. $id=GETPOST('id','int')?GETPOST('id','int'):GETPOST('socid','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, 'societe', $id,'');
  39. $object = new Societe($db);
  40. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  41. $hookmanager->initHooks(array('contactthirdparty','globalcard'));
  42. /*
  43. * Actions
  44. */
  45. if ($action == 'addcontact' && $user->rights->societe->creer)
  46. {
  47. $result = $object->fetch($id);
  48. if ($result > 0 && $id > 0)
  49. {
  50. $contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int'));
  51. $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
  52. }
  53. if ($result >= 0)
  54. {
  55. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  56. exit;
  57. }
  58. else
  59. {
  60. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  61. {
  62. $langs->load("errors");
  63. $mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
  64. }
  65. else
  66. {
  67. $mesg = '<div class="error">'.$object->error.'</div>';
  68. }
  69. }
  70. }
  71. // bascule du statut d'un contact
  72. else if ($action == 'swapstatut' && $user->rights->societe->creer)
  73. {
  74. if ($object->fetch($id))
  75. {
  76. $result=$object->swapContactStatus(GETPOST('ligne'));
  77. }
  78. else
  79. {
  80. dol_print_error($db);
  81. }
  82. }
  83. // Efface un contact
  84. else if ($action == 'deletecontact' && $user->rights->societe->creer)
  85. {
  86. $object->fetch($id);
  87. $result = $object->delete_contact($_GET["lineid"]);
  88. if ($result >= 0)
  89. {
  90. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  91. exit;
  92. }
  93. else {
  94. dol_print_error($db);
  95. }
  96. }
  97. /*
  98. else if ($action == 'setaddress' && $user->rights->societe->creer)
  99. {
  100. $object->fetch($id);
  101. $result=$object->setDeliveryAddress($_POST['fk_address']);
  102. if ($result < 0) dol_print_error($db,$object->error);
  103. }*/
  104. /*
  105. * View
  106. */
  107. $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  108. llxHeader('',$langs->trans("ThirdParty"),$help_url);
  109. $form = new Form($db);
  110. $formcompany = new FormCompany($db);
  111. $formother = new FormOther($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 ($object->fetch($id, $ref) > 0)
  122. {
  123. $soc = new Societe($db);
  124. $soc->fetch($object->socid);
  125. $head = societe_prepare_head($object);
  126. dol_fiche_head($head, 'contact', $langs->trans("ThirdParty"), -1, 'company');
  127. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  128. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  129. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  130. dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');
  131. print '<div class="fichecenter">';
  132. print '<div class="underbanner clearboth"></div>';
  133. print '<table class="border centpercent">';
  134. // Prospect/Customer
  135. /*print '<tr><td class="titlefield">'.$langs->trans('ProspectCustomer').'</td><td>';
  136. print $object->getLibCustProspStatut();
  137. print '</td></tr>';
  138. // Supplier
  139. print '<tr><td>'.$langs->trans('Supplier').'</td><td>';
  140. print yn($object->fournisseur);
  141. print '</td></tr>';*/
  142. if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field
  143. {
  144. print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
  145. }
  146. if ($object->client)
  147. {
  148. print '<tr><td class="titlefield">';
  149. print $langs->trans('CustomerCode').'</td><td colspan="3">';
  150. print $object->code_client;
  151. if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
  152. print '</td></tr>';
  153. }
  154. if ($object->fournisseur)
  155. {
  156. print '<tr><td class="titlefield">';
  157. print $langs->trans('SupplierCode').'</td><td colspan="3">';
  158. print $object->code_fournisseur;
  159. if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
  160. print '</td></tr>';
  161. }
  162. print '</table>';
  163. print '</div>';
  164. print '</form>';
  165. print '<br>';
  166. // Contacts lines (modules that overwrite templates must declare this into descriptor)
  167. $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
  168. foreach($dirtpls as $reldir)
  169. {
  170. $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
  171. if ($res) break;
  172. }
  173. // additionnal list with adherents of company
  174. if (! empty($conf->adherent->enabled) && $user->rights->adherent->lire)
  175. {
  176. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  177. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  178. $membertypestatic=new AdherentType($db);
  179. $memberstatic=new Adherent($db);
  180. $langs->load("members");
  181. $sql = "SELECT d.rowid, d.login, d.lastname, d.firstname, d.societe as company, d.fk_soc,";
  182. $sql.= " d.datefin,";
  183. $sql.= " d.email, d.fk_adherent_type as type_id, d.morphy, d.statut,";
  184. $sql.= " t.libelle as type, t.subscription";
  185. $sql.= " FROM ".MAIN_DB_PREFIX."adherent as d";
  186. $sql.= ", ".MAIN_DB_PREFIX."adherent_type as t";
  187. $sql.= " WHERE d.fk_soc = ".$id;
  188. $sql.= " AND d.fk_adherent_type = t.rowid";
  189. dol_syslog("get list sql=".$sql);
  190. $resql = $db->query($sql);
  191. if ($resql)
  192. {
  193. $num = $db->num_rows($resql);
  194. if ($num > 0 )
  195. {
  196. $titre=$langs->trans("MembersListOfTiers");
  197. print '<br>';
  198. print_barre_liste($titre,$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords,'');
  199. print "<table class=\"noborder\" width=\"100%\">";
  200. print '<tr class="liste_titre">';
  201. print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"d.rowid",$param,"","",$sortfield,$sortorder);
  202. print_liste_field_titre( $langs->trans("Name")." / ".$langs->trans("Company"),$_SERVER["PHP_SELF"],"d.lastname",$param,"","",$sortfield,$sortorder);
  203. print_liste_field_titre("Login",$_SERVER["PHP_SELF"],"d.login",$param,"","",$sortfield,$sortorder);
  204. print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"t.libelle",$param,"","",$sortfield,$sortorder);
  205. print_liste_field_titre("Person",$_SERVER["PHP_SELF"],"d.morphy",$param,"","",$sortfield,$sortorder);
  206. print_liste_field_titre("EMail",$_SERVER["PHP_SELF"],"d.email",$param,"","",$sortfield,$sortorder);
  207. print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"d.statut,d.datefin",$param,"","",$sortfield,$sortorder);
  208. print_liste_field_titre("EndSubscription",$_SERVER["PHP_SELF"],"d.datefin",$param,"",'align="center"',$sortfield,$sortorder);
  209. print "</tr>\n";
  210. $i=0;
  211. while ($i < $num && $i < $conf->liste_limit)
  212. {
  213. $objp = $db->fetch_object($resql);
  214. $datefin=$db->jdate($objp->datefin);
  215. $memberstatic->id=$objp->rowid;
  216. $memberstatic->ref=$objp->rowid;
  217. $memberstatic->lastname=$objp->lastname;
  218. $memberstatic->firstname=$objp->firstname;
  219. $memberstatic->statut=$objp->statut;
  220. $memberstatic->datefin=$db->jdate($objp->datefin);
  221. $companyname=$objp->company;
  222. print '<tr class="oddeven">';
  223. // Ref
  224. print "<td>";
  225. print $memberstatic->getNomUrl(1);
  226. print "</td>\n";
  227. // Lastname
  228. print "<td><a href=\"card.php?rowid=$objp->rowid\">";
  229. print ((! empty($objp->lastname) || ! empty($objp->firstname)) ? dol_trunc($memberstatic->getFullName($langs)) : '');
  230. print (((! empty($objp->lastname) || ! empty($objp->firstname)) && ! empty($companyname)) ? ' / ' : '');
  231. print (! empty($companyname) ? dol_trunc($companyname, 32) : '');
  232. print "</a></td>\n";
  233. // Login
  234. print "<td>".$objp->login."</td>\n";
  235. // Type
  236. $membertypestatic->id=$objp->type_id;
  237. $membertypestatic->libelle=$objp->type;
  238. print '<td class="nowrap">';
  239. print $membertypestatic->getNomUrl(1,32);
  240. print '</td>';
  241. // Moral/Physique
  242. print "<td>".$memberstatic->getmorphylib($objp->morphy)."</td>\n";
  243. // EMail
  244. print "<td>".dol_print_email($objp->email,0,0,1)."</td>\n";
  245. // Statut
  246. print '<td class="nowrap">';
  247. print $memberstatic->LibStatut($objp->statut,$objp->subscription,$datefin,2);
  248. print "</td>";
  249. // End of subscription date
  250. if ($datefin)
  251. {
  252. print '<td align="center" class="nowrap">';
  253. print dol_print_date($datefin,'day');
  254. if ($memberstatic->hasDelay()) {
  255. print " ".img_warning($langs->trans("SubscriptionLate"));
  256. }
  257. print '</td>';
  258. }
  259. else
  260. {
  261. print '<td align="left" class="nowrap">';
  262. if ($objp->subscription == 'yes')
  263. {
  264. print $langs->trans("SubscriptionNotReceived");
  265. if ($objp->statut > 0) print " ".img_warning();
  266. }
  267. else
  268. {
  269. print '&nbsp;';
  270. }
  271. print '</td>';
  272. }
  273. print "</tr>\n";
  274. $i++;
  275. }
  276. print "</table>\n";
  277. }
  278. }
  279. }
  280. }
  281. else
  282. {
  283. // Contrat non trouve
  284. print "ErrorRecordNotFound";
  285. }
  286. }
  287. // End of page
  288. llxFooter();
  289. $db->close();