list.php 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2006-2019 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2006-2010 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
  6. * Copyright (C) 2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
  7. * Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/projet/tasks/list.php
  24. * \ingroup project
  25. * \brief List all tasks of a project
  26. */
  27. require "../../main.inc.php";
  28. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  33. // Load translation files required by the page
  34. $langs->loadLangs(array('projects', 'users', 'companies'));
  35. $action = GETPOST('action', 'aZ09');
  36. $massaction = GETPOST('massaction', 'alpha');
  37. $show_files = GETPOST('show_files', 'int');
  38. $confirm = GETPOST('confirm', 'alpha');
  39. $toselect = GETPOST('toselect', 'array');
  40. $optioncss = GETPOST('optioncss', 'aZ09');
  41. $mode = GETPOST('mode', 'aZ');
  42. $id = GETPOST('id', 'int');
  43. $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  44. $search_categ = GETPOST("search_categ", 'int');
  45. $search_projectstatus = GETPOST('search_projectstatus');
  46. if (!isset($search_projectstatus) || $search_projectstatus === '') {
  47. if ($search_all != '') {
  48. $search_projectstatus = -1;
  49. } else {
  50. $search_projectstatus = 1;
  51. }
  52. }
  53. $search_project_ref = GETPOST('search_project_ref');
  54. $search_project_title = GETPOST('search_project_title');
  55. $search_task_ref = GETPOST('search_task_ref');
  56. $search_task_label = GETPOST('search_task_label');
  57. $search_task_description = GETPOST('search_task_description');
  58. $search_task_ref_parent = GETPOST('search_task_ref_parent');
  59. $search_project_user = GETPOST('search_project_user', getDolGlobalInt('PROJECT_SEARCH_USER_MULTIPLE') ?'array:int' :'int');
  60. $search_project_user_multiple_and = getDolGlobalInt('PROJECT_SEARCH_USER_MULTIPLE_AND');
  61. $search_task_user = GETPOST('search_task_user', getDolGlobalInt('PROJECT_SEARCH_USER_MULTIPLE') ?'array:int' :'int');
  62. $search_task_user_multiple_and = getDolGlobalInt('PROJECT_SEARCH_USER_MULTIPLE_AND');
  63. $search_task_progress = GETPOST('search_task_progress');
  64. $search_task_budget_amount = GETPOST('search_task_budget_amount');
  65. $search_societe = GETPOST('search_societe');
  66. $search_societe_alias = GETPOST('search_societe_alias');
  67. $search_opp_status = GETPOST("search_opp_status", 'alpha');
  68. $searchCategoryCustomerOperator = 0;
  69. if (GETPOSTISSET('formfilteraction')) {
  70. $searchCategoryCustomerOperator = GETPOST('search_category_customer_operator', 'int');
  71. } elseif (getDolGlobalString('MAIN_SEARCH_CAT_OR_BY_DEFAULT')) {
  72. $searchCategoryCustomerOperator = $conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT;
  73. }
  74. $searchCategoryCustomerList = GETPOST('search_category_customer_list', 'array');
  75. $mine = GETPOST('mode', 'alpha') == 'mine' ? 1 : 0;
  76. if ($mine) {
  77. $search_task_user = $user->id;
  78. $mine = 0;
  79. }
  80. $type = GETPOST('type');
  81. $search_date_startday = GETPOST('search_date_startday', 'int');
  82. $search_date_startmonth = GETPOST('search_date_startmonth', 'int');
  83. $search_date_startyear = GETPOST('search_date_startyear', 'int');
  84. $search_date_endday = GETPOST('search_date_endday', 'int');
  85. $search_date_endmonth = GETPOST('search_date_endmonth', 'int');
  86. $search_date_endyear = GETPOST('search_date_endyear', 'int');
  87. $search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver
  88. $search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
  89. $search_datelimit_startday = GETPOST('search_datelimit_startday', 'int');
  90. $search_datelimit_startmonth = GETPOST('search_datelimit_startmonth', 'int');
  91. $search_datelimit_startyear = GETPOST('search_datelimit_startyear', 'int');
  92. $search_datelimit_endday = GETPOST('search_datelimit_endday', 'int');
  93. $search_datelimit_endmonth = GETPOST('search_datelimit_endmonth', 'int');
  94. $search_datelimit_endyear = GETPOST('search_datelimit_endyear', 'int');
  95. $search_datelimit_start = dol_mktime(0, 0, 0, $search_datelimit_startmonth, $search_datelimit_startday, $search_datelimit_startyear);
  96. $search_datelimit_end = dol_mktime(23, 59, 59, $search_datelimit_endmonth, $search_datelimit_endday, $search_datelimit_endyear);
  97. // Initialize context for list
  98. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'tasklist';
  99. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  100. $object = new Task($db);
  101. $hookmanager->initHooks(array('tasklist'));
  102. $extrafields = new ExtraFields($db);
  103. // fetch optionals attributes and labels
  104. $extrafields->fetch_name_optionals_label($object->table_element);
  105. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  106. // Security check
  107. $socid = 0;
  108. //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.
  109. if (!$user->hasRight('projet', 'lire')) {
  110. accessforbidden();
  111. }
  112. $diroutputmassaction = $conf->project->dir_output.'/tasks/temp/massgeneration/'.$user->id;
  113. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  114. $sortfield = GETPOST('sortfield', 'aZ09comma');
  115. $sortorder = GETPOST('sortorder', 'aZ09comma');
  116. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  117. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  118. // If $page is not defined, or '' or -1 or if we click on clear filters
  119. $page = 0;
  120. }
  121. $offset = $limit * $page;
  122. $pageprev = $page - 1;
  123. $pagenext = $page + 1;
  124. if (!$sortfield) {
  125. $sortfield = 'p.ref';
  126. }
  127. if (!$sortorder) {
  128. $sortorder = 'DESC';
  129. }
  130. // List of fields to search into when doing a "search in all"
  131. $fieldstosearchall = array(
  132. 't.ref'=>"Ref",
  133. 't.label'=>"Label",
  134. 't.description'=>"Description",
  135. 't.note_public'=>"NotePublic",
  136. );
  137. if (empty($user->socid)) {
  138. $fieldstosearchall['t.note_private'] = "NotePrivate";
  139. }
  140. $arrayfields = array(
  141. 't.fk_task_parent'=>array('label'=>"RefTaskParent", 'checked'=>0, 'position'=>70),
  142. 't.ref'=>array('label'=>"RefTask", 'checked'=>1, 'position'=>80),
  143. 't.label'=>array('label'=>"LabelTask", 'checked'=>1, 'position'=>80),
  144. 't.description'=>array('label'=>"Description", 'checked'=>0, 'position'=>80),
  145. 't.dateo'=>array('label'=>"DateStart", 'checked'=>1, 'position'=>100),
  146. 't.datee'=>array('label'=>"Deadline", 'checked'=>1, 'position'=>101),
  147. 'p.ref'=>array('label'=>"ProjectRef", 'checked'=>1, 'position'=>151),
  148. 'p.title'=>array('label'=>"ProjectLabel", 'checked'=>0, 'position'=>152),
  149. 's.nom'=>array('label'=>"ThirdParty", 'checked'=>1, 'csslist'=>'tdoverflowmax125', 'position'=>200),
  150. 's.name_alias'=>array('label'=>"AliasNameShort", 'checked'=>0, 'csslist'=>'tdoverflowmax125', 'position'=>201),
  151. 'p.fk_statut'=>array('label'=>"ProjectStatus", 'checked'=>1, 'position'=>205),
  152. 't.planned_workload'=>array('label'=>"PlannedWorkload", 'checked'=>1, 'position'=>302),
  153. 't.duration_effective'=>array('label'=>"TimeSpent", 'checked'=>1, 'position'=>303),
  154. 't.progress_calculated'=>array('label'=>"ProgressCalculated", 'checked'=>1, 'position'=>304),
  155. 't.progress'=>array('label'=>"ProgressDeclared", 'checked'=>1, 'position'=>305),
  156. 't.progress_summary'=>array('label'=>"TaskProgressSummary", 'checked'=>1, 'position'=>306),
  157. 't.budget_amount'=>array('label'=>"Budget", 'checked'=>0, 'position'=>307),
  158. 't.tobill'=>array('label'=>"TimeToBill", 'checked'=>0, 'position'=>310),
  159. 't.billed'=>array('label'=>"TimeBilled", 'checked'=>0, 'position'=>311),
  160. 't.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500),
  161. 't.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>501),
  162. //'t.fk_statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000),
  163. );
  164. // Extra fields
  165. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  166. $object->fields = dol_sort_array($object->fields, 'position');
  167. $arrayfields = dol_sort_array($arrayfields, 'position');
  168. $permissiontoread = $user->hasRight('projet', 'lire');
  169. $permissiontocreate = $user->hasRight('projet', 'creer');
  170. $permissiontodelete = $user->hasRight('projet', 'supprimer');
  171. if (!$permissiontoread) {
  172. accessforbidden();
  173. }
  174. /*
  175. * Actions
  176. */
  177. if (GETPOST('cancel', 'alpha')) {
  178. $action = 'list';
  179. $massaction = '';
  180. }
  181. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  182. $massaction = '';
  183. }
  184. $parameters = array('socid'=>$socid);
  185. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  186. if ($reshook < 0) {
  187. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  188. }
  189. if (empty($reshook)) {
  190. // Selection of new fields
  191. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  192. // Purge search criteria
  193. 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
  194. $search_all = "";
  195. $search_categ = "";
  196. $search_projectstatus = -1;
  197. $search_project_ref = "";
  198. $search_societe = "";
  199. $search_societe_alias = "";
  200. $search_project_title = "";
  201. $search_task_ref = "";
  202. $search_task_label = "";
  203. $search_task_description = "";
  204. $search_task_ref_parent = "";
  205. $search_task_progress = "";
  206. $search_task_budget_amount = "";
  207. $search_task_user = -1;
  208. $search_project_user = -1;
  209. $search_date_startday = '';
  210. $search_date_startmonth = '';
  211. $search_date_startyear = '';
  212. $search_date_endday = '';
  213. $search_date_endmonth = '';
  214. $search_date_endyear = '';
  215. $search_date_start = '';
  216. $search_date_end = '';
  217. $search_datelimit_startday = '';
  218. $search_datelimit_startmonth = '';
  219. $search_datelimit_startyear = '';
  220. $search_datelimit_endday = '';
  221. $search_datelimit_endmonth = '';
  222. $search_datelimit_endyear = '';
  223. $search_datelimit_start = '';
  224. $search_datelimit_end = '';
  225. $toselect = array();
  226. $searchCategoryCustomerList = array();
  227. $search_array_options = array();
  228. }
  229. // Mass actions
  230. $objectclass = 'Task';
  231. $objectlabel = 'Tasks';
  232. $uploaddir = $conf->project->dir_output.'/tasks';
  233. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  234. }
  235. if (empty($search_projectstatus) && $search_projectstatus == '') {
  236. $search_projectstatus = 1;
  237. }
  238. /*
  239. * View
  240. */
  241. $form = new Form($db);
  242. $formother = new FormOther($db);
  243. $socstatic = new Societe($db);
  244. $projectstatic = new Project($db);
  245. $puser = new User($db);
  246. $tuser = new User($db);
  247. $now = dol_now();
  248. $title = $langs->trans("Activities");
  249. $help_url = "EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
  250. $morejs = array();
  251. $morecss = array();
  252. if ($search_project_user > 0) {
  253. $puser->fetch($search_project_user);
  254. }
  255. if ($search_task_user > 0) {
  256. $tuser->fetch($search_task_user);
  257. }
  258. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  259. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
  260. if ($id) {
  261. $projectstatic->fetch($id);
  262. $projectstatic->fetch_thirdparty();
  263. }
  264. // Get list of project id allowed to user (in a string list separated by coma)
  265. if (!$user->hasRight('projet', 'all', 'lire')) {
  266. $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
  267. }
  268. //var_dump($projectsListId);
  269. // Get id of types of contacts for projects (This list never contains a lot of elements)
  270. $listofprojectcontacttype = array();
  271. $sql = "SELECT ctc.rowid, ctc.code FROM ".MAIN_DB_PREFIX."c_type_contact as ctc";
  272. $sql .= " WHERE ctc.element = '".$db->escape($projectstatic->element)."'";
  273. $sql .= " AND ctc.source = 'internal'";
  274. $resql = $db->query($sql);
  275. if ($resql) {
  276. while ($obj = $db->fetch_object($resql)) {
  277. $listofprojectcontacttype[$obj->rowid] = $obj->code;
  278. }
  279. } else {
  280. dol_print_error($db);
  281. }
  282. if (count($listofprojectcontacttype) == 0) {
  283. $listofprojectcontacttype[0] = '0'; // To avoid sql syntax error if not found
  284. }
  285. // Get id of types of contacts for tasks (This list never contains a lot of elements)
  286. $listoftaskcontacttype = array();
  287. $sql = "SELECT ctc.rowid, ctc.code FROM ".MAIN_DB_PREFIX."c_type_contact as ctc";
  288. $sql .= " WHERE ctc.element = '".$db->escape($object->element)."'";
  289. $sql .= " AND ctc.source = 'internal'";
  290. $resql = $db->query($sql);
  291. if ($resql) {
  292. while ($obj = $db->fetch_object($resql)) {
  293. $listoftaskcontacttype[$obj->rowid] = $obj->code;
  294. }
  295. } else {
  296. dol_print_error($db);
  297. }
  298. if (count($listoftaskcontacttype) == 0) {
  299. $listoftaskcontacttype[0] = '0'; // To avoid sql syntax error if not found
  300. }
  301. // Build and execute select
  302. // --------------------------------------------------------------------
  303. $distinct = 'DISTINCT'; // We add distinct until we are added a protection to be sure a contact of a project and task is assigned only once.
  304. $sql = "SELECT ".$distinct." p.rowid as projectid, p.ref as projectref, p.title as projecttitle, p.fk_statut as projectstatus, p.datee as projectdatee, p.fk_opp_status, p.public, p.fk_user_creat as projectusercreate, p.usage_bill_time,";
  305. $sql .= " s.nom as name, s.name_alias as alias, s.rowid as socid,";
  306. $sql .= " t.datec as date_creation, t.dateo as date_start, t.datee as date_end, t.tms as date_update,";
  307. $sql .= " t.rowid as id, t.ref, t.label, t.planned_workload, t.duration_effective, t.progress, t.fk_statut,";
  308. $sql .= " t.description, t.fk_task_parent";
  309. $sql .= " ,t.budget_amount";
  310. // Add sum fields
  311. if (!empty($arrayfields['t.tobill']['checked']) || !empty($arrayfields['t.billed']['checked'])) {
  312. $sql .= " , SUM(tt.element_duration * ".$db->ifsql("invoice_id IS NULL", "1", "0").") as tobill, SUM(tt.element_duration * ".$db->ifsql("invoice_id IS NULL", "0", "1").") as billed";
  313. }
  314. // Add fields from extrafields
  315. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  316. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  317. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  318. }
  319. }
  320. // Add fields from hooks
  321. $parameters = array();
  322. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  323. $sql .= $hookmanager->resPrint;
  324. $sql = preg_replace('/,\s*$/', '', $sql);
  325. $sqlfields = $sql; // $sql fields to remove for count total
  326. $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
  327. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
  328. $sql .= ", ".MAIN_DB_PREFIX."projet_task as t";
  329. if (!empty($arrayfields['t.tobill']['checked']) || !empty($arrayfields['t.billed']['checked'])) {
  330. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_time as tt ON (tt.fk_element = t.rowid AND tt.elementtype = 'task')";
  331. }
  332. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  333. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  334. }
  335. if (!empty($search_project_user)) {
  336. if ($search_project_user_multiple_and) {
  337. for ($i=0; $i<count($search_project_user); $i++) {
  338. $sql .= ", ".MAIN_DB_PREFIX."element_contact as ecp$i";
  339. }
  340. }
  341. else {
  342. $sql .= ", ".MAIN_DB_PREFIX."element_contact as ecp";
  343. }
  344. }
  345. if (!empty($search_task_user)) {
  346. if ($search_task_user_multiple_and) {
  347. for ($i=0; $i<count($search_task_user); $i++) {
  348. $sql .= ", ".MAIN_DB_PREFIX."element_contact as ect$i";
  349. }
  350. }
  351. else {
  352. $sql .= ", ".MAIN_DB_PREFIX."element_contact as ect";
  353. }
  354. }
  355. $sql .= " WHERE t.fk_projet = p.rowid";
  356. $sql .= " AND p.entity IN (".getEntity('project').')';
  357. if (!$user->hasRight('projet', 'all', 'lire')) {
  358. $sql .= " AND p.rowid IN (".$db->sanitize($projectsListId ? $projectsListId : '0').")"; // public and assigned to projects, or restricted to company for external users
  359. }
  360. if (is_object($projectstatic) && $projectstatic->id > 0) {
  361. $sql .= " AND p.rowid = ".((int) $projectstatic->id);
  362. }
  363. // No need to check company, as filtering of projects must be done by getProjectsAuthorizedForUser
  364. if ($socid) {
  365. $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")";
  366. }
  367. if ($search_project_ref) {
  368. $sql .= natural_search('p.ref', $search_project_ref);
  369. }
  370. if ($search_project_title) {
  371. $sql .= natural_search('p.title', $search_project_title);
  372. }
  373. if ($search_task_ref) {
  374. $sql .= natural_search('t.ref', $search_task_ref);
  375. }
  376. if ($search_task_label) {
  377. $sql .= natural_search('t.label', $search_task_label);
  378. }
  379. if ($search_task_description) {
  380. $sql .= natural_search('t.description', $search_task_description);
  381. }
  382. if ($search_task_ref_parent) {
  383. $sql .= ' AND t.fk_task_parent IN (SELECT ipt.rowid FROM '.MAIN_DB_PREFIX.'projet_task as ipt WHERE '.natural_search('ipt.ref', $search_task_ref_parent, 0, 1).')';
  384. }
  385. if ($search_task_progress) {
  386. $sql .= natural_search('t.progress', $search_task_progress, 1);
  387. }
  388. if ($search_task_budget_amount) {
  389. $sql .= natural_search('t.budget_amount', $search_task_budget_amount, 1);
  390. }
  391. if (empty($arrayfields['s.name_alias']['checked']) && $search_societe) {
  392. $sql .= natural_search(array("s.nom", "s.name_alias"), $search_societe);
  393. } else {
  394. if ($search_societe) {
  395. $sql .= natural_search('s.nom', $search_societe);
  396. }
  397. if ($search_societe_alias) {
  398. $sql .= natural_search('s.name_alias', $search_societe_alias);
  399. }
  400. }
  401. if ($search_date_start) {
  402. $sql .= " AND t.dateo >= '".$db->idate($search_date_start)."'";
  403. }
  404. if ($search_date_end) {
  405. $sql .= " AND t.dateo <= '".$db->idate($search_date_end)."'";
  406. }
  407. if ($search_datelimit_start) {
  408. $sql .= " AND t.datee >= '".$db->idate($search_datelimit_start)."'";
  409. }
  410. if ($search_datelimit_end) {
  411. $sql .= " AND t.datee <= '".$db->idate($search_datelimit_end)."'";
  412. }
  413. if ($search_all) {
  414. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  415. }
  416. if ($search_projectstatus >= 0) {
  417. if ($search_projectstatus == 99) {
  418. $sql .= " AND p.fk_statut <> 2";
  419. } else {
  420. $sql .= " AND p.fk_statut = ".((int) $search_projectstatus);
  421. }
  422. }
  423. if (!empty($search_project_user)) {
  424. if (is_array($search_project_user)) {
  425. if ($search_project_user_multiple_and) {
  426. foreach($search_project_user as $i=>$uid) {
  427. $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);
  428. }
  429. }
  430. else {
  431. $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).")";
  432. }
  433. }
  434. elseif ($search_project_user > 0) {
  435. // TODO Replace this with a EXISTS and remove the link to table + DISTINCT
  436. $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);
  437. }
  438. }
  439. if (!empty($search_task_user)) {
  440. if (is_array($search_task_user)) {
  441. if ($search_task_user_multiple_and) {
  442. foreach($search_task_user as $i=>$uid) {
  443. $sql .= " AND ect$i.fk_c_type_contact IN (".$db->sanitize(join(',', array_keys($listoftaskcontacttype))).") AND ect$i.element_id = t.rowid AND ect$i.fk_socpeople = ".((int) $uid);
  444. }
  445. }
  446. else {
  447. $sql .= " AND ect.fk_c_type_contact IN (".$db->sanitize(join(',', array_keys($listoftaskcontacttype))).") AND ect.element_id = t.rowid AND ect.fk_socpeople IN (".implode(',', $search_task_user).")";
  448. }
  449. }
  450. elseif ($search_task_user > 0) {
  451. $sql .= " AND ect.fk_c_type_contact IN (".$db->sanitize(join(',', array_keys($listoftaskcontacttype))).") AND ect.element_id = t.rowid AND ect.fk_socpeople = ".((int) $search_task_user);
  452. }
  453. }
  454. // Search for tag/category ($searchCategoryProjectList is an array of ID)
  455. $searchCategoryProjectList = array($search_categ);
  456. $searchCategoryProjectOperator = 0;
  457. if (!empty($searchCategoryProjectList)) {
  458. $searchCategoryProjectSqlList = array();
  459. $listofcategoryid = '';
  460. foreach ($searchCategoryProjectList as $searchCategoryProject) {
  461. if (intval($searchCategoryProject) == -2) {
  462. $searchCategoryProjectSqlList[] = "NOT EXISTS (SELECT ck.fk_project FROM ".MAIN_DB_PREFIX."categorie_project as ck WHERE p.rowid = ck.fk_project)";
  463. } elseif (intval($searchCategoryProject) > 0) {
  464. if ($searchCategoryProjectOperator == 0) {
  465. $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).")";
  466. } else {
  467. $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProject);
  468. }
  469. }
  470. }
  471. if ($listofcategoryid) {
  472. $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)."))";
  473. }
  474. if ($searchCategoryProjectOperator == 1) {
  475. if (!empty($searchCategoryProjectSqlList)) {
  476. $sql .= " AND (".implode(' OR ', $searchCategoryProjectSqlList).")";
  477. }
  478. } else {
  479. if (!empty($searchCategoryProjectSqlList)) {
  480. $sql .= " AND (".implode(' AND ', $searchCategoryProjectSqlList).")";
  481. }
  482. }
  483. }
  484. $searchCategoryCustomerSqlList = array();
  485. if ($searchCategoryCustomerOperator == 1) {
  486. $existsCategoryCustomerList = array();
  487. foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
  488. if (intval($searchCategoryCustomer) == -2) {
  489. $sqlCategoryCustomerNotExists = " NOT EXISTS (";
  490. $sqlCategoryCustomerNotExists .= " SELECT cat_cus.fk_soc";
  491. $sqlCategoryCustomerNotExists .= " FROM ".$db->prefix()."categorie_societe AS cat_cus";
  492. $sqlCategoryCustomerNotExists .= " WHERE cat_cus.fk_soc = p.fk_soc";
  493. $sqlCategoryCustomerNotExists .= " )";
  494. $searchCategoryCustomerSqlList[] = $sqlCategoryCustomerNotExists;
  495. } elseif (intval($searchCategoryCustomer) > 0) {
  496. $existsCategoryCustomerList[] = $db->escape($searchCategoryCustomer);
  497. }
  498. }
  499. if (!empty($existsCategoryCustomerList)) {
  500. $sqlCategoryCustomerExists = " EXISTS (";
  501. $sqlCategoryCustomerExists .= " SELECT cat_cus.fk_soc";
  502. $sqlCategoryCustomerExists .= " FROM ".$db->prefix()."categorie_societe AS cat_cus";
  503. $sqlCategoryCustomerExists .= " WHERE cat_cus.fk_soc = p.fk_soc";
  504. $sqlCategoryCustomerExists .= " AND cat_cus.fk_categorie IN (".$db->sanitize(implode(',', $existsCategoryCustomerList)).")";
  505. $sqlCategoryCustomerExists .= " )";
  506. $searchCategoryCustomerSqlList[] = $sqlCategoryCustomerExists;
  507. }
  508. if (!empty($searchCategoryCustomerSqlList)) {
  509. $sql .= " AND (".implode(' OR ', $searchCategoryCustomerSqlList).")";
  510. }
  511. } else {
  512. foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
  513. if (intval($searchCategoryCustomer) == -2) {
  514. $sqlCategoryCustomerNotExists = " NOT EXISTS (";
  515. $sqlCategoryCustomerNotExists .= " SELECT cat_cus.fk_soc";
  516. $sqlCategoryCustomerNotExists .= " FROM ".$db->prefix()."categorie_societe AS cat_cus";
  517. $sqlCategoryCustomerNotExists .= " WHERE cat_cus.fk_soc = p.fk_soc";
  518. $sqlCategoryCustomerNotExists .= " )";
  519. $searchCategoryCustomerSqlList[] = $sqlCategoryCustomerNotExists;
  520. } elseif (intval($searchCategoryCustomer) > 0) {
  521. $searchCategoryCustomerSqlList[] = "p.fk_soc IN (SELECT fk_soc FROM ".$db->prefix()."categorie_societe WHERE fk_categorie = ".((int) $searchCategoryCustomer).")";
  522. }
  523. }
  524. if (!empty($searchCategoryCustomerSqlList)) {
  525. $sql .= " AND (".implode(' AND ', $searchCategoryCustomerSqlList).")";
  526. }
  527. }
  528. // Add where from extra fields
  529. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  530. // Add where from hooks
  531. $parameters = array();
  532. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  533. $sql .= $hookmanager->resPrint;
  534. if (!empty($arrayfields['t.tobill']['checked']) || !empty($arrayfields['t.billed']['checked'])) {
  535. $sql .= " GROUP BY p.rowid, p.ref, p.title, p.fk_statut, p.datee, p.fk_opp_status, p.public, p.fk_user_creat,";
  536. $sql .= " s.nom, s.rowid,";
  537. $sql .= " t.datec, t.dateo, t.datee, t.tms,";
  538. $sql .= " t.rowid, t.ref, t.label, t.planned_workload, t.duration_effective, t.progress,t.budget_amount, t.fk_statut";
  539. // Add fields from extrafields
  540. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  541. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  542. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key : '');
  543. }
  544. }
  545. }
  546. // Count total nb of records
  547. $nbtotalofrecords = '';
  548. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  549. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  550. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  551. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  552. $resql = $db->query($sqlforcount);
  553. if ($resql) {
  554. $objforcount = $db->fetch_object($resql);
  555. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  556. } else {
  557. dol_print_error($db);
  558. }
  559. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
  560. $page = 0;
  561. $offset = 0;
  562. }
  563. $db->free($resql);
  564. }
  565. // Complete request and execute it with limit
  566. $sql .= $db->order($sortfield, $sortorder);
  567. if ($limit) {
  568. $sql .= $db->plimit($limit + 1, $offset);
  569. }
  570. //echo '<pre>'.$sql.'</pre>'; die();
  571. $resql = $db->query($sql);
  572. if (!$resql) {
  573. dol_print_error($db);
  574. exit;
  575. }
  576. $num = $db->num_rows($resql);
  577. // Direct jump if only one record found
  578. if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all) {
  579. $obj = $db->fetch_object($resql);
  580. $id = $obj->id; // in select, task id has been aliases into 'id'
  581. header("Location: ".DOL_URL_ROOT.'/projet/tasks/task.php?id='.$id.'&withproject=1');
  582. exit;
  583. }
  584. // Output page
  585. // --------------------------------------------------------------------
  586. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist'); // Can use also classforhorizontalscrolloftabs instead of bodyforlist for no horizontal scroll
  587. $arrayofselected = is_array($toselect) ? $toselect : array();
  588. $param = '';
  589. if (!empty($mode)) {
  590. $param .= '&mode='.urlencode($mode);
  591. }
  592. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  593. $param .= '&contextpage='.urlencode($contextpage);
  594. }
  595. if ($limit > 0 && $limit != $conf->liste_limit) {
  596. $param .= '&limit='.((int) $limit);
  597. }
  598. if ($search_date_startday) {
  599. $param .= '&search_date_startday='.urlencode($search_date_startday);
  600. }
  601. if ($search_date_startmonth) {
  602. $param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
  603. }
  604. if ($search_date_startyear) {
  605. $param .= '&search_date_startyear='.urlencode($search_date_startyear);
  606. }
  607. if ($search_date_endday) {
  608. $param .= '&search_date_endday='.urlencode($search_date_endday);
  609. }
  610. if ($search_date_endmonth) {
  611. $param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
  612. }
  613. if ($search_date_endyear) {
  614. $param .= '&search_date_endyear='.urlencode($search_date_endyear);
  615. }
  616. if ($search_datelimit_startday) {
  617. $param .= '&search_datelimit_startday='.urlencode($search_datelimit_startday);
  618. }
  619. if ($search_datelimit_startmonth) {
  620. $param .= '&search_datelimit_startmonth='.urlencode($search_datelimit_startmonth);
  621. }
  622. if ($search_datelimit_startyear) {
  623. $param .= '&search_datelimit_startyear='.urlencode($search_datelimit_startyear);
  624. }
  625. if ($search_datelimit_endday) {
  626. $param .= '&search_datelimit_endday='.urlencode($search_datelimit_endday);
  627. }
  628. if ($search_datelimit_endmonth) {
  629. $param .= '&search_datelimit_endmonth='.urlencode($search_datelimit_endmonth);
  630. }
  631. if ($search_datelimit_endyear) {
  632. $param .= '&search_datelimit_endyear='.urlencode($search_datelimit_endyear);
  633. }
  634. if ($search_task_budget_amount) {
  635. $param .= '&search_task_budget_amount='.urlencode($search_task_budget_amount);
  636. }
  637. if ($socid) {
  638. $param .= '&socid='.urlencode($socid);
  639. }
  640. if ($search_all != '') {
  641. $param .= '&search_all='.urlencode($search_all);
  642. }
  643. if ($search_project_ref != '') {
  644. $param .= '&search_project_ref='.urlencode($search_project_ref);
  645. }
  646. if ($search_project_title != '') {
  647. $param .= '&search_project_title='.urlencode($search_project_title);
  648. }
  649. if ($search_task_ref != '') {
  650. $param .= '&search_task_ref='.urlencode($search_task_ref);
  651. }
  652. if ($search_task_label != '') {
  653. $param .= '&search_task_label='.urlencode($search_task_label);
  654. }
  655. if ($search_task_description != '') {
  656. $param .= '&search_task_description='.urlencode($search_task_description);
  657. }
  658. if ($search_task_ref_parent != '') {
  659. $param .= '&search_task_ref_parent='.urlencode($search_task_ref_parent);
  660. }
  661. if ($search_task_progress != '') {
  662. $param .= '&search_task_progress='.urlencode($search_task_progress);
  663. }
  664. if ($search_societe != '') {
  665. $param .= '&search_societe='.urlencode($search_societe);
  666. }
  667. if ($search_societe != '') {
  668. $param .= '&search_societe_alias='.urlencode($search_societe_alias);
  669. }
  670. if ($search_projectstatus != '') {
  671. $param .= '&search_projectstatus='.urlencode($search_projectstatus);
  672. }
  673. if ((is_numeric($search_opp_status) && $search_opp_status >= 0) || in_array($search_opp_status, array('all', 'none'))) {
  674. $param .= '&search_opp_status='.urlencode($search_opp_status);
  675. }
  676. if (!empty($search_project_user)) {
  677. if (is_array($search_project_user)) {
  678. foreach($search_project_user as $uid)
  679. $param .= '&search_project_user[]='.urlencode($uid);
  680. }
  681. elseif ($search_project_user > 0) {
  682. $param .= '&search_project_user='.urlencode($search_project_user);
  683. }
  684. }
  685. if (!empty($search_task_user)) {
  686. if (is_array($search_task_user)) {
  687. foreach($search_task_user as $uid)
  688. $param .= '&search_task_user[]='.urlencode($uid);
  689. }
  690. elseif ($search_task_user > 0) {
  691. $param .= '&search_task_user='.urlencode($search_task_user);
  692. }
  693. }
  694. if ($optioncss != '') {
  695. $param .= '&optioncss='.urlencode($optioncss);
  696. }
  697. foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
  698. $param .= "&search_category_customer_list[]=".urlencode($searchCategoryCustomer);
  699. }
  700. // Add $param from extra fields
  701. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  702. // Add $param from hooks
  703. $parameters = array('param' => &$param);
  704. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  705. $param .= $hookmanager->resPrint;
  706. // List of mass actions available
  707. $arrayofmassactions = array(
  708. // 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  709. // 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  710. );
  711. //if($user->rights->societe->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
  712. if (!empty($permissiontodelete)) {
  713. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  714. }
  715. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  716. $arrayofmassactions = array();
  717. }
  718. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  719. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  720. if ($optioncss != '') {
  721. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  722. }
  723. print '<input type="hidden" name="token" value="'.newToken().'">';
  724. print '<input type="hidden" name="action" value="list">';
  725. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  726. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  727. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  728. print '<input type="hidden" name="page" value="'.$page.'">';
  729. if (!empty($type)) {
  730. print '<input type="hidden" name="type" value="'.$type.'">';
  731. }
  732. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  733. print '<input type="hidden" name="page_y" value="">';
  734. print '<input type="hidden" name="mode" value="'.$mode.'">';
  735. $newcardbutton = '';
  736. $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'));
  737. $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'));
  738. $newcardbutton .= dolGetButtonTitleSeparator();
  739. $newcardbutton .= dolGetButtonTitle($langs->trans('NewTask'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/projet/tasks.php?action=create', '', $permissiontocreate);
  740. // Show description of content
  741. $texthelp = '';
  742. if ($search_task_user == $user->id) {
  743. $texthelp .= $langs->trans("MyTasksDesc");
  744. } else {
  745. if ($user->hasRight('projet', 'all', 'lire') && !$socid) {
  746. $texthelp .= $langs->trans("TasksOnProjectsDesc");
  747. } else {
  748. $texthelp .= $langs->trans("TasksOnProjectsPublicDesc");
  749. }
  750. }
  751. print_barre_liste($form->textwithpicto($title, $texthelp), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'projecttask', 0, $newcardbutton, '', $limit, 0, 0, 1);
  752. $topicmail = "Information";
  753. $modelmail = "task";
  754. $objecttmp = new Task($db);
  755. $trackid = 'tas'.$object->id;
  756. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  757. if ($search_all) {
  758. $setupstring = '';
  759. foreach ($fieldstosearchall as $key => $val) {
  760. $fieldstosearchall[$key] = $langs->trans($val);
  761. $setupstring .= $key."=".$val.";";
  762. }
  763. print '<!-- Search done like if TASK_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
  764. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>'."\n";
  765. }
  766. $moreforfilter = '';
  767. // Filter on categories
  768. if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire')) {
  769. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  770. $moreforfilter .= '<div class="divsearchfield">';
  771. $tmptitle = $langs->trans('ProjectCategories');
  772. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('project', $search_categ, 'search_categ', 1, $tmptitle, 'maxwidth300');
  773. $moreforfilter .= '</div>';
  774. }
  775. // If the user can view users
  776. $moreforfilter .= '<div class="divsearchfield">';
  777. $tmptitle = $langs->trans('ProjectsWithThisUserAsContact');
  778. $includeonly = '';
  779. if (!$user->hasRight('user', 'user', 'lire')) {
  780. $includeonly = array($user->id);
  781. }
  782. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_project_user ? $search_project_user : '', 'search_project_user', $tmptitle, '', 0, $includeonly, '', 0, 0, 0, '', 0, '', 'maxwidth250', 0, 0, getDolGlobalInt('PROJECT_SEARCH_USER_MULTIPLE'));
  783. $moreforfilter .= '</div>';
  784. // If the user can view users
  785. $moreforfilter .= '<div class="divsearchfield">';
  786. $tmptitle = $langs->trans('TasksWithThisUserAsContact');
  787. $includeonly = '';
  788. if (!$user->hasRight('user', 'user', 'lire')) {
  789. $includeonly = array($user->id);
  790. }
  791. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_task_user, 'search_task_user', $tmptitle, '', 0, $includeonly, '', 0, 0, 0, '', 0, '', 'maxwidth250', 0, 0, getDolGlobalInt('PROJECT_SEARCH_USER_MULTIPLE'));
  792. $moreforfilter .= '</div>';
  793. // Filter on customer categories
  794. if (getDolGlobalString('MAIN_SEARCH_CATEGORY_CUSTOMER_ON_TASK_LIST') && isModEnabled("categorie") && $user->hasRight('categorie', 'lire')) {
  795. $moreforfilter .= '<div class="divsearchfield">';
  796. $tmptitle = $langs->transnoentities('CustomersProspectsCategoriesShort');
  797. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
  798. $categoriesArr = $form->select_all_categories(Categorie::TYPE_CUSTOMER, '', '', 64, 0, 1);
  799. $categoriesArr[-2] = '- '.$langs->trans('NotCategorized').' -';
  800. $moreforfilter .= Form::multiselectarray('search_category_customer_list', $categoriesArr, $searchCategoryCustomerList, 0, 0, 'minwidth300', 0, 0, '', 'category', $tmptitle);
  801. $moreforfilter .= ' <input type="checkbox" class="valignmiddle" id="search_category_customer_operator" name="search_category_customer_operator" value="1"'.($searchCategoryCustomerOperator == 1 ? ' checked="checked"' : '').'/>';
  802. $moreforfilter .= $form->textwithpicto('', $langs->trans('UseOrOperatorForCategories') . ' : ' . $tmptitle, 1, 'help', '', 0, 2, 'tooltip_cat_cus'); // Tooltip on click
  803. $moreforfilter .= '</div>';
  804. }
  805. if (!empty($moreforfilter)) {
  806. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  807. print $moreforfilter;
  808. $parameters = array();
  809. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  810. print $hookmanager->resPrint;
  811. print '</div>';
  812. }
  813. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  814. $selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields
  815. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  816. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  817. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'" id="tablelines3">'."\n";
  818. // Fields title search
  819. // --------------------------------------------------------------------
  820. print '<tr class="liste_titre_filter">';
  821. // Action column
  822. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  823. print '<td class="liste_titre center maxwidthsearch">';
  824. $searchpicto = $form->showFilterButtons('left');
  825. print $searchpicto;
  826. print '</td>';
  827. }
  828. if (!empty($arrayfields['t.fk_task_parent']['checked'])) {
  829. print '<td class="liste_titre">';
  830. print '<input type="text" class="flat" name="search_task_ref_parent" value="'.dol_escape_htmltag($search_task_ref_parent).'" size="4">';
  831. print '</td>';
  832. }
  833. if (!empty($arrayfields['t.ref']['checked'])) {
  834. print '<td class="liste_titre">';
  835. print '<input type="text" class="flat" name="search_task_ref" value="'.dol_escape_htmltag($search_task_ref).'" size="4">';
  836. print '</td>';
  837. }
  838. if (!empty($arrayfields['t.label']['checked'])) {
  839. print '<td class="liste_titre">';
  840. print '<input type="text" class="flat" name="search_task_label" value="'.dol_escape_htmltag($search_task_label).'" size="8">';
  841. print '</td>';
  842. }
  843. // Task Description
  844. if (!empty($arrayfields['t.description']['checked'])) {
  845. print '<td class="liste_titre">';
  846. print '<input type="text" class="flat" name="search_task_description" value="'.dol_escape_htmltag($search_task_description).'" size="8">';
  847. print '</td>';
  848. }
  849. // Start date
  850. if (!empty($arrayfields['t.dateo']['checked'])) {
  851. print '<td class="liste_titre center">';
  852. print '<div class="nowrapfordate">';
  853. print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  854. print '</div>';
  855. print '<div class="nowrapfordate">';
  856. print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  857. print '</div>';
  858. print '</td>';
  859. }
  860. // End date
  861. if (!empty($arrayfields['t.datee']['checked'])) {
  862. print '<td class="liste_titre center">';
  863. print '<div class="nowrapfordate">';
  864. print $form->selectDate($search_datelimit_start ? $search_datelimit_start : -1, 'search_datelimit_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  865. print '</div>';
  866. print '<div class="nowrapfordate">';
  867. print $form->selectDate($search_datelimit_end ? $search_datelimit_end : -1, 'search_datelimit_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  868. // TODO Add option late
  869. //print '<br><input type="checkbox" name="search_option" value="late"'.($option == 'late' ? ' checked' : '').'> '.$langs->trans("Alert");
  870. print '</div>';
  871. print '</td>';
  872. }
  873. if (!empty($arrayfields['p.ref']['checked'])) {
  874. print '<td class="liste_titre">';
  875. print '<input type="text" class="flat" name="search_project_ref" value="'.$search_project_ref.'" size="4">';
  876. print '</td>';
  877. }
  878. if (!empty($arrayfields['p.title']['checked'])) {
  879. print '<td class="liste_titre">';
  880. print '<input type="text" class="flat" name="search_project_title" value="'.$search_project_title.'" size="6">';
  881. print '</td>';
  882. }
  883. if (!empty($arrayfields['s.nom']['checked'])) {
  884. print '<td class="liste_titre">';
  885. print '<input type="text" class="flat" name="search_societe" value="'.dol_escape_htmltag($search_societe).'" size="4">';
  886. print '</td>';
  887. }
  888. if (!empty($arrayfields['s.name_alias']['checked'])) {
  889. print '<td class="liste_titre">';
  890. print '<input type="text" class="flat" name="search_societe_alias" value="'.dol_escape_htmltag($search_societe_alias).'" size="4">';
  891. print '</td>';
  892. }
  893. if (!empty($arrayfields['p.fk_statut']['checked'])) {
  894. print '<td class="liste_titre center">';
  895. $arrayofstatus = array();
  896. foreach ($projectstatic->labelStatusShort as $key => $val) {
  897. $arrayofstatus[$key] = $langs->trans($val);
  898. }
  899. $arrayofstatus['99'] = $langs->trans("NotClosed").' ('.$langs->trans('Draft').'+'.$langs->trans('Opened').')';
  900. print $form->selectarray('search_projectstatus', $arrayofstatus, $search_projectstatus, 1, 0, 0, '', 0, 0, 0, '', 'maxwidth100');
  901. print '</td>';
  902. }
  903. if (!empty($arrayfields['t.planned_workload']['checked'])) {
  904. print '<td class="liste_titre"></td>';
  905. }
  906. if (!empty($arrayfields['t.duration_effective']['checked'])) {
  907. print '<td class="liste_titre"></td>';
  908. }
  909. if (!empty($arrayfields['t.progress_calculated']['checked'])) {
  910. print '<td class="liste_titre"></td>';
  911. }
  912. if (!empty($arrayfields['t.progress']['checked'])) {
  913. print '<td class="liste_titre center">';
  914. print '<input type="text" class="flat" name="search_task_progress" value="'.$search_task_progress.'" size="4">';
  915. print '</td>';
  916. }
  917. if (!empty($arrayfields['t.progress_summary']['checked'])) {
  918. print '<td class="liste_titre"></td>';
  919. }
  920. if (!empty($arrayfields['t.budget_amount']['checked'])) {
  921. print '<td class="liste_titre center">';
  922. print '<input type="text" class="flat" name="search_task_budget_amount" value="'.$search_task_budget_amount.'" size="4">';
  923. print '</td>';
  924. }
  925. if (!empty($arrayfields['t.tobill']['checked'])) {
  926. print '<td class="liste_titre"></td>';
  927. }
  928. if (!empty($arrayfields['t.billed']['checked'])) {
  929. print '<td class="liste_titre"></td>';
  930. }
  931. // Extra fields
  932. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  933. // Fields from hook
  934. $parameters = array('arrayfields'=>$arrayfields);
  935. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  936. print $hookmanager->resPrint;
  937. if (!empty($arrayfields['t.datec']['checked'])) {
  938. // Date creation
  939. print '<td class="liste_titre">';
  940. print '</td>';
  941. }
  942. if (!empty($arrayfields['t.tms']['checked'])) {
  943. // Date modification
  944. print '<td class="liste_titre">';
  945. print '</td>';
  946. }
  947. // Action column
  948. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  949. print '<td class="liste_titre center maxwidthsearch">';
  950. $searchpicto = $form->showFilterButtons();
  951. print $searchpicto;
  952. print '</td>';
  953. }
  954. print '</tr>'."\n";
  955. $totalarray = array(
  956. 'nbfield' => 0,
  957. 'val' => array(
  958. 't.planned_workload' => 0,
  959. 't.duration_effective' => 0,
  960. 't.progress' => 0,
  961. 't.budget_amount' => 0,
  962. ),
  963. 'totalplannedworkload' => 0,
  964. 'totaldurationeffective' => 0,
  965. 'totaldurationdeclared' => 0,
  966. 'totaltobillfield' => 0,
  967. 'totalbilledfield' => 0,
  968. 'totalbudget_amountfield' => 0,
  969. 'totalbudgetamount' => 0,
  970. 'totaltobill' => 0,
  971. 'totalbilled' => 0,
  972. );
  973. // Fields title label
  974. // --------------------------------------------------------------------
  975. print '<tr class="liste_titre">';
  976. // Action column
  977. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  978. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  979. $totalarray['nbfield']++;
  980. }
  981. if (!empty($arrayfields['t.fk_task_parent']['checked'])) {
  982. print_liste_field_titre($arrayfields['t.fk_task_parent']['label'], $_SERVER["PHP_SELF"], "t.fk_task_parent", "", $param, "", $sortfield, $sortorder);
  983. $totalarray['nbfield']++;
  984. }
  985. if (!empty($arrayfields['t.ref']['checked'])) {
  986. print_liste_field_titre($arrayfields['t.ref']['label'], $_SERVER["PHP_SELF"], "t.ref", "", $param, "", $sortfield, $sortorder);
  987. $totalarray['nbfield']++;
  988. }
  989. if (!empty($arrayfields['t.label']['checked'])) {
  990. print_liste_field_titre($arrayfields['t.label']['label'], $_SERVER["PHP_SELF"], "t.label", "", $param, "", $sortfield, $sortorder);
  991. $totalarray['nbfield']++;
  992. }
  993. if (!empty($arrayfields['t.description']['checked'])) {
  994. print_liste_field_titre($arrayfields['t.description']['label'], $_SERVER["PHP_SELF"], "t.description", "", $param, "", $sortfield, $sortorder);
  995. $totalarray['nbfield']++;
  996. }
  997. if (!empty($arrayfields['t.dateo']['checked'])) {
  998. print_liste_field_titre($arrayfields['t.dateo']['label'], $_SERVER["PHP_SELF"], "t.dateo", "", $param, '', $sortfield, $sortorder, 'center ');
  999. $totalarray['nbfield']++;
  1000. }
  1001. if (!empty($arrayfields['t.datee']['checked'])) {
  1002. print_liste_field_titre($arrayfields['t.datee']['label'], $_SERVER["PHP_SELF"], "t.datee", "", $param, '', $sortfield, $sortorder, 'center ');
  1003. $totalarray['nbfield']++;
  1004. }
  1005. if (!empty($arrayfields['p.ref']['checked'])) {
  1006. print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, "", $sortfield, $sortorder);
  1007. $totalarray['nbfield']++;
  1008. }
  1009. if (!empty($arrayfields['p.title']['checked'])) {
  1010. print_liste_field_titre($arrayfields['p.title']['label'], $_SERVER["PHP_SELF"], "p.title", "", $param, "", $sortfield, $sortorder);
  1011. $totalarray['nbfield']++;
  1012. }
  1013. if (!empty($arrayfields['s.nom']['checked'])) {
  1014. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, "", $sortfield, $sortorder);
  1015. $totalarray['nbfield']++;
  1016. }
  1017. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1018. print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER["PHP_SELF"], "s.name_alias", "", $param, "", $sortfield, $sortorder);
  1019. $totalarray['nbfield']++;
  1020. }
  1021. if (!empty($arrayfields['p.fk_statut']['checked'])) {
  1022. print_liste_field_titre($arrayfields['p.fk_statut']['label'], $_SERVER["PHP_SELF"], "p.fk_statut", "", $param, '', $sortfield, $sortorder, 'center ');
  1023. $totalarray['nbfield']++;
  1024. }
  1025. if (!empty($arrayfields['t.planned_workload']['checked'])) {
  1026. print_liste_field_titre($arrayfields['t.planned_workload']['label'], $_SERVER["PHP_SELF"], "t.planned_workload", "", $param, '', $sortfield, $sortorder, 'center ');
  1027. $totalarray['nbfield']++;
  1028. }
  1029. if (!empty($arrayfields['t.duration_effective']['checked'])) {
  1030. print_liste_field_titre($arrayfields['t.duration_effective']['label'], $_SERVER["PHP_SELF"], "t.duration_effective", "", $param, '', $sortfield, $sortorder, 'center ');
  1031. $totalarray['nbfield']++;
  1032. }
  1033. if (!empty($arrayfields['t.progress_calculated']['checked'])) {
  1034. print_liste_field_titre($arrayfields['t.progress_calculated']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', '', '', 'center ');
  1035. $totalarray['nbfield']++;
  1036. }
  1037. if (!empty($arrayfields['t.progress']['checked'])) {
  1038. print_liste_field_titre($arrayfields['t.progress']['label'], $_SERVER["PHP_SELF"], "t.progress", "", $param, '', $sortfield, $sortorder, 'center ');
  1039. $totalarray['nbfield']++;
  1040. }
  1041. if (!empty($arrayfields['t.progress_summary']['checked'])) {
  1042. print_liste_field_titre($arrayfields['t.progress_summary']['label'], $_SERVER["PHP_SELF"], "t.progress", "", $param, '', $sortfield, $sortorder, 'center ');
  1043. $totalarray['nbfield']++;
  1044. }
  1045. if (!empty($arrayfields['t.budget_amount']['checked'])) {
  1046. print_liste_field_titre($arrayfields['t.budget_amount']['label'], $_SERVER["PHP_SELF"], "t.budget_amount", "", $param, '', $sortfield, $sortorder, 'center ');
  1047. $totalarray['nbfield']++;
  1048. }
  1049. if (!empty($arrayfields['t.tobill']['checked'])) {
  1050. print_liste_field_titre($arrayfields['t.tobill']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'center ');
  1051. $totalarray['nbfield']++;
  1052. }
  1053. if (!empty($arrayfields['t.billed']['checked'])) {
  1054. print_liste_field_titre($arrayfields['t.billed']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'center ');
  1055. $totalarray['nbfield']++;
  1056. }
  1057. // Extra fields
  1058. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1059. // Hook fields
  1060. $parameters = array(
  1061. 'arrayfields' => $arrayfields,
  1062. 'param' => $param,
  1063. 'sortfield' => $sortfield,
  1064. 'sortorder' => $sortorder,
  1065. 'totalarray' => &$totalarray,
  1066. );
  1067. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  1068. print $hookmanager->resPrint;
  1069. if (!empty($arrayfields['t.datec']['checked'])) {
  1070. print_liste_field_titre($arrayfields['t.datec']['label'], $_SERVER["PHP_SELF"], "t.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1071. $totalarray['nbfield']++;
  1072. }
  1073. if (!empty($arrayfields['t.tms']['checked'])) {
  1074. print_liste_field_titre($arrayfields['t.tms']['label'], $_SERVER["PHP_SELF"], "t.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1075. $totalarray['nbfield']++;
  1076. }
  1077. // Action column
  1078. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1079. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  1080. $totalarray['nbfield']++;
  1081. }
  1082. print '</tr>'."\n";
  1083. $plannedworkloadoutputformat = 'allhourmin';
  1084. $timespentoutputformat = 'allhourmin';
  1085. if (getDolGlobalString('PROJECT_PLANNED_WORKLOAD_FORMAT')) {
  1086. $plannedworkloadoutputformat = $conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT;
  1087. }
  1088. if (getDolGlobalString('PROJECT_TIMES_SPENT_FORMAT')) {
  1089. $timespentoutputformat = $conf->global->PROJECT_TIME_SPENT_FORMAT;
  1090. }
  1091. // Loop on record
  1092. // --------------------------------------------------------------------
  1093. $i = 0;
  1094. $savnbfield = $totalarray['nbfield'];
  1095. $totalarray = array();
  1096. $totalarray['nbfield'] = 0;
  1097. $imaxinloop = ($limit ? min($num, $limit) : $num);
  1098. while ($i < $imaxinloop) {
  1099. $obj = $db->fetch_object($resql);
  1100. if (empty($obj)) {
  1101. break; // Should not happen
  1102. }
  1103. // Store properties in $object
  1104. $object->id = $obj->id;
  1105. $object->ref = $obj->ref;
  1106. $object->label = $obj->label;
  1107. $object->description = $obj->description;
  1108. $object->fk_statut = $obj->fk_statut;
  1109. $object->progress = $obj->progress;
  1110. $object->budget_amount = $obj->budget_amount;
  1111. $object->date_start = $db->jdate($obj->date_start);
  1112. $object->date_end = $db->jdate($obj->date_end);
  1113. $object->planned_workload = $obj->planned_workload;
  1114. $object->duration_effective = $obj->duration_effective;
  1115. $object->fk_task_parent = $obj->fk_task_parent;
  1116. $projectstatic->id = $obj->projectid;
  1117. $projectstatic->ref = $obj->projectref;
  1118. $projectstatic->title = $obj->projecttitle;
  1119. $projectstatic->public = $obj->public;
  1120. $projectstatic->statut = $obj->projectstatus;
  1121. $projectstatic->datee = $db->jdate($obj->projectdatee);
  1122. if ($obj->socid) {
  1123. $socstatic->id = $obj->socid;
  1124. $socstatic->name = $obj->name;
  1125. $socstatic->name_alias = $obj->alias;
  1126. }
  1127. if ($mode == 'kanban') {
  1128. if ($i == 0) {
  1129. print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
  1130. print '<div class="box-flex-container kanban">';
  1131. }
  1132. // Output Kanban
  1133. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1134. $selected = 0;
  1135. if (in_array($object->id, $arrayofselected)) {
  1136. $selected = 1;
  1137. }
  1138. }
  1139. $arraydata = array();
  1140. $arraydata['projectlink'] = $projectstatic->getNomUrl(1);
  1141. $arraydata['selected'] = in_array($object->id, $arrayofselected);
  1142. print $object->getKanbanView('', $arraydata);
  1143. if ($i == ($imaxinloop - 1)) {
  1144. print '</div>';
  1145. print '</td></tr>';
  1146. }
  1147. } else {
  1148. $userAccess = $projectstatic->restrictedProjectArea($user); // why this ?
  1149. if ($userAccess >= 0) {
  1150. // Show here line of result
  1151. $j = 0;
  1152. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  1153. // Action column
  1154. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1155. print '<td class="nowrap center">';
  1156. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1157. $selected = 0;
  1158. if (in_array($object->id, $arrayofselected)) {
  1159. $selected = 1;
  1160. }
  1161. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  1162. }
  1163. print '</td>';
  1164. if (!$i) {
  1165. $totalarray['nbfield']++;
  1166. }
  1167. }
  1168. // Ref Parent
  1169. if (!empty($arrayfields['t.fk_task_parent']['checked'])) {
  1170. print '<td class="nowraponall">';
  1171. if (!empty($object->fk_task_parent)) {
  1172. $object_parent = new Task($db);
  1173. $result = $object_parent->fetch($object->fk_task_parent);
  1174. if ($result < 0) {
  1175. setEventMessage($object_parent->error, 'errors');
  1176. } else {
  1177. print $object_parent->getNomUrl(1, 'withproject');
  1178. if ($object_parent->hasDelay()) {
  1179. print img_warning("Late");
  1180. }
  1181. }
  1182. }
  1183. print '</td>';
  1184. if (!$i) {
  1185. $totalarray['nbfield']++;
  1186. }
  1187. }
  1188. // Ref
  1189. if (!empty($arrayfields['t.ref']['checked'])) {
  1190. print '<td class="nowraponall">';
  1191. print $object->getNomUrl(1, 'withproject');
  1192. if ($object->hasDelay()) {
  1193. print img_warning("Late");
  1194. }
  1195. print '</td>';
  1196. if (!$i) {
  1197. $totalarray['nbfield']++;
  1198. }
  1199. }
  1200. // Label
  1201. if (!empty($arrayfields['t.label']['checked'])) {
  1202. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($object->label).'">';
  1203. print dol_escape_htmltag($object->label);
  1204. print '</td>';
  1205. if (!$i) {
  1206. $totalarray['nbfield']++;
  1207. }
  1208. }
  1209. // Description
  1210. if (!empty($arrayfields['t.description']['checked'])) {
  1211. print '<td>';
  1212. print dolGetFirstLineOfText($object->description, 5);
  1213. print '</td>';
  1214. if (!$i) {
  1215. $totalarray['nbfield']++;
  1216. }
  1217. }
  1218. // Date start project
  1219. if (!empty($arrayfields['t.dateo']['checked'])) {
  1220. print '<td class="center">';
  1221. print dol_print_date($db->jdate($obj->date_start), 'day');
  1222. print '</td>';
  1223. if (!$i) {
  1224. $totalarray['nbfield']++;
  1225. }
  1226. }
  1227. // Date end project
  1228. if (!empty($arrayfields['t.datee']['checked'])) {
  1229. print '<td class="center">';
  1230. print dol_print_date($db->jdate($obj->date_end), 'day');
  1231. print '</td>';
  1232. if (!$i) {
  1233. $totalarray['nbfield']++;
  1234. }
  1235. }
  1236. // Project ref
  1237. if (!empty($arrayfields['p.ref']['checked'])) {
  1238. print '<td class="nowraponall tdoverflowmax150">';
  1239. print $projectstatic->getNomUrl(1, 'task');
  1240. if ($projectstatic->hasDelay()) {
  1241. print img_warning("Late");
  1242. }
  1243. print '</td>';
  1244. if (!$i) {
  1245. $totalarray['nbfield']++;
  1246. }
  1247. }
  1248. // Project title
  1249. if (!empty($arrayfields['p.title']['checked'])) {
  1250. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->projecttitle).'">';
  1251. print dol_escape_htmltag($obj->projecttitle);
  1252. print '</td>';
  1253. if (!$i) {
  1254. $totalarray['nbfield']++;
  1255. }
  1256. }
  1257. // Third party
  1258. if (!empty($arrayfields['s.nom']['checked'])) {
  1259. print '<td class="tdoverflowmax125">';
  1260. if ($obj->socid) {
  1261. print $socstatic->getNomUrl(1, '', 0, 0, -1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
  1262. } else {
  1263. print '&nbsp;';
  1264. }
  1265. print '</td>';
  1266. if (!$i) {
  1267. $totalarray['nbfield']++;
  1268. }
  1269. }
  1270. // Alias
  1271. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1272. $name_alias = '';
  1273. if ($obj->socid) {
  1274. $name_alias = $socstatic->name_alias;
  1275. }
  1276. print '<td class="tdoverflowmax125" title="'.dol_escape_htmltag($name_alias).'">';
  1277. print dol_escape_htmltag($name_alias);
  1278. print '</td>';
  1279. if (!$i) {
  1280. $totalarray['nbfield']++;
  1281. }
  1282. }
  1283. // Project status
  1284. if (!empty($arrayfields['p.fk_statut']['checked'])) {
  1285. print '<td class="center">';
  1286. print $projectstatic->getLibStatut(1);
  1287. print '</td>';
  1288. if (!$i) {
  1289. $totalarray['nbfield']++;
  1290. }
  1291. }
  1292. // Planned workload
  1293. if (!empty($arrayfields['t.planned_workload']['checked'])) {
  1294. print '<td class="center">';
  1295. $fullhour = convertSecondToTime($obj->planned_workload, $plannedworkloadoutputformat);
  1296. $workingdelay = convertSecondToTime($obj->planned_workload, 'all', 86400, 7); // TODO Replace 86400 and 7 to take account working hours per day and working day per weeks
  1297. if ($obj->planned_workload != '') {
  1298. print $fullhour;
  1299. // TODO Add delay taking account of working hours per day and working day per week
  1300. //if ($workingdelay != $fullhour) print '<br>('.$workingdelay.')';
  1301. }
  1302. //else print '--:--';
  1303. print '</td>';
  1304. if (!$i) {
  1305. $totalarray['nbfield']++;
  1306. }
  1307. if (!$i) {
  1308. $totalarray['pos'][$totalarray['nbfield']] = 't.planned_workload';
  1309. }
  1310. if (!isset($totalarray['val']['planned_workload'])) {
  1311. $totalarray['val']['t.planned_workload'] = 0;
  1312. }
  1313. $totalarray['val']['t.planned_workload'] += $obj->planned_workload;
  1314. if (!$i) {
  1315. $totalarray['totalplannedworkloadfield'] = $totalarray['nbfield'];
  1316. }
  1317. if (!isset($totalarray['totalplannedworkload'])) {
  1318. $totalarray['totalplannedworkload'] = 0;
  1319. }
  1320. $totalarray['totalplannedworkload'] += $obj->planned_workload;
  1321. }
  1322. // Time spent
  1323. if (!empty($arrayfields['t.duration_effective']['checked'])) {
  1324. $showlineingray = 0;
  1325. $showproject = 1;
  1326. print '<td class="center">';
  1327. if ($showlineingray) {
  1328. print '<i>';
  1329. } else {
  1330. print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$object->id.($showproject ? '' : '&withproject=1').'">';
  1331. }
  1332. if ($obj->duration_effective) {
  1333. print convertSecondToTime($obj->duration_effective, $timespentoutputformat);
  1334. } else {
  1335. print '--:--';
  1336. }
  1337. if ($showlineingray) {
  1338. print '</i>';
  1339. } else {
  1340. print '</a>';
  1341. }
  1342. print '</td>';
  1343. if (!$i) {
  1344. $totalarray['nbfield']++;
  1345. }
  1346. if (!$i) {
  1347. $totalarray['pos'][$totalarray['nbfield']] = 't.duration_effective';
  1348. }
  1349. if (!isset($totalarray['val']['t.duration_effective'])) {
  1350. $totalarray['val']['t.duration_effective'] = 0;
  1351. }
  1352. $totalarray['val']['t.duration_effective'] += $obj->duration_effective;
  1353. if (!$i) {
  1354. $totalarray['totaldurationeffectivefield'] = $totalarray['nbfield'];
  1355. }
  1356. if (!isset($totalarray['totaldurationeffective'])) {
  1357. $totalarray['totaldurationeffective'] = 0;
  1358. }
  1359. $totalarray['totaldurationeffective'] += $obj->duration_effective;
  1360. }
  1361. // Calculated progress
  1362. if (!empty($arrayfields['t.progress_calculated']['checked'])) {
  1363. print '<td class="center">';
  1364. if ($obj->planned_workload || $obj->duration_effective) {
  1365. if ($obj->planned_workload) {
  1366. print round(100 * $obj->duration_effective / $obj->planned_workload, 2).' %';
  1367. } else {
  1368. print $form->textwithpicto('', $langs->trans('WorkloadNotDefined'), 1, 'help');
  1369. }
  1370. }
  1371. print '</td>';
  1372. if (!$i) {
  1373. $totalarray['nbfield']++;
  1374. }
  1375. if (!$i) {
  1376. $totalarray['totalprogress_calculatedfield'] = $totalarray['nbfield'];
  1377. }
  1378. }
  1379. // Declared progress
  1380. if (!empty($arrayfields['t.progress']['checked'])) {
  1381. print '<td class="center">';
  1382. if ($obj->progress != '') {
  1383. print getTaskProgressBadge($object);
  1384. }
  1385. print '</td>';
  1386. if (!$i) {
  1387. $totalarray['nbfield']++;
  1388. }
  1389. if (!$i) {
  1390. $totalarray['pos'][$totalarray['nbfield']] = 't.progress';
  1391. }
  1392. if (!isset($totalarray['val']['t.progress'])) {
  1393. $totalarray['val']['t.progress'] = 0;
  1394. }
  1395. $totalarray['val']['t.progress'] += ($obj->planned_workload * $obj->progress / 100);
  1396. if (!$i) {
  1397. $totalarray['totalprogress_declaredfield'] = $totalarray['nbfield'];
  1398. }
  1399. if (!isset($totalarray['totaldurationdeclared'])) {
  1400. $totalarray['totaldurationdeclared'] = 0;
  1401. }
  1402. $totalarray['totaldurationdeclared'] += $obj->planned_workload * $obj->progress / 100;
  1403. }
  1404. // Progress summary
  1405. if (!empty($arrayfields['t.progress_summary']['checked'])) {
  1406. print '<td class="center">';
  1407. if ($obj->progress != '' && $obj->duration_effective) {
  1408. print getTaskProgressView($object, false, false);
  1409. }
  1410. print '</td>';
  1411. if (!$i) {
  1412. $totalarray['nbfield']++;
  1413. }
  1414. if (!$i) {
  1415. $totalarray['totalprogress_summary'] = $totalarray['nbfield'];
  1416. }
  1417. }
  1418. // Budget for task
  1419. if (!empty($arrayfields['t.budget_amount']['checked'])) {
  1420. print '<td class="center">';
  1421. if ($object->budget_amount) {
  1422. print '<span class="amount">'.price($object->budget_amount, 0, $langs, 1, 0, 0, $conf->currency).'</span>';
  1423. }
  1424. print '</td>';
  1425. if (!$i) {
  1426. $totalarray['nbfield']++;
  1427. }
  1428. if (!$i) {
  1429. $totalarray['pos'][$totalarray['nbfield']] = 't.budget_amount';
  1430. }
  1431. $totalarray['val']['t.budget_amount'] += $obj->budget_amount;
  1432. if (!$i) {
  1433. $totalarray['totalbudget_amountfield'] = $totalarray['nbfield'];
  1434. }
  1435. $totalarray['totalbudgetamount'] += $obj->budget_amount;
  1436. }
  1437. // Time not billed
  1438. if (!empty($arrayfields['t.tobill']['checked'])) {
  1439. print '<td class="center">';
  1440. if ($obj->usage_bill_time) {
  1441. print convertSecondToTime($obj->tobill, 'allhourmin');
  1442. $totalarray['val']['t.tobill'] += $obj->tobill;
  1443. $totalarray['totaltobill'] += $obj->tobill;
  1444. } else {
  1445. print '<span class="opacitymedium">'.$langs->trans("NA").'</span>';
  1446. }
  1447. print '</td>';
  1448. if (!$i) {
  1449. $totalarray['nbfield']++;
  1450. }
  1451. if (!$i) {
  1452. $totalarray['pos'][$totalarray['nbfield']] = 't.tobill';
  1453. }
  1454. if (!$i) {
  1455. $totalarray['totaltobillfield'] = $totalarray['nbfield'];
  1456. }
  1457. }
  1458. // Time billed
  1459. if (!empty($arrayfields['t.billed']['checked'])) {
  1460. print '<td class="center">';
  1461. if ($obj->usage_bill_time) {
  1462. print convertSecondToTime($obj->billed, 'allhourmin');
  1463. $totalarray['val']['t.billed'] += $obj->billed;
  1464. $totalarray['totalbilled'] += $obj->billed;
  1465. } else {
  1466. print '<span class="opacitymedium">'.$langs->trans("NA").'</span>';
  1467. }
  1468. print '</td>';
  1469. if (!$i) {
  1470. $totalarray['nbfield']++;
  1471. }
  1472. if (!$i) {
  1473. $totalarray['pos'][$totalarray['nbfield']] = 't.billed';
  1474. }
  1475. if (!$i) {
  1476. $totalarray['totalbilledfield'] = $totalarray['nbfield'];
  1477. }
  1478. }
  1479. // Extra fields
  1480. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1481. // Fields from hook
  1482. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1483. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1484. print $hookmanager->resPrint;
  1485. // Date creation
  1486. if (!empty($arrayfields['t.datec']['checked'])) {
  1487. print '<td class="center">';
  1488. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  1489. print '</td>';
  1490. if (!$i) {
  1491. $totalarray['nbfield']++;
  1492. }
  1493. }
  1494. // Date modification
  1495. if (!empty($arrayfields['t.tms']['checked'])) {
  1496. print '<td class="center">';
  1497. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  1498. print '</td>';
  1499. if (!$i) {
  1500. $totalarray['nbfield']++;
  1501. }
  1502. }
  1503. // Status
  1504. /*if (!empty($arrayfields['p.fk_statut']['checked']))
  1505. {
  1506. $projectstatic->statut = $obj->fk_statut;
  1507. print '<td class="right">'.$projectstatic->getLibStatut(5).'</td>';
  1508. }*/
  1509. // Action column
  1510. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1511. print '<td class="nowrap center">';
  1512. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1513. $selected = 0;
  1514. if (in_array($object->id, $arrayofselected)) {
  1515. $selected = 1;
  1516. }
  1517. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  1518. }
  1519. print '</td>';
  1520. if (!$i) {
  1521. $totalarray['nbfield']++;
  1522. }
  1523. }
  1524. print '</tr>'."\n";
  1525. }
  1526. }
  1527. $i++;
  1528. }
  1529. // Show total line
  1530. if (!empty($totalarray['totalizable']) && is_array($totalarray['totalizable'])) {
  1531. foreach ($totalarray['totalizable'] as $keytotalizable => $valtotalizable) {
  1532. $totalarray['pos'][$valtotalizable['pos']] = $keytotalizable;
  1533. $totalarray['val'][$keytotalizable] = $valtotalizable['total'];
  1534. }
  1535. }
  1536. if (isset($totalarray['totaldurationeffectivefield']) || isset($totalarray['totalplannedworkloadfield']) || isset($totalarray['totalprogress_calculatedfield'])
  1537. || isset($totalarray['totaltobill']) || isset($totalarray['totalbilled']) || isset($totalarray['totalbudget'])) {
  1538. print '<tr class="liste_total">';
  1539. $i = 0;
  1540. while ($i < $totalarray['nbfield']) {
  1541. $i++;
  1542. if ($i == 1) {
  1543. if ($num < $limit && empty($offset)) {
  1544. print '<td class="left">'.$langs->trans("Total").'</td>';
  1545. } else {
  1546. print '<td class="left">'.$langs->trans("Totalforthispage").'</td>';
  1547. }
  1548. } elseif (isset($totalarray['totalplannedworkloadfield']) && $totalarray['totalplannedworkloadfield'] == $i) {
  1549. print '<td class="center">'.convertSecondToTime($totalarray['totalplannedworkload'], $plannedworkloadoutputformat).'</td>';
  1550. } elseif (isset($totalarray['totaldurationeffectivefield']) && $totalarray['totaldurationeffectivefield'] == $i) {
  1551. print '<td class="center">'.convertSecondToTime($totalarray['totaldurationeffective'], $timespentoutputformat).'</td>';
  1552. } elseif (isset($totalarray['totalprogress_calculatedfield']) && $totalarray['totalprogress_calculatedfield'] == $i) {
  1553. print '<td class="center">'.($totalarray['totalplannedworkload'] > 0 ? round(100 * $totalarray['totaldurationeffective'] / $totalarray['totalplannedworkload'], 2).' %' : '').'</td>';
  1554. } elseif (isset($totalarray['totalprogress_declaredfield']) && $totalarray['totalprogress_declaredfield'] == $i) {
  1555. print '<td class="center">'.($totalarray['totalplannedworkload'] > 0 ? round(100 * $totalarray['totaldurationdeclared'] / $totalarray['totalplannedworkload'], 2).' %' : '').'</td>';
  1556. } elseif (isset($totalarray['totaltobillfield']) && $totalarray['totaltobillfield'] == $i) {
  1557. print '<td class="center">'.convertSecondToTime($totalarray['totaltobill'], $plannedworkloadoutputformat).'</td>';
  1558. } elseif (isset($totalarray['totalbilledfield']) && $totalarray['totalbilledfield'] == $i) {
  1559. print '<td class="center">'.convertSecondToTime($totalarray['totalbilled'], $plannedworkloadoutputformat).'</td>';
  1560. } elseif (isset($totalarray['totalbudget_amountfield']) && $totalarray['totalbudget_amountfield'] == $i) {
  1561. print '<td class="center">'.price($totalarray['totalbudgetamount'], 0, $langs, 1, 0, 0, $conf->currency).'</td>';
  1562. } elseif (!empty($totalarray['pos'][$i])) {
  1563. print '<td class="right">';
  1564. if (isset($totalarray['type']) && $totalarray['type'][$i] == 'duration') {
  1565. print(!empty($totalarray['val'][$totalarray['pos'][$i]]) ? convertSecondToTime($totalarray['val'][$totalarray['pos'][$i]], 'allhourmin') : 0);
  1566. } else {
  1567. print price(!empty($totalarray['val'][$totalarray['pos'][$i]]) ? $totalarray['val'][$totalarray['pos'][$i]] : 0);
  1568. }
  1569. print '</td>';
  1570. } else {
  1571. print '<td></td>';
  1572. }
  1573. }
  1574. print '</tr>';
  1575. }
  1576. $db->free($resql);
  1577. $parameters = array('arrayfields'=>$arrayfields, 'sql' => $sql);
  1578. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1579. print $hookmanager->resPrint;
  1580. print '</table>'."\n";
  1581. print '</div>'."\n";
  1582. print '</form>'."\n";
  1583. // End of page
  1584. llxFooter();
  1585. $db->close();