PageRenderTime 35ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/societe/societe.php

https://bitbucket.org/speedealing/speedealing
PHP | 434 lines | 295 code | 47 blank | 92 comment | 68 complexity | 7c3a2dd4b54f76be47da134398bcc139 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2012 Marcos GarcĂ­a <marcosgdf@gmail.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/societe/societe.php
  22. * \ingroup societe
  23. * \brief Page to show a third party
  24. */
  25. require_once '../main.inc.php';
  26. include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  28. $langs->load("companies");
  29. $langs->load("customers");
  30. $langs->load("suppliers");
  31. // Security check
  32. $socid = GETPOST('socid','int');
  33. if ($user->societe_id) $socid=$user->societe_id;
  34. $result = restrictedArea($user,'societe',$socid,'');
  35. $search_nom=trim(GETPOST("search_nom"));
  36. $search_nom_only=trim(GETPOST("search_nom_only"));
  37. $search_all=trim(GETPOST("search_all"));
  38. $search_ville=trim(GETPOST("search_ville"));
  39. $socname=trim(GETPOST("socname"));
  40. $search_idprof1=trim(GETPOST('search_idprof1'));
  41. $search_idprof2=trim(GETPOST('search_idprof2'));
  42. $search_idprof3=trim(GETPOST('search_idprof3'));
  43. $search_idprof4=trim(GETPOST('search_idprof4'));
  44. $search_sale=trim(GETPOST("search_sale"));
  45. $search_categ=trim(GETPOST("search_categ"));
  46. $mode=GETPOST("mode");
  47. $modesearch=GETPOST("mode_search");
  48. $sortfield=GETPOST("sortfield",'alpha');
  49. $sortorder=GETPOST("sortorder",'alpha');
  50. $page=GETPOST("page",'int');
  51. if (! $sortorder) $sortorder="ASC";
  52. if (! $sortfield) $sortfield="s.nom";
  53. if ($page == -1) { $page = 0 ; }
  54. $offset = $conf->liste_limit * $page ;
  55. $pageprev = $page - 1;
  56. $pagenext = $page + 1;
  57. /*
  58. * Actions
  59. */
  60. // Recherche
  61. if ($mode == 'search')
  62. {
  63. $search_nom=$socname;
  64. $sql = "SELECT s.rowid";
  65. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  66. if ($search_sale || !$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  67. // We'll need this table joined to the select in order to filter by categ
  68. if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_societe as cs";
  69. $sql.= " WHERE s.entity IN (".getEntity('societe', 1).")";
  70. $sql.= " AND (";
  71. $sql.= " s.nom LIKE '%".$db->escape($socname)."%'";
  72. $sql.= " OR s.code_client LIKE '%".$db->escape($socname)."%'";
  73. $sql.= " OR s.email LIKE '%".$db->escape($socname)."%'";
  74. $sql.= " OR s.url LIKE '%".$db->escape($socname)."%'";
  75. if (!empty($conf->barcode->enabled))
  76. {
  77. $sql.= "OR s.barcode LIKE '".$db->escape($socname)."'";
  78. }
  79. $sql.= ")";
  80. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  81. if ($socid) $sql.= " AND s.rowid = ".$socid;
  82. if ($search_sale) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
  83. if ($search_categ) $sql.= " AND s.rowid = cs.fk_societe"; // Join for the needed table to filter by categ
  84. if (! $user->rights->societe->lire || ! $user->rights->fournisseur->lire)
  85. {
  86. if (! $user->rights->fournisseur->lire) $sql.=" AND s.fourn != 1";
  87. }
  88. // Insert sale filter
  89. if ($search_sale)
  90. {
  91. $sql .= " AND sc.fk_user = ".$search_sale;
  92. }
  93. // Insert categ filter
  94. if ($search_categ)
  95. {
  96. $sql .= " AND cs.fk_categorie = ".$search_categ;
  97. }
  98. $result=$db->query($sql);
  99. if ($result)
  100. {
  101. if ($db->num_rows($result) == 1)
  102. {
  103. $obj = $db->fetch_object($result);
  104. $socid = $obj->rowid;
  105. header("Location: ".DOL_URL_ROOT."/societe/soc.php?socid=".$socid);
  106. exit;
  107. }
  108. $db->free($result);
  109. }
  110. }
  111. /*
  112. * View
  113. */
  114. $form=new Form($db);
  115. $htmlother=new FormOther($db);
  116. $companystatic=new Societe($db);
  117. llxHeader('',$langs->trans("ThirdParty"));
  118. // Do we click on purge search criteria ?
  119. if (GETPOST("button_removefilter_x"))
  120. {
  121. $search_categ='';
  122. $search_sale='';
  123. $socname="";
  124. $search_nom="";
  125. $search_ville="";
  126. $search_idprof1='';
  127. $search_idprof2='';
  128. $search_idprof3='';
  129. $search_idprof4='';
  130. }
  131. if ($socname)
  132. {
  133. $search_nom=$socname;
  134. }
  135. /*
  136. * Mode Liste
  137. */
  138. /*
  139. REM: Regle sur droits "Voir tous les clients"
  140. REM: Exemple, voir la page societe.php dans le mode liste.
  141. Utilisateur interne socid=0 + Droits voir tous clients => Voit toute societe
  142. Utilisateur interne socid=0 + Pas de droits voir tous clients => Ne voit que les societes liees comme commercial
  143. Utilisateur externe socid=x + Droits voir tous clients => Ne voit que lui meme
  144. Utilisateur externe socid=x + Pas de droits voir tous clients => Ne voit que lui meme
  145. */
  146. $title=$langs->trans("ListOfThirdParties");
  147. $sql = "SELECT s.rowid, s.nom as name, s.ville, s.datec, s.datea,";
  148. $sql.= " st.libelle as stcomm, s.prefix_comm, s.client, s.fournisseur, s.canvas, s.status as status,";
  149. $sql.= " s.siren as idprof1, s.siret as idprof2, ape as idprof3, idprof4 as idprof4";
  150. // We'll need these fields in order to filter by sale (including the case where the user can only see his prospects)
  151. if ($search_sale) $sql .= ", sc.fk_soc, sc.fk_user";
  152. // We'll need these fields in order to filter by categ
  153. if ($search_categ) $sql .= ", cs.fk_categorie, cs.fk_societe";
  154. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,";
  155. $sql.= " ".MAIN_DB_PREFIX."c_stcomm as st";
  156. // We'll need this table joined to the select in order to filter by sale
  157. if ($search_sale || !$user->rights->societe->client->voir) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  158. // We'll need this table joined to the select in order to filter by categ
  159. if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_societe as cs";
  160. $sql.= " WHERE s.fk_stcomm = st.id";
  161. $sql.= " AND s.entity IN (".getEntity('societe', 1).")";
  162. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  163. if ($socid) $sql.= " AND s.rowid = ".$socid;
  164. if ($search_sale) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
  165. if ($search_categ) $sql.= " AND s.rowid = cs.fk_societe"; // Join for the needed table to filter by categ
  166. // TODO $stcomm is not defined !
  167. /*
  168. if (dol_strlen($stcomm))
  169. {
  170. $sql.= " AND s.fk_stcomm=".$stcomm;
  171. }
  172. */
  173. if (! $user->rights->fournisseur->lire) $sql.=" AND (s.fournisseur <> 1 OR s.client <> 0)"; // client=0, fournisseur=0 must be visible
  174. // Insert sale filter
  175. if ($search_sale)
  176. {
  177. $sql .= " AND sc.fk_user = ".$search_sale;
  178. }
  179. // Insert categ filter
  180. if ($search_categ)
  181. {
  182. $sql .= " AND cs.fk_categorie = ".$search_categ;
  183. }
  184. if ($search_nom_only)
  185. {
  186. $sql.= " AND s.nom LIKE '%".$db->escape($search_nom_only)."%'";
  187. }
  188. if ($search_all)
  189. {
  190. $sql.= " AND (";
  191. $sql.= "s.nom LIKE '%".$db->escape($search_all)."%'";
  192. $sql.= " OR s.code_client LIKE '%".$db->escape($search_all)."%'";
  193. $sql.= " OR s.email LIKE '%".$db->escape($search_all)."%'";
  194. $sql.= " OR s.url LIKE '%".$db->escape($search_all)."%'";
  195. $sql.= ")";
  196. }
  197. if ($search_nom)
  198. {
  199. $sql.= " AND (";
  200. $sql.= "s.nom LIKE '%".$db->escape($search_nom)."%'";
  201. $sql.= " OR s.code_client LIKE '%".$db->escape($search_nom)."%'";
  202. $sql.= " OR s.email LIKE '%".$db->escape($search_nom)."%'";
  203. $sql.= " OR s.url LIKE '%".$db->escape($search_nom)."%'";
  204. $sql.= ")";
  205. }
  206. if ($search_ville)
  207. {
  208. $sql .= " AND s.ville LIKE '%".$db->escape($search_ville)."%'";
  209. }
  210. if ($search_idprof1)
  211. {
  212. $sql .= " AND s.siren LIKE '%".$db->escape($search_idprof1)."%'";
  213. }
  214. if ($search_idprof2)
  215. {
  216. $sql .= " AND s.siret LIKE '%".$db->escape($search_idprof2)."%'";
  217. }
  218. if ($search_idprof3)
  219. {
  220. $sql .= " AND s.ape LIKE '%".$db->escape($search_idprof3)."%'";
  221. }
  222. if ($search_idprof4)
  223. {
  224. $sql .= " AND s.idprof4 LIKE '%".$db->escape($search_idprof4)."%'";
  225. }
  226. //print $sql;
  227. // Count total nb of records
  228. $nbtotalofrecords = 0;
  229. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  230. {
  231. $result = $db->query($sql);
  232. $nbtotalofrecords = $db->num_rows($result);
  233. }
  234. $sql.= $db->order($sortfield,$sortorder);
  235. $sql.= $db->plimit($conf->liste_limit+1, $offset);
  236. $resql = $db->query($sql);
  237. if ($resql)
  238. {
  239. $num = $db->num_rows($resql);
  240. $i = 0;
  241. $params = "&amp;socname=".$socname."&amp;search_nom=".$search_nom."&amp;search_ville=".$search_ville;
  242. $params.= '&amp;search_idprof1='.$search_idprof1;
  243. $params.= '&amp;search_idprof2='.$search_idprof2;
  244. $params.= '&amp;search_idprof3='.$search_idprof3;
  245. $params.= '&amp;search_idprof4='.$search_idprof4;
  246. print_barre_liste($title, $page, $_SERVER["PHP_SELF"],$params,$sortfield,$sortorder,'',$num,$nbtotalofrecords);
  247. // Show delete result message
  248. if (GETPOST('delsoc'))
  249. {
  250. dol_htmloutput_mesg($langs->trans("CompanyDeleted",GETPOST('delsoc')),'','ok');
  251. }
  252. $langs->load("other");
  253. $textprofid=array();
  254. foreach(array(1,2,3,4) as $key)
  255. {
  256. $label=$langs->transnoentities("ProfId".$key.$mysoc->country_code);
  257. $textprofid[$key]='';
  258. if ($label != "ProfId".$key.$mysoc->country_code)
  259. { // Get only text between ()
  260. if (preg_match('/\((.*)\)/i',$label,$reg)) $label=$reg[1];
  261. $textprofid[$key]=$langs->trans("ProfIdShortDesc",$key,$mysoc->country_code,$label);
  262. }
  263. }
  264. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
  265. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  266. print '<table class="liste" width="100%">';
  267. // Filter on categories
  268. /* Not possible in this page because list is for ALL third parties type
  269. $moreforfilter='';
  270. if (! empty($conf->categorie->enabled))
  271. {
  272. $moreforfilter.=$langs->trans('Categories'). ': ';
  273. $moreforfilter.=$htmlother->select_categories(2,$search_categ,'search_categ');
  274. $moreforfilter.=' &nbsp; &nbsp; &nbsp; ';
  275. }
  276. // If the user can view prospects other than his'
  277. if ($user->rights->societe->client->voir || $socid)
  278. {
  279. $moreforfilter.=$langs->trans('SalesRepresentatives'). ': ';
  280. $moreforfilter.=$htmlother->select_salesrepresentatives($search_sale,'search_sale',$user);
  281. }
  282. if ($moreforfilter)
  283. {
  284. print '<tr class="liste_titre">';
  285. print '<td class="liste_titre" colspan="8">';
  286. print $moreforfilter;
  287. print '</td></tr>';
  288. }
  289. */
  290. // Lines of titles
  291. print '<tr class="liste_titre">';
  292. print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","",$params,"",$sortfield,$sortorder);
  293. print_liste_field_titre($langs->trans("Town"),$_SERVER["PHP_SELF"],"s.ville","",$params,'',$sortfield,$sortorder);
  294. print_liste_field_titre($form->textwithpicto($langs->trans("ProfId1Short"),$textprofid[1],1,0),$_SERVER["PHP_SELF"],"s.siren","",$params,'nowrap="nowrap"',$sortfield,$sortorder);
  295. print_liste_field_titre($form->textwithpicto($langs->trans("ProfId2Short"),$textprofid[2],1,0),$_SERVER["PHP_SELF"],"s.siret","",$params,'nowrap="nowrap"',$sortfield,$sortorder);
  296. print_liste_field_titre($form->textwithpicto($langs->trans("ProfId3Short"),$textprofid[3],1,0),$_SERVER["PHP_SELF"],"s.ape","",$params,'nowrap="nowrap"',$sortfield,$sortorder);
  297. print_liste_field_titre($form->textwithpicto($langs->trans("ProfId4Short"),$textprofid[4],1,0),$_SERVER["PHP_SELF"],"s.idprof4","",$params,'nowrap="nowrap"',$sortfield,$sortorder);
  298. print '<td></td>';
  299. print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"s.status","",$params,'align="right"',$sortfield,$sortorder);
  300. print "</tr>\n";
  301. // Lignes des champs de filtre
  302. print '<tr class="liste_titre">';
  303. print '<td class="liste_titre">';
  304. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  305. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  306. if (! empty($search_nom_only) && empty($search_nom)) $search_nom=$search_nom_only;
  307. print '<input class="flat" type="text" name="search_nom" value="'.$search_nom.'">';
  308. print '</td><td class="liste_titre">';
  309. print '<input class="flat" size="10" type="text" name="search_ville" value="'.$search_ville.'">';
  310. print '</td>';
  311. // IdProf1
  312. print '<td class="liste_titre">';
  313. print '<input class="flat" size="8" type="text" name="search_idprof1" value="'.$search_idprof1.'">';
  314. print '</td>';
  315. // IdProf2
  316. print '<td class="liste_titre">';
  317. print '<input class="flat" size="8" type="text" name="search_idprof2" value="'.$search_idprof2.'">';
  318. print '</td>';
  319. // IdProf3
  320. print '<td class="liste_titre">';
  321. print '<input class="flat" size="8" type="text" name="search_idprof3" value="'.$search_idprof3.'">';
  322. print '</td>';
  323. // IdProf4
  324. print '<td class="liste_titre">';
  325. print '<input class="flat" size="8" type="text" name="search_idprof4" value="'.$search_idprof4.'">';
  326. print '</td>';
  327. // Type (customer/prospect/supplier)
  328. print '<td colspan="2" class="liste_titre" align="right">';
  329. print '<input type="image" class="liste_titre" name="button_search" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
  330. print '&nbsp; ';
  331. print '<input type="image" class="liste_titre" name="button_removefilter" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/searchclear.png" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
  332. print '</td>';
  333. print "</tr>\n";
  334. $var=True;
  335. while ($i < min($num,$conf->liste_limit))
  336. {
  337. $obj = $db->fetch_object($resql);
  338. $var=!$var;
  339. print "<tr $bc[$var]><td>";
  340. $companystatic->id=$obj->rowid;
  341. $companystatic->name=$obj->name;
  342. $companystatic->canvas=$obj->canvas;
  343. $companystatic->client=$obj->client;
  344. $companystatic->status=$obj->status;
  345. print $companystatic->getNomUrl(1,'',24);
  346. print "</td>\n";
  347. print "<td>".$obj->ville."</td>\n";
  348. print "<td>".$obj->idprof1."</td>\n";
  349. print "<td>".$obj->idprof2."</td>\n";
  350. print "<td>".$obj->idprof3."</td>\n";
  351. print "<td>".$obj->idprof4."</td>\n";
  352. print '<td align="center">';
  353. $s='';
  354. if (($obj->client==1 || $obj->client==3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS))
  355. {
  356. $companystatic->name=$langs->trans("Customer");
  357. $s.=$companystatic->getNomUrl(0,'customer');
  358. }
  359. if (($obj->client==2 || $obj->client==3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
  360. {
  361. if ($s) $s.=" / ";
  362. $companystatic->name=$langs->trans("Prospect");
  363. $s.=$companystatic->getNomUrl(0,'prospect');
  364. }
  365. if (! empty($conf->fournisseur->enabled) && $obj->fournisseur)
  366. {
  367. if ($s) $s.=" / ";
  368. $companystatic->name=$langs->trans("Supplier");
  369. $s.=$companystatic->getNomUrl(0,'supplier');
  370. }
  371. print $s;
  372. print '</td>';
  373. print '<td align="right">'.$companystatic->getLibStatut(3).'</td>';
  374. print '</tr>'."\n";
  375. $i++;
  376. }
  377. $db->free($resql);
  378. print "</table>";
  379. print '</form>';
  380. }
  381. else
  382. {
  383. dol_print_error($db);
  384. }
  385. llxFooter();
  386. $db->close();
  387. ?>