list.php 44 KB

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