list.php 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368
  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. * Copyright (C) 2020 Tobias Sean <tobias.sekan@startmail.com>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * \file htdocs/projet/list.php
  27. * \ingroup project
  28. * \brief Page to list projects
  29. */
  30. require '../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  35. if (!empty($conf->categorie->enabled)) {
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcategory.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  38. }
  39. // Load translation files required by the page
  40. $langs->loadLangs(array('projects', 'companies', 'commercial'));
  41. if ($conf->eventorganization->enabled) {
  42. $langs->loadLangs(array('eventorganization'));
  43. }
  44. $action = GETPOST('action', 'aZ09');
  45. $massaction = GETPOST('massaction', 'alpha');
  46. $show_files = GETPOST('show_files', 'int');
  47. $confirm = GETPOST('confirm', 'alpha');
  48. $toselect = GETPOST('toselect', 'array');
  49. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'projectlist';
  50. $title = $langs->trans("Projects");
  51. // Security check
  52. $socid = (is_numeric($_GET["socid"]) ? $_GET["socid"] : 0);
  53. //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.
  54. if ($socid > 0) {
  55. $soc = new Societe($db);
  56. $soc->fetch($socid);
  57. $title .= ' (<a href="list.php">'.$soc->name.'</a>)';
  58. }
  59. if (!$user->rights->projet->lire) {
  60. accessforbidden();
  61. }
  62. $diroutputmassaction = $conf->projet->dir_output.'/temp/massgeneration/'.$user->id;
  63. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  64. $sortfield = GETPOST("sortfield", "aZ09comma");
  65. $sortorder = GETPOST("sortorder", 'aZ09comma');
  66. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  67. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  68. $page = 0;
  69. } // If $page is not defined, or '' or -1 or if we click on clear filters
  70. if (!$sortfield) {
  71. $sortfield = "p.ref";
  72. }
  73. if (!$sortorder) {
  74. $sortorder = "ASC";
  75. }
  76. $offset = $limit * $page;
  77. $pageprev = $page - 1;
  78. $pagenext = $page + 1;
  79. $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
  80. $search_ref = GETPOST("search_ref", 'alpha');
  81. $search_label = GETPOST("search_label", 'alpha');
  82. $search_societe = GETPOST("search_societe", 'alpha');
  83. $search_status = GETPOST("search_status", 'int');
  84. $search_opp_status = GETPOST("search_opp_status", 'alpha');
  85. $search_opp_percent = GETPOST("search_opp_percent", 'alpha');
  86. $search_opp_amount = GETPOST("search_opp_amount", 'alpha');
  87. $search_budget_amount = GETPOST("search_budget_amount", 'alpha');
  88. $search_public = GETPOST("search_public", 'int');
  89. $search_project_user = GETPOST('search_project_user', 'int');
  90. $search_sale = GETPOST('search_sale', 'int');
  91. $search_usage_opportunity = GETPOST('search_usage_opportunity', 'int');
  92. $search_usage_task = GETPOST('search_usage_task', 'int');
  93. $search_usage_bill_time = GETPOST('search_usage_bill_time', 'int');
  94. $search_usage_event_organization = GETPOST('search_usage_event_organization', 'int');
  95. $search_accept_conference_suggestions = GETPOST('search_accept_conference_suggestions', 'int');
  96. $search_accept_booth_suggestions = GETPOST('search_accept_booth_suggestions', 'int');
  97. $search_price_registration = GETPOST("search_price_registration", 'alpha');
  98. $search_price_booth = GETPOST("search_price_booth", 'alpha');
  99. $optioncss = GETPOST('optioncss', 'alpha');
  100. $mine = $_REQUEST['mode'] == 'mine' ? 1 : 0;
  101. if ($mine) {
  102. $search_project_user = $user->id; $mine = 0;
  103. }
  104. $search_sday = GETPOST('search_sday', 'int');
  105. $search_smonth = GETPOST('search_smonth', 'int');
  106. $search_syear = GETPOST('search_syear', 'int');
  107. $search_eday = GETPOST('search_eday', 'int');
  108. $search_emonth = GETPOST('search_emonth', 'int');
  109. $search_eyear = GETPOST('search_eyear', 'int');
  110. if ($search_status == '') {
  111. $search_status = -1; // -1 or 1
  112. }
  113. if (!empty($conf->categorie->enabled)) {
  114. $search_category_array = GETPOST("search_category_".Categorie::TYPE_PROJECT."_list", "array");
  115. }
  116. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  117. $object = new Project($db);
  118. $hookmanager->initHooks(array('projectlist'));
  119. $extrafields = new ExtraFields($db);
  120. // fetch optionals attributes and labels
  121. $extrafields->fetch_name_optionals_label($object->table_element);
  122. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  123. // List of fields to search into when doing a "search in all"
  124. $fieldstosearchall = array();
  125. foreach ($object->fields as $key => $val) {
  126. if (empty($val['searchall'])) {
  127. continue;
  128. }
  129. // Don't allow search in private notes for external users when doing "search in all"
  130. if (!empty($user->socid) && $key == "note_private") {
  131. continue;
  132. }
  133. $fieldstosearchall['p.'.$key] = $val['label'];
  134. }
  135. // Add name object fields to "search in all"
  136. $fieldstosearchall['s.nom'] = "ThirdPartyName";
  137. // Definition of array of fields for columns
  138. $arrayfields = array();
  139. foreach ($object->fields as $key => $val) {
  140. // If $val['visible']==0, then we never show the field
  141. if (!empty($val['visible'])) {
  142. $visible = dol_eval($val['visible'], 1);
  143. $arrayfields['p.'.$key] = array(
  144. 'label'=>$val['label'],
  145. 'checked'=>(($visible < 0) ? 0 : 1),
  146. 'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1)),
  147. 'position'=>$val['position'],
  148. 'help'=> isset($val['help']) ? $val['help'] : ''
  149. );
  150. }
  151. }
  152. // Extra fields
  153. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  154. // Add non object fields to fields for list
  155. $arrayfields['s.nom'] = array('label'=>$langs->trans("ThirdParty"), 'checked'=>1, 'position'=>21, 'enabled'=>(empty($conf->societe->enabled) ? 0 : 1));
  156. $arrayfields['commercial'] = array('label'=>$langs->trans("SaleRepresentativesOfThirdParty"), 'checked'=>0, 'position'=>23);
  157. $arrayfields['opp_weighted_amount'] = array('label'=>$langs->trans('OpportunityWeightedAmountShort'), 'checked'=>0, 'position'=> 116, 'enabled'=>(empty($conf->global->PROJECT_USE_OPPORTUNITIES) ? 0 : 1), 'position'=>106);
  158. // Force some fields according to search_usage filter...
  159. if (GETPOST('search_usage_opportunity')) {
  160. //$arrayfields['p.usage_opportunity']['visible'] = 1; // Not require, filter on search_opp_status is enough
  161. //$arrayfields['p.usage_opportunity']['checked'] = 1; // Not require, filter on search_opp_status is enough
  162. }
  163. if (GETPOST('search_usage_event_organization')) {
  164. $arrayfields['p.fk_opp_status']['enabled'] = 0;
  165. $arrayfields['p.opp_amount']['enabled'] = 0;
  166. $arrayfields['p.opp_percent']['enabled'] = 0;
  167. $arrayfields['opp_weighted_amount']['enabled'] = 0;
  168. $arrayfields['p.usage_organize_event']['visible'] = 1;
  169. $arrayfields['p.usage_organize_event']['checked'] = 1;
  170. }
  171. $object->fields = dol_sort_array($object->fields, 'position');
  172. $arrayfields = dol_sort_array($arrayfields, 'position');
  173. /*
  174. * Actions
  175. */
  176. if (GETPOST('cancel', 'alpha')) {
  177. $action = 'list'; $massaction = '';
  178. }
  179. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') {
  180. $massaction = '';
  181. }
  182. $parameters = array('socid'=>$socid);
  183. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  184. if ($reshook < 0) {
  185. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  186. }
  187. if (empty($reshook)) {
  188. // Selection of new fields
  189. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  190. // Purge search criteria
  191. 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
  192. $search_all = '';
  193. $search_ref = "";
  194. $search_label = "";
  195. $search_societe = "";
  196. $search_status = -1;
  197. $search_opp_status = -1;
  198. $search_opp_amount = '';
  199. $search_opp_percent = '';
  200. $search_budget_amount = '';
  201. $search_public = "";
  202. $search_sale = "";
  203. $search_project_user = '';
  204. $search_sday = "";
  205. $search_smonth = "";
  206. $search_syear = "";
  207. $search_eday = "";
  208. $search_emonth = "";
  209. $search_eyear = "";
  210. $search_usage_opportunity = '';
  211. $search_usage_task = '';
  212. $search_usage_bill_time = '';
  213. $search_usage_event_organization = '';
  214. $search_accept_conference_suggestions = '';
  215. $search_accept_booth_suggestions = '';
  216. $search_price_registration = '';
  217. $search_price_booth = '';
  218. $toselect = '';
  219. $search_array_options = array();
  220. $search_category_array = array();
  221. }
  222. // Mass actions
  223. $objectclass = 'Project';
  224. $objectlabel = 'Project';
  225. $permissiontoread = $user->rights->projet->lire;
  226. $permissiontodelete = $user->rights->projet->supprimer;
  227. $permissiontoadd = $user->rights->projet->creer;
  228. $uploaddir = $conf->projet->dir_output;
  229. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  230. // Close records
  231. if (!$error && $massaction == 'close' && $user->rights->projet->creer) {
  232. $db->begin();
  233. $objecttmp = new $objectclass($db);
  234. $nbok = 0;
  235. foreach ($toselect as $toselectid) {
  236. $result = $objecttmp->fetch($toselectid);
  237. if ($result > 0) {
  238. $userWrite = $object->restrictedProjectArea($user, 'write');
  239. if ($userWrite > 0 && $objecttmp->statut == 1) {
  240. $result = $objecttmp->setClose($user);
  241. if ($result <= 0) {
  242. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  243. $error++;
  244. break;
  245. } else {
  246. $nbok++;
  247. }
  248. } elseif ($userWrite <= 0) {
  249. setEventMessages($langs->trans("DontHavePermissionForCloseProject", $objecttmp->ref), null, 'warnings');
  250. } else {
  251. setEventMessages($langs->trans("DontHaveTheValidateStatus", $objecttmp->ref), null, 'warnings');
  252. }
  253. } else {
  254. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  255. $error++;
  256. break;
  257. }
  258. }
  259. if (!$error) {
  260. if ($nbok > 1) {
  261. setEventMessages($langs->trans("RecordsClosed", $nbok), null, 'mesgs');
  262. } else {
  263. setEventMessages($langs->trans("RecordsClosed", $nbok), null, 'mesgs');
  264. }
  265. $db->commit();
  266. } else {
  267. $db->rollback();
  268. }
  269. }
  270. }
  271. /*
  272. * View
  273. */
  274. $companystatic = new Societe($db);
  275. $form = new Form($db);
  276. $formother = new FormOther($db);
  277. $formproject = new FormProjets($db);
  278. $help_url = "EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
  279. $title = $langs->trans("Projects");
  280. // Get list of project id allowed to user (in a string list separated by comma)
  281. $projectsListId = '';
  282. if (!$user->rights->projet->all->lire) {
  283. $projectsListId = $object->getProjectsAuthorizedForUser($user, 0, 1, $socid);
  284. }
  285. // Get id of types of contacts for projects (This list never contains a lot of elements)
  286. $listofprojectcontacttype = array();
  287. $sql = "SELECT ctc.rowid, ctc.code FROM ".MAIN_DB_PREFIX."c_type_contact as ctc";
  288. $sql .= " WHERE ctc.element = '".$db->escape($object->element)."'";
  289. $sql .= " AND ctc.source = 'internal'";
  290. $resql = $db->query($sql);
  291. if ($resql) {
  292. while ($obj = $db->fetch_object($resql)) {
  293. $listofprojectcontacttype[$obj->rowid] = $obj->code;
  294. }
  295. } else {
  296. dol_print_error($db);
  297. }
  298. if (count($listofprojectcontacttype) == 0) {
  299. $listofprojectcontacttype[0] = '0'; // To avoid sql syntax error if not found
  300. }
  301. $distinct = 'DISTINCT'; // We add distinct until we are added a protection to be sure a contact of a project and task is only once.
  302. $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,";
  303. $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,";
  304. $sql .= " p.usage_opportunity, p.usage_task, p.usage_bill_time, p.usage_organize_event,";
  305. $sql .= " p.email_msgid,";
  306. $sql .= " accept_conference_suggestions, accept_booth_suggestions, price_registration, price_booth,";
  307. $sql .= " s.rowid as socid, s.nom as name, s.name_alias as alias, s.email, s.email, s.phone, s.fax, s.address, s.town, s.zip, s.fk_pays, s.client, s.code_client,";
  308. $sql .= " country.code as country_code,";
  309. $sql .= " cls.code as opp_status_code";
  310. // Add fields from extrafields
  311. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  312. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  313. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
  314. }
  315. }
  316. // Add fields from hooks
  317. $parameters = array();
  318. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  319. $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
  320. $sql = preg_replace('/,\s*$/', '', $sql);
  321. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as p";
  322. if (!empty($conf->categorie->enabled)) {
  323. $sql .= Categorie::getFilterJoinQuery(Categorie::TYPE_PROJECT, "p.rowid");
  324. }
  325. if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  326. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (p.rowid = ef.fk_object)";
  327. }
  328. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
  329. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  330. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_lead_status as cls on p.fk_opp_status = cls.rowid";
  331. // We'll need this table joined to the select in order to filter by sale
  332. // No check is done on company permission because readability is managed by public status of project and assignement.
  333. //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";
  334. if ($search_sale > 0) {
  335. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = s.rowid";
  336. }
  337. if ($search_project_user > 0) {
  338. $sql .= ", ".MAIN_DB_PREFIX."element_contact as ecp";
  339. }
  340. $sql .= " WHERE p.entity IN (".getEntity('project').')';
  341. if (!empty($conf->categorie->enabled)) {
  342. $sql .= Categorie::getFilterSelectQuery(Categorie::TYPE_PROJECT, "p.rowid", $search_category_array);
  343. }
  344. if (!$user->rights->projet->all->lire) {
  345. $sql .= " AND p.rowid IN (".$db->sanitize($projectsListId).")"; // public and assigned to, or restricted to company for external users
  346. }
  347. // No need to check if company is external user, as filtering of projects must be done by getProjectsAuthorizedForUser
  348. if ($socid > 0) {
  349. $sql .= " AND (p.fk_soc = ".((int) $socid).")"; // This filter if when we use a hard coded filter on company on url (not related to filter for external users)
  350. }
  351. if ($search_ref) {
  352. $sql .= natural_search('p.ref', $search_ref);
  353. }
  354. if ($search_label) {
  355. $sql .= natural_search('p.title', $search_label);
  356. }
  357. if ($search_societe) {
  358. $sql .= natural_search('s.nom', $search_societe);
  359. }
  360. if ($search_opp_amount) {
  361. $sql .= natural_search('p.opp_amount', $search_opp_amount, 1);
  362. }
  363. if ($search_opp_percent) {
  364. $sql .= natural_search('p.opp_percent', $search_opp_percent, 1);
  365. }
  366. $sql .= dolSqlDateFilter('p.dateo', $search_sday, $search_smonth, $search_syear);
  367. $sql .= dolSqlDateFilter('p.datee', $search_eday, $search_emonth, $search_eyear);
  368. if ($search_all) {
  369. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  370. }
  371. if ($search_status >= 0) {
  372. if ($search_status == 99) {
  373. $sql .= " AND p.fk_statut <> 2";
  374. } else {
  375. $sql .= " AND p.fk_statut = ".((int) $search_status);
  376. }
  377. }
  378. if ($search_opp_status) {
  379. if (is_numeric($search_opp_status) && $search_opp_status > 0) {
  380. $sql .= " AND p.fk_opp_status = ".((int) $search_opp_status);
  381. }
  382. if ($search_opp_status == 'all') {
  383. $sql .= " AND (p.fk_opp_status IS NOT NULL AND p.fk_opp_status <> -1)";
  384. }
  385. if ($search_opp_status == 'openedopp') {
  386. $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'))";
  387. }
  388. if ($search_opp_status == 'notopenedopp') {
  389. $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 = 'WON'))";
  390. }
  391. if ($search_opp_status == 'none') {
  392. $sql .= " AND (p.fk_opp_status IS NULL OR p.fk_opp_status = -1)";
  393. }
  394. }
  395. if ($search_public != '') {
  396. $sql .= " AND p.public = ".((int) $search_public);
  397. }
  398. // For external user, no check is done on company permission because readability is managed by public status of project and assignement.
  399. //if ($socid > 0) $sql.= " AND s.rowid = ".((int) $socid);
  400. if ($search_sale > 0) {
  401. $sql .= " AND sc.fk_user = ".((int) $search_sale);
  402. }
  403. // No check is done on company permission because readability is managed by public status of project and assignement.
  404. //if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id).") OR (s.rowid IS NULL))";
  405. if ($search_project_user > 0) {
  406. $sql .= " AND ecp.fk_c_type_contact IN (".$db->sanitize(join(',', array_keys($listofprojectcontacttype))).") AND ecp.element_id = p.rowid AND ecp.fk_socpeople = ".((int) $search_project_user);
  407. }
  408. if ($search_opp_amount != '') {
  409. $sql .= natural_search('p.opp_amount', $search_opp_amount, 1);
  410. }
  411. if ($search_budget_amount != '') {
  412. $sql .= natural_search('p.budget_amount', $search_budget_amount, 1);
  413. }
  414. if ($search_usage_opportunity != '' && $search_usage_opportunity >= 0) {
  415. $sql .= natural_search('p.usage_opportunity', $search_usage_opportunity, 2);
  416. }
  417. if ($search_usage_task != '' && $search_usage_task >= 0) {
  418. $sql .= natural_search('p.usage_task', $search_usage_task, 2);
  419. }
  420. if ($search_usage_bill_time != '' && $search_usage_bill_time >= 0) {
  421. $sql .= natural_search('p.usage_bill_time', $search_usage_bill_time, 2);
  422. }
  423. if ($search_usage_event_organization != '' && $search_usage_event_organization >= 0) {
  424. $sql .= natural_search('p.usage_organize_event', $search_usage_event_organization, 2);
  425. }
  426. if ($search_accept_conference_suggestions != '' && $search_accept_conference_suggestions >= 0) {
  427. $sql .= natural_search('p.accept_conference_suggestions', $search_accept_conference_suggestions, 2);
  428. }
  429. if ($search_accept_booth_suggestions != '' && $search_accept_booth_suggestions >= 0) {
  430. $sql .= natural_search('p.accept_booth_suggestions', $search_accept_booth_suggestions, 2);
  431. }
  432. if ($search_price_registration != '') {
  433. $sql .= natural_search('p.price_registration', $search_price_registration, 1);
  434. }
  435. if ($search_price_booth != '') {
  436. $sql .= natural_search('p.price_booth', $search_price_booth, 1);
  437. }
  438. // Add where from extra fields
  439. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  440. // Add where from hooks
  441. $parameters = array();
  442. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  443. $sql .= $hookmanager->resPrint;
  444. $sql .= $db->order($sortfield, $sortorder);
  445. // Count total nb of records
  446. $nbtotalofrecords = '';
  447. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  448. $resql = $db->query($sql);
  449. $nbtotalofrecords = $db->num_rows($resql);
  450. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  451. $page = 0;
  452. $offset = 0;
  453. }
  454. }
  455. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
  456. if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
  457. $num = $nbtotalofrecords;
  458. } else {
  459. if ($limit) {
  460. $sql .= $db->plimit($limit + 1, $offset);
  461. }
  462. $resql = $db->query($sql);
  463. if (!$resql) {
  464. dol_print_error($db);
  465. exit;
  466. }
  467. $num = $db->num_rows($resql);
  468. }
  469. // Direct jump if only one record found
  470. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all) {
  471. $obj = $db->fetch_object($resql);
  472. header("Location: ".DOL_URL_ROOT.'/projet/card.php?id='.$obj->id);
  473. exit;
  474. }
  475. // Output page
  476. // --------------------------------------------------------------------
  477. dol_syslog("list allowed project", LOG_DEBUG);
  478. llxHeader('', $title, $help_url);
  479. $arrayofselected = is_array($toselect) ? $toselect : array();
  480. $param = '';
  481. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  482. $param .= '&contextpage='.urlencode($contextpage);
  483. }
  484. if ($limit > 0 && $limit != $conf->liste_limit) {
  485. $param .= '&limit='.urlencode($limit);
  486. }
  487. if ($search_all != '') {
  488. $param .= '&search_all='.urlencode($search_all);
  489. }
  490. if ($search_sday) {
  491. $param .= '&search_sday='.urlencode($search_sday);
  492. }
  493. if ($search_smonth) {
  494. $param .= '&search_smonth='.urlencode($search_smonth);
  495. }
  496. if ($search_syear) {
  497. $param .= '&search_syear='.urlencode($search_syear);
  498. }
  499. if ($search_eday) {
  500. $param .= '&search_eday='.urlencode($search_eday);
  501. }
  502. if ($search_emonth) {
  503. $param .= '&search_emonth='.urlencode($search_emonth);
  504. }
  505. if ($search_eyear) {
  506. $param .= '&search_eyear='.urlencode($search_eyear);
  507. }
  508. if ($socid) {
  509. $param .= '&socid='.urlencode($socid);
  510. }
  511. if ($search_categ) {
  512. $param .= '&search_categ='.urlencode($search_categ);
  513. }
  514. if ($search_ref != '') {
  515. $param .= '&search_ref='.urlencode($search_ref);
  516. }
  517. if ($search_label != '') {
  518. $param .= '&search_label='.urlencode($search_label);
  519. }
  520. if ($search_societe != '') {
  521. $param .= '&search_societe='.urlencode($search_societe);
  522. }
  523. if ($search_status >= 0) {
  524. $param .= '&search_status='.urlencode($search_status);
  525. }
  526. if ((is_numeric($search_opp_status) && $search_opp_status >= 0) || in_array($search_opp_status, array('all', 'openedopp', 'notopenedopp', 'none'))) {
  527. $param .= '&search_opp_status='.urlencode($search_opp_status);
  528. }
  529. if ($search_opp_percent != '') {
  530. $param .= '&search_opp_percent='.urlencode($search_opp_percent);
  531. }
  532. if ($search_public != '') {
  533. $param .= '&search_public='.urlencode($search_public);
  534. }
  535. if ($search_project_user != '') {
  536. $param .= '&search_project_user='.urlencode($search_project_user);
  537. }
  538. if ($search_sale > 0) {
  539. $param .= '&search_sale='.urlencode($search_sale);
  540. }
  541. if ($search_opp_amount != '') {
  542. $param .= '&search_opp_amount='.urlencode($search_opp_amount);
  543. }
  544. if ($search_budget_amount != '') {
  545. $param .= '&search_budget_amount='.urlencode($search_budget_amount);
  546. }
  547. if ($search_usage_task != '') {
  548. $param .= '&search_usage_task='.urlencode($search_usage_task);
  549. }
  550. if ($search_usage_bill_time != '') {
  551. $param .= '&search_usage_opportunity='.urlencode($search_usage_bill_time);
  552. }
  553. if ($search_usage_event_organization != '') {
  554. $param .= '&search_usage_event_organization='.urlencode($search_usage_event_organization);
  555. }
  556. if ($search_accept_conference_suggestions != '') {
  557. $param .= '&search_accept_conference_suggestions='.urlencode($search_accept_conference_suggestions);
  558. }
  559. if ($search_accept_booth_suggestions != '') {
  560. $param .= '&search_accept_booth_suggestions='.urlencode($search_accept_booth_suggestions);
  561. }
  562. if ($search_price_registration != '') {
  563. $param .= '&search_price_registration='.urlencode($search_price_registration);
  564. }
  565. if ($search_price_booth != '') {
  566. $param .= '&search_price_booth='.urlencode($search_price_booth);
  567. }
  568. if ($optioncss != '') {
  569. $param .= '&optioncss='.urlencode($optioncss);
  570. }
  571. // Add $param from extra fields
  572. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  573. // List of mass actions available
  574. $arrayofmassactions = array(
  575. 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  576. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  577. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  578. );
  579. //if($user->rights->societe->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
  580. if ($user->rights->projet->creer) {
  581. $arrayofmassactions['close'] = img_picto('', 'close_title', 'class="pictofixedwidth"').$langs->trans("Close");
  582. }
  583. if ($user->rights->projet->supprimer) {
  584. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  585. }
  586. if ($user->rights->projet->creer) {
  587. $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
  588. }
  589. if (in_array($massaction, array('presend', 'predelete', 'preaffecttag'))) {
  590. $arrayofmassactions = array();
  591. }
  592. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  593. $url = DOL_URL_ROOT.'/projet/card.php?action=create';
  594. if (!empty($socid)) {
  595. $url .= '&socid='.$socid;
  596. }
  597. $newcardbutton = dolGetButtonTitle($langs->trans('NewProject'), '', 'fa fa-plus-circle', $url, '', $user->rights->projet->creer);
  598. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  599. if ($optioncss != '') {
  600. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  601. }
  602. print '<input type="hidden" name="token" value="'.newToken().'">';
  603. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  604. print '<input type="hidden" name="action" value="list">';
  605. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  606. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  607. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  608. // Show description of content
  609. $texthelp = '';
  610. if ($search_project_user == $user->id) {
  611. $texthelp .= $langs->trans("MyProjectsDesc");
  612. } else {
  613. if ($user->rights->projet->all->lire && !$socid) {
  614. $texthelp .= $langs->trans("ProjectsDesc");
  615. } else {
  616. $texthelp .= $langs->trans("ProjectsPublicDesc");
  617. }
  618. }
  619. print_barre_liste($form->textwithpicto($title, $texthelp), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'project', 0, $newcardbutton, '', $limit, 0, 0, 1);
  620. $topicmail = "Information";
  621. $modelmail = "project";
  622. $objecttmp = new Project($db);
  623. $trackid = 'proj'.$object->id;
  624. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  625. if ($search_all) {
  626. foreach ($fieldstosearchall as $key => $val) {
  627. $fieldstosearchall[$key] = $langs->trans($val);
  628. }
  629. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  630. }
  631. $moreforfilter = '';
  632. // If the user can view user other than himself
  633. $moreforfilter .= '<div class="divsearchfield">';
  634. $tmptitle = $langs->trans('ProjectsWithThisUserAsContact');
  635. //$includeonly = 'hierarchyme';
  636. $includeonly = '';
  637. if (empty($user->rights->user->user->lire)) {
  638. $includeonly = array($user->id);
  639. }
  640. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_project_user ? $search_project_user : '', 'search_project_user', $tmptitle, '', 0, $includeonly, '', 0, 0, 0, '', 0, '', 'maxwidth250');
  641. $moreforfilter .= '</div>';
  642. // If the user can view thirdparties other than his'
  643. if ($user->rights->societe->client->voir || $socid) {
  644. $langs->load("commercial");
  645. $moreforfilter .= '<div class="divsearchfield">';
  646. $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
  647. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth250');
  648. $moreforfilter .= '</div>';
  649. }
  650. // Filter on categories
  651. if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) {
  652. $formcategory = new FormCategory($db);
  653. $moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_PROJECT, $search_category_array);
  654. }
  655. if (!empty($moreforfilter)) {
  656. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  657. print $moreforfilter;
  658. $parameters = array();
  659. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  660. print $hookmanager->resPrint;
  661. print '</div>';
  662. }
  663. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  664. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  665. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  666. print '<div class="div-table-responsive">';
  667. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  668. // Fields title search
  669. // --------------------------------------------------------------------
  670. print '<tr class="liste_titre_filter">';
  671. // Project ref
  672. if (!empty($arrayfields['p.ref']['checked'])) {
  673. print '<td class="liste_titre">';
  674. print '<input type="text" class="flat" name="search_ref" value="'.dol_escape_htmltag($search_ref).'" size="6">';
  675. print '</td>';
  676. }
  677. // Project label
  678. if (!empty($arrayfields['p.title']['checked'])) {
  679. print '<td class="liste_titre">';
  680. print '<input type="text" class="flat" name="search_label" size="8" value="'.dol_escape_htmltag($search_label).'">';
  681. print '</td>';
  682. }
  683. // Third party
  684. if (!empty($arrayfields['s.nom']['checked'])) {
  685. print '<td class="liste_titre">';
  686. if ($socid > 0) {
  687. $tmpthirdparty = new Societe($db);
  688. $tmpthirdparty->fetch($socid);
  689. $search_societe = $tmpthirdparty->name;
  690. }
  691. print '<input type="text" class="flat" name="search_societe" size="8" value="'.dol_escape_htmltag($search_societe).'">';
  692. print '</td>';
  693. }
  694. // Sale representative
  695. if (!empty($arrayfields['commercial']['checked'])) {
  696. print '<td class="liste_titre">&nbsp;</td>';
  697. }
  698. // Start date
  699. if (!empty($arrayfields['p.dateo']['checked'])) {
  700. print '<td class="liste_titre center nowraponall">';
  701. if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) {
  702. print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_sday" value="'.dol_escape_htmltag($search_sday).'">';
  703. }
  704. print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_smonth" value="'.dol_escape_htmltag($search_smonth).'">';
  705. $formother->select_year($search_syear ? $search_syear : -1, 'search_syear', 1, 20, 5, 0, 0, '', 'widthauto valignmiddle');
  706. print '</td>';
  707. }
  708. // End date
  709. if (!empty($arrayfields['p.datee']['checked'])) {
  710. print '<td class="liste_titre center nowraponall">';
  711. if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) {
  712. print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_eday" value="'.dol_escape_htmltag($search_eday).'">';
  713. }
  714. print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_emonth" value="'.dol_escape_htmltag($search_emonth).'">';
  715. $formother->select_year($search_eyear ? $search_eyear : -1, 'search_eyear', 1, 20, 5, 0, 0, '', 'widthauto valignmiddle');
  716. print '</td>';
  717. }
  718. if (!empty($arrayfields['p.public']['checked'])) {
  719. print '<td class="liste_titre">';
  720. $array = array(''=>'', 0 => $langs->trans("PrivateProject"), 1 => $langs->trans("SharedProject"));
  721. print $form->selectarray('search_public', $array, $search_public);
  722. print '</td>';
  723. }
  724. // Opp status
  725. if (!empty($arrayfields['p.fk_opp_status']['checked'])) {
  726. print '<td class="liste_titre nowrap center">';
  727. print $formproject->selectOpportunityStatus('search_opp_status', $search_opp_status, 1, 0, 1, 0, 'maxwidth100');
  728. print '</td>';
  729. }
  730. if (!empty($arrayfields['p.opp_amount']['checked'])) {
  731. print '<td class="liste_titre nowrap right">';
  732. print '<input type="text" class="flat" name="search_opp_amount" size="3" value="'.$search_opp_amount.'">';
  733. print '</td>';
  734. }
  735. if (!empty($arrayfields['p.opp_percent']['checked'])) {
  736. print '<td class="liste_titre nowrap right">';
  737. print '<input type="text" class="flat" name="search_opp_percent" size="2" value="'.$search_opp_percent.'">';
  738. print '</td>';
  739. }
  740. if (!empty($arrayfields['opp_weighted_amount']['checked'])) {
  741. print '<td class="liste_titre nowrap right">';
  742. print '</td>';
  743. }
  744. if (!empty($arrayfields['p.budget_amount']['checked'])) {
  745. print '<td class="liste_titre nowrap right">';
  746. print '<input type="text" class="flat" name="search_budget_amount" size="4" value="'.$search_budget_amount.'">';
  747. print '</td>';
  748. }
  749. if (!empty($arrayfields['p.usage_opportunity']['checked'])) {
  750. print '<td class="liste_titre nowrap right">';
  751. print $form->selectyesno('search_usage_opportunity', $search_usage_opportunity, 1, false, 1);
  752. print '';
  753. print '</td>';
  754. }
  755. if (!empty($arrayfields['p.usage_task']['checked'])) {
  756. print '<td class="liste_titre nowrap right">';
  757. print $form->selectyesno('search_usage_task', $search_usage_task, 1, false, 1);
  758. print '</td>';
  759. }
  760. if (!empty($arrayfields['p.usage_bill_time']['checked'])) {
  761. print '<td class="liste_titre nowrap right">';
  762. print $form->selectyesno('search_usage_bill_time', $search_usage_bill_time, 1, false, 1);
  763. print '</td>';
  764. }
  765. if (!empty($arrayfields['p.usage_organize_event']['checked'])) {
  766. print '<td class="liste_titre nowrap right">';
  767. print $form->selectyesno('search_usage_event_organization', $search_usage_event_organization, 1, false, 1);
  768. print '</td>';
  769. }
  770. if (!empty($arrayfields['p.accept_conference_suggestions']['checked'])) {
  771. print '<td class="liste_titre nowrap right">';
  772. print $form->selectyesno('search_accept_conference_suggestions', $search_accept_conference_suggestions, 1, false, 1);
  773. print '</td>';
  774. }
  775. if (!empty($arrayfields['p.accept_booth_suggestions']['checked'])) {
  776. print '<td class="liste_titre nowrap right">';
  777. print $form->selectyesno('search_accept_booth_suggestions', $search_accept_booth_suggestions, 1, false, 1);
  778. print '</td>';
  779. }
  780. if (!empty($arrayfields['p.price_registration']['checked'])) {
  781. print '<td class="liste_titre nowrap right">';
  782. print '<input type="text" class="flat" name="search_price_registration" size="4" value="'.$search_price_registration.'">';
  783. print '</td>';
  784. }
  785. if (!empty($arrayfields['p.price_booth']['checked'])) {
  786. print '<td class="liste_titre nowrap right">';
  787. print '<input type="text" class="flat" name="search_price_booth" size="4" value="'.$search_price_booth.'">';
  788. print '</td>';
  789. }
  790. // Extra fields
  791. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  792. // Fields from hook
  793. $parameters = array('arrayfields'=>$arrayfields);
  794. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  795. print $hookmanager->resPrint;
  796. if (!empty($arrayfields['p.datec']['checked'])) {
  797. // Date creation
  798. print '<td class="liste_titre">';
  799. print '</td>';
  800. }
  801. if (!empty($arrayfields['p.tms']['checked'])) {
  802. // Date modification
  803. print '<td class="liste_titre">';
  804. print '</td>';
  805. }
  806. if (!empty($arrayfields['p.email_msgid']['checked'])) {
  807. // Email msg id
  808. print '<td class="liste_titre">';
  809. print '</td>';
  810. }
  811. if (!empty($arrayfields['p.fk_statut']['checked'])) {
  812. print '<td class="liste_titre nowrap right">';
  813. $arrayofstatus = array();
  814. foreach ($object->statuts_short as $key => $val) {
  815. $arrayofstatus[$key] = $langs->trans($val);
  816. }
  817. $arrayofstatus['99'] = $langs->trans("NotClosed").' ('.$langs->trans('Draft').' + '.$langs->trans('Opened').')';
  818. print $form->selectarray('search_status', $arrayofstatus, $search_status, 1, 0, 0, '', 0, 0, 0, '', 'minwidth75imp maxwidth150 selectarrowonleft');
  819. print ajax_combobox('search_status');
  820. print '</td>';
  821. }
  822. // Action column
  823. print '<td class="liste_titre maxwidthsearch">';
  824. $searchpicto = $form->showFilterButtons();
  825. print $searchpicto;
  826. print '</td>';
  827. print '</tr>'."\n";
  828. print '<tr class="liste_titre">';
  829. if (!empty($arrayfields['p.ref']['checked'])) {
  830. print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, "", $sortfield, $sortorder);
  831. }
  832. if (!empty($arrayfields['p.title']['checked'])) {
  833. print_liste_field_titre($arrayfields['p.title']['label'], $_SERVER["PHP_SELF"], "p.title", "", $param, "", $sortfield, $sortorder);
  834. }
  835. if (!empty($arrayfields['s.nom']['checked'])) {
  836. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, "", $sortfield, $sortorder);
  837. }
  838. if (!empty($arrayfields['commercial']['checked'])) {
  839. print_liste_field_titre($arrayfields['commercial']['label'], $_SERVER["PHP_SELF"], "", "", $param, "", $sortfield, $sortorder, 'tdoverflowmax100imp ');
  840. }
  841. if (!empty($arrayfields['p.dateo']['checked'])) {
  842. print_liste_field_titre($arrayfields['p.dateo']['label'], $_SERVER["PHP_SELF"], "p.dateo", "", $param, '', $sortfield, $sortorder, 'center ');
  843. }
  844. if (!empty($arrayfields['p.datee']['checked'])) {
  845. print_liste_field_titre($arrayfields['p.datee']['label'], $_SERVER["PHP_SELF"], "p.datee", "", $param, '', $sortfield, $sortorder, 'center ');
  846. }
  847. if (!empty($arrayfields['p.public']['checked'])) {
  848. print_liste_field_titre($arrayfields['p.public']['label'], $_SERVER["PHP_SELF"], "p.public", "", $param, "", $sortfield, $sortorder);
  849. }
  850. if (!empty($arrayfields['p.fk_opp_status']['checked'])) {
  851. print_liste_field_titre($arrayfields['p.fk_opp_status']['label'], $_SERVER["PHP_SELF"], 'p.fk_opp_status', "", $param, '', $sortfield, $sortorder, 'center ');
  852. }
  853. if (!empty($arrayfields['p.opp_amount']['checked'])) {
  854. print_liste_field_titre($arrayfields['p.opp_amount']['label'], $_SERVER["PHP_SELF"], 'p.opp_amount', "", $param, '', $sortfield, $sortorder, 'right ');
  855. }
  856. if (!empty($arrayfields['p.opp_percent']['checked'])) {
  857. print_liste_field_titre($arrayfields['p.opp_percent']['label'], $_SERVER['PHP_SELF'], 'p.opp_percent', "", $param, '', $sortfield, $sortorder, 'right ');
  858. }
  859. if (!empty($arrayfields['opp_weighted_amount']['checked'])) {
  860. print_liste_field_titre($arrayfields['opp_weighted_amount']['label'], $_SERVER['PHP_SELF'], 'opp_weighted_amount', '', $param, '', $sortfield, $sortorder, 'right ');
  861. }
  862. if (!empty($arrayfields['p.budget_amount']['checked'])) {
  863. print_liste_field_titre($arrayfields['p.budget_amount']['label'], $_SERVER["PHP_SELF"], 'p.budget_amount', "", $param, '', $sortfield, $sortorder, 'right ');
  864. }
  865. if (!empty($arrayfields['p.usage_opportunity']['checked'])) {
  866. print_liste_field_titre($arrayfields['p.usage_opportunity']['label'], $_SERVER["PHP_SELF"], 'p.usage_opportunity', "", $param, '', $sortfield, $sortorder, 'right ');
  867. }
  868. if (!empty($arrayfields['p.usage_task']['checked'])) {
  869. print_liste_field_titre($arrayfields['p.usage_task']['label'], $_SERVER["PHP_SELF"], 'p.usage_task', "", $param, '', $sortfield, $sortorder, 'right ');
  870. }
  871. if (!empty($arrayfields['p.usage_bill_time']['checked'])) {
  872. print_liste_field_titre($arrayfields['p.usage_bill_time']['label'], $_SERVER["PHP_SELF"], 'p.usage_bill_time', "", $param, '', $sortfield, $sortorder, 'right ');
  873. }
  874. if (!empty($arrayfields['p.usage_organize_event']['checked'])) {
  875. print_liste_field_titre($arrayfields['p.usage_organize_event']['label'], $_SERVER["PHP_SELF"], 'p.usage_organize_event', "", $param, '', $sortfield, $sortorder, 'right ');
  876. }
  877. if (!empty($arrayfields['p.accept_conference_suggestions']['checked'])) {
  878. print_liste_field_titre($arrayfields['p.accept_conference_suggestions']['label'], $_SERVER["PHP_SELF"], 'p.accept_conference_suggestions', "", $param, '', $sortfield, $sortorder, 'right ');
  879. }
  880. if (!empty($arrayfields['p.accept_booth_suggestions']['checked'])) {
  881. print_liste_field_titre($arrayfields['p.accept_booth_suggestions']['label'], $_SERVER["PHP_SELF"], 'p.accept_booth_suggestions', "", $param, '', $sortfield, $sortorder, 'right ');
  882. }
  883. if (!empty($arrayfields['p.price_registration']['checked'])) {
  884. print_liste_field_titre($arrayfields['p.price_registration']['label'], $_SERVER["PHP_SELF"], 'p.price_registration', "", $param, '', $sortfield, $sortorder, 'right ');
  885. }
  886. if (!empty($arrayfields['p.price_booth']['checked'])) {
  887. print_liste_field_titre($arrayfields['p.price_booth']['label'], $_SERVER["PHP_SELF"], 'p.price_booth', "", $param, '', $sortfield, $sortorder, 'right ');
  888. }
  889. // Extra fields
  890. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  891. // Hook fields
  892. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  893. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  894. print $hookmanager->resPrint;
  895. if (!empty($arrayfields['p.datec']['checked'])) {
  896. print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  897. }
  898. if (!empty($arrayfields['p.tms']['checked'])) {
  899. print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  900. }
  901. if (!empty($arrayfields['p.email_msgid']['checked'])) {
  902. print_liste_field_titre($arrayfields['p.email_msgid']['label'], $_SERVER["PHP_SELF"], "p.email_msgid", "", $param, '', $sortfield, $sortorder, 'center ');
  903. }
  904. if (!empty($arrayfields['p.fk_statut']['checked'])) {
  905. print_liste_field_titre($arrayfields['p.fk_statut']['label'], $_SERVER["PHP_SELF"], "p.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
  906. }
  907. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  908. print "</tr>\n";
  909. $i = 0;
  910. $totalarray = array(
  911. 'nbfield' => 0,
  912. 'val' => array(),
  913. );
  914. while ($i < min($num, $limit)) {
  915. $obj = $db->fetch_object($resql);
  916. $object->id = $obj->id;
  917. $object->user_author_id = $obj->fk_user_creat;
  918. $object->public = $obj->public;
  919. $object->ref = $obj->ref;
  920. $object->datee = $db->jdate($obj->date_end);
  921. $object->statut = $obj->status; // deprecated
  922. $object->status = $obj->status;
  923. $object->public = $obj->public;
  924. $object->opp_status = $obj->fk_opp_status;
  925. $object->title = $obj->title;
  926. $userAccess = $object->restrictedProjectArea($user); // why this ?
  927. if ($userAccess >= 0) {
  928. $companystatic->id = $obj->socid;
  929. $companystatic->name = $obj->name;
  930. $companystatic->name_alias = $obj->alias;
  931. $companystatic->client = $obj->client;
  932. $companystatic->code_client = $obj->code_client;
  933. $companystatic->email = $obj->email;
  934. $companystatic->phone = $obj->phone;
  935. $companystatic->address = $obj->address;
  936. $companystatic->zip = $obj->zip;
  937. $companystatic->town = $obj->town;
  938. $companystatic->country_code = $obj->country_code;
  939. print '<tr class="oddeven">';
  940. // Project url
  941. if (!empty($arrayfields['p.ref']['checked'])) {
  942. print '<td class="nowraponall">';
  943. print $object->getNomUrl(1, (!empty(GETPOST('search_usage_event_organization', 'int'))?'eventorganization':''));
  944. if ($object->hasDelay()) {
  945. print img_warning($langs->trans('Late'));
  946. }
  947. print '</td>';
  948. if (!$i) {
  949. $totalarray['nbfield']++;
  950. }
  951. }
  952. // Title
  953. if (!empty($arrayfields['p.title']['checked'])) {
  954. print '<td class="tdoverflowmax200">';
  955. print dol_trunc($obj->title, 80);
  956. print '</td>';
  957. if (!$i) {
  958. $totalarray['nbfield']++;
  959. }
  960. }
  961. // Company
  962. if (!empty($arrayfields['s.nom']['checked'])) {
  963. print '<td class="tdoverflowmax100">';
  964. if ($obj->socid) {
  965. print $companystatic->getNomUrl(1);
  966. } else {
  967. print '&nbsp;';
  968. }
  969. print '</td>';
  970. if (!$i) {
  971. $totalarray['nbfield']++;
  972. }
  973. }
  974. // Sales Representatives
  975. if (!empty($arrayfields['commercial']['checked'])) {
  976. print '<td>';
  977. if ($obj->socid) {
  978. $companystatic->id = $obj->socid;
  979. $companystatic->name = $obj->name;
  980. $listsalesrepresentatives = $companystatic->getSalesRepresentatives($user);
  981. $nbofsalesrepresentative = count($listsalesrepresentatives);
  982. if ($nbofsalesrepresentative > 6) {
  983. // We print only number
  984. print $nbofsalesrepresentative;
  985. } elseif ($nbofsalesrepresentative > 0) {
  986. $userstatic = new User($db);
  987. $j = 0;
  988. foreach ($listsalesrepresentatives as $val) {
  989. $userstatic->id = $val['id'];
  990. $userstatic->lastname = $val['lastname'];
  991. $userstatic->firstname = $val['firstname'];
  992. $userstatic->email = $val['email'];
  993. $userstatic->statut = $val['statut'];
  994. $userstatic->entity = $val['entity'];
  995. $userstatic->photo = $val['photo'];
  996. $userstatic->login = $val['login'];
  997. $userstatic->office_phone = $val['office_phone'];
  998. $userstatic->office_fax = $val['office_fax'];
  999. $userstatic->user_mobile = $val['user_mobile'];
  1000. $userstatic->job = $val['job'];
  1001. $userstatic->gender = $val['gender'];
  1002. print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2);
  1003. $j++;
  1004. if ($j < $nbofsalesrepresentative) {
  1005. print ' ';
  1006. }
  1007. }
  1008. }
  1009. //else print $langs->trans("NoSalesRepresentativeAffected");
  1010. } else {
  1011. print '&nbsp;';
  1012. }
  1013. print '</td>';
  1014. if (!$i) {
  1015. $totalarray['nbfield']++;
  1016. }
  1017. }
  1018. // Date start
  1019. if (!empty($arrayfields['p.dateo']['checked'])) {
  1020. print '<td class="center">';
  1021. print dol_print_date($db->jdate($obj->date_start), 'day');
  1022. print '</td>';
  1023. if (!$i) {
  1024. $totalarray['nbfield']++;
  1025. }
  1026. }
  1027. // Date end
  1028. if (!empty($arrayfields['p.datee']['checked'])) {
  1029. print '<td class="center">';
  1030. print dol_print_date($db->jdate($obj->date_end), 'day');
  1031. print '</td>';
  1032. if (!$i) {
  1033. $totalarray['nbfield']++;
  1034. }
  1035. }
  1036. // Visibility
  1037. if (!empty($arrayfields['p.public']['checked'])) {
  1038. print '<td class="left">';
  1039. if ($obj->public) {
  1040. print $langs->trans('SharedProject');
  1041. } else {
  1042. print $langs->trans('PrivateProject');
  1043. }
  1044. print '</td>';
  1045. if (!$i) {
  1046. $totalarray['nbfield']++;
  1047. }
  1048. }
  1049. // Opp Status
  1050. if (!empty($arrayfields['p.fk_opp_status']['checked'])) {
  1051. print '<td class="center">';
  1052. if ($obj->opp_status_code) {
  1053. print $langs->trans("OppStatus".$obj->opp_status_code);
  1054. }
  1055. print '</td>';
  1056. if (!$i) {
  1057. $totalarray['nbfield']++;
  1058. }
  1059. }
  1060. // Opp Amount
  1061. if (!empty($arrayfields['p.opp_amount']['checked'])) {
  1062. print '<td class="right">';
  1063. //if ($obj->opp_status_code)
  1064. if (strcmp($obj->opp_amount, '')) {
  1065. print '<span class="amount">'.price($obj->opp_amount, 1, $langs, 1, -1, -1, '').'</span>';
  1066. $totalarray['val']['p.opp_amount'] += $obj->opp_amount;
  1067. }
  1068. print '</td>';
  1069. if (!$i) {
  1070. $totalarray['nbfield']++;
  1071. }
  1072. if (!$i) {
  1073. $totalarray['pos'][$totalarray['nbfield']] = 'p.opp_amount';
  1074. }
  1075. }
  1076. // Opp percent
  1077. if (!empty($arrayfields['p.opp_percent']['checked'])) {
  1078. print '<td class="right">';
  1079. if ($obj->opp_percent) {
  1080. print price($obj->opp_percent, 1, $langs, 1, 0).'%';
  1081. }
  1082. print '</td>';
  1083. if (!$i) {
  1084. $totalarray['nbfield']++;
  1085. }
  1086. }
  1087. // Opp weighted amount
  1088. if (!empty($arrayfields['opp_weighted_amount']['checked'])) {
  1089. if (!isset($totalarray['val']['opp_weighted_amount'])) {
  1090. $totalarray['val']['opp_weighted_amount'] = 0;
  1091. }
  1092. print '<td align="right">';
  1093. if ($obj->opp_weighted_amount) {
  1094. print '<span class="amount">'.price($obj->opp_weighted_amount, 1, $langs, 1, -1, -1, '').'</span>';
  1095. $totalarray['val']['opp_weighted_amount'] += $obj->opp_weighted_amount;
  1096. }
  1097. print '</td>';
  1098. if (!$i) {
  1099. $totalarray['nbfield']++;
  1100. }
  1101. if (!$i) {
  1102. $totalarray['pos'][$totalarray['nbfield']] = 'opp_weighted_amount';
  1103. }
  1104. }
  1105. // Budget
  1106. if (!empty($arrayfields['p.budget_amount']['checked'])) {
  1107. print '<td class="right">';
  1108. if ($obj->budget_amount != '') {
  1109. print '<span class="amount">'.price($obj->budget_amount, 1, $langs, 1, -1, -1).'</span>';
  1110. $totalarray['val']['p.budget_amount'] += $obj->budget_amount;
  1111. }
  1112. print '</td>';
  1113. if (!$i) {
  1114. $totalarray['nbfield']++;
  1115. }
  1116. if (!$i) {
  1117. $totalarray['pos'][$totalarray['nbfield']] = 'p.budget_amount';
  1118. }
  1119. }
  1120. // Usage opportunity
  1121. if (!empty($arrayfields['p.usage_opportunity']['checked'])) {
  1122. print '<td class="right">';
  1123. if ($obj->usage_opportunity) {
  1124. print yn($obj->usage_opportunity);
  1125. }
  1126. print '</td>';
  1127. if (!$i) {
  1128. $totalarray['nbfield']++;
  1129. }
  1130. }
  1131. // Usage task
  1132. if (!empty($arrayfields['p.usage_task']['checked'])) {
  1133. print '<td class="right">';
  1134. if ($obj->usage_task) {
  1135. print yn($obj->usage_task);
  1136. }
  1137. print '</td>';
  1138. if (!$i) {
  1139. $totalarray['nbfield']++;
  1140. }
  1141. }
  1142. // Bill time
  1143. if (!empty($arrayfields['p.usage_bill_time']['checked'])) {
  1144. print '<td class="right">';
  1145. if ($obj->usage_bill_time) {
  1146. print yn($obj->usage_bill_time);
  1147. }
  1148. print '</td>';
  1149. if (!$i) {
  1150. $totalarray['nbfield']++;
  1151. }
  1152. }
  1153. // Event Organization
  1154. if (!empty($arrayfields['p.usage_organize_event']['checked'])) {
  1155. print '<td class="right">';
  1156. if ($obj->usage_organize_event) {
  1157. print yn($obj->usage_organize_event);
  1158. }
  1159. print '</td>';
  1160. if (!$i) {
  1161. $totalarray['nbfield']++;
  1162. }
  1163. }
  1164. // Allow unknown people to suggest conferences
  1165. if (!empty($arrayfields['p.accept_conference_suggestions']['checked'])) {
  1166. print '<td class="right">';
  1167. if ($obj->accept_conference_suggestions) {
  1168. print yn($obj->accept_conference_suggestions);
  1169. }
  1170. print '</td>';
  1171. if (!$i) {
  1172. $totalarray['nbfield']++;
  1173. }
  1174. }
  1175. // Allow unknown people to suggest booth
  1176. if (!empty($arrayfields['p.accept_booth_suggestions']['checked'])) {
  1177. print '<td class="right">';
  1178. if ($obj->accept_booth_suggestions) {
  1179. print yn($obj->accept_booth_suggestions);
  1180. }
  1181. print '</td>';
  1182. if (!$i) {
  1183. $totalarray['nbfield']++;
  1184. }
  1185. }
  1186. // Price of registration
  1187. if (!empty($arrayfields['p.price_registration']['checked'])) {
  1188. print '<td class="right">';
  1189. if ($obj->price_registration != '') {
  1190. print '<span class="amount">'.price($obj->price_registration, 1, $langs, 1, -1, -1).'</span>';
  1191. $totalarray['val']['p.price_registration'] += $obj->price_registration;
  1192. }
  1193. print '</td>';
  1194. if (!$i) {
  1195. $totalarray['nbfield']++;
  1196. }
  1197. if (!$i) {
  1198. $totalarray['pos'][$totalarray['nbfield']] = 'p.price_registration';
  1199. }
  1200. }
  1201. // Price of booth
  1202. if (!empty($arrayfields['p.price_booth']['checked'])) {
  1203. print '<td class="right">';
  1204. if ($obj->price_booth != '') {
  1205. print '<span class="amount">'.price($obj->price_booth, 1, $langs, 1, -1, -1).'</span>';
  1206. $totalarray['val']['p.price_booth'] += $obj->price_booth;
  1207. }
  1208. print '</td>';
  1209. if (!$i) {
  1210. $totalarray['nbfield']++;
  1211. }
  1212. if (!$i) {
  1213. $totalarray['pos'][$totalarray['nbfield']] = 'p.price_booth';
  1214. }
  1215. }
  1216. // Extra fields
  1217. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1218. // Fields from hook
  1219. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1220. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  1221. print $hookmanager->resPrint;
  1222. // Date creation
  1223. if (!empty($arrayfields['p.datec']['checked'])) {
  1224. print '<td class="center nowraponall">';
  1225. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  1226. print '</td>';
  1227. if (!$i) {
  1228. $totalarray['nbfield']++;
  1229. }
  1230. }
  1231. // Date modification
  1232. if (!empty($arrayfields['p.tms']['checked'])) {
  1233. print '<td class="center nowraponall">';
  1234. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  1235. print '</td>';
  1236. if (!$i) {
  1237. $totalarray['nbfield']++;
  1238. }
  1239. }
  1240. // Email MsgID
  1241. if (!empty($arrayfields['p.email_msgid']['checked'])) {
  1242. print '<td class="center">';
  1243. print $obj->email_msgid;
  1244. print '</td>';
  1245. if (!$i) $totalarray['nbfield']++;
  1246. }
  1247. // Status
  1248. if (!empty($arrayfields['p.fk_statut']['checked'])) {
  1249. print '<td class="right">'.$object->getLibStatut(5).'</td>';
  1250. if (!$i) {
  1251. $totalarray['nbfield']++;
  1252. }
  1253. }
  1254. // Action column
  1255. print '<td class="nowrap center">';
  1256. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1257. $selected = 0;
  1258. if (in_array($obj->id, $arrayofselected)) {
  1259. $selected = 1;
  1260. }
  1261. print '<input id="cb'.$obj->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->id.'"'.($selected ? ' checked="checked"' : '').'>';
  1262. }
  1263. print '</td>';
  1264. if (!$i) {
  1265. $totalarray['nbfield']++;
  1266. }
  1267. print "</tr>\n";
  1268. }
  1269. $i++;
  1270. }
  1271. // Show total line
  1272. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  1273. $db->free($resql);
  1274. $parameters = array('sql' => $sql);
  1275. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
  1276. print $hookmanager->resPrint;
  1277. print "</table>\n";
  1278. print '</div>';
  1279. print "</form>\n";
  1280. // End of page
  1281. llxFooter();
  1282. $db->close();