list.php 61 KB

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