list.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <?php
  2. /* Copyright (C) 2001-2003 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) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  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/don/list.php
  22. * \ingroup donations
  23. * \brief List of donations
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
  27. if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  28. $langs->load("companies");
  29. $langs->load("donations");
  30. $sortfield = GETPOST("sortfield",'alpha');
  31. $sortorder = GETPOST("sortorder",'alpha');
  32. $page = GETPOST("page",'int');
  33. $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
  34. if ($page == -1) { $page = 0; }
  35. $offset = $limit * $page;
  36. $pageprev = $page - 1;
  37. $pagenext = $page + 1;
  38. if (! $sortorder) $sortorder="DESC";
  39. if (! $sortfield) $sortfield="d.datedon";
  40. $statut=isset($_GET["statut"])?$_GET["statut"]:"-1";
  41. $search_all=GETPOST('sall','alpha');
  42. $search_ref=GETPOST('search_ref','alpha');
  43. $search_company=GETPOST('search_company','alpha');
  44. $search_name=GETPOST('search_name','alpha');
  45. $search_amount = GETPOST('search_amount','alpha');
  46. $optioncss = GETPOST('optioncss','alpha');
  47. if (!$user->rights->don->lire) accessforbidden();
  48. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers
  49. {
  50. $search_all="";
  51. $search_ref="";
  52. $search_company="";
  53. $search_name="";
  54. $search_amount="";
  55. }
  56. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  57. $hookmanager->initHooks(array('orderlist'));
  58. // List of fields to search into when doing a "search in all"
  59. $fieldstosearchall = array(
  60. 'd.rowid'=>'Id',
  61. 'd.ref'=>'Ref',
  62. 'd.lastname'=>'Lastname',
  63. 'd.firstname'=>'Firstname',
  64. );
  65. /*
  66. * View
  67. */
  68. if (! empty($conf->projet->enabled)) $projectstatic=new Project($db);
  69. llxHeader('',$langs->trans("Donations"),'EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones');
  70. $donationstatic=new Don($db);
  71. // Genere requete de liste des dons
  72. $sql = "SELECT d.rowid, d.datedon, d.firstname, d.lastname, d.societe,";
  73. $sql.= " d.amount, d.fk_statut as statut, ";
  74. $sql.= " p.rowid as pid, p.ref, p.title, p.public";
  75. $sql.= " FROM ".MAIN_DB_PREFIX."don as d LEFT JOIN ".MAIN_DB_PREFIX."projet AS p";
  76. $sql.= " ON p.rowid = d.fk_projet WHERE 1 = 1";
  77. if ($statut >= 0)
  78. {
  79. $sql .= " AND d.fk_statut = ".$statut;
  80. }
  81. if (trim($search_ref) != '')
  82. {
  83. $sql.= ' AND d.rowid LIKE \'%'.$db->escape(trim($search_ref)) . '%\'';
  84. }
  85. if (trim($search_all) != '')
  86. {
  87. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  88. }
  89. if (trim($search_company) != '')
  90. {
  91. $sql .= natural_search('d.societe', $search_company);
  92. }
  93. if (trim($search_name) != '')
  94. {
  95. $sql .= natural_search(array('d.lastname', 'd.firstname'), $search_name);
  96. }
  97. if ($search_amount) $sql.= natural_search(array('d.amount'), price2num(trim($search_amount)), 1);
  98. $sql.= $db->order($sortfield,$sortorder);
  99. $sql.= $db->plimit($limit+1, $offset);
  100. $resql = $db->query($sql);
  101. if ($resql)
  102. {
  103. $num = $db->num_rows($resql);
  104. $i = 0;
  105. $param = '&statut='.$statut;
  106. if ($page > 0) $param.= '&page='.$page;
  107. if ($optioncss != '') $param.='&optioncss='.$optioncss;
  108. if ($statut >= 0)
  109. {
  110. $donationstatic->statut=$statut;
  111. $label=$donationstatic->getLibStatut(0);
  112. print_barre_liste($label, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num);
  113. }
  114. else
  115. {
  116. print_barre_liste($langs->trans("Donations"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num);
  117. }
  118. print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  119. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  120. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  121. print '<input type="hidden" name="action" value="list">';
  122. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  123. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  124. print '<input type="hidden" name="type" value="'.$type.'">';
  125. if ($search_all)
  126. {
  127. foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
  128. print $langs->trans("FilterOnInto", $search_all) . join(', ',$fieldstosearchall);
  129. }
  130. print "<table class=\"noborder\" width=\"100%\">";
  131. print '<tr class="liste_titre">';
  132. print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"d.rowid","", $param,"",$sortfield,$sortorder);
  133. print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"d.societe","", $param,"",$sortfield,$sortorder);
  134. print_liste_field_titre($langs->trans("Name"),$_SERVER["PHP_SELF"],"d.lastname","", $param,"",$sortfield,$sortorder);
  135. print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"],"d.datedon","", $param,'align="center"',$sortfield,$sortorder);
  136. if (! empty($conf->projet->enabled))
  137. {
  138. $langs->load("projects");
  139. print_liste_field_titre($langs->trans("Project"),$_SERVER["PHP_SELF"],"fk_projet","", $param,"",$sortfield,$sortorder);
  140. }
  141. print_liste_field_titre($langs->trans("Amount"),$_SERVER["PHP_SELF"],"d.amount","", $param,'align="right"',$sortfield,$sortorder);
  142. print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"d.fk_statut","", $param,'align="right"',$sortfield,$sortorder);
  143. print_liste_field_titre('');
  144. print "</tr>\n";
  145. // Filters lines
  146. print '<tr class="liste_titre">';
  147. print '<td class="liste_titre">';
  148. print '<input class="flat" size="10" type="text" name="search_ref" value="'.$search_ref.'">';
  149. print '</td>';
  150. print '<td class="liste_titre">';
  151. print '<input class="flat" size="10" type="text" name="search_company" value="'.$search_company.'">';
  152. print '</td>';
  153. print '<td class="liste_titre">';
  154. print '<input class="flat" size="10" type="text" name="search_name" value="'.$search_name.'">';
  155. print '</td>';
  156. print '<td class="liste_titre" align="left">';
  157. print '&nbsp;';
  158. print '</td>';
  159. if (! empty($conf->projet->enabled))
  160. {
  161. print '<td class="liste_titre" align="right">';
  162. print '&nbsp;';
  163. print '</td>';
  164. }
  165. print '<td class="liste_titre" align="right"><input name="search_amount" class="flat" type="text" size="8" value="'.$search_amount.'"></td>';
  166. print '<td class="liste_titre" align="right"></td>';
  167. print '<td class="liste_titre" align="right">';
  168. $searchpitco=$form->showFilterAndCheckAddButtons(0);
  169. print $searchpitco;
  170. print '</td>';
  171. print "</tr>\n";
  172. $var=True;
  173. while ($i < min($num,$limit))
  174. {
  175. $objp = $db->fetch_object($result);
  176. $var=!$var;
  177. print "<tr ".$bc[$var].">";
  178. $donationstatic->id=$objp->rowid;
  179. $donationstatic->ref=$objp->rowid;
  180. $donationstatic->lastname=$objp->lastname;
  181. $donationstatic->firstname=$objp->firstname;
  182. print "<td>".$donationstatic->getNomUrl(1)."</td>\n";
  183. print "<td>".$objp->societe."</td>\n";
  184. print "<td>".$donationstatic->getFullName($langs)."</td>\n";
  185. print '<td align="center">'.dol_print_date($db->jdate($objp->datedon),'day').'</td>';
  186. if (! empty($conf->projet->enabled))
  187. {
  188. print "<td>";
  189. if ($objp->pid)
  190. {
  191. $projectstatic->id=$objp->pid;
  192. $projectstatic->ref=$objp->ref;
  193. $projectstatic->id=$objp->pid;
  194. $projectstatic->public=$objp->public;
  195. $projectstatic->title=$objp->title;
  196. print $projectstatic->getNomUrl(1);
  197. }
  198. else print '&nbsp;';
  199. print "</td>\n";
  200. }
  201. print '<td align="right">'.price($objp->amount).'</td>';
  202. print '<td align="right">'.$donationstatic->LibStatut($objp->statut,5).'</td>';
  203. print '<td></td>';
  204. print "</tr>";
  205. $i++;
  206. }
  207. print "</table>";
  208. print "</form>\n";
  209. $db->free($resql);
  210. }
  211. else
  212. {
  213. dol_print_error($db);
  214. }
  215. llxFooter();
  216. $db->close();