project.lib.php 107 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723
  1. <?php
  2. /* Copyright (C) 2006-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2010 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
  6. * Copyright (C) 2022 Charlene Benke <charlene@patas-monkey.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. * or see https://www.gnu.org/
  21. */
  22. /**
  23. * \file htdocs/core/lib/project.lib.php
  24. * \brief Functions used by project module
  25. * \ingroup project
  26. */
  27. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  28. /**
  29. * Prepare array with list of tabs
  30. *
  31. * @param Project $project Object related to tabs
  32. * @param string $moreparam More param on url
  33. * @return array Array of tabs to show
  34. */
  35. function project_prepare_head(Project $project, $moreparam = '')
  36. {
  37. global $db, $langs, $conf, $user;
  38. $h = 0;
  39. $head = array();
  40. $head[$h][0] = DOL_URL_ROOT.'/projet/card.php?id='.((int) $project->id).($moreparam ? '&'.$moreparam : '');
  41. $head[$h][1] = $langs->trans("Project");
  42. $head[$h][2] = 'project';
  43. $h++;
  44. $nbContacts = 0;
  45. // Enable caching of project count Contacts
  46. require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
  47. $cachekey = 'count_contacts_project_'.$project->id;
  48. $dataretrieved = dol_getcache($cachekey);
  49. if (!is_null($dataretrieved)) {
  50. $nbContacts = $dataretrieved;
  51. } else {
  52. $nbContacts = count($project->liste_contact(-1, 'internal')) + count($project->liste_contact(-1, 'external'));
  53. dol_setcache($cachekey, $nbContacts, 120); // If setting cache fails, this is not a problem, so we do not test result.
  54. }
  55. $head[$h][0] = DOL_URL_ROOT.'/projet/contact.php?id='.((int) $project->id).($moreparam ? '&'.$moreparam : '');
  56. $head[$h][1] = $langs->trans("ProjectContact");
  57. if ($nbContacts > 0) {
  58. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContacts.'</span>';
  59. }
  60. $head[$h][2] = 'contact';
  61. $h++;
  62. if (empty($conf->global->PROJECT_HIDE_TASKS)) {
  63. // Then tab for sub level of projet, i mean tasks
  64. $nbTasks = 0;
  65. // Enable caching of project count Tasks
  66. require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
  67. $cachekey = 'count_tasks_project_'.$project->id;
  68. $dataretrieved = dol_getcache($cachekey);
  69. if (!is_null($dataretrieved)) {
  70. $nbTasks = $dataretrieved;
  71. } else {
  72. require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
  73. $taskstatic = new Task($db);
  74. $nbTasks = count($taskstatic->getTasksArray(0, 0, $project->id, 0, 0));
  75. dol_setcache($cachekey, $nbTasks, 120); // If setting cache fails, this is not a problem, so we do not test result.
  76. }
  77. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks.php?id='.((int) $project->id).($moreparam ? '&'.$moreparam : '');
  78. $head[$h][1] = $langs->trans("Tasks");
  79. if ($nbTasks > 0) {
  80. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbTasks).'</span>';
  81. }
  82. $head[$h][2] = 'tasks';
  83. $h++;
  84. $nbTimeSpent = 0;
  85. // Enable caching of project count Timespent
  86. $cachekey = 'count_timespent_project_'.$project->id;
  87. $dataretrieved = dol_getcache($cachekey);
  88. if (!is_null($dataretrieved)) {
  89. $nbTimeSpent = $dataretrieved;
  90. } else {
  91. $sql = "SELECT t.rowid";
  92. //$sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t, ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."user as u";
  93. //$sql .= " WHERE t.fk_user = u.rowid AND t.fk_task = pt.rowid";
  94. $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t, ".MAIN_DB_PREFIX."projet_task as pt";
  95. $sql .= " WHERE t.fk_task = pt.rowid";
  96. $sql .= " AND pt.fk_projet =".((int) $project->id);
  97. $resql = $db->query($sql);
  98. if ($resql) {
  99. $obj = $db->fetch_object($resql);
  100. if ($obj) {
  101. $nbTimeSpent = 1;
  102. dol_setcache($cachekey, $nbTimeSpent, 120); // If setting cache fails, this is not a problem, so we do not test result.
  103. }
  104. } else {
  105. dol_print_error($db);
  106. }
  107. }
  108. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?withproject=1&projectid='.((int) $project->id).($moreparam ? '&'.$moreparam : '');
  109. $head[$h][1] = $langs->trans("TimeSpent");
  110. if ($nbTimeSpent > 0) {
  111. $head[$h][1] .= '<span class="badge marginleftonlyshort">...</span>';
  112. }
  113. $head[$h][2] = 'timespent';
  114. $h++;
  115. }
  116. if (((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || isModEnabled("supplier_order") || isModEnabled("supplier_invoice"))
  117. || isModEnabled("propal") || isModEnabled('commande')
  118. || isModEnabled('facture') || isModEnabled('contrat')
  119. || isModEnabled('ficheinter') || isModEnabled('agenda') || isModEnabled('deplacement') || isModEnabled('stock')) {
  120. $nbElements = 0;
  121. // Enable caching of thirdrparty count Contacts
  122. $cachekey = 'count_elements_project_'.$project->id;
  123. $dataretrieved = dol_getcache($cachekey);
  124. if (!is_null($dataretrieved)) {
  125. $nbElements = $dataretrieved;
  126. } else {
  127. if (isModEnabled('stock')) {
  128. $nbElements += $project->getElementCount('stock', 'entrepot', 'fk_project');
  129. }
  130. if (isModEnabled("propal")) {
  131. $nbElements += $project->getElementCount('propal', 'propal');
  132. }
  133. if (isModEnabled('commande')) {
  134. $nbElements += $project->getElementCount('order', 'commande');
  135. }
  136. if (isModEnabled('facture')) {
  137. $nbElements += $project->getElementCount('invoice', 'facture');
  138. }
  139. if (isModEnabled('facture')) {
  140. $nbElements += $project->getElementCount('invoice_predefined', 'facture_rec');
  141. }
  142. if (isModEnabled('supplier_proposal')) {
  143. $nbElements += $project->getElementCount('proposal_supplier', 'supplier_proposal');
  144. }
  145. if (isModEnabled("supplier_order")) {
  146. $nbElements += $project->getElementCount('order_supplier', 'commande_fournisseur');
  147. }
  148. if (isModEnabled("supplier_invoice")) {
  149. $nbElements += $project->getElementCount('invoice_supplier', 'facture_fourn');
  150. }
  151. if (isModEnabled('contrat')) {
  152. $nbElements += $project->getElementCount('contract', 'contrat');
  153. }
  154. if (isModEnabled('ficheinter')) {
  155. $nbElements += $project->getElementCount('intervention', 'fichinter');
  156. }
  157. if (isModEnabled("expedition")) {
  158. $nbElements += $project->getElementCount('shipping', 'expedition');
  159. }
  160. if (isModEnabled('mrp')) {
  161. $nbElements += $project->getElementCount('mrp', 'mrp_mo', 'fk_project');
  162. }
  163. if (isModEnabled('deplacement')) {
  164. $nbElements += $project->getElementCount('trip', 'deplacement');
  165. }
  166. if (isModEnabled('expensereport')) {
  167. $nbElements += $project->getElementCount('expensereport', 'expensereport');
  168. }
  169. if (isModEnabled('don')) {
  170. $nbElements += $project->getElementCount('donation', 'don');
  171. }
  172. if (!empty($conf->loan->enabled)) {
  173. $nbElements += $project->getElementCount('loan', 'loan');
  174. }
  175. if (isModEnabled('tax')) {
  176. $nbElements += $project->getElementCount('chargesociales', 'chargesociales');
  177. }
  178. if (isModEnabled('project')) {
  179. $nbElements += $project->getElementCount('project_task', 'projet_task');
  180. }
  181. if (isModEnabled('stock')) {
  182. $nbElements += $project->getElementCount('stock_mouvement', 'stock');
  183. }
  184. if (!empty($conf->salaries->enabled)) {
  185. $nbElements += $project->getElementCount('salaries', 'payment_salary');
  186. }
  187. if (isModEnabled("banque")) {
  188. $nbElements += $project->getElementCount('variouspayment', 'payment_various');
  189. }
  190. dol_setcache($cachekey, $nbElements, 120); // If setting cache fails, this is not a problem, so we do not test result.
  191. }
  192. $head[$h][0] = DOL_URL_ROOT.'/projet/element.php?id='.$project->id;
  193. $head[$h][1] = $langs->trans("ProjectOverview");
  194. if ($nbElements > 0) {
  195. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbElements.'</span>';
  196. }
  197. $head[$h][2] = 'element';
  198. $h++;
  199. }
  200. if (isModEnabled('ticket') && $user->hasRight('ticket', 'read')) {
  201. require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
  202. $Tickettatic = new Ticket($db);
  203. $nbTicket = count($Tickettatic->getAllItemsLinkedByObjectID($project->id, '*', 'fk_project', 'ticket'));
  204. $head[$h][0] = DOL_URL_ROOT.'/ticket/list.php?projectid='.((int) $project->id);
  205. $head[$h][1] = $langs->trans("Ticket");
  206. if ($nbTicket > 0) {
  207. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbTicket).'</span>';
  208. }
  209. $head[$h][2] = 'ticket';
  210. $h++;
  211. }
  212. if (isModEnabled('eventorganization') && !empty($project->usage_organize_event)) {
  213. $langs->load('eventorganization');
  214. $head[$h][0] = DOL_URL_ROOT . '/eventorganization/conferenceorbooth_list.php?projectid=' . $project->id;
  215. $head[$h][1] = $langs->trans("EventOrganization");
  216. // Enable caching of conf or booth count
  217. $nbConfOrBooth = 0;
  218. require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
  219. $cachekey = 'count_conferenceorbooth_'.$project->id;
  220. $dataretrieved = dol_getcache($cachekey);
  221. if (!is_null($dataretrieved)) {
  222. $nbConfOrBooth = $dataretrieved;
  223. } else {
  224. require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorbooth.class.php';
  225. $conforbooth=new ConferenceOrBooth($db);
  226. $result = $conforbooth->fetchAll('', '', 0, 0, array('t.fk_project'=>$project->id));
  227. //,
  228. if (!is_array($result) && $result<0) {
  229. setEventMessages($conforbooth->error, $conforbooth->errors, 'errors');
  230. } else {
  231. $nbConfOrBooth = count($result);
  232. }
  233. dol_setcache($cachekey, $nbConfOrBooth, 120); // If setting cache fails, this is not a problem, so we do not test result.
  234. }
  235. if ($nbConfOrBooth > 0) {
  236. $head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbConfOrBooth . '</span>';
  237. }
  238. $head[$h][2] = 'eventorganisation';
  239. $h++;
  240. }
  241. // Show more tabs from modules
  242. // Entries must be declared in modules descriptor with line
  243. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  244. // $this->tabs = array('entity:-tabname); to remove a tab
  245. complete_head_from_modules($conf, $langs, $project, $head, $h, 'project', 'add', 'core');
  246. if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
  247. $nbNote = 0;
  248. if (!empty($project->note_private)) {
  249. $nbNote++;
  250. }
  251. if (!empty($project->note_public)) {
  252. $nbNote++;
  253. }
  254. $head[$h][0] = DOL_URL_ROOT.'/projet/note.php?id='.$project->id;
  255. $head[$h][1] = $langs->trans('Notes');
  256. if ($nbNote > 0) {
  257. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
  258. }
  259. $head[$h][2] = 'notes';
  260. $h++;
  261. }
  262. // Attached files and Links
  263. $totalAttached = 0;
  264. // Enable caching of thirdrparty count attached files and links
  265. require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
  266. $cachekey = 'count_attached_project_'.$project->id;
  267. $dataretrieved = dol_getcache($cachekey);
  268. if (!is_null($dataretrieved)) {
  269. $totalAttached = $dataretrieved;
  270. } else {
  271. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  272. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  273. $upload_dir = $conf->project->multidir_output[$project->entity]."/".dol_sanitizeFileName($project->ref);
  274. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  275. $nbLinks = Link::count($db, $project->element, $project->id);
  276. $totalAttached = $nbFiles + $nbLinks;
  277. dol_setcache($cachekey, $totalAttached, 120); // If setting cache fails, this is not a problem, so we do not test result.
  278. }
  279. $head[$h][0] = DOL_URL_ROOT.'/projet/document.php?id='.$project->id;
  280. $head[$h][1] = $langs->trans('Documents');
  281. if (($totalAttached) > 0) {
  282. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($totalAttached).'</span>';
  283. }
  284. $head[$h][2] = 'document';
  285. $h++;
  286. // Manage discussion
  287. if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT)) {
  288. $nbComments = 0;
  289. // Enable caching of thirdrparty count attached files and links
  290. require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
  291. $cachekey = 'count_attached_project_'.$project->id;
  292. $dataretrieved = dol_getcache($cachekey);
  293. if (!is_null($dataretrieved)) {
  294. $nbComments = $dataretrieved;
  295. } else {
  296. $nbComments = $project->getNbComments();
  297. dol_setcache($cachekey, $nbComments, 120); // If setting cache fails, this is not a problem, so we do not test result.
  298. }
  299. $head[$h][0] = DOL_URL_ROOT.'/projet/comment.php?id='.$project->id;
  300. $head[$h][1] = $langs->trans("CommentLink");
  301. if ($nbComments > 0) {
  302. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbComments.'</span>';
  303. }
  304. $head[$h][2] = 'project_comment';
  305. $h++;
  306. }
  307. $head[$h][0] = DOL_URL_ROOT.'/projet/messaging.php?id='.$project->id;
  308. $head[$h][1] = $langs->trans("Events");
  309. if (isModEnabled('agenda') && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
  310. $head[$h][1] .= '/';
  311. $head[$h][1] .= $langs->trans("Agenda");
  312. }
  313. $head[$h][2] = 'agenda';
  314. $h++;
  315. complete_head_from_modules($conf, $langs, $project, $head, $h, 'project', 'add', 'external');
  316. complete_head_from_modules($conf, $langs, $project, $head, $h, 'project', 'remove');
  317. return $head;
  318. }
  319. /**
  320. * Prepare array with list of tabs
  321. *
  322. * @param Object $object Object related to tabs
  323. * @return array Array of tabs to show
  324. */
  325. function task_prepare_head($object)
  326. {
  327. global $db, $langs, $conf, $user;
  328. $h = 0;
  329. $head = array();
  330. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/task.php?id='.$object->id.(GETPOST('withproject') ? '&withproject=1' : '');
  331. $head[$h][1] = $langs->trans("Task");
  332. $head[$h][2] = 'task_task';
  333. $h++;
  334. $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
  335. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/contact.php?id='.$object->id.(GETPOST('withproject') ? '&withproject=1' : '');
  336. $head[$h][1] = $langs->trans("TaskRessourceLinks");
  337. if ($nbContact > 0) {
  338. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
  339. }
  340. $head[$h][2] = 'task_contact';
  341. $h++;
  342. // Is there timespent ?
  343. $nbTimeSpent = 0;
  344. $sql = "SELECT t.rowid";
  345. //$sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t, ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."user as u";
  346. //$sql .= " WHERE t.fk_user = u.rowid AND t.fk_task = pt.rowid";
  347. $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t";
  348. $sql .= " WHERE t.fk_task = ".((int) $object->id);
  349. $resql = $db->query($sql);
  350. if ($resql) {
  351. $obj = $db->fetch_object($resql);
  352. if ($obj) {
  353. $nbTimeSpent = 1;
  354. }
  355. } else {
  356. dol_print_error($db);
  357. }
  358. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?id='.urlencode($object->id).(GETPOST('withproject') ? '&withproject=1' : '');
  359. $head[$h][1] = $langs->trans("TimeSpent");
  360. if ($nbTimeSpent > 0) {
  361. $head[$h][1] .= '<span class="badge marginleftonlyshort">...</span>';
  362. }
  363. $head[$h][2] = 'task_time';
  364. $h++;
  365. // Show more tabs from modules
  366. // Entries must be declared in modules descriptor with line
  367. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  368. // $this->tabs = array('entity:-tabname); to remove a tab
  369. complete_head_from_modules($conf, $langs, $object, $head, $h, 'task', 'add', 'core');
  370. if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
  371. $nbNote = 0;
  372. if (!empty($object->note_private)) {
  373. $nbNote++;
  374. }
  375. if (!empty($object->note_public)) {
  376. $nbNote++;
  377. }
  378. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/note.php?id='.urlencode($object->id).(GETPOST('withproject') ? '&withproject=1' : '');
  379. $head[$h][1] = $langs->trans('Notes');
  380. if ($nbNote > 0) {
  381. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
  382. }
  383. $head[$h][2] = 'task_notes';
  384. $h++;
  385. }
  386. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/document.php?id='.$object->id.(GETPOST('withproject') ? '&withproject=1' : '');
  387. $filesdir = $conf->project->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->project->ref).'/'.dol_sanitizeFileName($object->ref);
  388. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  389. include_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  390. $nbFiles = count(dol_dir_list($filesdir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  391. $nbLinks = Link::count($db, $object->element, $object->id);
  392. $head[$h][1] = $langs->trans('Documents');
  393. if (($nbFiles + $nbLinks) > 0) {
  394. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  395. }
  396. $head[$h][2] = 'task_document';
  397. $h++;
  398. // Manage discussion
  399. if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_TASK)) {
  400. $nbComments = $object->getNbComments();
  401. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/comment.php?id='.$object->id.(GETPOST('withproject') ? '&withproject=1' : '');
  402. $head[$h][1] = $langs->trans("CommentLink");
  403. if ($nbComments > 0) {
  404. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbComments.'</span>';
  405. }
  406. $head[$h][2] = 'task_comment';
  407. $h++;
  408. }
  409. complete_head_from_modules($conf, $langs, $object, $head, $h, 'task', 'add', 'external');
  410. complete_head_from_modules($conf, $langs, $object, $head, $h, 'task', 'remove');
  411. return $head;
  412. }
  413. /**
  414. * Prepare array with list of tabs
  415. *
  416. * @param string $mode Mode
  417. * @param string $fuser Filter on user
  418. * @return array Array of tabs to show
  419. */
  420. function project_timesheet_prepare_head($mode, $fuser = null)
  421. {
  422. global $langs, $conf, $user;
  423. $h = 0;
  424. $head = array();
  425. $h = 0;
  426. $param = '';
  427. $param .= ($mode ? '&mode='.$mode : '');
  428. if (is_object($fuser) && $fuser->id > 0 && $fuser->id != $user->id) {
  429. $param .= '&search_usertoprocessid='.$fuser->id;
  430. }
  431. if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERMONTH)) {
  432. $head[$h][0] = DOL_URL_ROOT."/projet/activity/permonth.php".($param ? '?'.$param : '');
  433. $head[$h][1] = $langs->trans("InputPerMonth");
  434. $head[$h][2] = 'inputpermonth';
  435. $h++;
  436. }
  437. if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERWEEK)) {
  438. $head[$h][0] = DOL_URL_ROOT."/projet/activity/perweek.php".($param ? '?'.$param : '');
  439. $head[$h][1] = $langs->trans("InputPerWeek");
  440. $head[$h][2] = 'inputperweek';
  441. $h++;
  442. }
  443. if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERTIME)) {
  444. $head[$h][0] = DOL_URL_ROOT."/projet/activity/perday.php".($param ? '?'.$param : '');
  445. $head[$h][1] = $langs->trans("InputPerDay");
  446. $head[$h][2] = 'inputperday';
  447. $h++;
  448. }
  449. complete_head_from_modules($conf, $langs, null, $head, $h, 'project_timesheet');
  450. complete_head_from_modules($conf, $langs, null, $head, $h, 'project_timesheet', 'remove');
  451. return $head;
  452. }
  453. /**
  454. * Prepare array with list of tabs
  455. *
  456. * @return array Array of tabs to show
  457. */
  458. function project_admin_prepare_head()
  459. {
  460. global $langs, $conf, $user, $db;
  461. $extrafields = new ExtraFields($db);
  462. $extrafields->fetch_name_optionals_label('projet');
  463. $extrafields->fetch_name_optionals_label('projet_task');
  464. $h = 0;
  465. $head = array();
  466. $head[$h][0] = DOL_URL_ROOT."/projet/admin/project.php";
  467. $head[$h][1] = $langs->trans("Projects");
  468. $head[$h][2] = 'project';
  469. $h++;
  470. complete_head_from_modules($conf, $langs, null, $head, $h, 'project_admin');
  471. $head[$h][0] = DOL_URL_ROOT."/projet/admin/project_extrafields.php";
  472. $head[$h][1] = $langs->trans("ExtraFieldsProject");
  473. $nbExtrafields = $extrafields->attributes['projet']['count'];
  474. if ($nbExtrafields > 0) {
  475. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  476. }
  477. $head[$h][2] = 'attributes';
  478. $h++;
  479. $head[$h][0] = DOL_URL_ROOT.'/projet/admin/project_task_extrafields.php';
  480. $head[$h][1] = $langs->trans("ExtraFieldsProjectTask");
  481. $nbExtrafields = $extrafields->attributes['projet_task']['count'];
  482. if ($nbExtrafields > 0) {
  483. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  484. }
  485. $head[$h][2] = 'attributes_task';
  486. $h++;
  487. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  488. $langs->load("members");
  489. $head[$h][0] = DOL_URL_ROOT.'/projet/admin/website.php';
  490. $head[$h][1] = $langs->trans("BlankSubscriptionForm");
  491. $head[$h][2] = 'website';
  492. $h++;
  493. }
  494. complete_head_from_modules($conf, $langs, null, $head, $h, 'project_admin', 'remove');
  495. return $head;
  496. }
  497. /**
  498. * Show task lines with a particular parent
  499. *
  500. * @param string $inc Line number (start to 0, then increased by recursive call)
  501. * @param string $parent Id of parent project to show (0 to show all)
  502. * @param Task[] $lines Array of lines
  503. * @param int $level Level (start to 0, then increased/decrease by recursive call), or -1 to show all level in order of $lines without the recursive groupment feature.
  504. * @param string $var Color
  505. * @param int $showproject Show project columns
  506. * @param int $taskrole Array of roles of user for each tasks
  507. * @param int $projectsListId List of id of project allowed to user (string separated with comma)
  508. * @param int $addordertick Add a tick to move task
  509. * @param int $projectidfortotallink 0 or Id of project to use on total line (link to see all time consumed for project)
  510. * @param string $filterprogresscalc filter text
  511. * @param string $showbilltime Add the column 'TimeToBill' and 'TimeBilled'
  512. * @param array $arrayfields Array with displayed coloumn information
  513. * @return int Nb of tasks shown
  514. */
  515. function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$taskrole, $projectsListId = '', $addordertick = 0, $projectidfortotallink = 0, $filterprogresscalc = '', $showbilltime = 0, $arrayfields = array())
  516. {
  517. global $user, $langs, $conf, $db, $hookmanager;
  518. global $projectstatic, $taskstatic, $extrafields;
  519. $lastprojectid = 0;
  520. $projectsArrayId = explode(',', $projectsListId);
  521. if ($filterprogresscalc !== '') {
  522. foreach ($lines as $key => $line) {
  523. if (!empty($line->planned_workload) && !empty($line->duration)) {
  524. $filterprogresscalc = str_replace(' = ', ' == ', $filterprogresscalc);
  525. if (!eval($filterprogresscalc)) {
  526. unset($lines[$key]);
  527. }
  528. }
  529. }
  530. $lines = array_values($lines);
  531. }
  532. $numlines = count($lines);
  533. // We declare counter as global because we want to edit them into recursive call
  534. global $total_projectlinesa_spent, $total_projectlinesa_planned, $total_projectlinesa_spent_if_planned, $total_projectlinesa_declared_if_planned, $total_projectlinesa_tobill, $total_projectlinesa_billed, $total_budget_amount;
  535. if ($level == 0) {
  536. $total_projectlinesa_spent = 0;
  537. $total_projectlinesa_planned = 0;
  538. $total_projectlinesa_spent_if_planned = 0;
  539. $total_projectlinesa_declared_if_planned = 0;
  540. $total_projectlinesa_tobill = 0;
  541. $total_projectlinesa_billed = 0;
  542. $total_budget_amount = 0;
  543. }
  544. for ($i = 0; $i < $numlines; $i++) {
  545. if ($parent == 0 && $level >= 0) {
  546. $level = 0; // if $level = -1, we dont' use sublevel recursion, we show all lines
  547. }
  548. // Process line
  549. // print "i:".$i."-".$lines[$i]->fk_project.'<br>';
  550. if ($lines[$i]->fk_parent == $parent || $level < 0) { // if $level = -1, we dont' use sublevel recursion, we show all lines
  551. // Show task line.
  552. $showline = 1;
  553. $showlineingray = 0;
  554. // If there is filters to use
  555. if (is_array($taskrole)) {
  556. // If task not legitimate to show, search if a legitimate task exists later in tree
  557. if (!isset($taskrole[$lines[$i]->id]) && $lines[$i]->id != $lines[$i]->fk_parent) {
  558. // So search if task has a subtask legitimate to show
  559. $foundtaskforuserdeeper = 0;
  560. searchTaskInChild($foundtaskforuserdeeper, $lines[$i]->id, $lines, $taskrole);
  561. //print '$foundtaskforuserpeeper='.$foundtaskforuserdeeper.'<br>';
  562. if ($foundtaskforuserdeeper > 0) {
  563. $showlineingray = 1; // We will show line but in gray
  564. } else {
  565. $showline = 0; // No reason to show line
  566. }
  567. }
  568. } else {
  569. // Caller did not ask to filter on tasks of a specific user (this probably means he want also tasks of all users, into public project
  570. // or into all other projects if user has permission to).
  571. if (empty($user->rights->projet->all->lire)) {
  572. // User is not allowed on this project and project is not public, so we hide line
  573. if (!in_array($lines[$i]->fk_project, $projectsArrayId)) {
  574. // Note that having a user assigned to a task into a project user has no permission on, should not be possible
  575. // because assignement on task can be done only on contact of project.
  576. // If assignement was done and after, was removed from contact of project, then we can hide the line.
  577. $showline = 0;
  578. }
  579. }
  580. }
  581. if ($showline) {
  582. // Break on a new project
  583. if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid) {
  584. $var = !$var;
  585. $lastprojectid = $lines[$i]->fk_project;
  586. }
  587. print '<tr class="oddeven" id="row-'.$lines[$i]->id.'">'."\n";
  588. $projectstatic->id = $lines[$i]->fk_project;
  589. $projectstatic->ref = $lines[$i]->projectref;
  590. $projectstatic->public = $lines[$i]->public;
  591. $projectstatic->title = $lines[$i]->projectlabel;
  592. $projectstatic->usage_bill_time = $lines[$i]->usage_bill_time;
  593. $projectstatic->status = $lines[$i]->projectstatus;
  594. $taskstatic->id = $lines[$i]->id;
  595. $taskstatic->ref = $lines[$i]->ref;
  596. $taskstatic->label = (!empty($taskrole[$lines[$i]->id]) ? $langs->trans("YourRole").': '.$taskrole[$lines[$i]->id] : '');
  597. $taskstatic->projectstatus = $lines[$i]->projectstatus;
  598. $taskstatic->progress = $lines[$i]->progress;
  599. $taskstatic->fk_statut = $lines[$i]->status;
  600. $taskstatic->date_start = $lines[$i]->date_start;
  601. $taskstatic->date_end = $lines[$i]->date_end;
  602. $taskstatic->datee = $lines[$i]->date_end; // deprecated
  603. $taskstatic->planned_workload = $lines[$i]->planned_workload;
  604. $taskstatic->duration_effective = $lines[$i]->duration;
  605. $taskstatic->budget_amount = $lines[$i]->budget_amount;
  606. if ($showproject) {
  607. // Project ref
  608. print '<td class="nowraponall">';
  609. //if ($showlineingray) print '<i>';
  610. if ($lines[$i]->public || in_array($lines[$i]->fk_project, $projectsArrayId) || !empty($user->rights->projet->all->lire)) {
  611. print $projectstatic->getNomUrl(1);
  612. } else {
  613. print $projectstatic->getNomUrl(1, 'nolink');
  614. }
  615. //if ($showlineingray) print '</i>';
  616. print "</td>";
  617. // Project status
  618. print '<td>';
  619. $projectstatic->statut = $lines[$i]->projectstatus;
  620. print $projectstatic->getLibStatut(2);
  621. print "</td>";
  622. }
  623. // Ref of task
  624. if (count($arrayfields) > 0 && !empty($arrayfields['t.ref']['checked'])) {
  625. print '<td class="nowraponall">';
  626. if ($showlineingray) {
  627. print '<i>'.img_object('', 'projecttask').' '.$lines[$i]->ref.'</i>';
  628. } else {
  629. print $taskstatic->getNomUrl(1, 'withproject');
  630. }
  631. print '</td>';
  632. }
  633. // Title of task
  634. if (count($arrayfields) > 0 && !empty($arrayfields['t.label']['checked'])) {
  635. $labeltoshow = '';
  636. if ($showlineingray) {
  637. $labeltoshow .= '<i>';
  638. }
  639. //else print '<a href="'.DOL_URL_ROOT.'/projet/tasks/task.php?id='.$lines[$i]->id.'&withproject=1">';
  640. for ($k = 0; $k < $level; $k++) {
  641. $labeltoshow .= '<div class="marginleftonly">';
  642. }
  643. $labeltoshow .= dol_escape_htmltag($lines[$i]->label);
  644. for ($k = 0; $k < $level; $k++) {
  645. $labeltoshow .= '</div>';
  646. }
  647. if ($showlineingray) {
  648. $labeltoshow .= '</i>';
  649. }
  650. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($labeltoshow).'">';
  651. print $labeltoshow;
  652. print "</td>\n";
  653. }
  654. if (count($arrayfields) > 0 && !empty($arrayfields['t.description']['checked'])) {
  655. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($lines[$i]->description).'">';
  656. print $lines[$i]->description;
  657. print "</td>\n";
  658. }
  659. // Date start
  660. if (count($arrayfields) > 0 && !empty($arrayfields['t.dateo']['checked'])) {
  661. print '<td class="center nowraponall">';
  662. print dol_print_date($lines[$i]->date_start, 'dayhour');
  663. print '</td>';
  664. }
  665. // Date end
  666. if (count($arrayfields) > 0 && !empty($arrayfields['t.datee']['checked'])) {
  667. print '<td class="center nowraponall">';
  668. print dol_print_date($lines[$i]->date_end, 'dayhour');
  669. if ($taskstatic->hasDelay()) {
  670. print img_warning($langs->trans("Late"));
  671. }
  672. print '</td>';
  673. }
  674. $plannedworkloadoutputformat = 'allhourmin';
  675. $timespentoutputformat = 'allhourmin';
  676. if (!empty($conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT)) {
  677. $plannedworkloadoutputformat = $conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT;
  678. }
  679. if (!empty($conf->global->PROJECT_TIMES_SPENT_FORMAT)) {
  680. $timespentoutputformat = $conf->global->PROJECT_TIME_SPENT_FORMAT;
  681. }
  682. // Planned Workload (in working hours)
  683. if (count($arrayfields) > 0 && !empty($arrayfields['t.planned_workload']['checked'])) {
  684. print '<td class="right">';
  685. $fullhour = convertSecondToTime($lines[$i]->planned_workload, $plannedworkloadoutputformat);
  686. $workingdelay = convertSecondToTime($lines[$i]->planned_workload, 'all', 86400, 7); // TODO Replace 86400 and 7 to take account working hours per day and working day per weeks
  687. if ($lines[$i]->planned_workload != '') {
  688. print $fullhour;
  689. // TODO Add delay taking account of working hours per day and working day per week
  690. //if ($workingdelay != $fullhour) print '<br>('.$workingdelay.')';
  691. }
  692. //else print '--:--';
  693. print '</td>';
  694. }
  695. // Time spent
  696. if (count($arrayfields) > 0 && !empty($arrayfields['t.duration_effective']['checked'])) {
  697. print '<td class="right">';
  698. if ($showlineingray) {
  699. print '<i>';
  700. } else {
  701. print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.($showproject ? '' : '&withproject=1').'">';
  702. }
  703. if ($lines[$i]->duration) {
  704. print convertSecondToTime($lines[$i]->duration, $timespentoutputformat);
  705. } else {
  706. print '--:--';
  707. }
  708. if ($showlineingray) {
  709. print '</i>';
  710. } else {
  711. print '</a>';
  712. }
  713. print '</td>';
  714. }
  715. // Progress calculated (Note: ->duration is time spent)
  716. if (count($arrayfields) > 0 && !empty($arrayfields['t.progress_calculated']['checked'])) {
  717. print '<td class="right">';
  718. if ($lines[$i]->planned_workload || $lines[$i]->duration) {
  719. if ($lines[$i]->planned_workload) {
  720. print round(100 * $lines[$i]->duration / $lines[$i]->planned_workload, 2).' %';
  721. } else {
  722. print '<span class="opacitymedium">'.$langs->trans('WorkloadNotDefined').'</span>';
  723. }
  724. }
  725. print '</td>';
  726. }
  727. // Progress declared
  728. if (count($arrayfields) > 0 && !empty($arrayfields['t.progress']['checked'])) {
  729. print '<td class="right">';
  730. if ($lines[$i]->progress != '') {
  731. print getTaskProgressBadge($taskstatic);
  732. }
  733. print '</td>';
  734. }
  735. // resume
  736. if (count($arrayfields) > 0 && !empty($arrayfields['t.progress_summary']['checked'])) {
  737. print '<td class="right">';
  738. if ($lines[$i]->progress != '' && $lines[$i]->duration) {
  739. print getTaskProgressView($taskstatic, false, false);
  740. }
  741. print '</td>';
  742. }
  743. if ($showbilltime) {
  744. // Time not billed
  745. if (count($arrayfields) > 0 && !empty($arrayfields['t.tobill']['checked'])) {
  746. print '<td class="right">';
  747. if ($lines[$i]->usage_bill_time) {
  748. print convertSecondToTime($lines[$i]->tobill, 'allhourmin');
  749. $total_projectlinesa_tobill += $lines[$i]->tobill;
  750. } else {
  751. print '<span class="opacitymedium">'.$langs->trans("NA").'</span>';
  752. }
  753. print '</td>';
  754. }
  755. // Time billed
  756. if (count($arrayfields) > 0 && !empty($arrayfields['t.billed']['checked'])) {
  757. print '<td class="right">';
  758. if ($lines[$i]->usage_bill_time) {
  759. print convertSecondToTime($lines[$i]->billed, 'allhourmin');
  760. $total_projectlinesa_billed += $lines[$i]->billed;
  761. } else {
  762. print '<span class="opacitymedium">'.$langs->trans("NA").'</span>';
  763. }
  764. print '</td>';
  765. }
  766. }
  767. // Budget task
  768. if (count($arrayfields) > 0 && !empty($arrayfields['t.budget_amount']['checked'])) {
  769. print '<td class="center">';
  770. if ($lines[$i]->budget_amount) {
  771. print '<span class="amount">'.price($lines[$i]->budget_amount, 0, $langs, 1, 0, 0, $conf->currency).'</span>';
  772. $total_budget_amount += $lines[$i]->budget_amount;
  773. }
  774. print '</td>';
  775. }
  776. // Contacts of task
  777. if (count($arrayfields) > 0 && !empty($arrayfields['c.assigned']['checked'])) {
  778. print '<td class="center">';
  779. $ifisrt = 1;
  780. foreach (array('internal', 'external') as $source) {
  781. $tab = $lines[$i]->liste_contact(-1, $source);
  782. $numcontact = count($tab);
  783. if (!empty($numcontact)) {
  784. foreach ($tab as $contacttask) {
  785. //var_dump($contacttask);
  786. if ($source == 'internal') {
  787. $c = new User($db);
  788. } else {
  789. $c = new Contact($db);
  790. }
  791. $c->fetch($contacttask['id']);
  792. if (!empty($c->photo)) {
  793. if (get_class($c) == 'User') {
  794. print $c->getNomUrl(-2, '', 0, 0, 24, 1, '', ($ifisrt ? '' : 'notfirst'));
  795. } else {
  796. print $c->getNomUrl(-2, '', 0, '', -1, 0, ($ifisrt ? '' : 'notfirst'));
  797. }
  798. } else {
  799. if (get_class($c) == 'User') {
  800. print $c->getNomUrl(2, '', 0, 0, 24, 1, '', ($ifisrt ? '' : 'notfirst'));
  801. } else {
  802. print $c->getNomUrl(2, '', 0, '', -1, 0, ($ifisrt ? '' : 'notfirst'));
  803. }
  804. }
  805. $ifisrt = 0;
  806. }
  807. }
  808. }
  809. print '</td>';
  810. }
  811. // Extra fields
  812. $extrafieldsobjectkey = $taskstatic->table_element;
  813. $obj = $lines[$i];
  814. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  815. // Fields from hook
  816. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$lines[$i]);
  817. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  818. print $hookmanager->resPrint;
  819. // Tick to drag and drop
  820. print '<td class="tdlineupdown center"></td>';
  821. print "</tr>\n";
  822. if (!$showlineingray) {
  823. $inc++;
  824. }
  825. if ($level >= 0) { // Call sublevels
  826. $level++;
  827. if ($lines[$i]->id) {
  828. projectLinesa($inc, $lines[$i]->id, $lines, $level, $var, $showproject, $taskrole, $projectsListId, $addordertick, $projectidfortotallink, $filterprogresscalc, $showbilltime, $arrayfields);
  829. }
  830. $level--;
  831. }
  832. $total_projectlinesa_spent += $lines[$i]->duration;
  833. $total_projectlinesa_planned += $lines[$i]->planned_workload;
  834. if ($lines[$i]->planned_workload) {
  835. $total_projectlinesa_spent_if_planned += $lines[$i]->duration;
  836. }
  837. if ($lines[$i]->planned_workload) {
  838. $total_projectlinesa_declared_if_planned += $lines[$i]->planned_workload * $lines[$i]->progress / 100;
  839. }
  840. }
  841. } else {
  842. //$level--;
  843. }
  844. }
  845. if (($total_projectlinesa_planned > 0 || $total_projectlinesa_spent > 0 || $total_projectlinesa_tobill > 0 || $total_projectlinesa_billed > 0 || $total_budget_amount > 0)
  846. && $level <= 0) {
  847. print '<tr class="liste_total nodrag nodrop">';
  848. print '<td class="liste_total">'.$langs->trans("Total").'</td>';
  849. if ($showproject) {
  850. print '<td></td><td></td>';
  851. }
  852. if (count($arrayfields) > 0 && !empty($arrayfields['t.label']['checked'])) {
  853. print '<td></td>';
  854. }
  855. if (count($arrayfields) > 0 && !empty($arrayfields['t.dateo']['checked'])) {
  856. print '<td></td>';
  857. }
  858. if (count($arrayfields) > 0 && !empty($arrayfields['t.datee']['checked'])) {
  859. print '<td></td>';
  860. }
  861. if (count($arrayfields) > 0 && !empty($arrayfields['t.planned_workload']['checked'])) {
  862. print '<td class="nowrap liste_total right">';
  863. print convertSecondToTime($total_projectlinesa_planned, 'allhourmin');
  864. print '</td>';
  865. }
  866. if (count($arrayfields) > 0 && !empty($arrayfields['t.duration_effective']['checked'])) {
  867. print '<td class="nowrap liste_total right">';
  868. if ($projectidfortotallink > 0) {
  869. print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?projectid='.$projectidfortotallink.($showproject ? '' : '&withproject=1').'">';
  870. }
  871. print convertSecondToTime($total_projectlinesa_spent, 'allhourmin');
  872. if ($projectidfortotallink > 0) {
  873. print '</a>';
  874. }
  875. print '</td>';
  876. }
  877. if ($total_projectlinesa_planned) {
  878. $totalAverageDeclaredProgress = round(100 * $total_projectlinesa_declared_if_planned / $total_projectlinesa_planned, 2);
  879. $totalCalculatedProgress = round(100 * $total_projectlinesa_spent / $total_projectlinesa_planned, 2);
  880. // this conf is actually hidden, by default we use 10% for "be carefull or warning"
  881. $warningRatio = !empty($conf->global->PROJECT_TIME_SPEND_WARNING_PERCENT) ? (1 + $conf->global->PROJECT_TIME_SPEND_WARNING_PERCENT / 100) : 1.10;
  882. // define progress color according to time spend vs workload
  883. $progressBarClass = 'progress-bar-info';
  884. $badgeClass = 'badge ';
  885. if ($totalCalculatedProgress > $totalAverageDeclaredProgress) {
  886. $progressBarClass = 'progress-bar-danger';
  887. $badgeClass .= 'badge-danger';
  888. } elseif ($totalCalculatedProgress * $warningRatio >= $totalAverageDeclaredProgress) { // warning if close at 1%
  889. $progressBarClass = 'progress-bar-warning';
  890. $badgeClass .= 'badge-warning';
  891. } else {
  892. $progressBarClass = 'progress-bar-success';
  893. $badgeClass .= 'badge-success';
  894. }
  895. }
  896. // Computed progress
  897. if (count($arrayfields) > 0 && !empty($arrayfields['t.progress_calculated']['checked'])) {
  898. print '<td class="nowrap liste_total right">';
  899. if ($total_projectlinesa_planned) {
  900. print $totalCalculatedProgress.' %';
  901. }
  902. print '</td>';
  903. }
  904. // Declared progress
  905. if (count($arrayfields) > 0 && !empty($arrayfields['t.progress']['checked'])) {
  906. print '<td class="nowrap liste_total right">';
  907. if ($total_projectlinesa_planned) {
  908. print '<span class="'.$badgeClass.'" >'.$totalAverageDeclaredProgress.' %</span>';
  909. }
  910. print '</td>';
  911. }
  912. // Progress
  913. if (count($arrayfields) > 0 && !empty($arrayfields['t.progress_summary']['checked'])) {
  914. print '<td class="right">';
  915. if ($total_projectlinesa_planned) {
  916. print '</span>';
  917. print ' <div class="progress sm" title="'.$totalAverageDeclaredProgress.'%" >';
  918. print ' <div class="progress-bar '.$progressBarClass.'" style="width: '.$totalAverageDeclaredProgress.'%"></div>';
  919. print ' </div>';
  920. print '</div>';
  921. }
  922. print '</td>';
  923. }
  924. if ($showbilltime) {
  925. if (count($arrayfields) > 0 && !empty($arrayfields['t.tobill']['checked'])) {
  926. print '<td class="nowrap liste_total right">';
  927. print convertSecondToTime($total_projectlinesa_tobill, 'allhourmin');
  928. print '</td>';
  929. }
  930. if (count($arrayfields) > 0 && !empty($arrayfields['t.billed']['checked'])) {
  931. print '<td class="nowrap liste_total right">';
  932. print convertSecondToTime($total_projectlinesa_billed, 'allhourmin');
  933. print '</td>';
  934. }
  935. }
  936. // Budget task
  937. if (count($arrayfields) > 0 && !empty($arrayfields['t.budget_amount']['checked'])) {
  938. print '<td class="nowrap liste_total center">';
  939. if (strcmp($total_budget_amount, '')) {
  940. print price($total_budget_amount, 0, $langs, 1, 0, 0, $conf->currency);
  941. }
  942. print '</td>';
  943. }
  944. // Contacts of task for backward compatibility,
  945. if (!empty($conf->global->PROJECT_SHOW_CONTACTS_IN_LIST)) {
  946. print '<td></td>';
  947. }
  948. // Contacts of task
  949. if (count($arrayfields) > 0 && !empty($arrayfields['c.assigned']['checked'])) {
  950. print '<td></td>';
  951. }
  952. print '<td class=""></td>';
  953. print '</tr>';
  954. }
  955. return $inc;
  956. }
  957. /**
  958. * Output a task line into a pertime intput mode
  959. *
  960. * @param string $inc Line number (start to 0, then increased by recursive call)
  961. * @param string $parent Id of parent task to show (0 to show all)
  962. * @param User|null $fuser Restrict list to user if defined
  963. * @param Task[] $lines Array of lines
  964. * @param int $level Level (start to 0, then increased/decrease by recursive call)
  965. * @param string $projectsrole Array of roles user has on project
  966. * @param string $tasksrole Array of roles user has on task
  967. * @param string $mine Show only task lines I am assigned to
  968. * @param int $restricteditformytask 0=No restriction, 1=Enable add time only if task is assigned to me, 2=Enable add time only if tasks is assigned to me and hide others
  969. * @param int $preselectedday Preselected day
  970. * @param array $isavailable Array with data that say if user is available for several days for morning and afternoon
  971. * @param int $oldprojectforbreak Old project id of last project break
  972. * @param array $arrayfields Array of additional column
  973. * @param Extrafields $extrafields Object extrafields
  974. * @return array Array with time spent for $fuser for each day of week on tasks in $lines and substasks
  975. */
  976. function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, $preselectedday, &$isavailable, $oldprojectforbreak = 0, $arrayfields = array(), $extrafields = null)
  977. {
  978. global $conf, $db, $user, $langs;
  979. global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
  980. $lastprojectid = 0;
  981. $totalforeachday = array();
  982. $workloadforid = array();
  983. $lineswithoutlevel0 = array();
  984. $numlines = count($lines);
  985. // Create a smaller array with sublevels only to be used later. This increase dramatically performances.
  986. if ($parent == 0) { // Always and only if at first level
  987. for ($i = 0; $i < $numlines; $i++) {
  988. if ($lines[$i]->fk_task_parent) {
  989. $lineswithoutlevel0[] = $lines[$i];
  990. }
  991. }
  992. }
  993. if (empty($oldprojectforbreak)) {
  994. $oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT) ? 0 : -1); // 0 to start break , -1 no break
  995. }
  996. $restrictBefore = null;
  997. if (!empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
  998. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  999. $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm');
  1000. }
  1001. //dol_syslog('projectLinesPerDay inc='.$inc.' preselectedday='.$preselectedday.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
  1002. for ($i = 0; $i < $numlines; $i++) {
  1003. if ($parent == 0) {
  1004. $level = 0;
  1005. }
  1006. if ($lines[$i]->fk_task_parent == $parent) {
  1007. $obj = &$lines[$i]; // To display extrafields
  1008. // If we want all or we have a role on task, we show it
  1009. if (empty($mine) || !empty($tasksrole[$lines[$i]->id])) {
  1010. //dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
  1011. if ($restricteditformytask == 2 && empty($tasksrole[$lines[$i]->id])) { // we have no role on task and we request to hide such cases
  1012. continue;
  1013. }
  1014. // Break on a new project
  1015. if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid) {
  1016. $lastprojectid = $lines[$i]->fk_project;
  1017. if ($preselectedday) {
  1018. $projectstatic->id = $lines[$i]->fk_project;
  1019. }
  1020. }
  1021. if (empty($workloadforid[$projectstatic->id])) {
  1022. if ($preselectedday) {
  1023. $projectstatic->loadTimeSpent($preselectedday, 0, $fuser->id); // Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
  1024. $workloadforid[$projectstatic->id] = 1;
  1025. }
  1026. }
  1027. $projectstatic->id = $lines[$i]->fk_project;
  1028. $projectstatic->ref = $lines[$i]->projectref;
  1029. $projectstatic->title = $lines[$i]->projectlabel;
  1030. $projectstatic->public = $lines[$i]->public;
  1031. $projectstatic->status = $lines[$i]->projectstatus;
  1032. $taskstatic->id = $lines[$i]->id;
  1033. $taskstatic->ref = ($lines[$i]->ref ? $lines[$i]->ref : $lines[$i]->id);
  1034. $taskstatic->label = $lines[$i]->label;
  1035. $taskstatic->date_start = $lines[$i]->date_start;
  1036. $taskstatic->date_end = $lines[$i]->date_end;
  1037. $thirdpartystatic->id = $lines[$i]->socid;
  1038. $thirdpartystatic->name = $lines[$i]->thirdparty_name;
  1039. $thirdpartystatic->email = $lines[$i]->thirdparty_email;
  1040. if (empty($oldprojectforbreak) || ($oldprojectforbreak != -1 && $oldprojectforbreak != $projectstatic->id)) {
  1041. $addcolspan = 0;
  1042. if (!empty($arrayfields['t.planned_workload']['checked'])) {
  1043. $addcolspan++;
  1044. }
  1045. if (!empty($arrayfields['t.progress']['checked'])) {
  1046. $addcolspan++;
  1047. }
  1048. foreach ($arrayfields as $key => $val) {
  1049. if ($val['checked'] && substr($key, 0, 5) == 'efpt.') {
  1050. $addcolspan++;
  1051. }
  1052. }
  1053. print '<tr class="oddeven trforbreak nobold">'."\n";
  1054. print '<td colspan="'.(7 + $addcolspan).'">';
  1055. print $projectstatic->getNomUrl(1, '', 0, '<strong>'.$langs->transnoentitiesnoconv("YourRole").':</strong> '.$projectsrole[$lines[$i]->fk_project]);
  1056. if ($thirdpartystatic->id > 0) {
  1057. print ' - '.$thirdpartystatic->getNomUrl(1);
  1058. }
  1059. if ($projectstatic->title) {
  1060. print ' - ';
  1061. print '<span class="secondary">'.$projectstatic->title.'</span>';
  1062. }
  1063. /*
  1064. $colspan=5+(empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)?0:2);
  1065. print '<table class="">';
  1066. print '<tr class="liste_titre">';
  1067. // PROJECT fields
  1068. if (!empty($arrayfields['p.fk_opp_status']['checked'])) print_liste_field_titre($arrayfields['p.fk_opp_status']['label'], $_SERVER["PHP_SELF"], 'p.fk_opp_status', "", $param, '', $sortfield, $sortorder, 'center ');
  1069. if (!empty($arrayfields['p.opp_amount']['checked'])) print_liste_field_titre($arrayfields['p.opp_amount']['label'], $_SERVER["PHP_SELF"], 'p.opp_amount', "", $param, '', $sortfield, $sortorder, 'right ');
  1070. if (!empty($arrayfields['p.opp_percent']['checked'])) print_liste_field_titre($arrayfields['p.opp_percent']['label'], $_SERVER["PHP_SELF"], 'p.opp_percent', "", $param, '', $sortfield, $sortorder, 'right ');
  1071. if (!empty($arrayfields['p.budget_amount']['checked'])) print_liste_field_titre($arrayfields['p.budget_amount']['label'], $_SERVER["PHP_SELF"], 'p.budget_amount', "", $param, '', $sortfield, $sortorder, 'right ');
  1072. if (!empty($arrayfields['p.usage_bill_time']['checked'])) print_liste_field_titre($arrayfields['p.usage_bill_time']['label'], $_SERVER["PHP_SELF"], 'p.usage_bill_time', "", $param, '', $sortfield, $sortorder, 'right ');
  1073. $extrafieldsobjectkey='projet';
  1074. $extrafieldsobjectprefix='efp.';
  1075. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1076. print '</tr>';
  1077. print '<tr>';
  1078. // PROJECT fields
  1079. if (!empty($arrayfields['p.fk_opp_status']['checked']))
  1080. {
  1081. print '<td class="nowrap">';
  1082. $code = dol_getIdFromCode($db, $lines[$i]->fk_opp_status, 'c_lead_status', 'rowid', 'code');
  1083. if ($code) print $langs->trans("OppStatus".$code);
  1084. print "</td>\n";
  1085. }
  1086. if (!empty($arrayfields['p.opp_amount']['checked']))
  1087. {
  1088. print '<td class="nowrap">';
  1089. print price($lines[$i]->opp_amount, 0, $langs, 1, 0, -1, $conf->currency);
  1090. print "</td>\n";
  1091. }
  1092. if (!empty($arrayfields['p.opp_percent']['checked']))
  1093. {
  1094. print '<td class="nowrap">';
  1095. print price($lines[$i]->opp_percent, 0, $langs, 1, 0).' %';
  1096. print "</td>\n";
  1097. }
  1098. if (!empty($arrayfields['p.budget_amount']['checked']))
  1099. {
  1100. print '<td class="nowrap">';
  1101. print price($lines[$i]->budget_amount, 0, $langs, 1, 0, 0, $conf->currency);
  1102. print "</td>\n";
  1103. }
  1104. if (!empty($arrayfields['p.usage_bill_time']['checked']))
  1105. {
  1106. print '<td class="nowrap">';
  1107. print yn($lines[$i]->usage_bill_time);
  1108. print "</td>\n";
  1109. }
  1110. $extrafieldsobjectkey='projet';
  1111. $extrafieldsobjectprefix='efp.';
  1112. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1113. print '</tr>';
  1114. print '</table>';
  1115. */
  1116. print '</td>';
  1117. print '</tr>';
  1118. }
  1119. if ($oldprojectforbreak != -1) {
  1120. $oldprojectforbreak = $projectstatic->id;
  1121. }
  1122. print '<tr class="oddeven" data-taskid="'.$lines[$i]->id.'">'."\n";
  1123. // User
  1124. /*
  1125. print '<td class="nowrap">';
  1126. print $fuser->getNomUrl(1, 'withproject', 'time');
  1127. print '</td>';
  1128. */
  1129. // Project
  1130. if (!empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)) {
  1131. print "<td>";
  1132. if ($oldprojectforbreak == -1) {
  1133. print $projectstatic->getNomUrl(1, '', 0, $langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
  1134. }
  1135. print "</td>";
  1136. }
  1137. // Thirdparty
  1138. if (!empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)) {
  1139. print '<td class="tdoverflowmax100">';
  1140. if ($thirdpartystatic->id > 0) {
  1141. print $thirdpartystatic->getNomUrl(1, 'project', 10);
  1142. }
  1143. print '</td>';
  1144. }
  1145. // Ref
  1146. print '<td>';
  1147. print '<!-- Task id = '.$lines[$i]->id.' -->';
  1148. for ($k = 0; $k < $level; $k++) {
  1149. print '<div class="marginleftonly">';
  1150. }
  1151. print $taskstatic->getNomUrl(1, 'withproject', 'time');
  1152. // Label task
  1153. print '<br>';
  1154. print '<span class="opacitymedium">'.$taskstatic->label.'</a>';
  1155. for ($k = 0; $k < $level; $k++) {
  1156. print "</div>";
  1157. }
  1158. print "</td>\n";
  1159. // TASK extrafields
  1160. $extrafieldsobjectkey = 'projet_task';
  1161. $extrafieldsobjectprefix = 'efpt.';
  1162. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1163. // Planned Workload
  1164. if (!empty($arrayfields['t.planned_workload']['checked'])) {
  1165. print '<td class="leftborder plannedworkload right">';
  1166. if ($lines[$i]->planned_workload) {
  1167. print convertSecondToTime($lines[$i]->planned_workload, 'allhourmin');
  1168. } else {
  1169. print '--:--';
  1170. }
  1171. print '</td>';
  1172. }
  1173. // Progress declared %
  1174. if (!empty($arrayfields['t.progress']['checked'])) {
  1175. print '<td class="right">';
  1176. print $formother->select_percent($lines[$i]->progress, $lines[$i]->id.'progress');
  1177. print '</td>';
  1178. }
  1179. if (!empty($arrayfields['timeconsumed']['checked'])) {
  1180. // Time spent by everybody
  1181. print '<td class="right">';
  1182. // $lines[$i]->duration is a denormalised field = summ of time spent by everybody for task. What we need is time consumed by user
  1183. if ($lines[$i]->duration) {
  1184. print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.'">';
  1185. print convertSecondToTime($lines[$i]->duration, 'allhourmin');
  1186. print '</a>';
  1187. } else {
  1188. print '--:--';
  1189. }
  1190. print "</td>\n";
  1191. // Time spent by user
  1192. print '<td class="right">';
  1193. $tmptimespent = $taskstatic->getSummaryOfTimeSpent($fuser->id);
  1194. if ($tmptimespent['total_duration']) {
  1195. print convertSecondToTime($tmptimespent['total_duration'], 'allhourmin');
  1196. } else {
  1197. print '--:--';
  1198. }
  1199. print "</td>\n";
  1200. }
  1201. $disabledproject = 1;
  1202. $disabledtask = 1;
  1203. //print "x".$lines[$i]->fk_project;
  1204. //var_dump($lines[$i]);
  1205. //var_dump($projectsrole[$lines[$i]->fk_project]);
  1206. // If at least one role for project
  1207. if ($lines[$i]->public || !empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer) {
  1208. $disabledproject = 0;
  1209. $disabledtask = 0;
  1210. }
  1211. // If $restricteditformytask is on and I have no role on task, i disable edit
  1212. if ($restricteditformytask && empty($tasksrole[$lines[$i]->id])) {
  1213. $disabledtask = 1;
  1214. }
  1215. if ($restrictBefore && $preselectedday < $restrictBefore) {
  1216. $disabledtask = 1;
  1217. }
  1218. // Select hour
  1219. print '<td class="nowraponall leftborder center minwidth150imp">';
  1220. $tableCell = $form->selectDate($preselectedday, $lines[$i]->id, 1, 1, 2, "addtime", 0, 0, $disabledtask);
  1221. print $tableCell;
  1222. print '</td>';
  1223. $cssonholiday = '';
  1224. if (!$isavailable[$preselectedday]['morning'] && !$isavailable[$preselectedday]['afternoon']) {
  1225. $cssonholiday .= 'onholidayallday ';
  1226. } elseif (!$isavailable[$preselectedday]['morning']) {
  1227. $cssonholiday .= 'onholidaymorning ';
  1228. } elseif (!$isavailable[$preselectedday]['afternoon']) {
  1229. $cssonholiday .= 'onholidayafternoon ';
  1230. }
  1231. global $daytoparse;
  1232. $tmparray = dol_getdate($daytoparse, true); // detail of current day
  1233. $idw = ($tmparray['wday'] - (empty($conf->global->MAIN_START_WEEK) ? 0 : 1));
  1234. global $numstartworkingday, $numendworkingday;
  1235. $cssweekend = '';
  1236. if ((($idw + 1) < $numstartworkingday) || (($idw + 1) > $numendworkingday)) { // This is a day is not inside the setup of working days, so we use a week-end css.
  1237. $cssweekend = 'weekend';
  1238. }
  1239. // Duration
  1240. print '<td class="center duration'.($cssonholiday ? ' '.$cssonholiday : '').($cssweekend ? ' '.$cssweekend : '').'">';
  1241. $dayWorkLoad = !empty($projectstatic->weekWorkLoadPerTask[$preselectedday][$lines[$i]->id]) ? $projectstatic->weekWorkLoadPerTask[$preselectedday][$lines[$i]->id] : 0;
  1242. if (!isset($totalforeachday[$preselectedday])) $totalforeachday[$preselectedday] = 0;
  1243. $totalforeachday[$preselectedday] += $dayWorkLoad;
  1244. $alreadyspent = '';
  1245. if ($dayWorkLoad > 0) {
  1246. $alreadyspent = convertSecondToTime($dayWorkLoad, 'allhourmin');
  1247. }
  1248. $idw = 0;
  1249. $tableCell = '';
  1250. $tableCell .= '<span class="timesheetalreadyrecorded" title="texttoreplace"><input type="text" class="center" size="2" disabled id="timespent['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="'.$alreadyspent.'"></span>';
  1251. $tableCell .= '<span class="hideonsmartphone"> + </span>';
  1252. //$tableCell.='&nbsp;&nbsp;&nbsp;';
  1253. $tableCell .= $form->select_duration($lines[$i]->id.'duration', '', $disabledtask, 'text', 0, 1);
  1254. //$tableCell.='&nbsp;<input type="submit" class="button"'.($disabledtask?' disabled':'').' value="'.$langs->trans("Add").'">';
  1255. print $tableCell;
  1256. // Comment for avoid unnecessary multiple calculation
  1257. /*$modeinput = 'hours';
  1258. print '<script type="text/javascript">';
  1259. print "jQuery(document).ready(function () {\n";
  1260. print " jQuery('.inputhour, .inputminute').bind('keyup', function(e) { updateTotal(0, '".$modeinput."') });";
  1261. print "})\n";
  1262. print '</script>';*/
  1263. print '</td>';
  1264. // Note
  1265. print '<td class="center">';
  1266. print '<textarea name="'.$lines[$i]->id.'note" rows="'.ROWS_2.'" id="'.$lines[$i]->id.'note"'.($disabledtask ? ' disabled="disabled"' : '').'>';
  1267. print '</textarea>';
  1268. print '</td>';
  1269. // Warning
  1270. print '<td class="right">';
  1271. if ((!$lines[$i]->public) && $disabledproject) {
  1272. print $form->textwithpicto('', $langs->trans("UserIsNotContactOfProject"));
  1273. } elseif ($disabledtask) {
  1274. $titleassigntask = $langs->trans("AssignTaskToMe");
  1275. if ($fuser->id != $user->id) {
  1276. $titleassigntask = $langs->trans("AssignTaskToUser", '...');
  1277. }
  1278. print $form->textwithpicto('', $langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
  1279. }
  1280. print '</td>';
  1281. print "</tr>\n";
  1282. }
  1283. $inc++;
  1284. $level++;
  1285. if ($lines[$i]->id > 0) {
  1286. //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level);
  1287. //var_dump($totalforeachday);
  1288. $ret = projectLinesPerDay($inc, $lines[$i]->id, $fuser, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $isavailable, $oldprojectforbreak, $arrayfields, $extrafields);
  1289. //var_dump('ret with parent='.$lines[$i]->id.' level='.$level);
  1290. //var_dump($ret);
  1291. foreach ($ret as $key => $val) {
  1292. $totalforeachday[$key] += $val;
  1293. }
  1294. //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level.' + subtasks');
  1295. //var_dump($totalforeachday);
  1296. }
  1297. $level--;
  1298. } else {
  1299. //$level--;
  1300. }
  1301. }
  1302. return $totalforeachday;
  1303. }
  1304. /**
  1305. * Output a task line into a perday intput mode
  1306. *
  1307. * @param string $inc Line output identificator (start to 0, then increased by recursive call)
  1308. * @param int $firstdaytoshow First day to show
  1309. * @param User|null $fuser Restrict list to user if defined
  1310. * @param string $parent Id of parent task to show (0 to show all)
  1311. * @param Task[] $lines Array of lines (list of tasks but we will show only if we have a specific role on task)
  1312. * @param int $level Level (start to 0, then increased/decrease by recursive call)
  1313. * @param string $projectsrole Array of roles user has on project
  1314. * @param string $tasksrole Array of roles user has on task
  1315. * @param string $mine Show only task lines I am assigned to
  1316. * @param int $restricteditformytask 0=No restriction, 1=Enable add time only if task is assigned to me, 2=Enable add time only if tasks is assigned to me and hide others
  1317. * @param array $isavailable Array with data that say if user is available for several days for morning and afternoon
  1318. * @param int $oldprojectforbreak Old project id of last project break
  1319. * @param array $arrayfields Array of additional column
  1320. * @param Extrafields $extrafields Object extrafields
  1321. * @return array Array with time spent for $fuser for each day of week on tasks in $lines and substasks
  1322. */
  1323. function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, &$isavailable, $oldprojectforbreak = 0, $arrayfields = array(), $extrafields = null)
  1324. {
  1325. global $conf, $db, $user, $langs;
  1326. global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
  1327. $numlines = count($lines);
  1328. $lastprojectid = 0;
  1329. $workloadforid = array();
  1330. $totalforeachday = array();
  1331. $lineswithoutlevel0 = array();
  1332. // Create a smaller array with sublevels only to be used later. This increase dramatically performances.
  1333. if ($parent == 0) { // Always and only if at first level
  1334. for ($i = 0; $i < $numlines; $i++) {
  1335. if ($lines[$i]->fk_task_parent) {
  1336. $lineswithoutlevel0[] = $lines[$i];
  1337. }
  1338. }
  1339. }
  1340. //dol_syslog('projectLinesPerWeek inc='.$inc.' firstdaytoshow='.$firstdaytoshow.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
  1341. if (empty($oldprojectforbreak)) {
  1342. $oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT) ? 0 : -1); // 0 = start break, -1 = never break
  1343. }
  1344. $restrictBefore = null;
  1345. if (!empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
  1346. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  1347. $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm');
  1348. }
  1349. for ($i = 0; $i < $numlines; $i++) {
  1350. if ($parent == 0) {
  1351. $level = 0;
  1352. }
  1353. if ($lines[$i]->fk_task_parent == $parent) {
  1354. $obj = &$lines[$i]; // To display extrafields
  1355. // If we want all or we have a role on task, we show it
  1356. if (empty($mine) || !empty($tasksrole[$lines[$i]->id])) {
  1357. //dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
  1358. if ($restricteditformytask == 2 && empty($tasksrole[$lines[$i]->id])) { // we have no role on task and we request to hide such cases
  1359. continue;
  1360. }
  1361. // Break on a new project
  1362. if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid) {
  1363. $lastprojectid = $lines[$i]->fk_project;
  1364. $projectstatic->id = $lines[$i]->fk_project;
  1365. }
  1366. //var_dump('--- '.$level.' '.$firstdaytoshow.' '.$fuser->id.' '.$projectstatic->id.' '.$workloadforid[$projectstatic->id]);
  1367. //var_dump($projectstatic->weekWorkLoadPerTask);
  1368. if (empty($workloadforid[$projectstatic->id])) {
  1369. $projectstatic->loadTimeSpent($firstdaytoshow, 0, $fuser->id); // Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
  1370. $workloadforid[$projectstatic->id] = 1;
  1371. }
  1372. //var_dump($projectstatic->weekWorkLoadPerTask);
  1373. //var_dump('--- '.$projectstatic->id.' '.$workloadforid[$projectstatic->id]);
  1374. $projectstatic->id = $lines[$i]->fk_project;
  1375. $projectstatic->ref = $lines[$i]->projectref;
  1376. $projectstatic->title = $lines[$i]->projectlabel;
  1377. $projectstatic->public = $lines[$i]->public;
  1378. $projectstatic->thirdparty_name = $lines[$i]->thirdparty_name;
  1379. $projectstatic->status = $lines[$i]->projectstatus;
  1380. $taskstatic->id = $lines[$i]->id;
  1381. $taskstatic->ref = ($lines[$i]->ref ? $lines[$i]->ref : $lines[$i]->id);
  1382. $taskstatic->label = $lines[$i]->label;
  1383. $taskstatic->date_start = $lines[$i]->date_start;
  1384. $taskstatic->date_end = $lines[$i]->date_end;
  1385. $thirdpartystatic->id = $lines[$i]->thirdparty_id;
  1386. $thirdpartystatic->name = $lines[$i]->thirdparty_name;
  1387. $thirdpartystatic->email = $lines[$i]->thirdparty_email;
  1388. if (empty($oldprojectforbreak) || ($oldprojectforbreak != -1 && $oldprojectforbreak != $projectstatic->id)) {
  1389. $addcolspan = 0;
  1390. if (!empty($arrayfields['t.planned_workload']['checked'])) {
  1391. $addcolspan++;
  1392. }
  1393. if (!empty($arrayfields['t.progress']['checked'])) {
  1394. $addcolspan++;
  1395. }
  1396. foreach ($arrayfields as $key => $val) {
  1397. if ($val['checked'] && substr($key, 0, 5) == 'efpt.') {
  1398. $addcolspan++;
  1399. }
  1400. }
  1401. print '<tr class="oddeven trforbreak nobold">'."\n";
  1402. print '<td colspan="'.(11 + $addcolspan).'">';
  1403. print $projectstatic->getNomUrl(1, '', 0, '<strong>'.$langs->transnoentitiesnoconv("YourRole").':</strong> '.$projectsrole[$lines[$i]->fk_project]);
  1404. if ($thirdpartystatic->id > 0) {
  1405. print ' - '.$thirdpartystatic->getNomUrl(1);
  1406. }
  1407. if ($projectstatic->title) {
  1408. print ' - ';
  1409. print '<span class="secondary">'.$projectstatic->title.'</span>';
  1410. }
  1411. /*$colspan=5+(empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)?0:2);
  1412. print '<table class="">';
  1413. print '<tr class="liste_titre">';
  1414. // PROJECT fields
  1415. if (!empty($arrayfields['p.fk_opp_status']['checked'])) print_liste_field_titre($arrayfields['p.fk_opp_status']['label'], $_SERVER["PHP_SELF"], 'p.fk_opp_status', "", $param, '', $sortfield, $sortorder, 'center ');
  1416. if (!empty($arrayfields['p.opp_amount']['checked'])) print_liste_field_titre($arrayfields['p.opp_amount']['label'], $_SERVER["PHP_SELF"], 'p.opp_amount', "", $param, '', $sortfield, $sortorder, 'right ');
  1417. if (!empty($arrayfields['p.opp_percent']['checked'])) print_liste_field_titre($arrayfields['p.opp_percent']['label'], $_SERVER["PHP_SELF"], 'p.opp_percent', "", $param, '', $sortfield, $sortorder, 'right ');
  1418. if (!empty($arrayfields['p.budget_amount']['checked'])) print_liste_field_titre($arrayfields['p.budget_amount']['label'], $_SERVER["PHP_SELF"], 'p.budget_amount', "", $param, '', $sortfield, $sortorder, 'right ');
  1419. if (!empty($arrayfields['p.usage_bill_time']['checked'])) print_liste_field_titre($arrayfields['p.usage_bill_time']['label'], $_SERVER["PHP_SELF"], 'p.usage_bill_time', "", $param, '', $sortfield, $sortorder, 'right ');
  1420. $extrafieldsobjectkey='projet';
  1421. $extrafieldsobjectprefix='efp.';
  1422. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1423. print '</tr>';
  1424. print '<tr>';
  1425. // PROJECT fields
  1426. if (!empty($arrayfields['p.fk_opp_status']['checked']))
  1427. {
  1428. print '<td class="nowrap">';
  1429. $code = dol_getIdFromCode($db, $lines[$i]->fk_opp_status, 'c_lead_status', 'rowid', 'code');
  1430. if ($code) print $langs->trans("OppStatus".$code);
  1431. print "</td>\n";
  1432. }
  1433. if (!empty($arrayfields['p.opp_amount']['checked']))
  1434. {
  1435. print '<td class="nowrap">';
  1436. print price($lines[$i]->opp_amount, 0, $langs, 1, 0, -1, $conf->currency);
  1437. print "</td>\n";
  1438. }
  1439. if (!empty($arrayfields['p.opp_percent']['checked']))
  1440. {
  1441. print '<td class="nowrap">';
  1442. print price($lines[$i]->opp_percent, 0, $langs, 1, 0).' %';
  1443. print "</td>\n";
  1444. }
  1445. if (!empty($arrayfields['p.budget_amount']['checked']))
  1446. {
  1447. print '<td class="nowrap">';
  1448. print price($lines[$i]->budget_amount, 0, $langs, 1, 0, 0, $conf->currency);
  1449. print "</td>\n";
  1450. }
  1451. if (!empty($arrayfields['p.usage_bill_time']['checked']))
  1452. {
  1453. print '<td class="nowrap">';
  1454. print yn($lines[$i]->usage_bill_time);
  1455. print "</td>\n";
  1456. }
  1457. $extrafieldsobjectkey='projet';
  1458. $extrafieldsobjectprefix='efp.';
  1459. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1460. print '</tr>';
  1461. print '</table>';
  1462. */
  1463. print '</td>';
  1464. print '</tr>';
  1465. }
  1466. if ($oldprojectforbreak != -1) {
  1467. $oldprojectforbreak = $projectstatic->id;
  1468. }
  1469. print '<tr class="oddeven" data-taskid="'.$lines[$i]->id.'">'."\n";
  1470. // User
  1471. /*
  1472. print '<td class="nowrap">';
  1473. print $fuser->getNomUrl(1, 'withproject', 'time');
  1474. print '</td>';
  1475. */
  1476. // Project
  1477. if (!empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)) {
  1478. print '<td class="nowrap">';
  1479. if ($oldprojectforbreak == -1) {
  1480. print $projectstatic->getNomUrl(1, '', 0, $langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
  1481. }
  1482. print "</td>";
  1483. }
  1484. // Thirdparty
  1485. if (!empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)) {
  1486. print '<td class="tdoverflowmax100">';
  1487. if ($thirdpartystatic->id > 0) {
  1488. print $thirdpartystatic->getNomUrl(1, 'project');
  1489. }
  1490. print '</td>';
  1491. }
  1492. // Ref
  1493. print '<td class="nowrap">';
  1494. print '<!-- Task id = '.$lines[$i]->id.' -->';
  1495. for ($k = 0; $k < $level; $k++) {
  1496. print '<div class="marginleftonly">';
  1497. }
  1498. print $taskstatic->getNomUrl(1, 'withproject', 'time');
  1499. // Label task
  1500. print '<br>';
  1501. print '<span class="opacitymedium">'.$taskstatic->label.'</span>';
  1502. for ($k = 0; $k < $level; $k++) {
  1503. print "</div>";
  1504. }
  1505. print "</td>\n";
  1506. // TASK extrafields
  1507. $extrafieldsobjectkey = 'projet_task';
  1508. $extrafieldsobjectprefix = 'efpt.';
  1509. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1510. // Planned Workload
  1511. if (!empty($arrayfields['t.planned_workload']['checked'])) {
  1512. print '<td class="leftborder plannedworkload right">';
  1513. if ($lines[$i]->planned_workload) {
  1514. print convertSecondToTime($lines[$i]->planned_workload, 'allhourmin');
  1515. } else {
  1516. print '--:--';
  1517. }
  1518. print '</td>';
  1519. }
  1520. if (!empty($arrayfields['t.progress']['checked'])) {
  1521. // Progress declared %
  1522. print '<td class="right">';
  1523. print $formother->select_percent($lines[$i]->progress, $lines[$i]->id.'progress');
  1524. print '</td>';
  1525. }
  1526. if (!empty($arrayfields['timeconsumed']['checked'])) {
  1527. // Time spent by everybody
  1528. print '<td class="right">';
  1529. // $lines[$i]->duration is a denormalised field = summ of time spent by everybody for task. What we need is time consumed by user
  1530. if ($lines[$i]->duration) {
  1531. print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.'">';
  1532. print convertSecondToTime($lines[$i]->duration, 'allhourmin');
  1533. print '</a>';
  1534. } else {
  1535. print '--:--';
  1536. }
  1537. print "</td>\n";
  1538. // Time spent by user
  1539. print '<td class="right">';
  1540. $tmptimespent = $taskstatic->getSummaryOfTimeSpent($fuser->id);
  1541. if ($tmptimespent['total_duration']) {
  1542. print convertSecondToTime($tmptimespent['total_duration'], 'allhourmin');
  1543. } else {
  1544. print '--:--';
  1545. }
  1546. print "</td>\n";
  1547. }
  1548. $disabledproject = 1;
  1549. $disabledtask = 1;
  1550. //print "x".$lines[$i]->fk_project;
  1551. //var_dump($lines[$i]);
  1552. //var_dump($projectsrole[$lines[$i]->fk_project]);
  1553. // If at least one role for project
  1554. if ($lines[$i]->public || !empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer) {
  1555. $disabledproject = 0;
  1556. $disabledtask = 0;
  1557. }
  1558. // If $restricteditformytask is on and I have no role on task, i disable edit
  1559. if ($restricteditformytask && empty($tasksrole[$lines[$i]->id])) {
  1560. $disabledtask = 1;
  1561. }
  1562. //var_dump($projectstatic->weekWorkLoadPerTask);
  1563. // Fields to show current time
  1564. $tableCell = '';
  1565. $modeinput = 'hours';
  1566. for ($idw = 0; $idw < 7; $idw++) {
  1567. $tmpday = dol_time_plus_duree($firstdaytoshow, $idw, 'd');
  1568. if (!isset($totalforeachday[$tmpday])) $totalforeachday[$tmpday] = 0;
  1569. $cssonholiday = '';
  1570. if (!$isavailable[$tmpday]['morning'] && !$isavailable[$tmpday]['afternoon']) {
  1571. $cssonholiday .= 'onholidayallday ';
  1572. } elseif (!$isavailable[$tmpday]['morning']) {
  1573. $cssonholiday .= 'onholidaymorning ';
  1574. } elseif (!$isavailable[$tmpday]['afternoon']) {
  1575. $cssonholiday .= 'onholidayafternoon ';
  1576. }
  1577. $tmparray = dol_getdate($tmpday);
  1578. $dayWorkLoad = (!empty($projectstatic->weekWorkLoadPerTask[$tmpday][$lines[$i]->id]) ? $projectstatic->weekWorkLoadPerTask[$tmpday][$lines[$i]->id] : 0);
  1579. $totalforeachday[$tmpday] += $dayWorkLoad;
  1580. $alreadyspent = '';
  1581. if ($dayWorkLoad > 0) {
  1582. $alreadyspent = convertSecondToTime($dayWorkLoad, 'allhourmin');
  1583. }
  1584. $alttitle = $langs->trans("AddHereTimeSpentForDay", !empty($tmparray['day']) ? $tmparray['day'] : 0, $tmparray['mon']);
  1585. global $numstartworkingday, $numendworkingday;
  1586. $cssweekend = '';
  1587. if (($idw + 1 < $numstartworkingday) || ($idw + 1 > $numendworkingday)) { // This is a day is not inside the setup of working days, so we use a week-end css.
  1588. $cssweekend = 'weekend';
  1589. }
  1590. $disabledtaskday = $disabledtask;
  1591. if (! $disabledtask && $restrictBefore && $tmpday < $restrictBefore) {
  1592. $disabledtaskday = 1;
  1593. }
  1594. $tableCell = '<td class="center hide'.$idw.($cssonholiday ? ' '.$cssonholiday : '').($cssweekend ? ' '.$cssweekend : '').'">';
  1595. //$tableCell .= 'idw='.$idw.' '.$conf->global->MAIN_START_WEEK.' '.$numstartworkingday.'-'.$numendworkingday;
  1596. $placeholder = '';
  1597. if ($alreadyspent) {
  1598. $tableCell .= '<span class="timesheetalreadyrecorded" title="texttoreplace"><input type="text" class="center smallpadd" size="2" disabled id="timespent['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="'.$alreadyspent.'"></span>';
  1599. //$placeholder=' placeholder="00:00"';
  1600. //$tableCell.='+';
  1601. }
  1602. $tableCell .= '<input type="text" alt="'.($disabledtaskday ? '' : $alttitle).'" title="'.($disabledtaskday ? '' : $alttitle).'" '.($disabledtaskday ? 'disabled' : $placeholder).' class="center smallpadd" size="2" id="timeadded['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="" cols="2" maxlength="5"';
  1603. $tableCell .= ' onkeypress="return regexEvent(this,event,\'timeChar\')"';
  1604. $tableCell .= ' onkeyup="updateTotal('.$idw.',\''.$modeinput.'\')"';
  1605. $tableCell .= ' onblur="regexEvent(this,event,\''.$modeinput.'\'); updateTotal('.$idw.',\''.$modeinput.'\')" />';
  1606. $tableCell .= '</td>';
  1607. print $tableCell;
  1608. }
  1609. // Warning
  1610. print '<td class="right">';
  1611. if ((!$lines[$i]->public) && $disabledproject) {
  1612. print $form->textwithpicto('', $langs->trans("UserIsNotContactOfProject"));
  1613. } elseif ($disabledtask) {
  1614. $titleassigntask = $langs->trans("AssignTaskToMe");
  1615. if ($fuser->id != $user->id) {
  1616. $titleassigntask = $langs->trans("AssignTaskToUser", '...');
  1617. }
  1618. print $form->textwithpicto('', $langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
  1619. }
  1620. print '</td>';
  1621. print "</tr>\n";
  1622. }
  1623. // Call to show task with a lower level (task under the current task)
  1624. $inc++;
  1625. $level++;
  1626. if ($lines[$i]->id > 0) {
  1627. //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level);
  1628. //var_dump($totalforeachday);
  1629. $ret = projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $isavailable, $oldprojectforbreak, $arrayfields, $extrafields);
  1630. //var_dump('ret with parent='.$lines[$i]->id.' level='.$level);
  1631. //var_dump($ret);
  1632. foreach ($ret as $key => $val) {
  1633. $totalforeachday[$key] += $val;
  1634. }
  1635. //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level.' + subtasks');
  1636. //var_dump($totalforeachday);
  1637. }
  1638. $level--;
  1639. } else {
  1640. //$level--;
  1641. }
  1642. }
  1643. return $totalforeachday;
  1644. }
  1645. /**
  1646. * Output a task line into a perday intput mode
  1647. *
  1648. * @param string $inc Line output identificator (start to 0, then increased by recursive call)
  1649. * @param int $firstdaytoshow First day to show
  1650. * @param User|null $fuser Restrict list to user if defined
  1651. * @param string $parent Id of parent task to show (0 to show all)
  1652. * @param Task[] $lines Array of lines (list of tasks but we will show only if we have a specific role on task)
  1653. * @param int $level Level (start to 0, then increased/decrease by recursive call)
  1654. * @param string $projectsrole Array of roles user has on project
  1655. * @param string $tasksrole Array of roles user has on task
  1656. * @param string $mine Show only task lines I am assigned to
  1657. * @param int $restricteditformytask 0=No restriction, 1=Enable add time only if task is a task i am affected to
  1658. * @param array $isavailable Array with data that say if user is available for several days for morning and afternoon
  1659. * @param int $oldprojectforbreak Old project id of last project break
  1660. * @param array $TWeek Array of week numbers
  1661. * @return array Array with time spent for $fuser for each day of week on tasks in $lines and substasks
  1662. */
  1663. function projectLinesPerMonth(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, &$isavailable, $oldprojectforbreak = 0, $TWeek = array())
  1664. {
  1665. global $conf, $db, $user, $langs;
  1666. global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
  1667. $numlines = count($lines);
  1668. $lastprojectid = 0;
  1669. $workloadforid = array();
  1670. $totalforeachweek = array();
  1671. $lineswithoutlevel0 = array();
  1672. // Create a smaller array with sublevels only to be used later. This increase dramatically performances.
  1673. if ($parent == 0) { // Always and only if at first level
  1674. for ($i = 0; $i < $numlines; $i++) {
  1675. if ($lines[$i]->fk_task_parent) {
  1676. $lineswithoutlevel0[] = $lines[$i];
  1677. }
  1678. }
  1679. }
  1680. //dol_syslog('projectLinesPerWeek inc='.$inc.' firstdaytoshow='.$firstdaytoshow.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
  1681. if (empty($oldprojectforbreak)) {
  1682. $oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT) ? 0 : -1); // 0 = start break, -1 = never break
  1683. }
  1684. $restrictBefore = null;
  1685. if (!empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
  1686. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  1687. $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm');
  1688. }
  1689. for ($i = 0; $i < $numlines; $i++) {
  1690. if ($parent == 0) {
  1691. $level = 0;
  1692. }
  1693. if ($lines[$i]->fk_task_parent == $parent) {
  1694. // If we want all or we have a role on task, we show it
  1695. if (empty($mine) || !empty($tasksrole[$lines[$i]->id])) {
  1696. //dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
  1697. // Break on a new project
  1698. if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid) {
  1699. $lastprojectid = $lines[$i]->fk_project;
  1700. $projectstatic->id = $lines[$i]->fk_project;
  1701. }
  1702. //var_dump('--- '.$level.' '.$firstdaytoshow.' '.$fuser->id.' '.$projectstatic->id.' '.$workloadforid[$projectstatic->id]);
  1703. //var_dump($projectstatic->weekWorkLoadPerTask);
  1704. if (empty($workloadforid[$projectstatic->id])) {
  1705. $projectstatic->loadTimeSpentMonth($firstdaytoshow, 0, $fuser->id); // Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
  1706. $workloadforid[$projectstatic->id] = 1;
  1707. }
  1708. //var_dump($projectstatic->weekWorkLoadPerTask);
  1709. //var_dump('--- '.$projectstatic->id.' '.$workloadforid[$projectstatic->id]);
  1710. $projectstatic->id = $lines[$i]->fk_project;
  1711. $projectstatic->ref = $lines[$i]->projectref;
  1712. $projectstatic->title = $lines[$i]->projectlabel;
  1713. $projectstatic->public = $lines[$i]->public;
  1714. $projectstatic->thirdparty_name = $lines[$i]->thirdparty_name;
  1715. $projectstatic->status = $lines[$i]->projectstatus;
  1716. $taskstatic->id = $lines[$i]->id;
  1717. $taskstatic->ref = ($lines[$i]->ref ? $lines[$i]->ref : $lines[$i]->id);
  1718. $taskstatic->label = $lines[$i]->label;
  1719. $taskstatic->date_start = $lines[$i]->date_start;
  1720. $taskstatic->date_end = $lines[$i]->date_end;
  1721. $thirdpartystatic->id = $lines[$i]->thirdparty_id;
  1722. $thirdpartystatic->name = $lines[$i]->thirdparty_name;
  1723. $thirdpartystatic->email = $lines[$i]->thirdparty_email;
  1724. if (empty($oldprojectforbreak) || ($oldprojectforbreak != -1 && $oldprojectforbreak != $projectstatic->id)) {
  1725. print '<tr class="oddeven trforbreak nobold">'."\n";
  1726. print '<td colspan="'.(6 + count($TWeek)).'">';
  1727. print $projectstatic->getNomUrl(1, '', 0, '<strong>'.$langs->transnoentitiesnoconv("YourRole").':</strong> '.$projectsrole[$lines[$i]->fk_project]);
  1728. if ($thirdpartystatic->id > 0) {
  1729. print ' - '.$thirdpartystatic->getNomUrl(1);
  1730. }
  1731. if ($projectstatic->title) {
  1732. print ' - ';
  1733. print '<span class="secondary">'.$projectstatic->title.'</span>';
  1734. }
  1735. print '</td>';
  1736. print '</tr>';
  1737. }
  1738. if ($oldprojectforbreak != -1) {
  1739. $oldprojectforbreak = $projectstatic->id;
  1740. }
  1741. print '<tr class="oddeven" data-taskid="'.$lines[$i]->id.'">'."\n";
  1742. // User
  1743. /*
  1744. print '<td class="nowrap">';
  1745. print $fuser->getNomUrl(1, 'withproject', 'time');
  1746. print '</td>';
  1747. */
  1748. // Project
  1749. /*print '<td class="nowrap">';
  1750. if ($oldprojectforbreak == -1) print $projectstatic->getNomUrl(1,'',0,$langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
  1751. print "</td>";*/
  1752. // Thirdparty
  1753. /*print '<td class="tdoverflowmax100">';
  1754. if ($thirdpartystatic->id > 0) print $thirdpartystatic->getNomUrl(1, 'project');
  1755. print '</td>';*/
  1756. // Ref
  1757. print '<td class="nowrap">';
  1758. print '<!-- Task id = '.$lines[$i]->id.' -->';
  1759. for ($k = 0; $k < $level; $k++) {
  1760. print '<div class="marginleftonly">';
  1761. }
  1762. print $taskstatic->getNomUrl(1, 'withproject', 'time');
  1763. // Label task
  1764. print '<br>';
  1765. print '<span class="opacitymedium">'.$taskstatic->label.'</span>';
  1766. for ($k = 0; $k < $level; $k++) {
  1767. print "</div>";
  1768. }
  1769. print "</td>\n";
  1770. // Planned Workload
  1771. print '<td class="leftborder plannedworkload right">';
  1772. if ($lines[$i]->planned_workload) {
  1773. print convertSecondToTime($lines[$i]->planned_workload, 'allhourmin');
  1774. } else {
  1775. print '--:--';
  1776. }
  1777. print '</td>';
  1778. // Progress declared %
  1779. print '<td class="right">';
  1780. print $formother->select_percent($lines[$i]->progress, $lines[$i]->id.'progress');
  1781. print '</td>';
  1782. // Time spent by everybody
  1783. print '<td class="right">';
  1784. // $lines[$i]->duration is a denormalised field = summ of time spent by everybody for task. What we need is time consumed by user
  1785. if ($lines[$i]->duration) {
  1786. print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.'">';
  1787. print convertSecondToTime($lines[$i]->duration, 'allhourmin');
  1788. print '</a>';
  1789. } else {
  1790. print '--:--';
  1791. }
  1792. print "</td>\n";
  1793. // Time spent by user
  1794. print '<td class="right">';
  1795. $tmptimespent = $taskstatic->getSummaryOfTimeSpent($fuser->id);
  1796. if ($tmptimespent['total_duration']) {
  1797. print convertSecondToTime($tmptimespent['total_duration'], 'allhourmin');
  1798. } else {
  1799. print '--:--';
  1800. }
  1801. print "</td>\n";
  1802. $disabledproject = 1;
  1803. $disabledtask = 1;
  1804. //print "x".$lines[$i]->fk_project;
  1805. //var_dump($lines[$i]);
  1806. //var_dump($projectsrole[$lines[$i]->fk_project]);
  1807. // If at least one role for project
  1808. if ($lines[$i]->public || !empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer) {
  1809. $disabledproject = 0;
  1810. $disabledtask = 0;
  1811. }
  1812. // If $restricteditformytask is on and I have no role on task, i disable edit
  1813. if ($restricteditformytask && empty($tasksrole[$lines[$i]->id])) {
  1814. $disabledtask = 1;
  1815. }
  1816. //var_dump($projectstatic->weekWorkLoadPerTask);
  1817. //TODO
  1818. // Fields to show current time
  1819. $tableCell = '';
  1820. $modeinput = 'hours';
  1821. $TFirstDay = getFirstDayOfEachWeek($TWeek, date('Y', $firstdaytoshow));
  1822. $TFirstDay[reset($TWeek)] = 1;
  1823. $firstdaytoshowarray = dol_getdate($firstdaytoshow);
  1824. $year = $firstdaytoshowarray['year'];
  1825. $month = $firstdaytoshowarray['mon'];
  1826. foreach ($TWeek as $weekIndex => $weekNb) {
  1827. $weekWorkLoad = !empty($projectstatic->monthWorkLoadPerTask[$weekNb][$lines[$i]->id]) ? $projectstatic->monthWorkLoadPerTask[$weekNb][$lines[$i]->id] : 0 ;
  1828. if (!isset($totalforeachweek[$weekNb])) $totalforeachweek[$weekNb] = 0;
  1829. $totalforeachweek[$weekNb] += $weekWorkLoad;
  1830. $alreadyspent = '';
  1831. if ($weekWorkLoad > 0) {
  1832. $alreadyspent = convertSecondToTime($weekWorkLoad, 'allhourmin');
  1833. }
  1834. $alttitle = $langs->trans("AddHereTimeSpentForWeek", $weekNb);
  1835. $disabledtaskweek = $disabledtask;
  1836. $firstdayofweek = dol_mktime(0, 0, 0, $month, $TFirstDay[$weekIndex], $year);
  1837. if (! $disabledtask && $restrictBefore && $firstdayofweek < $restrictBefore) {
  1838. $disabledtaskweek = 1;
  1839. }
  1840. $tableCell = '<td class="center hide weekend">';
  1841. $placeholder = '';
  1842. if ($alreadyspent) {
  1843. $tableCell .= '<span class="timesheetalreadyrecorded" title="texttoreplace"><input type="text" class="center smallpadd" size="2" disabled id="timespent['.$inc.']['.((int) $weekNb).']" name="task['.$lines[$i]->id.']['.$weekNb.']" value="'.$alreadyspent.'"></span>';
  1844. //$placeholder=' placeholder="00:00"';
  1845. //$tableCell.='+';
  1846. }
  1847. $tableCell .= '<input type="text" alt="'.($disabledtaskweek ? '' : $alttitle).'" title="'.($disabledtaskweek ? '' : $alttitle).'" '.($disabledtaskweek ? 'disabled' : $placeholder).' class="center smallpadd" size="2" id="timeadded['.$inc.']['.((int) $weekNb).']" name="task['.$lines[$i]->id.']['.($TFirstDay[$weekNb] - 1).']" value="" cols="2" maxlength="5"';
  1848. $tableCell .= ' onkeypress="return regexEvent(this,event,\'timeChar\')"';
  1849. $tableCell .= ' onkeyup="updateTotal('.$weekNb.',\''.$modeinput.'\')"';
  1850. $tableCell .= ' onblur="regexEvent(this,event,\''.$modeinput.'\'); updateTotal('.$weekNb.',\''.$modeinput.'\')" />';
  1851. $tableCell .= '</td>';
  1852. print $tableCell;
  1853. }
  1854. // Warning
  1855. print '<td class="right">';
  1856. if ((!$lines[$i]->public) && $disabledproject) {
  1857. print $form->textwithpicto('', $langs->trans("UserIsNotContactOfProject"));
  1858. } elseif ($disabledtask) {
  1859. $titleassigntask = $langs->trans("AssignTaskToMe");
  1860. if ($fuser->id != $user->id) {
  1861. $titleassigntask = $langs->trans("AssignTaskToUser", '...');
  1862. }
  1863. print $form->textwithpicto('', $langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
  1864. }
  1865. print '</td>';
  1866. print "</tr>\n";
  1867. }
  1868. // Call to show task with a lower level (task under the current task)
  1869. $inc++;
  1870. $level++;
  1871. if ($lines[$i]->id > 0) {
  1872. //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level);
  1873. //var_dump($totalforeachday);
  1874. $ret = projectLinesPerMonth($inc, $firstdaytoshow, $fuser, $lines[$i]->id, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $isavailable, $oldprojectforbreak, $TWeek);
  1875. //var_dump('ret with parent='.$lines[$i]->id.' level='.$level);
  1876. //var_dump($ret);
  1877. foreach ($ret as $key => $val) {
  1878. $totalforeachweek[$key] += $val;
  1879. }
  1880. //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level.' + subtasks');
  1881. //var_dump($totalforeachday);
  1882. }
  1883. $level--;
  1884. } else {
  1885. //$level--;
  1886. }
  1887. }
  1888. return $totalforeachweek;
  1889. }
  1890. /**
  1891. * Search in task lines with a particular parent if there is a task for a particular user (in taskrole)
  1892. *
  1893. * @param string $inc Counter that count number of lines legitimate to show (for return)
  1894. * @param int $parent Id of parent task to start
  1895. * @param array $lines Array of all tasks
  1896. * @param string $taskrole Array of task filtered on a particular user
  1897. * @return int 1 if there is
  1898. */
  1899. function searchTaskInChild(&$inc, $parent, &$lines, &$taskrole)
  1900. {
  1901. //print 'Search in line with parent id = '.$parent.'<br>';
  1902. $numlines = count($lines);
  1903. for ($i = 0; $i < $numlines; $i++) {
  1904. // Process line $lines[$i]
  1905. if ($lines[$i]->fk_parent == $parent && $lines[$i]->id != $lines[$i]->fk_parent) {
  1906. // If task is legitimate to show, no more need to search deeper
  1907. if (isset($taskrole[$lines[$i]->id])) {
  1908. //print 'Found a legitimate task id='.$lines[$i]->id.'<br>';
  1909. $inc++;
  1910. return $inc;
  1911. }
  1912. searchTaskInChild($inc, $lines[$i]->id, $lines, $taskrole);
  1913. //print 'Found inc='.$inc.'<br>';
  1914. if ($inc > 0) {
  1915. return $inc;
  1916. }
  1917. }
  1918. }
  1919. return $inc;
  1920. }
  1921. /**
  1922. * Return HTML table with list of projects and number of opened tasks
  1923. *
  1924. * @param DoliDB $db Database handler
  1925. * @param Form $form Object form
  1926. * @param int $socid Id thirdparty
  1927. * @param int $projectsListId Id of project I have permission on
  1928. * @param int $mytasks Limited to task I am contact to
  1929. * @param int $status -1=No filter on statut, 0 or 1 = Filter on status
  1930. * @param array $listofoppstatus List of opportunity status
  1931. * @param array $hiddenfields List of info to not show ('projectlabel', 'declaredprogress', '...', )
  1932. * @param int $max Max nb of record to show in HTML list
  1933. * @return void
  1934. */
  1935. function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks = 0, $status = -1, $listofoppstatus = array(), $hiddenfields = array(), $max = 0)
  1936. {
  1937. global $langs, $conf, $user;
  1938. global $theme_datacolor;
  1939. $maxofloop = (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
  1940. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  1941. $listofstatus = array_keys($listofoppstatus);
  1942. if (is_array($listofstatus) && !empty($conf->global->USE_COLOR_FOR_PROSPECTION_STATUS)) {
  1943. // Define $themeColorId and array $statusOppList for each $listofstatus
  1944. $themeColorId = 0;
  1945. $statusOppList = array();
  1946. foreach ($listofstatus as $oppStatus) {
  1947. $oppStatusCode = dol_getIdFromCode($db, $oppStatus, 'c_lead_status', 'rowid', 'code');
  1948. if ($oppStatusCode) {
  1949. $statusOppList[$oppStatus]['code'] = $oppStatusCode;
  1950. $statusOppList[$oppStatus]['color'] = isset($theme_datacolor[$themeColorId]) ? implode(', ', $theme_datacolor[$themeColorId]) : '';
  1951. }
  1952. $themeColorId++;
  1953. }
  1954. }
  1955. $projectstatic = new Project($db);
  1956. $thirdpartystatic = new Societe($db);
  1957. $sortfield = '';
  1958. $sortorder = '';
  1959. $project_year_filter = 0;
  1960. $title = $langs->trans("Projects");
  1961. if (strcmp($status, '') && $status >= 0) {
  1962. $title = $langs->trans("Projects").' '.$langs->trans($projectstatic->statuts_long[$status]);
  1963. }
  1964. print '<!-- print_projecttasks_array -->';
  1965. print '<div class="div-table-responsive-no-min">';
  1966. print '<table class="noborder centpercent">';
  1967. $sql = " FROM ".MAIN_DB_PREFIX."projet as p";
  1968. if ($mytasks) {
  1969. $sql .= ", ".MAIN_DB_PREFIX."projet_task as t";
  1970. $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
  1971. $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as ctc";
  1972. } else {
  1973. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t ON p.rowid = t.fk_projet";
  1974. }
  1975. $sql .= " WHERE p.entity IN (".getEntity('project').")";
  1976. $sql .= " AND p.rowid IN (".$db->sanitize($projectsListId).")";
  1977. if ($socid) {
  1978. $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")";
  1979. }
  1980. if ($mytasks) {
  1981. $sql .= " AND p.rowid = t.fk_projet";
  1982. $sql .= " AND ec.element_id = t.rowid";
  1983. $sql .= " AND ec.fk_socpeople = ".((int) $user->id);
  1984. $sql .= " AND ec.fk_c_type_contact = ctc.rowid"; // Replace the 2 lines with ec.fk_c_type_contact in $arrayidtypeofcontact
  1985. $sql .= " AND ctc.element = 'project_task'";
  1986. }
  1987. if ($status >= 0) {
  1988. $sql .= " AND p.fk_statut = ".(int) $status;
  1989. }
  1990. if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE)) {
  1991. $project_year_filter = GETPOST("project_year_filter");
  1992. //Check if empty or invalid year. Wildcard ignores the sql check
  1993. if ($project_year_filter != "*") {
  1994. if (empty($project_year_filter) || !ctype_digit($project_year_filter)) {
  1995. $project_year_filter = date("Y");
  1996. }
  1997. $sql .= " AND (p.dateo IS NULL OR p.dateo <= ".$db->idate(dol_get_last_day($project_year_filter, 12, false)).")";
  1998. $sql .= " AND (p.datee IS NULL OR p.datee >= ".$db->idate(dol_get_first_day($project_year_filter, 1, false)).")";
  1999. }
  2000. }
  2001. // Get id of project we must show tasks
  2002. $arrayidofprojects = array();
  2003. $sql1 = "SELECT p.rowid as projectid";
  2004. $sql1 .= $sql;
  2005. $resql = $db->query($sql1);
  2006. if ($resql) {
  2007. $i = 0;
  2008. $num = $db->num_rows($resql);
  2009. while ($i < $num) {
  2010. $objp = $db->fetch_object($resql);
  2011. $arrayidofprojects[$objp->projectid] = $objp->projectid;
  2012. $i++;
  2013. }
  2014. } else {
  2015. dol_print_error($db);
  2016. }
  2017. if (empty($arrayidofprojects)) {
  2018. $arrayidofprojects[0] = -1;
  2019. }
  2020. // Get list of project with calculation on tasks
  2021. $sql2 = "SELECT p.rowid as projectid, p.ref, p.title, p.fk_soc,";
  2022. $sql2 .= " s.rowid as socid, s.nom as socname, s.name_alias,";
  2023. $sql2 .= " s.code_client, s.code_compta, s.client,";
  2024. $sql2 .= " s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur,";
  2025. $sql2 .= " s.logo, s.email, s.entity,";
  2026. $sql2 .= " p.fk_user_creat, p.public, p.fk_statut as status, p.fk_opp_status as opp_status, p.opp_percent, p.opp_amount,";
  2027. $sql2 .= " p.dateo, p.datee,";
  2028. $sql2 .= " COUNT(t.rowid) as nb, SUM(t.planned_workload) as planned_workload, SUM(t.planned_workload * t.progress / 100) as declared_progess_workload";
  2029. $sql2 .= " FROM ".MAIN_DB_PREFIX."projet as p";
  2030. $sql2 .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
  2031. $sql2 .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t ON p.rowid = t.fk_projet";
  2032. $sql2 .= " WHERE p.rowid IN (".$db->sanitize(join(',', $arrayidofprojects)).")";
  2033. $sql2 .= " GROUP BY p.rowid, p.ref, p.title, p.fk_soc, s.rowid, s.nom, s.name_alias, s.code_client, s.code_compta, s.client, s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur,";
  2034. $sql2 .= " s.logo, s.email, s.entity, p.fk_user_creat, p.public, p.fk_statut, p.fk_opp_status, p.opp_percent, p.opp_amount, p.dateo, p.datee";
  2035. $sql2 .= " ORDER BY p.title, p.ref";
  2036. $resql = $db->query($sql2);
  2037. if ($resql) {
  2038. $othernb = 0;
  2039. $total_task = 0;
  2040. $total_opp_amount = 0;
  2041. $ponderated_opp_amount = 0;
  2042. $total_plannedworkload = 0;
  2043. $total_declaredprogressworkload = 0;
  2044. $num = $db->num_rows($resql);
  2045. $nbofloop = min($num, (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD));
  2046. $i = 0;
  2047. print '<tr class="liste_titre">';
  2048. print_liste_field_titre($title.'<a href="'.DOL_URL_ROOT.'/projet/list.php?search_status='.((int) $status).'"><span class="badge marginleftonlyshort">'.$num.'</span></a>', $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
  2049. print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
  2050. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  2051. if (!in_array('prospectionstatus', $hiddenfields)) {
  2052. print_liste_field_titre("OpportunityStatus", "", "", "", "", 'style="max-width: 100px"', $sortfield, $sortorder, 'center ');
  2053. }
  2054. print_liste_field_titre($form->textwithpicto($langs->trans("Amount"), $langs->trans("OpportunityAmount").' ('.$langs->trans("Tooltip").' = '.$langs->trans("OpportunityWeightedAmount").')'), "", "", "", "", 'style="max-width: 100px"', $sortfield, $sortorder, 'right ');
  2055. //print_liste_field_titre('OpportunityWeightedAmount', '', '', '', '', 'align="right"', $sortfield, $sortorder);
  2056. }
  2057. if (empty($conf->global->PROJECT_HIDE_TASKS)) {
  2058. print_liste_field_titre("Tasks", "", "", "", "", 'align="right"', $sortfield, $sortorder);
  2059. if (!in_array('plannedworkload', $hiddenfields)) {
  2060. print_liste_field_titre("PlannedWorkload", "", "", "", "", 'style="max-width: 100px"', $sortfield, $sortorder, 'right ');
  2061. }
  2062. if (!in_array('declaredprogress', $hiddenfields)) {
  2063. print_liste_field_titre("%", "", "", "", "", '', $sortfield, $sortorder, 'right ', $langs->trans("ProgressDeclared"));
  2064. }
  2065. }
  2066. if (!in_array('projectstatus', $hiddenfields)) {
  2067. print_liste_field_titre("Status", "", "", "", "", '', $sortfield, $sortorder, 'right ');
  2068. }
  2069. print "</tr>\n";
  2070. while ($i < $nbofloop) {
  2071. $objp = $db->fetch_object($resql);
  2072. if ($max && $i >= $max) {
  2073. $othernb++;
  2074. $i++;
  2075. $total_task += $objp->nb;
  2076. $total_opp_amount += $objp->opp_amount;
  2077. $opp_weighted_amount = $objp->opp_percent * $objp->opp_amount / 100;
  2078. $ponderated_opp_amount += price2num($opp_weighted_amount);
  2079. $plannedworkload = $objp->planned_workload;
  2080. $total_plannedworkload += $plannedworkload;
  2081. $declaredprogressworkload = $objp->declared_progess_workload;
  2082. $total_declaredprogressworkload += $declaredprogressworkload;
  2083. continue;
  2084. }
  2085. $projectstatic->id = $objp->projectid;
  2086. $projectstatic->user_author_id = $objp->fk_user_creat;
  2087. $projectstatic->public = $objp->public;
  2088. // Check is user has read permission on project
  2089. $userAccess = $projectstatic->restrictedProjectArea($user);
  2090. if ($userAccess >= 0) {
  2091. $projectstatic->ref = $objp->ref;
  2092. $projectstatic->status = $objp->status;
  2093. $projectstatic->title = $objp->title;
  2094. $projectstatic->date_end = $db->jdate($objp->datee);
  2095. $projectstatic->date_start = $db->jdate($objp->dateo);
  2096. print '<tr class="oddeven">';
  2097. print '<td class="tdoverflowmax150">';
  2098. print $projectstatic->getNomUrl(1, '', 0, '', '-', 0, -1, 'nowraponall');
  2099. if (!in_array('projectlabel', $hiddenfields)) {
  2100. print '<br><span class="opacitymedium">'.dol_trunc($objp->title, 24).'</span>';
  2101. }
  2102. print '</td>';
  2103. print '<td class="nowraponall tdoverflowmax100">';
  2104. if ($objp->fk_soc > 0) {
  2105. $thirdpartystatic->id = $objp->socid;
  2106. $thirdpartystatic->name = $objp->socname;
  2107. //$thirdpartystatic->name_alias = $objp->name_alias;
  2108. //$thirdpartystatic->code_client = $objp->code_client;
  2109. $thirdpartystatic->code_compta = $objp->code_compta;
  2110. $thirdpartystatic->client = $objp->client;
  2111. //$thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
  2112. $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
  2113. $thirdpartystatic->fournisseur = $objp->fournisseur;
  2114. $thirdpartystatic->logo = $objp->logo;
  2115. $thirdpartystatic->email = $objp->email;
  2116. $thirdpartystatic->entity = $objp->entity;
  2117. print $thirdpartystatic->getNomUrl(1);
  2118. }
  2119. print '</td>';
  2120. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  2121. if (!in_array('prospectionstatus', $hiddenfields)) {
  2122. print '<td class="center tdoverflowmax75">';
  2123. // Because color of prospection status has no meaning yet, it is used if hidden constant is set
  2124. if (empty($conf->global->USE_COLOR_FOR_PROSPECTION_STATUS)) {
  2125. $oppStatusCode = dol_getIdFromCode($db, $objp->opp_status, 'c_lead_status', 'rowid', 'code');
  2126. if ($langs->trans("OppStatus".$oppStatusCode) != "OppStatus".$oppStatusCode) {
  2127. print $langs->trans("OppStatus".$oppStatusCode);
  2128. }
  2129. } else {
  2130. if (isset($statusOppList[$objp->opp_status])) {
  2131. $oppStatusCode = $statusOppList[$objp->opp_status]['code'];
  2132. $oppStatusColor = $statusOppList[$objp->opp_status]['color'];
  2133. } else {
  2134. $oppStatusCode = dol_getIdFromCode($db, $objp->opp_status, 'c_lead_status', 'rowid', 'code');
  2135. $oppStatusColor = '';
  2136. }
  2137. if ($oppStatusCode) {
  2138. if (!empty($oppStatusColor)) {
  2139. print '<a href="'.dol_buildpath('/projet/list.php?search_opp_status='.$objp->opp_status, 1).'" style="display: inline-block; width: 4px; border: 5px solid rgb('.$oppStatusColor.'); border-radius: 2px;" title="'.$langs->trans("OppStatus".$oppStatusCode).'"></a>';
  2140. } else {
  2141. print '<a href="'.dol_buildpath('/projet/list.php?search_opp_status='.$objp->opp_status, 1).'" title="'.$langs->trans("OppStatus".$oppStatusCode).'">'.$oppStatusCode.'</a>';
  2142. }
  2143. }
  2144. }
  2145. print '</td>';
  2146. }
  2147. print '<td class="right">';
  2148. if ($objp->opp_percent && $objp->opp_amount) {
  2149. $opp_weighted_amount = $objp->opp_percent * $objp->opp_amount / 100;
  2150. $alttext = $langs->trans("OpportunityWeightedAmount").' '.price($opp_weighted_amount, 0, '', 1, -1, 0, $conf->currency);
  2151. $ponderated_opp_amount += price2num($opp_weighted_amount);
  2152. }
  2153. if ($objp->opp_amount) {
  2154. print '<span class="amount" title="'.$alttext.'">'.$form->textwithpicto(price($objp->opp_amount, 0, '', 1, -1, 0), $alttext).'</span>';
  2155. }
  2156. print '</td>';
  2157. }
  2158. if (empty($conf->global->PROJECT_HIDE_TASKS)) {
  2159. print '<td class="right">'.$objp->nb.'</td>';
  2160. $plannedworkload = $objp->planned_workload;
  2161. $total_plannedworkload += $plannedworkload;
  2162. if (!in_array('plannedworkload', $hiddenfields)) {
  2163. print '<td class="right nowraponall">'.($plannedworkload ?convertSecondToTime($plannedworkload) : '').'</td>';
  2164. }
  2165. if (!in_array('declaredprogress', $hiddenfields)) {
  2166. $declaredprogressworkload = $objp->declared_progess_workload;
  2167. $total_declaredprogressworkload += $declaredprogressworkload;
  2168. print '<td class="right nowraponall">';
  2169. //print $objp->planned_workload.'-'.$objp->declared_progess_workload."<br>";
  2170. print ($plannedworkload ?round(100 * $declaredprogressworkload / $plannedworkload, 0).'%' : '');
  2171. print '</td>';
  2172. }
  2173. }
  2174. if (!in_array('projectstatus', $hiddenfields)) {
  2175. print '<td class="right">';
  2176. print $projectstatic->getLibStatut(3);
  2177. print '</td>';
  2178. }
  2179. print "</tr>\n";
  2180. $total_task += $objp->nb;
  2181. $total_opp_amount += $objp->opp_amount;
  2182. }
  2183. $i++;
  2184. }
  2185. if ($othernb) {
  2186. print '<tr class="oddeven">';
  2187. print '<td class="nowrap" colspan="5">';
  2188. print '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
  2189. print '</td>';
  2190. print "</tr>\n";
  2191. }
  2192. print '<tr class="liste_total">';
  2193. print '<td>'.$langs->trans("Total")."</td><td></td>";
  2194. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  2195. if (!in_array('prospectionstatus', $hiddenfields)) {
  2196. print '<td class="liste_total"></td>';
  2197. }
  2198. print '<td class="liste_total right">';
  2199. //$form->textwithpicto(price($ponderated_opp_amount, 0, '', 1, -1, -1, $conf->currency), $langs->trans("OpportunityPonderatedAmountDesc"), 1);
  2200. print $form->textwithpicto(price($total_opp_amount, 0, '', 1, -1, 0), $langs->trans("OpportunityPonderatedAmountDesc").' : '.price($ponderated_opp_amount, 0, '', 1, -1, 0, $conf->currency));
  2201. print '</td>';
  2202. }
  2203. if (empty($conf->global->PROJECT_HIDE_TASKS)) {
  2204. print '<td class="liste_total right">'.$total_task.'</td>';
  2205. if (!in_array('plannedworkload', $hiddenfields)) {
  2206. print '<td class="liste_total right">'.($total_plannedworkload ?convertSecondToTime($total_plannedworkload) : '').'</td>';
  2207. }
  2208. if (!in_array('declaredprogress', $hiddenfields)) {
  2209. print '<td class="liste_total right">'.($total_plannedworkload ?round(100 * $total_declaredprogressworkload / $total_plannedworkload, 0).'%' : '').'</td>';
  2210. }
  2211. }
  2212. if (!in_array('projectstatus', $hiddenfields)) {
  2213. print '<td class="liste_total"></td>';
  2214. }
  2215. print '</tr>';
  2216. $db->free($resql);
  2217. } else {
  2218. dol_print_error($db);
  2219. }
  2220. print "</table>";
  2221. print '</div>';
  2222. if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE)) {
  2223. //Add the year filter input
  2224. print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">';
  2225. print '<table width="100%">';
  2226. print '<tr>';
  2227. print '<td>'.$langs->trans("Year").'</td>';
  2228. print '<td class="right"><input type="text" size="4" class="flat" name="project_year_filter" value="'.$project_year_filter.'"/>';
  2229. print "</tr>\n";
  2230. print '</table></form>';
  2231. }
  2232. }
  2233. /**
  2234. * @param Task $task the task object
  2235. * @param bool|string $label true = auto, false = dont display, string = replace output
  2236. * @param bool|string $progressNumber true = auto, false = dont display, string = replace output
  2237. * @param bool $hideOnProgressNull hide if progress is null
  2238. * @param bool $spaced used to add space at bottom (made by css)
  2239. * @return string
  2240. * @see getTaskProgressBadge()
  2241. */
  2242. function getTaskProgressView($task, $label = true, $progressNumber = true, $hideOnProgressNull = false, $spaced = false)
  2243. {
  2244. global $langs, $conf;
  2245. $out = '';
  2246. $plannedworkloadoutputformat = 'allhourmin';
  2247. $timespentoutputformat = 'allhourmin';
  2248. if (!empty($conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT)) {
  2249. $plannedworkloadoutputformat = $conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT;
  2250. }
  2251. if (!empty($conf->global->PROJECT_TIMES_SPENT_FORMAT)) {
  2252. $timespentoutputformat = $conf->global->PROJECT_TIME_SPENT_FORMAT;
  2253. }
  2254. if (empty($task->progress) && !empty($hideOnProgressNull)) {
  2255. return '';
  2256. }
  2257. $spaced = !empty($spaced) ? 'spaced' : '';
  2258. $diff = '';
  2259. // define progress color according to time spend vs workload
  2260. $progressBarClass = 'progress-bar-info';
  2261. $progressCalculated = 0;
  2262. if ($task->planned_workload) {
  2263. $progressCalculated = round(100 * floatval($task->duration_effective) / floatval($task->planned_workload), 2);
  2264. // this conf is actually hidden, by default we use 10% for "be carefull or warning"
  2265. $warningRatio = !empty($conf->global->PROJECT_TIME_SPEND_WARNING_PERCENT) ? (1 + $conf->global->PROJECT_TIME_SPEND_WARNING_PERCENT / 100) : 1.10;
  2266. $diffTitle = '<br>'.$langs->trans('ProgressDeclared').' : '.$task->progress.($task->progress ? '%' : '');
  2267. $diffTitle .= '<br>'.$langs->trans('ProgressCalculated').' : '.$progressCalculated.($progressCalculated ? '%' : '');
  2268. //var_dump($progressCalculated.' '.$warningRatio.' '.$task->progress.' '.floatval($task->progress * $warningRatio));
  2269. if (floatval($progressCalculated) > floatval($task->progress * $warningRatio)) {
  2270. $progressBarClass = 'progress-bar-danger';
  2271. $title = $langs->trans('TheReportedProgressIsLessThanTheCalculatedProgressionByX', abs($task->progress - $progressCalculated).' '.$langs->trans("point"));
  2272. $diff = '<span class="text-danger classfortooltip paddingrightonly" title="'.dol_htmlentities($title.$diffTitle).'" ><i class="fa fa-caret-down"></i> '.($task->progress - $progressCalculated).'%</span>';
  2273. } elseif (floatval($progressCalculated) > floatval($task->progress)) { // warning if close at 10%
  2274. $progressBarClass = 'progress-bar-warning';
  2275. $title = $langs->trans('TheReportedProgressIsLessThanTheCalculatedProgressionByX', abs($task->progress - $progressCalculated).' '.$langs->trans("point"));
  2276. $diff = '<span class="text-warning classfortooltip paddingrightonly" title="'.dol_htmlentities($title.$diffTitle).'" ><i class="fa fa-caret-left"></i> '.($task->progress - $progressCalculated).'%</span>';
  2277. } else {
  2278. $progressBarClass = 'progress-bar-success';
  2279. $title = $langs->trans('TheReportedProgressIsMoreThanTheCalculatedProgressionByX', ($task->progress - $progressCalculated).' '.$langs->trans("point"));
  2280. $diff = '<span class="text-success classfortooltip paddingrightonly" title="'.dol_htmlentities($title.$diffTitle).'" ><i class="fa fa-caret-up"></i> '.($task->progress - $progressCalculated).'%</span>';
  2281. }
  2282. }
  2283. $out .= '<div class="progress-group">';
  2284. if ($label !== false) {
  2285. $out .= ' <span class="progress-text">';
  2286. if ($label !== true) {
  2287. $out .= $label; // replace label by param
  2288. } else {
  2289. $out .= $task->getNomUrl(1).' '.dol_htmlentities($task->label);
  2290. }
  2291. $out .= ' </span>';
  2292. }
  2293. if ($progressNumber !== false) {
  2294. $out .= ' <span class="progress-number">';
  2295. if ($progressNumber !== true) {
  2296. $out .= $progressNumber; // replace label by param
  2297. } else {
  2298. if ($task->hasDelay()) {
  2299. $out .= img_warning($langs->trans("Late")).' ';
  2300. }
  2301. $url = DOL_URL_ROOT.'/projet/tasks/time.php?id='.$task->id;
  2302. $out .= !empty($diff) ? $diff.' ' : '';
  2303. $out .= '<a href="'.$url.'" >';
  2304. $out .= '<b title="'.$langs->trans('TimeSpent').'" >';
  2305. if ($task->duration_effective) {
  2306. $out .= convertSecondToTime($task->duration_effective, $timespentoutputformat);
  2307. } else {
  2308. $out .= '--:--';
  2309. }
  2310. $out .= '</b>';
  2311. $out .= '</a>';
  2312. $out .= ' / ';
  2313. $out .= '<a href="'.$url.'" >';
  2314. $out .= '<span title="'.$langs->trans('PlannedWorkload').'" >';
  2315. if ($task->planned_workload) {
  2316. $out .= convertSecondToTime($task->planned_workload, $plannedworkloadoutputformat);
  2317. } else {
  2318. $out .= '--:--';
  2319. }
  2320. $out .= '</a>';
  2321. }
  2322. $out .= ' </span>';
  2323. }
  2324. $out .= '</span>';
  2325. $out .= ' <div class="progress sm '.$spaced.'">';
  2326. $diffval = floatval($task->progress) - floatval($progressCalculated);
  2327. if ($diffval >= 0) {
  2328. // good
  2329. $out .= ' <div class="progress-bar '.$progressBarClass.'" style="width: '.floatval($task->progress).'%" title="'.floatval($task->progress).'%">';
  2330. if (!empty($task->progress)) {
  2331. $out .= ' <div class="progress-bar progress-bar-consumed" style="width: '.floatval($progressCalculated / (floatval($task->progress) === 0 ? 1 : $task->progress) * 100).'%" title="'.floatval($progressCalculated).'%"></div>';
  2332. }
  2333. $out .= ' </div>';
  2334. } else {
  2335. // bad
  2336. $out .= ' <div class="progress-bar progress-bar-consumed-late" style="width: '.floatval($progressCalculated).'%" title="'.floatval($progressCalculated).'%">';
  2337. $out .= ' <div class="progress-bar '.$progressBarClass.'" style="width: '.($task->progress ? floatval($task->progress / (floatval($progressCalculated) === 0 ? 1 : $progressCalculated) * 100).'%' : '1px').'" title="'.floatval($task->progress).'%"></div>';
  2338. $out .= ' </div>';
  2339. }
  2340. $out .= ' </div>';
  2341. $out .= '</div>';
  2342. return $out;
  2343. }
  2344. /**
  2345. * @param Task $task the task object
  2346. * @param string $label empty = auto (progress), string = replace output
  2347. * @param string $tooltip empty = auto , string = replace output
  2348. * @return string
  2349. * @see getTaskProgressView()
  2350. */
  2351. function getTaskProgressBadge($task, $label = '', $tooltip = '')
  2352. {
  2353. global $conf, $langs;
  2354. $out = '';
  2355. $badgeClass = '';
  2356. if ($task->progress != '') {
  2357. // TODO : manage 100%
  2358. // define color according to time spend vs workload
  2359. $badgeClass = 'badge ';
  2360. if ($task->planned_workload) {
  2361. $progressCalculated = round(100 * floatval($task->duration_effective) / floatval($task->planned_workload), 2);
  2362. // this conf is actually hidden, by default we use 10% for "be carefull or warning"
  2363. $warningRatio = !empty($conf->global->PROJECT_TIME_SPEND_WARNING_PERCENT) ? (1 + $conf->global->PROJECT_TIME_SPEND_WARNING_PERCENT / 100) : 1.10;
  2364. if (floatval($progressCalculated) > floatval($task->progress * $warningRatio)) {
  2365. $badgeClass .= 'badge-danger';
  2366. if (empty($tooltip)) {
  2367. $tooltip = $task->progress.'% < '.$langs->trans("TimeConsumed").' '.$progressCalculated.'%';
  2368. }
  2369. } elseif (floatval($progressCalculated) > floatval($task->progress)) { // warning if close at 10%
  2370. $badgeClass .= 'badge-warning';
  2371. if (empty($tooltip)) {
  2372. $tooltip = $task->progress.'% < '.$langs->trans("TimeConsumed").' '.$progressCalculated.'%';
  2373. }
  2374. } else {
  2375. $badgeClass .= 'badge-success';
  2376. if (empty($tooltip)) {
  2377. $tooltip = $task->progress.'% >= '.$langs->trans("TimeConsumed").' '.$progressCalculated.'%';
  2378. }
  2379. }
  2380. }
  2381. }
  2382. $title = '';
  2383. if (!empty($tooltip)) {
  2384. $badgeClass .= ' classfortooltip';
  2385. $title = 'title="'.dol_htmlentities($tooltip).'"';
  2386. }
  2387. if (empty($label)) {
  2388. $label = $task->progress.' %';
  2389. }
  2390. if (!empty($label)) {
  2391. $out = '<span class="'.$badgeClass.'" '.$title.' >'.$label.'</span>';
  2392. }
  2393. return $out;
  2394. }