PageRenderTime 43ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/projet/liste.php

http://github.com/Dolibarr/dolibarr
PHP | 214 lines | 140 code | 39 blank | 35 comment | 23 complexity | 2248a2da51868ade1b96936862c8ee66 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-3.0, LGPL-2.0, CC-BY-SA-4.0, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, MIT
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Bariley / Ocebo <marc@ocebo.com>
  5. * Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.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 2 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/projet/liste.php
  22. * \ingroup projet
  23. * \brief Page to list projects
  24. */
  25. require("../main.inc.php");
  26. require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php");
  27. $title = $langs->trans("Projects");
  28. // Security check
  29. $socid = (is_numeric($_GET["socid"]) ? $_GET["socid"] : 0 );
  30. if ($user->societe_id > 0) $socid=$user->societe_id;
  31. if ($socid > 0)
  32. {
  33. $soc = new Societe($db);
  34. $soc->fetch($socid);
  35. $title .= ' (<a href="liste.php">'.$soc->nom.'</a>)';
  36. }
  37. if (!$user->rights->projet->lire) accessforbidden();
  38. $sortfield = isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"];
  39. $sortorder = isset($_GET["sortorder"])?$_GET["sortorder"]:$_POST["sortorder"];
  40. $page = isset($_GET["page"])? $_GET["page"]:$_POST["page"];
  41. $page = is_numeric($page) ? $page : 0;
  42. $page = $page == -1 ? 0 : $page;
  43. if (! $sortfield) $sortfield="p.ref";
  44. if (! $sortorder) $sortorder="ASC";
  45. $offset = $conf->liste_limit * $page ;
  46. $pageprev = $page - 1;
  47. $pagenext = $page + 1;
  48. $mine = $_REQUEST['mode']=='mine' ? 1 : 0;
  49. $search_ref=GETPOST("search_ref");
  50. $search_label=GETPOST("search_label");
  51. $search_societe=GETPOST("search_societe");
  52. /*
  53. * View
  54. */
  55. $projectstatic = new Project($db);
  56. $socstatic = new Societe($db);
  57. llxHeader("",$langs->trans("Projects"),"EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos");
  58. $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,($mine?$mine:($user->rights->projet->all->lire?2:0)),1,$socid);
  59. $sql = "SELECT p.rowid as projectid, p.ref, p.title, p.fk_statut, p.public, p.fk_user_creat";
  60. $sql.= ", p.datec as date_create, p.dateo as date_start, p.datee as date_end";
  61. $sql.= ", s.nom, s.rowid as socid";
  62. $sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
  63. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
  64. $sql.= " WHERE p.entity = ".$conf->entity;
  65. if ($mine || ! $user->rights->projet->all->lire) $sql.= " AND p.rowid IN (".$projectsListId.")";
  66. // No need to check company, as filtering of projects must be done by getProjectsAuthorizedForUser
  67. //if ($socid || ! $user->rights->societe->client->voir) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
  68. if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
  69. if ($_GET["search_ref"])
  70. {
  71. $sql.= " AND p.ref LIKE '%".$db->escape($search_ref)."%'";
  72. }
  73. if ($_GET["search_label"])
  74. {
  75. $sql.= " AND p.title LIKE '%".$db->escape($search_label)."%'";
  76. }
  77. if ($_GET["search_societe"])
  78. {
  79. $sql.= " AND s.nom LIKE '%".$db->escape($search_societe)."%'";
  80. }
  81. $sql.= $db->order($sortfield,$sortorder);
  82. $sql.= $db->plimit($conf->liste_limit+1, $offset);
  83. $var=true;
  84. $resql = $db->query($sql);
  85. if ($resql)
  86. {
  87. $num = $db->num_rows($resql);
  88. $i = 0;
  89. $text=$langs->trans("Projects");
  90. if ($mine) $text=$langs->trans('MyProjects');
  91. print_barre_liste($text, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num);
  92. // Show description of content
  93. if ($mine) print $langs->trans("MyProjectsDesc").'<br><br>';
  94. else
  95. {
  96. if ($user->rights->projet->all->lire && ! $socid) print $langs->trans("ProjectsDesc").'<br><br>';
  97. else print $langs->trans("ProjectsPublicDesc").'<br><br>';
  98. }
  99. print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">';
  100. print '<table class="noborder" width="100%">';
  101. print '<tr class="liste_titre">';
  102. print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"p.ref","","","",$sortfield,$sortorder);
  103. print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"p.title","","","",$sortfield,$sortorder);
  104. print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","","",$sortfield,$sortorder);
  105. print_liste_field_titre($langs->trans("Visibility"),$_SERVER["PHP_SELF"],"p.public","","","",$sortfield,$sortorder);
  106. print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],'p.fk_statut',"","",'align="right"',$sortfield,$sortorder);
  107. print "</tr>\n";
  108. print '<tr class="liste_titre">';
  109. print '<td class="liste_titre">';
  110. print '<input type="text" class="flat" name="search_ref" value="'.$search_ref.'" size="6">';
  111. print '</td>';
  112. print '<td class="liste_titre">';
  113. print '<input type="text" class="flat" name="search_label" value="'.$search_label.'">';
  114. print '</td>';
  115. print '<td class="liste_titre">';
  116. print '<input type="text" class="flat" name="search_societe" value="'.$search_societe.'">';
  117. print '</td>';
  118. print '<td class="liste_titre">&nbsp;</td>';
  119. print '<td class="liste_titre" align="right"><input class="liste_titre" type="image" 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")).'"></td>';
  120. print "</tr>\n";
  121. while ($i < $num)
  122. {
  123. $objp = $db->fetch_object($resql);
  124. $projectstatic->id = $objp->projectid;
  125. $projectstatic->user_author_id = $objp->fk_user_creat;
  126. $projectstatic->public = $objp->public;
  127. $userAccess = $projectstatic->restrictedProjectArea($user);
  128. if ($userAccess >= 0)
  129. {
  130. $var=!$var;
  131. print "<tr ".$bc[$var].">";
  132. // Project url
  133. print "<td>";
  134. $projectstatic->ref = $objp->ref;
  135. print $projectstatic->getNomUrl(1);
  136. print "</td>";
  137. // Title
  138. print '<td>';
  139. print dol_trunc($objp->title,24);
  140. print '</td>';
  141. // Company
  142. print '<td>';
  143. if ($objp->socid)
  144. {
  145. $socstatic->id=$objp->socid;
  146. $socstatic->nom=$objp->nom;
  147. print $socstatic->getNomUrl(1);
  148. }
  149. else
  150. {
  151. print '&nbsp;';
  152. }
  153. print '</td>';
  154. // Visibility
  155. print '<td align="left">';
  156. if ($objp->public) print $langs->trans('SharedProject');
  157. else print $langs->trans('PrivateProject');
  158. print '</td>';
  159. // Status
  160. $projectstatic->statut = $objp->fk_statut;
  161. print '<td align="right">'.$projectstatic->getLibStatut(3).'</td>';
  162. print "</tr>\n";
  163. }
  164. $i++;
  165. }
  166. $db->free($resql);
  167. }
  168. else
  169. {
  170. dol_print_error($db);
  171. }
  172. print "</table>";
  173. llxFooter();
  174. $db->close();
  175. ?>