list.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Bariley / Ocebo <marc@ocebo.com>
  5. * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  7. * Copyright (C) 2015 Claudio Aschieri <c.aschieri@19.coop>
  8. * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/projet/list.php
  25. * \ingroup projet
  26. * \brief Page to list projects
  27. */
  28. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  33. // Load translation files required by the page
  34. $langs->loadLangs(array('projects', 'companies', 'commercial'));
  35. $action=GETPOST('action','alpha');
  36. $massaction=GETPOST('massaction','alpha');
  37. $show_files=GETPOST('show_files','int');
  38. $confirm=GETPOST('confirm','alpha');
  39. $toselect = GETPOST('toselect', 'array');
  40. $contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'projectlist';
  41. $title = $langs->trans("Projects");
  42. // Security check
  43. $socid = (is_numeric($_GET["socid"]) ? $_GET["socid"] : 0 );
  44. //if ($user->societe_id > 0) $socid = $user->societe_id; // For external user, no check is done on company because readability is managed by public status of project and assignement.
  45. if ($socid > 0)
  46. {
  47. $soc = new Societe($db);
  48. $soc->fetch($socid);
  49. $title .= ' (<a href="list.php">'.$soc->name.'</a>)';
  50. }
  51. if (!$user->rights->projet->lire) accessforbidden();
  52. $diroutputmassaction=$conf->projet->dir_output . '/temp/massgeneration/'.$user->id;
  53. $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
  54. $sortfield = GETPOST("sortfield","alpha");
  55. $sortorder = GETPOST("sortorder");
  56. $page = GETPOST("page");
  57. $page = is_numeric($page) ? $page : 0;
  58. $page = $page == -1 ? 0 : $page;
  59. if (! $sortfield) $sortfield="p.ref";
  60. if (! $sortorder) $sortorder="ASC";
  61. $offset = $limit * $page ;
  62. $pageprev = $page - 1;
  63. $pagenext = $page + 1;
  64. $search_all=GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
  65. $search_categ=GETPOST("search_categ",'alpha');
  66. $search_ref=GETPOST("search_ref");
  67. $search_label=GETPOST("search_label");
  68. $search_societe=GETPOST("search_societe");
  69. $search_year=GETPOST("search_year");
  70. $search_status=GETPOST("search_status",'int');
  71. $search_opp_status=GETPOST("search_opp_status",'alpha');
  72. $search_opp_percent=GETPOST("search_opp_percent",'alpha');
  73. $search_opp_amount=GETPOST("search_opp_amount",'alpha');
  74. $search_budget_amount=GETPOST("search_budget_amount",'alpha');
  75. $search_public=GETPOST("search_public",'int');
  76. $search_project_user=GETPOST('search_project_user','int');
  77. $search_sale=GETPOST('search_sale','int');
  78. $optioncss = GETPOST('optioncss','alpha');
  79. $mine = $_REQUEST['mode']=='mine' ? 1 : 0;
  80. if ($mine) { $search_project_user = $user->id; $mine=0; }
  81. $search_sday = GETPOST('search_sday','int');
  82. $search_smonth = GETPOST('search_smonth','int');
  83. $search_syear = GETPOST('search_syear','int');
  84. $search_eday = GETPOST('search_eday','int');
  85. $search_emonth = GETPOST('search_emonth','int');
  86. $search_eyear = GETPOST('search_eyear','int');
  87. if ($search_status == '') $search_status=-1; // -1 or 1
  88. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  89. $object = new Project($db);
  90. $hookmanager->initHooks(array('projectlist'));
  91. $extrafields = new ExtraFields($db);
  92. // fetch optionals attributes and labels
  93. $extralabels = $extrafields->fetch_name_optionals_label('projet');
  94. $search_array_options=$extrafields->getOptionalsFromPost($object->table_element,'','search_');
  95. // List of fields to search into when doing a "search in all"
  96. $fieldstosearchall = array(
  97. 'p.ref'=>"Ref",
  98. 'p.title'=>"Label",
  99. 's.nom'=>"ThirdPartyName",
  100. "p.note_public"=>"NotePublic"
  101. );
  102. if (empty($user->socid)) $fieldstosearchall["p.note_private"]="NotePrivate";
  103. $arrayfields=array(
  104. 'p.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
  105. 'p.title'=>array('label'=>$langs->trans("Label"), 'checked'=>1),
  106. 's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1, 'enabled'=>(empty($conf->societe->enabled)?0:1)),
  107. 'commercial'=>array('label'=>$langs->trans("SaleRepresentativesOfThirdParty"), 'checked'=>0),
  108. 'p.dateo'=>array('label'=>$langs->trans("DateStart"), 'checked'=>1, 'position'=>100),
  109. 'p.datee'=>array('label'=>$langs->trans("DateEnd"), 'checked'=>1, 'position'=>101),
  110. 'p.public'=>array('label'=>$langs->trans("Visibility"), 'checked'=>1, 'position'=>102),
  111. 'p.opp_amount'=>array('label'=>$langs->trans("OpportunityAmountShort"), 'checked'=>1, 'enabled'=>($conf->global->PROJECT_USE_OPPORTUNITIES?1:0), 'position'=>103),
  112. 'p.fk_opp_status'=>array('label'=>$langs->trans("OpportunityStatusShort"), 'checked'=>1, 'enabled'=>($conf->global->PROJECT_USE_OPPORTUNITIES?1:0), 'position'=>104),
  113. 'p.opp_percent'=>array('label'=>$langs->trans("OpportunityProbabilityShort"), 'checked'=>1, 'enabled'=>($conf->global->PROJECT_USE_OPPORTUNITIES?1:0), 'position'=>105),
  114. 'p.budget_amount'=>array('label'=>$langs->trans("Budget"), 'checked'=>0, 'position'=>110),
  115. 'p.datec'=>array('label'=>$langs->trans("DateCreationShort"), 'checked'=>0, 'position'=>500),
  116. 'p.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
  117. 'p.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
  118. );
  119. // Extra fields
  120. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  121. {
  122. foreach($extrafields->attribute_label as $key => $val)
  123. {
  124. if (! empty($extrafields->attribute_list[$key])) $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key]<0)?0:1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>(abs($extrafields->attribute_list[$key])!=3 && $extrafields->attribute_perms[$key]));
  125. }
  126. }
  127. /*
  128. * Actions
  129. */
  130. if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
  131. if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') { $massaction=''; }
  132. $parameters=array('socid'=>$socid);
  133. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  134. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  135. if (empty($reshook))
  136. {
  137. // Selection of new fields
  138. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  139. // Purge search criteria
  140. if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
  141. {
  142. $search_all='';
  143. $search_categ='';
  144. $search_ref="";
  145. $search_label="";
  146. $search_societe="";
  147. $search_year="";
  148. $search_status=-1;
  149. $search_opp_status=-1;
  150. $search_opp_amount='';
  151. $search_opp_percent='';
  152. $search_budget_amount='';
  153. $search_public="";
  154. $search_sale="";
  155. $search_project_user='';
  156. $search_sday="";
  157. $search_smonth="";
  158. $search_syear="";
  159. $search_eday="";
  160. $search_emonth="";
  161. $search_eyear="";
  162. $toselect='';
  163. $search_array_options=array();
  164. }
  165. // Mass actions
  166. $objectclass='Project';
  167. $objectlabel='Project';
  168. $permtoread = $user->rights->projet->lire;
  169. $permtodelete = $user->rights->projet->supprimer;
  170. $uploaddir = $conf->projet->dir_output;
  171. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  172. // Close records
  173. if (! $error && $massaction == 'close' && $user->rights->projet->creer)
  174. {
  175. $db->begin();
  176. $objecttmp=new $objectclass($db);
  177. $nbok = 0;
  178. foreach($toselect as $toselectid)
  179. {
  180. $result=$objecttmp->fetch($toselectid);
  181. if ($result > 0)
  182. {
  183. $userWrite = $object->restrictedProjectArea($user,'write');
  184. if ($userWrite > 0 && $objecttmp->statut == 1) {
  185. $result = $objecttmp->setClose($user);
  186. if ($result <= 0) {
  187. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  188. $error++;
  189. break;
  190. } else $nbok++;
  191. } elseif($userWrite <= 0) {
  192. setEventMessages($langs->trans("DontHavePermissionForCloseProject", $objecttmp->ref), null, 'warnings');
  193. } else {
  194. setEventMessages($langs->trans("DontHaveTheValidateStatus", $objecttmp->ref), null, 'warnings');
  195. }
  196. }
  197. else
  198. {
  199. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  200. $error++;
  201. break;
  202. }
  203. }
  204. if (! $error)
  205. {
  206. if ($nbok > 1) setEventMessages($langs->trans("RecordsClosed", $nbok), null, 'mesgs');
  207. else setEventMessages($langs->trans("RecordsClosed", $nbok), null, 'mesgs');
  208. $db->commit();
  209. }
  210. else
  211. {
  212. $db->rollback();
  213. }
  214. }
  215. }
  216. /*
  217. * View
  218. */
  219. $socstatic = new Societe($db);
  220. $form = new Form($db);
  221. $formother = new FormOther($db);
  222. $formproject = new FormProjets($db);
  223. $title=$langs->trans("Projects");
  224. //if ($search_project_user == $user->id) $title=$langs->trans("MyProjects");
  225. // Get list of project id allowed to user (in a string list separated by coma)
  226. $projectsListId='';
  227. if (! $user->rights->projet->all->lire) $projectsListId = $object->getProjectsAuthorizedForUser($user,0,1,$socid);
  228. // Get id of types of contacts for projects (This list never contains a lot of elements)
  229. $listofprojectcontacttype=array();
  230. $sql = "SELECT ctc.rowid, ctc.code FROM ".MAIN_DB_PREFIX."c_type_contact as ctc";
  231. $sql.= " WHERE ctc.element = '" . $object->element . "'";
  232. $sql.= " AND ctc.source = 'internal'";
  233. $resql = $db->query($sql);
  234. if ($resql)
  235. {
  236. while($obj = $db->fetch_object($resql))
  237. {
  238. $listofprojectcontacttype[$obj->rowid]=$obj->code;
  239. }
  240. }
  241. else dol_print_error($db);
  242. if (count($listofprojectcontacttype) == 0) $listofprojectcontacttype[0]='0'; // To avoid sql syntax error if not found
  243. $distinct='DISTINCT'; // We add distinct until we are added a protection to be sure a contact of a project and task is only once.
  244. $sql = "SELECT ".$distinct." p.rowid as id, p.ref, p.title, p.fk_statut, p.fk_opp_status, p.public, p.fk_user_creat";
  245. $sql.= ", p.datec as date_creation, p.dateo as date_start, p.datee as date_end, p.opp_amount, p.opp_percent, p.tms as date_update, p.budget_amount";
  246. $sql.= ", s.nom as name, s.rowid as socid";
  247. $sql.= ", cls.code as opp_status_code";
  248. // We'll need these fields in order to filter by categ
  249. if ($search_categ) $sql .= ", cs.fk_categorie, cs.fk_project";
  250. // Add fields for extrafields
  251. foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
  252. // Add fields from hooks
  253. $parameters=array();
  254. $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
  255. $sql.=$hookmanager->resPrint;
  256. $sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
  257. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet_extrafields as ef on (p.rowid = ef.fk_object)";
  258. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
  259. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_lead_status as cls on p.fk_opp_status = cls.rowid";
  260. // We'll need this table joined to the select in order to filter by categ
  261. if (! empty($search_categ)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_project as cs ON p.rowid = cs.fk_project"; // We'll need this table joined to the select in order to filter by categ
  262. // We'll need this table joined to the select in order to filter by sale
  263. // No check is done on company permission because readability is managed by public status of project and assignement.
  264. //if ($search_sale > 0 || (! $user->rights->societe->client->voir && ! $socid)) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = s.rowid";
  265. if ($search_sale > 0) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = s.rowid";
  266. if ($search_project_user > 0)
  267. {
  268. $sql.=", ".MAIN_DB_PREFIX."element_contact as ecp";
  269. }
  270. $sql.= " WHERE p.entity IN (".getEntity('project').')';
  271. if (! $user->rights->projet->all->lire) $sql.= " AND p.rowid IN (".$projectsListId.")"; // public and assigned to, or restricted to company for external users
  272. // No need to check if company is external user, as filtering of projects must be done by getProjectsAuthorizedForUser
  273. if ($socid > 0) $sql.= " AND (p.fk_soc = ".$socid.")"; // This filter if when we use a hard coded filter on company on url (not related to filter for external users)
  274. if ($search_categ > 0) $sql.= " AND cs.fk_categorie = ".$db->escape($search_categ);
  275. if ($search_categ == -2) $sql.= " AND cs.fk_categorie IS NULL";
  276. if ($search_ref) $sql .= natural_search('p.ref', $search_ref);
  277. if ($search_label) $sql .= natural_search('p.title', $search_label);
  278. if ($search_societe) $sql .= natural_search('s.nom', $search_societe);
  279. if ($search_opp_amount) $sql .= natural_search('p.opp_amount', $search_opp_amount, 1);
  280. if ($search_opp_percent) $sql .= natural_search('p.opp_percent', $search_opp_percent, 1);
  281. if ($search_smonth > 0)
  282. {
  283. if ($search_syear > 0 && empty($search_sday))
  284. $sql.= " AND p.dateo BETWEEN '".$db->idate(dol_get_first_day($search_syear,$search_smonth,false))."' AND '".$db->idate(dol_get_last_day($search_syear,$search_smonth,false))."'";
  285. else if ($search_syear > 0 && ! empty($search_sday))
  286. $sql.= " AND p.dateo BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_smonth, $search_sday, $search_syear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_smonth, $search_sday, $search_syear))."'";
  287. else
  288. $sql.= " AND date_format(p.dateo, '%m') = '".$search_smonth."'";
  289. }
  290. else if ($search_syear > 0)
  291. {
  292. $sql.= " AND p.dateo BETWEEN '".$db->idate(dol_get_first_day($search_syear,1,false))."' AND '".$db->idate(dol_get_last_day($search_syear,12,false))."'";
  293. }
  294. if ($search_emonth > 0)
  295. {
  296. if ($search_eyear > 0 && empty($search_eday))
  297. $sql.= " AND p.datee BETWEEN '".$db->idate(dol_get_first_day($search_eyear,$search_emonth,false))."' AND '".$db->idate(dol_get_last_day($search_eyear,$search_emonth,false))."'";
  298. else if ($search_eyear > 0 && ! empty($search_eday))
  299. $sql.= " AND p.datee BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_emonth, $search_eday, $search_eyear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_emonth, $search_eday, $search_eyear))."'";
  300. else
  301. $sql.= " AND date_format(p.datee, '%m') = '".$search_emonth."'";
  302. }
  303. else if ($search_eyear > 0)
  304. {
  305. $sql.= " AND p.datee BETWEEN '".$db->idate(dol_get_first_day($search_eyear,1,false))."' AND '".$db->idate(dol_get_last_day($search_eyear,12,false))."'";
  306. }
  307. if ($search_all) $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  308. if ($search_status >= 0)
  309. {
  310. if ($search_status == 99) $sql .= " AND p.fk_statut <> 2";
  311. else $sql .= " AND p.fk_statut = ".$db->escape($search_status);
  312. }
  313. if ($search_opp_status)
  314. {
  315. if (is_numeric($search_opp_status) && $search_opp_status > 0) $sql .= " AND p.fk_opp_status = ".$db->escape($search_opp_status);
  316. if ($search_opp_status == 'all') $sql .= " AND p.fk_opp_status IS NOT NULL";
  317. if ($search_opp_status == 'openedopp') $sql .= " AND p.fk_opp_status IS NOT NULL AND p.fk_opp_status NOT IN (SELECT rowid FROM ".MAIN_DB_PREFIX."c_lead_status WHERE code IN ('WON','LOST'))";
  318. if ($search_opp_status == 'notopenedopp') $sql .= " AND (p.fk_opp_status IS NULL OR p.fk_opp_status IN (SELECT rowid FROM ".MAIN_DB_PREFIX."c_lead_status WHERE code IN ('WON')))";
  319. if ($search_opp_status == 'none') $sql .= " AND p.fk_opp_status IS NULL";
  320. }
  321. if ($search_public!='') $sql .= " AND p.public = ".$db->escape($search_public);
  322. // For external user, no check is done on company permission because readability is managed by public status of project and assignement.
  323. //if ($socid > 0) $sql.= " AND s.rowid = ".$socid;
  324. if ($search_sale > 0) $sql.= " AND sc.fk_user = " .$search_sale;
  325. // No check is done on company permission because readability is managed by public status of project and assignement.
  326. //if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id.") OR (s.rowid IS NULL))";
  327. if ($search_project_user > 0) $sql.= " AND ecp.fk_c_type_contact IN (".join(',',array_keys($listofprojectcontacttype)).") AND ecp.element_id = p.rowid AND ecp.fk_socpeople = ".$search_project_user;
  328. if ($search_opp_amount != '') $sql .= natural_search('p.opp_amount', $search_opp_amount, 1);
  329. if ($search_budget_amount != '') $sql .= natural_search('p.budget_amount', $search_budget_amount, 1);
  330. // Add where from extra fields
  331. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  332. // Add where from hooks
  333. $parameters=array();
  334. $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
  335. $sql.=$hookmanager->resPrint;
  336. $sql.= $db->order($sortfield,$sortorder);
  337. $nbtotalofrecords = '';
  338. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  339. {
  340. $result = $db->query($sql);
  341. $nbtotalofrecords = $db->num_rows($result);
  342. if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
  343. {
  344. $page = 0;
  345. $offset = 0;
  346. }
  347. }
  348. $sql.= $db->plimit($limit + 1,$offset);
  349. dol_syslog("list allowed project", LOG_DEBUG);
  350. $resql = $db->query($sql);
  351. if (! $resql)
  352. {
  353. dol_print_error($db);
  354. exit;
  355. }
  356. $num = $db->num_rows($resql);
  357. $arrayofselected=is_array($toselect)?$toselect:array();
  358. if ($num == 1 && ! empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all)
  359. {
  360. $obj = $db->fetch_object($resql);
  361. header("Location: ".DOL_URL_ROOT.'/projet/card.php?id='.$obj->id);
  362. exit;
  363. }
  364. $help_url="EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
  365. llxHeader("", $title, $help_url);
  366. $param='';
  367. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  368. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  369. if ($search_all != '') $param.='&search_all='.$search_all;
  370. if ($search_sday) $param.='&search_sday='.$search_sday;
  371. if ($search_smonth) $param.='&search_smonth='.$search_smonth;
  372. if ($search_syear) $param.='&search_syear=' .$search_syear;
  373. if ($search_eday) $param.='&search_eday='.$search_eday;
  374. if ($search_emonth) $param.='&search_emonth='.$search_emonth;
  375. if ($search_eyear) $param.='&search_eyear=' .$search_eyear;
  376. if ($socid) $param.='&socid='.$socid;
  377. if ($search_ref != '') $param.='&search_ref='.$search_ref;
  378. if ($search_label != '') $param.='&search_label='.$search_label;
  379. if ($search_societe != '') $param.='&search_societe='.$search_societe;
  380. if ($search_status >= 0) $param.='&search_status='.$search_status;
  381. if ((is_numeric($search_opp_status) && $search_opp_status >= 0) || in_array($search_opp_status, array('all','openedopp','notopenedopp','none'))) $param.='&search_opp_status='.urlencode($search_opp_status);
  382. if ($search_opp_percent != '') $param.='&search_opp_percent='.urlencode($search_opp_percent);
  383. if ($search_public != '') $param.='&search_public='.$search_public;
  384. if ($search_project_user != '') $param.='&search_project_user='.$search_project_user;
  385. if ($search_sale > 0) $param.='&search_sale='.$search_sale;
  386. if ($search_opp_amount != '') $param.='&search_opp_amount='.$search_opp_amount;
  387. if ($search_budget_amount != '') $param.='&search_budget_amount='.$search_budget_amount;
  388. if ($optioncss != '') $param.='&optioncss='.$optioncss;
  389. // Add $param from extra fields
  390. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  391. // List of mass actions available
  392. $arrayofmassactions = array(
  393. // 'presend'=>$langs->trans("SendByMail"),
  394. // 'builddoc'=>$langs->trans("PDFMerge"),
  395. );
  396. //if($user->rights->societe->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
  397. if ($user->rights->projet->creer) $arrayofmassactions['close']=$langs->trans("Close");
  398. if ($user->rights->societe->supprimer) $arrayofmassactions['predelete']=$langs->trans("Delete");
  399. if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
  400. $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
  401. $newcardbutton='';
  402. if ($user->rights->projet->creer)
  403. {
  404. $newcardbutton = '<a class="butActionNew" href="'.DOL_URL_ROOT.'/projet/card.php?action=create"><span class="valignmiddle">'.$langs->trans('NewProject').'</span>';
  405. $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
  406. $newcardbutton.= '</a>';
  407. }
  408. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  409. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  410. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  411. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  412. print '<input type="hidden" name="action" value="list">';
  413. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  414. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  415. print '<input type="hidden" name="page" value="'.$page.'">';
  416. print '<input type="hidden" name="type" value="'.$type.'">';
  417. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  418. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_project', 0, $newcardbutton, '', $limit);
  419. // Show description of content
  420. print '<div class="opacitymedium">';
  421. if ($search_project_user == $user->id) print $langs->trans("MyProjectsDesc").'<br><br>';
  422. else
  423. {
  424. if ($user->rights->projet->all->lire && ! $socid) print $langs->trans("ProjectsDesc").'<br><br>';
  425. else print $langs->trans("ProjectsPublicDesc").'<br><br>';
  426. }
  427. print '</div>';
  428. $topicmail="Information";
  429. $modelmail="project";
  430. $objecttmp=new Project($db);
  431. $trackid='prj'.$object->id;
  432. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  433. if ($search_all)
  434. {
  435. foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
  436. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all) . join(', ',$fieldstosearchall).'</div>';
  437. }
  438. $moreforfilter='';
  439. // Filter on categories
  440. if (! empty($conf->categorie->enabled))
  441. {
  442. require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
  443. $moreforfilter.='<div class="divsearchfield">';
  444. $moreforfilter.=$langs->trans('ProjectCategories'). ': ';
  445. $moreforfilter.=$formother->select_categories('project', $search_categ, 'search_categ', 1, 1, 'maxwidth300');
  446. $moreforfilter.='</div>';
  447. }
  448. // If the user can view user other than himself
  449. $moreforfilter.='<div class="divsearchfield">';
  450. $moreforfilter.=$langs->trans('ProjectsWithThisUserAsContact'). ': ';
  451. $includeonly='hierachyme';
  452. if (empty($user->rights->user->user->lire)) $includeonly=array($user->id);
  453. $moreforfilter.=$form->select_dolusers($search_project_user?$search_project_user:'', 'search_project_user', 1, '', 0, $includeonly, '', 0, 0, 0, '', 0, '', 'maxwidth200');
  454. $moreforfilter.='</div>';
  455. // If the user can view thirdparties other than his'
  456. if ($user->rights->societe->client->voir || $socid)
  457. {
  458. $langs->load("commercial");
  459. $moreforfilter.='<div class="divsearchfield">';
  460. $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
  461. $moreforfilter.=$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth200');
  462. $moreforfilter.='</div>';
  463. }
  464. if (! empty($moreforfilter))
  465. {
  466. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  467. print $moreforfilter;
  468. $parameters=array();
  469. $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
  470. print $hookmanager->resPrint;
  471. print '</div>';
  472. }
  473. $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  474. $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  475. if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
  476. print '<div class="div-table-responsive">';
  477. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  478. print '<tr class="liste_titre_filter">';
  479. // Project ref
  480. if (! empty($arrayfields['p.ref']['checked']))
  481. {
  482. print '<td class="liste_titre">';
  483. print '<input type="text" class="flat" name="search_ref" value="'.dol_escape_htmltag($search_ref).'" size="6">';
  484. print '</td>';
  485. }
  486. // Project label
  487. if (! empty($arrayfields['p.title']['checked']))
  488. {
  489. print '<td class="liste_titre">';
  490. print '<input type="text" class="flat" name="search_label" size="8" value="'.dol_escape_htmltag($search_label).'">';
  491. print '</td>';
  492. }
  493. // Third party
  494. if (! empty($arrayfields['s.nom']['checked']))
  495. {
  496. print '<td class="liste_titre">';
  497. if ($socid > 0)
  498. {
  499. $tmpthirdparty=new Societe($db);
  500. $tmpthirdparty->fetch($socid);
  501. $search_societe=$tmpthirdparty->nom;
  502. }
  503. print '<input type="text" class="flat" name="search_societe" size="8" value="'.dol_escape_htmltag($search_societe).'">';
  504. print '</td>';
  505. }
  506. // Sale representative
  507. if (! empty($arrayfields['commercial']['checked']))
  508. {
  509. print '<td class="liste_titre">&nbsp;</td>';
  510. }
  511. // Start date
  512. if (! empty($arrayfields['p.dateo']['checked']))
  513. {
  514. print '<td class="liste_titre center nowraponall">';
  515. if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_sday" value="'.dol_escape_htmltag($search_sday).'">';
  516. print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_smonth" value="'.dol_escape_htmltag($search_smonth).'">';
  517. $formother->select_year($search_syear?$search_syear:-1,'search_syear',1, 20, 5, 0, 0, '', 'widthauto valignmiddle');
  518. print '</td>';
  519. }
  520. // End date
  521. if (! empty($arrayfields['p.datee']['checked']))
  522. {
  523. print '<td class="liste_titre center nowraponall">';
  524. if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_eday" value="'.dol_escape_htmltag($search_eday).'">';
  525. print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_emonth" value="'.dol_escape_htmltag($search_emonth).'">';
  526. $formother->select_year($search_eyear?$search_eyear:-1,'search_eyear',1, 20, 5, 0, 0, '', 'widthauto valignmiddle');
  527. print '</td>';
  528. }
  529. if (! empty($arrayfields['p.public']['checked']))
  530. {
  531. print '<td class="liste_titre">';
  532. $array=array(''=>'',0 => $langs->trans("PrivateProject"),1 => $langs->trans("SharedProject"));
  533. print $form->selectarray('search_public',$array,$search_public);
  534. print '</td>';
  535. }
  536. // Opp status
  537. if (! empty($arrayfields['p.fk_opp_status']['checked']))
  538. {
  539. print '<td class="liste_titre nowrap center">';
  540. print $formproject->selectOpportunityStatus('search_opp_status', $search_opp_status, 1, 0, 1, 0, 'maxwidth100');
  541. print '</td>';
  542. }
  543. if (! empty($arrayfields['p.opp_amount']['checked']))
  544. {
  545. print '<td class="liste_titre nowrap right">';
  546. print '<input type="text" class="flat" name="search_opp_amount" size="3" value="'.$search_opp_amount.'">';
  547. print '</td>';
  548. }
  549. if (! empty($arrayfields['p.opp_percent']['checked']))
  550. {
  551. print '<td class="liste_titre nowrap right">';
  552. print '<input type="text" class="flat" name="search_opp_percent" size="2" value="'.$search_opp_percent.'">';
  553. print '</td>';
  554. }
  555. if (! empty($arrayfields['p.budget_amount']['checked']))
  556. {
  557. print '<td class="liste_titre nowrap" align="right">';
  558. print '<input type="text" class="flat" name="search_budget_amount" size="4" value="'.$search_budget_amount.'">';
  559. print '</td>';
  560. }
  561. // Extra fields
  562. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  563. // Fields from hook
  564. $parameters=array('arrayfields'=>$arrayfields);
  565. $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
  566. print $hookmanager->resPrint;
  567. if (! empty($arrayfields['p.datec']['checked']))
  568. {
  569. // Date creation
  570. print '<td class="liste_titre">';
  571. print '</td>';
  572. }
  573. if (! empty($arrayfields['p.tms']['checked']))
  574. {
  575. // Date modification
  576. print '<td class="liste_titre">';
  577. print '</td>';
  578. }
  579. if (! empty($arrayfields['p.fk_statut']['checked']))
  580. {
  581. print '<td class="liste_titre nowrap" align="right">';
  582. $arrayofstatus = array();
  583. foreach($object->statuts_short as $key => $val) $arrayofstatus[$key]=$langs->trans($val);
  584. $arrayofstatus['99']=$langs->trans("NotClosed").' ('.$langs->trans('Draft').' + '.$langs->trans('Opened').')';
  585. print $form->selectarray('search_status', $arrayofstatus, $search_status, 1, 0, 0, '', 0, 0, 0, '', 'maxwidth100 selectarrowonleft');
  586. print ajax_combobox('search_status');
  587. print '</td>';
  588. }
  589. // Action column
  590. print '<td class="liste_titre" align="right">';
  591. $searchpicto=$form->showFilterButtons();
  592. print $searchpicto;
  593. print '</td>';
  594. print '</tr>'."\n";
  595. print '<tr class="liste_titre">';
  596. if (! empty($arrayfields['p.ref']['checked'])) print_liste_field_titre($arrayfields['p.ref']['label'],$_SERVER["PHP_SELF"],"p.ref","",$param,"",$sortfield,$sortorder);
  597. if (! empty($arrayfields['p.title']['checked'])) print_liste_field_titre($arrayfields['p.title']['label'],$_SERVER["PHP_SELF"],"p.title","",$param,"",$sortfield,$sortorder);
  598. if (! empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'],$_SERVER["PHP_SELF"],"s.nom","",$param,"",$sortfield,$sortorder);
  599. if (! empty($arrayfields['commercial']['checked'])) print_liste_field_titre($arrayfields['commercial']['label'],$_SERVER["PHP_SELF"],"","",$param,"",$sortfield,$sortorder);
  600. if (! empty($arrayfields['p.dateo']['checked'])) print_liste_field_titre($arrayfields['p.dateo']['label'],$_SERVER["PHP_SELF"],"p.dateo","",$param,'align="center"',$sortfield,$sortorder);
  601. if (! empty($arrayfields['p.datee']['checked'])) print_liste_field_titre($arrayfields['p.datee']['label'],$_SERVER["PHP_SELF"],"p.datee","",$param,'align="center"',$sortfield,$sortorder);
  602. if (! empty($arrayfields['p.public']['checked'])) print_liste_field_titre($arrayfields['p.public']['label'],$_SERVER["PHP_SELF"],"p.public","",$param,"",$sortfield,$sortorder);
  603. if (! empty($arrayfields['p.fk_opp_status']['checked'])) print_liste_field_titre($arrayfields['p.fk_opp_status']['label'],$_SERVER["PHP_SELF"],'p.fk_opp_status',"",$param,'align="center"',$sortfield,$sortorder);
  604. if (! empty($arrayfields['p.opp_amount']['checked'])) print_liste_field_titre($arrayfields['p.opp_amount']['label'],$_SERVER["PHP_SELF"],'p.opp_amount',"",$param,'align="right"',$sortfield,$sortorder);
  605. if (! empty($arrayfields['p.opp_percent']['checked'])) print_liste_field_titre($arrayfields['p.opp_percent']['label'],$_SERVER["PHP_SELF"],'p.opp_percent',"",$param,'align="right"',$sortfield,$sortorder);
  606. if (! empty($arrayfields['p.budget_amount']['checked'])) print_liste_field_titre($arrayfields['p.budget_amount']['label'],$_SERVER["PHP_SELF"],'p.budget_amount',"",$param,'align="right"',$sortfield,$sortorder);
  607. // Extra fields
  608. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  609. // Hook fields
  610. $parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder);
  611. $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
  612. print $hookmanager->resPrint;
  613. if (! empty($arrayfields['p.datec']['checked'])) print_liste_field_titre($arrayfields['p.datec']['label'],$_SERVER["PHP_SELF"],"p.datec","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
  614. if (! empty($arrayfields['p.tms']['checked'])) print_liste_field_titre($arrayfields['p.tms']['label'],$_SERVER["PHP_SELF"],"p.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
  615. if (! empty($arrayfields['p.fk_statut']['checked'])) print_liste_field_titre($arrayfields['p.fk_statut']['label'],$_SERVER["PHP_SELF"],"p.fk_statut","",$param,'align="right"',$sortfield,$sortorder);
  616. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
  617. print "</tr>\n";
  618. $i=0;
  619. $totalarray=array();
  620. while ($i < min($num,$limit))
  621. {
  622. $obj = $db->fetch_object($resql);
  623. $object->id = $obj->id;
  624. $object->user_author_id = $obj->fk_user_creat;
  625. $object->public = $obj->public;
  626. $object->ref = $obj->ref;
  627. $object->datee = $db->jdate($obj->date_end);
  628. $object->statut = $obj->fk_statut;
  629. $object->opp_status = $obj->fk_opp_status;
  630. $object->title = $obj->title;
  631. $userAccess = $object->restrictedProjectArea($user); // why this ?
  632. if ($userAccess >= 0)
  633. {
  634. print '<tr class="oddeven">';
  635. // Project url
  636. if (! empty($arrayfields['p.ref']['checked']))
  637. {
  638. print '<td class="nowrap">';
  639. print $object->getNomUrl(1);
  640. if ($object->hasDelay()) print img_warning($langs->trans('Late'));
  641. print '</td>';
  642. if (! $i) $totalarray['nbfield']++;
  643. }
  644. // Title
  645. if (! empty($arrayfields['p.title']['checked']))
  646. {
  647. print '<td class="tdoverflowmax100">';
  648. print dol_trunc($obj->title,80);
  649. print '</td>';
  650. if (! $i) $totalarray['nbfield']++;
  651. }
  652. // Company
  653. if (! empty($arrayfields['s.nom']['checked']))
  654. {
  655. print '<td class="tdoverflowmax100">';
  656. if ($obj->socid)
  657. {
  658. $socstatic->id=$obj->socid;
  659. $socstatic->name=$obj->name;
  660. print $socstatic->getNomUrl(1);
  661. }
  662. else
  663. {
  664. print '&nbsp;';
  665. }
  666. print '</td>';
  667. if (! $i) $totalarray['nbfield']++;
  668. }
  669. // Sales Representatives
  670. if (! empty($arrayfields['commercial']['checked']))
  671. {
  672. print '<td>';
  673. if ($obj->socid)
  674. {
  675. $socstatic->id=$obj->socid;
  676. $socstatic->name=$obj->name;
  677. $listsalesrepresentatives=$socstatic->getSalesRepresentatives($user);
  678. $nbofsalesrepresentative=count($listsalesrepresentatives);
  679. if ($nbofsalesrepresentative > 3) // We print only number
  680. {
  681. print '<a href="'.DOL_URL_ROOT.'/societe/commerciaux.php?socid='.$socstatic->id.'">';
  682. print $nbofsalesrepresentative;
  683. print '</a>';
  684. }
  685. else if ($nbofsalesrepresentative > 0)
  686. {
  687. $userstatic=new User($db);
  688. $j=0;
  689. foreach($listsalesrepresentatives as $val)
  690. {
  691. $userstatic->id=$val['id'];
  692. $userstatic->lastname=$val['lastname'];
  693. $userstatic->firstname=$val['firstname'];
  694. $userstatic->email=$val['email'];
  695. $userstatic->statut=$val['statut'];
  696. $userstatic->entity=$val['entity'];
  697. $userstatic->photo=$val['photo'];
  698. //print $userstatic->getNomUrl(1, '', 0, 0, 12);
  699. print $userstatic->getNomUrl(-2);
  700. $j++;
  701. if ($j < $nbofsalesrepresentative) print ' ';
  702. }
  703. }
  704. //else print $langs->trans("NoSalesRepresentativeAffected");
  705. }
  706. else
  707. {
  708. print '&nbsp';
  709. }
  710. print '</td>';
  711. if (! $i) $totalarray['nbfield']++;
  712. }
  713. // Date start
  714. if (! empty($arrayfields['p.dateo']['checked']))
  715. {
  716. print '<td class="center">';
  717. print dol_print_date($db->jdate($obj->date_start),'day');
  718. print '</td>';
  719. if (! $i) $totalarray['nbfield']++;
  720. }
  721. // Date end
  722. if (! empty($arrayfields['p.datee']['checked']))
  723. {
  724. print '<td class="center">';
  725. print dol_print_date($db->jdate($obj->date_end),'day');
  726. print '</td>';
  727. if (! $i) $totalarray['nbfield']++;
  728. }
  729. // Visibility
  730. if (! empty($arrayfields['p.public']['checked']))
  731. {
  732. print '<td align="left">';
  733. if ($obj->public) print $langs->trans('SharedProject');
  734. else print $langs->trans('PrivateProject');
  735. print '</td>';
  736. if (! $i) $totalarray['nbfield']++;
  737. }
  738. // Opp Status
  739. if (! empty($arrayfields['p.fk_opp_status']['checked']))
  740. {
  741. print '<td class="center">';
  742. if ($obj->opp_status_code) print $langs->trans("OppStatus".$obj->opp_status_code);
  743. print '</td>';
  744. if (! $i) $totalarray['nbfield']++;
  745. }
  746. // Opp Amount
  747. if (! empty($arrayfields['p.opp_amount']['checked']))
  748. {
  749. print '<td align="right">';
  750. //if ($obj->opp_status_code)
  751. if (strcmp($obj->opp_amount,''))
  752. {
  753. print price($obj->opp_amount, 1, $langs, 1, -1, -1, '');
  754. $totalarray['totalopp'] += $obj->opp_amount;
  755. }
  756. print '</td>';
  757. if (! $i) $totalarray['nbfield']++;
  758. if (! $i) $totalarray['totaloppfield']=$totalarray['nbfield'];
  759. }
  760. // Opp percent
  761. if (! empty($arrayfields['p.opp_percent']['checked']))
  762. {
  763. print '<td align="right">';
  764. if ($obj->opp_percent) print price($obj->opp_percent, 1, $langs, 1, 0).'%';
  765. print '</td>';
  766. if (! $i) $totalarray['nbfield']++;
  767. }
  768. // Budget
  769. if (! empty($arrayfields['p.budget_amount']['checked']))
  770. {
  771. print '<td align="right">';
  772. if ($obj->budget_amount != '')
  773. {
  774. print price($obj->budget_amount, 1, $langs, 1, -1, -1);
  775. $totalarray['totalbudget'] += $obj->budget_amount;
  776. }
  777. print '</td>';
  778. if (! $i) $totalarray['nbfield']++;
  779. if (! $i) $totalarray['totalbudgetfield']=$totalarray['nbfield'];
  780. }
  781. // Extra fields
  782. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  783. // Fields from hook
  784. $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
  785. $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
  786. print $hookmanager->resPrint;
  787. // Date creation
  788. if (! empty($arrayfields['p.datec']['checked']))
  789. {
  790. print '<td align="center">';
  791. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  792. print '</td>';
  793. if (! $i) $totalarray['nbfield']++;
  794. }
  795. // Date modification
  796. if (! empty($arrayfields['p.tms']['checked']))
  797. {
  798. print '<td align="center">';
  799. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  800. print '</td>';
  801. if (! $i) $totalarray['nbfield']++;
  802. }
  803. // Status
  804. if (! empty($arrayfields['p.fk_statut']['checked']))
  805. {
  806. print '<td align="right">'.$object->getLibStatut(5).'</td>';
  807. if (! $i) $totalarray['nbfield']++;
  808. }
  809. // Action column
  810. print '<td class="nowrap" align="center">';
  811. if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  812. {
  813. $selected=0;
  814. if (in_array($obj->id, $arrayofselected)) $selected=1;
  815. print '<input id="cb'.$obj->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->id.'"'.($selected?' checked="checked"':'').'>';
  816. }
  817. print '</td>';
  818. if (! $i) $totalarray['nbfield']++;
  819. print "</tr>\n";
  820. }
  821. $i++;
  822. }
  823. // Show total line
  824. if (isset($totalarray['totaloppfield']) || isset($totalarray['totalbudgetfield']))
  825. {
  826. print '<tr class="liste_total">';
  827. $i=0;
  828. while ($i < $totalarray['nbfield'])
  829. {
  830. $i++;
  831. if ($i == 1)
  832. {
  833. if ($num < $limit && empty($offset)) print '<td align="left">'.$langs->trans("Total").'</td>';
  834. else print '<td align="left">'.$langs->trans("Totalforthispage").'</td>';
  835. }
  836. elseif ($totalarray['totaloppfield'] == $i) print '<td align="right">'.price($totalarray['totalopp'], 1, $langs, 1, -1, -1).'</td>';
  837. elseif ($totalarray['totalbudgetfield'] == $i) print '<td align="right">'.price($totalarray['totalbudget'], 1, $langs, 1, -1, -1).'</td>';
  838. else print '<td></td>';
  839. }
  840. print '</tr>';
  841. }
  842. $db->free($resql);
  843. $parameters=array('sql' => $sql);
  844. $reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook
  845. print $hookmanager->resPrint;
  846. print "</table>\n";
  847. print '</div>';
  848. print "</form>\n";
  849. // End of page
  850. llxFooter();
  851. $db->close();