list.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  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', 'alphanohtml');
  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. $form=new Form($db);
  69. if (! empty($conf->projet->enabled)) $projectstatic=new Project($db);
  70. llxHeader('',$langs->trans("Donations"),'EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones');
  71. $donationstatic=new Don($db);
  72. // Genere requete de liste des dons
  73. $sql = "SELECT d.rowid, d.datedon, d.firstname, d.lastname, d.societe,";
  74. $sql.= " d.amount, d.fk_statut as statut, ";
  75. $sql.= " p.rowid as pid, p.ref, p.title, p.public";
  76. $sql.= " FROM ".MAIN_DB_PREFIX."don as d LEFT JOIN ".MAIN_DB_PREFIX."projet AS p";
  77. $sql.= " ON p.rowid = d.fk_projet WHERE 1 = 1";
  78. if ($statut >= 0)
  79. {
  80. $sql .= " AND d.fk_statut = ".$statut;
  81. }
  82. if (trim($search_ref) != '')
  83. {
  84. $sql.= ' AND d.rowid LIKE \'%'.$db->escape(trim($search_ref)) . '%\'';
  85. }
  86. if (trim($search_all) != '')
  87. {
  88. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  89. }
  90. if (trim($search_company) != '')
  91. {
  92. $sql .= natural_search('d.societe', $search_company);
  93. }
  94. if (trim($search_name) != '')
  95. {
  96. $sql .= natural_search(array('d.lastname', 'd.firstname'), $search_name);
  97. }
  98. if ($search_amount) $sql.= natural_search(array('d.amount'), price2num(trim($search_amount)), 1);
  99. $sql.= $db->order($sortfield,$sortorder);
  100. $nbtotalofrecords = '';
  101. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  102. {
  103. $result = $db->query($sql);
  104. $nbtotalofrecords = $db->num_rows($result);
  105. }
  106. $sql.= $db->plimit($limit+1, $offset);
  107. $resql = $db->query($sql);
  108. if ($resql)
  109. {
  110. $num = $db->num_rows($resql);
  111. $i = 0;
  112. $param = '&statut='.$statut;
  113. //if ($page > 0) $param.= '&page='.$page;
  114. if ($optioncss != '') $param.='&optioncss='.$optioncss;
  115. if ($statut >= 0)
  116. {
  117. $donationstatic->statut=$statut;
  118. $label=$donationstatic->getLibStatut(0);
  119. print_barre_liste($langs->trans("Donations"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num,$nbtotalofrecords);
  120. }
  121. else
  122. {
  123. print_barre_liste($langs->trans("Donations"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num,$nbtotalofrecords);
  124. }
  125. print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  126. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  127. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  128. print '<input type="hidden" name="action" value="list">';
  129. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  130. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  131. print '<input type="hidden" name="page" value="'.$page.'">';
  132. print '<input type="hidden" name="type" value="'.$type.'">';
  133. if ($search_all)
  134. {
  135. foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
  136. print $langs->trans("FilterOnInto", $search_all) . join(', ',$fieldstosearchall);
  137. }
  138. print '<div class="div-table-responsive">';
  139. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  140. // Filters lines
  141. print '<tr class="liste_titre_filter">';
  142. print '<td class="liste_titre">';
  143. print '<input class="flat" size="10" type="text" name="search_ref" value="'.$search_ref.'">';
  144. print '</td>';
  145. print '<td class="liste_titre">';
  146. print '<input class="flat" size="10" type="text" name="search_company" value="'.$search_company.'">';
  147. print '</td>';
  148. print '<td class="liste_titre">';
  149. print '<input class="flat" size="10" type="text" name="search_name" value="'.$search_name.'">';
  150. print '</td>';
  151. print '<td class="liste_titre" align="left">';
  152. print '&nbsp;';
  153. print '</td>';
  154. if (! empty($conf->projet->enabled))
  155. {
  156. print '<td class="liste_titre" align="right">';
  157. print '&nbsp;';
  158. print '</td>';
  159. }
  160. print '<td class="liste_titre" align="right"><input name="search_amount" class="flat" type="text" size="8" value="'.$search_amount.'"></td>';
  161. print '<td class="liste_titre" align="right"></td>';
  162. print '<td class="liste_titre" align="right">';
  163. $searchpicto=$form->showFilterAndCheckAddButtons(0);
  164. print $searchpicto;
  165. print '</td>';
  166. print "</tr>\n";
  167. print '<tr class="liste_titre">';
  168. print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"d.rowid","", $param,"",$sortfield,$sortorder);
  169. print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"d.societe","", $param,"",$sortfield,$sortorder);
  170. print_liste_field_titre($langs->trans("Name"),$_SERVER["PHP_SELF"],"d.lastname","", $param,"",$sortfield,$sortorder);
  171. print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"],"d.datedon","", $param,'align="center"',$sortfield,$sortorder);
  172. if (! empty($conf->projet->enabled))
  173. {
  174. $langs->load("projects");
  175. print_liste_field_titre($langs->trans("Project"),$_SERVER["PHP_SELF"],"fk_projet","", $param,"",$sortfield,$sortorder);
  176. }
  177. print_liste_field_titre($langs->trans("Amount"),$_SERVER["PHP_SELF"],"d.amount","", $param,'align="right"',$sortfield,$sortorder);
  178. print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"d.fk_statut","", $param,'align="right"',$sortfield,$sortorder);
  179. print_liste_field_titre('');
  180. print "</tr>\n";
  181. while ($i < min($num,$limit))
  182. {
  183. $objp = $db->fetch_object($resql);
  184. print '<tr class="oddeven">';
  185. $donationstatic->id=$objp->rowid;
  186. $donationstatic->ref=$objp->rowid;
  187. $donationstatic->lastname=$objp->lastname;
  188. $donationstatic->firstname=$objp->firstname;
  189. print "<td>".$donationstatic->getNomUrl(1)."</td>\n";
  190. print "<td>".$objp->societe."</td>\n";
  191. print "<td>".$donationstatic->getFullName($langs)."</td>\n";
  192. print '<td align="center">'.dol_print_date($db->jdate($objp->datedon),'day').'</td>';
  193. if (! empty($conf->projet->enabled))
  194. {
  195. print "<td>";
  196. if ($objp->pid)
  197. {
  198. $projectstatic->id=$objp->pid;
  199. $projectstatic->ref=$objp->ref;
  200. $projectstatic->id=$objp->pid;
  201. $projectstatic->public=$objp->public;
  202. $projectstatic->title=$objp->title;
  203. print $projectstatic->getNomUrl(1);
  204. }
  205. else print '&nbsp;';
  206. print "</td>\n";
  207. }
  208. print '<td align="right">'.price($objp->amount).'</td>';
  209. print '<td align="right">'.$donationstatic->LibStatut($objp->statut,5).'</td>';
  210. print '<td></td>';
  211. print "</tr>";
  212. $i++;
  213. }
  214. print "</table>";
  215. print '</div>';
  216. print "</form>\n";
  217. $db->free($resql);
  218. }
  219. else
  220. {
  221. dol_print_error($db);
  222. }
  223. llxFooter();
  224. $db->close();