list.php 87 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137
  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. // Load Dolibarr environment
  31. require '../main.inc.php';
  32. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
  38. if (isModEnabled('categorie')) {
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcategory.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  41. }
  42. // Load translation files required by the page
  43. $langs->loadLangs(array('projects', 'companies', 'commercial'));
  44. if (isModEnabled('eventorganization') && $conf->eventorganization->enabled) {
  45. $langs->loadLangs(array('eventorganization'));
  46. }
  47. $action = GETPOST('action', 'aZ09');
  48. $massaction = GETPOST('massaction', 'alpha');
  49. $show_files = GETPOST('show_files', 'int');
  50. $confirm = GETPOST('confirm', 'alpha');
  51. $toselect = GETPOST('toselect', 'array');
  52. $optioncss = GETPOST('optioncss', 'alpha');
  53. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'projectlist';
  54. $mode = GETPOST('mode', 'alpha');
  55. $title = $langs->trans("Projects");
  56. // Security check
  57. $socid = GETPOST('socid', 'int');
  58. //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.
  59. if ($socid > 0) {
  60. $soc = new Societe($db);
  61. $soc->fetch($socid);
  62. $title .= ' (<a href="list.php">'.$soc->name.'</a>)';
  63. }
  64. if (!$user->hasRight('projet', 'lire')) {
  65. accessforbidden();
  66. }
  67. $diroutputmassaction = $conf->project->dir_output.'/temp/massgeneration/'.$user->id;
  68. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  69. $sortfield = GETPOST('sortfield', 'aZ09comma');
  70. $sortorder = GETPOST('sortorder', 'aZ09comma');
  71. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  72. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  73. // If $page is not defined, or '' or -1 or if we click on clear filters
  74. $page = 0;
  75. }
  76. if (!$sortfield) {
  77. $sortfield = "p.ref";
  78. }
  79. if (!$sortorder) {
  80. $sortorder = "ASC";
  81. }
  82. $offset = $limit * $page;
  83. $pageprev = $page - 1;
  84. $pagenext = $page + 1;
  85. $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
  86. $search_ref = GETPOST("search_ref", 'alpha');
  87. $search_label = GETPOST("search_label", 'alpha');
  88. $search_societe = GETPOST("search_societe", 'alpha');
  89. $search_societe_alias = GETPOST("search_societe_alias", 'alpha');
  90. $search_opp_status = GETPOST("search_opp_status", 'alpha');
  91. $search_opp_percent = GETPOST("search_opp_percent", 'alpha');
  92. $search_opp_amount = GETPOST("search_opp_amount", 'alpha');
  93. $search_budget_amount = GETPOST("search_budget_amount", 'alpha');
  94. $search_public = GETPOST("search_public", 'int');
  95. $search_project_user = GETPOST('search_project_user', getDolGlobalInt('PROJECT_SEARCH_USER_MULTIPLE') ?'array:int' :'int');
  96. $search_project_user_multiple_and = getDolGlobalInt('PROJECT_SEARCH_USER_MULTIPLE_AND');
  97. $search_project_contact = GETPOST('search_project_contact', getDolGlobalInt('PROJECT_SEARCH_CONTACT_MULTIPLE') ?'array:int' :'int');
  98. $search_project_contact_multiple_and = getDolGlobalInt('PROJECT_SEARCH_CONTACT_MULTIPLE_AND');
  99. $search_sale = GETPOST('search_sale', 'int');
  100. $search_usage_opportunity = GETPOST('search_usage_opportunity', 'int');
  101. $search_usage_task = GETPOST('search_usage_task', 'int');
  102. $search_usage_bill_time = GETPOST('search_usage_bill_time', 'int');
  103. $search_usage_event_organization = GETPOST('search_usage_event_organization', 'int');
  104. $search_accept_conference_suggestions = GETPOST('search_accept_conference_suggestions', 'int');
  105. $search_accept_booth_suggestions = GETPOST('search_accept_booth_suggestions', 'int');
  106. $search_price_registration = GETPOST("search_price_registration", 'alpha');
  107. $search_price_booth = GETPOST("search_price_booth", 'alpha');
  108. $search_login = GETPOST('search_login', 'alpha');
  109. $search_import_key = GETPOST('search_import_key', 'alpha');
  110. $searchCategoryCustomerOperator = 0;
  111. if (GETPOSTISSET('formfilteraction')) {
  112. $searchCategoryCustomerOperator = GETPOST('search_category_customer_operator', 'int');
  113. } elseif (getDolGlobalString('MAIN_SEARCH_CAT_OR_BY_DEFAULT')) {
  114. $searchCategoryCustomerOperator = $conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT;
  115. }
  116. $searchCategoryCustomerList = GETPOST('search_category_customer_list', 'array');
  117. if (getDolGlobalInt('PROJECT_ENABLE_SUB_PROJECT')) {
  118. $search_omitChildren = GETPOST('search_omitChildren', 'alpha') == 'on' ? 1 : 0;
  119. }
  120. $mine = ((GETPOST('mode') == 'mine') ? 1 : 0);
  121. if ($mine) {
  122. $search_project_user = $user->id;
  123. $mine = 0;
  124. }
  125. $search_sday = GETPOST('search_sday', 'int');
  126. $search_smonth = GETPOST('search_smonth', 'int');
  127. $search_syear = GETPOST('search_syear', 'int');
  128. $search_eday = GETPOST('search_eday', 'int');
  129. $search_emonth = GETPOST('search_emonth', 'int');
  130. $search_eyear = GETPOST('search_eyear', 'int');
  131. $search_date_start_startmonth = GETPOST('search_date_start_startmonth', 'int');
  132. $search_date_start_startyear = GETPOST('search_date_start_startyear', 'int');
  133. $search_date_start_startday = GETPOST('search_date_start_startday', 'int');
  134. $search_date_start_start = dol_mktime(0, 0, 0, $search_date_start_startmonth, $search_date_start_startday, $search_date_start_startyear); // Use tzserver
  135. $search_date_start_endmonth = GETPOST('search_date_start_endmonth', 'int');
  136. $search_date_start_endyear = GETPOST('search_date_start_endyear', 'int');
  137. $search_date_start_endday = GETPOST('search_date_start_endday', 'int');
  138. $search_date_start_end = dol_mktime(23, 59, 59, $search_date_start_endmonth, $search_date_start_endday, $search_date_start_endyear); // Use tzserver
  139. $search_date_end_startmonth = GETPOST('search_date_end_startmonth', 'int');
  140. $search_date_end_startyear = GETPOST('search_date_end_startyear', 'int');
  141. $search_date_end_startday = GETPOST('search_date_end_startday', 'int');
  142. $search_date_end_start = dol_mktime(0, 0, 0, $search_date_end_startmonth, $search_date_end_startday, $search_date_end_startyear); // Use tzserver
  143. $search_date_end_endmonth = GETPOST('search_date_end_endmonth', 'int');
  144. $search_date_end_endyear = GETPOST('search_date_end_endyear', 'int');
  145. $search_date_end_endday = GETPOST('search_date_end_endday', 'int');
  146. $search_date_end_end = dol_mktime(23, 59, 59, $search_date_end_endmonth, $search_date_end_endday, $search_date_end_endyear); // Use tzserver
  147. $search_date_creation_startmonth = GETPOST('search_date_creation_startmonth', 'int');
  148. $search_date_creation_startyear = GETPOST('search_date_creation_startyear', 'int');
  149. $search_date_creation_startday = GETPOST('search_date_creation_startday', 'int');
  150. $search_date_creation_start = dol_mktime(0, 0, 0, $search_date_creation_startmonth, $search_date_creation_startday, $search_date_creation_startyear); // Use tzserver
  151. $search_date_creation_endmonth = GETPOST('search_date_creation_endmonth', 'int');
  152. $search_date_creation_endyear = GETPOST('search_date_creation_endyear', 'int');
  153. $search_date_creation_endday = GETPOST('search_date_creation_endday', 'int');
  154. $search_date_creation_end = dol_mktime(23, 59, 59, $search_date_creation_endmonth, $search_date_creation_endday, $search_date_creation_endyear); // Use tzserver
  155. $search_date_modif_startmonth = GETPOST('search_date_modif_startmonth', 'int');
  156. $search_date_modif_startyear = GETPOST('search_date_modif_startyear', 'int');
  157. $search_date_modif_startday = GETPOST('search_date_modif_startday', 'int');
  158. $search_date_modif_start = dol_mktime(0, 0, 0, $search_date_modif_startmonth, $search_date_modif_startday, $search_date_modif_startyear); // Use tzserver
  159. $search_date_modif_endmonth = GETPOST('search_date_modif_endmonth', 'int');
  160. $search_date_modif_endyear = GETPOST('search_date_modif_endyear', 'int');
  161. $search_date_modif_endday = GETPOST('search_date_modif_endday', 'int');
  162. $search_date_modif_end = dol_mktime(23, 59, 59, $search_date_modif_endmonth, $search_date_modif_endday, $search_date_modif_endyear); // Use tzserver
  163. $search_category_array = array();
  164. if (isModEnabled('categorie')) {
  165. $search_category_array = GETPOST("search_category_".Categorie::TYPE_PROJECT."_list", "array");
  166. }
  167. if (GETPOSTISARRAY('search_status')) {
  168. $search_status = join(',', GETPOST('search_status', 'array:intcomma'));
  169. } else {
  170. $search_status = (GETPOST('search_status', 'intcomma') != '' ? GETPOST('search_status', 'intcomma') : '0,1');
  171. }
  172. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  173. $object = new Project($db);
  174. $hookmanager->initHooks(array('projectlist'));
  175. $extrafields = new ExtraFields($db);
  176. // fetch optionals attributes and labels
  177. $extrafields->fetch_name_optionals_label($object->table_element);
  178. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  179. // List of fields to search into when doing a "search in all"
  180. $fieldstosearchall = array();
  181. foreach ($object->fields as $key => $val) {
  182. if (empty($val['searchall'])) {
  183. continue;
  184. }
  185. // Don't allow search in private notes for external users when doing "search in all"
  186. if (!empty($user->socid) && $key == "note_private") {
  187. continue;
  188. }
  189. $fieldstosearchall['p.'.$key] = $val['label'];
  190. }
  191. // Add name object fields to "search in all"
  192. $fieldstosearchall['s.nom'] = "ThirdPartyName";
  193. $fieldstosearchall['s.name_alias'] = "AliasNameShort";
  194. $fieldstosearchall['s.code_client'] = "CustomerCode";
  195. // Definition of array of fields for columns
  196. $arrayfields = array();
  197. foreach ($object->fields as $key => $val) {
  198. // If $val['visible']==0, then we never show the field
  199. if (!empty($val['visible'])) {
  200. $visible = dol_eval($val['visible'], 1, 1, '1');
  201. $arrayfields['p.'.$key] = array(
  202. 'label'=>$val['label'],
  203. 'checked'=>(($visible < 0) ? 0 : 1),
  204. 'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1, 1, '1')),
  205. 'position'=>$val['position'],
  206. 'help'=> isset($val['help']) ? $val['help'] : ''
  207. );
  208. }
  209. }
  210. // Extra fields
  211. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  212. // Add non object fields to fields for list
  213. $arrayfields['s.nom'] = array('label'=>$langs->trans("ThirdParty"), 'checked'=>1, 'position'=>21, 'enabled'=>(!isModEnabled('societe') ? 0 : 1));
  214. $arrayfields['s.name_alias'] = array('label'=>"AliasNameShort", 'checked'=>0, 'position'=>22);
  215. $arrayfields['commercial'] = array('label'=>$langs->trans("SaleRepresentativesOfThirdParty"), 'checked'=>0, 'position'=>23);
  216. $arrayfields['c.assigned'] = array('label'=>$langs->trans("AssignedTo"), 'checked'=>1, 'position'=>120);
  217. $arrayfields['opp_weighted_amount'] = array('label'=>$langs->trans('OpportunityWeightedAmountShort'), 'checked'=>0, 'enabled'=>(!getDolGlobalString('PROJECT_USE_OPPORTUNITIES') ? 0 : 1), 'position'=>106);
  218. $arrayfields['u.login'] = array('label'=>"Author", 'checked'=>-1, 'position'=>165);
  219. // Force some fields according to search_usage filter...
  220. if (GETPOST('search_usage_opportunity')) {
  221. //$arrayfields['p.usage_opportunity']['visible'] = 1; // Not require, filter on search_opp_status is enough
  222. //$arrayfields['p.usage_opportunity']['checked'] = 1; // Not require, filter on search_opp_status is enough
  223. }
  224. if (GETPOST('search_usage_event_organization')) {
  225. $arrayfields['p.fk_opp_status']['enabled'] = 0;
  226. $arrayfields['p.opp_amount']['enabled'] = 0;
  227. $arrayfields['p.opp_percent']['enabled'] = 0;
  228. $arrayfields['opp_weighted_amount']['enabled'] = 0;
  229. $arrayfields['p.usage_organize_event']['visible'] = 1;
  230. $arrayfields['p.usage_organize_event']['checked'] = 1;
  231. }
  232. $object->fields = dol_sort_array($object->fields, 'position');
  233. $arrayfields = dol_sort_array($arrayfields, 'position');
  234. /*
  235. * Actions
  236. */
  237. if (GETPOST('cancel', 'alpha')) {
  238. $action = 'list';
  239. $massaction = '';
  240. }
  241. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  242. $massaction = '';
  243. }
  244. $parameters = array('socid'=>$socid);
  245. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  246. if ($reshook < 0) {
  247. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  248. }
  249. if (empty($reshook)) {
  250. // Selection of new fields
  251. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  252. // Purge search criteria
  253. 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
  254. $search_all = '';
  255. $search_ref = "";
  256. $search_label = "";
  257. $search_societe = "";
  258. $search_societe_alias = '';
  259. $search_status = -1;
  260. $search_opp_status = -1;
  261. $search_opp_amount = '';
  262. $search_opp_percent = '';
  263. $search_budget_amount = '';
  264. $search_public = "";
  265. $search_sale = "";
  266. $search_project_user = '';
  267. $search_project_contact = '';
  268. $search_sday = "";
  269. $search_smonth = "";
  270. $search_syear = "";
  271. $search_eday = "";
  272. $search_emonth = "";
  273. $search_eyear = "";
  274. $search_date_start_startmonth = "";
  275. $search_date_start_startyear = "";
  276. $search_date_start_startday = "";
  277. $search_date_start_start = "";
  278. $search_date_start_endmonth = "";
  279. $search_date_start_endyear = "";
  280. $search_date_start_endday = "";
  281. $search_date_start_end = "";
  282. $search_date_end_startmonth = "";
  283. $search_date_end_startyear = "";
  284. $search_date_end_startday = "";
  285. $search_date_end_start = "";
  286. $search_date_end_endmonth = "";
  287. $search_date_end_endyear = "";
  288. $search_date_end_endday = "";
  289. $search_date_end_end = "";
  290. $search_date_creation_startmonth = "";
  291. $search_date_creation_startyear = "";
  292. $search_date_creation_startday = "";
  293. $search_date_creation_start = "";
  294. $search_date_creation_endmonth = "";
  295. $search_date_creation_endyear = "";
  296. $search_date_creation_endday = "";
  297. $search_date_creation_end = "";
  298. $search_date_modif_startmonth = "";
  299. $search_date_modif_startyear = "";
  300. $search_date_modif_startday = "";
  301. $search_date_modif_start = "";
  302. $search_date_modif_endmonth = "";
  303. $search_date_modif_endyear = "";
  304. $search_date_modif_endday = "";
  305. $search_date_modif_end = "";
  306. $search_usage_opportunity = '';
  307. $search_usage_task = '';
  308. $search_usage_bill_time = '';
  309. $search_usage_event_organization = '';
  310. $search_accept_conference_suggestions = '';
  311. $search_accept_booth_suggestions = '';
  312. $search_price_registration = '';
  313. $search_price_booth = '';
  314. $search_login = '';
  315. $search_import_key = '';
  316. $toselect = array();
  317. $search_array_options = array();
  318. $search_category_array = array();
  319. }
  320. // Mass actions
  321. $objectclass = 'Project';
  322. $objectlabel = 'Project';
  323. $permissiontoread = $user->hasRight('projet', 'lire');
  324. $permissiontodelete = $user->hasRight('projet', 'supprimer');
  325. $permissiontoadd = $user->hasRight('projet', 'creer');
  326. $uploaddir = $conf->project->dir_output;
  327. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  328. // Close records
  329. if (!$error && $massaction == 'close' && $user->hasRight('projet', 'creer')) {
  330. $db->begin();
  331. $objecttmp = new $objectclass($db);
  332. $nbok = 0;
  333. foreach ($toselect as $toselectid) {
  334. $result = $objecttmp->fetch($toselectid);
  335. if ($result > 0) {
  336. $userWrite = $object->restrictedProjectArea($user, 'write');
  337. if ($userWrite > 0 && $objecttmp->statut == 1) {
  338. $result = $objecttmp->setClose($user);
  339. if ($result <= 0) {
  340. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  341. $error++;
  342. break;
  343. } else {
  344. $nbok++;
  345. }
  346. } elseif ($userWrite <= 0) {
  347. setEventMessages($langs->trans("DontHavePermissionForCloseProject", $objecttmp->ref), null, 'warnings');
  348. } else {
  349. setEventMessages($langs->trans("DontHaveTheValidateStatus", $objecttmp->ref), null, 'warnings');
  350. }
  351. } else {
  352. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  353. $error++;
  354. break;
  355. }
  356. }
  357. if (!$error) {
  358. if ($nbok > 1) {
  359. setEventMessages($langs->trans("RecordsClosed", $nbok), null, 'mesgs');
  360. } else {
  361. setEventMessages($langs->trans("RecordsClosed", $nbok), null, 'mesgs');
  362. }
  363. $db->commit();
  364. } else {
  365. $db->rollback();
  366. }
  367. }
  368. }
  369. /*
  370. * View
  371. */
  372. unset($_SESSION['pageforbacktolist']['project']);
  373. $form = new Form($db);
  374. $formcompany = new FormCompany($db);
  375. $now = dol_now();
  376. $companystatic = new Societe($db);
  377. $taskstatic = new Task($db);
  378. $formother = new FormOther($db);
  379. $formproject = new FormProjets($db);
  380. $userstatic = new User($db);
  381. $help_url = "EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
  382. $title = $langs->trans("LeadsOrProjects");
  383. if (!getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
  384. $title = $langs->trans("Projects");
  385. }
  386. if (getDolGlobalInt('PROJECT_USE_OPPORTUNITIES') == 2) { // 2 = leads only
  387. $title = $langs->trans("Leads");
  388. }
  389. $morejs = array();
  390. $morecss = array();
  391. // Get list of project id allowed to user (in a string list separated by comma)
  392. $projectsListId = '';
  393. if (!$user->hasRight('projet', 'all', 'lire')) {
  394. $projectsListId = $object->getProjectsAuthorizedForUser($user, 0, 1, $socid);
  395. }
  396. // Get id of types of contacts for projects (This list never contains a lot of elements)
  397. $listofprojectcontacttype = array();
  398. $listofprojectcontacttypeexternal = array();
  399. $sql = "SELECT ctc.rowid, ctc.code, ctc.source FROM ".MAIN_DB_PREFIX."c_type_contact as ctc";
  400. $sql .= " WHERE ctc.element = '".$db->escape($object->element)."'";
  401. $resql = $db->query($sql);
  402. if ($resql) {
  403. while ($obj = $db->fetch_object($resql)) {
  404. if ($obj->source == 'internal') {
  405. $listofprojectcontacttype[$obj->rowid] = $obj->code;
  406. } else {
  407. $listofprojectcontacttypeexternal[$obj->rowid] = $obj->code;
  408. }
  409. }
  410. } else {
  411. dol_print_error($db);
  412. }
  413. if (count($listofprojectcontacttype) == 0) {
  414. $listofprojectcontacttype[0] = '0'; // To avoid sql syntax error if not found
  415. }
  416. if (count($listofprojectcontacttypeexternal) == 0) {
  417. $listofprojectcontacttypeexternal[0] = '0'; // To avoid sql syntax error if not found
  418. }
  419. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  420. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  421. $distinct = 'DISTINCT'; // We add distinct until filter on contact of project or task is implemented with AND EXISTS
  422. $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,";
  423. $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,";
  424. $sql .= " p.usage_opportunity, p.usage_task, p.usage_bill_time, p.usage_organize_event,";
  425. $sql .= " p.email_msgid, p.import_key,";
  426. $sql .= " p.accept_conference_suggestions, p.accept_booth_suggestions, p.price_registration, p.price_booth,";
  427. $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,";
  428. $sql .= " country.code as country_code,";
  429. $sql .= " cls.code as opp_status_code,";
  430. $sql .= ' u.login, u.lastname, u.firstname, u.email as user_email, u.statut as user_statut, u.entity, u.photo, u.office_phone, u.office_fax, u.user_mobile, u.job, u.gender';
  431. // Add fields from extrafields
  432. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  433. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  434. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  435. }
  436. }
  437. // Add fields from hooks
  438. $parameters = array();
  439. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  440. $sql .= $hookmanager->resPrint;
  441. $sql = preg_replace('/,\s*$/', '', $sql);
  442. $sqlfields = $sql; // $sql fields to remove for count total
  443. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as p";
  444. if (!empty($extrafields->attributes[$object->table_element]['label']) &&is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  445. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (p.rowid = ef.fk_object)";
  446. }
  447. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
  448. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  449. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_lead_status as cls on p.fk_opp_status = cls.rowid";
  450. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user AS u ON p.fk_user_creat = u.rowid';
  451. // We'll need this table joined to the select in order to filter by sale
  452. // No check is done on company permission because readability is managed by public status of project and assignement.
  453. //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";
  454. if ($search_sale > 0) {
  455. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = s.rowid";
  456. }
  457. if (!empty($search_project_user)) {
  458. if (is_array($search_project_user)) {
  459. if ($search_project_user_multiple_and) {
  460. for ($i=0; $i<count($search_project_user); $i++)
  461. $sql .= ", ".MAIN_DB_PREFIX."element_contact as ecp$i";
  462. }
  463. else {
  464. $sql .= ", ".MAIN_DB_PREFIX."element_contact as ecp";
  465. }
  466. }
  467. elseif($search_project_user > 0) {
  468. $sql .= ", ".MAIN_DB_PREFIX."element_contact as ecp";
  469. }
  470. }
  471. if (!empty($search_project_contact)) {
  472. if (is_array($search_project_contact)) {
  473. if ($search_project_contact_multiple_and) {
  474. for ($i=0; $i<count($search_project_contact); $i++)
  475. $sql .= ", ".MAIN_DB_PREFIX."element_contact as ecp_contact$i";
  476. }
  477. else {
  478. $sql .= ", ".MAIN_DB_PREFIX."element_contact as ecp_contact";
  479. }
  480. }
  481. elseif($search_project_contact > 0) {
  482. $sql .= ", ".MAIN_DB_PREFIX."element_contact as ecp_contact";
  483. }
  484. }
  485. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  486. $sql .= $hookmanager->resPrint;
  487. $sql .= " WHERE p.entity IN (".getEntity('project', (GETPOST('search_current_entity', 'int') ? 0 : 1)).')';
  488. if (!$user->hasRight('projet', 'all', 'lire')) {
  489. $sql .= " AND p.rowid IN (".$db->sanitize($projectsListId).")"; // public and assigned to, or restricted to company for external users
  490. }
  491. // No need to check if company is external user, as filtering of projects must be done by getProjectsAuthorizedForUser
  492. if ($socid > 0) {
  493. $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)
  494. }
  495. if ($search_ref) {
  496. $sql .= natural_search('p.ref', $search_ref);
  497. }
  498. if ($search_label) {
  499. $sql .= natural_search('p.title', $search_label);
  500. }
  501. if (empty($arrayfields['s.name_alias']['checked']) && $search_societe) {
  502. $sql .= natural_search(array("s.nom", "s.name_alias"), $search_societe);
  503. } else {
  504. if ($search_societe) {
  505. $sql .= natural_search('s.nom', $search_societe);
  506. }
  507. if ($search_societe_alias) {
  508. $sql .= natural_search('s.name_alias', $search_societe_alias);
  509. }
  510. }
  511. if ($search_opp_amount) {
  512. $sql .= natural_search('p.opp_amount', $search_opp_amount, 1);
  513. }
  514. if ($search_opp_percent) {
  515. $sql .= natural_search('p.opp_percent', $search_opp_percent, 1);
  516. }
  517. $sql .= dolSqlDateFilter('p.dateo', $search_sday, $search_smonth, $search_syear);
  518. $sql .= dolSqlDateFilter('p.datee', $search_eday, $search_emonth, $search_eyear);
  519. if ($search_date_start_start) {
  520. $sql .= " AND p.dateo >= '".$db->idate($search_date_start_start)."'";
  521. }
  522. if ($search_date_start_end) {
  523. $sql .= " AND p.dateo <= '".$db->idate($search_date_start_end)."'";
  524. }
  525. if ($search_date_end_start) {
  526. $sql .= " AND p.datee >= '".$db->idate($search_date_end_start)."'";
  527. }
  528. if ($search_date_end_end) {
  529. $sql .= " AND p.datee <= '".$db->idate($search_date_end_end)."'";
  530. }
  531. if ($search_date_creation_start) {
  532. $sql .= " AND p.datec >= '".$db->idate($search_date_creation_start)."'";
  533. }
  534. if ($search_date_creation_end) {
  535. $sql .= " AND p.datec <= '".$db->idate($search_date_creation_end)."'";
  536. }
  537. if ($search_date_modif_start) {
  538. $sql .= " AND p.tms >= '".$db->idate($search_date_modif_start)."'";
  539. }
  540. if ($search_date_modif_end) {
  541. $sql .= " AND p.tms <= '".$db->idate($search_date_modif_end)."'";
  542. }
  543. if ($search_all) {
  544. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  545. }
  546. if ($search_status != '' && $search_status != '-1') {
  547. if ($search_status == 99) {
  548. $sql .= " AND p.fk_statut IN (0,1)";
  549. } else {
  550. $sql .= " AND p.fk_statut IN (".$db->sanitize($db->escape($search_status)).")";
  551. }
  552. }
  553. if ($search_opp_status) {
  554. if (is_numeric($search_opp_status) && $search_opp_status > 0) {
  555. $sql .= " AND p.fk_opp_status = ".((int) $search_opp_status);
  556. }
  557. if ($search_opp_status == 'all') {
  558. $sql .= " AND (p.fk_opp_status IS NOT NULL AND p.fk_opp_status <> -1)";
  559. }
  560. if ($search_opp_status == 'openedopp') {
  561. $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'))";
  562. }
  563. if ($search_opp_status == 'notopenedopp') {
  564. $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'))";
  565. }
  566. if ($search_opp_status == 'none') {
  567. $sql .= " AND (p.fk_opp_status IS NULL OR p.fk_opp_status = -1)";
  568. }
  569. }
  570. if ($search_public != '') {
  571. $sql .= " AND p.public = ".((int) $search_public);
  572. }
  573. // For external user, no check is done on company permission because readability is managed by public status of project and assignement.
  574. //if ($socid > 0) $sql.= " AND s.rowid = ".((int) $socid);
  575. if ($search_sale > 0) {
  576. $sql .= " AND sc.fk_user = ".((int) $search_sale);
  577. }
  578. // No check is done on company permission because readability is managed by public status of project and assignement.
  579. //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))";
  580. if (!empty($search_project_user)) {
  581. if (is_array($search_project_user)) {
  582. if ($search_project_user_multiple_and) {
  583. foreach($search_project_user as $i=>$uid) {
  584. $sql .= " AND ecp$i.fk_c_type_contact IN (".$db->sanitize(join(',', array_keys($listofprojectcontacttype))).") AND ecp$i.element_id = p.rowid AND ecp$i.fk_socpeople = ".((int) $uid);
  585. }
  586. }
  587. else {
  588. $sql .= " AND ecp.fk_c_type_contact IN (".$db->sanitize(join(',', array_keys($listofprojectcontacttype))).") AND ecp.element_id = p.rowid AND ecp.fk_socpeople IN (".implode(',', $search_project_user).")";
  589. }
  590. }
  591. elseif ($search_project_user > 0) {
  592. // TODO Replace this with a EXISTS and remove the link to table + DISTINCT
  593. $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);
  594. }
  595. }
  596. if (!empty($search_project_contact)) {
  597. if (is_array($search_project_contact)) {
  598. if ($search_project_contact_multiple_and) {
  599. foreach($search_project_contact as $i=>$uid) {
  600. $sql .= " AND ecp_contact$i.fk_c_type_contact IN (".$db->sanitize(join(',', array_keys($listofprojectcontacttypeexternal))).") AND ecp_contact$i.element_id = p.rowid AND ecp_contact$i.fk_socpeople = ".((int) $uid);
  601. }
  602. }
  603. else {
  604. $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 IN (".implode(',', $search_project_contact).")";
  605. }
  606. }
  607. elseif ($search_project_contact > 0) {
  608. // TODO Replace this with a EXISTS and remove the link to table + DISTINCT
  609. $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);
  610. }
  611. }
  612. if ($search_opp_amount != '') {
  613. $sql .= natural_search('p.opp_amount', $search_opp_amount, 1);
  614. }
  615. if ($search_budget_amount != '') {
  616. $sql .= natural_search('p.budget_amount', $search_budget_amount, 1);
  617. }
  618. if ($search_usage_opportunity != '' && $search_usage_opportunity >= 0) {
  619. $sql .= natural_search('p.usage_opportunity', $search_usage_opportunity, 2);
  620. }
  621. if ($search_usage_task != '' && $search_usage_task >= 0) {
  622. $sql .= natural_search('p.usage_task', $search_usage_task, 2);
  623. }
  624. if ($search_usage_bill_time != '' && $search_usage_bill_time >= 0) {
  625. $sql .= natural_search('p.usage_bill_time', $search_usage_bill_time, 2);
  626. }
  627. if ($search_usage_event_organization != '' && $search_usage_event_organization >= 0) {
  628. $sql .= natural_search('p.usage_organize_event', $search_usage_event_organization, 2);
  629. }
  630. if ($search_accept_conference_suggestions != '' && $search_accept_conference_suggestions >= 0) {
  631. $sql .= natural_search('p.accept_conference_suggestions', $search_accept_conference_suggestions, 2);
  632. }
  633. if ($search_accept_booth_suggestions != '' && $search_accept_booth_suggestions >= 0) {
  634. $sql .= natural_search('p.accept_booth_suggestions', $search_accept_booth_suggestions, 2);
  635. }
  636. if ($search_price_registration != '') {
  637. $sql .= natural_search('p.price_registration', $search_price_registration, 1);
  638. }
  639. if ($search_price_booth != '') {
  640. $sql .= natural_search('p.price_booth', $search_price_booth, 1);
  641. }
  642. if ($search_login) {
  643. $sql .= natural_search(array('u.login', 'u.firstname', 'u.lastname'), $search_login);
  644. }
  645. if ($search_import_key) {
  646. $sql .= natural_search(array('p.import_key'), $search_import_key);
  647. }
  648. if (getDolGlobalInt('PROJECT_ENABLE_SUB_PROJECT')) {
  649. if ($search_omitChildren == 1) {
  650. $sql .= " AND p.fk_project IS NULL";
  651. }
  652. }
  653. // Search for tag/category ($searchCategoryProjectList is an array of ID)
  654. $searchCategoryProjectList = $search_category_array;
  655. $searchCategoryProjectOperator = 0;
  656. if (!empty($searchCategoryProjectList)) {
  657. $searchCategoryProjectSqlList = array();
  658. $listofcategoryid = '';
  659. foreach ($searchCategoryProjectList as $searchCategoryProject) {
  660. if (intval($searchCategoryProject) == -2) {
  661. $searchCategoryProjectSqlList[] = "NOT EXISTS (SELECT ck.fk_project FROM ".MAIN_DB_PREFIX."categorie_project as ck WHERE p.rowid = ck.fk_project)";
  662. } elseif (intval($searchCategoryProject) > 0) {
  663. if ($searchCategoryProjectOperator == 0) {
  664. $searchCategoryProjectSqlList[] = " EXISTS (SELECT ck.fk_project FROM ".MAIN_DB_PREFIX."categorie_project as ck WHERE p.rowid = ck.fk_project AND ck.fk_categorie = ".((int) $searchCategoryProject).")";
  665. } else {
  666. $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProject);
  667. }
  668. }
  669. }
  670. if ($listofcategoryid) {
  671. $searchCategoryProjectSqlList[] = " EXISTS (SELECT ck.fk_project FROM ".MAIN_DB_PREFIX."categorie_project as ck WHERE p.rowid = ck.fk_project AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
  672. }
  673. if ($searchCategoryProjectOperator == 1) {
  674. if (!empty($searchCategoryProjectSqlList)) {
  675. $sql .= " AND (".implode(' OR ', $searchCategoryProjectSqlList).")";
  676. }
  677. } else {
  678. if (!empty($searchCategoryProjectSqlList)) {
  679. $sql .= " AND (".implode(' AND ', $searchCategoryProjectSqlList).")";
  680. }
  681. }
  682. }
  683. $searchCategoryCustomerSqlList = array();
  684. if ($searchCategoryCustomerOperator == 1) {
  685. $existsCategoryCustomerList = array();
  686. foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
  687. if (intval($searchCategoryCustomer) == -2) {
  688. $sqlCategoryCustomerNotExists = " NOT EXISTS (";
  689. $sqlCategoryCustomerNotExists .= " SELECT cat_cus.fk_soc";
  690. $sqlCategoryCustomerNotExists .= " FROM ".$db->prefix()."categorie_societe AS cat_cus";
  691. $sqlCategoryCustomerNotExists .= " WHERE cat_cus.fk_soc = p.fk_soc";
  692. $sqlCategoryCustomerNotExists .= " )";
  693. $searchCategoryCustomerSqlList[] = $sqlCategoryCustomerNotExists;
  694. } elseif (intval($searchCategoryCustomer) > 0) {
  695. $existsCategoryCustomerList[] = $db->escape($searchCategoryCustomer);
  696. }
  697. }
  698. if (!empty($existsCategoryCustomerList)) {
  699. $sqlCategoryCustomerExists = " EXISTS (";
  700. $sqlCategoryCustomerExists .= " SELECT cat_cus.fk_soc";
  701. $sqlCategoryCustomerExists .= " FROM ".$db->prefix()."categorie_societe AS cat_cus";
  702. $sqlCategoryCustomerExists .= " WHERE cat_cus.fk_soc = p.fk_soc";
  703. $sqlCategoryCustomerExists .= " AND cat_cus.fk_categorie IN (".$db->sanitize(implode(',', $existsCategoryCustomerList)).")";
  704. $sqlCategoryCustomerExists .= " )";
  705. $searchCategoryCustomerSqlList[] = $sqlCategoryCustomerExists;
  706. }
  707. if (!empty($searchCategoryCustomerSqlList)) {
  708. $sql .= " AND (".implode(' OR ', $searchCategoryCustomerSqlList).")";
  709. }
  710. } else {
  711. foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
  712. if (intval($searchCategoryCustomer) == -2) {
  713. $sqlCategoryCustomerNotExists = " NOT EXISTS (";
  714. $sqlCategoryCustomerNotExists .= " SELECT cat_cus.fk_soc";
  715. $sqlCategoryCustomerNotExists .= " FROM ".$db->prefix()."categorie_societe AS cat_cus";
  716. $sqlCategoryCustomerNotExists .= " WHERE cat_cus.fk_soc = p.fk_soc";
  717. $sqlCategoryCustomerNotExists .= " )";
  718. $searchCategoryCustomerSqlList[] = $sqlCategoryCustomerNotExists;
  719. } elseif (intval($searchCategoryCustomer) > 0) {
  720. $searchCategoryCustomerSqlList[] = "p.fk_soc IN (SELECT fk_soc FROM ".$db->prefix()."categorie_societe WHERE fk_categorie = ".((int) $searchCategoryCustomer).")";
  721. }
  722. }
  723. if (!empty($searchCategoryCustomerSqlList)) {
  724. $sql .= " AND (".implode(' AND ', $searchCategoryCustomerSqlList).")";
  725. }
  726. }
  727. // Add where from extra fields
  728. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  729. // Add where from hooks
  730. $parameters = array();
  731. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  732. $sql .= $hookmanager->resPrint;
  733. //print $sql;
  734. // Count total nb of records
  735. $nbtotalofrecords = '';
  736. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  737. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  738. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  739. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  740. $resql = $db->query($sqlforcount);
  741. if ($resql) {
  742. $objforcount = $db->fetch_object($resql);
  743. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  744. } else {
  745. dol_print_error($db);
  746. }
  747. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  748. $page = 0;
  749. $offset = 0;
  750. }
  751. $db->free($resql);
  752. }
  753. // Complete request and execute it with limit
  754. $sql .= $db->order($sortfield, $sortorder);
  755. if ($limit) {
  756. $sql .= $db->plimit($limit + 1, $offset);
  757. }
  758. //echo '<pre>'.$sql.'</pre>'; die();
  759. $resql = $db->query($sql);
  760. if (!$resql) {
  761. dol_print_error($db);
  762. exit;
  763. }
  764. $num = $db->num_rows($resql);
  765. // Direct jump if only one record found
  766. if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
  767. $obj = $db->fetch_object($resql);
  768. header("Location: ".DOL_URL_ROOT.'/projet/card.php?id='.$obj->id);
  769. exit;
  770. }
  771. // Output page
  772. // --------------------------------------------------------------------
  773. llxHeader('', $title, $help_url);
  774. $arrayofselected = is_array($toselect) ? $toselect : array();
  775. $param = '';
  776. if (!empty($mode)) {
  777. $param .= '&mode='.urlencode($mode);
  778. }
  779. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  780. $param .= '&contextpage='.urlencode($contextpage);
  781. }
  782. if ($limit > 0 && $limit != $conf->liste_limit) {
  783. $param .= '&limit='.((int) $limit);
  784. }
  785. if ($optioncss != '') {
  786. $param .= '&optioncss='.urlencode($optioncss);
  787. }
  788. if ($socid) {
  789. $param .= '&socid='.urlencode($socid);
  790. }
  791. if ($search_all != '') {
  792. $param .= '&search_all='.urlencode($search_all);
  793. }
  794. if ($search_sday) {
  795. $param .= '&search_sday='.urlencode($search_sday);
  796. }
  797. if ($search_smonth) {
  798. $param .= '&search_smonth='.urlencode($search_smonth);
  799. }
  800. if ($search_syear) {
  801. $param .= '&search_syear='.urlencode($search_syear);
  802. }
  803. if ($search_eday) {
  804. $param .= '&search_eday='.urlencode($search_eday);
  805. }
  806. if ($search_emonth) {
  807. $param .= '&search_emonth='.urlencode($search_emonth);
  808. }
  809. if ($search_eyear) {
  810. $param .= '&search_eyear='.urlencode($search_eyear);
  811. }
  812. if ($search_date_start_startmonth) {
  813. $param .= '&search_date_start_startmonth='.urlencode($search_date_start_startmonth);
  814. }
  815. if ($search_date_start_startyear) {
  816. $param .= '&search_date_start_startyear='.urlencode($search_date_start_startyear);
  817. }
  818. if ($search_date_start_startday) {
  819. $param .= '&search_date_start_startday='.urlencode($search_date_start_startday);
  820. }
  821. if ($search_date_start_start) {
  822. $param .= '&search_date_start_start='.urlencode($search_date_start_start);
  823. }
  824. if ($search_date_start_endmonth) {
  825. $param .= '&search_date_start_endmonth='.urlencode($search_date_start_endmonth);
  826. }
  827. if ($search_date_start_endyear) {
  828. $param .= '&search_date_start_endyear='.urlencode($search_date_start_endyear);
  829. }
  830. if ($search_date_start_endday) {
  831. $param .= '&search_date_start_endday='.urlencode($search_date_start_endday);
  832. }
  833. if ($search_date_start_end) {
  834. $param .= '&search_date_start_end='.urlencode($search_date_start_end);
  835. }
  836. if ($search_date_end_startmonth) {
  837. $param .= '&search_date_end_startmonth='.urlencode($search_date_end_startmonth);
  838. }
  839. if ($search_date_end_startyear) {
  840. $param .= '&search_date_end_startyear='.urlencode($search_date_end_startyear);
  841. }
  842. if ($search_date_end_startday) {
  843. $param .= '&search_date_end_startday='.urlencode($search_date_end_startday);
  844. }
  845. if ($search_date_end_start) {
  846. $param .= '&search_date_end_start='.urlencode($search_date_end_start);
  847. }
  848. if ($search_date_end_endmonth) {
  849. $param .= '&search_date_end_endmonth='.urlencode($search_date_end_endmonth);
  850. }
  851. if ($search_date_end_endyear) {
  852. $param .= '&search_date_end_endyear='.urlencode($search_date_end_endyear);
  853. }
  854. if ($search_date_end_endday) {
  855. $param .= '&search_date_end_endday='.urlencode($search_date_end_endday);
  856. }
  857. if ($search_date_end_end) {
  858. $param .= '&search_date_end_end=' . urlencode($search_date_end_end);
  859. }
  860. if ($search_date_creation_startmonth) {
  861. $param .= '&search_date_creation_startmonth='.urlencode($search_date_creation_startmonth);
  862. }
  863. if ($search_date_creation_startyear) {
  864. $param .= '&search_date_creation_startyear='.urlencode($search_date_creation_startyear);
  865. }
  866. if ($search_date_creation_startday) {
  867. $param .= '&search_date_creation_startday='.urlencode($search_date_creation_startday);
  868. }
  869. if ($search_date_creation_start) {
  870. $param .= '&search_date_creation_start='.urlencode($search_date_creation_start);
  871. }
  872. if ($search_date_creation_endmonth) {
  873. $param .= '&search_date_creation_endmonth='.urlencode($search_date_creation_endmonth);
  874. }
  875. if ($search_date_creation_endyear) {
  876. $param .= '&search_date_creation_endyear='.urlencode($search_date_creation_endyear);
  877. }
  878. if ($search_date_creation_endday) {
  879. $param .= '&search_date_creation_endday='.urlencode($search_date_creation_endday);
  880. }
  881. if ($search_date_creation_end) {
  882. $param .= '&search_date_creation_end='.urlencode($search_date_creation_end);
  883. }
  884. if ($search_date_modif_startmonth) {
  885. $param .= '&search_date_modif_startmonth='.urlencode($search_date_modif_startmonth);
  886. }
  887. if ($search_date_modif_startyear) {
  888. $param .= '&search_date_modif_startyear='.urlencode($search_date_modif_startyear);
  889. }
  890. if ($search_date_modif_startday) {
  891. $param .= '&search_date_modif_startday='.urlencode($search_date_modif_startday);
  892. }
  893. if ($search_date_modif_start) {
  894. $param .= '&search_date_modif_start='.urlencode($search_date_modif_start);
  895. }
  896. if ($search_date_modif_endmonth) {
  897. $param .= '&search_date_modif_endmonth='.urlencode($search_date_modif_endmonth);
  898. }
  899. if ($search_date_modif_endyear) {
  900. $param .= '&search_date_modif_endyear='.urlencode($search_date_modif_endyear);
  901. }
  902. if ($search_date_modif_endday) {
  903. $param .= '&search_date_modif_endday='.urlencode($search_date_modif_endday);
  904. }
  905. if ($search_date_modif_end) {
  906. $param .= '&search_date_modif_end=' . urlencode($search_date_modif_end);
  907. }
  908. if (!empty($search_category_array)) {
  909. foreach ($search_category_array as $tmpval) {
  910. $param .= '&search_categegory_project_list[]='.urlencode($tmpval);
  911. }
  912. }
  913. if ($search_ref != '') {
  914. $param .= '&search_ref='.urlencode($search_ref);
  915. }
  916. if ($search_label != '') {
  917. $param .= '&search_label='.urlencode($search_label);
  918. }
  919. if ($search_societe != '') {
  920. $param .= '&search_societe='.urlencode($search_societe);
  921. }
  922. if ($search_societe_alias != '') {
  923. $param .= '&search_societe_alias='.urlencode($search_societe_alias);
  924. }
  925. if ($search_status != '' && $search_status != '-1') {
  926. $param .= "&search_status=".urlencode($search_status);
  927. }
  928. if ((is_numeric($search_opp_status) && $search_opp_status >= 0) || in_array($search_opp_status, array('all', 'openedopp', 'notopenedopp', 'none'))) {
  929. $param .= '&search_opp_status='.urlencode($search_opp_status);
  930. }
  931. if ($search_opp_percent != '') {
  932. $param .= '&search_opp_percent='.urlencode($search_opp_percent);
  933. }
  934. if ($search_public != '') {
  935. $param .= '&search_public='.urlencode($search_public);
  936. }
  937. if (!empty($search_project_user)) {
  938. if (is_array($search_project_user)) {
  939. foreach($search_project_user as $uid)
  940. $param .= '&search_project_user[]='.urlencode($uid);
  941. }
  942. elseif ($search_project_user > 0) {
  943. $param .= '&search_project_user='.urlencode($search_project_user);
  944. }
  945. }
  946. if (!empty($search_project_contact)) {
  947. if (is_array($search_project_contact)) {
  948. foreach($search_project_contact as $uid)
  949. $param .= '&search_project_contact[]='.urlencode($uid);
  950. }
  951. elseif ($search_project_contact > 0) {
  952. $param .= '&search_project_contact='.urlencode($search_project_contact);
  953. }
  954. }
  955. if ($search_sale > 0) {
  956. $param .= '&search_sale='.urlencode($search_sale);
  957. }
  958. if ($search_opp_amount != '') {
  959. $param .= '&search_opp_amount='.urlencode($search_opp_amount);
  960. }
  961. if ($search_budget_amount != '') {
  962. $param .= '&search_budget_amount='.urlencode($search_budget_amount);
  963. }
  964. if ($search_usage_task != '') {
  965. $param .= '&search_usage_task='.urlencode($search_usage_task);
  966. }
  967. if ($search_usage_bill_time != '') {
  968. $param .= '&search_usage_opportunity='.urlencode($search_usage_bill_time);
  969. }
  970. if ($search_usage_event_organization != '') {
  971. $param .= '&search_usage_event_organization='.urlencode($search_usage_event_organization);
  972. }
  973. if ($search_accept_conference_suggestions != '') {
  974. $param .= '&search_accept_conference_suggestions='.urlencode($search_accept_conference_suggestions);
  975. }
  976. if ($search_accept_booth_suggestions != '') {
  977. $param .= '&search_accept_booth_suggestions='.urlencode($search_accept_booth_suggestions);
  978. }
  979. if ($search_price_registration != '') {
  980. $param .= '&search_price_registration='.urlencode($search_price_registration);
  981. }
  982. if ($search_price_booth != '') {
  983. $param .= '&search_price_booth='.urlencode($search_price_booth);
  984. }
  985. if ($search_login) {
  986. $param .= '&search_login='.urlencode($search_login);
  987. }
  988. if ($search_import_key) {
  989. $param .= '&search_import_key='.urlencode($search_import_key);
  990. }
  991. foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
  992. $param .= "&search_category_customer_list[]=".urlencode($searchCategoryCustomer);
  993. }
  994. // Add $param from extra fields
  995. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  996. // Add $param from hooks
  997. $parameters = array('param' => &$param);
  998. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  999. $param .= $hookmanager->resPrint;
  1000. // List of mass actions available
  1001. $arrayofmassactions = array(
  1002. 'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  1003. 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  1004. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  1005. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  1006. );
  1007. //if($user->rights->societe->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
  1008. if ($user->hasRight('projet', 'creer')) {
  1009. $arrayofmassactions['close'] = img_picto('', 'close_title', 'class="pictofixedwidth"').$langs->trans("Close");
  1010. $arrayofmassactions['preaffectuser'] = img_picto('', 'user', 'class="pictofixedwidth"').$langs->trans("AffectUser");
  1011. }
  1012. if ($user->hasRight('projet', 'supprimer')) {
  1013. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  1014. }
  1015. if (isModEnabled('category') && $user->hasRight('projet', 'creer')) {
  1016. $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
  1017. }
  1018. if (in_array($massaction, array('presend', 'predelete', 'preaffecttag', 'preaffectuser'))) {
  1019. $arrayofmassactions = array();
  1020. }
  1021. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  1022. $url = DOL_URL_ROOT.'/projet/card.php?action=create';
  1023. if (!empty($socid)) {
  1024. $url .= '&socid='.$socid;
  1025. }
  1026. if ($search_usage_event_organization == 1) {
  1027. $url .= '&usage_organize_event=1';
  1028. if (((int) $search_usage_opportunity) < 1) {
  1029. $url .= '&usage_opportunity=0';
  1030. }
  1031. }
  1032. $newcardbutton = '';
  1033. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));
  1034. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition'));
  1035. $newcardbutton .= dolGetButtonTitleSeparator();
  1036. $newcardbutton .= dolGetButtonTitle($langs->trans('NewProject'), '', 'fa fa-plus-circle', $url, '', $user->hasRight('projet', 'creer'));
  1037. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  1038. if ($optioncss != '') {
  1039. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  1040. }
  1041. print '<input type="hidden" name="token" value="'.newToken().'">';
  1042. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  1043. print '<input type="hidden" name="action" value="list">';
  1044. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  1045. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  1046. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  1047. print '<input type="hidden" name="mode" value="'.$mode.'">';
  1048. // Show description of content
  1049. $texthelp = '';
  1050. if ($search_project_user == $user->id) {
  1051. $texthelp .= $langs->trans("MyProjectsDesc");
  1052. } else {
  1053. if ($user->hasRight('projet', 'all', 'lire') && !$socid) {
  1054. $texthelp .= $langs->trans("ProjectsDesc");
  1055. } else {
  1056. $texthelp .= $langs->trans("ProjectsPublicDesc");
  1057. }
  1058. }
  1059. print_barre_liste($form->textwithpicto($title, $texthelp), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'project', 0, $newcardbutton, '', $limit, 0, 0, 1);
  1060. $topicmail = "Information";
  1061. $modelmail = "project";
  1062. $objecttmp = new Project($db);
  1063. $trackid = 'proj'.$object->id;
  1064. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  1065. if ($search_all) {
  1066. foreach ($fieldstosearchall as $key => $val) {
  1067. $fieldstosearchall[$key] = $langs->trans($val);
  1068. }
  1069. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  1070. }
  1071. $moreforfilter = '';
  1072. // If the user can view user other than himself
  1073. $moreforfilter .= '<div class="divsearchfield">';
  1074. $tmptitle = $langs->trans('ProjectsWithThisUserAsContact');
  1075. //$includeonly = 'hierarchyme';
  1076. $includeonly = '';
  1077. if (!$user->hasRight('user', 'user', 'lire')) {
  1078. $includeonly = array($user->id);
  1079. }
  1080. $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, '', 'maxwidth300 widthcentpercentminusx', 0, 0, getDolGlobalInt('PROJECT_SEARCH_USER_MULTIPLE'));
  1081. $moreforfilter .= '</div>';
  1082. $moreforfilter .= '<div class="divsearchfield">';
  1083. $tmptitle = $langs->trans('ProjectsWithThisContact');
  1084. $moreforfilter .= img_picto($tmptitle, 'contact', 'class="pictofixedwidth"').$form->selectcontacts(0, $search_project_contact ? $search_project_contact : '', 'search_project_contact', $tmptitle, '', '', 0, 'maxwidth300 widthcentpercentminusx', false, 0, 0, [], '', '', getDolGlobalInt('PROJECT_SEARCH_CONTACT_MULTIPLE'));
  1085. $moreforfilter .= '</div>';
  1086. // If the user can view thirdparties other than his'
  1087. if ($user->hasRight('user', 'user', 'lire')) {
  1088. $langs->load("commercial");
  1089. $moreforfilter .= '<div class="divsearchfield">';
  1090. $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
  1091. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth300 widthcentpercentminusx');
  1092. $moreforfilter .= '</div>';
  1093. }
  1094. // Filter on categories
  1095. if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire')) {
  1096. $formcategory = new FormCategory($db);
  1097. $moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_PROJECT, $search_category_array, 'minwidth300imp minwidth300 widthcentpercentminusx');
  1098. }
  1099. // Filter on customer categories
  1100. if (getDolGlobalString('MAIN_SEARCH_CATEGORY_CUSTOMER_ON_PROJECT_LIST') && isModEnabled("categorie") && $user->hasRight('categorie', 'lire')) {
  1101. $moreforfilter .= '<div class="divsearchfield">';
  1102. $tmptitle = $langs->transnoentities('CustomersProspectsCategoriesShort');
  1103. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
  1104. $categoriesArr = $form->select_all_categories(Categorie::TYPE_CUSTOMER, '', '', 64, 0, 1);
  1105. $categoriesArr[-2] = '- '.$langs->trans('NotCategorized').' -';
  1106. $moreforfilter .= Form::multiselectarray('search_category_customer_list', $categoriesArr, $searchCategoryCustomerList, 0, 0, 'minwidth300im minwidth300 widthcentpercentminusx', 0, 0, '', 'category', $tmptitle);
  1107. $moreforfilter .= ' <input type="checkbox" class="valignmiddle" id="search_category_customer_operator" name="search_category_customer_operator" value="1"'.($searchCategoryCustomerOperator == 1 ? ' checked="checked"' : '').'/>';
  1108. $moreforfilter .= $form->textwithpicto('', $langs->trans('UseOrOperatorForCategories') . ' : ' . $tmptitle, 1, 'help', '', 0, 2, 'tooltip_cat_cus'); // Tooltip on click
  1109. $moreforfilter .= '</div>';
  1110. }
  1111. if (getDolGlobalInt('PROJECT_ENABLE_SUB_PROJECT')) {
  1112. //Checkbox for omitting child projects filter
  1113. $moreforfilter .= '<p style="display: inline-block; margin-left: 5px;">'.$langs->trans("Omit sub-projects").' </p><input type="checkbox" style="margin-left: 10px" class="valignmiddle" id="search_omitChildren" name="search_omitChildren"'.($search_omitChildren ? ' checked="checked"' : '').'"> ';
  1114. }
  1115. if (!empty($moreforfilter)) {
  1116. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  1117. print $moreforfilter;
  1118. $parameters = array();
  1119. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  1120. print $hookmanager->resPrint;
  1121. print '</div>';
  1122. }
  1123. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  1124. $selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields
  1125. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  1126. print '<div class="div-table-responsive">';
  1127. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  1128. // Fields title search
  1129. // --------------------------------------------------------------------
  1130. print '<tr class="liste_titre_filter">';
  1131. // Action column
  1132. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1133. print '<td class="liste_titre maxwidthsearch">';
  1134. $searchpicto = $form->showFilterButtons('left');
  1135. print $searchpicto;
  1136. print '</td>';
  1137. }
  1138. // Project ref
  1139. if (!empty($arrayfields['p.ref']['checked'])) {
  1140. print '<td class="liste_titre">';
  1141. print '<input type="text" class="flat" name="search_ref" value="'.dol_escape_htmltag($search_ref).'" size="6">';
  1142. print '</td>';
  1143. }
  1144. // Project label
  1145. if (!empty($arrayfields['p.title']['checked'])) {
  1146. print '<td class="liste_titre">';
  1147. print '<input type="text" class="flat" name="search_label" size="8" value="'.dol_escape_htmltag($search_label).'">';
  1148. print '</td>';
  1149. }
  1150. // Third party
  1151. if (!empty($arrayfields['s.nom']['checked'])) {
  1152. print '<td class="liste_titre">';
  1153. if ($socid > 0) {
  1154. $tmpthirdparty = new Societe($db);
  1155. $tmpthirdparty->fetch($socid);
  1156. $search_societe = $tmpthirdparty->name;
  1157. }
  1158. print '<input type="text" class="flat" name="search_societe" size="8" value="'.dol_escape_htmltag($search_societe).'">';
  1159. print '</td>';
  1160. }
  1161. // Alias
  1162. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1163. print '<td class="liste_titre">';
  1164. if ($socid > 0) {
  1165. $tmpthirdparty = new Societe($db);
  1166. $tmpthirdparty->fetch($socid);
  1167. $search_societe_alias = $tmpthirdparty->name_alias;
  1168. }
  1169. print '<input type="text" class="flat" name="search_societe_alias" size="8" value="'.dol_escape_htmltag($search_societe_alias).'">';
  1170. print '</td>';
  1171. }
  1172. // Sale representative
  1173. if (!empty($arrayfields['commercial']['checked'])) {
  1174. print '<td class="liste_titre">&nbsp;</td>';
  1175. }
  1176. // Start date
  1177. if (!empty($arrayfields['p.dateo']['checked'])) {
  1178. print '<td class="liste_titre center nowraponall">';
  1179. /*if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) {
  1180. print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_sday" value="'.dol_escape_htmltag($search_sday).'">';
  1181. }
  1182. print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_smonth" value="'.dol_escape_htmltag($search_smonth).'">';
  1183. print $formother->selectyear($search_syear ? $search_syear : -1, 'search_syear', 1, 20, 5, 0, 0, '', 'widthauto valignmiddle');*/
  1184. print '<div class="nowrapfordate">';
  1185. 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'));
  1186. print '</div>';
  1187. print '<div class="nowrapfordate">';
  1188. 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'));
  1189. print '</div>';
  1190. print '</td>';
  1191. }
  1192. // End date
  1193. if (!empty($arrayfields['p.datee']['checked'])) {
  1194. print '<td class="liste_titre center nowraponall">';
  1195. /*if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) {
  1196. print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_eday" value="'.dol_escape_htmltag($search_eday).'">';
  1197. }
  1198. print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_emonth" value="'.dol_escape_htmltag($search_emonth).'">';
  1199. print $formother->selectyear($search_eyear ? $search_eyear : -1, 'search_eyear', 1, 20, 5, 0, 0, '', 'widthauto valignmiddle');*/
  1200. print '<div class="nowrapfordate">';
  1201. 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'));
  1202. print '</div>';
  1203. print '<div class="nowrapfordate">';
  1204. 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'));
  1205. print '</div>';
  1206. print '</td>';
  1207. }
  1208. // Visibility
  1209. if (!empty($arrayfields['p.public']['checked'])) {
  1210. print '<td class="liste_titre center">';
  1211. $array = array(''=>'', 0 => $langs->trans("PrivateProject"), 1 => $langs->trans("SharedProject"));
  1212. print $form->selectarray('search_public', $array, $search_public, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth75');
  1213. print '</td>';
  1214. }
  1215. if (!empty($arrayfields['c.assigned']['checked'])) {
  1216. print '<td class="liste_titre center">';
  1217. print '</td>';
  1218. }
  1219. // Opp status
  1220. if (!empty($arrayfields['p.fk_opp_status']['checked'])) {
  1221. print '<td class="liste_titre nowrap center">';
  1222. print $formproject->selectOpportunityStatus('search_opp_status', $search_opp_status, 1, 1, 1, 0, 'maxwidth125 nowrapoption', 1, 1);
  1223. print '</td>';
  1224. }
  1225. if (!empty($arrayfields['p.opp_amount']['checked'])) {
  1226. print '<td class="liste_titre nowrap right">';
  1227. print '<input type="text" class="flat" name="search_opp_amount" size="3" value="'.$search_opp_amount.'">';
  1228. print '</td>';
  1229. }
  1230. if (!empty($arrayfields['p.opp_percent']['checked'])) {
  1231. print '<td class="liste_titre nowrap right">';
  1232. print '<input type="text" class="flat" name="search_opp_percent" size="2" value="'.$search_opp_percent.'">';
  1233. print '</td>';
  1234. }
  1235. if (!empty($arrayfields['opp_weighted_amount']['checked'])) {
  1236. print '<td class="liste_titre nowrap right">';
  1237. print '</td>';
  1238. }
  1239. if (!empty($arrayfields['p.budget_amount']['checked'])) {
  1240. print '<td class="liste_titre nowrap right">';
  1241. print '<input type="text" class="flat" name="search_budget_amount" size="4" value="'.$search_budget_amount.'">';
  1242. print '</td>';
  1243. }
  1244. if (!empty($arrayfields['p.usage_opportunity']['checked'])) {
  1245. print '<td class="liste_titre nowrap">';
  1246. print $form->selectyesno('search_usage_opportunity', $search_usage_opportunity, 1, false, 1, 1);
  1247. print '';
  1248. print '</td>';
  1249. }
  1250. if (!empty($arrayfields['p.usage_task']['checked'])) {
  1251. print '<td class="liste_titre nowrap">';
  1252. print $form->selectyesno('search_usage_task', $search_usage_task, 1, false, 1, 1);
  1253. print '</td>';
  1254. }
  1255. if (!empty($arrayfields['p.usage_bill_time']['checked'])) {
  1256. print '<td class="liste_titre nowrap">';
  1257. print $form->selectyesno('search_usage_bill_time', $search_usage_bill_time, 1, false, 1, 1);
  1258. print '</td>';
  1259. }
  1260. if (!empty($arrayfields['p.usage_organize_event']['checked'])) {
  1261. print '<td class="liste_titre nowrap">';
  1262. print $form->selectyesno('search_usage_event_organization', $search_usage_event_organization, 1, false, 1, 1);
  1263. print '</td>';
  1264. }
  1265. if (!empty($arrayfields['p.accept_conference_suggestions']['checked'])) {
  1266. print '<td class="liste_titre nowrap">';
  1267. print $form->selectyesno('search_accept_conference_suggestions', $search_accept_conference_suggestions, 1, false, 1, 1);
  1268. print '</td>';
  1269. }
  1270. if (!empty($arrayfields['p.accept_booth_suggestions']['checked'])) {
  1271. print '<td class="liste_titre nowrap">';
  1272. print $form->selectyesno('search_accept_booth_suggestions', $search_accept_booth_suggestions, 1, false, 1, 1);
  1273. print '</td>';
  1274. }
  1275. if (!empty($arrayfields['p.price_registration']['checked'])) {
  1276. print '<td class="liste_titre nowrap right">';
  1277. print '<input type="text" class="flat" name="search_price_registration" size="4" value="'.dol_escape_htmltag($search_price_registration).'">';
  1278. print '</td>';
  1279. }
  1280. if (!empty($arrayfields['p.price_booth']['checked'])) {
  1281. print '<td class="liste_titre nowrap right">';
  1282. print '<input type="text" class="flat" name="search_price_booth" size="4" value="'.dol_escape_htmltag($search_price_booth).'">';
  1283. print '</td>';
  1284. }
  1285. if (!empty($arrayfields['u.login']['checked'])) {
  1286. // Author
  1287. print '<td class="liste_titre" align="center">';
  1288. print '<input class="flat" size="4" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
  1289. print '</td>';
  1290. }
  1291. // Extra fields
  1292. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  1293. // Fields from hook
  1294. $parameters = array('arrayfields'=>$arrayfields);
  1295. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  1296. print $hookmanager->resPrint;
  1297. // Creation date
  1298. if (!empty($arrayfields['p.datec']['checked'])) {
  1299. print '<td class="liste_titre center nowraponall">';
  1300. print '<div class="nowrapfordate">';
  1301. print $form->selectDate($search_date_creation_start ? $search_date_creation_start : -1, 'search_date_creation_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  1302. print '</div>';
  1303. print '<div class="nowrapfordate">';
  1304. print $form->selectDate($search_date_creation_end ? $search_date_creation_end : -1, 'search_date_creation_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  1305. print '</div>';
  1306. print '</td>';
  1307. }
  1308. // Modification date
  1309. if (!empty($arrayfields['p.tms']['checked'])) {
  1310. print '<td class="liste_titre center nowraponall">';
  1311. print '<div class="nowrapfordate">';
  1312. print $form->selectDate($search_date_modif_start ? $search_date_modif_start : -1, 'search_date_modif_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  1313. print '</div>';
  1314. print '<div class="nowrapfordate">';
  1315. print $form->selectDate($search_date_modif_end ? $search_date_modif_end : -1, 'search_date_modif_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  1316. print '</div>';
  1317. print '</td>';
  1318. }
  1319. if (!empty($arrayfields['p.email_msgid']['checked'])) {
  1320. // Email msg id
  1321. print '<td class="liste_titre">';
  1322. print '</td>';
  1323. }
  1324. if (!empty($arrayfields['p.import_key']['checked'])) {
  1325. // Import key
  1326. print '<td class="liste_titre">';
  1327. print '<input class="flat width75" type="text" name="search_import_key" value="'.dol_escape_htmltag($search_import_key).'">';
  1328. print '</td>';
  1329. }
  1330. if (!empty($arrayfields['p.fk_statut']['checked'])) {
  1331. print '<td class="liste_titre center parentonrightofpage">';
  1332. $formproject->selectProjectsStatus($search_status, 1, 'search_status');
  1333. print '</td>';
  1334. }
  1335. // Action column
  1336. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1337. print '<td class="liste_titre maxwidthsearch">';
  1338. $searchpicto = $form->showFilterButtons();
  1339. print $searchpicto;
  1340. print '</td>';
  1341. }
  1342. print '</tr>'."\n";
  1343. $totalarray = array();
  1344. $totalarray['nbfield'] = 0;
  1345. // Fields title label
  1346. // --------------------------------------------------------------------
  1347. print '<tr class="liste_titre">';
  1348. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1349. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  1350. $totalarray['nbfield']++;
  1351. }
  1352. if (!empty($arrayfields['p.ref']['checked'])) {
  1353. print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, "", $sortfield, $sortorder);
  1354. $totalarray['nbfield']++;
  1355. }
  1356. if (!empty($arrayfields['p.title']['checked'])) {
  1357. print_liste_field_titre($arrayfields['p.title']['label'], $_SERVER["PHP_SELF"], "p.title", "", $param, "", $sortfield, $sortorder);
  1358. $totalarray['nbfield']++;
  1359. }
  1360. if (!empty($arrayfields['s.nom']['checked'])) {
  1361. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, "", $sortfield, $sortorder);
  1362. $totalarray['nbfield']++;
  1363. }
  1364. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1365. print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER["PHP_SELF"], "s.name_alias", "", $param, "", $sortfield, $sortorder);
  1366. $totalarray['nbfield']++;
  1367. }
  1368. if (!empty($arrayfields['commercial']['checked'])) {
  1369. print_liste_field_titre($arrayfields['commercial']['label'], $_SERVER["PHP_SELF"], "", "", $param, "", $sortfield, $sortorder, 'tdoverflowmax100imp ');
  1370. $totalarray['nbfield']++;
  1371. }
  1372. if (!empty($arrayfields['p.dateo']['checked'])) {
  1373. print_liste_field_titre($arrayfields['p.dateo']['label'], $_SERVER["PHP_SELF"], "p.dateo", "", $param, '', $sortfield, $sortorder, 'center ');
  1374. $totalarray['nbfield']++;
  1375. }
  1376. if (!empty($arrayfields['p.datee']['checked'])) {
  1377. print_liste_field_titre($arrayfields['p.datee']['label'], $_SERVER["PHP_SELF"], "p.datee", "", $param, '', $sortfield, $sortorder, 'center ');
  1378. $totalarray['nbfield']++;
  1379. }
  1380. if (!empty($arrayfields['p.public']['checked'])) {
  1381. print_liste_field_titre($arrayfields['p.public']['label'], $_SERVER["PHP_SELF"], "p.public", "", $param, "", $sortfield, $sortorder, 'center ');
  1382. $totalarray['nbfield']++;
  1383. }
  1384. if (!empty($arrayfields['c.assigned']['checked'])) {
  1385. print_liste_field_titre($arrayfields['c.assigned']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'center ', '');
  1386. $totalarray['nbfield']++;
  1387. }
  1388. if (!empty($arrayfields['p.fk_opp_status']['checked'])) {
  1389. print_liste_field_titre($arrayfields['p.fk_opp_status']['label'], $_SERVER["PHP_SELF"], 'p.fk_opp_status', "", $param, '', $sortfield, $sortorder, 'center ');
  1390. $totalarray['nbfield']++;
  1391. }
  1392. if (!empty($arrayfields['p.opp_amount']['checked'])) {
  1393. print_liste_field_titre($arrayfields['p.opp_amount']['label'], $_SERVER["PHP_SELF"], 'p.opp_amount', "", $param, '', $sortfield, $sortorder, 'right ');
  1394. $totalarray['nbfield']++;
  1395. }
  1396. if (!empty($arrayfields['p.opp_percent']['checked'])) {
  1397. print_liste_field_titre($arrayfields['p.opp_percent']['label'], $_SERVER['PHP_SELF'], 'p.opp_percent', "", $param, '', $sortfield, $sortorder, 'right ');
  1398. $totalarray['nbfield']++;
  1399. }
  1400. if (!empty($arrayfields['opp_weighted_amount']['checked'])) {
  1401. print_liste_field_titre($arrayfields['opp_weighted_amount']['label'], $_SERVER['PHP_SELF'], 'opp_weighted_amount', '', $param, '', $sortfield, $sortorder, 'right ');
  1402. $totalarray['nbfield']++;
  1403. }
  1404. if (!empty($arrayfields['p.budget_amount']['checked'])) {
  1405. print_liste_field_titre($arrayfields['p.budget_amount']['label'], $_SERVER["PHP_SELF"], 'p.budget_amount', "", $param, '', $sortfield, $sortorder, 'right ');
  1406. $totalarray['nbfield']++;
  1407. }
  1408. if (!empty($arrayfields['p.usage_opportunity']['checked'])) {
  1409. print_liste_field_titre($arrayfields['p.usage_opportunity']['label'], $_SERVER["PHP_SELF"], 'p.usage_opportunity', "", $param, '', $sortfield, $sortorder, '');
  1410. $totalarray['nbfield']++;
  1411. }
  1412. if (!empty($arrayfields['p.usage_task']['checked'])) {
  1413. print_liste_field_titre($arrayfields['p.usage_task']['label'], $_SERVER["PHP_SELF"], 'p.usage_task', "", $param, '', $sortfield, $sortorder, '');
  1414. $totalarray['nbfield']++;
  1415. }
  1416. if (!empty($arrayfields['p.usage_bill_time']['checked'])) {
  1417. print_liste_field_titre($arrayfields['p.usage_bill_time']['label'], $_SERVER["PHP_SELF"], 'p.usage_bill_time', "", $param, '', $sortfield, $sortorder, '');
  1418. $totalarray['nbfield']++;
  1419. }
  1420. if (!empty($arrayfields['p.usage_organize_event']['checked'])) {
  1421. print_liste_field_titre($arrayfields['p.usage_organize_event']['label'], $_SERVER["PHP_SELF"], 'p.usage_organize_event', "", $param, '', $sortfield, $sortorder, '');
  1422. $totalarray['nbfield']++;
  1423. }
  1424. if (!empty($arrayfields['p.accept_conference_suggestions']['checked'])) {
  1425. print_liste_field_titre($arrayfields['p.accept_conference_suggestions']['label'], $_SERVER["PHP_SELF"], 'p.accept_conference_suggestions', "", $param, '', $sortfield, $sortorder, '');
  1426. $totalarray['nbfield']++;
  1427. }
  1428. if (!empty($arrayfields['p.accept_booth_suggestions']['checked'])) {
  1429. print_liste_field_titre($arrayfields['p.accept_booth_suggestions']['label'], $_SERVER["PHP_SELF"], 'p.accept_booth_suggestions', "", $param, '', $sortfield, $sortorder, '');
  1430. $totalarray['nbfield']++;
  1431. }
  1432. if (!empty($arrayfields['p.price_registration']['checked'])) {
  1433. print_liste_field_titre($arrayfields['p.price_registration']['label'], $_SERVER["PHP_SELF"], 'p.price_registration', "", $param, '', $sortfield, $sortorder, 'right ');
  1434. $totalarray['nbfield']++;
  1435. }
  1436. if (!empty($arrayfields['p.price_booth']['checked'])) {
  1437. print_liste_field_titre($arrayfields['p.price_booth']['label'], $_SERVER["PHP_SELF"], 'p.price_booth', "", $param, '', $sortfield, $sortorder, 'right ');
  1438. $totalarray['nbfield']++;
  1439. }
  1440. if (!empty($arrayfields['u.login']['checked'])) {
  1441. print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, 'align="center"', $sortfield, $sortorder);
  1442. $totalarray['nbfield']++;
  1443. }
  1444. // Extra fields
  1445. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1446. // Hook fields
  1447. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
  1448. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1449. print $hookmanager->resPrint;
  1450. if (!empty($arrayfields['p.datec']['checked'])) {
  1451. print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1452. $totalarray['nbfield']++;
  1453. }
  1454. if (!empty($arrayfields['p.tms']['checked'])) {
  1455. print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1456. $totalarray['nbfield']++;
  1457. }
  1458. if (!empty($arrayfields['p.email_msgid']['checked'])) {
  1459. print_liste_field_titre($arrayfields['p.email_msgid']['label'], $_SERVER["PHP_SELF"], "p.email_msgid", "", $param, '', $sortfield, $sortorder, 'center ');
  1460. $totalarray['nbfield']++;
  1461. }
  1462. if (!empty($arrayfields['p.import_key']['checked'])) {
  1463. print_liste_field_titre($arrayfields['p.import_key']['label'], $_SERVER["PHP_SELF"], "p.import_key", "", $param, '', $sortfield, $sortorder, '');
  1464. $totalarray['nbfield']++;
  1465. }
  1466. if (!empty($arrayfields['p.fk_statut']['checked'])) {
  1467. print_liste_field_titre($arrayfields['p.fk_statut']['label'], $_SERVER["PHP_SELF"], "p.fk_statut", "", $param, '', $sortfield, $sortorder, 'center ');
  1468. $totalarray['nbfield']++;
  1469. }
  1470. // Action column
  1471. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1472. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  1473. $totalarray['nbfield']++;
  1474. }
  1475. print '</tr>'."\n";
  1476. $i = 0;
  1477. $savnbfield = $totalarray['nbfield'];
  1478. $totalarray = array(
  1479. 'nbfield' => 0,
  1480. 'val' => array()
  1481. );
  1482. $imaxinloop = ($limit ? min($num, $limit) : $num);
  1483. while ($i < $imaxinloop) {
  1484. $obj = $db->fetch_object($resql);
  1485. if (empty($obj)) {
  1486. break; // Should not happen
  1487. }
  1488. $object->id = $obj->id;
  1489. $object->ref = $obj->ref;
  1490. $object->title = $obj->title;
  1491. $object->fk_opp_status = $obj->fk_opp_status;
  1492. $object->user_author_id = $obj->fk_user_creat;
  1493. $object->date_creation = $db->jdate($obj->date_creation);
  1494. $object->date_start = $db->jdate($obj->date_start);
  1495. $object->date_end = $db->jdate($obj->date_end);
  1496. $object->statut = $obj->status; // deprecated
  1497. $object->status = $obj->status;
  1498. $object->public = $obj->public;
  1499. $object->opp_percent = $obj->opp_percent;
  1500. $object->opp_status = $obj->fk_opp_status;
  1501. $object->opp_status_code = $obj->opp_status_code;
  1502. $object->opp_amount = !empty($obj->opp_amount) ? $obj->opp_amount : "";
  1503. $object->opp_weighted_amount = $obj->opp_weighted_amount;
  1504. $object->budget_amount = $obj->budget_amount;
  1505. $object->usage_opportunity = $obj->usage_opportunity;
  1506. $object->usage_task = $obj->usage_task;
  1507. $object->usage_bill_time = $obj->usage_bill_time;
  1508. $object->usage_organize_event = $obj->usage_organize_event;
  1509. $object->email_msgid = $obj->email_msgid;
  1510. $object->import_key = $obj->import_key;
  1511. //$userAccess = $object->restrictedProjectArea($user); // disabled, permission on project must be done by the select
  1512. // Thirdparty
  1513. $companystatic->id = $obj->socid;
  1514. $companystatic->name = $obj->name;
  1515. $companystatic->name_alias = $obj->alias;
  1516. $companystatic->client = $obj->client;
  1517. $companystatic->code_client = $obj->code_client;
  1518. $companystatic->email = $obj->email;
  1519. $companystatic->phone = $obj->phone;
  1520. $companystatic->address = $obj->address;
  1521. $companystatic->zip = $obj->zip;
  1522. $companystatic->town = $obj->town;
  1523. $companystatic->country_code = $obj->country_code;
  1524. $object->thirdparty = $companystatic;
  1525. $stringassignedusers = '';
  1526. if (!empty($arrayfields['c.assigned']['checked'])) {
  1527. $ifisrt = 1;
  1528. foreach (array('internal', 'external') as $source) {
  1529. $tab = $object->liste_contact(-1, $source, 0, '', 1);
  1530. $numcontact = count($tab);
  1531. if (!empty($numcontact)) {
  1532. foreach ($tab as $contactproject) {
  1533. //var_dump($contacttask);
  1534. if ($source == 'internal') {
  1535. $c = new User($db);
  1536. } else {
  1537. $c = new Contact($db);
  1538. }
  1539. $c->fetch($contactproject['id']);
  1540. //var_dump($c->photo);
  1541. //if (!empty($c->photo)) {
  1542. if (get_class($c) == 'User') {
  1543. $stringassignedusers .= $c->getNomUrl(-2, '', 0, 0, 24, 1, '', 'valignmiddle'.($ifisrt ? '' : ' notfirst'));
  1544. } else {
  1545. $stringassignedusers .= $c->getNomUrl(-2, '', 0, '', -1, 0, 'valignmiddle'.($ifisrt ? '' : ' notfirst'));
  1546. }
  1547. /*} else {
  1548. // if (get_class($c) == 'User') {
  1549. $stringassignedusers .= $c->getNomUrl(2, '', 0, 0, 24, 1, '', 'valignmiddle'.($ifisrt ? '' : ' notfirst'));
  1550. } else {
  1551. $stringassignedusers .= $c->getNomUrl(2, '', 0, '', -1, 0, 'valignmiddle'.($ifisrt ? '' : ' notfirst'));
  1552. }
  1553. }*/
  1554. $ifisrt = 0;
  1555. }
  1556. }
  1557. }
  1558. }
  1559. if ($mode == 'kanban') {
  1560. if ($i == 0) {
  1561. print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
  1562. print '<div class="box-flex-container kanban">';
  1563. }
  1564. $selected = in_array($object->id, $arrayofselected);
  1565. $arrayofdata = array('assignedusers' => $stringassignedusers, 'thirdparty'=>$companystatic, 'selected' => $selected);
  1566. print $object->getKanbanView('', $arrayofdata);
  1567. if ($i == ($imaxinloop - 1)) {
  1568. print '</div>';
  1569. print '</td></tr>';
  1570. }
  1571. } else {
  1572. // Author
  1573. $userstatic->id = $obj->fk_user_creat;
  1574. $userstatic->login = $obj->login;
  1575. $userstatic->lastname = $obj->lastname;
  1576. $userstatic->firstname = $obj->firstname;
  1577. $userstatic->email = $obj->user_email;
  1578. $userstatic->statut = $obj->user_statut;
  1579. $userstatic->entity = $obj->entity;
  1580. $userstatic->photo = $obj->photo;
  1581. $userstatic->office_phone = $obj->office_phone;
  1582. $userstatic->office_fax = $obj->office_fax;
  1583. $userstatic->user_mobile = $obj->user_mobile;
  1584. $userstatic->job = $obj->job;
  1585. $userstatic->gender = $obj->gender;
  1586. // Show here line of result
  1587. $j = 0;
  1588. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  1589. // Action column
  1590. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1591. print '<td class="nowrap center">';
  1592. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1593. $selected = 0;
  1594. if (in_array($object->id, $arrayofselected)) {
  1595. $selected = 1;
  1596. }
  1597. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  1598. }
  1599. print '</td>';
  1600. if (!$i) {
  1601. $totalarray['nbfield']++;
  1602. }
  1603. }
  1604. // Project url
  1605. if (!empty($arrayfields['p.ref']['checked'])) {
  1606. print '<td class="nowraponall tdoverflowmax200">';
  1607. print $object->getNomUrl(1, (!empty(GETPOST('search_usage_event_organization', 'int')) ? 'eventorganization' : ''));
  1608. if ($object->hasDelay()) {
  1609. print img_warning($langs->trans('Late'));
  1610. }
  1611. print '</td>';
  1612. if (!$i) {
  1613. $totalarray['nbfield']++;
  1614. }
  1615. }
  1616. // Title
  1617. if (!empty($arrayfields['p.title']['checked'])) {
  1618. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->title).'">';
  1619. print dol_escape_htmltag($obj->title);
  1620. print '</td>';
  1621. if (!$i) {
  1622. $totalarray['nbfield']++;
  1623. }
  1624. }
  1625. // Company
  1626. if (!empty($arrayfields['s.nom']['checked'])) {
  1627. print '<td class="tdoverflowmax125">';
  1628. if ($obj->socid) {
  1629. print $companystatic->getNomUrl(1, '', 0, 0, -1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
  1630. } else {
  1631. print '&nbsp;';
  1632. }
  1633. print '</td>';
  1634. if (!$i) {
  1635. $totalarray['nbfield']++;
  1636. }
  1637. }
  1638. // Alias
  1639. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1640. print '<td class="tdoverflowmax100">';
  1641. if ($obj->socid) {
  1642. print $companystatic->name_alias;
  1643. } else {
  1644. print '&nbsp;';
  1645. }
  1646. print '</td>';
  1647. if (!$i) {
  1648. $totalarray['nbfield']++;
  1649. }
  1650. }
  1651. // Sales Representatives
  1652. if (!empty($arrayfields['commercial']['checked'])) {
  1653. print '<td class="tdoverflowmax150">';
  1654. if ($obj->socid) {
  1655. $companystatic->id = $obj->socid;
  1656. $companystatic->name = $obj->name;
  1657. $listsalesrepresentatives = $companystatic->getSalesRepresentatives($user);
  1658. $nbofsalesrepresentative = count($listsalesrepresentatives);
  1659. if ($nbofsalesrepresentative > 6) {
  1660. // We print only number
  1661. print $nbofsalesrepresentative;
  1662. } elseif ($nbofsalesrepresentative > 0) {
  1663. $userstatic = new User($db);
  1664. $j = 0;
  1665. foreach ($listsalesrepresentatives as $val) {
  1666. $userstatic->id = $val['id'];
  1667. $userstatic->lastname = $val['lastname'];
  1668. $userstatic->firstname = $val['firstname'];
  1669. $userstatic->email = $val['email'];
  1670. $userstatic->statut = $val['statut'];
  1671. $userstatic->entity = $val['entity'];
  1672. $userstatic->photo = $val['photo'];
  1673. $userstatic->login = $val['login'];
  1674. $userstatic->office_phone = $val['office_phone'];
  1675. $userstatic->office_fax = $val['office_fax'];
  1676. $userstatic->user_mobile = $val['user_mobile'];
  1677. $userstatic->job = $val['job'];
  1678. $userstatic->gender = $val['gender'];
  1679. print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2);
  1680. $j++;
  1681. if ($j < $nbofsalesrepresentative) {
  1682. print ' ';
  1683. }
  1684. }
  1685. }
  1686. //else print $langs->trans("NoSalesRepresentativeAffected");
  1687. } else {
  1688. print '&nbsp;';
  1689. }
  1690. print '</td>';
  1691. if (!$i) {
  1692. $totalarray['nbfield']++;
  1693. }
  1694. }
  1695. // Date start project
  1696. if (!empty($arrayfields['p.dateo']['checked'])) {
  1697. print '<td class="center">';
  1698. print dol_print_date($db->jdate($obj->date_start), 'day');
  1699. print '</td>';
  1700. if (!$i) {
  1701. $totalarray['nbfield']++;
  1702. }
  1703. }
  1704. // Date end project
  1705. if (!empty($arrayfields['p.datee']['checked'])) {
  1706. print '<td class="center">';
  1707. print dol_print_date($db->jdate($obj->date_end), 'day');
  1708. print '</td>';
  1709. if (!$i) {
  1710. $totalarray['nbfield']++;
  1711. }
  1712. }
  1713. // Visibility
  1714. if (!empty($arrayfields['p.public']['checked'])) {
  1715. print '<td class="center">';
  1716. if ($obj->public) {
  1717. print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
  1718. //print $langs->trans('SharedProject');
  1719. } else {
  1720. print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
  1721. //print $langs->trans('PrivateProject');
  1722. }
  1723. print '</td>';
  1724. if (!$i) {
  1725. $totalarray['nbfield']++;
  1726. }
  1727. }
  1728. // Assigned contacts of project
  1729. if (!empty($arrayfields['c.assigned']['checked'])) {
  1730. print '<td class="center nowraponall tdoverflowmax200">';
  1731. print $stringassignedusers;
  1732. print '</td>';
  1733. if (!$i) {
  1734. $totalarray['nbfield']++;
  1735. }
  1736. }
  1737. // Opp Status
  1738. if (!empty($arrayfields['p.fk_opp_status']['checked'])) {
  1739. print '<td class="center">';
  1740. if ($obj->opp_status_code) {
  1741. print $langs->trans("OppStatus".$obj->opp_status_code);
  1742. }
  1743. print '</td>';
  1744. if (!$i) {
  1745. $totalarray['nbfield']++;
  1746. }
  1747. }
  1748. // Opp Amount
  1749. if (!empty($arrayfields['p.opp_amount']['checked'])) {
  1750. print '<td class="right">';
  1751. //if ($obj->opp_status_code)
  1752. if (strcmp($obj->opp_amount, '')) {
  1753. print '<span class="amount">'.price($obj->opp_amount, 1, $langs, 1, -1, -1, '').'</span>';
  1754. if (!isset($totalarray['val']['p.opp_amount'])) {
  1755. $totalarray['val']['p.opp_amount'] = $obj->opp_amount;
  1756. } else {
  1757. $totalarray['val']['p.opp_amount'] += $obj->opp_amount;
  1758. }
  1759. }
  1760. print '</td>';
  1761. if (!$i) {
  1762. $totalarray['nbfield']++;
  1763. }
  1764. if (!$i) {
  1765. $totalarray['pos'][$totalarray['nbfield']] = 'p.opp_amount';
  1766. }
  1767. }
  1768. // Opp percent
  1769. if (!empty($arrayfields['p.opp_percent']['checked'])) {
  1770. print '<td class="right">';
  1771. if ($obj->opp_percent) {
  1772. print price($obj->opp_percent, 1, $langs, 1, 0).'%';
  1773. }
  1774. print '</td>';
  1775. if (!$i) {
  1776. $totalarray['nbfield']++;
  1777. }
  1778. }
  1779. // Opp weighted amount
  1780. if (!empty($arrayfields['opp_weighted_amount']['checked'])) {
  1781. if (!isset($totalarray['val']['opp_weighted_amount'])) {
  1782. $totalarray['val']['opp_weighted_amount'] = 0;
  1783. }
  1784. print '<td align="right">';
  1785. if ($obj->opp_weighted_amount) {
  1786. print '<span class="amount">'.price($obj->opp_weighted_amount, 1, $langs, 1, -1, -1, '').'</span>';
  1787. $totalarray['val']['opp_weighted_amount'] += $obj->opp_weighted_amount;
  1788. }
  1789. print '</td>';
  1790. if (!$i) {
  1791. $totalarray['nbfield']++;
  1792. $totalarray['pos'][$totalarray['nbfield']] = 'opp_weighted_amount';
  1793. }
  1794. }
  1795. // Budget
  1796. if (!empty($arrayfields['p.budget_amount']['checked'])) {
  1797. print '<td class="right">';
  1798. if ($obj->budget_amount != '') {
  1799. print '<span class="amount">'.price($obj->budget_amount, 1, $langs, 1, -1, -1).'</span>';
  1800. if (!isset($totalarray['val']['p.budget_amount'])) {
  1801. $totalarray['val']['p.budget_amount'] = $obj->budget_amount;
  1802. } else {
  1803. $totalarray['val']['p.budget_amount'] += $obj->budget_amount;
  1804. }
  1805. }
  1806. print '</td>';
  1807. if (!$i) {
  1808. $totalarray['nbfield']++;
  1809. $totalarray['pos'][$totalarray['nbfield']] = 'p.budget_amount';
  1810. }
  1811. }
  1812. // Usage opportunity
  1813. if (!empty($arrayfields['p.usage_opportunity']['checked'])) {
  1814. print '<td class="">';
  1815. if ($obj->usage_opportunity) {
  1816. print yn($obj->usage_opportunity);
  1817. }
  1818. print '</td>';
  1819. if (!$i) {
  1820. $totalarray['nbfield']++;
  1821. }
  1822. }
  1823. // Usage task
  1824. if (!empty($arrayfields['p.usage_task']['checked'])) {
  1825. print '<td class="">';
  1826. if ($obj->usage_task) {
  1827. print yn($obj->usage_task);
  1828. }
  1829. print '</td>';
  1830. if (!$i) {
  1831. $totalarray['nbfield']++;
  1832. }
  1833. }
  1834. // Bill time
  1835. if (!empty($arrayfields['p.usage_bill_time']['checked'])) {
  1836. print '<td class="">';
  1837. if ($obj->usage_bill_time) {
  1838. print yn($obj->usage_bill_time);
  1839. }
  1840. print '</td>';
  1841. if (!$i) {
  1842. $totalarray['nbfield']++;
  1843. }
  1844. }
  1845. // Event Organization
  1846. if (!empty($arrayfields['p.usage_organize_event']['checked'])) {
  1847. print '<td class="">';
  1848. if ($obj->usage_organize_event) {
  1849. print yn($obj->usage_organize_event);
  1850. }
  1851. print '</td>';
  1852. if (!$i) {
  1853. $totalarray['nbfield']++;
  1854. }
  1855. }
  1856. // Allow unknown people to suggest conferences
  1857. if (!empty($arrayfields['p.accept_conference_suggestions']['checked'])) {
  1858. print '<td class="">';
  1859. if ($obj->accept_conference_suggestions) {
  1860. print yn($obj->accept_conference_suggestions);
  1861. }
  1862. print '</td>';
  1863. if (!$i) {
  1864. $totalarray['nbfield']++;
  1865. }
  1866. }
  1867. // Allow unknown people to suggest booth
  1868. if (!empty($arrayfields['p.accept_booth_suggestions']['checked'])) {
  1869. print '<td class="">';
  1870. if ($obj->accept_booth_suggestions) {
  1871. print yn($obj->accept_booth_suggestions);
  1872. }
  1873. print '</td>';
  1874. if (!$i) {
  1875. $totalarray['nbfield']++;
  1876. }
  1877. }
  1878. // Price of registration
  1879. if (!empty($arrayfields['p.price_registration']['checked'])) {
  1880. print '<td class="right">';
  1881. if ($obj->price_registration != '') {
  1882. print '<span class="amount">'.price($obj->price_registration, 1, $langs, 1, -1, -1).'</span>';
  1883. $totalarray['val']['p.price_registration'] += $obj->price_registration;
  1884. }
  1885. print '</td>';
  1886. if (!$i) {
  1887. $totalarray['nbfield']++;
  1888. }
  1889. if (!$i) {
  1890. $totalarray['pos'][$totalarray['nbfield']] = 'p.price_registration';
  1891. }
  1892. }
  1893. // Price of booth
  1894. if (!empty($arrayfields['p.price_booth']['checked'])) {
  1895. print '<td class="right">';
  1896. if ($obj->price_booth != '') {
  1897. print '<span class="amount">'.price($obj->price_booth, 1, $langs, 1, -1, -1).'</span>';
  1898. $totalarray['val']['p.price_booth'] += $obj->price_booth;
  1899. }
  1900. print '</td>';
  1901. if (!$i) {
  1902. $totalarray['nbfield']++;
  1903. }
  1904. if (!$i) {
  1905. $totalarray['pos'][$totalarray['nbfield']] = 'p.price_booth';
  1906. }
  1907. }
  1908. // Author
  1909. if (!empty($arrayfields['u.login']['checked'])) {
  1910. print '<td class="center tdoverflowmax150">';
  1911. if ($userstatic->id) {
  1912. print $userstatic->getNomUrl(-1);
  1913. } else {
  1914. print '&nbsp;';
  1915. }
  1916. print "</td>\n";
  1917. if (!$i) {
  1918. $totalarray['nbfield']++;
  1919. }
  1920. }
  1921. // Extra fields
  1922. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1923. // Fields from hook
  1924. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1925. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1926. print $hookmanager->resPrint;
  1927. // Date creation
  1928. if (!empty($arrayfields['p.datec']['checked'])) {
  1929. print '<td class="center nowraponall">';
  1930. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  1931. print '</td>';
  1932. if (!$i) {
  1933. $totalarray['nbfield']++;
  1934. }
  1935. }
  1936. // Date modification
  1937. if (!empty($arrayfields['p.tms']['checked'])) {
  1938. print '<td class="center nowraponall">';
  1939. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  1940. print '</td>';
  1941. if (!$i) {
  1942. $totalarray['nbfield']++;
  1943. }
  1944. }
  1945. // Email MsgID
  1946. if (!empty($arrayfields['p.email_msgid']['checked'])) {
  1947. print '<td class="tdoverflowmax125" title="'.dol_escape_htmltag($obj->email_msgid).'">';
  1948. print dol_escape_htmltag($obj->email_msgid);
  1949. print '</td>';
  1950. if (!$i) {
  1951. $totalarray['nbfield']++;
  1952. }
  1953. }
  1954. // Import key
  1955. if (!empty($arrayfields['p.import_key']['checked'])) {
  1956. print '<td class="right">'.dol_escape_htmltag($obj->import_key).'</td>';
  1957. if (!$i) {
  1958. $totalarray['nbfield']++;
  1959. }
  1960. }
  1961. // Status
  1962. if (!empty($arrayfields['p.fk_statut']['checked'])) {
  1963. print '<td class="center">'.$object->getLibStatut(5).'</td>';
  1964. if (!$i) {
  1965. $totalarray['nbfield']++;
  1966. }
  1967. }
  1968. // Action column
  1969. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1970. print '<td class="nowrap center">';
  1971. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1972. $selected = 0;
  1973. if (in_array($object->id, $arrayofselected)) {
  1974. $selected = 1;
  1975. }
  1976. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  1977. }
  1978. print '</td>';
  1979. if (!$i) {
  1980. $totalarray['nbfield']++;
  1981. }
  1982. }
  1983. print '</tr>'."\n";
  1984. }
  1985. //}
  1986. $i++;
  1987. }
  1988. // Show total line
  1989. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  1990. // If no record found
  1991. if ($num == 0) {
  1992. $colspan = 1;
  1993. foreach ($arrayfields as $key => $val) {
  1994. if (!empty($val['checked'])) {
  1995. $colspan++;
  1996. }
  1997. }
  1998. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  1999. }
  2000. $db->free($resql);
  2001. $parameters = array('arrayfields'=>$arrayfields, 'sql' => $sql);
  2002. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  2003. print $hookmanager->resPrint;
  2004. print '</table>'."\n";
  2005. print '</div>'."\n";
  2006. print '</form>'."\n";
  2007. // End of page
  2008. llxFooter();
  2009. $db->close();